From c71d4feea5423c432d6895ef30a74e1f2005fcab Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Thu, 17 Mar 2022 10:08:37 +0200 Subject: [PATCH] shoetcuts in progress --- wax-prosemirror-core/src/Application.js | 7 +++++ wax-prosemirror-core/src/WaxView.js | 1 + .../BulletListService/BulletListService.js | 8 ++--- .../ListsService/LiftService/LiftService.js | 18 ++++++------ .../OrderedListService/OrderedListService.js | 8 ++--- .../src/SchemaService/Node.js | 3 +- .../src/ShortCutsService/ShortCuts.js | 23 +++++++-------- .../src/ShortCutsService/ShortCutsService.js | 29 +++++-------------- 8 files changed, 44 insertions(+), 53 deletions(-) diff --git a/wax-prosemirror-core/src/Application.js b/wax-prosemirror-core/src/Application.js index 63b621a86..2c1e9a5e6 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 ed6232668..26b332b0d 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 be0192010..a415165f3 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 a074a2f82..6ef225cf1 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 9c73e4410..c39cb53d0 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 b9d9e6e31..8fa643f92 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 1e08adbbb..581e0cc0b 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 96d705b12..e55f3c007 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); + }; + }); } } -- GitLab