@plasmicapp/react-web 0.2.156 → 0.2.157
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 +12 -2
- package/dist/react-web.cjs.development.js +44 -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 +44 -24
- package/dist/react-web.esm.js.map +1 -1
- package/dist/states/types.d.ts +11 -1
- package/dist/states/valtio.d.ts +2 -2
- package/dist/stories/UseDollarState.stories.d.ts +3 -0
- package/package.json +4 -4
- package/skinny/dist/index.js +34 -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 +2 -2
- 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,5 @@
|
|
|
1
|
-
import { $State, $StateSpec } from "./types";
|
|
2
|
-
export declare function useDollarState(specs: $StateSpec<any>[],
|
|
1
|
+
import { $State, $StateSpec, DollarStateEnv } from "./types";
|
|
2
|
+
export declare function useDollarState(specs: $StateSpec<any>[], env: DollarStateEnv, opts?: {
|
|
3
3
|
inCanvas: boolean;
|
|
4
4
|
}): $State;
|
|
5
5
|
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.157",
|
|
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.37",
|
|
44
44
|
"@plasmicapp/data-sources-context": "0.1.6",
|
|
45
|
-
"@plasmicapp/host": "1.0.
|
|
45
|
+
"@plasmicapp/host": "1.0.106",
|
|
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": "64f5e28630820046b17012ad59e544061dade419"
|
|
113
113
|
}
|
package/skinny/dist/index.js
CHANGED
|
@@ -1072,7 +1072,7 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
|
|
|
1072
1072
|
stateAccess.add({ path: path, node: node });
|
|
1073
1073
|
var spec = node.getSpec();
|
|
1074
1074
|
if (spec.valueProp) {
|
|
1075
|
-
return $$state.props[spec.valueProp];
|
|
1075
|
+
return $$state.env.$props[spec.valueProp];
|
|
1076
1076
|
}
|
|
1077
1077
|
else if (!node.hasState(path) && spec.initFunc) {
|
|
1078
1078
|
node.createStateCell(path);
|
|
@@ -1087,11 +1087,11 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
|
|
|
1087
1087
|
stateAccess.forEach(function (_a) {
|
|
1088
1088
|
var node = _a.node, path = _a.path;
|
|
1089
1089
|
node.addListener(path, function () {
|
|
1090
|
-
var newValue = initialSpecNode.getSpec().initFunc(
|
|
1090
|
+
var newValue = initialSpecNode.getSpec().initFunc(__assign({ $state: $state }, $$state.env));
|
|
1091
1091
|
set(proxyRoot, initialStatePath, newValue);
|
|
1092
1092
|
});
|
|
1093
1093
|
});
|
|
1094
|
-
var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))(
|
|
1094
|
+
var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))(__assign({ $state: $state }, $$state.env));
|
|
1095
1095
|
initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
|
|
1096
1096
|
var initialSpec = initialSpecNode.getSpec();
|
|
1097
1097
|
var value = initialSpec.isImmutable
|
|
@@ -1100,7 +1100,7 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
|
|
|
1100
1100
|
set(proxyRoot, initialStatePath, value);
|
|
1101
1101
|
//immediately fire onChange
|
|
1102
1102
|
if (initialSpec.onChangeProp) {
|
|
1103
|
-
(_b = (_a = $$state.props)[initialSpec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, initialValue);
|
|
1103
|
+
(_b = (_a = $$state.env.$props)[initialSpec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, initialValue);
|
|
1104
1104
|
}
|
|
1105
1105
|
return initialValue;
|
|
1106
1106
|
}
|
|
@@ -1125,7 +1125,7 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1125
1125
|
//we are always in a leaf, since we only have two cases:
|
|
1126
1126
|
// 1 - delete properties outside the state tree
|
|
1127
1127
|
// 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
|
|
1128
|
-
(_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, get(proxyRoot, currPath.slice(spec.pathObj.length)));
|
|
1128
|
+
(_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, get(proxyRoot, currPath.slice(spec.pathObj.length)));
|
|
1129
1129
|
}
|
|
1130
1130
|
var nextPath = getNextPath(property);
|
|
1131
1131
|
var nextNode = currNode.makeTransition(property);
|
|
@@ -1159,7 +1159,7 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1159
1159
|
return Reflect.get(target, property, receiver);
|
|
1160
1160
|
},
|
|
1161
1161
|
set: function (target, property, value, receiver) {
|
|
1162
|
-
var _a, _b;
|
|
1162
|
+
var _a, _b, _c, _d;
|
|
1163
1163
|
var nextPath = getNextPath(property);
|
|
1164
1164
|
var nextNode = currNode.makeTransition(property);
|
|
1165
1165
|
if (property === "registerInitFunc" && currPath.length === 0) {
|
|
@@ -1191,12 +1191,19 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1191
1191
|
else {
|
|
1192
1192
|
Reflect.set(target, property, value, receiver);
|
|
1193
1193
|
}
|
|
1194
|
-
|
|
1195
|
-
var _a, _b;
|
|
1194
|
+
if (currNode.isLeaf()) {
|
|
1196
1195
|
if (spec.onChangeProp) {
|
|
1197
|
-
(
|
|
1196
|
+
(_d = (_c = $$state.env.$props)[spec.onChangeProp]) === null || _d === void 0 ? void 0 : _d.call(_c, target);
|
|
1198
1197
|
}
|
|
1199
|
-
}
|
|
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
|
+
}
|
|
1200
1207
|
var newValue = (isOutside || currNode.isLeaf()) && currNode.getSpec().isImmutable
|
|
1201
1208
|
? mkUntrackedValue(value)
|
|
1202
1209
|
: value;
|
|
@@ -1233,22 +1240,27 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1233
1240
|
var mkUntrackedValue = function (o) {
|
|
1234
1241
|
return o != null && typeof o === "object" ? ref(o) : o;
|
|
1235
1242
|
};
|
|
1236
|
-
|
|
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) {
|
|
1237
1252
|
var $$state = React__default.useRef((function () {
|
|
1238
1253
|
var rootSpecTree = buildTree(specs);
|
|
1239
1254
|
return {
|
|
1240
1255
|
rootSpecTree: rootSpecTree,
|
|
1241
1256
|
specTreeLeaves: getStateCells(rootSpecTree),
|
|
1242
1257
|
stateValues: proxy({}),
|
|
1243
|
-
|
|
1244
|
-
ctx: {},
|
|
1258
|
+
env: envFieldsAreNonNill(env),
|
|
1245
1259
|
specs: [],
|
|
1246
1260
|
registrationsQueue: proxy([])
|
|
1247
1261
|
};
|
|
1248
1262
|
})()).current;
|
|
1249
|
-
$$state.
|
|
1250
|
-
$$state.ctx = $ctx !== null && $ctx !== void 0 ? $ctx : {};
|
|
1251
|
-
$$state.specs = specs;
|
|
1263
|
+
($$state.env = envFieldsAreNonNill(env)), ($$state.specs = specs);
|
|
1252
1264
|
var create$State = function () {
|
|
1253
1265
|
var $state = Object.assign(create$StateProxy($$state, function (node, path) {
|
|
1254
1266
|
if (!node.hasState(path)) {
|
|
@@ -1265,7 +1277,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
1265
1277
|
get: function (target, property, receiver) {
|
|
1266
1278
|
var spec = node.getSpec();
|
|
1267
1279
|
if (spec.valueProp) {
|
|
1268
|
-
return $$state.props[spec.valueProp];
|
|
1280
|
+
return $$state.env.$props[spec.valueProp];
|
|
1269
1281
|
}
|
|
1270
1282
|
else {
|
|
1271
1283
|
return Reflect.get(target, property, receiver);
|
|
@@ -1278,7 +1290,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
1278
1290
|
if (!node.hasState(realPath)) {
|
|
1279
1291
|
node.createStateCell(realPath);
|
|
1280
1292
|
}
|
|
1281
|
-
if (!deepEqual(node.getState(realPath).initialValue, f(
|
|
1293
|
+
if (!deepEqual(node.getState(realPath).initialValue, f(__assign({ $state: $state }, $$state.env)))) {
|
|
1282
1294
|
$$state.registrationsQueue.push(mkUntrackedValue({ node: node, path: realPath, f: f }));
|
|
1283
1295
|
}
|
|
1284
1296
|
}
|
|
@@ -1312,7 +1324,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
1312
1324
|
}
|
|
1313
1325
|
node.createStateCell(spec.pathObj);
|
|
1314
1326
|
var init = spec.valueProp
|
|
1315
|
-
? $$state.props[spec.valueProp]
|
|
1327
|
+
? $$state.env.$props[spec.valueProp]
|
|
1316
1328
|
: spec.initFunc
|
|
1317
1329
|
? initializeStateValue($$state, node, spec.pathObj, $state)
|
|
1318
1330
|
: spec.initVal;
|
|
@@ -1328,7 +1340,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
1328
1340
|
var node = _a.node, stateCell = _a.stateCell;
|
|
1329
1341
|
var initFunc = node.getInitFunc(stateCell);
|
|
1330
1342
|
if (initFunc) {
|
|
1331
|
-
var newInit = initFunc(
|
|
1343
|
+
var newInit = initFunc(__assign({ $state: $state }, envFieldsAreNonNill(env)));
|
|
1332
1344
|
if (!deepEqual(newInit, stateCell.initialValue)) {
|
|
1333
1345
|
resetSpecs.push({ stateCell: stateCell, node: node });
|
|
1334
1346
|
}
|
|
@@ -1339,7 +1351,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
1339
1351
|
var newInit = initializeStateValue($$state, node, stateCell.path, $state);
|
|
1340
1352
|
var spec = node.getSpec();
|
|
1341
1353
|
if (spec.onChangeProp) {
|
|
1342
|
-
(_b = (_a = $$state.props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, newInit);
|
|
1354
|
+
(_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, newInit);
|
|
1343
1355
|
}
|
|
1344
1356
|
};
|
|
1345
1357
|
useIsomorphicLayoutEffect(function () {
|
|
@@ -1347,7 +1359,7 @@ function useDollarState(specs, props, $ctx, opts) {
|
|
|
1347
1359
|
var stateCell = _a.stateCell, node = _a.node;
|
|
1348
1360
|
reInitializeState(node, stateCell);
|
|
1349
1361
|
});
|
|
1350
|
-
}, [props, resetSpecs]);
|
|
1362
|
+
}, [env.$props, resetSpecs]);
|
|
1351
1363
|
useIsomorphicLayoutEffect(function () {
|
|
1352
1364
|
while ($$state.registrationsQueue.length) {
|
|
1353
1365
|
var _a = $$state.registrationsQueue.shift(), node = _a.node, path = _a.path, f = _a.f;
|