@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.
@@ -20,6 +20,7 @@ import { Item, Section } from '@react-stately/collections';
20
20
  import { useSeparator } from '@react-aria/separator';
21
21
  import { useMenuTriggerState } from '@react-stately/menu';
22
22
  import { usePress } from '@react-aria/interactions';
23
+ import { usePlasmicCanvasContext } from '@plasmicapp/host';
23
24
  import { useListBox, useOption, useListBoxSection } from '@react-aria/listbox';
24
25
  import { useSelect as useSelect$1, HiddenSelect } from '@react-aria/select';
25
26
  import { useSelectState } from '@react-stately/select';
@@ -2636,13 +2637,14 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
2636
2637
  var node = _ref.node,
2637
2638
  path = _ref.path;
2638
2639
  node.addListener(path, function () {
2639
- var newValue = initialSpecNode.getSpec().initFunc(_extends({
2640
+ var newValue = invokeInitFuncBackwardsCompatible(initialSpecNode.getSpec().initFunc, _extends({
2640
2641
  $state: $state
2641
2642
  }, $$state.env));
2642
2643
  set(proxyRoot, initialStatePath, newValue);
2643
2644
  });
2644
2645
  });
2645
- var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))(_extends({
2646
+ var initFunc = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath));
2647
+ var initialValue = invokeInitFuncBackwardsCompatible(initFunc, _extends({
2646
2648
  $state: $state
2647
2649
  }, $$state.env));
2648
2650
  initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
@@ -2818,6 +2820,13 @@ function extractDollarStateParametersBackwardCompatible() {
2818
2820
  };
2819
2821
  }
2820
2822
  }
2823
+ function invokeInitFuncBackwardsCompatible(initFunc, env) {
2824
+ if (initFunc.length > 1) {
2825
+ return initFunc(env.$props, env.$state, env.$ctx);
2826
+ } else {
2827
+ return initFunc(env);
2828
+ }
2829
+ }
2821
2830
  function useDollarState(specs) {
2822
2831
  for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2823
2832
  rest[_key - 1] = arguments[_key];
@@ -2924,7 +2933,7 @@ function useDollarState(specs) {
2924
2933
  stateCell = _ref3.stateCell;
2925
2934
  var initFunc = node.getInitFunc(stateCell);
2926
2935
  if (initFunc) {
2927
- var newInit = initFunc(_extends({
2936
+ var newInit = invokeInitFuncBackwardsCompatible(initFunc, _extends({
2928
2937
  $state: $state
2929
2938
  }, envFieldsAreNonNill(env)));
2930
2939
  if (!deepEqual(newInit, stateCell.initialValue)) {
@@ -3164,6 +3173,58 @@ function useCheckbox(plasmicClass, props, config, ref) {
3164
3173
  };
3165
3174
  }
3166
3175
 
3176
+ function deriveItemsFromProps(props, opts) {
3177
+ if (opts.itemsProp && opts.itemsProp in props) {
3178
+ if (!opts.ItemComponent || !opts.SectionComponent) {
3179
+ throw new Error("You may need to re-generate your Plasmic* files");
3180
+ }
3181
+ var items = props[opts.itemsProp];
3182
+ return deriveItemsFromItemsProp(items, {
3183
+ ItemComponent: opts.ItemComponent,
3184
+ SectionComponent: opts.SectionComponent
3185
+ });
3186
+ } else {
3187
+ return deriveItemsFromChildren(props.children, opts);
3188
+ }
3189
+ }
3190
+ function deriveItemsFromItemsProp(items, opts) {
3191
+ var _items$map;
3192
+ var ItemComponent = opts.ItemComponent,
3193
+ SectionComponent = opts.SectionComponent;
3194
+ var disabledKeys = [];
3195
+ var transform = function transform(item) {
3196
+ if (typeof item === "string") {
3197
+ return React__default.createElement(ItemComponent, {
3198
+ key: item,
3199
+ value: item
3200
+ }, item);
3201
+ } else if ("children" in item) {
3202
+ return React__default.createElement(SectionComponent, {
3203
+ key: item.title,
3204
+ title: item.title
3205
+ }, item.children.map(function (x) {
3206
+ return transform(x);
3207
+ }));
3208
+ } else {
3209
+ var _item$label;
3210
+ if (item.isDisabled) {
3211
+ disabledKeys.push(item.value);
3212
+ }
3213
+ return React__default.createElement(ItemComponent, {
3214
+ key: item.value,
3215
+ value: item.value,
3216
+ textValue: item.textValue,
3217
+ isDisabled: item.isDisabled
3218
+ }, (_item$label = item.label) != null ? _item$label : item.value);
3219
+ }
3220
+ };
3221
+ return {
3222
+ items: (_items$map = items == null ? void 0 : items.map(function (x) {
3223
+ return transform(x);
3224
+ })) != null ? _items$map : [],
3225
+ disabledKeys: disabledKeys
3226
+ };
3227
+ }
3167
3228
  /**
3168
3229
  * Given children of a component like Select or Menu, derive the items
3169
3230
  * that we will pass into the Collections API. These will be
@@ -3240,6 +3301,28 @@ function deriveItemsFromChildren(children, opts) {
3240
3301
  disabledKeys: disabledKeys
3241
3302
  };
3242
3303
  }
3304
+ function useDerivedItems(props, opts) {
3305
+ var children = props.children;
3306
+ var itemPlumeType = opts.itemPlumeType,
3307
+ sectionPlumeType = opts.sectionPlumeType,
3308
+ invalidChildError = opts.invalidChildError,
3309
+ requireItemValue = opts.requireItemValue,
3310
+ ItemComponent = opts.ItemComponent,
3311
+ SectionComponent = opts.SectionComponent,
3312
+ itemsProp = opts.itemsProp;
3313
+ var items = itemsProp ? props[itemsProp] : undefined;
3314
+ return React__default.useMemo(function () {
3315
+ return deriveItemsFromProps(props, {
3316
+ itemPlumeType: itemPlumeType,
3317
+ sectionPlumeType: sectionPlumeType,
3318
+ invalidChildError: invalidChildError,
3319
+ requireItemValue: requireItemValue,
3320
+ itemsProp: itemsProp,
3321
+ ItemComponent: ItemComponent,
3322
+ SectionComponent: SectionComponent
3323
+ });
3324
+ }, [children, items, itemPlumeType, sectionPlumeType, invalidChildError, requireItemValue, ItemComponent, SectionComponent]);
3325
+ }
3243
3326
  function useDerivedItemsFromChildren(children, opts) {
3244
3327
  var itemPlumeType = opts.itemPlumeType,
3245
3328
  sectionPlumeType = opts.sectionPlumeType,
@@ -3790,18 +3873,20 @@ var COLLECTION_OPTS$1 = {
3790
3873
  * with the secret derived `_node` prop. That means Option and OptionGroup
3791
3874
  * render functions can assume that _node is passed in.
3792
3875
  */
3793
- function useAriaSelectProps(props) {
3876
+ function useAriaSelectProps(props, config) {
3794
3877
  var value = props.value,
3795
3878
  defaultValue = props.defaultValue,
3796
- children = props.children,
3797
3879
  onChange = props.onChange,
3798
3880
  rest = _objectWithoutPropertiesLoose(props, _excluded$6);
3799
- var _useDerivedItemsFromC = useDerivedItemsFromChildren(children, _extends({}, COLLECTION_OPTS$1, {
3881
+ var _useDerivedItems = useDerivedItems(props, _extends({}, COLLECTION_OPTS$1, {
3800
3882
  invalidChildError: "Can only use Select.Option and Select.OptionGroup as children to Select",
3801
- requireItemValue: true
3883
+ requireItemValue: true,
3884
+ ItemComponent: config.OptionComponent,
3885
+ SectionComponent: config.OptionGroupComponent,
3886
+ itemsProp: "options"
3802
3887
  })),
3803
- items = _useDerivedItemsFromC.items,
3804
- disabledKeys = _useDerivedItemsFromC.disabledKeys;
3888
+ items = _useDerivedItems.items,
3889
+ disabledKeys = _useDerivedItems.disabledKeys;
3805
3890
  var collectionChildRenderer = useCallback(function (child) {
3806
3891
  return renderAsCollectionChild(child, COLLECTION_OPTS$1);
3807
3892
  }, []);
@@ -3832,7 +3917,7 @@ function useSelect(plasmicClass, props, config, ref) {
3832
3917
  ref = null;
3833
3918
  }
3834
3919
  useEnsureSSRProvider();
3835
- var _useAriaSelectProps = useAriaSelectProps(props),
3920
+ var _useAriaSelectProps = useAriaSelectProps(props, config),
3836
3921
  ariaProps = _useAriaSelectProps.ariaProps;
3837
3922
  var placement = props.placement;
3838
3923
  var state = useSelectState(ariaProps);
@@ -3845,6 +3930,7 @@ function useSelect(plasmicClass, props, config, ref) {
3845
3930
  autoFocus = props.autoFocus,
3846
3931
  placeholder = props.placeholder,
3847
3932
  selectedContent = props.selectedContent;
3933
+ var canvasCtx = usePlasmicCanvasContext();
3848
3934
  var _useAriaSelect = useSelect$1(ariaProps, state, triggerRef),
3849
3935
  triggerPressProps = _useAriaSelect.triggerProps,
3850
3936
  menuProps = _useAriaSelect.menuProps;
@@ -3878,7 +3964,7 @@ function useSelect(plasmicClass, props, config, ref) {
3878
3964
  ref: rootRef
3879
3965
  }),
3880
3966
  wrapChildren: function wrapChildren(children) {
3881
- return createElement(Fragment, null, createElement(HiddenSelect, {
3967
+ return createElement(Fragment, null, !canvasCtx && createElement(HiddenSelect, {
3882
3968
  state: state,
3883
3969
  triggerRef: triggerRef,
3884
3970
  name: name,
@@ -3886,7 +3972,7 @@ function useSelect(plasmicClass, props, config, ref) {
3886
3972
  }), children);
3887
3973
  }
3888
3974
  }, _overrides[config.trigger] = {
3889
- props: mergeProps(triggerProps, {
3975
+ props: mergeProps(canvasCtx ? {} : triggerProps, {
3890
3976
  ref: triggerRef,
3891
3977
  autoFocus: autoFocus,
3892
3978
  disabled: !!isDisabled,
@@ -3978,13 +4064,14 @@ function ListBoxWrapper(props) {
3978
4064
  menuProps = props.menuProps,
3979
4065
  children = props.children;
3980
4066
  var ref = useRef(null);
4067
+ var canvasCtx = usePlasmicCanvasContext();
3981
4068
  var _useListBox = useListBox(_extends({}, menuProps, {
3982
4069
  isVirtualized: false,
3983
4070
  autoFocus: state.focusStrategy || true,
3984
4071
  disallowEmptySelection: true
3985
4072
  }), state, ref),
3986
4073
  listBoxProps = _useListBox.listBoxProps;
3987
- return cloneElement(children, mergeProps(children.props, listBoxProps, {
4074
+ return cloneElement(children, mergeProps(children.props, canvasCtx ? {} : listBoxProps, {
3988
4075
  style: noOutline(),
3989
4076
  ref: ref
3990
4077
  }));
@@ -4006,6 +4093,7 @@ function useSelectOption(plasmicClass, props, config, outerRef) {
4006
4093
  return getDefaultPlasmicProps(plasmicClass, props);
4007
4094
  }
4008
4095
  var children = props.children;
4096
+ var canvasCtx = usePlasmicCanvasContext();
4009
4097
  var rootRef = useRef(null);
4010
4098
  var onRef = mergeRefs(rootRef, outerRef);
4011
4099
  // We pass in the Node secretly as an undocumented prop from <Select />
@@ -4020,7 +4108,8 @@ function useSelectOption(plasmicClass, props, config, outerRef) {
4020
4108
  key: node.key,
4021
4109
  shouldSelectOnPressUp: true,
4022
4110
  shouldFocusOnHover: true,
4023
- isVirtualized: false
4111
+ isVirtualized: false,
4112
+ shouldUseVirtualFocus: !!canvasCtx
4024
4113
  }, state, rootRef),
4025
4114
  optionProps = _useAriaOption.optionProps,
4026
4115
  labelProps = _useAriaOption.labelProps;
@@ -4036,7 +4125,7 @@ function useSelectOption(plasmicClass, props, config, outerRef) {
4036
4125
  }));
4037
4126
  var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.labelSlot] = children, _extends2));
4038
4127
  var overrides = (_overrides = {}, _overrides[config.root] = {
4039
- props: mergeProps(optionProps, getStyleProps(props), {
4128
+ props: mergeProps(canvasCtx ? {} : optionProps, getStyleProps(props), {
4040
4129
  ref: onRef,
4041
4130
  style: noOutline()
4042
4131
  })
@@ -4347,7 +4436,8 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissabl
4347
4436
  def: config.isPlacedRightVariant,
4348
4437
  active: placementAxis === "right"
4349
4438
  }));
4350
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.contentSlot] = createElement(FocusScope, {
4439
+ var canvasCtx = usePlasmicCanvasContext();
4440
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.contentSlot] = canvasCtx ? children : createElement(FocusScope, {
4351
4441
  restoreFocus: true
4352
4442
  }, createElement(DismissButton, {
4353
4443
  onDismiss: state.close