Skip to content

Commit 2715a8b

Browse files
committed
feat: 🎸 add validate props for schema
1 parent de92225 commit 2715a8b

File tree

15 files changed

+25
-9
lines changed

15 files changed

+25
-9
lines changed

Diff for: packages/components/src/image-block/schema.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export const imageBlockSchema = $nodeSchema('image-block', () => {
1515
atom: true,
1616
priority: 100,
1717
attrs: {
18-
src: { default: '' },
19-
caption: { default: '' },
20-
ratio: { default: 1 },
18+
src: { default: '', validate: 'string' },
19+
caption: { default: '', validate: 'string' },
20+
ratio: { default: 1, validate: 'number' },
2121
},
2222
parseDOM: [
2323
{

Diff for: packages/plugins/preset-commonmark/src/mark/emphasis.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const emphasisSchema = $markSchema('emphasis', (ctx) => ({
2323
attrs: {
2424
marker: {
2525
default: ctx.get(remarkStringifyOptionsCtx).emphasis || '*',
26+
validate: 'string',
2627
},
2728
},
2829
parseDOM: [

Diff for: packages/plugins/preset-commonmark/src/mark/link.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ withMeta(linkAttr, {
1616
/// Link mark schema.
1717
export const linkSchema = $markSchema('link', (ctx) => ({
1818
attrs: {
19-
href: {},
20-
title: { default: null },
19+
href: { validate: 'string' },
20+
title: { default: null, validate: 'string|null' },
2121
},
2222
parseDOM: [
2323
{

Diff for: packages/plugins/preset-commonmark/src/mark/strong.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const strongSchema = $markSchema('strong', (ctx) => ({
2323
attrs: {
2424
marker: {
2525
default: ctx.get(remarkStringifyOptionsCtx).strong || '*',
26+
validate: 'string',
2627
},
2728
},
2829
parseDOM: [

Diff for: packages/plugins/preset-commonmark/src/node/bullet-list.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export const bulletListSchema = $nodeSchema('bullet_list', (ctx) => {
2626
group: 'block',
2727
attrs: {
2828
spread: {
29-
default: false,
29+
default: 'false',
30+
validate: 'string',
3031
},
3132
},
3233
parseDOM: [

Diff for: packages/plugins/preset-commonmark/src/node/code-block.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const codeBlockSchema = $nodeSchema('code_block', (ctx) => {
3333
attrs: {
3434
language: {
3535
default: '',
36+
validate: 'string',
3637
},
3738
},
3839
parseDOM: [

Diff for: packages/plugins/preset-commonmark/src/node/hardbreak.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const hardbreakSchema = $nodeSchema('hardbreak', (ctx) => ({
2626
attrs: {
2727
isInline: {
2828
default: false,
29+
validate: 'boolean',
2930
},
3031
},
3132
selectable: false,

Diff for: packages/plugins/preset-commonmark/src/node/heading.ts

+2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ export const headingSchema = $nodeSchema('heading', (ctx) => {
5656
attrs: {
5757
id: {
5858
default: '',
59+
validate: 'string',
5960
},
6061
level: {
6162
default: 1,
63+
validate: 'number',
6264
},
6365
},
6466
parseDOM: headingIndex.map((x) => ({

Diff for: packages/plugins/preset-commonmark/src/node/html.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const htmlSchema = $nodeSchema('html', (ctx) => {
1616
attrs: {
1717
value: {
1818
default: '',
19+
validate: 'string',
1920
},
2021
},
2122
toDOM: (node) => {

Diff for: packages/plugins/preset-commonmark/src/node/image.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export const imageSchema = $nodeSchema('image', (ctx) => {
2424
defining: true,
2525
isolating: true,
2626
attrs: {
27-
src: { default: '' },
28-
alt: { default: '' },
29-
title: { default: '' },
27+
src: { default: '', validate: 'string' },
28+
alt: { default: '', validate: 'string' },
29+
title: { default: '', validate: 'string' },
3030
},
3131
parseDOM: [
3232
{

Diff for: packages/plugins/preset-commonmark/src/node/list-item.ts

+3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ export const listItemSchema = $nodeSchema('list_item', (ctx) => ({
2525
attrs: {
2626
label: {
2727
default: '•',
28+
validate: 'string',
2829
},
2930
listType: {
3031
default: 'bullet',
32+
validate: 'string',
3133
},
3234
spread: {
3335
default: 'true',
36+
validate: 'string',
3437
},
3538
},
3639
defining: true,

Diff for: packages/plugins/preset-commonmark/src/node/ordered-list.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ export const orderedListSchema = $nodeSchema('ordered_list', (ctx) => ({
2626
attrs: {
2727
order: {
2828
default: 1,
29+
validate: 'number',
2930
},
3031
spread: {
3132
default: false,
33+
validate: 'boolean',
3234
},
3335
},
3436
parseDOM: [

Diff for: packages/plugins/preset-gfm/src/node/footnote/definition.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const footnoteDefinitionSchema = $nodeSchema(
1515
attrs: {
1616
label: {
1717
default: '',
18+
validate: 'string',
1819
},
1920
},
2021
parseDOM: [

Diff for: packages/plugins/preset-gfm/src/node/footnote/reference.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const footnoteReferenceSchema = $nodeSchema(
1414
attrs: {
1515
label: {
1616
default: '',
17+
validate: 'string',
1718
},
1819
},
1920
parseDOM: [

Diff for: packages/plugins/preset-gfm/src/node/task-list-item.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const extendListItemSchemaForTask = listItemSchema.extendSchema(
1515
...baseSchema.attrs,
1616
checked: {
1717
default: null,
18+
validate: 'boolean|null',
1819
},
1920
},
2021
parseDOM: [

0 commit comments

Comments
 (0)