@plasmicapp/react-web 0.2.158 → 0.2.160
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 +11 -4
- package/dist/react-web.cjs.development.js +82 -24
- package/dist/react-web.cjs.development.js.map +1 -1
- package/dist/react-web.cjs.production.min.js +1 -1
- package/dist/react-web.cjs.production.min.js.map +1 -1
- package/dist/react-web.esm.js +82 -24
- package/dist/react-web.esm.js.map +1 -1
- package/dist/states/types.d.ts +11 -1
- package/dist/states/valtio.d.ts +1 -3
- package/dist/stories/UseDollarState.stories.d.ts +3 -0
- package/package.json +4 -4
- package/skinny/dist/index.js +76 -22
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/states/types.d.ts +11 -1
- package/skinny/dist/states/valtio.d.ts +1 -3
- package/skinny/dist/stories/UseDollarState.stories.d.ts +3 -0
package/dist/react-web.esm.js
CHANGED
|
@@ -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,23 @@ 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(
|
|
2639
|
+
var newValue = 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))(
|
|
2645
|
+
var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))(_extends({
|
|
2646
|
+
$state: $state
|
|
2647
|
+
}, $$state.env));
|
|
2644
2648
|
initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
|
|
2645
2649
|
var initialSpec = initialSpecNode.getSpec();
|
|
2646
2650
|
var value = initialSpec.isImmutable ? mkUntrackedValue(initialValue) : clone(initialValue);
|
|
2647
2651
|
set(proxyRoot, initialStatePath, value);
|
|
2648
2652
|
//immediately fire onChange
|
|
2649
2653
|
if (initialSpec.onChangeProp) {
|
|
2650
|
-
var _$$state$props$
|
|
2651
|
-
(_$$state$props$
|
|
2654
|
+
var _$$state$env$$props$i, _$$state$env$$props;
|
|
2655
|
+
(_$$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
2656
|
}
|
|
2653
2657
|
return initialValue;
|
|
2654
2658
|
}
|
|
@@ -2666,11 +2670,11 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
2666
2670
|
}
|
|
2667
2671
|
delete _get($$state.stateValues, currPath)[property];
|
|
2668
2672
|
if (spec.onChangeProp) {
|
|
2669
|
-
var _$$state$props$
|
|
2673
|
+
var _$$state$env$$props$s, _$$state$env$$props2;
|
|
2670
2674
|
//we are always in a leaf, since we only have two cases:
|
|
2671
2675
|
// 1 - delete properties outside the state tree
|
|
2672
2676
|
// 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
|
|
2673
|
-
(_$$state$props$
|
|
2677
|
+
(_$$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
2678
|
}
|
|
2675
2679
|
var nextPath = getNextPath(property);
|
|
2676
2680
|
var nextNode = currNode.makeTransition(property);
|
|
@@ -2734,12 +2738,19 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
2734
2738
|
} else {
|
|
2735
2739
|
Reflect.set(target, property, value, receiver);
|
|
2736
2740
|
}
|
|
2737
|
-
|
|
2741
|
+
if (currNode.isLeaf()) {
|
|
2738
2742
|
if (spec.onChangeProp) {
|
|
2739
|
-
var _$$state$props$
|
|
2740
|
-
(_$$state$props$
|
|
2743
|
+
var _$$state$env$$props$s2, _$$state$env$$props3;
|
|
2744
|
+
(_$$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
2745
|
}
|
|
2742
|
-
}
|
|
2746
|
+
} else {
|
|
2747
|
+
nextNode.getAllSpecs().forEach(function (spec) {
|
|
2748
|
+
if (spec.onChangeProp) {
|
|
2749
|
+
var _$$state$env$$props$s3, _$$state$env$$props4;
|
|
2750
|
+
(_$$state$env$$props$s3 = (_$$state$env$$props4 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s3.call(_$$state$env$$props4, value);
|
|
2751
|
+
}
|
|
2752
|
+
});
|
|
2753
|
+
}
|
|
2743
2754
|
var newValue = (isOutside || currNode.isLeaf()) && currNode.getSpec().isImmutable ? mkUntrackedValue(value) : value;
|
|
2744
2755
|
set($$state.stateValues, nextPath, newValue);
|
|
2745
2756
|
return true;
|
|
@@ -2767,22 +2778,65 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
2767
2778
|
var mkUntrackedValue = function mkUntrackedValue(o) {
|
|
2768
2779
|
return o != null && typeof o === "object" ? ref(o) : o;
|
|
2769
2780
|
};
|
|
2770
|
-
|
|
2781
|
+
var envFieldsAreNonNill = function envFieldsAreNonNill(env) {
|
|
2782
|
+
var _env$$ctx, _env$$queries;
|
|
2783
|
+
return {
|
|
2784
|
+
$props: env.$props,
|
|
2785
|
+
$ctx: (_env$$ctx = env.$ctx) != null ? _env$$ctx : {},
|
|
2786
|
+
$queries: (_env$$queries = env.$queries) != null ? _env$$queries : {}
|
|
2787
|
+
};
|
|
2788
|
+
};
|
|
2789
|
+
/**
|
|
2790
|
+
* We need to support two versions with different parameters to be backward compatible
|
|
2791
|
+
* {
|
|
2792
|
+
* specs: $StateSpec<any>[],
|
|
2793
|
+
* props: Record<string, any>,
|
|
2794
|
+
* $ctx?: Record<string, any>,
|
|
2795
|
+
* opts?: { inCanvas: boolean; }
|
|
2796
|
+
* }
|
|
2797
|
+
* {
|
|
2798
|
+
* specs: $StateSpec<any>[],
|
|
2799
|
+
* env: { $props; $queries; $ctx },
|
|
2800
|
+
* opts?: { inCanvas: boolean }
|
|
2801
|
+
* }
|
|
2802
|
+
*/
|
|
2803
|
+
function extractDollarStateParametersBackwardCompatible() {
|
|
2804
|
+
if ("$props" in (arguments.length <= 0 ? undefined : arguments[0])) {
|
|
2805
|
+
// latest version
|
|
2806
|
+
return {
|
|
2807
|
+
env: arguments.length <= 0 ? undefined : arguments[0],
|
|
2808
|
+
opts: arguments.length <= 1 ? undefined : arguments[1]
|
|
2809
|
+
};
|
|
2810
|
+
} else {
|
|
2811
|
+
return {
|
|
2812
|
+
env: {
|
|
2813
|
+
$props: arguments.length <= 0 ? undefined : arguments[0],
|
|
2814
|
+
$ctx: arguments.length <= 1 ? undefined : arguments[1],
|
|
2815
|
+
$queries: {}
|
|
2816
|
+
},
|
|
2817
|
+
opts: arguments.length <= 2 ? undefined : arguments[2]
|
|
2818
|
+
};
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
function useDollarState(specs) {
|
|
2822
|
+
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
2823
|
+
rest[_key - 1] = arguments[_key];
|
|
2824
|
+
}
|
|
2825
|
+
var _extractDollarStatePa = extractDollarStateParametersBackwardCompatible.apply(void 0, rest),
|
|
2826
|
+
env = _extractDollarStatePa.env,
|
|
2827
|
+
opts = _extractDollarStatePa.opts;
|
|
2771
2828
|
var $$state = React__default.useRef(function () {
|
|
2772
2829
|
var rootSpecTree = buildTree(specs);
|
|
2773
2830
|
return {
|
|
2774
2831
|
rootSpecTree: rootSpecTree,
|
|
2775
2832
|
specTreeLeaves: getStateCells(rootSpecTree),
|
|
2776
2833
|
stateValues: proxy({}),
|
|
2777
|
-
|
|
2778
|
-
ctx: {},
|
|
2834
|
+
env: envFieldsAreNonNill(env),
|
|
2779
2835
|
specs: [],
|
|
2780
2836
|
registrationsQueue: proxy([])
|
|
2781
2837
|
};
|
|
2782
2838
|
}()).current;
|
|
2783
|
-
$$state.
|
|
2784
|
-
$$state.ctx = $ctx != null ? $ctx : {};
|
|
2785
|
-
$$state.specs = specs;
|
|
2839
|
+
$$state.env = envFieldsAreNonNill(env), $$state.specs = specs;
|
|
2786
2840
|
var create$State = function create$State() {
|
|
2787
2841
|
var $state = Object.assign(create$StateProxy($$state, function (node, path) {
|
|
2788
2842
|
if (!node.hasState(path)) {
|
|
@@ -2798,7 +2852,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2798
2852
|
get: function get(target, property, receiver) {
|
|
2799
2853
|
var spec = node.getSpec();
|
|
2800
2854
|
if (spec.valueProp) {
|
|
2801
|
-
return $$state.props[spec.valueProp];
|
|
2855
|
+
return $$state.env.$props[spec.valueProp];
|
|
2802
2856
|
} else {
|
|
2803
2857
|
return Reflect.get(target, property, receiver);
|
|
2804
2858
|
}
|
|
@@ -2812,7 +2866,9 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2812
2866
|
if (!node.hasState(realPath)) {
|
|
2813
2867
|
node.createStateCell(realPath);
|
|
2814
2868
|
}
|
|
2815
|
-
if (!deepEqual(node.getState(realPath).initialValue, f(
|
|
2869
|
+
if (!deepEqual(node.getState(realPath).initialValue, f(_extends({
|
|
2870
|
+
$state: $state
|
|
2871
|
+
}, $$state.env)))) {
|
|
2816
2872
|
$$state.registrationsQueue.push(mkUntrackedValue({
|
|
2817
2873
|
node: node,
|
|
2818
2874
|
path: realPath,
|
|
@@ -2849,7 +2905,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2849
2905
|
return;
|
|
2850
2906
|
}
|
|
2851
2907
|
node.createStateCell(spec.pathObj);
|
|
2852
|
-
var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, node, spec.pathObj, $state) : spec.initVal;
|
|
2908
|
+
var init = spec.valueProp ? $$state.env.$props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, node, spec.pathObj, $state) : spec.initVal;
|
|
2853
2909
|
set($state, spec.pathObj, init);
|
|
2854
2910
|
});
|
|
2855
2911
|
}
|
|
@@ -2868,7 +2924,9 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2868
2924
|
stateCell = _ref3.stateCell;
|
|
2869
2925
|
var initFunc = node.getInitFunc(stateCell);
|
|
2870
2926
|
if (initFunc) {
|
|
2871
|
-
var newInit = initFunc(
|
|
2927
|
+
var newInit = initFunc(_extends({
|
|
2928
|
+
$state: $state
|
|
2929
|
+
}, envFieldsAreNonNill(env)));
|
|
2872
2930
|
if (!deepEqual(newInit, stateCell.initialValue)) {
|
|
2873
2931
|
resetSpecs.push({
|
|
2874
2932
|
stateCell: stateCell,
|
|
@@ -2881,8 +2939,8 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2881
2939
|
var newInit = initializeStateValue($$state, node, stateCell.path, $state);
|
|
2882
2940
|
var spec = node.getSpec();
|
|
2883
2941
|
if (spec.onChangeProp) {
|
|
2884
|
-
var _$$state$props$
|
|
2885
|
-
(_$$state$props$
|
|
2942
|
+
var _$$state$env$$props$s4, _$$state$env$$props5;
|
|
2943
|
+
(_$$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
2944
|
}
|
|
2887
2945
|
};
|
|
2888
2946
|
useIsomorphicLayoutEffect$1(function () {
|
|
@@ -2891,7 +2949,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2891
2949
|
node = _ref4.node;
|
|
2892
2950
|
reInitializeState(node, stateCell);
|
|
2893
2951
|
});
|
|
2894
|
-
}, [props, resetSpecs]);
|
|
2952
|
+
}, [env.$props, resetSpecs]);
|
|
2895
2953
|
useIsomorphicLayoutEffect$1(function () {
|
|
2896
2954
|
while ($$state.registrationsQueue.length) {
|
|
2897
2955
|
var _$$state$registration = $$state.registrationsQueue.shift(),
|