draftly 0.1.0-alpha.1 → 1.0.7
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/dist/chunk-2B3A3VSQ.cjs +3382 -0
- package/dist/chunk-2B3A3VSQ.cjs.map +1 -0
- package/dist/{chunk-ZDSZRRUY.cjs → chunk-72ZYRGRT.cjs} +48 -104
- package/dist/chunk-72ZYRGRT.cjs.map +1 -0
- package/dist/{chunk-MOG6E2LY.js → chunk-CG4M4TC7.js} +46 -103
- package/dist/chunk-CG4M4TC7.js.map +1 -0
- package/dist/{chunk-LCQALOEI.js → chunk-DFQYXFOP.js} +36 -3
- package/dist/chunk-DFQYXFOP.js.map +1 -0
- package/dist/{chunk-6LQ2VR4I.js → chunk-HPSMS2WB.js} +38 -22
- package/dist/chunk-HPSMS2WB.js.map +1 -0
- package/dist/{chunk-7Z3SRTPZ.cjs → chunk-KBQDZ5IW.cjs} +38 -22
- package/dist/chunk-KBQDZ5IW.cjs.map +1 -0
- package/dist/{chunk-RV2SYFA6.cjs → chunk-KDEDLC3D.cjs} +36 -2
- package/dist/chunk-KDEDLC3D.cjs.map +1 -0
- package/dist/chunk-N3WL3XPB.js +3360 -0
- package/dist/chunk-N3WL3XPB.js.map +1 -0
- package/dist/{draftly-Bxu_H4nw.d.ts → draftly-BLnx3uGX.d.cts} +12 -6
- package/dist/{draftly-Bxu_H4nw.d.cts → draftly-BLnx3uGX.d.ts} +12 -6
- package/dist/editor/index.cjs +20 -12
- package/dist/editor/index.d.cts +3 -2
- package/dist/editor/index.d.ts +3 -2
- package/dist/editor/index.js +2 -2
- package/dist/index.cjs +59 -27
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -4
- package/dist/plugins/index.cjs +35 -11
- package/dist/plugins/index.d.cts +321 -3
- package/dist/plugins/index.d.ts +321 -3
- package/dist/plugins/index.js +3 -3
- package/dist/preview/index.cjs +7 -7
- package/dist/preview/index.d.cts +9 -4
- package/dist/preview/index.d.ts +9 -4
- package/dist/preview/index.js +2 -2
- package/package.json +2 -1
- package/src/editor/draftly.ts +9 -13
- package/src/editor/plugin.ts +4 -1
- package/src/editor/theme.ts +34 -1
- package/src/editor/utils.ts +49 -0
- package/src/editor/view-plugin.ts +6 -131
- package/src/plugins/code-plugin.ts +1119 -0
- package/src/plugins/heading-plugin.ts +23 -11
- package/src/plugins/hr-plugin.ts +102 -0
- package/src/plugins/image-plugin.ts +96 -2
- package/src/plugins/index.ts +57 -39
- package/src/plugins/inline-plugin.ts +125 -6
- package/src/plugins/link-plugin.ts +509 -0
- package/src/plugins/list-plugin.ts +116 -2
- package/src/plugins/math-plugin.ts +5 -1
- package/src/plugins/mermaid-plugin.ts +500 -0
- package/src/plugins/paragraph-plugin.ts +38 -0
- package/src/plugins/quote-plugin.ts +146 -0
- package/src/preview/context.ts +1 -1
- package/src/preview/css-generator.ts +3 -1
- package/src/preview/default-renderers.ts +0 -5
- package/src/preview/preview.ts +2 -2
- package/src/preview/renderer.ts +34 -12
- package/src/preview/types.ts +1 -1
- package/dist/chunk-6LQ2VR4I.js.map +0 -1
- package/dist/chunk-7Z3SRTPZ.cjs.map +0 -1
- package/dist/chunk-GA6NYY77.cjs +0 -1400
- package/dist/chunk-GA6NYY77.cjs.map +0 -1
- package/dist/chunk-LCQALOEI.js.map +0 -1
- package/dist/chunk-MOG6E2LY.js.map +0 -1
- package/dist/chunk-RV2SYFA6.cjs.map +0 -1
- package/dist/chunk-TKZNKWGF.js +0 -1385
- package/dist/chunk-TKZNKWGF.js.map +0 -1
- package/dist/chunk-ZDSZRRUY.cjs.map +0 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkKDEDLC3D_cjs = require('./chunk-KDEDLC3D.cjs');
|
|
4
4
|
var state = require('@codemirror/state');
|
|
5
5
|
var view = require('@codemirror/view');
|
|
6
6
|
var langMarkdown = require('@codemirror/lang-markdown');
|
|
7
7
|
var language = require('@codemirror/language');
|
|
8
|
+
var highlight = require('@lezer/highlight');
|
|
8
9
|
var commands = require('@codemirror/commands');
|
|
9
10
|
var languageData = require('@codemirror/language-data');
|
|
10
11
|
var styleMod = require('style-mod');
|
|
@@ -16,46 +17,45 @@ var draftlyBaseTheme = view.EditorView.theme({
|
|
|
16
17
|
lineHeight: "1.6"
|
|
17
18
|
},
|
|
18
19
|
"&.cm-draftly .cm-content": {
|
|
20
|
+
width: "100%",
|
|
19
21
|
maxWidth: "48rem",
|
|
22
|
+
padding: "0 0.5rem",
|
|
20
23
|
margin: "0 auto",
|
|
21
24
|
fontFamily: "var(--font-sans, sans-serif)",
|
|
22
25
|
fontSize: "16px",
|
|
23
26
|
lineHeight: "1.6"
|
|
24
27
|
},
|
|
25
28
|
"&.cm-draftly .cm-content .cm-line": {
|
|
26
|
-
|
|
29
|
+
paddingInline: 0
|
|
27
30
|
},
|
|
28
31
|
"&.cm-draftly .cm-content .cm-widgetBuffer": {
|
|
29
32
|
display: "none !important"
|
|
30
33
|
}
|
|
31
34
|
});
|
|
35
|
+
var markdownResetStyle = language.HighlightStyle.define([
|
|
36
|
+
{
|
|
37
|
+
tag: [
|
|
38
|
+
highlight.tags.heading,
|
|
39
|
+
highlight.tags.strong,
|
|
40
|
+
highlight.tags.emphasis,
|
|
41
|
+
highlight.tags.strikethrough,
|
|
42
|
+
highlight.tags.link,
|
|
43
|
+
highlight.tags.url,
|
|
44
|
+
highlight.tags.quote,
|
|
45
|
+
highlight.tags.list,
|
|
46
|
+
highlight.tags.meta,
|
|
47
|
+
highlight.tags.contentSeparator,
|
|
48
|
+
highlight.tags.labelName
|
|
49
|
+
],
|
|
50
|
+
color: "inherit",
|
|
51
|
+
fontWeight: "inherit",
|
|
52
|
+
fontStyle: "inherit",
|
|
53
|
+
textDecoration: "none"
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
56
|
+
var markdownResetExtension = language.syntaxHighlighting(markdownResetStyle, { fallback: false });
|
|
32
57
|
|
|
33
58
|
// src/editor/view-plugin.ts
|
|
34
|
-
var markDecorations = {
|
|
35
|
-
// Inline styles
|
|
36
|
-
"inline-code": view.Decoration.mark({ class: "cm-draftly-inline-code" }),
|
|
37
|
-
// Links and images
|
|
38
|
-
link: view.Decoration.mark({ class: "cm-draftly-link" }),
|
|
39
|
-
"link-text": view.Decoration.mark({ class: "cm-draftly-link-text" }),
|
|
40
|
-
url: view.Decoration.mark({ class: "cm-draftly-url" }),
|
|
41
|
-
image: view.Decoration.mark({ class: "cm-draftly-image" }),
|
|
42
|
-
// Emphasis markers (* _ ~~ `)
|
|
43
|
-
"emphasis-mark": view.Decoration.mark({ class: "cm-draftly-emphasis-mark" }),
|
|
44
|
-
// Code blocks
|
|
45
|
-
"fenced-code": view.Decoration.mark({ class: "cm-draftly-fenced-code" }),
|
|
46
|
-
"code-mark": view.Decoration.mark({ class: "cm-draftly-code-mark" }),
|
|
47
|
-
"code-info": view.Decoration.mark({ class: "cm-draftly-code-info" }),
|
|
48
|
-
// Blockquote
|
|
49
|
-
blockquote: view.Decoration.mark({ class: "cm-draftly-blockquote" }),
|
|
50
|
-
"quote-mark": view.Decoration.mark({ class: "cm-draftly-quote-mark" }),
|
|
51
|
-
// Horizontal rule
|
|
52
|
-
hr: view.Decoration.mark({ class: "cm-draftly-hr" })
|
|
53
|
-
};
|
|
54
|
-
var lineDecorations = {
|
|
55
|
-
blockquote: view.Decoration.line({ class: "cm-draftly-line-blockquote" }),
|
|
56
|
-
"code-block": view.Decoration.line({ class: "cm-draftly-line-code" }),
|
|
57
|
-
hr: view.Decoration.line({ class: "cm-draftly-line-hr" })
|
|
58
|
-
};
|
|
59
59
|
var DraftlyPluginsFacet = state.Facet.define({
|
|
60
60
|
combine: (values) => values.flat()
|
|
61
61
|
});
|
|
@@ -68,77 +68,19 @@ var draftlyThemeFacet = state.Facet.define({
|
|
|
68
68
|
function buildDecorations(view, plugins = []) {
|
|
69
69
|
const builder = new state.RangeSetBuilder();
|
|
70
70
|
const decorations = [];
|
|
71
|
-
const tree = language.syntaxTree(view.state);
|
|
72
|
-
tree.iterate({
|
|
73
|
-
enter: (node) => {
|
|
74
|
-
const { from, to, name } = node;
|
|
75
|
-
const cursorInNode = chunkRV2SYFA6_cjs.selectionOverlapsRange(view, from, to);
|
|
76
|
-
if (name === "InlineCode") {
|
|
77
|
-
decorations.push(markDecorations["inline-code"].range(from, to));
|
|
78
|
-
if (!cursorInNode) {
|
|
79
|
-
const marks = node.node.getChildren("CodeMark");
|
|
80
|
-
for (const mark of marks) {
|
|
81
|
-
decorations.push(markDecorations["code-mark"].range(mark.from, mark.to));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (name === "Link") {
|
|
86
|
-
decorations.push(markDecorations.link.range(from, to));
|
|
87
|
-
const url = node.node.getChild("URL");
|
|
88
|
-
if (url) {
|
|
89
|
-
decorations.push(markDecorations.url.range(url.from, url.to));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (name === "Image") {
|
|
93
|
-
decorations.push(markDecorations.image.range(from, to));
|
|
94
|
-
}
|
|
95
|
-
if (name === "FencedCode") {
|
|
96
|
-
decorations.push(markDecorations["fenced-code"].range(from, to));
|
|
97
|
-
const startLine = view.state.doc.lineAt(from);
|
|
98
|
-
const endLine = view.state.doc.lineAt(to);
|
|
99
|
-
for (let i = startLine.number; i <= endLine.number; i++) {
|
|
100
|
-
const line = view.state.doc.line(i);
|
|
101
|
-
decorations.push(lineDecorations["code-block"].range(line.from));
|
|
102
|
-
}
|
|
103
|
-
const codeInfo = node.node.getChild("CodeInfo");
|
|
104
|
-
if (codeInfo) {
|
|
105
|
-
decorations.push(markDecorations["code-info"].range(codeInfo.from, codeInfo.to));
|
|
106
|
-
}
|
|
107
|
-
const codeMarks = node.node.getChildren("CodeMark");
|
|
108
|
-
for (const mark of codeMarks) {
|
|
109
|
-
decorations.push(markDecorations["code-mark"].range(mark.from, mark.to));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (name === "Blockquote") {
|
|
113
|
-
decorations.push(markDecorations.blockquote.range(from, to));
|
|
114
|
-
const startLine = view.state.doc.lineAt(from);
|
|
115
|
-
const endLine = view.state.doc.lineAt(to);
|
|
116
|
-
for (let i = startLine.number; i <= endLine.number; i++) {
|
|
117
|
-
const line = view.state.doc.line(i);
|
|
118
|
-
decorations.push(lineDecorations.blockquote.range(line.from));
|
|
119
|
-
}
|
|
120
|
-
const quoteMarks = node.node.getChildren("QuoteMark");
|
|
121
|
-
for (const mark of quoteMarks) {
|
|
122
|
-
decorations.push(markDecorations["quote-mark"].range(mark.from, mark.to));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (name === "HorizontalRule") {
|
|
126
|
-
const line = view.state.doc.lineAt(from);
|
|
127
|
-
decorations.push(lineDecorations.hr.range(line.from));
|
|
128
|
-
decorations.push(markDecorations.hr.range(from, to));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
71
|
if (plugins.length > 0) {
|
|
133
72
|
const ctx = {
|
|
134
73
|
view,
|
|
135
74
|
decorations,
|
|
136
|
-
selectionOverlapsRange: (from, to) =>
|
|
137
|
-
cursorInRange: (from, to) =>
|
|
75
|
+
selectionOverlapsRange: (from, to) => chunkKDEDLC3D_cjs.selectionOverlapsRange(view, from, to),
|
|
76
|
+
cursorInRange: (from, to) => chunkKDEDLC3D_cjs.cursorInRange(view, from, to)
|
|
138
77
|
};
|
|
139
78
|
const sortedPlugins = [...plugins].sort((a, b) => a.decorationPriority - b.decorationPriority);
|
|
140
79
|
for (const plugin of sortedPlugins) {
|
|
141
|
-
|
|
80
|
+
try {
|
|
81
|
+
plugin.buildDecorations(ctx);
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
142
84
|
}
|
|
143
85
|
}
|
|
144
86
|
decorations.sort((a, b) => a.from - b.from || a.value.startSide - b.value.startSide);
|
|
@@ -186,7 +128,7 @@ var draftlyViewPluginClass = class {
|
|
|
186
128
|
to: nodeRef.to,
|
|
187
129
|
name: nodeRef.name,
|
|
188
130
|
children: [],
|
|
189
|
-
isSelected:
|
|
131
|
+
isSelected: chunkKDEDLC3D_cjs.selectionOverlapsRange(view, nodeRef.from, nodeRef.to)
|
|
190
132
|
};
|
|
191
133
|
if (stack.length > 0) {
|
|
192
134
|
stack[stack.length - 1].children.push(node);
|
|
@@ -220,7 +162,6 @@ function createDraftlyViewExtension(theme = "auto" /* AUTO */, baseStyles = true
|
|
|
220
162
|
function draftly(config = {}) {
|
|
221
163
|
const {
|
|
222
164
|
theme: configTheme = "auto" /* AUTO */,
|
|
223
|
-
themeStyle: configThemeStyle = void 0,
|
|
224
165
|
baseStyles = true,
|
|
225
166
|
plugins = [],
|
|
226
167
|
extensions = [],
|
|
@@ -274,25 +215,25 @@ function draftly(config = {}) {
|
|
|
274
215
|
...configHighlightActiveLine && disableViewPlugin ? [view.highlightActiveLine()] : []
|
|
275
216
|
];
|
|
276
217
|
const draftlyExtensions = [];
|
|
277
|
-
if (!disableViewPlugin)
|
|
218
|
+
if (!disableViewPlugin) {
|
|
278
219
|
draftlyExtensions.push(createDraftlyViewExtension(configTheme, baseStyles, allPlugins, configOnNodesChange));
|
|
220
|
+
draftlyExtensions.push(state.Prec.highest(markdownResetExtension));
|
|
221
|
+
}
|
|
279
222
|
if (!disableViewPlugin || configLineWrapping) draftlyExtensions.push(view.EditorView.lineWrapping);
|
|
280
223
|
const composedExtensions = [
|
|
281
224
|
// Core markdown support (highest priority)
|
|
282
225
|
state.Prec.high(markdownSupport),
|
|
283
226
|
state.Prec.high(view.keymap.of(langMarkdown.markdownKeymap)),
|
|
284
|
-
// Theme styles
|
|
285
|
-
...configThemeStyle ? [state.Prec.high(configThemeStyle)] : [],
|
|
286
|
-
// Core CodeMirror extensions
|
|
287
|
-
...baseExtensions,
|
|
288
227
|
// draftly view plugin for rich rendering
|
|
289
|
-
|
|
228
|
+
draftlyExtensions,
|
|
229
|
+
// Core CodeMirror extensions
|
|
230
|
+
baseExtensions,
|
|
290
231
|
// Plugin extensions & keymaps
|
|
291
|
-
|
|
232
|
+
pluginExtensions,
|
|
292
233
|
pluginKeymaps.length > 0 ? view.keymap.of(pluginKeymaps) : [],
|
|
293
234
|
// Config keymaps & extensions
|
|
294
235
|
configKeymap.length > 0 ? view.keymap.of(configKeymap) : [],
|
|
295
|
-
|
|
236
|
+
extensions
|
|
296
237
|
];
|
|
297
238
|
return composedExtensions;
|
|
298
239
|
}
|
|
@@ -301,6 +242,8 @@ var DraftlyPlugin = class {
|
|
|
301
242
|
decorationPriority = 100;
|
|
302
243
|
/** Plugin dependencies - names of required plugins */
|
|
303
244
|
dependencies = [];
|
|
245
|
+
/** Node types this plugin handles for decorations and preview rendering */
|
|
246
|
+
requiredNodes = [];
|
|
304
247
|
/** Private configuration storage */
|
|
305
248
|
_config = {};
|
|
306
249
|
/** Protected context - accessible to subclasses */
|
|
@@ -319,7 +262,7 @@ var DraftlyPlugin = class {
|
|
|
319
262
|
}
|
|
320
263
|
/** Plugin theme */
|
|
321
264
|
get theme() {
|
|
322
|
-
return
|
|
265
|
+
return chunkKDEDLC3D_cjs.createTheme({
|
|
323
266
|
default: {},
|
|
324
267
|
dark: {},
|
|
325
268
|
light: {}
|
|
@@ -451,5 +394,6 @@ exports.DraftlyPlugin = DraftlyPlugin;
|
|
|
451
394
|
exports.SyntaxPlugin = SyntaxPlugin;
|
|
452
395
|
exports.draftly = draftly;
|
|
453
396
|
exports.draftlyBaseTheme = draftlyBaseTheme;
|
|
454
|
-
|
|
455
|
-
//# sourceMappingURL=chunk-
|
|
397
|
+
exports.markdownResetExtension = markdownResetExtension;
|
|
398
|
+
//# sourceMappingURL=chunk-72ZYRGRT.cjs.map
|
|
399
|
+
//# sourceMappingURL=chunk-72ZYRGRT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/editor/theme.ts","../src/editor/view-plugin.ts","../src/editor/draftly.ts","../src/editor/plugin.ts"],"names":["EditorView","HighlightStyle","t","syntaxHighlighting","Facet","RangeSetBuilder","selectionOverlapsRange","cursorInRange","syntaxTree","ViewPlugin","markdown","markdownLanguage","languages","keymap","defaultKeymap","history","historyKeymap","indentOnInput","indentWithTab","highlightActiveLine","Prec","markdownKeymap","createTheme","styleMod","StyleModule"],"mappings":";;;;;;;;;;;;AAMO,IAAM,gBAAA,GAAmBA,gBAAW,KAAA,CAAM;AAAA;AAAA,EAE/C,cAAA,EAAgB;AAAA,IACd,QAAA,EAAU,MAAA;AAAA,IACV,UAAA,EAAY;AAAA,GACd;AAAA,EAEA,0BAAA,EAA4B;AAAA,IAC1B,KAAA,EAAO,MAAA;AAAA,IACP,QAAA,EAAU,OAAA;AAAA,IACV,OAAA,EAAS,UAAA;AAAA,IACT,MAAA,EAAQ,QAAA;AAAA,IACR,UAAA,EAAY,8BAAA;AAAA,IACZ,QAAA,EAAU,MAAA;AAAA,IACV,UAAA,EAAY;AAAA,GACd;AAAA,EAEA,mCAAA,EAAqC;AAAA,IACnC,aAAA,EAAe;AAAA,GACjB;AAAA,EAEA,2CAAA,EAA6C;AAAA,IAC3C,OAAA,EAAS;AAAA;AAEb,CAAC;AASD,IAAM,kBAAA,GAAqBC,wBAAe,MAAA,CAAO;AAAA,EAC/C;AAAA,IACE,GAAA,EAAK;AAAA,MACHC,cAAA,CAAE,OAAA;AAAA,MACFA,cAAA,CAAE,MAAA;AAAA,MACFA,cAAA,CAAE,QAAA;AAAA,MACFA,cAAA,CAAE,aAAA;AAAA,MACFA,cAAA,CAAE,IAAA;AAAA,MACFA,cAAA,CAAE,GAAA;AAAA,MACFA,cAAA,CAAE,KAAA;AAAA,MACFA,cAAA,CAAE,IAAA;AAAA,MACFA,cAAA,CAAE,IAAA;AAAA,MACFA,cAAA,CAAE,gBAAA;AAAA,MACFA,cAAA,CAAE;AAAA,KACJ;AAAA,IACA,KAAA,EAAO,SAAA;AAAA,IACP,UAAA,EAAY,SAAA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AA;AAAA,MAChC;AAAA,KACD,CAAA;AACD,IAAA,OAAOD,WAAS,QAAA,EAAS;AAAA,EAC3B;AACF;AAMO,IAAe,gBAAA,GAAf,cAAwC,aAAA,CAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAKlD,kBAAA,GAAqB,EAAA;AAOhC;AAMO,IAAe,YAAA,GAAf,cAAoC,aAAA,CAAc;AAKzD","file":"chunk-72ZYRGRT.cjs","sourcesContent":["import { EditorView } from \"@codemirror/view\";\n\n/**\n * Base theme for draftly styling\n * Note: Layout styles are scoped under .cm-draftly which is added by the view plugin\n */\nexport const draftlyBaseTheme = EditorView.theme({\n // Container styles - only apply when view plugin is enabled\n \"&.cm-draftly\": {\n fontSize: \"16px\",\n lineHeight: \"1.6\",\n },\n\n \"&.cm-draftly .cm-content\": {\n width: \"100%\",\n maxWidth: \"48rem\",\n padding: \"0 0.5rem\",\n margin: \"0 auto\",\n fontFamily: \"var(--font-sans, sans-serif)\",\n fontSize: \"16px\",\n lineHeight: \"1.6\",\n },\n\n \"&.cm-draftly .cm-content .cm-line\": {\n paddingInline: 0,\n },\n\n \"&.cm-draftly .cm-content .cm-widgetBuffer\": {\n display: \"none !important\",\n },\n});\n\nimport { HighlightStyle, syntaxHighlighting } from \"@codemirror/language\";\nimport { tags as t } from \"@lezer/highlight\";\n\n/**\n * Reset syntax highlighting for markdown elements\n * Used to disable theme colors for markdown syntax\n */\nconst markdownResetStyle = HighlightStyle.define([\n {\n tag: [\n t.heading,\n t.strong,\n t.emphasis,\n t.strikethrough,\n t.link,\n t.url,\n t.quote,\n t.list,\n t.meta,\n t.contentSeparator,\n t.labelName,\n ],\n color: \"inherit\",\n fontWeight: \"inherit\",\n fontStyle: \"inherit\",\n textDecoration: \"none\",\n },\n]);\n\nexport const markdownResetExtension = syntaxHighlighting(markdownResetStyle, { fallback: false });\n","import { Decoration, DecorationSet, EditorView, ViewPlugin, ViewUpdate } from \"@codemirror/view\";\nimport { Extension, Facet, Range, RangeSetBuilder } from \"@codemirror/state\";\nimport { syntaxTree } from \"@codemirror/language\";\nimport { cursorInRange, selectionOverlapsRange, ThemeEnum } from \"./utils\";\nimport { draftlyBaseTheme } from \"./theme\";\nimport { DecorationContext, DraftlyPlugin } from \"./plugin\";\nimport { DraftlyNode } from \"./draftly\";\n\n/**\n * Facet to register plugins with the view plugin\n */\nexport const DraftlyPluginsFacet = Facet.define<DraftlyPlugin[], DraftlyPlugin[]>({\n combine: (values) => values.flat(),\n});\n\n/**\n * Facet to register the onNodesChange callback\n */\nexport const draftlyOnNodesChangeFacet = Facet.define<\n ((nodes: DraftlyNode[]) => void) | undefined,\n ((nodes: DraftlyNode[]) => void) | undefined\n>({\n combine: (values) => values.find((v) => v !== undefined),\n});\n\n/**\n * Facet to register the theme\n */\nexport const draftlyThemeFacet = Facet.define<ThemeEnum, ThemeEnum>({\n combine: (values) => values.find((v) => v !== undefined) || ThemeEnum.AUTO,\n});\n\n/**\n * Build decorations for the visible viewport\n * @param view - The EditorView instance\n * @param plugins - Optional array of plugins to invoke for decorations\n */\nfunction buildDecorations(view: EditorView, plugins: DraftlyPlugin[] = []): DecorationSet {\n const builder = new RangeSetBuilder<Decoration>();\n const decorations: Range<Decoration>[] = [];\n\n // Allow plugins to contribute decorations\n if (plugins.length > 0) {\n const ctx: DecorationContext = {\n view,\n decorations,\n selectionOverlapsRange: (from, to) => selectionOverlapsRange(view, from, to),\n cursorInRange: (from, to) => cursorInRange(view, from, to),\n };\n\n // Sort plugins by priority and invoke each one's decoration builder\n const sortedPlugins = [...plugins].sort((a, b) => a.decorationPriority - b.decorationPriority);\n\n for (const plugin of sortedPlugins) {\n try {\n plugin.buildDecorations(ctx);\n } catch {\n // Silently ignore errors from partial tree states (e.g., Lezer TreeBuffer\n // \"Invalid child in posBefore\"). These resolve on the next update cycle.\n }\n }\n }\n\n // Sort decorations by position (required for RangeSetBuilder)\n decorations.sort((a, b) => a.from - b.from || a.value.startSide - b.value.startSide);\n\n // Build the decoration set\n for (const decoration of decorations) {\n builder.add(decoration.from, decoration.to, decoration.value);\n }\n\n return builder.finish();\n}\n\n/**\n * draftly View Plugin\n * Handles rich markdown rendering with decorations\n */\nclass draftlyViewPluginClass {\n decorations: DecorationSet;\n private plugins: DraftlyPlugin[];\n private onNodesChange: ((nodes: DraftlyNode[]) => void) | undefined;\n\n constructor(view: EditorView) {\n this.plugins = view.state.facet(DraftlyPluginsFacet);\n this.onNodesChange = view.state.facet(draftlyOnNodesChangeFacet);\n this.decorations = buildDecorations(view, this.plugins);\n\n // Notify plugins that view is ready\n for (const plugin of this.plugins) {\n plugin.onViewReady(view);\n }\n\n // Call onNodesChange callback with initial nodes\n if (this.onNodesChange && typeof this.onNodesChange === \"function\") {\n this.onNodesChange(this.buildNodes(view));\n }\n }\n\n update(update: ViewUpdate) {\n // Update plugins list if facet changed\n this.plugins = update.view.state.facet(DraftlyPluginsFacet);\n this.onNodesChange = update.view.state.facet(draftlyOnNodesChangeFacet);\n\n // Notify plugins of the update\n for (const plugin of this.plugins) {\n plugin.onViewUpdate(update);\n }\n\n // Rebuild decorations when:\n // - Document changes\n // - Selection changes (to show/hide syntax markers)\n // - Viewport changes\n if (update.docChanged || update.selectionSet || update.viewportChanged) {\n this.decorations = buildDecorations(update.view, this.plugins);\n\n // Call onNodesChange callback\n if (this.onNodesChange) {\n this.onNodesChange(this.buildNodes(update.view));\n }\n }\n }\n\n private buildNodes(view: EditorView): DraftlyNode[] {\n const tree = syntaxTree(view.state);\n const roots: DraftlyNode[] = [];\n const stack: DraftlyNode[] = [];\n\n tree.iterate({\n enter: (nodeRef) => {\n const node: DraftlyNode = {\n from: nodeRef.from,\n to: nodeRef.to,\n name: nodeRef.name,\n children: [],\n isSelected: selectionOverlapsRange(view, nodeRef.from, nodeRef.to),\n };\n\n if (stack.length > 0) {\n stack[stack.length - 1]!.children.push(node);\n } else {\n roots.push(node);\n }\n\n stack.push(node);\n },\n leave: () => {\n stack.pop();\n },\n });\n\n return roots;\n }\n}\n\n/**\n * The main draftly ViewPlugin extension\n */\nexport const draftlyViewPlugin = ViewPlugin.fromClass(draftlyViewPluginClass, {\n decorations: (v) => v.decorations,\n provide: () => [],\n});\n\n/**\n * Extension to add the cm-draftly-enabled class to the editor\n */\nconst draftlyEditorClass = EditorView.editorAttributes.of({ class: \"cm-draftly\" });\n\n/**\n * Create draftly view extension bundle with plugin support\n * @param plugins - Optional array of DraftlyPlugin instances\n * @param onNodesChange - Optional callback to receive nodes on every update\n * @returns Extension array including view plugin, theme, and plugin facet\n */\nexport function createDraftlyViewExtension(\n theme: ThemeEnum = ThemeEnum.AUTO,\n baseStyles: boolean = true,\n plugins: DraftlyPlugin[] = [],\n onNodesChange?: (nodes: DraftlyNode[]) => void\n): Extension[] {\n return [\n draftlyEditorClass,\n DraftlyPluginsFacet.of(plugins),\n draftlyOnNodesChangeFacet.of(onNodesChange),\n draftlyThemeFacet.of(theme),\n draftlyViewPlugin,\n ...(baseStyles ? [draftlyBaseTheme] : []),\n ];\n}\n","import { Extension, Prec } from \"@codemirror/state\";\nimport { EditorView, highlightActiveLine, KeyBinding, keymap } from \"@codemirror/view\";\nimport { markdown, markdownKeymap, markdownLanguage } from \"@codemirror/lang-markdown\";\nimport type { MarkdownConfig } from \"@lezer/markdown\";\nimport { DraftlyPlugin, PluginContext } from \"./plugin\";\nimport { createDraftlyViewExtension } from \"./view-plugin\";\nimport { defaultKeymap, history, historyKeymap, indentWithTab } from \"@codemirror/commands\";\nimport { indentOnInput } from \"@codemirror/language\";\nimport { languages } from \"@codemirror/language-data\";\nimport { ThemeEnum } from \"./utils\";\nimport { markdownResetExtension } from \"./theme\";\n\n/**\n * DraftlyNode: represents a node in the markdown tree\n *\n * Useful for debugging and development\n */\nexport type DraftlyNode = {\n from: number;\n to: number;\n name: string;\n children: DraftlyNode[];\n isSelected: boolean;\n};\n\n/**\n * Configuration options for the draftly editor\n */\nexport interface DraftlyConfig {\n /** Theme */\n theme?: ThemeEnum;\n\n /** Weather to load base styles */\n baseStyles?: boolean;\n\n /** Plugins to load */\n plugins?: DraftlyPlugin[];\n\n /** Additional markdown extensions for the parser */\n markdown?: MarkdownConfig[];\n\n /** Additional CodeMirror extensions */\n extensions?: Extension[];\n\n /** Additional keybindings */\n keymap?: KeyBinding[];\n\n /** Disable the built-in view plugin (for raw markdown mode) */\n disableViewPlugin?: boolean;\n\n /** Enable default keybindings */\n defaultKeybindings?: boolean;\n\n /** Enable history */\n history?: boolean;\n\n /** Enable indent with tab */\n indentWithTab?: boolean;\n\n /** Highlight active line */\n highlightActiveLine?: boolean;\n\n /** Line wrapping in raw markdown mode */\n lineWrapping?: boolean;\n\n /** Callback to receive the nodes on every update */\n onNodesChange?: (nodes: DraftlyNode[]) => void;\n}\n\n/**\n * Creates a draftly editor extension bundle for CodeMirror 6\n *\n * @param config - Configuration options for the editor\n * @returns CodeMirror Extension that can be added to EditorState\n *\n * @example\n * ```ts\n * import { EditorView } from '@codemirror/view';\n * import { EditorState } from '@codemirror/state';\n * import { draftly } from 'draftly';\n *\n * const view = new EditorView({\n * state: EditorState.create({\n * doc: '# Hello draftly',\n * extensions: [draftly()]\n * }),\n * parent: document.getElementById('editor')\n * });\n * ```\n */\nexport function draftly(config: DraftlyConfig = {}): Extension[] {\n const {\n theme: configTheme = ThemeEnum.AUTO,\n baseStyles = true,\n plugins = [],\n extensions = [],\n keymap: configKeymap = [],\n disableViewPlugin = false,\n defaultKeybindings = true,\n history: configHistory = true,\n indentWithTab: configIndentWithTab = true,\n highlightActiveLine: configHighlightActiveLine = true,\n lineWrapping: configLineWrapping = true,\n onNodesChange: configOnNodesChange = undefined,\n } = config;\n\n const allPlugins = [...plugins];\n\n // Collect all extensions from plugins\n const pluginExtensions: Extension[] = [];\n const pluginKeymaps: KeyBinding[] = [];\n const markdownExtensions: MarkdownConfig[] = [];\n\n // Create plugin context for lifecycle methods\n const pluginContext: PluginContext = { config };\n\n // Process each plugin\n for (const plugin of allPlugins) {\n // Call onRegister lifecycle hook\n plugin.onRegister(pluginContext);\n\n // Collect extensions via class method\n const exts = plugin.getExtensions();\n if (exts.length > 0) {\n pluginExtensions.push(...exts);\n }\n\n // Collect keymaps via class method\n const keys = plugin.getKeymap();\n if (keys.length > 0) {\n pluginKeymaps.push(...keys);\n }\n\n // Collect theme via class method\n const theme = plugin.theme;\n if (baseStyles && theme && typeof theme === \"function\") {\n pluginExtensions.push(EditorView.theme(theme(configTheme)));\n }\n\n // Collect markdown parser extensions via class method\n const md = plugin.getMarkdownConfig();\n if (md) {\n markdownExtensions.push(md);\n }\n }\n\n // Add config-level markdown extensions\n if (config.markdown) {\n markdownExtensions.push(...config.markdown);\n }\n\n // Build the base markdown language support\n const markdownSupport = markdown({\n base: markdownLanguage,\n codeLanguages: languages,\n extensions: markdownExtensions,\n addKeymap: true,\n completeHTMLTags: true,\n });\n\n // Core CodeMirror extensions (in order)\n const baseExtensions: Extension[] = [\n ...(defaultKeybindings ? [keymap.of(defaultKeymap)] : []),\n ...(configHistory ? [history(), keymap.of(historyKeymap)] : []),\n ...(configIndentWithTab ? [indentOnInput(), keymap.of([indentWithTab])] : []),\n ...(configHighlightActiveLine && disableViewPlugin ? [highlightActiveLine()] : []),\n ];\n\n // draftly extensions (pass plugins for decoration support)\n const draftlyExtensions: Extension[] = [];\n if (!disableViewPlugin) {\n draftlyExtensions.push(createDraftlyViewExtension(configTheme, baseStyles, allPlugins, configOnNodesChange));\n draftlyExtensions.push(Prec.highest(markdownResetExtension));\n }\n if (!disableViewPlugin || configLineWrapping) draftlyExtensions.push(EditorView.lineWrapping);\n\n // Compose all extensions together\n const composedExtensions: Extension[] = [\n // Core markdown support (highest priority)\n Prec.high(markdownSupport),\n Prec.high(keymap.of(markdownKeymap)),\n\n // draftly view plugin for rich rendering\n draftlyExtensions,\n\n // Core CodeMirror extensions\n baseExtensions,\n\n // Plugin extensions & keymaps\n pluginExtensions,\n pluginKeymaps.length > 0 ? keymap.of(pluginKeymaps) : [],\n\n // Config keymaps & extensions\n configKeymap.length > 0 ? keymap.of(configKeymap) : [],\n extensions,\n ];\n\n return composedExtensions;\n}\n","import { Decoration, EditorView, KeyBinding, ViewUpdate } from \"@codemirror/view\";\nimport { Extension, Range } from \"@codemirror/state\";\nimport { MarkdownConfig } from \"@lezer/markdown\";\nimport { SyntaxNode } from \"@lezer/common\";\nimport { DraftlyConfig } from \"./draftly\";\nimport { createTheme, ThemeEnum, ThemeStyle } from \"./utils\";\nimport { StyleModule } from \"style-mod\";\n\n/**\n * Context passed to plugin lifecycle methods\n */\nexport interface PluginContext {\n /** Current configuration */\n readonly config: DraftlyConfig;\n}\n\n/**\n * Plugin configuration schema\n */\nexport interface PluginConfig {\n [key: string]: unknown;\n}\n\n/**\n * Decoration context passed to plugin decoration builders\n * Provides access to view state and decoration collection\n */\nexport interface DecorationContext {\n /** The EditorView instance (readonly) */\n readonly view: EditorView;\n\n /** Array to push decorations into (will be sorted automatically) */\n readonly decorations: Range<Decoration>[];\n\n /** Check if selection overlaps with a range (to show raw markdown) */\n selectionOverlapsRange(from: number, to: number): boolean;\n\n /** Check if cursor is within a range */\n cursorInRange(from: number, to: number): boolean;\n}\n\n/**\n * Abstract base class for all draftly plugins\n *\n * Implements OOP principles:\n * - Abstraction: abstract name/version must be implemented by subclasses\n * - Encapsulation: private _config, protected _context\n * - Inheritance: specialized plugin classes can extend this\n */\nexport abstract class DraftlyPlugin {\n /** Unique plugin identifier (abstract - must be implemented) */\n abstract readonly name: string;\n\n /** Plugin version (abstract - must be implemented) */\n abstract readonly version: string;\n\n /** Decoration priority (higher = applied later) */\n readonly decorationPriority: number = 100;\n\n /** Plugin dependencies - names of required plugins */\n readonly dependencies: string[] = [];\n\n /** Node types this plugin handles for decorations and preview rendering */\n readonly requiredNodes: readonly string[] = [];\n\n /** Private configuration storage */\n private _config: PluginConfig = {};\n\n /** Protected context - accessible to subclasses */\n protected _context: PluginContext | null = null;\n\n /** Get plugin configuration */\n get config(): PluginConfig {\n return this._config;\n }\n\n /** Set plugin configuration */\n set config(value: PluginConfig) {\n this._config = value;\n }\n\n /** Get plugin context */\n get context(): PluginContext | null {\n return this._context;\n }\n\n /** Plugin theme */\n get theme(): (theme: ThemeEnum) => ThemeStyle {\n return createTheme({\n default: {},\n dark: {},\n light: {},\n });\n }\n\n // ============================================\n // EXTENSION METHODS (overridable by subclasses)\n // ============================================\n\n /**\n * Return CodeMirror extensions for this plugin\n * Override to provide custom extensions\n */\n getExtensions(): Extension[] {\n return [];\n }\n\n /**\n * Return markdown parser extensions\n * Override to extend markdown parsing\n */\n getMarkdownConfig(): MarkdownConfig | null {\n return null;\n }\n\n /**\n * Return keybindings for this plugin\n * Override to add custom keyboard shortcuts\n */\n getKeymap(): KeyBinding[] {\n return [];\n }\n\n // ============================================\n // DECORATION METHODS (overridable by subclasses)\n // ============================================\n\n /**\n * Build decorations for the current view state\n * Override to contribute decorations to the editor\n *\n * @param ctx - Decoration context with view and decoration array\n */\n buildDecorations(_ctx: DecorationContext): void {\n // Default implementation does nothing\n // Subclasses override to add decorations\n }\n\n // ============================================\n // LIFECYCLE HOOKS (overridable by subclasses)\n // ============================================\n\n /**\n * Called when plugin is registered with draftly\n * Override to perform initialization\n *\n * @param context - Plugin context with configuration\n */\n onRegister(context: PluginContext): void | Promise<void> {\n this._context = context;\n }\n\n /**\n * Called when plugin is unregistered\n * Override to perform cleanup\n */\n onUnregister(): void {\n this._context = null;\n }\n\n /**\n * Called when EditorView is created and ready\n * Override to perform view-specific initialization\n *\n * @param view - The EditorView instance\n */\n onViewReady(_view: EditorView): void {\n // Default implementation does nothing\n }\n\n /**\n * Called on view updates (document changes, selection changes, etc.)\n * Override to react to editor changes\n *\n * @param update - The ViewUpdate with change information\n */\n onViewUpdate(_update: ViewUpdate): void {\n // Default implementation does nothing\n }\n\n // ============================================\n // PROTECTED UTILITIES (for subclasses)\n // ============================================\n\n /**\n * Helper to get current editor state\n * @param view - The EditorView instance\n */\n protected getState(view: EditorView) {\n return view.state;\n }\n\n /**\n * Helper to get current document\n * @param view - The EditorView instance\n */\n protected getDocument(view: EditorView) {\n return view.state.doc;\n }\n\n // ============================================\n // PREVIEW RENDERING METHODS (for draftly/preview)\n // ============================================\n\n /**\n * Render a syntax node to HTML for preview mode\n * Override to provide custom HTML rendering for specific node types\n *\n * @param node - The syntax node to render\n * @param children - Pre-rendered children HTML\n * @param ctx - Preview context with document and utilities\n * @returns HTML string to use, or null to use default rendering\n */\n renderToHTML?(\n node: SyntaxNode,\n children: string,\n ctx: { sliceDoc(from: number, to: number): string; sanitize(html: string): string }\n ): string | null | Promise<string | null>;\n\n /**\n * Get CSS styles for preview mode\n * Override to provide custom CSS for preview rendering\n *\n * @param theme - Current theme enum\n * @returns CSS string for preview styles\n */\n getPreviewStyles(theme: ThemeEnum, wrapperClass: string): string {\n const themeStyles = this.theme(theme);\n return this.transformToCss(themeStyles, wrapperClass);\n }\n\n /**\n * Transform ThemeStyle object to CSS string for preview\n * Uses cssClassMap to convert CM selectors to semantic selectors\n */\n protected transformToCss(themeStyles: ThemeStyle, wrapperClass: string): string {\n const styleMod = new StyleModule(themeStyles, {\n finish: (sel) => {\n return `.${wrapperClass} ${sel}`;\n },\n });\n return styleMod.getRules();\n }\n}\n\n/**\n * Base class for plugins that primarily contribute decorations\n * Extends DraftlyPlugin with decoration-focused defaults\n */\nexport abstract class DecorationPlugin extends DraftlyPlugin {\n /**\n * Decoration priority - lower than default for decoration plugins\n * Override to customize\n */\n override decorationPriority = 50;\n\n /**\n * Subclasses must implement this to provide decorations\n * @param ctx - Decoration context\n */\n abstract override buildDecorations(ctx: DecorationContext): void;\n}\n\n/**\n * Base class for plugins that add syntax/parser extensions\n * Extends DraftlyPlugin with syntax-focused requirements\n */\nexport abstract class SyntaxPlugin extends DraftlyPlugin {\n /**\n * Subclasses must implement this to provide markdown config\n */\n abstract override getMarkdownConfig(): MarkdownConfig;\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { selectionOverlapsRange, cursorInRange, createTheme } from './chunk-
|
|
1
|
+
import { selectionOverlapsRange, cursorInRange, createTheme } from './chunk-DFQYXFOP.js';
|
|
2
2
|
import { Facet, RangeSetBuilder, Prec } from '@codemirror/state';
|
|
3
|
-
import { EditorView,
|
|
3
|
+
import { EditorView, ViewPlugin, keymap, highlightActiveLine } from '@codemirror/view';
|
|
4
4
|
import { markdown, markdownLanguage, markdownKeymap } from '@codemirror/lang-markdown';
|
|
5
|
-
import { syntaxTree, indentOnInput } from '@codemirror/language';
|
|
5
|
+
import { HighlightStyle, syntaxHighlighting, syntaxTree, indentOnInput } from '@codemirror/language';
|
|
6
|
+
import { tags } from '@lezer/highlight';
|
|
6
7
|
import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands';
|
|
7
8
|
import { languages } from '@codemirror/language-data';
|
|
8
9
|
import { StyleModule } from 'style-mod';
|
|
@@ -14,46 +15,45 @@ var draftlyBaseTheme = EditorView.theme({
|
|
|
14
15
|
lineHeight: "1.6"
|
|
15
16
|
},
|
|
16
17
|
"&.cm-draftly .cm-content": {
|
|
18
|
+
width: "100%",
|
|
17
19
|
maxWidth: "48rem",
|
|
20
|
+
padding: "0 0.5rem",
|
|
18
21
|
margin: "0 auto",
|
|
19
22
|
fontFamily: "var(--font-sans, sans-serif)",
|
|
20
23
|
fontSize: "16px",
|
|
21
24
|
lineHeight: "1.6"
|
|
22
25
|
},
|
|
23
26
|
"&.cm-draftly .cm-content .cm-line": {
|
|
24
|
-
|
|
27
|
+
paddingInline: 0
|
|
25
28
|
},
|
|
26
29
|
"&.cm-draftly .cm-content .cm-widgetBuffer": {
|
|
27
30
|
display: "none !important"
|
|
28
31
|
}
|
|
29
32
|
});
|
|
33
|
+
var markdownResetStyle = HighlightStyle.define([
|
|
34
|
+
{
|
|
35
|
+
tag: [
|
|
36
|
+
tags.heading,
|
|
37
|
+
tags.strong,
|
|
38
|
+
tags.emphasis,
|
|
39
|
+
tags.strikethrough,
|
|
40
|
+
tags.link,
|
|
41
|
+
tags.url,
|
|
42
|
+
tags.quote,
|
|
43
|
+
tags.list,
|
|
44
|
+
tags.meta,
|
|
45
|
+
tags.contentSeparator,
|
|
46
|
+
tags.labelName
|
|
47
|
+
],
|
|
48
|
+
color: "inherit",
|
|
49
|
+
fontWeight: "inherit",
|
|
50
|
+
fontStyle: "inherit",
|
|
51
|
+
textDecoration: "none"
|
|
52
|
+
}
|
|
53
|
+
]);
|
|
54
|
+
var markdownResetExtension = syntaxHighlighting(markdownResetStyle, { fallback: false });
|
|
30
55
|
|
|
31
56
|
// src/editor/view-plugin.ts
|
|
32
|
-
var markDecorations = {
|
|
33
|
-
// Inline styles
|
|
34
|
-
"inline-code": Decoration.mark({ class: "cm-draftly-inline-code" }),
|
|
35
|
-
// Links and images
|
|
36
|
-
link: Decoration.mark({ class: "cm-draftly-link" }),
|
|
37
|
-
"link-text": Decoration.mark({ class: "cm-draftly-link-text" }),
|
|
38
|
-
url: Decoration.mark({ class: "cm-draftly-url" }),
|
|
39
|
-
image: Decoration.mark({ class: "cm-draftly-image" }),
|
|
40
|
-
// Emphasis markers (* _ ~~ `)
|
|
41
|
-
"emphasis-mark": Decoration.mark({ class: "cm-draftly-emphasis-mark" }),
|
|
42
|
-
// Code blocks
|
|
43
|
-
"fenced-code": Decoration.mark({ class: "cm-draftly-fenced-code" }),
|
|
44
|
-
"code-mark": Decoration.mark({ class: "cm-draftly-code-mark" }),
|
|
45
|
-
"code-info": Decoration.mark({ class: "cm-draftly-code-info" }),
|
|
46
|
-
// Blockquote
|
|
47
|
-
blockquote: Decoration.mark({ class: "cm-draftly-blockquote" }),
|
|
48
|
-
"quote-mark": Decoration.mark({ class: "cm-draftly-quote-mark" }),
|
|
49
|
-
// Horizontal rule
|
|
50
|
-
hr: Decoration.mark({ class: "cm-draftly-hr" })
|
|
51
|
-
};
|
|
52
|
-
var lineDecorations = {
|
|
53
|
-
blockquote: Decoration.line({ class: "cm-draftly-line-blockquote" }),
|
|
54
|
-
"code-block": Decoration.line({ class: "cm-draftly-line-code" }),
|
|
55
|
-
hr: Decoration.line({ class: "cm-draftly-line-hr" })
|
|
56
|
-
};
|
|
57
57
|
var DraftlyPluginsFacet = Facet.define({
|
|
58
58
|
combine: (values) => values.flat()
|
|
59
59
|
});
|
|
@@ -66,67 +66,6 @@ var draftlyThemeFacet = Facet.define({
|
|
|
66
66
|
function buildDecorations(view, plugins = []) {
|
|
67
67
|
const builder = new RangeSetBuilder();
|
|
68
68
|
const decorations = [];
|
|
69
|
-
const tree = syntaxTree(view.state);
|
|
70
|
-
tree.iterate({
|
|
71
|
-
enter: (node) => {
|
|
72
|
-
const { from, to, name } = node;
|
|
73
|
-
const cursorInNode = selectionOverlapsRange(view, from, to);
|
|
74
|
-
if (name === "InlineCode") {
|
|
75
|
-
decorations.push(markDecorations["inline-code"].range(from, to));
|
|
76
|
-
if (!cursorInNode) {
|
|
77
|
-
const marks = node.node.getChildren("CodeMark");
|
|
78
|
-
for (const mark of marks) {
|
|
79
|
-
decorations.push(markDecorations["code-mark"].range(mark.from, mark.to));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (name === "Link") {
|
|
84
|
-
decorations.push(markDecorations.link.range(from, to));
|
|
85
|
-
const url = node.node.getChild("URL");
|
|
86
|
-
if (url) {
|
|
87
|
-
decorations.push(markDecorations.url.range(url.from, url.to));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (name === "Image") {
|
|
91
|
-
decorations.push(markDecorations.image.range(from, to));
|
|
92
|
-
}
|
|
93
|
-
if (name === "FencedCode") {
|
|
94
|
-
decorations.push(markDecorations["fenced-code"].range(from, to));
|
|
95
|
-
const startLine = view.state.doc.lineAt(from);
|
|
96
|
-
const endLine = view.state.doc.lineAt(to);
|
|
97
|
-
for (let i = startLine.number; i <= endLine.number; i++) {
|
|
98
|
-
const line = view.state.doc.line(i);
|
|
99
|
-
decorations.push(lineDecorations["code-block"].range(line.from));
|
|
100
|
-
}
|
|
101
|
-
const codeInfo = node.node.getChild("CodeInfo");
|
|
102
|
-
if (codeInfo) {
|
|
103
|
-
decorations.push(markDecorations["code-info"].range(codeInfo.from, codeInfo.to));
|
|
104
|
-
}
|
|
105
|
-
const codeMarks = node.node.getChildren("CodeMark");
|
|
106
|
-
for (const mark of codeMarks) {
|
|
107
|
-
decorations.push(markDecorations["code-mark"].range(mark.from, mark.to));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (name === "Blockquote") {
|
|
111
|
-
decorations.push(markDecorations.blockquote.range(from, to));
|
|
112
|
-
const startLine = view.state.doc.lineAt(from);
|
|
113
|
-
const endLine = view.state.doc.lineAt(to);
|
|
114
|
-
for (let i = startLine.number; i <= endLine.number; i++) {
|
|
115
|
-
const line = view.state.doc.line(i);
|
|
116
|
-
decorations.push(lineDecorations.blockquote.range(line.from));
|
|
117
|
-
}
|
|
118
|
-
const quoteMarks = node.node.getChildren("QuoteMark");
|
|
119
|
-
for (const mark of quoteMarks) {
|
|
120
|
-
decorations.push(markDecorations["quote-mark"].range(mark.from, mark.to));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (name === "HorizontalRule") {
|
|
124
|
-
const line = view.state.doc.lineAt(from);
|
|
125
|
-
decorations.push(lineDecorations.hr.range(line.from));
|
|
126
|
-
decorations.push(markDecorations.hr.range(from, to));
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
69
|
if (plugins.length > 0) {
|
|
131
70
|
const ctx = {
|
|
132
71
|
view,
|
|
@@ -136,7 +75,10 @@ function buildDecorations(view, plugins = []) {
|
|
|
136
75
|
};
|
|
137
76
|
const sortedPlugins = [...plugins].sort((a, b) => a.decorationPriority - b.decorationPriority);
|
|
138
77
|
for (const plugin of sortedPlugins) {
|
|
139
|
-
|
|
78
|
+
try {
|
|
79
|
+
plugin.buildDecorations(ctx);
|
|
80
|
+
} catch {
|
|
81
|
+
}
|
|
140
82
|
}
|
|
141
83
|
}
|
|
142
84
|
decorations.sort((a, b) => a.from - b.from || a.value.startSide - b.value.startSide);
|
|
@@ -218,7 +160,6 @@ function createDraftlyViewExtension(theme = "auto" /* AUTO */, baseStyles = true
|
|
|
218
160
|
function draftly(config = {}) {
|
|
219
161
|
const {
|
|
220
162
|
theme: configTheme = "auto" /* AUTO */,
|
|
221
|
-
themeStyle: configThemeStyle = void 0,
|
|
222
163
|
baseStyles = true,
|
|
223
164
|
plugins = [],
|
|
224
165
|
extensions = [],
|
|
@@ -272,25 +213,25 @@ function draftly(config = {}) {
|
|
|
272
213
|
...configHighlightActiveLine && disableViewPlugin ? [highlightActiveLine()] : []
|
|
273
214
|
];
|
|
274
215
|
const draftlyExtensions = [];
|
|
275
|
-
if (!disableViewPlugin)
|
|
216
|
+
if (!disableViewPlugin) {
|
|
276
217
|
draftlyExtensions.push(createDraftlyViewExtension(configTheme, baseStyles, allPlugins, configOnNodesChange));
|
|
218
|
+
draftlyExtensions.push(Prec.highest(markdownResetExtension));
|
|
219
|
+
}
|
|
277
220
|
if (!disableViewPlugin || configLineWrapping) draftlyExtensions.push(EditorView.lineWrapping);
|
|
278
221
|
const composedExtensions = [
|
|
279
222
|
// Core markdown support (highest priority)
|
|
280
223
|
Prec.high(markdownSupport),
|
|
281
224
|
Prec.high(keymap.of(markdownKeymap)),
|
|
282
|
-
// Theme styles
|
|
283
|
-
...configThemeStyle ? [Prec.high(configThemeStyle)] : [],
|
|
284
|
-
// Core CodeMirror extensions
|
|
285
|
-
...baseExtensions,
|
|
286
225
|
// draftly view plugin for rich rendering
|
|
287
|
-
|
|
226
|
+
draftlyExtensions,
|
|
227
|
+
// Core CodeMirror extensions
|
|
228
|
+
baseExtensions,
|
|
288
229
|
// Plugin extensions & keymaps
|
|
289
|
-
|
|
230
|
+
pluginExtensions,
|
|
290
231
|
pluginKeymaps.length > 0 ? keymap.of(pluginKeymaps) : [],
|
|
291
232
|
// Config keymaps & extensions
|
|
292
233
|
configKeymap.length > 0 ? keymap.of(configKeymap) : [],
|
|
293
|
-
|
|
234
|
+
extensions
|
|
294
235
|
];
|
|
295
236
|
return composedExtensions;
|
|
296
237
|
}
|
|
@@ -299,6 +240,8 @@ var DraftlyPlugin = class {
|
|
|
299
240
|
decorationPriority = 100;
|
|
300
241
|
/** Plugin dependencies - names of required plugins */
|
|
301
242
|
dependencies = [];
|
|
243
|
+
/** Node types this plugin handles for decorations and preview rendering */
|
|
244
|
+
requiredNodes = [];
|
|
302
245
|
/** Private configuration storage */
|
|
303
246
|
_config = {};
|
|
304
247
|
/** Protected context - accessible to subclasses */
|
|
@@ -444,6 +387,6 @@ var DecorationPlugin = class extends DraftlyPlugin {
|
|
|
444
387
|
var SyntaxPlugin = class extends DraftlyPlugin {
|
|
445
388
|
};
|
|
446
389
|
|
|
447
|
-
export { DecorationPlugin, DraftlyPlugin, SyntaxPlugin, draftly, draftlyBaseTheme };
|
|
448
|
-
//# sourceMappingURL=chunk-
|
|
449
|
-
//# sourceMappingURL=chunk-
|
|
390
|
+
export { DecorationPlugin, DraftlyPlugin, SyntaxPlugin, draftly, draftlyBaseTheme, markdownResetExtension };
|
|
391
|
+
//# sourceMappingURL=chunk-CG4M4TC7.js.map
|
|
392
|
+
//# sourceMappingURL=chunk-CG4M4TC7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/editor/theme.ts","../src/editor/view-plugin.ts","../src/editor/draftly.ts","../src/editor/plugin.ts"],"names":["t","EditorView"],"mappings":";;;;;;;;;;AAMO,IAAM,gBAAA,GAAmB,WAAW,KAAA,CAAM;AAAA;AAAA,EAE/C,cAAA,EAAgB;AAAA,IACd,QAAA,EAAU,MAAA;AAAA,IACV,UAAA,EAAY;AAAA,GACd;AAAA,EAEA,0BAAA,EAA4B;AAAA,IAC1B,KAAA,EAAO,MAAA;AAAA,IACP,QAAA,EAAU,OAAA;AAAA,IACV,OAAA,EAAS,UAAA;AAAA,IACT,MAAA,EAAQ,QAAA;AAAA,IACR,UAAA,EAAY,8BAAA;AAAA,IACZ,QAAA,EAAU,MAAA;A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A;AAAA;AAAA;AAAA,EAMU,YAAY,IAAA,EAAkB;AACtC,IAAA,OAAO,KAAK,KAAA,CAAM,GAAA;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA4BA,gBAAA,CAAiB,OAAkB,YAAA,EAA8B;AAC/D,IAAA,MAAM,WAAA,GAAc,IAAA,CAAK,KAAA,CAAM,KAAK,CAAA;AACpC,IAAA,OAAO,IAAA,CAAK,cAAA,CAAe,WAAA,EAAa,YAAY,CAAA;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMU,cAAA,CAAe,aAAyB,YAAA,EAA8B;AAC9E,IAAA,MAAM,QAAA,GAAW,IAAI,WAAA,CAAY,WAAA,EAAa;AAAA,MAC5C,MAAA,EAAQ,CAAC,GAAA,KAAQ;AACf,QAAA,OAAO,CAAA,CAAA,EAAI,YAAY,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA;AAAA,MAChC;AAAA,KACD,CAAA;AACD,IAAA,OAAO,SAAS,QAAA,EAAS;AAAA,EAC3B;AACF;AAMO,IAAe,gBAAA,GAAf,cAAwC,aAAA,CAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAKlD,kBAAA,GAAqB,EAAA;AAOhC;AAMO,IAAe,YAAA,GAAf,cAAoC,aAAA,CAAc;AAKzD","file":"chunk-CG4M4TC7.js","sourcesContent":["import { EditorView } from \"@codemirror/view\";\n\n/**\n * Base theme for draftly styling\n * Note: Layout styles are scoped under .cm-draftly which is added by the view plugin\n */\nexport const draftlyBaseTheme = EditorView.theme({\n // Container styles - only apply when view plugin is enabled\n \"&.cm-draftly\": {\n fontSize: \"16px\",\n lineHeight: \"1.6\",\n },\n\n \"&.cm-draftly .cm-content\": {\n width: \"100%\",\n maxWidth: \"48rem\",\n padding: \"0 0.5rem\",\n margin: \"0 auto\",\n fontFamily: \"var(--font-sans, sans-serif)\",\n fontSize: \"16px\",\n lineHeight: \"1.6\",\n },\n\n \"&.cm-draftly .cm-content .cm-line\": {\n paddingInline: 0,\n },\n\n \"&.cm-draftly .cm-content .cm-widgetBuffer\": {\n display: \"none !important\",\n },\n});\n\nimport { HighlightStyle, syntaxHighlighting } from \"@codemirror/language\";\nimport { tags as t } from \"@lezer/highlight\";\n\n/**\n * Reset syntax highlighting for markdown elements\n * Used to disable theme colors for markdown syntax\n */\nconst markdownResetStyle = HighlightStyle.define([\n {\n tag: [\n t.heading,\n t.strong,\n t.emphasis,\n t.strikethrough,\n t.link,\n t.url,\n t.quote,\n t.list,\n t.meta,\n t.contentSeparator,\n t.labelName,\n ],\n color: \"inherit\",\n fontWeight: \"inherit\",\n fontStyle: \"inherit\",\n textDecoration: \"none\",\n },\n]);\n\nexport const markdownResetExtension = syntaxHighlighting(markdownResetStyle, { fallback: false });\n","import { Decoration, DecorationSet, EditorView, ViewPlugin, ViewUpdate } from \"@codemirror/view\";\nimport { Extension, Facet, Range, RangeSetBuilder } from \"@codemirror/state\";\nimport { syntaxTree } from \"@codemirror/language\";\nimport { cursorInRange, selectionOverlapsRange, ThemeEnum } from \"./utils\";\nimport { draftlyBaseTheme } from \"./theme\";\nimport { DecorationContext, DraftlyPlugin } from \"./plugin\";\nimport { DraftlyNode } from \"./draftly\";\n\n/**\n * Facet to register plugins with the view plugin\n */\nexport const DraftlyPluginsFacet = Facet.define<DraftlyPlugin[], DraftlyPlugin[]>({\n combine: (values) => values.flat(),\n});\n\n/**\n * Facet to register the onNodesChange callback\n */\nexport const draftlyOnNodesChangeFacet = Facet.define<\n ((nodes: DraftlyNode[]) => void) | undefined,\n ((nodes: DraftlyNode[]) => void) | undefined\n>({\n combine: (values) => values.find((v) => v !== undefined),\n});\n\n/**\n * Facet to register the theme\n */\nexport const draftlyThemeFacet = Facet.define<ThemeEnum, ThemeEnum>({\n combine: (values) => values.find((v) => v !== undefined) || ThemeEnum.AUTO,\n});\n\n/**\n * Build decorations for the visible viewport\n * @param view - The EditorView instance\n * @param plugins - Optional array of plugins to invoke for decorations\n */\nfunction buildDecorations(view: EditorView, plugins: DraftlyPlugin[] = []): DecorationSet {\n const builder = new RangeSetBuilder<Decoration>();\n const decorations: Range<Decoration>[] = [];\n\n // Allow plugins to contribute decorations\n if (plugins.length > 0) {\n const ctx: DecorationContext = {\n view,\n decorations,\n selectionOverlapsRange: (from, to) => selectionOverlapsRange(view, from, to),\n cursorInRange: (from, to) => cursorInRange(view, from, to),\n };\n\n // Sort plugins by priority and invoke each one's decoration builder\n const sortedPlugins = [...plugins].sort((a, b) => a.decorationPriority - b.decorationPriority);\n\n for (const plugin of sortedPlugins) {\n try {\n plugin.buildDecorations(ctx);\n } catch {\n // Silently ignore errors from partial tree states (e.g., Lezer TreeBuffer\n // \"Invalid child in posBefore\"). These resolve on the next update cycle.\n }\n }\n }\n\n // Sort decorations by position (required for RangeSetBuilder)\n decorations.sort((a, b) => a.from - b.from || a.value.startSide - b.value.startSide);\n\n // Build the decoration set\n for (const decoration of decorations) {\n builder.add(decoration.from, decoration.to, decoration.value);\n }\n\n return builder.finish();\n}\n\n/**\n * draftly View Plugin\n * Handles rich markdown rendering with decorations\n */\nclass draftlyViewPluginClass {\n decorations: DecorationSet;\n private plugins: DraftlyPlugin[];\n private onNodesChange: ((nodes: DraftlyNode[]) => void) | undefined;\n\n constructor(view: EditorView) {\n this.plugins = view.state.facet(DraftlyPluginsFacet);\n this.onNodesChange = view.state.facet(draftlyOnNodesChangeFacet);\n this.decorations = buildDecorations(view, this.plugins);\n\n // Notify plugins that view is ready\n for (const plugin of this.plugins) {\n plugin.onViewReady(view);\n }\n\n // Call onNodesChange callback with initial nodes\n if (this.onNodesChange && typeof this.onNodesChange === \"function\") {\n this.onNodesChange(this.buildNodes(view));\n }\n }\n\n update(update: ViewUpdate) {\n // Update plugins list if facet changed\n this.plugins = update.view.state.facet(DraftlyPluginsFacet);\n this.onNodesChange = update.view.state.facet(draftlyOnNodesChangeFacet);\n\n // Notify plugins of the update\n for (const plugin of this.plugins) {\n plugin.onViewUpdate(update);\n }\n\n // Rebuild decorations when:\n // - Document changes\n // - Selection changes (to show/hide syntax markers)\n // - Viewport changes\n if (update.docChanged || update.selectionSet || update.viewportChanged) {\n this.decorations = buildDecorations(update.view, this.plugins);\n\n // Call onNodesChange callback\n if (this.onNodesChange) {\n this.onNodesChange(this.buildNodes(update.view));\n }\n }\n }\n\n private buildNodes(view: EditorView): DraftlyNode[] {\n const tree = syntaxTree(view.state);\n const roots: DraftlyNode[] = [];\n const stack: DraftlyNode[] = [];\n\n tree.iterate({\n enter: (nodeRef) => {\n const node: DraftlyNode = {\n from: nodeRef.from,\n to: nodeRef.to,\n name: nodeRef.name,\n children: [],\n isSelected: selectionOverlapsRange(view, nodeRef.from, nodeRef.to),\n };\n\n if (stack.length > 0) {\n stack[stack.length - 1]!.children.push(node);\n } else {\n roots.push(node);\n }\n\n stack.push(node);\n },\n leave: () => {\n stack.pop();\n },\n });\n\n return roots;\n }\n}\n\n/**\n * The main draftly ViewPlugin extension\n */\nexport const draftlyViewPlugin = ViewPlugin.fromClass(draftlyViewPluginClass, {\n decorations: (v) => v.decorations,\n provide: () => [],\n});\n\n/**\n * Extension to add the cm-draftly-enabled class to the editor\n */\nconst draftlyEditorClass = EditorView.editorAttributes.of({ class: \"cm-draftly\" });\n\n/**\n * Create draftly view extension bundle with plugin support\n * @param plugins - Optional array of DraftlyPlugin instances\n * @param onNodesChange - Optional callback to receive nodes on every update\n * @returns Extension array including view plugin, theme, and plugin facet\n */\nexport function createDraftlyViewExtension(\n theme: ThemeEnum = ThemeEnum.AUTO,\n baseStyles: boolean = true,\n plugins: DraftlyPlugin[] = [],\n onNodesChange?: (nodes: DraftlyNode[]) => void\n): Extension[] {\n return [\n draftlyEditorClass,\n DraftlyPluginsFacet.of(plugins),\n draftlyOnNodesChangeFacet.of(onNodesChange),\n draftlyThemeFacet.of(theme),\n draftlyViewPlugin,\n ...(baseStyles ? [draftlyBaseTheme] : []),\n ];\n}\n","import { Extension, Prec } from \"@codemirror/state\";\nimport { EditorView, highlightActiveLine, KeyBinding, keymap } from \"@codemirror/view\";\nimport { markdown, markdownKeymap, markdownLanguage } from \"@codemirror/lang-markdown\";\nimport type { MarkdownConfig } from \"@lezer/markdown\";\nimport { DraftlyPlugin, PluginContext } from \"./plugin\";\nimport { createDraftlyViewExtension } from \"./view-plugin\";\nimport { defaultKeymap, history, historyKeymap, indentWithTab } from \"@codemirror/commands\";\nimport { indentOnInput } from \"@codemirror/language\";\nimport { languages } from \"@codemirror/language-data\";\nimport { ThemeEnum } from \"./utils\";\nimport { markdownResetExtension } from \"./theme\";\n\n/**\n * DraftlyNode: represents a node in the markdown tree\n *\n * Useful for debugging and development\n */\nexport type DraftlyNode = {\n from: number;\n to: number;\n name: string;\n children: DraftlyNode[];\n isSelected: boolean;\n};\n\n/**\n * Configuration options for the draftly editor\n */\nexport interface DraftlyConfig {\n /** Theme */\n theme?: ThemeEnum;\n\n /** Weather to load base styles */\n baseStyles?: boolean;\n\n /** Plugins to load */\n plugins?: DraftlyPlugin[];\n\n /** Additional markdown extensions for the parser */\n markdown?: MarkdownConfig[];\n\n /** Additional CodeMirror extensions */\n extensions?: Extension[];\n\n /** Additional keybindings */\n keymap?: KeyBinding[];\n\n /** Disable the built-in view plugin (for raw markdown mode) */\n disableViewPlugin?: boolean;\n\n /** Enable default keybindings */\n defaultKeybindings?: boolean;\n\n /** Enable history */\n history?: boolean;\n\n /** Enable indent with tab */\n indentWithTab?: boolean;\n\n /** Highlight active line */\n highlightActiveLine?: boolean;\n\n /** Line wrapping in raw markdown mode */\n lineWrapping?: boolean;\n\n /** Callback to receive the nodes on every update */\n onNodesChange?: (nodes: DraftlyNode[]) => void;\n}\n\n/**\n * Creates a draftly editor extension bundle for CodeMirror 6\n *\n * @param config - Configuration options for the editor\n * @returns CodeMirror Extension that can be added to EditorState\n *\n * @example\n * ```ts\n * import { EditorView } from '@codemirror/view';\n * import { EditorState } from '@codemirror/state';\n * import { draftly } from 'draftly';\n *\n * const view = new EditorView({\n * state: EditorState.create({\n * doc: '# Hello draftly',\n * extensions: [draftly()]\n * }),\n * parent: document.getElementById('editor')\n * });\n * ```\n */\nexport function draftly(config: DraftlyConfig = {}): Extension[] {\n const {\n theme: configTheme = ThemeEnum.AUTO,\n baseStyles = true,\n plugins = [],\n extensions = [],\n keymap: configKeymap = [],\n disableViewPlugin = false,\n defaultKeybindings = true,\n history: configHistory = true,\n indentWithTab: configIndentWithTab = true,\n highlightActiveLine: configHighlightActiveLine = true,\n lineWrapping: configLineWrapping = true,\n onNodesChange: configOnNodesChange = undefined,\n } = config;\n\n const allPlugins = [...plugins];\n\n // Collect all extensions from plugins\n const pluginExtensions: Extension[] = [];\n const pluginKeymaps: KeyBinding[] = [];\n const markdownExtensions: MarkdownConfig[] = [];\n\n // Create plugin context for lifecycle methods\n const pluginContext: PluginContext = { config };\n\n // Process each plugin\n for (const plugin of allPlugins) {\n // Call onRegister lifecycle hook\n plugin.onRegister(pluginContext);\n\n // Collect extensions via class method\n const exts = plugin.getExtensions();\n if (exts.length > 0) {\n pluginExtensions.push(...exts);\n }\n\n // Collect keymaps via class method\n const keys = plugin.getKeymap();\n if (keys.length > 0) {\n pluginKeymaps.push(...keys);\n }\n\n // Collect theme via class method\n const theme = plugin.theme;\n if (baseStyles && theme && typeof theme === \"function\") {\n pluginExtensions.push(EditorView.theme(theme(configTheme)));\n }\n\n // Collect markdown parser extensions via class method\n const md = plugin.getMarkdownConfig();\n if (md) {\n markdownExtensions.push(md);\n }\n }\n\n // Add config-level markdown extensions\n if (config.markdown) {\n markdownExtensions.push(...config.markdown);\n }\n\n // Build the base markdown language support\n const markdownSupport = markdown({\n base: markdownLanguage,\n codeLanguages: languages,\n extensions: markdownExtensions,\n addKeymap: true,\n completeHTMLTags: true,\n });\n\n // Core CodeMirror extensions (in order)\n const baseExtensions: Extension[] = [\n ...(defaultKeybindings ? [keymap.of(defaultKeymap)] : []),\n ...(configHistory ? [history(), keymap.of(historyKeymap)] : []),\n ...(configIndentWithTab ? [indentOnInput(), keymap.of([indentWithTab])] : []),\n ...(configHighlightActiveLine && disableViewPlugin ? [highlightActiveLine()] : []),\n ];\n\n // draftly extensions (pass plugins for decoration support)\n const draftlyExtensions: Extension[] = [];\n if (!disableViewPlugin) {\n draftlyExtensions.push(createDraftlyViewExtension(configTheme, baseStyles, allPlugins, configOnNodesChange));\n draftlyExtensions.push(Prec.highest(markdownResetExtension));\n }\n if (!disableViewPlugin || configLineWrapping) draftlyExtensions.push(EditorView.lineWrapping);\n\n // Compose all extensions together\n const composedExtensions: Extension[] = [\n // Core markdown support (highest priority)\n Prec.high(markdownSupport),\n Prec.high(keymap.of(markdownKeymap)),\n\n // draftly view plugin for rich rendering\n draftlyExtensions,\n\n // Core CodeMirror extensions\n baseExtensions,\n\n // Plugin extensions & keymaps\n pluginExtensions,\n pluginKeymaps.length > 0 ? keymap.of(pluginKeymaps) : [],\n\n // Config keymaps & extensions\n configKeymap.length > 0 ? keymap.of(configKeymap) : [],\n extensions,\n ];\n\n return composedExtensions;\n}\n","import { Decoration, EditorView, KeyBinding, ViewUpdate } from \"@codemirror/view\";\nimport { Extension, Range } from \"@codemirror/state\";\nimport { MarkdownConfig } from \"@lezer/markdown\";\nimport { SyntaxNode } from \"@lezer/common\";\nimport { DraftlyConfig } from \"./draftly\";\nimport { createTheme, ThemeEnum, ThemeStyle } from \"./utils\";\nimport { StyleModule } from \"style-mod\";\n\n/**\n * Context passed to plugin lifecycle methods\n */\nexport interface PluginContext {\n /** Current configuration */\n readonly config: DraftlyConfig;\n}\n\n/**\n * Plugin configuration schema\n */\nexport interface PluginConfig {\n [key: string]: unknown;\n}\n\n/**\n * Decoration context passed to plugin decoration builders\n * Provides access to view state and decoration collection\n */\nexport interface DecorationContext {\n /** The EditorView instance (readonly) */\n readonly view: EditorView;\n\n /** Array to push decorations into (will be sorted automatically) */\n readonly decorations: Range<Decoration>[];\n\n /** Check if selection overlaps with a range (to show raw markdown) */\n selectionOverlapsRange(from: number, to: number): boolean;\n\n /** Check if cursor is within a range */\n cursorInRange(from: number, to: number): boolean;\n}\n\n/**\n * Abstract base class for all draftly plugins\n *\n * Implements OOP principles:\n * - Abstraction: abstract name/version must be implemented by subclasses\n * - Encapsulation: private _config, protected _context\n * - Inheritance: specialized plugin classes can extend this\n */\nexport abstract class DraftlyPlugin {\n /** Unique plugin identifier (abstract - must be implemented) */\n abstract readonly name: string;\n\n /** Plugin version (abstract - must be implemented) */\n abstract readonly version: string;\n\n /** Decoration priority (higher = applied later) */\n readonly decorationPriority: number = 100;\n\n /** Plugin dependencies - names of required plugins */\n readonly dependencies: string[] = [];\n\n /** Node types this plugin handles for decorations and preview rendering */\n readonly requiredNodes: readonly string[] = [];\n\n /** Private configuration storage */\n private _config: PluginConfig = {};\n\n /** Protected context - accessible to subclasses */\n protected _context: PluginContext | null = null;\n\n /** Get plugin configuration */\n get config(): PluginConfig {\n return this._config;\n }\n\n /** Set plugin configuration */\n set config(value: PluginConfig) {\n this._config = value;\n }\n\n /** Get plugin context */\n get context(): PluginContext | null {\n return this._context;\n }\n\n /** Plugin theme */\n get theme(): (theme: ThemeEnum) => ThemeStyle {\n return createTheme({\n default: {},\n dark: {},\n light: {},\n });\n }\n\n // ============================================\n // EXTENSION METHODS (overridable by subclasses)\n // ============================================\n\n /**\n * Return CodeMirror extensions for this plugin\n * Override to provide custom extensions\n */\n getExtensions(): Extension[] {\n return [];\n }\n\n /**\n * Return markdown parser extensions\n * Override to extend markdown parsing\n */\n getMarkdownConfig(): MarkdownConfig | null {\n return null;\n }\n\n /**\n * Return keybindings for this plugin\n * Override to add custom keyboard shortcuts\n */\n getKeymap(): KeyBinding[] {\n return [];\n }\n\n // ============================================\n // DECORATION METHODS (overridable by subclasses)\n // ============================================\n\n /**\n * Build decorations for the current view state\n * Override to contribute decorations to the editor\n *\n * @param ctx - Decoration context with view and decoration array\n */\n buildDecorations(_ctx: DecorationContext): void {\n // Default implementation does nothing\n // Subclasses override to add decorations\n }\n\n // ============================================\n // LIFECYCLE HOOKS (overridable by subclasses)\n // ============================================\n\n /**\n * Called when plugin is registered with draftly\n * Override to perform initialization\n *\n * @param context - Plugin context with configuration\n */\n onRegister(context: PluginContext): void | Promise<void> {\n this._context = context;\n }\n\n /**\n * Called when plugin is unregistered\n * Override to perform cleanup\n */\n onUnregister(): void {\n this._context = null;\n }\n\n /**\n * Called when EditorView is created and ready\n * Override to perform view-specific initialization\n *\n * @param view - The EditorView instance\n */\n onViewReady(_view: EditorView): void {\n // Default implementation does nothing\n }\n\n /**\n * Called on view updates (document changes, selection changes, etc.)\n * Override to react to editor changes\n *\n * @param update - The ViewUpdate with change information\n */\n onViewUpdate(_update: ViewUpdate): void {\n // Default implementation does nothing\n }\n\n // ============================================\n // PROTECTED UTILITIES (for subclasses)\n // ============================================\n\n /**\n * Helper to get current editor state\n * @param view - The EditorView instance\n */\n protected getState(view: EditorView) {\n return view.state;\n }\n\n /**\n * Helper to get current document\n * @param view - The EditorView instance\n */\n protected getDocument(view: EditorView) {\n return view.state.doc;\n }\n\n // ============================================\n // PREVIEW RENDERING METHODS (for draftly/preview)\n // ============================================\n\n /**\n * Render a syntax node to HTML for preview mode\n * Override to provide custom HTML rendering for specific node types\n *\n * @param node - The syntax node to render\n * @param children - Pre-rendered children HTML\n * @param ctx - Preview context with document and utilities\n * @returns HTML string to use, or null to use default rendering\n */\n renderToHTML?(\n node: SyntaxNode,\n children: string,\n ctx: { sliceDoc(from: number, to: number): string; sanitize(html: string): string }\n ): string | null | Promise<string | null>;\n\n /**\n * Get CSS styles for preview mode\n * Override to provide custom CSS for preview rendering\n *\n * @param theme - Current theme enum\n * @returns CSS string for preview styles\n */\n getPreviewStyles(theme: ThemeEnum, wrapperClass: string): string {\n const themeStyles = this.theme(theme);\n return this.transformToCss(themeStyles, wrapperClass);\n }\n\n /**\n * Transform ThemeStyle object to CSS string for preview\n * Uses cssClassMap to convert CM selectors to semantic selectors\n */\n protected transformToCss(themeStyles: ThemeStyle, wrapperClass: string): string {\n const styleMod = new StyleModule(themeStyles, {\n finish: (sel) => {\n return `.${wrapperClass} ${sel}`;\n },\n });\n return styleMod.getRules();\n }\n}\n\n/**\n * Base class for plugins that primarily contribute decorations\n * Extends DraftlyPlugin with decoration-focused defaults\n */\nexport abstract class DecorationPlugin extends DraftlyPlugin {\n /**\n * Decoration priority - lower than default for decoration plugins\n * Override to customize\n */\n override decorationPriority = 50;\n\n /**\n * Subclasses must implement this to provide decorations\n * @param ctx - Decoration context\n */\n abstract override buildDecorations(ctx: DecorationContext): void;\n}\n\n/**\n * Base class for plugins that add syntax/parser extensions\n * Extends DraftlyPlugin with syntax-focused requirements\n */\nexport abstract class SyntaxPlugin extends DraftlyPlugin {\n /**\n * Subclasses must implement this to provide markdown config\n */\n abstract override getMarkdownConfig(): MarkdownConfig;\n}\n"]}
|