@milkdown/preset-commonmark 7.0.0-next.0 → 7.0.0-next.2

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 (70) hide show
  1. package/README.md +1 -1
  2. package/lib/composed/commands.d.ts.map +1 -1
  3. package/lib/composed/inputrules.d.ts.map +1 -1
  4. package/lib/composed/keymap.d.ts.map +1 -1
  5. package/lib/composed/plugins.d.ts +2 -1
  6. package/lib/composed/plugins.d.ts.map +1 -1
  7. package/lib/composed/schema.d.ts.map +1 -1
  8. package/lib/index.d.ts.map +1 -1
  9. package/lib/index.es.js +15 -17
  10. package/lib/index.es.js.map +1 -1
  11. package/lib/mark/emphasis.d.ts.map +1 -1
  12. package/lib/mark/inline-code.d.ts.map +1 -1
  13. package/lib/mark/link.d.ts.map +1 -1
  14. package/lib/mark/strong.d.ts.map +1 -1
  15. package/lib/node/blockquote.d.ts.map +1 -1
  16. package/lib/node/bullet-list.d.ts.map +1 -1
  17. package/lib/node/code-block.d.ts.map +1 -1
  18. package/lib/node/doc.d.ts.map +1 -1
  19. package/lib/node/hardbreak.d.ts.map +1 -1
  20. package/lib/node/heading.d.ts.map +1 -1
  21. package/lib/node/hr.d.ts.map +1 -1
  22. package/lib/node/image.d.ts.map +1 -1
  23. package/lib/node/list-item.d.ts +1 -1
  24. package/lib/node/list-item.d.ts.map +1 -1
  25. package/lib/node/ordered-list.d.ts.map +1 -1
  26. package/lib/node/paragraph.d.ts.map +1 -1
  27. package/lib/node/text.d.ts.map +1 -1
  28. package/lib/plugin/hardbreak-clear-mark-plugin.d.ts.map +1 -1
  29. package/lib/plugin/hardbreak-filter-plugin.d.ts.map +1 -1
  30. package/lib/plugin/inline-nodes-cursor-plugin.d.ts +0 -4
  31. package/lib/plugin/inline-nodes-cursor-plugin.d.ts.map +1 -1
  32. package/lib/plugin/inline-sync-plugin/config.d.ts.map +1 -1
  33. package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts.map +1 -1
  34. package/lib/plugin/remark-add-order-in-list-plugin.d.ts.map +1 -1
  35. package/lib/plugin/remark-inline-link-plugin.d.ts.map +1 -1
  36. package/lib/plugin/remark-line-break.d.ts.map +1 -1
  37. package/lib/plugin/sync-heading-id-plugin.d.ts.map +1 -1
  38. package/package.json +7 -7
  39. package/src/composed/commands.ts +1 -0
  40. package/src/composed/inputrules.ts +1 -0
  41. package/src/composed/keymap.ts +1 -0
  42. package/src/composed/plugins.ts +3 -1
  43. package/src/composed/schema.ts +1 -0
  44. package/src/index.ts +1 -0
  45. package/src/mark/emphasis.ts +5 -0
  46. package/src/mark/inline-code.ts +6 -0
  47. package/src/mark/link.ts +9 -0
  48. package/src/mark/strong.ts +6 -0
  49. package/src/node/blockquote.ts +7 -0
  50. package/src/node/bullet-list.ts +7 -0
  51. package/src/node/code-block.ts +10 -0
  52. package/src/node/doc.ts +1 -0
  53. package/src/node/hardbreak.ts +8 -0
  54. package/src/node/heading.ts +16 -2
  55. package/src/node/hr.ts +6 -0
  56. package/src/node/image.ts +11 -0
  57. package/src/node/list-item.ts +46 -1
  58. package/src/node/ordered-list.ts +6 -0
  59. package/src/node/paragraph.ts +6 -0
  60. package/src/node/text.ts +1 -0
  61. package/src/plugin/hardbreak-clear-mark-plugin.ts +1 -0
  62. package/src/plugin/hardbreak-filter-plugin.ts +3 -1
  63. package/src/plugin/inline-nodes-cursor-plugin.ts +1 -4
  64. package/src/plugin/inline-sync-plugin/config.ts +15 -1
  65. package/src/plugin/inline-sync-plugin/inline-sync-plugin.ts +5 -0
  66. package/src/plugin/remark-add-order-in-list-plugin.ts +1 -0
  67. package/src/plugin/remark-inline-link-plugin.ts +1 -0
  68. package/src/plugin/remark-line-break.ts +3 -0
  69. package/src/plugin/sync-heading-id-plugin.ts +2 -0
  70. package/src/plugin/sync-list-order-plugin.ts +1 -1
@@ -4,8 +4,10 @@ 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
6
 
7
+ /// HTML attributes for list item node.
7
8
  export const listItemAttr = $nodeAttr('listItem')
8
9
 
10
+ /// Schema for list item node.
9
11
  export const listItemSchema = $nodeSchema('list_item', ctx => ({
10
12
  group: 'listItem',
11
13
  content: 'paragraph block*',
@@ -67,10 +69,53 @@ export const listItemSchema = $nodeSchema('list_item', ctx => ({
67
69
  },
68
70
  }))
69
71
 
72
+ /// The command to sink list item.
73
+ ///
74
+ /// For example:
75
+ /// ```md
76
+ /// * List item 1
77
+ /// * List item 2 <- cursor here
78
+ /// ```
79
+ /// Will get:
80
+ /// ```md
81
+ /// * List item 1
82
+ /// * List item 2
83
+ /// ```
70
84
  export const sinkListItemCommand = $command('SinkListItem', () => () => sinkListItem(listItemSchema.type()))
71
- export const splitListItemCommand = $command('SplitListItem', () => () => splitListItem(listItemSchema.type()))
85
+
86
+ /// The command to lift list item.
87
+ ///
88
+ /// For example:
89
+ /// ```md
90
+ /// * List item 1
91
+ /// * List item 2 <- cursor here
92
+ /// ```
93
+ /// Will get:
94
+ /// ```md
95
+ /// * List item 1
96
+ /// * List item 2
97
+ /// ```
72
98
  export const liftListItemCommand = $command('SplitListItem', () => () => liftListItem(listItemSchema.type()))
73
99
 
100
+ /// The command to split a list item.
101
+ ///
102
+ /// For example:
103
+ /// ```md
104
+ /// * List item 1
105
+ /// * List item 2 <- cursor here
106
+ /// ```
107
+ /// Will get:
108
+ /// ```md
109
+ /// * List item 1
110
+ /// * List item 2
111
+ /// * <- cursor here
112
+ /// ```
113
+ export const splitListItemCommand = $command('SplitListItem', () => () => splitListItem(listItemSchema.type()))
114
+
115
+ /// Keymap for list item node.
116
+ /// - `<Enter>`: Split the current list item.
117
+ /// - `<Tab>/<Mod-]>`: Sink the current list item.
118
+ /// - `<Shift-Tab>/<Mod-[>`: Lift the current list item.
74
119
  export const listItemKeymap = $useKeymap('listItemKeymap', {
75
120
  NextListItem: {
76
121
  shortcuts: 'Enter',
@@ -5,8 +5,10 @@ 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
7
 
8
+ /// HTML attributes for ordered list node.
8
9
  export const orderedListAttr = $nodeAttr('orderedList')
9
10
 
11
+ /// Schema for ordered list node.
10
12
  export const orderedListSchema = $nodeSchema('ordered_list', ctx => ({
11
13
  content: 'listItem+',
12
14
  group: 'block',
@@ -58,6 +60,7 @@ export const orderedListSchema = $nodeSchema('ordered_list', ctx => ({
58
60
  },
59
61
  }))
60
62
 
63
+ /// Input rule for wrapping a block in ordered list node.
61
64
  export const wrapInOrderedListInputRule = $inputRule(() => wrappingInputRule(
62
65
  /^\s*(\d+)\.\s$/,
63
66
  orderedListSchema.type(),
@@ -65,8 +68,11 @@ export const wrapInOrderedListInputRule = $inputRule(() => wrappingInputRule(
65
68
  (match, node) => node.childCount + node.attrs.order === Number(match[1]),
66
69
  ))
67
70
 
71
+ /// Command for wrapping a block in ordered list node.
68
72
  export const wrapInOrderedListCommand = $command('WrapInOrderedList', () => () => wrapIn(orderedListSchema.type()))
69
73
 
74
+ /// Keymap for ordered list node.
75
+ /// - `Mod-Alt-7`: Wrap a block in ordered list.
70
76
  export const orderedListKeymap = $useKeymap('orderedListKeymap', {
71
77
  WrapInOrderedList: {
72
78
  shortcuts: 'Mod-Alt-7',
@@ -5,7 +5,10 @@ import type { Node } from '@milkdown/prose/model'
5
5
  import { Fragment } from '@milkdown/prose/model'
6
6
  import { $command, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
7
7
 
8
+ /// HTML attributes for paragraph node.
8
9
  export const paragraphAttr = $nodeAttr('paragraph')
10
+
11
+ /// Schema for paragraph node.
9
12
  export const paragraphSchema = $nodeSchema('paragraph', ctx => ({
10
13
  content: 'inline*',
11
14
  group: 'block',
@@ -47,8 +50,11 @@ export const paragraphSchema = $nodeSchema('paragraph', ctx => ({
47
50
  },
48
51
  }))
49
52
 
53
+ /// This command can turn the selected block into paragraph.
50
54
  export const turnIntoTextCommand = $command('TurnIntoText', () => () => setBlockType(paragraphSchema.type()))
51
55
 
56
+ /// Keymap for paragraph node.
57
+ /// - `<Mod-Alt-0>`: Turn the selected block into paragraph.
52
58
  export const paragraphKeymap = $useKeymap('paragraphKeymap', {
53
59
  TurnIntoText: {
54
60
  shortcuts: 'Mod-Alt-0',
package/src/node/text.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { $node } from '@milkdown/utils'
3
3
 
4
+ /// The bottom-level node.
4
5
  export const textSchema = $node('text', () => ({
5
6
  group: 'inline',
6
7
  parseMarkdown: {
@@ -4,6 +4,7 @@ import { AddMarkStep, ReplaceStep } from '@milkdown/prose/transform'
4
4
  import { $prose } from '@milkdown/utils'
5
5
  import { hardbreakSchema } from '../node/hardbreak'
6
6
 
7
+ /// This plugin is used to clear the marks around the hardbreak node.
7
8
  export const hardbreakClearMarkPlugin = $prose(() => {
8
9
  return new Plugin({
9
10
  key: new PluginKey('MILKDOWN_HARDBREAK_MARKS'),
@@ -2,9 +2,11 @@
2
2
  import { Plugin, PluginKey } from '@milkdown/prose/state'
3
3
  import { $ctx, $prose } from '@milkdown/utils'
4
4
 
5
+ /// This slice contains the nodes that within which the hardbreak will be ignored.
5
6
  export const hardbreakFilterNodes = $ctx(['table', 'code_block'], 'hardbreakFilterNodes')
6
7
 
7
- // If the hardbreak is going to be inserted within a node that is in the `hardbreakFilterNodes`, ignore it.
8
+ /// This plugin is used to filter the hardbreak node.
9
+ /// If the hardbreak is going to be inserted within a node that is in the `hardbreakFilterNodes`, ignore it.
8
10
  export const hardbreakFilterPlugin = $prose((ctx) => {
9
11
  const notIn = ctx.get(hardbreakFilterNodes.key)
10
12
  return new Plugin({
@@ -3,10 +3,7 @@ import { Plugin, PluginKey } from '@milkdown/prose/state'
3
3
  import { Decoration, DecorationSet } from '@milkdown/prose/view'
4
4
  import { $prose } from '@milkdown/utils'
5
5
 
6
- /**
7
- * This plugin is to solve the chrome 98 bug:
8
- * https://discuss.prosemirror.net/t/cursor-jumps-at-the-end-of-line-when-it-betweens-two-inline-nodes/4641
9
- */
6
+ /// This plugin is to solve the [chrome 98 bug](https://discuss.prosemirror.net/t/cursor-jumps-at-the-end-of-line-when-it-betweens-two-inline-nodes/4641).
10
7
  export const inlineNodesCursorPlugin = $prose(() => {
11
8
  let lock = false
12
9
  const inlineNodesCursorPluginKey = new PluginKey('MILKDOWN_INLINE_NODES_CURSOR')
@@ -6,6 +6,7 @@ import { $ctx } from '@milkdown/utils'
6
6
 
7
7
  import { swap } from './utils'
8
8
 
9
+ /// @internal
9
10
  export type ShouldSyncNode = (context: {
10
11
  prevNode: Node
11
12
  nextNode: Node
@@ -14,12 +15,14 @@ export type ShouldSyncNode = (context: {
14
15
  text: string
15
16
  }) => boolean
16
17
 
18
+ /// @internal
17
19
  export interface SyncNodePlaceholder {
18
20
  hole: string
19
21
  punctuation: string
20
22
  char: string
21
23
  }
22
24
 
25
+ /// @internal
23
26
  export interface InlineSyncConfig {
24
27
  placeholderConfig: SyncNodePlaceholder
25
28
  shouldSyncNode: ShouldSyncNode
@@ -27,6 +30,7 @@ export interface InlineSyncConfig {
27
30
  movePlaceholder: (placeholderToMove: string, text: string) => string
28
31
  }
29
32
 
33
+ /// @internal
30
34
  export const defaultConfig: InlineSyncConfig = {
31
35
  placeholderConfig: {
32
36
  hole: '∅',
@@ -54,5 +58,15 @@ export const defaultConfig: InlineSyncConfig = {
54
58
  },
55
59
  }
56
60
 
57
- // export const inlineSyncConfigCtx = createSlice<InlineSyncConfig, 'inlineSyncConfig'>(defaultConfig, 'inlineSyncConfig')
61
+ /// A slice that contains the inline sync config.
62
+ /// You can set value to this slice to change the config.
63
+ ///
64
+ /// ```typescript
65
+ /// ctx.update(inlineSyncConfigCtx, (prevCfg) => ({
66
+ /// ...prevCfg,
67
+ /// // your config
68
+ /// }));
69
+ /// ```
70
+ ///
71
+ /// You can find the default config [here](https://github.com/Milkdown/milkdown/blob/main/packages/preset-commonmark/src/plugin/inline-sync-plugin/config.ts).
58
72
  export const inlineSyncConfig = $ctx<InlineSyncConfig, 'inlineSyncConfig'>(defaultConfig, 'inlineSyncConfig')
@@ -8,6 +8,11 @@ import { inlineSyncConfig } from './config'
8
8
  import { getContextByState } from './context'
9
9
  import { runReplacer } from './replacer'
10
10
 
11
+ /// This plugin is used to sync the inline mark.
12
+ /// It will create and remove marks automatically according to the user input.
13
+ ///
14
+ /// When users type something, the plugin will transform the line (for better performance) to real markdown AST by serializer
15
+ /// and render the AST to dom by parser, thus the input texts can be displayed correctly.
11
16
  export const inlineSyncPlugin = $prose((ctx: Ctx) => {
12
17
  let requestId: number | null = null
13
18
  const inlineSyncPluginKey = new PluginKey('MILKDOWN_INLINE_SYNC')
@@ -3,6 +3,7 @@ import { $remark } from '@milkdown/utils'
3
3
  import type { Node, Parent } from 'unist'
4
4
  import { visit } from 'unist-util-visit'
5
5
 
6
+ /// This plugin is used to add order in list for remark AST.
6
7
  export const remarkAddOrderInListPlugin = $remark(() => () => (tree: Node) => {
7
8
  visit(tree, 'list', (node: Parent & { ordered?: boolean; start?: number }) => {
8
9
  if (node.ordered) {
@@ -2,4 +2,5 @@
2
2
  import { $remark } from '@milkdown/utils'
3
3
  import remarkInlineLinks from 'remark-inline-links'
4
4
 
5
+ /// This plugin wraps [remark-inline-links](https://github.com/remarkjs/remark-inline-links).
5
6
  export const remarkInlineLinkPlugin = $remark(() => remarkInlineLinks)
@@ -3,6 +3,9 @@ import { $remark } from '@milkdown/utils'
3
3
  import type { Literal, Node, Parent } from 'unist'
4
4
  import { visit } from 'unist-util-visit'
5
5
 
6
+ /// This plugin is used to add inline line break for remark AST.
7
+ /// The inline line break should be treated as a `space`.
8
+ /// And the normal line break should be treated as a `LF`.
6
9
  export const remarkLineBreak = $remark(() => () => (tree: Node) => {
7
10
  const find = /[\t ]*(?:\r?\n|\r)/g
8
11
  visit(tree, 'text', (node: Literal, index: number, parent: Parent) => {
@@ -4,6 +4,8 @@ import type { EditorView } from '@milkdown/prose/view'
4
4
  import { $prose } from '@milkdown/utils'
5
5
  import { headingIdGenerator, headingSchema } from '../node/heading'
6
6
 
7
+ /// This plugin is used to sync the heading id when the heading content changes.
8
+ /// It will use the `headingIdGenerator` to generate the id.
7
9
  export const syncHeadingIdPlugin = $prose((ctx) => {
8
10
  const headingIdPluginKey = new PluginKey('MILKDOWN_HEADING_ID')
9
11
 
@@ -6,7 +6,7 @@ import { listItemSchema } from '../node/list-item'
6
6
 
7
7
  import { orderedListSchema } from '../node/ordered-list'
8
8
 
9
- // This plugin is used to keep the label of list item up to date in ordered list.
9
+ /// This plugin is used to keep the label of list item up to date in ordered list.
10
10
  export const syncListOrderPlugin = $prose(() => {
11
11
  const walkThrough = (state: EditorState, callback: (tr: Transaction) => void) => {
12
12
  const orderedListType = orderedListSchema.type()