@contentful/field-editor-shared 2.8.0 → 2.9.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/dist/cjs/index.js CHANGED
@@ -111,13 +111,15 @@ const _PredefinedValuesError = require("./PredefinedValuesError");
111
111
  const _typesEntity = require("./typesEntity");
112
112
  const _isValidImage = require("./utils/isValidImage");
113
113
  const _shortenStorageUnit = require("./utils/shortenStorageUnit");
114
- _export_star(require("./utils/parseReleaseParameters"), exports);
115
- _export_star(require("./hooks/useLocalePublishStatus"), exports);
116
- _export_star(require("./hooks/useActiveLocales"), exports);
117
114
  _export_star(require("./types"), exports);
115
+ _export_star(require("./hooks/useActiveLocales"), exports);
118
116
  _export_star(require("./hooks/useActiveReleaseLocalesStatuses"), exports);
117
+ _export_star(require("./hooks/useLocalePublishStatus"), exports);
119
118
  _export_star(require("./LocalePublishingEntityStatusBadge"), exports);
120
119
  _export_star(require("./ReleaseEntityStatusBadge"), exports);
120
+ _export_star(require("./utils/determineReleaseAction"), exports);
121
+ _export_star(require("./utils/getEntryReleaseStatus"), exports);
122
+ _export_star(require("./utils/parseReleaseParameters"), exports);
121
123
  const _ModalDialogLauncher = /*#__PURE__*/ _interop_require_wildcard(require("./ModalDialogLauncher"));
122
124
  const _constraints = /*#__PURE__*/ _interop_require_wildcard(require("./utils/constraints"));
123
125
  const _entityHelpers = /*#__PURE__*/ _interop_require_wildcard(require("./utils/entityHelpers"));
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "determineReleaseAction", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return determineReleaseAction;
9
+ }
10
+ });
11
+ function isEntryBasedAction(entityItem) {
12
+ return 'action' in entityItem && (entityItem.action === 'publish' || entityItem.action === 'unpublish');
13
+ }
14
+ function getLocalesFromEntity(entityItem) {
15
+ const addLocales = entityItem?.add?.fields?.['*'] ?? [];
16
+ const removeLocales = entityItem?.remove?.fields?.['*'] ?? [];
17
+ return {
18
+ addLocales,
19
+ removeLocales
20
+ };
21
+ }
22
+ function getLocaleBasedAction(addLocales, removeLocales) {
23
+ const hasPublish = addLocales.length > 0;
24
+ const hasUnpublish = removeLocales.length > 0;
25
+ if (hasPublish && !hasUnpublish) {
26
+ return 'publish';
27
+ }
28
+ if (!hasPublish && hasUnpublish) {
29
+ return 'unpublish';
30
+ }
31
+ return 'publish';
32
+ }
33
+ function determineReleaseAction(entryId, release) {
34
+ if (!release) {
35
+ return {
36
+ releaseAction: 'not-in-release'
37
+ };
38
+ }
39
+ const entityItem = release.entities?.items.find((item)=>item.entity.sys.id === entryId);
40
+ if (!entityItem) {
41
+ return {
42
+ releaseAction: 'not-in-release'
43
+ };
44
+ }
45
+ if (isEntryBasedAction(entityItem)) {
46
+ return {
47
+ releaseAction: entityItem.action,
48
+ entityItem
49
+ };
50
+ }
51
+ const { addLocales, removeLocales } = getLocalesFromEntity(entityItem);
52
+ const releaseAction = getLocaleBasedAction(addLocales, removeLocales);
53
+ return {
54
+ releaseAction,
55
+ entityItem,
56
+ addLocales,
57
+ removeLocales
58
+ };
59
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "getEntryReleaseStatus", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return getEntryReleaseStatus;
9
+ }
10
+ });
11
+ const _determineReleaseAction = require("./determineReleaseAction");
12
+ function getEntryReleaseStatus(entryId, locales, release) {
13
+ const { releaseAction, entityItem, addLocales, removeLocales } = (0, _determineReleaseAction.determineReleaseAction)(entryId, release);
14
+ if (releaseAction === 'not-in-release' || !entityItem) {
15
+ return {
16
+ releaseAction
17
+ };
18
+ }
19
+ if ('action' in entityItem) {
20
+ return {
21
+ releaseAction,
22
+ localesCount: locales.length,
23
+ entityItem
24
+ };
25
+ }
26
+ const localesCount = addLocales && addLocales.length > 0 ? addLocales.length : locales.length;
27
+ return {
28
+ releaseAction,
29
+ localesCount,
30
+ entityItem,
31
+ addLocales,
32
+ removeLocales
33
+ };
34
+ }
package/dist/esm/index.js CHANGED
@@ -1,21 +1,23 @@
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
3
  export { CharValidation } from './CharValidation';
4
+ export { ConstraintsUtils };
5
+ export { entityHelpers };
4
6
  export { FieldConnector } from './FieldConnector';
7
+ export { ModalDialogLauncher };
5
8
  export { PredefinedValuesError } from './PredefinedValuesError';
6
9
  export { Asset, Entry, File } from './typesEntity';
7
10
  export { isValidImage } from './utils/isValidImage';
8
11
  export { shortenStorageUnit, toLocaleString } from './utils/shortenStorageUnit';
9
- export * from './utils/parseReleaseParameters';
10
- export * from './hooks/useLocalePublishStatus';
11
- export * from './hooks/useActiveLocales';
12
- export { ModalDialogLauncher };
13
- export { entityHelpers };
14
- export { ConstraintsUtils };
15
12
  export * from './types';
13
+ export * from './hooks/useActiveLocales';
16
14
  export * from './hooks/useActiveReleaseLocalesStatuses';
15
+ export * from './hooks/useLocalePublishStatus';
17
16
  export * from './LocalePublishingEntityStatusBadge';
18
17
  export * from './ReleaseEntityStatusBadge';
18
+ export * from './utils/determineReleaseAction';
19
+ export * from './utils/getEntryReleaseStatus';
20
+ export * from './utils/parseReleaseParameters';
19
21
  import * as ModalDialogLauncher from './ModalDialogLauncher';
20
22
  import * as ConstraintsUtils from './utils/constraints';
21
23
  import * as entityHelpers from './utils/entityHelpers';
@@ -0,0 +1,49 @@
1
+ function isEntryBasedAction(entityItem) {
2
+ return 'action' in entityItem && (entityItem.action === 'publish' || entityItem.action === 'unpublish');
3
+ }
4
+ function getLocalesFromEntity(entityItem) {
5
+ const addLocales = entityItem?.add?.fields?.['*'] ?? [];
6
+ const removeLocales = entityItem?.remove?.fields?.['*'] ?? [];
7
+ return {
8
+ addLocales,
9
+ removeLocales
10
+ };
11
+ }
12
+ function getLocaleBasedAction(addLocales, removeLocales) {
13
+ const hasPublish = addLocales.length > 0;
14
+ const hasUnpublish = removeLocales.length > 0;
15
+ if (hasPublish && !hasUnpublish) {
16
+ return 'publish';
17
+ }
18
+ if (!hasPublish && hasUnpublish) {
19
+ return 'unpublish';
20
+ }
21
+ return 'publish';
22
+ }
23
+ export function determineReleaseAction(entryId, release) {
24
+ if (!release) {
25
+ return {
26
+ releaseAction: 'not-in-release'
27
+ };
28
+ }
29
+ const entityItem = release.entities?.items.find((item)=>item.entity.sys.id === entryId);
30
+ if (!entityItem) {
31
+ return {
32
+ releaseAction: 'not-in-release'
33
+ };
34
+ }
35
+ if (isEntryBasedAction(entityItem)) {
36
+ return {
37
+ releaseAction: entityItem.action,
38
+ entityItem
39
+ };
40
+ }
41
+ const { addLocales, removeLocales } = getLocalesFromEntity(entityItem);
42
+ const releaseAction = getLocaleBasedAction(addLocales, removeLocales);
43
+ return {
44
+ releaseAction,
45
+ entityItem,
46
+ addLocales,
47
+ removeLocales
48
+ };
49
+ }
@@ -0,0 +1,24 @@
1
+ import { determineReleaseAction } from './determineReleaseAction';
2
+ export function getEntryReleaseStatus(entryId, locales, release) {
3
+ const { releaseAction, entityItem, addLocales, removeLocales } = determineReleaseAction(entryId, release);
4
+ if (releaseAction === 'not-in-release' || !entityItem) {
5
+ return {
6
+ releaseAction
7
+ };
8
+ }
9
+ if ('action' in entityItem) {
10
+ return {
11
+ releaseAction,
12
+ localesCount: locales.length,
13
+ entityItem
14
+ };
15
+ }
16
+ const localesCount = addLocales && addLocales.length > 0 ? addLocales.length : locales.length;
17
+ return {
18
+ releaseAction,
19
+ localesCount,
20
+ entityItem,
21
+ addLocales,
22
+ removeLocales
23
+ };
24
+ }
@@ -1,22 +1,24 @@
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
3
  export { CharValidation } from './CharValidation';
4
+ export { ConstraintsUtils };
5
+ export { entityHelpers };
4
6
  export { FieldConnector } from './FieldConnector';
5
- export type { FieldConnectorChildProps } from './FieldConnector';
7
+ export { ModalDialogLauncher };
6
8
  export { PredefinedValuesError } from './PredefinedValuesError';
7
9
  export { Asset, Entry, File } from './typesEntity';
8
10
  export { isValidImage } from './utils/isValidImage';
9
11
  export { shortenStorageUnit, toLocaleString } from './utils/shortenStorageUnit';
10
- export * from './utils/parseReleaseParameters';
11
- export * from './hooks/useLocalePublishStatus';
12
- export * from './hooks/useActiveLocales';
13
- export { ModalDialogLauncher };
14
- export { entityHelpers };
15
- export { ConstraintsUtils };
12
+ export type { FieldConnectorChildProps } from './FieldConnector';
16
13
  export * from './types';
14
+ export * from './hooks/useActiveLocales';
17
15
  export * from './hooks/useActiveReleaseLocalesStatuses';
16
+ export * from './hooks/useLocalePublishStatus';
18
17
  export * from './LocalePublishingEntityStatusBadge';
19
18
  export * from './ReleaseEntityStatusBadge';
19
+ export * from './utils/determineReleaseAction';
20
+ export * from './utils/getEntryReleaseStatus';
21
+ export * from './utils/parseReleaseParameters';
20
22
  import * as ModalDialogLauncher from './ModalDialogLauncher';
21
23
  import * as ConstraintsUtils from './utils/constraints';
22
24
  import * as entityHelpers from './utils/entityHelpers';
@@ -0,0 +1,9 @@
1
+ import type { ReleaseAction, ReleaseV2Entity, ReleaseV2EntityWithLocales, ReleaseV2Props } from '../types';
2
+ type DetermineActionResult = {
3
+ releaseAction: ReleaseAction;
4
+ entityItem?: ReleaseV2Entity | ReleaseV2EntityWithLocales;
5
+ addLocales?: string[];
6
+ removeLocales?: string[];
7
+ };
8
+ export declare function determineReleaseAction(entryId: string, release?: ReleaseV2Props): DetermineActionResult;
9
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { LocaleProps } from 'contentful-management/types';
2
+ import type { ReleaseAction, ReleaseV2Entity, ReleaseV2EntityWithLocales, ReleaseV2Props } from '../types';
3
+ type GetEntryReleaseStatusResult = {
4
+ releaseAction: ReleaseAction;
5
+ localesCount?: number;
6
+ entityItem?: ReleaseV2Entity | ReleaseV2EntityWithLocales;
7
+ addLocales?: string[];
8
+ removeLocales?: string[];
9
+ };
10
+ export declare function getEntryReleaseStatus(entryId: string, locales: LocaleProps[], release?: ReleaseV2Props): GetEntryReleaseStatusResult;
11
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-shared",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -57,5 +57,5 @@
57
57
  "publishConfig": {
58
58
  "registry": "https://npm.pkg.github.com/"
59
59
  },
60
- "gitHead": "a86f67a6d507eb7c8c7a38b4312380361bdbebbb"
60
+ "gitHead": "44e5546797a12db4d96f290e039a483297265ffa"
61
61
  }