@plasmicapp/react-web 0.2.116 → 0.2.117

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/all.d.ts CHANGED
@@ -35,6 +35,7 @@ interface $StateSpec<T> {
35
35
  type: "private" | "readonly" | "writable";
36
36
  valueProp?: string;
37
37
  onChangeProp?: string;
38
+ isArray?: boolean;
38
39
  }
39
40
  declare function useDollarState(specs: $StateSpec<any>[], props: Record<string, any>): any;
40
41
 
package/dist/index.d.ts CHANGED
@@ -9,5 +9,3 @@ export * from "./plume/select";
9
9
  export * from "./plume/switch";
10
10
  export * from "./plume/text-input";
11
11
  export * from "./plume/triggered-overlay";
12
- export * from "./states/helpers";
13
- export { $State, default as useDollarState, useCanvasDollarState, } from "./states/valtio";
@@ -1982,13 +1982,33 @@ function initializeStateValue($$state, initialStatePath, initialSpec) {
1982
1982
  });
1983
1983
  $$state.unsubscriptionsByState[initialStateKey].push(unsubscribe);
1984
1984
  });
1985
- var untrackedInitialValue = mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(initialStatePath, initialSpec)));
1985
+ var initialValue = initialSpec.initFunc($$state.props, $state, getIndexes(initialStatePath, initialSpec));
1986
+ saveStateInitialValue($$state, initialStatePath, initialSpec, initialValue);
1987
+ return initialValue;
1988
+ }
1989
+
1990
+ function saveStateInitialValue($$state, path, spec, initialValue) {
1991
+ // array states are a special case.Wwe listen for changes in the array and in the array cells.
1992
+ // for example: $state.people.push(...), $state.people.splice(...), $state.people[0] = ...
1993
+ // that's why we need to track the array object
1994
+ if (spec.isArray && Array.isArray(initialValue)) {
1995
+ var array = initialValue.map(function (val) {
1996
+ return mkUntrackedValue(val);
1997
+ });
1998
+
1999
+ set($$state.stateValues, path, array); // we need to make the array untracked for initStateValues
2000
+ // so we can distinguish between stateValue and initStateValue.
2001
+ // otherwise they would reference the same array.
1986
2002
 
1987
- set($$state.initStateValues, initialStatePath, untrackedInitialValue);
1988
2003
 
1989
- set($$state.stateValues, initialStatePath, untrackedInitialValue);
2004
+ set($$state.initStateValues, path, mkUntrackedValue(array));
2005
+ } else {
2006
+ var untrackedValue = mkUntrackedValue(initialValue);
2007
+
2008
+ set($$state.stateValues, path, untrackedValue);
1990
2009
 
1991
- return untrackedInitialValue;
2010
+ set($$state.initStateValues, path, untrackedValue);
2011
+ }
1992
2012
  }
1993
2013
 
1994
2014
  function useDollarState(specs, props) {
@@ -2017,11 +2037,8 @@ function useDollarState(specs, props) {
2017
2037
  var _spec$initVal;
2018
2038
 
2019
2039
  saveNewState($$state, path, spec);
2020
- var untrackedValue = !spec.initFunc ? mkUntrackedValue((_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined) : initializeStateValue($$state, path, spec);
2021
-
2022
- set($$state.stateValues, path, untrackedValue);
2023
-
2024
- set($$state.initStateValues, path, untrackedValue);
2040
+ var initialValue = !spec.initFunc ? (_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined : initializeStateValue($$state, path, spec);
2041
+ saveStateInitialValue($$state, path, spec, initialValue);
2025
2042
  }
2026
2043
 
2027
2044
  return {
@@ -2318,9 +2335,7 @@ function useCheckbox(plasmicClass, props, config, ref) {
2318
2335
  ref: rootRef
2319
2336
  }),
2320
2337
  wrapChildren: function wrapChildren(children) {
2321
- return React.createElement(React.Fragment, null, React.createElement(visuallyHidden.VisuallyHidden, {
2322
- isFocusable: true
2323
- }, React.createElement("input", Object.assign({}, inputProps, {
2338
+ return React.createElement(React.Fragment, null, React.createElement(visuallyHidden.VisuallyHidden, null, React.createElement("input", Object.assign({}, inputProps, {
2324
2339
  ref: inputRef
2325
2340
  }))), children);
2326
2341
  }
@@ -3461,9 +3476,7 @@ function useSwitch(plasmicClass, props, config, ref) {
3461
3476
  ref: rootRef
3462
3477
  }),
3463
3478
  wrapChildren: function wrapChildren(children) {
3464
- return React.createElement(React.Fragment, null, React.createElement(visuallyHidden.VisuallyHidden, {
3465
- isFocusable: true
3466
- }, React.createElement("input", Object.assign({}, inputProps, {
3479
+ return React.createElement(React.Fragment, null, React.createElement(visuallyHidden.VisuallyHidden, null, React.createElement("input", Object.assign({}, inputProps, {
3467
3480
  ref: inputRef
3468
3481
  }))), children);
3469
3482
  }