@plasmicapp/react-web 0.2.201 → 0.2.203

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/dist/all.d.ts +1926 -1925
  2. package/dist/auth/PlasmicPageGuard.d.ts +11 -11
  3. package/dist/common.d.ts +10 -10
  4. package/dist/data-sources/index.d.ts +1 -1
  5. package/dist/host/index.d.ts +1 -1
  6. package/dist/index-common.d.ts +18 -18
  7. package/dist/index-skinny.d.ts +1 -1
  8. package/dist/index.cjs.js +3495 -3495
  9. package/dist/index.cjs.js.map +1 -1
  10. package/dist/index.d.ts +11 -11
  11. package/dist/plume/button/index.d.ts +36 -36
  12. package/dist/plume/checkbox/index.d.ts +47 -47
  13. package/dist/plume/collection-utils.d.ts +191 -191
  14. package/dist/plume/collection-utils.spec.d.ts +1 -1
  15. package/dist/plume/menu/context.d.ts +8 -8
  16. package/dist/plume/menu/index.d.ts +3 -3
  17. package/dist/plume/menu/menu-group.d.ts +23 -23
  18. package/dist/plume/menu/menu-item.d.ts +23 -23
  19. package/dist/plume/menu/menu.d.ts +39 -39
  20. package/dist/plume/menu-button/DropdownMenu.d.ts +34 -34
  21. package/dist/plume/menu-button/index.d.ts +2 -2
  22. package/dist/plume/menu-button/menu-button.d.ts +72 -72
  23. package/dist/plume/menu-button/menu-trigger.d.ts +21 -21
  24. package/dist/plume/plume-utils.d.ts +41 -41
  25. package/dist/plume/props-utils.d.ts +15 -15
  26. package/dist/plume/select/context.d.ts +3 -3
  27. package/dist/plume/select/index.d.ts +4 -4
  28. package/dist/plume/select/select-option-group.d.ts +23 -23
  29. package/dist/plume/select/select-option.d.ts +23 -23
  30. package/dist/plume/select/select.d.ts +111 -111
  31. package/dist/plume/switch/index.d.ts +39 -39
  32. package/dist/plume/text-input/index.d.ts +36 -36
  33. package/dist/plume/triggered-overlay/context.d.ts +14 -14
  34. package/dist/plume/triggered-overlay/index.d.ts +2 -2
  35. package/dist/plume/triggered-overlay/triggered-overlay.d.ts +24 -24
  36. package/dist/query/index.d.ts +1 -1
  37. package/dist/react-utils.d.ts +21 -21
  38. package/dist/react-utils.spec.d.ts +1 -1
  39. package/dist/react-web.esm.js +3496 -3496
  40. package/dist/react-web.esm.js.map +1 -1
  41. package/dist/render/PlasmicHead/index.d.ts +37 -37
  42. package/dist/render/PlasmicIcon.d.ts +4 -4
  43. package/dist/render/PlasmicImg/index.d.ts +81 -81
  44. package/dist/render/PlasmicLink.d.ts +2 -2
  45. package/dist/render/PlasmicSlot.d.ts +11 -11
  46. package/dist/render/Stack.d.ts +51 -51
  47. package/dist/render/elements.d.ts +74 -74
  48. package/dist/render/global-variants.d.ts +1 -1
  49. package/dist/render/screen-variants.d.ts +5 -5
  50. package/dist/render/ssr.d.ts +21 -21
  51. package/dist/render/translation.d.ts +19 -19
  52. package/dist/render/triggers.d.ts +39 -39
  53. package/dist/states/errors.d.ts +13 -13
  54. package/dist/states/graph.d.ts +25 -25
  55. package/dist/states/helpers.d.ts +43 -43
  56. package/dist/states/index.d.ts +4 -4
  57. package/dist/states/types.d.ts +66 -66
  58. package/dist/states/valtio.d.ts +10 -10
  59. package/dist/states/vanilla.d.ts +3 -3
  60. package/dist/stories/PlasmicImg.stories.d.ts +6 -6
  61. package/dist/stories/UseDollarState.stories.d.ts +78 -78
  62. package/lib/data-sources/index.d.ts +1 -1
  63. package/lib/host/index.d.ts +1 -1
  64. package/lib/query/index.d.ts +1 -1
  65. package/package.json +8 -9
  66. package/skinny/dist/auth/PlasmicPageGuard.d.ts +11 -11
  67. package/skinny/dist/{collection-utils-0967eaf0.js → collection-utils-2f28e4eb.js} +297 -297
  68. package/skinny/dist/{collection-utils-0967eaf0.js.map → collection-utils-2f28e4eb.js.map} +1 -1
  69. package/skinny/dist/{common-9d6d348d.js → common-ed411407.js} +130 -130
  70. package/skinny/dist/{common-9d6d348d.js.map → common-ed411407.js.map} +1 -1
  71. package/skinny/dist/common.d.ts +10 -10
  72. package/skinny/dist/data-sources/index.d.ts +1 -1
  73. package/skinny/dist/host/index.d.ts +1 -1
  74. package/skinny/dist/index-common.d.ts +18 -18
  75. package/skinny/dist/index-skinny.d.ts +1 -1
  76. package/skinny/dist/index.d.ts +11 -11
  77. package/skinny/dist/index.js +1559 -1559
  78. package/skinny/dist/index.js.map +1 -1
  79. package/skinny/dist/plume/button/index.d.ts +36 -36
  80. package/skinny/dist/plume/button/index.js +21 -21
  81. package/skinny/dist/plume/checkbox/index.d.ts +47 -47
  82. package/skinny/dist/plume/checkbox/index.js +64 -64
  83. package/skinny/dist/plume/collection-utils.d.ts +191 -191
  84. package/skinny/dist/plume/collection-utils.spec.d.ts +1 -1
  85. package/skinny/dist/plume/menu/context.d.ts +8 -8
  86. package/skinny/dist/plume/menu/index.d.ts +3 -3
  87. package/skinny/dist/plume/menu/index.js +165 -165
  88. package/skinny/dist/plume/menu/menu-group.d.ts +23 -23
  89. package/skinny/dist/plume/menu/menu-item.d.ts +23 -23
  90. package/skinny/dist/plume/menu/menu.d.ts +39 -39
  91. package/skinny/dist/plume/menu-button/DropdownMenu.d.ts +34 -34
  92. package/skinny/dist/plume/menu-button/index.d.ts +2 -2
  93. package/skinny/dist/plume/menu-button/index.js +125 -125
  94. package/skinny/dist/plume/menu-button/index.js.map +1 -1
  95. package/skinny/dist/plume/menu-button/menu-button.d.ts +72 -72
  96. package/skinny/dist/plume/menu-button/menu-trigger.d.ts +21 -21
  97. package/skinny/dist/plume/plume-utils.d.ts +41 -41
  98. package/skinny/dist/plume/props-utils.d.ts +15 -15
  99. package/skinny/dist/plume/select/context.d.ts +3 -3
  100. package/skinny/dist/plume/select/index.d.ts +4 -4
  101. package/skinny/dist/plume/select/index.js +250 -250
  102. package/skinny/dist/plume/select/index.js.map +1 -1
  103. package/skinny/dist/plume/select/select-option-group.d.ts +23 -23
  104. package/skinny/dist/plume/select/select-option.d.ts +23 -23
  105. package/skinny/dist/plume/select/select.d.ts +111 -111
  106. package/skinny/dist/plume/switch/index.d.ts +39 -39
  107. package/skinny/dist/plume/switch/index.js +61 -61
  108. package/skinny/dist/plume/text-input/index.d.ts +36 -36
  109. package/skinny/dist/plume/text-input/index.js +45 -45
  110. package/skinny/dist/plume/triggered-overlay/context.d.ts +14 -14
  111. package/skinny/dist/plume/triggered-overlay/index.d.ts +2 -2
  112. package/skinny/dist/plume/triggered-overlay/index.js +100 -100
  113. package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
  114. package/skinny/dist/plume/triggered-overlay/triggered-overlay.d.ts +24 -24
  115. package/skinny/dist/{plume-utils-7d68bcc0.js → plume-utils-e699cd08.js} +30 -30
  116. package/skinny/dist/{plume-utils-7d68bcc0.js.map → plume-utils-e699cd08.js.map} +1 -1
  117. package/skinny/dist/{props-utils-9f9c761a.js → props-utils-9d74371f.js} +4 -4
  118. package/skinny/dist/{props-utils-9f9c761a.js.map → props-utils-9d74371f.js.map} +1 -1
  119. package/skinny/dist/query/index.d.ts +1 -1
  120. package/skinny/dist/{react-utils-ee4e03ba.js → react-utils-5ff031c2.js} +195 -195
  121. package/skinny/dist/{react-utils-ee4e03ba.js.map → react-utils-5ff031c2.js.map} +1 -1
  122. package/skinny/dist/react-utils.d.ts +21 -21
  123. package/skinny/dist/react-utils.spec.d.ts +1 -1
  124. package/skinny/dist/render/PlasmicHead/index.d.ts +37 -37
  125. package/skinny/dist/render/PlasmicHead/index.js +54 -54
  126. package/skinny/dist/render/PlasmicIcon.d.ts +4 -4
  127. package/skinny/dist/render/PlasmicImg/index.d.ts +81 -81
  128. package/skinny/dist/render/PlasmicImg/index.js +297 -297
  129. package/skinny/dist/render/PlasmicLink.d.ts +2 -2
  130. package/skinny/dist/render/PlasmicSlot.d.ts +11 -11
  131. package/skinny/dist/render/Stack.d.ts +51 -51
  132. package/skinny/dist/render/elements.d.ts +74 -74
  133. package/skinny/dist/render/global-variants.d.ts +1 -1
  134. package/skinny/dist/render/screen-variants.d.ts +5 -5
  135. package/skinny/dist/render/ssr.d.ts +21 -21
  136. package/skinny/dist/render/translation.d.ts +19 -19
  137. package/skinny/dist/render/triggers.d.ts +39 -39
  138. package/skinny/dist/{ssr-c9834f50.js → ssr-8625df04.js} +107 -107
  139. package/skinny/dist/{ssr-c9834f50.js.map → ssr-8625df04.js.map} +1 -1
  140. package/skinny/dist/states/errors.d.ts +13 -13
  141. package/skinny/dist/states/graph.d.ts +25 -25
  142. package/skinny/dist/states/helpers.d.ts +43 -43
  143. package/skinny/dist/states/index.d.ts +4 -4
  144. package/skinny/dist/states/types.d.ts +66 -66
  145. package/skinny/dist/states/valtio.d.ts +10 -10
  146. package/skinny/dist/states/vanilla.d.ts +3 -3
  147. package/skinny/dist/stories/PlasmicImg.stories.d.ts +6 -6
  148. package/skinny/dist/stories/UseDollarState.stories.d.ts +78 -78
@@ -1,15 +1,15 @@
1
- import * as React from "react";
2
- import { AnyPlasmicClass, PlasmicClassArgs, PlasmicClassOverrides, PlasmicClassVariants } from "./plume-utils";
3
- export interface StyleProps {
4
- className?: string;
5
- style?: React.CSSProperties;
6
- }
7
- export declare function getStyleProps<P extends StyleProps>(props: P): StyleProps;
8
- export declare function getDefaultPlasmicProps<C extends AnyPlasmicClass>(plasmicClass: C, props: Record<string, any>): {
9
- plasmicProps: {
10
- variants: PlasmicClassVariants<C>;
11
- args: PlasmicClassArgs<C>;
12
- overrides: PlasmicClassOverrides<C>;
13
- };
14
- };
15
- export declare function getDataProps(props: Record<string, any>): Partial<Record<string, any>>;
1
+ import * as React from "react";
2
+ import { AnyPlasmicClass, PlasmicClassArgs, PlasmicClassOverrides, PlasmicClassVariants } from "./plume-utils";
3
+ export interface StyleProps {
4
+ className?: string;
5
+ style?: React.CSSProperties;
6
+ }
7
+ export declare function getStyleProps<P extends StyleProps>(props: P): StyleProps;
8
+ export declare function getDefaultPlasmicProps<C extends AnyPlasmicClass>(plasmicClass: C, props: Record<string, any>): {
9
+ plasmicProps: {
10
+ variants: PlasmicClassVariants<C>;
11
+ args: PlasmicClassArgs<C>;
12
+ overrides: PlasmicClassOverrides<C>;
13
+ };
14
+ };
15
+ export declare function getDataProps(props: Record<string, any>): Partial<Record<string, any>>;
@@ -1,3 +1,3 @@
1
- import * as React from "react";
2
- import type { ListState } from "@react-stately/list";
3
- export declare const SelectContext: React.Context<ListState<any> | undefined>;
1
+ import * as React from "react";
2
+ import type { ListState } from "@react-stately/list";
3
+ export declare const SelectContext: React.Context<ListState<any> | undefined>;
@@ -1,4 +1,4 @@
1
- export { BaseSelectProps, SelectRef, SelectRefValue, useSelect, } from "./select";
2
- export { BaseSelectOptionProps, SelectOptionRef, useSelectOption, } from "./select-option";
3
- export { BaseSelectOptionGroupProps, useSelectOptionGroup, } from "./select-option-group";
4
- export { SelectContext } from "./context";
1
+ export { BaseSelectProps, SelectRef, SelectRefValue, useSelect, } from "./select";
2
+ export { BaseSelectOptionProps, SelectOptionRef, useSelectOption, } from "./select-option";
3
+ export { BaseSelectOptionGroupProps, useSelectOptionGroup, } from "./select-option-group";
4
+ export { SelectContext } from "./context";
@@ -1,15 +1,15 @@
1
- import { b as __assign, p as pick, d as __spreadArray, e as __read, c as __rest } from '../../common-9d6d348d.js';
1
+ import { b as __assign, p as pick, d as __spreadArray, e as __read, c as __rest } from '../../common-ed411407.js';
2
2
  import { usePlasmicCanvasContext } from '@plasmicapp/host';
3
3
  import { usePress } from '@react-aria/interactions';
4
4
  import { useListBox, useOption, useListBoxSection } from '@react-aria/listbox';
5
5
  import { useSelect as useSelect$1, HiddenSelect } from '@react-aria/select';
6
6
  import { useSelectState } from '@react-stately/select';
7
7
  import * as React from 'react';
8
- import { m as mergeProps, d as mergeRefs } from '../../react-utils-ee4e03ba.js';
9
- import { a as useEnsureSSRProvider } from '../../ssr-c9834f50.js';
10
- import { g as getChildProp, r as renderCollectionNode, b as useDerivedItems, a as renderAsCollectionChild } from '../../collection-utils-0967eaf0.js';
11
- import { m as mergeVariantToggles, n as noOutline } from '../../plume-utils-7d68bcc0.js';
12
- import { g as getStyleProps } from '../../props-utils-9f9c761a.js';
8
+ import { m as mergeProps, d as mergeRefs } from '../../react-utils-5ff031c2.js';
9
+ import { a as useEnsureSSRProvider } from '../../ssr-8625df04.js';
10
+ import { g as getChildProp, r as renderCollectionNode, b as useDerivedItems, a as renderAsCollectionChild } from '../../collection-utils-2f28e4eb.js';
11
+ import { m as mergeVariantToggles, n as noOutline } from '../../plume-utils-e699cd08.js';
12
+ import { g as getStyleProps } from '../../props-utils-9d74371f.js';
13
13
  import { T as TriggeredOverlayContext } from '../../context-034b8d25.js';
14
14
  import { useSeparator } from '@react-aria/separator';
15
15
  import 'classnames';
@@ -20,254 +20,254 @@ import '@react-stately/collections';
20
20
 
21
21
  var SelectContext = React.createContext(undefined);
22
22
 
23
- var COLLECTION_OPTS = {
24
- itemPlumeType: "select-option",
25
- sectionPlumeType: "select-option-group"
26
- };
27
- /**
28
- * Converts props in our BaseSelectProps into props that react-aria's
29
- * useSelect() understands.
30
- *
31
- * Because we're not exposing the Collections API (see ./index.tsx),
32
- * we are converting our own API into props for useSelect.
33
- *
34
- * Specifically, in Plume's API,
35
- * - `children` flattens to a list of ReactElements of type Select.Option
36
- * or Select.OptionGroup
37
- *
38
- * and we map it this way to the Collections API:
39
- * - `items` is a list of those flattened ReactElements from `children`!
40
- * - `children`, as a render prop, is supposed to take one of the `items`
41
- * and return a `Section` or `Item` element. We take an Option/OptionGroup
42
- * element, and use its props to render the appropriate `Section` or
43
- * `Item`. The "trick" here is that we then stuff the Option element as
44
- * `Item.children`, and the OptionGroup element as `Section.title`.
45
- *
46
- * When the Collections API does its work deriving `Node`s, the corresponding
47
- * Option/OptionGroup ReactElements will end up as `Node.rendered`.
48
- *
49
- * Then, when we are actually rendering the content of the dropdown, we
50
- * iterate through each collected `Node`, and renders
51
- * React.cloneElement(Node.rendered, {_node: node}). This "secretly" passes
52
- * the derived collection `Node` as a prop to Option and OptionGroup, and they
53
- * can make use of the derived `Node.key` etc in their rendering functions.
54
- *
55
- * One thing to note here is that we never "rendered" the Option/OptionGroup
56
- * React elements that the user constructed; instead, we just looked at the
57
- * props used on those elements, and passed those onto the Collections API.
58
- * What gets rendered to the screen is the cloned version of these elements
59
- * with the secret derived `_node` prop. That means Option and OptionGroup
60
- * render functions can assume that _node is passed in.
61
- */
62
- function useAriaSelectProps(props, config) {
63
- var value = props.value, defaultValue = props.defaultValue; props.children; var onChange = props.onChange; props.placement; props.menuMatchTriggerWidth; props.menuWidth; var rest = __rest(props, ["value", "defaultValue", "children", "onChange", "placement", "menuMatchTriggerWidth", "menuWidth"]);
64
- var _a = useDerivedItems(props, __assign(__assign({}, COLLECTION_OPTS), { invalidChildError: "Can only use Select.Option and Select.OptionGroup as children to Select", requireItemValue: true, ItemComponent: config.OptionComponent, SectionComponent: config.OptionGroupComponent, itemsProp: "options" })), items = _a.items, disabledKeys = _a.disabledKeys;
65
- var collectionChildRenderer = React.useCallback(function (child) { return renderAsCollectionChild(child, COLLECTION_OPTS); }, []);
66
- var onSelectionChange = React.useMemo(function () {
67
- if (onChange) {
68
- return function (val) {
69
- return onChange((val == null || val === "null" ? null : val));
70
- };
71
- }
72
- else {
73
- return undefined;
74
- }
75
- }, [onChange]);
76
- return {
77
- ariaProps: __assign(__assign(__assign({}, rest), { children: collectionChildRenderer, onSelectionChange: onSelectionChange, items: items, disabledKeys: disabledKeys, defaultSelectedKey: defaultValue }), ("value" in props && { selectedKey: value !== null && value !== void 0 ? value : null }))
78
- };
79
- }
80
- function useSelect(plasmicClass, props, config, ref) {
81
- var _a, _b;
82
- if (ref === void 0) { ref = null; }
83
- useEnsureSSRProvider();
84
- var ariaProps = useAriaSelectProps(props, config).ariaProps;
85
- var placement = props.placement;
86
- var state = useSelectState(ariaProps);
87
- var triggerRef = React.useRef(null);
88
- var rootRef = React.useRef(null);
89
- var isDisabled = props.isDisabled, name = props.name, menuWidth = props.menuWidth, menuMatchTriggerWidth = props.menuMatchTriggerWidth, autoFocus = props.autoFocus, placeholder = props.placeholder, selectedContent = props.selectedContent;
90
- var canvasCtx = usePlasmicCanvasContext();
91
- var _c = useSelect$1(ariaProps, state, triggerRef), triggerPressProps = _c.triggerProps, menuProps = _c.menuProps;
92
- var triggerProps = usePress(__assign(__assign({}, triggerPressProps), { isDisabled: isDisabled })).pressProps;
93
- var triggerContent = state.selectedItem
94
- ? selectedContent !== null && selectedContent !== void 0 ? selectedContent : getChildProp(state.selectedItem.value, "children")
95
- : null;
96
- var variants = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.isOpenVariant, active: state.isOpen }, { def: config.placeholderVariant, active: !state.selectedItem }, { def: config.isDisabledVariant, active: isDisabled }));
97
- var triggerContext = React.useMemo(function () { return ({
98
- triggerRef: triggerRef,
99
- state: state,
100
- placement: placement,
101
- overlayMatchTriggerWidth: menuMatchTriggerWidth,
102
- overlayMinTriggerWidth: true,
103
- overlayWidth: menuWidth
104
- }); }, [triggerRef, state, placement, menuMatchTriggerWidth, menuWidth]);
105
- var overrides = (_a = {},
106
- _a[config.root] = {
107
- props: mergeProps(getStyleProps(props), {
108
- ref: rootRef
109
- }),
110
- wrapChildren: function (children) { return (React.createElement(React.Fragment, null,
111
- !canvasCtx && (React.createElement(HiddenSelect, { state: state, triggerRef: triggerRef, name: name, isDisabled: isDisabled })),
112
- children)); }
113
- },
114
- _a[config.trigger] = {
115
- props: mergeProps(canvasCtx ? {} : triggerProps, {
116
- ref: triggerRef,
117
- autoFocus: autoFocus,
118
- disabled: !!isDisabled,
119
- // Don't trigger form submission!
120
- type: "button"
121
- })
122
- },
123
- _a[config.overlay] = {
124
- wrap: function (content) { return (React.createElement(TriggeredOverlayContext.Provider, { value: triggerContext }, content)); }
125
- },
126
- _a[config.optionsContainer] = {
127
- wrap: function (content) { return (React.createElement(ListBoxWrapper, { state: state, menuProps: menuProps }, content)); }
128
- },
129
- _a);
130
- var args = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalArgProps), false))), (_b = {}, _b[config.triggerContentSlot] = triggerContent, _b[config.placeholderSlot] = placeholder, _b[config.optionsSlot] = (React.createElement(SelectContext.Provider, { value: state }, Array.from(state.collection).map(function (node) { return renderCollectionNode(node); }))), _b));
131
- var plumeState = React.useMemo(function () { return ({
132
- open: function () { return state.open(); },
133
- close: function () { return state.close(); },
134
- isOpen: function () { return state.isOpen; },
135
- getSelectedValue: function () {
136
- return state.selectedKey ? "".concat(state.selectedKey) : null;
137
- },
138
- setSelectedValue: function (key) { return state.setSelectedKey(key); }
139
- }); }, [state]);
140
- React.useImperativeHandle(ref, function () { return ({
141
- getRoot: function () { return rootRef.current; },
142
- getTrigger: function () { return triggerRef.current; },
143
- focus: function () { var _a; return (_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
144
- blur: function () { var _a; return (_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
145
- open: function () { return plumeState.open(); },
146
- close: function () { return plumeState.close(); },
147
- isOpen: function () { return plumeState.isOpen(); },
148
- getSelectedValue: function () { return plumeState.getSelectedValue(); },
149
- setSelectedValue: function (key) { return plumeState.setSelectedValue(key); }
150
- }); }, [rootRef, triggerRef, plumeState]);
151
- return {
152
- plasmicProps: {
153
- variants: variants,
154
- args: args,
155
- overrides: overrides
156
- },
157
- state: plumeState
158
- };
159
- }
160
- function ListBoxWrapper(props) {
161
- var state = props.state, menuProps = props.menuProps, children = props.children;
162
- var ref = React.useRef(null);
163
- var canvasCtx = usePlasmicCanvasContext();
164
- var listBoxProps = useListBox(__assign(__assign({}, menuProps), { isVirtualized: false, autoFocus: state.focusStrategy || true, disallowEmptySelection: true }), state, ref).listBoxProps;
165
- return React.cloneElement(children, mergeProps(children.props, canvasCtx ? {} : listBoxProps, {
166
- style: noOutline(),
167
- ref: ref
168
- }));
23
+ var COLLECTION_OPTS = {
24
+ itemPlumeType: "select-option",
25
+ sectionPlumeType: "select-option-group",
26
+ };
27
+ /**
28
+ * Converts props in our BaseSelectProps into props that react-aria's
29
+ * useSelect() understands.
30
+ *
31
+ * Because we're not exposing the Collections API (see ./index.tsx),
32
+ * we are converting our own API into props for useSelect.
33
+ *
34
+ * Specifically, in Plume's API,
35
+ * - `children` flattens to a list of ReactElements of type Select.Option
36
+ * or Select.OptionGroup
37
+ *
38
+ * and we map it this way to the Collections API:
39
+ * - `items` is a list of those flattened ReactElements from `children`!
40
+ * - `children`, as a render prop, is supposed to take one of the `items`
41
+ * and return a `Section` or `Item` element. We take an Option/OptionGroup
42
+ * element, and use its props to render the appropriate `Section` or
43
+ * `Item`. The "trick" here is that we then stuff the Option element as
44
+ * `Item.children`, and the OptionGroup element as `Section.title`.
45
+ *
46
+ * When the Collections API does its work deriving `Node`s, the corresponding
47
+ * Option/OptionGroup ReactElements will end up as `Node.rendered`.
48
+ *
49
+ * Then, when we are actually rendering the content of the dropdown, we
50
+ * iterate through each collected `Node`, and renders
51
+ * React.cloneElement(Node.rendered, {_node: node}). This "secretly" passes
52
+ * the derived collection `Node` as a prop to Option and OptionGroup, and they
53
+ * can make use of the derived `Node.key` etc in their rendering functions.
54
+ *
55
+ * One thing to note here is that we never "rendered" the Option/OptionGroup
56
+ * React elements that the user constructed; instead, we just looked at the
57
+ * props used on those elements, and passed those onto the Collections API.
58
+ * What gets rendered to the screen is the cloned version of these elements
59
+ * with the secret derived `_node` prop. That means Option and OptionGroup
60
+ * render functions can assume that _node is passed in.
61
+ */
62
+ function useAriaSelectProps(props, config) {
63
+ var value = props.value, defaultValue = props.defaultValue; props.children; var onChange = props.onChange; props.placement; props.menuMatchTriggerWidth; props.menuWidth; var rest = __rest(props, ["value", "defaultValue", "children", "onChange", "placement", "menuMatchTriggerWidth", "menuWidth"]);
64
+ var _a = useDerivedItems(props, __assign(__assign({}, COLLECTION_OPTS), { invalidChildError: "Can only use Select.Option and Select.OptionGroup as children to Select", requireItemValue: true, ItemComponent: config.OptionComponent, SectionComponent: config.OptionGroupComponent, itemsProp: "options" })), items = _a.items, disabledKeys = _a.disabledKeys;
65
+ var collectionChildRenderer = React.useCallback(function (child) { return renderAsCollectionChild(child, COLLECTION_OPTS); }, []);
66
+ var onSelectionChange = React.useMemo(function () {
67
+ if (onChange) {
68
+ return function (val) {
69
+ return onChange((val == null || val === "null" ? null : val));
70
+ };
71
+ }
72
+ else {
73
+ return undefined;
74
+ }
75
+ }, [onChange]);
76
+ return {
77
+ ariaProps: __assign(__assign(__assign({}, rest), { children: collectionChildRenderer, onSelectionChange: onSelectionChange, items: items, disabledKeys: disabledKeys, defaultSelectedKey: defaultValue }), ("value" in props && { selectedKey: value !== null && value !== void 0 ? value : null })),
78
+ };
79
+ }
80
+ function useSelect(plasmicClass, props, config, ref) {
81
+ var _a, _b;
82
+ if (ref === void 0) { ref = null; }
83
+ useEnsureSSRProvider();
84
+ var ariaProps = useAriaSelectProps(props, config).ariaProps;
85
+ var placement = props.placement;
86
+ var state = useSelectState(ariaProps);
87
+ var triggerRef = React.useRef(null);
88
+ var rootRef = React.useRef(null);
89
+ var isDisabled = props.isDisabled, name = props.name, menuWidth = props.menuWidth, menuMatchTriggerWidth = props.menuMatchTriggerWidth, autoFocus = props.autoFocus, placeholder = props.placeholder, selectedContent = props.selectedContent;
90
+ var canvasCtx = usePlasmicCanvasContext();
91
+ var _c = useSelect$1(ariaProps, state, triggerRef), triggerPressProps = _c.triggerProps, menuProps = _c.menuProps;
92
+ var triggerProps = usePress(__assign(__assign({}, triggerPressProps), { isDisabled: isDisabled })).pressProps;
93
+ var triggerContent = state.selectedItem
94
+ ? selectedContent !== null && selectedContent !== void 0 ? selectedContent : getChildProp(state.selectedItem.value, "children")
95
+ : null;
96
+ var variants = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.isOpenVariant, active: state.isOpen }, { def: config.placeholderVariant, active: !state.selectedItem }, { def: config.isDisabledVariant, active: isDisabled }));
97
+ var triggerContext = React.useMemo(function () { return ({
98
+ triggerRef: triggerRef,
99
+ state: state,
100
+ placement: placement,
101
+ overlayMatchTriggerWidth: menuMatchTriggerWidth,
102
+ overlayMinTriggerWidth: true,
103
+ overlayWidth: menuWidth,
104
+ }); }, [triggerRef, state, placement, menuMatchTriggerWidth, menuWidth]);
105
+ var overrides = (_a = {},
106
+ _a[config.root] = {
107
+ props: mergeProps(getStyleProps(props), {
108
+ ref: rootRef,
109
+ }),
110
+ wrapChildren: function (children) { return (React.createElement(React.Fragment, null,
111
+ (!canvasCtx || canvasCtx.interactive) && (React.createElement(HiddenSelect, { state: state, triggerRef: triggerRef, name: name, isDisabled: isDisabled })),
112
+ children)); },
113
+ },
114
+ _a[config.trigger] = {
115
+ props: mergeProps(canvasCtx && !canvasCtx.interactive ? {} : triggerProps, {
116
+ ref: triggerRef,
117
+ autoFocus: autoFocus,
118
+ disabled: !!isDisabled,
119
+ // Don't trigger form submission!
120
+ type: "button",
121
+ }),
122
+ },
123
+ _a[config.overlay] = {
124
+ wrap: function (content) { return (React.createElement(TriggeredOverlayContext.Provider, { value: triggerContext }, content)); },
125
+ },
126
+ _a[config.optionsContainer] = {
127
+ wrap: function (content) { return (React.createElement(ListBoxWrapper, { state: state, menuProps: menuProps }, content)); },
128
+ },
129
+ _a);
130
+ var args = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalArgProps), false))), (_b = {}, _b[config.triggerContentSlot] = triggerContent, _b[config.placeholderSlot] = placeholder, _b[config.optionsSlot] = (React.createElement(SelectContext.Provider, { value: state }, Array.from(state.collection).map(function (node) { return renderCollectionNode(node); }))), _b));
131
+ var plumeState = React.useMemo(function () { return ({
132
+ open: function () { return state.open(); },
133
+ close: function () { return state.close(); },
134
+ isOpen: function () { return state.isOpen; },
135
+ getSelectedValue: function () {
136
+ return state.selectedKey ? "".concat(state.selectedKey) : null;
137
+ },
138
+ setSelectedValue: function (key) { return state.setSelectedKey(key); },
139
+ }); }, [state]);
140
+ React.useImperativeHandle(ref, function () { return ({
141
+ getRoot: function () { return rootRef.current; },
142
+ getTrigger: function () { return triggerRef.current; },
143
+ focus: function () { var _a; return (_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
144
+ blur: function () { var _a; return (_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
145
+ open: function () { return plumeState.open(); },
146
+ close: function () { return plumeState.close(); },
147
+ isOpen: function () { return plumeState.isOpen(); },
148
+ getSelectedValue: function () { return plumeState.getSelectedValue(); },
149
+ setSelectedValue: function (key) { return plumeState.setSelectedValue(key); },
150
+ }); }, [rootRef, triggerRef, plumeState]);
151
+ return {
152
+ plasmicProps: {
153
+ variants: variants,
154
+ args: args,
155
+ overrides: overrides,
156
+ },
157
+ state: plumeState,
158
+ };
159
+ }
160
+ function ListBoxWrapper(props) {
161
+ var state = props.state, menuProps = props.menuProps, children = props.children;
162
+ var ref = React.useRef(null);
163
+ var canvasCtx = usePlasmicCanvasContext();
164
+ var listBoxProps = useListBox(__assign(__assign({}, menuProps), { isVirtualized: false, autoFocus: state.focusStrategy || true, disallowEmptySelection: true }), state, ref).listBoxProps;
165
+ return React.cloneElement(children, mergeProps(children.props, canvasCtx && !canvasCtx.interactive ? {} : listBoxProps, {
166
+ style: noOutline(),
167
+ ref: ref,
168
+ }));
169
169
  }
170
170
 
171
- function useSelectOption(plasmicClass, props, config, outerRef) {
172
- var _a, _b;
173
- if (outerRef === void 0) { outerRef = null; }
174
- var state = React.useContext(SelectContext);
175
- if (!state) {
176
- // If no context, then we are being incorrectly used. Complain or just don't
177
- // bother installing any hooks. It's okay to violate rules of hooks here
178
- // because this instance won't suddenly be used correctly in another render.
179
- {
180
- throw new Error("You can only use a Select.Option within a Select component.");
181
- }
182
- }
183
- var children = props.children;
184
- var canvasCtx = usePlasmicCanvasContext();
185
- var rootRef = React.useRef(null);
186
- var onRef = mergeRefs(rootRef, outerRef);
187
- // We pass in the Node secretly as an undocumented prop from <Select />
188
- var node = props._node;
189
- var isSelected = state.selectionManager.isSelected(node.key);
190
- var isDisabled = state.disabledKeys.has(node.key);
191
- var isHighlighted = state.selectionManager.isFocused &&
192
- state.selectionManager.focusedKey === node.key;
193
- var _c = useOption({
194
- isSelected: isSelected,
195
- isDisabled: isDisabled,
196
- "aria-label": node && node["aria-label"],
197
- key: node.key,
198
- shouldSelectOnPressUp: true,
199
- shouldFocusOnHover: true,
200
- isVirtualized: false,
201
- shouldUseVirtualFocus: !!canvasCtx
202
- }, state, rootRef), optionProps = _c.optionProps, labelProps = _c.labelProps;
203
- var variants = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.isSelectedVariant, active: isSelected }, { def: config.isDisabledVariant, active: isDisabled }, { def: config.isHighlightedVariant, active: isHighlighted }));
204
- var args = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalArgProps), false))), (_a = {}, _a[config.labelSlot] = children, _a));
205
- var overrides = (_b = {},
206
- _b[config.root] = {
207
- props: mergeProps(canvasCtx ? {} : optionProps, getStyleProps(props), {
208
- ref: onRef,
209
- style: noOutline()
210
- })
211
- },
212
- _b[config.labelContainer] = {
213
- props: labelProps
214
- },
215
- _b);
216
- return {
217
- plasmicProps: {
218
- variants: variants,
219
- args: args,
220
- overrides: overrides
221
- }
222
- };
171
+ function useSelectOption(plasmicClass, props, config, outerRef) {
172
+ var _a, _b;
173
+ if (outerRef === void 0) { outerRef = null; }
174
+ var state = React.useContext(SelectContext);
175
+ if (!state) {
176
+ // If no context, then we are being incorrectly used. Complain or just don't
177
+ // bother installing any hooks. It's okay to violate rules of hooks here
178
+ // because this instance won't suddenly be used correctly in another render.
179
+ {
180
+ throw new Error("You can only use a Select.Option within a Select component.");
181
+ }
182
+ }
183
+ var children = props.children;
184
+ var canvasCtx = usePlasmicCanvasContext();
185
+ var rootRef = React.useRef(null);
186
+ var onRef = mergeRefs(rootRef, outerRef);
187
+ // We pass in the Node secretly as an undocumented prop from <Select />
188
+ var node = props._node;
189
+ var isSelected = state.selectionManager.isSelected(node.key);
190
+ var isDisabled = state.disabledKeys.has(node.key);
191
+ var isHighlighted = state.selectionManager.isFocused &&
192
+ state.selectionManager.focusedKey === node.key;
193
+ var _c = useOption({
194
+ isSelected: isSelected,
195
+ isDisabled: isDisabled,
196
+ "aria-label": node && node["aria-label"],
197
+ key: node.key,
198
+ shouldSelectOnPressUp: true,
199
+ shouldFocusOnHover: true,
200
+ isVirtualized: false,
201
+ shouldUseVirtualFocus: canvasCtx && !canvasCtx.interactive,
202
+ }, state, rootRef), optionProps = _c.optionProps, labelProps = _c.labelProps;
203
+ var variants = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.isSelectedVariant, active: isSelected }, { def: config.isDisabledVariant, active: isDisabled }, { def: config.isHighlightedVariant, active: isHighlighted }));
204
+ var args = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalArgProps), false))), (_a = {}, _a[config.labelSlot] = children, _a));
205
+ var overrides = (_b = {},
206
+ _b[config.root] = {
207
+ props: mergeProps(canvasCtx && !canvasCtx.interactive ? {} : optionProps, getStyleProps(props), {
208
+ ref: onRef,
209
+ style: noOutline(),
210
+ }),
211
+ },
212
+ _b[config.labelContainer] = {
213
+ props: labelProps,
214
+ },
215
+ _b);
216
+ return {
217
+ plasmicProps: {
218
+ variants: variants,
219
+ args: args,
220
+ overrides: overrides,
221
+ },
222
+ };
223
223
  }
224
224
 
225
- function useSelectOptionGroup(plasmicClass, props, config) {
226
- var _a, _b;
227
- var state = React.useContext(SelectContext);
228
- // `node` should exist if the OptionGroup was instantiated properly
229
- // within a Select
230
- var node = props._node;
231
- if (!state || !node) {
232
- {
233
- throw new Error("You can only use a Select.OptionGroup within a Select component.");
234
- }
235
- }
236
- var _c = useListBoxSection({
237
- heading: props.title,
238
- "aria-label": props["aria-label"]
239
- }), headingProps = _c.headingProps, groupProps = _c.groupProps;
240
- var separatorProps = useSeparator({
241
- elementType: "li"
242
- }).separatorProps;
243
- var variants = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.noTitleVariant, active: !props.title }, {
244
- def: config.isFirstVariant,
245
- active: state.collection.getFirstKey() === node.key
246
- }));
247
- var args = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalArgProps), false))), (_a = {}, _a[config.titleSlot] = props.title, _a[config.optionsSlot] = Array.from(node.childNodes).map(function (childNode) {
248
- return renderCollectionNode(childNode);
249
- }), _a));
250
- var overrides = (_b = {},
251
- _b[config.root] = {
252
- props: getStyleProps(props)
253
- },
254
- _b[config.separator] = {
255
- props: __assign({}, separatorProps)
256
- },
257
- _b[config.titleContainer] = __assign({ props: __assign({ role: "presentation" }, headingProps) }, (!props.title && {
258
- render: function () { return null; }
259
- })),
260
- _b[config.optionsContainer] = {
261
- props: __assign({}, groupProps)
262
- },
263
- _b);
264
- return {
265
- plasmicProps: {
266
- variants: variants,
267
- args: args,
268
- overrides: overrides
269
- }
270
- };
225
+ function useSelectOptionGroup(plasmicClass, props, config) {
226
+ var _a, _b;
227
+ var state = React.useContext(SelectContext);
228
+ // `node` should exist if the OptionGroup was instantiated properly
229
+ // within a Select
230
+ var node = props._node;
231
+ if (!state || !node) {
232
+ {
233
+ throw new Error("You can only use a Select.OptionGroup within a Select component.");
234
+ }
235
+ }
236
+ var _c = useListBoxSection({
237
+ heading: props.title,
238
+ "aria-label": props["aria-label"],
239
+ }), headingProps = _c.headingProps, groupProps = _c.groupProps;
240
+ var separatorProps = useSeparator({
241
+ elementType: "li",
242
+ }).separatorProps;
243
+ var variants = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.noTitleVariant, active: !props.title }, {
244
+ def: config.isFirstVariant,
245
+ active: state.collection.getFirstKey() === node.key,
246
+ }));
247
+ var args = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalArgProps), false))), (_a = {}, _a[config.titleSlot] = props.title, _a[config.optionsSlot] = Array.from(node.childNodes).map(function (childNode) {
248
+ return renderCollectionNode(childNode);
249
+ }), _a));
250
+ var overrides = (_b = {},
251
+ _b[config.root] = {
252
+ props: getStyleProps(props),
253
+ },
254
+ _b[config.separator] = {
255
+ props: __assign({}, separatorProps),
256
+ },
257
+ _b[config.titleContainer] = __assign({ props: __assign({ role: "presentation" }, headingProps) }, (!props.title && {
258
+ render: function () { return null; },
259
+ })),
260
+ _b[config.optionsContainer] = {
261
+ props: __assign({}, groupProps),
262
+ },
263
+ _b);
264
+ return {
265
+ plasmicProps: {
266
+ variants: variants,
267
+ args: args,
268
+ overrides: overrides,
269
+ },
270
+ };
271
271
  }
272
272
 
273
273
  export { SelectContext, useSelect, useSelectOption, useSelectOptionGroup };