draftly 2.0.0 → 2.1.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/dist/{chunk-BWJLMREN.cjs → chunk-EQUQHE2E.cjs} +26 -24
- package/dist/chunk-EQUQHE2E.cjs.map +1 -0
- package/dist/{chunk-L2XSK57Y.js → chunk-NRPI5O6Y.js} +1267 -551
- package/dist/chunk-NRPI5O6Y.js.map +1 -0
- package/dist/{chunk-W5ALMXG2.cjs → chunk-OMFUE4AQ.cjs} +1304 -588
- package/dist/chunk-OMFUE4AQ.cjs.map +1 -0
- package/dist/{chunk-EEHILRG5.js → chunk-TD3L5C45.js} +13 -11
- package/dist/chunk-TD3L5C45.js.map +1 -0
- package/dist/{chunk-ZUI3GI3W.js → chunk-UCHBDJ4R.js} +22 -20
- package/dist/chunk-UCHBDJ4R.js.map +1 -0
- package/dist/{chunk-TBVZEK2H.cjs → chunk-W75QUUQC.cjs} +13 -11
- package/dist/chunk-W75QUUQC.cjs.map +1 -0
- package/dist/editor/index.cjs +16 -16
- package/dist/editor/index.js +2 -2
- package/dist/index.cjs +33 -33
- package/dist/index.js +3 -3
- package/dist/plugins/index.cjs +19 -19
- package/dist/plugins/index.d.cts +77 -42
- package/dist/plugins/index.d.ts +77 -42
- package/dist/plugins/index.js +3 -3
- package/dist/preview/index.cjs +1 -1
- package/dist/preview/index.js +1 -1
- package/package.json +1 -1
- package/src/editor/draftly.ts +29 -27
- package/src/editor/utils.ts +13 -11
- package/src/plugins/table-plugin.ts +1759 -900
- package/dist/chunk-BWJLMREN.cjs.map +0 -1
- package/dist/chunk-EEHILRG5.js.map +0 -1
- package/dist/chunk-L2XSK57Y.js.map +0 -1
- package/dist/chunk-TBVZEK2H.cjs.map +0 -1
- package/dist/chunk-W5ALMXG2.cjs.map +0 -1
- package/dist/chunk-ZUI3GI3W.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkW75QUUQC_cjs = require('./chunk-W75QUUQC.cjs');
|
|
4
4
|
var state = require('@codemirror/state');
|
|
5
5
|
var view = require('@codemirror/view');
|
|
6
6
|
var langMarkdown = require('@codemirror/lang-markdown');
|
|
@@ -73,8 +73,8 @@ function buildDecorations(view, plugins = []) {
|
|
|
73
73
|
const ctx = {
|
|
74
74
|
view,
|
|
75
75
|
decorations,
|
|
76
|
-
selectionOverlapsRange: (from, to) =>
|
|
77
|
-
cursorInRange: (from, to) =>
|
|
76
|
+
selectionOverlapsRange: (from, to) => chunkW75QUUQC_cjs.selectionOverlapsRange(view, from, to),
|
|
77
|
+
cursorInRange: (from, to) => chunkW75QUUQC_cjs.cursorInRange(view, from, to)
|
|
78
78
|
};
|
|
79
79
|
const sortedPlugins = [...plugins].sort((a, b) => a.decorationPriority - b.decorationPriority);
|
|
80
80
|
for (const plugin of sortedPlugins) {
|
|
@@ -129,7 +129,7 @@ var draftlyViewPluginClass = class {
|
|
|
129
129
|
to: nodeRef.to,
|
|
130
130
|
name: nodeRef.name,
|
|
131
131
|
children: [],
|
|
132
|
-
isSelected:
|
|
132
|
+
isSelected: chunkW75QUUQC_cjs.selectionOverlapsRange(view, nodeRef.from, nodeRef.to)
|
|
133
133
|
};
|
|
134
134
|
if (stack.length > 0) {
|
|
135
135
|
stack[stack.length - 1].children.push(node);
|
|
@@ -180,23 +180,25 @@ function draftly(config = {}) {
|
|
|
180
180
|
const pluginKeymaps = [];
|
|
181
181
|
const markdownExtensions = [];
|
|
182
182
|
const pluginContext = { config };
|
|
183
|
-
|
|
184
|
-
plugin
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
183
|
+
if (!disableViewPlugin) {
|
|
184
|
+
for (const plugin of allPlugins) {
|
|
185
|
+
plugin.onRegister(pluginContext);
|
|
186
|
+
const exts = plugin.getExtensions();
|
|
187
|
+
if (exts.length > 0) {
|
|
188
|
+
pluginExtensions.push(...exts);
|
|
189
|
+
}
|
|
190
|
+
const keys = plugin.getKeymap();
|
|
191
|
+
if (keys.length > 0) {
|
|
192
|
+
pluginKeymaps.push(...keys);
|
|
193
|
+
}
|
|
194
|
+
const theme = plugin.theme;
|
|
195
|
+
if (baseStyles && theme && typeof theme === "function") {
|
|
196
|
+
pluginExtensions.push(view.EditorView.theme(theme(configTheme)));
|
|
197
|
+
}
|
|
198
|
+
const md = plugin.getMarkdownConfig();
|
|
199
|
+
if (md) {
|
|
200
|
+
markdownExtensions.push(md);
|
|
201
|
+
}
|
|
200
202
|
}
|
|
201
203
|
}
|
|
202
204
|
if (config.markdown) {
|
|
@@ -264,7 +266,7 @@ var DraftlyPlugin = class {
|
|
|
264
266
|
}
|
|
265
267
|
/** Plugin theme */
|
|
266
268
|
get theme() {
|
|
267
|
-
return
|
|
269
|
+
return chunkW75QUUQC_cjs.createTheme({
|
|
268
270
|
default: {},
|
|
269
271
|
dark: {},
|
|
270
272
|
light: {}
|
|
@@ -397,5 +399,5 @@ exports.SyntaxPlugin = SyntaxPlugin;
|
|
|
397
399
|
exports.draftly = draftly;
|
|
398
400
|
exports.draftlyBaseTheme = draftlyBaseTheme;
|
|
399
401
|
exports.markdownResetExtension = markdownResetExtension;
|
|
400
|
-
//# sourceMappingURL=chunk-
|
|
401
|
-
//# sourceMappingURL=chunk-
|
|
402
|
+
//# sourceMappingURL=chunk-EQUQHE2E.cjs.map
|
|
403
|
+
//# sourceMappingURL=chunk-EQUQHE2E.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,KAAA;AAAA,IACZ,eAAA,EAAiB;AAAA,GACnB;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;AAAA,IACZ,SAAA,EAAW,SAAA;AAAA,IACX,cAAA,EAAgB;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,CAAA,EAAI,GAAG,CAAA,CAAA;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-EQUQHE2E.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 backgroundColor: \"transparent !important\",\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 if (!disableViewPlugin) {\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\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 pasteURLAsLink: 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: {\n sliceDoc(from: number, to: number): string;\n sanitize(html: string): string;\n syntaxHighlighters?: readonly import(\"@lezer/highlight\").Highlighter[];\n }\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"]}
|