@strapi/admin 4.14.2 → 4.14.4

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.
Files changed (173) hide show
  1. package/.eslintrc.js +4 -1
  2. package/admin/.eslintrc.js +16 -0
  3. package/admin/custom.d.ts +8 -0
  4. package/admin/src/components/AuthenticatedApp/index.js +3 -7
  5. package/admin/src/components/AuthenticatedApp/utils/api.js +1 -39
  6. package/admin/src/components/AuthenticatedApp/utils/checkLatestStrapiVersion.ts +13 -0
  7. package/admin/src/{hooks/useReleaseNotification/utils/api.js → components/AuthenticatedApp/utils/fetchStrapiLatestRelease.ts} +2 -3
  8. package/admin/src/components/{DragLayer/DragLayer.js → DragLayer.tsx} +18 -10
  9. package/admin/src/components/PrivateRoute.tsx +42 -0
  10. package/admin/src/components/Providers/index.js +2 -2
  11. package/admin/src/components/Theme.tsx +39 -0
  12. package/admin/src/components/ThemeToggleProvider.tsx +50 -0
  13. package/admin/src/components/{UnauthenticatedLogo/index.js → UnauthenticatedLogo.tsx} +2 -4
  14. package/admin/src/content-manager/components/BlocksEditor/BlocksInput/index.js +22 -3
  15. package/admin/src/content-manager/components/BlocksEditor/Toolbar/index.js +263 -134
  16. package/admin/src/content-manager/components/BlocksEditor/hooks/useBlocksStore.js +362 -95
  17. package/admin/src/content-manager/components/BlocksEditor/hooks/useModifiersStore.js +15 -0
  18. package/admin/src/content-manager/components/BlocksEditor/index.js +99 -9
  19. package/admin/src/content-manager/components/BlocksEditor/plugins/index.js +4 -0
  20. package/admin/src/content-manager/components/BlocksEditor/plugins/withLinks.js +61 -0
  21. package/admin/src/content-manager/components/BlocksEditor/plugins/withStrapiSchema.js +33 -0
  22. package/admin/src/content-manager/components/BlocksEditor/utils/links.js +90 -0
  23. package/admin/src/content-manager/components/InputUID/index.js +1 -1
  24. package/admin/src/content-manager/hooks/useAllowedAttributes.js +9 -1
  25. package/admin/src/content-manager/hooks/useRelation/useRelation.js +1 -0
  26. package/admin/src/content-manager/pages/EditSettingsView/index.js +1 -0
  27. package/admin/src/content-manager/pages/EditSettingsView/utils/createPossibleMainFieldsForModelsAndComponents.js +1 -0
  28. package/admin/src/content-manager/pages/ListSettingsView/constants.js +1 -0
  29. package/admin/src/content-manager/pages/ListView/index.js +2 -1
  30. package/admin/src/content-manager/utils/checkIfAttributeIsDisplayable.js +1 -1
  31. package/admin/src/content-manager/utils/schema.js +2 -2
  32. package/admin/src/contexts/configuration.ts +15 -0
  33. package/admin/src/contexts/index.js +1 -2
  34. package/admin/src/contexts/themeToggle.ts +16 -0
  35. package/admin/src/hooks/{useConfigurations/__mocks__/index.js → __mocks__/useConfigurations.ts} +4 -2
  36. package/admin/src/hooks/index.js +1 -5
  37. package/admin/src/hooks/useConfigurations.ts +5 -0
  38. package/admin/src/hooks/useDebounce.ts +17 -0
  39. package/admin/src/hooks/useLicenseLimitNotification.ts +3 -0
  40. package/admin/src/hooks/useThemeToggle.ts +9 -0
  41. package/admin/src/pages/App/index.js +1 -1
  42. package/admin/src/pages/AuthPage/components/ForgotPassword/index.js +1 -1
  43. package/admin/src/pages/AuthPage/components/ForgotPasswordSuccess/index.js +1 -1
  44. package/admin/src/pages/AuthPage/components/Login/BaseLogin.js +1 -1
  45. package/admin/src/pages/AuthPage/components/Oops/index.js +1 -1
  46. package/admin/src/pages/AuthPage/components/Register/index.js +1 -1
  47. package/admin/src/pages/AuthPage/components/ResetPassword/index.js +1 -1
  48. package/admin/src/pages/MarketplacePage/components/NpmPackageCard/index.js +0 -2
  49. package/admin/src/pages/MarketplacePage/hooks/__mocks__/useNavigatorOnline.ts +1 -0
  50. package/admin/src/{hooks/useNavigatorOnLine/index.js → pages/MarketplacePage/hooks/useNavigatorOnline.ts} +4 -6
  51. package/admin/src/pages/MarketplacePage/index.js +3 -3
  52. package/admin/src/pages/ProfilePage/index.js +1 -1
  53. package/admin/src/pages/SettingsPage/components/Tokens/Regenerate/index.js +1 -1
  54. package/admin/src/{hooks/useRegenerate/index.js → pages/SettingsPage/hooks/useRegenerate.ts} +13 -7
  55. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/Regenerate/index.js +1 -1
  56. package/admin/src/pages/UseCasePage/index.js +1 -1
  57. package/admin/src/translations/en.json +8 -0
  58. package/admin/tsconfig.json +5 -0
  59. package/build/1049.f7aed23d.chunk.js +1 -0
  60. package/build/{1227.969e24e6.chunk.js → 1227.f9c74718.chunk.js} +1 -1
  61. package/build/{1386.db9a2795.chunk.js → 1386.6b8819c6.chunk.js} +2 -2
  62. package/build/2224.8af54440.chunk.js +138 -0
  63. package/build/2225.d1bcf7e3.chunk.js +79 -0
  64. package/build/2379.f0baf826.chunk.js +1 -0
  65. package/build/{2395.f6ac2863.chunk.js → 2395.aca6ce66.chunk.js} +1 -1
  66. package/build/2421.a478ba24.chunk.js +105 -0
  67. package/build/2801.c49f88a1.chunk.js +1 -0
  68. package/build/{3483.f6b2439f.chunk.js → 3483.5df8e010.chunk.js} +1 -1
  69. package/build/3911.d4fada48.chunk.js +95 -0
  70. package/build/412.72afdf0c.chunk.js +689 -0
  71. package/build/{4174.3e13fb26.chunk.js → 4174.df9aa09a.chunk.js} +1 -1
  72. package/build/502.8666bbef.chunk.js +25 -0
  73. package/build/570.2f3b4c56.chunk.js +1 -0
  74. package/build/5702.5b433d50.chunk.js +1 -0
  75. package/build/6186.c33ce082.chunk.js +116 -0
  76. package/build/7464.43a4527c.chunk.js +1 -0
  77. package/build/7818.d2196a53.chunk.js +29 -0
  78. package/build/7897.5c03247b.chunk.js +25 -0
  79. package/build/{8276.951e198e.chunk.js → 8276.d4426fd8.chunk.js} +3 -3
  80. package/build/8690.33243bba.chunk.js +38 -0
  81. package/build/{9832.65ed5a44.chunk.js → 8743.31c921b1.chunk.js} +139 -123
  82. package/build/9218.8bc01ab9.chunk.js +1 -0
  83. package/build/Admin-authenticatedApp.27545a1b.chunk.js +112 -0
  84. package/build/{Admin_InternalErrorPage.b3163562.chunk.js → Admin_InternalErrorPage.b66ee9c1.chunk.js} +1 -1
  85. package/build/Admin_homePage.a6281dd6.chunk.js +124 -0
  86. package/build/Admin_marketplace.31b962b8.chunk.js +44 -0
  87. package/build/{Admin_pluginsPage.b9fa2947.chunk.js → Admin_pluginsPage.9217101d.chunk.js} +1 -1
  88. package/build/{Admin_profilePage.a4d41380.chunk.js → Admin_profilePage.680123d9.chunk.js} +2 -2
  89. package/build/{Admin_settingsPage.6dc2af9f.chunk.js → Admin_settingsPage.33378310.chunk.js} +1 -1
  90. package/build/{Upload_ConfigureTheView.cc7ca628.chunk.js → Upload_ConfigureTheView.b40eea4d.chunk.js} +1 -1
  91. package/build/admin-app.e8c52c37.chunk.js +36 -0
  92. package/build/admin-edit-roles-page.fcf056bf.chunk.js +275 -0
  93. package/build/{admin-edit-users.9b42cc9e.chunk.js → admin-edit-users.89efe3c4.chunk.js} +2 -2
  94. package/build/{admin-roles-list.cf964578.chunk.js → admin-roles-list.8b77704a.chunk.js} +3 -3
  95. package/build/admin-users.e3f1be14.chunk.js +19 -0
  96. package/build/{api-tokens-create-page.2f25ddf6.chunk.js → api-tokens-create-page.0dd63e91.chunk.js} +1 -1
  97. package/build/{api-tokens-edit-page.45faac16.chunk.js → api-tokens-edit-page.78d877f8.chunk.js} +1 -1
  98. package/build/{api-tokens-list-page.5baabf1a.chunk.js → api-tokens-list-page.ae13346c.chunk.js} +2 -2
  99. package/build/audit-logs-settings-page.e9c92a75.chunk.js +9 -0
  100. package/build/content-manager.5849dbe3.chunk.js +1226 -0
  101. package/build/{content-type-builder-list-view.aa8a5d1a.chunk.js → content-type-builder-list-view.3fffae65.chunk.js} +1 -1
  102. package/build/{content-type-builder-translation-en-json.b9e5cacd.chunk.js → content-type-builder-translation-en-json.43f9d7bc.chunk.js} +1 -1
  103. package/build/{content-type-builder.885f2cad.chunk.js → content-type-builder.98c71164.chunk.js} +14 -14
  104. package/build/{email-settings-page.6bd7b280.chunk.js → email-settings-page.ecfec9b3.chunk.js} +1 -1
  105. package/build/{en-json.a3973ff5.chunk.js → en-json.bd611a8e.chunk.js} +1 -1
  106. package/build/{i18n-settings-page.6c0157e7.chunk.js → i18n-settings-page.a9708926.chunk.js} +1 -1
  107. package/build/index.html +1 -1
  108. package/build/main.3abb6f34.js +3278 -0
  109. package/build/{review-workflows-settings-create-view.ae369a88.chunk.js → review-workflows-settings-create-view.b7b0c6c5.chunk.js} +1 -1
  110. package/build/{review-workflows-settings-edit-view.9a61c69f.chunk.js → review-workflows-settings-edit-view.c331b3fe.chunk.js} +1 -1
  111. package/build/review-workflows-settings-list-view.70218dc1.chunk.js +75 -0
  112. package/build/{runtime~main.cec66cd9.js → runtime~main.450561b1.js} +1 -1
  113. package/build/{sso-settings-page.a29e6c38.chunk.js → sso-settings-page.1a9e7f8f.chunk.js} +1 -1
  114. package/build/{transfer-tokens-create-page.6e1b8cee.chunk.js → transfer-tokens-create-page.e7f541d3.chunk.js} +1 -1
  115. package/build/{transfer-tokens-edit-page.10bb22e2.chunk.js → transfer-tokens-edit-page.bd1276c2.chunk.js} +1 -1
  116. package/build/{transfer-tokens-list-page.0306652c.chunk.js → transfer-tokens-list-page.5de6bb9f.chunk.js} +2 -2
  117. package/build/upload-settings.97ef4c92.chunk.js +14 -0
  118. package/build/{upload.19e14c8e.chunk.js → upload.f08715a1.chunk.js} +1 -1
  119. package/build/{users-advanced-settings-page.ed69812f.chunk.js → users-advanced-settings-page.36a3c363.chunk.js} +1 -1
  120. package/build/users-email-settings-page.47b47962.chunk.js +149 -0
  121. package/build/users-providers-settings-page.1e0c8376.chunk.js +154 -0
  122. package/build/{users-roles-settings-page.afab5a0d.chunk.js → users-roles-settings-page.d5a8e8a1.chunk.js} +4 -4
  123. package/build/{webhook-edit-page.4c037da4.chunk.js → webhook-edit-page.87456194.chunk.js} +3 -3
  124. package/build/{webhook-list-page.56c82f4a.chunk.js → webhook-list-page.c88a382b.chunk.js} +3 -3
  125. package/ee/admin/hooks/{useLicenseLimitNotification.js → useLicenseLimitNotification.ts} +4 -4
  126. package/ee/admin/pages/AuthPage/components/Providers/index.js +1 -1
  127. package/ee/admin/pages/SettingsPage/pages/Users/ListPage/index.js +1 -3
  128. package/package.json +13 -12
  129. package/scripts/build.js +6 -2
  130. package/webpack.config.js +1 -0
  131. package/admin/src/components/AuthenticatedApp/utils/checkLatestStrapiVersion.js +0 -11
  132. package/admin/src/components/DragLayer/index.js +0 -1
  133. package/admin/src/components/GlobalStyle/index.js +0 -9
  134. package/admin/src/components/PrivateRoute/index.js +0 -46
  135. package/admin/src/components/Theme/index.js +0 -26
  136. package/admin/src/components/ThemeToggleProvider/index.js +0 -79
  137. package/admin/src/contexts/Configurations/index.js +0 -5
  138. package/admin/src/contexts/ThemeToggle/index.js +0 -5
  139. package/admin/src/hooks/useConfigurations/index.js +0 -11
  140. package/admin/src/hooks/useDebounce/index.js +0 -19
  141. package/admin/src/hooks/useLicenseLimitNotification/index.js +0 -5
  142. package/admin/src/hooks/useReleaseNotification/index.js +0 -31
  143. package/admin/src/hooks/useReleaseNotification/utils/checkLatestStrapiVersion.js +0 -11
  144. package/admin/src/hooks/useThemeToggle/index.js +0 -11
  145. package/admin/src/tsconfig.json +0 -10
  146. package/build/1049.acb0e730.chunk.js +0 -1
  147. package/build/2225.78fb9b89.chunk.js +0 -79
  148. package/build/2379.906334f0.chunk.js +0 -1
  149. package/build/2614.3e088d3e.chunk.js +0 -35
  150. package/build/2659.cb94f1e7.chunk.js +0 -105
  151. package/build/2801.2afb4757.chunk.js +0 -1
  152. package/build/2950.216f2e89.chunk.js +0 -1
  153. package/build/3021.33ad47fb.chunk.js +0 -103
  154. package/build/3911.488fbde3.chunk.js +0 -95
  155. package/build/4546.1203ac95.chunk.js +0 -1
  156. package/build/502.9918bff7.chunk.js +0 -1
  157. package/build/5158.c85f841a.chunk.js +0 -1
  158. package/build/6266.e8990811.chunk.js +0 -146
  159. package/build/7464.0280cf59.chunk.js +0 -1
  160. package/build/7897.4a39de37.chunk.js +0 -6
  161. package/build/Admin-authenticatedApp.08f32723.chunk.js +0 -112
  162. package/build/Admin_homePage.6cb51f18.chunk.js +0 -81
  163. package/build/Admin_marketplace.3eb5e132.chunk.js +0 -55
  164. package/build/admin-app.98cdf43a.chunk.js +0 -36
  165. package/build/admin-edit-roles-page.418bb1c5.chunk.js +0 -267
  166. package/build/admin-users.8385dd73.chunk.js +0 -11
  167. package/build/audit-logs-settings-page.91489670.chunk.js +0 -1
  168. package/build/content-manager.0d2b4a60.chunk.js +0 -1199
  169. package/build/main.105dcf23.js +0 -2665
  170. package/build/review-workflows-settings-list-view.067e0c35.chunk.js +0 -56
  171. package/build/upload-settings.0af6edc5.chunk.js +0 -14
  172. package/build/users-email-settings-page.131a00fb.chunk.js +0 -9
  173. package/build/users-providers-settings-page.b3dca41d.chunk.js +0 -14
package/.eslintrc.js CHANGED
@@ -2,8 +2,11 @@ module.exports = {
2
2
  root: true,
3
3
  overrides: [
4
4
  {
5
- files: ['admin/**/*', 'ee/admin/**/*'],
5
+ files: ['ee/admin/**/*'],
6
6
  extends: ['custom/front'],
7
+ rules: {
8
+ 'import/extensions': 'off',
9
+ },
7
10
  },
8
11
  {
9
12
  files: ['**/*'],
@@ -0,0 +1,16 @@
1
+ module.exports = {
2
+ root: true,
3
+ overrides: [
4
+ {
5
+ files: ['**/*.js', '**/*.jsx'],
6
+ extends: ['custom/front'],
7
+ rules: {
8
+ 'import/extensions': 'off',
9
+ },
10
+ },
11
+ {
12
+ files: ['**/*.ts', '**/*.tsx'],
13
+ extends: ['custom/front/typescript'],
14
+ },
15
+ ],
16
+ };
@@ -0,0 +1,8 @@
1
+ export {};
2
+
3
+ import { StrapiTheme } from '@strapi/design-system';
4
+
5
+ declare module 'styled-components' {
6
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
7
+ export interface DefaultTheme extends StrapiTheme {}
8
+ }
@@ -18,13 +18,9 @@ import NpsSurvey from '../NpsSurvey';
18
18
  import PluginsInitializer from '../PluginsInitializer';
19
19
  import RBACProvider from '../RBACProvider';
20
20
 
21
- import {
22
- fetchAppInfo,
23
- fetchCurrentUserPermissions,
24
- fetchStrapiLatestRelease,
25
- fetchUserRoles,
26
- } from './utils/api';
27
- import checkLatestStrapiVersion from './utils/checkLatestStrapiVersion';
21
+ import { fetchAppInfo, fetchCurrentUserPermissions, fetchUserRoles } from './utils/api';
22
+ import { checkLatestStrapiVersion } from './utils/checkLatestStrapiVersion';
23
+ import { fetchStrapiLatestRelease } from './utils/fetchStrapiLatestRelease';
28
24
 
29
25
  const strapiVersion = packageJSON.version;
30
26
 
@@ -1,45 +1,7 @@
1
1
  import { getFetchClient } from '@strapi/helper-plugin';
2
2
 
3
- import packageJSON from '../../../../../package.json';
4
-
5
- import checkLatestStrapiVersion from './checkLatestStrapiVersion';
6
-
7
- const strapiVersion = packageJSON.version;
8
- const showUpdateNotif = !JSON.parse(localStorage.getItem('STRAPI_UPDATE_NOTIF'));
9
3
  const { get } = getFetchClient();
10
4
 
11
- const fetchStrapiLatestRelease = async (toggleNotification) => {
12
- try {
13
- const res = await fetch('https://api.github.com/repos/strapi/strapi/releases/latest');
14
-
15
- if (!res.ok) {
16
- throw new Error('Failed to fetch latest Strapi version.');
17
- }
18
- const { tag_name } = await res.json();
19
- const shouldUpdateStrapi = checkLatestStrapiVersion(strapiVersion, tag_name);
20
-
21
- if (shouldUpdateStrapi && showUpdateNotif) {
22
- toggleNotification({
23
- type: 'info',
24
- message: { id: 'notification.version.update.message' },
25
- link: {
26
- url: `https://github.com/strapi/strapi/releases/tag/${tag_name}`,
27
- label: {
28
- id: 'global.see-more',
29
- },
30
- },
31
- blockTransition: true,
32
- onClose: () => localStorage.setItem('STRAPI_UPDATE_NOTIF', true),
33
- });
34
- }
35
-
36
- return tag_name;
37
- } catch (err) {
38
- // Don't throw an error
39
- return strapiVersion;
40
- }
41
- };
42
-
43
5
  const fetchAppInfo = async () => {
44
6
  try {
45
7
  const { data, headers } = await get('/admin/information');
@@ -82,4 +44,4 @@ const fetchUserRoles = async () => {
82
44
  }
83
45
  };
84
46
 
85
- export { fetchAppInfo, fetchCurrentUserPermissions, fetchStrapiLatestRelease, fetchUserRoles };
47
+ export { fetchAppInfo, fetchCurrentUserPermissions, fetchUserRoles };
@@ -0,0 +1,13 @@
1
+ import lt from 'semver/functions/lt';
2
+ import valid from 'semver/functions/valid';
3
+
4
+ export const checkLatestStrapiVersion = (
5
+ currentPackageVersion: string,
6
+ latestPublishedVersion: string
7
+ ): boolean => {
8
+ if (!valid(currentPackageVersion) || !valid(latestPublishedVersion)) {
9
+ return false;
10
+ }
11
+
12
+ return lt(currentPackageVersion, latestPublishedVersion);
13
+ };
@@ -1,7 +1,8 @@
1
1
  import packageJSON from '../../../../../package.json';
2
2
 
3
3
  const strapiVersion = packageJSON.version;
4
- const fetchStrapiLatestRelease = async () => {
4
+
5
+ export const fetchStrapiLatestRelease = async () => {
5
6
  try {
6
7
  const res = await fetch('https://api.github.com/repos/strapi/strapi/releases/latest');
7
8
 
@@ -16,5 +17,3 @@ const fetchStrapiLatestRelease = async () => {
16
17
  return strapiVersion;
17
18
  }
18
19
  };
19
-
20
- export default fetchStrapiLatestRelease;
@@ -1,11 +1,14 @@
1
1
  import * as React from 'react';
2
2
 
3
3
  import { Box } from '@strapi/design-system';
4
- import PropTypes from 'prop-types';
5
- import { useDragLayer } from 'react-dnd';
6
-
7
- function getStyle(initialOffset, currentOffset, mouseOffset) {
8
- if (!initialOffset || !currentOffset) {
4
+ import { DragLayerMonitor, XYCoord, useDragLayer } from 'react-dnd';
5
+
6
+ function getStyle(
7
+ initialOffset: XYCoord | null,
8
+ currentOffset: XYCoord | null,
9
+ mouseOffset: XYCoord | null
10
+ ) {
11
+ if (!initialOffset || !currentOffset || !mouseOffset) {
9
12
  return { display: 'none' };
10
13
  }
11
14
 
@@ -16,7 +19,14 @@ function getStyle(initialOffset, currentOffset, mouseOffset) {
16
19
  };
17
20
  }
18
21
 
19
- export function DragLayer({ renderItem }) {
22
+ export interface DragLayerProps {
23
+ renderItem: (item: {
24
+ item: unknown;
25
+ type: ReturnType<DragLayerMonitor['getItemType']>;
26
+ }) => React.ReactNode;
27
+ }
28
+
29
+ const DragLayer = ({ renderItem }: DragLayerProps) => {
20
30
  const { itemType, isDragging, item, initialOffset, currentOffset, mouseOffset } = useDragLayer(
21
31
  (monitor) => ({
22
32
  item: monitor.getItem(),
@@ -47,8 +57,6 @@ export function DragLayer({ renderItem }) {
47
57
  </Box>
48
58
  </Box>
49
59
  );
50
- }
51
-
52
- DragLayer.propTypes = {
53
- renderItem: PropTypes.func.isRequired,
54
60
  };
61
+
62
+ export { DragLayer };
@@ -0,0 +1,42 @@
1
+ import * as React from 'react';
2
+
3
+ import { auth } from '@strapi/helper-plugin';
4
+ import { Redirect, Route, useLocation } from 'react-router-dom';
5
+
6
+ type PropsOf<T> = T extends React.ComponentType<infer P> ? P : object;
7
+
8
+ type PrivateRouteProps<TComponent extends React.ElementType> = {
9
+ component: TComponent;
10
+ path: string;
11
+ } & PropsOf<TComponent>;
12
+
13
+ const PrivateRoute = <TComponent extends React.ElementType>({
14
+ component: Component,
15
+ path,
16
+ ...rest
17
+ }: PrivateRouteProps<TComponent>) => {
18
+ const { pathname, search } = useLocation();
19
+
20
+ return (
21
+ <Route
22
+ path={path}
23
+ render={(props) =>
24
+ auth.getToken() !== null ? (
25
+ <Component {...rest} {...props} />
26
+ ) : (
27
+ <Redirect
28
+ to={{
29
+ pathname: '/auth/login',
30
+ search:
31
+ pathname !== '/'
32
+ ? `?redirectTo=${encodeURIComponent(`${pathname}${search}`)}`
33
+ : undefined,
34
+ }}
35
+ />
36
+ )
37
+ }
38
+ />
39
+ );
40
+ };
41
+
42
+ export { PrivateRoute };
@@ -16,8 +16,8 @@ import { AdminContext } from '../../contexts';
16
16
  import ConfigurationsProvider from '../ConfigurationsProvider';
17
17
  import GuidedTour from '../GuidedTour';
18
18
  import LanguageProvider from '../LanguageProvider';
19
- import Theme from '../Theme';
20
- import ThemeToggleProvider from '../ThemeToggleProvider';
19
+ import { Theme } from '../Theme';
20
+ import { ThemeToggleProvider } from '../ThemeToggleProvider';
21
21
 
22
22
  const queryClient = new QueryClient({
23
23
  defaultOptions: {
@@ -0,0 +1,39 @@
1
+ import * as React from 'react';
2
+
3
+ import { DesignSystemProvider } from '@strapi/design-system';
4
+ import { useIntl } from 'react-intl';
5
+ import { createGlobalStyle } from 'styled-components';
6
+
7
+ import { useThemeToggle } from '../hooks/useThemeToggle';
8
+
9
+ interface ThemeProps {
10
+ children: React.ReactNode;
11
+ }
12
+
13
+ const Theme = ({ children }: ThemeProps) => {
14
+ const { currentTheme, themes } = useThemeToggle();
15
+ const { locale } = useIntl();
16
+
17
+ return (
18
+ <DesignSystemProvider
19
+ locale={locale}
20
+ /**
21
+ * TODO: could we make this neater i.e. by setting up the context to throw
22
+ * if it can't find it, that way the type is always fully defined and we're
23
+ * not checking it all the time...
24
+ */
25
+ theme={currentTheme && themes ? themes[currentTheme] : themes?.light}
26
+ >
27
+ {children}
28
+ <GlobalStyle />
29
+ </DesignSystemProvider>
30
+ );
31
+ };
32
+
33
+ const GlobalStyle = createGlobalStyle`
34
+ body {
35
+ background: ${({ theme }) => theme.colors.neutral100};
36
+ }
37
+ `;
38
+
39
+ export { Theme };
@@ -0,0 +1,50 @@
1
+ import * as React from 'react';
2
+
3
+ import { DefaultTheme } from 'styled-components';
4
+
5
+ import { ThemeToggleContext, ThemeName } from '../contexts/themeToggle';
6
+
7
+ const THEME_KEY = 'STRAPI_THEME';
8
+
9
+ const getDefaultTheme = () => {
10
+ const browserTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
11
+ const persistedTheme = localStorage.getItem(THEME_KEY) as ThemeName | null;
12
+
13
+ if (!persistedTheme) {
14
+ localStorage.setItem(THEME_KEY, browserTheme);
15
+ }
16
+
17
+ return persistedTheme || browserTheme;
18
+ };
19
+
20
+ interface ThemeToggleProviderProps {
21
+ children: React.ReactNode;
22
+ themes: {
23
+ light: DefaultTheme;
24
+ dark: DefaultTheme;
25
+ };
26
+ }
27
+
28
+ const ThemeToggleProvider = ({ children, themes }: ThemeToggleProviderProps) => {
29
+ const [currentTheme, setCurrentTheme] = React.useState(getDefaultTheme());
30
+
31
+ const handleChangeTheme = React.useCallback(
32
+ (nextTheme: ThemeName) => {
33
+ setCurrentTheme(nextTheme);
34
+ localStorage.setItem(THEME_KEY, nextTheme);
35
+ },
36
+ [setCurrentTheme]
37
+ );
38
+
39
+ const themeValues = React.useMemo(() => {
40
+ return {
41
+ currentTheme,
42
+ onChangeTheme: handleChangeTheme,
43
+ themes,
44
+ };
45
+ }, [currentTheme, handleChangeTheme, themes]);
46
+
47
+ return <ThemeToggleContext.Provider value={themeValues}>{children}</ThemeToggleContext.Provider>;
48
+ };
49
+
50
+ export { ThemeToggleProvider };
@@ -1,8 +1,6 @@
1
- import React from 'react';
2
-
3
1
  import styled from 'styled-components';
4
2
 
5
- import { useConfigurations } from '../../hooks';
3
+ import { useConfigurations } from '../hooks/useConfigurations';
6
4
 
7
5
  const Img = styled.img`
8
6
  height: ${72 / 16}rem;
@@ -16,4 +14,4 @@ const Logo = () => {
16
14
  return <Img src={auth?.custom ?? auth.default} aria-hidden alt="" />;
17
15
  };
18
16
 
19
- export default Logo;
17
+ export { Logo };
@@ -13,6 +13,7 @@ const getEditorStyle = (theme) => ({
13
13
  display: 'flex',
14
14
  flexDirection: 'column',
15
15
  gap: theme.spaces[2],
16
+ height: '100%',
16
17
  });
17
18
 
18
19
  const baseRenderLeaf = (props, modifiers) => {
@@ -37,7 +38,7 @@ const baseRenderElement = (props, blocks) => {
37
38
  return block.renderElement(props);
38
39
  };
39
40
 
40
- const BlocksInput = ({ readOnly }) => {
41
+ const BlocksInput = ({ disabled, placeholder }) => {
41
42
  const theme = useTheme();
42
43
  const editor = useSlate();
43
44
 
@@ -62,16 +63,29 @@ const BlocksInput = ({ readOnly }) => {
62
63
  }
63
64
  };
64
65
 
66
+ const handleBackspaceEvent = (event) => {
67
+ const selectedNode = editor.children[editor.selection.anchor.path[0]];
68
+ const selectedBlock = Object.values(blocks).find((block) => block.matchNode(selectedNode));
69
+
70
+ if (selectedBlock.handleBackspaceKey) {
71
+ selectedBlock.handleBackspaceKey(editor, event);
72
+ }
73
+ };
74
+
65
75
  const handleKeyDown = (event) => {
66
76
  if (event.key === 'Enter') {
67
77
  event.preventDefault();
68
78
  handleEnter();
69
79
  }
80
+ if (event.key === 'Backspace') {
81
+ handleBackspaceEvent(event);
82
+ }
70
83
  };
71
84
 
72
85
  return (
73
86
  <Editable
74
- readOnly={readOnly}
87
+ readOnly={disabled}
88
+ placeholder={placeholder}
75
89
  style={getEditorStyle(theme)}
76
90
  renderElement={renderElement}
77
91
  renderLeaf={renderLeaf}
@@ -80,8 +94,13 @@ const BlocksInput = ({ readOnly }) => {
80
94
  );
81
95
  };
82
96
 
97
+ BlocksInput.defaultProps = {
98
+ placeholder: null,
99
+ };
100
+
83
101
  BlocksInput.propTypes = {
84
- readOnly: PropTypes.bool.isRequired,
102
+ disabled: PropTypes.bool.isRequired,
103
+ placeholder: PropTypes.string,
85
104
  };
86
105
 
87
106
  export default BlocksInput;