@plasmicapp/react-web 0.2.157 → 0.2.159

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.
@@ -1,14 +1,4 @@
1
- export declare type InitFuncEnv = {
2
- $props: Record<string, any>;
3
- $state: Record<string, any>;
4
- $queries?: Record<string, any>;
5
- $ctx?: Record<string, any>;
6
- };
7
- export declare type DollarStateEnv = Omit<InitFuncEnv, "$state">;
8
- export declare type NoUndefinedField<T> = {
9
- [P in keyof T]-?: T[P];
10
- };
11
- export declare type InitFunc<T> = (env: NoUndefinedField<InitFuncEnv>) => T;
1
+ export declare type InitFunc<T> = ($props: Record<string, any>, $state: $State, $ctx: Record<string, any>, indexes?: number[]) => T;
12
2
  export declare type ObjectPath = (string | number)[];
13
3
  export interface $StateSpec<T> {
14
4
  path: string;
@@ -1,5 +1,5 @@
1
- import { $State, $StateSpec, DollarStateEnv } from "./types";
2
- export declare function useDollarState(specs: $StateSpec<any>[], env: DollarStateEnv, opts?: {
1
+ import { $State, $StateSpec } from "./types";
2
+ export declare function useDollarState(specs: $StateSpec<any>[], props: Record<string, any>, $ctx?: Record<string, any>, opts?: {
3
3
  inCanvas: boolean;
4
4
  }): $State;
5
5
  export default useDollarState;
@@ -58,9 +58,6 @@ interface Person {
58
58
  export declare const FormBuilder: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, {
59
59
  people: Person[];
60
60
  }>;
61
- export declare const FormBuilderImplicitStates: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, {
62
- people: Person[];
63
- }>;
64
61
  export declare const StateCellIsArray: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, {
65
62
  people: Person[];
66
63
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/react-web",
3
- "version": "0.2.157",
3
+ "version": "0.2.159",
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,9 +40,9 @@
40
40
  },
41
41
  "prettier": {},
42
42
  "dependencies": {
43
- "@plasmicapp/data-sources": "0.1.37",
43
+ "@plasmicapp/data-sources": "0.1.38",
44
44
  "@plasmicapp/data-sources-context": "0.1.6",
45
- "@plasmicapp/host": "1.0.106",
45
+ "@plasmicapp/host": "1.0.107",
46
46
  "@plasmicapp/query": "0.1.61",
47
47
  "@react-aria/checkbox": "^3.5.0",
48
48
  "@react-aria/focus": "^3.7.0",
@@ -109,5 +109,5 @@
109
109
  "react": ">=16.8.0",
110
110
  "react-dom": ">=16.8.0"
111
111
  },
112
- "gitHead": "64f5e28630820046b17012ad59e544061dade419"
112
+ "gitHead": "c37c2f944f1fc0572fd11293d56313fb52a1720b"
113
113
  }
@@ -2,7 +2,7 @@ import React from "react";
2
2
  interface PlasmicPageGuardProps {
3
3
  appId: string;
4
4
  authorizeEndpoint: string;
5
- minRole: string;
5
+ minRole?: string;
6
6
  canTriggerLogin: boolean;
7
7
  children: React.ReactNode;
8
8
  }
@@ -79,6 +79,9 @@ function PlasmicPageGuard(props) {
79
79
  }
80
80
  }, [dataSourceCtxValue, appId, authorizeEndpoint, canTriggerLogin]);
81
81
  function canUserViewPage() {
82
+ if (!minRole) {
83
+ return true;
84
+ }
82
85
  if (!dataSourceCtxValue) {
83
86
  return false;
84
87
  }
@@ -1072,7 +1075,7 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
1072
1075
  stateAccess.add({ path: path, node: node });
1073
1076
  var spec = node.getSpec();
1074
1077
  if (spec.valueProp) {
1075
- return $$state.env.$props[spec.valueProp];
1078
+ return $$state.props[spec.valueProp];
1076
1079
  }
1077
1080
  else if (!node.hasState(path) && spec.initFunc) {
1078
1081
  node.createStateCell(path);
@@ -1087,11 +1090,11 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
1087
1090
  stateAccess.forEach(function (_a) {
1088
1091
  var node = _a.node, path = _a.path;
1089
1092
  node.addListener(path, function () {
1090
- var newValue = initialSpecNode.getSpec().initFunc(__assign({ $state: $state }, $$state.env));
1093
+ var newValue = initialSpecNode.getSpec().initFunc($$state.props, $state, $$state.ctx);
1091
1094
  set(proxyRoot, initialStatePath, newValue);
1092
1095
  });
1093
1096
  });
1094
- var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))(__assign({ $state: $state }, $$state.env));
1097
+ var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))($$state.props, $state, $$state.ctx);
1095
1098
  initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
1096
1099
  var initialSpec = initialSpecNode.getSpec();
1097
1100
  var value = initialSpec.isImmutable
@@ -1100,7 +1103,7 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
1100
1103
  set(proxyRoot, initialStatePath, value);
1101
1104
  //immediately fire onChange
1102
1105
  if (initialSpec.onChangeProp) {
1103
- (_b = (_a = $$state.env.$props)[initialSpec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, initialValue);
1106
+ (_b = (_a = $$state.props)[initialSpec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, initialValue);
1104
1107
  }
1105
1108
  return initialValue;
1106
1109
  }
@@ -1125,7 +1128,7 @@ function create$StateProxy($$state, leafHandlers) {
1125
1128
  //we are always in a leaf, since we only have two cases:
1126
1129
  // 1 - delete properties outside the state tree
1127
1130
  // 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
1128
- (_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, get(proxyRoot, currPath.slice(spec.pathObj.length)));
1131
+ (_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, get(proxyRoot, currPath.slice(spec.pathObj.length)));
1129
1132
  }
1130
1133
  var nextPath = getNextPath(property);
1131
1134
  var nextNode = currNode.makeTransition(property);
@@ -1159,7 +1162,7 @@ function create$StateProxy($$state, leafHandlers) {
1159
1162
  return Reflect.get(target, property, receiver);
1160
1163
  },
1161
1164
  set: function (target, property, value, receiver) {
1162
- var _a, _b, _c, _d;
1165
+ var _a, _b;
1163
1166
  var nextPath = getNextPath(property);
1164
1167
  var nextNode = currNode.makeTransition(property);
1165
1168
  if (property === "registerInitFunc" && currPath.length === 0) {
@@ -1191,19 +1194,12 @@ function create$StateProxy($$state, leafHandlers) {
1191
1194
  else {
1192
1195
  Reflect.set(target, property, value, receiver);
1193
1196
  }
1194
- if (currNode.isLeaf()) {
1197
+ nextNode.getAllSpecs().forEach(function (spec) {
1198
+ var _a, _b;
1195
1199
  if (spec.onChangeProp) {
1196
- (_d = (_c = $$state.env.$props)[spec.onChangeProp]) === null || _d === void 0 ? void 0 : _d.call(_c, target);
1200
+ (_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, value);
1197
1201
  }
1198
- }
1199
- else {
1200
- nextNode.getAllSpecs().forEach(function (spec) {
1201
- var _a, _b;
1202
- if (spec.onChangeProp) {
1203
- (_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, value);
1204
- }
1205
- });
1206
- }
1202
+ });
1207
1203
  var newValue = (isOutside || currNode.isLeaf()) && currNode.getSpec().isImmutable
1208
1204
  ? mkUntrackedValue(value)
1209
1205
  : value;
@@ -1240,27 +1236,22 @@ function create$StateProxy($$state, leafHandlers) {
1240
1236
  var mkUntrackedValue = function (o) {
1241
1237
  return o != null && typeof o === "object" ? ref(o) : o;
1242
1238
  };
1243
- var envFieldsAreNonNill = function (env) {
1244
- var _a, _b;
1245
- return ({
1246
- $props: env.$props,
1247
- $ctx: (_a = env.$ctx) !== null && _a !== void 0 ? _a : {},
1248
- $queries: (_b = env.$queries) !== null && _b !== void 0 ? _b : {}
1249
- });
1250
- };
1251
- function useDollarState(specs, env, opts) {
1239
+ function useDollarState(specs, props, $ctx, opts) {
1252
1240
  var $$state = React__default.useRef((function () {
1253
1241
  var rootSpecTree = buildTree(specs);
1254
1242
  return {
1255
1243
  rootSpecTree: rootSpecTree,
1256
1244
  specTreeLeaves: getStateCells(rootSpecTree),
1257
1245
  stateValues: proxy({}),
1258
- env: envFieldsAreNonNill(env),
1246
+ props: {},
1247
+ ctx: {},
1259
1248
  specs: [],
1260
1249
  registrationsQueue: proxy([])
1261
1250
  };
1262
1251
  })()).current;
1263
- ($$state.env = envFieldsAreNonNill(env)), ($$state.specs = specs);
1252
+ $$state.props = props;
1253
+ $$state.ctx = $ctx !== null && $ctx !== void 0 ? $ctx : {};
1254
+ $$state.specs = specs;
1264
1255
  var create$State = function () {
1265
1256
  var $state = Object.assign(create$StateProxy($$state, function (node, path) {
1266
1257
  if (!node.hasState(path)) {
@@ -1277,7 +1268,7 @@ function useDollarState(specs, env, opts) {
1277
1268
  get: function (target, property, receiver) {
1278
1269
  var spec = node.getSpec();
1279
1270
  if (spec.valueProp) {
1280
- return $$state.env.$props[spec.valueProp];
1271
+ return $$state.props[spec.valueProp];
1281
1272
  }
1282
1273
  else {
1283
1274
  return Reflect.get(target, property, receiver);
@@ -1290,7 +1281,7 @@ function useDollarState(specs, env, opts) {
1290
1281
  if (!node.hasState(realPath)) {
1291
1282
  node.createStateCell(realPath);
1292
1283
  }
1293
- if (!deepEqual(node.getState(realPath).initialValue, f(__assign({ $state: $state }, $$state.env)))) {
1284
+ if (!deepEqual(node.getState(realPath).initialValue, f($$state.props, $state, $$state.ctx))) {
1294
1285
  $$state.registrationsQueue.push(mkUntrackedValue({ node: node, path: realPath, f: f }));
1295
1286
  }
1296
1287
  }
@@ -1324,7 +1315,7 @@ function useDollarState(specs, env, opts) {
1324
1315
  }
1325
1316
  node.createStateCell(spec.pathObj);
1326
1317
  var init = spec.valueProp
1327
- ? $$state.env.$props[spec.valueProp]
1318
+ ? $$state.props[spec.valueProp]
1328
1319
  : spec.initFunc
1329
1320
  ? initializeStateValue($$state, node, spec.pathObj, $state)
1330
1321
  : spec.initVal;
@@ -1340,7 +1331,7 @@ function useDollarState(specs, env, opts) {
1340
1331
  var node = _a.node, stateCell = _a.stateCell;
1341
1332
  var initFunc = node.getInitFunc(stateCell);
1342
1333
  if (initFunc) {
1343
- var newInit = initFunc(__assign({ $state: $state }, envFieldsAreNonNill(env)));
1334
+ var newInit = initFunc(props, $state, $ctx !== null && $ctx !== void 0 ? $ctx : {});
1344
1335
  if (!deepEqual(newInit, stateCell.initialValue)) {
1345
1336
  resetSpecs.push({ stateCell: stateCell, node: node });
1346
1337
  }
@@ -1351,7 +1342,7 @@ function useDollarState(specs, env, opts) {
1351
1342
  var newInit = initializeStateValue($$state, node, stateCell.path, $state);
1352
1343
  var spec = node.getSpec();
1353
1344
  if (spec.onChangeProp) {
1354
- (_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, newInit);
1345
+ (_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, newInit);
1355
1346
  }
1356
1347
  };
1357
1348
  useIsomorphicLayoutEffect(function () {
@@ -1359,7 +1350,7 @@ function useDollarState(specs, env, opts) {
1359
1350
  var stateCell = _a.stateCell, node = _a.node;
1360
1351
  reInitializeState(node, stateCell);
1361
1352
  });
1362
- }, [env.$props, resetSpecs]);
1353
+ }, [props, resetSpecs]);
1363
1354
  useIsomorphicLayoutEffect(function () {
1364
1355
  while ($$state.registrationsQueue.length) {
1365
1356
  var _a = $$state.registrationsQueue.shift(), node = _a.node, path = _a.path, f = _a.f;