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,83 @@
import { createElement, Fragment } from "react";
/**
* WordPress dependencies
*/
import { useRef, Children } from '@wordpress/element';
import { useKeyboardShortcut } from '@wordpress/compose';
/**
* Internal dependencies
*/
function KeyboardShortcut({
target,
callback,
shortcut,
bindGlobal,
eventName
}) {
useKeyboardShortcut(shortcut, callback, {
bindGlobal,
target,
eventName
});
return null;
}
/**
* `KeyboardShortcuts` is a component which handles keyboard sequences during the lifetime of the rendering element.
*
* When passed children, it will capture key events which occur on or within the children. If no children are passed, events are captured on the document.
*
* It uses the [Mousetrap](https://craig.is/killing/mice) library to implement keyboard sequence bindings.
*
* ```jsx
* import { KeyboardShortcuts } from '@wordpress/components';
* import { useState } from '@wordpress/element';
*
* const MyKeyboardShortcuts = () => {
* const [ isAllSelected, setIsAllSelected ] = useState( false );
* const selectAll = () => {
* setIsAllSelected( true );
* };
*
* return (
* <div>
* <KeyboardShortcuts
* shortcuts={ {
* 'mod+a': selectAll,
* } }
* />
* [cmd/ctrl + A] Combination pressed? { isAllSelected ? 'Yes' : 'No' }
* </div>
* );
* };
* ```
*/
function KeyboardShortcuts({
children,
shortcuts,
bindGlobal,
eventName
}) {
const target = useRef(null);
const element = Object.entries(shortcuts !== null && shortcuts !== void 0 ? shortcuts : {}).map(([shortcut, callback]) => createElement(KeyboardShortcut, {
key: shortcut,
shortcut: shortcut,
callback: callback,
bindGlobal: bindGlobal,
eventName: eventName,
target: target
}));
// Render as non-visual if there are no children pressed. Keyboard
// events will be bound to the document instead.
if (!Children.count(children)) {
return createElement(Fragment, null, element);
}
return createElement("div", {
ref: target
}, element, children);
}
export default KeyboardShortcuts;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["useRef","Children","useKeyboardShortcut","KeyboardShortcut","target","callback","shortcut","bindGlobal","eventName","KeyboardShortcuts","children","shortcuts","element","Object","entries","map","createElement","key","count","Fragment","ref"],"sources":["@wordpress/components/src/keyboard-shortcuts/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, Children } from '@wordpress/element';\nimport { useKeyboardShortcut } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport type { KeyboardShortcutProps, KeyboardShortcutsProps } from './types';\n\nfunction KeyboardShortcut( {\n\ttarget,\n\tcallback,\n\tshortcut,\n\tbindGlobal,\n\teventName,\n}: KeyboardShortcutProps ) {\n\tuseKeyboardShortcut( shortcut, callback, {\n\t\tbindGlobal,\n\t\ttarget,\n\t\teventName,\n\t} );\n\n\treturn null;\n}\n\n/**\n * `KeyboardShortcuts` is a component which handles keyboard sequences during the lifetime of the rendering element.\n *\n * When passed children, it will capture key events which occur on or within the children. If no children are passed, events are captured on the document.\n *\n * It uses the [Mousetrap](https://craig.is/killing/mice) library to implement keyboard sequence bindings.\n *\n * ```jsx\n * import { KeyboardShortcuts } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyKeyboardShortcuts = () => {\n * \tconst [ isAllSelected, setIsAllSelected ] = useState( false );\n * \tconst selectAll = () => {\n * \t\tsetIsAllSelected( true );\n * \t};\n *\n * \treturn (\n * \t\t<div>\n * \t\t\t<KeyboardShortcuts\n * \t\t\t\tshortcuts={ {\n * \t\t\t\t\t'mod+a': selectAll,\n * \t\t\t\t} }\n * \t\t\t/>\n * \t\t\t[cmd/ctrl + A] Combination pressed? { isAllSelected ? 'Yes' : 'No' }\n * \t\t</div>\n * \t);\n * };\n * ```\n */\nfunction KeyboardShortcuts( {\n\tchildren,\n\tshortcuts,\n\tbindGlobal,\n\teventName,\n}: KeyboardShortcutsProps ) {\n\tconst target = useRef( null );\n\n\tconst element = Object.entries( shortcuts ?? {} ).map(\n\t\t( [ shortcut, callback ] ) => (\n\t\t\t<KeyboardShortcut\n\t\t\t\tkey={ shortcut }\n\t\t\t\tshortcut={ shortcut }\n\t\t\t\tcallback={ callback }\n\t\t\t\tbindGlobal={ bindGlobal }\n\t\t\t\teventName={ eventName }\n\t\t\t\ttarget={ target }\n\t\t\t/>\n\t\t)\n\t);\n\n\t// Render as non-visual if there are no children pressed. Keyboard\n\t// events will be bound to the document instead.\n\tif ( ! Children.count( children ) ) {\n\t\treturn <>{ element }</>;\n\t}\n\n\treturn (\n\t\t<div ref={ target }>\n\t\t\t{ element }\n\t\t\t{ children }\n\t\t</div>\n\t);\n}\n\nexport default KeyboardShortcuts;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,QAAQ,QAAQ,oBAAoB;AACrD,SAASC,mBAAmB,QAAQ,oBAAoB;;AAExD;AACA;AACA;;AAGA,SAASC,gBAAgBA,CAAE;EAC1BC,MAAM;EACNC,QAAQ;EACRC,QAAQ;EACRC,UAAU;EACVC;AACsB,CAAC,EAAG;EAC1BN,mBAAmB,CAAEI,QAAQ,EAAED,QAAQ,EAAE;IACxCE,UAAU;IACVH,MAAM;IACNI;EACD,CAAE,CAAC;EAEH,OAAO,IAAI;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,iBAAiBA,CAAE;EAC3BC,QAAQ;EACRC,SAAS;EACTJ,UAAU;EACVC;AACuB,CAAC,EAAG;EAC3B,MAAMJ,MAAM,GAAGJ,MAAM,CAAE,IAAK,CAAC;EAE7B,MAAMY,OAAO,GAAGC,MAAM,CAACC,OAAO,CAAEH,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,CAAC,CAAE,CAAC,CAACI,GAAG,CACpD,CAAE,CAAET,QAAQ,EAAED,QAAQ,CAAE,KACvBW,aAAA,CAACb,gBAAgB;IAChBc,GAAG,EAAGX,QAAU;IAChBA,QAAQ,EAAGA,QAAU;IACrBD,QAAQ,EAAGA,QAAU;IACrBE,UAAU,EAAGA,UAAY;IACzBC,SAAS,EAAGA,SAAW;IACvBJ,MAAM,EAAGA;EAAQ,CACjB,CAEH,CAAC;;EAED;EACA;EACA,IAAK,CAAEH,QAAQ,CAACiB,KAAK,CAAER,QAAS,CAAC,EAAG;IACnC,OAAOM,aAAA,CAAAG,QAAA,QAAIP,OAAW,CAAC;EACxB;EAEA,OACCI,aAAA;IAAKI,GAAG,EAAGhB;EAAQ,GAChBQ,OAAO,EACPF,QACE,CAAC;AAER;AAEA,eAAeD,iBAAiB"}

View File

@@ -0,0 +1,3 @@
const KeyboardShortcuts = () => null;
export default KeyboardShortcuts;
//# sourceMappingURL=index.native.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["KeyboardShortcuts"],"sources":["@wordpress/components/src/keyboard-shortcuts/index.native.js"],"sourcesContent":["const KeyboardShortcuts = () => null;\nexport default KeyboardShortcuts;\n"],"mappings":"AAAA,MAAMA,iBAAiB,GAAGA,CAAA,KAAM,IAAI;AACpC,eAAeA,iBAAiB"}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":[],"sources":["@wordpress/components/src/keyboard-shortcuts/types.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { useKeyboardShortcut } from '@wordpress/compose';\n\n// TODO: We wouldn't have to do this if this type was exported from `@wordpress/compose`.\ntype WPKeyboardShortcutConfig = NonNullable<\n\tParameters< typeof useKeyboardShortcut >[ 2 ]\n>;\n\nexport type KeyboardShortcutProps = {\n\tshortcut: string | string[];\n\t/**\n\t * @see {@link https://craig.is/killing/mice Mousetrap documentation}\n\t */\n\tcallback: ( event: Mousetrap.ExtendedKeyboardEvent, combo: string ) => void;\n} & Pick< WPKeyboardShortcutConfig, 'bindGlobal' | 'eventName' | 'target' >;\n\nexport type KeyboardShortcutsProps = {\n\t/**\n\t * Elements to render, upon whom key events are to be monitored.\n\t */\n\tchildren?: React.ReactNode;\n\t/**\n\t * An object of shortcut bindings, where each key is a keyboard combination,\n\t * the value of which is the callback to be invoked when the key combination is pressed.\n\t *\n\t * The value of each shortcut should be a consistent function reference, not an anonymous function.\n\t * Otherwise, the callback will not be correctly unbound when the component unmounts.\n\t *\n\t * The `KeyboardShortcuts` component will not update to reflect a changed `shortcuts` prop.\n\t * If you need to change shortcuts, mount a separate `KeyboardShortcuts` element,\n\t * which can be achieved by assigning a unique `key` prop.\n\t *\n\t * @see {@link https://craig.is/killing/mice Mousetrap documentation}\n\t */\n\tshortcuts: Record< string, KeyboardShortcutProps[ 'callback' ] >;\n\t/**\n\t * By default, a callback will not be invoked if the key combination occurs in an editable field.\n\t * Pass `bindGlobal` as `true` if the key events should be observed globally, including within editable fields.\n\t *\n\t * Tip: If you need some but not all keyboard events to be observed globally,\n\t * simply render two distinct `KeyboardShortcuts` elements, one with and one without the `bindGlobal` prop.\n\t */\n\tbindGlobal?: KeyboardShortcutProps[ 'bindGlobal' ];\n\t/**\n\t * By default, a callback is invoked in response to the `keydown` event.\n\t * To override this, pass `eventName` with the name of a specific keyboard event.\n\t */\n\teventName?: KeyboardShortcutProps[ 'eventName' ];\n};\n"],"mappings":""}