@milkdown/plugin-clipboard
Advanced tools
Comparing version 7.3.1 to 7.3.2
@@ -6,10 +6,11 @@ import { schemaCtx as D, editorViewOptionsCtx as N, parserCtx as T, serializerCtx as O } from "@milkdown/core"; | ||
import { $prose as F } from "@milkdown/utils"; | ||
const u = (r) => { | ||
function m(r) { | ||
if (!r) | ||
return !1; | ||
if (Array.isArray(r)) | ||
return r.length > 1 ? !1 : u(r[0]); | ||
return r.length > 1 ? !1 : m(r[0]); | ||
const e = r.content; | ||
return e ? u(e) : r.type === "text"; | ||
}, L = (r) => { | ||
return e ? m(e) : r.type === "text"; | ||
} | ||
function L(r) { | ||
if (r.content.childCount === 1) { | ||
@@ -26,3 +27,4 @@ const e = r.content.firstChild; | ||
return !1; | ||
}, W = F((r) => { | ||
} | ||
const W = F((r) => { | ||
const e = r.get(D); | ||
@@ -39,13 +41,13 @@ r.update(N, (t) => ({ | ||
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) | ||
const d = r.get(T), i = (S = (x = t.props).editable) == null ? void 0 : S.call(x, t.state), { clipboardData: a } = l; | ||
if (!i || !a || t.state.selection.$from.node().type.spec.code) | ||
return !1; | ||
const i = a.getData("text/plain"), f = a.getData("vscode-editor-data"); | ||
const s = 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) { | ||
if (s && 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, ` | ||
).insertText(s.replace(/\r\n?/g, ` | ||
`)), t.dispatch(c), !0; | ||
@@ -55,16 +57,16 @@ } | ||
const p = a.getData("text/html"); | ||
if (p.length === 0 && i.length === 0) | ||
if (p.length === 0 && s.length === 0) | ||
return !1; | ||
const b = k.fromSchema(e); | ||
let m; | ||
let u; | ||
if (p.length === 0) { | ||
const n = d(i); | ||
const n = d(s); | ||
if (!n || typeof n == "string") | ||
return !1; | ||
m = z.fromSchema(e).serializeFragment(n.content); | ||
u = z.fromSchema(e).serializeFragment(n.content); | ||
} else { | ||
const n = document.createElement("template"); | ||
n.innerHTML = p, m = n.content.cloneNode(!0), n.remove(); | ||
n.innerHTML = p, u = n.content.cloneNode(!0), n.remove(); | ||
} | ||
const h = b.parseSlice(m), g = L(h); | ||
const h = b.parseSlice(u), g = L(h); | ||
return g ? (t.dispatch(t.state.tr.replaceSelectionWith(g, !0)), !0) : (t.dispatch(t.state.tr.replaceSelection(h)), !0); | ||
@@ -74,8 +76,8 @@ }, | ||
const l = r.get(O); | ||
if (u(t.content.toJSON())) | ||
if (m(t.content.toJSON())) | ||
return t.content.textBetween(0, t.content.size, ` | ||
`); | ||
const s = e.topNodeType.createAndFill(void 0, t.content); | ||
return s ? l(s) : ""; | ||
const i = e.topNodeType.createAndFill(void 0, t.content); | ||
return i ? l(i) : ""; | ||
} | ||
@@ -82,0 +84,0 @@ } |
{ | ||
"name": "@milkdown/plugin-clipboard", | ||
"type": "module", | ||
"version": "7.3.1", | ||
"version": "7.3.2", | ||
"license": "MIT", | ||
@@ -28,7 +28,7 @@ "repository": { | ||
"tslib": "^2.5.0", | ||
"@milkdown/utils": "7.3.1" | ||
"@milkdown/utils": "7.3.2" | ||
}, | ||
"devDependencies": { | ||
"@milkdown/core": "7.3.1", | ||
"@milkdown/prose": "7.3.1" | ||
"@milkdown/core": "7.3.2", | ||
"@milkdown/prose": "7.3.2" | ||
}, | ||
@@ -35,0 +35,0 @@ "nx": { |
@@ -10,3 +10,3 @@ /* Copyright 2021, Milkdown by Mirone. */ | ||
type UnknownRecord = Record<string, unknown> | ||
const isPureText = (content: UnknownRecord | UnknownRecord[] | undefined | null): boolean => { | ||
function isPureText(content: UnknownRecord | UnknownRecord[] | undefined | null): boolean { | ||
if (!content) | ||
@@ -27,3 +27,3 @@ return false | ||
const isTextOnlySlice = (slice: Slice): Node | false => { | ||
function isTextOnlySlice(slice: Slice): Node | false { | ||
if (slice.content.childCount === 1) { | ||
@@ -30,0 +30,0 @@ const node = slice.content.firstChild |
Sorry, the diff of this file is not supported yet
18054
207
+ Added@milkdown/exception@7.3.2(transitive)
+ Added@milkdown/utils@7.3.2(transitive)
- Removed@milkdown/exception@7.3.1(transitive)
- Removed@milkdown/utils@7.3.1(transitive)
Updated@milkdown/utils@7.3.2