@milkdown/preset-commonmark 7.1.0 → 7.1.2-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/lib/__internal__/index.d.ts +3 -0
  2. package/lib/__internal__/index.d.ts.map +1 -0
  3. package/lib/__internal__/serialize-text.d.ts +4 -0
  4. package/lib/__internal__/serialize-text.d.ts.map +1 -0
  5. package/lib/__internal__/with-meta.d.ts +3 -0
  6. package/lib/__internal__/with-meta.d.ts.map +1 -0
  7. package/lib/index.es.js +1195 -678
  8. package/lib/index.es.js.map +1 -1
  9. package/lib/mark/emphasis.d.ts +1 -1
  10. package/lib/mark/emphasis.d.ts.map +1 -1
  11. package/lib/mark/inline-code.d.ts +1 -1
  12. package/lib/mark/inline-code.d.ts.map +1 -1
  13. package/lib/mark/link.d.ts +1 -1
  14. package/lib/mark/link.d.ts.map +1 -1
  15. package/lib/mark/strong.d.ts +1 -1
  16. package/lib/mark/strong.d.ts.map +1 -1
  17. package/lib/node/blockquote.d.ts.map +1 -1
  18. package/lib/node/bullet-list.d.ts.map +1 -1
  19. package/lib/node/code-block.d.ts.map +1 -1
  20. package/lib/node/doc.d.ts.map +1 -1
  21. package/lib/node/hardbreak.d.ts.map +1 -1
  22. package/lib/node/heading.d.ts.map +1 -1
  23. package/lib/node/hr.d.ts.map +1 -1
  24. package/lib/node/html.d.ts.map +1 -1
  25. package/lib/node/image.d.ts.map +1 -1
  26. package/lib/node/list-item.d.ts.map +1 -1
  27. package/lib/node/ordered-list.d.ts.map +1 -1
  28. package/lib/node/paragraph.d.ts.map +1 -1
  29. package/lib/node/text.d.ts.map +1 -1
  30. package/lib/plugin/hardbreak-clear-mark-plugin.d.ts.map +1 -1
  31. package/lib/plugin/hardbreak-filter-plugin.d.ts.map +1 -1
  32. package/lib/plugin/inline-nodes-cursor-plugin.d.ts.map +1 -1
  33. package/lib/plugin/inline-sync-plugin/config.d.ts.map +1 -1
  34. package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts.map +1 -1
  35. package/lib/plugin/remark-add-order-in-list-plugin.d.ts.map +1 -1
  36. package/lib/plugin/remark-html-transformer.d.ts.map +1 -1
  37. package/lib/plugin/remark-inline-link-plugin.d.ts.map +1 -1
  38. package/lib/plugin/remark-line-break.d.ts.map +1 -1
  39. package/lib/plugin/sync-heading-id-plugin.d.ts.map +1 -1
  40. package/lib/plugin/sync-list-order-plugin.d.ts.map +1 -1
  41. package/package.json +13 -10
  42. package/src/__internal__/index.ts +3 -0
  43. package/src/__internal__/serialize-text.ts +22 -0
  44. package/src/__internal__/with-meta.ts +16 -0
  45. package/src/mark/emphasis.ts +31 -0
  46. package/src/mark/inline-code.ts +31 -0
  47. package/src/mark/link.ts +21 -0
  48. package/src/mark/strong.ts +31 -0
  49. package/src/node/blockquote.ts +36 -0
  50. package/src/node/bullet-list.ts +36 -0
  51. package/src/node/code-block.ts +41 -0
  52. package/src/node/doc.ts +6 -0
  53. package/src/node/hardbreak.ts +32 -0
  54. package/src/node/heading.ts +49 -20
  55. package/src/node/hr.ts +26 -0
  56. package/src/node/html.ts +16 -0
  57. package/src/node/image.ts +31 -0
  58. package/src/node/list-item.ts +41 -0
  59. package/src/node/ordered-list.ts +36 -0
  60. package/src/node/paragraph.ts +31 -16
  61. package/src/node/text.ts +6 -0
  62. package/src/plugin/hardbreak-clear-mark-plugin.ts +7 -1
  63. package/src/plugin/hardbreak-filter-plugin.ts +11 -0
  64. package/src/plugin/inline-nodes-cursor-plugin.ts +6 -0
  65. package/src/plugin/inline-sync-plugin/config.ts +6 -0
  66. package/src/plugin/inline-sync-plugin/inline-sync-plugin.ts +8 -0
  67. package/src/plugin/remark-add-order-in-list-plugin.ts +6 -0
  68. package/src/plugin/remark-html-transformer.ts +6 -0
  69. package/src/plugin/remark-inline-link-plugin.ts +6 -0
  70. package/src/plugin/remark-line-break.ts +6 -0
  71. package/src/plugin/sync-heading-id-plugin.ts +6 -0
  72. package/src/plugin/sync-list-order-plugin.ts +6 -0
@@ -4,6 +4,7 @@ import { expectDomTypeError } from '@milkdown/exception'
4
4
  import { setBlockType } from '@milkdown/prose/commands'
5
5
  import { textblockTypeInputRule } from '@milkdown/prose/inputrules'
6
6
  import { $command, $inputRule, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
7
+ import { withMeta } from '../__internal__'
7
8
 
8
9
  /// HTML attributes for code block node.
9
10
  export const codeBlockAttr = $nodeAttr('codeBlock', () => ({
@@ -11,6 +12,11 @@ export const codeBlockAttr = $nodeAttr('codeBlock', () => ({
11
12
  code: {},
12
13
  }))
13
14
 
15
+ withMeta(codeBlockAttr, {
16
+ displayName: 'Attr<codeBlock>',
17
+ group: 'CodeBlock',
18
+ })
19
+
14
20
  /// Schema for code block node.
15
21
  export const codeBlockSchema = $nodeSchema('code_block', (ctx) => {
16
22
  return {
@@ -70,16 +76,36 @@ export const codeBlockSchema = $nodeSchema('code_block', (ctx) => {
70
76
  }
71
77
  })
72
78
 
79
+ withMeta(codeBlockSchema.node, {
80
+ displayName: 'NodeSchema<codeBlock>',
81
+ group: 'CodeBlock',
82
+ })
83
+
84
+ withMeta(codeBlockSchema.ctx, {
85
+ displayName: 'NodeSchemaCtx<codeBlock>',
86
+ group: 'CodeBlock',
87
+ })
88
+
73
89
  /// A input rule for creating code block.
74
90
  /// For example, ` ```javascript ` will create a code block with language javascript.
75
91
  export const createCodeBlockInputRule = $inputRule(() => textblockTypeInputRule(/^```(?<language>[a-z]*)?[\s\n]$/, codeBlockSchema.type(), match => ({
76
92
  language: match.groups?.language ?? '',
77
93
  })))
78
94
 
95
+ withMeta(createCodeBlockInputRule, {
96
+ displayName: 'InputRule<createCodeBlockInputRule>',
97
+ group: 'CodeBlock',
98
+ })
99
+
79
100
  /// A command for creating code block.
80
101
  /// You can pass the language of the code block as the parameter.
81
102
  export const createCodeBlockCommand = $command('CreateCodeBlock', () => (language = '') => setBlockType(codeBlockSchema.type(), { language }))
82
103
 
104
+ withMeta(createCodeBlockCommand, {
105
+ displayName: 'Command<createCodeBlockCommand>',
106
+ group: 'CodeBlock',
107
+ })
108
+
83
109
  /// A command for updating the code block language of the target position.
84
110
  export const updateCodeBlockLanguageCommand = $command('UpdateCodeBlockLanguage', () => ({ pos, language }: { pos: number; language: string } = { pos: -1, language: '' }) => (state, dispatch) => {
85
111
  if (pos >= 0) {
@@ -90,6 +116,11 @@ export const updateCodeBlockLanguageCommand = $command('UpdateCodeBlockLanguage'
90
116
  return false
91
117
  })
92
118
 
119
+ withMeta(updateCodeBlockLanguageCommand, {
120
+ displayName: 'Command<updateCodeBlockLanguageCommand>',
121
+ group: 'CodeBlock',
122
+ })
123
+
93
124
  /// Keymap for code block.
94
125
  /// - `Mod-Alt-c`: Create a code block.
95
126
  export const codeBlockKeymap = $useKeymap('codeBlockKeymap', {
@@ -101,3 +132,13 @@ export const codeBlockKeymap = $useKeymap('codeBlockKeymap', {
101
132
  },
102
133
  },
103
134
  })
135
+
136
+ withMeta(codeBlockKeymap.ctx, {
137
+ displayName: 'KeymapCtx<codeBlock>',
138
+ group: 'CodeBlock',
139
+ })
140
+
141
+ withMeta(codeBlockKeymap.shortcuts, {
142
+ displayName: 'Keymap<codeBlock>',
143
+ group: 'CodeBlock',
144
+ })
package/src/node/doc.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { $node } from '@milkdown/utils'
3
+ import { withMeta } from '../__internal__'
3
4
 
4
5
  /// The top-level document node.
5
6
  export const docSchema = $node('doc', () => ({
@@ -18,3 +19,8 @@ export const docSchema = $node('doc', () => ({
18
19
  },
19
20
  },
20
21
  }))
22
+
23
+ withMeta(docSchema, {
24
+ displayName: 'NodeSchema<doc>',
25
+ group: 'Doc',
26
+ })
@@ -2,6 +2,7 @@
2
2
  import { commandsCtx } from '@milkdown/core'
3
3
  import { Selection } from '@milkdown/prose/state'
4
4
  import { $command, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
5
+ import { withMeta } from '../__internal__'
5
6
 
6
7
  /// HTML attributes for the hardbreak node.
7
8
  ///
@@ -13,6 +14,11 @@ export const hardbreakAttr = $nodeAttr('hardbreak', (node) => {
13
14
  }
14
15
  })
15
16
 
17
+ withMeta(hardbreakAttr, {
18
+ displayName: 'Attr<hardbreak>',
19
+ group: 'Hardbreak',
20
+ })
21
+
16
22
  /// Hardbreak node schema.
17
23
  export const hardbreakSchema = $nodeSchema('hardbreak', ctx => ({
18
24
  inline: true,
@@ -31,6 +37,7 @@ export const hardbreakSchema = $nodeSchema('hardbreak', ctx => ({
31
37
  state.addNode(type, { isInline: Boolean(node.data?.isInline) })
32
38
  },
33
39
  },
40
+ leafText: () => '\n',
34
41
  toMarkdown: {
35
42
  match: node => node.type.name === 'hardbreak',
36
43
  runner: (state, node) => {
@@ -43,6 +50,16 @@ export const hardbreakSchema = $nodeSchema('hardbreak', ctx => ({
43
50
  },
44
51
  }))
45
52
 
53
+ withMeta(hardbreakSchema.node, {
54
+ displayName: 'NodeSchema<hardbreak>',
55
+ group: 'Hardbreak',
56
+ })
57
+
58
+ withMeta(hardbreakSchema.ctx, {
59
+ displayName: 'NodeSchemaCtx<hardbreak>',
60
+ group: 'Hardbreak',
61
+ })
62
+
46
63
  /// Command to insert a hardbreak.
47
64
  export const insertHardbreakCommand = $command('InsertHardbreak', () => () => (state, dispatch) => {
48
65
  const { selection, tr } = state
@@ -63,6 +80,11 @@ export const insertHardbreakCommand = $command('InsertHardbreak', () => () => (s
63
80
  return true
64
81
  })
65
82
 
83
+ withMeta(insertHardbreakCommand, {
84
+ displayName: 'Command<insertHardbreakCommand>',
85
+ group: 'Hardbreak',
86
+ })
87
+
66
88
  /// Keymap for the hardbreak node.
67
89
  /// - `Shift-Enter` - Insert a hardbreak.
68
90
  export const hardbreakKeymap = $useKeymap('hardbreakKeymap', {
@@ -74,3 +96,13 @@ export const hardbreakKeymap = $useKeymap('hardbreakKeymap', {
74
96
  },
75
97
  },
76
98
  })
99
+
100
+ withMeta(hardbreakKeymap.ctx, {
101
+ displayName: 'KeymapCtx<hardbreak>',
102
+ group: 'Hardbreak',
103
+ })
104
+
105
+ withMeta(hardbreakKeymap.shortcuts, {
106
+ displayName: 'Keymap<hardbreak>',
107
+ group: 'Hardbreak',
108
+ })
@@ -4,8 +4,9 @@ import { expectDomTypeError } from '@milkdown/exception'
4
4
  import { setBlockType } from '@milkdown/prose/commands'
5
5
  import { textblockTypeInputRule } from '@milkdown/prose/inputrules'
6
6
  import type { Node } from '@milkdown/prose/model'
7
- import { Fragment } from '@milkdown/prose/model'
8
7
  import { $command, $ctx, $inputRule, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
8
+ import slugify from '@sindresorhus/slugify'
9
+ import { serializeText, withMeta } from '../__internal__'
9
10
  import { paragraphSchema } from './paragraph'
10
11
 
11
12
  const headingIndex = Array(6)
@@ -13,19 +14,25 @@ const headingIndex = Array(6)
13
14
  .map((_, i) => i + 1)
14
15
 
15
16
  const defaultHeadingIdGenerator = (node: Node) =>
16
- node.textContent
17
- .replace(/[\p{P}\p{S}]/gu, '')
18
- .replace(/\s/g, '-')
19
- .toLowerCase()
20
- .trim()
17
+ slugify(node.textContent)
21
18
 
22
19
  /// This is a slice contains a function to generate heading id.
23
20
  /// You can configure it to generate id in your own way.
24
21
  export const headingIdGenerator = $ctx(defaultHeadingIdGenerator, 'headingIdGenerator')
25
22
 
23
+ withMeta(headingIdGenerator, {
24
+ displayName: 'Ctx<HeadingIdGenerator>',
25
+ group: 'Heading',
26
+ })
27
+
26
28
  /// HTML attributes for heading node.
27
29
  export const headingAttr = $nodeAttr('heading')
28
30
 
31
+ withMeta(headingAttr, {
32
+ displayName: 'Attr<heading>',
33
+ group: 'Heading',
34
+ })
35
+
29
36
  /// Schema for heading node.
30
37
  export const headingSchema = $nodeSchema('heading', (ctx) => {
31
38
  const getId = ctx.get(headingIdGenerator.key)
@@ -73,26 +80,23 @@ export const headingSchema = $nodeSchema('heading', (ctx) => {
73
80
  match: node => node.type.name === 'heading',
74
81
  runner: (state, node) => {
75
82
  state.openNode('heading', undefined, { depth: node.attrs.level })
76
- const lastIsHardbreak = node.childCount >= 1 && node.lastChild?.type.name === 'hardbreak'
77
- if (lastIsHardbreak) {
78
- const contentArr: Node[] = []
79
- node.content.forEach((n, _, i) => {
80
- if (i === node.childCount - 1)
81
- return
82
-
83
- contentArr.push(n)
84
- })
85
- state.next(Fragment.fromArray(contentArr))
86
- }
87
- else {
88
- state.next(node.content)
89
- }
83
+ serializeText(state, node)
90
84
  state.closeNode()
91
85
  },
92
86
  },
93
87
  }
94
88
  })
95
89
 
90
+ withMeta(headingSchema.node, {
91
+ displayName: 'NodeSchema<heading>',
92
+ group: 'Heading',
93
+ })
94
+
95
+ withMeta(headingSchema.ctx, {
96
+ displayName: 'NodeSchemaCtx<heading>',
97
+ group: 'Heading',
98
+ })
99
+
96
100
  /// This input rule can turn the selected block into heading.
97
101
  /// You can input numbers of `#` and a `space` to create heading.
98
102
  export const wrapInHeadingInputRule = $inputRule((ctx) => {
@@ -113,6 +117,11 @@ export const wrapInHeadingInputRule = $inputRule((ctx) => {
113
117
  })
114
118
  })
115
119
 
120
+ withMeta(wrapInHeadingInputRule, {
121
+ displayName: 'InputRule<wrapInHeadingInputRule>',
122
+ group: 'Heading',
123
+ })
124
+
116
125
  /// This command can turn the selected block into heading.
117
126
  /// You can pass the level of heading to this command.
118
127
  /// By default, the level is 1, which means it will create a `h1` element.
@@ -127,6 +136,11 @@ export const wrapInHeadingCommand = $command('WrapInHeading', () => {
127
136
  }
128
137
  })
129
138
 
139
+ withMeta(wrapInHeadingCommand, {
140
+ displayName: 'Command<wrapInHeadingCommand>',
141
+ group: 'Heading',
142
+ })
143
+
130
144
  /// This command can downgrade the selected heading.
131
145
  /// For example, if you have a `h2` element, and you call this command, you will get a `h1` element.
132
146
  /// If the element is already a `h1` element, it will turn it into a `p` element.
@@ -150,6 +164,11 @@ export const downgradeHeadingCommand = $command('DowngradeHeading', () => () =>
150
164
  return true
151
165
  })
152
166
 
167
+ withMeta(downgradeHeadingCommand, {
168
+ displayName: 'Command<downgradeHeadingCommand>',
169
+ group: 'Heading',
170
+ })
171
+
153
172
  /// Keymap for heading node.
154
173
  /// - `<Mod-Alt-{1-6}>`: Turn the selected block into `h{1-6}` element.
155
174
  /// - `<Delete>/<Backspace>`: Downgrade the selected heading.
@@ -204,3 +223,13 @@ export const headingKeymap = $useKeymap('headingKeymap', {
204
223
  },
205
224
  },
206
225
  })
226
+
227
+ withMeta(headingKeymap.ctx, {
228
+ displayName: 'KeymapCtx<heading>',
229
+ group: 'Heading',
230
+ })
231
+
232
+ withMeta(headingKeymap.shortcuts, {
233
+ displayName: 'Keymap<heading>',
234
+ group: 'Heading',
235
+ })
package/src/node/hr.ts CHANGED
@@ -2,11 +2,17 @@
2
2
  import { InputRule } from '@milkdown/prose/inputrules'
3
3
  import { Selection } from '@milkdown/prose/state'
4
4
  import { $command, $inputRule, $nodeAttr, $nodeSchema } from '@milkdown/utils'
5
+ import { withMeta } from '../__internal__'
5
6
  import { paragraphSchema } from './paragraph'
6
7
 
7
8
  /// HTML attributes for the hr node.
8
9
  export const hrAttr = $nodeAttr('hr')
9
10
 
11
+ withMeta(hrAttr, {
12
+ displayName: 'Attr<hr>',
13
+ group: 'Hr',
14
+ })
15
+
10
16
  /// Hr node schema.
11
17
  export const hrSchema = $nodeSchema('hr', ctx => ({
12
18
  group: 'block',
@@ -26,6 +32,16 @@ export const hrSchema = $nodeSchema('hr', ctx => ({
26
32
  },
27
33
  }))
28
34
 
35
+ withMeta(hrSchema.node, {
36
+ displayName: 'NodeSchema<hr>',
37
+ group: 'Hr',
38
+ })
39
+
40
+ withMeta(hrSchema.ctx, {
41
+ displayName: 'NodeSchemaCtx<hr>',
42
+ group: 'Hr',
43
+ })
44
+
29
45
  /// Input rule to insert a hr.
30
46
  /// For example, `---` will be converted to a hr.
31
47
  export const insertHrInputRule = $inputRule(() => new InputRule(
@@ -39,6 +55,11 @@ export const insertHrInputRule = $inputRule(() => new InputRule(
39
55
  },
40
56
  ))
41
57
 
58
+ withMeta(insertHrInputRule, {
59
+ displayName: 'InputRule<insertHrInputRule>',
60
+ group: 'Hr',
61
+ })
62
+
42
63
  /// Command to insert a hr.
43
64
  export const insertHrCommand = $command('InsertHr', () => () => (state, dispatch) => {
44
65
  if (!dispatch)
@@ -59,3 +80,8 @@ export const insertHrCommand = $command('InsertHr', () => () => (state, dispatch
59
80
  dispatch(_tr.setSelection(sel).scrollIntoView())
60
81
  return true
61
82
  })
83
+
84
+ withMeta(insertHrCommand, {
85
+ displayName: 'Command<insertHrCommand>',
86
+ group: 'Hr',
87
+ })
package/src/node/html.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { $nodeAttr, $nodeSchema } from '@milkdown/utils'
3
+ import { withMeta } from '../__internal__'
3
4
 
4
5
  export const htmlAttr = $nodeAttr('html')
5
6
 
7
+ withMeta(htmlAttr, {
8
+ displayName: 'Attr<html>',
9
+ group: 'Html',
10
+ })
11
+
6
12
  export const htmlSchema = $nodeSchema('html', (ctx) => {
7
13
  return {
8
14
  atom: true,
@@ -45,3 +51,13 @@ export const htmlSchema = $nodeSchema('html', (ctx) => {
45
51
  },
46
52
  }
47
53
  })
54
+
55
+ withMeta(htmlSchema.node, {
56
+ displayName: 'NodeSchema<html>',
57
+ group: 'Html',
58
+ })
59
+
60
+ withMeta(htmlSchema.ctx, {
61
+ displayName: 'NodeSchemaCtx<html>',
62
+ group: 'Html',
63
+ })
package/src/node/image.ts CHANGED
@@ -3,10 +3,16 @@ import { expectDomTypeError } from '@milkdown/exception'
3
3
  import { findSelectedNodeOfType } from '@milkdown/prose'
4
4
  import { InputRule } from '@milkdown/prose/inputrules'
5
5
  import { $command, $inputRule, $nodeAttr, $nodeSchema } from '@milkdown/utils'
6
+ import { withMeta } from '../__internal__'
6
7
 
7
8
  /// HTML attributes for image node.
8
9
  export const imageAttr = $nodeAttr('image')
9
10
 
11
+ withMeta(imageAttr, {
12
+ displayName: 'Attr<image>',
13
+ group: 'Image',
14
+ })
15
+
10
16
  /// Schema for image node.
11
17
  export const imageSchema = $nodeSchema('image', (ctx) => {
12
18
  return {
@@ -67,6 +73,16 @@ export const imageSchema = $nodeSchema('image', (ctx) => {
67
73
  }
68
74
  })
69
75
 
76
+ withMeta(imageSchema.node, {
77
+ displayName: 'NodeSchema<image>',
78
+ group: 'Image',
79
+ })
80
+
81
+ withMeta(imageSchema.ctx, {
82
+ displayName: 'NodeSchemaCtx<image>',
83
+ group: 'Image',
84
+ })
85
+
70
86
  /// @internal
71
87
  export type UpdateImageCommandPayload = {
72
88
  src?: string
@@ -91,6 +107,11 @@ export const insertImageCommand = $command('InsertImage', () => (payload: Update
91
107
  return true
92
108
  })
93
109
 
110
+ withMeta(insertImageCommand, {
111
+ displayName: 'Command<insertImageCommand>',
112
+ group: 'Image',
113
+ })
114
+
94
115
  /// This command will update the selected image node.
95
116
  /// You can pass a payload to update `src`, `alt` and `title` for the image node.
96
117
  export const updateImageCommand = $command('UpdateImage', () => (payload: UpdateImageCommandPayload = {}) => (state, dispatch) => {
@@ -113,6 +134,11 @@ export const updateImageCommand = $command('UpdateImage', () => (payload: Update
113
134
  return true
114
135
  })
115
136
 
137
+ withMeta(updateImageCommand, {
138
+ displayName: 'Command<updateImageCommand>',
139
+ group: 'Image',
140
+ })
141
+
116
142
  /// This input rule will insert a image node.
117
143
  /// You can input `![alt](src "title")` to insert a image node.
118
144
  /// The `title` is optional.
@@ -126,3 +152,8 @@ export const insertImageInputRule = $inputRule(() => new InputRule(
126
152
  return null
127
153
  },
128
154
  ))
155
+
156
+ withMeta(insertImageInputRule, {
157
+ displayName: 'InputRule<insertImageInputRule>',
158
+ group: 'Image',
159
+ })
@@ -3,10 +3,16 @@ import { commandsCtx } from '@milkdown/core'
3
3
  import { expectDomTypeError } from '@milkdown/exception'
4
4
  import { liftListItem, sinkListItem, splitListItem } from '@milkdown/prose/schema-list'
5
5
  import { $command, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
6
+ import { withMeta } from '../__internal__'
6
7
 
7
8
  /// HTML attributes for list item node.
8
9
  export const listItemAttr = $nodeAttr('listItem')
9
10
 
11
+ withMeta(listItemAttr, {
12
+ displayName: 'Attr<listItem>',
13
+ group: 'ListItem',
14
+ })
15
+
10
16
  /// Schema for list item node.
11
17
  export const listItemSchema = $nodeSchema('list_item', ctx => ({
12
18
  group: 'listItem',
@@ -69,6 +75,16 @@ export const listItemSchema = $nodeSchema('list_item', ctx => ({
69
75
  },
70
76
  }))
71
77
 
78
+ withMeta(listItemSchema.node, {
79
+ displayName: 'NodeSchema<listItem>',
80
+ group: 'ListItem',
81
+ })
82
+
83
+ withMeta(listItemSchema.ctx, {
84
+ displayName: 'NodeSchemaCtx<listItem>',
85
+ group: 'ListItem',
86
+ })
87
+
72
88
  /// The command to sink list item.
73
89
  ///
74
90
  /// For example:
@@ -83,6 +99,11 @@ export const listItemSchema = $nodeSchema('list_item', ctx => ({
83
99
  /// ```
84
100
  export const sinkListItemCommand = $command('SinkListItem', () => () => sinkListItem(listItemSchema.type()))
85
101
 
102
+ withMeta(sinkListItemCommand, {
103
+ displayName: 'Command<sinkListItemCommand>',
104
+ group: 'ListItem',
105
+ })
106
+
86
107
  /// The command to lift list item.
87
108
  ///
88
109
  /// For example:
@@ -97,6 +118,11 @@ export const sinkListItemCommand = $command('SinkListItem', () => () => sinkList
97
118
  /// ```
98
119
  export const liftListItemCommand = $command('SplitListItem', () => () => liftListItem(listItemSchema.type()))
99
120
 
121
+ withMeta(liftListItemCommand, {
122
+ displayName: 'Command<liftListItemCommand>',
123
+ group: 'ListItem',
124
+ })
125
+
100
126
  /// The command to split a list item.
101
127
  ///
102
128
  /// For example:
@@ -112,6 +138,11 @@ export const liftListItemCommand = $command('SplitListItem', () => () => liftLis
112
138
  /// ```
113
139
  export const splitListItemCommand = $command('SplitListItem', () => () => splitListItem(listItemSchema.type()))
114
140
 
141
+ withMeta(splitListItemCommand, {
142
+ displayName: 'Command<splitListItemCommand>',
143
+ group: 'ListItem',
144
+ })
145
+
115
146
  /// Keymap for list item node.
116
147
  /// - `<Enter>`: Split the current list item.
117
148
  /// - `<Tab>/<Mod-]>`: Sink the current list item.
@@ -139,3 +170,13 @@ export const listItemKeymap = $useKeymap('listItemKeymap', {
139
170
  },
140
171
  },
141
172
  })
173
+
174
+ withMeta(listItemKeymap.ctx, {
175
+ displayName: 'KeymapCtx<listItem>',
176
+ group: 'ListItem',
177
+ })
178
+
179
+ withMeta(listItemKeymap.shortcuts, {
180
+ displayName: 'Keymap<listItem>',
181
+ group: 'ListItem',
182
+ })
@@ -4,10 +4,16 @@ import { expectDomTypeError } from '@milkdown/exception'
4
4
  import { wrapIn } from '@milkdown/prose/commands'
5
5
  import { wrappingInputRule } from '@milkdown/prose/inputrules'
6
6
  import { $command, $inputRule, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
7
+ import { withMeta } from '../__internal__'
7
8
 
8
9
  /// HTML attributes for ordered list node.
9
10
  export const orderedListAttr = $nodeAttr('orderedList')
10
11
 
12
+ withMeta(orderedListAttr, {
13
+ displayName: 'Attr<orderedList>',
14
+ group: 'OrderedList',
15
+ })
16
+
11
17
  /// Schema for ordered list node.
12
18
  export const orderedListSchema = $nodeSchema('ordered_list', ctx => ({
13
19
  content: 'listItem+',
@@ -60,6 +66,16 @@ export const orderedListSchema = $nodeSchema('ordered_list', ctx => ({
60
66
  },
61
67
  }))
62
68
 
69
+ withMeta(orderedListSchema.node, {
70
+ displayName: 'NodeSchema<orderedList>',
71
+ group: 'OrderedList',
72
+ })
73
+
74
+ withMeta(orderedListSchema.ctx, {
75
+ displayName: 'NodeSchemaCtx<orderedList>',
76
+ group: 'OrderedList',
77
+ })
78
+
63
79
  /// Input rule for wrapping a block in ordered list node.
64
80
  export const wrapInOrderedListInputRule = $inputRule(() => wrappingInputRule(
65
81
  /^\s*(\d+)\.\s$/,
@@ -68,9 +84,19 @@ export const wrapInOrderedListInputRule = $inputRule(() => wrappingInputRule(
68
84
  (match, node) => node.childCount + node.attrs.order === Number(match[1]),
69
85
  ))
70
86
 
87
+ withMeta(wrapInOrderedListInputRule, {
88
+ displayName: 'InputRule<wrapInOrderedListInputRule>',
89
+ group: 'OrderedList',
90
+ })
91
+
71
92
  /// Command for wrapping a block in ordered list node.
72
93
  export const wrapInOrderedListCommand = $command('WrapInOrderedList', () => () => wrapIn(orderedListSchema.type()))
73
94
 
95
+ withMeta(wrapInOrderedListCommand, {
96
+ displayName: 'Command<wrapInOrderedListCommand>',
97
+ group: 'OrderedList',
98
+ })
99
+
74
100
  /// Keymap for ordered list node.
75
101
  /// - `Mod-Alt-7`: Wrap a block in ordered list.
76
102
  export const orderedListKeymap = $useKeymap('orderedListKeymap', {
@@ -82,3 +108,13 @@ export const orderedListKeymap = $useKeymap('orderedListKeymap', {
82
108
  },
83
109
  },
84
110
  })
111
+
112
+ withMeta(orderedListKeymap.ctx, {
113
+ displayName: 'KeymapCtx<orderedList>',
114
+ group: 'OrderedList',
115
+ })
116
+
117
+ withMeta(orderedListKeymap.shortcuts, {
118
+ displayName: 'Keymap<orderedList>',
119
+ group: 'OrderedList',
120
+ })
@@ -1,13 +1,17 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { commandsCtx } from '@milkdown/core'
3
3
  import { setBlockType } from '@milkdown/prose/commands'
4
- import type { Node } from '@milkdown/prose/model'
5
- import { Fragment } from '@milkdown/prose/model'
6
4
  import { $command, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
5
+ import { serializeText, withMeta } from '../__internal__'
7
6
 
8
7
  /// HTML attributes for paragraph node.
9
8
  export const paragraphAttr = $nodeAttr('paragraph')
10
9
 
10
+ withMeta(paragraphAttr, {
11
+ displayName: 'Attr<paragraph>',
12
+ group: 'Paragraph',
13
+ })
14
+
11
15
  /// Schema for paragraph node.
12
16
  export const paragraphSchema = $nodeSchema('paragraph', ctx => ({
13
17
  content: 'inline*',
@@ -31,28 +35,29 @@ export const paragraphSchema = $nodeSchema('paragraph', ctx => ({
31
35
  match: node => node.type.name === 'paragraph',
32
36
  runner: (state, node) => {
33
37
  state.openNode('paragraph')
34
- const lastIsHardbreak = node.childCount >= 1 && node.lastChild?.type.name === 'hardbreak'
35
- if (lastIsHardbreak) {
36
- const contentArr: Node[] = []
37
- node.content.forEach((n, _, i) => {
38
- if (i === node.childCount - 1)
39
- return
40
-
41
- contentArr.push(n)
42
- })
43
- state.next(Fragment.fromArray(contentArr))
44
- }
45
- else {
46
- state.next(node.content)
47
- }
38
+ serializeText(state, node)
48
39
  state.closeNode()
49
40
  },
50
41
  },
51
42
  }))
52
43
 
44
+ withMeta(paragraphSchema.node, {
45
+ displayName: 'NodeSchema<paragraph>',
46
+ group: 'Paragraph',
47
+ })
48
+ withMeta(paragraphSchema.ctx, {
49
+ displayName: 'NodeSchemaCtx<paragraph>',
50
+ group: 'Paragraph',
51
+ })
52
+
53
53
  /// This command can turn the selected block into paragraph.
54
54
  export const turnIntoTextCommand = $command('TurnIntoText', () => () => setBlockType(paragraphSchema.type()))
55
55
 
56
+ withMeta(turnIntoTextCommand, {
57
+ displayName: 'Command<turnIntoTextCommand>',
58
+ group: 'Paragraph',
59
+ })
60
+
56
61
  /// Keymap for paragraph node.
57
62
  /// - `<Mod-Alt-0>`: Turn the selected block into paragraph.
58
63
  export const paragraphKeymap = $useKeymap('paragraphKeymap', {
@@ -64,3 +69,13 @@ export const paragraphKeymap = $useKeymap('paragraphKeymap', {
64
69
  },
65
70
  },
66
71
  })
72
+
73
+ withMeta(paragraphKeymap.ctx, {
74
+ displayName: 'KeymapCtx<paragraph>',
75
+ group: 'Paragraph',
76
+ })
77
+
78
+ withMeta(paragraphKeymap.shortcuts, {
79
+ displayName: 'Keymap<paragraph>',
80
+ group: 'Paragraph',
81
+ })
package/src/node/text.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { $node } from '@milkdown/utils'
3
+ import { withMeta } from '../__internal__'
3
4
 
4
5
  /// The bottom-level node.
5
6
  export const textSchema = $node('text', () => ({
@@ -17,3 +18,8 @@ export const textSchema = $node('text', () => ({
17
18
  },
18
19
  },
19
20
  }))
21
+
22
+ withMeta(textSchema, {
23
+ displayName: 'NodeSchema<text>',
24
+ group: 'Text',
25
+ })