@kerebron/extension-codemirror 0.3.2 → 0.4.2
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 +3 -3
- package/esm/_dnt.polyfills.d.ts +101 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +127 -0
- package/esm/_dnt.shims.d.ts +6 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +61 -0
- package/esm/editor/src/CoreEditor.d.ts +13 -4
- package/esm/editor/src/CoreEditor.d.ts.map +1 -1
- package/esm/editor/src/CoreEditor.js +64 -12
- package/esm/editor/src/Extension.d.ts +6 -1
- package/esm/editor/src/Extension.d.ts.map +1 -1
- package/esm/editor/src/Extension.js +21 -1
- package/esm/editor/src/ExtensionManager.d.ts +5 -6
- package/esm/editor/src/ExtensionManager.d.ts.map +1 -1
- package/esm/editor/src/ExtensionManager.js +43 -55
- package/esm/editor/src/Mark.d.ts +3 -0
- package/esm/editor/src/Mark.d.ts.map +1 -1
- package/esm/editor/src/Mark.js +11 -0
- package/esm/editor/src/Node.d.ts +5 -2
- package/esm/editor/src/Node.d.ts.map +1 -1
- package/esm/editor/src/Node.js +13 -2
- package/esm/editor/src/commands/CommandManager.d.ts +13 -6
- package/esm/editor/src/commands/CommandManager.d.ts.map +1 -1
- package/esm/editor/src/commands/CommandManager.js +59 -2
- package/esm/editor/src/commands/baseCommandFactories.d.ts +3 -0
- package/esm/editor/src/commands/baseCommandFactories.d.ts.map +1 -0
- package/esm/editor/src/commands/baseCommandFactories.js +836 -0
- package/esm/editor/src/commands/keyCommandFactories.d.ts +3 -0
- package/esm/editor/src/commands/keyCommandFactories.d.ts.map +1 -0
- package/esm/editor/src/commands/keyCommandFactories.js +10 -0
- package/esm/editor/src/commands/mod.d.ts +5 -53
- package/esm/editor/src/commands/mod.d.ts.map +1 -1
- package/esm/editor/src/commands/mod.js +14 -821
- package/esm/editor/src/commands/replaceCommandFactories.d.ts +3 -0
- package/esm/editor/src/commands/replaceCommandFactories.d.ts.map +1 -0
- package/esm/editor/src/commands/replaceCommandFactories.js +94 -0
- package/esm/editor/src/commands/types.d.ts +18 -0
- package/esm/editor/src/commands/types.d.ts.map +1 -0
- package/esm/editor/src/commands/types.js +1 -0
- package/esm/editor/src/mod.d.ts +2 -0
- package/esm/editor/src/mod.d.ts.map +1 -1
- package/esm/editor/src/mod.js +2 -0
- package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts +6 -0
- package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts.map +1 -0
- package/esm/editor/src/plugins/TrackSelecionPlugin.js +24 -0
- package/esm/editor/src/types.d.ts +19 -1
- package/esm/editor/src/types.d.ts.map +1 -1
- package/esm/editor/src/ui.d.ts +15 -0
- package/esm/editor/src/ui.d.ts.map +1 -0
- package/esm/editor/src/ui.js +16 -0
- package/esm/editor/src/utilities/SmartOutput.d.ts +9 -7
- package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -1
- package/esm/editor/src/utilities/SmartOutput.js +35 -20
- package/esm/editor/src/utilities/getShadowRoot.d.ts +2 -0
- package/esm/editor/src/utilities/getShadowRoot.d.ts.map +1 -0
- package/esm/editor/src/utilities/getShadowRoot.js +16 -0
- package/esm/editor/src/utilities/mod.d.ts +2 -0
- package/esm/editor/src/utilities/mod.d.ts.map +1 -1
- package/esm/editor/src/utilities/mod.js +2 -0
- package/esm/editor/src/utilities/toRawTextResult.d.ts +3 -0
- package/esm/editor/src/utilities/toRawTextResult.d.ts.map +1 -0
- package/esm/editor/src/utilities/toRawTextResult.js +21 -0
- package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts +8 -0
- package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/AutocompletePlugin.js +232 -0
- package/esm/extension-autocomplete/src/DefaultRenderer.d.ts +17 -0
- package/esm/extension-autocomplete/src/DefaultRenderer.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/DefaultRenderer.js +137 -0
- package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts +26 -0
- package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/ExtensionAutocomplete.js +30 -0
- package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts +11 -0
- package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/createDefaultMatcher.js +58 -0
- package/esm/extension-autocomplete/src/createRegexMatcher.d.ts +4 -0
- package/esm/extension-autocomplete/src/createRegexMatcher.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/createRegexMatcher.js +50 -0
- package/esm/extension-autocomplete/src/mod.d.ts +3 -0
- package/esm/extension-autocomplete/src/mod.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/mod.js +2 -0
- package/esm/extension-autocomplete/src/types.d.ts +60 -0
- package/esm/extension-autocomplete/src/types.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/types.js +1 -0
- package/esm/extension-basic-editor/src/ExtensionHtml.d.ts +15 -0
- package/esm/extension-basic-editor/src/ExtensionHtml.d.ts.map +1 -0
- package/esm/extension-basic-editor/src/ExtensionHtml.js +108 -0
- package/esm/extension-basic-editor/src/NodeCodeBlock.d.ts +9 -0
- package/esm/extension-basic-editor/src/NodeCodeBlock.d.ts.map +1 -0
- package/esm/extension-basic-editor/src/NodeCodeBlock.js +58 -0
- package/esm/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.d.ts +24 -0
- package/esm/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.d.ts.map +1 -0
- package/esm/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.js +35 -0
- package/esm/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.d.ts +25 -0
- package/esm/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.d.ts.map +1 -0
- package/esm/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.js +96 -0
- package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts +15 -2
- package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts.map +1 -1
- package/esm/extension-codemirror/src/ExtensionCodeMirror.js +74 -2
- package/esm/extension-codemirror/src/NodeCodeMirror.d.ts +13 -9
- package/esm/extension-codemirror/src/NodeCodeMirror.d.ts.map +1 -1
- package/esm/extension-codemirror/src/NodeCodeMirror.js +34 -122
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts +3 -3
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts.map +1 -1
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.js +155 -107
- package/esm/extension-codemirror/src/defaults.d.ts +1 -1
- package/esm/extension-codemirror/src/defaults.d.ts.map +1 -1
- package/esm/extension-codemirror/src/defaults.js +4 -3
- package/esm/extension-codemirror/src/languageLoaders.d.ts.map +1 -1
- package/esm/extension-codemirror/src/languageLoaders.js +1 -2
- package/esm/extension-codemirror/src/lsp/LSPExtension.d.ts +14 -0
- package/esm/extension-codemirror/src/lsp/LSPExtension.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/LSPExtension.js +38 -0
- package/esm/extension-codemirror/src/lsp/completion.d.ts +8 -0
- package/esm/extension-codemirror/src/lsp/completion.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/completion.js +179 -0
- package/esm/extension-codemirror/src/lsp/hover.d.ts +5 -0
- package/esm/extension-codemirror/src/lsp/hover.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/hover.js +81 -0
- package/esm/extension-codemirror/src/lsp/index.d.ts +7 -0
- package/esm/extension-codemirror/src/lsp/index.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/index.js +49 -0
- package/esm/extension-codemirror/src/lsp/plugin.d.ts +37 -0
- package/esm/extension-codemirror/src/lsp/plugin.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/plugin.js +125 -0
- package/esm/extension-codemirror/src/lsp/pos.d.ts +5 -0
- package/esm/extension-codemirror/src/lsp/pos.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/pos.js +8 -0
- package/esm/extension-codemirror/src/lsp/text.d.ts +2 -0
- package/esm/extension-codemirror/src/lsp/text.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/text.js +47 -0
- package/esm/extension-codemirror/src/lsp/theme.d.ts +2 -0
- package/esm/extension-codemirror/src/lsp/theme.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/theme.js +76 -0
- package/esm/extension-codemirror/src/{y-remote-selections.d.ts → remote-selections.d.ts} +5 -5
- package/esm/extension-codemirror/src/remote-selections.d.ts.map +1 -0
- package/esm/extension-codemirror/src/{y-remote-selections.js → remote-selections.js} +49 -69
- package/esm/extension-codemirror/src/remote-sync.d.ts +11 -0
- package/esm/extension-codemirror/src/remote-sync.d.ts.map +1 -0
- package/esm/extension-codemirror/src/{y-sync.js → remote-sync.js} +6 -6
- package/esm/extension-codemirror/src/types.d.ts +10 -10
- package/esm/extension-codemirror/src/types.d.ts.map +1 -1
- package/esm/extension-codemirror/src/utils.d.ts +7 -6
- package/esm/extension-codemirror/src/utils.d.ts.map +1 -1
- package/esm/extension-codemirror/src/utils.js +21 -10
- package/esm/extension-lsp/src/DiagnosticPlugin.d.ts +32 -0
- package/esm/extension-lsp/src/DiagnosticPlugin.d.ts.map +1 -0
- package/esm/extension-lsp/src/DiagnosticPlugin.js +131 -0
- package/esm/extension-lsp/src/ExtensionLsp.d.ts +25 -0
- package/esm/extension-lsp/src/ExtensionLsp.d.ts.map +1 -0
- package/esm/extension-lsp/src/ExtensionLsp.js +126 -0
- package/esm/extension-lsp/src/LSPClient.d.ts +56 -0
- package/esm/extension-lsp/src/LSPClient.d.ts.map +1 -0
- package/esm/extension-lsp/src/LSPClient.js +449 -0
- package/esm/extension-lsp/src/computeIncrementalChanges.d.ts +8 -0
- package/esm/extension-lsp/src/computeIncrementalChanges.d.ts.map +1 -0
- package/esm/extension-lsp/src/computeIncrementalChanges.js +82 -0
- package/esm/extension-lsp/src/createLspAutocomplete.d.ts +23 -0
- package/esm/extension-lsp/src/createLspAutocomplete.d.ts.map +1 -0
- package/esm/extension-lsp/src/createLspAutocomplete.js +68 -0
- package/esm/extension-lsp/src/mod.d.ts +4 -0
- package/esm/extension-lsp/src/mod.d.ts.map +1 -0
- package/esm/extension-lsp/src/mod.js +3 -0
- package/esm/extension-lsp/src/workspace.d.ts +62 -0
- package/esm/extension-lsp/src/workspace.d.ts.map +1 -0
- package/esm/extension-lsp/src/workspace.js +168 -0
- package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts +36 -0
- package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts.map +1 -0
- package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.js +240 -0
- package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts +26 -0
- package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts.map +1 -0
- package/esm/extension-markdown/src/DocumentMarkdownTokenizer.js +115 -0
- package/esm/extension-markdown/src/ExtensionMarkdown.d.ts +22 -0
- package/esm/extension-markdown/src/ExtensionMarkdown.d.ts.map +1 -0
- package/esm/extension-markdown/src/ExtensionMarkdown.js +48 -0
- package/esm/extension-markdown/src/MarkdownParser.d.ts +61 -0
- package/esm/extension-markdown/src/MarkdownParser.d.ts.map +1 -0
- package/esm/extension-markdown/src/MarkdownParser.js +249 -0
- package/esm/extension-markdown/src/MarkdownSerializer.d.ts +42 -0
- package/esm/extension-markdown/src/MarkdownSerializer.d.ts.map +1 -0
- package/esm/extension-markdown/src/MarkdownSerializer.js +325 -0
- package/esm/extension-markdown/src/PositionMapper.d.ts +15 -0
- package/esm/extension-markdown/src/PositionMapper.d.ts.map +1 -0
- package/esm/extension-markdown/src/PositionMapper.js +100 -0
- package/esm/extension-markdown/src/TokenSource.d.ts +11 -0
- package/esm/extension-markdown/src/TokenSource.d.ts.map +1 -0
- package/esm/extension-markdown/src/TokenSource.js +39 -0
- package/esm/extension-markdown/src/mdToPmConverter.d.ts +5 -0
- package/esm/extension-markdown/src/mdToPmConverter.d.ts.map +1 -0
- package/esm/extension-markdown/src/mdToPmConverter.js +111 -0
- package/esm/extension-markdown/src/pmToMdConverter.d.ts +16 -0
- package/esm/extension-markdown/src/pmToMdConverter.d.ts.map +1 -0
- package/esm/extension-markdown/src/pmToMdConverter.js +433 -0
- package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts +4 -0
- package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/basic_token_handlers.js +151 -0
- package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts +3 -0
- package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.js +34 -0
- package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts +6 -0
- package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/inline_token_handlers.js +380 -0
- package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts +3 -0
- package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/lists_token_handlers.js +323 -0
- package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts +9 -0
- package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/table_token_handlers.js +308 -0
- package/esm/extension-markdown/src/treeSitterTokenizer.d.ts +5 -0
- package/esm/extension-markdown/src/treeSitterTokenizer.d.ts.map +1 -0
- package/esm/extension-markdown/src/treeSitterTokenizer.js +769 -0
- package/esm/extension-markdown/src/types.d.ts +28 -0
- package/esm/extension-markdown/src/types.d.ts.map +1 -0
- package/esm/extension-markdown/src/types.js +131 -0
- package/esm/extension-markdown/src/utils.d.ts +8 -0
- package/esm/extension-markdown/src/utils.d.ts.map +1 -0
- package/esm/extension-markdown/src/utils.js +86 -0
- package/esm/tree-sitter-shim/src/main.d.ts +15 -0
- package/esm/tree-sitter-shim/src/main.d.ts.map +1 -0
- package/esm/tree-sitter-shim/src/main.js +25 -0
- package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts +6 -0
- package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts.map +1 -0
- package/esm/tree-sitter-shim/src/tree_sitter/node.js +1 -0
- package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts +7 -0
- package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts.map +1 -0
- package/esm/tree-sitter-shim/src/tree_sitter/parser.js +5 -0
- package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts +6 -0
- package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts.map +1 -0
- package/esm/tree-sitter-shim/src/tree_sitter/tree.js +1 -0
- package/esm/wasm/src/mod.d.ts +12 -0
- package/esm/wasm/src/mod.d.ts.map +1 -0
- package/esm/wasm/src/mod.js +48 -0
- package/esm/wasm/wasm.d.ts +138 -0
- package/esm/wasm/wasm.d.ts.map +1 -0
- package/esm/wasm/wasm.js +120 -0
- package/package.json +5 -25
- package/esm/extension-codemirror/src/NodeDocumentCode.d.ts +0 -7
- package/esm/extension-codemirror/src/NodeDocumentCode.d.ts.map +0 -1
- package/esm/extension-codemirror/src/NodeDocumentCode.js +0 -37
- package/esm/extension-codemirror/src/y-remote-selections.d.ts.map +0 -1
- package/esm/extension-codemirror/src/y-sync.d.ts +0 -11
- package/esm/extension-codemirror/src/y-sync.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Fragment, Node, type ParseOptions, Schema } from 'prosemirror-model';
|
|
2
|
+
import { type Converter, type CoreEditor, Extension } from '../../editor/src/mod.js';
|
|
3
|
+
export type CreateNodeFromContentOptions = {
|
|
4
|
+
parseOptions?: ParseOptions;
|
|
5
|
+
errorOnInvalidContent?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function getHTMLFromFragment(fragment: Fragment, schema: Schema): string;
|
|
8
|
+
export declare function elementFromString(value: string): HTMLElement;
|
|
9
|
+
export declare function createNodeFromHTML(content: string, schema: Schema, options?: CreateNodeFromContentOptions): Node;
|
|
10
|
+
export declare function createFragmentFromHTML(content: string, schema: Schema, options?: CreateNodeFromContentOptions): Fragment;
|
|
11
|
+
export declare class ExtensionHtml extends Extension {
|
|
12
|
+
name: string;
|
|
13
|
+
getConverters(editor: CoreEditor, schema: Schema): Record<string, Converter>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=ExtensionHtml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionHtml.d.ts","sourceRoot":"","sources":["../../../src/extension-basic-editor/src/ExtensionHtml.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,QAAQ,EACR,IAAI,EACJ,KAAK,YAAY,EACjB,MAAM,EACP,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAErF,MAAM,MAAM,4BAA4B,GAAG;IACzC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAaR;AAqBD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAQ5D;AA+BD,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,IAAI,CAgBN;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,QAAQ,CAiBV;AAED,qBAAa,aAAc,SAAQ,SAAS;IAC1C,IAAI,SAAU;IAEL,aAAa,CACpB,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;CAe7B"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { DOMParser, DOMSerializer, Schema, } from 'prosemirror-model';
|
|
2
|
+
import { Extension } from '../../editor/src/mod.js';
|
|
3
|
+
export function getHTMLFromFragment(fragment, schema) {
|
|
4
|
+
const document = globalThis.document;
|
|
5
|
+
const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment, { document });
|
|
6
|
+
const temporaryDocument = document.implementation.createHTMLDocument();
|
|
7
|
+
const container = temporaryDocument.createElement('div');
|
|
8
|
+
container.appendChild(documentFragment);
|
|
9
|
+
return container.innerHTML;
|
|
10
|
+
}
|
|
11
|
+
const removeWhitespaces = (node) => {
|
|
12
|
+
const children = node.childNodes;
|
|
13
|
+
for (let i = children.length - 1; i >= 0; i -= 1) {
|
|
14
|
+
const child = children[i];
|
|
15
|
+
if (child.nodeType === 3 && child.nodeValue &&
|
|
16
|
+
/^(\n\s\s|\n)$/.test(child.nodeValue)) {
|
|
17
|
+
node.removeChild(child);
|
|
18
|
+
}
|
|
19
|
+
else if (child.nodeType === 1) {
|
|
20
|
+
removeWhitespaces(child);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return node;
|
|
24
|
+
};
|
|
25
|
+
export function elementFromString(value) {
|
|
26
|
+
// add a wrapper to preserve leading and trailing whitespace
|
|
27
|
+
const wrappedValue = `<body>${value}</body>`;
|
|
28
|
+
const html = new globalThis.DOMParser().parseFromString(wrappedValue, 'text/html').body;
|
|
29
|
+
return removeWhitespaces(html);
|
|
30
|
+
}
|
|
31
|
+
function prepareContentCheckSchema(schema) {
|
|
32
|
+
const contentCheckSchema = new Schema({
|
|
33
|
+
topNode: schema.spec.topNode,
|
|
34
|
+
marks: schema.spec.marks,
|
|
35
|
+
// Prosemirror's schemas are executed such that: the last to execute, matches last
|
|
36
|
+
// This means that we can add a catch-all node at the end of the schema to catch any content that we don't know how to handle
|
|
37
|
+
nodes: schema.spec.nodes.append({
|
|
38
|
+
__unknown__catch__all__node: {
|
|
39
|
+
content: 'inline*',
|
|
40
|
+
group: 'block',
|
|
41
|
+
parseDOM: [
|
|
42
|
+
{
|
|
43
|
+
tag: '*',
|
|
44
|
+
getAttrs: (e) => {
|
|
45
|
+
// Try to stringify the element for a more helpful error message
|
|
46
|
+
const invalidContent = typeof e === 'string' ? e : e.outerHTML;
|
|
47
|
+
throw new Error('Invalid HTML content', {
|
|
48
|
+
cause: new Error(`Invalid element found: ${invalidContent}`),
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
return contentCheckSchema;
|
|
57
|
+
}
|
|
58
|
+
export function createNodeFromHTML(content, schema, options) {
|
|
59
|
+
options = {
|
|
60
|
+
parseOptions: {},
|
|
61
|
+
...options,
|
|
62
|
+
};
|
|
63
|
+
if (options.errorOnInvalidContent) {
|
|
64
|
+
const contentCheckSchema = prepareContentCheckSchema(schema);
|
|
65
|
+
DOMParser.fromSchema(contentCheckSchema).parse(elementFromString(content), options.parseOptions);
|
|
66
|
+
}
|
|
67
|
+
const parser = DOMParser.fromSchema(schema);
|
|
68
|
+
return parser.parse(elementFromString(content), options.parseOptions);
|
|
69
|
+
}
|
|
70
|
+
export function createFragmentFromHTML(content, schema, options) {
|
|
71
|
+
options = {
|
|
72
|
+
parseOptions: {},
|
|
73
|
+
...options,
|
|
74
|
+
};
|
|
75
|
+
if (options.errorOnInvalidContent) {
|
|
76
|
+
const contentCheckSchema = prepareContentCheckSchema(schema);
|
|
77
|
+
DOMParser.fromSchema(contentCheckSchema).parseSlice(elementFromString(content), options.parseOptions);
|
|
78
|
+
}
|
|
79
|
+
const parser = DOMParser.fromSchema(schema);
|
|
80
|
+
return parser.parseSlice(elementFromString(content), options.parseOptions)
|
|
81
|
+
.content;
|
|
82
|
+
}
|
|
83
|
+
export class ExtensionHtml extends Extension {
|
|
84
|
+
constructor() {
|
|
85
|
+
super(...arguments);
|
|
86
|
+
Object.defineProperty(this, "name", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true,
|
|
89
|
+
writable: true,
|
|
90
|
+
value: 'html'
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
getConverters(editor, schema) {
|
|
94
|
+
const config = this.config;
|
|
95
|
+
return {
|
|
96
|
+
'text/html': {
|
|
97
|
+
fromDoc: async (document) => {
|
|
98
|
+
const html = getHTMLFromFragment(document.content, editor.schema);
|
|
99
|
+
return new TextEncoder().encode(html);
|
|
100
|
+
},
|
|
101
|
+
toDoc: async (buffer) => {
|
|
102
|
+
const html = new TextDecoder().decode(buffer);
|
|
103
|
+
return createNodeFromHTML(html, editor.schema);
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NodeSpec, NodeType } from 'prosemirror-model';
|
|
2
|
+
import { Node } from '../../editor/src/mod.js';
|
|
3
|
+
import { type InputRule } from '../../editor/src/plugins/input-rules/mod.js';
|
|
4
|
+
export declare class NodeCodeBlock extends Node {
|
|
5
|
+
name: string;
|
|
6
|
+
getNodeSpec(): NodeSpec;
|
|
7
|
+
getInputRules(type: NodeType): InputRule[];
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=NodeCodeBlock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeCodeBlock.d.ts","sourceRoot":"","sources":["../../../src/extension-basic-editor/src/NodeCodeBlock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EACL,KAAK,SAAS,EAEf,MAAM,6CAA6C,CAAC;AAErD,qBAAa,aAAc,SAAQ,IAAI;IAC5B,IAAI,SAAgB;IAEpB,WAAW,IAAI,QAAQ;IA0CvB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE;CAOpD"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Node } from '../../editor/src/mod.js';
|
|
2
|
+
import { textblockTypeInputRule, } from '../../editor/src/plugins/input-rules/mod.js';
|
|
3
|
+
export class NodeCodeBlock extends Node {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
Object.defineProperty(this, "name", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: 'code_block'
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
getNodeSpec() {
|
|
14
|
+
// const langs = this.config.languageWhitelist || LANGS;
|
|
15
|
+
return {
|
|
16
|
+
content: 'text*',
|
|
17
|
+
marks: '',
|
|
18
|
+
group: 'block',
|
|
19
|
+
code: true,
|
|
20
|
+
defining: true,
|
|
21
|
+
parseDOM: [
|
|
22
|
+
{
|
|
23
|
+
tag: 'pre',
|
|
24
|
+
preserveWhitespace: 'full',
|
|
25
|
+
getAttrs(dom) {
|
|
26
|
+
let lang = dom.getAttribute('lang');
|
|
27
|
+
// if (!lang) {
|
|
28
|
+
// for (const className of dom.classList) {
|
|
29
|
+
// if (
|
|
30
|
+
// className.startsWith('lang-') &&
|
|
31
|
+
// langs.indexOf(className.substring('lang-'.length)) > -1
|
|
32
|
+
// ) {
|
|
33
|
+
// lang = className.substring('lang-'.length);
|
|
34
|
+
// break;
|
|
35
|
+
// }
|
|
36
|
+
// }
|
|
37
|
+
// }
|
|
38
|
+
return {
|
|
39
|
+
lang,
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
attrs: { lang: { default: null } },
|
|
45
|
+
toDOM(node) {
|
|
46
|
+
const { lang } = node.attrs;
|
|
47
|
+
return ['pre', { lang }, ['code', 0]];
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
getInputRules(type) {
|
|
52
|
+
/// Given a code block node type, returns an input rule that turns a
|
|
53
|
+
/// textblock starting with three backticks into a code block.
|
|
54
|
+
return [
|
|
55
|
+
textblockTypeInputRule(/^```$/, type),
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
import { Extension } from '../../../editor/src/mod.js';
|
|
3
|
+
type Color = string;
|
|
4
|
+
export interface SelectionState {
|
|
5
|
+
clientId: number;
|
|
6
|
+
user: {
|
|
7
|
+
name: string;
|
|
8
|
+
color: Color;
|
|
9
|
+
colorLight: Color;
|
|
10
|
+
};
|
|
11
|
+
cursor?: {
|
|
12
|
+
anchor: number;
|
|
13
|
+
head: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export { remoteSelectionPluginKey } from './remoteSelectionPlugin.js';
|
|
17
|
+
export declare class ExtensionRemoteSelection extends Extension {
|
|
18
|
+
name: string;
|
|
19
|
+
private remoteStates;
|
|
20
|
+
getProseMirrorPlugins(): Plugin[];
|
|
21
|
+
getRemoteStates(): SelectionState[];
|
|
22
|
+
setRemoteStates(states: SelectionState[]): void;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=ExtensionRemoteSelection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionRemoteSelection.d.ts","sourceRoot":"","sources":["../../../../src/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAmB,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAIxE,KAAK,KAAK,GAAG,MAAM,CAAC;AAEpB,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,KAAK,CAAC;QACb,UAAU,EAAE,KAAK,CAAC;KACnB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,qBAAa,wBAAyB,SAAQ,SAAS;IAC5C,IAAI,SAAsB;IAEnC,OAAO,CAAC,YAAY,CAAwB;IAEnC,qBAAqB,IAAI,MAAM,EAAE;IAM1C,eAAe,IAAI,cAAc,EAAE;IAInC,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE;CAOzC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Extension } from '../../../editor/src/mod.js';
|
|
2
|
+
import { remoteSelectionPlugin } from './remoteSelectionPlugin.js';
|
|
3
|
+
export { remoteSelectionPluginKey } from './remoteSelectionPlugin.js';
|
|
4
|
+
export class ExtensionRemoteSelection extends Extension {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
Object.defineProperty(this, "name", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: 'remote-selection'
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "remoteStates", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: []
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
getProseMirrorPlugins() {
|
|
21
|
+
return [
|
|
22
|
+
remoteSelectionPlugin(this, this.editor),
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
getRemoteStates() {
|
|
26
|
+
return this.remoteStates;
|
|
27
|
+
}
|
|
28
|
+
setRemoteStates(states) {
|
|
29
|
+
this.remoteStates = states;
|
|
30
|
+
const event = new CustomEvent('remoteSelectionChange', {
|
|
31
|
+
detail: {},
|
|
32
|
+
});
|
|
33
|
+
this.editor.dispatchEvent(event);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { type DecorationAttrs } from 'prosemirror-view';
|
|
3
|
+
import type { CoreEditor } from '../../../editor/src/mod.js';
|
|
4
|
+
import type { ExtensionRemoteSelection } from './ExtensionRemoteSelection.js';
|
|
5
|
+
export declare const remoteSelectionPluginKey: PluginKey<any>;
|
|
6
|
+
/**
|
|
7
|
+
* Default generator for a cursor element
|
|
8
|
+
*/
|
|
9
|
+
export declare const defaultCursorBuilder: (user: any) => HTMLElement;
|
|
10
|
+
/**
|
|
11
|
+
* Default generator for the selection attributes
|
|
12
|
+
*/
|
|
13
|
+
export declare const defaultSelectionBuilder: (user: any) => DecorationAttrs;
|
|
14
|
+
export declare const createDecorations: (state: any, extension: ExtensionRemoteSelection, createCursor: (user: {
|
|
15
|
+
name: string;
|
|
16
|
+
color: string;
|
|
17
|
+
}, clientId: number) => Element, createSelection: (user: {
|
|
18
|
+
name: string;
|
|
19
|
+
color: string;
|
|
20
|
+
}, clientId: number) => DecorationAttrs) => any;
|
|
21
|
+
export declare const remoteSelectionPlugin: (extension: ExtensionRemoteSelection, editor: CoreEditor, { cursorBuilder, selectionBuilder, }?: {
|
|
22
|
+
cursorBuilder?: (user: any, clientId: number) => HTMLElement;
|
|
23
|
+
selectionBuilder?: (user: any, clientId: number) => DecorationAttrs;
|
|
24
|
+
}) => Plugin<any>;
|
|
25
|
+
//# sourceMappingURL=remoteSelectionPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remoteSelectionPlugin.d.ts","sourceRoot":"","sources":["../../../../src/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAE9E,eAAO,MAAM,wBAAwB,gBAAoC,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,MAAM,GAAG,KAAG,WAahD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAAI,MAAM,GAAG,KAAG,eAKnD,CAAC;AAIF,eAAO,MAAM,iBAAiB,GAC5B,OAAO,GAAG,EACV,WAAW,wBAAwB,EACnC,cAAc,CACZ,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EACrC,QAAQ,EAAE,MAAM,KACb,OAAO,EACZ,iBAAiB,CACf,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EACrC,QAAQ,EAAE,MAAM,KACb,eAAe,KACnB,GAwDF,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,WAAW,wBAAwB,EACnC,QAAQ,UAAU,EAClB,uCAGG;IACD,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,KAAK,WAAW,CAAC;IAC7D,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,KAAK,eAAe,CAAC;CAChE,gBAsCP,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
2
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
3
|
+
export const remoteSelectionPluginKey = new PluginKey('remote-selection');
|
|
4
|
+
/**
|
|
5
|
+
* Default generator for a cursor element
|
|
6
|
+
*/
|
|
7
|
+
export const defaultCursorBuilder = (user) => {
|
|
8
|
+
const cursor = document.createElement('span');
|
|
9
|
+
cursor.classList.add('kb-yjs__cursor');
|
|
10
|
+
cursor.setAttribute('style', `border-color: ${user.color};`);
|
|
11
|
+
const userDiv = document.createElement('div');
|
|
12
|
+
userDiv.setAttribute('style', `background-color: ${user.color}`);
|
|
13
|
+
userDiv.insertBefore(document.createTextNode(user.name), null);
|
|
14
|
+
const nonbreakingSpace1 = document.createTextNode('\u2060');
|
|
15
|
+
const nonbreakingSpace2 = document.createTextNode('\u2060');
|
|
16
|
+
cursor.insertBefore(nonbreakingSpace1, null);
|
|
17
|
+
cursor.insertBefore(userDiv, null);
|
|
18
|
+
cursor.insertBefore(nonbreakingSpace2, null);
|
|
19
|
+
return cursor;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Default generator for the selection attributes
|
|
23
|
+
*/
|
|
24
|
+
export const defaultSelectionBuilder = (user) => {
|
|
25
|
+
return {
|
|
26
|
+
style: `background-color: ${user.color}70`,
|
|
27
|
+
class: 'kb-yjs__selection',
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const rxValidColor = /^#[0-9a-fA-F]{6}$/;
|
|
31
|
+
export const createDecorations = (state, extension, createCursor, createSelection) => {
|
|
32
|
+
const decorations = [];
|
|
33
|
+
const remoteStates = extension.getRemoteStates();
|
|
34
|
+
if (remoteStates.length === 0) {
|
|
35
|
+
return DecorationSet.create(state.doc, []);
|
|
36
|
+
}
|
|
37
|
+
for (const remoteState of remoteStates) {
|
|
38
|
+
if (remoteState.cursor != null) {
|
|
39
|
+
const user = remoteState.user || {};
|
|
40
|
+
if (user.color == null) {
|
|
41
|
+
user.color = '#ffa500';
|
|
42
|
+
}
|
|
43
|
+
else if (!rxValidColor.test(user.color)) {
|
|
44
|
+
// We only support 6-digit RGB colors in y-prosemirror
|
|
45
|
+
console.warn('A user uses an unsupported color format', user);
|
|
46
|
+
}
|
|
47
|
+
if (user.name == null) {
|
|
48
|
+
user.name = `User: ${remoteState.clientId}`;
|
|
49
|
+
}
|
|
50
|
+
const cursor = remoteState.cursor;
|
|
51
|
+
let anchor = cursor.anchor || null;
|
|
52
|
+
let head = cursor.head || null;
|
|
53
|
+
if (anchor !== null && head !== null) {
|
|
54
|
+
const maxsize = Math.max(state.doc.content.size - 1, 0);
|
|
55
|
+
anchor = Math.min(anchor, maxsize);
|
|
56
|
+
head = Math.min(head, maxsize);
|
|
57
|
+
decorations.push(Decoration.widget(head, () => createCursor(user, remoteState.clientId), {
|
|
58
|
+
key: remoteState.clientId + '',
|
|
59
|
+
side: 10,
|
|
60
|
+
}));
|
|
61
|
+
const from = Math.min(anchor, head);
|
|
62
|
+
const to = Math.max(anchor, head);
|
|
63
|
+
decorations.push(Decoration.inline(from, to, createSelection(user, remoteState.clientId), {
|
|
64
|
+
inclusiveEnd: true,
|
|
65
|
+
inclusiveStart: false,
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return DecorationSet.create(state.doc, decorations);
|
|
71
|
+
};
|
|
72
|
+
export const remoteSelectionPlugin = (extension, editor, { cursorBuilder = defaultCursorBuilder, selectionBuilder = defaultSelectionBuilder, } = {}) => {
|
|
73
|
+
return new Plugin({
|
|
74
|
+
key: remoteSelectionPluginKey,
|
|
75
|
+
state: {
|
|
76
|
+
init(_, state) {
|
|
77
|
+
return createDecorations(state, extension, cursorBuilder, selectionBuilder);
|
|
78
|
+
},
|
|
79
|
+
apply(tr, prevState, _oldState, newState) {
|
|
80
|
+
const remoteCursorState = tr.getMeta(remoteSelectionPluginKey);
|
|
81
|
+
// TODO validate: isChangeOrigin
|
|
82
|
+
// const state = remoteSelectionPluginKey.getState(newState);
|
|
83
|
+
if ((remoteCursorState?.isChangeOrigin) ||
|
|
84
|
+
(remoteCursorState?.remotePositionUpdated)) {
|
|
85
|
+
return createDecorations(newState, extension, cursorBuilder, selectionBuilder);
|
|
86
|
+
}
|
|
87
|
+
return prevState.map(tr.mapping, tr.doc);
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
props: {
|
|
91
|
+
decorations: (state) => {
|
|
92
|
+
return remoteSelectionPluginKey.getState(state);
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
};
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import "../../_dnt.polyfills.js";
|
|
2
|
+
import { Schema } from 'prosemirror-model';
|
|
3
|
+
import { AnyExtensionOrReq, type Converter, type CoreEditor, Extension } from '../../editor/src/mod.js';
|
|
4
|
+
import { NodeCodeMirrorConfig } from './NodeCodeMirror.js';
|
|
2
5
|
export * from './NodeCodeMirror.js';
|
|
3
|
-
export
|
|
6
|
+
export interface ExtensionCodeMirrorConfig {
|
|
7
|
+
languageWhitelist?: NodeCodeMirrorConfig['languageWhitelist'];
|
|
8
|
+
theme?: NodeCodeMirrorConfig['theme'];
|
|
9
|
+
readOnly?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class ExtensionCodeMirror extends Extension {
|
|
12
|
+
protected config: ExtensionCodeMirrorConfig;
|
|
13
|
+
name: string;
|
|
14
|
+
requires: AnyExtensionOrReq[];
|
|
15
|
+
constructor(config: ExtensionCodeMirrorConfig);
|
|
16
|
+
getConverters(editor: CoreEditor, schema: Schema): Record<string, Converter>;
|
|
4
17
|
}
|
|
5
18
|
//# sourceMappingURL=ExtensionCodeMirror.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionCodeMirror.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/ExtensionCodeMirror.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"ExtensionCodeMirror.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/ExtensionCodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,EAAQ,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EACL,iBAAiB,EACjB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,SAAS,EACV,MAAM,yBAAyB,CAAC;AAEjC,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,4 +1,76 @@
|
|
|
1
|
-
|
|
1
|
+
import "../../_dnt.polyfills.js";
|
|
2
|
+
import { Extension, } from '../../editor/src/mod.js';
|
|
3
|
+
import { createNodeFromObject } from '../../editor/src/utilities/mod.js';
|
|
4
|
+
import { NodeCodeMirror } from './NodeCodeMirror.js';
|
|
2
5
|
export * from './NodeCodeMirror.js';
|
|
3
|
-
export class ExtensionCodeMirror {
|
|
6
|
+
export class ExtensionCodeMirror extends Extension {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
super(config);
|
|
9
|
+
Object.defineProperty(this, "config", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: config
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "name", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: 'code-mirror'
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "requires", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
});
|
|
27
|
+
this.requires = [
|
|
28
|
+
new NodeCodeMirror({
|
|
29
|
+
languageWhitelist: config.languageWhitelist,
|
|
30
|
+
theme: config.theme,
|
|
31
|
+
}),
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
getConverters(editor, schema) {
|
|
35
|
+
return {
|
|
36
|
+
'text/code-only': {
|
|
37
|
+
fromDoc: async (document) => {
|
|
38
|
+
const retVal = [];
|
|
39
|
+
if (document.content) {
|
|
40
|
+
for (const node of document.content.toJSON()) {
|
|
41
|
+
if ('code_block' === node.type && Array.isArray(node.content)) {
|
|
42
|
+
for (const content of node.content) {
|
|
43
|
+
retVal.push(content.text);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return new TextEncoder().encode(retVal.join(''));
|
|
49
|
+
},
|
|
50
|
+
toDoc: async (buffer) => {
|
|
51
|
+
const code = new TextDecoder().decode(buffer);
|
|
52
|
+
const content = {
|
|
53
|
+
'type': 'doc_code',
|
|
54
|
+
'content': [
|
|
55
|
+
{
|
|
56
|
+
'type': 'code_block',
|
|
57
|
+
'attrs': {
|
|
58
|
+
'lang': schema.topNodeType.spec.defaultAttrs?.lang,
|
|
59
|
+
},
|
|
60
|
+
'content': [
|
|
61
|
+
{
|
|
62
|
+
'type': 'text',
|
|
63
|
+
'text': code,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
return createNodeFromObject(content, schema, {
|
|
70
|
+
errorOnInvalidContent: false,
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
4
76
|
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
2
|
+
import type { NodeType } from 'prosemirror-model';
|
|
3
|
+
import { type CoreEditor } from '../../editor/src/mod.js';
|
|
4
4
|
import { type CommandFactories, type CommandShortcuts } from '../../editor/src/commands/mod.js';
|
|
5
|
-
import {
|
|
5
|
+
import { NodeCodeBlock } from '../../extension-basic-editor/src/NodeCodeBlock.js';
|
|
6
|
+
import { CodeBlockSettings } from './types.js';
|
|
6
7
|
export declare const codeMirrorBlockKey: PluginKey<any>;
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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);
|
|
12
16
|
getCommandFactories(editor: CoreEditor, type: NodeType): Partial<CommandFactories>;
|
|
13
17
|
getKeyboardShortcuts(): Partial<CommandShortcuts>;
|
|
14
|
-
getProseMirrorPlugins(
|
|
18
|
+
getProseMirrorPlugins(): Plugin[];
|
|
15
19
|
}
|
|
16
20
|
//# sourceMappingURL=NodeCodeMirror.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeCodeMirror.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/NodeCodeMirror.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NodeCodeMirror.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/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,yBAAyB,CAAC;AAE1D,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAElF,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"}
|