Skip to content

Commit f5c554b

Browse files
authored
feat: 🎸 add validate props for schema (#1810)
* feat: 🎸 add validate props for schema * fix: boolean
1 parent 4f20377 commit f5c554b

File tree

15 files changed

+29
-13
lines changed

15 files changed

+29
-13
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

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const bulletListSchema = $nodeSchema('bullet_list', (ctx) => {
2727
attrs: {
2828
spread: {
2929
default: false,
30+
validate: 'boolean',
3031
},
3132
},
3233
parseDOM: [
@@ -36,7 +37,7 @@ export const bulletListSchema = $nodeSchema('bullet_list', (ctx) => {
3637
if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom)
3738

3839
return {
39-
spread: dom.dataset.spread,
40+
spread: dom.dataset.spread === 'true',
4041
}
4142
},
4243
},
@@ -64,7 +65,7 @@ export const bulletListSchema = $nodeSchema('bullet_list', (ctx) => {
6465
state
6566
.openNode('list', undefined, {
6667
ordered: false,
67-
spread: node.attrs.spread === 'true',
68+
spread: node.attrs.spread,
6869
})
6970
.next(node.content)
7071
.closeNode()

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

+6-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: {
33-
default: 'true',
35+
default: true,
36+
validate: 'boolean',
3437
},
3538
},
3639
defining: true,
@@ -43,7 +46,7 @@ export const listItemSchema = $nodeSchema('list_item', (ctx) => ({
4346
return {
4447
label: dom.dataset.label,
4548
listType: dom.dataset.listType,
46-
spread: dom.dataset.spread,
49+
spread: dom.dataset.spread === 'true',
4750
}
4851
},
4952
},
@@ -73,7 +76,7 @@ export const listItemSchema = $nodeSchema('list_item', (ctx) => ({
7376
match: (node) => node.type.name === 'list_item',
7477
runner: (state, node) => {
7578
state.openNode('listItem', undefined, {
76-
spread: node.attrs.spread === 'true',
79+
spread: node.attrs.spread,
7780
})
7881
state.next(node.content)
7982
state.closeNode()

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)