@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
package/dist/react-web.esm.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import classNames$1 from 'classnames';
|
|
2
|
+
import _get from 'dlv';
|
|
2
3
|
import * as React from 'react';
|
|
3
4
|
import React__default, { forwardRef, createElement, Fragment, isValidElement, useContext, createContext, useState, useRef, useMemo, useImperativeHandle, useCallback, cloneElement } from 'react';
|
|
4
5
|
import ReactDOM__default, { createPortal } from 'react-dom';
|
|
6
|
+
import { PlasmicDataSourceContextProvider } from '@plasmicapp/data-sources-context';
|
|
7
|
+
export { PlasmicDataSourceContextProvider, useCurrentUser } from '@plasmicapp/data-sources-context';
|
|
5
8
|
import { SSRProvider, useIsSSR as useIsSSR$1 } from '@react-aria/ssr';
|
|
6
9
|
import { useFocusRing, useFocusable, FocusScope } from '@react-aria/focus';
|
|
7
10
|
import { useCheckbox as useCheckbox$1 } from '@react-aria/checkbox';
|
|
@@ -18,8 +21,9 @@ import { useListBox, useOption, useListBoxSection } from '@react-aria/listbox';
|
|
|
18
21
|
import { useSelectState } from '@react-stately/select';
|
|
19
22
|
import { useSwitch as useSwitch$1 } from '@react-aria/switch';
|
|
20
23
|
import { useOverlay, useOverlayPosition, DismissButton } from '@react-aria/overlays';
|
|
21
|
-
import
|
|
22
|
-
import {
|
|
24
|
+
import deepEqual from 'fast-deep-equal';
|
|
25
|
+
import { proxy, ref, useSnapshot } from 'valtio';
|
|
26
|
+
import { subscribeKey } from 'valtio/utils';
|
|
23
27
|
|
|
24
28
|
function _extends() {
|
|
25
29
|
_extends = Object.assign || function (target) {
|
|
@@ -72,28 +76,24 @@ function _arrayLikeToArray(arr, len) {
|
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
75
|
-
var it;
|
|
79
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
80
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
76
81
|
|
|
77
|
-
if (
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
done: true
|
|
84
|
-
};
|
|
85
|
-
return {
|
|
86
|
-
done: false,
|
|
87
|
-
value: o[i++]
|
|
88
|
-
};
|
|
82
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
83
|
+
if (it) o = it;
|
|
84
|
+
var i = 0;
|
|
85
|
+
return function () {
|
|
86
|
+
if (i >= o.length) return {
|
|
87
|
+
done: true
|
|
89
88
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
return {
|
|
90
|
+
done: false,
|
|
91
|
+
value: o[i++]
|
|
92
|
+
};
|
|
93
|
+
};
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
return it.next.bind(it);
|
|
96
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
function notNil(x) {
|
|
@@ -367,9 +367,13 @@ function getElementTypeName(element) {
|
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
|
|
370
|
+
var _excluded = ["children"],
|
|
371
|
+
_excluded2 = ["as", "hasGap"],
|
|
372
|
+
_excluded3 = ["hasGap"];
|
|
373
|
+
|
|
370
374
|
function renderStack(as, props, hasGap, ref) {
|
|
371
375
|
var children = props.children,
|
|
372
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
376
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
373
377
|
|
|
374
378
|
var wrappedChildren = wrapFlexContainerChildren(children, hasGap != null ? hasGap : false);
|
|
375
379
|
return createElementWithChildren(as, _extends({
|
|
@@ -380,7 +384,7 @@ function renderStack(as, props, hasGap, ref) {
|
|
|
380
384
|
function FlexStack_(props, outerRef) {
|
|
381
385
|
var as = props.as,
|
|
382
386
|
hasGap = props.hasGap,
|
|
383
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
387
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
384
388
|
|
|
385
389
|
return renderStack(as != null ? as : "div", rest, hasGap, outerRef);
|
|
386
390
|
}
|
|
@@ -390,7 +394,7 @@ var FlexStack = /*#__PURE__*/forwardRef(FlexStack_);
|
|
|
390
394
|
var makeStackImpl = function makeStackImpl(as) {
|
|
391
395
|
return forwardRef(function (props, ref) {
|
|
392
396
|
var hasGap = props.hasGap,
|
|
393
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
397
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded3);
|
|
394
398
|
|
|
395
399
|
return renderStack(as, rest, hasGap, ref);
|
|
396
400
|
});
|
|
@@ -685,6 +689,14 @@ function mergeVariants(v1, v2) {
|
|
|
685
689
|
return _extends({}, v1, v2);
|
|
686
690
|
}
|
|
687
691
|
|
|
692
|
+
function mergeVariantsWithStates(variants, $state, linkedStates) {
|
|
693
|
+
return _extends({}, variants, Object.fromEntries(linkedStates.map(function (_ref) {
|
|
694
|
+
var variantGroup = _ref.variantGroup,
|
|
695
|
+
statePath = _ref.statePath;
|
|
696
|
+
return [variantGroup, _get($state, statePath)];
|
|
697
|
+
})));
|
|
698
|
+
}
|
|
699
|
+
|
|
688
700
|
function mergeArgs(a1, a2) {
|
|
689
701
|
if (!a1 || !a2) {
|
|
690
702
|
return a1 || a2 || {};
|
|
@@ -710,7 +722,7 @@ function mergeFlexOverrides(o1, o2) {
|
|
|
710
722
|
}
|
|
711
723
|
|
|
712
724
|
function mergeFlexOverride(fo1, fo2) {
|
|
713
|
-
var _o1$props,
|
|
725
|
+
var _o1$props, _ref2;
|
|
714
726
|
|
|
715
727
|
if (!fo1) {
|
|
716
728
|
return fo2;
|
|
@@ -746,7 +758,7 @@ function mergeFlexOverride(fo1, fo2) {
|
|
|
746
758
|
} // "as" will take precedence
|
|
747
759
|
|
|
748
760
|
|
|
749
|
-
var as = (
|
|
761
|
+
var as = (_ref2 = o2.type === "as" ? o2.as : undefined) != null ? _ref2 : o1.type === "as" ? o1.as : undefined;
|
|
750
762
|
return _extends({
|
|
751
763
|
props: props,
|
|
752
764
|
wrap: wrap,
|
|
@@ -888,13 +900,15 @@ var plasmicHeadMeta = {
|
|
|
888
900
|
}
|
|
889
901
|
};
|
|
890
902
|
|
|
903
|
+
var _excluded$1 = ["PlasmicIconType"];
|
|
891
904
|
function PlasmicIcon(props) {
|
|
892
905
|
var PlasmicIconType = props.PlasmicIconType,
|
|
893
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
906
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$1);
|
|
894
907
|
|
|
895
908
|
return createElement(PlasmicIconType, Object.assign({}, rest));
|
|
896
909
|
}
|
|
897
910
|
|
|
911
|
+
var _excluded$2 = ["src", "className", "displayWidth", "displayHeight", "displayMinWidth", "displayMinHeight", "displayMaxWidth", "displayMaxHeight", "quality", "loader", "imgRef", "style", "loading"];
|
|
898
912
|
// TODO: make this configurable?
|
|
899
913
|
|
|
900
914
|
var IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
|
|
@@ -914,7 +928,7 @@ var PlasmicImg = /*#__PURE__*/React__default.forwardRef(function PlasmicImg(prop
|
|
|
914
928
|
imgRef = props.imgRef,
|
|
915
929
|
style = props.style,
|
|
916
930
|
loading = props.loading,
|
|
917
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
931
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$2);
|
|
918
932
|
|
|
919
933
|
var imgProps = Object.assign({}, rest, {
|
|
920
934
|
// Default loading to "lazy" if not specified (which is different from the
|
|
@@ -1373,6 +1387,7 @@ function hasKey(v, key) {
|
|
|
1373
1387
|
return typeof v === "object" && v !== null && key in v;
|
|
1374
1388
|
}
|
|
1375
1389
|
|
|
1390
|
+
var _excluded$3 = ["as", "defaultContents", "value"];
|
|
1376
1391
|
function PlasmicSlot(props) {
|
|
1377
1392
|
return renderPlasmicSlot(props);
|
|
1378
1393
|
}
|
|
@@ -1380,7 +1395,7 @@ function renderPlasmicSlot(opts) {
|
|
|
1380
1395
|
var as = opts.as,
|
|
1381
1396
|
defaultContents = opts.defaultContents,
|
|
1382
1397
|
value = opts.value,
|
|
1383
|
-
rest = _objectWithoutPropertiesLoose(opts,
|
|
1398
|
+
rest = _objectWithoutPropertiesLoose(opts, _excluded$3);
|
|
1384
1399
|
|
|
1385
1400
|
var content = value === undefined ? defaultContents : value;
|
|
1386
1401
|
|
|
@@ -1531,19 +1546,29 @@ function createUseScreenVariants(isMulti, screenQueries) {
|
|
|
1531
1546
|
var PlasmicRootContext = /*#__PURE__*/createContext(undefined);
|
|
1532
1547
|
function PlasmicRootProvider(props) {
|
|
1533
1548
|
var platform = props.platform,
|
|
1534
|
-
children = props.children
|
|
1549
|
+
children = props.children,
|
|
1550
|
+
userAuthToken = props.userAuthToken,
|
|
1551
|
+
user = props.user;
|
|
1535
1552
|
var context = useMemo(function () {
|
|
1536
1553
|
return {
|
|
1537
1554
|
platform: platform
|
|
1538
1555
|
};
|
|
1539
1556
|
}, [platform]);
|
|
1557
|
+
var dataSourceContextValue = useMemo(function () {
|
|
1558
|
+
return {
|
|
1559
|
+
userAuthToken: userAuthToken,
|
|
1560
|
+
user: user
|
|
1561
|
+
};
|
|
1562
|
+
}, [userAuthToken, user]);
|
|
1540
1563
|
return createElement(PlasmicRootContext.Provider, {
|
|
1541
1564
|
value: context
|
|
1542
|
-
}, createElement(SSRProvider, null, createElement(
|
|
1565
|
+
}, createElement(SSRProvider, null, createElement(PlasmicDataSourceContextProvider, {
|
|
1566
|
+
value: dataSourceContextValue
|
|
1567
|
+
}, createElement(PlasmicTranslatorContext.Provider, {
|
|
1543
1568
|
value: props.translator
|
|
1544
1569
|
}, createElement(PlasmicHeadContext.Provider, {
|
|
1545
1570
|
value: props.Head
|
|
1546
|
-
}, children))));
|
|
1571
|
+
}, children)))));
|
|
1547
1572
|
}
|
|
1548
1573
|
var useIsSSR = useIsSSR$1;
|
|
1549
1574
|
function useHasPlasmicRoot() {
|
|
@@ -1697,6 +1722,7 @@ function getPlumeType(child) {
|
|
|
1697
1722
|
return childType.__plumeType || (childType.getPlumeType == null ? void 0 : childType.getPlumeType(child.props));
|
|
1698
1723
|
}
|
|
1699
1724
|
|
|
1725
|
+
var _excluded$4 = ["link", "isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "children"];
|
|
1700
1726
|
function useButton(plasmicClass, props, config, ref) {
|
|
1701
1727
|
var _ref, _ref2, _extends2, _overrides;
|
|
1702
1728
|
|
|
@@ -1711,7 +1737,7 @@ function useButton(plasmicClass, props, config, ref) {
|
|
|
1711
1737
|
showStartIcon = props.showStartIcon,
|
|
1712
1738
|
showEndIcon = props.showEndIcon,
|
|
1713
1739
|
children = props.children,
|
|
1714
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
1740
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$4);
|
|
1715
1741
|
|
|
1716
1742
|
var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
|
|
1717
1743
|
def: config.showStartIconVariant,
|
|
@@ -2061,6 +2087,7 @@ var TriggeredOverlayContext = /*#__PURE__*/createContext(undefined);
|
|
|
2061
2087
|
|
|
2062
2088
|
var MenuContext = /*#__PURE__*/createContext(undefined);
|
|
2063
2089
|
|
|
2090
|
+
var _excluded$5 = ["children"];
|
|
2064
2091
|
var COLLECTION_OPTS = {
|
|
2065
2092
|
itemPlumeType: "menu-item",
|
|
2066
2093
|
sectionPlumeType: "menu-group"
|
|
@@ -2071,7 +2098,7 @@ var COLLECTION_OPTS = {
|
|
|
2071
2098
|
|
|
2072
2099
|
function asAriaMenuProps(props) {
|
|
2073
2100
|
var children = props.children,
|
|
2074
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
2101
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$5);
|
|
2075
2102
|
|
|
2076
2103
|
var _useDerivedItemsFromC = useDerivedItemsFromChildren(children, _extends({}, COLLECTION_OPTS, {
|
|
2077
2104
|
invalidChildError: "Can only use Menu.Item and Menu.Group as children to Menu",
|
|
@@ -2514,6 +2541,7 @@ function useMenuButton(plasmicClass, props, config, outerRef) {
|
|
|
2514
2541
|
|
|
2515
2542
|
var SelectContext = /*#__PURE__*/createContext(undefined);
|
|
2516
2543
|
|
|
2544
|
+
var _excluded$6 = ["value", "defaultValue", "children", "onChange", "placement", "menuMatchTriggerWidth", "menuWidth"];
|
|
2517
2545
|
var COLLECTION_OPTS$1 = {
|
|
2518
2546
|
itemPlumeType: "select-option",
|
|
2519
2547
|
sectionPlumeType: "select-option-group"
|
|
@@ -2559,7 +2587,7 @@ function useAriaSelectProps(props) {
|
|
|
2559
2587
|
defaultValue = props.defaultValue,
|
|
2560
2588
|
children = props.children,
|
|
2561
2589
|
onChange = props.onChange,
|
|
2562
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
2590
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$6);
|
|
2563
2591
|
|
|
2564
2592
|
var _useDerivedItemsFromC = useDerivedItemsFromChildren(children, _extends({}, COLLECTION_OPTS$1, {
|
|
2565
2593
|
invalidChildError: "Can only use Select.Option and Select.OptionGroup as children to Select",
|
|
@@ -3001,6 +3029,7 @@ function useSwitch(plasmicClass, props, config, ref) {
|
|
|
3001
3029
|
};
|
|
3002
3030
|
}
|
|
3003
3031
|
|
|
3032
|
+
var _excluded$7 = ["isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "className", "style", "inputClassName", "inputStyle"];
|
|
3004
3033
|
function useTextInput(plasmicClass, props, config, ref) {
|
|
3005
3034
|
var _ref, _ref2, _overrides;
|
|
3006
3035
|
|
|
@@ -3017,7 +3046,7 @@ function useTextInput(plasmicClass, props, config, ref) {
|
|
|
3017
3046
|
style = props.style,
|
|
3018
3047
|
inputClassName = props.inputClassName,
|
|
3019
3048
|
inputStyle = props.inputStyle,
|
|
3020
|
-
rest = _objectWithoutPropertiesLoose(props,
|
|
3049
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$7);
|
|
3021
3050
|
|
|
3022
3051
|
var rootRef = useRef(null);
|
|
3023
3052
|
var inputRef = useRef(null);
|
|
@@ -3210,7 +3239,7 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissabl
|
|
|
3210
3239
|
|
|
3211
3240
|
function generateStateOnChangeProp($state, stateName, dataReps) {
|
|
3212
3241
|
return function (val, path) {
|
|
3213
|
-
return
|
|
3242
|
+
return set($state, [stateName].concat(dataReps, path), val);
|
|
3214
3243
|
};
|
|
3215
3244
|
}
|
|
3216
3245
|
/**
|
|
@@ -3224,8 +3253,51 @@ function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
|
|
|
3224
3253
|
) {
|
|
3225
3254
|
return _get($state, path);
|
|
3226
3255
|
}
|
|
3256
|
+
/**
|
|
3257
|
+
* Forked from https://github.com/lukeed/dset
|
|
3258
|
+
* Changes: fixed setting a deep value to a proxy object
|
|
3259
|
+
*/
|
|
3227
3260
|
|
|
3228
|
-
|
|
3261
|
+
function set(obj, keys, val) {
|
|
3262
|
+
keys = keys.split ? keys.split(".") : keys;
|
|
3263
|
+
var i = 0,
|
|
3264
|
+
l = keys.length,
|
|
3265
|
+
t = obj,
|
|
3266
|
+
x,
|
|
3267
|
+
k;
|
|
3268
|
+
|
|
3269
|
+
while (i < l) {
|
|
3270
|
+
k = keys[i++];
|
|
3271
|
+
if (k === "__proto__" || k === "constructor" || k === "prototype") break;
|
|
3272
|
+
|
|
3273
|
+
if (i === l) {
|
|
3274
|
+
t[k] = val;
|
|
3275
|
+
t = t[k];
|
|
3276
|
+
} else {
|
|
3277
|
+
if (typeof (x = t[k]) === typeof keys) {
|
|
3278
|
+
t = t[k] = x;
|
|
3279
|
+
} else if (keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")) {
|
|
3280
|
+
t[k] = {};
|
|
3281
|
+
t = t[k];
|
|
3282
|
+
} else {
|
|
3283
|
+
t[k] = [];
|
|
3284
|
+
t = t[k];
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
|
|
3290
|
+
var mkUntrackedValue = function mkUntrackedValue(o) {
|
|
3291
|
+
return typeof o === "object" ? ref(o) : o;
|
|
3292
|
+
};
|
|
3293
|
+
|
|
3294
|
+
var transformPathStringToObj = function transformPathStringToObj(str) {
|
|
3295
|
+
var splitStatePathPart = function splitStatePathPart(state) {
|
|
3296
|
+
return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
|
|
3297
|
+
};
|
|
3298
|
+
|
|
3299
|
+
return str.split(".").flatMap(splitStatePathPart);
|
|
3300
|
+
};
|
|
3229
3301
|
|
|
3230
3302
|
function shallowEqual(a1, a2) {
|
|
3231
3303
|
if (a1.length !== a2.length) {
|
|
@@ -3241,145 +3313,144 @@ function shallowEqual(a1, a2) {
|
|
|
3241
3313
|
return true;
|
|
3242
3314
|
}
|
|
3243
3315
|
|
|
3244
|
-
|
|
3316
|
+
function isNum(value) {
|
|
3245
3317
|
return typeof value === "symbol" ? false : !isNaN(+value);
|
|
3246
|
-
}
|
|
3318
|
+
}
|
|
3247
3319
|
|
|
3248
|
-
function
|
|
3249
|
-
var
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3320
|
+
function saveNewState($$state, path, spec) {
|
|
3321
|
+
var key = JSON.stringify(path);
|
|
3322
|
+
$$state.existingStates.set(key, {
|
|
3323
|
+
path: path,
|
|
3324
|
+
specKey: spec.path
|
|
3325
|
+
});
|
|
3326
|
+
|
|
3327
|
+
if (!$$state.statesInstanceBySpec.has(spec.path)) {
|
|
3328
|
+
$$state.statesInstanceBySpec.set(spec.path, []);
|
|
3329
|
+
}
|
|
3330
|
+
|
|
3331
|
+
$$state.statesInstanceBySpec.get(spec.path).push({
|
|
3332
|
+
path: path,
|
|
3333
|
+
specKey: spec.path
|
|
3334
|
+
});
|
|
3335
|
+
}
|
|
3259
3336
|
|
|
3260
|
-
|
|
3261
|
-
|
|
3337
|
+
function create$StateProxy($$state, handlers) {
|
|
3338
|
+
var getNextKeyToSpecMap = function getNextKeyToSpecMap(currPath) {
|
|
3339
|
+
return new Map(Object.entries(Object.values($$state.specsByKey).filter(function (spec) {
|
|
3262
3340
|
return shallowEqual(currPath.map(function (p) {
|
|
3263
3341
|
return isNum(p) ? "[]" : p;
|
|
3264
|
-
}), spec.
|
|
3265
|
-
}).
|
|
3266
|
-
var
|
|
3267
|
-
|
|
3268
|
-
if (
|
|
3269
|
-
|
|
3270
|
-
isLast: true,
|
|
3271
|
-
specKey: spec.pathStr
|
|
3272
|
-
}];
|
|
3273
|
-
} else {
|
|
3274
|
-
return [nextPart, {
|
|
3275
|
-
isLast: false,
|
|
3276
|
-
specKey: spec.pathStr
|
|
3277
|
-
}];
|
|
3342
|
+
}), spec.pathObj.slice(0, currPath.length));
|
|
3343
|
+
}).reduce(function (agg, spec) {
|
|
3344
|
+
var nextKey = spec.pathObj[currPath.length];
|
|
3345
|
+
|
|
3346
|
+
if (!(nextKey in agg)) {
|
|
3347
|
+
agg[nextKey] = [];
|
|
3278
3348
|
}
|
|
3279
|
-
}));
|
|
3280
|
-
};
|
|
3281
|
-
/**
|
|
3282
|
-
* We use this function when we're setting a value in the middle of the state path.
|
|
3283
|
-
* We can't just set the value, because we need to keep the proxy properties, so
|
|
3284
|
-
* we use the specs to walk through the object and just set the value in the end of the path
|
|
3285
|
-
**/
|
|
3286
3349
|
|
|
3350
|
+
agg[nextKey].push(spec);
|
|
3351
|
+
return agg;
|
|
3352
|
+
}, {})));
|
|
3353
|
+
};
|
|
3287
3354
|
|
|
3288
|
-
var
|
|
3289
|
-
|
|
3290
|
-
return;
|
|
3291
|
-
}
|
|
3355
|
+
var rec = function rec(currPath) {
|
|
3356
|
+
var nextKeyToSpecs = getNextKeyToSpecMap(currPath);
|
|
3292
3357
|
|
|
3293
|
-
var
|
|
3358
|
+
var getSpecForProperty = function getSpecForProperty(property) {
|
|
3359
|
+
var _nextKeyToSpecs$get, _nextKeyToSpecs$get2;
|
|
3294
3360
|
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
nextPart = _Object$entries$_i[0],
|
|
3298
|
-
_Object$entries$_i$ = _Object$entries$_i[1],
|
|
3299
|
-
isLast = _Object$entries$_i$.isLast,
|
|
3300
|
-
specKey = _Object$entries$_i$.specKey;
|
|
3361
|
+
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;
|
|
3362
|
+
};
|
|
3301
3363
|
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
}
|
|
3306
|
-
} else if (nextPart in value) {
|
|
3307
|
-
if (isLast) {
|
|
3308
|
-
var _handlers$set, _handlers;
|
|
3309
|
-
|
|
3310
|
-
handlers == null ? void 0 : (_handlers$set = (_handlers = handlers({
|
|
3311
|
-
specKey: specKey,
|
|
3312
|
-
path: [].concat(currPath, [nextPart])
|
|
3313
|
-
})).set) == null ? void 0 : _handlers$set.call(_handlers, target, nextPart, value[nextPart], undefined);
|
|
3314
|
-
} else {
|
|
3315
|
-
cloneValue(target[nextPart], [].concat(currPath, [nextPart]), value[nextPart]);
|
|
3316
|
-
}
|
|
3317
|
-
}
|
|
3318
|
-
}
|
|
3319
|
-
};
|
|
3364
|
+
var getNextPath = function getNextPath(property) {
|
|
3365
|
+
return [].concat(currPath, [isNum(property) ? +property : property]);
|
|
3366
|
+
};
|
|
3320
3367
|
|
|
3321
|
-
|
|
3322
|
-
var nextParts = getNextParts(currPath);
|
|
3323
|
-
return new Proxy("[]" in nextParts ? [] : {}, {
|
|
3368
|
+
return new Proxy(nextKeyToSpecs.has("[]") ? [] : {}, {
|
|
3324
3369
|
deleteProperty: function deleteProperty(target, property) {
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
}
|
|
3370
|
+
var prefixPath = getNextPath(property);
|
|
3371
|
+
var specKeysToUpdate = new Set();
|
|
3372
|
+
$$state.existingStates.forEach(function (_ref) {
|
|
3373
|
+
var path = _ref.path,
|
|
3374
|
+
specKey = _ref.specKey;
|
|
3375
|
+
|
|
3376
|
+
if (path.length >= prefixPath.length && shallowEqual(path.slice(0, prefixPath.length), prefixPath)) {
|
|
3377
|
+
deleteState($$state, path);
|
|
3378
|
+
specKeysToUpdate.add(specKey);
|
|
3379
|
+
}
|
|
3380
|
+
});
|
|
3381
|
+
specKeysToUpdate.forEach(function (specKey) {
|
|
3382
|
+
var spec = $$state.specsByKey[specKey];
|
|
3336
3383
|
|
|
3337
|
-
|
|
3384
|
+
if (spec.onChangeProp) {
|
|
3385
|
+
var _$$state$props$spec$o, _$$state$props;
|
|
3386
|
+
|
|
3387
|
+
(_$$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);
|
|
3388
|
+
}
|
|
3389
|
+
});
|
|
3390
|
+
return Reflect.deleteProperty(target, property);
|
|
3338
3391
|
},
|
|
3339
3392
|
get: function get(target, property, receiver) {
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
if (
|
|
3346
|
-
var _handlers$get,
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
specKey: nextParts[property].specKey
|
|
3351
|
-
})).get) == null ? void 0 : _handlers$get.call(_handlers3, target, property, receiver);
|
|
3393
|
+
var spec = getSpecForProperty(property);
|
|
3394
|
+
|
|
3395
|
+
if (spec && typeof property !== "symbol") {
|
|
3396
|
+
var nextPath = getNextPath(property);
|
|
3397
|
+
|
|
3398
|
+
if (spec.pathObj.length === currPath.length + 1) {
|
|
3399
|
+
var _handlers$get, _handlers;
|
|
3400
|
+
|
|
3401
|
+
// reached the end of the spec
|
|
3402
|
+
target[property] = (_handlers$get = (_handlers = handlers(nextPath, spec)).get) == null ? void 0 : _handlers$get.call(_handlers, target, property, receiver);
|
|
3352
3403
|
} else if (!(property in target)) {
|
|
3353
|
-
target[property] = rec(
|
|
3404
|
+
target[property] = rec(nextPath);
|
|
3354
3405
|
}
|
|
3355
3406
|
}
|
|
3356
3407
|
|
|
3357
|
-
return target
|
|
3408
|
+
return Reflect.get(target, property, receiver);
|
|
3358
3409
|
},
|
|
3359
|
-
set: function set(target, property, value, receiver) {
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
target[property] = value;
|
|
3369
|
-
return (
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3410
|
+
set: function set$1(target, property, value, receiver) {
|
|
3411
|
+
var spec = getSpecForProperty(property);
|
|
3412
|
+
var nextPath = getNextPath(property);
|
|
3413
|
+
|
|
3414
|
+
if (spec && typeof property !== "symbol") {
|
|
3415
|
+
if (spec.pathObj.length === currPath.length + 1) {
|
|
3416
|
+
var _handlers$set, _handlers2;
|
|
3417
|
+
|
|
3418
|
+
// reached the end of the spec
|
|
3419
|
+
target[property] = (_handlers$set = (_handlers2 = handlers(nextPath, spec)).set) == null ? void 0 : _handlers$set.call(_handlers2, target, property, value, receiver);
|
|
3420
|
+
return Reflect.set(target, property, value, receiver);
|
|
3421
|
+
} else if (typeof value === "object") {
|
|
3422
|
+
target[property] = rec(nextPath);
|
|
3423
|
+
|
|
3424
|
+
for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
|
|
3425
|
+
var key = _Object$keys[_i];
|
|
3426
|
+
target[property][key] = value[key];
|
|
3427
|
+
}
|
|
3428
|
+
|
|
3429
|
+
return true;
|
|
3373
3430
|
}
|
|
3374
3431
|
}
|
|
3375
3432
|
|
|
3376
|
-
if (property === "registerInitFunc") {
|
|
3377
|
-
target
|
|
3378
|
-
} else if (typeof value === "object") {
|
|
3379
|
-
cloneValue(target[property], [].concat(currPath, [isNum(property) ? +property : property]), value);
|
|
3433
|
+
if (property === "registerInitFunc" && currPath.length === 0) {
|
|
3434
|
+
return Reflect.set(target, property, value, receiver);
|
|
3380
3435
|
}
|
|
3381
3436
|
|
|
3382
|
-
|
|
3437
|
+
if (nextKeyToSpecs.has("[]")) {
|
|
3438
|
+
var _nextKeyToSpecs$get3;
|
|
3439
|
+
|
|
3440
|
+
set($$state.stateValues, nextPath, value);
|
|
3441
|
+
|
|
3442
|
+
(_nextKeyToSpecs$get3 = nextKeyToSpecs.get("[]")) == null ? void 0 : _nextKeyToSpecs$get3.forEach(function (spec) {
|
|
3443
|
+
if (spec != null && spec.onChangeProp) {
|
|
3444
|
+
var _$$state$props$spec$o2, _$$state$props2;
|
|
3445
|
+
|
|
3446
|
+
(_$$state$props$spec$o2 = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props2, value, nextPath);
|
|
3447
|
+
}
|
|
3448
|
+
});
|
|
3449
|
+
return Reflect.set(target, property, value, receiver);
|
|
3450
|
+
} // invalid setting a value that doesn't make part of the spec
|
|
3451
|
+
|
|
3452
|
+
|
|
3453
|
+
return false;
|
|
3383
3454
|
}
|
|
3384
3455
|
});
|
|
3385
3456
|
};
|
|
@@ -3387,136 +3458,136 @@ function mkProxy(specs, maybeHandlers) {
|
|
|
3387
3458
|
return rec([]);
|
|
3388
3459
|
}
|
|
3389
3460
|
|
|
3390
|
-
function
|
|
3391
|
-
var
|
|
3392
|
-
Object.values(states).forEach(function (_ref) {
|
|
3393
|
-
var path = _ref.path;
|
|
3461
|
+
var deleteState = function deleteState($$state, path) {
|
|
3462
|
+
var _$$state$unsubscripti;
|
|
3394
3463
|
|
|
3395
|
-
|
|
3464
|
+
var key = JSON.stringify(path);
|
|
3465
|
+
(_$$state$unsubscripti = $$state.unsubscriptionsByState[key]) == null ? void 0 : _$$state$unsubscripti.forEach(function (f) {
|
|
3466
|
+
return f();
|
|
3396
3467
|
});
|
|
3397
|
-
|
|
3398
|
-
|
|
3468
|
+
delete $$state.unsubscriptionsByState[key];
|
|
3469
|
+
$$state.existingStates["delete"](key); // delete get($$state.stateValues, path.slice(-1))[path.slice(-1)[0]];
|
|
3470
|
+
// delete get($$state.initStateValues, path.slice(-1))[path.slice(-1)[0]];
|
|
3471
|
+
};
|
|
3399
3472
|
|
|
3400
|
-
function
|
|
3401
|
-
|
|
3402
|
-
}
|
|
3473
|
+
var getIndexes = function getIndexes(path, spec) {
|
|
3474
|
+
var indexes = [];
|
|
3403
3475
|
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
}
|
|
3476
|
+
if (path.length !== spec.pathObj.length) {
|
|
3477
|
+
throw new Error("Unexpected error: state path and spec path have different lengths");
|
|
3478
|
+
}
|
|
3407
3479
|
|
|
3408
|
-
var
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
}
|
|
3480
|
+
for (var i = 0; i < spec.pathObj.length; i++) {
|
|
3481
|
+
if (spec.pathObj[i] === "[]") {
|
|
3482
|
+
indexes.push(path[i]);
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3413
3485
|
|
|
3414
|
-
return
|
|
3486
|
+
return indexes;
|
|
3415
3487
|
};
|
|
3416
3488
|
|
|
3417
|
-
function
|
|
3418
|
-
var
|
|
3419
|
-
var $$state = React__default.useMemo(function () {
|
|
3420
|
-
var specs = Object.fromEntries(_specs.map(function (_ref2) {
|
|
3421
|
-
var pathStr = _ref2.path,
|
|
3422
|
-
spec = _objectWithoutPropertiesLoose(_ref2, ["path"]);
|
|
3423
|
-
|
|
3424
|
-
return [pathStr, _extends({}, spec, {
|
|
3425
|
-
pathStr: pathStr,
|
|
3426
|
-
path: transformPathStringToObj(pathStr),
|
|
3427
|
-
isRepeated: pathStr.split(".").some(function (part) {
|
|
3428
|
-
return part.endsWith("[]");
|
|
3429
|
-
})
|
|
3430
|
-
})];
|
|
3431
|
-
}));
|
|
3432
|
-
return {
|
|
3433
|
-
stateValues: mkProxy(specs),
|
|
3434
|
-
initStateDeps: {},
|
|
3435
|
-
initStateValues: mkProxy(specs),
|
|
3436
|
-
states: {},
|
|
3437
|
-
specs: specs
|
|
3438
|
-
};
|
|
3439
|
-
}, []);
|
|
3440
|
-
var $state = Object.assign(mkProxy($$state.specs, function (state) {
|
|
3441
|
-
return {
|
|
3442
|
-
deleteProperty: function deleteProperty(_target, _property) {
|
|
3443
|
-
var prefixPath = state.path;
|
|
3444
|
-
|
|
3445
|
-
for (var _i2 = 0, _Object$entries2 = Object.entries($$state.states); _i2 < _Object$entries2.length; _i2++) {
|
|
3446
|
-
var _Object$entries2$_i = _Object$entries2[_i2],
|
|
3447
|
-
key = _Object$entries2$_i[0],
|
|
3448
|
-
existingState = _Object$entries2$_i[1];
|
|
3449
|
-
|
|
3450
|
-
if (existingState.path.length >= prefixPath.length && shallowEqual(existingState.path.slice(0, prefixPath.length), prefixPath)) {
|
|
3451
|
-
delete $$state.states[key];
|
|
3452
|
-
}
|
|
3453
|
-
}
|
|
3489
|
+
function initializeStateValue($$state, initialStatePath, initialSpec) {
|
|
3490
|
+
var _$$state$unsubscripti2;
|
|
3454
3491
|
|
|
3455
|
-
|
|
3456
|
-
|
|
3492
|
+
var initialStateKey = JSON.stringify(initialStatePath);
|
|
3493
|
+
var stateAccess = new Set();
|
|
3494
|
+
var $state = create$StateProxy($$state, function (path, spec) {
|
|
3495
|
+
return {
|
|
3496
|
+
get: function get() {
|
|
3497
|
+
var key = JSON.stringify(path);
|
|
3498
|
+
stateAccess.add({
|
|
3499
|
+
path: path,
|
|
3500
|
+
spec: spec
|
|
3457
3501
|
});
|
|
3458
|
-
return true;
|
|
3459
|
-
},
|
|
3460
|
-
get: function get(_target, _property) {
|
|
3461
|
-
var spec = $$state.specs[state.specKey];
|
|
3462
3502
|
|
|
3463
3503
|
if (spec.valueProp) {
|
|
3464
|
-
|
|
3465
|
-
return props[spec.valueProp];
|
|
3466
|
-
} else {
|
|
3467
|
-
return _get(props[spec.valueProp], state.path.slice(1));
|
|
3468
|
-
}
|
|
3504
|
+
return !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
|
|
3469
3505
|
}
|
|
3470
3506
|
|
|
3471
|
-
if (
|
|
3472
|
-
|
|
3507
|
+
if ($$state.existingStates.has(key)) {
|
|
3508
|
+
// is already initialized
|
|
3509
|
+
return _get($$state.stateValues, path);
|
|
3510
|
+
} else if (spec.initFunc) {
|
|
3511
|
+
initializeStateValue($$state, path, spec);
|
|
3512
|
+
}
|
|
3473
3513
|
|
|
3474
|
-
|
|
3514
|
+
return _get($$state.stateValues, path);
|
|
3515
|
+
},
|
|
3516
|
+
set: function set() {
|
|
3517
|
+
throw new Error("Cannot update state values during initialization");
|
|
3518
|
+
}
|
|
3519
|
+
};
|
|
3520
|
+
});
|
|
3521
|
+
(_$$state$unsubscripti2 = $$state.unsubscriptionsByState[initialStateKey]) == null ? void 0 : _$$state$unsubscripti2.forEach(function (f) {
|
|
3522
|
+
return f();
|
|
3523
|
+
});
|
|
3524
|
+
$$state.unsubscriptionsByState[initialStateKey] = [];
|
|
3525
|
+
stateAccess.forEach(function (_ref2) {
|
|
3526
|
+
var path = _ref2.path,
|
|
3527
|
+
spec = _ref2.spec;
|
|
3528
|
+
var unsubscribe = subscribeKey(_get($$state.stateValues, path.slice(-1)), path.slice(-1)[0], function () {
|
|
3529
|
+
return set($$state.stateValues, initialStatePath, mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(path, spec))));
|
|
3530
|
+
});
|
|
3531
|
+
$$state.unsubscriptionsByState[initialStateKey].push(unsubscribe);
|
|
3532
|
+
});
|
|
3533
|
+
var untrackedInitialValue = mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(initialStatePath, initialSpec)));
|
|
3475
3534
|
|
|
3476
|
-
|
|
3535
|
+
set($$state.initStateValues, initialStatePath, untrackedInitialValue);
|
|
3477
3536
|
|
|
3478
|
-
|
|
3537
|
+
set($$state.stateValues, initialStatePath, untrackedInitialValue);
|
|
3479
3538
|
|
|
3480
|
-
|
|
3539
|
+
return untrackedInitialValue;
|
|
3540
|
+
}
|
|
3481
3541
|
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3542
|
+
function useDollarState(specs, props) {
|
|
3543
|
+
var $$state = React__default.useRef(proxy({
|
|
3544
|
+
stateValues: {},
|
|
3545
|
+
initStateValues: {},
|
|
3546
|
+
specsByKey: Object.fromEntries(specs.map(function (spec) {
|
|
3547
|
+
return [spec.path, _extends({}, spec, {
|
|
3548
|
+
pathObj: transformPathStringToObj(spec.path),
|
|
3549
|
+
isRepeated: spec.path.split(".").some(function (part) {
|
|
3550
|
+
return part.endsWith("[]");
|
|
3551
|
+
})
|
|
3552
|
+
})];
|
|
3553
|
+
})),
|
|
3554
|
+
statesInstanceBySpec: new Map(),
|
|
3555
|
+
existingStates: new Map(),
|
|
3556
|
+
unsubscriptionsByState: {},
|
|
3557
|
+
props: undefined,
|
|
3558
|
+
registrationsQueue: []
|
|
3559
|
+
})).current;
|
|
3560
|
+
$$state.props = mkUntrackedValue(props);
|
|
3561
|
+
var $state = React__default.useRef(Object.assign(create$StateProxy($$state, function (path, spec) {
|
|
3562
|
+
var key = JSON.stringify(path);
|
|
3488
3563
|
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
set: function set(_target, _property, newValue) {
|
|
3492
|
-
if (newValue !== _get($$state.stateValues, state.path)) {
|
|
3493
|
-
saveState(state, $$state.states);
|
|
3564
|
+
if (!$$state.existingStates.has(key)) {
|
|
3565
|
+
var _spec$initVal;
|
|
3494
3566
|
|
|
3495
|
-
|
|
3567
|
+
saveNewState($$state, path, spec);
|
|
3568
|
+
var untrackedValue = !spec.initFunc ? mkUntrackedValue((_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined) : initializeStateValue($$state, path, spec);
|
|
3496
3569
|
|
|
3497
|
-
|
|
3498
|
-
var _Object$entries3$_i = _Object$entries3[_i3],
|
|
3499
|
-
key = _Object$entries3$_i[0],
|
|
3500
|
-
deps = _Object$entries3$_i[1];
|
|
3570
|
+
set($$state.stateValues, path, untrackedValue);
|
|
3501
3571
|
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
}
|
|
3505
|
-
}
|
|
3572
|
+
set($$state.initStateValues, path, untrackedValue);
|
|
3573
|
+
}
|
|
3506
3574
|
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3575
|
+
return {
|
|
3576
|
+
get: function get() {
|
|
3577
|
+
if (spec.valueProp) {
|
|
3578
|
+
var value = !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
|
|
3579
|
+
return value;
|
|
3580
|
+
} else {
|
|
3581
|
+
return _get($$state.stateValues, path);
|
|
3512
3582
|
}
|
|
3513
|
-
|
|
3514
|
-
|
|
3583
|
+
},
|
|
3584
|
+
set: function set$1(_t, _p, value) {
|
|
3585
|
+
set($$state.stateValues, path, mkUntrackedValue(value));
|
|
3515
3586
|
|
|
3516
3587
|
if (spec.onChangeProp) {
|
|
3517
|
-
var
|
|
3588
|
+
var _$$state$props$spec$o3, _$$state$props3;
|
|
3518
3589
|
|
|
3519
|
-
(
|
|
3590
|
+
(_$$state$props$spec$o3 = (_$$state$props3 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o3.call(_$$state$props3, value, path);
|
|
3520
3591
|
}
|
|
3521
3592
|
|
|
3522
3593
|
return true;
|
|
@@ -3524,158 +3595,118 @@ function useVanillaDollarState(_specs, props) {
|
|
|
3524
3595
|
};
|
|
3525
3596
|
}), {
|
|
3526
3597
|
registerInitFunc: function registerInitFunc(pathStr, f) {
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
return _get($$state.
|
|
3598
|
+
var _$$state$statesInstan;
|
|
3599
|
+
|
|
3600
|
+
if ((_$$state$statesInstan = $$state.statesInstanceBySpec.get(pathStr)) != null && _$$state$statesInstan.some(function (_ref3) {
|
|
3601
|
+
var path = _ref3.path,
|
|
3602
|
+
specKey = _ref3.specKey;
|
|
3603
|
+
return !deepEqual(_get($$state.initStateValues, path), f(props, $state, getIndexes(path, $$state.specsByKey[specKey])));
|
|
3533
3604
|
})) {
|
|
3534
|
-
$$state.
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
forceRender(function (r) {
|
|
3538
|
-
return r + 1;
|
|
3605
|
+
$$state.registrationsQueue.push({
|
|
3606
|
+
pathStr: pathStr,
|
|
3607
|
+
f: f
|
|
3539
3608
|
});
|
|
3540
3609
|
}
|
|
3541
3610
|
}
|
|
3542
|
-
}); // For each spec with an initFunc, evaluate it and see if
|
|
3611
|
+
})).current; // For each spec with an initFunc, evaluate it and see if
|
|
3543
3612
|
// the init value has changed. If so, reset its state.
|
|
3544
3613
|
|
|
3545
|
-
var newStateValues = undefined;
|
|
3546
3614
|
var resetSpecs = [];
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
specKey = _Object$values$_i.specKey;
|
|
3552
|
-
var spec = $$state.specs[specKey];
|
|
3615
|
+
$$state.existingStates.forEach(function (_ref4) {
|
|
3616
|
+
var path = _ref4.path,
|
|
3617
|
+
specKey = _ref4.specKey;
|
|
3618
|
+
var spec = $$state.specsByKey[specKey];
|
|
3553
3619
|
|
|
3554
3620
|
if (spec.initFunc) {
|
|
3555
|
-
var newInit = spec.initFunc(props, $state);
|
|
3621
|
+
var newInit = spec.initFunc(props, $state, getIndexes(path, spec));
|
|
3556
3622
|
|
|
3557
|
-
if (newInit
|
|
3558
|
-
console.log("init changed for " + JSON.stringify(path) + " from " + _get($$state.initStateValues, path) + " to " + newInit + "; resetting state");
|
|
3623
|
+
if (!deepEqual(newInit, _get($$state.initStateValues, path))) {
|
|
3559
3624
|
resetSpecs.push({
|
|
3560
3625
|
path: path,
|
|
3561
|
-
|
|
3626
|
+
spec: spec
|
|
3562
3627
|
});
|
|
3563
|
-
|
|
3564
|
-
if (!newStateValues) {
|
|
3565
|
-
newStateValues = cloneProxy($$state.specs, $$state.states, $$state.stateValues);
|
|
3566
|
-
}
|
|
3567
|
-
|
|
3568
|
-
dset(newStateValues, path, UNINITIALIZED);
|
|
3569
3628
|
}
|
|
3570
3629
|
}
|
|
3571
|
-
}
|
|
3572
|
-
|
|
3630
|
+
});
|
|
3573
3631
|
React__default.useLayoutEffect(function () {
|
|
3574
|
-
|
|
3575
|
-
var
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
var path = _ref5.path;
|
|
3579
|
-
|
|
3580
|
-
dset(initStateValues, path, _get(newStateValues, path));
|
|
3581
|
-
});
|
|
3582
|
-
$$state.stateValues = cloneProxy($$state.specs, $$state.states, newStateValues);
|
|
3583
|
-
$$state.initStateValues = initStateValues;
|
|
3584
|
-
$$state.initStateDeps = _extends({}, $$state.initStateDeps, newDeps);
|
|
3585
|
-
forceRender(function (r) {
|
|
3586
|
-
return r + 1;
|
|
3587
|
-
});
|
|
3588
|
-
|
|
3589
|
-
for (var _iterator = _createForOfIteratorHelperLoose(resetSpecs), _step; !(_step = _iterator()).done;) {
|
|
3590
|
-
var _step$value = _step.value,
|
|
3591
|
-
_path = _step$value.path,
|
|
3592
|
-
_specKey = _step$value.specKey;
|
|
3593
|
-
var _spec = $$state.specs[_specKey];
|
|
3632
|
+
resetSpecs.forEach(function (_ref5) {
|
|
3633
|
+
var path = _ref5.path,
|
|
3634
|
+
spec = _ref5.spec;
|
|
3635
|
+
var newInit = initializeStateValue($$state, path, spec);
|
|
3594
3636
|
|
|
3595
|
-
|
|
3596
|
-
|
|
3637
|
+
if (spec.onChangeProp) {
|
|
3638
|
+
var _$$state$props$spec$o4, _$$state$props4;
|
|
3597
3639
|
|
|
3598
|
-
|
|
3599
|
-
(_props$_spec$onChange = props[_spec.onChangeProp]) == null ? void 0 : _props$_spec$onChange.call(props, _get(newStateValues, _path));
|
|
3600
|
-
}
|
|
3640
|
+
(_$$state$props$spec$o4 = (_$$state$props4 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o4.call(_$$state$props4, newInit, path);
|
|
3601
3641
|
}
|
|
3602
|
-
}
|
|
3603
|
-
}, [
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
for (var _i5 = 0, _Object$values2 = Object.values($$state.states); _i5 < _Object$values2.length; _i5++) {
|
|
3614
|
-
var _path2 = _Object$values2[_i5].path;
|
|
3615
|
-
|
|
3616
|
-
_get($state, _path2);
|
|
3617
|
-
}
|
|
3642
|
+
});
|
|
3643
|
+
}, [props, resetSpecs]);
|
|
3644
|
+
React__default.useLayoutEffect(function () {
|
|
3645
|
+
$$state.registrationsQueue.forEach(function (_ref6) {
|
|
3646
|
+
var f = _ref6.f,
|
|
3647
|
+
pathStr = _ref6.pathStr;
|
|
3648
|
+
$$state.specsByKey[pathStr].initFunc = f;
|
|
3649
|
+
});
|
|
3650
|
+
$$state.registrationsQueue = [];
|
|
3651
|
+
}, [$$state.registrationsQueue]); // Re-render if any value changed in one of these objects
|
|
3618
3652
|
|
|
3653
|
+
useSnapshot($$state.stateValues, {
|
|
3654
|
+
sync: true
|
|
3655
|
+
});
|
|
3656
|
+
useSnapshot($$state.specsByKey, {
|
|
3657
|
+
sync: true
|
|
3658
|
+
});
|
|
3619
3659
|
return $state;
|
|
3620
3660
|
}
|
|
3621
3661
|
|
|
3622
|
-
function
|
|
3623
|
-
var
|
|
3624
|
-
|
|
3625
|
-
|
|
3662
|
+
function useCanvasDollarState(specs, props) {
|
|
3663
|
+
var $$state = proxy({
|
|
3664
|
+
stateValues: {},
|
|
3665
|
+
initStateValues: {},
|
|
3666
|
+
specsByKey: Object.fromEntries(specs.map(function (spec) {
|
|
3667
|
+
return [spec.path, _extends({}, spec, {
|
|
3668
|
+
pathObj: transformPathStringToObj(spec.path),
|
|
3669
|
+
isRepeated: spec.path.split(".").some(function (part) {
|
|
3670
|
+
return part.endsWith("[]");
|
|
3671
|
+
})
|
|
3672
|
+
})];
|
|
3673
|
+
})),
|
|
3674
|
+
statesInstanceBySpec: new Map(),
|
|
3675
|
+
existingStates: new Map(),
|
|
3676
|
+
unsubscriptionsByState: {},
|
|
3677
|
+
props: undefined,
|
|
3678
|
+
registrationsQueue: []
|
|
3679
|
+
});
|
|
3680
|
+
$$state.props = mkUntrackedValue(props);
|
|
3681
|
+
var $state = create$StateProxy($$state, function (path, spec) {
|
|
3626
3682
|
return {
|
|
3627
|
-
get: function get(
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
return props[spec.valueProp];
|
|
3633
|
-
} else {
|
|
3634
|
-
return _get(props[spec.valueProp], state.path.slice(1));
|
|
3635
|
-
}
|
|
3636
|
-
}
|
|
3637
|
-
|
|
3638
|
-
var value = _get(stateValues, state.path);
|
|
3639
|
-
|
|
3640
|
-
if (value === UNINITIALIZED) {
|
|
3641
|
-
// This value has a init expression; need to be evaluated.
|
|
3642
|
-
value = tracked(state);
|
|
3683
|
+
get: function get() {
|
|
3684
|
+
return _get($$state.stateValues, path);
|
|
3685
|
+
},
|
|
3686
|
+
set: function set$1(_t, _p, value) {
|
|
3687
|
+
set($$state.stateValues, path, mkUntrackedValue(value));
|
|
3643
3688
|
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
// trackInit() to know what fields were used to compute
|
|
3647
|
-
// the init value
|
|
3689
|
+
if (spec.onChangeProp) {
|
|
3690
|
+
var _$$state$props$spec$o5, _$$state$props5;
|
|
3648
3691
|
|
|
3692
|
+
(_$$state$props$spec$o5 = (_$$state$props5 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o5.call(_$$state$props5, value, path);
|
|
3693
|
+
}
|
|
3649
3694
|
|
|
3650
|
-
|
|
3651
|
-
return value;
|
|
3652
|
-
},
|
|
3653
|
-
set: function set() {
|
|
3654
|
-
throw new Error("Cannot update state values during initialization");
|
|
3695
|
+
return true;
|
|
3655
3696
|
}
|
|
3656
3697
|
};
|
|
3657
|
-
}), {
|
|
3658
|
-
registerInitFunc: function registerInitFunc() {}
|
|
3659
3698
|
});
|
|
3660
3699
|
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
var
|
|
3664
|
-
var
|
|
3665
|
-
initFuncDeps[JSON.stringify(state.path)] = [].concat(deps.values());
|
|
3666
|
-
return res;
|
|
3667
|
-
}
|
|
3668
|
-
|
|
3669
|
-
for (var _i6 = 0, _Object$values3 = Object.values(states); _i6 < _Object$values3.length; _i6++) {
|
|
3670
|
-
var path = _Object$values3[_i6].path;
|
|
3700
|
+
for (var _iterator = _createForOfIteratorHelperLoose(specs), _step; !(_step = _iterator()).done;) {
|
|
3701
|
+
var spec = _step.value;
|
|
3702
|
+
var path = transformPathStringToObj(spec.path);
|
|
3703
|
+
var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initVal ? spec.initVal : spec.initFunc ? initializeStateValue($$state, path, $$state.specsByKey[spec.path]) : undefined;
|
|
3671
3704
|
|
|
3672
|
-
|
|
3673
|
-
_get($state, path);
|
|
3674
|
-
}
|
|
3705
|
+
set($state, path, init);
|
|
3675
3706
|
}
|
|
3676
3707
|
|
|
3677
|
-
return
|
|
3708
|
+
return $state;
|
|
3678
3709
|
}
|
|
3679
3710
|
|
|
3680
|
-
export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateValueProp, getDataProps, hasVariant, makeFragment, omit, pick, plasmicHeadMeta, renderPlasmicSlot, setPlumeStrictMode, useButton, useCheckbox,
|
|
3711
|
+
export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateValueProp, getDataProps, hasVariant, makeFragment, mergeVariantsWithStates, omit, pick, plasmicHeadMeta, renderPlasmicSlot, set, setPlumeStrictMode, useButton, useCanvasDollarState, useCheckbox, useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
|
|
3681
3712
|
//# sourceMappingURL=react-web.esm.js.map
|