@milkdown/preset-commonmark 5.4.0 → 6.0.0-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.
- package/README.md +5 -4
- package/lib/index.d.ts +34 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.es.js +320 -573
- package/lib/index.es.js.map +1 -1
- package/lib/{src/mark → mark}/code-inline.d.ts +1 -1
- package/lib/mark/code-inline.d.ts.map +1 -0
- package/lib/{src/mark → mark}/em.d.ts +1 -1
- package/lib/mark/em.d.ts.map +1 -0
- package/lib/mark/index.d.ts +6 -0
- package/lib/mark/index.d.ts.map +1 -0
- package/lib/{src/mark → mark}/link.d.ts +7 -1
- package/lib/mark/link.d.ts.map +1 -0
- package/lib/{src/mark → mark}/strong.d.ts +1 -1
- package/lib/mark/strong.d.ts.map +1 -0
- package/lib/{src/node → node}/blockquote.d.ts +1 -1
- package/lib/node/blockquote.d.ts.map +1 -0
- package/lib/{src/node → node}/bullet-list.d.ts +1 -1
- package/lib/node/bullet-list.d.ts.map +1 -0
- package/lib/{src/node → node}/code-fence.d.ts +1 -1
- package/lib/node/code-fence.d.ts.map +1 -0
- package/lib/{src/node → node}/doc.d.ts +1 -1
- package/lib/node/doc.d.ts.map +1 -0
- package/lib/{src/node → node}/hardbreak.d.ts +1 -1
- package/lib/node/hardbreak.d.ts.map +1 -0
- package/lib/{src/node → node}/heading.d.ts +1 -1
- package/lib/node/heading.d.ts.map +1 -0
- package/lib/{src/node → node}/hr.d.ts +1 -1
- package/lib/node/hr.d.ts.map +1 -0
- package/lib/{src/node → node}/image.d.ts +5 -5
- package/lib/node/image.d.ts.map +1 -0
- package/lib/{src/node → node}/index.d.ts +2 -2
- package/lib/node/index.d.ts.map +1 -0
- package/lib/{src/node → node}/list-item.d.ts +1 -1
- package/lib/node/list-item.d.ts.map +1 -0
- package/lib/{src/node → node}/ordered-list.d.ts +1 -1
- package/lib/node/ordered-list.d.ts.map +1 -0
- package/lib/{src/node → node}/paragraph.d.ts +1 -1
- package/lib/node/paragraph.d.ts.map +1 -0
- package/lib/{src/node → node}/text.d.ts +1 -1
- package/lib/node/text.d.ts.map +1 -0
- package/lib/{src/plugin → plugin}/filter-html.d.ts +0 -0
- package/lib/plugin/filter-html.d.ts.map +1 -0
- package/lib/plugin/index.d.ts +2 -0
- package/lib/plugin/index.d.ts.map +1 -0
- package/lib/{src/supported-keys.d.ts → supported-keys.d.ts} +0 -0
- package/lib/supported-keys.d.ts.map +1 -0
- package/package.json +33 -10
- package/src/mark/code-inline.ts +3 -14
- package/src/mark/em.ts +1 -1
- package/src/mark/link.ts +98 -24
- package/src/mark/strong.ts +2 -8
- package/src/node/blockquote.ts +2 -15
- package/src/node/bullet-list.ts +1 -1
- package/src/node/code-fence.ts +80 -188
- package/src/node/hardbreak.ts +3 -2
- package/src/node/heading.ts +15 -46
- package/src/node/hr.ts +2 -9
- package/src/node/image.ts +88 -240
- package/src/node/list-item.ts +37 -56
- package/src/node/ordered-list.ts +3 -3
- package/src/node/paragraph.ts +3 -11
- package/src/node/text.ts +1 -1
- package/src/plugin/filter-html.ts +10 -4
- package/lib/src/index.d.ts +0 -34
- package/lib/src/index.d.ts.map +0 -1
- package/lib/src/mark/code-inline.d.ts.map +0 -1
- package/lib/src/mark/em.d.ts.map +0 -1
- package/lib/src/mark/index.d.ts +0 -6
- package/lib/src/mark/index.d.ts.map +0 -1
- package/lib/src/mark/link.d.ts.map +0 -1
- package/lib/src/mark/strong.d.ts.map +0 -1
- package/lib/src/node/blockquote.d.ts.map +0 -1
- package/lib/src/node/bullet-list.d.ts.map +0 -1
- package/lib/src/node/code-fence.d.ts.map +0 -1
- package/lib/src/node/doc.d.ts.map +0 -1
- package/lib/src/node/hardbreak.d.ts.map +0 -1
- package/lib/src/node/heading.d.ts.map +0 -1
- package/lib/src/node/hr.d.ts.map +0 -1
- package/lib/src/node/image.d.ts.map +0 -1
- package/lib/src/node/index.d.ts.map +0 -1
- package/lib/src/node/list-item.d.ts.map +0 -1
- package/lib/src/node/ordered-list.d.ts.map +0 -1
- package/lib/src/node/paragraph.d.ts.map +0 -1
- package/lib/src/node/text.d.ts.map +0 -1
- package/lib/src/plugin/filter-html.d.ts.map +0 -1
- package/lib/src/plugin/index.d.ts +0 -2
- package/lib/src/plugin/index.d.ts.map +0 -1
- package/lib/src/supported-keys.d.ts.map +0 -1
- package/lib/src/types.d.ts +0 -5
package/src/node/image.ts
CHANGED
|
@@ -1,140 +1,22 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { createCmd, createCmdKey,
|
|
3
|
-
import
|
|
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
|
-
export const ModifyImage = createCmdKey<string>();
|
|
8
|
-
export const InsertImage = createCmdKey<string>();
|
|
6
|
+
export const ModifyImage = createCmdKey<string>('ModifyImage');
|
|
7
|
+
export const InsertImage = createCmdKey<string>('InsertImage');
|
|
9
8
|
const id = 'image';
|
|
10
9
|
export type ImageOptions = {
|
|
11
10
|
isBlock: boolean;
|
|
12
|
-
placeholder:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
194
|
-
const alt = node
|
|
195
|
-
const title = node
|
|
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
|
|
208
|
-
url: node.attrs
|
|
209
|
-
alt: node.attrs
|
|
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: (
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
318
|
-
|
|
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
|
|
141
|
+
dom,
|
|
326
142
|
update: (updatedNode) => {
|
|
327
143
|
if (updatedNode.type.name !== id) return false;
|
|
328
144
|
|
|
329
|
-
|
|
330
|
-
|
|
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
|
-
|
|
151
|
+
dom.classList.add('ProseMirror-selectednode');
|
|
357
152
|
},
|
|
358
153
|
deselectNode: () => {
|
|
359
|
-
|
|
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
|
});
|
package/src/node/list-item.ts
CHANGED
|
@@ -9,63 +9,44 @@ type Keys = SupportedKeys['SinkListItem'] | SupportedKeys['LiftListItem'] | Supp
|
|
|
9
9
|
|
|
10
10
|
const id = 'list_item';
|
|
11
11
|
|
|
12
|
-
export const SplitListItem = createCmdKey();
|
|
13
|
-
export const SinkListItem = createCmdKey();
|
|
14
|
-
export const LiftListItem = createCmdKey();
|
|
12
|
+
export const SplitListItem = createCmdKey('SplitListItem');
|
|
13
|
+
export const SinkListItem = createCmdKey('SinkListItem');
|
|
14
|
+
export const LiftListItem = createCmdKey('LiftListItem');
|
|
15
15
|
|
|
16
|
-
export const listItem = createNode<Keys>((utils) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
}));
|
package/src/node/ordered-list.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { SupportedKeys } from '../supported-keys';
|
|
|
7
7
|
|
|
8
8
|
type Keys = SupportedKeys['OrderedList'];
|
|
9
9
|
|
|
10
|
-
export const WrapInOrderedList = createCmdKey();
|
|
10
|
+
export const WrapInOrderedList = createCmdKey('WrapInOrderedList');
|
|
11
11
|
|
|
12
12
|
const id = 'ordered_list';
|
|
13
13
|
export const orderedList = createNode<Keys>((utils) => ({
|
|
@@ -34,7 +34,7 @@ export const orderedList = createNode<Keys>((utils) => ({
|
|
|
34
34
|
toDOM: (node) => [
|
|
35
35
|
'ol',
|
|
36
36
|
{
|
|
37
|
-
...(node.attrs
|
|
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
|
|
62
|
+
(match, node) => node.childCount + node.attrs['order'] === Number(match[1]),
|
|
63
63
|
),
|
|
64
64
|
],
|
|
65
65
|
commands: (nodeType) => [createCmd(WrapInOrderedList, () => wrapIn(nodeType))],
|
package/src/node/paragraph.ts
CHANGED
|
@@ -7,25 +7,17 @@ import { SupportedKeys } from '../supported-keys';
|
|
|
7
7
|
|
|
8
8
|
type Keys = SupportedKeys['Text'];
|
|
9
9
|
|
|
10
|
-
export const TurnIntoText = createCmdKey();
|
|
10
|
+
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
|
|
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
|
|
28
|
+
state.addText(node['value'] as string);
|
|
37
29
|
}
|
|
38
30
|
state.closeNode();
|
|
39
31
|
},
|
package/src/node/text.ts
CHANGED
|
@@ -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
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
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
|
}
|
package/lib/src/index.d.ts
DELETED
|
@@ -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
|
package/lib/src/index.d.ts.map
DELETED
|
@@ -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,4CAAiB,CAAC;AAE/C,eAAO,MAAM,UAAU;;;;EAyCrB,CAAC"}
|
package/lib/src/mark/em.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"em.d.ts","sourceRoot":"","sources":["em.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,YAAY,4CAAiB,CAAC;AAE3C,eAAO,MAAM,EAAE;;;;EAgCZ,CAAC"}
|
package/lib/src/mark/index.d.ts
DELETED
|
@@ -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,yCAAyB,CAAC;AACjD,eAAO,MAAM,UAAU,yCAAyB,CAAC;AAEjD,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,4CAAiB,CAAC;AACzC,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,4CAAiB,CAAC;AAE/C,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,4CAAiB,CAAC;AAE/C,eAAO,MAAM,UAAU;;;;EA8BrB,CAAC"}
|