import { Component } from "@wordpress/element"; import { safeDecodeURIComponent, addQueryArgs } from "@wordpress/url"; import { TextControl, Button, Flex } from "@wordpress/components"; import { withSelect } from "@wordpress/data"; import { useCopyToClipboard } from "@wordpress/compose"; import { store as editorStore } from "@wordpress/editor"; import { __ } from "@wordpress/i18n"; import CONSTANTS from "./constants"; const { META_KEY, QUERY_PARAM } = CONSTANTS; /** * Taken from PostPublishPanelPostpublish (@wordpress/editor) */ const CopyButton = ({ text, onCopy, children, ...props }) => { const ref = useCopyToClipboard(text, onCopy); return ( ); }; class CopyUrl extends Component { constructor() { super(...arguments); this.state = { showCopyConfirmation: false, }; this.onCopy = this.onCopy.bind(this); this.onSelectInput = this.onSelectInput.bind(this); } componentWillUnmount() { clearTimeout(this.dismissCopyConfirmation); } onCopy() { this.setState({ showCopyConfirmation: true, }); clearTimeout(this.dismissCopyConfirmation); this.dismissCopyConfirmation = setTimeout(() => { this.setState({ showCopyConfirmation: false, }); }, 4000); } onSelectInput(event) { event.target.select(); } render() { const url = addQueryArgs(this.props.postLink, { [QUERY_PARAM]: this.props.secretKey, }); return (