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>
72 lines
2.6 KiB
JavaScript
72 lines
2.6 KiB
JavaScript
/**
|
|
* WordPress dependencies
|
|
*/
|
|
import warn from '@wordpress/warning';
|
|
|
|
/**
|
|
* Internal dependencies
|
|
*/
|
|
import { useComponentsContext } from './context-system-provider';
|
|
import { getNamespace, getConnectedNamespace } from './utils';
|
|
import { getStyledClassNameFromKey } from './get-styled-class-name-from-key';
|
|
import { useCx } from '../utils/hooks/use-cx';
|
|
|
|
/**
|
|
* @template TProps
|
|
* @typedef {TProps & { className: string }} ConnectedProps
|
|
*/
|
|
|
|
/**
|
|
* Custom hook that derives registered props from the Context system.
|
|
* These derived props are then consolidated with incoming component props.
|
|
*
|
|
* @template {{ className?: string }} P
|
|
* @param {P} props Incoming props from the component.
|
|
* @param {string} namespace The namespace to register and to derive context props from.
|
|
* @return {ConnectedProps<P>} The connected props.
|
|
*/
|
|
export function useContextSystem(props, namespace) {
|
|
const contextSystemProps = useComponentsContext();
|
|
if (typeof namespace === 'undefined') {
|
|
typeof SCRIPT_DEBUG !== "undefined" && SCRIPT_DEBUG === true ? warn('useContextSystem: Please provide a namespace') : void 0;
|
|
}
|
|
const contextProps = contextSystemProps?.[namespace] || {};
|
|
|
|
/* eslint-disable jsdoc/no-undefined-types */
|
|
/** @type {ConnectedProps<P>} */
|
|
// @ts-ignore We fill in the missing properties below
|
|
const finalComponentProps = {
|
|
...getConnectedNamespace(),
|
|
...getNamespace(namespace)
|
|
};
|
|
/* eslint-enable jsdoc/no-undefined-types */
|
|
|
|
const {
|
|
_overrides: overrideProps,
|
|
...otherContextProps
|
|
} = contextProps;
|
|
const initialMergedProps = Object.entries(otherContextProps).length ? Object.assign({}, otherContextProps, props) : props;
|
|
const cx = useCx();
|
|
const classes = cx(getStyledClassNameFromKey(namespace), props.className);
|
|
|
|
// Provides the ability to customize the render of the component.
|
|
const rendered = typeof initialMergedProps.renderChildren === 'function' ? initialMergedProps.renderChildren(initialMergedProps) : initialMergedProps.children;
|
|
for (const key in initialMergedProps) {
|
|
// @ts-ignore filling in missing props
|
|
finalComponentProps[key] = initialMergedProps[key];
|
|
}
|
|
for (const key in overrideProps) {
|
|
// @ts-ignore filling in missing props
|
|
finalComponentProps[key] = overrideProps[key];
|
|
}
|
|
|
|
// Setting an `undefined` explicitly can cause unintended overwrites
|
|
// when a `cloneElement()` is involved.
|
|
if (rendered !== undefined) {
|
|
// @ts-ignore
|
|
finalComponentProps.children = rendered;
|
|
}
|
|
finalComponentProps.className = classes;
|
|
return finalComponentProps;
|
|
}
|
|
//# sourceMappingURL=use-context-system.js.map
|