@plasmicapp/react-web 0.2.145 → 0.2.146

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.
@@ -25,10 +25,7 @@ export declare class StateSpecNode<T> {
25
25
  getState(path: ObjectPath): StateCell<T>;
26
26
  getInitFunc(stateCell: StateCell<any>): InitFunc<any> | undefined;
27
27
  clearStates(): void;
28
- states(): {
29
- path: any;
30
- stateCell: StateCell<T>;
31
- }[];
28
+ states(): StateCell<T>[];
32
29
  hasState(path: ObjectPath): boolean;
33
30
  createStateCell(path: ObjectPath): void;
34
31
  setInitialValue(path: ObjectPath, value: any): void;
@@ -3,7 +3,15 @@ import { $State, ObjectPath } from "./types";
3
3
  export declare function generateStateOnChangeProp($state: $State, path: ObjectPath): (val: any) => void;
4
4
  export declare function generateStateValueProp($state: $State, path: ObjectPath): any;
5
5
  export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
6
- export declare function isPlasmicStateProxy(obj: any): any;
6
+ export declare function isPlasmicStateProxy(obj: any): boolean;
7
+ export declare function getStateCellsInPlasmicProxy(obj: any): {
8
+ realPath: ObjectPath;
9
+ path: string;
10
+ }[];
11
+ export declare function getStateSpecInPlasmicProxy(obj: any, path: ObjectPath): {
12
+ spec: import("./types").Internal$StateSpec<any>;
13
+ isImplicitStateArray: boolean;
14
+ } | undefined;
7
15
  export declare function shallowEqual<T>(a1: T[], a2: T[]): boolean;
8
16
  /**
9
17
  * Shallow comparison of arrays.
@@ -1,4 +1,4 @@
1
1
  export { default as get } from "dlv";
2
- export { generateStateOnChangeProp, generateStateValueProp, isPlasmicStateProxy, set, } from "./helpers";
3
- export { $State } from "./types";
2
+ export { generateStateOnChangeProp, generateStateValueProp, getStateCellsInPlasmicProxy, getStateSpecInPlasmicProxy, isPlasmicStateProxy, set, } from "./helpers";
3
+ export { $State, $StateSpec } from "./types";
4
4
  export { useDollarState } from "./valtio";
@@ -8,6 +8,7 @@ export interface $StateSpec<T> {
8
8
  valueProp?: string;
9
9
  onChangeProp?: string;
10
10
  isImmutable?: boolean;
11
+ variableType: "text" | "number" | "boolean" | "array" | "object" | "variant";
11
12
  }
12
13
  export interface $State {
13
14
  [key: string]: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/react-web",
3
- "version": "0.2.145",
3
+ "version": "0.2.146",
4
4
  "description": "plasmic library for rendering in the presentational style",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -109,5 +109,5 @@
109
109
  "react": ">=16.8.0",
110
110
  "react-dom": ">=16.8.0"
111
111
  },
112
- "gitHead": "cbf237ebd479221a7de2947b2d8179133fec5ed5"
112
+ "gitHead": "6c3d1c42af2561ca3ff9059e7a8b311fdb7f3c93"
113
113
  }
@@ -728,95 +728,6 @@ function useTrigger(trigger, opts) {
728
728
  var ARRAY_SYMBOL = Symbol("[]");
729
729
  var PLASMIC_STATE_PROXY_SYMBOL = Symbol("plasmic.state.proxy");
730
730
 
731
- function generateStateOnChangeProp($state, path) {
732
- return function (val) { return set($state, path, val); };
733
- }
734
- function generateStateValueProp($state, path) {
735
- return get($state, path);
736
- }
737
- var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
738
- function isPlasmicStateProxy(obj) {
739
- return (obj != null && typeof obj === "object" && obj[PLASMIC_STATE_PROXY_SYMBOL]);
740
- }
741
- function shallowEqual(a1, a2) {
742
- if (a1.length !== a2.length) {
743
- return false;
744
- }
745
- for (var i = 0; i < a1.length; i++) {
746
- if (a1[i] !== a2[i]) {
747
- return false;
748
- }
749
- }
750
- return true;
751
- }
752
- /**
753
- * Shallow comparison of arrays.
754
- */
755
- function arrayEq(xs, ys) {
756
- return (xs.length === ys.length && xs.every(function (_, index) { return xs[index] === ys[index]; }));
757
- }
758
- function isNum$1(value) {
759
- return typeof value === "symbol" ? false : !isNaN(+value);
760
- }
761
- function assert(cond, msg) {
762
- if (msg === void 0) { msg = "Assertion failed"; }
763
- if (!cond) {
764
- // We always generate an non empty message so that it doesn't get swallowed
765
- // by the async library.
766
- msg = (typeof msg === "string" ? msg : msg()) || "Assertion failed";
767
- debugger;
768
- throw new Error(msg);
769
- }
770
- }
771
- /**
772
- * Forked from https://github.com/lukeed/dset
773
- * Changes: fixed setting a deep value to a proxy object
774
- */
775
- function set(obj, keys, val) {
776
- keys = keys.split ? keys.split(".") : keys;
777
- var i = 0, l = keys.length, t = obj, x, k;
778
- while (i < l) {
779
- k = keys[i++];
780
- if (k === "__proto__" || k === "constructor" || k === "prototype")
781
- break;
782
- var newValue = i === l
783
- ? val
784
- : typeof (x = t[k]) === typeof keys
785
- ? x
786
- : keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")
787
- ? {}
788
- : [];
789
- assignValue(t, k, newValue);
790
- t = t[k];
791
- }
792
- }
793
- /**
794
- * Forked from lodash
795
- */
796
- function baseAssignValue(object, key, value) {
797
- if (key == "__proto__") {
798
- Object.defineProperty(object, key, {
799
- configurable: true,
800
- enumerable: true,
801
- value: value,
802
- writable: true
803
- });
804
- }
805
- else {
806
- object[key] = value;
807
- }
808
- }
809
- function eq(value, other) {
810
- return value === other || (value !== value && other !== other);
811
- }
812
- function assignValue(object, key, value) {
813
- var objValue = object[key];
814
- if (!(Object.prototype.hasOwnProperty.call(object, key) && eq(objValue, value)) ||
815
- (value === undefined && !(key in object))) {
816
- baseAssignValue(object, key, value);
817
- }
818
- }
819
-
820
731
  var UNINITIALIZED = Symbol("plasmic.unitialized");
821
732
  var StateSpecNode = /** @class */ (function () {
822
733
  function StateSpecNode(specs) {
@@ -872,13 +783,7 @@ var StateSpecNode = /** @class */ (function () {
872
783
  this._state = {};
873
784
  };
874
785
  StateSpecNode.prototype.states = function () {
875
- return Object.entries(this._state).map(function (_a) {
876
- var _b = __read(_a, 2), key = _b[0], stateCell = _b[1];
877
- return ({
878
- path: JSON.parse(key),
879
- stateCell: stateCell
880
- });
881
- });
786
+ return Object.values(this._state);
882
787
  };
883
788
  StateSpecNode.prototype.hasState = function (path) {
884
789
  var key = JSON.stringify(path);
@@ -1020,6 +925,125 @@ function findStateCell(root, pathStr, repetitionIndex) {
1020
925
  };
1021
926
  }
1022
927
 
928
+ function generateStateOnChangeProp($state, path) {
929
+ return function (val) { return set($state, path, val); };
930
+ }
931
+ function generateStateValueProp($state, path) {
932
+ return get($state, path);
933
+ }
934
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
935
+ function isPlasmicStateProxy(obj) {
936
+ return (obj != null && typeof obj === "object" && !!obj[PLASMIC_STATE_PROXY_SYMBOL]);
937
+ }
938
+ function getStateCellsInPlasmicProxy(obj) {
939
+ if (!isPlasmicStateProxy(obj)) {
940
+ return [];
941
+ }
942
+ var _a = obj[PLASMIC_STATE_PROXY_SYMBOL], rootNode = _a.node, rootPath = _a.path, isOutside = _a.isOutside;
943
+ if (isOutside) {
944
+ return [];
945
+ }
946
+ return getStateCells(rootNode).flatMap(function (node) {
947
+ return node.states().map(function (stateCell) { return ({
948
+ path: node.getSpec().path,
949
+ realPath: stateCell.path.slice(rootPath.length)
950
+ }); });
951
+ });
952
+ }
953
+ function getStateSpecInPlasmicProxy(obj, path) {
954
+ obj = get(obj, path.slice(0, path.length - 1));
955
+ if (!isPlasmicStateProxy(obj)) {
956
+ return undefined;
957
+ }
958
+ var _a = obj[PLASMIC_STATE_PROXY_SYMBOL], node = _a.node, isOutside = _a.isOutside;
959
+ var nextNode = node.makeTransition(path[path.length - 1]);
960
+ if (isOutside || node.isLeaf() || !nextNode) {
961
+ return undefined;
962
+ }
963
+ return {
964
+ spec: nextNode.getSpec(),
965
+ isImplicitStateArray: nextNode.hasArrayTransition()
966
+ };
967
+ }
968
+ function shallowEqual(a1, a2) {
969
+ if (a1.length !== a2.length) {
970
+ return false;
971
+ }
972
+ for (var i = 0; i < a1.length; i++) {
973
+ if (a1[i] !== a2[i]) {
974
+ return false;
975
+ }
976
+ }
977
+ return true;
978
+ }
979
+ /**
980
+ * Shallow comparison of arrays.
981
+ */
982
+ function arrayEq(xs, ys) {
983
+ return (xs.length === ys.length && xs.every(function (_, index) { return xs[index] === ys[index]; }));
984
+ }
985
+ function isNum$1(value) {
986
+ return typeof value === "symbol" ? false : !isNaN(+value);
987
+ }
988
+ function assert(cond, msg) {
989
+ if (msg === void 0) { msg = "Assertion failed"; }
990
+ if (!cond) {
991
+ // We always generate an non empty message so that it doesn't get swallowed
992
+ // by the async library.
993
+ msg = (typeof msg === "string" ? msg : msg()) || "Assertion failed";
994
+ debugger;
995
+ throw new Error(msg);
996
+ }
997
+ }
998
+ /**
999
+ * Forked from https://github.com/lukeed/dset
1000
+ * Changes: fixed setting a deep value to a proxy object
1001
+ */
1002
+ function set(obj, keys, val) {
1003
+ keys = keys.split ? keys.split(".") : keys;
1004
+ var i = 0, l = keys.length, t = obj, x, k;
1005
+ while (i < l) {
1006
+ k = keys[i++];
1007
+ if (k === "__proto__" || k === "constructor" || k === "prototype")
1008
+ break;
1009
+ var newValue = i === l
1010
+ ? val
1011
+ : typeof (x = t[k]) === typeof keys
1012
+ ? x
1013
+ : keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")
1014
+ ? {}
1015
+ : [];
1016
+ assignValue(t, k, newValue);
1017
+ t = t[k];
1018
+ }
1019
+ }
1020
+ /**
1021
+ * Forked from lodash
1022
+ */
1023
+ function baseAssignValue(object, key, value) {
1024
+ if (key == "__proto__") {
1025
+ Object.defineProperty(object, key, {
1026
+ configurable: true,
1027
+ enumerable: true,
1028
+ value: value,
1029
+ writable: true
1030
+ });
1031
+ }
1032
+ else {
1033
+ object[key] = value;
1034
+ }
1035
+ }
1036
+ function eq(value, other) {
1037
+ return value === other || (value !== value && other !== other);
1038
+ }
1039
+ function assignValue(object, key, value) {
1040
+ var objValue = object[key];
1041
+ if (!(Object.prototype.hasOwnProperty.call(object, key) && eq(objValue, value)) ||
1042
+ (value === undefined && !(key in object))) {
1043
+ baseAssignValue(object, key, value);
1044
+ }
1045
+ }
1046
+
1023
1047
  function isNum(value) {
1024
1048
  return typeof value === "symbol" ? false : !isNaN(+value);
1025
1049
  }
@@ -1093,7 +1117,11 @@ function create$StateProxy($$state, leafHandlers) {
1093
1117
  get: function (target, property, receiver) {
1094
1118
  var _a, _b;
1095
1119
  if (property === PLASMIC_STATE_PROXY_SYMBOL) {
1096
- return true;
1120
+ return {
1121
+ node: currNode,
1122
+ path: currPath,
1123
+ isOutside: isOutside
1124
+ };
1097
1125
  }
1098
1126
  var nextPath = getNextPath(property);
1099
1127
  if (isOutside || currNode.isLeaf()) {
@@ -1273,12 +1301,7 @@ function useDollarState(specs, props, $ctx, opts) {
1273
1301
  // the init value has changed. If so, reset its state.
1274
1302
  var resetSpecs = [];
1275
1303
  $$state.specTreeLeaves
1276
- .flatMap(function (node) {
1277
- return node.states().map(function (_a) {
1278
- var stateCell = _a.stateCell;
1279
- return ({ stateCell: stateCell, node: node });
1280
- });
1281
- })
1304
+ .flatMap(function (node) { return node.states().map(function (stateCell) { return ({ stateCell: stateCell, node: node }); }); })
1282
1305
  .forEach(function (_a) {
1283
1306
  var node = _a.node, stateCell = _a.stateCell;
1284
1307
  var initFunc = node.getInitFunc(stateCell);
@@ -1330,5 +1353,5 @@ function useDollarState(specs, props, $ctx, opts) {
1330
1353
  // Utilities used by generated code
1331
1354
  var classNames = classNames$1;
1332
1355
 
1333
- export { PlasmicIcon, PlasmicLink, PlasmicPageGuard, PlasmicSlot, Stack, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, generateStateOnChangeProp, generateStateValueProp, hasVariant, isPlasmicStateProxy, makeFragment, mergeVariantsWithStates, renderPlasmicSlot, set, useDollarState, useTrigger, wrapWithClassName };
1356
+ export { PlasmicIcon, PlasmicLink, PlasmicPageGuard, PlasmicSlot, Stack, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, generateStateOnChangeProp, generateStateValueProp, getStateCellsInPlasmicProxy, getStateSpecInPlasmicProxy, hasVariant, isPlasmicStateProxy, makeFragment, mergeVariantsWithStates, renderPlasmicSlot, set, useDollarState, useTrigger, wrapWithClassName };
1334
1357
  //# sourceMappingURL=index.js.map