@zag-js/color-picker 0.33.2 → 0.35.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.
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +118 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +119 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -14
- package/src/color-picker.machine.ts +119 -37
- package/src/color-picker.types.ts +9 -0
package/dist/index.d.mts
CHANGED
|
@@ -84,6 +84,10 @@ interface PublicContext extends CommonProperties, InteractOutsideHandlers {
|
|
|
84
84
|
* Whether the color picker is open
|
|
85
85
|
*/
|
|
86
86
|
open?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Whether the color picker open state is controlled by the user
|
|
89
|
+
*/
|
|
90
|
+
"open.controlled"?: boolean;
|
|
87
91
|
/**
|
|
88
92
|
* The color format to use
|
|
89
93
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -84,6 +84,10 @@ interface PublicContext extends CommonProperties, InteractOutsideHandlers {
|
|
|
84
84
|
* Whether the color picker is open
|
|
85
85
|
*/
|
|
86
86
|
open?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Whether the color picker open state is controlled by the user
|
|
89
|
+
*/
|
|
90
|
+
"open.controlled"?: boolean;
|
|
87
91
|
/**
|
|
88
92
|
* The color format to use
|
|
89
93
|
*/
|
package/dist/index.js
CHANGED
|
@@ -813,6 +813,7 @@ var parse = (colorString) => {
|
|
|
813
813
|
};
|
|
814
814
|
|
|
815
815
|
// src/color-picker.machine.ts
|
|
816
|
+
var { and } = import_core.guards;
|
|
816
817
|
function machine(userContext) {
|
|
817
818
|
const ctx = (0, import_utils2.compact)(userContext);
|
|
818
819
|
return (0, import_core.createMachine)(
|
|
@@ -830,6 +831,7 @@ function machine(userContext) {
|
|
|
830
831
|
activeChannel: null,
|
|
831
832
|
activeOrientation: null,
|
|
832
833
|
fieldsetDisabled: false,
|
|
834
|
+
restoreFocus: true,
|
|
833
835
|
positioning: {
|
|
834
836
|
...ctx.positioning,
|
|
835
837
|
placement: "bottom"
|
|
@@ -869,14 +871,30 @@ function machine(userContext) {
|
|
|
869
871
|
idle: {
|
|
870
872
|
tags: ["closed"],
|
|
871
873
|
on: {
|
|
872
|
-
OPEN: {
|
|
874
|
+
"CONTROLLED.OPEN": {
|
|
873
875
|
target: "open",
|
|
874
|
-
actions: ["setInitialFocus"
|
|
875
|
-
},
|
|
876
|
-
"TRIGGER.CLICK": {
|
|
877
|
-
target: "open",
|
|
878
|
-
actions: ["setInitialFocus", "invokeOnOpen"]
|
|
876
|
+
actions: ["setInitialFocus"]
|
|
879
877
|
},
|
|
878
|
+
OPEN: [
|
|
879
|
+
{
|
|
880
|
+
guard: "isOpenControlled",
|
|
881
|
+
actions: ["invokeOnOpen"]
|
|
882
|
+
},
|
|
883
|
+
{
|
|
884
|
+
target: "open",
|
|
885
|
+
actions: ["invokeOnOpen", "setInitialFocus"]
|
|
886
|
+
}
|
|
887
|
+
],
|
|
888
|
+
"TRIGGER.CLICK": [
|
|
889
|
+
{
|
|
890
|
+
guard: "isOpenControlled",
|
|
891
|
+
actions: ["invokeOnOpen"]
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
target: "open",
|
|
895
|
+
actions: ["invokeOnOpen", "setInitialFocus"]
|
|
896
|
+
}
|
|
897
|
+
],
|
|
880
898
|
"CHANNEL_INPUT.FOCUS": {
|
|
881
899
|
target: "focused",
|
|
882
900
|
actions: ["setActiveChannel"]
|
|
@@ -886,14 +904,30 @@ function machine(userContext) {
|
|
|
886
904
|
focused: {
|
|
887
905
|
tags: ["closed", "focused"],
|
|
888
906
|
on: {
|
|
889
|
-
OPEN: {
|
|
907
|
+
"CONTROLLED.OPEN": {
|
|
890
908
|
target: "open",
|
|
891
|
-
actions: ["setInitialFocus"
|
|
892
|
-
},
|
|
893
|
-
"TRIGGER.CLICK": {
|
|
894
|
-
target: "open",
|
|
895
|
-
actions: ["setInitialFocus", "invokeOnOpen"]
|
|
909
|
+
actions: ["setInitialFocus"]
|
|
896
910
|
},
|
|
911
|
+
OPEN: [
|
|
912
|
+
{
|
|
913
|
+
guard: "isOpenControlled",
|
|
914
|
+
actions: ["invokeOnOpen"]
|
|
915
|
+
},
|
|
916
|
+
{
|
|
917
|
+
target: "open",
|
|
918
|
+
actions: ["invokeOnOpen", "setInitialFocus"]
|
|
919
|
+
}
|
|
920
|
+
],
|
|
921
|
+
"TRIGGER.CLICK": [
|
|
922
|
+
{
|
|
923
|
+
guard: "isOpenControlled",
|
|
924
|
+
actions: ["invokeOnOpen"]
|
|
925
|
+
},
|
|
926
|
+
{
|
|
927
|
+
target: "open",
|
|
928
|
+
actions: ["invokeOnOpen", "setInitialFocus"]
|
|
929
|
+
}
|
|
930
|
+
],
|
|
897
931
|
"CHANNEL_INPUT.FOCUS": {
|
|
898
932
|
actions: ["setActiveChannel"]
|
|
899
933
|
},
|
|
@@ -910,10 +944,26 @@ function machine(userContext) {
|
|
|
910
944
|
tags: ["open"],
|
|
911
945
|
activities: ["trackPositioning", "trackDismissableElement"],
|
|
912
946
|
on: {
|
|
913
|
-
"
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
947
|
+
"CONTROLLED.CLOSE": [
|
|
948
|
+
{
|
|
949
|
+
guard: "shouldRestoreFocus",
|
|
950
|
+
target: "focused",
|
|
951
|
+
actions: ["setReturnFocus"]
|
|
952
|
+
},
|
|
953
|
+
{
|
|
954
|
+
target: "idle"
|
|
955
|
+
}
|
|
956
|
+
],
|
|
957
|
+
"TRIGGER.CLICK": [
|
|
958
|
+
{
|
|
959
|
+
guard: "isOpenControlled",
|
|
960
|
+
actions: ["invokeOnClose"]
|
|
961
|
+
},
|
|
962
|
+
{
|
|
963
|
+
target: "idle",
|
|
964
|
+
actions: ["invokeOnClose"]
|
|
965
|
+
}
|
|
966
|
+
],
|
|
917
967
|
"AREA.POINTER_DOWN": {
|
|
918
968
|
target: "open:dragging",
|
|
919
969
|
actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
|
|
@@ -974,25 +1024,39 @@ function machine(userContext) {
|
|
|
974
1024
|
actions: ["setChannelColorFromInput"]
|
|
975
1025
|
},
|
|
976
1026
|
INTERACT_OUTSIDE: [
|
|
1027
|
+
{
|
|
1028
|
+
guard: "isOpenControlled",
|
|
1029
|
+
actions: ["invokeOnClose"]
|
|
1030
|
+
},
|
|
977
1031
|
{
|
|
978
1032
|
guard: "shouldRestoreFocus",
|
|
979
1033
|
target: "focused",
|
|
980
|
-
actions: ["
|
|
1034
|
+
actions: ["invokeOnClose", "setReturnFocus"]
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
target: "idle",
|
|
1038
|
+
actions: ["invokeOnClose"]
|
|
1039
|
+
}
|
|
1040
|
+
],
|
|
1041
|
+
CLOSE: [
|
|
1042
|
+
{
|
|
1043
|
+
guard: "isOpenControlled",
|
|
1044
|
+
actions: ["invokeOnClose"]
|
|
981
1045
|
},
|
|
982
1046
|
{
|
|
983
1047
|
target: "idle",
|
|
984
1048
|
actions: ["invokeOnClose"]
|
|
985
1049
|
}
|
|
986
1050
|
],
|
|
987
|
-
CLOSE: {
|
|
988
|
-
target: "idle",
|
|
989
|
-
actions: ["invokeOnClose"]
|
|
990
|
-
},
|
|
991
1051
|
"SWATCH_TRIGGER.CLICK": [
|
|
1052
|
+
{
|
|
1053
|
+
guard: and("isOpenControlled", "closeOnSelect"),
|
|
1054
|
+
actions: ["setValue", "invokeOnClose"]
|
|
1055
|
+
},
|
|
992
1056
|
{
|
|
993
1057
|
guard: "closeOnSelect",
|
|
994
1058
|
target: "focused",
|
|
995
|
-
actions: ["setValue", "
|
|
1059
|
+
actions: ["setValue", "invokeOnClose", "setReturnFocus"]
|
|
996
1060
|
},
|
|
997
1061
|
{
|
|
998
1062
|
actions: ["setValue"]
|
|
@@ -1005,6 +1069,16 @@ function machine(userContext) {
|
|
|
1005
1069
|
exit: ["clearActiveChannel"],
|
|
1006
1070
|
activities: ["trackPointerMove", "disableTextSelection", "trackPositioning", "trackDismissableElement"],
|
|
1007
1071
|
on: {
|
|
1072
|
+
"CONTROLLED.CLOSE": [
|
|
1073
|
+
{
|
|
1074
|
+
guard: "shouldRestoreFocus",
|
|
1075
|
+
target: "focused",
|
|
1076
|
+
actions: ["setReturnFocus"]
|
|
1077
|
+
},
|
|
1078
|
+
{
|
|
1079
|
+
target: "idle"
|
|
1080
|
+
}
|
|
1081
|
+
],
|
|
1008
1082
|
"AREA.POINTER_MOVE": {
|
|
1009
1083
|
actions: ["setAreaColorFromPoint", "focusAreaThumb"]
|
|
1010
1084
|
},
|
|
@@ -1020,28 +1094,39 @@ function machine(userContext) {
|
|
|
1020
1094
|
actions: ["invokeOnChangeEnd"]
|
|
1021
1095
|
},
|
|
1022
1096
|
INTERACT_OUTSIDE: [
|
|
1097
|
+
{
|
|
1098
|
+
guard: "isOpenControlled",
|
|
1099
|
+
actions: ["invokeOnClose"]
|
|
1100
|
+
},
|
|
1023
1101
|
{
|
|
1024
1102
|
guard: "shouldRestoreFocus",
|
|
1025
1103
|
target: "focused",
|
|
1026
|
-
actions: ["
|
|
1104
|
+
actions: ["invokeOnClose", "setReturnFocus"]
|
|
1027
1105
|
},
|
|
1028
1106
|
{
|
|
1029
1107
|
target: "idle",
|
|
1030
1108
|
actions: ["invokeOnClose"]
|
|
1031
1109
|
}
|
|
1032
1110
|
],
|
|
1033
|
-
CLOSE:
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1111
|
+
CLOSE: [
|
|
1112
|
+
{
|
|
1113
|
+
guard: "isOpenControlled",
|
|
1114
|
+
actions: ["invokeOnClose"]
|
|
1115
|
+
},
|
|
1116
|
+
{
|
|
1117
|
+
target: "idle",
|
|
1118
|
+
actions: ["invokeOnClose"]
|
|
1119
|
+
}
|
|
1120
|
+
]
|
|
1037
1121
|
}
|
|
1038
1122
|
}
|
|
1039
1123
|
}
|
|
1040
1124
|
},
|
|
1041
1125
|
{
|
|
1042
1126
|
guards: {
|
|
1043
|
-
|
|
1044
|
-
|
|
1127
|
+
closeOnSelect: (ctx2) => !!ctx2.closeOnSelect,
|
|
1128
|
+
isOpenControlled: (ctx2) => !!ctx2["open.controlled"],
|
|
1129
|
+
shouldRestoreFocus: (ctx2) => !!ctx2.restoreFocus
|
|
1045
1130
|
},
|
|
1046
1131
|
activities: {
|
|
1047
1132
|
trackPositioning(ctx2) {
|
|
@@ -1053,15 +1138,11 @@ function machine(userContext) {
|
|
|
1053
1138
|
defer: true,
|
|
1054
1139
|
onComplete(data) {
|
|
1055
1140
|
ctx2.currentPlacement = data.placement;
|
|
1056
|
-
},
|
|
1057
|
-
onCleanup() {
|
|
1058
|
-
ctx2.currentPlacement = void 0;
|
|
1059
1141
|
}
|
|
1060
1142
|
});
|
|
1061
1143
|
},
|
|
1062
1144
|
trackDismissableElement(ctx2, _evt, { send }) {
|
|
1063
1145
|
const getContentEl = () => dom.getContentEl(ctx2);
|
|
1064
|
-
let restoreFocus = true;
|
|
1065
1146
|
return (0, import_dismissable.trackDismissableElement)(getContentEl, {
|
|
1066
1147
|
exclude: dom.getTriggerEl(ctx2),
|
|
1067
1148
|
defer: true,
|
|
@@ -1069,12 +1150,12 @@ function machine(userContext) {
|
|
|
1069
1150
|
ctx2.onInteractOutside?.(event);
|
|
1070
1151
|
if (event.defaultPrevented)
|
|
1071
1152
|
return;
|
|
1072
|
-
restoreFocus = !(event.detail.focusable || event.detail.contextmenu);
|
|
1153
|
+
ctx2.restoreFocus = !(event.detail.focusable || event.detail.contextmenu);
|
|
1073
1154
|
},
|
|
1074
1155
|
onPointerDownOutside: ctx2.onPointerDownOutside,
|
|
1075
1156
|
onFocusOutside: ctx2.onFocusOutside,
|
|
1076
1157
|
onDismiss() {
|
|
1077
|
-
send({ type: "INTERACT_OUTSIDE"
|
|
1158
|
+
send({ type: "INTERACT_OUTSIDE" });
|
|
1078
1159
|
}
|
|
1079
1160
|
});
|
|
1080
1161
|
},
|
|
@@ -1252,8 +1333,8 @@ function machine(userContext) {
|
|
|
1252
1333
|
invokeOnClose(ctx2) {
|
|
1253
1334
|
ctx2.onOpenChange?.({ open: false });
|
|
1254
1335
|
},
|
|
1255
|
-
toggleVisibility(ctx2,
|
|
1256
|
-
send({ type: ctx2.open ? "OPEN" : "CLOSE",
|
|
1336
|
+
toggleVisibility(ctx2, evt, { send }) {
|
|
1337
|
+
send({ type: ctx2.open ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE", previousEvent: evt });
|
|
1257
1338
|
}
|
|
1258
1339
|
},
|
|
1259
1340
|
compareFns: {
|