@contentful/default-field-editors 1.0.0 → 1.0.4
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 +20 -0
- package/dist/default-field-editors.cjs.development.js +6 -3
- package/dist/default-field-editors.cjs.development.js.map +1 -1
- package/dist/default-field-editors.cjs.production.min.js +1 -1
- package/dist/default-field-editors.cjs.production.min.js.map +1 -1
- package/dist/default-field-editors.esm.js +6 -3
- package/dist/default-field-editors.esm.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
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.0.4](https://github.com/contentful/field-editors/compare/@contentful/default-field-editors@1.0.3...@contentful/default-field-editors@1.0.4) (2021-11-08)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @contentful/default-field-editors
|
|
9
|
+
|
|
10
|
+
## [1.0.3](https://github.com/contentful/field-editors/compare/@contentful/default-field-editors@1.0.2...@contentful/default-field-editors@1.0.3) (2021-11-08)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @contentful/default-field-editors
|
|
13
|
+
|
|
14
|
+
## [1.0.2](https://github.com/contentful/field-editors/compare/@contentful/default-field-editors@1.0.1...@contentful/default-field-editors@1.0.2) (2021-11-04)
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
- add content type id to field id ([71f4d83](https://github.com/contentful/field-editors/commit/71f4d83fff6fff617430cb2048030bdaabfc6487))
|
|
19
|
+
|
|
20
|
+
## [1.0.1](https://github.com/contentful/field-editors/compare/@contentful/default-field-editors@1.0.0...@contentful/default-field-editors@1.0.1) (2021-11-04)
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
- pass a unique form-control id ([#908](https://github.com/contentful/field-editors/issues/908)) ([d0e0480](https://github.com/contentful/field-editors/commit/d0e048023287b77191e6ae4b7148472b169e5564))
|
|
25
|
+
|
|
6
26
|
# [1.0.0](https://github.com/contentful/field-editors/compare/@contentful/default-field-editors@0.11.0...@contentful/default-field-editors@1.0.0) (2021-11-04)
|
|
7
27
|
|
|
8
28
|
**Note:** Version bump only for package @contentful/default-field-editors
|
|
@@ -225,7 +225,7 @@ var styles = {
|
|
|
225
225
|
};
|
|
226
226
|
|
|
227
227
|
var FieldWrapper = function FieldWrapper(props) {
|
|
228
|
-
var _sdk$parameters$insta, _sdk$parameters, _sdk$parameters$insta2;
|
|
228
|
+
var _sdk$parameters$insta, _sdk$parameters, _sdk$parameters$insta2, _sdk$contentType, _sdk$contentType$sys;
|
|
229
229
|
|
|
230
230
|
var ids = props.sdk.ids;
|
|
231
231
|
|
|
@@ -255,15 +255,18 @@ var FieldWrapper = function FieldWrapper(props) {
|
|
|
255
255
|
setHasErrors((errors || []).length > 0);
|
|
256
256
|
});
|
|
257
257
|
}, [field]);
|
|
258
|
+
var fieldControlId = [field.id, field.locale, (_sdk$contentType = sdk.contentType) == null ? void 0 : (_sdk$contentType$sys = _sdk$contentType.sys) == null ? void 0 : _sdk$contentType$sys.id].filter(function (item) {
|
|
259
|
+
return item;
|
|
260
|
+
}).join('-');
|
|
258
261
|
return React.createElement(f36Components.FormControl, {
|
|
262
|
+
id: fieldControlId,
|
|
259
263
|
testId: "entity-field-controls",
|
|
260
264
|
"data-test-id": "entity-field-controls",
|
|
261
265
|
className: emotion.cx(showFocusBar && styles.withFocusBar, className),
|
|
262
266
|
"aria-invalid": hasErrors,
|
|
263
267
|
isRequired: field.required
|
|
264
268
|
}, renderHeading ? renderHeading(name) : React.createElement(f36Components.FormControl.Label, {
|
|
265
|
-
className: styles.label
|
|
266
|
-
htmlFor: field.id
|
|
269
|
+
className: styles.label
|
|
267
270
|
}, name), children, React.createElement(fieldEditorValidationErrors.ValidationErrors, {
|
|
268
271
|
field: field,
|
|
269
272
|
space: sdk.space,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-field-editors.cjs.development.js","sources":["../src/getDefaultWidgetId.ts","../src/Field.tsx","../src/FieldWrapper.styles.ts","../src/FieldWrapper.tsx"],"sourcesContent":["import type { FieldExtensionSDK } from '@contentful/field-editor-shared';\nimport type { WidgetType } from './types';\n\nconst DROPDOWN_TYPES = ['Text', 'Symbol', 'Integer', 'Number', 'Boolean'];\n\nexport const DEFAULTS: { [key: string]: WidgetType } = {\n Text: 'markdown',\n Symbol: 'singleLine',\n Integer: 'numberEditor',\n Number: 'numberEditor',\n Boolean: 'boolean',\n Date: 'datePicker',\n Location: 'locationEditor',\n Object: 'objectEditor',\n RichText: 'richTextEditor',\n Symbols: 'tagEditor',\n File: 'fileEditor',\n};\n\nexport function getDefaultWidgetId(\n sdk: Pick<FieldExtensionSDK, 'field' | 'contentType'>\n): WidgetType {\n const field = sdk.field;\n const fieldType = field.type;\n const hasInValidation = (field.validations || []).find((v) => 'in' in v);\n\n if (hasInValidation && DROPDOWN_TYPES.includes(fieldType)) {\n return 'dropdown';\n }\n\n if (fieldType === 'Array') {\n if (field.items?.linkType === 'Asset') {\n return 'assetLinksEditor';\n }\n return 'entryLinksEditor';\n }\n\n if (fieldType === 'Link') {\n // @ts-expect-error\n if (field.linkType === 'Asset') {\n return 'assetLinkEditor';\n }\n return 'entryLinkEditor';\n }\n\n const displayFieldId = sdk.contentType.displayField;\n\n const isTextField = fieldType === 'Text';\n const isDisplayField = field.id === displayFieldId;\n\n if (isTextField && isDisplayField) {\n return 'singleLine';\n }\n\n return DEFAULTS[fieldType];\n}\n","import * as React from 'react';\nimport { NumberEditor } from '@contentful/field-editor-number';\nimport { SingleLineEditor } from '@contentful/field-editor-single-line';\nimport { BooleanEditor } from '@contentful/field-editor-boolean';\nimport { DateEditor } from '@contentful/field-editor-date';\nimport { LocationEditor } from '@contentful/field-editor-location';\nimport { JsonEditor } from '@contentful/field-editor-json';\nimport { MultipleLineEditor } from '@contentful/field-editor-multiple-line';\nimport { TagsEditor } from '@contentful/field-editor-tags';\nimport { SlugEditor } from '@contentful/field-editor-slug';\nimport { DropdownEditor } from '@contentful/field-editor-dropdown';\nimport { UrlEditor } from '@contentful/field-editor-url';\nimport { RadioEditor } from '@contentful/field-editor-radio';\nimport { RatingEditor } from '@contentful/field-editor-rating';\nimport { CheckboxEditor } from '@contentful/field-editor-checkbox';\nimport { ListEditor } from '@contentful/field-editor-list';\nimport {\n SingleEntryReferenceEditor,\n MultipleEntryReferenceEditor,\n SingleMediaEditor,\n MultipleMediaEditor,\n} from '@contentful/field-editor-reference';\nimport { RichTextEditor } from '@contentful/field-editor-rich-text';\nimport { MarkdownEditor } from '@contentful/field-editor-markdown';\nimport type { FieldExtensionSDK } from '@contentful/field-editor-shared';\nimport type { EditorOptions, WidgetType } from './types';\nimport { getDefaultWidgetId } from './getDefaultWidgetId';\n\ntype FieldProps = {\n sdk: FieldExtensionSDK;\n widgetId?: WidgetType;\n isInitiallyDisabled?: boolean;\n renderFieldEditor?: (\n widgetId: WidgetType,\n sdk: FieldExtensionSDK,\n isInitiallyDisabled: boolean\n ) => JSX.Element | false;\n getOptions?: (widgetId: WidgetType, sdk: FieldExtensionSDK) => EditorOptions;\n};\n\nconst widgetComponents: Record<string, [React.ComponentType<any>, any?]> = {\n multipleLine: [MultipleLineEditor],\n boolean: [BooleanEditor],\n objectEditor: [JsonEditor],\n datePicker: [DateEditor],\n locationEditor: [LocationEditor],\n checkbox: [CheckboxEditor],\n listInput: [ListEditor],\n rating: [RatingEditor],\n radio: [RadioEditor],\n tagEditor: [TagsEditor],\n numberEditor: [NumberEditor],\n urlEditor: [UrlEditor],\n slugEditor: [SlugEditor],\n singleLine: [SingleLineEditor],\n dropdown: [DropdownEditor],\n entryLinkEditor: [SingleEntryReferenceEditor, { viewType: 'link', hasCardEditActions: true }],\n entryCardEditor: [SingleEntryReferenceEditor, { viewType: 'card', hasCardEditActions: true }],\n entryLinksEditor: [MultipleEntryReferenceEditor, { viewType: 'link', hasCardEditActions: true }],\n entryCardsEditor: [MultipleEntryReferenceEditor, { viewType: 'card', hasCardEditActions: true }],\n assetLinkEditor: [SingleMediaEditor, { viewType: 'link' }],\n assetLinksEditor: [MultipleMediaEditor, { viewType: 'link' }],\n assetGalleryEditor: [MultipleMediaEditor, { viewType: 'card' }],\n richTextEditor: [RichTextEditor],\n markdown: [MarkdownEditor],\n};\n\nexport const Field: React.FC<FieldProps> = (props: FieldProps) => {\n const {\n sdk,\n widgetId: possiblyUndefinedWidgetId,\n isInitiallyDisabled = false,\n renderFieldEditor,\n getOptions,\n } = props;\n const field = sdk.field;\n const locales = sdk.locales;\n\n const widgetId = possiblyUndefinedWidgetId ?? getDefaultWidgetId(sdk);\n\n if (renderFieldEditor) {\n const customEditor = renderFieldEditor(widgetId, sdk, isInitiallyDisabled);\n if (customEditor) {\n return customEditor;\n }\n }\n\n const options = getOptions ? getOptions(widgetId, sdk) : {};\n const referenceEditorParams =\n sdk.parameters && 'instance' in sdk.parameters\n ? sdk.parameters\n : {\n instance: {\n showCreateEntityAction: true,\n showLinkEntityAction: true,\n },\n };\n\n if (!widgetComponents[widgetId]) return null;\n\n const [WidgetComponent, widgetStaticProps] = widgetComponents[widgetId];\n\n const widgetComponentProps = {\n sdk,\n field,\n locales,\n isInitiallyDisabled,\n parameters: referenceEditorParams,\n ...widgetStaticProps,\n // @ts-expect-error\n ...options[widgetId],\n };\n\n const baseSdk = widgetId === 'slugEditor' ? sdk : undefined;\n\n return <WidgetComponent key={sdk.field.locale} {...widgetComponentProps} baseSdk={baseSdk} />;\n};\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const styles = {\n withFocusBar: css({\n marginLeft: tokens.spacingL,\n marginRight: tokens.spacingL,\n marginBottom: '29px',\n marginTop: '19px',\n paddingLeft: tokens.spacingM,\n borderLeft: `3px solid ${tokens.gray300}`,\n transition: 'border-color 0.18s linear',\n '&:focus-within': {\n borderColor: tokens.colorPrimary,\n },\n '&[aria-invalid=\"true\"]': {\n borderLeftColor: tokens.red500,\n },\n }),\n label: css({\n display: 'flex',\n width: '100%',\n maxWidth: '800px',\n color: tokens.gray500,\n fontSize: tokens.fontSizeM,\n fontWeight: tokens.fontWeightNormal,\n lineHeight: tokens.lineHeightDefault,\n whiteSpace: 'pre-wrap',\n }),\n helpText: css({\n margin: `${tokens.spacingXs} 0`,\n fontStyle: 'italic',\n }),\n};\n","import * as React from 'react';\nimport { cx } from 'emotion';\nimport { FormControl } from '@contentful/f36-components';\nimport { ValidationErrors } from '@contentful/field-editor-validation-errors';\nimport type { FieldExtensionSDK, Entry } from '@contentful/field-editor-shared';\nimport { styles } from './FieldWrapper.styles';\n\ntype FieldWrapperProps = {\n name: string;\n sdk: FieldExtensionSDK;\n /**\n * Generates a link to another entry with the same value when a \"non unique\" validation error occurs\n */\n getEntryURL?: (entry: Entry) => string;\n className?: string;\n showFocusBar?: boolean;\n children: React.ReactNode;\n renderHeading?: (name: string) => JSX.Element | null;\n renderHelpText?: (helpText: string) => JSX.Element | null;\n};\n\nexport const FieldWrapper: React.FC<FieldWrapperProps> = function (props: FieldWrapperProps) {\n const { ids } = props.sdk;\n const defaultGetEntryUrl = (entry: Entry) =>\n `/spaces/${ids.space}/environments/${ids.environmentAlias || ids.environment}/entries/${\n entry.sys.id\n }`;\n const {\n name,\n sdk,\n className,\n children,\n renderHeading,\n renderHelpText,\n showFocusBar = true,\n getEntryURL = defaultGetEntryUrl,\n } = props;\n const { field } = sdk;\n const helpText = (sdk.parameters?.instance as any)?.helpText ?? '';\n\n const [hasErrors, setHasErrors] = React.useState(false);\n React.useEffect(() => {\n return field.onSchemaErrorsChanged((errors: unknown[]) => {\n setHasErrors((errors || []).length > 0);\n });\n }, [field]);\n\n return (\n <FormControl\n testId=\"entity-field-controls\"\n data-test-id=\"entity-field-controls\"\n className={cx(showFocusBar && styles.withFocusBar, className)}\n aria-invalid={hasErrors}\n isRequired={field.required}>\n {renderHeading ? (\n renderHeading(name)\n ) : (\n <FormControl.Label className={styles.label} htmlFor={field.id}>\n {name}\n </FormControl.Label>\n )}\n\n {children}\n\n <ValidationErrors\n field={field}\n space={sdk.space}\n locales={sdk.locales}\n getEntryURL={getEntryURL || defaultGetEntryUrl}\n />\n\n {renderHelpText ? (\n renderHelpText(helpText)\n ) : (\n <FormControl.HelpText testId=\"field-hint\" className={styles.helpText}>\n {helpText}\n </FormControl.HelpText>\n )}\n </FormControl>\n );\n};\n"],"names":["DROPDOWN_TYPES","DEFAULTS","Text","Symbol","Integer","Number","Boolean","Date","Location","Object","RichText","Symbols","File","getDefaultWidgetId","sdk","field","fieldType","type","hasInValidation","validations","find","v","includes","items","linkType","displayFieldId","contentType","displayField","isTextField","isDisplayField","id","widgetComponents","multipleLine","MultipleLineEditor","BooleanEditor","objectEditor","JsonEditor","datePicker","DateEditor","locationEditor","LocationEditor","checkbox","CheckboxEditor","listInput","ListEditor","rating","RatingEditor","radio","RadioEditor","tagEditor","TagsEditor","numberEditor","NumberEditor","urlEditor","UrlEditor","slugEditor","SlugEditor","singleLine","SingleLineEditor","dropdown","DropdownEditor","entryLinkEditor","SingleEntryReferenceEditor","viewType","hasCardEditActions","entryCardEditor","entryLinksEditor","MultipleEntryReferenceEditor","entryCardsEditor","assetLinkEditor","SingleMediaEditor","assetLinksEditor","MultipleMediaEditor","assetGalleryEditor","richTextEditor","RichTextEditor","markdown","MarkdownEditor","Field","props","possiblyUndefinedWidgetId","widgetId","isInitiallyDisabled","renderFieldEditor","getOptions","locales","customEditor","options","referenceEditorParams","parameters","instance","showCreateEntityAction","showLinkEntityAction","WidgetComponent","widgetStaticProps","widgetComponentProps","baseSdk","undefined","React","key","locale","styles","withFocusBar","css","marginLeft","tokens","spacingL","marginRight","marginBottom","marginTop","paddingLeft","spacingM","borderLeft","gray300","transition","borderColor","colorPrimary","borderLeftColor","red500","label","display","width","maxWidth","color","gray500","fontSize","fontSizeM","fontWeight","fontWeightNormal","lineHeight","lineHeightDefault","whiteSpace","helpText","margin","spacingXs","fontStyle","FieldWrapper","ids","defaultGetEntryUrl","entry","space","environmentAlias","environment","sys","name","className","children","renderHeading","renderHelpText","showFocusBar","getEntryURL","hasErrors","setHasErrors","onSchemaErrorsChanged","errors","length","FormControl","testId","cx","isRequired","required","Label","htmlFor","ValidationErrors","HelpText"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAMA,cAAc,GAAG,CAAC,MAAD,EAAS,QAAT,EAAmB,SAAnB,EAA8B,QAA9B,EAAwC,SAAxC,CAAvB;AAEO,IAAMC,QAAQ,GAAkC;AACrDC,EAAAA,IAAI,EAAE,UAD+C;AAErDC,EAAAA,MAAM,EAAE,YAF6C;AAGrDC,EAAAA,OAAO,EAAE,cAH4C;AAIrDC,EAAAA,MAAM,EAAE,cAJ6C;AAKrDC,EAAAA,OAAO,EAAE,SAL4C;AAMrDC,EAAAA,IAAI,EAAE,YAN+C;AAOrDC,EAAAA,QAAQ,EAAE,gBAP2C;AAQrDC,EAAAA,MAAM,EAAE,cAR6C;AASrDC,EAAAA,QAAQ,EAAE,gBAT2C;AAUrDC,EAAAA,OAAO,EAAE,WAV4C;AAWrDC,EAAAA,IAAI,EAAE;AAX+C,CAAhD;SAcSC,mBACdC;AAEA,MAAMC,KAAK,GAAGD,GAAG,CAACC,KAAlB;AACA,MAAMC,SAAS,GAAGD,KAAK,CAACE,IAAxB;AACA,MAAMC,eAAe,GAAG,CAACH,KAAK,CAACI,WAAN,IAAqB,EAAtB,EAA0BC,IAA1B,CAA+B,UAACC,CAAD;AAAA,WAAO,QAAQA,CAAf;AAAA,GAA/B,CAAxB;;AAEA,MAAIH,eAAe,IAAIlB,cAAc,CAACsB,QAAf,CAAwBN,SAAxB,CAAvB,EAA2D;AACzD,WAAO,UAAP;AACD;;AAED,MAAIA,SAAS,KAAK,OAAlB,EAA2B;AAAA;;AACzB,QAAI,iBAAAD,KAA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AAS,EAAEa,UAAE,CAACT,YAAY,IAAIhD,MAAM,CAACC,YAAxB,EAAsC2C,SAAtC;oBACCM;AACdQ,IAAAA,UAAU,EAAEhJ,KAAK,CAACiJ;GALpB,EAMGb,aAAa,GACZA,aAAa,CAACH,IAAD,CADD,GAGZ9C,mBAAA,CAAC0D,yBAAW,CAACK,KAAb;AAAmBhB,IAAAA,SAAS,EAAE5C,MAAM,CAACkB;AAAO2C,IAAAA,OAAO,EAAEnJ,KAAK,CAACe;GAA3D,EACGkH,IADH,CATJ,EAcGE,QAdH,EAgBEhD,mBAAA,CAACiE,4CAAD;AACEpJ,IAAAA,KAAK,EAAEA;AACP6H,IAAAA,KAAK,EAAE9H,GAAG,CAAC8H;AACXvD,IAAAA,OAAO,EAAEvE,GAAG,CAACuE;AACbiE,IAAAA,WAAW,EAAEA,WAAW,IAAIZ;GAJ9B,CAhBF,EAuBGU,cAAc,GACbA,cAAc,CAAChB,QAAD,CADD,GAGblC,mBAAA,CAAC0D,yBAAW,CAACQ,QAAb;AAAsBP,IAAAA,MAAM,EAAC;AAAaZ,IAAAA,SAAS,EAAE5C,MAAM,CAAC+B;GAA5D,EACGA,QADH,CA1BJ,CADF;AAiCD,CA3DM;;;;;;"}
|
|
1
|
+
{"version":3,"file":"default-field-editors.cjs.development.js","sources":["../src/getDefaultWidgetId.ts","../src/Field.tsx","../src/FieldWrapper.styles.ts","../src/FieldWrapper.tsx"],"sourcesContent":["import type { FieldExtensionSDK } from '@contentful/field-editor-shared';\nimport type { WidgetType } from './types';\n\nconst DROPDOWN_TYPES = ['Text', 'Symbol', 'Integer', 'Number', 'Boolean'];\n\nexport const DEFAULTS: { [key: string]: WidgetType } = {\n Text: 'markdown',\n Symbol: 'singleLine',\n Integer: 'numberEditor',\n Number: 'numberEditor',\n Boolean: 'boolean',\n Date: 'datePicker',\n Location: 'locationEditor',\n Object: 'objectEditor',\n RichText: 'richTextEditor',\n Symbols: 'tagEditor',\n File: 'fileEditor',\n};\n\nexport function getDefaultWidgetId(\n sdk: Pick<FieldExtensionSDK, 'field' | 'contentType'>\n): WidgetType {\n const field = sdk.field;\n const fieldType = field.type;\n const hasInValidation = (field.validations || []).find((v) => 'in' in v);\n\n if (hasInValidation && DROPDOWN_TYPES.includes(fieldType)) {\n return 'dropdown';\n }\n\n if (fieldType === 'Array') {\n if (field.items?.linkType === 'Asset') {\n return 'assetLinksEditor';\n }\n return 'entryLinksEditor';\n }\n\n if (fieldType === 'Link') {\n // @ts-expect-error\n if (field.linkType === 'Asset') {\n return 'assetLinkEditor';\n }\n return 'entryLinkEditor';\n }\n\n const displayFieldId = sdk.contentType.displayField;\n\n const isTextField = fieldType === 'Text';\n const isDisplayField = field.id === displayFieldId;\n\n if (isTextField && isDisplayField) {\n return 'singleLine';\n }\n\n return DEFAULTS[fieldType];\n}\n","import * as React from 'react';\nimport { NumberEditor } from '@contentful/field-editor-number';\nimport { SingleLineEditor } from '@contentful/field-editor-single-line';\nimport { BooleanEditor } from '@contentful/field-editor-boolean';\nimport { DateEditor } from '@contentful/field-editor-date';\nimport { LocationEditor } from '@contentful/field-editor-location';\nimport { JsonEditor } from '@contentful/field-editor-json';\nimport { MultipleLineEditor } from '@contentful/field-editor-multiple-line';\nimport { TagsEditor } from '@contentful/field-editor-tags';\nimport { SlugEditor } from '@contentful/field-editor-slug';\nimport { DropdownEditor } from '@contentful/field-editor-dropdown';\nimport { UrlEditor } from '@contentful/field-editor-url';\nimport { RadioEditor } from '@contentful/field-editor-radio';\nimport { RatingEditor } from '@contentful/field-editor-rating';\nimport { CheckboxEditor } from '@contentful/field-editor-checkbox';\nimport { ListEditor } from '@contentful/field-editor-list';\nimport {\n SingleEntryReferenceEditor,\n MultipleEntryReferenceEditor,\n SingleMediaEditor,\n MultipleMediaEditor,\n} from '@contentful/field-editor-reference';\nimport { RichTextEditor } from '@contentful/field-editor-rich-text';\nimport { MarkdownEditor } from '@contentful/field-editor-markdown';\nimport type { FieldExtensionSDK } from '@contentful/field-editor-shared';\nimport type { EditorOptions, WidgetType } from './types';\nimport { getDefaultWidgetId } from './getDefaultWidgetId';\n\ntype FieldProps = {\n sdk: FieldExtensionSDK;\n widgetId?: WidgetType;\n isInitiallyDisabled?: boolean;\n renderFieldEditor?: (\n widgetId: WidgetType,\n sdk: FieldExtensionSDK,\n isInitiallyDisabled: boolean\n ) => JSX.Element | false;\n getOptions?: (widgetId: WidgetType, sdk: FieldExtensionSDK) => EditorOptions;\n};\n\nconst widgetComponents: Record<string, [React.ComponentType<any>, any?]> = {\n multipleLine: [MultipleLineEditor],\n boolean: [BooleanEditor],\n objectEditor: [JsonEditor],\n datePicker: [DateEditor],\n locationEditor: [LocationEditor],\n checkbox: [CheckboxEditor],\n listInput: [ListEditor],\n rating: [RatingEditor],\n radio: [RadioEditor],\n tagEditor: [TagsEditor],\n numberEditor: [NumberEditor],\n urlEditor: [UrlEditor],\n slugEditor: [SlugEditor],\n singleLine: [SingleLineEditor],\n dropdown: [DropdownEditor],\n entryLinkEditor: [SingleEntryReferenceEditor, { viewType: 'link', hasCardEditActions: true }],\n entryCardEditor: [SingleEntryReferenceEditor, { viewType: 'card', hasCardEditActions: true }],\n entryLinksEditor: [MultipleEntryReferenceEditor, { viewType: 'link', hasCardEditActions: true }],\n entryCardsEditor: [MultipleEntryReferenceEditor, { viewType: 'card', hasCardEditActions: true }],\n assetLinkEditor: [SingleMediaEditor, { viewType: 'link' }],\n assetLinksEditor: [MultipleMediaEditor, { viewType: 'link' }],\n assetGalleryEditor: [MultipleMediaEditor, { viewType: 'card' }],\n richTextEditor: [RichTextEditor],\n markdown: [MarkdownEditor],\n};\n\nexport const Field: React.FC<FieldProps> = (props: FieldProps) => {\n const {\n sdk,\n widgetId: possiblyUndefinedWidgetId,\n isInitiallyDisabled = false,\n renderFieldEditor,\n getOptions,\n } = props;\n const field = sdk.field;\n const locales = sdk.locales;\n\n const widgetId = possiblyUndefinedWidgetId ?? getDefaultWidgetId(sdk);\n\n if (renderFieldEditor) {\n const customEditor = renderFieldEditor(widgetId, sdk, isInitiallyDisabled);\n if (customEditor) {\n return customEditor;\n }\n }\n\n const options = getOptions ? getOptions(widgetId, sdk) : {};\n const referenceEditorParams =\n sdk.parameters && 'instance' in sdk.parameters\n ? sdk.parameters\n : {\n instance: {\n showCreateEntityAction: true,\n showLinkEntityAction: true,\n },\n };\n\n if (!widgetComponents[widgetId]) return null;\n\n const [WidgetComponent, widgetStaticProps] = widgetComponents[widgetId];\n\n const widgetComponentProps = {\n sdk,\n field,\n locales,\n isInitiallyDisabled,\n parameters: referenceEditorParams,\n ...widgetStaticProps,\n // @ts-expect-error\n ...options[widgetId],\n };\n\n const baseSdk = widgetId === 'slugEditor' ? sdk : undefined;\n\n return <WidgetComponent key={sdk.field.locale} {...widgetComponentProps} baseSdk={baseSdk} />;\n};\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const styles = {\n withFocusBar: css({\n marginLeft: tokens.spacingL,\n marginRight: tokens.spacingL,\n marginBottom: '29px',\n marginTop: '19px',\n paddingLeft: tokens.spacingM,\n borderLeft: `3px solid ${tokens.gray300}`,\n transition: 'border-color 0.18s linear',\n '&:focus-within': {\n borderColor: tokens.colorPrimary,\n },\n '&[aria-invalid=\"true\"]': {\n borderLeftColor: tokens.red500,\n },\n }),\n label: css({\n display: 'flex',\n width: '100%',\n maxWidth: '800px',\n color: tokens.gray500,\n fontSize: tokens.fontSizeM,\n fontWeight: tokens.fontWeightNormal,\n lineHeight: tokens.lineHeightDefault,\n whiteSpace: 'pre-wrap',\n }),\n helpText: css({\n margin: `${tokens.spacingXs} 0`,\n fontStyle: 'italic',\n }),\n};\n","import * as React from 'react';\nimport { cx } from 'emotion';\nimport { FormControl } from '@contentful/f36-components';\nimport { ValidationErrors } from '@contentful/field-editor-validation-errors';\nimport type { FieldExtensionSDK, Entry } from '@contentful/field-editor-shared';\nimport { styles } from './FieldWrapper.styles';\n\ntype FieldWrapperProps = {\n name: string;\n sdk: FieldExtensionSDK;\n /**\n * Generates a link to another entry with the same value when a \"non unique\" validation error occurs\n */\n getEntryURL?: (entry: Entry) => string;\n className?: string;\n showFocusBar?: boolean;\n children: React.ReactNode;\n renderHeading?: (name: string) => JSX.Element | null;\n renderHelpText?: (helpText: string) => JSX.Element | null;\n};\n\nexport const FieldWrapper: React.FC<FieldWrapperProps> = function (props: FieldWrapperProps) {\n const { ids } = props.sdk;\n const defaultGetEntryUrl = (entry: Entry) =>\n `/spaces/${ids.space}/environments/${ids.environmentAlias || ids.environment}/entries/${\n entry.sys.id\n }`;\n const {\n name,\n sdk,\n className,\n children,\n renderHeading,\n renderHelpText,\n showFocusBar = true,\n getEntryURL = defaultGetEntryUrl,\n } = props;\n const { field } = sdk;\n const helpText = (sdk.parameters?.instance as any)?.helpText ?? '';\n\n const [hasErrors, setHasErrors] = React.useState(false);\n React.useEffect(() => {\n return field.onSchemaErrorsChanged((errors: unknown[]) => {\n setHasErrors((errors || []).length > 0);\n });\n }, [field]);\n\n const fieldControlId = [field.id, field.locale, sdk.contentType?.sys?.id]\n .filter((item) => item)\n .join('-');\n\n return (\n <FormControl\n id={fieldControlId}\n testId=\"entity-field-controls\"\n data-test-id=\"entity-field-controls\"\n className={cx(showFocusBar && styles.withFocusBar, className)}\n aria-invalid={hasErrors}\n isRequired={field.required}>\n {renderHeading ? (\n renderHeading(name)\n ) : (\n <FormControl.Label className={styles.label}>{name}</FormControl.Label>\n )}\n\n {children}\n\n <ValidationErrors\n field={field}\n space={sdk.space}\n locales={sdk.locales}\n getEntryURL={getEntryURL || defaultGetEntryUrl}\n />\n\n {renderHelpText ? (\n renderHelpText(helpText)\n ) : (\n <FormControl.HelpText testId=\"field-hint\" className={styles.helpText}>\n {helpText}\n </FormControl.HelpText>\n )}\n </FormControl>\n );\n};\n"],"names":["DROPDOWN_TYPES","DEFAULTS","Text","Symbol","Integer","Number","Boolean","Date","Location","Object","RichText","Symbols","File","getDefaultWidgetId","sdk","field","fieldType","type","hasInValidation","validations","find","v","includes","items","linkType","displayFieldId","contentType","displayField","isTextField","isDisplayField","id","widgetComponents","multipleLine","MultipleLineEditor","BooleanEditor","objectEditor","JsonEditor","datePicker","DateEditor","locationEditor","LocationEditor","checkbox","CheckboxEditor","listInput","ListEditor","rating","RatingEditor","radio","RadioEditor","tagEditor","TagsEditor","numberEditor","NumberEditor","urlEditor","UrlEditor","slugEditor","SlugEditor","singleLine","SingleLineEditor","dropdown","DropdownEditor","entryLinkEditor","SingleEntryReferenceEditor","viewType","hasCardEditActions","entryCardEditor","entryLinksEditor","MultipleEntryReferenceEditor","entryCardsEditor","assetLinkEditor","SingleMediaEditor","assetLinksEditor","MultipleMediaEditor","assetGalleryEditor","richTextEditor","RichTextEditor","markdown","MarkdownEditor","Field","props","possiblyUndefinedWidgetId","widgetId","isInitiallyDisabled","renderFieldEditor","getOptions","locales","customEditor","options","referenceEditorParams","parameters","instance","showCreateEntityAction","showLinkEntityAction","WidgetComponent","widgetStaticProps","widgetComponentProps","baseSdk","undefined","React","key","locale","styles","withFocusBar","css","marginLeft","tokens","spacingL","marginRight","marginBottom","marginTop","paddingLeft","spacingM","borderLeft","gray300","transition","borderColor","colorPrimary","borderLeftColor","red500","label","display","width","maxWidth","color","gray500","fontSize","fontSizeM","fontWeight","fontWeightNormal","lineHeight","lineHeightDefault","whiteSpace","helpText","margin","spacingXs","fontStyle","FieldWrapper","ids","defaultGetEntryUrl","entry","space","environmentAlias","environment","sys","name","className","children","renderHeading","renderHelpText","showFocusBar","getEntryURL","hasErrors","setHasErrors","onSchemaErrorsChanged","errors","length","fieldControlId","filter","item","join","FormControl","testId","cx","isRequired","required","Label","ValidationErrors","HelpText"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAMA,cAAc,GAAG,CAAC,MAAD,EAAS,QAAT,EAAmB,SAAnB,EAA8B,QAA9B,EAAwC,SAAxC,CAAvB;AAEO,IAAMC,QAAQ,GAAkC;AACrDC,EAAAA,IAAI,EAAE,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,CAACH,IAAD,CADD,GAGZ9C,mBAAA,CAAC8D,yBAAW,CAACK,KAAb;AAAmBpB,IAAAA,SAAS,EAAE5C,MAAM,CAACkB;GAArC,EAA6CyB,IAA7C,CAVJ,EAaGE,QAbH,EAeEhD,mBAAA,CAACoE,4CAAD;AACEvJ,IAAAA,KAAK,EAAEA;AACP6H,IAAAA,KAAK,EAAE9H,GAAG,CAAC8H;AACXvD,IAAAA,OAAO,EAAEvE,GAAG,CAACuE;AACbiE,IAAAA,WAAW,EAAEA,WAAW,IAAIZ;GAJ9B,CAfF,EAsBGU,cAAc,GACbA,cAAc,CAAChB,QAAD,CADD,GAGblC,mBAAA,CAAC8D,yBAAW,CAACO,QAAb;AAAsBN,IAAAA,MAAM,EAAC;AAAahB,IAAAA,SAAS,EAAE5C,MAAM,CAAC+B;GAA5D,EACGA,QADH,CAzBJ,CADF;AAgCD,CA9DM;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),i=require("@contentful/field-editor-number"),r=require("@contentful/field-editor-single-line"),n=require("@contentful/field-editor-boolean"),o=require("@contentful/field-editor-date"),l=require("@contentful/field-editor-location"),d=require("@contentful/field-editor-json"),a=require("@contentful/field-editor-multiple-line"),s=require("@contentful/field-editor-tags"),c=require("@contentful/field-editor-slug"),u=require("@contentful/field-editor-dropdown"),f=require("@contentful/field-editor-url"),E=require("@contentful/field-editor-radio"),p=require("@contentful/field-editor-rating"),g=require("@contentful/field-editor-checkbox"),m=require("@contentful/field-editor-list"),y=require("@contentful/field-editor-reference"),h=require("@contentful/field-editor-rich-text"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),i=require("@contentful/field-editor-number"),r=require("@contentful/field-editor-single-line"),n=require("@contentful/field-editor-boolean"),o=require("@contentful/field-editor-date"),l=require("@contentful/field-editor-location"),d=require("@contentful/field-editor-json"),a=require("@contentful/field-editor-multiple-line"),s=require("@contentful/field-editor-tags"),c=require("@contentful/field-editor-slug"),u=require("@contentful/field-editor-dropdown"),f=require("@contentful/field-editor-url"),E=require("@contentful/field-editor-radio"),p=require("@contentful/field-editor-rating"),g=require("@contentful/field-editor-checkbox"),m=require("@contentful/field-editor-list"),y=require("@contentful/field-editor-reference"),h=require("@contentful/field-editor-rich-text"),v=require("@contentful/field-editor-markdown"),b=require("emotion"),k=require("@contentful/f36-components"),L=require("@contentful/field-editor-validation-errors"),x=(e=require("@contentful/f36-tokens"))&&"object"==typeof e&&"default"in e?e.default:e;function w(){return(w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e[r]=i[r])}return e}).apply(this,arguments)}var q=["Text","Symbol","Integer","Number","Boolean"],T={Text:"markdown",Symbol:"singleLine",Integer:"numberEditor",Number:"numberEditor",Boolean:"boolean",Date:"datePicker",Location:"locationEditor",Object:"objectEditor",RichText:"richTextEditor",Symbols:"tagEditor",File:"fileEditor"};function S(e){var t,i=e.field,r=i.type;return(i.validations||[]).find((function(e){return"in"in e}))&&q.includes(r)?"dropdown":"Array"===r?"Asset"===(null==(t=i.items)?void 0:t.linkType)?"assetLinksEditor":"entryLinksEditor":"Link"===r?"Asset"===i.linkType?"assetLinkEditor":"entryLinkEditor":"Text"===r&&i.id===e.contentType.displayField?"singleLine":T[r]}var C={multipleLine:[a.MultipleLineEditor],boolean:[n.BooleanEditor],objectEditor:[d.JsonEditor],datePicker:[o.DateEditor],locationEditor:[l.LocationEditor],checkbox:[g.CheckboxEditor],listInput:[m.ListEditor],rating:[p.RatingEditor],radio:[E.RadioEditor],tagEditor:[s.TagsEditor],numberEditor:[i.NumberEditor],urlEditor:[f.UrlEditor],slugEditor:[c.SlugEditor],singleLine:[r.SingleLineEditor],dropdown:[u.DropdownEditor],entryLinkEditor:[y.SingleEntryReferenceEditor,{viewType:"link",hasCardEditActions:!0}],entryCardEditor:[y.SingleEntryReferenceEditor,{viewType:"card",hasCardEditActions:!0}],entryLinksEditor:[y.MultipleEntryReferenceEditor,{viewType:"link",hasCardEditActions:!0}],entryCardsEditor:[y.MultipleEntryReferenceEditor,{viewType:"card",hasCardEditActions:!0}],assetLinkEditor:[y.SingleMediaEditor,{viewType:"link"}],assetLinksEditor:[y.MultipleMediaEditor,{viewType:"link"}],assetGalleryEditor:[y.MultipleMediaEditor,{viewType:"card"}],richTextEditor:[h.RichTextEditor],markdown:[v.MarkdownEditor]},M={withFocusBar:b.css({marginLeft:x.spacingL,marginRight:x.spacingL,marginBottom:"29px",marginTop:"19px",paddingLeft:x.spacingM,borderLeft:"3px solid "+x.gray300,transition:"border-color 0.18s linear","&:focus-within":{borderColor:x.colorPrimary},'&[aria-invalid="true"]':{borderLeftColor:x.red500}}),label:b.css({display:"flex",width:"100%",maxWidth:"800px",color:x.gray500,fontSize:x.fontSizeM,fontWeight:x.fontWeightNormal,lineHeight:x.lineHeightDefault,whiteSpace:"pre-wrap"}),helpText:b.css({margin:x.spacingXs+" 0",fontStyle:"italic"})};exports.Field=function(e){var i=e.sdk,r=e.widgetId,n=e.isInitiallyDisabled,o=void 0!==n&&n,l=e.renderFieldEditor,d=e.getOptions,a=i.field,s=i.locales,c=null!=r?r:S(i);if(l){var u=l(c,i,o);if(u)return u}var f=d?d(c,i):{};if(!C[c])return null;var E=C[c],p=E[0],g=w({sdk:i,field:a,locales:s,isInitiallyDisabled:o,parameters:i.parameters&&"instance"in i.parameters?i.parameters:{instance:{showCreateEntityAction:!0,showLinkEntityAction:!0}}},E[1],f[c]);return t.createElement(p,Object.assign({key:i.field.locale},g,{baseSdk:"slugEditor"===c?i:void 0}))},exports.FieldWrapper=function(e){var i,r,n,o,l,d=e.sdk.ids,a=function(e){return"/spaces/"+d.space+"/environments/"+(d.environmentAlias||d.environment)+"/entries/"+e.sys.id},s=e.name,c=e.sdk,u=e.className,f=e.children,E=e.renderHeading,p=e.renderHelpText,g=e.showFocusBar,m=void 0===g||g,y=e.getEntryURL,h=void 0===y?a:y,v=c.field,x=null!=(i=null==(r=c.parameters)||null==(n=r.instance)?void 0:n.helpText)?i:"",w=t.useState(!1),q=w[0],T=w[1];t.useEffect((function(){return v.onSchemaErrorsChanged((function(e){T((e||[]).length>0)}))}),[v]);var S=[v.id,v.locale,null==(o=c.contentType)||null==(l=o.sys)?void 0:l.id].filter((function(e){return e})).join("-");return t.createElement(k.FormControl,{id:S,testId:"entity-field-controls","data-test-id":"entity-field-controls",className:b.cx(m&&M.withFocusBar,u),"aria-invalid":q,isRequired:v.required},E?E(s):t.createElement(k.FormControl.Label,{className:M.label},s),f,t.createElement(L.ValidationErrors,{field:v,space:c.space,locales:c.locales,getEntryURL:h||a}),p?p(x):t.createElement(k.FormControl.HelpText,{testId:"field-hint",className:M.helpText},x))},exports.getDefaultWidgetId=S;
|
|
2
2
|
//# sourceMappingURL=default-field-editors.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-field-editors.cjs.production.min.js","sources":["../src/getDefaultWidgetId.ts","../src/Field.tsx","../src/FieldWrapper.styles.ts","../src/FieldWrapper.tsx"],"sourcesContent":["import type { FieldExtensionSDK } from '@contentful/field-editor-shared';\nimport type { WidgetType } from './types';\n\nconst DROPDOWN_TYPES = ['Text', 'Symbol', 'Integer', 'Number', 'Boolean'];\n\nexport const DEFAULTS: { [key: string]: WidgetType } = {\n Text: 'markdown',\n Symbol: 'singleLine',\n Integer: 'numberEditor',\n Number: 'numberEditor',\n Boolean: 'boolean',\n Date: 'datePicker',\n Location: 'locationEditor',\n Object: 'objectEditor',\n RichText: 'richTextEditor',\n Symbols: 'tagEditor',\n File: 'fileEditor',\n};\n\nexport function getDefaultWidgetId(\n sdk: Pick<FieldExtensionSDK, 'field' | 'contentType'>\n): WidgetType {\n const field = sdk.field;\n const fieldType = field.type;\n const hasInValidation = (field.validations || []).find((v) => 'in' in v);\n\n if (hasInValidation && DROPDOWN_TYPES.includes(fieldType)) {\n return 'dropdown';\n }\n\n if (fieldType === 'Array') {\n if (field.items?.linkType === 'Asset') {\n return 'assetLinksEditor';\n }\n return 'entryLinksEditor';\n }\n\n if (fieldType === 'Link') {\n // @ts-expect-error\n if (field.linkType === 'Asset') {\n return 'assetLinkEditor';\n }\n return 'entryLinkEditor';\n }\n\n const displayFieldId = sdk.contentType.displayField;\n\n const isTextField = fieldType === 'Text';\n const isDisplayField = field.id === displayFieldId;\n\n if (isTextField && isDisplayField) {\n return 'singleLine';\n }\n\n return DEFAULTS[fieldType];\n}\n","import * as React from 'react';\nimport { NumberEditor } from '@contentful/field-editor-number';\nimport { SingleLineEditor } from '@contentful/field-editor-single-line';\nimport { BooleanEditor } from '@contentful/field-editor-boolean';\nimport { DateEditor } from '@contentful/field-editor-date';\nimport { LocationEditor } from '@contentful/field-editor-location';\nimport { JsonEditor } from '@contentful/field-editor-json';\nimport { MultipleLineEditor } from '@contentful/field-editor-multiple-line';\nimport { TagsEditor } from '@contentful/field-editor-tags';\nimport { SlugEditor } from '@contentful/field-editor-slug';\nimport { DropdownEditor } from '@contentful/field-editor-dropdown';\nimport { UrlEditor } from '@contentful/field-editor-url';\nimport { RadioEditor } from '@contentful/field-editor-radio';\nimport { RatingEditor } from '@contentful/field-editor-rating';\nimport { CheckboxEditor } from '@contentful/field-editor-checkbox';\nimport { ListEditor } from '@contentful/field-editor-list';\nimport {\n SingleEntryReferenceEditor,\n MultipleEntryReferenceEditor,\n SingleMediaEditor,\n MultipleMediaEditor,\n} from '@contentful/field-editor-reference';\nimport { RichTextEditor } from '@contentful/field-editor-rich-text';\nimport { MarkdownEditor } from '@contentful/field-editor-markdown';\nimport type { FieldExtensionSDK } from '@contentful/field-editor-shared';\nimport type { EditorOptions, WidgetType } from './types';\nimport { getDefaultWidgetId } from './getDefaultWidgetId';\n\ntype FieldProps = {\n sdk: FieldExtensionSDK;\n widgetId?: WidgetType;\n isInitiallyDisabled?: boolean;\n renderFieldEditor?: (\n widgetId: WidgetType,\n sdk: FieldExtensionSDK,\n isInitiallyDisabled: boolean\n ) => JSX.Element | false;\n getOptions?: (widgetId: WidgetType, sdk: FieldExtensionSDK) => EditorOptions;\n};\n\nconst widgetComponents: Record<string, [React.ComponentType<any>, any?]> = {\n multipleLine: [MultipleLineEditor],\n boolean: [BooleanEditor],\n objectEditor: [JsonEditor],\n datePicker: [DateEditor],\n locationEditor: [LocationEditor],\n checkbox: [CheckboxEditor],\n listInput: [ListEditor],\n rating: [RatingEditor],\n radio: [RadioEditor],\n tagEditor: [TagsEditor],\n numberEditor: [NumberEditor],\n urlEditor: [UrlEditor],\n slugEditor: [SlugEditor],\n singleLine: [SingleLineEditor],\n dropdown: [DropdownEditor],\n entryLinkEditor: [SingleEntryReferenceEditor, { viewType: 'link', hasCardEditActions: true }],\n entryCardEditor: [SingleEntryReferenceEditor, { viewType: 'card', hasCardEditActions: true }],\n entryLinksEditor: [MultipleEntryReferenceEditor, { viewType: 'link', hasCardEditActions: true }],\n entryCardsEditor: [MultipleEntryReferenceEditor, { viewType: 'card', hasCardEditActions: true }],\n assetLinkEditor: [SingleMediaEditor, { viewType: 'link' }],\n assetLinksEditor: [MultipleMediaEditor, { viewType: 'link' }],\n assetGalleryEditor: [MultipleMediaEditor, { viewType: 'card' }],\n richTextEditor: [RichTextEditor],\n markdown: [MarkdownEditor],\n};\n\nexport const Field: React.FC<FieldProps> = (props: FieldProps) => {\n const {\n sdk,\n widgetId: possiblyUndefinedWidgetId,\n isInitiallyDisabled = false,\n renderFieldEditor,\n getOptions,\n } = props;\n const field = sdk.field;\n const locales = sdk.locales;\n\n const widgetId = possiblyUndefinedWidgetId ?? getDefaultWidgetId(sdk);\n\n if (renderFieldEditor) {\n const customEditor = renderFieldEditor(widgetId, sdk, isInitiallyDisabled);\n if (customEditor) {\n return customEditor;\n }\n }\n\n const options = getOptions ? getOptions(widgetId, sdk) : {};\n const referenceEditorParams =\n sdk.parameters && 'instance' in sdk.parameters\n ? sdk.parameters\n : {\n instance: {\n showCreateEntityAction: true,\n showLinkEntityAction: true,\n },\n };\n\n if (!widgetComponents[widgetId]) return null;\n\n const [WidgetComponent, widgetStaticProps] = widgetComponents[widgetId];\n\n const widgetComponentProps = {\n sdk,\n field,\n locales,\n isInitiallyDisabled,\n parameters: referenceEditorParams,\n ...widgetStaticProps,\n // @ts-expect-error\n ...options[widgetId],\n };\n\n const baseSdk = widgetId === 'slugEditor' ? sdk : undefined;\n\n return <WidgetComponent key={sdk.field.locale} {...widgetComponentProps} baseSdk={baseSdk} />;\n};\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const styles = {\n withFocusBar: css({\n marginLeft: tokens.spacingL,\n marginRight: tokens.spacingL,\n marginBottom: '29px',\n marginTop: '19px',\n paddingLeft: tokens.spacingM,\n borderLeft: `3px solid ${tokens.gray300}`,\n transition: 'border-color 0.18s linear',\n '&:focus-within': {\n borderColor: tokens.colorPrimary,\n },\n '&[aria-invalid=\"true\"]': {\n borderLeftColor: tokens.red500,\n },\n }),\n label: css({\n display: 'flex',\n width: '100%',\n maxWidth: '800px',\n color: tokens.gray500,\n fontSize: tokens.fontSizeM,\n fontWeight: tokens.fontWeightNormal,\n lineHeight: tokens.lineHeightDefault,\n whiteSpace: 'pre-wrap',\n }),\n helpText: css({\n margin: `${tokens.spacingXs} 0`,\n fontStyle: 'italic',\n }),\n};\n","import * as React from 'react';\nimport { cx } from 'emotion';\nimport { FormControl } from '@contentful/f36-components';\nimport { ValidationErrors } from '@contentful/field-editor-validation-errors';\nimport type { FieldExtensionSDK, Entry } from '@contentful/field-editor-shared';\nimport { styles } from './FieldWrapper.styles';\n\ntype FieldWrapperProps = {\n name: string;\n sdk: FieldExtensionSDK;\n /**\n * Generates a link to another entry with the same value when a \"non unique\" validation error occurs\n */\n getEntryURL?: (entry: Entry) => string;\n className?: string;\n showFocusBar?: boolean;\n children: React.ReactNode;\n renderHeading?: (name: string) => JSX.Element | null;\n renderHelpText?: (helpText: string) => JSX.Element | null;\n};\n\nexport const FieldWrapper: React.FC<FieldWrapperProps> = function (props: FieldWrapperProps) {\n const { ids } = props.sdk;\n const defaultGetEntryUrl = (entry: Entry) =>\n `/spaces/${ids.space}/environments/${ids.environmentAlias || ids.environment}/entries/${\n entry.sys.id\n }`;\n const {\n name,\n sdk,\n className,\n children,\n renderHeading,\n renderHelpText,\n showFocusBar = true,\n getEntryURL = defaultGetEntryUrl,\n } = props;\n const { field } = sdk;\n const helpText = (sdk.parameters?.instance as any)?.helpText ?? '';\n\n const [hasErrors, setHasErrors] = React.useState(false);\n React.useEffect(() => {\n return field.onSchemaErrorsChanged((errors: unknown[]) => {\n setHasErrors((errors || []).length > 0);\n });\n }, [field]);\n\n return (\n <FormControl\n testId=\"entity-field-controls\"\n data-test-id=\"entity-field-controls\"\n className={cx(showFocusBar && styles.withFocusBar, className)}\n aria-invalid={hasErrors}\n isRequired={field.required}>\n {renderHeading ? (\n renderHeading(name)\n ) : (\n <FormControl.Label className={styles.label} htmlFor={field.id}>\n {name}\n </FormControl.Label>\n )}\n\n {children}\n\n <ValidationErrors\n field={field}\n space={sdk.space}\n locales={sdk.locales}\n getEntryURL={getEntryURL || defaultGetEntryUrl}\n />\n\n {renderHelpText ? (\n renderHelpText(helpText)\n ) : (\n <FormControl.HelpText testId=\"field-hint\" className={styles.helpText}>\n {helpText}\n </FormControl.HelpText>\n )}\n </FormControl>\n );\n};\n"],"names":["DROPDOWN_TYPES","DEFAULTS","Text","Symbol","Integer","Number","Boolean","Date","Location","Object","RichText","Symbols","File","getDefaultWidgetId","sdk","field","fieldType","type","validations","find","v","includes","items","linkType","id","contentType","displayField","widgetComponents","multipleLine","MultipleLineEditor","BooleanEditor","objectEditor","JsonEditor","datePicker","DateEditor","locationEditor","LocationEditor","checkbox","CheckboxEditor","listInput","ListEditor","rating","RatingEditor","radio","RadioEditor","tagEditor","TagsEditor","numberEditor","NumberEditor","urlEditor","UrlEditor","slugEditor","SlugEditor","singleLine","SingleLineEditor","dropdown","DropdownEditor","entryLinkEditor","SingleEntryReferenceEditor","viewType","hasCardEditActions","entryCardEditor","entryLinksEditor","MultipleEntryReferenceEditor","entryCardsEditor","assetLinkEditor","SingleMediaEditor","assetLinksEditor","MultipleMediaEditor","assetGalleryEditor","richTextEditor","RichTextEditor","markdown","MarkdownEditor","styles","withFocusBar","css","marginLeft","tokens","spacingL","marginRight","marginBottom","marginTop","paddingLeft","spacingM","borderLeft","gray300","transition","borderColor","colorPrimary","borderLeftColor","red500","label","display","width","maxWidth","color","gray500","fontSize","fontSizeM","fontWeight","fontWeightNormal","lineHeight","lineHeightDefault","whiteSpace","helpText","margin","spacingXs","fontStyle","props","possiblyUndefinedWidgetId","widgetId","isInitiallyDisabled","renderFieldEditor","getOptions","locales","customEditor","options","WidgetComponent","widgetComponentProps","parameters","instance","showCreateEntityAction","showLinkEntityAction","React","key","locale","baseSdk","undefined","ids","defaultGetEntryUrl","entry","space","environmentAlias","environment","sys","name","className","children","renderHeading","renderHelpText","showFocusBar","getEntryURL","_sdk$parameters","_sdk$parameters$insta2","hasErrors","setHasErrors","onSchemaErrorsChanged","errors","length","FormControl","testId","cx","isRequired","required","Label","htmlFor","ValidationErrors","HelpText"],"mappings":"+yCAGA,IAAMA,EAAiB,CAAC,OAAQ,SAAU,UAAW,SAAU,WAElDC,EAA0C,CACrDC,KAAM,WACNC,OAAQ,aACRC,QAAS,eACTC,OAAQ,eACRC,QAAS,UACTC,KAAM,aACNC,SAAU,iBACVC,OAAQ,eACRC,SAAU,iBACVC,QAAS,YACTC,KAAM,uBAGQC,EACdC,SAEMC,EAAQD,EAAIC,MACZC,EAAYD,EAAME,YACCF,EAAMG,aAAe,IAAIC,MAAK,SAACC,SAAM,OAAQA,MAE/CpB,EAAeqB,SAASL,GACtC,WAGS,UAAdA,EAC4B,oBAA1BD,EAAMO,gBAAOC,UACR,mBAEF,mBAGS,SAAdP,EAEqB,UAAnBD,EAAMQ,SACD,kBAEF,kBAKyB,SAAdP,GACGD,EAAMS,KAHNV,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BACbd,UAAWe,KAAGX,GAAgBnE,EAAOC,aAAc8D,kBACrCQ,EACdQ,WAAY1I,EAAM2I,UACjBf,EACCA,EAAcH,GAEdZ,gBAAC0B,cAAYK,OAAMlB,UAAW/D,EAAOkB,MAAOgE,QAAS7I,EAAMS,IACxDgH,GAIJE,EAEDd,gBAACiC,oBACC9I,MAAOA,EACPqH,MAAOtH,EAAIsH,MACXjB,QAASrG,EAAIqG,QACb2B,YAAaA,GAAeZ,IAG7BU,EACCA,EAAenC,GAEfmB,gBAAC0B,cAAYQ,UAASP,OAAO,aAAad,UAAW/D,EAAO+B,UACzDA"}
|
|
1
|
+
{"version":3,"file":"default-field-editors.cjs.production.min.js","sources":["../src/getDefaultWidgetId.ts","../src/Field.tsx","../src/FieldWrapper.styles.ts","../src/FieldWrapper.tsx"],"sourcesContent":["import type { FieldExtensionSDK } from '@contentful/field-editor-shared';\nimport type { WidgetType } from './types';\n\nconst DROPDOWN_TYPES = ['Text', 'Symbol', 'Integer', 'Number', 'Boolean'];\n\nexport const DEFAULTS: { [key: string]: WidgetType } = {\n Text: 'markdown',\n Symbol: 'singleLine',\n Integer: 'numberEditor',\n Number: 'numberEditor',\n Boolean: 'boolean',\n Date: 'datePicker',\n Location: 'locationEditor',\n Object: 'objectEditor',\n RichText: 'richTextEditor',\n Symbols: 'tagEditor',\n File: 'fileEditor',\n};\n\nexport function getDefaultWidgetId(\n sdk: Pick<FieldExtensionSDK, 'field' | 'contentType'>\n): WidgetType {\n const field = sdk.field;\n const fieldType = field.type;\n const hasInValidation = (field.validations || []).find((v) => 'in' in v);\n\n if (hasInValidation && DROPDOWN_TYPES.includes(fieldType)) {\n return 'dropdown';\n }\n\n if (fieldType === 'Array') {\n if (field.items?.linkType === 'Asset') {\n return 'assetLinksEditor';\n }\n return 'entryLinksEditor';\n }\n\n if (fieldType === 'Link') {\n // @ts-expect-error\n if (field.linkType === 'Asset') {\n return 'assetLinkEditor';\n }\n return 'entryLinkEditor';\n }\n\n const displayFieldId = sdk.contentType.displayField;\n\n const isTextField = fieldType === 'Text';\n const isDisplayField = field.id === displayFieldId;\n\n if (isTextField && isDisplayField) {\n return 'singleLine';\n }\n\n return DEFAULTS[fieldType];\n}\n","import * as React from 'react';\nimport { NumberEditor } from '@contentful/field-editor-number';\nimport { SingleLineEditor } from '@contentful/field-editor-single-line';\nimport { BooleanEditor } from '@contentful/field-editor-boolean';\nimport { DateEditor } from '@contentful/field-editor-date';\nimport { LocationEditor } from '@contentful/field-editor-location';\nimport { JsonEditor } from '@contentful/field-editor-json';\nimport { MultipleLineEditor } from '@contentful/field-editor-multiple-line';\nimport { TagsEditor } from '@contentful/field-editor-tags';\nimport { SlugEditor } from '@contentful/field-editor-slug';\nimport { DropdownEditor } from '@contentful/field-editor-dropdown';\nimport { UrlEditor } from '@contentful/field-editor-url';\nimport { RadioEditor } from '@contentful/field-editor-radio';\nimport { RatingEditor } from '@contentful/field-editor-rating';\nimport { CheckboxEditor } from '@contentful/field-editor-checkbox';\nimport { ListEditor } from '@contentful/field-editor-list';\nimport {\n SingleEntryReferenceEditor,\n MultipleEntryReferenceEditor,\n SingleMediaEditor,\n MultipleMediaEditor,\n} from '@contentful/field-editor-reference';\nimport { RichTextEditor } from '@contentful/field-editor-rich-text';\nimport { MarkdownEditor } from '@contentful/field-editor-markdown';\nimport type { FieldExtensionSDK } from '@contentful/field-editor-shared';\nimport type { EditorOptions, WidgetType } from './types';\nimport { getDefaultWidgetId } from './getDefaultWidgetId';\n\ntype FieldProps = {\n sdk: FieldExtensionSDK;\n widgetId?: WidgetType;\n isInitiallyDisabled?: boolean;\n renderFieldEditor?: (\n widgetId: WidgetType,\n sdk: FieldExtensionSDK,\n isInitiallyDisabled: boolean\n ) => JSX.Element | false;\n getOptions?: (widgetId: WidgetType, sdk: FieldExtensionSDK) => EditorOptions;\n};\n\nconst widgetComponents: Record<string, [React.ComponentType<any>, any?]> = {\n multipleLine: [MultipleLineEditor],\n boolean: [BooleanEditor],\n objectEditor: [JsonEditor],\n datePicker: [DateEditor],\n locationEditor: [LocationEditor],\n checkbox: [CheckboxEditor],\n listInput: [ListEditor],\n rating: [RatingEditor],\n radio: [RadioEditor],\n tagEditor: [TagsEditor],\n numberEditor: [NumberEditor],\n urlEditor: [UrlEditor],\n slugEditor: [SlugEditor],\n singleLine: [SingleLineEditor],\n dropdown: [DropdownEditor],\n entryLinkEditor: [SingleEntryReferenceEditor, { viewType: 'link', hasCardEditActions: true }],\n entryCardEditor: [SingleEntryReferenceEditor, { viewType: 'card', hasCardEditActions: true }],\n entryLinksEditor: [MultipleEntryReferenceEditor, { viewType: 'link', hasCardEditActions: true }],\n entryCardsEditor: [MultipleEntryReferenceEditor, { viewType: 'card', hasCardEditActions: true }],\n assetLinkEditor: [SingleMediaEditor, { viewType: 'link' }],\n assetLinksEditor: [MultipleMediaEditor, { viewType: 'link' }],\n assetGalleryEditor: [MultipleMediaEditor, { viewType: 'card' }],\n richTextEditor: [RichTextEditor],\n markdown: [MarkdownEditor],\n};\n\nexport const Field: React.FC<FieldProps> = (props: FieldProps) => {\n const {\n sdk,\n widgetId: possiblyUndefinedWidgetId,\n isInitiallyDisabled = false,\n renderFieldEditor,\n getOptions,\n } = props;\n const field = sdk.field;\n const locales = sdk.locales;\n\n const widgetId = possiblyUndefinedWidgetId ?? getDefaultWidgetId(sdk);\n\n if (renderFieldEditor) {\n const customEditor = renderFieldEditor(widgetId, sdk, isInitiallyDisabled);\n if (customEditor) {\n return customEditor;\n }\n }\n\n const options = getOptions ? getOptions(widgetId, sdk) : {};\n const referenceEditorParams =\n sdk.parameters && 'instance' in sdk.parameters\n ? sdk.parameters\n : {\n instance: {\n showCreateEntityAction: true,\n showLinkEntityAction: true,\n },\n };\n\n if (!widgetComponents[widgetId]) return null;\n\n const [WidgetComponent, widgetStaticProps] = widgetComponents[widgetId];\n\n const widgetComponentProps = {\n sdk,\n field,\n locales,\n isInitiallyDisabled,\n parameters: referenceEditorParams,\n ...widgetStaticProps,\n // @ts-expect-error\n ...options[widgetId],\n };\n\n const baseSdk = widgetId === 'slugEditor' ? sdk : undefined;\n\n return <WidgetComponent key={sdk.field.locale} {...widgetComponentProps} baseSdk={baseSdk} />;\n};\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const styles = {\n withFocusBar: css({\n marginLeft: tokens.spacingL,\n marginRight: tokens.spacingL,\n marginBottom: '29px',\n marginTop: '19px',\n paddingLeft: tokens.spacingM,\n borderLeft: `3px solid ${tokens.gray300}`,\n transition: 'border-color 0.18s linear',\n '&:focus-within': {\n borderColor: tokens.colorPrimary,\n },\n '&[aria-invalid=\"true\"]': {\n borderLeftColor: tokens.red500,\n },\n }),\n label: css({\n display: 'flex',\n width: '100%',\n maxWidth: '800px',\n color: tokens.gray500,\n fontSize: tokens.fontSizeM,\n fontWeight: tokens.fontWeightNormal,\n lineHeight: tokens.lineHeightDefault,\n whiteSpace: 'pre-wrap',\n }),\n helpText: css({\n margin: `${tokens.spacingXs} 0`,\n fontStyle: 'italic',\n }),\n};\n","import * as React from 'react';\nimport { cx } from 'emotion';\nimport { FormControl } from '@contentful/f36-components';\nimport { ValidationErrors } from '@contentful/field-editor-validation-errors';\nimport type { FieldExtensionSDK, Entry } from '@contentful/field-editor-shared';\nimport { styles } from './FieldWrapper.styles';\n\ntype FieldWrapperProps = {\n name: string;\n sdk: FieldExtensionSDK;\n /**\n * Generates a link to another entry with the same value when a \"non unique\" validation error occurs\n */\n getEntryURL?: (entry: Entry) => string;\n className?: string;\n showFocusBar?: boolean;\n children: React.ReactNode;\n renderHeading?: (name: string) => JSX.Element | null;\n renderHelpText?: (helpText: string) => JSX.Element | null;\n};\n\nexport const FieldWrapper: React.FC<FieldWrapperProps> = function (props: FieldWrapperProps) {\n const { ids } = props.sdk;\n const defaultGetEntryUrl = (entry: Entry) =>\n `/spaces/${ids.space}/environments/${ids.environmentAlias || ids.environment}/entries/${\n entry.sys.id\n }`;\n const {\n name,\n sdk,\n className,\n children,\n renderHeading,\n renderHelpText,\n showFocusBar = true,\n getEntryURL = defaultGetEntryUrl,\n } = props;\n const { field } = sdk;\n const helpText = (sdk.parameters?.instance as any)?.helpText ?? '';\n\n const [hasErrors, setHasErrors] = React.useState(false);\n React.useEffect(() => {\n return field.onSchemaErrorsChanged((errors: unknown[]) => {\n setHasErrors((errors || []).length > 0);\n });\n }, [field]);\n\n const fieldControlId = [field.id, field.locale, sdk.contentType?.sys?.id]\n .filter((item) => item)\n .join('-');\n\n return (\n <FormControl\n id={fieldControlId}\n testId=\"entity-field-controls\"\n data-test-id=\"entity-field-controls\"\n className={cx(showFocusBar && styles.withFocusBar, className)}\n aria-invalid={hasErrors}\n isRequired={field.required}>\n {renderHeading ? (\n renderHeading(name)\n ) : (\n <FormControl.Label className={styles.label}>{name}</FormControl.Label>\n )}\n\n {children}\n\n <ValidationErrors\n field={field}\n space={sdk.space}\n locales={sdk.locales}\n getEntryURL={getEntryURL || defaultGetEntryUrl}\n />\n\n {renderHelpText ? (\n renderHelpText(helpText)\n ) : (\n <FormControl.HelpText testId=\"field-hint\" className={styles.helpText}>\n {helpText}\n </FormControl.HelpText>\n )}\n </FormControl>\n );\n};\n"],"names":["DROPDOWN_TYPES","DEFAULTS","Text","Symbol","Integer","Number","Boolean","Date","Location","Object","RichText","Symbols","File","getDefaultWidgetId","sdk","field","fieldType","type","validations","find","v","includes","items","linkType","id","contentType","displayField","widgetComponents","multipleLine","MultipleLineEditor","BooleanEditor","objectEditor","JsonEditor","datePicker","DateEditor","locationEditor","LocationEditor","checkbox","CheckboxEditor","listInput","ListEditor","rating","RatingEditor","radio","RadioEditor","tagEditor","TagsEditor","numberEditor","NumberEditor","urlEditor","UrlEditor","slugEditor","SlugEditor","singleLine","SingleLineEditor","dropdown","DropdownEditor","entryLinkEditor","SingleEntryReferenceEditor","viewType","hasCardEditActions","entryCardEditor","entryLinksEditor","MultipleEntryReferenceEditor","entryCardsEditor","assetLinkEditor","SingleMediaEditor","assetLinksEditor","MultipleMediaEditor","assetGalleryEditor","richTextEditor","RichTextEditor","markdown","MarkdownEditor","styles","withFocusBar","css","marginLeft","tokens","spacingL","marginRight","marginBottom","marginTop","paddingLeft","spacingM","borderLeft","gray300","transition","borderColor","colorPrimary","borderLeftColor","red500","label","display","width","maxWidth","color","gray500","fontSize","fontSizeM","fontWeight","fontWeightNormal","lineHeight","lineHeightDefault","whiteSpace","helpText","margin","spacingXs","fontStyle","props","possiblyUndefinedWidgetId","widgetId","isInitiallyDisabled","renderFieldEditor","getOptions","locales","customEditor","options","WidgetComponent","widgetComponentProps","parameters","instance","showCreateEntityAction","showLinkEntityAction","React","key","locale","baseSdk","undefined","ids","defaultGetEntryUrl","entry","space","environmentAlias","environment","sys","name","className","children","renderHeading","renderHelpText","showFocusBar","getEntryURL","_sdk$parameters","_sdk$parameters$insta2","hasErrors","setHasErrors","onSchemaErrorsChanged","errors","length","fieldControlId","_sdk$contentType","_sdk$contentType$sys","filter","item","join","FormControl","testId","cx","isRequired","required","Label","ValidationErrors","HelpText"],"mappings":"+yCAGA,IAAMA,EAAiB,CAAC,OAAQ,SAAU,UAAW,SAAU,WAElDC,EAA0C,CACrDC,KAAM,WACNC,OAAQ,aACRC,QAAS,eACTC,OAAQ,eACRC,QAAS,UACTC,KAAM,aACNC,SAAU,iBACVC,OAAQ,eACRC,SAAU,iBACVC,QAAS,YACTC,KAAM,uBAGQC,EACdC,SAEMC,EAAQD,EAAIC,MACZC,EAAYD,EAAME,YACCF,EAAMG,aAAe,IAAIC,MAAK,SAACC,SAAM,OAAQA,MAE/CpB,EAAeqB,SAASL,GACtC,WAGS,UAAdA,EAC4B,oBAA1BD,EAAMO,gBAAOC,UACR,mBAEF,mBAGS,SAAdP,EAEqB,UAAnBD,EAAMQ,SACD,kBAEF,kBAKyB,SAAdP,GACGD,EAAMS,KAHNV,EAAIW,YAAYC,aAM9B,aAGFzB,EAASe,GCdlB,IAAMW,EAAqE,CACzEC,aAAc,CAACC,8BACN,CAACC,iBACVC,aAAc,CAACC,cACfC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,gBAACgC,eACCpI,GAAI8H,EACJO,OAAO,uCACM,wBACbpB,UAAWqB,KAAGjB,GAAgBnE,EAAOC,aAAc8D,kBACrCQ,EACdc,WAAYhJ,EAAMiJ,UACjBrB,EACCA,EAAcH,GAEdZ,gBAACgC,cAAYK,OAAMxB,UAAW/D,EAAOkB,OAAQ4C,GAG9CE,EAEDd,gBAACsC,oBACCnJ,MAAOA,EACPqH,MAAOtH,EAAIsH,MACXjB,QAASrG,EAAIqG,QACb2B,YAAaA,GAAeZ,IAG7BU,EACCA,EAAenC,GAEfmB,gBAACgC,cAAYO,UAASN,OAAO,aAAapB,UAAW/D,EAAO+B,UACzDA"}
|
|
@@ -219,7 +219,7 @@ var styles = {
|
|
|
219
219
|
};
|
|
220
220
|
|
|
221
221
|
var FieldWrapper = function FieldWrapper(props) {
|
|
222
|
-
var _sdk$parameters$insta, _sdk$parameters, _sdk$parameters$insta2;
|
|
222
|
+
var _sdk$parameters$insta, _sdk$parameters, _sdk$parameters$insta2, _sdk$contentType, _sdk$contentType$sys;
|
|
223
223
|
|
|
224
224
|
var ids = props.sdk.ids;
|
|
225
225
|
|
|
@@ -249,15 +249,18 @@ var FieldWrapper = function FieldWrapper(props) {
|
|
|
249
249
|
setHasErrors((errors || []).length > 0);
|
|
250
250
|
});
|
|
251
251
|
}, [field]);
|
|
252
|
+
var fieldControlId = [field.id, field.locale, (_sdk$contentType = sdk.contentType) == null ? void 0 : (_sdk$contentType$sys = _sdk$contentType.sys) == null ? void 0 : _sdk$contentType$sys.id].filter(function (item) {
|
|
253
|
+
return item;
|
|
254
|
+
}).join('-');
|
|
252
255
|
return createElement(FormControl, {
|
|
256
|
+
id: fieldControlId,
|
|
253
257
|
testId: "entity-field-controls",
|
|
254
258
|
"data-test-id": "entity-field-controls",
|
|
255
259
|
className: cx(showFocusBar && styles.withFocusBar, className),
|
|
256
260
|
"aria-invalid": hasErrors,
|
|
257
261
|
isRequired: field.required
|
|
258
262
|
}, renderHeading ? renderHeading(name) : createElement(FormControl.Label, {
|
|
259
|
-
className: styles.label
|
|
260
|
-
htmlFor: field.id
|
|
263
|
+
className: styles.label
|
|
261
264
|
}, name), children, createElement(ValidationErrors, {
|
|
262
265
|
field: field,
|
|
263
266
|
space: sdk.space,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-field-editors.esm.js","sources":["../src/getDefaultWidgetId.ts","../src/Field.tsx","../src/FieldWrapper.styles.ts","../src/FieldWrapper.tsx"],"sourcesContent":["import type { FieldExtensionSDK } from '@contentful/field-editor-shared';\nimport type { WidgetType } from './types';\n\nconst DROPDOWN_TYPES = ['Text', 'Symbol', 'Integer', 'Number', 'Boolean'];\n\nexport const DEFAULTS: { [key: string]: WidgetType } = {\n Text: 'markdown',\n Symbol: 'singleLine',\n Integer: 'numberEditor',\n Number: 'numberEditor',\n Boolean: 'boolean',\n Date: 'datePicker',\n Location: 'locationEditor',\n Object: 'objectEditor',\n RichText: 'richTextEditor',\n Symbols: 'tagEditor',\n File: 'fileEditor',\n};\n\nexport function getDefaultWidgetId(\n sdk: Pick<FieldExtensionSDK, 'field' | 'contentType'>\n): WidgetType {\n const field = sdk.field;\n const fieldType = field.type;\n const hasInValidation = (field.validations || []).find((v) => 'in' in v);\n\n if (hasInValidation && DROPDOWN_TYPES.includes(fieldType)) {\n return 'dropdown';\n }\n\n if (fieldType === 'Array') {\n if (field.items?.linkType === 'Asset') {\n return 'assetLinksEditor';\n }\n return 'entryLinksEditor';\n }\n\n if (fieldType === 'Link') {\n // @ts-expect-error\n if (field.linkType === 'Asset') {\n return 'assetLinkEditor';\n }\n return 'entryLinkEditor';\n }\n\n const displayFieldId = sdk.contentType.displayField;\n\n const isTextField = fieldType === 'Text';\n const isDisplayField = field.id === displayFieldId;\n\n if (isTextField && isDisplayField) {\n return 'singleLine';\n }\n\n return DEFAULTS[fieldType];\n}\n","import * as React from 'react';\nimport { NumberEditor } from '@contentful/field-editor-number';\nimport { SingleLineEditor } from '@contentful/field-editor-single-line';\nimport { BooleanEditor } from '@contentful/field-editor-boolean';\nimport { DateEditor } from '@contentful/field-editor-date';\nimport { LocationEditor } from '@contentful/field-editor-location';\nimport { JsonEditor } from '@contentful/field-editor-json';\nimport { MultipleLineEditor } from '@contentful/field-editor-multiple-line';\nimport { TagsEditor } from '@contentful/field-editor-tags';\nimport { SlugEditor } from '@contentful/field-editor-slug';\nimport { DropdownEditor } from '@contentful/field-editor-dropdown';\nimport { UrlEditor } from '@contentful/field-editor-url';\nimport { RadioEditor } from '@contentful/field-editor-radio';\nimport { RatingEditor } from '@contentful/field-editor-rating';\nimport { CheckboxEditor } from '@contentful/field-editor-checkbox';\nimport { ListEditor } from '@contentful/field-editor-list';\nimport {\n SingleEntryReferenceEditor,\n MultipleEntryReferenceEditor,\n SingleMediaEditor,\n MultipleMediaEditor,\n} from '@contentful/field-editor-reference';\nimport { RichTextEditor } from '@contentful/field-editor-rich-text';\nimport { MarkdownEditor } from '@contentful/field-editor-markdown';\nimport type { FieldExtensionSDK } from '@contentful/field-editor-shared';\nimport type { EditorOptions, WidgetType } from './types';\nimport { getDefaultWidgetId } from './getDefaultWidgetId';\n\ntype FieldProps = {\n sdk: FieldExtensionSDK;\n widgetId?: WidgetType;\n isInitiallyDisabled?: boolean;\n renderFieldEditor?: (\n widgetId: WidgetType,\n sdk: FieldExtensionSDK,\n isInitiallyDisabled: boolean\n ) => JSX.Element | false;\n getOptions?: (widgetId: WidgetType, sdk: FieldExtensionSDK) => EditorOptions;\n};\n\nconst widgetComponents: Record<string, [React.ComponentType<any>, any?]> = {\n multipleLine: [MultipleLineEditor],\n boolean: [BooleanEditor],\n objectEditor: [JsonEditor],\n datePicker: [DateEditor],\n locationEditor: [LocationEditor],\n checkbox: [CheckboxEditor],\n listInput: [ListEditor],\n rating: [RatingEditor],\n radio: [RadioEditor],\n tagEditor: [TagsEditor],\n numberEditor: [NumberEditor],\n urlEditor: [UrlEditor],\n slugEditor: [SlugEditor],\n singleLine: [SingleLineEditor],\n dropdown: [DropdownEditor],\n entryLinkEditor: [SingleEntryReferenceEditor, { viewType: 'link', hasCardEditActions: true }],\n entryCardEditor: [SingleEntryReferenceEditor, { viewType: 'card', hasCardEditActions: true }],\n entryLinksEditor: [MultipleEntryReferenceEditor, { viewType: 'link', hasCardEditActions: true }],\n entryCardsEditor: [MultipleEntryReferenceEditor, { viewType: 'card', hasCardEditActions: true }],\n assetLinkEditor: [SingleMediaEditor, { viewType: 'link' }],\n assetLinksEditor: [MultipleMediaEditor, { viewType: 'link' }],\n assetGalleryEditor: [MultipleMediaEditor, { viewType: 'card' }],\n richTextEditor: [RichTextEditor],\n markdown: [MarkdownEditor],\n};\n\nexport const Field: React.FC<FieldProps> = (props: FieldProps) => {\n const {\n sdk,\n widgetId: possiblyUndefinedWidgetId,\n isInitiallyDisabled = false,\n renderFieldEditor,\n getOptions,\n } = props;\n const field = sdk.field;\n const locales = sdk.locales;\n\n const widgetId = possiblyUndefinedWidgetId ?? getDefaultWidgetId(sdk);\n\n if (renderFieldEditor) {\n const customEditor = renderFieldEditor(widgetId, sdk, isInitiallyDisabled);\n if (customEditor) {\n return customEditor;\n }\n }\n\n const options = getOptions ? getOptions(widgetId, sdk) : {};\n const referenceEditorParams =\n sdk.parameters && 'instance' in sdk.parameters\n ? sdk.parameters\n : {\n instance: {\n showCreateEntityAction: true,\n showLinkEntityAction: true,\n },\n };\n\n if (!widgetComponents[widgetId]) return null;\n\n const [WidgetComponent, widgetStaticProps] = widgetComponents[widgetId];\n\n const widgetComponentProps = {\n sdk,\n field,\n locales,\n isInitiallyDisabled,\n parameters: referenceEditorParams,\n ...widgetStaticProps,\n // @ts-expect-error\n ...options[widgetId],\n };\n\n const baseSdk = widgetId === 'slugEditor' ? sdk : undefined;\n\n return <WidgetComponent key={sdk.field.locale} {...widgetComponentProps} baseSdk={baseSdk} />;\n};\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const styles = {\n withFocusBar: css({\n marginLeft: tokens.spacingL,\n marginRight: tokens.spacingL,\n marginBottom: '29px',\n marginTop: '19px',\n paddingLeft: tokens.spacingM,\n borderLeft: `3px solid ${tokens.gray300}`,\n transition: 'border-color 0.18s linear',\n '&:focus-within': {\n borderColor: tokens.colorPrimary,\n },\n '&[aria-invalid=\"true\"]': {\n borderLeftColor: tokens.red500,\n },\n }),\n label: css({\n display: 'flex',\n width: '100%',\n maxWidth: '800px',\n color: tokens.gray500,\n fontSize: tokens.fontSizeM,\n fontWeight: tokens.fontWeightNormal,\n lineHeight: tokens.lineHeightDefault,\n whiteSpace: 'pre-wrap',\n }),\n helpText: css({\n margin: `${tokens.spacingXs} 0`,\n fontStyle: 'italic',\n }),\n};\n","import * as React from 'react';\nimport { cx } from 'emotion';\nimport { FormControl } from '@contentful/f36-components';\nimport { ValidationErrors } from '@contentful/field-editor-validation-errors';\nimport type { FieldExtensionSDK, Entry } from '@contentful/field-editor-shared';\nimport { styles } from './FieldWrapper.styles';\n\ntype FieldWrapperProps = {\n name: string;\n sdk: FieldExtensionSDK;\n /**\n * Generates a link to another entry with the same value when a \"non unique\" validation error occurs\n */\n getEntryURL?: (entry: Entry) => string;\n className?: string;\n showFocusBar?: boolean;\n children: React.ReactNode;\n renderHeading?: (name: string) => JSX.Element | null;\n renderHelpText?: (helpText: string) => JSX.Element | null;\n};\n\nexport const FieldWrapper: React.FC<FieldWrapperProps> = function (props: FieldWrapperProps) {\n const { ids } = props.sdk;\n const defaultGetEntryUrl = (entry: Entry) =>\n `/spaces/${ids.space}/environments/${ids.environmentAlias || ids.environment}/entries/${\n entry.sys.id\n }`;\n const {\n name,\n sdk,\n className,\n children,\n renderHeading,\n renderHelpText,\n showFocusBar = true,\n getEntryURL = defaultGetEntryUrl,\n } = props;\n const { field } = sdk;\n const helpText = (sdk.parameters?.instance as any)?.helpText ?? '';\n\n const [hasErrors, setHasErrors] = React.useState(false);\n React.useEffect(() => {\n return field.onSchemaErrorsChanged((errors: unknown[]) => {\n setHasErrors((errors || []).length > 0);\n });\n }, [field]);\n\n return (\n <FormControl\n testId=\"entity-field-controls\"\n data-test-id=\"entity-field-controls\"\n className={cx(showFocusBar && styles.withFocusBar, className)}\n aria-invalid={hasErrors}\n isRequired={field.required}>\n {renderHeading ? (\n renderHeading(name)\n ) : (\n <FormControl.Label className={styles.label} htmlFor={field.id}>\n {name}\n </FormControl.Label>\n )}\n\n {children}\n\n <ValidationErrors\n field={field}\n space={sdk.space}\n locales={sdk.locales}\n getEntryURL={getEntryURL || defaultGetEntryUrl}\n />\n\n {renderHelpText ? (\n renderHelpText(helpText)\n ) : (\n <FormControl.HelpText testId=\"field-hint\" className={styles.helpText}>\n {helpText}\n </FormControl.HelpText>\n )}\n </FormControl>\n );\n};\n"],"names":["DROPDOWN_TYPES","DEFAULTS","Text","Symbol","Integer","Number","Boolean","Date","Location","Object","RichText","Symbols","File","getDefaultWidgetId","sdk","field","fieldType","type","hasInValidation","validations","find","v","includes","items","linkType","displayFieldId","contentType","displayField","isTextField","isDisplayField","id","widgetComponents","multipleLine","MultipleLineEditor","BooleanEditor","objectEditor","JsonEditor","datePicker","DateEditor","locationEditor","LocationEditor","checkbox","CheckboxEditor","listInput","ListEditor","rating","RatingEditor","radio","RadioEditor","tagEditor","TagsEditor","numberEditor","NumberEditor","urlEditor","UrlEditor","slugEditor","SlugEditor","singleLine","SingleLineEditor","dropdown","DropdownEditor","entryLinkEditor","SingleEntryReferenceEditor","viewType","hasCardEditActions","entryCardEditor","entryLinksEditor","MultipleEntryReferenceEditor","entryCardsEditor","assetLinkEditor","SingleMediaEditor","assetLinksEditor","MultipleMediaEditor","assetGalleryEditor","richTextEditor","RichTextEditor","markdown","MarkdownEditor","Field","props","possiblyUndefinedWidgetId","widgetId","isInitiallyDisabled","renderFieldEditor","getOptions","locales","customEditor","options","referenceEditorParams","parameters","instance","showCreateEntityAction","showLinkEntityAction","WidgetComponent","widgetStaticProps","widgetComponentProps","baseSdk","undefined","React","key","locale","styles","withFocusBar","css","marginLeft","tokens","spacingL","marginRight","marginBottom","marginTop","paddingLeft","spacingM","borderLeft","gray300","transition","borderColor","colorPrimary","borderLeftColor","red500","label","display","width","maxWidth","color","gray500","fontSize","fontSizeM","fontWeight","fontWeightNormal","lineHeight","lineHeightDefault","whiteSpace","helpText","margin","spacingXs","fontStyle","FieldWrapper","ids","defaultGetEntryUrl","entry","space","environmentAlias","environment","sys","name","className","children","renderHeading","renderHelpText","showFocusBar","getEntryURL","hasErrors","setHasErrors","onSchemaErrorsChanged","errors","length","FormControl","testId","cx","isRequired","required","Label","htmlFor","ValidationErrors","HelpText"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAMA,cAAc,GAAG,CAAC,MAAD,EAAS,QAAT,EAAmB,SAAnB,EAA8B,QAA9B,EAAwC,SAAxC,CAAvB;AAEO,IAAMC,QAAQ,GAAkC;AACrDC,EAAAA,IAAI,EAAE,UAD+C;AAErDC,EAAAA,MAAM,EAAE,YAF6C;AAGrDC,EAAAA,OAAO,EAAE,cAH4C;AAIrDC,EAAAA,MAAM,EAAE,cAJ6C;AAKrDC,EAAAA,OAAO,EAAE,SAL4C;AAMrDC,EAAAA,IAAI,EAAE,YAN+C;AAOrDC,EAAAA,QAAQ,EAAE,gBAP2C;AAQrDC,EAAAA,MAAM,EAAE,cAR6C;AASrDC,EAAAA,QAAQ,EAAE,gBAT2C;AAUrDC,EAAAA,OAAO,EAAE,WAV4C;AAWrDC,EAAAA,IAAI,EAAE;AAX+C,CAAhD;SAcSC,mBACdC;AAEA,MAAMC,KAAK,GAAGD,GAAG,CAACC,KAAlB;AACA,MAAMC,SAAS,GAAGD,KAAK,CAACE,IAAxB;AACA,MAAMC,eAAe,GAAG,CAACH,KAAK,CAACI,WAAN,IAAqB,EAAtB,EAA0BC,IAA1B,CAA+B,UAACC,CAAD;AAAA,WAAO,QAAQA,CAAf;AAAA,GAA/B,CAAxB;;AAEA,MAAIH,eAAe,IAAIlB,cAAc,CAACsB,QAAf,CAA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AC5I,KAAD,CAJH;AAMA,SACEmF,aAAA,CAAC0D,WAAD;AACEC,IAAAA,MAAM,EAAC;oBACM;AACbZ,IAAAA,SAAS,EAAEa,EAAE,CAACT,YAAY,IAAIhD,MAAM,CAACC,YAAxB,EAAsC2C,SAAtC;oBACCM;AACdQ,IAAAA,UAAU,EAAEhJ,KAAK,CAACiJ;GALpB,EAMGb,aAAa,GACZA,aAAa,CAACH,IAAD,CADD,GAGZ9C,aAAA,CAAC0D,WAAW,CAACK,KAAb;AAAmBhB,IAAAA,SAAS,EAAE5C,MAAM,CAACkB;AAAO2C,IAAAA,OAAO,EAAEnJ,KAAK,CAACe;GAA3D,EACGkH,IADH,CATJ,EAcGE,QAdH,EAgBEhD,aAAA,CAACiE,gBAAD;AACEpJ,IAAAA,KAAK,EAAEA;AACP6H,IAAAA,KAAK,EAAE9H,GAAG,CAAC8H;AACXvD,IAAAA,OAAO,EAAEvE,GAAG,CAACuE;AACbiE,IAAAA,WAAW,EAAEA,WAAW,IAAIZ;GAJ9B,CAhBF,EAuBGU,cAAc,GACbA,cAAc,CAAChB,QAAD,CADD,GAGblC,aAAA,CAAC0D,WAAW,CAACQ,QAAb;AAAsBP,IAAAA,MAAM,EAAC;AAAaZ,IAAAA,SAAS,EAAE5C,MAAM,CAAC+B;GAA5D,EACGA,QADH,CA1BJ,CADF;AAiCD,CA3DM;;;;"}
|
|
1
|
+
{"version":3,"file":"default-field-editors.esm.js","sources":["../src/getDefaultWidgetId.ts","../src/Field.tsx","../src/FieldWrapper.styles.ts","../src/FieldWrapper.tsx"],"sourcesContent":["import type { FieldExtensionSDK } from '@contentful/field-editor-shared';\nimport type { WidgetType } from './types';\n\nconst DROPDOWN_TYPES = ['Text', 'Symbol', 'Integer', 'Number', 'Boolean'];\n\nexport const DEFAULTS: { [key: string]: WidgetType } = {\n Text: 'markdown',\n Symbol: 'singleLine',\n Integer: 'numberEditor',\n Number: 'numberEditor',\n Boolean: 'boolean',\n Date: 'datePicker',\n Location: 'locationEditor',\n Object: 'objectEditor',\n RichText: 'richTextEditor',\n Symbols: 'tagEditor',\n File: 'fileEditor',\n};\n\nexport function getDefaultWidgetId(\n sdk: Pick<FieldExtensionSDK, 'field' | 'contentType'>\n): WidgetType {\n const field = sdk.field;\n const fieldType = field.type;\n const hasInValidation = (field.validations || []).find((v) => 'in' in v);\n\n if (hasInValidation && DROPDOWN_TYPES.includes(fieldType)) {\n return 'dropdown';\n }\n\n if (fieldType === 'Array') {\n if (field.items?.linkType === 'Asset') {\n return 'assetLinksEditor';\n }\n return 'entryLinksEditor';\n }\n\n if (fieldType === 'Link') {\n // @ts-expect-error\n if (field.linkType === 'Asset') {\n return 'assetLinkEditor';\n }\n return 'entryLinkEditor';\n }\n\n const displayFieldId = sdk.contentType.displayField;\n\n const isTextField = fieldType === 'Text';\n const isDisplayField = field.id === displayFieldId;\n\n if (isTextField && isDisplayField) {\n return 'singleLine';\n }\n\n return DEFAULTS[fieldType];\n}\n","import * as React from 'react';\nimport { NumberEditor } from '@contentful/field-editor-number';\nimport { SingleLineEditor } from '@contentful/field-editor-single-line';\nimport { BooleanEditor } from '@contentful/field-editor-boolean';\nimport { DateEditor } from '@contentful/field-editor-date';\nimport { LocationEditor } from '@contentful/field-editor-location';\nimport { JsonEditor } from '@contentful/field-editor-json';\nimport { MultipleLineEditor } from '@contentful/field-editor-multiple-line';\nimport { TagsEditor } from '@contentful/field-editor-tags';\nimport { SlugEditor } from '@contentful/field-editor-slug';\nimport { DropdownEditor } from '@contentful/field-editor-dropdown';\nimport { UrlEditor } from '@contentful/field-editor-url';\nimport { RadioEditor } from '@contentful/field-editor-radio';\nimport { RatingEditor } from '@contentful/field-editor-rating';\nimport { CheckboxEditor } from '@contentful/field-editor-checkbox';\nimport { ListEditor } from '@contentful/field-editor-list';\nimport {\n SingleEntryReferenceEditor,\n MultipleEntryReferenceEditor,\n SingleMediaEditor,\n MultipleMediaEditor,\n} from '@contentful/field-editor-reference';\nimport { RichTextEditor } from '@contentful/field-editor-rich-text';\nimport { MarkdownEditor } from '@contentful/field-editor-markdown';\nimport type { FieldExtensionSDK } from '@contentful/field-editor-shared';\nimport type { EditorOptions, WidgetType } from './types';\nimport { getDefaultWidgetId } from './getDefaultWidgetId';\n\ntype FieldProps = {\n sdk: FieldExtensionSDK;\n widgetId?: WidgetType;\n isInitiallyDisabled?: boolean;\n renderFieldEditor?: (\n widgetId: WidgetType,\n sdk: FieldExtensionSDK,\n isInitiallyDisabled: boolean\n ) => JSX.Element | false;\n getOptions?: (widgetId: WidgetType, sdk: FieldExtensionSDK) => EditorOptions;\n};\n\nconst widgetComponents: Record<string, [React.ComponentType<any>, any?]> = {\n multipleLine: [MultipleLineEditor],\n boolean: [BooleanEditor],\n objectEditor: [JsonEditor],\n datePicker: [DateEditor],\n locationEditor: [LocationEditor],\n checkbox: [CheckboxEditor],\n listInput: [ListEditor],\n rating: [RatingEditor],\n radio: [RadioEditor],\n tagEditor: [TagsEditor],\n numberEditor: [NumberEditor],\n urlEditor: [UrlEditor],\n slugEditor: [SlugEditor],\n singleLine: [SingleLineEditor],\n dropdown: [DropdownEditor],\n entryLinkEditor: [SingleEntryReferenceEditor, { viewType: 'link', hasCardEditActions: true }],\n entryCardEditor: [SingleEntryReferenceEditor, { viewType: 'card', hasCardEditActions: true }],\n entryLinksEditor: [MultipleEntryReferenceEditor, { viewType: 'link', hasCardEditActions: true }],\n entryCardsEditor: [MultipleEntryReferenceEditor, { viewType: 'card', hasCardEditActions: true }],\n assetLinkEditor: [SingleMediaEditor, { viewType: 'link' }],\n assetLinksEditor: [MultipleMediaEditor, { viewType: 'link' }],\n assetGalleryEditor: [MultipleMediaEditor, { viewType: 'card' }],\n richTextEditor: [RichTextEditor],\n markdown: [MarkdownEditor],\n};\n\nexport const Field: React.FC<FieldProps> = (props: FieldProps) => {\n const {\n sdk,\n widgetId: possiblyUndefinedWidgetId,\n isInitiallyDisabled = false,\n renderFieldEditor,\n getOptions,\n } = props;\n const field = sdk.field;\n const locales = sdk.locales;\n\n const widgetId = possiblyUndefinedWidgetId ?? getDefaultWidgetId(sdk);\n\n if (renderFieldEditor) {\n const customEditor = renderFieldEditor(widgetId, sdk, isInitiallyDisabled);\n if (customEditor) {\n return customEditor;\n }\n }\n\n const options = getOptions ? getOptions(widgetId, sdk) : {};\n const referenceEditorParams =\n sdk.parameters && 'instance' in sdk.parameters\n ? sdk.parameters\n : {\n instance: {\n showCreateEntityAction: true,\n showLinkEntityAction: true,\n },\n };\n\n if (!widgetComponents[widgetId]) return null;\n\n const [WidgetComponent, widgetStaticProps] = widgetComponents[widgetId];\n\n const widgetComponentProps = {\n sdk,\n field,\n locales,\n isInitiallyDisabled,\n parameters: referenceEditorParams,\n ...widgetStaticProps,\n // @ts-expect-error\n ...options[widgetId],\n };\n\n const baseSdk = widgetId === 'slugEditor' ? sdk : undefined;\n\n return <WidgetComponent key={sdk.field.locale} {...widgetComponentProps} baseSdk={baseSdk} />;\n};\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const styles = {\n withFocusBar: css({\n marginLeft: tokens.spacingL,\n marginRight: tokens.spacingL,\n marginBottom: '29px',\n marginTop: '19px',\n paddingLeft: tokens.spacingM,\n borderLeft: `3px solid ${tokens.gray300}`,\n transition: 'border-color 0.18s linear',\n '&:focus-within': {\n borderColor: tokens.colorPrimary,\n },\n '&[aria-invalid=\"true\"]': {\n borderLeftColor: tokens.red500,\n },\n }),\n label: css({\n display: 'flex',\n width: '100%',\n maxWidth: '800px',\n color: tokens.gray500,\n fontSize: tokens.fontSizeM,\n fontWeight: tokens.fontWeightNormal,\n lineHeight: tokens.lineHeightDefault,\n whiteSpace: 'pre-wrap',\n }),\n helpText: css({\n margin: `${tokens.spacingXs} 0`,\n fontStyle: 'italic',\n }),\n};\n","import * as React from 'react';\nimport { cx } from 'emotion';\nimport { FormControl } from '@contentful/f36-components';\nimport { ValidationErrors } from '@contentful/field-editor-validation-errors';\nimport type { FieldExtensionSDK, Entry } from '@contentful/field-editor-shared';\nimport { styles } from './FieldWrapper.styles';\n\ntype FieldWrapperProps = {\n name: string;\n sdk: FieldExtensionSDK;\n /**\n * Generates a link to another entry with the same value when a \"non unique\" validation error occurs\n */\n getEntryURL?: (entry: Entry) => string;\n className?: string;\n showFocusBar?: boolean;\n children: React.ReactNode;\n renderHeading?: (name: string) => JSX.Element | null;\n renderHelpText?: (helpText: string) => JSX.Element | null;\n};\n\nexport const FieldWrapper: React.FC<FieldWrapperProps> = function (props: FieldWrapperProps) {\n const { ids } = props.sdk;\n const defaultGetEntryUrl = (entry: Entry) =>\n `/spaces/${ids.space}/environments/${ids.environmentAlias || ids.environment}/entries/${\n entry.sys.id\n }`;\n const {\n name,\n sdk,\n className,\n children,\n renderHeading,\n renderHelpText,\n showFocusBar = true,\n getEntryURL = defaultGetEntryUrl,\n } = props;\n const { field } = sdk;\n const helpText = (sdk.parameters?.instance as any)?.helpText ?? '';\n\n const [hasErrors, setHasErrors] = React.useState(false);\n React.useEffect(() => {\n return field.onSchemaErrorsChanged((errors: unknown[]) => {\n setHasErrors((errors || []).length > 0);\n });\n }, [field]);\n\n const fieldControlId = [field.id, field.locale, sdk.contentType?.sys?.id]\n .filter((item) => item)\n .join('-');\n\n return (\n <FormControl\n id={fieldControlId}\n testId=\"entity-field-controls\"\n data-test-id=\"entity-field-controls\"\n className={cx(showFocusBar && styles.withFocusBar, className)}\n aria-invalid={hasErrors}\n isRequired={field.required}>\n {renderHeading ? (\n renderHeading(name)\n ) : (\n <FormControl.Label className={styles.label}>{name}</FormControl.Label>\n )}\n\n {children}\n\n <ValidationErrors\n field={field}\n space={sdk.space}\n locales={sdk.locales}\n getEntryURL={getEntryURL || defaultGetEntryUrl}\n />\n\n {renderHelpText ? (\n renderHelpText(helpText)\n ) : (\n <FormControl.HelpText testId=\"field-hint\" className={styles.helpText}>\n {helpText}\n </FormControl.HelpText>\n )}\n </FormControl>\n );\n};\n"],"names":["DROPDOWN_TYPES","DEFAULTS","Text","Symbol","Integer","Number","Boolean","Date","Location","Object","RichText","Symbols","File","getDefaultWidgetId","sdk","field","fieldType","type","hasInValidation","validations","find","v","includes","items","linkType","displayFieldId","contentType","displayField","isTextField","isDisplayField","id","widgetComponents","multipleLine","MultipleLineEditor","BooleanEditor","objectEditor","JsonEditor","datePicker","DateEditor","locationEditor","LocationEditor","checkbox","CheckboxEditor","listInput","ListEditor","rating","RatingEditor","radio","RadioEditor","tagEditor","TagsEditor","numberEditor","NumberEditor","urlEditor","UrlEditor","slugEditor","SlugEditor","singleLine","SingleLineEditor","dropdown","DropdownEditor","entryLinkEditor","SingleEntryReferenceEditor","viewType","hasCardEditActions","entryCardEditor","entryLinksEditor","MultipleEntryReferenceEditor","entryCardsEditor","assetLinkEditor","SingleMediaEditor","assetLinksEditor","MultipleMediaEditor","assetGalleryEditor","richTextEditor","RichTextEditor","markdown","MarkdownEditor","Field","props","possiblyUndefinedWidgetId","widgetId","isInitiallyDisabled","renderFieldEditor","getOptions","locales","customEditor","options","referenceEditorParams","parameters","instance","showCreateEntityAction","showLinkEntityAction","WidgetComponent","widgetStaticProps","widgetComponentProps","baseSdk","undefined","React","key","locale","styles","withFocusBar","css","marginLeft","tokens","spacingL","marginRight","marginBottom","marginTop","paddingLeft","spacingM","borderLeft","gray300","transition","borderColor","colorPrimary","borderLeftColor","red500","label","display","width","maxWidth","color","gray500","fontSize","fontSizeM","fontWeight","fontWeightNormal","lineHeight","lineHeightDefault","whiteSpace","helpText","margin","spacingXs","fontStyle","FieldWrapper","ids","defaultGetEntryUrl","entry","space","environmentAlias","environment","sys","name","className","children","renderHeading","renderHelpText","showFocusBar","getEntryURL","hasErrors","setHasErrors","onSchemaErrorsChanged","errors","length","fieldControlId","filter","item","join","FormControl","testId","cx","isRequired","required","Label","ValidationErrors","HelpText"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAMA,cAAc,GAAG,CAAC,MAAD,EAAS,QAAT,EAAmB,SAAnB,EAA8B,QAA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U,EAAEpJ,KAAK,CAACqJ;GANpB,EAOGjB,aAAa,GACZA,aAAa,CAACH,IAAD,CADD,GAGZ9C,aAAA,CAAC8D,WAAW,CAACK,KAAb;AAAmBpB,IAAAA,SAAS,EAAE5C,MAAM,CAACkB;GAArC,EAA6CyB,IAA7C,CAVJ,EAaGE,QAbH,EAeEhD,aAAA,CAACoE,gBAAD;AACEvJ,IAAAA,KAAK,EAAEA;AACP6H,IAAAA,KAAK,EAAE9H,GAAG,CAAC8H;AACXvD,IAAAA,OAAO,EAAEvE,GAAG,CAACuE;AACbiE,IAAAA,WAAW,EAAEA,WAAW,IAAIZ;GAJ9B,CAfF,EAsBGU,cAAc,GACbA,cAAc,CAAChB,QAAD,CADD,GAGblC,aAAA,CAAC8D,WAAW,CAACO,QAAb;AAAsBN,IAAAA,MAAM,EAAC;AAAahB,IAAAA,SAAS,EAAE5C,MAAM,CAAC+B;GAA5D,EACGA,QADH,CAzBJ,CADF;AAgCD,CA9DM;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/default-field-editors",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/default-field-editors.esm.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@contentful/field-editor-number": "^1.0.0",
|
|
35
35
|
"@contentful/field-editor-radio": "^1.0.0",
|
|
36
36
|
"@contentful/field-editor-rating": "^1.0.0",
|
|
37
|
-
"@contentful/field-editor-reference": "^4.0.
|
|
38
|
-
"@contentful/field-editor-rich-text": "^1.0.
|
|
37
|
+
"@contentful/field-editor-reference": "^4.0.2",
|
|
38
|
+
"@contentful/field-editor-rich-text": "^1.0.2",
|
|
39
39
|
"@contentful/field-editor-shared": "^1.0.0",
|
|
40
40
|
"@contentful/field-editor-single-line": "^1.0.0",
|
|
41
41
|
"@contentful/field-editor-slug": "^1.0.0",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "488f2c7475b1d89770db6666709b5b66c592c1b5"
|
|
67
67
|
}
|