Files
formipay/node_modules/@wordpress/components/build-module/clipboard-button/index.js
dwindown e8fbfb14c1 fix: prevent asset conflicts between React and Grid.js versions
Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-18 17:02:14 +07:00

64 lines
1.7 KiB
JavaScript

import { createElement } from "react";
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useRef, useEffect } from '@wordpress/element';
import { useCopyToClipboard } from '@wordpress/compose';
import deprecated from '@wordpress/deprecated';
/**
* Internal dependencies
*/
import Button from '../button';
const TIMEOUT = 4000;
export default function ClipboardButton({
className,
children,
onCopy,
onFinishCopy,
text,
...buttonProps
}) {
deprecated('wp.components.ClipboardButton', {
since: '5.8',
alternative: 'wp.compose.useCopyToClipboard'
});
const timeoutId = useRef();
const ref = useCopyToClipboard(text, () => {
onCopy();
if (timeoutId.current) {
clearTimeout(timeoutId.current);
}
if (onFinishCopy) {
timeoutId.current = setTimeout(() => onFinishCopy(), TIMEOUT);
}
});
useEffect(() => {
if (timeoutId.current) {
clearTimeout(timeoutId.current);
}
}, []);
const classes = classnames('components-clipboard-button', className);
// Workaround for inconsistent behavior in Safari, where <textarea> is not
// the document.activeElement at the moment when the copy event fires.
// This causes documentHasSelection() in the copy-handler component to
// mistakenly override the ClipboardButton, and copy a serialized string
// of the current block instead.
const focusOnCopyEventTarget = event => {
// @ts-expect-error: Should be currentTarget, but not changing because this component is deprecated.
event.target.focus();
};
return createElement(Button, {
...buttonProps,
className: classes,
ref: ref,
onCopy: focusOnCopyEventTarget
}, children);
}
//# sourceMappingURL=index.js.map