@kerebron/extension-codemirror 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Permission is hereby granted, free of charge, to any
2
+ person obtaining a copy of this software and associated
3
+ documentation files (the "Software"), to deal in the
4
+ Software without restriction, including without
5
+ limitation the rights to use, copy, modify, merge,
6
+ publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software
8
+ is furnished to do so, subject to the following
9
+ conditions:
10
+
11
+ The above copyright notice and this permission notice
12
+ shall be included in all copies or substantial portions
13
+ of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
+ DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Codemirror extension for Kerebron editor kit
2
+
3
+ ## Usage as a code only editor
4
+
5
+ ```js
6
+ import { CoreEditor } from '@kerebron/editor';
7
+ import { ExtensionBasicEditor } from '@kerebron/extension-basic-editor';
8
+ import {
9
+ NodeCodeMirror,
10
+ NodeDocumentCode,
11
+ } from '@kerebron/extension-codemirror';
12
+
13
+ this.editor = new CoreEditor({
14
+ topNode: 'doc_code',
15
+ element: document.querySelector('div#editor'),
16
+ extensions: [
17
+ new ExtensionBasicEditor(),
18
+ new NodeDocumentCode({ lang: 'yaml' }),
19
+ new NodeCodeMirror({ languageWhitelist: ['yaml'] }),
20
+ ],
21
+ });
22
+ ```
23
+
24
+ ```js
25
+ this.editor.setDocument(
26
+ '# Multiline string with literal block syntax -preserved new lines\n' +
27
+ 'string1: |\n' +
28
+ ' Line1\n' +
29
+ ' line2\n' +
30
+ ' "line3"\n' +
31
+ ' line4\n',
32
+ 'text/code-only',
33
+ );
34
+
35
+ const code = this.editor.getDocument('text/code-only');
36
+ ```
@@ -0,0 +1,5 @@
1
+ export * from './NodeDocumentCode.js';
2
+ export * from './NodeCodeMirror.js';
3
+ export declare class ExtensionCodeMirror {
4
+ }
5
+ //# sourceMappingURL=ExtensionCodeMirror.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtensionCodeMirror.d.ts","sourceRoot":"","sources":["../src/ExtensionCodeMirror.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AAEpC,qBAAa,mBAAmB;CAC/B"}
@@ -0,0 +1,4 @@
1
+ export * from './NodeDocumentCode.js';
2
+ export * from './NodeCodeMirror.js';
3
+ export class ExtensionCodeMirror {
4
+ }
@@ -0,0 +1,27 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ import type { NodeSpec, NodeType, Schema } from 'prosemirror-model';
3
+ import { Converter, type CoreEditor, Node } from '@kerebron/editor';
4
+ import { type Commands, type CommandShortcuts } from '@kerebron/editor/commands';
5
+ import { type InputRule } from '@kerebron/editor/plugins/input-rules';
6
+ export declare const codeMirrorBlockKey: any;
7
+ export declare class NodeCodeMirror extends Node {
8
+ name: string;
9
+ automerge: {
10
+ block: string;
11
+ attrParsers: {
12
+ fromAutomerge: (block: any) => {
13
+ lang: any;
14
+ };
15
+ fromProsemirror: (node: any) => {
16
+ lang: any;
17
+ };
18
+ };
19
+ };
20
+ getConverters(editor: CoreEditor, schema: Schema): Record<string, Converter>;
21
+ getNodeSpec(): NodeSpec;
22
+ getInputRules(type: NodeType): InputRule[];
23
+ getCommands(editor: CoreEditor, type: NodeType): Partial<Commands>;
24
+ getKeyboardShortcuts(): Partial<CommandShortcuts>;
25
+ getProseMirrorPlugins(editor: CoreEditor): Plugin[];
26
+ }
27
+ //# sourceMappingURL=NodeCodeMirror.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeCodeMirror.d.ts","sourceRoot":"","sources":["../src/NodeCodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAwB,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,SAAS,EAEf,MAAM,sCAAsC,CAAC;AAQ9C,eAAO,MAAM,kBAAkB,KAAoC,CAAC;AAoBpE,qBAAa,cAAe,SAAQ,IAAI;IAC7B,IAAI,SAAgB;IAG7B,SAAS;;;;;;;;;;MAMP;IAEO,aAAa,CACpB,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IAgDnB,WAAW,IAAI,QAAQ;IA0BvB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE;IAQ1C,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAUlE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAUjD,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,EAAE;CAiD7D"}
@@ -0,0 +1,186 @@
1
+ import { Plugin, PluginKey, Selection } from 'prosemirror-state';
2
+ import { Node } from '@kerebron/editor';
3
+ import { setBlockType, } from '@kerebron/editor/commands';
4
+ import { textblockTypeInputRule, } from '@kerebron/editor/plugins/input-rules';
5
+ import { codeMirrorBlockNodeView } from './codeMirrorBlockNodeView.js';
6
+ import { defaultSettings } from './defaults.js';
7
+ import languageLoaders, { legacyLanguageLoaders } from './languageLoaders.js';
8
+ import { dracula } from 'thememirror';
9
+ import { createNodeFromObject } from '@kerebron/editor/utilities';
10
+ export const codeMirrorBlockKey = new PluginKey('codemirror-block');
11
+ function arrowHandler(dir) {
12
+ return (state, dispatch, view) => {
13
+ if (state.selection.empty && view.endOfTextblock(dir)) {
14
+ let side = dir == 'left' || dir == 'up' ? -1 : 1;
15
+ let $head = state.selection.$head;
16
+ let nextPos = Selection.near(state.doc.resolve(side > 0 ? $head.after() : $head.before()), side);
17
+ if (nextPos.$head && nextPos.$head.parent.type.name == 'code_block') {
18
+ dispatch(state.tr.setSelection(nextPos));
19
+ return true;
20
+ }
21
+ }
22
+ return false;
23
+ };
24
+ }
25
+ export class NodeCodeMirror extends Node {
26
+ constructor() {
27
+ super(...arguments);
28
+ Object.defineProperty(this, "name", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: 'code_block'
33
+ });
34
+ // requires = ['doc'];
35
+ Object.defineProperty(this, "automerge", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: {
40
+ block: this.name,
41
+ attrParsers: {
42
+ fromAutomerge: (block) => ({ lang: block.attrs.lang }),
43
+ fromProsemirror: (node) => ({ lang: node.attrs.lang }),
44
+ },
45
+ }
46
+ });
47
+ }
48
+ getConverters(editor, schema) {
49
+ return {
50
+ 'text/code-only': {
51
+ fromDoc(document) {
52
+ const retVal = [];
53
+ if (document.content) {
54
+ for (const node of document.content.toJSON()) {
55
+ if ('code_block' === node.type && Array.isArray(node.content)) {
56
+ for (const content of node.content) {
57
+ retVal.push(content.text);
58
+ }
59
+ }
60
+ }
61
+ }
62
+ return retVal.join('');
63
+ },
64
+ toDoc(code) {
65
+ const content = {
66
+ 'type': 'doc_code',
67
+ 'content': [
68
+ {
69
+ 'type': 'code_block',
70
+ 'attrs': {
71
+ 'lang': null,
72
+ },
73
+ 'content': [
74
+ {
75
+ 'type': 'text',
76
+ 'text': code,
77
+ },
78
+ ],
79
+ },
80
+ ],
81
+ };
82
+ return createNodeFromObject(content, schema, {
83
+ slice: false,
84
+ errorOnInvalidContent: false,
85
+ });
86
+ },
87
+ },
88
+ };
89
+ }
90
+ getNodeSpec() {
91
+ return {
92
+ content: 'text*',
93
+ marks: '',
94
+ group: 'block',
95
+ code: true,
96
+ defining: true,
97
+ parseDOM: [
98
+ {
99
+ tag: 'pre',
100
+ preserveWhitespace: 'full',
101
+ getAttrs(dom) {
102
+ return {
103
+ lang: dom.getAttribute('lang'),
104
+ };
105
+ },
106
+ },
107
+ ],
108
+ attrs: { lang: { default: null } },
109
+ toDOM(node) {
110
+ const { lang } = node.attrs;
111
+ return ['pre', { lang }, ['code', 0]];
112
+ },
113
+ };
114
+ }
115
+ getInputRules(type) {
116
+ /// Given a code block node type, returns an input rule that turns a
117
+ /// textblock starting with three backticks into a code block.
118
+ return [
119
+ textblockTypeInputRule(/^```$/, type),
120
+ ];
121
+ }
122
+ getCommands(editor, type) {
123
+ return {
124
+ 'setCodeBlock': (lang) => setBlockType(type, { lang }),
125
+ ArrowLeft: () => arrowHandler('left'),
126
+ ArrowRight: () => arrowHandler('right'),
127
+ ArrowUp: () => arrowHandler('up'),
128
+ ArrowDown: () => arrowHandler('down'),
129
+ };
130
+ }
131
+ getKeyboardShortcuts() {
132
+ return {
133
+ 'Shift-Ctrl-"': 'setCodeBlock',
134
+ 'ArrowLeft': 'ArrowLeft',
135
+ 'ArrowRight': 'ArrowRight',
136
+ 'ArrowUp': 'ArrowUp',
137
+ 'ArrowDown': 'ArrowDown',
138
+ };
139
+ }
140
+ getProseMirrorPlugins(editor) {
141
+ const codeMirrorBlockPlugin = (settings) => new Plugin({
142
+ key: codeMirrorBlockKey,
143
+ props: {
144
+ nodeViews: {
145
+ [this.name]: codeMirrorBlockNodeView(settings),
146
+ },
147
+ },
148
+ });
149
+ const LANGS = [
150
+ 'diff',
151
+ 'dockerfile',
152
+ 'http',
153
+ 'nginx',
154
+ 'properties',
155
+ 'shell',
156
+ 'toml',
157
+ 'yaml',
158
+ 'sql',
159
+ 'javascript',
160
+ 'cpp',
161
+ 'css',
162
+ 'xml',
163
+ 'java',
164
+ 'json',
165
+ 'markdown',
166
+ 'rust',
167
+ 'html',
168
+ ];
169
+ return [
170
+ codeMirrorBlockPlugin({
171
+ provider: this.config.provider,
172
+ ...defaultSettings,
173
+ languageWhitelist: this.config.languageWhitelist || LANGS,
174
+ languageLoaders: { ...languageLoaders, ...legacyLanguageLoaders },
175
+ undo: () => {
176
+ editor.chain().undo().run();
177
+ },
178
+ redo: () => {
179
+ editor.chain().redo().run();
180
+ },
181
+ theme: [dracula],
182
+ }),
183
+ // keymap(codeBlockKeymap),
184
+ ];
185
+ }
186
+ }
@@ -0,0 +1,7 @@
1
+ import { NodeSpec } from 'prosemirror-model';
2
+ import { Node } from '@kerebron/editor';
3
+ export declare class NodeDocumentCode extends Node {
4
+ name: string;
5
+ getNodeSpec(): NodeSpec;
6
+ }
7
+ //# sourceMappingURL=NodeDocumentCode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeDocumentCode.d.ts","sourceRoot":"","sources":["../src/NodeDocumentCode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,qBAAa,gBAAiB,SAAQ,IAAI;IAC/B,IAAI,SAAc;IAElB,WAAW,IAAI,QAAQ;CAsBjC"}
@@ -0,0 +1,34 @@
1
+ import { Node } from '@kerebron/editor';
2
+ export class NodeDocumentCode extends Node {
3
+ constructor() {
4
+ super(...arguments);
5
+ Object.defineProperty(this, "name", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: 'doc_code'
10
+ });
11
+ }
12
+ getNodeSpec() {
13
+ return {
14
+ content: 'code_block',
15
+ EMPTY_DOC: {
16
+ 'type': this.name,
17
+ 'content': [
18
+ {
19
+ 'type': 'code_block',
20
+ 'attrs': {
21
+ 'lang': this.config.lang || null,
22
+ },
23
+ 'content': [
24
+ // {
25
+ // "type": "text",
26
+ // "text": ""
27
+ // }
28
+ ],
29
+ },
30
+ ],
31
+ },
32
+ };
33
+ }
34
+ }
@@ -0,0 +1,6 @@
1
+ import { Node } from 'prosemirror-model';
2
+ import { EditorView as PMEditorView, NodeView } from 'prosemirror-view';
3
+ import { CodeBlockSettings } from './types.js';
4
+ export declare const themeCallbacks: Array<(theme: string) => void>;
5
+ export declare const codeMirrorBlockNodeView: (settings: CodeBlockSettings) => (pmNode: Node, view: PMEditorView, getPos: (() => number) | boolean) => NodeView;
6
+ //# sourceMappingURL=codeMirrorBlockNodeView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codeMirrorBlockNodeView.d.ts","sourceRoot":"","sources":["../src/codeMirrorBlockNodeView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAEL,UAAU,IAAI,YAAY,EAC1B,QAAQ,EACT,MAAM,kBAAkB,CAAC;AA0C1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAO/C,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAM,CAAC;AAuQjE,eAAO,MAAM,uBAAuB,EAAE,CACpC,QAAQ,EAAE,iBAAiB,KACxB,CACH,MAAM,EAAE,IAAI,EACZ,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,OAAO,KAC7B,QAQJ,CAAC"}
@@ -0,0 +1,265 @@
1
+ import { exitCode, selectAll } from '@kerebron/editor/commands';
2
+ import { drawSelection, EditorView as CodeMirror, highlightActiveLine, highlightActiveLineGutter, keymap, lineNumbers, rectangularSelection, } from '@codemirror/view';
3
+ import { highlightSelectionMatches, selectNextOccurrence, } from '@codemirror/search';
4
+ import { bracketMatching, defaultHighlightStyle, foldGutter, foldKeymap, indentOnInput, syntaxHighlighting, } from '@codemirror/language';
5
+ import { autocompletion, closeBrackets, closeBracketsKeymap, completionKeymap, } from '@codemirror/autocomplete';
6
+ import { defaultKeymap, indentWithTab } from '@codemirror/commands';
7
+ import { Compartment, EditorState } from '@codemirror/state';
8
+ import { backspaceHandler, computeChange, forwardSelection, maybeEscape, setMode, setTheme, valueChanged, } from './utils.js';
9
+ import { YSyncConfig, ySyncFacet } from './y-sync.js';
10
+ import { yRemoteSelections, yRemoteSelectionsTheme, } from './y-remote-selections.js';
11
+ export const themeCallbacks = [];
12
+ class CodeMirrorBlockNodeView {
13
+ constructor(node, view, getPos, settings) {
14
+ Object.defineProperty(this, "node", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: node
19
+ });
20
+ Object.defineProperty(this, "view", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: view
25
+ });
26
+ Object.defineProperty(this, "getPos", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: getPos
31
+ });
32
+ Object.defineProperty(this, "settings", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: settings
37
+ });
38
+ Object.defineProperty(this, "dom", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: void 0
43
+ });
44
+ Object.defineProperty(this, "codeMirrorView", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: void 0
49
+ });
50
+ Object.defineProperty(this, "updating", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: void 0
55
+ });
56
+ Object.defineProperty(this, "createCopyButtonCB", {
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true,
60
+ value: void 0
61
+ });
62
+ Object.defineProperty(this, "selectDeleteCB", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: void 0
67
+ });
68
+ Object.defineProperty(this, "languageConf", {
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true,
72
+ value: void 0
73
+ });
74
+ this.updating = false;
75
+ const dom = document.createElement('div');
76
+ this.dom = dom;
77
+ dom.className = 'codeblock-root';
78
+ this.languageConf = new Compartment();
79
+ const themeConfig = new Compartment();
80
+ const yCollab = () => {
81
+ const plugins = [];
82
+ if (settings.provider?.awareness) {
83
+ const ySyncConfig = new YSyncConfig(() => this.node, getPos, settings.provider.awareness);
84
+ plugins.push(ySyncFacet.of(ySyncConfig));
85
+ plugins.push(yRemoteSelectionsTheme, yRemoteSelections);
86
+ }
87
+ return plugins;
88
+ };
89
+ const state = EditorState.create({
90
+ extensions: [
91
+ EditorState.readOnly.of(settings.readOnly),
92
+ CodeMirror.editable.of(!settings.readOnly),
93
+ lineNumbers(),
94
+ highlightActiveLineGutter(),
95
+ foldGutter(),
96
+ bracketMatching(),
97
+ closeBrackets(),
98
+ highlightSelectionMatches(),
99
+ autocompletion(),
100
+ rectangularSelection(),
101
+ drawSelection({ cursorBlinkRate: 1000 }), // broken focus
102
+ EditorState.allowMultipleSelections.of(true),
103
+ highlightActiveLine(),
104
+ syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
105
+ this.languageConf.of([]),
106
+ indentOnInput(),
107
+ keymap.of([
108
+ { key: 'Mod-d', run: selectNextOccurrence, preventDefault: true },
109
+ {
110
+ key: 'ArrowUp',
111
+ run: (cmView) => maybeEscape('line', -1, cmView, view, getPos),
112
+ },
113
+ {
114
+ key: 'ArrowLeft',
115
+ run: (cmView) => maybeEscape('char', -1, cmView, view, getPos),
116
+ },
117
+ {
118
+ key: 'ArrowDown',
119
+ run: (cmView) => maybeEscape('line', 1, cmView, view, getPos),
120
+ },
121
+ {
122
+ key: 'ArrowRight',
123
+ run: (cmView) => maybeEscape('char', 1, cmView, view, getPos),
124
+ },
125
+ {
126
+ key: 'Ctrl-Enter',
127
+ run: () => {
128
+ if (!exitCode(view.state, view.dispatch))
129
+ return false;
130
+ view.focus();
131
+ return true;
132
+ },
133
+ },
134
+ {
135
+ key: 'Mod-z',
136
+ run: () => settings.undo?.(view.state, view.dispatch) || true,
137
+ shift: () => settings.redo?.(view.state, view.dispatch) || true,
138
+ },
139
+ {
140
+ key: 'Mod-y',
141
+ run: () => settings.redo?.(view.state, view.dispatch) || true,
142
+ },
143
+ { key: 'Backspace', run: (cmView) => backspaceHandler(view, cmView) },
144
+ {
145
+ key: 'Mod-Backspace',
146
+ run: (cmView) => backspaceHandler(view, cmView),
147
+ },
148
+ {
149
+ key: 'Mod-a',
150
+ run: () => {
151
+ const result = selectAll(view.state, view.dispatch);
152
+ view.focus();
153
+ return result;
154
+ },
155
+ },
156
+ {
157
+ key: 'Enter',
158
+ run: (cmView) => {
159
+ const sel = cmView.state.selection.main;
160
+ if (cmView.state.doc.line(cmView.state.doc.lines).text === '' &&
161
+ sel.from === sel.to &&
162
+ sel.from === cmView.state.doc.length) {
163
+ exitCode(view.state, view.dispatch);
164
+ view.focus();
165
+ return true;
166
+ }
167
+ return false;
168
+ },
169
+ },
170
+ ...defaultKeymap,
171
+ ...foldKeymap,
172
+ ...closeBracketsKeymap,
173
+ ...completionKeymap,
174
+ indentWithTab,
175
+ ]),
176
+ ...(settings.theme ? settings.theme : []),
177
+ themeConfig.of([]),
178
+ yCollab(),
179
+ ],
180
+ doc: node.textContent,
181
+ });
182
+ this.codeMirrorView = new CodeMirror({
183
+ state,
184
+ dispatch: (tr) => {
185
+ this.codeMirrorView.update([tr]);
186
+ if (!this.updating) {
187
+ const textUpdate = tr.state.toJSON().doc;
188
+ valueChanged(textUpdate, this.node, getPos, view);
189
+ forwardSelection(this.codeMirrorView, view, getPos);
190
+ }
191
+ },
192
+ });
193
+ dom.append(this.codeMirrorView.dom);
194
+ if (!(Array.isArray(settings.languageWhitelist) &&
195
+ settings.languageWhitelist.length === 1)) {
196
+ this.selectDeleteCB = settings.createSelect(settings, dom, node, view, getPos);
197
+ }
198
+ this.createCopyButtonCB = settings.createCopyButton(settings, dom, node, view, this.codeMirrorView, getPos);
199
+ setMode(node.attrs.lang, this.codeMirrorView, settings, this.languageConf);
200
+ const currentTheme = settings.getCurrentTheme?.();
201
+ setTheme(this.codeMirrorView, themeConfig, [
202
+ settings.themes.find((t) => t.name === currentTheme),
203
+ ]);
204
+ this.updateTheme = (theme) => {
205
+ setTheme(this.codeMirrorView, themeConfig, [
206
+ settings.themes.find((t) => t.name === theme),
207
+ ]);
208
+ };
209
+ themeCallbacks.push(this.updateTheme);
210
+ }
211
+ updateTheme(updateTheme) {
212
+ throw new Error('Method not implemented.');
213
+ }
214
+ selectNode() {
215
+ this.codeMirrorView.focus();
216
+ }
217
+ stopEvent(e) {
218
+ return this.settings.stopEvent(e, this.node, this.getPos, this.view, this.dom);
219
+ }
220
+ setSelection(anchor, head) {
221
+ this.codeMirrorView.focus();
222
+ this.updating = true;
223
+ this.codeMirrorView.dispatch({ selection: { anchor, head } });
224
+ this.updating = false;
225
+ }
226
+ update(updateNode) {
227
+ if (updateNode.type.name !== this.node.type.name)
228
+ return false;
229
+ if (updateNode.attrs.lang !== this.node.attrs.lang) {
230
+ setMode(updateNode.attrs.lang, this.codeMirrorView, this.settings, this.languageConf);
231
+ }
232
+ const oldNode = this.node;
233
+ this.node = updateNode;
234
+ const change = computeChange(this.codeMirrorView.state.doc.toString(), this.node.textContent);
235
+ if (change) {
236
+ this.updating = true;
237
+ this.codeMirrorView.dispatch({
238
+ changes: {
239
+ from: change.from,
240
+ to: change.to,
241
+ insert: change.text,
242
+ },
243
+ selection: { anchor: change.from + change.text.length },
244
+ });
245
+ this.updating = false;
246
+ }
247
+ this.settings.updateSelect(this.settings, this.dom, updateNode, this.view, this.getPos, oldNode);
248
+ return true;
249
+ }
250
+ ignoreMutation() {
251
+ return true;
252
+ }
253
+ destroy() {
254
+ if (this.selectDeleteCB) {
255
+ this.selectDeleteCB();
256
+ }
257
+ this.createCopyButtonCB();
258
+ themeCallbacks.splice(themeCallbacks.indexOf(this.updateTheme), 1);
259
+ }
260
+ }
261
+ export const codeMirrorBlockNodeView = (settings) => {
262
+ return (pmNode, view, getPos) => {
263
+ return new CodeMirrorBlockNodeView(pmNode, view, getPos, settings);
264
+ };
265
+ };
@@ -0,0 +1,6 @@
1
+ import { Node } from 'prosemirror-model';
2
+ import { EditorView } from 'prosemirror-view';
3
+ import { CodeBlockSettings } from './types.js';
4
+ export declare const defaultCreateSelect: (settings: CodeBlockSettings, dom: HTMLElement, node: Node, view: EditorView, getPos: (() => number) | boolean) => () => void;
5
+ export declare const defaultSettings: CodeBlockSettings;
6
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,eAAO,MAAM,mBAAmB,aACpB,iBAAiB,OACtB,WAAW,QACV,IAAI,QACJ,UAAU,UACR,CAAC,MAAM,MAAM,CAAC,GAAG,OAAO,eAwCjC,CAAC;AAmBF,eAAO,MAAM,eAAe,EAAE,iBAS7B,CAAC"}