@reltio/components 1.4.1667 → 1.4.1668

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 (45) hide show
  1. package/cjs/components/ConnectionEditor/ConnectionEditor.js +2 -2
  2. package/cjs/components/EntityUriLink/EntityUriLink.d.ts +3 -5
  3. package/cjs/components/EntityUriLink/EntityUriLink.js +6 -8
  4. package/cjs/components/ValueChip/ValueChip.d.ts +7 -14
  5. package/cjs/components/ValueChip/ValueChip.js +1 -7
  6. package/cjs/components/ValueChip/styles.d.ts +2 -2
  7. package/cjs/components/attributes/editMode/NestedAttribute/NestedAttribute.d.ts +1 -1
  8. package/cjs/components/attributes/editMode/Tags/Tags.js +63 -19
  9. package/cjs/components/attributes/inline/ComplexAttribute/ComplexAttribute.js +2 -2
  10. package/cjs/components/attributes/inline/NestedAttributesBlock/NestedAttributesBlock.js +1 -1
  11. package/cjs/components/attributes/inline/SimpleAttribute/SimpleAttribute.js +2 -2
  12. package/cjs/components/attributes/inline/SimpleAttributesBlock/SimpleAttributesBlock.js +1 -1
  13. package/cjs/components/attributes/readMode/NestedAttribute/NestedAttribute.d.ts +1 -1
  14. package/cjs/components/crosswalks/AttributesTable/AddAttributesButton/AddAttributesButton.js +1 -1
  15. package/cjs/components/editors/DataTypeValueEditor/useEditorContext.d.ts +1 -1
  16. package/cjs/components/editors/TypeaheadEditor/TypeaheadEditor.d.ts +20 -24
  17. package/cjs/components/editors/TypeaheadEditor/TypeaheadEditor.js +155 -83
  18. package/cjs/components/editors/TypeaheadEditor/styles.d.ts +1 -1
  19. package/cjs/components/editors/TypeaheadEditor/styles.js +17 -17
  20. package/cjs/components/history/ContributorsPanel/styles.d.ts +1 -1
  21. package/cjs/hooks/useCommentsEntitiesMap.js +1 -1
  22. package/cjs/hooks/useMatchesLoader.js +2 -2
  23. package/esm/components/ConnectionEditor/ConnectionEditor.js +3 -3
  24. package/esm/components/EntityUriLink/EntityUriLink.d.ts +3 -5
  25. package/esm/components/EntityUriLink/EntityUriLink.js +6 -8
  26. package/esm/components/ValueChip/ValueChip.d.ts +7 -14
  27. package/esm/components/ValueChip/ValueChip.js +1 -7
  28. package/esm/components/ValueChip/styles.d.ts +2 -2
  29. package/esm/components/attributes/editMode/NestedAttribute/NestedAttribute.d.ts +1 -1
  30. package/esm/components/attributes/editMode/Tags/Tags.js +65 -21
  31. package/esm/components/attributes/inline/ComplexAttribute/ComplexAttribute.js +3 -3
  32. package/esm/components/attributes/inline/NestedAttributesBlock/NestedAttributesBlock.js +2 -2
  33. package/esm/components/attributes/inline/SimpleAttribute/SimpleAttribute.js +3 -3
  34. package/esm/components/attributes/inline/SimpleAttributesBlock/SimpleAttributesBlock.js +2 -2
  35. package/esm/components/attributes/readMode/NestedAttribute/NestedAttribute.d.ts +1 -1
  36. package/esm/components/crosswalks/AttributesTable/AddAttributesButton/AddAttributesButton.js +2 -2
  37. package/esm/components/editors/DataTypeValueEditor/useEditorContext.d.ts +1 -1
  38. package/esm/components/editors/TypeaheadEditor/TypeaheadEditor.d.ts +20 -24
  39. package/esm/components/editors/TypeaheadEditor/TypeaheadEditor.js +155 -83
  40. package/esm/components/editors/TypeaheadEditor/styles.d.ts +1 -1
  41. package/esm/components/editors/TypeaheadEditor/styles.js +17 -17
  42. package/esm/components/history/ContributorsPanel/styles.d.ts +1 -1
  43. package/esm/hooks/useCommentsEntitiesMap.js +2 -2
  44. package/esm/hooks/useMatchesLoader.js +3 -3
  45. package/package.json +2 -2
@@ -1,33 +1,77 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
1
48
  import React, { useCallback } from 'react';
2
- import { getFacets, EntityAttrTypes, buildFilterQueryString } from '@reltio/mdm-sdk';
49
+ import { EntityAttrTypes, getFacetedAttributeData } from '@reltio/mdm-sdk';
3
50
  import DeleteIcon from '@mui/icons-material/Delete';
4
51
  import TypeaheadEditor from '../../../editors/TypeaheadEditor/TypeaheadEditor';
5
52
  import SmallIconButton from '../../../SmallIconButton/SmallIconButton';
6
- import { useMdmEntityUri } from '../../../../contexts';
53
+ import { useMdmEntityUri, useMdmGlobalSearchRequestOptions } from '../../../../contexts';
7
54
  import { useStyles } from './styles';
8
- var filtersWithSearch = function (searchQuery) { return [
9
- {
10
- filter: 'containsWordStartingWith',
11
- fieldName: 'tags',
12
- values: [searchQuery]
13
- }
14
- ]; };
15
- var getQuery = function (searchQuery) {
16
- return searchQuery ? "?filter=".concat(buildFilterQueryString()(filtersWithSearch(searchQuery))) : '';
17
- };
18
- var body = [
19
- {
20
- fieldName: 'tags',
21
- orderType: 'reversedCount'
22
- }
23
- ];
24
- var getSuggestions = function (searchQuery) {
25
- return getFacets({ query: getQuery(searchQuery), body: body }).then(function (response) { return Object.keys(response.tags); });
26
- };
27
55
  var Tags = function (_a) {
28
56
  var className = _a.className, values = _a.values, onChange = _a.onChange, onDelete = _a.onDelete;
29
57
  var styles = useStyles();
30
58
  var entityUri = useMdmEntityUri();
59
+ var globalSearchRequestOptions = useMdmGlobalSearchRequestOptions();
60
+ var getSuggestions = useCallback(function (searchValue, max, pageNo) { return __awaiter(void 0, void 0, void 0, function () {
61
+ var response;
62
+ return __generator(this, function (_a) {
63
+ switch (_a.label) {
64
+ case 0: return [4 /*yield*/, getFacetedAttributeData({
65
+ fieldName: 'tags',
66
+ searchValue: searchValue,
67
+ options: __assign(__assign({}, globalSearchRequestOptions), { max: max, pageNo: pageNo })
68
+ })];
69
+ case 1:
70
+ response = _a.sent();
71
+ return [2 /*return*/, Object.keys(response.tags)];
72
+ }
73
+ });
74
+ }); }, [globalSearchRequestOptions]);
31
75
  var handleChange = useCallback(function (tags) {
32
76
  onChange({
33
77
  value: tags,
@@ -1,5 +1,5 @@
1
1
  import React, { useState } from 'react';
2
- import { areOneHierarchyUris, checkMetadataForDelete, checkMetadataForUpdate, isTempUri, getCrosswalkId, ModeTypes } from '@reltio/mdm-sdk';
2
+ import { areOneHierarchyUris, checkMetadataForDelete, checkMetadataForUpdate, isTempUri, getCrosswalkId, Mode } from '@reltio/mdm-sdk';
3
3
  import { useAttributeState } from '../hooks/useAttributeState';
4
4
  import { Spacer } from '../../../index';
5
5
  import CrosswalkIcon from '../common/CrosswalkIcon';
@@ -16,8 +16,8 @@ var ComplexAttribute = function (_a) {
16
16
  var attributeType = _a.attributeType, attributeValue = _a.attributeValue, attributeTypesList = _a.attributeTypesList, label = _a.label, crosswalksMap = _a.crosswalksMap, disableEdit = _a.disableEdit, disableDelete = _a.disableDelete, onPin = _a.onPin, onIgnore = _a.onIgnore, onDelete = _a.onDelete, onEdit = _a.onEdit, onAdd = _a.onAdd, emptyTempAttributeUris = _a.emptyTempAttributeUris;
17
17
  var styles = useStyles();
18
18
  var _b = useAttributeState(), isReadingMode = _b.isReadingMode, onMouseEnter = _b.onMouseEnter, onMouseLeave = _b.onMouseLeave;
19
- var canEdit = !disableEdit && checkMetadataForUpdate(ModeTypes.EDITING, attributeType);
20
- var canDelete = !disableDelete && checkMetadataForDelete(ModeTypes.EDITING, attributeType);
19
+ var canEdit = !disableEdit && checkMetadataForUpdate(Mode.Editing, attributeType);
20
+ var canDelete = !disableDelete && checkMetadataForDelete(Mode.Editing, attributeType);
21
21
  var isTemporary = isTempUri(attributeValue.uri);
22
22
  var showPin = !isTemporary && ((!isReadingMode && canEdit) || attributeValue.pin);
23
23
  var showIgnore = !isTemporary && ((!isReadingMode && canEdit) || attributeValue.ignored);
@@ -21,13 +21,13 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  return t;
22
22
  };
23
23
  import React from 'react';
24
- import { checkMetadataForCreate, ModeTypes } from '@reltio/mdm-sdk';
24
+ import { checkMetadataForCreate, Mode } from '@reltio/mdm-sdk';
25
25
  import NestedAttribute from '../NestedAttribute/NestedAttribute';
26
26
  import Button from '@mui/material/Button';
27
27
  import i18n from 'ui-i18n';
28
28
  var NestedAttributesBlock = function (_a) {
29
29
  var className = _a.className, attributeValues = _a.attributeValues, attributeType = _a.attributeType, onAdd = _a.onAdd, parentUri = _a.parentUri, disableEdit = _a.disableEdit, props = __rest(_a, ["className", "attributeValues", "attributeType", "onAdd", "parentUri", "disableEdit"]);
30
- var canCreate = !disableEdit && checkMetadataForCreate(ModeTypes.EDITING, attributeType);
30
+ var canCreate = !disableEdit && checkMetadataForCreate(Mode.Editing, attributeType);
31
31
  return attributeValues.length === 0 && canCreate ? (React.createElement(Button, { variant: "text", color: "primary", onClick: function () {
32
32
  return onAdd({
33
33
  parentUri: parentUri,
@@ -2,7 +2,7 @@ import React, { useEffect, useRef } from 'react';
2
2
  import DeleteIcon from '@mui/icons-material/Delete';
3
3
  import EditIcon from '@mui/icons-material/Edit';
4
4
  import MoreVertIcon from '@mui/icons-material/MoreVert';
5
- import { checkMetadataForDelete, checkMetadataForUpdate, getAttrDataTypeDefinition, getAttributeValue, getLastUriPart, isAutoGeneratedAttribute, isCrosswalkDisabled, isTempUri, MetadataPermissions, ModeTypes, checkBasicMetadataPermission } from '@reltio/mdm-sdk';
5
+ import { checkMetadataForDelete, checkMetadataForUpdate, getAttrDataTypeDefinition, getAttributeValue, getLastUriPart, isAutoGeneratedAttribute, isCrosswalkDisabled, isTempUri, MetadataPermissions, Mode, checkBasicMetadataPermission } from '@reltio/mdm-sdk';
6
6
  import classnames from 'classnames';
7
7
  import i18n from 'ui-i18n';
8
8
  import DataTypeValue from '../../../DataTypeValue/DataTypeValue';
@@ -22,8 +22,8 @@ var SimpleAttribute = function (_a) {
22
22
  var id = getLastUriPart(attributeValue.uri);
23
23
  var crosswalkDisabled = isCrosswalkDisabled(crosswalk);
24
24
  var canModifyAttribute = !attributeType.system && !crosswalkDisabled;
25
- var canEdit = canModifyAttribute && !disableEdit && checkMetadataForUpdate(ModeTypes.EDITING, attributeType);
26
- var canDelete = canModifyAttribute && !disableDelete && checkMetadataForDelete(ModeTypes.EDITING, attributeType);
25
+ var canEdit = canModifyAttribute && !disableEdit && checkMetadataForUpdate(Mode.Editing, attributeType);
26
+ var canDelete = canModifyAttribute && !disableDelete && checkMetadataForDelete(Mode.Editing, attributeType);
27
27
  var isTemporary = isTempUri(attributeValue.uri);
28
28
  var hasBasicPermission = checkBasicMetadataPermission(MetadataPermissions.UPDATE, attributeType) && !disableEdit && canModifyAttribute;
29
29
  var showPin = !isTemporary && ((!isReadingMode && hasBasicPermission) || attributeValue.pin);
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  };
23
23
  import React from 'react';
24
24
  import SimpleAttribute from '../SimpleAttribute';
25
- import { checkMetadataForCreate, isEntityTypeUri, isEntityUri, isRelationTypeUri, isRelationUri, ModeTypes } from '@reltio/mdm-sdk';
25
+ import { checkMetadataForCreate, isEntityTypeUri, isEntityUri, isRelationTypeUri, isRelationUri, Mode } from '@reltio/mdm-sdk';
26
26
  import { useDrop } from 'react-dnd';
27
27
  import i18n from 'ui-i18n';
28
28
  import { useStyles } from './styles';
@@ -35,7 +35,7 @@ var SimpleAttributesBlock = function (_a) {
35
35
  var crosswalk = _a.crosswalk;
36
36
  var isRelationCrosswalk = isRelationUri(crosswalk.uri) || crosswalk.ownerType === 'relation';
37
37
  var isEntityCrosswalk = isEntityUri(crosswalk.uri) && crosswalk.ownerType === 'entity';
38
- return (checkMetadataForCreate(ModeTypes.EDITING, attributeType) &&
38
+ return (checkMetadataForCreate(Mode.Editing, attributeType) &&
39
39
  !disableEdit &&
40
40
  ((isRelationCrosswalk && isRelationTypeUri(attributeType.uri)) ||
41
41
  (isEntityCrosswalk && isEntityTypeUri(attributeType.uri))));
@@ -22,7 +22,7 @@ declare const _default: React.MemoExoticComponent<{
22
22
  }>>;
23
23
  showEmptyEditors: import("prop-types").Requireable<boolean>;
24
24
  lazy: import("prop-types").Requireable<boolean>;
25
- mode: import("prop-types").Requireable<any>;
25
+ mode: import("prop-types").Requireable<import("@reltio/mdm-sdk").Mode>;
26
26
  metadata: import("prop-types").Requireable<import("prop-types").InferProps<{
27
27
  uri: import("prop-types").Requireable<string>;
28
28
  description: import("prop-types").Requireable<string>;
@@ -12,7 +12,7 @@ import MoreAttributesButton from '../../../attributes/editMode/MoreAttributesBut
12
12
  import { withTableContext } from '../../../BasicTableView';
13
13
  import i18n from 'ui-i18n';
14
14
  import { both, either, filter, pick, pipe, propEq, propOr, reject } from 'ramda';
15
- import { checkCanCreateAttribute, isImage, isNested, isReadableAttribute, isReference, ModeTypes } from '@reltio/mdm-sdk';
15
+ import { checkCanCreateAttribute, isImage, isNested, isReadableAttribute, isReference, Mode } from '@reltio/mdm-sdk';
16
16
  import { useMdmMetadata } from '../../../../contexts';
17
17
  import { useStyles } from './styles';
18
18
  export var AddAttributesButton = function (_a) {
@@ -21,7 +21,7 @@ export var AddAttributesButton = function (_a) {
21
21
  var metadata = useMdmMetadata();
22
22
  var parentType = __spreadArray(__spreadArray([], metadata.entityTypes, true), (metadata.relationTypes || []), true).find(propEq('uri', parentTypeUri));
23
23
  var isNotSelected = function (attrType) { return !(selectedAttributeTypes === null || selectedAttributeTypes === void 0 ? void 0 : selectedAttributeTypes.find(propEq('uri', attrType.uri))); };
24
- var canCreate = function (attributeType) { return checkCanCreateAttribute({ attributeType: attributeType, mode: ModeTypes.EDITING }); };
24
+ var canCreate = function (attributeType) { return checkCanCreateAttribute({ attributeType: attributeType, mode: Mode.Editing }); };
25
25
  var data = pipe(propOr([], 'attributes'), reject(either(isReference, isImage)), filter(either(isNested, isNotSelected)), filter(both(isReadableAttribute, canCreate)))(parentType);
26
26
  var handleAdd = function (addedTypes) {
27
27
  var typesToSelect = addedTypes.filter(isNotSelected);
@@ -33,7 +33,7 @@ declare function useEditorContext(fieldName: any, dataTypeDefinition: any): {
33
33
  format?: undefined;
34
34
  tenant?: undefined;
35
35
  } | {
36
- getSuggestions: (searchValue: any, max: any, pageNo: any) => Promise<any>;
36
+ getSuggestions: (searchValue: any, max: any, pageNo: any) => Promise<Record<string, unknown>>;
37
37
  entries?: undefined;
38
38
  lookups?: undefined;
39
39
  lookupCode?: undefined;
@@ -1,26 +1,22 @@
1
- export default TypeaheadEditor;
2
- declare function TypeaheadEditor({ value, max, getSuggestions, onChange, multiple, fullWidth, InputProps, isCrossedOut, ...inputProps }: {
3
- [x: string]: any;
4
- value: any;
1
+ /// <reference types="react" />
2
+ import { TextFieldProps } from '@mui/material/TextField';
3
+ type CommonProps = Omit<TextFieldProps, 'onChange' | 'value'> & {
4
+ getSuggestions?: (value: string, pageSize: number, pageNumber?: number) => Promise<string[]>;
5
5
  max?: number;
6
- getSuggestions: any;
7
- onChange: any;
8
- multiple: any;
9
- fullWidth: any;
10
- InputProps?: {};
6
+ multiple?: boolean;
7
+ fullWidth?: boolean;
11
8
  isCrossedOut?: boolean;
12
- }): JSX.Element;
13
- declare namespace TypeaheadEditor {
14
- namespace propTypes {
15
- const multiple: PropTypes.Requireable<boolean>;
16
- const fullWidth: PropTypes.Requireable<boolean>;
17
- const placeholder: PropTypes.Requireable<string>;
18
- const value: PropTypes.Requireable<NonNullable<string | string[]>>;
19
- const onChange: PropTypes.Validator<(...args: any[]) => any>;
20
- const getSuggestions: PropTypes.Validator<(...args: any[]) => any>;
21
- const InputProps: PropTypes.Requireable<object>;
22
- const max: PropTypes.Requireable<number>;
23
- const isCrossedOut: PropTypes.Requireable<boolean>;
24
- }
25
- }
26
- import PropTypes from 'prop-types';
9
+ };
10
+ type MultipleProps = CommonProps & {
11
+ value: string[];
12
+ onChange: (values: string[]) => void;
13
+ multiple: true;
14
+ };
15
+ type SingleProps = CommonProps & {
16
+ value: string;
17
+ onChange: (value: string) => void;
18
+ multiple?: false;
19
+ };
20
+ export type Props = MultipleProps | SingleProps;
21
+ declare const TypeaheadEditor: ({ value, max, getSuggestions, onChange, multiple, fullWidth, InputProps, isCrossedOut, ...inputProps }: Props) => JSX.Element;
22
+ export default TypeaheadEditor;
@@ -9,6 +9,42 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
12
48
  var __rest = (this && this.__rest) || function (s, e) {
13
49
  var t = {};
14
50
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -29,133 +65,169 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
29
65
  }
30
66
  return to.concat(ar || Array.prototype.slice.call(from));
31
67
  };
68
+ import React, { useCallback, useRef, useMemo, useState, useEffect } from 'react';
69
+ import { identity, isEmpty, nthArg, path, pipe, prop, remove, T, uniq } from 'ramda';
70
+ import classnames from 'classnames';
71
+ import { debounce, isEmptyValue } from '@reltio/mdm-sdk';
32
72
  import Autosuggest from 'react-autosuggest';
33
73
  import AutosizeInput from 'react-input-autosize';
34
- import classnames from 'classnames';
35
74
  import TextField from '@mui/material/TextField';
36
75
  import MenuItem from '@mui/material/MenuItem';
37
76
  import Paper from '@mui/material/Paper';
77
+ import { useDidUpdateEffect } from '../../../hooks';
38
78
  import Popper from '../../Popper/Popper';
39
- import PropTypes from 'prop-types';
40
- import React, { useCallback, useRef, useMemo, useState } from 'react';
41
79
  import { NoResults } from '../../../components/EmptySearchResult';
42
- import { always, andThen, both, concat, defaultTo, F, identity, ifElse, isEmpty, nthArg, path, pipe, prop, propEq, remove, T, tap, trim, uniq } from 'ramda';
43
- import { debounce, isEmptyValue } from '@reltio/mdm-sdk';
44
- import { getValue } from '../../../core/utils';
45
- import { useStyles } from './styles';
46
80
  import ExpandedValueTooltip from '../../ExpandedValueTooltip/ExpandedValueTooltip';
47
81
  import ValueChip from '../../ValueChip/ValueChip';
48
82
  import LoadMoreButton from '../../commonReactSelectComponents/LoadMoreButton';
49
- import { useDidUpdateEffect } from '../../../hooks';
83
+ import { useStyles } from './styles';
50
84
  var FETCH_DEBOUNCE_INTERVAL = 300;
51
85
  var PAGE_SIZE = 50;
86
+ var ChangeMethod;
87
+ (function (ChangeMethod) {
88
+ ChangeMethod["Type"] = "type";
89
+ ChangeMethod["Escape"] = "escape";
90
+ ChangeMethod["Click"] = "click";
91
+ ChangeMethod["Enter"] = "enter";
92
+ })(ChangeMethod || (ChangeMethod = {}));
52
93
  var TypeaheadEditor = function (_a) {
53
94
  var value = _a.value, _b = _a.max, max = _b === void 0 ? PAGE_SIZE : _b, getSuggestions = _a.getSuggestions, onChange = _a.onChange, multiple = _a.multiple, fullWidth = _a.fullWidth, _c = _a.InputProps, InputProps = _c === void 0 ? {} : _c, _d = _a.isCrossedOut, isCrossedOut = _d === void 0 ? false : _d, inputProps = __rest(_a, ["value", "max", "getSuggestions", "onChange", "multiple", "fullWidth", "InputProps", "isCrossedOut"]);
95
+ var styles = useStyles();
96
+ var inputRef = useRef(null);
54
97
  var _e = useState([]), suggestions = _e[0], setSuggestions = _e[1];
55
98
  var _f = useState(false), isPlaceholderVisible = _f[0], setPlaceholderVisibility = _f[1];
56
99
  var _g = useState(1), pageNumber = _g[0], setPageNumber = _g[1];
57
100
  var _h = useState(false), nextPageIsLoading = _h[0], setNextPageIsLoading = _h[1];
101
+ var _j = useState(''), inputValue = _j[0], setInputValue = _j[1];
102
+ var _k = useState(null), highlightedItem = _k[0], setHighlightedItem = _k[1];
58
103
  var pageSizeForRequest = max + 1;
59
- var _j = useState(''), currentValue = _j[0], setCurrentValue = _j[1];
60
- value = defaultTo(multiple ? [] : '', value);
61
- var inputValue = multiple ? currentValue : value;
62
- useDidUpdateEffect(function () {
63
- setPageNumber(1);
64
- }, [inputValue]);
65
- var inputRef = useRef();
66
- var styles = useStyles();
104
+ var displayedSuggestions = useMemo(function () { return suggestions.slice(0, pageNumber * max); }, [suggestions, pageNumber, max]);
105
+ var showMoreButton = suggestions.length > displayedSuggestions.length;
67
106
  var isFocused = function () { var _a; return ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('input')) === document.activeElement; };
68
- var fetchSuggestions = pipe(prop('value'), trim, function (value) { return getSuggestions(value, pageSizeForRequest); }, andThen(pipe(tap(setSuggestions), both(isEmpty, isFocused), setPlaceholderVisibility)));
69
- var onLoadMoreSuggestions = function () {
70
- setNextPageIsLoading(true);
71
- getSuggestions(inputValue, pageSizeForRequest, pageNumber + 1)
72
- .then(pipe(concat(suggestions), setSuggestions, always(pageNumber + 1), setPageNumber))
73
- .finally(function () {
74
- setNextPageIsLoading(false);
107
+ var fetchSuggestions = useCallback(function (_a) {
108
+ var value = _a.value;
109
+ return __awaiter(void 0, void 0, void 0, function () {
110
+ var response;
111
+ return __generator(this, function (_b) {
112
+ switch (_b.label) {
113
+ case 0: return [4 /*yield*/, getSuggestions(value.trim(), pageSizeForRequest)];
114
+ case 1:
115
+ response = _b.sent();
116
+ setSuggestions(response);
117
+ setPlaceholderVisibility(isEmpty(response) && isFocused());
118
+ return [2 /*return*/];
119
+ }
120
+ });
75
121
  });
76
- };
77
- var onMouseDown = function (event) {
78
- event.preventDefault();
79
- };
122
+ }, [getSuggestions, pageSizeForRequest]);
80
123
  var debouncedFetchSuggestions = useCallback(debounce(fetchSuggestions, FETCH_DEBOUNCE_INTERVAL), [
81
124
  getSuggestions
82
125
  ]);
83
- var displayedSuggestions = useMemo(function () { return suggestions.slice(0, pageNumber * max); }, [suggestions, pageNumber, max]);
84
- var showMoreButton = suggestions.length > displayedSuggestions.length;
85
- var _k = useState(false), hasHighlightedItem = _k[0], setHasHighlightedItem = _k[1];
86
- var onInputChange = function (_a) {
126
+ var handleLoadMoreSuggestions = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
127
+ var response_1;
128
+ return __generator(this, function (_a) {
129
+ switch (_a.label) {
130
+ case 0:
131
+ setNextPageIsLoading(true);
132
+ _a.label = 1;
133
+ case 1:
134
+ _a.trys.push([1, , 3, 4]);
135
+ return [4 /*yield*/, getSuggestions(inputValue, pageSizeForRequest, pageNumber + 1)];
136
+ case 2:
137
+ response_1 = _a.sent();
138
+ setSuggestions(function (prevSuggestions) { return __spreadArray(__spreadArray([], prevSuggestions, true), response_1, true); });
139
+ setPageNumber(function (prevPageNumber) { return prevPageNumber + 1; });
140
+ return [3 /*break*/, 4];
141
+ case 3:
142
+ setNextPageIsLoading(false);
143
+ return [7 /*endfinally*/];
144
+ case 4: return [2 /*return*/];
145
+ }
146
+ });
147
+ }); }, [getSuggestions, inputValue, pageNumber, pageSizeForRequest]);
148
+ var handleSuggestionsFetchRequested = useCallback(function (value) {
149
+ if (value.reason === 'input-changed') {
150
+ debouncedFetchSuggestions(value);
151
+ }
152
+ else {
153
+ fetchSuggestions(value);
154
+ }
155
+ }, [debouncedFetchSuggestions, fetchSuggestions]);
156
+ var handleSuggestionsClearRequested = useCallback(function () {
157
+ setSuggestions([]);
158
+ setPlaceholderVisibility(false);
159
+ setPageNumber(1);
160
+ }, []);
161
+ var handleSuggestionHighlighted = useCallback(function (_a) {
162
+ var suggestion = _a.suggestion;
163
+ setHighlightedItem(suggestion);
164
+ }, []);
165
+ var handleInputValueChange = useCallback(function (_a) {
87
166
  var newValue = _a.newValue, method = _a.method;
88
167
  switch (method) {
89
- case 'type': {
90
- if (multiple) {
91
- setCurrentValue(newValue);
92
- }
93
- break;
94
- }
95
- case 'escape': {
96
- if (multiple) {
97
- setCurrentValue(newValue);
98
- }
99
- else {
100
- onChange(newValue);
101
- }
168
+ case ChangeMethod.Type:
169
+ case ChangeMethod.Escape:
170
+ setInputValue(newValue);
102
171
  break;
103
- }
104
- case 'click':
105
- case 'enter': {
106
- if (multiple) {
107
- setCurrentValue('');
108
- if (newValue) {
172
+ case ChangeMethod.Click:
173
+ case ChangeMethod.Enter: {
174
+ if (multiple === true) {
175
+ if (newValue)
109
176
  onChange(uniq(__spreadArray(__spreadArray([], value, true), [newValue], false)));
110
- }
177
+ setInputValue('');
111
178
  }
112
179
  else {
113
- onChange(newValue);
180
+ setInputValue(newValue);
114
181
  }
115
- break;
116
182
  }
117
183
  }
118
- };
119
- return (React.createElement(Autosuggest, { suggestions: displayedSuggestions, shouldRenderSuggestions: T, inputProps: __assign(__assign({ value: inputValue, onChange: pipe(nthArg(1), onInputChange), onKeyDown: function (event) {
120
- if (event.code === 'Enter' && multiple && !hasHighlightedItem) {
121
- onInputChange({ method: 'enter', newValue: currentValue });
122
- }
123
- }, fullWidth: fullWidth }, inputProps), { autoComplete: 'nope' }), getSuggestionValue: identity, onSuggestionsFetchRequested: ifElse(propEq('reason', 'input-changed'), debouncedFetchSuggestions, fetchSuggestions), onSuggestionsClearRequested: pipe(always([]), setSuggestions, F, setPlaceholderVisibility, always(1), setPageNumber), renderInputComponent: function (_a) {
184
+ }, [multiple, onChange, value]);
185
+ var handleKeyDown = useCallback(function (event) {
186
+ if (event.code !== 'Enter' || highlightedItem)
187
+ return;
188
+ if (multiple === true) {
189
+ handleInputValueChange({ method: ChangeMethod.Enter, newValue: inputValue });
190
+ }
191
+ else {
192
+ onChange(inputValue);
193
+ }
194
+ }, [handleInputValueChange, onChange, highlightedItem, inputValue, multiple]);
195
+ var handleBlur = useCallback(function () {
196
+ if (multiple !== true)
197
+ onChange(inputValue);
198
+ }, [inputValue, onChange, multiple]);
199
+ useEffect(function () {
200
+ if (multiple !== true)
201
+ setInputValue(value !== null && value !== void 0 ? value : '');
202
+ }, [value, multiple]);
203
+ useDidUpdateEffect(function () {
204
+ setPageNumber(1);
205
+ }, [inputValue]);
206
+ return (React.createElement(Autosuggest, { suggestions: displayedSuggestions, shouldRenderSuggestions: T, getSuggestionValue: identity, onSuggestionsFetchRequested: handleSuggestionsFetchRequested, onSuggestionsClearRequested: handleSuggestionsClearRequested, onSuggestionHighlighted: handleSuggestionHighlighted, theme: {
207
+ container: fullWidth ? styles.suggestionsContainer : '',
208
+ suggestionsList: styles.suggestionsList,
209
+ suggestionsContainerOpen: styles.suggestionsContainerOpen
210
+ }, inputProps: __assign({ value: inputValue, onChange: pipe(nthArg(1), handleInputValueChange), onKeyDown: handleKeyDown, onBlur: handleBlur, fullWidth: fullWidth, variant: 'standard', autoComplete: 'nope' }, inputProps), renderInputComponent: function (_a) {
124
211
  var _b, _c;
125
- var ref = _a.ref, onInputChange = _a.onChange, otherProps = __rest(_a, ["ref", "onChange"]);
212
+ var ref = _a.ref, otherProps = __rest(_a, ["ref"]);
126
213
  var commonClasses = {
127
- underline: classnames((_b = {}, _b[styles['input__underline']] = isEmptyValue(value), _b)),
214
+ underline: classnames((_b = {}, _b[styles.underline] = isEmptyValue(value), _b)),
128
215
  input: classnames(styles['rawInput'], path(['classes', 'input'], InputProps))
129
216
  };
130
- return multiple ? (React.createElement(TextField, __assign({ variant: "standard" }, otherProps, { ref: inputRef, inputRef: ref, InputProps: __assign(__assign({}, InputProps), { startAdornment: value.map(function (item, index) { return (React.createElement(ValueChip, { key: item, label: item, onDelete: function () { return onChange(remove(index, 1, value)); } })); }), inputComponent: AutosizeInput, classes: __assign(__assign({ root: classnames(styles['multiple-input__input'], path(['classes', 'root'], InputProps)) }, commonClasses), { input: classnames(styles.autosizeInput, commonClasses.input), adornedStart: styles['multiple-input__adornedStart'] }) }), value: currentValue, onChange: onInputChange, classes: { root: styles['multiple-input__root'] } }))) : (React.createElement(TextField, __assign({ variant: "standard" }, otherProps, { ref: inputRef, inputRef: ref, value: value, onChange: pipe(tap(onInputChange), getValue, onChange), InputProps: __assign(__assign({}, InputProps), { classes: __assign({ root: classnames(styles['input__root'], path(['classes', 'root'], InputProps), (_c = {},
217
+ return multiple === true ? (React.createElement(TextField, __assign({}, otherProps, { ref: inputRef, inputRef: ref, InputProps: __assign(__assign({}, InputProps), { startAdornment: value.map(function (item, index) { return (React.createElement(ValueChip, { key: item, label: item, onDelete: function () { return onChange(remove(index, 1, value)); } })); }), inputComponent: AutosizeInput, classes: __assign(__assign({ root: classnames(styles.multipleTextFieldInput, path(['classes', 'root'], InputProps)) }, commonClasses), { input: classnames(styles.autosizeInput, commonClasses.input), adornedStart: styles.multipleTextFieldAdornedStart }) }), classes: { root: styles.multipleTextField } }))) : (React.createElement(TextField, __assign({}, otherProps, { ref: inputRef, inputRef: ref, InputProps: __assign(__assign({}, InputProps), { classes: __assign({ root: classnames(styles.inputRoot, path(['classes', 'root'], InputProps), (_c = {},
131
218
  _c[styles.isCrossedOut] = isCrossedOut,
132
219
  _c)) }, commonClasses) }) })));
133
220
  }, renderSuggestionsContainer: function (_a) {
134
221
  var children = _a.children, _b = _a.containerProps, ref = _b.ref, restContainerProps = __rest(_b, ["ref"]);
135
222
  return (React.createElement(Popper, { anchorEl: inputRef.current, open: Boolean(children) || isPlaceholderVisible },
136
- React.createElement(Paper, __assign({ ref: ref, square: true }, restContainerProps, { style: { width: prop('clientWidth', inputRef.current) } }),
137
- children || React.createElement(NoResults, { className: styles['typeahead__suggestions-placeholder'] }),
138
- showMoreButton && !isPlaceholderVisible && (React.createElement(LoadMoreButton, { onClick: onLoadMoreSuggestions, onMouseDown: onMouseDown, loading: nextPageIsLoading })))));
223
+ React.createElement(Paper, __assign({}, restContainerProps, { ref: ref, square: true, style: { width: prop('clientWidth', inputRef.current) } }),
224
+ children || React.createElement(NoResults, { className: styles.suggestionsPlaceholder }),
225
+ showMoreButton && !isPlaceholderVisible && (React.createElement(LoadMoreButton, { onClick: handleLoadMoreSuggestions, onMouseDown: function (event) { return event.preventDefault(); }, loading: nextPageIsLoading })))));
139
226
  }, renderSuggestion: function (suggestion, _a) {
140
227
  var isHighlighted = _a.isHighlighted;
141
- return (React.createElement(MenuItem, { className: styles['typeahead__suggestions-menuItem'], selected: isHighlighted, component: "div" },
228
+ return (React.createElement(MenuItem, { className: styles.suggestionsItem, selected: isHighlighted, component: "div" },
142
229
  React.createElement(ExpandedValueTooltip, { value: suggestion },
143
- React.createElement("div", { className: styles['menuItem--item'] }, suggestion))));
144
- }, theme: {
145
- container: fullWidth ? styles['typeahead__suggestions-container'] : '',
146
- suggestionsList: styles['typeahead__suggestions-list'],
147
- suggestionsContainerOpen: styles['typeahead__suggestions-container--open']
148
- }, onSuggestionHighlighted: pipe(prop('suggestion'), Boolean, setHasHighlightedItem) }));
149
- };
150
- TypeaheadEditor.propTypes = {
151
- multiple: PropTypes.bool,
152
- fullWidth: PropTypes.bool,
153
- placeholder: PropTypes.string,
154
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
155
- onChange: PropTypes.func.isRequired,
156
- getSuggestions: PropTypes.func.isRequired,
157
- InputProps: PropTypes.object,
158
- max: PropTypes.number,
159
- isCrossedOut: PropTypes.bool
230
+ React.createElement("div", { className: styles.suggestionsItemText }, suggestion))));
231
+ } }));
160
232
  };
161
233
  export default TypeaheadEditor;
@@ -1 +1 @@
1
- export const useStyles: (props?: any) => import("@mui/styles").ClassNameMap<"isCrossedOut" | "autosizeInput" | "typeahead__suggestions-placeholder" | "typeahead__suggestions-container--open" | "typeahead__suggestions-list" | "typeahead__suggestions-menuItem" | "input__root" | "rawInput" | "multiple-input__root" | "multiple-input__input" | "multiple-input__adornedStart" | "input__underline" | "typeahead__suggestions-container" | "menuItem--item">;
1
+ export declare const useStyles: (props?: any) => import("@mui/styles").ClassNameMap<"underline" | "inputRoot" | "isCrossedOut" | "autosizeInput" | "suggestionsPlaceholder" | "suggestionsContainer" | "suggestionsContainerOpen" | "suggestionsList" | "suggestionsItem" | "suggestionsItemText" | "rawInput" | "multipleTextField" | "multipleTextFieldInput" | "multipleTextFieldAdornedStart">;