@nulogy/components 8.2.2 → 8.3.0

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/dist/main.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('styled-components'), require('@babel/runtime/helpers/typeof'), require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass'), require('@babel/runtime/helpers/defineProperty'), require('object-assign'), require('@nulogy/icons'), require('@babel/runtime/helpers/extends'), require('@babel/runtime/helpers/assertThisInitialized'), require('@babel/runtime/helpers/inheritsLoose'), require('prop-types'), require('react-fast-compare'), require('warning'), require('@babel/runtime/helpers/slicedToArray'), require('@babel/runtime/helpers/objectWithoutPropertiesLoose'), require('deep-equal'), require('create-react-context'), require('react-resize-detector'), require('react-windowed-select'), require('react-dom'), require('exenv'), require('smoothscroll-polyfill'), require('classnames'), require('@babel/runtime/helpers/toConsumableArray'), require('react-input-autosize'), require('@babel/runtime/helpers/taggedTemplateLiteral')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react', 'styled-components', '@babel/runtime/helpers/typeof', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass', '@babel/runtime/helpers/defineProperty', 'object-assign', '@nulogy/icons', '@babel/runtime/helpers/extends', '@babel/runtime/helpers/assertThisInitialized', '@babel/runtime/helpers/inheritsLoose', 'prop-types', 'react-fast-compare', 'warning', '@babel/runtime/helpers/slicedToArray', '@babel/runtime/helpers/objectWithoutPropertiesLoose', 'deep-equal', 'create-react-context', 'react-resize-detector', 'react-windowed-select', 'react-dom', 'exenv', 'smoothscroll-polyfill', 'classnames', '@babel/runtime/helpers/toConsumableArray', 'react-input-autosize', '@babel/runtime/helpers/taggedTemplateLiteral'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.NDSComponents = {}, global.React, global.styled, global.typeof, global.classCallCheck, global.createClass, global.defineProperty, global.assign, global.icons, global.extends, global.assertThisInitialized, global.inheritsLoose, global.PropTypes, global.isEqual, global.warning, global.slicedToArray, global.objectWithoutPropertiesLoose, global.deepEqual, global.createReactContext, global.ReactResizeDetector, global.components, global.reactDom, global.exenv, global.smoothscroll, global.t, null, global.AutosizeInput));
5
- }(this, (function (exports, React, styled, _typeof$1, _classCallCheck$1, _createClass$1, _defineProperty$1, assign$1, icons, _extends$4, _assertThisInitialized$2, _inheritsLoose$2, PropTypes, isEqual$2, warning$1, _slicedToArray$1, _objectWithoutPropertiesLoose$2, deepEqual, createContext, ReactResizeDetector, WindowedSelect, reactDom, exenv, smoothscroll, t, toConsumableArray, AutosizeInput) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('styled-components'), require('@babel/runtime/helpers/typeof'), require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass'), require('@babel/runtime/helpers/defineProperty'), require('object-assign'), require('@nulogy/icons'), require('@babel/runtime/helpers/extends'), require('@babel/runtime/helpers/assertThisInitialized'), require('@babel/runtime/helpers/inheritsLoose'), require('prop-types'), require('react-fast-compare'), require('warning'), require('@babel/runtime/helpers/slicedToArray'), require('@babel/runtime/helpers/objectWithoutPropertiesLoose'), require('deep-equal'), require('create-react-context'), require('react-resize-detector'), require('react-windowed-select'), require('regenerator-runtime'), require('react-dom'), require('exenv'), require('smoothscroll-polyfill'), require('classnames'), require('@babel/runtime/helpers/toConsumableArray'), require('react-input-autosize'), require('@babel/runtime/helpers/taggedTemplateLiteral')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react', 'styled-components', '@babel/runtime/helpers/typeof', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass', '@babel/runtime/helpers/defineProperty', 'object-assign', '@nulogy/icons', '@babel/runtime/helpers/extends', '@babel/runtime/helpers/assertThisInitialized', '@babel/runtime/helpers/inheritsLoose', 'prop-types', 'react-fast-compare', 'warning', '@babel/runtime/helpers/slicedToArray', '@babel/runtime/helpers/objectWithoutPropertiesLoose', 'deep-equal', 'create-react-context', 'react-resize-detector', 'react-windowed-select', 'regenerator-runtime', 'react-dom', 'exenv', 'smoothscroll-polyfill', 'classnames', '@babel/runtime/helpers/toConsumableArray', 'react-input-autosize', '@babel/runtime/helpers/taggedTemplateLiteral'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.NDSComponents = {}, global.React, global.styled, global.typeof, global.classCallCheck, global.createClass, global.defineProperty, global.assign, global.icons, global.extends, global.assertThisInitialized, global.inheritsLoose, global.PropTypes, global.isEqual, global.warning, global.slicedToArray, global.objectWithoutPropertiesLoose, global.deepEqual, global.createReactContext, global.ReactResizeDetector, global.components, global.regeneratorRuntime, global.reactDom, global.exenv, global.smoothscroll, global.t, null, global.AutosizeInput));
5
+ }(this, (function (exports, React, styled, _typeof$1, _classCallCheck$1, _createClass$1, _defineProperty$1, assign$1, icons, _extends$4, _assertThisInitialized$2, _inheritsLoose$2, PropTypes, isEqual$2, warning$1, _slicedToArray$1, _objectWithoutPropertiesLoose$2, deepEqual, createContext, ReactResizeDetector, WindowedSelect, regeneratorRuntime, reactDom, exenv, smoothscroll, t, toConsumableArray, AutosizeInput) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -47,6 +47,7 @@
47
47
  var createContext__default = /*#__PURE__*/_interopDefaultLegacy(createContext);
48
48
  var ReactResizeDetector__default = /*#__PURE__*/_interopDefaultLegacy(ReactResizeDetector);
49
49
  var WindowedSelect__default = /*#__PURE__*/_interopDefaultLegacy(WindowedSelect);
50
+ var regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(regeneratorRuntime);
50
51
  var reactDom__default = /*#__PURE__*/_interopDefaultLegacy(reactDom);
51
52
  var exenv__default = /*#__PURE__*/_interopDefaultLegacy(exenv);
52
53
  var smoothscroll__default = /*#__PURE__*/_interopDefaultLegacy(smoothscroll);
@@ -11737,6 +11738,16 @@
11737
11738
  t[p[i]] = s[p[i]];
11738
11739
  }
11739
11740
  return t;
11741
+ }
11742
+
11743
+ function __awaiter(thisArg, _arguments, P, generator) {
11744
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11745
+ return new (P || (P = Promise))(function (resolve, reject) {
11746
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11747
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11748
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11749
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11750
+ });
11740
11751
  }
11741
11752
 
11742
11753
  var prefix = "random-id-";
@@ -22982,6 +22993,8 @@
22982
22993
  }), /*#__PURE__*/React__default['default'].createElement(WindowedSelect.components.Option, Object.assign({}, props)));
22983
22994
  };
22984
22995
 
22996
+ var regenerator = regeneratorRuntime__default['default'];
22997
+
22985
22998
  var getBorderColor = function getBorderColor(_ref) {
22986
22999
  var errored = _ref.errored,
22987
23000
  disabled = _ref.disabled,
@@ -23195,6 +23208,20 @@
23195
23208
  };
23196
23209
  };
23197
23210
 
23211
+ var extractValuesFromCsvString = function extractValuesFromCsvString(csv) {
23212
+ var quoteRegEx = /(["'])(?:(?=(\\?))\2.)*?\1/gim;
23213
+ var matchedValues = csv.match(quoteRegEx) || [];
23214
+ var quotedValues = matchedValues.map(function (str) {
23215
+ return str.replace(/(["',])/g, "");
23216
+ });
23217
+ var values = Array.from(new Set(csv.replace(quoteRegEx, "").split(",").map(function (value) {
23218
+ return value.trim();
23219
+ }).filter(function (str) {
23220
+ return str.length > 0;
23221
+ }).concat(quotedValues)));
23222
+ return values;
23223
+ };
23224
+
23198
23225
  var SelectControl = function SelectControl(props) {
23199
23226
  // eslint-disable-next-line react/prop-types
23200
23227
  var isFocused = props.isFocused;
@@ -23267,61 +23294,7 @@
23267
23294
  components: undefined,
23268
23295
  closeMenuOnSelect: true
23269
23296
  };
23270
-
23271
- var checkOptionsAreValid = function checkOptionsAreValid(options) {
23272
- if (options && process.env.NODE_ENV === "development") {
23273
- var uniq = function uniq(a) {
23274
- return Array.from(new Set(a));
23275
- };
23276
-
23277
- var uniqueValues = uniq(options.map(function (_ref) {
23278
- var value = _ref.value;
23279
- return value === null ? "_null_" : value;
23280
- }));
23281
-
23282
- if (uniqueValues.length < options.length) {
23283
- console.warn("NDS: The options prop passed to Select must have unique values for each option", options);
23284
- }
23285
- }
23286
- };
23287
-
23288
- var getOption = function getOption(options, value) {
23289
- // allows an option with a null value to be matched
23290
- if (options.length > 0 && value !== undefined) {
23291
- var optionWithMatchingValue = options.find(function (o) {
23292
- return o.value === value;
23293
- });
23294
- return optionWithMatchingValue || null;
23295
- }
23296
-
23297
- return value;
23298
- };
23299
-
23300
- var getReactSelectValue = function getReactSelectValue(options, input) {
23301
- if (Array.isArray(input)) {
23302
- return input.map(function (i) {
23303
- return getOption(options, i);
23304
- });
23305
- }
23306
-
23307
- return getOption(options, input);
23308
- };
23309
-
23310
- var extractValue = function extractValue(options, isMulti) {
23311
- if (isMulti) {
23312
- return options && options.length ? options.map(function (o) {
23313
- return o.value;
23314
- }) : [];
23315
- }
23316
-
23317
- if (options == null) {
23318
- return options;
23319
- } else {
23320
- return options.value;
23321
- }
23322
- };
23323
-
23324
- var ReactSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
23297
+ var ReactSelect = /*#__PURE__*/React__default['default'].forwardRef(function (_a, ref) {
23325
23298
  var autocomplete = _a.autocomplete,
23326
23299
  options = _a.options,
23327
23300
  labelText = _a.labelText,
@@ -23350,17 +23323,83 @@
23350
23323
  var _useTranslation = useTranslation(),
23351
23324
  t = _useTranslation.t;
23352
23325
 
23353
- var themeContext = React.useContext(styled.ThemeContext);
23326
+ var themeContext = React__default['default'].useContext(styled.ThemeContext);
23354
23327
  var spaceProps = getSubset(props, propTypes.space);
23355
- React.useEffect(function () {
23328
+ var reactSelectRef = React__default['default'].useRef(null);
23329
+ React__default['default'].useEffect(function () {
23356
23330
  checkOptionsAreValid(options);
23357
23331
  }, [options]);
23332
+ var handleChange = React__default['default'].useCallback(function (option) {
23333
+ onChange && onChange(extractValue(option, multiselect));
23334
+ }, [multiselect, onChange]);
23335
+ var handlePaste = React__default['default'].useCallback(function (e) {
23336
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
23337
+ var currentRef, currentValue, clipboardData, values, notExistingOptions, pastedOptions, newValue;
23338
+ return regenerator.wrap(function _callee$(_context) {
23339
+ while (1) {
23340
+ switch (_context.prev = _context.next) {
23341
+ case 0:
23342
+ e.preventDefault();
23343
+ currentRef = reactSelectRef.current;
23344
+ currentValue = currentRef.state.value || [];
23345
+ clipboardData = e.clipboardData.getData("text/plain") || "";
23346
+ values = extractValuesFromCsvString(clipboardData);
23347
+ notExistingOptions = [];
23348
+ pastedOptions = values.map(function (pastedOption) {
23349
+ var existingOption = options.find(function (option) {
23350
+ return option.label === pastedOption || option.value === pastedOption;
23351
+ });
23352
+
23353
+ if (existingOption) {
23354
+ return existingOption;
23355
+ }
23356
+
23357
+ notExistingOptions.push(pastedOption);
23358
+ return null;
23359
+ }).filter(Boolean).filter(function (pastedOption) {
23360
+ return (// ignoring already selected options
23361
+ currentValue.findIndex(function (option) {
23362
+ return pastedOption.value === option.value;
23363
+ }) === -1
23364
+ );
23365
+ });
23366
+ newValue = [].concat(currentValue, pastedOptions);
23367
+ currentRef.setState(function (prevState) {
23368
+ return Object.assign(Object.assign({}, prevState), {
23369
+ value: newValue,
23370
+ inputValue: notExistingOptions.join(", ")
23371
+ });
23372
+ });
23373
+ handleChange(newValue);
23374
+
23375
+ case 10:
23376
+ case "end":
23377
+ return _context.stop();
23378
+ }
23379
+ }
23380
+ }, _callee);
23381
+ }));
23382
+ }, [options]);
23383
+
23384
+ var _SelectInput = React__default['default'].useCallback(function (inputProps) {
23385
+ return /*#__PURE__*/React__default['default'].createElement(SelectInput, Object.assign({}, inputProps, multiselect ? {
23386
+ onPaste: handlePaste
23387
+ } : {}));
23388
+ }, [handlePaste, multiselect]);
23389
+
23390
+ React__default['default'].useEffect(function () {
23391
+ if (ref) {
23392
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
23393
+ // @ts-ignore
23394
+ ref.current = reactSelectRef.current;
23395
+ }
23396
+ }, [reactSelectRef, ref]);
23358
23397
  return /*#__PURE__*/React__default['default'].createElement(Field, Object.assign({}, spaceProps), /*#__PURE__*/React__default['default'].createElement(MaybeFieldLabel, {
23359
23398
  labelText: labelText,
23360
23399
  requirementText: requirementText,
23361
23400
  helpText: helpText
23362
23401
  }, /*#__PURE__*/React__default['default'].createElement(WindowedSelect__default['default'], Object.assign({
23363
- ref: ref,
23402
+ ref: reactSelectRef,
23364
23403
  placeholder: placeholder || t("select ..."),
23365
23404
  windowThreshold: windowThreshold,
23366
23405
  styles: customStyles({
@@ -23375,9 +23414,7 @@
23375
23414
  "aria-invalid": error,
23376
23415
  defaultMenuIsOpen: initialIsOpen,
23377
23416
  inputId: id,
23378
- onChange: onChange && function (option) {
23379
- return onChange(extractValue(option, multiselect));
23380
- },
23417
+ onChange: handleChange,
23381
23418
  defaultValue: getReactSelectValue(options, defaultValue),
23382
23419
  value: getReactSelectValue(options, value),
23383
23420
  isMulti: multiselect,
@@ -23390,7 +23427,7 @@
23390
23427
  DropdownIndicator: SelectDropdownIndicator,
23391
23428
  SelectContainer: SelectContainer$1,
23392
23429
  Menu: SelectMenu,
23393
- Input: SelectInput
23430
+ Input: _SelectInput
23394
23431
  }, components),
23395
23432
  "aria-label": ariaLabel,
23396
23433
  options: options,
@@ -23401,6 +23438,60 @@
23401
23438
  errorList: errorList
23402
23439
  })));
23403
23440
  });
23441
+
23442
+ var checkOptionsAreValid = function checkOptionsAreValid(options) {
23443
+ if (options && process.env.NODE_ENV === "development") {
23444
+ var uniq = function uniq(a) {
23445
+ return Array.from(new Set(a));
23446
+ };
23447
+
23448
+ var uniqueValues = uniq(options.map(function (_ref) {
23449
+ var value = _ref.value;
23450
+ return value === null ? "_null_" : value;
23451
+ }));
23452
+
23453
+ if (uniqueValues.length < options.length) {
23454
+ console.warn("NDS: The options prop passed to Select must have unique values for each option", options);
23455
+ }
23456
+ }
23457
+ };
23458
+
23459
+ var getOption = function getOption(options, value) {
23460
+ // allows an option with a null value to be matched
23461
+ if (options.length > 0 && value !== undefined) {
23462
+ var optionWithMatchingValue = options.find(function (o) {
23463
+ return o.value === value;
23464
+ });
23465
+ return optionWithMatchingValue || null;
23466
+ }
23467
+
23468
+ return value;
23469
+ };
23470
+
23471
+ var getReactSelectValue = function getReactSelectValue(options, input) {
23472
+ if (Array.isArray(input)) {
23473
+ return input.map(function (i) {
23474
+ return getOption(options, i);
23475
+ });
23476
+ }
23477
+
23478
+ return getOption(options, input);
23479
+ };
23480
+
23481
+ var extractValue = function extractValue(options, isMulti) {
23482
+ if (isMulti) {
23483
+ return options && options.length ? options.map(function (o) {
23484
+ return o.value;
23485
+ }) : [];
23486
+ }
23487
+
23488
+ if (options == null) {
23489
+ return options;
23490
+ } else {
23491
+ return options.value;
23492
+ }
23493
+ };
23494
+
23404
23495
  ReactSelect.defaultProps = Object.assign(Object.assign({}, SelectDefaultProps), {
23405
23496
  windowThreshold: 300,
23406
23497
  filterOption: undefined
@@ -19,6 +19,7 @@ import deepEqual from 'deep-equal';
19
19
  import createContext$1 from 'create-react-context';
20
20
  import ReactResizeDetector from 'react-resize-detector';
21
21
  import WindowedSelect, { components as components$1 } from 'react-windowed-select';
22
+ import regeneratorRuntime from 'regenerator-runtime';
22
23
  import reactDom, { findDOMNode, createPortal } from 'react-dom';
23
24
  import exenv from 'exenv';
24
25
  import smoothscroll from 'smoothscroll-polyfill';
@@ -11711,6 +11712,16 @@ function __rest(s, e) {
11711
11712
  t[p[i]] = s[p[i]];
11712
11713
  }
11713
11714
  return t;
11715
+ }
11716
+
11717
+ function __awaiter(thisArg, _arguments, P, generator) {
11718
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11719
+ return new (P || (P = Promise))(function (resolve, reject) {
11720
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11721
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11722
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11723
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11724
+ });
11714
11725
  }
11715
11726
 
11716
11727
  var prefix = "random-id-";
@@ -22956,6 +22967,8 @@ var SelectOption = function SelectOption(props) {
22956
22967
  }), /*#__PURE__*/React__default.createElement(components$1.Option, Object.assign({}, props)));
22957
22968
  };
22958
22969
 
22970
+ var regenerator = regeneratorRuntime;
22971
+
22959
22972
  var getBorderColor = function getBorderColor(_ref) {
22960
22973
  var errored = _ref.errored,
22961
22974
  disabled = _ref.disabled,
@@ -23169,6 +23182,20 @@ var customStyles = function customStyles(_ref4) {
23169
23182
  };
23170
23183
  };
23171
23184
 
23185
+ var extractValuesFromCsvString = function extractValuesFromCsvString(csv) {
23186
+ var quoteRegEx = /(["'])(?:(?=(\\?))\2.)*?\1/gim;
23187
+ var matchedValues = csv.match(quoteRegEx) || [];
23188
+ var quotedValues = matchedValues.map(function (str) {
23189
+ return str.replace(/(["',])/g, "");
23190
+ });
23191
+ var values = Array.from(new Set(csv.replace(quoteRegEx, "").split(",").map(function (value) {
23192
+ return value.trim();
23193
+ }).filter(function (str) {
23194
+ return str.length > 0;
23195
+ }).concat(quotedValues)));
23196
+ return values;
23197
+ };
23198
+
23172
23199
  var SelectControl = function SelectControl(props) {
23173
23200
  // eslint-disable-next-line react/prop-types
23174
23201
  var isFocused = props.isFocused;
@@ -23241,61 +23268,7 @@ var SelectDefaultProps = {
23241
23268
  components: undefined,
23242
23269
  closeMenuOnSelect: true
23243
23270
  };
23244
-
23245
- var checkOptionsAreValid = function checkOptionsAreValid(options) {
23246
- if (options && process.env.NODE_ENV === "development") {
23247
- var uniq = function uniq(a) {
23248
- return Array.from(new Set(a));
23249
- };
23250
-
23251
- var uniqueValues = uniq(options.map(function (_ref) {
23252
- var value = _ref.value;
23253
- return value === null ? "_null_" : value;
23254
- }));
23255
-
23256
- if (uniqueValues.length < options.length) {
23257
- console.warn("NDS: The options prop passed to Select must have unique values for each option", options);
23258
- }
23259
- }
23260
- };
23261
-
23262
- var getOption = function getOption(options, value) {
23263
- // allows an option with a null value to be matched
23264
- if (options.length > 0 && value !== undefined) {
23265
- var optionWithMatchingValue = options.find(function (o) {
23266
- return o.value === value;
23267
- });
23268
- return optionWithMatchingValue || null;
23269
- }
23270
-
23271
- return value;
23272
- };
23273
-
23274
- var getReactSelectValue = function getReactSelectValue(options, input) {
23275
- if (Array.isArray(input)) {
23276
- return input.map(function (i) {
23277
- return getOption(options, i);
23278
- });
23279
- }
23280
-
23281
- return getOption(options, input);
23282
- };
23283
-
23284
- var extractValue = function extractValue(options, isMulti) {
23285
- if (isMulti) {
23286
- return options && options.length ? options.map(function (o) {
23287
- return o.value;
23288
- }) : [];
23289
- }
23290
-
23291
- if (options == null) {
23292
- return options;
23293
- } else {
23294
- return options.value;
23295
- }
23296
- };
23297
-
23298
- var ReactSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
23271
+ var ReactSelect = /*#__PURE__*/React__default.forwardRef(function (_a, ref) {
23299
23272
  var autocomplete = _a.autocomplete,
23300
23273
  options = _a.options,
23301
23274
  labelText = _a.labelText,
@@ -23324,17 +23297,83 @@ var ReactSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
23324
23297
  var _useTranslation = useTranslation(),
23325
23298
  t = _useTranslation.t;
23326
23299
 
23327
- var themeContext = useContext(ThemeContext$1);
23300
+ var themeContext = React__default.useContext(ThemeContext$1);
23328
23301
  var spaceProps = getSubset(props, propTypes.space);
23329
- useEffect(function () {
23302
+ var reactSelectRef = React__default.useRef(null);
23303
+ React__default.useEffect(function () {
23330
23304
  checkOptionsAreValid(options);
23331
23305
  }, [options]);
23306
+ var handleChange = React__default.useCallback(function (option) {
23307
+ onChange && onChange(extractValue(option, multiselect));
23308
+ }, [multiselect, onChange]);
23309
+ var handlePaste = React__default.useCallback(function (e) {
23310
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
23311
+ var currentRef, currentValue, clipboardData, values, notExistingOptions, pastedOptions, newValue;
23312
+ return regenerator.wrap(function _callee$(_context) {
23313
+ while (1) {
23314
+ switch (_context.prev = _context.next) {
23315
+ case 0:
23316
+ e.preventDefault();
23317
+ currentRef = reactSelectRef.current;
23318
+ currentValue = currentRef.state.value || [];
23319
+ clipboardData = e.clipboardData.getData("text/plain") || "";
23320
+ values = extractValuesFromCsvString(clipboardData);
23321
+ notExistingOptions = [];
23322
+ pastedOptions = values.map(function (pastedOption) {
23323
+ var existingOption = options.find(function (option) {
23324
+ return option.label === pastedOption || option.value === pastedOption;
23325
+ });
23326
+
23327
+ if (existingOption) {
23328
+ return existingOption;
23329
+ }
23330
+
23331
+ notExistingOptions.push(pastedOption);
23332
+ return null;
23333
+ }).filter(Boolean).filter(function (pastedOption) {
23334
+ return (// ignoring already selected options
23335
+ currentValue.findIndex(function (option) {
23336
+ return pastedOption.value === option.value;
23337
+ }) === -1
23338
+ );
23339
+ });
23340
+ newValue = [].concat(currentValue, pastedOptions);
23341
+ currentRef.setState(function (prevState) {
23342
+ return Object.assign(Object.assign({}, prevState), {
23343
+ value: newValue,
23344
+ inputValue: notExistingOptions.join(", ")
23345
+ });
23346
+ });
23347
+ handleChange(newValue);
23348
+
23349
+ case 10:
23350
+ case "end":
23351
+ return _context.stop();
23352
+ }
23353
+ }
23354
+ }, _callee);
23355
+ }));
23356
+ }, [options]);
23357
+
23358
+ var _SelectInput = React__default.useCallback(function (inputProps) {
23359
+ return /*#__PURE__*/React__default.createElement(SelectInput, Object.assign({}, inputProps, multiselect ? {
23360
+ onPaste: handlePaste
23361
+ } : {}));
23362
+ }, [handlePaste, multiselect]);
23363
+
23364
+ React__default.useEffect(function () {
23365
+ if (ref) {
23366
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
23367
+ // @ts-ignore
23368
+ ref.current = reactSelectRef.current;
23369
+ }
23370
+ }, [reactSelectRef, ref]);
23332
23371
  return /*#__PURE__*/React__default.createElement(Field, Object.assign({}, spaceProps), /*#__PURE__*/React__default.createElement(MaybeFieldLabel, {
23333
23372
  labelText: labelText,
23334
23373
  requirementText: requirementText,
23335
23374
  helpText: helpText
23336
23375
  }, /*#__PURE__*/React__default.createElement(WindowedSelect, Object.assign({
23337
- ref: ref,
23376
+ ref: reactSelectRef,
23338
23377
  placeholder: placeholder || t("select ..."),
23339
23378
  windowThreshold: windowThreshold,
23340
23379
  styles: customStyles({
@@ -23349,9 +23388,7 @@ var ReactSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
23349
23388
  "aria-invalid": error,
23350
23389
  defaultMenuIsOpen: initialIsOpen,
23351
23390
  inputId: id,
23352
- onChange: onChange && function (option) {
23353
- return onChange(extractValue(option, multiselect));
23354
- },
23391
+ onChange: handleChange,
23355
23392
  defaultValue: getReactSelectValue(options, defaultValue),
23356
23393
  value: getReactSelectValue(options, value),
23357
23394
  isMulti: multiselect,
@@ -23364,7 +23401,7 @@ var ReactSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
23364
23401
  DropdownIndicator: SelectDropdownIndicator,
23365
23402
  SelectContainer: SelectContainer$1,
23366
23403
  Menu: SelectMenu,
23367
- Input: SelectInput
23404
+ Input: _SelectInput
23368
23405
  }, components),
23369
23406
  "aria-label": ariaLabel,
23370
23407
  options: options,
@@ -23375,6 +23412,60 @@ var ReactSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
23375
23412
  errorList: errorList
23376
23413
  })));
23377
23414
  });
23415
+
23416
+ var checkOptionsAreValid = function checkOptionsAreValid(options) {
23417
+ if (options && process.env.NODE_ENV === "development") {
23418
+ var uniq = function uniq(a) {
23419
+ return Array.from(new Set(a));
23420
+ };
23421
+
23422
+ var uniqueValues = uniq(options.map(function (_ref) {
23423
+ var value = _ref.value;
23424
+ return value === null ? "_null_" : value;
23425
+ }));
23426
+
23427
+ if (uniqueValues.length < options.length) {
23428
+ console.warn("NDS: The options prop passed to Select must have unique values for each option", options);
23429
+ }
23430
+ }
23431
+ };
23432
+
23433
+ var getOption = function getOption(options, value) {
23434
+ // allows an option with a null value to be matched
23435
+ if (options.length > 0 && value !== undefined) {
23436
+ var optionWithMatchingValue = options.find(function (o) {
23437
+ return o.value === value;
23438
+ });
23439
+ return optionWithMatchingValue || null;
23440
+ }
23441
+
23442
+ return value;
23443
+ };
23444
+
23445
+ var getReactSelectValue = function getReactSelectValue(options, input) {
23446
+ if (Array.isArray(input)) {
23447
+ return input.map(function (i) {
23448
+ return getOption(options, i);
23449
+ });
23450
+ }
23451
+
23452
+ return getOption(options, input);
23453
+ };
23454
+
23455
+ var extractValue = function extractValue(options, isMulti) {
23456
+ if (isMulti) {
23457
+ return options && options.length ? options.map(function (o) {
23458
+ return o.value;
23459
+ }) : [];
23460
+ }
23461
+
23462
+ if (options == null) {
23463
+ return options;
23464
+ } else {
23465
+ return options.value;
23466
+ }
23467
+ };
23468
+
23378
23469
  ReactSelect.defaultProps = Object.assign(Object.assign({}, SelectDefaultProps), {
23379
23470
  windowThreshold: 300,
23380
23471
  filterOption: undefined
@@ -66,6 +66,6 @@ export declare const SelectDefaultProps: {
66
66
  components: any;
67
67
  closeMenuOnSelect: boolean;
68
68
  };
69
- export declare const getOption: (options: any, value: any) => any;
70
69
  declare const ReactSelect: React.ForwardRefExoticComponent<Pick<SelectProps, React.ReactText> & React.RefAttributes<unknown>>;
70
+ export declare const getOption: (options: any, value: any) => any;
71
71
  export default ReactSelect;
@@ -108,3 +108,4 @@ export declare const UsingRefToControlFocus: {
108
108
  };
109
109
  };
110
110
  export declare const WithCustomProps: () => JSX.Element;
111
+ export declare const PasteCsvValueInSelect: (props: any) => JSX.Element;
@@ -0,0 +1 @@
1
+ export declare const extractValuesFromCsvString: (csv: string) => string[];
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nulogy/components",
3
- "version": "8.2.2",
3
+ "version": "8.3.0",
4
4
  "description": "Component library for the Nulogy Design System - http://nulogy.design",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -179,6 +179,7 @@
179
179
  ],
180
180
  "testMatch": [
181
181
  "**/src/**/*.spec.tsx",
182
+ "**/src/**/*.spec.ts",
182
183
  "**/spec/**/*.spec.tsx"
183
184
  ],
184
185
  "setupFiles": [