@plasmicapp/react-web 0.2.159 → 0.2.161

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.
@@ -2620,7 +2620,7 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
2620
2620
  });
2621
2621
  var spec = node.getSpec();
2622
2622
  if (spec.valueProp) {
2623
- return $$state.props[spec.valueProp];
2623
+ return $$state.env.$props[spec.valueProp];
2624
2624
  } else if (!node.hasState(path) && spec.initFunc) {
2625
2625
  node.createStateCell(path);
2626
2626
  return initializeStateValue($$state, node, path, proxyRoot);
@@ -2636,19 +2636,24 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
2636
2636
  var node = _ref.node,
2637
2637
  path = _ref.path;
2638
2638
  node.addListener(path, function () {
2639
- var newValue = initialSpecNode.getSpec().initFunc($$state.props, $state, $$state.ctx);
2639
+ var newValue = invokeInitFuncBackwardsCompatible(initialSpecNode.getSpec().initFunc, _extends({
2640
+ $state: $state
2641
+ }, $$state.env));
2640
2642
  set(proxyRoot, initialStatePath, newValue);
2641
2643
  });
2642
2644
  });
2643
- var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))($$state.props, $state, $$state.ctx);
2645
+ var initFunc = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath));
2646
+ var initialValue = invokeInitFuncBackwardsCompatible(initFunc, _extends({
2647
+ $state: $state
2648
+ }, $$state.env));
2644
2649
  initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
2645
2650
  var initialSpec = initialSpecNode.getSpec();
2646
2651
  var value = initialSpec.isImmutable ? mkUntrackedValue(initialValue) : clone(initialValue);
2647
2652
  set(proxyRoot, initialStatePath, value);
2648
2653
  //immediately fire onChange
2649
2654
  if (initialSpec.onChangeProp) {
2650
- var _$$state$props$initia, _$$state$props;
2651
- (_$$state$props$initia = (_$$state$props = $$state.props)[initialSpec.onChangeProp]) == null ? void 0 : _$$state$props$initia.call(_$$state$props, initialValue);
2655
+ var _$$state$env$$props$i, _$$state$env$$props;
2656
+ (_$$state$env$$props$i = (_$$state$env$$props = $$state.env.$props)[initialSpec.onChangeProp]) == null ? void 0 : _$$state$env$$props$i.call(_$$state$env$$props, initialValue);
2652
2657
  }
2653
2658
  return initialValue;
2654
2659
  }
@@ -2666,11 +2671,11 @@ function create$StateProxy($$state, leafHandlers) {
2666
2671
  }
2667
2672
  delete _get($$state.stateValues, currPath)[property];
2668
2673
  if (spec.onChangeProp) {
2669
- var _$$state$props$spec$o, _$$state$props2;
2674
+ var _$$state$env$$props$s, _$$state$env$$props2;
2670
2675
  //we are always in a leaf, since we only have two cases:
2671
2676
  // 1 - delete properties outside the state tree
2672
2677
  // 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
2673
- (_$$state$props$spec$o = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o.call(_$$state$props2, _get(proxyRoot, currPath.slice(spec.pathObj.length)));
2678
+ (_$$state$env$$props$s = (_$$state$env$$props2 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s.call(_$$state$env$$props2, _get(proxyRoot, currPath.slice(spec.pathObj.length)));
2674
2679
  }
2675
2680
  var nextPath = getNextPath(property);
2676
2681
  var nextNode = currNode.makeTransition(property);
@@ -2734,12 +2739,19 @@ function create$StateProxy($$state, leafHandlers) {
2734
2739
  } else {
2735
2740
  Reflect.set(target, property, value, receiver);
2736
2741
  }
2737
- nextNode.getAllSpecs().forEach(function (spec) {
2742
+ if (currNode.isLeaf()) {
2738
2743
  if (spec.onChangeProp) {
2739
- var _$$state$props$spec$o2, _$$state$props3;
2740
- (_$$state$props$spec$o2 = (_$$state$props3 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props3, value);
2744
+ var _$$state$env$$props$s2, _$$state$env$$props3;
2745
+ (_$$state$env$$props$s2 = (_$$state$env$$props3 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s2.call(_$$state$env$$props3, target);
2741
2746
  }
2742
- });
2747
+ } else {
2748
+ nextNode.getAllSpecs().forEach(function (spec) {
2749
+ if (spec.onChangeProp) {
2750
+ var _$$state$env$$props$s3, _$$state$env$$props4;
2751
+ (_$$state$env$$props$s3 = (_$$state$env$$props4 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s3.call(_$$state$env$$props4, value);
2752
+ }
2753
+ });
2754
+ }
2743
2755
  var newValue = (isOutside || currNode.isLeaf()) && currNode.getSpec().isImmutable ? mkUntrackedValue(value) : value;
2744
2756
  set($$state.stateValues, nextPath, newValue);
2745
2757
  return true;
@@ -2767,22 +2779,72 @@ function create$StateProxy($$state, leafHandlers) {
2767
2779
  var mkUntrackedValue = function mkUntrackedValue(o) {
2768
2780
  return o != null && typeof o === "object" ? ref(o) : o;
2769
2781
  };
2770
- function useDollarState(specs, props, $ctx, opts) {
2782
+ var envFieldsAreNonNill = function envFieldsAreNonNill(env) {
2783
+ var _env$$ctx, _env$$queries;
2784
+ return {
2785
+ $props: env.$props,
2786
+ $ctx: (_env$$ctx = env.$ctx) != null ? _env$$ctx : {},
2787
+ $queries: (_env$$queries = env.$queries) != null ? _env$$queries : {}
2788
+ };
2789
+ };
2790
+ /**
2791
+ * We need to support two versions with different parameters to be backward compatible
2792
+ * {
2793
+ * specs: $StateSpec<any>[],
2794
+ * props: Record<string, any>,
2795
+ * $ctx?: Record<string, any>,
2796
+ * opts?: { inCanvas: boolean; }
2797
+ * }
2798
+ * {
2799
+ * specs: $StateSpec<any>[],
2800
+ * env: { $props; $queries; $ctx },
2801
+ * opts?: { inCanvas: boolean }
2802
+ * }
2803
+ */
2804
+ function extractDollarStateParametersBackwardCompatible() {
2805
+ if ("$props" in (arguments.length <= 0 ? undefined : arguments[0])) {
2806
+ // latest version
2807
+ return {
2808
+ env: arguments.length <= 0 ? undefined : arguments[0],
2809
+ opts: arguments.length <= 1 ? undefined : arguments[1]
2810
+ };
2811
+ } else {
2812
+ return {
2813
+ env: {
2814
+ $props: arguments.length <= 0 ? undefined : arguments[0],
2815
+ $ctx: arguments.length <= 1 ? undefined : arguments[1],
2816
+ $queries: {}
2817
+ },
2818
+ opts: arguments.length <= 2 ? undefined : arguments[2]
2819
+ };
2820
+ }
2821
+ }
2822
+ function invokeInitFuncBackwardsCompatible(initFunc, env) {
2823
+ if (initFunc.length > 1) {
2824
+ return initFunc(env.$props, env.$state, env.$ctx);
2825
+ } else {
2826
+ return initFunc(env);
2827
+ }
2828
+ }
2829
+ function useDollarState(specs) {
2830
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2831
+ rest[_key - 1] = arguments[_key];
2832
+ }
2833
+ var _extractDollarStatePa = extractDollarStateParametersBackwardCompatible.apply(void 0, rest),
2834
+ env = _extractDollarStatePa.env,
2835
+ opts = _extractDollarStatePa.opts;
2771
2836
  var $$state = React__default.useRef(function () {
2772
2837
  var rootSpecTree = buildTree(specs);
2773
2838
  return {
2774
2839
  rootSpecTree: rootSpecTree,
2775
2840
  specTreeLeaves: getStateCells(rootSpecTree),
2776
2841
  stateValues: proxy({}),
2777
- props: {},
2778
- ctx: {},
2842
+ env: envFieldsAreNonNill(env),
2779
2843
  specs: [],
2780
2844
  registrationsQueue: proxy([])
2781
2845
  };
2782
2846
  }()).current;
2783
- $$state.props = props;
2784
- $$state.ctx = $ctx != null ? $ctx : {};
2785
- $$state.specs = specs;
2847
+ $$state.env = envFieldsAreNonNill(env), $$state.specs = specs;
2786
2848
  var create$State = function create$State() {
2787
2849
  var $state = Object.assign(create$StateProxy($$state, function (node, path) {
2788
2850
  if (!node.hasState(path)) {
@@ -2798,7 +2860,7 @@ function useDollarState(specs, props, $ctx, opts) {
2798
2860
  get: function get(target, property, receiver) {
2799
2861
  var spec = node.getSpec();
2800
2862
  if (spec.valueProp) {
2801
- return $$state.props[spec.valueProp];
2863
+ return $$state.env.$props[spec.valueProp];
2802
2864
  } else {
2803
2865
  return Reflect.get(target, property, receiver);
2804
2866
  }
@@ -2812,7 +2874,9 @@ function useDollarState(specs, props, $ctx, opts) {
2812
2874
  if (!node.hasState(realPath)) {
2813
2875
  node.createStateCell(realPath);
2814
2876
  }
2815
- if (!deepEqual(node.getState(realPath).initialValue, f($$state.props, $state, $$state.ctx))) {
2877
+ if (!deepEqual(node.getState(realPath).initialValue, f(_extends({
2878
+ $state: $state
2879
+ }, $$state.env)))) {
2816
2880
  $$state.registrationsQueue.push(mkUntrackedValue({
2817
2881
  node: node,
2818
2882
  path: realPath,
@@ -2849,7 +2913,7 @@ function useDollarState(specs, props, $ctx, opts) {
2849
2913
  return;
2850
2914
  }
2851
2915
  node.createStateCell(spec.pathObj);
2852
- var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, node, spec.pathObj, $state) : spec.initVal;
2916
+ var init = spec.valueProp ? $$state.env.$props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, node, spec.pathObj, $state) : spec.initVal;
2853
2917
  set($state, spec.pathObj, init);
2854
2918
  });
2855
2919
  }
@@ -2868,7 +2932,9 @@ function useDollarState(specs, props, $ctx, opts) {
2868
2932
  stateCell = _ref3.stateCell;
2869
2933
  var initFunc = node.getInitFunc(stateCell);
2870
2934
  if (initFunc) {
2871
- var newInit = initFunc(props, $state, $ctx != null ? $ctx : {});
2935
+ var newInit = invokeInitFuncBackwardsCompatible(initFunc, _extends({
2936
+ $state: $state
2937
+ }, envFieldsAreNonNill(env)));
2872
2938
  if (!deepEqual(newInit, stateCell.initialValue)) {
2873
2939
  resetSpecs.push({
2874
2940
  stateCell: stateCell,
@@ -2881,8 +2947,8 @@ function useDollarState(specs, props, $ctx, opts) {
2881
2947
  var newInit = initializeStateValue($$state, node, stateCell.path, $state);
2882
2948
  var spec = node.getSpec();
2883
2949
  if (spec.onChangeProp) {
2884
- var _$$state$props$spec$o3, _$$state$props4;
2885
- (_$$state$props$spec$o3 = (_$$state$props4 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o3.call(_$$state$props4, newInit);
2950
+ var _$$state$env$$props$s4, _$$state$env$$props5;
2951
+ (_$$state$env$$props$s4 = (_$$state$env$$props5 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s4.call(_$$state$env$$props5, newInit);
2886
2952
  }
2887
2953
  };
2888
2954
  useIsomorphicLayoutEffect$1(function () {
@@ -2891,7 +2957,7 @@ function useDollarState(specs, props, $ctx, opts) {
2891
2957
  node = _ref4.node;
2892
2958
  reInitializeState(node, stateCell);
2893
2959
  });
2894
- }, [props, resetSpecs]);
2960
+ }, [env.$props, resetSpecs]);
2895
2961
  useIsomorphicLayoutEffect$1(function () {
2896
2962
  while ($$state.registrationsQueue.length) {
2897
2963
  var _$$state$registration = $$state.registrationsQueue.shift(),