@contentful/field-editor-shared 1.4.8 → 1.5.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.
@@ -63,17 +63,15 @@ const styles = {
63
63
  })
64
64
  };
65
65
  function CharCounter(props) {
66
- const { constraints, value, checkConstraint } = props;
67
66
  let count = 0;
68
- if (value) {
69
- count = value.length;
67
+ if (props.value) {
68
+ count = props.value.length;
70
69
  }
71
- const valid = count === 0 || checkConstraint(count);
70
+ const valid = count === 0 || props.checkConstraint(count);
72
71
  return _react.createElement("span", {
73
72
  "data-status-code": valid ? null : 'invalid-size',
74
- "data-test-id": "cf-ui-char-counter",
75
73
  className: (0, _emotion.cx)({
76
74
  [styles.invalid]: !valid
77
75
  })
78
- }, constraints.type === 'min' ? `${count}` : `${count} / ${constraints.max}`);
76
+ }, count, " characters");
79
77
  }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "CharValidation", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return CharValidation;
9
+ }
10
+ });
11
+ const _react = _interop_require_wildcard(require("react"));
12
+ function _getRequireWildcardCache(nodeInterop) {
13
+ if (typeof WeakMap !== "function") return null;
14
+ var cacheBabelInterop = new WeakMap();
15
+ var cacheNodeInterop = new WeakMap();
16
+ return (_getRequireWildcardCache = function(nodeInterop) {
17
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
18
+ })(nodeInterop);
19
+ }
20
+ function _interop_require_wildcard(obj, nodeInterop) {
21
+ if (!nodeInterop && obj && obj.__esModule) {
22
+ return obj;
23
+ }
24
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
25
+ return {
26
+ default: obj
27
+ };
28
+ }
29
+ var cache = _getRequireWildcardCache(nodeInterop);
30
+ if (cache && cache.has(obj)) {
31
+ return cache.get(obj);
32
+ }
33
+ var newObj = {
34
+ __proto__: null
35
+ };
36
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
37
+ for(var key in obj){
38
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
39
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
40
+ if (desc && (desc.get || desc.set)) {
41
+ Object.defineProperty(newObj, key, desc);
42
+ } else {
43
+ newObj[key] = obj[key];
44
+ }
45
+ }
46
+ }
47
+ newObj.default = obj;
48
+ if (cache) {
49
+ cache.set(obj, newObj);
50
+ }
51
+ return newObj;
52
+ }
53
+ function CharValidation(props) {
54
+ const { constraints } = props;
55
+ if (constraints.type === 'max') {
56
+ return _react.createElement("span", null, "Maximum ", constraints.max, " characters");
57
+ } else if (constraints.type === 'min') {
58
+ return _react.createElement("span", null, "Requires at least ", constraints.min, " characters");
59
+ } else {
60
+ return _react.createElement("span", null, "Requires between ", constraints.min, " and ", constraints.max, " characters");
61
+ }
62
+ }
package/dist/cjs/index.js CHANGED
@@ -24,6 +24,9 @@ _export(exports, {
24
24
  CharCounter: function() {
25
25
  return _CharCounter.CharCounter;
26
26
  },
27
+ CharValidation: function() {
28
+ return _CharValidation.CharValidation;
29
+ },
27
30
  ConstraintsUtils: function() {
28
31
  return _constraints;
29
32
  },
@@ -102,6 +105,7 @@ _export(exports, {
102
105
  });
103
106
  const _appsdk = require("@contentful/app-sdk");
104
107
  const _CharCounter = require("./CharCounter");
108
+ const _CharValidation = require("./CharValidation");
105
109
  const _FieldConnector = require("./FieldConnector");
106
110
  const _PredefinedValuesError = require("./PredefinedValuesError");
107
111
  const _typesEntity = require("./typesEntity");
@@ -160,7 +160,7 @@ function getEntryTitle({ entry, contentType, localeCode, defaultLocaleCode, defa
160
160
  }
161
161
  return titleOrDefault(title, defaultTitle);
162
162
  }
163
- function getEntryStatus(sys) {
163
+ function getEntryStatus(sys, localeCodes) {
164
164
  if (!sys || sys.type !== 'Entry' && sys.type !== 'Asset') {
165
165
  throw new TypeError('Invalid entity metadata object');
166
166
  }
@@ -168,6 +168,26 @@ function getEntryStatus(sys) {
168
168
  return 'deleted';
169
169
  } else if (sys.archivedVersion) {
170
170
  return 'archived';
171
+ } else if (sys.fieldStatus) {
172
+ let status = 'draft';
173
+ const condition = (locale)=>{
174
+ if (Array.isArray(localeCodes)) {
175
+ return localeCodes.includes(locale);
176
+ }
177
+ return localeCodes ? localeCodes === locale : true;
178
+ };
179
+ Object.entries(sys.fieldStatus['*']).forEach(([localeCode, fieldStatus])=>{
180
+ if (condition(localeCode)) {
181
+ if (fieldStatus === 'changed') {
182
+ status = fieldStatus;
183
+ return;
184
+ }
185
+ if (fieldStatus === 'published') {
186
+ status = fieldStatus;
187
+ }
188
+ }
189
+ });
190
+ return status;
171
191
  } else if (sys.publishedVersion) {
172
192
  if (sys.version > sys.publishedVersion + 1) {
173
193
  return 'changed';
@@ -7,17 +7,15 @@ const styles = {
7
7
  })
8
8
  };
9
9
  export function CharCounter(props) {
10
- const { constraints, value, checkConstraint } = props;
11
10
  let count = 0;
12
- if (value) {
13
- count = value.length;
11
+ if (props.value) {
12
+ count = props.value.length;
14
13
  }
15
- const valid = count === 0 || checkConstraint(count);
14
+ const valid = count === 0 || props.checkConstraint(count);
16
15
  return React.createElement("span", {
17
16
  "data-status-code": valid ? null : 'invalid-size',
18
- "data-test-id": "cf-ui-char-counter",
19
17
  className: cx({
20
18
  [styles.invalid]: !valid
21
19
  })
22
- }, constraints.type === 'min' ? `${count}` : `${count} / ${constraints.max}`);
20
+ }, count, " characters");
23
21
  }
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ export function CharValidation(props) {
3
+ const { constraints } = props;
4
+ if (constraints.type === 'max') {
5
+ return React.createElement("span", null, "Maximum ", constraints.max, " characters");
6
+ } else if (constraints.type === 'min') {
7
+ return React.createElement("span", null, "Requires at least ", constraints.min, " characters");
8
+ } else {
9
+ return React.createElement("span", null, "Requires between ", constraints.min, " and ", constraints.max, " characters");
10
+ }
11
+ }
package/dist/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { AccessAPI, AppConfigAPI, BaseAppSDK, ContentType, DialogsAPI, EntryAPI, EntryFieldAPI, FieldAPI, FieldAppSDK, IdsAPI, LocalesAPI, LocationAPI, NavigatorAPI, NotifierAPI, OpenCustomWidgetOptions, ParametersAPI, SpaceAPI, WindowAPI } from '@contentful/app-sdk';
2
2
  export { CharCounter } from './CharCounter';
3
+ export { CharValidation } from './CharValidation';
3
4
  export { FieldConnector } from './FieldConnector';
4
5
  export { PredefinedValuesError } from './PredefinedValuesError';
5
6
  export { Asset, Entry, File } from './typesEntity';
@@ -116,7 +116,7 @@ export function getEntryTitle({ entry, contentType, localeCode, defaultLocaleCod
116
116
  }
117
117
  return titleOrDefault(title, defaultTitle);
118
118
  }
119
- export function getEntryStatus(sys) {
119
+ export function getEntryStatus(sys, localeCodes) {
120
120
  if (!sys || sys.type !== 'Entry' && sys.type !== 'Asset') {
121
121
  throw new TypeError('Invalid entity metadata object');
122
122
  }
@@ -124,6 +124,26 @@ export function getEntryStatus(sys) {
124
124
  return 'deleted';
125
125
  } else if (sys.archivedVersion) {
126
126
  return 'archived';
127
+ } else if (sys.fieldStatus) {
128
+ let status = 'draft';
129
+ const condition = (locale)=>{
130
+ if (Array.isArray(localeCodes)) {
131
+ return localeCodes.includes(locale);
132
+ }
133
+ return localeCodes ? localeCodes === locale : true;
134
+ };
135
+ Object.entries(sys.fieldStatus['*']).forEach(([localeCode, fieldStatus])=>{
136
+ if (condition(localeCode)) {
137
+ if (fieldStatus === 'changed') {
138
+ status = fieldStatus;
139
+ return;
140
+ }
141
+ if (fieldStatus === 'published') {
142
+ status = fieldStatus;
143
+ }
144
+ }
145
+ });
146
+ return status;
127
147
  } else if (sys.publishedVersion) {
128
148
  if (sys.version > sys.publishedVersion + 1) {
129
149
  return 'changed';
@@ -1,9 +1,7 @@
1
1
  /// <reference types="react" />
2
- import { ValidationType } from 'types';
3
2
  interface CharCounterProps {
4
3
  value?: string;
5
4
  checkConstraint: (n: number) => boolean;
6
- constraints: ValidationType;
7
5
  }
8
6
  export declare function CharCounter(props: CharCounterProps): JSX.Element;
9
7
  export {};
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { ValidationType } from './types';
3
+ interface CharValidationProps {
4
+ constraints: ValidationType;
5
+ }
6
+ export declare function CharValidation(props: CharValidationProps): JSX.Element;
7
+ export {};
@@ -1,5 +1,6 @@
1
1
  export { AccessAPI, AppConfigAPI, BaseAppSDK, ContentType, DialogsAPI, EntryAPI, EntryFieldAPI, FieldAPI, FieldAppSDK, IdsAPI, LocalesAPI, LocationAPI, NavigatorAPI, NotifierAPI, OpenCustomWidgetOptions, ParametersAPI, SpaceAPI, WindowAPI, } from '@contentful/app-sdk';
2
2
  export { CharCounter } from './CharCounter';
3
+ export { CharValidation } from './CharValidation';
3
4
  export { FieldConnector } from './FieldConnector';
4
5
  export type { FieldConnectorChildProps } from './FieldConnector';
5
6
  export { PredefinedValuesError } from './PredefinedValuesError';
@@ -55,7 +55,13 @@ export declare function getEntryTitle({ entry, contentType, localeCode, defaultL
55
55
  defaultLocaleCode: string;
56
56
  defaultTitle: string;
57
57
  }): string;
58
- export declare function getEntryStatus(sys: Entry['sys']): "deleted" | "archived" | "changed" | "published" | "draft";
58
+ type AsyncPublishStatus = 'draft' | 'published' | 'changed';
59
+ type FieldStatus = {
60
+ '*': Record<string, AsyncPublishStatus>;
61
+ };
62
+ export declare function getEntryStatus(sys: Entry['sys'] & {
63
+ fieldStatus?: FieldStatus;
64
+ }, localeCodes?: string | string[]): "draft" | "published" | "changed" | "deleted" | "archived";
59
65
  /**
60
66
  * Gets a promise resolving with a localized asset image field representing a
61
67
  * given entities file. The promise may resolve with null.
@@ -66,3 +72,4 @@ export declare const getEntryImage: ({ entry, contentType, localeCode, }: {
66
72
  localeCode: string;
67
73
  defaultLocaleCode: string;
68
74
  }, getAsset: (assetId: string) => Promise<unknown>) => Promise<null | File>;
75
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-shared",
3
- "version": "1.4.8",
3
+ "version": "1.5.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -51,5 +51,5 @@
51
51
  "publishConfig": {
52
52
  "registry": "https://npm.pkg.github.com/"
53
53
  },
54
- "gitHead": "1d7d630fe6f9576ee4cf35feed8badc8440acbf1"
54
+ "gitHead": "843655f104af6fb8c116869d59cd9f20e6f1ab14"
55
55
  }