@plasmicapp/react-web 0.2.158 → 0.2.160
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 +11 -4
- package/dist/react-web.cjs.development.js +82 -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 +82 -24
- package/dist/react-web.esm.js.map +1 -1
- package/dist/states/types.d.ts +11 -1
- package/dist/states/valtio.d.ts +1 -3
- package/dist/stories/UseDollarState.stories.d.ts +3 -0
- package/package.json +4 -4
- package/skinny/dist/index.js +76 -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 +1 -3
- package/skinny/dist/stories/UseDollarState.stories.d.ts +3 -0
package/dist/states/types.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
export declare type
|
|
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;
|
|
2
12
|
export declare type ObjectPath = (string | number)[];
|
|
3
13
|
export interface $StateSpec<T> {
|
|
4
14
|
path: string;
|
package/dist/states/valtio.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { $State, $StateSpec } from "./types";
|
|
2
|
-
export declare function useDollarState(specs: $StateSpec<any>[],
|
|
3
|
-
inCanvas: boolean;
|
|
4
|
-
}): $State;
|
|
2
|
+
export declare function useDollarState(specs: $StateSpec<any>[], ...rest: any[]): $State;
|
|
5
3
|
export default useDollarState;
|
|
@@ -58,6 +58,9 @@ 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
|
+
}>;
|
|
61
64
|
export declare const StateCellIsArray: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, {
|
|
62
65
|
people: Person[];
|
|
63
66
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/react-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.160",
|
|
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.
|
|
43
|
+
"@plasmicapp/data-sources": "0.1.38",
|
|
44
44
|
"@plasmicapp/data-sources-context": "0.1.6",
|
|
45
|
-
"@plasmicapp/host": "1.0.
|
|
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": "
|
|
112
|
+
"gitHead": "fe1acf49f45a1c6f14418cd4f3ff62efddb5183d"
|
|
113
113
|
}
|
package/skinny/dist/index.js
CHANGED
|
@@ -1075,7 +1075,7 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
|
|
|
1075
1075
|
stateAccess.add({ path: path, node: node });
|
|
1076
1076
|
var spec = node.getSpec();
|
|
1077
1077
|
if (spec.valueProp) {
|
|
1078
|
-
return $$state.props[spec.valueProp];
|
|
1078
|
+
return $$state.env.$props[spec.valueProp];
|
|
1079
1079
|
}
|
|
1080
1080
|
else if (!node.hasState(path) && spec.initFunc) {
|
|
1081
1081
|
node.createStateCell(path);
|
|
@@ -1090,11 +1090,11 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
|
|
|
1090
1090
|
stateAccess.forEach(function (_a) {
|
|
1091
1091
|
var node = _a.node, path = _a.path;
|
|
1092
1092
|
node.addListener(path, function () {
|
|
1093
|
-
var newValue = initialSpecNode.getSpec().initFunc(
|
|
1093
|
+
var newValue = initialSpecNode.getSpec().initFunc(__assign({ $state: $state }, $$state.env));
|
|
1094
1094
|
set(proxyRoot, initialStatePath, newValue);
|
|
1095
1095
|
});
|
|
1096
1096
|
});
|
|
1097
|
-
var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))(
|
|
1097
|
+
var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))(__assign({ $state: $state }, $$state.env));
|
|
1098
1098
|
initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
|
|
1099
1099
|
var initialSpec = initialSpecNode.getSpec();
|
|
1100
1100
|
var value = initialSpec.isImmutable
|
|
@@ -1103,7 +1103,7 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
|
|
|
1103
1103
|
set(proxyRoot, initialStatePath, value);
|
|
1104
1104
|
//immediately fire onChange
|
|
1105
1105
|
if (initialSpec.onChangeProp) {
|
|
1106
|
-
(_b = (_a = $$state.props)[initialSpec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, initialValue);
|
|
1106
|
+
(_b = (_a = $$state.env.$props)[initialSpec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, initialValue);
|
|
1107
1107
|
}
|
|
1108
1108
|
return initialValue;
|
|
1109
1109
|
}
|
|
@@ -1128,7 +1128,7 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1128
1128
|
//we are always in a leaf, since we only have two cases:
|
|
1129
1129
|
// 1 - delete properties outside the state tree
|
|
1130
1130
|
// 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
|
|
1131
|
-
(_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, get(proxyRoot, currPath.slice(spec.pathObj.length)));
|
|
1131
|
+
(_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, get(proxyRoot, currPath.slice(spec.pathObj.length)));
|
|
1132
1132
|
}
|
|
1133
1133
|
var nextPath = getNextPath(property);
|
|
1134
1134
|
var nextNode = currNode.makeTransition(property);
|
|
@@ -1162,7 +1162,7 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1162
1162
|
return Reflect.get(target, property, receiver);
|
|
1163
1163
|
},
|
|
1164
1164
|
set: function (target, property, value, receiver) {
|
|
1165
|
-
var _a, _b;
|
|
1165
|
+
var _a, _b, _c, _d;
|
|
1166
1166
|
var nextPath = getNextPath(property);
|
|
1167
1167
|
var nextNode = currNode.makeTransition(property);
|
|
1168
1168
|
if (property === "registerInitFunc" && currPath.length === 0) {
|
|
@@ -1194,12 +1194,19 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1194
1194
|
else {
|
|
1195
1195
|
Reflect.set(target, property, value, receiver);
|
|
1196
1196
|
}
|
|
1197
|
-
|
|
1198
|
-
var _a, _b;
|
|
1197
|
+
if (currNode.isLeaf()) {
|
|
1199
1198
|
if (spec.onChangeProp) {
|
|
1200
|
-
(
|
|
1199
|
+
(_d = (_c = $$state.env.$props)[spec.onChangeProp]) === null || _d === void 0 ? void 0 : _d.call(_c, target);
|
|
1201
1200
|
}
|
|
1202
|
-
}
|
|
1201
|
+
}
|
|
1202
|
+
else {
|
|
1203
|
+
nextNode.getAllSpecs().forEach(function (spec) {
|
|
1204
|
+
var _a, _b;
|
|
1205
|
+
if (spec.onChangeProp) {
|
|
1206
|
+
(_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, value);
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1203
1210
|
var newValue = (isOutside || currNode.isLeaf()) && currNode.getSpec().isImmutable
|
|
1204
1211
|
? mkUntrackedValue(value)
|
|
1205
1212
|
: value;
|
|
@@ -1236,22 +1243,69 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1236
1243
|
var mkUntrackedValue = function (o) {
|
|
1237
1244
|
return o != null && typeof o === "object" ? ref(o) : o;
|
|
1238
1245
|
};
|
|
1239
|
-
|
|
1246
|
+
var envFieldsAreNonNill = function (env) {
|
|
1247
|
+
var _a, _b;
|
|
1248
|
+
return ({
|
|
1249
|
+
$props: env.$props,
|
|
1250
|
+
$ctx: (_a = env.$ctx) !== null && _a !== void 0 ? _a : {},
|
|
1251
|
+
$queries: (_b = env.$queries) !== null && _b !== void 0 ? _b : {}
|
|
1252
|
+
});
|
|
1253
|
+
};
|
|
1254
|
+
/**
|
|
1255
|
+
* We need to support two versions with different parameters to be backward compatible
|
|
1256
|
+
* {
|
|
1257
|
+
* specs: $StateSpec<any>[],
|
|
1258
|
+
* props: Record<string, any>,
|
|
1259
|
+
* $ctx?: Record<string, any>,
|
|
1260
|
+
* opts?: { inCanvas: boolean; }
|
|
1261
|
+
* }
|
|
1262
|
+
* {
|
|
1263
|
+
* specs: $StateSpec<any>[],
|
|
1264
|
+
* env: { $props; $queries; $ctx },
|
|
1265
|
+
* opts?: { inCanvas: boolean }
|
|
1266
|
+
* }
|
|
1267
|
+
*/
|
|
1268
|
+
function extractDollarStateParametersBackwardCompatible() {
|
|
1269
|
+
var rest = [];
|
|
1270
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1271
|
+
rest[_i] = arguments[_i];
|
|
1272
|
+
}
|
|
1273
|
+
if ("$props" in rest[0]) {
|
|
1274
|
+
// latest version
|
|
1275
|
+
return {
|
|
1276
|
+
env: rest[0],
|
|
1277
|
+
opts: rest[1]
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
else {
|
|
1281
|
+
return {
|
|
1282
|
+
env: {
|
|
1283
|
+
$props: rest[0],
|
|
1284
|
+
$ctx: rest[1],
|
|
1285
|
+
$queries: {}
|
|
1286
|
+
},
|
|
1287
|
+
opts: rest[2]
|
|
1288
|
+
};
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
function useDollarState(specs) {
|
|
1292
|
+
var rest = [];
|
|
1293
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1294
|
+
rest[_i - 1] = arguments[_i];
|
|
1295
|
+
}
|
|
1296
|
+
var _a = extractDollarStateParametersBackwardCompatible.apply(void 0, __spreadArray([], __read(rest), false)), env = _a.env, opts = _a.opts;
|
|
1240
1297
|
var $$state = React__default.useRef((function () {
|
|
1241
1298
|
var rootSpecTree = buildTree(specs);
|
|
1242
1299
|
return {
|
|
1243
1300
|
rootSpecTree: rootSpecTree,
|
|
1244
1301
|
specTreeLeaves: getStateCells(rootSpecTree),
|
|
1245
1302
|
stateValues: proxy({}),
|
|
1246
|
-
|
|
1247
|
-
ctx: {},
|
|
1303
|
+
env: envFieldsAreNonNill(env),
|
|
1248
1304
|
specs: [],
|
|
1249
1305
|
registrationsQueue: proxy([])
|
|
1250
1306
|
};
|
|
1251
1307
|
})()).current;
|
|
1252
|
-
$$state.
|
|
1253
|
-
$$state.ctx = $ctx !== null && $ctx !== void 0 ? $ctx : {};
|
|
1254
|
-
$$state.specs = specs;
|
|
1308
|
+
($$state.env = envFieldsAreNonNill(env)), ($$state.specs = specs);
|
|
1255
1309
|
var create$State = function () {
|
|
1256
1310
|
var $state = Object.assign(create$StateProxy($$state, function (node, path) {
|
|
1257
1311
|
if (!node.hasState(path)) {
|
|
@@ -1268,7 +1322,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
1268
1322
|
get: function (target, property, receiver) {
|
|
1269
1323
|
var spec = node.getSpec();
|
|
1270
1324
|
if (spec.valueProp) {
|
|
1271
|
-
return $$state.props[spec.valueProp];
|
|
1325
|
+
return $$state.env.$props[spec.valueProp];
|
|
1272
1326
|
}
|
|
1273
1327
|
else {
|
|
1274
1328
|
return Reflect.get(target, property, receiver);
|
|
@@ -1281,7 +1335,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
1281
1335
|
if (!node.hasState(realPath)) {
|
|
1282
1336
|
node.createStateCell(realPath);
|
|
1283
1337
|
}
|
|
1284
|
-
if (!deepEqual(node.getState(realPath).initialValue, f(
|
|
1338
|
+
if (!deepEqual(node.getState(realPath).initialValue, f(__assign({ $state: $state }, $$state.env)))) {
|
|
1285
1339
|
$$state.registrationsQueue.push(mkUntrackedValue({ node: node, path: realPath, f: f }));
|
|
1286
1340
|
}
|
|
1287
1341
|
}
|
|
@@ -1315,7 +1369,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
1315
1369
|
}
|
|
1316
1370
|
node.createStateCell(spec.pathObj);
|
|
1317
1371
|
var init = spec.valueProp
|
|
1318
|
-
? $$state.props[spec.valueProp]
|
|
1372
|
+
? $$state.env.$props[spec.valueProp]
|
|
1319
1373
|
: spec.initFunc
|
|
1320
1374
|
? initializeStateValue($$state, node, spec.pathObj, $state)
|
|
1321
1375
|
: spec.initVal;
|
|
@@ -1331,7 +1385,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
1331
1385
|
var node = _a.node, stateCell = _a.stateCell;
|
|
1332
1386
|
var initFunc = node.getInitFunc(stateCell);
|
|
1333
1387
|
if (initFunc) {
|
|
1334
|
-
var newInit = initFunc(
|
|
1388
|
+
var newInit = initFunc(__assign({ $state: $state }, envFieldsAreNonNill(env)));
|
|
1335
1389
|
if (!deepEqual(newInit, stateCell.initialValue)) {
|
|
1336
1390
|
resetSpecs.push({ stateCell: stateCell, node: node });
|
|
1337
1391
|
}
|
|
@@ -1342,7 +1396,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
1342
1396
|
var newInit = initializeStateValue($$state, node, stateCell.path, $state);
|
|
1343
1397
|
var spec = node.getSpec();
|
|
1344
1398
|
if (spec.onChangeProp) {
|
|
1345
|
-
(_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, newInit);
|
|
1399
|
+
(_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, newInit);
|
|
1346
1400
|
}
|
|
1347
1401
|
};
|
|
1348
1402
|
useIsomorphicLayoutEffect(function () {
|
|
@@ -1350,7 +1404,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
1350
1404
|
var stateCell = _a.stateCell, node = _a.node;
|
|
1351
1405
|
reInitializeState(node, stateCell);
|
|
1352
1406
|
});
|
|
1353
|
-
}, [props, resetSpecs]);
|
|
1407
|
+
}, [env.$props, resetSpecs]);
|
|
1354
1408
|
useIsomorphicLayoutEffect(function () {
|
|
1355
1409
|
while ($$state.registrationsQueue.length) {
|
|
1356
1410
|
var _a = $$state.registrationsQueue.shift(), node = _a.node, path = _a.path, f = _a.f;
|