@react-stately/color 3.3.3-nightly.3940 → 3.3.3-nightly.3960

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.
package/dist/import.mjs CHANGED
@@ -1050,13 +1050,17 @@ const $6e14a98a7f67141d$var$DEFAULT_COLOR = (0, $799cddbef784668f$export$6e865ea
1050
1050
  function $6e14a98a7f67141d$export$6df7f0e2cabc7eef(props) {
1051
1051
  let { value: value , defaultValue: defaultValue , xChannel: xChannel , yChannel: yChannel , onChange: onChange , onChangeEnd: onChangeEnd } = props;
1052
1052
  if (!value && !defaultValue) defaultValue = $6e14a98a7f67141d$var$DEFAULT_COLOR;
1053
- let [color, setColor] = (0, $cBgAy$useControlledState)(value && (0, $799cddbef784668f$export$4cde5df63f53f473)(value), defaultValue && (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue), onChange);
1053
+ let [color, setColorState] = (0, $cBgAy$useControlledState)(value && (0, $799cddbef784668f$export$4cde5df63f53f473)(value), defaultValue && (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue), onChange);
1054
1054
  let valueRef = (0, $cBgAy$useRef)(color);
1055
- valueRef.current = color;
1056
- let channels = (0, $cBgAy$useMemo)(()=>valueRef.current.getColorSpaceAxes({
1055
+ let setColor = (color)=>{
1056
+ valueRef.current = color;
1057
+ setColorState(color);
1058
+ };
1059
+ let channels = (0, $cBgAy$useMemo)(()=>color.getColorSpaceAxes({
1057
1060
  xChannel: xChannel,
1058
1061
  yChannel: yChannel
1059
1062
  }), [
1063
+ color,
1060
1064
  xChannel,
1061
1065
  yChannel
1062
1066
  ]);
@@ -1065,18 +1069,18 @@ function $6e14a98a7f67141d$export$6df7f0e2cabc7eef(props) {
1065
1069
  let { minValue: minValueX , maxValue: maxValueX , step: stepX , pageSize: pageSizeX } = xChannelRange;
1066
1070
  let { minValue: minValueY , maxValue: maxValueY , step: stepY , pageSize: pageSizeY } = yChannelRange;
1067
1071
  let [isDragging, setDragging] = (0, $cBgAy$useState)(false);
1068
- let isDraggingRef = (0, $cBgAy$useRef)(false).current;
1072
+ let isDraggingRef = (0, $cBgAy$useRef)(false);
1069
1073
  let xValue = color.getChannelValue(channels.xChannel);
1070
1074
  let yValue = color.getChannelValue(channels.yChannel);
1071
1075
  let setXValue = (v)=>{
1072
1076
  if (v === xValue) return;
1073
- valueRef.current = color.withChannelValue(channels.xChannel, v);
1074
- setColor(valueRef.current);
1077
+ let newColor = color.withChannelValue(channels.xChannel, v);
1078
+ setColor(newColor);
1075
1079
  };
1076
1080
  let setYValue = (v)=>{
1077
1081
  if (v === yValue) return;
1078
- valueRef.current = color.withChannelValue(channels.yChannel, v);
1079
- setColor(valueRef.current);
1082
+ let newColor = color.withChannelValue(channels.yChannel, v);
1083
+ setColor(newColor);
1080
1084
  };
1081
1085
  return {
1082
1086
  channels: channels,
@@ -1086,9 +1090,7 @@ function $6e14a98a7f67141d$export$6df7f0e2cabc7eef(props) {
1086
1090
  yChannelPageStep: pageSizeY,
1087
1091
  value: color,
1088
1092
  setValue (value) {
1089
- let c = (0, $799cddbef784668f$export$4cde5df63f53f473)(value);
1090
- valueRef.current = c;
1091
- setColor(c);
1093
+ setColor((0, $799cddbef784668f$export$4cde5df63f53f473)(value));
1092
1094
  },
1093
1095
  xValue: xValue,
1094
1096
  setXValue: setXValue,
@@ -1131,8 +1133,8 @@ function $6e14a98a7f67141d$export$6df7f0e2cabc7eef(props) {
1131
1133
  setYValue((0, $cBgAy$snapValueToStep)(yValue - stepSize, minValueY, maxValueY, stepY));
1132
1134
  },
1133
1135
  setDragging (isDragging) {
1134
- let wasDragging = isDraggingRef;
1135
- isDraggingRef = isDragging;
1136
+ let wasDragging = isDraggingRef.current;
1137
+ isDraggingRef.current = isDragging;
1136
1138
  if (onChangeEnd && !isDragging && wasDragging) onChangeEnd(valueRef.current);
1137
1139
  setDragging(isDragging);
1138
1140
  },
@@ -1256,13 +1258,16 @@ function $ee4262c74a467b07$var$cartesianToAngle(x, y, radius) {
1256
1258
  function $ee4262c74a467b07$export$f4301076d9336137(props) {
1257
1259
  let { defaultValue: defaultValue , onChange: onChange , onChangeEnd: onChangeEnd } = props;
1258
1260
  if (!props.value && !defaultValue) defaultValue = $ee4262c74a467b07$var$DEFAULT_COLOR;
1259
- let [value, setValue] = (0, $cBgAy$useControlledState)((0, $799cddbef784668f$export$4cde5df63f53f473)(props.value), (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue), onChange);
1261
+ let [value, setValueState] = (0, $cBgAy$useControlledState)((0, $799cddbef784668f$export$4cde5df63f53f473)(props.value), (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue), onChange);
1260
1262
  let valueRef = (0, $cBgAy$useRef)(value);
1261
- valueRef.current = value;
1263
+ let setValue = (value)=>{
1264
+ valueRef.current = value;
1265
+ setValueState(value);
1266
+ };
1262
1267
  let channelRange = value.getChannelRange("hue");
1263
1268
  let { minValue: minValueX , maxValue: maxValueX , step: step , pageSize: pageStep } = channelRange;
1264
1269
  let [isDragging, setDragging] = (0, $cBgAy$useState)(false);
1265
- let isDraggingRef = (0, $cBgAy$useRef)(false).current;
1270
+ let isDraggingRef = (0, $cBgAy$useRef)(false);
1266
1271
  let hue = value.getChannelValue("hue");
1267
1272
  function setHue(v) {
1268
1273
  if (v > 360) // Make sure you can always get back to 0.
@@ -1270,7 +1275,6 @@ function $ee4262c74a467b07$export$f4301076d9336137(props) {
1270
1275
  v = $ee4262c74a467b07$var$roundToStep($ee4262c74a467b07$var$mod(v, 360), step);
1271
1276
  if (hue !== v) {
1272
1277
  let color = value.withChannelValue("hue", v);
1273
- valueRef.current = color;
1274
1278
  setValue(color);
1275
1279
  }
1276
1280
  }
@@ -1280,7 +1284,6 @@ function $ee4262c74a467b07$export$f4301076d9336137(props) {
1280
1284
  pageStep: pageStep,
1281
1285
  setValue (v) {
1282
1286
  let color = (0, $799cddbef784668f$export$4cde5df63f53f473)(v);
1283
- valueRef.current = color;
1284
1287
  setValue(color);
1285
1288
  },
1286
1289
  hue: hue,
@@ -1306,8 +1309,8 @@ function $ee4262c74a467b07$export$f4301076d9336137(props) {
1306
1309
  else setHue($ee4262c74a467b07$var$roundToStep($ee4262c74a467b07$var$mod(hue - s, 360), s));
1307
1310
  },
1308
1311
  setDragging (isDragging) {
1309
- let wasDragging = isDraggingRef;
1310
- isDraggingRef = isDragging;
1312
+ let wasDragging = isDraggingRef.current;
1313
+ isDraggingRef.current = isDragging;
1311
1314
  if (onChangeEnd && !isDragging && wasDragging) onChangeEnd(valueRef.current);
1312
1315
  setDragging(isDragging);
1313
1316
  },
@@ -1379,10 +1382,10 @@ function $b335ada08155d9c0$export$d52a01683abdfcd6(props) {
1379
1382
  return;
1380
1383
  }
1381
1384
  };
1382
- let prevValue = (0, $cBgAy$useRef)(colorValue);
1383
- if (prevValue.current !== colorValue) {
1385
+ let [prevValue, setPrevValue] = (0, $cBgAy$useState)(colorValue);
1386
+ if (prevValue !== colorValue) {
1384
1387
  setInputValue(colorValue ? colorValue.toString("hex") : "");
1385
- prevValue.current = colorValue;
1388
+ setPrevValue(colorValue);
1386
1389
  }
1387
1390
  let parsedValue = (0, $cBgAy$useMemo)(()=>{
1388
1391
  let color;
@@ -1395,8 +1398,6 @@ function $b335ada08155d9c0$export$d52a01683abdfcd6(props) {
1395
1398
  }, [
1396
1399
  inputValue
1397
1400
  ]);
1398
- let parsed = (0, $cBgAy$useRef)(null);
1399
- parsed.current = parsedValue;
1400
1401
  let commit = ()=>{
1401
1402
  // Set to empty state if input value is empty
1402
1403
  if (!inputValue.length) {
@@ -1405,18 +1406,18 @@ function $b335ada08155d9c0$export$d52a01683abdfcd6(props) {
1405
1406
  return;
1406
1407
  }
1407
1408
  // if it failed to parse, then reset input to formatted version of current number
1408
- if (parsed.current == null) {
1409
+ if (parsedValue == null) {
1409
1410
  setInputValue(colorValue ? colorValue.toString("hex") : "");
1410
1411
  return;
1411
1412
  }
1412
- safelySetColorValue(parsed.current);
1413
+ safelySetColorValue(parsedValue);
1413
1414
  // in a controlled state, the numberValue won't change, so we won't go back to our old input without help
1414
1415
  let newColorValue = "";
1415
1416
  if (colorValue) newColorValue = colorValue.toString("hex");
1416
1417
  setInputValue(newColorValue);
1417
1418
  };
1418
1419
  let increment = ()=>{
1419
- let newValue = $b335ada08155d9c0$var$addColorValue(parsed.current, step);
1420
+ let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, step);
1420
1421
  // if we've arrived at the same value that was previously in the state, the
1421
1422
  // input value should be updated to match
1422
1423
  // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
@@ -1425,7 +1426,7 @@ function $b335ada08155d9c0$export$d52a01683abdfcd6(props) {
1425
1426
  safelySetColorValue(newValue);
1426
1427
  };
1427
1428
  let decrement = ()=>{
1428
- let newValue = $b335ada08155d9c0$var$addColorValue(parsed.current, -step);
1429
+ let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, -step);
1429
1430
  // if we've arrived at the same value that was previously in the state, the
1430
1431
  // input value should be updated to match
1431
1432
  // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
package/dist/main.js CHANGED
@@ -1059,13 +1059,17 @@ const $af2d7ac9990cfee2$var$DEFAULT_COLOR = (0, $83fe1a57d631223b$export$6e865ea
1059
1059
  function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
1060
1060
  let { value: value , defaultValue: defaultValue , xChannel: xChannel , yChannel: yChannel , onChange: onChange , onChangeEnd: onChangeEnd } = props;
1061
1061
  if (!value && !defaultValue) defaultValue = $af2d7ac9990cfee2$var$DEFAULT_COLOR;
1062
- let [color, setColor] = (0, $4tN2K$reactstatelyutils.useControlledState)(value && (0, $83fe1a57d631223b$export$4cde5df63f53f473)(value), defaultValue && (0, $83fe1a57d631223b$export$4cde5df63f53f473)(defaultValue), onChange);
1062
+ let [color, setColorState] = (0, $4tN2K$reactstatelyutils.useControlledState)(value && (0, $83fe1a57d631223b$export$4cde5df63f53f473)(value), defaultValue && (0, $83fe1a57d631223b$export$4cde5df63f53f473)(defaultValue), onChange);
1063
1063
  let valueRef = (0, $4tN2K$react.useRef)(color);
1064
- valueRef.current = color;
1065
- let channels = (0, $4tN2K$react.useMemo)(()=>valueRef.current.getColorSpaceAxes({
1064
+ let setColor = (color)=>{
1065
+ valueRef.current = color;
1066
+ setColorState(color);
1067
+ };
1068
+ let channels = (0, $4tN2K$react.useMemo)(()=>color.getColorSpaceAxes({
1066
1069
  xChannel: xChannel,
1067
1070
  yChannel: yChannel
1068
1071
  }), [
1072
+ color,
1069
1073
  xChannel,
1070
1074
  yChannel
1071
1075
  ]);
@@ -1074,18 +1078,18 @@ function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
1074
1078
  let { minValue: minValueX , maxValue: maxValueX , step: stepX , pageSize: pageSizeX } = xChannelRange;
1075
1079
  let { minValue: minValueY , maxValue: maxValueY , step: stepY , pageSize: pageSizeY } = yChannelRange;
1076
1080
  let [isDragging, setDragging] = (0, $4tN2K$react.useState)(false);
1077
- let isDraggingRef = (0, $4tN2K$react.useRef)(false).current;
1081
+ let isDraggingRef = (0, $4tN2K$react.useRef)(false);
1078
1082
  let xValue = color.getChannelValue(channels.xChannel);
1079
1083
  let yValue = color.getChannelValue(channels.yChannel);
1080
1084
  let setXValue = (v)=>{
1081
1085
  if (v === xValue) return;
1082
- valueRef.current = color.withChannelValue(channels.xChannel, v);
1083
- setColor(valueRef.current);
1086
+ let newColor = color.withChannelValue(channels.xChannel, v);
1087
+ setColor(newColor);
1084
1088
  };
1085
1089
  let setYValue = (v)=>{
1086
1090
  if (v === yValue) return;
1087
- valueRef.current = color.withChannelValue(channels.yChannel, v);
1088
- setColor(valueRef.current);
1091
+ let newColor = color.withChannelValue(channels.yChannel, v);
1092
+ setColor(newColor);
1089
1093
  };
1090
1094
  return {
1091
1095
  channels: channels,
@@ -1095,9 +1099,7 @@ function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
1095
1099
  yChannelPageStep: pageSizeY,
1096
1100
  value: color,
1097
1101
  setValue (value) {
1098
- let c = (0, $83fe1a57d631223b$export$4cde5df63f53f473)(value);
1099
- valueRef.current = c;
1100
- setColor(c);
1102
+ setColor((0, $83fe1a57d631223b$export$4cde5df63f53f473)(value));
1101
1103
  },
1102
1104
  xValue: xValue,
1103
1105
  setXValue: setXValue,
@@ -1140,8 +1142,8 @@ function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
1140
1142
  setYValue((0, $4tN2K$reactstatelyutils.snapValueToStep)(yValue - stepSize, minValueY, maxValueY, stepY));
1141
1143
  },
1142
1144
  setDragging (isDragging) {
1143
- let wasDragging = isDraggingRef;
1144
- isDraggingRef = isDragging;
1145
+ let wasDragging = isDraggingRef.current;
1146
+ isDraggingRef.current = isDragging;
1145
1147
  if (onChangeEnd && !isDragging && wasDragging) onChangeEnd(valueRef.current);
1146
1148
  setDragging(isDragging);
1147
1149
  },
@@ -1265,13 +1267,16 @@ function $9d7d8736d45f74b8$var$cartesianToAngle(x, y, radius) {
1265
1267
  function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
1266
1268
  let { defaultValue: defaultValue , onChange: onChange , onChangeEnd: onChangeEnd } = props;
1267
1269
  if (!props.value && !defaultValue) defaultValue = $9d7d8736d45f74b8$var$DEFAULT_COLOR;
1268
- let [value, setValue] = (0, $4tN2K$reactstatelyutils.useControlledState)((0, $83fe1a57d631223b$export$4cde5df63f53f473)(props.value), (0, $83fe1a57d631223b$export$4cde5df63f53f473)(defaultValue), onChange);
1270
+ let [value, setValueState] = (0, $4tN2K$reactstatelyutils.useControlledState)((0, $83fe1a57d631223b$export$4cde5df63f53f473)(props.value), (0, $83fe1a57d631223b$export$4cde5df63f53f473)(defaultValue), onChange);
1269
1271
  let valueRef = (0, $4tN2K$react.useRef)(value);
1270
- valueRef.current = value;
1272
+ let setValue = (value)=>{
1273
+ valueRef.current = value;
1274
+ setValueState(value);
1275
+ };
1271
1276
  let channelRange = value.getChannelRange("hue");
1272
1277
  let { minValue: minValueX , maxValue: maxValueX , step: step , pageSize: pageStep } = channelRange;
1273
1278
  let [isDragging, setDragging] = (0, $4tN2K$react.useState)(false);
1274
- let isDraggingRef = (0, $4tN2K$react.useRef)(false).current;
1279
+ let isDraggingRef = (0, $4tN2K$react.useRef)(false);
1275
1280
  let hue = value.getChannelValue("hue");
1276
1281
  function setHue(v) {
1277
1282
  if (v > 360) // Make sure you can always get back to 0.
@@ -1279,7 +1284,6 @@ function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
1279
1284
  v = $9d7d8736d45f74b8$var$roundToStep($9d7d8736d45f74b8$var$mod(v, 360), step);
1280
1285
  if (hue !== v) {
1281
1286
  let color = value.withChannelValue("hue", v);
1282
- valueRef.current = color;
1283
1287
  setValue(color);
1284
1288
  }
1285
1289
  }
@@ -1289,7 +1293,6 @@ function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
1289
1293
  pageStep: pageStep,
1290
1294
  setValue (v) {
1291
1295
  let color = (0, $83fe1a57d631223b$export$4cde5df63f53f473)(v);
1292
- valueRef.current = color;
1293
1296
  setValue(color);
1294
1297
  },
1295
1298
  hue: hue,
@@ -1315,8 +1318,8 @@ function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
1315
1318
  else setHue($9d7d8736d45f74b8$var$roundToStep($9d7d8736d45f74b8$var$mod(hue - s, 360), s));
1316
1319
  },
1317
1320
  setDragging (isDragging) {
1318
- let wasDragging = isDraggingRef;
1319
- isDraggingRef = isDragging;
1321
+ let wasDragging = isDraggingRef.current;
1322
+ isDraggingRef.current = isDragging;
1320
1323
  if (onChangeEnd && !isDragging && wasDragging) onChangeEnd(valueRef.current);
1321
1324
  setDragging(isDragging);
1322
1325
  },
@@ -1388,10 +1391,10 @@ function $d59d0c2b2ce1568f$export$d52a01683abdfcd6(props) {
1388
1391
  return;
1389
1392
  }
1390
1393
  };
1391
- let prevValue = (0, $4tN2K$react.useRef)(colorValue);
1392
- if (prevValue.current !== colorValue) {
1394
+ let [prevValue, setPrevValue] = (0, $4tN2K$react.useState)(colorValue);
1395
+ if (prevValue !== colorValue) {
1393
1396
  setInputValue(colorValue ? colorValue.toString("hex") : "");
1394
- prevValue.current = colorValue;
1397
+ setPrevValue(colorValue);
1395
1398
  }
1396
1399
  let parsedValue = (0, $4tN2K$react.useMemo)(()=>{
1397
1400
  let color;
@@ -1404,8 +1407,6 @@ function $d59d0c2b2ce1568f$export$d52a01683abdfcd6(props) {
1404
1407
  }, [
1405
1408
  inputValue
1406
1409
  ]);
1407
- let parsed = (0, $4tN2K$react.useRef)(null);
1408
- parsed.current = parsedValue;
1409
1410
  let commit = ()=>{
1410
1411
  // Set to empty state if input value is empty
1411
1412
  if (!inputValue.length) {
@@ -1414,18 +1415,18 @@ function $d59d0c2b2ce1568f$export$d52a01683abdfcd6(props) {
1414
1415
  return;
1415
1416
  }
1416
1417
  // if it failed to parse, then reset input to formatted version of current number
1417
- if (parsed.current == null) {
1418
+ if (parsedValue == null) {
1418
1419
  setInputValue(colorValue ? colorValue.toString("hex") : "");
1419
1420
  return;
1420
1421
  }
1421
- safelySetColorValue(parsed.current);
1422
+ safelySetColorValue(parsedValue);
1422
1423
  // in a controlled state, the numberValue won't change, so we won't go back to our old input without help
1423
1424
  let newColorValue = "";
1424
1425
  if (colorValue) newColorValue = colorValue.toString("hex");
1425
1426
  setInputValue(newColorValue);
1426
1427
  };
1427
1428
  let increment = ()=>{
1428
- let newValue = $d59d0c2b2ce1568f$var$addColorValue(parsed.current, step);
1429
+ let newValue = $d59d0c2b2ce1568f$var$addColorValue(parsedValue, step);
1429
1430
  // if we've arrived at the same value that was previously in the state, the
1430
1431
  // input value should be updated to match
1431
1432
  // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
@@ -1434,7 +1435,7 @@ function $d59d0c2b2ce1568f$export$d52a01683abdfcd6(props) {
1434
1435
  safelySetColorValue(newValue);
1435
1436
  };
1436
1437
  let decrement = ()=>{
1437
- let newValue = $d59d0c2b2ce1568f$var$addColorValue(parsed.current, -step);
1438
+ let newValue = $d59d0c2b2ce1568f$var$addColorValue(parsedValue, -step);
1438
1439
  // if we've arrived at the same value that was previously in the state, the
1439
1440
  // input value should be updated to match
1440
1441
  // ex type 4, press increment, highlight the number in the input, type 4 again, press increment