@contentful/field-editor-validation-errors 1.1.11 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,175 +0,0 @@
1
- import React from 'react';
2
- import { entityHelpers } from '@contentful/field-editor-shared';
3
- import { css } from 'emotion';
4
- import tokens from '@contentful/f36-tokens';
5
- import { List, ListItem, TextLink } from '@contentful/f36-components';
6
- import { InfoCircleIcon, ExternalLinkIcon } from '@contentful/f36-icons';
7
-
8
- function _extends() {
9
- _extends = Object.assign || function (target) {
10
- for (var i = 1; i < arguments.length; i++) {
11
- var source = arguments[i];
12
-
13
- for (var key in source) {
14
- if (Object.prototype.hasOwnProperty.call(source, key)) {
15
- target[key] = source[key];
16
- }
17
- }
18
- }
19
-
20
- return target;
21
- };
22
-
23
- return _extends.apply(this, arguments);
24
- }
25
-
26
- var errorList = /*#__PURE__*/css({
27
- padding: 0,
28
- wordWrap: 'break-word',
29
- marginTop: tokens.spacingS,
30
- color: tokens.red500,
31
- listStyleType: 'none'
32
- });
33
- var errorMessage = /*#__PURE__*/css({
34
- display: 'inline-flex',
35
- flexDirection: 'column',
36
- marginLeft: tokens.spacingXs
37
- });
38
- var errorItem = /*#__PURE__*/css({
39
- display: 'flex',
40
- alignItems: 'center'
41
- });
42
- var entryLink = /*#__PURE__*/css({
43
- fontWeight: /*#__PURE__*/Number(tokens.fontWeightDemiBold)
44
- });
45
-
46
- function UniquenessError(props) {
47
- var _React$useState = React.useState({
48
- loading: true,
49
- entries: []
50
- }),
51
- state = _React$useState[0],
52
- setState = _React$useState[1];
53
-
54
- var contentTypesById = React.useMemo(function () {
55
- return (// Maps ID => Content Type
56
- props.space.getCachedContentTypes().reduce(function (prev, ct) {
57
- var _extends2;
58
-
59
- return _extends({}, prev, (_extends2 = {}, _extends2[ct.sys.id] = ct, _extends2));
60
- }, {})
61
- );
62
- }, [props.space]);
63
- var getTitle = React.useCallback(function (entry) {
64
- return entityHelpers.getEntryTitle({
65
- entry: entry,
66
- defaultTitle: 'Untitled',
67
- localeCode: props.localeCode,
68
- defaultLocaleCode: props.defaultLocaleCode,
69
- contentType: contentTypesById[entry.sys.contentType.sys.id]
70
- });
71
- }, [props.localeCode, props.defaultLocaleCode, contentTypesById]);
72
- var conflicting = [];
73
-
74
- if ('conflicting' in props.error) {
75
- conflicting = props.error.conflicting;
76
- }
77
-
78
- React.useEffect(function () {
79
- var entryIds = state.entries.map(function (entry) {
80
- return entry.id;
81
- });
82
- var conflictIds = conflicting.map(function (entry) {
83
- return entry.sys.id;
84
- }); // Avoid unnecessary refetching
85
-
86
- if (conflictIds.every(function (id) {
87
- return entryIds.includes(id);
88
- })) {
89
- return;
90
- }
91
-
92
- setState(function (state) {
93
- return _extends({}, state, {
94
- loading: true
95
- });
96
- });
97
- var query = {
98
- 'sys.id[in]': conflictIds.join(',')
99
- };
100
- props.space.getEntries(query).then(function (_ref) {
101
- var items = _ref.items;
102
- var entries = items.map(function (entry) {
103
- return {
104
- id: entry.sys.id,
105
- title: getTitle(entry),
106
- href: props.getEntryURL(entry)
107
- };
108
- });
109
- setState({
110
- loading: false,
111
- entries: entries
112
- });
113
- }); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate these dependencies
114
- }, [getTitle, state.entries, conflicting, props.space.getEntries, props.getEntryURL]);
115
- return React.createElement(List, {
116
- className: errorList,
117
- testId: "validation-errors-uniqueness"
118
- }, React.createElement(ListItem, {
119
- className: entryLink
120
- }, state.loading ? React.createElement("div", null, "Loading title for conflicting entry\u2026") : state.entries.map(function (entry) {
121
- return React.createElement(TextLink, {
122
- key: entry.id,
123
- href: entry.href,
124
- icon: React.createElement(ExternalLinkIcon, null),
125
- alignIcon: "end",
126
- variant: "negative",
127
- target: "_blank",
128
- rel: "noopener noreferrer"
129
- }, entry.title);
130
- })));
131
- }
132
-
133
- function ValidationErrors(props) {
134
- var _React$useState2 = React.useState([]),
135
- errors = _React$useState2[0],
136
- setErrors = _React$useState2[1];
137
-
138
- React.useEffect(function () {
139
- var onErrors = function onErrors(errors) {
140
- setErrors(errors || []);
141
- };
142
-
143
- return props.field.onSchemaErrorsChanged(onErrors);
144
- }, [props.field]);
145
-
146
- if (errors.length === 0) {
147
- return null;
148
- }
149
-
150
- return React.createElement(List, {
151
- className: errorList,
152
- testId: "validation-errors"
153
- }, errors.map(function (error, index) {
154
- return React.createElement("li", {
155
- key: index,
156
- role: "status",
157
- "aria-roledescription": "field-locale-schema",
158
- "data-error-code": "entry.schema." + error.name,
159
- className: errorItem
160
- }, React.createElement(InfoCircleIcon, {
161
- variant: "negative"
162
- }), React.createElement("div", {
163
- className: errorMessage
164
- }, error.message, error.name === 'unique' && React.createElement(UniquenessError, {
165
- error: error,
166
- space: props.space,
167
- localeCode: props.field.locale,
168
- defaultLocaleCode: props.locales["default"],
169
- getEntryURL: props.getEntryURL
170
- })));
171
- }));
172
- }
173
-
174
- export { ValidationErrors };
175
- //# sourceMappingURL=field-editor-validation-errors.esm.js.map
@@ -1 +0,0 @@
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/f36-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';\n\nimport * as styles from './styles';\n\nimport { TextLink, List, ListItem } from '@contentful/f36-components';\n\nimport { ExternalLinkIcon, InfoCircleIcon } from '@contentful/f36-icons';\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 // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate these dependencies\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={<ExternalLinkIcon />}\n alignIcon=\"end\"\n variant=\"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 <InfoCircleIcon variant=\"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","ExternalLinkIcon","alignIcon","variant","target","rel","ValidationErrors","errors","setErrors","onErrors","field","onSchemaErrorsChanged","length","index","role","name","InfoCircleIcon","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;;ACGP,SAASC,eAAT,CAAyBC,KAAzB;AACE,wBAA0BC,KAAK,CAACC,QAAN,CAGvB;AACDC,IAAAA,OAAO,EAAE,IADR;AAEDC,IAAAA,OAAO,EAAE;AAFR,GAHuB,CAA1B;AAAA,MAAOC,KAAP;AAAA,MAAcC,QAAd;;AAQA,MAAMC,gBAAgB,GAAGN,KAAK,CAACO,OAAN,CACvB;AAAA;AAEER,MAAAA,KAAK,CAACS,KAAN,CAAYC,qBAAZ,GAAoCC,MAApC,CACE,UAACC,IAAD,EAAOC,EAAP;AAAA;;AAAA,4BACKD,IADL,6BAEGC,EAAE,CAACC,GAAH,CAAOC,EAFV,IAEeF,EAFf;AAAA,OADF,EAKE,EALF;AAFF;AAAA,GAD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EAAET,KAAK,CAACS;AACba,MAAAA,UAAU,EAAEtB,KAAK,CAAC0D,KAAN,CAAYQ;AACxB3C,MAAAA,iBAAiB,EAAEvB,KAAK,CAACmE,OAAN;AACnB3B,MAAAA,WAAW,EAAExC,KAAK,CAACwC;KALrB,CAHJ,CAPF,CADF;AAsBD,GAvBA,CADH,CADF;AA4BD;;;;"}
package/dist/index.js DELETED
@@ -1,8 +0,0 @@
1
-
2
- 'use strict'
3
-
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./field-editor-validation-errors.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./field-editor-validation-errors.cjs.development.js')
8
- }