@kerebron/extension-codemirror 0.2.0 → 0.3.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/README.md +4 -3
- package/esm/editor/src/CoreEditor.d.ts +31 -0
- package/esm/editor/src/CoreEditor.d.ts.map +1 -0
- package/esm/editor/src/CoreEditor.js +198 -0
- package/esm/editor/src/DummyEditorView.d.ts +60 -0
- package/esm/editor/src/DummyEditorView.d.ts.map +1 -0
- package/esm/editor/src/DummyEditorView.js +277 -0
- package/esm/editor/src/Extension.d.ts +26 -0
- package/esm/editor/src/Extension.d.ts.map +1 -0
- package/esm/editor/src/Extension.js +33 -0
- package/esm/editor/src/ExtensionManager.d.ts +33 -0
- package/esm/editor/src/ExtensionManager.d.ts.map +1 -0
- package/esm/editor/src/ExtensionManager.js +272 -0
- package/esm/editor/src/Mark.d.ts +20 -0
- package/esm/editor/src/Mark.d.ts.map +1 -0
- package/esm/editor/src/Mark.js +40 -0
- package/esm/editor/src/Node.d.ts +29 -0
- package/esm/editor/src/Node.d.ts.map +1 -0
- package/esm/editor/src/Node.js +49 -0
- package/esm/editor/src/commands/CommandManager.d.ts +16 -0
- package/esm/editor/src/commands/CommandManager.d.ts.map +1 -0
- package/esm/editor/src/commands/CommandManager.js +61 -0
- package/esm/editor/src/commands/createChainableState.d.ts +3 -0
- package/esm/editor/src/commands/createChainableState.d.ts.map +1 -0
- package/esm/editor/src/commands/createChainableState.js +29 -0
- package/esm/editor/src/commands/mod.d.ts +55 -0
- package/esm/editor/src/commands/mod.d.ts.map +1 -0
- package/esm/editor/src/commands/mod.js +883 -0
- package/esm/editor/src/mod.d.ts +7 -0
- package/esm/editor/src/mod.d.ts.map +1 -0
- package/esm/editor/src/mod.js +6 -0
- package/esm/editor/src/nodeToTreeString.d.ts +4 -0
- package/esm/editor/src/nodeToTreeString.d.ts.map +1 -0
- package/esm/editor/src/nodeToTreeString.js +58 -0
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +163 -0
- package/esm/editor/src/plugins/input-rules/mod.d.ts +3 -0
- package/esm/editor/src/plugins/input-rules/mod.d.ts.map +1 -0
- package/esm/editor/src/plugins/input-rules/mod.js +2 -0
- package/esm/editor/src/plugins/input-rules/rulebuilders.d.ts +5 -0
- package/esm/editor/src/plugins/input-rules/rulebuilders.d.ts.map +1 -0
- package/esm/editor/src/plugins/input-rules/rulebuilders.js +50 -0
- package/esm/editor/src/plugins/keymap/keymap.d.ts +11 -0
- package/esm/editor/src/plugins/keymap/keymap.d.ts.map +1 -0
- package/esm/editor/src/plugins/keymap/keymap.js +125 -0
- package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts +4 -0
- package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts.map +1 -0
- package/esm/editor/src/plugins/keymap/w3c-keyname.js +124 -0
- package/esm/editor/src/types.d.ts +34 -0
- package/esm/editor/src/types.d.ts.map +1 -0
- package/esm/editor/src/types.js +1 -0
- package/esm/editor/src/utilities/createNodeFromContent.d.ts +9 -0
- package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -0
- package/esm/editor/src/utilities/createNodeFromContent.js +32 -0
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts +9 -0
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -0
- package/esm/editor/src/utilities/getHtmlAttributes.js +47 -0
- package/esm/editor/src/utilities/mod.d.ts +3 -0
- package/esm/editor/src/utilities/mod.d.ts.map +1 -0
- package/esm/editor/src/utilities/mod.js +2 -0
- package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts +5 -0
- package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts.map +1 -0
- package/esm/extension-codemirror/src/ExtensionCodeMirror.js +4 -0
- package/esm/extension-codemirror/src/NodeCodeMirror.d.ts +16 -0
- package/esm/extension-codemirror/src/NodeCodeMirror.d.ts.map +1 -0
- package/esm/extension-codemirror/src/NodeCodeMirror.js +186 -0
- package/esm/extension-codemirror/src/NodeDocumentCode.d.ts +7 -0
- package/esm/extension-codemirror/src/NodeDocumentCode.d.ts.map +1 -0
- package/esm/extension-codemirror/src/NodeDocumentCode.js +37 -0
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts +6 -0
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts.map +1 -0
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.js +267 -0
- package/esm/extension-codemirror/src/defaults.d.ts +6 -0
- package/esm/extension-codemirror/src/defaults.d.ts.map +1 -0
- package/esm/extension-codemirror/src/defaults.js +57 -0
- package/esm/extension-codemirror/src/languageLoaders.d.ts +5 -0
- package/esm/extension-codemirror/src/languageLoaders.d.ts.map +1 -0
- package/esm/extension-codemirror/src/languageLoaders.js +113 -0
- package/esm/extension-codemirror/src/languages.d.ts +109 -0
- package/esm/extension-codemirror/src/languages.d.ts.map +1 -0
- package/esm/extension-codemirror/src/languages.js +110 -0
- package/esm/extension-codemirror/src/types.d.ts +30 -0
- package/esm/extension-codemirror/src/types.d.ts.map +1 -0
- package/esm/extension-codemirror/src/types.js +1 -0
- package/esm/extension-codemirror/src/utils.d.ts +39 -0
- package/esm/extension-codemirror/src/utils.d.ts.map +1 -0
- package/esm/extension-codemirror/src/utils.js +199 -0
- package/esm/extension-codemirror/src/y-remote-selections.d.ts +15 -0
- package/esm/extension-codemirror/src/y-remote-selections.d.ts.map +1 -0
- package/esm/extension-codemirror/src/y-remote-selections.js +273 -0
- package/esm/extension-codemirror/src/y-sync.d.ts +11 -0
- package/esm/extension-codemirror/src/y-sync.d.ts.map +1 -0
- package/esm/extension-codemirror/src/y-sync.js +29 -0
- package/esm/package.json +3 -0
- package/package.json +2 -6
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export var CodeBlockLanguages;
|
|
2
|
+
(function (CodeBlockLanguages) {
|
|
3
|
+
CodeBlockLanguages["javascript"] = "javascript";
|
|
4
|
+
CodeBlockLanguages["html"] = "html";
|
|
5
|
+
CodeBlockLanguages["css"] = "css";
|
|
6
|
+
CodeBlockLanguages["sql"] = "sql";
|
|
7
|
+
CodeBlockLanguages["python"] = "python";
|
|
8
|
+
CodeBlockLanguages["rust"] = "rust";
|
|
9
|
+
CodeBlockLanguages["xml"] = "xml";
|
|
10
|
+
CodeBlockLanguages["json"] = "json";
|
|
11
|
+
CodeBlockLanguages["markdown"] = "markdown";
|
|
12
|
+
CodeBlockLanguages["java"] = "java";
|
|
13
|
+
CodeBlockLanguages["cpp"] = "cpp";
|
|
14
|
+
CodeBlockLanguages["lezer"] = "lezer";
|
|
15
|
+
CodeBlockLanguages["php"] = "php";
|
|
16
|
+
CodeBlockLanguages["wast"] = "wast";
|
|
17
|
+
})(CodeBlockLanguages || (CodeBlockLanguages = {}));
|
|
18
|
+
export var LegacyLanguages;
|
|
19
|
+
(function (LegacyLanguages) {
|
|
20
|
+
LegacyLanguages["apl"] = "apl";
|
|
21
|
+
LegacyLanguages["asciiarmor"] = "asciiarmor";
|
|
22
|
+
LegacyLanguages["asn1"] = "asn1";
|
|
23
|
+
LegacyLanguages["asterisk"] = "asterisk";
|
|
24
|
+
LegacyLanguages["brainfuck"] = "brainfuck";
|
|
25
|
+
LegacyLanguages["clike"] = "clike";
|
|
26
|
+
LegacyLanguages["clojure"] = "clojure";
|
|
27
|
+
LegacyLanguages["cmake"] = "cmake";
|
|
28
|
+
LegacyLanguages["cobol"] = "cobol";
|
|
29
|
+
LegacyLanguages["coffeescript"] = "coffeescript";
|
|
30
|
+
LegacyLanguages["commonlisp"] = "commonlisp";
|
|
31
|
+
LegacyLanguages["crystal"] = "crystal";
|
|
32
|
+
LegacyLanguages["cypher"] = "cypher";
|
|
33
|
+
LegacyLanguages["d"] = "d";
|
|
34
|
+
LegacyLanguages["diff"] = "diff";
|
|
35
|
+
LegacyLanguages["dockerfile"] = "dockerfile";
|
|
36
|
+
LegacyLanguages["dtd"] = "dtd";
|
|
37
|
+
LegacyLanguages["dylan"] = "dylan";
|
|
38
|
+
LegacyLanguages["ebnf"] = "ebnf";
|
|
39
|
+
LegacyLanguages["ecl"] = "ecl";
|
|
40
|
+
LegacyLanguages["eiffel"] = "eiffel";
|
|
41
|
+
LegacyLanguages["elm"] = "elm";
|
|
42
|
+
LegacyLanguages["erlang"] = "erlang";
|
|
43
|
+
LegacyLanguages["factor"] = "factor";
|
|
44
|
+
LegacyLanguages["fcl"] = "fcl";
|
|
45
|
+
LegacyLanguages["forth"] = "forth";
|
|
46
|
+
LegacyLanguages["fortran"] = "fortran";
|
|
47
|
+
LegacyLanguages["gas"] = "gas";
|
|
48
|
+
LegacyLanguages["gherkin"] = "gherkin";
|
|
49
|
+
LegacyLanguages["go"] = "go";
|
|
50
|
+
LegacyLanguages["groovy"] = "groovy";
|
|
51
|
+
LegacyLanguages["haskell"] = "haskell";
|
|
52
|
+
LegacyLanguages["haxe"] = "haxe";
|
|
53
|
+
LegacyLanguages["http"] = "http";
|
|
54
|
+
LegacyLanguages["idl"] = "idl";
|
|
55
|
+
LegacyLanguages["jinja2"] = "jinja2";
|
|
56
|
+
LegacyLanguages["julia"] = "julia";
|
|
57
|
+
LegacyLanguages["livescript"] = "livescript";
|
|
58
|
+
LegacyLanguages["lua"] = "lua";
|
|
59
|
+
LegacyLanguages["mathematica"] = "mathematica";
|
|
60
|
+
LegacyLanguages["mbox"] = "mbox";
|
|
61
|
+
LegacyLanguages["mirc"] = "mirc";
|
|
62
|
+
LegacyLanguages["mllike"] = "mllike";
|
|
63
|
+
LegacyLanguages["modelica"] = "modelica";
|
|
64
|
+
LegacyLanguages["mscgen"] = "mscgen";
|
|
65
|
+
LegacyLanguages["mumps"] = "mumps";
|
|
66
|
+
LegacyLanguages["nginx"] = "nginx";
|
|
67
|
+
LegacyLanguages["nsis"] = "nsis";
|
|
68
|
+
LegacyLanguages["ntriples"] = "ntriples";
|
|
69
|
+
LegacyLanguages["octave"] = "octave";
|
|
70
|
+
LegacyLanguages["oz"] = "oz";
|
|
71
|
+
LegacyLanguages["pascal"] = "pascal";
|
|
72
|
+
LegacyLanguages["perl"] = "perl";
|
|
73
|
+
LegacyLanguages["pig"] = "pig";
|
|
74
|
+
LegacyLanguages["powershell"] = "powershell";
|
|
75
|
+
LegacyLanguages["properties"] = "properties";
|
|
76
|
+
LegacyLanguages["protobuf"] = "protobuf";
|
|
77
|
+
LegacyLanguages["puppet"] = "puppet";
|
|
78
|
+
LegacyLanguages["q"] = "q";
|
|
79
|
+
LegacyLanguages["r"] = "r";
|
|
80
|
+
LegacyLanguages["rpm"] = "rpm";
|
|
81
|
+
LegacyLanguages["ruby"] = "ruby";
|
|
82
|
+
LegacyLanguages["sas"] = "sas";
|
|
83
|
+
LegacyLanguages["scheme"] = "scheme";
|
|
84
|
+
LegacyLanguages["shell"] = "shell";
|
|
85
|
+
LegacyLanguages["smalltalk"] = "smalltalk";
|
|
86
|
+
LegacyLanguages["solr"] = "solr";
|
|
87
|
+
LegacyLanguages["sparql"] = "sparql";
|
|
88
|
+
LegacyLanguages["spreadsheet"] = "spreadsheet";
|
|
89
|
+
LegacyLanguages["stex"] = "stex";
|
|
90
|
+
LegacyLanguages["stylus"] = "stylus";
|
|
91
|
+
LegacyLanguages["swift"] = "swift";
|
|
92
|
+
LegacyLanguages["tcl"] = "tcl";
|
|
93
|
+
LegacyLanguages["textile"] = "textile";
|
|
94
|
+
LegacyLanguages["tiddlywiki"] = "tiddlywiki";
|
|
95
|
+
LegacyLanguages["tiki"] = "tiki";
|
|
96
|
+
LegacyLanguages["toml"] = "toml";
|
|
97
|
+
LegacyLanguages["troff"] = "troff";
|
|
98
|
+
LegacyLanguages["ttcn"] = "ttcn";
|
|
99
|
+
LegacyLanguages["turtle"] = "turtle";
|
|
100
|
+
LegacyLanguages["vb"] = "vb";
|
|
101
|
+
LegacyLanguages["vbscript"] = "vbscript";
|
|
102
|
+
LegacyLanguages["velocity"] = "velocity";
|
|
103
|
+
LegacyLanguages["verilog"] = "verilog";
|
|
104
|
+
LegacyLanguages["vhdl"] = "vhdl";
|
|
105
|
+
LegacyLanguages["webidl"] = "webidl";
|
|
106
|
+
LegacyLanguages["xquery"] = "xquery";
|
|
107
|
+
LegacyLanguages["yacas"] = "yacas";
|
|
108
|
+
LegacyLanguages["yaml"] = "yaml";
|
|
109
|
+
LegacyLanguages["z80"] = "z80";
|
|
110
|
+
})(LegacyLanguages || (LegacyLanguages = {}));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EditorState, Transaction } from 'prosemirror-state';
|
|
2
|
+
import { EditorView as CodemirrorView } from '@codemirror/view';
|
|
3
|
+
import { Node } from 'prosemirror-model';
|
|
4
|
+
import { EditorView } from 'prosemirror-view';
|
|
5
|
+
import { LanguageSupport } from '@codemirror/language';
|
|
6
|
+
import { Extension } from '@codemirror/state';
|
|
7
|
+
export type LanguageLoaders = Record<string, () => Promise<LanguageSupport>>;
|
|
8
|
+
export type ThemeItem = {
|
|
9
|
+
extension: Extension;
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
export type CodeBlockSettings = {
|
|
13
|
+
provider?: any;
|
|
14
|
+
createSelect: (settings: CodeBlockSettings, dom: HTMLElement, node: Node, view: EditorView, getPos: (() => number) | boolean) => () => void;
|
|
15
|
+
updateSelect: (settings: CodeBlockSettings, dom: HTMLElement, node: Node, view: EditorView, getPos: (() => number) | boolean, oldNode: Node) => void;
|
|
16
|
+
createCopyButton: (settings: CodeBlockSettings, dom: HTMLElement, node: Node, view: EditorView, codeMirrorView: CodemirrorView, getPos: (() => number) | boolean) => () => void;
|
|
17
|
+
stopEvent: (e: Event, node: Node, getPos: (() => number) | boolean, view: EditorView, dom: HTMLElement) => boolean;
|
|
18
|
+
languageLoaders?: LanguageLoaders;
|
|
19
|
+
languageNameMap?: Record<string, string>;
|
|
20
|
+
languageWhitelist?: string[];
|
|
21
|
+
undo?: (state: EditorState, dispatch: (tr: Transaction) => void) => void;
|
|
22
|
+
redo?: (state: EditorState, dispatch: (tr: Transaction) => void) => void;
|
|
23
|
+
theme?: Extension[];
|
|
24
|
+
readOnly: boolean;
|
|
25
|
+
themes: ThemeItem[];
|
|
26
|
+
getCurrentTheme?: () => string;
|
|
27
|
+
codeBlockName?: string;
|
|
28
|
+
shadowRoot?: ShadowRoot;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC;AAE7E,MAAM,MAAM,SAAS,GAAG;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,YAAY,EAAE,CACZ,QAAQ,EAAE,iBAAiB,EAC3B,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,OAAO,KAC7B,MAAM,IAAI,CAAC;IAChB,YAAY,EAAE,CACZ,QAAQ,EAAE,iB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|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Command, EditorState, TextSelection, Transaction } from 'prosemirror-state';
|
|
2
|
+
import { EditorView as PMEditorView } from 'prosemirror-view';
|
|
3
|
+
import { Node } from 'prosemirror-model';
|
|
4
|
+
import { EditorView } from '@codemirror/view';
|
|
5
|
+
import { Compartment } from '@codemirror/state';
|
|
6
|
+
import { CodeBlockSettings, ThemeItem } from './types.js';
|
|
7
|
+
export declare const CodeBlockNodeName = "code_block";
|
|
8
|
+
export declare function computeChange(oldVal: string, newVal: string): {
|
|
9
|
+
from: number;
|
|
10
|
+
to: number;
|
|
11
|
+
text: string;
|
|
12
|
+
} | null;
|
|
13
|
+
export declare const asProseMirrorSelection: (pmDoc: Node, cmView: EditorView, getPos: (() => number) | boolean) => TextSelection;
|
|
14
|
+
export declare const forwardSelection: (cmView: EditorView, pmView: PMEditorView, getPos: (() => number) | boolean) => void;
|
|
15
|
+
export declare const valueChanged: (textUpdate: string, node: Node, getPos: (() => number) | boolean, view: PMEditorView) => void;
|
|
16
|
+
export declare const maybeEscape: (unit: "char" | "line", dir: -1 | 1, cm: EditorView, view: PMEditorView, getPos: boolean | (() => number)) => boolean;
|
|
17
|
+
export declare const backspaceHandler: (pmView: PMEditorView, view: EditorView) => boolean;
|
|
18
|
+
export declare const setMode: (lang: string, cmView: EditorView, settings: CodeBlockSettings, languageConf: Compartment) => Promise<void>;
|
|
19
|
+
export declare const setTheme: (cmView: EditorView, themeConfig: Compartment, theme: Array<ThemeItem | undefined>) => Promise<void>;
|
|
20
|
+
export declare const createCodeBlock: (state: EditorState, dispatch: ((tr: Transaction) => void) | undefined, attributes: object) => boolean;
|
|
21
|
+
export declare const removeCodeBlock: (state: EditorState, dispatch: ((tr: Transaction) => void) | undefined) => boolean;
|
|
22
|
+
export declare const toggleCodeBlock: (state: EditorState, dispatch: ((tr: Transaction) => void) | undefined, attributes: object) => boolean;
|
|
23
|
+
export declare const codeBlockArrowHandlers: {
|
|
24
|
+
ArrowLeft: Command;
|
|
25
|
+
ArrowRight: Command;
|
|
26
|
+
ArrowUp: Command;
|
|
27
|
+
ArrowDown: Command;
|
|
28
|
+
};
|
|
29
|
+
export declare const codeBlockToggleShortcut: {
|
|
30
|
+
'Mod-Alt-c': Command;
|
|
31
|
+
};
|
|
32
|
+
export declare const codeBlockKeymap: {
|
|
33
|
+
ArrowLeft: Command;
|
|
34
|
+
ArrowRight: Command;
|
|
35
|
+
ArrowUp: Command;
|
|
36
|
+
ArrowDown: Command;
|
|
37
|
+
'Mod-Alt-c': Command;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,WAAW,EAEX,aAAa,EACb,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAa,MAAM,mBAAmB,CAAC;AAI3D,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE1D,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAM9C,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;SAoB3D;AAED,eAAO,MAAM,sBAAsB,GACjC,OAAO,IAAI,EACX,QAAQ,UAAU,EAClB,QAAQ,CAAC,MAAM,MAAM,CAAC,GAAG,OAAO,kBAMjC,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,UAAU,EAClB,QAAQ,YAAY,EACpB,QAAQ,CAAC,MAAM,MAA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M,OAAO;CAMxC,CAAC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// From prosemirror guide
|
|
2
|
+
import { Selection, TextSelection, } from 'prosemirror-state';
|
|
3
|
+
import { setBlockType } from '../../editor/src/commands/mod.js';
|
|
4
|
+
export const CodeBlockNodeName = 'code_block';
|
|
5
|
+
function nonEmpty(value) {
|
|
6
|
+
return value !== null && value !== undefined;
|
|
7
|
+
}
|
|
8
|
+
export function computeChange(oldVal, newVal) {
|
|
9
|
+
if (oldVal === newVal)
|
|
10
|
+
return null;
|
|
11
|
+
let start = 0;
|
|
12
|
+
let oldEnd = oldVal.length;
|
|
13
|
+
let newEnd = newVal.length;
|
|
14
|
+
while (start < oldEnd &&
|
|
15
|
+
oldVal.charCodeAt(start) === newVal.charCodeAt(start)) {
|
|
16
|
+
start += 1;
|
|
17
|
+
}
|
|
18
|
+
while (oldEnd > start &&
|
|
19
|
+
newEnd > start &&
|
|
20
|
+
oldVal.charCodeAt(oldEnd - 1) === newVal.charCodeAt(newEnd - 1)) {
|
|
21
|
+
oldEnd -= 1;
|
|
22
|
+
newEnd -= 1;
|
|
23
|
+
}
|
|
24
|
+
return { from: start, to: oldEnd, text: newVal.slice(start, newEnd) };
|
|
25
|
+
}
|
|
26
|
+
export const asProseMirrorSelection = (pmDoc, cmView, getPos) => {
|
|
27
|
+
const offset = (typeof getPos === 'function' ? getPos() || 0 : 0) + 1;
|
|
28
|
+
const anchor = cmView.state.selection.main.from + offset;
|
|
29
|
+
const head = cmView.state.selection.main.to + offset;
|
|
30
|
+
return TextSelection.create(pmDoc, anchor, head);
|
|
31
|
+
};
|
|
32
|
+
export const forwardSelection = (cmView, pmView, getPos) => {
|
|
33
|
+
if (!cmView.hasFocus)
|
|
34
|
+
return;
|
|
35
|
+
const selection = asProseMirrorSelection(pmView.state.doc, cmView, getPos);
|
|
36
|
+
if (!selection.eq(pmView.state.selection)) {
|
|
37
|
+
pmView.dispatch(pmView.state.tr.setSelection(selection));
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const valueChanged = (textUpdate, node, getPos, view) => {
|
|
41
|
+
const change = computeChange(node.textContent, textUpdate);
|
|
42
|
+
if (change && typeof getPos === 'function') {
|
|
43
|
+
const start = getPos() + 1;
|
|
44
|
+
let pmTr = view.state.tr;
|
|
45
|
+
pmTr = pmTr.replaceWith(start + change.from, start + change.to, change.text ? view.state.schema.text(change.text) : []);
|
|
46
|
+
view.dispatch(pmTr);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export const maybeEscape = (unit, dir, cm, view, getPos) => {
|
|
50
|
+
const sel = cm.state.selection.main;
|
|
51
|
+
const line = cm.state.doc.lineAt(sel.from);
|
|
52
|
+
const lastLine = cm.state.doc.lines;
|
|
53
|
+
if (sel.to !== sel.from ||
|
|
54
|
+
line.number !== (dir < 0 ? 1 : lastLine) ||
|
|
55
|
+
(unit === 'char' && sel.from !== (dir < 0 ? 0 : line.to)) ||
|
|
56
|
+
typeof getPos !== 'function') {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
view.focus();
|
|
60
|
+
const node = view.state.doc.nodeAt(getPos());
|
|
61
|
+
if (!node)
|
|
62
|
+
return false;
|
|
63
|
+
const targetPos = getPos() + (dir < 0 ? 0 : node.nodeSize);
|
|
64
|
+
const selection = Selection.near(view.state.doc.resolve(targetPos), dir);
|
|
65
|
+
view.dispatch(view.state.tr.setSelection(selection).scrollIntoView());
|
|
66
|
+
view.focus();
|
|
67
|
+
return true;
|
|
68
|
+
};
|
|
69
|
+
export const backspaceHandler = (pmView, view) => {
|
|
70
|
+
const { selection } = view.state;
|
|
71
|
+
if (selection.main.empty && selection.main.from === 0) {
|
|
72
|
+
setBlockType(pmView.state.schema.nodes.paragraph)(pmView.state, pmView.dispatch);
|
|
73
|
+
setTimeout(() => pmView.focus(), 20);
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
};
|
|
78
|
+
export const setMode = async (lang, cmView, settings, languageConf) => {
|
|
79
|
+
const support = await settings.languageLoaders?.[lang]?.();
|
|
80
|
+
if (support) {
|
|
81
|
+
cmView.dispatch({
|
|
82
|
+
effects: languageConf.reconfigure(support),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const isTheme = (theme) => {
|
|
87
|
+
if (!Array.isArray(theme)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return theme.every((item) => item !== undefined &&
|
|
91
|
+
typeof item.extension === 'object' && // or whatever type Extension is
|
|
92
|
+
typeof item.name === 'string');
|
|
93
|
+
};
|
|
94
|
+
export const setTheme = async (cmView, themeConfig, theme) => {
|
|
95
|
+
if (isTheme(theme)) {
|
|
96
|
+
cmView.dispatch({
|
|
97
|
+
effects: themeConfig.reconfigure(theme),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const arrowHandler = (dir) => (state, dispatch, view) => {
|
|
102
|
+
if (state.selection.empty && view?.endOfTextblock(dir)) {
|
|
103
|
+
const side = dir === 'left' || dir === 'up' ? -1 : 1;
|
|
104
|
+
const { $head } = state.selection;
|
|
105
|
+
const nextPos = Selection.near(state.doc.resolve(side > 0 ? $head.after() : $head.before()), side);
|
|
106
|
+
if (nextPos.$head &&
|
|
107
|
+
nextPos.$head.parent.type.name === CodeBlockNodeName) {
|
|
108
|
+
dispatch?.(state.tr.setSelection(nextPos));
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
};
|
|
114
|
+
export const createCodeBlock = (state, dispatch, attributes) => {
|
|
115
|
+
const { $from, $to } = state.selection;
|
|
116
|
+
//if we are in a CodeBlock node we do nothing
|
|
117
|
+
const parentNode = $from.node($from.depth);
|
|
118
|
+
if (parentNode && parentNode.type.name === CodeBlockNodeName) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
//if from and to in the same paragraph
|
|
122
|
+
if ($from.parentOffset === $to.parentOffset &&
|
|
123
|
+
$from.parent.type.name === 'paragraph') {
|
|
124
|
+
const text = $from.parent.textContent;
|
|
125
|
+
const tr = state.tr;
|
|
126
|
+
const newNode = state.schema.nodes[CodeBlockNodeName].createAndFill(attributes, text ? [state.schema.text($from.parent.textContent)] : []);
|
|
127
|
+
if (newNode && dispatch) {
|
|
128
|
+
const pos = $from.before($from.depth);
|
|
129
|
+
tr.delete(pos, pos + $from.parent.nodeSize - 1);
|
|
130
|
+
tr.insert(pos, newNode);
|
|
131
|
+
tr.setSelection(TextSelection.create(tr.doc, $from.pos));
|
|
132
|
+
dispatch(tr);
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
if (dispatch) {
|
|
137
|
+
const tr = state.tr;
|
|
138
|
+
const slice = state.doc.slice($from.before($from.depth), $to.after($to.depth), true);
|
|
139
|
+
const content = slice.content.textBetween(0, slice.content.size, '\n');
|
|
140
|
+
const newNode = state.schema.nodes[CodeBlockNodeName].createAndFill(attributes, state.schema.text(content));
|
|
141
|
+
if (newNode) {
|
|
142
|
+
tr.delete($from.before(slice.openStart + 1), $to.after(slice.openEnd + 1));
|
|
143
|
+
tr.insert($from.before(slice.openStart + 1), newNode);
|
|
144
|
+
tr.setSelection(TextSelection.create(tr.doc, $from.pos, $from.pos + newNode.nodeSize - 2));
|
|
145
|
+
dispatch(tr);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
};
|
|
150
|
+
export const removeCodeBlock = (state, dispatch) => {
|
|
151
|
+
const { $from } = state.selection;
|
|
152
|
+
const parentNode = $from.node($from.depth);
|
|
153
|
+
if (parentNode && parentNode.type.name === CodeBlockNodeName) {
|
|
154
|
+
const children = [];
|
|
155
|
+
parentNode.forEach((child) => {
|
|
156
|
+
children.push(child);
|
|
157
|
+
});
|
|
158
|
+
const childrenNodes = children
|
|
159
|
+
.map((child) => {
|
|
160
|
+
return state.schema.nodes.paragraph.createAndFill({}, [child]);
|
|
161
|
+
})
|
|
162
|
+
.filter(nonEmpty);
|
|
163
|
+
const tr = state.tr;
|
|
164
|
+
const pos = $from.before($from.depth);
|
|
165
|
+
tr.delete(pos, pos + parentNode.nodeSize - 1);
|
|
166
|
+
tr.insert(pos, childrenNodes);
|
|
167
|
+
tr.setSelection(TextSelection.create(tr.doc, $from.pos - 1));
|
|
168
|
+
if (dispatch) {
|
|
169
|
+
dispatch(tr.scrollIntoView());
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
};
|
|
174
|
+
export const toggleCodeBlock = (state, dispatch, attributes) => {
|
|
175
|
+
const { $from } = state.selection;
|
|
176
|
+
if ($from.pos === 0) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
const parentNode = $from.node($from.depth);
|
|
180
|
+
if (parentNode && parentNode.type.name === CodeBlockNodeName) {
|
|
181
|
+
return removeCodeBlock(state, dispatch);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
return createCodeBlock(state, dispatch, attributes);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
export const codeBlockArrowHandlers = {
|
|
188
|
+
ArrowLeft: arrowHandler('left'),
|
|
189
|
+
ArrowRight: arrowHandler('right'),
|
|
190
|
+
ArrowUp: arrowHandler('up'),
|
|
191
|
+
ArrowDown: arrowHandler('down'),
|
|
192
|
+
};
|
|
193
|
+
export const codeBlockToggleShortcut = {
|
|
194
|
+
'Mod-Alt-c': toggleCodeBlock,
|
|
195
|
+
};
|
|
196
|
+
export const codeBlockKeymap = {
|
|
197
|
+
...codeBlockToggleShortcut,
|
|
198
|
+
...codeBlockArrowHandlers,
|
|
199
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as cmView from '@codemirror/view';
|
|
2
|
+
import * as cmState from '@codemirror/state';
|
|
3
|
+
import { YSyncConfig } from './y-sync.js';
|
|
4
|
+
export declare const yRemoteSelectionsTheme: cmState.Extension;
|
|
5
|
+
export declare class YRemoteSelectionsPluginValue {
|
|
6
|
+
conf: YSyncConfig;
|
|
7
|
+
private _listener;
|
|
8
|
+
private _awareness;
|
|
9
|
+
decorations: cmView.DecorationSet;
|
|
10
|
+
constructor(view: cmView.EditorView);
|
|
11
|
+
destroy(): void;
|
|
12
|
+
update(update: cmView.ViewUpdate): void;
|
|
13
|
+
}
|
|
14
|
+
export declare const yRemoteSelections: cmView.ViewPlugin<YRemoteSelectionsPluginValue, undefined>;
|
|
15
|
+
//# sourceMappingURL=y-remote-selections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"y-remote-selections.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/y-remote-selections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAE3C,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AAO7C,OAAO,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AAEtD,eAAO,MAAM,sBAAsB,mBAuDjC,CAAC;AA8CH,qBAAa,4BAA4B;IACvC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,CAAC,SAAS,CAQP;IACV,OAAO,CAAC,UAAU,CAA8B;IAChD,WAAW,EAAE,MAAM,CAAC,aAAa,CAAC;gBAEtB,IAAI,EAAE,MAAM,CAAC,UAAU;IAiBnC,OAAO;IAIP,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU;CAmIjC;AAED,eAAO,MAAM,iBAAiB,4DAK7B,CAAC"}
|