Skip to content

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

refactor: remove legacy files

Wenzhao Hu149e12723cee
diff --git a/packages/base-render/src/Component/Docs/Block/Paragraph/Bullet.Ruler.ts b/packages/base-render/src/Component/Docs/Block/Paragraph/Bullet.Ruler.ts
index bf53cbd5ac..d1067036de 100644
--- a/packages/base-render/src/Component/Docs/Block/Paragraph/Bullet.Ruler.ts
+++ b/packages/base-render/src/Component/Docs/Block/Paragraph/Bullet.Ruler.ts
@@ -1,10 +1,10 @@
-import { ContextBase, GlyphType, numberToListABC } from '@univerjs/core';
-import { dealWidthCustomBulletOrderedSymbol } from '../../../../Custom/UseCustom';
+import { GlyphType, numberToListABC } from '@univerjs/core';
+// import { dealWidthCustomBulletOrderedSymbol } from '../../../../Custom/UseCustom';
-export function getBulletOrderedSymbol(startIndex: number, startNumber: number, glyphType: GlyphType | string, context?: ContextBase) {
- if (!(glyphType in GlyphType)) {
- return dealWidthCustomBulletOrderedSymbol(startIndex, startNumber, glyphType as string, context); // 插件定义更多类型的bullet
- }
+export function getBulletOrderedSymbol(startIndex: number, startNumber: number, glyphType: GlyphType | string) {
+ // if (!(glyphType in GlyphType)) {
+ // return dealWidthCustomBulletOrderedSymbol(startIndex, startNumber, glyphType as string); // 插件定义更多类型的bullet
+ // }
return generateOrderedSymbol(startIndex, startNumber, glyphType as GlyphType);
}
diff --git a/packages/base-render/src/Component/Docs/Block/Paragraph/Bullet.ts b/packages/base-render/src/Component/Docs/Block/Paragraph/Bullet.ts
index 6199ea95a5..28670a0f14 100644
--- a/packages/base-render/src/Component/Docs/Block/Paragraph/Bullet.ts
+++ b/packages/base-render/src/Component/Docs/Block/Paragraph/Bullet.ts
@@ -1,190 +1,187 @@
-import { ContextBase, IBullet, ILists, INestingLevel, ITextStyle, Nullable } from '@univerjs/core';
-import { FontCache } from '../../../../Basics/FontCache';
-import { getFontStyleString } from '../../../../Basics/Tools';
-import { IDocumentSkeletonBullet } from '../../../../Basics/IDocumentSkeletonCached';
-import { IFontLocale } from '../../../../Basics/Interfaces';
-import { getBulletOrderedSymbol } from './Bullet.Ruler';
-
-export function dealWidthBullet(
- bullet?: IBullet,
- lists?: ILists,
- listLevelAncestors?: Array<Nullable<IDocumentSkeletonBullet>>,
- fontLocale?: IFontLocale,
- context?: ContextBase
-): IDocumentSkeletonBullet | undefined {
- if (!bullet || !lists) {
- return;
- }
-
- const { listId, nestingLevel = 0, textStyle } = bullet;
-
- const list = lists[listId];
-
- if (!list || !list.nestingLevel) {
- return getDefaultBulletSke(listId, listLevelAncestors?.[nestingLevel]?.startIndexItem, fontLocale);
- }
-
- const nesting = list.nestingLevel[nestingLevel];
-
- if (!nesting) {
- return getDefaultBulletSke(listId, listLevelAncestors?.[nestingLevel]?.startIndexItem, fontLocale);
- }
-
- const bulletSke = _getBulletSke(listId, nestingLevel, list.nestingLevel, listLevelAncestors, textStyle, fontLocale, context);
- return bulletSke;
-}
-
-export function getDefaultBulletSke(listId: string, startIndex: number = 1, fontLocale?: IFontLocale): IDocumentSkeletonBullet {
- return {
- listId,
- symbol: '\u25CF', // symbol 列表的内容
- ts: {
- ff: fontLocale?.fontList[0] || 'Arial',
- fs: fontLocale?.defaultFontSize || 9,
- }, // 文字样式
- startIndexItem: startIndex,
- bBox: {
- width: 8.4560546875,
- ba: 7,
- bd: -1,
- aba: 7,
- abd: -1,
- sp: -2,
- sbr: 0.5,
- sbo: 0,
- spr: 0.5,
- spo: 0,
- },
- indentFirstLine: 0,
- hanging: 21,
- indentStart: 0,
- };
-}
-
-function _getBulletSke(
- listId: string,
- nestingLevel: number,
- nestings: INestingLevel[],
- listLevelAncestors?: Array<Nullable<IDocumentSkeletonBullet>>,
- textStyleConfig?: ITextStyle,
- fontLocale?: IFontLocale,
- context?: ContextBase
-): IDocumentSkeletonBullet {
- const nesting = nestings[nestingLevel];
- const { bulletAlignment, glyphFormat, textStyle: textStyleFirst, startNumber, glyphType, glyphSymbol, indentFirstLine, hanging, indentStart } = nesting;
-
- const textStyle = { ...textStyleConfig, ...textStyleFirst };
-
- const fontStyle = getFontStyleString(textStyle, fontLocale); // 获得canvas.font格式的字体样式
-
- let symbolContent: string;
- if (glyphSymbol) {
- // 无序列表直接使用
- symbolContent = glyphSymbol;
- } else {
- // 有序列表
- symbolContent = __generateOrderedListSymbol(glyphFormat, nestingLevel, nestings, listLevelAncestors, context); // 有序列表的处理
- }
-
- const bBox = FontCache.getTextSize(symbolContent, fontStyle);
- const startIndex = listLevelAncestors?.[nestingLevel]?.startIndexItem ?? 1;
-
- return {
- listId,
- symbol: symbolContent, // symbol 列表的内容
- ts: textStyle, // 文字样式
- fontStyle, //
- startIndexItem: startIndex + 1,
- bBox,
- nestingLevel: nesting,
- bulletAlign: bulletAlignment,
- bulletType: glyphSymbol ? false : !!glyphType, // 默认是无序列表,假如glyphSymbol为空且glyphType不为空才是有序列表
- indentFirstLine,
- hanging,
- indentStart,
- };
-}
-
-function __generateOrderedListSymbol(
- glyphFormat: string,
- nestingLevel: number,
- nestings: INestingLevel[],
- listLevelAncestors?: Array<Nullable<IDocumentSkeletonBullet>>,
- context?: ContextBase
-) {
- // const indexNumber = startNumber + startIndex;
- // parse <prefix>%[nestingLevelMinusOne]<suffix>, return symbolContent
- // <w:lvl w:ilvl="0">
- // <w:start w:val="1"/>
- // <w:numFmt w:val="decimal"/>
- // <w:lvlText w:val="%1."/>
- // <w:lvlJc w:val="left"/>
- // </w:lvl>
- const glyphFormatSplit = glyphFormat.split('%');
- const prefix = glyphFormatSplit[0];
- const resultSymbol = [prefix];
- for (let i = 1; i < glyphFormatSplit.length; i++) {
- const levelAndSuffixPre = glyphFormatSplit[i];
- const { level, suffix } = ___getLevelAndSuffix(levelAndSuffixPre);
- let startIndexItem = listLevelAncestors?.[level]?.startIndexItem || 1;
- if (level !== nestingLevel && listLevelAncestors?.[level] !== null) {
- startIndexItem -= 1;
- }
- const singleSymbol = ___getSymbolByBesting(startIndexItem, nestings[level], context);
- // console.log(
- // '___getSymbolByBesting',
- // singleSymbol,
- // level,
- // suffix,
- // listLevelAncestors?.length,
- // listLevelAncestors?.[level]?.startIndexItem,
- // listLevelAncestors?.[level]?.symbol,
- // nestings
- // );
- resultSymbol.push(singleSymbol, suffix);
- }
- return resultSymbol.join('');
-}
-
-function ___getSymbolByBesting(startIndex: number = 1, nesting: INestingLevel, context?: ContextBase) {
- const { startNumber, glyphType, glyphSymbol } = nesting;
-
- if (glyphSymbol) {
- // 无序列表直接使用
- return glyphSymbol;
- }
-
- if (!glyphType) {
- return '\u25CF';
- }
-
- return getBulletOrderedSymbol(startIndex, startNumber, glyphType, context);
-}
-
-function ___getLevelAndSuffix(levelAndSuffixPre: string) {
- if (levelAndSuffixPre === '') {
- return {
- level: 0,
- suffix: '',
- };
- }
-
- const levelAndSuffixPreSpit = levelAndSuffixPre.split('');
- let level = '';
- let suffix = '';
- let isSuffixState = false;
- const digitReg = /[0-9]/g;
- levelAndSuffixPreSpit.forEach((w: string) => {
- if (!isSuffixState && digitReg.test(`${level}${w}`)) {
- level += w;
- } else {
- isSuffixState = true;
- suffix += w;
- }
- });
-
- return {
- level: parseInt(level) - 1,
- suffix,
- };
-}
+import { IBullet, ILists, INestingLevel, ITextStyle, Nullable } from '@univerjs/core';
+import { FontCache } from '../../../../Basics/FontCache';
+import { getFontStyleString } from '../../../../Basics/Tools';
+import { IDocumentSkeletonBullet } from '../../../../Basics/IDocumentSkeletonCached';
+import { IFontLocale } from '../../../../Basics/Interfaces';
+import { getBulletOrderedSymbol } from './Bullet.Ruler';
+
+export function dealWidthBullet(
+ bullet?: IBullet,
+ lists?: ILists,
+ listLevelAncestors?: Array<Nullable<IDocumentSkeletonBullet>>,
+ fontLocale?: IFontLocale,
+): IDocumentSkeletonBullet | undefined {
+ if (!bullet || !lists) {
+ return;
+ }
+
+ const { listId, nestingLevel = 0, textStyle } = bullet;
+
+ const list = lists[listId];
+
+ if (!list || !list.nestingLevel) {
+ return getDefaultBulletSke(listId, listLevelAncestors?.[nestingLevel]?.startIndexItem, fontLocale);
+ }
+
+ const nesting = list.nestingLevel[nestingLevel];
+
+ if (!nesting) {
+ return getDefaultBulletSke(listId, listLevelAncestors?.[nestingLevel]?.startIndexItem, fontLocale);
+ }
+
+ const bulletSke = _getBulletSke(listId, nestingLevel, list.nestingLevel, listLevelAncestors, textStyle, fontLocale, context);
+ return bulletSke;
+}
+
+export function getDefaultBulletSke(listId: string, startIndex: number = 1, fontLocale?: IFontLocale): IDocumentSkeletonBullet {
+ return {
+ listId,
+ symbol: '\u25CF', // symbol 列表的内容
+ ts: {
+ ff: fontLocale?.fontList[0] || 'Arial',
+ fs: fontLocale?.defaultFontSize || 9,
+ }, // 文字样式
+ startIndexItem: startIndex,
+ bBox: {
+ width: 8.4560546875,
+ ba: 7,
+ bd: -1,
+ aba: 7,
+ abd: -1,
+ sp: -2,
+ sbr: 0.5,
+ sbo: 0,
+ spr: 0.5,
+ spo: 0,
+ },
+ indentFirstLine: 0,
+ hanging: 21,
+ indentStart: 0,
+ };
+}
+
+function _getBulletSke(
+ listId: string,
+ nestingLevel: number,
+ nestings: INestingLevel[],
+ listLevelAncestors?: Array<Nullable<IDocumentSkeletonBullet>>,
+ textStyleConfig?: ITextStyle,
+ fontLocale?: IFontLocale,
+): IDocumentSkeletonBullet {
+ const nesting = nestings[nestingLevel];
+ const { bulletAlignment, glyphFormat, textStyle: textStyleFirst, startNumber, glyphType, glyphSymbol, indentFirstLine, hanging, indentStart } = nesting;
+
+ const textStyle = { ...textStyleConfig, ...textStyleFirst };
+
+ const fontStyle = getFontStyleString(textStyle, fontLocale); // 获得canvas.font格式的字体样式
+
+ let symbolContent: string;
+ if (glyphSymbol) {
+ // 无序列表直接使用
+ symbolContent = glyphSymbol;
+ } else {
+ // 有序列表
+ symbolContent = __generateOrderedListSymbol(glyphFormat, nestingLevel, nestings, listLevelAncestors, context); // 有序列表的处理
+ }
+
+ const bBox = FontCache.getTextSize(symbolContent, fontStyle);
+ const startIndex = listLevelAncestors?.[nestingLevel]?.startIndexItem ?? 1;
+
+ return {
+ listId,
+ symbol: symbolContent, // symbol 列表的内容
+ ts: textStyle, // 文字样式
+ fontStyle, //
+ startIndexItem: startIndex + 1,
+ bBox,
+ nestingLevel: nesting,
+ bulletAlign: bulletAlignment,
+ bulletType: glyphSymbol ? false : !!glyphType, // 默认是无序列表,假如glyphSymbol为空且glyphType不为空才是有序列表
+ indentFirstLine,
+ hanging,
+ indentStart,
+ };
+}
+
+function __generateOrderedListSymbol(
+ glyphFormat: string,
+ nestingLevel: number,
+ nestings: INestingLevel[],
+ listLevelAncestors?: Array<Nullable<IDocumentSkeletonBullet>>,
+) {
+ // const indexNumber = startNumber + startIndex;
+ // parse <prefix>%[nestingLevelMinusOne]<suffix>, return symbolContent
+ // <w:lvl w:ilvl="0">
+ // <w:start w:val="1"/>
+ // <w:numFmt w:val="decimal"/>
+ // <w:lvlText w:val="%1."/>
+ // <w:lvlJc w:val="left"/>
+ // </w:lvl>
+ const glyphFormatSplit = glyphFormat.split('%');
+ const prefix = glyphFormatSplit[0];
+ const resultSymbol = [prefix];
+ for (let i = 1; i < glyphFormatSplit.length; i++) {
+ const levelAndSuffixPre = glyphFormatSplit[i];
+ const { level, suffix } = ___getLevelAndSuffix(levelAndSuffixPre);
+ let startIndexItem = listLevelAncestors?.[level]?.startIndexItem || 1;
+ if (level !== nestingLevel && listLevelAncestors?.[level] !== null) {
+ startIndexItem -= 1;
+ }
+ const singleSymbol = ___getSymbolByBesting(startIndexItem, nestings[level], context);
+ // console.log(
+ // '___getSymbolByBesting',
+ // singleSymbol,
+ // level,
+ // suffix,
+ // listLevelAncestors?.length,
+ // listLevelAncestors?.[level]?.startIndexItem,
+ // listLevelAncestors?.[level]?.symbol,
+ // nestings
+ // );
+ resultSymbol.push(singleSymbol, suffix);
+ }
+ return resultSymbol.join('');
+}
+
+function ___getSymbolByBesting(startIndex: number = 1, nesting: INestingLevel) {
+ const { startNumber, glyphType, glyphSymbol } = nesting;
+
+ if (glyphSymbol) {
+ // 无序列表直接使用
+ return glyphSymbol;
+ }
+
+ if (!glyphType) {
+ return '\u25CF';
+ }
+
+ return getBulletOrderedSymbol(startIndex, startNumber, glyphType, context);
+}
+
+function ___getLevelAndSuffix(levelAndSuffixPre: string) {
+ if (levelAndSuffixPre === '') {
+ return {
+ level: 0,
+ suffix: '',
+ };
+ }
+
+ const levelAndSuffixPreSpit = levelAndSuffixPre.split('');
+ let level = '';
+ let suffix = '';
+ let isSuffixState = false;
+ const digitReg = /[0-9]/g;
+ levelAndSuffixPreSpit.forEach((w: string) => {
+ if (!isSuffixState && digitReg.test(`${level}${w}`)) {
+ level += w;
+ } else {
+ isSuffixState = true;
+ suffix += w;
+ }
+ });
+
+ return {
+ level: parseInt(level) - 1,
+ suffix,
+ };
+}
diff --git a/packages/base-render/src/Component/Docs/Block/Paragraph/Paragraph.ts b/packages/base-render/src/Component/Docs/Block/Paragraph/Paragraph.ts
index adaa73296d..534e723f24 100644
--- a/packages/base-render/src/Component/Docs/Block/Paragraph/Paragraph.ts
+++ b/packages/base-render/src/Component/Docs/Block/Paragraph/Paragraph.ts
@@ -1,319 +1,317 @@
-import {
- IBullet,
- IDrawing,
- IDrawings,
- Nullable,
- PositionedObjectLayoutType,
- ContextBase,
- DataStreamTreeNode,
- GridType,
- HorizontalAlign,
- BooleanNumber,
- DataStreamTreeTokenType,
- ICustomBlock,
- DocumentBodyModel,
-} from '@univerjs/core';
-import { dealWidthBullet } from './Bullet';
-import { dealWidthInlineDrawing } from './InlineDrawing';
-
-import { clearFontCreateConfigCache, getCharSpaceApply, getFontCreateConfig, getLastNotFullColumnInfo, getSpanGroupWidth, lineIterator } from '../../Common/Tools';
-// eslint-disable-next-line import/no-cycle
-import { createSkeletonPage } from '../../Common/Page';
-import { setColumnFullState } from '../../Common/Section';
-
-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 { createSkeletonTabSpan, createSkeletonWordSpan } from '../../Common/Span';
-
-// eslint-disable-next-line max-lines-per-function
-export function dealWidthParagraph(
- bodyModel: DocumentBodyModel,
- paragraphNode: DataStreamTreeNode,
- curPage: IDocumentSkeletonPage,
- sectionBreakConfig: ISectionBreakConfig,
- skeletonResourceReference: ISkeletonResourceReference,
- context?: ContextBase
-): IDocumentSkeletonPage[] {
- const {
- gridType = GridType.LINES,
- charSpace = 0,
- defaultTabStop = 10.5,
-
- pageSize = {
- width: Infinity,
- height: Infinity,
- },
-
- marginRight = 0,
- marginLeft = 0,
-
- lists,
- drawings = {},
- fontLocale,
- } = sectionBreakConfig;
-
- const { endIndex, startIndex, content = '', blocks = [] } = paragraphNode;
-
- const paragraph = bodyModel.getParagraph(endIndex) || { startIndex: 0 };
-
- const { paragraphStyle = {}, bullet } = paragraph;
-
- // const paragraphAffectSkeDrawings = _changeDrawingToSkeletonFormat(drawingIds, drawings);
-
- // curPage.skeDrawings = paragraphAffectSkeDrawings;
-
- const { skeHeaders, skeFooters, skeListLevel, drawingAnchor } = skeletonResourceReference;
-
- // const pageWidth = pageSize.w || Infinity;
- // const pageHeight = pageSize.h || Infinity;
-
- // const headerAndFooterAffectSkeDrawings = new Map([
- // ...(skeHeaders?.get(curPage.headerId)?.get(pageWidth)?.skeDrawings || []),
- // ...(skeFooters?.get(curPage.footerId)?.get(pageWidth)?.skeDrawings || []),
- // ]);
-
- // curPage.skeDrawings = affectSkeDrawings; // 加入本段落的对象
-
- // const pages = [curPage];
- // let lastPage = curPage;
-
- // if (pageSize.h === Infinity) {
- // // 无需分页的情况,适合表格单元格或者类似notion的block布局
- // }
-
- // if (curPage.sections.length > 0) {
- // // 处理接上一页的情况
- // let columnHeight = _getColumnHeight(curPage);
- // curPage.skeDrawings;
-
- // return [];
- // }
-
- const paragraphAffectSkeDrawings: Map<string, IDocumentSkeletonDrawing> = new Map();
-
- const paragraphConfig: IParagraphConfig = {
- paragraphIndex: endIndex,
- paragraphStyle,
- paragraphAffectSkeDrawings,
- skeHeaders,
- skeFooters,
- drawingAnchor,
- };
-
- const listLevelAncestors = _getListLevelAncestors(bullet, skeListLevel); // 取得列表所有level的缓存
- const bulletSkeleton = dealWidthBullet(bullet, lists, listLevelAncestors, fontLocale, context); // 生成bullet
- _updateListLevelAncestors(bullet, bulletSkeleton, skeListLevel); // 更新最新的level缓存列表
- paragraphConfig.bulletSkeleton = bulletSkeleton;
-
- const { horizontalAlign = HorizontalAlign.UNSPECIFIED, snapToGrid = BooleanNumber.TRUE } = paragraphStyle;
-
- let allPages: IDocumentSkeletonPage[] = [curPage];
-
- const customBlockCache = new Map<number, Nullable<ICustomBlock>>();
- for (let i = 0, len = blocks.length; i < len; i++) {
- const charIndex = blocks[i];
- const customBlock = bodyModel.getCustomBlock(charIndex);
- if (customBlock == null) {
- continue;
- }
- customBlockCache.set(charIndex, customBlock);
- const blockId = customBlock.blockId;
- const drawingOrigin = drawings[blockId];
- if (drawingOrigin.layoutType !== PositionedObjectLayoutType.INLINE) {
- paragraphAffectSkeDrawings.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));
- }
- }
-
- clearFontCreateConfigCache();
-
- for (let i = 0, len = content.length; i < len; i++) {
- const charIndex = i + startIndex;
- const char = content[i];
-
- const fontCreateConfig = getFontCreateConfig(i, bodyModel, paragraphNode, sectionBreakConfig, paragraphStyle);
-
- 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);
- continue;
- } else if (char === DataStreamTreeTokenType.CUSTOM_BLOCK) {
- let customBlock = customBlockCache.get(charIndex);
- if (customBlock == null) {
- customBlock = bodyModel.getCustomBlock(charIndex);
- }
- if (customBlock != null) {
- const blockId = customBlock.blockId;
- const drawingOrigin = drawings[blockId];
- if (drawingOrigin.layoutType === PositionedObjectLayoutType.INLINE) {
- allPages = dealWidthInlineDrawing(drawingOrigin, sectionBreakConfig, allPages, paragraphConfig, fontLocale);
- }
- }
- } else if (char === DataStreamTreeTokenType.PAGE_BREAK) {
- allPages.push(createSkeletonPage(sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(allPages[allPages.length - 1]), BreakType.PAGE));
- paragraphAffectSkeDrawings.clear();
- } 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 {
- allPages.push(createSkeletonPage(sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(lastPage), BreakType.COLUMN));
- }
- }
-
- const paragraphStart = i === 0;
- const languageHandlerResult = composeCharForLanguage(char, i, content, bodyModel, paragraphNode, sectionBreakConfig, paragraphStyle); // 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);
- }
-
- lineIterator(allPages, (line: IDocumentSkeletonLine) => {
- horizontalAlignHandler(line, horizontalAlign);
- });
-
- return allPages;
-}
-
-function _getListLevelAncestors(bullet?: IBullet, listLevel?: Map<string, IDocumentSkeletonBullet[]>): Array<Nullable<IDocumentSkeletonBullet>> | undefined {
- if (!bullet || !listLevel) {
- return;
- }
-
- const { listId, nestingLevel } = bullet;
-
- const sameList = listLevel?.get(listId);
-
- let level = nestingLevel;
-
- if (level < 0) {
- level = 0;
- }
-
- const listLevelAncestors: Array<Nullable<IDocumentSkeletonBullet>> = [];
-
- for (let i = level; i >= 0; i--) {
- const bs = sameList?.[i];
- listLevelAncestors[i] = bs || null;
- }
-
- // console.log('SymbolByBesting', sameList, listLevelAncestors, level, listId, listLevel);
-
- return listLevelAncestors;
-}
-
-function _updateListLevelAncestors(bullet?: IBullet, bulletSkeleton?: IDocumentSkeletonBullet, listLevel?: Map<string, IDocumentSkeletonBullet[]>) {
- if (!bullet || !bulletSkeleton) {
- return;
- }
-
- const { listId, nestingLevel } = bullet;
-
- const cacheItem: IDocumentSkeletonBullet[] = [...(listLevel?.get(listId) || [])];
-
- // [[nestingLevel, bulletSkeleton]];
-
- cacheItem[nestingLevel] = bulletSkeleton;
-
- cacheItem.splice(nestingLevel + 1); // 文档自上而下渲染,如果一个level被更新,则它以下的level数据的startIndex就要重置
-
- listLevel?.set(listId, cacheItem);
-}
-
-function _changeDrawingToSkeletonFormat(drawingIds: string[], drawings: IDrawings): Map<string, IDocumentSkeletonDrawing> {
- const skeDrawings: Map<string, IDocumentSkeletonDrawing> = new Map();
- drawingIds.forEach((objectId) => {
- const drawingOrigin = drawings[objectId];
- drawingOrigin && skeDrawings.set(objectId, _getDrawingSkeletonFormat(drawingOrigin));
- });
- return skeDrawings;
-}
-
-function _getDrawingSkeletonFormat(drawingOrigin: IDrawing) {
- const objectId = drawingOrigin.objectId;
- return {
- objectId,
- aLeft: 0,
- aTop: 0,
- width: 0,
- height: 0,
- angle: 0,
- initialState: false,
- drawingOrigin,
- };
-}
-
-function _checkAndPush(pages: IDocumentSkeletonPage[], currentPages: IDocumentSkeletonPage[]) {
- const curLast = pages.slice(-1)[0];
- const newFirst = currentPages[0];
- if (curLast === newFirst) {
- if (currentPages.length === 1) {
- return curLast;
- }
- currentPages.shift();
- }
-
- pages.push(...currentPages);
-
- return pages.slice(-1)[0];
-}
-
-// function _getAllSkeDrawings(curPage: IDocumentSkeletonPage, pageWidth: number, skeletonResourceReference: ISkeletonResourceReference, paragraphAffectSkeDrawings: Map<string, IDocumentSkeletonDrawing>) {
-// const { skeHeaders, skeFooters, skeListLevel } = skeletonResourceReference;
-// const affectAllSkeDrawings = new Map([
-// ...(skeHeaders?.get(curPage.headerId)?.get(pageWidth)?.skeDrawings || []),
-// ...(skeFooters?.get(curPage.footerId)?.get(pageWidth)?.skeDrawings || []),
-// ...paragraphAffectSkeDrawings,
-// ]);
-// }
-
-function _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 */
- }
- }
-}
+import {
+ IBullet,
+ IDrawing,
+ IDrawings,
+ Nullable,
+ PositionedObjectLayoutType,
+ DataStreamTreeNode,
+ GridType,
+ HorizontalAlign,
+ BooleanNumber,
+ DataStreamTreeTokenType,
+ ICustomBlock,
+ DocumentBodyModel,
+} from '@univerjs/core';
+import { dealWidthBullet } from './Bullet';
+import { dealWidthInlineDrawing } from './InlineDrawing';
+
+import { clearFontCreateConfigCache, getCharSpaceApply, getFontCreateConfig, getLastNotFullColumnInfo, getSpanGroupWidth, lineIterator } from '../../Common/Tools';
+// eslint-disable-next-line import/no-cycle
+import { createSkeletonPage } from '../../Common/Page';
+import { setColumnFullState } from '../../Common/Section';
+
+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 { createSkeletonTabSpan, createSkeletonWordSpan } from '../../Common/Span';
+
+// eslint-disable-next-line max-lines-per-function
+export function dealWidthParagraph(
+ bodyModel: DocumentBodyModel,
+ paragraphNode: DataStreamTreeNode,
+ curPage: IDocumentSkeletonPage,
+ sectionBreakConfig: ISectionBreakConfig,
+ skeletonResourceReference: ISkeletonResourceReference,
+): IDocumentSkeletonPage[] {
+ const {
+ gridType = GridType.LINES,
+ charSpace = 0,
+ defaultTabStop = 10.5,
+
+ pageSize = {
+ width: Infinity,
+ height: Infinity,
+ },
+
+ marginRight = 0,
+ marginLeft = 0,
+
+ lists,
+ drawings = {},
+ fontLocale,
+ } = sectionBreakConfig;
+
+ const { endIndex, startIndex, content = '', blocks = [] } = paragraphNode;
+
+ const paragraph = bodyModel.getParagraph(endIndex) || { startIndex: 0 };
+
+ const { paragraphStyle = {}, bullet } = paragraph;
+
+ // const paragraphAffectSkeDrawings = _changeDrawingToSkeletonFormat(drawingIds, drawings);
+
+ // curPage.skeDrawings = paragraphAffectSkeDrawings;
+
+ const { skeHeaders, skeFooters, skeListLevel, drawingAnchor } = skeletonResourceReference;
+
+ // const pageWidth = pageSize.w || Infinity;
+ // const pageHeight = pageSize.h || Infinity;
+
+ // const headerAndFooterAffectSkeDrawings = new Map([
+ // ...(skeHeaders?.get(curPage.headerId)?.get(pageWidth)?.skeDrawings || []),
+ // ...(skeFooters?.get(curPage.footerId)?.get(pageWidth)?.skeDrawings || []),
+ // ]);
+
+ // curPage.skeDrawings = affectSkeDrawings; // 加入本段落的对象
+
+ // const pages = [curPage];
+ // let lastPage = curPage;
+
+ // if (pageSize.h === Infinity) {
+ // // 无需分页的情况,适合表格单元格或者类似notion的block布局
+ // }
+
+ // if (curPage.sections.length > 0) {
+ // // 处理接上一页的情况
+ // let columnHeight = _getColumnHeight(curPage);
+ // curPage.skeDrawings;
+
+ // return [];
+ // }
+
+ const paragraphAffectSkeDrawings: Map<string, IDocumentSkeletonDrawing> = new Map();
+
+ const paragraphConfig: IParagraphConfig = {
+ paragraphIndex: endIndex,
+ paragraphStyle,
+ paragraphAffectSkeDrawings,
+ skeHeaders,
+ skeFooters,
+ drawingAnchor,
+ };
+
+ const listLevelAncestors = _getListLevelAncestors(bullet, skeListLevel); // 取得列表所有level的缓存
+ const bulletSkeleton = dealWidthBullet(bullet, lists, listLevelAncestors, fontLocale); // 生成bullet
+ _updateListLevelAncestors(bullet, bulletSkeleton, skeListLevel); // 更新最新的level缓存列表
+ paragraphConfig.bulletSkeleton = bulletSkeleton;
+
+ const { horizontalAlign = HorizontalAlign.UNSPECIFIED, snapToGrid = BooleanNumber.TRUE } = paragraphStyle;
+
+ let allPages: IDocumentSkeletonPage[] = [curPage];
+
+ const customBlockCache = new Map<number, Nullable<ICustomBlock>>();
+ for (let i = 0, len = blocks.length; i < len; i++) {
+ const charIndex = blocks[i];
+ const customBlock = bodyModel.getCustomBlock(charIndex);
+ if (customBlock == null) {
+ continue;
+ }
+ customBlockCache.set(charIndex, customBlock);
+ const blockId = customBlock.blockId;
+ const drawingOrigin = drawings[blockId];
+ if (drawingOrigin.layoutType !== PositionedObjectLayoutType.INLINE) {
+ paragraphAffectSkeDrawings.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));
+ }
+ }
+
+ clearFontCreateConfigCache();
+
+ for (let i = 0, len = content.length; i < len; i++) {
+ const charIndex = i + startIndex;
+ const char = content[i];
+
+ const fontCreateConfig = getFontCreateConfig(i, bodyModel, paragraphNode, sectionBreakConfig, paragraphStyle);
+
+ 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);
+ continue;
+ } else if (char === DataStreamTreeTokenType.CUSTOM_BLOCK) {
+ let customBlock = customBlockCache.get(charIndex);
+ if (customBlock == null) {
+ customBlock = bodyModel.getCustomBlock(charIndex);
+ }
+ if (customBlock != null) {
+ const blockId = customBlock.blockId;
+ const drawingOrigin = drawings[blockId];
+ if (drawingOrigin.layoutType === PositionedObjectLayoutType.INLINE) {
+ allPages = dealWidthInlineDrawing(drawingOrigin, sectionBreakConfig, allPages, paragraphConfig, fontLocale);
+ }
+ }
+ } else if (char === DataStreamTreeTokenType.PAGE_BREAK) {
+ allPages.push(createSkeletonPage(sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(allPages[allPages.length - 1]), BreakType.PAGE));
+ paragraphAffectSkeDrawings.clear();
+ } 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 {
+ allPages.push(createSkeletonPage(sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(lastPage), BreakType.COLUMN));
+ }
+ }
+
+ const paragraphStart = i === 0;
+ const languageHandlerResult = composeCharForLanguage(char, i, content, bodyModel, paragraphNode, sectionBreakConfig, paragraphStyle); // 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);
+ }
+
+ lineIterator(allPages, (line: IDocumentSkeletonLine) => {
+ horizontalAlignHandler(line, horizontalAlign);
+ });
+
+ return allPages;
+}
+
+function _getListLevelAncestors(bullet?: IBullet, listLevel?: Map<string, IDocumentSkeletonBullet[]>): Array<Nullable<IDocumentSkeletonBullet>> | undefined {
+ if (!bullet || !listLevel) {
+ return;
+ }
+
+ const { listId, nestingLevel } = bullet;
+
+ const sameList = listLevel?.get(listId);
+
+ let level = nestingLevel;
+
+ if (level < 0) {
+ level = 0;
+ }
+
+ const listLevelAncestors: Array<Nullable<IDocumentSkeletonBullet>> = [];
+
+ for (let i = level; i >= 0; i--) {
+ const bs = sameList?.[i];
+ listLevelAncestors[i] = bs || null;
+ }
+
+ // console.log('SymbolByBesting', sameList, listLevelAncestors, level, listId, listLevel);
+
+ return listLevelAncestors;
+}
+
+function _updateListLevelAncestors(bullet?: IBullet, bulletSkeleton?: IDocumentSkeletonBullet, listLevel?: Map<string, IDocumentSkeletonBullet[]>) {
+ if (!bullet || !bulletSkeleton) {
+ return;
+ }
+
+ const { listId, nestingLevel } = bullet;
+
+ const cacheItem: IDocumentSkeletonBullet[] = [...(listLevel?.get(listId) || [])];
+
+ // [[nestingLevel, bulletSkeleton]];
+
+ cacheItem[nestingLevel] = bulletSkeleton;
+
+ cacheItem.splice(nestingLevel + 1); // 文档自上而下渲染,如果一个level被更新,则它以下的level数据的startIndex就要重置
+
+ listLevel?.set(listId, cacheItem);
+}
+
+function _changeDrawingToSkeletonFormat(drawingIds: string[], drawings: IDrawings): Map<string, IDocumentSkeletonDrawing> {
+ const skeDrawings: Map<string, IDocumentSkeletonDrawing> = new Map();
+ drawingIds.forEach((objectId) => {
+ const drawingOrigin = drawings[objectId];
+ drawingOrigin && skeDrawings.set(objectId, _getDrawingSkeletonFormat(drawingOrigin));
+ });
+ return skeDrawings;
+}
+
+function _getDrawingSkeletonFormat(drawingOrigin: IDrawing) {
+ const objectId = drawingOrigin.objectId;
+ return {
+ objectId,
+ aLeft: 0,
+ aTop: 0,
+ width: 0,
+ height: 0,
+ angle: 0,
+ initialState: false,
+ drawingOrigin,
+ };
+}
+
+function _checkAndPush(pages: IDocumentSkeletonPage[], currentPages: IDocumentSkeletonPage[]) {
+ const curLast = pages.slice(-1)[0];
+ const newFirst = currentPages[0];
+ if (curLast === newFirst) {
+ if (currentPages.length === 1) {
+ return curLast;
+ }
+ currentPages.shift();
+ }
+
+ pages.push(...currentPages);
+
+ return pages.slice(-1)[0];
+}
+
+// function _getAllSkeDrawings(curPage: IDocumentSkeletonPage, pageWidth: number, skeletonResourceReference: ISkeletonResourceReference, paragraphAffectSkeDrawings: Map<string, IDocumentSkeletonDrawing>) {
+// const { skeHeaders, skeFooters, skeListLevel } = skeletonResourceReference;
+// const affectAllSkeDrawings = new Map([
+// ...(skeHeaders?.get(curPage.headerId)?.get(pageWidth)?.skeDrawings || []),
+// ...(skeFooters?.get(curPage.footerId)?.get(pageWidth)?.skeDrawings || []),
+// ...paragraphAffectSkeDrawings,
+// ]);
+// }
+
+function _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 */
+ }
+ }
+}
\ No newline at end of file
diff --git a/packages/base-render/src/Component/Docs/Block/Section.ts b/packages/base-render/src/Component/Docs/Block/Section.ts
index 83bb25756e..a6d463af9a 100644
--- a/packages/base-render/src/Component/Docs/Block/Section.ts
+++ b/packages/base-render/src/Component/Docs/Block/Section.ts
@@ -1,4 +1,4 @@
-import { DataStreamTreeNodeType, ContextBase, DataStreamTreeNode, DocumentBodyModel } from '@univerjs/core';
+import { DataStreamTreeNodeType, DataStreamTreeNode, DocumentBodyModel } from '@univerjs/core';
// eslint-disable-next-line import/no-cycle
import { dealWidthParagraph } from './Paragraph';
import { dealWithBlockError } from './BlockError';
@@ -12,7 +12,6 @@ export function dealWithSections(
sectionBreakConfig: ISectionBreakConfig,
skeletonResourceReference: ISkeletonResourceReference,
preRenderedBlockIdMap?: Map<string, boolean>,
- context?: ContextBase
) {
const allCurrentSkeletonPages: IDocumentSkeletonPage[] = [];
const renderedBlockIdMap = new Map<string, boolean>();
@@ -28,7 +27,7 @@ export function dealWithSections(
}
if (node.nodeType === DataStreamTreeNodeType.PARAGRAPH) {
// Paragraph 段落
- skeletonPages = dealWidthParagraph(bodyModel, node, currentPageCache, sectionBreakConfig, skeletonResourceReference, context);
+ skeletonPages = dealWidthParagraph(bodyModel, node, currentPageCache, sectionBreakConfig, skeletonResourceReference);
} else if (node.nodeType === DataStreamTreeNodeType.TABLE) {
// Table 表格
}
diff --git a/packages/base-render/src/Custom/UseCustom.ts b/packages/base-render/src/Custom/UseCustom.ts
index 9eaa0df260..f9c95f6800 100644
--- a/packages/base-render/src/Custom/UseCustom.ts
+++ b/packages/base-render/src/Custom/UseCustom.ts
@@ -1,4 +1,3 @@
-import { ContextBase } from '@univerjs/core';
import { BlockPlugin } from './BlockPlugin';
import { BulletPlugin } from './BulletPlugin';
import { IDocumentSkeletonPage, ISkeletonResourceReference } from '../Basics/IDocumentSkeletonCached';
@@ -13,7 +12,6 @@ export function dealWidthCustomBlock(
curPage: IDocumentSkeletonPage,
sectionBreakConfig: ISectionBreakConfig,
skeletonResourceReference: ISkeletonResourceReference,
- context?: ContextBase
) {
if (!context) {
return [];
@@ -25,7 +23,7 @@ export function dealWidthCustomBlock(
return [];
}
-export function dealWidthCustomBulletOrderedSymbol(startIndex: number, startNumber: number, glyphType: string, context?: ContextBase) {
+export function dealWidthCustomBulletOrderedSymbol(startIndex: number, startNumber: number, glyphType: string) {
if (!context) {
return '';
}
diff --git a/packages/core/src/Basics/Context.ts b/packages/core/src/Basics/Context.ts
deleted file mode 100644
index c3553100aa..0000000000
--- a/packages/core/src/Basics/Context.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import { IUniverData } from '../Types/Interfaces/IUniverData';
-import { Locale } from '../Shared/Locale';
-import { Tools } from '../Shared/Tools';
-import { ContextBase } from './ContextBase';
-
-/**
- * univer context
- */
-export class Context extends ContextBase {
- /** @deprecated get LocaleService from DI system instead */
- protected _locale: Locale;
-
- private _univerId: string;
-
- constructor(univerData: Partial<IUniverData> = {}) {
- super();
-
- this._locale = new Locale();
-
- // Initialize internationalization
- this._locale.initialize(univerData.locale);
-
- if (univerData.id == null || univerData.id.length === 0) {
- this._univerId = Tools.generateRandomId(10);
- } else {
- this._univerId = univerData.id;
- }
- }
-
- /** @deprecated get LocaleService from DI system instead */
- getLocale(): Locale {
- return this._locale;
- }
-
- getUniverId() {
- return this._univerId;
- }
-
- protected _setObserver(): void {}
-}
\ No newline at end of file
diff --git a/packages/core/src/Basics/ContextBase.ts b/packages/core/src/Basics/ContextBase.ts
deleted file mode 100644
index fef2b88cf4..0000000000
--- a/packages/core/src/Basics/ContextBase.ts
+++ /dev/null
@@ -1,89 +0,0 @@
-import { CommandManager } from '../Command/CommandManager';
-import { UndoManager } from '../Command/UndoManager';
-import { ObservableHooks, ObserverManager } from '../Observer';
-import { HooksManager } from '../Observer/HooksManager';
-import { Univer } from './Univer';
-import { PluginManager } from '../Plugin/PluginManager';
-import { Nullable } from '../Shared';
-import { Environment } from './Environment';
-
-/**
- * Core context, mount important instances, managers
- */
-export abstract class ContextBase {
- protected _commandManager: CommandManager;
-
- protected _pluginManager: PluginManager;
-
- protected _environment: Environment;
-
- protected _hooksManager: HooksManager;
-
- protected _undoManager: UndoManager;
-
- protected _observerManager: ObserverManager;
-
- protected _univer: Univer;
-
- constructor() {
- this._hooksManager = new HooksManager();
- this._pluginManager = new PluginManager(this);
- this._environment = new Environment();
- this._observerManager = new ObserverManager();
- this._initialize();
- }
-
- /**
- * This is a temporary hack before we completely remove Context.
- */
- UNSAFE_setObserverManager(observerManager: ObserverManager): void {
- this._observerManager = observerManager;
- }
-
- onUniver(univer: Univer): void {
- const globalContext = univer.getGlobalContext();
- this._univer = univer;
-
- // TODO: huwenzhao: 这里的意思其实就是业务 Context 里面要复用上层的 undoManager 和 CommandManager
- this._undoManager = globalContext.getUndoManager();
- this._commandManager = globalContext.getCommandManager();
- }
-
- getHook<T>(path: string): Nullable<ObservableHooks<T>> {
- return this._hooksManager.getHooks<T>(path);
- }
-
- getHooksManager(): HooksManager {
- return this._hooksManager;
- }
-
- getObserverManager(): ObserverManager {
- return this._observerManager;
- }
-
- /** @deprecated DI */
- getPluginManager(): PluginManager {
- return this._pluginManager;
- }
-
- /** @deprecated DI */
- getUndoManager(): UndoManager {
- return this._undoManager;
- }
-
- /** @deprecated DI */
- getCommandManager(): CommandManager {
- return this._commandManager;
- }
-
- getUniver(): Univer {
- return this._univer;
- }
-
- protected _initialize(): void {
- this._undoManager = new UndoManager();
- this._commandManager = new CommandManager(this);
- }
-
- protected abstract _setObserver(): void;
-}
\ No newline at end of file
diff --git a/packages/core/src/Command/CommandManager.ts b/packages/core/src/Command/CommandManager.ts
index 0a51e580d9..6c513df9ec 100644
--- a/packages/core/src/Command/CommandManager.ts
+++ b/packages/core/src/Command/CommandManager.ts
@@ -1,5 +1,5 @@
+import { Inject } from '@wendellhu/redi';
import { Class } from '../Shared/Types';
-import { ContextBase } from '../Basics/ContextBase';
import { ActionBase, IActionData } from './ActionBase';
import { CommandObservers } from './CommandObservers';
import { ActionObservers } from './ActionObservers';
@@ -7,7 +7,6 @@ import { CommandInjectorObservers } from './CommandInjectorObservers';
import { UndoManager } from './UndoManager';
import { ActionExtensionManager } from './ActionExtensionManager';
import { Command } from './Command';
-import { Inject } from '@wendellhu/redi';
/**
* Manage command
@@ -87,4 +86,4 @@ export class CommandManager {
}
}
-CommandManager.staticInitialize();
\ No newline at end of file
+CommandManager.staticInitialize();
diff --git a/packages/core/src/Plugin/PluginManager.ts b/packages/core/src/Plugin/PluginManager.ts
deleted file mode 100644
index 8bd71e6598..0000000000
--- a/packages/core/src/Plugin/PluginManager.ts
+++ /dev/null
@@ -1,77 +0,0 @@
-import { BasePlugin } from './Plugin';
-import { Nullable } from '../Shared';
-import { ContextBase } from '../Basics/ContextBase';
-
-/**
- * Provides APIs to initialize, install, and uninstall plugins
- */
-export class PluginManager {
- protected _context: ContextBase;
-
- protected _plugins: BasePlugin[];
-
- protected _initialized: boolean;
-
- constructor(context: ContextBase, plugins: BasePlugin[] = []) {
- this._context = context;
- this._plugins = [];
- this._initialized = true;
- this._plugins = this._plugins.concat(plugins);
- this._initialize();
- }
-
- install(plugin: BasePlugin) {
- const { _plugins } = this;
- _plugins.push(plugin);
- plugin.onCreate(this._context);
- plugin.onMounted(this._context);
- }
-
- uninstall(name: string) {
- const { _plugins } = this;
- const index = _plugins.findIndex((item) => item.getPluginName() === name);
- if (index > -1) {
- const plugin = _plugins.splice(index, 1)[0];
- if (plugin) {
- plugin.onDestroy();
- }
- }
- }
-
- setContext(context: ContextBase) {
- this._context = context;
- }
-
- getRequirePluginByName<T extends BasePlugin>(pluginName: string): T {
- for (let i = 0; i < this._plugins.length; i++) {
- if (this._plugins[i].getPluginName() === pluginName) {
- return this._plugins[i] as T;
- }
- }
-
- throw new Error(`not found plugin ${pluginName}`);
- }
-
- getPlugins(): BasePlugin[] {
- return this._plugins;
- }
-
- getPluginByName<T extends BasePlugin>(pluginName: string): Nullable<T> {
- for (let i = 0; i < this._plugins.length; i++) {
- if (this._plugins[i].getPluginName() === pluginName) {
- return this._plugins[i] as T;
- }
- }
- return null;
- }
-
- protected _initialize() {
- if (this._initialized) {
- this._initialized = false;
- this._plugins.forEach((plugin: BasePlugin) => {
- plugin.onCreate(this._context);
- plugin.onMounted(this._context);
- });
- }
- }
-}
diff --git a/packages/core/src/Plugin/index.ts b/packages/core/src/Plugin/index.ts
index bb40d407d2..a40b4944c5 100644
--- a/packages/core/src/Plugin/index.ts
+++ b/packages/core/src/Plugin/index.ts
@@ -1,4 +1,3 @@
// @index('./*.ts', f => `export * from '${f.path}'`)
export * from './Plugin';
-export * from './PluginManager';
// @endindex