@milkdown/preset-commonmark 5.4.1 → 6.0.0-next.1

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 (88) hide show
  1. package/README.md +5 -4
  2. package/lib/index.d.ts +34 -1
  3. package/lib/index.d.ts.map +1 -0
  4. package/lib/index.es.js +302 -555
  5. package/lib/index.es.js.map +1 -1
  6. package/lib/{src/mark → mark}/code-inline.d.ts +1 -1
  7. package/lib/mark/code-inline.d.ts.map +1 -0
  8. package/lib/{src/mark → mark}/em.d.ts +1 -1
  9. package/lib/mark/em.d.ts.map +1 -0
  10. package/lib/mark/index.d.ts +6 -0
  11. package/lib/mark/index.d.ts.map +1 -0
  12. package/lib/{src/mark → mark}/link.d.ts +7 -1
  13. package/lib/mark/link.d.ts.map +1 -0
  14. package/lib/{src/mark → mark}/strong.d.ts +1 -1
  15. package/lib/mark/strong.d.ts.map +1 -0
  16. package/lib/{src/node → node}/blockquote.d.ts +1 -1
  17. package/lib/node/blockquote.d.ts.map +1 -0
  18. package/lib/{src/node → node}/bullet-list.d.ts +1 -1
  19. package/lib/node/bullet-list.d.ts.map +1 -0
  20. package/lib/{src/node → node}/code-fence.d.ts +1 -1
  21. package/lib/node/code-fence.d.ts.map +1 -0
  22. package/lib/{src/node → node}/doc.d.ts +1 -1
  23. package/lib/node/doc.d.ts.map +1 -0
  24. package/lib/{src/node → node}/hardbreak.d.ts +1 -1
  25. package/lib/node/hardbreak.d.ts.map +1 -0
  26. package/lib/{src/node → node}/heading.d.ts +1 -1
  27. package/lib/node/heading.d.ts.map +1 -0
  28. package/lib/{src/node → node}/hr.d.ts +1 -1
  29. package/lib/node/hr.d.ts.map +1 -0
  30. package/lib/{src/node → node}/image.d.ts +5 -5
  31. package/lib/node/image.d.ts.map +1 -0
  32. package/lib/{src/node → node}/index.d.ts +2 -2
  33. package/lib/node/index.d.ts.map +1 -0
  34. package/lib/{src/node → node}/list-item.d.ts +1 -1
  35. package/lib/node/list-item.d.ts.map +1 -0
  36. package/lib/{src/node → node}/ordered-list.d.ts +1 -1
  37. package/lib/node/ordered-list.d.ts.map +1 -0
  38. package/lib/{src/node → node}/paragraph.d.ts +1 -1
  39. package/lib/node/paragraph.d.ts.map +1 -0
  40. package/lib/{src/node → node}/text.d.ts +1 -1
  41. package/lib/node/text.d.ts.map +1 -0
  42. package/lib/{src/plugin → plugin}/filter-html.d.ts +0 -0
  43. package/lib/plugin/filter-html.d.ts.map +1 -0
  44. package/lib/plugin/index.d.ts +2 -0
  45. package/lib/plugin/index.d.ts.map +1 -0
  46. package/lib/{src/supported-keys.d.ts → supported-keys.d.ts} +0 -0
  47. package/lib/supported-keys.d.ts.map +1 -0
  48. package/package.json +33 -10
  49. package/src/mark/code-inline.ts +2 -13
  50. package/src/mark/link.ts +96 -22
  51. package/src/mark/strong.ts +1 -7
  52. package/src/node/blockquote.ts +1 -14
  53. package/src/node/code-fence.ts +79 -187
  54. package/src/node/hardbreak.ts +2 -1
  55. package/src/node/heading.ts +14 -45
  56. package/src/node/hr.ts +1 -8
  57. package/src/node/image.ts +86 -238
  58. package/src/node/list-item.ts +34 -53
  59. package/src/node/ordered-list.ts +2 -2
  60. package/src/node/paragraph.ts +2 -10
  61. package/src/node/text.ts +1 -1
  62. package/src/plugin/filter-html.ts +10 -4
  63. package/lib/src/index.d.ts +0 -34
  64. package/lib/src/index.d.ts.map +0 -1
  65. package/lib/src/mark/code-inline.d.ts.map +0 -1
  66. package/lib/src/mark/em.d.ts.map +0 -1
  67. package/lib/src/mark/index.d.ts +0 -6
  68. package/lib/src/mark/index.d.ts.map +0 -1
  69. package/lib/src/mark/link.d.ts.map +0 -1
  70. package/lib/src/mark/strong.d.ts.map +0 -1
  71. package/lib/src/node/blockquote.d.ts.map +0 -1
  72. package/lib/src/node/bullet-list.d.ts.map +0 -1
  73. package/lib/src/node/code-fence.d.ts.map +0 -1
  74. package/lib/src/node/doc.d.ts.map +0 -1
  75. package/lib/src/node/hardbreak.d.ts.map +0 -1
  76. package/lib/src/node/heading.d.ts.map +0 -1
  77. package/lib/src/node/hr.d.ts.map +0 -1
  78. package/lib/src/node/image.d.ts.map +0 -1
  79. package/lib/src/node/index.d.ts.map +0 -1
  80. package/lib/src/node/list-item.d.ts.map +0 -1
  81. package/lib/src/node/ordered-list.d.ts.map +0 -1
  82. package/lib/src/node/paragraph.d.ts.map +0 -1
  83. package/lib/src/node/text.d.ts.map +0 -1
  84. package/lib/src/plugin/filter-html.d.ts.map +0 -1
  85. package/lib/src/plugin/index.d.ts +0 -2
  86. package/lib/src/plugin/index.d.ts.map +0 -1
  87. package/lib/src/supported-keys.d.ts.map +0 -1
  88. package/lib/src/types.d.ts +0 -5
package/src/node/image.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { createCmd, createCmdKey, themeToolCtx } from '@milkdown/core';
3
- import type { Icon } from '@milkdown/design-system';
4
- import { findSelectedNodeOfType, InputRule } from '@milkdown/prose';
2
+ import { commandsCtx, createCmd, createCmdKey, ThemeImageType, ThemeInputChipType } from '@milkdown/core';
3
+ import { EditorView, findSelectedNodeOfType, InputRule, Plugin, PluginKey } from '@milkdown/prose';
5
4
  import { createNode } from '@milkdown/utils';
6
5
 
7
6
  export const ModifyImage = createCmdKey<string>('ModifyImage');
@@ -9,132 +8,15 @@ export const InsertImage = createCmdKey<string>('InsertImage');
9
8
  const id = 'image';
10
9
  export type ImageOptions = {
11
10
  isBlock: boolean;
12
- placeholder: {
13
- loading: string;
14
- empty: string;
15
- failed: string;
11
+ placeholder: string;
12
+ input: {
13
+ placeholder: string;
14
+ buttonText?: string;
16
15
  };
17
16
  };
17
+ const key = new PluginKey('MILKDOWN_PLUGIN_IMAGE_INPUT');
18
18
 
19
19
  export const image = createNode<string, ImageOptions>((utils, options) => {
20
- const placeholder = {
21
- loading: 'Loading...',
22
- empty: 'Add an Image',
23
- failed: 'Image loads failed',
24
- ...(options?.placeholder ?? {}),
25
- };
26
- const isBlock = options?.isBlock ?? false;
27
- const containerStyle = utils.getStyle(
28
- (themeTool, { css }) =>
29
- css`
30
- display: inline-block;
31
- position: relative;
32
- text-align: center;
33
- font-size: 0;
34
- vertical-align: text-bottom;
35
- line-height: 1;
36
-
37
- ${isBlock
38
- ? `
39
- width: 100%;
40
- margin: 0 auto;
41
- `
42
- : ''}
43
-
44
- &.ProseMirror-selectednode::after {
45
- content: '';
46
- background: ${themeTool.palette('secondary', 0.38)};
47
- position: absolute;
48
- top: 0;
49
- left: 0;
50
- right: 0;
51
- bottom: 0;
52
- }
53
-
54
- img {
55
- max-width: 100%;
56
- height: auto;
57
- object-fit: contain;
58
- margin: 0 2px;
59
- }
60
- .icon,
61
- .placeholder {
62
- display: none;
63
- }
64
-
65
- &.system {
66
- width: 100%;
67
- padding: 0 2rem;
68
-
69
- img {
70
- width: 0;
71
- height: 0;
72
- display: none;
73
- }
74
-
75
- .icon,
76
- .placeholder {
77
- display: inline;
78
- }
79
-
80
- box-sizing: border-box;
81
- height: 3rem;
82
- background-color: ${themeTool.palette('background')};
83
- border-radius: ${themeTool.size.radius};
84
- display: inline-flex;
85
- gap: 2rem;
86
- justify-content: flex-start;
87
- align-items: center;
88
- .placeholder {
89
- margin: 0;
90
- line-height: 1;
91
- &::before {
92
- content: '';
93
- font-size: 0.875rem;
94
- color: ${themeTool.palette('neutral', 0.6)};
95
- }
96
- }
97
- }
98
-
99
- &.loading {
100
- .placeholder {
101
- &::before {
102
- content: '${placeholder.loading}';
103
- }
104
- }
105
- }
106
-
107
- &.empty {
108
- .placeholder {
109
- &::before {
110
- content: '${placeholder.empty}';
111
- }
112
- }
113
- }
114
-
115
- &.failed {
116
- .placeholder {
117
- &::before {
118
- content: '${placeholder.failed}';
119
- }
120
- }
121
- }
122
- `,
123
- );
124
-
125
- const style = utils.getStyle(
126
- (_, { css }) =>
127
- css`
128
- display: inline-block;
129
- margin: 0 auto;
130
- object-fit: contain;
131
- width: 100%;
132
- position: relative;
133
- height: auto;
134
- text-align: center;
135
- `,
136
- );
137
-
138
20
  return {
139
21
  id: 'image',
140
22
  schema: () => ({
@@ -150,9 +32,6 @@ export const image = createNode<string, ImageOptions>((utils, options) => {
150
32
  src: { default: '' },
151
33
  alt: { default: null },
152
34
  title: { default: null },
153
- failed: { default: false },
154
- loading: { default: true },
155
- width: { default: null },
156
35
  },
157
36
  parseDOM: [
158
37
  {
@@ -162,8 +41,6 @@ export const image = createNode<string, ImageOptions>((utils, options) => {
162
41
  throw new Error();
163
42
  }
164
43
  return {
165
- failed: dom.classList.contains('failed'),
166
- loading: dom.classList.contains('loading'),
167
44
  src: dom.getAttribute('src') || '',
168
45
  alt: dom.getAttribute('alt'),
169
46
  title: dom.getAttribute('title') || dom.getAttribute('alt'),
@@ -177,22 +54,16 @@ export const image = createNode<string, ImageOptions>((utils, options) => {
177
54
  'img',
178
55
  {
179
56
  ...node.attrs,
180
- class: utils.getClassName(
181
- node.attrs,
182
- id,
183
- node.attrs.failed ? 'failed' : '',
184
- node.attrs.loading ? 'loading' : '',
185
- style,
186
- ),
57
+ class: utils.getClassName(node.attrs, id),
187
58
  },
188
59
  ];
189
60
  },
190
61
  parseMarkdown: {
191
62
  match: ({ type }) => type === id,
192
63
  runner: (state, node, type) => {
193
- const url = node.url as string;
194
- const alt = node.alt as string;
195
- const title = node.title as string;
64
+ const url = node['url'] as string;
65
+ const alt = node['alt'] as string;
66
+ const title = node['title'] as string;
196
67
  state.addNode(type, {
197
68
  src: url,
198
69
  alt,
@@ -204,9 +75,9 @@ export const image = createNode<string, ImageOptions>((utils, options) => {
204
75
  match: (node) => node.type.name === id,
205
76
  runner: (state, node) => {
206
77
  state.addNode('image', undefined, undefined, {
207
- title: node.attrs.title,
208
- url: node.attrs.src,
209
- alt: node.attrs.alt,
78
+ title: node.attrs['title'],
79
+ url: node.attrs['src'],
80
+ alt: node.attrs['alt'],
210
81
  });
211
82
  },
212
83
  },
@@ -249,116 +120,93 @@ export const image = createNode<string, ImageOptions>((utils, options) => {
249
120
  },
250
121
  ),
251
122
  ],
252
- view: (ctx) => (node, view, getPos) => {
253
- const nodeType = node.type;
254
- const createIcon = ctx.get(themeToolCtx).slots.icon;
255
- const container = document.createElement('span');
256
- container.className = utils.getClassName(node.attrs, id, containerStyle);
257
-
258
- const content = document.createElement('img');
259
-
260
- container.append(content);
261
- let icon = createIcon('image');
262
- const placeholder = document.createElement('span');
263
- placeholder.classList.add('placeholder');
264
- container.append(icon, placeholder);
265
-
266
- const setIcon = (name: Icon) => {
267
- const nextIcon = createIcon(name);
268
- container.replaceChild(nextIcon, icon);
269
- icon = nextIcon;
270
- };
271
-
272
- const loadImage = (src: string) => {
273
- container.classList.add('system', 'loading');
274
- setIcon('loading');
275
- const img = document.createElement('img');
276
- img.src = src;
277
-
278
- img.onerror = () => {
279
- const pos = getPos();
280
- if (!pos) return;
281
-
282
- const { tr } = view.state;
283
- const _tr = tr.setNodeMarkup(pos, nodeType, {
284
- ...node.attrs,
285
- src,
286
- loading: false,
287
- failed: true,
288
- });
289
- view.dispatch(_tr);
290
- };
291
-
292
- img.onload = () => {
293
- const { tr } = view.state;
294
-
295
- const pos = getPos();
296
- if (!pos) return;
297
-
298
- const _tr = tr.setNodeMarkup(pos, nodeType, {
299
- ...node.attrs,
300
- width: img.width,
301
- src,
302
- loading: false,
303
- failed: false,
304
- });
305
- view.dispatch(_tr);
306
- };
307
- };
308
-
309
- const { src, loading, title, alt, width } = node.attrs;
310
- content.src = src;
311
- content.title = title || alt;
312
- content.alt = alt;
313
- if (width) {
314
- content.width = width;
123
+ view: () => (node) => {
124
+ let currNode = node;
125
+
126
+ const placeholder = options?.placeholder ?? 'Add an Image';
127
+ const isBlock = options?.isBlock ?? false;
128
+ const renderer = utils.themeManager.get<ThemeImageType>('image', {
129
+ placeholder,
130
+ isBlock,
131
+ });
132
+
133
+ if (!renderer) {
134
+ return {};
315
135
  }
316
136
 
317
- if (src.length === 0) {
318
- container.classList.add('system', 'empty');
319
- setIcon('image');
320
- } else if (loading) {
321
- loadImage(src);
322
- }
137
+ const { dom, onUpdate } = renderer;
138
+ onUpdate(currNode);
323
139
 
324
140
  return {
325
- dom: container,
141
+ dom,
326
142
  update: (updatedNode) => {
327
143
  if (updatedNode.type.name !== id) return false;
328
144
 
329
- const { src, alt, title, loading, failed, width } = updatedNode.attrs;
330
- content.src = src;
331
- content.alt = alt;
332
- content.title = title || alt;
333
- if (width) {
334
- content.width = width;
335
- }
336
- if (loading) {
337
- loadImage(src);
338
- return true;
339
- }
340
- if (failed) {
341
- container.classList.remove('loading', 'empty');
342
- container.classList.add('system', 'failed');
343
- setIcon('brokenImage');
344
- return true;
345
- }
346
- if (src.length > 0) {
347
- container.classList.remove('system', 'empty', 'loading');
348
- return true;
349
- }
145
+ currNode = updatedNode;
146
+ onUpdate(currNode);
350
147
 
351
- container.classList.add('system', 'empty');
352
- setIcon('image');
353
148
  return true;
354
149
  },
355
150
  selectNode: () => {
356
- container.classList.add('ProseMirror-selectednode');
151
+ dom.classList.add('ProseMirror-selectednode');
357
152
  },
358
153
  deselectNode: () => {
359
- container.classList.remove('ProseMirror-selectednode');
154
+ dom.classList.remove('ProseMirror-selectednode');
155
+ },
156
+ };
157
+ },
158
+ prosePlugins: (type, ctx) => {
159
+ const inputChipRenderer = utils.themeManager.get<ThemeInputChipType>('input-chip', {
160
+ placeholder: options?.input?.placeholder ?? 'Input Image Link',
161
+ buttonText: options?.input?.buttonText,
162
+ onUpdate: (value) => {
163
+ ctx.get(commandsCtx).call(ModifyImage, value);
360
164
  },
165
+ });
166
+ const shouldDisplay = (view: EditorView) => {
167
+ return Boolean(type && findSelectedNodeOfType(view.state.selection, type));
168
+ };
169
+ const getCurrentLink = (view: EditorView) => {
170
+ const result = findSelectedNodeOfType(view.state.selection, type);
171
+ if (!result) return;
172
+
173
+ const value = result.node.attrs['src'];
174
+ return value;
361
175
  };
176
+ const renderByView = (view: EditorView) => {
177
+ if (!view.editable) {
178
+ return;
179
+ }
180
+ const display = shouldDisplay(view);
181
+ if (display) {
182
+ inputChipRenderer.show(view);
183
+ inputChipRenderer.update(getCurrentLink(view));
184
+ } else {
185
+ inputChipRenderer.hide();
186
+ }
187
+ };
188
+ return [
189
+ new Plugin({
190
+ key,
191
+ view: (editorView) => {
192
+ inputChipRenderer.init(editorView);
193
+ renderByView(editorView);
194
+
195
+ return {
196
+ update: (view, prevState) => {
197
+ const isEqualSelection =
198
+ prevState?.doc.eq(view.state.doc) && prevState.selection.eq(view.state.selection);
199
+ if (isEqualSelection) return;
200
+
201
+ renderByView(view);
202
+ },
203
+ destroy: () => {
204
+ inputChipRenderer.destroy();
205
+ },
206
+ };
207
+ },
208
+ }),
209
+ ];
362
210
  },
363
211
  };
364
212
  });
@@ -13,59 +13,40 @@ export const SplitListItem = createCmdKey('SplitListItem');
13
13
  export const SinkListItem = createCmdKey('SinkListItem');
14
14
  export const LiftListItem = createCmdKey('LiftListItem');
15
15
 
16
- export const listItem = createNode<Keys>((utils) => {
17
- const style = utils.getStyle(
18
- (themeTool, { css }) =>
19
- css`
20
- &,
21
- & > * {
22
- margin: 0.5rem 0;
23
- }
24
-
25
- &,
26
- li {
27
- &::marker {
28
- color: ${themeTool.palette('primary')};
29
- }
30
- }
31
- `,
32
- );
33
-
34
- return {
35
- id,
36
- schema: () => ({
37
- group: 'listItem',
38
- content: 'paragraph block*',
39
- defining: true,
40
- parseDOM: [{ tag: 'li' }],
41
- toDOM: (node) => ['li', { class: utils.getClassName(node.attrs, 'list-item', style) }, 0],
42
- parseMarkdown: {
43
- match: ({ type, checked }) => type === 'listItem' && checked === null,
44
- runner: (state, node, type) => {
45
- state.openNode(type);
46
- state.next(node.children);
47
- state.closeNode();
48
- },
16
+ export const listItem = createNode<Keys>((utils) => ({
17
+ id,
18
+ schema: () => ({
19
+ group: 'listItem',
20
+ content: 'paragraph block*',
21
+ defining: true,
22
+ parseDOM: [{ tag: 'li' }],
23
+ toDOM: (node) => ['li', { class: utils.getClassName(node.attrs, 'list-item') }, 0],
24
+ parseMarkdown: {
25
+ match: ({ type, checked }) => type === 'listItem' && checked === null,
26
+ runner: (state, node, type) => {
27
+ state.openNode(type);
28
+ state.next(node.children);
29
+ state.closeNode();
49
30
  },
50
- toMarkdown: {
51
- match: (node) => node.type.name === id,
52
- runner: (state, node) => {
53
- state.openNode('listItem');
54
- state.next(node.content);
55
- state.closeNode();
56
- },
31
+ },
32
+ toMarkdown: {
33
+ match: (node) => node.type.name === id,
34
+ runner: (state, node) => {
35
+ state.openNode('listItem');
36
+ state.next(node.content);
37
+ state.closeNode();
57
38
  },
58
- }),
59
- inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
60
- commands: (nodeType) => [
61
- createCmd(SplitListItem, () => splitListItem(nodeType)),
62
- createCmd(SinkListItem, () => sinkListItem(nodeType)),
63
- createCmd(LiftListItem, () => liftListItem(nodeType)),
64
- ],
65
- shortcuts: {
66
- [SupportedKeys.NextListItem]: createShortcut(SplitListItem, 'Enter'),
67
- [SupportedKeys.SinkListItem]: createShortcut(SinkListItem, 'Mod-]'),
68
- [SupportedKeys.LiftListItem]: createShortcut(LiftListItem, 'Mod-['),
69
39
  },
70
- };
71
- });
40
+ }),
41
+ inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
42
+ commands: (nodeType) => [
43
+ createCmd(SplitListItem, () => splitListItem(nodeType)),
44
+ createCmd(SinkListItem, () => sinkListItem(nodeType)),
45
+ createCmd(LiftListItem, () => liftListItem(nodeType)),
46
+ ],
47
+ shortcuts: {
48
+ [SupportedKeys.NextListItem]: createShortcut(SplitListItem, 'Enter'),
49
+ [SupportedKeys.SinkListItem]: createShortcut(SinkListItem, 'Mod-]'),
50
+ [SupportedKeys.LiftListItem]: createShortcut(LiftListItem, 'Mod-['),
51
+ },
52
+ }));
@@ -34,7 +34,7 @@ export const orderedList = createNode<Keys>((utils) => ({
34
34
  toDOM: (node) => [
35
35
  'ol',
36
36
  {
37
- ...(node.attrs.order === 1 ? {} : node.attrs.order),
37
+ ...(node.attrs['order'] === 1 ? {} : node.attrs['order']),
38
38
  class: utils.getClassName(node.attrs, 'ordered-list'),
39
39
  },
40
40
  0,
@@ -59,7 +59,7 @@ export const orderedList = createNode<Keys>((utils) => ({
59
59
  /^(\d+)\.\s$/,
60
60
  nodeType,
61
61
  (match) => ({ order: Number(match[1]) }),
62
- (match, node) => node.childCount + node.attrs.order === Number(match[1]),
62
+ (match, node) => node.childCount + node.attrs['order'] === Number(match[1]),
63
63
  ),
64
64
  ],
65
65
  commands: (nodeType) => [createCmd(WrapInOrderedList, () => wrapIn(nodeType))],
@@ -11,21 +11,13 @@ export const TurnIntoText = createCmdKey('TurnIntoText');
11
11
 
12
12
  const id = 'paragraph';
13
13
  export const paragraph = createNode<Keys>((utils) => {
14
- const style = utils.getStyle((_, { css }) => {
15
- return css`
16
- font-size: 1rem;
17
- line-height: 1.5;
18
- letter-spacing: 0.5px;
19
- `;
20
- });
21
-
22
14
  return {
23
15
  id,
24
16
  schema: () => ({
25
17
  content: 'inline*',
26
18
  group: 'block',
27
19
  parseDOM: [{ tag: 'p' }],
28
- toDOM: (node) => ['p', { class: utils.getClassName(node.attrs, id, style) }, 0],
20
+ toDOM: (node) => ['p', { class: utils.getClassName(node.attrs, id) }, 0],
29
21
  parseMarkdown: {
30
22
  match: (node) => node.type === 'paragraph',
31
23
  runner: (state, node, type) => {
@@ -33,7 +25,7 @@ export const paragraph = createNode<Keys>((utils) => {
33
25
  if (node.children) {
34
26
  state.next(node.children);
35
27
  } else {
36
- state.addText(node.value as string);
28
+ state.addText(node['value'] as string);
37
29
  }
38
30
  state.closeNode();
39
31
  },
package/src/node/text.ts CHANGED
@@ -8,7 +8,7 @@ export const text = createNode(() => ({
8
8
  parseMarkdown: {
9
9
  match: ({ type }) => type === 'text',
10
10
  runner: (state, node) => {
11
- state.addText(node.value as string);
11
+ state.addText(node['value'] as string);
12
12
  },
13
13
  },
14
14
  toMarkdown: {
@@ -11,10 +11,16 @@ function flatMapWithDepth(ast: Node, fn: (node: Node, index: number, parent: Nod
11
11
  if (isParent(node)) {
12
12
  const out = [];
13
13
  for (let i = 0, n = node.children.length; i < n; i++) {
14
- const xs = transform(node.children[i], i, node);
15
- if (xs) {
16
- for (let j = 0, m = xs.length; j < m; j++) {
17
- out.push(xs[j]);
14
+ const nthChild = node.children[i];
15
+ if (nthChild) {
16
+ const xs = transform(nthChild, i, node);
17
+ if (xs) {
18
+ for (let j = 0, m = xs.length; j < m; j++) {
19
+ const item = xs[j];
20
+ if (item) {
21
+ out.push(item);
22
+ }
23
+ }
18
24
  }
19
25
  }
20
26
  }
@@ -1,34 +0,0 @@
1
- import { AtomList } from '@milkdown/utils';
2
- import { commonmarkPlugins } from './plugin';
3
- export * from './mark';
4
- export * from './node';
5
- export * from './supported-keys';
6
- export declare const commonmarkNodes: AtomList<(import("@milkdown/utils/lib/src/types").Metadata<import("@milkdown/utils/lib/src/types").GetPlugin<"CodeFence", {
7
- languageList?: string[] | undefined;
8
- }>> & import("@milkdown/core").MilkdownPlugin) | (import("@milkdown/utils/lib/src/types").Metadata<import("@milkdown/utils/lib/src/types").GetPlugin<string, import("./node").ImageOptions>> & import("@milkdown/core").MilkdownPlugin)>;
9
- export { commonmarkPlugins };
10
- export declare const commonmark: AtomList<(import("@milkdown/utils/lib/src/types").Metadata<import("@milkdown/utils/lib/src/types").GetPlugin<"CodeFence", {
11
- languageList?: string[] | undefined;
12
- }>> & import("@milkdown/core").MilkdownPlugin) | (import("@milkdown/utils/lib/src/types").Metadata<import("@milkdown/utils/lib/src/types").GetPlugin<string, import("./node").ImageOptions>> & import("@milkdown/core").MilkdownPlugin)>;
13
- export declare const commands: {
14
- readonly ToggleInlineCode: import("@milkdown/core").CmdKey<undefined>;
15
- readonly ToggleItalic: import("@milkdown/core").CmdKey<undefined>;
16
- readonly ToggleLink: import("@milkdown/core").CmdKey<string>;
17
- readonly ToggleBold: import("@milkdown/core").CmdKey<undefined>;
18
- readonly ModifyLink: import("@milkdown/core").CmdKey<string>;
19
- readonly ModifyImage: import("@milkdown/core").CmdKey<string>;
20
- readonly WrapInBlockquote: import("@milkdown/core").CmdKey<undefined>;
21
- readonly WrapInBulletList: import("@milkdown/core").CmdKey<undefined>;
22
- readonly WrapInOrderedList: import("@milkdown/core").CmdKey<undefined>;
23
- readonly TurnIntoCodeFence: import("@milkdown/core").CmdKey<undefined>;
24
- readonly TurnIntoHeading: import("@milkdown/core").CmdKey<number>;
25
- readonly TurnIntoText: import("@milkdown/core").CmdKey<undefined>;
26
- readonly InsertHardbreak: import("@milkdown/core").CmdKey<undefined>;
27
- readonly InsertHr: import("@milkdown/core").CmdKey<string>;
28
- readonly InsertImage: import("@milkdown/core").CmdKey<string>;
29
- readonly SplitListItem: import("@milkdown/core").CmdKey<undefined>;
30
- readonly SinkListItem: import("@milkdown/core").CmdKey<undefined>;
31
- readonly LiftListItem: import("@milkdown/core").CmdKey<undefined>;
32
- };
33
- export declare type Commands = typeof commands;
34
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAmB3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AAEjC,eAAO,MAAM,eAAe;;wOAAwC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,eAAO,MAAM,UAAU;;wOAA8D,CAAC;AAEtF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;CAwBX,CAAC;AACX,oBAAY,QAAQ,GAAG,OAAO,QAAQ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"code-inline.d.ts","sourceRoot":"","sources":["code-inline.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,gBAAgB,4CAAmC,CAAC;AAEjE,eAAO,MAAM,UAAU;;;;EAyCrB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"em.d.ts","sourceRoot":"","sources":["em.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,YAAY,4CAA+B,CAAC;AAEzD,eAAO,MAAM,EAAE;;;;EAgCZ,CAAC"}
@@ -1,6 +0,0 @@
1
- export declare const marks: (import("@milkdown/utils/lib/src/types").Metadata<import("@milkdown/utils/lib/src/types").GetPlugin<string, import("@milkdown/utils").UnknownRecord>> & import("@milkdown/core").MilkdownPlugin)[];
2
- export * from './code-inline';
3
- export * from './em';
4
- export * from './link';
5
- export * from './strong';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,KAAK,oMAAyC,CAAC;AAE5D,cAAc,eAAe,CAAC;AAC9B,cAAc,MAAM,CAAC;AACrB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["link.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,UAAU,yCAAqC,CAAC;AAC7D,eAAO,MAAM,UAAU,yCAAqC,CAAC;AAE7D,eAAO,MAAM,IAAI;;;;EA8Gf,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"strong.d.ts","sourceRoot":"","sources":["strong.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,UAAU,4CAA6B,CAAC;AACrD,eAAO,MAAM,MAAM;;;;EAwCjB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"blockquote.d.ts","sourceRoot":"","sources":["blockquote.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,gBAAgB,4CAAmC,CAAC;AAEjE,eAAO,MAAM,UAAU;;;;EAyCrB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"bullet-list.d.ts","sourceRoot":"","sources":["bullet-list.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,gBAAgB,4CAAmC,CAAC;AAEjE,eAAO,MAAM,UAAU;;;;EA8BrB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"code-fence.d.ts","sourceRoot":"","sources":["code-fence.ts"],"names":[],"mappings":"AA4BA,eAAO,MAAM,kBAAkB,QAAoC,CAAC;AACpE,eAAO,MAAM,eAAe,QAAoC,CAAC;AAEjE,eAAO,MAAM,iBAAiB,4CAAoC,CAAC;AAGnE,eAAO,MAAM,SAAS;;;;;;EA8RpB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["doc.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,GAAG;;;;EAoBd,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"hardbreak.d.ts","sourceRoot":"","sources":["hardbreak.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,eAAe,4CAAkC,CAAC;AAE/D,eAAO,MAAM,SAAS;;;;EAmEpB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["heading.ts"],"names":[],"mappings":"AAEA,OAAO,EAIH,SAAS,EAIZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMlD,aAAK,IAAI,GACH,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,CAAC;AAE1B,eAAO,MAAM,eAAe,yCAA0C,CAAC;AAEvE,eAAO,MAAM,gBAAgB,qBAAsC,CAAC;AAEpE,eAAO,MAAM,OAAO;;;;EAqKlB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"hr.d.ts","sourceRoot":"","sources":["hr.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,yCAAmC,CAAC;AACzD,eAAO,MAAM,EAAE;;;;EAyDb,CAAC"}