@contentful/field-editor-list 1.2.0 → 1.3.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.
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ListEditor", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ListEditor;
9
+ }
10
+ });
11
+ const _react = _interop_require_wildcard(require("react"));
12
+ const _f36components = require("@contentful/f36-components");
13
+ const _fieldeditorshared = require("@contentful/field-editor-shared");
14
+ const _isEqual = _interop_require_default(require("lodash/isEqual"));
15
+ const _styles = _interop_require_wildcard(require("./styles"));
16
+ function _interop_require_default(obj) {
17
+ return obj && obj.__esModule ? obj : {
18
+ default: obj
19
+ };
20
+ }
21
+ function _getRequireWildcardCache(nodeInterop) {
22
+ if (typeof WeakMap !== "function") return null;
23
+ var cacheBabelInterop = new WeakMap();
24
+ var cacheNodeInterop = new WeakMap();
25
+ return (_getRequireWildcardCache = function(nodeInterop) {
26
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
27
+ })(nodeInterop);
28
+ }
29
+ function _interop_require_wildcard(obj, nodeInterop) {
30
+ if (!nodeInterop && obj && obj.__esModule) {
31
+ return obj;
32
+ }
33
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
34
+ return {
35
+ default: obj
36
+ };
37
+ }
38
+ var cache = _getRequireWildcardCache(nodeInterop);
39
+ if (cache && cache.has(obj)) {
40
+ return cache.get(obj);
41
+ }
42
+ var newObj = {};
43
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
44
+ for(var key in obj){
45
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
46
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
47
+ if (desc && (desc.get || desc.set)) {
48
+ Object.defineProperty(newObj, key, desc);
49
+ } else {
50
+ newObj[key] = obj[key];
51
+ }
52
+ }
53
+ }
54
+ newObj.default = obj;
55
+ if (cache) {
56
+ cache.set(obj, newObj);
57
+ }
58
+ return newObj;
59
+ }
60
+ function isEmptyListValue(value) {
61
+ return value === null || value.length === 0;
62
+ }
63
+ function ListEditor(props) {
64
+ const { field , locales } = props;
65
+ const direction = locales.direction[field.locale] || 'ltr';
66
+ return _react.createElement(_fieldeditorshared.FieldConnector, {
67
+ throttle: 0,
68
+ isEmptyValue: isEmptyListValue,
69
+ field: field,
70
+ isInitiallyDisabled: props.isInitiallyDisabled
71
+ }, (childProps)=>_react.createElement(ListEditorInternal, {
72
+ ...childProps,
73
+ direction: direction,
74
+ isRequired: field.required
75
+ }));
76
+ }
77
+ function ListEditorInternal({ setValue , value , errors , disabled , direction , isRequired }) {
78
+ const [valueState, setValueState] = _react.useState(()=>(value || []).join(', '));
79
+ const onChange = (e)=>{
80
+ const valueAsArray = e.target.value.split(',').map((item)=>item.trim()).filter((item)=>item);
81
+ const changed = !(0, _isEqual.default)(valueAsArray, value);
82
+ setValue(valueAsArray);
83
+ const valueAsString = valueAsArray.join(', ');
84
+ setValueState(changed ? valueAsString : e.target.value);
85
+ };
86
+ return _react.createElement(_f36components.TextInput, {
87
+ testId: "list-editor-input",
88
+ className: direction === 'rtl' ? _styles.rightToLeft : '',
89
+ isRequired: isRequired,
90
+ isInvalid: errors.length > 0,
91
+ isDisabled: disabled,
92
+ value: valueState,
93
+ onChange: onChange
94
+ });
95
+ }
96
+ ListEditor.defaultProps = {
97
+ isInitiallyDisabled: true
98
+ };
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _react = _interop_require_wildcard(require("react"));
6
+ const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
7
+ require("@testing-library/jest-dom/extend-expect");
8
+ const _react1 = require("@testing-library/react");
9
+ const _ListEditor = require("./ListEditor");
10
+ function _getRequireWildcardCache(nodeInterop) {
11
+ if (typeof WeakMap !== "function") return null;
12
+ var cacheBabelInterop = new WeakMap();
13
+ var cacheNodeInterop = new WeakMap();
14
+ return (_getRequireWildcardCache = function(nodeInterop) {
15
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
16
+ })(nodeInterop);
17
+ }
18
+ function _interop_require_wildcard(obj, nodeInterop) {
19
+ if (!nodeInterop && obj && obj.__esModule) {
20
+ return obj;
21
+ }
22
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
23
+ return {
24
+ default: obj
25
+ };
26
+ }
27
+ var cache = _getRequireWildcardCache(nodeInterop);
28
+ if (cache && cache.has(obj)) {
29
+ return cache.get(obj);
30
+ }
31
+ var newObj = {};
32
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
33
+ for(var key in obj){
34
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
35
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
36
+ if (desc && (desc.get || desc.set)) {
37
+ Object.defineProperty(newObj, key, desc);
38
+ } else {
39
+ newObj[key] = obj[key];
40
+ }
41
+ }
42
+ }
43
+ newObj.default = obj;
44
+ if (cache) {
45
+ cache.set(obj, newObj);
46
+ }
47
+ return newObj;
48
+ }
49
+ (0, _react1.configure)({
50
+ testIdAttribute: 'data-test-id'
51
+ });
52
+ describe('ListEditor', ()=>{
53
+ afterEach(_react1.cleanup);
54
+ function expectInputValue({ getByTestId }, expected) {
55
+ const $input = getByTestId('list-editor-input');
56
+ expect($input).toHaveValue(expected);
57
+ }
58
+ function changeInputValue({ getByTestId }, value) {
59
+ const $input = getByTestId('list-editor-input');
60
+ _react1.fireEvent.change($input, {
61
+ target: {
62
+ value
63
+ }
64
+ });
65
+ }
66
+ it('renders empty value properly', ()=>{
67
+ const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((mock)=>{
68
+ return {
69
+ ...mock,
70
+ validations: []
71
+ };
72
+ });
73
+ const renderResult = (0, _react1.render)(_react.createElement(_ListEditor.ListEditor, {
74
+ field: field,
75
+ locales: (0, _fieldeditortestutils.createFakeLocalesAPI)(),
76
+ isInitiallyDisabled: false
77
+ }));
78
+ expectInputValue(renderResult, '');
79
+ });
80
+ it('renders non-empty value properly', ()=>{
81
+ const initialValue = [
82
+ 'test1',
83
+ 'test2',
84
+ 'test3'
85
+ ];
86
+ const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((mock)=>{
87
+ return {
88
+ ...mock,
89
+ validations: []
90
+ };
91
+ }, initialValue);
92
+ const renderResult = (0, _react1.render)(_react.createElement(_ListEditor.ListEditor, {
93
+ field: field,
94
+ locales: (0, _fieldeditortestutils.createFakeLocalesAPI)(),
95
+ isInitiallyDisabled: false
96
+ }));
97
+ expectInputValue(renderResult, 'test1, test2, test3');
98
+ });
99
+ it('calls setValue and removeValue when user inputs data', ()=>{
100
+ const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
101
+ jest.spyOn(field, 'setValue');
102
+ jest.spyOn(field, 'removeValue');
103
+ return {
104
+ ...field,
105
+ validations: []
106
+ };
107
+ });
108
+ const renderResult = (0, _react1.render)(_react.createElement(_ListEditor.ListEditor, {
109
+ field: field,
110
+ locales: (0, _fieldeditortestutils.createFakeLocalesAPI)(),
111
+ isInitiallyDisabled: false
112
+ }));
113
+ changeInputValue(renderResult, 'test1');
114
+ expect(field.setValue).toHaveBeenLastCalledWith([
115
+ 'test1'
116
+ ]);
117
+ changeInputValue(renderResult, 'test1, test2 , test3');
118
+ expectInputValue(renderResult, 'test1, test2, test3');
119
+ expect(field.setValue).toHaveBeenCalledWith([
120
+ 'test1',
121
+ 'test2',
122
+ 'test3'
123
+ ]);
124
+ changeInputValue(renderResult, '');
125
+ expect(field.removeValue).toHaveBeenCalledTimes(1);
126
+ expect(field.setValue).toHaveBeenCalledTimes(2);
127
+ });
128
+ it('keeps trailing commas', ()=>{
129
+ const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
130
+ jest.spyOn(field, 'setValue');
131
+ return {
132
+ ...field,
133
+ validations: []
134
+ };
135
+ }, [
136
+ 'test1'
137
+ ]);
138
+ const renderResult = (0, _react1.render)(_react.createElement(_ListEditor.ListEditor, {
139
+ field: field,
140
+ locales: (0, _fieldeditortestutils.createFakeLocalesAPI)(),
141
+ isInitiallyDisabled: false
142
+ }));
143
+ changeInputValue(renderResult, 'test1,');
144
+ expect(field.setValue).toHaveBeenLastCalledWith([
145
+ 'test1'
146
+ ]);
147
+ expectInputValue(renderResult, 'test1,');
148
+ });
149
+ });
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ListEditor", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _ListEditor.ListEditor;
9
+ }
10
+ });
11
+ const _ListEditor = require("./ListEditor");
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "rightToLeft", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return rightToLeft;
9
+ }
10
+ });
11
+ const _emotion = require("emotion");
12
+ const rightToLeft = (0, _emotion.css)({
13
+ direction: 'rtl'
14
+ });
@@ -0,0 +1,44 @@
1
+ import * as React from 'react';
2
+ import { TextInput } from '@contentful/f36-components';
3
+ import { FieldConnector } from '@contentful/field-editor-shared';
4
+ import isEqual from 'lodash/isEqual';
5
+ import * as styles from './styles';
6
+ function isEmptyListValue(value) {
7
+ return value === null || value.length === 0;
8
+ }
9
+ export function ListEditor(props) {
10
+ const { field , locales } = props;
11
+ const direction = locales.direction[field.locale] || 'ltr';
12
+ return React.createElement(FieldConnector, {
13
+ throttle: 0,
14
+ isEmptyValue: isEmptyListValue,
15
+ field: field,
16
+ isInitiallyDisabled: props.isInitiallyDisabled
17
+ }, (childProps)=>React.createElement(ListEditorInternal, {
18
+ ...childProps,
19
+ direction: direction,
20
+ isRequired: field.required
21
+ }));
22
+ }
23
+ function ListEditorInternal({ setValue , value , errors , disabled , direction , isRequired }) {
24
+ const [valueState, setValueState] = React.useState(()=>(value || []).join(', '));
25
+ const onChange = (e)=>{
26
+ const valueAsArray = e.target.value.split(',').map((item)=>item.trim()).filter((item)=>item);
27
+ const changed = !isEqual(valueAsArray, value);
28
+ setValue(valueAsArray);
29
+ const valueAsString = valueAsArray.join(', ');
30
+ setValueState(changed ? valueAsString : e.target.value);
31
+ };
32
+ return React.createElement(TextInput, {
33
+ testId: "list-editor-input",
34
+ className: direction === 'rtl' ? styles.rightToLeft : '',
35
+ isRequired: isRequired,
36
+ isInvalid: errors.length > 0,
37
+ isDisabled: disabled,
38
+ value: valueState,
39
+ onChange: onChange
40
+ });
41
+ }
42
+ ListEditor.defaultProps = {
43
+ isInitiallyDisabled: true
44
+ };
@@ -0,0 +1,106 @@
1
+ import * as React from 'react';
2
+ import { createFakeFieldAPI, createFakeLocalesAPI } from '@contentful/field-editor-test-utils';
3
+ import '@testing-library/jest-dom/extend-expect';
4
+ import { cleanup, configure, fireEvent, render } from '@testing-library/react';
5
+ import { ListEditor } from './ListEditor';
6
+ configure({
7
+ testIdAttribute: 'data-test-id'
8
+ });
9
+ describe('ListEditor', ()=>{
10
+ afterEach(cleanup);
11
+ function expectInputValue({ getByTestId }, expected) {
12
+ const $input = getByTestId('list-editor-input');
13
+ expect($input).toHaveValue(expected);
14
+ }
15
+ function changeInputValue({ getByTestId }, value) {
16
+ const $input = getByTestId('list-editor-input');
17
+ fireEvent.change($input, {
18
+ target: {
19
+ value
20
+ }
21
+ });
22
+ }
23
+ it('renders empty value properly', ()=>{
24
+ const [field] = createFakeFieldAPI((mock)=>{
25
+ return {
26
+ ...mock,
27
+ validations: []
28
+ };
29
+ });
30
+ const renderResult = render(React.createElement(ListEditor, {
31
+ field: field,
32
+ locales: createFakeLocalesAPI(),
33
+ isInitiallyDisabled: false
34
+ }));
35
+ expectInputValue(renderResult, '');
36
+ });
37
+ it('renders non-empty value properly', ()=>{
38
+ const initialValue = [
39
+ 'test1',
40
+ 'test2',
41
+ 'test3'
42
+ ];
43
+ const [field] = createFakeFieldAPI((mock)=>{
44
+ return {
45
+ ...mock,
46
+ validations: []
47
+ };
48
+ }, initialValue);
49
+ const renderResult = render(React.createElement(ListEditor, {
50
+ field: field,
51
+ locales: createFakeLocalesAPI(),
52
+ isInitiallyDisabled: false
53
+ }));
54
+ expectInputValue(renderResult, 'test1, test2, test3');
55
+ });
56
+ it('calls setValue and removeValue when user inputs data', ()=>{
57
+ const [field] = createFakeFieldAPI((field)=>{
58
+ jest.spyOn(field, 'setValue');
59
+ jest.spyOn(field, 'removeValue');
60
+ return {
61
+ ...field,
62
+ validations: []
63
+ };
64
+ });
65
+ const renderResult = render(React.createElement(ListEditor, {
66
+ field: field,
67
+ locales: createFakeLocalesAPI(),
68
+ isInitiallyDisabled: false
69
+ }));
70
+ changeInputValue(renderResult, 'test1');
71
+ expect(field.setValue).toHaveBeenLastCalledWith([
72
+ 'test1'
73
+ ]);
74
+ changeInputValue(renderResult, 'test1, test2 , test3');
75
+ expectInputValue(renderResult, 'test1, test2, test3');
76
+ expect(field.setValue).toHaveBeenCalledWith([
77
+ 'test1',
78
+ 'test2',
79
+ 'test3'
80
+ ]);
81
+ changeInputValue(renderResult, '');
82
+ expect(field.removeValue).toHaveBeenCalledTimes(1);
83
+ expect(field.setValue).toHaveBeenCalledTimes(2);
84
+ });
85
+ it('keeps trailing commas', ()=>{
86
+ const [field] = createFakeFieldAPI((field)=>{
87
+ jest.spyOn(field, 'setValue');
88
+ return {
89
+ ...field,
90
+ validations: []
91
+ };
92
+ }, [
93
+ 'test1'
94
+ ]);
95
+ const renderResult = render(React.createElement(ListEditor, {
96
+ field: field,
97
+ locales: createFakeLocalesAPI(),
98
+ isInitiallyDisabled: false
99
+ }));
100
+ changeInputValue(renderResult, 'test1,');
101
+ expect(field.setValue).toHaveBeenLastCalledWith([
102
+ 'test1'
103
+ ]);
104
+ expectInputValue(renderResult, 'test1,');
105
+ });
106
+ });
@@ -0,0 +1 @@
1
+ export { ListEditor } from './ListEditor';
@@ -0,0 +1,4 @@
1
+ import { css } from 'emotion';
2
+ export const rightToLeft = css({
3
+ direction: 'rtl'
4
+ });
@@ -1,22 +1,22 @@
1
- /// <reference types="react" />
2
- import { FieldAPI, LocalesAPI } from '@contentful/field-editor-shared';
3
- export interface ListEditorProps {
4
- /**
5
- * is the field disabled initially
6
- */
7
- isInitiallyDisabled: boolean;
8
- /**
9
- * sdk.field
10
- */
11
- field: FieldAPI;
12
- /**
13
- * sdk.locales
14
- */
15
- locales: LocalesAPI;
16
- }
17
- export declare function ListEditor(props: ListEditorProps): JSX.Element;
18
- export declare namespace ListEditor {
19
- var defaultProps: {
20
- isInitiallyDisabled: boolean;
21
- };
22
- }
1
+ import * as React from 'react';
2
+ import { FieldAPI, LocalesAPI } from '@contentful/field-editor-shared';
3
+ export interface ListEditorProps {
4
+ /**
5
+ * is the field disabled initially
6
+ */
7
+ isInitiallyDisabled: boolean;
8
+ /**
9
+ * sdk.field
10
+ */
11
+ field: FieldAPI;
12
+ /**
13
+ * sdk.locales
14
+ */
15
+ locales: LocalesAPI;
16
+ }
17
+ export declare function ListEditor(props: ListEditorProps): React.JSX.Element;
18
+ export declare namespace ListEditor {
19
+ var defaultProps: {
20
+ isInitiallyDisabled: boolean;
21
+ };
22
+ }
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/extend-expect';
@@ -1 +1 @@
1
- export { ListEditor } from './ListEditor';
1
+ export { ListEditor } from './ListEditor';
@@ -1 +1 @@
1
- export declare const rightToLeft: string;
1
+ export declare const rightToLeft: string;
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-list",
3
- "version": "1.2.0",
4
- "main": "dist/index.js",
5
- "module": "dist/field-editor-list.esm.js",
6
- "typings": "dist/index.d.ts",
3
+ "version": "1.3.0",
4
+ "main": "dist/cjs/index.js",
5
+ "module": "dist/esm/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/types/index.d.ts",
10
+ "require": "./dist/cjs/index.js",
11
+ "default": "./dist/cjs/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
7
15
  "files": [
8
16
  "dist"
9
17
  ],
@@ -14,25 +22,31 @@
14
22
  "url": "https://github.com/contentful/field-editors"
15
23
  },
16
24
  "scripts": {
17
- "watch": "tsdx watch",
18
- "build": "tsdx build",
19
- "test": "tsdx test --env=jsdom --watch",
20
- "test:ci": "tsdx test --env=jsdom --ci",
25
+ "watch": "yarn concurrently \"yarn:watch:*\"",
26
+ "watch:cjs": "yarn build:cjs -w",
27
+ "watch:esm": "yarn build:esm -w",
28
+ "watch:types": "yarn build:types --watch",
29
+ "build": "yarn build:types && yarn build:cjs && yarn build:esm",
30
+ "build:types": "tsc --outDir dist/types --emitDeclarationOnly",
31
+ "build:cjs": "swc src --config-file ../../.swcrc -d dist/cjs -C module.type=commonjs",
32
+ "build:esm": "swc src --config-file ../../.swcrc -d dist/esm",
33
+ "test": "jest --watch",
34
+ "test:ci": "jest --ci",
21
35
  "tsc": "tsc -p ./ --noEmit"
22
36
  },
23
37
  "dependencies": {
24
38
  "@contentful/f36-components": "^4.0.27",
25
39
  "@contentful/f36-tokens": "^4.0.0",
26
- "@contentful/field-editor-shared": "^1.2.0",
40
+ "@contentful/field-editor-shared": "^1.3.0",
27
41
  "emotion": "^10.0.17",
28
42
  "lodash": "^4.17.15",
29
43
  "lodash-es": "^4.17.15"
30
44
  },
31
45
  "devDependencies": {
32
- "@contentful/field-editor-test-utils": "^1.3.0"
46
+ "@contentful/field-editor-test-utils": "^1.4.0"
33
47
  },
34
48
  "peerDependencies": {
35
49
  "react": ">=16.8.0"
36
50
  },
37
- "gitHead": "de7e74e3485dd69c240cfe9c545e6e50e41fb295"
51
+ "gitHead": "543e02672a8dd4edc810f9f3568d6b69c454e1f9"
38
52
  }
package/CHANGELOG.md DELETED
@@ -1,198 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [1.2.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.1.11...@contentful/field-editor-list@1.2.0) (2023-04-19)
7
-
8
- ### Features
9
-
10
- - upgrade cypress [TOL-1036] ([#1391](https://github.com/contentful/field-editors/issues/1391)) ([9c1aec9](https://github.com/contentful/field-editors/commit/9c1aec98aabbe464cdc3f1236c3bb1cc29b8208d))
11
-
12
- ## [1.1.11](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.1.10...@contentful/field-editor-list@1.1.11) (2023-03-14)
13
-
14
- **Note:** Version bump only for package @contentful/field-editor-list
15
-
16
- ## [1.1.10](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.1.9...@contentful/field-editor-list@1.1.10) (2023-03-10)
17
-
18
- **Note:** Version bump only for package @contentful/field-editor-list
19
-
20
- ## [1.1.9](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.1.8...@contentful/field-editor-list@1.1.9) (2023-02-21)
21
-
22
- **Note:** Version bump only for package @contentful/field-editor-list
23
-
24
- ## [1.1.8](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.1.7...@contentful/field-editor-list@1.1.8) (2023-02-07)
25
-
26
- **Note:** Version bump only for package @contentful/field-editor-list
27
-
28
- ## [1.1.7](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.1.6...@contentful/field-editor-list@1.1.7) (2022-12-08)
29
-
30
- **Note:** Version bump only for package @contentful/field-editor-list
31
-
32
- ## [1.1.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.1.5...@contentful/field-editor-list@1.1.6) (2022-07-29)
33
-
34
- **Note:** Version bump only for package @contentful/field-editor-list
35
-
36
- ## [1.1.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.1.4...@contentful/field-editor-list@1.1.5) (2022-07-29)
37
-
38
- **Note:** Version bump only for package @contentful/field-editor-list
39
-
40
- ## [1.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.1.3...@contentful/field-editor-list@1.1.4) (2022-07-11)
41
-
42
- **Note:** Version bump only for package @contentful/field-editor-list
43
-
44
- ## [1.1.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.1.2...@contentful/field-editor-list@1.1.3) (2022-06-22)
45
-
46
- **Note:** Version bump only for package @contentful/field-editor-list
47
-
48
- ## [1.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.1.1...@contentful/field-editor-list@1.1.2) (2022-02-15)
49
-
50
- ### Bug Fixes
51
-
52
- - bump f36 packages ([#1025](https://github.com/contentful/field-editors/issues/1025)) ([ec37a40](https://github.com/contentful/field-editors/commit/ec37a4000db7cd75c66dd9621136b2272c9feeea))
53
-
54
- ## [1.1.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.1.0...@contentful/field-editor-list@1.1.1) (2022-02-14)
55
-
56
- **Note:** Version bump only for package @contentful/field-editor-list
57
-
58
- # [1.1.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.0.4...@contentful/field-editor-list@1.1.0) (2022-01-11)
59
-
60
- ### Features
61
-
62
- - bump f36 packages to stable v4 [BAU-521] ([#988](https://github.com/contentful/field-editors/issues/988)) ([419cf56](https://github.com/contentful/field-editors/commit/419cf56692179b074fcfa2743469d5265ed98429))
63
-
64
- ## [1.0.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.0.3...@contentful/field-editor-list@1.0.4) (2021-12-23)
65
-
66
- ### Bug Fixes
67
-
68
- - markdown buttons ([#968](https://github.com/contentful/field-editors/issues/968)) ([9803b98](https://github.com/contentful/field-editors/commit/9803b98c25d92df6148686ffe2749a77f7efdbb9))
69
-
70
- ## [1.0.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.0.2...@contentful/field-editor-list@1.0.3) (2021-12-20)
71
-
72
- **Note:** Version bump only for package @contentful/field-editor-list
73
-
74
- ## [1.0.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.0.1...@contentful/field-editor-list@1.0.2) (2021-11-18)
75
-
76
- ### Bug Fixes
77
-
78
- - fix list field preventing commas after forma36 v4 ([#930](https://github.com/contentful/field-editors/issues/930)) ([01bc621](https://github.com/contentful/field-editors/commit/01bc6217d0e43ed28f8b5c013475697c159dcd73))
79
-
80
- ## [1.0.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@1.0.0...@contentful/field-editor-list@1.0.1) (2021-11-17)
81
-
82
- ### Bug Fixes
83
-
84
- - **card-actions:** update forma 36 to fix card actions click issue ([#927](https://github.com/contentful/field-editors/issues/927)) ([3dfdef2](https://github.com/contentful/field-editors/commit/3dfdef2c2b0045f12ea94ddafca89a8e9f25e7d0))
85
-
86
- # [1.0.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.16.0...@contentful/field-editor-list@1.0.0) (2021-11-04)
87
-
88
- **Note:** Version bump only for package @contentful/field-editor-list
89
-
90
- # [0.16.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.15.6...@contentful/field-editor-list@0.16.0) (2021-11-04)
91
-
92
- ### Features
93
-
94
- - Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
95
-
96
- ### BREAKING CHANGES
97
-
98
- - adopts a new Forma v4 beta
99
-
100
- ## [0.15.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.15.5...@contentful/field-editor-list@0.15.6) (2021-10-14)
101
-
102
- **Note:** Version bump only for package @contentful/field-editor-list
103
-
104
- ## [0.15.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.15.4...@contentful/field-editor-list@0.15.5) (2021-10-06)
105
-
106
- **Note:** Version bump only for package @contentful/field-editor-list
107
-
108
- ## [0.15.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.15.3...@contentful/field-editor-list@0.15.4) (2021-09-17)
109
-
110
- **Note:** Version bump only for package @contentful/field-editor-list
111
-
112
- ## [0.15.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.15.2...@contentful/field-editor-list@0.15.3) (2021-09-16)
113
-
114
- **Note:** Version bump only for package @contentful/field-editor-list
115
-
116
- ## [0.15.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.15.1...@contentful/field-editor-list@0.15.2) (2021-08-19)
117
-
118
- **Note:** Version bump only for package @contentful/field-editor-list
119
-
120
- ## [0.15.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.15.0...@contentful/field-editor-list@0.15.1) (2021-07-29)
121
-
122
- **Note:** Version bump only for package @contentful/field-editor-list
123
-
124
- # [0.15.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.14.6...@contentful/field-editor-list@0.15.0) (2021-07-23)
125
-
126
- ### Features
127
-
128
- - 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
129
-
130
- ## [0.14.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.14.3...@contentful/field-editor-list@0.14.6) (2021-07-06)
131
-
132
- **Note:** Version bump only for package @contentful/field-editor-list
133
-
134
- ## [0.14.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.14.3...@contentful/field-editor-list@0.14.5) (2021-07-06)
135
-
136
- **Note:** Version bump only for package @contentful/field-editor-list
137
-
138
- ## [0.14.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.14.3...@contentful/field-editor-list@0.14.4) (2021-06-23)
139
-
140
- **Note:** Version bump only for package @contentful/field-editor-list
141
-
142
- ## [0.14.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.14.2...@contentful/field-editor-list@0.14.3) (2021-06-23)
143
-
144
- **Note:** Version bump only for package @contentful/field-editor-list
145
-
146
- ## [0.14.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.14.1...@contentful/field-editor-list@0.14.2) (2021-06-22)
147
-
148
- **Note:** Version bump only for package @contentful/field-editor-list
149
-
150
- ## [0.14.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.14.0...@contentful/field-editor-list@0.14.1) (2021-03-05)
151
-
152
- **Note:** Version bump only for package @contentful/field-editor-list
153
-
154
- # [0.14.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.13.2...@contentful/field-editor-list@0.14.0) (2021-02-19)
155
-
156
- ### Features
157
-
158
- - bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
159
-
160
- ## [0.13.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.13.1...@contentful/field-editor-list@0.13.2) (2021-02-09)
161
-
162
- **Note:** Version bump only for package @contentful/field-editor-list
163
-
164
- ## [0.13.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.13.0...@contentful/field-editor-list@0.13.1) (2021-02-01)
165
-
166
- **Note:** Version bump only for package @contentful/field-editor-list
167
-
168
- # [0.13.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.12.0...@contentful/field-editor-list@0.13.0) (2021-01-20)
169
-
170
- ### Features
171
-
172
- - update minimal forma-36 versions to use updated design ([#565](https://github.com/contentful/field-editors/issues/565)) ([332c734](https://github.com/contentful/field-editors/commit/332c734bfaf54f0e9773fcbb460d743b1f5459ec))
173
-
174
- # [0.12.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.11.5...@contentful/field-editor-list@0.12.0) (2021-01-12)
175
-
176
- ### Features
177
-
178
- - update minimal required Forma version to the 3.73.12 ([#552](https://github.com/contentful/field-editors/issues/552)) ([2816fd9](https://github.com/contentful/field-editors/commit/2816fd960c28815faebf49a9ef8f4c4c0d91fc36))
179
-
180
- ## [0.11.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.11.4...@contentful/field-editor-list@0.11.5) (2020-12-16)
181
-
182
- **Note:** Version bump only for package @contentful/field-editor-list
183
-
184
- ## [0.11.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.11.3...@contentful/field-editor-list@0.11.4) (2020-11-06)
185
-
186
- **Note:** Version bump only for package @contentful/field-editor-list
187
-
188
- ## [0.11.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.11.2...@contentful/field-editor-list@0.11.3) (2020-11-06)
189
-
190
- **Note:** Version bump only for package @contentful/field-editor-list
191
-
192
- ## [0.11.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.11.1...@contentful/field-editor-list@0.11.2) (2020-10-28)
193
-
194
- **Note:** Version bump only for package @contentful/field-editor-list
195
-
196
- ## [0.11.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-list@0.11.0...@contentful/field-editor-list@0.11.1) (2020-08-24)
197
-
198
- **Note:** Version bump only for package @contentful/field-editor-list
@@ -1,72 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var React = require('react');
8
- var f36Components = require('@contentful/f36-components');
9
- var fieldEditorShared = require('@contentful/field-editor-shared');
10
- var isEqual = _interopDefault(require('lodash/isEqual'));
11
- var emotion = require('emotion');
12
-
13
- const rightToLeft = /*#__PURE__*/emotion.css({
14
- direction: 'rtl'
15
- });
16
-
17
- function isEmptyListValue(value) {
18
- return value === null || value.length === 0;
19
- }
20
-
21
- function ListEditor(props) {
22
- const {
23
- field,
24
- locales
25
- } = props;
26
- const direction = locales.direction[field.locale] || 'ltr';
27
- return React.createElement(fieldEditorShared.FieldConnector, {
28
- throttle: 0,
29
- isEmptyValue: isEmptyListValue,
30
- field: field,
31
- isInitiallyDisabled: props.isInitiallyDisabled
32
- }, childProps => React.createElement(ListEditorInternal, { ...childProps,
33
- direction: direction,
34
- isRequired: field.required
35
- }));
36
- }
37
-
38
- function ListEditorInternal({
39
- setValue,
40
- value,
41
- errors,
42
- disabled,
43
- direction,
44
- isRequired
45
- }) {
46
- const [valueState, setValueState] = React.useState(() => (value || []).join(', '));
47
-
48
- const onChange = e => {
49
- const valueAsArray = e.target.value.split(',').map(item => item.trim()).filter(item => item);
50
- const changed = !isEqual(valueAsArray, value);
51
- setValue(valueAsArray);
52
- const valueAsString = valueAsArray.join(', ');
53
- setValueState(changed ? valueAsString : e.target.value);
54
- };
55
-
56
- return React.createElement(f36Components.TextInput, {
57
- testId: "list-editor-input",
58
- className: direction === 'rtl' ? rightToLeft : '',
59
- isRequired: isRequired,
60
- isInvalid: errors.length > 0,
61
- isDisabled: disabled,
62
- value: valueState,
63
- onChange: onChange
64
- });
65
- }
66
-
67
- ListEditor.defaultProps = {
68
- isInitiallyDisabled: true
69
- };
70
-
71
- exports.ListEditor = ListEditor;
72
- //# sourceMappingURL=field-editor-list.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"field-editor-list.cjs.development.js","sources":["../src/styles.ts","../src/ListEditor.tsx"],"sourcesContent":["import { css } from 'emotion';\n\nexport const rightToLeft = css({\n direction: 'rtl',\n});\n","import * as React from 'react';\n\nimport { TextInput } from '@contentful/f36-components';\nimport { FieldAPI, FieldConnector, LocalesAPI } from '@contentful/field-editor-shared';\nimport { FieldConnectorChildProps } from '@contentful/field-editor-shared/dist/FieldConnector';\nimport isEqual from 'lodash/isEqual';\n\nimport * as styles from './styles';\n\n\nexport interface ListEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\ntype ListValue = string[];\n\nfunction isEmptyListValue(value: ListValue | null) {\n return value === null || value.length === 0;\n}\n\nexport function ListEditor(props: ListEditorProps) {\n const { field, locales } = props;\n\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<ListValue>\n throttle={0}\n isEmptyValue={isEmptyListValue}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {(childProps) => (\n <ListEditorInternal {...childProps} direction={direction} isRequired={field.required} />\n )}\n </FieldConnector>\n );\n}\n\nfunction ListEditorInternal({\n setValue,\n value,\n errors,\n disabled,\n direction,\n isRequired,\n}: FieldConnectorChildProps<ListValue> & { direction: 'rtl' | 'ltr'; isRequired: boolean }) {\n const [valueState, setValueState] = React.useState(() => (value || []).join(', '));\n\n const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const valueAsArray = e.target.value\n .split(',')\n .map((item) => item.trim())\n .filter((item) => item);\n const changed = !isEqual(valueAsArray, value);\n setValue(valueAsArray);\n\n const valueAsString = valueAsArray.join(', ');\n setValueState(changed ? valueAsString : e.target.value);\n };\n\n return (\n <TextInput\n testId=\"list-editor-input\"\n className={direction === 'rtl' ? styles.rightToLeft : ''}\n isRequired={isRequired}\n isInvalid={errors.length > 0}\n isDisabled={disabled}\n value={valueState}\n onChange={onChange}\n />\n );\n}\n\nListEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["rightToLeft","css","direction","isEmptyListValue","value","length","ListEditor","props","field","locales","locale","React","FieldConnector","throttle","isEmptyValue","isInitiallyDisabled","childProps","ListEditorInternal","isRequired","required","setValue","errors","disabled","valueState","setValueState","join","onChange","e","valueAsArray","target","split","map","item","trim","filter","changed","isEqual","valueAsString","TextInput","testId","className","styles","isInvalid","isDisabled","defaultProps"],"mappings":";;;;;;;;;;;;AAEO,MAAMA,WAAW,gBAAGC,WAAG,CAAC;AAC7BC,EAAAA,SAAS,EAAE;AADkB,CAAD,CAAvB;;AC2BP,SAASC,gBAAT,CAA0BC,KAA1B;AACE,SAAOA,KAAK,KAAK,IAAV,IAAkBA,KAAK,CAACC,MAAN,KAAiB,CAA1C;AACD;;AAED,SAAgBC,WAAWC;AACzB,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAAqBF,KAA3B;AAEA,QAAML,SAAS,GAAGO,OAAO,CAACP,SAAR,CAAkBM,KAAK,CAACE,MAAxB,KAAmC,KAArD;AAEA,SACEC,mBAAA,CAACC,gCAAD;AACEC,IAAAA,QAAQ,EAAE;AACVC,IAAAA,YAAY,EAAEX;AACdK,IAAAA,KAAK,EAAEA;AACPO,IAAAA,mBAAmB,EAAER,KAAK,CAACQ;GAJ7B,EAKIC,UAAD,IACCL,mBAAA,CAACM,kBAAD,OAAwBD;AAAYd,IAAAA,SAAS,EAAEA;AAAWgB,IAAAA,UAAU,EAAEV,KAAK,CAACW;GAA5E,CANJ,CADF;AAWD;;AAED,SAASF,kBAAT,CAA4B;AAC1BG,EAAAA,QAD0B;AAE1BhB,EAAAA,KAF0B;AAG1BiB,EAAAA,MAH0B;AAI1BC,EAAAA,QAJ0B;AAK1BpB,EAAAA,SAL0B;AAM1BgB,EAAAA;AAN0B,CAA5B;AAQE,QAAM,CAACK,UAAD,EAAaC,aAAb,IAA8Bb,cAAA,CAAe,MAAM,CAACP,KAAK,IAAI,EAAV,EAAcqB,IAAd,CAAmB,IAAnB,CAArB,CAApC;;AAEA,QAAMC,QAAQ,GAAIC,CAAD;AACf,UAAMC,YAAY,GAAGD,CAAC,CAACE,MAAF,CAASzB,KAAT,CAClB0B,KADkB,CACZ,GADY,EAElBC,GAFkB,CAEbC,IAAD,IAAUA,IAAI,CAACC,IAAL,EAFI,EAGlBC,MAHkB,CAGVF,IAAD,IAAUA,IAHC,CAArB;AAIA,UAAMG,OAAO,GAAG,CAACC,OAAO,CAACR,YAAD,EAAexB,KAAf,CAAxB;AACAgB,IAAAA,QAAQ,CAACQ,YAAD,CAAR;AAEA,UAAMS,aAAa,GAAGT,YAAY,CAACH,IAAb,CAAkB,IAAlB,CAAtB;AACAD,IAAAA,aAAa,CAACW,OAAO,GAAGE,aAAH,GAAmBV,CAAC,CAACE,MAAF,CAASzB,KAApC,CAAb;AACD,GAVD;;AAYA,SACEO,mBAAA,CAAC2B,uBAAD;AACEC,IAAAA,MAAM,EAAC;AACPC,IAAAA,SAAS,EAAEtC,SAAS,KAAK,KAAd,GAAsBuC,WAAtB,GAA2C;AACtDvB,IAAAA,UAAU,EAAEA;AACZwB,IAAAA,SAAS,EAAErB,MAAM,CAAChB,MAAP,GAAgB;AAC3BsC,IAAAA,UAAU,EAAErB;AACZlB,IAAAA,KAAK,EAAEmB;AACPG,IAAAA,QAAQ,EAAEA;GAPZ,CADF;AAWD;;AAEDpB,UAAU,CAACsC,YAAX,GAA0B;AACxB7B,EAAAA,mBAAmB,EAAE;AADG,CAA1B;;;;"}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),i=require("@contentful/f36-components"),r=require("@contentful/field-editor-shared"),l=(e=require("lodash/isEqual"))&&"object"==typeof e&&"default"in e?e.default:e;const n=require("emotion").css({direction:"rtl"});function s(e){return null===e||0===e.length}function o(e){const{field:i,locales:l}=e,n=l.direction[i.locale]||"ltr";return t.createElement(r.FieldConnector,{throttle:0,isEmptyValue:s,field:i,isInitiallyDisabled:e.isInitiallyDisabled},e=>t.createElement(a,{...e,direction:n,isRequired:i.required}))}function a({setValue:e,value:r,errors:s,disabled:o,direction:a,isRequired:u}){const[d,c]=t.useState(()=>(r||[]).join(", "));return t.createElement(i.TextInput,{testId:"list-editor-input",className:"rtl"===a?n:"",isRequired:u,isInvalid:s.length>0,isDisabled:o,value:d,onChange:t=>{const i=t.target.value.split(",").map(e=>e.trim()).filter(e=>e),n=!l(i,r);e(i);const s=i.join(", ");c(n?s:t.target.value)}})}o.defaultProps={isInitiallyDisabled:!0},exports.ListEditor=o;
2
- //# sourceMappingURL=field-editor-list.cjs.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"field-editor-list.cjs.production.min.js","sources":["../src/styles.ts","../src/ListEditor.tsx"],"sourcesContent":["import { css } from 'emotion';\n\nexport const rightToLeft = css({\n direction: 'rtl',\n});\n","import * as React from 'react';\n\nimport { TextInput } from '@contentful/f36-components';\nimport { FieldAPI, FieldConnector, LocalesAPI } from '@contentful/field-editor-shared';\nimport { FieldConnectorChildProps } from '@contentful/field-editor-shared/dist/FieldConnector';\nimport isEqual from 'lodash/isEqual';\n\nimport * as styles from './styles';\n\n\nexport interface ListEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\ntype ListValue = string[];\n\nfunction isEmptyListValue(value: ListValue | null) {\n return value === null || value.length === 0;\n}\n\nexport function ListEditor(props: ListEditorProps) {\n const { field, locales } = props;\n\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<ListValue>\n throttle={0}\n isEmptyValue={isEmptyListValue}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {(childProps) => (\n <ListEditorInternal {...childProps} direction={direction} isRequired={field.required} />\n )}\n </FieldConnector>\n );\n}\n\nfunction ListEditorInternal({\n setValue,\n value,\n errors,\n disabled,\n direction,\n isRequired,\n}: FieldConnectorChildProps<ListValue> & { direction: 'rtl' | 'ltr'; isRequired: boolean }) {\n const [valueState, setValueState] = React.useState(() => (value || []).join(', '));\n\n const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const valueAsArray = e.target.value\n .split(',')\n .map((item) => item.trim())\n .filter((item) => item);\n const changed = !isEqual(valueAsArray, value);\n setValue(valueAsArray);\n\n const valueAsString = valueAsArray.join(', ');\n setValueState(changed ? valueAsString : e.target.value);\n };\n\n return (\n <TextInput\n testId=\"list-editor-input\"\n className={direction === 'rtl' ? styles.rightToLeft : ''}\n isRequired={isRequired}\n isInvalid={errors.length > 0}\n isDisabled={disabled}\n value={valueState}\n onChange={onChange}\n />\n );\n}\n\nListEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["rightToLeft","direction","isEmptyListValue","value","length","ListEditor","props","field","locales","locale","React","FieldConnector","throttle","isEmptyValue","isInitiallyDisabled","childProps","ListEditorInternal","isRequired","required","setValue","errors","disabled","valueState","setValueState","join","TextInput","testId","className","styles","isInvalid","isDisabled","onChange","e","valueAsArray","target","split","map","item","trim","filter","changed","isEqual","valueAsString","defaultProps"],"mappings":"iQAEO,MAAMA,yBAAkB,CAC7BC,UAAW,QC0Bb,SAASC,EAAiBC,UACP,OAAVA,GAAmC,IAAjBA,EAAMC,gBAGjBC,EAAWC,SACnBC,MAAEA,EAAFC,QAASA,GAAYF,EAErBL,EAAYO,EAAQP,UAAUM,EAAME,SAAW,aAGnDC,gBAACC,kBACCC,SAAU,EACVC,aAAcX,EACdK,MAAOA,EACPO,oBAAqBR,EAAMQ,qBACzBC,GACAL,gBAACM,MAAuBD,EAAYd,UAAWA,EAAWgB,WAAYV,EAAMW,YAMpF,SAASF,GAAmBG,SAC1BA,EAD0BhB,MAE1BA,EAF0BiB,OAG1BA,EAH0BC,SAI1BA,EAJ0BpB,UAK1BA,EAL0BgB,WAM1BA,UAEOK,EAAYC,GAAiBb,WAAe,KAAOP,GAAS,IAAIqB,KAAK,cAe1Ed,gBAACe,aACCC,OAAO,oBACPC,UAAyB,QAAd1B,EAAsB2B,EAAqB,GACtDX,WAAYA,EACZY,UAAWT,EAAOhB,OAAS,EAC3B0B,WAAYT,EACZlB,MAAOmB,EACPS,SApBcC,UACVC,EAAeD,EAAEE,OAAO/B,MAC3BgC,MAAM,KACNC,IAAKC,GAASA,EAAKC,QACnBC,OAAQF,GAASA,GACdG,GAAWC,EAAQR,EAAc9B,GACvCgB,EAASc,SAEHS,EAAgBT,EAAaT,KAAK,MACxCD,EAAciB,EAAUE,EAAgBV,EAAEE,OAAO/B,UAgBrDE,EAAWsC,aAAe,CACxB7B,qBAAqB"}
@@ -1,66 +0,0 @@
1
- import { createElement, useState } from 'react';
2
- import { TextInput } from '@contentful/f36-components';
3
- import { FieldConnector } from '@contentful/field-editor-shared';
4
- import isEqual from 'lodash-es/isEqual';
5
- import { css } from 'emotion';
6
-
7
- const rightToLeft = /*#__PURE__*/css({
8
- direction: 'rtl'
9
- });
10
-
11
- function isEmptyListValue(value) {
12
- return value === null || value.length === 0;
13
- }
14
-
15
- function ListEditor(props) {
16
- const {
17
- field,
18
- locales
19
- } = props;
20
- const direction = locales.direction[field.locale] || 'ltr';
21
- return createElement(FieldConnector, {
22
- throttle: 0,
23
- isEmptyValue: isEmptyListValue,
24
- field: field,
25
- isInitiallyDisabled: props.isInitiallyDisabled
26
- }, childProps => createElement(ListEditorInternal, { ...childProps,
27
- direction: direction,
28
- isRequired: field.required
29
- }));
30
- }
31
-
32
- function ListEditorInternal({
33
- setValue,
34
- value,
35
- errors,
36
- disabled,
37
- direction,
38
- isRequired
39
- }) {
40
- const [valueState, setValueState] = useState(() => (value || []).join(', '));
41
-
42
- const onChange = e => {
43
- const valueAsArray = e.target.value.split(',').map(item => item.trim()).filter(item => item);
44
- const changed = !isEqual(valueAsArray, value);
45
- setValue(valueAsArray);
46
- const valueAsString = valueAsArray.join(', ');
47
- setValueState(changed ? valueAsString : e.target.value);
48
- };
49
-
50
- return createElement(TextInput, {
51
- testId: "list-editor-input",
52
- className: direction === 'rtl' ? rightToLeft : '',
53
- isRequired: isRequired,
54
- isInvalid: errors.length > 0,
55
- isDisabled: disabled,
56
- value: valueState,
57
- onChange: onChange
58
- });
59
- }
60
-
61
- ListEditor.defaultProps = {
62
- isInitiallyDisabled: true
63
- };
64
-
65
- export { ListEditor };
66
- //# sourceMappingURL=field-editor-list.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"field-editor-list.esm.js","sources":["../src/styles.ts","../src/ListEditor.tsx"],"sourcesContent":["import { css } from 'emotion';\n\nexport const rightToLeft = css({\n direction: 'rtl',\n});\n","import * as React from 'react';\n\nimport { TextInput } from '@contentful/f36-components';\nimport { FieldAPI, FieldConnector, LocalesAPI } from '@contentful/field-editor-shared';\nimport { FieldConnectorChildProps } from '@contentful/field-editor-shared/dist/FieldConnector';\nimport isEqual from 'lodash/isEqual';\n\nimport * as styles from './styles';\n\n\nexport interface ListEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\ntype ListValue = string[];\n\nfunction isEmptyListValue(value: ListValue | null) {\n return value === null || value.length === 0;\n}\n\nexport function ListEditor(props: ListEditorProps) {\n const { field, locales } = props;\n\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<ListValue>\n throttle={0}\n isEmptyValue={isEmptyListValue}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {(childProps) => (\n <ListEditorInternal {...childProps} direction={direction} isRequired={field.required} />\n )}\n </FieldConnector>\n );\n}\n\nfunction ListEditorInternal({\n setValue,\n value,\n errors,\n disabled,\n direction,\n isRequired,\n}: FieldConnectorChildProps<ListValue> & { direction: 'rtl' | 'ltr'; isRequired: boolean }) {\n const [valueState, setValueState] = React.useState(() => (value || []).join(', '));\n\n const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const valueAsArray = e.target.value\n .split(',')\n .map((item) => item.trim())\n .filter((item) => item);\n const changed = !isEqual(valueAsArray, value);\n setValue(valueAsArray);\n\n const valueAsString = valueAsArray.join(', ');\n setValueState(changed ? valueAsString : e.target.value);\n };\n\n return (\n <TextInput\n testId=\"list-editor-input\"\n className={direction === 'rtl' ? styles.rightToLeft : ''}\n isRequired={isRequired}\n isInvalid={errors.length > 0}\n isDisabled={disabled}\n value={valueState}\n onChange={onChange}\n />\n );\n}\n\nListEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["rightToLeft","css","direction","isEmptyListValue","value","length","ListEditor","props","field","locales","locale","React","FieldConnector","throttle","isEmptyValue","isInitiallyDisabled","childProps","ListEditorInternal","isRequired","required","setValue","errors","disabled","valueState","setValueState","join","onChange","e","valueAsArray","target","split","map","item","trim","filter","changed","isEqual","valueAsString","TextInput","testId","className","styles","isInvalid","isDisabled","defaultProps"],"mappings":";;;;;;AAEO,MAAMA,WAAW,gBAAGC,GAAG,CAAC;AAC7BC,EAAAA,SAAS,EAAE;AADkB,CAAD,CAAvB;;AC2BP,SAASC,gBAAT,CAA0BC,KAA1B;AACE,SAAOA,KAAK,KAAK,IAAV,IAAkBA,KAAK,CAACC,MAAN,KAAiB,CAA1C;AACD;;AAED,SAAgBC,WAAWC;AACzB,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAAqBF,KAA3B;AAEA,QAAML,SAAS,GAAGO,OAAO,CAACP,SAAR,CAAkBM,KAAK,CAACE,MAAxB,KAAmC,KAArD;AAEA,SACEC,aAAA,CAACC,cAAD;AACEC,IAAAA,QAAQ,EAAE;AACVC,IAAAA,YAAY,EAAEX;AACdK,IAAAA,KAAK,EAAEA;AACPO,IAAAA,mBAAmB,EAAER,KAAK,CAACQ;GAJ7B,EAKIC,UAAD,IACCL,aAAA,CAACM,kBAAD,OAAwBD;AAAYd,IAAAA,SAAS,EAAEA;AAAWgB,IAAAA,UAAU,EAAEV,KAAK,CAACW;GAA5E,CANJ,CADF;AAWD;;AAED,SAASF,kBAAT,CAA4B;AAC1BG,EAAAA,QAD0B;AAE1BhB,EAAAA,KAF0B;AAG1BiB,EAAAA,MAH0B;AAI1BC,EAAAA,QAJ0B;AAK1BpB,EAAAA,SAL0B;AAM1BgB,EAAAA;AAN0B,CAA5B;AAQE,QAAM,CAACK,UAAD,EAAaC,aAAb,IAA8Bb,QAAA,CAAe,MAAM,CAACP,KAAK,IAAI,EAAV,EAAcqB,IAAd,CAAmB,IAAnB,CAArB,CAApC;;AAEA,QAAMC,QAAQ,GAAIC,CAAD;AACf,UAAMC,YAAY,GAAGD,CAAC,CAACE,MAAF,CAASzB,KAAT,CAClB0B,KADkB,CACZ,GADY,EAElBC,GAFkB,CAEbC,IAAD,IAAUA,IAAI,CAACC,IAAL,EAFI,EAGlBC,MAHkB,CAGVF,IAAD,IAAUA,IAHC,CAArB;AAIA,UAAMG,OAAO,GAAG,CAACC,OAAO,CAACR,YAAD,EAAexB,KAAf,CAAxB;AACAgB,IAAAA,QAAQ,CAACQ,YAAD,CAAR;AAEA,UAAMS,aAAa,GAAGT,YAAY,CAACH,IAAb,CAAkB,IAAlB,CAAtB;AACAD,IAAAA,aAAa,CAACW,OAAO,GAAGE,aAAH,GAAmBV,CAAC,CAACE,MAAF,CAASzB,KAApC,CAAb;AACD,GAVD;;AAYA,SACEO,aAAA,CAAC2B,SAAD;AACEC,IAAAA,MAAM,EAAC;AACPC,IAAAA,SAAS,EAAEtC,SAAS,KAAK,KAAd,GAAsBuC,WAAtB,GAA2C;AACtDvB,IAAAA,UAAU,EAAEA;AACZwB,IAAAA,SAAS,EAAErB,MAAM,CAAChB,MAAP,GAAgB;AAC3BsC,IAAAA,UAAU,EAAErB;AACZlB,IAAAA,KAAK,EAAEmB;AACPG,IAAAA,QAAQ,EAAEA;GAPZ,CADF;AAWD;;AAEDpB,UAAU,CAACsC,YAAX,GAA0B;AACxB7B,EAAAA,mBAAmB,EAAE;AADG,CAA1B;;;;"}
package/dist/index.js DELETED
@@ -1,8 +0,0 @@
1
-
2
- 'use strict'
3
-
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./field-editor-list.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./field-editor-list.cjs.development.js')
8
- }