Commit 7e7bae1e authored by chris's avatar chris

create rules

parent 71d85d77
...@@ -17,7 +17,9 @@ import { ...@@ -17,7 +17,9 @@ import {
goToNextCell goToNextCell
} from "prosemirror-tables"; } from "prosemirror-tables";
import { Wax, CreateSchema } from "wax-prosemirror-core"; import { emDash, ellipsis } from "prosemirror-inputrules";
import { Wax, CreateSchema, CreateShortCuts } from "wax-prosemirror-core";
import { EditoriaSchema } from "wax-prosemirror-schema"; import { EditoriaSchema } from "wax-prosemirror-schema";
import { LinkToolTipPlugin } from "wax-prosemirror-plugins"; import { LinkToolTipPlugin } from "wax-prosemirror-plugins";
import { MainMenuBar, SideMenuBar } from "wax-prosemirror-components"; import { MainMenuBar, SideMenuBar } from "wax-prosemirror-components";
...@@ -61,10 +63,14 @@ const shortCuts = { ...@@ -61,10 +63,14 @@ const shortCuts = {
"Shift-Ctrl-9": wrapInList(schema.nodes.ordered_list) "Shift-Ctrl-9": wrapInList(schema.nodes.ordered_list)
}; };
const keys = new CreateShortCuts({ schema, shortCuts });
const rules = [emDash, ellipsis];
const options = { const options = {
schema, schema,
plugins, plugins,
shortCuts keys,
rules
}; };
const GlobalStyle = createGlobalStyle` const GlobalStyle = createGlobalStyle`
......
...@@ -8,6 +8,7 @@ import defaultPlugins from "./config/defaultPlugins"; ...@@ -8,6 +8,7 @@ import defaultPlugins from "./config/defaultPlugins";
import placeholder from "./config/plugins/placeholder"; import placeholder from "./config/plugins/placeholder";
import CreateShortCuts from "./config/classes/CreateShortCuts"; import CreateShortCuts from "./config/classes/CreateShortCuts";
import CreateRules from "./config/classes/CreateRules";
const parser = schema => { const parser = schema => {
const parser = DOMParser.fromSchema(schema); const parser = DOMParser.fromSchema(schema);
...@@ -32,15 +33,20 @@ const serializer = schema => { ...@@ -32,15 +33,20 @@ const serializer = schema => {
class Wax extends Component { class Wax extends Component {
componentWillMount() { componentWillMount() {
const { value, onChange, options } = this.props; const { value, onChange, options } = this.props;
const { schema, plugins, shortCuts } = options; const { schema, plugins, keys, rules } = options;
const WaxOnchange = onChange ? onChange : value => true; const WaxOnchange = onChange ? onChange : value => true;
const keys = new CreateShortCuts({ schema: schema, shortCuts: shortCuts }); const WaxKeys =
options && options.keys
? options.keys
: new CreateShortCuts({ schema: schema, shortCuts: {} });
const WaxRules = new CreateRules({ schema: schema, rules: rules });
const editorContent = value ? value : ""; const editorContent = value ? value : "";
defaultPlugins.push( defaultPlugins.push(
...[placeholder({ content: this.props.placeholder }), keys] ...[placeholder({ content: this.props.placeholder }), WaxKeys, WaxRules]
); );
if (plugins) defaultPlugins.push(...plugins); if (plugins) defaultPlugins.push(...plugins);
......
import {
inputRules,
wrappingInputRule,
textblockTypeInputRule,
smartQuotes
} from "prosemirror-inputrules";
class CreateRules {
constructor(config) {
this.allRules = this.allRules.bind(this);
this.schema = config.schema;
return inputRules(this.allRules(this.rules));
}
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 })
)
]
};
}
}
export default CreateRules;
...@@ -4,12 +4,4 @@ import { gapCursor } from "prosemirror-gapcursor"; ...@@ -4,12 +4,4 @@ import { gapCursor } from "prosemirror-gapcursor";
import "prosemirror-gapcursor/style/gapcursor.css"; import "prosemirror-gapcursor/style/gapcursor.css";
import placeholderPlugin from "./plugins/placeholderPlugin"; import placeholderPlugin from "./plugins/placeholderPlugin";
// import rules from "./rules"; export default [dropCursor(), gapCursor(), history(), placeholderPlugin];
export default [
// rules,
dropCursor(),
gapCursor(),
history(),
placeholderPlugin
];
import {
inputRules,
wrappingInputRule,
textblockTypeInputRule,
smartQuotes,
emDash,
ellipsis
} from "prosemirror-inputrules";
// import WaxSchema from "./classes/WaxSchema";
// const schema = WaxSchema();
export default inputRules({
rules: [
...smartQuotes,
ellipsis,
emDash,
// > blockquote
wrappingInputRule(/^\s*>\s$/, schema.nodes.blockquote),
// 1. ordered list
wrappingInputRule(
/^(\d+)\.\s$/,
schema.nodes.ordered_list,
match => ({ order: +match[1] }),
(match, node) => node.childCount + node.attrs.order === +match[1]
),
// * bullet list
wrappingInputRule(/^\s*([-+*])\s$/, schema.nodes.bullet_list),
// ``` code block
textblockTypeInputRule(/^```$/, schema.nodes.code_block),
// # heading
textblockTypeInputRule(
new RegExp("^(#{1,6})\\s$"),
schema.nodes.heading,
match => ({ level: match[1].length })
)
]
});
Markdown is supported
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