@plasmicapp/react-web 0.2.107 → 0.2.108

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 (66) hide show
  1. package/dist/react-web.cjs.development.js.map +1 -1
  2. package/dist/react-web.cjs.production.min.js.map +1 -1
  3. package/dist/react-web.esm.js.map +1 -1
  4. package/dist/render/{PlasmicHead.d.ts → PlasmicHead/index.d.ts} +0 -0
  5. package/package.json +1 -1
  6. package/skinny/dist/index.js +3 -2
  7. package/skinny/dist/index.js.map +1 -1
  8. package/skinny/dist/plume/checkbox/index.js +2 -1
  9. package/skinny/dist/plume/checkbox/index.js.map +1 -1
  10. package/skinny/dist/plume/menu/index.js +2 -1
  11. package/skinny/dist/plume/menu/index.js.map +1 -1
  12. package/skinny/dist/plume/menu-button/index.js +2 -1
  13. package/skinny/dist/plume/menu-button/index.js.map +1 -1
  14. package/skinny/dist/plume/select/index.js +2 -1
  15. package/skinny/dist/plume/select/index.js.map +1 -1
  16. package/skinny/dist/plume/switch/index.js +2 -1
  17. package/skinny/dist/plume/switch/index.js.map +1 -1
  18. package/skinny/dist/render/PlasmicHead/index.d.ts +35 -0
  19. package/skinny/dist/render/PlasmicHead/index.js +53 -0
  20. package/skinny/dist/render/PlasmicHead/index.js.map +1 -0
  21. package/skinny/dist/{ssr-a8081074.js → ssr-14264281.js} +57 -7
  22. package/skinny/dist/ssr-14264281.js.map +1 -0
  23. package/skinny/dist/{ssr-902d1292.js → ssr-5141fc77.js} +62 -9
  24. package/skinny/dist/ssr-5141fc77.js.map +1 -0
  25. package/skinny/dist/ssr-579df58f.js +158 -0
  26. package/skinny/dist/ssr-579df58f.js.map +1 -0
  27. package/skinny/dist/{ssr-64e38713.js → ssr-84e27ffb.js} +5 -3
  28. package/skinny/dist/ssr-84e27ffb.js.map +1 -0
  29. package/skinny/dist/collection-utils-47e89cbe.js +0 -238
  30. package/skinny/dist/collection-utils-47e89cbe.js.map +0 -1
  31. package/skinny/dist/collection-utils-4dae6efa.js +0 -292
  32. package/skinny/dist/collection-utils-4dae6efa.js.map +0 -1
  33. package/skinny/dist/collection-utils-57ec40f9.js +0 -292
  34. package/skinny/dist/collection-utils-57ec40f9.js.map +0 -1
  35. package/skinny/dist/collection-utils-96cde83c.js +0 -238
  36. package/skinny/dist/collection-utils-96cde83c.js.map +0 -1
  37. package/skinny/dist/collection-utils-b0b8f30e.js +0 -291
  38. package/skinny/dist/collection-utils-b0b8f30e.js.map +0 -1
  39. package/skinny/dist/plume-utils-5c413fd1.js +0 -35
  40. package/skinny/dist/plume-utils-5c413fd1.js.map +0 -1
  41. package/skinny/dist/props-utils-4633caf6.js +0 -8
  42. package/skinny/dist/props-utils-4633caf6.js.map +0 -1
  43. package/skinny/dist/props-utils-5c0ad25a.js +0 -59
  44. package/skinny/dist/props-utils-5c0ad25a.js.map +0 -1
  45. package/skinny/dist/props-utils-754f655a.js +0 -39
  46. package/skinny/dist/props-utils-754f655a.js.map +0 -1
  47. package/skinny/dist/props-utils-c632595f.js +0 -59
  48. package/skinny/dist/props-utils-c632595f.js.map +0 -1
  49. package/skinny/dist/props-utils-fd5f444e.js +0 -59
  50. package/skinny/dist/props-utils-fd5f444e.js.map +0 -1
  51. package/skinny/dist/react-utils-118d8539.js +0 -190
  52. package/skinny/dist/react-utils-118d8539.js.map +0 -1
  53. package/skinny/dist/react-utils-2a2fd6c9.js +0 -339
  54. package/skinny/dist/react-utils-2a2fd6c9.js.map +0 -1
  55. package/skinny/dist/react-utils-2d70bbbe.js +0 -172
  56. package/skinny/dist/react-utils-2d70bbbe.js.map +0 -1
  57. package/skinny/dist/react-utils-675565b4.js +0 -334
  58. package/skinny/dist/react-utils-675565b4.js.map +0 -1
  59. package/skinny/dist/render/PlasmicImg.d.ts +0 -62
  60. package/skinny/dist/ssr-64e38713.js.map +0 -1
  61. package/skinny/dist/ssr-902d1292.js.map +0 -1
  62. package/skinny/dist/ssr-a8081074.js.map +0 -1
  63. package/skinny/dist/tslib.es6-00014098.js +0 -148
  64. package/skinny/dist/tslib.es6-00014098.js.map +0 -1
  65. package/skinny/dist/tslib.es6-73236e8e.js +0 -141
  66. package/skinny/dist/tslib.es6-73236e8e.js.map +0 -1
@@ -1,292 +0,0 @@
1
- import {
2
- a as __assign,
3
- l as isString,
4
- t as toChildArray,
5
- q as getElementTypeName,
6
- } from "./react-utils-2a2fd6c9.js";
7
- import React__default from "react";
8
- import { Item, Section } from "react-stately";
9
- import {
10
- a as getPlumeType,
11
- P as PLUME_STRICT_MODE,
12
- } from "./props-utils-5c0ad25a.js";
13
-
14
- /**
15
- * In general, we try not to expose react-aria's Collections API to Plume users.
16
- * The Collections API is how react-aria users pass data about collections of
17
- * things using the built-in Item and Section components, which are abstract,
18
- * metadata-only components that don't render anything but only serve to specify
19
- * data. For example, here's how you would use react-spectrum's Picker:
20
- *
21
- * <Picker>
22
- * <Section title="Asia">
23
- * <Item key="taiwan">Taiwan</Item>
24
- * <Item key="japan">Japan</Item>
25
- * <Item key="china">China</Item>
26
- * </Section>
27
- * <Section title="Europe">
28
- * <Item key="germany">Germany</Item>
29
- * <Item key="france">France</Item>
30
- * </Section>
31
- * </Picker>
32
- *
33
- * You would re-use this same Item/Section components to pass similar things to
34
- * Menu, Tabs, etc.
35
- *
36
- * For Plasmic, this API is too abstract. The user has explicitly designed components
37
- * like Select.Option and Select.OptionGroup, and it is weird that they don't actually
38
- * use these components. It is more natural to do:
39
- *
40
- * <Select>
41
- * <Select.OptionGroup title="Asia">
42
- * <Select.Option key="taiwan">Taiwan</Select>
43
- * </Select.OptionGroup>
44
- * </Select>
45
- *
46
- * For Plume, we let users directly use the components they designed, both to collect
47
- * information and to perform actual rendering. For example, for Plume,
48
- * you'd use Select.Option instead of Item, and Select.OptionGroup instead of Section.
49
- * This means that the Select.Option props will collect the same information Item
50
- * does.
51
- *
52
- * A component like Select.Option then serves two purposes:
53
- *
54
- * 1. Allow users to specify the collection of data, like in the above example
55
- * Here, we're mainly interested in the props in those ReactElements so
56
- * we can pass the Item/Section data onto react-aria's APIs. We are not
57
- * actually rendering these elements.
58
- * 2. Once react-aria's Collections API has gone through them and built
59
- * Collection "nodes", we then create cloned versions of these elements
60
- * with the corresponding node passed in as a secret prop. These ReactElements
61
- * are then actually used to _render_ the corresponding Option / OptionGroup.
62
- *
63
- * This file contains helper functions to help with implementing the above.
64
- *
65
- * Note also that most of the collections-based react-aria components expose
66
- * a parallel API that accepts a list of "items" and a render prop, instead
67
- * of list of Item/Section elements. This is for efficiency, but we are opting
68
- * to only support the composite-component pattern for now for simplicity.
69
- */
70
- /**
71
- * Given children of a component like Select or Menu, derive the items
72
- * that we will pass into the Collections API. These will be
73
- * ReactElement<ItemLikeProps|SectionLikeProps>[].
74
- *
75
- * Will also assign keys to items by their index in the collection,
76
- * and collect the keys of disabled items.
77
- */
78
- function deriveItemsFromChildren(children, opts) {
79
- if (!children) {
80
- return {
81
- items: [],
82
- disabledKeys: [],
83
- };
84
- }
85
- var itemPlumeType = opts.itemPlumeType,
86
- sectionPlumeType = opts.sectionPlumeType,
87
- invalidChildError = opts.invalidChildError;
88
- // For Plume items without an explicit key, we assign a key as the index
89
- // of the collection.
90
- var itemCount = 0;
91
- var sectionCount = 0;
92
- var ensureValue = function (element) {
93
- if (!propInChild(element, "value")) {
94
- if (opts.requireItemValue && PLUME_STRICT_MODE) {
95
- throw new Error(
96
- 'Must specify a "value" prop for ' + getElementTypeName(element)
97
- );
98
- } else {
99
- return cloneChild(element, { value: "" + itemCount++ });
100
- }
101
- } else {
102
- // Still increment count even if key is present, so that the
103
- // auto-assigned key really reflects the index
104
- itemCount++;
105
- return element;
106
- }
107
- };
108
- var disabledKeys = [];
109
- var flattenedChildren = function (children) {
110
- return toChildArray(children).flatMap(function (child) {
111
- var _a;
112
- if (React__default.isValidElement(child)) {
113
- if (child.type === React__default.Fragment) {
114
- return flattenedChildren(child.props.children);
115
- }
116
- var type = getPlumeType(child);
117
- if (type === itemPlumeType) {
118
- child = ensureValue(child);
119
- var childKey = getItemLikeKey(child);
120
- if (getChildProp(child, "isDisabled") && !!childKey) {
121
- disabledKeys.push(childKey);
122
- }
123
- return [child];
124
- }
125
- if (type === sectionPlumeType) {
126
- return [
127
- cloneChild(child, {
128
- // key of section doesn't actually matter, just needs
129
- // to be unique
130
- key:
131
- (_a = child.key) !== null && _a !== void 0
132
- ? _a
133
- : "section-" + sectionCount++,
134
- children: flattenedChildren(getChildProp(child, "children")),
135
- }),
136
- ];
137
- }
138
- }
139
- {
140
- throw new Error(
141
- invalidChildError !== null && invalidChildError !== void 0
142
- ? invalidChildError
143
- : "Unexpected child"
144
- );
145
- }
146
- });
147
- };
148
- return { items: flattenedChildren(children), disabledKeys: disabledKeys };
149
- }
150
- function useDerivedItemsFromChildren(children, opts) {
151
- var itemPlumeType = opts.itemPlumeType,
152
- sectionPlumeType = opts.sectionPlumeType,
153
- invalidChildError = opts.invalidChildError,
154
- requireItemValue = opts.requireItemValue;
155
- return React__default.useMemo(
156
- function () {
157
- return deriveItemsFromChildren(children, {
158
- itemPlumeType: itemPlumeType,
159
- sectionPlumeType: sectionPlumeType,
160
- invalidChildError: invalidChildError,
161
- requireItemValue: requireItemValue,
162
- });
163
- },
164
- [
165
- children,
166
- itemPlumeType,
167
- sectionPlumeType,
168
- invalidChildError,
169
- requireItemValue,
170
- ]
171
- );
172
- }
173
- /**
174
- * Given a Collection node, create the React element that we should use
175
- * to render it.
176
- */
177
- function renderCollectionNode(node) {
178
- // node.rendered should already have our item-like or section-like Plume
179
- // component elements, so we just need to clone them with a secret
180
- // _node prop that we use to render.
181
- return cloneChild(node.rendered, {
182
- _node: node,
183
- key: node.key,
184
- });
185
- }
186
- /**
187
- * Renders a item-like or section-like Plume component element into an
188
- * Item or a Section element.
189
- */
190
- function renderAsCollectionChild(child, opts) {
191
- var _a;
192
- var plumeType = getPlumeType(child);
193
- if (plumeType === opts.itemPlumeType) {
194
- var option = child;
195
- // We look at the children passed to the item-like element, and derive key
196
- // or textValue from it if it is a string
197
- var content = getChildProp(option, "children");
198
- // The children render prop needs to return an <Item/>
199
- return React__default.createElement(
200
- Item,
201
- // We use ItemLike.value if the user explicitly specified a value,
202
- // and we fallback to key. If the user specified neither, then
203
- // the Collections API will generate a unique key for this item.
204
- {
205
- // We use ItemLike.value if the user explicitly specified a value,
206
- // and we fallback to key. If the user specified neither, then
207
- // the Collections API will generate a unique key for this item.
208
- key: getItemLikeKey(option),
209
- // textValue is either explicitly specified by the user, or we
210
- // try to derive it if `content` is a string.
211
- textValue:
212
- (_a = getChildProp(option, "textValue")) !== null && _a !== void 0
213
- ? _a
214
- : isString(content)
215
- ? content
216
- : propInChild(option, "value")
217
- ? getChildProp(option, "value")
218
- : option.key,
219
- "aria-label": getChildProp(option, "aria-label"),
220
- },
221
- option
222
- );
223
- } else {
224
- var group = child;
225
- return React__default.createElement(
226
- Section,
227
- // Note that we are using the whole section-like element as the title
228
- // here, and not group.props.title; we want the entire section-like
229
- // Plume element to end up as Node.rendered.
230
- {
231
- // Note that we are using the whole section-like element as the title
232
- // here, and not group.props.title; we want the entire section-like
233
- // Plume element to end up as Node.rendered.
234
- title: group,
235
- "aria-label": getChildProp(group, "aria-label"),
236
- // We are flattening and deriving the descendant Options as items here.
237
- // group.props.children should've already been cleaned up by
238
- // deriveItemsFromChildren()
239
- items: getChildProp(group, "children"),
240
- },
241
- function (c) {
242
- return renderAsCollectionChild(c, opts);
243
- }
244
- );
245
- }
246
- }
247
- function getItemLikeKey(element) {
248
- var _a;
249
- return (_a = getChildProp(element, "value")) !== null && _a !== void 0
250
- ? _a
251
- : element.key;
252
- }
253
- // PlasmicLoader-aware function to get prop from child.
254
- function getChildProp(child, prop) {
255
- return "componentProps" in child.props
256
- ? child.props.componentProps[prop]
257
- : child.props[prop];
258
- }
259
- // PlasmicLoader-aware function to check `if (prop in element.props)`.
260
- function propInChild(child, prop) {
261
- return "componentProps" in child.props
262
- ? prop in child.props.componentProps
263
- : prop in child.props;
264
- }
265
- // PlasmicLoader-aware function to clone React element.
266
- function cloneChild(child, props) {
267
- if (child.type.getPlumeType) {
268
- // If React element has getPlumeType(), assume that it is PlasmicLoader,
269
- // so add nodeProps to componentProps instead of element props.
270
- return React__default.cloneElement(
271
- child,
272
- __assign(
273
- {
274
- componentProps: __assign(
275
- __assign({}, child.props.componentProps),
276
- props
277
- ),
278
- },
279
- props.key ? { key: props.key } : {}
280
- )
281
- );
282
- }
283
- return React__default.cloneElement(child, props);
284
- }
285
-
286
- export {
287
- renderAsCollectionChild as a,
288
- getChildProp as g,
289
- renderCollectionNode as r,
290
- useDerivedItemsFromChildren as u,
291
- };
292
- //# sourceMappingURL=collection-utils-4dae6efa.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"collection-utils-4dae6efa.js","sources":["../../src/plume/collection-utils.tsx"],"sourcesContent":["/**\n * In general, we try not to expose react-aria's Collections API to Plume users.\n * The Collections API is how react-aria users pass data about collections of\n * things using the built-in Item and Section components, which are abstract,\n * metadata-only components that don't render anything but only serve to specify\n * data. For example, here's how you would use react-spectrum's Picker:\n *\n * <Picker>\n * <Section title=\"Asia\">\n * <Item key=\"taiwan\">Taiwan</Item>\n * <Item key=\"japan\">Japan</Item>\n * <Item key=\"china\">China</Item>\n * </Section>\n * <Section title=\"Europe\">\n * <Item key=\"germany\">Germany</Item>\n * <Item key=\"france\">France</Item>\n * </Section>\n * </Picker>\n *\n * You would re-use this same Item/Section components to pass similar things to\n * Menu, Tabs, etc.\n *\n * For Plasmic, this API is too abstract. The user has explicitly designed components\n * like Select.Option and Select.OptionGroup, and it is weird that they don't actually\n * use these components. It is more natural to do:\n *\n * <Select>\n * <Select.OptionGroup title=\"Asia\">\n * <Select.Option key=\"taiwan\">Taiwan</Select>\n * </Select.OptionGroup>\n * </Select>\n *\n * For Plume, we let users directly use the components they designed, both to collect\n * information and to perform actual rendering. For example, for Plume,\n * you'd use Select.Option instead of Item, and Select.OptionGroup instead of Section.\n * This means that the Select.Option props will collect the same information Item\n * does.\n *\n * A component like Select.Option then serves two purposes:\n *\n * 1. Allow users to specify the collection of data, like in the above example\n * Here, we're mainly interested in the props in those ReactElements so\n * we can pass the Item/Section data onto react-aria's APIs. We are not\n * actually rendering these elements.\n * 2. Once react-aria's Collections API has gone through them and built\n * Collection \"nodes\", we then create cloned versions of these elements\n * with the corresponding node passed in as a secret prop. These ReactElements\n * are then actually used to _render_ the corresponding Option / OptionGroup.\n *\n * This file contains helper functions to help with implementing the above.\n *\n * Note also that most of the collections-based react-aria components expose\n * a parallel API that accepts a list of \"items\" and a render prop, instead\n * of list of Item/Section elements. This is for efficiency, but we are opting\n * to only support the composite-component pattern for now for simplicity.\n */\n\nimport { Node } from \"@react-types/shared\";\nimport React from \"react\";\nimport { Item, Section } from \"react-stately\";\nimport { isString } from \"../common\";\nimport { getElementTypeName, toChildArray } from \"../react-utils\";\nimport { getPlumeType, PLUME_STRICT_MODE } from \"./plume-utils\";\n\nexport interface PlasmicLoaderProps<T> {\n component: string;\n componentProps: T;\n}\n\n/**\n * Props for a Plume component that corresponds to an Item\n */\nexport interface ItemLikeProps {\n /**\n * value key corresponding to this item. Not required if you use the\n * `key` prop instead.\n */\n value?: string | null;\n\n /**\n * The text string value corresponding to this item. Used to support\n * keyboard type-ahead. If not specified, then will be derived from\n * `children` if it is a string, or the `value` or `key`.\n */\n textValue?: string;\n\n /**\n * aria-label for this item.\n */\n \"aria-label\"?: string;\n\n /**\n * Primary content label for this item.\n */\n children?: React.ReactNode;\n\n /**\n * If true, this item will not be selectable.\n */\n isDisabled?: boolean;\n}\n\ntype LoaderAwareItemLikeProps =\n | ItemLikeProps\n | PlasmicLoaderProps<ItemLikeProps>;\n\n/**\n * Props for a Plume component that corresponds to a Section\n */\nexport interface SectionLikeProps {\n /**\n * Heading content of the title\n */\n title?: React.ReactNode;\n\n /**\n * aria-label for this section\n */\n \"aria-label\"?: string;\n\n /**\n * A list of items that belong in this group\n */\n children?: React.ReactNode;\n}\n\ntype LoaderAwareSectionLikeProps =\n | SectionLikeProps\n | PlasmicLoaderProps<SectionLikeProps>;\n\n/**\n * Given children of a component like Select or Menu, derive the items\n * that we will pass into the Collections API. These will be\n * ReactElement<ItemLikeProps|SectionLikeProps>[].\n *\n * Will also assign keys to items by their index in the collection,\n * and collect the keys of disabled items.\n */\nexport function deriveItemsFromChildren<T extends React.ReactElement>(\n children: React.ReactNode,\n opts: {\n itemPlumeType: string;\n sectionPlumeType?: string;\n invalidChildError?: string;\n requireItemValue: boolean;\n }\n) {\n if (!children) {\n return {\n items: [] as T[],\n disabledKeys: [] as React.Key[],\n };\n }\n\n const { itemPlumeType, sectionPlumeType, invalidChildError } = opts;\n\n // For Plume items without an explicit key, we assign a key as the index\n // of the collection.\n let itemCount = 0;\n let sectionCount = 0;\n\n const ensureValue = (element: React.ReactElement) => {\n if (!propInChild(element, \"value\")) {\n if (opts.requireItemValue && PLUME_STRICT_MODE) {\n throw new Error(\n `Must specify a \"value\" prop for ${getElementTypeName(element)}`\n );\n } else {\n return cloneChild(element, { value: `${itemCount++}` });\n }\n } else {\n // Still increment count even if key is present, so that the\n // auto-assigned key really reflects the index\n itemCount++;\n return element;\n }\n };\n\n const disabledKeys: React.Key[] = [];\n\n const flattenedChildren = (\n children: React.ReactNode\n ): React.ReactElement[] => {\n return toChildArray(children).flatMap((child) => {\n if (React.isValidElement(child)) {\n if (child.type === React.Fragment) {\n return flattenedChildren(child.props.children);\n }\n const type = getPlumeType(child);\n if (type === itemPlumeType) {\n child = ensureValue(child);\n const childKey = getItemLikeKey(child);\n if (getChildProp(child, \"isDisabled\") && !!childKey) {\n disabledKeys.push(childKey);\n }\n return [child];\n }\n if (type === sectionPlumeType) {\n return [\n cloneChild(child, {\n // key of section doesn't actually matter, just needs\n // to be unique\n key: child.key ?? `section-${sectionCount++}`,\n children: flattenedChildren(getChildProp(child, \"children\")),\n }),\n ];\n }\n }\n\n if (PLUME_STRICT_MODE) {\n throw new Error(invalidChildError ?? `Unexpected child`);\n } else {\n return [];\n }\n });\n };\n\n return { items: flattenedChildren(children) as T[], disabledKeys };\n}\n\nexport function useDerivedItemsFromChildren<T extends React.ReactElement>(\n children: React.ReactNode,\n opts: {\n itemPlumeType: string;\n sectionPlumeType?: string;\n invalidChildError?: string;\n requireItemValue: boolean;\n }\n) {\n const {\n itemPlumeType,\n sectionPlumeType,\n invalidChildError,\n requireItemValue,\n } = opts;\n return React.useMemo(() => {\n return deriveItemsFromChildren<T>(children, {\n itemPlumeType,\n sectionPlumeType,\n invalidChildError,\n requireItemValue,\n });\n }, [\n children,\n itemPlumeType,\n sectionPlumeType,\n invalidChildError,\n requireItemValue,\n ]);\n}\n\n/**\n * Given a Collection node, create the React element that we should use\n * to render it.\n */\nexport function renderCollectionNode(node: Node<any>) {\n // node.rendered should already have our item-like or section-like Plume\n // component elements, so we just need to clone them with a secret\n // _node prop that we use to render.\n return cloneChild(node.rendered as React.ReactElement, {\n _node: node,\n key: node.key,\n });\n}\n\n/**\n * Renders a item-like or section-like Plume component element into an\n * Item or a Section element.\n */\nexport function renderAsCollectionChild<\n T extends React.ReactElement<\n LoaderAwareItemLikeProps | LoaderAwareSectionLikeProps\n >\n>(\n child: T,\n opts: {\n itemPlumeType: string;\n sectionPlumeType?: string;\n }\n) {\n const plumeType = getPlumeType(child);\n if (plumeType === opts.itemPlumeType) {\n const option = child as React.ReactElement<LoaderAwareItemLikeProps>;\n\n // We look at the children passed to the item-like element, and derive key\n // or textValue from it if it is a string\n const content = getChildProp(option, \"children\");\n\n // The children render prop needs to return an <Item/>\n return (\n <Item\n // We use ItemLike.value if the user explicitly specified a value,\n // and we fallback to key. If the user specified neither, then\n // the Collections API will generate a unique key for this item.\n key={getItemLikeKey(option)}\n // textValue is either explicitly specified by the user, or we\n // try to derive it if `content` is a string.\n textValue={\n getChildProp(option, \"textValue\") ??\n (isString(content)\n ? content\n : propInChild(option, \"value\")\n ? getChildProp(option, \"value\")\n : option.key)\n }\n aria-label={getChildProp(option, \"aria-label\")}\n >\n {\n // Note that what we setting the item-like element as the children\n // here, and not content; we want the entire item-like Plume element to\n // end up as Node.rendered.\n }\n {option}\n </Item>\n );\n } else {\n const group = child as React.ReactElement<LoaderAwareSectionLikeProps>;\n return (\n <Section\n // Note that we are using the whole section-like element as the title\n // here, and not group.props.title; we want the entire section-like\n // Plume element to end up as Node.rendered.\n title={group}\n aria-label={getChildProp(group, \"aria-label\")}\n // We are flattening and deriving the descendant Options as items here.\n // group.props.children should've already been cleaned up by\n // deriveItemsFromChildren()\n items={getChildProp(group, \"children\") as React.ReactElement[]}\n >\n {\n // We use the same render function to turn descendent Options into Items\n }\n {(c: React.ReactElement) => renderAsCollectionChild(c, opts)}\n </Section>\n );\n }\n}\n\nfunction getItemLikeKey(element: React.ReactElement<LoaderAwareItemLikeProps>) {\n return getChildProp(element, \"value\") ?? element.key;\n}\n\n// PlasmicLoader-aware function to get prop from child.\nexport function getChildProp(child: React.ReactElement, prop: string) {\n return \"componentProps\" in child.props\n ? child.props.componentProps[prop]\n : child.props[prop];\n}\n\n// PlasmicLoader-aware function to check `if (prop in element.props)`.\nfunction propInChild(child: React.ReactElement, prop: string): boolean {\n return \"componentProps\" in child.props\n ? prop in child.props.componentProps\n : prop in child.props;\n}\n\n// PlasmicLoader-aware function to clone React element.\nfunction cloneChild(child: React.ReactElement, props: Record<string, any>) {\n if ((child.type as any).getPlumeType) {\n // If React element has getPlumeType(), assume that it is PlasmicLoader,\n // so add nodeProps to componentProps instead of element props.\n return React.cloneElement(child, {\n componentProps: {\n ...child.props.componentProps,\n ...props,\n },\n ...(props.key ? { key: props.key } : {}),\n });\n }\n\n return React.cloneElement(child, props);\n}\n"],"names":["React"],"mappings":";;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkIA;;;;;;;;SAQgB,uBAAuB,CACrC,QAAyB,EACzB,IAKC;IAED,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO;YACL,KAAK,EAAE,EAAS;YAChB,YAAY,EAAE,EAAiB;S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AC,IAAI,CAAC;UAChC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAED;AACA,SAAS,WAAW,CAAC,KAAyB,EAAE,IAAY;IAC1D,OAAO,gBAAgB,IAAI,KAAK,CAAC,KAAK;UAClC,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,cAAc;UAClC,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC;AAC1B,CAAC;AAED;AACA,SAAS,UAAU,CAAC,KAAyB,EAAE,KAA0B;IACvE,IAAK,KAAK,CAAC,IAAY,CAAC,YAAY,EAAE;;;QAGpC,OAAOA,cAAK,CAAC,YAAY,CAAC,KAAK,aAC7B,cAAc,wBACT,KAAK,CAAC,KAAK,CAAC,cAAc,GAC1B,KAAK,MAEN,KAAK,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GACvC,CAAC;KACJ;IAED,OAAOA,cAAK,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC1C;;;;"}
@@ -1,292 +0,0 @@
1
- import {
2
- a as __assign,
3
- t as toChildArray,
4
- l as isString,
5
- q as getElementTypeName,
6
- } from "./react-utils-675565b4.js";
7
- import React__default from "react";
8
- import { Item, Section } from "react-stately";
9
- import {
10
- a as getPlumeType,
11
- P as PLUME_STRICT_MODE,
12
- } from "./props-utils-fd5f444e.js";
13
-
14
- /**
15
- * In general, we try not to expose react-aria's Collections API to Plume users.
16
- * The Collections API is how react-aria users pass data about collections of
17
- * things using the built-in Item and Section components, which are abstract,
18
- * metadata-only components that don't render anything but only serve to specify
19
- * data. For example, here's how you would use react-spectrum's Picker:
20
- *
21
- * <Picker>
22
- * <Section title="Asia">
23
- * <Item key="taiwan">Taiwan</Item>
24
- * <Item key="japan">Japan</Item>
25
- * <Item key="china">China</Item>
26
- * </Section>
27
- * <Section title="Europe">
28
- * <Item key="germany">Germany</Item>
29
- * <Item key="france">France</Item>
30
- * </Section>
31
- * </Picker>
32
- *
33
- * You would re-use this same Item/Section components to pass similar things to
34
- * Menu, Tabs, etc.
35
- *
36
- * For Plasmic, this API is too abstract. The user has explicitly designed components
37
- * like Select.Option and Select.OptionGroup, and it is weird that they don't actually
38
- * use these components. It is more natural to do:
39
- *
40
- * <Select>
41
- * <Select.OptionGroup title="Asia">
42
- * <Select.Option key="taiwan">Taiwan</Select>
43
- * </Select.OptionGroup>
44
- * </Select>
45
- *
46
- * For Plume, we let users directly use the components they designed, both to collect
47
- * information and to perform actual rendering. For example, for Plume,
48
- * you'd use Select.Option instead of Item, and Select.OptionGroup instead of Section.
49
- * This means that the Select.Option props will collect the same information Item
50
- * does.
51
- *
52
- * A component like Select.Option then serves two purposes:
53
- *
54
- * 1. Allow users to specify the collection of data, like in the above example
55
- * Here, we're mainly interested in the props in those ReactElements so
56
- * we can pass the Item/Section data onto react-aria's APIs. We are not
57
- * actually rendering these elements.
58
- * 2. Once react-aria's Collections API has gone through them and built
59
- * Collection "nodes", we then create cloned versions of these elements
60
- * with the corresponding node passed in as a secret prop. These ReactElements
61
- * are then actually used to _render_ the corresponding Option / OptionGroup.
62
- *
63
- * This file contains helper functions to help with implementing the above.
64
- *
65
- * Note also that most of the collections-based react-aria components expose
66
- * a parallel API that accepts a list of "items" and a render prop, instead
67
- * of list of Item/Section elements. This is for efficiency, but we are opting
68
- * to only support the composite-component pattern for now for simplicity.
69
- */
70
- /**
71
- * Given children of a component like Select or Menu, derive the items
72
- * that we will pass into the Collections API. These will be
73
- * ReactElement<ItemLikeProps|SectionLikeProps>[].
74
- *
75
- * Will also assign keys to items by their index in the collection,
76
- * and collect the keys of disabled items.
77
- */
78
- function deriveItemsFromChildren(children, opts) {
79
- if (!children) {
80
- return {
81
- items: [],
82
- disabledKeys: [],
83
- };
84
- }
85
- var itemPlumeType = opts.itemPlumeType,
86
- sectionPlumeType = opts.sectionPlumeType,
87
- invalidChildError = opts.invalidChildError;
88
- // For Plume items without an explicit key, we assign a key as the index
89
- // of the collection.
90
- var itemCount = 0;
91
- var sectionCount = 0;
92
- var ensureValue = function (element) {
93
- if (!propInChild(element, "value")) {
94
- if (opts.requireItemValue && PLUME_STRICT_MODE) {
95
- throw new Error(
96
- 'Must specify a "value" prop for ' + getElementTypeName(element)
97
- );
98
- } else {
99
- return cloneChild(element, { value: "" + itemCount++ });
100
- }
101
- } else {
102
- // Still increment count even if key is present, so that the
103
- // auto-assigned key really reflects the index
104
- itemCount++;
105
- return element;
106
- }
107
- };
108
- var disabledKeys = [];
109
- var flattenedChildren = function (children) {
110
- return toChildArray(children).flatMap(function (child) {
111
- var _a;
112
- if (React__default.isValidElement(child)) {
113
- if (child.type === React__default.Fragment) {
114
- return flattenedChildren(child.props.children);
115
- }
116
- var type = getPlumeType(child);
117
- if (type === itemPlumeType) {
118
- child = ensureValue(child);
119
- var childKey = getItemLikeKey(child);
120
- if (getChildProp(child, "isDisabled") && !!childKey) {
121
- disabledKeys.push(childKey);
122
- }
123
- return [child];
124
- }
125
- if (type === sectionPlumeType) {
126
- return [
127
- cloneChild(child, {
128
- // key of section doesn't actually matter, just needs
129
- // to be unique
130
- key:
131
- (_a = child.key) !== null && _a !== void 0
132
- ? _a
133
- : "section-" + sectionCount++,
134
- children: flattenedChildren(getChildProp(child, "children")),
135
- }),
136
- ];
137
- }
138
- }
139
- {
140
- throw new Error(
141
- invalidChildError !== null && invalidChildError !== void 0
142
- ? invalidChildError
143
- : "Unexpected child"
144
- );
145
- }
146
- });
147
- };
148
- return { items: flattenedChildren(children), disabledKeys: disabledKeys };
149
- }
150
- function useDerivedItemsFromChildren(children, opts) {
151
- var itemPlumeType = opts.itemPlumeType,
152
- sectionPlumeType = opts.sectionPlumeType,
153
- invalidChildError = opts.invalidChildError,
154
- requireItemValue = opts.requireItemValue;
155
- return React__default.useMemo(
156
- function () {
157
- return deriveItemsFromChildren(children, {
158
- itemPlumeType: itemPlumeType,
159
- sectionPlumeType: sectionPlumeType,
160
- invalidChildError: invalidChildError,
161
- requireItemValue: requireItemValue,
162
- });
163
- },
164
- [
165
- children,
166
- itemPlumeType,
167
- sectionPlumeType,
168
- invalidChildError,
169
- requireItemValue,
170
- ]
171
- );
172
- }
173
- /**
174
- * Given a Collection node, create the React element that we should use
175
- * to render it.
176
- */
177
- function renderCollectionNode(node) {
178
- // node.rendered should already have our item-like or section-like Plume
179
- // component elements, so we just need to clone them with a secret
180
- // _node prop that we use to render.
181
- return cloneChild(node.rendered, {
182
- _node: node,
183
- key: node.key,
184
- });
185
- }
186
- /**
187
- * Renders a item-like or section-like Plume component element into an
188
- * Item or a Section element.
189
- */
190
- function renderAsCollectionChild(child, opts) {
191
- var _a;
192
- var plumeType = getPlumeType(child);
193
- if (plumeType === opts.itemPlumeType) {
194
- var option = child;
195
- // We look at the children passed to the item-like element, and derive key
196
- // or textValue from it if it is a string
197
- var content = getChildProp(option, "children");
198
- // The children render prop needs to return an <Item/>
199
- return React__default.createElement(
200
- Item,
201
- // We use ItemLike.value if the user explicitly specified a value,
202
- // and we fallback to key. If the user specified neither, then
203
- // the Collections API will generate a unique key for this item.
204
- {
205
- // We use ItemLike.value if the user explicitly specified a value,
206
- // and we fallback to key. If the user specified neither, then
207
- // the Collections API will generate a unique key for this item.
208
- key: getItemLikeKey(option),
209
- // textValue is either explicitly specified by the user, or we
210
- // try to derive it if `content` is a string.
211
- textValue:
212
- (_a = getChildProp(option, "textValue")) !== null && _a !== void 0
213
- ? _a
214
- : isString(content)
215
- ? content
216
- : propInChild(option, "value")
217
- ? getChildProp(option, "value")
218
- : option.key,
219
- "aria-label": getChildProp(option, "aria-label"),
220
- },
221
- option
222
- );
223
- } else {
224
- var group = child;
225
- return React__default.createElement(
226
- Section,
227
- // Note that we are using the whole section-like element as the title
228
- // here, and not group.props.title; we want the entire section-like
229
- // Plume element to end up as Node.rendered.
230
- {
231
- // Note that we are using the whole section-like element as the title
232
- // here, and not group.props.title; we want the entire section-like
233
- // Plume element to end up as Node.rendered.
234
- title: group,
235
- "aria-label": getChildProp(group, "aria-label"),
236
- // We are flattening and deriving the descendant Options as items here.
237
- // group.props.children should've already been cleaned up by
238
- // deriveItemsFromChildren()
239
- items: getChildProp(group, "children"),
240
- },
241
- function (c) {
242
- return renderAsCollectionChild(c, opts);
243
- }
244
- );
245
- }
246
- }
247
- function getItemLikeKey(element) {
248
- var _a;
249
- return (_a = getChildProp(element, "value")) !== null && _a !== void 0
250
- ? _a
251
- : element.key;
252
- }
253
- // PlasmicLoader-aware function to get prop from child.
254
- function getChildProp(child, prop) {
255
- return "componentProps" in child.props
256
- ? child.props.componentProps[prop]
257
- : child.props[prop];
258
- }
259
- // PlasmicLoader-aware function to check `if (prop in element.props)`.
260
- function propInChild(child, prop) {
261
- return "componentProps" in child.props
262
- ? prop in child.props.componentProps
263
- : prop in child.props;
264
- }
265
- // PlasmicLoader-aware function to clone React element.
266
- function cloneChild(child, props) {
267
- if (child.type.getPlumeType) {
268
- // If React element has getPlumeType(), assume that it is PlasmicLoader,
269
- // so add nodeProps to componentProps instead of element props.
270
- return React__default.cloneElement(
271
- child,
272
- __assign(
273
- {
274
- componentProps: __assign(
275
- __assign({}, child.props.componentProps),
276
- props
277
- ),
278
- },
279
- props.key ? { key: props.key } : {}
280
- )
281
- );
282
- }
283
- return React__default.cloneElement(child, props);
284
- }
285
-
286
- export {
287
- renderAsCollectionChild as a,
288
- getChildProp as g,
289
- renderCollectionNode as r,
290
- useDerivedItemsFromChildren as u,
291
- };
292
- //# sourceMappingURL=collection-utils-57ec40f9.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"collection-utils-57ec40f9.js","sources":["../../src/plume/collection-utils.tsx"],"sourcesContent":["/**\n * In general, we try not to expose react-aria's Collections API to Plume users.\n * The Collections API is how react-aria users pass data about collections of\n * things using the built-in Item and Section components, which are abstract,\n * metadata-only components that don't render anything but only serve to specify\n * data. For example, here's how you would use react-spectrum's Picker:\n *\n * <Picker>\n * <Section title=\"Asia\">\n * <Item key=\"taiwan\">Taiwan</Item>\n * <Item key=\"japan\">Japan</Item>\n * <Item key=\"china\">China</Item>\n * </Section>\n * <Section title=\"Europe\">\n * <Item key=\"germany\">Germany</Item>\n * <Item key=\"france\">France</Item>\n * </Section>\n * </Picker>\n *\n * You would re-use this same Item/Section components to pass similar things to\n * Menu, Tabs, etc.\n *\n * For Plasmic, this API is too abstract. The user has explicitly designed components\n * like Select.Option and Select.OptionGroup, and it is weird that they don't actually\n * use these components. It is more natural to do:\n *\n * <Select>\n * <Select.OptionGroup title=\"Asia\">\n * <Select.Option key=\"taiwan\">Taiwan</Select>\n * </Select.OptionGroup>\n * </Select>\n *\n * For Plume, we let users directly use the components they designed, both to collect\n * information and to perform actual rendering. For example, for Plume,\n * you'd use Select.Option instead of Item, and Select.OptionGroup instead of Section.\n * This means that the Select.Option props will collect the same information Item\n * does.\n *\n * A component like Select.Option then serves two purposes:\n *\n * 1. Allow users to specify the collection of data, like in the above example\n * Here, we're mainly interested in the props in those ReactElements so\n * we can pass the Item/Section data onto react-aria's APIs. We are not\n * actually rendering these elements.\n * 2. Once react-aria's Collections API has gone through them and built\n * Collection \"nodes\", we then create cloned versions of these elements\n * with the corresponding node passed in as a secret prop. These ReactElements\n * are then actually used to _render_ the corresponding Option / OptionGroup.\n *\n * This file contains helper functions to help with implementing the above.\n *\n * Note also that most of the collections-based react-aria components expose\n * a parallel API that accepts a list of \"items\" and a render prop, instead\n * of list of Item/Section elements. This is for efficiency, but we are opting\n * to only support the composite-component pattern for now for simplicity.\n */\n\nimport { Node } from \"@react-types/shared\";\nimport React from \"react\";\nimport { Item, Section } from \"react-stately\";\nimport { isString } from \"../common\";\nimport { getElementTypeName, toChildArray } from \"../react-utils\";\nimport { getPlumeType, PLUME_STRICT_MODE } from \"./plume-utils\";\n\nexport interface PlasmicLoaderProps<T> {\n component: string;\n componentProps: T;\n}\n\n/**\n * Props for a Plume component that corresponds to an Item\n */\nexport interface ItemLikeProps {\n /**\n * value key corresponding to this item. Not required if you use the\n * `key` prop instead.\n */\n value?: string | null;\n\n /**\n * The text string value corresponding to this item. Used to support\n * keyboard type-ahead. If not specified, then will be derived from\n * `children` if it is a string, or the `value` or `key`.\n */\n textValue?: string;\n\n /**\n * aria-label for this item.\n */\n \"aria-label\"?: string;\n\n /**\n * Primary content label for this item.\n */\n children?: React.ReactNode;\n\n /**\n * If true, this item will not be selectable.\n */\n isDisabled?: boolean;\n}\n\ntype LoaderAwareItemLikeProps =\n | ItemLikeProps\n | PlasmicLoaderProps<ItemLikeProps>;\n\n/**\n * Props for a Plume component that corresponds to a Section\n */\nexport interface SectionLikeProps {\n /**\n * Heading content of the title\n */\n title?: React.ReactNode;\n\n /**\n * aria-label for this section\n */\n \"aria-label\"?: string;\n\n /**\n * A list of items that belong in this group\n */\n children?: React.ReactNode;\n}\n\ntype LoaderAwareSectionLikeProps =\n | SectionLikeProps\n | PlasmicLoaderProps<SectionLikeProps>;\n\n/**\n * Given children of a component like Select or Menu, derive the items\n * that we will pass into the Collections API. These will be\n * ReactElement<ItemLikeProps|SectionLikeProps>[].\n *\n * Will also assign keys to items by their index in the collection,\n * and collect the keys of disabled items.\n */\nexport function deriveItemsFromChildren<T extends React.ReactElement>(\n children: React.ReactNode,\n opts: {\n itemPlumeType: string;\n sectionPlumeType?: string;\n invalidChildError?: string;\n requireItemValue: boolean;\n }\n) {\n if (!children) {\n return {\n items: [] as T[],\n disabledKeys: [] as React.Key[],\n };\n }\n\n const { itemPlumeType, sectionPlumeType, invalidChildError } = opts;\n\n // For Plume items without an explicit key, we assign a key as the index\n // of the collection.\n let itemCount = 0;\n let sectionCount = 0;\n\n const ensureValue = (element: React.ReactElement) => {\n if (!propInChild(element, \"value\")) {\n if (opts.requireItemValue && PLUME_STRICT_MODE) {\n throw new Error(\n `Must specify a \"value\" prop for ${getElementTypeName(element)}`\n );\n } else {\n return cloneChild(element, { value: `${itemCount++}` });\n }\n } else {\n // Still increment count even if key is present, so that the\n // auto-assigned key really reflects the index\n itemCount++;\n return element;\n }\n };\n\n const disabledKeys: React.Key[] = [];\n\n const flattenedChildren = (\n children: React.ReactNode\n ): React.ReactElement[] => {\n return toChildArray(children).flatMap((child) => {\n if (React.isValidElement(child)) {\n if (child.type === React.Fragment) {\n return flattenedChildren(child.props.children);\n }\n const type = getPlumeType(child);\n if (type === itemPlumeType) {\n child = ensureValue(child);\n const childKey = getItemLikeKey(child);\n if (getChildProp(child, \"isDisabled\") && !!childKey) {\n disabledKeys.push(childKey);\n }\n return [child];\n }\n if (type === sectionPlumeType) {\n return [\n cloneChild(child, {\n // key of section doesn't actually matter, just needs\n // to be unique\n key: child.key ?? `section-${sectionCount++}`,\n children: flattenedChildren(getChildProp(child, \"children\")),\n }),\n ];\n }\n }\n\n if (PLUME_STRICT_MODE) {\n throw new Error(invalidChildError ?? `Unexpected child`);\n } else {\n return [];\n }\n });\n };\n\n return { items: flattenedChildren(children) as T[], disabledKeys };\n}\n\nexport function useDerivedItemsFromChildren<T extends React.ReactElement>(\n children: React.ReactNode,\n opts: {\n itemPlumeType: string;\n sectionPlumeType?: string;\n invalidChildError?: string;\n requireItemValue: boolean;\n }\n) {\n const {\n itemPlumeType,\n sectionPlumeType,\n invalidChildError,\n requireItemValue,\n } = opts;\n return React.useMemo(() => {\n return deriveItemsFromChildren<T>(children, {\n itemPlumeType,\n sectionPlumeType,\n invalidChildError,\n requireItemValue,\n });\n }, [\n children,\n itemPlumeType,\n sectionPlumeType,\n invalidChildError,\n requireItemValue,\n ]);\n}\n\n/**\n * Given a Collection node, create the React element that we should use\n * to render it.\n */\nexport function renderCollectionNode(node: Node<any>) {\n // node.rendered should already have our item-like or section-like Plume\n // component elements, so we just need to clone them with a secret\n // _node prop that we use to render.\n return cloneChild(node.rendered as React.ReactElement, {\n _node: node,\n key: node.key,\n });\n}\n\n/**\n * Renders a item-like or section-like Plume component element into an\n * Item or a Section element.\n */\nexport function renderAsCollectionChild<\n T extends React.ReactElement<\n LoaderAwareItemLikeProps | LoaderAwareSectionLikeProps\n >\n>(\n child: T,\n opts: {\n itemPlumeType: string;\n sectionPlumeType?: string;\n }\n) {\n const plumeType = getPlumeType(child);\n if (plumeType === opts.itemPlumeType) {\n const option = child as React.ReactElement<LoaderAwareItemLikeProps>;\n\n // We look at the children passed to the item-like element, and derive key\n // or textValue from it if it is a string\n const content = getChildProp(option, \"children\");\n\n // The children render prop needs to return an <Item/>\n return (\n <Item\n // We use ItemLike.value if the user explicitly specified a value,\n // and we fallback to key. If the user specified neither, then\n // the Collections API will generate a unique key for this item.\n key={getItemLikeKey(option)}\n // textValue is either explicitly specified by the user, or we\n // try to derive it if `content` is a string.\n textValue={\n getChildProp(option, \"textValue\") ??\n (isString(content)\n ? content\n : propInChild(option, \"value\")\n ? getChildProp(option, \"value\")\n : option.key)\n }\n aria-label={getChildProp(option, \"aria-label\")}\n >\n {\n // Note that what we setting the item-like element as the children\n // here, and not content; we want the entire item-like Plume element to\n // end up as Node.rendered.\n }\n {option}\n </Item>\n );\n } else {\n const group = child as React.ReactElement<LoaderAwareSectionLikeProps>;\n return (\n <Section\n // Note that we are using the whole section-like element as the title\n // here, and not group.props.title; we want the entire section-like\n // Plume element to end up as Node.rendered.\n title={group}\n aria-label={getChildProp(group, \"aria-label\")}\n // We are flattening and deriving the descendant Options as items here.\n // group.props.children should've already been cleaned up by\n // deriveItemsFromChildren()\n items={getChildProp(group, \"children\") as React.ReactElement[]}\n >\n {\n // We use the same render function to turn descendent Options into Items\n }\n {(c: React.ReactElement) => renderAsCollectionChild(c, opts)}\n </Section>\n );\n }\n}\n\nfunction getItemLikeKey(element: React.ReactElement<LoaderAwareItemLikeProps>) {\n return getChildProp(element, \"value\") ?? element.key;\n}\n\n// PlasmicLoader-aware function to get prop from child.\nexport function getChildProp(child: React.ReactElement, prop: string) {\n return \"componentProps\" in child.props\n ? child.props.componentProps[prop]\n : child.props[prop];\n}\n\n// PlasmicLoader-aware function to check `if (prop in element.props)`.\nfunction propInChild(child: React.ReactElement, prop: string): boolean {\n return \"componentProps\" in child.props\n ? prop in child.props.componentProps\n : prop in child.props;\n}\n\n// PlasmicLoader-aware function to clone React element.\nfunction cloneChild(child: React.ReactElement, props: Record<string, any>) {\n if ((child.type as any).getPlumeType) {\n // If React element has getPlumeType(), assume that it is PlasmicLoader,\n // so add nodeProps to componentProps instead of element props.\n return React.cloneElement(child, {\n componentProps: {\n ...child.props.componentProps,\n ...props,\n },\n ...(props.key ? { key: props.key } : {}),\n });\n }\n\n return React.cloneElement(child, props);\n}\n"],"names":["React"],"mappings":";;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkIA;;;;;;;;SAQgB,uBAAuB,CACrC,QAAyB,EACzB,IAKC;IAED,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO;YACL,KAAK,EAAE,EAAS;YAChB,YAAY,EAAE,EAAiB;SAChC,CAAC;KACH;IAEO,IAAA,aAAa,GAA0C,IAAI,cAA9C,EAAE,gBAAgB,GAAwB,IAAI,iBAA5B,EAAE,iBAAiB,GAAK,IAAI,kBAAT,CAAU;;;IAIpE,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,IAAM,WAAW,GAAG,UAAC,OAA2B;QAC9C,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE;YAClC,IAAI,IAAI,CAAC,gBAAgB,IAAI,iBAAiB,EAAE;gBAC9C,MAAM,IAAI,KAAK,CACb,uCAAmC,kBAAkB,CAAC,OAAO,CAAG,CACjE,CAAC;aACH;iBAAM;gBACL,OAAO,UAAU,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAG,SAAS,EAAI,EAAE,CAAC,CAAC;aACzD;SACF;aAAM;;;YAGL,SAAS,EAAE,CAAC;YACZ,OAAO,OAAO,CAAC;SAChB;KACF,CAAC;IAEF,IAAM,YAAY,GAAgB,EAAE,CAAC;IAErC,IAAM,iBAAiB,GAAG,UACxB,QAAyB;QAEzB,OAAO,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