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,79 @@
/**
* WordPress dependencies
*/
import { useEffect } from '@wordpress/element';
/*
* Setting `overflow: hidden` on html and body elements resets body scroll in iOS.
* Save scroll top so we can restore it after locking scroll.
*
* NOTE: It would be cleaner and possibly safer to find a localized solution such
* as preventing default on certain touchmove events.
*/
let previousScrollTop = 0;
function setLocked(locked) {
const scrollingElement = document.scrollingElement || document.body;
if (locked) {
previousScrollTop = scrollingElement.scrollTop;
}
const methodName = locked ? 'add' : 'remove';
scrollingElement.classList[methodName]('lockscroll');
// Adding the class to the document element seems to be necessary in iOS.
document.documentElement.classList[methodName]('lockscroll');
if (!locked) {
scrollingElement.scrollTop = previousScrollTop;
}
}
let lockCounter = 0;
/**
* ScrollLock is a content-free React component for declaratively preventing
* scroll bleed from modal UI to the page body. This component applies a
* `lockscroll` class to the `document.documentElement` and
* `document.scrollingElement` elements to stop the body from scrolling. When it
* is present, the lock is applied.
*
* ```jsx
* import { ScrollLock, Button } from '@wordpress/components';
* import { useState } from '@wordpress/element';
*
* const MyScrollLock = () => {
* const [ isScrollLocked, setIsScrollLocked ] = useState( false );
*
* const toggleLock = () => {
* setIsScrollLocked( ( locked ) => ! locked ) );
* };
*
* return (
* <div>
* <Button variant="secondary" onClick={ toggleLock }>
* Toggle scroll lock
* </Button>
* { isScrollLocked && <ScrollLock /> }
* <p>
* Scroll locked:
* <strong>{ isScrollLocked ? 'Yes' : 'No' }</strong>
* </p>
* </div>
* );
* };
* ```
*/
export function ScrollLock() {
useEffect(() => {
if (lockCounter === 0) {
setLocked(true);
}
++lockCounter;
return () => {
if (lockCounter === 1) {
setLocked(false);
}
--lockCounter;
};
}, []);
return null;
}
export default ScrollLock;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["useEffect","previousScrollTop","setLocked","locked","scrollingElement","document","body","scrollTop","methodName","classList","documentElement","lockCounter","ScrollLock"],"sources":["@wordpress/components/src/scroll-lock/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\n\n/*\n * Setting `overflow: hidden` on html and body elements resets body scroll in iOS.\n * Save scroll top so we can restore it after locking scroll.\n *\n * NOTE: It would be cleaner and possibly safer to find a localized solution such\n * as preventing default on certain touchmove events.\n */\nlet previousScrollTop = 0;\n\nfunction setLocked( locked: boolean ) {\n\tconst scrollingElement = document.scrollingElement || document.body;\n\n\tif ( locked ) {\n\t\tpreviousScrollTop = scrollingElement.scrollTop;\n\t}\n\n\tconst methodName = locked ? 'add' : 'remove';\n\tscrollingElement.classList[ methodName ]( 'lockscroll' );\n\n\t// Adding the class to the document element seems to be necessary in iOS.\n\tdocument.documentElement.classList[ methodName ]( 'lockscroll' );\n\n\tif ( ! locked ) {\n\t\tscrollingElement.scrollTop = previousScrollTop;\n\t}\n}\n\nlet lockCounter = 0;\n\n/**\n * ScrollLock is a content-free React component for declaratively preventing\n * scroll bleed from modal UI to the page body. This component applies a\n * `lockscroll` class to the `document.documentElement` and\n * `document.scrollingElement` elements to stop the body from scrolling. When it\n * is present, the lock is applied.\n *\n * ```jsx\n * import { ScrollLock, Button } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyScrollLock = () => {\n * const [ isScrollLocked, setIsScrollLocked ] = useState( false );\n *\n * const toggleLock = () => {\n * setIsScrollLocked( ( locked ) => ! locked ) );\n * };\n *\n * return (\n * <div>\n * <Button variant=\"secondary\" onClick={ toggleLock }>\n * Toggle scroll lock\n * </Button>\n * { isScrollLocked && <ScrollLock /> }\n * <p>\n * Scroll locked:\n * <strong>{ isScrollLocked ? 'Yes' : 'No' }</strong>\n * </p>\n * </div>\n * );\n * };\n * ```\n */\nexport function ScrollLock(): null {\n\tuseEffect( () => {\n\t\tif ( lockCounter === 0 ) {\n\t\t\tsetLocked( true );\n\t\t}\n\n\t\t++lockCounter;\n\n\t\treturn () => {\n\t\t\tif ( lockCounter === 1 ) {\n\t\t\t\tsetLocked( false );\n\t\t\t}\n\n\t\t\t--lockCounter;\n\t\t};\n\t}, [] );\n\n\treturn null;\n}\n\nexport default ScrollLock;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,oBAAoB;;AAE9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIC,iBAAiB,GAAG,CAAC;AAEzB,SAASC,SAASA,CAAEC,MAAe,EAAG;EACrC,MAAMC,gBAAgB,GAAGC,QAAQ,CAACD,gBAAgB,IAAIC,QAAQ,CAACC,IAAI;EAEnE,IAAKH,MAAM,EAAG;IACbF,iBAAiB,GAAGG,gBAAgB,CAACG,SAAS;EAC/C;EAEA,MAAMC,UAAU,GAAGL,MAAM,GAAG,KAAK,GAAG,QAAQ;EAC5CC,gBAAgB,CAACK,SAAS,CAAED,UAAU,CAAE,CAAE,YAAa,CAAC;;EAExD;EACAH,QAAQ,CAACK,eAAe,CAACD,SAAS,CAAED,UAAU,CAAE,CAAE,YAAa,CAAC;EAEhE,IAAK,CAAEL,MAAM,EAAG;IACfC,gBAAgB,CAACG,SAAS,GAAGN,iBAAiB;EAC/C;AACD;AAEA,IAAIU,WAAW,GAAG,CAAC;;AAEnB;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;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAAA,EAAS;EAClCZ,SAAS,CAAE,MAAM;IAChB,IAAKW,WAAW,KAAK,CAAC,EAAG;MACxBT,SAAS,CAAE,IAAK,CAAC;IAClB;IAEA,EAAES,WAAW;IAEb,OAAO,MAAM;MACZ,IAAKA,WAAW,KAAK,CAAC,EAAG;QACxBT,SAAS,CAAE,KAAM,CAAC;MACnB;MAEA,EAAES,WAAW;IACd,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,OAAO,IAAI;AACZ;AAEA,eAAeC,UAAU"}