mardora 1.2.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/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/chunk-3OCUX4OO.js +7690 -0
- package/dist/chunk-3OCUX4OO.js.map +1 -0
- package/dist/chunk-3ZOCCFDL.cjs +74 -0
- package/dist/chunk-3ZOCCFDL.cjs.map +1 -0
- package/dist/chunk-7JOEPNEV.cjs +7740 -0
- package/dist/chunk-7JOEPNEV.cjs.map +1 -0
- package/dist/chunk-BIKZQZ6W.js +33 -0
- package/dist/chunk-BIKZQZ6W.js.map +1 -0
- package/dist/chunk-EQJESPP2.js +234 -0
- package/dist/chunk-EQJESPP2.js.map +1 -0
- package/dist/chunk-G4SE26YY.js +70 -0
- package/dist/chunk-G4SE26YY.js.map +1 -0
- package/dist/chunk-KNDWF2DP.cjs +35 -0
- package/dist/chunk-KNDWF2DP.cjs.map +1 -0
- package/dist/chunk-MLBEBFHB.cjs +2971 -0
- package/dist/chunk-MLBEBFHB.cjs.map +1 -0
- package/dist/chunk-P7JFCYU3.js +905 -0
- package/dist/chunk-P7JFCYU3.js.map +1 -0
- package/dist/chunk-SWFUKJDO.cjs +243 -0
- package/dist/chunk-SWFUKJDO.cjs.map +1 -0
- package/dist/chunk-WFVCG4LD.cjs +926 -0
- package/dist/chunk-WFVCG4LD.cjs.map +1 -0
- package/dist/chunk-XL6WFGJT.js +2901 -0
- package/dist/chunk-XL6WFGJT.js.map +1 -0
- package/dist/editor/index.cjs +277 -0
- package/dist/editor/index.cjs.map +1 -0
- package/dist/editor/index.d.cts +186 -0
- package/dist/editor/index.d.ts +186 -0
- package/dist/editor/index.js +4 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/index.cjs +405 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/index.cjs +12 -0
- package/dist/lib/index.cjs.map +1 -0
- package/dist/lib/index.d.cts +16 -0
- package/dist/lib/index.d.ts +16 -0
- package/dist/lib/index.js +3 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/mardora-DCwjomil.d.cts +640 -0
- package/dist/mardora-DCwjomil.d.ts +640 -0
- package/dist/plugins/index.cjs +104 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +740 -0
- package/dist/plugins/index.d.ts +740 -0
- package/dist/plugins/index.js +7 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/preview/index.cjs +38 -0
- package/dist/preview/index.cjs.map +1 -0
- package/dist/preview/index.d.cts +101 -0
- package/dist/preview/index.d.ts +101 -0
- package/dist/preview/index.js +5 -0
- package/dist/preview/index.js.map +1 -0
- package/dist/types-NBsaxl4d.d.cts +71 -0
- package/dist/types-Pw2SWWAR.d.ts +71 -0
- package/package.json +92 -0
- package/src/editor/attachments/extension.ts +181 -0
- package/src/editor/attachments/format.ts +63 -0
- package/src/editor/attachments/index.ts +3 -0
- package/src/editor/attachments/types.ts +37 -0
- package/src/editor/heading-fold/config.ts +25 -0
- package/src/editor/heading-fold/extension.ts +268 -0
- package/src/editor/heading-fold/extract.ts +88 -0
- package/src/editor/heading-fold/index.ts +5 -0
- package/src/editor/heading-fold/theme.ts +85 -0
- package/src/editor/heading-fold/types.ts +24 -0
- package/src/editor/i18n.ts +13 -0
- package/src/editor/icons/index.ts +367 -0
- package/src/editor/index.ts +16 -0
- package/src/editor/mardora.ts +257 -0
- package/src/editor/media-lightbox-theme.ts +146 -0
- package/src/editor/media-lightbox.ts +125 -0
- package/src/editor/plugin.ts +294 -0
- package/src/editor/selection-toolbar/activation.ts +123 -0
- package/src/editor/selection-toolbar/commands.ts +279 -0
- package/src/editor/selection-toolbar/extension.ts +564 -0
- package/src/editor/selection-toolbar/i18n.ts +164 -0
- package/src/editor/selection-toolbar/index.ts +7 -0
- package/src/editor/selection-toolbar/menu.ts +252 -0
- package/src/editor/selection-toolbar/position.ts +43 -0
- package/src/editor/selection-toolbar/theme.ts +195 -0
- package/src/editor/selection-toolbar/types.ts +155 -0
- package/src/editor/slash/default-commands.ts +190 -0
- package/src/editor/slash/extension.ts +319 -0
- package/src/editor/slash/index.ts +7 -0
- package/src/editor/slash/insertions.ts +26 -0
- package/src/editor/slash/menu.ts +123 -0
- package/src/editor/slash/position.ts +61 -0
- package/src/editor/slash/query.ts +33 -0
- package/src/editor/slash/theme.ts +113 -0
- package/src/editor/slash/types.ts +40 -0
- package/src/editor/table-of-contents/extension.ts +202 -0
- package/src/editor/table-of-contents/extract.ts +53 -0
- package/src/editor/table-of-contents/index.ts +7 -0
- package/src/editor/table-of-contents/panel.ts +83 -0
- package/src/editor/table-of-contents/slug.ts +50 -0
- package/src/editor/table-of-contents/storage.ts +35 -0
- package/src/editor/table-of-contents/theme.ts +153 -0
- package/src/editor/table-of-contents/types.ts +44 -0
- package/src/editor/theme.ts +72 -0
- package/src/editor/utils.ts +176 -0
- package/src/editor/view-plugin.ts +189 -0
- package/src/index.ts +5 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/input-handler.ts +47 -0
- package/src/plugins/code-plugin.theme.ts +545 -0
- package/src/plugins/code-plugin.ts +1892 -0
- package/src/plugins/emoji-plugin.ts +140 -0
- package/src/plugins/heading-plugin.ts +194 -0
- package/src/plugins/hr-plugin.ts +102 -0
- package/src/plugins/html-plugin.ts +353 -0
- package/src/plugins/image-plugin.ts +806 -0
- package/src/plugins/index.ts +71 -0
- package/src/plugins/inline-plugin.ts +311 -0
- package/src/plugins/link-plugin.ts +509 -0
- package/src/plugins/list-plugin.ts +492 -0
- package/src/plugins/math-plugin.ts +526 -0
- package/src/plugins/mermaid-plugin.ts +513 -0
- package/src/plugins/paragraph-plugin.ts +38 -0
- package/src/plugins/quote-plugin.ts +733 -0
- package/src/plugins/table-controls-theme.ts +126 -0
- package/src/plugins/table-controls.ts +423 -0
- package/src/plugins/table-model.ts +661 -0
- package/src/plugins/table-plugin.ts +2111 -0
- package/src/preview/context.ts +45 -0
- package/src/preview/css-generator.ts +64 -0
- package/src/preview/default-renderers.ts +29 -0
- package/src/preview/index.ts +29 -0
- package/src/preview/preview.ts +41 -0
- package/src/preview/renderer.ts +184 -0
- package/src/preview/syntax-theme.ts +112 -0
- package/src/preview/toc.ts +23 -0
- package/src/preview/types.ts +89 -0
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
type IconElementName = "circle" | "line" | "path" | "rect";
|
|
2
|
+
|
|
3
|
+
type IconElementDefinition = {
|
|
4
|
+
name: IconElementName;
|
|
5
|
+
attrs: Record<string, string>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type MardoraIconName =
|
|
9
|
+
| "arrow-down"
|
|
10
|
+
| "arrow-down-to-line"
|
|
11
|
+
| "arrow-left"
|
|
12
|
+
| "arrow-left-to-line"
|
|
13
|
+
| "arrow-right"
|
|
14
|
+
| "arrow-right-to-line"
|
|
15
|
+
| "arrow-up"
|
|
16
|
+
| "arrow-up-to-line"
|
|
17
|
+
| "badge-alert"
|
|
18
|
+
| "baseline"
|
|
19
|
+
| "bold"
|
|
20
|
+
| "code"
|
|
21
|
+
| "code-xml"
|
|
22
|
+
| "copy"
|
|
23
|
+
| "external-link"
|
|
24
|
+
| "file"
|
|
25
|
+
| "heading-1"
|
|
26
|
+
| "heading-2"
|
|
27
|
+
| "heading-3"
|
|
28
|
+
| "heading-4"
|
|
29
|
+
| "heading-5"
|
|
30
|
+
| "heading-6"
|
|
31
|
+
| "highlighter"
|
|
32
|
+
| "image"
|
|
33
|
+
| "info"
|
|
34
|
+
| "italic"
|
|
35
|
+
| "link"
|
|
36
|
+
| "lightbulb"
|
|
37
|
+
| "list"
|
|
38
|
+
| "list-ordered"
|
|
39
|
+
| "list-todo"
|
|
40
|
+
| "maximize-2"
|
|
41
|
+
| "minus"
|
|
42
|
+
| "music-2"
|
|
43
|
+
| "octagon-alert"
|
|
44
|
+
| "play"
|
|
45
|
+
| "rotate-ccw"
|
|
46
|
+
| "strikethrough"
|
|
47
|
+
| "table"
|
|
48
|
+
| "table-delete"
|
|
49
|
+
| "table-of-contents"
|
|
50
|
+
| "text-align-start"
|
|
51
|
+
| "text-quote"
|
|
52
|
+
| "trash-2"
|
|
53
|
+
| "triangle-alert"
|
|
54
|
+
| "underline"
|
|
55
|
+
| "type"
|
|
56
|
+
| "x";
|
|
57
|
+
|
|
58
|
+
const svgNamespace = "http://www.w3.org/2000/svg";
|
|
59
|
+
|
|
60
|
+
const iconDefinitions: Record<MardoraIconName, IconElementDefinition[]> = {
|
|
61
|
+
"arrow-down": [
|
|
62
|
+
{ name: "path", attrs: { d: "M12 5v14" } },
|
|
63
|
+
{ name: "path", attrs: { d: "m19 12-7 7-7-7" } },
|
|
64
|
+
],
|
|
65
|
+
"arrow-down-to-line": [
|
|
66
|
+
{ name: "path", attrs: { d: "M19 21H5" } },
|
|
67
|
+
{ name: "path", attrs: { d: "M12 3v14" } },
|
|
68
|
+
{ name: "path", attrs: { d: "m19 10-7 7-7-7" } },
|
|
69
|
+
],
|
|
70
|
+
"arrow-left": [
|
|
71
|
+
{ name: "path", attrs: { d: "M19 12H5" } },
|
|
72
|
+
{ name: "path", attrs: { d: "m12 19-7-7 7-7" } },
|
|
73
|
+
],
|
|
74
|
+
"arrow-left-to-line": [
|
|
75
|
+
{ name: "path", attrs: { d: "M3 5v14" } },
|
|
76
|
+
{ name: "path", attrs: { d: "M21 12H7" } },
|
|
77
|
+
{ name: "path", attrs: { d: "m14 19-7-7 7-7" } },
|
|
78
|
+
],
|
|
79
|
+
"arrow-right": [
|
|
80
|
+
{ name: "path", attrs: { d: "M5 12h14" } },
|
|
81
|
+
{ name: "path", attrs: { d: "m12 5 7 7-7 7" } },
|
|
82
|
+
],
|
|
83
|
+
"arrow-right-to-line": [
|
|
84
|
+
{ name: "path", attrs: { d: "M21 5v14" } },
|
|
85
|
+
{ name: "path", attrs: { d: "M3 12h14" } },
|
|
86
|
+
{ name: "path", attrs: { d: "m10 5 7 7-7 7" } },
|
|
87
|
+
],
|
|
88
|
+
"arrow-up": [
|
|
89
|
+
{ name: "path", attrs: { d: "M12 19V5" } },
|
|
90
|
+
{ name: "path", attrs: { d: "m5 12 7-7 7 7" } },
|
|
91
|
+
],
|
|
92
|
+
"arrow-up-to-line": [
|
|
93
|
+
{ name: "path", attrs: { d: "M5 3h14" } },
|
|
94
|
+
{ name: "path", attrs: { d: "M12 21V7" } },
|
|
95
|
+
{ name: "path", attrs: { d: "m5 14 7-7 7 7" } },
|
|
96
|
+
],
|
|
97
|
+
"badge-alert": [
|
|
98
|
+
{
|
|
99
|
+
name: "path",
|
|
100
|
+
attrs: {
|
|
101
|
+
d: "M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{ name: "line", attrs: { x1: "12", x2: "12", y1: "8", y2: "12" } },
|
|
105
|
+
{ name: "line", attrs: { x1: "12", x2: "12.01", y1: "16", y2: "16" } },
|
|
106
|
+
],
|
|
107
|
+
baseline: [
|
|
108
|
+
{ name: "path", attrs: { d: "M4 20h16" } },
|
|
109
|
+
{ name: "path", attrs: { d: "m6 16 6-12 6 12" } },
|
|
110
|
+
{ name: "path", attrs: { d: "M8 12h8" } },
|
|
111
|
+
],
|
|
112
|
+
bold: [
|
|
113
|
+
{
|
|
114
|
+
name: "path",
|
|
115
|
+
attrs: {
|
|
116
|
+
d: "M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8",
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
code: [
|
|
121
|
+
{ name: "path", attrs: { d: "m16 18 6-6-6-6" } },
|
|
122
|
+
{ name: "path", attrs: { d: "m8 6-6 6 6 6" } },
|
|
123
|
+
],
|
|
124
|
+
"code-xml": [
|
|
125
|
+
{ name: "path", attrs: { d: "m18 16 4-4-4-4" } },
|
|
126
|
+
{ name: "path", attrs: { d: "m6 8-4 4 4 4" } },
|
|
127
|
+
{ name: "path", attrs: { d: "m14.5 4-5 16" } },
|
|
128
|
+
],
|
|
129
|
+
copy: [
|
|
130
|
+
{ name: "rect", attrs: { width: "14", height: "14", x: "8", y: "8", rx: "2", ry: "2" } },
|
|
131
|
+
{ name: "path", attrs: { d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" } },
|
|
132
|
+
],
|
|
133
|
+
"external-link": [
|
|
134
|
+
{ name: "path", attrs: { d: "M15 3h6v6" } },
|
|
135
|
+
{ name: "path", attrs: { d: "M10 14 21 3" } },
|
|
136
|
+
{ name: "path", attrs: { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" } },
|
|
137
|
+
],
|
|
138
|
+
file: [
|
|
139
|
+
{
|
|
140
|
+
name: "path",
|
|
141
|
+
attrs: {
|
|
142
|
+
d: "M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
{ name: "path", attrs: { d: "M14 2v5a1 1 0 0 0 1 1h5" } },
|
|
146
|
+
],
|
|
147
|
+
"heading-1": [
|
|
148
|
+
{ name: "path", attrs: { d: "M4 12h8" } },
|
|
149
|
+
{ name: "path", attrs: { d: "M4 18V6" } },
|
|
150
|
+
{ name: "path", attrs: { d: "M12 18V6" } },
|
|
151
|
+
{ name: "path", attrs: { d: "m17 12 3-2v8" } },
|
|
152
|
+
],
|
|
153
|
+
"heading-2": [
|
|
154
|
+
{ name: "path", attrs: { d: "M4 12h8" } },
|
|
155
|
+
{ name: "path", attrs: { d: "M4 18V6" } },
|
|
156
|
+
{ name: "path", attrs: { d: "M12 18V6" } },
|
|
157
|
+
{ name: "path", attrs: { d: "M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1" } },
|
|
158
|
+
],
|
|
159
|
+
"heading-3": [
|
|
160
|
+
{ name: "path", attrs: { d: "M4 12h8" } },
|
|
161
|
+
{ name: "path", attrs: { d: "M4 18V6" } },
|
|
162
|
+
{ name: "path", attrs: { d: "M12 18V6" } },
|
|
163
|
+
{ name: "path", attrs: { d: "M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2" } },
|
|
164
|
+
{ name: "path", attrs: { d: "M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2" } },
|
|
165
|
+
],
|
|
166
|
+
"heading-4": [
|
|
167
|
+
{ name: "path", attrs: { d: "M12 18V6" } },
|
|
168
|
+
{ name: "path", attrs: { d: "M17 10v3a1 1 0 0 0 1 1h3" } },
|
|
169
|
+
{ name: "path", attrs: { d: "M21 10v8" } },
|
|
170
|
+
{ name: "path", attrs: { d: "M4 12h8" } },
|
|
171
|
+
{ name: "path", attrs: { d: "M4 18V6" } },
|
|
172
|
+
],
|
|
173
|
+
"heading-5": [
|
|
174
|
+
{ name: "path", attrs: { d: "M4 12h8" } },
|
|
175
|
+
{ name: "path", attrs: { d: "M4 18V6" } },
|
|
176
|
+
{ name: "path", attrs: { d: "M12 18V6" } },
|
|
177
|
+
{ name: "path", attrs: { d: "M17 13v-3h4" } },
|
|
178
|
+
{ name: "path", attrs: { d: "M17 17.7c.4.2.8.3 1.3.3 1.5 0 2.7-1.1 2.7-2.5S19.8 13 18.3 13H17" } },
|
|
179
|
+
],
|
|
180
|
+
"heading-6": [
|
|
181
|
+
{ name: "path", attrs: { d: "M4 12h8" } },
|
|
182
|
+
{ name: "path", attrs: { d: "M4 18V6" } },
|
|
183
|
+
{ name: "path", attrs: { d: "M12 18V6" } },
|
|
184
|
+
{ name: "circle", attrs: { cx: "19", cy: "16", r: "2" } },
|
|
185
|
+
{ name: "path", attrs: { d: "M20 10c-2 2-3 3.5-3 6" } },
|
|
186
|
+
],
|
|
187
|
+
highlighter: [
|
|
188
|
+
{ name: "path", attrs: { d: "m9 11-6 6v3h9l3-3" } },
|
|
189
|
+
{ name: "path", attrs: { d: "m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4" } },
|
|
190
|
+
],
|
|
191
|
+
image: [
|
|
192
|
+
{ name: "rect", attrs: { width: "18", height: "18", x: "3", y: "3", rx: "2", ry: "2" } },
|
|
193
|
+
{ name: "circle", attrs: { cx: "9", cy: "9", r: "2" } },
|
|
194
|
+
{ name: "path", attrs: { d: "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" } },
|
|
195
|
+
],
|
|
196
|
+
info: [
|
|
197
|
+
{ name: "circle", attrs: { cx: "12", cy: "12", r: "10" } },
|
|
198
|
+
{ name: "path", attrs: { d: "M12 16v-4" } },
|
|
199
|
+
{ name: "path", attrs: { d: "M12 8h.01" } },
|
|
200
|
+
],
|
|
201
|
+
italic: [
|
|
202
|
+
{ name: "line", attrs: { x1: "19", x2: "10", y1: "4", y2: "4" } },
|
|
203
|
+
{ name: "line", attrs: { x1: "14", x2: "5", y1: "20", y2: "20" } },
|
|
204
|
+
{ name: "line", attrs: { x1: "15", x2: "9", y1: "4", y2: "20" } },
|
|
205
|
+
],
|
|
206
|
+
link: [
|
|
207
|
+
{ name: "path", attrs: { d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" } },
|
|
208
|
+
{ name: "path", attrs: { d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" } },
|
|
209
|
+
],
|
|
210
|
+
lightbulb: [
|
|
211
|
+
{
|
|
212
|
+
name: "path",
|
|
213
|
+
attrs: {
|
|
214
|
+
d: "M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
{ name: "path", attrs: { d: "M9 18h6" } },
|
|
218
|
+
{ name: "path", attrs: { d: "M10 22h4" } },
|
|
219
|
+
],
|
|
220
|
+
list: [
|
|
221
|
+
{ name: "path", attrs: { d: "M3 5h.01" } },
|
|
222
|
+
{ name: "path", attrs: { d: "M3 12h.01" } },
|
|
223
|
+
{ name: "path", attrs: { d: "M3 19h.01" } },
|
|
224
|
+
{ name: "path", attrs: { d: "M8 5h13" } },
|
|
225
|
+
{ name: "path", attrs: { d: "M8 12h13" } },
|
|
226
|
+
{ name: "path", attrs: { d: "M8 19h13" } },
|
|
227
|
+
],
|
|
228
|
+
"list-ordered": [
|
|
229
|
+
{ name: "path", attrs: { d: "M11 5h10" } },
|
|
230
|
+
{ name: "path", attrs: { d: "M11 12h10" } },
|
|
231
|
+
{ name: "path", attrs: { d: "M11 19h10" } },
|
|
232
|
+
{ name: "path", attrs: { d: "M4 4h1v5" } },
|
|
233
|
+
{ name: "path", attrs: { d: "M4 9h2" } },
|
|
234
|
+
{ name: "path", attrs: { d: "M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02" } },
|
|
235
|
+
],
|
|
236
|
+
"list-todo": [
|
|
237
|
+
{ name: "path", attrs: { d: "M13 5h8" } },
|
|
238
|
+
{ name: "path", attrs: { d: "M13 12h8" } },
|
|
239
|
+
{ name: "path", attrs: { d: "M13 19h8" } },
|
|
240
|
+
{ name: "path", attrs: { d: "m3 17 2 2 4-4" } },
|
|
241
|
+
{ name: "rect", attrs: { x: "3", y: "4", width: "6", height: "6", rx: "1" } },
|
|
242
|
+
],
|
|
243
|
+
"maximize-2": [
|
|
244
|
+
{ name: "path", attrs: { d: "M15 3h6v6" } },
|
|
245
|
+
{ name: "path", attrs: { d: "m21 3-7 7" } },
|
|
246
|
+
{ name: "path", attrs: { d: "M9 21H3v-6" } },
|
|
247
|
+
{ name: "path", attrs: { d: "m3 21 7-7" } },
|
|
248
|
+
],
|
|
249
|
+
minus: [{ name: "path", attrs: { d: "M5 12h14" } }],
|
|
250
|
+
"music-2": [
|
|
251
|
+
{ name: "circle", attrs: { cx: "8", cy: "18", r: "4" } },
|
|
252
|
+
{ name: "path", attrs: { d: "M12 18V2l7 4" } },
|
|
253
|
+
],
|
|
254
|
+
"octagon-alert": [
|
|
255
|
+
{ name: "path", attrs: { d: "M12 16h.01" } },
|
|
256
|
+
{ name: "path", attrs: { d: "M12 8v4" } },
|
|
257
|
+
{
|
|
258
|
+
name: "path",
|
|
259
|
+
attrs: {
|
|
260
|
+
d: "M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z",
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
play: [
|
|
265
|
+
{
|
|
266
|
+
name: "path",
|
|
267
|
+
attrs: { d: "M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z" },
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
"rotate-ccw": [
|
|
271
|
+
{ name: "path", attrs: { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" } },
|
|
272
|
+
{ name: "path", attrs: { d: "M3 3v5h5" } },
|
|
273
|
+
],
|
|
274
|
+
strikethrough: [
|
|
275
|
+
{ name: "path", attrs: { d: "M16 4H9a3 3 0 0 0-2.83 4" } },
|
|
276
|
+
{ name: "path", attrs: { d: "M14 12a4 4 0 0 1 0 8H6" } },
|
|
277
|
+
{ name: "line", attrs: { x1: "4", x2: "20", y1: "12", y2: "12" } },
|
|
278
|
+
],
|
|
279
|
+
table: [
|
|
280
|
+
{ name: "path", attrs: { d: "M12 3v18" } },
|
|
281
|
+
{ name: "rect", attrs: { width: "18", height: "18", x: "3", y: "3", rx: "2" } },
|
|
282
|
+
{ name: "path", attrs: { d: "M3 9h18" } },
|
|
283
|
+
{ name: "path", attrs: { d: "M3 15h18" } },
|
|
284
|
+
],
|
|
285
|
+
"table-delete": [
|
|
286
|
+
{ name: "rect", attrs: { width: "18", height: "18", x: "3", y: "3", rx: "2" } },
|
|
287
|
+
{ name: "path", attrs: { d: "M3 9h18" } },
|
|
288
|
+
{ name: "path", attrs: { d: "M9 3v18" } },
|
|
289
|
+
{ name: "path", attrs: { d: "m14 14 4 4" } },
|
|
290
|
+
{ name: "path", attrs: { d: "m18 14-4 4" } },
|
|
291
|
+
],
|
|
292
|
+
"table-of-contents": [
|
|
293
|
+
{ name: "path", attrs: { d: "M16 5H3" } },
|
|
294
|
+
{ name: "path", attrs: { d: "M16 12H3" } },
|
|
295
|
+
{ name: "path", attrs: { d: "M16 19H3" } },
|
|
296
|
+
{ name: "path", attrs: { d: "M21 5h.01" } },
|
|
297
|
+
{ name: "path", attrs: { d: "M21 12h.01" } },
|
|
298
|
+
{ name: "path", attrs: { d: "M21 19h.01" } },
|
|
299
|
+
],
|
|
300
|
+
"text-align-start": [
|
|
301
|
+
{ name: "path", attrs: { d: "M21 5H3" } },
|
|
302
|
+
{ name: "path", attrs: { d: "M15 12H3" } },
|
|
303
|
+
{ name: "path", attrs: { d: "M17 19H3" } },
|
|
304
|
+
],
|
|
305
|
+
"text-quote": [
|
|
306
|
+
{ name: "path", attrs: { d: "M17 5H3" } },
|
|
307
|
+
{ name: "path", attrs: { d: "M21 12H8" } },
|
|
308
|
+
{ name: "path", attrs: { d: "M21 19H8" } },
|
|
309
|
+
{ name: "path", attrs: { d: "M3 12v7" } },
|
|
310
|
+
],
|
|
311
|
+
"trash-2": [
|
|
312
|
+
{ name: "path", attrs: { d: "M10 11v6" } },
|
|
313
|
+
{ name: "path", attrs: { d: "M14 11v6" } },
|
|
314
|
+
{ name: "path", attrs: { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" } },
|
|
315
|
+
{ name: "path", attrs: { d: "M3 6h18" } },
|
|
316
|
+
{ name: "path", attrs: { d: "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" } },
|
|
317
|
+
],
|
|
318
|
+
"triangle-alert": [
|
|
319
|
+
{ name: "path", attrs: { d: "m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" } },
|
|
320
|
+
{ name: "path", attrs: { d: "M12 9v4" } },
|
|
321
|
+
{ name: "path", attrs: { d: "M12 17h.01" } },
|
|
322
|
+
],
|
|
323
|
+
underline: [
|
|
324
|
+
{ name: "path", attrs: { d: "M6 4v6a6 6 0 0 0 12 0V4" } },
|
|
325
|
+
{ name: "line", attrs: { x1: "4", x2: "20", y1: "20", y2: "20" } },
|
|
326
|
+
],
|
|
327
|
+
type: [
|
|
328
|
+
{ name: "path", attrs: { d: "M12 4v16" } },
|
|
329
|
+
{ name: "path", attrs: { d: "M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2" } },
|
|
330
|
+
{ name: "path", attrs: { d: "M9 20h6" } },
|
|
331
|
+
],
|
|
332
|
+
x: [
|
|
333
|
+
{ name: "path", attrs: { d: "M18 6 6 18" } },
|
|
334
|
+
{ name: "path", attrs: { d: "m6 6 12 12" } },
|
|
335
|
+
],
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
export function hasMardoraIcon(name: string): name is MardoraIconName {
|
|
339
|
+
return name in iconDefinitions;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export function createMardoraIcon(name: string): SVGSVGElement | null {
|
|
343
|
+
if (!hasMardoraIcon(name)) return null;
|
|
344
|
+
|
|
345
|
+
const svg = document.createElementNS(svgNamespace, "svg");
|
|
346
|
+
svg.setAttribute("xmlns", svgNamespace);
|
|
347
|
+
svg.setAttribute("width", "24");
|
|
348
|
+
svg.setAttribute("height", "24");
|
|
349
|
+
svg.setAttribute("viewBox", "0 0 24 24");
|
|
350
|
+
svg.setAttribute("fill", "none");
|
|
351
|
+
svg.setAttribute("stroke", "currentColor");
|
|
352
|
+
svg.setAttribute("stroke-width", "2");
|
|
353
|
+
svg.setAttribute("stroke-linecap", "round");
|
|
354
|
+
svg.setAttribute("stroke-linejoin", "round");
|
|
355
|
+
svg.setAttribute("aria-hidden", "true");
|
|
356
|
+
svg.setAttribute("focusable", "false");
|
|
357
|
+
|
|
358
|
+
for (const definition of iconDefinitions[name]) {
|
|
359
|
+
const element = document.createElementNS(svgNamespace, definition.name);
|
|
360
|
+
for (const [attr, value] of Object.entries(definition.attrs)) {
|
|
361
|
+
element.setAttribute(attr, value);
|
|
362
|
+
}
|
|
363
|
+
svg.appendChild(element);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return svg;
|
|
367
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Core editor
|
|
2
|
+
export { Compartment, EditorSelection, EditorState, StateEffect, StateField } from "@codemirror/state";
|
|
3
|
+
export type { ChangeSpec, Extension, SelectionRange, Transaction } from "@codemirror/state";
|
|
4
|
+
export { EditorView, highlightActiveLine, keymap } from "@codemirror/view";
|
|
5
|
+
export type { KeyBinding, ViewUpdate } from "@codemirror/view";
|
|
6
|
+
export * from "./mardora";
|
|
7
|
+
export * from "./plugin";
|
|
8
|
+
export * from "./utils";
|
|
9
|
+
export * from "./theme";
|
|
10
|
+
export * from "./icons";
|
|
11
|
+
export * from "./i18n";
|
|
12
|
+
export * from "./slash";
|
|
13
|
+
export * from "./attachments";
|
|
14
|
+
export * from "./selection-toolbar";
|
|
15
|
+
export * from "./table-of-contents";
|
|
16
|
+
export * from "./heading-fold";
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { Extension, Prec } from "@codemirror/state";
|
|
2
|
+
import { EditorView, highlightActiveLine, KeyBinding, keymap } from "@codemirror/view";
|
|
3
|
+
import { markdown, markdownKeymap, markdownLanguage } from "@codemirror/lang-markdown";
|
|
4
|
+
import type { MarkdownConfig } from "@lezer/markdown";
|
|
5
|
+
import { MardoraPlugin, PluginContext } from "./plugin";
|
|
6
|
+
import { createMardoraViewExtension } from "./view-plugin";
|
|
7
|
+
import { defaultKeymap, history, historyKeymap, indentWithTab } from "@codemirror/commands";
|
|
8
|
+
import { indentOnInput } from "@codemirror/language";
|
|
9
|
+
import { languages } from "@codemirror/language-data";
|
|
10
|
+
import { ThemeEnum } from "./utils";
|
|
11
|
+
import { markdownResetExtension } from "./theme";
|
|
12
|
+
import type { MardoraSlashCommandsConfig } from "./slash";
|
|
13
|
+
import { slashCommands } from "./slash";
|
|
14
|
+
import type { MardoraAttachmentsConfig } from "./attachments";
|
|
15
|
+
import { attachments } from "./attachments";
|
|
16
|
+
import type { MardoraSelectionToolbarConfig } from "./selection-toolbar";
|
|
17
|
+
import { selectionToolbar } from "./selection-toolbar";
|
|
18
|
+
import type { MardoraTocConfig } from "./table-of-contents";
|
|
19
|
+
import { tableOfContents } from "./table-of-contents";
|
|
20
|
+
import type { MardoraHeadingFoldConfig } from "./heading-fold";
|
|
21
|
+
import { headingFold } from "./heading-fold";
|
|
22
|
+
import type { MardoraI18nConfig, MardoraLocale } from "./i18n";
|
|
23
|
+
import { resolveMardoraLocale } from "./i18n";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* MardoraNode: represents a node in the markdown tree
|
|
27
|
+
*
|
|
28
|
+
* Useful for debugging and development
|
|
29
|
+
*/
|
|
30
|
+
export type MardoraNode = {
|
|
31
|
+
from: number;
|
|
32
|
+
to: number;
|
|
33
|
+
name: string;
|
|
34
|
+
children: MardoraNode[];
|
|
35
|
+
isSelected: boolean;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Configuration options for the mardora editor
|
|
40
|
+
*/
|
|
41
|
+
export interface MardoraConfig {
|
|
42
|
+
/** Theme */
|
|
43
|
+
theme?: ThemeEnum;
|
|
44
|
+
|
|
45
|
+
/** Editor UI locale. Defaults to Simplified Chinese. */
|
|
46
|
+
locale?: MardoraLocale;
|
|
47
|
+
|
|
48
|
+
/** Internationalization configuration for editor-owned UI text */
|
|
49
|
+
i18n?: MardoraI18nConfig;
|
|
50
|
+
|
|
51
|
+
/** Weather to load base styles */
|
|
52
|
+
baseStyles?: boolean;
|
|
53
|
+
|
|
54
|
+
/** Plugins to load */
|
|
55
|
+
plugins?: MardoraPlugin[];
|
|
56
|
+
|
|
57
|
+
/** Additional markdown extensions for the parser */
|
|
58
|
+
markdown?: MarkdownConfig[];
|
|
59
|
+
|
|
60
|
+
/** Additional CodeMirror extensions */
|
|
61
|
+
extensions?: Extension[];
|
|
62
|
+
|
|
63
|
+
/** Additional keybindings */
|
|
64
|
+
keymap?: KeyBinding[];
|
|
65
|
+
|
|
66
|
+
/** Disable the built-in view plugin (for raw markdown mode) */
|
|
67
|
+
disableViewPlugin?: boolean;
|
|
68
|
+
|
|
69
|
+
/** Enable default keybindings */
|
|
70
|
+
defaultKeybindings?: boolean;
|
|
71
|
+
|
|
72
|
+
/** Enable history */
|
|
73
|
+
history?: boolean;
|
|
74
|
+
|
|
75
|
+
/** Enable indent with tab */
|
|
76
|
+
indentWithTab?: boolean;
|
|
77
|
+
|
|
78
|
+
/** Highlight active line */
|
|
79
|
+
highlightActiveLine?: boolean;
|
|
80
|
+
|
|
81
|
+
/** Line wrapping in raw markdown mode */
|
|
82
|
+
lineWrapping?: boolean;
|
|
83
|
+
|
|
84
|
+
/** Callback to receive the nodes on every update */
|
|
85
|
+
onNodesChange?: (nodes: MardoraNode[]) => void;
|
|
86
|
+
|
|
87
|
+
/** Slash command menu configuration */
|
|
88
|
+
slashCommands?: MardoraSlashCommandsConfig;
|
|
89
|
+
|
|
90
|
+
/** Browser attachment upload configuration */
|
|
91
|
+
attachments?: MardoraAttachmentsConfig;
|
|
92
|
+
|
|
93
|
+
/** Selected text floating toolbar configuration */
|
|
94
|
+
selectionToolbar?: MardoraSelectionToolbarConfig;
|
|
95
|
+
|
|
96
|
+
/** Table of contents configuration */
|
|
97
|
+
toc?: MardoraTocConfig;
|
|
98
|
+
|
|
99
|
+
/** Heading section folding configuration */
|
|
100
|
+
headingFold?: MardoraHeadingFoldConfig;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Creates a mardora editor extension bundle for CodeMirror 6
|
|
105
|
+
*
|
|
106
|
+
* @param config - Configuration options for the editor
|
|
107
|
+
* @returns CodeMirror Extension that can be added to EditorState
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { EditorView } from '@codemirror/view';
|
|
112
|
+
* import { EditorState } from '@codemirror/state';
|
|
113
|
+
* import { mardora } from 'mardora';
|
|
114
|
+
*
|
|
115
|
+
* const view = new EditorView({
|
|
116
|
+
* state: EditorState.create({
|
|
117
|
+
* doc: '# Hello mardora',
|
|
118
|
+
* extensions: [mardora()]
|
|
119
|
+
* }),
|
|
120
|
+
* parent: document.getElementById('editor')
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export function mardora(config: MardoraConfig = {}): Extension[] {
|
|
125
|
+
const {
|
|
126
|
+
locale: configLocale,
|
|
127
|
+
i18n: configI18n = {},
|
|
128
|
+
theme: configTheme = ThemeEnum.AUTO,
|
|
129
|
+
baseStyles = true,
|
|
130
|
+
plugins = [],
|
|
131
|
+
extensions = [],
|
|
132
|
+
keymap: configKeymap = [],
|
|
133
|
+
disableViewPlugin = false,
|
|
134
|
+
defaultKeybindings = true,
|
|
135
|
+
history: configHistory = true,
|
|
136
|
+
indentWithTab: configIndentWithTab = true,
|
|
137
|
+
highlightActiveLine: configHighlightActiveLine = true,
|
|
138
|
+
lineWrapping: configLineWrapping = true,
|
|
139
|
+
onNodesChange: configOnNodesChange = undefined,
|
|
140
|
+
slashCommands: configSlashCommands = { enabled: true },
|
|
141
|
+
attachments: configAttachments = { enabled: false },
|
|
142
|
+
selectionToolbar: configSelectionToolbar = { enabled: true },
|
|
143
|
+
toc: configToc = { enabled: true },
|
|
144
|
+
headingFold: configHeadingFold = { enabled: true },
|
|
145
|
+
} = config;
|
|
146
|
+
const resolvedLocale = resolveMardoraLocale(configSlashCommands.locale ?? configI18n.locale ?? configLocale);
|
|
147
|
+
|
|
148
|
+
const allPlugins = [...plugins];
|
|
149
|
+
|
|
150
|
+
// Collect all extensions from plugins
|
|
151
|
+
const pluginExtensions: Extension[] = [];
|
|
152
|
+
const pluginKeymaps: KeyBinding[] = [];
|
|
153
|
+
const markdownExtensions: MarkdownConfig[] = [];
|
|
154
|
+
|
|
155
|
+
// Create plugin context for lifecycle methods
|
|
156
|
+
const pluginContext: PluginContext = { config };
|
|
157
|
+
|
|
158
|
+
if (!disableViewPlugin) {
|
|
159
|
+
// Process each plugin
|
|
160
|
+
for (const plugin of allPlugins) {
|
|
161
|
+
// Call onRegister lifecycle hook
|
|
162
|
+
plugin.onRegister(pluginContext);
|
|
163
|
+
|
|
164
|
+
// Collect extensions via class method
|
|
165
|
+
const exts = plugin.getExtensions();
|
|
166
|
+
if (exts.length > 0) {
|
|
167
|
+
pluginExtensions.push(...exts);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Collect keymaps via class method
|
|
171
|
+
const keys = plugin.getKeymap();
|
|
172
|
+
if (keys.length > 0) {
|
|
173
|
+
pluginKeymaps.push(...keys);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Collect theme via class method
|
|
177
|
+
const theme = plugin.theme;
|
|
178
|
+
if (baseStyles && theme && typeof theme === "function") {
|
|
179
|
+
pluginExtensions.push(EditorView.theme(theme(configTheme)));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Collect markdown parser extensions via class method
|
|
183
|
+
const md = plugin.getMarkdownConfig();
|
|
184
|
+
if (md) {
|
|
185
|
+
markdownExtensions.push(md);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Add config-level markdown extensions
|
|
191
|
+
if (config.markdown) {
|
|
192
|
+
markdownExtensions.push(...config.markdown);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Build the base markdown language support
|
|
196
|
+
const markdownSupport = markdown({
|
|
197
|
+
base: markdownLanguage,
|
|
198
|
+
codeLanguages: languages,
|
|
199
|
+
extensions: markdownExtensions,
|
|
200
|
+
addKeymap: true,
|
|
201
|
+
completeHTMLTags: true,
|
|
202
|
+
pasteURLAsLink: true,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Core CodeMirror extensions (in order)
|
|
206
|
+
const baseExtensions: Extension[] = [
|
|
207
|
+
...(defaultKeybindings ? [keymap.of(defaultKeymap)] : []),
|
|
208
|
+
...(configHistory ? [history(), keymap.of(historyKeymap)] : []),
|
|
209
|
+
...(configIndentWithTab ? [indentOnInput(), keymap.of([indentWithTab])] : []),
|
|
210
|
+
...(configHighlightActiveLine && disableViewPlugin ? [highlightActiveLine()] : []),
|
|
211
|
+
];
|
|
212
|
+
|
|
213
|
+
// mardora extensions (pass plugins for decoration support)
|
|
214
|
+
const mardoraExtensions: Extension[] = [];
|
|
215
|
+
if (!disableViewPlugin) {
|
|
216
|
+
mardoraExtensions.push(createMardoraViewExtension(configTheme, baseStyles, allPlugins, configOnNodesChange));
|
|
217
|
+
mardoraExtensions.push(Prec.highest(markdownResetExtension));
|
|
218
|
+
}
|
|
219
|
+
if (!disableViewPlugin || configLineWrapping) mardoraExtensions.push(EditorView.lineWrapping);
|
|
220
|
+
|
|
221
|
+
// Compose all extensions together
|
|
222
|
+
const composedExtensions: Extension[] = [
|
|
223
|
+
// Core markdown support (highest priority)
|
|
224
|
+
Prec.high(markdownSupport),
|
|
225
|
+
Prec.high(keymap.of(markdownKeymap)),
|
|
226
|
+
|
|
227
|
+
// mardora view plugin for rich rendering
|
|
228
|
+
mardoraExtensions,
|
|
229
|
+
|
|
230
|
+
// Core CodeMirror extensions
|
|
231
|
+
baseExtensions,
|
|
232
|
+
|
|
233
|
+
// Mardora editor commands and browser attachments
|
|
234
|
+
slashCommands({
|
|
235
|
+
...configSlashCommands,
|
|
236
|
+
inheritedLocale: resolvedLocale,
|
|
237
|
+
attachmentUploader: configAttachments.uploader,
|
|
238
|
+
}),
|
|
239
|
+
attachments(configAttachments),
|
|
240
|
+
selectionToolbar({
|
|
241
|
+
...configSelectionToolbar,
|
|
242
|
+
inheritedLocale: resolvedLocale,
|
|
243
|
+
}),
|
|
244
|
+
tableOfContents(configToc),
|
|
245
|
+
...(!disableViewPlugin ? headingFold(configHeadingFold) : []),
|
|
246
|
+
|
|
247
|
+
// Plugin extensions & keymaps
|
|
248
|
+
pluginExtensions,
|
|
249
|
+
pluginKeymaps.length > 0 ? keymap.of(pluginKeymaps) : [],
|
|
250
|
+
|
|
251
|
+
// Config keymaps & extensions
|
|
252
|
+
configKeymap.length > 0 ? keymap.of(configKeymap) : [],
|
|
253
|
+
extensions,
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
return composedExtensions;
|
|
257
|
+
}
|