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
1.4 KiB
JavaScript
72 lines
1.4 KiB
JavaScript
const { hasOwnProperty } = Object.prototype;
|
|
|
|
function buildMap(list, caseInsensitive) {
|
|
const map = Object.create(null);
|
|
|
|
if (!Array.isArray(list)) {
|
|
return null;
|
|
}
|
|
|
|
for (let name of list) {
|
|
if (caseInsensitive) {
|
|
name = name.toLowerCase();
|
|
}
|
|
|
|
map[name] = true;
|
|
}
|
|
|
|
return map;
|
|
}
|
|
|
|
function buildList(data) {
|
|
if (!data) {
|
|
return null;
|
|
}
|
|
|
|
const tags = buildMap(data.tags, true);
|
|
const ids = buildMap(data.ids);
|
|
const classes = buildMap(data.classes);
|
|
|
|
if (tags === null &&
|
|
ids === null &&
|
|
classes === null) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
tags,
|
|
ids,
|
|
classes
|
|
};
|
|
}
|
|
|
|
export function buildIndex(data) {
|
|
let scopes = false;
|
|
|
|
if (data.scopes && Array.isArray(data.scopes)) {
|
|
scopes = Object.create(null);
|
|
|
|
for (let i = 0; i < data.scopes.length; i++) {
|
|
const list = data.scopes[i];
|
|
|
|
if (!list || !Array.isArray(list)) {
|
|
throw new Error('Wrong usage format');
|
|
}
|
|
|
|
for (const name of list) {
|
|
if (hasOwnProperty.call(scopes, name)) {
|
|
throw new Error(`Class can't be used for several scopes: ${name}`);
|
|
}
|
|
|
|
scopes[name] = i + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
whitelist: buildList(data),
|
|
blacklist: buildList(data.blacklist),
|
|
scopes
|
|
};
|
|
}
|