Socket
Socket
Sign inDemoInstall

@milkdown/plugin-clipboard

Package Overview
Dependencies
75
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.2.3 to 7.2.4

115

./lib/index.es.js

@@ -1,63 +0,76 @@

import { schemaCtx as y, editorViewOptionsCtx as D, parserCtx as N, serializerCtx as P } from "@milkdown/core";
import { getNodeFromSchema as T } from "@milkdown/prose";
import { DOMParser as O, DOMSerializer as z } from "@milkdown/prose/model";
import { PluginKey as k, Plugin as C, TextSelection as M } from "@milkdown/prose/state";
import { $prose as A } from "@milkdown/utils";
const d = (t) => {
if (!t)
import { schemaCtx as D, editorViewOptionsCtx as N, parserCtx as T, serializerCtx as O } from "@milkdown/core";
import { getNodeFromSchema as P } from "@milkdown/prose";
import { DOMParser as k, DOMSerializer as z } from "@milkdown/prose/model";
import { PluginKey as M, Plugin as A, TextSelection as B } from "@milkdown/prose/state";
import { $prose as F } from "@milkdown/utils";
const u = (r) => {
if (!r)
return !1;
if (Array.isArray(t))
return t.length > 1 ? !1 : d(t[0]);
const o = t.content;
return o ? d(o) : t.type === "text";
}, B = A((t) => {
const o = t.get(y);
t.update(D, (e) => ({
...e,
editable: e.editable ?? (() => !0)
if (Array.isArray(r))
return r.length > 1 ? !1 : u(r[0]);
const e = r.content;
return e ? u(e) : r.type === "text";
}, L = (r) => {
if (r.content.childCount === 1) {
const e = r.content.firstChild;
if ((e == null ? void 0 : e.type.name) === "text" && e.marks.length === 0)
return e;
if ((e == null ? void 0 : e.type.name) === "paragraph" && e.childCount === 1) {
const o = e.firstChild;
if ((o == null ? void 0 : o.type.name) === "text" && o.marks.length === 0)
return o;
}
}
return !1;
}, W = F((r) => {
const e = r.get(D);
r.update(N, (t) => ({
...t,
editable: t.editable ?? (() => !0)
}));
const x = new k("MILKDOWN_CLIPBOARD");
return new C({
key: x,
const o = new M("MILKDOWN_CLIPBOARD");
return new A({
key: o,
props: {
handlePaste: (e, i) => {
var f, g;
const m = t.get(N), a = (g = (f = e.props).editable) == null ? void 0 : g.call(f, e.state), { clipboardData: n } = i;
if (!a || !n || e.state.selection.$from.node().type.spec.code)
handlePaste: (t, l) => {
var x, S;
const d = r.get(T), s = (S = (x = t.props).editable) == null ? void 0 : S.call(x, t.state), { clipboardData: a } = l;
if (!s || !a || t.state.selection.$from.node().type.spec.code)
return !1;
const s = n.getData("text/plain"), u = n.getData("vscode-editor-data");
if (u) {
const r = JSON.parse(u), h = r == null ? void 0 : r.mode;
if (s && h) {
const { tr: c } = e.state, b = T("code_block", o);
return c.replaceSelectionWith(b.create({ language: h })).setSelection(
M.near(c.doc.resolve(Math.max(0, c.selection.from - 2)))
).insertText(s.replace(/\r\n?/g, `
`)), e.dispatch(c), !0;
const i = a.getData("text/plain"), f = a.getData("vscode-editor-data");
if (f) {
const n = JSON.parse(f), y = n == null ? void 0 : n.mode;
if (i && y) {
const { tr: c } = t.state, C = P("code_block", e);
return c.replaceSelectionWith(C.create({ language: y })).setSelection(
B.near(c.doc.resolve(Math.max(0, c.selection.from - 2)))
).insertText(i.replace(/\r\n?/g, `
`)), t.dispatch(c), !0;
}
}
const l = n.getData("text/html");
if (l.length === 0 && s.length === 0)
const p = a.getData("text/html");
if (p.length === 0 && i.length === 0)
return !1;
const S = O.fromSchema(o);
let p;
if (l.length === 0) {
const r = m(s);
if (!r || typeof r == "string")
const b = k.fromSchema(e);
let m;
if (p.length === 0) {
const n = d(i);
if (!n || typeof n == "string")
return !1;
p = z.fromSchema(o).serializeFragment(r.content);
m = z.fromSchema(e).serializeFragment(n.content);
} else {
const r = document.createElement("template");
r.innerHTML = l, p = r.content.cloneNode(!0), r.remove();
const n = document.createElement("template");
n.innerHTML = p, m = n.content.cloneNode(!0), n.remove();
}
return e.dispatch(e.state.tr.replaceSelection(S.parseSlice(p))), !0;
const h = b.parseSlice(m), g = L(h);
return g ? (t.dispatch(t.state.tr.replaceSelectionWith(g, !0)), !0) : (t.dispatch(t.state.tr.replaceSelection(h)), !0);
},
clipboardTextSerializer: (e) => {
const i = t.get(P);
if (d(e.content.toJSON()))
return e.content.textBetween(0, e.content.size, `
clipboardTextSerializer: (t) => {
const l = r.get(O);
if (u(t.content.toJSON()))
return t.content.textBetween(0, t.content.size, `
`);
const a = o.topNodeType.createAndFill(void 0, e.content);
return a ? i(a) : "";
const s = e.topNodeType.createAndFill(void 0, t.content);
return s ? l(s) : "";
}

@@ -67,3 +80,3 @@ }

});
B.meta = {
W.meta = {
displayName: "Prose<clipboard>",

@@ -73,4 +86,4 @@ package: "@milkdown/plugin-clipboard"

export {
B as clipboard
W as clipboard
};
//# sourceMappingURL=index.es.js.map

@@ -1,63 +0,76 @@

import { schemaCtx as y, editorViewOptionsCtx as D, parserCtx as N, serializerCtx as P } from "@milkdown/core";
import { getNodeFromSchema as T } from "@milkdown/prose";
import { DOMParser as O, DOMSerializer as z } from "@milkdown/prose/model";
import { PluginKey as k, Plugin as C, TextSelection as M } from "@milkdown/prose/state";
import { $prose as A } from "@milkdown/utils";
const d = (t) => {
if (!t)
import { schemaCtx as D, editorViewOptionsCtx as N, parserCtx as T, serializerCtx as O } from "@milkdown/core";
import { getNodeFromSchema as P } from "@milkdown/prose";
import { DOMParser as k, DOMSerializer as z } from "@milkdown/prose/model";
import { PluginKey as M, Plugin as A, TextSelection as B } from "@milkdown/prose/state";
import { $prose as F } from "@milkdown/utils";
const u = (r) => {
if (!r)
return !1;
if (Array.isArray(t))
return t.length > 1 ? !1 : d(t[0]);
const o = t.content;
return o ? d(o) : t.type === "text";
}, B = A((t) => {
const o = t.get(y);
t.update(D, (e) => ({
...e,
editable: e.editable ?? (() => !0)
if (Array.isArray(r))
return r.length > 1 ? !1 : u(r[0]);
const e = r.content;
return e ? u(e) : r.type === "text";
}, L = (r) => {
if (r.content.childCount === 1) {
const e = r.content.firstChild;
if ((e == null ? void 0 : e.type.name) === "text" && e.marks.length === 0)
return e;
if ((e == null ? void 0 : e.type.name) === "paragraph" && e.childCount === 1) {
const o = e.firstChild;
if ((o == null ? void 0 : o.type.name) === "text" && o.marks.length === 0)
return o;
}
}
return !1;
}, W = F((r) => {
const e = r.get(D);
r.update(N, (t) => ({
...t,
editable: t.editable ?? (() => !0)
}));
const x = new k("MILKDOWN_CLIPBOARD");
return new C({
key: x,
const o = new M("MILKDOWN_CLIPBOARD");
return new A({
key: o,
props: {
handlePaste: (e, i) => {
var f, g;
const m = t.get(N), a = (g = (f = e.props).editable) == null ? void 0 : g.call(f, e.state), { clipboardData: n } = i;
if (!a || !n || e.state.selection.$from.node().type.spec.code)
handlePaste: (t, l) => {
var x, S;
const d = r.get(T), s = (S = (x = t.props).editable) == null ? void 0 : S.call(x, t.state), { clipboardData: a } = l;
if (!s || !a || t.state.selection.$from.node().type.spec.code)
return !1;
const s = n.getData("text/plain"), u = n.getData("vscode-editor-data");
if (u) {
const r = JSON.parse(u), h = r == null ? void 0 : r.mode;
if (s && h) {
const { tr: c } = e.state, b = T("code_block", o);
return c.replaceSelectionWith(b.create({ language: h })).setSelection(
M.near(c.doc.resolve(Math.max(0, c.selection.from - 2)))
).insertText(s.replace(/\r\n?/g, `
`)), e.dispatch(c), !0;
const i = a.getData("text/plain"), f = a.getData("vscode-editor-data");
if (f) {
const n = JSON.parse(f), y = n == null ? void 0 : n.mode;
if (i && y) {
const { tr: c } = t.state, C = P("code_block", e);
return c.replaceSelectionWith(C.create({ language: y })).setSelection(
B.near(c.doc.resolve(Math.max(0, c.selection.from - 2)))
).insertText(i.replace(/\r\n?/g, `
`)), t.dispatch(c), !0;
}
}
const l = n.getData("text/html");
if (l.length === 0 && s.length === 0)
const p = a.getData("text/html");
if (p.length === 0 && i.length === 0)
return !1;
const S = O.fromSchema(o);
let p;
if (l.length === 0) {
const r = m(s);
if (!r || typeof r == "string")
const b = k.fromSchema(e);
let m;
if (p.length === 0) {
const n = d(i);
if (!n || typeof n == "string")
return !1;
p = z.fromSchema(o).serializeFragment(r.content);
m = z.fromSchema(e).serializeFragment(n.content);
} else {
const r = document.createElement("template");
r.innerHTML = l, p = r.content.cloneNode(!0), r.remove();
const n = document.createElement("template");
n.innerHTML = p, m = n.content.cloneNode(!0), n.remove();
}
return e.dispatch(e.state.tr.replaceSelection(S.parseSlice(p))), !0;
const h = b.parseSlice(m), g = L(h);
return g ? (t.dispatch(t.state.tr.replaceSelectionWith(g, !0)), !0) : (t.dispatch(t.state.tr.replaceSelection(h)), !0);
},
clipboardTextSerializer: (e) => {
const i = t.get(P);
if (d(e.content.toJSON()))
return e.content.textBetween(0, e.content.size, `
clipboardTextSerializer: (t) => {
const l = r.get(O);
if (u(t.content.toJSON()))
return t.content.textBetween(0, t.content.size, `
`);
const a = o.topNodeType.createAndFill(void 0, e.content);
return a ? i(a) : "";
const s = e.topNodeType.createAndFill(void 0, t.content);
return s ? l(s) : "";
}

@@ -67,3 +80,3 @@ }

});
B.meta = {
W.meta = {
displayName: "Prose<clipboard>",

@@ -73,4 +86,4 @@ package: "@milkdown/plugin-clipboard"

export {
B as clipboard
W as clipboard
};
//# sourceMappingURL=index.es.js.map
{
"name": "@milkdown/plugin-clipboard",
"type": "module",
"version": "7.2.3",
"version": "7.2.4",
"license": "MIT",

@@ -28,7 +28,7 @@ "repository": {

"tslib": "^2.5.0",
"@milkdown/utils": "7.2.3"
"@milkdown/utils": "7.2.4"
},
"devDependencies": {
"@milkdown/core": "7.2.3",
"@milkdown/prose": "7.2.3"
"@milkdown/core": "7.2.4",
"@milkdown/prose": "7.2.4"
},

@@ -35,0 +35,0 @@ "nx": {

/* Copyright 2021, Milkdown by Mirone. */
import { editorViewOptionsCtx, parserCtx, schemaCtx, serializerCtx } from '@milkdown/core'
import { getNodeFromSchema } from '@milkdown/prose'
import type { Node } from '@milkdown/prose/model'
import type { Node, Slice } from '@milkdown/prose/model'
import { DOMParser, DOMSerializer } from '@milkdown/prose/model'

@@ -26,2 +26,18 @@ import { Plugin, PluginKey, TextSelection } from '@milkdown/prose/state'

const isTextOnlySlice = (slice: Slice): Node | false => {
if (slice.content.childCount === 1) {
const node = slice.content.firstChild
if (node?.type.name === 'text' && node.marks.length === 0)
return node
if (node?.type.name === 'paragraph' && node.childCount === 1) {
const _node = node.firstChild
if (_node?.type.name === 'text' && _node.marks.length === 0)
return _node
}
}
return false
}
/// The prosemirror plugin for clipboard.

@@ -94,4 +110,10 @@ export const clipboard = $prose((ctx) => {

view.dispatch(view.state.tr.replaceSelection(domParser.parseSlice(dom)))
const slice = domParser.parseSlice(dom)
const node = isTextOnlySlice(slice)
if (node) {
view.dispatch(view.state.tr.replaceSelectionWith(node, true))
return true
}
view.dispatch(view.state.tr.replaceSelection(slice))
return true

@@ -98,0 +120,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc