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 { ...@@ -77,7 +77,7 @@ export default class Application {
this.PmPlugins = {}; this.PmPlugins = {};
this.schema = {}; this.schema = {};
this.shortCuts = {}; this.shortCuts = {};
this.rules = []; this.rules = {};
} }
static create(config) { static create(config) {
......
...@@ -46,7 +46,6 @@ const WaxView = forwardRef((props, ref) => { ...@@ -46,7 +46,6 @@ const WaxView = forwardRef((props, ref) => {
} = props; } = props;
const WaxEditorRef = useRef(); const WaxEditorRef = useRef();
const [mounted, setMounted] = useState(false);
const context = useContext(WaxContext); const context = useContext(WaxContext);
const { createPortal } = useContext(PortalContext); const { createPortal } = useContext(PortalContext);
...@@ -54,12 +53,6 @@ const WaxView = forwardRef((props, ref) => { ...@@ -54,12 +53,6 @@ const WaxView = forwardRef((props, ref) => {
const schema = context.app.getSchema(); const schema = context.app.getSchema();
if (!mounted) {
context.app.bootServices();
context.app.getShortCuts();
context.app.getRules();
}
const setEditorRef = useCallback( const setEditorRef = useCallback(
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
node => { node => {
...@@ -69,6 +62,10 @@ const WaxView = forwardRef((props, ref) => { ...@@ -69,6 +62,10 @@ const WaxView = forwardRef((props, ref) => {
// clean up the unmount if you need to. // clean up the unmount if you need to.
} }
if (node) { if (node) {
context.app.bootServices();
context.app.getShortCuts();
context.app.getRules();
const options = WaxOptions({ const options = WaxOptions({
...props, ...props,
schema, schema,
...@@ -100,8 +97,6 @@ const WaxView = forwardRef((props, ref) => { ...@@ -100,8 +97,6 @@ const WaxView = forwardRef((props, ref) => {
}, },
); );
setMounted(true);
context.updateView( context.updateView(
{ {
main: view, main: view,
......
...@@ -10,6 +10,9 @@ export default class LinkService extends Service { ...@@ -10,6 +10,9 @@ export default class LinkService extends Service {
boot() { boot() {
const createOverlay = this.container.get('CreateOverlay'); const createOverlay = this.container.get('CreateOverlay');
const createRule = this.container.get('CreateRule'); const createRule = this.container.get('CreateRule');
const {
schema: { schema },
} = this.app;
createOverlay( createOverlay(
LinkComponent, LinkComponent,
{}, {},
...@@ -19,7 +22,7 @@ export default class LinkService extends Service { ...@@ -19,7 +22,7 @@ export default class LinkService extends Service {
selection: false, selection: false,
}, },
); );
// createRule([linkRule(this.schema.marks.link)]); createRule([linkRule(schema.marks.link)]);
} }
register() { register() {
......
...@@ -6,13 +6,7 @@ const blockInputRule = (pattern, nodeType, getAttrs) => { ...@@ -6,13 +6,7 @@ const blockInputRule = (pattern, nodeType, getAttrs) => {
return new InputRule(pattern, (state, match, start, end) => { return new InputRule(pattern, (state, match, start, end) => {
let $start = state.doc.resolve(start); let $start = state.doc.resolve(start);
let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; 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 ( if (
!$start !$start
.node(-1) .node(-1)
......
...@@ -16,9 +16,13 @@ class MathService extends Service { ...@@ -16,9 +16,13 @@ class MathService extends Service {
this.app.PmPlugins.add('mathplugin', mathPlugin); this.app.PmPlugins.add('mathplugin', mathPlugin);
this.app.PmPlugins.add('mathselectplugin', mathSelectPlugin); this.app.PmPlugins.add('mathselectplugin', mathSelectPlugin);
const createRule = this.container.get('CreateRule'); const createRule = this.container.get('CreateRule');
const {
schema: { schema },
} = this.app;
createRule([ createRule([
blockInputRule(/^\$\$\s+$/, this.schema.nodes.math_display), blockInputRule(/^\$\$\s+$/, schema.nodes.math_display),
inlineInputRule(/(?!\\)\$(.+)(?!\\)\$/, this.schema.nodes.math_inline), inlineInputRule(/(?!\\)\$(.+)(?!\\)\$/, schema.nodes.math_inline),
]); ]);
} }
......
import { injectable } from 'inversify'; import { injectable } from 'inversify';
import { import { inputRules, smartQuotes } from 'prosemirror-inputrules';
inputRules,
wrappingInputRule,
textblockTypeInputRule,
smartQuotes,
} from 'prosemirror-inputrules';
const defaultRules = [ const defaultRules = [
...smartQuotes, ...smartQuotes,
...@@ -38,7 +33,6 @@ class Rules { ...@@ -38,7 +33,6 @@ class Rules {
extendedRules = defaultRules; extendedRules = defaultRules;
addRule(rule) { addRule(rule) {
this.extendedRules.push(...rule); this.extendedRules.push(...rule);
// this.extendedRules = defaultRules.concat(...rule);
} }
createRules() { createRules() {
......
...@@ -7,14 +7,13 @@ export default class RulesService extends Service { ...@@ -7,14 +7,13 @@ export default class RulesService extends Service {
boot() { boot() {
const configRules = this.app.config.get('config.RulesService'); const configRules = this.app.config.get('config.RulesService');
const createRule = this.container.get('CreateRule'); const createRule = this.container.get('CreateRule');
// if (configRules) createRule(configRules); if (configRules) createRule(configRules);
} }
register() { register() {
this.container.bind('Rules').to(Rules).inSingletonScope(); this.container.bind('Rules').to(Rules).inSingletonScope();
this.container.bind('CreateRule').toFactory(context => { this.container.bind('CreateRule').toFactory(context => {
return rule => { return rule => {
console.log(rule);
const ruleInstance = context.container.get('Rules'); const ruleInstance = context.container.get('Rules');
ruleInstance.addRule(rule); 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