@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,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,57 @@ 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
- defaultValue = _ref.defaultValue;
14797
+ defaultValue = _ref.defaultValue,
14798
+ _ref$triggerChangeOnM = _ref.triggerChangeOnMount,
14799
+ triggerChangeOnMount = _ref$triggerChangeOnM === void 0 ? true : _ref$triggerChangeOnM;
14800
14800
  var dropdownId = v4();
14801
- var _useState = useState(defaultValue || (options == null ? void 0 : (_options$ = options[0]) == null ? void 0 : _options$.value)),
14801
+ var _useState = useState(defaultValue || ''),
14802
14802
  selectedValue = _useState[0],
14803
14803
  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)),
14804
+ var _useState2 = useState(''),
14807
14805
  selectedOption = _useState2[0],
14808
14806
  setSelectedOption = _useState2[1];
14809
14807
  var _useState3 = useState(false),
14810
14808
  opened = _useState3[0],
14811
14809
  setOpened = _useState3[1];
14810
+ useEffect(function () {
14811
+ var firstOption = options[0];
14812
+ if (firstOption) {
14813
+ var change = !selectedValue;
14814
+ if (!change) {
14815
+ change = options.filter(function (o) {
14816
+ return o.value === selectedValue;
14817
+ }).length < 1;
14818
+ }
14819
+ /**
14820
+ * make a selection if there is no selected value already present
14821
+ * or if there is a selected value but its not in new options
14822
+ */
14823
+ if (change) {
14824
+ setSelectedValue(firstOption.value);
14825
+ setSelectedOption(firstOption.option);
14826
+ }
14827
+ }
14828
+ }, [options]);
14812
14829
  useEffect(function () {
14813
14830
  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);
14831
+ var option = options.find(function (o) {
14832
+ return o.value === defaultValue;
14833
+ });
14834
+ if (option) {
14835
+ setSelectedValue(option.value);
14836
+ setSelectedOption(option.option);
14837
+ }
14823
14838
  }
14824
- }, [options, defaultValue]);
14825
- var handleSelection = function handleSelection(value, option) {
14826
- if (value !== selectedValue) {
14827
- setSelectedValue(value);
14828
- setSelectedOption(option);
14829
- onChange(value);
14839
+ }, [defaultValue]);
14840
+ useEffect(function () {
14841
+ if (selectedValue && triggerChangeOnMount) {
14842
+ onChange(selectedValue);
14830
14843
  }
14831
- };
14844
+ }, [selectedValue]);
14832
14845
  return React.createElement(Container$d, {
14833
14846
  onMouseLeave: function onMouseLeave() {
14834
14847
  return setOpened(false);
@@ -14842,43 +14855,33 @@ var Dropdown = function Dropdown(_ref) {
14842
14855
  return !prev;
14843
14856
  });
14844
14857
  }
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, {
14858
+ }, React.createElement("label", null, "\u25BC"), " ", selectedOption), React.createElement(DropdownOptions, {
14849
14859
  className: "rpgui-dropdown-imp",
14850
14860
  opened: opened
14851
- }, options == null ? void 0 : options.map(function (option) {
14861
+ }, options.map(function (option) {
14852
14862
  return React.createElement("li", {
14853
14863
  key: option.id,
14854
14864
  onPointerUp: function onPointerUp() {
14855
- handleSelection(option.value, option.option);
14865
+ setSelectedValue(option.value);
14866
+ setSelectedOption(option.option);
14856
14867
  setOpened(false);
14857
14868
  }
14858
14869
  }, option.option);
14859
14870
  })));
14860
14871
  };
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
14872
  var Container$d = /*#__PURE__*/styled.div.withConfig({
14870
14873
  displayName: "Dropdown__Container",
14871
- componentId: "sc-8arn65-2"
14874
+ componentId: "sc-8arn65-0"
14872
14875
  })(["position:relative;width:", ";"], function (props) {
14873
14876
  return props.width || '100%';
14874
14877
  });
14875
14878
  var DropdownSelect = /*#__PURE__*/styled.p.withConfig({
14876
14879
  displayName: "Dropdown__DropdownSelect",
14877
- componentId: "sc-8arn65-3"
14880
+ componentId: "sc-8arn65-1"
14878
14881
  })(["width:100%;box-sizing:border-box;label{display:inline-block;transform:translateY(-2px);}"]);
14879
14882
  var DropdownOptions = /*#__PURE__*/styled.ul.withConfig({
14880
14883
  displayName: "Dropdown__DropdownOptions",
14881
- componentId: "sc-8arn65-4"
14884
+ componentId: "sc-8arn65-2"
14882
14885
  })(["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
14886
  return props.opened ? 'block' : 'none';
14884
14887
  });