@teselagen/ui 0.3.73 → 0.3.74

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/index.cjs.js CHANGED
@@ -63,6 +63,7 @@ const ReactDOM = require("react-dom");
63
63
  const reduxForm = require("redux-form");
64
64
  const reactRedux = require("react-redux");
65
65
  const select = require("@blueprintjs/select");
66
+ const redux = require("redux");
66
67
  const datetime = require("@blueprintjs/datetime");
67
68
  function _interopNamespaceDefault(e2) {
68
69
  const n2 = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -17117,25 +17118,16 @@ var toString$6 = {}.toString;
17117
17118
  var _cof = /* @__PURE__ */ __name(function(it) {
17118
17119
  return toString$6.call(it).slice(8, -1);
17119
17120
  }, "_cof");
17120
- var _iobject;
17121
- var hasRequired_iobject;
17122
- function require_iobject() {
17123
- if (hasRequired_iobject)
17124
- return _iobject;
17125
- hasRequired_iobject = 1;
17126
- var cof2 = _cof;
17127
- _iobject = Object("z").propertyIsEnumerable(0) ? Object : function(it) {
17128
- return cof2(it) == "String" ? it.split("") : Object(it);
17129
- };
17130
- return _iobject;
17131
- }
17132
- __name(require_iobject, "require_iobject");
17121
+ var cof$2 = _cof;
17122
+ var _iobject = Object("z").propertyIsEnumerable(0) ? Object : function(it) {
17123
+ return cof$2(it) == "String" ? it.split("") : Object(it);
17124
+ };
17133
17125
  var _defined = /* @__PURE__ */ __name(function(it) {
17134
17126
  if (it == void 0)
17135
17127
  throw TypeError("Can't call method on " + it);
17136
17128
  return it;
17137
17129
  }, "_defined");
17138
- var IObject = require_iobject();
17130
+ var IObject = _iobject;
17139
17131
  var defined$2 = _defined;
17140
17132
  var _toIobject = /* @__PURE__ */ __name(function(it) {
17141
17133
  return IObject(defined$2(it));
@@ -17256,7 +17248,7 @@ function require_objectAssign() {
17256
17248
  var gOPS2 = _objectGops;
17257
17249
  var pIE2 = require_objectPie();
17258
17250
  var toObject2 = _toObject;
17259
- var IObject2 = require_iobject();
17251
+ var IObject2 = _iobject;
17260
17252
  var $assign = Object.assign;
17261
17253
  _objectAssign = !$assign || _fails(function() {
17262
17254
  var A2 = {};
@@ -39054,27 +39046,51 @@ __publicField(_TgSelect, "defaultProps", {
39054
39046
  value: void 0
39055
39047
  });
39056
39048
  let TgSelect = _TgSelect;
39057
- const TgSelect$1 = withProps((props) => {
39058
- const { multi, value, options } = props;
39059
- let optionsToRet = options;
39060
- if (multi && value) {
39061
- const valArray = getValueArray(value);
39062
- optionsToRet = options.filter((op) => {
39063
- const isOptionSelected = valArray.some((val) => {
39064
- if (!val)
39065
- return false;
39066
- const matching = lodashExports.isEqual(val.value, op.value);
39067
- return matching;
39049
+ const withAsyncOptions = /* @__PURE__ */ __name((Component) => (props) => {
39050
+ const _a2 = props, { loadOptions, options } = _a2, rest = __objRest(_a2, ["loadOptions", "options"]);
39051
+ const [asyncOptions, setAsyncOptions] = React$1.useState([]);
39052
+ const [isLoading, setLoading] = React$1.useState(false);
39053
+ React$1.useEffect(() => {
39054
+ if (loadOptions) {
39055
+ setLoading(true);
39056
+ loadOptions().then((options2) => {
39057
+ setAsyncOptions(options2);
39058
+ setLoading(false);
39068
39059
  });
39069
- return !isOptionSelected;
39070
- });
39071
- }
39072
- return {
39073
- // unfilteredOptions is needed for finding selected items
39074
- unfilteredOptions: options,
39075
- options: optionsToRet
39076
- };
39077
- })(TgSelect);
39060
+ }
39061
+ }, [loadOptions]);
39062
+ return /* @__PURE__ */ React$1.createElement(
39063
+ Component,
39064
+ __spreadProps(__spreadValues({}, rest), {
39065
+ isLoading: isLoading || rest.isLoading,
39066
+ options: loadOptions ? asyncOptions : options
39067
+ })
39068
+ );
39069
+ }, "withAsyncOptions");
39070
+ const TgSelect$1 = redux.compose(
39071
+ withAsyncOptions,
39072
+ withProps((props) => {
39073
+ const { multi, value, options = [] } = props;
39074
+ let optionsToRet = options;
39075
+ if (multi && value) {
39076
+ const valArray = getValueArray(value);
39077
+ optionsToRet = options.filter((op) => {
39078
+ const isOptionSelected = valArray.some((val) => {
39079
+ if (!val)
39080
+ return false;
39081
+ const matching = lodashExports.isEqual(val.value, op.value);
39082
+ return matching;
39083
+ });
39084
+ return !isOptionSelected;
39085
+ });
39086
+ }
39087
+ return {
39088
+ // unfilteredOptions is needed for finding selected items
39089
+ unfilteredOptions: options,
39090
+ options: optionsToRet
39091
+ };
39092
+ })
39093
+ )(TgSelect);
39078
39094
  const itemDisabled = /* @__PURE__ */ __name((i) => i.disabled, "itemDisabled");
39079
39095
  const noResultsDefault = /* @__PURE__ */ React$1.createElement("div", null, "No Results...");
39080
39096
  const renderCreateNewOption$1 = /* @__PURE__ */ __name((query, active3, handleClick) => /* @__PURE__ */ React$1.createElement(
package/index.es.js CHANGED
@@ -63,6 +63,7 @@ import ReactDOM, { unstable_batchedUpdates, findDOMNode as findDOMNode$1 } from
63
63
  import { FormName, formValueSelector, change, Field, reduxForm, SubmissionError, destroy, initialize, Fields } from "redux-form";
64
64
  import { connect, useStore } from "react-redux";
65
65
  import { getCreateNewItem, MultiSelect, Suggest } from "@blueprintjs/select";
66
+ import { compose as compose$1 } from "redux";
66
67
  import { DateRangeInput, DateInput } from "@blueprintjs/datetime";
67
68
  const blueprint = "";
68
69
  const blueprintDatetime = "";
@@ -17099,25 +17100,16 @@ var toString$6 = {}.toString;
17099
17100
  var _cof = /* @__PURE__ */ __name(function(it) {
17100
17101
  return toString$6.call(it).slice(8, -1);
17101
17102
  }, "_cof");
17102
- var _iobject;
17103
- var hasRequired_iobject;
17104
- function require_iobject() {
17105
- if (hasRequired_iobject)
17106
- return _iobject;
17107
- hasRequired_iobject = 1;
17108
- var cof2 = _cof;
17109
- _iobject = Object("z").propertyIsEnumerable(0) ? Object : function(it) {
17110
- return cof2(it) == "String" ? it.split("") : Object(it);
17111
- };
17112
- return _iobject;
17113
- }
17114
- __name(require_iobject, "require_iobject");
17103
+ var cof$2 = _cof;
17104
+ var _iobject = Object("z").propertyIsEnumerable(0) ? Object : function(it) {
17105
+ return cof$2(it) == "String" ? it.split("") : Object(it);
17106
+ };
17115
17107
  var _defined = /* @__PURE__ */ __name(function(it) {
17116
17108
  if (it == void 0)
17117
17109
  throw TypeError("Can't call method on " + it);
17118
17110
  return it;
17119
17111
  }, "_defined");
17120
- var IObject = require_iobject();
17112
+ var IObject = _iobject;
17121
17113
  var defined$2 = _defined;
17122
17114
  var _toIobject = /* @__PURE__ */ __name(function(it) {
17123
17115
  return IObject(defined$2(it));
@@ -17238,7 +17230,7 @@ function require_objectAssign() {
17238
17230
  var gOPS2 = _objectGops;
17239
17231
  var pIE2 = require_objectPie();
17240
17232
  var toObject2 = _toObject;
17241
- var IObject2 = require_iobject();
17233
+ var IObject2 = _iobject;
17242
17234
  var $assign = Object.assign;
17243
17235
  _objectAssign = !$assign || _fails(function() {
17244
17236
  var A2 = {};
@@ -39036,27 +39028,51 @@ __publicField(_TgSelect, "defaultProps", {
39036
39028
  value: void 0
39037
39029
  });
39038
39030
  let TgSelect = _TgSelect;
39039
- const TgSelect$1 = withProps((props) => {
39040
- const { multi, value, options } = props;
39041
- let optionsToRet = options;
39042
- if (multi && value) {
39043
- const valArray = getValueArray(value);
39044
- optionsToRet = options.filter((op) => {
39045
- const isOptionSelected = valArray.some((val) => {
39046
- if (!val)
39047
- return false;
39048
- const matching = lodashExports.isEqual(val.value, op.value);
39049
- return matching;
39031
+ const withAsyncOptions = /* @__PURE__ */ __name((Component2) => (props) => {
39032
+ const _a2 = props, { loadOptions, options } = _a2, rest = __objRest(_a2, ["loadOptions", "options"]);
39033
+ const [asyncOptions, setAsyncOptions] = useState([]);
39034
+ const [isLoading, setLoading] = useState(false);
39035
+ useEffect(() => {
39036
+ if (loadOptions) {
39037
+ setLoading(true);
39038
+ loadOptions().then((options2) => {
39039
+ setAsyncOptions(options2);
39040
+ setLoading(false);
39050
39041
  });
39051
- return !isOptionSelected;
39052
- });
39053
- }
39054
- return {
39055
- // unfilteredOptions is needed for finding selected items
39056
- unfilteredOptions: options,
39057
- options: optionsToRet
39058
- };
39059
- })(TgSelect);
39042
+ }
39043
+ }, [loadOptions]);
39044
+ return /* @__PURE__ */ React__default.createElement(
39045
+ Component2,
39046
+ __spreadProps(__spreadValues({}, rest), {
39047
+ isLoading: isLoading || rest.isLoading,
39048
+ options: loadOptions ? asyncOptions : options
39049
+ })
39050
+ );
39051
+ }, "withAsyncOptions");
39052
+ const TgSelect$1 = compose$1(
39053
+ withAsyncOptions,
39054
+ withProps((props) => {
39055
+ const { multi, value, options = [] } = props;
39056
+ let optionsToRet = options;
39057
+ if (multi && value) {
39058
+ const valArray = getValueArray(value);
39059
+ optionsToRet = options.filter((op) => {
39060
+ const isOptionSelected = valArray.some((val) => {
39061
+ if (!val)
39062
+ return false;
39063
+ const matching = lodashExports.isEqual(val.value, op.value);
39064
+ return matching;
39065
+ });
39066
+ return !isOptionSelected;
39067
+ });
39068
+ }
39069
+ return {
39070
+ // unfilteredOptions is needed for finding selected items
39071
+ unfilteredOptions: options,
39072
+ options: optionsToRet
39073
+ };
39074
+ })
39075
+ )(TgSelect);
39060
39076
  const itemDisabled = /* @__PURE__ */ __name((i) => i.disabled, "itemDisabled");
39061
39077
  const noResultsDefault = /* @__PURE__ */ React__default.createElement("div", null, "No Results...");
39062
39078
  const renderCreateNewOption$1 = /* @__PURE__ */ __name((query, active3, handleClick) => /* @__PURE__ */ React__default.createElement(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/ui",
3
- "version": "0.3.73",
3
+ "version": "0.3.74",
4
4
  "main": "./src/index.js",
5
5
  "exports": {
6
6
  ".": {
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-empty-function */
2
2
  import { MultiSelect, getCreateNewItem } from "@blueprintjs/select";
3
3
  import { Keys, Button, MenuItem, Tag } from "@blueprintjs/core";
4
- import React from "react";
4
+ import React, { useEffect, useState } from "react";
5
5
  import { filter, isEqual } from "lodash";
6
6
  import classNames from "classnames";
7
7
  import "./style.css";
@@ -10,6 +10,7 @@ import fuzzysearch from "fuzzysearch";
10
10
  import getTextFromEl from "../utils/getTextFromEl";
11
11
  import { getTagColorStyle, getTagProps } from "../utils/tagUtils";
12
12
  import popoverOverflowModifiers from "../utils/popoverOverflowModifiers";
13
+ import { compose } from "redux";
13
14
 
14
15
  class TgSelect extends React.Component {
15
16
  constructor(props) {
@@ -384,27 +385,54 @@ class TgSelect extends React.Component {
384
385
  );
385
386
  }
386
387
  }
387
- export default withProps(props => {
388
- const { multi, value, options } = props;
389
- let optionsToRet = options;
390
- // based on incoming value hide those selected options from the option list
391
- if (multi && value) {
392
- const valArray = getValueArray(value);
393
- optionsToRet = options.filter(op => {
394
- const isOptionSelected = valArray.some(val => {
395
- if (!val) return false;
396
- const matching = isEqual(val.value, op.value);
397
- return matching;
388
+
389
+ const withAsyncOptions = Component => props => {
390
+ const { loadOptions, options, ...rest } = props;
391
+ const [asyncOptions, setAsyncOptions] = useState([]);
392
+ const [isLoading, setLoading] = useState(false);
393
+ useEffect(() => {
394
+ if (loadOptions) {
395
+ setLoading(true);
396
+ loadOptions().then(options => {
397
+ setAsyncOptions(options);
398
+ setLoading(false);
398
399
  });
399
- return !isOptionSelected;
400
- });
401
- }
402
- return {
403
- // unfilteredOptions is needed for finding selected items
404
- unfilteredOptions: options,
405
- options: optionsToRet
406
- };
407
- })(TgSelect);
400
+ }
401
+ }, [loadOptions]);
402
+
403
+ return (
404
+ <Component
405
+ {...rest}
406
+ isLoading={isLoading || rest.isLoading}
407
+ options={loadOptions ? asyncOptions : options}
408
+ />
409
+ );
410
+ };
411
+
412
+ export default compose(
413
+ withAsyncOptions,
414
+ withProps(props => {
415
+ const { multi, value, options = [] } = props;
416
+ let optionsToRet = options;
417
+ // based on incoming value hide those selected options from the option list
418
+ if (multi && value) {
419
+ const valArray = getValueArray(value);
420
+ optionsToRet = options.filter(op => {
421
+ const isOptionSelected = valArray.some(val => {
422
+ if (!val) return false;
423
+ const matching = isEqual(val.value, op.value);
424
+ return matching;
425
+ });
426
+ return !isOptionSelected;
427
+ });
428
+ }
429
+ return {
430
+ // unfilteredOptions is needed for finding selected items
431
+ unfilteredOptions: options,
432
+ options: optionsToRet
433
+ };
434
+ })
435
+ )(TgSelect);
408
436
 
409
437
  const itemDisabled = i => i.disabled;
410
438
  const noResultsDefault = <div>No Results...</div>;
@@ -440,11 +468,13 @@ export const itemListPredicate = (_queryString = "", items, isSimpleSearch) => {
440
468
  text: item.toLowerCase
441
469
  ? item.toLowerCase()
442
470
  : item.label
443
- ? item.label.toLowerCase
444
- ? item.label.toLowerCase()
445
- : getTextFromEl(item.label).toLowerCase()
446
- : (item.value && item.value.toLowerCase && item.value.toLowerCase()) ||
447
- ""
471
+ ? item.label.toLowerCase
472
+ ? item.label.toLowerCase()
473
+ : getTextFromEl(item.label).toLowerCase()
474
+ : (item.value &&
475
+ item.value.toLowerCase &&
476
+ item.value.toLowerCase()) ||
477
+ ""
448
478
  };
449
479
  });
450
480
  let toRet = toSearchArr.filter(({ text }) =>