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,283 @@
import { createElement } from "react";
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { __, isRTL } from '@wordpress/i18n';
import { useRef, useState, forwardRef } from '@wordpress/element';
import { useInstanceId, useMergeRefs } from '@wordpress/compose';
/**
* Internal dependencies
*/
import BaseControl from '../base-control';
import Button from '../button';
import Icon from '../icon';
import { COLORS } from '../utils';
import { floatClamp, useControlledRangeValue } from './utils';
import { clamp } from '../utils/math';
import InputRange from './input-range';
import RangeRail from './rail';
import SimpleTooltip from './tooltip';
import { ActionRightWrapper, AfterIconWrapper, BeforeIconWrapper, InputNumber, Root, Track, ThumbWrapper, Thumb, Wrapper } from './styles/range-control-styles';
import { space } from '../utils/space';
const noop = () => {};
function UnforwardedRangeControl(props, forwardedRef) {
const {
__nextHasNoMarginBottom = false,
afterIcon,
allowReset = false,
beforeIcon,
className,
color: colorProp = COLORS.theme.accent,
currentInput,
disabled = false,
help,
hideLabelFromVision = false,
initialPosition,
isShiftStepEnabled = true,
label,
marks = false,
max = 100,
min = 0,
onBlur = noop,
onChange = noop,
onFocus = noop,
onMouseLeave = noop,
onMouseMove = noop,
railColor,
renderTooltipContent = v => v,
resetFallbackValue,
__next40pxDefaultSize = false,
shiftStep = 10,
showTooltip: showTooltipProp,
step = 1,
trackColor,
value: valueProp,
withInputField = true,
...otherProps
} = props;
const [value, setValue] = useControlledRangeValue({
min,
max,
value: valueProp !== null && valueProp !== void 0 ? valueProp : null,
initial: initialPosition
});
const isResetPendent = useRef(false);
let hasTooltip = showTooltipProp;
let hasInputField = withInputField;
if (step === 'any') {
// The tooltip and number input field are hidden when the step is "any"
// because the decimals get too lengthy to fit well.
hasTooltip = false;
hasInputField = false;
}
const [showTooltip, setShowTooltip] = useState(hasTooltip);
const [isFocused, setIsFocused] = useState(false);
const inputRef = useRef();
const isCurrentlyFocused = inputRef.current?.matches(':focus');
const isThumbFocused = !disabled && isFocused;
const isValueReset = value === null;
const currentValue = value !== undefined ? value : currentInput;
const inputSliderValue = isValueReset ? '' : currentValue;
const rangeFillValue = isValueReset ? (max - min) / 2 + min : value;
const fillValue = isValueReset ? 50 : (value - min) / (max - min) * 100;
const fillValueOffset = `${clamp(fillValue, 0, 100)}%`;
const classes = classnames('components-range-control', className);
const wrapperClasses = classnames('components-range-control__wrapper', !!marks && 'is-marked');
const id = useInstanceId(UnforwardedRangeControl, 'inspector-range-control');
const describedBy = !!help ? `${id}__help` : undefined;
const enableTooltip = hasTooltip !== false && Number.isFinite(value);
const handleOnRangeChange = event => {
const nextValue = parseFloat(event.target.value);
setValue(nextValue);
onChange(nextValue);
};
const handleOnChange = next => {
// @ts-expect-error TODO: Investigate if it's problematic for setValue() to
// potentially receive a NaN when next is undefined.
let nextValue = parseFloat(next);
setValue(nextValue);
/*
* Calls onChange only when nextValue is numeric
* otherwise may queue a reset for the blur event.
*/
if (!isNaN(nextValue)) {
if (nextValue < min || nextValue > max) {
nextValue = floatClamp(nextValue, min, max);
}
onChange(nextValue);
isResetPendent.current = false;
} else if (allowReset) {
isResetPendent.current = true;
}
};
const handleOnInputNumberBlur = () => {
if (isResetPendent.current) {
handleOnReset();
isResetPendent.current = false;
}
};
const handleOnReset = () => {
let resetValue = parseFloat(`${resetFallbackValue}`);
let onChangeResetValue = resetValue;
if (isNaN(resetValue)) {
resetValue = null;
onChangeResetValue = undefined;
}
setValue(resetValue);
/**
* Previously, this callback would always receive undefined as
* an argument. This behavior is unexpected, specifically
* when resetFallbackValue is defined.
*
* The value of undefined is not ideal. Passing it through
* to internal <input /> elements would change it from a
* controlled component to an uncontrolled component.
*
* For now, to minimize unexpected regressions, we're going to
* preserve the undefined callback argument, except when a
* resetFallbackValue is defined.
*/
onChange(onChangeResetValue);
};
const handleShowTooltip = () => setShowTooltip(true);
const handleHideTooltip = () => setShowTooltip(false);
const handleOnBlur = event => {
onBlur(event);
setIsFocused(false);
handleHideTooltip();
};
const handleOnFocus = event => {
onFocus(event);
setIsFocused(true);
handleShowTooltip();
};
const offsetStyle = {
[isRTL() ? 'right' : 'left']: fillValueOffset
};
return createElement(BaseControl, {
__nextHasNoMarginBottom: __nextHasNoMarginBottom,
className: classes,
label: label,
hideLabelFromVision: hideLabelFromVision,
id: `${id}`,
help: help
}, createElement(Root, {
className: "components-range-control__root",
__next40pxDefaultSize: __next40pxDefaultSize
}, beforeIcon && createElement(BeforeIconWrapper, null, createElement(Icon, {
icon: beforeIcon
})), createElement(Wrapper, {
__nextHasNoMarginBottom: __nextHasNoMarginBottom,
className: wrapperClasses,
color: colorProp,
marks: !!marks
}, createElement(InputRange, {
...otherProps,
className: "components-range-control__slider",
describedBy: describedBy,
disabled: disabled,
id: `${id}`,
label: label,
max: max,
min: min,
onBlur: handleOnBlur,
onChange: handleOnRangeChange,
onFocus: handleOnFocus,
onMouseMove: onMouseMove,
onMouseLeave: onMouseLeave,
ref: useMergeRefs([inputRef, forwardedRef]),
step: step,
value: inputSliderValue !== null && inputSliderValue !== void 0 ? inputSliderValue : undefined
}), createElement(RangeRail, {
"aria-hidden": true,
disabled: disabled,
marks: marks,
max: max,
min: min,
railColor: railColor,
step: step,
value: rangeFillValue
}), createElement(Track, {
"aria-hidden": true,
className: "components-range-control__track",
disabled: disabled,
style: {
width: fillValueOffset
},
trackColor: trackColor
}), createElement(ThumbWrapper, {
className: "components-range-control__thumb-wrapper",
style: offsetStyle,
disabled: disabled
}, createElement(Thumb, {
"aria-hidden": true,
isFocused: isThumbFocused,
disabled: disabled
})), enableTooltip && createElement(SimpleTooltip, {
className: "components-range-control__tooltip",
inputRef: inputRef,
tooltipPosition: "bottom",
renderTooltipContent: renderTooltipContent,
show: isCurrentlyFocused || showTooltip,
style: offsetStyle,
value: value
})), afterIcon && createElement(AfterIconWrapper, null, createElement(Icon, {
icon: afterIcon
})), hasInputField && createElement(InputNumber, {
"aria-label": label,
className: "components-range-control__number",
disabled: disabled,
inputMode: "decimal",
isShiftStepEnabled: isShiftStepEnabled,
max: max,
min: min,
onBlur: handleOnInputNumberBlur,
onChange: handleOnChange,
shiftStep: shiftStep,
size: __next40pxDefaultSize ? '__unstable-large' : 'default',
__unstableInputWidth: __next40pxDefaultSize ? space(20) : space(16),
step: step
// @ts-expect-error TODO: Investigate if the `null` value is necessary
,
value: inputSliderValue
}), allowReset && createElement(ActionRightWrapper, null, createElement(Button, {
className: "components-range-control__reset",
disabled: disabled || value === undefined,
variant: "secondary",
size: "small",
onClick: handleOnReset
}, __('Reset')))));
}
/**
* RangeControls are used to make selections from a range of incremental values.
*
* ```jsx
* import { RangeControl } from '@wordpress/components';
* import { useState } from '@wordpress/element';
*
* const MyRangeControl = () => {
* const [ isChecked, setChecked ] = useState( true );
* return (
* <RangeControl
* help="Please select how transparent you would like this."
* initialPosition={50}
* label="Opacity"
* max={100}
* min={0}
* onChange={() => {}}
* />
* );
* };
* ```
*/
export const RangeControl = forwardRef(UnforwardedRangeControl);
export default RangeControl;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,64 @@
import { createElement } from "react";
/**
* WordPress dependencies
*/
import { memo } from '@wordpress/element';
/**
* Internal dependencies
*/
import RangeCell from '../mobile/bottom-sheet/range-cell';
import StepperCell from '../mobile/bottom-sheet/stepper-cell';
const RangeControl = memo(({
className,
currentInput,
label,
value,
instanceId,
onChange,
beforeIcon,
afterIcon,
help,
allowReset,
initialPosition,
min,
max,
type,
separatorType,
disabled,
...props
}) => {
if (type === 'stepper') {
return createElement(StepperCell, {
label: label,
max: max,
min: min,
onChange: onChange,
separatorType: separatorType,
value: value,
disabled: disabled
});
}
const id = `inspector-range-control-${instanceId}`;
const currentInputValue = currentInput === null ? value : currentInput;
const initialSliderValue = isFinite(currentInputValue) ? currentInputValue : initialPosition;
return createElement(RangeCell, {
label: label,
id: id,
help: help,
className: className,
onChange: onChange,
"aria-describedby": !!help ? `${id}__help` : undefined,
minimumValue: min,
maximumValue: max,
value: value,
beforeIcon: beforeIcon,
afterIcon: afterIcon,
allowReset: allowReset,
defaultValue: initialSliderValue,
separatorType: separatorType,
disabled: disabled,
...props
});
});
export default RangeControl;
//# sourceMappingURL=index.native.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["memo","RangeCell","StepperCell","RangeControl","className","currentInput","label","value","instanceId","onChange","beforeIcon","afterIcon","help","allowReset","initialPosition","min","max","type","separatorType","disabled","props","createElement","id","currentInputValue","initialSliderValue","isFinite","undefined","minimumValue","maximumValue","defaultValue"],"sources":["@wordpress/components/src/range-control/index.native.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { memo } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport RangeCell from '../mobile/bottom-sheet/range-cell';\nimport StepperCell from '../mobile/bottom-sheet/stepper-cell';\n\nconst RangeControl = memo(\n\t( {\n\t\tclassName,\n\t\tcurrentInput,\n\t\tlabel,\n\t\tvalue,\n\t\tinstanceId,\n\t\tonChange,\n\t\tbeforeIcon,\n\t\tafterIcon,\n\t\thelp,\n\t\tallowReset,\n\t\tinitialPosition,\n\t\tmin,\n\t\tmax,\n\t\ttype,\n\t\tseparatorType,\n\t\tdisabled,\n\t\t...props\n\t} ) => {\n\t\tif ( type === 'stepper' ) {\n\t\t\treturn (\n\t\t\t\t<StepperCell\n\t\t\t\t\tlabel={ label }\n\t\t\t\t\tmax={ max }\n\t\t\t\t\tmin={ min }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tseparatorType={ separatorType }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t\tconst id = `inspector-range-control-${ instanceId }`;\n\t\tconst currentInputValue = currentInput === null ? value : currentInput;\n\t\tconst initialSliderValue = isFinite( currentInputValue )\n\t\t\t? currentInputValue\n\t\t\t: initialPosition;\n\n\t\treturn (\n\t\t\t<RangeCell\n\t\t\t\tlabel={ label }\n\t\t\t\tid={ id }\n\t\t\t\thelp={ help }\n\t\t\t\tclassName={ className }\n\t\t\t\tonChange={ onChange }\n\t\t\t\taria-describedby={ !! help ? `${ id }__help` : undefined }\n\t\t\t\tminimumValue={ min }\n\t\t\t\tmaximumValue={ max }\n\t\t\t\tvalue={ value }\n\t\t\t\tbeforeIcon={ beforeIcon }\n\t\t\t\tafterIcon={ afterIcon }\n\t\t\t\tallowReset={ allowReset }\n\t\t\t\tdefaultValue={ initialSliderValue }\n\t\t\t\tseparatorType={ separatorType }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\t{ ...props }\n\t\t\t/>\n\t\t);\n\t}\n);\n\nexport default RangeControl;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,IAAI,QAAQ,oBAAoB;AACzC;AACA;AACA;AACA,OAAOC,SAAS,MAAM,mCAAmC;AACzD,OAAOC,WAAW,MAAM,qCAAqC;AAE7D,MAAMC,YAAY,GAAGH,IAAI,CACxB,CAAE;EACDI,SAAS;EACTC,YAAY;EACZC,KAAK;EACLC,KAAK;EACLC,UAAU;EACVC,QAAQ;EACRC,UAAU;EACVC,SAAS;EACTC,IAAI;EACJC,UAAU;EACVC,eAAe;EACfC,GAAG;EACHC,GAAG;EACHC,IAAI;EACJC,aAAa;EACbC,QAAQ;EACR,GAAGC;AACJ,CAAC,KAAM;EACN,IAAKH,IAAI,KAAK,SAAS,EAAG;IACzB,OACCI,aAAA,CAACnB,WAAW;MACXI,KAAK,EAAGA,KAAO;MACfU,GAAG,EAAGA,GAAK;MACXD,GAAG,EAAGA,GAAK;MACXN,QAAQ,EAAGA,QAAU;MACrBS,aAAa,EAAGA,aAAe;MAC/BX,KAAK,EAAGA,KAAO;MACfY,QAAQ,EAAGA;IAAU,CACrB,CAAC;EAEJ;EACA,MAAMG,EAAE,GAAI,2BAA2Bd,UAAY,EAAC;EACpD,MAAMe,iBAAiB,GAAGlB,YAAY,KAAK,IAAI,GAAGE,KAAK,GAAGF,YAAY;EACtE,MAAMmB,kBAAkB,GAAGC,QAAQ,CAAEF,iBAAkB,CAAC,GACrDA,iBAAiB,GACjBT,eAAe;EAElB,OACCO,aAAA,CAACpB,SAAS;IACTK,KAAK,EAAGA,KAAO;IACfgB,EAAE,EAAGA,EAAI;IACTV,IAAI,EAAGA,IAAM;IACbR,SAAS,EAAGA,SAAW;IACvBK,QAAQ,EAAGA,QAAU;IACrB,oBAAmB,CAAC,CAAEG,IAAI,GAAI,GAAGU,EAAI,QAAO,GAAGI,SAAW;IAC1DC,YAAY,EAAGZ,GAAK;IACpBa,YAAY,EAAGZ,GAAK;IACpBT,KAAK,EAAGA,KAAO;IACfG,UAAU,EAAGA,UAAY;IACzBC,SAAS,EAAGA,SAAW;IACvBE,UAAU,EAAGA,UAAY;IACzBgB,YAAY,EAAGL,kBAAoB;IACnCN,aAAa,EAAGA,aAAe;IAC/BC,QAAQ,EAAGA,QAAU;IAAA,GAChBC;EAAK,CACV,CAAC;AAEJ,CACD,CAAC;AAED,eAAejB,YAAY"}

View File

@@ -0,0 +1,31 @@
import { createElement } from "react";
/**
* WordPress dependencies
*/
import { forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import { InputRange as BaseInputRange } from './styles/range-control-styles';
function InputRange(props, ref) {
const {
describedBy,
label,
value,
...otherProps
} = props;
return createElement(BaseInputRange, {
...otherProps,
"aria-describedby": describedBy,
"aria-label": label,
"aria-hidden": false,
ref: ref,
tabIndex: 0,
type: "range",
value: value
});
}
const ForwardedComponent = forwardRef(InputRange);
export default ForwardedComponent;
//# sourceMappingURL=input-range.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["forwardRef","InputRange","BaseInputRange","props","ref","describedBy","label","value","otherProps","createElement","tabIndex","type","ForwardedComponent"],"sources":["@wordpress/components/src/range-control/input-range.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { InputRange as BaseInputRange } from './styles/range-control-styles';\n\nimport type { InputRangeProps } from './types';\nimport type { WordPressComponentProps } from '../context';\n\nfunction InputRange(\n\tprops: WordPressComponentProps< InputRangeProps, 'input' >,\n\tref: React.ForwardedRef< HTMLInputElement >\n) {\n\tconst { describedBy, label, value, ...otherProps } = props;\n\treturn (\n\t\t<BaseInputRange\n\t\t\t{ ...otherProps }\n\t\t\taria-describedby={ describedBy }\n\t\t\taria-label={ label }\n\t\t\taria-hidden={ false }\n\t\t\tref={ ref }\n\t\t\ttabIndex={ 0 }\n\t\t\ttype=\"range\"\n\t\t\tvalue={ value }\n\t\t/>\n\t);\n}\n\nconst ForwardedComponent = forwardRef( InputRange );\n\nexport default ForwardedComponent;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,oBAAoB;;AAE/C;AACA;AACA;AACA,SAASC,UAAU,IAAIC,cAAc,QAAQ,+BAA+B;AAK5E,SAASD,UAAUA,CAClBE,KAA0D,EAC1DC,GAA2C,EAC1C;EACD,MAAM;IAAEC,WAAW;IAAEC,KAAK;IAAEC,KAAK;IAAE,GAAGC;EAAW,CAAC,GAAGL,KAAK;EAC1D,OACCM,aAAA,CAACP,cAAc;IAAA,GACTM,UAAU;IACf,oBAAmBH,WAAa;IAChC,cAAaC,KAAO;IACpB,eAAc,KAAO;IACrBF,GAAG,EAAGA,GAAK;IACXM,QAAQ,EAAG,CAAG;IACdC,IAAI,EAAC,OAAO;IACZJ,KAAK,EAAGA;EAAO,CACf,CAAC;AAEJ;AAEA,MAAMK,kBAAkB,GAAGZ,UAAU,CAAEC,UAAW,CAAC;AAEnD,eAAeW,kBAAkB"}

View File

@@ -0,0 +1,34 @@
import { createElement, Fragment } from "react";
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* Internal dependencies
*/
import { Mark, MarkLabel } from './styles/range-control-styles';
export default function RangeMark(props) {
const {
className,
isFilled = false,
label,
style = {},
...otherProps
} = props;
const classes = classnames('components-range-control__mark', isFilled && 'is-filled', className);
const labelClasses = classnames('components-range-control__mark-label', isFilled && 'is-filled');
return createElement(Fragment, null, createElement(Mark, {
...otherProps,
"aria-hidden": "true",
className: classes,
isFilled: isFilled,
style: style
}), label && createElement(MarkLabel, {
"aria-hidden": "true",
className: labelClasses,
isFilled: isFilled,
style: style
}, label));
}
//# sourceMappingURL=mark.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["classnames","Mark","MarkLabel","RangeMark","props","className","isFilled","label","style","otherProps","classes","labelClasses","createElement","Fragment"],"sources":["@wordpress/components/src/range-control/mark.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * Internal dependencies\n */\nimport { Mark, MarkLabel } from './styles/range-control-styles';\n\nimport type { RangeMarkProps } from './types';\nimport type { WordPressComponentProps } from '../context';\n\nexport default function RangeMark(\n\tprops: WordPressComponentProps< RangeMarkProps, 'span' >\n) {\n\tconst {\n\t\tclassName,\n\t\tisFilled = false,\n\t\tlabel,\n\t\tstyle = {},\n\t\t...otherProps\n\t} = props;\n\n\tconst classes = classnames(\n\t\t'components-range-control__mark',\n\t\tisFilled && 'is-filled',\n\t\tclassName\n\t);\n\tconst labelClasses = classnames(\n\t\t'components-range-control__mark-label',\n\t\tisFilled && 'is-filled'\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<Mark\n\t\t\t\t{ ...otherProps }\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tclassName={ classes }\n\t\t\t\tisFilled={ isFilled }\n\t\t\t\tstyle={ style }\n\t\t\t/>\n\t\t\t{ label && (\n\t\t\t\t<MarkLabel\n\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\tclassName={ labelClasses }\n\t\t\t\t\tisFilled={ isFilled }\n\t\t\t\t\tstyle={ style }\n\t\t\t\t>\n\t\t\t\t\t{ label }\n\t\t\t\t</MarkLabel>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,IAAI,EAAEC,SAAS,QAAQ,+BAA+B;AAK/D,eAAe,SAASC,SAASA,CAChCC,KAAwD,EACvD;EACD,MAAM;IACLC,SAAS;IACTC,QAAQ,GAAG,KAAK;IAChBC,KAAK;IACLC,KAAK,GAAG,CAAC,CAAC;IACV,GAAGC;EACJ,CAAC,GAAGL,KAAK;EAET,MAAMM,OAAO,GAAGV,UAAU,CACzB,gCAAgC,EAChCM,QAAQ,IAAI,WAAW,EACvBD,SACD,CAAC;EACD,MAAMM,YAAY,GAAGX,UAAU,CAC9B,sCAAsC,EACtCM,QAAQ,IAAI,WACb,CAAC;EAED,OACCM,aAAA,CAAAC,QAAA,QACCD,aAAA,CAACX,IAAI;IAAA,GACCQ,UAAU;IACf,eAAY,MAAM;IAClBJ,SAAS,EAAGK,OAAS;IACrBJ,QAAQ,EAAGA,QAAU;IACrBE,KAAK,EAAGA;EAAO,CACf,CAAC,EACAD,KAAK,IACNK,aAAA,CAACV,SAAS;IACT,eAAY,MAAM;IAClBG,SAAS,EAAGM,YAAc;IAC1BL,QAAQ,EAAGA,QAAU;IACrBE,KAAK,EAAGA;EAAO,GAEbD,KACQ,CAEX,CAAC;AAEL"}

View File

@@ -0,0 +1,99 @@
import { createElement, Fragment } from "react";
/**
* WordPress dependencies
*/
import { isRTL } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import RangeMark from './mark';
import { MarksWrapper, Rail } from './styles/range-control-styles';
export default function RangeRail(props) {
const {
disabled = false,
marks = false,
min = 0,
max = 100,
step = 1,
value = 0,
...restProps
} = props;
return createElement(Fragment, null, createElement(Rail, {
disabled: disabled,
...restProps
}), marks && createElement(Marks, {
disabled: disabled,
marks: marks,
min: min,
max: max,
step: step,
value: value
}));
}
function Marks(props) {
const {
disabled = false,
marks = false,
min = 0,
max = 100,
step: stepProp = 1,
value = 0
} = props;
const step = stepProp === 'any' ? 1 : stepProp;
const marksData = useMarks({
marks,
min,
max,
step,
value
});
return createElement(MarksWrapper, {
"aria-hidden": "true",
className: "components-range-control__marks"
}, marksData.map(mark => createElement(RangeMark, {
...mark,
key: mark.key,
"aria-hidden": "true",
disabled: disabled
})));
}
function useMarks({
marks,
min = 0,
max = 100,
step = 1,
value = 0
}) {
if (!marks) {
return [];
}
const range = max - min;
if (!Array.isArray(marks)) {
marks = [];
const count = 1 + Math.round(range / step);
while (count > marks.push({
value: step * marks.length + min
}));
}
const placedMarks = [];
marks.forEach((mark, index) => {
if (mark.value < min || mark.value > max) {
return;
}
const key = `mark-${index}`;
const isFilled = mark.value <= value;
const offset = `${(mark.value - min) / range * 100}%`;
const offsetStyle = {
[isRTL() ? 'right' : 'left']: offset
};
placedMarks.push({
...mark,
isFilled,
key,
style: offsetStyle
});
});
return placedMarks;
}
//# sourceMappingURL=rail.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,68 @@
import { createElement } from "react";
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useCallback, useEffect, useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import { Tooltip } from './styles/range-control-styles';
export default function SimpleTooltip(props) {
const {
className,
inputRef,
tooltipPosition,
show = false,
style = {},
value = 0,
renderTooltipContent = v => v,
zIndex = 100,
...restProps
} = props;
const position = useTooltipPosition({
inputRef,
tooltipPosition
});
const classes = classnames('components-simple-tooltip', className);
const styles = {
...style,
zIndex
};
return createElement(Tooltip, {
...restProps,
"aria-hidden": show,
className: classes,
position: position,
show: show,
role: "tooltip",
style: styles
}, renderTooltipContent(value));
}
function useTooltipPosition({
inputRef,
tooltipPosition
}) {
const [position, setPosition] = useState();
const setTooltipPosition = useCallback(() => {
if (inputRef && inputRef.current) {
setPosition(tooltipPosition);
}
}, [tooltipPosition, inputRef]);
useEffect(() => {
setTooltipPosition();
}, [setTooltipPosition]);
useEffect(() => {
window.addEventListener('resize', setTooltipPosition);
return () => {
window.removeEventListener('resize', setTooltipPosition);
};
});
return position;
}
//# sourceMappingURL=tooltip.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["classnames","useCallback","useEffect","useState","Tooltip","SimpleTooltip","props","className","inputRef","tooltipPosition","show","style","value","renderTooltipContent","v","zIndex","restProps","position","useTooltipPosition","classes","styles","createElement","role","setPosition","setTooltipPosition","current","window","addEventListener","removeEventListener"],"sources":["@wordpress/components/src/range-control/tooltip.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Tooltip } from './styles/range-control-styles';\n\nimport type { TooltipProps } from './types';\nimport type { WordPressComponentProps } from '../context';\n\nexport default function SimpleTooltip(\n\tprops: WordPressComponentProps< TooltipProps, 'span' >\n) {\n\tconst {\n\t\tclassName,\n\t\tinputRef,\n\t\ttooltipPosition,\n\t\tshow = false,\n\t\tstyle = {},\n\t\tvalue = 0,\n\t\trenderTooltipContent = ( v ) => v,\n\t\tzIndex = 100,\n\t\t...restProps\n\t} = props;\n\tconst position = useTooltipPosition( { inputRef, tooltipPosition } );\n\tconst classes = classnames( 'components-simple-tooltip', className );\n\tconst styles = {\n\t\t...style,\n\t\tzIndex,\n\t};\n\n\treturn (\n\t\t<Tooltip\n\t\t\t{ ...restProps }\n\t\t\taria-hidden={ show }\n\t\t\tclassName={ classes }\n\t\t\tposition={ position }\n\t\t\tshow={ show }\n\t\t\trole=\"tooltip\"\n\t\t\tstyle={ styles }\n\t\t>\n\t\t\t{ renderTooltipContent( value ) }\n\t\t</Tooltip>\n\t);\n}\n\nfunction useTooltipPosition( { inputRef, tooltipPosition }: TooltipProps ) {\n\tconst [ position, setPosition ] = useState< string >();\n\n\tconst setTooltipPosition = useCallback( () => {\n\t\tif ( inputRef && inputRef.current ) {\n\t\t\tsetPosition( tooltipPosition );\n\t\t}\n\t}, [ tooltipPosition, inputRef ] );\n\n\tuseEffect( () => {\n\t\tsetTooltipPosition();\n\t}, [ setTooltipPosition ] );\n\n\tuseEffect( () => {\n\t\twindow.addEventListener( 'resize', setTooltipPosition );\n\n\t\treturn () => {\n\t\t\twindow.removeEventListener( 'resize', setTooltipPosition );\n\t\t};\n\t} );\n\n\treturn position;\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,oBAAoB;;AAErE;AACA;AACA;AACA,SAASC,OAAO,QAAQ,+BAA+B;AAKvD,eAAe,SAASC,aAAaA,CACpCC,KAAsD,EACrD;EACD,MAAM;IACLC,SAAS;IACTC,QAAQ;IACRC,eAAe;IACfC,IAAI,GAAG,KAAK;IACZC,KAAK,GAAG,CAAC,CAAC;IACVC,KAAK,GAAG,CAAC;IACTC,oBAAoB,GAAKC,CAAC,IAAMA,CAAC;IACjCC,MAAM,GAAG,GAAG;IACZ,GAAGC;EACJ,CAAC,GAAGV,KAAK;EACT,MAAMW,QAAQ,GAAGC,kBAAkB,CAAE;IAAEV,QAAQ;IAAEC;EAAgB,CAAE,CAAC;EACpE,MAAMU,OAAO,GAAGnB,UAAU,CAAE,2BAA2B,EAAEO,SAAU,CAAC;EACpE,MAAMa,MAAM,GAAG;IACd,GAAGT,KAAK;IACRI;EACD,CAAC;EAED,OACCM,aAAA,CAACjB,OAAO;IAAA,GACFY,SAAS;IACd,eAAcN,IAAM;IACpBH,SAAS,EAAGY,OAAS;IACrBF,QAAQ,EAAGA,QAAU;IACrBP,IAAI,EAAGA,IAAM;IACbY,IAAI,EAAC,SAAS;IACdX,KAAK,EAAGS;EAAQ,GAEdP,oBAAoB,CAAED,KAAM,CACtB,CAAC;AAEZ;AAEA,SAASM,kBAAkBA,CAAE;EAAEV,QAAQ;EAAEC;AAA8B,CAAC,EAAG;EAC1E,MAAM,CAAEQ,QAAQ,EAAEM,WAAW,CAAE,GAAGpB,QAAQ,CAAW,CAAC;EAEtD,MAAMqB,kBAAkB,GAAGvB,WAAW,CAAE,MAAM;IAC7C,IAAKO,QAAQ,IAAIA,QAAQ,CAACiB,OAAO,EAAG;MACnCF,WAAW,CAAEd,eAAgB,CAAC;IAC/B;EACD,CAAC,EAAE,CAAEA,eAAe,EAAED,QAAQ,CAAG,CAAC;EAElCN,SAAS,CAAE,MAAM;IAChBsB,kBAAkB,CAAC,CAAC;EACrB,CAAC,EAAE,CAAEA,kBAAkB,CAAG,CAAC;EAE3BtB,SAAS,CAAE,MAAM;IAChBwB,MAAM,CAACC,gBAAgB,CAAE,QAAQ,EAAEH,kBAAmB,CAAC;IAEvD,OAAO,MAAM;MACZE,MAAM,CAACE,mBAAmB,CAAE,QAAQ,EAAEJ,kBAAmB,CAAC;IAC3D,CAAC;EACF,CAAE,CAAC;EAEH,OAAOP,QAAQ;AAChB"}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=types.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,56 @@
/**
* WordPress dependencies
*/
import { useCallback } from '@wordpress/element';
/**
* Internal dependencies
*/
import { useControlledState } from '../utils/hooks';
import { clamp } from '../utils/math';
/**
* A float supported clamp function for a specific value.
*
* @param value The value to clamp.
* @param min The minimum value.
* @param max The maximum value.
*
* @return A (float) number
*/
export function floatClamp(value, min, max) {
if (typeof value !== 'number') {
return null;
}
return parseFloat(`${clamp(value, min, max)}`);
}
/**
* Hook to store a clamped value, derived from props.
*
* @param settings
* @return The controlled value and the value setter.
*/
export function useControlledRangeValue(settings) {
const {
min,
max,
value: valueProp,
initial
} = settings;
const [state, setInternalState] = useControlledState(floatClamp(valueProp, min, max), {
initial: floatClamp(initial !== null && initial !== void 0 ? initial : null, min, max),
fallback: null
});
const setState = useCallback(nextValue => {
if (nextValue === null) {
setInternalState(null);
} else {
setInternalState(floatClamp(nextValue, min, max));
}
}, [min, max, setInternalState]);
// `state` can't be an empty string because we specified a fallback value of
// `null` in `useControlledState`
return [state, setState];
}
//# sourceMappingURL=utils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["useCallback","useControlledState","clamp","floatClamp","value","min","max","parseFloat","useControlledRangeValue","settings","valueProp","initial","state","setInternalState","fallback","setState","nextValue"],"sources":["@wordpress/components/src/range-control/utils.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useControlledState } from '../utils/hooks';\nimport { clamp } from '../utils/math';\n\nimport type { UseControlledRangeValueArgs } from './types';\n\n/**\n * A float supported clamp function for a specific value.\n *\n * @param value The value to clamp.\n * @param min The minimum value.\n * @param max The maximum value.\n *\n * @return A (float) number\n */\nexport function floatClamp( value: number | null, min: number, max: number ) {\n\tif ( typeof value !== 'number' ) {\n\t\treturn null;\n\t}\n\n\treturn parseFloat( `${ clamp( value, min, max ) }` );\n}\n\n/**\n * Hook to store a clamped value, derived from props.\n *\n * @param settings\n * @return The controlled value and the value setter.\n */\nexport function useControlledRangeValue(\n\tsettings: UseControlledRangeValueArgs\n) {\n\tconst { min, max, value: valueProp, initial } = settings;\n\tconst [ state, setInternalState ] = useControlledState(\n\t\tfloatClamp( valueProp, min, max ),\n\t\t{\n\t\t\tinitial: floatClamp( initial ?? null, min, max ),\n\t\t\tfallback: null,\n\t\t}\n\t);\n\n\tconst setState = useCallback(\n\t\t( nextValue: number | null ) => {\n\t\t\tif ( nextValue === null ) {\n\t\t\t\tsetInternalState( null );\n\t\t\t} else {\n\t\t\t\tsetInternalState( floatClamp( nextValue, min, max ) );\n\t\t\t}\n\t\t},\n\t\t[ min, max, setInternalState ]\n\t);\n\n\t// `state` can't be an empty string because we specified a fallback value of\n\t// `null` in `useControlledState`\n\treturn [ state as Exclude< typeof state, '' >, setState ] as const;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,oBAAoB;;AAEhD;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,KAAK,QAAQ,eAAe;AAIrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAAEC,KAAoB,EAAEC,GAAW,EAAEC,GAAW,EAAG;EAC5E,IAAK,OAAOF,KAAK,KAAK,QAAQ,EAAG;IAChC,OAAO,IAAI;EACZ;EAEA,OAAOG,UAAU,CAAG,GAAGL,KAAK,CAAEE,KAAK,EAAEC,GAAG,EAAEC,GAAI,CAAG,EAAE,CAAC;AACrD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,uBAAuBA,CACtCC,QAAqC,EACpC;EACD,MAAM;IAAEJ,GAAG;IAAEC,GAAG;IAAEF,KAAK,EAAEM,SAAS;IAAEC;EAAQ,CAAC,GAAGF,QAAQ;EACxD,MAAM,CAAEG,KAAK,EAAEC,gBAAgB,CAAE,GAAGZ,kBAAkB,CACrDE,UAAU,CAAEO,SAAS,EAAEL,GAAG,EAAEC,GAAI,CAAC,EACjC;IACCK,OAAO,EAAER,UAAU,CAAEQ,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAI,IAAI,EAAEN,GAAG,EAAEC,GAAI,CAAC;IAChDQ,QAAQ,EAAE;EACX,CACD,CAAC;EAED,MAAMC,QAAQ,GAAGf,WAAW,CACzBgB,SAAwB,IAAM;IAC/B,IAAKA,SAAS,KAAK,IAAI,EAAG;MACzBH,gBAAgB,CAAE,IAAK,CAAC;IACzB,CAAC,MAAM;MACNA,gBAAgB,CAAEV,UAAU,CAAEa,SAAS,EAAEX,GAAG,EAAEC,GAAI,CAAE,CAAC;IACtD;EACD,CAAC,EACD,CAAED,GAAG,EAAEC,GAAG,EAAEO,gBAAgB,CAC7B,CAAC;;EAED;EACA;EACA,OAAO,CAAED,KAAK,EAAiCG,QAAQ,CAAE;AAC1D"}