@ozen-ui/kit 0.83.3 → 0.84.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.
Files changed (37) hide show
  1. package/__inner__/cjs/components/AutocompleteBase/AutocompleteBase.js +3 -1
  2. package/__inner__/cjs/components/AutocompleteBase/entities/open/index.js +1 -0
  3. package/__inner__/cjs/components/AutocompleteBase/entities/open/onOpenChange.js +2 -0
  4. package/__inner__/cjs/components/AutocompleteBase/hooks/useAutocompleteBaseDropdown/useAutocompleteBaseDropdown.js +3 -1
  5. package/__inner__/cjs/components/AutocompleteBase/hooks/useAutocompleteBaseOptions/useAutocompleteBaseOptions.js +17 -5
  6. package/__inner__/cjs/components/AutocompleteBase/hooks/useAutocompleteBaseValue/useAutocompleteBaseValue.js +19 -6
  7. package/__inner__/cjs/components/AutocompleteBase/modules/AutocompleteBaseDropdown/AutocompleteBaseDropdown.js +4 -4
  8. package/__inner__/cjs/components/AutocompleteBase/utils/index.js +2 -0
  9. package/__inner__/cjs/components/AutocompleteBase/utils/isId.js +8 -0
  10. package/__inner__/cjs/components/AutocompleteBase/utils/isInternalOption.js +13 -0
  11. package/__inner__/cjs/components/AutocompleteListCard/modules/AutocompleteListCardDropdown/AutocompleteListCardDropdown.js +5 -5
  12. package/__inner__/cjs/components/ButtonBase/index.js +1 -0
  13. package/__inner__/esm/components/AutocompleteBase/AutocompleteBase.js +3 -1
  14. package/__inner__/esm/components/AutocompleteBase/entities/open/index.js +1 -0
  15. package/__inner__/esm/components/AutocompleteBase/entities/open/onOpenChange.js +1 -0
  16. package/__inner__/esm/components/AutocompleteBase/hooks/useAutocompleteBaseDropdown/useAutocompleteBaseDropdown.js +3 -1
  17. package/__inner__/esm/components/AutocompleteBase/hooks/useAutocompleteBaseOptions/useAutocompleteBaseOptions.js +18 -6
  18. package/__inner__/esm/components/AutocompleteBase/hooks/useAutocompleteBaseValue/useAutocompleteBaseValue.js +19 -6
  19. package/__inner__/esm/components/AutocompleteBase/modules/AutocompleteBaseDropdown/AutocompleteBaseDropdown.js +4 -4
  20. package/__inner__/esm/components/AutocompleteBase/utils/index.js +2 -0
  21. package/__inner__/esm/components/AutocompleteBase/utils/isId.js +4 -0
  22. package/__inner__/esm/components/AutocompleteBase/utils/isInternalOption.js +9 -0
  23. package/__inner__/esm/components/AutocompleteListCard/modules/AutocompleteListCardDropdown/AutocompleteListCardDropdown.js +5 -5
  24. package/__inner__/esm/components/ButtonBase/index.js +1 -0
  25. package/__inner__/types/components/AutocompleteBase/entities/input/ref.d.ts +1 -1
  26. package/__inner__/types/components/AutocompleteBase/entities/open/index.d.ts +1 -0
  27. package/__inner__/types/components/AutocompleteBase/entities/open/onOpenChange.d.ts +1 -0
  28. package/__inner__/types/components/AutocompleteBase/hooks/useAutocompleteBaseDropdown/useAutocompleteBaseDropdown.d.ts +4 -3
  29. package/__inner__/types/components/AutocompleteBase/hooks/useAutocompleteBaseOptions/types.d.ts +2 -2
  30. package/__inner__/types/components/AutocompleteBase/hooks/useAutocompleteBaseOptions/useAutocompleteBaseOptions.d.ts +3 -2
  31. package/__inner__/types/components/AutocompleteBase/hooks/useAutocompleteBaseValue/types.d.ts +2 -2
  32. package/__inner__/types/components/AutocompleteBase/types.d.ts +3 -1
  33. package/__inner__/types/components/AutocompleteBase/utils/index.d.ts +2 -0
  34. package/__inner__/types/components/AutocompleteBase/utils/isId.d.ts +2 -0
  35. package/__inner__/types/components/AutocompleteBase/utils/isInternalOption.d.ts +2 -0
  36. package/__inner__/types/components/ButtonBase/index.d.ts +1 -0
  37. package/package.json +4 -4
@@ -16,7 +16,7 @@ var AutocompleteBase = function (inProps) {
16
16
  props: inProps,
17
17
  name: 'AutocompleteBase',
18
18
  });
19
- var dropdown = props.dropdown, input = props.input, inputValueProp = props.inputValue, _a = props.multiple, multiple = _a === void 0 ? constants_1.AUTOCOMPLETE_BASE_DEFAULT_MULTIPLE : _a, valueProp = props.value, defaultValue = props.defaultValue, searchFunctionProp = props.searchFunction, optionsProp = props.options, _b = props.prepareOption, prepareOptionProp = _b === void 0 ? utils_1.autocompleteBaseDefaultPrepareOption : _b, openProp = props.open, defaultOpen = props.defaultOpen, onOpen = props.onOpen, onClose = props.onClose, _c = props.size, size = _c === void 0 ? constants_1.AUTOCOMPLETE_BASE_DEFAULT_SIZE : _c, _d = props.disabled, disabled = _d === void 0 ? constants_1.AUTOCOMPLETE_BASE_DEFAULT_DISABLED : _d, onChange = props.onChange, allowCustomValue = props.allowCustomValue, _e = props.loading, loading = _e === void 0 ? constants_1.AUTOCOMPLETE_BASE_DEFAULT_LOADING : _e, _f = props.closeOnSelect, closeOnSelect = _f === void 0 ? constants_1.AUTOCOMPLETE_BASE_DEFAULT_CLOSE_ON_SELECT : _f, _g = props.error, error = _g === void 0 ? constants_1.AUTOCOMPLETE_BASE_DEFAULT_ERROR : _g, onInputChange = props.onInputChange;
19
+ var dropdown = props.dropdown, input = props.input, inputValueProp = props.inputValue, _a = props.multiple, multiple = _a === void 0 ? constants_1.AUTOCOMPLETE_BASE_DEFAULT_MULTIPLE : _a, valueProp = props.value, defaultValue = props.defaultValue, searchFunctionProp = props.searchFunction, optionsProp = props.options, _b = props.prepareOption, prepareOptionProp = _b === void 0 ? utils_1.autocompleteBaseDefaultPrepareOption : _b, openProp = props.open, defaultOpen = props.defaultOpen, onOpen = props.onOpen, onClose = props.onClose, _c = props.size, size = _c === void 0 ? constants_1.AUTOCOMPLETE_BASE_DEFAULT_SIZE : _c, _d = props.disabled, disabled = _d === void 0 ? constants_1.AUTOCOMPLETE_BASE_DEFAULT_DISABLED : _d, onChange = props.onChange, allowCustomValue = props.allowCustomValue, _e = props.loading, loading = _e === void 0 ? constants_1.AUTOCOMPLETE_BASE_DEFAULT_LOADING : _e, _f = props.closeOnSelect, closeOnSelect = _f === void 0 ? constants_1.AUTOCOMPLETE_BASE_DEFAULT_CLOSE_ON_SELECT : _f, _g = props.error, error = _g === void 0 ? constants_1.AUTOCOMPLETE_BASE_DEFAULT_ERROR : _g, onInputChange = props.onInputChange, onOpenChange = props.onOpenChange;
20
20
  var anchorRef = (0, react_1.useRef)(null);
21
21
  var inputRef = (0, react_1.useRef)(null);
22
22
  var dropdownControl = (0, hooks_1.useAutocompleteBaseDropdown)({
@@ -24,6 +24,7 @@ var AutocompleteBase = function (inProps) {
24
24
  defaultOpen: defaultOpen,
25
25
  onOpen: onOpen,
26
26
  onClose: onClose,
27
+ onOpenChange: onOpenChange,
27
28
  });
28
29
  var searchControl = (0, hooks_1.useAutocompleteBaseSearch)(searchFunctionProp);
29
30
  var prepareOption = function (option) { return (tslib_1.__assign(tslib_1.__assign({}, prepareOptionProp(option)), { raw: option })); };
@@ -58,6 +59,7 @@ var AutocompleteBase = function (inProps) {
58
59
  filteredOptions: filteredOptions,
59
60
  valueControl: valueControl,
60
61
  multiple: multiple,
62
+ prepareOption: prepareOption,
61
63
  });
62
64
  var inputEventsControl = (0, hooks_1.useAutocompleteBaseInputEvents)({
63
65
  multiple: multiple,
@@ -3,3 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./onClose"), exports);
5
5
  tslib_1.__exportStar(require("./onOpen"), exports);
6
+ tslib_1.__exportStar(require("./onOpenChange"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -4,7 +4,7 @@ exports.useAutocompleteBaseDropdown = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var useControlled_1 = require("../../../../hooks/useControlled");
6
6
  var useAutocompleteBaseDropdown = function (_a) {
7
- var openProp = _a.open, defaultOpen = _a.defaultOpen, onClose = _a.onClose, onOpen = _a.onOpen;
7
+ var openProp = _a.open, defaultOpen = _a.defaultOpen, onClose = _a.onClose, onOpen = _a.onOpen, onOpenChange = _a.onOpenChange;
8
8
  var _b = tslib_1.__read((0, useControlled_1.useControlled)({
9
9
  value: openProp,
10
10
  defaultValue: defaultOpen,
@@ -15,11 +15,13 @@ var useAutocompleteBaseDropdown = function (_a) {
15
15
  var close = function () {
16
16
  setIsOpen(false);
17
17
  onClose === null || onClose === void 0 ? void 0 : onClose();
18
+ onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(false);
18
19
  };
19
20
  /** Открытие */
20
21
  var open = function () {
21
22
  setIsOpen(true);
22
23
  onOpen === null || onOpen === void 0 ? void 0 : onOpen();
24
+ onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(true);
23
25
  };
24
26
  /** Переключатель открытия и закрытия */
25
27
  var toggle = function () {
@@ -3,13 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useAutocompleteBaseOptions = void 0;
4
4
  var utils_1 = require("../../utils");
5
5
  var useAutocompleteBaseOptions = function (_a) {
6
- var options = _a.options, filteredOptions = _a.filteredOptions, valueControl = _a.valueControl, multiple = _a.multiple;
6
+ var options = _a.options, filteredOptions = _a.filteredOptions, valueControl = _a.valueControl, multiple = _a.multiple, prepareOption = _a.prepareOption;
7
7
  var isSelected = function (option) {
8
- var _a, _b, _c;
9
- if ((0, utils_1.isMultipleInternalValue)(valueControl.value, multiple)) {
10
- return ((_b = (_a = valueControl.value) === null || _a === void 0 ? void 0 : _a.some(function (selectedOption) { return selectedOption.id === option.id; })) !== null && _b !== void 0 ? _b : false);
8
+ var valueState = valueControl.value;
9
+ if (valueState === null || valueState === undefined) {
10
+ return false;
11
11
  }
12
- return ((_c = valueControl.value) === null || _c === void 0 ? void 0 : _c.id) === option.id;
12
+ var id = (function () {
13
+ if ((0, utils_1.isId)(option)) {
14
+ return option;
15
+ }
16
+ if ((0, utils_1.isInternalOption)(option)) {
17
+ return option.id;
18
+ }
19
+ return prepareOption(option).id;
20
+ })();
21
+ if ((0, utils_1.isMultipleInternalValue)(valueState, multiple)) {
22
+ return valueState.some(function (option) { return option.id === id; });
23
+ }
24
+ return valueState.id === id;
13
25
  };
14
26
  var hasOptions = (filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.length) > 0;
15
27
  return {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useAutocompleteBaseValue = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ var logger_1 = require("@ozen-ui/logger");
5
6
  var useControlled_1 = require("../../../../hooks/useControlled");
6
7
  var array_1 = require("../../../../utils/array");
7
8
  var isNotNil_1 = require("../../../../utils/isNotNil");
@@ -31,9 +32,9 @@ var useAutocompleteBaseValue = function (_a) {
31
32
  onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(event, option, params);
32
33
  };
33
34
  var setValue = function (event, optionId, paramsProp) {
34
- var _a, _b, _c, _d;
35
+ var _a, _b, _c, _d, _e;
35
36
  var source = paramsProp.source;
36
- var option = optionId === null
37
+ var option = optionId === null || (0, array_1.isArray)(optionId)
37
38
  ? null
38
39
  : options.find(function (option) { return option.id === optionId; });
39
40
  if (option === undefined) {
@@ -43,7 +44,19 @@ var useAutocompleteBaseValue = function (_a) {
43
44
  var params = tslib_1.__assign(tslib_1.__assign({}, inProps), { onChange: onChange });
44
45
  if ((0, utils_1.isMultipleProps)(params) &&
45
46
  (0, utils_1.isMultipleInternalValue)(valueState, multiple)) {
46
- if (option === null) {
47
+ if ((0, array_1.isArray)(optionId)) {
48
+ var preparedOptions_1 = [];
49
+ optionId.forEach(function (optionId) {
50
+ var option = options.find(function (option) { return option.id === optionId; });
51
+ if (!option) {
52
+ logger_1.logger.error("\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043D\u0430\u0439\u0442\u0438 option \u0434\u043B\u044F \"".concat(optionId, "\""));
53
+ return;
54
+ }
55
+ preparedOptions_1.push(option.raw);
56
+ });
57
+ (_a = params.onChange) === null || _a === void 0 ? void 0 : _a.call(params, event, preparedOptions_1, { source: source });
58
+ }
59
+ else if (option === null) {
47
60
  onChange === null || onChange === void 0 ? void 0 : onChange(event, null, { source: source });
48
61
  }
49
62
  else {
@@ -64,13 +77,13 @@ var useAutocompleteBaseValue = function (_a) {
64
77
  }
65
78
  return value_1.map(function (option) { return option.raw; });
66
79
  })();
67
- (_a = params.onChange) === null || _a === void 0 ? void 0 : _a.call(params, event, result, { source: source });
80
+ (_b = params.onChange) === null || _b === void 0 ? void 0 : _b.call(params, event, result, { source: source });
68
81
  }
69
82
  searchControl.deactivate();
70
83
  }
71
84
  else if ((0, utils_1.isSingleProps)(params)) {
72
- inputValue = (_b = option === null || option === void 0 ? void 0 : option.label) !== null && _b !== void 0 ? _b : '';
73
- (_c = params.onChange) === null || _c === void 0 ? void 0 : _c.call(params, event, (_d = option === null || option === void 0 ? void 0 : option.raw) !== null && _d !== void 0 ? _d : null, { source: source });
85
+ inputValue = (_c = option === null || option === void 0 ? void 0 : option.label) !== null && _c !== void 0 ? _c : '';
86
+ (_d = params.onChange) === null || _d === void 0 ? void 0 : _d.call(params, event, (_e = option === null || option === void 0 ? void 0 : option.raw) !== null && _e !== void 0 ? _e : null, { source: source });
74
87
  if (option) {
75
88
  searchControl.deactivate();
76
89
  }
@@ -15,7 +15,7 @@ var AutocompleteBaseContext_1 = require("../../AutocompleteBaseContext");
15
15
  var cnAutocompleteBaseDropdown = (0, classname_1.cn)('AutocompleteBaseDropdown');
16
16
  exports.AutocompleteBaseDropdown = (0, polymorphicComponentWithRef_1.polymorphicComponentWithRef)(function (_a, ref) {
17
17
  var children = _a.children, _b = _a.strategy, strategy = _b === void 0 ? 'absolute' : _b, _c = _a.offset, offset = _c === void 0 ? [0, 4] : _c, _d = _a.placement, placement = _d === void 0 ? 'bottom-start' : _d, _e = _a.as, as = _e === void 0 ? Paper_1.Paper : _e, className = _a.className, onExited = _a.onExited, popoverProps = tslib_1.__rest(_a, ["children", "strategy", "offset", "placement", "as", "className", "onExited"]);
18
- var _f = (0, AutocompleteBaseContext_1.useAutocompleteBaseContext)(), size = _f.size, dropdownControl = _f.dropdownControl, searchControl = _f.searchControl, anchorRef = _f.anchorRef, inputRef = _f.inputRef;
18
+ var _f = (0, AutocompleteBaseContext_1.useAutocompleteBaseContext)(), size = _f.size, dropdownControl = _f.dropdownControl, searchControl = _f.searchControl, anchorRef = _f.anchorRef;
19
19
  var radius = (0, getPaperSizeToFormElement_1.getPaperSizeToFormElement)(size);
20
20
  var updateStored = (0, useStoredValue_1.useStoredValue)(null);
21
21
  var resizeObserver = (0, useCreateResizeObserver_1.useCreateResizeObserver)(function () {
@@ -23,11 +23,11 @@ exports.AutocompleteBaseDropdown = (0, polymorphicComponentWithRef_1.polymorphic
23
23
  (_a = updateStored.current) === null || _a === void 0 ? void 0 : _a.call(updateStored);
24
24
  });
25
25
  (0, react_1.useEffect)(function () {
26
- var input = inputRef.current;
26
+ var input = anchorRef.current;
27
27
  if (input) {
28
- resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(inputRef.current);
28
+ resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(anchorRef.current);
29
29
  }
30
- }, [inputRef]);
30
+ }, [anchorRef]);
31
31
  return (react_1.default.createElement(Popover_1.Popover, tslib_1.__assign({ offset: offset, strategy: strategy, placement: placement, setUpdate: function (update) {
32
32
  updateStored.current = update;
33
33
  }, as: as, transitionProps: { classNames: 'AutocompleteBaseDropdown-animation' }, className: cnAutocompleteBaseDropdown('', [className]), equalAnchorWidth: true, disableReturnFocus: true, disableEnforceFocus: true, onExited: function () {
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./isId"), exports);
5
+ tslib_1.__exportStar(require("./isInternalOption"), exports);
4
6
  tslib_1.__exportStar(require("./isMultiple"), exports);
5
7
  tslib_1.__exportStar(require("./isSingle"), exports);
6
8
  tslib_1.__exportStar(require("./prepareOption"), exports);
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isId = void 0;
4
+ var utils_1 = require("../../../utils");
5
+ var isId = function (value) {
6
+ return (0, utils_1.isString)(value) || (0, utils_1.isNumber)(value);
7
+ };
8
+ exports.isId = isId;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isInternalOption = void 0;
4
+ var utils_1 = require("../../../utils");
5
+ var isInternalOption = function (value) {
6
+ return (0, utils_1.isPlainObject)(value) &&
7
+ Object.keys(value).length === 4 &&
8
+ 'raw' in value &&
9
+ 'disabled' in value &&
10
+ 'label' in value &&
11
+ 'id' in value;
12
+ };
13
+ exports.isInternalOption = isInternalOption;
@@ -18,7 +18,7 @@ exports.AutocompleteListCardDropdown = (0, polymorphicComponentWithRef_1.polymor
18
18
  name: 'AutocompleteListCardDropdown',
19
19
  });
20
20
  var _a = props.as, as = _a === void 0 ? constants_1.AUTOCOMPLETE_LIST_CARD_DEFAULT_DROPDOWN_TAG : _a, onClose = props.onClose, other = tslib_1.__rest(props, ["as", "onClose"]);
21
- var _b = (0, context_1.useAutocompleteListCardContext)(), inputRef = _b.inputRef, size = _b.size, dropdownControl = _b.dropdownControl, multiple = _b.multiple, valueControl = _b.valueControl, disabled = _b.disabled;
21
+ var _b = (0, context_1.useAutocompleteListCardContext)(), anchorRef = _b.anchorRef, size = _b.size, dropdownControl = _b.dropdownControl, multiple = _b.multiple, valueControl = _b.valueControl, disabled = _b.disabled;
22
22
  var children = (0, hooks_1.useAutocompleteListCardDropdownChildren)();
23
23
  var updateStored = (0, useStoredValue_1.useStoredValue)(null);
24
24
  var resizeObserver = (0, useCreateResizeObserver_1.useCreateResizeObserver)(function () {
@@ -26,12 +26,12 @@ exports.AutocompleteListCardDropdown = (0, polymorphicComponentWithRef_1.polymor
26
26
  (_a = updateStored.current) === null || _a === void 0 ? void 0 : _a.call(updateStored);
27
27
  });
28
28
  (0, react_1.useEffect)(function () {
29
- var input = inputRef.current;
29
+ var input = anchorRef.current;
30
30
  if (input) {
31
- resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(inputRef.current);
31
+ resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(anchorRef.current);
32
32
  }
33
- }, [inputRef]);
34
- return (react_1.default.createElement(DataListCard_1.DataListCard, tslib_1.__assign({}, other, { ref: ref, as: as, anchorRef: inputRef, size: size, open: dropdownControl.isOpen, onClose: function () {
33
+ }, [anchorRef]);
34
+ return (react_1.default.createElement(DataListCard_1.DataListCard, tslib_1.__assign({}, other, { ref: ref, as: as, anchorRef: anchorRef, size: size, open: dropdownControl.isOpen, onClose: function () {
35
35
  onClose === null || onClose === void 0 ? void 0 : onClose();
36
36
  dropdownControl.close();
37
37
  }, setUpdate: function (update) {
@@ -2,3 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./ButtonBase"), exports);
5
+ tslib_1.__exportStar(require("./constants"), exports);
@@ -13,7 +13,7 @@ export var AutocompleteBase = function (inProps) {
13
13
  props: inProps,
14
14
  name: 'AutocompleteBase',
15
15
  });
16
- var dropdown = props.dropdown, input = props.input, inputValueProp = props.inputValue, _a = props.multiple, multiple = _a === void 0 ? AUTOCOMPLETE_BASE_DEFAULT_MULTIPLE : _a, valueProp = props.value, defaultValue = props.defaultValue, searchFunctionProp = props.searchFunction, optionsProp = props.options, _b = props.prepareOption, prepareOptionProp = _b === void 0 ? autocompleteBaseDefaultPrepareOption : _b, openProp = props.open, defaultOpen = props.defaultOpen, onOpen = props.onOpen, onClose = props.onClose, _c = props.size, size = _c === void 0 ? AUTOCOMPLETE_BASE_DEFAULT_SIZE : _c, _d = props.disabled, disabled = _d === void 0 ? AUTOCOMPLETE_BASE_DEFAULT_DISABLED : _d, onChange = props.onChange, allowCustomValue = props.allowCustomValue, _e = props.loading, loading = _e === void 0 ? AUTOCOMPLETE_BASE_DEFAULT_LOADING : _e, _f = props.closeOnSelect, closeOnSelect = _f === void 0 ? AUTOCOMPLETE_BASE_DEFAULT_CLOSE_ON_SELECT : _f, _g = props.error, error = _g === void 0 ? AUTOCOMPLETE_BASE_DEFAULT_ERROR : _g, onInputChange = props.onInputChange;
16
+ var dropdown = props.dropdown, input = props.input, inputValueProp = props.inputValue, _a = props.multiple, multiple = _a === void 0 ? AUTOCOMPLETE_BASE_DEFAULT_MULTIPLE : _a, valueProp = props.value, defaultValue = props.defaultValue, searchFunctionProp = props.searchFunction, optionsProp = props.options, _b = props.prepareOption, prepareOptionProp = _b === void 0 ? autocompleteBaseDefaultPrepareOption : _b, openProp = props.open, defaultOpen = props.defaultOpen, onOpen = props.onOpen, onClose = props.onClose, _c = props.size, size = _c === void 0 ? AUTOCOMPLETE_BASE_DEFAULT_SIZE : _c, _d = props.disabled, disabled = _d === void 0 ? AUTOCOMPLETE_BASE_DEFAULT_DISABLED : _d, onChange = props.onChange, allowCustomValue = props.allowCustomValue, _e = props.loading, loading = _e === void 0 ? AUTOCOMPLETE_BASE_DEFAULT_LOADING : _e, _f = props.closeOnSelect, closeOnSelect = _f === void 0 ? AUTOCOMPLETE_BASE_DEFAULT_CLOSE_ON_SELECT : _f, _g = props.error, error = _g === void 0 ? AUTOCOMPLETE_BASE_DEFAULT_ERROR : _g, onInputChange = props.onInputChange, onOpenChange = props.onOpenChange;
17
17
  var anchorRef = useRef(null);
18
18
  var inputRef = useRef(null);
19
19
  var dropdownControl = useAutocompleteBaseDropdown({
@@ -21,6 +21,7 @@ export var AutocompleteBase = function (inProps) {
21
21
  defaultOpen: defaultOpen,
22
22
  onOpen: onOpen,
23
23
  onClose: onClose,
24
+ onOpenChange: onOpenChange,
24
25
  });
25
26
  var searchControl = useAutocompleteBaseSearch(searchFunctionProp);
26
27
  var prepareOption = function (option) { return (__assign(__assign({}, prepareOptionProp(option)), { raw: option })); };
@@ -55,6 +56,7 @@ export var AutocompleteBase = function (inProps) {
55
56
  filteredOptions: filteredOptions,
56
57
  valueControl: valueControl,
57
58
  multiple: multiple,
59
+ prepareOption: prepareOption,
58
60
  });
59
61
  var inputEventsControl = useAutocompleteBaseInputEvents({
60
62
  multiple: multiple,
@@ -1,2 +1,3 @@
1
1
  export * from './onClose';
2
2
  export * from './onOpen';
3
+ export * from './onOpenChange';
@@ -1,7 +1,7 @@
1
1
  import { __read } from "tslib";
2
2
  import { useControlled } from '../../../../hooks/useControlled';
3
3
  export var useAutocompleteBaseDropdown = function (_a) {
4
- var openProp = _a.open, defaultOpen = _a.defaultOpen, onClose = _a.onClose, onOpen = _a.onOpen;
4
+ var openProp = _a.open, defaultOpen = _a.defaultOpen, onClose = _a.onClose, onOpen = _a.onOpen, onOpenChange = _a.onOpenChange;
5
5
  var _b = __read(useControlled({
6
6
  value: openProp,
7
7
  defaultValue: defaultOpen,
@@ -12,11 +12,13 @@ export var useAutocompleteBaseDropdown = function (_a) {
12
12
  var close = function () {
13
13
  setIsOpen(false);
14
14
  onClose === null || onClose === void 0 ? void 0 : onClose();
15
+ onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(false);
15
16
  };
16
17
  /** Открытие */
17
18
  var open = function () {
18
19
  setIsOpen(true);
19
20
  onOpen === null || onOpen === void 0 ? void 0 : onOpen();
21
+ onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(true);
20
22
  };
21
23
  /** Переключатель открытия и закрытия */
22
24
  var toggle = function () {
@@ -1,12 +1,24 @@
1
- import { isMultipleInternalValue } from '../../utils';
1
+ import { isId, isInternalOption, isMultipleInternalValue } from '../../utils';
2
2
  export var useAutocompleteBaseOptions = function (_a) {
3
- var options = _a.options, filteredOptions = _a.filteredOptions, valueControl = _a.valueControl, multiple = _a.multiple;
3
+ var options = _a.options, filteredOptions = _a.filteredOptions, valueControl = _a.valueControl, multiple = _a.multiple, prepareOption = _a.prepareOption;
4
4
  var isSelected = function (option) {
5
- var _a, _b, _c;
6
- if (isMultipleInternalValue(valueControl.value, multiple)) {
7
- return ((_b = (_a = valueControl.value) === null || _a === void 0 ? void 0 : _a.some(function (selectedOption) { return selectedOption.id === option.id; })) !== null && _b !== void 0 ? _b : false);
5
+ var valueState = valueControl.value;
6
+ if (valueState === null || valueState === undefined) {
7
+ return false;
8
8
  }
9
- return ((_c = valueControl.value) === null || _c === void 0 ? void 0 : _c.id) === option.id;
9
+ var id = (function () {
10
+ if (isId(option)) {
11
+ return option;
12
+ }
13
+ if (isInternalOption(option)) {
14
+ return option.id;
15
+ }
16
+ return prepareOption(option).id;
17
+ })();
18
+ if (isMultipleInternalValue(valueState, multiple)) {
19
+ return valueState.some(function (option) { return option.id === id; });
20
+ }
21
+ return valueState.id === id;
10
22
  };
11
23
  var hasOptions = (filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.length) > 0;
12
24
  return {
@@ -1,4 +1,5 @@
1
1
  import { __assign, __read, __spreadArray } from "tslib";
2
+ import { logger } from '@ozen-ui/logger';
2
3
  import { useControlled } from '../../../../hooks/useControlled';
3
4
  import { isArray } from '../../../../utils/array';
4
5
  import { isNotNil } from '../../../../utils/isNotNil';
@@ -28,9 +29,9 @@ export var useAutocompleteBaseValue = function (_a) {
28
29
  onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(event, option, params);
29
30
  };
30
31
  var setValue = function (event, optionId, paramsProp) {
31
- var _a, _b, _c, _d;
32
+ var _a, _b, _c, _d, _e;
32
33
  var source = paramsProp.source;
33
- var option = optionId === null
34
+ var option = optionId === null || isArray(optionId)
34
35
  ? null
35
36
  : options.find(function (option) { return option.id === optionId; });
36
37
  if (option === undefined) {
@@ -40,7 +41,19 @@ export var useAutocompleteBaseValue = function (_a) {
40
41
  var params = __assign(__assign({}, inProps), { onChange: onChange });
41
42
  if (isMultipleProps(params) &&
42
43
  isMultipleInternalValue(valueState, multiple)) {
43
- if (option === null) {
44
+ if (isArray(optionId)) {
45
+ var preparedOptions_1 = [];
46
+ optionId.forEach(function (optionId) {
47
+ var option = options.find(function (option) { return option.id === optionId; });
48
+ if (!option) {
49
+ logger.error("\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043D\u0430\u0439\u0442\u0438 option \u0434\u043B\u044F \"".concat(optionId, "\""));
50
+ return;
51
+ }
52
+ preparedOptions_1.push(option.raw);
53
+ });
54
+ (_a = params.onChange) === null || _a === void 0 ? void 0 : _a.call(params, event, preparedOptions_1, { source: source });
55
+ }
56
+ else if (option === null) {
44
57
  onChange === null || onChange === void 0 ? void 0 : onChange(event, null, { source: source });
45
58
  }
46
59
  else {
@@ -61,13 +74,13 @@ export var useAutocompleteBaseValue = function (_a) {
61
74
  }
62
75
  return value_1.map(function (option) { return option.raw; });
63
76
  })();
64
- (_a = params.onChange) === null || _a === void 0 ? void 0 : _a.call(params, event, result, { source: source });
77
+ (_b = params.onChange) === null || _b === void 0 ? void 0 : _b.call(params, event, result, { source: source });
65
78
  }
66
79
  searchControl.deactivate();
67
80
  }
68
81
  else if (isSingleProps(params)) {
69
- inputValue = (_b = option === null || option === void 0 ? void 0 : option.label) !== null && _b !== void 0 ? _b : '';
70
- (_c = params.onChange) === null || _c === void 0 ? void 0 : _c.call(params, event, (_d = option === null || option === void 0 ? void 0 : option.raw) !== null && _d !== void 0 ? _d : null, { source: source });
82
+ inputValue = (_c = option === null || option === void 0 ? void 0 : option.label) !== null && _c !== void 0 ? _c : '';
83
+ (_d = params.onChange) === null || _d === void 0 ? void 0 : _d.call(params, event, (_e = option === null || option === void 0 ? void 0 : option.raw) !== null && _e !== void 0 ? _e : null, { source: source });
71
84
  if (option) {
72
85
  searchControl.deactivate();
73
86
  }
@@ -12,7 +12,7 @@ import { useAutocompleteBaseContext } from '../../AutocompleteBaseContext';
12
12
  var cnAutocompleteBaseDropdown = cn('AutocompleteBaseDropdown');
13
13
  export var AutocompleteBaseDropdown = polymorphicComponentWithRef(function (_a, ref) {
14
14
  var children = _a.children, _b = _a.strategy, strategy = _b === void 0 ? 'absolute' : _b, _c = _a.offset, offset = _c === void 0 ? [0, 4] : _c, _d = _a.placement, placement = _d === void 0 ? 'bottom-start' : _d, _e = _a.as, as = _e === void 0 ? Paper : _e, className = _a.className, onExited = _a.onExited, popoverProps = __rest(_a, ["children", "strategy", "offset", "placement", "as", "className", "onExited"]);
15
- var _f = useAutocompleteBaseContext(), size = _f.size, dropdownControl = _f.dropdownControl, searchControl = _f.searchControl, anchorRef = _f.anchorRef, inputRef = _f.inputRef;
15
+ var _f = useAutocompleteBaseContext(), size = _f.size, dropdownControl = _f.dropdownControl, searchControl = _f.searchControl, anchorRef = _f.anchorRef;
16
16
  var radius = getPaperSizeToFormElement(size);
17
17
  var updateStored = useStoredValue(null);
18
18
  var resizeObserver = useCreateResizeObserver(function () {
@@ -20,11 +20,11 @@ export var AutocompleteBaseDropdown = polymorphicComponentWithRef(function (_a,
20
20
  (_a = updateStored.current) === null || _a === void 0 ? void 0 : _a.call(updateStored);
21
21
  });
22
22
  useEffect(function () {
23
- var input = inputRef.current;
23
+ var input = anchorRef.current;
24
24
  if (input) {
25
- resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(inputRef.current);
25
+ resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(anchorRef.current);
26
26
  }
27
- }, [inputRef]);
27
+ }, [anchorRef]);
28
28
  return (React.createElement(Popover, __assign({ offset: offset, strategy: strategy, placement: placement, setUpdate: function (update) {
29
29
  updateStored.current = update;
30
30
  }, as: as, transitionProps: { classNames: 'AutocompleteBaseDropdown-animation' }, className: cnAutocompleteBaseDropdown('', [className]), equalAnchorWidth: true, disableReturnFocus: true, disableEnforceFocus: true, onExited: function () {
@@ -1,3 +1,5 @@
1
+ export * from './isId';
2
+ export * from './isInternalOption';
1
3
  export * from './isMultiple';
2
4
  export * from './isSingle';
3
5
  export * from './prepareOption';
@@ -0,0 +1,4 @@
1
+ import { isNumber, isString } from '../../../utils';
2
+ export var isId = function (value) {
3
+ return isString(value) || isNumber(value);
4
+ };
@@ -0,0 +1,9 @@
1
+ import { isPlainObject } from '../../../utils';
2
+ export var isInternalOption = function (value) {
3
+ return isPlainObject(value) &&
4
+ Object.keys(value).length === 4 &&
5
+ 'raw' in value &&
6
+ 'disabled' in value &&
7
+ 'label' in value &&
8
+ 'id' in value;
9
+ };
@@ -15,7 +15,7 @@ export var AutocompleteListCardDropdown = polymorphicComponentWithRef(function (
15
15
  name: 'AutocompleteListCardDropdown',
16
16
  });
17
17
  var _a = props.as, as = _a === void 0 ? AUTOCOMPLETE_LIST_CARD_DEFAULT_DROPDOWN_TAG : _a, onClose = props.onClose, other = __rest(props, ["as", "onClose"]);
18
- var _b = useAutocompleteListCardContext(), inputRef = _b.inputRef, size = _b.size, dropdownControl = _b.dropdownControl, multiple = _b.multiple, valueControl = _b.valueControl, disabled = _b.disabled;
18
+ var _b = useAutocompleteListCardContext(), anchorRef = _b.anchorRef, size = _b.size, dropdownControl = _b.dropdownControl, multiple = _b.multiple, valueControl = _b.valueControl, disabled = _b.disabled;
19
19
  var children = useAutocompleteListCardDropdownChildren();
20
20
  var updateStored = useStoredValue(null);
21
21
  var resizeObserver = useCreateResizeObserver(function () {
@@ -23,12 +23,12 @@ export var AutocompleteListCardDropdown = polymorphicComponentWithRef(function (
23
23
  (_a = updateStored.current) === null || _a === void 0 ? void 0 : _a.call(updateStored);
24
24
  });
25
25
  useEffect(function () {
26
- var input = inputRef.current;
26
+ var input = anchorRef.current;
27
27
  if (input) {
28
- resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(inputRef.current);
28
+ resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(anchorRef.current);
29
29
  }
30
- }, [inputRef]);
31
- return (React.createElement(DataListCard, __assign({}, other, { ref: ref, as: as, anchorRef: inputRef, size: size, open: dropdownControl.isOpen, onClose: function () {
30
+ }, [anchorRef]);
31
+ return (React.createElement(DataListCard, __assign({}, other, { ref: ref, as: as, anchorRef: anchorRef, size: size, open: dropdownControl.isOpen, onClose: function () {
32
32
  onClose === null || onClose === void 0 ? void 0 : onClose();
33
33
  dropdownControl.close();
34
34
  }, setUpdate: function (update) {
@@ -1 +1,2 @@
1
1
  export * from './ButtonBase';
2
+ export * from './constants';
@@ -1 +1 @@
1
- export type AutoCompleteBaseInputRef = HTMLElement;
1
+ export type AutoCompleteBaseInputRef = HTMLInputElement;
@@ -1,2 +1,3 @@
1
1
  export * from './onClose';
2
2
  export * from './onOpen';
3
+ export * from './onOpenChange';
@@ -0,0 +1 @@
1
+ export type AutocompleteBaseOnOpenChange = (isOpen: boolean) => void;
@@ -1,8 +1,9 @@
1
- import type { AutocompleteBaseOnClose } from '../../entities';
1
+ import type { AutocompleteBaseOnClose, AutocompleteBaseOnOpen, AutocompleteBaseOnOpenChange } from '../../entities';
2
2
  import type { AutocompleteBaseDropdownControl } from './types';
3
- export declare const useAutocompleteBaseDropdown: ({ open: openProp, defaultOpen, onClose, onOpen, }: {
3
+ export declare const useAutocompleteBaseDropdown: ({ open: openProp, defaultOpen, onClose, onOpen, onOpenChange, }: {
4
4
  open: boolean | undefined;
5
5
  defaultOpen: boolean | undefined;
6
6
  onClose: AutocompleteBaseOnClose | undefined;
7
- onOpen: AutocompleteBaseOnClose | undefined;
7
+ onOpen: AutocompleteBaseOnOpen | undefined;
8
+ onOpenChange: AutocompleteBaseOnOpenChange | undefined;
8
9
  }) => AutocompleteBaseDropdownControl;
@@ -1,5 +1,5 @@
1
- import type { AutocompleteBaseInternalOption } from '../../entities';
2
- export type AutocompleteBaseOptionsIsSelected<Option> = (option: AutocompleteBaseInternalOption<Option>) => boolean;
1
+ import type { AutocompleteBaseInternalOption, AutocompleteBaseOptionId } from '../../entities';
2
+ export type AutocompleteBaseOptionsIsSelected<Option> = (option: AutocompleteBaseInternalOption<Option> | Option | AutocompleteBaseOptionId) => boolean;
3
3
  export type AutocompleteBaseOptionsControl<Option> = {
4
4
  options: AutocompleteBaseInternalOption<Option>[];
5
5
  filteredOptions: AutocompleteBaseInternalOption<Option>[];
@@ -1,9 +1,10 @@
1
- import type { AutocompleteBaseInternalOption } from '../../entities';
1
+ import type { AutocompleteBaseInternalOption, AutocompleteBasePrepareOption } from '../../entities';
2
2
  import type { AutocompleteBaseValueControl } from '../useAutocompleteBaseValue';
3
3
  import type { AutocompleteBaseOptionsControl } from './types';
4
- export declare const useAutocompleteBaseOptions: <Option, Multiple extends boolean>({ options, filteredOptions, valueControl, multiple, }: {
4
+ export declare const useAutocompleteBaseOptions: <Option, Multiple extends boolean>({ options, filteredOptions, valueControl, multiple, prepareOption, }: {
5
5
  options: AutocompleteBaseInternalOption<Option>[];
6
6
  filteredOptions: AutocompleteBaseInternalOption<Option>[];
7
7
  valueControl: AutocompleteBaseValueControl<Option, Multiple>;
8
8
  multiple: boolean;
9
+ prepareOption: AutocompleteBasePrepareOption<Option>;
9
10
  }) => AutocompleteBaseOptionsControl<Option>;
@@ -3,10 +3,10 @@ import type { AutocompleteBaseInternalValue, AutocompleteBaseOnChangeSource, Aut
3
3
  export type AutocompleteBaseValueControlSetValueParams = {
4
4
  source: AutocompleteBaseOnChangeSource;
5
5
  };
6
- export type AutocompleteBaseValueControlSetValue = (event: SyntheticEvent | KeyboardEvent | null, optionId: AutocompleteBaseOptionId | null, params: AutocompleteBaseValueControlSetValueParams) => void;
6
+ export type AutocompleteBaseValueControlSetValue<Multiple extends boolean> = (event: SyntheticEvent | KeyboardEvent | null, optionId: Multiple extends true ? AutocompleteBaseOptionId | AutocompleteBaseOptionId[] | null : AutocompleteBaseOptionId | null, params: AutocompleteBaseValueControlSetValueParams) => void;
7
7
  export type AutocompleteBaseValueControl<Option, Multiple extends boolean> = {
8
8
  value: AutocompleteBaseInternalValue<Option, Multiple> | undefined;
9
- setValue: AutocompleteBaseValueControlSetValue;
9
+ setValue: AutocompleteBaseValueControlSetValue<Multiple>;
10
10
  hasValue: boolean;
11
11
  selectedOptionsLength: number;
12
12
  };
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode } from 'react';
2
- import type { AutocompleteBaseOnInputChange, AutocompleteBaseOnChange, AutocompleteBaseOnClose, AutocompleteBaseOnOpen, AutocompleteBaseDefaultOption, AutocompleteBasePropPrepareOption, AutocompleteBaseSearchFunction, AutocompleteBaseSize, AutocompleteBaseValue } from './entities';
2
+ import type { AutocompleteBaseOnInputChange, AutocompleteBaseOnChange, AutocompleteBaseOnClose, AutocompleteBaseOnOpen, AutocompleteBaseDefaultOption, AutocompleteBasePropPrepareOption, AutocompleteBaseSearchFunction, AutocompleteBaseSize, AutocompleteBaseValue, AutocompleteBaseOnOpenChange } from './entities';
3
3
  export type AutocompleteBaseProps<Option = AutocompleteBaseDefaultOption, Multiple extends boolean = false> = {
4
4
  /** Если `true` из списка можно выбрать несколько вариантов */
5
5
  multiple?: Multiple;
@@ -21,6 +21,8 @@ export type AutocompleteBaseProps<Option = AutocompleteBaseDefaultOption, Multip
21
21
  onOpen?: AutocompleteBaseOnOpen;
22
22
  /** Функция обратного вызова, которая будет вызвана когда компонент запрашивает закрытие */
23
23
  onClose?: AutocompleteBaseOnClose;
24
+ /** Функция обратного вызова, которая будет вызвана когда компонент запрашивает закрытие/открытие */
25
+ onOpenChange?: AutocompleteBaseOnOpenChange;
24
26
  /** Функция обратного вызова, которая будет вызвана при выборе значения */
25
27
  onChange?: AutocompleteBaseOnChange<Option, Multiple>;
26
28
  /** Функция обратного вызова, которая будет вызвана при вводе значения с клавиатуры */
@@ -1,3 +1,5 @@
1
+ export * from './isId';
2
+ export * from './isInternalOption';
1
3
  export * from './isMultiple';
2
4
  export * from './isSingle';
3
5
  export * from './prepareOption';
@@ -0,0 +1,2 @@
1
+ import type { AutocompleteBaseOptionId } from '../entities';
2
+ export declare const isId: (value: unknown) => value is AutocompleteBaseOptionId;
@@ -0,0 +1,2 @@
1
+ import type { AutocompleteBaseInternalOption } from '../entities';
2
+ export declare const isInternalOption: (value: unknown) => value is AutocompleteBaseInternalOption<unknown>;
@@ -1 +1,2 @@
1
1
  export * from './ButtonBase';
2
+ export * from './constants';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ozen-ui/kit",
3
- "version": "0.83.3",
3
+ "version": "0.84.0",
4
4
  "description": "React component library",
5
5
  "files": [
6
6
  "*"
@@ -29,9 +29,9 @@
29
29
  "react-popper": "^2.3.0",
30
30
  "react-transition-group": "^4.4.5",
31
31
  "tslib": "^2.6.3",
32
- "@ozen-ui/fonts": "0.83.3",
33
- "@ozen-ui/icons": "0.83.3",
34
- "@ozen-ui/logger": "0.83.3"
32
+ "@ozen-ui/fonts": "0.84.0",
33
+ "@ozen-ui/icons": "0.84.0",
34
+ "@ozen-ui/logger": "0.84.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/lodash.isequal": "^4.5.0"