@plasmicapp/react-web 0.2.133 → 0.2.135
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 +17 -22
- package/dist/index-common.d.ts +2 -1
- package/dist/react-web.cjs.development.js +136 -92
- 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 +135 -93
- package/dist/react-web.esm.js.map +1 -1
- package/dist/render/elements.d.ts +1 -1
- package/dist/states/graph.d.ts +15 -0
- package/dist/states/helpers.d.ts +2 -0
- package/dist/states/index.d.ts +16 -7
- package/dist/states/valtio.d.ts +2 -15
- package/dist/states/vanilla.d.ts +3 -0
- package/dist/stories/UseDollarState.stories.d.ts +5 -2
- package/package.json +7 -5
- package/skinny/dist/index-common.d.ts +2 -1
- package/skinny/dist/index.js +115 -82
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/render/elements.d.ts +1 -1
- package/skinny/dist/states/graph.d.ts +15 -0
- package/skinny/dist/states/helpers.d.ts +2 -0
- package/skinny/dist/states/index.d.ts +16 -7
- package/skinny/dist/states/valtio.d.ts +2 -15
- package/skinny/dist/states/vanilla.d.ts +3 -0
- package/skinny/dist/stories/UseDollarState.stories.d.ts +5 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { $StateSpec, Internal$StateSpec } from ".";
|
|
2
|
+
export declare class StateSpecNode<T> {
|
|
3
|
+
private specs;
|
|
4
|
+
private edges;
|
|
5
|
+
constructor(specs: Internal$StateSpec<T>[]);
|
|
6
|
+
hasEdge(key: string | symbol): boolean;
|
|
7
|
+
addEdge(key: string | symbol, node: StateSpecNode<any>): void;
|
|
8
|
+
makeTransition(key: string | symbol | number): StateSpecNode<any> | undefined;
|
|
9
|
+
isLeaf(): boolean;
|
|
10
|
+
hasArrayTransition(): boolean;
|
|
11
|
+
getSpec(): Internal$StateSpec<T>;
|
|
12
|
+
getAllSpecs(): Internal$StateSpec<T>[];
|
|
13
|
+
}
|
|
14
|
+
export declare const transformPathStringToObj: (str: string) => (string | symbol)[];
|
|
15
|
+
export declare function buildGraph(specs: $StateSpec<any>[]): StateSpecNode<any>;
|
package/dist/states/helpers.d.ts
CHANGED
|
@@ -15,4 +15,6 @@ export declare function generateStateValueProp($state: $State, path: (string | n
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function set(obj: any, keys: any, val: any): void;
|
|
17
17
|
export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
18
|
+
export declare function shallowEqual<T>(a1: T[], a2: T[]): boolean;
|
|
19
|
+
export declare function isNum(value: string | number | symbol): value is number;
|
|
18
20
|
export { get };
|
package/dist/states/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
declare type InitFunc<T> = ($props: Record<string, any>, $state: $State) => T;
|
|
2
|
-
export
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
registerInitFunc?: (path: string, f: InitFunc<any>) => any;
|
|
5
|
-
}
|
|
1
|
+
export declare type InitFunc<T> = ($props: Record<string, any>, $state: $State, $ctx: Record<string, any>, indexes?: number[]) => T;
|
|
2
|
+
export declare type ObjectPath = (string | number)[];
|
|
6
3
|
export interface $StateSpec<T> {
|
|
7
4
|
path: string;
|
|
8
5
|
initFunc?: InitFunc<T>;
|
|
@@ -10,6 +7,18 @@ export interface $StateSpec<T> {
|
|
|
10
7
|
type: "private" | "readonly" | "writable";
|
|
11
8
|
valueProp?: string;
|
|
12
9
|
onChangeProp?: string;
|
|
10
|
+
isImmutable?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface $State {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
registerInitFunc?: (path: string, f: InitFunc<any>) => any;
|
|
15
|
+
}
|
|
16
|
+
export declare const ARRAY_SYMBOL: unique symbol;
|
|
17
|
+
export interface Internal$StateSpec<T> extends $StateSpec<T> {
|
|
18
|
+
isRepeated: boolean;
|
|
19
|
+
pathObj: (string | symbol)[];
|
|
20
|
+
}
|
|
21
|
+
export interface Internal$StateInstance {
|
|
22
|
+
path: ObjectPath;
|
|
23
|
+
specKey: string;
|
|
13
24
|
}
|
|
14
|
-
declare function useVanillaDollarState(_specs: $StateSpec<any>[], props: Record<string, any>): $State;
|
|
15
|
-
export default useVanillaDollarState;
|
package/dist/states/valtio.d.ts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export interface $State {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
registerInitFunc?: (path: string, f: InitFunc<any>) => any;
|
|
5
|
-
}
|
|
6
|
-
export interface $StateSpec<T> {
|
|
7
|
-
path: string;
|
|
8
|
-
initFunc?: InitFunc<T>;
|
|
9
|
-
initVal?: T;
|
|
10
|
-
type: "private" | "readonly" | "writable";
|
|
11
|
-
valueProp?: string;
|
|
12
|
-
onChangeProp?: string;
|
|
13
|
-
isArray?: boolean;
|
|
14
|
-
}
|
|
1
|
+
import { $StateSpec } from ".";
|
|
15
2
|
export declare function useDollarState(specs: $StateSpec<any>[], props: Record<string, any>, $ctx?: Record<string, any>): any;
|
|
16
3
|
export default useDollarState;
|
|
17
|
-
export declare function useCanvasDollarState(specs: $StateSpec<any>[], props: Record<string, any>, $ctx?: Record<string, any>):
|
|
4
|
+
export declare function useCanvasDollarState(specs: $StateSpec<any>[], props: Record<string, any>, $ctx?: Record<string, any>): {};
|
|
@@ -52,9 +52,12 @@ interface Person {
|
|
|
52
52
|
export declare const FormBuilder: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, {
|
|
53
53
|
people: Person[];
|
|
54
54
|
}>;
|
|
55
|
-
export declare const
|
|
55
|
+
export declare const StateCellIsArray: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, {
|
|
56
56
|
people: Person[];
|
|
57
57
|
}>;
|
|
58
|
-
export declare const
|
|
58
|
+
export declare const StateCellIsMatrix: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, {
|
|
59
|
+
board: number[][];
|
|
60
|
+
}>;
|
|
61
|
+
export declare const ImmutableStateCells: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, {
|
|
59
62
|
people: Person[];
|
|
60
63
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/react-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.135",
|
|
4
4
|
"description": "plasmic library for rendering in the presentational style",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
},
|
|
41
41
|
"prettier": {},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@plasmicapp/data-sources": "0.1.
|
|
43
|
+
"@plasmicapp/data-sources": "0.1.22",
|
|
44
44
|
"@plasmicapp/data-sources-context": "0.1.2",
|
|
45
|
-
"@plasmicapp/host": "1.0.
|
|
46
|
-
"@plasmicapp/query": "0.1.
|
|
45
|
+
"@plasmicapp/host": "1.0.92",
|
|
46
|
+
"@plasmicapp/query": "0.1.58",
|
|
47
47
|
"@react-aria/checkbox": "^3.5.0",
|
|
48
48
|
"@react-aria/focus": "^3.7.0",
|
|
49
49
|
"@react-aria/interactions": "^3.10.0",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"@react-stately/toggle": "^3.4.0",
|
|
64
64
|
"@react-stately/tree": "^3.3.2",
|
|
65
65
|
"classnames": "^2.2.6",
|
|
66
|
+
"clone": "^2.1.2",
|
|
66
67
|
"dlv": "^1.1.3",
|
|
67
68
|
"dset": "^3.1.2",
|
|
68
69
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -86,6 +87,7 @@
|
|
|
86
87
|
"@storybook/test-runner": "^0.5.0",
|
|
87
88
|
"@storybook/testing-library": "^0.0.13",
|
|
88
89
|
"@types/classnames": "^2.2.9",
|
|
90
|
+
"@types/clone": "^2.1.1",
|
|
89
91
|
"@types/dlv": "^1.1.2",
|
|
90
92
|
"@types/react": "^17.0.39",
|
|
91
93
|
"@types/react-dom": "^17.0.11",
|
|
@@ -108,5 +110,5 @@
|
|
|
108
110
|
"react": ">=16.8.0",
|
|
109
111
|
"react-dom": ">=16.8.0"
|
|
110
112
|
},
|
|
111
|
-
"gitHead": "
|
|
113
|
+
"gitHead": "d714c8c2cb1245a3f3c763e96a082c8c78929997"
|
|
112
114
|
}
|
|
@@ -13,6 +13,7 @@ export { PlasmicDataSourceContextProvider, PlasmicRootProvider, useCurrentUser,
|
|
|
13
13
|
export { Stack } from "./render/Stack";
|
|
14
14
|
export { genTranslatableString, Trans } from "./render/translation";
|
|
15
15
|
export { useTrigger } from "./render/triggers";
|
|
16
|
+
export { $State } from "./states";
|
|
16
17
|
export * from "./states/helpers";
|
|
17
|
-
export {
|
|
18
|
+
export { default as useDollarState, useCanvasDollarState, } from "./states/valtio";
|
|
18
19
|
export declare const classNames: typeof _classNames;
|
package/skinny/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { T as Trans } from './ssr-b16a1854.js';
|
|
|
12
12
|
export { P as PlasmicRootProvider, T as Trans, g as genTranslatableString, u as useIsSSR } from './ssr-b16a1854.js';
|
|
13
13
|
import ReactDOM__default from 'react-dom';
|
|
14
14
|
import { useFocusRing } from '@react-aria/focus';
|
|
15
|
+
import clone from 'clone';
|
|
15
16
|
import deepEqual from 'fast-deep-equal';
|
|
16
17
|
import { proxy, ref, useSnapshot } from 'valtio';
|
|
17
18
|
import { subscribeKey } from 'valtio/utils';
|
|
@@ -680,18 +681,84 @@ function set(obj, keys, val) {
|
|
|
680
681
|
}
|
|
681
682
|
}
|
|
682
683
|
}
|
|
683
|
-
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
684
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
685
|
+
function shallowEqual$1(a1, a2) {
|
|
686
|
+
if (a1.length !== a2.length) {
|
|
687
|
+
return false;
|
|
688
|
+
}
|
|
689
|
+
for (var i = 0; i < a1.length; i++) {
|
|
690
|
+
if (a1[i] !== a2[i]) {
|
|
691
|
+
return false;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
return true;
|
|
695
|
+
}
|
|
696
|
+
function isNum$1(value) {
|
|
697
|
+
return typeof value === "symbol" ? false : !isNaN(+value);
|
|
698
|
+
}
|
|
684
699
|
|
|
685
|
-
var
|
|
686
|
-
|
|
687
|
-
|
|
700
|
+
var ARRAY_SYMBOL = Symbol("[]");
|
|
701
|
+
|
|
702
|
+
var StateSpecNode = /** @class */ (function () {
|
|
703
|
+
function StateSpecNode(specs) {
|
|
704
|
+
this.specs = specs;
|
|
705
|
+
this.edges = new Map();
|
|
706
|
+
}
|
|
707
|
+
StateSpecNode.prototype.hasEdge = function (key) {
|
|
708
|
+
return this.edges.has(key);
|
|
709
|
+
};
|
|
710
|
+
StateSpecNode.prototype.addEdge = function (key, node) {
|
|
711
|
+
this.edges.set(key, node);
|
|
712
|
+
};
|
|
713
|
+
StateSpecNode.prototype.makeTransition = function (key) {
|
|
714
|
+
key = isNum$1(key) ? ARRAY_SYMBOL : key;
|
|
715
|
+
return this.edges.get(key);
|
|
716
|
+
};
|
|
717
|
+
StateSpecNode.prototype.isLeaf = function () {
|
|
718
|
+
return this.edges.size === 0;
|
|
719
|
+
};
|
|
720
|
+
StateSpecNode.prototype.hasArrayTransition = function () {
|
|
721
|
+
return this.edges.has(ARRAY_SYMBOL);
|
|
722
|
+
};
|
|
723
|
+
StateSpecNode.prototype.getSpec = function () {
|
|
724
|
+
return this.specs[0];
|
|
725
|
+
};
|
|
726
|
+
StateSpecNode.prototype.getAllSpecs = function () {
|
|
727
|
+
return this.specs;
|
|
728
|
+
};
|
|
729
|
+
return StateSpecNode;
|
|
730
|
+
}());
|
|
688
731
|
var transformPathStringToObj = function (str) {
|
|
689
732
|
var splitStatePathPart = function (state) {
|
|
690
733
|
return state.endsWith("[]")
|
|
691
|
-
? __spreadArray(__spreadArray([], __read(splitStatePathPart(state.slice(0, -2))), false), [
|
|
734
|
+
? __spreadArray(__spreadArray([], __read(splitStatePathPart(state.slice(0, -2))), false), [ARRAY_SYMBOL], false) : [state];
|
|
692
735
|
};
|
|
693
736
|
return str.split(".").flatMap(splitStatePathPart);
|
|
694
737
|
};
|
|
738
|
+
function buildGraph(specs) {
|
|
739
|
+
var internalSpec = specs.map(function (spec) {
|
|
740
|
+
return (__assign(__assign({}, spec), { pathObj: transformPathStringToObj(spec.path), isRepeated: spec.path.split(".").some(function (part) { return part.endsWith("[]"); }) }));
|
|
741
|
+
});
|
|
742
|
+
var rec = function (currentPath) {
|
|
743
|
+
var node = new StateSpecNode(internalSpec.filter(function (spec) {
|
|
744
|
+
return shallowEqual$1(currentPath, spec.pathObj.slice(0, currentPath.length));
|
|
745
|
+
}));
|
|
746
|
+
node.getAllSpecs().forEach(function (spec) {
|
|
747
|
+
if (spec.pathObj.length > currentPath.length) {
|
|
748
|
+
var nextKey = spec.pathObj[currentPath.length];
|
|
749
|
+
if (!node.hasEdge(nextKey)) {
|
|
750
|
+
node.addEdge(nextKey, rec(__spreadArray(__spreadArray([], __read(currentPath), false), [nextKey], false)));
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
return node;
|
|
755
|
+
};
|
|
756
|
+
return rec([]);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
var mkUntrackedValue = function (o) {
|
|
760
|
+
return o != null && typeof o === "object" ? ref(o) : o;
|
|
761
|
+
};
|
|
695
762
|
function shallowEqual(a1, a2) {
|
|
696
763
|
if (a1.length !== a2.length) {
|
|
697
764
|
return false;
|
|
@@ -717,34 +784,11 @@ function saveNewState($$state, path, spec) {
|
|
|
717
784
|
.push({ path: path, specKey: spec.path });
|
|
718
785
|
}
|
|
719
786
|
function create$StateProxy($$state, handlers) {
|
|
720
|
-
var
|
|
721
|
-
return new Map(Object.entries(Object.values($$state.specsByKey)
|
|
722
|
-
.filter(function (spec) {
|
|
723
|
-
return shallowEqual(currPath.map(function (p) { return (isNum(p) ? "[]" : p); }), spec.pathObj.slice(0, currPath.length));
|
|
724
|
-
})
|
|
725
|
-
.reduce(function (agg, spec) {
|
|
726
|
-
var nextKey = spec.pathObj[currPath.length];
|
|
727
|
-
if (!(nextKey in agg)) {
|
|
728
|
-
agg[nextKey] = [];
|
|
729
|
-
}
|
|
730
|
-
agg[nextKey].push(spec);
|
|
731
|
-
return agg;
|
|
732
|
-
}, {})));
|
|
733
|
-
};
|
|
734
|
-
var rec = function (currPath) {
|
|
735
|
-
var nextKeyToSpecs = getNextKeyToSpecMap(currPath);
|
|
736
|
-
var getSpecForProperty = function (property) {
|
|
737
|
-
var _a, _b;
|
|
738
|
-
return nextKeyToSpecs.has("[]") && isNum(property)
|
|
739
|
-
? (_a = nextKeyToSpecs.get("[]")) === null || _a === void 0 ? void 0 : _a[0]
|
|
740
|
-
: typeof property === "string" && nextKeyToSpecs.has(property)
|
|
741
|
-
? (_b = nextKeyToSpecs.get(property)) === null || _b === void 0 ? void 0 : _b[0]
|
|
742
|
-
: undefined;
|
|
743
|
-
};
|
|
787
|
+
var rec = function (currPath, currNode) {
|
|
744
788
|
var getNextPath = function (property) { return __spreadArray(__spreadArray([], __read(currPath), false), [
|
|
745
789
|
isNum(property) ? +property : property,
|
|
746
790
|
], false); };
|
|
747
|
-
return new Proxy(
|
|
791
|
+
return new Proxy(currNode.hasArrayTransition() ? [] : {}, {
|
|
748
792
|
deleteProperty: function (target, property) {
|
|
749
793
|
var prefixPath = getNextPath(property);
|
|
750
794
|
var specKeysToUpdate = new Set();
|
|
@@ -767,42 +811,41 @@ function create$StateProxy($$state, handlers) {
|
|
|
767
811
|
},
|
|
768
812
|
get: function (target, property, receiver) {
|
|
769
813
|
var _a, _b;
|
|
770
|
-
var
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
if (
|
|
774
|
-
|
|
775
|
-
target[property] = (_b = (_a = handlers(nextPath, spec)).get) === null || _b === void 0 ? void 0 : _b.call(_a, target, property, receiver);
|
|
814
|
+
var nextPath = getNextPath(property);
|
|
815
|
+
var nextNode = currNode.makeTransition(property);
|
|
816
|
+
if (nextNode) {
|
|
817
|
+
if (nextNode.isLeaf()) {
|
|
818
|
+
target[property] = (_b = (_a = handlers(nextPath, nextNode.getSpec())).get) === null || _b === void 0 ? void 0 : _b.call(_a, target, property, receiver);
|
|
776
819
|
}
|
|
777
820
|
else if (!(property in target)) {
|
|
778
|
-
target[property] = rec(nextPath);
|
|
821
|
+
target[property] = rec(nextPath, nextNode);
|
|
779
822
|
}
|
|
780
823
|
}
|
|
781
824
|
return Reflect.get(target, property, receiver);
|
|
782
825
|
},
|
|
783
826
|
set: function (target, property, value, receiver) {
|
|
784
827
|
var e_1, _a;
|
|
785
|
-
var _b, _c, _d;
|
|
786
|
-
var spec = getSpecForProperty(property);
|
|
828
|
+
var _b, _c, _d, _e;
|
|
787
829
|
var nextPath = getNextPath(property);
|
|
788
|
-
|
|
789
|
-
|
|
830
|
+
var nextNode = currNode.makeTransition(property);
|
|
831
|
+
if (nextNode && typeof property !== "symbol") {
|
|
832
|
+
if (nextNode.isLeaf()) {
|
|
790
833
|
// reached the end of the spec
|
|
791
|
-
target[property] = (_c = (_b = handlers(nextPath,
|
|
834
|
+
target[property] = (_c = (_b = handlers(nextPath, nextNode.getSpec())).set) === null || _c === void 0 ? void 0 : _c.call(_b, target, property, value, receiver);
|
|
792
835
|
return Reflect.set(target, property, value, receiver);
|
|
793
836
|
}
|
|
794
837
|
else if (typeof value === "object") {
|
|
795
|
-
target[property] = rec(nextPath);
|
|
838
|
+
target[property] = rec(nextPath, nextNode);
|
|
796
839
|
try {
|
|
797
|
-
for (var
|
|
798
|
-
var key =
|
|
840
|
+
for (var _f = __values(Object.keys(value)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
841
|
+
var key = _g.value;
|
|
799
842
|
target[property][key] = value[key];
|
|
800
843
|
}
|
|
801
844
|
}
|
|
802
845
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
803
846
|
finally {
|
|
804
847
|
try {
|
|
805
|
-
if (
|
|
848
|
+
if (_g && !_g.done && (_a = _f["return"])) _a.call(_f);
|
|
806
849
|
}
|
|
807
850
|
finally { if (e_1) throw e_1.error; }
|
|
808
851
|
}
|
|
@@ -812,11 +855,12 @@ function create$StateProxy($$state, handlers) {
|
|
|
812
855
|
if (property === "registerInitFunc" && currPath.length === 0) {
|
|
813
856
|
return Reflect.set(target, property, value, receiver);
|
|
814
857
|
}
|
|
815
|
-
if (
|
|
858
|
+
if (currNode.hasArrayTransition()) {
|
|
816
859
|
set($$state.stateValues, nextPath, value);
|
|
817
|
-
(
|
|
860
|
+
(_e = (_d = currNode
|
|
861
|
+
.makeTransition(ARRAY_SYMBOL)) === null || _d === void 0 ? void 0 : _d.getAllSpecs()) === null || _e === void 0 ? void 0 : _e.forEach(function (spec) {
|
|
818
862
|
var _a, _b;
|
|
819
|
-
if (spec
|
|
863
|
+
if (spec.onChangeProp) {
|
|
820
864
|
(_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, value, nextPath);
|
|
821
865
|
}
|
|
822
866
|
});
|
|
@@ -827,7 +871,7 @@ function create$StateProxy($$state, handlers) {
|
|
|
827
871
|
}
|
|
828
872
|
});
|
|
829
873
|
};
|
|
830
|
-
return rec([]);
|
|
874
|
+
return rec([], $$state.rootStateSpec);
|
|
831
875
|
}
|
|
832
876
|
var deleteState = function ($$state, path) {
|
|
833
877
|
var _a;
|
|
@@ -881,7 +925,7 @@ function initializeStateValue($$state, initialStatePath, initialSpec) {
|
|
|
881
925
|
stateAccess.forEach(function (_a) {
|
|
882
926
|
var path = _a.path, spec = _a.spec;
|
|
883
927
|
var unsubscribe = subscribeKey(get($$state.stateValues, path.slice(-1)), path.slice(-1)[0], function () {
|
|
884
|
-
return
|
|
928
|
+
return saveValue($$state, initialStatePath, initialSpec, initialSpec.initFunc($$state.props, $state, $$state.ctx, getIndexes(path, spec)));
|
|
885
929
|
});
|
|
886
930
|
$$state.unsubscriptionsByState[initialStateKey].push(unsubscribe);
|
|
887
931
|
});
|
|
@@ -889,22 +933,23 @@ function initializeStateValue($$state, initialStatePath, initialSpec) {
|
|
|
889
933
|
saveStateInitialValue($$state, initialStatePath, initialSpec, initialValue);
|
|
890
934
|
return initialValue;
|
|
891
935
|
}
|
|
892
|
-
function
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
// that's why we need to track the array object
|
|
896
|
-
if (spec.isArray && Array.isArray(initialValue)) {
|
|
897
|
-
var array = initialValue.map(function (val) { return mkUntrackedValue(val); });
|
|
898
|
-
set($$state.stateValues, path, array);
|
|
899
|
-
// we need to make the array untracked for initStateValues
|
|
900
|
-
// so we can distinguish between stateValue and initStateValue.
|
|
901
|
-
// otherwise they would reference the same array.
|
|
902
|
-
set($$state.initStateValues, path, mkUntrackedValue(array));
|
|
936
|
+
function saveValue($$state, path, spec, value) {
|
|
937
|
+
if (spec.isImmutable) {
|
|
938
|
+
set($$state.stateValues, path, mkUntrackedValue(value));
|
|
903
939
|
}
|
|
904
940
|
else {
|
|
941
|
+
set($$state.stateValues, path, value);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
function saveStateInitialValue($$state, path, spec, initialValue) {
|
|
945
|
+
if (spec.isImmutable) {
|
|
905
946
|
var untrackedValue = mkUntrackedValue(initialValue);
|
|
906
947
|
set($$state.stateValues, path, untrackedValue);
|
|
907
|
-
set($$state.initStateValues, path, untrackedValue);
|
|
948
|
+
set($$state.initStateValues, path, clone(untrackedValue));
|
|
949
|
+
}
|
|
950
|
+
else {
|
|
951
|
+
set($$state.stateValues, path, clone(initialValue));
|
|
952
|
+
set($$state.initStateValues, path, clone(initialValue));
|
|
908
953
|
}
|
|
909
954
|
}
|
|
910
955
|
function useDollarState(specs, props, $ctx) {
|
|
@@ -922,7 +967,8 @@ function useDollarState(specs, props, $ctx) {
|
|
|
922
967
|
unsubscriptionsByState: {},
|
|
923
968
|
props: {},
|
|
924
969
|
ctx: {},
|
|
925
|
-
registrationsQueue: []
|
|
970
|
+
registrationsQueue: [],
|
|
971
|
+
rootStateSpec: buildGraph(specs)
|
|
926
972
|
})).current;
|
|
927
973
|
$$state.props = mkUntrackedValue(props);
|
|
928
974
|
$$state.ctx = mkUntrackedValue($ctx !== null && $ctx !== void 0 ? $ctx : {});
|
|
@@ -950,7 +996,7 @@ function useDollarState(specs, props, $ctx) {
|
|
|
950
996
|
},
|
|
951
997
|
set: function (_t, _p, value) {
|
|
952
998
|
var _a, _b;
|
|
953
|
-
|
|
999
|
+
saveValue($$state, path, spec, value);
|
|
954
1000
|
if (spec.onChangeProp) {
|
|
955
1001
|
(_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, value, path);
|
|
956
1002
|
}
|
|
@@ -1019,25 +1065,12 @@ function useCanvasDollarState(specs, props, $ctx) {
|
|
|
1019
1065
|
unsubscriptionsByState: {},
|
|
1020
1066
|
props: {},
|
|
1021
1067
|
ctx: {},
|
|
1022
|
-
registrationsQueue: []
|
|
1068
|
+
registrationsQueue: [],
|
|
1069
|
+
rootStateSpec: buildGraph(specs)
|
|
1023
1070
|
});
|
|
1024
1071
|
$$state.props = mkUntrackedValue(props);
|
|
1025
1072
|
$$state.ctx = mkUntrackedValue($ctx);
|
|
1026
|
-
var $state =
|
|
1027
|
-
return {
|
|
1028
|
-
get: function () {
|
|
1029
|
-
return get($$state.stateValues, path);
|
|
1030
|
-
},
|
|
1031
|
-
set: function (_t, _p, value) {
|
|
1032
|
-
var _a, _b;
|
|
1033
|
-
set($$state.stateValues, path, mkUntrackedValue(value));
|
|
1034
|
-
if (spec.onChangeProp) {
|
|
1035
|
-
(_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, value, path);
|
|
1036
|
-
}
|
|
1037
|
-
return true;
|
|
1038
|
-
}
|
|
1039
|
-
};
|
|
1040
|
-
});
|
|
1073
|
+
var $state = {};
|
|
1041
1074
|
try {
|
|
1042
1075
|
for (var specs_1 = __values(specs), specs_1_1 = specs_1.next(); !specs_1_1.done; specs_1_1 = specs_1.next()) {
|
|
1043
1076
|
var spec = specs_1_1.value;
|
|
@@ -1065,5 +1098,5 @@ function useCanvasDollarState(specs, props, $ctx) {
|
|
|
1065
1098
|
// Utilities used by generated code
|
|
1066
1099
|
var classNames = classNames$1;
|
|
1067
1100
|
|
|
1068
|
-
export { PlasmicIcon, PlasmicLink, PlasmicSlot, Stack, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, generateStateOnChangeProp, generateStateValueProp, hasVariant, makeFragment, mergeVariantsWithStates, renderPlasmicSlot, set, useCanvasDollarState, useDollarState, useIsomorphicLayoutEffect, useTrigger, wrapWithClassName };
|
|
1101
|
+
export { PlasmicIcon, PlasmicLink, PlasmicSlot, Stack, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, generateStateOnChangeProp, generateStateValueProp, hasVariant, isNum$1 as isNum, makeFragment, mergeVariantsWithStates, renderPlasmicSlot, set, shallowEqual$1 as shallowEqual, useCanvasDollarState, useDollarState, useIsomorphicLayoutEffect, useTrigger, wrapWithClassName };
|
|
1069
1102
|
//# sourceMappingURL=index.js.map
|