@plasmicapp/react-web 0.2.201 → 0.2.202

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/dist/all.d.ts +1926 -1925
  2. package/dist/auth/PlasmicPageGuard.d.ts +11 -11
  3. package/dist/common.d.ts +10 -10
  4. package/dist/data-sources/index.d.ts +1 -1
  5. package/dist/host/index.d.ts +1 -1
  6. package/dist/index-common.d.ts +18 -18
  7. package/dist/index-skinny.d.ts +1 -1
  8. package/dist/index.cjs.js +3495 -3495
  9. package/dist/index.cjs.js.map +1 -1
  10. package/dist/index.d.ts +11 -11
  11. package/dist/plume/button/index.d.ts +36 -36
  12. package/dist/plume/checkbox/index.d.ts +47 -47
  13. package/dist/plume/collection-utils.d.ts +191 -191
  14. package/dist/plume/collection-utils.spec.d.ts +1 -1
  15. package/dist/plume/menu/context.d.ts +8 -8
  16. package/dist/plume/menu/index.d.ts +3 -3
  17. package/dist/plume/menu/menu-group.d.ts +23 -23
  18. package/dist/plume/menu/menu-item.d.ts +23 -23
  19. package/dist/plume/menu/menu.d.ts +39 -39
  20. package/dist/plume/menu-button/DropdownMenu.d.ts +34 -34
  21. package/dist/plume/menu-button/index.d.ts +2 -2
  22. package/dist/plume/menu-button/menu-button.d.ts +72 -72
  23. package/dist/plume/menu-button/menu-trigger.d.ts +21 -21
  24. package/dist/plume/plume-utils.d.ts +41 -41
  25. package/dist/plume/props-utils.d.ts +15 -15
  26. package/dist/plume/select/context.d.ts +3 -3
  27. package/dist/plume/select/index.d.ts +4 -4
  28. package/dist/plume/select/select-option-group.d.ts +23 -23
  29. package/dist/plume/select/select-option.d.ts +23 -23
  30. package/dist/plume/select/select.d.ts +111 -111
  31. package/dist/plume/switch/index.d.ts +39 -39
  32. package/dist/plume/text-input/index.d.ts +36 -36
  33. package/dist/plume/triggered-overlay/context.d.ts +14 -14
  34. package/dist/plume/triggered-overlay/index.d.ts +2 -2
  35. package/dist/plume/triggered-overlay/triggered-overlay.d.ts +24 -24
  36. package/dist/query/index.d.ts +1 -1
  37. package/dist/react-utils.d.ts +21 -21
  38. package/dist/react-utils.spec.d.ts +1 -1
  39. package/dist/react-web.esm.js +3496 -3496
  40. package/dist/react-web.esm.js.map +1 -1
  41. package/dist/render/PlasmicHead/index.d.ts +37 -37
  42. package/dist/render/PlasmicIcon.d.ts +4 -4
  43. package/dist/render/PlasmicImg/index.d.ts +81 -81
  44. package/dist/render/PlasmicLink.d.ts +2 -2
  45. package/dist/render/PlasmicSlot.d.ts +11 -11
  46. package/dist/render/Stack.d.ts +51 -51
  47. package/dist/render/elements.d.ts +74 -74
  48. package/dist/render/global-variants.d.ts +1 -1
  49. package/dist/render/screen-variants.d.ts +5 -5
  50. package/dist/render/ssr.d.ts +21 -21
  51. package/dist/render/translation.d.ts +19 -19
  52. package/dist/render/triggers.d.ts +39 -39
  53. package/dist/states/errors.d.ts +13 -13
  54. package/dist/states/graph.d.ts +25 -25
  55. package/dist/states/helpers.d.ts +43 -43
  56. package/dist/states/index.d.ts +4 -4
  57. package/dist/states/types.d.ts +66 -66
  58. package/dist/states/valtio.d.ts +10 -10
  59. package/dist/states/vanilla.d.ts +3 -3
  60. package/dist/stories/PlasmicImg.stories.d.ts +6 -6
  61. package/dist/stories/UseDollarState.stories.d.ts +78 -78
  62. package/lib/data-sources/index.d.ts +1 -1
  63. package/lib/host/index.d.ts +1 -1
  64. package/lib/query/index.d.ts +1 -1
  65. package/package.json +8 -9
  66. package/skinny/dist/auth/PlasmicPageGuard.d.ts +11 -11
  67. package/skinny/dist/{collection-utils-0967eaf0.js → collection-utils-2f28e4eb.js} +297 -297
  68. package/skinny/dist/{collection-utils-0967eaf0.js.map → collection-utils-2f28e4eb.js.map} +1 -1
  69. package/skinny/dist/{common-9d6d348d.js → common-ed411407.js} +130 -130
  70. package/skinny/dist/{common-9d6d348d.js.map → common-ed411407.js.map} +1 -1
  71. package/skinny/dist/common.d.ts +10 -10
  72. package/skinny/dist/data-sources/index.d.ts +1 -1
  73. package/skinny/dist/host/index.d.ts +1 -1
  74. package/skinny/dist/index-common.d.ts +18 -18
  75. package/skinny/dist/index-skinny.d.ts +1 -1
  76. package/skinny/dist/index.d.ts +11 -11
  77. package/skinny/dist/index.js +1559 -1559
  78. package/skinny/dist/index.js.map +1 -1
  79. package/skinny/dist/plume/button/index.d.ts +36 -36
  80. package/skinny/dist/plume/button/index.js +21 -21
  81. package/skinny/dist/plume/checkbox/index.d.ts +47 -47
  82. package/skinny/dist/plume/checkbox/index.js +64 -64
  83. package/skinny/dist/plume/collection-utils.d.ts +191 -191
  84. package/skinny/dist/plume/collection-utils.spec.d.ts +1 -1
  85. package/skinny/dist/plume/menu/context.d.ts +8 -8
  86. package/skinny/dist/plume/menu/index.d.ts +3 -3
  87. package/skinny/dist/plume/menu/index.js +165 -165
  88. package/skinny/dist/plume/menu/menu-group.d.ts +23 -23
  89. package/skinny/dist/plume/menu/menu-item.d.ts +23 -23
  90. package/skinny/dist/plume/menu/menu.d.ts +39 -39
  91. package/skinny/dist/plume/menu-button/DropdownMenu.d.ts +34 -34
  92. package/skinny/dist/plume/menu-button/index.d.ts +2 -2
  93. package/skinny/dist/plume/menu-button/index.js +125 -125
  94. package/skinny/dist/plume/menu-button/index.js.map +1 -1
  95. package/skinny/dist/plume/menu-button/menu-button.d.ts +72 -72
  96. package/skinny/dist/plume/menu-button/menu-trigger.d.ts +21 -21
  97. package/skinny/dist/plume/plume-utils.d.ts +41 -41
  98. package/skinny/dist/plume/props-utils.d.ts +15 -15
  99. package/skinny/dist/plume/select/context.d.ts +3 -3
  100. package/skinny/dist/plume/select/index.d.ts +4 -4
  101. package/skinny/dist/plume/select/index.js +250 -250
  102. package/skinny/dist/plume/select/index.js.map +1 -1
  103. package/skinny/dist/plume/select/select-option-group.d.ts +23 -23
  104. package/skinny/dist/plume/select/select-option.d.ts +23 -23
  105. package/skinny/dist/plume/select/select.d.ts +111 -111
  106. package/skinny/dist/plume/switch/index.d.ts +39 -39
  107. package/skinny/dist/plume/switch/index.js +61 -61
  108. package/skinny/dist/plume/text-input/index.d.ts +36 -36
  109. package/skinny/dist/plume/text-input/index.js +45 -45
  110. package/skinny/dist/plume/triggered-overlay/context.d.ts +14 -14
  111. package/skinny/dist/plume/triggered-overlay/index.d.ts +2 -2
  112. package/skinny/dist/plume/triggered-overlay/index.js +100 -100
  113. package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
  114. package/skinny/dist/plume/triggered-overlay/triggered-overlay.d.ts +24 -24
  115. package/skinny/dist/{plume-utils-7d68bcc0.js → plume-utils-e699cd08.js} +30 -30
  116. package/skinny/dist/{plume-utils-7d68bcc0.js.map → plume-utils-e699cd08.js.map} +1 -1
  117. package/skinny/dist/{props-utils-9f9c761a.js → props-utils-9d74371f.js} +4 -4
  118. package/skinny/dist/{props-utils-9f9c761a.js.map → props-utils-9d74371f.js.map} +1 -1
  119. package/skinny/dist/query/index.d.ts +1 -1
  120. package/skinny/dist/{react-utils-ee4e03ba.js → react-utils-5ff031c2.js} +195 -195
  121. package/skinny/dist/{react-utils-ee4e03ba.js.map → react-utils-5ff031c2.js.map} +1 -1
  122. package/skinny/dist/react-utils.d.ts +21 -21
  123. package/skinny/dist/react-utils.spec.d.ts +1 -1
  124. package/skinny/dist/render/PlasmicHead/index.d.ts +37 -37
  125. package/skinny/dist/render/PlasmicHead/index.js +54 -54
  126. package/skinny/dist/render/PlasmicIcon.d.ts +4 -4
  127. package/skinny/dist/render/PlasmicImg/index.d.ts +81 -81
  128. package/skinny/dist/render/PlasmicImg/index.js +297 -297
  129. package/skinny/dist/render/PlasmicLink.d.ts +2 -2
  130. package/skinny/dist/render/PlasmicSlot.d.ts +11 -11
  131. package/skinny/dist/render/Stack.d.ts +51 -51
  132. package/skinny/dist/render/elements.d.ts +74 -74
  133. package/skinny/dist/render/global-variants.d.ts +1 -1
  134. package/skinny/dist/render/screen-variants.d.ts +5 -5
  135. package/skinny/dist/render/ssr.d.ts +21 -21
  136. package/skinny/dist/render/translation.d.ts +19 -19
  137. package/skinny/dist/render/triggers.d.ts +39 -39
  138. package/skinny/dist/{ssr-c9834f50.js → ssr-8625df04.js} +107 -107
  139. package/skinny/dist/{ssr-c9834f50.js.map → ssr-8625df04.js.map} +1 -1
  140. package/skinny/dist/states/errors.d.ts +13 -13
  141. package/skinny/dist/states/graph.d.ts +25 -25
  142. package/skinny/dist/states/helpers.d.ts +43 -43
  143. package/skinny/dist/states/index.d.ts +4 -4
  144. package/skinny/dist/states/types.d.ts +66 -66
  145. package/skinny/dist/states/valtio.d.ts +10 -10
  146. package/skinny/dist/states/vanilla.d.ts +3 -3
  147. package/skinny/dist/stories/PlasmicImg.stories.d.ts +6 -6
  148. package/skinny/dist/stories/UseDollarState.stories.d.ts +78 -78
@@ -1,303 +1,303 @@
1
- import { b as __assign, l as isString } from './common-9d6d348d.js';
1
+ import { b as __assign, l as isString } from './common-ed411407.js';
2
2
  import { Item, Section } from '@react-stately/collections';
3
3
  import React__default from 'react';
4
- import { t as toChildArray, g as getElementTypeName } from './react-utils-ee4e03ba.js';
5
- import { g as getPlumeType, P as PLUME_STRICT_MODE } from './plume-utils-7d68bcc0.js';
4
+ import { t as toChildArray, g as getElementTypeName } from './react-utils-5ff031c2.js';
5
+ import { g as getPlumeType, P as PLUME_STRICT_MODE } from './plume-utils-e699cd08.js';
6
6
 
7
- /**
8
- * In general, we try not to expose react-aria's Collections API to Plume users.
9
- * The Collections API is how react-aria users pass data about collections of
10
- * things using the built-in Item and Section components, which are abstract,
11
- * metadata-only components that don't render anything but only serve to specify
12
- * data. For example, here's how you would use react-spectrum's Picker:
13
- *
14
- * <Picker>
15
- * <Section title="Asia">
16
- * <Item key="taiwan">Taiwan</Item>
17
- * <Item key="japan">Japan</Item>
18
- * <Item key="china">China</Item>
19
- * </Section>
20
- * <Section title="Europe">
21
- * <Item key="germany">Germany</Item>
22
- * <Item key="france">France</Item>
23
- * </Section>
24
- * </Picker>
25
- *
26
- * You would re-use this same Item/Section components to pass similar things to
27
- * Menu, Tabs, etc.
28
- *
29
- * For Plasmic, this API is too abstract. The user has explicitly designed components
30
- * like Select.Option and Select.OptionGroup, and it is weird that they don't actually
31
- * use these components. It is more natural to do:
32
- *
33
- * <Select>
34
- * <Select.OptionGroup title="Asia">
35
- * <Select.Option key="taiwan">Taiwan</Select>
36
- * </Select.OptionGroup>
37
- * </Select>
38
- *
39
- * For Plume, we let users directly use the components they designed, both to collect
40
- * information and to perform actual rendering. For example, for Plume,
41
- * you'd use Select.Option instead of Item, and Select.OptionGroup instead of Section.
42
- * This means that the Select.Option props will collect the same information Item
43
- * does.
44
- *
45
- * A component like Select.Option then serves two purposes:
46
- *
47
- * 1. Allow users to specify the collection of data, like in the above example
48
- * Here, we're mainly interested in the props in those ReactElements so
49
- * we can pass the Item/Section data onto react-aria's APIs. We are not
50
- * actually rendering these elements.
51
- * 2. Once react-aria's Collections API has gone through them and built
52
- * Collection "nodes", we then create cloned versions of these elements
53
- * with the corresponding node passed in as a secret prop. These ReactElements
54
- * are then actually used to _render_ the corresponding Option / OptionGroup.
55
- *
56
- * This file contains helper functions to help with implementing the above.
57
- *
58
- * Note also that most of the collections-based react-aria components expose
59
- * a parallel API that accepts a list of "items" and a render prop, instead
60
- * of list of Item/Section elements. This is for efficiency, but we are opting
61
- * to only support the composite-component pattern for now for simplicity.
62
- */
63
- function deriveItemsFromProps(props, opts) {
64
- if (opts.itemsProp && opts.itemsProp in props) {
65
- if (!opts.ItemComponent || !opts.SectionComponent) {
66
- throw new Error("You may need to re-generate your Plasmic* files");
67
- }
68
- var items = props[opts.itemsProp];
69
- return deriveItemsFromItemsProp(items, {
70
- ItemComponent: opts.ItemComponent,
71
- SectionComponent: opts.SectionComponent
72
- });
73
- }
74
- else {
75
- return deriveItemsFromChildren(props.children, opts);
76
- }
77
- }
78
- function deriveItemsFromItemsProp(items, opts) {
79
- var _a;
80
- var ItemComponent = opts.ItemComponent, SectionComponent = opts.SectionComponent;
81
- var disabledKeys = [];
82
- var transform = function (item) {
83
- var _a;
84
- if (typeof item === "string") {
85
- return (React__default.createElement(ItemComponent, { key: item, value: item }, item));
86
- }
87
- else if ("children" in item) {
88
- return (React__default.createElement(SectionComponent, { key: item.title, title: item.title }, item.children.map(function (x) { return transform(x); })));
89
- }
90
- else {
91
- if (item.isDisabled) {
92
- disabledKeys.push(item.value);
93
- }
94
- return (React__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));
95
- }
96
- };
97
- return {
98
- items: (_a = items === null || items === void 0 ? void 0 : items.map(function (x) { return transform(x); })) !== null && _a !== void 0 ? _a : [],
99
- disabledKeys: disabledKeys
100
- };
101
- }
102
- /**
103
- * Given children of a component like Select or Menu, derive the items
104
- * that we will pass into the Collections API. These will be
105
- * ReactElement<ItemLikeProps|SectionLikeProps>[].
106
- *
107
- * Will also assign keys to items by their index in the collection,
108
- * and collect the keys of disabled items.
109
- */
110
- function deriveItemsFromChildren(children, opts) {
111
- if (!children) {
112
- return {
113
- items: [],
114
- disabledKeys: []
115
- };
116
- }
117
- var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError;
118
- // For Plume items without an explicit key, we assign a key as the index
119
- // of the collection.
120
- var itemCount = 0;
121
- var sectionCount = 0;
122
- var ensureValue = function (element) {
123
- if (!propInChild(element, "value")) {
124
- if (opts.requireItemValue && PLUME_STRICT_MODE) {
125
- throw new Error("Must specify a \"value\" prop for ".concat(getElementTypeName(element)));
126
- }
127
- else {
128
- return cloneChild(element, { value: "".concat(itemCount++) });
129
- }
130
- }
131
- else {
132
- // Still increment count even if key is present, so that the
133
- // auto-assigned key really reflects the index
134
- itemCount++;
135
- return element;
136
- }
137
- };
138
- var disabledKeys = [];
139
- var flattenedChildren = function (children) {
140
- return toChildArray(children).flatMap(function (child) {
141
- var _a;
142
- if (React__default.isValidElement(child)) {
143
- if (child.type === React__default.Fragment) {
144
- return flattenedChildren(child.props
145
- .children);
146
- }
147
- var type = getPlumeType(child);
148
- if (type === itemPlumeType) {
149
- child = ensureValue(child);
150
- var childKey = getItemLikeKey(child);
151
- if (getChildProp(child, "isDisabled") && !!childKey) {
152
- disabledKeys.push(childKey);
153
- }
154
- return [child];
155
- }
156
- if (type === sectionPlumeType) {
157
- return [
158
- cloneChild(child, {
159
- // key of section doesn't actually matter, just needs
160
- // to be unique
161
- key: (_a = child.key) !== null && _a !== void 0 ? _a : "section-".concat(sectionCount++),
162
- children: flattenedChildren(getChildProp(child, "children"))
163
- }),
164
- ];
165
- }
166
- }
167
- {
168
- throw new Error(invalidChildError !== null && invalidChildError !== void 0 ? invalidChildError : "Unexpected child");
169
- }
170
- });
171
- };
172
- return { items: flattenedChildren(children), disabledKeys: disabledKeys };
173
- }
174
- function useDerivedItems(props, opts) {
175
- var children = props.children;
176
- var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError, requireItemValue = opts.requireItemValue, ItemComponent = opts.ItemComponent, SectionComponent = opts.SectionComponent, itemsProp = opts.itemsProp;
177
- var items = itemsProp ? props[itemsProp] : undefined;
178
- return React__default.useMemo(function () {
179
- return deriveItemsFromProps(props, {
180
- itemPlumeType: itemPlumeType,
181
- sectionPlumeType: sectionPlumeType,
182
- invalidChildError: invalidChildError,
183
- requireItemValue: requireItemValue,
184
- itemsProp: itemsProp,
185
- ItemComponent: ItemComponent,
186
- SectionComponent: SectionComponent
187
- });
188
- }, [
189
- children,
190
- items,
191
- itemPlumeType,
192
- sectionPlumeType,
193
- invalidChildError,
194
- requireItemValue,
195
- ItemComponent,
196
- SectionComponent,
197
- ]);
198
- }
199
- function useDerivedItemsFromChildren(children, opts) {
200
- var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError, requireItemValue = opts.requireItemValue;
201
- return React__default.useMemo(function () {
202
- return deriveItemsFromChildren(children, {
203
- itemPlumeType: itemPlumeType,
204
- sectionPlumeType: sectionPlumeType,
205
- invalidChildError: invalidChildError,
206
- requireItemValue: requireItemValue
207
- });
208
- }, [
209
- children,
210
- itemPlumeType,
211
- sectionPlumeType,
212
- invalidChildError,
213
- requireItemValue,
214
- ]);
215
- }
216
- /**
217
- * Given a Collection node, create the React element that we should use
218
- * to render it.
219
- */
220
- function renderCollectionNode(node) {
221
- // node.rendered should already have our item-like or section-like Plume
222
- // component elements, so we just need to clone them with a secret
223
- // _node prop that we use to render.
224
- return cloneChild(node.rendered, {
225
- _node: node,
226
- key: node.key
227
- });
228
- }
229
- /**
230
- * Renders a item-like or section-like Plume component element into an
231
- * Item or a Section element.
232
- */
233
- function renderAsCollectionChild(child, opts) {
234
- var _a;
235
- var plumeType = getPlumeType(child);
236
- if (plumeType === opts.itemPlumeType) {
237
- var option = child;
238
- // We look at the children passed to the item-like element, and derive key
239
- // or textValue from it if it is a string
240
- var content = getChildProp(option, "children");
241
- // The children render prop needs to return an <Item/>
242
- return (React__default.createElement(Item
243
- // We use ItemLike.value if the user explicitly specified a value,
244
- // and we fallback to key. If the user specified neither, then
245
- // the Collections API will generate a unique key for this item.
246
- , {
247
- // We use ItemLike.value if the user explicitly specified a value,
248
- // and we fallback to key. If the user specified neither, then
249
- // the Collections API will generate a unique key for this item.
250
- key: getItemLikeKey(option),
251
- // textValue is either explicitly specified by the user, or we
252
- // try to derive it if `content` is a string.
253
- textValue: (_a = getChildProp(option, "textValue")) !== null && _a !== void 0 ? _a : (isString(content)
254
- ? content
255
- : propInChild(option, "value")
256
- ? getChildProp(option, "value")
257
- : option.key), "aria-label": getChildProp(option, "aria-label") }, option));
258
- }
259
- else {
260
- var group = child;
261
- return (React__default.createElement(Section
262
- // Note that we are using the whole section-like element as the title
263
- // here, and not group.props.title; we want the entire section-like
264
- // Plume element to end up as Node.rendered.
265
- , {
266
- // Note that we are using the whole section-like element as the title
267
- // here, and not group.props.title; we want the entire section-like
268
- // Plume element to end up as Node.rendered.
269
- title: group, "aria-label": getChildProp(group, "aria-label"),
270
- // We are flattening and deriving the descendant Options as items here.
271
- // group.props.children should've already been cleaned up by
272
- // deriveItemsFromChildren()
273
- items: getChildProp(group, "children") }, function (c) { return renderAsCollectionChild(c, opts); }));
274
- }
275
- }
276
- function getItemLikeKey(element) {
277
- var _a;
278
- return (_a = getChildProp(element, "value")) !== null && _a !== void 0 ? _a : element.key;
279
- }
280
- // PlasmicLoader-aware function to get prop from child.
281
- function getChildProp(child, prop) {
282
- return "componentProps" in child.props
283
- ? child.props.componentProps[prop]
284
- : child.props[prop];
285
- }
286
- // PlasmicLoader-aware function to check `if (prop in element.props)`.
287
- function propInChild(child, prop) {
288
- return "componentProps" in child.props
289
- ? prop in child.props.componentProps
290
- : prop in child.props;
291
- }
292
- // PlasmicLoader-aware function to clone React element.
293
- function cloneChild(child, props) {
294
- if (child.type.getPlumeType) {
295
- // If React element has getPlumeType(), assume that it is PlasmicLoader,
296
- // so add nodeProps to componentProps instead of element props.
297
- return React__default.cloneElement(child, __assign({ componentProps: __assign(__assign({}, child.props.componentProps), props) }, (props.key ? { key: props.key } : {})));
298
- }
299
- return React__default.cloneElement(child, props);
7
+ /**
8
+ * In general, we try not to expose react-aria's Collections API to Plume users.
9
+ * The Collections API is how react-aria users pass data about collections of
10
+ * things using the built-in Item and Section components, which are abstract,
11
+ * metadata-only components that don't render anything but only serve to specify
12
+ * data. For example, here's how you would use react-spectrum's Picker:
13
+ *
14
+ * <Picker>
15
+ * <Section title="Asia">
16
+ * <Item key="taiwan">Taiwan</Item>
17
+ * <Item key="japan">Japan</Item>
18
+ * <Item key="china">China</Item>
19
+ * </Section>
20
+ * <Section title="Europe">
21
+ * <Item key="germany">Germany</Item>
22
+ * <Item key="france">France</Item>
23
+ * </Section>
24
+ * </Picker>
25
+ *
26
+ * You would re-use this same Item/Section components to pass similar things to
27
+ * Menu, Tabs, etc.
28
+ *
29
+ * For Plasmic, this API is too abstract. The user has explicitly designed components
30
+ * like Select.Option and Select.OptionGroup, and it is weird that they don't actually
31
+ * use these components. It is more natural to do:
32
+ *
33
+ * <Select>
34
+ * <Select.OptionGroup title="Asia">
35
+ * <Select.Option key="taiwan">Taiwan</Select>
36
+ * </Select.OptionGroup>
37
+ * </Select>
38
+ *
39
+ * For Plume, we let users directly use the components they designed, both to collect
40
+ * information and to perform actual rendering. For example, for Plume,
41
+ * you'd use Select.Option instead of Item, and Select.OptionGroup instead of Section.
42
+ * This means that the Select.Option props will collect the same information Item
43
+ * does.
44
+ *
45
+ * A component like Select.Option then serves two purposes:
46
+ *
47
+ * 1. Allow users to specify the collection of data, like in the above example
48
+ * Here, we're mainly interested in the props in those ReactElements so
49
+ * we can pass the Item/Section data onto react-aria's APIs. We are not
50
+ * actually rendering these elements.
51
+ * 2. Once react-aria's Collections API has gone through them and built
52
+ * Collection "nodes", we then create cloned versions of these elements
53
+ * with the corresponding node passed in as a secret prop. These ReactElements
54
+ * are then actually used to _render_ the corresponding Option / OptionGroup.
55
+ *
56
+ * This file contains helper functions to help with implementing the above.
57
+ *
58
+ * Note also that most of the collections-based react-aria components expose
59
+ * a parallel API that accepts a list of "items" and a render prop, instead
60
+ * of list of Item/Section elements. This is for efficiency, but we are opting
61
+ * to only support the composite-component pattern for now for simplicity.
62
+ */
63
+ function deriveItemsFromProps(props, opts) {
64
+ if (opts.itemsProp && opts.itemsProp in props) {
65
+ if (!opts.ItemComponent || !opts.SectionComponent) {
66
+ throw new Error("You may need to re-generate your Plasmic* files");
67
+ }
68
+ var items = props[opts.itemsProp];
69
+ return deriveItemsFromItemsProp(items, {
70
+ ItemComponent: opts.ItemComponent,
71
+ SectionComponent: opts.SectionComponent,
72
+ });
73
+ }
74
+ else {
75
+ return deriveItemsFromChildren(props.children, opts);
76
+ }
77
+ }
78
+ function deriveItemsFromItemsProp(items, opts) {
79
+ var _a;
80
+ var ItemComponent = opts.ItemComponent, SectionComponent = opts.SectionComponent;
81
+ var disabledKeys = [];
82
+ var transform = function (item) {
83
+ var _a;
84
+ if (typeof item === "string") {
85
+ return (React__default.createElement(ItemComponent, { key: item, value: item }, item));
86
+ }
87
+ else if ("children" in item) {
88
+ return (React__default.createElement(SectionComponent, { key: item.title, title: item.title }, item.children.map(function (x) { return transform(x); })));
89
+ }
90
+ else {
91
+ if (item.isDisabled) {
92
+ disabledKeys.push(item.value);
93
+ }
94
+ return (React__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));
95
+ }
96
+ };
97
+ return {
98
+ items: (_a = items === null || items === void 0 ? void 0 : items.map(function (x) { return transform(x); })) !== null && _a !== void 0 ? _a : [],
99
+ disabledKeys: disabledKeys,
100
+ };
101
+ }
102
+ /**
103
+ * Given children of a component like Select or Menu, derive the items
104
+ * that we will pass into the Collections API. These will be
105
+ * ReactElement<ItemLikeProps|SectionLikeProps>[].
106
+ *
107
+ * Will also assign keys to items by their index in the collection,
108
+ * and collect the keys of disabled items.
109
+ */
110
+ function deriveItemsFromChildren(children, opts) {
111
+ if (!children) {
112
+ return {
113
+ items: [],
114
+ disabledKeys: [],
115
+ };
116
+ }
117
+ var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError;
118
+ // For Plume items without an explicit key, we assign a key as the index
119
+ // of the collection.
120
+ var itemCount = 0;
121
+ var sectionCount = 0;
122
+ var ensureValue = function (element) {
123
+ if (!propInChild(element, "value")) {
124
+ if (opts.requireItemValue && PLUME_STRICT_MODE) {
125
+ throw new Error("Must specify a \"value\" prop for ".concat(getElementTypeName(element)));
126
+ }
127
+ else {
128
+ return cloneChild(element, { value: "".concat(itemCount++) });
129
+ }
130
+ }
131
+ else {
132
+ // Still increment count even if key is present, so that the
133
+ // auto-assigned key really reflects the index
134
+ itemCount++;
135
+ return element;
136
+ }
137
+ };
138
+ var disabledKeys = [];
139
+ var flattenedChildren = function (children) {
140
+ return toChildArray(children).flatMap(function (child) {
141
+ var _a;
142
+ if (React__default.isValidElement(child)) {
143
+ if (child.type === React__default.Fragment) {
144
+ return flattenedChildren(child.props
145
+ .children);
146
+ }
147
+ var type = getPlumeType(child);
148
+ if (type === itemPlumeType) {
149
+ child = ensureValue(child);
150
+ var childKey = getItemLikeKey(child);
151
+ if (getChildProp(child, "isDisabled") && !!childKey) {
152
+ disabledKeys.push(childKey);
153
+ }
154
+ return [child];
155
+ }
156
+ if (type === sectionPlumeType) {
157
+ return [
158
+ cloneChild(child, {
159
+ // key of section doesn't actually matter, just needs
160
+ // to be unique
161
+ key: (_a = child.key) !== null && _a !== void 0 ? _a : "section-".concat(sectionCount++),
162
+ children: flattenedChildren(getChildProp(child, "children")),
163
+ }),
164
+ ];
165
+ }
166
+ }
167
+ {
168
+ throw new Error(invalidChildError !== null && invalidChildError !== void 0 ? invalidChildError : "Unexpected child");
169
+ }
170
+ });
171
+ };
172
+ return { items: flattenedChildren(children), disabledKeys: disabledKeys };
173
+ }
174
+ function useDerivedItems(props, opts) {
175
+ var children = props.children;
176
+ var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError, requireItemValue = opts.requireItemValue, ItemComponent = opts.ItemComponent, SectionComponent = opts.SectionComponent, itemsProp = opts.itemsProp;
177
+ var items = itemsProp ? props[itemsProp] : undefined;
178
+ return React__default.useMemo(function () {
179
+ return deriveItemsFromProps(props, {
180
+ itemPlumeType: itemPlumeType,
181
+ sectionPlumeType: sectionPlumeType,
182
+ invalidChildError: invalidChildError,
183
+ requireItemValue: requireItemValue,
184
+ itemsProp: itemsProp,
185
+ ItemComponent: ItemComponent,
186
+ SectionComponent: SectionComponent,
187
+ });
188
+ }, [
189
+ children,
190
+ items,
191
+ itemPlumeType,
192
+ sectionPlumeType,
193
+ invalidChildError,
194
+ requireItemValue,
195
+ ItemComponent,
196
+ SectionComponent,
197
+ ]);
198
+ }
199
+ function useDerivedItemsFromChildren(children, opts) {
200
+ var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError, requireItemValue = opts.requireItemValue;
201
+ return React__default.useMemo(function () {
202
+ return deriveItemsFromChildren(children, {
203
+ itemPlumeType: itemPlumeType,
204
+ sectionPlumeType: sectionPlumeType,
205
+ invalidChildError: invalidChildError,
206
+ requireItemValue: requireItemValue,
207
+ });
208
+ }, [
209
+ children,
210
+ itemPlumeType,
211
+ sectionPlumeType,
212
+ invalidChildError,
213
+ requireItemValue,
214
+ ]);
215
+ }
216
+ /**
217
+ * Given a Collection node, create the React element that we should use
218
+ * to render it.
219
+ */
220
+ function renderCollectionNode(node) {
221
+ // node.rendered should already have our item-like or section-like Plume
222
+ // component elements, so we just need to clone them with a secret
223
+ // _node prop that we use to render.
224
+ return cloneChild(node.rendered, {
225
+ _node: node,
226
+ key: node.key,
227
+ });
228
+ }
229
+ /**
230
+ * Renders a item-like or section-like Plume component element into an
231
+ * Item or a Section element.
232
+ */
233
+ function renderAsCollectionChild(child, opts) {
234
+ var _a;
235
+ var plumeType = getPlumeType(child);
236
+ if (plumeType === opts.itemPlumeType) {
237
+ var option = child;
238
+ // We look at the children passed to the item-like element, and derive key
239
+ // or textValue from it if it is a string
240
+ var content = getChildProp(option, "children");
241
+ // The children render prop needs to return an <Item/>
242
+ return (React__default.createElement(Item
243
+ // We use ItemLike.value if the user explicitly specified a value,
244
+ // and we fallback to key. If the user specified neither, then
245
+ // the Collections API will generate a unique key for this item.
246
+ , {
247
+ // We use ItemLike.value if the user explicitly specified a value,
248
+ // and we fallback to key. If the user specified neither, then
249
+ // the Collections API will generate a unique key for this item.
250
+ key: getItemLikeKey(option),
251
+ // textValue is either explicitly specified by the user, or we
252
+ // try to derive it if `content` is a string.
253
+ textValue: (_a = getChildProp(option, "textValue")) !== null && _a !== void 0 ? _a : (isString(content)
254
+ ? content
255
+ : propInChild(option, "value")
256
+ ? getChildProp(option, "value")
257
+ : option.key), "aria-label": getChildProp(option, "aria-label") }, option));
258
+ }
259
+ else {
260
+ var group = child;
261
+ return (React__default.createElement(Section
262
+ // Note that we are using the whole section-like element as the title
263
+ // here, and not group.props.title; we want the entire section-like
264
+ // Plume element to end up as Node.rendered.
265
+ , {
266
+ // Note that we are using the whole section-like element as the title
267
+ // here, and not group.props.title; we want the entire section-like
268
+ // Plume element to end up as Node.rendered.
269
+ title: group, "aria-label": getChildProp(group, "aria-label"),
270
+ // We are flattening and deriving the descendant Options as items here.
271
+ // group.props.children should've already been cleaned up by
272
+ // deriveItemsFromChildren()
273
+ items: getChildProp(group, "children") }, function (c) { return renderAsCollectionChild(c, opts); }));
274
+ }
275
+ }
276
+ function getItemLikeKey(element) {
277
+ var _a;
278
+ return (_a = getChildProp(element, "value")) !== null && _a !== void 0 ? _a : element.key;
279
+ }
280
+ // PlasmicLoader-aware function to get prop from child.
281
+ function getChildProp(child, prop) {
282
+ return "componentProps" in child.props
283
+ ? child.props.componentProps[prop]
284
+ : child.props[prop];
285
+ }
286
+ // PlasmicLoader-aware function to check `if (prop in element.props)`.
287
+ function propInChild(child, prop) {
288
+ return "componentProps" in child.props
289
+ ? prop in child.props.componentProps
290
+ : prop in child.props;
291
+ }
292
+ // PlasmicLoader-aware function to clone React element.
293
+ function cloneChild(child, props) {
294
+ if (child.type.getPlumeType) {
295
+ // If React element has getPlumeType(), assume that it is PlasmicLoader,
296
+ // so add nodeProps to componentProps instead of element props.
297
+ return React__default.cloneElement(child, __assign({ componentProps: __assign(__assign({}, child.props.componentProps), props) }, (props.key ? { key: props.key } : {})));
298
+ }
299
+ return React__default.cloneElement(child, props);
300
300
  }
301
301
 
302
302
  export { renderAsCollectionChild as a, useDerivedItems as b, getChildProp as g, renderCollectionNode as r, useDerivedItemsFromChildren as u };
303
- //# sourceMappingURL=collection-utils-0967eaf0.js.map
303
+ //# sourceMappingURL=collection-utils-2f28e4eb.js.map