@milkdown/preset-commonmark 6.5.2 → 6.5.4
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/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +228 -219
- package/lib/index.es.js.map +1 -1
- package/lib/mark/code-inline.d.ts +1 -1
- package/lib/mark/code-inline.d.ts.map +1 -1
- package/lib/mark/em.d.ts +1 -1
- package/lib/mark/em.d.ts.map +1 -1
- package/lib/mark/index.d.ts.map +1 -1
- package/lib/mark/link.d.ts +4 -3
- package/lib/mark/link.d.ts.map +1 -1
- package/lib/mark/strong.d.ts +1 -1
- package/lib/mark/strong.d.ts.map +1 -1
- package/lib/node/blockquote.d.ts +1 -1
- package/lib/node/blockquote.d.ts.map +1 -1
- package/lib/node/bullet-list.d.ts +1 -1
- package/lib/node/bullet-list.d.ts.map +1 -1
- package/lib/node/code-fence.d.ts.map +1 -1
- package/lib/node/doc.d.ts +1 -1
- package/lib/node/doc.d.ts.map +1 -1
- package/lib/node/hardbreak.d.ts.map +1 -1
- package/lib/node/heading.d.ts +2 -2
- package/lib/node/heading.d.ts.map +1 -1
- package/lib/node/hr.d.ts +1 -1
- package/lib/node/hr.d.ts.map +1 -1
- package/lib/node/image.d.ts +2 -2
- package/lib/node/image.d.ts.map +1 -1
- package/lib/node/index.d.ts +1 -1
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/list-item.d.ts +2 -2
- package/lib/node/list-item.d.ts.map +1 -1
- package/lib/node/ordered-list.d.ts +1 -1
- package/lib/node/ordered-list.d.ts.map +1 -1
- package/lib/node/paragraph.d.ts +1 -1
- package/lib/node/paragraph.d.ts.map +1 -1
- package/lib/node/text.d.ts +1 -1
- package/lib/node/text.d.ts.map +1 -1
- package/lib/plugin/add-order-in-list.d.ts +1 -1
- package/lib/plugin/add-order-in-list.d.ts.map +1 -1
- package/lib/plugin/filter-html.d.ts +1 -1
- package/lib/plugin/filter-html.d.ts.map +1 -1
- package/lib/plugin/index.d.ts +1 -1
- package/lib/plugin/index.d.ts.map +1 -1
- package/lib/plugin/inline-nodes-cursor.d.ts.map +1 -1
- package/lib/plugin/inline-sync/config.d.ts +8 -8
- package/lib/plugin/inline-sync/config.d.ts.map +1 -1
- package/lib/plugin/inline-sync/context.d.ts +5 -5
- package/lib/plugin/inline-sync/context.d.ts.map +1 -1
- package/lib/plugin/inline-sync/index.d.ts +1 -1
- package/lib/plugin/inline-sync/index.d.ts.map +1 -1
- package/lib/plugin/inline-sync/regexp.d.ts.map +1 -1
- package/lib/plugin/inline-sync/replacer.d.ts +3 -3
- package/lib/plugin/inline-sync/replacer.d.ts.map +1 -1
- package/lib/plugin/inline-sync/utils.d.ts +2 -2
- package/lib/plugin/inline-sync/utils.d.ts.map +1 -1
- package/lib/supported-keys.d.ts +1 -1
- package/lib/supported-keys.d.ts.map +1 -1
- package/package.json +22 -17
- package/src/index.ts +52 -52
- package/src/mark/code-inline.ts +56 -55
- package/src/mark/em.ts +36 -36
- package/src/mark/index.ts +9 -9
- package/src/mark/link.ts +250 -223
- package/src/mark/strong.ts +37 -37
- package/src/node/blockquote.ts +35 -35
- package/src/node/bullet-list.ts +65 -65
- package/src/node/code-fence.ts +236 -229
- package/src/node/doc.ts +21 -21
- package/src/node/hardbreak.ts +108 -107
- package/src/node/heading.ts +275 -272
- package/src/node/hr.ts +55 -55
- package/src/node/image.ts +216 -210
- package/src/node/index.ts +38 -38
- package/src/node/list-item.ts +139 -140
- package/src/node/ordered-list.ts +71 -71
- package/src/node/paragraph.ts +55 -53
- package/src/node/text.ts +18 -18
- package/src/plugin/add-order-in-list.ts +15 -15
- package/src/plugin/filter-html.ts +31 -33
- package/src/plugin/index.ts +13 -13
- package/src/plugin/inline-nodes-cursor.ts +78 -79
- package/src/plugin/inline-sync/config.ts +46 -45
- package/src/plugin/inline-sync/context.ts +88 -83
- package/src/plugin/inline-sync/index.ts +46 -42
- package/src/plugin/inline-sync/regexp.ts +2 -2
- package/src/plugin/inline-sync/replacer.ts +33 -31
- package/src/plugin/inline-sync/utils.ts +53 -55
- package/src/supported-keys.ts +22 -21
package/src/node/hr.ts
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { createCmd, createCmdKey, schemaCtx } from '@milkdown/core'
|
|
3
|
-
import { InputRule } from '@milkdown/prose/inputrules'
|
|
4
|
-
import { Selection } from '@milkdown/prose/state'
|
|
5
|
-
import { createNode } from '@milkdown/utils'
|
|
2
|
+
import { createCmd, createCmdKey, schemaCtx } from '@milkdown/core'
|
|
3
|
+
import { InputRule } from '@milkdown/prose/inputrules'
|
|
4
|
+
import { Selection } from '@milkdown/prose/state'
|
|
5
|
+
import { createNode } from '@milkdown/utils'
|
|
6
6
|
|
|
7
|
-
const id = 'hr'
|
|
8
|
-
export const InsertHr = createCmdKey<string>('InsertHr')
|
|
7
|
+
const id = 'hr'
|
|
8
|
+
export const InsertHr = createCmdKey<string>('InsertHr')
|
|
9
9
|
export const hr = createNode((utils) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
10
|
+
return {
|
|
11
|
+
id,
|
|
12
|
+
schema: () => ({
|
|
13
|
+
group: 'block',
|
|
14
|
+
parseDOM: [{ tag: 'hr' }],
|
|
15
|
+
toDOM: node => ['hr', { class: utils.getClassName(node.attrs, id) }],
|
|
16
|
+
parseMarkdown: {
|
|
17
|
+
match: ({ type }) => type === 'thematicBreak',
|
|
18
|
+
runner: (state, _, type) => {
|
|
19
|
+
state.addNode(type)
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
toMarkdown: {
|
|
23
|
+
match: node => node.type.name === id,
|
|
24
|
+
runner: (state) => {
|
|
25
|
+
state.addNode('thematicBreak')
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
inputRules: type => [
|
|
30
|
+
new InputRule(/^(?:---|___\s|\*\*\*\s)$/, (state, match, start, end) => {
|
|
31
|
+
const { tr } = state
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
33
|
+
if (match[0])
|
|
34
|
+
tr.replaceWith(start - 1, end, type.create())
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
return tr
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
commands: (type, ctx) => [
|
|
40
|
+
createCmd(InsertHr, () => (state, dispatch) => {
|
|
41
|
+
if (!dispatch)
|
|
42
|
+
return true
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})
|
|
44
|
+
const paragraph = ctx.get(schemaCtx).node('paragraph')
|
|
45
|
+
const { tr, selection } = state
|
|
46
|
+
const { from } = selection
|
|
47
|
+
const node = type.create()
|
|
48
|
+
if (!node)
|
|
49
|
+
return true
|
|
50
|
+
|
|
51
|
+
const _tr = tr.replaceSelectionWith(node).insert(from, paragraph)
|
|
52
|
+
const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true)
|
|
53
|
+
if (!sel)
|
|
54
|
+
return true
|
|
55
|
+
|
|
56
|
+
dispatch(_tr.setSelection(sel).scrollIntoView())
|
|
57
|
+
return true
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
60
|
+
}
|
|
61
|
+
})
|
package/src/node/image.ts
CHANGED
|
@@ -1,218 +1,224 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
2
|
+
import type { ThemeImageType, ThemeInputChipType } from '@milkdown/core'
|
|
3
|
+
import { commandsCtx, createCmd, createCmdKey } from '@milkdown/core'
|
|
4
|
+
import { expectDomTypeError } from '@milkdown/exception'
|
|
5
|
+
import { findSelectedNodeOfType } from '@milkdown/prose'
|
|
6
|
+
import { InputRule } from '@milkdown/prose/inputrules'
|
|
7
|
+
import { Plugin, PluginKey } from '@milkdown/prose/state'
|
|
8
|
+
import type { EditorView, NodeView } from '@milkdown/prose/view'
|
|
9
|
+
import { createNode } from '@milkdown/utils'
|
|
10
|
+
|
|
11
|
+
export const ModifyImage = createCmdKey<string>('ModifyImage')
|
|
12
|
+
export const InsertImage = createCmdKey<string>('InsertImage')
|
|
13
|
+
const id = 'image'
|
|
14
|
+
export interface ImageOptions {
|
|
15
|
+
isBlock: boolean
|
|
16
|
+
placeholder: string
|
|
17
|
+
input: {
|
|
18
|
+
placeholder: string
|
|
19
|
+
buttonText?: string
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const key = new PluginKey('MILKDOWN_IMAGE_INPUT')
|
|
22
23
|
|
|
23
24
|
export const image = createNode<string, ImageOptions>((utils, options) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
toDOM: (node) => {
|
|
56
|
-
return [
|
|
57
|
-
'img',
|
|
58
|
-
{
|
|
59
|
-
...node.attrs,
|
|
60
|
-
class: utils.getClassName(node.attrs, id),
|
|
61
|
-
},
|
|
62
|
-
];
|
|
63
|
-
},
|
|
64
|
-
parseMarkdown: {
|
|
65
|
-
match: ({ type }) => type === id,
|
|
66
|
-
runner: (state, node, type) => {
|
|
67
|
-
const url = node['url'] as string;
|
|
68
|
-
const alt = node['alt'] as string;
|
|
69
|
-
const title = node['title'] as string;
|
|
70
|
-
state.addNode(type, {
|
|
71
|
-
src: url,
|
|
72
|
-
alt,
|
|
73
|
-
title,
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
toMarkdown: {
|
|
78
|
-
match: (node) => node.type.name === id,
|
|
79
|
-
runner: (state, node) => {
|
|
80
|
-
state.addNode('image', undefined, undefined, {
|
|
81
|
-
title: node.attrs['title'],
|
|
82
|
-
url: node.attrs['src'],
|
|
83
|
-
alt: node.attrs['alt'],
|
|
84
|
-
});
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
}),
|
|
88
|
-
commands: (type) => [
|
|
89
|
-
createCmd(InsertImage, (src = '') => (state, dispatch) => {
|
|
90
|
-
if (!dispatch) return true;
|
|
91
|
-
const { tr } = state;
|
|
92
|
-
const node = type.create({ src });
|
|
93
|
-
if (!node) {
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
const _tr = tr.replaceSelectionWith(node);
|
|
97
|
-
dispatch(_tr.scrollIntoView());
|
|
98
|
-
return true;
|
|
99
|
-
}),
|
|
100
|
-
createCmd(ModifyImage, (src = '') => (state, dispatch) => {
|
|
101
|
-
const node = findSelectedNodeOfType(state.selection, type);
|
|
102
|
-
if (!node) return false;
|
|
103
|
-
|
|
104
|
-
const { tr } = state;
|
|
105
|
-
dispatch?.(
|
|
106
|
-
tr.setNodeMarkup(node.pos, undefined, { ...node.node.attrs, loading: true, src }).scrollIntoView(),
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
return true;
|
|
110
|
-
}),
|
|
111
|
-
],
|
|
112
|
-
inputRules: (type) => [
|
|
113
|
-
new InputRule(
|
|
114
|
-
/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,
|
|
115
|
-
(state, match, start, end) => {
|
|
116
|
-
const [okay, alt, src = '', title] = match;
|
|
117
|
-
const { tr } = state;
|
|
118
|
-
if (okay) {
|
|
119
|
-
tr.replaceWith(start, end, type.create({ src, alt, title }));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return tr;
|
|
123
|
-
},
|
|
124
|
-
),
|
|
125
|
-
],
|
|
126
|
-
view: () => (node) => {
|
|
127
|
-
let currNode = node;
|
|
128
|
-
|
|
129
|
-
const placeholder = options?.placeholder ?? 'Add an Image';
|
|
130
|
-
const isBlock = options?.isBlock ?? false;
|
|
131
|
-
const renderer = utils.themeManager.get<ThemeImageType>('image', {
|
|
132
|
-
placeholder,
|
|
133
|
-
isBlock,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
if (!renderer) {
|
|
137
|
-
return {} as NodeView;
|
|
25
|
+
return {
|
|
26
|
+
id: 'image',
|
|
27
|
+
schema: () => ({
|
|
28
|
+
inline: true,
|
|
29
|
+
group: 'inline',
|
|
30
|
+
selectable: true,
|
|
31
|
+
draggable: true,
|
|
32
|
+
marks: '',
|
|
33
|
+
atom: true,
|
|
34
|
+
defining: true,
|
|
35
|
+
isolating: true,
|
|
36
|
+
attrs: {
|
|
37
|
+
src: { default: '' },
|
|
38
|
+
alt: { default: '' },
|
|
39
|
+
title: { default: '' },
|
|
40
|
+
},
|
|
41
|
+
parseDOM: [
|
|
42
|
+
{
|
|
43
|
+
tag: 'img[src]',
|
|
44
|
+
getAttrs: (dom) => {
|
|
45
|
+
if (!(dom instanceof HTMLElement))
|
|
46
|
+
throw expectDomTypeError(dom)
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
src: dom.getAttribute('src') || '',
|
|
50
|
+
alt: dom.getAttribute('alt') || '',
|
|
51
|
+
title: dom.getAttribute('title') || dom.getAttribute('alt') || '',
|
|
138
52
|
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
toDOM: (node) => {
|
|
57
|
+
return [
|
|
58
|
+
'img',
|
|
59
|
+
{
|
|
60
|
+
...node.attrs,
|
|
61
|
+
class: utils.getClassName(node.attrs, id),
|
|
62
|
+
},
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
parseMarkdown: {
|
|
66
|
+
match: ({ type }) => type === id,
|
|
67
|
+
runner: (state, node, type) => {
|
|
68
|
+
const url = node.url as string
|
|
69
|
+
const alt = node.alt as string
|
|
70
|
+
const title = node.title as string
|
|
71
|
+
state.addNode(type, {
|
|
72
|
+
src: url,
|
|
73
|
+
alt,
|
|
74
|
+
title,
|
|
75
|
+
})
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
toMarkdown: {
|
|
79
|
+
match: node => node.type.name === id,
|
|
80
|
+
runner: (state, node) => {
|
|
81
|
+
state.addNode('image', undefined, undefined, {
|
|
82
|
+
title: node.attrs.title,
|
|
83
|
+
url: node.attrs.src,
|
|
84
|
+
alt: node.attrs.alt,
|
|
85
|
+
})
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
commands: type => [
|
|
90
|
+
createCmd(InsertImage, (src = '') => (state, dispatch) => {
|
|
91
|
+
if (!dispatch)
|
|
92
|
+
return true
|
|
93
|
+
const { tr } = state
|
|
94
|
+
const node = type.create({ src })
|
|
95
|
+
if (!node)
|
|
96
|
+
return true
|
|
139
97
|
|
|
140
|
-
|
|
141
|
-
|
|
98
|
+
const _tr = tr.replaceSelectionWith(node)
|
|
99
|
+
dispatch(_tr.scrollIntoView())
|
|
100
|
+
return true
|
|
101
|
+
}),
|
|
102
|
+
createCmd(ModifyImage, (src = '') => (state, dispatch) => {
|
|
103
|
+
const node = findSelectedNodeOfType(state.selection, type)
|
|
104
|
+
if (!node)
|
|
105
|
+
return false
|
|
142
106
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
107
|
+
const { tr } = state
|
|
108
|
+
dispatch?.(
|
|
109
|
+
tr.setNodeMarkup(node.pos, undefined, { ...node.node.attrs, loading: true, src }).scrollIntoView(),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
return true
|
|
113
|
+
}),
|
|
114
|
+
],
|
|
115
|
+
inputRules: type => [
|
|
116
|
+
new InputRule(
|
|
117
|
+
/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,
|
|
118
|
+
(state, match, start, end) => {
|
|
119
|
+
const [okay, alt, src = '', title] = match
|
|
120
|
+
const { tr } = state
|
|
121
|
+
if (okay)
|
|
122
|
+
tr.replaceWith(start, end, type.create({ src, alt, title }))
|
|
123
|
+
|
|
124
|
+
return tr
|
|
125
|
+
},
|
|
126
|
+
),
|
|
127
|
+
],
|
|
128
|
+
view: () => (node) => {
|
|
129
|
+
let currNode = node
|
|
130
|
+
|
|
131
|
+
const placeholder = options?.placeholder ?? 'Add an Image'
|
|
132
|
+
const isBlock = options?.isBlock ?? false
|
|
133
|
+
const renderer = utils.themeManager.get<ThemeImageType>('image', {
|
|
134
|
+
placeholder,
|
|
135
|
+
isBlock,
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
if (!renderer)
|
|
139
|
+
return {} as NodeView
|
|
140
|
+
|
|
141
|
+
const { dom, onUpdate } = renderer
|
|
142
|
+
onUpdate(currNode)
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
dom,
|
|
146
|
+
update: (updatedNode) => {
|
|
147
|
+
if (updatedNode.type.name !== id)
|
|
148
|
+
return false
|
|
149
|
+
|
|
150
|
+
currNode = updatedNode
|
|
151
|
+
onUpdate(currNode)
|
|
152
|
+
|
|
153
|
+
return true
|
|
154
|
+
},
|
|
155
|
+
selectNode: () => {
|
|
156
|
+
dom.classList.add('ProseMirror-selectednode')
|
|
160
157
|
},
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
new Plugin({
|
|
164
|
-
key,
|
|
165
|
-
view: (editorView) => {
|
|
166
|
-
const inputChipRenderer = utils.themeManager.get<ThemeInputChipType>('input-chip', {
|
|
167
|
-
placeholder: options?.input?.placeholder ?? 'Input Image Link',
|
|
168
|
-
buttonText: options?.input?.buttonText,
|
|
169
|
-
onUpdate: (value) => {
|
|
170
|
-
ctx.get(commandsCtx).call(ModifyImage, value);
|
|
171
|
-
},
|
|
172
|
-
});
|
|
173
|
-
if (!inputChipRenderer) return {};
|
|
174
|
-
const shouldDisplay = (view: EditorView) => {
|
|
175
|
-
return Boolean(
|
|
176
|
-
view.hasFocus() && type && findSelectedNodeOfType(view.state.selection, type),
|
|
177
|
-
);
|
|
178
|
-
};
|
|
179
|
-
const getCurrentLink = (view: EditorView) => {
|
|
180
|
-
const result = findSelectedNodeOfType(view.state.selection, type);
|
|
181
|
-
if (!result) return;
|
|
182
|
-
|
|
183
|
-
const value = result.node.attrs['src'];
|
|
184
|
-
return value;
|
|
185
|
-
};
|
|
186
|
-
const renderByView = (view: EditorView) => {
|
|
187
|
-
if (!view.editable) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
const display = shouldDisplay(view);
|
|
191
|
-
if (display) {
|
|
192
|
-
inputChipRenderer.show(view);
|
|
193
|
-
inputChipRenderer.update(getCurrentLink(view));
|
|
194
|
-
} else {
|
|
195
|
-
inputChipRenderer.hide();
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
inputChipRenderer.init(editorView);
|
|
199
|
-
renderByView(editorView);
|
|
200
|
-
|
|
201
|
-
return {
|
|
202
|
-
update: (view, prevState) => {
|
|
203
|
-
const isEqualSelection =
|
|
204
|
-
prevState?.doc.eq(view.state.doc) && prevState.selection.eq(view.state.selection);
|
|
205
|
-
if (isEqualSelection) return;
|
|
206
|
-
|
|
207
|
-
renderByView(view);
|
|
208
|
-
},
|
|
209
|
-
destroy: () => {
|
|
210
|
-
inputChipRenderer.destroy();
|
|
211
|
-
},
|
|
212
|
-
};
|
|
213
|
-
},
|
|
214
|
-
}),
|
|
215
|
-
];
|
|
158
|
+
deselectNode: () => {
|
|
159
|
+
dom.classList.remove('ProseMirror-selectednode')
|
|
216
160
|
},
|
|
217
|
-
|
|
218
|
-
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
prosePlugins: (type, ctx) => {
|
|
164
|
+
return [
|
|
165
|
+
new Plugin({
|
|
166
|
+
key,
|
|
167
|
+
view: (editorView) => {
|
|
168
|
+
const inputChipRenderer = utils.themeManager.get<ThemeInputChipType>('input-chip', {
|
|
169
|
+
placeholder: options?.input?.placeholder ?? 'Input Image Link',
|
|
170
|
+
buttonText: options?.input?.buttonText,
|
|
171
|
+
onUpdate: (value) => {
|
|
172
|
+
ctx.get(commandsCtx).call(ModifyImage, value)
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
if (!inputChipRenderer)
|
|
176
|
+
return {}
|
|
177
|
+
const shouldDisplay = (view: EditorView) => {
|
|
178
|
+
return Boolean(
|
|
179
|
+
view.hasFocus() && type && findSelectedNodeOfType(view.state.selection, type),
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
const getCurrentLink = (view: EditorView) => {
|
|
183
|
+
const result = findSelectedNodeOfType(view.state.selection, type)
|
|
184
|
+
if (!result)
|
|
185
|
+
return
|
|
186
|
+
|
|
187
|
+
const value = result.node.attrs.src
|
|
188
|
+
return value
|
|
189
|
+
}
|
|
190
|
+
const renderByView = (view: EditorView) => {
|
|
191
|
+
if (!view.editable)
|
|
192
|
+
return
|
|
193
|
+
|
|
194
|
+
const display = shouldDisplay(view)
|
|
195
|
+
if (display) {
|
|
196
|
+
inputChipRenderer.show(view)
|
|
197
|
+
inputChipRenderer.update(getCurrentLink(view))
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
inputChipRenderer.hide()
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
inputChipRenderer.init(editorView)
|
|
204
|
+
renderByView(editorView)
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
update: (view, prevState) => {
|
|
208
|
+
const isEqualSelection
|
|
209
|
+
= prevState?.doc.eq(view.state.doc) && prevState.selection.eq(view.state.selection)
|
|
210
|
+
if (isEqualSelection)
|
|
211
|
+
return
|
|
212
|
+
|
|
213
|
+
renderByView(view)
|
|
214
|
+
},
|
|
215
|
+
destroy: () => {
|
|
216
|
+
inputChipRenderer.destroy()
|
|
217
|
+
},
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
}),
|
|
221
|
+
]
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
})
|
package/src/node/index.ts
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { AtomPlugin } from '@milkdown/utils'
|
|
2
|
+
import type { AtomPlugin } from '@milkdown/utils'
|
|
3
3
|
|
|
4
|
-
import { blockquote } from './blockquote'
|
|
5
|
-
import { bulletList } from './bullet-list'
|
|
6
|
-
import { codeFence } from './code-fence'
|
|
7
|
-
import { doc } from './doc'
|
|
8
|
-
import { hardbreak } from './hardbreak'
|
|
9
|
-
import { heading } from './heading'
|
|
10
|
-
import { hr } from './hr'
|
|
11
|
-
import { image } from './image'
|
|
12
|
-
import { listItem } from './list-item'
|
|
13
|
-
import { orderedList } from './ordered-list'
|
|
14
|
-
import { paragraph } from './paragraph'
|
|
15
|
-
import { text } from './text'
|
|
4
|
+
import { blockquote } from './blockquote'
|
|
5
|
+
import { bulletList } from './bullet-list'
|
|
6
|
+
import { codeFence } from './code-fence'
|
|
7
|
+
import { doc } from './doc'
|
|
8
|
+
import { hardbreak } from './hardbreak'
|
|
9
|
+
import { heading } from './heading'
|
|
10
|
+
import { hr } from './hr'
|
|
11
|
+
import { image } from './image'
|
|
12
|
+
import { listItem } from './list-item'
|
|
13
|
+
import { orderedList } from './ordered-list'
|
|
14
|
+
import { paragraph } from './paragraph'
|
|
15
|
+
import { text } from './text'
|
|
16
16
|
|
|
17
17
|
export const nodes: AtomPlugin[] = [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
]
|
|
18
|
+
doc(),
|
|
19
|
+
paragraph(),
|
|
20
|
+
hardbreak(),
|
|
21
|
+
blockquote(),
|
|
22
|
+
codeFence(),
|
|
23
|
+
bulletList(),
|
|
24
|
+
orderedList(),
|
|
25
|
+
listItem(),
|
|
26
|
+
heading(),
|
|
27
|
+
hr(),
|
|
28
|
+
image(),
|
|
29
|
+
text(),
|
|
30
|
+
]
|
|
31
31
|
|
|
32
|
-
export * from './blockquote'
|
|
33
|
-
export * from './bullet-list'
|
|
34
|
-
export * from './code-fence'
|
|
35
|
-
export * from './doc'
|
|
36
|
-
export * from './hardbreak'
|
|
37
|
-
export * from './heading'
|
|
38
|
-
export * from './hr'
|
|
39
|
-
export * from './image'
|
|
40
|
-
export * from './list-item'
|
|
41
|
-
export * from './ordered-list'
|
|
42
|
-
export * from './paragraph'
|
|
43
|
-
export * from './text'
|
|
32
|
+
export * from './blockquote'
|
|
33
|
+
export * from './bullet-list'
|
|
34
|
+
export * from './code-fence'
|
|
35
|
+
export * from './doc'
|
|
36
|
+
export * from './hardbreak'
|
|
37
|
+
export * from './heading'
|
|
38
|
+
export * from './hr'
|
|
39
|
+
export * from './image'
|
|
40
|
+
export * from './list-item'
|
|
41
|
+
export * from './ordered-list'
|
|
42
|
+
export * from './paragraph'
|
|
43
|
+
export * from './text'
|