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.

feat(engine-render): support legal list numbering (#7613)

wpxp1234568254c0984a64
diff --git a/packages/core/src/types/interfaces/i-document-data.ts b/packages/core/src/types/interfaces/i-document-data.ts
index d0eb8af42b..1867b7d8c5 100644
--- a/packages/core/src/types/interfaces/i-document-data.ts
+++ b/packages/core/src/types/interfaces/i-document-data.ts
@@ -239,6 +239,8 @@ export interface INestingLevel {
// Union field glyph_kind can be only one of the following:
glyphType?: ListGlyphType; // ordered list string is to support custom rules https://developers.google.com/docs/api/reference/rest/v1/documents#glyphtype, ms numFmt: GlyphType
glyphSymbol?: string; // the tag of the unordered list
+ /** Display all numbered placeholders as decimal values, matching Word's w:isLgl. */
+ isLegal?: boolean;
// End of list of possible types for union field glyph_kind.
}
diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/__tests__/bullet.spec.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/__tests__/bullet.spec.ts
index cb8392da75..0751908d9d 100644
--- a/packages/engine-render/src/components/docs/layout/block/paragraph/__tests__/bullet.spec.ts
+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/__tests__/bullet.spec.ts
@@ -171,6 +171,30 @@ describe('bullet', () => {
expect(result?.symbol).toBe('2.2.');
});
+ it('renders legal numbering placeholders as decimal values', () => {
+ const bullet = createBullet({ nestingLevel: 1 });
+ const lists = createLists([
+ createNestingLevel({ glyphType: ListGlyphType.UPPER_ROMAN }),
+ createNestingLevel({
+ glyphFormat: '%1.%2.',
+ glyphType: ListGlyphType.DECIMAL,
+ isLegal: true,
+ }),
+ ]);
+ const listLevelAncestors: Array<Record<string, unknown> | null> = [
+ { startIndexItem: 3, startNumber: 0, symbol: 'III.' },
+ null,
+ ];
+
+ const result = dealWithBullet(
+ bullet,
+ lists as unknown as ILists,
+ listLevelAncestors as unknown as Parameters<typeof dealWithBullet>[2]
+ );
+
+ expect(result?.symbol).toBe('2.2.');
+ });
+
it('merges textStyle from bullet and nestingLevel', () => {
const bullet = createBullet({ textStyle: { fs: 14 } });
const lists = createLists([
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.ts
index e5f980b615..04e28811fe 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,6 +16,7 @@
import type { IBullet, ILists, INestingLevel, ITextStyle, LocaleService, Nullable } from '@univerjs/core';
import type { IDocumentSkeletonBullet } from '../../../../../basics/i-document-skeleton-cached';
+import { ListGlyphType } from '@univerjs/core';
import { getFontStyleString } from '../../../../../basics/tools';
import { getBulletOrderedSymbol } from './bullet-ruler';
@@ -215,7 +216,12 @@ function __generateOrderedListSymbol(
const startNumber = level === nestingLevel
? currentStartNumber
: ancestor?.startNumber ?? nestings[level].startNumber;
- const singleSymbol = ___getSymbolByBesting(startIndexItem, nestings[level], startNumber);
+ const placeholderNesting = nestings[level];
+ const glyphType = nestings[nestingLevel]?.isLegal
+ && placeholderNesting.glyphType !== ListGlyphType.DECIMAL_ZERO
+ ? ListGlyphType.DECIMAL
+ : placeholderNesting.glyphType;
+ const singleSymbol = ___getSymbolByBesting(startIndexItem, placeholderNesting, startNumber, glyphType);
// console.log(
// '___getSymbolByBesting',
// singleSymbol,
@@ -232,8 +238,13 @@ function __generateOrderedListSymbol(
return resultSymbol.join('');
}
-function ___getSymbolByBesting(startIndex: number = 1, nesting: INestingLevel, startNumber = nesting.startNumber) {
- const { glyphType, glyphSymbol } = nesting;
+function ___getSymbolByBesting(
+ startIndex: number = 1,
+ nesting: INestingLevel,
+ startNumber = nesting.startNumber,
+ glyphType = nesting.glyphType
+) {
+ const { glyphSymbol } = nesting;
if (glyphSymbol) {
// Unordered list uses directly