@plasmicapp/react-web 0.2.115 → 0.2.117
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 +25 -24
- package/dist/index-common.d.ts +2 -0
- package/dist/index.d.ts +0 -2
- package/dist/react-web.cjs.development.js +1611 -1598
- 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 +1611 -1598
- package/dist/react-web.esm.js.map +1 -1
- package/dist/states/valtio.d.ts +1 -0
- package/dist/stories/UseDollarState.stories.d.ts +3 -0
- package/package.json +2 -2
- package/skinny/dist/index-common.d.ts +2 -0
- package/skinny/dist/index.d.ts +0 -2
- package/skinny/dist/index.js +423 -1
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/plume/checkbox/index.js +2 -2
- package/skinny/dist/plume/checkbox/index.js.map +1 -1
- package/skinny/dist/plume/switch/index.js +2 -2
- package/skinny/dist/plume/switch/index.js.map +1 -1
- package/skinny/dist/states/valtio.d.ts +1 -0
- package/skinny/dist/stories/UseDollarState.stories.d.ts +3 -0
package/dist/states/valtio.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface $StateSpec<T> {
|
|
|
10
10
|
type: "private" | "readonly" | "writable";
|
|
11
11
|
valueProp?: string;
|
|
12
12
|
onChangeProp?: string;
|
|
13
|
+
isArray?: boolean;
|
|
13
14
|
}
|
|
14
15
|
export declare function useDollarState(specs: $StateSpec<any>[], props: Record<string, any>): any;
|
|
15
16
|
export default useDollarState;
|
|
@@ -49,3 +49,6 @@ export declare const FormBuilder: import("@storybook/csf").AnnotatedStoryFn<impo
|
|
|
49
49
|
export declare const FormBuilderImplicitStates: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, {
|
|
50
50
|
people: Person[];
|
|
51
51
|
}>;
|
|
52
|
+
export declare const VariableCellIsArray: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, {
|
|
53
|
+
people: Person[];
|
|
54
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/react-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.117",
|
|
4
4
|
"description": "plasmic library for rendering in the presentational style",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -105,5 +105,5 @@
|
|
|
105
105
|
"react": ">=16.8.0",
|
|
106
106
|
"react-dom": ">=16.8.0"
|
|
107
107
|
},
|
|
108
|
-
"gitHead": "
|
|
108
|
+
"gitHead": "87a321aeb0d3ffcf66ac60e84319bbe32859f5e6"
|
|
109
109
|
}
|
|
@@ -14,3 +14,5 @@ export { PlasmicDataSourceContextProvider, PlasmicRootProvider, useCurrentUser,
|
|
|
14
14
|
export { Stack } from "./render/Stack";
|
|
15
15
|
export { genTranslatableString, Trans } from "./render/translation";
|
|
16
16
|
export { useTrigger } from "./render/triggers";
|
|
17
|
+
export * from "./states/helpers";
|
|
18
|
+
export { $State, default as useDollarState, useCanvasDollarState, } from "./states/valtio";
|
package/skinny/dist/index.d.ts
CHANGED
|
@@ -9,5 +9,3 @@ export * from "./plume/select";
|
|
|
9
9
|
export * from "./plume/switch";
|
|
10
10
|
export * from "./plume/text-input";
|
|
11
11
|
export * from "./plume/triggered-overlay";
|
|
12
|
-
export * from "./states/helpers";
|
|
13
|
-
export { $State, default as useDollarState, useCanvasDollarState, } from "./states/valtio";
|
package/skinny/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import classNames$1 from 'classnames';
|
|
2
2
|
import get from 'dlv';
|
|
3
|
+
export { default as get } from 'dlv';
|
|
3
4
|
import * as React from 'react';
|
|
4
5
|
import React__default from 'react';
|
|
5
6
|
import { c as createElementWithChildren, m as mergeProps, e as ensureNotArray, N as NONE, a as mergePropVals, i as isReactNode, b as isBrowser, u as useIsomorphicLayoutEffect } from './react-utils-7bc53870.js';
|
|
@@ -11,6 +12,9 @@ import { T as Trans } from './ssr-b16a1854.js';
|
|
|
11
12
|
export { P as PlasmicRootProvider, T as Trans, g as genTranslatableString, u as useIsSSR } from './ssr-b16a1854.js';
|
|
12
13
|
import ReactDOM__default from 'react-dom';
|
|
13
14
|
import { useFocusRing } from '@react-aria/focus';
|
|
15
|
+
import deepEqual from 'fast-deep-equal';
|
|
16
|
+
import { proxy, ref, useSnapshot } from 'valtio';
|
|
17
|
+
import { subscribeKey } from 'valtio/utils';
|
|
14
18
|
export { PlasmicDataSourceContextProvider, useCurrentUser } from '@plasmicapp/data-sources-context';
|
|
15
19
|
import '@react-aria/ssr';
|
|
16
20
|
|
|
@@ -633,8 +637,426 @@ function useTrigger(trigger, opts) {
|
|
|
633
637
|
return TRIGGER_TO_HOOK[trigger](opts);
|
|
634
638
|
}
|
|
635
639
|
|
|
640
|
+
function generateStateOnChangeProp($state, stateName, dataReps) {
|
|
641
|
+
return function (val, path) { return set($state, __spreadArray(__spreadArray([stateName], __read(dataReps), false), __read(path), false), val); };
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* This function generate the state value prop for repeated states
|
|
645
|
+
* Example:
|
|
646
|
+
* - parent[][].counter[].count
|
|
647
|
+
* We need to pass `parent[index1][index2].counter to the child component
|
|
648
|
+
*/
|
|
649
|
+
function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
|
|
650
|
+
) {
|
|
651
|
+
return get($state, path);
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Forked from https://github.com/lukeed/dset
|
|
655
|
+
* Changes: fixed setting a deep value to a proxy object
|
|
656
|
+
*/
|
|
657
|
+
function set(obj, keys, val) {
|
|
658
|
+
keys = keys.split ? keys.split(".") : keys;
|
|
659
|
+
var i = 0, l = keys.length, t = obj, x, k;
|
|
660
|
+
while (i < l) {
|
|
661
|
+
k = keys[i++];
|
|
662
|
+
if (k === "__proto__" || k === "constructor" || k === "prototype")
|
|
663
|
+
break;
|
|
664
|
+
if (i === l) {
|
|
665
|
+
t[k] = val;
|
|
666
|
+
t = t[k];
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
if (typeof (x = t[k]) === typeof keys) {
|
|
670
|
+
t = t[k] = x;
|
|
671
|
+
}
|
|
672
|
+
else if (keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")) {
|
|
673
|
+
t[k] = {};
|
|
674
|
+
t = t[k];
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
t[k] = [];
|
|
678
|
+
t = t[k];
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
var mkUntrackedValue = function (o) { return (typeof o === "object" ? ref(o) : o); };
|
|
685
|
+
var transformPathStringToObj = function (str) {
|
|
686
|
+
var splitStatePathPart = function (state) {
|
|
687
|
+
return state.endsWith("[]")
|
|
688
|
+
? __spreadArray(__spreadArray([], __read(splitStatePathPart(state.slice(0, -2))), false), ["[]"], false) : [state];
|
|
689
|
+
};
|
|
690
|
+
return str.split(".").flatMap(splitStatePathPart);
|
|
691
|
+
};
|
|
692
|
+
function shallowEqual(a1, a2) {
|
|
693
|
+
if (a1.length !== a2.length) {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
for (var i = 0; i < a1.length; i++) {
|
|
697
|
+
if (a1[i] !== a2[i]) {
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
return true;
|
|
702
|
+
}
|
|
703
|
+
function isNum(value) {
|
|
704
|
+
return typeof value === "symbol" ? false : !isNaN(+value);
|
|
705
|
+
}
|
|
706
|
+
function saveNewState($$state, path, spec) {
|
|
707
|
+
var key = JSON.stringify(path);
|
|
708
|
+
$$state.existingStates.set(key, { path: path, specKey: spec.path });
|
|
709
|
+
if (!$$state.statesInstanceBySpec.has(spec.path)) {
|
|
710
|
+
$$state.statesInstanceBySpec.set(spec.path, []);
|
|
711
|
+
}
|
|
712
|
+
$$state.statesInstanceBySpec
|
|
713
|
+
.get(spec.path)
|
|
714
|
+
.push({ path: path, specKey: spec.path });
|
|
715
|
+
}
|
|
716
|
+
function create$StateProxy($$state, handlers) {
|
|
717
|
+
var getNextKeyToSpecMap = function (currPath) {
|
|
718
|
+
return new Map(Object.entries(Object.values($$state.specsByKey)
|
|
719
|
+
.filter(function (spec) {
|
|
720
|
+
return shallowEqual(currPath.map(function (p) { return (isNum(p) ? "[]" : p); }), spec.pathObj.slice(0, currPath.length));
|
|
721
|
+
})
|
|
722
|
+
.reduce(function (agg, spec) {
|
|
723
|
+
var nextKey = spec.pathObj[currPath.length];
|
|
724
|
+
if (!(nextKey in agg)) {
|
|
725
|
+
agg[nextKey] = [];
|
|
726
|
+
}
|
|
727
|
+
agg[nextKey].push(spec);
|
|
728
|
+
return agg;
|
|
729
|
+
}, {})));
|
|
730
|
+
};
|
|
731
|
+
var rec = function (currPath) {
|
|
732
|
+
var nextKeyToSpecs = getNextKeyToSpecMap(currPath);
|
|
733
|
+
var getSpecForProperty = function (property) {
|
|
734
|
+
var _a, _b;
|
|
735
|
+
return nextKeyToSpecs.has("[]") && isNum(property)
|
|
736
|
+
? (_a = nextKeyToSpecs.get("[]")) === null || _a === void 0 ? void 0 : _a[0]
|
|
737
|
+
: typeof property === "string" && nextKeyToSpecs.has(property)
|
|
738
|
+
? (_b = nextKeyToSpecs.get(property)) === null || _b === void 0 ? void 0 : _b[0]
|
|
739
|
+
: undefined;
|
|
740
|
+
};
|
|
741
|
+
var getNextPath = function (property) { return __spreadArray(__spreadArray([], __read(currPath), false), [
|
|
742
|
+
isNum(property) ? +property : property,
|
|
743
|
+
], false); };
|
|
744
|
+
return new Proxy(nextKeyToSpecs.has("[]") ? [] : {}, {
|
|
745
|
+
deleteProperty: function (target, property) {
|
|
746
|
+
var prefixPath = getNextPath(property);
|
|
747
|
+
var specKeysToUpdate = new Set();
|
|
748
|
+
$$state.existingStates.forEach(function (_a) {
|
|
749
|
+
var path = _a.path, specKey = _a.specKey;
|
|
750
|
+
if (path.length >= prefixPath.length &&
|
|
751
|
+
shallowEqual(path.slice(0, prefixPath.length), prefixPath)) {
|
|
752
|
+
deleteState($$state, path);
|
|
753
|
+
specKeysToUpdate.add(specKey);
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
specKeysToUpdate.forEach(function (specKey) {
|
|
757
|
+
var _a, _b;
|
|
758
|
+
var spec = $$state.specsByKey[specKey];
|
|
759
|
+
if (spec.onChangeProp) {
|
|
760
|
+
(_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, get($$state.stateValues, currPath), currPath);
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
return Reflect.deleteProperty(target, property);
|
|
764
|
+
},
|
|
765
|
+
get: function (target, property, receiver) {
|
|
766
|
+
var _a, _b;
|
|
767
|
+
var spec = getSpecForProperty(property);
|
|
768
|
+
if (spec && typeof property !== "symbol") {
|
|
769
|
+
var nextPath = getNextPath(property);
|
|
770
|
+
if (spec.pathObj.length === currPath.length + 1) {
|
|
771
|
+
// reached the end of the spec
|
|
772
|
+
target[property] = (_b = (_a = handlers(nextPath, spec)).get) === null || _b === void 0 ? void 0 : _b.call(_a, target, property, receiver);
|
|
773
|
+
}
|
|
774
|
+
else if (!(property in target)) {
|
|
775
|
+
target[property] = rec(nextPath);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
return Reflect.get(target, property, receiver);
|
|
779
|
+
},
|
|
780
|
+
set: function (target, property, value, receiver) {
|
|
781
|
+
var e_1, _a;
|
|
782
|
+
var _b, _c, _d;
|
|
783
|
+
var spec = getSpecForProperty(property);
|
|
784
|
+
var nextPath = getNextPath(property);
|
|
785
|
+
if (spec && typeof property !== "symbol") {
|
|
786
|
+
if (spec.pathObj.length === currPath.length + 1) {
|
|
787
|
+
// reached the end of the spec
|
|
788
|
+
target[property] = (_c = (_b = handlers(nextPath, spec)).set) === null || _c === void 0 ? void 0 : _c.call(_b, target, property, value, receiver);
|
|
789
|
+
return Reflect.set(target, property, value, receiver);
|
|
790
|
+
}
|
|
791
|
+
else if (typeof value === "object") {
|
|
792
|
+
target[property] = rec(nextPath);
|
|
793
|
+
try {
|
|
794
|
+
for (var _e = __values(Object.keys(value)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
795
|
+
var key = _f.value;
|
|
796
|
+
target[property][key] = value[key];
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
800
|
+
finally {
|
|
801
|
+
try {
|
|
802
|
+
if (_f && !_f.done && (_a = _e["return"])) _a.call(_e);
|
|
803
|
+
}
|
|
804
|
+
finally { if (e_1) throw e_1.error; }
|
|
805
|
+
}
|
|
806
|
+
return true;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
if (property === "registerInitFunc" && currPath.length === 0) {
|
|
810
|
+
return Reflect.set(target, property, value, receiver);
|
|
811
|
+
}
|
|
812
|
+
if (nextKeyToSpecs.has("[]")) {
|
|
813
|
+
set($$state.stateValues, nextPath, value);
|
|
814
|
+
(_d = nextKeyToSpecs.get("[]")) === null || _d === void 0 ? void 0 : _d.forEach(function (spec) {
|
|
815
|
+
var _a, _b;
|
|
816
|
+
if (spec === null || spec === void 0 ? void 0 : spec.onChangeProp) {
|
|
817
|
+
(_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, value, nextPath);
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
return Reflect.set(target, property, value, receiver);
|
|
821
|
+
}
|
|
822
|
+
// invalid setting a value that doesn't make part of the spec
|
|
823
|
+
return false;
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
};
|
|
827
|
+
return rec([]);
|
|
828
|
+
}
|
|
829
|
+
var deleteState = function ($$state, path) {
|
|
830
|
+
var _a;
|
|
831
|
+
var key = JSON.stringify(path);
|
|
832
|
+
(_a = $$state.unsubscriptionsByState[key]) === null || _a === void 0 ? void 0 : _a.forEach(function (f) { return f(); });
|
|
833
|
+
delete $$state.unsubscriptionsByState[key];
|
|
834
|
+
$$state.existingStates["delete"](key);
|
|
835
|
+
// delete get($$state.stateValues, path.slice(-1))[path.slice(-1)[0]];
|
|
836
|
+
// delete get($$state.initStateValues, path.slice(-1))[path.slice(-1)[0]];
|
|
837
|
+
};
|
|
838
|
+
var getIndexes = function (path, spec) {
|
|
839
|
+
var indexes = [];
|
|
840
|
+
if (path.length !== spec.pathObj.length) {
|
|
841
|
+
throw new Error("Unexpected error: state path and spec path have different lengths");
|
|
842
|
+
}
|
|
843
|
+
for (var i = 0; i < spec.pathObj.length; i++) {
|
|
844
|
+
if (spec.pathObj[i] === "[]") {
|
|
845
|
+
indexes.push(path[i]);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return indexes;
|
|
849
|
+
};
|
|
850
|
+
function initializeStateValue($$state, initialStatePath, initialSpec) {
|
|
851
|
+
var _a;
|
|
852
|
+
var initialStateKey = JSON.stringify(initialStatePath);
|
|
853
|
+
var stateAccess = new Set();
|
|
854
|
+
var $state = create$StateProxy($$state, function (path, spec) { return ({
|
|
855
|
+
get: function () {
|
|
856
|
+
var key = JSON.stringify(path);
|
|
857
|
+
stateAccess.add({ path: path, spec: spec });
|
|
858
|
+
if (spec.valueProp) {
|
|
859
|
+
return !spec.isRepeated
|
|
860
|
+
? $$state.props[spec.valueProp]
|
|
861
|
+
: get($$state.props[spec.valueProp], path.slice(1));
|
|
862
|
+
}
|
|
863
|
+
if ($$state.existingStates.has(key)) {
|
|
864
|
+
// is already initialized
|
|
865
|
+
return get($$state.stateValues, path);
|
|
866
|
+
}
|
|
867
|
+
else if (spec.initFunc) {
|
|
868
|
+
initializeStateValue($$state, path, spec);
|
|
869
|
+
}
|
|
870
|
+
return get($$state.stateValues, path);
|
|
871
|
+
},
|
|
872
|
+
set: function () {
|
|
873
|
+
throw new Error("Cannot update state values during initialization");
|
|
874
|
+
}
|
|
875
|
+
}); });
|
|
876
|
+
(_a = $$state.unsubscriptionsByState[initialStateKey]) === null || _a === void 0 ? void 0 : _a.forEach(function (f) { return f(); });
|
|
877
|
+
$$state.unsubscriptionsByState[initialStateKey] = [];
|
|
878
|
+
stateAccess.forEach(function (_a) {
|
|
879
|
+
var path = _a.path, spec = _a.spec;
|
|
880
|
+
var unsubscribe = subscribeKey(get($$state.stateValues, path.slice(-1)), path.slice(-1)[0], function () {
|
|
881
|
+
return set($$state.stateValues, initialStatePath, mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(path, spec))));
|
|
882
|
+
});
|
|
883
|
+
$$state.unsubscriptionsByState[initialStateKey].push(unsubscribe);
|
|
884
|
+
});
|
|
885
|
+
var initialValue = initialSpec.initFunc($$state.props, $state, getIndexes(initialStatePath, initialSpec));
|
|
886
|
+
saveStateInitialValue($$state, initialStatePath, initialSpec, initialValue);
|
|
887
|
+
return initialValue;
|
|
888
|
+
}
|
|
889
|
+
function saveStateInitialValue($$state, path, spec, initialValue) {
|
|
890
|
+
// array states are a special case.Wwe listen for changes in the array and in the array cells.
|
|
891
|
+
// for example: $state.people.push(...), $state.people.splice(...), $state.people[0] = ...
|
|
892
|
+
// that's why we need to track the array object
|
|
893
|
+
if (spec.isArray && Array.isArray(initialValue)) {
|
|
894
|
+
var array = initialValue.map(function (val) { return mkUntrackedValue(val); });
|
|
895
|
+
set($$state.stateValues, path, array);
|
|
896
|
+
// we need to make the array untracked for initStateValues
|
|
897
|
+
// so we can distinguish between stateValue and initStateValue.
|
|
898
|
+
// otherwise they would reference the same array.
|
|
899
|
+
set($$state.initStateValues, path, mkUntrackedValue(array));
|
|
900
|
+
}
|
|
901
|
+
else {
|
|
902
|
+
var untrackedValue = mkUntrackedValue(initialValue);
|
|
903
|
+
set($$state.stateValues, path, untrackedValue);
|
|
904
|
+
set($$state.initStateValues, path, untrackedValue);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
function useDollarState(specs, props) {
|
|
908
|
+
var $$state = React__default.useRef(proxy({
|
|
909
|
+
stateValues: {},
|
|
910
|
+
initStateValues: {},
|
|
911
|
+
specsByKey: Object.fromEntries(specs.map(function (spec) { return [
|
|
912
|
+
spec.path,
|
|
913
|
+
__assign(__assign({}, spec), { pathObj: transformPathStringToObj(spec.path), isRepeated: spec.path
|
|
914
|
+
.split(".")
|
|
915
|
+
.some(function (part) { return part.endsWith("[]"); }) }),
|
|
916
|
+
]; })),
|
|
917
|
+
statesInstanceBySpec: new Map(),
|
|
918
|
+
existingStates: new Map(),
|
|
919
|
+
unsubscriptionsByState: {},
|
|
920
|
+
props: undefined,
|
|
921
|
+
registrationsQueue: []
|
|
922
|
+
})).current;
|
|
923
|
+
$$state.props = mkUntrackedValue(props);
|
|
924
|
+
var $state = React__default.useRef(Object.assign(create$StateProxy($$state, function (path, spec) {
|
|
925
|
+
var _a;
|
|
926
|
+
var key = JSON.stringify(path);
|
|
927
|
+
if (!$$state.existingStates.has(key)) {
|
|
928
|
+
saveNewState($$state, path, spec);
|
|
929
|
+
var initialValue = !spec.initFunc
|
|
930
|
+
? (_a = spec.initVal) !== null && _a !== void 0 ? _a : undefined
|
|
931
|
+
: initializeStateValue($$state, path, spec);
|
|
932
|
+
saveStateInitialValue($$state, path, spec, initialValue);
|
|
933
|
+
}
|
|
934
|
+
return {
|
|
935
|
+
get: function () {
|
|
936
|
+
if (spec.valueProp) {
|
|
937
|
+
var value = !spec.isRepeated
|
|
938
|
+
? $$state.props[spec.valueProp]
|
|
939
|
+
: get($$state.props[spec.valueProp], path.slice(1));
|
|
940
|
+
return value;
|
|
941
|
+
}
|
|
942
|
+
else {
|
|
943
|
+
return get($$state.stateValues, path);
|
|
944
|
+
}
|
|
945
|
+
},
|
|
946
|
+
set: function (_t, _p, value) {
|
|
947
|
+
var _a, _b;
|
|
948
|
+
set($$state.stateValues, path, mkUntrackedValue(value));
|
|
949
|
+
if (spec.onChangeProp) {
|
|
950
|
+
(_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, value, path);
|
|
951
|
+
}
|
|
952
|
+
return true;
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
}), {
|
|
956
|
+
registerInitFunc: function (pathStr, f) {
|
|
957
|
+
var _a;
|
|
958
|
+
if ((_a = $$state.statesInstanceBySpec
|
|
959
|
+
.get(pathStr)) === null || _a === void 0 ? void 0 : _a.some(function (_a) {
|
|
960
|
+
var path = _a.path, specKey = _a.specKey;
|
|
961
|
+
return !deepEqual(get($$state.initStateValues, path), f(props, $state, getIndexes(path, $$state.specsByKey[specKey])));
|
|
962
|
+
})) {
|
|
963
|
+
$$state.registrationsQueue.push({ pathStr: pathStr, f: f });
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
})).current;
|
|
967
|
+
// For each spec with an initFunc, evaluate it and see if
|
|
968
|
+
// the init value has changed. If so, reset its state.
|
|
969
|
+
var resetSpecs = [];
|
|
970
|
+
$$state.existingStates.forEach(function (_a) {
|
|
971
|
+
var path = _a.path, specKey = _a.specKey;
|
|
972
|
+
var spec = $$state.specsByKey[specKey];
|
|
973
|
+
if (spec.initFunc) {
|
|
974
|
+
var newInit = spec.initFunc(props, $state, getIndexes(path, spec));
|
|
975
|
+
if (!deepEqual(newInit, get($$state.initStateValues, path))) {
|
|
976
|
+
resetSpecs.push({ path: path, spec: spec });
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
React__default.useLayoutEffect(function () {
|
|
981
|
+
resetSpecs.forEach(function (_a) {
|
|
982
|
+
var _b, _c;
|
|
983
|
+
var path = _a.path, spec = _a.spec;
|
|
984
|
+
var newInit = initializeStateValue($$state, path, spec);
|
|
985
|
+
if (spec.onChangeProp) {
|
|
986
|
+
(_c = (_b = $$state.props)[spec.onChangeProp]) === null || _c === void 0 ? void 0 : _c.call(_b, newInit, path);
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
}, [props, resetSpecs]);
|
|
990
|
+
React__default.useLayoutEffect(function () {
|
|
991
|
+
$$state.registrationsQueue.forEach(function (_a) {
|
|
992
|
+
var f = _a.f, pathStr = _a.pathStr;
|
|
993
|
+
$$state.specsByKey[pathStr].initFunc = f;
|
|
994
|
+
});
|
|
995
|
+
$$state.registrationsQueue = [];
|
|
996
|
+
}, [$$state.registrationsQueue]);
|
|
997
|
+
// Re-render if any value changed in one of these objects
|
|
998
|
+
useSnapshot($$state.stateValues, { sync: true });
|
|
999
|
+
useSnapshot($$state.specsByKey, { sync: true });
|
|
1000
|
+
return $state;
|
|
1001
|
+
}
|
|
1002
|
+
// Simple version of $state useDollarState for read-only
|
|
1003
|
+
function useCanvasDollarState(specs, props) {
|
|
1004
|
+
var e_2, _a;
|
|
1005
|
+
var $$state = proxy({
|
|
1006
|
+
stateValues: {},
|
|
1007
|
+
initStateValues: {},
|
|
1008
|
+
specsByKey: Object.fromEntries(specs.map(function (spec) { return [
|
|
1009
|
+
spec.path,
|
|
1010
|
+
__assign(__assign({}, spec), { pathObj: transformPathStringToObj(spec.path), isRepeated: spec.path.split(".").some(function (part) { return part.endsWith("[]"); }) }),
|
|
1011
|
+
]; })),
|
|
1012
|
+
statesInstanceBySpec: new Map(),
|
|
1013
|
+
existingStates: new Map(),
|
|
1014
|
+
unsubscriptionsByState: {},
|
|
1015
|
+
props: undefined,
|
|
1016
|
+
registrationsQueue: []
|
|
1017
|
+
});
|
|
1018
|
+
$$state.props = mkUntrackedValue(props);
|
|
1019
|
+
var $state = create$StateProxy($$state, function (path, spec) {
|
|
1020
|
+
return {
|
|
1021
|
+
get: function () {
|
|
1022
|
+
return get($$state.stateValues, path);
|
|
1023
|
+
},
|
|
1024
|
+
set: function (_t, _p, value) {
|
|
1025
|
+
var _a, _b;
|
|
1026
|
+
set($$state.stateValues, path, mkUntrackedValue(value));
|
|
1027
|
+
if (spec.onChangeProp) {
|
|
1028
|
+
(_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, value, path);
|
|
1029
|
+
}
|
|
1030
|
+
return true;
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
});
|
|
1034
|
+
try {
|
|
1035
|
+
for (var specs_1 = __values(specs), specs_1_1 = specs_1.next(); !specs_1_1.done; specs_1_1 = specs_1.next()) {
|
|
1036
|
+
var spec = specs_1_1.value;
|
|
1037
|
+
var path = transformPathStringToObj(spec.path);
|
|
1038
|
+
var init = spec.valueProp
|
|
1039
|
+
? $$state.props[spec.valueProp]
|
|
1040
|
+
: spec.initVal
|
|
1041
|
+
? spec.initVal
|
|
1042
|
+
: spec.initFunc
|
|
1043
|
+
? initializeStateValue($$state, path, $$state.specsByKey[spec.path])
|
|
1044
|
+
: undefined;
|
|
1045
|
+
set($state, path, init);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1049
|
+
finally {
|
|
1050
|
+
try {
|
|
1051
|
+
if (specs_1_1 && !specs_1_1.done && (_a = specs_1["return"])) _a.call(specs_1);
|
|
1052
|
+
}
|
|
1053
|
+
finally { if (e_2) throw e_2.error; }
|
|
1054
|
+
}
|
|
1055
|
+
return $state;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
636
1058
|
// Utilities used by generated code
|
|
637
1059
|
var classNames = classNames$1;
|
|
638
1060
|
|
|
639
|
-
export { PlasmicIcon, PlasmicLink, PlasmicSlot, Stack, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, hasVariant, makeFragment, mergeVariantsWithStates, renderPlasmicSlot, useTrigger, wrapWithClassName };
|
|
1061
|
+
export { PlasmicIcon, PlasmicLink, PlasmicSlot, Stack, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, generateStateOnChangeProp, generateStateValueProp, hasVariant, makeFragment, mergeVariantsWithStates, renderPlasmicSlot, set, useCanvasDollarState, useDollarState, useTrigger, wrapWithClassName };
|
|
640
1062
|
//# sourceMappingURL=index.js.map
|