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,146 @@
import { createElement } from "react";
/**
* External dependencies
*/
import { View, TouchableWithoutFeedback, Text, Platform, Animated, Easing } from 'react-native';
/**
* WordPress dependencies
*/
import { useState, useEffect } from '@wordpress/element';
import { usePreferredColorSchemeStyle } from '@wordpress/compose';
/**
* Internal dependencies
*/
import { performLayoutAnimation } from '../layout-animation';
import styles from './style.scss';
const ANIMATION_DURATION = 200;
const isIOS = Platform.OS === 'ios';
const Segment = ({
isSelected,
title,
onPress,
onLayout,
...props
}) => {
const isSelectedIOS = isIOS && isSelected;
const segmentStyle = [styles.segment, isIOS && styles.segmentIOS];
const textStyle = usePreferredColorSchemeStyle(styles.buttonTextDefault, styles.buttonTextDefaultDark);
const selectedTextStyle = usePreferredColorSchemeStyle(styles.buttonTextSelected, styles.buttonTextSelectedDark);
const shadowStyle = usePreferredColorSchemeStyle(styles.shadowIOS, {});
return createElement(View, {
style: isSelectedIOS && shadowStyle
}, createElement(TouchableWithoutFeedback, {
onPress: onPress
}, createElement(View, {
style: segmentStyle,
onLayout: onLayout,
...props
}, createElement(Text, {
style: [textStyle, isSelected && selectedTextStyle],
maxFontSizeMultiplier: 2
}, title))));
};
const SegmentedControls = ({
segments,
segmentHandler,
selectedIndex,
addonLeft,
addonRight
}) => {
const selectedSegmentIndex = selectedIndex || 0;
const [activeSegmentIndex, setActiveSegmentIndex] = useState(selectedSegmentIndex);
const [segmentsDimensions, setSegmentsDimensions] = useState({
[activeSegmentIndex]: {
width: 0,
height: 0
}
});
const [positionAnimationValue] = useState(new Animated.Value(0));
useEffect(() => {
setActiveSegmentIndex(selectedSegmentIndex);
segmentHandler(segments[selectedSegmentIndex]);
// Disable reason: deferring this refactor to the native team.
// see https://github.com/WordPress/gutenberg/pull/41166
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
positionAnimationValue.setValue(calculateEndValue(activeSegmentIndex));
// Disable reason: deferring this refactor to the native team.
// see https://github.com/WordPress/gutenberg/pull/41166
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [segmentsDimensions]);
const containerStyle = usePreferredColorSchemeStyle(styles.container, styles.containerDark);
function performSwatchAnimation(index) {
Animated.timing(positionAnimationValue, {
toValue: calculateEndValue(index),
duration: ANIMATION_DURATION,
easing: Easing.ease,
useNativeDriver: false
}).start();
}
function calculateEndValue(index) {
const {
paddingLeft: offset
} = isIOS ? styles.containerIOS : styles.container;
const widths = Object.values(segmentsDimensions).map(dimension => dimension.width);
const widthsDistance = widths.slice(0, index);
const widthsDistanceSum = widthsDistance.reduce((sum, n) => sum + n, 0);
const endValue = index === 0 ? 0 : widthsDistanceSum;
return endValue + offset;
}
function onHandlePress(segment, index) {
performLayoutAnimation(ANIMATION_DURATION);
setActiveSegmentIndex(index);
segmentHandler(segment);
performSwatchAnimation(index);
}
function segmentOnLayout(event, index) {
const {
width,
height
} = event.nativeEvent.layout;
setSegmentsDimensions({
...segmentsDimensions,
[index]: {
width,
height
}
});
}
const selectedStyle = usePreferredColorSchemeStyle(styles.selected, styles.selectedDark);
const width = segmentsDimensions[activeSegmentIndex]?.width;
const height = segmentsDimensions[activeSegmentIndex]?.height;
const outlineStyle = [styles.outline, isIOS && styles.outlineIOS];
return createElement(View, {
style: styles.row
}, createElement(View, {
style: styles.flex
}, addonLeft), createElement(View, {
style: [containerStyle, isIOS && styles.containerIOS]
}, createElement(Animated.View, {
style: [{
width,
left: positionAnimationValue,
height
}, selectedStyle, outlineStyle]
}), segments.map((segment, index) => {
return createElement(Segment, {
title: segment,
onPress: () => onHandlePress(segment, index),
isSelected: activeSegmentIndex === index,
key: index,
onLayout: event => segmentOnLayout(event, index),
accessibilityState: {
selected: activeSegmentIndex === index
},
accessibilityRole: 'button',
accessibilityLabel: segment,
accessibilityHint: `${index + 1} on ${segments.length}`
});
})), createElement(View, {
style: styles.flex
}, addonRight));
};
export default SegmentedControls;
//# sourceMappingURL=index.native.js.map

File diff suppressed because one or more lines are too long