diff --git a/components/debug-panel/debug-panel.tsx b/components/debug-panel/debug-panel.tsx index 6fb68cbdd..12bf73707 100644 --- a/components/debug-panel/debug-panel.tsx +++ b/components/debug-panel/debug-panel.tsx @@ -7,8 +7,10 @@ import { breakpoints, IconButton, RowButton, IconWrapper } from '../shared' import { Cross2Icon, PlayIcon, + DotIcon, CrumpledPaperIcon, StopIcon, + ClipboardIcon, ClipboardCopyIcon, } from '@radix-ui/react-icons' import logger from 'state/logger' @@ -16,6 +18,7 @@ import { useStateDesigner } from '@state-designer/react' const stopPropagation = (e: React.KeyboardEvent) => e.stopPropagation() const toggleDebugPanel = () => state.send('TOGGLED_DEBUG_PANEL') +const handleStateCopy = () => state.send('COPIED_STATE_TO_CLIPBOARD') export default function CodePanel(): JSX.Element { const rContainer = useRef(null) @@ -104,12 +107,19 @@ export default function CodePanel(): JSX.Element {
+
+ + Copy State + + + +
{local.isIn('stopped') ? ( Start Logger - + ) : ( @@ -120,19 +130,15 @@ export default function CodePanel(): JSX.Element { )} - { - + - Copy Log - - - - - } - + + Play Back Log + + +
@@ -185,7 +194,8 @@ const StylePanelRoot = styled(Panel.Root, { }) const JSONTextAreaWrapper = styled('div', { - padding: '4px', + position: 'relative', + margin: '4px 0', }) const JSONTextArea = styled('textarea', { diff --git a/state/clipboard.ts b/state/clipboard.ts index 4abde7a87..65cbf488f 100644 --- a/state/clipboard.ts +++ b/state/clipboard.ts @@ -119,30 +119,34 @@ class Clipboard { } copyStringToClipboard = (string: string) => { - const textarea = document.createElement('textarea') - textarea.setAttribute('position', 'fixed') - textarea.setAttribute('top', '0') - textarea.setAttribute('readonly', 'true') - textarea.setAttribute('contenteditable', 'true') - textarea.style.position = 'fixed' - textarea.value = string - document.body.appendChild(textarea) - textarea.focus() - textarea.select() - try { - const range = document.createRange() - range.selectNodeContents(textarea) + navigator.clipboard.writeText(string) + } catch (e) { + const textarea = document.createElement('textarea') + textarea.setAttribute('position', 'fixed') + textarea.setAttribute('top', '0') + textarea.setAttribute('readonly', 'true') + textarea.setAttribute('contenteditable', 'true') + textarea.style.position = 'fixed' + textarea.value = string + document.body.appendChild(textarea) + textarea.focus() + textarea.select() - const sel = window.getSelection() - sel.removeAllRanges() - sel.addRange(range) + try { + const range = document.createRange() + range.selectNodeContents(textarea) - textarea.setSelectionRange(0, textarea.value.length) - } catch (err) { - null // Could not copy to clipboard - } finally { - document.body.removeChild(textarea) + const sel = window.getSelection() + sel.removeAllRanges() + sel.addRange(range) + + textarea.setSelectionRange(0, textarea.value.length) + } catch (err) { + null // Could not copy to clipboard + } finally { + document.body.removeChild(textarea) + } } return this