@atlaskit/editor-core 150.0.3 → 151.0.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 (195) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/cjs/actions/index.js +5 -23
  3. package/dist/cjs/create-editor/ErrorBoundary.js +113 -79
  4. package/dist/cjs/create-editor/ReactEditorView.js +145 -31
  5. package/dist/cjs/create-editor/create-plugins-list.js +4 -2
  6. package/dist/cjs/editor.js +101 -40
  7. package/dist/cjs/labs/next/presets/cxhtml.js +2 -1
  8. package/dist/cjs/plugins/analytics/types/enums.js +3 -1
  9. package/dist/cjs/plugins/base/index.js +4 -3
  10. package/dist/cjs/plugins/base/pm-plugins/frozen-editor.js +66 -36
  11. package/dist/cjs/plugins/block-type/ui/ToolbarBlockType/styled.js +3 -1
  12. package/dist/cjs/plugins/card/index.js +13 -2
  13. package/dist/cjs/plugins/card/nodeviews/embedCard.js +1 -0
  14. package/dist/cjs/plugins/card/pm-plugins/main.js +7 -2
  15. package/dist/cjs/plugins/card/pm-plugins/util/resolve.js +10 -3
  16. package/dist/cjs/plugins/code-block/toolbar.js +1 -1
  17. package/dist/cjs/plugins/emoji/styles.js +1 -1
  18. package/dist/cjs/plugins/extension/pm-plugins/main.js +1 -4
  19. package/dist/cjs/plugins/extension/toolbar.js +28 -23
  20. package/dist/cjs/plugins/feature-flags-context/feature-flags-from-props.js +8 -3
  21. package/dist/cjs/plugins/find-replace/ui/Find.js +27 -7
  22. package/dist/cjs/plugins/hyperlink/pm-plugins/keymap.js +3 -3
  23. package/dist/cjs/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.js +7 -4
  24. package/dist/cjs/plugins/hyperlink/utils.js +6 -69
  25. package/dist/cjs/plugins/media/index.js +14 -3
  26. package/dist/cjs/plugins/media/nodeviews/mediaGroup.js +24 -10
  27. package/dist/cjs/plugins/media/nodeviews/mediaInline.js +179 -0
  28. package/dist/cjs/plugins/media/pm-plugins/main.js +18 -9
  29. package/dist/cjs/plugins/media/toolbar/index.js +49 -17
  30. package/dist/cjs/plugins/media/toolbar/utils.js +20 -2
  31. package/dist/cjs/plugins/media/utils/media-files.js +67 -1
  32. package/dist/cjs/plugins/panel/index.js +2 -3
  33. package/dist/cjs/plugins/panel/message.js +47 -0
  34. package/dist/cjs/plugins/panel/toolbar.js +64 -84
  35. package/dist/cjs/plugins/panel/utils.js +2 -2
  36. package/dist/cjs/plugins/paste/linkify-md-plugin.js +3 -3
  37. package/dist/cjs/plugins/status/styles.js +1 -1
  38. package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +18 -2
  39. package/dist/cjs/profiler/render-count.js +82 -0
  40. package/dist/cjs/ui/Appearance/Comment/Comment.js +6 -5
  41. package/dist/cjs/utils/react-hooks/use-component-renderer-tracking/index.js +55 -19
  42. package/dist/cjs/version-wrapper.js +1 -1
  43. package/dist/cjs/version.json +1 -1
  44. package/dist/es2019/actions/index.js +6 -28
  45. package/dist/es2019/create-editor/ErrorBoundary.js +73 -60
  46. package/dist/es2019/create-editor/ReactEditorView.js +130 -23
  47. package/dist/es2019/create-editor/create-plugins-list.js +4 -2
  48. package/dist/es2019/editor.js +74 -35
  49. package/dist/es2019/labs/next/presets/cxhtml.js +2 -1
  50. package/dist/es2019/plugins/analytics/types/enums.js +3 -1
  51. package/dist/es2019/plugins/base/index.js +4 -3
  52. package/dist/es2019/plugins/base/pm-plugins/frozen-editor.js +63 -35
  53. package/dist/es2019/plugins/block-type/ui/ToolbarBlockType/styled.js +2 -1
  54. package/dist/es2019/plugins/card/index.js +7 -2
  55. package/dist/es2019/plugins/card/nodeviews/embedCard.js +1 -0
  56. package/dist/es2019/plugins/card/pm-plugins/main.js +9 -2
  57. package/dist/es2019/plugins/card/pm-plugins/util/resolve.js +12 -5
  58. package/dist/es2019/plugins/code-block/toolbar.js +1 -1
  59. package/dist/es2019/plugins/emoji/styles.js +2 -0
  60. package/dist/es2019/plugins/extension/pm-plugins/main.js +1 -4
  61. package/dist/es2019/plugins/extension/toolbar.js +30 -25
  62. package/dist/es2019/plugins/feature-flags-context/feature-flags-from-props.js +8 -4
  63. package/dist/es2019/plugins/find-replace/ui/Find.js +27 -6
  64. package/dist/es2019/plugins/hyperlink/pm-plugins/keymap.js +1 -1
  65. package/dist/es2019/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.js +7 -4
  66. package/dist/es2019/plugins/hyperlink/utils.js +3 -59
  67. package/dist/es2019/plugins/media/index.js +13 -4
  68. package/dist/es2019/plugins/media/nodeviews/mediaGroup.js +16 -7
  69. package/dist/es2019/plugins/media/nodeviews/mediaInline.js +88 -0
  70. package/dist/es2019/plugins/media/pm-plugins/main.js +20 -11
  71. package/dist/es2019/plugins/media/toolbar/index.js +44 -15
  72. package/dist/es2019/plugins/media/toolbar/utils.js +16 -0
  73. package/dist/es2019/plugins/media/utils/media-files.js +68 -2
  74. package/dist/es2019/plugins/panel/index.js +3 -4
  75. package/dist/es2019/plugins/panel/message.js +38 -0
  76. package/dist/es2019/plugins/panel/toolbar.js +52 -71
  77. package/dist/es2019/plugins/panel/utils.js +2 -2
  78. package/dist/es2019/plugins/paste/linkify-md-plugin.js +2 -2
  79. package/dist/es2019/plugins/status/styles.js +2 -0
  80. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +18 -2
  81. package/dist/es2019/profiler/render-count.js +60 -0
  82. package/dist/es2019/ui/Appearance/Comment/Comment.js +4 -2
  83. package/dist/es2019/utils/react-hooks/use-component-renderer-tracking/index.js +51 -18
  84. package/dist/es2019/version-wrapper.js +1 -1
  85. package/dist/es2019/version.json +1 -1
  86. package/dist/esm/actions/index.js +6 -24
  87. package/dist/esm/create-editor/ErrorBoundary.js +113 -78
  88. package/dist/esm/create-editor/ReactEditorView.js +146 -31
  89. package/dist/esm/create-editor/create-plugins-list.js +4 -2
  90. package/dist/esm/editor.js +100 -40
  91. package/dist/esm/labs/next/presets/cxhtml.js +2 -1
  92. package/dist/esm/plugins/analytics/types/enums.js +3 -1
  93. package/dist/esm/plugins/base/index.js +4 -3
  94. package/dist/esm/plugins/base/pm-plugins/frozen-editor.js +64 -36
  95. package/dist/esm/plugins/block-type/ui/ToolbarBlockType/styled.js +3 -1
  96. package/dist/esm/plugins/card/index.js +13 -2
  97. package/dist/esm/plugins/card/nodeviews/embedCard.js +1 -0
  98. package/dist/esm/plugins/card/pm-plugins/main.js +7 -2
  99. package/dist/esm/plugins/card/pm-plugins/util/resolve.js +12 -5
  100. package/dist/esm/plugins/code-block/toolbar.js +1 -1
  101. package/dist/esm/plugins/emoji/styles.js +1 -1
  102. package/dist/esm/plugins/extension/pm-plugins/main.js +1 -4
  103. package/dist/esm/plugins/extension/toolbar.js +28 -23
  104. package/dist/esm/plugins/feature-flags-context/feature-flags-from-props.js +8 -4
  105. package/dist/esm/plugins/find-replace/ui/Find.js +27 -7
  106. package/dist/esm/plugins/hyperlink/pm-plugins/keymap.js +1 -1
  107. package/dist/esm/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.js +7 -4
  108. package/dist/esm/plugins/hyperlink/utils.js +3 -59
  109. package/dist/esm/plugins/media/index.js +14 -4
  110. package/dist/esm/plugins/media/nodeviews/mediaGroup.js +24 -10
  111. package/dist/esm/plugins/media/nodeviews/mediaInline.js +147 -0
  112. package/dist/esm/plugins/media/pm-plugins/main.js +19 -11
  113. package/dist/esm/plugins/media/toolbar/index.js +47 -19
  114. package/dist/esm/plugins/media/toolbar/utils.js +15 -1
  115. package/dist/esm/plugins/media/utils/media-files.js +60 -2
  116. package/dist/esm/plugins/panel/index.js +3 -4
  117. package/dist/esm/plugins/panel/message.js +38 -0
  118. package/dist/esm/plugins/panel/toolbar.js +57 -77
  119. package/dist/esm/plugins/panel/utils.js +2 -2
  120. package/dist/esm/plugins/paste/linkify-md-plugin.js +2 -2
  121. package/dist/esm/plugins/status/styles.js +1 -1
  122. package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +18 -2
  123. package/dist/esm/profiler/render-count.js +57 -0
  124. package/dist/esm/ui/Appearance/Comment/Comment.js +6 -5
  125. package/dist/esm/utils/react-hooks/use-component-renderer-tracking/index.js +53 -20
  126. package/dist/esm/version-wrapper.js +1 -1
  127. package/dist/esm/version.json +1 -1
  128. package/dist/types/create-editor/ErrorBoundary.d.ts +6 -6
  129. package/dist/types/create-editor/ReactEditorView.d.ts +15 -3
  130. package/dist/types/editor.d.ts +2 -0
  131. package/dist/types/plugins/analytics/index.d.ts +1 -1
  132. package/dist/types/plugins/analytics/types/enums.d.ts +4 -2
  133. package/dist/types/plugins/analytics/types/events.d.ts +7 -2
  134. package/dist/types/plugins/analytics/types/general-events.d.ts +4 -1
  135. package/dist/types/plugins/analytics/types/index.d.ts +1 -1
  136. package/dist/types/plugins/analytics/types/insert-events.d.ts +6 -1
  137. package/dist/types/plugins/analytics/types/link-tool-bar-events.d.ts +1 -0
  138. package/dist/types/plugins/base/index.d.ts +1 -0
  139. package/dist/types/plugins/base/pm-plugins/frozen-editor.d.ts +3 -2
  140. package/dist/types/plugins/card/pm-plugins/main.d.ts +2 -3
  141. package/dist/types/plugins/card/pm-plugins/util/resolve.d.ts +2 -1
  142. package/dist/types/plugins/card/types.d.ts +6 -0
  143. package/dist/types/plugins/extension/types.d.ts +0 -2
  144. package/dist/types/plugins/feature-flags-context/get-enabled-feature-flag-keys.d.ts +1 -1
  145. package/dist/types/plugins/floating-toolbar/types.d.ts +1 -1
  146. package/dist/types/plugins/floating-toolbar/ui/Select.d.ts +1 -1
  147. package/dist/types/plugins/hyperlink/utils.d.ts +0 -21
  148. package/dist/types/plugins/media/nodeviews/mediaInline.d.ts +27 -0
  149. package/dist/types/plugins/media/pm-plugins/main.d.ts +2 -2
  150. package/dist/types/plugins/media/toolbar/utils.d.ts +2 -0
  151. package/dist/types/plugins/media/utils/media-files.d.ts +8 -0
  152. package/dist/types/plugins/panel/message.d.ts +37 -0
  153. package/dist/types/plugins/panel/toolbar.d.ts +4 -37
  154. package/dist/types/plugins/panel/types.d.ts +1 -0
  155. package/dist/types/profiler/render-count.d.ts +14 -0
  156. package/dist/types/types/feature-flags.d.ts +8 -0
  157. package/dist/types/ui/LinkSearch/types.d.ts +1 -0
  158. package/dist/types/utils/react-hooks/use-component-renderer-tracking/index.d.ts +17 -1
  159. package/package.json +19 -16
  160. package/dist/cjs/plugins/caption/nodeviews/index.test.js +0 -135
  161. package/dist/cjs/plugins/caption/pm-plugins/keymap.test.js +0 -203
  162. package/dist/cjs/plugins/caption/pm-plugins/main.test.js +0 -141
  163. package/dist/cjs/plugins/code-block/language-list.test.js +0 -74
  164. package/dist/cjs/plugins/extension/ui/SaveIndicator/SaveIndicator.test.js +0 -101
  165. package/dist/cjs/plugins/floating-toolbar/ui/EmojiPickerButton.test.js +0 -98
  166. package/dist/cjs/plugins/media/commands/captions.test.js +0 -149
  167. package/dist/cjs/plugins/media/commands/linking.test.js +0 -296
  168. package/dist/cjs/plugins/media/ui/CaptionPlaceholder/index.test.js +0 -50
  169. package/dist/cjs/plugins/panel/toolbar.test.js +0 -250
  170. package/dist/cjs/ui/ColorPickerButton/index.test.js +0 -123
  171. package/dist/cjs/ui/PortalProvider/index.test.js +0 -139
  172. package/dist/es2019/plugins/caption/nodeviews/index.test.js +0 -122
  173. package/dist/es2019/plugins/caption/pm-plugins/keymap.test.js +0 -193
  174. package/dist/es2019/plugins/caption/pm-plugins/main.test.js +0 -132
  175. package/dist/es2019/plugins/code-block/language-list.test.js +0 -69
  176. package/dist/es2019/plugins/extension/ui/SaveIndicator/SaveIndicator.test.js +0 -83
  177. package/dist/es2019/plugins/floating-toolbar/ui/EmojiPickerButton.test.js +0 -85
  178. package/dist/es2019/plugins/media/commands/captions.test.js +0 -126
  179. package/dist/es2019/plugins/media/commands/linking.test.js +0 -208
  180. package/dist/es2019/plugins/media/ui/CaptionPlaceholder/index.test.js +0 -41
  181. package/dist/es2019/plugins/panel/toolbar.test.js +0 -200
  182. package/dist/es2019/ui/ColorPickerButton/index.test.js +0 -88
  183. package/dist/es2019/ui/PortalProvider/index.test.js +0 -115
  184. package/dist/esm/plugins/caption/nodeviews/index.test.js +0 -125
  185. package/dist/esm/plugins/caption/pm-plugins/keymap.test.js +0 -195
  186. package/dist/esm/plugins/caption/pm-plugins/main.test.js +0 -124
  187. package/dist/esm/plugins/code-block/language-list.test.js +0 -71
  188. package/dist/esm/plugins/extension/ui/SaveIndicator/SaveIndicator.test.js +0 -92
  189. package/dist/esm/plugins/floating-toolbar/ui/EmojiPickerButton.test.js +0 -85
  190. package/dist/esm/plugins/media/commands/captions.test.js +0 -135
  191. package/dist/esm/plugins/media/commands/linking.test.js +0 -268
  192. package/dist/esm/plugins/media/ui/CaptionPlaceholder/index.test.js +0 -41
  193. package/dist/esm/plugins/panel/toolbar.test.js +0 -230
  194. package/dist/esm/ui/ColorPickerButton/index.test.js +0 -107
  195. package/dist/esm/ui/PortalProvider/index.test.js +0 -129
@@ -1,33 +1,66 @@
1
- import { useEffect, useRef } from 'react';
1
+ import { useMemo, useEffect, useRef } from 'react';
2
+ import debounce from 'lodash/debounce';
2
3
  import { getShallowPropsDifference, getPropsDifference } from '../../compare';
3
4
  import { EVENT_TYPE } from '../../../plugins/analytics';
4
- export function useComponentRenderTracking(props, action, actionSubject, handleAnalyticsEvent, propsToIgnore = [], useShallow) {
5
+ export function useComponentRenderTracking({
6
+ onRender,
7
+ propsDiffingOptions,
8
+ zeroBasedCount = true
9
+ }) {
5
10
  const propsRef = useRef();
6
- const renderCountRef = useRef(0);
11
+ const renderCountRef = useRef(zeroBasedCount ? 0 : 1);
7
12
  useEffect(() => {
8
13
  const lastProps = propsRef.current;
9
14
  const renderCount = renderCountRef.current;
15
+ let propsDifference;
10
16
 
11
- if (lastProps) {
12
- let difference = useShallow ? getShallowPropsDifference(lastProps, props) : getPropsDifference(lastProps, props, 0, 2, propsToIgnore);
13
- handleAnalyticsEvent({
14
- payload: {
15
- action,
16
- actionSubject,
17
- attributes: {
18
- propsDifference: difference,
19
- count: renderCount
20
- },
21
- eventType: EVENT_TYPE.OPERATIONAL
22
- }
23
- });
17
+ if (propsDiffingOptions !== null && propsDiffingOptions !== void 0 && propsDiffingOptions.enabled && lastProps) {
18
+ propsDifference = propsDiffingOptions !== null && propsDiffingOptions !== void 0 && propsDiffingOptions.useShallow ? getShallowPropsDifference(lastProps, propsDiffingOptions.props) : getPropsDifference(lastProps, propsDiffingOptions.props, 0, 2, propsDiffingOptions === null || propsDiffingOptions === void 0 ? void 0 : propsDiffingOptions.propsToIgnore);
19
+ }
20
+
21
+ const result = {
22
+ renderCount,
23
+ propsDifference
24
+ };
25
+ onRender(result);
26
+
27
+ if (propsDiffingOptions !== null && propsDiffingOptions !== void 0 && propsDiffingOptions.enabled) {
28
+ propsRef.current = propsDiffingOptions.props;
24
29
  }
25
30
 
26
- propsRef.current = props;
27
31
  renderCountRef.current = renderCountRef.current + 1;
28
32
  }); // No dependencies run on each render
29
33
  }
30
34
  export function RenderTracking(props) {
31
- useComponentRenderTracking(props.componentProps, props.action, props.actionSubject, props.handleAnalyticsEvent, props.propsToIgnore, props.useShallow);
35
+ const debouncedHandleAnalyticsEvent = useMemo(() => debounce(props.handleAnalyticsEvent, 500), [props.handleAnalyticsEvent]);
36
+ useComponentRenderTracking({
37
+ onRender: ({
38
+ renderCount,
39
+ propsDifference
40
+ }) => {
41
+ if (!renderCount) {
42
+ return;
43
+ }
44
+
45
+ debouncedHandleAnalyticsEvent({
46
+ payload: {
47
+ action: props.action,
48
+ actionSubject: props.actionSubject,
49
+ attributes: {
50
+ count: renderCount,
51
+ propsDifference: propsDifference
52
+ },
53
+ eventType: EVENT_TYPE.OPERATIONAL
54
+ }
55
+ });
56
+ },
57
+ propsDiffingOptions: {
58
+ enabled: true,
59
+ props: props.componentProps,
60
+ propsToIgnore: props.propsToIgnore,
61
+ useShallow: props.useShallow
62
+ },
63
+ zeroBasedCount: true
64
+ });
32
65
  return null;
33
66
  }
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "150.0.3";
2
+ export const version = "151.0.0";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "150.0.3",
3
+ "version": "151.0.0",
4
4
  "sideEffects": false
5
5
  }
@@ -4,7 +4,7 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
4
  import _createClass from "@babel/runtime/helpers/createClass";
5
5
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
6
6
  import { Node } from 'prosemirror-model';
7
- import { TextSelection, Selection } from 'prosemirror-state';
7
+ import { TextSelection } from 'prosemirror-state';
8
8
  import { toJSON } from '../utils';
9
9
  import { processRawValue, isEmptyDocument } from '../utils/document';
10
10
  import { getEditorValueWithMedia, __temporaryFixForConfigPanel as _temporaryFixForConfigPanel } from '../utils/action';
@@ -244,31 +244,13 @@ var EditorActions = /*#__PURE__*/function () {
244
244
  return false;
245
245
  }
246
246
 
247
- var state = this.editorView.state;
248
- var schema = state.schema;
249
- var content = processRawValue(schema, rawValue, undefined, undefined, this.contentTransformer, this.dispatchAnalyticsEvent);
250
-
251
- if (!content) {
252
- return false;
253
- } // In case of replacing a whole document, we only need a content of a top level node e.g. document.
254
-
255
-
256
- var tr = state.tr.replaceWith(0, state.doc.nodeSize - 2, content.content);
257
-
258
- if (!shouldScrollToBottom && !tr.selectionSet) {
259
- // Restore selection at start of document instead of the end.
260
- tr.setSelection(Selection.atStart(tr.doc));
261
- }
262
-
263
- if (shouldScrollToBottom) {
264
- tr = tr.scrollIntoView();
265
- }
266
-
267
- if (!shouldAddToHistory) {
268
- tr.setMeta('addToHistory', false);
247
+ if (this.eventDispatcher) {
248
+ this.eventDispatcher.emit('resetEditorState', {
249
+ doc: rawValue,
250
+ shouldScrollToBottom: shouldScrollToBottom
251
+ });
269
252
  }
270
253
 
271
- this.editorView.dispatch(tr);
272
254
  return true;
273
255
  }
274
256
  }, {
@@ -8,6 +8,10 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstruct
8
8
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
9
9
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
10
10
 
11
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
12
+
13
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
14
+
11
15
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
12
16
 
13
17
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
@@ -16,6 +20,7 @@ import React from 'react';
16
20
  import uuid from 'uuid';
17
21
  import memoizeOne from 'memoize-one';
18
22
  import { sniffUserBrowserExtensions } from '@atlaskit/editor-common';
23
+ import { ExperienceStore } from '@atlaskit/editor-common/ufo';
19
24
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '../plugins/analytics';
20
25
  import { editorAnalyticsChannel } from '../plugins/analytics/consts';
21
26
  import { getFeatureFlags } from '../plugins/feature-flags-context';
@@ -26,16 +31,12 @@ export var ErrorBoundaryWithEditorView = /*#__PURE__*/function (_React$Component
26
31
 
27
32
  var _super = _createSuper(ErrorBoundaryWithEditorView);
28
33
 
29
- function ErrorBoundaryWithEditorView() {
34
+ function ErrorBoundaryWithEditorView(props) {
30
35
  var _this;
31
36
 
32
37
  _classCallCheck(this, ErrorBoundaryWithEditorView);
33
38
 
34
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
35
- args[_key] = arguments[_key];
36
- }
37
-
38
- _this = _super.call.apply(_super, [this].concat(args));
39
+ _this = _super.call(this, props);
39
40
 
40
41
  _defineProperty(_assertThisInitialized(_this), "browserExtensions", undefined);
41
42
 
@@ -51,102 +52,138 @@ export var ErrorBoundaryWithEditorView = /*#__PURE__*/function (_React$Component
51
52
  return getFeatureFlags(editorView.state);
52
53
  }));
53
54
 
54
- _defineProperty(_assertThisInitialized(_this), "fireAnalytics", function (analyticsErrorPayload) {
55
- var createAnalyticsEvent = _this.props.createAnalyticsEvent;
56
-
57
- _this.getProductName().then(function (product) {
58
- if (createAnalyticsEvent) {
59
- var error = analyticsErrorPayload.error,
60
- errorInfo = analyticsErrorPayload.errorInfo,
61
- errorStack = analyticsErrorPayload.errorStack;
62
- var sharedId = uuid();
63
- var event = {
64
- action: ACTION.EDITOR_CRASHED,
65
- actionSubject: ACTION_SUBJECT.EDITOR,
66
- eventType: EVENT_TYPE.OPERATIONAL,
67
- attributes: {
68
- product: product,
69
- browserInfo: window && window.navigator && window.navigator.userAgent ? window.navigator.userAgent : 'unknown',
70
- error: error,
71
- errorInfo: errorInfo,
72
- errorId: sharedId,
73
- browserExtensions: _this.browserExtensions
74
- }
75
- }; // Add doc structure if the feature flag is on
55
+ _defineProperty(_assertThisInitialized(_this), "sendErrorData", /*#__PURE__*/function () {
56
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(analyticsErrorPayload) {
57
+ var product, error, errorInfo, errorStack, sharedId, attributes, _this$experienceStore;
76
58
 
77
- if (_this.featureFlags.errorBoundaryDocStructure && _this.props.editorView) {
78
- event.attributes.docStructure = getDocStructure(_this.props.editorView.state.doc, {
79
- compact: true
80
- });
81
- }
59
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
60
+ while (1) {
61
+ switch (_context.prev = _context.next) {
62
+ case 0:
63
+ _context.next = 2;
64
+ return _this.getProductName();
65
+
66
+ case 2:
67
+ product = _context.sent;
68
+ error = analyticsErrorPayload.error, errorInfo = analyticsErrorPayload.errorInfo, errorStack = analyticsErrorPayload.errorStack;
69
+ sharedId = uuid();
70
+ attributes = {
71
+ product: product,
72
+ browserInfo: window && window.navigator && window.navigator.userAgent ? window.navigator.userAgent : 'unknown',
73
+ error: error,
74
+ errorInfo: errorInfo,
75
+ errorId: sharedId,
76
+ browserExtensions: _this.browserExtensions,
77
+ docStructure: _this.featureFlags.errorBoundaryDocStructure && _this.props.editorView ? getDocStructure(_this.props.editorView.state.doc, {
78
+ compact: true
79
+ }) : undefined
80
+ };
81
+
82
+ _this.fireAnalyticsEvent({
83
+ action: ACTION.EDITOR_CRASHED,
84
+ actionSubject: ACTION_SUBJECT.EDITOR,
85
+ eventType: EVENT_TYPE.OPERATIONAL,
86
+ attributes: attributes
87
+ });
88
+
89
+ _this.fireAnalyticsEvent({
90
+ action: ACTION.EDITOR_CRASHED_ADDITIONAL_INFORMATION,
91
+ actionSubject: ACTION_SUBJECT.EDITOR,
92
+ eventType: EVENT_TYPE.OPERATIONAL,
93
+ attributes: {
94
+ errorStack: errorStack,
95
+ errorId: sharedId
96
+ }
97
+ });
98
+
99
+ if (_this.featureFlags.ufo && _this.props.editorView) {
100
+ (_this$experienceStore = _this.experienceStore) === null || _this$experienceStore === void 0 ? void 0 : _this$experienceStore.failAll(_objectSpread(_objectSpread({}, _this.getExperienceMetadata(attributes)), {}, {
101
+ errorStack: errorStack
102
+ }));
103
+ }
82
104
 
83
- createAnalyticsEvent(event).fire(editorAnalyticsChannel);
84
- createAnalyticsEvent({
85
- action: ACTION.EDITOR_CRASHED_ADDITIONAL_INFORMATION,
86
- actionSubject: ACTION_SUBJECT.EDITOR,
87
- eventType: EVENT_TYPE.OPERATIONAL,
88
- attributes: {
89
- errorStack: errorStack,
90
- errorId: sharedId
105
+ case 9:
106
+ case "end":
107
+ return _context.stop();
91
108
  }
92
- }).fire(editorAnalyticsChannel);
93
- } else {
94
- // eslint-disable-next-line no-console
95
- console.error('Editor Error Boundary: Missing `createAnalyticsEvent` prop.', {
96
- channel: editorAnalyticsChannel,
97
- product: product,
98
- error: analyticsErrorPayload
99
- });
100
- }
101
- }).catch(function (e) {
102
- // eslint-disable-next-line no-console
103
- console.error('Failed to resolve product name from contextIdentifierProvider.', e);
104
- });
105
- });
109
+ }
110
+ }, _callee);
111
+ }));
112
+
113
+ return function (_x) {
114
+ return _ref.apply(this, arguments);
115
+ };
116
+ }());
106
117
 
107
- _defineProperty(_assertThisInitialized(_this), "getProductName", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
118
+ _defineProperty(_assertThisInitialized(_this), "getProductName", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
108
119
  var contextIdentifierProvider, context;
109
- return _regeneratorRuntime.wrap(function _callee$(_context) {
120
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
110
121
  while (1) {
111
- switch (_context.prev = _context.next) {
122
+ switch (_context2.prev = _context2.next) {
112
123
  case 0:
113
124
  contextIdentifierProvider = _this.props.contextIdentifierProvider;
114
125
 
115
126
  if (!contextIdentifierProvider) {
116
- _context.next = 7;
127
+ _context2.next = 7;
117
128
  break;
118
129
  }
119
130
 
120
- _context.next = 4;
131
+ _context2.next = 4;
121
132
  return contextIdentifierProvider;
122
133
 
123
134
  case 4:
124
- context = _context.sent;
135
+ context = _context2.sent;
125
136
 
126
137
  if (!context.product) {
127
- _context.next = 7;
138
+ _context2.next = 7;
128
139
  break;
129
140
  }
130
141
 
131
- return _context.abrupt("return", context.product);
142
+ return _context2.abrupt("return", context.product);
132
143
 
133
144
  case 7:
134
- return _context.abrupt("return", 'atlaskit');
145
+ return _context2.abrupt("return", 'atlaskit');
135
146
 
136
147
  case 8:
137
148
  case "end":
138
- return _context.stop();
149
+ return _context2.stop();
139
150
  }
140
151
  }
141
- }, _callee);
152
+ }, _callee2);
142
153
  })));
143
154
 
155
+ _defineProperty(_assertThisInitialized(_this), "fireAnalyticsEvent", function (event) {
156
+ var _this$props$createAna, _this$props;
157
+
158
+ (_this$props$createAna = (_this$props = _this.props).createAnalyticsEvent) === null || _this$props$createAna === void 0 ? void 0 : _this$props$createAna.call(_this$props, event).fire(editorAnalyticsChannel);
159
+ });
160
+
161
+ _defineProperty(_assertThisInitialized(_this), "getExperienceMetadata", function (attributes) {
162
+ var _attributes$browserEx;
163
+
164
+ return {
165
+ browserInfo: attributes.browserInfo,
166
+ error: attributes.error.toString(),
167
+ errorInfo: {
168
+ componentStack: attributes.errorInfo.componentStack
169
+ },
170
+ errorId: attributes.errorId,
171
+ browserExtensions: (_attributes$browserEx = attributes.browserExtensions) === null || _attributes$browserEx === void 0 ? void 0 : _attributes$browserEx.toString(),
172
+ docStructure: attributes.docStructure
173
+ };
174
+ });
175
+
176
+ if (props.editorView) {
177
+ _this.experienceStore = ExperienceStore.getInstance(props.editorView);
178
+ }
179
+
144
180
  return _this;
145
181
  }
146
182
 
147
183
  _createClass(ErrorBoundaryWithEditorView, [{
148
184
  key: "featureFlags",
149
- get: function get() {
185
+ get: // Memoizing this as react alternative suggestion of https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops
186
+ function get() {
150
187
  return this.getFeatureFlags(this.props.editorView);
151
188
  }
152
189
  }, {
@@ -154,13 +191,11 @@ export var ErrorBoundaryWithEditorView = /*#__PURE__*/function (_React$Component
154
191
  value: function componentDidCatch(error, errorInfo) {
155
192
  var _this2 = this;
156
193
 
157
- // Log the error
158
- this.fireAnalytics({
194
+ this.sendErrorData({
159
195
  error: error.toString(),
160
196
  errorInfo: errorInfo,
161
197
  errorStack: error.stack
162
- }); //
163
- // // Update state to allow a re-render to attempt graceful recovery (in the event that
198
+ }); // // Update state to allow a re-render to attempt graceful recovery (in the event that
164
199
  // // the error was caused by a race condition or is intermittent)
165
200
 
166
201
  this.setState({
@@ -180,12 +215,12 @@ export var ErrorBoundaryWithEditorView = /*#__PURE__*/function (_React$Component
180
215
  }, {
181
216
  key: "componentDidMount",
182
217
  value: function () {
183
- var _componentDidMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
184
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
218
+ var _componentDidMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
219
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
185
220
  while (1) {
186
- switch (_context2.prev = _context2.next) {
221
+ switch (_context3.prev = _context3.next) {
187
222
  case 0:
188
- _context2.next = 2;
223
+ _context3.next = 2;
189
224
  return sniffUserBrowserExtensions({
190
225
  extensions: ['grammarly'],
191
226
  async: true,
@@ -193,14 +228,14 @@ export var ErrorBoundaryWithEditorView = /*#__PURE__*/function (_React$Component
193
228
  });
194
229
 
195
230
  case 2:
196
- this.browserExtensions = _context2.sent;
231
+ this.browserExtensions = _context3.sent;
197
232
 
198
233
  case 3:
199
234
  case "end":
200
- return _context2.stop();
235
+ return _context3.stop();
201
236
  }
202
237
  }
203
- }, _callee2, this);
238
+ }, _callee3, this);
204
239
  }));
205
240
 
206
241
  function componentDidMount() {