md-editor-v3 5.3.2 → 5.4.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/chunks/index.cjs +36 -12
- package/lib/es/chunks/index.mjs +36 -12
- package/lib/umd/index.js +78 -78
- package/package.json +2 -2
package/lib/cjs/chunks/index.cjs
CHANGED
|
@@ -5,7 +5,6 @@ const eventName = require("./event-name.cjs");
|
|
|
5
5
|
const util = require("@vavt/util");
|
|
6
6
|
const dom = require("./dom.cjs");
|
|
7
7
|
const mediumZoom = require("medium-zoom");
|
|
8
|
-
const copy = require("copy-to-clipboard");
|
|
9
8
|
const mdit = require("markdown-it");
|
|
10
9
|
const ImageFiguresPlugin = require("markdown-it-image-figures");
|
|
11
10
|
const SubPlugin = require("markdown-it-sub");
|
|
@@ -50,6 +49,28 @@ const userZoom = (props, html) => {
|
|
|
50
49
|
}
|
|
51
50
|
});
|
|
52
51
|
};
|
|
52
|
+
const copy2Clipboard = async (text) => {
|
|
53
|
+
if (typeof text !== "string") return;
|
|
54
|
+
if (window.isSecureContext && navigator.clipboard) {
|
|
55
|
+
return await navigator.clipboard.writeText(text);
|
|
56
|
+
} else {
|
|
57
|
+
const textarea = document.createElement("textarea");
|
|
58
|
+
let successed = false;
|
|
59
|
+
textarea.value = text;
|
|
60
|
+
textarea.style.position = "fixed";
|
|
61
|
+
textarea.style.opacity = 0;
|
|
62
|
+
textarea.style.zIndex = "-10000";
|
|
63
|
+
textarea.style.top = "-10000";
|
|
64
|
+
document.body.appendChild(textarea);
|
|
65
|
+
textarea.select();
|
|
66
|
+
successed = document.execCommand("copy");
|
|
67
|
+
document.body.removeChild(textarea);
|
|
68
|
+
if (successed) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
throw new Error('Failed to copy content via "execCommand"!');
|
|
72
|
+
}
|
|
73
|
+
};
|
|
53
74
|
const useCopyCode = (props, html, key) => {
|
|
54
75
|
const editorId = vue.inject("editorId");
|
|
55
76
|
const rootRef = vue.inject("rootRef");
|
|
@@ -66,21 +87,24 @@ const useCopyCode = (props, html, key) => {
|
|
|
66
87
|
clearTimeout(clearTimer);
|
|
67
88
|
const activeCode = codeBlock.querySelector("input:checked + pre code") || codeBlock.querySelector("pre code");
|
|
68
89
|
const codeText = activeCode.textContent;
|
|
69
|
-
const success = copy(props.formatCopiedText(codeText));
|
|
70
90
|
const { text, successTips, failTips } = ult.value.copyCode;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
copyButton.innerHTML = msg;
|
|
76
|
-
}
|
|
77
|
-
clearTimer = window.setTimeout(() => {
|
|
91
|
+
let msg = successTips;
|
|
92
|
+
copy2Clipboard(props.formatCopiedText(codeText)).catch(() => {
|
|
93
|
+
msg = failTips;
|
|
94
|
+
}).finally(() => {
|
|
78
95
|
if (copyButton.dataset.isIcon) {
|
|
79
|
-
copyButton.dataset.tips =
|
|
96
|
+
copyButton.dataset.tips = msg;
|
|
80
97
|
} else {
|
|
81
|
-
copyButton.innerHTML =
|
|
98
|
+
copyButton.innerHTML = msg;
|
|
82
99
|
}
|
|
83
|
-
|
|
100
|
+
clearTimer = window.setTimeout(() => {
|
|
101
|
+
if (copyButton.dataset.isIcon) {
|
|
102
|
+
copyButton.dataset.tips = text;
|
|
103
|
+
} else {
|
|
104
|
+
copyButton.innerHTML = text;
|
|
105
|
+
}
|
|
106
|
+
}, 1500);
|
|
107
|
+
});
|
|
84
108
|
};
|
|
85
109
|
});
|
|
86
110
|
};
|
package/lib/es/chunks/index.mjs
CHANGED
|
@@ -4,7 +4,6 @@ import { b as bus, g as CATALOG_CHANGED, P as PUSH_CATALOG, h as RERENDER, B as
|
|
|
4
4
|
import { debounce, randomId, deepMerge, deepClone } from "@vavt/util";
|
|
5
5
|
import { a as appendHandler, u as updateHandler, z as zoomMermaid } from "./dom.mjs";
|
|
6
6
|
import mediumZoom from "medium-zoom";
|
|
7
|
-
import copy from "copy-to-clipboard";
|
|
8
7
|
import mdit from "markdown-it";
|
|
9
8
|
import ImageFiguresPlugin from "markdown-it-image-figures";
|
|
10
9
|
import SubPlugin from "markdown-it-sub";
|
|
@@ -49,6 +48,28 @@ const userZoom = (props, html) => {
|
|
|
49
48
|
}
|
|
50
49
|
});
|
|
51
50
|
};
|
|
51
|
+
const copy2Clipboard = async (text) => {
|
|
52
|
+
if (typeof text !== "string") return;
|
|
53
|
+
if (window.isSecureContext && navigator.clipboard) {
|
|
54
|
+
return await navigator.clipboard.writeText(text);
|
|
55
|
+
} else {
|
|
56
|
+
const textarea = document.createElement("textarea");
|
|
57
|
+
let successed = false;
|
|
58
|
+
textarea.value = text;
|
|
59
|
+
textarea.style.position = "fixed";
|
|
60
|
+
textarea.style.opacity = 0;
|
|
61
|
+
textarea.style.zIndex = "-10000";
|
|
62
|
+
textarea.style.top = "-10000";
|
|
63
|
+
document.body.appendChild(textarea);
|
|
64
|
+
textarea.select();
|
|
65
|
+
successed = document.execCommand("copy");
|
|
66
|
+
document.body.removeChild(textarea);
|
|
67
|
+
if (successed) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
throw new Error('Failed to copy content via "execCommand"!');
|
|
71
|
+
}
|
|
72
|
+
};
|
|
52
73
|
const useCopyCode = (props, html, key) => {
|
|
53
74
|
const editorId = inject("editorId");
|
|
54
75
|
const rootRef = inject("rootRef");
|
|
@@ -65,21 +86,24 @@ const useCopyCode = (props, html, key) => {
|
|
|
65
86
|
clearTimeout(clearTimer);
|
|
66
87
|
const activeCode = codeBlock.querySelector("input:checked + pre code") || codeBlock.querySelector("pre code");
|
|
67
88
|
const codeText = activeCode.textContent;
|
|
68
|
-
const success = copy(props.formatCopiedText(codeText));
|
|
69
89
|
const { text, successTips, failTips } = ult.value.copyCode;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
copyButton.innerHTML = msg;
|
|
75
|
-
}
|
|
76
|
-
clearTimer = window.setTimeout(() => {
|
|
90
|
+
let msg = successTips;
|
|
91
|
+
copy2Clipboard(props.formatCopiedText(codeText)).catch(() => {
|
|
92
|
+
msg = failTips;
|
|
93
|
+
}).finally(() => {
|
|
77
94
|
if (copyButton.dataset.isIcon) {
|
|
78
|
-
copyButton.dataset.tips =
|
|
95
|
+
copyButton.dataset.tips = msg;
|
|
79
96
|
} else {
|
|
80
|
-
copyButton.innerHTML =
|
|
97
|
+
copyButton.innerHTML = msg;
|
|
81
98
|
}
|
|
82
|
-
|
|
99
|
+
clearTimer = window.setTimeout(() => {
|
|
100
|
+
if (copyButton.dataset.isIcon) {
|
|
101
|
+
copyButton.dataset.tips = text;
|
|
102
|
+
} else {
|
|
103
|
+
copyButton.innerHTML = text;
|
|
104
|
+
}
|
|
105
|
+
}, 1500);
|
|
106
|
+
});
|
|
83
107
|
};
|
|
84
108
|
});
|
|
85
109
|
};
|