Skip to content
Snippets Groups Projects
Commit 813932c8 authored by chris's avatar chris
Browse files

fix rules

parent 46d74e2e
No related branches found
No related tags found
1 merge request!388config rules
......@@ -77,7 +77,7 @@ export default class Application {
this.PmPlugins = {};
this.schema = {};
this.shortCuts = {};
this.rules = [];
this.rules = {};
}
static create(config) {
......
......@@ -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,
......
......@@ -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() {
......
......@@ -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)
......
......@@ -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),
]);
}
......
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() {
......
......@@ -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);
};
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment