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>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

View File

@@ -0,0 +1,166 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.ConfirmDialog = void 0;
var _react = require("react");
var _i18n = require("@wordpress/i18n");
var _element = require("@wordpress/element");
var _modal = _interopRequireDefault(require("../modal"));
var _context = require("../context");
var _flex = require("../flex");
var _button = _interopRequireDefault(require("../button"));
var _text = require("../text");
var _vStack = require("../v-stack");
var styles = _interopRequireWildcard(require("./styles"));
var _useCx = require("../utils/hooks/use-cx");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const UnconnectedConfirmDialog = (props, forwardedRef) => {
const {
isOpen: isOpenProp,
onConfirm,
onCancel,
children,
confirmButtonText,
cancelButtonText,
...otherProps
} = (0, _context.useContextSystem)(props, 'ConfirmDialog');
const cx = (0, _useCx.useCx)();
const wrapperClassName = cx(styles.wrapper);
const cancelButtonRef = (0, _element.useRef)();
const confirmButtonRef = (0, _element.useRef)();
const [isOpen, setIsOpen] = (0, _element.useState)();
const [shouldSelfClose, setShouldSelfClose] = (0, _element.useState)();
(0, _element.useEffect)(() => {
// We only allow the dialog to close itself if `isOpenProp` is *not* set.
// If `isOpenProp` is set, then it (probably) means it's controlled by a
// parent component. In that case, `shouldSelfClose` might do more harm than
// good, so we disable it.
const isIsOpenSet = typeof isOpenProp !== 'undefined';
setIsOpen(isIsOpenSet ? isOpenProp : true);
setShouldSelfClose(!isIsOpenSet);
}, [isOpenProp]);
const handleEvent = (0, _element.useCallback)(callback => event => {
callback?.(event);
if (shouldSelfClose) {
setIsOpen(false);
}
}, [shouldSelfClose, setIsOpen]);
const handleEnter = (0, _element.useCallback)(event => {
// Avoid triggering the 'confirm' action when a button is focused,
// as this can cause a double submission.
const isConfirmOrCancelButton = event.target === cancelButtonRef.current || event.target === confirmButtonRef.current;
if (!isConfirmOrCancelButton && event.key === 'Enter') {
handleEvent(onConfirm)(event);
}
}, [handleEvent, onConfirm]);
const cancelLabel = cancelButtonText !== null && cancelButtonText !== void 0 ? cancelButtonText : (0, _i18n.__)('Cancel');
const confirmLabel = confirmButtonText !== null && confirmButtonText !== void 0 ? confirmButtonText : (0, _i18n.__)('OK');
return (0, _react.createElement)(_react.Fragment, null, isOpen && (0, _react.createElement)(_modal.default, {
onRequestClose: handleEvent(onCancel),
onKeyDown: handleEnter,
closeButtonLabel: cancelLabel,
isDismissible: true,
ref: forwardedRef,
overlayClassName: wrapperClassName,
__experimentalHideHeader: true,
...otherProps
}, (0, _react.createElement)(_vStack.VStack, {
spacing: 8
}, (0, _react.createElement)(_text.Text, null, children), (0, _react.createElement)(_flex.Flex, {
direction: "row",
justify: "flex-end"
}, (0, _react.createElement)(_button.default, {
ref: cancelButtonRef,
variant: "tertiary",
onClick: handleEvent(onCancel)
}, cancelLabel), (0, _react.createElement)(_button.default, {
ref: confirmButtonRef,
variant: "primary",
onClick: handleEvent(onConfirm)
}, confirmLabel)))));
};
/**
* `ConfirmDialog` is built of top of [`Modal`](/packages/components/src/modal/README.md)
* and displays a confirmation dialog, with _confirm_ and _cancel_ buttons.
* The dialog is confirmed by clicking the _confirm_ button or by pressing the `Enter` key.
* It is cancelled (closed) by clicking the _cancel_ button, by pressing the `ESC` key, or by
* clicking outside the dialog focus (i.e, the overlay).
*
* `ConfirmDialog` has two main implicit modes: controlled and uncontrolled.
*
* UnControlled:
*
* Allows the component to be used standalone, just by declaring it as part of another React's component render method:
* - It will be automatically open (displayed) upon mounting;
* - It will be automatically closed when clicking the _cancel_ button, by pressing the `ESC` key, or by clicking outside the dialog focus (i.e, the overlay);
* - `onCancel` is not mandatory but can be passed. Even if passed, the dialog will still be able to close itself.
*
* Activating this mode is as simple as omitting the `isOpen` prop. The only mandatory prop, in this case, is the `onConfirm` callback. The message is passed as the `children`. You can pass any JSX you'd like, which allows to further format the message or include sub-component if you'd like:
*
* ```jsx
* import { __experimentalConfirmDialog as ConfirmDialog } from '@wordpress/components';
*
* function Example() {
* return (
* <ConfirmDialog onConfirm={ () => console.debug( ' Confirmed! ' ) }>
* Are you sure? <strong>This action cannot be undone!</strong>
* </ConfirmDialog>
* );
* }
* ```
*
*
* Controlled mode:
* Let the parent component control when the dialog is open/closed. It's activated when a
* boolean value is passed to `isOpen`:
* - It will not be automatically closed. You need to let it know when to open/close by updating the value of the `isOpen` prop;
* - Both `onConfirm` and the `onCancel` callbacks are mandatory props in this mode;
* - You'll want to update the state that controls `isOpen` by updating it from the `onCancel` and `onConfirm` callbacks.
*
*```jsx
* import { __experimentalConfirmDialog as ConfirmDialog } from '@wordpress/components';
* import { useState } from '@wordpress/element';
*
* function Example() {
* const [ isOpen, setIsOpen ] = useState( true );
*
* const handleConfirm = () => {
* console.debug( 'Confirmed!' );
* setIsOpen( false );
* };
*
* const handleCancel = () => {
* console.debug( 'Cancelled!' );
* setIsOpen( false );
* };
*
* return (
* <ConfirmDialog
* isOpen={ isOpen }
* onConfirm={ handleConfirm }
* onCancel={ handleCancel }
* >
* Are you sure? <strong>This action cannot be undone!</strong>
* </ConfirmDialog>
* );
* }
* ```
*/
const ConfirmDialog = (0, _context.contextConnect)(UnconnectedConfirmDialog, 'ConfirmDialog');
exports.ConfirmDialog = ConfirmDialog;
var _default = ConfirmDialog;
exports.default = _default;
//# sourceMappingURL=component.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,14 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "ConfirmDialog", {
enumerable: true,
get: function () {
return _component.default;
}
});
var _component = _interopRequireDefault(require("./component"));
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["_component","_interopRequireDefault","require"],"sources":["@wordpress/components/src/confirm-dialog/index.tsx"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport ConfirmDialog from './component';\n\nexport { ConfirmDialog };\n"],"mappings":";;;;;;;;;;;;AAGA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA"}

View File

@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.wrapper = void 0;
var _react = require("@emotion/react");
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
/**
* The z-index for ConfirmDialog is being set here instead of in
* packages/base-styles/_z-index.scss, because this component uses
* emotion instead of sass.
*
* ConfirmDialog needs this higher z-index to ensure it renders on top of
* any parent Popover component.
*/
const wrapper = process.env.NODE_ENV === "production" ? {
name: "7g5ii0",
styles: "&&{z-index:1000001;}"
} : {
name: "1gucf3d-wrapper",
styles: "&&{z-index:1000001;};label:wrapper;",
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvY29uZmlybS1kaWFsb2cvc3R5bGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQWEwQiIsImZpbGUiOiJAd29yZHByZXNzL2NvbXBvbmVudHMvc3JjL2NvbmZpcm0tZGlhbG9nL3N0eWxlcy50cyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogRXh0ZXJuYWwgZGVwZW5kZW5jaWVzXG4gKi9cbmltcG9ydCB7IGNzcyB9IGZyb20gJ0BlbW90aW9uL3JlYWN0JztcblxuLyoqXG4gKiBUaGUgei1pbmRleCBmb3IgQ29uZmlybURpYWxvZyBpcyBiZWluZyBzZXQgaGVyZSBpbnN0ZWFkIG9mIGluXG4gKiBwYWNrYWdlcy9iYXNlLXN0eWxlcy9fei1pbmRleC5zY3NzLCBiZWNhdXNlIHRoaXMgY29tcG9uZW50IHVzZXNcbiAqIGVtb3Rpb24gaW5zdGVhZCBvZiBzYXNzLlxuICpcbiAqIENvbmZpcm1EaWFsb2cgbmVlZHMgdGhpcyBoaWdoZXIgei1pbmRleCB0byBlbnN1cmUgaXQgcmVuZGVycyBvbiB0b3Agb2ZcbiAqIGFueSBwYXJlbnQgUG9wb3ZlciBjb21wb25lbnQuXG4gKi9cbmV4cG9ydCBjb25zdCB3cmFwcGVyID0gY3NzYFxuXHQmJiB7XG5cdFx0ei1pbmRleDogMTAwMDAwMTtcblx0fVxuYDtcbiJdfQ== */",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
};
exports.wrapper = wrapper;
//# sourceMappingURL=styles.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["_react","require","_EMOTION_STRINGIFIED_CSS_ERROR__","wrapper","process","env","NODE_ENV","name","styles","map","toString","exports"],"sources":["@wordpress/components/src/confirm-dialog/styles.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport { css } from '@emotion/react';\n\n/**\n * The z-index for ConfirmDialog is being set here instead of in\n * packages/base-styles/_z-index.scss, because this component uses\n * emotion instead of sass.\n *\n * ConfirmDialog needs this higher z-index to ensure it renders on top of\n * any parent Popover component.\n */\nexport const wrapper = css`\n\t&& {\n\t\tz-index: 1000001;\n\t}\n`;\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AAAqC,SAAAC,iCAAA;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,OAAO,GAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA;EAAAC,IAAA;EAAAC,MAAA;AAAA;EAAAD,IAAA;EAAAC,MAAA;EAAAC,GAAA;EAAAC,QAAA,EAAAR;AAAA,CAInB;AAACS,OAAA,CAAAR,OAAA,GAAAA,OAAA"}

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":[],"sources":["@wordpress/components/src/confirm-dialog/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { MouseEvent, KeyboardEvent, ReactNode } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { ModalProps } from '../modal/types';\n\nexport type DialogInputEvent =\n\t| Parameters< ModalProps[ 'onRequestClose' ] >[ 0 ]\n\t| KeyboardEvent< HTMLDivElement >\n\t| MouseEvent< HTMLButtonElement >;\n\nexport type ConfirmDialogProps = {\n\t/**\n\t * The actual message for the dialog. It's passed as children and any valid `ReactNode` is accepted.\n\t */\n\tchildren: ReactNode;\n\t/**\n\t * The callback that's called when the user confirms.\n\t * A confirmation can happen when the `OK` button is clicked or when `Enter` is pressed.\n\t */\n\tonConfirm: ( event: DialogInputEvent ) => void;\n\t/**\n\t * The optional custom text to display as the confirmation button's label.\n\t */\n\tconfirmButtonText?: string;\n\t/**\n\t * The optional custom text to display as the cancellation button's label.\n\t */\n\tcancelButtonText?: string;\n\t/**\n\t * The callback that's called when the user cancels. A cancellation can happen\n\t * when the `Cancel` button is clicked, when the `ESC` key is pressed, or when\n\t * a click outside of the dialog focus is detected (i.e. in the overlay).\n\t *\n\t * It's not required if `isOpen` is not set (uncontrolled mode), as the component\n\t * will take care of closing itself, but you can still pass a callback if something\n\t * must be done upon cancelling (the component will still close itself in this case).\n\t *\n\t * If `isOpen` is set (controlled mode), then it's required, and you need to set\n\t * the state that defines `isOpen` to `false` as part of this callback if you want the\n\t * dialog to close when the user cancels.\n\t */\n\tonCancel?: ( event: DialogInputEvent ) => void;\n\t/**\n\t * Defines if the dialog is open (displayed) or closed (not rendered/displayed).\n\t * It also implicitly toggles the controlled mode if set or the uncontrolled mode if it's not set.\n\t */\n\tisOpen?: boolean;\n};\n"],"mappings":""}