@contentful/field-editor-tags 1.1.2 → 1.1.5
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 +14 -0
- package/dist/field-editor-tags.cjs.development.js +26 -5
- package/dist/field-editor-tags.cjs.development.js.map +1 -1
- package/dist/field-editor-tags.cjs.production.min.js +1 -1
- package/dist/field-editor-tags.cjs.production.min.js.map +1 -1
- package/dist/field-editor-tags.esm.js +27 -6
- package/dist/field-editor-tags.esm.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
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.1.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-tags@1.1.4...@contentful/field-editor-tags@1.1.5) (2022-07-11)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @contentful/field-editor-tags
|
|
9
|
+
|
|
10
|
+
## [1.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-tags@1.1.3...@contentful/field-editor-tags@1.1.4) (2022-06-22)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @contentful/field-editor-tags
|
|
13
|
+
|
|
14
|
+
## [1.1.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-tags@1.1.2...@contentful/field-editor-tags@1.1.3) (2022-05-04)
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
- reflect disabled state on fields ([#1125](https://github.com/contentful/field-editors/issues/1125)) ([01502b9](https://github.com/contentful/field-editors/commit/01502b9d785c5f782b0e5de782d092c439cb690f))
|
|
19
|
+
|
|
6
20
|
## [1.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-tags@1.1.1...@contentful/field-editor-tags@1.1.2) (2022-02-15)
|
|
7
21
|
|
|
8
22
|
### Bug Fixes
|
|
@@ -45,6 +45,14 @@ var styles = {
|
|
|
45
45
|
marginRight: tokens.spacingS,
|
|
46
46
|
marginBottom: tokens.spacingS
|
|
47
47
|
}),
|
|
48
|
+
pillDisabled: /*#__PURE__*/emotion.css({
|
|
49
|
+
cursor: 'not-allowed !important',
|
|
50
|
+
button: {
|
|
51
|
+
cursor: 'not-allowed !important',
|
|
52
|
+
// instead of changing the @contentful/f36-components package
|
|
53
|
+
pointerEvents: 'none'
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
48
56
|
handle: /*#__PURE__*/emotion.css({
|
|
49
57
|
lineHeight: '1.5rem',
|
|
50
58
|
padding: '0.375rem 0.625rem',
|
|
@@ -57,25 +65,31 @@ var styles = {
|
|
|
57
65
|
}
|
|
58
66
|
})
|
|
59
67
|
};
|
|
60
|
-
var SortablePillHandle = /*#__PURE__*/reactSortableHoc.SortableHandle(function () {
|
|
68
|
+
var SortablePillHandle = /*#__PURE__*/reactSortableHoc.SortableHandle(function (props) {
|
|
69
|
+
var _cx;
|
|
70
|
+
|
|
61
71
|
return React__default.createElement("div", {
|
|
62
|
-
className: styles.handle
|
|
72
|
+
className: emotion.cx(styles.handle, (_cx = {}, _cx[styles.pillDisabled] = props.isDisabled, _cx))
|
|
63
73
|
}, React__default.createElement(f36Icons.DragIcon, {
|
|
64
74
|
variant: "muted"
|
|
65
75
|
}));
|
|
66
76
|
});
|
|
67
77
|
var SortablePill = /*#__PURE__*/reactSortableHoc.SortableElement(function (props) {
|
|
78
|
+
var _cx2;
|
|
79
|
+
|
|
68
80
|
return React__default.createElement(f36Components.Pill, {
|
|
69
81
|
testId: "tag-editor-pill",
|
|
70
|
-
className: styles.pill,
|
|
82
|
+
className: emotion.cx(styles.pill, (_cx2 = {}, _cx2[styles.pillDisabled] = props.isSortablePillDisabled, _cx2)),
|
|
71
83
|
label: props.label,
|
|
72
84
|
onClose: function onClose() {
|
|
73
|
-
if (!props.
|
|
85
|
+
if (!props.isSortablePillDisabled) {
|
|
74
86
|
props.onRemove(props.index);
|
|
75
87
|
}
|
|
76
88
|
},
|
|
77
89
|
onDrag: noop,
|
|
78
|
-
dragHandleComponent: React__default.createElement(SortablePillHandle,
|
|
90
|
+
dragHandleComponent: React__default.createElement(SortablePillHandle, {
|
|
91
|
+
isDisabled: props.isSortablePillDisabled
|
|
92
|
+
})
|
|
79
93
|
});
|
|
80
94
|
});
|
|
81
95
|
var SortableList = /*#__PURE__*/reactSortableHoc.SortableContainer(function (props) {
|
|
@@ -142,6 +156,13 @@ function TagsEditor(props) {
|
|
|
142
156
|
index: index,
|
|
143
157
|
key: item + index,
|
|
144
158
|
disabled: isDisabled,
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* `isSortablePillDisabled` is needed as SortableElement
|
|
162
|
+
* from react-sortable-hoc doesn't pass down the disabled prop.
|
|
163
|
+
* See: https://github.com/clauderic/react-sortable-hoc/issues/612
|
|
164
|
+
*/
|
|
165
|
+
isSortablePillDisabled: isDisabled,
|
|
145
166
|
onRemove: function onRemove() {
|
|
146
167
|
removeItem(index);
|
|
147
168
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-tags.cjs.development.js","sources":["../src/TagsEditorConstraints.tsx","../src/TagsEditor.tsx","../src/TagsEditorContainer.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport { css } from 'emotion';\nimport { Constraint, ConstraintsType } from './types';\n\nimport { Text } from '@contentful/f36-components';\n\ninterface TagEditorConstraintsProps {\n constraintsType: ConstraintsType;\n constraints: Constraint;\n}\n\nexport function TagsEditorConstraints(props: TagEditorConstraintsProps) {\n const { constraintsType, constraints } = props;\n return (\n <Text\n as=\"p\"\n fontColor=\"gray600\"\n marginBottom=\"none\"\n marginTop=\"spacingS\"\n className={css({\n fontStyle: 'italic',\n })}\n testId=\"tag-editor-constraints\">\n {constraintsType === 'min' && (\n <span>\n Requires at least {constraints.min} {constraints.min === 1 ? 'tag' : 'tags'}\n </span>\n )}\n {constraintsType === 'max' && (\n <span>\n Requires no more than {constraints.max} {constraints.max === 1 ? 'tag' : 'tags'}\n </span>\n )}\n {constraintsType === 'min-max' && constraints.max !== constraints.min && (\n <span>\n Requires between {constraints.min} and {constraints.max} tags\n </span>\n )}\n {constraintsType === 'min-max' && constraints.max === constraints.min && (\n <span>\n Requires exactly {constraints.max} {constraints.max === 1 ? 'tag' : 'tags'}\n </span>\n )}\n </Text>\n );\n}\n","import noop from 'lodash/noop';\nimport React, { useState, useCallback } from 'react';\nimport { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\nimport { TagsEditorConstraints } from './TagsEditorConstraints';\nimport { ConstraintsType, Constraint } from './types';\nimport { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';\nimport arrayMove from 'array-move';\n\nimport { Pill, TextInput } from '@contentful/f36-components';\n\nimport { DragIcon } from '@contentful/f36-icons';\n\nexport interface TagsEditorProps {\n items: string[];\n isDisabled: boolean;\n hasError: boolean;\n constraintsType?: ConstraintsType;\n constraints?: Constraint;\n onUpdate: (items: string[]) => void;\n}\n\nconst styles = {\n dropContainer: css({\n whiteSpace: 'nowrap',\n display: 'flex',\n flexWrap: 'wrap',\n }),\n input: css({\n marginTop: tokens.spacingS,\n marginBottom: tokens.spacingM,\n }),\n pill: css({\n marginRight: tokens.spacingS,\n marginBottom: tokens.spacingS,\n }),\n handle: css({\n lineHeight: '1.5rem',\n padding: '0.375rem 0.625rem',\n paddingRight: 0,\n cursor: 'grab',\n userSelect: 'none',\n svg: {\n fill: tokens.gray500,\n verticalAlign: 'middle',\n },\n }),\n};\n\nconst SortablePillHandle = SortableHandle(() => (\n <div className={styles.handle}>\n <DragIcon variant=\"muted\" />\n </div>\n));\n\ninterface SortablePillProps {\n label: string;\n onRemove: Function;\n disabled: boolean;\n index: number;\n}\n\nconst SortablePill = SortableElement((props: SortablePillProps) => (\n <Pill\n testId=\"tag-editor-pill\"\n className={styles.pill}\n label={props.label}\n onClose={() => {\n if (!props.disabled) {\n props.onRemove(props.index);\n }\n }}\n onDrag={noop}\n dragHandleComponent={<SortablePillHandle />}\n />\n));\n\ninterface SortableListProps {\n children: React.ReactNode;\n}\n\nconst SortableList = SortableContainer((props: SortableListProps) => (\n <div className={styles.dropContainer}>{props.children}</div>\n));\n\nexport function TagsEditor(props: TagsEditorProps) {\n const [pendingValue, setPendingValue] = useState('');\n\n const { isDisabled, items, constraints, constraintsType, hasError } = props;\n\n const removeItem = useCallback(\n (index) => {\n const newItems = props.items.filter((_, filterIndex) => index !== filterIndex);\n props.onUpdate(newItems);\n },\n [props]\n );\n\n const swapItems = useCallback(\n ({ oldIndex, newIndex }) => {\n const newItems = arrayMove(props.items, oldIndex, newIndex);\n props.onUpdate(newItems);\n },\n [props]\n );\n\n return (\n <div data-test-id=\"tag-editor-container\">\n <TextInput\n testId=\"tag-editor-input\"\n className={styles.input}\n isDisabled={isDisabled}\n isInvalid={hasError}\n type=\"text\"\n value={pendingValue}\n placeholder=\"Type the value and hit enter\"\n onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {\n if (pendingValue && e.keyCode === 13) {\n props.onUpdate([...props.items, pendingValue]);\n setPendingValue('');\n }\n }}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n setPendingValue(e.target.value);\n }}\n />\n <SortableList\n useDragHandle\n axis=\"xy\"\n distance={10}\n onSortEnd={({ oldIndex, newIndex }) => {\n swapItems({ oldIndex, newIndex });\n }}>\n {items.map((item, index) => {\n return (\n <SortablePill\n label={item}\n index={index}\n key={item + index}\n disabled={isDisabled}\n onRemove={() => {\n removeItem(index);\n }}\n />\n );\n })}\n </SortableList>\n {constraints && constraintsType && (\n <TagsEditorConstraints constraints={constraints} constraintsType={constraintsType} />\n )}\n </div>\n );\n}\n","import * as React from 'react';\nimport isNumber from 'lodash/isNumber';\nimport { FieldAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport { TagsEditor } from './TagsEditor';\nimport { ConstraintsType, Constraint } from './types';\n\nexport interface TagsEditorContainerProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n}\n\ntype TagEditorValue = string[];\n\nfunction isEmptyTagsValue(value: TagEditorValue | null) {\n return value === null || value.length === 0;\n}\n\nfunction getConstraintsType(sizeConstraints?: Constraint): ConstraintsType | undefined {\n if (!sizeConstraints) {\n return undefined;\n }\n if (isNumber(sizeConstraints.min) && isNumber(sizeConstraints.max)) {\n return 'min-max';\n } else if (isNumber(sizeConstraints.min)) {\n return 'min';\n } else if (isNumber(sizeConstraints.max)) {\n return 'max';\n } else {\n return undefined;\n }\n}\n\nexport function TagsEditorContainer(props: TagsEditorContainerProps) {\n const field = props.field;\n\n const validations = field.validations || [];\n\n const sizeValidations = (validations as { size?: Constraint }[])\n .filter((validation) => validation.size)\n .map((validation) => validation.size);\n\n const constraints = sizeValidations.length > 0 ? sizeValidations[0] : {};\n\n const constraintsType = getConstraintsType(constraints);\n\n return (\n <FieldConnector<TagEditorValue>\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}\n isEmptyValue={isEmptyTagsValue}\n throttle={0}>\n {({ disabled, value, errors, setValue }) => {\n const items = value || [];\n return (\n <TagsEditor\n constraints={constraints}\n constraintsType={constraintsType}\n isDisabled={disabled}\n hasError={errors.length > 0}\n items={items}\n onUpdate={(items) => {\n setValue(items);\n }}\n />\n );\n }}\n </FieldConnector>\n );\n}\n\nTagsEditorContainer.defaultProps = {\n isInitiallyDisabled: true,\n};\n","import { TagsEditorContainer } from './TagsEditorContainer';\n\nexport const TagsEditor = TagsEditorContainer;\n"],"names":["TagsEditorConstraints","props","constraintsType","constraints","React","Text","as","fontColor","marginBottom","marginTop","className","css","fontStyle","testId","min","max","styles","dropContainer","whiteSpace","display","flexWrap","input","tokens","spacingS","spacingM","pill","marginRight","handle","lineHeight","padding","paddingRight","cursor","userSelect","svg","fill","gray500","verticalAlign","SortablePillHandle","SortableHandle","DragIcon","variant","SortablePill","SortableElement","Pill","label","onClose","disabled","onRemove","index","onDrag","noop","dragHandleComponent","SortableList","SortableContainer","children","TagsEditor","useState","pendingValue","setPendingValue","isDisabled","items","hasError","removeItem","useCallback","newItems","filter","_","filterIndex","onUpdate","swapItems","oldIndex","newIndex","arrayMove","TextInput","isInvalid","type","value","placeholder","onKeyDown","e","keyCode","onChange","target","useDragHandle","axis","distance","onSortEnd","map","item","key","isEmptyTagsValue","length","getConstraintsType","sizeConstraints","undefined","isNumber","TagsEditorContainer","field","validations","sizeValidations","validation","size","FieldConnector","isInitiallyDisabled","isEmptyValue","throttle","errors","setValue","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;SAWgBA,sBAAsBC;AACpC,MAAQC,eAAR,GAAyCD,KAAzC,CAAQC,eAAR;AAAA,MAAyBC,WAAzB,GAAyCF,KAAzC,CAAyBE,WAAzB;AACA,SACEC,4BAAA,CAACC,kBAAD;AACEC,IAAAA,EAAE,EAAC;AACHC,IAAAA,SAAS,EAAC;AACVC,IAAAA,YAAY,EAAC;AACbC,IAAAA,SAAS,EAAC;AACVC,IAAAA,SAAS,EAAEC,WAAG,CAAC;AACbC,MAAAA,SAAS,EAAE;AADE,KAAD;AAGdC,IAAAA,MAAM,EAAC;GART,EASGX,eAAe,KAAK,KAApB,IACCE,4BAAA,OAAA,MAAA,sBAAA,EACqBD,WAAW,CAACW,GADjC,KAAA,EACuCX,WAAW,CAACW,GAAZ,KAAoB,CAApB,GAAwB,KAAxB,GAAgC,MADvE,CAVJ,EAcGZ,eAAe,KAAK,KAApB,IACCE,4BAAA,OAAA,MAAA,0BAAA,EACyBD,WAAW,CAACY,GADrC,KAAA,EAC2CZ,WAAW,CAACY,GAAZ,KAAoB,CAApB,GAAwB,KAAxB,GAAgC,MAD3E,CAfJ,EAmBGb,eAAe,KAAK,SAApB,IAAiCC,WAAW,CAACY,GAAZ,KAAoBZ,WAAW,CAACW,GAAjE,IACCV,4BAAA,OAAA,MAAA,qBAAA,EACoBD,WAAW,CAACW,GADhC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AzC;AAEA,MAAMC,eAAe,GAAID,WAAuC,CAC7DjC,MADsB,CACf,UAACmC,UAAD;AAAA,WAAgBA,UAAU,CAACC,IAA3B;AAAA,GADe,EAEtBd,GAFsB,CAElB,UAACa,UAAD;AAAA,WAAgBA,UAAU,CAACC,IAA3B;AAAA,GAFkB,CAAzB;AAIA,MAAMlG,WAAW,GAAGgG,eAAe,CAACR,MAAhB,GAAyB,CAAzB,GAA6BQ,eAAe,CAAC,CAAD,CAA5C,GAAkD,EAAtE;AAEA,MAAMjG,eAAe,GAAG0F,kBAAkB,CAACzF,WAAD,CAA1C;AAEA,SACEC,mBAAA,CAACkG,gCAAD;AACEL,IAAAA,KAAK,EAAEA;AACPM,IAAAA,mBAAmB,EAAEtG,KAAK,CAACsG;AAC3BC,IAAAA,YAAY,EAAEd;AACde,IAAAA,QAAQ,EAAE;GAJZ,EAKG;QAAG3D,gBAAAA;QAAU8B,aAAAA;QAAO8B,cAAAA;QAAQC,gBAAAA;AAC3B,QAAM/C,KAAK,GAAGgB,KAAK,IAAI,EAAvB;AACA,WACExE,mBAAA,CAACmD,UAAD;AACEpD,MAAAA,WAAW,EAAEA;AACbD,MAAAA,eAAe,EAAEA;AACjByD,MAAAA,UAAU,EAAEb;AACZe,MAAAA,QAAQ,EAAE6C,MAAM,CAACf,MAAP,GAAgB;AAC1B/B,MAAAA,KAAK,EAAEA;AACPQ,MAAAA,QAAQ,EAAE,kBAACR,KAAD;AACR+C,QAAAA,QAAQ,CAAC/C,KAAD,CAAR;AACD;KARH,CADF;AAYD,GAnBH,CADF;AAuBD;AAEDoC,mBAAmB,CAACY,YAApB,GAAmC;AACjCL,EAAAA,mBAAmB,EAAE;AADY,CAAnC;;IC1EahD,YAAU,GAAGyC,mBAAnB;;;;"}
|
|
1
|
+
{"version":3,"file":"field-editor-tags.cjs.development.js","sources":["../src/TagsEditorConstraints.tsx","../src/TagsEditor.tsx","../src/TagsEditorContainer.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport { css } from 'emotion';\nimport { Constraint, ConstraintsType } from './types';\n\nimport { Text } from '@contentful/f36-components';\n\ninterface TagEditorConstraintsProps {\n constraintsType: ConstraintsType;\n constraints: Constraint;\n}\n\nexport function TagsEditorConstraints(props: TagEditorConstraintsProps) {\n const { constraintsType, constraints } = props;\n return (\n <Text\n as=\"p\"\n fontColor=\"gray600\"\n marginBottom=\"none\"\n marginTop=\"spacingS\"\n className={css({\n fontStyle: 'italic',\n })}\n testId=\"tag-editor-constraints\">\n {constraintsType === 'min' && (\n <span>\n Requires at least {constraints.min} {constraints.min === 1 ? 'tag' : 'tags'}\n </span>\n )}\n {constraintsType === 'max' && (\n <span>\n Requires no more than {constraints.max} {constraints.max === 1 ? 'tag' : 'tags'}\n </span>\n )}\n {constraintsType === 'min-max' && constraints.max !== constraints.min && (\n <span>\n Requires between {constraints.min} and {constraints.max} tags\n </span>\n )}\n {constraintsType === 'min-max' && constraints.max === constraints.min && (\n <span>\n Requires exactly {constraints.max} {constraints.max === 1 ? 'tag' : 'tags'}\n </span>\n )}\n </Text>\n );\n}\n","import noop from 'lodash/noop';\nimport React, { useState, useCallback } from 'react';\nimport { css, cx } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\nimport { TagsEditorConstraints } from './TagsEditorConstraints';\nimport { ConstraintsType, Constraint } from './types';\nimport { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';\nimport arrayMove from 'array-move';\n\nimport { Pill, TextInput } from '@contentful/f36-components';\n\nimport { DragIcon } from '@contentful/f36-icons';\n\nexport interface TagsEditorProps {\n items: string[];\n isDisabled: boolean;\n hasError: boolean;\n constraintsType?: ConstraintsType;\n constraints?: Constraint;\n onUpdate: (items: string[]) => void;\n}\n\nconst styles = {\n dropContainer: css({\n whiteSpace: 'nowrap',\n display: 'flex',\n flexWrap: 'wrap',\n }),\n input: css({\n marginTop: tokens.spacingS,\n marginBottom: tokens.spacingM,\n }),\n pill: css({\n marginRight: tokens.spacingS,\n marginBottom: tokens.spacingS,\n }),\n pillDisabled: css({\n cursor: 'not-allowed !important',\n button: {\n cursor: 'not-allowed !important',\n // instead of changing the @contentful/f36-components package\n pointerEvents: 'none',\n },\n }),\n handle: css({\n lineHeight: '1.5rem',\n padding: '0.375rem 0.625rem',\n paddingRight: 0,\n cursor: 'grab',\n userSelect: 'none',\n svg: {\n fill: tokens.gray500,\n verticalAlign: 'middle',\n },\n }),\n};\n\nconst SortablePillHandle = SortableHandle((props: { isDisabled: boolean }) => (\n <div className={cx(styles.handle, { [styles.pillDisabled]: props.isDisabled })}>\n <DragIcon variant=\"muted\" />\n </div>\n));\n\ninterface SortablePillProps {\n label: string;\n onRemove: Function;\n isSortablePillDisabled: boolean;\n index: number;\n}\n\nconst SortablePill = SortableElement((props: SortablePillProps) => (\n <Pill\n testId=\"tag-editor-pill\"\n className={cx(styles.pill, { [styles.pillDisabled]: props.isSortablePillDisabled })}\n label={props.label}\n onClose={() => {\n if (!props.isSortablePillDisabled) {\n props.onRemove(props.index);\n }\n }}\n onDrag={noop}\n dragHandleComponent={<SortablePillHandle isDisabled={props.isSortablePillDisabled} />}\n />\n));\n\ninterface SortableListProps {\n children: React.ReactNode;\n}\n\nconst SortableList = SortableContainer((props: SortableListProps) => (\n <div className={styles.dropContainer}>{props.children}</div>\n));\n\nexport function TagsEditor(props: TagsEditorProps) {\n const [pendingValue, setPendingValue] = useState('');\n\n const { isDisabled, items, constraints, constraintsType, hasError } = props;\n\n const removeItem = useCallback(\n (index) => {\n const newItems = props.items.filter((_, filterIndex) => index !== filterIndex);\n props.onUpdate(newItems);\n },\n [props]\n );\n\n const swapItems = useCallback(\n ({ oldIndex, newIndex }) => {\n const newItems = arrayMove(props.items, oldIndex, newIndex);\n props.onUpdate(newItems);\n },\n [props]\n );\n\n return (\n <div data-test-id=\"tag-editor-container\">\n <TextInput\n testId=\"tag-editor-input\"\n className={styles.input}\n isDisabled={isDisabled}\n isInvalid={hasError}\n type=\"text\"\n value={pendingValue}\n placeholder=\"Type the value and hit enter\"\n onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {\n if (pendingValue && e.keyCode === 13) {\n props.onUpdate([...props.items, pendingValue]);\n setPendingValue('');\n }\n }}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n setPendingValue(e.target.value);\n }}\n />\n <SortableList\n useDragHandle\n axis=\"xy\"\n distance={10}\n onSortEnd={({ oldIndex, newIndex }) => {\n swapItems({ oldIndex, newIndex });\n }}>\n {items.map((item, index) => {\n return (\n <SortablePill\n label={item}\n index={index}\n key={item + index}\n disabled={isDisabled}\n /**\n * `isSortablePillDisabled` is needed as SortableElement\n * from react-sortable-hoc doesn't pass down the disabled prop.\n * See: https://github.com/clauderic/react-sortable-hoc/issues/612\n */\n isSortablePillDisabled={isDisabled}\n onRemove={() => {\n removeItem(index);\n }}\n />\n );\n })}\n </SortableList>\n {constraints && constraintsType && (\n <TagsEditorConstraints constraints={constraints} constraintsType={constraintsType} />\n )}\n </div>\n );\n}\n","import * as React from 'react';\nimport isNumber from 'lodash/isNumber';\nimport { FieldAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport { TagsEditor } from './TagsEditor';\nimport { ConstraintsType, Constraint } from './types';\n\nexport interface TagsEditorContainerProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n}\n\ntype TagEditorValue = string[];\n\nfunction isEmptyTagsValue(value: TagEditorValue | null) {\n return value === null || value.length === 0;\n}\n\nfunction getConstraintsType(sizeConstraints?: Constraint): ConstraintsType | undefined {\n if (!sizeConstraints) {\n return undefined;\n }\n if (isNumber(sizeConstraints.min) && isNumber(sizeConstraints.max)) {\n return 'min-max';\n } else if (isNumber(sizeConstraints.min)) {\n return 'min';\n } else if (isNumber(sizeConstraints.max)) {\n return 'max';\n } else {\n return undefined;\n }\n}\n\nexport function TagsEditorContainer(props: TagsEditorContainerProps) {\n const field = props.field;\n\n const validations = field.validations || [];\n\n const sizeValidations = (validations as { size?: Constraint }[])\n .filter((validation) => validation.size)\n .map((validation) => validation.size);\n\n const constraints = sizeValidations.length > 0 ? sizeValidations[0] : {};\n\n const constraintsType = getConstraintsType(constraints);\n\n return (\n <FieldConnector<TagEditorValue>\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}\n isEmptyValue={isEmptyTagsValue}\n throttle={0}>\n {({ disabled, value, errors, setValue }) => {\n const items = value || [];\n return (\n <TagsEditor\n constraints={constraints}\n constraintsType={constraintsType}\n isDisabled={disabled}\n hasError={errors.length > 0}\n items={items}\n onUpdate={(items) => {\n setValue(items);\n }}\n />\n );\n }}\n </FieldConnector>\n );\n}\n\nTagsEditorContainer.defaultProps = {\n isInitiallyDisabled: true,\n};\n","import { TagsEditorContainer } from './TagsEditorContainer';\n\nexport const TagsEditor = TagsEditorContainer;\n"],"names":["TagsEditorConstraints","props","constraintsType","constraints","React","Text","as","fontColor","marginBottom","marginTop","className","css","fontStyle","testId","min","max","styles","dropContainer","whiteSpace","display","flexWrap","input","tokens","spacingS","spacingM","pill","marginRight","pillDisabled","cursor","button","pointerEvents","handle","lineHeight","padding","paddingRight","userSelect","svg","fill","gray500","verticalAlign","SortablePillHandle","SortableHandle","cx","isDisabled","DragIcon","variant","SortablePill","SortableElement","Pill","isSortablePillDisabled","label","onClose","onRemove","index","onDrag","noop","dragHandleComponent","SortableList","SortableContainer","children","TagsEditor","useState","pendingValue","setPendingValue","items","hasError","removeItem","useCallback","newItems","filter","_","filterIndex","onUpdate","swapItems","oldIndex","newIndex","arrayMove","TextInput","isInvalid","type","value","placeholder","onKeyDown","e","keyCode","onChange","target","useDragHandle","axis","distance","onSortEnd","map","item","key","disabled","isEmptyTagsValue","length","getConstraintsType","sizeConstraints","undefined","isNumber","TagsEditorContainer","field","validations","sizeValidations","validation","size","FieldConnector","isInitiallyDisabled","isEmptyValue","throttle","errors","setValue","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;SAWgBA,sBAAsBC;AACpC,MAAQC,eAAR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ule",{value:!0});var
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),n=e(t),a=e(require("lodash/isNumber")),i=require("@contentful/field-editor-shared"),r=e(require("lodash/noop")),l=require("emotion"),o=e(require("@contentful/f36-tokens")),s=require("@contentful/f36-components"),c=require("react-sortable-hoc"),d=e(require("array-move")),u=require("@contentful/f36-icons");function m(e){var t=e.constraintsType,a=e.constraints;return n.createElement(s.Text,{as:"p",fontColor:"gray600",marginBottom:"none",marginTop:"spacingS",className:l.css({fontStyle:"italic"}),testId:"tag-editor-constraints"},"min"===t&&n.createElement("span",null,"Requires at least ",a.min," ",1===a.min?"tag":"tags"),"max"===t&&n.createElement("span",null,"Requires no more than ",a.max," ",1===a.max?"tag":"tags"),"min-max"===t&&a.max!==a.min&&n.createElement("span",null,"Requires between ",a.min," and ",a.max," tags"),"min-max"===t&&a.max===a.min&&n.createElement("span",null,"Requires exactly ",a.max," ",1===a.max?"tag":"tags"))}var p={dropContainer:l.css({whiteSpace:"nowrap",display:"flex",flexWrap:"wrap"}),input:l.css({marginTop:o.spacingS,marginBottom:o.spacingM}),pill:l.css({marginRight:o.spacingS,marginBottom:o.spacingS}),pillDisabled:l.css({cursor:"not-allowed !important",button:{cursor:"not-allowed !important",pointerEvents:"none"}}),handle:l.css({lineHeight:"1.5rem",padding:"0.375rem 0.625rem",paddingRight:0,cursor:"grab",userSelect:"none",svg:{fill:o.gray500,verticalAlign:"middle"}})},f=c.SortableHandle((function(e){var t;return n.createElement("div",{className:l.cx(p.handle,(t={},t[p.pillDisabled]=e.isDisabled,t))},n.createElement(u.DragIcon,{variant:"muted"}))})),g=c.SortableElement((function(e){var t;return n.createElement(s.Pill,{testId:"tag-editor-pill",className:l.cx(p.pill,(t={},t[p.pillDisabled]=e.isSortablePillDisabled,t)),label:e.label,onClose:function(){e.isSortablePillDisabled||e.onRemove(e.index)},onDrag:r,dragHandleComponent:n.createElement(f,{isDisabled:e.isSortablePillDisabled})})})),b=c.SortableContainer((function(e){return n.createElement("div",{className:p.dropContainer},e.children)}));function x(e){var a=t.useState(""),i=a[0],r=a[1],l=e.isDisabled,o=e.items,c=e.constraints,u=e.constraintsType,f=e.hasError,x=t.useCallback((function(t){var n=e.items.filter((function(e,n){return t!==n}));e.onUpdate(n)}),[e]),v=t.useCallback((function(t){var n=d(e.items,t.oldIndex,t.newIndex);e.onUpdate(n)}),[e]);return n.createElement("div",{"data-test-id":"tag-editor-container"},n.createElement(s.TextInput,{testId:"tag-editor-input",className:p.input,isDisabled:l,isInvalid:f,type:"text",value:i,placeholder:"Type the value and hit enter",onKeyDown:function(t){i&&13===t.keyCode&&(e.onUpdate([].concat(e.items,[i])),r(""))},onChange:function(e){r(e.target.value)}}),n.createElement(b,{useDragHandle:!0,axis:"xy",distance:10,onSortEnd:function(e){v({oldIndex:e.oldIndex,newIndex:e.newIndex})}},o.map((function(e,t){return n.createElement(g,{label:e,index:t,key:e+t,disabled:l,isSortablePillDisabled:l,onRemove:function(){x(t)}})}))),c&&u&&n.createElement(m,{constraints:c,constraintsType:u}))}function v(e){return null===e||0===e.length}function E(e){var n=e.field,r=(n.validations||[]).filter((function(e){return e.size})).map((function(e){return e.size})),l=r.length>0?r[0]:{},o=function(e){if(e)return a(e.min)&&a(e.max)?"min-max":a(e.min)?"min":a(e.max)?"max":void 0}(l);return t.createElement(i.FieldConnector,{field:n,isInitiallyDisabled:e.isInitiallyDisabled,isEmptyValue:v,throttle:0},(function(e){var n=e.setValue;return t.createElement(x,{constraints:l,constraintsType:o,isDisabled:e.disabled,hasError:e.errors.length>0,items:e.value||[],onUpdate:function(e){n(e)}})}))}E.defaultProps={isInitiallyDisabled:!0},exports.TagsEditor=E;
|
|
2
2
|
//# sourceMappingURL=field-editor-tags.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-tags.cjs.production.min.js","sources":["../src/TagsEditorConstraints.tsx","../src/TagsEditor.tsx","../src/TagsEditorContainer.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport { css } from 'emotion';\nimport { Constraint, ConstraintsType } from './types';\n\nimport { Text } from '@contentful/f36-components';\n\ninterface TagEditorConstraintsProps {\n constraintsType: ConstraintsType;\n constraints: Constraint;\n}\n\nexport function TagsEditorConstraints(props: TagEditorConstraintsProps) {\n const { constraintsType, constraints } = props;\n return (\n <Text\n as=\"p\"\n fontColor=\"gray600\"\n marginBottom=\"none\"\n marginTop=\"spacingS\"\n className={css({\n fontStyle: 'italic',\n })}\n testId=\"tag-editor-constraints\">\n {constraintsType === 'min' && (\n <span>\n Requires at least {constraints.min} {constraints.min === 1 ? 'tag' : 'tags'}\n </span>\n )}\n {constraintsType === 'max' && (\n <span>\n Requires no more than {constraints.max} {constraints.max === 1 ? 'tag' : 'tags'}\n </span>\n )}\n {constraintsType === 'min-max' && constraints.max !== constraints.min && (\n <span>\n Requires between {constraints.min} and {constraints.max} tags\n </span>\n )}\n {constraintsType === 'min-max' && constraints.max === constraints.min && (\n <span>\n Requires exactly {constraints.max} {constraints.max === 1 ? 'tag' : 'tags'}\n </span>\n )}\n </Text>\n );\n}\n","import noop from 'lodash/noop';\nimport React, { useState, useCallback } from 'react';\nimport { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\nimport { TagsEditorConstraints } from './TagsEditorConstraints';\nimport { ConstraintsType, Constraint } from './types';\nimport { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';\nimport arrayMove from 'array-move';\n\nimport { Pill, TextInput } from '@contentful/f36-components';\n\nimport { DragIcon } from '@contentful/f36-icons';\n\nexport interface TagsEditorProps {\n items: string[];\n isDisabled: boolean;\n hasError: boolean;\n constraintsType?: ConstraintsType;\n constraints?: Constraint;\n onUpdate: (items: string[]) => void;\n}\n\nconst styles = {\n dropContainer: css({\n whiteSpace: 'nowrap',\n display: 'flex',\n flexWrap: 'wrap',\n }),\n input: css({\n marginTop: tokens.spacingS,\n marginBottom: tokens.spacingM,\n }),\n pill: css({\n marginRight: tokens.spacingS,\n marginBottom: tokens.spacingS,\n }),\n handle: css({\n lineHeight: '1.5rem',\n padding: '0.375rem 0.625rem',\n paddingRight: 0,\n cursor: 'grab',\n userSelect: 'none',\n svg: {\n fill: tokens.gray500,\n verticalAlign: 'middle',\n },\n }),\n};\n\nconst SortablePillHandle = SortableHandle(() => (\n <div className={styles.handle}>\n <DragIcon variant=\"muted\" />\n </div>\n));\n\ninterface SortablePillProps {\n label: string;\n onRemove: Function;\n disabled: boolean;\n index: number;\n}\n\nconst SortablePill = SortableElement((props: SortablePillProps) => (\n <Pill\n testId=\"tag-editor-pill\"\n className={styles.pill}\n label={props.label}\n onClose={() => {\n if (!props.disabled) {\n props.onRemove(props.index);\n }\n }}\n onDrag={noop}\n dragHandleComponent={<SortablePillHandle />}\n />\n));\n\ninterface SortableListProps {\n children: React.ReactNode;\n}\n\nconst SortableList = SortableContainer((props: SortableListProps) => (\n <div className={styles.dropContainer}>{props.children}</div>\n));\n\nexport function TagsEditor(props: TagsEditorProps) {\n const [pendingValue, setPendingValue] = useState('');\n\n const { isDisabled, items, constraints, constraintsType, hasError } = props;\n\n const removeItem = useCallback(\n (index) => {\n const newItems = props.items.filter((_, filterIndex) => index !== filterIndex);\n props.onUpdate(newItems);\n },\n [props]\n );\n\n const swapItems = useCallback(\n ({ oldIndex, newIndex }) => {\n const newItems = arrayMove(props.items, oldIndex, newIndex);\n props.onUpdate(newItems);\n },\n [props]\n );\n\n return (\n <div data-test-id=\"tag-editor-container\">\n <TextInput\n testId=\"tag-editor-input\"\n className={styles.input}\n isDisabled={isDisabled}\n isInvalid={hasError}\n type=\"text\"\n value={pendingValue}\n placeholder=\"Type the value and hit enter\"\n onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {\n if (pendingValue && e.keyCode === 13) {\n props.onUpdate([...props.items, pendingValue]);\n setPendingValue('');\n }\n }}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n setPendingValue(e.target.value);\n }}\n />\n <SortableList\n useDragHandle\n axis=\"xy\"\n distance={10}\n onSortEnd={({ oldIndex, newIndex }) => {\n swapItems({ oldIndex, newIndex });\n }}>\n {items.map((item, index) => {\n return (\n <SortablePill\n label={item}\n index={index}\n key={item + index}\n disabled={isDisabled}\n onRemove={() => {\n removeItem(index);\n }}\n />\n );\n })}\n </SortableList>\n {constraints && constraintsType && (\n <TagsEditorConstraints constraints={constraints} constraintsType={constraintsType} />\n )}\n </div>\n );\n}\n","import * as React from 'react';\nimport isNumber from 'lodash/isNumber';\nimport { FieldAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport { TagsEditor } from './TagsEditor';\nimport { ConstraintsType, Constraint } from './types';\n\nexport interface TagsEditorContainerProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n}\n\ntype TagEditorValue = string[];\n\nfunction isEmptyTagsValue(value: TagEditorValue | null) {\n return value === null || value.length === 0;\n}\n\nfunction getConstraintsType(sizeConstraints?: Constraint): ConstraintsType | undefined {\n if (!sizeConstraints) {\n return undefined;\n }\n if (isNumber(sizeConstraints.min) && isNumber(sizeConstraints.max)) {\n return 'min-max';\n } else if (isNumber(sizeConstraints.min)) {\n return 'min';\n } else if (isNumber(sizeConstraints.max)) {\n return 'max';\n } else {\n return undefined;\n }\n}\n\nexport function TagsEditorContainer(props: TagsEditorContainerProps) {\n const field = props.field;\n\n const validations = field.validations || [];\n\n const sizeValidations = (validations as { size?: Constraint }[])\n .filter((validation) => validation.size)\n .map((validation) => validation.size);\n\n const constraints = sizeValidations.length > 0 ? sizeValidations[0] : {};\n\n const constraintsType = getConstraintsType(constraints);\n\n return (\n <FieldConnector<TagEditorValue>\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}\n isEmptyValue={isEmptyTagsValue}\n throttle={0}>\n {({ disabled, value, errors, setValue }) => {\n const items = value || [];\n return (\n <TagsEditor\n constraints={constraints}\n constraintsType={constraintsType}\n isDisabled={disabled}\n hasError={errors.length > 0}\n items={items}\n onUpdate={(items) => {\n setValue(items);\n }}\n />\n );\n }}\n </FieldConnector>\n );\n}\n\nTagsEditorContainer.defaultProps = {\n isInitiallyDisabled: true,\n};\n","import { TagsEditorContainer } from './TagsEditorContainer';\n\nexport const TagsEditor = TagsEditorContainer;\n"],"names":["TagsEditorConstraints","props","constraintsType","constraints","React","Text","as","fontColor","marginBottom","marginTop","className","css","fontStyle","testId","min","max","styles","dropContainer","whiteSpace","display","flexWrap","input","tokens","spacingS","spacingM","pill","marginRight","handle","lineHeight","padding","paddingRight","cursor","userSelect","svg","fill","gray500","verticalAlign","SortablePillHandle","SortableHandle","DragIcon","variant","SortablePill","SortableElement","Pill","label","onClose","disabled","onRemove","index","onDrag","noop","dragHandleComponent","SortableList","SortableContainer","children","TagsEditor","useState","pendingValue","setPendingValue","isDisabled","items","hasError","removeItem","useCallback","newItems","filter","_","filterIndex","onUpdate","swapItems","arrayMove","oldIndex","newIndex","TextInput","isInvalid","type","value","placeholder","onKeyDown","e","keyCode","onChange","target","useDragHandle","axis","distance","onSortEnd","map","item","key","isEmptyTagsValue","length","TagsEditorContainer","field","sizeValidations","validations","validation","size","sizeConstraints","isNumber","getConstraintsType","FieldConnector","isInitiallyDisabled","isEmptyValue","throttle","setValue","errors","defaultProps"],"mappings":"4dAWgBA,EAAsBC,OAC5BC,EAAiCD,EAAjCC,gBAAiBC,EAAgBF,EAAhBE,mBAEvBC,gBAACC,QACCC,GAAG,IACHC,UAAU,UACVC,aAAa,OACbC,UAAU,WACVC,UAAWC,MAAI,CACbC,UAAW,WAEbC,OAAO,0BACc,QAApBX,GACCE,iDACqBD,EAAYW,QAA0B,IAApBX,EAAYW,IAAY,MAAQ,QAGpD,QAApBZ,GACCE,qDACyBD,EAAYY,QAA0B,IAApBZ,EAAYY,IAAY,MAAQ,QAGxD,YAApBb,GAAiCC,EAAYY,MAAQZ,EAAYW,KAChEV,gDACoBD,EA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OAOEf,OAAS,EAC1B/B,QARQgB,OACW,GAQnBR,SAAU,SAACR,GACT6C,EAAS7C,SASvBgC,EAAoBe,aAAe,CACjCL,qBAAqB,sBC3EGV"}
|
|
1
|
+
{"version":3,"file":"field-editor-tags.cjs.production.min.js","sources":["../src/TagsEditorConstraints.tsx","../src/TagsEditor.tsx","../src/TagsEditorContainer.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport { css } from 'emotion';\nimport { Constraint, ConstraintsType } from './types';\n\nimport { Text } from '@contentful/f36-components';\n\ninterface TagEditorConstraintsProps {\n constraintsType: ConstraintsType;\n constraints: Constraint;\n}\n\nexport function TagsEditorConstraints(props: TagEditorConstraintsProps) {\n const { constraintsType, constraints } = props;\n return (\n <Text\n as=\"p\"\n fontColor=\"gray600\"\n marginBottom=\"none\"\n marginTop=\"spacingS\"\n className={css({\n fontStyle: 'italic',\n })}\n testId=\"tag-editor-constraints\">\n {constraintsType === 'min' && (\n <span>\n Requires at least {constraints.min} {constraints.min === 1 ? 'tag' : 'tags'}\n </span>\n )}\n {constraintsType === 'max' && (\n <span>\n Requires no more than {constraints.max} {constraints.max === 1 ? 'tag' : 'tags'}\n </span>\n )}\n {constraintsType === 'min-max' && constraints.max !== constraints.min && (\n <span>\n Requires between {constraints.min} and {constraints.max} tags\n </span>\n )}\n {constraintsType === 'min-max' && constraints.max === constraints.min && (\n <span>\n Requires exactly {constraints.max} {constraints.max === 1 ? 'tag' : 'tags'}\n </span>\n )}\n </Text>\n );\n}\n","import noop from 'lodash/noop';\nimport React, { useState, useCallback } from 'react';\nimport { css, cx } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\nimport { TagsEditorConstraints } from './TagsEditorConstraints';\nimport { ConstraintsType, Constraint } from './types';\nimport { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';\nimport arrayMove from 'array-move';\n\nimport { Pill, TextInput } from '@contentful/f36-components';\n\nimport { DragIcon } from '@contentful/f36-icons';\n\nexport interface TagsEditorProps {\n items: string[];\n isDisabled: boolean;\n hasError: boolean;\n constraintsType?: ConstraintsType;\n constraints?: Constraint;\n onUpdate: (items: string[]) => void;\n}\n\nconst styles = {\n dropContainer: css({\n whiteSpace: 'nowrap',\n display: 'flex',\n flexWrap: 'wrap',\n }),\n input: css({\n marginTop: tokens.spacingS,\n marginBottom: tokens.spacingM,\n }),\n pill: css({\n marginRight: tokens.spacingS,\n marginBottom: tokens.spacingS,\n }),\n pillDisabled: css({\n cursor: 'not-allowed !important',\n button: {\n cursor: 'not-allowed !important',\n // instead of changing the @contentful/f36-components package\n pointerEvents: 'none',\n },\n }),\n handle: css({\n lineHeight: '1.5rem',\n padding: '0.375rem 0.625rem',\n paddingRight: 0,\n cursor: 'grab',\n userSelect: 'none',\n svg: {\n fill: tokens.gray500,\n verticalAlign: 'middle',\n },\n }),\n};\n\nconst SortablePillHandle = SortableHandle((props: { isDisabled: boolean }) => (\n <div className={cx(styles.handle, { [styles.pillDisabled]: props.isDisabled })}>\n <DragIcon variant=\"muted\" />\n </div>\n));\n\ninterface SortablePillProps {\n label: string;\n onRemove: Function;\n isSortablePillDisabled: boolean;\n index: number;\n}\n\nconst SortablePill = SortableElement((props: SortablePillProps) => (\n <Pill\n testId=\"tag-editor-pill\"\n className={cx(styles.pill, { [styles.pillDisabled]: props.isSortablePillDisabled })}\n label={props.label}\n onClose={() => {\n if (!props.isSortablePillDisabled) {\n props.onRemove(props.index);\n }\n }}\n onDrag={noop}\n dragHandleComponent={<SortablePillHandle isDisabled={props.isSortablePillDisabled} />}\n />\n));\n\ninterface SortableListProps {\n children: React.ReactNode;\n}\n\nconst SortableList = SortableContainer((props: SortableListProps) => (\n <div className={styles.dropContainer}>{props.children}</div>\n));\n\nexport function TagsEditor(props: TagsEditorProps) {\n const [pendingValue, setPendingValue] = useState('');\n\n const { isDisabled, items, constraints, constraintsType, hasError } = props;\n\n const removeItem = useCallback(\n (index) => {\n const newItems = props.items.filter((_, filterIndex) => index !== filterIndex);\n props.onUpdate(newItems);\n },\n [props]\n );\n\n const swapItems = useCallback(\n ({ oldIndex, newIndex }) => {\n const newItems = arrayMove(props.items, oldIndex, newIndex);\n props.onUpdate(newItems);\n },\n [props]\n );\n\n return (\n <div data-test-id=\"tag-editor-container\">\n <TextInput\n testId=\"tag-editor-input\"\n className={styles.input}\n isDisabled={isDisabled}\n isInvalid={hasError}\n type=\"text\"\n value={pendingValue}\n placeholder=\"Type the value and hit enter\"\n onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {\n if (pendingValue && e.keyCode === 13) {\n props.onUpdate([...props.items, pendingValue]);\n setPendingValue('');\n }\n }}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n setPendingValue(e.target.value);\n }}\n />\n <SortableList\n useDragHandle\n axis=\"xy\"\n distance={10}\n onSortEnd={({ oldIndex, newIndex }) => {\n swapItems({ oldIndex, newIndex });\n }}>\n {items.map((item, index) => {\n return (\n <SortablePill\n label={item}\n index={index}\n key={item + index}\n disabled={isDisabled}\n /**\n * `isSortablePillDisabled` is needed as SortableElement\n * from react-sortable-hoc doesn't pass down the disabled prop.\n * See: https://github.com/clauderic/react-sortable-hoc/issues/612\n */\n isSortablePillDisabled={isDisabled}\n onRemove={() => {\n removeItem(index);\n }}\n />\n );\n })}\n </SortableList>\n {constraints && constraintsType && (\n <TagsEditorConstraints constraints={constraints} constraintsType={constraintsType} />\n )}\n </div>\n );\n}\n","import * as React from 'react';\nimport isNumber from 'lodash/isNumber';\nimport { FieldAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport { TagsEditor } from './TagsEditor';\nimport { ConstraintsType, Constraint } from './types';\n\nexport interface TagsEditorContainerProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n}\n\ntype TagEditorValue = string[];\n\nfunction isEmptyTagsValue(value: TagEditorValue | null) {\n return value === null || value.length === 0;\n}\n\nfunction getConstraintsType(sizeConstraints?: Constraint): ConstraintsType | undefined {\n if (!sizeConstraints) {\n return undefined;\n }\n if (isNumber(sizeConstraints.min) && isNumber(sizeConstraints.max)) {\n return 'min-max';\n } else if (isNumber(sizeConstraints.min)) {\n return 'min';\n } else if (isNumber(sizeConstraints.max)) {\n return 'max';\n } else {\n return undefined;\n }\n}\n\nexport function TagsEditorContainer(props: TagsEditorContainerProps) {\n const field = props.field;\n\n const validations = field.validations || [];\n\n const sizeValidations = (validations as { size?: Constraint }[])\n .filter((validation) => validation.size)\n .map((validation) => validation.size);\n\n const constraints = sizeValidations.length > 0 ? sizeValidations[0] : {};\n\n const constraintsType = getConstraintsType(constraints);\n\n return (\n <FieldConnector<TagEditorValue>\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}\n isEmptyValue={isEmptyTagsValue}\n throttle={0}>\n {({ disabled, value, errors, setValue }) => {\n const items = value || [];\n return (\n <TagsEditor\n constraints={constraints}\n constraintsType={constraintsType}\n isDisabled={disabled}\n hasError={errors.length > 0}\n items={items}\n onUpdate={(items) => {\n setValue(items);\n }}\n />\n );\n }}\n </FieldConnector>\n );\n}\n\nTagsEditorContainer.defaultProps = {\n isInitiallyDisabled: true,\n};\n","import { TagsEditorContainer } from './TagsEditorContainer';\n\nexport const TagsEditor = TagsEditorContainer;\n"],"names":["TagsEditorConstraints","props","constraintsType","constraints","React","Text","as","fontColor","marginBottom","marginTop","className","css","fontStyle","testId","min","max","styles","dropContainer","whiteSpace","display","flexWrap","input","tokens","spacingS","spacingM","pill","marginRight","pillDisabled","cursor","button","pointerEvents","handle","lineHeight","padding","paddingRight","userSelect","svg","fill","gray500","verticalAlign","SortablePillHandle","SortableHandle","cx","isDisabled","DragIcon","variant","SortablePill","SortableElement","Pill","isSortablePillDisabled","label","onClose","onRemove","index","onDrag","noop","dragHandleComponent","SortableList","SortableContainer","children","TagsEditor","useState","pendingValue","setPendingValue","items","hasError","removeItem","useCallback","newItems","filter","_","filterIndex","onUpdate","swapItems","arrayMove","oldIndex","newIndex","TextInput","isInvalid","type","value","placeholder","onKeyDown","e","keyCode","onChange","target","useDragHandle","axis","distance","onSortEnd","map","item","key","disabled","isEmptyTagsValue","length","TagsEditorContainer","field","sizeValidations","validations","validation","size","sizeConstraints","isNumber","getConstraintsType","FieldConnector","isInitiallyDisabled","isEmptyValue","throttle","setValue","errors","defaultProps"],"mappings":"4dAWgBA,EAAsBC,OAC5BC,EAAiCD,EAAjCC,gBAAiBC,EAAgBF,EAAhBE,mBAEvBC,gBAACC,QACCC,GAAG,IACHC,UAAU,UACVC,aAAa,OACbC,UAAU,WACVC,UAAWC,MAAI,CACbC,UAAW,WAEbC,OAAO,0BACc,QAApBX,GACCE,iDACqBD,EAAYW,QAA0B,IAApBX,EAAYW,IAAY,MAAQ,QAGpD,QAApBZ,GACCE,qDACyBD,EAAYY,QAA0B,IAApBZ,EAAYY,IAAY,MAAQ,QAGxD,YAApBb,GAAiCC,EAAYY,MAAQZ,EAAYW,KAChEV,gDACoBD,EAAYW,YAAUX,EAAYY,aAGnC,YAApBb,GAAiCC,EAAYY,MAAQZ,EAAYW,KAChEV,gDACoBD,EAAYY,QAA0B,IAApBZ,EAAYY,IAAY,MAAQ,SClB9E,IAAMC,EAAS,CACbC,cAAeN,MAAI,CACjBO,WAAY,SACZC,QAAS,OACTC,SAAU,SAEZC,MAAOV,MAAI,CACTF,UAAWa,EAAOC,SAClBf,aAAcc,EAAOE,WAEvBC,KAAMd,MAAI,CACRe,YAAaJ,EAAOC,SACpBf,aAAcc,EAAOC,WAEvBI,aAAchB,MAAI,CAChBiB,OAAQ,yBACRC,OAAQ,CACND,OAAQ,yBAERE,cAAe,UAGnBC,OAAQpB,MAAI,CACVqB,WAAY,SACZC,QAAS,oBACTC,aAAc,EACdN,OAAQ,OACRO,WAAY,OACZC,IAAK,CACHC,KAAMf,EAAOgB,QACbC,cAAe,aAKfC,EAAqBC,kBAAe,SAACxC,gBACzCG,uBAAKM,UAAWgC,KAAG1B,EAAOe,eAAWf,EAAOW,cAAe1B,EAAM0C,gBAC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vC,UAEdjD,gBAAC0C,GACCI,MAAO0C,EACPvC,MAAOA,EACPwC,IAAKD,EAAOvC,EACZyC,SAAUnD,EAMVM,uBAAwBN,EACxBS,SAAU,WACRc,EAAWb,UAMpBlD,GAAeD,GACdE,gBAACJ,GAAsBG,YAAaA,EAAaD,gBAAiBA,KC/I1E,SAAS6F,EAAiBf,UACP,OAAVA,GAAmC,IAAjBA,EAAMgB,gBAkBjBC,EAAoBhG,OAC5BiG,EAAQjG,EAAMiG,MAIdC,GAFcD,EAAME,aAAe,IAGtC/B,QAAO,SAACgC,UAAeA,EAAWC,QAClCX,KAAI,SAACU,UAAeA,EAAWC,QAE5BnG,EAAcgG,EAAgBH,OAAS,EAAIG,EAAgB,GAAK,GAEhEjG,EA1BR,SAA4BqG,MACrBA,SAGDC,EAASD,EAAgBzF,MAAQ0F,EAASD,EAAgBxF,KACrD,UACEyF,EAASD,EAAgBzF,KAC3B,MACE0F,EAASD,EAAgBxF,KAC3B,aAiBe0F,CAAmBtG,UAGzCC,gBAACsG,kBACCR,MAAOA,EACPS,oBAAqB1G,EAAM0G,oBAC3BC,aAAcb,EACdc,SAAU,IACT,gBAA4BC,IAAAA,gBAGzB1G,gBAACwD,GACCzD,YAAaA,EACbD,gBAAiBA,EACjByC,aANFmD,SAOE7B,WAPe8C,OAOEf,OAAS,EAC1BhC,QARQgB,OACW,GAQnBR,SAAU,SAACR,GACT8C,EAAS9C,SASvBiC,EAAoBe,aAAe,CACjCL,qBAAqB,sBC3EGV"}
|
|
@@ -2,7 +2,7 @@ import React__default, { useState, useCallback, createElement } from 'react';
|
|
|
2
2
|
import isNumber from 'lodash-es/isNumber';
|
|
3
3
|
import { FieldConnector } from '@contentful/field-editor-shared';
|
|
4
4
|
import noop from 'lodash-es/noop';
|
|
5
|
-
import { css } from 'emotion';
|
|
5
|
+
import { css, cx } from 'emotion';
|
|
6
6
|
import tokens from '@contentful/f36-tokens';
|
|
7
7
|
import { Text, TextInput, Pill } from '@contentful/f36-components';
|
|
8
8
|
import { SortableElement, SortableContainer, SortableHandle } from 'react-sortable-hoc';
|
|
@@ -38,6 +38,14 @@ var styles = {
|
|
|
38
38
|
marginRight: tokens.spacingS,
|
|
39
39
|
marginBottom: tokens.spacingS
|
|
40
40
|
}),
|
|
41
|
+
pillDisabled: /*#__PURE__*/css({
|
|
42
|
+
cursor: 'not-allowed !important',
|
|
43
|
+
button: {
|
|
44
|
+
cursor: 'not-allowed !important',
|
|
45
|
+
// instead of changing the @contentful/f36-components package
|
|
46
|
+
pointerEvents: 'none'
|
|
47
|
+
}
|
|
48
|
+
}),
|
|
41
49
|
handle: /*#__PURE__*/css({
|
|
42
50
|
lineHeight: '1.5rem',
|
|
43
51
|
padding: '0.375rem 0.625rem',
|
|
@@ -50,25 +58,31 @@ var styles = {
|
|
|
50
58
|
}
|
|
51
59
|
})
|
|
52
60
|
};
|
|
53
|
-
var SortablePillHandle = /*#__PURE__*/SortableHandle(function () {
|
|
61
|
+
var SortablePillHandle = /*#__PURE__*/SortableHandle(function (props) {
|
|
62
|
+
var _cx;
|
|
63
|
+
|
|
54
64
|
return React__default.createElement("div", {
|
|
55
|
-
className: styles.handle
|
|
65
|
+
className: cx(styles.handle, (_cx = {}, _cx[styles.pillDisabled] = props.isDisabled, _cx))
|
|
56
66
|
}, React__default.createElement(DragIcon, {
|
|
57
67
|
variant: "muted"
|
|
58
68
|
}));
|
|
59
69
|
});
|
|
60
70
|
var SortablePill = /*#__PURE__*/SortableElement(function (props) {
|
|
71
|
+
var _cx2;
|
|
72
|
+
|
|
61
73
|
return React__default.createElement(Pill, {
|
|
62
74
|
testId: "tag-editor-pill",
|
|
63
|
-
className: styles.pill,
|
|
75
|
+
className: cx(styles.pill, (_cx2 = {}, _cx2[styles.pillDisabled] = props.isSortablePillDisabled, _cx2)),
|
|
64
76
|
label: props.label,
|
|
65
77
|
onClose: function onClose() {
|
|
66
|
-
if (!props.
|
|
78
|
+
if (!props.isSortablePillDisabled) {
|
|
67
79
|
props.onRemove(props.index);
|
|
68
80
|
}
|
|
69
81
|
},
|
|
70
82
|
onDrag: noop,
|
|
71
|
-
dragHandleComponent: React__default.createElement(SortablePillHandle,
|
|
83
|
+
dragHandleComponent: React__default.createElement(SortablePillHandle, {
|
|
84
|
+
isDisabled: props.isSortablePillDisabled
|
|
85
|
+
})
|
|
72
86
|
});
|
|
73
87
|
});
|
|
74
88
|
var SortableList = /*#__PURE__*/SortableContainer(function (props) {
|
|
@@ -135,6 +149,13 @@ function TagsEditor(props) {
|
|
|
135
149
|
index: index,
|
|
136
150
|
key: item + index,
|
|
137
151
|
disabled: isDisabled,
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* `isSortablePillDisabled` is needed as SortableElement
|
|
155
|
+
* from react-sortable-hoc doesn't pass down the disabled prop.
|
|
156
|
+
* See: https://github.com/clauderic/react-sortable-hoc/issues/612
|
|
157
|
+
*/
|
|
158
|
+
isSortablePillDisabled: isDisabled,
|
|
138
159
|
onRemove: function onRemove() {
|
|
139
160
|
removeItem(index);
|
|
140
161
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-tags.esm.js","sources":["../src/TagsEditorConstraints.tsx","../src/TagsEditor.tsx","../src/TagsEditorContainer.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport { css } from 'emotion';\nimport { Constraint, ConstraintsType } from './types';\n\nimport { Text } from '@contentful/f36-components';\n\ninterface TagEditorConstraintsProps {\n constraintsType: ConstraintsType;\n constraints: Constraint;\n}\n\nexport function TagsEditorConstraints(props: TagEditorConstraintsProps) {\n const { constraintsType, constraints } = props;\n return (\n <Text\n as=\"p\"\n fontColor=\"gray600\"\n marginBottom=\"none\"\n marginTop=\"spacingS\"\n className={css({\n fontStyle: 'italic',\n })}\n testId=\"tag-editor-constraints\">\n {constraintsType === 'min' && (\n <span>\n Requires at least {constraints.min} {constraints.min === 1 ? 'tag' : 'tags'}\n </span>\n )}\n {constraintsType === 'max' && (\n <span>\n Requires no more than {constraints.max} {constraints.max === 1 ? 'tag' : 'tags'}\n </span>\n )}\n {constraintsType === 'min-max' && constraints.max !== constraints.min && (\n <span>\n Requires between {constraints.min} and {constraints.max} tags\n </span>\n )}\n {constraintsType === 'min-max' && constraints.max === constraints.min && (\n <span>\n Requires exactly {constraints.max} {constraints.max === 1 ? 'tag' : 'tags'}\n </span>\n )}\n </Text>\n );\n}\n","import noop from 'lodash/noop';\nimport React, { useState, useCallback } from 'react';\nimport { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\nimport { TagsEditorConstraints } from './TagsEditorConstraints';\nimport { ConstraintsType, Constraint } from './types';\nimport { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';\nimport arrayMove from 'array-move';\n\nimport { Pill, TextInput } from '@contentful/f36-components';\n\nimport { DragIcon } from '@contentful/f36-icons';\n\nexport interface TagsEditorProps {\n items: string[];\n isDisabled: boolean;\n hasError: boolean;\n constraintsType?: ConstraintsType;\n constraints?: Constraint;\n onUpdate: (items: string[]) => void;\n}\n\nconst styles = {\n dropContainer: css({\n whiteSpace: 'nowrap',\n display: 'flex',\n flexWrap: 'wrap',\n }),\n input: css({\n marginTop: tokens.spacingS,\n marginBottom: tokens.spacingM,\n }),\n pill: css({\n marginRight: tokens.spacingS,\n marginBottom: tokens.spacingS,\n }),\n handle: css({\n lineHeight: '1.5rem',\n padding: '0.375rem 0.625rem',\n paddingRight: 0,\n cursor: 'grab',\n userSelect: 'none',\n svg: {\n fill: tokens.gray500,\n verticalAlign: 'middle',\n },\n }),\n};\n\nconst SortablePillHandle = SortableHandle(() => (\n <div className={styles.handle}>\n <DragIcon variant=\"muted\" />\n </div>\n));\n\ninterface SortablePillProps {\n label: string;\n onRemove: Function;\n disabled: boolean;\n index: number;\n}\n\nconst SortablePill = SortableElement((props: SortablePillProps) => (\n <Pill\n testId=\"tag-editor-pill\"\n className={styles.pill}\n label={props.label}\n onClose={() => {\n if (!props.disabled) {\n props.onRemove(props.index);\n }\n }}\n onDrag={noop}\n dragHandleComponent={<SortablePillHandle />}\n />\n));\n\ninterface SortableListProps {\n children: React.ReactNode;\n}\n\nconst SortableList = SortableContainer((props: SortableListProps) => (\n <div className={styles.dropContainer}>{props.children}</div>\n));\n\nexport function TagsEditor(props: TagsEditorProps) {\n const [pendingValue, setPendingValue] = useState('');\n\n const { isDisabled, items, constraints, constraintsType, hasError } = props;\n\n const removeItem = useCallback(\n (index) => {\n const newItems = props.items.filter((_, filterIndex) => index !== filterIndex);\n props.onUpdate(newItems);\n },\n [props]\n );\n\n const swapItems = useCallback(\n ({ oldIndex, newIndex }) => {\n const newItems = arrayMove(props.items, oldIndex, newIndex);\n props.onUpdate(newItems);\n },\n [props]\n );\n\n return (\n <div data-test-id=\"tag-editor-container\">\n <TextInput\n testId=\"tag-editor-input\"\n className={styles.input}\n isDisabled={isDisabled}\n isInvalid={hasError}\n type=\"text\"\n value={pendingValue}\n placeholder=\"Type the value and hit enter\"\n onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {\n if (pendingValue && e.keyCode === 13) {\n props.onUpdate([...props.items, pendingValue]);\n setPendingValue('');\n }\n }}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n setPendingValue(e.target.value);\n }}\n />\n <SortableList\n useDragHandle\n axis=\"xy\"\n distance={10}\n onSortEnd={({ oldIndex, newIndex }) => {\n swapItems({ oldIndex, newIndex });\n }}>\n {items.map((item, index) => {\n return (\n <SortablePill\n label={item}\n index={index}\n key={item + index}\n disabled={isDisabled}\n onRemove={() => {\n removeItem(index);\n }}\n />\n );\n })}\n </SortableList>\n {constraints && constraintsType && (\n <TagsEditorConstraints constraints={constraints} constraintsType={constraintsType} />\n )}\n </div>\n );\n}\n","import * as React from 'react';\nimport isNumber from 'lodash/isNumber';\nimport { FieldAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport { TagsEditor } from './TagsEditor';\nimport { ConstraintsType, Constraint } from './types';\n\nexport interface TagsEditorContainerProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n}\n\ntype TagEditorValue = string[];\n\nfunction isEmptyTagsValue(value: TagEditorValue | null) {\n return value === null || value.length === 0;\n}\n\nfunction getConstraintsType(sizeConstraints?: Constraint): ConstraintsType | undefined {\n if (!sizeConstraints) {\n return undefined;\n }\n if (isNumber(sizeConstraints.min) && isNumber(sizeConstraints.max)) {\n return 'min-max';\n } else if (isNumber(sizeConstraints.min)) {\n return 'min';\n } else if (isNumber(sizeConstraints.max)) {\n return 'max';\n } else {\n return undefined;\n }\n}\n\nexport function TagsEditorContainer(props: TagsEditorContainerProps) {\n const field = props.field;\n\n const validations = field.validations || [];\n\n const sizeValidations = (validations as { size?: Constraint }[])\n .filter((validation) => validation.size)\n .map((validation) => validation.size);\n\n const constraints = sizeValidations.length > 0 ? sizeValidations[0] : {};\n\n const constraintsType = getConstraintsType(constraints);\n\n return (\n <FieldConnector<TagEditorValue>\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}\n isEmptyValue={isEmptyTagsValue}\n throttle={0}>\n {({ disabled, value, errors, setValue }) => {\n const items = value || [];\n return (\n <TagsEditor\n constraints={constraints}\n constraintsType={constraintsType}\n isDisabled={disabled}\n hasError={errors.length > 0}\n items={items}\n onUpdate={(items) => {\n setValue(items);\n }}\n />\n );\n }}\n </FieldConnector>\n );\n}\n\nTagsEditorContainer.defaultProps = {\n isInitiallyDisabled: true,\n};\n","import { TagsEditorContainer } from './TagsEditorContainer';\n\nexport const TagsEditor = TagsEditorContainer;\n"],"names":["TagsEditorConstraints","props","constraintsType","constraints","React","Text","as","fontColor","marginBottom","marginTop","className","css","fontStyle","testId","min","max","styles","dropContainer","whiteSpace","display","flexWrap","input","tokens","spacingS","spacingM","pill","marginRight","handle","lineHeight","padding","paddingRight","cursor","userSelect","svg","fill","gray500","verticalAlign","SortablePillHandle","SortableHandle","DragIcon","variant","SortablePill","SortableElement","Pill","label","onClose","disabled","onRemove","index","onDrag","noop","dragHandleComponent","SortableList","SortableContainer","children","TagsEditor","useState","pendingValue","setPendingValue","isDisabled","items","hasError","removeItem","useCallback","newItems","filter","_","filterIndex","onUpdate","swapItems","oldIndex","newIndex","arrayMove","TextInput","isInvalid","type","value","placeholder","onKeyDown","e","keyCode","onChange","target","useDragHandle","axis","distance","onSortEnd","map","item","key","isEmptyTagsValue","length","getConstraintsType","sizeConstraints","undefined","isNumber","TagsEditorContainer","field","validations","sizeValidations","validation","size","FieldConnector","isInitiallyDisabled","isEmptyValue","throttle","errors","setValue","defaultProps"],"mappings":";;;;;;;;;;;SAWgBA,sBAAsBC;AACpC,MAAQC,eAAR,GAAyCD,KAAzC,CAAQC,eAAR;AAAA,MAAyBC,WAAzB,GAAyCF,KAAzC,CAAyBE,WAAzB;AACA,SACEC,4BAAA,CAACC,IAAD;AACEC,IAAAA,EAAE,EAAC;AACHC,IAAAA,SAAS,EAAC;AACVC,IAAAA,YAAY,EAAC;AACbC,IAAAA,SAAS,EAAC;AACVC,IAAAA,SAAS,EAAEC,GAAG,CAAC;AACbC,MAAAA,SAAS,EAAE;AADE,KAAD;AAGdC,IAAAA,MAAM,EAAC;GART,EASGX,eAAe,KAAK,KAApB,IACCE,4BAAA,OAAA,MAAA,sBAAA,EACqBD,WAAW,CAACW,GADjC,KAAA,EACuCX,WAAW,CAACW,GAAZ,KAAoB,CAApB,GAAwB,KAAxB,GAAgC,MADvE,CAVJ,EAcGZ,eAAe,KAAK,KAApB,IACCE,4BAAA,OAAA,MAAA,0BAAA,EACyBD,WAAW,CAACY,GADrC,KAAA,EAC2CZ,WAAW,CAACY,GAAZ,KAAoB,CAApB,GAAwB,KAAxB,GAAgC,MAD3E,CAfJ,EAmBGb,eAAe,KAAK,SAApB,IAAiCC,WAAW,CAACY,GAAZ,KAAoBZ,WAAW,CAACW,GAAjE,IACCV,4BAAA,OAAA,MAAA,qBAAA,EACoBD,WAAW,CAACW,GADhC,SAAA,EAC0CX,WAAW,CAACY,GADtD,SAAA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MADsB,CACf,UAACmC,UAAD;AAAA,WAAgBA,UAAU,CAACC,IAA3B;AAAA,GADe,EAEtBd,GAFsB,CAElB,UAACa,UAAD;AAAA,WAAgBA,UAAU,CAACC,IAA3B;AAAA,GAFkB,CAAzB;AAIA,MAAMlG,WAAW,GAAGgG,eAAe,CAACR,MAAhB,GAAyB,CAAzB,GAA6BQ,eAAe,CAAC,CAAD,CAA5C,GAAkD,EAAtE;AAEA,MAAMjG,eAAe,GAAG0F,kBAAkB,CAACzF,WAAD,CAA1C;AAEA,SACEC,aAAA,CAACkG,cAAD;AACEL,IAAAA,KAAK,EAAEA;AACPM,IAAAA,mBAAmB,EAAEtG,KAAK,CAACsG;AAC3BC,IAAAA,YAAY,EAAEd;AACde,IAAAA,QAAQ,EAAE;GAJZ,EAKG;QAAG3D,gBAAAA;QAAU8B,aAAAA;QAAO8B,cAAAA;QAAQC,gBAAAA;AAC3B,QAAM/C,KAAK,GAAGgB,KAAK,IAAI,EAAvB;AACA,WACExE,aAAA,CAACmD,UAAD;AACEpD,MAAAA,WAAW,EAAEA;AACbD,MAAAA,eAAe,EAAEA;AACjByD,MAAAA,UAAU,EAAEb;AACZe,MAAAA,QAAQ,EAAE6C,MAAM,CAACf,MAAP,GAAgB;AAC1B/B,MAAAA,KAAK,EAAEA;AACPQ,MAAAA,QAAQ,EAAE,kBAACR,KAAD;AACR+C,QAAAA,QAAQ,CAAC/C,KAAD,CAAR;AACD;KARH,CADF;AAYD,GAnBH,CADF;AAuBD;AAEDoC,mBAAmB,CAACY,YAApB,GAAmC;AACjCL,EAAAA,mBAAmB,EAAE;AADY,CAAnC;;IC1EahD,YAAU,GAAGyC,mBAAnB;;;;"}
|
|
1
|
+
{"version":3,"file":"field-editor-tags.esm.js","sources":["../src/TagsEditorConstraints.tsx","../src/TagsEditor.tsx","../src/TagsEditorContainer.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport { css } from 'emotion';\nimport { Constraint, ConstraintsType } from './types';\n\nimport { Text } from '@contentful/f36-components';\n\ninterface TagEditorConstraintsProps {\n constraintsType: ConstraintsType;\n constraints: Constraint;\n}\n\nexport function TagsEditorConstraints(props: TagEditorConstraintsProps) {\n const { constraintsType, constraints } = props;\n return (\n <Text\n as=\"p\"\n fontColor=\"gray600\"\n marginBottom=\"none\"\n marginTop=\"spacingS\"\n className={css({\n fontStyle: 'italic',\n })}\n testId=\"tag-editor-constraints\">\n {constraintsType === 'min' && (\n <span>\n Requires at least {constraints.min} {constraints.min === 1 ? 'tag' : 'tags'}\n </span>\n )}\n {constraintsType === 'max' && (\n <span>\n Requires no more than {constraints.max} {constraints.max === 1 ? 'tag' : 'tags'}\n </span>\n )}\n {constraintsType === 'min-max' && constraints.max !== constraints.min && (\n <span>\n Requires between {constraints.min} and {constraints.max} tags\n </span>\n )}\n {constraintsType === 'min-max' && constraints.max === constraints.min && (\n <span>\n Requires exactly {constraints.max} {constraints.max === 1 ? 'tag' : 'tags'}\n </span>\n )}\n </Text>\n );\n}\n","import noop from 'lodash/noop';\nimport React, { useState, useCallback } from 'react';\nimport { css, cx } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\nimport { TagsEditorConstraints } from './TagsEditorConstraints';\nimport { ConstraintsType, Constraint } from './types';\nimport { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';\nimport arrayMove from 'array-move';\n\nimport { Pill, TextInput } from '@contentful/f36-components';\n\nimport { DragIcon } from '@contentful/f36-icons';\n\nexport interface TagsEditorProps {\n items: string[];\n isDisabled: boolean;\n hasError: boolean;\n constraintsType?: ConstraintsType;\n constraints?: Constraint;\n onUpdate: (items: string[]) => void;\n}\n\nconst styles = {\n dropContainer: css({\n whiteSpace: 'nowrap',\n display: 'flex',\n flexWrap: 'wrap',\n }),\n input: css({\n marginTop: tokens.spacingS,\n marginBottom: tokens.spacingM,\n }),\n pill: css({\n marginRight: tokens.spacingS,\n marginBottom: tokens.spacingS,\n }),\n pillDisabled: css({\n cursor: 'not-allowed !important',\n button: {\n cursor: 'not-allowed !important',\n // instead of changing the @contentful/f36-components package\n pointerEvents: 'none',\n },\n }),\n handle: css({\n lineHeight: '1.5rem',\n padding: '0.375rem 0.625rem',\n paddingRight: 0,\n cursor: 'grab',\n userSelect: 'none',\n svg: {\n fill: tokens.gray500,\n verticalAlign: 'middle',\n },\n }),\n};\n\nconst SortablePillHandle = SortableHandle((props: { isDisabled: boolean }) => (\n <div className={cx(styles.handle, { [styles.pillDisabled]: props.isDisabled })}>\n <DragIcon variant=\"muted\" />\n </div>\n));\n\ninterface SortablePillProps {\n label: string;\n onRemove: Function;\n isSortablePillDisabled: boolean;\n index: number;\n}\n\nconst SortablePill = SortableElement((props: SortablePillProps) => (\n <Pill\n testId=\"tag-editor-pill\"\n className={cx(styles.pill, { [styles.pillDisabled]: props.isSortablePillDisabled })}\n label={props.label}\n onClose={() => {\n if (!props.isSortablePillDisabled) {\n props.onRemove(props.index);\n }\n }}\n onDrag={noop}\n dragHandleComponent={<SortablePillHandle isDisabled={props.isSortablePillDisabled} />}\n />\n));\n\ninterface SortableListProps {\n children: React.ReactNode;\n}\n\nconst SortableList = SortableContainer((props: SortableListProps) => (\n <div className={styles.dropContainer}>{props.children}</div>\n));\n\nexport function TagsEditor(props: TagsEditorProps) {\n const [pendingValue, setPendingValue] = useState('');\n\n const { isDisabled, items, constraints, constraintsType, hasError } = props;\n\n const removeItem = useCallback(\n (index) => {\n const newItems = props.items.filter((_, filterIndex) => index !== filterIndex);\n props.onUpdate(newItems);\n },\n [props]\n );\n\n const swapItems = useCallback(\n ({ oldIndex, newIndex }) => {\n const newItems = arrayMove(props.items, oldIndex, newIndex);\n props.onUpdate(newItems);\n },\n [props]\n );\n\n return (\n <div data-test-id=\"tag-editor-container\">\n <TextInput\n testId=\"tag-editor-input\"\n className={styles.input}\n isDisabled={isDisabled}\n isInvalid={hasError}\n type=\"text\"\n value={pendingValue}\n placeholder=\"Type the value and hit enter\"\n onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {\n if (pendingValue && e.keyCode === 13) {\n props.onUpdate([...props.items, pendingValue]);\n setPendingValue('');\n }\n }}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n setPendingValue(e.target.value);\n }}\n />\n <SortableList\n useDragHandle\n axis=\"xy\"\n distance={10}\n onSortEnd={({ oldIndex, newIndex }) => {\n swapItems({ oldIndex, newIndex });\n }}>\n {items.map((item, index) => {\n return (\n <SortablePill\n label={item}\n index={index}\n key={item + index}\n disabled={isDisabled}\n /**\n * `isSortablePillDisabled` is needed as SortableElement\n * from react-sortable-hoc doesn't pass down the disabled prop.\n * See: https://github.com/clauderic/react-sortable-hoc/issues/612\n */\n isSortablePillDisabled={isDisabled}\n onRemove={() => {\n removeItem(index);\n }}\n />\n );\n })}\n </SortableList>\n {constraints && constraintsType && (\n <TagsEditorConstraints constraints={constraints} constraintsType={constraintsType} />\n )}\n </div>\n );\n}\n","import * as React from 'react';\nimport isNumber from 'lodash/isNumber';\nimport { FieldAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport { TagsEditor } from './TagsEditor';\nimport { ConstraintsType, Constraint } from './types';\n\nexport interface TagsEditorContainerProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n}\n\ntype TagEditorValue = string[];\n\nfunction isEmptyTagsValue(value: TagEditorValue | null) {\n return value === null || value.length === 0;\n}\n\nfunction getConstraintsType(sizeConstraints?: Constraint): ConstraintsType | undefined {\n if (!sizeConstraints) {\n return undefined;\n }\n if (isNumber(sizeConstraints.min) && isNumber(sizeConstraints.max)) {\n return 'min-max';\n } else if (isNumber(sizeConstraints.min)) {\n return 'min';\n } else if (isNumber(sizeConstraints.max)) {\n return 'max';\n } else {\n return undefined;\n }\n}\n\nexport function TagsEditorContainer(props: TagsEditorContainerProps) {\n const field = props.field;\n\n const validations = field.validations || [];\n\n const sizeValidations = (validations as { size?: Constraint }[])\n .filter((validation) => validation.size)\n .map((validation) => validation.size);\n\n const constraints = sizeValidations.length > 0 ? sizeValidations[0] : {};\n\n const constraintsType = getConstraintsType(constraints);\n\n return (\n <FieldConnector<TagEditorValue>\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}\n isEmptyValue={isEmptyTagsValue}\n throttle={0}>\n {({ disabled, value, errors, setValue }) => {\n const items = value || [];\n return (\n <TagsEditor\n constraints={constraints}\n constraintsType={constraintsType}\n isDisabled={disabled}\n hasError={errors.length > 0}\n items={items}\n onUpdate={(items) => {\n setValue(items);\n }}\n />\n );\n }}\n </FieldConnector>\n );\n}\n\nTagsEditorContainer.defaultProps = {\n isInitiallyDisabled: true,\n};\n","import { TagsEditorContainer } from './TagsEditorContainer';\n\nexport const TagsEditor = TagsEditorContainer;\n"],"names":["TagsEditorConstraints","props","constraintsType","constraints","React","Text","as","fontColor","marginBottom","marginTop","className","css","fontStyle","testId","min","max","styles","dropContainer","whiteSpace","display","flexWrap","input","tokens","spacingS","spacingM","pill","marginRight","pillDisabled","cursor","button","pointerEvents","handle","lineHeight","padding","paddingRight","userSelect","svg","fill","gray500","verticalAlign","SortablePillHandle","SortableHandle","cx","isDisabled","DragIcon","variant","SortablePill","SortableElement","Pill","isSortablePillDisabled","label","onClose","onRemove","index","onDrag","noop","dragHandleComponent","SortableList","SortableContainer","children","TagsEditor","useState","pendingValue","setPendingValue","items","hasError","removeItem","useCallback","newItems","filter","_","filterIndex","onUpdate","swapItems","oldIndex","newIndex","arrayMove","TextInput","isInvalid","type","value","placeholder","onKeyDown","e","keyCode","onChange","target","useDragHandle","axis","distance","onSortEnd","map","item","key","disabled","isEmptyTagsValue","length","getConstraintsType","sizeConstraints","undefined","isNumber","TagsEditorContainer","field","validations","sizeValidations","validation","size","FieldConnector","isInitiallyDisabled","isEmptyValue","throttle","errors","setValue","defaultProps"],"mappings":";;;;;;;;;;;SAWgBA,sBAAsBC;AACpC,MAAQC,eAAR,GAAyCD,KAAzC,CAAQC,eAAR;AAAA,MAAyBC,WAAzB,GAAyCF,KA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module": "dist/field-editor-tags.esm.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@contentful/f36-components": "^4.0.27",
|
|
25
25
|
"@contentful/f36-icons": "^4.1.0",
|
|
26
26
|
"@contentful/f36-tokens": "^4.0.0",
|
|
27
|
-
"@contentful/field-editor-shared": "^1.1.
|
|
27
|
+
"@contentful/field-editor-shared": "^1.1.3",
|
|
28
28
|
"array-move": "^3.0.0",
|
|
29
29
|
"emotion": "^10.0.0",
|
|
30
30
|
"lodash": "^4.17.15",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"react-sortable-hoc": "^2.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@contentful/field-editor-test-utils": "^1.
|
|
35
|
+
"@contentful/field-editor-test-utils": "^1.2.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": ">=16.8.0"
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "6cee7fea6ac7d0f8cf1c6689ad8c95fc5814d85e"
|
|
51
51
|
}
|