Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getContentEditorKeymap(editor: AppContentEditor, schema: ContentEditorSchema) {
const isMac = typeof navigator != 'undefined' ? /Mac/.test(navigator.platform) : false;
const keymap = {
'Mod-z': undo,
'Shift-Mod-z': redo,
'Mod-b': toggleMark(schema.marks.strong),
'Mod-i': toggleMark(schema.marks.em),
'Mod-`': toggleMark(schema.marks.code),
'Shift-Enter': chainCommands(exitCodeStart(editor.capabilities), exitCode, insertHardBreak),
// open emoji panel
'Mod-e': () => {
if (editor.capabilities.emoji) {
editor.showEmojiPanel();
}
return true;
},
// Add/remove link
'Mod-k': showLinkModal(editor.capabilities, schema),
} as { [k: string]: any };
const enterCommands = [] as PMKeymapCommand[];
run: function (state, dispatch, view, attrs) {
// Toggle link off
if (markActive(state, markType)) {
toggleMark(markType)(state, dispatch)
return true
}
// Toggle link on
if (attrs) {
toggleMark(markType, attrs)(state, dispatch)
return true
}
// Prompt for link
const {from, to} = state.selection
const selectedText = state.doc.textBetween(from, to)
const urlLike = isUrlLike(selectedText)
const value = (urlLike ? selectedText : '')
const {ed} = key.get(state).options.edStuff
}
// 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);
}
/* -------------- */
})
}
/**
* Underline – <span style="text-decoration: underline">
*/
if ((type = schema.marks.underline)) {
bind('Mod-u', toggleMark(type))
}
/**
* Hard Break – <br>
*/
if ((type = schema.nodes.hard_break)) {
const br = type,
cmd = chainCommands(exitCode, (state, dispatch) => {
// @ts-ignore
dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView())
return true
})
if (!schema.nodes.paragraph) {
bind('Enter', cmd)
}
bind('Mod-Enter', cmd)
bind('Shift-Enter', cmd)
if (mac) bind('Ctrl-Enter', cmd)
}
/**
* Headings -
*/
if ((type = schema.nodes.heading)) {</span>
EXTERNAL = "external",
FORMATTING = "autoformatting",
FLOATING_TB = "floatingToolbar",
KEYBOARD = "keyboard",
INSERT_MENU = "insertMenu",
MANUAL = "manual",
PICKER = "picker",
PICKER_CLOUD = "cloudPicker",
QUICK_INSERT = "quickInsert",
SHORTCUT = "shortcut",
TOOLBAR = "toolbar",
TYPEAHEAD = "typeAhead",
}
const not = (fn: (args: T) => boolean) => (arg: T) => !fn(arg)
const tryUndoInputRuleElseUndoHistory = chainCommands(undoInputRule, undoCmd)
export const removeBlockMarks = (
state: EditorState,
marks: Array,
): Transaction | undefined => {
// tslint:disable-next-line:no-shadowed-variable
const { selection, schema } = state
let { tr } = state
// Marks might not exist in Schema
const marksToRemove = marks.filter(Boolean)
if (marksToRemove.length === 0) {
return undefined
}
/** Saves an extra dispatch */
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);
}
/* -------------- */