@wordpress/components 32.2.2-next.v.202602200903.0 → 32.3.1-next.v.202602241322.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/build/color-picker/color-input.cjs +11 -8
  3. package/build/color-picker/color-input.cjs.map +2 -2
  4. package/build/color-picker/component.cjs +47 -3
  5. package/build/color-picker/component.cjs.map +2 -2
  6. package/build/color-picker/hsl-input.cjs +7 -28
  7. package/build/color-picker/hsl-input.cjs.map +2 -2
  8. package/build/color-picker/picker.cjs +29 -20
  9. package/build/color-picker/picker.cjs.map +2 -2
  10. package/build/number-control/index.cjs +2 -5
  11. package/build/number-control/index.cjs.map +2 -2
  12. package/build/toggle-group-control/toggle-group-control-option-base/styles.cjs +8 -8
  13. package/build/toggle-group-control/toggle-group-control-option-base/styles.cjs.map +2 -2
  14. package/build-module/color-picker/color-input.mjs +11 -8
  15. package/build-module/color-picker/color-input.mjs.map +2 -2
  16. package/build-module/color-picker/component.mjs +48 -4
  17. package/build-module/color-picker/component.mjs.map +2 -2
  18. package/build-module/color-picker/hsl-input.mjs +7 -28
  19. package/build-module/color-picker/hsl-input.mjs.map +2 -2
  20. package/build-module/color-picker/picker.mjs +30 -21
  21. package/build-module/color-picker/picker.mjs.map +2 -2
  22. package/build-module/number-control/index.mjs +2 -5
  23. package/build-module/number-control/index.mjs.map +2 -2
  24. package/build-module/toggle-group-control/toggle-group-control-option-base/styles.mjs +8 -8
  25. package/build-module/toggle-group-control/toggle-group-control-option-base/styles.mjs.map +2 -2
  26. package/build-types/color-picker/color-input.d.ts +1 -1
  27. package/build-types/color-picker/color-input.d.ts.map +1 -1
  28. package/build-types/color-picker/component.d.ts.map +1 -1
  29. package/build-types/color-picker/hsl-input.d.ts +1 -1
  30. package/build-types/color-picker/hsl-input.d.ts.map +1 -1
  31. package/build-types/color-picker/picker.d.ts +1 -1
  32. package/build-types/color-picker/picker.d.ts.map +1 -1
  33. package/build-types/color-picker/types.d.ts +6 -4
  34. package/build-types/color-picker/types.d.ts.map +1 -1
  35. package/build-types/number-control/index.d.ts.map +1 -1
  36. package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts.map +1 -1
  37. package/package.json +21 -21
  38. package/src/color-picker/color-input.tsx +23 -4
  39. package/src/color-picker/component.tsx +88 -4
  40. package/src/color-picker/hsl-input.tsx +9 -51
  41. package/src/color-picker/picker.tsx +28 -24
  42. package/src/color-picker/test/index.tsx +139 -6
  43. package/src/color-picker/types.ts +6 -4
  44. package/src/number-control/index.tsx +73 -77
  45. package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +18 -16
  46. package/src/toggle-group-control/toggle-group-control-option-base/styles.ts +4 -6
package/CHANGELOG.md CHANGED
@@ -2,11 +2,21 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- ## 32.2.1-next.0 (2026-02-20)
5
+ ## 32.3.0-next.0 (2026-02-24)
6
6
 
7
7
  ### Bug Fixes
8
8
 
9
+ - `ColorPicker`: Preserve hue and saturation when the selected color becomes achromatic ([#75493](https://github.com/WordPress/gutenberg/pull/75493)).
9
10
  - `SnackbarList`: Fix scaling distortion when a snackbar's content is updated in place via a shared notice ID ([#75709](https://github.com/WordPress/gutenberg/pull/75709)).
11
+ - `ToggleGroupControl`: Fix hover styles on disabled items ([#75737](https://github.com/WordPress/gutenberg/pull/75737)).
12
+
13
+ ### Enhancements
14
+
15
+ - `ToggleGroupControl`: Make unselected item color consistent across all variants ([#75737](https://github.com/WordPress/gutenberg/pull/75737)).
16
+
17
+ ### Internal
18
+
19
+ - `NumberControl`: Improved code and types for state reducer ([#75822](https://github.com/WordPress/gutenberg/pull/75822)).
10
20
 
11
21
  ## 32.2.0 (2026-02-18)
12
22
 
@@ -30,27 +30,30 @@ var import_jsx_runtime = require("react/jsx-runtime");
30
30
  var ColorInput = ({
31
31
  colorType,
32
32
  color,
33
+ hsla,
33
34
  onChange,
35
+ onHSLChange,
34
36
  enableAlpha
35
37
  }) => {
36
- const props = {
37
- color,
38
- onChange,
39
- enableAlpha
40
- };
41
38
  switch (colorType) {
42
39
  case "hsl":
43
40
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_hsl_input.HslInput, {
44
- ...props
41
+ hsla,
42
+ onChange: onHSLChange,
43
+ enableAlpha
45
44
  });
46
45
  case "rgb":
47
46
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_rgb_input.RgbInput, {
48
- ...props
47
+ color,
48
+ onChange,
49
+ enableAlpha
49
50
  });
50
51
  default:
51
52
  case "hex":
52
53
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_hex_input.HexInput, {
53
- ...props
54
+ color,
55
+ onChange,
56
+ enableAlpha
54
57
  });
55
58
  }
56
59
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/color-picker/color-input.tsx"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { RgbInput } from './rgb-input';\nimport { HslInput } from './hsl-input';\nimport { HexInput } from './hex-input';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nexport const ColorInput = ({\n colorType,\n color,\n onChange,\n enableAlpha\n}) => {\n const props = {\n color,\n onChange,\n enableAlpha\n };\n switch (colorType) {\n case 'hsl':\n return /*#__PURE__*/_jsx(HslInput, {\n ...props\n });\n case 'rgb':\n return /*#__PURE__*/_jsx(RgbInput, {\n ...props\n });\n default:\n case 'hex':\n return /*#__PURE__*/_jsx(HexInput, {\n ...props\n });\n }\n};"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAyB;AACzB,uBAAyB;AACzB,uBAAyB;AACzB,yBAA4B;AACrB,IAAM,aAAa,CAAC;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,UAAQ,WAAW;AAAA,IACjB,KAAK;AACH,aAAoB,uCAAAA,KAAK,2BAAU;AAAA,QACjC,GAAG;AAAA,MACL,CAAC;AAAA,IACH,KAAK;AACH,aAAoB,uCAAAA,KAAK,2BAAU;AAAA,QACjC,GAAG;AAAA,MACL,CAAC;AAAA,IACH;AAAA,IACA,KAAK;AACH,aAAoB,uCAAAA,KAAK,2BAAU;AAAA,QACjC,GAAG;AAAA,MACL,CAAC;AAAA,EACL;AACF;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { RgbInput } from './rgb-input';\nimport { HslInput } from './hsl-input';\nimport { HexInput } from './hex-input';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nexport const ColorInput = ({\n colorType,\n color,\n hsla,\n onChange,\n onHSLChange,\n enableAlpha\n}) => {\n switch (colorType) {\n case 'hsl':\n return /*#__PURE__*/_jsx(HslInput, {\n hsla: hsla,\n onChange: onHSLChange,\n enableAlpha: enableAlpha\n });\n case 'rgb':\n return /*#__PURE__*/_jsx(RgbInput, {\n color: color,\n onChange: onChange,\n enableAlpha: enableAlpha\n });\n default:\n case 'hex':\n return /*#__PURE__*/_jsx(HexInput, {\n color: color,\n onChange: onChange,\n enableAlpha: enableAlpha\n });\n }\n};"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAyB;AACzB,uBAAyB;AACzB,uBAAyB;AACzB,yBAA4B;AACrB,IAAM,aAAa,CAAC;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,UAAQ,WAAW;AAAA,IACjB,KAAK;AACH,aAAoB,uCAAAA,KAAK,2BAAU;AAAA,QACjC;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MACF,CAAC;AAAA,IACH,KAAK;AACH,aAAoB,uCAAAA,KAAK,2BAAU;AAAA,QACjC;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA,KAAK;AACH,aAAoB,uCAAAA,KAAK,2BAAU;AAAA,QACjC;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,EACL;AACF;",
6
6
  "names": ["_jsx"]
7
7
  }
@@ -47,6 +47,22 @@ var import_picker = require("./picker.cjs");
47
47
  var import_hooks = require("../utils/hooks/index.cjs");
48
48
  var import_jsx_runtime = require("react/jsx-runtime");
49
49
  (0, import_colord.extend)([import_names.default]);
50
+ function mergeHSLA(nextHSLA, prevHSLA) {
51
+ if (nextHSLA.s === 0) {
52
+ if (nextHSLA.l === 0 || nextHSLA.l === 100) {
53
+ return {
54
+ ...nextHSLA,
55
+ h: prevHSLA.h,
56
+ s: prevHSLA.s
57
+ };
58
+ }
59
+ return {
60
+ ...nextHSLA,
61
+ h: prevHSLA.h
62
+ };
63
+ }
64
+ return nextHSLA;
65
+ }
50
66
  var options = [{
51
67
  label: "RGB",
52
68
  value: "rgb"
@@ -75,8 +91,34 @@ var UnconnectedColorPicker = (props, forwardedRef) => {
75
91
  return (0, import_colord.colord)(color || "");
76
92
  }, [color]);
77
93
  const debouncedSetColor = (0, import_compose.useDebounce)(setColor);
94
+ const [internalHSLA, setInternalHSLA] = (0, import_element.useState)(() => ({
95
+ ...safeColordColor.toHsl()
96
+ }));
97
+ const lastProducedHexRef = (0, import_element.useRef)(safeColordColor.toHex());
98
+ (0, import_element.useEffect)(() => {
99
+ const incomingHex = safeColordColor.toHex();
100
+ if (incomingHex === lastProducedHexRef.current) {
101
+ return;
102
+ }
103
+ lastProducedHexRef.current = incomingHex;
104
+ const externalHSLA = safeColordColor.toHsl();
105
+ setInternalHSLA((prev) => mergeHSLA(externalHSLA, prev));
106
+ }, [safeColordColor]);
107
+ const handleHSLAChange = (0, import_element.useCallback)((nextHSLA) => {
108
+ setInternalHSLA(nextHSLA);
109
+ const previousHex = lastProducedHexRef.current;
110
+ const nextHex = (0, import_colord.colord)(nextHSLA).toHex();
111
+ if (nextHex !== previousHex) {
112
+ lastProducedHexRef.current = nextHex;
113
+ setColor(nextHex);
114
+ }
115
+ }, [setColor]);
78
116
  const handleChange = (0, import_element.useCallback)((nextValue) => {
79
- debouncedSetColor(nextValue.toHex());
117
+ const nextHSLA = nextValue.toHsl();
118
+ setInternalHSLA((prev) => mergeHSLA(nextHSLA, prev));
119
+ const nextHex = nextValue.toHex();
120
+ lastProducedHexRef.current = nextHex;
121
+ debouncedSetColor(nextHex);
80
122
  }, [debouncedSetColor]);
81
123
  const [colorType, setColorType] = (0, import_element.useState)(copyFormat || "hex");
82
124
  const maybeHandlePaste = (0, import_element.useCallback)((event) => {
@@ -107,8 +149,8 @@ var UnconnectedColorPicker = (props, forwardedRef) => {
107
149
  ...divProps,
108
150
  onPasteCapture: maybeHandlePaste,
109
151
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_picker.Picker, {
110
- onChange: handleChange,
111
- color: safeColordColor,
152
+ onChange: handleHSLAChange,
153
+ hsla: internalHSLA,
112
154
  enableAlpha
113
155
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_styles.AuxiliaryColorArtefactWrapper, {
114
156
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_styles.AuxiliaryColorArtefactHStackHeader, {
@@ -131,7 +173,9 @@ var UnconnectedColorPicker = (props, forwardedRef) => {
131
173
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_color_input.ColorInput, {
132
174
  colorType,
133
175
  color: safeColordColor,
176
+ hsla: internalHSLA,
134
177
  onChange: handleChange,
178
+ onHSLChange: handleHSLAChange,
135
179
  enableAlpha
136
180
  })
137
181
  })]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/color-picker/component.tsx"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\n\nimport { colord, extend, getFormat } from 'colord';\nimport namesPlugin from 'colord/plugins/names';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useState, useMemo } from '@wordpress/element';\nimport { useDebounce } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useContextSystem, contextConnect } from '../context';\nimport { ColorfulWrapper, SelectControl, AuxiliaryColorArtefactWrapper, AuxiliaryColorArtefactHStackHeader, ColorInputWrapper } from './styles';\nimport { ColorCopyButton } from './color-copy-button';\nimport { ColorInput } from './color-input';\nimport { Picker } from './picker';\nimport { useControlledValue } from '../utils/hooks';\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nextend([namesPlugin]);\nconst options = [{\n label: 'RGB',\n value: 'rgb'\n}, {\n label: 'HSL',\n value: 'hsl'\n}, {\n label: 'Hex',\n value: 'hex'\n}];\nconst UnconnectedColorPicker = (props, forwardedRef) => {\n const {\n enableAlpha = false,\n color: colorProp,\n onChange,\n defaultValue = '#fff',\n copyFormat,\n ...divProps\n } = useContextSystem(props, 'ColorPicker');\n\n // Use a safe default value for the color and remove the possibility of `undefined`.\n const [color, setColor] = useControlledValue({\n onChange,\n value: colorProp,\n defaultValue\n });\n const safeColordColor = useMemo(() => {\n return colord(color || '');\n }, [color]);\n const debouncedSetColor = useDebounce(setColor);\n const handleChange = useCallback(nextValue => {\n debouncedSetColor(nextValue.toHex());\n }, [debouncedSetColor]);\n const [colorType, setColorType] = useState(copyFormat || 'hex');\n\n /*\n * ! Listener intended for the CAPTURE phase\n *\n * Capture paste events over the entire color picker, looking for clipboard\n * data that could be parsed as a color. If not, let the paste event\n * propagate normally, so that individual input controls within the\n * component have a chance to handle it.\n */\n const maybeHandlePaste = useCallback(event => {\n const pastedText = event.clipboardData?.getData('text')?.trim();\n if (!pastedText) {\n return;\n }\n const parsedColor = colord(pastedText);\n if (!parsedColor.isValid()) {\n return;\n }\n\n // Apply all valid colors, even if the format isn't supported in\n // the UI (e.g. names like \"cyan\" or, in the future color spaces\n // like \"lch\" if we add the right colord plugins)\n handleChange(parsedColor);\n\n // This redundancy helps TypeScript and is safer than assertions\n const supportedFormats = {\n hex: 'hex',\n rgb: 'rgb',\n hsl: 'hsl'\n };\n const detectedFormat = String(getFormat(pastedText));\n const newColorType = supportedFormats[detectedFormat];\n if (newColorType) {\n setColorType(newColorType);\n }\n\n // Stop at capture phase; no bubbling\n event.stopPropagation();\n event.preventDefault();\n }, [handleChange, setColorType]);\n return /*#__PURE__*/_jsxs(ColorfulWrapper, {\n ref: forwardedRef,\n ...divProps,\n onPasteCapture: maybeHandlePaste,\n children: [/*#__PURE__*/_jsx(Picker, {\n onChange: handleChange,\n color: safeColordColor,\n enableAlpha: enableAlpha\n }), /*#__PURE__*/_jsxs(AuxiliaryColorArtefactWrapper, {\n children: [/*#__PURE__*/_jsxs(AuxiliaryColorArtefactHStackHeader, {\n justify: \"space-between\",\n children: [/*#__PURE__*/_jsx(SelectControl, {\n size: \"compact\",\n options: options,\n value: colorType,\n onChange: nextColorType => setColorType(nextColorType),\n label: __('Color format'),\n hideLabelFromVision: true,\n variant: \"minimal\"\n }), /*#__PURE__*/_jsx(ColorCopyButton, {\n color: safeColordColor,\n colorType: copyFormat || colorType\n })]\n }), /*#__PURE__*/_jsx(ColorInputWrapper, {\n direction: \"column\",\n gap: 2,\n children: /*#__PURE__*/_jsx(ColorInput, {\n colorType: colorType,\n color: safeColordColor,\n onChange: handleChange,\n enableAlpha: enableAlpha\n })\n })]\n })]\n });\n};\nexport const ColorPicker = contextConnect(UnconnectedColorPicker, 'ColorPicker');\nexport default ColorPicker;"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAA0C;AAC1C,mBAAwB;AAKxB,qBAA+C;AAC/C,qBAA4B;AAC5B,kBAAmB;AAKnB,qBAAiD;AACjD,oBAAqI;AACrI,+BAAgC;AAChC,yBAA2B;AAC3B,oBAAuB;AACvB,mBAAmC;AACnC,yBAA2C;AAAA,IAC3C,sBAAO,CAAC,aAAAA,OAAW,CAA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AA,EACvB,GAAG,CAAC,cAAc,YAAY,CAAC;AAC/B,SAAoB,uCAAAC,MAAM,+BAAiB;AAAA,IACzC,KAAK;AAAA,IACL,GAAG;AAAA,IACH,gBAAgB;AAAA,IAChB,UAAU,CAAc,uCAAAC,KAAK,sBAAQ;AAAA,MACnC,UAAU;AAAA,MACV,OAAO;AAAA,MACP;AAAA,IACF,CAAC,GAAgB,uCAAAD,MAAM,6CAA+B;AAAA,MACpD,UAAU,CAAc,uCAAAA,MAAM,kDAAoC;AAAA,QAChE,SAAS;AAAA,QACT,UAAU,CAAc,uCAAAC,KAAK,6BAAe;AAAA,UAC1C,MAAM;AAAA,UACN;AAAA,UACA,OAAO;AAAA,UACP,UAAU,mBAAiB,aAAa,aAAa;AAAA,UACrD,WAAO,gBAAG,cAAc;AAAA,UACxB,qBAAqB;AAAA,UACrB,SAAS;AAAA,QACX,CAAC,GAAgB,uCAAAA,KAAK,0CAAiB;AAAA,UACrC,OAAO;AAAA,UACP,WAAW,cAAc;AAAA,QAC3B,CAAC,CAAC;AAAA,MACJ,CAAC,GAAgB,uCAAAA,KAAK,iCAAmB;AAAA,QACvC,WAAW;AAAA,QACX,KAAK;AAAA,QACL,UAAuB,uCAAAA,KAAK,+BAAY;AAAA,UACtC;AAAA,UACA,OAAO;AAAA,UACP,UAAU;AAAA,UACV;AAAA,QACF,CAAC;AAAA,MACH,CAAC,CAAC;AAAA,IACJ,CAAC,CAAC;AAAA,EACJ,CAAC;AACH;AACO,IAAM,kBAAc,+BAAe,wBAAwB,aAAa;AAC/E,IAAO,oBAAQ;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\n\nimport { colord, extend, getFormat } from 'colord';\nimport namesPlugin from 'colord/plugins/names';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState, useMemo } from '@wordpress/element';\nimport { useDebounce } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useContextSystem, contextConnect } from '../context';\nimport { ColorfulWrapper, SelectControl, AuxiliaryColorArtefactWrapper, AuxiliaryColorArtefactHStackHeader, ColorInputWrapper } from './styles';\nimport { ColorCopyButton } from './color-copy-button';\nimport { ColorInput } from './color-input';\nimport { Picker } from './picker';\nimport { useControlledValue } from '../utils/hooks';\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nextend([namesPlugin]);\n\n/**\n * Merges incoming HSLA with previous state, preserving hue for achromatic\n * colors and saturation only at lightness extremes (black/white) where\n * it has no visual effect.\n */\nfunction mergeHSLA(nextHSLA, prevHSLA) {\n if (nextHSLA.s === 0) {\n if (nextHSLA.l === 0 || nextHSLA.l === 100) {\n return {\n ...nextHSLA,\n h: prevHSLA.h,\n s: prevHSLA.s\n };\n }\n return {\n ...nextHSLA,\n h: prevHSLA.h\n };\n }\n return nextHSLA;\n}\nconst options = [{\n label: 'RGB',\n value: 'rgb'\n}, {\n label: 'HSL',\n value: 'hsl'\n}, {\n label: 'Hex',\n value: 'hex'\n}];\nconst UnconnectedColorPicker = (props, forwardedRef) => {\n const {\n enableAlpha = false,\n color: colorProp,\n onChange,\n defaultValue = '#fff',\n copyFormat,\n ...divProps\n } = useContextSystem(props, 'ColorPicker');\n\n // Use a safe default value for the color and remove the possibility of `undefined`.\n const [color, setColor] = useControlledValue({\n onChange,\n value: colorProp,\n defaultValue\n });\n const safeColordColor = useMemo(() => {\n return colord(color || '');\n }, [color]);\n const debouncedSetColor = useDebounce(setColor);\n\n // Internal HSLA state preserves hue and saturation values that\n // would otherwise be lost when converting to/from hex at achromatic\n // colors (e.g. pure black or white where any H/S maps to the same hex).\n const [internalHSLA, setInternalHSLA] = useState(() => ({\n ...safeColordColor.toHsl()\n }));\n\n // Track the last hex we produced so the sync effect can\n // distinguish our own updates from external prop changes.\n const lastProducedHexRef = useRef(safeColordColor.toHex());\n\n // Sync internalHSLA when the color prop changes externally (e.g.\n // parent passes a new color that wasn't produced by our onChange).\n useEffect(() => {\n const incomingHex = safeColordColor.toHex();\n\n // If this hex matches what we last produced, it's our own\n // update arriving back \u2014 skip the sync to avoid overwriting\n // internalHSLA with lossy round-tripped values.\n if (incomingHex === lastProducedHexRef.current) {\n return;\n }\n\n // Genuinely external change \u2014 sync internalHSLA.\n lastProducedHexRef.current = incomingHex;\n const externalHSLA = safeColordColor.toHsl();\n setInternalHSLA(prev => mergeHSLA(externalHSLA, prev));\n }, [safeColordColor]);\n\n // Handler for HSL-aware components (Picker, HSL inputs) that\n // provide raw HSLA values without information loss.\n // Uses direct setColor (not debounced) to prevent race conditions\n // where a stale debounced hex would overwrite newer internalHSLA.\n // This is safe performance-wise because react-colorful internally\n // throttles its onChange callbacks using requestAnimationFrame.\n\n const handleHSLAChange = useCallback(nextHSLA => {\n // No mergeHSLA here \u2014 this handler receives the user's explicit\n // choice from the picker or HSL inputs, with no lossy conversion.\n setInternalHSLA(nextHSLA);\n const previousHex = lastProducedHexRef.current;\n const nextHex = colord(nextHSLA).toHex();\n // Only notify parent when the hex actually changes. This\n // avoids firing onChange for H/S changes on achromatic\n // colors (e.g. adjusting hue on pure white).\n if (nextHex !== previousHex) {\n lastProducedHexRef.current = nextHex;\n setColor(nextHex);\n }\n }, [setColor]);\n\n // Handler for components that provide Colord values (RGB, Hex inputs).\n // Uses debouncedSetColor since the hex input fires per keystroke.\n const handleChange = useCallback(nextValue => {\n const nextHSLA = nextValue.toHsl();\n setInternalHSLA(prev => mergeHSLA(nextHSLA, prev));\n const nextHex = nextValue.toHex();\n lastProducedHexRef.current = nextHex;\n debouncedSetColor(nextHex);\n }, [debouncedSetColor]);\n const [colorType, setColorType] = useState(copyFormat || 'hex');\n\n /*\n * ! Listener intended for the CAPTURE phase\n *\n * Capture paste events over the entire color picker, looking for clipboard\n * data that could be parsed as a color. If not, let the paste event\n * propagate normally, so that individual input controls within the\n * component have a chance to handle it.\n */\n const maybeHandlePaste = useCallback(event => {\n const pastedText = event.clipboardData?.getData('text')?.trim();\n if (!pastedText) {\n return;\n }\n const parsedColor = colord(pastedText);\n if (!parsedColor.isValid()) {\n return;\n }\n\n // Apply all valid colors, even if the format isn't supported in\n // the UI (e.g. names like \"cyan\" or, in the future color spaces\n // like \"lch\" if we add the right colord plugins)\n handleChange(parsedColor);\n\n // This redundancy helps TypeScript and is safer than assertions\n const supportedFormats = {\n hex: 'hex',\n rgb: 'rgb',\n hsl: 'hsl'\n };\n const detectedFormat = String(getFormat(pastedText));\n const newColorType = supportedFormats[detectedFormat];\n if (newColorType) {\n setColorType(newColorType);\n }\n\n // Stop at capture phase; no bubbling\n event.stopPropagation();\n event.preventDefault();\n }, [handleChange, setColorType]);\n return /*#__PURE__*/_jsxs(ColorfulWrapper, {\n ref: forwardedRef,\n ...divProps,\n onPasteCapture: maybeHandlePaste,\n children: [/*#__PURE__*/_jsx(Picker, {\n onChange: handleHSLAChange,\n hsla: internalHSLA,\n enableAlpha: enableAlpha\n }), /*#__PURE__*/_jsxs(AuxiliaryColorArtefactWrapper, {\n children: [/*#__PURE__*/_jsxs(AuxiliaryColorArtefactHStackHeader, {\n justify: \"space-between\",\n children: [/*#__PURE__*/_jsx(SelectControl, {\n size: \"compact\",\n options: options,\n value: colorType,\n onChange: nextColorType => setColorType(nextColorType),\n label: __('Color format'),\n hideLabelFromVision: true,\n variant: \"minimal\"\n }), /*#__PURE__*/_jsx(ColorCopyButton, {\n color: safeColordColor,\n colorType: copyFormat || colorType\n })]\n }), /*#__PURE__*/_jsx(ColorInputWrapper, {\n direction: \"column\",\n gap: 2,\n children: /*#__PURE__*/_jsx(ColorInput, {\n colorType: colorType,\n color: safeColordColor,\n hsla: internalHSLA,\n onChange: handleChange,\n onHSLChange: handleHSLAChange,\n enableAlpha: enableAlpha\n })\n })]\n })]\n });\n};\nexport const ColorPicker = contextConnect(UnconnectedColorPicker, 'ColorPicker');\nexport default ColorPicker;"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBA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AAgB;AACtB,UAAM,eAAe;AAAA,EACvB,GAAG,CAAC,cAAc,YAAY,CAAC;AAC/B,SAAoB,uCAAAC,MAAM,+BAAiB;AAAA,IACzC,KAAK;AAAA,IACL,GAAG;AAAA,IACH,gBAAgB;AAAA,IAChB,UAAU,CAAc,uCAAAC,KAAK,sBAAQ;AAAA,MACnC,UAAU;AAAA,MACV,MAAM;AAAA,MACN;AAAA,IACF,CAAC,GAAgB,uCAAAD,MAAM,6CAA+B;AAAA,MACpD,UAAU,CAAc,uCAAAA,MAAM,kDAAoC;AAAA,QAChE,SAAS;AAAA,QACT,UAAU,CAAc,uCAAAC,KAAK,6BAAe;AAAA,UAC1C,MAAM;AAAA,UACN;AAAA,UACA,OAAO;AAAA,UACP,UAAU,mBAAiB,aAAa,aAAa;AAAA,UACrD,WAAO,gBAAG,cAAc;AAAA,UACxB,qBAAqB;AAAA,UACrB,SAAS;AAAA,QACX,CAAC,GAAgB,uCAAAA,KAAK,0CAAiB;AAAA,UACrC,OAAO;AAAA,UACP,WAAW,cAAc;AAAA,QAC3B,CAAC,CAAC;AAAA,MACJ,CAAC,GAAgB,uCAAAA,KAAK,iCAAmB;AAAA,QACvC,WAAW;AAAA,QACX,KAAK;AAAA,QACL,UAAuB,uCAAAA,KAAK,+BAAY;AAAA,UACtC;AAAA,UACA,OAAO;AAAA,UACP,MAAM;AAAA,UACN,UAAU;AAAA,UACV,aAAa;AAAA,UACb;AAAA,QACF,CAAC;AAAA,MACH,CAAC,CAAC;AAAA,IACJ,CAAC,CAAC;AAAA,EACJ,CAAC;AACH;AACO,IAAM,kBAAc,+BAAe,wBAAwB,aAAa;AAC/E,IAAO,oBAAQ;",
6
6
  "names": ["namesPlugin", "_jsxs", "_jsx"]
7
7
  }
@@ -23,39 +23,18 @@ __export(hsl_input_exports, {
23
23
  HslInput: () => HslInput
24
24
  });
25
25
  module.exports = __toCommonJS(hsl_input_exports);
26
- var import_colord = require("colord");
27
- var import_element = require("@wordpress/element");
28
26
  var import_input_with_slider = require("./input-with-slider.cjs");
29
27
  var import_jsx_runtime = require("react/jsx-runtime");
30
28
  var HslInput = ({
31
- color,
29
+ hsla,
32
30
  onChange,
33
31
  enableAlpha
34
32
  }) => {
35
- const colorPropHSLA = (0, import_element.useMemo)(() => color.toHsl(), [color]);
36
- const [internalHSLA, setInternalHSLA] = (0, import_element.useState)({
37
- ...colorPropHSLA
38
- });
39
- const isInternalColorSameAsReceivedColor = color.isEqual((0, import_colord.colord)(internalHSLA));
40
- (0, import_element.useEffect)(() => {
41
- if (!isInternalColorSameAsReceivedColor) {
42
- setInternalHSLA(colorPropHSLA);
43
- }
44
- }, [colorPropHSLA, isInternalColorSameAsReceivedColor]);
45
- const colorValue = isInternalColorSameAsReceivedColor ? internalHSLA : colorPropHSLA;
46
33
  const updateHSLAValue = (partialNewValue) => {
47
- const nextOnChangeValue = (0, import_colord.colord)({
48
- ...colorValue,
34
+ onChange({
35
+ ...hsla,
49
36
  ...partialNewValue
50
37
  });
51
- if (!color.isEqual(nextOnChangeValue)) {
52
- onChange(nextOnChangeValue);
53
- } else {
54
- setInternalHSLA((prevHSLA) => ({
55
- ...prevHSLA,
56
- ...partialNewValue
57
- }));
58
- }
59
38
  };
60
39
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
61
40
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_input_with_slider.InputWithSlider, {
@@ -63,7 +42,7 @@ var HslInput = ({
63
42
  max: 359,
64
43
  label: "Hue",
65
44
  abbreviation: "H",
66
- value: colorValue.h,
45
+ value: hsla.h,
67
46
  onChange: (nextH) => {
68
47
  updateHSLAValue({
69
48
  h: nextH
@@ -74,7 +53,7 @@ var HslInput = ({
74
53
  max: 100,
75
54
  label: "Saturation",
76
55
  abbreviation: "S",
77
- value: colorValue.s,
56
+ value: hsla.s,
78
57
  onChange: (nextS) => {
79
58
  updateHSLAValue({
80
59
  s: nextS
@@ -85,7 +64,7 @@ var HslInput = ({
85
64
  max: 100,
86
65
  label: "Lightness",
87
66
  abbreviation: "L",
88
- value: colorValue.l,
67
+ value: hsla.l,
89
68
  onChange: (nextL) => {
90
69
  updateHSLAValue({
91
70
  l: nextL
@@ -96,7 +75,7 @@ var HslInput = ({
96
75
  max: 100,
97
76
  label: "Alpha",
98
77
  abbreviation: "A",
99
- value: Math.trunc(100 * colorValue.a),
78
+ value: Math.trunc(100 * hsla.a),
100
79
  onChange: (nextA) => {
101
80
  updateHSLAValue({
102
81
  a: nextA / 100
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/color-picker/hsl-input.tsx"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport { colord } from 'colord';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useEffect, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { InputWithSlider } from './input-with-slider';\nimport { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from \"react/jsx-runtime\";\nexport const HslInput = ({\n color,\n onChange,\n enableAlpha\n}) => {\n const colorPropHSLA = useMemo(() => color.toHsl(), [color]);\n const [internalHSLA, setInternalHSLA] = useState({\n ...colorPropHSLA\n });\n const isInternalColorSameAsReceivedColor = color.isEqual(colord(internalHSLA));\n useEffect(() => {\n if (!isInternalColorSameAsReceivedColor) {\n // Keep internal HSLA color up to date with the received color prop\n setInternalHSLA(colorPropHSLA);\n }\n }, [colorPropHSLA, isInternalColorSameAsReceivedColor]);\n\n // If the internal color is equal to the received color prop, we can use the\n // HSLA values from the local state which, compared to the received color prop,\n // retain more details about the actual H and S values that the user selected,\n // and thus allow for better UX when interacting with the H and S sliders.\n const colorValue = isInternalColorSameAsReceivedColor ? internalHSLA : colorPropHSLA;\n const updateHSLAValue = partialNewValue => {\n const nextOnChangeValue = colord({\n ...colorValue,\n ...partialNewValue\n });\n\n // Fire `onChange` only if the resulting color is different from the\n // current one.\n // Otherwise, update the internal HSLA color to cause a re-render.\n if (!color.isEqual(nextOnChangeValue)) {\n onChange(nextOnChangeValue);\n } else {\n setInternalHSLA(prevHSLA => ({\n ...prevHSLA,\n ...partialNewValue\n }));\n }\n };\n return /*#__PURE__*/_jsxs(_Fragment, {\n children: [/*#__PURE__*/_jsx(InputWithSlider, {\n min: 0,\n max: 359,\n label: \"Hue\",\n abbreviation: \"H\",\n value: colorValue.h,\n onChange: nextH => {\n updateHSLAValue({\n h: nextH\n });\n }\n }), /*#__PURE__*/_jsx(InputWithSlider, {\n min: 0,\n max: 100,\n label: \"Saturation\",\n abbreviation: \"S\",\n value: colorValue.s,\n onChange: nextS => {\n updateHSLAValue({\n s: nextS\n });\n }\n }), /*#__PURE__*/_jsx(InputWithSlider, {\n min: 0,\n max: 100,\n label: \"Lightness\",\n abbreviation: \"L\",\n value: colorValue.l,\n onChange: nextL => {\n updateHSLAValue({\n l: nextL\n });\n }\n }), enableAlpha && /*#__PURE__*/_jsx(InputWithSlider, {\n min: 0,\n max: 100,\n label: \"Alpha\",\n abbreviation: \"A\",\n value: Math.trunc(100 * colorValue.a),\n onChange: nextA => {\n updateHSLAValue({\n a: nextA / 100\n });\n }\n })]\n });\n};"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAuB;AAKvB,qBAA6C;AAK7C,+BAAgC;AAChC,yBAAkE;AAC3D,IAAM,WAAW,CAAC;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,oBAAgB,wBAAQ,MAAM,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC;AAC1D,QAAM,CAAC,cAAc,eAAe,QAAI,yBAAS;AAAA,IAC/C,GAAG;AAAA,EACL,CAAC;AACD,QAAM,qCAAqC,MAAM,YAAQ,sBAAO,YAAY,CAAC;AAC7E,gCAAU,MAAM;AACd,QAAI,CAAC,oCAAoC;AAEvC,sBAAgB,aAAa;AAAA,IAC/B;AAAA,EACF,GAAG,CAAC,eAAe,kC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S;AACjB,wBAAgB;AAAA,UACd,GAAG,QAAQ;AAAA,QACb,CAAC;AAAA,MACH;AAAA,IACF,CAAC,CAAC;AAAA,EACJ,CAAC;AACH;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\n\n/**\n * Internal dependencies\n */\nimport { InputWithSlider } from './input-with-slider';\nimport { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from \"react/jsx-runtime\";\nexport const HslInput = ({\n hsla,\n onChange,\n enableAlpha\n}) => {\n const updateHSLAValue = partialNewValue => {\n onChange({\n ...hsla,\n ...partialNewValue\n });\n };\n return /*#__PURE__*/_jsxs(_Fragment, {\n children: [/*#__PURE__*/_jsx(InputWithSlider, {\n min: 0,\n max: 359,\n label: \"Hue\",\n abbreviation: \"H\",\n value: hsla.h,\n onChange: nextH => {\n updateHSLAValue({\n h: nextH\n });\n }\n }), /*#__PURE__*/_jsx(InputWithSlider, {\n min: 0,\n max: 100,\n label: \"Saturation\",\n abbreviation: \"S\",\n value: hsla.s,\n onChange: nextS => {\n updateHSLAValue({\n s: nextS\n });\n }\n }), /*#__PURE__*/_jsx(InputWithSlider, {\n min: 0,\n max: 100,\n label: \"Lightness\",\n abbreviation: \"L\",\n value: hsla.l,\n onChange: nextL => {\n updateHSLAValue({\n l: nextL\n });\n }\n }), enableAlpha && /*#__PURE__*/_jsx(InputWithSlider, {\n min: 0,\n max: 100,\n label: \"Alpha\",\n abbreviation: \"A\",\n value: Math.trunc(100 * hsla.a),\n onChange: nextA => {\n updateHSLAValue({\n a: nextA / 100\n });\n }\n })]\n });\n};"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,+BAAgC;AAChC,yBAAkE;AAC3D,IAAM,WAAW,CAAC;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,kBAAkB,qBAAmB;AACzC,aAAS;AAAA,MACP,GAAG;AAAA,MACH,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACA,SAAoB,uCAAAA,MAAM,mBAAAC,UAAW;AAAA,IACnC,UAAU,CAAc,uCAAAC,KAAK,0CAAiB;AAAA,MAC5C,KAAK;AAAA,MACL,KAAK;AAAA,MACL,OAAO;AAAA,MACP,cAAc;AAAA,MACd,OAAO,KAAK;AAAA,MACZ,UAAU,WAAS;AACjB,wBAAgB;AAAA,UACd,GAAG;AAAA,QACL,CAAC;AAAA,MACH;AAAA,IACF,CAAC,GAAgB,uCAAAA,KAAK,0CAAiB;AAAA,MACrC,KAAK;AAAA,MACL,KAAK;AAAA,MACL,OAAO;AAAA,MACP,cAAc;AAAA,MACd,OAAO,KAAK;AAAA,MACZ,UAAU,WAAS;AACjB,wBAAgB;AAAA,UACd,GAAG;AAAA,QACL,CAAC;AAAA,MACH;AAAA,IACF,CAAC,GAAgB,uCAAAA,KAAK,0CAAiB;AAAA,MACrC,KAAK;AAAA,MACL,KAAK;AAAA,MACL,OAAO;AAAA,MACP,cAAc;AAAA,MACd,OAAO,KAAK;AAAA,MACZ,UAAU,WAAS;AACjB,wBAAgB;AAAA,UACd,GAAG;AAAA,QACL,CAAC;AAAA,MACH;AAAA,IACF,CAAC,GAAG,eAA4B,uCAAAA,KAAK,0CAAiB;AAAA,MACpD,KAAK;AAAA,MACL,KAAK;AAAA,MACL,OAAO;AAAA,MACP,cAAc;AAAA,MACd,OAAO,KAAK,MAAM,MAAM,KAAK,CAAC;AAAA,MAC9B,UAAU,WAAS;AACjB,wBAAgB;AAAA,UACd,GAAG,QAAQ;AAAA,QACb,CAAC;AAAA,MACH;AAAA,IACF,CAAC,CAAC;AAAA,EACJ,CAAC;AACH;",
6
6
  "names": ["_jsxs", "_Fragment", "_jsx"]
7
7
  }
@@ -24,33 +24,42 @@ __export(picker_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(picker_exports);
26
26
  var import_react_colorful = require("react-colorful");
27
- var import_colord = require("colord");
28
- var import_element = require("@wordpress/element");
29
27
  var import_jsx_runtime = require("react/jsx-runtime");
28
+ var pointerCaptureProps = {
29
+ onPointerDown({
30
+ currentTarget,
31
+ pointerId
32
+ }) {
33
+ currentTarget.setPointerCapture(pointerId);
34
+ },
35
+ onPointerUp({
36
+ currentTarget,
37
+ pointerId
38
+ }) {
39
+ currentTarget.releasePointerCapture(pointerId);
40
+ }
41
+ };
30
42
  var Picker = ({
31
- color,
43
+ hsla,
32
44
  enableAlpha,
33
45
  onChange
34
46
  }) => {
35
- const Component = enableAlpha ? import_react_colorful.RgbaStringColorPicker : import_react_colorful.RgbStringColorPicker;
36
- const rgbColor = (0, import_element.useMemo)(() => color.toRgbString(), [color]);
37
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
38
- color: rgbColor,
47
+ if (enableAlpha) {
48
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_colorful.HslaColorPicker, {
49
+ color: hsla,
50
+ onChange,
51
+ ...pointerCaptureProps
52
+ });
53
+ }
54
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_colorful.HslColorPicker, {
55
+ color: hsla,
39
56
  onChange: (nextColor) => {
40
- onChange((0, import_colord.colord)(nextColor));
41
- },
42
- onPointerDown: ({
43
- currentTarget,
44
- pointerId
45
- }) => {
46
- currentTarget.setPointerCapture(pointerId);
57
+ onChange({
58
+ ...nextColor,
59
+ a: hsla.a
60
+ });
47
61
  },
48
- onPointerUp: ({
49
- currentTarget,
50
- pointerId
51
- }) => {
52
- currentTarget.releasePointerCapture(pointerId);
53
- }
62
+ ...pointerCaptureProps
54
63
  });
55
64
  };
56
65
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/color-picker/picker.tsx"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport { RgbStringColorPicker, RgbaStringColorPicker } from 'react-colorful';\nimport { colord } from 'colord';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nexport const Picker = ({\n color,\n enableAlpha,\n onChange\n}) => {\n const Component = enableAlpha ? RgbaStringColorPicker : RgbStringColorPicker;\n const rgbColor = useMemo(() => color.toRgbString(), [color]);\n return /*#__PURE__*/_jsx(Component, {\n color: rgbColor,\n onChange: nextColor => {\n onChange(colord(nextColor));\n }\n // Pointer capture fortifies drag gestures so that they continue to\n // work while dragging outside the component over objects like\n // iframes. If a newer version of react-colorful begins to employ\n // pointer capture this will be redundant and should be removed.\n ,\n onPointerDown: ({\n currentTarget,\n pointerId\n }) => {\n currentTarget.setPointerCapture(pointerId);\n },\n onPointerUp: ({\n currentTarget,\n pointerId\n }) => {\n currentTarget.releasePointerCapture(pointerId);\n }\n });\n};"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,4BAA4D;AAC5D,oBAAuB;AAKvB,qBAAwB;AAIxB,yBAA4B;AACrB,IAAM,SAAS,CAAC;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,YAAY,cAAc,8CAAwB;AACxD,QAAM,eAAW,wBAAQ,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,CAAC;AAC3D,SAAoB,uCAAAA,KAAK,WAAW;AAAA,IAClC,OAAO;AAAA,IACP,UAAU,eAAa;AACrB,mBAAS,sBAAO,SAAS,CAAC;AAAA,IAC5B;AAAA,IAMA,eAAe,CAAC;AAAA,MACd;AAAA,MACA;AAAA,IACF,MAAM;AACJ,oBAAc,kBAAkB,SAAS;AAAA,IAC3C;AAAA,IACA,aAAa,CAAC;AAAA,MACZ;AAAA,MACA;AAAA,IACF,MAAM;AACJ,oBAAc,sBAAsB,SAAS;AAAA,IAC/C;AAAA,EACF,CAAC;AACH;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { HslColorPicker, HslaColorPicker } from 'react-colorful';\n\n/**\n * Internal dependencies\n */\nimport { jsx as _jsx } from \"react/jsx-runtime\";\n// Pointer capture fortifies drag gestures so that they continue to work\n// while dragging outside the component over objects like iframes. If a\n// newer version of react-colorful begins to employ pointer capture this\n// will be redundant and should be removed.\nconst pointerCaptureProps = {\n onPointerDown({\n currentTarget,\n pointerId\n }) {\n currentTarget.setPointerCapture(pointerId);\n },\n onPointerUp({\n currentTarget,\n pointerId\n }) {\n currentTarget.releasePointerCapture(pointerId);\n }\n};\nexport const Picker = ({\n hsla,\n enableAlpha,\n onChange\n}) => {\n if (enableAlpha) {\n return /*#__PURE__*/_jsx(HslaColorPicker, {\n color: hsla,\n onChange: onChange,\n ...pointerCaptureProps\n });\n }\n return /*#__PURE__*/_jsx(HslColorPicker, {\n color: hsla,\n onChange: nextColor => {\n onChange({\n ...nextColor,\n a: hsla.a\n });\n },\n ...pointerCaptureProps\n });\n};"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,4BAAgD;AAKhD,yBAA4B;AAK5B,IAAM,sBAAsB;AAAA,EAC1B,cAAc;AAAA,IACZ;AAAA,IACA;AAAA,EACF,GAAG;AACD,kBAAc,kBAAkB,SAAS;AAAA,EAC3C;AAAA,EACA,YAAY;AAAA,IACV;AAAA,IACA;AAAA,EACF,GAAG;AACD,kBAAc,sBAAsB,SAAS;AAAA,EAC/C;AACF;AACO,IAAM,SAAS,CAAC;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,MAAI,aAAa;AACf,WAAoB,uCAAAA,KAAK,uCAAiB;AAAA,MACxC,OAAO;AAAA,MACP;AAAA,MACA,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACA,SAAoB,uCAAAA,KAAK,sCAAgB;AAAA,IACvC,OAAO;AAAA,IACP,UAAU,eAAa;AACrB,eAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAG,KAAK;AAAA,MACV,CAAC;AAAA,IACH;AAAA,IACA,GAAG;AAAA,EACL,CAAC;AACH;",
6
6
  "names": ["_jsx"]
7
7
  }
@@ -171,7 +171,7 @@ function UnforwardedNumberControl(props, forwardedRef) {
171
171
  constrainValue(currentValue)
172
172
  );
173
173
  }
174
- return nextState;
174
+ return stateReducerProp?.(nextState, action) ?? nextState;
175
175
  };
176
176
  const buildSpinButtonClickHandler = (direction) => (event) => onChange(String(spinValue(valueProp, direction, event)), {
177
177
  // Set event.target to the <input> so that consumers can use
@@ -197,10 +197,7 @@ function UnforwardedNumberControl(props, forwardedRef) {
197
197
  step,
198
198
  type: typeProp,
199
199
  value: valueProp,
200
- __unstableStateReducer: (state, action) => {
201
- const baseState = numberControlStateReducer(state, action);
202
- return stateReducerProp?.(baseState, action) ?? baseState;
203
- },
200
+ __unstableStateReducer: numberControlStateReducer,
204
201
  size,
205
202
  __shouldNotWarnDeprecated36pxSize: true,
206
203
  suffix: spinControls === "custom" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/number-control/index.tsx"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n/**\n * WordPress dependencies\n */\nimport { useRef, forwardRef } from '@wordpress/element';\nimport { isRTL, __ } from '@wordpress/i18n';\nimport { plus as plusIcon, reset as resetIcon } from '@wordpress/icons';\nimport { useMergeRefs } from '@wordpress/compose';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { Input, SpinButton, styles } from './styles/number-control-styles';\nimport * as inputControlActionTypes from '../input-control/reducer/actions';\nimport { add, subtract, clamp, ensureValidStep } from '../utils/math';\nimport { ensureNumber, isValueEmpty } from '../utils/values';\nimport { HStack } from '../h-stack';\nimport { Spacer } from '../spacer';\nimport { useCx } from '../utils';\nimport { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props';\nimport { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';\nimport { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\nconst noop = () => {};\nfunction UnforwardedNumberControl(props, forwardedRef) {\n const {\n __unstableStateReducer: stateReducerProp,\n className,\n dragDirection = 'n',\n hideHTMLArrows = false,\n spinControls = hideHTMLArrows ? 'none' : 'native',\n isDragEnabled = true,\n isShiftStepEnabled = true,\n label,\n max = Infinity,\n min = -Infinity,\n required = false,\n shiftStep = 10,\n step = 1,\n spinFactor = 1,\n type: typeProp = 'number',\n value: valueProp,\n size = 'default',\n suffix,\n onChange = noop,\n __shouldNotWarnDeprecated36pxSize,\n ...restProps\n } = useDeprecated36pxDefaultSizeProp(props);\n maybeWarnDeprecated36pxSize({\n componentName: 'NumberControl',\n size,\n __next40pxDefaultSize: restProps.__next40pxDefaultSize,\n __shouldNotWarnDeprecated36pxSize\n });\n if (hideHTMLArrows) {\n deprecated('wp.components.NumberControl hideHTMLArrows prop ', {\n alternative: 'spinControls=\"none\"',\n since: '6.2',\n version: '6.3'\n });\n }\n const inputRef = useRef(null);\n const mergedRef = useMergeRefs([inputRef, forwardedRef]);\n const isStepAny = step === 'any';\n const baseStep = isStepAny ? 1 : ensureNumber(step);\n const baseSpin = ensureNumber(spinFactor) * baseStep;\n const constrainValue = (value, stepOverride) => {\n // When step is not \"any\" the value must be a valid step.\n if (!isStepAny) {\n value = ensureValidStep(value, min, stepOverride ?? baseStep);\n }\n return `${clamp(value, min, max)}`;\n };\n const baseValue = constrainValue(0);\n const autoComplete = typeProp === 'number' ? 'off' : undefined;\n const classes = clsx('components-number-control', className);\n const cx = useCx();\n const spinButtonClasses = cx(size === 'small' && styles.smallSpinButtons);\n const spinValue = (value, direction, event) => {\n event?.preventDefault();\n const shift = event?.shiftKey && isShiftStepEnabled;\n const delta = shift ? ensureNumber(shiftStep) * baseSpin : baseSpin;\n let nextValue = isValueEmpty(value) ? baseValue : value;\n if (direction === 'up') {\n nextValue = add(nextValue, delta);\n } else if (direction === 'down') {\n nextValue = subtract(nextValue, delta);\n }\n return constrainValue(nextValue, shift ? delta : undefined);\n };\n\n /**\n * \"Middleware\" function that intercepts updates from InputControl.\n * This allows us to tap into actions to transform the (next) state for\n * InputControl.\n *\n * @return The updated state to apply to InputControl\n */\n const numberControlStateReducer = (state, action) => {\n const nextState = {\n ...state\n };\n const {\n type,\n payload\n } = action;\n const event = payload.event;\n const currentValue = nextState.value;\n\n /**\n * Handles custom UP and DOWN Keyboard events\n */\n if (type === inputControlActionTypes.PRESS_UP || type === inputControlActionTypes.PRESS_DOWN) {\n nextState.value = spinValue(currentValue, type === inputControlActionTypes.PRESS_UP ? 'up' : 'down', event);\n }\n\n /**\n * Handles drag to update events\n */\n if (type === inputControlActionTypes.DRAG && isDragEnabled) {\n const [x, y] = payload.delta;\n const enableShift = payload.shiftKey && isShiftStepEnabled;\n const modifier = enableShift ? ensureNumber(shiftStep) * baseSpin : baseSpin;\n let directionModifier;\n let delta;\n switch (dragDirection) {\n case 'n':\n delta = y;\n directionModifier = -1;\n break;\n case 'e':\n delta = x;\n directionModifier = isRTL() ? -1 : 1;\n break;\n case 's':\n delta = y;\n directionModifier = 1;\n break;\n case 'w':\n delta = x;\n directionModifier = isRTL() ? 1 : -1;\n break;\n }\n if (delta !== 0) {\n delta = Math.ceil(Math.abs(delta)) * Math.sign(delta);\n const distance = delta * modifier * directionModifier;\n nextState.value = constrainValue(\n // @ts-expect-error TODO: Investigate if it's ok for currentValue to be undefined\n add(currentValue, distance), enableShift ? modifier : undefined);\n }\n }\n\n /**\n * Handles commit (ENTER key press or blur)\n */\n if (type === inputControlActionTypes.PRESS_ENTER || type === inputControlActionTypes.COMMIT) {\n const applyEmptyValue = required === false && currentValue === '';\n nextState.value = applyEmptyValue ? currentValue :\n // @ts-expect-error TODO: Investigate if it's ok for currentValue to be undefined\n constrainValue(currentValue);\n }\n return nextState;\n };\n const buildSpinButtonClickHandler = direction => event => onChange(String(spinValue(valueProp, direction, event)), {\n // Set event.target to the <input> so that consumers can use\n // e.g. event.target.validity.\n event: {\n ...event,\n target: inputRef.current\n }\n });\n return /*#__PURE__*/_jsx(Input, {\n autoComplete: autoComplete,\n inputMode: \"numeric\",\n ...restProps,\n className: classes,\n dragDirection: dragDirection,\n hideHTMLArrows: spinControls !== 'native',\n isDragEnabled: isDragEnabled,\n label: label,\n max: max === Infinity ? undefined : max,\n min: min === -Infinity ? undefined : min,\n ref: mergedRef,\n required: required,\n step: step,\n type: typeProp\n // @ts-expect-error TODO: Resolve discrepancy between `value` types in InputControl based components\n ,\n value: valueProp,\n __unstableStateReducer: (state, action) => {\n const baseState = numberControlStateReducer(state, action);\n return stateReducerProp?.(baseState, action) ?? baseState;\n },\n size: size,\n __shouldNotWarnDeprecated36pxSize: true,\n suffix: spinControls === 'custom' ? /*#__PURE__*/_jsxs(_Fragment, {\n children: [suffix, /*#__PURE__*/_jsx(Spacer, {\n marginBottom: 0,\n marginRight: 2,\n children: /*#__PURE__*/_jsxs(HStack, {\n spacing: 1,\n children: [/*#__PURE__*/_jsx(SpinButton, {\n className: spinButtonClasses,\n icon: plusIcon,\n size: \"small\",\n label: __('Increment'),\n onClick: buildSpinButtonClickHandler('up')\n }), /*#__PURE__*/_jsx(SpinButton, {\n className: spinButtonClasses,\n icon: resetIcon,\n size: \"small\",\n label: __('Decrement'),\n onClick: buildSpinButtonClickHandler('down')\n })]\n })\n })]\n }) : suffix,\n onChange: onChange\n });\n}\nexport const NumberControl = forwardRef(UnforwardedNumberControl);\nNumberControl.displayName = 'NumberControl';\nexport default NumberControl;"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAIjB,qBAAmC;AACnC,kBAA0B;AAC1B,mBAAqD;AACrD,qBAA6B;AAC7B,wBAAuB;AAKvB,mCAA0C;AAC1C,8BAAyC;AACzC,kBAAsD;AACtD,oBAA2C;AAC3C,qBAAuB;AACvB,oBAAuB;AACvB,mBAAsB;AACtB,k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UAAuB,uCAAAC,MAAM,uBAAQ;AAAA,UACnC,SAAS;AAAA,UACT,UAAU,CAAc,uCAAAD,KAAK,yCAAY;AAAA,YACvC,WAAW;AAAA,YACX,MAAM,aAAAG;AAAA,YACN,MAAM;AAAA,YACN,WAAO,gBAAG,WAAW;AAAA,YACrB,SAAS,4BAA4B,IAAI;AAAA,UAC3C,CAAC,GAAgB,uCAAAH,KAAK,yCAAY;AAAA,YAChC,WAAW;AAAA,YACX,MAAM,aAAAI;AAAA,YACN,MAAM;AAAA,YACN,WAAO,gBAAG,WAAW;AAAA,YACrB,SAAS,4BAA4B,MAAM;AAAA,UAC7C,CAAC,CAAC;AAAA,QACJ,CAAC;AAAA,MACH,CAAC,CAAC;AAAA,IACJ,CAAC,IAAI;AAAA,IACL;AAAA,EACF,CAAC;AACH;AACO,IAAM,oBAAgB,2BAAW,wBAAwB;AAChE,cAAc,cAAc;AAC5B,IAAO,yBAAQ;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n/**\n * WordPress dependencies\n */\nimport { useRef, forwardRef } from '@wordpress/element';\nimport { isRTL, __ } from '@wordpress/i18n';\nimport { plus as plusIcon, reset as resetIcon } from '@wordpress/icons';\nimport { useMergeRefs } from '@wordpress/compose';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { Input, SpinButton, styles } from './styles/number-control-styles';\nimport * as inputControlActionTypes from '../input-control/reducer/actions';\nimport { add, subtract, clamp, ensureValidStep } from '../utils/math';\nimport { ensureNumber, isValueEmpty } from '../utils/values';\nimport { HStack } from '../h-stack';\nimport { Spacer } from '../spacer';\nimport { useCx } from '../utils';\nimport { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props';\nimport { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';\nimport { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\nconst noop = () => {};\nfunction UnforwardedNumberControl(props, forwardedRef) {\n const {\n __unstableStateReducer: stateReducerProp,\n className,\n dragDirection = 'n',\n hideHTMLArrows = false,\n spinControls = hideHTMLArrows ? 'none' : 'native',\n isDragEnabled = true,\n isShiftStepEnabled = true,\n label,\n max = Infinity,\n min = -Infinity,\n required = false,\n shiftStep = 10,\n step = 1,\n spinFactor = 1,\n type: typeProp = 'number',\n value: valueProp,\n size = 'default',\n suffix,\n onChange = noop,\n __shouldNotWarnDeprecated36pxSize,\n ...restProps\n } = useDeprecated36pxDefaultSizeProp(props);\n maybeWarnDeprecated36pxSize({\n componentName: 'NumberControl',\n size,\n __next40pxDefaultSize: restProps.__next40pxDefaultSize,\n __shouldNotWarnDeprecated36pxSize\n });\n if (hideHTMLArrows) {\n deprecated('wp.components.NumberControl hideHTMLArrows prop ', {\n alternative: 'spinControls=\"none\"',\n since: '6.2',\n version: '6.3'\n });\n }\n const inputRef = useRef(null);\n const mergedRef = useMergeRefs([inputRef, forwardedRef]);\n const isStepAny = step === 'any';\n const baseStep = isStepAny ? 1 : ensureNumber(step);\n const baseSpin = ensureNumber(spinFactor) * baseStep;\n const constrainValue = (value, stepOverride) => {\n // When step is not \"any\" the value must be a valid step.\n if (!isStepAny) {\n value = ensureValidStep(value, min, stepOverride ?? baseStep);\n }\n return `${clamp(value, min, max)}`;\n };\n const baseValue = constrainValue(0);\n const autoComplete = typeProp === 'number' ? 'off' : undefined;\n const classes = clsx('components-number-control', className);\n const cx = useCx();\n const spinButtonClasses = cx(size === 'small' && styles.smallSpinButtons);\n const spinValue = (value, direction, event) => {\n event?.preventDefault();\n const shift = event?.shiftKey && isShiftStepEnabled;\n const delta = shift ? ensureNumber(shiftStep) * baseSpin : baseSpin;\n let nextValue = isValueEmpty(value) ? baseValue : value;\n if (direction === 'up') {\n nextValue = add(nextValue, delta);\n } else if (direction === 'down') {\n nextValue = subtract(nextValue, delta);\n }\n return constrainValue(nextValue, shift ? delta : undefined);\n };\n\n /**\n * \"Middleware\" function that intercepts updates from InputControl.\n * This allows us to tap into actions to transform the (next) state for\n * InputControl.\n *\n * @return The updated state to apply to InputControl\n */\n const numberControlStateReducer = (state, action) => {\n const nextState = {\n ...state\n };\n const {\n type,\n payload\n } = action;\n const event = payload.event;\n const currentValue = nextState.value;\n\n /**\n * Handles custom UP and DOWN Keyboard events\n */\n if (type === inputControlActionTypes.PRESS_UP || type === inputControlActionTypes.PRESS_DOWN) {\n nextState.value = spinValue(currentValue, type === inputControlActionTypes.PRESS_UP ? 'up' : 'down', event);\n }\n\n /**\n * Handles drag to update events\n */\n if (type === inputControlActionTypes.DRAG && isDragEnabled) {\n const [x, y] = payload.delta;\n const enableShift = payload.shiftKey && isShiftStepEnabled;\n const modifier = enableShift ? ensureNumber(shiftStep) * baseSpin : baseSpin;\n let directionModifier;\n let delta;\n switch (dragDirection) {\n case 'n':\n delta = y;\n directionModifier = -1;\n break;\n case 'e':\n delta = x;\n directionModifier = isRTL() ? -1 : 1;\n break;\n case 's':\n delta = y;\n directionModifier = 1;\n break;\n case 'w':\n delta = x;\n directionModifier = isRTL() ? 1 : -1;\n break;\n }\n if (delta !== 0) {\n delta = Math.ceil(Math.abs(delta)) * Math.sign(delta);\n const distance = delta * modifier * directionModifier;\n nextState.value = constrainValue(\n // @ts-expect-error TODO: Investigate if it's ok for currentValue to be undefined\n add(currentValue, distance), enableShift ? modifier : undefined);\n }\n }\n\n /**\n * Handles commit (ENTER key press or blur)\n */\n if (type === inputControlActionTypes.PRESS_ENTER || type === inputControlActionTypes.COMMIT) {\n const applyEmptyValue = required === false && currentValue === '';\n nextState.value = applyEmptyValue ? currentValue :\n // @ts-expect-error TODO: Investigate if it's ok for currentValue to be undefined\n constrainValue(currentValue);\n }\n return stateReducerProp?.(nextState, action) ?? nextState;\n };\n const buildSpinButtonClickHandler = direction => event => onChange(String(spinValue(valueProp, direction, event)), {\n // Set event.target to the <input> so that consumers can use\n // e.g. event.target.validity.\n event: {\n ...event,\n target: inputRef.current\n }\n });\n return /*#__PURE__*/_jsx(Input, {\n autoComplete: autoComplete,\n inputMode: \"numeric\",\n ...restProps,\n className: classes,\n dragDirection: dragDirection,\n hideHTMLArrows: spinControls !== 'native',\n isDragEnabled: isDragEnabled,\n label: label,\n max: max === Infinity ? undefined : max,\n min: min === -Infinity ? undefined : min,\n ref: mergedRef,\n required: required,\n step: step,\n type: typeProp\n // @ts-expect-error TODO: Resolve discrepancy between `value` types in InputControl based components\n ,\n value: valueProp,\n __unstableStateReducer: numberControlStateReducer,\n size: size,\n __shouldNotWarnDeprecated36pxSize: true,\n suffix: spinControls === 'custom' ? /*#__PURE__*/_jsxs(_Fragment, {\n children: [suffix, /*#__PURE__*/_jsx(Spacer, {\n marginBottom: 0,\n marginRight: 2,\n children: /*#__PURE__*/_jsxs(HStack, {\n spacing: 1,\n children: [/*#__PURE__*/_jsx(SpinButton, {\n className: spinButtonClasses,\n icon: plusIcon,\n size: \"small\",\n label: __('Increment'),\n onClick: buildSpinButtonClickHandler('up')\n }), /*#__PURE__*/_jsx(SpinButton, {\n className: spinButtonClasses,\n icon: resetIcon,\n size: \"small\",\n label: __('Decrement'),\n onClick: buildSpinButtonClickHandler('down')\n })]\n })\n })]\n }) : suffix,\n onChange: onChange\n });\n}\nexport const NumberControl = forwardRef(UnforwardedNumberControl);\nNumberControl.displayName = 'NumberControl';\nexport default NumberControl;"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAIjB,qBAAmC;AACnC,kBAA0B;AAC1B,mBAAqD;AACrD,qBAA6B;AAC7B,wBAAuB;AAKvB,mCAA0C;AAC1C,8BAAyC;AACzC,kBAAsD;AACtD,oBAA2C;AAC3C,qBAAuB;AACvB,oBAAuB;AACvB,mBAAsB;AACtB,kCAAiD;AACjD,kCAA4C;AAC5C,yBAAkE;AAClE,IAAM,OAAO,MAAM;AAAC;AACpB,SAAS,yBAAyB,OAAO,cAAc;AACrD,QAAM;AAAA,IACJ,wBAAwB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