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,294 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.RangeControl = void 0;
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _i18n = require("@wordpress/i18n");
var _element = require("@wordpress/element");
var _compose = require("@wordpress/compose");
var _baseControl = _interopRequireDefault(require("../base-control"));
var _button = _interopRequireDefault(require("../button"));
var _icon = _interopRequireDefault(require("../icon"));
var _utils = require("../utils");
var _utils2 = require("./utils");
var _math = require("../utils/math");
var _inputRange = _interopRequireDefault(require("./input-range"));
var _rail = _interopRequireDefault(require("./rail"));
var _tooltip = _interopRequireDefault(require("./tooltip"));
var _rangeControlStyles = require("./styles/range-control-styles");
var _space = require("../utils/space");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const noop = () => {};
function UnforwardedRangeControl(props, forwardedRef) {
const {
__nextHasNoMarginBottom = false,
afterIcon,
allowReset = false,
beforeIcon,
className,
color: colorProp = _utils.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] = (0, _utils2.useControlledRangeValue)({
min,
max,
value: valueProp !== null && valueProp !== void 0 ? valueProp : null,
initial: initialPosition
});
const isResetPendent = (0, _element.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] = (0, _element.useState)(hasTooltip);
const [isFocused, setIsFocused] = (0, _element.useState)(false);
const inputRef = (0, _element.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 = `${(0, _math.clamp)(fillValue, 0, 100)}%`;
const classes = (0, _classnames.default)('components-range-control', className);
const wrapperClasses = (0, _classnames.default)('components-range-control__wrapper', !!marks && 'is-marked');
const id = (0, _compose.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 = (0, _utils2.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 = {
[(0, _i18n.isRTL)() ? 'right' : 'left']: fillValueOffset
};
return (0, _react.createElement)(_baseControl.default, {
__nextHasNoMarginBottom: __nextHasNoMarginBottom,
className: classes,
label: label,
hideLabelFromVision: hideLabelFromVision,
id: `${id}`,
help: help
}, (0, _react.createElement)(_rangeControlStyles.Root, {
className: "components-range-control__root",
__next40pxDefaultSize: __next40pxDefaultSize
}, beforeIcon && (0, _react.createElement)(_rangeControlStyles.BeforeIconWrapper, null, (0, _react.createElement)(_icon.default, {
icon: beforeIcon
})), (0, _react.createElement)(_rangeControlStyles.Wrapper, {
__nextHasNoMarginBottom: __nextHasNoMarginBottom,
className: wrapperClasses,
color: colorProp,
marks: !!marks
}, (0, _react.createElement)(_inputRange.default, {
...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: (0, _compose.useMergeRefs)([inputRef, forwardedRef]),
step: step,
value: inputSliderValue !== null && inputSliderValue !== void 0 ? inputSliderValue : undefined
}), (0, _react.createElement)(_rail.default, {
"aria-hidden": true,
disabled: disabled,
marks: marks,
max: max,
min: min,
railColor: railColor,
step: step,
value: rangeFillValue
}), (0, _react.createElement)(_rangeControlStyles.Track, {
"aria-hidden": true,
className: "components-range-control__track",
disabled: disabled,
style: {
width: fillValueOffset
},
trackColor: trackColor
}), (0, _react.createElement)(_rangeControlStyles.ThumbWrapper, {
className: "components-range-control__thumb-wrapper",
style: offsetStyle,
disabled: disabled
}, (0, _react.createElement)(_rangeControlStyles.Thumb, {
"aria-hidden": true,
isFocused: isThumbFocused,
disabled: disabled
})), enableTooltip && (0, _react.createElement)(_tooltip.default, {
className: "components-range-control__tooltip",
inputRef: inputRef,
tooltipPosition: "bottom",
renderTooltipContent: renderTooltipContent,
show: isCurrentlyFocused || showTooltip,
style: offsetStyle,
value: value
})), afterIcon && (0, _react.createElement)(_rangeControlStyles.AfterIconWrapper, null, (0, _react.createElement)(_icon.default, {
icon: afterIcon
})), hasInputField && (0, _react.createElement)(_rangeControlStyles.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 ? (0, _space.space)(20) : (0, _space.space)(16),
step: step
// @ts-expect-error TODO: Investigate if the `null` value is necessary
,
value: inputSliderValue
}), allowReset && (0, _react.createElement)(_rangeControlStyles.ActionRightWrapper, null, (0, _react.createElement)(_button.default, {
className: "components-range-control__reset",
disabled: disabled || value === undefined,
variant: "secondary",
size: "small",
onClick: handleOnReset
}, (0, _i18n.__)('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={() => {}}
* />
* );
* };
* ```
*/
const RangeControl = (0, _element.forwardRef)(UnforwardedRangeControl);
exports.RangeControl = RangeControl;
var _default = RangeControl;
exports.default = _default;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,74 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _element = require("@wordpress/element");
var _rangeCell = _interopRequireDefault(require("../mobile/bottom-sheet/range-cell"));
var _stepperCell = _interopRequireDefault(require("../mobile/bottom-sheet/stepper-cell"));
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const RangeControl = (0, _element.memo)(({
className,
currentInput,
label,
value,
instanceId,
onChange,
beforeIcon,
afterIcon,
help,
allowReset,
initialPosition,
min,
max,
type,
separatorType,
disabled,
...props
}) => {
if (type === 'stepper') {
return (0, _react.createElement)(_stepperCell.default, {
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 (0, _react.createElement)(_rangeCell.default, {
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
});
});
var _default = RangeControl;
exports.default = _default;
//# sourceMappingURL=index.native.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["_element","require","_rangeCell","_interopRequireDefault","_stepperCell","RangeControl","memo","className","currentInput","label","value","instanceId","onChange","beforeIcon","afterIcon","help","allowReset","initialPosition","min","max","type","separatorType","disabled","props","_react","createElement","default","id","currentInputValue","initialSliderValue","isFinite","undefined","minimumValue","maximumValue","defaultValue","_default","exports"],"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":";;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAIA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,YAAA,GAAAD,sBAAA,CAAAF,OAAA;AARA;AACA;AACA;;AAEA;AACA;AACA;;AAIA,MAAMI,YAAY,GAAG,IAAAC,aAAI,EACxB,CAAE;EACDC,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,OACC,IAAAI,MAAA,CAAAC,aAAA,EAACrB,YAAA,CAAAsB,OAAW;MACXjB,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,MAAMK,EAAE,GAAI,2BAA2BhB,UAAY,EAAC;EACpD,MAAMiB,iBAAiB,GAAGpB,YAAY,KAAK,IAAI,GAAGE,KAAK,GAAGF,YAAY;EACtE,MAAMqB,kBAAkB,GAAGC,QAAQ,CAAEF,iBAAkB,CAAC,GACrDA,iBAAiB,GACjBX,eAAe;EAElB,OACC,IAAAO,MAAA,CAAAC,aAAA,EAACvB,UAAA,CAAAwB,OAAS;IACTjB,KAAK,EAAGA,KAAO;IACfkB,EAAE,EAAGA,EAAI;IACTZ,IAAI,EAAGA,IAAM;IACbR,SAAS,EAAGA,SAAW;IACvBK,QAAQ,EAAGA,QAAU;IACrB,oBAAmB,CAAC,CAAEG,IAAI,GAAI,GAAGY,EAAI,QAAO,GAAGI,SAAW;IAC1DC,YAAY,EAAGd,GAAK;IACpBe,YAAY,EAAGd,GAAK;IACpBT,KAAK,EAAGA,KAAO;IACfG,UAAU,EAAGA,UAAY;IACzBC,SAAS,EAAGA,SAAW;IACvBE,UAAU,EAAGA,UAAY;IACzBkB,YAAY,EAAGL,kBAAoB;IACnCR,aAAa,EAAGA,aAAe;IAC/BC,QAAQ,EAAGA,QAAU;IAAA,GAChBC;EAAK,CACV,CAAC;AAEJ,CACD,CAAC;AAAC,IAAAY,QAAA,GAEa9B,YAAY;AAAA+B,OAAA,CAAAV,OAAA,GAAAS,QAAA"}

View File

@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _element = require("@wordpress/element");
var _rangeControlStyles = require("./styles/range-control-styles");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
function InputRange(props, ref) {
const {
describedBy,
label,
value,
...otherProps
} = props;
return (0, _react.createElement)(_rangeControlStyles.InputRange, {
...otherProps,
"aria-describedby": describedBy,
"aria-label": label,
"aria-hidden": false,
ref: ref,
tabIndex: 0,
type: "range",
value: value
});
}
const ForwardedComponent = (0, _element.forwardRef)(InputRange);
var _default = ForwardedComponent;
exports.default = _default;
//# sourceMappingURL=input-range.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["_element","require","_rangeControlStyles","InputRange","props","ref","describedBy","label","value","otherProps","_react","createElement","tabIndex","type","ForwardedComponent","forwardRef","_default","exports","default"],"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":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,mBAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAMA,SAASE,UAAUA,CAClBC,KAA0D,EAC1DC,GAA2C,EAC1C;EACD,MAAM;IAAEC,WAAW;IAAEC,KAAK;IAAEC,KAAK;IAAE,GAAGC;EAAW,CAAC,GAAGL,KAAK;EAC1D,OACC,IAAAM,MAAA,CAAAC,aAAA,EAACT,mBAAA,CAAAC,UAAc;IAAA,GACTM,UAAU;IACf,oBAAmBH,WAAa;IAChC,cAAaC,KAAO;IACpB,eAAc,KAAO;IACrBF,GAAG,EAAGA,GAAK;IACXO,QAAQ,EAAG,CAAG;IACdC,IAAI,EAAC,OAAO;IACZL,KAAK,EAAGA;EAAO,CACf,CAAC;AAEJ;AAEA,MAAMM,kBAAkB,GAAG,IAAAC,mBAAU,EAAEZ,UAAW,CAAC;AAAC,IAAAa,QAAA,GAErCF,kBAAkB;AAAAG,OAAA,CAAAC,OAAA,GAAAF,QAAA"}

View File

@@ -0,0 +1,42 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = RangeMark;
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _rangeControlStyles = require("./styles/range-control-styles");
/**
* External dependencies
*/
/**
* Internal dependencies
*/
function RangeMark(props) {
const {
className,
isFilled = false,
label,
style = {},
...otherProps
} = props;
const classes = (0, _classnames.default)('components-range-control__mark', isFilled && 'is-filled', className);
const labelClasses = (0, _classnames.default)('components-range-control__mark-label', isFilled && 'is-filled');
return (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_rangeControlStyles.Mark, {
...otherProps,
"aria-hidden": "true",
className: classes,
isFilled: isFilled,
style: style
}), label && (0, _react.createElement)(_rangeControlStyles.MarkLabel, {
"aria-hidden": "true",
className: labelClasses,
isFilled: isFilled,
style: style
}, label));
}
//# sourceMappingURL=mark.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["_classnames","_interopRequireDefault","require","_rangeControlStyles","RangeMark","props","className","isFilled","label","style","otherProps","classes","classnames","labelClasses","_react","createElement","Fragment","Mark","MarkLabel"],"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":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,mBAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAMe,SAASE,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,GAAG,IAAAC,mBAAU,EACzB,gCAAgC,EAChCL,QAAQ,IAAI,WAAW,EACvBD,SACD,CAAC;EACD,MAAMO,YAAY,GAAG,IAAAD,mBAAU,EAC9B,sCAAsC,EACtCL,QAAQ,IAAI,WACb,CAAC;EAED,OACC,IAAAO,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA,QACC,IAAAF,MAAA,CAAAC,aAAA,EAACZ,mBAAA,CAAAc,IAAI;IAAA,GACCP,UAAU;IACf,eAAY,MAAM;IAClBJ,SAAS,EAAGK,OAAS;IACrBJ,QAAQ,EAAGA,QAAU;IACrBE,KAAK,EAAGA;EAAO,CACf,CAAC,EACAD,KAAK,IACN,IAAAM,MAAA,CAAAC,aAAA,EAACZ,mBAAA,CAAAe,SAAS;IACT,eAAY,MAAM;IAClBZ,SAAS,EAAGO,YAAc;IAC1BN,QAAQ,EAAGA,QAAU;IACrBE,KAAK,EAAGA;EAAO,GAEbD,KACQ,CAEX,CAAC;AAEL"}

View File

@@ -0,0 +1,107 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = RangeRail;
var _react = require("react");
var _i18n = require("@wordpress/i18n");
var _mark = _interopRequireDefault(require("./mark"));
var _rangeControlStyles = require("./styles/range-control-styles");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
function RangeRail(props) {
const {
disabled = false,
marks = false,
min = 0,
max = 100,
step = 1,
value = 0,
...restProps
} = props;
return (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_rangeControlStyles.Rail, {
disabled: disabled,
...restProps
}), marks && (0, _react.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 (0, _react.createElement)(_rangeControlStyles.MarksWrapper, {
"aria-hidden": "true",
className: "components-range-control__marks"
}, marksData.map(mark => (0, _react.createElement)(_mark.default, {
...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 = {
[(0, _i18n.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,76 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = SimpleTooltip;
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _element = require("@wordpress/element");
var _rangeControlStyles = require("./styles/range-control-styles");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
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 = (0, _classnames.default)('components-simple-tooltip', className);
const styles = {
...style,
zIndex
};
return (0, _react.createElement)(_rangeControlStyles.Tooltip, {
...restProps,
"aria-hidden": show,
className: classes,
position: position,
show: show,
role: "tooltip",
style: styles
}, renderTooltipContent(value));
}
function useTooltipPosition({
inputRef,
tooltipPosition
}) {
const [position, setPosition] = (0, _element.useState)();
const setTooltipPosition = (0, _element.useCallback)(() => {
if (inputRef && inputRef.current) {
setPosition(tooltipPosition);
}
}, [tooltipPosition, inputRef]);
(0, _element.useEffect)(() => {
setTooltipPosition();
}, [setTooltipPosition]);
(0, _element.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","_interopRequireDefault","require","_element","_rangeControlStyles","SimpleTooltip","props","className","inputRef","tooltipPosition","show","style","value","renderTooltipContent","v","zIndex","restProps","position","useTooltipPosition","classes","classnames","styles","_react","createElement","Tooltip","role","setPosition","useState","setTooltipPosition","useCallback","current","useEffect","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":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,mBAAA,GAAAF,OAAA;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAMe,SAASG,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,GAAG,IAAAC,mBAAU,EAAE,2BAA2B,EAAEb,SAAU,CAAC;EACpE,MAAMc,MAAM,GAAG;IACd,GAAGV,KAAK;IACRI;EACD,CAAC;EAED,OACC,IAAAO,MAAA,CAAAC,aAAA,EAACnB,mBAAA,CAAAoB,OAAO;IAAA,GACFR,SAAS;IACd,eAAcN,IAAM;IACpBH,SAAS,EAAGY,OAAS;IACrBF,QAAQ,EAAGA,QAAU;IACrBP,IAAI,EAAGA,IAAM;IACbe,IAAI,EAAC,SAAS;IACdd,KAAK,EAAGU;EAAQ,GAEdR,oBAAoB,CAAED,KAAM,CACtB,CAAC;AAEZ;AAEA,SAASM,kBAAkBA,CAAE;EAAEV,QAAQ;EAAEC;AAA8B,CAAC,EAAG;EAC1E,MAAM,CAAEQ,QAAQ,EAAES,WAAW,CAAE,GAAG,IAAAC,iBAAQ,EAAW,CAAC;EAEtD,MAAMC,kBAAkB,GAAG,IAAAC,oBAAW,EAAE,MAAM;IAC7C,IAAKrB,QAAQ,IAAIA,QAAQ,CAACsB,OAAO,EAAG;MACnCJ,WAAW,CAAEjB,eAAgB,CAAC;IAC/B;EACD,CAAC,EAAE,CAAEA,eAAe,EAAED,QAAQ,CAAG,CAAC;EAElC,IAAAuB,kBAAS,EAAE,MAAM;IAChBH,kBAAkB,CAAC,CAAC;EACrB,CAAC,EAAE,CAAEA,kBAAkB,CAAG,CAAC;EAE3B,IAAAG,kBAAS,EAAE,MAAM;IAChBC,MAAM,CAACC,gBAAgB,CAAE,QAAQ,EAAEL,kBAAmB,CAAC;IAEvD,OAAO,MAAM;MACZI,MAAM,CAACE,mBAAmB,CAAE,QAAQ,EAAEN,kBAAmB,CAAC;IAC3D,CAAC;EACF,CAAE,CAAC;EAEH,OAAOX,QAAQ;AAChB"}

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=types.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,64 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.floatClamp = floatClamp;
exports.useControlledRangeValue = useControlledRangeValue;
var _element = require("@wordpress/element");
var _hooks = require("../utils/hooks");
var _math = require("../utils/math");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* 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
*/
function floatClamp(value, min, max) {
if (typeof value !== 'number') {
return null;
}
return parseFloat(`${(0, _math.clamp)(value, min, max)}`);
}
/**
* Hook to store a clamped value, derived from props.
*
* @param settings
* @return The controlled value and the value setter.
*/
function useControlledRangeValue(settings) {
const {
min,
max,
value: valueProp,
initial
} = settings;
const [state, setInternalState] = (0, _hooks.useControlledState)(floatClamp(valueProp, min, max), {
initial: floatClamp(initial !== null && initial !== void 0 ? initial : null, min, max),
fallback: null
});
const setState = (0, _element.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":["_element","require","_hooks","_math","floatClamp","value","min","max","parseFloat","clamp","useControlledRangeValue","settings","valueProp","initial","state","setInternalState","useControlledState","fallback","setState","useCallback","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":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,UAAUA,CAAEC,KAAoB,EAAEC,GAAW,EAAEC,GAAW,EAAG;EAC5E,IAAK,OAAOF,KAAK,KAAK,QAAQ,EAAG;IAChC,OAAO,IAAI;EACZ;EAEA,OAAOG,UAAU,CAAG,GAAG,IAAAC,WAAK,EAAEJ,KAAK,EAAEC,GAAG,EAAEC,GAAI,CAAG,EAAE,CAAC;AACrD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,uBAAuBA,CACtCC,QAAqC,EACpC;EACD,MAAM;IAAEL,GAAG;IAAEC,GAAG;IAAEF,KAAK,EAAEO,SAAS;IAAEC;EAAQ,CAAC,GAAGF,QAAQ;EACxD,MAAM,CAAEG,KAAK,EAAEC,gBAAgB,CAAE,GAAG,IAAAC,yBAAkB,EACrDZ,UAAU,CAAEQ,SAAS,EAAEN,GAAG,EAAEC,GAAI,CAAC,EACjC;IACCM,OAAO,EAAET,UAAU,CAAES,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAI,IAAI,EAAEP,GAAG,EAAEC,GAAI,CAAC;IAChDU,QAAQ,EAAE;EACX,CACD,CAAC;EAED,MAAMC,QAAQ,GAAG,IAAAC,oBAAW,EACzBC,SAAwB,IAAM;IAC/B,IAAKA,SAAS,KAAK,IAAI,EAAG;MACzBL,gBAAgB,CAAE,IAAK,CAAC;IACzB,CAAC,MAAM;MACNA,gBAAgB,CAAEX,UAAU,CAAEgB,SAAS,EAAEd,GAAG,EAAEC,GAAI,CAAE,CAAC;IACtD;EACD,CAAC,EACD,CAAED,GAAG,EAAEC,GAAG,EAAEQ,gBAAgB,CAC7B,CAAC;;EAED;EACA;EACA,OAAO,CAAED,KAAK,EAAiCI,QAAQ,CAAE;AAC1D"}