@mmb-digital/ds-lilly 0.3.2 → 0.3.3

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/ds-lilly.js CHANGED
@@ -98277,21 +98277,21 @@ var Autocomplete2_spreadArray = (undefined && undefined.__spreadArray) || functi
98277
98277
 
98278
98278
  var Autocomplete2 = function (_a) {
98279
98279
  var _b;
98280
- var _c = _a.asyncDelayMilliseconds, asyncDelayMilliseconds = _c === void 0 ? 200 : _c, disabledTooltip = _a.disabledTooltip, _d = _a.displayDetails, displayDetails = _d === void 0 ? false : _d, dropdownTheme = _a.dropdownTheme, emptyValueLabel = _a.emptyValueLabel, error = _a.error, _e = _a.filterMinimumLength, filterMinimumLength = _e === void 0 ? 2 : _e, _f = _a.hasFullWidthOptions, hasFullWidthOptions = _f === void 0 ? true : _f, help = _a.help, isDisabled = _a.isDisabled, isLazyLoaded = _a.isLazyLoaded, _g = _a.items, inputItems = _g === void 0 ? [] : _g, label = _a.label, labelTooltip = _a.labelTooltip, loadItems = _a.loadItems, loadMoreItems = _a.loadMoreItems, name = _a.name, messages = _a.messages, _h = _a.newItemMinimumLength, newItemMinimumLength = _h === void 0 ? 2 : _h, onBlur = _a.onBlur, onChange = _a.onChange, onCreateNewItem = _a.onCreateNewItem, onFocus = _a.onFocus, placeholder = _a.placeholder, testId = _a.testId, theme = _a.theme, value = _a.value;
98281
- var _j = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(false), isDropdownVisible = _j[0], setIsDropdownVisible = _j[1];
98282
- var _k = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(null), buttonValue = _k[0], setButtonValue = _k[1];
98283
- var _l = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(false), typingMode = _l[0], setTypingMode = _l[1];
98284
- var _m = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(''), fulltextValue = _m[0], setFulltextValue = _m[1];
98285
- var _o = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(-1), currentItemPosition = _o[0], setCurrentItemPosition = _o[1];
98286
- var _p = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])([]), items = _p[0], setItems = _p[1];
98287
- var _q = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])({
98280
+ var _c = _a.asyncDelayMilliseconds, asyncDelayMilliseconds = _c === void 0 ? 200 : _c, _d = _a.canAlwaysCreateNewItem, canAlwaysCreateNewItem = _d === void 0 ? false : _d, disabledTooltip = _a.disabledTooltip, _e = _a.displayDetails, displayDetails = _e === void 0 ? false : _e, dropdownTheme = _a.dropdownTheme, emptyValueLabel = _a.emptyValueLabel, error = _a.error, _f = _a.filterMinimumLength, filterMinimumLength = _f === void 0 ? 2 : _f, _g = _a.hasFullWidthOptions, hasFullWidthOptions = _g === void 0 ? true : _g, help = _a.help, isDisabled = _a.isDisabled, isLazyLoaded = _a.isLazyLoaded, _h = _a.items, inputItems = _h === void 0 ? [] : _h, label = _a.label, labelTooltip = _a.labelTooltip, loadItems = _a.loadItems, loadMoreItems = _a.loadMoreItems, name = _a.name, messages = _a.messages, _j = _a.newItemMinimumLength, newItemMinimumLength = _j === void 0 ? 2 : _j, onBlur = _a.onBlur, onChange = _a.onChange, onCreateNewItem = _a.onCreateNewItem, onFocus = _a.onFocus, placeholder = _a.placeholder, testId = _a.testId, theme = _a.theme, value = _a.value;
98281
+ var _k = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(false), isDropdownVisible = _k[0], setIsDropdownVisible = _k[1];
98282
+ var _l = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(null), buttonValue = _l[0], setButtonValue = _l[1];
98283
+ var _m = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(false), typingMode = _m[0], setTypingMode = _m[1];
98284
+ var _o = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(''), fulltextValue = _o[0], setFulltextValue = _o[1];
98285
+ var _p = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(-1), currentItemPosition = _p[0], setCurrentItemPosition = _p[1];
98286
+ var _q = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])([]), items = _q[0], setItems = _q[1];
98287
+ var _r = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])({
98288
98288
  loading: false,
98289
98289
  found: -1
98290
- }), searchState = _q[0], setSearchState = _q[1];
98291
- var _r = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])({
98290
+ }), searchState = _r[0], setSearchState = _r[1];
98291
+ var _s = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])({
98292
98292
  loading: false,
98293
98293
  found: -1
98294
- }), pagingState = _r[0], setPagingState = _r[1];
98294
+ }), pagingState = _s[0], setPagingState = _s[1];
98295
98295
  var loadAsyncItems = function (query) { return Autocomplete2_awaiter(void 0, void 0, void 0, function () {
98296
98296
  var newItems, isCategorised, found;
98297
98297
  var _a;
@@ -98337,10 +98337,10 @@ var Autocomplete2 = function (_a) {
98337
98337
  return map;
98338
98338
  }, [items, isCategorised]);
98339
98339
  var showCreatable = !!onCreateNewItem &&
98340
- itemsIndex.length === 0 &&
98340
+ (itemsIndex.length === 0 || canAlwaysCreateNewItem) &&
98341
98341
  typingMode &&
98342
98342
  fulltextValue.length >= newItemMinimumLength &&
98343
- (!loadItems || (!!loadItems && searchState.found === 0));
98343
+ (!loadItems || (!!loadItems && searchState.found === 0) || (!!loadItems && canAlwaysCreateNewItem));
98344
98344
  var getItemIndexByValue = function (val, sourceItems) {
98345
98345
  if (sourceItems === void 0) { sourceItems = items; }
98346
98346
  if (val === '' || val === undefined) {
@@ -98440,9 +98440,10 @@ var Autocomplete2 = function (_a) {
98440
98440
  var itemElementId = isCategorised ? name + "_option-" + category + "-" + item : name + "_option-" + item;
98441
98441
  (_a = document.getElementById(itemElementId)) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ block: center ? 'center' : 'nearest' });
98442
98442
  };
98443
- var scrollToCreatable = function () {
98444
- var _a;
98443
+ var focusCreatable = function () {
98444
+ var _a, _b;
98445
98445
  (_a = document.getElementById(name + "_option-createNew")) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ block: 'nearest' });
98446
+ (_b = document.getElementById(name + "_list-createNew")) === null || _b === void 0 ? void 0 : _b.focus();
98446
98447
  };
98447
98448
  var focusFulltextInput = function () {
98448
98449
  setTimeout(function () {
@@ -98561,7 +98562,7 @@ var Autocomplete2 = function (_a) {
98561
98562
  onCreateNewItem && onCreateNewItem(fulltextValue);
98562
98563
  };
98563
98564
  var handleOptionKeyPress = function (event) {
98564
- var ctrlKey = event.ctrlKey, key = event.key, target = event.target;
98565
+ var ctrlKey = event.ctrlKey, key = event.key, metaKey = event.metaKey, target = event.target;
98565
98566
  switch (key) {
98566
98567
  case KEYS.Enter:
98567
98568
  case KEYS.Tab:
@@ -98583,9 +98584,9 @@ var Autocomplete2 = function (_a) {
98583
98584
  handleFocusedItem(itemIndex.item, itemIndex.category);
98584
98585
  }
98585
98586
  else if (showCreatable) {
98586
- if (currentItemPosition === -1) {
98587
+ if (currentItemPosition + 1 === itemsIndex.length) {
98587
98588
  setCurrentItemPosition(itemsIndex.length);
98588
- scrollToCreatable();
98589
+ focusCreatable();
98589
98590
  }
98590
98591
  else {
98591
98592
  setCurrentItemPosition(-1);
@@ -98640,7 +98641,7 @@ var Autocomplete2 = function (_a) {
98640
98641
  event.preventDefault();
98641
98642
  break;
98642
98643
  default:
98643
- if (!ctrlKey) {
98644
+ if (!(ctrlKey || metaKey)) {
98644
98645
  setFulltextValue(function (prev) { return "" + prev + key; });
98645
98646
  }
98646
98647
  break;
@@ -98665,9 +98666,7 @@ var Autocomplete2 = function (_a) {
98665
98666
  else if (showCreatable) {
98666
98667
  setCurrentItemPosition(itemsIndex.length);
98667
98668
  setTimeout(function () {
98668
- var _a;
98669
- scrollToCreatable();
98670
- (_a = document.getElementById(name + "_list-createNew")) === null || _a === void 0 ? void 0 : _a.focus();
98669
+ focusCreatable();
98671
98670
  });
98672
98671
  }
98673
98672
  return;
@@ -98690,7 +98689,7 @@ var Autocomplete2 = function (_a) {
98690
98689
  }
98691
98690
  if (key === KEYS.ArrowUp && isDropdownVisible) {
98692
98691
  event.preventDefault();
98693
- if (itemsIndex.length > 0) {
98692
+ if (itemsIndex.length > 0 && !showCreatable) {
98694
98693
  if (isLazyLoaded && currentItemPosition === -1)
98695
98694
  return;
98696
98695
  var _b = itemsIndex[currentItemPosition > -1 ? currentItemPosition : itemsIndex.length - 1], category_2 = _b.category, item_2 = _b.item;
@@ -98702,12 +98701,10 @@ var Autocomplete2 = function (_a) {
98702
98701
  (_a = document.getElementById(listElementId)) === null || _a === void 0 ? void 0 : _a.focus();
98703
98702
  });
98704
98703
  }
98705
- else if (showCreatable && currentItemPosition === -1) {
98704
+ else if (showCreatable) {
98706
98705
  setCurrentItemPosition(itemsIndex.length);
98707
98706
  setTimeout(function () {
98708
- var _a;
98709
- scrollToCreatable();
98710
- (_a = document.getElementById(name + "_list-createNew")) === null || _a === void 0 ? void 0 : _a.focus();
98707
+ focusCreatable();
98711
98708
  });
98712
98709
  }
98713
98710
  else {
@@ -4,6 +4,8 @@ import { FormField2PropsType, Theme } from '../../../types';
4
4
  export interface Autocomplete2PropsType extends FormField2PropsType {
5
5
  /** A delay before async loadItems is called after user stops typing */
6
6
  asyncDelayMilliseconds?: number;
7
+ /** A flag whether option to create new item should be rendered always (true) or only on empty result (false, default) */
8
+ canAlwaysCreateNewItem?: boolean;
7
9
  /** Displays additional information for selected option. (perex, amount) */
8
10
  displayDetails?: boolean;
9
11
  /** Custom theme for dropdown items. */
@@ -40,5 +42,5 @@ export interface Autocomplete2PropsType extends FormField2PropsType {
40
42
  /** A callback to create new item */
41
43
  onCreateNewItem?: (value?: string) => void;
42
44
  }
43
- export declare const Autocomplete2: ({ asyncDelayMilliseconds, disabledTooltip, displayDetails, dropdownTheme, emptyValueLabel, error, filterMinimumLength, hasFullWidthOptions, help, isDisabled, isLazyLoaded, items: inputItems, label, labelTooltip, loadItems, loadMoreItems, name, messages, newItemMinimumLength, onBlur, onChange, onCreateNewItem, onFocus, placeholder, testId, theme, value }: Autocomplete2PropsType) => JSX.Element;
45
+ export declare const Autocomplete2: ({ asyncDelayMilliseconds, canAlwaysCreateNewItem, disabledTooltip, displayDetails, dropdownTheme, emptyValueLabel, error, filterMinimumLength, hasFullWidthOptions, help, isDisabled, isLazyLoaded, items: inputItems, label, labelTooltip, loadItems, loadMoreItems, name, messages, newItemMinimumLength, onBlur, onChange, onCreateNewItem, onFocus, placeholder, testId, theme, value }: Autocomplete2PropsType) => JSX.Element;
44
46
  //# sourceMappingURL=Autocomplete2.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmb-digital/ds-lilly",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "MMB LILLY design system",
5
5
  "license": "UNLICENSED",
6
6
  "sideEffects": false,
package/dist/.DS_Store DELETED
Binary file