From dba8dbb490a4a38fca35dc50631dfbe02c5bc1e7 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Tue, 28 Jul 2020 03:58:44 +0300 Subject: [PATCH] enable tool --- editors/editoria/src/config/config.js | 5 +++++ wax-prosemirror-schema/src/nodes/codeBlockNode.js | 2 +- .../src/CodeBlockService/CodeBlockService.js | 2 +- .../src/CodeBlockService/CodeBlockTool.js | 8 ++++++-- .../WaxToolGroups/CodeBlockToolGroupService/CodeBlock.js | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/editors/editoria/src/config/config.js b/editors/editoria/src/config/config.js index 09caa7d42..5efeb8d0f 100644 --- a/editors/editoria/src/config/config.js +++ b/editors/editoria/src/config/config.js @@ -21,6 +21,8 @@ import { NoteToolGroupService, TrackChangeService, CommentsService, + CodeBlockService, + CodeBlockToolGroupService, } from 'wax-prosemirror-services'; import { WaxSelectionPlugin } from 'wax-prosemirror-plugins'; @@ -45,6 +47,7 @@ export default { 'Lists', 'Images', 'Tables', + 'CodeBlock', ], }, { @@ -86,5 +89,7 @@ export default { new AnnotationToolGroupService(), new NoteToolGroupService(), new ListToolGroupService(), + new CodeBlockService(), + new CodeBlockToolGroupService(), ], }; diff --git a/wax-prosemirror-schema/src/nodes/codeBlockNode.js b/wax-prosemirror-schema/src/nodes/codeBlockNode.js index 18ae5b294..21fbdd2c6 100644 --- a/wax-prosemirror-schema/src/nodes/codeBlockNode.js +++ b/wax-prosemirror-schema/src/nodes/codeBlockNode.js @@ -1,5 +1,5 @@ const codeBlock = { - content: 'text*', + content: 'block+', group: 'block', code: true, defining: true, diff --git a/wax-prosemirror-services/src/CodeBlockService/CodeBlockService.js b/wax-prosemirror-services/src/CodeBlockService/CodeBlockService.js index 29c71105c..1fa6cab70 100644 --- a/wax-prosemirror-services/src/CodeBlockService/CodeBlockService.js +++ b/wax-prosemirror-services/src/CodeBlockService/CodeBlockService.js @@ -6,7 +6,7 @@ export default class CodeBlockService extends Service { boot() {} register() { - this.container.bind('CodeBlock').to(CodeBlockTool); + this.container.bind('CodeBlockTool').to(CodeBlockTool); const createNode = this.container.get('CreateNode'); createNode({ diff --git a/wax-prosemirror-services/src/CodeBlockService/CodeBlockTool.js b/wax-prosemirror-services/src/CodeBlockService/CodeBlockTool.js index 8e7faff1b..bce0d126d 100644 --- a/wax-prosemirror-services/src/CodeBlockService/CodeBlockTool.js +++ b/wax-prosemirror-services/src/CodeBlockService/CodeBlockTool.js @@ -1,14 +1,18 @@ import Tools from '../lib/Tools'; import { injectable } from 'inversify'; import { icons } from 'wax-prosemirror-components'; -import { Fragment } from 'prosemirror-model'; +import { wrapIn } from 'prosemirror-commands'; @injectable() class CodeBlockTool extends Tools { title = 'Insert Code Block'; content = icons.footnote; - get run() {} + get run() { + return (state, dispatch) => { + wrapIn(state.config.schema.nodes.codeblock)(state, dispatch); + }; + } get enable() {} } diff --git a/wax-prosemirror-services/src/WaxToolGroups/CodeBlockToolGroupService/CodeBlock.js b/wax-prosemirror-services/src/WaxToolGroups/CodeBlockToolGroupService/CodeBlock.js index 8ad99cdf3..51fdb7b5e 100644 --- a/wax-prosemirror-services/src/WaxToolGroups/CodeBlockToolGroupService/CodeBlock.js +++ b/wax-prosemirror-services/src/WaxToolGroups/CodeBlockToolGroupService/CodeBlock.js @@ -4,7 +4,7 @@ import ToolGroup from '../../lib/ToolGroup'; @injectable() class CodeBlock extends ToolGroup { tools = []; - constructor(@inject('CodeBlock') codeblock) { + constructor(@inject('CodeBlockTool') codeblock) { super(); this.tools = [codeblock]; } -- GitLab