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
fix(docs-ui): doc list can't toggle (#3473)
zhangw3dc6d955ceee
diff --git a/packages/core/src/docs/data-model/preset-list-type.ts b/packages/core/src/docs/data-model/preset-list-type.tsindex 251ee34a09..ea00878123 100644--- a/packages/core/src/docs/data-model/preset-list-type.ts+++ b/packages/core/src/docs/data-model/preset-list-type.ts@@ -97,7 +97,7 @@ const bulletListFactory = (symbols: BulletSymbols): INestingLevel[] => {startNumber: 0,paragraphProperties: {hanging: { v: 21 },- indentStart: { v: 21 * (i + 1) },+ indentStart: { v: 21 * (i) },},}));};@@ -112,7 +112,7 @@ const orderListFactory = (options: { glyphFormat: string; glyphType: GlyphType }startNumber: 0,paragraphProperties: {hanging: { v: 21 },- indentStart: { v: 21 * (i + 1) },+ indentStart: { v: 21 * (i) },},}));};@@ -128,7 +128,7 @@ const checkListFactory = (symbol: string, textStyle?: ITextStyle): INestingLevelstartNumber: 0,paragraphProperties: {hanging: { v: 21 },- indentStart: { v: 21 * (i + 1) },+ indentStart: { v: 21 * (i) },textStyle,},} as INestingLevel));diff --git a/packages/docs-ui/src/services/doc-event-manager.service.ts b/packages/docs-ui/src/services/doc-event-manager.service.tsindex 1000c0ff49..299a44314b 100644--- a/packages/docs-ui/src/services/doc-event-manager.service.ts+++ b/packages/docs-ui/src/services/doc-event-manager.service.ts@@ -19,7 +19,7 @@ import { DocSkeletonManagerService } from '@univerjs/docs';import { CURSOR_TYPE, TRANSFORM_CHANGE_OBSERVABLE_TYPE } from '@univerjs/engine-render';import { BehaviorSubject, distinctUntilChanged, filter, map, mergeMap, Subject, take, throttleTime } from 'rxjs';import type { DocumentDataModel, ICustomRange, IParagraph, ITextRangeParam, Nullable } from '@univerjs/core';-import type { Documents, DocumentSkeleton, IBoundRectNoAngle, IDocumentSkeletonGlyph, IMouseEvent, IPointerEvent, IRenderContext, IRenderModule } from '@univerjs/engine-render';+import type { Documents, DocumentSkeleton, IBoundRectNoAngle, IDocumentSkeletonGlyph, IDocumentSkeletonPage, IMouseEvent, IPointerEvent, IRenderContext, IRenderModule } from '@univerjs/engine-render';import { DOC_VERTICAL_PADDING } from '../types/const/padding';import { transformOffset2Bound } from './doc-popup-manager.service';import { NodePositionConvertToCursor } from './selection/convert-text-range';@@ -291,48 +291,66 @@ export class DocEventManagerService extends Disposable implements IRenderModule);}- private _buildBulletBoundsBySegment(segmentId?: string, segmentPage = -1) {+ private _buildBulletBoundsBySegment(segmentId?: string, segmentPage = -1): IBulletBound[] {const body = this._context.unit.getSelfOrHeaderFooterModel(segmentId)?.getBody();- const paragraphs = body?.paragraphs ?? [];+ const paragraphs = (body?.paragraphs ?? []).filter((p) => p.bullet && p.bullet.listType.indexOf('CHECK_LIST') === 0);const bounds: IBulletBound[] = [];+ const skeletonData = this._skeleton.getSkeletonData();+ if (!skeletonData) {+ return bounds;+ }- paragraphs.forEach((paragraph) => {- if (paragraph.bullet && paragraph.bullet.listType.indexOf('CHECK_LIST') === 0) {- const calcRect = (pageIndex: number) => {- const node = this._skeleton.findNodeByCharIndex(paragraph.startIndex, segmentId, pageIndex);- const divide = node?.parent;- const line = divide?.parent;- const column = line?.parent;- const targetLine = column?.lines.find((l) => l.paragraphStart && l.paragraphIndex === paragraph.startIndex);- const bulletNode = targetLine?.divides?.[0]?.glyphGroup?.[0];-- if (!bulletNode) {- return;- }-- if (!bulletNode) {- return;- }-- const rect = calcDocGlyphPosition(bulletNode, this._documents, this._skeleton, pageIndex);+ const calc = (pages: IDocumentSkeletonPage[]) => {+ for (const page of pages) {+ const sections = [...page.sections];+ if (page.skeTables) {+ const tables = Array.from(page.skeTables.values());+ sections.push(...tables.map((i) => i.rows.map((i) => i.cells.map((i) => i.sections))).flat(4));+ }- if (!rect) {- return;+ for (const selection of sections) {+ for (const column of selection.columns) {+ for (const line of column.lines) {+ if (line.paragraphStart) {+ const paragraph: Nullable<IParagraph> = paragraphs.find((p) => p.startIndex === line.paragraphIndex);+ if (paragraph) {+ const targetLine = line;+ const bulletNode = targetLine?.divides?.[0]?.glyphGroup?.[0];++ if (!bulletNode) {+ continue;+ }++ const rect = calcDocGlyphPosition(bulletNode, this._documents, this._skeleton, segmentPage);++ if (!rect) {+ continue;+ }++ bounds.push({+ rect,+ segmentId,+ segmentPageIndex: segmentPage,+ paragraph,+ });+ }+ }+ }}+ }+ }+ return bounds;+ };- bounds.push({- rect,- segmentId,- segmentPageIndex: pageIndex,- paragraph,- });- };-- calcRect(segmentPage);+ if (segmentId) {+ const page = skeletonData.skeFooters.get(segmentId)?.values() ?? skeletonData.skeHeaders.get(segmentId)?.values();+ if (!page) {+ return bounds;}- });+ return calc(Array.from(page));+ }- return bounds;+ return calc(skeletonData.pages);}private _buildBulletBounds() {diff --git a/packages/engine-render/src/basics/i-document-skeleton-cached.ts b/packages/engine-render/src/basics/i-document-skeleton-cached.tsindex 2d13f6ab16..d736512404 100644--- a/packages/engine-render/src/basics/i-document-skeleton-cached.ts+++ b/packages/engine-render/src/basics/i-document-skeleton-cached.ts@@ -234,7 +234,7 @@ export interface IDocumentSkeletonBullet {ts: ITextStyle; // 文字样式fontStyle?: IDocumentSkeletonFontStyle; // fontStyle 从ITextStyle转换为canvas fontstartIndexItem: number; // startIndexItem,列表从第几开始- bBox: IDocumentSkeletonBoundingBox; // bBox 文字的位置信息+ // bBox: IDocumentSkeletonBoundingBox; // bBox 文字的位置信息nestingLevel?: INestingLevel;bulletAlign?: BulletAlignment;bulletType?: boolean; // bulletType false unordered, true ordered;diff --git a/packages/engine-render/src/components/docs/extensions/font-and-base-line.ts b/packages/engine-render/src/components/docs/extensions/font-and-base-line.tsindex 27d467e24d..adcd0ffec6 100644--- a/packages/engine-render/src/components/docs/extensions/font-and-base-line.ts+++ b/packages/engine-render/src/components/docs/extensions/font-and-base-line.ts@@ -14,17 +14,17 @@* limitations under the License.*/-import type { IScale } from '@univerjs/core';import { BaselineOffset, getColorStyle } from '@univerjs/core';+import type { IScale } from '@univerjs/core';import { GlyphType, hasCJK } from '../../../basics';import { COLOR_BLACK_RGB } from '../../../basics/const';-import type { IDocumentSkeletonGlyph } from '../../../basics/i-document-skeleton-cached';import { Vector2 } from '../../../basics/vector2';-import type { UniverRenderingContext } from '../../../context';+import { Checkbox } from '../../../shape';import { DocumentsSpanAndLineExtensionRegistry } from '../../extension';import { docExtension } from '../doc-extension';-import { Checkbox } from '../../../shape';+import type { IDocumentSkeletonGlyph } from '../../../basics/i-document-skeleton-cached';+import type { UniverRenderingContext } from '../../../context';const UNIQUE_KEY = 'DefaultDocsFontAndBaseLineExtension';@@ -110,9 +110,11 @@ export class FontAndBaseLine extends docExtension {const UNCHECKED_GLYPH = '\u2610';if ((content === UNCHECKED_GLYPH || content === CHECKED_GLYPH) && glyph.glyphType === GlyphType.LIST) {ctx.save();- const size = glyph.ts?.fs ?? 16;- const MAGIC_OFFSET = 3;- ctx.translate(spanPointWithFont.x, spanPointWithFont.y - (bBox.aba + bBox.abd) - MAGIC_OFFSET);+ const size = Math.ceil((glyph.ts?.fs ?? 12) * 1.2);+ // const MAGIC_OFFSET = 3;+ // const lineHeight = glyph.parent?.parent?.lineHeight ?? 0;+ // console.log('===lineHeight', lineHeight, spanPointWithFont);+ ctx.translate(spanPointWithFont.x, spanPointWithFont.y - size);Checkbox.drawWith(ctx, {width: size,height: size,diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/bullet.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/bullet.tsindex 1d6e956db8..fb5e5d4c16 100644--- a/packages/engine-render/src/components/docs/layout/block/paragraph/bullet.ts+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/bullet.ts@@ -16,10 +16,9 @@import type { IBullet, ILists, INestingLevel, ITextStyle, LocaleService, Nullable } from '@univerjs/core';-import { FontCache } from '../../shaping-engine/font-cache';-import type { IDocumentSkeletonBullet } from '../../../../../basics/i-document-skeleton-cached';import { getFontStyleString } from '../../../../../basics/tools';import { getBulletOrderedSymbol } from './bullet-ruler';+import type { IDocumentSkeletonBullet } from '../../../../../basics/i-document-skeleton-cached';export function dealWithBullet(bullet?: IBullet,@@ -66,18 +65,18 @@ export function getDefaultBulletSke(listId: string, startIndex: number = 1): IDofs: 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,- },+ // bBox: {+ // width: 8.4560546875,+ // ba: 7,+ // bd: -1,+ // aba: 7,+ // abd: -1,+ // sp: -2,+ // sbr: 0.5,+ // sbo: 0,+ // spr: 0.5,+ // spo: 0,+ // },paragraphProperties: {indentFirstLine: { v: 0 },hanging: { v: 21 },@@ -99,7 +98,7 @@ function _getBulletSke(bulletAlignment,glyphFormat,textStyle: textStyleFirst = {},- startNumber,+ // startNumber,glyphType,glyphSymbol,} = nesting;@@ -117,7 +116,7 @@ function _getBulletSke(symbolContent = __generateOrderedListSymbol(glyphFormat, nestingLevel, nestings, listLevelAncestors); // 有序列表的处理}- const bBox = FontCache.getTextSize(symbolContent, fontStyle);+ // const bBox = FontCache.getTextSize(symbolContent, fontStyle);const startIndex = listLevelAncestors?.[nestingLevel]?.startIndexItem ?? 1;return {@@ -126,7 +125,7 @@ function _getBulletSke(ts: textStyle, // 文字样式fontStyle, //startIndexItem: startIndex + 1,- bBox,+ // bBox,nestingLevel: nesting,bulletAlign: bulletAlignment,bulletType: glyphSymbol ? false : !!glyphType, // 默认是无序列表,假如glyphSymbol为空且glyphType不为空才是有序列表diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.tsindex bce0fbcb4d..5372df67f0 100644--- a/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts@@ -14,20 +14,11 @@* limitations under the License.*/-import type { INumberUnit, IParagraphStyle, Nullable } from '@univerjs/core';import { BooleanNumber, DataStreamTreeTokenType, GridType, ObjectRelativeFromV, PositionedObjectLayoutType, SpacingRule, TableTextWrapType } from '@univerjs/core';-import type {- IDocumentSkeletonColumn,- IDocumentSkeletonDivide,- IDocumentSkeletonDrawing,- IDocumentSkeletonGlyph,- IDocumentSkeletonLine,- IDocumentSkeletonPage,- IDocumentSkeletonSection,- IDocumentSkeletonTable,-} from '../../../../../basics/i-document-skeleton-cached';+import type { INumberUnit, IParagraphProperties, IParagraphStyle, Nullable } from '@univerjs/core';import { GlyphType, LineType } from '../../../../../basics/i-document-skeleton-cached';-import type { IParagraphConfig, IParagraphTableCache, ISectionBreakConfig } from '../../../../../basics/interfaces';+import { BreakPointType } from '../../line-breaker/break';+import { addGlyphToDivide, createSkeletonBulletGlyph } from '../../model/glyph';import {calculateLineTopByDrawings,collisionDetection,@@ -38,10 +29,6 @@ import {} from '../../model/line';import { createSkeletonPage } from '../../model/page';import { setColumnFullState } from '../../model/section';-import { addGlyphToDivide, createSkeletonBulletGlyph } from '../../model/glyph';-import type {- ILayoutContext,-} from '../../tools';import {getCharSpaceApply,getCharSpaceConfig,@@ -58,8 +45,21 @@ import {lineIterator,mergeByV,} from '../../tools';-import { BreakPointType } from '../../line-breaker/break';import { getNullTableSkeleton, getTableIdAndSliceIndex, getTableSliceId } from '../table';+import type {+ IDocumentSkeletonColumn,+ IDocumentSkeletonDivide,+ IDocumentSkeletonDrawing,+ IDocumentSkeletonGlyph,+ IDocumentSkeletonLine,+ IDocumentSkeletonPage,+ IDocumentSkeletonSection,+ IDocumentSkeletonTable,+} from '../../../../../basics/i-document-skeleton-cached';+import type { IParagraphConfig, IParagraphTableCache, ISectionBreakConfig } from '../../../../../basics/interfaces';+import type {+ ILayoutContext,+} from '../../tools';export function layoutParagraph(ctx: ILayoutContext,@@ -77,15 +77,14 @@ export function layoutParagraph(// 如果是一个段落的开头,需要加入bulletconst { gridType = GridType.LINES, charSpace = 0, defaultTabStop = 10.5 } = sectionBreakConfig;- const paragraphProperties = bulletSkeleton.paragraphProperties || {};-- paragraphConfig.paragraphStyle = mergeByV<IParagraphStyle>(paragraphConfig.paragraphStyle, paragraphProperties, 'max');-const { snapToGrid = BooleanNumber.TRUE } = paragraphStyle;const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);-const bulletGlyph = createSkeletonBulletGlyph(glyphGroup[0], bulletSkeleton, charSpaceApply);+ const paragraphProperties = bulletSkeleton.paragraphProperties || {};++ paragraphConfig.paragraphStyle = mergeByV<IParagraphStyle>(paragraphConfig.paragraphStyle, { ...paragraphProperties, hanging: { v: bulletGlyph.width } } as IParagraphProperties, 'max');+_lineOperator(ctx, [bulletGlyph, ...glyphGroup], pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType);} else {_lineOperator(ctx, glyphGroup, pages, sectionBreakConfig, paragraphConfig, isParagraphFirstShapedText, breakPointType);diff --git a/packages/engine-render/src/components/docs/layout/model/glyph.ts b/packages/engine-render/src/components/docs/layout/model/glyph.tsindex b716e44fe3..25a76ece95 100644--- a/packages/engine-render/src/components/docs/layout/model/glyph.ts+++ b/packages/engine-render/src/components/docs/layout/model/glyph.ts@@ -16,17 +16,18 @@import { BooleanNumber, BulletAlignment, DataStreamTreeTokenType as DT, GridType } from '@univerjs/core';+import { GlyphType } from '../../../../basics/i-document-skeleton-cached';+import { hasCJK, hasCJKText, isCjkCenterAlignedPunctuation, isCjkLeftAlignedPunctuation, isCjkRightAlignedPunctuation, ptToPixel } from '../../../../basics/tools';import { FontCache } from '../shaping-engine/font-cache';+import { validationGrid } from '../tools';import type {IAdjustability,+ IDocumentSkeletonBoundingBox,IDocumentSkeletonBullet,IDocumentSkeletonDivide,IDocumentSkeletonGlyph,} from '../../../../basics/i-document-skeleton-cached';-import { GlyphType } from '../../../../basics/i-document-skeleton-cached';import type { IFontCreateConfig } from '../../../../basics/interfaces';-import { hasCJK, hasCJKText, isCjkCenterAlignedPunctuation, isCjkLeftAlignedPunctuation, isCjkRightAlignedPunctuation, ptToPixel } from '../../../../basics/tools';-import { validationGrid } from '../tools';import type { IOpenTypeGlyphInfo } from '../shaping-engine/text-shaping';export function isSpace(char: string) {@@ -249,13 +250,17 @@ export function createSkeletonBulletGlyph(charSpaceApply: number): IDocumentSkeletonGlyph {const {- bBox: boundingBox,+ // bBox: boundingBox,symbol: content,- ts: textStyle,- fontStyle,+ // ts: textStyle,+ // fontStyle,bulletAlign = BulletAlignment.START,bulletType = false,} = bulletSkeleton;+ const { fontStyle } = glyph;+ // glyph.fontStyle+ // getFontStyleString(fontStyle, localeService);+ const boundingBox = FontCache.getTextSize(content, fontStyle!);const contentWidth = boundingBox.width;// 当文字也需要对齐到网格式,进行处理, LINES默认参照是doc全局字体大小@@ -275,13 +280,13 @@ export function createSkeletonBulletGlyph(}}- const bBox = _getMaxBoundingBox(glyph, bulletSkeleton);+ const bBox = _getMaxBoundingBox(glyph, boundingBox);return {content,ts: {...glyph.ts,- ...textStyle,+ // ...textStyle,st: {s: BooleanNumber.FALSE,},@@ -333,15 +338,15 @@ export function addGlyphToDivide(divide.glyphGroup.push(...glyphGroup);}-function _getMaxBoundingBox(glyph: IDocumentSkeletonGlyph, bulletSkeleton: IDocumentSkeletonBullet) {+function _getMaxBoundingBox(glyph: IDocumentSkeletonGlyph, bulletBBox: IDocumentSkeletonBoundingBox) {const { ba: spanAscent, bd: spanDescent } = glyph.bBox;- const { ba: bulletAscent, bd: bulletDescent } = bulletSkeleton.bBox;+ const { ba: bulletAscent, bd: bulletDescent } = bulletBBox;if (spanAscent + spanDescent > bulletAscent + bulletDescent) {return glyph.bBox;}- return bulletSkeleton.bBox;+ return bulletBBox;}export function glyphShrinkRight(glyph: IDocumentSkeletonGlyph, amount: number) {