From 813932c82dd991f9e78c78f72897710e9c576c2e Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Sat, 26 Mar 2022 13:23:44 +0200 Subject: [PATCH] fix rules --- wax-prosemirror-core/src/Application.js | 2 +- wax-prosemirror-core/src/WaxView.js | 13 ++++--------- .../src/LinkService/LinkService.js | 5 ++++- .../src/MathService/BlockInputRule.js | 8 +------- .../src/MathService/MathService.js | 8 ++++++-- wax-prosemirror-services/src/RulesService/Rules.js | 8 +------- .../src/RulesService/RulesService.js | 3 +-- 7 files changed, 18 insertions(+), 29 deletions(-) diff --git a/wax-prosemirror-core/src/Application.js b/wax-prosemirror-core/src/Application.js index 5b5c089c0..33d89fade 100644 --- a/wax-prosemirror-core/src/Application.js +++ b/wax-prosemirror-core/src/Application.js @@ -77,7 +77,7 @@ export default class Application { this.PmPlugins = {}; this.schema = {}; this.shortCuts = {}; - this.rules = []; + this.rules = {}; } static create(config) { diff --git a/wax-prosemirror-core/src/WaxView.js b/wax-prosemirror-core/src/WaxView.js index bf9cfb857..4eac61ebe 100644 --- a/wax-prosemirror-core/src/WaxView.js +++ b/wax-prosemirror-core/src/WaxView.js @@ -46,7 +46,6 @@ const WaxView = forwardRef((props, ref) => { } = props; const WaxEditorRef = useRef(); - const [mounted, setMounted] = useState(false); const context = useContext(WaxContext); const { createPortal } = useContext(PortalContext); @@ -54,12 +53,6 @@ const WaxView = forwardRef((props, ref) => { const schema = context.app.getSchema(); - if (!mounted) { - context.app.bootServices(); - context.app.getShortCuts(); - context.app.getRules(); - } - const setEditorRef = useCallback( // eslint-disable-next-line consistent-return node => { @@ -69,6 +62,10 @@ const WaxView = forwardRef((props, ref) => { // clean up the unmount if you need to. } if (node) { + context.app.bootServices(); + context.app.getShortCuts(); + context.app.getRules(); + const options = WaxOptions({ ...props, schema, @@ -100,8 +97,6 @@ const WaxView = forwardRef((props, ref) => { }, ); - setMounted(true); - context.updateView( { main: view, diff --git a/wax-prosemirror-services/src/LinkService/LinkService.js b/wax-prosemirror-services/src/LinkService/LinkService.js index 68c92c1a2..f89d026c9 100644 --- a/wax-prosemirror-services/src/LinkService/LinkService.js +++ b/wax-prosemirror-services/src/LinkService/LinkService.js @@ -10,6 +10,9 @@ export default class LinkService extends Service { boot() { const createOverlay = this.container.get('CreateOverlay'); const createRule = this.container.get('CreateRule'); + const { + schema: { schema }, + } = this.app; createOverlay( LinkComponent, {}, @@ -19,7 +22,7 @@ export default class LinkService extends Service { selection: false, }, ); - // createRule([linkRule(this.schema.marks.link)]); + createRule([linkRule(schema.marks.link)]); } register() { diff --git a/wax-prosemirror-services/src/MathService/BlockInputRule.js b/wax-prosemirror-services/src/MathService/BlockInputRule.js index fbfb5067c..2ca7c9094 100644 --- a/wax-prosemirror-services/src/MathService/BlockInputRule.js +++ b/wax-prosemirror-services/src/MathService/BlockInputRule.js @@ -6,13 +6,7 @@ const blockInputRule = (pattern, nodeType, getAttrs) => { return new InputRule(pattern, (state, match, start, end) => { let $start = state.doc.resolve(start); let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; - console.log( - !$start - .node(-1) - .canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType), - nodeType, - $start.node(-1), - ); + if ( !$start .node(-1) diff --git a/wax-prosemirror-services/src/MathService/MathService.js b/wax-prosemirror-services/src/MathService/MathService.js index 12f54b4b7..5e0e26498 100644 --- a/wax-prosemirror-services/src/MathService/MathService.js +++ b/wax-prosemirror-services/src/MathService/MathService.js @@ -16,9 +16,13 @@ class MathService extends Service { this.app.PmPlugins.add('mathplugin', mathPlugin); this.app.PmPlugins.add('mathselectplugin', mathSelectPlugin); const createRule = this.container.get('CreateRule'); + const { + schema: { schema }, + } = this.app; + createRule([ - blockInputRule(/^\$\$\s+$/, this.schema.nodes.math_display), - inlineInputRule(/(?!\\)\$(.+)(?!\\)\$/, this.schema.nodes.math_inline), + blockInputRule(/^\$\$\s+$/, schema.nodes.math_display), + inlineInputRule(/(?!\\)\$(.+)(?!\\)\$/, schema.nodes.math_inline), ]); } diff --git a/wax-prosemirror-services/src/RulesService/Rules.js b/wax-prosemirror-services/src/RulesService/Rules.js index b682ddb74..6b4ebacab 100644 --- a/wax-prosemirror-services/src/RulesService/Rules.js +++ b/wax-prosemirror-services/src/RulesService/Rules.js @@ -1,10 +1,5 @@ import { injectable } from 'inversify'; -import { - inputRules, - wrappingInputRule, - textblockTypeInputRule, - smartQuotes, -} from 'prosemirror-inputrules'; +import { inputRules, smartQuotes } from 'prosemirror-inputrules'; const defaultRules = [ ...smartQuotes, @@ -38,7 +33,6 @@ class Rules { extendedRules = defaultRules; addRule(rule) { this.extendedRules.push(...rule); - // this.extendedRules = defaultRules.concat(...rule); } createRules() { diff --git a/wax-prosemirror-services/src/RulesService/RulesService.js b/wax-prosemirror-services/src/RulesService/RulesService.js index 529054a37..92e8d7f48 100644 --- a/wax-prosemirror-services/src/RulesService/RulesService.js +++ b/wax-prosemirror-services/src/RulesService/RulesService.js @@ -7,14 +7,13 @@ export default class RulesService extends Service { boot() { const configRules = this.app.config.get('config.RulesService'); const createRule = this.container.get('CreateRule'); - // if (configRules) createRule(configRules); + if (configRules) createRule(configRules); } register() { this.container.bind('Rules').to(Rules).inSingletonScope(); this.container.bind('CreateRule').toFactory(context => { return rule => { - console.log(rule); const ruleInstance = context.container.get('Rules'); ruleInstance.addRule(rule); }; -- GitLab