@plasmicapp/react-web 0.2.103 → 0.2.104
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 +118 -105
- package/dist/plume/menu-button/menu-trigger.d.ts +1 -1
- package/dist/react-web.cjs.development.js +218 -126
- 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 +218 -126
- package/dist/react-web.esm.js.map +1 -1
- package/dist/render/triggers.d.ts +4 -4
- package/dist/states/index.d.ts +3 -1
- package/dist/stories/UseDollarState.stories.d.ts +7 -0
- package/package.json +20 -19
- package/skinny/dist/collection-utils-57c273dc.js +238 -0
- package/skinny/dist/collection-utils-57c273dc.js.map +1 -0
- package/skinny/dist/common-182a0b0c.js +201 -0
- package/skinny/dist/common-182a0b0c.js.map +1 -0
- package/skinny/dist/index.js +63 -43
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/plume/button/index.js +5 -5
- package/skinny/dist/plume/button/index.js.map +1 -1
- package/skinny/dist/plume/checkbox/index.js +6 -6
- package/skinny/dist/plume/checkbox/index.js.map +1 -1
- package/skinny/dist/plume/menu/index.js +11 -11
- package/skinny/dist/plume/menu/index.js.map +1 -1
- package/skinny/dist/plume/menu-button/index.js +6 -6
- package/skinny/dist/plume/menu-button/index.js.map +1 -1
- package/skinny/dist/plume/menu-button/menu-trigger.d.ts +1 -1
- package/skinny/dist/plume/select/index.js +11 -11
- package/skinny/dist/plume/select/index.js.map +1 -1
- package/skinny/dist/plume/switch/index.js +6 -6
- package/skinny/dist/plume/switch/index.js.map +1 -1
- package/skinny/dist/plume/text-input/index.js +5 -5
- package/skinny/dist/plume/text-input/index.js.map +1 -1
- package/skinny/dist/plume/triggered-overlay/index.js +7 -7
- package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
- package/skinny/dist/plume-utils-623b91cc.js +35 -0
- package/skinny/dist/plume-utils-623b91cc.js.map +1 -0
- package/skinny/dist/props-utils-b2ad4997.js +8 -0
- package/skinny/dist/props-utils-b2ad4997.js.map +1 -0
- package/skinny/dist/react-utils-35cb2a4e.js +201 -0
- package/skinny/dist/react-utils-35cb2a4e.js.map +1 -0
- package/skinny/dist/render/PlasmicImg/index.js +3 -3
- package/skinny/dist/render/PlasmicImg/index.js.map +1 -1
- package/skinny/dist/render/triggers.d.ts +4 -4
- package/skinny/dist/states/index.d.ts +3 -1
- package/skinny/dist/stories/UseDollarState.stories.d.ts +7 -0
|
@@ -3174,8 +3174,8 @@ function mkProxy(specs, maybeHandlers) {
|
|
|
3174
3174
|
};
|
|
3175
3175
|
};
|
|
3176
3176
|
|
|
3177
|
-
var
|
|
3178
|
-
|
|
3177
|
+
var getNextParts = function getNextParts(currPath) {
|
|
3178
|
+
return Object.fromEntries(Object.values(specs).filter(function (spec) {
|
|
3179
3179
|
return shallowEqual(currPath.map(function (p) {
|
|
3180
3180
|
return isNum(p) ? "[]" : p;
|
|
3181
3181
|
}), spec.path.slice(0, currPath.length));
|
|
@@ -3185,16 +3185,74 @@ function mkProxy(specs, maybeHandlers) {
|
|
|
3185
3185
|
if (spec.path.length === currPath.length + 1) {
|
|
3186
3186
|
return [nextPart, {
|
|
3187
3187
|
isLast: true,
|
|
3188
|
-
|
|
3188
|
+
specKey: spec.pathStr
|
|
3189
3189
|
}];
|
|
3190
3190
|
} else {
|
|
3191
3191
|
return [nextPart, {
|
|
3192
3192
|
isLast: false,
|
|
3193
|
-
|
|
3193
|
+
specKey: spec.pathStr
|
|
3194
3194
|
}];
|
|
3195
3195
|
}
|
|
3196
3196
|
}));
|
|
3197
|
+
};
|
|
3198
|
+
/**
|
|
3199
|
+
* We use this function when we're setting a value in the middle of the state path.
|
|
3200
|
+
* We can't just set the value, because we need to keep the proxy properties, so
|
|
3201
|
+
* we use the specs to walk through the object and just set the value in the end of the path
|
|
3202
|
+
**/
|
|
3203
|
+
|
|
3204
|
+
|
|
3205
|
+
var cloneValue = function cloneValue(target, currPath, value) {
|
|
3206
|
+
if (typeof value !== "object") {
|
|
3207
|
+
return;
|
|
3208
|
+
}
|
|
3209
|
+
|
|
3210
|
+
var nextParts = getNextParts(currPath);
|
|
3211
|
+
|
|
3212
|
+
for (var _i = 0, _Object$entries = Object.entries(nextParts); _i < _Object$entries.length; _i++) {
|
|
3213
|
+
var _Object$entries$_i = _Object$entries[_i],
|
|
3214
|
+
nextPart = _Object$entries$_i[0],
|
|
3215
|
+
_Object$entries$_i$ = _Object$entries$_i[1],
|
|
3216
|
+
isLast = _Object$entries$_i$.isLast,
|
|
3217
|
+
specKey = _Object$entries$_i$.specKey;
|
|
3218
|
+
|
|
3219
|
+
if (nextPart === "[]" && Array.isArray(value)) {
|
|
3220
|
+
for (var i = 0; i < value.length; i++) {
|
|
3221
|
+
cloneValue(target[i], [].concat(currPath, [i]), value[i]);
|
|
3222
|
+
}
|
|
3223
|
+
} else if (nextPart in value) {
|
|
3224
|
+
if (isLast) {
|
|
3225
|
+
var _handlers$set, _handlers;
|
|
3226
|
+
|
|
3227
|
+
handlers == null ? void 0 : (_handlers$set = (_handlers = handlers({
|
|
3228
|
+
specKey: specKey,
|
|
3229
|
+
path: [].concat(currPath, [nextPart])
|
|
3230
|
+
})).set) == null ? void 0 : _handlers$set.call(_handlers, target, nextPart, value[nextPart], undefined);
|
|
3231
|
+
} else {
|
|
3232
|
+
cloneValue(target[nextPart], [].concat(currPath, [nextPart]), value[nextPart]);
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
};
|
|
3237
|
+
|
|
3238
|
+
var rec = function rec(currPath) {
|
|
3239
|
+
var nextParts = getNextParts(currPath);
|
|
3197
3240
|
return new Proxy("[]" in nextParts ? [] : {}, {
|
|
3241
|
+
deleteProperty: function deleteProperty(target, property) {
|
|
3242
|
+
if ("[]" in nextParts && isNum(property)) {
|
|
3243
|
+
var _handlers$deletePrope, _handlers2;
|
|
3244
|
+
|
|
3245
|
+
delete target[property];
|
|
3246
|
+
handlers == null ? void 0 : (_handlers$deletePrope = (_handlers2 = handlers({
|
|
3247
|
+
path: [].concat(currPath, [+property]),
|
|
3248
|
+
specKey: nextParts["[]"].specKey
|
|
3249
|
+
})).deleteProperty) == null ? void 0 : _handlers$deletePrope.call(_handlers2, target, property);
|
|
3250
|
+
} else {
|
|
3251
|
+
throw new Error("You can't delete a non-repeated property in the middle of the path");
|
|
3252
|
+
}
|
|
3253
|
+
|
|
3254
|
+
return true;
|
|
3255
|
+
},
|
|
3198
3256
|
get: function get(target, property, receiver) {
|
|
3199
3257
|
if ("[]" in nextParts && isNum(property)) {
|
|
3200
3258
|
if (!(property in target)) {
|
|
@@ -3202,12 +3260,12 @@ function mkProxy(specs, maybeHandlers) {
|
|
|
3202
3260
|
}
|
|
3203
3261
|
} else if (property in nextParts) {
|
|
3204
3262
|
if (nextParts[property].isLast) {
|
|
3205
|
-
var _handlers$get,
|
|
3263
|
+
var _handlers$get, _handlers3;
|
|
3206
3264
|
|
|
3207
|
-
return handlers == null ? void 0 : (_handlers$get = (
|
|
3265
|
+
return target[property] = handlers == null ? void 0 : (_handlers$get = (_handlers3 = handlers({
|
|
3208
3266
|
path: [].concat(currPath, [property]),
|
|
3209
|
-
|
|
3210
|
-
})).get) == null ? void 0 : _handlers$get.call(
|
|
3267
|
+
specKey: nextParts[property].specKey
|
|
3268
|
+
})).get) == null ? void 0 : _handlers$get.call(_handlers3, target, property, receiver);
|
|
3211
3269
|
} else if (!(property in target)) {
|
|
3212
3270
|
target[property] = rec([].concat(currPath, [property]));
|
|
3213
3271
|
}
|
|
@@ -3216,21 +3274,29 @@ function mkProxy(specs, maybeHandlers) {
|
|
|
3216
3274
|
return target[property];
|
|
3217
3275
|
},
|
|
3218
3276
|
set: function set(target, property, value, receiver) {
|
|
3219
|
-
if (
|
|
3277
|
+
if ("[]" in nextParts && isNum(property)) {
|
|
3278
|
+
if (!(property in target)) {
|
|
3279
|
+
target[property] = rec([].concat(currPath, [+property]));
|
|
3280
|
+
}
|
|
3281
|
+
} else if (property in nextParts) {
|
|
3220
3282
|
if (nextParts[property].isLast) {
|
|
3221
|
-
var _handlers$
|
|
3283
|
+
var _handlers$set2, _handlers$set3, _handlers4;
|
|
3222
3284
|
|
|
3223
|
-
|
|
3285
|
+
target[property] = value;
|
|
3286
|
+
return (_handlers$set2 = (_handlers$set3 = (_handlers4 = handlers({
|
|
3224
3287
|
path: [].concat(currPath, [property]),
|
|
3225
|
-
|
|
3226
|
-
})).set) == null ? void 0 : _handlers$
|
|
3227
|
-
} else {
|
|
3228
|
-
throw new Error("You can't set a value in the middle of the path");
|
|
3288
|
+
specKey: nextParts[property].specKey
|
|
3289
|
+
})).set) == null ? void 0 : _handlers$set3.call(_handlers4, target, property, value, receiver)) != null ? _handlers$set2 : false;
|
|
3229
3290
|
}
|
|
3230
|
-
}
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3293
|
+
if (property === "registerInitFunc") {
|
|
3231
3294
|
target[property] = value;
|
|
3232
|
-
|
|
3295
|
+
} else if (typeof value === "object") {
|
|
3296
|
+
cloneValue(target[property], [].concat(currPath, [isNum(property) ? +property : property]), value);
|
|
3233
3297
|
}
|
|
3298
|
+
|
|
3299
|
+
return true;
|
|
3234
3300
|
}
|
|
3235
3301
|
});
|
|
3236
3302
|
};
|
|
@@ -3266,133 +3332,141 @@ var transformPathStringToObj = function transformPathStringToObj(str) {
|
|
|
3266
3332
|
};
|
|
3267
3333
|
|
|
3268
3334
|
function useVanillaDollarState(_specs, props) {
|
|
3269
|
-
var
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
var stateValues = mkProxy(specs);
|
|
3284
|
-
var initStates = {};
|
|
3285
|
-
|
|
3286
|
-
for (var _iterator = _createForOfIteratorHelperLoose(specs), _step; !(_step = _iterator()).done;) {
|
|
3287
|
-
var spec = _step.value;
|
|
3288
|
-
|
|
3289
|
-
if (spec.valueProp || spec.isRepeated) {
|
|
3290
|
-
continue;
|
|
3291
|
-
} else if (spec.initFunc) {
|
|
3292
|
-
dset.dset(stateValues, spec.path, UNINITIALIZED);
|
|
3293
|
-
} else {
|
|
3294
|
-
var _spec$initVal;
|
|
3295
|
-
|
|
3296
|
-
dset.dset(stateValues, spec.path, (_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined);
|
|
3297
|
-
}
|
|
3298
|
-
|
|
3299
|
-
saveState({
|
|
3300
|
-
path: spec.path,
|
|
3301
|
-
spec: spec
|
|
3302
|
-
}, initStates);
|
|
3303
|
-
}
|
|
3304
|
-
|
|
3305
|
-
var deps = fillUninitializedStateValues(specs, props, stateValues, initStates);
|
|
3335
|
+
var forceRender = React__default.useState(0)[1];
|
|
3336
|
+
var $$state = React__default.useMemo(function () {
|
|
3337
|
+
var specs = Object.fromEntries(_specs.map(function (_ref2) {
|
|
3338
|
+
var pathStr = _ref2.path,
|
|
3339
|
+
spec = _objectWithoutPropertiesLoose(_ref2, ["path"]);
|
|
3340
|
+
|
|
3341
|
+
return [pathStr, _extends({}, spec, {
|
|
3342
|
+
pathStr: pathStr,
|
|
3343
|
+
path: transformPathStringToObj(pathStr),
|
|
3344
|
+
isRepeated: pathStr.split(".").some(function (part) {
|
|
3345
|
+
return part.endsWith("[]");
|
|
3346
|
+
})
|
|
3347
|
+
})];
|
|
3348
|
+
}));
|
|
3306
3349
|
return {
|
|
3307
|
-
stateValues:
|
|
3308
|
-
initStateDeps:
|
|
3309
|
-
initStateValues:
|
|
3310
|
-
states:
|
|
3350
|
+
stateValues: mkProxy(specs),
|
|
3351
|
+
initStateDeps: {},
|
|
3352
|
+
initStateValues: mkProxy(specs),
|
|
3353
|
+
states: {},
|
|
3354
|
+
specs: specs
|
|
3311
3355
|
};
|
|
3312
|
-
})
|
|
3313
|
-
|
|
3314
|
-
set$$State = _React$useState[1];
|
|
3315
|
-
|
|
3316
|
-
var $state = mkProxy(specs, function (state) {
|
|
3356
|
+
}, []);
|
|
3357
|
+
var $state = Object.assign(mkProxy($$state.specs, function (state) {
|
|
3317
3358
|
return {
|
|
3359
|
+
deleteProperty: function deleteProperty(_target, _property) {
|
|
3360
|
+
var prefixPath = state.path;
|
|
3361
|
+
|
|
3362
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries($$state.states); _i2 < _Object$entries2.length; _i2++) {
|
|
3363
|
+
var _Object$entries2$_i = _Object$entries2[_i2],
|
|
3364
|
+
key = _Object$entries2$_i[0],
|
|
3365
|
+
existingState = _Object$entries2$_i[1];
|
|
3366
|
+
|
|
3367
|
+
if (existingState.path.length >= prefixPath.length && shallowEqual(existingState.path.slice(0, prefixPath.length), prefixPath)) {
|
|
3368
|
+
delete $$state.states[key];
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
|
|
3372
|
+
forceRender(function (r) {
|
|
3373
|
+
return r + 1;
|
|
3374
|
+
});
|
|
3375
|
+
return true;
|
|
3376
|
+
},
|
|
3318
3377
|
get: function get(_target, _property) {
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3378
|
+
var spec = $$state.specs[state.specKey];
|
|
3379
|
+
|
|
3380
|
+
if (spec.valueProp) {
|
|
3381
|
+
if (!spec.isRepeated) {
|
|
3382
|
+
return props[spec.valueProp];
|
|
3322
3383
|
} else {
|
|
3323
|
-
return _get(props[
|
|
3384
|
+
return _get(props[spec.valueProp], state.path.slice(1));
|
|
3324
3385
|
}
|
|
3325
3386
|
}
|
|
3326
3387
|
|
|
3327
3388
|
if (!hasState(state, $$state.states)) {
|
|
3328
|
-
var
|
|
3389
|
+
var _spec$initVal;
|
|
3329
3390
|
|
|
3330
3391
|
saveState(state, $$state.states);
|
|
3331
3392
|
|
|
3332
|
-
dset.dset($$state.stateValues, state.path,
|
|
3393
|
+
dset.dset($$state.stateValues, state.path, spec.initFunc ? UNINITIALIZED : (_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined);
|
|
3333
3394
|
|
|
3334
|
-
var deps =
|
|
3395
|
+
var deps = spec.initFunc ? fillUninitializedStateValues($$state.specs, props, $$state.stateValues, $$state.states) : {};
|
|
3335
3396
|
|
|
3336
3397
|
dset.dset($$state.initStateValues, state.path, _get($$state.stateValues, state.path));
|
|
3337
3398
|
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
stateValues: cloneProxy(specs, prev.states, prev.initStateValues),
|
|
3342
|
-
initStateDeps: _extends({}, prev.initStateDeps, deps),
|
|
3343
|
-
states: _extends({}, prev.states)
|
|
3344
|
-
};
|
|
3399
|
+
$$state.initStateDeps = _extends({}, $$state.initStateDeps, deps);
|
|
3400
|
+
forceRender(function (r) {
|
|
3401
|
+
return r + 1;
|
|
3345
3402
|
});
|
|
3403
|
+
return spec.initFunc ? spec.initFunc(props, $state) : spec.initVal;
|
|
3346
3404
|
}
|
|
3347
3405
|
|
|
3348
3406
|
return _get($$state.stateValues, state.path);
|
|
3349
3407
|
},
|
|
3350
3408
|
set: function set(_target, _property, newValue) {
|
|
3351
|
-
saveState(state, $$state.states);
|
|
3352
|
-
|
|
3353
3409
|
if (newValue !== _get($$state.stateValues, state.path)) {
|
|
3410
|
+
saveState(state, $$state.states);
|
|
3411
|
+
|
|
3354
3412
|
dset.dset($$state.stateValues, state.path, newValue);
|
|
3355
3413
|
|
|
3356
|
-
for (var
|
|
3357
|
-
var _Object$
|
|
3358
|
-
key = _Object$
|
|
3359
|
-
deps = _Object$
|
|
3414
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries($$state.initStateDeps); _i3 < _Object$entries3.length; _i3++) {
|
|
3415
|
+
var _Object$entries3$_i = _Object$entries3[_i3],
|
|
3416
|
+
key = _Object$entries3$_i[0],
|
|
3417
|
+
deps = _Object$entries3$_i[1];
|
|
3360
3418
|
|
|
3361
3419
|
if (deps.includes(JSON.stringify(state.path))) {
|
|
3362
3420
|
dset.dset($$state.stateValues, JSON.parse(key), UNINITIALIZED);
|
|
3363
3421
|
}
|
|
3364
3422
|
}
|
|
3365
3423
|
|
|
3366
|
-
var newDeps = fillUninitializedStateValues(specs, props, $$state.stateValues, $$state.states);
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
stateValues: cloneProxy(specs, prev.states, prev.stateValues),
|
|
3371
|
-
initStateDeps: _extends({}, prev.initStateDeps, newDeps),
|
|
3372
|
-
states: _extends({}, prev.states)
|
|
3373
|
-
};
|
|
3424
|
+
var newDeps = fillUninitializedStateValues($$state.specs, props, $$state.stateValues, $$state.states);
|
|
3425
|
+
$$state.initStateDeps = _extends({}, $$state.initStateDeps, newDeps);
|
|
3426
|
+
forceRender(function (r) {
|
|
3427
|
+
return r + 1;
|
|
3374
3428
|
});
|
|
3429
|
+
}
|
|
3375
3430
|
|
|
3376
|
-
|
|
3377
|
-
var _props$state$spec$onC;
|
|
3431
|
+
var spec = $$state.specs[state.specKey];
|
|
3378
3432
|
|
|
3379
|
-
|
|
3380
|
-
|
|
3433
|
+
if (spec.onChangeProp) {
|
|
3434
|
+
var _props$spec$onChangeP;
|
|
3435
|
+
|
|
3436
|
+
(_props$spec$onChangeP = props[spec.onChangeProp]) == null ? void 0 : _props$spec$onChangeP.call(props, newValue, state.path);
|
|
3381
3437
|
}
|
|
3382
3438
|
|
|
3383
3439
|
return true;
|
|
3384
3440
|
}
|
|
3385
3441
|
};
|
|
3442
|
+
}), {
|
|
3443
|
+
registerInitFunc: function registerInitFunc(pathStr, f) {
|
|
3444
|
+
if (Object.values($$state.states).filter(function (_ref3) {
|
|
3445
|
+
var specKey = _ref3.specKey;
|
|
3446
|
+
return specKey === pathStr;
|
|
3447
|
+
}).some(function (_ref4) {
|
|
3448
|
+
var path = _ref4.path;
|
|
3449
|
+
return _get($$state.stateValues, path) !== f(props, $state);
|
|
3450
|
+
})) {
|
|
3451
|
+
$$state.specs[pathStr] = _extends({}, $$state.specs[pathStr], {
|
|
3452
|
+
initFunc: f
|
|
3453
|
+
});
|
|
3454
|
+
forceRender(function (r) {
|
|
3455
|
+
return r + 1;
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
}
|
|
3386
3459
|
}); // For each spec with an initFunc, evaluate it and see if
|
|
3387
3460
|
// the init value has changed. If so, reset its state.
|
|
3388
3461
|
|
|
3389
3462
|
var newStateValues = undefined;
|
|
3390
3463
|
var resetSpecs = [];
|
|
3391
3464
|
|
|
3392
|
-
for (var
|
|
3393
|
-
var _Object$values$_i = _Object$values[
|
|
3465
|
+
for (var _i4 = 0, _Object$values = Object.values($$state.states); _i4 < _Object$values.length; _i4++) {
|
|
3466
|
+
var _Object$values$_i = _Object$values[_i4],
|
|
3394
3467
|
path = _Object$values$_i.path,
|
|
3395
|
-
|
|
3468
|
+
specKey = _Object$values$_i.specKey;
|
|
3469
|
+
var spec = $$state.specs[specKey];
|
|
3396
3470
|
|
|
3397
3471
|
if (spec.initFunc) {
|
|
3398
3472
|
var newInit = spec.initFunc(props, $state);
|
|
@@ -3401,11 +3475,11 @@ function useVanillaDollarState(_specs, props) {
|
|
|
3401
3475
|
console.log("init changed for " + JSON.stringify(path) + " from " + _get($$state.initStateValues, path) + " to " + newInit + "; resetting state");
|
|
3402
3476
|
resetSpecs.push({
|
|
3403
3477
|
path: path,
|
|
3404
|
-
|
|
3478
|
+
specKey: specKey
|
|
3405
3479
|
});
|
|
3406
3480
|
|
|
3407
3481
|
if (!newStateValues) {
|
|
3408
|
-
newStateValues = cloneProxy(specs, $$state.states, $$state.stateValues);
|
|
3482
|
+
newStateValues = cloneProxy($$state.specs, $$state.states, $$state.stateValues);
|
|
3409
3483
|
}
|
|
3410
3484
|
|
|
3411
3485
|
dset.dset(newStateValues, path, UNINITIALIZED);
|
|
@@ -3415,26 +3489,25 @@ function useVanillaDollarState(_specs, props) {
|
|
|
3415
3489
|
|
|
3416
3490
|
React__default.useLayoutEffect(function () {
|
|
3417
3491
|
if (newStateValues !== undefined) {
|
|
3418
|
-
var newDeps = fillUninitializedStateValues(specs, props, newStateValues, $$state.states);
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
var path = _ref3.path;
|
|
3492
|
+
var newDeps = fillUninitializedStateValues($$state.specs, props, newStateValues, $$state.states);
|
|
3493
|
+
var initStateValues = cloneProxy($$state.specs, $$state.states, $$state.initStateValues);
|
|
3494
|
+
resetSpecs.forEach(function (_ref5) {
|
|
3495
|
+
var path = _ref5.path;
|
|
3423
3496
|
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
};
|
|
3497
|
+
dset.dset(initStateValues, path, _get(newStateValues, path));
|
|
3498
|
+
});
|
|
3499
|
+
$$state.stateValues = cloneProxy($$state.specs, $$state.states, newStateValues);
|
|
3500
|
+
$$state.initStateValues = initStateValues;
|
|
3501
|
+
$$state.initStateDeps = _extends({}, $$state.initStateDeps, newDeps);
|
|
3502
|
+
forceRender(function (r) {
|
|
3503
|
+
return r + 1;
|
|
3432
3504
|
});
|
|
3433
3505
|
|
|
3434
|
-
for (var
|
|
3435
|
-
var
|
|
3436
|
-
_path =
|
|
3437
|
-
|
|
3506
|
+
for (var _iterator = _createForOfIteratorHelperLoose(resetSpecs), _step; !(_step = _iterator()).done;) {
|
|
3507
|
+
var _step$value = _step.value,
|
|
3508
|
+
_path = _step$value.path,
|
|
3509
|
+
_specKey = _step$value.specKey;
|
|
3510
|
+
var _spec = $$state.specs[_specKey];
|
|
3438
3511
|
|
|
3439
3512
|
if (_spec.onChangeProp) {
|
|
3440
3513
|
var _props$_spec$onChange;
|
|
@@ -3444,21 +3517,38 @@ function useVanillaDollarState(_specs, props) {
|
|
|
3444
3517
|
}
|
|
3445
3518
|
}
|
|
3446
3519
|
}
|
|
3447
|
-
}, [newStateValues, props, resetSpecs, specs]);
|
|
3520
|
+
}, [newStateValues, props, resetSpecs, $$state.specs]);
|
|
3521
|
+
/* *
|
|
3522
|
+
* Initialize all known states. (we need to do it for repeated states
|
|
3523
|
+
* because they're created only after the first get/set operation)
|
|
3524
|
+
* If we don't initialize them, we won't be able to consume the repeated states properly.
|
|
3525
|
+
* For example, let's say the consumer is just mapping the repeated states. The first operation
|
|
3526
|
+
* is to get the length of the array which will always be 0 because the existing states
|
|
3527
|
+
* weren't allocated yet -- they're only stored in internal state)
|
|
3528
|
+
* */
|
|
3529
|
+
|
|
3530
|
+
for (var _i5 = 0, _Object$values2 = Object.values($$state.states); _i5 < _Object$values2.length; _i5++) {
|
|
3531
|
+
var _path2 = _Object$values2[_i5].path;
|
|
3532
|
+
|
|
3533
|
+
_get($state, _path2);
|
|
3534
|
+
}
|
|
3535
|
+
|
|
3448
3536
|
return $state;
|
|
3449
3537
|
}
|
|
3450
3538
|
|
|
3451
3539
|
function fillUninitializedStateValues(specs, props, stateValues, states) {
|
|
3452
3540
|
var stateAccessStack = [new Set()];
|
|
3453
3541
|
var initFuncDeps = {};
|
|
3454
|
-
var $state = mkProxy(specs, function (state) {
|
|
3542
|
+
var $state = Object.assign(mkProxy(specs, function (state) {
|
|
3455
3543
|
return {
|
|
3456
3544
|
get: function get(_target, _property) {
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3545
|
+
var spec = specs[state.specKey];
|
|
3546
|
+
|
|
3547
|
+
if (spec.valueProp) {
|
|
3548
|
+
if (!spec.isRepeated) {
|
|
3549
|
+
return props[spec.valueProp];
|
|
3460
3550
|
} else {
|
|
3461
|
-
return _get(props[
|
|
3551
|
+
return _get(props[spec.valueProp], state.path.slice(1));
|
|
3462
3552
|
}
|
|
3463
3553
|
}
|
|
3464
3554
|
|
|
@@ -3481,18 +3571,20 @@ function fillUninitializedStateValues(specs, props, stateValues, states) {
|
|
|
3481
3571
|
throw new Error("Cannot update state values during initialization");
|
|
3482
3572
|
}
|
|
3483
3573
|
};
|
|
3574
|
+
}), {
|
|
3575
|
+
registerInitFunc: function registerInitFunc() {}
|
|
3484
3576
|
});
|
|
3485
3577
|
|
|
3486
3578
|
function tracked(state) {
|
|
3487
3579
|
stateAccessStack.push(new Set());
|
|
3488
|
-
var res = state.
|
|
3580
|
+
var res = specs[state.specKey].initFunc(props, $state);
|
|
3489
3581
|
var deps = stateAccessStack.pop();
|
|
3490
3582
|
initFuncDeps[JSON.stringify(state.path)] = [].concat(deps.values());
|
|
3491
3583
|
return res;
|
|
3492
3584
|
}
|
|
3493
3585
|
|
|
3494
|
-
for (var
|
|
3495
|
-
var path = _Object$
|
|
3586
|
+
for (var _i6 = 0, _Object$values3 = Object.values(states); _i6 < _Object$values3.length; _i6++) {
|
|
3587
|
+
var path = _Object$values3[_i6].path;
|
|
3496
3588
|
|
|
3497
3589
|
if (_get(stateValues, path) === UNINITIALIZED) {
|
|
3498
3590
|
_get($state, path);
|