Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
refactor(docs): use enum for document block ranges (#7010)
wpxp123456ff33ab810089
diff --git a/packages/core/src/docs/data-model/text-x/__tests__/block-ranges.spec.ts b/packages/core/src/docs/data-model/text-x/__tests__/block-ranges.spec.tsindex 556e9748e7..19d1a9aa7d 100644--- a/packages/core/src/docs/data-model/text-x/__tests__/block-ranges.spec.ts+++ b/packages/core/src/docs/data-model/text-x/__tests__/block-ranges.spec.ts@@ -15,6 +15,7 @@*/import type { IDocumentBody } from '../../../../types/interfaces';+import { DocumentBlockRangeType } from '@univerjs/core';import { describe, expect, it } from 'vitest';import { DataStreamTreeTokenType } from '../../types';import { deleteBlockRanges, insertBlockRanges } from '../apply-utils/common';@@ -25,52 +26,52 @@ describe('document block ranges', () => {it('moves following block ranges when text is inserted before them', () => {const body: IDocumentBody = {dataStream: 'A\rB\r\n',- blockRanges: [{ blockId: 'callout-1', blockType: 'callout', startIndex: 2, endIndex: 3 }],+ blockRanges: [{ blockId: 'callout-1', blockType: DocumentBlockRangeType.CALLOUT, startIndex: 2, endIndex: 3 }],};insertBlockRanges(body, { dataStream: 'XX' }, 2, 1);expect(body.blockRanges).toEqual([- { blockId: 'callout-1', blockType: 'callout', startIndex: 4, endIndex: 5 },+ { blockId: 'callout-1', blockType: DocumentBlockRangeType.CALLOUT, startIndex: 4, endIndex: 5 },]);});it('expands containing block ranges when text is inserted inside them', () => {const body: IDocumentBody = {dataStream: `${DataStreamTreeTokenType.BLOCK_START}A\r${DataStreamTreeTokenType.BLOCK_END}\n`,- blockRanges: [{ blockId: 'callout-1', blockType: 'callout', startIndex: 0, endIndex: 3 }],+ blockRanges: [{ blockId: 'callout-1', blockType: DocumentBlockRangeType.CALLOUT, startIndex: 0, endIndex: 3 }],};insertBlockRanges(body, { dataStream: 'XX' }, 2, 2);expect(body.blockRanges).toEqual([- { blockId: 'callout-1', blockType: 'callout', startIndex: 0, endIndex: 5 },+ { blockId: 'callout-1', blockType: DocumentBlockRangeType.CALLOUT, startIndex: 0, endIndex: 5 },]);});it('cuts block ranges to the copied body with relative indexes', () => {const body: IDocumentBody = {dataStream: `A\r${DataStreamTreeTokenType.BLOCK_START}B\r${DataStreamTreeTokenType.BLOCK_END}C\r\n`,- blockRanges: [{ blockId: 'callout-1', blockType: 'callout', startIndex: 2, endIndex: 5 }],+ blockRanges: [{ blockId: 'callout-1', blockType: DocumentBlockRangeType.CALLOUT, startIndex: 2, endIndex: 5 }],};const slice = getBodySlice(body, 2, 6);expect(slice.dataStream).toBe(`${DataStreamTreeTokenType.BLOCK_START}B\r${DataStreamTreeTokenType.BLOCK_END}`);expect(slice.blockRanges).toEqual([- { blockId: 'callout-1', blockType: 'callout', startIndex: 0, endIndex: 3 },+ { blockId: 'callout-1', blockType: DocumentBlockRangeType.CALLOUT, startIndex: 0, endIndex: 3 },]);});it('removes fully deleted block ranges', () => {const body: IDocumentBody = {dataStream: `${DataStreamTreeTokenType.BLOCK_START}A\r${DataStreamTreeTokenType.BLOCK_END}\n`,- blockRanges: [{ blockId: 'callout-1', blockType: 'callout', startIndex: 0, endIndex: 3 }],+ blockRanges: [{ blockId: 'callout-1', blockType: DocumentBlockRangeType.CALLOUT, startIndex: 0, endIndex: 3 }],};const removed = deleteBlockRanges(body, 4, 0);- expect(removed).toEqual([{ blockId: 'callout-1', blockType: 'callout', startIndex: 0, endIndex: 3 }]);+ expect(removed).toEqual([{ blockId: 'callout-1', blockType: DocumentBlockRangeType.CALLOUT, startIndex: 0, endIndex: 3 }]);expect(body.blockRanges).toEqual([]);});diff --git a/packages/core/src/types/interfaces/i-document-data.ts b/packages/core/src/types/interfaces/i-document-data.tsindex 3830d1d975..ccb06adfde 100644--- a/packages/core/src/types/interfaces/i-document-data.ts+++ b/packages/core/src/types/interfaces/i-document-data.ts@@ -14,9 +14,9 @@* limitations under the License.*/+import type { ImageSourceType } from '../../services/image-io/image-io.service';import type { ISize } from '../../shared/shape';import type { BooleanNumber, CellValueType, HorizontalAlign, LocaleType, TextDirection, VerticalAlign, WrapStrategy } from '../enum';-import type { ImageSourceType } from '../../services/image-io/image-io.service';import type { IDrawingParam } from './i-drawing';import type { IMention } from './i-mention';import type { IColorStyle, IStyleBase } from './i-style-data';@@ -366,11 +366,17 @@ export type IHyperLinkCustomRange = ICustomRange<{ url: string }>;export type IMentionCustomRange = ICustomRange<IMention>;+export enum DocumentBlockRangeType {+ CALLOUT = 'callout',+ QUOTE = 'quote',+ CODE = 'code',+}+export interface IDocumentBlockRange {startIndex: number;endIndex: number;blockId: string;- blockType: string;+ blockType: DocumentBlockRangeType;}export enum CustomRangeType {diff --git a/packages/docs-ui/src/commands/commands/__tests__/core-editing.command.spec.ts b/packages/docs-ui/src/commands/commands/__tests__/core-editing.command.spec.tsindex 7e0d64b30f..fff0c3fb1a 100644--- a/packages/docs-ui/src/commands/commands/__tests__/core-editing.command.spec.ts+++ b/packages/docs-ui/src/commands/commands/__tests__/core-editing.command.spec.ts@@ -22,13 +22,22 @@ import {CustomRangeType,DataStreamTreeTokenType,DeleteDirection,+ DocumentBlockRangeType,HorizontalAlign,ICommandService,IUniverInstanceService,UniverInstanceType,UpdateDocsAttributeType,} from '@univerjs/core';-import { DeleteTextCommand, DocSelectionManagerService, DocSkeletonManagerService, InsertTextCommand, RichTextEditingMutation, SetTextSelectionsOperation, UpdateTextCommand } from '@univerjs/docs';+import {+ DeleteTextCommand,+ DocSelectionManagerService,+ DocSkeletonManagerService,+ InsertTextCommand,+ RichTextEditingMutation,+ SetTextSelectionsOperation,+ UpdateTextCommand,+} from '@univerjs/docs';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { DeleteLeftCommand, DeleteRightCommand, isDeleteOffsetInsideBlockRange } from '../doc-delete.command';import { createCommandTestBed } from './create-command-test-bed';@@ -134,7 +143,7 @@ function getIndentedBlockRangeDocumentData(): IDocumentData {}],blockRanges: [{blockId: 'quote-1',- blockType: 'quote',+ blockType: DocumentBlockRangeType.QUOTE,startIndex: 0,endIndex: 3,}],@@ -355,7 +364,7 @@ describe('core editing commands', () => {dataStream,blockRanges: [{blockId: 'block-1',- blockType: 'quote',+ blockType: DocumentBlockRangeType.QUOTE,startIndex: 0,endIndex: 3,}],@@ -373,7 +382,7 @@ describe('core editing commands', () => {dataStream,blockRanges: [{blockId: 'block-1',- blockType: 'callout',+ blockType: DocumentBlockRangeType.CALLOUT,startIndex: 0,endIndex: 2,}],diff --git a/packages/docs-ui/src/commands/commands/__tests__/doc-block-move.command.spec.ts b/packages/docs-ui/src/commands/commands/__tests__/doc-block-move.command.spec.tsindex a164d21e03..e2624dc949 100644--- a/packages/docs-ui/src/commands/commands/__tests__/doc-block-move.command.spec.ts+++ b/packages/docs-ui/src/commands/commands/__tests__/doc-block-move.command.spec.ts@@ -15,7 +15,7 @@*/import type { IDocumentData } from '@univerjs/core';-import { BlockType, CustomRangeType } from '@univerjs/core';+import { BlockType, CustomRangeType, DocumentBlockRangeType } from '@univerjs/core';import { describe, expect, it } from 'vitest';import { buildMoveDocBlockActions } from '../doc-block-move.command';@@ -41,7 +41,7 @@ describe('buildMoveDocBlockActions', () => {const documentData = createDocument('aa\rBB\rcc\r\n', {paragraphs: [{ startIndex: 2 }, { startIndex: 5 }, { startIndex: 8 }],sectionBreaks: [{ startIndex: 9 }],- blockRanges: [{ blockId: 'quote-1', blockType: 'quote', startIndex: 3, endIndex: 5 }],+ blockRanges: [{ blockId: 'quote-1', blockType: DocumentBlockRangeType.QUOTE, startIndex: 3, endIndex: 5 }],});const { nextDocumentData, movedRange } = buildMoveDocBlockActions({diff --git a/packages/docs-ui/src/controllers/render-controllers/doc-contextmenu.render-controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc-contextmenu.render-controller.tsindex 9a125e408a..0b1a816610 100644--- a/packages/docs-ui/src/controllers/render-controllers/doc-contextmenu.render-controller.ts+++ b/packages/docs-ui/src/controllers/render-controllers/doc-contextmenu.render-controller.ts@@ -22,6 +22,7 @@ import {DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,DOCS_NORMAL_EDITOR_UNIT_ID_KEY,DOCS_ZEN_EDITOR_UNIT_ID_KEY,+ DocumentBlockRangeType,ICommandService,Inject,IUniverInstanceService,@@ -91,7 +92,7 @@ export class DocContextMenuRenderController extends Disposable implements IRendeprivate _isSelectionInCodeBlock(): boolean {const documentDataModel = this._univerInstanceService.getCurrentUnitOfType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC);- const blockRanges = documentDataModel?.getBody()?.blockRanges?.filter((range) => range.blockType === 'code') ?? [];+ const blockRanges = documentDataModel?.getBody()?.blockRanges?.filter((range) => range.blockType === DocumentBlockRangeType.CODE) ?? [];const textRanges = this._docSelectionManagerService.getTextRanges() ?? [];if (!blockRanges.length || !textRanges.length) {return false;diff --git a/packages/docs-ui/src/menu/menu.ts b/packages/docs-ui/src/menu/menu.tsindex 418590e23c..3f81e73c9b 100644--- a/packages/docs-ui/src/menu/menu.ts+++ b/packages/docs-ui/src/menu/menu.ts@@ -23,6 +23,7 @@ import {BuildTextUtils,DEFAULT_STYLES,DOCS_ZEN_EDITOR_UNIT_ID_KEY,+ DocumentBlockRangeType,DocumentFlavor,HorizontalAlign,ICommandService,@@ -237,7 +238,7 @@ export function disableMenuWhenNoDocRange(accessor: IAccessor): Observable<boole}const document = univerInstanceService.getCurrentUnitOfType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC);- const codeBlockRanges = document?.getBody()?.blockRanges?.filter((range) => range.blockType === 'code') ?? [];+ const codeBlockRanges = document?.getBody()?.blockRanges?.filter((range) => range.blockType === DocumentBlockRangeType.CODE) ?? [];if (codeBlockRanges.some((blockRange) => textRanges.some((range) => (Math.max(range.startOffset, blockRange.startIndex) <= Math.min(range.endOffset, blockRange.endIndex))))) {diff --git a/packages/docs-ui/src/services/__tests__/doc-paragraph-menu.service.spec.ts b/packages/docs-ui/src/services/__tests__/doc-paragraph-menu.service.spec.tsindex beb23b54ac..e72d03ac4a 100644--- a/packages/docs-ui/src/services/__tests__/doc-paragraph-menu.service.spec.ts+++ b/packages/docs-ui/src/services/__tests__/doc-paragraph-menu.service.spec.ts@@ -15,7 +15,7 @@*/import type { IMutiPageParagraphBound } from '../doc-event-manager.service';-import { DataStreamTreeTokenType, PresetListType } from '@univerjs/core';+import { DataStreamTreeTokenType, DocumentBlockRangeType, PresetListType } from '@univerjs/core';import { DocumentEditArea } from '@univerjs/engine-render';import { BehaviorSubject, Subject } from 'rxjs';import { describe, expect, it, vi } from 'vitest';@@ -83,7 +83,7 @@ describe('DocParagraphMenuService', () => {const service = createService({attachPopupToRect,dataStream: blockText,- blockRanges: [{ blockId: 'block-1', blockType: 'quote', startIndex: 0, endIndex: blockText.length - 1 }],+ blockRanges: [{ blockId: 'block-1', blockType: DocumentBlockRangeType.QUOTE, startIndex: 0, endIndex: blockText.length - 1 }],});service.showParagraphMenu(createParagraphBound({@@ -118,7 +118,7 @@ describe('DocParagraphMenuService', () => {const service = createService({attachPopupToRect,dataStream: blockText,- blockRanges: [{ blockId: 'block-1', blockType: 'quote', startIndex: 0, endIndex: blockText.length - 1 }],+ blockRanges: [{ blockId: 'block-1', blockType: DocumentBlockRangeType.QUOTE, startIndex: 0, endIndex: blockText.length - 1 }],paragraphBounds: new Map([[2, firstBlockParagraph],[4, secondBlockParagraph],diff --git a/packages/docs-ui/src/services/clipboard/__test__/html-and-udm-convert.spec.ts b/packages/docs-ui/src/services/clipboard/__test__/html-and-udm-convert.spec.tsindex fc4fcd52c0..84af121369 100644--- a/packages/docs-ui/src/services/clipboard/__test__/html-and-udm-convert.spec.ts+++ b/packages/docs-ui/src/services/clipboard/__test__/html-and-udm-convert.spec.ts@@ -15,13 +15,19 @@*/import type { IDocumentBody, IDocumentData, Nullable } from '@univerjs/core';-import { BooleanNumber, DataStreamTreeTokenType, HorizontalAlign, PresetListType, TableSizeType } from '@univerjs/core';+import { BooleanNumber, DataStreamTreeTokenType, DocumentBlockRangeType, HorizontalAlign, PresetListType, TableSizeType } from '@univerjs/core';import { afterEach, beforeEach, describe, expect, it } from 'vitest';-import { HtmlToUDMService } from '../html-to-udm/converter';import PastePluginLark from '../html-to-udm/paste-plugins/plugin-lark';import PastePluginWord from '../html-to-udm/paste-plugins/plugin-word';-import { createInternalClipboardDocData, createInternalClipboardDocDataList, createInternalClipboardFragment, embedInternalClipboardFragment, extractInternalClipboardFragmentFromHtml, wrapClipboardHtml } from '../internal-fragment';+import {+ createInternalClipboardDocData,+ createInternalClipboardDocDataList,+ createInternalClipboardFragment,+ embedInternalClipboardFragment,+ extractInternalClipboardFragmentFromHtml,+ wrapClipboardHtml,+} from '../internal-fragment';import { UDMToHtmlService } from '../udm-to-html/convertor';HtmlToUDMService.use(PastePluginWord);@@ -129,7 +135,11 @@ describe('test case in html and udm convert', () => {<ol><li>First</li><li>Second</li></ol>`);- expect(udm.body?.blockRanges?.map((range) => range.blockType)).toEqual(['quote', 'code', 'callout']);+ expect(udm.body?.blockRanges?.map((range) => range.blockType)).toEqual([+ DocumentBlockRangeType.QUOTE,+ DocumentBlockRangeType.CODE,+ DocumentBlockRangeType.CALLOUT,+ ]);expect(udm.body?.paragraphs?.filter((paragraph) => paragraph.bullet).map((paragraph) => paragraph.bullet?.listType)).toEqual(['ORDER_LIST', 'ORDER_LIST']);expect(udm.body?.dataStream).toContain('Quote text\r');expect(udm.body?.dataStream).toContain('const a = 1;\r');@@ -274,9 +284,9 @@ describe('test case in html and udm convert', () => {body: {dataStream: 'Quote\rCode\rCallout\rItem\r',blockRanges: [- { blockId: 'quote-1', blockType: 'quote', startIndex: 0, endIndex: 5 },- { blockId: 'code-1', blockType: 'code', startIndex: 6, endIndex: 10 },- { blockId: 'callout-1', blockType: 'callout', startIndex: 11, endIndex: 18 },+ { blockId: 'quote-1', blockType: DocumentBlockRangeType.QUOTE, startIndex: 0, endIndex: 5 },+ { blockId: 'code-1', blockType: DocumentBlockRangeType.CODE, startIndex: 6, endIndex: 10 },+ { blockId: 'callout-1', blockType: DocumentBlockRangeType.CALLOUT, startIndex: 11, endIndex: 18 },],paragraphs: [{ startIndex: 5 },@@ -513,7 +523,11 @@ describe('test case in html and udm convert', () => {expect(styledRun.ts?.ul?.s).toBe(BooleanNumber.TRUE);expect(bulletParagraph).toBeDefined();expect(orderedParagraph).toBeDefined();- expect(blockTypes).toEqual(['callout', 'code', 'quote']);+ expect(blockTypes).toEqual([+ DocumentBlockRangeType.CALLOUT,+ DocumentBlockRangeType.CODE,+ DocumentBlockRangeType.QUOTE,+ ]);expect(table).toBeDefined();const headerCell = table!.tableRows[0]!.tableCells[0]!;expect(table!.tableColumns.map((column) => column.size.width.v)).toEqual([90, 210]);diff --git a/packages/docs-ui/src/services/clipboard/html-to-udm/converter.ts b/packages/docs-ui/src/services/clipboard/html-to-udm/converter.tsindex b8d5367308..eab9233127 100644--- a/packages/docs-ui/src/services/clipboard/html-to-udm/converter.ts+++ b/packages/docs-ui/src/services/clipboard/html-to-udm/converter.ts@@ -20,6 +20,7 @@ import {ColorKit,CustomRangeType,DataStreamTreeTokenType,+ DocumentBlockRangeType,DrawingTypeEnum,generateRandomId,isSafeUrl,@@ -267,7 +268,7 @@ export class HtmlToUDMService {body.blockRanges ??= [];body.blockRanges.push({blockId: generateRandomId(6),- blockType: 'code',+ blockType: DocumentBlockRangeType.CODE,startIndex,endIndex: body.dataStream.length - 1,});@@ -934,23 +935,23 @@ function roundCssNumber(value: number): number {return Math.round(value * 100) / 100;}-function getStructuredBlockType(node: HTMLElement): string | null {+function getStructuredBlockType(node: HTMLElement): DocumentBlockRangeType | null {const docType = node.dataset.docType;- if (docType === 'quote') {- return 'quote';+ if (docType === DocumentBlockRangeType.QUOTE) {+ return DocumentBlockRangeType.QUOTE;}- if (docType === 'callout') {- return 'callout';+ if (docType === DocumentBlockRangeType.CALLOUT) {+ return DocumentBlockRangeType.CALLOUT;}const tagName = node.tagName.toUpperCase();if (tagName === 'BLOCKQUOTE') {- return docType === 'callout' ? 'callout' : 'quote';+ return docType === DocumentBlockRangeType.CALLOUT ? DocumentBlockRangeType.CALLOUT : DocumentBlockRangeType.QUOTE;}if (tagName === 'ASIDE' && node.getAttribute('role') === 'note') {- return 'callout';+ return DocumentBlockRangeType.CALLOUT;}return null;diff --git a/packages/docs-ui/src/services/clipboard/udm-to-html/__test__/convertor.spec.ts b/packages/docs-ui/src/services/clipboard/udm-to-html/__test__/convertor.spec.tsindex 04a1a98694..507e2aefa8 100644--- a/packages/docs-ui/src/services/clipboard/udm-to-html/__test__/convertor.spec.ts+++ b/packages/docs-ui/src/services/clipboard/udm-to-html/__test__/convertor.spec.ts@@ -15,7 +15,7 @@*/import type { IDocumentBody } from '@univerjs/core';-import { BooleanNumber, DataStreamTreeTokenType, NamedStyleType, TableRowHeightRule, TableSizeType } from '@univerjs/core';+import { BooleanNumber, DataStreamTreeTokenType, DocumentBlockRangeType, NamedStyleType, TableRowHeightRule, TableSizeType } from '@univerjs/core';import { describe, expect, it } from 'vitest';import { convertBodyToHtml, covertTextRunToHtml, getBodySliceHtml, UDMToHtmlService } from '../convertor';@@ -198,7 +198,7 @@ describe('test case in html and udm convert', () => {blockRanges: [{startIndex: blockStart,endIndex: blockStart + tokens.BLOCK_START.length + code.length - 1,- blockType: 'code',+ blockType: DocumentBlockRangeType.CODE,}] as any,},});diff --git a/packages/docs-ui/src/services/clipboard/udm-to-html/convertor.ts b/packages/docs-ui/src/services/clipboard/udm-to-html/convertor.tsindex 5956abd485..0da1e2ca63 100644--- a/packages/docs-ui/src/services/clipboard/udm-to-html/convertor.ts+++ b/packages/docs-ui/src/services/clipboard/udm-to-html/convertor.ts@@ -17,7 +17,18 @@import type { IDocumentBody, IDocumentData, IParagraph, ITable, ITableCell, ITextRun, ITextStyle } from '@univerjs/core';import type { IDocImage } from '@univerjs/docs-drawing';import type { DataStreamTreeNode } from '@univerjs/engine-render';-import { BaselineOffset, BooleanNumber, CustomRangeType, DataStreamTreeNodeType, DrawingTypeEnum, HorizontalAlign, NamedStyleType, PresetListType, Tools } from '@univerjs/core';+import {+ BaselineOffset,+ BooleanNumber,+ CustomRangeType,+ DataStreamTreeNodeType,+ DocumentBlockRangeType,+ DrawingTypeEnum,+ HorizontalAlign,+ NamedStyleType,+ PresetListType,+ Tools,+} from '@univerjs/core';import { ImageSourceType } from '@univerjs/drawing';import { parseDataStreamToTree } from '@univerjs/engine-render';@@ -424,11 +435,11 @@ function renderBlockParagraphHtml(doc: IDocumentData, paragraph: IParagraph, sta?? `<p class="UniverNormal" ${style.length ? `style="${style.join('; ')};"` : ''}>${innerHtml}</p>`;switch (blockRange?.blockType) {- case 'quote':+ case DocumentBlockRangeType.QUOTE:return `<blockquote data-doc-type="quote" style="border-left: 4px solid #d0d7de; margin: 8px 0; padding: 4px 0 4px 12px; color: #57606a;">${paragraphHtml}</blockquote>`;- case 'code':+ case DocumentBlockRangeType.CODE:return `<pre data-doc-type="code-block" style="font-family: Consolas, 'Courier New', monospace; background: #f6f8fa; padding: 12px; border-radius: 6px; white-space: pre-wrap;"><code>${innerHtml.replace(/<\/?[^>]+>/g, '')}</code></pre>`;- case 'callout':+ case DocumentBlockRangeType.CALLOUT:return `<aside data-doc-type="callout" role="note" style="background: #fff8c5; border-left: 4px solid #d4a72c; padding: 8px 12px; margin: 8px 0; border-radius: 4px;"><p><span data-callout-icon="true" style="margin-right: 6px;">💡</span>${innerHtml}</p></aside>`;default:return paragraphHtml;diff --git a/packages/docs-ui/src/services/float-menu.service.ts b/packages/docs-ui/src/services/float-menu.service.tsindex 291bd8ed39..ef318c775d 100644--- a/packages/docs-ui/src/services/float-menu.service.ts+++ b/packages/docs-ui/src/services/float-menu.service.ts@@ -16,7 +16,7 @@import type { DocumentDataModel, IDisposable, ITextRangeParam, Nullable } from '@univerjs/core';import type { INodePosition, IRenderContext, IRenderModule, ITextRangeWithStyle } from '@univerjs/engine-render';-import { DataStreamTreeTokenType, deepCompare, Disposable, Inject, isInternalEditorID, IUniverInstanceService, toDisposable, UniverInstanceType } from '@univerjs/core';+import { DataStreamTreeTokenType, deepCompare, Disposable, DocumentBlockRangeType, Inject, isInternalEditorID, IUniverInstanceService, toDisposable, UniverInstanceType } from '@univerjs/core';import { DocSelectionManagerService } from '@univerjs/docs';import { ComponentManager } from '@univerjs/ui';import { FloatToolbar } from '../components/float-toolbar/FloatToolbar';@@ -143,7 +143,7 @@ function isRangeInCodeBlock(documentDataModel: DocumentDataModel, range: ITextRaconst blockRanges = documentDataModel.getBody()?.blockRanges ?? [];return blockRanges.some((blockRange) => (- blockRange.blockType === 'code' &&+ blockRange.blockType === DocumentBlockRangeType.CODE &&Math.max(range.startOffset, blockRange.startIndex) <= Math.min(range.endOffset, blockRange.endIndex)));}diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/__tests__/linebreaking.spec.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/__tests__/linebreaking.spec.tsindex 51c0076cc7..fb2f546ab9 100644--- a/packages/engine-render/src/components/docs/layout/block/paragraph/__tests__/linebreaking.spec.ts+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/__tests__/linebreaking.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { DocumentFlavor } from '@univerjs/core';+import { DocumentBlockRangeType, DocumentFlavor } from '@univerjs/core';import { describe, expect, it, vi } from 'vitest';import { lineBreaking } from '../linebreaking';import { shaping } from '../shaping';@@ -105,7 +105,7 @@ describe('linebreaking', () => {paragraphs: [paragraph],blockRanges: [{blockId: 'callout-1',- blockType: 'callout',+ blockType: DocumentBlockRangeType.CALLOUT,startIndex: 0,endIndex: 6,}],@@ -163,13 +163,13 @@ describe('linebreaking', () => {blockRanges: [{blockId: 'callout-1',- blockType: 'callout',+ blockType: DocumentBlockRangeType.CALLOUT,startIndex: 0,endIndex: 2,},{blockId: 'quote-1',- blockType: 'quote',+ blockType: DocumentBlockRangeType.QUOTE,startIndex: 3,endIndex: 5,},@@ -225,7 +225,7 @@ describe('linebreaking', () => {paragraphs: [firstParagraph, lastParagraph],blockRanges: [{blockId: 'quote-1',- blockType: 'quote',+ blockType: DocumentBlockRangeType.QUOTE,startIndex: 0,endIndex: 6,}],@@ -277,7 +277,7 @@ describe('linebreaking', () => {paragraphs: [paragraph],blockRanges: [{blockId: 'code-1',- blockType: 'code',+ blockType: DocumentBlockRangeType.CODE,startIndex: 0,endIndex: 6,}],diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.tsindex b5f6f7da48..b42c9a5109 100644--- a/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.ts+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.ts@@ -21,7 +21,16 @@ import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-noimport type { DocumentViewModel } from '../../../view-model/document-view-model';import type { ILayoutContext } from '../../tools';import type { IShapedText } from './shaping';-import { DataStreamTreeTokenType, DEFAULT_DOCUMENT_PARAGRAPH_LINE_SPACING, DEFAULT_DOCUMENT_PARAGRAPH_SPACE_ABOVE, DEFAULT_DOCUMENT_PARAGRAPH_SPACE_BELOW, DocumentFlavor, PositionedObjectLayoutType, Tools } from '@univerjs/core';+import {+ DataStreamTreeTokenType,+ DEFAULT_DOCUMENT_PARAGRAPH_LINE_SPACING,+ DEFAULT_DOCUMENT_PARAGRAPH_SPACE_ABOVE,+ DEFAULT_DOCUMENT_PARAGRAPH_SPACE_BELOW,+ DocumentBlockRangeType,+ DocumentFlavor,+ PositionedObjectLayoutType,+ Tools,+} from '@univerjs/core';import { BreakType } from '../../../../../basics/i-document-skeleton-cached';import { createSkeletonPage } from '../../model/page';import { setColumnFullState } from '../../model/section';@@ -30,9 +39,9 @@ import { dealWithBullet } from './bullet';import { layoutParagraph } from './layout-ruler';const BLOCK_LAYOUT_OUTER_SPACING_MAP = new Map([- ['callout', 34],- ['code', 32],- ['quote', 24],+ [DocumentBlockRangeType.CALLOUT, 34],+ [DocumentBlockRangeType.CODE, 32],+ [DocumentBlockRangeType.QUOTE, 24],]);function _getListLevelAncestors(diff --git a/packages/engine-render/src/components/docs/layout/model/__tests__/page.spec.ts b/packages/engine-render/src/components/docs/layout/model/__tests__/page.spec.tsindex 92cdb7932e..0f09e3ec89 100644--- a/packages/engine-render/src/components/docs/layout/model/__tests__/page.spec.ts+++ b/packages/engine-render/src/components/docs/layout/model/__tests__/page.spec.ts@@ -14,10 +14,9 @@* limitations under the License.*/-import { BooleanNumber, ColumnSeparatorType, PageOrientType, PositionedObjectLayoutType } from '@univerjs/core';+import { BooleanNumber, ColumnSeparatorType, DocumentBlockRangeType, PageOrientType, PositionedObjectLayoutType } from '@univerjs/core';import { describe, expect, it, vi } from 'vitest';import { DocumentSkeletonPageType } from '../../../../../basics/i-document-skeleton-cached';-import {createNullCellPage,createSkeletonCellPages,@@ -234,7 +233,7 @@ describe('page model', () => {const ctx = {dataModel: {getBody: () => ({- blockRanges: [{ blockId: 'callout-1', blockType: 'callout', startIndex: 10, endIndex: 14 }],+ blockRanges: [{ blockId: 'callout-1', blockType: DocumentBlockRangeType.CALLOUT, startIndex: 10, endIndex: 14 }],paragraphs: [{ startIndex: 12 }],}),},@@ -312,7 +311,7 @@ describe('page model', () => {const ctx = {dataModel: {getBody: () => ({- blockRanges: [{ blockId: 'callout-1', blockType: 'callout', startIndex: 10, endIndex: 14 }],+ blockRanges: [{ blockId: 'callout-1', blockType: DocumentBlockRangeType.CALLOUT, startIndex: 10, endIndex: 14 }],paragraphs: [{ startIndex: 12 }, { startIndex: 15 }],}),},