Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// Create an icon for a heading at the given level
function heading(level) {
return {
command: setBlockType(schema.nodes.heading, {level}),
dom: icon("H" + level, "heading")
}
}
let menu = menuPlugin([
{command: toggleMark(schema.marks.strong), dom: icon("B", "strong")},
{command: toggleMark(schema.marks.em), dom: icon("i", "em")},
{command: setBlockType(schema.nodes.paragraph), dom: icon("p", "paragraph")},
heading(1), heading(2), heading(3),
{command: wrapIn(schema.nodes.blockquote), dom: icon(">", "blockquote")}
])
// }
import {EditorState} from "prosemirror-state"
import {EditorView} from "prosemirror-view"
import {baseKeymap} from "prosemirror-commands"
import {keymap} from "prosemirror-keymap"
import {DOMParser} from "prosemirror-model"
window.view = new EditorView(document.querySelector("#editor"), {
state: EditorState.create({
doc: DOMParser.fromSchema(schema).parse(document.querySelector("#content")),
plugins: [keymap(baseKeymap), menu]
})
})
run(state, dispatch) {
// FIXME if (options.attrs instanceof Function) options.attrs(state, attrs => wrapIn(nodeType, attrs)(state))
return wrapIn(nodeType, options.attrs)(state, dispatch)
},
select(state) {
function toggleWrap(type) {
if (blockTypeIsActive(type)) {
return lift(view.state, view.dispatch);
}
const wrapFunction = wrapIn(type);
return wrapFunction(view.state, view.dispatch);
}
/* -------------- */
function toggleWrap(type) {
if (blockTypeIsActive(type)) {
return lift(view.state, view.dispatch);
}
const wrapFunction = wrapIn(type);
return wrapFunction(view.state, view.dispatch);
}
/* -------------- */
static getMenuItem(schema) {
if (!this.isAvailable(schema)) {
console.log(schema);
throw new Error('Blockquote is not available in schema!');
}
return new MenuItem({
command: wrapIn(schema.nodes.blockquote),
icon: svgIcon('format-quote-close'),
label: LANG.plugins.prosemirror['label:blockquote'],
});
}
}
});
const paragraphMenuItem = new MenuItem({
command: setBlockType(schema.nodes.paragraph),
icon: svgIcon('format-paragraph'),
label: 'Paragraph',
});
const codeBlockMenuItem = new MenuItem({
command: setBlockTypeNoAttrCheck(schema.nodes.code_block),
icon: svgIcon('code-braces'),
label: 'Code Block',
});
const blockquoteMenuItem = new MenuItem({
command: wrapIn(schema.nodes.blockquote),
icon: svgIcon('format-quote-close'),
label: 'Blockquote',
});
const pluginBlockMenuItem = new MenuItem({
command: setBlockType(schema.nodes.dwplugin_block),
icon: svgIcon('puzzle'),
label: 'Plugin block',
});
const pluginInlineMenuItem = new MenuItem({
command: (state, dispatch) => {
const { $from } = state.selection;
const index = $from.index();
if (!$from.parent.canReplaceWith(index, index, schema.nodes.dwplugin_inline)) {
blockQuote = () =>
wrapIn(this.props.view.state.schema.nodes.blockquote)(
this.props.view.state,
this.props.view.dispatch
)
lift = () => lift(this.props.view.state, this.props.view.dispatch)
return (state, dispatch, view) => {
const isActive = nodeIsActive(state, type)
if (isActive) {
return lift(state, dispatch)
}
return wrapIn(type)(state, dispatch, view)
}
}
function wrapInBlockquote(state: EditorState, dispatch: any) {
return wrapIn(state.schema.nodes.blockquote)(state, dispatch)
}
function makeCodeBlock(state: EditorState, dispatch: any) {
export const toggleWrap = (type: NodeType, attrs?: Attrs): CommandFunction => (state, dispatch) => {
const isActive = nodeActive(state, type);
if (isActive) {
return lift(state, dispatch);
}
return wrapIn(type, attrs)(state, dispatch);
};