@plasmicapp/react-web 0.2.110 → 0.2.113
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/LICENSE.md +21 -0
- package/dist/all.d.ts +65 -28
- package/dist/common.d.ts +3 -3
- package/dist/index-common.d.ts +4 -3
- package/dist/index.d.ts +1 -1
- package/dist/react-web.cjs.development.js +415 -370
- 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 +401 -370
- package/dist/react-web.esm.js.map +1 -1
- package/dist/render/elements.d.ts +5 -0
- package/dist/render/ssr.d.ts +1 -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 +8 -3
- package/skinny/dist/{collection-utils-57c273dc.js → collection-utils-43f97262.js} +14 -13
- package/skinny/dist/collection-utils-43f97262.js.map +1 -0
- package/skinny/dist/{common-182a0b0c.js → common-9ebe374e.js} +1 -1
- package/skinny/dist/common-9ebe374e.js.map +1 -0
- package/skinny/dist/common.d.ts +3 -3
- package/skinny/dist/index-common.d.ts +4 -3
- package/skinny/dist/index.d.ts +1 -1
- package/skinny/dist/index.js +53 -42
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/plume/button/index.js +7 -7
- package/skinny/dist/plume/button/index.js.map +1 -1
- package/skinny/dist/plume/checkbox/index.js +18 -17
- package/skinny/dist/plume/checkbox/index.js.map +1 -1
- package/skinny/dist/plume/menu/index.js +39 -39
- package/skinny/dist/plume/menu/index.js.map +1 -1
- package/skinny/dist/plume/menu-button/index.js +23 -22
- package/skinny/dist/plume/menu-button/index.js.map +1 -1
- package/skinny/dist/plume/select/index.js +42 -43
- package/skinny/dist/plume/select/index.js.map +1 -1
- package/skinny/dist/plume/switch/index.js +17 -16
- package/skinny/dist/plume/switch/index.js.map +1 -1
- package/skinny/dist/plume/text-input/index.js +10 -10
- package/skinny/dist/plume/text-input/index.js.map +1 -1
- package/skinny/dist/plume/triggered-overlay/index.js +14 -14
- package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
- package/skinny/dist/{plume-utils-623b91cc.js → plume-utils-d9811bf3.js} +2 -2
- package/skinny/dist/{plume-utils-27cd384f.js.map → plume-utils-d9811bf3.js.map} +1 -1
- package/skinny/dist/{props-utils-b2ad4997.js → props-utils-228208e6.js} +2 -2
- package/skinny/dist/{props-utils-7c02c0a8.js.map → props-utils-228208e6.js.map} +1 -1
- package/skinny/dist/{react-utils-35cb2a4e.js → react-utils-7bc53870.js} +6 -6
- package/skinny/dist/{react-utils-35cb2a4e.js.map → react-utils-7bc53870.js.map} +1 -1
- package/skinny/dist/render/PlasmicHead/index.js +6 -6
- package/skinny/dist/render/PlasmicImg/index.js +27 -27
- package/skinny/dist/render/PlasmicImg/index.js.map +1 -1
- package/skinny/dist/render/elements.d.ts +5 -0
- package/skinny/dist/render/ssr.d.ts +1 -0
- package/skinny/dist/{ssr-b1615b80.js → ssr-b16a1854.js} +16 -10
- package/skinny/dist/ssr-b16a1854.js.map +1 -0
- package/skinny/dist/states/helpers.d.ts +5 -0
- package/skinny/dist/states/index.d.ts +1 -1
- package/skinny/dist/states/valtio.d.ts +16 -0
- package/skinny/dist/stories/UseDollarState.stories.d.ts +11 -0
- package/skinny/dist/collection-utils-2745acd4.js +0 -238
- package/skinny/dist/collection-utils-2745acd4.js.map +0 -1
- package/skinny/dist/collection-utils-3487dd27.js +0 -238
- package/skinny/dist/collection-utils-3487dd27.js.map +0 -1
- package/skinny/dist/collection-utils-57c273dc.js.map +0 -1
- package/skinny/dist/common-182a0b0c.js.map +0 -1
- package/skinny/dist/plume-utils-27cd384f.js +0 -35
- package/skinny/dist/plume-utils-623b91cc.js.map +0 -1
- package/skinny/dist/props-utils-7c02c0a8.js +0 -8
- package/skinny/dist/props-utils-b2ad4997.js.map +0 -1
- package/skinny/dist/react-utils-7c01e440.js +0 -172
- package/skinny/dist/react-utils-7c01e440.js.map +0 -1
- package/skinny/dist/render/PlasmicHead.d.ts +0 -35
- 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-84e27ffb.js +0 -110
- package/skinny/dist/ssr-84e27ffb.js.map +0 -1
- package/skinny/dist/ssr-9ebd98ed.js +0 -158
- package/skinny/dist/ssr-9ebd98ed.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
- package/skinny/dist/ssr-f4053cdd.js +0 -110
- package/skinny/dist/ssr-f4053cdd.js.map +0 -1
- package/skinny/dist/ssr-fbf922f6.js +0 -108
- package/skinny/dist/ssr-fbf922f6.js.map +0 -1
- package/skinny/dist/tslib.es6-d26ffe68.js +0 -132
- package/skinny/dist/tslib.es6-d26ffe68.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) {
|
|
@@ -79,28 +82,24 @@ function _arrayLikeToArray(arr, len) {
|
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
82
|
-
var it;
|
|
85
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
86
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
83
87
|
|
|
84
|
-
if (
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
done: true
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
done: false,
|
|
94
|
-
value: o[i++]
|
|
95
|
-
};
|
|
88
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
89
|
+
if (it) o = it;
|
|
90
|
+
var i = 0;
|
|
91
|
+
return function () {
|
|
92
|
+
if (i >= o.length) return {
|
|
93
|
+
done: true
|
|
96
94
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
return {
|
|
96
|
+
done: false,
|
|
97
|
+
value: o[i++]
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
return it.next.bind(it);
|
|
102
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
function notNil(x) {
|
|
@@ -374,9 +373,13 @@ function getElementTypeName(element) {
|
|
|
374
373
|
}
|
|
375
374
|
}
|
|
376
375
|
|
|
376
|
+
var _excluded = ["children"],
|
|
377
|
+
_excluded2 = ["as", "hasGap"],
|
|
378
|
+
_excluded3 = ["hasGap"];
|
|
379
|
+
|
|
377
380
|
function renderStack(as, props, hasGap, ref) {
|
|
378
381
|
var children = props.children,
|
|
379
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
382
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
380
383
|
|
|
381
384
|
var wrappedChildren = wrapFlexContainerChildren(children, hasGap != null ? hasGap : false);
|
|
382
385
|
return createElementWithChildren(as, _extends({
|
|
@@ -387,7 +390,7 @@ function renderStack(as, props, hasGap, ref) {
|
|
|
387
390
|
function FlexStack_(props, outerRef) {
|
|
388
391
|
var as = props.as,
|
|
389
392
|
hasGap = props.hasGap,
|
|
390
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
393
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
391
394
|
|
|
392
395
|
return renderStack(as != null ? as : "div", rest, hasGap, outerRef);
|
|
393
396
|
}
|
|
@@ -397,7 +400,7 @@ var FlexStack = /*#__PURE__*/React.forwardRef(FlexStack_);
|
|
|
397
400
|
var makeStackImpl = function makeStackImpl(as) {
|
|
398
401
|
return React.forwardRef(function (props, ref) {
|
|
399
402
|
var hasGap = props.hasGap,
|
|
400
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
403
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded3);
|
|
401
404
|
|
|
402
405
|
return renderStack(as, rest, hasGap, ref);
|
|
403
406
|
});
|
|
@@ -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,
|
|
@@ -895,13 +906,15 @@ var plasmicHeadMeta = {
|
|
|
895
906
|
}
|
|
896
907
|
};
|
|
897
908
|
|
|
909
|
+
var _excluded$1 = ["PlasmicIconType"];
|
|
898
910
|
function PlasmicIcon(props) {
|
|
899
911
|
var PlasmicIconType = props.PlasmicIconType,
|
|
900
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
912
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$1);
|
|
901
913
|
|
|
902
914
|
return React.createElement(PlasmicIconType, Object.assign({}, rest));
|
|
903
915
|
}
|
|
904
916
|
|
|
917
|
+
var _excluded$2 = ["src", "className", "displayWidth", "displayHeight", "displayMinWidth", "displayMinHeight", "displayMaxWidth", "displayMaxHeight", "quality", "loader", "imgRef", "style", "loading"];
|
|
905
918
|
// TODO: make this configurable?
|
|
906
919
|
|
|
907
920
|
var IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
|
|
@@ -921,7 +934,7 @@ var PlasmicImg = /*#__PURE__*/React__default.forwardRef(function PlasmicImg(prop
|
|
|
921
934
|
imgRef = props.imgRef,
|
|
922
935
|
style = props.style,
|
|
923
936
|
loading = props.loading,
|
|
924
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
937
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$2);
|
|
925
938
|
|
|
926
939
|
var imgProps = Object.assign({}, rest, {
|
|
927
940
|
// Default loading to "lazy" if not specified (which is different from the
|
|
@@ -1380,6 +1393,7 @@ function hasKey(v, key) {
|
|
|
1380
1393
|
return typeof v === "object" && v !== null && key in v;
|
|
1381
1394
|
}
|
|
1382
1395
|
|
|
1396
|
+
var _excluded$3 = ["as", "defaultContents", "value"];
|
|
1383
1397
|
function PlasmicSlot(props) {
|
|
1384
1398
|
return renderPlasmicSlot(props);
|
|
1385
1399
|
}
|
|
@@ -1387,7 +1401,7 @@ function renderPlasmicSlot(opts) {
|
|
|
1387
1401
|
var as = opts.as,
|
|
1388
1402
|
defaultContents = opts.defaultContents,
|
|
1389
1403
|
value = opts.value,
|
|
1390
|
-
rest = _objectWithoutPropertiesLoose(opts,
|
|
1404
|
+
rest = _objectWithoutPropertiesLoose(opts, _excluded$3);
|
|
1391
1405
|
|
|
1392
1406
|
var content = value === undefined ? defaultContents : value;
|
|
1393
1407
|
|
|
@@ -1538,19 +1552,29 @@ function createUseScreenVariants(isMulti, screenQueries) {
|
|
|
1538
1552
|
var PlasmicRootContext = /*#__PURE__*/React.createContext(undefined);
|
|
1539
1553
|
function PlasmicRootProvider(props) {
|
|
1540
1554
|
var platform = props.platform,
|
|
1541
|
-
children = props.children
|
|
1555
|
+
children = props.children,
|
|
1556
|
+
userAuthToken = props.userAuthToken,
|
|
1557
|
+
user = props.user;
|
|
1542
1558
|
var context = React.useMemo(function () {
|
|
1543
1559
|
return {
|
|
1544
1560
|
platform: platform
|
|
1545
1561
|
};
|
|
1546
1562
|
}, [platform]);
|
|
1563
|
+
var dataSourceContextValue = React.useMemo(function () {
|
|
1564
|
+
return {
|
|
1565
|
+
userAuthToken: userAuthToken,
|
|
1566
|
+
user: user
|
|
1567
|
+
};
|
|
1568
|
+
}, [userAuthToken, user]);
|
|
1547
1569
|
return React.createElement(PlasmicRootContext.Provider, {
|
|
1548
1570
|
value: context
|
|
1549
|
-
}, React.createElement(ssr.SSRProvider, null, React.createElement(
|
|
1571
|
+
}, React.createElement(ssr.SSRProvider, null, React.createElement(dataSourcesContext.PlasmicDataSourceContextProvider, {
|
|
1572
|
+
value: dataSourceContextValue
|
|
1573
|
+
}, React.createElement(PlasmicTranslatorContext.Provider, {
|
|
1550
1574
|
value: props.translator
|
|
1551
1575
|
}, React.createElement(PlasmicHeadContext.Provider, {
|
|
1552
1576
|
value: props.Head
|
|
1553
|
-
}, children))));
|
|
1577
|
+
}, children)))));
|
|
1554
1578
|
}
|
|
1555
1579
|
var useIsSSR = ssr.useIsSSR;
|
|
1556
1580
|
function useHasPlasmicRoot() {
|
|
@@ -1704,6 +1728,7 @@ function getPlumeType(child) {
|
|
|
1704
1728
|
return childType.__plumeType || (childType.getPlumeType == null ? void 0 : childType.getPlumeType(child.props));
|
|
1705
1729
|
}
|
|
1706
1730
|
|
|
1731
|
+
var _excluded$4 = ["link", "isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "children"];
|
|
1707
1732
|
function useButton(plasmicClass, props, config, ref) {
|
|
1708
1733
|
var _ref, _ref2, _extends2, _overrides;
|
|
1709
1734
|
|
|
@@ -1718,7 +1743,7 @@ function useButton(plasmicClass, props, config, ref) {
|
|
|
1718
1743
|
showStartIcon = props.showStartIcon,
|
|
1719
1744
|
showEndIcon = props.showEndIcon,
|
|
1720
1745
|
children = props.children,
|
|
1721
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
1746
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$4);
|
|
1722
1747
|
|
|
1723
1748
|
var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
|
|
1724
1749
|
def: config.showStartIconVariant,
|
|
@@ -2068,6 +2093,7 @@ var TriggeredOverlayContext = /*#__PURE__*/React.createContext(undefined);
|
|
|
2068
2093
|
|
|
2069
2094
|
var MenuContext = /*#__PURE__*/React.createContext(undefined);
|
|
2070
2095
|
|
|
2096
|
+
var _excluded$5 = ["children"];
|
|
2071
2097
|
var COLLECTION_OPTS = {
|
|
2072
2098
|
itemPlumeType: "menu-item",
|
|
2073
2099
|
sectionPlumeType: "menu-group"
|
|
@@ -2078,7 +2104,7 @@ var COLLECTION_OPTS = {
|
|
|
2078
2104
|
|
|
2079
2105
|
function asAriaMenuProps(props) {
|
|
2080
2106
|
var children = props.children,
|
|
2081
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
2107
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$5);
|
|
2082
2108
|
|
|
2083
2109
|
var _useDerivedItemsFromC = useDerivedItemsFromChildren(children, _extends({}, COLLECTION_OPTS, {
|
|
2084
2110
|
invalidChildError: "Can only use Menu.Item and Menu.Group as children to Menu",
|
|
@@ -2521,6 +2547,7 @@ function useMenuButton(plasmicClass, props, config, outerRef) {
|
|
|
2521
2547
|
|
|
2522
2548
|
var SelectContext = /*#__PURE__*/React.createContext(undefined);
|
|
2523
2549
|
|
|
2550
|
+
var _excluded$6 = ["value", "defaultValue", "children", "onChange", "placement", "menuMatchTriggerWidth", "menuWidth"];
|
|
2524
2551
|
var COLLECTION_OPTS$1 = {
|
|
2525
2552
|
itemPlumeType: "select-option",
|
|
2526
2553
|
sectionPlumeType: "select-option-group"
|
|
@@ -2566,7 +2593,7 @@ function useAriaSelectProps(props) {
|
|
|
2566
2593
|
defaultValue = props.defaultValue,
|
|
2567
2594
|
children = props.children,
|
|
2568
2595
|
onChange = props.onChange,
|
|
2569
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
2596
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$6);
|
|
2570
2597
|
|
|
2571
2598
|
var _useDerivedItemsFromC = useDerivedItemsFromChildren(children, _extends({}, COLLECTION_OPTS$1, {
|
|
2572
2599
|
invalidChildError: "Can only use Select.Option and Select.OptionGroup as children to Select",
|
|
@@ -3008,6 +3035,7 @@ function useSwitch(plasmicClass, props, config, ref) {
|
|
|
3008
3035
|
};
|
|
3009
3036
|
}
|
|
3010
3037
|
|
|
3038
|
+
var _excluded$7 = ["isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "className", "style", "inputClassName", "inputStyle"];
|
|
3011
3039
|
function useTextInput(plasmicClass, props, config, ref) {
|
|
3012
3040
|
var _ref, _ref2, _overrides;
|
|
3013
3041
|
|
|
@@ -3024,7 +3052,7 @@ function useTextInput(plasmicClass, props, config, ref) {
|
|
|
3024
3052
|
style = props.style,
|
|
3025
3053
|
inputClassName = props.inputClassName,
|
|
3026
3054
|
inputStyle = props.inputStyle,
|
|
3027
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
3055
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$7);
|
|
3028
3056
|
|
|
3029
3057
|
var rootRef = React.useRef(null);
|
|
3030
3058
|
var inputRef = React.useRef(null);
|
|
@@ -3217,7 +3245,7 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissabl
|
|
|
3217
3245
|
|
|
3218
3246
|
function generateStateOnChangeProp($state, stateName, dataReps) {
|
|
3219
3247
|
return function (val, path) {
|
|
3220
|
-
return
|
|
3248
|
+
return set($state, [stateName].concat(dataReps, path), val);
|
|
3221
3249
|
};
|
|
3222
3250
|
}
|
|
3223
3251
|
/**
|
|
@@ -3231,8 +3259,51 @@ function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
|
|
|
3231
3259
|
) {
|
|
3232
3260
|
return _get($state, path);
|
|
3233
3261
|
}
|
|
3262
|
+
/**
|
|
3263
|
+
* Forked from https://github.com/lukeed/dset
|
|
3264
|
+
* Changes: fixed setting a deep value to a proxy object
|
|
3265
|
+
*/
|
|
3266
|
+
|
|
3267
|
+
function set(obj, keys, val) {
|
|
3268
|
+
keys = keys.split ? keys.split(".") : keys;
|
|
3269
|
+
var i = 0,
|
|
3270
|
+
l = keys.length,
|
|
3271
|
+
t = obj,
|
|
3272
|
+
x,
|
|
3273
|
+
k;
|
|
3274
|
+
|
|
3275
|
+
while (i < l) {
|
|
3276
|
+
k = keys[i++];
|
|
3277
|
+
if (k === "__proto__" || k === "constructor" || k === "prototype") break;
|
|
3278
|
+
|
|
3279
|
+
if (i === l) {
|
|
3280
|
+
t[k] = val;
|
|
3281
|
+
t = t[k];
|
|
3282
|
+
} else {
|
|
3283
|
+
if (typeof (x = t[k]) === typeof keys) {
|
|
3284
|
+
t = t[k] = x;
|
|
3285
|
+
} else if (keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")) {
|
|
3286
|
+
t[k] = {};
|
|
3287
|
+
t = t[k];
|
|
3288
|
+
} else {
|
|
3289
|
+
t[k] = [];
|
|
3290
|
+
t = t[k];
|
|
3291
|
+
}
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
}
|
|
3295
|
+
|
|
3296
|
+
var mkUntrackedValue = function mkUntrackedValue(o) {
|
|
3297
|
+
return typeof o === "object" ? valtio.ref(o) : o;
|
|
3298
|
+
};
|
|
3299
|
+
|
|
3300
|
+
var transformPathStringToObj = function transformPathStringToObj(str) {
|
|
3301
|
+
var splitStatePathPart = function splitStatePathPart(state) {
|
|
3302
|
+
return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
|
|
3303
|
+
};
|
|
3234
3304
|
|
|
3235
|
-
|
|
3305
|
+
return str.split(".").flatMap(splitStatePathPart);
|
|
3306
|
+
};
|
|
3236
3307
|
|
|
3237
3308
|
function shallowEqual(a1, a2) {
|
|
3238
3309
|
if (a1.length !== a2.length) {
|
|
@@ -3248,145 +3319,144 @@ function shallowEqual(a1, a2) {
|
|
|
3248
3319
|
return true;
|
|
3249
3320
|
}
|
|
3250
3321
|
|
|
3251
|
-
|
|
3322
|
+
function isNum(value) {
|
|
3252
3323
|
return typeof value === "symbol" ? false : !isNaN(+value);
|
|
3253
|
-
}
|
|
3324
|
+
}
|
|
3254
3325
|
|
|
3255
|
-
function
|
|
3256
|
-
var
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3326
|
+
function saveNewState($$state, path, spec) {
|
|
3327
|
+
var key = JSON.stringify(path);
|
|
3328
|
+
$$state.existingStates.set(key, {
|
|
3329
|
+
path: path,
|
|
3330
|
+
specKey: spec.path
|
|
3331
|
+
});
|
|
3332
|
+
|
|
3333
|
+
if (!$$state.statesInstanceBySpec.has(spec.path)) {
|
|
3334
|
+
$$state.statesInstanceBySpec.set(spec.path, []);
|
|
3335
|
+
}
|
|
3336
|
+
|
|
3337
|
+
$$state.statesInstanceBySpec.get(spec.path).push({
|
|
3338
|
+
path: path,
|
|
3339
|
+
specKey: spec.path
|
|
3340
|
+
});
|
|
3341
|
+
}
|
|
3266
3342
|
|
|
3267
|
-
|
|
3268
|
-
|
|
3343
|
+
function create$StateProxy($$state, handlers) {
|
|
3344
|
+
var getNextKeyToSpecMap = function getNextKeyToSpecMap(currPath) {
|
|
3345
|
+
return new Map(Object.entries(Object.values($$state.specsByKey).filter(function (spec) {
|
|
3269
3346
|
return shallowEqual(currPath.map(function (p) {
|
|
3270
3347
|
return isNum(p) ? "[]" : p;
|
|
3271
|
-
}), spec.
|
|
3272
|
-
}).
|
|
3273
|
-
var
|
|
3274
|
-
|
|
3275
|
-
if (
|
|
3276
|
-
|
|
3277
|
-
isLast: true,
|
|
3278
|
-
specKey: spec.pathStr
|
|
3279
|
-
}];
|
|
3280
|
-
} else {
|
|
3281
|
-
return [nextPart, {
|
|
3282
|
-
isLast: false,
|
|
3283
|
-
specKey: spec.pathStr
|
|
3284
|
-
}];
|
|
3348
|
+
}), spec.pathObj.slice(0, currPath.length));
|
|
3349
|
+
}).reduce(function (agg, spec) {
|
|
3350
|
+
var nextKey = spec.pathObj[currPath.length];
|
|
3351
|
+
|
|
3352
|
+
if (!(nextKey in agg)) {
|
|
3353
|
+
agg[nextKey] = [];
|
|
3285
3354
|
}
|
|
3286
|
-
}));
|
|
3287
|
-
};
|
|
3288
|
-
/**
|
|
3289
|
-
* We use this function when we're setting a value in the middle of the state path.
|
|
3290
|
-
* We can't just set the value, because we need to keep the proxy properties, so
|
|
3291
|
-
* we use the specs to walk through the object and just set the value in the end of the path
|
|
3292
|
-
**/
|
|
3293
3355
|
|
|
3356
|
+
agg[nextKey].push(spec);
|
|
3357
|
+
return agg;
|
|
3358
|
+
}, {})));
|
|
3359
|
+
};
|
|
3294
3360
|
|
|
3295
|
-
var
|
|
3296
|
-
|
|
3297
|
-
return;
|
|
3298
|
-
}
|
|
3361
|
+
var rec = function rec(currPath) {
|
|
3362
|
+
var nextKeyToSpecs = getNextKeyToSpecMap(currPath);
|
|
3299
3363
|
|
|
3300
|
-
var
|
|
3364
|
+
var getSpecForProperty = function getSpecForProperty(property) {
|
|
3365
|
+
var _nextKeyToSpecs$get, _nextKeyToSpecs$get2;
|
|
3301
3366
|
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
nextPart = _Object$entries$_i[0],
|
|
3305
|
-
_Object$entries$_i$ = _Object$entries$_i[1],
|
|
3306
|
-
isLast = _Object$entries$_i$.isLast,
|
|
3307
|
-
specKey = _Object$entries$_i$.specKey;
|
|
3367
|
+
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;
|
|
3368
|
+
};
|
|
3308
3369
|
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
}
|
|
3313
|
-
} else if (nextPart in value) {
|
|
3314
|
-
if (isLast) {
|
|
3315
|
-
var _handlers$set, _handlers;
|
|
3316
|
-
|
|
3317
|
-
handlers == null ? void 0 : (_handlers$set = (_handlers = handlers({
|
|
3318
|
-
specKey: specKey,
|
|
3319
|
-
path: [].concat(currPath, [nextPart])
|
|
3320
|
-
})).set) == null ? void 0 : _handlers$set.call(_handlers, target, nextPart, value[nextPart], undefined);
|
|
3321
|
-
} else {
|
|
3322
|
-
cloneValue(target[nextPart], [].concat(currPath, [nextPart]), value[nextPart]);
|
|
3323
|
-
}
|
|
3324
|
-
}
|
|
3325
|
-
}
|
|
3326
|
-
};
|
|
3370
|
+
var getNextPath = function getNextPath(property) {
|
|
3371
|
+
return [].concat(currPath, [isNum(property) ? +property : property]);
|
|
3372
|
+
};
|
|
3327
3373
|
|
|
3328
|
-
|
|
3329
|
-
var nextParts = getNextParts(currPath);
|
|
3330
|
-
return new Proxy("[]" in nextParts ? [] : {}, {
|
|
3374
|
+
return new Proxy(nextKeyToSpecs.has("[]") ? [] : {}, {
|
|
3331
3375
|
deleteProperty: function deleteProperty(target, property) {
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
}
|
|
3376
|
+
var prefixPath = getNextPath(property);
|
|
3377
|
+
var specKeysToUpdate = new Set();
|
|
3378
|
+
$$state.existingStates.forEach(function (_ref) {
|
|
3379
|
+
var path = _ref.path,
|
|
3380
|
+
specKey = _ref.specKey;
|
|
3381
|
+
|
|
3382
|
+
if (path.length >= prefixPath.length && shallowEqual(path.slice(0, prefixPath.length), prefixPath)) {
|
|
3383
|
+
deleteState($$state, path);
|
|
3384
|
+
specKeysToUpdate.add(specKey);
|
|
3385
|
+
}
|
|
3386
|
+
});
|
|
3387
|
+
specKeysToUpdate.forEach(function (specKey) {
|
|
3388
|
+
var spec = $$state.specsByKey[specKey];
|
|
3343
3389
|
|
|
3344
|
-
|
|
3390
|
+
if (spec.onChangeProp) {
|
|
3391
|
+
var _$$state$props$spec$o, _$$state$props;
|
|
3392
|
+
|
|
3393
|
+
(_$$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);
|
|
3394
|
+
}
|
|
3395
|
+
});
|
|
3396
|
+
return Reflect.deleteProperty(target, property);
|
|
3345
3397
|
},
|
|
3346
3398
|
get: function get(target, property, receiver) {
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
if (
|
|
3353
|
-
var _handlers$get,
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
specKey: nextParts[property].specKey
|
|
3358
|
-
})).get) == null ? void 0 : _handlers$get.call(_handlers3, target, property, receiver);
|
|
3399
|
+
var spec = getSpecForProperty(property);
|
|
3400
|
+
|
|
3401
|
+
if (spec && typeof property !== "symbol") {
|
|
3402
|
+
var nextPath = getNextPath(property);
|
|
3403
|
+
|
|
3404
|
+
if (spec.pathObj.length === currPath.length + 1) {
|
|
3405
|
+
var _handlers$get, _handlers;
|
|
3406
|
+
|
|
3407
|
+
// reached the end of the spec
|
|
3408
|
+
target[property] = (_handlers$get = (_handlers = handlers(nextPath, spec)).get) == null ? void 0 : _handlers$get.call(_handlers, target, property, receiver);
|
|
3359
3409
|
} else if (!(property in target)) {
|
|
3360
|
-
target[property] = rec(
|
|
3410
|
+
target[property] = rec(nextPath);
|
|
3361
3411
|
}
|
|
3362
3412
|
}
|
|
3363
3413
|
|
|
3364
|
-
return target
|
|
3414
|
+
return Reflect.get(target, property, receiver);
|
|
3365
3415
|
},
|
|
3366
|
-
set: function set(target, property, value, receiver) {
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
target[property] = value;
|
|
3376
|
-
return (
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3416
|
+
set: function set$1(target, property, value, receiver) {
|
|
3417
|
+
var spec = getSpecForProperty(property);
|
|
3418
|
+
var nextPath = getNextPath(property);
|
|
3419
|
+
|
|
3420
|
+
if (spec && typeof property !== "symbol") {
|
|
3421
|
+
if (spec.pathObj.length === currPath.length + 1) {
|
|
3422
|
+
var _handlers$set, _handlers2;
|
|
3423
|
+
|
|
3424
|
+
// reached the end of the spec
|
|
3425
|
+
target[property] = (_handlers$set = (_handlers2 = handlers(nextPath, spec)).set) == null ? void 0 : _handlers$set.call(_handlers2, target, property, value, receiver);
|
|
3426
|
+
return Reflect.set(target, property, value, receiver);
|
|
3427
|
+
} else if (typeof value === "object") {
|
|
3428
|
+
target[property] = rec(nextPath);
|
|
3429
|
+
|
|
3430
|
+
for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
|
|
3431
|
+
var key = _Object$keys[_i];
|
|
3432
|
+
target[property][key] = value[key];
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3435
|
+
return true;
|
|
3380
3436
|
}
|
|
3381
3437
|
}
|
|
3382
3438
|
|
|
3383
|
-
if (property === "registerInitFunc") {
|
|
3384
|
-
target
|
|
3385
|
-
} else if (typeof value === "object") {
|
|
3386
|
-
cloneValue(target[property], [].concat(currPath, [isNum(property) ? +property : property]), value);
|
|
3439
|
+
if (property === "registerInitFunc" && currPath.length === 0) {
|
|
3440
|
+
return Reflect.set(target, property, value, receiver);
|
|
3387
3441
|
}
|
|
3388
3442
|
|
|
3389
|
-
|
|
3443
|
+
if (nextKeyToSpecs.has("[]")) {
|
|
3444
|
+
var _nextKeyToSpecs$get3;
|
|
3445
|
+
|
|
3446
|
+
set($$state.stateValues, nextPath, value);
|
|
3447
|
+
|
|
3448
|
+
(_nextKeyToSpecs$get3 = nextKeyToSpecs.get("[]")) == null ? void 0 : _nextKeyToSpecs$get3.forEach(function (spec) {
|
|
3449
|
+
if (spec != null && spec.onChangeProp) {
|
|
3450
|
+
var _$$state$props$spec$o2, _$$state$props2;
|
|
3451
|
+
|
|
3452
|
+
(_$$state$props$spec$o2 = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props2, value, nextPath);
|
|
3453
|
+
}
|
|
3454
|
+
});
|
|
3455
|
+
return Reflect.set(target, property, value, receiver);
|
|
3456
|
+
} // invalid setting a value that doesn't make part of the spec
|
|
3457
|
+
|
|
3458
|
+
|
|
3459
|
+
return false;
|
|
3390
3460
|
}
|
|
3391
3461
|
});
|
|
3392
3462
|
};
|
|
@@ -3394,136 +3464,136 @@ function mkProxy(specs, maybeHandlers) {
|
|
|
3394
3464
|
return rec([]);
|
|
3395
3465
|
}
|
|
3396
3466
|
|
|
3397
|
-
function
|
|
3398
|
-
var
|
|
3399
|
-
Object.values(states).forEach(function (_ref) {
|
|
3400
|
-
var path = _ref.path;
|
|
3467
|
+
var deleteState = function deleteState($$state, path) {
|
|
3468
|
+
var _$$state$unsubscripti;
|
|
3401
3469
|
|
|
3402
|
-
|
|
3470
|
+
var key = JSON.stringify(path);
|
|
3471
|
+
(_$$state$unsubscripti = $$state.unsubscriptionsByState[key]) == null ? void 0 : _$$state$unsubscripti.forEach(function (f) {
|
|
3472
|
+
return f();
|
|
3403
3473
|
});
|
|
3404
|
-
|
|
3405
|
-
|
|
3474
|
+
delete $$state.unsubscriptionsByState[key];
|
|
3475
|
+
$$state.existingStates["delete"](key); // delete get($$state.stateValues, path.slice(-1))[path.slice(-1)[0]];
|
|
3476
|
+
// delete get($$state.initStateValues, path.slice(-1))[path.slice(-1)[0]];
|
|
3477
|
+
};
|
|
3406
3478
|
|
|
3407
|
-
function
|
|
3408
|
-
|
|
3409
|
-
}
|
|
3479
|
+
var getIndexes = function getIndexes(path, spec) {
|
|
3480
|
+
var indexes = [];
|
|
3410
3481
|
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
}
|
|
3482
|
+
if (path.length !== spec.pathObj.length) {
|
|
3483
|
+
throw new Error("Unexpected error: state path and spec path have different lengths");
|
|
3484
|
+
}
|
|
3414
3485
|
|
|
3415
|
-
var
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
}
|
|
3486
|
+
for (var i = 0; i < spec.pathObj.length; i++) {
|
|
3487
|
+
if (spec.pathObj[i] === "[]") {
|
|
3488
|
+
indexes.push(path[i]);
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3420
3491
|
|
|
3421
|
-
return
|
|
3492
|
+
return indexes;
|
|
3422
3493
|
};
|
|
3423
3494
|
|
|
3424
|
-
function
|
|
3425
|
-
var
|
|
3426
|
-
var $$state = React__default.useMemo(function () {
|
|
3427
|
-
var specs = Object.fromEntries(_specs.map(function (_ref2) {
|
|
3428
|
-
var pathStr = _ref2.path,
|
|
3429
|
-
spec = _objectWithoutPropertiesLoose(_ref2, ["path"]);
|
|
3430
|
-
|
|
3431
|
-
return [pathStr, _extends({}, spec, {
|
|
3432
|
-
pathStr: pathStr,
|
|
3433
|
-
path: transformPathStringToObj(pathStr),
|
|
3434
|
-
isRepeated: pathStr.split(".").some(function (part) {
|
|
3435
|
-
return part.endsWith("[]");
|
|
3436
|
-
})
|
|
3437
|
-
})];
|
|
3438
|
-
}));
|
|
3439
|
-
return {
|
|
3440
|
-
stateValues: mkProxy(specs),
|
|
3441
|
-
initStateDeps: {},
|
|
3442
|
-
initStateValues: mkProxy(specs),
|
|
3443
|
-
states: {},
|
|
3444
|
-
specs: specs
|
|
3445
|
-
};
|
|
3446
|
-
}, []);
|
|
3447
|
-
var $state = Object.assign(mkProxy($$state.specs, function (state) {
|
|
3448
|
-
return {
|
|
3449
|
-
deleteProperty: function deleteProperty(_target, _property) {
|
|
3450
|
-
var prefixPath = state.path;
|
|
3451
|
-
|
|
3452
|
-
for (var _i2 = 0, _Object$entries2 = Object.entries($$state.states); _i2 < _Object$entries2.length; _i2++) {
|
|
3453
|
-
var _Object$entries2$_i = _Object$entries2[_i2],
|
|
3454
|
-
key = _Object$entries2$_i[0],
|
|
3455
|
-
existingState = _Object$entries2$_i[1];
|
|
3495
|
+
function initializeStateValue($$state, initialStatePath, initialSpec) {
|
|
3496
|
+
var _$$state$unsubscripti2;
|
|
3456
3497
|
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3498
|
+
var initialStateKey = JSON.stringify(initialStatePath);
|
|
3499
|
+
var stateAccess = new Set();
|
|
3500
|
+
var $state = create$StateProxy($$state, function (path, spec) {
|
|
3501
|
+
return {
|
|
3502
|
+
get: function get() {
|
|
3503
|
+
var key = JSON.stringify(path);
|
|
3504
|
+
stateAccess.add({
|
|
3505
|
+
path: path,
|
|
3506
|
+
spec: spec
|
|
3464
3507
|
});
|
|
3465
|
-
return true;
|
|
3466
|
-
},
|
|
3467
|
-
get: function get(_target, _property) {
|
|
3468
|
-
var spec = $$state.specs[state.specKey];
|
|
3469
3508
|
|
|
3470
3509
|
if (spec.valueProp) {
|
|
3471
|
-
|
|
3472
|
-
return props[spec.valueProp];
|
|
3473
|
-
} else {
|
|
3474
|
-
return _get(props[spec.valueProp], state.path.slice(1));
|
|
3475
|
-
}
|
|
3510
|
+
return !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
|
|
3476
3511
|
}
|
|
3477
3512
|
|
|
3478
|
-
if (
|
|
3479
|
-
|
|
3513
|
+
if ($$state.existingStates.has(key)) {
|
|
3514
|
+
// is already initialized
|
|
3515
|
+
return _get($$state.stateValues, path);
|
|
3516
|
+
} else if (spec.initFunc) {
|
|
3517
|
+
initializeStateValue($$state, path, spec);
|
|
3518
|
+
}
|
|
3480
3519
|
|
|
3481
|
-
|
|
3520
|
+
return _get($$state.stateValues, path);
|
|
3521
|
+
},
|
|
3522
|
+
set: function set() {
|
|
3523
|
+
throw new Error("Cannot update state values during initialization");
|
|
3524
|
+
}
|
|
3525
|
+
};
|
|
3526
|
+
});
|
|
3527
|
+
(_$$state$unsubscripti2 = $$state.unsubscriptionsByState[initialStateKey]) == null ? void 0 : _$$state$unsubscripti2.forEach(function (f) {
|
|
3528
|
+
return f();
|
|
3529
|
+
});
|
|
3530
|
+
$$state.unsubscriptionsByState[initialStateKey] = [];
|
|
3531
|
+
stateAccess.forEach(function (_ref2) {
|
|
3532
|
+
var path = _ref2.path,
|
|
3533
|
+
spec = _ref2.spec;
|
|
3534
|
+
var unsubscribe = utils.subscribeKey(_get($$state.stateValues, path.slice(-1)), path.slice(-1)[0], function () {
|
|
3535
|
+
return set($$state.stateValues, initialStatePath, mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(path, spec))));
|
|
3536
|
+
});
|
|
3537
|
+
$$state.unsubscriptionsByState[initialStateKey].push(unsubscribe);
|
|
3538
|
+
});
|
|
3539
|
+
var untrackedInitialValue = mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(initialStatePath, initialSpec)));
|
|
3482
3540
|
|
|
3483
|
-
|
|
3541
|
+
set($$state.initStateValues, initialStatePath, untrackedInitialValue);
|
|
3484
3542
|
|
|
3485
|
-
|
|
3543
|
+
set($$state.stateValues, initialStatePath, untrackedInitialValue);
|
|
3486
3544
|
|
|
3487
|
-
|
|
3545
|
+
return untrackedInitialValue;
|
|
3546
|
+
}
|
|
3488
3547
|
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3548
|
+
function useDollarState(specs, props) {
|
|
3549
|
+
var $$state = React__default.useRef(valtio.proxy({
|
|
3550
|
+
stateValues: {},
|
|
3551
|
+
initStateValues: {},
|
|
3552
|
+
specsByKey: Object.fromEntries(specs.map(function (spec) {
|
|
3553
|
+
return [spec.path, _extends({}, spec, {
|
|
3554
|
+
pathObj: transformPathStringToObj(spec.path),
|
|
3555
|
+
isRepeated: spec.path.split(".").some(function (part) {
|
|
3556
|
+
return part.endsWith("[]");
|
|
3557
|
+
})
|
|
3558
|
+
})];
|
|
3559
|
+
})),
|
|
3560
|
+
statesInstanceBySpec: new Map(),
|
|
3561
|
+
existingStates: new Map(),
|
|
3562
|
+
unsubscriptionsByState: {},
|
|
3563
|
+
props: undefined,
|
|
3564
|
+
registrationsQueue: []
|
|
3565
|
+
})).current;
|
|
3566
|
+
$$state.props = mkUntrackedValue(props);
|
|
3567
|
+
var $state = React__default.useRef(Object.assign(create$StateProxy($$state, function (path, spec) {
|
|
3568
|
+
var key = JSON.stringify(path);
|
|
3495
3569
|
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
set: function set(_target, _property, newValue) {
|
|
3499
|
-
if (newValue !== _get($$state.stateValues, state.path)) {
|
|
3500
|
-
saveState(state, $$state.states);
|
|
3570
|
+
if (!$$state.existingStates.has(key)) {
|
|
3571
|
+
var _spec$initVal;
|
|
3501
3572
|
|
|
3502
|
-
|
|
3573
|
+
saveNewState($$state, path, spec);
|
|
3574
|
+
var untrackedValue = !spec.initFunc ? mkUntrackedValue((_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined) : initializeStateValue($$state, path, spec);
|
|
3503
3575
|
|
|
3504
|
-
|
|
3505
|
-
var _Object$entries3$_i = _Object$entries3[_i3],
|
|
3506
|
-
key = _Object$entries3$_i[0],
|
|
3507
|
-
deps = _Object$entries3$_i[1];
|
|
3576
|
+
set($$state.stateValues, path, untrackedValue);
|
|
3508
3577
|
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
}
|
|
3512
|
-
}
|
|
3578
|
+
set($$state.initStateValues, path, untrackedValue);
|
|
3579
|
+
}
|
|
3513
3580
|
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3581
|
+
return {
|
|
3582
|
+
get: function get() {
|
|
3583
|
+
if (spec.valueProp) {
|
|
3584
|
+
var value = !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
|
|
3585
|
+
return value;
|
|
3586
|
+
} else {
|
|
3587
|
+
return _get($$state.stateValues, path);
|
|
3519
3588
|
}
|
|
3520
|
-
|
|
3521
|
-
|
|
3589
|
+
},
|
|
3590
|
+
set: function set$1(_t, _p, value) {
|
|
3591
|
+
set($$state.stateValues, path, mkUntrackedValue(value));
|
|
3522
3592
|
|
|
3523
3593
|
if (spec.onChangeProp) {
|
|
3524
|
-
var
|
|
3594
|
+
var _$$state$props$spec$o3, _$$state$props3;
|
|
3525
3595
|
|
|
3526
|
-
(
|
|
3596
|
+
(_$$state$props$spec$o3 = (_$$state$props3 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o3.call(_$$state$props3, value, path);
|
|
3527
3597
|
}
|
|
3528
3598
|
|
|
3529
3599
|
return true;
|
|
@@ -3531,159 +3601,131 @@ function useVanillaDollarState(_specs, props) {
|
|
|
3531
3601
|
};
|
|
3532
3602
|
}), {
|
|
3533
3603
|
registerInitFunc: function registerInitFunc(pathStr, f) {
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
return _get($$state.
|
|
3604
|
+
var _$$state$statesInstan;
|
|
3605
|
+
|
|
3606
|
+
if ((_$$state$statesInstan = $$state.statesInstanceBySpec.get(pathStr)) != null && _$$state$statesInstan.some(function (_ref3) {
|
|
3607
|
+
var path = _ref3.path,
|
|
3608
|
+
specKey = _ref3.specKey;
|
|
3609
|
+
return !deepEqual(_get($$state.initStateValues, path), f(props, $state, getIndexes(path, $$state.specsByKey[specKey])));
|
|
3540
3610
|
})) {
|
|
3541
|
-
$$state.
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
forceRender(function (r) {
|
|
3545
|
-
return r + 1;
|
|
3611
|
+
$$state.registrationsQueue.push({
|
|
3612
|
+
pathStr: pathStr,
|
|
3613
|
+
f: f
|
|
3546
3614
|
});
|
|
3547
3615
|
}
|
|
3548
3616
|
}
|
|
3549
|
-
}); // For each spec with an initFunc, evaluate it and see if
|
|
3617
|
+
})).current; // For each spec with an initFunc, evaluate it and see if
|
|
3550
3618
|
// the init value has changed. If so, reset its state.
|
|
3551
3619
|
|
|
3552
|
-
var newStateValues = undefined;
|
|
3553
3620
|
var resetSpecs = [];
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
specKey = _Object$values$_i.specKey;
|
|
3559
|
-
var spec = $$state.specs[specKey];
|
|
3621
|
+
$$state.existingStates.forEach(function (_ref4) {
|
|
3622
|
+
var path = _ref4.path,
|
|
3623
|
+
specKey = _ref4.specKey;
|
|
3624
|
+
var spec = $$state.specsByKey[specKey];
|
|
3560
3625
|
|
|
3561
3626
|
if (spec.initFunc) {
|
|
3562
|
-
var newInit = spec.initFunc(props, $state);
|
|
3627
|
+
var newInit = spec.initFunc(props, $state, getIndexes(path, spec));
|
|
3563
3628
|
|
|
3564
|
-
if (newInit
|
|
3565
|
-
console.log("init changed for " + JSON.stringify(path) + " from " + _get($$state.initStateValues, path) + " to " + newInit + "; resetting state");
|
|
3629
|
+
if (!deepEqual(newInit, _get($$state.initStateValues, path))) {
|
|
3566
3630
|
resetSpecs.push({
|
|
3567
3631
|
path: path,
|
|
3568
|
-
|
|
3632
|
+
spec: spec
|
|
3569
3633
|
});
|
|
3570
|
-
|
|
3571
|
-
if (!newStateValues) {
|
|
3572
|
-
newStateValues = cloneProxy($$state.specs, $$state.states, $$state.stateValues);
|
|
3573
|
-
}
|
|
3574
|
-
|
|
3575
|
-
dset.dset(newStateValues, path, UNINITIALIZED);
|
|
3576
3634
|
}
|
|
3577
3635
|
}
|
|
3578
|
-
}
|
|
3579
|
-
|
|
3636
|
+
});
|
|
3580
3637
|
React__default.useLayoutEffect(function () {
|
|
3581
|
-
|
|
3582
|
-
var
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
var path = _ref5.path;
|
|
3586
|
-
|
|
3587
|
-
dset.dset(initStateValues, path, _get(newStateValues, path));
|
|
3588
|
-
});
|
|
3589
|
-
$$state.stateValues = cloneProxy($$state.specs, $$state.states, newStateValues);
|
|
3590
|
-
$$state.initStateValues = initStateValues;
|
|
3591
|
-
$$state.initStateDeps = _extends({}, $$state.initStateDeps, newDeps);
|
|
3592
|
-
forceRender(function (r) {
|
|
3593
|
-
return r + 1;
|
|
3594
|
-
});
|
|
3595
|
-
|
|
3596
|
-
for (var _iterator = _createForOfIteratorHelperLoose(resetSpecs), _step; !(_step = _iterator()).done;) {
|
|
3597
|
-
var _step$value = _step.value,
|
|
3598
|
-
_path = _step$value.path,
|
|
3599
|
-
_specKey = _step$value.specKey;
|
|
3600
|
-
var _spec = $$state.specs[_specKey];
|
|
3638
|
+
resetSpecs.forEach(function (_ref5) {
|
|
3639
|
+
var path = _ref5.path,
|
|
3640
|
+
spec = _ref5.spec;
|
|
3641
|
+
var newInit = initializeStateValue($$state, path, spec);
|
|
3601
3642
|
|
|
3602
|
-
|
|
3603
|
-
|
|
3643
|
+
if (spec.onChangeProp) {
|
|
3644
|
+
var _$$state$props$spec$o4, _$$state$props4;
|
|
3604
3645
|
|
|
3605
|
-
|
|
3606
|
-
(_props$_spec$onChange = props[_spec.onChangeProp]) == null ? void 0 : _props$_spec$onChange.call(props, _get(newStateValues, _path));
|
|
3607
|
-
}
|
|
3646
|
+
(_$$state$props$spec$o4 = (_$$state$props4 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o4.call(_$$state$props4, newInit, path);
|
|
3608
3647
|
}
|
|
3609
|
-
}
|
|
3610
|
-
}, [
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
for (var _i5 = 0, _Object$values2 = Object.values($$state.states); _i5 < _Object$values2.length; _i5++) {
|
|
3621
|
-
var _path2 = _Object$values2[_i5].path;
|
|
3622
|
-
|
|
3623
|
-
_get($state, _path2);
|
|
3624
|
-
}
|
|
3648
|
+
});
|
|
3649
|
+
}, [props, resetSpecs]);
|
|
3650
|
+
React__default.useLayoutEffect(function () {
|
|
3651
|
+
$$state.registrationsQueue.forEach(function (_ref6) {
|
|
3652
|
+
var f = _ref6.f,
|
|
3653
|
+
pathStr = _ref6.pathStr;
|
|
3654
|
+
$$state.specsByKey[pathStr].initFunc = f;
|
|
3655
|
+
});
|
|
3656
|
+
$$state.registrationsQueue = [];
|
|
3657
|
+
}, [$$state.registrationsQueue]); // Re-render if any value changed in one of these objects
|
|
3625
3658
|
|
|
3659
|
+
valtio.useSnapshot($$state.stateValues, {
|
|
3660
|
+
sync: true
|
|
3661
|
+
});
|
|
3662
|
+
valtio.useSnapshot($$state.specsByKey, {
|
|
3663
|
+
sync: true
|
|
3664
|
+
});
|
|
3626
3665
|
return $state;
|
|
3627
3666
|
}
|
|
3628
3667
|
|
|
3629
|
-
function
|
|
3630
|
-
var
|
|
3631
|
-
|
|
3632
|
-
|
|
3668
|
+
function useCanvasDollarState(specs, props) {
|
|
3669
|
+
var $$state = valtio.proxy({
|
|
3670
|
+
stateValues: {},
|
|
3671
|
+
initStateValues: {},
|
|
3672
|
+
specsByKey: Object.fromEntries(specs.map(function (spec) {
|
|
3673
|
+
return [spec.path, _extends({}, spec, {
|
|
3674
|
+
pathObj: transformPathStringToObj(spec.path),
|
|
3675
|
+
isRepeated: spec.path.split(".").some(function (part) {
|
|
3676
|
+
return part.endsWith("[]");
|
|
3677
|
+
})
|
|
3678
|
+
})];
|
|
3679
|
+
})),
|
|
3680
|
+
statesInstanceBySpec: new Map(),
|
|
3681
|
+
existingStates: new Map(),
|
|
3682
|
+
unsubscriptionsByState: {},
|
|
3683
|
+
props: undefined,
|
|
3684
|
+
registrationsQueue: []
|
|
3685
|
+
});
|
|
3686
|
+
$$state.props = mkUntrackedValue(props);
|
|
3687
|
+
var $state = create$StateProxy($$state, function (path, spec) {
|
|
3633
3688
|
return {
|
|
3634
|
-
get: function get(
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
return props[spec.valueProp];
|
|
3640
|
-
} else {
|
|
3641
|
-
return _get(props[spec.valueProp], state.path.slice(1));
|
|
3642
|
-
}
|
|
3643
|
-
}
|
|
3644
|
-
|
|
3645
|
-
var value = _get(stateValues, state.path);
|
|
3646
|
-
|
|
3647
|
-
if (value === UNINITIALIZED) {
|
|
3648
|
-
// This value has a init expression; need to be evaluated.
|
|
3649
|
-
value = tracked(state);
|
|
3689
|
+
get: function get() {
|
|
3690
|
+
return _get($$state.stateValues, path);
|
|
3691
|
+
},
|
|
3692
|
+
set: function set$1(_t, _p, value) {
|
|
3693
|
+
set($$state.stateValues, path, mkUntrackedValue(value));
|
|
3650
3694
|
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
// trackInit() to know what fields were used to compute
|
|
3654
|
-
// the init value
|
|
3695
|
+
if (spec.onChangeProp) {
|
|
3696
|
+
var _$$state$props$spec$o5, _$$state$props5;
|
|
3655
3697
|
|
|
3698
|
+
(_$$state$props$spec$o5 = (_$$state$props5 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o5.call(_$$state$props5, value, path);
|
|
3699
|
+
}
|
|
3656
3700
|
|
|
3657
|
-
|
|
3658
|
-
return value;
|
|
3659
|
-
},
|
|
3660
|
-
set: function set() {
|
|
3661
|
-
throw new Error("Cannot update state values during initialization");
|
|
3701
|
+
return true;
|
|
3662
3702
|
}
|
|
3663
3703
|
};
|
|
3664
|
-
}), {
|
|
3665
|
-
registerInitFunc: function registerInitFunc() {}
|
|
3666
3704
|
});
|
|
3667
3705
|
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
var
|
|
3671
|
-
var
|
|
3672
|
-
initFuncDeps[JSON.stringify(state.path)] = [].concat(deps.values());
|
|
3673
|
-
return res;
|
|
3674
|
-
}
|
|
3675
|
-
|
|
3676
|
-
for (var _i6 = 0, _Object$values3 = Object.values(states); _i6 < _Object$values3.length; _i6++) {
|
|
3677
|
-
var path = _Object$values3[_i6].path;
|
|
3706
|
+
for (var _iterator = _createForOfIteratorHelperLoose(specs), _step; !(_step = _iterator()).done;) {
|
|
3707
|
+
var spec = _step.value;
|
|
3708
|
+
var path = transformPathStringToObj(spec.path);
|
|
3709
|
+
var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initVal ? spec.initVal : spec.initFunc ? initializeStateValue($$state, path, $$state.specsByKey[spec.path]) : undefined;
|
|
3678
3710
|
|
|
3679
|
-
|
|
3680
|
-
_get($state, path);
|
|
3681
|
-
}
|
|
3711
|
+
set($state, path, init);
|
|
3682
3712
|
}
|
|
3683
3713
|
|
|
3684
|
-
return
|
|
3714
|
+
return $state;
|
|
3685
3715
|
}
|
|
3686
3716
|
|
|
3717
|
+
Object.defineProperty(exports, 'PlasmicDataSourceContextProvider', {
|
|
3718
|
+
enumerable: true,
|
|
3719
|
+
get: function () {
|
|
3720
|
+
return dataSourcesContext.PlasmicDataSourceContextProvider;
|
|
3721
|
+
}
|
|
3722
|
+
});
|
|
3723
|
+
Object.defineProperty(exports, 'useCurrentUser', {
|
|
3724
|
+
enumerable: true,
|
|
3725
|
+
get: function () {
|
|
3726
|
+
return dataSourcesContext.useCurrentUser;
|
|
3727
|
+
}
|
|
3728
|
+
});
|
|
3687
3729
|
exports.DropdownMenu = DropdownMenu;
|
|
3688
3730
|
exports.PlasmicHead = PlasmicHead;
|
|
3689
3731
|
exports.PlasmicIcon = PlasmicIcon;
|
|
@@ -3706,14 +3748,17 @@ exports.generateStateValueProp = generateStateValueProp;
|
|
|
3706
3748
|
exports.getDataProps = getDataProps;
|
|
3707
3749
|
exports.hasVariant = hasVariant;
|
|
3708
3750
|
exports.makeFragment = makeFragment;
|
|
3751
|
+
exports.mergeVariantsWithStates = mergeVariantsWithStates;
|
|
3709
3752
|
exports.omit = omit;
|
|
3710
3753
|
exports.pick = pick;
|
|
3711
3754
|
exports.plasmicHeadMeta = plasmicHeadMeta;
|
|
3712
3755
|
exports.renderPlasmicSlot = renderPlasmicSlot;
|
|
3756
|
+
exports.set = set;
|
|
3713
3757
|
exports.setPlumeStrictMode = setPlumeStrictMode;
|
|
3714
3758
|
exports.useButton = useButton;
|
|
3759
|
+
exports.useCanvasDollarState = useCanvasDollarState;
|
|
3715
3760
|
exports.useCheckbox = useCheckbox;
|
|
3716
|
-
exports.useDollarState =
|
|
3761
|
+
exports.useDollarState = useDollarState;
|
|
3717
3762
|
exports.useIsSSR = useIsSSR;
|
|
3718
3763
|
exports.useMenu = useMenu;
|
|
3719
3764
|
exports.useMenuButton = useMenuButton;
|