@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.
- package/dist/all.d.ts +11 -4
- package/dist/react-web.cjs.development.js +90 -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 +90 -24
- package/dist/react-web.esm.js.map +1 -1
- package/dist/states/types.d.ts +12 -1
- package/dist/states/valtio.d.ts +1 -3
- package/dist/stories/UseDollarState.stories.d.ts +3 -0
- package/package.json +3 -3
- package/skinny/dist/index.js +85 -22
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/states/types.d.ts +12 -1
- package/skinny/dist/states/valtio.d.ts +1 -3
- package/skinny/dist/stories/UseDollarState.stories.d.ts +3 -0
package/dist/all.d.ts
CHANGED
|
@@ -36,7 +36,16 @@ 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
|
|
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 NoUndefinedField<T> = {
|
|
46
|
+
[P in keyof T]-?: T[P];
|
|
47
|
+
};
|
|
48
|
+
declare type InitFunc<T> = (env: NoUndefinedField<InitFuncEnv>) => T;
|
|
40
49
|
declare type ObjectPath = (string | number)[];
|
|
41
50
|
interface $StateSpec<T> {
|
|
42
51
|
path: string;
|
|
@@ -74,9 +83,7 @@ declare function getStateSpecInPlasmicProxy(obj: any, path: ObjectPath): {
|
|
|
74
83
|
*/
|
|
75
84
|
declare function set(obj: any, keys: any, val: any): void;
|
|
76
85
|
|
|
77
|
-
declare function useDollarState(specs: $StateSpec<any>[],
|
|
78
|
-
inCanvas: boolean;
|
|
79
|
-
}): $State;
|
|
86
|
+
declare function useDollarState(specs: $StateSpec<any>[], ...rest: any[]): $State;
|
|
80
87
|
|
|
81
88
|
interface Variants {
|
|
82
89
|
[vg: string]: any;
|
|
@@ -2625,7 +2625,7 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
|
|
|
2625
2625
|
});
|
|
2626
2626
|
var spec = node.getSpec();
|
|
2627
2627
|
if (spec.valueProp) {
|
|
2628
|
-
return $$state.props[spec.valueProp];
|
|
2628
|
+
return $$state.env.$props[spec.valueProp];
|
|
2629
2629
|
} else if (!node.hasState(path) && spec.initFunc) {
|
|
2630
2630
|
node.createStateCell(path);
|
|
2631
2631
|
return initializeStateValue($$state, node, path, proxyRoot);
|
|
@@ -2641,19 +2641,24 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
|
|
|
2641
2641
|
var node = _ref.node,
|
|
2642
2642
|
path = _ref.path;
|
|
2643
2643
|
node.addListener(path, function () {
|
|
2644
|
-
var newValue = initialSpecNode.getSpec().initFunc
|
|
2644
|
+
var newValue = invokeInitFuncBackwardsCompatible(initialSpecNode.getSpec().initFunc, _extends({
|
|
2645
|
+
$state: $state
|
|
2646
|
+
}, $$state.env));
|
|
2645
2647
|
set(proxyRoot, initialStatePath, newValue);
|
|
2646
2648
|
});
|
|
2647
2649
|
});
|
|
2648
|
-
var
|
|
2650
|
+
var initFunc = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath));
|
|
2651
|
+
var initialValue = invokeInitFuncBackwardsCompatible(initFunc, _extends({
|
|
2652
|
+
$state: $state
|
|
2653
|
+
}, $$state.env));
|
|
2649
2654
|
initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
|
|
2650
2655
|
var initialSpec = initialSpecNode.getSpec();
|
|
2651
2656
|
var value = initialSpec.isImmutable ? mkUntrackedValue(initialValue) : clone(initialValue);
|
|
2652
2657
|
set(proxyRoot, initialStatePath, value);
|
|
2653
2658
|
//immediately fire onChange
|
|
2654
2659
|
if (initialSpec.onChangeProp) {
|
|
2655
|
-
var _$$state$props$
|
|
2656
|
-
(_$$state$props$
|
|
2660
|
+
var _$$state$env$$props$i, _$$state$env$$props;
|
|
2661
|
+
(_$$state$env$$props$i = (_$$state$env$$props = $$state.env.$props)[initialSpec.onChangeProp]) == null ? void 0 : _$$state$env$$props$i.call(_$$state$env$$props, initialValue);
|
|
2657
2662
|
}
|
|
2658
2663
|
return initialValue;
|
|
2659
2664
|
}
|
|
@@ -2671,11 +2676,11 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
2671
2676
|
}
|
|
2672
2677
|
delete _get($$state.stateValues, currPath)[property];
|
|
2673
2678
|
if (spec.onChangeProp) {
|
|
2674
|
-
var _$$state$props$
|
|
2679
|
+
var _$$state$env$$props$s, _$$state$env$$props2;
|
|
2675
2680
|
//we are always in a leaf, since we only have two cases:
|
|
2676
2681
|
// 1 - delete properties outside the state tree
|
|
2677
2682
|
// 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
|
|
2678
|
-
(_$$state$props$
|
|
2683
|
+
(_$$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)));
|
|
2679
2684
|
}
|
|
2680
2685
|
var nextPath = getNextPath(property);
|
|
2681
2686
|
var nextNode = currNode.makeTransition(property);
|
|
@@ -2739,12 +2744,19 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
2739
2744
|
} else {
|
|
2740
2745
|
Reflect.set(target, property, value, receiver);
|
|
2741
2746
|
}
|
|
2742
|
-
|
|
2747
|
+
if (currNode.isLeaf()) {
|
|
2743
2748
|
if (spec.onChangeProp) {
|
|
2744
|
-
var _$$state$props$
|
|
2745
|
-
(_$$state$props$
|
|
2749
|
+
var _$$state$env$$props$s2, _$$state$env$$props3;
|
|
2750
|
+
(_$$state$env$$props$s2 = (_$$state$env$$props3 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s2.call(_$$state$env$$props3, target);
|
|
2746
2751
|
}
|
|
2747
|
-
}
|
|
2752
|
+
} else {
|
|
2753
|
+
nextNode.getAllSpecs().forEach(function (spec) {
|
|
2754
|
+
if (spec.onChangeProp) {
|
|
2755
|
+
var _$$state$env$$props$s3, _$$state$env$$props4;
|
|
2756
|
+
(_$$state$env$$props$s3 = (_$$state$env$$props4 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s3.call(_$$state$env$$props4, value);
|
|
2757
|
+
}
|
|
2758
|
+
});
|
|
2759
|
+
}
|
|
2748
2760
|
var newValue = (isOutside || currNode.isLeaf()) && currNode.getSpec().isImmutable ? mkUntrackedValue(value) : value;
|
|
2749
2761
|
set($$state.stateValues, nextPath, newValue);
|
|
2750
2762
|
return true;
|
|
@@ -2772,22 +2784,72 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
2772
2784
|
var mkUntrackedValue = function mkUntrackedValue(o) {
|
|
2773
2785
|
return o != null && typeof o === "object" ? valtio.ref(o) : o;
|
|
2774
2786
|
};
|
|
2775
|
-
|
|
2787
|
+
var envFieldsAreNonNill = function envFieldsAreNonNill(env) {
|
|
2788
|
+
var _env$$ctx, _env$$queries;
|
|
2789
|
+
return {
|
|
2790
|
+
$props: env.$props,
|
|
2791
|
+
$ctx: (_env$$ctx = env.$ctx) != null ? _env$$ctx : {},
|
|
2792
|
+
$queries: (_env$$queries = env.$queries) != null ? _env$$queries : {}
|
|
2793
|
+
};
|
|
2794
|
+
};
|
|
2795
|
+
/**
|
|
2796
|
+
* We need to support two versions with different parameters to be backward compatible
|
|
2797
|
+
* {
|
|
2798
|
+
* specs: $StateSpec<any>[],
|
|
2799
|
+
* props: Record<string, any>,
|
|
2800
|
+
* $ctx?: Record<string, any>,
|
|
2801
|
+
* opts?: { inCanvas: boolean; }
|
|
2802
|
+
* }
|
|
2803
|
+
* {
|
|
2804
|
+
* specs: $StateSpec<any>[],
|
|
2805
|
+
* env: { $props; $queries; $ctx },
|
|
2806
|
+
* opts?: { inCanvas: boolean }
|
|
2807
|
+
* }
|
|
2808
|
+
*/
|
|
2809
|
+
function extractDollarStateParametersBackwardCompatible() {
|
|
2810
|
+
if ("$props" in (arguments.length <= 0 ? undefined : arguments[0])) {
|
|
2811
|
+
// latest version
|
|
2812
|
+
return {
|
|
2813
|
+
env: arguments.length <= 0 ? undefined : arguments[0],
|
|
2814
|
+
opts: arguments.length <= 1 ? undefined : arguments[1]
|
|
2815
|
+
};
|
|
2816
|
+
} else {
|
|
2817
|
+
return {
|
|
2818
|
+
env: {
|
|
2819
|
+
$props: arguments.length <= 0 ? undefined : arguments[0],
|
|
2820
|
+
$ctx: arguments.length <= 1 ? undefined : arguments[1],
|
|
2821
|
+
$queries: {}
|
|
2822
|
+
},
|
|
2823
|
+
opts: arguments.length <= 2 ? undefined : arguments[2]
|
|
2824
|
+
};
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
function invokeInitFuncBackwardsCompatible(initFunc, env) {
|
|
2828
|
+
if (initFunc.length > 1) {
|
|
2829
|
+
return initFunc(env.$props, env.$state, env.$ctx);
|
|
2830
|
+
} else {
|
|
2831
|
+
return initFunc(env);
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2834
|
+
function useDollarState(specs) {
|
|
2835
|
+
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
2836
|
+
rest[_key - 1] = arguments[_key];
|
|
2837
|
+
}
|
|
2838
|
+
var _extractDollarStatePa = extractDollarStateParametersBackwardCompatible.apply(void 0, rest),
|
|
2839
|
+
env = _extractDollarStatePa.env,
|
|
2840
|
+
opts = _extractDollarStatePa.opts;
|
|
2776
2841
|
var $$state = React__default.useRef(function () {
|
|
2777
2842
|
var rootSpecTree = buildTree(specs);
|
|
2778
2843
|
return {
|
|
2779
2844
|
rootSpecTree: rootSpecTree,
|
|
2780
2845
|
specTreeLeaves: getStateCells(rootSpecTree),
|
|
2781
2846
|
stateValues: valtio.proxy({}),
|
|
2782
|
-
|
|
2783
|
-
ctx: {},
|
|
2847
|
+
env: envFieldsAreNonNill(env),
|
|
2784
2848
|
specs: [],
|
|
2785
2849
|
registrationsQueue: valtio.proxy([])
|
|
2786
2850
|
};
|
|
2787
2851
|
}()).current;
|
|
2788
|
-
$$state.
|
|
2789
|
-
$$state.ctx = $ctx != null ? $ctx : {};
|
|
2790
|
-
$$state.specs = specs;
|
|
2852
|
+
$$state.env = envFieldsAreNonNill(env), $$state.specs = specs;
|
|
2791
2853
|
var create$State = function create$State() {
|
|
2792
2854
|
var $state = Object.assign(create$StateProxy($$state, function (node, path) {
|
|
2793
2855
|
if (!node.hasState(path)) {
|
|
@@ -2803,7 +2865,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2803
2865
|
get: function get(target, property, receiver) {
|
|
2804
2866
|
var spec = node.getSpec();
|
|
2805
2867
|
if (spec.valueProp) {
|
|
2806
|
-
return $$state.props[spec.valueProp];
|
|
2868
|
+
return $$state.env.$props[spec.valueProp];
|
|
2807
2869
|
} else {
|
|
2808
2870
|
return Reflect.get(target, property, receiver);
|
|
2809
2871
|
}
|
|
@@ -2817,7 +2879,9 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2817
2879
|
if (!node.hasState(realPath)) {
|
|
2818
2880
|
node.createStateCell(realPath);
|
|
2819
2881
|
}
|
|
2820
|
-
if (!deepEqual(node.getState(realPath).initialValue, f(
|
|
2882
|
+
if (!deepEqual(node.getState(realPath).initialValue, f(_extends({
|
|
2883
|
+
$state: $state
|
|
2884
|
+
}, $$state.env)))) {
|
|
2821
2885
|
$$state.registrationsQueue.push(mkUntrackedValue({
|
|
2822
2886
|
node: node,
|
|
2823
2887
|
path: realPath,
|
|
@@ -2854,7 +2918,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2854
2918
|
return;
|
|
2855
2919
|
}
|
|
2856
2920
|
node.createStateCell(spec.pathObj);
|
|
2857
|
-
var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, node, spec.pathObj, $state) : spec.initVal;
|
|
2921
|
+
var init = spec.valueProp ? $$state.env.$props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, node, spec.pathObj, $state) : spec.initVal;
|
|
2858
2922
|
set($state, spec.pathObj, init);
|
|
2859
2923
|
});
|
|
2860
2924
|
}
|
|
@@ -2873,7 +2937,9 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2873
2937
|
stateCell = _ref3.stateCell;
|
|
2874
2938
|
var initFunc = node.getInitFunc(stateCell);
|
|
2875
2939
|
if (initFunc) {
|
|
2876
|
-
var newInit = initFunc
|
|
2940
|
+
var newInit = invokeInitFuncBackwardsCompatible(initFunc, _extends({
|
|
2941
|
+
$state: $state
|
|
2942
|
+
}, envFieldsAreNonNill(env)));
|
|
2877
2943
|
if (!deepEqual(newInit, stateCell.initialValue)) {
|
|
2878
2944
|
resetSpecs.push({
|
|
2879
2945
|
stateCell: stateCell,
|
|
@@ -2886,8 +2952,8 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2886
2952
|
var newInit = initializeStateValue($$state, node, stateCell.path, $state);
|
|
2887
2953
|
var spec = node.getSpec();
|
|
2888
2954
|
if (spec.onChangeProp) {
|
|
2889
|
-
var _$$state$props$
|
|
2890
|
-
(_$$state$props$
|
|
2955
|
+
var _$$state$env$$props$s4, _$$state$env$$props5;
|
|
2956
|
+
(_$$state$env$$props$s4 = (_$$state$env$$props5 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s4.call(_$$state$env$$props5, newInit);
|
|
2891
2957
|
}
|
|
2892
2958
|
};
|
|
2893
2959
|
useIsomorphicLayoutEffect$1(function () {
|
|
@@ -2896,7 +2962,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2896
2962
|
node = _ref4.node;
|
|
2897
2963
|
reInitializeState(node, stateCell);
|
|
2898
2964
|
});
|
|
2899
|
-
}, [props, resetSpecs]);
|
|
2965
|
+
}, [env.$props, resetSpecs]);
|
|
2900
2966
|
useIsomorphicLayoutEffect$1(function () {
|
|
2901
2967
|
while ($$state.registrationsQueue.length) {
|
|
2902
2968
|
var _$$state$registration = $$state.registrationsQueue.shift(),
|