From 2ad884936f185a98131d83bb251c844140610b93 Mon Sep 17 00:00:00 2001 From: bbsqq <1491812683@qq.com> Date: Wed, 9 Aug 2023 15:12:49 +0800 Subject: [PATCH] feat(ava/ntv): add block element metadata --- packages/ava/src/ntv/schema/common.ts | 8 ++++++++ packages/ava/src/ntv/schema/paragraph.ts | 5 ++++- packages/ava/src/ntv/schema/structure.ts | 7 ++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/ava/src/ntv/schema/common.ts b/packages/ava/src/ntv/schema/common.ts index 2b0ff43c3..7d2007f15 100644 --- a/packages/ava/src/ntv/schema/common.ts +++ b/packages/ava/src/ntv/schema/common.ts @@ -11,6 +11,7 @@ export type CommonProps = { export type CustomBlockElement = CommonProps & { // customType is required for custom block structure customType: string; + metadata?: BlockMetaData; [key: string]: unknown; }; @@ -20,3 +21,10 @@ export type CustomMetaData = { customType: string; [key: string]: unknown; }; + +/** block element (section,paragraph) metadata info */ +export type BlockMetaData = Partial<{ + /** if element is generate by loop */ + loopId: string; + // TODO 之后这里还会扩展条件判断等... +}>; diff --git a/packages/ava/src/ntv/schema/paragraph.ts b/packages/ava/src/ntv/schema/paragraph.ts index 26b0a56de..b9dbe9b6f 100644 --- a/packages/ava/src/ntv/schema/paragraph.ts +++ b/packages/ava/src/ntv/schema/paragraph.ts @@ -1,5 +1,5 @@ import type { PhraseSpec } from './phrase'; -import type { CommonProps, CustomBlockElement } from './common'; +import type { CommonProps, CustomBlockElement, BlockMetaData } from './common'; export type ParagraphSpec = HeadingParagraphSpec | TextParagraphSpec | BulletsParagraphSpec | CustomBlockElement; @@ -25,12 +25,14 @@ export type TextParagraphSpec = CommonProps & { type: 'normal'; phrases: PhraseSpec[]; indents?: ParagraphIndent[]; + metadata?: BlockMetaData; }; export type BulletsParagraphSpec = CommonProps & { type: 'bullets'; isOrder: boolean; bullets: BulletItemSpec[]; + metadata?: BlockMetaData; }; export type BulletItemSpec = CommonProps & { @@ -38,4 +40,5 @@ export type BulletItemSpec = CommonProps & { phrases: PhraseSpec[]; // nested list subBullet?: BulletsParagraphSpec; + metadata?: BlockMetaData; }; diff --git a/packages/ava/src/ntv/schema/structure.ts b/packages/ava/src/ntv/schema/structure.ts index d5cb0c571..1e0b924a2 100644 --- a/packages/ava/src/ntv/schema/structure.ts +++ b/packages/ava/src/ntv/schema/structure.ts @@ -1,4 +1,4 @@ -import type { CommonProps, CustomBlockElement } from './common'; +import type { CommonProps, CustomBlockElement, BlockMetaData } from './common'; import type { PhraseSpec } from './phrase'; import type { ParagraphSpec } from './paragraph'; @@ -12,8 +12,9 @@ export type HeadlineSpec = CommonProps & { phrases: PhraseSpec[]; }; -export type StandardSectionSpec = { +export type StandardSectionSpec = CommonProps & { paragraphs?: ParagraphSpec[]; + metadata?: BlockMetaData; }; -export type SectionSpec = (StandardSectionSpec | CustomBlockElement) & CommonProps; +export type SectionSpec = StandardSectionSpec | CustomBlockElement;