Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ava/ntv): add block element metadata #724

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/ava/src/ntv/schema/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 想收敛只新增循环、条件判断等逻辑,暂不透出 group 的概念
  2. 如果只透出 loop 也有些纠结要不要写 loopInfo.id 这样的多层结构 🤔

// TODO 之后这里还会扩展条件判断等...
}>;
5 changes: 4 additions & 1 deletion packages/ava/src/ntv/schema/paragraph.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -25,17 +25,20 @@ 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 & {
type: 'bullet-item';
phrases: PhraseSpec[];
// nested list
subBullet?: BulletsParagraphSpec;
metadata?: BlockMetaData;
};
7 changes: 4 additions & 3 deletions packages/ava/src/ntv/schema/structure.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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;