@kerebron/extension-codemirror 0.4.26 → 0.4.27

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.
Files changed (57) hide show
  1. package/package.json +6 -5
  2. package/assets/codemirror.css +0 -80
  3. package/esm/ExtensionCodeMirror.d.ts +0 -17
  4. package/esm/ExtensionCodeMirror.d.ts.map +0 -1
  5. package/esm/ExtensionCodeMirror.js +0 -61
  6. package/esm/NodeCodeMirror.d.ts +0 -20
  7. package/esm/NodeCodeMirror.d.ts.map +0 -1
  8. package/esm/NodeCodeMirror.js +0 -95
  9. package/esm/codeMirrorBlockNodeView.d.ts +0 -7
  10. package/esm/codeMirrorBlockNodeView.d.ts.map +0 -1
  11. package/esm/codeMirrorBlockNodeView.js +0 -268
  12. package/esm/defaults.d.ts +0 -6
  13. package/esm/defaults.d.ts.map +0 -1
  14. package/esm/defaults.js +0 -58
  15. package/esm/languageLoaders.d.ts +0 -5
  16. package/esm/languageLoaders.d.ts.map +0 -1
  17. package/esm/languageLoaders.js +0 -112
  18. package/esm/languages.d.ts +0 -109
  19. package/esm/languages.d.ts.map +0 -1
  20. package/esm/languages.js +0 -110
  21. package/esm/lsp/LSPExtension.d.ts +0 -14
  22. package/esm/lsp/LSPExtension.d.ts.map +0 -1
  23. package/esm/lsp/LSPExtension.js +0 -29
  24. package/esm/lsp/completion.d.ts +0 -8
  25. package/esm/lsp/completion.d.ts.map +0 -1
  26. package/esm/lsp/completion.js +0 -179
  27. package/esm/lsp/hover.d.ts +0 -5
  28. package/esm/lsp/hover.d.ts.map +0 -1
  29. package/esm/lsp/hover.js +0 -81
  30. package/esm/lsp/index.d.ts +0 -7
  31. package/esm/lsp/index.d.ts.map +0 -1
  32. package/esm/lsp/index.js +0 -49
  33. package/esm/lsp/plugin.d.ts +0 -37
  34. package/esm/lsp/plugin.d.ts.map +0 -1
  35. package/esm/lsp/plugin.js +0 -86
  36. package/esm/lsp/pos.d.ts +0 -5
  37. package/esm/lsp/pos.d.ts.map +0 -1
  38. package/esm/lsp/pos.js +0 -8
  39. package/esm/lsp/text.d.ts +0 -2
  40. package/esm/lsp/text.d.ts.map +0 -1
  41. package/esm/lsp/text.js +0 -47
  42. package/esm/lsp/theme.d.ts +0 -2
  43. package/esm/lsp/theme.d.ts.map +0 -1
  44. package/esm/lsp/theme.js +0 -76
  45. package/esm/package.json +0 -3
  46. package/esm/remote-selections.d.ts +0 -15
  47. package/esm/remote-selections.d.ts.map +0 -1
  48. package/esm/remote-selections.js +0 -225
  49. package/esm/remote-sync.d.ts +0 -11
  50. package/esm/remote-sync.d.ts.map +0 -1
  51. package/esm/remote-sync.js +0 -17
  52. package/esm/types.d.ts +0 -30
  53. package/esm/types.d.ts.map +0 -1
  54. package/esm/types.js +0 -1
  55. package/esm/utils.d.ts +0 -40
  56. package/esm/utils.d.ts.map +0 -1
  57. package/esm/utils.js +0 -210
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kerebron/extension-codemirror",
3
- "version": "0.4.26",
3
+ "version": "0.4.27",
4
4
  "license": "MIT",
5
5
  "module": "./esm/ExtensionCodeMirror.js",
6
6
  "exports": {
@@ -12,6 +12,7 @@
12
12
  }
13
13
  },
14
14
  "scripts": {},
15
+ "files": [],
15
16
  "dependencies": {
16
17
  "@codemirror/autocomplete": "6.18.6",
17
18
  "@codemirror/commands": "6.8.1",
@@ -34,10 +35,10 @@
34
35
  "@codemirror/search": "6.5.10",
35
36
  "@codemirror/state": "6.5.2",
36
37
  "@codemirror/view": "6.38.1",
37
- "@kerebron/editor": "0.4.26",
38
- "@kerebron/extension-basic-editor": "0.4.26",
39
- "@kerebron/extension-lsp": "0.4.26",
40
- "@kerebron/extension-markdown": "0.4.26",
38
+ "@kerebron/editor": "0.4.27",
39
+ "@kerebron/extension-basic-editor": "0.4.27",
40
+ "@kerebron/extension-lsp": "0.4.27",
41
+ "@kerebron/extension-markdown": "0.4.27",
41
42
  "lib0": "0.2.109",
42
43
  "prosemirror-model": "1.25.3",
43
44
  "prosemirror-state": "1.4.3",
@@ -1,80 +0,0 @@
1
- .codeblock-select {
2
- position: absolute;
3
- right: 0;
4
- z-index: 100;
5
- opacity: 0;
6
- transition: all 0.3s ease;
7
- margin: 6px 14px;
8
- }
9
-
10
- .codeblock-root {
11
- position: relative;
12
- }
13
-
14
- .codeblock-root:hover .codeblock-select {
15
- opacity: 1;
16
- }
17
-
18
- /* Code block mobile optimization */
19
- @media (max-width: 767px) {
20
- .kb-editor pre {
21
- font-size: var(--kb-text-sm);
22
- overflow-x: auto;
23
- -webkit-overflow-scrolling: touch;
24
- }
25
-
26
- .codeblock-select {
27
- opacity: 1;
28
- position: static;
29
- margin: var(--kb-space-sm);
30
- display: flex;
31
- justify-content: flex-end;
32
- }
33
-
34
- .codeblock-select select {
35
- min-height: var(--kb-touch-target-min);
36
- padding: var(--kb-space-sm);
37
- border: 1px solid var(--kb-color-border);
38
- border-radius: var(--kb-radius-sm);
39
- background: var(--kb-color-surface);
40
- color: var(--kb-color-text);
41
- }
42
- }
43
-
44
- .kb-yjs__cursor {
45
- position: fixed;
46
- margin-left: -1px;
47
- margin-right: -1px;
48
- /*border-left: 1px solid black;*/
49
- /*border-right: 1px solid black;*/
50
- /*border-color: orange;*/
51
- word-break: normal;
52
- pointer-events: none;
53
- }
54
-
55
- /* This renders the username above the caret */
56
- .kb-yjs__cursor > div {
57
- position: absolute;
58
- top: -1.05em;
59
- left: -1px;
60
- font-size: 13px;
61
- background-color: rgb(250, 129, 0);
62
- font-family: serif;
63
- font-style: normal;
64
- font-weight: normal;
65
- line-height: normal;
66
- user-select: none;
67
- color: white;
68
- padding-left: 2px;
69
- padding-right: 2px;
70
- white-space: nowrap;
71
- }
72
-
73
- /* Collaborative cursor optimization for mobile */
74
- @media (max-width: 767px) {
75
- .kb-yjs__cursor > div {
76
- font-size: var(--kb-text-xs);
77
- padding: 1px var(--kb-space-xs);
78
- border-radius: var(--kb-radius-sm);
79
- }
80
- }
@@ -1,17 +0,0 @@
1
- import { Schema } from 'prosemirror-model';
2
- import { AnyExtensionOrReq, type Converter, type CoreEditor, Extension } from '@kerebron/editor';
3
- import { NodeCodeMirrorConfig } from './NodeCodeMirror.js';
4
- export * from './NodeCodeMirror.js';
5
- export interface ExtensionCodeMirrorConfig {
6
- languageWhitelist?: NodeCodeMirrorConfig['languageWhitelist'];
7
- theme?: NodeCodeMirrorConfig['theme'];
8
- readOnly?: boolean;
9
- }
10
- export declare class ExtensionCodeMirror extends Extension {
11
- protected config: ExtensionCodeMirrorConfig;
12
- name: string;
13
- requires: AnyExtensionOrReq[];
14
- constructor(config: ExtensionCodeMirrorConfig);
15
- getConverters(editor: CoreEditor, schema: Schema): Record<string, Converter>;
16
- }
17
- //# sourceMappingURL=ExtensionCodeMirror.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExtensionCodeMirror.d.ts","sourceRoot":"","sources":["../src/ExtensionCodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EACL,iBAAiB,EACjB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,SAAS,EACV,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAkB,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3E,cAAc,qBAAqB,CAAC;AAEpC,MAAM,WAAW,yBAAyB;IACxC,iBAAiB,CAAC,EAAE,oBAAoB,CAAC,mBAAmB,CAAC,CAAC;IAC9D,KAAK,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,mBAAoB,SAAQ,SAAS;cAIjB,MAAM,EAAE,yBAAyB;IAHvD,IAAI,SAAiB;IAC9B,QAAQ,EAAE,iBAAiB,EAAE,CAAC;gBAEC,MAAM,EAAE,yBAAyB;IAWvD,aAAa,CACpB,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;CA+C7B"}
@@ -1,61 +0,0 @@
1
- import { Extension, } from '@kerebron/editor';
2
- import { createNodeFromObject } from '@kerebron/editor/utilities';
3
- import { NodeCodeMirror } from './NodeCodeMirror.js';
4
- export * from './NodeCodeMirror.js';
5
- export class ExtensionCodeMirror extends Extension {
6
- config;
7
- name = 'code-mirror';
8
- requires;
9
- constructor(config) {
10
- super(config);
11
- this.config = config;
12
- this.requires = [
13
- new NodeCodeMirror({
14
- languageWhitelist: config.languageWhitelist,
15
- theme: config.theme,
16
- }),
17
- ];
18
- }
19
- getConverters(editor, schema) {
20
- return {
21
- 'text/code-only': {
22
- fromDoc: async (document) => {
23
- const retVal = [];
24
- if (document.content) {
25
- for (const node of document.content.toJSON()) {
26
- if ('code_block' === node.type && Array.isArray(node.content)) {
27
- for (const content of node.content) {
28
- retVal.push(content.text);
29
- }
30
- }
31
- }
32
- }
33
- return new TextEncoder().encode(retVal.join(''));
34
- },
35
- toDoc: async (buffer) => {
36
- const code = new TextDecoder().decode(buffer);
37
- const content = {
38
- 'type': 'doc_code',
39
- 'content': [
40
- {
41
- 'type': 'code_block',
42
- 'attrs': {
43
- 'lang': schema.topNodeType.spec.defaultAttrs?.lang,
44
- },
45
- 'content': [
46
- {
47
- 'type': 'text',
48
- 'text': code,
49
- },
50
- ],
51
- },
52
- ],
53
- };
54
- return createNodeFromObject(content, schema, {
55
- errorOnInvalidContent: false,
56
- });
57
- },
58
- },
59
- };
60
- }
61
- }
@@ -1,20 +0,0 @@
1
- import { Plugin, PluginKey } from 'prosemirror-state';
2
- import type { NodeType } from 'prosemirror-model';
3
- import { type CoreEditor } from '@kerebron/editor';
4
- import { type CommandFactories, type CommandShortcuts } from '@kerebron/editor/commands';
5
- import { NodeCodeBlock } from '@kerebron/extension-basic-editor/NodeCodeBlock';
6
- import { CodeBlockSettings } from './types.js';
7
- export declare const codeMirrorBlockKey: PluginKey<any>;
8
- export interface NodeCodeMirrorConfig {
9
- readOnly?: boolean;
10
- languageWhitelist?: CodeBlockSettings['languageWhitelist'];
11
- theme?: CodeBlockSettings['theme'];
12
- }
13
- export declare class NodeCodeMirror extends NodeCodeBlock {
14
- config: NodeCodeMirrorConfig;
15
- constructor(config: NodeCodeMirrorConfig);
16
- getCommandFactories(editor: CoreEditor, type: NodeType): Partial<CommandFactories>;
17
- getKeyboardShortcuts(): Partial<CommandShortcuts>;
18
- getProseMirrorPlugins(): Plugin[];
19
- }
20
- //# sourceMappingURL=NodeCodeMirror.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NodeCodeMirror.d.ts","sourceRoot":"","sources":["../src/NodeCodeMirror.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,MAAM,EACN,SAAS,EAGV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAE/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAK/C,eAAO,MAAM,kBAAkB,gBAAoC,CAAC;AA+CpE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;IAC3D,KAAK,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;CACpC;AAED,qBAAa,cAAe,SAAQ,aAAa;IAC1B,MAAM,EAAE,oBAAoB;gBAA5B,MAAM,EAAE,oBAAoB;IAIxC,mBAAmB,CAC1B,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,gBAAgB,CAAC;IAWnB,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAUjD,qBAAqB,IAAI,MAAM,EAAE;CA6B3C"}
@@ -1,95 +0,0 @@
1
- import { Plugin, PluginKey, Selection, } from 'prosemirror-state';
2
- import { getShadowRoot } from '@kerebron/editor/utilities';
3
- import { NodeCodeBlock } from '@kerebron/extension-basic-editor/NodeCodeBlock';
4
- import { codeMirrorBlockNodeView } from './codeMirrorBlockNodeView.js';
5
- import { defaultSettings } from './defaults.js';
6
- import languageLoaders, { legacyLanguageLoaders } from './languageLoaders.js';
7
- export const codeMirrorBlockKey = new PluginKey('codemirror-block');
8
- function arrowHandler(dir) {
9
- return (state, dispatch, view) => {
10
- if (state.selection.empty && view && view.endOfTextblock(dir)) {
11
- let side = dir == 'left' || dir == 'up' ? -1 : 1;
12
- let $head = state.selection.$head;
13
- let nextPos = Selection.near(state.doc.resolve(side > 0 ? $head.after() : $head.before()), side);
14
- if (nextPos.$head && nextPos.$head.parent.type.name == 'code_block') {
15
- if (dispatch) {
16
- dispatch(state.tr.setSelection(nextPos));
17
- }
18
- return true;
19
- }
20
- }
21
- return false;
22
- };
23
- }
24
- const LANGS = [
25
- 'diff',
26
- 'dockerfile',
27
- 'http',
28
- 'nginx',
29
- 'properties',
30
- 'shell',
31
- 'toml',
32
- 'yaml',
33
- 'sql',
34
- 'javascript',
35
- 'cpp',
36
- 'css',
37
- 'xml',
38
- 'java',
39
- 'json',
40
- 'markdown',
41
- 'rust',
42
- 'html',
43
- ];
44
- export class NodeCodeMirror extends NodeCodeBlock {
45
- config;
46
- constructor(config) {
47
- super(config);
48
- this.config = config;
49
- }
50
- getCommandFactories(editor, type) {
51
- return {
52
- 'setCodeBlock': (lang) => editor.commandFactories.setBlockType(type, { lang }),
53
- ArrowLeft: () => arrowHandler('left'),
54
- ArrowRight: () => arrowHandler('right'),
55
- ArrowUp: () => arrowHandler('up'),
56
- ArrowDown: () => arrowHandler('down'),
57
- };
58
- }
59
- getKeyboardShortcuts() {
60
- return {
61
- 'Shift-Ctrl-"': 'setCodeBlock',
62
- 'ArrowLeft': 'ArrowLeft',
63
- 'ArrowRight': 'ArrowRight',
64
- 'ArrowUp': 'ArrowUp',
65
- 'ArrowDown': 'ArrowDown',
66
- };
67
- }
68
- getProseMirrorPlugins() {
69
- const shadowRoot = getShadowRoot(this.editor.config.element);
70
- const settings = {
71
- languageWhitelist: this.config.languageWhitelist || LANGS,
72
- shadowRoot,
73
- ...defaultSettings,
74
- readOnly: this.editor.config.readOnly || this.config.readOnly,
75
- languageLoaders: { ...languageLoaders, ...legacyLanguageLoaders },
76
- undo: () => {
77
- this.editor.chain().undo().run();
78
- },
79
- redo: () => {
80
- this.editor.chain().redo().run();
81
- },
82
- theme: [...(this.config.theme || [])],
83
- };
84
- return [
85
- new Plugin({
86
- key: codeMirrorBlockKey,
87
- props: {
88
- nodeViews: {
89
- [this.name]: codeMirrorBlockNodeView(settings, this.editor),
90
- },
91
- },
92
- }),
93
- ];
94
- }
95
- }
@@ -1,7 +0,0 @@
1
- import { Node } from 'prosemirror-model';
2
- import { Decoration, DecorationSource, EditorView, NodeView } from 'prosemirror-view';
3
- import { CoreEditor } from '@kerebron/editor';
4
- import { CodeBlockSettings } from './types.js';
5
- export declare const themeCallbacks: Array<(theme: string) => void>;
6
- export declare const codeMirrorBlockNodeView: (settings: CodeBlockSettings, editor: CoreEditor) => (node: Node, view: EditorView, getPos: () => number | undefined, decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView;
7
- //# sourceMappingURL=codeMirrorBlockNodeView.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codeMirrorBlockNodeView.d.ts","sourceRoot":"","sources":["../src/codeMirrorBlockNodeView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,UAAU,EAEV,QAAQ,EACT,MAAM,kBAAkB,CAAC;AA8B1B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAY9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAS/C,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAM,CAAC;AAoUjE,eAAO,MAAM,uBAAuB,EAAE,CACpC,QAAQ,EAAE,iBAAiB,EAC3B,MAAM,EAAE,UAAU,KACf,CACH,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS,EAChC,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,gBAAgB,EAAE,gBAAgB,KAC/B,QAQJ,CAAC"}
@@ -1,268 +0,0 @@
1
- import { drawSelection, EditorView as CodeMirror, highlightActiveLineGutter, keymap, lineNumbers, rectangularSelection, } from '@codemirror/view';
2
- import { selectNextOccurrence } from '@codemirror/search';
3
- import { bracketMatching, defaultHighlightStyle, foldGutter, foldKeymap, indentOnInput, syntaxHighlighting, } from '@codemirror/language';
4
- import { autocompletion, closeBrackets, closeBracketsKeymap, completionKeymap, } from '@codemirror/autocomplete';
5
- import { defaultKeymap, indentWithTab } from '@codemirror/commands';
6
- import { Compartment, EditorState } from '@codemirror/state';
7
- import { backspaceHandler, computeChange, forwardSelection, maybeEscape, setMode, setTheme, valueChanged, } from './utils.js';
8
- import { RemoteSyncConfig, remoteSyncFacet } from './remote-sync.js';
9
- import { yRemoteSelections, yRemoteSelectionsTheme, } from './remote-selections.js';
10
- import { languageServerExtensions, LSPPlugin } from './lsp/index.js';
11
- import { LSPExtension } from './lsp/LSPExtension.js';
12
- export const themeCallbacks = [];
13
- class CodeMirrorBlockNodeView {
14
- node;
15
- view;
16
- getPos;
17
- settings;
18
- editor;
19
- dom;
20
- codeMirrorView;
21
- updating;
22
- createCopyButtonCB;
23
- selectDeleteCB;
24
- languageConf;
25
- uri = 'file:///' + Math.random() + '.ts';
26
- diagListener;
27
- constructor(node, view, getPos, settings, editor) {
28
- this.node = node;
29
- this.view = view;
30
- this.getPos = getPos;
31
- this.settings = settings;
32
- this.editor = editor;
33
- this.updating = false;
34
- const dom = document.createElement('div');
35
- this.dom = dom;
36
- dom.className = 'codeblock-root';
37
- this.languageConf = new Compartment();
38
- const themeConfig = new Compartment();
39
- const yCollab = () => {
40
- const plugins = [];
41
- const remoteSyncConfig = new RemoteSyncConfig(() => this.node, getPos, editor);
42
- plugins.push(remoteSyncFacet.of(remoteSyncConfig));
43
- plugins.push(yRemoteSelectionsTheme, yRemoteSelections);
44
- return plugins;
45
- };
46
- const extensions = [
47
- EditorState.readOnly.of(!!settings.readOnly),
48
- CodeMirror.editable.of(!settings.readOnly),
49
- lineNumbers(),
50
- highlightActiveLineGutter(),
51
- foldGutter(),
52
- bracketMatching(),
53
- closeBrackets(),
54
- rectangularSelection(),
55
- drawSelection({ cursorBlinkRate: 1000 }), // broken focus
56
- syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
57
- this.languageConf.of([]),
58
- indentOnInput(),
59
- keymap.of([
60
- { key: 'Mod-d', run: selectNextOccurrence, preventDefault: true },
61
- {
62
- key: 'ArrowUp',
63
- run: (cmView) => maybeEscape('line', -1, cmView, view, getPos),
64
- },
65
- {
66
- key: 'ArrowLeft',
67
- run: (cmView) => maybeEscape('char', -1, cmView, view, getPos),
68
- },
69
- {
70
- key: 'ArrowDown',
71
- run: (cmView) => maybeEscape('line', 1, cmView, view, getPos),
72
- },
73
- {
74
- key: 'ArrowRight',
75
- run: (cmView) => maybeEscape('char', 1, cmView, view, getPos),
76
- },
77
- {
78
- key: 'Ctrl-Enter',
79
- run: () => {
80
- if (!editor.run.exitCode()) {
81
- return false;
82
- }
83
- view.focus();
84
- return true;
85
- },
86
- },
87
- {
88
- key: 'Mod-z',
89
- run: () => settings.undo?.(view.state, view.dispatch) || true,
90
- shift: () => settings.redo?.(view.state, view.dispatch) || true,
91
- },
92
- {
93
- key: 'Mod-y',
94
- run: () => settings.redo?.(view.state, view.dispatch) || true,
95
- },
96
- {
97
- key: 'Backspace',
98
- run: (cmView) => backspaceHandler(view, cmView, editor),
99
- },
100
- {
101
- key: 'Mod-Backspace',
102
- run: (cmView) => backspaceHandler(view, cmView, editor),
103
- },
104
- {
105
- key: 'Mod-a',
106
- run: () => {
107
- const result = editor.run.selectAll();
108
- view.focus();
109
- return result;
110
- },
111
- },
112
- ...defaultKeymap,
113
- ...foldKeymap,
114
- ...closeBracketsKeymap,
115
- ...completionKeymap,
116
- indentWithTab,
117
- {
118
- key: 'Ctrl-`',
119
- run: () => {
120
- editor.chain().toggleDevToolkit().run();
121
- return true;
122
- },
123
- },
124
- ]),
125
- ...(settings.theme ? settings.theme : []),
126
- themeConfig.of([]),
127
- yCollab(),
128
- ];
129
- const extensionLsp = editor.getExtension('lsp');
130
- if (extensionLsp) {
131
- const extension = new LSPExtension({
132
- getPos: this.getPos,
133
- extensions: languageServerExtensions(),
134
- });
135
- extensions.push(extension.plugin(extensionLsp, editor));
136
- }
137
- else {
138
- // Define custom completions
139
- const myCompletions = [
140
- { label: 'console.log', type: 'function' },
141
- { label: 'const', type: 'keyword' },
142
- { label: 'let', type: 'keyword' },
143
- { label: 'var', type: 'keyword' },
144
- { label: 'function', type: 'keyword' },
145
- ];
146
- // Custom autocomplete function
147
- const complete = (context) => {
148
- let word = context.matchBefore(/\w*/);
149
- if (!word) {
150
- return null;
151
- }
152
- if (word.from == word.to && !context.explicit)
153
- return null;
154
- return {
155
- from: word.from,
156
- options: myCompletions,
157
- };
158
- };
159
- extensions.push(autocompletion({
160
- override: [
161
- complete,
162
- ],
163
- }));
164
- }
165
- const state = EditorState.create({
166
- extensions,
167
- doc: node.textContent,
168
- });
169
- const root = (editor.view && 'root' in editor.view)
170
- ? editor.view.root
171
- : document || document;
172
- this.codeMirrorView = new CodeMirror({
173
- state,
174
- root,
175
- dispatch: (tr) => {
176
- this.codeMirrorView.update([tr]);
177
- if (!this.updating) {
178
- const textUpdate = tr.state.toJSON().doc;
179
- valueChanged(textUpdate, this.node, getPos, view);
180
- forwardSelection(this.codeMirrorView, view, getPos);
181
- const lspPlugin = LSPPlugin.get(this.codeMirrorView);
182
- if (lspPlugin) {
183
- lspPlugin.update();
184
- }
185
- }
186
- },
187
- });
188
- dom.append(this.codeMirrorView.dom);
189
- if (!(Array.isArray(settings.languageWhitelist) &&
190
- settings.languageWhitelist.length === 1)) {
191
- this.selectDeleteCB = settings.createSelect(settings, dom, node, view, getPos);
192
- }
193
- this.createCopyButtonCB = settings.createCopyButton(settings, dom, node, view, this.codeMirrorView, getPos);
194
- setMode(node.attrs.lang, this.codeMirrorView, settings, this.languageConf);
195
- const currentTheme = settings.getCurrentTheme?.();
196
- setTheme(this.codeMirrorView, themeConfig, [
197
- settings.themes.find((t) => t.name === currentTheme),
198
- ]);
199
- this.updateTheme = (theme) => {
200
- setTheme(this.codeMirrorView, themeConfig, [
201
- settings.themes.find((t) => t.name === theme),
202
- ]);
203
- };
204
- themeCallbacks.push(this.updateTheme);
205
- }
206
- updateTheme(updateTheme) {
207
- throw new Error('Method not implemented.');
208
- }
209
- selectNode() {
210
- this.codeMirrorView.focus();
211
- }
212
- stopEvent(e) {
213
- return this.settings.stopEvent(e, this.node, this.getPos, this.view, this.dom);
214
- }
215
- setSelection(anchor, head) {
216
- this.codeMirrorView.focus();
217
- this.updating = true;
218
- this.codeMirrorView.dispatch({ selection: { anchor, head } });
219
- this.updating = false;
220
- }
221
- update(updateNode, decorations, innerDecorations) {
222
- const codeDecorations = [];
223
- innerDecorations
224
- .forEachSet((set) => set.find()
225
- .map((d) => {
226
- codeDecorations.push(d);
227
- }));
228
- // https://codemirror.net/examples/decoration/
229
- if (updateNode.type.name !== this.node.type.name)
230
- return false;
231
- if (updateNode.attrs.lang !== this.node.attrs.lang) {
232
- setMode(updateNode.attrs.lang, this.codeMirrorView, this.settings, this.languageConf);
233
- }
234
- const oldNode = this.node;
235
- this.node = updateNode;
236
- const change = computeChange(this.codeMirrorView.state.doc.toString(), this.node.textContent);
237
- if (change) {
238
- this.updating = true;
239
- this.codeMirrorView.dispatch({
240
- changes: {
241
- from: change.from,
242
- to: change.to,
243
- insert: change.text,
244
- },
245
- selection: { anchor: change.from + change.text.length },
246
- // effects <- codeDecorations
247
- });
248
- this.updating = false;
249
- }
250
- this.settings.updateSelect(this.settings, this.dom, updateNode, this.view, this.getPos, oldNode);
251
- return true;
252
- }
253
- ignoreMutation() {
254
- return true;
255
- }
256
- destroy() {
257
- if (this.selectDeleteCB) {
258
- this.selectDeleteCB();
259
- }
260
- this.createCopyButtonCB();
261
- themeCallbacks.splice(themeCallbacks.indexOf(this.updateTheme), 1);
262
- }
263
- }
264
- export const codeMirrorBlockNodeView = (settings, editor) => {
265
- return (pmNode, view, getPos) => {
266
- return new CodeMirrorBlockNodeView(pmNode, view, getPos, settings, editor);
267
- };
268
- };
package/esm/defaults.d.ts DELETED
@@ -1,6 +0,0 @@
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 | undefined) => () => void;
5
- export declare const defaultSettings: CodeBlockSettings;
6
- //# sourceMappingURL=defaults.d.ts.map
@@ -1 +0,0 @@
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,GAC9B,UAAU,iBAAiB,EAC3B,KAAK,WAAW,EAChB,MAAM,IAAI,EACV,MAAM,UAAU,EAChB,QAAQ,MAAM,MAAM,GAAG,SAAS,eAyCjC,CAAC;AAmBF,eAAO,MAAM,eAAe,EAAE,iBAS7B,CAAC"}
package/esm/defaults.js DELETED
@@ -1,58 +0,0 @@
1
- export const defaultCreateSelect = (settings, dom, node, view, getPos) => {
2
- if (!settings.languageLoaders)
3
- return () => { };
4
- const { languageLoaders } = settings;
5
- const select = document.createElement('select');
6
- select.className = 'codeblock-select';
7
- const noneOption = document.createElement('option');
8
- noneOption.value = 'none';
9
- noneOption.textContent = settings.languageNameMap?.none || 'none';
10
- select.append(noneOption);
11
- Object.keys(languageLoaders)
12
- .sort()
13
- .forEach((lang) => {
14
- if (settings.languageWhitelist &&
15
- !settings.languageWhitelist.includes(lang)) {
16
- return;
17
- }
18
- const option = document.createElement('option');
19
- option.value = lang;
20
- option.textContent = settings.languageNameMap?.[lang] || lang;
21
- select.append(option);
22
- });
23
- select.value = node.attrs.lang || 'none';
24
- dom.prepend(select);
25
- select.onchange = (e) => {
26
- if (!(e.target instanceof HTMLSelectElement))
27
- return;
28
- const lang = e.target.value;
29
- const pos = getPos();
30
- if (pos) {
31
- view.dispatch(view.state.tr.setNodeMarkup(pos, undefined, {
32
- ...node.attrs,
33
- lang,
34
- }));
35
- }
36
- };
37
- // Delete code.
38
- return () => { };
39
- };
40
- const defaultUpdateSelect = (settings, dom, node, view, getPos, oldNode) => {
41
- if (oldNode.attrs.lang !== node.attrs.lang) {
42
- const select = dom.querySelector('.codeblock-select');
43
- if (!(select instanceof HTMLSelectElement))
44
- return;
45
- select.value = node.attrs.lang || 'none';
46
- }
47
- };
48
- const defaultStopEvent = () => true;
49
- export const defaultSettings = {
50
- createSelect: defaultCreateSelect,
51
- updateSelect: defaultUpdateSelect,
52
- createCopyButton: () => {
53
- return () => { };
54
- },
55
- stopEvent: defaultStopEvent,
56
- readOnly: false,
57
- themes: [],
58
- };
@@ -1,5 +0,0 @@
1
- import { LanguageLoaders } from './types.js';
2
- declare const languageLoaders: LanguageLoaders;
3
- export declare const legacyLanguageLoaders: LanguageLoaders;
4
- export default languageLoaders;
5
- //# sourceMappingURL=languageLoaders.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"languageLoaders.d.ts","sourceRoot":"","sources":["../src/languageLoaders.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,QAAA,MAAM,eAAe,EAAE,eA6BtB,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,eAyWnC,CAAC;AAEF,eAAe,eAAe,CAAC"}