@strapi/admin 4.6.0 → 4.7.0-beta.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/.browserslistrc +2 -1
- package/admin/src/assets/images/onboarding-preview.png +0 -0
- package/admin/src/components/AuthenticatedApp/utils/api.js +5 -4
- package/admin/src/components/LeftMenu/index.js +9 -3
- package/admin/src/content-manager/components/CollectionTypeFormWrapper/index.js +18 -16
- package/admin/src/content-manager/components/DynamicTable/CellContent/RelationMultiple/index.js +5 -5
- package/admin/src/content-manager/components/EditViewDataManagerProvider/utils/findLeafByPathAndReplace.js +1 -3
- package/admin/src/content-manager/components/EditViewDataManagerProvider/utils/schema.js +6 -5
- package/admin/src/content-manager/components/InputUID/index.js +4 -4
- package/admin/src/content-manager/components/Inputs/index.js +0 -2
- package/admin/src/content-manager/components/SingleTypeFormWrapper/index.js +35 -14
- package/admin/src/content-manager/hooks/useFetchContentTypeLayout/index.js +4 -3
- package/admin/src/content-manager/hooks/useLazyComponents/index.js +9 -13
- package/admin/src/content-manager/hooks/useRelation/useRelation.js +4 -4
- package/admin/src/content-manager/pages/App/useModels.js +8 -3
- package/admin/src/content-manager/pages/App/utils/getContentTypeLinks.js +3 -2
- package/admin/src/content-manager/pages/ComponentSetttingsView/index.js +4 -4
- package/admin/src/content-manager/pages/EditSettingsView/utils/api.js +4 -2
- package/admin/src/content-manager/pages/ListSettingsView/utils/api.js +4 -2
- package/admin/src/content-manager/pages/ListView/index.js +9 -9
- package/admin/src/core/utils/index.js +0 -1
- package/admin/src/hooks/useFetchEnabledPlugins/utils/api.js +3 -2
- package/admin/src/hooks/useInjectReducer/index.js +1 -0
- package/admin/src/hooks/useInjectReducer/useInjectReducer.js +19 -0
- package/admin/src/hooks/useRegenerate/index.js +4 -4
- package/admin/src/hooks/useRolesList/index.js +5 -3
- package/admin/src/hooks/useSettingsMenu/utils/defaultGlobalLinks.js +7 -0
- package/admin/src/index.js +4 -3
- package/admin/src/pages/Admin/Onboarding/constants.js +46 -0
- package/admin/src/pages/Admin/Onboarding/index.js +161 -89
- package/admin/src/pages/Admin/index.js +5 -2
- package/admin/src/pages/ProfilePage/utils/api.js +5 -3
- package/admin/src/pages/SettingsPage/{pages/Users/ListPage → components}/Filters/index.js +0 -0
- package/admin/src/pages/SettingsPage/{pages/ApiTokens/EditView/components → components/Tokens}/FormHead/index.js +36 -19
- package/admin/src/pages/SettingsPage/components/Tokens/FormiTokenContainer/LifeSpanInput.js +96 -0
- package/admin/src/pages/SettingsPage/components/Tokens/LifeSpanInput/index.js +98 -0
- package/admin/src/pages/SettingsPage/components/Tokens/Regenerate/index.js +73 -0
- package/admin/src/pages/SettingsPage/{pages/ApiTokens/ListView/DynamicTable → components/Tokens/Table}/DefaultButton/index.js +1 -1
- package/admin/src/pages/SettingsPage/{pages/ApiTokens/ListView/DynamicTable → components/Tokens/Table}/DeleteButton/index.js +1 -1
- package/admin/src/pages/SettingsPage/{pages/ApiTokens/ListView/DynamicTable → components/Tokens/Table}/ReadButton/index.js +0 -0
- package/admin/src/pages/SettingsPage/{pages/ApiTokens/ListView/DynamicTable → components/Tokens/Table}/UpdateButton/index.js +0 -0
- package/admin/src/pages/SettingsPage/components/Tokens/Table/index.js +135 -0
- package/admin/src/pages/SettingsPage/{pages/ApiTokens/EditView/components/ContentBox → components/Tokens/TokenBox}/index.js +17 -17
- package/admin/src/pages/SettingsPage/components/Tokens/TokenDescription/index.js +51 -0
- package/admin/src/pages/SettingsPage/components/Tokens/TokenName/index.js +46 -0
- package/admin/src/pages/SettingsPage/components/Tokens/TokenTypeSelect/index.js +69 -0
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/CollapsableContentType/index.js +5 -3
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/FormApiTokenContainer/index.js +52 -142
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/Regenerate/index.js +5 -1
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/index.js +43 -19
- package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/index.js +9 -16
- package/admin/src/pages/SettingsPage/pages/ApplicationInfosPage/utils/api.js +5 -3
- package/admin/src/pages/SettingsPage/pages/TransferTokens/EditView/components/FormTransferTokenContainer/index.js +105 -0
- package/admin/src/pages/SettingsPage/pages/TransferTokens/EditView/components/LoadingView/index.js +50 -0
- package/admin/src/pages/SettingsPage/pages/TransferTokens/EditView/index.js +201 -0
- package/admin/src/pages/SettingsPage/pages/TransferTokens/EditView/utils/getDateOfExpiration.js +16 -0
- package/admin/src/pages/SettingsPage/pages/TransferTokens/EditView/utils/index.js +4 -0
- package/admin/src/pages/SettingsPage/pages/TransferTokens/EditView/utils/schema.js +10 -0
- package/admin/src/pages/SettingsPage/pages/TransferTokens/ListView/index.js +182 -0
- package/admin/src/pages/SettingsPage/pages/TransferTokens/ListView/utils/tableHeaders.js +48 -0
- package/admin/src/pages/SettingsPage/pages/TransferTokens/ProtectedCreateView/index.js +14 -0
- package/admin/src/pages/SettingsPage/pages/TransferTokens/ProtectedEditView/index.js +14 -0
- package/admin/src/pages/SettingsPage/pages/TransferTokens/ProtectedListView/index.js +12 -0
- package/admin/src/pages/SettingsPage/pages/Users/EditPage/utils/api.js +6 -3
- package/admin/src/pages/SettingsPage/pages/Users/ListPage/ModalForm/index.js +9 -3
- package/admin/src/pages/SettingsPage/pages/Users/ListPage/index.js +1 -1
- package/admin/src/pages/SettingsPage/pages/Users/ListPage/utils/api.js +6 -3
- package/admin/src/pages/SettingsPage/pages/Users/components/SelectRoles/index.js +3 -2
- package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/index.js +3 -2
- package/admin/src/pages/SettingsPage/utils/defaultRoutes.js +33 -0
- package/admin/src/permissions/defaultPermissions.js +8 -0
- package/admin/src/translations/en.json +25 -6
- package/admin/src/translations/eu.json +796 -0
- package/admin/src/translations/languageNativeNames.js +1 -0
- package/admin/src/translations/ru.json +9 -9
- package/build/1412.936ed920.chunk.js +159 -0
- package/build/1683.c8aa7b7c.chunk.js +268 -0
- package/build/19eb2dfcf2603eb55733.png +0 -0
- package/build/2607.2e48dbf8.chunk.js +66 -0
- package/build/2743.6d1632f9.chunk.js +45 -0
- package/build/3075.dc3894fe.chunk.js +108 -0
- package/build/3632.0317b618.chunk.js +138 -0
- package/build/4649.15cc0afe.chunk.js +30 -0
- package/build/{5910.a5374848.chunk.js → 4855.bd092921.chunk.js} +65 -65
- package/build/7259.aa68d808.chunk.js +1 -0
- package/build/7407.883fb1f5.chunk.js +1 -0
- package/build/9707.7290fd92.chunk.js +96 -0
- package/build/Admin-authenticatedApp.f29f6021.chunk.js +79 -0
- package/build/{Admin_homePage.79ab880c.chunk.js → Admin_homePage.b1730882.chunk.js} +1 -1
- package/build/{Admin_marketplace.eabf21b2.chunk.js → Admin_marketplace.ea0316c2.chunk.js} +2 -2
- package/build/Admin_pluginsPage.5c24f963.chunk.js +6 -0
- package/build/Admin_profilePage.59af1978.chunk.js +15 -0
- package/build/Admin_settingsPage.178dc6e3.chunk.js +178 -0
- package/build/admin-app.77a50e1f.chunk.js +112 -0
- package/build/admin-edit-roles-page.446b69dc.chunk.js +1 -0
- package/build/admin-edit-users.2ed69bfd.chunk.js +10 -0
- package/build/admin-users.fc003b10.chunk.js +11 -0
- package/build/{api-tokens-create-page.0e686c30.chunk.js → api-tokens-create-page.0db3aec1.chunk.js} +1 -1
- package/build/{api-tokens-edit-page.d6c7487b.chunk.js → api-tokens-edit-page.671e0e26.chunk.js} +1 -1
- package/build/api-tokens-list-page.7387102c.chunk.js +16 -0
- package/build/audit-logs-settings-page.c3dce30d.chunk.js +1 -0
- package/build/content-manager.42b24d46.chunk.js +1139 -0
- package/build/{content-type-builder-list-view.4243b2b1.chunk.js → content-type-builder-list-view.79e84b36.chunk.js} +1 -6
- package/build/{content-type-builder.365b6bf4.chunk.js → content-type-builder.855db321.chunk.js} +16 -15
- package/build/{email-settings-page.379552b1.chunk.js → email-settings-page.d1fcc7a3.chunk.js} +4 -9
- package/build/en-json.b0748970.chunk.js +1 -0
- package/build/eu-json.fceecd8b.chunk.js +1 -0
- package/build/i18n-settings-page.b8d8753e.chunk.js +60 -0
- package/build/index.html +1 -1
- package/build/main.1022ed01.js +4393 -0
- package/build/ru-json.aa5cd123.chunk.js +1 -0
- package/build/runtime~main.84941a97.js +2 -0
- package/build/sso-settings-page.b85ad080.chunk.js +41 -0
- package/build/transfer-tokens-create-page.16e23791.chunk.js +1 -0
- package/build/transfer-tokens-edit-page.3886c973.chunk.js +1 -0
- package/build/transfer-tokens-list-page.e8010a89.chunk.js +16 -0
- package/build/upload-settings.ef64bbf9.chunk.js +84 -0
- package/build/upload.c5730dfa.chunk.js +33 -0
- package/build/users-advanced-settings-page.fce9908e.chunk.js +8 -0
- package/build/users-email-settings-page.343d0ad2.chunk.js +23 -0
- package/build/users-providers-settings-page.e5a9a3f1.chunk.js +99 -0
- package/build/users-roles-settings-page.66312f31.chunk.js +30 -0
- package/build/webhook-edit-page.73e51e64.chunk.js +75 -0
- package/build/{webhook-list-page.f75ba3f2.chunk.js → webhook-list-page.1134f130.chunk.js} +1 -1
- package/ee/admin/pages/SettingsPage/pages/AuditLogs/ListView/ComboboxFilter/index.js +41 -0
- package/ee/admin/pages/SettingsPage/pages/AuditLogs/ListView/Modal/ActionBody.js +1 -3
- package/ee/admin/pages/SettingsPage/pages/AuditLogs/ListView/TableRows/index.js +1 -1
- package/ee/admin/pages/SettingsPage/pages/AuditLogs/ListView/hooks/useAuditLogsData.js +47 -0
- package/ee/admin/pages/SettingsPage/pages/AuditLogs/ListView/index.js +30 -31
- package/ee/admin/pages/SettingsPage/pages/AuditLogs/ListView/utils/getActionTypesDefaultMessages.js +7 -9
- package/ee/admin/pages/SettingsPage/pages/AuditLogs/ListView/utils/getDisplayedFilters.js +88 -0
- package/ee/admin/pages/SettingsPage/pages/Roles/ListPage/index.js +4 -2
- package/ee/server/migrations/audit-logs-table.js +45 -0
- package/ee/server/register.js +2 -0
- package/ee/server/services/audit-logs.js +11 -1
- package/package.json +30 -30
- package/server/bootstrap.js +2 -0
- package/server/config/admin-actions.js +48 -0
- package/server/content-types/index.js +2 -0
- package/server/content-types/transfer-token-permission.js +36 -0
- package/server/content-types/transfer-token.js +66 -0
- package/server/controllers/admin.js +16 -0
- package/server/controllers/api-token.js +4 -5
- package/server/controllers/index.js +1 -0
- package/server/controllers/transfer/index.js +13 -0
- package/server/controllers/transfer/runner.js +24 -0
- package/server/controllers/transfer/token.js +131 -0
- package/server/register.js +2 -9
- package/server/routes/index.js +2 -0
- package/server/routes/transfer.js +95 -0
- package/server/services/api-token.js +2 -3
- package/server/services/constants.js +6 -0
- package/server/services/index.js +1 -0
- package/server/services/transfer/index.js +6 -0
- package/server/services/transfer/permission.js +22 -0
- package/server/services/transfer/token.js +409 -0
- package/server/strategies/api-token.js +4 -2
- package/server/strategies/data-transfer.js +107 -0
- package/server/strategies/index.js +1 -0
- package/server/utils/index.d.ts +2 -0
- package/server/validation/api-tokens.js +1 -6
- package/server/validation/transfer/index.js +5 -0
- package/server/validation/transfer/token.js +34 -0
- package/admin/src/content-manager/components/InputJSON/FieldWrapper.js +0 -40
- package/admin/src/content-manager/components/InputJSON/Label.js +0 -35
- package/admin/src/content-manager/components/InputJSON/components.js +0 -36
- package/admin/src/content-manager/components/InputJSON/index.js +0 -223
- package/admin/src/content-manager/components/InputJSON/jsonlint.js +0 -680
- package/admin/src/core/utils/axiosInstance.js +0 -40
- package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/FormBody/index.js +0 -78
- package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/index.js +0 -112
- package/build/2607.ce06608e.chunk.js +0 -66
- package/build/2743.dea372fb.chunk.js +0 -42
- package/build/3075.03ebe93d.chunk.js +0 -115
- package/build/3632.963ac97d.chunk.js +0 -138
- package/build/4318.8cb388a5.chunk.js +0 -30
- package/build/4656.a0d43cca.chunk.js +0 -159
- package/build/8633.4af74a50.chunk.js +0 -1
- package/build/9641.a311b612.chunk.js +0 -276
- package/build/9707.62831b4d.chunk.js +0 -101
- package/build/Admin-authenticatedApp.50dc27f9.chunk.js +0 -75
- package/build/Admin_pluginsPage.953e796b.chunk.js +0 -6
- package/build/Admin_profilePage.5c2efda5.chunk.js +0 -15
- package/build/Admin_settingsPage.19cfb9ca.chunk.js +0 -178
- package/build/admin-app.34295b50.chunk.js +0 -112
- package/build/admin-edit-roles-page.d50d9654.chunk.js +0 -1
- package/build/admin-edit-users.912b856d.chunk.js +0 -10
- package/build/admin-users.e36e7111.chunk.js +0 -11
- package/build/api-tokens-list-page.1cd86136.chunk.js +0 -16
- package/build/audit-logs-settings-page.308a6250.chunk.js +0 -1
- package/build/codemirror-addon-closebrackets.71aa4bbd.chunk.js +0 -2
- package/build/codemirror-addon-lint-js.405f70fb.chunk.js +0 -1
- package/build/codemirror-addon-lint.8487ad3d.chunk.js +0 -1
- package/build/codemirror-addon-mark-selection.1928c849.chunk.js +0 -1
- package/build/codemirror-css.359a2a4b.chunk.js +0 -345
- package/build/codemirror-javacript.af237b68.chunk.js +0 -1
- package/build/codemirror-theme.2fe63a16.chunk.js +0 -33
- package/build/content-manager.851f40ce.chunk.js +0 -1170
- package/build/en-json.38d182e5.chunk.js +0 -1
- package/build/i18n-settings-page.3ab28b1a.chunk.js +0 -65
- package/build/main.9f31732e.js +0 -4454
- package/build/ru-json.3b411a39.chunk.js +0 -1
- package/build/runtime~main.2b8e2318.js +0 -2
- package/build/sso-settings-page.b64a44e8.chunk.js +0 -41
- package/build/upload-settings.6c26ff37.chunk.js +0 -89
- package/build/upload.2c69d238.chunk.js +0 -38
- package/build/users-advanced-settings-page.c4270682.chunk.js +0 -13
- package/build/users-email-settings-page.60422a2f.chunk.js +0 -28
- package/build/users-providers-settings-page.e1834060.chunk.js +0 -104
- package/build/users-roles-settings-page.3ef35132.chunk.js +0 -30
- package/build/webhook-edit-page.c0080dc1.chunk.js +0 -75
package/server/utils/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import * as token from '../services/token';
|
|
|
7
7
|
import * as auth from '../services/auth';
|
|
8
8
|
import * as apiToken from '../services/api-token';
|
|
9
9
|
import * as projectSettings from '../services/project-settings';
|
|
10
|
+
import * as transfer from '../services/transfer';
|
|
10
11
|
|
|
11
12
|
type S = {
|
|
12
13
|
role: typeof role;
|
|
@@ -18,6 +19,7 @@ type S = {
|
|
|
18
19
|
metrics: typeof metrics;
|
|
19
20
|
'api-token': typeof apiToken;
|
|
20
21
|
'project-settings': typeof projectSettings;
|
|
22
|
+
transfer: typeof transfer;
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
export function getService<T extends keyof S>(name: T): S[T];
|
|
@@ -10,12 +10,7 @@ const apiTokenCreationSchema = yup
|
|
|
10
10
|
description: yup.string().optional(),
|
|
11
11
|
type: yup.string().oneOf(Object.values(constants.API_TOKEN_TYPE)).required(),
|
|
12
12
|
permissions: yup.array().of(yup.string()).nullable(),
|
|
13
|
-
lifespan: yup
|
|
14
|
-
.number()
|
|
15
|
-
.integer()
|
|
16
|
-
.min(1)
|
|
17
|
-
.oneOf(Object.values(constants.API_TOKEN_LIFESPANS))
|
|
18
|
-
.nullable(),
|
|
13
|
+
lifespan: yup.number().min(1).oneOf(Object.values(constants.API_TOKEN_LIFESPANS)).nullable(),
|
|
19
14
|
})
|
|
20
15
|
.noUnknown()
|
|
21
16
|
.strict();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { yup, validateYupSchema } = require('@strapi/utils');
|
|
4
|
+
const constants = require('../../services/constants');
|
|
5
|
+
|
|
6
|
+
const transferTokenCreationSchema = yup
|
|
7
|
+
.object()
|
|
8
|
+
.shape({
|
|
9
|
+
name: yup.string().min(1).required(),
|
|
10
|
+
description: yup.string().optional(),
|
|
11
|
+
permissions: yup.array().of(yup.string()).nullable(),
|
|
12
|
+
lifespan: yup
|
|
13
|
+
.number()
|
|
14
|
+
.min(1)
|
|
15
|
+
.oneOf(Object.values(constants.TRANSFER_TOKEN_LIFESPANS))
|
|
16
|
+
.nullable(),
|
|
17
|
+
})
|
|
18
|
+
.noUnknown()
|
|
19
|
+
.strict();
|
|
20
|
+
|
|
21
|
+
const transferTokenUpdateSchema = yup
|
|
22
|
+
.object()
|
|
23
|
+
.shape({
|
|
24
|
+
name: yup.string().min(1).notNull(),
|
|
25
|
+
description: yup.string().nullable(),
|
|
26
|
+
permissions: yup.array().of(yup.string()).nullable(),
|
|
27
|
+
})
|
|
28
|
+
.noUnknown()
|
|
29
|
+
.strict();
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
validateTransferTokenCreationInput: validateYupSchema(transferTokenCreationSchema),
|
|
33
|
+
validateTransferTokenUpdateInput: validateYupSchema(transferTokenUpdateSchema),
|
|
34
|
+
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { useIntl } from 'react-intl';
|
|
4
|
-
import { Field } from '@strapi/design-system/Field';
|
|
5
|
-
|
|
6
|
-
const FieldWrapper = ({ name, hint, error, children, required }) => {
|
|
7
|
-
const { formatMessage } = useIntl();
|
|
8
|
-
const errorMessage = error ? formatMessage({ id: error, defaultMessage: error }) : '';
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<Field
|
|
12
|
-
name={name}
|
|
13
|
-
hint={hint && formatMessage(hint)}
|
|
14
|
-
error={errorMessage}
|
|
15
|
-
id={name}
|
|
16
|
-
required={required}
|
|
17
|
-
>
|
|
18
|
-
{children}
|
|
19
|
-
</Field>
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
FieldWrapper.defaultProps = {
|
|
24
|
-
hint: undefined,
|
|
25
|
-
error: '',
|
|
26
|
-
required: false,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
FieldWrapper.propTypes = {
|
|
30
|
-
name: PropTypes.string.isRequired,
|
|
31
|
-
hint: PropTypes.shape({
|
|
32
|
-
id: PropTypes.string,
|
|
33
|
-
defaultMessage: PropTypes.string,
|
|
34
|
-
}),
|
|
35
|
-
error: PropTypes.string,
|
|
36
|
-
children: PropTypes.node.isRequired,
|
|
37
|
-
required: PropTypes.bool,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export default FieldWrapper;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { useIntl } from 'react-intl';
|
|
4
|
-
import { FieldLabel } from '@strapi/design-system/Field';
|
|
5
|
-
|
|
6
|
-
const Label = ({ intlLabel, labelAction, name }) => {
|
|
7
|
-
const { formatMessage } = useIntl();
|
|
8
|
-
const label = intlLabel?.id
|
|
9
|
-
? formatMessage(
|
|
10
|
-
{ id: intlLabel.id, defaultMessage: intlLabel.defaultMessage },
|
|
11
|
-
{ ...intlLabel.values }
|
|
12
|
-
)
|
|
13
|
-
: name;
|
|
14
|
-
|
|
15
|
-
return <FieldLabel action={labelAction}>{label}</FieldLabel>;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
Label.defaultProps = {
|
|
19
|
-
id: undefined,
|
|
20
|
-
intlLabel: undefined,
|
|
21
|
-
labelAction: undefined,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
Label.propTypes = {
|
|
25
|
-
id: PropTypes.string,
|
|
26
|
-
intlLabel: PropTypes.shape({
|
|
27
|
-
id: PropTypes.string.isRequired,
|
|
28
|
-
defaultMessage: PropTypes.string.isRequired,
|
|
29
|
-
values: PropTypes.object,
|
|
30
|
-
}),
|
|
31
|
-
labelAction: PropTypes.element,
|
|
32
|
-
name: PropTypes.string.isRequired,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export default Label;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import styled from 'styled-components';
|
|
2
|
-
import { Box } from '@strapi/design-system/Box';
|
|
3
|
-
|
|
4
|
-
/* eslint-disable */
|
|
5
|
-
/* stylelint-disable */
|
|
6
|
-
const EditorWrapper = styled.div`
|
|
7
|
-
cursor: ${({ disabled }) => (disabled ? 'not-allowed !important' : 'auto')};
|
|
8
|
-
/* BASICS */
|
|
9
|
-
|
|
10
|
-
.colored {
|
|
11
|
-
background-color: yellow;
|
|
12
|
-
color: black !important;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
> div {
|
|
16
|
-
border-radius: 3px;
|
|
17
|
-
> div:last-of-type {
|
|
18
|
-
min-height: 253px;
|
|
19
|
-
max-height: 506px;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.CodeMirror {
|
|
24
|
-
/* Set height, width, borders, and global font properties here */
|
|
25
|
-
font-size: ${14 / 16}rem;
|
|
26
|
-
direction: ltr;
|
|
27
|
-
z-index: 0;
|
|
28
|
-
}
|
|
29
|
-
`;
|
|
30
|
-
|
|
31
|
-
const StyledBox = styled(Box)`
|
|
32
|
-
border-radius: ${({ theme }) => theme.borderRadius};
|
|
33
|
-
border: 1px solid ${({ theme, error }) => (error ? theme.colors.danger600 : 'transparent')};
|
|
34
|
-
`;
|
|
35
|
-
|
|
36
|
-
export { EditorWrapper, StyledBox };
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* InputJSON
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import PropTypes from 'prop-types';
|
|
9
|
-
import cm from 'codemirror';
|
|
10
|
-
import trimStart from 'lodash/trimStart';
|
|
11
|
-
import { Stack } from '@strapi/design-system/Stack';
|
|
12
|
-
import { FieldHint, FieldError } from '@strapi/design-system/Field';
|
|
13
|
-
import jsonlint from './jsonlint';
|
|
14
|
-
import { EditorWrapper, StyledBox } from './components';
|
|
15
|
-
import Label from './Label';
|
|
16
|
-
import FieldWrapper from './FieldWrapper';
|
|
17
|
-
|
|
18
|
-
const WAIT = 600;
|
|
19
|
-
const DEFAULT_THEME = 'blackboard';
|
|
20
|
-
|
|
21
|
-
const loadCss = async () => {
|
|
22
|
-
await import(
|
|
23
|
-
/* webpackChunkName: "codemirror-javacript" */ 'codemirror/mode/javascript/javascript'
|
|
24
|
-
);
|
|
25
|
-
await import(/* webpackChunkName: "codemirror-addon-lint" */ 'codemirror/addon/lint/lint');
|
|
26
|
-
await import(
|
|
27
|
-
/* webpackChunkName: "codemirror-addon-lint-js" */ 'codemirror/addon/lint/javascript-lint'
|
|
28
|
-
);
|
|
29
|
-
await import(
|
|
30
|
-
/* webpackChunkName: "codemirror-addon-closebrackets" */ 'codemirror/addon/edit/closebrackets'
|
|
31
|
-
);
|
|
32
|
-
await import(
|
|
33
|
-
/* webpackChunkName: "codemirror-addon-mark-selection" */ 'codemirror/addon/selection/mark-selection'
|
|
34
|
-
);
|
|
35
|
-
await import(/* webpackChunkName: "codemirror-css" */ 'codemirror/lib/codemirror.css');
|
|
36
|
-
await import(/* webpackChunkName: "codemirror-theme" */ 'codemirror/theme/blackboard.css');
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
loadCss();
|
|
40
|
-
|
|
41
|
-
class InputJSON extends React.Component {
|
|
42
|
-
timer = null;
|
|
43
|
-
|
|
44
|
-
constructor(props) {
|
|
45
|
-
super(props);
|
|
46
|
-
this.editor = React.createRef();
|
|
47
|
-
this.state = { error: false, markedText: null };
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
componentDidMount() {
|
|
51
|
-
// Init codemirror component
|
|
52
|
-
this.codeMirror = cm.fromTextArea(this.editor.current, {
|
|
53
|
-
autoCloseBrackets: true,
|
|
54
|
-
lineNumbers: true,
|
|
55
|
-
matchBrackets: true,
|
|
56
|
-
mode: 'application/json',
|
|
57
|
-
readOnly: this.props.disabled,
|
|
58
|
-
smartIndent: true,
|
|
59
|
-
styleSelectedText: true,
|
|
60
|
-
tabSize: 2,
|
|
61
|
-
theme: DEFAULT_THEME,
|
|
62
|
-
fontSize: '13px',
|
|
63
|
-
});
|
|
64
|
-
this.codeMirror.on('change', this.handleChange);
|
|
65
|
-
|
|
66
|
-
this.setSize();
|
|
67
|
-
this.setInitValue();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
componentDidUpdate(prevProps) {
|
|
71
|
-
if (prevProps.value !== this.props.value && !this.codeMirror.state.focused) {
|
|
72
|
-
this.setInitValue();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
setInitValue = () => {
|
|
77
|
-
const { value } = this.props;
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
if (value === null) return this.codeMirror.setValue('');
|
|
81
|
-
|
|
82
|
-
if (value === 0) return this.codeMirror.setValue('0');
|
|
83
|
-
|
|
84
|
-
return this.codeMirror.setValue(value);
|
|
85
|
-
} catch (err) {
|
|
86
|
-
return this.setState({ error: true });
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
setSize = () => this.codeMirror.setSize('100%', 'auto');
|
|
91
|
-
|
|
92
|
-
getContentAtLine = (line) => this.codeMirror.getLine(line);
|
|
93
|
-
|
|
94
|
-
// getEditorOption = (opt) => this.codeMirror.getOption(opt);
|
|
95
|
-
// getValue = () => this.codeMirror.getValue();
|
|
96
|
-
|
|
97
|
-
markSelection = ({ message }) => {
|
|
98
|
-
let line = parseInt(message.split(':')[0].split('line ')[1], 10) - 1;
|
|
99
|
-
let content = this.getContentAtLine(line);
|
|
100
|
-
|
|
101
|
-
if (content === '{') {
|
|
102
|
-
line += 1;
|
|
103
|
-
content = this.getContentAtLine(line);
|
|
104
|
-
}
|
|
105
|
-
const chEnd = content.length;
|
|
106
|
-
const chStart = chEnd - trimStart(content, ' ').length;
|
|
107
|
-
const markedText = this.codeMirror.markText(
|
|
108
|
-
{ line, ch: chStart },
|
|
109
|
-
{ line, ch: chEnd },
|
|
110
|
-
{ className: 'colored' }
|
|
111
|
-
);
|
|
112
|
-
this.setState({ markedText });
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
handleChange = (doc, change) => {
|
|
116
|
-
if (change.origin === 'setValue') {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const { name, onChange } = this.props;
|
|
121
|
-
let value = doc.getValue();
|
|
122
|
-
|
|
123
|
-
if (value === '') {
|
|
124
|
-
value = null;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Update the parent
|
|
128
|
-
onChange({
|
|
129
|
-
target: {
|
|
130
|
-
name,
|
|
131
|
-
value,
|
|
132
|
-
type: 'json',
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// Remove higlight error
|
|
137
|
-
if (this.state.markedText) {
|
|
138
|
-
this.state.markedText.clear();
|
|
139
|
-
this.setState({ markedText: null, error: null });
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
clearTimeout(this.timer);
|
|
143
|
-
this.timer = setTimeout(() => this.testJSON(doc.getValue()), WAIT);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
testJSON = (value) => {
|
|
147
|
-
try {
|
|
148
|
-
jsonlint.parse(value);
|
|
149
|
-
} catch (err) {
|
|
150
|
-
this.markSelection(err);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
render() {
|
|
155
|
-
if (this.state.error) {
|
|
156
|
-
return <div>error json</div>;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return (
|
|
160
|
-
<FieldWrapper
|
|
161
|
-
name={this.props.name}
|
|
162
|
-
hint={this.props.description}
|
|
163
|
-
error={this.props.error}
|
|
164
|
-
required={this.props.required}
|
|
165
|
-
>
|
|
166
|
-
<Stack spacing={1}>
|
|
167
|
-
<Label
|
|
168
|
-
intlLabel={this.props.intlLabel}
|
|
169
|
-
name={this.props.name}
|
|
170
|
-
labelAction={this.props.labelAction}
|
|
171
|
-
/>
|
|
172
|
-
<StyledBox error={this.props.error}>
|
|
173
|
-
<EditorWrapper disabled={this.props.disabled}>
|
|
174
|
-
<textarea
|
|
175
|
-
ref={this.editor}
|
|
176
|
-
autoComplete="off"
|
|
177
|
-
id={this.props.id || this.props.name}
|
|
178
|
-
defaultValue=""
|
|
179
|
-
/>
|
|
180
|
-
</EditorWrapper>
|
|
181
|
-
</StyledBox>
|
|
182
|
-
<FieldHint />
|
|
183
|
-
<FieldError />
|
|
184
|
-
</Stack>
|
|
185
|
-
</FieldWrapper>
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
InputJSON.defaultProps = {
|
|
191
|
-
description: null,
|
|
192
|
-
disabled: false,
|
|
193
|
-
id: undefined,
|
|
194
|
-
error: undefined,
|
|
195
|
-
intlLabel: undefined,
|
|
196
|
-
labelAction: undefined,
|
|
197
|
-
onChange() {},
|
|
198
|
-
value: null,
|
|
199
|
-
required: false,
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
InputJSON.propTypes = {
|
|
203
|
-
description: PropTypes.shape({
|
|
204
|
-
id: PropTypes.string.isRequired,
|
|
205
|
-
defaultMessage: PropTypes.string.isRequired,
|
|
206
|
-
values: PropTypes.object,
|
|
207
|
-
}),
|
|
208
|
-
disabled: PropTypes.bool,
|
|
209
|
-
error: PropTypes.string,
|
|
210
|
-
id: PropTypes.string,
|
|
211
|
-
intlLabel: PropTypes.shape({
|
|
212
|
-
id: PropTypes.string.isRequired,
|
|
213
|
-
defaultMessage: PropTypes.string.isRequired,
|
|
214
|
-
values: PropTypes.object,
|
|
215
|
-
}),
|
|
216
|
-
labelAction: PropTypes.element,
|
|
217
|
-
name: PropTypes.string.isRequired,
|
|
218
|
-
onChange: PropTypes.func,
|
|
219
|
-
value: PropTypes.any,
|
|
220
|
-
required: PropTypes.bool,
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
export default InputJSON;
|