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