@contentful/field-editor-validation-errors 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/ValidationErrors.d.ts +0 -9
- package/dist/field-editor-validation-errors.cjs.development.js +9 -5
- package/dist/field-editor-validation-errors.cjs.development.js.map +1 -1
- package/dist/field-editor-validation-errors.cjs.production.min.js +1 -1
- package/dist/field-editor-validation-errors.cjs.production.min.js.map +1 -1
- package/dist/field-editor-validation-errors.esm.js +9 -5
- package/dist/field-editor-validation-errors.esm.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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
|
+
# [0.7.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-validation-errors@0.6.4...@contentful/field-editor-validation-errors@0.7.0) (2021-10-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* [EXT-3161] bump app sdk to v4 ([#881](https://github.com/contentful/field-editors/issues/881)) ([9c4a2af](https://github.com/contentful/field-editors/commit/9c4a2af07da203d59fb5f15c3a5188ecc64b1d44))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [0.6.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-validation-errors@0.6.3...@contentful/field-editor-validation-errors@0.6.4) (2021-09-17)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @contentful/field-editor-validation-errors
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { SpaceAPI, Entry, FieldAPI, LocalesAPI } from '@contentful/field-editor-shared';
|
|
3
|
-
export declare type ValidationError = {
|
|
4
|
-
name: string;
|
|
5
|
-
message: string;
|
|
6
|
-
conflicting?: Array<{
|
|
7
|
-
sys: {
|
|
8
|
-
id: string;
|
|
9
|
-
};
|
|
10
|
-
}>;
|
|
11
|
-
};
|
|
12
3
|
export interface ValidationErrorsProps {
|
|
13
4
|
field: FieldAPI;
|
|
14
5
|
space: SpaceAPI;
|
|
@@ -74,15 +74,19 @@ function UniquenessError(props) {
|
|
|
74
74
|
contentType: contentTypesById[entry.sys.contentType.sys.id]
|
|
75
75
|
});
|
|
76
76
|
}, [props.localeCode, props.defaultLocaleCode, contentTypesById]);
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
var conflicting = [];
|
|
78
|
+
|
|
79
|
+
if ('conflicting' in props.error) {
|
|
80
|
+
conflicting = props.error.conflicting;
|
|
81
|
+
}
|
|
79
82
|
|
|
83
|
+
React.useEffect(function () {
|
|
80
84
|
var entryIds = state.entries.map(function (entry) {
|
|
81
85
|
return entry.id;
|
|
82
86
|
});
|
|
83
|
-
var conflictIds =
|
|
87
|
+
var conflictIds = conflicting.map(function (entry) {
|
|
84
88
|
return entry.sys.id;
|
|
85
|
-
})
|
|
89
|
+
}); // Avoid unnecessary refetching
|
|
86
90
|
|
|
87
91
|
if (conflictIds.every(function (id) {
|
|
88
92
|
return entryIds.includes(id);
|
|
@@ -112,7 +116,7 @@ function UniquenessError(props) {
|
|
|
112
116
|
entries: entries
|
|
113
117
|
});
|
|
114
118
|
});
|
|
115
|
-
}, [getTitle, state.entries,
|
|
119
|
+
}, [getTitle, state.entries, conflicting, props.space.getEntries, props.getEntryURL]);
|
|
116
120
|
return React.createElement(forma36ReactComponents.List, {
|
|
117
121
|
className: errorList,
|
|
118
122
|
testId: "validation-errors-uniqueness"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-validation-errors.cjs.development.js","sources":["../src/styles.ts","../src/ValidationErrors.tsx"],"sourcesContent":["import { css } from 'emotion';\nimport tokens from '@contentful/forma-36-tokens';\n\nexport const errorList = css({\n padding: 0,\n wordWrap: 'break-word',\n marginTop: tokens.spacingS,\n color: tokens.red500,\n listStyleType: 'none',\n});\n\nexport const errorMessage = css({\n display: 'inline-flex',\n flexDirection: 'column',\n marginLeft: tokens.spacingXs,\n});\n\nexport const errorItem = css({\n display: 'flex',\n alignItems: 'center',\n});\n\nexport const entryLink = css({\n fontWeight: Number(tokens.fontWeightDemiBold),\n});\n","import React from 'react';\nimport type {\n SpaceAPI,\n Entry,\n ContentType,\n FieldAPI,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { entityHelpers } from '@contentful/field-editor-shared';\nimport { TextLink, List, ListItem, Icon } from '@contentful/forma-36-react-components';\n\nimport * as styles from './styles';\n\nexport type ValidationError = {\n name: string;\n message: string;\n conflicting?: Array<{ sys: { id: string } }>;\n};\n\ntype UniquenessErrorProps = {\n error: ValidationError;\n space: SpaceAPI;\n localeCode: string;\n defaultLocaleCode: string;\n getEntryURL: (entry: Entry) => string;\n};\n\nfunction UniquenessError(props: UniquenessErrorProps) {\n const [state, setState] = React.useState<{\n loading: boolean;\n entries: { id: string; title: string; href: string }[];\n }>({\n loading: true,\n entries: [],\n });\n\n const contentTypesById = React.useMemo(\n (): Record<string, ContentType> =>\n // Maps ID => Content Type\n props.space.getCachedContentTypes().reduce(\n (prev, ct) => ({\n ...prev,\n [ct.sys.id]: ct,\n }),\n {}\n ),\n [props.space]\n );\n\n const getTitle = React.useCallback(\n (entry: Entry) =>\n entityHelpers.getEntryTitle({\n entry,\n defaultTitle: 'Untitled',\n localeCode: props.localeCode,\n defaultLocaleCode: props.defaultLocaleCode,\n contentType: contentTypesById[entry.sys.contentType.sys.id],\n }),\n [props.localeCode, props.defaultLocaleCode, contentTypesById]\n );\n\n React.useEffect(() => {\n const entryIds = state.entries.map((entry) => entry.id);\n const conflictIds = props.error.conflicting?.map((entry) => entry.sys.id) || [];\n\n // Avoid unnecessary refetching\n if (conflictIds.every((id) => entryIds.includes(id))) {\n return;\n }\n\n setState((state) => ({ ...state, loading: true }));\n\n const query = {\n 'sys.id[in]': conflictIds.join(','),\n };\n\n props.space.getEntries<Entry>(query).then(({ items }) => {\n const entries = items.map((entry) => ({\n id: entry.sys.id,\n title: getTitle(entry),\n href: props.getEntryURL(entry),\n }));\n\n setState({\n loading: false,\n entries,\n });\n });\n }, [getTitle, state.entries, props.error.conflicting, props.space.getEntries, props.getEntryURL]);\n\n return (\n <List className={styles.errorList} testId=\"validation-errors-uniqueness\">\n <ListItem className={styles.entryLink}>\n {state.loading ? (\n <div>Loading title for conflicting entry…</div>\n ) : (\n state.entries.map((entry) => (\n <TextLink\n key={entry.id}\n href={entry.href}\n icon=\"ExternalLink\"\n iconPosition=\"right\"\n linkType=\"negative\"\n target=\"_blank\"\n rel=\"noopener noreferrer\">\n {entry.title}\n </TextLink>\n ))\n )}\n </ListItem>\n </List>\n );\n}\n\nexport interface ValidationErrorsProps {\n field: FieldAPI;\n space: SpaceAPI;\n locales: LocalesAPI;\n getEntryURL: (entry: Entry) => string;\n}\n\nexport function ValidationErrors(props: ValidationErrorsProps) {\n const [errors, setErrors] = React.useState<ValidationError[]>([]);\n\n React.useEffect(() => {\n const onErrors = (errors?: ValidationError[]) => {\n setErrors(errors || []);\n };\n\n return props.field.onSchemaErrorsChanged(onErrors);\n }, [props.field]);\n\n if (errors.length === 0) {\n return null;\n }\n\n return (\n <List className={styles.errorList} testId=\"validation-errors\">\n {errors.map((error, index) => {\n return (\n <li\n key={index}\n role=\"status\"\n aria-roledescription=\"field-locale-schema\"\n data-error-code={`entry.schema.${error.name}`}\n className={styles.errorItem}>\n <Icon icon=\"InfoCircle\" color=\"negative\" />\n <div className={styles.errorMessage}>\n {error.message}\n {error.name === 'unique' && (\n <UniquenessError\n error={error}\n space={props.space}\n localeCode={props.field.locale}\n defaultLocaleCode={props.locales.default}\n getEntryURL={props.getEntryURL}\n />\n )}\n </div>\n </li>\n );\n })}\n </List>\n );\n}\n"],"names":["errorList","css","padding","wordWrap","marginTop","tokens","spacingS","color","red500","listStyleType","errorMessage","display","flexDirection","marginLeft","spacingXs","errorItem","alignItems","entryLink","fontWeight","Number","fontWeightDemiBold","UniquenessError","props","React","useState","loading","entries","state","setState","contentTypesById","useMemo","space","getCachedContentTypes","reduce","prev","ct","sys","id","getTitle","useCallback","entry","entityHelpers","getEntryTitle","defaultTitle","localeCode","defaultLocaleCode","contentType","useEffect","entryIds","map","conflictIds","error","conflicting","every","includes","query","join","getEntries","then","items","title","href","getEntryURL","List","className","styles","testId","ListItem","TextLink","key","icon","iconPosition","linkType","target","rel","ValidationErrors","errors","setErrors","onErrors","field","onSchemaErrorsChanged","length","index","role","name","Icon","message","locale","locales"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAMA,SAAS,gBAAGC,WAAG,CAAC;AAC3BC,EAAAA,OAAO,EAAE,CADkB;AAE3BC,EAAAA,QAAQ,EAAE,YAFiB;AAG3BC,EAAAA,SAAS,EAAEC,MAAM,CAACC,QAHS;AAI3BC,EAAAA,KAAK,EAAEF,MAAM,CAACG,MAJa;AAK3BC,EAAAA,aAAa,EAAE;AALY,CAAD,CAArB;AAQA,IAAMC,YAAY,gBAAGT,WAAG,CAAC;AAC9BU,EAAAA,OAAO,EAAE,aADqB;AAE9BC,EAAAA,aAAa,EAAE,QAFe;AAG9BC,EAAAA,UAAU,EAAER,MAAM,CAACS;AAHW,CAAD,CAAxB;AAMA,IAAMC,SAAS,gBAAGd,WAAG,CAAC;AAC3BU,EAAAA,OAAO,EAAE,MADkB;AAE3BK,EAAAA,UAAU,EAAE;AAFe,CAAD,CAArB;AAKA,IAAMC,SAAS,gBAAGhB,WAAG,CAAC;AAC3BiB,EAAAA,UAAU,eAAEC,MAAM,CAACd,MAAM,CAACe,kBAAR;AADS,CAAD,CAArB;;ACKP,SAASC,eAAT,CAAyBC,KAAzB;AACE,wBAA0BC,KAAK,CAACC,QAAN,CAGvB;AACDC,IAAAA,OAAO,EAAE,IADR;AAEDC,IAAAA,OAAO,EAAE;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,IAAI,EAAC;AAAa/D,MAAAA,KAAK,EAAC;KAA9B,CANF,EAOEgB,mBAAA,MAAA;AAAKyC,MAAAA,SAAS,EAAEC;KAAhB,EACGd,KAAK,CAACmC,OADT,EAEGnC,KAAK,CAACiC,IAAN,KAAe,QAAf,IACC7D,mBAAA,CAACF,eAAD;AACE8B,MAAAA,KAAK,EAAEA;AACPpB,MAAAA,KAAK,EAAET,KAAK,CAACS;AACba,MAAAA,UAAU,EAAEtB,KAAK,CAACyD,KAAN,CAAYQ;AACxB1C,MAAAA,iBAAiB,EAAEvB,KAAK,CAACkE,OAAN;AACnB1B,MAAAA,WAAW,EAAExC,KAAK,CAACwC;KALrB,CAHJ,CAPF,CADF;AAsBD,GAvBA,CADH,CADF;AA4BD;;;;"}
|
|
1
|
+
{"version":3,"file":"field-editor-validation-errors.cjs.development.js","sources":["../src/styles.ts","../src/ValidationErrors.tsx"],"sourcesContent":["import { css } from 'emotion';\nimport tokens from '@contentful/forma-36-tokens';\n\nexport const errorList = css({\n padding: 0,\n wordWrap: 'break-word',\n marginTop: tokens.spacingS,\n color: tokens.red500,\n listStyleType: 'none',\n});\n\nexport const errorMessage = css({\n display: 'inline-flex',\n flexDirection: 'column',\n marginLeft: tokens.spacingXs,\n});\n\nexport const errorItem = css({\n display: 'flex',\n alignItems: 'center',\n});\n\nexport const entryLink = css({\n fontWeight: Number(tokens.fontWeightDemiBold),\n});\n","import React from 'react';\nimport { ValidationError, Link } from '@contentful/app-sdk';\nimport type {\n SpaceAPI,\n Entry,\n ContentType,\n FieldAPI,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { entityHelpers } from '@contentful/field-editor-shared';\nimport { TextLink, List, ListItem, Icon } from '@contentful/forma-36-react-components';\n\nimport * as styles from './styles';\n\ntype UniquenessErrorProps = {\n error: ValidationError;\n space: SpaceAPI;\n localeCode: string;\n defaultLocaleCode: string;\n getEntryURL: (entry: Entry) => string;\n};\n\nfunction UniquenessError(props: UniquenessErrorProps) {\n const [state, setState] = React.useState<{\n loading: boolean;\n entries: { id: string; title: string; href: string }[];\n }>({\n loading: true,\n entries: [],\n });\n\n const contentTypesById = React.useMemo(\n (): Record<string, ContentType> =>\n // Maps ID => Content Type\n props.space.getCachedContentTypes().reduce(\n (prev, ct) => ({\n ...prev,\n [ct.sys.id]: ct,\n }),\n {}\n ),\n [props.space]\n );\n\n const getTitle = React.useCallback(\n (entry: Entry) =>\n entityHelpers.getEntryTitle({\n entry,\n defaultTitle: 'Untitled',\n localeCode: props.localeCode,\n defaultLocaleCode: props.defaultLocaleCode,\n contentType: contentTypesById[entry.sys.contentType.sys.id],\n }),\n [props.localeCode, props.defaultLocaleCode, contentTypesById]\n );\n\n let conflicting: Link<'Entry', 'Link'>[] = [];\n if ('conflicting' in props.error) {\n conflicting = props.error.conflicting;\n }\n React.useEffect(() => {\n const entryIds = state.entries.map((entry) => entry.id);\n const conflictIds = conflicting.map((entry) => entry.sys.id);\n\n // Avoid unnecessary refetching\n if (conflictIds.every((id) => entryIds.includes(id))) {\n return;\n }\n\n setState((state) => ({ ...state, loading: true }));\n\n const query = {\n 'sys.id[in]': conflictIds.join(','),\n };\n\n props.space.getEntries<Entry>(query).then(({ items }) => {\n const entries = items.map((entry) => ({\n id: entry.sys.id,\n title: getTitle(entry),\n href: props.getEntryURL(entry),\n }));\n\n setState({\n loading: false,\n entries,\n });\n });\n }, [getTitle, state.entries, conflicting, props.space.getEntries, props.getEntryURL]);\n\n return (\n <List className={styles.errorList} testId=\"validation-errors-uniqueness\">\n <ListItem className={styles.entryLink}>\n {state.loading ? (\n <div>Loading title for conflicting entry…</div>\n ) : (\n state.entries.map((entry) => (\n <TextLink\n key={entry.id}\n href={entry.href}\n icon=\"ExternalLink\"\n iconPosition=\"right\"\n linkType=\"negative\"\n target=\"_blank\"\n rel=\"noopener noreferrer\">\n {entry.title}\n </TextLink>\n ))\n )}\n </ListItem>\n </List>\n );\n}\n\nexport interface ValidationErrorsProps {\n field: FieldAPI;\n space: SpaceAPI;\n locales: LocalesAPI;\n getEntryURL: (entry: Entry) => string;\n}\n\nexport function ValidationErrors(props: ValidationErrorsProps) {\n const [errors, setErrors] = React.useState<ValidationError[]>([]);\n\n React.useEffect(() => {\n const onErrors = (errors?: ValidationError[]) => {\n setErrors(errors || []);\n };\n\n return props.field.onSchemaErrorsChanged(onErrors);\n }, [props.field]);\n\n if (errors.length === 0) {\n return null;\n }\n\n return (\n <List className={styles.errorList} testId=\"validation-errors\">\n {errors.map((error, index) => {\n return (\n <li\n key={index}\n role=\"status\"\n aria-roledescription=\"field-locale-schema\"\n data-error-code={`entry.schema.${error.name}`}\n className={styles.errorItem}>\n <Icon icon=\"InfoCircle\" color=\"negative\" />\n <div className={styles.errorMessage}>\n {error.message}\n {error.name === 'unique' && (\n <UniquenessError\n error={error}\n space={props.space}\n localeCode={props.field.locale}\n defaultLocaleCode={props.locales.default}\n getEntryURL={props.getEntryURL}\n />\n )}\n </div>\n </li>\n );\n })}\n </List>\n );\n}\n"],"names":["errorList","css","padding","wordWrap","marginTop","tokens","spacingS","color","red500","listStyleType","errorMessage","display","flexDirection","marginLeft","spacingXs","errorItem","alignItems","entryLink","fontWeight","Number","fontWeightDemiBold","UniquenessError","props","React","useState","loading","entries","state","setState","contentTypesById","useMemo","space","getCachedContentTypes","reduce","prev","ct","sys","id","getTitle","useCallback","entry","entityHelpers","getEntryTitle","defaultTitle","localeCode","defaultLocaleCode","contentType","conflicting","error","useEffect","entryIds","map","conflictIds","every","includes","query","join","getEntries","then","items","title","href","getEntryURL","List","className","styles","testId","ListItem","TextLink","key","icon","iconPosition","linkType","target","rel","ValidationErrors","errors","setErrors","onErrors","field","onSchemaErrorsChanged","length","index","role","name","Icon","message","locale","locales"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAMA,SAAS,gBAAGC,WAAG,CAAC;AAC3BC,EAAAA,OAAO,EAAE,CADkB;AAE3BC,EAAAA,QAAQ,EAAE,YAFiB;AAG3BC,EAAAA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2 @@
|
|
|
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=e(require("react")),n=require("@contentful/field-editor-shared"),r=require("@contentful/forma-36-react-components"),i=require("emotion"),
|
|
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=e(require("react")),n=require("@contentful/field-editor-shared"),r=require("@contentful/forma-36-react-components"),i=require("emotion"),a=e(require("@contentful/forma-36-tokens"));function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var l=i.css({padding:0,wordWrap:"break-word",marginTop:a.spacingS,color:a.red500,listStyleType:"none"}),c=i.css({display:"inline-flex",flexDirection:"column",marginLeft:a.spacingXs}),s=i.css({display:"flex",alignItems:"center"}),u=i.css({fontWeight:Number(a.fontWeightDemiBold)});function d(e){var i=t.useState({loading:!0,entries:[]}),a=i[0],c=i[1],s=t.useMemo((function(){return e.space.getCachedContentTypes().reduce((function(e,t){var n;return o({},e,((n={})[t.sys.id]=t,n))}),{})}),[e.space]),d=t.useCallback((function(t){return n.entityHelpers.getEntryTitle({entry:t,defaultTitle:"Untitled",localeCode:e.localeCode,defaultLocaleCode:e.defaultLocaleCode,contentType:s[t.sys.contentType.sys.id]})}),[e.localeCode,e.defaultLocaleCode,s]),f=[];return"conflicting"in e.error&&(f=e.error.conflicting),t.useEffect((function(){var t=a.entries.map((function(e){return e.id})),n=f.map((function(e){return e.sys.id}));if(!n.every((function(e){return t.includes(e)}))){c((function(e){return o({},e,{loading:!0})}));var r={"sys.id[in]":n.join(",")};e.space.getEntries(r).then((function(t){var n=t.items.map((function(t){return{id:t.sys.id,title:d(t),href:e.getEntryURL(t)}}));c({loading:!1,entries:n})}))}}),[d,a.entries,f,e.space.getEntries,e.getEntryURL]),t.createElement(r.List,{className:l,testId:"validation-errors-uniqueness"},t.createElement(r.ListItem,{className:u},a.loading?t.createElement("div",null,"Loading title for conflicting entry…"):a.entries.map((function(e){return t.createElement(r.TextLink,{key:e.id,href:e.href,icon:"ExternalLink",iconPosition:"right",linkType:"negative",target:"_blank",rel:"noopener noreferrer"},e.title)}))))}exports.ValidationErrors=function(e){var n=t.useState([]),i=n[0],a=n[1];return t.useEffect((function(){return e.field.onSchemaErrorsChanged((function(e){a(e||[])}))}),[e.field]),0===i.length?null:t.createElement(r.List,{className:l,testId:"validation-errors"},i.map((function(n,i){return t.createElement("li",{key:i,role:"status","aria-roledescription":"field-locale-schema","data-error-code":"entry.schema."+n.name,className:s},t.createElement(r.Icon,{icon:"InfoCircle",color:"negative"}),t.createElement("div",{className:c},n.message,"unique"===n.name&&t.createElement(d,{error:n,space:e.space,localeCode:e.field.locale,defaultLocaleCode:e.locales.default,getEntryURL:e.getEntryURL})))})))};
|
|
2
2
|
//# sourceMappingURL=field-editor-validation-errors.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-validation-errors.cjs.production.min.js","sources":["../src/styles.ts","../src/ValidationErrors.tsx"],"sourcesContent":["import { css } from 'emotion';\nimport tokens from '@contentful/forma-36-tokens';\n\nexport const errorList = css({\n padding: 0,\n wordWrap: 'break-word',\n marginTop: tokens.spacingS,\n color: tokens.red500,\n listStyleType: 'none',\n});\n\nexport const errorMessage = css({\n display: 'inline-flex',\n flexDirection: 'column',\n marginLeft: tokens.spacingXs,\n});\n\nexport const errorItem = css({\n display: 'flex',\n alignItems: 'center',\n});\n\nexport const entryLink = css({\n fontWeight: Number(tokens.fontWeightDemiBold),\n});\n","import React from 'react';\nimport type {\n SpaceAPI,\n Entry,\n ContentType,\n FieldAPI,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { entityHelpers } from '@contentful/field-editor-shared';\nimport { TextLink, List, ListItem, Icon } from '@contentful/forma-36-react-components';\n\nimport * as styles from './styles';\n\
|
|
1
|
+
{"version":3,"file":"field-editor-validation-errors.cjs.production.min.js","sources":["../src/styles.ts","../src/ValidationErrors.tsx"],"sourcesContent":["import { css } from 'emotion';\nimport tokens from '@contentful/forma-36-tokens';\n\nexport const errorList = css({\n padding: 0,\n wordWrap: 'break-word',\n marginTop: tokens.spacingS,\n color: tokens.red500,\n listStyleType: 'none',\n});\n\nexport const errorMessage = css({\n display: 'inline-flex',\n flexDirection: 'column',\n marginLeft: tokens.spacingXs,\n});\n\nexport const errorItem = css({\n display: 'flex',\n alignItems: 'center',\n});\n\nexport const entryLink = css({\n fontWeight: Number(tokens.fontWeightDemiBold),\n});\n","import React from 'react';\nimport { ValidationError, Link } from '@contentful/app-sdk';\nimport type {\n SpaceAPI,\n Entry,\n ContentType,\n FieldAPI,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { entityHelpers } from '@contentful/field-editor-shared';\nimport { TextLink, List, ListItem, Icon } from '@contentful/forma-36-react-components';\n\nimport * as styles from './styles';\n\ntype UniquenessErrorProps = {\n error: ValidationError;\n space: SpaceAPI;\n localeCode: string;\n defaultLocaleCode: string;\n getEntryURL: (entry: Entry) => string;\n};\n\nfunction UniquenessError(props: UniquenessErrorProps) {\n const [state, setState] = React.useState<{\n loading: boolean;\n entries: { id: string; title: string; href: string }[];\n }>({\n loading: true,\n entries: [],\n });\n\n const contentTypesById = React.useMemo(\n (): Record<string, ContentType> =>\n // Maps ID => Content Type\n props.space.getCachedContentTypes().reduce(\n (prev, ct) => ({\n ...prev,\n [ct.sys.id]: ct,\n }),\n {}\n ),\n [props.space]\n );\n\n const getTitle = React.useCallback(\n (entry: Entry) =>\n entityHelpers.getEntryTitle({\n entry,\n defaultTitle: 'Untitled',\n localeCode: props.localeCode,\n defaultLocaleCode: props.defaultLocaleCode,\n contentType: contentTypesById[entry.sys.contentType.sys.id],\n }),\n [props.localeCode, props.defaultLocaleCode, contentTypesById]\n );\n\n let conflicting: Link<'Entry', 'Link'>[] = [];\n if ('conflicting' in props.error) {\n conflicting = props.error.conflicting;\n }\n React.useEffect(() => {\n const entryIds = state.entries.map((entry) => entry.id);\n const conflictIds = conflicting.map((entry) => entry.sys.id);\n\n // Avoid unnecessary refetching\n if (conflictIds.every((id) => entryIds.includes(id))) {\n return;\n }\n\n setState((state) => ({ ...state, loading: true }));\n\n const query = {\n 'sys.id[in]': conflictIds.join(','),\n };\n\n props.space.getEntries<Entry>(query).then(({ items }) => {\n const entries = items.map((entry) => ({\n id: entry.sys.id,\n title: getTitle(entry),\n href: props.getEntryURL(entry),\n }));\n\n setState({\n loading: false,\n entries,\n });\n });\n }, [getTitle, state.entries, conflicting, props.space.getEntries, props.getEntryURL]);\n\n return (\n <List className={styles.errorList} testId=\"validation-errors-uniqueness\">\n <ListItem className={styles.entryLink}>\n {state.loading ? (\n <div>Loading title for conflicting entry…</div>\n ) : (\n state.entries.map((entry) => (\n <TextLink\n key={entry.id}\n href={entry.href}\n icon=\"ExternalLink\"\n iconPosition=\"right\"\n linkType=\"negative\"\n target=\"_blank\"\n rel=\"noopener noreferrer\">\n {entry.title}\n </TextLink>\n ))\n )}\n </ListItem>\n </List>\n );\n}\n\nexport interface ValidationErrorsProps {\n field: FieldAPI;\n space: SpaceAPI;\n locales: LocalesAPI;\n getEntryURL: (entry: Entry) => string;\n}\n\nexport function ValidationErrors(props: ValidationErrorsProps) {\n const [errors, setErrors] = React.useState<ValidationError[]>([]);\n\n React.useEffect(() => {\n const onErrors = (errors?: ValidationError[]) => {\n setErrors(errors || []);\n };\n\n return props.field.onSchemaErrorsChanged(onErrors);\n }, [props.field]);\n\n if (errors.length === 0) {\n return null;\n }\n\n return (\n <List className={styles.errorList} testId=\"validation-errors\">\n {errors.map((error, index) => {\n return (\n <li\n key={index}\n role=\"status\"\n aria-roledescription=\"field-locale-schema\"\n data-error-code={`entry.schema.${error.name}`}\n className={styles.errorItem}>\n <Icon icon=\"InfoCircle\" color=\"negative\" />\n <div className={styles.errorMessage}>\n {error.message}\n {error.name === 'unique' && (\n <UniquenessError\n error={error}\n space={props.space}\n localeCode={props.field.locale}\n defaultLocaleCode={props.locales.default}\n getEntryURL={props.getEntryURL}\n />\n )}\n </div>\n </li>\n );\n })}\n </List>\n );\n}\n"],"names":["errorList","css","padding","wordWrap","marginTop","tokens","spacingS","color","red500","listStyleType","errorMessage","display","flexDirection","marginLeft","spacingXs","errorItem","alignItems","entryLink","fontWeight","Number","fontWeightDemiBold","UniquenessError","props","React","useState","loading","entries","state","setState","contentTypesById","useMemo","space","getCachedContentTypes","reduce","prev","ct","sys","id","getTitle","useCallback","entry","entityHelpers","getEntryTitle","defaultTitle","localeCode","defaultLocaleCode","contentType","conflicting","error","useEffect","entryIds","map","conflictIds","every","includes","query","join","getEntries","then","items","title","href","getEntryURL","List","className","styles","testId","ListItem","TextLink","key","icon","iconPosition","linkType","target","rel","errors","setErrors","field","onSchemaErrorsChanged","length","index","role","name","Icon","message","locale","locales"],"mappings":"ohBAGO,IAAMA,EAAYC,MAAI,CAC3BC,QAAS,EACTC,SAAU,aACVC,UAAWC,EAAOC,SAClBC,MAAOF,EAAOG,OACdC,cAAe,SAGJC,EAAeT,MAAI,CAC9BU,QAAS,cACTC,cAAe,SACfC,WAAYR,EAAOS,YAGRC,EAAYd,MAAI,CAC3BU,QAAS,OACTK,WAAY,WAGDC,EAAYhB,MAAI,CAC3BiB,WAAYC,OAAOd,EAAOe,sBCD5B,SAASC,EAAgBC,SACGC,EAAMC,SAG7B,CACDC,SAAS,EACTC,QAAS,KALJC,OAAOC,OAQRC,EAAmBN,EAAMO,SAC7B,kBAEER,EAAMS,MAAMC,wBAAwBC,QAClC,SAACC,EAAMC,qBACFD,UACFC,EAAGC,IAAIC,IAAKF,QAEf,MAEJ,CAACb,EAAMS,QAGHO,EAAWf,EAAMgB,aACrB,SAACC,UACCC,gBAAcC,cAAc,CAC1BF,MAAAA,EACAG,aAAc,WACdC,WAAYtB,EAAMsB,WAClBC,kBAAmBvB,EAAMuB,kBACz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CS,EAAOxB,KAAI,SAACH,EAAOgC,UAEhBzD,sBACE8C,IAAKW,EACLC,KAAK,gCACgB,wDACYjC,EAAMkC,KACvClB,UAAWC,GACX1C,gBAAC4D,QAAKb,KAAK,aAAa/D,MAAM,aAC9BgB,uBAAKyC,UAAWC,GACbjB,EAAMoC,QACS,WAAfpC,EAAMkC,MACL3D,gBAACF,GACC2B,MAAOA,EACPjB,MAAOT,EAAMS,MACba,WAAYtB,EAAMuD,MAAMQ,OACxBxC,kBAAmBvB,EAAMgE,gBACzBxB,YAAaxC,EAAMwC"}
|
|
@@ -68,15 +68,19 @@ function UniquenessError(props) {
|
|
|
68
68
|
contentType: contentTypesById[entry.sys.contentType.sys.id]
|
|
69
69
|
});
|
|
70
70
|
}, [props.localeCode, props.defaultLocaleCode, contentTypesById]);
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
var conflicting = [];
|
|
72
|
+
|
|
73
|
+
if ('conflicting' in props.error) {
|
|
74
|
+
conflicting = props.error.conflicting;
|
|
75
|
+
}
|
|
73
76
|
|
|
77
|
+
React.useEffect(function () {
|
|
74
78
|
var entryIds = state.entries.map(function (entry) {
|
|
75
79
|
return entry.id;
|
|
76
80
|
});
|
|
77
|
-
var conflictIds =
|
|
81
|
+
var conflictIds = conflicting.map(function (entry) {
|
|
78
82
|
return entry.sys.id;
|
|
79
|
-
})
|
|
83
|
+
}); // Avoid unnecessary refetching
|
|
80
84
|
|
|
81
85
|
if (conflictIds.every(function (id) {
|
|
82
86
|
return entryIds.includes(id);
|
|
@@ -106,7 +110,7 @@ function UniquenessError(props) {
|
|
|
106
110
|
entries: entries
|
|
107
111
|
});
|
|
108
112
|
});
|
|
109
|
-
}, [getTitle, state.entries,
|
|
113
|
+
}, [getTitle, state.entries, conflicting, props.space.getEntries, props.getEntryURL]);
|
|
110
114
|
return React.createElement(List, {
|
|
111
115
|
className: errorList,
|
|
112
116
|
testId: "validation-errors-uniqueness"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-validation-errors.esm.js","sources":["../src/styles.ts","../src/ValidationErrors.tsx"],"sourcesContent":["import { css } from 'emotion';\nimport tokens from '@contentful/forma-36-tokens';\n\nexport const errorList = css({\n padding: 0,\n wordWrap: 'break-word',\n marginTop: tokens.spacingS,\n color: tokens.red500,\n listStyleType: 'none',\n});\n\nexport const errorMessage = css({\n display: 'inline-flex',\n flexDirection: 'column',\n marginLeft: tokens.spacingXs,\n});\n\nexport const errorItem = css({\n display: 'flex',\n alignItems: 'center',\n});\n\nexport const entryLink = css({\n fontWeight: Number(tokens.fontWeightDemiBold),\n});\n","import React from 'react';\nimport type {\n SpaceAPI,\n Entry,\n ContentType,\n FieldAPI,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { entityHelpers } from '@contentful/field-editor-shared';\nimport { TextLink, List, ListItem, Icon } from '@contentful/forma-36-react-components';\n\nimport * as styles from './styles';\n\nexport type ValidationError = {\n name: string;\n message: string;\n conflicting?: Array<{ sys: { id: string } }>;\n};\n\ntype UniquenessErrorProps = {\n error: ValidationError;\n space: SpaceAPI;\n localeCode: string;\n defaultLocaleCode: string;\n getEntryURL: (entry: Entry) => string;\n};\n\nfunction UniquenessError(props: UniquenessErrorProps) {\n const [state, setState] = React.useState<{\n loading: boolean;\n entries: { id: string; title: string; href: string }[];\n }>({\n loading: true,\n entries: [],\n });\n\n const contentTypesById = React.useMemo(\n (): Record<string, ContentType> =>\n // Maps ID => Content Type\n props.space.getCachedContentTypes().reduce(\n (prev, ct) => ({\n ...prev,\n [ct.sys.id]: ct,\n }),\n {}\n ),\n [props.space]\n );\n\n const getTitle = React.useCallback(\n (entry: Entry) =>\n entityHelpers.getEntryTitle({\n entry,\n defaultTitle: 'Untitled',\n localeCode: props.localeCode,\n defaultLocaleCode: props.defaultLocaleCode,\n contentType: contentTypesById[entry.sys.contentType.sys.id],\n }),\n [props.localeCode, props.defaultLocaleCode, contentTypesById]\n );\n\n React.useEffect(() => {\n const entryIds = state.entries.map((entry) => entry.id);\n const conflictIds = props.error.conflicting?.map((entry) => entry.sys.id) || [];\n\n // Avoid unnecessary refetching\n if (conflictIds.every((id) => entryIds.includes(id))) {\n return;\n }\n\n setState((state) => ({ ...state, loading: true }));\n\n const query = {\n 'sys.id[in]': conflictIds.join(','),\n };\n\n props.space.getEntries<Entry>(query).then(({ items }) => {\n const entries = items.map((entry) => ({\n id: entry.sys.id,\n title: getTitle(entry),\n href: props.getEntryURL(entry),\n }));\n\n setState({\n loading: false,\n entries,\n });\n });\n }, [getTitle, state.entries, props.error.conflicting, props.space.getEntries, props.getEntryURL]);\n\n return (\n <List className={styles.errorList} testId=\"validation-errors-uniqueness\">\n <ListItem className={styles.entryLink}>\n {state.loading ? (\n <div>Loading title for conflicting entry…</div>\n ) : (\n state.entries.map((entry) => (\n <TextLink\n key={entry.id}\n href={entry.href}\n icon=\"ExternalLink\"\n iconPosition=\"right\"\n linkType=\"negative\"\n target=\"_blank\"\n rel=\"noopener noreferrer\">\n {entry.title}\n </TextLink>\n ))\n )}\n </ListItem>\n </List>\n );\n}\n\nexport interface ValidationErrorsProps {\n field: FieldAPI;\n space: SpaceAPI;\n locales: LocalesAPI;\n getEntryURL: (entry: Entry) => string;\n}\n\nexport function ValidationErrors(props: ValidationErrorsProps) {\n const [errors, setErrors] = React.useState<ValidationError[]>([]);\n\n React.useEffect(() => {\n const onErrors = (errors?: ValidationError[]) => {\n setErrors(errors || []);\n };\n\n return props.field.onSchemaErrorsChanged(onErrors);\n }, [props.field]);\n\n if (errors.length === 0) {\n return null;\n }\n\n return (\n <List className={styles.errorList} testId=\"validation-errors\">\n {errors.map((error, index) => {\n return (\n <li\n key={index}\n role=\"status\"\n aria-roledescription=\"field-locale-schema\"\n data-error-code={`entry.schema.${error.name}`}\n className={styles.errorItem}>\n <Icon icon=\"InfoCircle\" color=\"negative\" />\n <div className={styles.errorMessage}>\n {error.message}\n {error.name === 'unique' && (\n <UniquenessError\n error={error}\n space={props.space}\n localeCode={props.field.locale}\n defaultLocaleCode={props.locales.default}\n getEntryURL={props.getEntryURL}\n />\n )}\n </div>\n </li>\n );\n })}\n </List>\n );\n}\n"],"names":["errorList","css","padding","wordWrap","marginTop","tokens","spacingS","color","red500","listStyleType","errorMessage","display","flexDirection","marginLeft","spacingXs","errorItem","alignItems","entryLink","fontWeight","Number","fontWeightDemiBold","UniquenessError","props","React","useState","loading","entries","state","setState","contentTypesById","useMemo","space","getCachedContentTypes","reduce","prev","ct","sys","id","getTitle","useCallback","entry","entityHelpers","getEntryTitle","defaultTitle","localeCode","defaultLocaleCode","contentType","useEffect","entryIds","map","conflictIds","error","conflicting","every","includes","query","join","getEntries","then","items","title","href","getEntryURL","List","className","styles","testId","ListItem","TextLink","key","icon","iconPosition","linkType","target","rel","ValidationErrors","errors","setErrors","onErrors","field","onSchemaErrorsChanged","length","index","role","name","Icon","message","locale","locales"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAMA,SAAS,gBAAGC,GAAG,CAAC;AAC3BC,EAAAA,OAAO,EAAE,CADkB;AAE3BC,EAAAA,QAAQ,EAAE,YAFiB;AAG3BC,EAAAA,SAAS,EAAEC,MAAM,CAACC,QAHS;AAI3BC,EAAAA,KAAK,EAAEF,MAAM,CAACG,MAJa;AAK3BC,EAAAA,aAAa,EAAE;AALY,CAAD,CAArB;AAQA,IAAMC,YAAY,gBAAGT,GAAG,CAAC;AAC9BU,EAAAA,OAAO,EAAE,aADqB;AAE9BC,EAAAA,aAAa,EAAE,QAFe;AAG9BC,EAAAA,UAAU,EAAER,MAAM,CAACS;AAHW,CAAD,CAAxB;AAMA,IAAMC,SAAS,gBAAGd,GAAG,CAAC;AAC3BU,EAAAA,OAAO,EAAE,MADkB;AAE3BK,EAAAA,UAAU,EAAE;AAFe,CAAD,CAArB;AAKA,IAAMC,SAAS,gBAAGhB,GAAG,CAAC;AAC3BiB,EAAAA,UAAU,eAAEC,MAAM,CAACd,MAAM,CAACe,kBAAR;AADS,CAAD,CAArB;;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AAA,IAAI,EAAC;8BACgB;2CACYhC,KAAK,CAACiC;AACvCpB,MAAAA,SAAS,EAAEC;KALb,EAME1C,mBAAA,CAAC8D,IAAD;AAAMf,MAAAA,IAAI,EAAC;AAAa/D,MAAAA,KAAK,EAAC;KAA9B,CANF,EAOEgB,mBAAA,MAAA;AAAKyC,MAAAA,SAAS,EAAEC;KAAhB,EACGd,KAAK,CAACmC,OADT,EAEGnC,KAAK,CAACiC,IAAN,KAAe,QAAf,IACC7D,mBAAA,CAACF,eAAD;AACE8B,MAAAA,KAAK,EAAEA;AACPpB,MAAAA,KAAK,EAAET,KAAK,CAACS;AACba,MAAAA,UAAU,EAAEtB,KAAK,CAACyD,KAAN,CAAYQ;AACxB1C,MAAAA,iBAAiB,EAAEvB,KAAK,CAACkE,OAAN;AACnB1B,MAAAA,WAAW,EAAExC,KAAK,CAACwC;KALrB,CAHJ,CAPF,CADF;AAsBD,GAvBA,CADH,CADF;AA4BD;;;;"}
|
|
1
|
+
{"version":3,"file":"field-editor-validation-errors.esm.js","sources":["../src/styles.ts","../src/ValidationErrors.tsx"],"sourcesContent":["import { css } from 'emotion';\nimport tokens from '@contentful/forma-36-tokens';\n\nexport const errorList = css({\n padding: 0,\n wordWrap: 'break-word',\n marginTop: tokens.spacingS,\n color: tokens.red500,\n listStyleType: 'none',\n});\n\nexport const errorMessage = css({\n display: 'inline-flex',\n flexDirection: 'column',\n marginLeft: tokens.spacingXs,\n});\n\nexport const errorItem = css({\n display: 'flex',\n alignItems: 'center',\n});\n\nexport const entryLink = css({\n fontWeight: Number(tokens.fontWeightDemiBold),\n});\n","import React from 'react';\nimport { ValidationError, Link } from '@contentful/app-sdk';\nimport type {\n SpaceAPI,\n Entry,\n ContentType,\n FieldAPI,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { entityHelpers } from '@contentful/field-editor-shared';\nimport { TextLink, List, ListItem, Icon } from '@contentful/forma-36-react-components';\n\nimport * as styles from './styles';\n\ntype UniquenessErrorProps = {\n error: ValidationError;\n space: SpaceAPI;\n localeCode: string;\n defaultLocaleCode: string;\n getEntryURL: (entry: Entry) => string;\n};\n\nfunction UniquenessError(props: UniquenessErrorProps) {\n const [state, setState] = React.useState<{\n loading: boolean;\n entries: { id: string; title: string; href: string }[];\n }>({\n loading: true,\n entries: [],\n });\n\n const contentTypesById = React.useMemo(\n (): Record<string, ContentType> =>\n // Maps ID => Content Type\n props.space.getCachedContentTypes().reduce(\n (prev, ct) => ({\n ...prev,\n [ct.sys.id]: ct,\n }),\n {}\n ),\n [props.space]\n );\n\n const getTitle = React.useCallback(\n (entry: Entry) =>\n entityHelpers.getEntryTitle({\n entry,\n defaultTitle: 'Untitled',\n localeCode: props.localeCode,\n defaultLocaleCode: props.defaultLocaleCode,\n contentType: contentTypesById[entry.sys.contentType.sys.id],\n }),\n [props.localeCode, props.defaultLocaleCode, contentTypesById]\n );\n\n let conflicting: Link<'Entry', 'Link'>[] = [];\n if ('conflicting' in props.error) {\n conflicting = props.error.conflicting;\n }\n React.useEffect(() => {\n const entryIds = state.entries.map((entry) => entry.id);\n const conflictIds = conflicting.map((entry) => entry.sys.id);\n\n // Avoid unnecessary refetching\n if (conflictIds.every((id) => entryIds.includes(id))) {\n return;\n }\n\n setState((state) => ({ ...state, loading: true }));\n\n const query = {\n 'sys.id[in]': conflictIds.join(','),\n };\n\n props.space.getEntries<Entry>(query).then(({ items }) => {\n const entries = items.map((entry) => ({\n id: entry.sys.id,\n title: getTitle(entry),\n href: props.getEntryURL(entry),\n }));\n\n setState({\n loading: false,\n entries,\n });\n });\n }, [getTitle, state.entries, conflicting, props.space.getEntries, props.getEntryURL]);\n\n return (\n <List className={styles.errorList} testId=\"validation-errors-uniqueness\">\n <ListItem className={styles.entryLink}>\n {state.loading ? (\n <div>Loading title for conflicting entry…</div>\n ) : (\n state.entries.map((entry) => (\n <TextLink\n key={entry.id}\n href={entry.href}\n icon=\"ExternalLink\"\n iconPosition=\"right\"\n linkType=\"negative\"\n target=\"_blank\"\n rel=\"noopener noreferrer\">\n {entry.title}\n </TextLink>\n ))\n )}\n </ListItem>\n </List>\n );\n}\n\nexport interface ValidationErrorsProps {\n field: FieldAPI;\n space: SpaceAPI;\n locales: LocalesAPI;\n getEntryURL: (entry: Entry) => string;\n}\n\nexport function ValidationErrors(props: ValidationErrorsProps) {\n const [errors, setErrors] = React.useState<ValidationError[]>([]);\n\n React.useEffect(() => {\n const onErrors = (errors?: ValidationError[]) => {\n setErrors(errors || []);\n };\n\n return props.field.onSchemaErrorsChanged(onErrors);\n }, [props.field]);\n\n if (errors.length === 0) {\n return null;\n }\n\n return (\n <List className={styles.errorList} testId=\"validation-errors\">\n {errors.map((error, index) => {\n return (\n <li\n key={index}\n role=\"status\"\n aria-roledescription=\"field-locale-schema\"\n data-error-code={`entry.schema.${error.name}`}\n className={styles.errorItem}>\n <Icon icon=\"InfoCircle\" color=\"negative\" />\n <div className={styles.errorMessage}>\n {error.message}\n {error.name === 'unique' && (\n <UniquenessError\n error={error}\n space={props.space}\n localeCode={props.field.locale}\n defaultLocaleCode={props.locales.default}\n getEntryURL={props.getEntryURL}\n />\n )}\n </div>\n </li>\n );\n })}\n </List>\n );\n}\n"],"names":["errorList","css","padding","wordWrap","marginTop","tokens","spacingS","color","red500","listStyleType","errorMessage","display","flexDirection","marginLeft","spacingXs","errorItem","alignItems","entryLink","fontWeight","Number","fontWeightDemiBold","UniquenessError","props","React","useState","loading","entries","state","setState","contentTypesById","useMemo","space","getCachedContentTypes","reduce","prev","ct","sys","id","getTitle","useCallback","entry","entityHelpers","getEntryTitle","defaultTitle","localeCode","defaultLocaleCode","contentType","conflicting","error","useEffect","entryIds","map","conflictIds","every","includes","query","join","getEntries","then","items","title","href","getEntryURL","List","className","styles","testId","ListItem","TextLink","key","icon","iconPosition","linkType","target","rel","ValidationErrors","errors","setErrors","onErrors","field","onSchemaErrorsChanged","length","index","role","name","Icon","message","locale","locales"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAMA,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W,EAAExC,KAAK,CAACwC;KALrB,CAHJ,CAPF,CADF;AAsBD,GAvBA,CADH,CADF;AA4BD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-validation-errors",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/field-editor-validation-errors.esm.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"tsc": "tsc -p ./ --noEmit"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@contentful/field-editor-shared": "^0.
|
|
24
|
+
"@contentful/field-editor-shared": "^0.25.0",
|
|
25
25
|
"@contentful/forma-36-react-components": "^3.93.4",
|
|
26
26
|
"@contentful/forma-36-tokens": "^0.11.0",
|
|
27
27
|
"emotion": "^10.0.17"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@contentful/field-editor-test-utils": "^0.
|
|
30
|
+
"@contentful/field-editor-test-utils": "^0.18.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": ">=16.8.0"
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "917572e21ded4ddb74828b2e1b2ce7bdc1c14fc8"
|
|
46
46
|
}
|