@contentful/field-editor-shared 1.1.8 → 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.
- 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} +47 -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 -11
- package/CHANGELOG.md +0 -190
- package/dist/CharCounter.d.ts +0 -7
- package/dist/PredefinedValuesError.d.ts +0 -2
- package/dist/field-editor-shared.cjs.development.js +0 -1513
- 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 -1498
- package/dist/field-editor-shared.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createFakeFieldAPI } from '@contentful/field-editor-test-utils';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import noop from 'lodash/noop';
|
|
5
|
+
import { FieldConnector } from './FieldConnector';
|
|
6
|
+
it('does not rerender with outdated value after calling setValue', ()=>{
|
|
7
|
+
function getChild() {
|
|
8
|
+
return props.children.mock.calls[props.children.mock.calls.length - 1][0];
|
|
9
|
+
}
|
|
10
|
+
const onSchemaErrorsChanged = jest.fn();
|
|
11
|
+
const [field] = createFakeFieldAPI((field)=>{
|
|
12
|
+
return {
|
|
13
|
+
...field,
|
|
14
|
+
setValue: ()=>new Promise(noop),
|
|
15
|
+
onSchemaErrorsChanged
|
|
16
|
+
};
|
|
17
|
+
}, 'initial value');
|
|
18
|
+
const props = {
|
|
19
|
+
isInitiallyDisabled: false,
|
|
20
|
+
children: jest.fn().mockImplementation(()=>null),
|
|
21
|
+
field,
|
|
22
|
+
throttle: 0
|
|
23
|
+
};
|
|
24
|
+
render(React.createElement(FieldConnector, props));
|
|
25
|
+
let child = getChild();
|
|
26
|
+
expect(child.value).toBe('initial value');
|
|
27
|
+
const initialRenderCount = props.children.mock.calls.length;
|
|
28
|
+
child.setValue('new value');
|
|
29
|
+
onSchemaErrorsChanged.mock.calls.forEach(([cb])=>cb([]));
|
|
30
|
+
child = getChild();
|
|
31
|
+
expect(child.value).toBe('new value');
|
|
32
|
+
expect(props.children.mock.calls.length).toBeGreaterThan(initialRenderCount);
|
|
33
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { Modal, ModalHeader } from '@contentful/f36-components';
|
|
4
|
+
import isNumber from 'lodash/isNumber';
|
|
5
|
+
export function open(componentRenderer) {
|
|
6
|
+
let rootDom = null;
|
|
7
|
+
const getRoot = ()=>{
|
|
8
|
+
if (rootDom === null) {
|
|
9
|
+
rootDom = document.createElement('div');
|
|
10
|
+
rootDom.setAttribute('id', 'field-editor-modal-root');
|
|
11
|
+
document.body.appendChild(rootDom);
|
|
12
|
+
}
|
|
13
|
+
return rootDom;
|
|
14
|
+
};
|
|
15
|
+
return new Promise((resolve)=>{
|
|
16
|
+
let currentConfig = {
|
|
17
|
+
onClose,
|
|
18
|
+
isShown: true
|
|
19
|
+
};
|
|
20
|
+
function render({ onClose , isShown }) {
|
|
21
|
+
ReactDOM.render(componentRenderer({
|
|
22
|
+
onClose,
|
|
23
|
+
isShown
|
|
24
|
+
}), getRoot());
|
|
25
|
+
}
|
|
26
|
+
function onClose(...args) {
|
|
27
|
+
currentConfig = {
|
|
28
|
+
...currentConfig,
|
|
29
|
+
isShown: false
|
|
30
|
+
};
|
|
31
|
+
render(currentConfig);
|
|
32
|
+
resolve(...args);
|
|
33
|
+
getRoot().remove();
|
|
34
|
+
}
|
|
35
|
+
render(currentConfig);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export function openDialog(options, Component) {
|
|
39
|
+
const key = Date.now();
|
|
40
|
+
const size = isNumber(options.width) ? `${options.width}px` : options.width;
|
|
41
|
+
return open(({ isShown , onClose })=>{
|
|
42
|
+
const onCloseHandler = ()=>onClose();
|
|
43
|
+
return React.createElement(Modal, {
|
|
44
|
+
key: key,
|
|
45
|
+
shouldCloseOnOverlayClick: options.shouldCloseOnOverlayClick || false,
|
|
46
|
+
shouldCloseOnEscapePress: options.shouldCloseOnEscapePress || false,
|
|
47
|
+
allowHeightOverflow: options.allowHeightOverflow || false,
|
|
48
|
+
position: options.position || 'center',
|
|
49
|
+
isShown: isShown,
|
|
50
|
+
onClose: onCloseHandler,
|
|
51
|
+
size: size || '700px'
|
|
52
|
+
}, ()=>React.createElement(React.Fragment, null, options.title && React.createElement(ModalHeader, {
|
|
53
|
+
testId: "dialog-title",
|
|
54
|
+
title: options.title,
|
|
55
|
+
onClose: onCloseHandler
|
|
56
|
+
}), React.createElement("div", {
|
|
57
|
+
style: {
|
|
58
|
+
minHeight: options.minHeight || 'auto'
|
|
59
|
+
}
|
|
60
|
+
}, React.createElement(Component, {
|
|
61
|
+
onClose: onClose
|
|
62
|
+
}))));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export default {
|
|
66
|
+
openDialog
|
|
67
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Note } from '@contentful/f36-note';
|
|
3
|
+
export function PredefinedValuesError() {
|
|
4
|
+
return React.createElement(Note, {
|
|
5
|
+
variant: "warning",
|
|
6
|
+
testId: "predefined-values-warning"
|
|
7
|
+
}, "The widget failed to initialize. You can fix the problem by providing predefined values under the validations tab in the field settings.");
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { AccessAPI, AppConfigAPI, BaseExtensionSDK, ContentType, DialogsAPI, EntryAPI, EntryFieldAPI, FieldAPI, FieldExtensionSDK, IdsAPI, LocalesAPI, LocationAPI, NavigatorAPI, NotifierAPI, OpenCustomWidgetOptions, ParametersAPI, SpaceAPI, WindowAPI } from '@contentful/app-sdk';
|
|
2
|
+
export { CharCounter } from './CharCounter';
|
|
3
|
+
export { CharValidation } from './CharValidation';
|
|
4
|
+
export { FieldConnector } from './FieldConnector';
|
|
5
|
+
export { PredefinedValuesError } from './PredefinedValuesError';
|
|
6
|
+
export { Asset, Entry, File } from './typesEntity';
|
|
7
|
+
export { isValidImage } from './utils/isValidImage';
|
|
8
|
+
export { shortenStorageUnit, toLocaleString } from './utils/shortenStorageUnit';
|
|
9
|
+
export { ModalDialogLauncher };
|
|
10
|
+
export { entityHelpers };
|
|
11
|
+
export { ConstraintsUtils };
|
|
12
|
+
import * as ModalDialogLauncher from './ModalDialogLauncher';
|
|
13
|
+
import * as ConstraintsUtils from './utils/constraints';
|
|
14
|
+
import * as entityHelpers from './utils/entityHelpers';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BaseExtensionSDK, ContentType, ContentTypeField, Link, Entry, Asset } from '@contentful/app-sdk';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import isNumber from 'lodash/isNumber';
|
|
2
|
+
export function fromFieldValidations(validations = [], fieldType) {
|
|
3
|
+
const sizeValidation = validations.find((v)=>'size' in v);
|
|
4
|
+
const size = sizeValidation && sizeValidation.size || {};
|
|
5
|
+
const min = size.min;
|
|
6
|
+
const max = size.max;
|
|
7
|
+
if (isNumber(min) && isNumber(max)) {
|
|
8
|
+
return {
|
|
9
|
+
type: 'min-max',
|
|
10
|
+
min,
|
|
11
|
+
max
|
|
12
|
+
};
|
|
13
|
+
} else if (isNumber(min)) {
|
|
14
|
+
return {
|
|
15
|
+
type: 'min',
|
|
16
|
+
min
|
|
17
|
+
};
|
|
18
|
+
} else if (isNumber(max)) {
|
|
19
|
+
return {
|
|
20
|
+
type: 'max',
|
|
21
|
+
max
|
|
22
|
+
};
|
|
23
|
+
} else {
|
|
24
|
+
return {
|
|
25
|
+
type: 'max',
|
|
26
|
+
max: fieldType === 'Symbol' ? 256 : 50000
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function makeChecker(constraint) {
|
|
31
|
+
return function checkConstraint(length) {
|
|
32
|
+
if (constraint.type === 'max') {
|
|
33
|
+
return length <= constraint.max;
|
|
34
|
+
} else if (constraint.type === 'min') {
|
|
35
|
+
return length >= constraint.min;
|
|
36
|
+
} else {
|
|
37
|
+
return length >= constraint.min && length <= constraint.max;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import get from 'lodash/get';
|
|
2
|
+
import isObject from 'lodash/isObject';
|
|
3
|
+
import isString from 'lodash/isString';
|
|
4
|
+
function titleOrDefault(title, defaultTitle) {
|
|
5
|
+
if (!isString(title)) {
|
|
6
|
+
return defaultTitle;
|
|
7
|
+
}
|
|
8
|
+
if (title) {
|
|
9
|
+
const trimmedTitle = title.trim();
|
|
10
|
+
if (trimmedTitle.length === 0) {
|
|
11
|
+
return defaultTitle;
|
|
12
|
+
}
|
|
13
|
+
return trimmedTitle;
|
|
14
|
+
}
|
|
15
|
+
return defaultTitle;
|
|
16
|
+
}
|
|
17
|
+
export function getFieldValue({ entity , fieldId , localeCode , defaultLocaleCode }) {
|
|
18
|
+
const values = get(entity, [
|
|
19
|
+
'fields',
|
|
20
|
+
fieldId
|
|
21
|
+
]);
|
|
22
|
+
if (!isObject(values)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const firstLocaleCode = Object.keys(values)[0];
|
|
26
|
+
return values[localeCode] || values[defaultLocaleCode] || values[firstLocaleCode];
|
|
27
|
+
}
|
|
28
|
+
export function getAssetTitle({ asset , localeCode , defaultLocaleCode , defaultTitle }) {
|
|
29
|
+
const title = getFieldValue({
|
|
30
|
+
entity: {
|
|
31
|
+
fields: {
|
|
32
|
+
title: asset.fields?.title
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
fieldId: 'title',
|
|
36
|
+
localeCode,
|
|
37
|
+
defaultLocaleCode
|
|
38
|
+
});
|
|
39
|
+
return titleOrDefault(title, defaultTitle);
|
|
40
|
+
}
|
|
41
|
+
export const isAssetField = (field)=>field.type === 'Link' && field.linkType === 'Asset';
|
|
42
|
+
export function isDisplayField({ field , contentType }) {
|
|
43
|
+
return field.id === contentType.displayField;
|
|
44
|
+
}
|
|
45
|
+
export function isDescriptionField({ field , contentType }) {
|
|
46
|
+
const isTextField = (field)=>[
|
|
47
|
+
'Symbol',
|
|
48
|
+
'Text'
|
|
49
|
+
].includes(field.type);
|
|
50
|
+
const isMaybeSlugField = (field)=>/\bslug\b/.test(field.name);
|
|
51
|
+
return isTextField(field) && !isDisplayField({
|
|
52
|
+
field,
|
|
53
|
+
contentType
|
|
54
|
+
}) && !isMaybeSlugField(field);
|
|
55
|
+
}
|
|
56
|
+
export function getEntityDescription({ entity , contentType , localeCode , defaultLocaleCode }) {
|
|
57
|
+
if (!contentType) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
const descriptionField = contentType.fields.find((field)=>isDescriptionField({
|
|
61
|
+
field,
|
|
62
|
+
contentType
|
|
63
|
+
}));
|
|
64
|
+
if (!descriptionField) {
|
|
65
|
+
return '';
|
|
66
|
+
}
|
|
67
|
+
return getFieldValue({
|
|
68
|
+
entity,
|
|
69
|
+
fieldId: descriptionField.id,
|
|
70
|
+
localeCode,
|
|
71
|
+
defaultLocaleCode
|
|
72
|
+
}) || '';
|
|
73
|
+
}
|
|
74
|
+
export function getEntryTitle({ entry , contentType , localeCode , defaultLocaleCode , defaultTitle }) {
|
|
75
|
+
let title;
|
|
76
|
+
if (!contentType) {
|
|
77
|
+
return defaultTitle;
|
|
78
|
+
}
|
|
79
|
+
const displayField = contentType.displayField;
|
|
80
|
+
if (!displayField) {
|
|
81
|
+
return defaultTitle;
|
|
82
|
+
}
|
|
83
|
+
const displayFieldInfo = contentType.fields.find((field)=>field.id === displayField);
|
|
84
|
+
if (!displayFieldInfo) {
|
|
85
|
+
return defaultTitle;
|
|
86
|
+
}
|
|
87
|
+
if (displayFieldInfo.localized) {
|
|
88
|
+
title = getFieldValue({
|
|
89
|
+
entity: entry,
|
|
90
|
+
fieldId: displayField,
|
|
91
|
+
localeCode,
|
|
92
|
+
defaultLocaleCode
|
|
93
|
+
});
|
|
94
|
+
if (!title) {
|
|
95
|
+
title = getFieldValue({
|
|
96
|
+
entity: entry,
|
|
97
|
+
fieldId: displayFieldInfo.id,
|
|
98
|
+
localeCode,
|
|
99
|
+
defaultLocaleCode
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
title = getFieldValue({
|
|
104
|
+
entity: entry,
|
|
105
|
+
fieldId: displayField,
|
|
106
|
+
defaultLocaleCode,
|
|
107
|
+
localeCode: ''
|
|
108
|
+
});
|
|
109
|
+
if (!title) {
|
|
110
|
+
title = getFieldValue({
|
|
111
|
+
entity: entry,
|
|
112
|
+
fieldId: displayFieldInfo.id,
|
|
113
|
+
defaultLocaleCode,
|
|
114
|
+
localeCode: ''
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return titleOrDefault(title, defaultTitle);
|
|
119
|
+
}
|
|
120
|
+
export function getEntryStatus(sys) {
|
|
121
|
+
if (!sys || sys.type !== 'Entry' && sys.type !== 'Asset') {
|
|
122
|
+
throw new TypeError('Invalid entity metadata object');
|
|
123
|
+
}
|
|
124
|
+
if (sys.deletedVersion) {
|
|
125
|
+
return 'deleted';
|
|
126
|
+
} else if (sys.archivedVersion) {
|
|
127
|
+
return 'archived';
|
|
128
|
+
} else if (sys.publishedVersion) {
|
|
129
|
+
if (sys.version > sys.publishedVersion + 1) {
|
|
130
|
+
return 'changed';
|
|
131
|
+
} else {
|
|
132
|
+
return 'published';
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
return 'draft';
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export const getEntryImage = async ({ entry , contentType , localeCode }, getAsset)=>{
|
|
139
|
+
if (!contentType) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
const assetLink = contentType.fields.find(isAssetField);
|
|
143
|
+
if (!assetLink) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
const assetId = get(entry.fields, [
|
|
147
|
+
assetLink.id,
|
|
148
|
+
localeCode,
|
|
149
|
+
'sys',
|
|
150
|
+
'id'
|
|
151
|
+
]);
|
|
152
|
+
if (!assetId) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
const asset = await getAsset(assetId);
|
|
157
|
+
const file = get(asset, [
|
|
158
|
+
'fields',
|
|
159
|
+
'file',
|
|
160
|
+
localeCode
|
|
161
|
+
]);
|
|
162
|
+
const isImage = Boolean(get(file, [
|
|
163
|
+
'details',
|
|
164
|
+
'image'
|
|
165
|
+
], false));
|
|
166
|
+
return isImage ? file : null;
|
|
167
|
+
} catch (e) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function isValidImage(file) {
|
|
2
|
+
const validMimeTypes = [
|
|
3
|
+
'image/avif',
|
|
4
|
+
'image/bmp',
|
|
5
|
+
'image/x-windows-bmp',
|
|
6
|
+
'image/gif',
|
|
7
|
+
'image/webp',
|
|
8
|
+
'image/jpg',
|
|
9
|
+
'image/jpeg',
|
|
10
|
+
'image/pjpeg',
|
|
11
|
+
'image/x-jps',
|
|
12
|
+
'image/png',
|
|
13
|
+
'image/svg+xml'
|
|
14
|
+
];
|
|
15
|
+
return validMimeTypes.includes(file.contentType);
|
|
16
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function toLocaleString(number) {
|
|
2
|
+
return number.toLocaleString('en-US');
|
|
3
|
+
}
|
|
4
|
+
function formatFloat(value, localize) {
|
|
5
|
+
return localize ? toLocaleString(value) : value.toFixed(2).replace(/\.(0)*$|0*$/, '');
|
|
6
|
+
}
|
|
7
|
+
export function shortenStorageUnit(value, uom) {
|
|
8
|
+
if (value <= 0) {
|
|
9
|
+
return '0 B';
|
|
10
|
+
}
|
|
11
|
+
const units = [
|
|
12
|
+
'PB',
|
|
13
|
+
'TB',
|
|
14
|
+
'GB',
|
|
15
|
+
'MB',
|
|
16
|
+
'KB',
|
|
17
|
+
'B'
|
|
18
|
+
];
|
|
19
|
+
const getBigger = (unit)=>units[units.indexOf(unit) - 1];
|
|
20
|
+
const getSmaller = (unit)=>units[units.indexOf(unit) + 1];
|
|
21
|
+
const isBiggestUnit = (unit)=>units.indexOf(unit) === 0;
|
|
22
|
+
const isSmallestUnit = (unit)=>units.indexOf(unit) === units.length - 1;
|
|
23
|
+
const reduce = (number, unit)=>{
|
|
24
|
+
if (number < 0.99 && !isSmallestUnit(unit)) {
|
|
25
|
+
return reduce(number * 1000, getSmaller(unit));
|
|
26
|
+
} else if (number >= 1000 && !isBiggestUnit(unit)) {
|
|
27
|
+
return reduce(number / 1000, getBigger(unit));
|
|
28
|
+
} else {
|
|
29
|
+
return {
|
|
30
|
+
number,
|
|
31
|
+
unit
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const { number , unit } = reduce(value, uom);
|
|
36
|
+
return `${formatFloat(number, false)} ${unit}`;
|
|
37
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { ValidationType } from './types';
|
|
3
|
-
interface CharValidationProps {
|
|
4
|
-
constraints: ValidationType;
|
|
5
|
-
}
|
|
6
|
-
export declare function CharValidation(props: CharValidationProps): JSX.Element;
|
|
7
|
-
export {};
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ValidationType } from './types';
|
|
3
|
+
interface CharValidationProps {
|
|
4
|
+
constraints: ValidationType;
|
|
5
|
+
}
|
|
6
|
+
export declare function CharValidation(props: CharValidationProps): React.JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -1,48 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
export {};
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { FieldAPI, ValidationError } from '@contentful/app-sdk';
|
|
3
|
+
type Nullable = null | undefined;
|
|
4
|
+
export interface FieldConnectorChildProps<ValueType> {
|
|
5
|
+
isLocalValueChange: boolean;
|
|
6
|
+
externalReset: number;
|
|
7
|
+
lastRemoteValue: ValueType | Nullable;
|
|
8
|
+
value: ValueType | Nullable;
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
errors: ValidationError[];
|
|
11
|
+
setValue: (value: ValueType | Nullable) => Promise<unknown>;
|
|
12
|
+
}
|
|
13
|
+
interface FieldConnectorState<ValueType> {
|
|
14
|
+
isLocalValueChange: boolean;
|
|
15
|
+
externalReset: number;
|
|
16
|
+
lastRemoteValue: ValueType | Nullable;
|
|
17
|
+
value: ValueType | Nullable;
|
|
18
|
+
disabled: boolean;
|
|
19
|
+
errors: ValidationError[];
|
|
20
|
+
}
|
|
21
|
+
interface FieldConnectorProps<ValueType> {
|
|
22
|
+
field: FieldAPI;
|
|
23
|
+
isInitiallyDisabled: boolean;
|
|
24
|
+
isDisabled?: boolean;
|
|
25
|
+
children: (state: FieldConnectorChildProps<ValueType>) => React.ReactNode;
|
|
26
|
+
isEmptyValue: (value: ValueType | null) => boolean;
|
|
27
|
+
isEqualValues: (value1: ValueType | Nullable, value2: ValueType | Nullable) => boolean;
|
|
28
|
+
throttle: number;
|
|
29
|
+
}
|
|
30
|
+
export declare class FieldConnector<ValueType> extends React.Component<FieldConnectorProps<ValueType>, FieldConnectorState<ValueType>> {
|
|
31
|
+
static defaultProps: {
|
|
32
|
+
children: () => null;
|
|
33
|
+
isEmptyValue: (value: any | Nullable) => boolean;
|
|
34
|
+
isEqualValues: (value1: any | Nullable, value2: any | Nullable) => boolean;
|
|
35
|
+
throttle: number;
|
|
36
|
+
};
|
|
37
|
+
constructor(props: FieldConnectorProps<ValueType>);
|
|
38
|
+
unsubscribeErrors: Function | null;
|
|
39
|
+
unsubscribeDisabled: Function | null;
|
|
40
|
+
unsubscribeValue: Function | null;
|
|
41
|
+
setValue: (value: ValueType | Nullable) => Promise<void>;
|
|
42
|
+
triggerSetValueCallbacks: import("lodash-es").DebouncedFunc<(value: ValueType | Nullable) => Promise<unknown>>;
|
|
43
|
+
componentDidMount(): void;
|
|
44
|
+
componentWillUnmount(): void;
|
|
45
|
+
render(): React.ReactNode;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { OpenCustomWidgetOptions } from '@contentful/app-sdk';
|
|
3
|
-
export declare function open(componentRenderer: (params: {
|
|
4
|
-
onClose: Function;
|
|
5
|
-
isShown: boolean;
|
|
6
|
-
}) => any): Promise<unknown>;
|
|
7
|
-
export declare function openDialog<T>(options: OpenCustomWidgetOptions, Component: React.SFC<{
|
|
8
|
-
onClose: (result: T) => void;
|
|
9
|
-
}>): Promise<unknown>;
|
|
10
|
-
declare const _default: {
|
|
11
|
-
openDialog: typeof openDialog;
|
|
12
|
-
};
|
|
13
|
-
export default _default;
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { OpenCustomWidgetOptions } from '@contentful/app-sdk';
|
|
3
|
+
export declare function open(componentRenderer: (params: {
|
|
4
|
+
onClose: Function;
|
|
5
|
+
isShown: boolean;
|
|
6
|
+
}) => any): Promise<unknown>;
|
|
7
|
+
export declare function openDialog<T>(options: OpenCustomWidgetOptions, Component: React.SFC<{
|
|
8
|
+
onClose: (result: T) => void;
|
|
9
|
+
}>): Promise<unknown>;
|
|
10
|
+
declare const _default: {
|
|
11
|
+
openDialog: typeof openDialog;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
|
|
12
|
-
export { ConstraintsUtils };
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
export { AccessAPI, AppConfigAPI, BaseExtensionSDK, ContentType, DialogsAPI, EntryAPI, EntryFieldAPI, FieldAPI, FieldExtensionSDK, IdsAPI, LocalesAPI, LocationAPI, NavigatorAPI, NotifierAPI, OpenCustomWidgetOptions, ParametersAPI, SpaceAPI, WindowAPI, } from '@contentful/app-sdk';
|
|
2
|
+
export { CharCounter } from './CharCounter';
|
|
3
|
+
export { CharValidation } from './CharValidation';
|
|
4
|
+
export { FieldConnector } from './FieldConnector';
|
|
5
|
+
export type { FieldConnectorChildProps } from './FieldConnector';
|
|
6
|
+
export { PredefinedValuesError } from './PredefinedValuesError';
|
|
7
|
+
export { Asset, Entry, File } from './typesEntity';
|
|
8
|
+
export { isValidImage } from './utils/isValidImage';
|
|
9
|
+
export { shortenStorageUnit, toLocaleString } from './utils/shortenStorageUnit';
|
|
10
|
+
export { ModalDialogLauncher };
|
|
11
|
+
export { entityHelpers };
|
|
12
|
+
export { ConstraintsUtils };
|
|
13
|
+
import * as ModalDialogLauncher from './ModalDialogLauncher';
|
|
14
|
+
import * as ConstraintsUtils from './utils/constraints';
|
|
15
|
+
import * as entityHelpers from './utils/entityHelpers';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
type: 'max';
|
|
3
|
-
max: number;
|
|
4
|
-
} | {
|
|
5
|
-
type: 'min';
|
|
6
|
-
min: number;
|
|
7
|
-
} | {
|
|
8
|
-
type: 'min-max';
|
|
9
|
-
min: number;
|
|
10
|
-
max: number;
|
|
11
|
-
};
|
|
1
|
+
export type ValidationType = {
|
|
2
|
+
type: 'max';
|
|
3
|
+
max: number;
|
|
4
|
+
} | {
|
|
5
|
+
type: 'min';
|
|
6
|
+
min: number;
|
|
7
|
+
} | {
|
|
8
|
+
type: 'min-max';
|
|
9
|
+
min: number;
|
|
10
|
+
max: number;
|
|
11
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { BaseExtensionSDK, ContentType, ContentTypeField, Link, Entry, Asset, } from '@contentful/app-sdk';
|
|
2
|
-
export interface File {
|
|
3
|
-
fileName: string;
|
|
4
|
-
contentType: string;
|
|
5
|
-
upload?: string;
|
|
6
|
-
url?: string;
|
|
7
|
-
details?: Record<string, any>;
|
|
8
|
-
uploadFrom?: Record<string, any>;
|
|
9
|
-
}
|
|
1
|
+
export { BaseExtensionSDK, ContentType, ContentTypeField, Link, Entry, Asset, } from '@contentful/app-sdk';
|
|
2
|
+
export interface File {
|
|
3
|
+
fileName: string;
|
|
4
|
+
contentType: string;
|
|
5
|
+
upload?: string;
|
|
6
|
+
url?: string;
|
|
7
|
+
details?: Record<string, any>;
|
|
8
|
+
uploadFrom?: Record<string, any>;
|
|
9
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ValidationType } from '../types';
|
|
2
|
-
export declare function fromFieldValidations(validations: Record<string, any>[] | undefined, fieldType: 'Symbol' | 'Text'): ValidationType;
|
|
3
|
-
export declare function makeChecker(constraint: ValidationType): (length: number) => boolean;
|
|
1
|
+
import { ValidationType } from '../types';
|
|
2
|
+
export declare function fromFieldValidations(validations: Record<string, any>[] | undefined, fieldType: 'Symbol' | 'Text'): ValidationType;
|
|
3
|
+
export declare function makeChecker(constraint: ValidationType): (length: number) => boolean;
|