@contentful/field-editor-tags 1.4.4 → 1.4.6
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/cjs/TagsEditor.js +9 -7
- package/dist/cjs/TagsEditorConstraints.js +4 -2
- package/dist/cjs/TagsEditorContainer.js +4 -2
- package/dist/cjs/TagsEditorContainer.spec.js +10 -8
- package/dist/esm/TagsEditor.js +6 -6
- package/dist/esm/TagsEditorConstraints.js +1 -1
- package/dist/esm/TagsEditorContainer.js +1 -1
- package/dist/esm/TagsEditorContainer.spec.js +7 -7
- package/package.json +4 -4
package/dist/cjs/TagsEditor.js
CHANGED
|
@@ -44,7 +44,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
44
44
|
if (cache && cache.has(obj)) {
|
|
45
45
|
return cache.get(obj);
|
|
46
46
|
}
|
|
47
|
-
var newObj = {
|
|
47
|
+
var newObj = {
|
|
48
|
+
__proto__: null
|
|
49
|
+
};
|
|
48
50
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
49
51
|
for(var key in obj){
|
|
50
52
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -79,8 +81,8 @@ const styles = {
|
|
|
79
81
|
}
|
|
80
82
|
})
|
|
81
83
|
};
|
|
82
|
-
const SortablePill = ({ id
|
|
83
|
-
const { listeners
|
|
84
|
+
const SortablePill = ({ id, label, index, disabled, onRemove })=>{
|
|
85
|
+
const { listeners, setNodeRef, setActivatorNodeRef, transform, transition } = (0, _sortable.useSortable)({
|
|
84
86
|
id
|
|
85
87
|
});
|
|
86
88
|
const style = {
|
|
@@ -115,7 +117,7 @@ const SortablePill = ({ id , label , index , disabled , onRemove })=>{
|
|
|
115
117
|
};
|
|
116
118
|
function TagsEditor(props) {
|
|
117
119
|
const [pendingValue, setPendingValue] = (0, _react.useState)('');
|
|
118
|
-
const { isDisabled
|
|
120
|
+
const { isDisabled, items, constraints, constraintsType, hasError, onUpdate } = props;
|
|
119
121
|
const itemsMap = _react.default.useMemo(()=>items.map((item, index)=>({
|
|
120
122
|
id: item + index,
|
|
121
123
|
value: item
|
|
@@ -129,10 +131,10 @@ function TagsEditor(props) {
|
|
|
129
131
|
items,
|
|
130
132
|
onUpdate
|
|
131
133
|
]);
|
|
132
|
-
const swapItems = (0, _react.useCallback)(({ active
|
|
134
|
+
const swapItems = (0, _react.useCallback)(({ active, over })=>{
|
|
133
135
|
if (active.id !== over.id) {
|
|
134
|
-
const oldIndex = itemsMap.findIndex(({ id
|
|
135
|
-
const newIndex = itemsMap.findIndex(({ id
|
|
136
|
+
const oldIndex = itemsMap.findIndex(({ id })=>id === active.id);
|
|
137
|
+
const newIndex = itemsMap.findIndex(({ id })=>id === over.id);
|
|
136
138
|
const newItems = (0, _sortable.arrayMove)(items, oldIndex, newIndex);
|
|
137
139
|
onUpdate(newItems);
|
|
138
140
|
}
|
|
@@ -32,7 +32,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
32
32
|
if (cache && cache.has(obj)) {
|
|
33
33
|
return cache.get(obj);
|
|
34
34
|
}
|
|
35
|
-
var newObj = {
|
|
35
|
+
var newObj = {
|
|
36
|
+
__proto__: null
|
|
37
|
+
};
|
|
36
38
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
37
39
|
for(var key in obj){
|
|
38
40
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -51,7 +53,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
51
53
|
return newObj;
|
|
52
54
|
}
|
|
53
55
|
function TagsEditorConstraints(props) {
|
|
54
|
-
const { constraintsType
|
|
56
|
+
const { constraintsType, constraints } = props;
|
|
55
57
|
return _react.createElement(_f36components.Text, {
|
|
56
58
|
as: "p",
|
|
57
59
|
fontColor: "gray600",
|
|
@@ -38,7 +38,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
38
38
|
if (cache && cache.has(obj)) {
|
|
39
39
|
return cache.get(obj);
|
|
40
40
|
}
|
|
41
|
-
var newObj = {
|
|
41
|
+
var newObj = {
|
|
42
|
+
__proto__: null
|
|
43
|
+
};
|
|
42
44
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
43
45
|
for(var key in obj){
|
|
44
46
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -84,7 +86,7 @@ function TagsEditorContainer(props) {
|
|
|
84
86
|
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
85
87
|
isEmptyValue: isEmptyTagsValue,
|
|
86
88
|
debounce: 0
|
|
87
|
-
}, ({ disabled
|
|
89
|
+
}, ({ disabled, value, errors, setValue })=>{
|
|
88
90
|
const items = value || [];
|
|
89
91
|
return _react.createElement(_TagsEditor.TagsEditor, {
|
|
90
92
|
constraints: constraints,
|
|
@@ -28,7 +28,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
28
28
|
if (cache && cache.has(obj)) {
|
|
29
29
|
return cache.get(obj);
|
|
30
30
|
}
|
|
31
|
-
var newObj = {
|
|
31
|
+
var newObj = {
|
|
32
|
+
__proto__: null
|
|
33
|
+
};
|
|
32
34
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
33
35
|
for(var key in obj){
|
|
34
36
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -51,23 +53,23 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
51
53
|
});
|
|
52
54
|
describe('TagsEditor', ()=>{
|
|
53
55
|
afterEach(_react1.cleanup);
|
|
54
|
-
function expectNoConstraints({ queryByTestId
|
|
56
|
+
function expectNoConstraints({ queryByTestId }) {
|
|
55
57
|
const $constraints = queryByTestId('tag-editor-constraints');
|
|
56
58
|
expect($constraints).not.toBeInTheDocument();
|
|
57
59
|
}
|
|
58
|
-
function expectInputValue({ getByTestId
|
|
60
|
+
function expectInputValue({ getByTestId }, expected) {
|
|
59
61
|
const $input = getByTestId('tag-editor-input');
|
|
60
62
|
expect($input).toHaveValue(expected);
|
|
61
63
|
}
|
|
62
|
-
function expectTagsCount({ queryAllByTestId
|
|
64
|
+
function expectTagsCount({ queryAllByTestId }, expectedCount) {
|
|
63
65
|
const $values = queryAllByTestId('tag-editor-pill');
|
|
64
66
|
expect($values).toHaveLength(expectedCount);
|
|
65
67
|
}
|
|
66
|
-
function expectTag({ queryAllByTestId
|
|
68
|
+
function expectTag({ queryAllByTestId }, index, content) {
|
|
67
69
|
const $values = queryAllByTestId('tag-editor-pill');
|
|
68
70
|
expect($values[index].textContent).toEqual(content);
|
|
69
71
|
}
|
|
70
|
-
function typePendingValueAndHitEnter({ getByTestId
|
|
72
|
+
function typePendingValueAndHitEnter({ getByTestId }, value) {
|
|
71
73
|
const $input = getByTestId('tag-editor-input');
|
|
72
74
|
_react1.fireEvent.change($input, {
|
|
73
75
|
target: {
|
|
@@ -78,7 +80,7 @@ describe('TagsEditor', ()=>{
|
|
|
78
80
|
keyCode: 13
|
|
79
81
|
});
|
|
80
82
|
}
|
|
81
|
-
function clickRemoveTag({ getAllByTestId
|
|
83
|
+
function clickRemoveTag({ getAllByTestId }, index) {
|
|
82
84
|
_react1.fireEvent.click(getAllByTestId('tag-editor-pill')[index].querySelector('button'));
|
|
83
85
|
}
|
|
84
86
|
it('renders empty value properly', ()=>{
|
|
@@ -178,7 +180,7 @@ describe('TagsEditor', ()=>{
|
|
|
178
180
|
]
|
|
179
181
|
};
|
|
180
182
|
});
|
|
181
|
-
const { getByTestId
|
|
183
|
+
const { getByTestId } = (0, _react1.render)(_react.createElement(_TagsEditorContainer.TagsEditorContainer, {
|
|
182
184
|
field: field,
|
|
183
185
|
isInitiallyDisabled: false
|
|
184
186
|
}));
|
package/dist/esm/TagsEditor.js
CHANGED
|
@@ -25,8 +25,8 @@ const styles = {
|
|
|
25
25
|
}
|
|
26
26
|
})
|
|
27
27
|
};
|
|
28
|
-
const SortablePill = ({ id
|
|
29
|
-
const { listeners
|
|
28
|
+
const SortablePill = ({ id, label, index, disabled, onRemove })=>{
|
|
29
|
+
const { listeners, setNodeRef, setActivatorNodeRef, transform, transition } = useSortable({
|
|
30
30
|
id
|
|
31
31
|
});
|
|
32
32
|
const style = {
|
|
@@ -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
|
|
64
|
+
const { isDisabled, items, constraints, constraintsType, hasError, onUpdate } = props;
|
|
65
65
|
const itemsMap = React.useMemo(()=>items.map((item, index)=>({
|
|
66
66
|
id: item + index,
|
|
67
67
|
value: item
|
|
@@ -75,10 +75,10 @@ export function TagsEditor(props) {
|
|
|
75
75
|
items,
|
|
76
76
|
onUpdate
|
|
77
77
|
]);
|
|
78
|
-
const swapItems = useCallback(({ active
|
|
78
|
+
const swapItems = useCallback(({ active, over })=>{
|
|
79
79
|
if (active.id !== over.id) {
|
|
80
|
-
const oldIndex = itemsMap.findIndex(({ id
|
|
81
|
-
const newIndex = itemsMap.findIndex(({ id
|
|
80
|
+
const oldIndex = itemsMap.findIndex(({ id })=>id === active.id);
|
|
81
|
+
const newIndex = itemsMap.findIndex(({ id })=>id === over.id);
|
|
82
82
|
const newItems = arrayMove(items, oldIndex, newIndex);
|
|
83
83
|
onUpdate(newItems);
|
|
84
84
|
}
|
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { Text } from '@contentful/f36-components';
|
|
3
3
|
import { css } from 'emotion';
|
|
4
4
|
export function TagsEditorConstraints(props) {
|
|
5
|
-
const { constraintsType
|
|
5
|
+
const { constraintsType, constraints } = props;
|
|
6
6
|
return React.createElement(Text, {
|
|
7
7
|
as: "p",
|
|
8
8
|
fontColor: "gray600",
|
|
@@ -30,7 +30,7 @@ export function TagsEditorContainer(props) {
|
|
|
30
30
|
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
31
31
|
isEmptyValue: isEmptyTagsValue,
|
|
32
32
|
debounce: 0
|
|
33
|
-
}, ({ disabled
|
|
33
|
+
}, ({ disabled, value, errors, setValue })=>{
|
|
34
34
|
const items = value || [];
|
|
35
35
|
return React.createElement(TagsEditor, {
|
|
36
36
|
constraints: constraints,
|
|
@@ -8,23 +8,23 @@ configure({
|
|
|
8
8
|
});
|
|
9
9
|
describe('TagsEditor', ()=>{
|
|
10
10
|
afterEach(cleanup);
|
|
11
|
-
function expectNoConstraints({ queryByTestId
|
|
11
|
+
function expectNoConstraints({ queryByTestId }) {
|
|
12
12
|
const $constraints = queryByTestId('tag-editor-constraints');
|
|
13
13
|
expect($constraints).not.toBeInTheDocument();
|
|
14
14
|
}
|
|
15
|
-
function expectInputValue({ getByTestId
|
|
15
|
+
function expectInputValue({ getByTestId }, expected) {
|
|
16
16
|
const $input = getByTestId('tag-editor-input');
|
|
17
17
|
expect($input).toHaveValue(expected);
|
|
18
18
|
}
|
|
19
|
-
function expectTagsCount({ queryAllByTestId
|
|
19
|
+
function expectTagsCount({ queryAllByTestId }, expectedCount) {
|
|
20
20
|
const $values = queryAllByTestId('tag-editor-pill');
|
|
21
21
|
expect($values).toHaveLength(expectedCount);
|
|
22
22
|
}
|
|
23
|
-
function expectTag({ queryAllByTestId
|
|
23
|
+
function expectTag({ queryAllByTestId }, index, content) {
|
|
24
24
|
const $values = queryAllByTestId('tag-editor-pill');
|
|
25
25
|
expect($values[index].textContent).toEqual(content);
|
|
26
26
|
}
|
|
27
|
-
function typePendingValueAndHitEnter({ getByTestId
|
|
27
|
+
function typePendingValueAndHitEnter({ getByTestId }, value) {
|
|
28
28
|
const $input = getByTestId('tag-editor-input');
|
|
29
29
|
fireEvent.change($input, {
|
|
30
30
|
target: {
|
|
@@ -35,7 +35,7 @@ describe('TagsEditor', ()=>{
|
|
|
35
35
|
keyCode: 13
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
function clickRemoveTag({ getAllByTestId
|
|
38
|
+
function clickRemoveTag({ getAllByTestId }, index) {
|
|
39
39
|
fireEvent.click(getAllByTestId('tag-editor-pill')[index].querySelector('button'));
|
|
40
40
|
}
|
|
41
41
|
it('renders empty value properly', ()=>{
|
|
@@ -135,7 +135,7 @@ describe('TagsEditor', ()=>{
|
|
|
135
135
|
]
|
|
136
136
|
};
|
|
137
137
|
});
|
|
138
|
-
const { getByTestId
|
|
138
|
+
const { getByTestId } = render(React.createElement(TagsEditorContainer, {
|
|
139
139
|
field: field,
|
|
140
140
|
isInitiallyDisabled: false
|
|
141
141
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-tags",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.6",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@contentful/f36-components": "^4.0.27",
|
|
39
39
|
"@contentful/f36-icons": "^4.1.0",
|
|
40
40
|
"@contentful/f36-tokens": "^4.0.0",
|
|
41
|
-
"@contentful/field-editor-shared": "^1.4.
|
|
41
|
+
"@contentful/field-editor-shared": "^1.4.6",
|
|
42
42
|
"@dnd-kit/core": "^6.0.8",
|
|
43
43
|
"@dnd-kit/modifiers": "^6.0.1",
|
|
44
44
|
"@dnd-kit/sortable": "^7.0.2",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"lodash": "^4.17.15"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@contentful/field-editor-test-utils": "^1.4.
|
|
49
|
+
"@contentful/field-editor-test-utils": "^1.4.7"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"react": ">=16.8.0"
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"registry": "https://npm.pkg.github.com/"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "894934e9a2888aeb0a894cfebea3e034ba830f2a"
|
|
58
58
|
}
|