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>
118 lines
3.6 KiB
JavaScript
118 lines
3.6 KiB
JavaScript
"use strict";
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.PanelBody = void 0;
|
|
exports.UnforwardedPanelBody = UnforwardedPanelBody;
|
|
exports.default = void 0;
|
|
var _react = require("react");
|
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
var _compose = require("@wordpress/compose");
|
|
var _element = require("@wordpress/element");
|
|
var _icons = require("@wordpress/icons");
|
|
var _button = _interopRequireDefault(require("../button"));
|
|
var _icon = _interopRequireDefault(require("../icon"));
|
|
var _utils = require("../utils");
|
|
/**
|
|
* External dependencies
|
|
*/
|
|
|
|
/**
|
|
* WordPress dependencies
|
|
*/
|
|
|
|
const noop = () => {};
|
|
function UnforwardedPanelBody(props, ref) {
|
|
const {
|
|
buttonProps = {},
|
|
children,
|
|
className,
|
|
icon,
|
|
initialOpen,
|
|
onToggle = noop,
|
|
opened,
|
|
title,
|
|
scrollAfterOpen = true
|
|
} = props;
|
|
const [isOpened, setIsOpened] = (0, _utils.useControlledState)(opened, {
|
|
initial: initialOpen === undefined ? true : initialOpen,
|
|
fallback: false
|
|
});
|
|
const nodeRef = (0, _element.useRef)(null);
|
|
|
|
// Defaults to 'smooth' scrolling
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
|
|
const scrollBehavior = (0, _compose.useReducedMotion)() ? 'auto' : 'smooth';
|
|
const handleOnToggle = event => {
|
|
event.preventDefault();
|
|
const next = !isOpened;
|
|
setIsOpened(next);
|
|
onToggle(next);
|
|
};
|
|
|
|
// Ref is used so that the effect does not re-run upon scrollAfterOpen changing value.
|
|
const scrollAfterOpenRef = (0, _element.useRef)();
|
|
scrollAfterOpenRef.current = scrollAfterOpen;
|
|
// Runs after initial render.
|
|
(0, _utils.useUpdateEffect)(() => {
|
|
if (isOpened && scrollAfterOpenRef.current && nodeRef.current?.scrollIntoView) {
|
|
/*
|
|
* Scrolls the content into view when visible.
|
|
* This improves the UX when there are multiple stacking <PanelBody />
|
|
* components in a scrollable container.
|
|
*/
|
|
nodeRef.current.scrollIntoView({
|
|
inline: 'nearest',
|
|
block: 'nearest',
|
|
behavior: scrollBehavior
|
|
});
|
|
}
|
|
}, [isOpened, scrollBehavior]);
|
|
const classes = (0, _classnames.default)('components-panel__body', className, {
|
|
'is-opened': isOpened
|
|
});
|
|
return (0, _react.createElement)("div", {
|
|
className: classes,
|
|
ref: (0, _compose.useMergeRefs)([nodeRef, ref])
|
|
}, (0, _react.createElement)(PanelBodyTitle, {
|
|
icon: icon,
|
|
isOpened: Boolean(isOpened),
|
|
onClick: handleOnToggle,
|
|
title: title,
|
|
...buttonProps
|
|
}), typeof children === 'function' ? children({
|
|
opened: Boolean(isOpened)
|
|
}) : isOpened && children);
|
|
}
|
|
const PanelBodyTitle = (0, _element.forwardRef)(({
|
|
isOpened,
|
|
icon,
|
|
title,
|
|
...props
|
|
}, ref) => {
|
|
if (!title) return null;
|
|
return (0, _react.createElement)("h2", {
|
|
className: "components-panel__body-title"
|
|
}, (0, _react.createElement)(_button.default, {
|
|
className: "components-panel__body-toggle",
|
|
"aria-expanded": isOpened,
|
|
ref: ref,
|
|
...props
|
|
}, (0, _react.createElement)("span", {
|
|
"aria-hidden": "true"
|
|
}, (0, _react.createElement)(_icon.default, {
|
|
className: "components-panel__arrow",
|
|
icon: isOpened ? _icons.chevronUp : _icons.chevronDown
|
|
})), title, icon && (0, _react.createElement)(_icon.default, {
|
|
icon: icon,
|
|
className: "components-panel__icon",
|
|
size: 20
|
|
})));
|
|
});
|
|
const PanelBody = (0, _element.forwardRef)(UnforwardedPanelBody);
|
|
exports.PanelBody = PanelBody;
|
|
var _default = PanelBody;
|
|
exports.default = _default;
|
|
//# sourceMappingURL=body.js.map
|