This commit is contained in:
2025-01-04 00:34:03 +01:00
parent 41829408dc
commit 0ca14bbc19
18111 changed files with 1871397 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import ProseMirrorPlugin from "./plugin.mjs";
import { Plugin } from "prosemirror-state";
import { randomID } from "../utils/helpers.mjs";
import { transformSlice } from "./util.mjs";
/**
* A class responsible for applying transformations to content pasted inside the editor.
*/
export default class ProseMirrorPasteTransformer extends ProseMirrorPlugin {
/** @override */
static build(schema, options={}) {
const plugin = new ProseMirrorPasteTransformer(schema);
return new Plugin({
props: {
transformPasted: plugin._onPaste.bind(plugin)
}
});
}
/* -------------------------------------------- */
/**
* Transform content before it is injected into the ProseMirror document.
* @param {Slice} slice The content slice.
* @param {EditorView} view The ProseMirror editor view.
* @returns {Slice} The transformed content.
*/
_onPaste(slice, view) {
// Give pasted secret blocks new IDs.
const secret = view.state.schema.nodes.secret;
return transformSlice(slice, node => {
if ( node.type === secret ) {
return secret.create({ ...node.attrs, id: `secret-${randomID()}` }, node.content, node.marks);
}
});
}
}