@plasmicapp/react-web 0.2.201 → 0.2.202

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.
Files changed (148) hide show
  1. package/dist/all.d.ts +1926 -1925
  2. package/dist/auth/PlasmicPageGuard.d.ts +11 -11
  3. package/dist/common.d.ts +10 -10
  4. package/dist/data-sources/index.d.ts +1 -1
  5. package/dist/host/index.d.ts +1 -1
  6. package/dist/index-common.d.ts +18 -18
  7. package/dist/index-skinny.d.ts +1 -1
  8. package/dist/index.cjs.js +3495 -3495
  9. package/dist/index.cjs.js.map +1 -1
  10. package/dist/index.d.ts +11 -11
  11. package/dist/plume/button/index.d.ts +36 -36
  12. package/dist/plume/checkbox/index.d.ts +47 -47
  13. package/dist/plume/collection-utils.d.ts +191 -191
  14. package/dist/plume/collection-utils.spec.d.ts +1 -1
  15. package/dist/plume/menu/context.d.ts +8 -8
  16. package/dist/plume/menu/index.d.ts +3 -3
  17. package/dist/plume/menu/menu-group.d.ts +23 -23
  18. package/dist/plume/menu/menu-item.d.ts +23 -23
  19. package/dist/plume/menu/menu.d.ts +39 -39
  20. package/dist/plume/menu-button/DropdownMenu.d.ts +34 -34
  21. package/dist/plume/menu-button/index.d.ts +2 -2
  22. package/dist/plume/menu-button/menu-button.d.ts +72 -72
  23. package/dist/plume/menu-button/menu-trigger.d.ts +21 -21
  24. package/dist/plume/plume-utils.d.ts +41 -41
  25. package/dist/plume/props-utils.d.ts +15 -15
  26. package/dist/plume/select/context.d.ts +3 -3
  27. package/dist/plume/select/index.d.ts +4 -4
  28. package/dist/plume/select/select-option-group.d.ts +23 -23
  29. package/dist/plume/select/select-option.d.ts +23 -23
  30. package/dist/plume/select/select.d.ts +111 -111
  31. package/dist/plume/switch/index.d.ts +39 -39
  32. package/dist/plume/text-input/index.d.ts +36 -36
  33. package/dist/plume/triggered-overlay/context.d.ts +14 -14
  34. package/dist/plume/triggered-overlay/index.d.ts +2 -2
  35. package/dist/plume/triggered-overlay/triggered-overlay.d.ts +24 -24
  36. package/dist/query/index.d.ts +1 -1
  37. package/dist/react-utils.d.ts +21 -21
  38. package/dist/react-utils.spec.d.ts +1 -1
  39. package/dist/react-web.esm.js +3496 -3496
  40. package/dist/react-web.esm.js.map +1 -1
  41. package/dist/render/PlasmicHead/index.d.ts +37 -37
  42. package/dist/render/PlasmicIcon.d.ts +4 -4
  43. package/dist/render/PlasmicImg/index.d.ts +81 -81
  44. package/dist/render/PlasmicLink.d.ts +2 -2
  45. package/dist/render/PlasmicSlot.d.ts +11 -11
  46. package/dist/render/Stack.d.ts +51 -51
  47. package/dist/render/elements.d.ts +74 -74
  48. package/dist/render/global-variants.d.ts +1 -1
  49. package/dist/render/screen-variants.d.ts +5 -5
  50. package/dist/render/ssr.d.ts +21 -21
  51. package/dist/render/translation.d.ts +19 -19
  52. package/dist/render/triggers.d.ts +39 -39
  53. package/dist/states/errors.d.ts +13 -13
  54. package/dist/states/graph.d.ts +25 -25
  55. package/dist/states/helpers.d.ts +43 -43
  56. package/dist/states/index.d.ts +4 -4
  57. package/dist/states/types.d.ts +66 -66
  58. package/dist/states/valtio.d.ts +10 -10
  59. package/dist/states/vanilla.d.ts +3 -3
  60. package/dist/stories/PlasmicImg.stories.d.ts +6 -6
  61. package/dist/stories/UseDollarState.stories.d.ts +78 -78
  62. package/lib/data-sources/index.d.ts +1 -1
  63. package/lib/host/index.d.ts +1 -1
  64. package/lib/query/index.d.ts +1 -1
  65. package/package.json +8 -9
  66. package/skinny/dist/auth/PlasmicPageGuard.d.ts +11 -11
  67. package/skinny/dist/{collection-utils-0967eaf0.js → collection-utils-2f28e4eb.js} +297 -297
  68. package/skinny/dist/{collection-utils-0967eaf0.js.map → collection-utils-2f28e4eb.js.map} +1 -1
  69. package/skinny/dist/{common-9d6d348d.js → common-ed411407.js} +130 -130
  70. package/skinny/dist/{common-9d6d348d.js.map → common-ed411407.js.map} +1 -1
  71. package/skinny/dist/common.d.ts +10 -10
  72. package/skinny/dist/data-sources/index.d.ts +1 -1
  73. package/skinny/dist/host/index.d.ts +1 -1
  74. package/skinny/dist/index-common.d.ts +18 -18
  75. package/skinny/dist/index-skinny.d.ts +1 -1
  76. package/skinny/dist/index.d.ts +11 -11
  77. package/skinny/dist/index.js +1559 -1559
  78. package/skinny/dist/index.js.map +1 -1
  79. package/skinny/dist/plume/button/index.d.ts +36 -36
  80. package/skinny/dist/plume/button/index.js +21 -21
  81. package/skinny/dist/plume/checkbox/index.d.ts +47 -47
  82. package/skinny/dist/plume/checkbox/index.js +64 -64
  83. package/skinny/dist/plume/collection-utils.d.ts +191 -191
  84. package/skinny/dist/plume/collection-utils.spec.d.ts +1 -1
  85. package/skinny/dist/plume/menu/context.d.ts +8 -8
  86. package/skinny/dist/plume/menu/index.d.ts +3 -3
  87. package/skinny/dist/plume/menu/index.js +165 -165
  88. package/skinny/dist/plume/menu/menu-group.d.ts +23 -23
  89. package/skinny/dist/plume/menu/menu-item.d.ts +23 -23
  90. package/skinny/dist/plume/menu/menu.d.ts +39 -39
  91. package/skinny/dist/plume/menu-button/DropdownMenu.d.ts +34 -34
  92. package/skinny/dist/plume/menu-button/index.d.ts +2 -2
  93. package/skinny/dist/plume/menu-button/index.js +125 -125
  94. package/skinny/dist/plume/menu-button/index.js.map +1 -1
  95. package/skinny/dist/plume/menu-button/menu-button.d.ts +72 -72
  96. package/skinny/dist/plume/menu-button/menu-trigger.d.ts +21 -21
  97. package/skinny/dist/plume/plume-utils.d.ts +41 -41
  98. package/skinny/dist/plume/props-utils.d.ts +15 -15
  99. package/skinny/dist/plume/select/context.d.ts +3 -3
  100. package/skinny/dist/plume/select/index.d.ts +4 -4
  101. package/skinny/dist/plume/select/index.js +250 -250
  102. package/skinny/dist/plume/select/index.js.map +1 -1
  103. package/skinny/dist/plume/select/select-option-group.d.ts +23 -23
  104. package/skinny/dist/plume/select/select-option.d.ts +23 -23
  105. package/skinny/dist/plume/select/select.d.ts +111 -111
  106. package/skinny/dist/plume/switch/index.d.ts +39 -39
  107. package/skinny/dist/plume/switch/index.js +61 -61
  108. package/skinny/dist/plume/text-input/index.d.ts +36 -36
  109. package/skinny/dist/plume/text-input/index.js +45 -45
  110. package/skinny/dist/plume/triggered-overlay/context.d.ts +14 -14
  111. package/skinny/dist/plume/triggered-overlay/index.d.ts +2 -2
  112. package/skinny/dist/plume/triggered-overlay/index.js +100 -100
  113. package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
  114. package/skinny/dist/plume/triggered-overlay/triggered-overlay.d.ts +24 -24
  115. package/skinny/dist/{plume-utils-7d68bcc0.js → plume-utils-e699cd08.js} +30 -30
  116. package/skinny/dist/{plume-utils-7d68bcc0.js.map → plume-utils-e699cd08.js.map} +1 -1
  117. package/skinny/dist/{props-utils-9f9c761a.js → props-utils-9d74371f.js} +4 -4
  118. package/skinny/dist/{props-utils-9f9c761a.js.map → props-utils-9d74371f.js.map} +1 -1
  119. package/skinny/dist/query/index.d.ts +1 -1
  120. package/skinny/dist/{react-utils-ee4e03ba.js → react-utils-5ff031c2.js} +195 -195
  121. package/skinny/dist/{react-utils-ee4e03ba.js.map → react-utils-5ff031c2.js.map} +1 -1
  122. package/skinny/dist/react-utils.d.ts +21 -21
  123. package/skinny/dist/react-utils.spec.d.ts +1 -1
  124. package/skinny/dist/render/PlasmicHead/index.d.ts +37 -37
  125. package/skinny/dist/render/PlasmicHead/index.js +54 -54
  126. package/skinny/dist/render/PlasmicIcon.d.ts +4 -4
  127. package/skinny/dist/render/PlasmicImg/index.d.ts +81 -81
  128. package/skinny/dist/render/PlasmicImg/index.js +297 -297
  129. package/skinny/dist/render/PlasmicLink.d.ts +2 -2
  130. package/skinny/dist/render/PlasmicSlot.d.ts +11 -11
  131. package/skinny/dist/render/Stack.d.ts +51 -51
  132. package/skinny/dist/render/elements.d.ts +74 -74
  133. package/skinny/dist/render/global-variants.d.ts +1 -1
  134. package/skinny/dist/render/screen-variants.d.ts +5 -5
  135. package/skinny/dist/render/ssr.d.ts +21 -21
  136. package/skinny/dist/render/translation.d.ts +19 -19
  137. package/skinny/dist/render/triggers.d.ts +39 -39
  138. package/skinny/dist/{ssr-c9834f50.js → ssr-8625df04.js} +107 -107
  139. package/skinny/dist/{ssr-c9834f50.js.map → ssr-8625df04.js.map} +1 -1
  140. package/skinny/dist/states/errors.d.ts +13 -13
  141. package/skinny/dist/states/graph.d.ts +25 -25
  142. package/skinny/dist/states/helpers.d.ts +43 -43
  143. package/skinny/dist/states/index.d.ts +4 -4
  144. package/skinny/dist/states/types.d.ts +66 -66
  145. package/skinny/dist/states/valtio.d.ts +10 -10
  146. package/skinny/dist/states/vanilla.d.ts +3 -3
  147. package/skinny/dist/stories/PlasmicImg.stories.d.ts +6 -6
  148. package/skinny/dist/stories/UseDollarState.stories.d.ts +78 -78
@@ -5,13 +5,13 @@ import * as React from 'react';
5
5
  import React__default, { useLayoutEffect, useEffect } from 'react';
6
6
  import get from 'dlv';
7
7
  export { default as get } from 'dlv';
8
- import { c as createElementWithChildren, m as mergeProps, e as ensureNotArray, N as NONE, a as mergePropVals, i as isReactNode, b as isBrowser, u as useIsomorphicLayoutEffect$1 } from './react-utils-ee4e03ba.js';
9
- import { _ as __awaiter, a as __generator, b as __assign, c as __rest, d as __spreadArray, e as __read, o as omit, p as pick, f as __values, i as isSubset, g as chainSingleArgFuncs, n as notNil, h as __extends, j as ensure } from './common-9d6d348d.js';
10
- export { o as omit, p as pick } from './common-9d6d348d.js';
8
+ import { c as createElementWithChildren, m as mergeProps, e as ensureNotArray, N as NONE, a as mergePropVals, i as isReactNode, b as isBrowser, u as useIsomorphicLayoutEffect$1 } from './react-utils-5ff031c2.js';
9
+ import { _ as __awaiter, a as __generator, b as __assign, c as __rest, d as __spreadArray, e as __read, o as omit, p as pick, f as __values, i as isSubset, g as chainSingleArgFuncs, n as notNil, h as __extends, j as ensure } from './common-ed411407.js';
10
+ export { o as omit, p as pick } from './common-ed411407.js';
11
11
  export { PlasmicHead, plasmicHeadMeta } from './render/PlasmicHead/index.js';
12
12
  export { PlasmicImg } from './render/PlasmicImg/index.js';
13
- import { T as Trans } from './ssr-c9834f50.js';
14
- export { P as PlasmicRootProvider, T as Trans, g as genTranslatableString, u as useIsSSR } from './ssr-c9834f50.js';
13
+ import { T as Trans } from './ssr-8625df04.js';
14
+ export { P as PlasmicRootProvider, T as Trans, g as genTranslatableString, u as useIsSSR } from './ssr-8625df04.js';
15
15
  import ReactDOM__default from 'react-dom';
16
16
  import { useFocusRing } from '@react-aria/focus';
17
17
  import { proxy, ref, useSnapshot, getVersion, subscribe } from 'valtio';
@@ -19,1588 +19,1588 @@ import clone from 'clone';
19
19
  import deepEqual from 'fast-deep-equal';
20
20
  import '@react-aria/ssr';
21
21
 
22
- // https://stackoverflow.com/a/2117523
23
- function uuidv4() {
24
- // @ts-ignore
25
- return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
26
- return (c ^
27
- (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16);
28
- });
29
- }
30
- function triggerLogin(appId, authorizeEndpoint, redirectUri) {
31
- return __awaiter(this, void 0, void 0, function () {
32
- function sha256(text) {
33
- return __awaiter(this, void 0, void 0, function () {
34
- var encoder, data, hashBuffer, hashArray, hashHex;
35
- return __generator(this, function (_a) {
36
- switch (_a.label) {
37
- case 0:
38
- encoder = new TextEncoder();
39
- data = encoder.encode(text);
40
- return [4 /*yield*/, crypto.subtle.digest("SHA-256", data)];
41
- case 1:
42
- hashBuffer = _a.sent();
43
- hashArray = Array.from(new Uint8Array(hashBuffer));
44
- hashHex = hashArray
45
- .map(function (b) { return b.toString(16).padStart(2, "0"); })
46
- .join("");
47
- return [2 /*return*/, hashHex];
48
- }
49
- });
50
- });
51
- }
52
- var continueTo, state, code_verifier, code_challenge, params, url;
53
- return __generator(this, function (_a) {
54
- switch (_a.label) {
55
- case 0:
56
- continueTo = window.location.href;
57
- state = JSON.stringify({ continueTo: continueTo });
58
- code_verifier = uuidv4();
59
- localStorage.setItem("code_verifier", code_verifier);
60
- return [4 /*yield*/, sha256(code_verifier)];
61
- case 1:
62
- code_challenge = _a.sent();
63
- params = new URLSearchParams();
64
- params.set("client_id", appId);
65
- params.set("state", state);
66
- params.set("response_type", "code");
67
- params.set("code_challenge", code_challenge);
68
- params.set("code_challenge_method", "S256");
69
- if (redirectUri) {
70
- params.set("redirect_uri", redirectUri);
71
- }
72
- url = "".concat(authorizeEndpoint, "?").concat(params.toString());
73
- window.location.href = url;
74
- return [2 /*return*/];
75
- }
76
- });
77
- });
78
- }
79
- function PlasmicPageGuard(props) {
80
- var appId = props.appId, authorizeEndpoint = props.authorizeEndpoint, minRole = props.minRole, canTriggerLogin = props.canTriggerLogin, children = props.children;
81
- var dataSourceCtxValue = usePlasmicDataSourceContext();
82
- React__default.useEffect(function () {
83
- if (canTriggerLogin) {
84
- if (minRole &&
85
- dataSourceCtxValue &&
86
- "isUserLoading" in dataSourceCtxValue &&
87
- !dataSourceCtxValue.isUserLoading &&
88
- !dataSourceCtxValue.user) {
89
- triggerLogin(appId, authorizeEndpoint, dataSourceCtxValue.authRedirectUri);
90
- }
91
- }
92
- }, [dataSourceCtxValue, appId, authorizeEndpoint, canTriggerLogin, minRole]);
93
- function canUserViewPage() {
94
- if (!minRole) {
95
- return true;
96
- }
97
- if (!dataSourceCtxValue) {
98
- return false;
99
- }
100
- if (!dataSourceCtxValue.user) {
101
- return false;
102
- }
103
- if (!("roleIds" in dataSourceCtxValue.user)) {
104
- return false;
105
- }
106
- if (!Array.isArray(dataSourceCtxValue.user.roleIds)) {
107
- return false;
108
- }
109
- return dataSourceCtxValue.user.roleIds.includes(minRole);
110
- }
111
- if (!dataSourceCtxValue ||
112
- dataSourceCtxValue.isUserLoading ||
113
- (!dataSourceCtxValue.user && minRole && canTriggerLogin)) {
114
- return null;
115
- }
116
- if (!canUserViewPage()) {
117
- return React__default.createElement("div", null, "You don't have access to this page");
118
- }
119
- return React__default.createElement(React__default.Fragment, null, children);
120
- }
121
- function withPlasmicPageGuard(WrappedComponent, options) {
122
- var PageGuard = function (props) { return (React__default.createElement(PlasmicPageGuard, __assign({}, options),
123
- React__default.createElement(WrappedComponent, __assign({}, props)))); };
124
- return PageGuard;
22
+ // https://stackoverflow.com/a/2117523
23
+ function uuidv4() {
24
+ // @ts-ignore
25
+ return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
26
+ return (c ^
27
+ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16);
28
+ });
29
+ }
30
+ function triggerLogin(appId, authorizeEndpoint, redirectUri) {
31
+ return __awaiter(this, void 0, void 0, function () {
32
+ function sha256(text) {
33
+ return __awaiter(this, void 0, void 0, function () {
34
+ var encoder, data, hashBuffer, hashArray, hashHex;
35
+ return __generator(this, function (_a) {
36
+ switch (_a.label) {
37
+ case 0:
38
+ encoder = new TextEncoder();
39
+ data = encoder.encode(text);
40
+ return [4 /*yield*/, crypto.subtle.digest("SHA-256", data)];
41
+ case 1:
42
+ hashBuffer = _a.sent();
43
+ hashArray = Array.from(new Uint8Array(hashBuffer));
44
+ hashHex = hashArray
45
+ .map(function (b) { return b.toString(16).padStart(2, "0"); })
46
+ .join("");
47
+ return [2 /*return*/, hashHex];
48
+ }
49
+ });
50
+ });
51
+ }
52
+ var continueTo, state, code_verifier, code_challenge, params, url;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0:
56
+ continueTo = window.location.href;
57
+ state = JSON.stringify({ continueTo: continueTo });
58
+ code_verifier = uuidv4();
59
+ localStorage.setItem("code_verifier", code_verifier);
60
+ return [4 /*yield*/, sha256(code_verifier)];
61
+ case 1:
62
+ code_challenge = _a.sent();
63
+ params = new URLSearchParams();
64
+ params.set("client_id", appId);
65
+ params.set("state", state);
66
+ params.set("response_type", "code");
67
+ params.set("code_challenge", code_challenge);
68
+ params.set("code_challenge_method", "S256");
69
+ if (redirectUri) {
70
+ params.set("redirect_uri", redirectUri);
71
+ }
72
+ url = "".concat(authorizeEndpoint, "?").concat(params.toString());
73
+ window.location.href = url;
74
+ return [2 /*return*/];
75
+ }
76
+ });
77
+ });
78
+ }
79
+ function PlasmicPageGuard(props) {
80
+ var appId = props.appId, authorizeEndpoint = props.authorizeEndpoint, minRole = props.minRole, canTriggerLogin = props.canTriggerLogin, children = props.children;
81
+ var dataSourceCtxValue = usePlasmicDataSourceContext();
82
+ React__default.useEffect(function () {
83
+ if (canTriggerLogin) {
84
+ if (minRole &&
85
+ dataSourceCtxValue &&
86
+ "isUserLoading" in dataSourceCtxValue &&
87
+ !dataSourceCtxValue.isUserLoading &&
88
+ !dataSourceCtxValue.user) {
89
+ triggerLogin(appId, authorizeEndpoint, dataSourceCtxValue.authRedirectUri);
90
+ }
91
+ }
92
+ }, [dataSourceCtxValue, appId, authorizeEndpoint, canTriggerLogin, minRole]);
93
+ function canUserViewPage() {
94
+ if (!minRole) {
95
+ return true;
96
+ }
97
+ if (!dataSourceCtxValue) {
98
+ return false;
99
+ }
100
+ if (!dataSourceCtxValue.user) {
101
+ return false;
102
+ }
103
+ if (!("roleIds" in dataSourceCtxValue.user)) {
104
+ return false;
105
+ }
106
+ if (!Array.isArray(dataSourceCtxValue.user.roleIds)) {
107
+ return false;
108
+ }
109
+ return dataSourceCtxValue.user.roleIds.includes(minRole);
110
+ }
111
+ if (!dataSourceCtxValue ||
112
+ dataSourceCtxValue.isUserLoading ||
113
+ (!dataSourceCtxValue.user && minRole && canTriggerLogin)) {
114
+ return null;
115
+ }
116
+ if (!canUserViewPage()) {
117
+ return React__default.createElement("div", null, "You don't have access to this page");
118
+ }
119
+ return React__default.createElement(React__default.Fragment, null, children);
120
+ }
121
+ function withPlasmicPageGuard(WrappedComponent, options) {
122
+ var PageGuard = function (props) { return (React__default.createElement(PlasmicPageGuard, __assign({}, options),
123
+ React__default.createElement(WrappedComponent, __assign({}, props)))); };
124
+ return PageGuard;
125
125
  }
126
126
 
127
- function renderStack(as, props, hasGap, ref) {
128
- var children = props.children, rest = __rest(props, ["children"]);
129
- var wrappedChildren = wrapFlexContainerChildren(children, hasGap !== null && hasGap !== void 0 ? hasGap : false);
130
- return createElementWithChildren(as, __assign({ ref: ref }, rest), wrappedChildren);
131
- }
132
- function FlexStack_(props, outerRef) {
133
- var as = props.as, hasGap = props.hasGap, rest = __rest(props, ["as", "hasGap"]);
134
- return renderStack(as !== null && as !== void 0 ? as : "div", rest, hasGap, outerRef);
135
- }
136
- var FlexStack = React.forwardRef(FlexStack_);
137
- var makeStackImpl = function (as) {
138
- return React.forwardRef(function (props, ref) {
139
- var hasGap = props.hasGap, rest = __rest(props, ["hasGap"]);
140
- return renderStack(as, rest, hasGap, ref);
141
- });
142
- };
143
- var Stack = Object.assign(FlexStack, {
144
- div: makeStackImpl("div"),
145
- a: makeStackImpl("a"),
146
- button: makeStackImpl("button"),
147
- h1: makeStackImpl("h1"),
148
- h2: makeStackImpl("h2"),
149
- h3: makeStackImpl("h3"),
150
- h4: makeStackImpl("h4"),
151
- h5: makeStackImpl("h5"),
152
- h6: makeStackImpl("h6"),
153
- label: makeStackImpl("label"),
154
- form: makeStackImpl("form"),
155
- section: makeStackImpl("section"),
156
- head: makeStackImpl("head"),
157
- main: makeStackImpl("main"),
158
- nav: makeStackImpl("nav")
127
+ function renderStack(as, props, hasGap, ref) {
128
+ var children = props.children, rest = __rest(props, ["children"]);
129
+ var wrappedChildren = wrapFlexContainerChildren(children, hasGap !== null && hasGap !== void 0 ? hasGap : false);
130
+ return createElementWithChildren(as, __assign({ ref: ref }, rest), wrappedChildren);
131
+ }
132
+ function FlexStack_(props, outerRef) {
133
+ var as = props.as, hasGap = props.hasGap, rest = __rest(props, ["as", "hasGap"]);
134
+ return renderStack(as !== null && as !== void 0 ? as : "div", rest, hasGap, outerRef);
135
+ }
136
+ var FlexStack = React.forwardRef(FlexStack_);
137
+ var makeStackImpl = function (as) {
138
+ return React.forwardRef(function (props, ref) {
139
+ var hasGap = props.hasGap, rest = __rest(props, ["hasGap"]);
140
+ return renderStack(as, rest, hasGap, ref);
141
+ });
142
+ };
143
+ var Stack = Object.assign(FlexStack, {
144
+ div: makeStackImpl("div"),
145
+ a: makeStackImpl("a"),
146
+ button: makeStackImpl("button"),
147
+ h1: makeStackImpl("h1"),
148
+ h2: makeStackImpl("h2"),
149
+ h3: makeStackImpl("h3"),
150
+ h4: makeStackImpl("h4"),
151
+ h5: makeStackImpl("h5"),
152
+ h6: makeStackImpl("h6"),
153
+ label: makeStackImpl("label"),
154
+ form: makeStackImpl("form"),
155
+ section: makeStackImpl("section"),
156
+ head: makeStackImpl("head"),
157
+ main: makeStackImpl("main"),
158
+ nav: makeStackImpl("nav"),
159
159
  });
160
160
 
161
- function hasVariant(variants, groupName, variant) {
162
- if (variants == null) {
163
- return false;
164
- }
165
- var groupVariants = variants[groupName];
166
- if (groupVariants == null) {
167
- return false;
168
- }
169
- else if (groupVariants === true) {
170
- return variant === groupName;
171
- }
172
- else if (groupVariants === false) {
173
- return false;
174
- }
175
- else if (Array.isArray(groupVariants)) {
176
- return groupVariants.includes(variant);
177
- }
178
- else if (typeof groupVariants === "string") {
179
- return groupVariants === variant;
180
- }
181
- else {
182
- return (groupVariants[variant] !== undefined && groupVariants[variant] !== false);
183
- }
184
- }
185
- function wrapFlexContainerChildren(children, hasGap) {
186
- // We need to always wrap the children, even if there are no gaps, because
187
- // otherwise if we toggle between with and without gap, React reconciliation
188
- // will blow away the children tree and all state if we switch from having
189
- // a wrapper and not.
190
- var className = hasGap ? "__wab_flex-container" : "__wab_passthrough";
191
- if (!children) {
192
- return null;
193
- }
194
- else if (Array.isArray(children)) {
195
- return React.createElement.apply(React, __spreadArray(["div", { className: className }], __read(children), false));
196
- }
197
- else {
198
- return React.createElement("div", { className: className }, children);
199
- }
200
- }
201
- function createPlasmicElement(override, defaultRoot, defaultProps, wrapChildrenInFlex) {
202
- if (!override || Object.keys(override).length === 0) {
203
- return createElementWithChildren(defaultRoot, defaultProps, defaultProps.children);
204
- }
205
- var override2 = deriveOverride(override);
206
- var props = mergeOverrideProps(defaultProps, override2.props);
207
- if (override2.type === "render") {
208
- return override2.render(props, defaultRoot);
209
- }
210
- var root = defaultRoot;
211
- if (override2.type === "as" && override2.as) {
212
- if (defaultRoot === Stack) {
213
- // If there was an "as" override specified, but the default type is
214
- // a Stack, then we don't want to switch to using "as" as the root,
215
- // because then we'd lose the flex wrapper that Stack provides.
216
- // Instead, we specify the "as" as the "as" prop to Stack.
217
- props.as = override2.as;
218
- }
219
- else {
220
- root = override2.as;
221
- }
222
- }
223
- var children = props.children;
224
- if (override2.wrapChildren) {
225
- children = override2.wrapChildren(ensureNotArray(children));
226
- }
227
- if (wrapChildrenInFlex) {
228
- // For legacy, we still support data-plasmic-wrap-flex-children
229
- children = wrapFlexContainerChildren(children, true);
230
- }
231
- var result = createElementWithChildren(root, props, children);
232
- if (override2.wrap) {
233
- result = override2.wrap(result);
234
- }
235
- return result;
236
- }
237
- // We use data-plasmic-XXX attributes for custom properties since Typescript doesn't
238
- // support type check on jsx pragma. See https://github.com/microsoft/TypeScript/issues/21699
239
- // for more info.
240
- var seenElements = new Map();
241
- function createPlasmicElementProxy(defaultElement, props) {
242
- // We use seenElements to keep track of elements that has been rendered by
243
- // createPlasmicElementProxy(). When a JSX tree is evaluated, the JSX factory
244
- // is invoked from the leaf to the root as the last call. So we can store
245
- // all the elements we've created until we encounter the leaf, at which point
246
- // we will clear this map. We are guaranteed that this map will only contain
247
- // elements from one Plasmic* component at a time, because we're just creating
248
- // elements and not "rendering" at this point; even if this JSX tree references
249
- // other Plasmic* elements, we'll just create an element referencing that component,
250
- // rather than following into the content of that component.
251
- //
252
- // TODO: is this ConcurrentMode friendly?
253
- var _a;
254
- var children = [];
255
- for (var _i = 2; _i < arguments.length; _i++) {
256
- children[_i - 2] = arguments[_i];
257
- }
258
- if (props == null) {
259
- props = {};
260
- }
261
- var name = props["data-plasmic-name"];
262
- var isRoot = props["data-plasmic-root"];
263
- var forNodeName = props["data-plasmic-for-node"];
264
- delete props["data-plasmic-name"];
265
- delete props["data-plasmic-root"];
266
- delete props["data-plasmic-for-node"];
267
- var element = createPlasmicElementFromJsx.apply(void 0, __spreadArray([defaultElement,
268
- props], __read(children), false));
269
- if (name) {
270
- seenElements.set(name, element);
271
- }
272
- if (isRoot) {
273
- // If this is the root, and we requested a specific node by specifying data-plasmic-for-node,
274
- // then return that node instead
275
- var forNode = forNodeName
276
- ? (_a = seenElements.get(forNodeName)) !== null && _a !== void 0 ? _a : null
277
- : element;
278
- // Clear out the seenElements map, as we're done rendering this Plasmic* component.
279
- seenElements.clear();
280
- return forNode;
281
- }
282
- return element;
283
- }
284
- function createPlasmicElementFromJsx(defaultElement, props) {
285
- var _a;
286
- var children = [];
287
- for (var _i = 2; _i < arguments.length; _i++) {
288
- children[_i - 2] = arguments[_i];
289
- }
290
- var override = props["data-plasmic-override"];
291
- var wrapFlexChild = props["data-plasmic-wrap-flex-child"];
292
- var triggerProps = ((_a = props["data-plasmic-trigger-props"]) !== null && _a !== void 0 ? _a : []);
293
- delete props["data-plasmic-override"];
294
- delete props["data-plasmic-wrap-flex-child"];
295
- delete props["data-plasmic-trigger-props"];
296
- return createPlasmicElement(override, defaultElement, mergeProps.apply(void 0, __spreadArray([props,
297
- children.length === 0
298
- ? {}
299
- : { children: children.length === 1 ? children[0] : children }], __read(triggerProps), false)), wrapFlexChild);
300
- }
301
- function makeFragment() {
302
- var children = [];
303
- for (var _i = 0; _i < arguments.length; _i++) {
304
- children[_i] = arguments[_i];
305
- }
306
- return React.createElement.apply(React, __spreadArray([React.Fragment, {}], __read(children), false));
307
- }
308
- var UNSET = Symbol("UNSET");
309
- function mergeOverrideProps(defaults, overrides) {
310
- var e_1, _a;
311
- if (!overrides) {
312
- return defaults;
313
- }
314
- var result = __assign({}, defaults);
315
- try {
316
- for (var _b = __values(Object.keys(overrides)), _c = _b.next(); !_c.done; _c = _b.next()) {
317
- var key = _c.value;
318
- var defaultVal = defaults[key];
319
- var overrideVal = overrides[key];
320
- if (overrideVal === UNSET) {
321
- delete result[key];
322
- }
323
- else {
324
- // We use the NONE sentinel if the overrideVal is nil, and is not one of the
325
- // props that we merge by default -- which are className, style, and
326
- // event handlers. This means for all other "normal" props -- like children,
327
- // title, etc -- a nil value will unset the default.
328
- if (overrideVal == null &&
329
- key !== "className" &&
330
- key !== "style" &&
331
- !(key.startsWith("on") && typeof defaultVal === "function")) {
332
- overrideVal = NONE;
333
- }
334
- result[key] = mergePropVals(key, defaultVal, overrideVal);
335
- }
336
- }
337
- }
338
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
339
- finally {
340
- try {
341
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
342
- }
343
- finally { if (e_1) throw e_1.error; }
344
- }
345
- return result;
346
- }
347
- function wrapWithClassName(element, className) {
348
- var key = React.isValidElement(element)
349
- ? element.key || undefined
350
- : undefined;
351
- return React.createElement("div", {
352
- key: key,
353
- className: className,
354
- style: {
355
- display: "grid"
356
- }
357
- }, element);
358
- }
359
- function deriveOverride(x) {
360
- if (!x) {
361
- // undefined Binding is an empty Binding
362
- return {
363
- type: "default",
364
- props: {}
365
- };
366
- }
367
- else if (isReactNode(x)) {
368
- // If ReactNode, then assume this is the children
369
- return {
370
- type: "default",
371
- props: {
372
- children: x
373
- }
374
- };
375
- }
376
- else if (typeof x === "object") {
377
- // If any of the overrideKeys is a key of this object, then assume
378
- // this is a full Override
379
- if ("as" in x) {
380
- return __assign(__assign({}, x), { props: x.props || {}, type: "as" });
381
- }
382
- else if ("render" in x) {
383
- return __assign(__assign({}, x), { type: "render" });
384
- }
385
- else if ("props" in x) {
386
- return __assign(__assign({}, x), { props: x.props || {}, type: "default" });
387
- }
388
- else if (isSubset(Object.keys(x), ["wrap", "wrapChildren"])) {
389
- // Only twiddling functions present, so assume no props overrides
390
- // (otherwise we'd assume these were props).
391
- return __assign(__assign({}, x), { props: {}, type: "default" });
392
- }
393
- // Else, assume this is just a props object.
394
- return {
395
- type: "default",
396
- props: x
397
- };
398
- }
399
- else if (typeof x === "function") {
400
- return {
401
- type: "render",
402
- render: x
403
- };
404
- }
405
- throw new Error("Unexpected override: ".concat(x));
406
- }
407
- function mergeVariants(v1, v2) {
408
- if (!v1 || !v2) {
409
- return v1 || v2 || {};
410
- }
411
- return __assign(__assign({}, v1), v2);
412
- }
413
- function mergeVariantsWithStates(variants, $state, linkedStates) {
414
- return __assign(__assign({}, variants), Object.fromEntries(linkedStates.map(function (_a) {
415
- var variantGroup = _a.variantGroup, statePath = _a.statePath;
416
- return [
417
- variantGroup,
418
- get($state, statePath),
419
- ];
420
- })));
421
- }
422
- function mergeArgs(a1, a2) {
423
- if (!a1 || !a2) {
424
- return a1 || a2 || {};
425
- }
426
- return __assign(__assign({}, a1), a2);
427
- }
428
- function mergeFlexOverrides(o1, o2) {
429
- var e_2, _a;
430
- if (!o2) {
431
- return o1;
432
- }
433
- var keys = Array.from(new Set(__spreadArray(__spreadArray([], __read(Object.keys(o1)), false), __read(Object.keys(o2)), false)));
434
- var merged = {};
435
- try {
436
- for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
437
- var key = keys_1_1.value;
438
- merged[key] = mergeFlexOverride(o1[key], o2[key]);
439
- }
440
- }
441
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
442
- finally {
443
- try {
444
- if (keys_1_1 && !keys_1_1.done && (_a = keys_1["return"])) _a.call(keys_1);
445
- }
446
- finally { if (e_2) throw e_2.error; }
447
- }
448
- return merged;
449
- }
450
- function mergeFlexOverride(fo1, fo2) {
451
- var _a, _b;
452
- if (!fo1) {
453
- return fo2;
454
- }
455
- if (!fo2) {
456
- return fo1;
457
- }
458
- var o1 = deriveOverride(fo1);
459
- var o2 = deriveOverride(fo2);
460
- var wrap = chainSingleArgFuncs.apply(void 0, __spreadArray([], __read([o1.wrap, o2.wrap].filter(notNil)), false));
461
- var wrapChildren = chainSingleArgFuncs.apply(void 0, __spreadArray([], __read([o1.wrapChildren, o2.wrapChildren].filter(notNil)), false));
462
- // "render" type always takes precedence, but we still merge the props
463
- var props = mergeOverrideProps((_a = o1.props) !== null && _a !== void 0 ? _a : {}, o2.props);
464
- if (o2.type === "render") {
465
- return {
466
- render: o2.render,
467
- props: props,
468
- wrap: wrap,
469
- wrapChildren: wrapChildren
470
- };
471
- }
472
- if (o1.type === "render") {
473
- return {
474
- render: o1.render,
475
- props: props,
476
- wrap: wrap,
477
- wrapChildren: wrapChildren
478
- };
479
- }
480
- // "as" will take precedence
481
- var as = (_b = (o2.type === "as" ? o2.as : undefined)) !== null && _b !== void 0 ? _b : (o1.type === "as" ? o1.as : undefined);
482
- return __assign({ props: props, wrap: wrap, wrapChildren: wrapChildren }, (as ? { as: as } : {}));
483
- }
484
- function deriveRenderOpts(props, config) {
485
- var _a;
486
- var name = config.name, descendantNames = config.descendantNames, internalVariantPropNames = config.internalVariantPropNames, internalArgPropNames = config.internalArgPropNames;
487
- var reservedPropNames = ["variants", "args", "overrides"];
488
- var variants = mergeVariants(omit.apply(void 0, __spreadArray([pick.apply(void 0, __spreadArray([props], __read(internalVariantPropNames), false))], __read(reservedPropNames), false)), props.variants);
489
- var args = mergeArgs(omit.apply(void 0, __spreadArray([pick.apply(void 0, __spreadArray([props], __read(internalArgPropNames), false))], __read(reservedPropNames), false)), props.args);
490
- var overrides = mergeFlexOverrides(omit.apply(void 0, __spreadArray(__spreadArray(__spreadArray([pick.apply(void 0, __spreadArray([props], __read(descendantNames), false))], __read(internalArgPropNames), false), __read(internalVariantPropNames), false), __read(reservedPropNames), false)), props.overrides);
491
- var leftoverProps = omit.apply(void 0, __spreadArray(__spreadArray(__spreadArray([props,
492
- "variants",
493
- "args",
494
- "overrides"], __read(descendantNames), false), __read(internalVariantPropNames), false), __read(internalArgPropNames), false));
495
- if (Object.keys(leftoverProps).length > 0) {
496
- overrides = mergeFlexOverrides(overrides, (_a = {},
497
- _a[name] = {
498
- props: leftoverProps
499
- },
500
- _a));
501
- }
502
- return { variants: variants, args: args, overrides: overrides };
161
+ function hasVariant(variants, groupName, variant) {
162
+ if (variants == null) {
163
+ return false;
164
+ }
165
+ var groupVariants = variants[groupName];
166
+ if (groupVariants == null) {
167
+ return false;
168
+ }
169
+ else if (groupVariants === true) {
170
+ return variant === groupName;
171
+ }
172
+ else if (groupVariants === false) {
173
+ return false;
174
+ }
175
+ else if (Array.isArray(groupVariants)) {
176
+ return groupVariants.includes(variant);
177
+ }
178
+ else if (typeof groupVariants === "string") {
179
+ return groupVariants === variant;
180
+ }
181
+ else {
182
+ return (groupVariants[variant] !== undefined && groupVariants[variant] !== false);
183
+ }
184
+ }
185
+ function wrapFlexContainerChildren(children, hasGap) {
186
+ // We need to always wrap the children, even if there are no gaps, because
187
+ // otherwise if we toggle between with and without gap, React reconciliation
188
+ // will blow away the children tree and all state if we switch from having
189
+ // a wrapper and not.
190
+ var className = hasGap ? "__wab_flex-container" : "__wab_passthrough";
191
+ if (!children) {
192
+ return null;
193
+ }
194
+ else if (Array.isArray(children)) {
195
+ return React.createElement.apply(React, __spreadArray(["div", { className: className }], __read(children), false));
196
+ }
197
+ else {
198
+ return React.createElement("div", { className: className }, children);
199
+ }
200
+ }
201
+ function createPlasmicElement(override, defaultRoot, defaultProps, wrapChildrenInFlex) {
202
+ if (!override || Object.keys(override).length === 0) {
203
+ return createElementWithChildren(defaultRoot, defaultProps, defaultProps.children);
204
+ }
205
+ var override2 = deriveOverride(override);
206
+ var props = mergeOverrideProps(defaultProps, override2.props);
207
+ if (override2.type === "render") {
208
+ return override2.render(props, defaultRoot);
209
+ }
210
+ var root = defaultRoot;
211
+ if (override2.type === "as" && override2.as) {
212
+ if (defaultRoot === Stack) {
213
+ // If there was an "as" override specified, but the default type is
214
+ // a Stack, then we don't want to switch to using "as" as the root,
215
+ // because then we'd lose the flex wrapper that Stack provides.
216
+ // Instead, we specify the "as" as the "as" prop to Stack.
217
+ props.as = override2.as;
218
+ }
219
+ else {
220
+ root = override2.as;
221
+ }
222
+ }
223
+ var children = props.children;
224
+ if (override2.wrapChildren) {
225
+ children = override2.wrapChildren(ensureNotArray(children));
226
+ }
227
+ if (wrapChildrenInFlex) {
228
+ // For legacy, we still support data-plasmic-wrap-flex-children
229
+ children = wrapFlexContainerChildren(children, true);
230
+ }
231
+ var result = createElementWithChildren(root, props, children);
232
+ if (override2.wrap) {
233
+ result = override2.wrap(result);
234
+ }
235
+ return result;
236
+ }
237
+ // We use data-plasmic-XXX attributes for custom properties since Typescript doesn't
238
+ // support type check on jsx pragma. See https://github.com/microsoft/TypeScript/issues/21699
239
+ // for more info.
240
+ var seenElements = new Map();
241
+ function createPlasmicElementProxy(defaultElement, props) {
242
+ // We use seenElements to keep track of elements that has been rendered by
243
+ // createPlasmicElementProxy(). When a JSX tree is evaluated, the JSX factory
244
+ // is invoked from the leaf to the root as the last call. So we can store
245
+ // all the elements we've created until we encounter the leaf, at which point
246
+ // we will clear this map. We are guaranteed that this map will only contain
247
+ // elements from one Plasmic* component at a time, because we're just creating
248
+ // elements and not "rendering" at this point; even if this JSX tree references
249
+ // other Plasmic* elements, we'll just create an element referencing that component,
250
+ // rather than following into the content of that component.
251
+ //
252
+ // TODO: is this ConcurrentMode friendly?
253
+ var _a;
254
+ var children = [];
255
+ for (var _i = 2; _i < arguments.length; _i++) {
256
+ children[_i - 2] = arguments[_i];
257
+ }
258
+ if (props == null) {
259
+ props = {};
260
+ }
261
+ var name = props["data-plasmic-name"];
262
+ var isRoot = props["data-plasmic-root"];
263
+ var forNodeName = props["data-plasmic-for-node"];
264
+ delete props["data-plasmic-name"];
265
+ delete props["data-plasmic-root"];
266
+ delete props["data-plasmic-for-node"];
267
+ var element = createPlasmicElementFromJsx.apply(void 0, __spreadArray([defaultElement,
268
+ props], __read(children), false));
269
+ if (name) {
270
+ seenElements.set(name, element);
271
+ }
272
+ if (isRoot) {
273
+ // If this is the root, and we requested a specific node by specifying data-plasmic-for-node,
274
+ // then return that node instead
275
+ var forNode = forNodeName
276
+ ? (_a = seenElements.get(forNodeName)) !== null && _a !== void 0 ? _a : null
277
+ : element;
278
+ // Clear out the seenElements map, as we're done rendering this Plasmic* component.
279
+ seenElements.clear();
280
+ return forNode;
281
+ }
282
+ return element;
283
+ }
284
+ function createPlasmicElementFromJsx(defaultElement, props) {
285
+ var _a;
286
+ var children = [];
287
+ for (var _i = 2; _i < arguments.length; _i++) {
288
+ children[_i - 2] = arguments[_i];
289
+ }
290
+ var override = props["data-plasmic-override"];
291
+ var wrapFlexChild = props["data-plasmic-wrap-flex-child"];
292
+ var triggerProps = ((_a = props["data-plasmic-trigger-props"]) !== null && _a !== void 0 ? _a : []);
293
+ delete props["data-plasmic-override"];
294
+ delete props["data-plasmic-wrap-flex-child"];
295
+ delete props["data-plasmic-trigger-props"];
296
+ return createPlasmicElement(override, defaultElement, mergeProps.apply(void 0, __spreadArray([props,
297
+ children.length === 0
298
+ ? {}
299
+ : { children: children.length === 1 ? children[0] : children }], __read(triggerProps), false)), wrapFlexChild);
300
+ }
301
+ function makeFragment() {
302
+ var children = [];
303
+ for (var _i = 0; _i < arguments.length; _i++) {
304
+ children[_i] = arguments[_i];
305
+ }
306
+ return React.createElement.apply(React, __spreadArray([React.Fragment, {}], __read(children), false));
307
+ }
308
+ var UNSET = Symbol("UNSET");
309
+ function mergeOverrideProps(defaults, overrides) {
310
+ var e_1, _a;
311
+ if (!overrides) {
312
+ return defaults;
313
+ }
314
+ var result = __assign({}, defaults);
315
+ try {
316
+ for (var _b = __values(Object.keys(overrides)), _c = _b.next(); !_c.done; _c = _b.next()) {
317
+ var key = _c.value;
318
+ var defaultVal = defaults[key];
319
+ var overrideVal = overrides[key];
320
+ if (overrideVal === UNSET) {
321
+ delete result[key];
322
+ }
323
+ else {
324
+ // We use the NONE sentinel if the overrideVal is nil, and is not one of the
325
+ // props that we merge by default -- which are className, style, and
326
+ // event handlers. This means for all other "normal" props -- like children,
327
+ // title, etc -- a nil value will unset the default.
328
+ if (overrideVal == null &&
329
+ key !== "className" &&
330
+ key !== "style" &&
331
+ !(key.startsWith("on") && typeof defaultVal === "function")) {
332
+ overrideVal = NONE;
333
+ }
334
+ result[key] = mergePropVals(key, defaultVal, overrideVal);
335
+ }
336
+ }
337
+ }
338
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
339
+ finally {
340
+ try {
341
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
342
+ }
343
+ finally { if (e_1) throw e_1.error; }
344
+ }
345
+ return result;
346
+ }
347
+ function wrapWithClassName(element, className) {
348
+ var key = React.isValidElement(element)
349
+ ? element.key || undefined
350
+ : undefined;
351
+ return React.createElement("div", {
352
+ key: key,
353
+ className: className,
354
+ style: {
355
+ display: "grid",
356
+ },
357
+ }, element);
358
+ }
359
+ function deriveOverride(x) {
360
+ if (!x) {
361
+ // undefined Binding is an empty Binding
362
+ return {
363
+ type: "default",
364
+ props: {},
365
+ };
366
+ }
367
+ else if (isReactNode(x)) {
368
+ // If ReactNode, then assume this is the children
369
+ return {
370
+ type: "default",
371
+ props: {
372
+ children: x,
373
+ },
374
+ };
375
+ }
376
+ else if (typeof x === "object") {
377
+ // If any of the overrideKeys is a key of this object, then assume
378
+ // this is a full Override
379
+ if ("as" in x) {
380
+ return __assign(__assign({}, x), { props: x.props || {}, type: "as" });
381
+ }
382
+ else if ("render" in x) {
383
+ return __assign(__assign({}, x), { type: "render" });
384
+ }
385
+ else if ("props" in x) {
386
+ return __assign(__assign({}, x), { props: x.props || {}, type: "default" });
387
+ }
388
+ else if (isSubset(Object.keys(x), ["wrap", "wrapChildren"])) {
389
+ // Only twiddling functions present, so assume no props overrides
390
+ // (otherwise we'd assume these were props).
391
+ return __assign(__assign({}, x), { props: {}, type: "default" });
392
+ }
393
+ // Else, assume this is just a props object.
394
+ return {
395
+ type: "default",
396
+ props: x,
397
+ };
398
+ }
399
+ else if (typeof x === "function") {
400
+ return {
401
+ type: "render",
402
+ render: x,
403
+ };
404
+ }
405
+ throw new Error("Unexpected override: ".concat(x));
406
+ }
407
+ function mergeVariants(v1, v2) {
408
+ if (!v1 || !v2) {
409
+ return v1 || v2 || {};
410
+ }
411
+ return __assign(__assign({}, v1), v2);
412
+ }
413
+ function mergeVariantsWithStates(variants, $state, linkedStates) {
414
+ return __assign(__assign({}, variants), Object.fromEntries(linkedStates.map(function (_a) {
415
+ var variantGroup = _a.variantGroup, statePath = _a.statePath;
416
+ return [
417
+ variantGroup,
418
+ get($state, statePath),
419
+ ];
420
+ })));
421
+ }
422
+ function mergeArgs(a1, a2) {
423
+ if (!a1 || !a2) {
424
+ return a1 || a2 || {};
425
+ }
426
+ return __assign(__assign({}, a1), a2);
427
+ }
428
+ function mergeFlexOverrides(o1, o2) {
429
+ var e_2, _a;
430
+ if (!o2) {
431
+ return o1;
432
+ }
433
+ var keys = Array.from(new Set(__spreadArray(__spreadArray([], __read(Object.keys(o1)), false), __read(Object.keys(o2)), false)));
434
+ var merged = {};
435
+ try {
436
+ for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
437
+ var key = keys_1_1.value;
438
+ merged[key] = mergeFlexOverride(o1[key], o2[key]);
439
+ }
440
+ }
441
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
442
+ finally {
443
+ try {
444
+ if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
445
+ }
446
+ finally { if (e_2) throw e_2.error; }
447
+ }
448
+ return merged;
449
+ }
450
+ function mergeFlexOverride(fo1, fo2) {
451
+ var _a, _b;
452
+ if (!fo1) {
453
+ return fo2;
454
+ }
455
+ if (!fo2) {
456
+ return fo1;
457
+ }
458
+ var o1 = deriveOverride(fo1);
459
+ var o2 = deriveOverride(fo2);
460
+ var wrap = chainSingleArgFuncs.apply(void 0, __spreadArray([], __read([o1.wrap, o2.wrap].filter(notNil)), false));
461
+ var wrapChildren = chainSingleArgFuncs.apply(void 0, __spreadArray([], __read([o1.wrapChildren, o2.wrapChildren].filter(notNil)), false));
462
+ // "render" type always takes precedence, but we still merge the props
463
+ var props = mergeOverrideProps((_a = o1.props) !== null && _a !== void 0 ? _a : {}, o2.props);
464
+ if (o2.type === "render") {
465
+ return {
466
+ render: o2.render,
467
+ props: props,
468
+ wrap: wrap,
469
+ wrapChildren: wrapChildren,
470
+ };
471
+ }
472
+ if (o1.type === "render") {
473
+ return {
474
+ render: o1.render,
475
+ props: props,
476
+ wrap: wrap,
477
+ wrapChildren: wrapChildren,
478
+ };
479
+ }
480
+ // "as" will take precedence
481
+ var as = (_b = (o2.type === "as" ? o2.as : undefined)) !== null && _b !== void 0 ? _b : (o1.type === "as" ? o1.as : undefined);
482
+ return __assign({ props: props, wrap: wrap, wrapChildren: wrapChildren }, (as ? { as: as } : {}));
483
+ }
484
+ function deriveRenderOpts(props, config) {
485
+ var _a;
486
+ var name = config.name, descendantNames = config.descendantNames, internalVariantPropNames = config.internalVariantPropNames, internalArgPropNames = config.internalArgPropNames;
487
+ var reservedPropNames = ["variants", "args", "overrides"];
488
+ var variants = mergeVariants(omit.apply(void 0, __spreadArray([pick.apply(void 0, __spreadArray([props], __read(internalVariantPropNames), false))], __read(reservedPropNames), false)), props.variants);
489
+ var args = mergeArgs(omit.apply(void 0, __spreadArray([pick.apply(void 0, __spreadArray([props], __read(internalArgPropNames), false))], __read(reservedPropNames), false)), props.args);
490
+ var overrides = mergeFlexOverrides(omit.apply(void 0, __spreadArray(__spreadArray(__spreadArray([pick.apply(void 0, __spreadArray([props], __read(descendantNames), false))], __read(internalArgPropNames), false), __read(internalVariantPropNames), false), __read(reservedPropNames), false)), props.overrides);
491
+ var leftoverProps = omit.apply(void 0, __spreadArray(__spreadArray(__spreadArray([props,
492
+ "variants",
493
+ "args",
494
+ "overrides"], __read(descendantNames), false), __read(internalVariantPropNames), false), __read(internalArgPropNames), false));
495
+ if (Object.keys(leftoverProps).length > 0) {
496
+ overrides = mergeFlexOverrides(overrides, (_a = {},
497
+ _a[name] = {
498
+ props: leftoverProps,
499
+ },
500
+ _a));
501
+ }
502
+ return { variants: variants, args: args, overrides: overrides };
503
503
  }
504
504
 
505
- var isDefaultValue = function (val) { return val === "PLEASE_RENDER_INSIDE_PROVIDER"; };
506
- var seenDefaultVariants = {};
507
- function ensureGlobalVariants(globalVariantValues) {
508
- Object.entries(globalVariantValues)
509
- .filter(function (_a) {
510
- var _b = __read(_a, 2); _b[0]; var value = _b[1];
511
- return isDefaultValue(value);
512
- })
513
- .forEach(function (_a) {
514
- var _b = __read(_a, 2), key = _b[0]; _b[1];
515
- globalVariantValues[key] = undefined;
516
- if (!seenDefaultVariants[key] && process.env.NODE_ENV === "development") {
517
- seenDefaultVariants[key] = true;
518
- var providerName = "".concat(key[0].toUpperCase()).concat(key.substring(1), "Context.Provider");
519
- console.warn("Plasmic context value for global variant \"".concat(key, "\" was not provided; please use ").concat(providerName, " at the root of your React app. Learn More: https://www.plasmic.app/learn/other-assets/#global-variants"));
520
- }
521
- });
522
- return globalVariantValues;
505
+ var isDefaultValue = function (val) { return val === "PLEASE_RENDER_INSIDE_PROVIDER"; };
506
+ var seenDefaultVariants = {};
507
+ function ensureGlobalVariants(globalVariantValues) {
508
+ Object.entries(globalVariantValues)
509
+ .filter(function (_a) {
510
+ var _b = __read(_a, 2); _b[0]; var value = _b[1];
511
+ return isDefaultValue(value);
512
+ })
513
+ .forEach(function (_a) {
514
+ var _b = __read(_a, 2), key = _b[0]; _b[1];
515
+ globalVariantValues[key] = undefined;
516
+ if (!seenDefaultVariants[key] && process.env.NODE_ENV === "development") {
517
+ seenDefaultVariants[key] = true;
518
+ var providerName = "".concat(key[0].toUpperCase()).concat(key.substring(1), "Context.Provider");
519
+ console.warn("Plasmic context value for global variant \"".concat(key, "\" was not provided; please use ").concat(providerName, " at the root of your React app. Learn More: https://www.plasmic.app/learn/other-assets/#global-variants"));
520
+ }
521
+ });
522
+ return globalVariantValues;
523
523
  }
524
524
 
525
- function PlasmicIcon(props) {
526
- var PlasmicIconType = props.PlasmicIconType, rest = __rest(props, ["PlasmicIconType"]);
527
- return React.createElement(PlasmicIconType, __assign({}, rest));
525
+ function PlasmicIcon(props) {
526
+ var PlasmicIconType = props.PlasmicIconType, rest = __rest(props, ["PlasmicIconType"]);
527
+ return React.createElement(PlasmicIconType, __assign({}, rest));
528
528
  }
529
529
 
530
- var PlasmicLink = React__default.forwardRef(function PlasmicLink(props, ref) {
531
- // props.href is required for nextjs; if no props.href,
532
- // then we just render the default anchor element
533
- if (props.platform === "nextjs" && props.href) {
534
- var nextjsProps = [
535
- "href",
536
- "replace",
537
- "scroll",
538
- "shallow",
539
- "passHref",
540
- "prefetch",
541
- "locale",
542
- ];
543
- return React__default.createElement(props.component, __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(nextjsProps), false))), { legacyBehavior: true }), React__default.createElement("a", __assign({}, omit.apply(void 0, __spreadArray([props, "component", "platform"], __read(nextjsProps), false)), { ref: ref })));
544
- }
545
- if (props.platform === "gatsby" && isInternalHref(props.href)) {
546
- return React__default.createElement(props.component, __assign(__assign({}, omit(props, "component", "platform", "href")), { to: props.href, ref: ref }));
547
- }
548
- return React__default.createElement("a", __assign({}, omit(props, "component", "platform"), { ref: ref }));
549
- });
550
- function isInternalHref(href) {
551
- return /^\/(?!\/)/.test(href);
530
+ var PlasmicLink = React__default.forwardRef(function PlasmicLink(props, ref) {
531
+ // props.href is required for nextjs; if no props.href,
532
+ // then we just render the default anchor element
533
+ if (props.platform === "nextjs" && props.href) {
534
+ var nextjsProps = [
535
+ "href",
536
+ "replace",
537
+ "scroll",
538
+ "shallow",
539
+ "passHref",
540
+ "prefetch",
541
+ "locale",
542
+ ];
543
+ return React__default.createElement(props.component, __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(nextjsProps), false))), { legacyBehavior: true }), React__default.createElement("a", __assign({}, omit.apply(void 0, __spreadArray([props, "component", "platform"], __read(nextjsProps), false)), { ref: ref })));
544
+ }
545
+ if (props.platform === "gatsby" && isInternalHref(props.href)) {
546
+ return React__default.createElement(props.component, __assign(__assign({}, omit(props, "component", "platform", "href")), { to: props.href, ref: ref }));
547
+ }
548
+ return React__default.createElement("a", __assign({}, omit(props, "component", "platform"), { ref: ref }));
549
+ });
550
+ function isInternalHref(href) {
551
+ return /^\/(?!\/)/.test(href);
552
552
  }
553
553
 
554
- function PlasmicSlot(props) {
555
- return renderPlasmicSlot(props);
556
- }
557
- function renderPlasmicSlot(opts) {
558
- var as = opts.as, defaultContents = opts.defaultContents, value = opts.value, rest = __rest(opts, ["as", "defaultContents", "value"]);
559
- var content = value === undefined ? defaultContents : value;
560
- if (!content || (Array.isArray(content) && content.length === 0)) {
561
- return null;
562
- }
563
- // If the content is a raw string, then we need to wrap the raw string
564
- // into an element, in case the slot is inside a flex-gap
565
- // container (you cannot apply margin to just a text node).
566
- var maybeString = maybeAsString(content);
567
- if (maybeString) {
568
- content = React.createElement("span", { className: "__wab_slot-string-wrapper" }, maybeString);
569
- }
570
- var nonEmptyProps = Object.keys(rest).filter(function (p) { return !!rest[p]; });
571
- if (nonEmptyProps.length === 0) {
572
- // No attrs to apply to the slot (which means the slot is unstyled), then
573
- // just render the content directly; no need for style wrapper.
574
- return React.createElement(React.Fragment, null, content);
575
- }
576
- return React.createElement(as || "span", mergeProps({ className: "__wab_slot" }, rest), content);
577
- }
578
- function maybeAsString(node) {
579
- // Unwrap fragments
580
- if (React.isValidElement(node)) {
581
- // Fragment doesn't render DOM elements
582
- if (node.type === React.Fragment) {
583
- return maybeAsString(node.props.children);
584
- }
585
- else if (node.type === Trans) {
586
- // Trans also doesn't render DOM elements. But we don't want to just render
587
- // its content string, because we want to keep the <Trans/> for the localization.
588
- // So we render the same node, to be wrapped into __wab_slot-string-wrapper.
589
- return node;
590
- }
591
- }
592
- if (typeof node === "string") {
593
- return node;
594
- }
595
- if (Array.isArray(node) && node.length === 1 && typeof node[0] === "string") {
596
- return node[0];
597
- }
598
- return undefined;
554
+ function PlasmicSlot(props) {
555
+ return renderPlasmicSlot(props);
556
+ }
557
+ function renderPlasmicSlot(opts) {
558
+ var as = opts.as, defaultContents = opts.defaultContents, value = opts.value, rest = __rest(opts, ["as", "defaultContents", "value"]);
559
+ var content = value === undefined ? defaultContents : value;
560
+ if (!content || (Array.isArray(content) && content.length === 0)) {
561
+ return null;
562
+ }
563
+ // If the content is a raw string, then we need to wrap the raw string
564
+ // into an element, in case the slot is inside a flex-gap
565
+ // container (you cannot apply margin to just a text node).
566
+ var maybeString = maybeAsString(content);
567
+ if (maybeString) {
568
+ content = React.createElement("span", { className: "__wab_slot-string-wrapper" }, maybeString);
569
+ }
570
+ var nonEmptyProps = Object.keys(rest).filter(function (p) { return !!rest[p]; });
571
+ if (nonEmptyProps.length === 0) {
572
+ // No attrs to apply to the slot (which means the slot is unstyled), then
573
+ // just render the content directly; no need for style wrapper.
574
+ return React.createElement(React.Fragment, null, content);
575
+ }
576
+ return React.createElement(as || "span", mergeProps({ className: "__wab_slot" }, rest), content);
577
+ }
578
+ function maybeAsString(node) {
579
+ // Unwrap fragments
580
+ if (React.isValidElement(node)) {
581
+ // Fragment doesn't render DOM elements
582
+ if (node.type === React.Fragment) {
583
+ return maybeAsString(node.props.children);
584
+ }
585
+ else if (node.type === Trans) {
586
+ // Trans also doesn't render DOM elements. But we don't want to just render
587
+ // its content string, because we want to keep the <Trans/> for the localization.
588
+ // So we render the same node, to be wrapped into __wab_slot-string-wrapper.
589
+ return node;
590
+ }
591
+ }
592
+ if (typeof node === "string") {
593
+ return node;
594
+ }
595
+ if (Array.isArray(node) && node.length === 1 && typeof node[0] === "string") {
596
+ return node[0];
597
+ }
598
+ return undefined;
599
599
  }
600
600
 
601
- var listeners = [];
602
- var queries = {};
603
- function matchScreenVariants() {
604
- if (!isBrowser) {
605
- return [];
606
- }
607
- return Object.entries(queries)
608
- .filter(function (_a) {
609
- var _b = __read(_a, 2), query = _b[1];
610
- return window.matchMedia(query).matches;
611
- })
612
- .map(function (_a) {
613
- var _b = __read(_a, 1), name = _b[0];
614
- return name;
615
- });
616
- }
617
- // undefined if screen variants have never been calculated
618
- var curScreenVariants = undefined;
619
- function recalculateScreenVariants() {
620
- var screenVariant = matchScreenVariants();
621
- if (!curScreenVariants ||
622
- screenVariant.join("") !== curScreenVariants.join("")) {
623
- curScreenVariants = screenVariant;
624
- ReactDOM__default.unstable_batchedUpdates(function () {
625
- return listeners.forEach(function (listener) { return listener(); });
626
- });
627
- }
628
- }
629
- function ensureInitCurScreenVariants() {
630
- // Initializes curScreenVariants if it hadn't been before. Note that this must
631
- // be called from within an effect.
632
- if (curScreenVariants === undefined) {
633
- curScreenVariants = matchScreenVariants();
634
- }
635
- }
636
- if (isBrowser) {
637
- window.addEventListener("resize", recalculateScreenVariants);
638
- }
639
- function createUseScreenVariants(isMulti, screenQueries) {
640
- Object.assign(queries, screenQueries);
641
- curScreenVariants = undefined;
642
- return function () {
643
- // It is important that upon first render, we return [] or undefined, because
644
- // that is what SSR will use, and the client must match. In an effect (which
645
- // only happens on the client), we then actually ask for the real screen variant
646
- // and, if different from [] or undefined, forces a re-render.
647
- var _a = __read(React.useState(), 2), updateState = _a[1];
648
- var lastScreenVariantsRef = React.useRef(curScreenVariants || []);
649
- // We do useLayoutEffect instead of useEffect to immediately
650
- // register our forceUpdate. This ensures that if there was
651
- // a window resize event between render and effects, that the
652
- // listener will be registered in time
653
- useIsomorphicLayoutEffect$1(function () {
654
- var updateIfChanged = function () {
655
- if (curScreenVariants &&
656
- lastScreenVariantsRef.current.join("") !== curScreenVariants.join("")) {
657
- lastScreenVariantsRef.current = curScreenVariants;
658
- // Force update
659
- updateState({});
660
- }
661
- };
662
- // Listeners are invoked whenever the window is resized
663
- listeners.push(updateIfChanged);
664
- // Initialize the curScreenVariants for the first time. We don't need
665
- // to invoke the listeners here because all components will already
666
- // have this effect running and will re-render if the real screen
667
- // variant is non-empty.
668
- ensureInitCurScreenVariants();
669
- // Now, if the curScreenVariants differs from what we returned last,
670
- // then force a re-render.
671
- updateIfChanged();
672
- return function () {
673
- // Remove our listener on unmount
674
- listeners.splice(listeners.indexOf(updateIfChanged), 1);
675
- };
676
- }, []);
677
- if (isMulti) {
678
- return curScreenVariants || [];
679
- }
680
- else if (curScreenVariants) {
681
- return curScreenVariants[curScreenVariants.length - 1];
682
- }
683
- else {
684
- return undefined;
685
- }
686
- };
601
+ var listeners = [];
602
+ var queries = {};
603
+ function matchScreenVariants() {
604
+ if (!isBrowser) {
605
+ return [];
606
+ }
607
+ return Object.entries(queries)
608
+ .filter(function (_a) {
609
+ var _b = __read(_a, 2), query = _b[1];
610
+ return window.matchMedia(query).matches;
611
+ })
612
+ .map(function (_a) {
613
+ var _b = __read(_a, 1), name = _b[0];
614
+ return name;
615
+ });
616
+ }
617
+ // undefined if screen variants have never been calculated
618
+ var curScreenVariants = undefined;
619
+ function recalculateScreenVariants() {
620
+ var screenVariant = matchScreenVariants();
621
+ if (!curScreenVariants ||
622
+ screenVariant.join("") !== curScreenVariants.join("")) {
623
+ curScreenVariants = screenVariant;
624
+ ReactDOM__default.unstable_batchedUpdates(function () {
625
+ return listeners.forEach(function (listener) { return listener(); });
626
+ });
627
+ }
628
+ }
629
+ function ensureInitCurScreenVariants() {
630
+ // Initializes curScreenVariants if it hadn't been before. Note that this must
631
+ // be called from within an effect.
632
+ if (curScreenVariants === undefined) {
633
+ curScreenVariants = matchScreenVariants();
634
+ }
635
+ }
636
+ if (isBrowser) {
637
+ window.addEventListener("resize", recalculateScreenVariants);
638
+ }
639
+ function createUseScreenVariants(isMulti, screenQueries) {
640
+ Object.assign(queries, screenQueries);
641
+ curScreenVariants = undefined;
642
+ return function () {
643
+ // It is important that upon first render, we return [] or undefined, because
644
+ // that is what SSR will use, and the client must match. In an effect (which
645
+ // only happens on the client), we then actually ask for the real screen variant
646
+ // and, if different from [] or undefined, forces a re-render.
647
+ var _a = __read(React.useState(), 2), updateState = _a[1];
648
+ var lastScreenVariantsRef = React.useRef(curScreenVariants || []);
649
+ // We do useLayoutEffect instead of useEffect to immediately
650
+ // register our forceUpdate. This ensures that if there was
651
+ // a window resize event between render and effects, that the
652
+ // listener will be registered in time
653
+ useIsomorphicLayoutEffect$1(function () {
654
+ var updateIfChanged = function () {
655
+ if (curScreenVariants &&
656
+ lastScreenVariantsRef.current.join("") !== curScreenVariants.join("")) {
657
+ lastScreenVariantsRef.current = curScreenVariants;
658
+ // Force update
659
+ updateState({});
660
+ }
661
+ };
662
+ // Listeners are invoked whenever the window is resized
663
+ listeners.push(updateIfChanged);
664
+ // Initialize the curScreenVariants for the first time. We don't need
665
+ // to invoke the listeners here because all components will already
666
+ // have this effect running and will re-render if the real screen
667
+ // variant is non-empty.
668
+ ensureInitCurScreenVariants();
669
+ // Now, if the curScreenVariants differs from what we returned last,
670
+ // then force a re-render.
671
+ updateIfChanged();
672
+ return function () {
673
+ // Remove our listener on unmount
674
+ listeners.splice(listeners.indexOf(updateIfChanged), 1);
675
+ };
676
+ }, []);
677
+ if (isMulti) {
678
+ return curScreenVariants || [];
679
+ }
680
+ else if (curScreenVariants) {
681
+ return curScreenVariants[curScreenVariants.length - 1];
682
+ }
683
+ else {
684
+ return undefined;
685
+ }
686
+ };
687
687
  }
688
688
 
689
- function useFocused(opts) {
690
- var _a = useFocusRing({
691
- within: false,
692
- isTextInput: opts.isTextInput
693
- }), isFocused = _a.isFocused, focusProps = _a.focusProps;
694
- return [isFocused, focusProps];
695
- }
696
- function useFocusVisible(opts) {
697
- var _a = useFocusRing({
698
- within: false,
699
- isTextInput: opts.isTextInput
700
- }), isFocusVisible = _a.isFocusVisible, focusProps = _a.focusProps;
701
- return [isFocusVisible, focusProps];
702
- }
703
- function useFocusedWithin(opts) {
704
- var _a = useFocusRing({
705
- within: true,
706
- isTextInput: opts.isTextInput
707
- }), isFocused = _a.isFocused, focusProps = _a.focusProps;
708
- return [isFocused, focusProps];
709
- }
710
- function useFocusVisibleWithin(opts) {
711
- var _a = useFocusRing({
712
- within: true,
713
- isTextInput: opts.isTextInput
714
- }), isFocusVisible = _a.isFocusVisible, focusProps = _a.focusProps;
715
- return [isFocusVisible, focusProps];
716
- }
717
- function useHover() {
718
- var _a = __read(React.useState(false), 2), isHover = _a[0], setHover = _a[1];
719
- return [
720
- isHover,
721
- {
722
- onMouseEnter: function () { return setHover(true); },
723
- onMouseLeave: function () { return setHover(false); }
724
- },
725
- ];
726
- }
727
- function usePressed() {
728
- var _a = __read(React.useState(false), 2), isPressed = _a[0], setPressed = _a[1];
729
- return [
730
- isPressed,
731
- {
732
- onMouseDown: function () { return setPressed(true); },
733
- onMouseUp: function () { return setPressed(false); }
734
- },
735
- ];
736
- }
737
- var TRIGGER_TO_HOOK = {
738
- useHover: useHover,
739
- useFocused: useFocused,
740
- useFocusVisible: useFocusVisible,
741
- useFocusedWithin: useFocusedWithin,
742
- useFocusVisibleWithin: useFocusVisibleWithin,
743
- usePressed: usePressed
744
- };
745
- /**
746
- * Installs argment trigger. All the useTrigger calls must use hardcoded `trigger` arg,
747
- * as it's not valid to install variable React hooks!
748
- */
749
- function useTrigger(trigger, opts) {
750
- return TRIGGER_TO_HOOK[trigger](opts);
689
+ function useFocused(opts) {
690
+ var _a = useFocusRing({
691
+ within: false,
692
+ isTextInput: opts.isTextInput,
693
+ }), isFocused = _a.isFocused, focusProps = _a.focusProps;
694
+ return [isFocused, focusProps];
695
+ }
696
+ function useFocusVisible(opts) {
697
+ var _a = useFocusRing({
698
+ within: false,
699
+ isTextInput: opts.isTextInput,
700
+ }), isFocusVisible = _a.isFocusVisible, focusProps = _a.focusProps;
701
+ return [isFocusVisible, focusProps];
702
+ }
703
+ function useFocusedWithin(opts) {
704
+ var _a = useFocusRing({
705
+ within: true,
706
+ isTextInput: opts.isTextInput,
707
+ }), isFocused = _a.isFocused, focusProps = _a.focusProps;
708
+ return [isFocused, focusProps];
709
+ }
710
+ function useFocusVisibleWithin(opts) {
711
+ var _a = useFocusRing({
712
+ within: true,
713
+ isTextInput: opts.isTextInput,
714
+ }), isFocusVisible = _a.isFocusVisible, focusProps = _a.focusProps;
715
+ return [isFocusVisible, focusProps];
716
+ }
717
+ function useHover() {
718
+ var _a = __read(React.useState(false), 2), isHover = _a[0], setHover = _a[1];
719
+ return [
720
+ isHover,
721
+ {
722
+ onMouseEnter: function () { return setHover(true); },
723
+ onMouseLeave: function () { return setHover(false); },
724
+ },
725
+ ];
726
+ }
727
+ function usePressed() {
728
+ var _a = __read(React.useState(false), 2), isPressed = _a[0], setPressed = _a[1];
729
+ return [
730
+ isPressed,
731
+ {
732
+ onMouseDown: function () { return setPressed(true); },
733
+ onMouseUp: function () { return setPressed(false); },
734
+ },
735
+ ];
736
+ }
737
+ var TRIGGER_TO_HOOK = {
738
+ useHover: useHover,
739
+ useFocused: useFocused,
740
+ useFocusVisible: useFocusVisible,
741
+ useFocusedWithin: useFocusedWithin,
742
+ useFocusVisibleWithin: useFocusVisibleWithin,
743
+ usePressed: usePressed,
744
+ };
745
+ /**
746
+ * Installs argment trigger. All the useTrigger calls must use hardcoded `trigger` arg,
747
+ * as it's not valid to install variable React hooks!
748
+ */
749
+ function useTrigger(trigger, opts) {
750
+ return TRIGGER_TO_HOOK[trigger](opts);
751
751
  }
752
752
 
753
- var ARRAY_SYMBOL = Symbol("[]");
754
- var PLASMIC_STATE_PROXY_SYMBOL = Symbol("plasmic.state.proxy");
753
+ var ARRAY_SYMBOL = Symbol("[]");
754
+ var PLASMIC_STATE_PROXY_SYMBOL = Symbol("plasmic.state.proxy");
755
755
  var UNINITIALIZED = Symbol("plasmic.unitialized");
756
756
 
757
- /** @class */ ((function (_super) {
758
- __extends(CustomError, _super);
759
- function CustomError(msg) {
760
- var _a;
761
- var _this = _super.call(this, msg) || this;
762
- _this.name = _this.constructor.name;
763
- (_a = _this, _this.message = _a.message, _this.stack = _a.stack);
764
- return _this;
765
- }
766
- return CustomError;
767
- })(Error));
768
- var CyclicStatesReferencesError = /** @class */ (function (_super) {
769
- __extends(CyclicStatesReferencesError, _super);
770
- function CyclicStatesReferencesError(stateAccessCycle) {
771
- return _super.call(this, "Cyclic reference found in state initialization: " +
772
- stateAccessCycle.join(" -> ")) || this;
773
- }
774
- return CyclicStatesReferencesError;
775
- }(Error));
776
- var InvalidOperation = /** @class */ (function (_super) {
777
- __extends(InvalidOperation, _super);
778
- function InvalidOperation(msg) {
779
- return _super.call(this, msg) || this;
780
- }
781
- return InvalidOperation;
782
- }(Error));
783
- var UnknownError = /** @class */ (function (_super) {
784
- __extends(UnknownError, _super);
785
- function UnknownError(msg) {
786
- return _super.call(this, msg) || this;
787
- }
788
- return UnknownError;
757
+ /** @class */ ((function (_super) {
758
+ __extends(CustomError, _super);
759
+ function CustomError(msg) {
760
+ var _a;
761
+ var _this = _super.call(this, msg) || this;
762
+ _this.name = _this.constructor.name;
763
+ (_a = _this, _this.message = _a.message, _this.stack = _a.stack);
764
+ return _this;
765
+ }
766
+ return CustomError;
767
+ })(Error));
768
+ var CyclicStatesReferencesError = /** @class */ (function (_super) {
769
+ __extends(CyclicStatesReferencesError, _super);
770
+ function CyclicStatesReferencesError(stateAccessCycle) {
771
+ return _super.call(this, "Cyclic reference found in state initialization: " +
772
+ stateAccessCycle.join(" -> ")) || this;
773
+ }
774
+ return CyclicStatesReferencesError;
775
+ }(Error));
776
+ var InvalidOperation = /** @class */ (function (_super) {
777
+ __extends(InvalidOperation, _super);
778
+ function InvalidOperation(msg) {
779
+ return _super.call(this, msg) || this;
780
+ }
781
+ return InvalidOperation;
782
+ }(Error));
783
+ var UnknownError = /** @class */ (function (_super) {
784
+ __extends(UnknownError, _super);
785
+ function UnknownError(msg) {
786
+ return _super.call(this, msg) || this;
787
+ }
788
+ return UnknownError;
789
789
  }(Error));
790
790
 
791
- var StateSpecNode = /** @class */ (function () {
792
- function StateSpecNode(specs) {
793
- this._specs = specs;
794
- this._edges = new Map();
795
- }
796
- StateSpecNode.prototype.setSpecs = function (specs) {
797
- this._specs = specs;
798
- };
799
- StateSpecNode.prototype.edges = function () {
800
- return this._edges;
801
- };
802
- StateSpecNode.prototype.hasEdge = function (key) {
803
- return this._edges.has(key);
804
- };
805
- StateSpecNode.prototype.addEdge = function (key, node) {
806
- this._edges.set(key, node);
807
- };
808
- StateSpecNode.prototype.clearEdges = function () {
809
- this._edges = new Map();
810
- };
811
- StateSpecNode.prototype.children = function () {
812
- return this._edges.values();
813
- };
814
- StateSpecNode.prototype.makeTransition = function (key) {
815
- key = isNum(key) ? ARRAY_SYMBOL : key;
816
- return this._edges.get(key);
817
- };
818
- StateSpecNode.prototype.isLeaf = function () {
819
- return this._edges.size === 0 && this.getAllSpecs().length > 0;
820
- };
821
- StateSpecNode.prototype.hasArrayTransition = function () {
822
- return this._edges.has(ARRAY_SYMBOL);
823
- };
824
- StateSpecNode.prototype.getSpec = function () {
825
- return this._specs[0];
826
- };
827
- StateSpecNode.prototype.getAllSpecs = function () {
828
- return this._specs;
829
- };
830
- return StateSpecNode;
831
- }());
832
- var transformPathStringToObj = function (str) {
833
- var splitStatePathPart = function (state) {
834
- return state.endsWith("[]")
835
- ? __spreadArray(__spreadArray([], __read(splitStatePathPart(state.slice(0, -2))), false), [ARRAY_SYMBOL], false) : [state];
836
- };
837
- return str.split(".").flatMap(splitStatePathPart);
838
- };
839
- function buildTree(specs) {
840
- var internalSpec = specs.map(function (spec) {
841
- return (__assign(__assign({}, spec), { pathObj: transformPathStringToObj(spec.path), isRepeated: spec.path.split(".").some(function (part) { return part.endsWith("[]"); }) }));
842
- });
843
- var rec = function (currentPath) {
844
- var node = new StateSpecNode(internalSpec.filter(function (spec) {
845
- return shallowEqual(currentPath, spec.pathObj.slice(0, currentPath.length));
846
- }));
847
- node.getAllSpecs().forEach(function (spec) {
848
- if (spec.pathObj.length > currentPath.length) {
849
- var nextKey = spec.pathObj[currentPath.length];
850
- if (!node.hasEdge(nextKey)) {
851
- node.addEdge(nextKey, rec(__spreadArray(__spreadArray([], __read(currentPath), false), [nextKey], false)));
852
- }
853
- }
854
- });
855
- return node;
856
- };
857
- return rec([]);
858
- }
859
- function updateTree(root, specs) {
860
- var internalSpec = specs.map(function (spec) {
861
- return (__assign(__assign({}, spec), { pathObj: transformPathStringToObj(spec.path), isRepeated: spec.path.split(".").some(function (part) { return part.endsWith("[]"); }) }));
862
- });
863
- var rec = function (oldNode, currentPath) {
864
- var nodeSpecs = internalSpec.filter(function (spec) {
865
- return shallowEqual(currentPath, spec.pathObj.slice(0, currentPath.length));
866
- });
867
- var node = oldNode !== null && oldNode !== void 0 ? oldNode : new StateSpecNode(nodeSpecs);
868
- node.setSpecs(nodeSpecs);
869
- var oldEdges = oldNode === null || oldNode === void 0 ? void 0 : oldNode.edges();
870
- node.clearEdges();
871
- node.getAllSpecs().forEach(function (spec) {
872
- if (spec.pathObj.length > currentPath.length) {
873
- var nextKey = spec.pathObj[currentPath.length];
874
- if (!node.hasEdge(nextKey)) {
875
- node.addEdge(nextKey, rec(oldEdges === null || oldEdges === void 0 ? void 0 : oldEdges.get(nextKey), __spreadArray(__spreadArray([], __read(currentPath), false), [nextKey], false)));
876
- }
877
- }
878
- });
879
- return node;
880
- };
881
- return rec(root, []);
882
- }
883
- function getSpecTreeLeaves(root) {
884
- var leaves = [];
885
- var rec = function (node) {
886
- var e_1, _a;
887
- try {
888
- for (var _b = __values(node.children()), _c = _b.next(); !_c.done; _c = _b.next()) {
889
- var child = _c.value;
890
- rec(child);
891
- }
892
- }
893
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
894
- finally {
895
- try {
896
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
897
- }
898
- finally { if (e_1) throw e_1.error; }
899
- }
900
- if (node.isLeaf() && node.getAllSpecs().length > 0) {
901
- leaves.push(node);
902
- }
903
- };
904
- rec(root);
905
- return leaves;
906
- }
907
- function findStateCell(root, pathStr, repetitionIndex) {
908
- var e_2, _a;
909
- var realPath = [];
910
- var pathObj = transformPathStringToObj(pathStr);
911
- var currRepIndex = 0;
912
- try {
913
- for (var pathObj_1 = __values(pathObj), pathObj_1_1 = pathObj_1.next(); !pathObj_1_1.done; pathObj_1_1 = pathObj_1.next()) {
914
- var part = pathObj_1_1.value;
915
- if (typeof part === "symbol") {
916
- if (!root.hasArrayTransition() ||
917
- !repetitionIndex ||
918
- currRepIndex > repetitionIndex.length) {
919
- throw new Error("transition not found: pathStr ".concat(pathStr, " part ").concat(typeof part === "symbol" ? "[]" : part));
920
- }
921
- realPath.push(repetitionIndex[currRepIndex++]);
922
- root = root.makeTransition(ARRAY_SYMBOL);
923
- }
924
- else {
925
- if (!root.hasEdge(part)) {
926
- throw new Error("transition not found: pathStr ".concat(pathStr, " part ").concat(typeof part === "symbol" ? "[]" : part));
927
- }
928
- realPath.push(part);
929
- root = root.makeTransition(part);
930
- }
931
- }
932
- }
933
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
934
- finally {
935
- try {
936
- if (pathObj_1_1 && !pathObj_1_1.done && (_a = pathObj_1["return"])) _a.call(pathObj_1);
937
- }
938
- finally { if (e_2) throw e_2.error; }
939
- }
940
- return {
941
- node: root,
942
- realPath: realPath
943
- };
791
+ var StateSpecNode = /** @class */ (function () {
792
+ function StateSpecNode(specs) {
793
+ this._specs = specs;
794
+ this._edges = new Map();
795
+ }
796
+ StateSpecNode.prototype.setSpecs = function (specs) {
797
+ this._specs = specs;
798
+ };
799
+ StateSpecNode.prototype.edges = function () {
800
+ return this._edges;
801
+ };
802
+ StateSpecNode.prototype.hasEdge = function (key) {
803
+ return this._edges.has(key);
804
+ };
805
+ StateSpecNode.prototype.addEdge = function (key, node) {
806
+ this._edges.set(key, node);
807
+ };
808
+ StateSpecNode.prototype.clearEdges = function () {
809
+ this._edges = new Map();
810
+ };
811
+ StateSpecNode.prototype.children = function () {
812
+ return this._edges.values();
813
+ };
814
+ StateSpecNode.prototype.makeTransition = function (key) {
815
+ key = isNum(key) ? ARRAY_SYMBOL : key;
816
+ return this._edges.get(key);
817
+ };
818
+ StateSpecNode.prototype.isLeaf = function () {
819
+ return this._edges.size === 0 && this.getAllSpecs().length > 0;
820
+ };
821
+ StateSpecNode.prototype.hasArrayTransition = function () {
822
+ return this._edges.has(ARRAY_SYMBOL);
823
+ };
824
+ StateSpecNode.prototype.getSpec = function () {
825
+ return this._specs[0];
826
+ };
827
+ StateSpecNode.prototype.getAllSpecs = function () {
828
+ return this._specs;
829
+ };
830
+ return StateSpecNode;
831
+ }());
832
+ var transformPathStringToObj = function (str) {
833
+ var splitStatePathPart = function (state) {
834
+ return state.endsWith("[]")
835
+ ? __spreadArray(__spreadArray([], __read(splitStatePathPart(state.slice(0, -2))), false), [ARRAY_SYMBOL], false) : [state];
836
+ };
837
+ return str.split(".").flatMap(splitStatePathPart);
838
+ };
839
+ function buildTree(specs) {
840
+ var internalSpec = specs.map(function (spec) {
841
+ return (__assign(__assign({}, spec), { pathObj: transformPathStringToObj(spec.path), isRepeated: spec.path.split(".").some(function (part) { return part.endsWith("[]"); }) }));
842
+ });
843
+ var rec = function (currentPath) {
844
+ var node = new StateSpecNode(internalSpec.filter(function (spec) {
845
+ return shallowEqual(currentPath, spec.pathObj.slice(0, currentPath.length));
846
+ }));
847
+ node.getAllSpecs().forEach(function (spec) {
848
+ if (spec.pathObj.length > currentPath.length) {
849
+ var nextKey = spec.pathObj[currentPath.length];
850
+ if (!node.hasEdge(nextKey)) {
851
+ node.addEdge(nextKey, rec(__spreadArray(__spreadArray([], __read(currentPath), false), [nextKey], false)));
852
+ }
853
+ }
854
+ });
855
+ return node;
856
+ };
857
+ return rec([]);
858
+ }
859
+ function updateTree(root, specs) {
860
+ var internalSpec = specs.map(function (spec) {
861
+ return (__assign(__assign({}, spec), { pathObj: transformPathStringToObj(spec.path), isRepeated: spec.path.split(".").some(function (part) { return part.endsWith("[]"); }) }));
862
+ });
863
+ var rec = function (oldNode, currentPath) {
864
+ var nodeSpecs = internalSpec.filter(function (spec) {
865
+ return shallowEqual(currentPath, spec.pathObj.slice(0, currentPath.length));
866
+ });
867
+ var node = oldNode !== null && oldNode !== void 0 ? oldNode : new StateSpecNode(nodeSpecs);
868
+ node.setSpecs(nodeSpecs);
869
+ var oldEdges = oldNode === null || oldNode === void 0 ? void 0 : oldNode.edges();
870
+ node.clearEdges();
871
+ node.getAllSpecs().forEach(function (spec) {
872
+ if (spec.pathObj.length > currentPath.length) {
873
+ var nextKey = spec.pathObj[currentPath.length];
874
+ if (!node.hasEdge(nextKey)) {
875
+ node.addEdge(nextKey, rec(oldEdges === null || oldEdges === void 0 ? void 0 : oldEdges.get(nextKey), __spreadArray(__spreadArray([], __read(currentPath), false), [nextKey], false)));
876
+ }
877
+ }
878
+ });
879
+ return node;
880
+ };
881
+ return rec(root, []);
882
+ }
883
+ function getSpecTreeLeaves(root) {
884
+ var leaves = [];
885
+ var rec = function (node) {
886
+ var e_1, _a;
887
+ try {
888
+ for (var _b = __values(node.children()), _c = _b.next(); !_c.done; _c = _b.next()) {
889
+ var child = _c.value;
890
+ rec(child);
891
+ }
892
+ }
893
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
894
+ finally {
895
+ try {
896
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
897
+ }
898
+ finally { if (e_1) throw e_1.error; }
899
+ }
900
+ if (node.isLeaf() && node.getAllSpecs().length > 0) {
901
+ leaves.push(node);
902
+ }
903
+ };
904
+ rec(root);
905
+ return leaves;
906
+ }
907
+ function findStateCell(root, pathStr, repetitionIndex) {
908
+ var e_2, _a;
909
+ var realPath = [];
910
+ var pathObj = transformPathStringToObj(pathStr);
911
+ var currRepIndex = 0;
912
+ try {
913
+ for (var pathObj_1 = __values(pathObj), pathObj_1_1 = pathObj_1.next(); !pathObj_1_1.done; pathObj_1_1 = pathObj_1.next()) {
914
+ var part = pathObj_1_1.value;
915
+ if (typeof part === "symbol") {
916
+ if (!root.hasArrayTransition() ||
917
+ !repetitionIndex ||
918
+ currRepIndex > repetitionIndex.length) {
919
+ throw new Error("transition not found: pathStr ".concat(pathStr, " part ").concat(typeof part === "symbol" ? "[]" : part));
920
+ }
921
+ realPath.push(repetitionIndex[currRepIndex++]);
922
+ root = root.makeTransition(ARRAY_SYMBOL);
923
+ }
924
+ else {
925
+ if (!root.hasEdge(part)) {
926
+ throw new Error("transition not found: pathStr ".concat(pathStr, " part ").concat(typeof part === "symbol" ? "[]" : part));
927
+ }
928
+ realPath.push(part);
929
+ root = root.makeTransition(part);
930
+ }
931
+ }
932
+ }
933
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
934
+ finally {
935
+ try {
936
+ if (pathObj_1_1 && !pathObj_1_1.done && (_a = pathObj_1.return)) _a.call(pathObj_1);
937
+ }
938
+ finally { if (e_2) throw e_2.error; }
939
+ }
940
+ return {
941
+ node: root,
942
+ realPath: realPath,
943
+ };
944
944
  }
945
945
 
946
- function isNum$1(value) {
947
- return typeof value === "symbol" ? false : !isNaN(+value);
948
- }
949
- function canProxy(value) {
950
- return typeof value === "object" && value != null;
951
- }
952
- var proxyObjToStateCell = new WeakMap();
953
- var valtioSubscriptions = new WeakMap();
954
- function ensureStateCell(target, property, path, node) {
955
- var _a;
956
- if (!proxyObjToStateCell.has(target)) {
957
- proxyObjToStateCell.set(target, {});
958
- }
959
- var stateCell = proxyObjToStateCell.get(target);
960
- if (!(property in stateCell)) {
961
- stateCell[property] = {
962
- listeners: [],
963
- initialValue: UNINITIALIZED,
964
- path: path,
965
- node: node,
966
- initFunc: node.getSpec().initFunc,
967
- initFuncHash: (_a = node.getSpec().initFuncHash) !== null && _a !== void 0 ? _a : ""
968
- };
969
- }
970
- return stateCell[property];
971
- }
972
- function getStateCell(target, property) {
973
- var _a;
974
- return (_a = proxyObjToStateCell.get(target)) === null || _a === void 0 ? void 0 : _a[property];
975
- }
976
- function tryGetStateCellFrom$StateRoot($state, path) {
977
- if (path.length === 0) {
978
- throw new UnknownError("expected a path with length greater than 0");
979
- }
980
- var target = get($state, path.slice(0, -1));
981
- get(target, path.slice(-1)); // create state cell;
982
- return getStateCell(target, path.slice(-1)[0]);
983
- }
984
- function getStateCellFrom$StateRoot($state, path) {
985
- return ensure(tryGetStateCellFrom$StateRoot($state, path));
986
- }
987
- function unsubscribeToValtio($$state, statePath) {
988
- var _a;
989
- var oldValue = get($$state.stateValues, statePath);
990
- if (getVersion(oldValue)) {
991
- (_a = valtioSubscriptions.get(oldValue)) === null || _a === void 0 ? void 0 : _a.forEach(function (f) { return f(); });
992
- valtioSubscriptions["delete"](oldValue);
993
- }
994
- }
995
- function subscribeToValtio($$state, statePath, node) {
996
- var spec = node.getSpec();
997
- var maybeValtioProxy = spec.valueProp
998
- ? $$state.env.$props[spec.valueProp]
999
- : get($$state.stateValues, statePath);
1000
- if (getVersion(maybeValtioProxy) && spec.onChangeProp) {
1001
- var unsub = subscribe(maybeValtioProxy, function () {
1002
- var _a, _b;
1003
- (_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, spec.valueProp
1004
- ? $$state.env.$props[spec.valueProp]
1005
- : get($$state.stateValues, statePath));
1006
- });
1007
- if (!valtioSubscriptions.has(maybeValtioProxy)) {
1008
- valtioSubscriptions.set(maybeValtioProxy, []);
1009
- }
1010
- ensure(valtioSubscriptions.get(maybeValtioProxy)).push(unsub);
1011
- }
1012
- }
1013
- function initializeStateValue($$state, initialStateCell, proxyRoot) {
1014
- var _a, _b, _c;
1015
- var initialStateName = initialStateCell.node.getSpec().path;
1016
- var stateAccess = new Set();
1017
- $$state.stateInitializationEnv.visited.add(initialStateName);
1018
- $$state.stateInitializationEnv.stack.push(initialStateName);
1019
- var $state = create$StateProxy($$state, function (internalStateCell) { return ({
1020
- get: function () {
1021
- var spec = internalStateCell.node.getSpec();
1022
- if ($$state.stateInitializationEnv.visited.has(spec.path)) {
1023
- // cyclic reference found
1024
- var stateAccessCycle = [spec.path];
1025
- while ($$state.stateInitializationEnv.stack.length > 0) {
1026
- var curr = $$state.stateInitializationEnv.stack.pop();
1027
- if (!curr) {
1028
- break;
1029
- }
1030
- stateAccessCycle.push(curr);
1031
- if (curr === spec.path) {
1032
- throw new CyclicStatesReferencesError(stateAccessCycle);
1033
- }
1034
- }
1035
- throw new UnknownError("Internal error: cycle not found");
1036
- }
1037
- var stateCell = getStateCellFrom$StateRoot(proxyRoot, internalStateCell.path);
1038
- stateAccess.add({ stateCell: stateCell });
1039
- if (spec.valueProp) {
1040
- return $$state.env.$props[spec.valueProp];
1041
- }
1042
- else if (spec.initFunc && stateCell.initialValue === UNINITIALIZED) {
1043
- return initializeStateValue($$state, stateCell, proxyRoot);
1044
- }
1045
- return get(proxyRoot, stateCell.path);
1046
- },
1047
- set: function () {
1048
- throw new InvalidOperation("Cannot update state values during initialization");
1049
- }
1050
- }); });
1051
- stateAccess.forEach(function (_a) {
1052
- var stateCell = _a.stateCell;
1053
- stateCell.listeners.push(function () {
1054
- var _a;
1055
- var newValue = invokeInitFuncBackwardsCompatible(initialStateCell.node.getSpec().initFunc, __assign({ $state: $state }, ((_a = initialStateCell.overrideEnv) !== null && _a !== void 0 ? _a : $$state.env)));
1056
- set(proxyRoot, initialStateCell.path, newValue);
1057
- });
1058
- });
1059
- var initialValue = invokeInitFuncBackwardsCompatible(initialStateCell.initFunc, __assign({ $state: $state }, ((_a = initialStateCell.overrideEnv) !== null && _a !== void 0 ? _a : $$state.env)));
1060
- initialStateCell.initialValue = clone(initialValue);
1061
- var initialSpec = initialStateCell.node.getSpec();
1062
- var value = initialSpec.isImmutable
1063
- ? mkUntrackedValue(initialValue)
1064
- : clone(initialValue);
1065
- set(proxyRoot, initialStateCell.path, value);
1066
- //immediately fire onChange
1067
- if (initialSpec.onChangeProp) {
1068
- (_c = (_b = $$state.env.$props)[initialSpec.onChangeProp]) === null || _c === void 0 ? void 0 : _c.call(_b, initialValue);
1069
- }
1070
- $$state.stateInitializationEnv.visited["delete"](initialStateName);
1071
- $$state.stateInitializationEnv.stack.pop();
1072
- return initialValue;
1073
- }
1074
- function create$StateProxy($$state, leafHandlers) {
1075
- var proxyRoot;
1076
- var rec = function (currPath, currNode) {
1077
- var getNextPath = function (property) { return __spreadArray(__spreadArray([], __read(currPath), false), [
1078
- isNum$1(property) ? +property : property,
1079
- ], false); };
1080
- var spec = currNode.getSpec();
1081
- var handlers = {
1082
- deleteProperty: function (target, property) {
1083
- var _a, _b;
1084
- if (!currNode.isLeaf() &&
1085
- !currNode.hasArrayTransition() &&
1086
- !isNum$1(property)) {
1087
- throw new InvalidOperation("Can't delete a property in the middle of the state spec");
1088
- }
1089
- delete get($$state.stateValues, currPath)[property];
1090
- if (spec.onChangeProp) {
1091
- //we are always in a leaf, since we only have two cases:
1092
- // 1 - delete properties outside the state tree
1093
- // 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
1094
- (_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, get(proxyRoot, currPath.slice(spec.pathObj.length)));
1095
- }
1096
- return Reflect.deleteProperty(target, property);
1097
- },
1098
- get: function (target, property, receiver) {
1099
- var _a, _b;
1100
- if (property === PLASMIC_STATE_PROXY_SYMBOL) {
1101
- return {
1102
- node: currNode,
1103
- path: currPath
1104
- };
1105
- }
1106
- var nextPath = getNextPath(property);
1107
- var nextNode = currNode.makeTransition(property);
1108
- if (nextNode === null || nextNode === void 0 ? void 0 : nextNode.isLeaf()) {
1109
- return (_b = (_a = leafHandlers(ensureStateCell(receiver, property, nextPath, nextNode))).get) === null || _b === void 0 ? void 0 : _b.call(_a, target, property, receiver);
1110
- }
1111
- else if (nextNode && !(property in target)) {
1112
- target[property] = rec(nextPath, nextNode);
1113
- }
1114
- return Reflect.get(target, property, receiver);
1115
- },
1116
- set: function (target, property, value, receiver) {
1117
- var _a, _b, _c, _d;
1118
- var nextPath = getNextPath(property);
1119
- var nextNode = currNode.makeTransition(property);
1120
- var nextSpec = nextNode === null || nextNode === void 0 ? void 0 : nextNode.getSpec();
1121
- if (property === "registerInitFunc" && currPath.length === 0) {
1122
- return Reflect.set(target, property, value, receiver);
1123
- }
1124
- if (!nextNode && currNode.hasArrayTransition()) {
1125
- set($$state.stateValues, nextPath, value);
1126
- //array can set his own properties such as length, map, ...
1127
- return Reflect.set(target, property, value, receiver);
1128
- }
1129
- if (nextNode === null || nextNode === void 0 ? void 0 : nextNode.isLeaf()) {
1130
- (_b = (_a = leafHandlers(ensureStateCell(receiver, property, nextPath, nextNode))).set) === null || _b === void 0 ? void 0 : _b.call(_a, target, property, value, receiver);
1131
- Reflect.set(target, property, value, receiver);
1132
- if (nextSpec === null || nextSpec === void 0 ? void 0 : nextSpec.onChangeProp) {
1133
- (_d = (_c = $$state.env.$props)[nextSpec.onChangeProp]) === null || _d === void 0 ? void 0 : _d.call(_c, value);
1134
- }
1135
- }
1136
- if (!nextNode) {
1137
- // can't set an unknown field in $state
1138
- return false;
1139
- }
1140
- if (canProxy(value) && !nextNode.isLeaf()) {
1141
- target[property] = rec(nextPath, nextNode);
1142
- Reflect.ownKeys(value).forEach(function (key) {
1143
- target[property][key] = value[key];
1144
- });
1145
- }
1146
- else if (!nextNode.isLeaf()) {
1147
- throw new InvalidOperation("inserting a primitive value into a non-leaf");
1148
- }
1149
- var newValue = nextNode.isLeaf() && (nextSpec === null || nextSpec === void 0 ? void 0 : nextSpec.isImmutable)
1150
- ? mkUntrackedValue(value)
1151
- : value;
1152
- unsubscribeToValtio($$state, nextPath);
1153
- set($$state.stateValues, nextPath, newValue);
1154
- subscribeToValtio($$state, nextPath, nextNode);
1155
- return true;
1156
- }
1157
- };
1158
- var baseObject = currNode.hasArrayTransition() ? [] : {};
1159
- var proxyObj = new Proxy(baseObject, handlers);
1160
- if (currPath.length === 0) {
1161
- proxyRoot = proxyObj;
1162
- }
1163
- return proxyObj;
1164
- };
1165
- return rec([], $$state.rootSpecTree);
1166
- }
1167
- var mkUntrackedValue = function (o) {
1168
- return o != null && typeof o === "object" ? ref(o) : o;
1169
- };
1170
- var envFieldsAreNonNill = function (env) {
1171
- var _a, _b;
1172
- return ({
1173
- $props: env.$props,
1174
- $ctx: (_a = env.$ctx) !== null && _a !== void 0 ? _a : {},
1175
- $queries: (_b = env.$queries) !== null && _b !== void 0 ? _b : {}
1176
- });
1177
- };
1178
- /**
1179
- * We need to support two versions with different parameters to be backward compatible
1180
- * {
1181
- * specs: $StateSpec<any>[],
1182
- * props: Record<string, any>,
1183
- * $ctx?: Record<string, any>,
1184
- * opts?: { inCanvas: boolean; }
1185
- * }
1186
- * {
1187
- * specs: $StateSpec<any>[],
1188
- * env: { $props; $queries; $ctx },
1189
- * opts?: { inCanvas: boolean }
1190
- * }
1191
- */
1192
- function extractDollarStateParametersBackwardCompatible() {
1193
- var rest = [];
1194
- for (var _i = 0; _i < arguments.length; _i++) {
1195
- rest[_i] = arguments[_i];
1196
- }
1197
- if ("$props" in rest[0]) {
1198
- // latest version
1199
- return {
1200
- env: rest[0],
1201
- opts: rest[1]
1202
- };
1203
- }
1204
- else {
1205
- return {
1206
- env: {
1207
- $props: rest[0],
1208
- $ctx: rest[1],
1209
- $queries: {}
1210
- },
1211
- opts: rest[2]
1212
- };
1213
- }
1214
- }
1215
- function invokeInitFuncBackwardsCompatible(initFunc, env) {
1216
- if (initFunc.length > 1) {
1217
- return initFunc(env.$props, env.$state, env.$ctx);
1218
- }
1219
- else {
1220
- return initFunc(env);
1221
- }
1222
- }
1223
- function useDollarState(specs) {
1224
- var rest = [];
1225
- for (var _i = 1; _i < arguments.length; _i++) {
1226
- rest[_i - 1] = arguments[_i];
1227
- }
1228
- var _a = extractDollarStateParametersBackwardCompatible.apply(void 0, __spreadArray([], __read(rest), false)), env = _a.env, opts = _a.opts;
1229
- var $$state = React__default.useRef((function () {
1230
- var rootSpecTree = buildTree(specs);
1231
- return {
1232
- rootSpecTree: rootSpecTree,
1233
- specTreeLeaves: getSpecTreeLeaves(rootSpecTree),
1234
- stateValues: proxy({}),
1235
- env: envFieldsAreNonNill(env),
1236
- specs: [],
1237
- registrationsQueue: proxy([]),
1238
- stateInitializationEnv: { stack: [], visited: new Set() }
1239
- };
1240
- })()).current;
1241
- $$state.env = envFieldsAreNonNill(env);
1242
- $$state.specs = specs;
1243
- var create$State = React__default.useCallback(function () {
1244
- var $state = Object.assign(create$StateProxy($$state, function (stateCell) {
1245
- var spec = stateCell.node.getSpec();
1246
- if (stateCell.initialValue === UNINITIALIZED && spec.initFunc) {
1247
- initializeStateValue($$state, stateCell, $state);
1248
- }
1249
- else if (stateCell.initialValue === UNINITIALIZED &&
1250
- !spec.valueProp) {
1251
- stateCell.initialValue = spec.initVal;
1252
- set($state, stateCell.path, spec.initVal);
1253
- }
1254
- return {
1255
- get: function () {
1256
- var spec = stateCell.node.getSpec();
1257
- if (spec.valueProp) {
1258
- var valueProp = $$state.env.$props[spec.valueProp];
1259
- subscribeToValtio($$state, stateCell.path, stateCell.node);
1260
- return valueProp;
1261
- }
1262
- else {
1263
- return get($$state.stateValues, stateCell.path);
1264
- }
1265
- }
1266
- };
1267
- }), {
1268
- registerInitFunc: function (pathStr, f, repetitionIndex, overrideEnv) {
1269
- var _a = findStateCell($$state.rootSpecTree, pathStr, repetitionIndex), node = _a.node, realPath = _a.realPath;
1270
- var stateCell = getStateCellFrom$StateRoot($state, realPath);
1271
- var env = overrideEnv
1272
- ? envFieldsAreNonNill(overrideEnv)
1273
- : $$state.env;
1274
- if (!deepEqual(stateCell.initialValue, f(__assign({ $state: $state }, env)))) {
1275
- $$state.registrationsQueue.push(mkUntrackedValue({
1276
- node: node,
1277
- path: realPath,
1278
- f: f,
1279
- overrideEnv: overrideEnv
1280
- ? envFieldsAreNonNill(overrideEnv)
1281
- : undefined
1282
- }));
1283
- }
1284
- }
1285
- });
1286
- return $state;
1287
- }, []);
1288
- var ref = React__default.useRef(undefined);
1289
- if (!ref.current) {
1290
- ref.current = create$State();
1291
- }
1292
- var $state = ref.current;
1293
- if (opts === null || opts === void 0 ? void 0 : opts.inCanvas) {
1294
- $$state.rootSpecTree = updateTree($$state.rootSpecTree, specs);
1295
- var newLeaves = getSpecTreeLeaves($$state.rootSpecTree);
1296
- if (!arrayEq(newLeaves, $$state.specTreeLeaves)) {
1297
- var old$state_1 = $state;
1298
- $state = ref.current = create$State();
1299
- $$state.specTreeLeaves = newLeaves;
1300
- getStateCells(old$state_1, $$state.rootSpecTree).forEach(function (_a) {
1301
- var path = _a.path;
1302
- var oldStateCell = tryGetStateCellFrom$StateRoot(old$state_1, path);
1303
- if (oldStateCell) {
1304
- set($state, path, get(old$state_1, path));
1305
- var newStateCell = getStateCellFrom$StateRoot($state, path);
1306
- newStateCell.initialValue = oldStateCell.initialValue;
1307
- }
1308
- });
1309
- }
1310
- // we need to eager initialize all states in canvas to populate the data picker
1311
- $$state.specTreeLeaves.forEach(function (node) {
1312
- var _a, _b;
1313
- var spec = node.getSpec();
1314
- if (spec.isRepeated) {
1315
- return;
1316
- }
1317
- var stateCell = getStateCellFrom$StateRoot($state, spec.pathObj);
1318
- var newSpec = specs.find(function (sp) { return sp.path === spec.path; });
1319
- if (!newSpec ||
1320
- (stateCell.initFuncHash === ((_a = newSpec === null || newSpec === void 0 ? void 0 : newSpec.initFuncHash) !== null && _a !== void 0 ? _a : "") &&
1321
- stateCell.initialValue !== UNINITIALIZED)) {
1322
- return;
1323
- }
1324
- stateCell.initFunc = newSpec.initFunc;
1325
- stateCell.initFuncHash = (_b = newSpec.initFuncHash) !== null && _b !== void 0 ? _b : "";
1326
- var init = spec.valueProp
1327
- ? $$state.env.$props[spec.valueProp]
1328
- : spec.initFunc
1329
- ? initializeStateValue($$state, stateCell, $state)
1330
- : spec.initVal;
1331
- set($state, spec.pathObj, init);
1332
- });
1333
- }
1334
- // For each spec with an initFunc, evaluate it and see if
1335
- // the init value has changed. If so, reset its state.
1336
- var resetSpecs = [];
1337
- getStateCells($state, $$state.rootSpecTree).forEach(function (stateCell) {
1338
- var _a;
1339
- if (stateCell.initFunc) {
1340
- var newInit = invokeInitFuncBackwardsCompatible(stateCell.initFunc, __assign({ $state: $state }, ((_a = stateCell.overrideEnv) !== null && _a !== void 0 ? _a : envFieldsAreNonNill(env))));
1341
- if (!deepEqual(newInit, stateCell.initialValue)) {
1342
- resetSpecs.push({ stateCell: stateCell });
1343
- }
1344
- }
1345
- });
1346
- var reInitializeState = function (stateCell) {
1347
- var _a, _b;
1348
- var newInit = initializeStateValue($$state, stateCell, $state);
1349
- var spec = stateCell.node.getSpec();
1350
- if (spec.onChangeProp) {
1351
- (_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, newInit);
1352
- }
1353
- };
1354
- useIsomorphicLayoutEffect(function () {
1355
- resetSpecs.forEach(function (_a) {
1356
- var stateCell = _a.stateCell;
1357
- reInitializeState(stateCell);
1358
- });
1359
- }, [env.$props, resetSpecs]);
1360
- useIsomorphicLayoutEffect(function () {
1361
- while ($$state.registrationsQueue.length) {
1362
- var _a = $$state.registrationsQueue.shift(), path = _a.path, f = _a.f, overrideEnv = _a.overrideEnv;
1363
- var stateCell = getStateCellFrom$StateRoot($state, path);
1364
- stateCell.initFunc = f;
1365
- stateCell.overrideEnv = overrideEnv;
1366
- reInitializeState(stateCell);
1367
- }
1368
- }, [$$state.registrationsQueue.length]);
1369
- // immediately initialize exposed non-private states
1370
- useIsomorphicLayoutEffect(function () {
1371
- $$state.specTreeLeaves.forEach(function (node) {
1372
- var spec = node.getSpec();
1373
- if (!spec.isRepeated && spec.type !== "private" && spec.initFunc) {
1374
- var stateCell = getStateCellFrom$StateRoot($state, spec.pathObj);
1375
- initializeStateValue($$state, stateCell, $state);
1376
- }
1377
- });
1378
- }, []);
1379
- // Re-render if any value changed in one of these objects
1380
- useSnapshot($$state.stateValues, { sync: true });
1381
- useSnapshot($$state.registrationsQueue, { sync: true });
1382
- return $state;
946
+ function isNum$1(value) {
947
+ return typeof value === "symbol" ? false : !isNaN(+value);
948
+ }
949
+ function canProxy(value) {
950
+ return typeof value === "object" && value != null;
951
+ }
952
+ var proxyObjToStateCell = new WeakMap();
953
+ var valtioSubscriptions = new WeakMap();
954
+ function ensureStateCell(target, property, path, node) {
955
+ var _a;
956
+ if (!proxyObjToStateCell.has(target)) {
957
+ proxyObjToStateCell.set(target, {});
958
+ }
959
+ var stateCell = proxyObjToStateCell.get(target);
960
+ if (!(property in stateCell)) {
961
+ stateCell[property] = {
962
+ listeners: [],
963
+ initialValue: UNINITIALIZED,
964
+ path: path,
965
+ node: node,
966
+ initFunc: node.getSpec().initFunc,
967
+ initFuncHash: (_a = node.getSpec().initFuncHash) !== null && _a !== void 0 ? _a : "",
968
+ };
969
+ }
970
+ return stateCell[property];
971
+ }
972
+ function getStateCell(target, property) {
973
+ var _a;
974
+ return (_a = proxyObjToStateCell.get(target)) === null || _a === void 0 ? void 0 : _a[property];
975
+ }
976
+ function tryGetStateCellFrom$StateRoot($state, path) {
977
+ if (path.length === 0) {
978
+ throw new UnknownError("expected a path with length greater than 0");
979
+ }
980
+ var target = get($state, path.slice(0, -1));
981
+ get(target, path.slice(-1)); // create state cell;
982
+ return getStateCell(target, path.slice(-1)[0]);
983
+ }
984
+ function getStateCellFrom$StateRoot($state, path) {
985
+ return ensure(tryGetStateCellFrom$StateRoot($state, path));
986
+ }
987
+ function unsubscribeToValtio($$state, statePath) {
988
+ var _a;
989
+ var oldValue = get($$state.stateValues, statePath);
990
+ if (getVersion(oldValue)) {
991
+ (_a = valtioSubscriptions.get(oldValue)) === null || _a === void 0 ? void 0 : _a.forEach(function (f) { return f(); });
992
+ valtioSubscriptions.delete(oldValue);
993
+ }
994
+ }
995
+ function subscribeToValtio($$state, statePath, node) {
996
+ var spec = node.getSpec();
997
+ var maybeValtioProxy = spec.valueProp
998
+ ? $$state.env.$props[spec.valueProp]
999
+ : get($$state.stateValues, statePath);
1000
+ if (getVersion(maybeValtioProxy) && spec.onChangeProp) {
1001
+ var unsub = subscribe(maybeValtioProxy, function () {
1002
+ var _a, _b;
1003
+ (_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, spec.valueProp
1004
+ ? $$state.env.$props[spec.valueProp]
1005
+ : get($$state.stateValues, statePath));
1006
+ });
1007
+ if (!valtioSubscriptions.has(maybeValtioProxy)) {
1008
+ valtioSubscriptions.set(maybeValtioProxy, []);
1009
+ }
1010
+ ensure(valtioSubscriptions.get(maybeValtioProxy)).push(unsub);
1011
+ }
1012
+ }
1013
+ function initializeStateValue($$state, initialStateCell, proxyRoot) {
1014
+ var _a, _b, _c;
1015
+ var initialStateName = initialStateCell.node.getSpec().path;
1016
+ var stateAccess = new Set();
1017
+ $$state.stateInitializationEnv.visited.add(initialStateName);
1018
+ $$state.stateInitializationEnv.stack.push(initialStateName);
1019
+ var $state = create$StateProxy($$state, function (internalStateCell) { return ({
1020
+ get: function () {
1021
+ var spec = internalStateCell.node.getSpec();
1022
+ if ($$state.stateInitializationEnv.visited.has(spec.path)) {
1023
+ // cyclic reference found
1024
+ var stateAccessCycle = [spec.path];
1025
+ while ($$state.stateInitializationEnv.stack.length > 0) {
1026
+ var curr = $$state.stateInitializationEnv.stack.pop();
1027
+ if (!curr) {
1028
+ break;
1029
+ }
1030
+ stateAccessCycle.push(curr);
1031
+ if (curr === spec.path) {
1032
+ throw new CyclicStatesReferencesError(stateAccessCycle);
1033
+ }
1034
+ }
1035
+ throw new UnknownError("Internal error: cycle not found");
1036
+ }
1037
+ var stateCell = getStateCellFrom$StateRoot(proxyRoot, internalStateCell.path);
1038
+ stateAccess.add({ stateCell: stateCell });
1039
+ if (spec.valueProp) {
1040
+ return $$state.env.$props[spec.valueProp];
1041
+ }
1042
+ else if (spec.initFunc && stateCell.initialValue === UNINITIALIZED) {
1043
+ return initializeStateValue($$state, stateCell, proxyRoot);
1044
+ }
1045
+ return get(proxyRoot, stateCell.path);
1046
+ },
1047
+ set: function () {
1048
+ throw new InvalidOperation("Cannot update state values during initialization");
1049
+ },
1050
+ }); });
1051
+ stateAccess.forEach(function (_a) {
1052
+ var stateCell = _a.stateCell;
1053
+ stateCell.listeners.push(function () {
1054
+ var _a;
1055
+ var newValue = invokeInitFuncBackwardsCompatible(initialStateCell.node.getSpec().initFunc, __assign({ $state: $state }, ((_a = initialStateCell.overrideEnv) !== null && _a !== void 0 ? _a : $$state.env)));
1056
+ set(proxyRoot, initialStateCell.path, newValue);
1057
+ });
1058
+ });
1059
+ var initialValue = invokeInitFuncBackwardsCompatible(initialStateCell.initFunc, __assign({ $state: $state }, ((_a = initialStateCell.overrideEnv) !== null && _a !== void 0 ? _a : $$state.env)));
1060
+ initialStateCell.initialValue = clone(initialValue);
1061
+ var initialSpec = initialStateCell.node.getSpec();
1062
+ var value = initialSpec.isImmutable
1063
+ ? mkUntrackedValue(initialValue)
1064
+ : clone(initialValue);
1065
+ set(proxyRoot, initialStateCell.path, value);
1066
+ //immediately fire onChange
1067
+ if (initialSpec.onChangeProp) {
1068
+ (_c = (_b = $$state.env.$props)[initialSpec.onChangeProp]) === null || _c === void 0 ? void 0 : _c.call(_b, initialValue);
1069
+ }
1070
+ $$state.stateInitializationEnv.visited.delete(initialStateName);
1071
+ $$state.stateInitializationEnv.stack.pop();
1072
+ return initialValue;
1073
+ }
1074
+ function create$StateProxy($$state, leafHandlers) {
1075
+ var proxyRoot;
1076
+ var rec = function (currPath, currNode) {
1077
+ var getNextPath = function (property) { return __spreadArray(__spreadArray([], __read(currPath), false), [
1078
+ isNum$1(property) ? +property : property,
1079
+ ], false); };
1080
+ var spec = currNode.getSpec();
1081
+ var handlers = {
1082
+ deleteProperty: function (target, property) {
1083
+ var _a, _b;
1084
+ if (!currNode.isLeaf() &&
1085
+ !currNode.hasArrayTransition() &&
1086
+ !isNum$1(property)) {
1087
+ throw new InvalidOperation("Can't delete a property in the middle of the state spec");
1088
+ }
1089
+ delete get($$state.stateValues, currPath)[property];
1090
+ if (spec.onChangeProp) {
1091
+ //we are always in a leaf, since we only have two cases:
1092
+ // 1 - delete properties outside the state tree
1093
+ // 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
1094
+ (_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, get(proxyRoot, currPath.slice(spec.pathObj.length)));
1095
+ }
1096
+ return Reflect.deleteProperty(target, property);
1097
+ },
1098
+ get: function (target, property, receiver) {
1099
+ var _a, _b;
1100
+ if (property === PLASMIC_STATE_PROXY_SYMBOL) {
1101
+ return {
1102
+ node: currNode,
1103
+ path: currPath,
1104
+ };
1105
+ }
1106
+ var nextPath = getNextPath(property);
1107
+ var nextNode = currNode.makeTransition(property);
1108
+ if (nextNode === null || nextNode === void 0 ? void 0 : nextNode.isLeaf()) {
1109
+ return (_b = (_a = leafHandlers(ensureStateCell(receiver, property, nextPath, nextNode))).get) === null || _b === void 0 ? void 0 : _b.call(_a, target, property, receiver);
1110
+ }
1111
+ else if (nextNode && !(property in target)) {
1112
+ target[property] = rec(nextPath, nextNode);
1113
+ }
1114
+ return Reflect.get(target, property, receiver);
1115
+ },
1116
+ set: function (target, property, value, receiver) {
1117
+ var _a, _b, _c, _d;
1118
+ var nextPath = getNextPath(property);
1119
+ var nextNode = currNode.makeTransition(property);
1120
+ var nextSpec = nextNode === null || nextNode === void 0 ? void 0 : nextNode.getSpec();
1121
+ if (property === "registerInitFunc" && currPath.length === 0) {
1122
+ return Reflect.set(target, property, value, receiver);
1123
+ }
1124
+ if (!nextNode && currNode.hasArrayTransition()) {
1125
+ set($$state.stateValues, nextPath, value);
1126
+ //array can set his own properties such as length, map, ...
1127
+ return Reflect.set(target, property, value, receiver);
1128
+ }
1129
+ if (nextNode === null || nextNode === void 0 ? void 0 : nextNode.isLeaf()) {
1130
+ (_b = (_a = leafHandlers(ensureStateCell(receiver, property, nextPath, nextNode))).set) === null || _b === void 0 ? void 0 : _b.call(_a, target, property, value, receiver);
1131
+ Reflect.set(target, property, value, receiver);
1132
+ if (nextSpec === null || nextSpec === void 0 ? void 0 : nextSpec.onChangeProp) {
1133
+ (_d = (_c = $$state.env.$props)[nextSpec.onChangeProp]) === null || _d === void 0 ? void 0 : _d.call(_c, value);
1134
+ }
1135
+ }
1136
+ if (!nextNode) {
1137
+ // can't set an unknown field in $state
1138
+ return false;
1139
+ }
1140
+ if (canProxy(value) && !nextNode.isLeaf()) {
1141
+ target[property] = rec(nextPath, nextNode);
1142
+ Reflect.ownKeys(value).forEach(function (key) {
1143
+ target[property][key] = value[key];
1144
+ });
1145
+ }
1146
+ else if (!nextNode.isLeaf()) {
1147
+ throw new InvalidOperation("inserting a primitive value into a non-leaf");
1148
+ }
1149
+ var newValue = nextNode.isLeaf() && (nextSpec === null || nextSpec === void 0 ? void 0 : nextSpec.isImmutable)
1150
+ ? mkUntrackedValue(value)
1151
+ : value;
1152
+ unsubscribeToValtio($$state, nextPath);
1153
+ set($$state.stateValues, nextPath, newValue);
1154
+ subscribeToValtio($$state, nextPath, nextNode);
1155
+ return true;
1156
+ },
1157
+ };
1158
+ var baseObject = currNode.hasArrayTransition() ? [] : {};
1159
+ var proxyObj = new Proxy(baseObject, handlers);
1160
+ if (currPath.length === 0) {
1161
+ proxyRoot = proxyObj;
1162
+ }
1163
+ return proxyObj;
1164
+ };
1165
+ return rec([], $$state.rootSpecTree);
1166
+ }
1167
+ var mkUntrackedValue = function (o) {
1168
+ return o != null && typeof o === "object" ? ref(o) : o;
1169
+ };
1170
+ var envFieldsAreNonNill = function (env) {
1171
+ var _a, _b;
1172
+ return ({
1173
+ $props: env.$props,
1174
+ $ctx: (_a = env.$ctx) !== null && _a !== void 0 ? _a : {},
1175
+ $queries: (_b = env.$queries) !== null && _b !== void 0 ? _b : {},
1176
+ });
1177
+ };
1178
+ /**
1179
+ * We need to support two versions with different parameters to be backward compatible
1180
+ * {
1181
+ * specs: $StateSpec<any>[],
1182
+ * props: Record<string, any>,
1183
+ * $ctx?: Record<string, any>,
1184
+ * opts?: { inCanvas: boolean; }
1185
+ * }
1186
+ * {
1187
+ * specs: $StateSpec<any>[],
1188
+ * env: { $props; $queries; $ctx },
1189
+ * opts?: { inCanvas: boolean }
1190
+ * }
1191
+ */
1192
+ function extractDollarStateParametersBackwardCompatible() {
1193
+ var rest = [];
1194
+ for (var _i = 0; _i < arguments.length; _i++) {
1195
+ rest[_i] = arguments[_i];
1196
+ }
1197
+ if ("$props" in rest[0]) {
1198
+ // latest version
1199
+ return {
1200
+ env: rest[0],
1201
+ opts: rest[1],
1202
+ };
1203
+ }
1204
+ else {
1205
+ return {
1206
+ env: {
1207
+ $props: rest[0],
1208
+ $ctx: rest[1],
1209
+ $queries: {},
1210
+ },
1211
+ opts: rest[2],
1212
+ };
1213
+ }
1214
+ }
1215
+ function invokeInitFuncBackwardsCompatible(initFunc, env) {
1216
+ if (initFunc.length > 1) {
1217
+ return initFunc(env.$props, env.$state, env.$ctx);
1218
+ }
1219
+ else {
1220
+ return initFunc(env);
1221
+ }
1222
+ }
1223
+ function useDollarState(specs) {
1224
+ var rest = [];
1225
+ for (var _i = 1; _i < arguments.length; _i++) {
1226
+ rest[_i - 1] = arguments[_i];
1227
+ }
1228
+ var _a = extractDollarStateParametersBackwardCompatible.apply(void 0, __spreadArray([], __read(rest), false)), env = _a.env, opts = _a.opts;
1229
+ var $$state = React__default.useRef((function () {
1230
+ var rootSpecTree = buildTree(specs);
1231
+ return {
1232
+ rootSpecTree: rootSpecTree,
1233
+ specTreeLeaves: getSpecTreeLeaves(rootSpecTree),
1234
+ stateValues: proxy({}),
1235
+ env: envFieldsAreNonNill(env),
1236
+ specs: [],
1237
+ registrationsQueue: proxy([]),
1238
+ stateInitializationEnv: { stack: [], visited: new Set() },
1239
+ };
1240
+ })()).current;
1241
+ $$state.env = envFieldsAreNonNill(env);
1242
+ $$state.specs = specs;
1243
+ var create$State = React__default.useCallback(function () {
1244
+ var $state = Object.assign(create$StateProxy($$state, function (stateCell) {
1245
+ var spec = stateCell.node.getSpec();
1246
+ if (stateCell.initialValue === UNINITIALIZED && spec.initFunc) {
1247
+ initializeStateValue($$state, stateCell, $state);
1248
+ }
1249
+ else if (stateCell.initialValue === UNINITIALIZED &&
1250
+ !spec.valueProp) {
1251
+ stateCell.initialValue = spec.initVal;
1252
+ set($state, stateCell.path, spec.initVal);
1253
+ }
1254
+ return {
1255
+ get: function () {
1256
+ var spec = stateCell.node.getSpec();
1257
+ if (spec.valueProp) {
1258
+ var valueProp = $$state.env.$props[spec.valueProp];
1259
+ subscribeToValtio($$state, stateCell.path, stateCell.node);
1260
+ return valueProp;
1261
+ }
1262
+ else {
1263
+ return get($$state.stateValues, stateCell.path);
1264
+ }
1265
+ },
1266
+ };
1267
+ }), {
1268
+ registerInitFunc: function (pathStr, f, repetitionIndex, overrideEnv) {
1269
+ var _a = findStateCell($$state.rootSpecTree, pathStr, repetitionIndex), node = _a.node, realPath = _a.realPath;
1270
+ var stateCell = getStateCellFrom$StateRoot($state, realPath);
1271
+ var env = overrideEnv
1272
+ ? envFieldsAreNonNill(overrideEnv)
1273
+ : $$state.env;
1274
+ if (!deepEqual(stateCell.initialValue, f(__assign({ $state: $state }, env)))) {
1275
+ $$state.registrationsQueue.push(mkUntrackedValue({
1276
+ node: node,
1277
+ path: realPath,
1278
+ f: f,
1279
+ overrideEnv: overrideEnv
1280
+ ? envFieldsAreNonNill(overrideEnv)
1281
+ : undefined,
1282
+ }));
1283
+ }
1284
+ },
1285
+ });
1286
+ return $state;
1287
+ }, []);
1288
+ var ref = React__default.useRef(undefined);
1289
+ if (!ref.current) {
1290
+ ref.current = create$State();
1291
+ }
1292
+ var $state = ref.current;
1293
+ if (opts === null || opts === void 0 ? void 0 : opts.inCanvas) {
1294
+ $$state.rootSpecTree = updateTree($$state.rootSpecTree, specs);
1295
+ var newLeaves = getSpecTreeLeaves($$state.rootSpecTree);
1296
+ if (!arrayEq(newLeaves, $$state.specTreeLeaves)) {
1297
+ var old$state_1 = $state;
1298
+ $state = ref.current = create$State();
1299
+ $$state.specTreeLeaves = newLeaves;
1300
+ getStateCells(old$state_1, $$state.rootSpecTree).forEach(function (_a) {
1301
+ var path = _a.path;
1302
+ var oldStateCell = tryGetStateCellFrom$StateRoot(old$state_1, path);
1303
+ if (oldStateCell) {
1304
+ set($state, path, get(old$state_1, path));
1305
+ var newStateCell = getStateCellFrom$StateRoot($state, path);
1306
+ newStateCell.initialValue = oldStateCell.initialValue;
1307
+ }
1308
+ });
1309
+ }
1310
+ // we need to eager initialize all states in canvas to populate the data picker
1311
+ $$state.specTreeLeaves.forEach(function (node) {
1312
+ var _a, _b;
1313
+ var spec = node.getSpec();
1314
+ if (spec.isRepeated) {
1315
+ return;
1316
+ }
1317
+ var stateCell = getStateCellFrom$StateRoot($state, spec.pathObj);
1318
+ var newSpec = specs.find(function (sp) { return sp.path === spec.path; });
1319
+ if (!newSpec ||
1320
+ (stateCell.initFuncHash === ((_a = newSpec === null || newSpec === void 0 ? void 0 : newSpec.initFuncHash) !== null && _a !== void 0 ? _a : "") &&
1321
+ stateCell.initialValue !== UNINITIALIZED)) {
1322
+ return;
1323
+ }
1324
+ stateCell.initFunc = newSpec.initFunc;
1325
+ stateCell.initFuncHash = (_b = newSpec.initFuncHash) !== null && _b !== void 0 ? _b : "";
1326
+ var init = spec.valueProp
1327
+ ? $$state.env.$props[spec.valueProp]
1328
+ : spec.initFunc
1329
+ ? initializeStateValue($$state, stateCell, $state)
1330
+ : spec.initVal;
1331
+ set($state, spec.pathObj, init);
1332
+ });
1333
+ }
1334
+ // For each spec with an initFunc, evaluate it and see if
1335
+ // the init value has changed. If so, reset its state.
1336
+ var resetSpecs = [];
1337
+ getStateCells($state, $$state.rootSpecTree).forEach(function (stateCell) {
1338
+ var _a;
1339
+ if (stateCell.initFunc) {
1340
+ var newInit = invokeInitFuncBackwardsCompatible(stateCell.initFunc, __assign({ $state: $state }, ((_a = stateCell.overrideEnv) !== null && _a !== void 0 ? _a : envFieldsAreNonNill(env))));
1341
+ if (!deepEqual(newInit, stateCell.initialValue)) {
1342
+ resetSpecs.push({ stateCell: stateCell });
1343
+ }
1344
+ }
1345
+ });
1346
+ var reInitializeState = function (stateCell) {
1347
+ var _a, _b;
1348
+ var newInit = initializeStateValue($$state, stateCell, $state);
1349
+ var spec = stateCell.node.getSpec();
1350
+ if (spec.onChangeProp) {
1351
+ (_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, newInit);
1352
+ }
1353
+ };
1354
+ useIsomorphicLayoutEffect(function () {
1355
+ resetSpecs.forEach(function (_a) {
1356
+ var stateCell = _a.stateCell;
1357
+ reInitializeState(stateCell);
1358
+ });
1359
+ }, [env.$props, resetSpecs]);
1360
+ useIsomorphicLayoutEffect(function () {
1361
+ while ($$state.registrationsQueue.length) {
1362
+ var _a = $$state.registrationsQueue.shift(), path = _a.path, f = _a.f, overrideEnv = _a.overrideEnv;
1363
+ var stateCell = getStateCellFrom$StateRoot($state, path);
1364
+ stateCell.initFunc = f;
1365
+ stateCell.overrideEnv = overrideEnv;
1366
+ reInitializeState(stateCell);
1367
+ }
1368
+ }, [$$state.registrationsQueue.length]);
1369
+ // immediately initialize exposed non-private states
1370
+ useIsomorphicLayoutEffect(function () {
1371
+ $$state.specTreeLeaves.forEach(function (node) {
1372
+ var spec = node.getSpec();
1373
+ if (!spec.isRepeated && spec.type !== "private" && spec.initFunc) {
1374
+ var stateCell = getStateCellFrom$StateRoot($state, spec.pathObj);
1375
+ initializeStateValue($$state, stateCell, $state);
1376
+ }
1377
+ });
1378
+ }, []);
1379
+ // Re-render if any value changed in one of these objects
1380
+ useSnapshot($$state.stateValues, { sync: true });
1381
+ useSnapshot($$state.registrationsQueue, { sync: true });
1382
+ return $state;
1383
1383
  }
1384
1384
 
1385
- function initializeCodeComponentStates($state, states, repetitionIndex, componentHelpers, child$Props) {
1386
- var e_1, _a;
1387
- var _b, _c;
1388
- var stateHelpers = (_b = componentHelpers === null || componentHelpers === void 0 ? void 0 : componentHelpers.states) !== null && _b !== void 0 ? _b : {};
1389
- var _loop_1 = function (name_1, plasmicStateName) {
1390
- if (name_1 in stateHelpers && "initFunc" in stateHelpers[name_1]) {
1391
- (_c = $state.registerInitFunc) === null || _c === void 0 ? void 0 : _c.call($state, plasmicStateName, function (_a) {
1392
- var _b, _c;
1393
- var $props = _a.$props;
1394
- return (_c = (_b = stateHelpers[name_1]).initFunc) === null || _c === void 0 ? void 0 : _c.call(_b, $props);
1395
- }, repetitionIndex !== null && repetitionIndex !== void 0 ? repetitionIndex : [], { $props: child$Props });
1396
- }
1397
- };
1398
- try {
1399
- for (var states_1 = __values(states), states_1_1 = states_1.next(); !states_1_1.done; states_1_1 = states_1.next()) {
1400
- var _d = states_1_1.value, name_1 = _d.name, plasmicStateName = _d.plasmicStateName;
1401
- _loop_1(name_1, plasmicStateName);
1402
- }
1403
- }
1404
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1405
- finally {
1406
- try {
1407
- if (states_1_1 && !states_1_1.done && (_a = states_1["return"])) _a.call(states_1);
1408
- }
1409
- finally { if (e_1) throw e_1.error; }
1410
- }
1411
- }
1412
- function initializePlasmicStates($state, states, repetitionIndex) {
1413
- var e_2, _a;
1414
- var _b;
1415
- try {
1416
- for (var states_2 = __values(states), states_2_1 = states_2.next(); !states_2_1.done; states_2_1 = states_2.next()) {
1417
- var _c = states_2_1.value, name_2 = _c.name, initFunc = _c.initFunc;
1418
- (_b = $state.registerInitFunc) === null || _b === void 0 ? void 0 : _b.call($state, name_2, initFunc, repetitionIndex !== null && repetitionIndex !== void 0 ? repetitionIndex : []);
1419
- }
1420
- }
1421
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1422
- finally {
1423
- try {
1424
- if (states_2_1 && !states_2_1.done && (_a = states_2["return"])) _a.call(states_2);
1425
- }
1426
- finally { if (e_2) throw e_2.error; }
1427
- }
1428
- }
1429
- function generateStateOnChangeProp($state, path) {
1430
- return function (val) { return set($state, path, val); };
1431
- }
1432
- function generateStateOnChangePropForCodeComponents($state, stateName, plasmicStatePath, componentHelpers) {
1433
- var _a, _b;
1434
- var onChangeArgsToValue = (_b = (_a = componentHelpers === null || componentHelpers === void 0 ? void 0 : componentHelpers.states) === null || _a === void 0 ? void 0 : _a[stateName]) === null || _b === void 0 ? void 0 : _b.onChangeArgsToValue;
1435
- if (!onChangeArgsToValue || typeof onChangeArgsToValue !== "function") {
1436
- return generateStateOnChangeProp($state, plasmicStatePath);
1437
- }
1438
- return function () {
1439
- var args = [];
1440
- for (var _i = 0; _i < arguments.length; _i++) {
1441
- args[_i] = arguments[_i];
1442
- }
1443
- return generateStateOnChangeProp($state, plasmicStatePath)(onChangeArgsToValue.apply(null, args));
1444
- };
1445
- }
1446
- function generateStateValueProp($state, path) {
1447
- return get($state, path);
1448
- }
1449
- var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
1450
- function isPlasmicStateProxy(obj) {
1451
- return (obj != null && typeof obj === "object" && !!obj[PLASMIC_STATE_PROXY_SYMBOL]);
1452
- }
1453
- function is$StateProxy(obj) {
1454
- return (obj != null &&
1455
- typeof obj === "object" &&
1456
- (!!obj[PLASMIC_STATE_PROXY_SYMBOL] || getVersion(obj)));
1457
- }
1458
- function getStateCells($state, root) {
1459
- var e_3, _a;
1460
- var _b;
1461
- if ($state == null || typeof $state !== "object") {
1462
- return [];
1463
- }
1464
- if (root.hasArrayTransition()) {
1465
- return Object.keys($state).flatMap(function (key) {
1466
- return getStateCells($state[key], ensure(root.makeTransition(ARRAY_SYMBOL)));
1467
- });
1468
- }
1469
- else {
1470
- var stateCell = (_b = proxyObjToStateCell.get($state)) !== null && _b !== void 0 ? _b : {};
1471
- var stateCells = [];
1472
- try {
1473
- for (var _c = __values(root.edges().entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
1474
- var _e = __read(_d.value, 2), key = _e[0], child = _e[1];
1475
- if (typeof key === "string" && key in $state) {
1476
- stateCells.push.apply(stateCells, __spreadArray([], __read(getStateCells($state[key], child)), false));
1477
- if (key in stateCell) {
1478
- stateCells.push(stateCell[key]);
1479
- }
1480
- }
1481
- }
1482
- }
1483
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1484
- finally {
1485
- try {
1486
- if (_d && !_d.done && (_a = _c["return"])) _a.call(_c);
1487
- }
1488
- finally { if (e_3) throw e_3.error; }
1489
- }
1490
- return stateCells;
1491
- }
1492
- }
1493
- function getStateCellsInPlasmicProxy(obj) {
1494
- if (!isPlasmicStateProxy(obj)) {
1495
- return [];
1496
- }
1497
- var _a = obj[PLASMIC_STATE_PROXY_SYMBOL], rootNode = _a.node, rootPath = _a.path, isOutside = _a.isOutside;
1498
- if (isOutside) {
1499
- return [];
1500
- }
1501
- return getStateCells(obj, rootNode).map(function (stateCell) { return ({
1502
- path: stateCell.node.getSpec().path,
1503
- realPath: stateCell.path.slice(rootPath.length)
1504
- }); });
1505
- }
1506
- function getStateSpecInPlasmicProxy(obj, path) {
1507
- obj = get(obj, path.slice(0, path.length - 1));
1508
- if (!isPlasmicStateProxy(obj)) {
1509
- return undefined;
1510
- }
1511
- var node = obj[PLASMIC_STATE_PROXY_SYMBOL].node;
1512
- var nextNode = node.makeTransition(path[path.length - 1]);
1513
- if (node.isLeaf() || !nextNode) {
1514
- return undefined;
1515
- }
1516
- return {
1517
- spec: nextNode.getSpec(),
1518
- isImplicitStateArray: nextNode.hasArrayTransition()
1519
- };
1520
- }
1521
- function getCurrentInitialValue(obj, path) {
1522
- var _a;
1523
- if (!isPlasmicStateProxy(obj)) {
1524
- return undefined;
1525
- }
1526
- return (_a = tryGetStateCellFrom$StateRoot(obj, path)) === null || _a === void 0 ? void 0 : _a.initialValue;
1527
- }
1528
- function resetToInitialValue(obj, path) {
1529
- var stateCell = tryGetStateCellFrom$StateRoot(obj, path);
1530
- if (stateCell) {
1531
- set(obj, path, stateCell.initialValue);
1532
- }
1533
- }
1534
- function shallowEqual(a1, a2) {
1535
- if (a1.length !== a2.length) {
1536
- return false;
1537
- }
1538
- for (var i = 0; i < a1.length; i++) {
1539
- if (a1[i] !== a2[i]) {
1540
- return false;
1541
- }
1542
- }
1543
- return true;
1544
- }
1545
- /**
1546
- * Shallow comparison of arrays.
1547
- */
1548
- function arrayEq(xs, ys) {
1549
- return (xs.length === ys.length && xs.every(function (_, index) { return xs[index] === ys[index]; }));
1550
- }
1551
- function isNum(value) {
1552
- return typeof value === "symbol" ? false : !isNaN(+value);
1553
- }
1554
- /**
1555
- * Forked from https://github.com/lukeed/dset
1556
- * Changes: fixed setting a deep value to a proxy object
1557
- */
1558
- function set(obj, keys, val) {
1559
- keys = keys.split ? keys.split(".") : keys;
1560
- var i = 0, l = keys.length, t = obj, x, k;
1561
- while (i < l) {
1562
- k = keys[i++];
1563
- if (k === "__proto__" || k === "constructor" || k === "prototype")
1564
- break;
1565
- var newValue = i === l
1566
- ? val
1567
- : typeof (x = t[k]) === typeof keys
1568
- ? x
1569
- : keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")
1570
- ? {}
1571
- : [];
1572
- assignValue(t, k, newValue);
1573
- t = t[k];
1574
- }
1575
- }
1576
- /**
1577
- * Forked from lodash
1578
- */
1579
- function baseAssignValue(object, key, value) {
1580
- if (key == "__proto__") {
1581
- Object.defineProperty(object, key, {
1582
- configurable: true,
1583
- enumerable: true,
1584
- value: value,
1585
- writable: true
1586
- });
1587
- }
1588
- else {
1589
- object[key] = value;
1590
- }
1591
- }
1592
- function eq(value, other) {
1593
- return value === other || (value !== value && other !== other);
1594
- }
1595
- function assignValue(object, key, value) {
1596
- var objValue = object[key];
1597
- if (!(Object.prototype.hasOwnProperty.call(object, key) && eq(objValue, value)) ||
1598
- (value === undefined && !(key in object))) {
1599
- baseAssignValue(object, key, value);
1600
- }
1385
+ function initializeCodeComponentStates($state, states, repetitionIndex, componentHelpers, child$Props) {
1386
+ var e_1, _a;
1387
+ var _b, _c;
1388
+ var stateHelpers = (_b = componentHelpers === null || componentHelpers === void 0 ? void 0 : componentHelpers.states) !== null && _b !== void 0 ? _b : {};
1389
+ var _loop_1 = function (name_1, plasmicStateName) {
1390
+ if (name_1 in stateHelpers && "initFunc" in stateHelpers[name_1]) {
1391
+ (_c = $state.registerInitFunc) === null || _c === void 0 ? void 0 : _c.call($state, plasmicStateName, function (_a) {
1392
+ var _b, _c;
1393
+ var $props = _a.$props;
1394
+ return (_c = (_b = stateHelpers[name_1]).initFunc) === null || _c === void 0 ? void 0 : _c.call(_b, $props);
1395
+ }, repetitionIndex !== null && repetitionIndex !== void 0 ? repetitionIndex : [], { $props: child$Props });
1396
+ }
1397
+ };
1398
+ try {
1399
+ for (var states_1 = __values(states), states_1_1 = states_1.next(); !states_1_1.done; states_1_1 = states_1.next()) {
1400
+ var _d = states_1_1.value, name_1 = _d.name, plasmicStateName = _d.plasmicStateName;
1401
+ _loop_1(name_1, plasmicStateName);
1402
+ }
1403
+ }
1404
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1405
+ finally {
1406
+ try {
1407
+ if (states_1_1 && !states_1_1.done && (_a = states_1.return)) _a.call(states_1);
1408
+ }
1409
+ finally { if (e_1) throw e_1.error; }
1410
+ }
1411
+ }
1412
+ function initializePlasmicStates($state, states, repetitionIndex) {
1413
+ var e_2, _a;
1414
+ var _b;
1415
+ try {
1416
+ for (var states_2 = __values(states), states_2_1 = states_2.next(); !states_2_1.done; states_2_1 = states_2.next()) {
1417
+ var _c = states_2_1.value, name_2 = _c.name, initFunc = _c.initFunc;
1418
+ (_b = $state.registerInitFunc) === null || _b === void 0 ? void 0 : _b.call($state, name_2, initFunc, repetitionIndex !== null && repetitionIndex !== void 0 ? repetitionIndex : []);
1419
+ }
1420
+ }
1421
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1422
+ finally {
1423
+ try {
1424
+ if (states_2_1 && !states_2_1.done && (_a = states_2.return)) _a.call(states_2);
1425
+ }
1426
+ finally { if (e_2) throw e_2.error; }
1427
+ }
1428
+ }
1429
+ function generateStateOnChangeProp($state, path) {
1430
+ return function (val) { return set($state, path, val); };
1431
+ }
1432
+ function generateStateOnChangePropForCodeComponents($state, stateName, plasmicStatePath, componentHelpers) {
1433
+ var _a, _b;
1434
+ var onChangeArgsToValue = (_b = (_a = componentHelpers === null || componentHelpers === void 0 ? void 0 : componentHelpers.states) === null || _a === void 0 ? void 0 : _a[stateName]) === null || _b === void 0 ? void 0 : _b.onChangeArgsToValue;
1435
+ if (!onChangeArgsToValue || typeof onChangeArgsToValue !== "function") {
1436
+ return generateStateOnChangeProp($state, plasmicStatePath);
1437
+ }
1438
+ return function () {
1439
+ var args = [];
1440
+ for (var _i = 0; _i < arguments.length; _i++) {
1441
+ args[_i] = arguments[_i];
1442
+ }
1443
+ return generateStateOnChangeProp($state, plasmicStatePath)(onChangeArgsToValue.apply(null, args));
1444
+ };
1445
+ }
1446
+ function generateStateValueProp($state, path) {
1447
+ return get($state, path);
1448
+ }
1449
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
1450
+ function isPlasmicStateProxy(obj) {
1451
+ return (obj != null && typeof obj === "object" && !!obj[PLASMIC_STATE_PROXY_SYMBOL]);
1452
+ }
1453
+ function is$StateProxy(obj) {
1454
+ return (obj != null &&
1455
+ typeof obj === "object" &&
1456
+ (!!obj[PLASMIC_STATE_PROXY_SYMBOL] || getVersion(obj)));
1457
+ }
1458
+ function getStateCells($state, root) {
1459
+ var e_3, _a;
1460
+ var _b;
1461
+ if ($state == null || typeof $state !== "object") {
1462
+ return [];
1463
+ }
1464
+ if (root.hasArrayTransition()) {
1465
+ return Object.keys($state).flatMap(function (key) {
1466
+ return getStateCells($state[key], ensure(root.makeTransition(ARRAY_SYMBOL)));
1467
+ });
1468
+ }
1469
+ else {
1470
+ var stateCell = (_b = proxyObjToStateCell.get($state)) !== null && _b !== void 0 ? _b : {};
1471
+ var stateCells = [];
1472
+ try {
1473
+ for (var _c = __values(root.edges().entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
1474
+ var _e = __read(_d.value, 2), key = _e[0], child = _e[1];
1475
+ if (typeof key === "string" && key in $state) {
1476
+ stateCells.push.apply(stateCells, __spreadArray([], __read(getStateCells($state[key], child)), false));
1477
+ if (key in stateCell) {
1478
+ stateCells.push(stateCell[key]);
1479
+ }
1480
+ }
1481
+ }
1482
+ }
1483
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1484
+ finally {
1485
+ try {
1486
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1487
+ }
1488
+ finally { if (e_3) throw e_3.error; }
1489
+ }
1490
+ return stateCells;
1491
+ }
1492
+ }
1493
+ function getStateCellsInPlasmicProxy(obj) {
1494
+ if (!isPlasmicStateProxy(obj)) {
1495
+ return [];
1496
+ }
1497
+ var _a = obj[PLASMIC_STATE_PROXY_SYMBOL], rootNode = _a.node, rootPath = _a.path, isOutside = _a.isOutside;
1498
+ if (isOutside) {
1499
+ return [];
1500
+ }
1501
+ return getStateCells(obj, rootNode).map(function (stateCell) { return ({
1502
+ path: stateCell.node.getSpec().path,
1503
+ realPath: stateCell.path.slice(rootPath.length),
1504
+ }); });
1505
+ }
1506
+ function getStateSpecInPlasmicProxy(obj, path) {
1507
+ obj = get(obj, path.slice(0, path.length - 1));
1508
+ if (!isPlasmicStateProxy(obj)) {
1509
+ return undefined;
1510
+ }
1511
+ var node = obj[PLASMIC_STATE_PROXY_SYMBOL].node;
1512
+ var nextNode = node.makeTransition(path[path.length - 1]);
1513
+ if (node.isLeaf() || !nextNode) {
1514
+ return undefined;
1515
+ }
1516
+ return {
1517
+ spec: nextNode.getSpec(),
1518
+ isImplicitStateArray: nextNode.hasArrayTransition(),
1519
+ };
1520
+ }
1521
+ function getCurrentInitialValue(obj, path) {
1522
+ var _a;
1523
+ if (!isPlasmicStateProxy(obj)) {
1524
+ return undefined;
1525
+ }
1526
+ return (_a = tryGetStateCellFrom$StateRoot(obj, path)) === null || _a === void 0 ? void 0 : _a.initialValue;
1527
+ }
1528
+ function resetToInitialValue(obj, path) {
1529
+ var stateCell = tryGetStateCellFrom$StateRoot(obj, path);
1530
+ if (stateCell) {
1531
+ set(obj, path, stateCell.initialValue);
1532
+ }
1533
+ }
1534
+ function shallowEqual(a1, a2) {
1535
+ if (a1.length !== a2.length) {
1536
+ return false;
1537
+ }
1538
+ for (var i = 0; i < a1.length; i++) {
1539
+ if (a1[i] !== a2[i]) {
1540
+ return false;
1541
+ }
1542
+ }
1543
+ return true;
1544
+ }
1545
+ /**
1546
+ * Shallow comparison of arrays.
1547
+ */
1548
+ function arrayEq(xs, ys) {
1549
+ return (xs.length === ys.length && xs.every(function (_, index) { return xs[index] === ys[index]; }));
1550
+ }
1551
+ function isNum(value) {
1552
+ return typeof value === "symbol" ? false : !isNaN(+value);
1553
+ }
1554
+ /**
1555
+ * Forked from https://github.com/lukeed/dset
1556
+ * Changes: fixed setting a deep value to a proxy object
1557
+ */
1558
+ function set(obj, keys, val) {
1559
+ keys = keys.split ? keys.split(".") : keys;
1560
+ var i = 0, l = keys.length, t = obj, x, k;
1561
+ while (i < l) {
1562
+ k = keys[i++];
1563
+ if (k === "__proto__" || k === "constructor" || k === "prototype")
1564
+ break;
1565
+ var newValue = i === l
1566
+ ? val
1567
+ : typeof (x = t[k]) === typeof keys
1568
+ ? x
1569
+ : keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")
1570
+ ? {}
1571
+ : [];
1572
+ assignValue(t, k, newValue);
1573
+ t = t[k];
1574
+ }
1575
+ }
1576
+ /**
1577
+ * Forked from lodash
1578
+ */
1579
+ function baseAssignValue(object, key, value) {
1580
+ if (key == "__proto__") {
1581
+ Object.defineProperty(object, key, {
1582
+ configurable: true,
1583
+ enumerable: true,
1584
+ value: value,
1585
+ writable: true,
1586
+ });
1587
+ }
1588
+ else {
1589
+ object[key] = value;
1590
+ }
1591
+ }
1592
+ function eq(value, other) {
1593
+ return value === other || (value !== value && other !== other);
1594
+ }
1595
+ function assignValue(object, key, value) {
1596
+ var objValue = object[key];
1597
+ if (!(Object.prototype.hasOwnProperty.call(object, key) && eq(objValue, value)) ||
1598
+ (value === undefined && !(key in object))) {
1599
+ baseAssignValue(object, key, value);
1600
+ }
1601
1601
  }
1602
1602
 
1603
- // Utilities used by generated code
1603
+ // Utilities used by generated code
1604
1604
  var classNames = classNames$1;
1605
1605
 
1606
1606
  export { PlasmicIcon, PlasmicLink, PlasmicPageGuard, PlasmicSlot, Stack, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, generateStateOnChangeProp, generateStateOnChangePropForCodeComponents, generateStateValueProp, getCurrentInitialValue, getStateCellsInPlasmicProxy, getStateSpecInPlasmicProxy, hasVariant, initializeCodeComponentStates, initializePlasmicStates, is$StateProxy, isPlasmicStateProxy, makeFragment, mergeVariantsWithStates, renderPlasmicSlot, resetToInitialValue, set, useDollarState, useTrigger, withPlasmicPageGuard, wrapWithClassName };