@plasmicapp/react-web 0.2.157 → 0.2.159

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
@@ -20,7 +20,7 @@ declare function classNames$1(...args: Argument[]): string;
20
20
  interface PlasmicPageGuardProps {
21
21
  appId: string;
22
22
  authorizeEndpoint: string;
23
- minRole: string;
23
+ minRole?: string;
24
24
  canTriggerLogin: boolean;
25
25
  children: React__default.ReactNode;
26
26
  }
@@ -36,17 +36,7 @@ declare type HTMLElementRefOf<T extends keyof JSX.IntrinsicElements> = Exclude<R
36
36
 
37
37
  declare function dlv(object: object, key: string | Array<string | number>, defaultValue?: any): any;
38
38
 
39
- declare type InitFuncEnv = {
40
- $props: Record<string, any>;
41
- $state: Record<string, any>;
42
- $queries?: Record<string, any>;
43
- $ctx?: Record<string, any>;
44
- };
45
- declare type DollarStateEnv = Omit<InitFuncEnv, "$state">;
46
- declare type NoUndefinedField<T> = {
47
- [P in keyof T]-?: T[P];
48
- };
49
- declare type InitFunc<T> = (env: NoUndefinedField<InitFuncEnv>) => T;
39
+ declare type InitFunc<T> = ($props: Record<string, any>, $state: $State, $ctx: Record<string, any>, indexes?: number[]) => T;
50
40
  declare type ObjectPath = (string | number)[];
51
41
  interface $StateSpec<T> {
52
42
  path: string;
@@ -84,7 +74,7 @@ declare function getStateSpecInPlasmicProxy(obj: any, path: ObjectPath): {
84
74
  */
85
75
  declare function set(obj: any, keys: any, val: any): void;
86
76
 
87
- declare function useDollarState(specs: $StateSpec<any>[], env: DollarStateEnv, opts?: {
77
+ declare function useDollarState(specs: $StateSpec<any>[], props: Record<string, any>, $ctx?: Record<string, any>, opts?: {
88
78
  inCanvas: boolean;
89
79
  }): $State;
90
80
 
@@ -2,7 +2,7 @@ import React from "react";
2
2
  interface PlasmicPageGuardProps {
3
3
  appId: string;
4
4
  authorizeEndpoint: string;
5
- minRole: string;
5
+ minRole?: string;
6
6
  canTriggerLogin: boolean;
7
7
  children: React.ReactNode;
8
8
  }
@@ -859,6 +859,9 @@ function PlasmicPageGuard(props) {
859
859
  }
860
860
  }, [dataSourceCtxValue, appId, authorizeEndpoint, canTriggerLogin]);
861
861
  function canUserViewPage() {
862
+ if (!minRole) {
863
+ return true;
864
+ }
862
865
  if (!dataSourceCtxValue) {
863
866
  return false;
864
867
  }
@@ -2622,7 +2625,7 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
2622
2625
  });
2623
2626
  var spec = node.getSpec();
2624
2627
  if (spec.valueProp) {
2625
- return $$state.env.$props[spec.valueProp];
2628
+ return $$state.props[spec.valueProp];
2626
2629
  } else if (!node.hasState(path) && spec.initFunc) {
2627
2630
  node.createStateCell(path);
2628
2631
  return initializeStateValue($$state, node, path, proxyRoot);
@@ -2638,23 +2641,19 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
2638
2641
  var node = _ref.node,
2639
2642
  path = _ref.path;
2640
2643
  node.addListener(path, function () {
2641
- var newValue = initialSpecNode.getSpec().initFunc(_extends({
2642
- $state: $state
2643
- }, $$state.env));
2644
+ var newValue = initialSpecNode.getSpec().initFunc($$state.props, $state, $$state.ctx);
2644
2645
  set(proxyRoot, initialStatePath, newValue);
2645
2646
  });
2646
2647
  });
2647
- var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))(_extends({
2648
- $state: $state
2649
- }, $$state.env));
2648
+ var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))($$state.props, $state, $$state.ctx);
2650
2649
  initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
2651
2650
  var initialSpec = initialSpecNode.getSpec();
2652
2651
  var value = initialSpec.isImmutable ? mkUntrackedValue(initialValue) : clone(initialValue);
2653
2652
  set(proxyRoot, initialStatePath, value);
2654
2653
  //immediately fire onChange
2655
2654
  if (initialSpec.onChangeProp) {
2656
- var _$$state$env$$props$i, _$$state$env$$props;
2657
- (_$$state$env$$props$i = (_$$state$env$$props = $$state.env.$props)[initialSpec.onChangeProp]) == null ? void 0 : _$$state$env$$props$i.call(_$$state$env$$props, initialValue);
2655
+ var _$$state$props$initia, _$$state$props;
2656
+ (_$$state$props$initia = (_$$state$props = $$state.props)[initialSpec.onChangeProp]) == null ? void 0 : _$$state$props$initia.call(_$$state$props, initialValue);
2658
2657
  }
2659
2658
  return initialValue;
2660
2659
  }
@@ -2672,11 +2671,11 @@ function create$StateProxy($$state, leafHandlers) {
2672
2671
  }
2673
2672
  delete _get($$state.stateValues, currPath)[property];
2674
2673
  if (spec.onChangeProp) {
2675
- var _$$state$env$$props$s, _$$state$env$$props2;
2674
+ var _$$state$props$spec$o, _$$state$props2;
2676
2675
  //we are always in a leaf, since we only have two cases:
2677
2676
  // 1 - delete properties outside the state tree
2678
2677
  // 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
2679
- (_$$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)));
2678
+ (_$$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)));
2680
2679
  }
2681
2680
  var nextPath = getNextPath(property);
2682
2681
  var nextNode = currNode.makeTransition(property);
@@ -2740,19 +2739,12 @@ function create$StateProxy($$state, leafHandlers) {
2740
2739
  } else {
2741
2740
  Reflect.set(target, property, value, receiver);
2742
2741
  }
2743
- if (currNode.isLeaf()) {
2742
+ nextNode.getAllSpecs().forEach(function (spec) {
2744
2743
  if (spec.onChangeProp) {
2745
- var _$$state$env$$props$s2, _$$state$env$$props3;
2746
- (_$$state$env$$props$s2 = (_$$state$env$$props3 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s2.call(_$$state$env$$props3, target);
2744
+ var _$$state$props$spec$o2, _$$state$props3;
2745
+ (_$$state$props$spec$o2 = (_$$state$props3 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props3, value);
2747
2746
  }
2748
- } else {
2749
- nextNode.getAllSpecs().forEach(function (spec) {
2750
- if (spec.onChangeProp) {
2751
- var _$$state$env$$props$s3, _$$state$env$$props4;
2752
- (_$$state$env$$props$s3 = (_$$state$env$$props4 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s3.call(_$$state$env$$props4, value);
2753
- }
2754
- });
2755
- }
2747
+ });
2756
2748
  var newValue = (isOutside || currNode.isLeaf()) && currNode.getSpec().isImmutable ? mkUntrackedValue(value) : value;
2757
2749
  set($$state.stateValues, nextPath, newValue);
2758
2750
  return true;
@@ -2780,27 +2772,22 @@ function create$StateProxy($$state, leafHandlers) {
2780
2772
  var mkUntrackedValue = function mkUntrackedValue(o) {
2781
2773
  return o != null && typeof o === "object" ? valtio.ref(o) : o;
2782
2774
  };
2783
- var envFieldsAreNonNill = function envFieldsAreNonNill(env) {
2784
- var _env$$ctx, _env$$queries;
2785
- return {
2786
- $props: env.$props,
2787
- $ctx: (_env$$ctx = env.$ctx) != null ? _env$$ctx : {},
2788
- $queries: (_env$$queries = env.$queries) != null ? _env$$queries : {}
2789
- };
2790
- };
2791
- function useDollarState(specs, env, opts) {
2775
+ function useDollarState(specs, props, $ctx, opts) {
2792
2776
  var $$state = React__default.useRef(function () {
2793
2777
  var rootSpecTree = buildTree(specs);
2794
2778
  return {
2795
2779
  rootSpecTree: rootSpecTree,
2796
2780
  specTreeLeaves: getStateCells(rootSpecTree),
2797
2781
  stateValues: valtio.proxy({}),
2798
- env: envFieldsAreNonNill(env),
2782
+ props: {},
2783
+ ctx: {},
2799
2784
  specs: [],
2800
2785
  registrationsQueue: valtio.proxy([])
2801
2786
  };
2802
2787
  }()).current;
2803
- $$state.env = envFieldsAreNonNill(env), $$state.specs = specs;
2788
+ $$state.props = props;
2789
+ $$state.ctx = $ctx != null ? $ctx : {};
2790
+ $$state.specs = specs;
2804
2791
  var create$State = function create$State() {
2805
2792
  var $state = Object.assign(create$StateProxy($$state, function (node, path) {
2806
2793
  if (!node.hasState(path)) {
@@ -2816,7 +2803,7 @@ function useDollarState(specs, env, opts) {
2816
2803
  get: function get(target, property, receiver) {
2817
2804
  var spec = node.getSpec();
2818
2805
  if (spec.valueProp) {
2819
- return $$state.env.$props[spec.valueProp];
2806
+ return $$state.props[spec.valueProp];
2820
2807
  } else {
2821
2808
  return Reflect.get(target, property, receiver);
2822
2809
  }
@@ -2830,9 +2817,7 @@ function useDollarState(specs, env, opts) {
2830
2817
  if (!node.hasState(realPath)) {
2831
2818
  node.createStateCell(realPath);
2832
2819
  }
2833
- if (!deepEqual(node.getState(realPath).initialValue, f(_extends({
2834
- $state: $state
2835
- }, $$state.env)))) {
2820
+ if (!deepEqual(node.getState(realPath).initialValue, f($$state.props, $state, $$state.ctx))) {
2836
2821
  $$state.registrationsQueue.push(mkUntrackedValue({
2837
2822
  node: node,
2838
2823
  path: realPath,
@@ -2869,7 +2854,7 @@ function useDollarState(specs, env, opts) {
2869
2854
  return;
2870
2855
  }
2871
2856
  node.createStateCell(spec.pathObj);
2872
- var init = spec.valueProp ? $$state.env.$props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, node, spec.pathObj, $state) : spec.initVal;
2857
+ var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, node, spec.pathObj, $state) : spec.initVal;
2873
2858
  set($state, spec.pathObj, init);
2874
2859
  });
2875
2860
  }
@@ -2888,9 +2873,7 @@ function useDollarState(specs, env, opts) {
2888
2873
  stateCell = _ref3.stateCell;
2889
2874
  var initFunc = node.getInitFunc(stateCell);
2890
2875
  if (initFunc) {
2891
- var newInit = initFunc(_extends({
2892
- $state: $state
2893
- }, envFieldsAreNonNill(env)));
2876
+ var newInit = initFunc(props, $state, $ctx != null ? $ctx : {});
2894
2877
  if (!deepEqual(newInit, stateCell.initialValue)) {
2895
2878
  resetSpecs.push({
2896
2879
  stateCell: stateCell,
@@ -2903,8 +2886,8 @@ function useDollarState(specs, env, opts) {
2903
2886
  var newInit = initializeStateValue($$state, node, stateCell.path, $state);
2904
2887
  var spec = node.getSpec();
2905
2888
  if (spec.onChangeProp) {
2906
- var _$$state$env$$props$s4, _$$state$env$$props5;
2907
- (_$$state$env$$props$s4 = (_$$state$env$$props5 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s4.call(_$$state$env$$props5, newInit);
2889
+ var _$$state$props$spec$o3, _$$state$props4;
2890
+ (_$$state$props$spec$o3 = (_$$state$props4 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o3.call(_$$state$props4, newInit);
2908
2891
  }
2909
2892
  };
2910
2893
  useIsomorphicLayoutEffect$1(function () {
@@ -2913,7 +2896,7 @@ function useDollarState(specs, env, opts) {
2913
2896
  node = _ref4.node;
2914
2897
  reInitializeState(node, stateCell);
2915
2898
  });
2916
- }, [env.$props, resetSpecs]);
2899
+ }, [props, resetSpecs]);
2917
2900
  useIsomorphicLayoutEffect$1(function () {
2918
2901
  while ($$state.registrationsQueue.length) {
2919
2902
  var _$$state$registration = $$state.registrationsQueue.shift(),