@zag-js/slider 0.2.2 → 0.2.3

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.ts CHANGED
@@ -25,6 +25,10 @@ declare type PublicContext = DirectionProperty & CommonProperties & {
25
25
  * The name associated with the slider (when used in a form)
26
26
  */
27
27
  name?: string;
28
+ /**
29
+ * The associate form of the underlying input element.
30
+ */
31
+ form?: string;
28
32
  /**
29
33
  * Whether the slider is disabled
30
34
  */
@@ -32,7 +36,7 @@ declare type PublicContext = DirectionProperty & CommonProperties & {
32
36
  /**
33
37
  * Whether the slider is read-only
34
38
  */
35
- readonly?: boolean;
39
+ readOnly?: boolean;
36
40
  /**
37
41
  * Whether the slider value is invalid
38
42
  */
package/dist/index.js CHANGED
@@ -405,6 +405,21 @@ function trackFieldsetDisabled(el, callback) {
405
405
  callback(fieldset.disabled);
406
406
  return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
407
407
  }
408
+ function trackFormControl(el, options) {
409
+ if (!el)
410
+ return;
411
+ const { onFieldsetDisabled, onFormReset } = options;
412
+ const cleanups = [
413
+ trackFormReset(el, onFormReset),
414
+ trackFieldsetDisabled(el, (disabled) => {
415
+ if (disabled)
416
+ onFieldsetDisabled();
417
+ })
418
+ ];
419
+ return () => {
420
+ cleanups.forEach((cleanup) => cleanup == null ? void 0 : cleanup());
421
+ };
422
+ }
408
423
 
409
424
  // ../../utilities/number/dist/index.mjs
410
425
  function round(v, t) {
@@ -791,6 +806,7 @@ function connect(state2, send, normalize) {
791
806
  type: "text",
792
807
  defaultValue: state2.context.value,
793
808
  name: state2.context.name,
809
+ form: state2.context.form,
794
810
  id: dom.getInputId(state2.context),
795
811
  hidden: true
796
812
  }),
@@ -906,13 +922,13 @@ function machine(userContext) {
906
922
  isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
907
923
  isVertical: (ctx2) => ctx2.orientation === "vertical",
908
924
  isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
909
- isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
925
+ isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly),
910
926
  hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
911
927
  },
912
928
  watch: {
913
929
  value: ["invokeOnChange", "dispatchChangeEvent"]
914
930
  },
915
- activities: ["trackFormReset", "trackFieldsetDisabled", "trackThumbSize"],
931
+ activities: ["trackFormControlState", "trackThumbSize"],
916
932
  on: {
917
933
  SET_VALUE: {
918
934
  actions: "setValue"
@@ -1001,17 +1017,15 @@ function machine(userContext) {
1001
1017
  isVertical: (ctx2) => ctx2.isVertical
1002
1018
  },
1003
1019
  activities: {
1004
- trackFieldsetDisabled(ctx2) {
1005
- return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
1006
- if (disabled) {
1007
- ctx2.disabled = disabled;
1008
- }
1009
- });
1010
- },
1011
- trackFormReset(ctx2) {
1012
- return trackFormReset(dom.getInputEl(ctx2), () => {
1013
- if (ctx2.initialValue != null) {
1014
- ctx2.value = ctx2.initialValue;
1020
+ trackFormControlState(ctx2) {
1021
+ return trackFormControl(dom.getInputEl(ctx2), {
1022
+ onFieldsetDisabled() {
1023
+ ctx2.disabled = true;
1024
+ },
1025
+ onFormReset() {
1026
+ if (ctx2.initialValue != null) {
1027
+ ctx2.value = ctx2.initialValue;
1028
+ }
1015
1029
  }
1016
1030
  });
1017
1031
  },
package/dist/index.mjs CHANGED
@@ -377,6 +377,21 @@ function trackFieldsetDisabled(el, callback) {
377
377
  callback(fieldset.disabled);
378
378
  return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
379
379
  }
380
+ function trackFormControl(el, options) {
381
+ if (!el)
382
+ return;
383
+ const { onFieldsetDisabled, onFormReset } = options;
384
+ const cleanups = [
385
+ trackFormReset(el, onFormReset),
386
+ trackFieldsetDisabled(el, (disabled) => {
387
+ if (disabled)
388
+ onFieldsetDisabled();
389
+ })
390
+ ];
391
+ return () => {
392
+ cleanups.forEach((cleanup) => cleanup == null ? void 0 : cleanup());
393
+ };
394
+ }
380
395
 
381
396
  // ../../utilities/number/dist/index.mjs
382
397
  function round(v, t) {
@@ -763,6 +778,7 @@ function connect(state2, send, normalize) {
763
778
  type: "text",
764
779
  defaultValue: state2.context.value,
765
780
  name: state2.context.name,
781
+ form: state2.context.form,
766
782
  id: dom.getInputId(state2.context),
767
783
  hidden: true
768
784
  }),
@@ -878,13 +894,13 @@ function machine(userContext) {
878
894
  isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
879
895
  isVertical: (ctx2) => ctx2.orientation === "vertical",
880
896
  isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
881
- isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
897
+ isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly),
882
898
  hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
883
899
  },
884
900
  watch: {
885
901
  value: ["invokeOnChange", "dispatchChangeEvent"]
886
902
  },
887
- activities: ["trackFormReset", "trackFieldsetDisabled", "trackThumbSize"],
903
+ activities: ["trackFormControlState", "trackThumbSize"],
888
904
  on: {
889
905
  SET_VALUE: {
890
906
  actions: "setValue"
@@ -973,17 +989,15 @@ function machine(userContext) {
973
989
  isVertical: (ctx2) => ctx2.isVertical
974
990
  },
975
991
  activities: {
976
- trackFieldsetDisabled(ctx2) {
977
- return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
978
- if (disabled) {
979
- ctx2.disabled = disabled;
980
- }
981
- });
982
- },
983
- trackFormReset(ctx2) {
984
- return trackFormReset(dom.getInputEl(ctx2), () => {
985
- if (ctx2.initialValue != null) {
986
- ctx2.value = ctx2.initialValue;
992
+ trackFormControlState(ctx2) {
993
+ return trackFormControl(dom.getInputEl(ctx2), {
994
+ onFieldsetDisabled() {
995
+ ctx2.disabled = true;
996
+ },
997
+ onFormReset() {
998
+ if (ctx2.initialValue != null) {
999
+ ctx2.value = ctx2.initialValue;
1000
+ }
987
1001
  }
988
1002
  });
989
1003
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/slider",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Core logic for the slider widget implemented as a state machine",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@zag-js/dom-utils": "0.2.1",
38
- "@zag-js/form-utils": "0.2.1",
38
+ "@zag-js/form-utils": "0.2.2",
39
39
  "@zag-js/utils": "0.3.1",
40
40
  "@zag-js/number-utils": "0.2.0"
41
41
  },