From 454d9befdec0586987fa0da650aa1c40db1d84a3 Mon Sep 17 00:00:00 2001 From: sibiraj-s Date: Mon, 25 Jan 2021 23:15:18 +0530 Subject: [PATCH] chore: fix code_mirror example --- demo/src/app/app.component.ts | 2 +- .../custom-menu/custom-menu.component.ts | 4 +-- demo/src/app/doc.ts | 2 +- demo/src/app/nodeviews/index.ts | 2 +- demo/src/app/schema.ts | 29 +++++++++---------- docs/codemirror.md | 4 +-- docs/menu.md | 4 +-- 7 files changed, 22 insertions(+), 25 deletions(-) diff --git a/demo/src/app/app.component.ts b/demo/src/app/app.component.ts index f5415567..b8bd105d 100644 --- a/demo/src/app/app.component.ts +++ b/demo/src/app/app.component.ts @@ -34,7 +34,7 @@ export class AppComponent implements OnInit, OnDestroy { ]; form = new FormGroup({ - editorContent: new FormControl(jsonDoc, Validators.required()) + editorContent: new FormControl(jsonDoc, Validators.required(schema)) }); get doc(): AbstractControl { diff --git a/demo/src/app/components/custom-menu/custom-menu.component.ts b/demo/src/app/components/custom-menu/custom-menu.component.ts index fcbd36e6..a1862b3c 100644 --- a/demo/src/app/components/custom-menu/custom-menu.component.ts +++ b/demo/src/app/components/custom-menu/custom-menu.component.ts @@ -31,13 +31,13 @@ export class CustomMenuComponent implements OnInit { return setBlockType(schema.nodes.paragraph)(state, dispatch); } - return setBlockType(schema.nodes.code_block)(state, dispatch); + return setBlockType(schema.nodes.code_mirror)(state, dispatch); } update = (view: EditorView) => { const { state } = view; const { schema } = state; - this.isActive = isNodeActive(state, schema.nodes.code_block); + this.isActive = isNodeActive(state, schema.nodes.code_mirror); this.isDisabled = !this.execute(state, null); // returns true if executable } diff --git a/demo/src/app/doc.ts b/demo/src/app/doc.ts index 59d0104f..0bd3e3d6 100644 --- a/demo/src/app/doc.ts +++ b/demo/src/app/doc.ts @@ -176,7 +176,7 @@ export default { ] }, { - type: 'code_block', + type: 'code_mirror', content: [ { type: 'text', diff --git a/demo/src/app/nodeviews/index.ts b/demo/src/app/nodeviews/index.ts index 464e7272..08a8fada 100644 --- a/demo/src/app/nodeviews/index.ts +++ b/demo/src/app/nodeviews/index.ts @@ -4,7 +4,7 @@ import { EditorView } from 'prosemirror-view'; import CodeBlockView from './CodeMirror'; const nodeViews = { - code_block: (node: ProsemirrorNode, view: EditorView, getPos: () => number) => { + code_mirror: (node: ProsemirrorNode, view: EditorView, getPos: () => number) => { return new CodeBlockView(node, view, getPos); } }; diff --git a/demo/src/app/schema.ts b/demo/src/app/schema.ts index a73db67b..d807489a 100644 --- a/demo/src/app/schema.ts +++ b/demo/src/app/schema.ts @@ -1,25 +1,22 @@ import { nodes as basicNodes, marks } from 'ngx-editor'; -import { Schema, Node as ProsemirrorNode, NodeSpec, DOMOutputSpec } from 'prosemirror-model'; +import { Schema, NodeSpec, DOMOutputSpec } from 'prosemirror-model'; const codeMirror: NodeSpec = { + content: 'text*', + marks: '', group: 'block', - attrs: { - text: { default: '' }, - language: { default: 'text/javascript' } - }, - parseDOM: [{ - tag: 'pre', - getAttrs: (dom: HTMLElement) => { - return { - text: dom.textContent, - language: dom.getAttribute('data-language') || 'text/plain' - }; + code: true, + defining: true, + isolating: true, + parseDOM: [ + { + tag: 'pre', + preserveWhitespace: 'full' } - } ], - toDOM(node: ProsemirrorNode): DOMOutputSpec { - return ['pre', { 'data-language': node.attrs.language }, node.attrs.text]; - } + toDOM(): DOMOutputSpec { + return ['pre', ['code', 0]]; + }, }; const nodes = { diff --git a/docs/codemirror.md b/docs/codemirror.md index 5ebbae04..7cfdc453 100644 --- a/docs/codemirror.md +++ b/docs/codemirror.md @@ -213,8 +213,8 @@ import schema from './schema.ts'; new Editor({ schema, nodeViews: { - code_block: ( - // first define schema `code_block`. see schema section + code_mirror: ( + // first define schema `code_mirror`. see schema section node: ProsemirrorNode, view: EditorView, getPos: () => number diff --git a/docs/menu.md b/docs/menu.md index 95a88f81..218639fc 100644 --- a/docs/menu.md +++ b/docs/menu.md @@ -124,13 +124,13 @@ export class CustomMenuComponent implements OnInit { return setBlockType(schema.nodes.paragraph)(state, dispatch); } - return setBlockType(schema.nodes.code_block)(state, dispatch); + return setBlockType(schema.nodes.code_mirror)(state, dispatch); } update = (view: EditorView) => { const { state } = view; const { schema } = state; - this.isActive = isNodeActive(state, schema.nodes.code_block); + this.isActive = isNodeActive(state, schema.nodes.code_mirror); this.isDisabled = !this.execute(state, null); // returns true if executable };