@contentful/field-editor-single-line 1.1.10 → 1.2.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.
- package/CHANGELOG.md +10 -0
- package/dist/field-editor-single-line.cjs.development.js +20 -19
- package/dist/field-editor-single-line.cjs.development.js.map +1 -1
- package/dist/field-editor-single-line.cjs.production.min.js +1 -1
- package/dist/field-editor-single-line.cjs.production.min.js.map +1 -1
- package/dist/field-editor-single-line.esm.js +20 -19
- package/dist/field-editor-single-line.esm.js.map +1 -1
- package/package.json +4 -14
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.2.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-single-line@1.1.11...@contentful/field-editor-single-line@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-single-line@1.1.10...@contentful/field-editor-single-line@1.1.11) (2023-03-14)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @contentful/field-editor-single-line
|
|
15
|
+
|
|
6
16
|
## [1.1.10](https://github.com/contentful/field-editors/compare/@contentful/field-editor-single-line@1.1.9...@contentful/field-editor-single-line@1.1.10) (2023-03-10)
|
|
7
17
|
|
|
8
18
|
### Bug Fixes
|
|
@@ -5,19 +5,19 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
6
|
|
|
7
7
|
var React = require('react');
|
|
8
|
+
var f36Components = require('@contentful/f36-components');
|
|
8
9
|
var fieldEditorShared = require('@contentful/field-editor-shared');
|
|
9
|
-
var emotion = require('emotion');
|
|
10
10
|
var tokens = _interopDefault(require('@contentful/f36-tokens'));
|
|
11
|
-
var
|
|
11
|
+
var emotion = require('emotion');
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const validationRow = /*#__PURE__*/emotion.css({
|
|
14
14
|
display: 'flex',
|
|
15
15
|
justifyContent: 'space-between',
|
|
16
16
|
fontSize: tokens.fontSizeM,
|
|
17
17
|
marginTop: tokens.spacingXs,
|
|
18
18
|
color: tokens.gray700
|
|
19
19
|
});
|
|
20
|
-
|
|
20
|
+
const rightToLeft = /*#__PURE__*/emotion.css({
|
|
21
21
|
direction: 'rtl'
|
|
22
22
|
});
|
|
23
23
|
|
|
@@ -26,25 +26,28 @@ function isSupportedFieldTypes(val) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function SingleLineEditor(props) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const {
|
|
30
|
+
field,
|
|
31
|
+
locales
|
|
32
|
+
} = props;
|
|
31
33
|
|
|
32
34
|
if (!isSupportedFieldTypes(field.type)) {
|
|
33
|
-
throw new Error("
|
|
35
|
+
throw new Error(`"${field.type}" field type is not supported by SingleLineEditor`);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const constraints = fieldEditorShared.ConstraintsUtils.fromFieldValidations(field.validations, field.type);
|
|
39
|
+
const checkConstraint = fieldEditorShared.ConstraintsUtils.makeChecker(constraints);
|
|
40
|
+
const direction = locales.direction[field.locale] || 'ltr';
|
|
39
41
|
return React.createElement(fieldEditorShared.FieldConnector, {
|
|
40
42
|
field: field,
|
|
41
43
|
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
42
44
|
isDisabled: props.isDisabled
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
}, ({
|
|
46
|
+
value,
|
|
47
|
+
errors,
|
|
48
|
+
disabled,
|
|
49
|
+
setValue
|
|
50
|
+
}) => {
|
|
48
51
|
return React.createElement("div", {
|
|
49
52
|
"data-test-id": "single-line-editor"
|
|
50
53
|
}, React.createElement(f36Components.TextInput, {
|
|
@@ -53,7 +56,7 @@ function SingleLineEditor(props) {
|
|
|
53
56
|
isInvalid: errors.length > 0,
|
|
54
57
|
isDisabled: disabled,
|
|
55
58
|
value: value || '',
|
|
56
|
-
onChange:
|
|
59
|
+
onChange: e => {
|
|
57
60
|
setValue(e.target.value);
|
|
58
61
|
}
|
|
59
62
|
}), props.withCharValidation && React.createElement("div", {
|
|
@@ -67,9 +70,7 @@ function SingleLineEditor(props) {
|
|
|
67
70
|
className: validationRow
|
|
68
71
|
}, React.createElement(fieldEditorShared.CharCounter, {
|
|
69
72
|
value: value || '',
|
|
70
|
-
checkConstraint:
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
+
checkConstraint: () => true
|
|
73
74
|
})));
|
|
74
75
|
});
|
|
75
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-single-line.cjs.development.js","sources":["../src/styles.ts","../src/SingleLineEditor.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"field-editor-single-line.cjs.development.js","sources":["../src/styles.ts","../src/SingleLineEditor.tsx"],"sourcesContent":["import tokens from '@contentful/f36-tokens';\nimport { css } from 'emotion';\n\nexport const validationRow = css({\n display: 'flex',\n justifyContent: 'space-between',\n fontSize: tokens.fontSizeM,\n marginTop: tokens.spacingXs,\n color: tokens.gray700,\n});\n\nexport const rightToLeft = css({\n direction: 'rtl',\n});\n","import * as React from 'react';\n\nimport { TextInput } from '@contentful/f36-components';\nimport {\n FieldAPI,\n FieldConnector,\n ConstraintsUtils,\n CharCounter,\n CharValidation,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\n\nimport * as styles from './styles';\n\n\nexport interface SingleLineEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * is the field manually disabled\n */\n isDisabled?: boolean;\n\n /**\n * whether char validation should be shown or not\n */\n withCharValidation: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\nfunction isSupportedFieldTypes(val: string): val is 'Symbol' | 'Text' {\n return val === 'Symbol' || val === 'Text';\n}\n\nexport function SingleLineEditor(props: SingleLineEditorProps) {\n const { field, locales } = props;\n\n if (!isSupportedFieldTypes(field.type)) {\n throw new Error(`\"${field.type}\" field type is not supported by SingleLineEditor`);\n }\n\n const constraints = ConstraintsUtils.fromFieldValidations(field.validations, field.type);\n const checkConstraint = ConstraintsUtils.makeChecker(constraints);\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<string>\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}\n isDisabled={props.isDisabled}>\n {({ value, errors, disabled, setValue }) => {\n return (\n <div data-test-id=\"single-line-editor\">\n <TextInput\n className={direction === 'rtl' ? styles.rightToLeft : ''}\n isRequired={field.required}\n isInvalid={errors.length > 0}\n isDisabled={disabled}\n value={value || ''}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n setValue(e.target.value);\n }}\n />\n {props.withCharValidation && (\n <div className={styles.validationRow}>\n <CharCounter value={value || ''} checkConstraint={checkConstraint} />\n <CharValidation constraints={constraints} />\n </div>\n )}\n {props.withCharValidation === false && (\n <div className={styles.validationRow}>\n <CharCounter value={value || ''} checkConstraint={() => true} />\n </div>\n )}\n </div>\n );\n }}\n </FieldConnector>\n );\n}\n\nSingleLineEditor.defaultProps = {\n isInitiallyDisabled: true,\n withCharValidation: true,\n};\n"],"names":["validationRow","css","display","justifyContent","fontSize","tokens","fontSizeM","marginTop","spacingXs","color","gray700","rightToLeft","direction","isSupportedFieldTypes","val","SingleLineEditor","props","field","locales","type","Error","constraints","ConstraintsUtils","fromFieldValidations","validations","checkConstraint","makeChecker","locale","React","FieldConnector","isInitiallyDisabled","isDisabled","value","errors","disabled","setValue","TextInput","className","styles","isRequired","required","isInvalid","length","onChange","e","target","withCharValidation","CharCounter","CharValidation","defaultProps"],"mappings":";;;;;;;;;;;;AAGO,MAAMA,aAAa,gBAAGC,WAAG,CAAC;AAC/BC,EAAAA,OAAO,EAAE,MADsB;AAE/BC,EAAAA,cAAc,EAAE,eAFe;AAG/BC,EAAAA,QAAQ,EAAEC,MAAM,CAACC,SAHc;AAI/BC,EAAAA,SAAS,EAAEF,MAAM,CAACG,SAJa;AAK/BC,EAAAA,KAAK,EAAEJ,MAAM,CAACK;AALiB,CAAD,CAAzB;AAQA,MAAMC,WAAW,gBAAGV,WAAG,CAAC;AAC7BW,EAAAA,SAAS,EAAE;AADkB,CAAD,CAAvB;;AC8BP,SAASC,qBAAT,CAA+BC,GAA/B;AACE,SAAOA,GAAG,KAAK,QAAR,IAAoBA,GAAG,KAAK,MAAnC;AACD;;AAED,SAAgBC,iBAAiBC;AAC/B,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAAqBF,KAA3B;;AAEA,MAAI,CAACH,qBAAqB,CAACI,KAAK,CAACE,IAAP,CAA1B,EAAwC;AACtC,UAAM,IAAIC,KAAJ,KAAcH,KAAK,CAACE,uDAApB,CAAN;AACD;;AAED,QAAME,WAAW,GAAGC,kCAAgB,CAACC,oBAAjB,CAAsCN,KAAK,CAACO,WAA5C,EAAyDP,KAAK,CAACE,IAA/D,CAApB;AACA,QAAMM,eAAe,GAAGH,kCAAgB,CAACI,WAAjB,CAA6BL,WAA7B,CAAxB;AACA,QAAMT,SAAS,GAAGM,OAAO,CAACN,SAAR,CAAkBK,KAAK,CAACU,MAAxB,KAAmC,KAArD;AAEA,SACEC,mBAAA,CAACC,gCAAD;AACEZ,IAAAA,KAAK,EAAEA;AACPa,IAAAA,mBAAmB,EAAEd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,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),i=require("@contentful/
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),i=require("@contentful/f36-components"),a=require("@contentful/field-editor-shared"),n=(e=require("@contentful/f36-tokens"))&&"object"==typeof e&&"default"in e?e.default:e,r=require("emotion");const l=r.css({display:"flex",justifyContent:"space-between",fontSize:n.fontSizeM,marginTop:n.spacingXs,color:n.gray700}),s=r.css({direction:"rtl"});function o(e){const{field:n,locales:r}=e;if("Symbol"!==(o=n.type)&&"Text"!==o)throw new Error(`"${n.type}" field type is not supported by SingleLineEditor`);var o;const d=a.ConstraintsUtils.fromFieldValidations(n.validations,n.type),c=a.ConstraintsUtils.makeChecker(d),u=r.direction[n.locale]||"ltr";return t.createElement(a.FieldConnector,{field:n,isInitiallyDisabled:e.isInitiallyDisabled,isDisabled:e.isDisabled},({value:r,errors:o,disabled:f,setValue:m})=>t.createElement("div",{"data-test-id":"single-line-editor"},t.createElement(i.TextInput,{className:"rtl"===u?s:"",isRequired:n.required,isInvalid:o.length>0,isDisabled:f,value:r||"",onChange:e=>{m(e.target.value)}}),e.withCharValidation&&t.createElement("div",{className:l},t.createElement(a.CharCounter,{value:r||"",checkConstraint:c}),t.createElement(a.CharValidation,{constraints:d})),!1===e.withCharValidation&&t.createElement("div",{className:l},t.createElement(a.CharCounter,{value:r||"",checkConstraint:()=>!0}))))}o.defaultProps={isInitiallyDisabled:!0,withCharValidation:!0},exports.SingleLineEditor=o;
|
|
2
2
|
//# sourceMappingURL=field-editor-single-line.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-single-line.cjs.production.min.js","sources":["../src/styles.ts","../src/SingleLineEditor.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"field-editor-single-line.cjs.production.min.js","sources":["../src/styles.ts","../src/SingleLineEditor.tsx"],"sourcesContent":["import tokens from '@contentful/f36-tokens';\nimport { css } from 'emotion';\n\nexport const validationRow = css({\n display: 'flex',\n justifyContent: 'space-between',\n fontSize: tokens.fontSizeM,\n marginTop: tokens.spacingXs,\n color: tokens.gray700,\n});\n\nexport const rightToLeft = css({\n direction: 'rtl',\n});\n","import * as React from 'react';\n\nimport { TextInput } from '@contentful/f36-components';\nimport {\n FieldAPI,\n FieldConnector,\n ConstraintsUtils,\n CharCounter,\n CharValidation,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\n\nimport * as styles from './styles';\n\n\nexport interface SingleLineEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * is the field manually disabled\n */\n isDisabled?: boolean;\n\n /**\n * whether char validation should be shown or not\n */\n withCharValidation: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\nfunction isSupportedFieldTypes(val: string): val is 'Symbol' | 'Text' {\n return val === 'Symbol' || val === 'Text';\n}\n\nexport function SingleLineEditor(props: SingleLineEditorProps) {\n const { field, locales } = props;\n\n if (!isSupportedFieldTypes(field.type)) {\n throw new Error(`\"${field.type}\" field type is not supported by SingleLineEditor`);\n }\n\n const constraints = ConstraintsUtils.fromFieldValidations(field.validations, field.type);\n const checkConstraint = ConstraintsUtils.makeChecker(constraints);\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<string>\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}\n isDisabled={props.isDisabled}>\n {({ value, errors, disabled, setValue }) => {\n return (\n <div data-test-id=\"single-line-editor\">\n <TextInput\n className={direction === 'rtl' ? styles.rightToLeft : ''}\n isRequired={field.required}\n isInvalid={errors.length > 0}\n isDisabled={disabled}\n value={value || ''}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n setValue(e.target.value);\n }}\n />\n {props.withCharValidation && (\n <div className={styles.validationRow}>\n <CharCounter value={value || ''} checkConstraint={checkConstraint} />\n <CharValidation constraints={constraints} />\n </div>\n )}\n {props.withCharValidation === false && (\n <div className={styles.validationRow}>\n <CharCounter value={value || ''} checkConstraint={() => true} />\n </div>\n )}\n </div>\n );\n }}\n </FieldConnector>\n );\n}\n\nSingleLineEditor.defaultProps = {\n isInitiallyDisabled: true,\n withCharValidation: true,\n};\n"],"names":["validationRow","css","display","justifyContent","fontSize","tokens","fontSizeM","marginTop","spacingXs","color","gray700","rightToLeft","direction","SingleLineEditor","props","field","locales","val","type","Error","constraints","ConstraintsUtils","fromFieldValidations","validations","checkConstraint","makeChecker","locale","React","FieldConnector","isInitiallyDisabled","isDisabled","value","errors","disabled","setValue","TextInput","className","styles","isRequired","required","isInvalid","length","onChange","e","target","withCharValidation","CharCounter","CharValidation","defaultProps"],"mappings":"8RAGO,MAAMA,EAAgBC,MAAI,CAC/BC,QAAS,OACTC,eAAgB,gBAChBC,SAAUC,EAAOC,UACjBC,UAAWF,EAAOG,UAClBC,MAAOJ,EAAOK,UAGHC,EAAcV,MAAI,CAC7BW,UAAW,iBCiCGC,EAAiBC,SACzBC,MAAEA,EAAFC,QAASA,GAAYF,KAJZ,YADcG,EAOFF,EAAMG,OANE,SAARD,QAOnB,IAAIE,UAAUJ,EAAMG,yDAR9B,IAA+BD,QAWvBG,EAAcC,mBAAiBC,qBAAqBP,EAAMQ,YAAaR,EAAMG,MAC7EM,EAAkBH,mBAAiBI,YAAYL,GAC/CR,EAAYI,EAAQJ,UAAUG,EAAMW,SAAW,aAGnDC,gBAACC,kBACCb,MAAOA,EACPc,oBAAqBf,EAAMe,oBAC3BC,WAAYhB,EAAMgB,YACjB,EAAGC,MAAAA,EAAOC,OAAAA,EAAQC,SAAAA,EAAUC,SAAAA,KAEzBP,sCAAkB,sBAChBA,gBAACQ,aACCC,UAAyB,QAAdxB,EAAsByB,EAAqB,GACtDC,WAAYvB,EAAMwB,SAClBC,UAAWR,EAAOS,OAAS,EAC3BX,WAAYG,EACZF,MAAOA,GAAS,GAChBW,SAAWC,IACTT,EAASS,EAAEC,OAAOb,UAGrBjB,EAAM+B,oBACLlB,uBAAKS,UAAWC,GACdV,gBAACmB,eAAYf,MAAOA,GAAS,GAAIP,gBAAiBA,IAClDG,gBAACoB,kBAAe3B,YAAaA,MAGH,IAA7BN,EAAM+B,oBACLlB,uBAAKS,UAAWC,GACdV,gBAACmB,eAAYf,MAAOA,GAAS,GAAIP,gBAAiB,KAAM,OAUxEX,EAAiBmC,aAAe,CAC9BnB,qBAAqB,EACrBgB,oBAAoB"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
|
+
import { TextInput } from '@contentful/f36-components';
|
|
2
3
|
import { ConstraintsUtils, FieldConnector, CharCounter, CharValidation } from '@contentful/field-editor-shared';
|
|
3
|
-
import { css } from 'emotion';
|
|
4
4
|
import tokens from '@contentful/f36-tokens';
|
|
5
|
-
import {
|
|
5
|
+
import { css } from 'emotion';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const validationRow = /*#__PURE__*/css({
|
|
8
8
|
display: 'flex',
|
|
9
9
|
justifyContent: 'space-between',
|
|
10
10
|
fontSize: tokens.fontSizeM,
|
|
11
11
|
marginTop: tokens.spacingXs,
|
|
12
12
|
color: tokens.gray700
|
|
13
13
|
});
|
|
14
|
-
|
|
14
|
+
const rightToLeft = /*#__PURE__*/css({
|
|
15
15
|
direction: 'rtl'
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -20,25 +20,28 @@ function isSupportedFieldTypes(val) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function SingleLineEditor(props) {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const {
|
|
24
|
+
field,
|
|
25
|
+
locales
|
|
26
|
+
} = props;
|
|
25
27
|
|
|
26
28
|
if (!isSupportedFieldTypes(field.type)) {
|
|
27
|
-
throw new Error("
|
|
29
|
+
throw new Error(`"${field.type}" field type is not supported by SingleLineEditor`);
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
const constraints = ConstraintsUtils.fromFieldValidations(field.validations, field.type);
|
|
33
|
+
const checkConstraint = ConstraintsUtils.makeChecker(constraints);
|
|
34
|
+
const direction = locales.direction[field.locale] || 'ltr';
|
|
33
35
|
return createElement(FieldConnector, {
|
|
34
36
|
field: field,
|
|
35
37
|
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
36
38
|
isDisabled: props.isDisabled
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
}, ({
|
|
40
|
+
value,
|
|
41
|
+
errors,
|
|
42
|
+
disabled,
|
|
43
|
+
setValue
|
|
44
|
+
}) => {
|
|
42
45
|
return createElement("div", {
|
|
43
46
|
"data-test-id": "single-line-editor"
|
|
44
47
|
}, createElement(TextInput, {
|
|
@@ -47,7 +50,7 @@ function SingleLineEditor(props) {
|
|
|
47
50
|
isInvalid: errors.length > 0,
|
|
48
51
|
isDisabled: disabled,
|
|
49
52
|
value: value || '',
|
|
50
|
-
onChange:
|
|
53
|
+
onChange: e => {
|
|
51
54
|
setValue(e.target.value);
|
|
52
55
|
}
|
|
53
56
|
}), props.withCharValidation && createElement("div", {
|
|
@@ -61,9 +64,7 @@ function SingleLineEditor(props) {
|
|
|
61
64
|
className: validationRow
|
|
62
65
|
}, createElement(CharCounter, {
|
|
63
66
|
value: value || '',
|
|
64
|
-
checkConstraint:
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
+
checkConstraint: () => true
|
|
67
68
|
})));
|
|
68
69
|
});
|
|
69
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-single-line.esm.js","sources":["../src/styles.ts","../src/SingleLineEditor.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"field-editor-single-line.esm.js","sources":["../src/styles.ts","../src/SingleLineEditor.tsx"],"sourcesContent":["import tokens from '@contentful/f36-tokens';\nimport { css } from 'emotion';\n\nexport const validationRow = css({\n display: 'flex',\n justifyContent: 'space-between',\n fontSize: tokens.fontSizeM,\n marginTop: tokens.spacingXs,\n color: tokens.gray700,\n});\n\nexport const rightToLeft = css({\n direction: 'rtl',\n});\n","import * as React from 'react';\n\nimport { TextInput } from '@contentful/f36-components';\nimport {\n FieldAPI,\n FieldConnector,\n ConstraintsUtils,\n CharCounter,\n CharValidation,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\n\nimport * as styles from './styles';\n\n\nexport interface SingleLineEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * is the field manually disabled\n */\n isDisabled?: boolean;\n\n /**\n * whether char validation should be shown or not\n */\n withCharValidation: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\nfunction isSupportedFieldTypes(val: string): val is 'Symbol' | 'Text' {\n return val === 'Symbol' || val === 'Text';\n}\n\nexport function SingleLineEditor(props: SingleLineEditorProps) {\n const { field, locales } = props;\n\n if (!isSupportedFieldTypes(field.type)) {\n throw new Error(`\"${field.type}\" field type is not supported by SingleLineEditor`);\n }\n\n const constraints = ConstraintsUtils.fromFieldValidations(field.validations, field.type);\n const checkConstraint = ConstraintsUtils.makeChecker(constraints);\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<string>\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}\n isDisabled={props.isDisabled}>\n {({ value, errors, disabled, setValue }) => {\n return (\n <div data-test-id=\"single-line-editor\">\n <TextInput\n className={direction === 'rtl' ? styles.rightToLeft : ''}\n isRequired={field.required}\n isInvalid={errors.length > 0}\n isDisabled={disabled}\n value={value || ''}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n setValue(e.target.value);\n }}\n />\n {props.withCharValidation && (\n <div className={styles.validationRow}>\n <CharCounter value={value || ''} checkConstraint={checkConstraint} />\n <CharValidation constraints={constraints} />\n </div>\n )}\n {props.withCharValidation === false && (\n <div className={styles.validationRow}>\n <CharCounter value={value || ''} checkConstraint={() => true} />\n </div>\n )}\n </div>\n );\n }}\n </FieldConnector>\n );\n}\n\nSingleLineEditor.defaultProps = {\n isInitiallyDisabled: true,\n withCharValidation: true,\n};\n"],"names":["validationRow","css","display","justifyContent","fontSize","tokens","fontSizeM","marginTop","spacingXs","color","gray700","rightToLeft","direction","isSupportedFieldTypes","val","SingleLineEditor","props","field","locales","type","Error","constraints","ConstraintsUtils","fromFieldValidations","validations","checkConstraint","makeChecker","locale","React","FieldConnector","isInitiallyDisabled","isDisabled","value","errors","disabled","setValue","TextInput","className","styles","isRequired","required","isInvalid","length","onChange","e","target","withCharValidation","CharCounter","CharValidation","defaultProps"],"mappings":";;;;;;AAGO,MAAMA,aAAa,gBAAGC,GAAG,CAAC;AAC/BC,EAAAA,OAAO,EAAE,MADsB;AAE/BC,EAAAA,cAAc,EAAE,eAFe;AAG/BC,EAAAA,QAAQ,EAAEC,MAAM,CAACC,SAHc;AAI/BC,EAAAA,SAAS,EAAEF,MAAM,CAACG,SAJa;AAK/BC,EAAAA,KAAK,EAAEJ,MAAM,CAACK;AALiB,CAAD,CAAzB;AAQA,MAAMC,WAAW,gBAAGV,GAAG,CAAC;AAC7BW,EAAAA,SAAS,EAAE;AADkB,CAAD,CAAvB;;AC8BP,SAASC,qBAAT,CAA+BC,GAA/B;AACE,SAAOA,GAAG,KAAK,QAAR,IAAoBA,GAAG,KAAK,MAAnC;AACD;;AAED,SAAgBC,iBAAiBC;AAC/B,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAAqBF,KAA3B;;AAEA,MAAI,CAACH,qBAAqB,CAACI,KAAK,CAACE,IAAP,CAA1B,EAAwC;AACtC,UAAM,IAAIC,KAAJ,KAAcH,KAAK,CAACE,uDAApB,CAAN;AACD;;AAED,QAAME,WAAW,GAAGC,gBAAgB,CAACC,oBAAjB,CAAsCN,KAAK,CAACO,W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WAAD;AAAaf,MAAAA,KAAK,EAAEA,KAAK,IAAI;AAAIP,MAAAA,eAAe,EAAE,MAAM;KAAxD,CADF,CAlBJ,CADF;AAyBD,GA9BH,CADF;AAkCD;AAEDV,gBAAgB,CAACkC,YAAjB,GAAgC;AAC9BnB,EAAAA,mBAAmB,EAAE,IADS;AAE9BgB,EAAAA,kBAAkB,EAAE;AAFU,CAAhC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-single-line",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/field-editor-single-line.esm.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -23,26 +23,16 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@contentful/f36-components": "^4.0.27",
|
|
25
25
|
"@contentful/f36-tokens": "^4.0.0",
|
|
26
|
-
"@contentful/field-editor-shared": "^1.
|
|
26
|
+
"@contentful/field-editor-shared": "^1.2.0",
|
|
27
27
|
"emotion": "^10.0.17",
|
|
28
28
|
"lodash": "^4.17.15",
|
|
29
29
|
"lodash-es": "^4.17.15"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@contentful/field-editor-test-utils": "^1.
|
|
32
|
+
"@contentful/field-editor-test-utils": "^1.3.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": ">=16.8.0"
|
|
36
36
|
},
|
|
37
|
-
"
|
|
38
|
-
"testMatch": [
|
|
39
|
-
"**/?(*.)+(spec|test).[jt]s?(x)"
|
|
40
|
-
],
|
|
41
|
-
"globals": {
|
|
42
|
-
"ts-jest": {
|
|
43
|
-
"diagnostics": false
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"gitHead": "1e4a7d92c48f0e1949f2b48b3c9974da1602fd5c"
|
|
37
|
+
"gitHead": "de7e74e3485dd69c240cfe9c545e6e50e41fb295"
|
|
48
38
|
}
|