@plasmicapp/react-web 0.2.156 → 0.2.157
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 +12 -2
- package/dist/react-web.cjs.development.js +44 -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 +44 -24
- package/dist/react-web.esm.js.map +1 -1
- package/dist/states/types.d.ts +11 -1
- package/dist/states/valtio.d.ts +2 -2
- package/dist/stories/UseDollarState.stories.d.ts +3 -0
- package/package.json +4 -4
- package/skinny/dist/index.js +34 -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 +2 -2
- package/skinny/dist/stories/UseDollarState.stories.d.ts +3 -0
package/dist/all.d.ts
CHANGED
|
@@ -36,7 +36,17 @@ 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 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;
|
|
40
50
|
declare type ObjectPath = (string | number)[];
|
|
41
51
|
interface $StateSpec<T> {
|
|
42
52
|
path: string;
|
|
@@ -74,7 +84,7 @@ declare function getStateSpecInPlasmicProxy(obj: any, path: ObjectPath): {
|
|
|
74
84
|
*/
|
|
75
85
|
declare function set(obj: any, keys: any, val: any): void;
|
|
76
86
|
|
|
77
|
-
declare function useDollarState(specs: $StateSpec<any>[],
|
|
87
|
+
declare function useDollarState(specs: $StateSpec<any>[], env: DollarStateEnv, opts?: {
|
|
78
88
|
inCanvas: boolean;
|
|
79
89
|
}): $State;
|
|
80
90
|
|
|
@@ -2622,7 +2622,7 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
|
|
|
2622
2622
|
});
|
|
2623
2623
|
var spec = node.getSpec();
|
|
2624
2624
|
if (spec.valueProp) {
|
|
2625
|
-
return $$state.props[spec.valueProp];
|
|
2625
|
+
return $$state.env.$props[spec.valueProp];
|
|
2626
2626
|
} else if (!node.hasState(path) && spec.initFunc) {
|
|
2627
2627
|
node.createStateCell(path);
|
|
2628
2628
|
return initializeStateValue($$state, node, path, proxyRoot);
|
|
@@ -2638,19 +2638,23 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
|
|
|
2638
2638
|
var node = _ref.node,
|
|
2639
2639
|
path = _ref.path;
|
|
2640
2640
|
node.addListener(path, function () {
|
|
2641
|
-
var newValue = initialSpecNode.getSpec().initFunc(
|
|
2641
|
+
var newValue = initialSpecNode.getSpec().initFunc(_extends({
|
|
2642
|
+
$state: $state
|
|
2643
|
+
}, $$state.env));
|
|
2642
2644
|
set(proxyRoot, initialStatePath, newValue);
|
|
2643
2645
|
});
|
|
2644
2646
|
});
|
|
2645
|
-
var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))(
|
|
2647
|
+
var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))(_extends({
|
|
2648
|
+
$state: $state
|
|
2649
|
+
}, $$state.env));
|
|
2646
2650
|
initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
|
|
2647
2651
|
var initialSpec = initialSpecNode.getSpec();
|
|
2648
2652
|
var value = initialSpec.isImmutable ? mkUntrackedValue(initialValue) : clone(initialValue);
|
|
2649
2653
|
set(proxyRoot, initialStatePath, value);
|
|
2650
2654
|
//immediately fire onChange
|
|
2651
2655
|
if (initialSpec.onChangeProp) {
|
|
2652
|
-
var _$$state$props$
|
|
2653
|
-
(_$$state$props$
|
|
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);
|
|
2654
2658
|
}
|
|
2655
2659
|
return initialValue;
|
|
2656
2660
|
}
|
|
@@ -2668,11 +2672,11 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
2668
2672
|
}
|
|
2669
2673
|
delete _get($$state.stateValues, currPath)[property];
|
|
2670
2674
|
if (spec.onChangeProp) {
|
|
2671
|
-
var _$$state$props$
|
|
2675
|
+
var _$$state$env$$props$s, _$$state$env$$props2;
|
|
2672
2676
|
//we are always in a leaf, since we only have two cases:
|
|
2673
2677
|
// 1 - delete properties outside the state tree
|
|
2674
2678
|
// 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
|
|
2675
|
-
(_$$state$props$
|
|
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)));
|
|
2676
2680
|
}
|
|
2677
2681
|
var nextPath = getNextPath(property);
|
|
2678
2682
|
var nextNode = currNode.makeTransition(property);
|
|
@@ -2736,12 +2740,19 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
2736
2740
|
} else {
|
|
2737
2741
|
Reflect.set(target, property, value, receiver);
|
|
2738
2742
|
}
|
|
2739
|
-
|
|
2743
|
+
if (currNode.isLeaf()) {
|
|
2740
2744
|
if (spec.onChangeProp) {
|
|
2741
|
-
var _$$state$props$
|
|
2742
|
-
(_$$state$props$
|
|
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);
|
|
2743
2747
|
}
|
|
2744
|
-
}
|
|
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
|
+
}
|
|
2745
2756
|
var newValue = (isOutside || currNode.isLeaf()) && currNode.getSpec().isImmutable ? mkUntrackedValue(value) : value;
|
|
2746
2757
|
set($$state.stateValues, nextPath, newValue);
|
|
2747
2758
|
return true;
|
|
@@ -2769,22 +2780,27 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
2769
2780
|
var mkUntrackedValue = function mkUntrackedValue(o) {
|
|
2770
2781
|
return o != null && typeof o === "object" ? valtio.ref(o) : o;
|
|
2771
2782
|
};
|
|
2772
|
-
|
|
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) {
|
|
2773
2792
|
var $$state = React__default.useRef(function () {
|
|
2774
2793
|
var rootSpecTree = buildTree(specs);
|
|
2775
2794
|
return {
|
|
2776
2795
|
rootSpecTree: rootSpecTree,
|
|
2777
2796
|
specTreeLeaves: getStateCells(rootSpecTree),
|
|
2778
2797
|
stateValues: valtio.proxy({}),
|
|
2779
|
-
|
|
2780
|
-
ctx: {},
|
|
2798
|
+
env: envFieldsAreNonNill(env),
|
|
2781
2799
|
specs: [],
|
|
2782
2800
|
registrationsQueue: valtio.proxy([])
|
|
2783
2801
|
};
|
|
2784
2802
|
}()).current;
|
|
2785
|
-
$$state.
|
|
2786
|
-
$$state.ctx = $ctx != null ? $ctx : {};
|
|
2787
|
-
$$state.specs = specs;
|
|
2803
|
+
$$state.env = envFieldsAreNonNill(env), $$state.specs = specs;
|
|
2788
2804
|
var create$State = function create$State() {
|
|
2789
2805
|
var $state = Object.assign(create$StateProxy($$state, function (node, path) {
|
|
2790
2806
|
if (!node.hasState(path)) {
|
|
@@ -2800,7 +2816,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2800
2816
|
get: function get(target, property, receiver) {
|
|
2801
2817
|
var spec = node.getSpec();
|
|
2802
2818
|
if (spec.valueProp) {
|
|
2803
|
-
return $$state.props[spec.valueProp];
|
|
2819
|
+
return $$state.env.$props[spec.valueProp];
|
|
2804
2820
|
} else {
|
|
2805
2821
|
return Reflect.get(target, property, receiver);
|
|
2806
2822
|
}
|
|
@@ -2814,7 +2830,9 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2814
2830
|
if (!node.hasState(realPath)) {
|
|
2815
2831
|
node.createStateCell(realPath);
|
|
2816
2832
|
}
|
|
2817
|
-
if (!deepEqual(node.getState(realPath).initialValue, f(
|
|
2833
|
+
if (!deepEqual(node.getState(realPath).initialValue, f(_extends({
|
|
2834
|
+
$state: $state
|
|
2835
|
+
}, $$state.env)))) {
|
|
2818
2836
|
$$state.registrationsQueue.push(mkUntrackedValue({
|
|
2819
2837
|
node: node,
|
|
2820
2838
|
path: realPath,
|
|
@@ -2851,7 +2869,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2851
2869
|
return;
|
|
2852
2870
|
}
|
|
2853
2871
|
node.createStateCell(spec.pathObj);
|
|
2854
|
-
var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, node, spec.pathObj, $state) : spec.initVal;
|
|
2872
|
+
var init = spec.valueProp ? $$state.env.$props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, node, spec.pathObj, $state) : spec.initVal;
|
|
2855
2873
|
set($state, spec.pathObj, init);
|
|
2856
2874
|
});
|
|
2857
2875
|
}
|
|
@@ -2870,7 +2888,9 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2870
2888
|
stateCell = _ref3.stateCell;
|
|
2871
2889
|
var initFunc = node.getInitFunc(stateCell);
|
|
2872
2890
|
if (initFunc) {
|
|
2873
|
-
var newInit = initFunc(
|
|
2891
|
+
var newInit = initFunc(_extends({
|
|
2892
|
+
$state: $state
|
|
2893
|
+
}, envFieldsAreNonNill(env)));
|
|
2874
2894
|
if (!deepEqual(newInit, stateCell.initialValue)) {
|
|
2875
2895
|
resetSpecs.push({
|
|
2876
2896
|
stateCell: stateCell,
|
|
@@ -2883,8 +2903,8 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2883
2903
|
var newInit = initializeStateValue($$state, node, stateCell.path, $state);
|
|
2884
2904
|
var spec = node.getSpec();
|
|
2885
2905
|
if (spec.onChangeProp) {
|
|
2886
|
-
var _$$state$props$
|
|
2887
|
-
(_$$state$props$
|
|
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);
|
|
2888
2908
|
}
|
|
2889
2909
|
};
|
|
2890
2910
|
useIsomorphicLayoutEffect$1(function () {
|
|
@@ -2893,7 +2913,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
2893
2913
|
node = _ref4.node;
|
|
2894
2914
|
reInitializeState(node, stateCell);
|
|
2895
2915
|
});
|
|
2896
|
-
}, [props, resetSpecs]);
|
|
2916
|
+
}, [env.$props, resetSpecs]);
|
|
2897
2917
|
useIsomorphicLayoutEffect$1(function () {
|
|
2898
2918
|
while ($$state.registrationsQueue.length) {
|
|
2899
2919
|
var _$$state$registration = $$state.registrationsQueue.shift(),
|