@plasmicapp/react-web 0.2.160 → 0.2.162

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 CHANGED
@@ -1015,6 +1015,17 @@ interface SectionLikeProps {
1015
1015
  * A list of items that belong in this group
1016
1016
  */
1017
1017
  children?: React__default.ReactNode;
1018
+ }
1019
+ declare type ItemJson = LeafItemJson | SectionJson;
1020
+ declare type LeafItemJson = string | {
1021
+ value: string;
1022
+ label?: string;
1023
+ textValue?: string;
1024
+ isDisabled?: boolean;
1025
+ };
1026
+ interface SectionJson {
1027
+ title: string;
1028
+ children: ItemJson[];
1018
1029
  }
1019
1030
 
1020
1031
  interface BaseMenuGroupProps extends SectionLikeProps, StyleProps {
@@ -1191,6 +1202,15 @@ interface BaseSelectProps extends DOMProps, AriaLabelingProps, FocusableDOMProps
1191
1202
  * List of Select.Options
1192
1203
  */
1193
1204
  children?: React.ReactNode;
1205
+ /**
1206
+ * List of options as an array, instead of using `children` prop. If this
1207
+ * is passed in, then `children` is ignored.
1208
+ *
1209
+ * The options can be a list of strings, or a list of objects with
1210
+ * fields `value` (for the value of the option), `label` (for what's rendered
1211
+ * in the option), and `isDisabled` (if the option should be disabled).
1212
+ */
1213
+ options?: ItemJson[];
1194
1214
  /**
1195
1215
  * Whether the Select is currently open
1196
1216
  */
@@ -1251,6 +1271,8 @@ interface SelectConfig<C extends AnyPlasmicClass> {
1251
1271
  trigger: keyof PlasmicClassOverrides<C>;
1252
1272
  overlay: keyof PlasmicClassOverrides<C>;
1253
1273
  optionsContainer: keyof PlasmicClassOverrides<C>;
1274
+ OptionComponent?: React.ComponentType<ItemLikeProps>;
1275
+ OptionGroupComponent?: React.ComponentType<SectionLikeProps>;
1254
1276
  }
1255
1277
  interface SelectState {
1256
1278
  open: () => void;
@@ -107,6 +107,32 @@ export interface SectionLikeProps {
107
107
  children?: React.ReactNode;
108
108
  }
109
109
  declare type LoaderAwareSectionLikeProps = SectionLikeProps | PlasmicLoaderProps<SectionLikeProps>;
110
+ export declare type ItemJson = LeafItemJson | SectionJson;
111
+ export declare type LeafItemJson = string | {
112
+ value: string;
113
+ label?: string;
114
+ textValue?: string;
115
+ isDisabled?: boolean;
116
+ };
117
+ export interface SectionJson {
118
+ title: string;
119
+ children: ItemJson[];
120
+ }
121
+ export declare function deriveItemsFromProps(props: any, opts: {
122
+ itemPlumeType: string;
123
+ sectionPlumeType?: string;
124
+ invalidChildError?: string;
125
+ requireItemValue: boolean;
126
+ ItemComponent?: React.ComponentType<ItemLikeProps>;
127
+ SectionComponent?: React.ComponentType<SectionLikeProps>;
128
+ itemsProp?: string;
129
+ }): {
130
+ items: JSX.Element[];
131
+ disabledKeys: string[];
132
+ } | {
133
+ items: React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)>[];
134
+ disabledKeys: React.Key[];
135
+ };
110
136
  /**
111
137
  * Given children of a component like Select or Menu, derive the items
112
138
  * that we will pass into the Collections API. These will be
@@ -124,6 +150,21 @@ export declare function deriveItemsFromChildren<T extends React.ReactElement>(ch
124
150
  items: T[];
125
151
  disabledKeys: React.Key[];
126
152
  };
153
+ export declare function useDerivedItems(props: any, opts: {
154
+ itemPlumeType: string;
155
+ sectionPlumeType?: string;
156
+ invalidChildError?: string;
157
+ requireItemValue: boolean;
158
+ ItemComponent?: React.ComponentType<ItemLikeProps>;
159
+ SectionComponent?: React.ComponentType<SectionLikeProps>;
160
+ itemsProp?: string;
161
+ }): {
162
+ items: JSX.Element[];
163
+ disabledKeys: string[];
164
+ } | {
165
+ items: React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)>[];
166
+ disabledKeys: React.Key[];
167
+ };
127
168
  export declare function useDerivedItemsFromChildren<T extends React.ReactElement>(children: React.ReactNode, opts: {
128
169
  itemPlumeType: string;
129
170
  sectionPlumeType?: string;
@@ -1,6 +1,7 @@
1
1
  import { Placement } from "@react-types/overlays";
2
2
  import { AriaLabelingProps, DOMProps, FocusableDOMProps, FocusableProps, InputBase } from "@react-types/shared";
3
3
  import * as React from "react";
4
+ import { ItemJson, ItemLikeProps, SectionLikeProps } from "../collection-utils";
4
5
  import { AnyPlasmicClass, PlasmicClassArgs, PlasmicClassOverrides, PlasmicClassVariants, VariantDef } from "../plume-utils";
5
6
  import { StyleProps } from "../props-utils";
6
7
  export interface BaseSelectProps extends DOMProps, AriaLabelingProps, FocusableDOMProps, InputBase, FocusableProps, StyleProps {
@@ -20,6 +21,15 @@ export interface BaseSelectProps extends DOMProps, AriaLabelingProps, FocusableD
20
21
  * List of Select.Options
21
22
  */
22
23
  children?: React.ReactNode;
24
+ /**
25
+ * List of options as an array, instead of using `children` prop. If this
26
+ * is passed in, then `children` is ignored.
27
+ *
28
+ * The options can be a list of strings, or a list of objects with
29
+ * fields `value` (for the value of the option), `label` (for what's rendered
30
+ * in the option), and `isDisabled` (if the option should be disabled).
31
+ */
32
+ options?: ItemJson[];
23
33
  /**
24
34
  * Whether the Select is currently open
25
35
  */
@@ -80,6 +90,8 @@ interface SelectConfig<C extends AnyPlasmicClass> {
80
90
  trigger: keyof PlasmicClassOverrides<C>;
81
91
  overlay: keyof PlasmicClassOverrides<C>;
82
92
  optionsContainer: keyof PlasmicClassOverrides<C>;
93
+ OptionComponent?: React.ComponentType<ItemLikeProps>;
94
+ OptionGroupComponent?: React.ComponentType<SectionLikeProps>;
83
95
  }
84
96
  interface SelectState {
85
97
  open: () => void;
@@ -25,6 +25,7 @@ var collections = require('@react-stately/collections');
25
25
  var separator = require('@react-aria/separator');
26
26
  var menu$1 = require('@react-stately/menu');
27
27
  var interactions = require('@react-aria/interactions');
28
+ var host = require('@plasmicapp/host');
28
29
  var listbox = require('@react-aria/listbox');
29
30
  var select = require('@react-aria/select');
30
31
  var select$1 = require('@react-stately/select');
@@ -2641,13 +2642,14 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
2641
2642
  var node = _ref.node,
2642
2643
  path = _ref.path;
2643
2644
  node.addListener(path, function () {
2644
- var newValue = initialSpecNode.getSpec().initFunc(_extends({
2645
+ var newValue = invokeInitFuncBackwardsCompatible(initialSpecNode.getSpec().initFunc, _extends({
2645
2646
  $state: $state
2646
2647
  }, $$state.env));
2647
2648
  set(proxyRoot, initialStatePath, newValue);
2648
2649
  });
2649
2650
  });
2650
- var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))(_extends({
2651
+ var initFunc = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath));
2652
+ var initialValue = invokeInitFuncBackwardsCompatible(initFunc, _extends({
2651
2653
  $state: $state
2652
2654
  }, $$state.env));
2653
2655
  initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
@@ -2823,6 +2825,13 @@ function extractDollarStateParametersBackwardCompatible() {
2823
2825
  };
2824
2826
  }
2825
2827
  }
2828
+ function invokeInitFuncBackwardsCompatible(initFunc, env) {
2829
+ if (initFunc.length > 1) {
2830
+ return initFunc(env.$props, env.$state, env.$ctx);
2831
+ } else {
2832
+ return initFunc(env);
2833
+ }
2834
+ }
2826
2835
  function useDollarState(specs) {
2827
2836
  for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2828
2837
  rest[_key - 1] = arguments[_key];
@@ -2929,7 +2938,7 @@ function useDollarState(specs) {
2929
2938
  stateCell = _ref3.stateCell;
2930
2939
  var initFunc = node.getInitFunc(stateCell);
2931
2940
  if (initFunc) {
2932
- var newInit = initFunc(_extends({
2941
+ var newInit = invokeInitFuncBackwardsCompatible(initFunc, _extends({
2933
2942
  $state: $state
2934
2943
  }, envFieldsAreNonNill(env)));
2935
2944
  if (!deepEqual(newInit, stateCell.initialValue)) {
@@ -3169,6 +3178,58 @@ function useCheckbox(plasmicClass, props, config, ref) {
3169
3178
  };
3170
3179
  }
3171
3180
 
3181
+ function deriveItemsFromProps(props, opts) {
3182
+ if (opts.itemsProp && opts.itemsProp in props) {
3183
+ if (!opts.ItemComponent || !opts.SectionComponent) {
3184
+ throw new Error("You may need to re-generate your Plasmic* files");
3185
+ }
3186
+ var items = props[opts.itemsProp];
3187
+ return deriveItemsFromItemsProp(items, {
3188
+ ItemComponent: opts.ItemComponent,
3189
+ SectionComponent: opts.SectionComponent
3190
+ });
3191
+ } else {
3192
+ return deriveItemsFromChildren(props.children, opts);
3193
+ }
3194
+ }
3195
+ function deriveItemsFromItemsProp(items, opts) {
3196
+ var _items$map;
3197
+ var ItemComponent = opts.ItemComponent,
3198
+ SectionComponent = opts.SectionComponent;
3199
+ var disabledKeys = [];
3200
+ var transform = function transform(item) {
3201
+ if (typeof item === "string") {
3202
+ return React__default.createElement(ItemComponent, {
3203
+ key: item,
3204
+ value: item
3205
+ }, item);
3206
+ } else if ("children" in item) {
3207
+ return React__default.createElement(SectionComponent, {
3208
+ key: item.title,
3209
+ title: item.title
3210
+ }, item.children.map(function (x) {
3211
+ return transform(x);
3212
+ }));
3213
+ } else {
3214
+ var _item$label;
3215
+ if (item.isDisabled) {
3216
+ disabledKeys.push(item.value);
3217
+ }
3218
+ return React__default.createElement(ItemComponent, {
3219
+ key: item.value,
3220
+ value: item.value,
3221
+ textValue: item.textValue,
3222
+ isDisabled: item.isDisabled
3223
+ }, (_item$label = item.label) != null ? _item$label : item.value);
3224
+ }
3225
+ };
3226
+ return {
3227
+ items: (_items$map = items == null ? void 0 : items.map(function (x) {
3228
+ return transform(x);
3229
+ })) != null ? _items$map : [],
3230
+ disabledKeys: disabledKeys
3231
+ };
3232
+ }
3172
3233
  /**
3173
3234
  * Given children of a component like Select or Menu, derive the items
3174
3235
  * that we will pass into the Collections API. These will be
@@ -3245,6 +3306,28 @@ function deriveItemsFromChildren(children, opts) {
3245
3306
  disabledKeys: disabledKeys
3246
3307
  };
3247
3308
  }
3309
+ function useDerivedItems(props, opts) {
3310
+ var children = props.children;
3311
+ var itemPlumeType = opts.itemPlumeType,
3312
+ sectionPlumeType = opts.sectionPlumeType,
3313
+ invalidChildError = opts.invalidChildError,
3314
+ requireItemValue = opts.requireItemValue,
3315
+ ItemComponent = opts.ItemComponent,
3316
+ SectionComponent = opts.SectionComponent,
3317
+ itemsProp = opts.itemsProp;
3318
+ var items = itemsProp ? props[itemsProp] : undefined;
3319
+ return React__default.useMemo(function () {
3320
+ return deriveItemsFromProps(props, {
3321
+ itemPlumeType: itemPlumeType,
3322
+ sectionPlumeType: sectionPlumeType,
3323
+ invalidChildError: invalidChildError,
3324
+ requireItemValue: requireItemValue,
3325
+ itemsProp: itemsProp,
3326
+ ItemComponent: ItemComponent,
3327
+ SectionComponent: SectionComponent
3328
+ });
3329
+ }, [children, items, itemPlumeType, sectionPlumeType, invalidChildError, requireItemValue, ItemComponent, SectionComponent]);
3330
+ }
3248
3331
  function useDerivedItemsFromChildren(children, opts) {
3249
3332
  var itemPlumeType = opts.itemPlumeType,
3250
3333
  sectionPlumeType = opts.sectionPlumeType,
@@ -3795,18 +3878,20 @@ var COLLECTION_OPTS$1 = {
3795
3878
  * with the secret derived `_node` prop. That means Option and OptionGroup
3796
3879
  * render functions can assume that _node is passed in.
3797
3880
  */
3798
- function useAriaSelectProps(props) {
3881
+ function useAriaSelectProps(props, config) {
3799
3882
  var value = props.value,
3800
3883
  defaultValue = props.defaultValue,
3801
- children = props.children,
3802
3884
  onChange = props.onChange,
3803
3885
  rest = _objectWithoutPropertiesLoose(props, _excluded$6);
3804
- var _useDerivedItemsFromC = useDerivedItemsFromChildren(children, _extends({}, COLLECTION_OPTS$1, {
3886
+ var _useDerivedItems = useDerivedItems(props, _extends({}, COLLECTION_OPTS$1, {
3805
3887
  invalidChildError: "Can only use Select.Option and Select.OptionGroup as children to Select",
3806
- requireItemValue: true
3888
+ requireItemValue: true,
3889
+ ItemComponent: config.OptionComponent,
3890
+ SectionComponent: config.OptionGroupComponent,
3891
+ itemsProp: "options"
3807
3892
  })),
3808
- items = _useDerivedItemsFromC.items,
3809
- disabledKeys = _useDerivedItemsFromC.disabledKeys;
3893
+ items = _useDerivedItems.items,
3894
+ disabledKeys = _useDerivedItems.disabledKeys;
3810
3895
  var collectionChildRenderer = React.useCallback(function (child) {
3811
3896
  return renderAsCollectionChild(child, COLLECTION_OPTS$1);
3812
3897
  }, []);
@@ -3837,7 +3922,7 @@ function useSelect(plasmicClass, props, config, ref) {
3837
3922
  ref = null;
3838
3923
  }
3839
3924
  useEnsureSSRProvider();
3840
- var _useAriaSelectProps = useAriaSelectProps(props),
3925
+ var _useAriaSelectProps = useAriaSelectProps(props, config),
3841
3926
  ariaProps = _useAriaSelectProps.ariaProps;
3842
3927
  var placement = props.placement;
3843
3928
  var state = select$1.useSelectState(ariaProps);
@@ -3850,6 +3935,7 @@ function useSelect(plasmicClass, props, config, ref) {
3850
3935
  autoFocus = props.autoFocus,
3851
3936
  placeholder = props.placeholder,
3852
3937
  selectedContent = props.selectedContent;
3938
+ var canvasCtx = host.usePlasmicCanvasContext();
3853
3939
  var _useAriaSelect = select.useSelect(ariaProps, state, triggerRef),
3854
3940
  triggerPressProps = _useAriaSelect.triggerProps,
3855
3941
  menuProps = _useAriaSelect.menuProps;
@@ -3883,7 +3969,7 @@ function useSelect(plasmicClass, props, config, ref) {
3883
3969
  ref: rootRef
3884
3970
  }),
3885
3971
  wrapChildren: function wrapChildren(children) {
3886
- return React.createElement(React.Fragment, null, React.createElement(select.HiddenSelect, {
3972
+ return React.createElement(React.Fragment, null, !canvasCtx && React.createElement(select.HiddenSelect, {
3887
3973
  state: state,
3888
3974
  triggerRef: triggerRef,
3889
3975
  name: name,
@@ -3891,7 +3977,7 @@ function useSelect(plasmicClass, props, config, ref) {
3891
3977
  }), children);
3892
3978
  }
3893
3979
  }, _overrides[config.trigger] = {
3894
- props: mergeProps(triggerProps, {
3980
+ props: mergeProps(canvasCtx ? {} : triggerProps, {
3895
3981
  ref: triggerRef,
3896
3982
  autoFocus: autoFocus,
3897
3983
  disabled: !!isDisabled,
@@ -3983,13 +4069,14 @@ function ListBoxWrapper(props) {
3983
4069
  menuProps = props.menuProps,
3984
4070
  children = props.children;
3985
4071
  var ref = React.useRef(null);
4072
+ var canvasCtx = host.usePlasmicCanvasContext();
3986
4073
  var _useListBox = listbox.useListBox(_extends({}, menuProps, {
3987
4074
  isVirtualized: false,
3988
4075
  autoFocus: state.focusStrategy || true,
3989
4076
  disallowEmptySelection: true
3990
4077
  }), state, ref),
3991
4078
  listBoxProps = _useListBox.listBoxProps;
3992
- return React.cloneElement(children, mergeProps(children.props, listBoxProps, {
4079
+ return React.cloneElement(children, mergeProps(children.props, canvasCtx ? {} : listBoxProps, {
3993
4080
  style: noOutline(),
3994
4081
  ref: ref
3995
4082
  }));
@@ -4011,6 +4098,7 @@ function useSelectOption(plasmicClass, props, config, outerRef) {
4011
4098
  return getDefaultPlasmicProps(plasmicClass, props);
4012
4099
  }
4013
4100
  var children = props.children;
4101
+ var canvasCtx = host.usePlasmicCanvasContext();
4014
4102
  var rootRef = React.useRef(null);
4015
4103
  var onRef = mergeRefs(rootRef, outerRef);
4016
4104
  // We pass in the Node secretly as an undocumented prop from <Select />
@@ -4025,7 +4113,8 @@ function useSelectOption(plasmicClass, props, config, outerRef) {
4025
4113
  key: node.key,
4026
4114
  shouldSelectOnPressUp: true,
4027
4115
  shouldFocusOnHover: true,
4028
- isVirtualized: false
4116
+ isVirtualized: false,
4117
+ shouldUseVirtualFocus: !!canvasCtx
4029
4118
  }, state, rootRef),
4030
4119
  optionProps = _useAriaOption.optionProps,
4031
4120
  labelProps = _useAriaOption.labelProps;
@@ -4041,7 +4130,7 @@ function useSelectOption(plasmicClass, props, config, outerRef) {
4041
4130
  }));
4042
4131
  var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.labelSlot] = children, _extends2));
4043
4132
  var overrides = (_overrides = {}, _overrides[config.root] = {
4044
- props: mergeProps(optionProps, getStyleProps(props), {
4133
+ props: mergeProps(canvasCtx ? {} : optionProps, getStyleProps(props), {
4045
4134
  ref: onRef,
4046
4135
  style: noOutline()
4047
4136
  })
@@ -4352,7 +4441,8 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissabl
4352
4441
  def: config.isPlacedRightVariant,
4353
4442
  active: placementAxis === "right"
4354
4443
  }));
4355
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.contentSlot] = React.createElement(focus.FocusScope, {
4444
+ var canvasCtx = host.usePlasmicCanvasContext();
4445
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.contentSlot] = canvasCtx ? children : React.createElement(focus.FocusScope, {
4356
4446
  restoreFocus: true
4357
4447
  }, React.createElement(overlays.DismissButton, {
4358
4448
  onDismiss: state.close