@plasmicapp/react-web 0.2.196 → 0.2.198

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 (70) hide show
  1. package/dist/index.cjs.js +3715 -0
  2. package/dist/index.cjs.js.map +1 -0
  3. package/dist/plume/button/index.d.ts +4 -4
  4. package/dist/plume/checkbox/index.d.ts +1 -1
  5. package/dist/plume/collection-utils.d.ts +7 -7
  6. package/dist/plume/collection-utils.spec.d.ts +1 -0
  7. package/dist/plume/menu/menu.d.ts +1 -1
  8. package/dist/plume/menu-button/menu-button.d.ts +1 -1
  9. package/dist/plume/menu-button/menu-trigger.d.ts +1 -1
  10. package/dist/plume/plume-utils.d.ts +13 -13
  11. package/dist/plume/select/select-option.d.ts +1 -1
  12. package/dist/plume/select/select.d.ts +1 -1
  13. package/dist/plume/switch/index.d.ts +1 -1
  14. package/dist/plume/text-input/index.d.ts +1 -1
  15. package/dist/plume/triggered-overlay/triggered-overlay.d.ts +1 -1
  16. package/dist/react-utils.d.ts +3 -3
  17. package/dist/react-utils.spec.d.ts +1 -0
  18. package/dist/react-web.esm.js +3485 -4538
  19. package/dist/react-web.esm.js.map +1 -1
  20. package/dist/render/PlasmicHead/index.d.ts +2 -2
  21. package/dist/render/PlasmicImg/index.d.ts +1 -1
  22. package/dist/render/Stack.d.ts +1 -1
  23. package/dist/render/elements.d.ts +12 -12
  24. package/dist/render/screen-variants.d.ts +1 -1
  25. package/dist/render/translation.d.ts +2 -2
  26. package/dist/render/triggers.d.ts +1 -1
  27. package/dist/states/helpers.d.ts +1 -1
  28. package/dist/states/types.d.ts +6 -6
  29. package/dist/stories/PlasmicImg.stories.d.ts +3 -2
  30. package/dist/stories/UseDollarState.stories.d.ts +23 -22
  31. package/package.json +17 -44
  32. package/skinny/dist/{collection-utils-0967eaf0.js → collection-utils-33d43bc0.js} +5 -4
  33. package/skinny/dist/{collection-utils-0967eaf0.js.map → collection-utils-33d43bc0.js.map} +1 -1
  34. package/skinny/dist/common-dc5a84e8.js +135 -0
  35. package/skinny/dist/common-dc5a84e8.js.map +1 -0
  36. package/skinny/dist/index.js +4 -3
  37. package/skinny/dist/index.js.map +1 -1
  38. package/skinny/dist/plume/button/index.js +3 -2
  39. package/skinny/dist/plume/button/index.js.map +1 -1
  40. package/skinny/dist/plume/checkbox/index.js +5 -4
  41. package/skinny/dist/plume/checkbox/index.js.map +1 -1
  42. package/skinny/dist/plume/menu/index.js +6 -5
  43. package/skinny/dist/plume/menu/index.js.map +1 -1
  44. package/skinny/dist/plume/menu-button/index.js +5 -4
  45. package/skinny/dist/plume/menu-button/index.js.map +1 -1
  46. package/skinny/dist/plume/select/index.js +6 -5
  47. package/skinny/dist/plume/select/index.js.map +1 -1
  48. package/skinny/dist/plume/switch/index.js +5 -4
  49. package/skinny/dist/plume/switch/index.js.map +1 -1
  50. package/skinny/dist/plume/text-input/index.js +3 -2
  51. package/skinny/dist/plume/text-input/index.js.map +1 -1
  52. package/skinny/dist/plume/triggered-overlay/index.js +5 -4
  53. package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
  54. package/skinny/dist/{plume-utils-7d68bcc0.js → plume-utils-83879d02.js} +2 -2
  55. package/skinny/dist/{plume-utils-7d68bcc0.js.map → plume-utils-83879d02.js.map} +1 -1
  56. package/skinny/dist/props-utils-1c39261f.js +9 -0
  57. package/skinny/dist/{props-utils-9f9c761a.js.map → props-utils-1c39261f.js.map} +1 -1
  58. package/skinny/dist/{react-utils-ee4e03ba.js → react-utils-898d19d0.js} +2 -2
  59. package/skinny/dist/{react-utils-ee4e03ba.js.map → react-utils-898d19d0.js.map} +1 -1
  60. package/skinny/dist/render/PlasmicImg/index.js +3 -2
  61. package/skinny/dist/render/PlasmicImg/index.js.map +1 -1
  62. package/dist/all.d.ts +0 -13357
  63. package/dist/index.js +0 -8
  64. package/dist/react-web.cjs.development.js +0 -4737
  65. package/dist/react-web.cjs.development.js.map +0 -1
  66. package/dist/react-web.cjs.production.min.js +0 -2
  67. package/dist/react-web.cjs.production.min.js.map +0 -1
  68. package/skinny/dist/common-9d6d348d.js +0 -264
  69. package/skinny/dist/common-9d6d348d.js.map +0 -1
  70. package/skinny/dist/props-utils-9f9c761a.js +0 -8
@@ -0,0 +1,3715 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var classNames$1 = require('classnames');
7
+ var tslib = require('tslib');
8
+ var dataSourcesContext = require('@plasmicapp/data-sources-context');
9
+ var React = require('react');
10
+ var get = require('dlv');
11
+ var ReactDOM = require('react-dom');
12
+ var ssr = require('@react-aria/ssr');
13
+ var focus = require('@react-aria/focus');
14
+ var valtio = require('valtio');
15
+ var clone = require('clone');
16
+ var deepEqual = require('fast-deep-equal');
17
+ var checkbox = require('@react-aria/checkbox');
18
+ var visuallyHidden = require('@react-aria/visually-hidden');
19
+ var toggle = require('@react-stately/toggle');
20
+ var menu = require('@react-aria/menu');
21
+ var tree = require('@react-stately/tree');
22
+ var collections = require('@react-stately/collections');
23
+ var separator = require('@react-aria/separator');
24
+ var menu$1 = require('@react-stately/menu');
25
+ var interactions = require('@react-aria/interactions');
26
+ var host = require('@plasmicapp/host');
27
+ var listbox = require('@react-aria/listbox');
28
+ var select$1 = require('@react-aria/select');
29
+ var select = require('@react-stately/select');
30
+ var _switch = require('@react-aria/switch');
31
+ var overlays = require('@react-aria/overlays');
32
+
33
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
34
+
35
+ function _interopNamespace(e) {
36
+ if (e && e.__esModule) return e;
37
+ var n = Object.create(null);
38
+ if (e) {
39
+ Object.keys(e).forEach(function (k) {
40
+ if (k !== 'default') {
41
+ var d = Object.getOwnPropertyDescriptor(e, k);
42
+ Object.defineProperty(n, k, d.get ? d : {
43
+ enumerable: true,
44
+ get: function () {
45
+ return e[k];
46
+ }
47
+ });
48
+ }
49
+ });
50
+ }
51
+ n['default'] = e;
52
+ return Object.freeze(n);
53
+ }
54
+
55
+ var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames$1);
56
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
57
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
58
+ var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
59
+ var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
60
+ var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
61
+ var clone__default = /*#__PURE__*/_interopDefaultLegacy(clone);
62
+ var deepEqual__default = /*#__PURE__*/_interopDefaultLegacy(deepEqual);
63
+
64
+ // https://stackoverflow.com/a/2117523
65
+ function uuidv4() {
66
+ // @ts-ignore
67
+ return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
68
+ return (c ^
69
+ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16);
70
+ });
71
+ }
72
+ function triggerLogin(appId, authorizeEndpoint, redirectUri) {
73
+ return tslib.__awaiter(this, void 0, void 0, function () {
74
+ function sha256(text) {
75
+ return tslib.__awaiter(this, void 0, void 0, function () {
76
+ var encoder, data, hashBuffer, hashArray, hashHex;
77
+ return tslib.__generator(this, function (_a) {
78
+ switch (_a.label) {
79
+ case 0:
80
+ encoder = new TextEncoder();
81
+ data = encoder.encode(text);
82
+ return [4 /*yield*/, crypto.subtle.digest("SHA-256", data)];
83
+ case 1:
84
+ hashBuffer = _a.sent();
85
+ hashArray = Array.from(new Uint8Array(hashBuffer));
86
+ hashHex = hashArray
87
+ .map(function (b) { return b.toString(16).padStart(2, "0"); })
88
+ .join("");
89
+ return [2 /*return*/, hashHex];
90
+ }
91
+ });
92
+ });
93
+ }
94
+ var continueTo, state, code_verifier, code_challenge, params, url;
95
+ return tslib.__generator(this, function (_a) {
96
+ switch (_a.label) {
97
+ case 0:
98
+ continueTo = window.location.href;
99
+ state = JSON.stringify({ continueTo: continueTo });
100
+ code_verifier = uuidv4();
101
+ localStorage.setItem("code_verifier", code_verifier);
102
+ return [4 /*yield*/, sha256(code_verifier)];
103
+ case 1:
104
+ code_challenge = _a.sent();
105
+ params = new URLSearchParams();
106
+ params.set("client_id", appId);
107
+ params.set("state", state);
108
+ params.set("response_type", "code");
109
+ params.set("code_challenge", code_challenge);
110
+ params.set("code_challenge_method", "S256");
111
+ if (redirectUri) {
112
+ params.set("redirect_uri", redirectUri);
113
+ }
114
+ url = "".concat(authorizeEndpoint, "?").concat(params.toString());
115
+ window.location.href = url;
116
+ return [2 /*return*/];
117
+ }
118
+ });
119
+ });
120
+ }
121
+ function PlasmicPageGuard(props) {
122
+ var appId = props.appId, authorizeEndpoint = props.authorizeEndpoint, minRole = props.minRole, canTriggerLogin = props.canTriggerLogin, children = props.children;
123
+ var dataSourceCtxValue = dataSourcesContext.usePlasmicDataSourceContext();
124
+ React__default['default'].useEffect(function () {
125
+ if (canTriggerLogin) {
126
+ if (minRole &&
127
+ dataSourceCtxValue &&
128
+ "isUserLoading" in dataSourceCtxValue &&
129
+ !dataSourceCtxValue.isUserLoading &&
130
+ !dataSourceCtxValue.user) {
131
+ triggerLogin(appId, authorizeEndpoint, dataSourceCtxValue.authRedirectUri);
132
+ }
133
+ }
134
+ }, [dataSourceCtxValue, appId, authorizeEndpoint, canTriggerLogin, minRole]);
135
+ function canUserViewPage() {
136
+ if (!minRole) {
137
+ return true;
138
+ }
139
+ if (!dataSourceCtxValue) {
140
+ return false;
141
+ }
142
+ if (!dataSourceCtxValue.user) {
143
+ return false;
144
+ }
145
+ if (!("roleIds" in dataSourceCtxValue.user)) {
146
+ return false;
147
+ }
148
+ if (!Array.isArray(dataSourceCtxValue.user.roleIds)) {
149
+ return false;
150
+ }
151
+ return dataSourceCtxValue.user.roleIds.includes(minRole);
152
+ }
153
+ if (!dataSourceCtxValue ||
154
+ dataSourceCtxValue.isUserLoading ||
155
+ (!dataSourceCtxValue.user && minRole && canTriggerLogin)) {
156
+ return null;
157
+ }
158
+ if (!canUserViewPage()) {
159
+ return React__default['default'].createElement("div", null, "You don't have access to this page");
160
+ }
161
+ return React__default['default'].createElement(React__default['default'].Fragment, null, children);
162
+ }
163
+ function withPlasmicPageGuard(WrappedComponent, options) {
164
+ var PageGuard = function (props) { return (React__default['default'].createElement(PlasmicPageGuard, tslib.__assign({}, options),
165
+ React__default['default'].createElement(WrappedComponent, tslib.__assign({}, props)))); };
166
+ return PageGuard;
167
+ }
168
+
169
+ function notNil(x) {
170
+ return x != null;
171
+ }
172
+ function pick(obj) {
173
+ var e_1, _a;
174
+ var keys = [];
175
+ for (var _i = 1; _i < arguments.length; _i++) {
176
+ keys[_i - 1] = arguments[_i];
177
+ }
178
+ if (Object.keys(obj).length === 0) {
179
+ return obj;
180
+ }
181
+ var res = {};
182
+ try {
183
+ for (var keys_1 = tslib.__values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
184
+ var key = keys_1_1.value;
185
+ if (key in obj) {
186
+ res[key] = obj[key];
187
+ }
188
+ }
189
+ }
190
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
191
+ finally {
192
+ try {
193
+ if (keys_1_1 && !keys_1_1.done && (_a = keys_1["return"])) _a.call(keys_1);
194
+ }
195
+ finally { if (e_1) throw e_1.error; }
196
+ }
197
+ return res;
198
+ }
199
+ function pickBy(obj, func) {
200
+ var e_2, _a;
201
+ var res = {};
202
+ try {
203
+ for (var _b = tslib.__values(Object.entries(obj)), _c = _b.next(); !_c.done; _c = _b.next()) {
204
+ var _d = tslib.__read(_c.value, 2), key = _d[0], val = _d[1];
205
+ if (func(key, val)) {
206
+ res[key] = obj[key];
207
+ }
208
+ }
209
+ }
210
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
211
+ finally {
212
+ try {
213
+ if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
214
+ }
215
+ finally { if (e_2) throw e_2.error; }
216
+ }
217
+ return res;
218
+ }
219
+ function omit(obj) {
220
+ var e_3, _a;
221
+ var keys = [];
222
+ for (var _i = 1; _i < arguments.length; _i++) {
223
+ keys[_i - 1] = arguments[_i];
224
+ }
225
+ if (Object.keys(obj).length === 0) {
226
+ return obj;
227
+ }
228
+ var res = {};
229
+ try {
230
+ for (var _b = tslib.__values(Object.keys(obj)), _c = _b.next(); !_c.done; _c = _b.next()) {
231
+ var key = _c.value;
232
+ if (!keys.includes(key)) {
233
+ res[key] = obj[key];
234
+ }
235
+ }
236
+ }
237
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
238
+ finally {
239
+ try {
240
+ if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
241
+ }
242
+ finally { if (e_3) throw e_3.error; }
243
+ }
244
+ return res;
245
+ }
246
+ function isSubset(a1, a2) {
247
+ return a1.every(function (x) { return a2.includes(x); });
248
+ }
249
+ function chainSingleArgFuncs() {
250
+ var funcs = [];
251
+ for (var _i = 0; _i < arguments.length; _i++) {
252
+ funcs[_i] = arguments[_i];
253
+ }
254
+ if (funcs.length === 0) {
255
+ return undefined;
256
+ }
257
+ return function (arg) {
258
+ var e_4, _a;
259
+ var res = arg;
260
+ try {
261
+ for (var funcs_1 = tslib.__values(funcs), funcs_1_1 = funcs_1.next(); !funcs_1_1.done; funcs_1_1 = funcs_1.next()) {
262
+ var func = funcs_1_1.value;
263
+ res = func(res);
264
+ }
265
+ }
266
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
267
+ finally {
268
+ try {
269
+ if (funcs_1_1 && !funcs_1_1.done && (_a = funcs_1["return"])) _a.call(funcs_1);
270
+ }
271
+ finally { if (e_4) throw e_4.error; }
272
+ }
273
+ return res;
274
+ };
275
+ }
276
+ function ensure(x) {
277
+ if (x === null || x === undefined) {
278
+ debugger;
279
+ throw new Error("Value must not be undefined or null");
280
+ }
281
+ else {
282
+ return x;
283
+ }
284
+ }
285
+ function isString(x) {
286
+ return typeof x === "string";
287
+ }
288
+ function groupBy(collection, keyFunc) {
289
+ var e_5, _a;
290
+ var result = {};
291
+ try {
292
+ for (var collection_1 = tslib.__values(collection), collection_1_1 = collection_1.next(); !collection_1_1.done; collection_1_1 = collection_1.next()) {
293
+ var obj = collection_1_1.value;
294
+ var key = keyFunc(obj);
295
+ if (key in result) {
296
+ result[key].push(obj);
297
+ }
298
+ else {
299
+ result[key] = [obj];
300
+ }
301
+ }
302
+ }
303
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
304
+ finally {
305
+ try {
306
+ if (collection_1_1 && !collection_1_1.done && (_a = collection_1["return"])) _a.call(collection_1);
307
+ }
308
+ finally { if (e_5) throw e_5.error; }
309
+ }
310
+ return result;
311
+ }
312
+ function mapValues(obj, mapper) {
313
+ var result = {};
314
+ for (var key in obj) {
315
+ result[key] = mapper(obj[key]);
316
+ }
317
+ return result;
318
+ }
319
+
320
+ var isBrowser = typeof window !== "undefined";
321
+ var NONE = Symbol("NONE");
322
+ var useIsomorphicLayoutEffect$1 = isBrowser
323
+ ? React__default['default'].useLayoutEffect
324
+ : React__default['default'].useEffect;
325
+ function createElementWithChildren(elementType, props, children) {
326
+ if (Array.isArray(children)) {
327
+ return React__default['default'].createElement.apply(React__default['default'], tslib.__spreadArray([elementType,
328
+ props], tslib.__read(children), false));
329
+ }
330
+ else if (children || "children" in props) {
331
+ // Only call React.createElement with `children` if there are actual children,
332
+ // or if there was an explicit (albeit undefined) children passed via
333
+ // props. Otherwise, if you pass `undefined` as the children argument
334
+ // to React.createElement, the created element will have prop {children: undefined}.
335
+ // If the `root` is an PlasmicGeneratedComponent, and these props with {children: undefined}
336
+ // are used, then it will be taken as a `children` override, and will thus blank out
337
+ // everything under the root node.
338
+ return React__default['default'].createElement(elementType, props, children);
339
+ }
340
+ else {
341
+ return React__default['default'].createElement(elementType, props);
342
+ }
343
+ }
344
+ function ensureNotArray(children) {
345
+ if (Array.isArray(children)) {
346
+ if (children.length === 1) {
347
+ return children[0];
348
+ }
349
+ else {
350
+ return React__default['default'].createElement.apply(React__default['default'], tslib.__spreadArray([React__default['default'].Fragment, {}], tslib.__read(children), false));
351
+ }
352
+ }
353
+ else {
354
+ return children;
355
+ }
356
+ }
357
+ /**
358
+ * Flattens ReactNode into an array of ReactChild, but does NOT replace
359
+ * missing keys with array index, as React.Children.toArray() does.
360
+ */
361
+ function toChildArray(children) {
362
+ if (isReactChild(children)) {
363
+ return [children];
364
+ }
365
+ else if (Array.isArray(children)) {
366
+ return children.flatMap(toChildArray);
367
+ }
368
+ else {
369
+ return [];
370
+ }
371
+ }
372
+ function isReactText(child) {
373
+ return typeof child === "string" || typeof child === "number";
374
+ }
375
+ function isReactChild(child) {
376
+ return React__default['default'].isValidElement(child) || isReactText(child);
377
+ }
378
+ function isReactNode(x) {
379
+ return (typeof x === "string" || typeof x === "number" || React__default['default'].isValidElement(x));
380
+ }
381
+ function mergeProps(props) {
382
+ var e_1, _a, e_2, _b;
383
+ var restProps = [];
384
+ for (var _i = 1; _i < arguments.length; _i++) {
385
+ restProps[_i - 1] = arguments[_i];
386
+ }
387
+ if (restProps.every(function (rest) { return Object.keys(rest).length === 0; })) {
388
+ return props;
389
+ }
390
+ var result = tslib.__assign({}, props);
391
+ try {
392
+ for (var restProps_1 = tslib.__values(restProps), restProps_1_1 = restProps_1.next(); !restProps_1_1.done; restProps_1_1 = restProps_1.next()) {
393
+ var rest = restProps_1_1.value;
394
+ try {
395
+ for (var _c = (e_2 = void 0, tslib.__values(Object.keys(rest))), _d = _c.next(); !_d.done; _d = _c.next()) {
396
+ var key = _d.value;
397
+ result[key] = mergePropVals(key, result[key], rest[key]);
398
+ }
399
+ }
400
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
401
+ finally {
402
+ try {
403
+ if (_d && !_d.done && (_b = _c["return"])) _b.call(_c);
404
+ }
405
+ finally { if (e_2) throw e_2.error; }
406
+ }
407
+ }
408
+ }
409
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
410
+ finally {
411
+ try {
412
+ if (restProps_1_1 && !restProps_1_1.done && (_a = restProps_1["return"])) _a.call(restProps_1);
413
+ }
414
+ finally { if (e_1) throw e_1.error; }
415
+ }
416
+ return result;
417
+ }
418
+ function updateRef(ref, value) {
419
+ if (!ref) {
420
+ return;
421
+ }
422
+ if (typeof ref === "function") {
423
+ ref(value);
424
+ }
425
+ else {
426
+ if (!Object.isFrozen(ref)) {
427
+ ref.current = value;
428
+ }
429
+ }
430
+ }
431
+ function mergeRefs() {
432
+ var refs = [];
433
+ for (var _i = 0; _i < arguments.length; _i++) {
434
+ refs[_i] = arguments[_i];
435
+ }
436
+ return function (value) {
437
+ var e_3, _a;
438
+ try {
439
+ for (var refs_1 = tslib.__values(refs), refs_1_1 = refs_1.next(); !refs_1_1.done; refs_1_1 = refs_1.next()) {
440
+ var ref = refs_1_1.value;
441
+ updateRef(ref, value);
442
+ }
443
+ }
444
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
445
+ finally {
446
+ try {
447
+ if (refs_1_1 && !refs_1_1.done && (_a = refs_1["return"])) _a.call(refs_1);
448
+ }
449
+ finally { if (e_3) throw e_3.error; }
450
+ }
451
+ };
452
+ }
453
+ function mergePropVals(name, val1, val2) {
454
+ if (val1 === NONE || val2 === NONE) {
455
+ // The NONE sentinel always skips all merging and returns null
456
+ return null;
457
+ }
458
+ else if (val1 == null) {
459
+ // If either of them is nil, prefer the other
460
+ return val2;
461
+ }
462
+ else if (val2 == null) {
463
+ return val1;
464
+ }
465
+ else if (name === "className") {
466
+ // Special case for className -- always combine both class names
467
+ return classNames__default['default'](val1, val2);
468
+ }
469
+ else if (name === "style") {
470
+ // Special case for style -- always shallow-merge style dicts
471
+ return tslib.__assign(tslib.__assign({}, val1), val2);
472
+ }
473
+ else if (name === "ref") {
474
+ // Special case for ref
475
+ return mergeRefs(val1, val2);
476
+ }
477
+ else if (typeof val1 !== typeof val2) {
478
+ // If the type of the two values are different, then no way to merge them.
479
+ // Prefer val2.
480
+ return val2;
481
+ }
482
+ else if (name.startsWith("on") && typeof val1 === "function") {
483
+ // Special case for event handlers -- always call both handlers
484
+ return function () {
485
+ var args = [];
486
+ for (var _i = 0; _i < arguments.length; _i++) {
487
+ args[_i] = arguments[_i];
488
+ }
489
+ var res;
490
+ if (typeof val1 === "function") {
491
+ res = val1.apply(void 0, tslib.__spreadArray([], tslib.__read(args), false));
492
+ }
493
+ if (typeof val2 === "function") {
494
+ res = val2.apply(void 0, tslib.__spreadArray([], tslib.__read(args), false));
495
+ }
496
+ return res;
497
+ };
498
+ }
499
+ else {
500
+ // For all else, prefer val2
501
+ return val2;
502
+ }
503
+ }
504
+ function getElementTypeName(element) {
505
+ var _a, _b, _c, _d;
506
+ if (typeof element.type === "string") {
507
+ return element.type;
508
+ }
509
+ else {
510
+ var comp = element.type;
511
+ return (_d = (_b = (_a = comp.displayName) !== null && _a !== void 0 ? _a : comp.name) !== null && _b !== void 0 ? _b : (_c = comp.render) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : "Component";
512
+ }
513
+ }
514
+
515
+ function renderStack(as, props, hasGap, ref) {
516
+ var children = props.children, rest = tslib.__rest(props, ["children"]);
517
+ var wrappedChildren = wrapFlexContainerChildren(children, hasGap !== null && hasGap !== void 0 ? hasGap : false);
518
+ return createElementWithChildren(as, tslib.__assign({ ref: ref }, rest), wrappedChildren);
519
+ }
520
+ function FlexStack_(props, outerRef) {
521
+ var as = props.as, hasGap = props.hasGap, rest = tslib.__rest(props, ["as", "hasGap"]);
522
+ return renderStack(as !== null && as !== void 0 ? as : "div", rest, hasGap, outerRef);
523
+ }
524
+ var FlexStack = React__namespace.forwardRef(FlexStack_);
525
+ var makeStackImpl = function (as) {
526
+ return React__namespace.forwardRef(function (props, ref) {
527
+ var hasGap = props.hasGap, rest = tslib.__rest(props, ["hasGap"]);
528
+ return renderStack(as, rest, hasGap, ref);
529
+ });
530
+ };
531
+ var Stack = Object.assign(FlexStack, {
532
+ div: makeStackImpl("div"),
533
+ a: makeStackImpl("a"),
534
+ button: makeStackImpl("button"),
535
+ h1: makeStackImpl("h1"),
536
+ h2: makeStackImpl("h2"),
537
+ h3: makeStackImpl("h3"),
538
+ h4: makeStackImpl("h4"),
539
+ h5: makeStackImpl("h5"),
540
+ h6: makeStackImpl("h6"),
541
+ label: makeStackImpl("label"),
542
+ form: makeStackImpl("form"),
543
+ section: makeStackImpl("section"),
544
+ head: makeStackImpl("head"),
545
+ main: makeStackImpl("main"),
546
+ nav: makeStackImpl("nav")
547
+ });
548
+
549
+ function hasVariant(variants, groupName, variant) {
550
+ if (variants == null) {
551
+ return false;
552
+ }
553
+ var groupVariants = variants[groupName];
554
+ if (groupVariants == null) {
555
+ return false;
556
+ }
557
+ else if (groupVariants === true) {
558
+ return variant === groupName;
559
+ }
560
+ else if (groupVariants === false) {
561
+ return false;
562
+ }
563
+ else if (Array.isArray(groupVariants)) {
564
+ return groupVariants.includes(variant);
565
+ }
566
+ else if (typeof groupVariants === "string") {
567
+ return groupVariants === variant;
568
+ }
569
+ else {
570
+ return (groupVariants[variant] !== undefined && groupVariants[variant] !== false);
571
+ }
572
+ }
573
+ function wrapFlexContainerChildren(children, hasGap) {
574
+ // We need to always wrap the children, even if there are no gaps, because
575
+ // otherwise if we toggle between with and without gap, React reconciliation
576
+ // will blow away the children tree and all state if we switch from having
577
+ // a wrapper and not.
578
+ var className = hasGap ? "__wab_flex-container" : "__wab_passthrough";
579
+ if (!children) {
580
+ return null;
581
+ }
582
+ else if (Array.isArray(children)) {
583
+ return React__namespace.createElement.apply(React__namespace, tslib.__spreadArray(["div", { className: className }], tslib.__read(children), false));
584
+ }
585
+ else {
586
+ return React__namespace.createElement("div", { className: className }, children);
587
+ }
588
+ }
589
+ function createPlasmicElement(override, defaultRoot, defaultProps, wrapChildrenInFlex) {
590
+ if (!override || Object.keys(override).length === 0) {
591
+ return createElementWithChildren(defaultRoot, defaultProps, defaultProps.children);
592
+ }
593
+ var override2 = deriveOverride(override);
594
+ var props = mergeOverrideProps(defaultProps, override2.props);
595
+ if (override2.type === "render") {
596
+ return override2.render(props, defaultRoot);
597
+ }
598
+ var root = defaultRoot;
599
+ if (override2.type === "as" && override2.as) {
600
+ if (defaultRoot === Stack) {
601
+ // If there was an "as" override specified, but the default type is
602
+ // a Stack, then we don't want to switch to using "as" as the root,
603
+ // because then we'd lose the flex wrapper that Stack provides.
604
+ // Instead, we specify the "as" as the "as" prop to Stack.
605
+ props.as = override2.as;
606
+ }
607
+ else {
608
+ root = override2.as;
609
+ }
610
+ }
611
+ var children = props.children;
612
+ if (override2.wrapChildren) {
613
+ children = override2.wrapChildren(ensureNotArray(children));
614
+ }
615
+ if (wrapChildrenInFlex) {
616
+ // For legacy, we still support data-plasmic-wrap-flex-children
617
+ children = wrapFlexContainerChildren(children, true);
618
+ }
619
+ var result = createElementWithChildren(root, props, children);
620
+ if (override2.wrap) {
621
+ result = override2.wrap(result);
622
+ }
623
+ return result;
624
+ }
625
+ // We use data-plasmic-XXX attributes for custom properties since Typescript doesn't
626
+ // support type check on jsx pragma. See https://github.com/microsoft/TypeScript/issues/21699
627
+ // for more info.
628
+ var seenElements = new Map();
629
+ function createPlasmicElementProxy(defaultElement, props) {
630
+ // We use seenElements to keep track of elements that has been rendered by
631
+ // createPlasmicElementProxy(). When a JSX tree is evaluated, the JSX factory
632
+ // is invoked from the leaf to the root as the last call. So we can store
633
+ // all the elements we've created until we encounter the leaf, at which point
634
+ // we will clear this map. We are guaranteed that this map will only contain
635
+ // elements from one Plasmic* component at a time, because we're just creating
636
+ // elements and not "rendering" at this point; even if this JSX tree references
637
+ // other Plasmic* elements, we'll just create an element referencing that component,
638
+ // rather than following into the content of that component.
639
+ //
640
+ // TODO: is this ConcurrentMode friendly?
641
+ var _a;
642
+ var children = [];
643
+ for (var _i = 2; _i < arguments.length; _i++) {
644
+ children[_i - 2] = arguments[_i];
645
+ }
646
+ if (props == null) {
647
+ props = {};
648
+ }
649
+ var name = props["data-plasmic-name"];
650
+ var isRoot = props["data-plasmic-root"];
651
+ var forNodeName = props["data-plasmic-for-node"];
652
+ delete props["data-plasmic-name"];
653
+ delete props["data-plasmic-root"];
654
+ delete props["data-plasmic-for-node"];
655
+ var element = createPlasmicElementFromJsx.apply(void 0, tslib.__spreadArray([defaultElement,
656
+ props], tslib.__read(children), false));
657
+ if (name) {
658
+ seenElements.set(name, element);
659
+ }
660
+ if (isRoot) {
661
+ // If this is the root, and we requested a specific node by specifying data-plasmic-for-node,
662
+ // then return that node instead
663
+ var forNode = forNodeName
664
+ ? (_a = seenElements.get(forNodeName)) !== null && _a !== void 0 ? _a : null
665
+ : element;
666
+ // Clear out the seenElements map, as we're done rendering this Plasmic* component.
667
+ seenElements.clear();
668
+ return forNode;
669
+ }
670
+ return element;
671
+ }
672
+ function createPlasmicElementFromJsx(defaultElement, props) {
673
+ var _a;
674
+ var children = [];
675
+ for (var _i = 2; _i < arguments.length; _i++) {
676
+ children[_i - 2] = arguments[_i];
677
+ }
678
+ var override = props["data-plasmic-override"];
679
+ var wrapFlexChild = props["data-plasmic-wrap-flex-child"];
680
+ var triggerProps = ((_a = props["data-plasmic-trigger-props"]) !== null && _a !== void 0 ? _a : []);
681
+ delete props["data-plasmic-override"];
682
+ delete props["data-plasmic-wrap-flex-child"];
683
+ delete props["data-plasmic-trigger-props"];
684
+ return createPlasmicElement(override, defaultElement, mergeProps.apply(void 0, tslib.__spreadArray([props,
685
+ children.length === 0
686
+ ? {}
687
+ : { children: children.length === 1 ? children[0] : children }], tslib.__read(triggerProps), false)), wrapFlexChild);
688
+ }
689
+ function makeFragment() {
690
+ var children = [];
691
+ for (var _i = 0; _i < arguments.length; _i++) {
692
+ children[_i] = arguments[_i];
693
+ }
694
+ return React__namespace.createElement.apply(React__namespace, tslib.__spreadArray([React__namespace.Fragment, {}], tslib.__read(children), false));
695
+ }
696
+ var UNSET = Symbol("UNSET");
697
+ function mergeOverrideProps(defaults, overrides) {
698
+ var e_1, _a;
699
+ if (!overrides) {
700
+ return defaults;
701
+ }
702
+ var result = tslib.__assign({}, defaults);
703
+ try {
704
+ for (var _b = tslib.__values(Object.keys(overrides)), _c = _b.next(); !_c.done; _c = _b.next()) {
705
+ var key = _c.value;
706
+ var defaultVal = defaults[key];
707
+ var overrideVal = overrides[key];
708
+ if (overrideVal === UNSET) {
709
+ delete result[key];
710
+ }
711
+ else {
712
+ // We use the NONE sentinel if the overrideVal is nil, and is not one of the
713
+ // props that we merge by default -- which are className, style, and
714
+ // event handlers. This means for all other "normal" props -- like children,
715
+ // title, etc -- a nil value will unset the default.
716
+ if (overrideVal == null &&
717
+ key !== "className" &&
718
+ key !== "style" &&
719
+ !(key.startsWith("on") && typeof defaultVal === "function")) {
720
+ overrideVal = NONE;
721
+ }
722
+ result[key] = mergePropVals(key, defaultVal, overrideVal);
723
+ }
724
+ }
725
+ }
726
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
727
+ finally {
728
+ try {
729
+ if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
730
+ }
731
+ finally { if (e_1) throw e_1.error; }
732
+ }
733
+ return result;
734
+ }
735
+ function wrapWithClassName(element, className) {
736
+ var key = React__namespace.isValidElement(element)
737
+ ? element.key || undefined
738
+ : undefined;
739
+ return React__namespace.createElement("div", {
740
+ key: key,
741
+ className: className,
742
+ style: {
743
+ display: "grid"
744
+ }
745
+ }, element);
746
+ }
747
+ function deriveOverride(x) {
748
+ if (!x) {
749
+ // undefined Binding is an empty Binding
750
+ return {
751
+ type: "default",
752
+ props: {}
753
+ };
754
+ }
755
+ else if (isReactNode(x)) {
756
+ // If ReactNode, then assume this is the children
757
+ return {
758
+ type: "default",
759
+ props: {
760
+ children: x
761
+ }
762
+ };
763
+ }
764
+ else if (typeof x === "object") {
765
+ // If any of the overrideKeys is a key of this object, then assume
766
+ // this is a full Override
767
+ if ("as" in x) {
768
+ return tslib.__assign(tslib.__assign({}, x), { props: x.props || {}, type: "as" });
769
+ }
770
+ else if ("render" in x) {
771
+ return tslib.__assign(tslib.__assign({}, x), { type: "render" });
772
+ }
773
+ else if ("props" in x) {
774
+ return tslib.__assign(tslib.__assign({}, x), { props: x.props || {}, type: "default" });
775
+ }
776
+ else if (isSubset(Object.keys(x), ["wrap", "wrapChildren"])) {
777
+ // Only twiddling functions present, so assume no props overrides
778
+ // (otherwise we'd assume these were props).
779
+ return tslib.__assign(tslib.__assign({}, x), { props: {}, type: "default" });
780
+ }
781
+ // Else, assume this is just a props object.
782
+ return {
783
+ type: "default",
784
+ props: x
785
+ };
786
+ }
787
+ else if (typeof x === "function") {
788
+ return {
789
+ type: "render",
790
+ render: x
791
+ };
792
+ }
793
+ throw new Error("Unexpected override: ".concat(x));
794
+ }
795
+ function mergeVariants(v1, v2) {
796
+ if (!v1 || !v2) {
797
+ return v1 || v2 || {};
798
+ }
799
+ return tslib.__assign(tslib.__assign({}, v1), v2);
800
+ }
801
+ function mergeVariantsWithStates(variants, $state, linkedStates) {
802
+ return tslib.__assign(tslib.__assign({}, variants), Object.fromEntries(linkedStates.map(function (_a) {
803
+ var variantGroup = _a.variantGroup, statePath = _a.statePath;
804
+ return [
805
+ variantGroup,
806
+ get__default['default']($state, statePath),
807
+ ];
808
+ })));
809
+ }
810
+ function mergeArgs(a1, a2) {
811
+ if (!a1 || !a2) {
812
+ return a1 || a2 || {};
813
+ }
814
+ return tslib.__assign(tslib.__assign({}, a1), a2);
815
+ }
816
+ function mergeFlexOverrides(o1, o2) {
817
+ var e_2, _a;
818
+ if (!o2) {
819
+ return o1;
820
+ }
821
+ var keys = Array.from(new Set(tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(Object.keys(o1)), false), tslib.__read(Object.keys(o2)), false)));
822
+ var merged = {};
823
+ try {
824
+ for (var keys_1 = tslib.__values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
825
+ var key = keys_1_1.value;
826
+ merged[key] = mergeFlexOverride(o1[key], o2[key]);
827
+ }
828
+ }
829
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
830
+ finally {
831
+ try {
832
+ if (keys_1_1 && !keys_1_1.done && (_a = keys_1["return"])) _a.call(keys_1);
833
+ }
834
+ finally { if (e_2) throw e_2.error; }
835
+ }
836
+ return merged;
837
+ }
838
+ function mergeFlexOverride(fo1, fo2) {
839
+ var _a, _b;
840
+ if (!fo1) {
841
+ return fo2;
842
+ }
843
+ if (!fo2) {
844
+ return fo1;
845
+ }
846
+ var o1 = deriveOverride(fo1);
847
+ var o2 = deriveOverride(fo2);
848
+ var wrap = chainSingleArgFuncs.apply(void 0, tslib.__spreadArray([], tslib.__read([o1.wrap, o2.wrap].filter(notNil)), false));
849
+ var wrapChildren = chainSingleArgFuncs.apply(void 0, tslib.__spreadArray([], tslib.__read([o1.wrapChildren, o2.wrapChildren].filter(notNil)), false));
850
+ // "render" type always takes precedence, but we still merge the props
851
+ var props = mergeOverrideProps((_a = o1.props) !== null && _a !== void 0 ? _a : {}, o2.props);
852
+ if (o2.type === "render") {
853
+ return {
854
+ render: o2.render,
855
+ props: props,
856
+ wrap: wrap,
857
+ wrapChildren: wrapChildren
858
+ };
859
+ }
860
+ if (o1.type === "render") {
861
+ return {
862
+ render: o1.render,
863
+ props: props,
864
+ wrap: wrap,
865
+ wrapChildren: wrapChildren
866
+ };
867
+ }
868
+ // "as" will take precedence
869
+ var as = (_b = (o2.type === "as" ? o2.as : undefined)) !== null && _b !== void 0 ? _b : (o1.type === "as" ? o1.as : undefined);
870
+ return tslib.__assign({ props: props, wrap: wrap, wrapChildren: wrapChildren }, (as ? { as: as } : {}));
871
+ }
872
+ function deriveRenderOpts(props, config) {
873
+ var _a;
874
+ var name = config.name, descendantNames = config.descendantNames, internalVariantPropNames = config.internalVariantPropNames, internalArgPropNames = config.internalArgPropNames;
875
+ var reservedPropNames = ["variants", "args", "overrides"];
876
+ var variants = mergeVariants(omit.apply(void 0, tslib.__spreadArray([pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(internalVariantPropNames), false))], tslib.__read(reservedPropNames), false)), props.variants);
877
+ var args = mergeArgs(omit.apply(void 0, tslib.__spreadArray([pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(internalArgPropNames), false))], tslib.__read(reservedPropNames), false)), props.args);
878
+ var overrides = mergeFlexOverrides(omit.apply(void 0, tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(descendantNames), false))], tslib.__read(internalArgPropNames), false), tslib.__read(internalVariantPropNames), false), tslib.__read(reservedPropNames), false)), props.overrides);
879
+ var leftoverProps = omit.apply(void 0, tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([props,
880
+ "variants",
881
+ "args",
882
+ "overrides"], tslib.__read(descendantNames), false), tslib.__read(internalVariantPropNames), false), tslib.__read(internalArgPropNames), false));
883
+ if (Object.keys(leftoverProps).length > 0) {
884
+ overrides = mergeFlexOverrides(overrides, (_a = {},
885
+ _a[name] = {
886
+ props: leftoverProps
887
+ },
888
+ _a));
889
+ }
890
+ return { variants: variants, args: args, overrides: overrides };
891
+ }
892
+
893
+ var isDefaultValue = function (val) { return val === "PLEASE_RENDER_INSIDE_PROVIDER"; };
894
+ var seenDefaultVariants = {};
895
+ function ensureGlobalVariants(globalVariantValues) {
896
+ Object.entries(globalVariantValues)
897
+ .filter(function (_a) {
898
+ var _b = tslib.__read(_a, 2); _b[0]; var value = _b[1];
899
+ return isDefaultValue(value);
900
+ })
901
+ .forEach(function (_a) {
902
+ var _b = tslib.__read(_a, 2), key = _b[0]; _b[1];
903
+ globalVariantValues[key] = undefined;
904
+ if (!seenDefaultVariants[key] && process.env.NODE_ENV === "development") {
905
+ seenDefaultVariants[key] = true;
906
+ var providerName = "".concat(key[0].toUpperCase()).concat(key.substring(1), "Context.Provider");
907
+ 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"));
908
+ }
909
+ });
910
+ return globalVariantValues;
911
+ }
912
+
913
+ var PlasmicHeadContext = React__namespace.createContext(undefined);
914
+ function PlasmicHead(props) {
915
+ var Head = React__namespace.useContext(PlasmicHeadContext);
916
+ if (!Head) {
917
+ console.warn("Plasmic: Head meta tags are being ignored. To make them work, pass a Head component into PlasmicRootProvider.");
918
+ // TODO: Link to doc about Head.
919
+ return null;
920
+ }
921
+ // Helmet does not support React.Fragments, so we need to use `[<meta />,
922
+ // <meta />]` instead of `<><meta /><meta /></>`.
923
+ return (React__namespace.createElement(Head, null,
924
+ props.image ? ([
925
+ React__namespace.createElement("meta", { key: "twitter:card", name: "twitter:card", content: "summary_large_image" }),
926
+ React__namespace.createElement("meta", { key: "og:image", property: "og:image", content: props.image }),
927
+ React__namespace.createElement("meta", { key: "twitter:image", name: "twitter:image", content: props.image }),
928
+ ]) : (React__namespace.createElement("meta", { key: "twitter:card", name: "twitter:card", content: "summary" })),
929
+ props.title && [
930
+ React__namespace.createElement("title", { key: "title" }, props.title),
931
+ React__namespace.createElement("meta", { key: "og:title", property: "og:title", content: props.title }),
932
+ React__namespace.createElement("meta", { key: "twitter:title", property: "twitter:title", content: props.title }),
933
+ ],
934
+ props.description && [
935
+ React__namespace.createElement("meta", { key: "description", name: "description", content: props.description }),
936
+ React__namespace.createElement("meta", { key: "og:description", property: "og:description", content: props.description }),
937
+ React__namespace.createElement("meta", { key: "twitter:description", name: "twitter:description", content: props.description }),
938
+ ],
939
+ props.canonical && (React__namespace.createElement("link", { key: "canonical", ref: "canonical", href: props.canonical }))));
940
+ }
941
+ var plasmicHeadMeta = {
942
+ name: "hostless-plasmic-head",
943
+ displayName: "Head",
944
+ description: "Used to add page metadata to HTML <head />.",
945
+ importName: "PlasmicHead",
946
+ importPath: "@plasmicapp/react-web",
947
+ isRepeatable: false,
948
+ styleSections: false,
949
+ props: {
950
+ title: {
951
+ type: "string",
952
+ displayName: "Title"
953
+ },
954
+ description: {
955
+ type: "string",
956
+ displayName: "Description"
957
+ },
958
+ image: {
959
+ type: "imageUrl",
960
+ displayName: "Image"
961
+ },
962
+ canonical: {
963
+ type: "string",
964
+ displayName: "Canonical URL"
965
+ }
966
+ }
967
+ };
968
+
969
+ function PlasmicIcon(props) {
970
+ var PlasmicIconType = props.PlasmicIconType, rest = tslib.__rest(props, ["PlasmicIconType"]);
971
+ return React__namespace.createElement(PlasmicIconType, tslib.__assign({}, rest));
972
+ }
973
+
974
+ /**
975
+ * Responsive `<img/>` replacement, based on `next/image`
976
+ */
977
+ // Default image sizes to snap to
978
+ // TODO: make this configurable?
979
+ var IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
980
+ var DEVICE_SIZES = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
981
+ var ALL_SIZES = tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(IMG_SIZES), false), tslib.__read(DEVICE_SIZES), false);
982
+ var PlasmicImg = React__default['default'].forwardRef(function PlasmicImg(props, outerRef) {
983
+ var src = props.src, className = props.className, displayWidth = props.displayWidth, displayHeight = props.displayHeight, displayMinWidth = props.displayMinWidth, displayMinHeight = props.displayMinHeight, displayMaxWidth = props.displayMaxWidth, displayMaxHeight = props.displayMaxHeight, quality = props.quality, loader = props.loader, imgRef = props.imgRef, style = props.style, loading = props.loading, rest = tslib.__rest(props, ["src", "className", "displayWidth", "displayHeight", "displayMinWidth", "displayMinHeight", "displayMaxWidth", "displayMaxHeight", "quality", "loader", "imgRef", "style", "loading"]);
984
+ var imgProps = Object.assign({}, rest, {
985
+ // Default loading to "lazy" if not specified (which is different from the
986
+ // html img, which defaults to eager!)
987
+ loading: loading !== null && loading !== void 0 ? loading : "lazy"
988
+ });
989
+ var _a = typeof src === "string" || !src
990
+ ? { fullWidth: undefined, fullHeight: undefined, aspectRatio: undefined }
991
+ : src, fullWidth = _a.fullWidth, fullHeight = _a.fullHeight, aspectRatio = _a.aspectRatio;
992
+ var srcStr = src
993
+ ? typeof src === "string"
994
+ ? src
995
+ : typeof src.src === "string"
996
+ ? src.src
997
+ : src.src.src
998
+ : "";
999
+ // Assume external image if either dimension is null and use usual <img>
1000
+ if (fullHeight == null || fullWidth == null) {
1001
+ return (React__default['default'].createElement("img", tslib.__assign({ src: srcStr, className: className, style: style }, imgProps, { loading: loading, ref: mergeRefs(imgRef, outerRef) })));
1002
+ }
1003
+ if (isSvg(srcStr) &&
1004
+ (displayHeight == null || displayHeight === "auto") &&
1005
+ (displayWidth == null || displayWidth === "auto")) {
1006
+ displayWidth = "100%";
1007
+ }
1008
+ var computedDisplayWidth = displayWidth;
1009
+ if (fullWidth &&
1010
+ fullHeight &&
1011
+ (!displayWidth || displayWidth === "auto") &&
1012
+ !!getPixelLength(displayHeight)) {
1013
+ // If there's a pixel length specified for displayHeight but not displayWidth,
1014
+ // then we can derive the pixel length for displayWidth. Having an explicit
1015
+ // displayWidth makes this a fixed-size image, which makes it possible for us to
1016
+ // generate better markup!
1017
+ if (!isSvg(srcStr)) {
1018
+ // We shouldn't do it for SVGs though, because `fullWidth` and
1019
+ // `fullHeight` might have rounded values so the final
1020
+ // `displayWidth` could differ by 1px or so.
1021
+ computedDisplayWidth =
1022
+ (getPixelLength(displayHeight) * fullWidth) / fullHeight;
1023
+ }
1024
+ }
1025
+ var spacerWidth = fullWidth;
1026
+ var spacerHeight = fullHeight;
1027
+ if (aspectRatio && isFinite(aspectRatio) && isSvg(srcStr)) {
1028
+ // For SVGs, fullWidth and fullHeight can be rounded values, which would
1029
+ // cause some discrepancy between the actual aspect ratio and the aspect
1030
+ // ratio from those values. So, for those cases, we set large width / height
1031
+ // values to get a more precise ratio from the spacer.
1032
+ spacerWidth = DEFAULT_SVG_WIDTH;
1033
+ spacerHeight = Math.round(spacerWidth / aspectRatio);
1034
+ }
1035
+ var _b = getWidths(computedDisplayWidth, fullWidth, {
1036
+ minWidth: displayMinWidth
1037
+ }), sizes = _b.sizes, widthDescs = _b.widthDescs;
1038
+ var imageLoader = getImageLoader(loader);
1039
+ var spacerSvg = "<svg width=\"".concat(spacerWidth, "\" height=\"").concat(spacerHeight, "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>");
1040
+ var spacerSvgBase64 = typeof window === "undefined"
1041
+ ? Buffer.from(spacerSvg).toString("base64")
1042
+ : window.btoa(spacerSvg);
1043
+ var wrapperStyle = tslib.__assign({}, (style || {}));
1044
+ var spacerStyle = tslib.__assign({}, pick(style || {}, "objectFit", "objectPosition"));
1045
+ if (displayWidth != null && displayWidth !== "auto") {
1046
+ // If width is set, set it on the wrapper along with min/max width
1047
+ // and just use `width: 100%` on the spacer
1048
+ spacerStyle.width = "100%";
1049
+ // Rely on the styles set by `classname` on the wrapper:
1050
+ // wrapperStyle.width = displayWidth;
1051
+ // wrapperStyle.minWidth = displayMinWidth;
1052
+ // wrapperStyle.maxWidth = displayMaxWidth;
1053
+ }
1054
+ else {
1055
+ // Otherwise, we want auto sizing from the spacer, so set width there.
1056
+ //
1057
+ // But if we have min/max width, it should be set in the wrapper and it
1058
+ // can be percentage values (and we add corresponding min/max width to
1059
+ // 100% in the spacer). In general it ends up with the correct effect,
1060
+ // but some edge cases might make `min-width: 100%` shrink the image more
1061
+ // than it should.
1062
+ spacerStyle.width = displayWidth;
1063
+ wrapperStyle.width = "auto";
1064
+ if (displayMinWidth) {
1065
+ spacerStyle.minWidth = "100%";
1066
+ // Rely on min-width set by `classname` on the wrapper:
1067
+ // wrapperStyle.minWidth = displayMinWidth;
1068
+ }
1069
+ if (displayMaxWidth != null && displayMaxWidth !== "none") {
1070
+ spacerStyle.maxWidth = "100%";
1071
+ // Rely on max-width set by `classname` on the wrapper:
1072
+ // wrapperStyle.maxWidth = displayMaxWidth;
1073
+ }
1074
+ }
1075
+ if (displayHeight != null && displayHeight !== "auto") {
1076
+ spacerStyle.height = "100%";
1077
+ // wrapperStyle.height = displayHeight;
1078
+ // wrapperStyle.minHeight = displayMinHeight;
1079
+ // wrapperStyle.maxHeight = displayMaxHeight;
1080
+ }
1081
+ else {
1082
+ spacerStyle.height = displayHeight;
1083
+ wrapperStyle.height = "auto";
1084
+ if (displayMinHeight) {
1085
+ spacerStyle.minHeight = "100%";
1086
+ // wrapperStyle.minHeight = displayMinHeight;
1087
+ }
1088
+ if (displayMaxHeight != null && displayMaxHeight !== "none") {
1089
+ spacerStyle.maxHeight = "100%";
1090
+ // wrapperStyle.maxHeight = displayMaxHeight;
1091
+ }
1092
+ }
1093
+ return (React__default['default'].createElement("div", { className: classNames__default['default'](className, "__wab_img-wrapper"), ref: outerRef, style: wrapperStyle },
1094
+ React__default['default'].createElement("img", { alt: "", "aria-hidden": true, className: "__wab_img-spacer-svg", src: "data:image/svg+xml;base64,".concat(spacerSvgBase64), style: spacerStyle }),
1095
+ makePicture({
1096
+ imageLoader: imageLoader,
1097
+ widthDescs: widthDescs,
1098
+ sizes: sizes,
1099
+ src: srcStr,
1100
+ quality: quality,
1101
+ ref: imgRef,
1102
+ style: style ? pick(style, "objectFit", "objectPosition") : undefined,
1103
+ imgProps: imgProps,
1104
+ className: "__wab_img"
1105
+ })));
1106
+ });
1107
+ function makePicture(opts) {
1108
+ // If imageLoader is undefined, then this renders to just a normal
1109
+ // <img />. Else it will render to a <picture> with a <source> for
1110
+ // webp, and srcSet/sizes set according to width requirements.
1111
+ var imageLoader = opts.imageLoader, widthDescs = opts.widthDescs, src = opts.src, quality = opts.quality, style = opts.style, className = opts.className, sizes = opts.sizes, imgProps = opts.imgProps, ref = opts.ref;
1112
+ return (React__default['default'].createElement("picture", { className: "__wab_picture" },
1113
+ imageLoader && imageLoader.supportsUrl(src) && (React__default['default'].createElement("source", { type: "image/webp", srcSet: widthDescs
1114
+ .map(function (wd) {
1115
+ return "".concat(imageLoader.transformUrl({
1116
+ src: src,
1117
+ quality: quality,
1118
+ width: wd.width,
1119
+ format: "webp"
1120
+ }), " ").concat(wd.desc);
1121
+ })
1122
+ .join(", ") })),
1123
+ React__default['default'].createElement("img", tslib.__assign({}, imgProps, { ref: ref, className: className, decoding: "async", src: imageLoader && imageLoader.supportsUrl(src)
1124
+ ? imageLoader.transformUrl({
1125
+ src: src,
1126
+ quality: quality,
1127
+ width: widthDescs[widthDescs.length - 1].width
1128
+ })
1129
+ : src, srcSet: imageLoader && imageLoader.supportsUrl(src)
1130
+ ? widthDescs
1131
+ .map(function (wd) {
1132
+ return "".concat(imageLoader.transformUrl({
1133
+ src: src,
1134
+ quality: quality,
1135
+ width: wd.width
1136
+ }), " ").concat(wd.desc);
1137
+ })
1138
+ .join(", ")
1139
+ : undefined, sizes: imageLoader && imageLoader.supportsUrl(src) ? sizes : undefined, style: tslib.__assign(tslib.__assign({}, (style ? pick(style, "objectFit", "objectPosition") : {})), { width: 0, height: 0 }) }))));
1140
+ }
1141
+ var DEFAULT_SVG_WIDTH = 10000;
1142
+ function isSvg(src) {
1143
+ return src.endsWith(".svg") || src.startsWith("data:image/svg");
1144
+ }
1145
+ function getClosestPresetSize(width, fullWidth) {
1146
+ var _a;
1147
+ var nextBiggerIndex = (_a = ALL_SIZES.findIndex(function (w) { return w >= width; })) !== null && _a !== void 0 ? _a : ALL_SIZES.length - 1;
1148
+ var nextBigger = ALL_SIZES[nextBiggerIndex];
1149
+ if (nextBigger >= fullWidth) {
1150
+ // If the requested width is larger than the fullWidth,
1151
+ // we just use the original width instead. It's impossible
1152
+ // to make an image bigger than fullWidth!
1153
+ return undefined;
1154
+ }
1155
+ else if (nextBiggerIndex + 1 < ALL_SIZES.length &&
1156
+ fullWidth <= ALL_SIZES[nextBiggerIndex + 1]) {
1157
+ // If the fullWidth is just between nextBigger and the one after that,
1158
+ // then also might as well just use the original size (so, width is 30,
1159
+ // nextBigger is 32, then we just use the original as long as fullWidth is
1160
+ // less than 48)
1161
+ return undefined;
1162
+ }
1163
+ return nextBigger;
1164
+ }
1165
+ /**
1166
+ * Computes the appropriate srcSet and sizes to use
1167
+ */
1168
+ function getWidths(width, fullWidth, extra) {
1169
+ var minWidth = extra === null || extra === void 0 ? void 0 : extra.minWidth;
1170
+ var pixelWidth = getPixelLength(width);
1171
+ var pixelMinWidth = getPixelLength(minWidth);
1172
+ if (pixelWidth != null && (!minWidth || pixelMinWidth != null)) {
1173
+ // If there's an exact width, then we just need to display it at 1x and 2x density
1174
+ return {
1175
+ widthDescs: [
1176
+ {
1177
+ width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth !== null && pixelMinWidth !== void 0 ? pixelMinWidth : 0), fullWidth),
1178
+ desc: "1x"
1179
+ },
1180
+ {
1181
+ width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth !== null && pixelMinWidth !== void 0 ? pixelMinWidth : 0) * 2, fullWidth),
1182
+ desc: "2x"
1183
+ },
1184
+ ],
1185
+ sizes: undefined
1186
+ };
1187
+ }
1188
+ // Otherwise we don't know what sizes we'll end up, so we just cap it at
1189
+ // device width. TODO: do better!
1190
+ var usefulSizes = DEVICE_SIZES.filter(function (size) { return !fullWidth || size < fullWidth; });
1191
+ if (!!fullWidth && usefulSizes.length === 0) {
1192
+ // image fullWidth is smaller than all device sizes. So all we can do
1193
+ // is offer 1x
1194
+ return {
1195
+ widthDescs: [
1196
+ {
1197
+ width: getClosestPresetSize(fullWidth, fullWidth),
1198
+ desc: "1x"
1199
+ },
1200
+ ],
1201
+ sizes: undefined
1202
+ };
1203
+ }
1204
+ return {
1205
+ widthDescs: usefulSizes.map(function (size) { return ({
1206
+ width: getClosestPresetSize(size, fullWidth),
1207
+ // If this is the last (buggest) useful width, but it is
1208
+ // still within the bounds set by DEVICE_SIZES, then just
1209
+ // use the original, unresized image. This means if we match
1210
+ // the largest size, we use unresized and best quality image.
1211
+ // We only do this, though, if fullWidth is "reasonable" --
1212
+ // smaller than the largest size we would consider.
1213
+ // i === usefulSizes.length - 1 &&
1214
+ // fullWidth < DEVICE_SIZES[DEVICE_SIZES.length - 1]
1215
+ // ? undefined
1216
+ // : size,
1217
+ desc: "".concat(size, "w")
1218
+ }); }),
1219
+ sizes: "100vw"
1220
+ };
1221
+ }
1222
+ function getPixelLength(length) {
1223
+ if (length == null || length == "") {
1224
+ return undefined;
1225
+ }
1226
+ if (typeof length === "number") {
1227
+ return length;
1228
+ }
1229
+ var parsed = parseNumeric(length);
1230
+ if (parsed && (!parsed.units || parsed.units === "px")) {
1231
+ return parsed.num;
1232
+ }
1233
+ return undefined;
1234
+ }
1235
+ function parseNumeric(val) {
1236
+ // Parse strings like "30", "30px", "30%", "30px /* blah blah */"
1237
+ var res = val.match(/^\s*(-?(?:\d+\.\d*|\d*\.\d+|\d+))\s*([a-z]*|%)\s*(?:\/\*.*)?$/i);
1238
+ if (res == null) {
1239
+ return undefined;
1240
+ }
1241
+ var num = res[1];
1242
+ var units = res[2];
1243
+ return { num: +num, units: units };
1244
+ }
1245
+ function getImageLoader(loader) {
1246
+ if (loader == null) {
1247
+ return undefined;
1248
+ }
1249
+ else if (loader === "plasmic") {
1250
+ return PLASMIC_IMAGE_LOADER;
1251
+ }
1252
+ else {
1253
+ return loader;
1254
+ }
1255
+ }
1256
+ var PLASMIC_IMAGE_LOADER = {
1257
+ supportsUrl: function (src) {
1258
+ return src.startsWith("https://img.plasmic.app") && !isSvg(src);
1259
+ },
1260
+ transformUrl: function (opts) {
1261
+ var _a;
1262
+ var params = [
1263
+ opts.width ? "w=".concat(opts.width) : undefined,
1264
+ "q=".concat((_a = opts.quality) !== null && _a !== void 0 ? _a : 75),
1265
+ opts.format ? "f=".concat(opts.format) : undefined,
1266
+ ].filter(function (x) { return !!x; });
1267
+ return "".concat(opts.src, "?").concat(params.join("&"));
1268
+ }
1269
+ };
1270
+
1271
+ var PlasmicLink = React__default['default'].forwardRef(function PlasmicLink(props, ref) {
1272
+ // props.href is required for nextjs; if no props.href,
1273
+ // then we just render the default anchor element
1274
+ if (props.platform === "nextjs" && props.href) {
1275
+ var nextjsProps = [
1276
+ "href",
1277
+ "replace",
1278
+ "scroll",
1279
+ "shallow",
1280
+ "passHref",
1281
+ "prefetch",
1282
+ "locale",
1283
+ ];
1284
+ return React__default['default'].createElement(props.component, tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(nextjsProps), false))), { legacyBehavior: true }), React__default['default'].createElement("a", tslib.__assign({}, omit.apply(void 0, tslib.__spreadArray([props, "component", "platform"], tslib.__read(nextjsProps), false)), { ref: ref })));
1285
+ }
1286
+ if (props.platform === "gatsby" && isInternalHref(props.href)) {
1287
+ return React__default['default'].createElement(props.component, tslib.__assign(tslib.__assign({}, omit(props, "component", "platform", "href")), { to: props.href, ref: ref }));
1288
+ }
1289
+ return React__default['default'].createElement("a", tslib.__assign({}, omit(props, "component", "platform"), { ref: ref }));
1290
+ });
1291
+ function isInternalHref(href) {
1292
+ return /^\/(?!\/)/.test(href);
1293
+ }
1294
+
1295
+ var PlasmicTranslatorContext = React__default['default'].createContext(undefined);
1296
+ function isIterable(val) {
1297
+ return val != null && typeof val[Symbol.iterator] === "function";
1298
+ }
1299
+ function genTranslatableString(elt) {
1300
+ var components = {};
1301
+ var componentsCount = 0;
1302
+ var getText = function (node) {
1303
+ if (!node) {
1304
+ return "";
1305
+ }
1306
+ if (typeof node === "number" ||
1307
+ typeof node === "boolean" ||
1308
+ typeof node === "string") {
1309
+ return node.toString();
1310
+ }
1311
+ if (typeof node !== "object") {
1312
+ return "";
1313
+ }
1314
+ if (Array.isArray(node) || isIterable(node)) {
1315
+ return Array.from(node)
1316
+ .map(function (child) { return getText(child); })
1317
+ .filter(function (child) { return !!child; })
1318
+ .join("");
1319
+ }
1320
+ var nodeChildren = (hasKey(node, "props") &&
1321
+ hasKey(node.props, "children") &&
1322
+ node.props.children) ||
1323
+ (hasKey(node, "children") && node.children) ||
1324
+ [];
1325
+ var contents = "".concat(React__default['default'].Children.toArray(nodeChildren)
1326
+ .map(function (child) { return getText(child); })
1327
+ .filter(function (child) { return !!child; })
1328
+ .join(""));
1329
+ if (React__default['default'].isValidElement(node) && node.type === React__default['default'].Fragment) {
1330
+ return contents;
1331
+ }
1332
+ var componentId = componentsCount + 1;
1333
+ componentsCount++;
1334
+ components[componentId] = React__default['default'].isValidElement(node)
1335
+ ? React__default['default'].cloneElement(node, {
1336
+ key: componentId,
1337
+ children: undefined
1338
+ })
1339
+ : node;
1340
+ return "<".concat(componentId, ">").concat(contents, "</").concat(componentId, ">");
1341
+ };
1342
+ var str = getText(elt);
1343
+ return {
1344
+ str: str,
1345
+ components: components,
1346
+ componentsCount: componentsCount
1347
+ };
1348
+ }
1349
+ function Trans(_a) {
1350
+ var transKey = _a.transKey, children = _a.children;
1351
+ var _t = React__default['default'].useContext(PlasmicTranslatorContext);
1352
+ if (!_t) {
1353
+ warnNoTranslationFunctionAtMostOnce();
1354
+ return children;
1355
+ }
1356
+ var _b = genTranslatableString(children), str = _b.str, components = _b.components, componentsCount = _b.componentsCount;
1357
+ return _t(transKey !== null && transKey !== void 0 ? transKey : str, componentsCount > 0 ? { components: components } : undefined);
1358
+ }
1359
+ var hasWarned = false;
1360
+ function warnNoTranslationFunctionAtMostOnce() {
1361
+ if (!hasWarned) {
1362
+ console.warn("Using Plasmic Translation but no translation function has been provided");
1363
+ hasWarned = true;
1364
+ }
1365
+ }
1366
+ function hasKey(v, key) {
1367
+ return typeof v === "object" && v !== null && key in v;
1368
+ }
1369
+
1370
+ function PlasmicSlot(props) {
1371
+ return renderPlasmicSlot(props);
1372
+ }
1373
+ function renderPlasmicSlot(opts) {
1374
+ var as = opts.as, defaultContents = opts.defaultContents, value = opts.value, rest = tslib.__rest(opts, ["as", "defaultContents", "value"]);
1375
+ var content = value === undefined ? defaultContents : value;
1376
+ if (!content || (Array.isArray(content) && content.length === 0)) {
1377
+ return null;
1378
+ }
1379
+ // If the content is a raw string, then we need to wrap the raw string
1380
+ // into an element, in case the slot is inside a flex-gap
1381
+ // container (you cannot apply margin to just a text node).
1382
+ var maybeString = maybeAsString(content);
1383
+ if (maybeString) {
1384
+ content = React__namespace.createElement("span", { className: "__wab_slot-string-wrapper" }, maybeString);
1385
+ }
1386
+ var nonEmptyProps = Object.keys(rest).filter(function (p) { return !!rest[p]; });
1387
+ if (nonEmptyProps.length === 0) {
1388
+ // No attrs to apply to the slot (which means the slot is unstyled), then
1389
+ // just render the content directly; no need for style wrapper.
1390
+ return React__namespace.createElement(React__namespace.Fragment, null, content);
1391
+ }
1392
+ return React__namespace.createElement(as || "span", mergeProps({ className: "__wab_slot" }, rest), content);
1393
+ }
1394
+ function maybeAsString(node) {
1395
+ // Unwrap fragments
1396
+ if (React__namespace.isValidElement(node)) {
1397
+ // Fragment doesn't render DOM elements
1398
+ if (node.type === React__namespace.Fragment) {
1399
+ return maybeAsString(node.props.children);
1400
+ }
1401
+ else if (node.type === Trans) {
1402
+ // Trans also doesn't render DOM elements. But we don't want to just render
1403
+ // its content string, because we want to keep the <Trans/> for the localization.
1404
+ // So we render the same node, to be wrapped into __wab_slot-string-wrapper.
1405
+ return node;
1406
+ }
1407
+ }
1408
+ if (typeof node === "string") {
1409
+ return node;
1410
+ }
1411
+ if (Array.isArray(node) && node.length === 1 && typeof node[0] === "string") {
1412
+ return node[0];
1413
+ }
1414
+ return undefined;
1415
+ }
1416
+
1417
+ var listeners = [];
1418
+ var queries = {};
1419
+ function matchScreenVariants() {
1420
+ if (!isBrowser) {
1421
+ return [];
1422
+ }
1423
+ return Object.entries(queries)
1424
+ .filter(function (_a) {
1425
+ var _b = tslib.__read(_a, 2), query = _b[1];
1426
+ return window.matchMedia(query).matches;
1427
+ })
1428
+ .map(function (_a) {
1429
+ var _b = tslib.__read(_a, 1), name = _b[0];
1430
+ return name;
1431
+ });
1432
+ }
1433
+ // undefined if screen variants have never been calculated
1434
+ var curScreenVariants = undefined;
1435
+ function recalculateScreenVariants() {
1436
+ var screenVariant = matchScreenVariants();
1437
+ if (!curScreenVariants ||
1438
+ screenVariant.join("") !== curScreenVariants.join("")) {
1439
+ curScreenVariants = screenVariant;
1440
+ ReactDOM__default['default'].unstable_batchedUpdates(function () {
1441
+ return listeners.forEach(function (listener) { return listener(); });
1442
+ });
1443
+ }
1444
+ }
1445
+ function ensureInitCurScreenVariants() {
1446
+ // Initializes curScreenVariants if it hadn't been before. Note that this must
1447
+ // be called from within an effect.
1448
+ if (curScreenVariants === undefined) {
1449
+ curScreenVariants = matchScreenVariants();
1450
+ }
1451
+ }
1452
+ if (isBrowser) {
1453
+ window.addEventListener("resize", recalculateScreenVariants);
1454
+ }
1455
+ function createUseScreenVariants(isMulti, screenQueries) {
1456
+ Object.assign(queries, screenQueries);
1457
+ curScreenVariants = undefined;
1458
+ return function () {
1459
+ // It is important that upon first render, we return [] or undefined, because
1460
+ // that is what SSR will use, and the client must match. In an effect (which
1461
+ // only happens on the client), we then actually ask for the real screen variant
1462
+ // and, if different from [] or undefined, forces a re-render.
1463
+ var _a = tslib.__read(React__namespace.useState(), 2), updateState = _a[1];
1464
+ var lastScreenVariantsRef = React__namespace.useRef(curScreenVariants || []);
1465
+ // We do useLayoutEffect instead of useEffect to immediately
1466
+ // register our forceUpdate. This ensures that if there was
1467
+ // a window resize event between render and effects, that the
1468
+ // listener will be registered in time
1469
+ useIsomorphicLayoutEffect$1(function () {
1470
+ var updateIfChanged = function () {
1471
+ if (curScreenVariants &&
1472
+ lastScreenVariantsRef.current.join("") !== curScreenVariants.join("")) {
1473
+ lastScreenVariantsRef.current = curScreenVariants;
1474
+ // Force update
1475
+ updateState({});
1476
+ }
1477
+ };
1478
+ // Listeners are invoked whenever the window is resized
1479
+ listeners.push(updateIfChanged);
1480
+ // Initialize the curScreenVariants for the first time. We don't need
1481
+ // to invoke the listeners here because all components will already
1482
+ // have this effect running and will re-render if the real screen
1483
+ // variant is non-empty.
1484
+ ensureInitCurScreenVariants();
1485
+ // Now, if the curScreenVariants differs from what we returned last,
1486
+ // then force a re-render.
1487
+ updateIfChanged();
1488
+ return function () {
1489
+ // Remove our listener on unmount
1490
+ listeners.splice(listeners.indexOf(updateIfChanged), 1);
1491
+ };
1492
+ }, []);
1493
+ if (isMulti) {
1494
+ return curScreenVariants || [];
1495
+ }
1496
+ else if (curScreenVariants) {
1497
+ return curScreenVariants[curScreenVariants.length - 1];
1498
+ }
1499
+ else {
1500
+ return undefined;
1501
+ }
1502
+ };
1503
+ }
1504
+
1505
+ var PlasmicRootContext = React__namespace.createContext(undefined);
1506
+ function PlasmicRootProvider(props) {
1507
+ var platform = props.platform, children = props.children, userAuthToken = props.userAuthToken, isUserLoading = props.isUserLoading, authRedirectUri = props.authRedirectUri, user = props.user;
1508
+ var context = React__namespace.useMemo(function () { return ({
1509
+ platform: platform
1510
+ }); }, [platform]);
1511
+ var dataSourceContextValue = React__namespace.useMemo(function () { return ({
1512
+ userAuthToken: userAuthToken,
1513
+ user: user,
1514
+ isUserLoading: isUserLoading,
1515
+ authRedirectUri: authRedirectUri
1516
+ }); }, [userAuthToken, isUserLoading, user, authRedirectUri]);
1517
+ return (React__namespace.createElement(PlasmicRootContext.Provider, { value: context },
1518
+ React__namespace.createElement(ssr.SSRProvider, null,
1519
+ React__namespace.createElement(dataSourcesContext.PlasmicDataSourceContextProvider, { value: dataSourceContextValue },
1520
+ React__namespace.createElement(PlasmicTranslatorContext.Provider, { value: props.translator },
1521
+ React__namespace.createElement(PlasmicHeadContext.Provider, { value: props.Head }, children))))));
1522
+ }
1523
+ var useIsSSR = ssr.useIsSSR;
1524
+ function useHasPlasmicRoot() {
1525
+ return !!React__namespace.useContext(PlasmicRootContext);
1526
+ }
1527
+ var hasWarnedSSR = false;
1528
+ /**
1529
+ * Warns the user if PlasmicRootProvider is not used
1530
+ */
1531
+ function useEnsureSSRProvider() {
1532
+ var hasRoot = useHasPlasmicRoot();
1533
+ if (hasRoot || hasWarnedSSR || process.env.NODE_ENV !== "development") {
1534
+ return;
1535
+ }
1536
+ hasWarnedSSR = true;
1537
+ console.warn("Plasmic: To ensure your components work correctly with server-side rendering, please use PlasmicRootProvider at the root of your application. See https://docs.plasmic.app/learn/ssr");
1538
+ }
1539
+
1540
+ function useFocused(opts) {
1541
+ var _a = focus.useFocusRing({
1542
+ within: false,
1543
+ isTextInput: opts.isTextInput
1544
+ }), isFocused = _a.isFocused, focusProps = _a.focusProps;
1545
+ return [isFocused, focusProps];
1546
+ }
1547
+ function useFocusVisible(opts) {
1548
+ var _a = focus.useFocusRing({
1549
+ within: false,
1550
+ isTextInput: opts.isTextInput
1551
+ }), isFocusVisible = _a.isFocusVisible, focusProps = _a.focusProps;
1552
+ return [isFocusVisible, focusProps];
1553
+ }
1554
+ function useFocusedWithin(opts) {
1555
+ var _a = focus.useFocusRing({
1556
+ within: true,
1557
+ isTextInput: opts.isTextInput
1558
+ }), isFocused = _a.isFocused, focusProps = _a.focusProps;
1559
+ return [isFocused, focusProps];
1560
+ }
1561
+ function useFocusVisibleWithin(opts) {
1562
+ var _a = focus.useFocusRing({
1563
+ within: true,
1564
+ isTextInput: opts.isTextInput
1565
+ }), isFocusVisible = _a.isFocusVisible, focusProps = _a.focusProps;
1566
+ return [isFocusVisible, focusProps];
1567
+ }
1568
+ function useHover() {
1569
+ var _a = tslib.__read(React__namespace.useState(false), 2), isHover = _a[0], setHover = _a[1];
1570
+ return [
1571
+ isHover,
1572
+ {
1573
+ onMouseEnter: function () { return setHover(true); },
1574
+ onMouseLeave: function () { return setHover(false); }
1575
+ },
1576
+ ];
1577
+ }
1578
+ function usePressed() {
1579
+ var _a = tslib.__read(React__namespace.useState(false), 2), isPressed = _a[0], setPressed = _a[1];
1580
+ return [
1581
+ isPressed,
1582
+ {
1583
+ onMouseDown: function () { return setPressed(true); },
1584
+ onMouseUp: function () { return setPressed(false); }
1585
+ },
1586
+ ];
1587
+ }
1588
+ var TRIGGER_TO_HOOK = {
1589
+ useHover: useHover,
1590
+ useFocused: useFocused,
1591
+ useFocusVisible: useFocusVisible,
1592
+ useFocusedWithin: useFocusedWithin,
1593
+ useFocusVisibleWithin: useFocusVisibleWithin,
1594
+ usePressed: usePressed
1595
+ };
1596
+ /**
1597
+ * Installs argment trigger. All the useTrigger calls must use hardcoded `trigger` arg,
1598
+ * as it's not valid to install variable React hooks!
1599
+ */
1600
+ function useTrigger(trigger, opts) {
1601
+ return TRIGGER_TO_HOOK[trigger](opts);
1602
+ }
1603
+
1604
+ var ARRAY_SYMBOL = Symbol("[]");
1605
+ var PLASMIC_STATE_PROXY_SYMBOL = Symbol("plasmic.state.proxy");
1606
+ var UNINITIALIZED = Symbol("plasmic.unitialized");
1607
+
1608
+ /** @class */ ((function (_super) {
1609
+ tslib.__extends(CustomError, _super);
1610
+ function CustomError(msg) {
1611
+ var _a;
1612
+ var _this = _super.call(this, msg) || this;
1613
+ _this.name = _this.constructor.name;
1614
+ (_a = _this, _this.message = _a.message, _this.stack = _a.stack);
1615
+ return _this;
1616
+ }
1617
+ return CustomError;
1618
+ })(Error));
1619
+ var CyclicStatesReferencesError = /** @class */ (function (_super) {
1620
+ tslib.__extends(CyclicStatesReferencesError, _super);
1621
+ function CyclicStatesReferencesError(stateAccessCycle) {
1622
+ return _super.call(this, "Cyclic reference found in state initialization: " +
1623
+ stateAccessCycle.join(" -> ")) || this;
1624
+ }
1625
+ return CyclicStatesReferencesError;
1626
+ }(Error));
1627
+ var InvalidOperation = /** @class */ (function (_super) {
1628
+ tslib.__extends(InvalidOperation, _super);
1629
+ function InvalidOperation(msg) {
1630
+ return _super.call(this, msg) || this;
1631
+ }
1632
+ return InvalidOperation;
1633
+ }(Error));
1634
+ var UnknownError = /** @class */ (function (_super) {
1635
+ tslib.__extends(UnknownError, _super);
1636
+ function UnknownError(msg) {
1637
+ return _super.call(this, msg) || this;
1638
+ }
1639
+ return UnknownError;
1640
+ }(Error));
1641
+
1642
+ var StateSpecNode = /** @class */ (function () {
1643
+ function StateSpecNode(specs) {
1644
+ this._specs = specs;
1645
+ this._edges = new Map();
1646
+ }
1647
+ StateSpecNode.prototype.setSpecs = function (specs) {
1648
+ this._specs = specs;
1649
+ };
1650
+ StateSpecNode.prototype.edges = function () {
1651
+ return this._edges;
1652
+ };
1653
+ StateSpecNode.prototype.hasEdge = function (key) {
1654
+ return this._edges.has(key);
1655
+ };
1656
+ StateSpecNode.prototype.addEdge = function (key, node) {
1657
+ this._edges.set(key, node);
1658
+ };
1659
+ StateSpecNode.prototype.clearEdges = function () {
1660
+ this._edges = new Map();
1661
+ };
1662
+ StateSpecNode.prototype.children = function () {
1663
+ return this._edges.values();
1664
+ };
1665
+ StateSpecNode.prototype.makeTransition = function (key) {
1666
+ key = isNum(key) ? ARRAY_SYMBOL : key;
1667
+ return this._edges.get(key);
1668
+ };
1669
+ StateSpecNode.prototype.isLeaf = function () {
1670
+ return this._edges.size === 0 && this.getAllSpecs().length > 0;
1671
+ };
1672
+ StateSpecNode.prototype.hasArrayTransition = function () {
1673
+ return this._edges.has(ARRAY_SYMBOL);
1674
+ };
1675
+ StateSpecNode.prototype.getSpec = function () {
1676
+ return this._specs[0];
1677
+ };
1678
+ StateSpecNode.prototype.getAllSpecs = function () {
1679
+ return this._specs;
1680
+ };
1681
+ return StateSpecNode;
1682
+ }());
1683
+ var transformPathStringToObj = function (str) {
1684
+ var splitStatePathPart = function (state) {
1685
+ return state.endsWith("[]")
1686
+ ? tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(splitStatePathPart(state.slice(0, -2))), false), [ARRAY_SYMBOL], false) : [state];
1687
+ };
1688
+ return str.split(".").flatMap(splitStatePathPart);
1689
+ };
1690
+ function buildTree(specs) {
1691
+ var internalSpec = specs.map(function (spec) {
1692
+ return (tslib.__assign(tslib.__assign({}, spec), { pathObj: transformPathStringToObj(spec.path), isRepeated: spec.path.split(".").some(function (part) { return part.endsWith("[]"); }) }));
1693
+ });
1694
+ var rec = function (currentPath) {
1695
+ var node = new StateSpecNode(internalSpec.filter(function (spec) {
1696
+ return shallowEqual(currentPath, spec.pathObj.slice(0, currentPath.length));
1697
+ }));
1698
+ node.getAllSpecs().forEach(function (spec) {
1699
+ if (spec.pathObj.length > currentPath.length) {
1700
+ var nextKey = spec.pathObj[currentPath.length];
1701
+ if (!node.hasEdge(nextKey)) {
1702
+ node.addEdge(nextKey, rec(tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(currentPath), false), [nextKey], false)));
1703
+ }
1704
+ }
1705
+ });
1706
+ return node;
1707
+ };
1708
+ return rec([]);
1709
+ }
1710
+ function updateTree(root, specs) {
1711
+ var internalSpec = specs.map(function (spec) {
1712
+ return (tslib.__assign(tslib.__assign({}, spec), { pathObj: transformPathStringToObj(spec.path), isRepeated: spec.path.split(".").some(function (part) { return part.endsWith("[]"); }) }));
1713
+ });
1714
+ var rec = function (oldNode, currentPath) {
1715
+ var nodeSpecs = internalSpec.filter(function (spec) {
1716
+ return shallowEqual(currentPath, spec.pathObj.slice(0, currentPath.length));
1717
+ });
1718
+ var node = oldNode !== null && oldNode !== void 0 ? oldNode : new StateSpecNode(nodeSpecs);
1719
+ node.setSpecs(nodeSpecs);
1720
+ var oldEdges = oldNode === null || oldNode === void 0 ? void 0 : oldNode.edges();
1721
+ node.clearEdges();
1722
+ node.getAllSpecs().forEach(function (spec) {
1723
+ if (spec.pathObj.length > currentPath.length) {
1724
+ var nextKey = spec.pathObj[currentPath.length];
1725
+ if (!node.hasEdge(nextKey)) {
1726
+ node.addEdge(nextKey, rec(oldEdges === null || oldEdges === void 0 ? void 0 : oldEdges.get(nextKey), tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(currentPath), false), [nextKey], false)));
1727
+ }
1728
+ }
1729
+ });
1730
+ return node;
1731
+ };
1732
+ return rec(root, []);
1733
+ }
1734
+ function getSpecTreeLeaves(root) {
1735
+ var leaves = [];
1736
+ var rec = function (node) {
1737
+ var e_1, _a;
1738
+ try {
1739
+ for (var _b = tslib.__values(node.children()), _c = _b.next(); !_c.done; _c = _b.next()) {
1740
+ var child = _c.value;
1741
+ rec(child);
1742
+ }
1743
+ }
1744
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1745
+ finally {
1746
+ try {
1747
+ if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
1748
+ }
1749
+ finally { if (e_1) throw e_1.error; }
1750
+ }
1751
+ if (node.isLeaf() && node.getAllSpecs().length > 0) {
1752
+ leaves.push(node);
1753
+ }
1754
+ };
1755
+ rec(root);
1756
+ return leaves;
1757
+ }
1758
+ function findStateCell(root, pathStr, repetitionIndex) {
1759
+ var e_2, _a;
1760
+ var realPath = [];
1761
+ var pathObj = transformPathStringToObj(pathStr);
1762
+ var currRepIndex = 0;
1763
+ try {
1764
+ for (var pathObj_1 = tslib.__values(pathObj), pathObj_1_1 = pathObj_1.next(); !pathObj_1_1.done; pathObj_1_1 = pathObj_1.next()) {
1765
+ var part = pathObj_1_1.value;
1766
+ if (typeof part === "symbol") {
1767
+ if (!root.hasArrayTransition() ||
1768
+ !repetitionIndex ||
1769
+ currRepIndex > repetitionIndex.length) {
1770
+ throw new Error("transition not found: pathStr ".concat(pathStr, " part ").concat(typeof part === "symbol" ? "[]" : part));
1771
+ }
1772
+ realPath.push(repetitionIndex[currRepIndex++]);
1773
+ root = root.makeTransition(ARRAY_SYMBOL);
1774
+ }
1775
+ else {
1776
+ if (!root.hasEdge(part)) {
1777
+ throw new Error("transition not found: pathStr ".concat(pathStr, " part ").concat(typeof part === "symbol" ? "[]" : part));
1778
+ }
1779
+ realPath.push(part);
1780
+ root = root.makeTransition(part);
1781
+ }
1782
+ }
1783
+ }
1784
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1785
+ finally {
1786
+ try {
1787
+ if (pathObj_1_1 && !pathObj_1_1.done && (_a = pathObj_1["return"])) _a.call(pathObj_1);
1788
+ }
1789
+ finally { if (e_2) throw e_2.error; }
1790
+ }
1791
+ return {
1792
+ node: root,
1793
+ realPath: realPath
1794
+ };
1795
+ }
1796
+
1797
+ function isNum$1(value) {
1798
+ return typeof value === "symbol" ? false : !isNaN(+value);
1799
+ }
1800
+ function canProxy(value) {
1801
+ return typeof value === "object" && value != null;
1802
+ }
1803
+ var proxyObjToStateCell = new WeakMap();
1804
+ var valtioSubscriptions = new WeakMap();
1805
+ function ensureStateCell(target, property, path, node) {
1806
+ var _a;
1807
+ if (!proxyObjToStateCell.has(target)) {
1808
+ proxyObjToStateCell.set(target, {});
1809
+ }
1810
+ var stateCell = proxyObjToStateCell.get(target);
1811
+ if (!(property in stateCell)) {
1812
+ stateCell[property] = {
1813
+ listeners: [],
1814
+ initialValue: UNINITIALIZED,
1815
+ path: path,
1816
+ node: node,
1817
+ initFunc: node.getSpec().initFunc,
1818
+ initFuncHash: (_a = node.getSpec().initFuncHash) !== null && _a !== void 0 ? _a : ""
1819
+ };
1820
+ }
1821
+ return stateCell[property];
1822
+ }
1823
+ function getStateCell(target, property) {
1824
+ var _a;
1825
+ return (_a = proxyObjToStateCell.get(target)) === null || _a === void 0 ? void 0 : _a[property];
1826
+ }
1827
+ function tryGetStateCellFrom$StateRoot($state, path) {
1828
+ if (path.length === 0) {
1829
+ throw new UnknownError("expected a path with length greater than 0");
1830
+ }
1831
+ var target = get__default['default']($state, path.slice(0, -1));
1832
+ get__default['default'](target, path.slice(-1)); // create state cell;
1833
+ return getStateCell(target, path.slice(-1)[0]);
1834
+ }
1835
+ function getStateCellFrom$StateRoot($state, path) {
1836
+ return ensure(tryGetStateCellFrom$StateRoot($state, path));
1837
+ }
1838
+ function unsubscribeToValtio($$state, statePath) {
1839
+ var _a;
1840
+ var oldValue = get__default['default']($$state.stateValues, statePath);
1841
+ if (valtio.getVersion(oldValue)) {
1842
+ (_a = valtioSubscriptions.get(oldValue)) === null || _a === void 0 ? void 0 : _a.forEach(function (f) { return f(); });
1843
+ valtioSubscriptions["delete"](oldValue);
1844
+ }
1845
+ }
1846
+ function subscribeToValtio($$state, statePath, node) {
1847
+ var spec = node.getSpec();
1848
+ var maybeValtioProxy = spec.valueProp
1849
+ ? $$state.env.$props[spec.valueProp]
1850
+ : get__default['default']($$state.stateValues, statePath);
1851
+ if (valtio.getVersion(maybeValtioProxy) && spec.onChangeProp) {
1852
+ var unsub = valtio.subscribe(maybeValtioProxy, function () {
1853
+ var _a, _b;
1854
+ (_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, spec.valueProp
1855
+ ? $$state.env.$props[spec.valueProp]
1856
+ : get__default['default']($$state.stateValues, statePath));
1857
+ });
1858
+ if (!valtioSubscriptions.has(maybeValtioProxy)) {
1859
+ valtioSubscriptions.set(maybeValtioProxy, []);
1860
+ }
1861
+ ensure(valtioSubscriptions.get(maybeValtioProxy)).push(unsub);
1862
+ }
1863
+ }
1864
+ function initializeStateValue($$state, initialStateCell, proxyRoot) {
1865
+ var _a, _b, _c;
1866
+ var initialStateName = initialStateCell.node.getSpec().path;
1867
+ var stateAccess = new Set();
1868
+ $$state.stateInitializationEnv.visited.add(initialStateName);
1869
+ $$state.stateInitializationEnv.stack.push(initialStateName);
1870
+ var $state = create$StateProxy($$state, function (internalStateCell) { return ({
1871
+ get: function () {
1872
+ var spec = internalStateCell.node.getSpec();
1873
+ if ($$state.stateInitializationEnv.visited.has(spec.path)) {
1874
+ // cyclic reference found
1875
+ var stateAccessCycle = [spec.path];
1876
+ while ($$state.stateInitializationEnv.stack.length > 0) {
1877
+ var curr = $$state.stateInitializationEnv.stack.pop();
1878
+ if (!curr) {
1879
+ break;
1880
+ }
1881
+ stateAccessCycle.push(curr);
1882
+ if (curr === spec.path) {
1883
+ throw new CyclicStatesReferencesError(stateAccessCycle);
1884
+ }
1885
+ }
1886
+ throw new UnknownError("Internal error: cycle not found");
1887
+ }
1888
+ var stateCell = getStateCellFrom$StateRoot(proxyRoot, internalStateCell.path);
1889
+ stateAccess.add({ stateCell: stateCell });
1890
+ if (spec.valueProp) {
1891
+ return $$state.env.$props[spec.valueProp];
1892
+ }
1893
+ else if (spec.initFunc && stateCell.initialValue === UNINITIALIZED) {
1894
+ return initializeStateValue($$state, stateCell, proxyRoot);
1895
+ }
1896
+ return get__default['default'](proxyRoot, stateCell.path);
1897
+ },
1898
+ set: function () {
1899
+ throw new InvalidOperation("Cannot update state values during initialization");
1900
+ }
1901
+ }); });
1902
+ stateAccess.forEach(function (_a) {
1903
+ var stateCell = _a.stateCell;
1904
+ stateCell.listeners.push(function () {
1905
+ var _a;
1906
+ var newValue = invokeInitFuncBackwardsCompatible(initialStateCell.node.getSpec().initFunc, tslib.__assign({ $state: $state }, ((_a = initialStateCell.overrideEnv) !== null && _a !== void 0 ? _a : $$state.env)));
1907
+ set(proxyRoot, initialStateCell.path, newValue);
1908
+ });
1909
+ });
1910
+ var initialValue = invokeInitFuncBackwardsCompatible(initialStateCell.initFunc, tslib.__assign({ $state: $state }, ((_a = initialStateCell.overrideEnv) !== null && _a !== void 0 ? _a : $$state.env)));
1911
+ initialStateCell.initialValue = clone__default['default'](initialValue);
1912
+ var initialSpec = initialStateCell.node.getSpec();
1913
+ var value = initialSpec.isImmutable
1914
+ ? mkUntrackedValue(initialValue)
1915
+ : clone__default['default'](initialValue);
1916
+ set(proxyRoot, initialStateCell.path, value);
1917
+ //immediately fire onChange
1918
+ if (initialSpec.onChangeProp) {
1919
+ (_c = (_b = $$state.env.$props)[initialSpec.onChangeProp]) === null || _c === void 0 ? void 0 : _c.call(_b, initialValue);
1920
+ }
1921
+ $$state.stateInitializationEnv.visited["delete"](initialStateName);
1922
+ $$state.stateInitializationEnv.stack.pop();
1923
+ return initialValue;
1924
+ }
1925
+ function create$StateProxy($$state, leafHandlers) {
1926
+ var proxyRoot;
1927
+ var rec = function (currPath, currNode) {
1928
+ var getNextPath = function (property) { return tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(currPath), false), [
1929
+ isNum$1(property) ? +property : property,
1930
+ ], false); };
1931
+ var spec = currNode.getSpec();
1932
+ var handlers = {
1933
+ deleteProperty: function (target, property) {
1934
+ var _a, _b;
1935
+ if (!currNode.isLeaf() &&
1936
+ !currNode.hasArrayTransition() &&
1937
+ !isNum$1(property)) {
1938
+ throw new InvalidOperation("Can't delete a property in the middle of the state spec");
1939
+ }
1940
+ delete get__default['default']($$state.stateValues, currPath)[property];
1941
+ if (spec.onChangeProp) {
1942
+ //we are always in a leaf, since we only have two cases:
1943
+ // 1 - delete properties outside the state tree
1944
+ // 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
1945
+ (_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, get__default['default'](proxyRoot, currPath.slice(spec.pathObj.length)));
1946
+ }
1947
+ return Reflect.deleteProperty(target, property);
1948
+ },
1949
+ get: function (target, property, receiver) {
1950
+ var _a, _b;
1951
+ if (property === PLASMIC_STATE_PROXY_SYMBOL) {
1952
+ return {
1953
+ node: currNode,
1954
+ path: currPath
1955
+ };
1956
+ }
1957
+ var nextPath = getNextPath(property);
1958
+ var nextNode = currNode.makeTransition(property);
1959
+ if (nextNode === null || nextNode === void 0 ? void 0 : nextNode.isLeaf()) {
1960
+ return (_b = (_a = leafHandlers(ensureStateCell(receiver, property, nextPath, nextNode))).get) === null || _b === void 0 ? void 0 : _b.call(_a, target, property, receiver);
1961
+ }
1962
+ else if (nextNode && !(property in target)) {
1963
+ target[property] = rec(nextPath, nextNode);
1964
+ }
1965
+ return Reflect.get(target, property, receiver);
1966
+ },
1967
+ set: function (target, property, value, receiver) {
1968
+ var _a, _b, _c, _d;
1969
+ var nextPath = getNextPath(property);
1970
+ var nextNode = currNode.makeTransition(property);
1971
+ var nextSpec = nextNode === null || nextNode === void 0 ? void 0 : nextNode.getSpec();
1972
+ if (property === "registerInitFunc" && currPath.length === 0) {
1973
+ return Reflect.set(target, property, value, receiver);
1974
+ }
1975
+ if (!nextNode && currNode.hasArrayTransition()) {
1976
+ set($$state.stateValues, nextPath, value);
1977
+ //array can set his own properties such as length, map, ...
1978
+ return Reflect.set(target, property, value, receiver);
1979
+ }
1980
+ if (nextNode === null || nextNode === void 0 ? void 0 : nextNode.isLeaf()) {
1981
+ (_b = (_a = leafHandlers(ensureStateCell(receiver, property, nextPath, nextNode))).set) === null || _b === void 0 ? void 0 : _b.call(_a, target, property, value, receiver);
1982
+ Reflect.set(target, property, value, receiver);
1983
+ if (nextSpec === null || nextSpec === void 0 ? void 0 : nextSpec.onChangeProp) {
1984
+ (_d = (_c = $$state.env.$props)[nextSpec.onChangeProp]) === null || _d === void 0 ? void 0 : _d.call(_c, value);
1985
+ }
1986
+ }
1987
+ if (!nextNode) {
1988
+ // can't set an unknown field in $state
1989
+ return false;
1990
+ }
1991
+ if (canProxy(value) && !nextNode.isLeaf()) {
1992
+ target[property] = rec(nextPath, nextNode);
1993
+ Reflect.ownKeys(value).forEach(function (key) {
1994
+ target[property][key] = value[key];
1995
+ });
1996
+ }
1997
+ else if (!nextNode.isLeaf()) {
1998
+ throw new InvalidOperation("inserting a primitive value into a non-leaf");
1999
+ }
2000
+ var newValue = nextNode.isLeaf() && (nextSpec === null || nextSpec === void 0 ? void 0 : nextSpec.isImmutable)
2001
+ ? mkUntrackedValue(value)
2002
+ : value;
2003
+ unsubscribeToValtio($$state, nextPath);
2004
+ set($$state.stateValues, nextPath, newValue);
2005
+ subscribeToValtio($$state, nextPath, nextNode);
2006
+ return true;
2007
+ }
2008
+ };
2009
+ var baseObject = currNode.hasArrayTransition() ? [] : {};
2010
+ var proxyObj = new Proxy(baseObject, handlers);
2011
+ if (currPath.length === 0) {
2012
+ proxyRoot = proxyObj;
2013
+ }
2014
+ return proxyObj;
2015
+ };
2016
+ return rec([], $$state.rootSpecTree);
2017
+ }
2018
+ var mkUntrackedValue = function (o) {
2019
+ return o != null && typeof o === "object" ? valtio.ref(o) : o;
2020
+ };
2021
+ var envFieldsAreNonNill = function (env) {
2022
+ var _a, _b;
2023
+ return ({
2024
+ $props: env.$props,
2025
+ $ctx: (_a = env.$ctx) !== null && _a !== void 0 ? _a : {},
2026
+ $queries: (_b = env.$queries) !== null && _b !== void 0 ? _b : {}
2027
+ });
2028
+ };
2029
+ /**
2030
+ * We need to support two versions with different parameters to be backward compatible
2031
+ * {
2032
+ * specs: $StateSpec<any>[],
2033
+ * props: Record<string, any>,
2034
+ * $ctx?: Record<string, any>,
2035
+ * opts?: { inCanvas: boolean; }
2036
+ * }
2037
+ * {
2038
+ * specs: $StateSpec<any>[],
2039
+ * env: { $props; $queries; $ctx },
2040
+ * opts?: { inCanvas: boolean }
2041
+ * }
2042
+ */
2043
+ function extractDollarStateParametersBackwardCompatible() {
2044
+ var rest = [];
2045
+ for (var _i = 0; _i < arguments.length; _i++) {
2046
+ rest[_i] = arguments[_i];
2047
+ }
2048
+ if ("$props" in rest[0]) {
2049
+ // latest version
2050
+ return {
2051
+ env: rest[0],
2052
+ opts: rest[1]
2053
+ };
2054
+ }
2055
+ else {
2056
+ return {
2057
+ env: {
2058
+ $props: rest[0],
2059
+ $ctx: rest[1],
2060
+ $queries: {}
2061
+ },
2062
+ opts: rest[2]
2063
+ };
2064
+ }
2065
+ }
2066
+ function invokeInitFuncBackwardsCompatible(initFunc, env) {
2067
+ if (initFunc.length > 1) {
2068
+ return initFunc(env.$props, env.$state, env.$ctx);
2069
+ }
2070
+ else {
2071
+ return initFunc(env);
2072
+ }
2073
+ }
2074
+ function useDollarState(specs) {
2075
+ var rest = [];
2076
+ for (var _i = 1; _i < arguments.length; _i++) {
2077
+ rest[_i - 1] = arguments[_i];
2078
+ }
2079
+ var _a = extractDollarStateParametersBackwardCompatible.apply(void 0, tslib.__spreadArray([], tslib.__read(rest), false)), env = _a.env, opts = _a.opts;
2080
+ var $$state = React__default['default'].useRef((function () {
2081
+ var rootSpecTree = buildTree(specs);
2082
+ return {
2083
+ rootSpecTree: rootSpecTree,
2084
+ specTreeLeaves: getSpecTreeLeaves(rootSpecTree),
2085
+ stateValues: valtio.proxy({}),
2086
+ env: envFieldsAreNonNill(env),
2087
+ specs: [],
2088
+ registrationsQueue: valtio.proxy([]),
2089
+ stateInitializationEnv: { stack: [], visited: new Set() }
2090
+ };
2091
+ })()).current;
2092
+ $$state.env = envFieldsAreNonNill(env);
2093
+ $$state.specs = specs;
2094
+ var create$State = React__default['default'].useCallback(function () {
2095
+ var $state = Object.assign(create$StateProxy($$state, function (stateCell) {
2096
+ var spec = stateCell.node.getSpec();
2097
+ if (stateCell.initialValue === UNINITIALIZED && spec.initFunc) {
2098
+ initializeStateValue($$state, stateCell, $state);
2099
+ }
2100
+ else if (stateCell.initialValue === UNINITIALIZED &&
2101
+ !spec.valueProp) {
2102
+ stateCell.initialValue = spec.initVal;
2103
+ set($state, stateCell.path, spec.initVal);
2104
+ }
2105
+ return {
2106
+ get: function () {
2107
+ var spec = stateCell.node.getSpec();
2108
+ if (spec.valueProp) {
2109
+ var valueProp = $$state.env.$props[spec.valueProp];
2110
+ subscribeToValtio($$state, stateCell.path, stateCell.node);
2111
+ return valueProp;
2112
+ }
2113
+ else {
2114
+ return get__default['default']($$state.stateValues, stateCell.path);
2115
+ }
2116
+ }
2117
+ };
2118
+ }), {
2119
+ registerInitFunc: function (pathStr, f, repetitionIndex, overrideEnv) {
2120
+ var _a = findStateCell($$state.rootSpecTree, pathStr, repetitionIndex), node = _a.node, realPath = _a.realPath;
2121
+ var stateCell = getStateCellFrom$StateRoot($state, realPath);
2122
+ var env = overrideEnv
2123
+ ? envFieldsAreNonNill(overrideEnv)
2124
+ : $$state.env;
2125
+ if (!deepEqual__default['default'](stateCell.initialValue, f(tslib.__assign({ $state: $state }, env)))) {
2126
+ $$state.registrationsQueue.push(mkUntrackedValue({
2127
+ node: node,
2128
+ path: realPath,
2129
+ f: f,
2130
+ overrideEnv: overrideEnv
2131
+ ? envFieldsAreNonNill(overrideEnv)
2132
+ : undefined
2133
+ }));
2134
+ }
2135
+ }
2136
+ });
2137
+ return $state;
2138
+ }, []);
2139
+ var ref = React__default['default'].useRef(undefined);
2140
+ if (!ref.current) {
2141
+ ref.current = create$State();
2142
+ }
2143
+ var $state = ref.current;
2144
+ if (opts === null || opts === void 0 ? void 0 : opts.inCanvas) {
2145
+ $$state.rootSpecTree = updateTree($$state.rootSpecTree, specs);
2146
+ var newLeaves = getSpecTreeLeaves($$state.rootSpecTree);
2147
+ if (!arrayEq(newLeaves, $$state.specTreeLeaves)) {
2148
+ var old$state_1 = $state;
2149
+ $state = ref.current = create$State();
2150
+ $$state.specTreeLeaves = newLeaves;
2151
+ getStateCells(old$state_1, $$state.rootSpecTree).forEach(function (_a) {
2152
+ var path = _a.path;
2153
+ var oldStateCell = tryGetStateCellFrom$StateRoot(old$state_1, path);
2154
+ if (oldStateCell) {
2155
+ set($state, path, get__default['default'](old$state_1, path));
2156
+ var newStateCell = getStateCellFrom$StateRoot($state, path);
2157
+ newStateCell.initialValue = oldStateCell.initialValue;
2158
+ }
2159
+ });
2160
+ }
2161
+ // we need to eager initialize all states in canvas to populate the data picker
2162
+ $$state.specTreeLeaves.forEach(function (node) {
2163
+ var _a, _b;
2164
+ var spec = node.getSpec();
2165
+ if (spec.isRepeated) {
2166
+ return;
2167
+ }
2168
+ var stateCell = getStateCellFrom$StateRoot($state, spec.pathObj);
2169
+ var newSpec = specs.find(function (sp) { return sp.path === spec.path; });
2170
+ if (!newSpec ||
2171
+ (stateCell.initFuncHash === ((_a = newSpec === null || newSpec === void 0 ? void 0 : newSpec.initFuncHash) !== null && _a !== void 0 ? _a : "") &&
2172
+ stateCell.initialValue !== UNINITIALIZED)) {
2173
+ return;
2174
+ }
2175
+ stateCell.initFunc = newSpec.initFunc;
2176
+ stateCell.initFuncHash = (_b = newSpec.initFuncHash) !== null && _b !== void 0 ? _b : "";
2177
+ var init = spec.valueProp
2178
+ ? $$state.env.$props[spec.valueProp]
2179
+ : spec.initFunc
2180
+ ? initializeStateValue($$state, stateCell, $state)
2181
+ : spec.initVal;
2182
+ set($state, spec.pathObj, init);
2183
+ });
2184
+ }
2185
+ // For each spec with an initFunc, evaluate it and see if
2186
+ // the init value has changed. If so, reset its state.
2187
+ var resetSpecs = [];
2188
+ getStateCells($state, $$state.rootSpecTree).forEach(function (stateCell) {
2189
+ var _a;
2190
+ if (stateCell.initFunc) {
2191
+ var newInit = invokeInitFuncBackwardsCompatible(stateCell.initFunc, tslib.__assign({ $state: $state }, ((_a = stateCell.overrideEnv) !== null && _a !== void 0 ? _a : envFieldsAreNonNill(env))));
2192
+ if (!deepEqual__default['default'](newInit, stateCell.initialValue)) {
2193
+ resetSpecs.push({ stateCell: stateCell });
2194
+ }
2195
+ }
2196
+ });
2197
+ var reInitializeState = function (stateCell) {
2198
+ var _a, _b;
2199
+ var newInit = initializeStateValue($$state, stateCell, $state);
2200
+ var spec = stateCell.node.getSpec();
2201
+ if (spec.onChangeProp) {
2202
+ (_b = (_a = $$state.env.$props)[spec.onChangeProp]) === null || _b === void 0 ? void 0 : _b.call(_a, newInit);
2203
+ }
2204
+ };
2205
+ useIsomorphicLayoutEffect(function () {
2206
+ resetSpecs.forEach(function (_a) {
2207
+ var stateCell = _a.stateCell;
2208
+ reInitializeState(stateCell);
2209
+ });
2210
+ }, [env.$props, resetSpecs]);
2211
+ useIsomorphicLayoutEffect(function () {
2212
+ while ($$state.registrationsQueue.length) {
2213
+ var _a = $$state.registrationsQueue.shift(), path = _a.path, f = _a.f, overrideEnv = _a.overrideEnv;
2214
+ var stateCell = getStateCellFrom$StateRoot($state, path);
2215
+ stateCell.initFunc = f;
2216
+ stateCell.overrideEnv = overrideEnv;
2217
+ reInitializeState(stateCell);
2218
+ }
2219
+ }, [$$state.registrationsQueue.length]);
2220
+ // immediately initialize exposed non-private states
2221
+ useIsomorphicLayoutEffect(function () {
2222
+ $$state.specTreeLeaves.forEach(function (node) {
2223
+ var spec = node.getSpec();
2224
+ if (!spec.isRepeated && spec.type !== "private" && spec.initFunc) {
2225
+ var stateCell = getStateCellFrom$StateRoot($state, spec.pathObj);
2226
+ initializeStateValue($$state, stateCell, $state);
2227
+ }
2228
+ });
2229
+ }, []);
2230
+ // Re-render if any value changed in one of these objects
2231
+ valtio.useSnapshot($$state.stateValues, { sync: true });
2232
+ valtio.useSnapshot($$state.registrationsQueue, { sync: true });
2233
+ return $state;
2234
+ }
2235
+
2236
+ function initializeCodeComponentStates($state, states, repetitionIndex, componentHelpers, child$Props) {
2237
+ var e_1, _a;
2238
+ var _b, _c;
2239
+ var stateHelpers = (_b = componentHelpers === null || componentHelpers === void 0 ? void 0 : componentHelpers.states) !== null && _b !== void 0 ? _b : {};
2240
+ var _loop_1 = function (name_1, plasmicStateName) {
2241
+ if (name_1 in stateHelpers && "initFunc" in stateHelpers[name_1]) {
2242
+ (_c = $state.registerInitFunc) === null || _c === void 0 ? void 0 : _c.call($state, plasmicStateName, function (_a) {
2243
+ var _b, _c;
2244
+ var $props = _a.$props;
2245
+ return (_c = (_b = stateHelpers[name_1]).initFunc) === null || _c === void 0 ? void 0 : _c.call(_b, $props);
2246
+ }, repetitionIndex !== null && repetitionIndex !== void 0 ? repetitionIndex : [], { $props: child$Props });
2247
+ }
2248
+ };
2249
+ try {
2250
+ for (var states_1 = tslib.__values(states), states_1_1 = states_1.next(); !states_1_1.done; states_1_1 = states_1.next()) {
2251
+ var _d = states_1_1.value, name_1 = _d.name, plasmicStateName = _d.plasmicStateName;
2252
+ _loop_1(name_1, plasmicStateName);
2253
+ }
2254
+ }
2255
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2256
+ finally {
2257
+ try {
2258
+ if (states_1_1 && !states_1_1.done && (_a = states_1["return"])) _a.call(states_1);
2259
+ }
2260
+ finally { if (e_1) throw e_1.error; }
2261
+ }
2262
+ }
2263
+ function initializePlasmicStates($state, states, repetitionIndex) {
2264
+ var e_2, _a;
2265
+ var _b;
2266
+ try {
2267
+ for (var states_2 = tslib.__values(states), states_2_1 = states_2.next(); !states_2_1.done; states_2_1 = states_2.next()) {
2268
+ var _c = states_2_1.value, name_2 = _c.name, initFunc = _c.initFunc;
2269
+ (_b = $state.registerInitFunc) === null || _b === void 0 ? void 0 : _b.call($state, name_2, initFunc, repetitionIndex !== null && repetitionIndex !== void 0 ? repetitionIndex : []);
2270
+ }
2271
+ }
2272
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2273
+ finally {
2274
+ try {
2275
+ if (states_2_1 && !states_2_1.done && (_a = states_2["return"])) _a.call(states_2);
2276
+ }
2277
+ finally { if (e_2) throw e_2.error; }
2278
+ }
2279
+ }
2280
+ function generateStateOnChangeProp($state, path) {
2281
+ return function (val) { return set($state, path, val); };
2282
+ }
2283
+ function generateStateOnChangePropForCodeComponents($state, stateName, plasmicStatePath, componentHelpers) {
2284
+ var _a, _b;
2285
+ 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;
2286
+ if (!onChangeArgsToValue || typeof onChangeArgsToValue !== "function") {
2287
+ return generateStateOnChangeProp($state, plasmicStatePath);
2288
+ }
2289
+ return function () {
2290
+ var args = [];
2291
+ for (var _i = 0; _i < arguments.length; _i++) {
2292
+ args[_i] = arguments[_i];
2293
+ }
2294
+ return generateStateOnChangeProp($state, plasmicStatePath)(onChangeArgsToValue.apply(null, args));
2295
+ };
2296
+ }
2297
+ function generateStateValueProp($state, path) {
2298
+ return get__default['default']($state, path);
2299
+ }
2300
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
2301
+ function isPlasmicStateProxy(obj) {
2302
+ return (obj != null && typeof obj === "object" && !!obj[PLASMIC_STATE_PROXY_SYMBOL]);
2303
+ }
2304
+ function is$StateProxy(obj) {
2305
+ return (obj != null &&
2306
+ typeof obj === "object" &&
2307
+ (!!obj[PLASMIC_STATE_PROXY_SYMBOL] || valtio.getVersion(obj)));
2308
+ }
2309
+ function getStateCells($state, root) {
2310
+ var e_3, _a;
2311
+ var _b;
2312
+ if ($state == null || typeof $state !== "object") {
2313
+ return [];
2314
+ }
2315
+ if (root.hasArrayTransition()) {
2316
+ return Object.keys($state).flatMap(function (key) {
2317
+ return getStateCells($state[key], ensure(root.makeTransition(ARRAY_SYMBOL)));
2318
+ });
2319
+ }
2320
+ else {
2321
+ var stateCell = (_b = proxyObjToStateCell.get($state)) !== null && _b !== void 0 ? _b : {};
2322
+ var stateCells = [];
2323
+ try {
2324
+ for (var _c = tslib.__values(root.edges().entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
2325
+ var _e = tslib.__read(_d.value, 2), key = _e[0], child = _e[1];
2326
+ if (typeof key === "string" && key in $state) {
2327
+ stateCells.push.apply(stateCells, tslib.__spreadArray([], tslib.__read(getStateCells($state[key], child)), false));
2328
+ if (key in stateCell) {
2329
+ stateCells.push(stateCell[key]);
2330
+ }
2331
+ }
2332
+ }
2333
+ }
2334
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
2335
+ finally {
2336
+ try {
2337
+ if (_d && !_d.done && (_a = _c["return"])) _a.call(_c);
2338
+ }
2339
+ finally { if (e_3) throw e_3.error; }
2340
+ }
2341
+ return stateCells;
2342
+ }
2343
+ }
2344
+ function getStateCellsInPlasmicProxy(obj) {
2345
+ if (!isPlasmicStateProxy(obj)) {
2346
+ return [];
2347
+ }
2348
+ var _a = obj[PLASMIC_STATE_PROXY_SYMBOL], rootNode = _a.node, rootPath = _a.path, isOutside = _a.isOutside;
2349
+ if (isOutside) {
2350
+ return [];
2351
+ }
2352
+ return getStateCells(obj, rootNode).map(function (stateCell) { return ({
2353
+ path: stateCell.node.getSpec().path,
2354
+ realPath: stateCell.path.slice(rootPath.length)
2355
+ }); });
2356
+ }
2357
+ function getStateSpecInPlasmicProxy(obj, path) {
2358
+ obj = get__default['default'](obj, path.slice(0, path.length - 1));
2359
+ if (!isPlasmicStateProxy(obj)) {
2360
+ return undefined;
2361
+ }
2362
+ var node = obj[PLASMIC_STATE_PROXY_SYMBOL].node;
2363
+ var nextNode = node.makeTransition(path[path.length - 1]);
2364
+ if (node.isLeaf() || !nextNode) {
2365
+ return undefined;
2366
+ }
2367
+ return {
2368
+ spec: nextNode.getSpec(),
2369
+ isImplicitStateArray: nextNode.hasArrayTransition()
2370
+ };
2371
+ }
2372
+ function getCurrentInitialValue(obj, path) {
2373
+ var _a;
2374
+ if (!isPlasmicStateProxy(obj)) {
2375
+ return undefined;
2376
+ }
2377
+ return (_a = tryGetStateCellFrom$StateRoot(obj, path)) === null || _a === void 0 ? void 0 : _a.initialValue;
2378
+ }
2379
+ function resetToInitialValue(obj, path) {
2380
+ var stateCell = tryGetStateCellFrom$StateRoot(obj, path);
2381
+ if (stateCell) {
2382
+ set(obj, path, stateCell.initialValue);
2383
+ }
2384
+ }
2385
+ function shallowEqual(a1, a2) {
2386
+ if (a1.length !== a2.length) {
2387
+ return false;
2388
+ }
2389
+ for (var i = 0; i < a1.length; i++) {
2390
+ if (a1[i] !== a2[i]) {
2391
+ return false;
2392
+ }
2393
+ }
2394
+ return true;
2395
+ }
2396
+ /**
2397
+ * Shallow comparison of arrays.
2398
+ */
2399
+ function arrayEq(xs, ys) {
2400
+ return (xs.length === ys.length && xs.every(function (_, index) { return xs[index] === ys[index]; }));
2401
+ }
2402
+ function isNum(value) {
2403
+ return typeof value === "symbol" ? false : !isNaN(+value);
2404
+ }
2405
+ /**
2406
+ * Forked from https://github.com/lukeed/dset
2407
+ * Changes: fixed setting a deep value to a proxy object
2408
+ */
2409
+ function set(obj, keys, val) {
2410
+ keys = keys.split ? keys.split(".") : keys;
2411
+ var i = 0, l = keys.length, t = obj, x, k;
2412
+ while (i < l) {
2413
+ k = keys[i++];
2414
+ if (k === "__proto__" || k === "constructor" || k === "prototype")
2415
+ break;
2416
+ var newValue = i === l
2417
+ ? val
2418
+ : typeof (x = t[k]) === typeof keys
2419
+ ? x
2420
+ : keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")
2421
+ ? {}
2422
+ : [];
2423
+ assignValue(t, k, newValue);
2424
+ t = t[k];
2425
+ }
2426
+ }
2427
+ /**
2428
+ * Forked from lodash
2429
+ */
2430
+ function baseAssignValue(object, key, value) {
2431
+ if (key == "__proto__") {
2432
+ Object.defineProperty(object, key, {
2433
+ configurable: true,
2434
+ enumerable: true,
2435
+ value: value,
2436
+ writable: true
2437
+ });
2438
+ }
2439
+ else {
2440
+ object[key] = value;
2441
+ }
2442
+ }
2443
+ function eq(value, other) {
2444
+ return value === other || (value !== value && other !== other);
2445
+ }
2446
+ function assignValue(object, key, value) {
2447
+ var objValue = object[key];
2448
+ if (!(Object.prototype.hasOwnProperty.call(object, key) && eq(objValue, value)) ||
2449
+ (value === undefined && !(key in object))) {
2450
+ baseAssignValue(object, key, value);
2451
+ }
2452
+ }
2453
+
2454
+ // Utilities used by generated code
2455
+ var classNames = classNames__default['default'];
2456
+
2457
+ var PLUME_STRICT_MODE = true;
2458
+ function setPlumeStrictMode(mode) {
2459
+ PLUME_STRICT_MODE = mode;
2460
+ }
2461
+ function mergeVariantToggles() {
2462
+ var toggles = [];
2463
+ for (var _i = 0; _i < arguments.length; _i++) {
2464
+ toggles[_i] = arguments[_i];
2465
+ }
2466
+ var definedToggles = toggles.filter(function (x) { return !!x.def; });
2467
+ var grouped = groupBy(definedToggles, function (_a) {
2468
+ var def = _a.def;
2469
+ return def.group;
2470
+ });
2471
+ return mapValues(grouped, function (subToggles) {
2472
+ return Object.fromEntries(subToggles.map(function (_a) {
2473
+ var def = _a.def, active = _a.active;
2474
+ return [def.variant, !!active];
2475
+ }));
2476
+ });
2477
+ }
2478
+ function noOutline() {
2479
+ return { outline: "none" };
2480
+ }
2481
+ function getPlumeType(child) {
2482
+ var _a;
2483
+ if (!React__namespace.isValidElement(child)) {
2484
+ return undefined;
2485
+ }
2486
+ var childType = child.type;
2487
+ return (childType.__plumeType || ((_a = childType.getPlumeType) === null || _a === void 0 ? void 0 : _a.call(childType, child.props)));
2488
+ }
2489
+
2490
+ function useButton(plasmicClass, props, config, ref) {
2491
+ var _a, _b, _c, _d;
2492
+ if (ref === void 0) { ref = null; }
2493
+ var link = props.link, isDisabled = props.isDisabled, startIcon = props.startIcon, endIcon = props.endIcon, showStartIcon = props.showStartIcon, showEndIcon = props.showEndIcon, children = props.children, rest = tslib.__rest(props, ["link", "isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "children"]);
2494
+ var variants = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.showStartIconVariant, active: showStartIcon }, { def: config.showEndIconVariant, active: showEndIcon }, { def: config.isDisabledVariant, active: isDisabled }));
2495
+ var args = tslib.__assign(tslib.__assign(tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false))), (config.startIconSlot && (_a = {}, _a[config.startIconSlot] = startIcon, _a))), (config.endIconSlot && (_b = {}, _b[config.endIconSlot] = endIcon, _b))), (_c = {}, _c[config.contentSlot] = children, _c));
2496
+ var overrides = (_d = {},
2497
+ _d[config.root] = {
2498
+ as: !!link ? "a" : "button",
2499
+ props: tslib.__assign(tslib.__assign(tslib.__assign({}, omit.apply(void 0, tslib.__spreadArray(tslib.__spreadArray([rest], tslib.__read(plasmicClass.internalArgProps), false), tslib.__read(plasmicClass.internalVariantProps), false))), { ref: ref, disabled: isDisabled }), (!!link && { href: link }))
2500
+ },
2501
+ _d);
2502
+ return {
2503
+ plasmicProps: {
2504
+ variants: variants,
2505
+ args: args,
2506
+ overrides: overrides
2507
+ }
2508
+ };
2509
+ }
2510
+
2511
+ function getStyleProps(props) {
2512
+ return pick(props, "className", "style");
2513
+ }
2514
+ function getDefaultPlasmicProps(plasmicClass, props) {
2515
+ return {
2516
+ plasmicProps: {
2517
+ variants: pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false)),
2518
+ args: pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false)),
2519
+ overrides: {}
2520
+ }
2521
+ };
2522
+ }
2523
+ var RE_DATA_PROP = /^(data-.*)$/;
2524
+ function getDataProps(props) {
2525
+ return pickBy(props, function (k) { return RE_DATA_PROP.test(k); });
2526
+ }
2527
+
2528
+ function asAriaCheckboxProps(props) {
2529
+ var ariaProps = tslib.__assign(tslib.__assign({}, props), { isSelected: props.isChecked, defaultSelected: props.defaultChecked });
2530
+ delete ariaProps["isChecked"];
2531
+ delete ariaProps["defaultChecked"];
2532
+ return ariaProps;
2533
+ }
2534
+ function useCheckbox(plasmicClass, props, config, ref) {
2535
+ var _a, _b;
2536
+ if (ref === void 0) { ref = null; }
2537
+ var children = props.children, isDisabled = props.isDisabled, isIndeterminate = props.isIndeterminate;
2538
+ useEnsureSSRProvider();
2539
+ var inputRef = React__namespace.useRef(null);
2540
+ var rootRef = React__namespace.useRef(null);
2541
+ var ariaProps = asAriaCheckboxProps(props);
2542
+ var state = toggle.useToggleState(ariaProps);
2543
+ var inputProps = checkbox.useCheckbox(ariaProps, state, inputRef).inputProps;
2544
+ var variants = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({
2545
+ def: config.isDisabledVariant,
2546
+ active: isDisabled
2547
+ }, {
2548
+ def: config.isCheckedVariant,
2549
+ active: state.isSelected
2550
+ }, {
2551
+ def: config.isIndeterminateVariant,
2552
+ active: isIndeterminate
2553
+ }, {
2554
+ def: config.noLabelVariant,
2555
+ active: !children
2556
+ }));
2557
+ var overrides = (_a = {},
2558
+ _a[config.root] = {
2559
+ as: "label",
2560
+ props: mergeProps(getStyleProps(props), {
2561
+ ref: rootRef
2562
+ }),
2563
+ wrapChildren: function (children) { return (React__namespace.createElement(React__namespace.Fragment, null,
2564
+ React__namespace.createElement(visuallyHidden.VisuallyHidden, null,
2565
+ React__namespace.createElement("input", tslib.__assign({}, inputProps, { ref: inputRef }))),
2566
+ children)); }
2567
+ },
2568
+ _a);
2569
+ var args = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false))), (config.labelSlot ? (_b = {}, _b[config.labelSlot] = children, _b) : {}));
2570
+ var plumeState = React__namespace.useMemo(function () { return ({
2571
+ setChecked: function (checked) { return state.setSelected(checked); }
2572
+ }); }, [state]);
2573
+ React__namespace.useImperativeHandle(ref, function () { return ({
2574
+ getRoot: function () { return rootRef.current; },
2575
+ focus: function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
2576
+ blur: function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
2577
+ setChecked: function (checked) { return plumeState.setChecked(checked); }
2578
+ }); }, [rootRef, inputRef, plumeState]);
2579
+ return {
2580
+ plasmicProps: {
2581
+ variants: variants,
2582
+ overrides: overrides,
2583
+ args: args
2584
+ },
2585
+ state: plumeState
2586
+ };
2587
+ }
2588
+
2589
+ /**
2590
+ * In general, we try not to expose react-aria's Collections API to Plume users.
2591
+ * The Collections API is how react-aria users pass data about collections of
2592
+ * things using the built-in Item and Section components, which are abstract,
2593
+ * metadata-only components that don't render anything but only serve to specify
2594
+ * data. For example, here's how you would use react-spectrum's Picker:
2595
+ *
2596
+ * <Picker>
2597
+ * <Section title="Asia">
2598
+ * <Item key="taiwan">Taiwan</Item>
2599
+ * <Item key="japan">Japan</Item>
2600
+ * <Item key="china">China</Item>
2601
+ * </Section>
2602
+ * <Section title="Europe">
2603
+ * <Item key="germany">Germany</Item>
2604
+ * <Item key="france">France</Item>
2605
+ * </Section>
2606
+ * </Picker>
2607
+ *
2608
+ * You would re-use this same Item/Section components to pass similar things to
2609
+ * Menu, Tabs, etc.
2610
+ *
2611
+ * For Plasmic, this API is too abstract. The user has explicitly designed components
2612
+ * like Select.Option and Select.OptionGroup, and it is weird that they don't actually
2613
+ * use these components. It is more natural to do:
2614
+ *
2615
+ * <Select>
2616
+ * <Select.OptionGroup title="Asia">
2617
+ * <Select.Option key="taiwan">Taiwan</Select>
2618
+ * </Select.OptionGroup>
2619
+ * </Select>
2620
+ *
2621
+ * For Plume, we let users directly use the components they designed, both to collect
2622
+ * information and to perform actual rendering. For example, for Plume,
2623
+ * you'd use Select.Option instead of Item, and Select.OptionGroup instead of Section.
2624
+ * This means that the Select.Option props will collect the same information Item
2625
+ * does.
2626
+ *
2627
+ * A component like Select.Option then serves two purposes:
2628
+ *
2629
+ * 1. Allow users to specify the collection of data, like in the above example
2630
+ * Here, we're mainly interested in the props in those ReactElements so
2631
+ * we can pass the Item/Section data onto react-aria's APIs. We are not
2632
+ * actually rendering these elements.
2633
+ * 2. Once react-aria's Collections API has gone through them and built
2634
+ * Collection "nodes", we then create cloned versions of these elements
2635
+ * with the corresponding node passed in as a secret prop. These ReactElements
2636
+ * are then actually used to _render_ the corresponding Option / OptionGroup.
2637
+ *
2638
+ * This file contains helper functions to help with implementing the above.
2639
+ *
2640
+ * Note also that most of the collections-based react-aria components expose
2641
+ * a parallel API that accepts a list of "items" and a render prop, instead
2642
+ * of list of Item/Section elements. This is for efficiency, but we are opting
2643
+ * to only support the composite-component pattern for now for simplicity.
2644
+ */
2645
+ function deriveItemsFromProps(props, opts) {
2646
+ if (opts.itemsProp && opts.itemsProp in props) {
2647
+ if (!opts.ItemComponent || !opts.SectionComponent) {
2648
+ throw new Error("You may need to re-generate your Plasmic* files");
2649
+ }
2650
+ var items = props[opts.itemsProp];
2651
+ return deriveItemsFromItemsProp(items, {
2652
+ ItemComponent: opts.ItemComponent,
2653
+ SectionComponent: opts.SectionComponent
2654
+ });
2655
+ }
2656
+ else {
2657
+ return deriveItemsFromChildren(props.children, opts);
2658
+ }
2659
+ }
2660
+ function deriveItemsFromItemsProp(items, opts) {
2661
+ var _a;
2662
+ var ItemComponent = opts.ItemComponent, SectionComponent = opts.SectionComponent;
2663
+ var disabledKeys = [];
2664
+ var transform = function (item) {
2665
+ var _a;
2666
+ if (typeof item === "string") {
2667
+ return (React__default['default'].createElement(ItemComponent, { key: item, value: item }, item));
2668
+ }
2669
+ else if ("children" in item) {
2670
+ return (React__default['default'].createElement(SectionComponent, { key: item.title, title: item.title }, item.children.map(function (x) { return transform(x); })));
2671
+ }
2672
+ else {
2673
+ if (item.isDisabled) {
2674
+ disabledKeys.push(item.value);
2675
+ }
2676
+ return (React__default['default'].createElement(ItemComponent, { key: item.value, value: item.value, textValue: item.textValue, isDisabled: item.isDisabled }, (_a = item.label) !== null && _a !== void 0 ? _a : item.value));
2677
+ }
2678
+ };
2679
+ return {
2680
+ items: (_a = items === null || items === void 0 ? void 0 : items.map(function (x) { return transform(x); })) !== null && _a !== void 0 ? _a : [],
2681
+ disabledKeys: disabledKeys
2682
+ };
2683
+ }
2684
+ /**
2685
+ * Given children of a component like Select or Menu, derive the items
2686
+ * that we will pass into the Collections API. These will be
2687
+ * ReactElement<ItemLikeProps|SectionLikeProps>[].
2688
+ *
2689
+ * Will also assign keys to items by their index in the collection,
2690
+ * and collect the keys of disabled items.
2691
+ */
2692
+ function deriveItemsFromChildren(children, opts) {
2693
+ if (!children) {
2694
+ return {
2695
+ items: [],
2696
+ disabledKeys: []
2697
+ };
2698
+ }
2699
+ var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError;
2700
+ // For Plume items without an explicit key, we assign a key as the index
2701
+ // of the collection.
2702
+ var itemCount = 0;
2703
+ var sectionCount = 0;
2704
+ var ensureValue = function (element) {
2705
+ if (!propInChild(element, "value")) {
2706
+ if (opts.requireItemValue && PLUME_STRICT_MODE) {
2707
+ throw new Error("Must specify a \"value\" prop for ".concat(getElementTypeName(element)));
2708
+ }
2709
+ else {
2710
+ return cloneChild(element, { value: "".concat(itemCount++) });
2711
+ }
2712
+ }
2713
+ else {
2714
+ // Still increment count even if key is present, so that the
2715
+ // auto-assigned key really reflects the index
2716
+ itemCount++;
2717
+ return element;
2718
+ }
2719
+ };
2720
+ var disabledKeys = [];
2721
+ var flattenedChildren = function (children) {
2722
+ return toChildArray(children).flatMap(function (child) {
2723
+ var _a;
2724
+ if (React__default['default'].isValidElement(child)) {
2725
+ if (child.type === React__default['default'].Fragment) {
2726
+ return flattenedChildren(child.props
2727
+ .children);
2728
+ }
2729
+ var type = getPlumeType(child);
2730
+ if (type === itemPlumeType) {
2731
+ child = ensureValue(child);
2732
+ var childKey = getItemLikeKey(child);
2733
+ if (getChildProp(child, "isDisabled") && !!childKey) {
2734
+ disabledKeys.push(childKey);
2735
+ }
2736
+ return [child];
2737
+ }
2738
+ if (type === sectionPlumeType) {
2739
+ return [
2740
+ cloneChild(child, {
2741
+ // key of section doesn't actually matter, just needs
2742
+ // to be unique
2743
+ key: (_a = child.key) !== null && _a !== void 0 ? _a : "section-".concat(sectionCount++),
2744
+ children: flattenedChildren(getChildProp(child, "children"))
2745
+ }),
2746
+ ];
2747
+ }
2748
+ }
2749
+ if (PLUME_STRICT_MODE) {
2750
+ throw new Error(invalidChildError !== null && invalidChildError !== void 0 ? invalidChildError : "Unexpected child");
2751
+ }
2752
+ else {
2753
+ return [];
2754
+ }
2755
+ });
2756
+ };
2757
+ return { items: flattenedChildren(children), disabledKeys: disabledKeys };
2758
+ }
2759
+ function useDerivedItems(props, opts) {
2760
+ var children = props.children;
2761
+ var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError, requireItemValue = opts.requireItemValue, ItemComponent = opts.ItemComponent, SectionComponent = opts.SectionComponent, itemsProp = opts.itemsProp;
2762
+ var items = itemsProp ? props[itemsProp] : undefined;
2763
+ return React__default['default'].useMemo(function () {
2764
+ return deriveItemsFromProps(props, {
2765
+ itemPlumeType: itemPlumeType,
2766
+ sectionPlumeType: sectionPlumeType,
2767
+ invalidChildError: invalidChildError,
2768
+ requireItemValue: requireItemValue,
2769
+ itemsProp: itemsProp,
2770
+ ItemComponent: ItemComponent,
2771
+ SectionComponent: SectionComponent
2772
+ });
2773
+ }, [
2774
+ children,
2775
+ items,
2776
+ itemPlumeType,
2777
+ sectionPlumeType,
2778
+ invalidChildError,
2779
+ requireItemValue,
2780
+ ItemComponent,
2781
+ SectionComponent,
2782
+ ]);
2783
+ }
2784
+ function useDerivedItemsFromChildren(children, opts) {
2785
+ var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError, requireItemValue = opts.requireItemValue;
2786
+ return React__default['default'].useMemo(function () {
2787
+ return deriveItemsFromChildren(children, {
2788
+ itemPlumeType: itemPlumeType,
2789
+ sectionPlumeType: sectionPlumeType,
2790
+ invalidChildError: invalidChildError,
2791
+ requireItemValue: requireItemValue
2792
+ });
2793
+ }, [
2794
+ children,
2795
+ itemPlumeType,
2796
+ sectionPlumeType,
2797
+ invalidChildError,
2798
+ requireItemValue,
2799
+ ]);
2800
+ }
2801
+ /**
2802
+ * Given a Collection node, create the React element that we should use
2803
+ * to render it.
2804
+ */
2805
+ function renderCollectionNode(node) {
2806
+ // node.rendered should already have our item-like or section-like Plume
2807
+ // component elements, so we just need to clone them with a secret
2808
+ // _node prop that we use to render.
2809
+ return cloneChild(node.rendered, {
2810
+ _node: node,
2811
+ key: node.key
2812
+ });
2813
+ }
2814
+ /**
2815
+ * Renders a item-like or section-like Plume component element into an
2816
+ * Item or a Section element.
2817
+ */
2818
+ function renderAsCollectionChild(child, opts) {
2819
+ var _a;
2820
+ var plumeType = getPlumeType(child);
2821
+ if (plumeType === opts.itemPlumeType) {
2822
+ var option = child;
2823
+ // We look at the children passed to the item-like element, and derive key
2824
+ // or textValue from it if it is a string
2825
+ var content = getChildProp(option, "children");
2826
+ // The children render prop needs to return an <Item/>
2827
+ return (React__default['default'].createElement(collections.Item
2828
+ // We use ItemLike.value if the user explicitly specified a value,
2829
+ // and we fallback to key. If the user specified neither, then
2830
+ // the Collections API will generate a unique key for this item.
2831
+ , {
2832
+ // We use ItemLike.value if the user explicitly specified a value,
2833
+ // and we fallback to key. If the user specified neither, then
2834
+ // the Collections API will generate a unique key for this item.
2835
+ key: getItemLikeKey(option),
2836
+ // textValue is either explicitly specified by the user, or we
2837
+ // try to derive it if `content` is a string.
2838
+ textValue: (_a = getChildProp(option, "textValue")) !== null && _a !== void 0 ? _a : (isString(content)
2839
+ ? content
2840
+ : propInChild(option, "value")
2841
+ ? getChildProp(option, "value")
2842
+ : option.key), "aria-label": getChildProp(option, "aria-label") }, option));
2843
+ }
2844
+ else {
2845
+ var group = child;
2846
+ return (React__default['default'].createElement(collections.Section
2847
+ // Note that we are using the whole section-like element as the title
2848
+ // here, and not group.props.title; we want the entire section-like
2849
+ // Plume element to end up as Node.rendered.
2850
+ , {
2851
+ // Note that we are using the whole section-like element as the title
2852
+ // here, and not group.props.title; we want the entire section-like
2853
+ // Plume element to end up as Node.rendered.
2854
+ title: group, "aria-label": getChildProp(group, "aria-label"),
2855
+ // We are flattening and deriving the descendant Options as items here.
2856
+ // group.props.children should've already been cleaned up by
2857
+ // deriveItemsFromChildren()
2858
+ items: getChildProp(group, "children") }, function (c) { return renderAsCollectionChild(c, opts); }));
2859
+ }
2860
+ }
2861
+ function getItemLikeKey(element) {
2862
+ var _a;
2863
+ return (_a = getChildProp(element, "value")) !== null && _a !== void 0 ? _a : element.key;
2864
+ }
2865
+ // PlasmicLoader-aware function to get prop from child.
2866
+ function getChildProp(child, prop) {
2867
+ return "componentProps" in child.props
2868
+ ? child.props.componentProps[prop]
2869
+ : child.props[prop];
2870
+ }
2871
+ // PlasmicLoader-aware function to check `if (prop in element.props)`.
2872
+ function propInChild(child, prop) {
2873
+ return "componentProps" in child.props
2874
+ ? prop in child.props.componentProps
2875
+ : prop in child.props;
2876
+ }
2877
+ // PlasmicLoader-aware function to clone React element.
2878
+ function cloneChild(child, props) {
2879
+ if (child.type.getPlumeType) {
2880
+ // If React element has getPlumeType(), assume that it is PlasmicLoader,
2881
+ // so add nodeProps to componentProps instead of element props.
2882
+ return React__default['default'].cloneElement(child, tslib.__assign({ componentProps: tslib.__assign(tslib.__assign({}, child.props.componentProps), props) }, (props.key ? { key: props.key } : {})));
2883
+ }
2884
+ return React__default['default'].cloneElement(child, props);
2885
+ }
2886
+
2887
+ var TriggeredOverlayContext = React__namespace.createContext(undefined);
2888
+
2889
+ var MenuContext = React__namespace.createContext(undefined);
2890
+
2891
+ var COLLECTION_OPTS$1 = {
2892
+ itemPlumeType: "menu-item",
2893
+ sectionPlumeType: "menu-group"
2894
+ };
2895
+ /**
2896
+ * Converts props from BaseMenuProps to react-aria's useMenu() props.
2897
+ */
2898
+ function asAriaMenuProps(props) {
2899
+ var children = props.children, rest = tslib.__rest(props, ["children"]);
2900
+ var _a = useDerivedItemsFromChildren(children, tslib.__assign(tslib.__assign({}, COLLECTION_OPTS$1), { invalidChildError: "Can only use Menu.Item and Menu.Group as children to Menu", requireItemValue: false })), items = _a.items, disabledKeys = _a.disabledKeys;
2901
+ var collectionChildRenderer = React__namespace.useCallback(function (child) { return renderAsCollectionChild(child, COLLECTION_OPTS$1); }, []);
2902
+ return {
2903
+ ariaProps: tslib.__assign(tslib.__assign({}, rest), { children: collectionChildRenderer, items: items, disabledKeys: disabledKeys })
2904
+ };
2905
+ }
2906
+ function useMenu(plasmicClass, props, config, ref) {
2907
+ var _a, _b;
2908
+ if (ref === void 0) { ref = null; }
2909
+ useEnsureSSRProvider();
2910
+ var ariaProps = asAriaMenuProps(props).ariaProps;
2911
+ var triggerContext = React__namespace.useContext(TriggeredOverlayContext);
2912
+ var rootRef = React__namespace.useRef(null);
2913
+ var state = tree.useTreeState(ariaProps);
2914
+ var menuListRef = React__namespace.useRef(null);
2915
+ var menuProps = menu.useMenu(tslib.__assign(tslib.__assign({}, ariaProps), { autoFocus: triggerContext === null || triggerContext === void 0 ? void 0 : triggerContext.autoFocus }), state, menuListRef).menuProps;
2916
+ var contextValue = React__namespace.useMemo(function () { return ({ state: state, menuProps: props }); }, [
2917
+ state,
2918
+ props,
2919
+ ]);
2920
+ var variants = tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false)));
2921
+ var overrides = (_a = {},
2922
+ _a[config.root] = {
2923
+ props: mergeProps(getStyleProps(props), {
2924
+ ref: rootRef
2925
+ })
2926
+ },
2927
+ _a[config.itemsContainer] = {
2928
+ as: "ul",
2929
+ props: mergeProps(menuProps, {
2930
+ ref: menuListRef,
2931
+ style: tslib.__assign({}, noOutline())
2932
+ })
2933
+ },
2934
+ _a);
2935
+ var args = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false))), (_b = {}, _b[config.itemsSlot] = (React__namespace.createElement(MenuContext.Provider, { value: contextValue }, Array.from(state.collection).map(function (node) { return renderCollectionNode(node); }))), _b));
2936
+ var plumeState = React__namespace.useMemo(function () { return ({
2937
+ getFocusedValue: function () { return state.selectionManager.focusedKey; },
2938
+ setFocusedValue: function (value) {
2939
+ return state.selectionManager.setFocusedKey(value);
2940
+ }
2941
+ }); }, [state]);
2942
+ React__namespace.useImperativeHandle(ref, function () { return ({
2943
+ getRoot: function () { return rootRef.current; },
2944
+ getFocusedValue: function () { return plumeState.getFocusedValue(); },
2945
+ setFocusedValue: function (key) { return plumeState.setFocusedValue(key); }
2946
+ }); }, [rootRef, plumeState]);
2947
+ return {
2948
+ plasmicProps: {
2949
+ variants: variants,
2950
+ args: args,
2951
+ overrides: overrides
2952
+ },
2953
+ state: plumeState
2954
+ };
2955
+ }
2956
+
2957
+ function useMenuGroup(plasmicClass, props, config) {
2958
+ var _a, _b;
2959
+ var context = React__namespace.useContext(MenuContext);
2960
+ var node = props._node;
2961
+ if (!context || !node) {
2962
+ if (PLUME_STRICT_MODE) {
2963
+ throw new Error("You can only use a Menu.Group within a Menu component.");
2964
+ }
2965
+ return getDefaultPlasmicProps(plasmicClass, props);
2966
+ }
2967
+ var _c = menu.useMenuSection({
2968
+ heading: props.title,
2969
+ "aria-label": props["aria-label"]
2970
+ }), headingProps = _c.headingProps, groupProps = _c.groupProps;
2971
+ var separatorProps = separator.useSeparator({
2972
+ elementType: "li"
2973
+ }).separatorProps;
2974
+ var variants = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.noTitleVariant, active: !props.title }, {
2975
+ def: config.isFirstVariant,
2976
+ active: context.state.collection.getFirstKey() === node.key
2977
+ }));
2978
+ var args = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false))), (_a = {}, _a[config.titleSlot] = props.title, _a[config.itemsSlot] = Array.from(node.childNodes).map(function (childNode) {
2979
+ return renderCollectionNode(childNode);
2980
+ }), _a));
2981
+ var overrides = (_b = {},
2982
+ _b[config.root] = {
2983
+ props: getStyleProps(props)
2984
+ },
2985
+ _b[config.separator] = {
2986
+ props: tslib.__assign({}, separatorProps),
2987
+ as: "li"
2988
+ },
2989
+ _b[config.titleContainer] = tslib.__assign({ props: tslib.__assign({ role: "presentation" }, headingProps) }, (!props.title && {
2990
+ render: function () { return null; }
2991
+ })),
2992
+ _b[config.itemsContainer] = {
2993
+ props: tslib.__assign({}, groupProps),
2994
+ as: "ul"
2995
+ },
2996
+ _b);
2997
+ return {
2998
+ plasmicProps: {
2999
+ variants: variants,
3000
+ args: args,
3001
+ overrides: overrides
3002
+ }
3003
+ };
3004
+ }
3005
+
3006
+ function useMenuItem(plasmicClass, props, config) {
3007
+ var _a, _b;
3008
+ var menuContext = React__namespace.useContext(MenuContext);
3009
+ var triggerContext = React__namespace.useContext(TriggeredOverlayContext);
3010
+ if (!menuContext) {
3011
+ if (PLUME_STRICT_MODE) {
3012
+ throw new Error("You can only use a Menu.Item within a Menu component.");
3013
+ }
3014
+ return getDefaultPlasmicProps(plasmicClass, props);
3015
+ }
3016
+ var children = props.children, onAction = props.onAction;
3017
+ var state = menuContext.state, menuProps = menuContext.menuProps;
3018
+ // We pass in the Node secretly as an undocumented prop from <Select />
3019
+ var node = props._node;
3020
+ var isDisabled = state.disabledKeys.has(node.key);
3021
+ var isHighlighted = state.selectionManager.isFocused &&
3022
+ state.selectionManager.focusedKey === node.key;
3023
+ var ref = React__namespace.useRef(null);
3024
+ var _c = menu.useMenuItem(mergeProps({
3025
+ // We need to merge both the onAction on MenuItem and the onAction
3026
+ // on Menu
3027
+ onAction: onAction
3028
+ }, {
3029
+ onAction: menuProps.onAction,
3030
+ onClose: triggerContext === null || triggerContext === void 0 ? void 0 : triggerContext.state.close
3031
+ }, {
3032
+ isDisabled: isDisabled,
3033
+ "aria-label": node && node["aria-label"],
3034
+ key: node.key,
3035
+ isVirtualized: false,
3036
+ closeOnSelect: true
3037
+ }), state, ref), menuItemProps = _c.menuItemProps, labelProps = _c.labelProps;
3038
+ var variants = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.isDisabledVariant, active: isDisabled }, { def: config.isHighlightedVariant, active: isHighlighted }));
3039
+ var args = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false))), (_a = {}, _a[config.labelSlot] = children, _a));
3040
+ var overrides = (_b = {},
3041
+ _b[config.root] = {
3042
+ as: "li",
3043
+ props: mergeProps(menuItemProps, { ref: ref, style: noOutline() })
3044
+ },
3045
+ _b[config.labelContainer] = {
3046
+ props: tslib.__assign({}, labelProps)
3047
+ },
3048
+ _b);
3049
+ return {
3050
+ plasmicProps: {
3051
+ variants: variants,
3052
+ args: args,
3053
+ overrides: overrides
3054
+ }
3055
+ };
3056
+ }
3057
+
3058
+ /**
3059
+ * A menu trigger hook that combines react-aria's useMenuTrigger, useAriaMenuTrigger,
3060
+ * useOverlayPosition, useOverlay, and usePress
3061
+ */
3062
+ function useMenuTrigger(opts, state) {
3063
+ var triggerRef = opts.triggerRef, isDisabled = opts.isDisabled, placement = opts.placement, menuMatchTriggerWidth = opts.menuMatchTriggerWidth, menuWidth = opts.menuWidth, menu$1 = opts.menu;
3064
+ var _a = menu.useMenuTrigger({
3065
+ type: "menu",
3066
+ isDisabled: isDisabled
3067
+ }, state, triggerRef), triggerPressProps = _a.menuTriggerProps, menuProps = _a.menuProps;
3068
+ var triggerProps = interactions.usePress(tslib.__assign(tslib.__assign({}, triggerPressProps), { isDisabled: isDisabled })).pressProps;
3069
+ var makeMenu = function () {
3070
+ var realMenu = typeof menu$1 === "function" ? menu$1() : menu$1;
3071
+ if (!realMenu) {
3072
+ return null;
3073
+ }
3074
+ if (getPlumeType(realMenu) !== "menu") {
3075
+ if (PLUME_STRICT_MODE) {
3076
+ throw new Error("Must use an instance of the Menu component.");
3077
+ }
3078
+ return null;
3079
+ }
3080
+ return React__namespace.cloneElement(realMenu, mergeProps(realMenu.props, menuProps));
3081
+ };
3082
+ var triggerContext = React__namespace.useMemo(function () {
3083
+ var _a;
3084
+ return ({
3085
+ triggerRef: triggerRef,
3086
+ state: state,
3087
+ autoFocus: (_a = state.focusStrategy) !== null && _a !== void 0 ? _a : true,
3088
+ placement: placement,
3089
+ overlayMatchTriggerWidth: menuMatchTriggerWidth,
3090
+ overlayMinTriggerWidth: true,
3091
+ overlayWidth: menuWidth
3092
+ });
3093
+ }, [triggerRef, state, placement, menuMatchTriggerWidth, menuWidth]);
3094
+ return {
3095
+ triggerProps: triggerProps,
3096
+ makeMenu: makeMenu,
3097
+ triggerContext: triggerContext
3098
+ };
3099
+ }
3100
+
3101
+ function DropdownMenu(props) {
3102
+ var isOpen = props.isOpen, defaultOpen = props.defaultOpen, onOpenChange = props.onOpenChange, children = props.children, placement = props.placement, menu = props.menu;
3103
+ var triggerRef = React__namespace.useRef(null);
3104
+ var state = menu$1.useMenuTriggerState({
3105
+ isOpen: isOpen,
3106
+ defaultOpen: defaultOpen,
3107
+ onOpenChange: onOpenChange,
3108
+ shouldFlip: true
3109
+ });
3110
+ var _a = useMenuTrigger({
3111
+ triggerRef: triggerRef,
3112
+ placement: placement,
3113
+ menu: menu
3114
+ }, state), triggerProps = _a.triggerProps, makeMenu = _a.makeMenu, triggerContext = _a.triggerContext;
3115
+ return (React__namespace.createElement(TriggeredOverlayContext.Provider, { value: triggerContext },
3116
+ React__namespace.cloneElement(children, mergeProps(children.props, triggerProps, { ref: triggerRef })),
3117
+ state.isOpen && makeMenu()));
3118
+ }
3119
+
3120
+ function useMenuButton(plasmicClass, props, config, outerRef) {
3121
+ var _a, _b;
3122
+ if (outerRef === void 0) { outerRef = null; }
3123
+ var placement = props.placement, isOpen = props.isOpen, defaultOpen = props.defaultOpen, onOpenChange = props.onOpenChange, isDisabled = props.isDisabled, menu = props.menu, autoFocus = props.autoFocus, menuMatchTriggerWidth = props.menuMatchTriggerWidth, menuWidth = props.menuWidth;
3124
+ useEnsureSSRProvider();
3125
+ var rootRef = React__namespace.useRef(null);
3126
+ var triggerRef = React__namespace.useRef(null);
3127
+ var state = menu$1.useMenuTriggerState({
3128
+ isOpen: isOpen,
3129
+ defaultOpen: defaultOpen,
3130
+ onOpenChange: onOpenChange,
3131
+ shouldFlip: true
3132
+ });
3133
+ var _c = useMenuTrigger({
3134
+ isDisabled: isDisabled,
3135
+ triggerRef: triggerRef,
3136
+ placement: placement,
3137
+ menuMatchTriggerWidth: menuMatchTriggerWidth,
3138
+ menuWidth: menuWidth,
3139
+ menu: menu
3140
+ }, state), triggerProps = _c.triggerProps, makeMenu = _c.makeMenu, triggerContext = _c.triggerContext;
3141
+ var triggerFocusProps = focus.useFocusable(props, triggerRef).focusableProps;
3142
+ var variants = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.isOpenVariant, active: state.isOpen }, { def: config.isDisabledVariant, active: isDisabled }));
3143
+ var args = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false))), (_a = {}, _a[config.menuSlot] = state.isOpen ? makeMenu() : undefined, _a));
3144
+ var overrides = (_b = {},
3145
+ _b[config.root] = {
3146
+ wrapChildren: function (children) { return (React__namespace.createElement(TriggeredOverlayContext.Provider, { value: triggerContext }, children)); },
3147
+ props: {
3148
+ ref: rootRef
3149
+ }
3150
+ },
3151
+ _b[config.trigger] = {
3152
+ props: mergeProps(triggerProps, triggerFocusProps, getStyleProps(props), pick(props, "title"), {
3153
+ ref: triggerRef,
3154
+ autoFocus: autoFocus,
3155
+ disabled: !!isDisabled,
3156
+ // Make sure this button is not interpreted as submit
3157
+ type: "button"
3158
+ })
3159
+ },
3160
+ _b);
3161
+ var plumeState = React__namespace.useMemo(function () { return ({
3162
+ open: function () { return state.open(); },
3163
+ close: function () { return state.close(); },
3164
+ isOpen: function () { return state.isOpen; }
3165
+ }); }, [state]);
3166
+ React__namespace.useImperativeHandle(outerRef, function () { return ({
3167
+ getRoot: function () { return rootRef.current; },
3168
+ getTrigger: function () { return triggerRef.current; },
3169
+ focus: function () { return triggerRef.current && triggerRef.current.focus(); },
3170
+ blur: function () { return triggerRef.current && triggerRef.current.blur(); },
3171
+ open: plumeState.open,
3172
+ close: plumeState.close,
3173
+ isOpen: plumeState.isOpen
3174
+ }); }, [rootRef, triggerRef, plumeState]);
3175
+ return {
3176
+ plasmicProps: {
3177
+ variants: variants,
3178
+ args: args,
3179
+ overrides: overrides
3180
+ },
3181
+ state: plumeState
3182
+ };
3183
+ }
3184
+
3185
+ var SelectContext = React__namespace.createContext(undefined);
3186
+
3187
+ var COLLECTION_OPTS = {
3188
+ itemPlumeType: "select-option",
3189
+ sectionPlumeType: "select-option-group"
3190
+ };
3191
+ /**
3192
+ * Converts props in our BaseSelectProps into props that react-aria's
3193
+ * useSelect() understands.
3194
+ *
3195
+ * Because we're not exposing the Collections API (see ./index.tsx),
3196
+ * we are converting our own API into props for useSelect.
3197
+ *
3198
+ * Specifically, in Plume's API,
3199
+ * - `children` flattens to a list of ReactElements of type Select.Option
3200
+ * or Select.OptionGroup
3201
+ *
3202
+ * and we map it this way to the Collections API:
3203
+ * - `items` is a list of those flattened ReactElements from `children`!
3204
+ * - `children`, as a render prop, is supposed to take one of the `items`
3205
+ * and return a `Section` or `Item` element. We take an Option/OptionGroup
3206
+ * element, and use its props to render the appropriate `Section` or
3207
+ * `Item`. The "trick" here is that we then stuff the Option element as
3208
+ * `Item.children`, and the OptionGroup element as `Section.title`.
3209
+ *
3210
+ * When the Collections API does its work deriving `Node`s, the corresponding
3211
+ * Option/OptionGroup ReactElements will end up as `Node.rendered`.
3212
+ *
3213
+ * Then, when we are actually rendering the content of the dropdown, we
3214
+ * iterate through each collected `Node`, and renders
3215
+ * React.cloneElement(Node.rendered, {_node: node}). This "secretly" passes
3216
+ * the derived collection `Node` as a prop to Option and OptionGroup, and they
3217
+ * can make use of the derived `Node.key` etc in their rendering functions.
3218
+ *
3219
+ * One thing to note here is that we never "rendered" the Option/OptionGroup
3220
+ * React elements that the user constructed; instead, we just looked at the
3221
+ * props used on those elements, and passed those onto the Collections API.
3222
+ * What gets rendered to the screen is the cloned version of these elements
3223
+ * with the secret derived `_node` prop. That means Option and OptionGroup
3224
+ * render functions can assume that _node is passed in.
3225
+ */
3226
+ function useAriaSelectProps(props, config) {
3227
+ var value = props.value, defaultValue = props.defaultValue; props.children; var onChange = props.onChange; props.placement; props.menuMatchTriggerWidth; props.menuWidth; var rest = tslib.__rest(props, ["value", "defaultValue", "children", "onChange", "placement", "menuMatchTriggerWidth", "menuWidth"]);
3228
+ var _a = useDerivedItems(props, tslib.__assign(tslib.__assign({}, COLLECTION_OPTS), { invalidChildError: "Can only use Select.Option and Select.OptionGroup as children to Select", requireItemValue: true, ItemComponent: config.OptionComponent, SectionComponent: config.OptionGroupComponent, itemsProp: "options" })), items = _a.items, disabledKeys = _a.disabledKeys;
3229
+ var collectionChildRenderer = React__namespace.useCallback(function (child) { return renderAsCollectionChild(child, COLLECTION_OPTS); }, []);
3230
+ var onSelectionChange = React__namespace.useMemo(function () {
3231
+ if (onChange) {
3232
+ return function (val) {
3233
+ return onChange((val == null || val === "null" ? null : val));
3234
+ };
3235
+ }
3236
+ else {
3237
+ return undefined;
3238
+ }
3239
+ }, [onChange]);
3240
+ return {
3241
+ ariaProps: tslib.__assign(tslib.__assign(tslib.__assign({}, rest), { children: collectionChildRenderer, onSelectionChange: onSelectionChange, items: items, disabledKeys: disabledKeys, defaultSelectedKey: defaultValue }), ("value" in props && { selectedKey: value !== null && value !== void 0 ? value : null }))
3242
+ };
3243
+ }
3244
+ function useSelect(plasmicClass, props, config, ref) {
3245
+ var _a, _b;
3246
+ if (ref === void 0) { ref = null; }
3247
+ useEnsureSSRProvider();
3248
+ var ariaProps = useAriaSelectProps(props, config).ariaProps;
3249
+ var placement = props.placement;
3250
+ var state = select.useSelectState(ariaProps);
3251
+ var triggerRef = React__namespace.useRef(null);
3252
+ var rootRef = React__namespace.useRef(null);
3253
+ var isDisabled = props.isDisabled, name = props.name, menuWidth = props.menuWidth, menuMatchTriggerWidth = props.menuMatchTriggerWidth, autoFocus = props.autoFocus, placeholder = props.placeholder, selectedContent = props.selectedContent;
3254
+ var canvasCtx = host.usePlasmicCanvasContext();
3255
+ var _c = select$1.useSelect(ariaProps, state, triggerRef), triggerPressProps = _c.triggerProps, menuProps = _c.menuProps;
3256
+ var triggerProps = interactions.usePress(tslib.__assign(tslib.__assign({}, triggerPressProps), { isDisabled: isDisabled })).pressProps;
3257
+ var triggerContent = state.selectedItem
3258
+ ? selectedContent !== null && selectedContent !== void 0 ? selectedContent : getChildProp(state.selectedItem.value, "children")
3259
+ : null;
3260
+ var variants = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.isOpenVariant, active: state.isOpen }, { def: config.placeholderVariant, active: !state.selectedItem }, { def: config.isDisabledVariant, active: isDisabled }));
3261
+ var triggerContext = React__namespace.useMemo(function () { return ({
3262
+ triggerRef: triggerRef,
3263
+ state: state,
3264
+ placement: placement,
3265
+ overlayMatchTriggerWidth: menuMatchTriggerWidth,
3266
+ overlayMinTriggerWidth: true,
3267
+ overlayWidth: menuWidth
3268
+ }); }, [triggerRef, state, placement, menuMatchTriggerWidth, menuWidth]);
3269
+ var overrides = (_a = {},
3270
+ _a[config.root] = {
3271
+ props: mergeProps(getStyleProps(props), {
3272
+ ref: rootRef
3273
+ }),
3274
+ wrapChildren: function (children) { return (React__namespace.createElement(React__namespace.Fragment, null,
3275
+ !canvasCtx && (React__namespace.createElement(select$1.HiddenSelect, { state: state, triggerRef: triggerRef, name: name, isDisabled: isDisabled })),
3276
+ children)); }
3277
+ },
3278
+ _a[config.trigger] = {
3279
+ props: mergeProps(canvasCtx ? {} : triggerProps, {
3280
+ ref: triggerRef,
3281
+ autoFocus: autoFocus,
3282
+ disabled: !!isDisabled,
3283
+ // Don't trigger form submission!
3284
+ type: "button"
3285
+ })
3286
+ },
3287
+ _a[config.overlay] = {
3288
+ wrap: function (content) { return (React__namespace.createElement(TriggeredOverlayContext.Provider, { value: triggerContext }, content)); }
3289
+ },
3290
+ _a[config.optionsContainer] = {
3291
+ wrap: function (content) { return (React__namespace.createElement(ListBoxWrapper, { state: state, menuProps: menuProps }, content)); }
3292
+ },
3293
+ _a);
3294
+ var args = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false))), (_b = {}, _b[config.triggerContentSlot] = triggerContent, _b[config.placeholderSlot] = placeholder, _b[config.optionsSlot] = (React__namespace.createElement(SelectContext.Provider, { value: state }, Array.from(state.collection).map(function (node) { return renderCollectionNode(node); }))), _b));
3295
+ var plumeState = React__namespace.useMemo(function () { return ({
3296
+ open: function () { return state.open(); },
3297
+ close: function () { return state.close(); },
3298
+ isOpen: function () { return state.isOpen; },
3299
+ getSelectedValue: function () {
3300
+ return state.selectedKey ? "".concat(state.selectedKey) : null;
3301
+ },
3302
+ setSelectedValue: function (key) { return state.setSelectedKey(key); }
3303
+ }); }, [state]);
3304
+ React__namespace.useImperativeHandle(ref, function () { return ({
3305
+ getRoot: function () { return rootRef.current; },
3306
+ getTrigger: function () { return triggerRef.current; },
3307
+ focus: function () { var _a; return (_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
3308
+ blur: function () { var _a; return (_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
3309
+ open: function () { return plumeState.open(); },
3310
+ close: function () { return plumeState.close(); },
3311
+ isOpen: function () { return plumeState.isOpen(); },
3312
+ getSelectedValue: function () { return plumeState.getSelectedValue(); },
3313
+ setSelectedValue: function (key) { return plumeState.setSelectedValue(key); }
3314
+ }); }, [rootRef, triggerRef, plumeState]);
3315
+ return {
3316
+ plasmicProps: {
3317
+ variants: variants,
3318
+ args: args,
3319
+ overrides: overrides
3320
+ },
3321
+ state: plumeState
3322
+ };
3323
+ }
3324
+ function ListBoxWrapper(props) {
3325
+ var state = props.state, menuProps = props.menuProps, children = props.children;
3326
+ var ref = React__namespace.useRef(null);
3327
+ var canvasCtx = host.usePlasmicCanvasContext();
3328
+ var listBoxProps = listbox.useListBox(tslib.__assign(tslib.__assign({}, menuProps), { isVirtualized: false, autoFocus: state.focusStrategy || true, disallowEmptySelection: true }), state, ref).listBoxProps;
3329
+ return React__namespace.cloneElement(children, mergeProps(children.props, canvasCtx ? {} : listBoxProps, {
3330
+ style: noOutline(),
3331
+ ref: ref
3332
+ }));
3333
+ }
3334
+
3335
+ function useSelectOption(plasmicClass, props, config, outerRef) {
3336
+ var _a, _b;
3337
+ if (outerRef === void 0) { outerRef = null; }
3338
+ var state = React__namespace.useContext(SelectContext);
3339
+ if (!state) {
3340
+ // If no context, then we are being incorrectly used. Complain or just don't
3341
+ // bother installing any hooks. It's okay to violate rules of hooks here
3342
+ // because this instance won't suddenly be used correctly in another render.
3343
+ if (PLUME_STRICT_MODE) {
3344
+ throw new Error("You can only use a Select.Option within a Select component.");
3345
+ }
3346
+ return getDefaultPlasmicProps(plasmicClass, props);
3347
+ }
3348
+ var children = props.children;
3349
+ var canvasCtx = host.usePlasmicCanvasContext();
3350
+ var rootRef = React__namespace.useRef(null);
3351
+ var onRef = mergeRefs(rootRef, outerRef);
3352
+ // We pass in the Node secretly as an undocumented prop from <Select />
3353
+ var node = props._node;
3354
+ var isSelected = state.selectionManager.isSelected(node.key);
3355
+ var isDisabled = state.disabledKeys.has(node.key);
3356
+ var isHighlighted = state.selectionManager.isFocused &&
3357
+ state.selectionManager.focusedKey === node.key;
3358
+ var _c = listbox.useOption({
3359
+ isSelected: isSelected,
3360
+ isDisabled: isDisabled,
3361
+ "aria-label": node && node["aria-label"],
3362
+ key: node.key,
3363
+ shouldSelectOnPressUp: true,
3364
+ shouldFocusOnHover: true,
3365
+ isVirtualized: false,
3366
+ shouldUseVirtualFocus: !!canvasCtx
3367
+ }, state, rootRef), optionProps = _c.optionProps, labelProps = _c.labelProps;
3368
+ var variants = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.isSelectedVariant, active: isSelected }, { def: config.isDisabledVariant, active: isDisabled }, { def: config.isHighlightedVariant, active: isHighlighted }));
3369
+ var args = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false))), (_a = {}, _a[config.labelSlot] = children, _a));
3370
+ var overrides = (_b = {},
3371
+ _b[config.root] = {
3372
+ props: mergeProps(canvasCtx ? {} : optionProps, getStyleProps(props), {
3373
+ ref: onRef,
3374
+ style: noOutline()
3375
+ })
3376
+ },
3377
+ _b[config.labelContainer] = {
3378
+ props: labelProps
3379
+ },
3380
+ _b);
3381
+ return {
3382
+ plasmicProps: {
3383
+ variants: variants,
3384
+ args: args,
3385
+ overrides: overrides
3386
+ }
3387
+ };
3388
+ }
3389
+
3390
+ function useSelectOptionGroup(plasmicClass, props, config) {
3391
+ var _a, _b;
3392
+ var state = React__namespace.useContext(SelectContext);
3393
+ // `node` should exist if the OptionGroup was instantiated properly
3394
+ // within a Select
3395
+ var node = props._node;
3396
+ if (!state || !node) {
3397
+ if (PLUME_STRICT_MODE) {
3398
+ throw new Error("You can only use a Select.OptionGroup within a Select component.");
3399
+ }
3400
+ return getDefaultPlasmicProps(plasmicClass, props);
3401
+ }
3402
+ var _c = listbox.useListBoxSection({
3403
+ heading: props.title,
3404
+ "aria-label": props["aria-label"]
3405
+ }), headingProps = _c.headingProps, groupProps = _c.groupProps;
3406
+ var separatorProps = separator.useSeparator({
3407
+ elementType: "li"
3408
+ }).separatorProps;
3409
+ var variants = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.noTitleVariant, active: !props.title }, {
3410
+ def: config.isFirstVariant,
3411
+ active: state.collection.getFirstKey() === node.key
3412
+ }));
3413
+ var args = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false))), (_a = {}, _a[config.titleSlot] = props.title, _a[config.optionsSlot] = Array.from(node.childNodes).map(function (childNode) {
3414
+ return renderCollectionNode(childNode);
3415
+ }), _a));
3416
+ var overrides = (_b = {},
3417
+ _b[config.root] = {
3418
+ props: getStyleProps(props)
3419
+ },
3420
+ _b[config.separator] = {
3421
+ props: tslib.__assign({}, separatorProps)
3422
+ },
3423
+ _b[config.titleContainer] = tslib.__assign({ props: tslib.__assign({ role: "presentation" }, headingProps) }, (!props.title && {
3424
+ render: function () { return null; }
3425
+ })),
3426
+ _b[config.optionsContainer] = {
3427
+ props: tslib.__assign({}, groupProps)
3428
+ },
3429
+ _b);
3430
+ return {
3431
+ plasmicProps: {
3432
+ variants: variants,
3433
+ args: args,
3434
+ overrides: overrides
3435
+ }
3436
+ };
3437
+ }
3438
+
3439
+ function asAriaSwitchProps(props) {
3440
+ var ariaProps = tslib.__assign(tslib.__assign({}, props), { isSelected: props.isChecked, defaultSelected: props.defaultChecked });
3441
+ delete ariaProps["isChecked"];
3442
+ delete ariaProps["defaultChecked"];
3443
+ return ariaProps;
3444
+ }
3445
+ function useSwitch(plasmicClass, props, config, ref) {
3446
+ var _a, _b;
3447
+ if (ref === void 0) { ref = null; }
3448
+ var children = props.children, isDisabled = props.isDisabled;
3449
+ useEnsureSSRProvider();
3450
+ var inputRef = React__namespace.useRef(null);
3451
+ var rootRef = React__namespace.useRef(null);
3452
+ var ariaProps = asAriaSwitchProps(props);
3453
+ var state = toggle.useToggleState(ariaProps);
3454
+ var inputProps = _switch.useSwitch(ariaProps, state, inputRef).inputProps;
3455
+ var variants = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({
3456
+ def: config.isDisabledVariant,
3457
+ active: isDisabled
3458
+ }, {
3459
+ def: config.isCheckedVariant,
3460
+ active: state.isSelected
3461
+ }, {
3462
+ def: config.noLabelVariant,
3463
+ active: !children
3464
+ }));
3465
+ var overrides = (_a = {},
3466
+ _a[config.root] = {
3467
+ as: "label",
3468
+ props: mergeProps(getStyleProps(props), {
3469
+ ref: rootRef
3470
+ }),
3471
+ wrapChildren: function (children) { return (React__namespace.createElement(React__namespace.Fragment, null,
3472
+ React__namespace.createElement(visuallyHidden.VisuallyHidden, null,
3473
+ React__namespace.createElement("input", tslib.__assign({}, inputProps, { ref: inputRef }))),
3474
+ children)); }
3475
+ },
3476
+ _a);
3477
+ var args = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false))), (config.labelSlot ? (_b = {}, _b[config.labelSlot] = children, _b) : {}));
3478
+ var plumeState = React__namespace.useMemo(function () { return ({
3479
+ setChecked: function (checked) { return state.setSelected(checked); }
3480
+ }); }, [state]);
3481
+ React__namespace.useImperativeHandle(ref, function () { return ({
3482
+ getRoot: function () { return rootRef.current; },
3483
+ focus: function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
3484
+ blur: function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
3485
+ setChecked: function (checked) { return plumeState.setChecked(checked); }
3486
+ }); }, [rootRef, inputRef, plumeState]);
3487
+ return {
3488
+ plasmicProps: {
3489
+ variants: variants,
3490
+ overrides: overrides,
3491
+ args: args
3492
+ },
3493
+ state: plumeState
3494
+ };
3495
+ }
3496
+
3497
+ function useTextInput(plasmicClass, props, config, ref) {
3498
+ var _a, _b, _c;
3499
+ if (ref === void 0) { ref = null; }
3500
+ var isDisabled = props.isDisabled, startIcon = props.startIcon, endIcon = props.endIcon, showStartIcon = props.showStartIcon, showEndIcon = props.showEndIcon, className = props.className, style = props.style, inputClassName = props.inputClassName, inputStyle = props.inputStyle, rest = tslib.__rest(props, ["isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "className", "style", "inputClassName", "inputStyle"]);
3501
+ var rootRef = React__namespace.useRef(null);
3502
+ var inputRef = React__namespace.useRef(null);
3503
+ React__namespace.useImperativeHandle(ref, function () { return ({
3504
+ focus: function () {
3505
+ var _a;
3506
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
3507
+ },
3508
+ blur: function () {
3509
+ var _a;
3510
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
3511
+ },
3512
+ getRoot: function () {
3513
+ return rootRef.current;
3514
+ },
3515
+ getInput: function () {
3516
+ return inputRef.current;
3517
+ }
3518
+ }); }, [rootRef, inputRef]);
3519
+ var variants = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.showStartIconVariant, active: showStartIcon }, { def: config.showEndIconVariant, active: showEndIcon }, { def: config.isDisabledVariant, active: isDisabled }));
3520
+ var args = tslib.__assign(tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false))), (config.startIconSlot && (_a = {}, _a[config.startIconSlot] = startIcon, _a))), (config.endIconSlot && (_b = {}, _b[config.endIconSlot] = endIcon, _b)));
3521
+ var overrides = (_c = {},
3522
+ _c[config.root] = {
3523
+ props: {
3524
+ ref: rootRef,
3525
+ className: className,
3526
+ style: style
3527
+ }
3528
+ },
3529
+ _c[config.input] = {
3530
+ props: tslib.__assign(tslib.__assign({}, omit.apply(void 0, tslib.__spreadArray(tslib.__spreadArray([rest], tslib.__read(plasmicClass.internalArgProps.filter(function (prop) { return prop !== "required"; })), false), tslib.__read(plasmicClass.internalVariantProps), false))), { disabled: isDisabled, ref: inputRef, className: inputClassName, style: inputStyle })
3531
+ },
3532
+ _c);
3533
+ return {
3534
+ plasmicProps: {
3535
+ variants: variants,
3536
+ args: args,
3537
+ overrides: overrides
3538
+ }
3539
+ };
3540
+ }
3541
+
3542
+ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissable) {
3543
+ var _a, _b;
3544
+ if (outerRef === void 0) { outerRef = null; }
3545
+ if (isDismissable === void 0) { isDismissable = true; }
3546
+ var overlayRef = React__namespace.useRef(null);
3547
+ var onOverlayRef = mergeRefs(overlayRef, outerRef);
3548
+ var context = React__namespace.useContext(TriggeredOverlayContext);
3549
+ if (!context) {
3550
+ // If no context, then we are not being correctly used. Either complain, or
3551
+ // exit early. It's okay to exit early and break the rules of React hooks
3552
+ // because we won't suddenly have the appropriate context anyway for this instance.
3553
+ if (PLUME_STRICT_MODE) {
3554
+ throw new Error("You can only use a triggered overlay with a TriggeredOverlayContext");
3555
+ }
3556
+ return getDefaultPlasmicProps(plasmicClass, props);
3557
+ }
3558
+ var children = props.children;
3559
+ var triggerRef = context.triggerRef, placement = context.placement, overlayMatchTriggerWidth = context.overlayMatchTriggerWidth, overlayMinTriggerWidth = context.overlayMinTriggerWidth, overlayWidth = context.overlayWidth, state = context.state;
3560
+ // Measure the width of the trigger to inform the width of the menu (below).
3561
+ var _c = tslib.__read(React__namespace.useState(false), 2), isRendered = _c[0], setRendered = _c[1];
3562
+ var triggerWidth = triggerRef.current && (overlayMatchTriggerWidth || overlayMinTriggerWidth)
3563
+ ? triggerRef.current.offsetWidth
3564
+ : undefined;
3565
+ useIsomorphicLayoutEffect$1(function () {
3566
+ if (!isRendered &&
3567
+ triggerRef.current &&
3568
+ (overlayMatchTriggerWidth || overlayMinTriggerWidth)) {
3569
+ setRendered(true);
3570
+ }
3571
+ }, [
3572
+ triggerRef,
3573
+ isRendered,
3574
+ overlayMatchTriggerWidth,
3575
+ overlayMinTriggerWidth,
3576
+ ]);
3577
+ var overlayAriaProps = overlays.useOverlay({
3578
+ isOpen: state.isOpen,
3579
+ onClose: state.close,
3580
+ isDismissable: isDismissable,
3581
+ shouldCloseOnBlur: true
3582
+ }, overlayRef).overlayProps;
3583
+ var _d = overlays.useOverlayPosition({
3584
+ targetRef: triggerRef,
3585
+ overlayRef: overlayRef,
3586
+ placement: placement !== null && placement !== void 0 ? placement : "bottom left",
3587
+ shouldFlip: true,
3588
+ isOpen: state.isOpen,
3589
+ onClose: state.close,
3590
+ containerPadding: 0
3591
+ }), overlayPositionProps = _d.overlayProps, updatePosition = _d.updatePosition, placementAxis = _d.placement;
3592
+ useIsomorphicLayoutEffect$1(function () {
3593
+ if (state.isOpen) {
3594
+ requestAnimationFrame(function () {
3595
+ updatePosition();
3596
+ });
3597
+ }
3598
+ }, [state.isOpen, updatePosition]);
3599
+ var overlayProps = mergeProps({
3600
+ style: {
3601
+ left: "auto",
3602
+ right: "auto",
3603
+ top: "auto",
3604
+ bottom: "auto",
3605
+ position: "absolute",
3606
+ width: overlayWidth !== null && overlayWidth !== void 0 ? overlayWidth : (overlayMatchTriggerWidth ? triggerWidth : "auto"),
3607
+ minWidth: overlayMinTriggerWidth ? triggerWidth : "auto"
3608
+ }
3609
+ }, overlayAriaProps, overlayPositionProps);
3610
+ var variants = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.isPlacedTopVariant, active: placementAxis === "top" }, { def: config.isPlacedBottomVariant, active: placementAxis === "bottom" }, { def: config.isPlacedLeftVariant, active: placementAxis === "left" }, { def: config.isPlacedRightVariant, active: placementAxis === "right" }));
3611
+ var canvasCtx = host.usePlasmicCanvasContext();
3612
+ var args = tslib.__assign(tslib.__assign({}, pick.apply(void 0, tslib.__spreadArray([props], tslib.__read(plasmicClass.internalArgProps), false))), (_a = {}, _a[config.contentSlot] = canvasCtx ? (children) : (React__namespace.createElement(focus.FocusScope, { restoreFocus: true },
3613
+ React__namespace.createElement(overlays.DismissButton, { onDismiss: state.close }),
3614
+ children)), _a));
3615
+ var overrides = (_b = {},
3616
+ _b[config.root] = {
3617
+ props: mergeProps(overlayProps, getStyleProps(props), {
3618
+ ref: onOverlayRef
3619
+ }),
3620
+ wrap: function (root) {
3621
+ if (typeof document !== "undefined") {
3622
+ return ReactDOM__namespace.createPortal(root, document.body);
3623
+ }
3624
+ else {
3625
+ // Possibly being invoked on the server during SSR; no need to
3626
+ // bother with a portal in that case.
3627
+ return root;
3628
+ }
3629
+ }
3630
+ },
3631
+ _b);
3632
+ return {
3633
+ plasmicProps: {
3634
+ variants: variants,
3635
+ args: args,
3636
+ overrides: overrides
3637
+ }
3638
+ };
3639
+ }
3640
+
3641
+ Object.defineProperty(exports, 'PlasmicDataSourceContextProvider', {
3642
+ enumerable: true,
3643
+ get: function () {
3644
+ return dataSourcesContext.PlasmicDataSourceContextProvider;
3645
+ }
3646
+ });
3647
+ Object.defineProperty(exports, 'useCurrentUser', {
3648
+ enumerable: true,
3649
+ get: function () {
3650
+ return dataSourcesContext.useCurrentUser;
3651
+ }
3652
+ });
3653
+ Object.defineProperty(exports, 'get', {
3654
+ enumerable: true,
3655
+ get: function () {
3656
+ return get__default['default'];
3657
+ }
3658
+ });
3659
+ exports.DropdownMenu = DropdownMenu;
3660
+ exports.PlasmicHead = PlasmicHead;
3661
+ exports.PlasmicIcon = PlasmicIcon;
3662
+ exports.PlasmicImg = PlasmicImg;
3663
+ exports.PlasmicLink = PlasmicLink;
3664
+ exports.PlasmicPageGuard = PlasmicPageGuard;
3665
+ exports.PlasmicRootProvider = PlasmicRootProvider;
3666
+ exports.PlasmicSlot = PlasmicSlot;
3667
+ exports.SelectContext = SelectContext;
3668
+ exports.Stack = Stack;
3669
+ exports.Trans = Trans;
3670
+ exports.TriggeredOverlayContext = TriggeredOverlayContext;
3671
+ exports.classNames = classNames;
3672
+ exports.createPlasmicElementProxy = createPlasmicElementProxy;
3673
+ exports.createUseScreenVariants = createUseScreenVariants;
3674
+ exports.deriveRenderOpts = deriveRenderOpts;
3675
+ exports.ensureGlobalVariants = ensureGlobalVariants;
3676
+ exports.genTranslatableString = genTranslatableString;
3677
+ exports.generateStateOnChangeProp = generateStateOnChangeProp;
3678
+ exports.generateStateOnChangePropForCodeComponents = generateStateOnChangePropForCodeComponents;
3679
+ exports.generateStateValueProp = generateStateValueProp;
3680
+ exports.getCurrentInitialValue = getCurrentInitialValue;
3681
+ exports.getDataProps = getDataProps;
3682
+ exports.getStateCellsInPlasmicProxy = getStateCellsInPlasmicProxy;
3683
+ exports.getStateSpecInPlasmicProxy = getStateSpecInPlasmicProxy;
3684
+ exports.hasVariant = hasVariant;
3685
+ exports.initializeCodeComponentStates = initializeCodeComponentStates;
3686
+ exports.initializePlasmicStates = initializePlasmicStates;
3687
+ exports.is$StateProxy = is$StateProxy;
3688
+ exports.isPlasmicStateProxy = isPlasmicStateProxy;
3689
+ exports.makeFragment = makeFragment;
3690
+ exports.mergeVariantsWithStates = mergeVariantsWithStates;
3691
+ exports.omit = omit;
3692
+ exports.pick = pick;
3693
+ exports.plasmicHeadMeta = plasmicHeadMeta;
3694
+ exports.renderPlasmicSlot = renderPlasmicSlot;
3695
+ exports.resetToInitialValue = resetToInitialValue;
3696
+ exports.set = set;
3697
+ exports.setPlumeStrictMode = setPlumeStrictMode;
3698
+ exports.useButton = useButton;
3699
+ exports.useCheckbox = useCheckbox;
3700
+ exports.useDollarState = useDollarState;
3701
+ exports.useIsSSR = useIsSSR;
3702
+ exports.useMenu = useMenu;
3703
+ exports.useMenuButton = useMenuButton;
3704
+ exports.useMenuGroup = useMenuGroup;
3705
+ exports.useMenuItem = useMenuItem;
3706
+ exports.useSelect = useSelect;
3707
+ exports.useSelectOption = useSelectOption;
3708
+ exports.useSelectOptionGroup = useSelectOptionGroup;
3709
+ exports.useSwitch = useSwitch;
3710
+ exports.useTextInput = useTextInput;
3711
+ exports.useTrigger = useTrigger;
3712
+ exports.useTriggeredOverlay = useTriggeredOverlay;
3713
+ exports.withPlasmicPageGuard = withPlasmicPageGuard;
3714
+ exports.wrapWithClassName = wrapWithClassName;
3715
+ //# sourceMappingURL=index.cjs.js.map