@milkdown/preset-gfm 5.5.0 → 6.0.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 +4 -4
- package/lib/{src/auto-link.d.ts → auto-link.d.ts} +0 -0
- package/lib/auto-link.d.ts.map +1 -0
- package/lib/footnote/definition.d.ts +7 -0
- package/lib/footnote/definition.d.ts.map +1 -0
- package/lib/footnote/index.d.ts +3 -0
- package/lib/footnote/index.d.ts.map +1 -0
- package/lib/footnote/reference.d.ts +7 -0
- package/lib/footnote/reference.d.ts.map +1 -0
- package/lib/footnote/utils.d.ts +3 -0
- package/lib/footnote/utils.d.ts.map +1 -0
- package/lib/index.d.ts +37 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.es.js +569 -426
- package/lib/index.es.js.map +1 -1
- package/lib/{src/strike-through.d.ts → strike-through.d.ts} +1 -1
- package/lib/strike-through.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/lib/{src/table → table}/command.d.ts +0 -0
- package/lib/table/command.d.ts.map +1 -0
- package/lib/{src/table → table}/index.d.ts +0 -0
- package/lib/table/index.d.ts.map +1 -0
- package/lib/{src/table → table}/nodes/index.d.ts +3 -3
- package/lib/table/nodes/index.d.ts.map +1 -0
- package/lib/{src/table → table}/nodes/schema.d.ts +0 -0
- package/lib/table/nodes/schema.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/actions.d.ts +0 -0
- package/lib/table/operator-plugin/actions.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/calc-pos.d.ts +0 -0
- package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/constant.d.ts +0 -0
- package/lib/table/operator-plugin/constant.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/helper.d.ts +0 -0
- package/lib/table/operator-plugin/helper.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/index.d.ts +0 -0
- package/lib/table/operator-plugin/index.d.ts.map +1 -0
- package/lib/table/operator-plugin/style.d.ts +3 -0
- package/lib/table/operator-plugin/style.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/widget.d.ts +0 -0
- package/lib/table/operator-plugin/widget.d.ts.map +1 -0
- package/lib/{src/table → table}/utils.d.ts +1 -0
- package/lib/table/utils.d.ts.map +1 -0
- package/lib/{src/task-list-item.d.ts → task-list-item.d.ts} +1 -1
- package/lib/task-list-item.d.ts.map +1 -0
- package/package.json +36 -12
- package/src/footnote/definition.ts +184 -0
- package/src/footnote/index.ts +3 -0
- package/src/footnote/reference.ts +171 -0
- package/src/footnote/utils.ts +4 -0
- package/src/index.ts +5 -0
- package/src/strike-through.ts +2 -9
- package/src/table/nodes/index.ts +0 -2
- package/src/table/operator-plugin/actions.ts +9 -9
- package/src/table/operator-plugin/index.ts +9 -8
- package/src/table/operator-plugin/style.ts +109 -37
- package/src/table/operator-plugin/widget.ts +3 -4
- package/src/task-list-item.ts +62 -127
- package/lib/src/auto-link.d.ts.map +0 -1
- package/lib/src/index.d.ts +0 -36
- package/lib/src/index.d.ts.map +0 -1
- package/lib/src/strike-through.d.ts.map +0 -1
- package/lib/src/supported-keys.d.ts.map +0 -1
- package/lib/src/table/command.d.ts.map +0 -1
- package/lib/src/table/index.d.ts.map +0 -1
- package/lib/src/table/nodes/index.d.ts.map +0 -1
- package/lib/src/table/nodes/schema.d.ts.map +0 -1
- package/lib/src/table/nodes/style.d.ts +0 -3
- package/lib/src/table/nodes/style.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/actions.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/calc-pos.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/constant.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/helper.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/index.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/style.d.ts +0 -3
- package/lib/src/table/operator-plugin/style.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/widget.d.ts.map +0 -1
- package/lib/src/table/utils.d.ts.map +0 -1
- package/lib/src/task-list-item.d.ts.map +0 -1
- package/src/table/nodes/style.ts +0 -170
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
|
|
3
|
+
import { commandsCtx, createCmd, createCmdKey, editorViewCtx, ThemeInputChipType } from '@milkdown/core';
|
|
4
|
+
import {
|
|
5
|
+
EditorView,
|
|
6
|
+
findSelectedNodeOfType,
|
|
7
|
+
NodeSelection,
|
|
8
|
+
Plugin,
|
|
9
|
+
PluginKey,
|
|
10
|
+
wrappingInputRule,
|
|
11
|
+
} from '@milkdown/prose';
|
|
12
|
+
import { createNode } from '@milkdown/utils';
|
|
13
|
+
|
|
14
|
+
import { getFootnoteDefId, getFootnoteRefId } from './utils';
|
|
15
|
+
|
|
16
|
+
const key = new PluginKey('MILKDOWN_PLUGIN_FOOTNOTE_DEF_INPUT');
|
|
17
|
+
export const ModifyFootnoteDef = createCmdKey<string>('ModifyFootnoteDef');
|
|
18
|
+
|
|
19
|
+
export const footnoteDefinition = createNode((utils) => {
|
|
20
|
+
const id = 'footnote_definition';
|
|
21
|
+
const markdownId = 'footnoteDefinition';
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
id,
|
|
25
|
+
schema: (ctx) => ({
|
|
26
|
+
group: 'block',
|
|
27
|
+
content: 'block+',
|
|
28
|
+
defining: true,
|
|
29
|
+
attrs: {
|
|
30
|
+
label: {
|
|
31
|
+
default: '',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
parseDOM: [
|
|
35
|
+
{
|
|
36
|
+
tag: `div[data-type="${id}"]`,
|
|
37
|
+
getAttrs: (dom) => {
|
|
38
|
+
if (!(dom instanceof HTMLElement)) {
|
|
39
|
+
throw new Error();
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
label: dom.dataset['label'],
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
toDOM: (node) => {
|
|
48
|
+
const label = node.attrs['label'];
|
|
49
|
+
const className = utils.getClassName(node.attrs, 'footnote-definition');
|
|
50
|
+
|
|
51
|
+
const dt = document.createElement('dt');
|
|
52
|
+
dt.textContent = `[${label}]:`;
|
|
53
|
+
dt.onclick = () => {
|
|
54
|
+
const view = ctx.get(editorViewCtx);
|
|
55
|
+
const selection = NodeSelection.create(view.state.doc, view.state.selection.from - 2);
|
|
56
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const a = document.createElement('a');
|
|
60
|
+
a.href = `#${getFootnoteRefId(label)}`;
|
|
61
|
+
a.contentEditable = 'false';
|
|
62
|
+
a.textContent = '↩';
|
|
63
|
+
a.onmousedown = (e) => {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return [
|
|
68
|
+
'div',
|
|
69
|
+
{
|
|
70
|
+
class: className,
|
|
71
|
+
'data-label': label,
|
|
72
|
+
'data-type': id,
|
|
73
|
+
id: getFootnoteDefId(label),
|
|
74
|
+
},
|
|
75
|
+
['div', { class: 'footnote-definition_content' }, dt, ['dd', 0]],
|
|
76
|
+
['div', { class: 'footnote-definition_anchor' }, a],
|
|
77
|
+
];
|
|
78
|
+
},
|
|
79
|
+
parseMarkdown: {
|
|
80
|
+
match: ({ type }) => type === markdownId,
|
|
81
|
+
runner: (state, node, type) => {
|
|
82
|
+
state
|
|
83
|
+
.openNode(type, {
|
|
84
|
+
label: node['label'] as string,
|
|
85
|
+
})
|
|
86
|
+
.next(node.children)
|
|
87
|
+
.closeNode();
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
toMarkdown: {
|
|
91
|
+
match: (node) => node.type.name === id,
|
|
92
|
+
runner: (state, node) => {
|
|
93
|
+
state
|
|
94
|
+
.openNode(markdownId, undefined, {
|
|
95
|
+
label: node.attrs['label'],
|
|
96
|
+
identifier: node.attrs['label'],
|
|
97
|
+
})
|
|
98
|
+
.next(node.content)
|
|
99
|
+
.closeNode();
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
103
|
+
commands: (nodeType) => [
|
|
104
|
+
createCmd(ModifyFootnoteDef, (label = '') => (state, dispatch) => {
|
|
105
|
+
const node = findSelectedNodeOfType(state.selection, nodeType);
|
|
106
|
+
if (!node) return false;
|
|
107
|
+
|
|
108
|
+
const { tr } = state;
|
|
109
|
+
const _tr = tr.setNodeMarkup(node.pos, undefined, { ...node.node.attrs, label });
|
|
110
|
+
dispatch?.(_tr.setSelection(NodeSelection.create(_tr.doc, node.pos)));
|
|
111
|
+
|
|
112
|
+
return true;
|
|
113
|
+
}),
|
|
114
|
+
],
|
|
115
|
+
inputRules: (nodeType) => [
|
|
116
|
+
wrappingInputRule(
|
|
117
|
+
/(?:\[\^)([^:]+)(?::)$/,
|
|
118
|
+
nodeType,
|
|
119
|
+
(match) => {
|
|
120
|
+
const label = match[1] ?? 'footnote';
|
|
121
|
+
return {
|
|
122
|
+
label,
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
() => false,
|
|
126
|
+
),
|
|
127
|
+
],
|
|
128
|
+
prosePlugins: (type, ctx) => {
|
|
129
|
+
return [
|
|
130
|
+
new Plugin({
|
|
131
|
+
key,
|
|
132
|
+
view: (editorView) => {
|
|
133
|
+
const inputChipRenderer = utils.themeManager.get<ThemeInputChipType>('input-chip', {
|
|
134
|
+
width: '12em',
|
|
135
|
+
placeholder: 'Input Footnote Label',
|
|
136
|
+
onUpdate: (value) => {
|
|
137
|
+
ctx.get(commandsCtx).call(ModifyFootnoteDef, value);
|
|
138
|
+
},
|
|
139
|
+
isBindMode: true,
|
|
140
|
+
});
|
|
141
|
+
if (!inputChipRenderer) return {};
|
|
142
|
+
const shouldDisplay = (view: EditorView) => {
|
|
143
|
+
return Boolean(type && findSelectedNodeOfType(view.state.selection, type));
|
|
144
|
+
};
|
|
145
|
+
const getCurrentLabel = (view: EditorView) => {
|
|
146
|
+
const result = findSelectedNodeOfType(view.state.selection, type);
|
|
147
|
+
if (!result) return;
|
|
148
|
+
|
|
149
|
+
const value = result.node.attrs['label'];
|
|
150
|
+
return value;
|
|
151
|
+
};
|
|
152
|
+
const renderByView = (view: EditorView) => {
|
|
153
|
+
if (!view.editable) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const display = shouldDisplay(view);
|
|
157
|
+
if (display) {
|
|
158
|
+
inputChipRenderer.show(view);
|
|
159
|
+
inputChipRenderer.update(getCurrentLabel(view));
|
|
160
|
+
} else {
|
|
161
|
+
inputChipRenderer.hide();
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
inputChipRenderer.init(editorView);
|
|
165
|
+
renderByView(editorView);
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
update: (view, prevState) => {
|
|
169
|
+
const isEqualSelection =
|
|
170
|
+
prevState?.doc.eq(view.state.doc) && prevState.selection.eq(view.state.selection);
|
|
171
|
+
if (isEqualSelection) return;
|
|
172
|
+
|
|
173
|
+
renderByView(view);
|
|
174
|
+
},
|
|
175
|
+
destroy: () => {
|
|
176
|
+
inputChipRenderer.destroy();
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
}),
|
|
181
|
+
];
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
|
|
3
|
+
import { commandsCtx, createCmd, createCmdKey, editorViewCtx, ThemeInputChipType } from '@milkdown/core';
|
|
4
|
+
import { EditorView, findSelectedNodeOfType, InputRule, NodeSelection, Plugin, PluginKey } from '@milkdown/prose';
|
|
5
|
+
import { createNode } from '@milkdown/utils';
|
|
6
|
+
|
|
7
|
+
import { getFootnoteDefId, getFootnoteRefId } from './utils';
|
|
8
|
+
|
|
9
|
+
export const ModifyFootnoteRef = createCmdKey<string>('ModifyFootnoteRef');
|
|
10
|
+
const key = new PluginKey('MILKDOWN_PLUGIN_FOOTNOTE_REF_INPUT');
|
|
11
|
+
|
|
12
|
+
export const footnoteReference = createNode((utils) => {
|
|
13
|
+
const id = 'footnote_reference';
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
id,
|
|
17
|
+
schema: (ctx) => ({
|
|
18
|
+
group: 'inline',
|
|
19
|
+
inline: true,
|
|
20
|
+
atom: true,
|
|
21
|
+
attrs: {
|
|
22
|
+
label: {
|
|
23
|
+
default: '',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
parseDOM: [
|
|
27
|
+
{
|
|
28
|
+
tag: `sup[data-type="${id}"]`,
|
|
29
|
+
getAttrs: (dom) => {
|
|
30
|
+
if (!(dom instanceof HTMLElement)) {
|
|
31
|
+
throw new Error();
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
label: dom.dataset['label'],
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
toDOM: (node) => {
|
|
40
|
+
const label = node.attrs['label'];
|
|
41
|
+
const a = document.createElement('a');
|
|
42
|
+
const href = `#${getFootnoteDefId(label)}`;
|
|
43
|
+
a.href = href;
|
|
44
|
+
a.textContent = `[${label}]`;
|
|
45
|
+
a.onclick = (e) => {
|
|
46
|
+
const view = ctx.get(editorViewCtx);
|
|
47
|
+
if (view.editable) {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
a.ondblclick = () => {
|
|
52
|
+
const view = ctx.get(editorViewCtx);
|
|
53
|
+
if (view.editable) {
|
|
54
|
+
window.location.href = href;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return [
|
|
58
|
+
'sup',
|
|
59
|
+
{
|
|
60
|
+
'data-label': label,
|
|
61
|
+
'data-type': id,
|
|
62
|
+
id: getFootnoteRefId(label),
|
|
63
|
+
},
|
|
64
|
+
a,
|
|
65
|
+
];
|
|
66
|
+
},
|
|
67
|
+
parseMarkdown: {
|
|
68
|
+
match: ({ type }) => type === 'footnoteReference',
|
|
69
|
+
runner: (state, node, type) => {
|
|
70
|
+
state.addNode(type, {
|
|
71
|
+
label: node['label'] as string,
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
toMarkdown: {
|
|
76
|
+
match: (node) => node.type.name === id,
|
|
77
|
+
runner: (state, node) => {
|
|
78
|
+
state.addNode('footnoteReference', undefined, undefined, {
|
|
79
|
+
label: node.attrs['label'],
|
|
80
|
+
identifier: node.attrs['label'],
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
commands: (nodeType) => [
|
|
86
|
+
createCmd(ModifyFootnoteRef, (label = '') => (state, dispatch) => {
|
|
87
|
+
const node = findSelectedNodeOfType(state.selection, nodeType);
|
|
88
|
+
if (!node) return false;
|
|
89
|
+
|
|
90
|
+
const { tr } = state;
|
|
91
|
+
const _tr = tr.setNodeMarkup(node.pos, undefined, { ...node.node.attrs, label });
|
|
92
|
+
dispatch?.(_tr.setSelection(NodeSelection.create(_tr.doc, node.pos)));
|
|
93
|
+
|
|
94
|
+
return true;
|
|
95
|
+
}),
|
|
96
|
+
],
|
|
97
|
+
inputRules: (nodeType) => [
|
|
98
|
+
new InputRule(/(?:\[\^)([^\]]+)(?:\])$/, (state, match, start, end) => {
|
|
99
|
+
const $start = state.doc.resolve(start);
|
|
100
|
+
const index = $start.index();
|
|
101
|
+
const $end = state.doc.resolve(end);
|
|
102
|
+
if (!$start.parent.canReplaceWith(index, $end.index(), nodeType)) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const label = match[1];
|
|
106
|
+
return state.tr.replaceRangeWith(
|
|
107
|
+
start,
|
|
108
|
+
end,
|
|
109
|
+
nodeType.create({
|
|
110
|
+
label,
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
}),
|
|
114
|
+
],
|
|
115
|
+
prosePlugins: (type, ctx) => {
|
|
116
|
+
const inputChipRenderer = utils.themeManager.get<ThemeInputChipType>('input-chip', {
|
|
117
|
+
width: '12em',
|
|
118
|
+
placeholder: 'Input Footnote Label',
|
|
119
|
+
onUpdate: (value) => {
|
|
120
|
+
ctx.get(commandsCtx).call(ModifyFootnoteRef, value);
|
|
121
|
+
},
|
|
122
|
+
isBindMode: true,
|
|
123
|
+
});
|
|
124
|
+
if (!inputChipRenderer) return [];
|
|
125
|
+
const shouldDisplay = (view: EditorView) => {
|
|
126
|
+
return Boolean(type && findSelectedNodeOfType(view.state.selection, type));
|
|
127
|
+
};
|
|
128
|
+
const getCurrentLabel = (view: EditorView) => {
|
|
129
|
+
const result = findSelectedNodeOfType(view.state.selection, type);
|
|
130
|
+
if (!result) return;
|
|
131
|
+
|
|
132
|
+
const value = result.node.attrs['label'];
|
|
133
|
+
return value;
|
|
134
|
+
};
|
|
135
|
+
const renderByView = (view: EditorView) => {
|
|
136
|
+
if (!view.editable) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const display = shouldDisplay(view);
|
|
140
|
+
if (display) {
|
|
141
|
+
inputChipRenderer.show(view);
|
|
142
|
+
inputChipRenderer.update(getCurrentLabel(view));
|
|
143
|
+
} else {
|
|
144
|
+
inputChipRenderer.hide();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
return [
|
|
148
|
+
new Plugin({
|
|
149
|
+
key,
|
|
150
|
+
view: (editorView) => {
|
|
151
|
+
inputChipRenderer.init(editorView);
|
|
152
|
+
renderByView(editorView);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
update: (view, prevState) => {
|
|
156
|
+
const isEqualSelection =
|
|
157
|
+
prevState?.doc.eq(view.state.doc) && prevState.selection.eq(view.state.selection);
|
|
158
|
+
if (isEqualSelection) return;
|
|
159
|
+
|
|
160
|
+
renderByView(view);
|
|
161
|
+
},
|
|
162
|
+
destroy: () => {
|
|
163
|
+
inputChipRenderer.destroy();
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
}),
|
|
168
|
+
];
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { $remark, AtomList } from '@milkdown/utils';
|
|
|
4
4
|
import remarkGFM from 'remark-gfm';
|
|
5
5
|
|
|
6
6
|
import { urlPlugin } from './auto-link';
|
|
7
|
+
import { footnoteReference } from './footnote';
|
|
8
|
+
import { footnoteDefinition } from './footnote/definition';
|
|
7
9
|
import { strikeThrough, ToggleStrikeThrough } from './strike-through';
|
|
8
10
|
import { table } from './table';
|
|
9
11
|
import {
|
|
@@ -14,6 +16,7 @@ import {
|
|
|
14
16
|
TurnIntoTaskList,
|
|
15
17
|
} from './task-list-item';
|
|
16
18
|
|
|
19
|
+
export * from './footnote';
|
|
17
20
|
export * from './strike-through';
|
|
18
21
|
export { SupportedKeys } from './supported-keys';
|
|
19
22
|
export {
|
|
@@ -77,6 +80,8 @@ export const gfm = AtomList.create([
|
|
|
77
80
|
urlPlugin,
|
|
78
81
|
strikeThrough(),
|
|
79
82
|
taskListItem(),
|
|
83
|
+
footnoteReference(),
|
|
84
|
+
footnoteDefinition(),
|
|
80
85
|
]);
|
|
81
86
|
|
|
82
87
|
export const commands = {
|
package/src/strike-through.ts
CHANGED
|
@@ -9,15 +9,8 @@ type Keys = SupportedKeys['StrikeThrough'];
|
|
|
9
9
|
|
|
10
10
|
export const ToggleStrikeThrough = createCmdKey('ToggleStrikeThrough');
|
|
11
11
|
|
|
12
|
+
const id = 'strike_through';
|
|
12
13
|
export const strikeThrough = createMark<Keys>((utils) => {
|
|
13
|
-
const id = 'strike_through';
|
|
14
|
-
const style = utils.getStyle(
|
|
15
|
-
(themeTool, { css }) =>
|
|
16
|
-
css`
|
|
17
|
-
text-decoration-color: ${themeTool.palette('secondary')};
|
|
18
|
-
`,
|
|
19
|
-
);
|
|
20
|
-
|
|
21
14
|
return {
|
|
22
15
|
id,
|
|
23
16
|
schema: () => ({
|
|
@@ -25,7 +18,7 @@ export const strikeThrough = createMark<Keys>((utils) => {
|
|
|
25
18
|
{ tag: 'del' },
|
|
26
19
|
{ style: 'text-decoration', getAttrs: (value) => (value === 'line-through') as false },
|
|
27
20
|
],
|
|
28
|
-
toDOM: (mark) => ['del', { class: utils.getClassName(mark.attrs, 'strike-through'
|
|
21
|
+
toDOM: (mark) => ['del', { class: utils.getClassName(mark.attrs, 'strike-through') }],
|
|
29
22
|
parseMarkdown: {
|
|
30
23
|
match: (node) => node.type === 'delete',
|
|
31
24
|
runner: (state, node, markType) => {
|
package/src/table/nodes/index.ts
CHANGED
|
@@ -15,7 +15,6 @@ import { exitTable } from '../command';
|
|
|
15
15
|
import { operatorPlugin } from '../operator-plugin';
|
|
16
16
|
import { createTable } from '../utils';
|
|
17
17
|
import { schema } from './schema';
|
|
18
|
-
import { injectStyle } from './style';
|
|
19
18
|
|
|
20
19
|
export const SupportedKeys = {
|
|
21
20
|
NextCell: 'NextCell',
|
|
@@ -32,7 +31,6 @@ export const BreakTable = createCmdKey('BreakTable');
|
|
|
32
31
|
export const InsertTable = createCmdKey('InsertTable');
|
|
33
32
|
|
|
34
33
|
export const table = createPlugin<Keys, Record<string, unknown>, keyof typeof schema>((utils) => {
|
|
35
|
-
injectStyle(utils);
|
|
36
34
|
return {
|
|
37
35
|
schema: () => ({
|
|
38
36
|
node: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { Ctx,
|
|
2
|
+
import { Ctx, ThemeIcon, themeManagerCtx } from '@milkdown/core';
|
|
3
3
|
import {
|
|
4
4
|
addColumnAfter,
|
|
5
5
|
addColumnBefore,
|
|
@@ -35,17 +35,17 @@ export enum Action {
|
|
|
35
35
|
|
|
36
36
|
export const createActions: (ctx: Ctx) => Record<Action, Item> = (ctx) => ({
|
|
37
37
|
[Action.AddColLeft]: {
|
|
38
|
-
$: ctx.get(
|
|
38
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'leftArrow')?.dom as HTMLElement,
|
|
39
39
|
command: () => addColumnBefore,
|
|
40
40
|
disable: (view) => !getCellSelection(view).isColSelection(),
|
|
41
41
|
},
|
|
42
42
|
[Action.AddColRight]: {
|
|
43
|
-
$: ctx.get(
|
|
43
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'rightArrow')?.dom as HTMLElement,
|
|
44
44
|
command: () => addColumnAfter,
|
|
45
45
|
disable: (view) => !getCellSelection(view).isColSelection(),
|
|
46
46
|
},
|
|
47
47
|
[Action.AddRowTop]: {
|
|
48
|
-
$: ctx.get(
|
|
48
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'upArrow')?.dom as HTMLElement,
|
|
49
49
|
command: () => (state, dispatch) => {
|
|
50
50
|
if (!isInTable(state)) return false;
|
|
51
51
|
if (dispatch) {
|
|
@@ -59,7 +59,7 @@ export const createActions: (ctx: Ctx) => Record<Action, Item> = (ctx) => ({
|
|
|
59
59
|
getCellSelection(view).$head.parent.type.name === 'table_header',
|
|
60
60
|
},
|
|
61
61
|
[Action.AddRowBottom]: {
|
|
62
|
-
$: ctx.get(
|
|
62
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'downArrow')?.dom as HTMLElement,
|
|
63
63
|
command: () => (state, dispatch) => {
|
|
64
64
|
if (!isInTable(state)) return false;
|
|
65
65
|
if (dispatch) {
|
|
@@ -71,22 +71,22 @@ export const createActions: (ctx: Ctx) => Record<Action, Item> = (ctx) => ({
|
|
|
71
71
|
disable: (view) => !getCellSelection(view).isRowSelection(),
|
|
72
72
|
},
|
|
73
73
|
[Action.AlignLeft]: {
|
|
74
|
-
$: ctx.get(
|
|
74
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignLeft')?.dom as HTMLElement,
|
|
75
75
|
command: () => setCellAttr('alignment', 'left'),
|
|
76
76
|
disable: (view) => !getCellSelection(view).isColSelection(),
|
|
77
77
|
},
|
|
78
78
|
[Action.AlignCenter]: {
|
|
79
|
-
$: ctx.get(
|
|
79
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignCenter')?.dom as HTMLElement,
|
|
80
80
|
command: () => setCellAttr('alignment', 'center'),
|
|
81
81
|
disable: (view) => !getCellSelection(view).isColSelection(),
|
|
82
82
|
},
|
|
83
83
|
[Action.AlignRight]: {
|
|
84
|
-
$: ctx.get(
|
|
84
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignRight')?.dom as HTMLElement,
|
|
85
85
|
command: () => setCellAttr('alignment', 'right'),
|
|
86
86
|
disable: (view) => !getCellSelection(view).isColSelection(),
|
|
87
87
|
},
|
|
88
88
|
[Action.Delete]: {
|
|
89
|
-
$: ctx.get(
|
|
89
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'delete')?.dom as HTMLElement,
|
|
90
90
|
command: (_, view) => {
|
|
91
91
|
const selection = getCellSelection(view);
|
|
92
92
|
const isCol = selection.isColSelection();
|
|
@@ -15,14 +15,6 @@ import { createWidget } from './widget';
|
|
|
15
15
|
export const key = 'MILKDOWN_PLUGIN_TABLE';
|
|
16
16
|
|
|
17
17
|
export const operatorPlugin = (ctx: Ctx, utils: Utils) => {
|
|
18
|
-
const items = createActions(ctx);
|
|
19
|
-
const tooltip = document.createElement('div');
|
|
20
|
-
const style = utils.getStyle(injectStyle);
|
|
21
|
-
if (style) {
|
|
22
|
-
tooltip.classList.add(style);
|
|
23
|
-
}
|
|
24
|
-
tooltip.classList.add('table-tooltip', 'hide');
|
|
25
|
-
|
|
26
18
|
return new Plugin({
|
|
27
19
|
key: new PluginKey('MILKDOWN_TABLE_OP'),
|
|
28
20
|
props: {
|
|
@@ -47,6 +39,15 @@ export const operatorPlugin = (ctx: Ctx, utils: Utils) => {
|
|
|
47
39
|
},
|
|
48
40
|
},
|
|
49
41
|
view: (editorView) => {
|
|
42
|
+
const items = Object.fromEntries(Object.entries(createActions(ctx)).filter(([, value]) => value.$ != null));
|
|
43
|
+
const tooltip = document.createElement('div');
|
|
44
|
+
utils.themeManager.onFlush(() => {
|
|
45
|
+
const style = utils.getStyle((emotion) => injectStyle(utils.themeManager, emotion));
|
|
46
|
+
if (style) {
|
|
47
|
+
tooltip.classList.add(style);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
tooltip.classList.add('table-tooltip', 'hide');
|
|
50
51
|
Object.values(items).forEach(({ $ }) => tooltip.appendChild($));
|
|
51
52
|
editorView.dom.parentNode?.appendChild(tooltip);
|
|
52
53
|
|