diff --git a/editors/editoria/src/config/config.js b/editors/editoria/src/config/config.js index 82fb3775f1ed02ff8924f5e6641e27626487ccd4..4138b0607514616730b31bb6808487fce7f35768 100644 --- a/editors/editoria/src/config/config.js +++ b/editors/editoria/src/config/config.js @@ -13,7 +13,7 @@ export default { ], RulesService: [ { - rules: [emDash, ellipsis] + rules: [ellipsis] } ] }; diff --git a/wax-prosemirror-core/src/Config/defaultConfig.js b/wax-prosemirror-core/src/Config/defaultConfig.js index 7cb00a6322aa70c361c6ddb1f44b176ac1507360..10ea27853f1331c5715b35451e9d618a0a9c4648 100644 --- a/wax-prosemirror-core/src/Config/defaultConfig.js +++ b/wax-prosemirror-core/src/Config/defaultConfig.js @@ -11,13 +11,13 @@ import { export default { services: [ + new RulesService(), new LayoutService(), new MenuService(), new RedoUndoService(), new AnnotationService(), new TextStyleService(), new PlaceholderService(), - new ImageService(), - new RulesService() + new ImageService() ] }; diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js index 0665cda4fb9aeee6101aaa745aa7c11f95e493dc..91666d49e8e39fc959521f1247b3d3f2b613be6e 100644 --- a/wax-prosemirror-core/src/Wax.js +++ b/wax-prosemirror-core/src/Wax.js @@ -51,6 +51,7 @@ class Wax extends Component { const { value, onChange, options } = this.props; const { schema, plugins, keys, rules } = options; const WaxOnchange = onChange ? onChange : value => true; + this.application.bootServices(); // const WaxShortCuts = keys // ? keys @@ -63,7 +64,7 @@ class Wax extends Component { placeholder({ content: this.props.placeholder }), ...this.application.getPlugins() ]); - + console.log("cretated?"); this.WaxOptions = { schema, plugins: finalPlugins @@ -73,8 +74,6 @@ class Wax extends Component { const serialize = serializer(schema); this.WaxOptions.doc = parse(editorContent); - this.application.bootServices(); - this.onChange = debounce( value => { WaxOnchange(serialize(value)); diff --git a/wax-prosemirror-plugins/src/PlaceholderService/PlaceholderService.js b/wax-prosemirror-plugins/src/PlaceholderService/PlaceholderService.js index a3c08b71fb520b0f3e4670aaf9d86843d1fb1e18..0b16f671fe33a653d0055426e94cb7946f8ba796 100644 --- a/wax-prosemirror-plugins/src/PlaceholderService/PlaceholderService.js +++ b/wax-prosemirror-plugins/src/PlaceholderService/PlaceholderService.js @@ -1,11 +1,14 @@ import Service from "wax-prosemirror-core/src/services/Service"; import placeholderPlugin from "./pmPlugins/placeholderPlugin"; const PLUGIN_KEY = "imagePlaceHolder"; +import { emDash } from "prosemirror-inputrules"; export default class PlaceholderService extends Service { name = "PlaceholderService"; register() { + const rules = this.container.get("Rules"); + rules.addRule([emDash]); this.app.PmPlugins.add(PLUGIN_KEY, placeholderPlugin(PLUGIN_KEY)); } } diff --git a/wax-prosemirror-plugins/src/RulesService/Rules.js b/wax-prosemirror-plugins/src/RulesService/Rules.js index e2c79deda440963c54cb8e0c4d9918ffef42ae5b..041ac1c75f8dc75b4158121de163ce8e3de256e6 100644 --- a/wax-prosemirror-plugins/src/RulesService/Rules.js +++ b/wax-prosemirror-plugins/src/RulesService/Rules.js @@ -11,43 +11,45 @@ class Rules { constructor(schema, plugins) { this.PmPlugins = plugins; this.schema = schema; + this.extendedRules = this.allRules(); } addRule(rules) { - const rulesCreated = inputRules(this.allRules(rules)); + this.extendedRules.push(...rules); + } + + createRules() { + const rulesCreated = inputRules({ rules: this.extendedRules }); this.PmPlugins.add("rules", rulesCreated); } - allRules(rules = []) { - return { - rules: [ - ...smartQuotes, - ...rules, - // > blockquote - wrappingInputRule(/^\s*>\s$/, this.schema.nodes.blockquote), - - // 1. ordered list - wrappingInputRule( - /^(\d+)\.\s$/, - this.schema.nodes.ordered_list, - match => ({ order: +match[1] }), - (match, node) => node.childCount + node.attrs.order === +match[1] - ), - - // * bullet list - wrappingInputRule(/^\s*([-+*])\s$/, this.schema.nodes.bullet_list), - - // ``` code block - textblockTypeInputRule(/^```$/, this.schema.nodes.code_block), - - // # heading - textblockTypeInputRule( - new RegExp("^(#{1,6})\\s$"), - this.schema.nodes.heading, - match => ({ level: match[1].length }) - ) - ] - }; + allRules() { + return [ + ...smartQuotes, + // > blockquote + wrappingInputRule(/^\s*>\s$/, this.schema.nodes.blockquote), + + // 1. ordered list + wrappingInputRule( + /^(\d+)\.\s$/, + this.schema.nodes.ordered_list, + match => ({ order: +match[1] }), + (match, node) => node.childCount + node.attrs.order === +match[1] + ), + + // * bullet list + wrappingInputRule(/^\s*([-+*])\s$/, this.schema.nodes.bullet_list), + + // ``` code block + textblockTypeInputRule(/^```$/, this.schema.nodes.code_block), + + // # heading + textblockTypeInputRule( + new RegExp("^(#{1,6})\\s$"), + this.schema.nodes.heading, + match => ({ level: match[1].length }) + ) + ]; } } diff --git a/wax-prosemirror-plugins/src/RulesService/RulesService.js b/wax-prosemirror-plugins/src/RulesService/RulesService.js index b64f262146d5e6bf31db62fdcc40e8b67f97cf0b..88b8487fc68e15a6224614094569c66f146d0604 100644 --- a/wax-prosemirror-plugins/src/RulesService/RulesService.js +++ b/wax-prosemirror-plugins/src/RulesService/RulesService.js @@ -4,16 +4,19 @@ import Rules from "./Rules"; export default class RulesService extends Service { name = "RulesService"; + boot() { + this.container.get("Rules").createRules(); + } + register() { const { schema } = this.container.get("config").options; - const configRules = this.config[0].rules; const PmPlugins = this.app.PmPlugins; this.container .bind("Rules") .toDynamicValue(() => new Rules(schema, PmPlugins)) .inSingletonScope(); - + const configRules = this.config[0].rules; const rules = this.container.get("Rules"); rules.addRule(configRules); }