@plasmicapp/react-web 0.2.96 → 0.2.99

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 (56) hide show
  1. package/dist/react-web.cjs.development.js +16 -17
  2. package/dist/react-web.cjs.development.js.map +1 -1
  3. package/dist/react-web.cjs.production.min.js +1 -1
  4. package/dist/react-web.cjs.production.min.js.map +1 -1
  5. package/dist/react-web.esm.js +16 -17
  6. package/dist/react-web.esm.js.map +1 -1
  7. package/package.json +1 -1
  8. package/skinny/dist/collection-utils-3487dd27.js +238 -0
  9. package/skinny/dist/collection-utils-3487dd27.js.map +1 -0
  10. package/skinny/dist/collection-utils-47e89cbe.js +238 -0
  11. package/skinny/dist/collection-utils-47e89cbe.js.map +1 -0
  12. package/skinny/dist/collection-utils-4dae6efa.js +292 -0
  13. package/skinny/dist/collection-utils-4dae6efa.js.map +1 -0
  14. package/skinny/dist/collection-utils-57ec40f9.js +292 -0
  15. package/skinny/dist/collection-utils-57ec40f9.js.map +1 -0
  16. package/skinny/dist/collection-utils-96cde83c.js +238 -0
  17. package/skinny/dist/collection-utils-96cde83c.js.map +1 -0
  18. package/skinny/dist/collection-utils-b0b8f30e.js +291 -0
  19. package/skinny/dist/collection-utils-b0b8f30e.js.map +1 -0
  20. package/skinny/dist/plume/text-input/index.js +1 -1
  21. package/skinny/dist/plume/text-input/index.js.map +1 -1
  22. package/skinny/dist/plume-utils-5c413fd1.js +35 -0
  23. package/skinny/dist/plume-utils-5c413fd1.js.map +1 -0
  24. package/skinny/dist/props-utils-4633caf6.js +8 -0
  25. package/skinny/dist/props-utils-4633caf6.js.map +1 -0
  26. package/skinny/dist/props-utils-5c0ad25a.js +59 -0
  27. package/skinny/dist/props-utils-5c0ad25a.js.map +1 -0
  28. package/skinny/dist/props-utils-754f655a.js +39 -0
  29. package/skinny/dist/props-utils-754f655a.js.map +1 -0
  30. package/skinny/dist/props-utils-c632595f.js +59 -0
  31. package/skinny/dist/props-utils-c632595f.js.map +1 -0
  32. package/skinny/dist/props-utils-fd5f444e.js +59 -0
  33. package/skinny/dist/props-utils-fd5f444e.js.map +1 -0
  34. package/skinny/dist/react-utils-118d8539.js +190 -0
  35. package/skinny/dist/react-utils-118d8539.js.map +1 -0
  36. package/skinny/dist/react-utils-2a2fd6c9.js +339 -0
  37. package/skinny/dist/react-utils-2a2fd6c9.js.map +1 -0
  38. package/skinny/dist/react-utils-2d70bbbe.js +172 -0
  39. package/skinny/dist/react-utils-2d70bbbe.js.map +1 -0
  40. package/skinny/dist/react-utils-675565b4.js +334 -0
  41. package/skinny/dist/react-utils-675565b4.js.map +1 -0
  42. package/skinny/dist/render/PlasmicImg/index.js +13 -10
  43. package/skinny/dist/render/PlasmicImg/index.js.map +1 -1
  44. package/skinny/dist/render/PlasmicImg.d.ts +62 -0
  45. package/skinny/dist/ssr-64e38713.js +108 -0
  46. package/skinny/dist/ssr-64e38713.js.map +1 -0
  47. package/skinny/dist/ssr-902d1292.js +105 -0
  48. package/skinny/dist/ssr-902d1292.js.map +1 -0
  49. package/skinny/dist/ssr-a8081074.js +108 -0
  50. package/skinny/dist/ssr-a8081074.js.map +1 -0
  51. package/skinny/dist/ssr-d2fd94f2.js +31 -0
  52. package/skinny/dist/ssr-d2fd94f2.js.map +1 -0
  53. package/skinny/dist/tslib.es6-00014098.js +148 -0
  54. package/skinny/dist/tslib.es6-00014098.js.map +1 -0
  55. package/skinny/dist/tslib.es6-73236e8e.js +141 -0
  56. package/skinny/dist/tslib.es6-73236e8e.js.map +1 -0
@@ -0,0 +1,238 @@
1
+ import { a as __assign, d as isString } from './tslib.es6-d26ffe68.js';
2
+ import React__default from 'react';
3
+ import { Item, Section } from 'react-stately';
4
+ import { t as toChildArray, g as getElementTypeName } from './react-utils-7c01e440.js';
5
+ import { a as getPlumeType, P as PLUME_STRICT_MODE } from './props-utils-754f655a.js';
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
+ /**
64
+ * Given children of a component like Select or Menu, derive the items
65
+ * that we will pass into the Collections API. These will be
66
+ * ReactElement<ItemLikeProps|SectionLikeProps>[].
67
+ *
68
+ * Will also assign keys to items by their index in the collection,
69
+ * and collect the keys of disabled items.
70
+ */
71
+ function deriveItemsFromChildren(children, opts) {
72
+ if (!children) {
73
+ return {
74
+ items: [],
75
+ disabledKeys: [],
76
+ };
77
+ }
78
+ var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError;
79
+ // For Plume items without an explicit key, we assign a key as the index
80
+ // of the collection.
81
+ var itemCount = 0;
82
+ var sectionCount = 0;
83
+ var ensureValue = function (element) {
84
+ if (!propInChild(element, "value")) {
85
+ if (opts.requireItemValue && PLUME_STRICT_MODE) {
86
+ throw new Error("Must specify a \"value\" prop for " + getElementTypeName(element));
87
+ }
88
+ else {
89
+ return cloneChild(element, { value: "" + itemCount++ });
90
+ }
91
+ }
92
+ else {
93
+ // Still increment count even if key is present, so that the
94
+ // auto-assigned key really reflects the index
95
+ itemCount++;
96
+ return element;
97
+ }
98
+ };
99
+ var disabledKeys = [];
100
+ var flattenedChildren = function (children) {
101
+ return toChildArray(children).flatMap(function (child) {
102
+ var _a;
103
+ if (React__default.isValidElement(child)) {
104
+ if (child.type === React__default.Fragment) {
105
+ return flattenedChildren(child.props.children);
106
+ }
107
+ var type = getPlumeType(child);
108
+ if (type === itemPlumeType) {
109
+ child = ensureValue(child);
110
+ var childKey = getItemLikeKey(child);
111
+ if (getChildProp(child, "isDisabled") && !!childKey) {
112
+ disabledKeys.push(childKey);
113
+ }
114
+ return [child];
115
+ }
116
+ if (type === sectionPlumeType) {
117
+ return [
118
+ cloneChild(child, {
119
+ // key of section doesn't actually matter, just needs
120
+ // to be unique
121
+ key: (_a = child.key) !== null && _a !== void 0 ? _a : "section-" + sectionCount++,
122
+ children: flattenedChildren(getChildProp(child, "children")),
123
+ }),
124
+ ];
125
+ }
126
+ }
127
+ {
128
+ throw new Error(invalidChildError !== null && invalidChildError !== void 0 ? invalidChildError : "Unexpected child");
129
+ }
130
+ });
131
+ };
132
+ return { items: flattenedChildren(children), disabledKeys: disabledKeys };
133
+ }
134
+ function useDerivedItemsFromChildren(children, opts) {
135
+ var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError, requireItemValue = opts.requireItemValue;
136
+ return React__default.useMemo(function () {
137
+ return deriveItemsFromChildren(children, {
138
+ itemPlumeType: itemPlumeType,
139
+ sectionPlumeType: sectionPlumeType,
140
+ invalidChildError: invalidChildError,
141
+ requireItemValue: requireItemValue,
142
+ });
143
+ }, [
144
+ children,
145
+ itemPlumeType,
146
+ sectionPlumeType,
147
+ invalidChildError,
148
+ requireItemValue,
149
+ ]);
150
+ }
151
+ /**
152
+ * Given a Collection node, create the React element that we should use
153
+ * to render it.
154
+ */
155
+ function renderCollectionNode(node) {
156
+ // node.rendered should already have our item-like or section-like Plume
157
+ // component elements, so we just need to clone them with a secret
158
+ // _node prop that we use to render.
159
+ return cloneChild(node.rendered, {
160
+ _node: node,
161
+ key: node.key,
162
+ });
163
+ }
164
+ /**
165
+ * Renders a item-like or section-like Plume component element into an
166
+ * Item or a Section element.
167
+ */
168
+ function renderAsCollectionChild(child, opts) {
169
+ var _a;
170
+ var plumeType = getPlumeType(child);
171
+ if (plumeType === opts.itemPlumeType) {
172
+ var option = child;
173
+ // We look at the children passed to the item-like element, and derive key
174
+ // or textValue from it if it is a string
175
+ var content = getChildProp(option, "children");
176
+ // The children render prop needs to return an <Item/>
177
+ return (React__default.createElement(Item
178
+ // We use ItemLike.value if the user explicitly specified a value,
179
+ // and we fallback to key. If the user specified neither, then
180
+ // the Collections API will generate a unique key for this item.
181
+ , {
182
+ // We use ItemLike.value if the user explicitly specified a value,
183
+ // and we fallback to key. If the user specified neither, then
184
+ // the Collections API will generate a unique key for this item.
185
+ key: getItemLikeKey(option),
186
+ // textValue is either explicitly specified by the user, or we
187
+ // try to derive it if `content` is a string.
188
+ textValue: (_a = getChildProp(option, "textValue")) !== null && _a !== void 0 ? _a : (isString(content)
189
+ ? content
190
+ : propInChild(option, "value")
191
+ ? getChildProp(option, "value")
192
+ : option.key), "aria-label": getChildProp(option, "aria-label") }, option));
193
+ }
194
+ else {
195
+ var group = child;
196
+ return (React__default.createElement(Section
197
+ // Note that we are using the whole section-like element as the title
198
+ // here, and not group.props.title; we want the entire section-like
199
+ // Plume element to end up as Node.rendered.
200
+ , {
201
+ // Note that we are using the whole section-like element as the title
202
+ // here, and not group.props.title; we want the entire section-like
203
+ // Plume element to end up as Node.rendered.
204
+ title: group, "aria-label": getChildProp(group, "aria-label"),
205
+ // We are flattening and deriving the descendant Options as items here.
206
+ // group.props.children should've already been cleaned up by
207
+ // deriveItemsFromChildren()
208
+ items: getChildProp(group, "children") }, function (c) { return renderAsCollectionChild(c, opts); }));
209
+ }
210
+ }
211
+ function getItemLikeKey(element) {
212
+ var _a;
213
+ return (_a = getChildProp(element, "value")) !== null && _a !== void 0 ? _a : element.key;
214
+ }
215
+ // PlasmicLoader-aware function to get prop from child.
216
+ function getChildProp(child, prop) {
217
+ return "componentProps" in child.props
218
+ ? child.props.componentProps[prop]
219
+ : child.props[prop];
220
+ }
221
+ // PlasmicLoader-aware function to check `if (prop in element.props)`.
222
+ function propInChild(child, prop) {
223
+ return "componentProps" in child.props
224
+ ? prop in child.props.componentProps
225
+ : prop in child.props;
226
+ }
227
+ // PlasmicLoader-aware function to clone React element.
228
+ function cloneChild(child, props) {
229
+ if (child.type.getPlumeType) {
230
+ // If React element has getPlumeType(), assume that it is PlasmicLoader,
231
+ // so add nodeProps to componentProps instead of element props.
232
+ return React__default.cloneElement(child, __assign({ componentProps: __assign(__assign({}, child.props.componentProps), props) }, (props.key ? { key: props.key } : {})));
233
+ }
234
+ return React__default.cloneElement(child, props);
235
+ }
236
+
237
+ export { renderAsCollectionChild as a, getChildProp as g, renderCollectionNode as r, useDerivedItemsFromChildren as u };
238
+ //# sourceMappingURL=collection-utils-96cde83c.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection-utils-96cde83c.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,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E;;;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;;;;"}
@@ -0,0 +1,291 @@
1
+ import { a as __assign, d as isString } from "./tslib.es6-00014098.js";
2
+ import React__default from "react";
3
+ import { Item, Section } from "react-stately";
4
+ import {
5
+ t as toChildArray,
6
+ g as getElementTypeName,
7
+ } from "./react-utils-118d8539.js";
8
+ import {
9
+ a as getPlumeType,
10
+ P as PLUME_STRICT_MODE,
11
+ } from "./props-utils-c632595f.js";
12
+
13
+ /**
14
+ * In general, we try not to expose react-aria's Collections API to Plume users.
15
+ * The Collections API is how react-aria users pass data about collections of
16
+ * things using the built-in Item and Section components, which are abstract,
17
+ * metadata-only components that don't render anything but only serve to specify
18
+ * data. For example, here's how you would use react-spectrum's Picker:
19
+ *
20
+ * <Picker>
21
+ * <Section title="Asia">
22
+ * <Item key="taiwan">Taiwan</Item>
23
+ * <Item key="japan">Japan</Item>
24
+ * <Item key="china">China</Item>
25
+ * </Section>
26
+ * <Section title="Europe">
27
+ * <Item key="germany">Germany</Item>
28
+ * <Item key="france">France</Item>
29
+ * </Section>
30
+ * </Picker>
31
+ *
32
+ * You would re-use this same Item/Section components to pass similar things to
33
+ * Menu, Tabs, etc.
34
+ *
35
+ * For Plasmic, this API is too abstract. The user has explicitly designed components
36
+ * like Select.Option and Select.OptionGroup, and it is weird that they don't actually
37
+ * use these components. It is more natural to do:
38
+ *
39
+ * <Select>
40
+ * <Select.OptionGroup title="Asia">
41
+ * <Select.Option key="taiwan">Taiwan</Select>
42
+ * </Select.OptionGroup>
43
+ * </Select>
44
+ *
45
+ * For Plume, we let users directly use the components they designed, both to collect
46
+ * information and to perform actual rendering. For example, for Plume,
47
+ * you'd use Select.Option instead of Item, and Select.OptionGroup instead of Section.
48
+ * This means that the Select.Option props will collect the same information Item
49
+ * does.
50
+ *
51
+ * A component like Select.Option then serves two purposes:
52
+ *
53
+ * 1. Allow users to specify the collection of data, like in the above example
54
+ * Here, we're mainly interested in the props in those ReactElements so
55
+ * we can pass the Item/Section data onto react-aria's APIs. We are not
56
+ * actually rendering these elements.
57
+ * 2. Once react-aria's Collections API has gone through them and built
58
+ * Collection "nodes", we then create cloned versions of these elements
59
+ * with the corresponding node passed in as a secret prop. These ReactElements
60
+ * are then actually used to _render_ the corresponding Option / OptionGroup.
61
+ *
62
+ * This file contains helper functions to help with implementing the above.
63
+ *
64
+ * Note also that most of the collections-based react-aria components expose
65
+ * a parallel API that accepts a list of "items" and a render prop, instead
66
+ * of list of Item/Section elements. This is for efficiency, but we are opting
67
+ * to only support the composite-component pattern for now for simplicity.
68
+ */
69
+ /**
70
+ * Given children of a component like Select or Menu, derive the items
71
+ * that we will pass into the Collections API. These will be
72
+ * ReactElement<ItemLikeProps|SectionLikeProps>[].
73
+ *
74
+ * Will also assign keys to items by their index in the collection,
75
+ * and collect the keys of disabled items.
76
+ */
77
+ function deriveItemsFromChildren(children, opts) {
78
+ if (!children) {
79
+ return {
80
+ items: [],
81
+ disabledKeys: [],
82
+ };
83
+ }
84
+ var itemPlumeType = opts.itemPlumeType,
85
+ sectionPlumeType = opts.sectionPlumeType,
86
+ invalidChildError = opts.invalidChildError;
87
+ // For Plume items without an explicit key, we assign a key as the index
88
+ // of the collection.
89
+ var itemCount = 0;
90
+ var sectionCount = 0;
91
+ var ensureValue = function (element) {
92
+ if (!propInChild(element, "value")) {
93
+ if (opts.requireItemValue && PLUME_STRICT_MODE) {
94
+ throw new Error(
95
+ 'Must specify a "value" prop for ' + getElementTypeName(element)
96
+ );
97
+ } else {
98
+ return cloneChild(element, { value: "" + itemCount++ });
99
+ }
100
+ } else {
101
+ // Still increment count even if key is present, so that the
102
+ // auto-assigned key really reflects the index
103
+ itemCount++;
104
+ return element;
105
+ }
106
+ };
107
+ var disabledKeys = [];
108
+ var flattenedChildren = function (children) {
109
+ return toChildArray(children).flatMap(function (child) {
110
+ var _a;
111
+ if (React__default.isValidElement(child)) {
112
+ if (child.type === React__default.Fragment) {
113
+ return flattenedChildren(child.props.children);
114
+ }
115
+ var type = getPlumeType(child);
116
+ if (type === itemPlumeType) {
117
+ child = ensureValue(child);
118
+ var childKey = getItemLikeKey(child);
119
+ if (getChildProp(child, "isDisabled") && !!childKey) {
120
+ disabledKeys.push(childKey);
121
+ }
122
+ return [child];
123
+ }
124
+ if (type === sectionPlumeType) {
125
+ return [
126
+ cloneChild(child, {
127
+ // key of section doesn't actually matter, just needs
128
+ // to be unique
129
+ key:
130
+ (_a = child.key) !== null && _a !== void 0
131
+ ? _a
132
+ : "section-" + sectionCount++,
133
+ children: flattenedChildren(getChildProp(child, "children")),
134
+ }),
135
+ ];
136
+ }
137
+ }
138
+ {
139
+ throw new Error(
140
+ invalidChildError !== null && invalidChildError !== void 0
141
+ ? invalidChildError
142
+ : "Unexpected child"
143
+ );
144
+ }
145
+ });
146
+ };
147
+ return { items: flattenedChildren(children), disabledKeys: disabledKeys };
148
+ }
149
+ function useDerivedItemsFromChildren(children, opts) {
150
+ var itemPlumeType = opts.itemPlumeType,
151
+ sectionPlumeType = opts.sectionPlumeType,
152
+ invalidChildError = opts.invalidChildError,
153
+ requireItemValue = opts.requireItemValue;
154
+ return React__default.useMemo(
155
+ function () {
156
+ return deriveItemsFromChildren(children, {
157
+ itemPlumeType: itemPlumeType,
158
+ sectionPlumeType: sectionPlumeType,
159
+ invalidChildError: invalidChildError,
160
+ requireItemValue: requireItemValue,
161
+ });
162
+ },
163
+ [
164
+ children,
165
+ itemPlumeType,
166
+ sectionPlumeType,
167
+ invalidChildError,
168
+ requireItemValue,
169
+ ]
170
+ );
171
+ }
172
+ /**
173
+ * Given a Collection node, create the React element that we should use
174
+ * to render it.
175
+ */
176
+ function renderCollectionNode(node) {
177
+ // node.rendered should already have our item-like or section-like Plume
178
+ // component elements, so we just need to clone them with a secret
179
+ // _node prop that we use to render.
180
+ return cloneChild(node.rendered, {
181
+ _node: node,
182
+ key: node.key,
183
+ });
184
+ }
185
+ /**
186
+ * Renders a item-like or section-like Plume component element into an
187
+ * Item or a Section element.
188
+ */
189
+ function renderAsCollectionChild(child, opts) {
190
+ var _a;
191
+ var plumeType = getPlumeType(child);
192
+ if (plumeType === opts.itemPlumeType) {
193
+ var option = child;
194
+ // We look at the children passed to the item-like element, and derive key
195
+ // or textValue from it if it is a string
196
+ var content = getChildProp(option, "children");
197
+ // The children render prop needs to return an <Item/>
198
+ return React__default.createElement(
199
+ Item,
200
+ // We use ItemLike.value if the user explicitly specified a value,
201
+ // and we fallback to key. If the user specified neither, then
202
+ // the Collections API will generate a unique key for this item.
203
+ {
204
+ // We use ItemLike.value if the user explicitly specified a value,
205
+ // and we fallback to key. If the user specified neither, then
206
+ // the Collections API will generate a unique key for this item.
207
+ key: getItemLikeKey(option),
208
+ // textValue is either explicitly specified by the user, or we
209
+ // try to derive it if `content` is a string.
210
+ textValue:
211
+ (_a = getChildProp(option, "textValue")) !== null && _a !== void 0
212
+ ? _a
213
+ : isString(content)
214
+ ? content
215
+ : propInChild(option, "value")
216
+ ? getChildProp(option, "value")
217
+ : option.key,
218
+ "aria-label": getChildProp(option, "aria-label"),
219
+ },
220
+ option
221
+ );
222
+ } else {
223
+ var group = child;
224
+ return React__default.createElement(
225
+ Section,
226
+ // Note that we are using the whole section-like element as the title
227
+ // here, and not group.props.title; we want the entire section-like
228
+ // Plume element to end up as Node.rendered.
229
+ {
230
+ // Note that we are using the whole section-like element as the title
231
+ // here, and not group.props.title; we want the entire section-like
232
+ // Plume element to end up as Node.rendered.
233
+ title: group,
234
+ "aria-label": getChildProp(group, "aria-label"),
235
+ // We are flattening and deriving the descendant Options as items here.
236
+ // group.props.children should've already been cleaned up by
237
+ // deriveItemsFromChildren()
238
+ items: getChildProp(group, "children"),
239
+ },
240
+ function (c) {
241
+ return renderAsCollectionChild(c, opts);
242
+ }
243
+ );
244
+ }
245
+ }
246
+ function getItemLikeKey(element) {
247
+ var _a;
248
+ return (_a = getChildProp(element, "value")) !== null && _a !== void 0
249
+ ? _a
250
+ : element.key;
251
+ }
252
+ // PlasmicLoader-aware function to get prop from child.
253
+ function getChildProp(child, prop) {
254
+ return "componentProps" in child.props
255
+ ? child.props.componentProps[prop]
256
+ : child.props[prop];
257
+ }
258
+ // PlasmicLoader-aware function to check `if (prop in element.props)`.
259
+ function propInChild(child, prop) {
260
+ return "componentProps" in child.props
261
+ ? prop in child.props.componentProps
262
+ : prop in child.props;
263
+ }
264
+ // PlasmicLoader-aware function to clone React element.
265
+ function cloneChild(child, props) {
266
+ if (child.type.getPlumeType) {
267
+ // If React element has getPlumeType(), assume that it is PlasmicLoader,
268
+ // so add nodeProps to componentProps instead of element props.
269
+ return React__default.cloneElement(
270
+ child,
271
+ __assign(
272
+ {
273
+ componentProps: __assign(
274
+ __assign({}, child.props.componentProps),
275
+ props
276
+ ),
277
+ },
278
+ props.key ? { key: props.key } : {}
279
+ )
280
+ );
281
+ }
282
+ return React__default.cloneElement(child, props);
283
+ }
284
+
285
+ export {
286
+ renderAsCollectionChild as a,
287
+ getChildProp as g,
288
+ renderCollectionNode as r,
289
+ useDerivedItemsFromChildren as u,
290
+ };
291
+ //# sourceMappingURL=collection-utils-b0b8f30e.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection-utils-b0b8f30e.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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
  },
36
36
  },
37
37
  _c[config.input] = {
38
- props: __assign(__assign({}, omit.apply(void 0, __spreadArray(__spreadArray([rest], plasmicClass.internalArgProps), plasmicClass.internalVariantProps))), { disabled: isDisabled, ref: inputRef, className: inputClassName, style: inputStyle }),
38
+ props: __assign(__assign({}, omit.apply(void 0, __spreadArray(__spreadArray([rest], plasmicClass.internalArgProps.filter(function (prop) { return prop !== "required"; })), plasmicClass.internalVariantProps))), { disabled: isDisabled, ref: inputRef, className: inputClassName, style: inputStyle }),
39
39
  },
40
40
  _c);
41
41
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/plume/text-input/index.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { omit, pick } from \"../../common\";\nimport { Overrides } from \"../../render/elements\";\nimport {\n AnyPlasmicClass,\n mergeVariantToggles,\n PlasmicClassArgs,\n PlasmicClassOverrides,\n PlasmicClassVariants,\n VariantDef,\n} from \"../plume-utils\";\n\nexport interface BaseTextInputProps\n extends Omit<React.ComponentProps<\"input\">, \"type\" | \"disabled\"> {\n showStartIcon?: boolean;\n showEndIcon?: boolean;\n startIcon?: React.ReactNode;\n endIcon?: React.ReactNode;\n isDisabled?: boolean;\n type?: \"text\" | \"password\" | \"email\" | \"url\" | string;\n inputClassName?: string;\n inputStyle?: React.CSSProperties;\n}\n\nexport interface TextInputRefValue {\n focus: () => void;\n blur: () => void;\n getRoot: () => HTMLElement | null;\n getInput: () => HTMLInputElement | null;\n}\n\nexport type TextInputRef = React.Ref<TextInputRefValue>;\n\ninterface TextInputConfig<C extends AnyPlasmicClass> {\n showStartIconVariant: VariantDef<PlasmicClassVariants<C>>;\n showEndIconVariant?: VariantDef<PlasmicClassVariants<C>>;\n isDisabledVariant?: VariantDef<PlasmicClassVariants<C>>;\n startIconSlot?: keyof PlasmicClassArgs<C>;\n endIconSlot?: keyof PlasmicClassArgs<C>;\n root: keyof PlasmicClassOverrides<C>;\n input: keyof PlasmicClassOverrides<C>;\n}\n\nexport function useTextInput<\n P extends BaseTextInputProps,\n C extends AnyPlasmicClass\n>(\n plasmicClass: C,\n props: P,\n config: TextInputConfig<C>,\n ref: TextInputRef = null\n) {\n const {\n isDisabled,\n startIcon,\n endIcon,\n showStartIcon,\n showEndIcon,\n className,\n style,\n inputClassName,\n inputStyle,\n ...rest\n } = props;\n const rootRef = React.useRef<HTMLElement>(null);\n const inputRef = React.useRef<HTMLInputElement>(null);\n\n React.useImperativeHandle(\n ref,\n () => ({\n focus() {\n inputRef.current?.focus();\n },\n blur() {\n inputRef.current?.blur();\n },\n getRoot() {\n return rootRef.current;\n },\n getInput() {\n return inputRef.current;\n },\n }),\n [rootRef, inputRef]\n );\n\n const variants = {\n ...pick(props, ...plasmicClass.internalVariantProps),\n ...mergeVariantToggles(\n { def: config.showStartIconVariant, active: showStartIcon },\n { def: config.showEndIconVariant, active: showEndIcon },\n { def: config.isDisabledVariant, active: isDisabled }\n ),\n };\n\n const args = {\n ...pick(props, ...plasmicClass.internalArgProps),\n ...(config.startIconSlot && { [config.startIconSlot]: startIcon }),\n ...(config.endIconSlot && { [config.endIconSlot]: endIcon }),\n };\n\n const overrides: Overrides = {\n [config.root]: {\n props: {\n ref: rootRef,\n className,\n style,\n },\n },\n [config.input]: {\n props: {\n ...omit(\n rest as any,\n ...plasmicClass.internalArgProps,\n ...plasmicClass.internalVariantProps\n ),\n disabled: isDisabled,\n ref: inputRef,\n className: inputClassName,\n style: inputStyle,\n },\n },\n };\n\n return {\n plasmicProps: {\n variants: variants as PlasmicClassVariants<C>,\n args: args as PlasmicClassArgs<C>,\n overrides: overrides as PlasmicClassOverrides<C>,\n },\n };\n}\n"],"names":[],"mappings":";;;;SA2CgB,YAAY,CAI1B,YAAe,EACf,KAAQ,EACR,MAA0B,EAC1B,GAAwB;;IAAxB,oBAAA,EAAA,UAAwB;IAGtB,IAAA,UAAU,GAUR,KAAK,WAVG,EACV,SAAS,GASP,KAAK,UATE,EACT,OAAO,GAQL,KAAK,QARA,EACP,aA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,WAAW,IAAG,OAAO,KAAE,EAC5D,CAAC;IAEF,IAAM,SAAS;QACb,GAAC,MAAM,CAAC,IAAI,IAAG;YACb,KAAK,EAAE;gBACL,GAAG,EAAE,OAAO;gBACZ,SAAS,WAAA;gBACT,KAAK,OAAA;aACN;SACF;QACD,GAAC,MAAM,CAAC,KAAK,IAAG;YACd,KAAK,wBACA,IAAI,4CACL,IAAW,GACR,YAAY,CAAC,gBAAgB,GAC7B,YAAY,CAAC,oBAAoB,OAEtC,QAAQ,EAAE,UAAU,EACpB,GAAG,EAAE,QAAQ,EACb,SAAS,EAAE,cAAc,EACzB,KAAK,EAAE,UAAU,GAClB;SACF;WACF,CAAC;IAEF,OAAO;QACL,YAAY,EAAE;YACZ,QAAQ,EAAE,QAAmC;YAC7C,IAAI,EAAE,IAA2B;YACjC,SAAS,EAAE,SAAqC;SACjD;KACF,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/plume/text-input/index.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { omit, pick } from \"../../common\";\nimport { Overrides } from \"../../render/elements\";\nimport {\n AnyPlasmicClass,\n mergeVariantToggles,\n PlasmicClassArgs,\n PlasmicClassOverrides,\n PlasmicClassVariants,\n VariantDef,\n} from \"../plume-utils\";\n\nexport interface BaseTextInputProps\n extends Omit<React.ComponentProps<\"input\">, \"type\" | \"disabled\"> {\n showStartIcon?: boolean;\n showEndIcon?: boolean;\n startIcon?: React.ReactNode;\n endIcon?: React.ReactNode;\n isDisabled?: boolean;\n type?: \"text\" | \"password\" | \"email\" | \"url\" | string;\n inputClassName?: string;\n inputStyle?: React.CSSProperties;\n}\n\nexport interface TextInputRefValue {\n focus: () => void;\n blur: () => void;\n getRoot: () => HTMLElement | null;\n getInput: () => HTMLInputElement | null;\n}\n\nexport type TextInputRef = React.Ref<TextInputRefValue>;\n\ninterface TextInputConfig<C extends AnyPlasmicClass> {\n showStartIconVariant: VariantDef<PlasmicClassVariants<C>>;\n showEndIconVariant?: VariantDef<PlasmicClassVariants<C>>;\n isDisabledVariant?: VariantDef<PlasmicClassVariants<C>>;\n startIconSlot?: keyof PlasmicClassArgs<C>;\n endIconSlot?: keyof PlasmicClassArgs<C>;\n root: keyof PlasmicClassOverrides<C>;\n input: keyof PlasmicClassOverrides<C>;\n}\n\nexport function useTextInput<\n P extends BaseTextInputProps,\n C extends AnyPlasmicClass\n>(\n plasmicClass: C,\n props: P,\n config: TextInputConfig<C>,\n ref: TextInputRef = null\n) {\n const {\n isDisabled,\n startIcon,\n endIcon,\n showStartIcon,\n showEndIcon,\n className,\n style,\n inputClassName,\n inputStyle,\n ...rest\n } = props;\n const rootRef = React.useRef<HTMLElement>(null);\n const inputRef = React.useRef<HTMLInputElement>(null);\n\n React.useImperativeHandle(\n ref,\n () => ({\n focus() {\n inputRef.current?.focus();\n },\n blur() {\n inputRef.current?.blur();\n },\n getRoot() {\n return rootRef.current;\n },\n getInput() {\n return inputRef.current;\n },\n }),\n [rootRef, inputRef]\n );\n\n const variants = {\n ...pick(props, ...plasmicClass.internalVariantProps),\n ...mergeVariantToggles(\n { def: config.showStartIconVariant, active: showStartIcon },\n { def: config.showEndIconVariant, active: showEndIcon },\n { def: config.isDisabledVariant, active: isDisabled }\n ),\n };\n\n const args = {\n ...pick(props, ...plasmicClass.internalArgProps),\n ...(config.startIconSlot && { [config.startIconSlot]: startIcon }),\n ...(config.endIconSlot && { [config.endIconSlot]: endIcon }),\n };\n\n const overrides: Overrides = {\n [config.root]: {\n props: {\n ref: rootRef,\n className,\n style,\n },\n },\n [config.input]: {\n props: {\n ...omit(\n rest as any,\n // We need to remove `required` from the list of internalArgProps to\n // be omitted in the props being passed through because Plume pkg\n // <= 19.1.1 had a bug: input[required] was not linked to the\n // `required` arg as it should.\n ...plasmicClass.internalArgProps.filter(\n (prop) => prop !== \"required\"\n ),\n ...plasmicClass.internalVariantProps\n ),\n disabled: isDisabled,\n ref: inputRef,\n className: inputClassName,\n style: inputStyle,\n },\n },\n };\n\n return {\n plasmicProps: {\n variants: variants as PlasmicClassVariants<C>,\n args: args as PlasmicClassArgs<C>,\n overrides: overrides as PlasmicClassOverrides<C>,\n },\n };\n}\n"],"names":[],"mappings":";;;;SA2CgB,YAAY,CAI1B,YAAe,EACf,KAAQ,EACR,MAA0B,EAC1B,GAAwB;;IAAxB,oBAAA,EAAA,UAAwB;IAGtB,IAAA,UAAU,GAUR,KAAK,WAVG,EACV,SAAS,GASP,KAAK,UATE,EACT,OAAO,GAQL,KAAK,QARA,EACP,aAAa,GAOX,KAAK,cAPM,EACb,WAAW,GAMT,KAAK,YANI,EACX,SAAS,GAKP,KAAK,UALE,EACT,KAAK,GAIH,KAAK,MAJF,EACL,cAAc,GAGZ,KAAK,eAHO,EACd,UAAU,GAER,KAAK,WAFG,EACP,IAAI,UACL,KAAK,EAXH,4HAWL,CADQ,CACC;IACV,IAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAc,IAAI,CAAC,CAAC;IAChD,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAmB,IAAI,CAAC,CAAC;IAEtD,KAAK,CAAC,mBAAmB,CACvB,GAAG,EACH,cAAM,QAAC;QACL,KAAK;;YACH,MAAA,QAAQ,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAC;SAC3B;QACD,IAAI;;YACF,MAAA,QAAQ,CAAC,OAAO,0CAAE,IAAI,EAAE,CAAC;SAC1B;QACD,OAAO;YACL,OAAO,OAAO,CAAC,OAAO,CAAC;SACxB;QACD,QAAQ;YACN,OAAO,QAAQ,CAAC,OAAO,CAAC;SACzB;KACF,IAAC,EACF,CAAC,OAAO,EAAE,QAAQ,CAAC,CACpB,CAAC;IAEF,IAAM,QAAQ,yBACT,IAAI,8BAAC,KAAK,GAAK,YAAY,CAAC,oBAAoB,KAChD,mBAAmB,CACpB,EAAE,GAAG,EAAE,MAAM,CAAC,oBAAoB,EAAE,MAAM,EAAE,aAAa,EAAE,EAC3D,EAAE,GAAG,EAAE,MAAM,CA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