Create copy-to-clipboard module and tooltip module

pull/1/head
ninabreznik 7 years ago committed by yann300
parent 73ead83353
commit 5d0b690242
  1. 83
      src/app/execution/txLogger.js
  2. 10
      src/app/tabs/compile-tab.js
  3. 19
      src/app/tabs/run-tab.js
  4. 32
      src/app/ui/copy-to-clipboard.js
  5. 52
      src/app/ui/tooltip.js
  6. 33
      src/universal-dapp.js

@ -1,6 +1,6 @@
'use strict'
var yo = require('yo-yo')
const copy = require('clipboard-copy')
var copyToClipboard = require('../ui/copy-to-clipboard')
// -------------- styling ----------------------
var csjs = require('csjs-inject')
@ -55,14 +55,6 @@ var css = csjs`
margin-left: 5px;
cursor: pointer;
}
.clipboardCopy {
margin-left: 5px;
cursor: pointer;
color: ${styles.terminal.icon_Color_CopyToClipboard};
}
.clipboardCopy:hover {
color: ${styles.terminal.icon_HoverColor_CopyToClipboard};
}
`
/**
* This just export a function that register to `newTransaction` and forward them to the logger.
@ -324,22 +316,26 @@ function createTable (opts) {
<tr class="${css.tr}">
<td class="${css.td}"> status </td>
<td class="${css.td}">${opts.status}${msg}</td>
</tr class="${css.tr}">`)
</tr>`)
}
var contractAddress = yo`
<tr class="${css.tr}">
<td class="${css.td}"> contractAddress </td>
<td class="${css.td}">${opts.contractAddress}<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(opts.contractAddress) }} title='Copy to clipboard'></i></td>
</tr class="${css.tr}">
<td class="${css.td}">${opts.contractAddress}
${copyToClipboard(() => opts.contractAddress)}
</td>
</tr>
`
if (opts.contractAddress) table.appendChild(contractAddress)
var from = yo`
<tr class="${css.tr}">
<td class="${css.td} ${css.tableTitle}"> from </td>
<td class="${css.td}">${opts.from}<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(opts.from) }} title='Copy to clipboard'></i></td>
</tr class="${css.tr}">
<td class="${css.td}">${opts.from}
${copyToClipboard(() => opts.from)}
</td>
</tr>
`
if (opts.from) table.appendChild(from)
@ -353,16 +349,20 @@ function createTable (opts) {
var to = yo`
<tr class="${css.tr}">
<td class="${css.td}"> to </td>
<td class="${css.td}">${toHash}<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(data.to ? data.to : toHash) }} title='Copy to clipboard'></i></td>
</tr class="${css.tr}">
<td class="${css.td}">${toHash}
${copyToClipboard(() => data.to ? data.to : toHash)}
</td>
</tr>
`
if (opts.to) table.appendChild(to)
var gas = yo`
<tr class="${css.tr}">
<td class="${css.td}"> gas </td>
<td class="${css.td}">${opts.gas} gas<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(opts.gas) }} title='Copy to clipboard'></i></td>
</tr class="${css.tr}">
<td class="${css.td}">${opts.gas} gas
${copyToClipboard(() => opts.gas)}
</td>
</tr>
`
if (opts.gas) table.appendChild(gas)
@ -374,31 +374,39 @@ function createTable (opts) {
table.appendChild(yo`
<tr class="${css.tr}">
<td class="${css.td}"> transaction cost </td>
<td class="${css.td}">${opts.transactionCost} gas ${callWarning}<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(opts.transactionCost) }} title='Copy to clipboard'></i></td>
</tr class="${css.tr}">`)
<td class="${css.td}">${opts.transactionCost} gas ${callWarning}
${copyToClipboard(() => opts.transactionCost)}
</td>
</tr>`)
}
if (opts.executionCost) {
table.appendChild(yo`
<tr class="${css.tr}">
<td class="${css.td}"> execution cost </td>
<td class="${css.td}">${opts.executionCost} gas ${callWarning}<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(opts.executionCost) }} title='Copy to clipboard'></i></td>
</tr class="${css.tr}">`)
<td class="${css.td}">${opts.executionCost} gas ${callWarning}
${copyToClipboard(() => opts.executionCost)}
</td>
</tr>`)
}
var hash = yo`
<tr class="${css.tr}">
<td class="${css.td}"> hash </td>
<td class="${css.td}">${opts.hash}<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(opts.hash) }} title='Copy to clipboard'></i></td>
</tr class="${css.tr}">
<td class="${css.td}">${opts.hash}
${copyToClipboard(() => opts.hash)}
</td>
</tr>
`
if (opts.hash) table.appendChild(hash)
var input = yo`
<tr class="${css.tr}">
<td class="${css.td}"> input </td>
<td class="${css.td}">${opts.input}<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(opts.input) }} title='Copy to clipboard'></i></td>
</tr class="${css.tr}">
<td class="${css.td}">${opts.input}
${copyToClipboard(() => opts.input)}
</td>
</tr>
`
if (opts.input) table.appendChild(input)
@ -406,8 +414,10 @@ function createTable (opts) {
var inputDecoded = yo`
<tr class="${css.tr}">
<td class="${css.td}"> decoded input </td>
<td class="${css.td}">${opts['decoded input']}<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(opts['decoded input']) }} title='Copy to clipboard'></i></td>
</tr class="${css.tr}">`
<td class="${css.td}">${opts['decoded input']}
${copyToClipboard(opts['decoded input'])}
</td>
</tr>`
table.appendChild(inputDecoded)
}
@ -416,7 +426,7 @@ function createTable (opts) {
<tr class="${css.tr}">
<td class="${css.td}"> decoded output </td>
<td class="${css.td}" id="decodedoutput" >${opts['decoded output']}</td>
</tr class="${css.tr}">`
</tr>`
table.appendChild(outputDecoded)
}
@ -428,10 +438,11 @@ function createTable (opts) {
<tr class="${css.tr}">
<td class="${css.td}"> logs </td>
<td class="${css.td}" id="logs">
${JSON.stringify(stringified, null, '\t')}
<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(JSON.stringify(stringified, null, '\t')) }} title='Copy Logs to clipboard'></i>
<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(JSON.stringify(opts.logs.raw || '0')) }} title='Copy Raw Logs to clipboard'></i></td>
</tr class="${css.tr}">
${JSON.stringify(stringified, null, '\t')}
${copyToClipboard(() => JSON.stringify(stringified, null, '\t'))}
${copyToClipboard(() => JSON.stringify(opts.logs.raw || '0'))}
</td>
</tr>
`
if (opts.logs) table.appendChild(logs)
@ -439,8 +450,10 @@ function createTable (opts) {
val = yo`
<tr class="${css.tr}">
<td class="${css.td}"> value </td>
<td class="${css.td}">${val} wei<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(`${val} wei`) }} title='Copy to clipboard'></i></td>
</tr class="${css.tr}">
<td class="${css.td}">${val} wei
${copyToClipboard(() => `${val} wei`)}
</td>
</tr>
`
if (opts.val) table.appendChild(val)

@ -2,13 +2,13 @@
var $ = require('jquery')
var yo = require('yo-yo')
const copy = require('clipboard-copy')
var parseContracts = require('../contract/contractParser')
var publishOnSwarm = require('../contract/publishOnSwarm')
var modalDialog = require('../ui/modaldialog')
var modalDialogCustom = require('../ui/modal-dialog-custom')
var TreeView = require('remix-debugger').ui.TreeView
var copyToClipboard = require('../ui/copy-to-clipboard')
// -------------- styling ----------------------
var csjs = require('csjs-inject')
@ -96,6 +96,7 @@ var css = csjs`
display: flex;
flex-direction: column;
margin-bottom: 5%;
overflow: visible;
}
.key {
margin-right: 5px;
@ -108,13 +109,11 @@ var css = csjs`
width: 100%;
margin-top: 1.5%;
}
.copyDetails,
.questionMark {
margin-left: 2%;
cursor: pointer;
color: ${styles.rightPanel.icon_Color_TogglePanel};
}
.copyDetails:hover,
.questionMark:hover {
color: ${styles.rightPanel.icon_HoverColor_TogglePanel};
}
@ -357,12 +356,15 @@ function compileTab (container, appAPI, appEvents, opts) {
function details () {
var select = el.querySelector('select')
if (select.children.length > 0 && select.selectedIndex >= 0) {
var contractName = select.children[select.selectedIndex].innerHTML
var contractProperties = contractsDetails[contractName]
var log = yo`<div class="${css.detailsJSON}"></div>`
Object.keys(contractProperties).map(propertyName => {
var copyDetails = yo`<span class="${css.copyDetails}"><i title="Copy value to clipboard" class="fa fa-clipboard" onclick=${() => { copy(contractProperties[propertyName]) }} aria-hidden="true"></i></span>`
var copyDetails = yo`<span class="${css.copyDetails}">
${copyToClipboard(() => contractProperties[propertyName])}
</span>`
var questionMark = yo`<span class="${css.questionMark}"><i title="${detailsHelpSection()[propertyName]}" class="fa fa-question-circle" aria-hidden="true"></i></span>`
log.appendChild(yo`
<div class=${css.log}>

@ -7,7 +7,7 @@ var txFormat = require('../execution/txFormat')
var txHelper = require('../execution/txHelper')
var modalDialogCustom = require('../ui/modal-dialog-custom')
var executionContext = require('../../execution-context')
const copy = require('clipboard-copy')
var copyToClipboard = require('../ui/copy-to-clipboard')
// -------------- styling ----------------------
var csjs = require('csjs-inject')
@ -29,6 +29,7 @@ var css = csjs`
.crow {
margin-top: .5em;
display: flex;
align-items: center;
}
.col1 {
width: 30%;
@ -60,15 +61,6 @@ var css = csjs`
font-weight: normal;
min-width: 150px;
}
.copyaddress {
margin-left: 0.5em;
margin-top: 0.7em;
cursor: pointer;
color: ${styles.rightPanel.runTab.icon_Color_Instance_CopyToClipboard};
}
.copyaddress:hover {
color: ${styles.rightPanel.runTab.icon_HoverColor_Instance_CopyToClipboard};
}
.instanceContainer {
${styles.rightPanel.runTab.box_Instance}
display: flex;
@ -374,11 +366,6 @@ function contractDropdown (appAPI, appEvents, instanceContainer) {
section SETTINGS: Environment, Account, Gas, Value
------------------------------------------------ */
function settings (appAPI, appEvents) {
// COPY ADDRESS
function copyAddress () {
copy(document.querySelector('#runTabView #txorigin').value)
}
// SETTINGS HTML
var el = yo`
<div class="${css.settings}">
@ -411,7 +398,7 @@ function settings (appAPI, appEvents) {
<div class="${css.crow}">
<div class="${css.col1_1}">Account</div>
<select name="txorigin" class="${css.select}" id="txorigin"></select>
<i title="Copy Address" class="copytxorigin fa fa-clipboard ${css.copyaddress}" onclick=${copyAddress} aria-hidden="true"></i>
${copyToClipboard(() => document.querySelector('#runTabView #txorigin').value)}
</div>
<div class="${css.crow}">
<div class="${css.col1_1}">Gas limit</div>

@ -0,0 +1,32 @@
var yo = require('yo-yo')
// -------------- copyToClipboard ----------------------
const copy = require('clipboard-copy')
var addTooltip = require('./tooltip')
// -------------- styling ----------------------
var csjs = require('csjs-inject')
var remixLib = require('remix-lib')
var styleGuide = remixLib.ui.styleGuide
var styles = styleGuide()
var css = csjs`
.copyIcon {
margin-left: 5px;
cursor: pointer;
}
`
module.exports = function copyToClipboard (getContent) {
var copyIcon = yo`<i title="Copy value to clipboard" class="${css.copyIcon} fa fa-clipboard" aria-hidden="true"></i>`
copyIcon.style.color = styles.remix.icon_Color_CopyToClipboard
copyIcon.onmouseenter = function (event) { copyIcon.style.color = styles.remix.icon_HoverColor_CopyToClipboard }
copyIcon.onmouseleave = function (event) { copyIcon.style.color = styles.remix.icon_Color_CopyToClipboard }
copyIcon.onclick = (event) => {
event.stopPropagation()
var copiableContent = getContent()
if (copiableContent) { // module `copy` keeps last copied thing in the memory, so don't show tooltip if nothing is copied, because nothing was added to memory
copy(copiableContent)
addTooltip(event)
}
}
return copyIcon
}

@ -0,0 +1,52 @@
var yo = require('yo-yo')
// -------------- styling ----------------------
var csjs = require('csjs-inject')
var remixLib = require('remix-lib')
var styleGuide = remixLib.ui.styleGuide
var styles = styleGuide()
var css = csjs`
.tooltip {
visibility: hidden;
width: 100px;
background-color: ${styles.remix.tooltip_CopyToClipboard_BackgroundColor};
color: ${styles.remix.tooltip_CopyToClipboard_Color};
font-weight: bold;
font-size: 12px;
text-transform: initial;
text-align: center;
border-radius: 3px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 160%;
left: 100%;
margin-left: -60px;
opacity: 0;
transition: opacity 1s;
}
.tooltip::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: ${styles.remix.tooltip_CopyToClipboard_BackgroundColor} transparent transparent transparent;
}
`
module.exports = function addTooltip (event) {
var icon = event.target
icon.style.position = 'relative'
var tooltip = yo`<div class=${css.tooltip}>Copied!</div>`
icon.appendChild(tooltip)
var copiedToolbox = event.target.children[0]
copiedToolbox.style.visibility = 'visible'
copiedToolbox.style.opacity = 1
setTimeout(function () {
copiedToolbox.style.visibility = 'hidden'
copiedToolbox.style.opacity = 0
}, 1000)
}

@ -15,9 +15,7 @@ var txHelper = require('./app/execution/txHelper')
var txExecution = require('./app/execution/txExecution')
var helper = require('./lib/helper')
var executionContext = require('./execution-context')
// copy to copyToClipboard
const copy = require('clipboard-copy')
var copyToClipboard = require('./app/ui/copy-to-clipboard')
// -------------- styling ----------------------
var csjs = require('csjs-inject')
@ -42,6 +40,7 @@ var css = csjs`
overflow: hidden;
word-break: break-word;
line-height: initial;
overflow: visible;
}
.titleLine {
display: flex;
@ -71,14 +70,6 @@ var css = csjs`
.instance.hidesub .titleLine {
display: flex;
}
.copy {
cursor: pointer;
margin-left: 3%;
color: ${styles.rightPanel.runTab.icon_Color_Instance_CopyToClipboard};
}
.copy:hover{
color: ${styles.rightPanel.runTab.icon_HoverColor_Instance_CopyToClipboard};
}
.buttonsContainer {
margin-top: 2%;
display: flex;
@ -299,28 +290,20 @@ UniversalDApp.prototype.renderInstance = function (contract, address, contractNa
address = (address.slice(0, 2) === '0x' ? '' : '0x') + address.toString('hex')
var shortAddress = helper.shortenAddress(address)
var title = yo`
<div class=${css.titleLine}>
<div class="${css.title}" onclick=${toggleClass}>
<div class="${css.titleText}"> ${contractName} at ${shortAddress} (${context}) </div>
</div>
<i class="fa fa-clipboard ${css.copy}" aria-hidden="true" onclick=${copyToClipboard} title='Copy to clipboard'></i>
</div>
`
var title = yo`<div class="${css.title}" onclick=${toggleClass}>
<div class="${css.titleText}"> ${contractName} at ${shortAddress} (${context}) </div>
${copyToClipboard(() => address)}
</div>`
if (self.removable_instances) {
var close = yo`<div class="${css.udappClose}" onclick=${remove}><i class="${css.closeIcon} fa fa-close" aria-hidden="true"></i></div>`
title.querySelector(`.${css.title}`).appendChild(close)
instance.append(close)
}
function toggleClass () {
instance.classList.toggle(`${css.hidesub}`)
}
function copyToClipboard (event) {
event.stopPropagation()
copy(address)
}
var abi = txHelper.sortAbiFunction(contract)
instance.appendChild(title)

Loading…
Cancel
Save