now browsers with literally no clipboard support are ok
Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
parent
464ab31431
commit
eea14e1cc9
1 changed files with 25 additions and 21 deletions
|
@ -54,7 +54,9 @@ const selectTransformTool = () =>
|
||||||
|
|
||||||
state.snapToGrid = true;
|
state.snapToGrid = true;
|
||||||
state.keepAspectRatio = true;
|
state.keepAspectRatio = true;
|
||||||
state.useClipboard = !!navigator.clipboard.write; // Use it by default if supported
|
state.useClipboard = !!(
|
||||||
|
navigator.clipboard && navigator.clipboard.write
|
||||||
|
); // Use it by default if supported
|
||||||
|
|
||||||
state.original = null;
|
state.original = null;
|
||||||
state.dragging = null;
|
state.dragging = null;
|
||||||
|
@ -489,6 +491,7 @@ const selectTransformTool = () =>
|
||||||
// Send to clipboard
|
// Send to clipboard
|
||||||
state.clipboard.copy.toBlob((blob) => {
|
state.clipboard.copy.toBlob((blob) => {
|
||||||
const item = new ClipboardItem({"image/png": blob});
|
const item = new ClipboardItem({"image/png": blob});
|
||||||
|
navigator.clipboard &&
|
||||||
navigator.clipboard.write([item]).catch((e) => {
|
navigator.clipboard.write([item]).catch((e) => {
|
||||||
console.warn("Error sending to clipboard");
|
console.warn("Error sending to clipboard");
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
|
@ -501,6 +504,7 @@ const selectTransformTool = () =>
|
||||||
state.ctrlvcb = (evn) => {
|
state.ctrlvcb = (evn) => {
|
||||||
if (state.useClipboard) {
|
if (state.useClipboard) {
|
||||||
// If we use the clipboard, do some proccessing of clipboard data (ugly but kind of minimum required)
|
// If we use the clipboard, do some proccessing of clipboard data (ugly but kind of minimum required)
|
||||||
|
navigator.clipboard &&
|
||||||
navigator.clipboard.read().then((items) => {
|
navigator.clipboard.read().then((items) => {
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
for (const type of item.types) {
|
for (const type of item.types) {
|
||||||
|
@ -562,7 +566,7 @@ const selectTransformTool = () =>
|
||||||
"Use clipboard"
|
"Use clipboard"
|
||||||
);
|
);
|
||||||
state.ctxmenu.useClipboardLabel = clipboardCheckbox.label;
|
state.ctxmenu.useClipboardLabel = clipboardCheckbox.label;
|
||||||
if (!navigator.clipboard.write)
|
if (!(navigator.clipboard && navigator.clipboard.write))
|
||||||
clipboardCheckbox.checkbox.disabled = true; // Disable if not available
|
clipboardCheckbox.checkbox.disabled = true; // Disable if not available
|
||||||
|
|
||||||
// Some useful actions to do with selection
|
// Some useful actions to do with selection
|
||||||
|
|
Loading…
Reference in a new issue