@krainovsd/markdown-editor 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index-CDtGUxs-.js +52 -0
- package/lib/cjs/index-CDtGUxs-.js.map +1 -0
- package/lib/cjs/{index-JTLnXX8Q.js → index-CiorogHq.js} +979 -372
- package/lib/cjs/index-CiorogHq.js.map +1 -0
- package/lib/cjs/index.js +6 -3
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/extensions/init-extensions.js +6 -2
- package/lib/esm/extensions/init-extensions.js.map +1 -1
- package/lib/esm/extensions/listeners/get-focus-event.js +1 -0
- package/lib/esm/extensions/listeners/get-focus-event.js.map +1 -1
- package/lib/esm/extensions/markdown/blockquote/blockquote-decoration.js +2 -2
- package/lib/esm/extensions/markdown/blockquote/blockquote-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/bold/bold-decoration.js +2 -2
- package/lib/esm/extensions/markdown/bold/bold-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/code/code-decoration.js +2 -2
- package/lib/esm/extensions/markdown/code/code-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/header/header-decoration.js +3 -3
- package/lib/esm/extensions/markdown/header/header-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/horizontal/horizontal-decoration.js +2 -2
- package/lib/esm/extensions/markdown/horizontal/horizontal-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/image/image-decoration.js +33 -26
- package/lib/esm/extensions/markdown/image/image-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/image/image-widget.js +82 -74
- package/lib/esm/extensions/markdown/image/image-widget.js.map +1 -1
- package/lib/esm/extensions/markdown/init-markdown.js +5 -2
- package/lib/esm/extensions/markdown/init-markdown.js.map +1 -1
- package/lib/esm/extensions/markdown/italic/italic-decoration.js +7 -7
- package/lib/esm/extensions/markdown/italic/italic-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/link/auto-link-decoration.js +24 -4
- package/lib/esm/extensions/markdown/link/auto-link-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/link/link-decoration.js +25 -5
- package/lib/esm/extensions/markdown/link/link-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/link/link-label-decoration.js +3 -2
- package/lib/esm/extensions/markdown/link/link-label-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/link/link-widget.js +137 -112
- package/lib/esm/extensions/markdown/link/link-widget.js.map +1 -1
- package/lib/esm/extensions/markdown/list/list-decoration.js +3 -3
- package/lib/esm/extensions/markdown/list/list-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/markdown-decoration.js +89 -44
- package/lib/esm/extensions/markdown/markdown-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/markdown-state.js +29 -0
- package/lib/esm/extensions/markdown/markdown-state.js.map +1 -0
- package/lib/esm/extensions/markdown/mention/mention-decoration.js +2 -2
- package/lib/esm/extensions/markdown/mention/mention-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/strike-through/strike-through-decoration.js +2 -2
- package/lib/esm/extensions/markdown/strike-through/strike-through-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/todo/todo-decoration.js +3 -3
- package/lib/esm/extensions/markdown/todo/todo-decoration.js.map +1 -1
- package/lib/esm/extensions/markdown/todo/todo-widget.js +1 -0
- package/lib/esm/extensions/markdown/todo/todo-widget.js.map +1 -1
- package/lib/esm/extensions/settings/init-settings.js +1 -0
- package/lib/esm/extensions/settings/init-settings.js.map +1 -1
- package/lib/esm/index.js +9 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/lib/utils/get-decoration.js +2 -1
- package/lib/esm/lib/utils/get-decoration.js.map +1 -1
- package/lib/esm/module/Editor/Editor.js +4 -0
- package/lib/esm/module/Editor/Editor.js.map +1 -1
- package/lib/esm/module/Editor/lib/init-editor.js +1 -0
- package/lib/esm/module/Editor/lib/init-editor.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/package.json +1 -1
- package/lib/cjs/index-JTLnXX8Q.js.map +0 -1
- package/lib/cjs/index-v4GhIAcy.js +0 -528
- package/lib/cjs/index-v4GhIAcy.js.map +0 -1
- package/lib/esm/lib/utils/tick.js +0 -22
- package/lib/esm/lib/utils/tick.js.map +0 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { syntaxTree } from '@codemirror/language';
|
|
2
|
+
import '@codemirror/state';
|
|
2
3
|
import { ViewPlugin, Decoration } from '@codemirror/view';
|
|
4
|
+
import { saveDispatch } from '../../lib/utils/save-dispatch.js';
|
|
3
5
|
import { blockquoteDecorationPlugin } from './blockquote/blockquote-decoration.js';
|
|
4
6
|
import { boldDecorationPlugin } from './bold/bold-decoration.js';
|
|
5
7
|
import { codeDecorationPlugin } from './code/code-decoration.js';
|
|
@@ -10,6 +12,7 @@ import { italicDecorationPlugin } from './italic/italic-decoration.js';
|
|
|
10
12
|
import { linkDecorationPlugin } from './link/link-decoration.js';
|
|
11
13
|
import { autoLinkDecorationPlugin } from './link/auto-link-decoration.js';
|
|
12
14
|
import { listDecorationPlugin } from './list/list-decoration.js';
|
|
15
|
+
import { imageSrcGetterEffect } from './markdown-state.js';
|
|
13
16
|
import { mentionDecorationPlugin } from './mention/mention-decoration.js';
|
|
14
17
|
import { strikeThroughDecorationPlugin } from './strike-through/strike-through-decoration.js';
|
|
15
18
|
import { todoDecorationPlugin } from './todo/todo-decoration.js';
|
|
@@ -54,52 +57,94 @@ const SKIP_MARKS = new Set([
|
|
|
54
57
|
"HeaderMark",
|
|
55
58
|
"TaskMarker",
|
|
56
59
|
]);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
60
|
+
function createDecorationsGetter() {
|
|
61
|
+
let markdownDecorationsCache = [];
|
|
62
|
+
let markdownSelectionDecorationsCache = [];
|
|
63
|
+
function getDecorations(view, isChanged, mouseReleased) {
|
|
64
|
+
const processDecorations = isChanged;
|
|
65
|
+
const processSelectionDecorations = isChanged || mouseReleased;
|
|
66
|
+
const decorations = processDecorations ? [] : markdownDecorationsCache;
|
|
67
|
+
const selectionDecorations = processSelectionDecorations
|
|
68
|
+
? []
|
|
69
|
+
: markdownSelectionDecorationsCache;
|
|
70
|
+
const contentEditable = view.contentDOM.getAttribute("contenteditable");
|
|
71
|
+
const isReadonly = !contentEditable || contentEditable === "false";
|
|
72
|
+
for (const { from: fromVisible, to: toVisible } of view.visibleRanges) {
|
|
73
|
+
syntaxTree(view.state).iterate({
|
|
74
|
+
from: fromVisible,
|
|
75
|
+
to: toVisible,
|
|
76
|
+
enter: (node) => {
|
|
77
|
+
if (SKIP_MARKS.has(node.name))
|
|
78
|
+
return;
|
|
79
|
+
/** Decoration by change content */
|
|
80
|
+
if (processDecorations)
|
|
81
|
+
decorationFunctions.forEach((f) => f({ decorations, node, view }));
|
|
82
|
+
/** Decoration by selection content */
|
|
83
|
+
if (processSelectionDecorations)
|
|
84
|
+
selectionDecorationFunctions.forEach((f) => f({
|
|
85
|
+
decorations: selectionDecorations,
|
|
86
|
+
node,
|
|
87
|
+
view,
|
|
88
|
+
forceActive: isReadonly,
|
|
89
|
+
}));
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (processDecorations) {
|
|
94
|
+
markdownDecorationsCache = decorations;
|
|
95
|
+
}
|
|
96
|
+
if (processSelectionDecorations) {
|
|
97
|
+
markdownSelectionDecorationsCache = selectionDecorations;
|
|
98
|
+
}
|
|
99
|
+
return Decoration.set([...decorations, ...selectionDecorations], true);
|
|
86
100
|
}
|
|
87
|
-
return
|
|
101
|
+
return getDecorations;
|
|
88
102
|
}
|
|
89
|
-
const markdownDecorationPlugin =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
const markdownDecorationPlugin = (stateConfig) => {
|
|
104
|
+
return ViewPlugin.fromClass(class DecorationMarkdown {
|
|
105
|
+
decorations;
|
|
106
|
+
mouseReleased = true;
|
|
107
|
+
dom;
|
|
108
|
+
view;
|
|
109
|
+
decorationGetter;
|
|
110
|
+
constructor(view) {
|
|
111
|
+
this.decorationGetter = createDecorationsGetter();
|
|
112
|
+
this.decorations = this.decorationGetter(view, true, this.mouseReleased);
|
|
113
|
+
this.dom = view.dom;
|
|
114
|
+
this.view = view;
|
|
115
|
+
document.addEventListener("mousedown", this.onMouseDown.bind(this));
|
|
116
|
+
document.addEventListener("mouseup", this.onMouseUp.bind(this));
|
|
117
|
+
saveDispatch(() => {
|
|
118
|
+
this.view.dispatch(this.view.state.update({
|
|
119
|
+
effects: [imageSrcGetterEffect.of(stateConfig.imageSrcGetter)],
|
|
120
|
+
}));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
update(update) {
|
|
124
|
+
const isDocumentChanged = update.docChanged ||
|
|
125
|
+
update.viewportChanged ||
|
|
126
|
+
syntaxTree(update.startState) != syntaxTree(update.state);
|
|
127
|
+
this.decorations = this.decorationGetter(update.view, isDocumentChanged, this.mouseReleased);
|
|
128
|
+
}
|
|
129
|
+
destroy() {
|
|
130
|
+
document.removeEventListener("mousedown", this.onMouseDown.bind(this));
|
|
131
|
+
document.removeEventListener("mouseup", this.onMouseUp.bind(this));
|
|
132
|
+
}
|
|
133
|
+
onMouseDown() {
|
|
134
|
+
this.mouseReleased = false;
|
|
135
|
+
}
|
|
136
|
+
onMouseUp() {
|
|
137
|
+
this.mouseReleased = true;
|
|
138
|
+
if (this.view.state.selection.ranges[0].from !== this.view.state.selection.ranges[0].to) {
|
|
139
|
+
saveDispatch(() => {
|
|
140
|
+
this.view.dispatch(this.view.state.update({}));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}, {
|
|
145
|
+
decorations: (plugin) => plugin.decorations,
|
|
146
|
+
});
|
|
147
|
+
};
|
|
103
148
|
|
|
104
149
|
export { markdownDecorationPlugin };
|
|
105
150
|
//# sourceMappingURL=markdown-decoration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-decoration.js","sources":["../../../../src/extensions/markdown/markdown-decoration.ts"],"sourcesContent":["import { syntaxTree } from \"@codemirror/language\";\nimport { type Range } from \"@codemirror/state\";\nimport {\n Decoration,\n type DecorationSet,\n type EditorView,\n ViewPlugin,\n type ViewUpdate,\n} from \"@codemirror/view\";\nimport { blockquoteDecorationPlugin } from \"./blockquote\";\nimport { boldDecorationPlugin } from \"./bold\";\nimport { codeDecorationPlugin } from \"./code\";\nimport { headerDecorationPlugin } from \"./header\";\nimport { horizontalDecorationPlugin } from \"./horizontal\";\nimport { imageDecorationPlugin } from \"./image/image-decoration\";\nimport { italicDecorationPlugin } from \"./italic\";\nimport { autoLinkDecorationPlugin, linkDecorationPlugin } from \"./link\";\nimport { listDecorationPlugin } from \"./list\";\nimport type {\n DecorationPlugin,\n GetDecorationFunction,\n GetSelectionDecorationFunction,\n} from \"./markdown-types\";\nimport { mentionDecorationPlugin } from \"./mention/mention-decoration\";\nimport { strikeThroughDecorationPlugin } from \"./strike-through\";\nimport { todoDecorationPlugin } from \"./todo\";\n\nconst decorationPlugins: DecorationPlugin[] = [\n blockquoteDecorationPlugin,\n boldDecorationPlugin,\n codeDecorationPlugin,\n headerDecorationPlugin,\n horizontalDecorationPlugin,\n imageDecorationPlugin,\n italicDecorationPlugin,\n linkDecorationPlugin,\n listDecorationPlugin,\n autoLinkDecorationPlugin,\n mentionDecorationPlugin,\n strikeThroughDecorationPlugin,\n todoDecorationPlugin,\n];\n\nlet decorationFunctions: GetDecorationFunction[] = [];\nlet selectionDecorationFunctions: GetSelectionDecorationFunction[] = [];\n\nfor (const plugin of decorationPlugins) {\n if (plugin.decorations) decorationFunctions = decorationFunctions.concat(plugin.decorations);\n if (plugin.selectionDecorations)\n selectionDecorationFunctions = selectionDecorationFunctions.concat(plugin.selectionDecorations);\n}\n\nconst SKIP_MARKS = new Set([\n \"Document\",\n \"Paragraph\",\n \"EmphasisMark\",\n \"Blockquote\",\n \"StrikethroughMark\",\n \"BulletList\",\n \"OrderedList\",\n \"ListItem\",\n \"LinkMark\",\n \"URL\",\n \"CodeMark\",\n \"CodeInfo\",\n \"CodeText\",\n \"HeaderMark\",\n \"TaskMarker\",\n]);\n\nlet markdownDecorations: Range<Decoration>[] = [];\n\nfunction getDecorations(view: EditorView, isChanged: boolean) {\n const decorations: Range<Decoration>[] = isChanged ? [] : markdownDecorations;\n const selectionDecorations: Range<Decoration>[] = [];\n const contentEditable = view.contentDOM.getAttribute(\"contenteditable\");\n const isReadonly = !contentEditable || contentEditable === \"false\";\n\n for (const { from: fromVisible, to: toVisible } of view.visibleRanges) {\n syntaxTree(view.state).iterate({\n from: fromVisible,\n to: toVisible,\n enter: (node) => {\n if (SKIP_MARKS.has(node.name)) return;\n /** Decoration by change content */\n if (isChanged) {\n decorationFunctions.forEach((f) => f({ decorations, node, view }));\n }\n\n /** Decoration by selection content */\n selectionDecorationFunctions.forEach((f) =>\n f({\n decorations: selectionDecorations,\n node,\n view,\n isReadonly,\n }),\n );\n },\n });\n }\n\n if (isChanged) {\n markdownDecorations = decorations;\n }\n\n return Decoration.set([...decorations, ...selectionDecorations], true);\n}\n\nexport const markdownDecorationPlugin = ViewPlugin.fromClass(\n class DecorationMarkdown {\n decorations: DecorationSet;\n\n constructor(view: EditorView) {\n this.decorations = getDecorations(view, true);\n }\n\n update(update: ViewUpdate) {\n const isDocumentChanged =\n update.docChanged ||\n update.viewportChanged ||\n syntaxTree(update.startState) != syntaxTree(update.state);\n this.decorations = getDecorations(update.view, isDocumentChanged);\n }\n },\n {\n decorations: (plugin) => plugin.decorations,\n },\n);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA2BA,MAAM,iBAAiB,GAAuB;IAC5C,0BAA0B;IAC1B,oBAAoB;IACpB,oBAAoB;IACpB,sBAAsB;IACtB,0BAA0B;IAC1B,qBAAqB;IACrB,sBAAsB;IACtB,oBAAoB;IACpB,oBAAoB;IACpB,wBAAwB;IACxB,uBAAuB;IACvB,6BAA6B;IAC7B,oBAAoB;CACrB;AAED,IAAI,mBAAmB,GAA4B,EAAE;AACrD,IAAI,4BAA4B,GAAqC,EAAE;AAEvE,KAAK,MAAM,MAAM,IAAI,iBAAiB,EAAE;IACtC,IAAI,MAAM,CAAC,WAAW;QAAE,mBAAmB,GAAG,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;IAC5F,IAAI,MAAM,CAAC,oBAAoB;QAC7B,4BAA4B,GAAG,4BAA4B,CAAC,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC;AACnG;AAEA,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,UAAU;IACV,WAAW;IACX,cAAc;IACd,YAAY;IACZ,mBAAmB;IACnB,YAAY;IACZ,aAAa;IACb,UAAU;IACV,UAAU;IACV,KAAK;IACL,UAAU;IACV,UAAU;IACV,UAAU;IACV,YAAY;IACZ,YAAY;AACb,CAAA,CAAC;AAEF,IAAI,mBAAmB,GAAwB,EAAE;AAEjD,SAAS,cAAc,CAAC,IAAgB,EAAE,SAAkB,EAAA;IAC1D,MAAM,WAAW,GAAwB,SAAS,GAAG,EAAE,GAAG,mBAAmB;IAC7E,MAAM,oBAAoB,GAAwB,EAAE;IACpD,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,iBAAiB,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AAA,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC;QAC3D,IAAI,CAAC,WAAW,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,iBAAiB,CAAC;;CAEpE,EACD;IACE,WAAW,EAAE,CAAC,MAAM,KAAK,MAAM,CAAC,WAAW;AAC5C,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"markdown-decoration.js","sources":["../../../../src/extensions/markdown/markdown-decoration.ts"],"sourcesContent":["import { syntaxTree } from \"@codemirror/language\";\nimport { type Range } from \"@codemirror/state\";\nimport {\n Decoration,\n type DecorationSet,\n type EditorView,\n ViewPlugin,\n type ViewUpdate,\n} from \"@codemirror/view\";\nimport { saveDispatch } from \"@/lib/utils\";\nimport { blockquoteDecorationPlugin } from \"./blockquote\";\nimport { boldDecorationPlugin } from \"./bold\";\nimport { codeDecorationPlugin } from \"./code\";\nimport { headerDecorationPlugin } from \"./header\";\nimport { horizontalDecorationPlugin } from \"./horizontal\";\nimport { imageDecorationPlugin } from \"./image/image-decoration\";\nimport { italicDecorationPlugin } from \"./italic\";\nimport { autoLinkDecorationPlugin, linkDecorationPlugin } from \"./link\";\nimport { listDecorationPlugin } from \"./list\";\nimport { imageSrcGetterEffect } from \"./markdown-state\";\nimport type {\n DecorationPlugin,\n GetDecorationFunction,\n GetSelectionDecorationFunction,\n MarkdownStateConfig,\n} from \"./markdown-types\";\nimport { mentionDecorationPlugin } from \"./mention/mention-decoration\";\nimport { strikeThroughDecorationPlugin } from \"./strike-through\";\nimport { todoDecorationPlugin } from \"./todo\";\n\nconst decorationPlugins: DecorationPlugin[] = [\n blockquoteDecorationPlugin,\n boldDecorationPlugin,\n codeDecorationPlugin,\n headerDecorationPlugin,\n horizontalDecorationPlugin,\n imageDecorationPlugin,\n italicDecorationPlugin,\n linkDecorationPlugin,\n listDecorationPlugin,\n autoLinkDecorationPlugin,\n mentionDecorationPlugin,\n strikeThroughDecorationPlugin,\n todoDecorationPlugin,\n];\n\nlet decorationFunctions: GetDecorationFunction[] = [];\nlet selectionDecorationFunctions: GetSelectionDecorationFunction[] = [];\n\nfor (const plugin of decorationPlugins) {\n if (plugin.decorations) decorationFunctions = decorationFunctions.concat(plugin.decorations);\n if (plugin.selectionDecorations)\n selectionDecorationFunctions = selectionDecorationFunctions.concat(plugin.selectionDecorations);\n}\n\nconst SKIP_MARKS = new Set([\n \"Document\",\n \"Paragraph\",\n \"EmphasisMark\",\n \"Blockquote\",\n \"StrikethroughMark\",\n \"BulletList\",\n \"OrderedList\",\n \"ListItem\",\n \"LinkMark\",\n \"URL\",\n \"CodeMark\",\n \"CodeInfo\",\n \"CodeText\",\n \"HeaderMark\",\n \"TaskMarker\",\n]);\n\nfunction createDecorationsGetter() {\n let markdownDecorationsCache: Range<Decoration>[] = [];\n let markdownSelectionDecorationsCache: Range<Decoration>[] = [];\n\n function getDecorations(view: EditorView, isChanged: boolean, mouseReleased: boolean) {\n const processDecorations = isChanged;\n const processSelectionDecorations = isChanged || mouseReleased;\n const decorations: Range<Decoration>[] = processDecorations ? [] : markdownDecorationsCache;\n const selectionDecorations: Range<Decoration>[] = processSelectionDecorations\n ? []\n : markdownSelectionDecorationsCache;\n\n const contentEditable = view.contentDOM.getAttribute(\"contenteditable\");\n const isReadonly = !contentEditable || contentEditable === \"false\";\n\n for (const { from: fromVisible, to: toVisible } of view.visibleRanges) {\n syntaxTree(view.state).iterate({\n from: fromVisible,\n to: toVisible,\n enter: (node) => {\n if (SKIP_MARKS.has(node.name)) return;\n /** Decoration by change content */\n if (processDecorations)\n decorationFunctions.forEach((f) => f({ decorations, node, view }));\n\n /** Decoration by selection content */\n if (processSelectionDecorations)\n selectionDecorationFunctions.forEach((f) =>\n f({\n decorations: selectionDecorations,\n node,\n view,\n forceActive: isReadonly,\n }),\n );\n },\n });\n }\n\n if (processDecorations) {\n markdownDecorationsCache = decorations;\n }\n if (processSelectionDecorations) {\n markdownSelectionDecorationsCache = selectionDecorations;\n }\n\n return Decoration.set([...decorations, ...selectionDecorations], true);\n }\n\n return getDecorations;\n}\n\nexport const markdownDecorationPlugin = (stateConfig: MarkdownStateConfig) => {\n return ViewPlugin.fromClass(\n class DecorationMarkdown {\n decorations: DecorationSet;\n\n mouseReleased: boolean = true;\n\n dom: HTMLElement;\n\n view: EditorView;\n\n decorationGetter: (\n view: EditorView,\n isChanged: boolean,\n mouseReleased: boolean,\n ) => DecorationSet;\n\n constructor(view: EditorView) {\n this.decorationGetter = createDecorationsGetter();\n this.decorations = this.decorationGetter(view, true, this.mouseReleased);\n this.dom = view.dom;\n this.view = view;\n document.addEventListener(\"mousedown\", this.onMouseDown.bind(this));\n document.addEventListener(\"mouseup\", this.onMouseUp.bind(this));\n\n saveDispatch(() => {\n this.view.dispatch(\n this.view.state.update({\n effects: [imageSrcGetterEffect.of(stateConfig.imageSrcGetter)],\n }),\n );\n });\n }\n\n update(update: ViewUpdate) {\n const isDocumentChanged =\n update.docChanged ||\n update.viewportChanged ||\n syntaxTree(update.startState) != syntaxTree(update.state);\n this.decorations = this.decorationGetter(\n update.view,\n isDocumentChanged,\n this.mouseReleased,\n );\n }\n\n destroy() {\n document.removeEventListener(\"mousedown\", this.onMouseDown.bind(this));\n document.removeEventListener(\"mouseup\", this.onMouseUp.bind(this));\n }\n\n onMouseDown(this: DecorationMarkdown) {\n this.mouseReleased = false;\n }\n\n onMouseUp(this: DecorationMarkdown) {\n this.mouseReleased = true;\n if (this.view.state.selection.ranges[0].from !== this.view.state.selection.ranges[0].to) {\n saveDispatch(() => {\n this.view.dispatch(this.view.state.update({}));\n });\n }\n }\n },\n {\n decorations: (plugin) => plugin.decorations,\n },\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,MAAM,iBAAiB,GAAuB;IAC5C,0BAA0B;IAC1B,oBAAoB;IACpB,oBAAoB;IACpB,sBAAsB;IACtB,0BAA0B;IAC1B,qBAAqB;IACrB,sBAAsB;IACtB,oBA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,YAAA,IAAI,CAAC,aAAa,GAAG,KAAK;;QAG5B,SAAS,GAAA;AACP,YAAA,IAAI,CAAC,aAAa,GAAG,IAAI;AACzB,YAAA,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;gBACvF,YAAY,CAAC,MAAK;AAChB,oBAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAChD,iBAAC,CAAC;;;KAGP,EACD;QACE,WAAW,EAAE,CAAC,MAAM,KAAK,MAAM,CAAC,WAAW;AAC5C,KAAA,CACF;AACH;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { StateEffect, StateField } from '@codemirror/state';
|
|
2
|
+
|
|
3
|
+
const openedImageEffect = StateEffect.define();
|
|
4
|
+
const openedLinkEffect = StateEffect.define();
|
|
5
|
+
const imageSrcGetterEffect = StateEffect.define();
|
|
6
|
+
const markdownState = StateField.define({
|
|
7
|
+
create() {
|
|
8
|
+
return {
|
|
9
|
+
openedImage: undefined,
|
|
10
|
+
imageSrcGetter: undefined,
|
|
11
|
+
openedLink: undefined,
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
update(value, transaction) {
|
|
15
|
+
const newValue = { ...value };
|
|
16
|
+
for (const effect of transaction.effects) {
|
|
17
|
+
if (effect.is(openedImageEffect))
|
|
18
|
+
newValue.openedImage = effect.value;
|
|
19
|
+
if (effect.is(imageSrcGetterEffect))
|
|
20
|
+
newValue.imageSrcGetter = effect.value;
|
|
21
|
+
if (effect.is(openedLinkEffect))
|
|
22
|
+
newValue.openedLink = effect.value;
|
|
23
|
+
}
|
|
24
|
+
return newValue;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export { imageSrcGetterEffect, markdownState, openedImageEffect, openedLinkEffect };
|
|
29
|
+
//# sourceMappingURL=markdown-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-state.js","sources":["../../../../src/extensions/markdown/markdown-state.ts"],"sourcesContent":["import { StateEffect, StateField } from \"@codemirror/state\";\nimport type { MarkdownState } from \"./markdown-types\";\n\nexport const openedImageEffect = StateEffect.define<string | undefined>();\nexport const openedLinkEffect = StateEffect.define<string | undefined>();\nexport const imageSrcGetterEffect = StateEffect.define<((src: string) => string) | undefined>();\n\nexport const markdownState = StateField.define<MarkdownState>({\n create() {\n return {\n openedImage: undefined,\n imageSrcGetter: undefined,\n openedLink: undefined,\n };\n },\n\n update(value, transaction) {\n const newValue = { ...value };\n\n for (const effect of transaction.effects) {\n if (effect.is(openedImageEffect)) newValue.openedImage = effect.value;\n if (effect.is(imageSrcGetterEffect)) newValue.imageSrcGetter = effect.value;\n if (effect.is(openedLinkEffect)) newValue.openedLink = effect.value;\n }\n\n return newValue;\n },\n});\n"],"names":[],"mappings":";;MAGa,iBAAiB,GAAG,WAAW,CAAC,MAAM;MACtC,gBAAgB,GAAG,WAAW,CAAC,MAAM;MACrC,oBAAoB,GAAG,WAAW,CAAC,MAAM;AAEzC,MAAA,aAAa,GAAG,UAAU,CAAC,MAAM,CAAgB;IAC5D,MAAM,GAAA;QACJ,OAAO;AACL,YAAA,WAAW,EAAE,SAAS;AACtB,YAAA,cAAc,EAAE,SAAS;AACzB,YAAA,UAAU,EAAE,SAAS;SACtB;KACF;IAED,MAAM,CAAC,KAAK,EAAE,WAAW,EAAA;AACvB,QAAA,MAAM,QAAQ,GAAG,EAAE,GAAG,KAAK,EAAE;AAE7B,QAAA,KAAK,MAAM,MAAM,IAAI,WAAW,CAAC,OAAO,EAAE;AACxC,YAAA,IAAI,MAAM,CAAC,EAAE,CAAC,iBAAiB,CAAC;AAAE,gBAAA,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,KAAK;AACrE,YAAA,IAAI,MAAM,CAAC,EAAE,CAAC,oBAAoB,CAAC;AAAE,gBAAA,QAAQ,CAAC,cAAc,GAAG,MAAM,CAAC,KAAK;AAC3E,YAAA,IAAI,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC;AAAE,gBAAA,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,KAAK;;AAGrE,QAAA,OAAO,QAAQ;KAChB;AACF,CAAA;;;;"}
|
|
@@ -18,11 +18,11 @@ function getMentionDecorations({ decorations, node }) {
|
|
|
18
18
|
range: [node.from, node.to],
|
|
19
19
|
}));
|
|
20
20
|
}
|
|
21
|
-
function getMentionSelectionDecorations({ decorations, node, view,
|
|
21
|
+
function getMentionSelectionDecorations({ decorations, node, view, forceActive, }) {
|
|
22
22
|
if (node.name !== NAME_OF_MENTION) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
if (
|
|
25
|
+
if (forceActive ||
|
|
26
26
|
!view.hasFocus ||
|
|
27
27
|
!isInRange(view.state.selection.ranges, [node.from, node.to])) {
|
|
28
28
|
decorations.push(getHideDecoration({ range: [node.from, node.from + 1] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mention-decoration.js","sources":["../../../../../src/extensions/markdown/mention/mention-decoration.ts"],"sourcesContent":["import clsx from \"clsx\";\nimport { CLASSES } from \"@/extensions/theme\";\nimport { utils } from \"@/lib\";\nimport type {\n DecorationPlugin,\n GetDecorationOptions,\n GetSelectionDecorationOptions,\n} from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { NAME_OF_MENTION } from \"./mention-constants\";\n\nfunction getMentionDecorations({ decorations, node }: GetDecorationOptions) {\n if (node.name !== NAME_OF_MENTION) {\n return;\n }\n\n decorations.push(\n utils.getMarkDecoration({\n style: clsx(styles.mention, CLASSES.mention),\n range: [node.from, node.to],\n }),\n );\n}\n\nfunction getMentionSelectionDecorations({\n decorations,\n node,\n view,\n
|
|
1
|
+
{"version":3,"file":"mention-decoration.js","sources":["../../../../../src/extensions/markdown/mention/mention-decoration.ts"],"sourcesContent":["import clsx from \"clsx\";\nimport { CLASSES } from \"@/extensions/theme\";\nimport { utils } from \"@/lib\";\nimport type {\n DecorationPlugin,\n GetDecorationOptions,\n GetSelectionDecorationOptions,\n} from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { NAME_OF_MENTION } from \"./mention-constants\";\n\nfunction getMentionDecorations({ decorations, node }: GetDecorationOptions) {\n if (node.name !== NAME_OF_MENTION) {\n return;\n }\n\n decorations.push(\n utils.getMarkDecoration({\n style: clsx(styles.mention, CLASSES.mention),\n range: [node.from, node.to],\n }),\n );\n}\n\nfunction getMentionSelectionDecorations({\n decorations,\n node,\n view,\n forceActive,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_MENTION) {\n return;\n }\n\n if (\n forceActive ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [node.from, node.to])\n ) {\n decorations.push(utils.getHideDecoration({ range: [node.from, node.from + 1] }));\n }\n}\n\nexport const mentionDecorationPlugin: DecorationPlugin = {\n decorations: [getMentionDecorations],\n selectionDecorations: [getMentionSelectionDecorations],\n};\n"],"names":["utils.getMarkDecoration","utils.isInRange","utils.getHideDecoration"],"mappings":";;;;;;;;;;;AAWA,SAAS,qBAAqB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAwB,EAAA;AACxE,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,eAAe,EAAE;QACjC;;AAGF,IAAA,WAAW,CAAC,IAAI,CACdA,iBAAuB,CAAC;QACtB,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;QAC5C,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;AAC5B,KAAA,CAAC,CACH;AACH;AAEA,SAAS,8BAA8B,CAAC,EACtC,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,WAAW,GACmB,EAAA;AAC9B,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,eAAe,EAAE;QACjC;;AAGF,IAAA,IACE,WAAW;QACX,CAAC,IAAI,CAAC,QAAQ;QACd,CAACC,SAAe,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,EACnE;QACA,WAAW,CAAC,IAAI,CAACC,iBAAuB,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;;AAEpF;AAEa,MAAA,uBAAuB,GAAqB;IACvD,WAAW,EAAE,CAAC,qBAAqB,CAAC;IACpC,oBAAoB,EAAE,CAAC,8BAA8B,CAAC;;;;;"}
|
|
@@ -12,11 +12,11 @@ function getStrikeThroughDecorations({ decorations, node }) {
|
|
|
12
12
|
range: [node.from, node.to],
|
|
13
13
|
}));
|
|
14
14
|
}
|
|
15
|
-
function getStrikeThroughSelectionDecorations({ decorations, node, view,
|
|
15
|
+
function getStrikeThroughSelectionDecorations({ decorations, node, view, forceActive, }) {
|
|
16
16
|
if (node.name !== NAME_OF_STRIKE_THROUGH) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
if (
|
|
19
|
+
if (forceActive ||
|
|
20
20
|
!view.hasFocus ||
|
|
21
21
|
!isInRange(view.state.selection.ranges, [node.from, node.to])) {
|
|
22
22
|
decorations.push(getHideDecoration({ range: [node.from, node.from + 2] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strike-through-decoration.js","sources":["../../../../../src/extensions/markdown/strike-through/strike-through-decoration.ts"],"sourcesContent":["import { utils } from \"@/lib\";\nimport type {\n DecorationPlugin,\n GetDecorationOptions,\n GetSelectionDecorationOptions,\n} from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { NAME_OF_STRIKE_THROUGH } from \"./strike-through-constants\";\n\nfunction getStrikeThroughDecorations({ decorations, node }: GetDecorationOptions) {\n if (node.name !== NAME_OF_STRIKE_THROUGH) {\n return;\n }\n\n decorations.push(\n utils.getMarkDecoration({\n style: styles[\"strike-through\"],\n range: [node.from, node.to],\n }),\n );\n}\n\nfunction getStrikeThroughSelectionDecorations({\n decorations,\n node,\n view,\n
|
|
1
|
+
{"version":3,"file":"strike-through-decoration.js","sources":["../../../../../src/extensions/markdown/strike-through/strike-through-decoration.ts"],"sourcesContent":["import { utils } from \"@/lib\";\nimport type {\n DecorationPlugin,\n GetDecorationOptions,\n GetSelectionDecorationOptions,\n} from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { NAME_OF_STRIKE_THROUGH } from \"./strike-through-constants\";\n\nfunction getStrikeThroughDecorations({ decorations, node }: GetDecorationOptions) {\n if (node.name !== NAME_OF_STRIKE_THROUGH) {\n return;\n }\n\n decorations.push(\n utils.getMarkDecoration({\n style: styles[\"strike-through\"],\n range: [node.from, node.to],\n }),\n );\n}\n\nfunction getStrikeThroughSelectionDecorations({\n decorations,\n node,\n view,\n forceActive,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_STRIKE_THROUGH) {\n return;\n }\n\n if (\n forceActive ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [node.from, node.to])\n ) {\n decorations.push(utils.getHideDecoration({ range: [node.from, node.from + 2] }));\n decorations.push(utils.getHideDecoration({ range: [node.to - 2, node.to] }));\n }\n}\n\nexport const strikeThroughDecorationPlugin: DecorationPlugin = {\n decorations: [getStrikeThroughDecorations],\n selectionDecorations: [getStrikeThroughSelectionDecorations],\n};\n"],"names":["utils.getMarkDecoration","utils.isInRange","utils.getHideDecoration"],"mappings":";;;;;AASA,SAAS,2BAA2B,CAAC,EAAE,WAAW,EAAE,IAAI,EAAwB,EAAA;AAC9E,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,sBAAsB,EAAE;QACxC;;AAGF,IAAA,WAAW,CAAC,IAAI,CACdA,iBAAuB,CAAC;AACtB,QAAA,KAAK,EAAE,MAAM,CAAC,gBAAgB,CAAC;QAC/B,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;AAC5B,KAAA,CAAC,CACH;AACH;AAEA,SAAS,oCAAoC,CAAC,EAC5C,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,WAAW,GACmB,EAAA;AAC9B,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,sBAAsB,EAAE;QACxC;;AAGF,IAAA,IACE,WAAW;QACX,CAAC,IAAI,CAAC,QAAQ;QACd,CAACC,SAAe,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,EACnE;QACA,WAAW,CAAC,IAAI,CAACC,iBAAuB,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;QAChF,WAAW,CAAC,IAAI,CAACA,iBAAuB,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;;AAEhF;AAEa,MAAA,6BAA6B,GAAqB;IAC7D,WAAW,EAAE,CAAC,2BAA2B,CAAC;IAC1C,oBAAoB,EAAE,CAAC,oCAAoC,CAAC;;;;;"}
|
|
@@ -4,14 +4,14 @@ import styles from '../styles.module.scss.js';
|
|
|
4
4
|
import { NAME_OF_TODO, NAME_OF_LIST_MARK, LIST_OF_TODO_MARKS } from './todo-constants.js';
|
|
5
5
|
import { TodoWidget } from './todo-widget.js';
|
|
6
6
|
|
|
7
|
-
function getTodoSelectionDecoration({ decorations, node, view,
|
|
7
|
+
function getTodoSelectionDecoration({ decorations, node, view, forceActive, }) {
|
|
8
8
|
if (node.name !== NAME_OF_TODO)
|
|
9
9
|
return;
|
|
10
10
|
const prevSibling = node.node.prevSibling;
|
|
11
11
|
if (!prevSibling || prevSibling.name !== NAME_OF_LIST_MARK)
|
|
12
12
|
return;
|
|
13
13
|
const isChecked = LIST_OF_TODO_MARKS.has(view.state.doc.sliceString(node.from + 1, node.from + 2).codePointAt(0) || 0);
|
|
14
|
-
if (
|
|
14
|
+
if (forceActive ||
|
|
15
15
|
!view.hasFocus ||
|
|
16
16
|
!isInRange(view.state.selection.ranges, [prevSibling.from, node.from + 3])) {
|
|
17
17
|
decorations.push(getReplaceDecoration({
|
|
@@ -21,7 +21,7 @@ function getTodoSelectionDecoration({ decorations, node, view, isReadonly, }) {
|
|
|
21
21
|
}
|
|
22
22
|
if (isChecked) {
|
|
23
23
|
const line = view.lineBlockAt(node.from);
|
|
24
|
-
if (
|
|
24
|
+
if (forceActive ||
|
|
25
25
|
!view.hasFocus ||
|
|
26
26
|
!isInRange(view.state.selection.ranges, [line.from, line.to]))
|
|
27
27
|
decorations.push(getMarkDecoration({ style: styles.todo__checked, range: [node.from + 4, node.to] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"todo-decoration.js","sources":["../../../../../src/extensions/markdown/todo/todo-decoration.ts"],"sourcesContent":["import { utils } from \"@/lib\";\nimport type { DecorationPlugin, GetSelectionDecorationOptions } from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { LIST_OF_TODO_MARKS, NAME_OF_LIST_MARK, NAME_OF_TODO } from \"./todo-constants\";\nimport { TodoWidget } from \"./todo-widget\";\n\nfunction getTodoSelectionDecoration({\n decorations,\n node,\n view,\n
|
|
1
|
+
{"version":3,"file":"todo-decoration.js","sources":["../../../../../src/extensions/markdown/todo/todo-decoration.ts"],"sourcesContent":["import { utils } from \"@/lib\";\nimport type { DecorationPlugin, GetSelectionDecorationOptions } from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { LIST_OF_TODO_MARKS, NAME_OF_LIST_MARK, NAME_OF_TODO } from \"./todo-constants\";\nimport { TodoWidget } from \"./todo-widget\";\n\nfunction getTodoSelectionDecoration({\n decorations,\n node,\n view,\n forceActive,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_TODO) return;\n\n const prevSibling = node.node.prevSibling;\n if (!prevSibling || prevSibling.name !== NAME_OF_LIST_MARK) return;\n\n const isChecked = LIST_OF_TODO_MARKS.has(\n view.state.doc.sliceString(node.from + 1, node.from + 2).codePointAt(0) || 0,\n );\n\n if (\n forceActive ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [prevSibling.from, node.from + 3])\n ) {\n decorations.push(\n utils.getReplaceDecoration({\n range: [node.from, node.from + 3],\n widget: new TodoWidget(isChecked, node.from + 1),\n }),\n );\n }\n\n if (isChecked) {\n const line = view.lineBlockAt(node.from);\n\n if (\n forceActive ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [line.from, line.to])\n )\n decorations.push(\n utils.getMarkDecoration({ style: styles.todo__checked, range: [node.from + 4, node.to] }),\n );\n }\n}\n\nexport const todoDecorationPlugin: DecorationPlugin = {\n selectionDecorations: [getTodoSelectionDecoration],\n};\n"],"names":["utils.isInRange","utils.getReplaceDecoration","utils.getMarkDecoration"],"mappings":";;;;;;AAMA,SAAS,0BAA0B,CAAC,EAClC,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,WAAW,GACmB,EAAA;AAC9B,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY;QAAE;AAEhC,IAAA,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW;AACzC,IAAA,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,IAAI,KAAK,iBAAiB;QAAE;AAE5D,IAAA,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CACtC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC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eSpec } from \"@codemirror/state\";\nimport { type EditorView, WidgetType } from \"@codemirror/view\";\nimport { saveDispatch } from \"@/lib/utils\";\nimport styles from \"../styles.module.scss\";\n\nexport class TodoWidget extends WidgetType {\n view: EditorView | undefined;\n\n constructor(\n public checked: boolean,\n private readonly position: number,\n ) {\n super();\n }\n\n onClick(event: MouseEvent) {\n event.stopPropagation();\n event.preventDefault();\n\n const target = event.target as HTMLInputElement;\n const change: ChangeSpec = {\n from: this.position,\n to: this.position + 1,\n insert: this.checked ? \" \" : \"x\",\n };\n\n saveDispatch(() => {\n if (!this.view) return;\n\n this.view.dispatch(this.view.state.update({ changes: change }));\n });\n\n this.checked = !this.checked;\n target.checked = this.checked;\n }\n\n onBlock(event: MouseEvent) {\n event.stopPropagation();\n event.preventDefault();\n }\n\n toDOM(view: EditorView): HTMLElement {\n const span = document.createElement(\"span\");\n span.classList.add(styles.todo);\n this.view = view;\n\n const checkbox = document.createElement(\"input\");\n checkbox.type = \"checkbox\";\n checkbox.checked = this.checked;\n\n checkbox.addEventListener(\"click\", this.onBlock.bind(this));\n checkbox.addEventListener(\"mousedown\", this.onClick.bind(this));\n\n span.appendChild(checkbox);\n\n return span;\n }\n\n destroy(dom: HTMLElement): void {\n dom.removeEventListener(\"click\", this.onBlock.bind(this));\n dom.removeEventListener(\"mousedown\", this.onClick.bind(this));\n }\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"todo-widget.js","sources":["../../../../../src/extensions/markdown/todo/todo-widget.ts"],"sourcesContent":["import { type ChangeSpec } from \"@codemirror/state\";\nimport { type EditorView, WidgetType } from \"@codemirror/view\";\nimport { saveDispatch } from \"@/lib/utils\";\nimport styles from \"../styles.module.scss\";\n\nexport class TodoWidget extends WidgetType {\n view: EditorView | undefined;\n\n constructor(\n public checked: boolean,\n private readonly position: number,\n ) {\n super();\n }\n\n onClick(event: MouseEvent) {\n event.stopPropagation();\n event.preventDefault();\n\n const target = event.target as HTMLInputElement;\n const change: ChangeSpec = {\n from: this.position,\n to: this.position + 1,\n insert: this.checked ? \" \" : \"x\",\n };\n\n saveDispatch(() => {\n if (!this.view) return;\n\n this.view.dispatch(this.view.state.update({ changes: change }));\n });\n\n this.checked = !this.checked;\n target.checked = this.checked;\n }\n\n onBlock(event: MouseEvent) {\n event.stopPropagation();\n event.preventDefault();\n }\n\n toDOM(view: EditorView): HTMLElement {\n const span = document.createElement(\"span\");\n span.classList.add(styles.todo);\n this.view = view;\n\n const checkbox = document.createElement(\"input\");\n checkbox.type = \"checkbox\";\n checkbox.checked = this.checked;\n\n checkbox.addEventListener(\"click\", this.onBlock.bind(this));\n checkbox.addEventListener(\"mousedown\", this.onClick.bind(this));\n\n span.appendChild(checkbox);\n\n return span;\n }\n\n destroy(dom: HTMLElement): void {\n dom.removeEventListener(\"click\", this.onBlock.bind(this));\n dom.removeEventListener(\"mousedown\", this.onClick.bind(this));\n }\n}\n"],"names":[],"mappings":";;;;;AAKM,MAAO,UAAW,SAAQ,UAAU,CAAA;AAI/B,IAAA,OAAA;AACU,IAAA,QAAA;AAJnB,IAAA,IAAI;IAEJ,WACS,CAAA,OAAgB,EACN,QAAgB,EAAA;AAEjC,QAAA,KAAK,EAAE;QAHA,IAAO,CAAA,OAAA,GAAP,OAAO;QACG,IAAQ,CAAA,QAAA,GAAR,QAAQ;;AAK3B,IAAA,OAAO,CAAC,KAAiB,EAAA;QACvB,KAAK,CAAC,eAAe,EAAE;QACvB,KAAK,CAAC,cAAc,EAAE;AAEtB,QAAA,MAAM,MAAM,GAAG,KAAK,CAAC,MAA0B;AAC/C,QAAA,MAAM,MAAM,GAAe;YACzB,IAAI,EAAE,IAAI,CAAC,QAAQ;AACnB,YAAA,EAAE,EAAE,IAAI,CAAC,QAAQ,GAAG,CAAC;YACrB,MAAM,EAAE,IAAI,CAAC,OAAO,GAAG,GAAG,GAAG,GAAG;SACjC;QAED,YAAY,CAAC,MAAK;YAChB,IAAI,CAAC,IAAI,CAAC,IAAI;gBAAE;YAEhB,I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AAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;AAEhE;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-settings.js","sources":["../../../../src/extensions/settings/init-settings.ts"],"sourcesContent":["import { history } from \"@codemirror/commands\";\nimport { type Extension } from \"@codemirror/state\";\nimport { EditorView, drawSelection } from \"@codemirror/view\";\nimport { ReadonlyCompartment, VimModeCompartment } from \"../compartments\";\n\nexport type InitSettingsOptions = {\n readonly?: boolean;\n vimMode?: boolean;\n};\n\nexport async function InitSettings({\n readonly,\n vimMode,\n}: InitSettingsOptions): Promise<Extension[]> {\n let vimExtension: Extension = [];\n if (vimMode) {\n const { vim } = await import(\"@replit/codemirror-vim\");\n vimExtension = [vim({ status: true }), drawSelection()];\n }\n\n return [\n ReadonlyCompartment.of(EditorView.editable.of(!readonly)),\n VimModeCompartment.of(vimExtension),\n history(),\n ];\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init-settings.js","sources":["../../../../src/extensions/settings/init-settings.ts"],"sourcesContent":["import { history } from \"@codemirror/commands\";\nimport { type Extension } from \"@codemirror/state\";\nimport { EditorView, drawSelection } from \"@codemirror/view\";\nimport { ReadonlyCompartment, VimModeCompartment } from \"../compartments\";\n\nexport type InitSettingsOptions = {\n readonly?: boolean;\n vimMode?: boolean;\n};\n\nexport async function InitSettings({\n readonly,\n vimMode,\n}: InitSettingsOptions): Promise<Extension[]> {\n let vimExtension: Extension = [];\n if (vimMode) {\n const { vim } = await import(\"@replit/codemirror-vim\");\n vimExtension = [vim({ status: true }), drawSelection()];\n }\n\n return [\n ReadonlyCompartment.of(EditorView.editable.of(!readonly)),\n VimModeCompartment.of(vimExtension),\n history(),\n ];\n}\n"],"names":[],"mappings":";;;;;AAUO,eAAe,YAAY,CAAC,EACjC,QAAQ,EACR,OAAO,GACa,EAAA;IACpB,IAAI,YAAY,GAAc,EAAE;IAChC,IAAI,OAAO,EAAE;QACX,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,OAAO,wBAAwB,CAAC;AACtD,QAAA,YAAY,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC;;IAGzD,OAAO;AACL,QAAA,mBAAmB,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;AACzD,QAAA,kBAAkB,CAAC,EAAE,CAAC,YAAY,CAAC;AACnC,QAAA,OAAO,EAAE;KACV;AACH;;;;"}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
export { Editor } from './module/Editor/Editor.js';
|
|
2
|
+
import './extensions/compartments/index.js';
|
|
3
|
+
import '@codemirror/commands';
|
|
4
|
+
import '@codemirror/view';
|
|
5
|
+
import '@codemirror/language';
|
|
6
|
+
import '@lezer/highlight';
|
|
7
|
+
import '@codemirror/state';
|
|
8
|
+
import '@codemirror/lang-markdown';
|
|
9
|
+
import './extensions/markdown/markdown-decoration.js';
|
|
10
|
+
import './extensions/markdown/markdown-state.js';
|
|
2
11
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -5,9 +5,10 @@ function getLineDecoration({ style, range }) {
|
|
|
5
5
|
class: style,
|
|
6
6
|
}).range(range[0], range[1]);
|
|
7
7
|
}
|
|
8
|
-
function getMarkDecoration({ range, style }) {
|
|
8
|
+
function getMarkDecoration({ range, style, attributes }) {
|
|
9
9
|
return Decoration.mark({
|
|
10
10
|
class: style,
|
|
11
|
+
attributes,
|
|
11
12
|
}).range(range[0], range[1]);
|
|
12
13
|
}
|
|
13
14
|
function getHideDecoration({ range }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-decoration.js","sources":["../../../../src/lib/utils/get-decoration.ts"],"sourcesContent":["import { Decoration, type WidgetType } from \"@codemirror/view\";\n\ntype GetLineDecorationOptions = {\n style: string;\n range: [number, number?];\n};\nexport function getLineDecoration({ style, range }: GetLineDecorationOptions) {\n return Decoration.line({\n class: style,\n }).range(range[0], range[1]);\n}\n\ntype GetMarkDecorationOptions = {\n style
|
|
1
|
+
{"version":3,"file":"get-decoration.js","sources":["../../../../src/lib/utils/get-decoration.ts"],"sourcesContent":["import { Decoration, type WidgetType } from \"@codemirror/view\";\n\ntype GetLineDecorationOptions = {\n style: string;\n range: [number, number?];\n};\nexport function getLineDecoration({ style, range }: GetLineDecorationOptions) {\n return Decoration.line({\n class: style,\n }).range(range[0], range[1]);\n}\n\ntype GetMarkDecorationOptions = {\n style?: string;\n attributes?: Record<string, string>;\n range: [number, number];\n};\nexport function getMarkDecoration({ range, style, attributes }: GetMarkDecorationOptions) {\n return Decoration.mark({\n class: style,\n attributes,\n }).range(range[0], range[1]);\n}\n\ntype GetHideDecorationOptions = {\n range: [number, number];\n};\nexport function getHideDecoration({ range }: GetHideDecorationOptions) {\n return Decoration.replace({}).range(range[0], range[1]);\n}\n\ntype GetReplaceDecorationOptions = {\n range: [number, number?];\n widget: WidgetType;\n};\nexport function getReplaceDecoration({ range, widget }: GetReplaceDecorationOptions) {\n return Decoration.replace({ widget }).range(range[0], range[1]);\n}\n\ntype GetWidgetDecorationOptions = {\n widget: WidgetType;\n range: [number, number?];\n};\nexport function getWidgetDecorationOptions({ widget, range }: GetWidgetDecorationOptions) {\n return Decoration.widget({ widget, side: 1 }).range(range[0], range[1]);\n}\n"],"names":[],"mappings":";;SAMgB,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAA4B,EAAA;IAC1E,OAAO,UAAU,CAAC,IAAI,CAAC;AACrB,QAAA,KAAK,EAAE,KAAK;AACb,KAAA,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAC9B;AAOM,SAAU,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAA4B,EAAA;IACtF,OAAO,UAAU,CAAC,IAAI,CAAC;AACrB,QAAA,KAAK,EAAE,KAAK;QACZ,UAAU;AACX,KAAA,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAC9B;AAKgB,SAAA,iBAAiB,CAAC,EAAE,KAAK,EAA4B,EAAA;AACnE,IAAA,OAAO,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AACzD;SAMgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,MAAM,EAA+B,EAAA;IACjF,OAAO,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AACjE;SAMgB,0BAA0B,CAAC,EAAE,MAAM,EAAE,KAAK,EAA8B,EAAA;IACtF,OAAO,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AACzE;;;;"}
|
|
@@ -4,6 +4,10 @@ import '@codemirror/commands';
|
|
|
4
4
|
import { saveDispatch } from '../../lib/utils/save-dispatch.js';
|
|
5
5
|
import { getDarkTheme } from '../../extensions/theme/themes/get-dark-theme.js';
|
|
6
6
|
import { getLightTheme } from '../../extensions/theme/themes/get-light-theme.js';
|
|
7
|
+
import '@codemirror/state';
|
|
8
|
+
import '@codemirror/lang-markdown';
|
|
9
|
+
import '../../extensions/markdown/markdown-decoration.js';
|
|
10
|
+
import '../../extensions/markdown/markdown-state.js';
|
|
7
11
|
import { initEditor } from './lib/init-editor.js';
|
|
8
12
|
|
|
9
13
|
class Editor {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.js","sources":["../../../../src/module/Editor/Editor.ts"],"sourcesContent":["import { EditorView, drawSelection } from \"@codemirror/view\";\nimport type { WebsocketProvider } from \"y-websocket\";\nimport {\n type EditorTheme,\n ReadonlyCompartment,\n ThemeCompartment,\n VimModeCompartment,\n getDarkTheme,\n getLightTheme,\n} from \"@/extensions\";\nimport { saveDispatch } from \"@/lib/utils\";\nimport { type EditorArguments } from \"./Editor.types\";\nimport { initEditor } from \"./lib\";\n\nexport class Editor {\n view: EditorView | undefined;\n\n provider: WebsocketProvider | undefined;\n\n arguments: EditorArguments;\n\n constructor(options: EditorArguments) {\n void initEditor(options).then((editor) => {\n this.view = editor.view;\n this.provider = editor.provider;\n });\n\n this.arguments = options;\n }\n\n focus = () => {\n if (!this.view) return;\n\n this.view.focus();\n };\n\n getContent = () => {\n if (!this.view) return;\n\n return this.view.state.doc.toString();\n };\n\n setContent = (content: string, position?: number) => {\n if (!this.view) return;\n\n if (position == undefined) {\n const cursor = this.view.state.selection.main.head;\n position = cursor;\n }\n\n const transaction = this.view.state.update({\n changes: {\n from: position,\n insert: content,\n },\n });\n saveDispatch(() => {\n if (!this.view) return;\n\n this.view.dispatch(transaction);\n });\n };\n\n setReadonly = (readonly: boolean) => {\n saveDispatch(() => {\n if (!this.view) return;\n this.view.dispatch({\n effects: ReadonlyCompartment.reconfigure(EditorView.editable.of(!readonly)),\n });\n });\n };\n\n setTheme = (theme?: EditorTheme) => {\n saveDispatch(() => {\n if (!this.view) return;\n this.view.dispatch({\n effects: ThemeCompartment.reconfigure(\n theme === \"dark\"\n ? getDarkTheme({\n dark: this.arguments.dark,\n light: this.arguments.light,\n theme,\n })\n : getLightTheme({\n dark: this.arguments.dark,\n light: this.arguments.light,\n theme,\n }),\n ),\n });\n });\n };\n\n setVimMode = async (mode: boolean) => {\n if (!this.view) return;\n\n const { vim } = await import(\"@replit/codemirror-vim\");\n\n saveDispatch(() => {\n if (!this.view) return;\n this.view.dispatch({\n effects: VimModeCompartment.reconfigure(\n mode ? [vim({ status: true }), drawSelection()] : [],\n ),\n });\n });\n };\n\n setUserProvider = (name: string = \"Anonymous\", color: string = \"#000000\") => {\n if (!this.provider) return;\n\n this.provider.awareness.setLocalStateField(\"user\", { name, color });\n };\n\n destroy = () => {\n saveDispatch(() => {\n if (!this.view) return;\n this.view.destroy();\n });\n saveDispatch(() => {\n if (this.provider) this.provider.destroy();\n });\n };\n}\n\nexport type EditorInterface = typeof Editor;\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Editor.js","sources":["../../../../src/module/Editor/Editor.ts"],"sourcesContent":["import { EditorView, drawSelection } from \"@codemirror/view\";\nimport type { WebsocketProvider } from \"y-websocket\";\nimport {\n type EditorTheme,\n ReadonlyCompartment,\n ThemeCompartment,\n VimModeCompartment,\n getDarkTheme,\n getLightTheme,\n} from \"@/extensions\";\nimport { saveDispatch } from \"@/lib/utils\";\nimport { type EditorArguments } from \"./Editor.types\";\nimport { initEditor } from \"./lib\";\n\nexport class Editor {\n view: EditorView | undefined;\n\n provider: WebsocketProvider | undefined;\n\n arguments: EditorArguments;\n\n constructor(options: EditorArguments) {\n void initEditor(options).then((editor) => {\n this.view = editor.view;\n this.provider = editor.provider;\n });\n\n this.arguments = options;\n }\n\n focus = () => {\n if (!this.view) return;\n\n this.view.focus();\n };\n\n getContent = () => {\n if (!this.view) return;\n\n return this.view.state.doc.toString();\n };\n\n setContent = (content: string, position?: number) => {\n if (!this.view) return;\n\n if (position == undefined) {\n const cursor = this.view.state.selection.main.head;\n position = cursor;\n }\n\n const transaction = this.view.state.update({\n changes: {\n from: position,\n insert: content,\n },\n });\n saveDispatch(() => {\n if (!this.view) return;\n\n this.view.dispatch(transaction);\n });\n };\n\n setReadonly = (readonly: boolean) => {\n saveDispatch(() => {\n if (!this.view) return;\n this.view.dispatch({\n effects: ReadonlyCompartment.reconfigure(EditorView.editable.of(!readonly)),\n });\n });\n };\n\n setTheme = (theme?: EditorTheme) => {\n saveDispatch(() => {\n if (!this.view) return;\n this.view.dispatch({\n effects: ThemeCompartment.reconfigure(\n theme === \"dark\"\n ? getDarkTheme({\n dark: this.arguments.dark,\n light: this.arguments.light,\n theme,\n })\n : getLightTheme({\n dark: this.arguments.dark,\n light: this.arguments.light,\n theme,\n }),\n ),\n });\n });\n };\n\n setVimMode = async (mode: boolean) => {\n if (!this.view) return;\n\n const { vim } = await import(\"@replit/codemirror-vim\");\n\n saveDispatch(() => {\n if (!this.view) return;\n this.view.dispatch({\n effects: VimModeCompartment.reconfigure(\n mode ? [vim({ status: true }), drawSelection()] : [],\n ),\n });\n });\n };\n\n setUserProvider = (name: string = \"Anonymous\", color: string = \"#000000\") => {\n if (!this.provider) return;\n\n this.provider.awareness.setLocalStateField(\"user\", { name, color });\n };\n\n destroy = () => {\n saveDispatch(() => {\n if (!this.view) return;\n this.view.destroy();\n });\n saveDispatch(() => {\n if (this.provider) this.provider.destroy();\n });\n };\n}\n\nexport type EditorInterface = typeof Editor;\n"],"names":[],"mappings":";;;;;;;;;;;;MAca,MAAM,CAAA;AACjB,IAAA,IAAI;AAEJ,IAAA,QAAQ;AAER,IAAA,SAAS;AAET,IAAA,WAAA,CAAY,OAAwB,EAAA;QAClC,KAAK,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAI;AACvC,YAAA,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI;AACvB,YAAA,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ;AACjC,SAAC,CAAC;AAEF,QAAA,IAAI,CAAC,SAAS,GAAG,OAAO;;IAG1B,KAAK,GAAG,MAAK;QACX,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE;AAEhB,QAAA,IAAI,CAAC,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IAAI,CAAC,IAAI,CAAC,IAAI;gBAAE;AAChB,YAAA,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;AACrB,SAAC,CAAC;QACF,YAAY,CAAC,MAAK;YAChB,IAAI,IAAI,CAAC,QAAQ;AAAE,gBAAA,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;AAC5C,SAAC,CAAC;AACJ,KAAC;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-editor.js","sources":["../../../../../src/module/Editor/lib/init-editor.ts"],"sourcesContent":["import { EditorView } from \"@codemirror/view\";\nimport { type WebsocketProvider } from \"y-websocket\";\nimport type { Text } from \"yjs\";\nimport type { EditorArguments } from \"../Editor.types\";\nimport { initEditorProvider } from \"./init-editor-provider\";\nimport { initEditorState } from \"./init-editor-state\";\n\nexport async function initEditor({ multiCursor, root, initialText, ...rest }: EditorArguments) {\n let provider: WebsocketProvider | undefined;\n let multiCursorText: Text | undefined;\n\n if (multiCursor) {\n const editorProvider = await initEditorProvider({ ...multiCursor, initialText });\n provider = editorProvider.provider;\n multiCursorText = editorProvider.multiCursorText;\n }\n\n const state = await initEditorState({\n ...rest,\n text: initialText || \"\",\n provider,\n multiCursorText,\n });\n const view = new EditorView({\n state,\n parent: root,\n });\n\n return { view, provider };\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init-editor.js","sources":["../../../../../src/module/Editor/lib/init-editor.ts"],"sourcesContent":["import { EditorView } from \"@codemirror/view\";\nimport { type WebsocketProvider } from \"y-websocket\";\nimport type { Text } from \"yjs\";\nimport type { EditorArguments } from \"../Editor.types\";\nimport { initEditorProvider } from \"./init-editor-provider\";\nimport { initEditorState } from \"./init-editor-state\";\n\nexport async function initEditor({ multiCursor, root, initialText, ...rest }: EditorArguments) {\n let provider: WebsocketProvider | undefined;\n let multiCursorText: Text | undefined;\n\n if (multiCursor) {\n const editorProvider = await initEditorProvider({ ...multiCursor, initialText });\n provider = editorProvider.provider;\n multiCursorText = editorProvider.multiCursorText;\n }\n\n const state = await initEditorState({\n ...rest,\n text: initialText || \"\",\n provider,\n multiCursorText,\n });\n const view = new EditorView({\n state,\n parent: root,\n });\n\n return { view, provider };\n}\n"],"names":[],"mappings":";;;;;AAOO,eAAe,UAAU,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,EAAmB,EAAA;AAC3F,IAAA,IAAI,QAAuC;AAC3C,IAAA,IAAI,eAAiC;IAErC,IAAI,WAAW,EAAE;AACf,QAAA,MAAM,cAAc,GAAG,MAAM,kBAAkB,CAAC,EAAE,GAAG,WAAW,EAAE,WAAW,EAAE,CAAC;AAChF,QAAA,QAAQ,GAAG,cAAc,CAAC,QAAQ;AAClC,QAAA,eAAe,GAAG,cAAc,CAAC,eAAe;;AAGlD,IAAA,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC;AAClC,QAAA,GAAG,IAAI;QACP,IAAI,EAAE,WAAW,IAAI,EAAE;QACvB,QAAQ;QACR,eAAe;AAChB,KAAA,CAAC;AACF,IAAA,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC;QAC1B,KAAK;AACL,QAAA,MAAM,EAAE,IAAI;AACb,KAAA,CAAC;AAEF,IAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE;AAC3B;;;;"}
|
package/lib/index.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ type InitListenersOptions = GetFocusEventOptions & GetChangeEventOptions;
|
|
|
75
75
|
|
|
76
76
|
type InitMarkdownOptions = {
|
|
77
77
|
languages?: LanguageDescription[];
|
|
78
|
+
imageSrcGetter?: (src: string) => string;
|
|
78
79
|
};
|
|
79
80
|
type GetDecorationOptions = {
|
|
80
81
|
node: SyntaxNodeRef;
|
|
@@ -85,7 +86,7 @@ type GetSelectionDecorationOptions = {
|
|
|
85
86
|
node: SyntaxNodeRef;
|
|
86
87
|
decorations: Range<Decoration>[];
|
|
87
88
|
view: EditorView;
|
|
88
|
-
|
|
89
|
+
forceActive: boolean;
|
|
89
90
|
};
|
|
90
91
|
type GetDecorationFunction = (options: GetDecorationOptions) => void;
|
|
91
92
|
type GetSelectionDecorationFunction = (options: GetSelectionDecorationOptions) => void;
|