Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}]
}
// }
// schema{
import {Schema, DOMParser} from "prosemirror-model"
import {schema} from "prosemirror-schema-basic"
const dinoSchema = new Schema({
nodes: schema.spec.nodes.addBefore("image", "dino", dinoNodeSpec),
marks: schema.spec.marks
})
let content = document.querySelector("#content")
let startDoc = DOMParser.fromSchema(dinoSchema).parse(content)
// }
// command{
let dinoType = dinoSchema.nodes.dino
function insertDino(type) {
return function(state, dispatch) {
let {$from} = state.selection, index = $from.index()
if (!$from.parent.canReplaceWith(index, index, dinoType))
return false
if (dispatch)
dispatch(state.tr.replaceSelectionWith(dinoType.create({type})))
return true
}
}
// }
{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]
})
})
}
if (typeof content === 'object') {
try {
return this.schema.nodeFromJSON(content)
} catch (error) {
console.warn('[tiptap warn]: Invalid content.', 'Passed value:', content, 'Error:', error)
return this.schema.nodeFromJSON(this.options.emptyDocument)
}
}
if (typeof content === 'string') {
const element = document.createElement('div')
element.innerHTML = content.trim()
return DOMParser.fromSchema(this.schema).parse(element, parseOptions)
}
return false
}
const {addListNodes} = require("prosemirror-schema-list")
const {exampleSetup} = require("prosemirror-example-setup")
const schema = new Schema({
nodes: addListNodes(baseSchema.spec.nodes, "paragraph block*", "block"),
marks: baseSchema.spec.marks
})
let content = document.querySelector("#content")
content.style.display = "none"
let tip = document.querySelector(".demotip")
let view = new MenuBarEditorView(document.querySelector("#editor"), {
state: EditorState.create({
doc: DOMParser.fromSchema(schema).parse(content),
plugins: exampleSetup({schema})
}),
onFocus() {
if (tip) {
tip.innerHTML = "<a style="text-decoration: none; pointer-events: auto; color: inherit" href="#demos">Find more demos below ↓</a>"
tip = null
}
}
})
window.view = view.editor
createEditor() {
const simpleSchema = new Schema({
nodes: {
doc: nodes.doc,
paragraph: nodes.paragraph,
text: nodes.text,
},
marks: marks,
});
const wrapperElem = document.createElement('div');
wrapperElem.innerHTML = this.props.initialHtmlString;
const editorState = EditorState.create({
doc: DOMParser.fromSchema(simpleSchema).parse(wrapperElem),
schema: simpleSchema,
plugins: getBasePlugins({
schema: simpleSchema,
placeholder: this.props.placeholder,
})
});
this.view = new EditorView(document.getElementById(this.containerId), {
state: editorState,
dispatchTransaction: this._onAction,
});
}
export const getDocForHtmlString = (htmlString, schema) => {
const wrapperElem = document.createElement('div');
wrapperElem.innerHTML = htmlString;
return DOMParser.fromSchema(schema).parse(wrapperElem);
};
function start(place, content, schema, plugins = []) {
let doc = DOMParser.fromSchema(schema).parse(content)
return new EditorView(place, {
state: EditorState.create({
doc,
plugins: plugins.concat([histKeymap, keymap(baseKeymap), history()])
})
})
}
}
})
} else if (n.type == view.state.schema.nodes.tab) {
}
return true
})
return true
},
destroy: () => {
}
}
})
});
let state = EditorState.create({
doc: DOMParser.fromSchema(this.editorSchema).parse(this.$.content),
plugins: [
keymap({
"Tab": (state: EditorState, dispatch: any, editorView: EditorView) => {
let tabType = this.editorSchema.nodes.tab
let {$from} = state.selection, index = $from.index()
if (!$from.parent.canReplaceWith(index, index, this.editorSchema.nodes.tab))
return false
if (dispatch)
dispatch(state.tr.replaceSelectionWith(tabType.create()))
return true
}
}),
keymap(baseKeymap),
history(),
columnResizing({}),
tableEditing(),
const convertFromHTML = (html = "<p></p>") => {
if (!document)
throw new Error("Document object is required to convert from html.");
const contentWrapper = document.createElement("div");
document.body.appendChild(contentWrapper);
contentWrapper.innerHTML = html;
const parser = DOMParser.fromSchema(schema);
const content = parser.parse(contentWrapper);
document.body.removeChild(contentWrapper);
return {
doc: content.toJSON(),
selection: {
type: "text",
anchor: 0,
head: 0
}
};
};