Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
view: view => {
getPluginState(ctx.pluginKey, view.state).init(view);
return {};
},
props: {
appendTransaction: (transactions, _b, state) => {
return getPluginState(ctx.pluginKey, state).appendTransaction(transactions);
},
state: {
export const getSuggestPluginState = (state: EditorState) =>
getPluginState(suggestPluginKey, state);
findPositionTracker: (id: unknown) => {
const decorations = getPluginState(this.pluginKey, getState());
const found = decorations.find(undefined, undefined, spec => spec.id === id);
return found.length ? found[0].from : undefined;
},
decorations(state: EditorState) {
const { doc } = state;
const positions = getPluginState(ctx.pluginKey, state);
if (positions?.length) {
const decorations = positions.map(position => {
const node = document.createElement('span');
node.appendChild(document.createTextNode(ZERO_WIDTH_SPACE_CHAR));
return Decoration.widget(position, node, {
raw: true,
side: -1,
} as any);
});
return DecorationSet.create(doc, decorations);
}
return null;
},
},
beforeinput: (view, ev: Event) => {
const event = Cast(ev);
if (event.inputType === 'deleteContentBackward' && isAndroidOS()) {
const pluginState = getPluginState(ctx.pluginKey, view.state);
pluginState.startDelete();
return patchDeleteContentBackward(ctx.options, view, event, pluginState);
}
return true;
},
},
decorations: state => {
return getPluginState(key, state);
},
},
clearPositionTrackers: (tr: Transaction = getState().tr) => {
const positionTrackerState = getPluginState(this.pluginKey, getState());
if (positionTrackerState === DecorationSet.empty) {
return;
}
return tr.setMeta(this.pluginKey, { clear: CLEAR });
},
public getPluginState(name: this['_N']): GState {
this.checkInitialized();
const key = this.pluginKeys[name];
if (!key) {
throw new Error(`Cannot retrieve state for an extension: ${name} which doesn't exist`);
}
return getPluginState(key, this.getState());
}
const createDecorationSet = ({ extension, state }: SharedParams) => {
const { empty } = getPluginState(extension.pluginKey, state);
const { emptyNodeClass, placeholder } = extension.options;
if (!empty) {
return;
}
const decorations: Decoration[] = [];
state.doc.descendants((node, pos) => {
const decoration = Decoration.node(pos, pos + node.nodeSize, {
class: emptyNodeClass,
'data-placeholder': placeholder,
});
decorations.push(decoration);
});
return DecorationSet.create(state.doc, decorations);
};