@plasmicapp/react-web 0.2.109 → 0.2.112
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 +30 -13
- package/dist/index-common.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/react-web.cjs.development.js +378 -349
- 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 +375 -349
- package/dist/react-web.esm.js.map +1 -1
- package/dist/render/elements.d.ts +5 -0
- package/dist/states/helpers.d.ts +5 -0
- package/dist/states/index.d.ts +1 -1
- package/dist/states/valtio.d.ts +16 -0
- package/dist/stories/UseDollarState.stories.d.ts +11 -0
- package/package.json +6 -2
- package/skinny/dist/collection-utils-42de4441.js +244 -0
- package/skinny/dist/collection-utils-42de4441.js.map +1 -0
- package/skinny/dist/{collection-utils-3487dd27.js → collection-utils-bf37b8fb.js} +5 -5
- package/skinny/dist/collection-utils-bf37b8fb.js.map +1 -0
- package/skinny/dist/common-98719219.js +68 -0
- package/skinny/dist/common-98719219.js.map +1 -0
- package/skinny/dist/common-9efbae57.js +201 -0
- package/skinny/dist/common-9efbae57.js.map +1 -0
- package/skinny/dist/context-4ca6f5cd.js +6 -0
- package/skinny/dist/context-4ca6f5cd.js.map +1 -0
- package/skinny/dist/index-common.d.ts +1 -1
- package/skinny/dist/index.d.ts +1 -1
- package/skinny/dist/index.js +17 -4
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/plume/checkbox/index.js +2 -1
- package/skinny/dist/plume/checkbox/index.js.map +1 -1
- package/skinny/dist/plume/menu/index.js +2 -1
- package/skinny/dist/plume/menu/index.js.map +1 -1
- package/skinny/dist/plume/menu-button/index.js +2 -1
- package/skinny/dist/plume/menu-button/index.js.map +1 -1
- package/skinny/dist/plume/select/index.js +2 -1
- package/skinny/dist/plume/select/index.js.map +1 -1
- package/skinny/dist/plume/switch/index.js +2 -1
- package/skinny/dist/plume/switch/index.js.map +1 -1
- package/skinny/dist/plume-utils-1e225de5.js +25 -0
- package/skinny/dist/plume-utils-1e225de5.js.map +1 -0
- package/skinny/dist/plume-utils-d2476af1.js +35 -0
- package/skinny/dist/plume-utils-d2476af1.js.map +1 -0
- package/skinny/dist/props-utils-c60d3105.js +8 -0
- package/skinny/dist/props-utils-c60d3105.js.map +1 -0
- package/skinny/dist/props-utils-cac0cccf.js +8 -0
- package/skinny/dist/props-utils-cac0cccf.js.map +1 -0
- package/skinny/dist/react-utils-6050fadc.js +201 -0
- package/skinny/dist/react-utils-6050fadc.js.map +1 -0
- package/skinny/dist/react-utils-b5dc6320.js +155 -0
- package/skinny/dist/react-utils-b5dc6320.js.map +1 -0
- package/skinny/dist/render/PlasmicHead/index.js +14 -9
- package/skinny/dist/render/PlasmicHead/index.js.map +1 -1
- package/skinny/dist/render/elements.d.ts +5 -0
- package/skinny/dist/ssr-68913b60.js +107 -0
- package/skinny/dist/ssr-68913b60.js.map +1 -0
- package/skinny/dist/{ssr-84e27ffb.js → ssr-d3321868.js} +9 -4
- package/skinny/dist/ssr-d3321868.js.map +1 -0
- package/skinny/dist/{ssr-b1615b80.js → ssr-f4053cdd.js} +1 -1
- package/skinny/dist/{ssr-84e27ffb.js.map → ssr-f4053cdd.js.map} +1 -1
- package/skinny/dist/states/helpers.d.ts +5 -0
- package/skinny/dist/states/index.d.ts +1 -1
- package/skinny/dist/states/valtio copy.d.ts +15 -0
- package/skinny/dist/states/valtio.d.ts +16 -0
- package/skinny/dist/stories/UseDollarState.stories.d.ts +11 -0
- package/skinny/dist/stories/UseDollarState.test.d.ts +11 -0
- package/skinny/dist/stories/UseDollarState2.stories.d.ts +7 -0
- package/skinny/dist/collection-utils-3487dd27.js.map +0 -1
- package/skinny/dist/ssr-14264281.js +0 -158
- package/skinny/dist/ssr-14264281.js.map +0 -1
- package/skinny/dist/ssr-5141fc77.js +0 -158
- package/skinny/dist/ssr-5141fc77.js.map +0 -1
- package/skinny/dist/ssr-579df58f.js +0 -158
- package/skinny/dist/ssr-579df58f.js.map +0 -1
- package/skinny/dist/ssr-b1615b80.js.map +0 -1
- package/skinny/dist/ssr-d2fd94f2.js +0 -31
- package/skinny/dist/ssr-d2fd94f2.js.map +0 -1
|
@@ -5,10 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
6
|
|
|
7
7
|
var classNames$1 = _interopDefault(require('classnames'));
|
|
8
|
+
var _get = _interopDefault(require('dlv'));
|
|
8
9
|
var React = require('react');
|
|
9
10
|
var React__default = _interopDefault(React);
|
|
10
11
|
var ReactDOM = require('react-dom');
|
|
11
12
|
var ReactDOM__default = _interopDefault(ReactDOM);
|
|
13
|
+
var dataSourcesContext = require('@plasmicapp/data-sources-context');
|
|
12
14
|
var ssr = require('@react-aria/ssr');
|
|
13
15
|
var focus = require('@react-aria/focus');
|
|
14
16
|
var checkbox = require('@react-aria/checkbox');
|
|
@@ -25,8 +27,9 @@ var listbox = require('@react-aria/listbox');
|
|
|
25
27
|
var select$1 = require('@react-stately/select');
|
|
26
28
|
var _switch = require('@react-aria/switch');
|
|
27
29
|
var overlays = require('@react-aria/overlays');
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
+
var deepEqual = _interopDefault(require('fast-deep-equal'));
|
|
31
|
+
var valtio = require('valtio');
|
|
32
|
+
var utils = require('valtio/utils');
|
|
30
33
|
|
|
31
34
|
function _extends() {
|
|
32
35
|
_extends = Object.assign || function (target) {
|
|
@@ -692,6 +695,14 @@ function mergeVariants(v1, v2) {
|
|
|
692
695
|
return _extends({}, v1, v2);
|
|
693
696
|
}
|
|
694
697
|
|
|
698
|
+
function mergeVariantsWithStates(variants, $state, linkedStates) {
|
|
699
|
+
return _extends({}, variants, Object.fromEntries(linkedStates.map(function (_ref) {
|
|
700
|
+
var variantGroup = _ref.variantGroup,
|
|
701
|
+
statePath = _ref.statePath;
|
|
702
|
+
return [variantGroup, _get($state, statePath)];
|
|
703
|
+
})));
|
|
704
|
+
}
|
|
705
|
+
|
|
695
706
|
function mergeArgs(a1, a2) {
|
|
696
707
|
if (!a1 || !a2) {
|
|
697
708
|
return a1 || a2 || {};
|
|
@@ -717,7 +728,7 @@ function mergeFlexOverrides(o1, o2) {
|
|
|
717
728
|
}
|
|
718
729
|
|
|
719
730
|
function mergeFlexOverride(fo1, fo2) {
|
|
720
|
-
var _o1$props,
|
|
731
|
+
var _o1$props, _ref2;
|
|
721
732
|
|
|
722
733
|
if (!fo1) {
|
|
723
734
|
return fo2;
|
|
@@ -753,7 +764,7 @@ function mergeFlexOverride(fo1, fo2) {
|
|
|
753
764
|
} // "as" will take precedence
|
|
754
765
|
|
|
755
766
|
|
|
756
|
-
var as = (
|
|
767
|
+
var as = (_ref2 = o2.type === "as" ? o2.as : undefined) != null ? _ref2 : o1.type === "as" ? o1.as : undefined;
|
|
757
768
|
return _extends({
|
|
758
769
|
props: props,
|
|
759
770
|
wrap: wrap,
|
|
@@ -819,9 +830,12 @@ function PlasmicHead(props) {
|
|
|
819
830
|
console.warn("Plasmic: Head meta tags are being ignored. To make them work, pass a Head component into PlasmicRootProvider."); // TODO: Link to doc about Head.
|
|
820
831
|
|
|
821
832
|
return null;
|
|
822
|
-
}
|
|
833
|
+
} // Helmet does not support React.Fragments, so we need to use `[<meta />,
|
|
834
|
+
// <meta />]` instead of `<><meta /><meta /></>`.
|
|
823
835
|
|
|
824
|
-
|
|
836
|
+
|
|
837
|
+
return React.createElement(Head, null, props.image ? [React.createElement("meta", {
|
|
838
|
+
key: "twitter:card",
|
|
825
839
|
name: "twitter:card",
|
|
826
840
|
content: "summary_large_image"
|
|
827
841
|
}), React.createElement("meta", {
|
|
@@ -832,10 +846,11 @@ function PlasmicHead(props) {
|
|
|
832
846
|
key: "twitter:image",
|
|
833
847
|
name: "twitter:image",
|
|
834
848
|
content: props.image
|
|
835
|
-
})
|
|
849
|
+
})] : React.createElement("meta", {
|
|
850
|
+
key: "twitter:card",
|
|
836
851
|
name: "twitter:card",
|
|
837
852
|
content: "summary"
|
|
838
|
-
}), props.title && React.createElement(
|
|
853
|
+
}), props.title && [React.createElement("title", {
|
|
839
854
|
key: "title"
|
|
840
855
|
}, props.title), React.createElement("meta", {
|
|
841
856
|
key: "og:title",
|
|
@@ -845,7 +860,7 @@ function PlasmicHead(props) {
|
|
|
845
860
|
key: "twitter:title",
|
|
846
861
|
property: "twitter:title",
|
|
847
862
|
content: props.title
|
|
848
|
-
})
|
|
863
|
+
})], props.description && [React.createElement("meta", {
|
|
849
864
|
key: "description",
|
|
850
865
|
name: "description",
|
|
851
866
|
content: props.description
|
|
@@ -857,7 +872,8 @@ function PlasmicHead(props) {
|
|
|
857
872
|
key: "twitter:description",
|
|
858
873
|
name: "twitter:description",
|
|
859
874
|
content: props.description
|
|
860
|
-
})
|
|
875
|
+
})], props.canonical && React.createElement("link", {
|
|
876
|
+
key: "canonical",
|
|
861
877
|
ref: "canonical",
|
|
862
878
|
href: props.canonical
|
|
863
879
|
}));
|
|
@@ -865,7 +881,7 @@ function PlasmicHead(props) {
|
|
|
865
881
|
var plasmicHeadMeta = {
|
|
866
882
|
name: "hostless-plasmic-head",
|
|
867
883
|
displayName: "Head",
|
|
868
|
-
description: "Used to add page metadata to
|
|
884
|
+
description: "Used to add page metadata to HTML <head />.",
|
|
869
885
|
importName: "PlasmicHead",
|
|
870
886
|
importPath: "@plasmicapp/react-web",
|
|
871
887
|
isRepeatable: false,
|
|
@@ -1533,19 +1549,27 @@ function createUseScreenVariants(isMulti, screenQueries) {
|
|
|
1533
1549
|
var PlasmicRootContext = /*#__PURE__*/React.createContext(undefined);
|
|
1534
1550
|
function PlasmicRootProvider(props) {
|
|
1535
1551
|
var platform = props.platform,
|
|
1536
|
-
children = props.children
|
|
1552
|
+
children = props.children,
|
|
1553
|
+
userAuthToken = props.userAuthToken;
|
|
1537
1554
|
var context = React.useMemo(function () {
|
|
1538
1555
|
return {
|
|
1539
1556
|
platform: platform
|
|
1540
1557
|
};
|
|
1541
1558
|
}, [platform]);
|
|
1559
|
+
var dataSourceContextValue = React.useMemo(function () {
|
|
1560
|
+
return {
|
|
1561
|
+
userAuthToken: userAuthToken
|
|
1562
|
+
};
|
|
1563
|
+
}, [userAuthToken]);
|
|
1542
1564
|
return React.createElement(PlasmicRootContext.Provider, {
|
|
1543
1565
|
value: context
|
|
1544
|
-
}, React.createElement(ssr.SSRProvider, null, React.createElement(
|
|
1566
|
+
}, React.createElement(ssr.SSRProvider, null, React.createElement(dataSourcesContext.PlasmicDataSourceContextProvider, {
|
|
1567
|
+
value: dataSourceContextValue
|
|
1568
|
+
}, React.createElement(PlasmicTranslatorContext.Provider, {
|
|
1545
1569
|
value: props.translator
|
|
1546
1570
|
}, React.createElement(PlasmicHeadContext.Provider, {
|
|
1547
1571
|
value: props.Head
|
|
1548
|
-
}, children))));
|
|
1572
|
+
}, children)))));
|
|
1549
1573
|
}
|
|
1550
1574
|
var useIsSSR = ssr.useIsSSR;
|
|
1551
1575
|
function useHasPlasmicRoot() {
|
|
@@ -3212,7 +3236,7 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissabl
|
|
|
3212
3236
|
|
|
3213
3237
|
function generateStateOnChangeProp($state, stateName, dataReps) {
|
|
3214
3238
|
return function (val, path) {
|
|
3215
|
-
return
|
|
3239
|
+
return set($state, [stateName].concat(dataReps, path), val);
|
|
3216
3240
|
};
|
|
3217
3241
|
}
|
|
3218
3242
|
/**
|
|
@@ -3226,8 +3250,51 @@ function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
|
|
|
3226
3250
|
) {
|
|
3227
3251
|
return _get($state, path);
|
|
3228
3252
|
}
|
|
3253
|
+
/**
|
|
3254
|
+
* Forked from https://github.com/lukeed/dset
|
|
3255
|
+
* Changes: fixed setting a deep value to a proxy object
|
|
3256
|
+
*/
|
|
3257
|
+
|
|
3258
|
+
function set(obj, keys, val) {
|
|
3259
|
+
keys = keys.split ? keys.split(".") : keys;
|
|
3260
|
+
var i = 0,
|
|
3261
|
+
l = keys.length,
|
|
3262
|
+
t = obj,
|
|
3263
|
+
x,
|
|
3264
|
+
k;
|
|
3265
|
+
|
|
3266
|
+
while (i < l) {
|
|
3267
|
+
k = keys[i++];
|
|
3268
|
+
if (k === "__proto__" || k === "constructor" || k === "prototype") break;
|
|
3269
|
+
|
|
3270
|
+
if (i === l) {
|
|
3271
|
+
t[k] = val;
|
|
3272
|
+
t = t[k];
|
|
3273
|
+
} else {
|
|
3274
|
+
if (typeof (x = t[k]) === typeof keys) {
|
|
3275
|
+
t = t[k] = x;
|
|
3276
|
+
} else if (keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")) {
|
|
3277
|
+
t[k] = {};
|
|
3278
|
+
t = t[k];
|
|
3279
|
+
} else {
|
|
3280
|
+
t[k] = [];
|
|
3281
|
+
t = t[k];
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
|
|
3287
|
+
var mkUntrackedValue = function mkUntrackedValue(o) {
|
|
3288
|
+
return typeof o === "object" ? valtio.ref(o) : o;
|
|
3289
|
+
};
|
|
3290
|
+
|
|
3291
|
+
var transformPathStringToObj = function transformPathStringToObj(str) {
|
|
3292
|
+
var splitStatePathPart = function splitStatePathPart(state) {
|
|
3293
|
+
return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
|
|
3294
|
+
};
|
|
3229
3295
|
|
|
3230
|
-
|
|
3296
|
+
return str.split(".").flatMap(splitStatePathPart);
|
|
3297
|
+
};
|
|
3231
3298
|
|
|
3232
3299
|
function shallowEqual(a1, a2) {
|
|
3233
3300
|
if (a1.length !== a2.length) {
|
|
@@ -3243,145 +3310,144 @@ function shallowEqual(a1, a2) {
|
|
|
3243
3310
|
return true;
|
|
3244
3311
|
}
|
|
3245
3312
|
|
|
3246
|
-
|
|
3313
|
+
function isNum(value) {
|
|
3247
3314
|
return typeof value === "symbol" ? false : !isNaN(+value);
|
|
3248
|
-
}
|
|
3315
|
+
}
|
|
3249
3316
|
|
|
3250
|
-
function
|
|
3251
|
-
var
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
};
|
|
3317
|
+
function saveNewState($$state, path, spec) {
|
|
3318
|
+
var key = JSON.stringify(path);
|
|
3319
|
+
$$state.existingStates.set(key, {
|
|
3320
|
+
path: path,
|
|
3321
|
+
specKey: spec.path
|
|
3322
|
+
});
|
|
3323
|
+
|
|
3324
|
+
if (!$$state.statesInstanceBySpec.has(spec.path)) {
|
|
3325
|
+
$$state.statesInstanceBySpec.set(spec.path, []);
|
|
3326
|
+
}
|
|
3261
3327
|
|
|
3262
|
-
|
|
3263
|
-
|
|
3328
|
+
$$state.statesInstanceBySpec.get(spec.path).push({
|
|
3329
|
+
path: path,
|
|
3330
|
+
specKey: spec.path
|
|
3331
|
+
});
|
|
3332
|
+
}
|
|
3333
|
+
|
|
3334
|
+
function create$StateProxy($$state, handlers) {
|
|
3335
|
+
var getNextKeyToSpecMap = function getNextKeyToSpecMap(currPath) {
|
|
3336
|
+
return new Map(Object.entries(Object.values($$state.specsByKey).filter(function (spec) {
|
|
3264
3337
|
return shallowEqual(currPath.map(function (p) {
|
|
3265
3338
|
return isNum(p) ? "[]" : p;
|
|
3266
|
-
}), spec.
|
|
3267
|
-
}).
|
|
3268
|
-
var
|
|
3269
|
-
|
|
3270
|
-
if (
|
|
3271
|
-
|
|
3272
|
-
isLast: true,
|
|
3273
|
-
specKey: spec.pathStr
|
|
3274
|
-
}];
|
|
3275
|
-
} else {
|
|
3276
|
-
return [nextPart, {
|
|
3277
|
-
isLast: false,
|
|
3278
|
-
specKey: spec.pathStr
|
|
3279
|
-
}];
|
|
3339
|
+
}), spec.pathObj.slice(0, currPath.length));
|
|
3340
|
+
}).reduce(function (agg, spec) {
|
|
3341
|
+
var nextKey = spec.pathObj[currPath.length];
|
|
3342
|
+
|
|
3343
|
+
if (!(nextKey in agg)) {
|
|
3344
|
+
agg[nextKey] = [];
|
|
3280
3345
|
}
|
|
3281
|
-
}));
|
|
3282
|
-
};
|
|
3283
|
-
/**
|
|
3284
|
-
* We use this function when we're setting a value in the middle of the state path.
|
|
3285
|
-
* We can't just set the value, because we need to keep the proxy properties, so
|
|
3286
|
-
* we use the specs to walk through the object and just set the value in the end of the path
|
|
3287
|
-
**/
|
|
3288
3346
|
|
|
3347
|
+
agg[nextKey].push(spec);
|
|
3348
|
+
return agg;
|
|
3349
|
+
}, {})));
|
|
3350
|
+
};
|
|
3289
3351
|
|
|
3290
|
-
var
|
|
3291
|
-
|
|
3292
|
-
return;
|
|
3293
|
-
}
|
|
3352
|
+
var rec = function rec(currPath) {
|
|
3353
|
+
var nextKeyToSpecs = getNextKeyToSpecMap(currPath);
|
|
3294
3354
|
|
|
3295
|
-
var
|
|
3355
|
+
var getSpecForProperty = function getSpecForProperty(property) {
|
|
3356
|
+
var _nextKeyToSpecs$get, _nextKeyToSpecs$get2;
|
|
3296
3357
|
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
nextPart = _Object$entries$_i[0],
|
|
3300
|
-
_Object$entries$_i$ = _Object$entries$_i[1],
|
|
3301
|
-
isLast = _Object$entries$_i$.isLast,
|
|
3302
|
-
specKey = _Object$entries$_i$.specKey;
|
|
3358
|
+
return nextKeyToSpecs.has("[]") && isNum(property) ? (_nextKeyToSpecs$get = nextKeyToSpecs.get("[]")) == null ? void 0 : _nextKeyToSpecs$get[0] : typeof property === "string" && nextKeyToSpecs.has(property) ? (_nextKeyToSpecs$get2 = nextKeyToSpecs.get(property)) == null ? void 0 : _nextKeyToSpecs$get2[0] : undefined;
|
|
3359
|
+
};
|
|
3303
3360
|
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
}
|
|
3308
|
-
} else if (nextPart in value) {
|
|
3309
|
-
if (isLast) {
|
|
3310
|
-
var _handlers$set, _handlers;
|
|
3311
|
-
|
|
3312
|
-
handlers == null ? void 0 : (_handlers$set = (_handlers = handlers({
|
|
3313
|
-
specKey: specKey,
|
|
3314
|
-
path: [].concat(currPath, [nextPart])
|
|
3315
|
-
})).set) == null ? void 0 : _handlers$set.call(_handlers, target, nextPart, value[nextPart], undefined);
|
|
3316
|
-
} else {
|
|
3317
|
-
cloneValue(target[nextPart], [].concat(currPath, [nextPart]), value[nextPart]);
|
|
3318
|
-
}
|
|
3319
|
-
}
|
|
3320
|
-
}
|
|
3321
|
-
};
|
|
3361
|
+
var getNextPath = function getNextPath(property) {
|
|
3362
|
+
return [].concat(currPath, [isNum(property) ? +property : property]);
|
|
3363
|
+
};
|
|
3322
3364
|
|
|
3323
|
-
|
|
3324
|
-
var nextParts = getNextParts(currPath);
|
|
3325
|
-
return new Proxy("[]" in nextParts ? [] : {}, {
|
|
3365
|
+
return new Proxy(nextKeyToSpecs.has("[]") ? [] : {}, {
|
|
3326
3366
|
deleteProperty: function deleteProperty(target, property) {
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
}
|
|
3367
|
+
var prefixPath = getNextPath(property);
|
|
3368
|
+
var specKeysToUpdate = new Set();
|
|
3369
|
+
$$state.existingStates.forEach(function (_ref) {
|
|
3370
|
+
var path = _ref.path,
|
|
3371
|
+
specKey = _ref.specKey;
|
|
3372
|
+
|
|
3373
|
+
if (path.length >= prefixPath.length && shallowEqual(path.slice(0, prefixPath.length), prefixPath)) {
|
|
3374
|
+
deleteState($$state, path);
|
|
3375
|
+
specKeysToUpdate.add(specKey);
|
|
3376
|
+
}
|
|
3377
|
+
});
|
|
3378
|
+
specKeysToUpdate.forEach(function (specKey) {
|
|
3379
|
+
var spec = $$state.specsByKey[specKey];
|
|
3338
3380
|
|
|
3339
|
-
|
|
3381
|
+
if (spec.onChangeProp) {
|
|
3382
|
+
var _$$state$props$spec$o, _$$state$props;
|
|
3383
|
+
|
|
3384
|
+
(_$$state$props$spec$o = (_$$state$props = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o.call(_$$state$props, _get($$state.stateValues, currPath), currPath);
|
|
3385
|
+
}
|
|
3386
|
+
});
|
|
3387
|
+
return Reflect.deleteProperty(target, property);
|
|
3340
3388
|
},
|
|
3341
3389
|
get: function get(target, property, receiver) {
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
if (
|
|
3348
|
-
var _handlers$get,
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
specKey: nextParts[property].specKey
|
|
3353
|
-
})).get) == null ? void 0 : _handlers$get.call(_handlers3, target, property, receiver);
|
|
3390
|
+
var spec = getSpecForProperty(property);
|
|
3391
|
+
|
|
3392
|
+
if (spec && typeof property !== "symbol") {
|
|
3393
|
+
var nextPath = getNextPath(property);
|
|
3394
|
+
|
|
3395
|
+
if (spec.pathObj.length === currPath.length + 1) {
|
|
3396
|
+
var _handlers$get, _handlers;
|
|
3397
|
+
|
|
3398
|
+
// reached the end of the spec
|
|
3399
|
+
target[property] = (_handlers$get = (_handlers = handlers(nextPath, spec)).get) == null ? void 0 : _handlers$get.call(_handlers, target, property, receiver);
|
|
3354
3400
|
} else if (!(property in target)) {
|
|
3355
|
-
target[property] = rec(
|
|
3401
|
+
target[property] = rec(nextPath);
|
|
3356
3402
|
}
|
|
3357
3403
|
}
|
|
3358
3404
|
|
|
3359
|
-
return target
|
|
3405
|
+
return Reflect.get(target, property, receiver);
|
|
3360
3406
|
},
|
|
3361
|
-
set: function set(target, property, value, receiver) {
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
target[property] = value;
|
|
3371
|
-
return (
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3407
|
+
set: function set$1(target, property, value, receiver) {
|
|
3408
|
+
var spec = getSpecForProperty(property);
|
|
3409
|
+
var nextPath = getNextPath(property);
|
|
3410
|
+
|
|
3411
|
+
if (spec && typeof property !== "symbol") {
|
|
3412
|
+
if (spec.pathObj.length === currPath.length + 1) {
|
|
3413
|
+
var _handlers$set, _handlers2;
|
|
3414
|
+
|
|
3415
|
+
// reached the end of the spec
|
|
3416
|
+
target[property] = (_handlers$set = (_handlers2 = handlers(nextPath, spec)).set) == null ? void 0 : _handlers$set.call(_handlers2, target, property, value, receiver);
|
|
3417
|
+
return Reflect.set(target, property, value, receiver);
|
|
3418
|
+
} else if (typeof value === "object") {
|
|
3419
|
+
target[property] = rec(nextPath);
|
|
3420
|
+
|
|
3421
|
+
for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
|
|
3422
|
+
var key = _Object$keys[_i];
|
|
3423
|
+
target[property][key] = value[key];
|
|
3424
|
+
}
|
|
3425
|
+
|
|
3426
|
+
return true;
|
|
3375
3427
|
}
|
|
3376
3428
|
}
|
|
3377
3429
|
|
|
3378
|
-
if (property === "registerInitFunc") {
|
|
3379
|
-
target
|
|
3380
|
-
} else if (typeof value === "object") {
|
|
3381
|
-
cloneValue(target[property], [].concat(currPath, [isNum(property) ? +property : property]), value);
|
|
3430
|
+
if (property === "registerInitFunc" && currPath.length === 0) {
|
|
3431
|
+
return Reflect.set(target, property, value, receiver);
|
|
3382
3432
|
}
|
|
3383
3433
|
|
|
3384
|
-
|
|
3434
|
+
if (nextKeyToSpecs.has("[]")) {
|
|
3435
|
+
var _nextKeyToSpecs$get3;
|
|
3436
|
+
|
|
3437
|
+
set($$state.stateValues, nextPath, value);
|
|
3438
|
+
|
|
3439
|
+
(_nextKeyToSpecs$get3 = nextKeyToSpecs.get("[]")) == null ? void 0 : _nextKeyToSpecs$get3.forEach(function (spec) {
|
|
3440
|
+
if (spec != null && spec.onChangeProp) {
|
|
3441
|
+
var _$$state$props$spec$o2, _$$state$props2;
|
|
3442
|
+
|
|
3443
|
+
(_$$state$props$spec$o2 = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props2, value, nextPath);
|
|
3444
|
+
}
|
|
3445
|
+
});
|
|
3446
|
+
return Reflect.set(target, property, value, receiver);
|
|
3447
|
+
} // invalid setting a value that doesn't make part of the spec
|
|
3448
|
+
|
|
3449
|
+
|
|
3450
|
+
return false;
|
|
3385
3451
|
}
|
|
3386
3452
|
});
|
|
3387
3453
|
};
|
|
@@ -3389,136 +3455,136 @@ function mkProxy(specs, maybeHandlers) {
|
|
|
3389
3455
|
return rec([]);
|
|
3390
3456
|
}
|
|
3391
3457
|
|
|
3392
|
-
function
|
|
3393
|
-
var
|
|
3394
|
-
Object.values(states).forEach(function (_ref) {
|
|
3395
|
-
var path = _ref.path;
|
|
3458
|
+
var deleteState = function deleteState($$state, path) {
|
|
3459
|
+
var _$$state$unsubscripti;
|
|
3396
3460
|
|
|
3397
|
-
|
|
3461
|
+
var key = JSON.stringify(path);
|
|
3462
|
+
(_$$state$unsubscripti = $$state.unsubscriptionsByState[key]) == null ? void 0 : _$$state$unsubscripti.forEach(function (f) {
|
|
3463
|
+
return f();
|
|
3398
3464
|
});
|
|
3399
|
-
|
|
3400
|
-
|
|
3465
|
+
delete $$state.unsubscriptionsByState[key];
|
|
3466
|
+
$$state.existingStates["delete"](key); // delete get($$state.stateValues, path.slice(-1))[path.slice(-1)[0]];
|
|
3467
|
+
// delete get($$state.initStateValues, path.slice(-1))[path.slice(-1)[0]];
|
|
3468
|
+
};
|
|
3401
3469
|
|
|
3402
|
-
function
|
|
3403
|
-
|
|
3404
|
-
}
|
|
3470
|
+
var getIndexes = function getIndexes(path, spec) {
|
|
3471
|
+
var indexes = [];
|
|
3405
3472
|
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
}
|
|
3473
|
+
if (path.length !== spec.pathObj.length) {
|
|
3474
|
+
throw new Error("Unexpected error: state path and spec path have different lengths");
|
|
3475
|
+
}
|
|
3409
3476
|
|
|
3410
|
-
var
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
}
|
|
3477
|
+
for (var i = 0; i < spec.pathObj.length; i++) {
|
|
3478
|
+
if (spec.pathObj[i] === "[]") {
|
|
3479
|
+
indexes.push(path[i]);
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3415
3482
|
|
|
3416
|
-
return
|
|
3483
|
+
return indexes;
|
|
3417
3484
|
};
|
|
3418
3485
|
|
|
3419
|
-
function
|
|
3420
|
-
var
|
|
3421
|
-
var $$state = React__default.useMemo(function () {
|
|
3422
|
-
var specs = Object.fromEntries(_specs.map(function (_ref2) {
|
|
3423
|
-
var pathStr = _ref2.path,
|
|
3424
|
-
spec = _objectWithoutPropertiesLoose(_ref2, ["path"]);
|
|
3425
|
-
|
|
3426
|
-
return [pathStr, _extends({}, spec, {
|
|
3427
|
-
pathStr: pathStr,
|
|
3428
|
-
path: transformPathStringToObj(pathStr),
|
|
3429
|
-
isRepeated: pathStr.split(".").some(function (part) {
|
|
3430
|
-
return part.endsWith("[]");
|
|
3431
|
-
})
|
|
3432
|
-
})];
|
|
3433
|
-
}));
|
|
3434
|
-
return {
|
|
3435
|
-
stateValues: mkProxy(specs),
|
|
3436
|
-
initStateDeps: {},
|
|
3437
|
-
initStateValues: mkProxy(specs),
|
|
3438
|
-
states: {},
|
|
3439
|
-
specs: specs
|
|
3440
|
-
};
|
|
3441
|
-
}, []);
|
|
3442
|
-
var $state = Object.assign(mkProxy($$state.specs, function (state) {
|
|
3443
|
-
return {
|
|
3444
|
-
deleteProperty: function deleteProperty(_target, _property) {
|
|
3445
|
-
var prefixPath = state.path;
|
|
3446
|
-
|
|
3447
|
-
for (var _i2 = 0, _Object$entries2 = Object.entries($$state.states); _i2 < _Object$entries2.length; _i2++) {
|
|
3448
|
-
var _Object$entries2$_i = _Object$entries2[_i2],
|
|
3449
|
-
key = _Object$entries2$_i[0],
|
|
3450
|
-
existingState = _Object$entries2$_i[1];
|
|
3486
|
+
function initializeStateValue($$state, initialStatePath, initialSpec) {
|
|
3487
|
+
var _$$state$unsubscripti2;
|
|
3451
3488
|
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3489
|
+
var initialStateKey = JSON.stringify(initialStatePath);
|
|
3490
|
+
var stateAccess = new Set();
|
|
3491
|
+
var $state = create$StateProxy($$state, function (path, spec) {
|
|
3492
|
+
return {
|
|
3493
|
+
get: function get() {
|
|
3494
|
+
var key = JSON.stringify(path);
|
|
3495
|
+
stateAccess.add({
|
|
3496
|
+
path: path,
|
|
3497
|
+
spec: spec
|
|
3459
3498
|
});
|
|
3460
|
-
return true;
|
|
3461
|
-
},
|
|
3462
|
-
get: function get(_target, _property) {
|
|
3463
|
-
var spec = $$state.specs[state.specKey];
|
|
3464
3499
|
|
|
3465
3500
|
if (spec.valueProp) {
|
|
3466
|
-
|
|
3467
|
-
return props[spec.valueProp];
|
|
3468
|
-
} else {
|
|
3469
|
-
return _get(props[spec.valueProp], state.path.slice(1));
|
|
3470
|
-
}
|
|
3501
|
+
return !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
|
|
3471
3502
|
}
|
|
3472
3503
|
|
|
3473
|
-
if (
|
|
3474
|
-
|
|
3504
|
+
if ($$state.existingStates.has(key)) {
|
|
3505
|
+
// is already initialized
|
|
3506
|
+
return _get($$state.stateValues, path);
|
|
3507
|
+
} else if (spec.initFunc) {
|
|
3508
|
+
initializeStateValue($$state, path, spec);
|
|
3509
|
+
}
|
|
3475
3510
|
|
|
3476
|
-
|
|
3511
|
+
return _get($$state.stateValues, path);
|
|
3512
|
+
},
|
|
3513
|
+
set: function set() {
|
|
3514
|
+
throw new Error("Cannot update state values during initialization");
|
|
3515
|
+
}
|
|
3516
|
+
};
|
|
3517
|
+
});
|
|
3518
|
+
(_$$state$unsubscripti2 = $$state.unsubscriptionsByState[initialStateKey]) == null ? void 0 : _$$state$unsubscripti2.forEach(function (f) {
|
|
3519
|
+
return f();
|
|
3520
|
+
});
|
|
3521
|
+
$$state.unsubscriptionsByState[initialStateKey] = [];
|
|
3522
|
+
stateAccess.forEach(function (_ref2) {
|
|
3523
|
+
var path = _ref2.path,
|
|
3524
|
+
spec = _ref2.spec;
|
|
3525
|
+
var unsubscribe = utils.subscribeKey(_get($$state.stateValues, path.slice(-1)), path.slice(-1)[0], function () {
|
|
3526
|
+
return set($$state.stateValues, initialStatePath, mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(path, spec))));
|
|
3527
|
+
});
|
|
3528
|
+
$$state.unsubscriptionsByState[initialStateKey].push(unsubscribe);
|
|
3529
|
+
});
|
|
3530
|
+
var untrackedInitialValue = mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(initialStatePath, initialSpec)));
|
|
3477
3531
|
|
|
3478
|
-
|
|
3532
|
+
set($$state.initStateValues, initialStatePath, untrackedInitialValue);
|
|
3479
3533
|
|
|
3480
|
-
|
|
3534
|
+
set($$state.stateValues, initialStatePath, untrackedInitialValue);
|
|
3481
3535
|
|
|
3482
|
-
|
|
3536
|
+
return untrackedInitialValue;
|
|
3537
|
+
}
|
|
3483
3538
|
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3539
|
+
function useDollarState(specs, props) {
|
|
3540
|
+
var $$state = React__default.useRef(valtio.proxy({
|
|
3541
|
+
stateValues: {},
|
|
3542
|
+
initStateValues: {},
|
|
3543
|
+
specsByKey: Object.fromEntries(specs.map(function (spec) {
|
|
3544
|
+
return [spec.path, _extends({}, spec, {
|
|
3545
|
+
pathObj: transformPathStringToObj(spec.path),
|
|
3546
|
+
isRepeated: spec.path.split(".").some(function (part) {
|
|
3547
|
+
return part.endsWith("[]");
|
|
3548
|
+
})
|
|
3549
|
+
})];
|
|
3550
|
+
})),
|
|
3551
|
+
statesInstanceBySpec: new Map(),
|
|
3552
|
+
existingStates: new Map(),
|
|
3553
|
+
unsubscriptionsByState: {},
|
|
3554
|
+
props: undefined,
|
|
3555
|
+
registrationsQueue: []
|
|
3556
|
+
})).current;
|
|
3557
|
+
$$state.props = mkUntrackedValue(props);
|
|
3558
|
+
var $state = React__default.useRef(Object.assign(create$StateProxy($$state, function (path, spec) {
|
|
3559
|
+
var key = JSON.stringify(path);
|
|
3490
3560
|
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
set: function set(_target, _property, newValue) {
|
|
3494
|
-
if (newValue !== _get($$state.stateValues, state.path)) {
|
|
3495
|
-
saveState(state, $$state.states);
|
|
3561
|
+
if (!$$state.existingStates.has(key)) {
|
|
3562
|
+
var _spec$initVal;
|
|
3496
3563
|
|
|
3497
|
-
|
|
3564
|
+
saveNewState($$state, path, spec);
|
|
3565
|
+
var untrackedValue = !spec.initFunc ? mkUntrackedValue((_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined) : initializeStateValue($$state, path, spec);
|
|
3498
3566
|
|
|
3499
|
-
|
|
3500
|
-
var _Object$entries3$_i = _Object$entries3[_i3],
|
|
3501
|
-
key = _Object$entries3$_i[0],
|
|
3502
|
-
deps = _Object$entries3$_i[1];
|
|
3567
|
+
set($$state.stateValues, path, untrackedValue);
|
|
3503
3568
|
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
}
|
|
3507
|
-
}
|
|
3569
|
+
set($$state.initStateValues, path, untrackedValue);
|
|
3570
|
+
}
|
|
3508
3571
|
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3572
|
+
return {
|
|
3573
|
+
get: function get() {
|
|
3574
|
+
if (spec.valueProp) {
|
|
3575
|
+
var value = !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
|
|
3576
|
+
return value;
|
|
3577
|
+
} else {
|
|
3578
|
+
return _get($$state.stateValues, path);
|
|
3514
3579
|
}
|
|
3515
|
-
|
|
3516
|
-
|
|
3580
|
+
},
|
|
3581
|
+
set: function set$1(_t, _p, value) {
|
|
3582
|
+
set($$state.stateValues, path, mkUntrackedValue(value));
|
|
3517
3583
|
|
|
3518
3584
|
if (spec.onChangeProp) {
|
|
3519
|
-
var
|
|
3585
|
+
var _$$state$props$spec$o3, _$$state$props3;
|
|
3520
3586
|
|
|
3521
|
-
(
|
|
3587
|
+
(_$$state$props$spec$o3 = (_$$state$props3 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o3.call(_$$state$props3, value, path);
|
|
3522
3588
|
}
|
|
3523
3589
|
|
|
3524
3590
|
return true;
|
|
@@ -3526,157 +3592,117 @@ function useVanillaDollarState(_specs, props) {
|
|
|
3526
3592
|
};
|
|
3527
3593
|
}), {
|
|
3528
3594
|
registerInitFunc: function registerInitFunc(pathStr, f) {
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
return _get($$state.
|
|
3595
|
+
var _$$state$statesInstan;
|
|
3596
|
+
|
|
3597
|
+
if ((_$$state$statesInstan = $$state.statesInstanceBySpec.get(pathStr)) != null && _$$state$statesInstan.some(function (_ref3) {
|
|
3598
|
+
var path = _ref3.path,
|
|
3599
|
+
specKey = _ref3.specKey;
|
|
3600
|
+
return !deepEqual(_get($$state.initStateValues, path), f(props, $state, getIndexes(path, $$state.specsByKey[specKey])));
|
|
3535
3601
|
})) {
|
|
3536
|
-
$$state.
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
forceRender(function (r) {
|
|
3540
|
-
return r + 1;
|
|
3602
|
+
$$state.registrationsQueue.push({
|
|
3603
|
+
pathStr: pathStr,
|
|
3604
|
+
f: f
|
|
3541
3605
|
});
|
|
3542
3606
|
}
|
|
3543
3607
|
}
|
|
3544
|
-
}); // For each spec with an initFunc, evaluate it and see if
|
|
3608
|
+
})).current; // For each spec with an initFunc, evaluate it and see if
|
|
3545
3609
|
// the init value has changed. If so, reset its state.
|
|
3546
3610
|
|
|
3547
|
-
var newStateValues = undefined;
|
|
3548
3611
|
var resetSpecs = [];
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
specKey = _Object$values$_i.specKey;
|
|
3554
|
-
var spec = $$state.specs[specKey];
|
|
3612
|
+
$$state.existingStates.forEach(function (_ref4) {
|
|
3613
|
+
var path = _ref4.path,
|
|
3614
|
+
specKey = _ref4.specKey;
|
|
3615
|
+
var spec = $$state.specsByKey[specKey];
|
|
3555
3616
|
|
|
3556
3617
|
if (spec.initFunc) {
|
|
3557
|
-
var newInit = spec.initFunc(props, $state);
|
|
3618
|
+
var newInit = spec.initFunc(props, $state, getIndexes(path, spec));
|
|
3558
3619
|
|
|
3559
|
-
if (newInit
|
|
3560
|
-
console.log("init changed for " + JSON.stringify(path) + " from " + _get($$state.initStateValues, path) + " to " + newInit + "; resetting state");
|
|
3620
|
+
if (!deepEqual(newInit, _get($$state.initStateValues, path))) {
|
|
3561
3621
|
resetSpecs.push({
|
|
3562
3622
|
path: path,
|
|
3563
|
-
|
|
3623
|
+
spec: spec
|
|
3564
3624
|
});
|
|
3565
|
-
|
|
3566
|
-
if (!newStateValues) {
|
|
3567
|
-
newStateValues = cloneProxy($$state.specs, $$state.states, $$state.stateValues);
|
|
3568
|
-
}
|
|
3569
|
-
|
|
3570
|
-
dset.dset(newStateValues, path, UNINITIALIZED);
|
|
3571
3625
|
}
|
|
3572
3626
|
}
|
|
3573
|
-
}
|
|
3574
|
-
|
|
3627
|
+
});
|
|
3575
3628
|
React__default.useLayoutEffect(function () {
|
|
3576
|
-
|
|
3577
|
-
var
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
var path = _ref5.path;
|
|
3581
|
-
|
|
3582
|
-
dset.dset(initStateValues, path, _get(newStateValues, path));
|
|
3583
|
-
});
|
|
3584
|
-
$$state.stateValues = cloneProxy($$state.specs, $$state.states, newStateValues);
|
|
3585
|
-
$$state.initStateValues = initStateValues;
|
|
3586
|
-
$$state.initStateDeps = _extends({}, $$state.initStateDeps, newDeps);
|
|
3587
|
-
forceRender(function (r) {
|
|
3588
|
-
return r + 1;
|
|
3589
|
-
});
|
|
3590
|
-
|
|
3591
|
-
for (var _iterator = _createForOfIteratorHelperLoose(resetSpecs), _step; !(_step = _iterator()).done;) {
|
|
3592
|
-
var _step$value = _step.value,
|
|
3593
|
-
_path = _step$value.path,
|
|
3594
|
-
_specKey = _step$value.specKey;
|
|
3595
|
-
var _spec = $$state.specs[_specKey];
|
|
3629
|
+
resetSpecs.forEach(function (_ref5) {
|
|
3630
|
+
var path = _ref5.path,
|
|
3631
|
+
spec = _ref5.spec;
|
|
3632
|
+
var newInit = initializeStateValue($$state, path, spec);
|
|
3596
3633
|
|
|
3597
|
-
|
|
3598
|
-
|
|
3634
|
+
if (spec.onChangeProp) {
|
|
3635
|
+
var _$$state$props$spec$o4, _$$state$props4;
|
|
3599
3636
|
|
|
3600
|
-
|
|
3601
|
-
(_props$_spec$onChange = props[_spec.onChangeProp]) == null ? void 0 : _props$_spec$onChange.call(props, _get(newStateValues, _path));
|
|
3602
|
-
}
|
|
3637
|
+
(_$$state$props$spec$o4 = (_$$state$props4 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o4.call(_$$state$props4, newInit, path);
|
|
3603
3638
|
}
|
|
3604
|
-
}
|
|
3605
|
-
}, [
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
for (var _i5 = 0, _Object$values2 = Object.values($$state.states); _i5 < _Object$values2.length; _i5++) {
|
|
3616
|
-
var _path2 = _Object$values2[_i5].path;
|
|
3617
|
-
|
|
3618
|
-
_get($state, _path2);
|
|
3619
|
-
}
|
|
3639
|
+
});
|
|
3640
|
+
}, [props, resetSpecs]);
|
|
3641
|
+
React__default.useLayoutEffect(function () {
|
|
3642
|
+
$$state.registrationsQueue.forEach(function (_ref6) {
|
|
3643
|
+
var f = _ref6.f,
|
|
3644
|
+
pathStr = _ref6.pathStr;
|
|
3645
|
+
$$state.specsByKey[pathStr].initFunc = f;
|
|
3646
|
+
});
|
|
3647
|
+
$$state.registrationsQueue = [];
|
|
3648
|
+
}, [$$state.registrationsQueue]); // Re-render if any value changed in one of these objects
|
|
3620
3649
|
|
|
3650
|
+
valtio.useSnapshot($$state.stateValues, {
|
|
3651
|
+
sync: true
|
|
3652
|
+
});
|
|
3653
|
+
valtio.useSnapshot($$state.specsByKey, {
|
|
3654
|
+
sync: true
|
|
3655
|
+
});
|
|
3621
3656
|
return $state;
|
|
3622
3657
|
}
|
|
3623
3658
|
|
|
3624
|
-
function
|
|
3625
|
-
var
|
|
3626
|
-
|
|
3627
|
-
|
|
3659
|
+
function useCanvasDollarState(specs, props) {
|
|
3660
|
+
var $$state = valtio.proxy({
|
|
3661
|
+
stateValues: {},
|
|
3662
|
+
initStateValues: {},
|
|
3663
|
+
specsByKey: Object.fromEntries(specs.map(function (spec) {
|
|
3664
|
+
return [spec.path, _extends({}, spec, {
|
|
3665
|
+
pathObj: transformPathStringToObj(spec.path),
|
|
3666
|
+
isRepeated: spec.path.split(".").some(function (part) {
|
|
3667
|
+
return part.endsWith("[]");
|
|
3668
|
+
})
|
|
3669
|
+
})];
|
|
3670
|
+
})),
|
|
3671
|
+
statesInstanceBySpec: new Map(),
|
|
3672
|
+
existingStates: new Map(),
|
|
3673
|
+
unsubscriptionsByState: {},
|
|
3674
|
+
props: undefined,
|
|
3675
|
+
registrationsQueue: []
|
|
3676
|
+
});
|
|
3677
|
+
$$state.props = mkUntrackedValue(props);
|
|
3678
|
+
var $state = create$StateProxy($$state, function (path, spec) {
|
|
3628
3679
|
return {
|
|
3629
|
-
get: function get(
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
return props[spec.valueProp];
|
|
3635
|
-
} else {
|
|
3636
|
-
return _get(props[spec.valueProp], state.path.slice(1));
|
|
3637
|
-
}
|
|
3638
|
-
}
|
|
3639
|
-
|
|
3640
|
-
var value = _get(stateValues, state.path);
|
|
3641
|
-
|
|
3642
|
-
if (value === UNINITIALIZED) {
|
|
3643
|
-
// This value has a init expression; need to be evaluated.
|
|
3644
|
-
value = tracked(state);
|
|
3680
|
+
get: function get() {
|
|
3681
|
+
return _get($$state.stateValues, path);
|
|
3682
|
+
},
|
|
3683
|
+
set: function set$1(_t, _p, value) {
|
|
3684
|
+
set($$state.stateValues, path, mkUntrackedValue(value));
|
|
3645
3685
|
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
// trackInit() to know what fields were used to compute
|
|
3649
|
-
// the init value
|
|
3686
|
+
if (spec.onChangeProp) {
|
|
3687
|
+
var _$$state$props$spec$o5, _$$state$props5;
|
|
3650
3688
|
|
|
3689
|
+
(_$$state$props$spec$o5 = (_$$state$props5 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o5.call(_$$state$props5, value, path);
|
|
3690
|
+
}
|
|
3651
3691
|
|
|
3652
|
-
|
|
3653
|
-
return value;
|
|
3654
|
-
},
|
|
3655
|
-
set: function set() {
|
|
3656
|
-
throw new Error("Cannot update state values during initialization");
|
|
3692
|
+
return true;
|
|
3657
3693
|
}
|
|
3658
3694
|
};
|
|
3659
|
-
}), {
|
|
3660
|
-
registerInitFunc: function registerInitFunc() {}
|
|
3661
3695
|
});
|
|
3662
3696
|
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
var
|
|
3666
|
-
var
|
|
3667
|
-
initFuncDeps[JSON.stringify(state.path)] = [].concat(deps.values());
|
|
3668
|
-
return res;
|
|
3669
|
-
}
|
|
3670
|
-
|
|
3671
|
-
for (var _i6 = 0, _Object$values3 = Object.values(states); _i6 < _Object$values3.length; _i6++) {
|
|
3672
|
-
var path = _Object$values3[_i6].path;
|
|
3697
|
+
for (var _iterator = _createForOfIteratorHelperLoose(specs), _step; !(_step = _iterator()).done;) {
|
|
3698
|
+
var spec = _step.value;
|
|
3699
|
+
var path = transformPathStringToObj(spec.path);
|
|
3700
|
+
var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initVal ? spec.initVal : spec.initFunc ? initializeStateValue($$state, path, $$state.specsByKey[spec.path]) : undefined;
|
|
3673
3701
|
|
|
3674
|
-
|
|
3675
|
-
_get($state, path);
|
|
3676
|
-
}
|
|
3702
|
+
set($state, path, init);
|
|
3677
3703
|
}
|
|
3678
3704
|
|
|
3679
|
-
return
|
|
3705
|
+
return $state;
|
|
3680
3706
|
}
|
|
3681
3707
|
|
|
3682
3708
|
exports.DropdownMenu = DropdownMenu;
|
|
@@ -3701,14 +3727,17 @@ exports.generateStateValueProp = generateStateValueProp;
|
|
|
3701
3727
|
exports.getDataProps = getDataProps;
|
|
3702
3728
|
exports.hasVariant = hasVariant;
|
|
3703
3729
|
exports.makeFragment = makeFragment;
|
|
3730
|
+
exports.mergeVariantsWithStates = mergeVariantsWithStates;
|
|
3704
3731
|
exports.omit = omit;
|
|
3705
3732
|
exports.pick = pick;
|
|
3706
3733
|
exports.plasmicHeadMeta = plasmicHeadMeta;
|
|
3707
3734
|
exports.renderPlasmicSlot = renderPlasmicSlot;
|
|
3735
|
+
exports.set = set;
|
|
3708
3736
|
exports.setPlumeStrictMode = setPlumeStrictMode;
|
|
3709
3737
|
exports.useButton = useButton;
|
|
3738
|
+
exports.useCanvasDollarState = useCanvasDollarState;
|
|
3710
3739
|
exports.useCheckbox = useCheckbox;
|
|
3711
|
-
exports.useDollarState =
|
|
3740
|
+
exports.useDollarState = useDollarState;
|
|
3712
3741
|
exports.useIsSSR = useIsSSR;
|
|
3713
3742
|
exports.useMenu = useMenu;
|
|
3714
3743
|
exports.useMenuButton = useMenuButton;
|