@rpg-engine/long-bow 0.5.61 → 0.5.62

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