@contentful/field-editor-list 1.1.11 → 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.1.11",
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.1.8",
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.2.7"
46
+ "@contentful/field-editor-test-utils": "^1.4.0"
33
47
  },
34
48
  "peerDependencies": {
35
49
  "react": ">=16.8.0"
36
50
  },
37
- "gitHead": "4fff7b9534374dcc44cb477240d369fc34f46415"
51
+ "gitHead": "543e02672a8dd4edc810f9f3568d6b69c454e1f9"
38
52
  }
package/CHANGELOG.md DELETED
@@ -1,192 +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.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)
7
-
8
- **Note:** Version bump only for package @contentful/field-editor-list
9
-
10
- ## [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)
11
-
12
- **Note:** Version bump only for package @contentful/field-editor-list
13
-
14
- ## [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)
15
-
16
- **Note:** Version bump only for package @contentful/field-editor-list
17
-
18
- ## [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)
19
-
20
- **Note:** Version bump only for package @contentful/field-editor-list
21
-
22
- ## [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)
23
-
24
- **Note:** Version bump only for package @contentful/field-editor-list
25
-
26
- ## [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)
27
-
28
- **Note:** Version bump only for package @contentful/field-editor-list
29
-
30
- ## [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)
31
-
32
- **Note:** Version bump only for package @contentful/field-editor-list
33
-
34
- ## [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)
35
-
36
- **Note:** Version bump only for package @contentful/field-editor-list
37
-
38
- ## [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)
39
-
40
- **Note:** Version bump only for package @contentful/field-editor-list
41
-
42
- ## [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)
43
-
44
- ### Bug Fixes
45
-
46
- - bump f36 packages ([#1025](https://github.com/contentful/field-editors/issues/1025)) ([ec37a40](https://github.com/contentful/field-editors/commit/ec37a4000db7cd75c66dd9621136b2272c9feeea))
47
-
48
- ## [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)
49
-
50
- **Note:** Version bump only for package @contentful/field-editor-list
51
-
52
- # [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)
53
-
54
- ### Features
55
-
56
- - 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))
57
-
58
- ## [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)
59
-
60
- ### Bug Fixes
61
-
62
- - markdown buttons ([#968](https://github.com/contentful/field-editors/issues/968)) ([9803b98](https://github.com/contentful/field-editors/commit/9803b98c25d92df6148686ffe2749a77f7efdbb9))
63
-
64
- ## [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)
65
-
66
- **Note:** Version bump only for package @contentful/field-editor-list
67
-
68
- ## [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)
69
-
70
- ### Bug Fixes
71
-
72
- - 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))
73
-
74
- ## [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)
75
-
76
- ### Bug Fixes
77
-
78
- - **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))
79
-
80
- # [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)
81
-
82
- **Note:** Version bump only for package @contentful/field-editor-list
83
-
84
- # [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)
85
-
86
- ### Features
87
-
88
- - Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
89
-
90
- ### BREAKING CHANGES
91
-
92
- - adopts a new Forma v4 beta
93
-
94
- ## [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)
95
-
96
- **Note:** Version bump only for package @contentful/field-editor-list
97
-
98
- ## [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)
99
-
100
- **Note:** Version bump only for package @contentful/field-editor-list
101
-
102
- ## [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)
103
-
104
- **Note:** Version bump only for package @contentful/field-editor-list
105
-
106
- ## [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)
107
-
108
- **Note:** Version bump only for package @contentful/field-editor-list
109
-
110
- ## [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)
111
-
112
- **Note:** Version bump only for package @contentful/field-editor-list
113
-
114
- ## [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)
115
-
116
- **Note:** Version bump only for package @contentful/field-editor-list
117
-
118
- # [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)
119
-
120
- ### Features
121
-
122
- - 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
123
-
124
- ## [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)
125
-
126
- **Note:** Version bump only for package @contentful/field-editor-list
127
-
128
- ## [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)
129
-
130
- **Note:** Version bump only for package @contentful/field-editor-list
131
-
132
- ## [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)
133
-
134
- **Note:** Version bump only for package @contentful/field-editor-list
135
-
136
- ## [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)
137
-
138
- **Note:** Version bump only for package @contentful/field-editor-list
139
-
140
- ## [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)
141
-
142
- **Note:** Version bump only for package @contentful/field-editor-list
143
-
144
- ## [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)
145
-
146
- **Note:** Version bump only for package @contentful/field-editor-list
147
-
148
- # [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)
149
-
150
- ### Features
151
-
152
- - bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
153
-
154
- ## [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)
155
-
156
- **Note:** Version bump only for package @contentful/field-editor-list
157
-
158
- ## [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)
159
-
160
- **Note:** Version bump only for package @contentful/field-editor-list
161
-
162
- # [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)
163
-
164
- ### Features
165
-
166
- - 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))
167
-
168
- # [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)
169
-
170
- ### Features
171
-
172
- - 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))
173
-
174
- ## [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)
175
-
176
- **Note:** Version bump only for package @contentful/field-editor-list
177
-
178
- ## [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)
179
-
180
- **Note:** Version bump only for package @contentful/field-editor-list
181
-
182
- ## [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)
183
-
184
- **Note:** Version bump only for package @contentful/field-editor-list
185
-
186
- ## [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)
187
-
188
- **Note:** Version bump only for package @contentful/field-editor-list
189
-
190
- ## [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)
191
-
192
- **Note:** Version bump only for package @contentful/field-editor-list
@@ -1,98 +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 fieldEditorShared = require('@contentful/field-editor-shared');
9
- var emotion = require('emotion');
10
- var isEqual = _interopDefault(require('lodash/isEqual'));
11
- var f36Components = require('@contentful/f36-components');
12
-
13
- function _extends() {
14
- _extends = Object.assign || function (target) {
15
- for (var i = 1; i < arguments.length; i++) {
16
- var source = arguments[i];
17
-
18
- for (var key in source) {
19
- if (Object.prototype.hasOwnProperty.call(source, key)) {
20
- target[key] = source[key];
21
- }
22
- }
23
- }
24
-
25
- return target;
26
- };
27
-
28
- return _extends.apply(this, arguments);
29
- }
30
-
31
- var rightToLeft = /*#__PURE__*/emotion.css({
32
- direction: 'rtl'
33
- });
34
-
35
- function isEmptyListValue(value) {
36
- return value === null || value.length === 0;
37
- }
38
-
39
- function ListEditor(props) {
40
- var field = props.field,
41
- locales = props.locales;
42
- var direction = locales.direction[field.locale] || 'ltr';
43
- return React.createElement(fieldEditorShared.FieldConnector, {
44
- throttle: 0,
45
- isEmptyValue: isEmptyListValue,
46
- field: field,
47
- isInitiallyDisabled: props.isInitiallyDisabled
48
- }, function (childProps) {
49
- return React.createElement(ListEditorInternal, _extends({}, childProps, {
50
- direction: direction,
51
- isRequired: field.required
52
- }));
53
- });
54
- }
55
-
56
- function ListEditorInternal(_ref) {
57
- var setValue = _ref.setValue,
58
- value = _ref.value,
59
- errors = _ref.errors,
60
- disabled = _ref.disabled,
61
- direction = _ref.direction,
62
- isRequired = _ref.isRequired;
63
-
64
- var _React$useState = React.useState(function () {
65
- return (value || []).join(', ');
66
- }),
67
- valueState = _React$useState[0],
68
- setValueState = _React$useState[1];
69
-
70
- var onChange = function onChange(e) {
71
- var valueAsArray = e.target.value.split(',').map(function (item) {
72
- return item.trim();
73
- }).filter(function (item) {
74
- return item;
75
- });
76
- var changed = !isEqual(valueAsArray, value);
77
- setValue(valueAsArray);
78
- var valueAsString = valueAsArray.join(', ');
79
- setValueState(changed ? valueAsString : e.target.value);
80
- };
81
-
82
- return React.createElement(f36Components.TextInput, {
83
- testId: "list-editor-input",
84
- className: direction === 'rtl' ? rightToLeft : '',
85
- isRequired: isRequired,
86
- isInvalid: errors.length > 0,
87
- isDisabled: disabled,
88
- value: valueState,
89
- onChange: onChange
90
- });
91
- }
92
-
93
- ListEditor.defaultProps = {
94
- isInitiallyDisabled: true
95
- };
96
-
97
- exports.ListEditor = ListEditor;
98
- //# 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';\nimport { FieldAPI, FieldConnector, LocalesAPI } from '@contentful/field-editor-shared';\nimport * as styles from './styles';\nimport isEqual from 'lodash/isEqual';\n\nimport { TextInput } from '@contentful/f36-components';\nimport { FieldConnectorChildProps } from '@contentful/field-editor-shared/dist/FieldConnector';\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","join","valueState","setValueState","onChange","e","valueAsArray","target","split","map","item","trim","filter","changed","isEqual","valueAsString","TextInput","testId","className","styles","isInvalid","isDisabled","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,IAAMA,WAAW,gBAAGC,WAAG,CAAC;AAC7BC,EAAAA,SAAS,EAAE;AADkB,CAAD,CAAvB;;ACyBP,SAASC,gBAAT,CAA0BC,KAA1B;AACE,SAAOA,KAAK,KAAK,IAAV,IAAkBA,KAAK,CAACC,MAAN,KAAiB,CAA1C;AACD;;AAED,SAAgBC,WAAWC;AACzB,MAAQC,KAAR,GAA2BD,KAA3B,CAAQC,KAAR;AAAA,MAAeC,OAAf,GAA2BF,KAA3B,CAAeE,OAAf;AAEA,MAAMP,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,EAKG,UAACC,UAAD;AAAA,WACCL,mBAAA,CAACM,kBAAD,eAAwBD,UAAxB;AAAoCd,MAAAA,SAAS,EAAEA,SAA/C;AAA0DgB,MAAAA,UAAU,EAAEV,KAAK,CAACW;AAA5E,OADD;AAAA,GALH,CADF;AAWD;;AAED,SAASF,kBAAT;MACEG,gBAAAA;MACAhB,aAAAA;MACAiB,cAAAA;MACAC,gBAAAA;MACApB,iBAAAA;MACAgB,kBAAAA;;AAEA,wBAAoCP,cAAA,CAAe;AAAA,WAAM,CAACP,KAAK,IAAI,EAAV,EAAcmB,IAAd,CAAmB,IAAnB,CAAN;AAAA,GAAf,CAApC;AAAA,MAAOC,UAAP;AAAA,MAAmBC,aAAnB;;AAEA,MAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACC,CAAD;AACf,QAAMC,YAAY,GAAGD,CAAC,CAACE,MAAF,CAASzB,KAAT,CAClB0B,KADkB,CACZ,GADY,EAElBC,GAFkB,CAEd,UAACC,IAAD;AAAA,aAAUA,IAAI,CAACC,IAAL,EAAV;AAAA,KAFc,EAGlBC,MAHkB,CAGX,UAACF,IAAD;AAAA,aAAUA,IAAV;AAAA,KAHW,CAArB;AAIA,QAAMG,OAAO,GAAG,CAACC,OAAO,CAACR,YAAD,EAAexB,KAAf,CAAxB;AACAgB,IAAAA,QAAQ,CAACQ,YAAD,CAAR;AAEA,QAAMS,aAAa,GAAGT,YAAY,CAACL,IAAb,CAAkB,IAAlB,CAAtB;AACAE,IAAAA,aAAa,CAACU,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,EAAEoB;AACPE,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"),r=require("@contentful/field-editor-shared"),i=require("emotion"),n=(e=require("lodash/isEqual"))&&"object"==typeof e&&"default"in e?e.default:e,l=require("@contentful/f36-components");function a(){return(a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e}).apply(this,arguments)}var u=i.css({direction:"rtl"});function o(e){return null===e||0===e.length}function s(e){var i=e.field,n=e.locales.direction[i.locale]||"ltr";return t.createElement(r.FieldConnector,{throttle:0,isEmptyValue:o,field:i,isInitiallyDisabled:e.isInitiallyDisabled},(function(e){return t.createElement(c,a({},e,{direction:n,isRequired:i.required}))}))}function c(e){var r=e.setValue,i=e.value,a=e.errors,o=e.disabled,s=e.direction,c=e.isRequired,d=t.useState((function(){return(i||[]).join(", ")})),f=d[1];return t.createElement(l.TextInput,{testId:"list-editor-input",className:"rtl"===s?u:"",isRequired:c,isInvalid:a.length>0,isDisabled:o,value:d[0],onChange:function(e){var t=e.target.value.split(",").map((function(e){return e.trim()})).filter((function(e){return e})),l=!n(t,i);r(t);var a=t.join(", ");f(l?a:e.target.value)}})}s.defaultProps={isInitiallyDisabled:!0},exports.ListEditor=s;
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';\nimport { FieldAPI, FieldConnector, LocalesAPI } from '@contentful/field-editor-shared';\nimport * as styles from './styles';\nimport isEqual from 'lodash/isEqual';\n\nimport { TextInput } from '@contentful/f36-components';\nimport { FieldConnectorChildProps } from '@contentful/field-editor-shared/dist/FieldConnector';\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","join","setValueState","TextInput","testId","className","styles","isInvalid","isDisabled","onChange","e","valueAsArray","target","split","map","item","trim","filter","changed","isEqual","valueAsString","defaultProps"],"mappings":"qeAEO,IAAMA,EAAcC,MAAI,CAC7BC,UAAW,QCwBb,SAASC,EAAiBC,UACP,OAAVA,GAAmC,IAAjBA,EAAMC,gBAGjBC,EAAWC,OACjBC,EAAmBD,EAAnBC,MAEFN,EAFqBK,EAAZE,QAEWP,UAAUM,EAAME,SAAW,aAGnDC,gBAACC,kBACCC,SAAU,EACVC,aAAcX,EACdK,MAAOA,EACPO,oBAAqBR,EAAMQ,sBAC1B,SAACC,UACAL,gBAACM,OAAuBD,GAAYd,UAAWA,EAAWgB,WAAYV,EAAMW,eAMpF,SAASF,SACPG,IAAAA,SACAhB,IAAAA,MACAiB,IAAAA,OACAC,IAAAA,SACApB,IAAAA,UACAgB,IAAAA,aAEoCP,YAAe,kBAAOP,GAAS,IAAImB,KAAK,SAAzDC,cAejBb,gBAACc,aACCC,OAAO,oBACPC,UAAyB,QAAdzB,EAAsB0B,EAAqB,GACtDV,WAAYA,EACZW,UAAWR,EAAOhB,OAAS,EAC3ByB,WAAYR,EACZlB,WACA2B,SApBa,SAACC,OACVC,EAAeD,EAAEE,OAAO9B,MAC3B+B,MAAM,KACNC,KAAI,SAACC,UAASA,EAAKC,UACnBC,QAAO,SAACF,UAASA,KACdG,GAAWC,EAAQR,EAAc7B,GACvCgB,EAASa,OAEHS,EAAgBT,EAAaV,KAAK,MACxCC,EAAcgB,EAAUE,EAAgBV,EAAEE,OAAO9B,UAgBrDE,EAAWqC,aAAe,CACxB5B,qBAAqB"}
@@ -1,92 +0,0 @@
1
- import { createElement, useState } from 'react';
2
- import { FieldConnector } from '@contentful/field-editor-shared';
3
- import { css } from 'emotion';
4
- import isEqual from 'lodash-es/isEqual';
5
- import { TextInput } from '@contentful/f36-components';
6
-
7
- function _extends() {
8
- _extends = Object.assign || function (target) {
9
- for (var i = 1; i < arguments.length; i++) {
10
- var source = arguments[i];
11
-
12
- for (var key in source) {
13
- if (Object.prototype.hasOwnProperty.call(source, key)) {
14
- target[key] = source[key];
15
- }
16
- }
17
- }
18
-
19
- return target;
20
- };
21
-
22
- return _extends.apply(this, arguments);
23
- }
24
-
25
- var rightToLeft = /*#__PURE__*/css({
26
- direction: 'rtl'
27
- });
28
-
29
- function isEmptyListValue(value) {
30
- return value === null || value.length === 0;
31
- }
32
-
33
- function ListEditor(props) {
34
- var field = props.field,
35
- locales = props.locales;
36
- var direction = locales.direction[field.locale] || 'ltr';
37
- return createElement(FieldConnector, {
38
- throttle: 0,
39
- isEmptyValue: isEmptyListValue,
40
- field: field,
41
- isInitiallyDisabled: props.isInitiallyDisabled
42
- }, function (childProps) {
43
- return createElement(ListEditorInternal, _extends({}, childProps, {
44
- direction: direction,
45
- isRequired: field.required
46
- }));
47
- });
48
- }
49
-
50
- function ListEditorInternal(_ref) {
51
- var setValue = _ref.setValue,
52
- value = _ref.value,
53
- errors = _ref.errors,
54
- disabled = _ref.disabled,
55
- direction = _ref.direction,
56
- isRequired = _ref.isRequired;
57
-
58
- var _React$useState = useState(function () {
59
- return (value || []).join(', ');
60
- }),
61
- valueState = _React$useState[0],
62
- setValueState = _React$useState[1];
63
-
64
- var onChange = function onChange(e) {
65
- var valueAsArray = e.target.value.split(',').map(function (item) {
66
- return item.trim();
67
- }).filter(function (item) {
68
- return item;
69
- });
70
- var changed = !isEqual(valueAsArray, value);
71
- setValue(valueAsArray);
72
- var valueAsString = valueAsArray.join(', ');
73
- setValueState(changed ? valueAsString : e.target.value);
74
- };
75
-
76
- return createElement(TextInput, {
77
- testId: "list-editor-input",
78
- className: direction === 'rtl' ? rightToLeft : '',
79
- isRequired: isRequired,
80
- isInvalid: errors.length > 0,
81
- isDisabled: disabled,
82
- value: valueState,
83
- onChange: onChange
84
- });
85
- }
86
-
87
- ListEditor.defaultProps = {
88
- isInitiallyDisabled: true
89
- };
90
-
91
- export { ListEditor };
92
- //# 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';\nimport { FieldAPI, FieldConnector, LocalesAPI } from '@contentful/field-editor-shared';\nimport * as styles from './styles';\nimport isEqual from 'lodash/isEqual';\n\nimport { TextInput } from '@contentful/f36-components';\nimport { FieldConnectorChildProps } from '@contentful/field-editor-shared/dist/FieldConnector';\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","join","valueState","setValueState","onChange","e","valueAsArray","target","split","map","item","trim","filter","changed","isEqual","valueAsString","TextInput","testId","className","styles","isInvalid","isDisabled","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAEO,IAAMA,WAAW,gBAAGC,GAAG,CAAC;AAC7BC,EAAAA,SAAS,EAAE;AADkB,CAAD,CAAvB;;ACyBP,SAASC,gBAAT,CAA0BC,KAA1B;AACE,SAAOA,KAAK,KAAK,IAAV,IAAkBA,KAAK,CAACC,MAAN,KAAiB,CAA1C;AACD;;AAED,SAAgBC,WAAWC;AACzB,MAAQC,KAAR,GAA2BD,KAA3B,CAAQC,KAAR;AAAA,MAAeC,OAAf,GAA2BF,KAA3B,CAAeE,OAAf;AAEA,MAAMP,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,EAKG,UAACC,UAAD;AAAA,WACCL,aAAA,CAACM,kBAAD,eAAwBD,UAAxB;AAAoCd,MAAAA,SAAS,EAAEA,SAA/C;AAA0DgB,MAAAA,UAAU,EAAEV,KAAK,CAACW;AAA5E,OADD;AAAA,GALH,CADF;AAWD;;AAED,SAASF,kBAAT;MACEG,gBAAAA;MACAhB,aAAAA;MACAiB,cAAAA;MACAC,gBAAAA;MACApB,iBAAAA;MACAgB,kBAAAA;;AAEA,wBAAoCP,QAAA,CAAe;AAAA,WAAM,CAACP,KAAK,IAAI,EAAV,EAAcmB,IAAd,CAAmB,IAAnB,CAAN;AAAA,GAAf,CAApC;AAAA,MAAOC,UAAP;AAAA,MAAmBC,aAAnB;;AAEA,MAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACC,CAAD;AACf,QAAMC,YAAY,GAAGD,CAAC,CAACE,MAAF,CAASzB,KAAT,CAClB0B,KADkB,CACZ,GADY,EAElBC,GAFkB,CAEd,UAACC,IAAD;AAAA,aAAUA,IAAI,CAACC,IAAL,EAAV;AAAA,KAFc,EAGlBC,MAHkB,CAGX,UAACF,IAAD;AAAA,aAAUA,IAAV;AAAA,KAHW,CAArB;AAIA,QAAMG,OAAO,GAAG,CAACC,OAAO,CAACR,YAAD,EAAexB,KAAf,CAAxB;AACAgB,IAAAA,QAAQ,CAACQ,YAAD,CAAR;AAEA,QAAMS,aAAa,GAAGT,YAAY,CAACL,IAAb,CAAkB,IAAlB,CAAtB;AACAE,IAAAA,aAAa,CAACU,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,EAAEoB;AACPE,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
- }