@rpg-engine/long-bow 0.5.61 → 0.5.65

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.
@@ -9,5 +9,6 @@ export interface IDropdownProps {
9
9
  width?: string;
10
10
  onChange: (value: string) => void;
11
11
  defaultValue?: string;
12
+ triggerChangeOnMount?: boolean;
12
13
  }
13
14
  export declare const Dropdown: React.FC<IDropdownProps>;
@@ -17,7 +17,6 @@ var ReactDOM = _interopDefault(require('react-dom'));
17
17
  var lodash = require('lodash');
18
18
  var mobxReactLite = require('mobx-react-lite');
19
19
  var uuid = require('uuid');
20
- var reactSpinners = require('react-spinners');
21
20
  var ai = require('react-icons/ai');
22
21
  require('rpgui/rpgui.css');
23
22
  require('rpgui/rpgui.min.js');
@@ -14798,43 +14797,57 @@ var ItemTypes = /*#__PURE__*/styled__default.div.withConfig({
14798
14797
  })(["display:flex;overflow-y:scroll;overflow-x:hidden;width:max-content;flex-direction:column;padding-right:5px;@media (max-width:", "){overflow-x:scroll;overflow-y:hidden;padding-right:0;width:100%;}"], mobilePortrait.width);
14799
14798
 
14800
14799
  var Dropdown = function Dropdown(_ref) {
14801
- var _options$, _options$find, _options$2;
14802
14800
  var options = _ref.options,
14803
14801
  width = _ref.width,
14804
14802
  onChange = _ref.onChange,
14805
- defaultValue = _ref.defaultValue;
14803
+ defaultValue = _ref.defaultValue,
14804
+ _ref$triggerChangeOnM = _ref.triggerChangeOnMount,
14805
+ triggerChangeOnMount = _ref$triggerChangeOnM === void 0 ? true : _ref$triggerChangeOnM;
14806
14806
  var dropdownId = uuid.v4();
14807
- var _useState = React.useState(defaultValue || (options == null ? void 0 : (_options$ = options[0]) == null ? void 0 : _options$.value)),
14807
+ var _useState = React.useState(defaultValue || ''),
14808
14808
  selectedValue = _useState[0],
14809
14809
  setSelectedValue = _useState[1];
14810
- var _useState2 = React.useState((options == null ? void 0 : (_options$find = options.find(function (option) {
14811
- return option.value === defaultValue;
14812
- })) == null ? void 0 : _options$find.option) || (options == null ? void 0 : (_options$2 = options[0]) == null ? void 0 : _options$2.option)),
14810
+ var _useState2 = React.useState(''),
14813
14811
  selectedOption = _useState2[0],
14814
14812
  setSelectedOption = _useState2[1];
14815
14813
  var _useState3 = React.useState(false),
14816
14814
  opened = _useState3[0],
14817
14815
  setOpened = _useState3[1];
14816
+ React.useEffect(function () {
14817
+ var firstOption = options[0];
14818
+ if (firstOption) {
14819
+ var change = !selectedValue;
14820
+ if (!change) {
14821
+ change = options.filter(function (o) {
14822
+ return o.value === selectedValue;
14823
+ }).length < 1;
14824
+ }
14825
+ /**
14826
+ * make a selection if there is no selected value already present
14827
+ * or if there is a selected value but its not in new options
14828
+ */
14829
+ if (change) {
14830
+ setSelectedValue(firstOption.value);
14831
+ setSelectedOption(firstOption.option);
14832
+ }
14833
+ }
14834
+ }, [options]);
14818
14835
  React.useEffect(function () {
14819
14836
  if (defaultValue) {
14820
- var _options$find2;
14821
- setSelectedValue(defaultValue);
14822
- setSelectedOption( //@ts-ignore
14823
- options == null ? void 0 : (_options$find2 = options.find(function (option) {
14824
- return option.value === defaultValue;
14825
- })) == null ? void 0 : _options$find2.option);
14826
- } else if ((options == null ? void 0 : options.length) > 0) {
14827
- setSelectedValue(options[0].value);
14828
- setSelectedOption(options[0].option);
14837
+ var option = options.find(function (o) {
14838
+ return o.value === defaultValue;
14839
+ });
14840
+ if (option) {
14841
+ setSelectedValue(option.value);
14842
+ setSelectedOption(option.option);
14843
+ }
14829
14844
  }
14830
- }, [options, defaultValue]);
14831
- var handleSelection = function handleSelection(value, option) {
14832
- if (value !== selectedValue) {
14833
- setSelectedValue(value);
14834
- setSelectedOption(option);
14835
- onChange(value);
14845
+ }, [defaultValue]);
14846
+ React.useEffect(function () {
14847
+ if (selectedValue && triggerChangeOnMount) {
14848
+ onChange(selectedValue);
14836
14849
  }
14837
- };
14850
+ }, [selectedValue]);
14838
14851
  return React__default.createElement(Container$d, {
14839
14852
  onMouseLeave: function onMouseLeave() {
14840
14853
  return setOpened(false);
@@ -14848,43 +14861,33 @@ var Dropdown = function Dropdown(_ref) {
14848
14861
  return !prev;
14849
14862
  });
14850
14863
  }
14851
- }, React__default.createElement(DropdownDisplay, null, React__default.createElement(DropdownLabel, null, "\u25BC"), " ", selectedOption, !options.length && React__default.createElement(reactSpinners.BeatLoader, {
14852
- size: 4,
14853
- color: uiColors.white
14854
- }))), React__default.createElement(DropdownOptions, {
14864
+ }, React__default.createElement("label", null, "\u25BC"), " ", selectedOption), React__default.createElement(DropdownOptions, {
14855
14865
  className: "rpgui-dropdown-imp",
14856
14866
  opened: opened
14857
- }, options == null ? void 0 : options.map(function (option) {
14867
+ }, options.map(function (option) {
14858
14868
  return React__default.createElement("li", {
14859
14869
  key: option.id,
14860
14870
  onPointerUp: function onPointerUp() {
14861
- handleSelection(option.value, option.option);
14871
+ setSelectedValue(option.value);
14872
+ setSelectedOption(option.option);
14862
14873
  setOpened(false);
14863
14874
  }
14864
14875
  }, option.option);
14865
14876
  })));
14866
14877
  };
14867
- var DropdownDisplay = /*#__PURE__*/styled__default.span.withConfig({
14868
- displayName: "Dropdown__DropdownDisplay",
14869
- componentId: "sc-8arn65-0"
14870
- })(["display:flex;flex-wrap:wrap;justify-content:start;align-items:center;"]);
14871
- var DropdownLabel = /*#__PURE__*/styled__default.label.withConfig({
14872
- displayName: "Dropdown__DropdownLabel",
14873
- componentId: "sc-8arn65-1"
14874
- })(["margin-right:0.5rem;"]);
14875
14878
  var Container$d = /*#__PURE__*/styled__default.div.withConfig({
14876
14879
  displayName: "Dropdown__Container",
14877
- componentId: "sc-8arn65-2"
14880
+ componentId: "sc-8arn65-0"
14878
14881
  })(["position:relative;width:", ";"], function (props) {
14879
14882
  return props.width || '100%';
14880
14883
  });
14881
14884
  var DropdownSelect = /*#__PURE__*/styled__default.p.withConfig({
14882
14885
  displayName: "Dropdown__DropdownSelect",
14883
- componentId: "sc-8arn65-3"
14886
+ componentId: "sc-8arn65-1"
14884
14887
  })(["width:100%;box-sizing:border-box;label{display:inline-block;transform:translateY(-2px);}"]);
14885
14888
  var DropdownOptions = /*#__PURE__*/styled__default.ul.withConfig({
14886
14889
  displayName: "Dropdown__DropdownOptions",
14887
- componentId: "sc-8arn65-4"
14890
+ componentId: "sc-8arn65-2"
14888
14891
  })(["position:absolute;width:100%;max-height:300px;overflow-y:auto;display:", ";box-sizing:border-box;@media (max-width:768px){padding:8px 0;}"], function (props) {
14889
14892
  return props.opened ? 'block' : 'none';
14890
14893
  });