mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Split marks and nodes into their own files
This commit is contained in:
@ -5,7 +5,7 @@ import {
|
|||||||
|
|
||||||
import {toggleMark} from "prosemirror-commands";
|
import {toggleMark} from "prosemirror-commands";
|
||||||
import {menuBar} from "./menubar"
|
import {menuBar} from "./menubar"
|
||||||
import schema from "../schema";
|
import index from "../schema/schema";
|
||||||
|
|
||||||
|
|
||||||
function cmdItem(cmd, options) {
|
function cmdItem(cmd, options) {
|
||||||
@ -53,49 +53,49 @@ function markItem(markType, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const inlineStyles = [
|
const inlineStyles = [
|
||||||
markItem(schema.marks.strong, {title: "Bold", icon: icons.strong}),
|
markItem(index.marks.strong, {title: "Bold", icon: icons.strong}),
|
||||||
markItem(schema.marks.em, {title: "Italic", icon: icons.em}),
|
markItem(index.marks.em, {title: "Italic", icon: icons.em}),
|
||||||
markItem(schema.marks.underline, {title: "Underline", label: 'U'}),
|
markItem(index.marks.underline, {title: "Underline", label: 'U'}),
|
||||||
markItem(schema.marks.strike, {title: "Strikethrough", label: '-S-'}),
|
markItem(index.marks.strike, {title: "Strikethrough", label: '-S-'}),
|
||||||
markItem(schema.marks.superscript, {title: "Superscript", label: 'sup'}),
|
markItem(index.marks.superscript, {title: "Superscript", label: 'sup'}),
|
||||||
markItem(schema.marks.subscript, {title: "Subscript", label: 'sub'}),
|
markItem(index.marks.subscript, {title: "Subscript", label: 'sub'}),
|
||||||
];
|
];
|
||||||
|
|
||||||
const formats = [
|
const formats = [
|
||||||
blockTypeItem(schema.nodes.heading, {
|
blockTypeItem(index.nodes.heading, {
|
||||||
label: "Header Large",
|
label: "Header Large",
|
||||||
attrs: {level: 2}
|
attrs: {level: 2}
|
||||||
}),
|
}),
|
||||||
blockTypeItem(schema.nodes.heading, {
|
blockTypeItem(index.nodes.heading, {
|
||||||
label: "Header Medium",
|
label: "Header Medium",
|
||||||
attrs: {level: 3}
|
attrs: {level: 3}
|
||||||
}),
|
}),
|
||||||
blockTypeItem(schema.nodes.heading, {
|
blockTypeItem(index.nodes.heading, {
|
||||||
label: "Header Small",
|
label: "Header Small",
|
||||||
attrs: {level: 4}
|
attrs: {level: 4}
|
||||||
}),
|
}),
|
||||||
blockTypeItem(schema.nodes.heading, {
|
blockTypeItem(index.nodes.heading, {
|
||||||
label: "Header Tiny",
|
label: "Header Tiny",
|
||||||
attrs: {level: 5}
|
attrs: {level: 5}
|
||||||
}),
|
}),
|
||||||
blockTypeItem(schema.nodes.paragraph, {
|
blockTypeItem(index.nodes.paragraph, {
|
||||||
label: "Paragraph",
|
label: "Paragraph",
|
||||||
attrs: {}
|
attrs: {}
|
||||||
}),
|
}),
|
||||||
new DropdownSubmenu([
|
new DropdownSubmenu([
|
||||||
blockTypeItem(schema.nodes.callout, {
|
blockTypeItem(index.nodes.callout, {
|
||||||
label: "Info Callout",
|
label: "Info Callout",
|
||||||
attrs: {type: 'info'}
|
attrs: {type: 'info'}
|
||||||
}),
|
}),
|
||||||
blockTypeItem(schema.nodes.callout, {
|
blockTypeItem(index.nodes.callout, {
|
||||||
label: "Danger Callout",
|
label: "Danger Callout",
|
||||||
attrs: {type: 'danger'}
|
attrs: {type: 'danger'}
|
||||||
}),
|
}),
|
||||||
blockTypeItem(schema.nodes.callout, {
|
blockTypeItem(index.nodes.callout, {
|
||||||
label: "Success Callout",
|
label: "Success Callout",
|
||||||
attrs: {type: 'success'}
|
attrs: {type: 'success'}
|
||||||
}),
|
}),
|
||||||
blockTypeItem(schema.nodes.callout, {
|
blockTypeItem(index.nodes.callout, {
|
||||||
label: "Warning Callout",
|
label: "Warning Callout",
|
||||||
attrs: {type: 'warning'}
|
attrs: {type: 'warning'}
|
||||||
})
|
})
|
||||||
|
40
resources/js/editor/schema-marks.js
Normal file
40
resources/js/editor/schema-marks.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import {schema as basicSchema} from "prosemirror-schema-basic";
|
||||||
|
|
||||||
|
const baseMarks = basicSchema.spec.marks;
|
||||||
|
|
||||||
|
const underline = {
|
||||||
|
parseDOM: [{tag: "u"}, {style: "text-decoration=underline"}],
|
||||||
|
toDOM() {
|
||||||
|
return ["span", {style: "text-decoration: underline;"}, 0];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const strike = {
|
||||||
|
parseDOM: [{tag: "s"}, {tag: "strike"}, {style: "text-decoration=line-through"}],
|
||||||
|
toDOM() {
|
||||||
|
return ["span", {style: "text-decoration: line-through;"}, 0];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const superscript = {
|
||||||
|
parseDOM: [{tag: "sup"}],
|
||||||
|
toDOM() {
|
||||||
|
return ["sup", 0];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const subscript = {
|
||||||
|
parseDOM: [{tag: "sub"}],
|
||||||
|
toDOM() {
|
||||||
|
return ["sub", 0];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const marks = baseMarks.append({
|
||||||
|
underline,
|
||||||
|
strike,
|
||||||
|
superscript,
|
||||||
|
subscript,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default marks;
|
30
resources/js/editor/schema-nodes.js
Normal file
30
resources/js/editor/schema-nodes.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import {schema as basicSchema} from "prosemirror-schema-basic";
|
||||||
|
import {addListNodes} from "prosemirror-schema-list";
|
||||||
|
|
||||||
|
const baseNodes = addListNodes(basicSchema.spec.nodes, "paragraph block*", "block");
|
||||||
|
|
||||||
|
const callout = {
|
||||||
|
attrs: {
|
||||||
|
type: {default: 'info'},
|
||||||
|
},
|
||||||
|
content: "inline*",
|
||||||
|
group: "block",
|
||||||
|
defining: true,
|
||||||
|
parseDOM: [
|
||||||
|
{tag: 'p.callout.info', attrs: {type: 'info'}, priority: 75,},
|
||||||
|
{tag: 'p.callout.success', attrs: {type: 'success'}, priority: 75,},
|
||||||
|
{tag: 'p.callout.danger', attrs: {type: 'danger'}, priority: 75,},
|
||||||
|
{tag: 'p.callout.warning', attrs: {type: 'warning'}, priority: 75,},
|
||||||
|
{tag: 'p.callout', attrs: {type: 'info'}, priority: 75},
|
||||||
|
],
|
||||||
|
toDOM(node) {
|
||||||
|
const type = node.attrs.type || 'info';
|
||||||
|
return ['p', {class: 'callout ' + type}, 0];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const nodes = baseNodes.append({
|
||||||
|
callout,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default nodes;
|
@ -1,72 +1,11 @@
|
|||||||
import {Schema} from "prosemirror-model";
|
import {Schema} from "prosemirror-model";
|
||||||
import {schema as basicSchema} from "prosemirror-schema-basic";
|
|
||||||
import {addListNodes} from "prosemirror-schema-list";
|
|
||||||
|
|
||||||
const baseNodes = addListNodes(basicSchema.spec.nodes, "paragraph block*", "block");
|
import nodes from "./schema-nodes";
|
||||||
const baseMarks = basicSchema.spec.marks;
|
import marks from "./schema-marks";
|
||||||
|
|
||||||
const nodeCallout = {
|
const index = new Schema({
|
||||||
attrs: {
|
nodes,
|
||||||
type: {default: 'info'},
|
marks,
|
||||||
},
|
|
||||||
content: "inline*",
|
|
||||||
group: "block",
|
|
||||||
defining: true,
|
|
||||||
parseDOM: [
|
|
||||||
{tag: 'p.callout.info', attrs: {type: 'info'}, priority: 75,},
|
|
||||||
{tag: 'p.callout.success', attrs: {type: 'success'}, priority: 75,},
|
|
||||||
{tag: 'p.callout.danger', attrs: {type: 'danger'}, priority: 75,},
|
|
||||||
{tag: 'p.callout.warning', attrs: {type: 'warning'}, priority: 75,},
|
|
||||||
{tag: 'p.callout', attrs: {type: 'info'}, priority: 75},
|
|
||||||
],
|
|
||||||
toDOM(node) {
|
|
||||||
const type = node.attrs.type || 'info';
|
|
||||||
return ['p', {class: 'callout ' + type}, 0];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const markUnderline = {
|
|
||||||
parseDOM: [{tag: "u"}, {style: "text-decoration=underline"}],
|
|
||||||
toDOM() {
|
|
||||||
return ["span", {style: "text-decoration: underline;"}, 0];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const markStrike = {
|
|
||||||
parseDOM: [{tag: "s"}, {tag: "strike"}, {style: "text-decoration=line-through"}],
|
|
||||||
toDOM() {
|
|
||||||
return ["span", {style: "text-decoration: line-through;"}, 0];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const markSuperscript = {
|
|
||||||
parseDOM: [{tag: "sup"}],
|
|
||||||
toDOM() {
|
|
||||||
return ["sup", 0];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const markSubscript = {
|
|
||||||
parseDOM: [{tag: "sub"}],
|
|
||||||
toDOM() {
|
|
||||||
return ["sub", 0];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const customNodes = baseNodes.append({
|
|
||||||
callout: nodeCallout,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const customMarks = baseMarks.append({
|
export default index;
|
||||||
underline: markUnderline,
|
|
||||||
strike: markStrike,
|
|
||||||
superscript: markSuperscript,
|
|
||||||
subscript: markSubscript,
|
|
||||||
});
|
|
||||||
|
|
||||||
const schema = new Schema({
|
|
||||||
nodes: customNodes,
|
|
||||||
marks: customMarks,
|
|
||||||
})
|
|
||||||
|
|
||||||
export default schema;
|
|
Reference in New Issue
Block a user