From 48b997af10c4c308d80aeb296b35bac7609e2f45 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Wed, 4 Nov 2020 19:38:18 +0200 Subject: [PATCH] new schema creation --- editors/editoria/src/config/config.js | 4 ++- .../src/SchemaService/Schema.js | 26 ++++++++++--------- .../src/ShortCutsService/ShortCuts.js | 25 +++++++++--------- wax-prosemirror-utilities/index.js | 7 ++--- .../src/schema}/DefaultSchema.js | 0 5 files changed, 34 insertions(+), 28 deletions(-) rename {wax-prosemirror-services/src/SchemaService => wax-prosemirror-utilities/src/schema}/DefaultSchema.js (100%) diff --git a/editors/editoria/src/config/config.js b/editors/editoria/src/config/config.js index dabe19bde..723813162 100644 --- a/editors/editoria/src/config/config.js +++ b/editors/editoria/src/config/config.js @@ -30,6 +30,8 @@ import { TrackingAndEditingToolGroupService, } from 'wax-prosemirror-services'; +import { DefaultSchema } from 'wax-prosemirror-utilities'; + import { WaxSelectionPlugin } from 'wax-prosemirror-plugins'; import invisibles, { @@ -62,7 +64,7 @@ export default { }, ], - SchemaService: {}, + SchemaService: DefaultSchema, RulesService: [emDash, ellipsis], ShortCutsService: {}, diff --git a/wax-prosemirror-services/src/SchemaService/Schema.js b/wax-prosemirror-services/src/SchemaService/Schema.js index 34672efc6..304b5a94c 100644 --- a/wax-prosemirror-services/src/SchemaService/Schema.js +++ b/wax-prosemirror-services/src/SchemaService/Schema.js @@ -1,8 +1,5 @@ import { Schema as PmPschema } from 'prosemirror-model'; import { injectable } from 'inversify'; -import { pickBy, identity } from 'lodash'; -import DefaultSchema from './DefaultSchema'; - import Node from './Node'; import Mark from './Mark'; @@ -83,7 +80,7 @@ class Schema { } getSchema() { - const nodes = DefaultSchema.nodes; + const nodes = {}; const marks = {}; // console.log(this._nodes); @@ -96,15 +93,20 @@ class Schema { } this.schema = new PmPschema({ - nodes: pickBy( - Object.assign(nodes, this.prosemirrorSchema.nodes), - identity, - ), - marks: pickBy( - Object.assign(marks, this.prosemirrorSchema.marks), - identity, - ), + nodes: Object.assign(this.prosemirrorSchema.nodes, nodes), + marks: Object.assign(this.prosemirrorSchema.marks, marks), }); + + // this.schema = new PmPschema({ + // nodes: pickBy( + // Object.assign(nodes, this.prosemirrorSchema.nodes), + // identity, + // ), + // marks: pickBy( + // Object.assign(marks, this.prosemirrorSchema.marks), + // identity, + // ), + // }); return this.schema; } } diff --git a/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js b/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js index 87660df9b..7e420653d 100644 --- a/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js +++ b/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js @@ -58,6 +58,18 @@ const backSpaceShortCut = (state, dispatch, view) => { ); }; +const pressEnter = (state, dispatch) => { + // LISTS + console.log(state); + console.log('lisr', splitListItem(state.schema.nodes.list_item)(state)); + splitListItem(state.schema.nodes.list_item)(state, dispatch); + if (splitListItem(state.schema.nodes.list_item)(state)) { + return true; + } + + return false; +}; + const undoShortCut = (state, dispatch, view) => undo(state, tr => dispatch(tr.setMeta('inputType', 'Undo')), view); @@ -68,7 +80,6 @@ const redoShortCut = (state, dispatch, view) => class ShortCuts { constructor(plugins, schema) { this.insertBreak = this.insertBreak.bind(this); - this.pressEnter = this.pressEnter.bind(this); this.insertRule = this.insertRule.bind(this); this.PmPlugins = plugins; this.schema = schema; @@ -81,16 +92,6 @@ class ShortCuts { return true; } - pressEnter(state, dispatch) { - // LISTS - if (splitListItem(this.schema.nodes.list_item)(state)) { - splitListItem(this.schema.nodes.list_item)(state, dispatch); - return true; - } - - return false; - } - insertRule(state, dispatch) { const hr = this.schema.nodes.horizontal_rule.create(); dispatch(state.tr.replaceSelectionWith(hr).scrollIntoView()); @@ -131,7 +132,7 @@ class ShortCuts { 'Mod-_': this.insertRule, 'Mod-[': liftListItem(this.schema.nodes.list_item), 'Mod-]': sinkListItem(this.schema.nodes.list_item), - Enter: this.pressEnter, + Enter: pressEnter, 'Shift-Ctrl-8': wrapInList(this.schema.nodes.bulletlist), 'Shift-Ctrl-9': wrapInList(this.schema.nodes.orderedlist), }; diff --git a/wax-prosemirror-utilities/index.js b/wax-prosemirror-utilities/index.js index 6996a4213..5abfc3886 100644 --- a/wax-prosemirror-utilities/index.js +++ b/wax-prosemirror-utilities/index.js @@ -1,3 +1,4 @@ -export { default as SchemaHelpers } from "./src/schema/SchemaHelpers"; -export { default as DocumentHelpers } from "./src/document/DocumentHelpers"; -export { default as Commands } from "./src/commands/Commands"; +export { default as SchemaHelpers } from './src/schema/SchemaHelpers'; +export { default as DocumentHelpers } from './src/document/DocumentHelpers'; +export { default as Commands } from './src/commands/Commands'; +export { default as DefaultSchema } from './src/schema/DefaultSchema'; diff --git a/wax-prosemirror-services/src/SchemaService/DefaultSchema.js b/wax-prosemirror-utilities/src/schema/DefaultSchema.js similarity index 100% rename from wax-prosemirror-services/src/SchemaService/DefaultSchema.js rename to wax-prosemirror-utilities/src/schema/DefaultSchema.js -- GitLab