Fixed copy to clipboard

pull/5370/head
ioedeveloper 4 years ago
parent 958a325d3d
commit 9aca1f068b
  1. 21
      libs/remix-ui/clipboard/src/lib/copy-to-clipboard/copy-to-clipboard.tsx
  2. 5
      libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx
  3. 43
      libs/remix-ui/debugger-ui/src/lib/vm-debugger/dropdown-panel.tsx
  4. 2
      libs/remix-ui/debugger-ui/src/lib/vm-debugger/full-storages-changes.tsx

@ -1,28 +1,19 @@
import React from 'react' import React from 'react'
import * as copy from 'copy-text-to-clipboard' import copy from 'copy-text-to-clipboard'
import './copy-to-clipboard.css' import './copy-to-clipboard.css'
export const CopyToClipboard = ({ getContent, tip='Copy value to clipboard', icon='fa-copy', ...otherProps }) => { export const CopyToClipboard = ({ content, tip='Copy value to clipboard', icon='fa-copy', ...otherProps }) => {
const handleClick = () => { const handleClick = () => {
let copiableContent:string if (content) { // module `copy` keeps last copied thing in the memory, so don't show tooltip if nothing is copied, because nothing was added to memory
try {
copiableContent = getContent()
} catch (e) {
// addTooltip(e.message)
return
}
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
try { try {
if (typeof copiableContent !== 'string') { if (typeof content !== 'string') {
copiableContent = JSON.stringify(copiableContent, null, '\t') content = JSON.stringify(content, null, '\t')
} }
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
copy(copiableContent) copy(content)
// addTooltip('Copied value to clipboard.') // addTooltip('Copied value to clipboard.')
} else { } else {
// addTooltip('Cannot copy empty content!') // addTooltip('Cannot copy empty content!')

@ -9,13 +9,10 @@ import toaster from '../../../../../apps/remix-ide/src/app/ui/tooltip'
/* eslint-disable-next-line */ /* eslint-disable-next-line */
import SourceHighlighter from '../../../../../apps/remix-ide/src/app/editor/sourceHighlighter' import SourceHighlighter from '../../../../../apps/remix-ide/src/app/editor/sourceHighlighter'
/* eslint-disable-next-line */ /* eslint-disable-next-line */
import EventManager from '../../../../../apps/remix-ide/src/lib/events'
/* eslint-disable-next-line */
import globalRegistry from '../../../../../apps/remix-ide/src/global/registry' import globalRegistry from '../../../../../apps/remix-ide/src/global/registry'
import './debugger-ui.css' import './debugger-ui.css'
export const DebuggerUI = ({ debuggerModule, fetchContractAndCompile, debugHash, getTraceHash, removeHighlights }) => { export const DebuggerUI = ({ debuggerModule, fetchContractAndCompile, debugHash, getTraceHash, removeHighlights }) => {
const event = new EventManager()
const sourceHighlighter = new SourceHighlighter() const sourceHighlighter = new SourceHighlighter()
const init = remixDebug.init const init = remixDebug.init
const [state, setState] = useState({ const [state, setState] = useState({
@ -143,7 +140,7 @@ export const DebuggerUI = ({ debuggerModule, fetchContractAndCompile, debugHash,
// } // }
// } // }
// }) // })
event.trigger('traceUnloaded', []) // event.trigger('traceUnloaded', [])
} }
const startDebugging = async (blockNumber, txNumber, tx) => { const startDebugging = async (blockNumber, txNumber, tx) => {

@ -6,13 +6,10 @@ import { CopyToClipboard } from '@remix-ui/clipboard'
import './styles/dropdown-panel.css' import './styles/dropdown-panel.css'
/* eslint-disable-next-line */
import EventManager from '../../../../../../apps/remix-ide/src/lib/events'
export const DropdownPanel = (props: DropdownPanelProps) => { export const DropdownPanel = (props: DropdownPanelProps) => {
const { dropdownName, dropdownMessage, opts, calldata, header, loading, extractFunc, formatSelfFunc } = props const { dropdownName, dropdownMessage, opts, calldata, header, loading, extractFunc, formatSelfFunc } = props
const data = useExtractData(calldata, extractFunc) const data = useExtractData(calldata, extractFunc)
const event = new EventManager()
const dropdownRawEl = useRef(null) const dropdownRawEl = useRef(null)
const [state, setState] = useState({ const [state, setState] = useState({
header: '', header: '',
@ -26,14 +23,11 @@ export const DropdownPanel = (props: DropdownPanelProps) => {
innerText: '', innerText: '',
display: 'none' display: 'none'
}, },
dropdownRawContent: {
innerText: '',
display: 'none'
},
title: { title: {
innerText: '', innerText: '',
display: 'none' display: 'none'
}, },
copiableContent: '',
updating: false updating: false
}) })
@ -51,8 +45,6 @@ export const DropdownPanel = (props: DropdownPanelProps) => {
const handleToggle = () => { const handleToggle = () => {
setState(prevState => { setState(prevState => {
if (prevState.toggleDropdown) event.trigger('hide', [])
else event.trigger('show', [])
return { return {
...prevState, ...prevState,
toggleDropdown: !prevState.toggleDropdown toggleDropdown: !prevState.toggleDropdown
@ -86,14 +78,11 @@ export const DropdownPanel = (props: DropdownPanelProps) => {
innerText: '', innerText: '',
display: 'none' display: 'none'
}, },
dropdownRawContent: {
...prevState.dropdownRawContent,
display: 'none'
},
dropdownContent: { dropdownContent: {
...prevState.dropdownContent, ...prevState.dropdownContent,
display: 'none' display: 'none'
}, },
copiableContent: '',
updating: true updating: true
} }
}) })
@ -107,35 +96,12 @@ export const DropdownPanel = (props: DropdownPanelProps) => {
...prevState.dropdownContent, ...prevState.dropdownContent,
display: 'block' display: 'block'
}, },
dropdownRawContent: { copiableContent: JSON.stringify(calldata, null, '\t'),
innerText: JSON.stringify(calldata, null, '\t'),
display: 'block'
},
updating: false updating: false
} }
}) })
} }
const hide = () => {
setState(prevState => {
return {
...prevState,
toggleDropdown: false
}
})
event.trigger('hide', [])
}
const show = () => {
setState(prevState => {
return {
...prevState,
toggleDropdown: true
}
})
event.trigger('show', [])
}
const formatSelfDefault = (key: string, data: ExtractData) => { const formatSelfDefault = (key: string, data: ExtractData) => {
return ( return (
<div className="d-flex mb-1 flex-row label_item"> <div className="d-flex mb-1 flex-row label_item">
@ -180,7 +146,7 @@ export const DropdownPanel = (props: DropdownPanelProps) => {
const title = <div className="py-0 px-1 title"> const title = <div className="py-0 px-1 title">
<div className={state.toggleDropdown ? 'icon fas fa-caret-down' : 'icon fas fa-caret-right'} onClick={handleToggle}></div> <div className={state.toggleDropdown ? 'icon fas fa-caret-down' : 'icon fas fa-caret-right'} onClick={handleToggle}></div>
<div className="name" onClick={handleToggle}>{dropdownName}</div><span className="nameDetail" onClick={handleToggle}>{ header }</span> <div className="name" onClick={handleToggle}>{dropdownName}</div><span className="nameDetail" onClick={handleToggle}>{ header }</span>
<CopyToClipboard getContent={copyClipboard} /> <CopyToClipboard content={state.copiableContent} />
</div> </div>
return ( return (
@ -191,7 +157,6 @@ export const DropdownPanel = (props: DropdownPanelProps) => {
<div className='dropdowncontent' style={{ display: state.dropdownContent.display }}> <div className='dropdowncontent' style={{ display: state.dropdownContent.display }}>
{ content } { content }
</div> </div>
<div className='dropdownrawcontent' style={{ display: state.dropdownRawContent.display }} ref={ dropdownRawEl }></div>
<div className='message' style={{ display: state.message.display }}>{ state.message.innerText }</div> <div className='message' style={{ display: state.message.display }}>{ state.message.innerText }</div>
</div> </div>
</div> </div>

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import Dropdown, { DropdownPanel } from './dropdown-panel' import { DropdownPanel } from './dropdown-panel'
export const FullStoragesChanges = ({ storageData }) => { export const FullStoragesChanges = ({ storageData }) => {
return ( return (

Loading…
Cancel
Save