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>
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
import * as babelModuleImports from '@babel/helper-module-imports';
|
|
import * as t from '@babel/types';
|
|
import * as plugin from 'aslemammad-vite-plugin-macro';
|
|
import * as babelMacro from 'babel-plugin-macros';
|
|
|
|
const { defineMacro, defineMacroProvider, createMacroPlugin } = "default" in plugin ? plugin.default : plugin;
|
|
const valtioMacro = defineMacro(`useProxy`).withSignature(`<T extends object>(proxyObject: T): void`).withHandler((ctx) => {
|
|
var _a, _b, _c, _d;
|
|
const { path, args } = ctx;
|
|
const hook = babelModuleImports.addNamed(path, "useSnapshot", "valtio");
|
|
const proxy = (_a = args[0]) == null ? void 0 : _a.node;
|
|
if (!t.isIdentifier(proxy)) {
|
|
throw new babelMacro.MacroError("no proxy object");
|
|
}
|
|
const snap = t.identifier(`valtio_macro_snap_${proxy.name}`);
|
|
(_b = path.parentPath) == null ? void 0 : _b.replaceWith(
|
|
t.variableDeclaration("const", [
|
|
t.variableDeclarator(snap, t.callExpression(hook, [proxy]))
|
|
])
|
|
);
|
|
let inFunction = 0;
|
|
(_d = (_c = path.parentPath) == null ? void 0 : _c.getFunctionParent()) == null ? void 0 : _d.traverse({
|
|
Identifier(p) {
|
|
if (inFunction === 0 && p.node !== proxy && p.node.name === proxy.name) {
|
|
p.node.name = snap.name;
|
|
}
|
|
},
|
|
Function: {
|
|
enter() {
|
|
++inFunction;
|
|
},
|
|
exit() {
|
|
--inFunction;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
function provideValtioMacro() {
|
|
return defineMacroProvider({
|
|
id: "valtio/macro",
|
|
exports: {
|
|
"valtio/macro": {
|
|
macros: [valtioMacro]
|
|
}
|
|
}
|
|
});
|
|
}
|
|
const macroPlugin = createMacroPlugin({}).use(provideValtioMacro());
|
|
|
|
export { macroPlugin as default, provideValtioMacro, valtioMacro };
|