@strapi/admin 4.12.6 → 4.13.0-alpha.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.
Files changed (211) hide show
  1. package/admin/src/StrapiApp.js +1 -1
  2. package/admin/src/components/AuthenticatedApp/index.js +118 -0
  3. package/admin/src/components/AuthenticatedApp/utils/api.js +85 -0
  4. package/admin/src/components/AuthenticatedApp/utils/checkLatestStrapiVersion.js +11 -0
  5. package/admin/src/components/GuidedTour/Modal/index.js +3 -1
  6. package/admin/src/components/NpsSurvey/hooks/useNpsSurveySettings.js +17 -0
  7. package/admin/src/components/NpsSurvey/index.js +365 -0
  8. package/admin/src/components/PluginsInitializer/index.js +68 -0
  9. package/admin/src/components/PluginsInitializer/init.js +11 -0
  10. package/admin/src/components/PluginsInitializer/reducer.js +22 -0
  11. package/admin/src/content-manager/components/DynamicTable/CellContent/ReviewWorkflowsStage/getTableColumns.js +2 -0
  12. package/admin/src/content-manager/components/DynamicZone/components/DynamicZoneLabel.js +1 -1
  13. package/admin/src/content-manager/components/EditViewDataManagerProvider/reducer.js +8 -1
  14. package/admin/src/content-manager/components/Filter/CustomInputs/AdminUsersFilter.js +42 -0
  15. package/admin/src/content-manager/components/Filter/Filter.js +54 -0
  16. package/admin/src/content-manager/components/Filter/index.js +1 -0
  17. package/admin/src/content-manager/components/InputUID/index.js +222 -216
  18. package/admin/src/content-manager/components/RelationInput/RelationInput.js +4 -0
  19. package/admin/src/content-manager/components/RepeatableComponent/index.js +32 -2
  20. package/admin/src/content-manager/components/Wysiwyg/Editor.js +432 -68
  21. package/admin/src/content-manager/components/Wysiwyg/WysiwygStyles.js +0 -7
  22. package/admin/src/content-manager/components/Wysiwyg/index.js +147 -152
  23. package/admin/src/content-manager/hooks/useAllowedAttributes.js +47 -0
  24. package/admin/src/content-manager/pages/App/index.js +16 -5
  25. package/admin/src/content-manager/pages/EditView/Information/index.js +9 -8
  26. package/admin/src/content-manager/pages/ListSettingsView/components/Settings.js +40 -7
  27. package/admin/src/content-manager/pages/ListSettingsView/index.js +6 -2
  28. package/admin/src/content-manager/pages/ListView/components/BulkActionButtons/SelectedEntriesModal/index.js +2 -2
  29. package/admin/src/content-manager/pages/ListView/components/FieldPicker/index.js +67 -69
  30. package/admin/src/content-manager/pages/ListView/components/TableRows/index.js +1 -1
  31. package/admin/src/content-manager/pages/ListView/components/ViewSettingsMenu/index.js +80 -0
  32. package/admin/src/content-manager/pages/ListView/index.js +236 -67
  33. package/admin/src/content-manager/utils/getDisplayName.js +33 -0
  34. package/admin/src/content-manager/utils/index.js +1 -0
  35. package/admin/src/hooks/useSettingsForm/index.js +3 -14
  36. package/admin/src/hooks/useSettingsMenu/index.js +2 -2
  37. package/admin/src/hooks/useSettingsMenu/utils/formatLinks.js +3 -1
  38. package/admin/src/hooks/useSettingsMenu/utils/sortLinks.js +3 -1
  39. package/admin/src/index.js +1 -1
  40. package/admin/src/layouts/AppLayout/index.js +33 -0
  41. package/admin/src/pages/Admin/Onboarding/index.js +3 -1
  42. package/admin/src/pages/Admin/index.js +73 -77
  43. package/admin/src/pages/App/constants.js +1 -1
  44. package/admin/src/pages/App/index.js +122 -160
  45. package/admin/src/pages/AuthPage/components/Register/index.js +5 -0
  46. package/admin/src/pages/AuthPage/index.js +4 -2
  47. package/admin/src/pages/HomePage/index.js +3 -1
  48. package/admin/src/pages/InstalledPluginsPage/index.js +3 -1
  49. package/admin/src/pages/{InternalErrorPage.js → InternalErrorPage/index.js} +4 -3
  50. package/admin/src/pages/{NotFoundPage.js → NotFoundPage/index.js} +3 -1
  51. package/admin/src/pages/ProfilePage/index.js +4 -2
  52. package/admin/src/pages/SettingsPage/constants.js +132 -67
  53. package/admin/src/pages/SettingsPage/index.js +18 -23
  54. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/index.js +1 -1
  55. package/admin/src/pages/SettingsPage/pages/TransferTokens/EditView/index.js +1 -1
  56. package/admin/src/pages/SettingsPage/pages/Users/EditPage/index.js +1 -2
  57. package/admin/src/pages/SettingsPage/pages/Users/ListPage/DynamicTable/TableRows/index.js +1 -1
  58. package/admin/src/pages/UseCasePage/index.js +175 -0
  59. package/admin/src/plugins.js +7 -8
  60. package/admin/src/translations/en.json +10 -1
  61. package/admin/src/utils/checkFormValidity.js +15 -0
  62. package/admin/src/utils/createRoute.js +7 -5
  63. package/admin/src/utils/formatAPIErrors.js +3 -1
  64. package/admin/src/utils/getAttributesToDisplay.js +19 -0
  65. package/admin/src/utils/getExistingActions.js +32 -0
  66. package/admin/src/utils/getFullName.js +1 -1
  67. package/admin/src/utils/index.js +9 -0
  68. package/admin/src/utils/makeUniqueRoutes.js +6 -0
  69. package/admin/src/utils/sortLinks.js +3 -1
  70. package/admin/src/utils/uniqueAdminHash.js +9 -2
  71. package/build/{1049.9d69d231.chunk.js → 1049.ec69f5e0.chunk.js} +1 -1
  72. package/build/1227.9f37e1dc.chunk.js +1 -0
  73. package/build/1386.ea73b677.chunk.js +7 -0
  74. package/build/{2225.33287e1b.chunk.js → 2225.649fb7bc.chunk.js} +2 -2
  75. package/build/{2237.03792b63.chunk.js → 2237.b832ae6e.chunk.js} +4 -4
  76. package/build/{2379.401f56f3.chunk.js → 2379.1f98a31a.chunk.js} +1 -1
  77. package/build/{2395.e6a79fbb.chunk.js → 2395.0e5e8ded.chunk.js} +1 -1
  78. package/build/{2801.31393ffe.chunk.js → 2801.8e1aa82a.chunk.js} +1 -1
  79. package/build/3483.19381b40.chunk.js +1 -0
  80. package/build/3739.63e352f1.chunk.js +103 -0
  81. package/build/4174.f1f39e40.chunk.js +1 -0
  82. package/build/448.829e1344.chunk.js +1 -0
  83. package/build/4546.a5946d22.chunk.js +1 -0
  84. package/build/4724.aea5c8c1.chunk.js +6 -0
  85. package/build/{502.8dd074ff.chunk.js → 502.7bba43b1.chunk.js} +1 -1
  86. package/build/6158.c3c13c20.chunk.js +1 -0
  87. package/build/6691.4985ef22.chunk.js +105 -0
  88. package/build/{7464.592a9295.chunk.js → 7464.eb057bec.chunk.js} +1 -1
  89. package/build/78.dcc6df5c.chunk.js +1 -0
  90. package/build/{8276.e519a707.chunk.js → 8276.be3ed581.chunk.js} +2 -2
  91. package/build/{2747.d1442a90.chunk.js → 9806.5d5a0e8d.chunk.js} +64 -72
  92. package/build/9944.7af075a5.chunk.js +26 -0
  93. package/build/Admin-authenticatedApp.43b6ec9a.chunk.js +79 -0
  94. package/build/Admin_InternalErrorPage.38155af3.chunk.js +1 -0
  95. package/build/Admin_homePage.6f128523.chunk.js +81 -0
  96. package/build/Admin_marketplace.061a6e5a.chunk.js +55 -0
  97. package/build/Admin_pluginsPage.16f837b8.chunk.js +6 -0
  98. package/build/Admin_profilePage.678bce24.chunk.js +13 -0
  99. package/build/Admin_settingsPage.af7309e4.chunk.js +111 -0
  100. package/build/{Upload_ConfigureTheView.345ac1e0.chunk.js → Upload_ConfigureTheView.3fc1c100.chunk.js} +1 -1
  101. package/build/admin-app.d63bd229.chunk.js +36 -0
  102. package/build/{admin-edit-roles-page.24bdf746.chunk.js → admin-edit-roles-page.38a6c863.chunk.js} +3 -3
  103. package/build/admin-edit-users.545fc882.chunk.js +10 -0
  104. package/build/{admin-roles-list.23ddff26.chunk.js → admin-roles-list.1e2e814d.chunk.js} +1 -1
  105. package/build/admin-users.b8ea5677.chunk.js +11 -0
  106. package/build/{api-tokens-create-page.46c2ea84.chunk.js → api-tokens-create-page.e0c15627.chunk.js} +1 -1
  107. package/build/{api-tokens-edit-page.58139df9.chunk.js → api-tokens-edit-page.9f2dce47.chunk.js} +1 -1
  108. package/build/{api-tokens-list-page.0af7d431.chunk.js → api-tokens-list-page.d747051c.chunk.js} +2 -2
  109. package/build/{audit-logs-settings-page.0f73ccf8.chunk.js → audit-logs-settings-page.96f9d608.chunk.js} +1 -1
  110. package/build/content-manager.ccff1078.chunk.js +1097 -0
  111. package/build/{content-type-builder-list-view.bf9be456.chunk.js → content-type-builder-list-view.b71cf240.chunk.js} +1 -1
  112. package/build/{content-type-builder.66066281.chunk.js → content-type-builder.e5669749.chunk.js} +18 -18
  113. package/build/{email-settings-page.2f7e35c0.chunk.js → email-settings-page.2809f0bf.chunk.js} +1 -1
  114. package/build/en-json.e12fd5fc.chunk.js +1 -0
  115. package/build/{i18n-settings-page.47f78016.chunk.js → i18n-settings-page.5f716172.chunk.js} +1 -1
  116. package/build/index.html +1 -1
  117. package/build/main.c6c9e04c.js +2859 -0
  118. package/build/{review-workflows-settings-create-view.d24a32b9.chunk.js → review-workflows-settings-create-view.4a156a19.chunk.js} +1 -1
  119. package/build/{review-workflows-settings-edit-view.6044b022.chunk.js → review-workflows-settings-edit-view.ce984d1f.chunk.js} +1 -1
  120. package/build/{review-workflows-settings-list-view.3f0ef4bc.chunk.js → review-workflows-settings-list-view.419b8deb.chunk.js} +2 -2
  121. package/build/runtime~main.dcf1cb45.js +2 -0
  122. package/build/{sso-settings-page.4dba0670.chunk.js → sso-settings-page.45153df5.chunk.js} +1 -1
  123. package/build/{transfer-tokens-create-page.1597e6ab.chunk.js → transfer-tokens-create-page.ebba16d8.chunk.js} +1 -1
  124. package/build/{transfer-tokens-edit-page.8741529f.chunk.js → transfer-tokens-edit-page.d7bb2b3e.chunk.js} +1 -1
  125. package/build/{transfer-tokens-list-page.d6986b03.chunk.js → transfer-tokens-list-page.cfe1736c.chunk.js} +2 -2
  126. package/build/{upload-settings.7f93d4c0.chunk.js → upload-settings.cc5ad813.chunk.js} +1 -1
  127. package/build/{upload.37488080.chunk.js → upload.756efc28.chunk.js} +1 -1
  128. package/build/{users-advanced-settings-page.17052d72.chunk.js → users-advanced-settings-page.818d84eb.chunk.js} +1 -1
  129. package/build/{users-email-settings-page.3de8ea50.chunk.js → users-email-settings-page.c1967c09.chunk.js} +1 -1
  130. package/build/{users-providers-settings-page.0eaa916d.chunk.js → users-providers-settings-page.11893e08.chunk.js} +1 -1
  131. package/build/{users-roles-settings-page.957ad48b.chunk.js → users-roles-settings-page.2b051e6a.chunk.js} +1 -1
  132. package/build/webhook-edit-page.de45c635.chunk.js +33 -0
  133. package/build/{webhook-list-page.65e1b5bb.chunk.js → webhook-list-page.ca91df8b.chunk.js} +1 -1
  134. package/ee/admin/content-manager/components/Filter/CustomInputs/ReviewWorkflows/AssigneeFilter.js +42 -0
  135. package/ee/admin/content-manager/components/Filter/CustomInputs/ReviewWorkflows/StageFilter.js +70 -0
  136. package/ee/admin/content-manager/components/Filter/CustomInputs/ReviewWorkflows/constants.js +71 -0
  137. package/ee/admin/content-manager/pages/EditView/InformationBox/InformationBoxEE.js +9 -217
  138. package/ee/admin/content-manager/pages/EditView/InformationBox/components/AssigneeSelect/AssigneeSelect.js +147 -0
  139. package/ee/admin/content-manager/pages/EditView/InformationBox/components/AssigneeSelect/index.js +1 -0
  140. package/ee/admin/content-manager/pages/EditView/InformationBox/components/StageSelect/StageSelect.js +243 -0
  141. package/ee/admin/content-manager/pages/EditView/InformationBox/components/StageSelect/index.js +1 -0
  142. package/ee/admin/content-manager/pages/EditView/InformationBox/constants.js +2 -0
  143. package/ee/admin/content-manager/pages/ListSettingsView/constants.js +7 -0
  144. package/ee/admin/content-manager/pages/ListView/ReviewWorkflowsColumn/ReviewWorkflowsAssigneeEE.js +21 -0
  145. package/ee/admin/content-manager/pages/ListView/ReviewWorkflowsColumn/constants.js +44 -17
  146. package/ee/admin/content-manager/pages/ListView/ReviewWorkflowsColumn/index.js +1 -0
  147. package/ee/admin/pages/App/constants.js +5 -6
  148. package/ee/admin/pages/SettingsPage/constants.js +42 -27
  149. package/ee/server/constants/workflows.js +1 -0
  150. package/ee/server/controllers/index.js +1 -0
  151. package/ee/server/controllers/workflows/assignees/index.js +44 -0
  152. package/ee/server/routes/review-workflows.js +17 -0
  153. package/ee/server/services/index.js +1 -0
  154. package/ee/server/services/review-workflows/assignees.js +54 -0
  155. package/ee/server/services/review-workflows/metrics/index.js +5 -0
  156. package/ee/server/services/review-workflows/review-workflows.js +20 -11
  157. package/ee/server/validation/review-workflows.js +8 -0
  158. package/index.js +2 -6
  159. package/package.json +9 -9
  160. package/scripts/build.js +15 -15
  161. package/scripts/create-dev-plugins-file.js +5 -38
  162. package/server/controllers/role.js +2 -0
  163. package/server/controllers/user.js +2 -0
  164. package/server/services/permission/permissions-manager/index.js +3 -1
  165. package/server/services/permission/permissions-manager/sanitize.js +19 -7
  166. package/server/services/permission/permissions-manager/validate.js +218 -0
  167. package/utils/create-cache-dir.js +62 -16
  168. package/utils/create-plugins-exclude-path.js +3 -23
  169. package/utils/get-plugins.js +110 -0
  170. package/utils/index.js +1 -1
  171. package/webpack.config.js +10 -13
  172. package/admin/src/components/AuthenticatedApp.js +0 -229
  173. package/admin/src/content-manager/components/AttributeFilter/Filters.js +0 -58
  174. package/admin/src/content-manager/components/AttributeFilter/hooks/useAllowedAttributes.js +0 -42
  175. package/admin/src/content-manager/components/AttributeFilter/index.js +0 -40
  176. package/admin/src/content-manager/components/Wysiwyg/EditorStylesContainer.js +0 -344
  177. package/admin/src/pages/UseCasePage.js +0 -174
  178. package/build/2166.c837469a.chunk.js +0 -1
  179. package/build/3483.8517171f.chunk.js +0 -1
  180. package/build/3984.dda474f7.chunk.js +0 -1
  181. package/build/4546.7a3c0d03.chunk.js +0 -1
  182. package/build/5483.5bfbb00d.chunk.js +0 -6
  183. package/build/6158.c974fd83.chunk.js +0 -1
  184. package/build/748.fd2e5afd.chunk.js +0 -105
  185. package/build/773.6381d62d.chunk.js +0 -18
  186. package/build/7826.399afe81.chunk.js +0 -103
  187. package/build/8261.2525d35c.chunk.js +0 -7
  188. package/build/8299.62b67c72.chunk.js +0 -1
  189. package/build/Admin-AuthPage.90d64342.chunk.js +0 -35
  190. package/build/Admin-AuthenticatedApp.379ac945.chunk.js +0 -24
  191. package/build/Admin-UseCasePage.1f757db5.chunk.js +0 -13
  192. package/build/Admin_GuidedTourModal.8ccf1fbc.chunk.js +0 -12
  193. package/build/Admin_InternalErrorPage.9de92c6d.chunk.js +0 -9
  194. package/build/Admin_NotFoundPage.21620424.chunk.js +0 -9
  195. package/build/Admin_Onboarding.dbfa32f6.chunk.js +0 -43
  196. package/build/Admin_homePage.2000cbe9.chunk.js +0 -86
  197. package/build/Admin_marketplace.ec80e29b.chunk.js +0 -63
  198. package/build/Admin_pluginsPage.0c6851f8.chunk.js +0 -14
  199. package/build/Admin_profilePage.78cd8495.chunk.js +0 -21
  200. package/build/Admin_settingsPage.1760c3ce.chunk.js +0 -119
  201. package/build/StrapiApp.221fac30.chunk.js +0 -5
  202. package/build/admin-edit-users.5d10d444.chunk.js +0 -10
  203. package/build/admin-users.2b3e4305.chunk.js +0 -11
  204. package/build/content-manager.fb0833bd.chunk.js +0 -1099
  205. package/build/en-json.08c05fcf.chunk.js +0 -1
  206. package/build/main.ee3c1938.js +0 -2859
  207. package/build/runtime~main.397ee447.js +0 -2
  208. package/build/webhook-edit-page.665210af.chunk.js +0 -33
  209. package/scripts/create-plugins-file.js +0 -92
  210. package/utils/get-plugins-path.js +0 -41
  211. /package/server/services/permission/permissions-manager/{query-builers.js → query-builders.js} +0 -0
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable import/no-cycle */
2
- import React, { memo, useMemo, useState } from 'react';
2
+ import React, { memo, useEffect, useMemo, useState } from 'react';
3
3
 
4
4
  import { Box, Flex, TextButton, VisuallyHidden } from '@strapi/design-system';
5
- import { useCMEditViewDataManager, useNotification } from '@strapi/helper-plugin';
5
+ import { useCMEditViewDataManager, useNotification, useQuery } from '@strapi/helper-plugin';
6
6
  import { Plus } from '@strapi/icons';
7
7
  import get from 'lodash/get';
8
8
  import PropTypes from 'prop-types';
@@ -50,6 +50,36 @@ const RepeatableComponent = ({
50
50
  [componentUid, getComponentLayout]
51
51
  );
52
52
 
53
+ const search = useQuery();
54
+
55
+ /**
56
+ * Get the temp key of the component that has the field that is currently focussed
57
+ * as defined by the `field` query param. We can then force this specific component
58
+ * to be in it's "open" state.
59
+ */
60
+ const componentTmpKeyWithFocussedField = useMemo(() => {
61
+ if (search.has('field')) {
62
+ const field = search.get('field');
63
+
64
+ const [, path] = field.split(`${name}.`);
65
+
66
+ if (get(componentValue, path, undefined) !== undefined) {
67
+ const subpaths = path.split('.');
68
+
69
+ return get(componentValue, subpaths[0], undefined)?.__temp_key__;
70
+ }
71
+ }
72
+
73
+ // eslint-disable-next-line consistent-return
74
+ return undefined;
75
+ }, [componentValue, search, name]);
76
+
77
+ useEffect(() => {
78
+ if (typeof componentTmpKeyWithFocussedField === 'number') {
79
+ setCollapseToOpen(componentTmpKeyWithFocussedField);
80
+ }
81
+ }, [componentTmpKeyWithFocussedField]);
82
+
53
83
  const nextTempKey = useMemo(() => getMaxTempKey(componentValue || []) + 1, [componentValue]);
54
84
 
55
85
  const componentErrorKeys = getComponentErrorKeys(name, formErrors);
@@ -1,83 +1,101 @@
1
- import React, { useEffect, useRef } from 'react';
1
+ import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
2
2
 
3
3
  import CodeMirror from 'codemirror5';
4
4
  import PropTypes from 'prop-types';
5
+ import styled from 'styled-components';
5
6
 
6
7
  import PreviewWysiwyg from '../PreviewWysiwyg';
7
8
 
8
- import { EditorStylesContainer } from './EditorStylesContainer';
9
9
  import newlineAndIndentContinueMarkdownList from './utils/continueList';
10
- import { EditorAndPreviewWrapper } from './WysiwygStyles';
11
10
 
12
11
  import 'codemirror5/addon/display/placeholder';
13
12
 
14
- const Editor = ({
15
- disabled,
16
- editorRef,
17
- error,
18
- isPreviewMode,
19
- isExpandMode,
20
- name,
21
- onChange,
22
- placeholder,
23
- textareaRef,
24
- value,
25
- }) => {
26
- const onChangeRef = useRef(onChange);
27
-
28
- useEffect(() => {
29
- editorRef.current = CodeMirror.fromTextArea(textareaRef.current, {
30
- lineWrapping: true,
31
- extraKeys: {
32
- Enter: 'newlineAndIndentContinueMarkdownList',
33
- Tab: false,
34
- 'Shift-Tab': false,
35
- },
36
- readOnly: false,
37
- smartIndent: false,
13
+ const Editor = forwardRef(
14
+ (
15
+ {
16
+ disabled,
17
+ editorRef,
18
+ error,
19
+ isPreviewMode,
20
+ isExpandMode,
21
+ name,
22
+ onChange,
38
23
  placeholder,
39
- spellcheck: true,
40
- inputStyle: 'contenteditable',
41
- });
42
-
43
- CodeMirror.commands.newlineAndIndentContinueMarkdownList = newlineAndIndentContinueMarkdownList;
44
- editorRef.current.on('change', (doc) => {
45
- onChangeRef.current({ target: { name, value: doc.getValue(), type: 'wysiwyg' } });
46
- });
47
- }, [editorRef, textareaRef, name, placeholder]);
48
-
49
- useEffect(() => {
50
- if (value && !editorRef.current.hasFocus()) {
51
- editorRef.current.setValue(value);
52
- }
53
- }, [editorRef, value]);
24
+ textareaRef,
25
+ value,
26
+ },
27
+ forwardedRef
28
+ ) => {
29
+ const onChangeRef = useRef(onChange);
54
30
 
55
- useEffect(() => {
56
- if (isPreviewMode || disabled) {
57
- editorRef.current.setOption('readOnly', 'nocursor');
58
- } else {
59
- editorRef.current.setOption('readOnly', false);
60
- }
61
- }, [disabled, isPreviewMode, editorRef]);
62
-
63
- useEffect(() => {
64
- if (error) {
65
- editorRef.current.setOption('screenReaderLabel', error);
66
- } else {
67
- // to replace with translation
68
- editorRef.current.setOption('screenReaderLabel', 'Editor');
69
- }
70
- }, [editorRef, error]);
71
-
72
- return (
73
- <EditorAndPreviewWrapper>
74
- <EditorStylesContainer isExpandMode={isExpandMode} disabled={disabled || isPreviewMode}>
75
- <textarea ref={textareaRef} />
76
- </EditorStylesContainer>
77
- {isPreviewMode && <PreviewWysiwyg data={value} />}
78
- </EditorAndPreviewWrapper>
79
- );
80
- };
31
+ useEffect(() => {
32
+ editorRef.current = CodeMirror.fromTextArea(textareaRef.current, {
33
+ lineWrapping: true,
34
+ extraKeys: {
35
+ Enter: 'newlineAndIndentContinueMarkdownList',
36
+ Tab: false,
37
+ 'Shift-Tab': false,
38
+ },
39
+ readOnly: false,
40
+ smartIndent: false,
41
+ placeholder,
42
+ spellcheck: true,
43
+ inputStyle: 'contenteditable',
44
+ });
45
+
46
+ CodeMirror.commands.newlineAndIndentContinueMarkdownList =
47
+ newlineAndIndentContinueMarkdownList;
48
+ editorRef.current.on('change', (doc) => {
49
+ onChangeRef.current({ target: { name, value: doc.getValue(), type: 'wysiwyg' } });
50
+ });
51
+ }, [editorRef, textareaRef, name, placeholder]);
52
+
53
+ useEffect(() => {
54
+ if (value && !editorRef.current.hasFocus()) {
55
+ editorRef.current.setValue(value);
56
+ }
57
+ }, [editorRef, value]);
58
+
59
+ useEffect(() => {
60
+ if (isPreviewMode || disabled) {
61
+ editorRef.current.setOption('readOnly', 'nocursor');
62
+ } else {
63
+ editorRef.current.setOption('readOnly', false);
64
+ }
65
+ }, [disabled, isPreviewMode, editorRef]);
66
+
67
+ useEffect(() => {
68
+ if (error) {
69
+ editorRef.current.setOption('screenReaderLabel', error);
70
+ } else {
71
+ // to replace with translation
72
+ editorRef.current.setOption('screenReaderLabel', 'Editor');
73
+ }
74
+ }, [editorRef, error]);
75
+
76
+ useImperativeHandle(
77
+ forwardedRef,
78
+ () => ({
79
+ focus() {
80
+ editorRef.current.getInputField().focus();
81
+ },
82
+ scrollIntoView(args) {
83
+ editorRef.current.getInputField().scrollIntoView(args);
84
+ },
85
+ }),
86
+ [editorRef]
87
+ );
88
+
89
+ return (
90
+ <EditorAndPreviewWrapper>
91
+ <EditorStylesContainer isExpandMode={isExpandMode} disabled={disabled || isPreviewMode}>
92
+ <textarea ref={textareaRef} />
93
+ </EditorStylesContainer>
94
+ {isPreviewMode && <PreviewWysiwyg data={value} />}
95
+ </EditorAndPreviewWrapper>
96
+ );
97
+ }
98
+ );
81
99
 
82
100
  Editor.defaultProps = {
83
101
  disabled: false,
@@ -101,4 +119,350 @@ Editor.propTypes = {
101
119
  value: PropTypes.string,
102
120
  };
103
121
 
122
+ const EditorAndPreviewWrapper = styled.div`
123
+ position: relative;
124
+ height: calc(100% - 48px);
125
+ `;
126
+
127
+ const EditorStylesContainer = styled.div`
128
+ cursor: ${({ disabled }) => (disabled ? 'not-allowed !important' : 'auto')};
129
+ height: 100%;
130
+ /* BASICS */
131
+ .CodeMirror-placeholder {
132
+ color: ${({ theme }) => theme.colors.neutral600} !important;
133
+ }
134
+
135
+ .CodeMirror {
136
+ /* Set height, width, borders, and global font properties here */
137
+ font-size: ${14 / 16}rem;
138
+ height: ${({ isExpandMode }) => (isExpandMode ? '100%' : '290px')};
139
+ color: ${({ theme }) => theme.colors.neutral800};
140
+ direction: ltr;
141
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
142
+ 'Open Sans', 'Helvetica Neue', sans-serif;
143
+ }
144
+
145
+ /* PADDING */
146
+
147
+ .CodeMirror-lines {
148
+ padding: ${({ theme }) => `${theme.spaces[3]} ${theme.spaces[4]}`};
149
+ /* Vertical padding around content */
150
+ }
151
+
152
+ .CodeMirror-scrollbar-filler,
153
+ .CodeMirror-gutter-filler {
154
+ /* The little square between H and V scrollbars */
155
+ background-color: ${({ theme }) => `${theme.colors.neutral0}`};
156
+ }
157
+
158
+ /* GUTTER */
159
+
160
+ .CodeMirror-gutters {
161
+ border-right: 1px solid #ddd;
162
+ background-color: #f7f7f7;
163
+ white-space: nowrap;
164
+ }
165
+ .CodeMirror-linenumbers {
166
+ }
167
+ .CodeMirror-linenumber {
168
+ padding: 0 3px 0 5px;
169
+ min-width: 20px;
170
+ text-align: right;
171
+ color: #999;
172
+ white-space: nowrap;
173
+ }
174
+
175
+ .CodeMirror-guttermarker {
176
+ color: black;
177
+ }
178
+ .CodeMirror-guttermarker-subtle {
179
+ color: #999;
180
+ }
181
+
182
+ /* CURSOR */
183
+
184
+ .CodeMirror-cursor {
185
+ border-left: 1px solid black;
186
+ border-right: none;
187
+ width: 0;
188
+ }
189
+ /* Shown when moving in bi-directional text */
190
+ .CodeMirror div.CodeMirror-secondarycursor {
191
+ border-left: 1px solid silver;
192
+ }
193
+ .cm-fat-cursor .CodeMirror-cursor {
194
+ width: auto;
195
+ border: 0 !important;
196
+ background: #7e7;
197
+ }
198
+ .cm-fat-cursor div.CodeMirror-cursors {
199
+ /* z-index: 1; */
200
+ }
201
+
202
+ .cm-fat-cursor-mark {
203
+ background-color: rgba(20, 255, 20, 0.5);
204
+ -webkit-animation: blink 1.06s steps(1) infinite;
205
+ -moz-animation: blink 1.06s steps(1) infinite;
206
+ animation: blink 1.06s steps(1) infinite;
207
+ }
208
+ .cm-animate-fat-cursor {
209
+ width: auto;
210
+ border: 0;
211
+ -webkit-animation: blink 1.06s steps(1) infinite;
212
+ -moz-animation: blink 1.06s steps(1) infinite;
213
+ animation: blink 1.06s steps(1) infinite;
214
+ background-color: #7e7;
215
+ }
216
+
217
+ /* Can style cursor different in overwrite (non-insert) mode */
218
+ .CodeMirror-overwrite .CodeMirror-cursor {
219
+ }
220
+
221
+ .cm-tab {
222
+ display: inline-block;
223
+ text-decoration: inherit;
224
+ }
225
+
226
+ .CodeMirror-rulers {
227
+ position: absolute;
228
+ left: 0;
229
+ right: 0;
230
+ top: -50px;
231
+ bottom: 0;
232
+ overflow: hidden;
233
+ }
234
+ .CodeMirror-ruler {
235
+ border-left: 1px solid #ccc;
236
+ top: 0;
237
+ bottom: 0;
238
+ position: absolute;
239
+ }
240
+
241
+ /* DEFAULT THEME */
242
+
243
+ .cm-header,
244
+ .cm-strong {
245
+ font-weight: bold;
246
+ }
247
+ .cm-em {
248
+ font-style: italic;
249
+ }
250
+ .cm-link {
251
+ text-decoration: underline;
252
+ }
253
+ .cm-strikethrough {
254
+ text-decoration: line-through;
255
+ }
256
+
257
+ .CodeMirror-composing {
258
+ border-bottom: 2px solid;
259
+ }
260
+
261
+ /* Default styles for common addons */
262
+
263
+ div.CodeMirror span.CodeMirror-matchingbracket {
264
+ color: #0b0;
265
+ }
266
+ div.CodeMirror span.CodeMirror-nonmatchingbracket {
267
+ color: #a22;
268
+ }
269
+ .CodeMirror-matchingtag {
270
+ background: rgba(255, 150, 0, 0.3);
271
+ }
272
+ .CodeMirror-activeline-background {
273
+ background: #e8f2ff;
274
+ }
275
+
276
+ /* STOP */
277
+
278
+ /* The rest of this file contains styles related to the mechanics of
279
+ the editor. You probably shouldn't touch them. */
280
+
281
+ .CodeMirror {
282
+ position: relative;
283
+ overflow: hidden;
284
+ background: ${({ theme }) => `${theme.colors.neutral0}`};
285
+ }
286
+
287
+ .CodeMirror-scroll {
288
+ overflow: scroll !important; /* Things will break if this is overridden */
289
+ /* 50px is the magic margin used to hide the element's real scrollbars */
290
+ /* See overflow: hidden in .CodeMirror */
291
+ margin-bottom: -50px;
292
+ margin-right: -50px;
293
+ padding-bottom: 50px;
294
+ height: 100%;
295
+ outline: none; /* Prevent dragging from highlighting the element */
296
+ position: relative;
297
+ }
298
+ .CodeMirror-sizer {
299
+ position: relative;
300
+ border-right: 50px solid transparent;
301
+ }
302
+
303
+ /* The fake, visible scrollbars. Used to force redraw during scrolling
304
+ before actual scrolling happens, thus preventing shaking and
305
+ flickering artifacts. */
306
+ .CodeMirror-vscrollbar,
307
+ .CodeMirror-hscrollbar,
308
+ .CodeMirror-scrollbar-filler,
309
+ .CodeMirror-gutter-filler {
310
+ position: absolute;
311
+ z-index: 1;
312
+ display: none;
313
+ outline: none;
314
+ }
315
+
316
+ .CodeMirror-vscrollbar {
317
+ right: 0;
318
+ top: 0;
319
+ overflow-x: hidden;
320
+ overflow-y: scroll;
321
+ }
322
+ .CodeMirror-hscrollbar {
323
+ bottom: 0;
324
+ left: 0;
325
+ overflow-y: hidden;
326
+ overflow-x: scroll;
327
+ }
328
+ .CodeMirror-scrollbar-filler {
329
+ right: 0;
330
+ bottom: 0;
331
+ }
332
+
333
+ .CodeMirror-lines {
334
+ cursor: text;
335
+ min-height: 1px; /* prevents collapsing before first draw */
336
+ }
337
+ /* Reset some styles that the rest of the page might have set */
338
+ .CodeMirror pre.CodeMirror-line,
339
+ .CodeMirror pre.CodeMirror-line-like {
340
+ -moz-border-radius: 0;
341
+ -webkit-border-radius: 0;
342
+ border-radius: 0;
343
+ border-width: 0;
344
+ background: transparent;
345
+ font-family: inherit;
346
+ font-size: inherit;
347
+ margin: 0;
348
+ white-space: pre;
349
+ word-wrap: normal;
350
+ line-height: 1.5;
351
+ color: inherit;
352
+ /* z-index: 2; */
353
+ position: relative;
354
+ overflow: visible;
355
+ -webkit-tap-highlight-color: transparent;
356
+ -webkit-font-variant-ligatures: contextual;
357
+ font-variant-ligatures: contextual;
358
+ }
359
+
360
+ .CodeMirror pre.CodeMirror-line-like {
361
+ z-index: 2;
362
+ }
363
+
364
+ .CodeMirror-wrap pre.CodeMirror-line,
365
+ .CodeMirror-wrap pre.CodeMirror-line-like {
366
+ word-wrap: break-word;
367
+ white-space: pre-wrap;
368
+ word-break: normal;
369
+ }
370
+
371
+ .CodeMirror-linebackground {
372
+ position: absolute;
373
+ left: 0;
374
+ right: 0;
375
+ top: 0;
376
+ bottom: 0;
377
+ z-index: 0;
378
+ }
379
+
380
+ .CodeMirror-linewidget {
381
+ position: relative;
382
+ /* z-index: 2; */
383
+ padding: 0.1px; /* Force widget margins to stay inside of the container */
384
+ }
385
+
386
+ .CodeMirror-widget {
387
+ }
388
+
389
+ .CodeMirror-rtl pre {
390
+ direction: rtl;
391
+ }
392
+
393
+ .CodeMirror-code {
394
+ outline: none;
395
+ }
396
+
397
+ /* Force content-box sizing for the elements where we expect it */
398
+ .CodeMirror-scroll,
399
+ .CodeMirror-sizer,
400
+ .CodeMirror-gutter,
401
+ .CodeMirror-gutters,
402
+ .CodeMirror-linenumber {
403
+ -moz-box-sizing: content-box;
404
+ box-sizing: content-box;
405
+ }
406
+
407
+ .CodeMirror-measure {
408
+ position: absolute;
409
+ width: 100%;
410
+ height: 0;
411
+ overflow: hidden;
412
+ visibility: hidden;
413
+ }
414
+
415
+ .CodeMirror-cursor {
416
+ position: absolute;
417
+ pointer-events: none;
418
+ border-color: ${({ theme }) => `${theme.colors.neutral800}`};
419
+ }
420
+ .CodeMirror-measure pre {
421
+ position: static;
422
+ }
423
+
424
+ div.CodeMirror-cursors {
425
+ visibility: hidden;
426
+ position: relative;
427
+ + div {
428
+ z-index: 0 !important;
429
+ }
430
+ }
431
+
432
+ div.CodeMirror-dragcursors {
433
+ visibility: visible;
434
+ }
435
+
436
+ .CodeMirror-focused div.CodeMirror-cursors {
437
+ visibility: visible;
438
+ }
439
+
440
+ .CodeMirror-selected {
441
+ background: ${({ theme }) => theme.colors.neutral200};
442
+ /* z-index: -10; */
443
+ }
444
+ .CodeMirror-crosshair {
445
+ cursor: crosshair;
446
+ }
447
+
448
+ /* Used to force a border model for a node */
449
+ .cm-force-border {
450
+ padding-right: 0.1px;
451
+ }
452
+
453
+ /* See issue #2901 */
454
+ .cm-tab-wrap-hack:after {
455
+ content: '';
456
+ }
457
+
458
+ /* Help users use markselection to safely style text background */
459
+ span.CodeMirror-selectedtext {
460
+ background: none;
461
+ }
462
+
463
+ span {
464
+ color: ${({ theme }) => theme.colors.neutral800} !important;
465
+ }
466
+ `;
467
+
104
468
  export default Editor;
@@ -40,13 +40,6 @@ export const IconButtonGroupMargin = styled(IconButtonGroup)`
40
40
  margin-right: ${({ theme }) => `${theme.spaces[2]}`};
41
41
  `;
42
42
 
43
- // EDITOR && PREVIEW
44
-
45
- export const EditorAndPreviewWrapper = styled.div`
46
- position: relative;
47
- height: calc(100% - 48px);
48
- `;
49
-
50
43
  // FOOTER
51
44
  export const ExpandButton = styled(BaseButton)`
52
45
  background-color: transparent;