diff --git a/wax-prosemirror-core/src/Application.js b/wax-prosemirror-core/src/Application.js index 63b621a865b604a833a1f1011274ef7362b4e7ce..2c1e9a5e6071127f420bef66109871ab318cc357 100644 --- a/wax-prosemirror-core/src/Application.js +++ b/wax-prosemirror-core/src/Application.js @@ -61,11 +61,18 @@ export default class Application { return this.schema.getSchema(); } + getShortCuts() { + this.shortCuts = this.container.get('ShortCuts'); + console.log(this.shortCuts); + this.PmPlugins.add('shortcuts', this.shortCuts.createShortCuts()); + } + resetApp() { this.container = {}; this.config = {}; this.PmPlugins = {}; this.schema = {}; + this.shortCuts = {}; } static create(config) { diff --git a/wax-prosemirror-core/src/WaxView.js b/wax-prosemirror-core/src/WaxView.js index ed62326688b5c55b68d5800ada9ba0ed9a4cd6b7..26b332b0d7c175a8e83ef50eabf3e6a11df4f885 100644 --- a/wax-prosemirror-core/src/WaxView.js +++ b/wax-prosemirror-core/src/WaxView.js @@ -56,6 +56,7 @@ const WaxView = forwardRef((props, ref) => { if (!mounted) { context.app.bootServices(); + context.app.getShortCuts(); } const setEditorRef = useCallback( diff --git a/wax-prosemirror-services/src/ListsService/BulletListService/BulletListService.js b/wax-prosemirror-services/src/ListsService/BulletListService/BulletListService.js index be0192010ee5415109ea4661eed55c7f2157ab02..a415165f3069d88ca075c646911619d141e78e70 100644 --- a/wax-prosemirror-services/src/ListsService/BulletListService/BulletListService.js +++ b/wax-prosemirror-services/src/ListsService/BulletListService/BulletListService.js @@ -1,4 +1,4 @@ -// import { wrapInList } from 'prosemirror-schema-list'; +import { wrapInList } from 'prosemirror-schema-list'; import { bulletListNode } from 'wax-prosemirror-schema'; import Service from '../../Service'; import BulletList from './BulletList'; @@ -7,9 +7,9 @@ class BulletListService extends Service { name = 'BulletListService'; boot() { const shortCuts = this.container.get('ShortCuts'); - // shortCuts.addShortCut({ - // "Shift-Ctrl-8": wrapInList(this.schema.nodes.bulletlist) - // }); + shortCuts.addShortCut({ + 'Shift-Ctrl-8': wrapInList(this.schema.nodes.bulletlist), + }); } register() { diff --git a/wax-prosemirror-services/src/ListsService/LiftService/LiftService.js b/wax-prosemirror-services/src/ListsService/LiftService/LiftService.js index a074a2f82b4786130ec6e651e38323ad6ac17c6e..6ef225cf1e607b10103ccb4797f0e8c4a275a2e2 100644 --- a/wax-prosemirror-services/src/ListsService/LiftService/LiftService.js +++ b/wax-prosemirror-services/src/ListsService/LiftService/LiftService.js @@ -1,18 +1,18 @@ -import Service from "../../Service"; -import { liftListItem, sinkListItem } from "prosemirror-schema-list"; -import Lift from "./Lift"; +import { liftListItem, sinkListItem } from 'prosemirror-schema-list'; +import Service from '../../Service'; +import Lift from './Lift'; class LiftService extends Service { boot() { - const shortCuts = this.container.get("ShortCuts"); - // shortCuts.addShortCut({ - // "Mod-[": liftListItem(this.schema.nodes.list_item), - // "Mod-]": sinkListItem(this.schema.nodes.list_item) - // }); + const shortCuts = this.container.get('ShortCuts'); + shortCuts.addShortCut({ + 'Mod-[': liftListItem(this.schema.nodes.list_item), + 'Mod-]': sinkListItem(this.schema.nodes.list_item), + }); } register() { - this.container.bind("Lift").to(Lift); + this.container.bind('Lift').to(Lift); } } diff --git a/wax-prosemirror-services/src/ListsService/OrderedListService/OrderedListService.js b/wax-prosemirror-services/src/ListsService/OrderedListService/OrderedListService.js index 9c73e4410eb9fcd45dfb4b25b56e21fcbb6eb6d5..c39cb53d0af9170117e7f724433ca7df2cced9d1 100644 --- a/wax-prosemirror-services/src/ListsService/OrderedListService/OrderedListService.js +++ b/wax-prosemirror-services/src/ListsService/OrderedListService/OrderedListService.js @@ -1,15 +1,15 @@ -import Service from '../../Service'; import { wrapInList } from 'prosemirror-schema-list'; import { orderedListNode } from 'wax-prosemirror-schema'; +import Service from '../../Service'; import OrderedList from './OrderedList'; class OrderedListService extends Service { name = 'OrderedListService'; boot() { const shortCuts = this.container.get('ShortCuts'); - // shortCuts.addShortCut({ - // "Shift-Ctrl-9": wrapInList(this.schema.nodes.orderedlist) - // }); + shortCuts.addShortCut({ + 'Shift-Ctrl-9': wrapInList(this.schema.nodes.orderedlist), + }); } register() { diff --git a/wax-prosemirror-services/src/SchemaService/Node.js b/wax-prosemirror-services/src/SchemaService/Node.js index b9d9e6e31723746cdc9de32b653acc25b25d5e62..8fa643f92d8d870c99b6acaae8a72f600831df1e 100644 --- a/wax-prosemirror-services/src/SchemaService/Node.js +++ b/wax-prosemirror-services/src/SchemaService/Node.js @@ -1,3 +1,4 @@ +/* eslint-disable no-underscore-dangle */ import { isPlainObject } from 'lodash'; import ParseRule from './ParseRule'; import Middleware from '../lib/Middleware'; @@ -55,7 +56,7 @@ export default class Node { } toJSON() { - const importer = this.importer; + const { importer } = this; return { atom: this.atom, diff --git a/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js b/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js index 1e08adbbb2e891fc316610fa8ace99d3b296ba07..581e0cc0bc83e9096d43eb950459f60dcc0f6681 100644 --- a/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js +++ b/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js @@ -113,12 +113,12 @@ const redoShortCut = (state, dispatch, view) => redo(state, tr => dispatch(tr.setMeta('inputType', 'Redo')), view); @injectable() -class ShortCuts { - constructor(plugins, schema) { +export default class ShortCuts { + constructor() { this.insertBreak = this.insertBreak.bind(this); this.insertRule = this.insertRule.bind(this); - this.PmPlugins = plugins; - this.schema = schema; + // this.PmPlugins = plugins; + // this.schema = schema; this.keys = this.getKeys(); } @@ -135,13 +135,12 @@ class ShortCuts { } createShortCuts() { - const shortCuts = keymap(this.createKeyBindings()); - this.PmPlugins.add('shortcuts', shortCuts); + this.shortCuts = keymap(this.createKeyBindings()); + return this.shortCuts; } addShortCut(shortcut) { Object.assign(this.keys, shortcut); - this.createShortCuts(); } createKeyBindings() { @@ -166,13 +165,11 @@ class ShortCuts { 'Shift-Enter': chainCommands(exitCode, this.insertBreak), 'Ctrl-Enter': chainCommands(exitCode, this.insertBreak), 'Mod-_': this.insertRule, - 'Mod-[': liftListItem(this.schema.nodes.list_item), - 'Mod-]': sinkListItem(this.schema.nodes.list_item), + // 'Mod-[': liftListItem(this.schema.nodes.list_item), + // 'Mod-]': sinkListItem(this.schema.nodes.list_item), Enter: pressEnter, - 'Shift-Ctrl-8': wrapInList(this.schema.nodes.bulletlist), - 'Shift-Ctrl-9': wrapInList(this.schema.nodes.orderedlist), + // 'Shift-Ctrl-8': wrapInList(this.schema.nodes.bulletlist), + // 'Shift-Ctrl-9': wrapInList(this.schema.nodes.orderedlist), }; } } - -export default ShortCuts; diff --git a/wax-prosemirror-services/src/ShortCutsService/ShortCutsService.js b/wax-prosemirror-services/src/ShortCutsService/ShortCutsService.js index 96d705b12e6fb30e1e7e52807d1af34afb2894d7..e55f3c00754dc99c769f5da38200b1b3bf827833 100644 --- a/wax-prosemirror-services/src/ShortCutsService/ShortCutsService.js +++ b/wax-prosemirror-services/src/ShortCutsService/ShortCutsService.js @@ -4,30 +4,15 @@ import ShortCuts from './ShortCuts'; export default class ShortCutsService extends Service { name = 'ShortCutsService'; - boot() { - const shortCuts = this.container.get('ShortCuts'); - shortCuts.createShortCuts(); - } - // TODO start ShortCuts as Schema is initiated register() { - const { PmPlugins } = this.app; - this.container - .bind('ShortCuts') - .toDynamicValue(() => { - if (this.app.schema) { - const { - schema: { schema }, - } = this.app; - - return new ShortCuts(PmPlugins, schema); - } + this.container.bind('ShortCuts').to(ShortCuts).inSingletonScope(); - return new ShortCuts( - PmPlugins, - this.container.get('Schema').getSchema(), - ); - }) - .inSingletonScope(); + this.container.bind('CreateShortCut').toFactory(context => { + return shortCut => { + const shortCutsInstance = context.container.get('ShortCuts'); + shortCutsInstance.addShortCut(shortCut); + }; + }); } }