Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setTimeout(() => {
const pluginState: PluginState = plugin.getState(localView.state);
// If there's already a validation in flight, defer validation
// for another throttle tick
if (pluginState.validationInFlight) {
return scheduleValidation();
}
localView.dispatch(
localView.state.tr.setMeta(
VALIDATION_PLUGIN_ACTION,
validationRequestStart()
)
);
}, plugin.getState(localView.state).currentThrottle);
};
const plugin: Plugin = new Plugin({
state: {
init(_, { doc }): PluginState {
// getValidationRangesForDocument(doc);
// Hook up our validation events.
validationService.on(
ValidationEvents.VALIDATION_SUCCESS,
(validationResponse: ValidationResponse) =>
localView.dispatch(
localView.state.tr.setMeta(
VALIDATION_PLUGIN_ACTION,
validationRequestSuccess(validationResponse)
)
)
);
validationService.on(
// placeholderPlugin{
import {Plugin} from "prosemirror-state"
import {Decoration, DecorationSet} from "prosemirror-view"
let placeholderPlugin = new Plugin({
state: {
init() { return DecorationSet.empty },
apply(tr, set) {
// Adjust decoration positions to changes made by the transaction
set = set.map(tr.mapping, tr.doc)
// See if the transaction adds or removes any placeholders
let action = tr.getMeta(this)
if (action && action.add) {
let widget = document.createElement("placeholder")
let deco = Decoration.widget(action.add.pos, widget, {id: action.add.id})
set = set.add(tr.doc, [deco])
} else if (action && action.remove) {
set = set.remove(set.find(null, null,
spec => spec.id == action.remove.id))
}
return set
import { Plugin } from 'prosemirror-state';
import { getPluginState } from '../plugins';
import { keys } from './pluginKeys';
import { schema } from '../schema';
const { DecorationSet, Decoration } = require('prosemirror-view');
const mentionsPlugin = new Plugin({
state: {
init(config, instance) {
// const set = DecorationSet.empty;
return { decos: DecorationSet.empty, start: null };
},
apply(transaction, state, prevEditorState, editorState) {
const sel = editorState.selection;
const updateMentions = this.spec.editorView.props.viewHandlers.updateMentions;
if (!sel.empty) {
updateMentions('');
return { decos: DecorationSet.empty, start: null, };
}
// const doc = editorState.doc;
function menuPlugin(items) {
return new Plugin({
view(editorView) {
let menuView = new MenuView(items, editorView)
editorView.dom.parentNode.insertBefore(menuView.dom, editorView.dom)
return menuView
}
})
}
// }
function widgets(positions, sides) {
return new Plugin({
state: {
init(state) {
let deco = positions.map((p, i) => Decoration.widget(p, () => {
let s = document.createElement("var")
s.textContent = "×"
return s
}, {side: sides[i]}))
return DecorationSet.create(state.doc, deco)
},
apply(tr, deco) {
return deco.map(tr.mapping, tr.doc)
}
},
props: {
decorations(state) { return this.getState(state) }
}
export default function createCodeBlockPlugin({ extension, type }: CreateCodeBlockPluginParams) {
const pluginState = new CodeBlockState(type);
const handler = () => {
pluginState.setDeleted(true);
return false;
};
return new Plugin({
key: extension.pluginKey,
state: {
init(_, state) {
return pluginState.init(state);
},
apply(tr, _, oldState, newState) {
return pluginState.apply({ tr, oldState, newState });
},
},
props: {
handleKeyDown: keydownHandler({
Backspace: handler,
'Mod-Backspace': handler,
Delete: handler,
'Mod-Delete': handler,
'Ctrl-h': handler,
},
blur: (view, event) => {
this.focused = false
this.emit('blur', {
event,
state: view.state,
view,
})
const transaction = this.state.tr.setMeta('focused', false)
this.view.dispatch(transaction)
},
},
},
}),
new Plugin({
props: this.options.editorProps,
}),
],
})
}
static getPlugins({ pluginKey }) {
return [new Plugin({
key: pluginKey,
state: {
init() {
return {
isActive: false,
start: 0,
end: 0,
positionNumber: 0,
parentOffset: 0,
emptyLine: false,
substring: '',
};
},
apply(transaction, state, prevEditorState, editorState) {
const doc = editorState.doc;
const emptyDoc = doc.childCount === 0 || (doc.childCount === 1 && doc.firstChild.isTextblock && doc.firstChild.content.size === 0);
export function dropCursorPlugin(
params: ExtensionManagerParams,
extension: Extension,
) {
const dropCursorState = new DropCursorState(params, extension);
return new Plugin({
key: extension.pluginKey,
view(editorView) {
dropCursorState.init(editorView);
return pick(dropCursorState, ['destroy']);
},
state: {
init: () => dropCursorState,
apply: () => dropCursorState,
},
props: {
decorations: () => dropCursorState.decorationSet,
handleDOMEvents: {
dragover: (_, event) => {
dropCursorState.dragover(event as DragEvent);
return false;
},
ready() {
super.ready()
const proseEditor = this
let selectionTrackingPlugin = new Plugin({
view(view) {
return {
update: function (view, prevState) {
var state = view.state;
if (!(prevState && prevState.doc.eq(state.doc) && prevState.selection.eq(state.selection))) {
let {$anchor, $cursor} = state.selection as TextSelection, index = $anchor.pos
let node = state.doc.nodeAt(index)
if (!node && !$cursor) {
proseEditor.set('currentHeading', null)
proseEditor.set('currentFont', null)
proseEditor.set('currentSize', null)
return
}