@contentful/field-editor-shared 1.2.0 → 1.3.1
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/CharCounter.js +75 -0
- package/dist/cjs/CharValidation.js +60 -0
- package/dist/cjs/FieldConnector.js +167 -0
- package/dist/cjs/FieldConnector.test.js +81 -0
- package/dist/cjs/ModalDialogLauncher.js +132 -0
- package/dist/cjs/PredefinedValuesError.js +57 -0
- package/dist/cjs/index.js +155 -0
- package/dist/cjs/types.js +4 -0
- package/dist/cjs/typesEntity.js +31 -0
- package/dist/cjs/utils/constraints.js +63 -0
- package/dist/cjs/utils/entityHelpers.js +214 -0
- package/dist/cjs/utils/isValidImage.js +26 -0
- package/dist/cjs/utils/shortenStorageUnit.js +55 -0
- package/dist/esm/CharCounter.js +21 -0
- package/dist/esm/CharValidation.js +11 -0
- package/dist/esm/FieldConnector.js +113 -0
- package/dist/esm/FieldConnector.test.js +33 -0
- package/dist/esm/ModalDialogLauncher.js +67 -0
- package/dist/esm/PredefinedValuesError.js +8 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/typesEntity.js +1 -0
- package/dist/esm/utils/constraints.js +40 -0
- package/dist/esm/utils/entityHelpers.js +170 -0
- package/dist/esm/utils/isValidImage.js +16 -0
- package/dist/esm/utils/shortenStorageUnit.js +37 -0
- package/dist/types/CharCounter.d.ts +7 -0
- package/dist/{CharValidation.d.ts → types/CharValidation.d.ts} +7 -7
- package/dist/{FieldConnector.d.ts → types/FieldConnector.d.ts} +48 -48
- package/dist/types/FieldConnector.test.d.ts +1 -0
- package/dist/{ModalDialogLauncher.d.ts → types/ModalDialogLauncher.d.ts} +13 -13
- package/dist/types/PredefinedValuesError.d.ts +2 -0
- package/dist/{index.d.ts → types/index.d.ts} +15 -15
- package/dist/{types.d.ts → types/types.d.ts} +11 -11
- package/dist/{typesEntity.d.ts → types/typesEntity.d.ts} +9 -9
- package/dist/{utils → types/utils}/constraints.d.ts +3 -3
- package/dist/{utils → types/utils}/entityHelpers.d.ts +68 -68
- package/dist/{utils → types/utils}/isValidImage.d.ts +5 -5
- package/dist/{utils → types/utils}/shortenStorageUnit.d.ts +17 -17
- package/package.json +26 -12
- package/CHANGELOG.md +0 -196
- package/dist/CharCounter.d.ts +0 -7
- package/dist/PredefinedValuesError.d.ts +0 -2
- package/dist/field-editor-shared.cjs.development.js +0 -634
- package/dist/field-editor-shared.cjs.development.js.map +0 -1
- package/dist/field-editor-shared.cjs.production.min.js +0 -2
- package/dist/field-editor-shared.cjs.production.min.js.map +0 -1
- package/dist/field-editor-shared.esm.js +0 -619
- package/dist/field-editor-shared.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
AccessAPI: function() {
|
|
13
|
+
return _appsdk.AccessAPI;
|
|
14
|
+
},
|
|
15
|
+
AppConfigAPI: function() {
|
|
16
|
+
return _appsdk.AppConfigAPI;
|
|
17
|
+
},
|
|
18
|
+
BaseExtensionSDK: function() {
|
|
19
|
+
return _appsdk.BaseExtensionSDK;
|
|
20
|
+
},
|
|
21
|
+
ContentType: function() {
|
|
22
|
+
return _appsdk.ContentType;
|
|
23
|
+
},
|
|
24
|
+
DialogsAPI: function() {
|
|
25
|
+
return _appsdk.DialogsAPI;
|
|
26
|
+
},
|
|
27
|
+
EntryAPI: function() {
|
|
28
|
+
return _appsdk.EntryAPI;
|
|
29
|
+
},
|
|
30
|
+
EntryFieldAPI: function() {
|
|
31
|
+
return _appsdk.EntryFieldAPI;
|
|
32
|
+
},
|
|
33
|
+
FieldAPI: function() {
|
|
34
|
+
return _appsdk.FieldAPI;
|
|
35
|
+
},
|
|
36
|
+
FieldExtensionSDK: function() {
|
|
37
|
+
return _appsdk.FieldExtensionSDK;
|
|
38
|
+
},
|
|
39
|
+
IdsAPI: function() {
|
|
40
|
+
return _appsdk.IdsAPI;
|
|
41
|
+
},
|
|
42
|
+
LocalesAPI: function() {
|
|
43
|
+
return _appsdk.LocalesAPI;
|
|
44
|
+
},
|
|
45
|
+
LocationAPI: function() {
|
|
46
|
+
return _appsdk.LocationAPI;
|
|
47
|
+
},
|
|
48
|
+
NavigatorAPI: function() {
|
|
49
|
+
return _appsdk.NavigatorAPI;
|
|
50
|
+
},
|
|
51
|
+
NotifierAPI: function() {
|
|
52
|
+
return _appsdk.NotifierAPI;
|
|
53
|
+
},
|
|
54
|
+
OpenCustomWidgetOptions: function() {
|
|
55
|
+
return _appsdk.OpenCustomWidgetOptions;
|
|
56
|
+
},
|
|
57
|
+
ParametersAPI: function() {
|
|
58
|
+
return _appsdk.ParametersAPI;
|
|
59
|
+
},
|
|
60
|
+
SpaceAPI: function() {
|
|
61
|
+
return _appsdk.SpaceAPI;
|
|
62
|
+
},
|
|
63
|
+
WindowAPI: function() {
|
|
64
|
+
return _appsdk.WindowAPI;
|
|
65
|
+
},
|
|
66
|
+
CharCounter: function() {
|
|
67
|
+
return _CharCounter.CharCounter;
|
|
68
|
+
},
|
|
69
|
+
CharValidation: function() {
|
|
70
|
+
return _CharValidation.CharValidation;
|
|
71
|
+
},
|
|
72
|
+
FieldConnector: function() {
|
|
73
|
+
return _FieldConnector.FieldConnector;
|
|
74
|
+
},
|
|
75
|
+
PredefinedValuesError: function() {
|
|
76
|
+
return _PredefinedValuesError.PredefinedValuesError;
|
|
77
|
+
},
|
|
78
|
+
Asset: function() {
|
|
79
|
+
return _typesEntity.Asset;
|
|
80
|
+
},
|
|
81
|
+
Entry: function() {
|
|
82
|
+
return _typesEntity.Entry;
|
|
83
|
+
},
|
|
84
|
+
File: function() {
|
|
85
|
+
return _typesEntity.File;
|
|
86
|
+
},
|
|
87
|
+
isValidImage: function() {
|
|
88
|
+
return _isValidImage.isValidImage;
|
|
89
|
+
},
|
|
90
|
+
shortenStorageUnit: function() {
|
|
91
|
+
return _shortenStorageUnit.shortenStorageUnit;
|
|
92
|
+
},
|
|
93
|
+
toLocaleString: function() {
|
|
94
|
+
return _shortenStorageUnit.toLocaleString;
|
|
95
|
+
},
|
|
96
|
+
ModalDialogLauncher: function() {
|
|
97
|
+
return _ModalDialogLauncher;
|
|
98
|
+
},
|
|
99
|
+
entityHelpers: function() {
|
|
100
|
+
return _entityHelpers;
|
|
101
|
+
},
|
|
102
|
+
ConstraintsUtils: function() {
|
|
103
|
+
return _constraints;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
const _appsdk = require("@contentful/app-sdk");
|
|
107
|
+
const _CharCounter = require("./CharCounter");
|
|
108
|
+
const _CharValidation = require("./CharValidation");
|
|
109
|
+
const _FieldConnector = require("./FieldConnector");
|
|
110
|
+
const _PredefinedValuesError = require("./PredefinedValuesError");
|
|
111
|
+
const _typesEntity = require("./typesEntity");
|
|
112
|
+
const _isValidImage = require("./utils/isValidImage");
|
|
113
|
+
const _shortenStorageUnit = require("./utils/shortenStorageUnit");
|
|
114
|
+
const _ModalDialogLauncher = _interop_require_wildcard(require("./ModalDialogLauncher"));
|
|
115
|
+
const _constraints = _interop_require_wildcard(require("./utils/constraints"));
|
|
116
|
+
const _entityHelpers = _interop_require_wildcard(require("./utils/entityHelpers"));
|
|
117
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
118
|
+
if (typeof WeakMap !== "function") return null;
|
|
119
|
+
var cacheBabelInterop = new WeakMap();
|
|
120
|
+
var cacheNodeInterop = new WeakMap();
|
|
121
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
122
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
123
|
+
})(nodeInterop);
|
|
124
|
+
}
|
|
125
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
126
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
127
|
+
return obj;
|
|
128
|
+
}
|
|
129
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
130
|
+
return {
|
|
131
|
+
default: obj
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
135
|
+
if (cache && cache.has(obj)) {
|
|
136
|
+
return cache.get(obj);
|
|
137
|
+
}
|
|
138
|
+
var newObj = {};
|
|
139
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
140
|
+
for(var key in obj){
|
|
141
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
142
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
143
|
+
if (desc && (desc.get || desc.set)) {
|
|
144
|
+
Object.defineProperty(newObj, key, desc);
|
|
145
|
+
} else {
|
|
146
|
+
newObj[key] = obj[key];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
newObj.default = obj;
|
|
151
|
+
if (cache) {
|
|
152
|
+
cache.set(obj, newObj);
|
|
153
|
+
}
|
|
154
|
+
return newObj;
|
|
155
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
BaseExtensionSDK: function() {
|
|
13
|
+
return _appsdk.BaseExtensionSDK;
|
|
14
|
+
},
|
|
15
|
+
ContentType: function() {
|
|
16
|
+
return _appsdk.ContentType;
|
|
17
|
+
},
|
|
18
|
+
ContentTypeField: function() {
|
|
19
|
+
return _appsdk.ContentTypeField;
|
|
20
|
+
},
|
|
21
|
+
Link: function() {
|
|
22
|
+
return _appsdk.Link;
|
|
23
|
+
},
|
|
24
|
+
Entry: function() {
|
|
25
|
+
return _appsdk.Entry;
|
|
26
|
+
},
|
|
27
|
+
Asset: function() {
|
|
28
|
+
return _appsdk.Asset;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const _appsdk = require("@contentful/app-sdk");
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
fromFieldValidations: function() {
|
|
13
|
+
return fromFieldValidations;
|
|
14
|
+
},
|
|
15
|
+
makeChecker: function() {
|
|
16
|
+
return makeChecker;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _isNumber = _interop_require_default(require("lodash/isNumber"));
|
|
20
|
+
function _interop_require_default(obj) {
|
|
21
|
+
return obj && obj.__esModule ? obj : {
|
|
22
|
+
default: obj
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function fromFieldValidations(validations = [], fieldType) {
|
|
26
|
+
const sizeValidation = validations.find((v)=>'size' in v);
|
|
27
|
+
const size = sizeValidation && sizeValidation.size || {};
|
|
28
|
+
const min = size.min;
|
|
29
|
+
const max = size.max;
|
|
30
|
+
if ((0, _isNumber.default)(min) && (0, _isNumber.default)(max)) {
|
|
31
|
+
return {
|
|
32
|
+
type: 'min-max',
|
|
33
|
+
min,
|
|
34
|
+
max
|
|
35
|
+
};
|
|
36
|
+
} else if ((0, _isNumber.default)(min)) {
|
|
37
|
+
return {
|
|
38
|
+
type: 'min',
|
|
39
|
+
min
|
|
40
|
+
};
|
|
41
|
+
} else if ((0, _isNumber.default)(max)) {
|
|
42
|
+
return {
|
|
43
|
+
type: 'max',
|
|
44
|
+
max
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
return {
|
|
48
|
+
type: 'max',
|
|
49
|
+
max: fieldType === 'Symbol' ? 256 : 50000
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function makeChecker(constraint) {
|
|
54
|
+
return function checkConstraint(length) {
|
|
55
|
+
if (constraint.type === 'max') {
|
|
56
|
+
return length <= constraint.max;
|
|
57
|
+
} else if (constraint.type === 'min') {
|
|
58
|
+
return length >= constraint.min;
|
|
59
|
+
} else {
|
|
60
|
+
return length >= constraint.min && length <= constraint.max;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getFieldValue: function() {
|
|
13
|
+
return getFieldValue;
|
|
14
|
+
},
|
|
15
|
+
getAssetTitle: function() {
|
|
16
|
+
return getAssetTitle;
|
|
17
|
+
},
|
|
18
|
+
isAssetField: function() {
|
|
19
|
+
return isAssetField;
|
|
20
|
+
},
|
|
21
|
+
isDisplayField: function() {
|
|
22
|
+
return isDisplayField;
|
|
23
|
+
},
|
|
24
|
+
isDescriptionField: function() {
|
|
25
|
+
return isDescriptionField;
|
|
26
|
+
},
|
|
27
|
+
getEntityDescription: function() {
|
|
28
|
+
return getEntityDescription;
|
|
29
|
+
},
|
|
30
|
+
getEntryTitle: function() {
|
|
31
|
+
return getEntryTitle;
|
|
32
|
+
},
|
|
33
|
+
getEntryStatus: function() {
|
|
34
|
+
return getEntryStatus;
|
|
35
|
+
},
|
|
36
|
+
getEntryImage: function() {
|
|
37
|
+
return getEntryImage;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const _get = _interop_require_default(require("lodash/get"));
|
|
41
|
+
const _isObject = _interop_require_default(require("lodash/isObject"));
|
|
42
|
+
const _isString = _interop_require_default(require("lodash/isString"));
|
|
43
|
+
function _interop_require_default(obj) {
|
|
44
|
+
return obj && obj.__esModule ? obj : {
|
|
45
|
+
default: obj
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function titleOrDefault(title, defaultTitle) {
|
|
49
|
+
if (!(0, _isString.default)(title)) {
|
|
50
|
+
return defaultTitle;
|
|
51
|
+
}
|
|
52
|
+
if (title) {
|
|
53
|
+
const trimmedTitle = title.trim();
|
|
54
|
+
if (trimmedTitle.length === 0) {
|
|
55
|
+
return defaultTitle;
|
|
56
|
+
}
|
|
57
|
+
return trimmedTitle;
|
|
58
|
+
}
|
|
59
|
+
return defaultTitle;
|
|
60
|
+
}
|
|
61
|
+
function getFieldValue({ entity , fieldId , localeCode , defaultLocaleCode }) {
|
|
62
|
+
const values = (0, _get.default)(entity, [
|
|
63
|
+
'fields',
|
|
64
|
+
fieldId
|
|
65
|
+
]);
|
|
66
|
+
if (!(0, _isObject.default)(values)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const firstLocaleCode = Object.keys(values)[0];
|
|
70
|
+
return values[localeCode] || values[defaultLocaleCode] || values[firstLocaleCode];
|
|
71
|
+
}
|
|
72
|
+
function getAssetTitle({ asset , localeCode , defaultLocaleCode , defaultTitle }) {
|
|
73
|
+
const title = getFieldValue({
|
|
74
|
+
entity: {
|
|
75
|
+
fields: {
|
|
76
|
+
title: asset.fields?.title
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
fieldId: 'title',
|
|
80
|
+
localeCode,
|
|
81
|
+
defaultLocaleCode
|
|
82
|
+
});
|
|
83
|
+
return titleOrDefault(title, defaultTitle);
|
|
84
|
+
}
|
|
85
|
+
const isAssetField = (field)=>field.type === 'Link' && field.linkType === 'Asset';
|
|
86
|
+
function isDisplayField({ field , contentType }) {
|
|
87
|
+
return field.id === contentType.displayField;
|
|
88
|
+
}
|
|
89
|
+
function isDescriptionField({ field , contentType }) {
|
|
90
|
+
const isTextField = (field)=>[
|
|
91
|
+
'Symbol',
|
|
92
|
+
'Text'
|
|
93
|
+
].includes(field.type);
|
|
94
|
+
const isMaybeSlugField = (field)=>/\bslug\b/.test(field.name);
|
|
95
|
+
return isTextField(field) && !isDisplayField({
|
|
96
|
+
field,
|
|
97
|
+
contentType
|
|
98
|
+
}) && !isMaybeSlugField(field);
|
|
99
|
+
}
|
|
100
|
+
function getEntityDescription({ entity , contentType , localeCode , defaultLocaleCode }) {
|
|
101
|
+
if (!contentType) {
|
|
102
|
+
return '';
|
|
103
|
+
}
|
|
104
|
+
const descriptionField = contentType.fields.find((field)=>isDescriptionField({
|
|
105
|
+
field,
|
|
106
|
+
contentType
|
|
107
|
+
}));
|
|
108
|
+
if (!descriptionField) {
|
|
109
|
+
return '';
|
|
110
|
+
}
|
|
111
|
+
return getFieldValue({
|
|
112
|
+
entity,
|
|
113
|
+
fieldId: descriptionField.id,
|
|
114
|
+
localeCode,
|
|
115
|
+
defaultLocaleCode
|
|
116
|
+
}) || '';
|
|
117
|
+
}
|
|
118
|
+
function getEntryTitle({ entry , contentType , localeCode , defaultLocaleCode , defaultTitle }) {
|
|
119
|
+
let title;
|
|
120
|
+
if (!contentType) {
|
|
121
|
+
return defaultTitle;
|
|
122
|
+
}
|
|
123
|
+
const displayField = contentType.displayField;
|
|
124
|
+
if (!displayField) {
|
|
125
|
+
return defaultTitle;
|
|
126
|
+
}
|
|
127
|
+
const displayFieldInfo = contentType.fields.find((field)=>field.id === displayField);
|
|
128
|
+
if (!displayFieldInfo) {
|
|
129
|
+
return defaultTitle;
|
|
130
|
+
}
|
|
131
|
+
if (displayFieldInfo.localized) {
|
|
132
|
+
title = getFieldValue({
|
|
133
|
+
entity: entry,
|
|
134
|
+
fieldId: displayField,
|
|
135
|
+
localeCode,
|
|
136
|
+
defaultLocaleCode
|
|
137
|
+
});
|
|
138
|
+
if (!title) {
|
|
139
|
+
title = getFieldValue({
|
|
140
|
+
entity: entry,
|
|
141
|
+
fieldId: displayFieldInfo.id,
|
|
142
|
+
localeCode,
|
|
143
|
+
defaultLocaleCode
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
title = getFieldValue({
|
|
148
|
+
entity: entry,
|
|
149
|
+
fieldId: displayField,
|
|
150
|
+
defaultLocaleCode,
|
|
151
|
+
localeCode: ''
|
|
152
|
+
});
|
|
153
|
+
if (!title) {
|
|
154
|
+
title = getFieldValue({
|
|
155
|
+
entity: entry,
|
|
156
|
+
fieldId: displayFieldInfo.id,
|
|
157
|
+
defaultLocaleCode,
|
|
158
|
+
localeCode: ''
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return titleOrDefault(title, defaultTitle);
|
|
163
|
+
}
|
|
164
|
+
function getEntryStatus(sys) {
|
|
165
|
+
if (!sys || sys.type !== 'Entry' && sys.type !== 'Asset') {
|
|
166
|
+
throw new TypeError('Invalid entity metadata object');
|
|
167
|
+
}
|
|
168
|
+
if (sys.deletedVersion) {
|
|
169
|
+
return 'deleted';
|
|
170
|
+
} else if (sys.archivedVersion) {
|
|
171
|
+
return 'archived';
|
|
172
|
+
} else if (sys.publishedVersion) {
|
|
173
|
+
if (sys.version > sys.publishedVersion + 1) {
|
|
174
|
+
return 'changed';
|
|
175
|
+
} else {
|
|
176
|
+
return 'published';
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
return 'draft';
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const getEntryImage = async ({ entry , contentType , localeCode }, getAsset)=>{
|
|
183
|
+
if (!contentType) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
const assetLink = contentType.fields.find(isAssetField);
|
|
187
|
+
if (!assetLink) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
const assetId = (0, _get.default)(entry.fields, [
|
|
191
|
+
assetLink.id,
|
|
192
|
+
localeCode,
|
|
193
|
+
'sys',
|
|
194
|
+
'id'
|
|
195
|
+
]);
|
|
196
|
+
if (!assetId) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
const asset = await getAsset(assetId);
|
|
201
|
+
const file = (0, _get.default)(asset, [
|
|
202
|
+
'fields',
|
|
203
|
+
'file',
|
|
204
|
+
localeCode
|
|
205
|
+
]);
|
|
206
|
+
const isImage = Boolean((0, _get.default)(file, [
|
|
207
|
+
'details',
|
|
208
|
+
'image'
|
|
209
|
+
], false));
|
|
210
|
+
return isImage ? file : null;
|
|
211
|
+
} catch (e) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "isValidImage", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return isValidImage;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function isValidImage(file) {
|
|
12
|
+
const validMimeTypes = [
|
|
13
|
+
'image/avif',
|
|
14
|
+
'image/bmp',
|
|
15
|
+
'image/x-windows-bmp',
|
|
16
|
+
'image/gif',
|
|
17
|
+
'image/webp',
|
|
18
|
+
'image/jpg',
|
|
19
|
+
'image/jpeg',
|
|
20
|
+
'image/pjpeg',
|
|
21
|
+
'image/x-jps',
|
|
22
|
+
'image/png',
|
|
23
|
+
'image/svg+xml'
|
|
24
|
+
];
|
|
25
|
+
return validMimeTypes.includes(file.contentType);
|
|
26
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
toLocaleString: function() {
|
|
13
|
+
return toLocaleString;
|
|
14
|
+
},
|
|
15
|
+
shortenStorageUnit: function() {
|
|
16
|
+
return shortenStorageUnit;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
function toLocaleString(number) {
|
|
20
|
+
return number.toLocaleString('en-US');
|
|
21
|
+
}
|
|
22
|
+
function formatFloat(value, localize) {
|
|
23
|
+
return localize ? toLocaleString(value) : value.toFixed(2).replace(/\.(0)*$|0*$/, '');
|
|
24
|
+
}
|
|
25
|
+
function shortenStorageUnit(value, uom) {
|
|
26
|
+
if (value <= 0) {
|
|
27
|
+
return '0 B';
|
|
28
|
+
}
|
|
29
|
+
const units = [
|
|
30
|
+
'PB',
|
|
31
|
+
'TB',
|
|
32
|
+
'GB',
|
|
33
|
+
'MB',
|
|
34
|
+
'KB',
|
|
35
|
+
'B'
|
|
36
|
+
];
|
|
37
|
+
const getBigger = (unit)=>units[units.indexOf(unit) - 1];
|
|
38
|
+
const getSmaller = (unit)=>units[units.indexOf(unit) + 1];
|
|
39
|
+
const isBiggestUnit = (unit)=>units.indexOf(unit) === 0;
|
|
40
|
+
const isSmallestUnit = (unit)=>units.indexOf(unit) === units.length - 1;
|
|
41
|
+
const reduce = (number, unit)=>{
|
|
42
|
+
if (number < 0.99 && !isSmallestUnit(unit)) {
|
|
43
|
+
return reduce(number * 1000, getSmaller(unit));
|
|
44
|
+
} else if (number >= 1000 && !isBiggestUnit(unit)) {
|
|
45
|
+
return reduce(number / 1000, getBigger(unit));
|
|
46
|
+
} else {
|
|
47
|
+
return {
|
|
48
|
+
number,
|
|
49
|
+
unit
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const { number , unit } = reduce(value, uom);
|
|
54
|
+
return `${formatFloat(number, false)} ${unit}`;
|
|
55
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import tokens from '@contentful/f36-tokens';
|
|
3
|
+
import { css, cx } from 'emotion';
|
|
4
|
+
const styles = {
|
|
5
|
+
invalid: css({
|
|
6
|
+
color: tokens.red600
|
|
7
|
+
})
|
|
8
|
+
};
|
|
9
|
+
export function CharCounter(props) {
|
|
10
|
+
let count = 0;
|
|
11
|
+
if (props.value) {
|
|
12
|
+
count = props.value.length;
|
|
13
|
+
}
|
|
14
|
+
const valid = count === 0 || props.checkConstraint(count);
|
|
15
|
+
return React.createElement("span", {
|
|
16
|
+
"data-status-code": valid ? null : 'invalid-size',
|
|
17
|
+
className: cx({
|
|
18
|
+
[styles.invalid]: !valid
|
|
19
|
+
})
|
|
20
|
+
}, count, " characters");
|
|
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
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
import isEqual from 'lodash/isEqual';
|
|
16
|
+
import throttle from 'lodash/throttle';
|
|
17
|
+
var _React_Component;
|
|
18
|
+
export class FieldConnector extends (_React_Component = React.Component) {
|
|
19
|
+
componentDidMount() {
|
|
20
|
+
const { field } = this.props;
|
|
21
|
+
this.unsubscribeErrors = field.onSchemaErrorsChanged((errors)=>{
|
|
22
|
+
this.setState({
|
|
23
|
+
errors: errors || []
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
this.unsubscribeDisabled = field.onIsDisabledChanged((disabled)=>{
|
|
27
|
+
this.setState({
|
|
28
|
+
disabled
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
this.unsubscribeValue = field.onValueChanged((value)=>{
|
|
32
|
+
this.setState((currentState)=>{
|
|
33
|
+
const isLocalValueChange = this.props.isEqualValues(value, currentState.value);
|
|
34
|
+
const lastRemoteValue = isLocalValueChange ? currentState.lastRemoteValue : value;
|
|
35
|
+
const externalReset = currentState.externalReset + (isLocalValueChange ? 0 : 1);
|
|
36
|
+
return {
|
|
37
|
+
value,
|
|
38
|
+
lastRemoteValue,
|
|
39
|
+
isLocalValueChange,
|
|
40
|
+
externalReset
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
componentWillUnmount() {
|
|
46
|
+
if (typeof this.unsubscribeErrors === 'function') {
|
|
47
|
+
this.unsubscribeErrors();
|
|
48
|
+
}
|
|
49
|
+
if (typeof this.unsubscribeDisabled === 'function') {
|
|
50
|
+
this.unsubscribeDisabled();
|
|
51
|
+
}
|
|
52
|
+
if (typeof this.unsubscribeValue === 'function') {
|
|
53
|
+
this.unsubscribeValue();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
render() {
|
|
57
|
+
return this.props.children({
|
|
58
|
+
...this.state,
|
|
59
|
+
setValue: this.setValue,
|
|
60
|
+
disabled: this.props.isDisabled || this.state.disabled
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
constructor(props){
|
|
64
|
+
super(props);
|
|
65
|
+
_define_property(this, "unsubscribeErrors", null);
|
|
66
|
+
_define_property(this, "unsubscribeDisabled", null);
|
|
67
|
+
_define_property(this, "unsubscribeValue", null);
|
|
68
|
+
_define_property(this, "setValue", async (value)=>{
|
|
69
|
+
if (this.props.isEmptyValue(value ?? null)) {
|
|
70
|
+
this.setState({
|
|
71
|
+
value: undefined
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
this.setState({
|
|
75
|
+
value
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
await this.triggerSetValueCallbacks(value);
|
|
79
|
+
});
|
|
80
|
+
_define_property(this, "triggerSetValueCallbacks", throttle((value)=>{
|
|
81
|
+
return new Promise((resolve, reject)=>{
|
|
82
|
+
if (this.props.isEmptyValue(value ?? null)) {
|
|
83
|
+
this.props.field.removeValue().then(resolve).catch(reject);
|
|
84
|
+
} else {
|
|
85
|
+
this.props.field.setValue(value).then(resolve).catch(reject);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}, this.props.throttle, {
|
|
89
|
+
leading: this.props.throttle === 0
|
|
90
|
+
}));
|
|
91
|
+
const initialValue = props.field.getValue();
|
|
92
|
+
this.state = {
|
|
93
|
+
isLocalValueChange: false,
|
|
94
|
+
externalReset: 0,
|
|
95
|
+
value: initialValue,
|
|
96
|
+
lastRemoteValue: initialValue,
|
|
97
|
+
disabled: props.isInitiallyDisabled ?? false,
|
|
98
|
+
errors: []
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
_define_property(FieldConnector, "defaultProps", {
|
|
103
|
+
children: ()=>{
|
|
104
|
+
return null;
|
|
105
|
+
},
|
|
106
|
+
isEmptyValue: (value)=>{
|
|
107
|
+
return value === null || value === '';
|
|
108
|
+
},
|
|
109
|
+
isEqualValues: (value1, value2)=>{
|
|
110
|
+
return isEqual(value1, value2);
|
|
111
|
+
},
|
|
112
|
+
throttle: 300
|
|
113
|
+
});
|