diff --git a/.eslintrc.js b/.eslintrc.js index a1e07b0..b483a62 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -20,6 +20,7 @@ module.exports = { 'func-style': ['error', 'declaration', { allowArrowFunctions: true }], 'no-use-before-define': ['error', { functions: false }], '@typescript-eslint/no-use-before-define': ['error', { functions: false }], + 'consistent-return': 1 }, settings: { 'import/resolver': { diff --git a/package.json b/package.json index 82ea695..8b978c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wetty", - "version": "1.1.8", + "version": "1.1.9", "description": "WeTTY = Web + TTY. Terminal access in browser over http/https", "homepage": "https://github.com/krishnasrinivas/wetty", "repository": { @@ -47,7 +47,7 @@ "*.json" ] }, - "preferGlobal": "true", + "preferGlobal": true, "dependencies": { "compression": "^1.7.4", "express": "^4.17.1", diff --git a/src/client/copyToClipboard.ts b/src/client/copyToClipboard.ts new file mode 100644 index 0000000..4b8e608 --- /dev/null +++ b/src/client/copyToClipboard.ts @@ -0,0 +1,22 @@ +// NOTE text selection on double click or select +const copyToClipboard = (text: string) : any => { + if (window.clipboardData && window.clipboardData.setData) { + return window.clipboardData.setData("Text", text); + } if (document.queryCommandSupported && document.queryCommandSupported("copy")) { + const textarea = document.createElement("textarea"); + textarea.textContent = text; + textarea.style.position = "fixed"; + document.body.appendChild(textarea); + textarea.select(); + try { + return document.execCommand("copy"); + } catch (ex) { + console.warn("Copy to clipboard failed.", ex); + return false; + } finally { + document.body.removeChild(textarea); + } + } +} + +export default copyToClipboard; \ No newline at end of file diff --git a/src/client/index.ts b/src/client/index.ts index a17e107..a0026fd 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -4,6 +4,8 @@ import * as io from 'socket.io-client'; import { fit } from 'xterm/lib/addons/fit/fit'; import * as fileType from 'file-type'; import Toastify from 'toastify-js'; + +import copyToClipboard from "./copyToClipboard"; import './wetty.scss'; import './favicon.ico'; @@ -17,27 +19,6 @@ const socket = io(window.location.origin, { const FILE_BEGIN = '\u001b[5i'; const FILE_END = '\u001b[4i'; -//NOTE text selection on double click or select -const copyToClipboard = (text: string) => { - if (window.clipboardData && window.clipboardData.setData) { - return clipboardData.setData("Text", text); - } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) { - let textarea = document.createElement("textarea"); - textarea.textContent = text; - textarea.style.position = "fixed"; - document.body.appendChild(textarea); - textarea.select(); - try { - return document.execCommand("copy"); - } catch (ex) { - console.warn("Copy to clipboard failed.", ex); - return false; - } finally { - document.body.removeChild(textarea); - } - } -} - socket.on('connect', () => { const term = new Terminal(); let fileBuffer = []; @@ -100,9 +81,9 @@ socket.on('connect', () => { return true; }); - //NOTE copytoclipboard + // NOTE copytoclipboard document.addEventListener('mouseup', () => { - if (term.hasSelection()) + if (term.hasSelection()) copyToClipboard(term.getSelection()) }, false);