@contentful/field-editor-tags 1.4.35 → 1.5.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.
@@ -117,7 +117,7 @@ const SortablePill = ({ id, label, index, disabled, onRemove })=>{
117
117
  };
118
118
  function TagsEditor(props) {
119
119
  const [pendingValue, setPendingValue] = (0, _react.useState)('');
120
- const { isDisabled, items, constraints, constraintsType, hasError, onUpdate } = props;
120
+ const { isDisabled, items, constraints, constraintsType, hasError, onUpdate, id } = props;
121
121
  const itemsMap = _react.default.useMemo(()=>items.map((item, index)=>({
122
122
  id: item + index,
123
123
  value: item
@@ -147,6 +147,7 @@ function TagsEditor(props) {
147
147
  "data-test-id": "tag-editor-container"
148
148
  }, _react.default.createElement(_f36components.TextInput, {
149
149
  testId: "tag-editor-input",
150
+ id: id,
150
151
  className: styles.input,
151
152
  isDisabled: isDisabled,
152
153
  isInvalid: hasError,
@@ -62,33 +62,34 @@ function isEmptyTagsValue(value) {
62
62
  return value === null || value.length === 0;
63
63
  }
64
64
  function getConstraintsType(sizeConstraints) {
65
- if (!sizeConstraints) {
65
+ if (!sizeConstraints || !(0, _isNumber.default)(sizeConstraints.min) && !(0, _isNumber.default)(sizeConstraints.max)) {
66
66
  return undefined;
67
67
  }
68
68
  if ((0, _isNumber.default)(sizeConstraints.min) && (0, _isNumber.default)(sizeConstraints.max)) {
69
69
  return 'min-max';
70
- } else if ((0, _isNumber.default)(sizeConstraints.min)) {
70
+ }
71
+ if ((0, _isNumber.default)(sizeConstraints.min)) {
71
72
  return 'min';
72
- } else if ((0, _isNumber.default)(sizeConstraints.max)) {
73
+ }
74
+ if ((0, _isNumber.default)(sizeConstraints.max)) {
73
75
  return 'max';
74
- } else {
75
- return undefined;
76
76
  }
77
+ return undefined;
77
78
  }
78
- function TagsEditorContainer(props) {
79
- const field = props.field;
79
+ function TagsEditorContainer({ isInitiallyDisabled, field, id }) {
80
80
  const validations = field.validations || [];
81
81
  const sizeValidations = validations.filter((validation)=>validation.size).map((validation)=>validation.size);
82
82
  const constraints = sizeValidations.length > 0 ? sizeValidations[0] : {};
83
83
  const constraintsType = getConstraintsType(constraints);
84
84
  return _react.createElement(_fieldeditorshared.FieldConnector, {
85
85
  field: field,
86
- isInitiallyDisabled: props.isInitiallyDisabled,
86
+ isInitiallyDisabled: isInitiallyDisabled,
87
87
  isEmptyValue: isEmptyTagsValue,
88
88
  debounce: 0
89
89
  }, ({ disabled, value, errors, setValue })=>{
90
90
  const items = value || [];
91
91
  return _react.createElement(_TagsEditor.TagsEditor, {
92
+ id: id,
92
93
  constraints: constraints,
93
94
  constraintsType: constraintsType,
94
95
  isDisabled: disabled,
@@ -61,7 +61,7 @@ const SortablePill = ({ id, label, index, disabled, onRemove })=>{
61
61
  };
62
62
  export function TagsEditor(props) {
63
63
  const [pendingValue, setPendingValue] = useState('');
64
- const { isDisabled, items, constraints, constraintsType, hasError, onUpdate } = props;
64
+ const { isDisabled, items, constraints, constraintsType, hasError, onUpdate, id } = props;
65
65
  const itemsMap = React.useMemo(()=>items.map((item, index)=>({
66
66
  id: item + index,
67
67
  value: item
@@ -91,6 +91,7 @@ export function TagsEditor(props) {
91
91
  "data-test-id": "tag-editor-container"
92
92
  }, React.createElement(TextInput, {
93
93
  testId: "tag-editor-input",
94
+ id: id,
94
95
  className: styles.input,
95
96
  isDisabled: isDisabled,
96
97
  isInvalid: hasError,
@@ -6,33 +6,34 @@ function isEmptyTagsValue(value) {
6
6
  return value === null || value.length === 0;
7
7
  }
8
8
  function getConstraintsType(sizeConstraints) {
9
- if (!sizeConstraints) {
9
+ if (!sizeConstraints || !isNumber(sizeConstraints.min) && !isNumber(sizeConstraints.max)) {
10
10
  return undefined;
11
11
  }
12
12
  if (isNumber(sizeConstraints.min) && isNumber(sizeConstraints.max)) {
13
13
  return 'min-max';
14
- } else if (isNumber(sizeConstraints.min)) {
14
+ }
15
+ if (isNumber(sizeConstraints.min)) {
15
16
  return 'min';
16
- } else if (isNumber(sizeConstraints.max)) {
17
+ }
18
+ if (isNumber(sizeConstraints.max)) {
17
19
  return 'max';
18
- } else {
19
- return undefined;
20
20
  }
21
+ return undefined;
21
22
  }
22
- export function TagsEditorContainer(props) {
23
- const field = props.field;
23
+ export function TagsEditorContainer({ isInitiallyDisabled, field, id }) {
24
24
  const validations = field.validations || [];
25
25
  const sizeValidations = validations.filter((validation)=>validation.size).map((validation)=>validation.size);
26
26
  const constraints = sizeValidations.length > 0 ? sizeValidations[0] : {};
27
27
  const constraintsType = getConstraintsType(constraints);
28
28
  return React.createElement(FieldConnector, {
29
29
  field: field,
30
- isInitiallyDisabled: props.isInitiallyDisabled,
30
+ isInitiallyDisabled: isInitiallyDisabled,
31
31
  isEmptyValue: isEmptyTagsValue,
32
32
  debounce: 0
33
33
  }, ({ disabled, value, errors, setValue })=>{
34
34
  const items = value || [];
35
35
  return React.createElement(TagsEditor, {
36
+ id: id,
36
37
  constraints: constraints,
37
38
  constraintsType: constraintsType,
38
39
  isDisabled: disabled,
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { Constraint, ConstraintsType } from './types';
2
+ import type { Constraint, ConstraintsType } from './types';
3
3
  export interface TagsEditorProps {
4
4
  items: string[];
5
5
  isDisabled: boolean;
@@ -7,5 +7,6 @@ export interface TagsEditorProps {
7
7
  constraintsType?: ConstraintsType;
8
8
  constraints?: Constraint;
9
9
  onUpdate: (items: string[]) => void;
10
+ id?: string;
10
11
  }
11
12
  export declare function TagsEditor(props: TagsEditorProps): React.JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { FieldAPI } from '@contentful/field-editor-shared';
2
+ import { type FieldAPI } from '@contentful/field-editor-shared';
3
3
  export interface TagsEditorContainerProps {
4
4
  /**
5
5
  * is the field disabled initially
@@ -9,8 +9,12 @@ export interface TagsEditorContainerProps {
9
9
  * sdk.field
10
10
  */
11
11
  field: FieldAPI;
12
+ /**
13
+ * id used for associating the input field with its label
14
+ */
15
+ id?: string;
12
16
  }
13
- export declare function TagsEditorContainer(props: TagsEditorContainerProps): React.JSX.Element;
17
+ export declare function TagsEditorContainer({ isInitiallyDisabled, field, id }: TagsEditorContainerProps): React.JSX.Element;
14
18
  export declare namespace TagsEditorContainer {
15
19
  var defaultProps: {
16
20
  isInitiallyDisabled: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-tags",
3
- "version": "1.4.35",
3
+ "version": "1.5.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -54,5 +54,5 @@
54
54
  "publishConfig": {
55
55
  "registry": "https://npm.pkg.github.com/"
56
56
  },
57
- "gitHead": "1d0dc6dc10cf4ad43aa48b04fa67d29ab7edaee8"
57
+ "gitHead": "7ec565308c8d4da384b8fec6f5d840bdf6d4927d"
58
58
  }