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>
59 lines
1.1 KiB
JavaScript
59 lines
1.1 KiB
JavaScript
/** @typedef {import('./types').RichTextFormat} RichTextFormat */
|
|
|
|
/**
|
|
* Optimised equality check for format objects.
|
|
*
|
|
* @param {?RichTextFormat} format1 Format to compare.
|
|
* @param {?RichTextFormat} format2 Format to compare.
|
|
*
|
|
* @return {boolean} True if formats are equal, false if not.
|
|
*/
|
|
export function isFormatEqual( format1, format2 ) {
|
|
// Both not defined.
|
|
if ( format1 === format2 ) {
|
|
return true;
|
|
}
|
|
|
|
// Either not defined.
|
|
if ( ! format1 || ! format2 ) {
|
|
return false;
|
|
}
|
|
|
|
if ( format1.type !== format2.type ) {
|
|
return false;
|
|
}
|
|
|
|
const attributes1 = format1.attributes;
|
|
const attributes2 = format2.attributes;
|
|
|
|
// Both not defined.
|
|
if ( attributes1 === attributes2 ) {
|
|
return true;
|
|
}
|
|
|
|
// Either not defined.
|
|
if ( ! attributes1 || ! attributes2 ) {
|
|
return false;
|
|
}
|
|
|
|
const keys1 = Object.keys( attributes1 );
|
|
const keys2 = Object.keys( attributes2 );
|
|
|
|
if ( keys1.length !== keys2.length ) {
|
|
return false;
|
|
}
|
|
|
|
const length = keys1.length;
|
|
|
|
// Optimise for speed.
|
|
for ( let i = 0; i < length; i++ ) {
|
|
const name = keys1[ i ];
|
|
|
|
if ( attributes1[ name ] !== attributes2[ name ] ) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|