@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,149 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
8
-
9
- var _createEditor = require("@atlaskit/editor-test-helpers/create-editor");
10
-
11
- var _docBuilder = require("@atlaskit/editor-test-helpers/doc-builder");
12
-
13
- var analyticsUtils = _interopRequireWildcard(require("../../analytics/utils"));
14
-
15
- var _captions = require("./captions");
16
-
17
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
-
19
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
-
21
- 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; }
22
-
23
- 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) { (0, _defineProperty2.default)(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; }
24
-
25
- describe('Caption plugin', function () {
26
- var createEditor = (0, _createEditor.createEditorFactory)();
27
-
28
- var editor = function editor(doc) {
29
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
30
- return createEditor(_objectSpread({
31
- doc: doc
32
- }, opts));
33
- };
34
-
35
- it('should insert the caption node and select it', function () {
36
- var _editor = editor((0, _docBuilder.doc)('{<node>}', (0, _docBuilder.mediaSingle)()((0, _docBuilder.media)({
37
- id: 'a559980d-cd47-43e2-8377-27359fcb905f',
38
- type: 'file',
39
- collection: 'MediaServicesSample'
40
- })()), (0, _docBuilder.p)('Line two')), {
41
- editorProps: {
42
- media: {
43
- allowMediaSingle: true,
44
- featureFlags: {
45
- captions: true
46
- }
47
- }
48
- }
49
- }),
50
- editorView = _editor.editorView;
51
-
52
- (0, _captions.insertAndSelectCaptionFromMediaSinglePos)(0, editorView.state.doc.child(0))(editorView.state, editorView.dispatch);
53
- expect(editorView.state).toEqualDocumentAndSelection((0, _docBuilder.doc)((0, _docBuilder.mediaSingle)()((0, _docBuilder.media)({
54
- id: 'a559980d-cd47-43e2-8377-27359fcb905f',
55
- type: 'file',
56
- collection: 'MediaServicesSample'
57
- })(), (0, _docBuilder.caption)('{<>}')), (0, _docBuilder.p)('Line two')));
58
- });
59
- it('should not insert the caption node when it exists already', function () {
60
- var _editor2 = editor((0, _docBuilder.doc)('{<node>}', (0, _docBuilder.mediaSingle)()((0, _docBuilder.media)({
61
- id: 'a559980d-cd47-43e2-8377-27359fcb905f',
62
- type: 'file',
63
- collection: 'MediaServicesSample'
64
- })(), (0, _docBuilder.caption)('test')), (0, _docBuilder.p)('Line two')), {
65
- editorProps: {
66
- media: {
67
- allowMediaSingle: true,
68
- featureFlags: {
69
- captions: true
70
- }
71
- }
72
- }
73
- }),
74
- editorView = _editor2.editorView;
75
-
76
- expect((0, _captions.insertAndSelectCaptionFromMediaSinglePos)(0, editorView.state.doc.child(0))(editorView.state, editorView.dispatch)).toBeFalsy();
77
- });
78
- it('create an added analytic for captions', function () {
79
- var addAnalyticsSpy = jest.spyOn(analyticsUtils, 'addAnalytics');
80
-
81
- var _editor3 = editor((0, _docBuilder.doc)('{<node>}', (0, _docBuilder.mediaSingle)()((0, _docBuilder.media)({
82
- id: 'a559980d-cd47-43e2-8377-27359fcb905f',
83
- type: 'file',
84
- collection: 'MediaServicesSample'
85
- })()), (0, _docBuilder.p)('Line two')), {
86
- editorProps: {
87
- media: {
88
- allowMediaSingle: true,
89
- featureFlags: {
90
- captions: true
91
- }
92
- }
93
- }
94
- }),
95
- editorView = _editor3.editorView;
96
-
97
- (0, _captions.insertAndSelectCaptionFromMediaSinglePos)(0, editorView.state.doc.child(0))(editorView.state, editorView.dispatch);
98
- expect(addAnalyticsSpy).toBeCalled();
99
- expect(addAnalyticsSpy.mock.calls[0][2]).toEqual({
100
- action: 'added',
101
- actionSubject: 'mediaSingle',
102
- actionSubjectId: 'caption',
103
- eventType: 'track'
104
- });
105
- });
106
- it('should move selection to an existing caption node', function () {
107
- var _editor4 = editor((0, _docBuilder.doc)('{<node>}', (0, _docBuilder.mediaSingle)()((0, _docBuilder.media)({
108
- id: 'a559980d-cd47-43e2-8377-27359fcb905f',
109
- type: 'file',
110
- collection: 'MediaServicesSample'
111
- })(), (0, _docBuilder.caption)('hello world')), (0, _docBuilder.p)('Line two')), {
112
- editorProps: {
113
- media: {
114
- allowMediaSingle: true,
115
- featureFlags: {
116
- captions: true
117
- }
118
- }
119
- }
120
- }),
121
- editorView = _editor4.editorView;
122
-
123
- (0, _captions.selectCaptionFromMediaSinglePos)(0, editorView.state.doc.child(0))(editorView.state, editorView.dispatch);
124
- expect(editorView.state).toEqualDocumentAndSelection((0, _docBuilder.doc)((0, _docBuilder.mediaSingle)()((0, _docBuilder.media)({
125
- id: 'a559980d-cd47-43e2-8377-27359fcb905f',
126
- type: 'file',
127
- collection: 'MediaServicesSample'
128
- })(), (0, _docBuilder.caption)('hello world{<>}')), (0, _docBuilder.p)('Line two')));
129
- });
130
- it('should not move selection to a non existing caption node', function () {
131
- var _editor5 = editor((0, _docBuilder.doc)('{<node>}', (0, _docBuilder.mediaSingle)()((0, _docBuilder.media)({
132
- id: 'a559980d-cd47-43e2-8377-27359fcb905f',
133
- type: 'file',
134
- collection: 'MediaServicesSample'
135
- })()), (0, _docBuilder.p)('Line two')), {
136
- editorProps: {
137
- media: {
138
- allowMediaSingle: true,
139
- featureFlags: {
140
- captions: true
141
- }
142
- }
143
- }
144
- }),
145
- editorView = _editor5.editorView;
146
-
147
- expect((0, _captions.selectCaptionFromMediaSinglePos)(0, editorView.state.doc.child(0))(editorView.state, editorView.dispatch)).toBeFalsy();
148
- });
149
- });
@@ -1,296 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
8
-
9
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
-
11
- var _docBuilder = require("@atlaskit/editor-test-helpers/doc-builder");
12
-
13
- var _mediaTestHelpers = require("@atlaskit/media-test-helpers");
14
-
15
- var _createProsemirrorEditor = require("@atlaskit/editor-test-helpers/create-prosemirror-editor");
16
-
17
- var _sendKeyToPm = _interopRequireDefault(require("@atlaskit/editor-test-helpers/send-key-to-pm"));
18
-
19
- var _editorCommon = require("@atlaskit/editor-common");
20
-
21
- var _hyperlink = _interopRequireDefault(require("../../hyperlink"));
22
-
23
- var _ = _interopRequireDefault(require("../"));
24
-
25
- var _actions = require("../pm-plugins/linking/actions");
26
-
27
- var _checkMediaType = require("../utils/check-media-type");
28
-
29
- var _linking = require("../pm-plugins/linking");
30
-
31
- var linking = _interopRequireWildcard(require("./linking"));
32
-
33
- var _types = require("../../analytics/types");
34
-
35
- var analyticUtils = _interopRequireWildcard(require("../../analytics/utils"));
36
-
37
- var commands = _interopRequireWildcard(require("../../../commands"));
38
-
39
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
40
-
41
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
42
-
43
- var setUrlToMedia = linking.setUrlToMedia,
44
- showLinkingToolbarWithMediaTypeCheck = linking.showLinkingToolbarWithMediaTypeCheck,
45
- unlink = linking.unlink;
46
- jest.mock('../utils/check-media-type', function () {
47
- return {
48
- checkMediaType: jest.fn()
49
- };
50
- });
51
- describe('image linking', function () {
52
- var createEditor = (0, _createProsemirrorEditor.createProsemirrorEditorFactory)();
53
- var preset = new _createProsemirrorEditor.Preset();
54
- var mediaProvider = Promise.resolve({
55
- viewMediaClientConfig: (0, _mediaTestHelpers.getDefaultMediaClientConfig)()
56
- });
57
-
58
- var providerFactory = _editorCommon.ProviderFactory.create({
59
- mediaProvider: mediaProvider
60
- });
61
-
62
- preset.add([_.default, {
63
- allowMediaSingle: true,
64
- allowLinking: true
65
- }]).add(_hyperlink.default);
66
-
67
- var editor = function editor(doc) {
68
- return createEditor({
69
- doc: doc,
70
- preset: preset,
71
- providerFactory: providerFactory
72
- });
73
- };
74
-
75
- var document = (0, _docBuilder.doc)('{<node>}', (0, _docBuilder.mediaSingle)()((0, _docBuilder.media)({
76
- id: 'a559980d-cd47-43e2-8377-27359fcb905f',
77
- type: 'file',
78
- collection: 'MediaServicesSample'
79
- })()), (0, _docBuilder.mediaSingle)()((0, _docBuilder.media)({
80
- id: 'a559980d-cd47-43e2-8377-27359fcb905f',
81
- type: 'file',
82
- collection: 'MediaServicesSample'
83
- })()));
84
- var mockDispatch = jest.fn();
85
- afterEach(function () {
86
- mockDispatch.mockClear();
87
- });
88
- describe('analytics', function () {
89
- var FIRST_CALL = 0;
90
- var ANALYTIC_PAYLOAD = 2;
91
- var analyticUtilsSpy = jest.spyOn(analyticUtils, 'addAnalytics');
92
- beforeEach(function () {
93
- analyticUtilsSpy.mockReset();
94
- });
95
- afterAll(function () {
96
- jest.resetAllMocks();
97
- });
98
- it('should call analytic when creating a link', function () {
99
- var _editor = editor(document),
100
- editorView = _editor.editorView;
101
-
102
- setUrlToMedia('http://google.com', _types.INPUT_METHOD.MANUAL)(editorView.state, mockDispatch, editorView);
103
- expect(analyticUtilsSpy).toBeCalled();
104
- expect(analyticUtilsSpy.mock.calls[FIRST_CALL][ANALYTIC_PAYLOAD]).toEqual({
105
- action: 'added',
106
- actionSubject: 'media',
107
- actionSubjectId: 'link',
108
- attributes: expect.objectContaining({
109
- inputMethod: 'manual'
110
- }),
111
- eventType: 'track'
112
- });
113
- });
114
- describe('existing links', function () {
115
- var googleUrl = 'http://google.com';
116
- var documentWithMediaWithLink = (0, _docBuilder.doc)('{<node>}', (0, _docBuilder.mediaSingle)()((0, _docBuilder.a)({
117
- href: googleUrl
118
- })((0, _docBuilder.media)({
119
- id: 'a559980d-cd47-43e2-8377-27359fcb905f',
120
- type: 'file',
121
- collection: 'MediaServicesSample'
122
- })())));
123
- it('should add edit analytic when modifying link', function () {
124
- var _editor2 = editor(documentWithMediaWithLink),
125
- editorView = _editor2.editorView;
126
-
127
- setUrlToMedia('http://random-url.com', _types.INPUT_METHOD.MANUAL)(editorView.state, editorView.dispatch, editorView);
128
- expect(analyticUtilsSpy).toHaveBeenCalledTimes(1);
129
- expect(analyticUtilsSpy.mock.calls[FIRST_CALL][ANALYTIC_PAYLOAD]).toEqual({
130
- action: 'edited',
131
- actionSubject: 'media',
132
- actionSubjectId: 'link',
133
- eventType: 'track'
134
- });
135
- });
136
- it('should delete analytic when removing a link', function () {
137
- var _editor3 = editor(documentWithMediaWithLink),
138
- editorView = _editor3.editorView;
139
-
140
- unlink(editorView.state, editorView.dispatch, editorView);
141
- expect(analyticUtilsSpy).toBeCalledTimes(1);
142
- expect(analyticUtilsSpy.mock.calls[FIRST_CALL][ANALYTIC_PAYLOAD]).toEqual({
143
- action: 'deleted',
144
- actionSubject: 'media',
145
- actionSubjectId: 'link',
146
- eventType: 'track'
147
- });
148
- });
149
- it("shouldn't call an analytic if the url was modified to the same url", function () {
150
- var _editor4 = editor(documentWithMediaWithLink),
151
- editorView = _editor4.editorView;
152
-
153
- setUrlToMedia(googleUrl, _types.INPUT_METHOD.MANUAL)(editorView.state, mockDispatch, editorView);
154
- expect(analyticUtilsSpy).not.toBeCalled();
155
- });
156
- });
157
- describe('errors', function () {
158
- beforeAll(function () {
159
- jest.spyOn(commands, 'createToggleBlockMarkOnRange').mockImplementation(function () {
160
- throw new Error('This error should be caught');
161
- });
162
- });
163
- it("should call analytic if there's an error creating a link", function () {
164
- var _editor5 = editor(document),
165
- editorView = _editor5.editorView;
166
-
167
- try {
168
- setUrlToMedia('http://google.com', _types.INPUT_METHOD.MANUAL)(editorView.state, mockDispatch, editorView);
169
- } catch (e) {// noop
170
- }
171
-
172
- expect(analyticUtilsSpy.mock.calls[FIRST_CALL][ANALYTIC_PAYLOAD]).toEqual({
173
- action: 'errored',
174
- actionSubject: 'media',
175
- actionSubjectId: 'link',
176
- attributes: {
177
- action: 'added'
178
- },
179
- eventType: 'track'
180
- });
181
- });
182
- });
183
- });
184
- describe('show linking toolbar', function () {
185
- describe('selected media is an image', function () {
186
- beforeAll(function () {
187
- _checkMediaType.checkMediaType.mockReturnValue(Promise.resolve('image'));
188
- });
189
- it('call dispatch with correct param with a media is selected', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
190
- var _editor6, editorView, result, expectTransaction;
191
-
192
- return _regenerator.default.wrap(function _callee$(_context) {
193
- while (1) {
194
- switch (_context.prev = _context.next) {
195
- case 0:
196
- _editor6 = editor(document), editorView = _editor6.editorView;
197
- _context.next = 3;
198
- return (0, _mediaTestHelpers.flushPromises)();
199
-
200
- case 3:
201
- result = showLinkingToolbarWithMediaTypeCheck(editorView.state, mockDispatch, editorView);
202
- expectTransaction = editorView.state.tr.setMeta(_linking.mediaLinkingPluginKey, {
203
- type: _actions.MediaLinkingActionsTypes.showToolbar
204
- });
205
- _context.next = 7;
206
- return (0, _mediaTestHelpers.flushPromises)();
207
-
208
- case 7:
209
- expect(result).toEqual(true);
210
- expect(mockDispatch).toHaveBeenCalledWith(expectTransaction);
211
-
212
- case 9:
213
- case "end":
214
- return _context.stop();
215
- }
216
- }
217
- }, _callee);
218
- })));
219
- it('does not call dispatch when selection is not a media single node', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
220
- var _editor7, editorView, result;
221
-
222
- return _regenerator.default.wrap(function _callee2$(_context2) {
223
- while (1) {
224
- switch (_context2.prev = _context2.next) {
225
- case 0:
226
- _editor7 = editor(document), editorView = _editor7.editorView;
227
- result = showLinkingToolbarWithMediaTypeCheck(editorView.state, mockDispatch, editorView);
228
- _context2.next = 4;
229
- return (0, _mediaTestHelpers.flushPromises)();
230
-
231
- case 4:
232
- expect(result).toEqual(false);
233
- expect(mockDispatch).not.toHaveBeenCalled();
234
-
235
- case 6:
236
- case "end":
237
- return _context2.stop();
238
- }
239
- }
240
- }, _callee2);
241
- })));
242
- it('does not call dispatch when selection has changed', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
243
- var _editor8, editorView, result;
244
-
245
- return _regenerator.default.wrap(function _callee3$(_context3) {
246
- while (1) {
247
- switch (_context3.prev = _context3.next) {
248
- case 0:
249
- _editor8 = editor(document), editorView = _editor8.editorView;
250
- result = showLinkingToolbarWithMediaTypeCheck(editorView.state, mockDispatch, editorView);
251
- (0, _sendKeyToPm.default)(editorView, 'ArrowDown');
252
- _context3.next = 5;
253
- return (0, _mediaTestHelpers.flushPromises)();
254
-
255
- case 5:
256
- expect(result).toEqual(false);
257
- expect(mockDispatch).not.toHaveBeenCalled();
258
-
259
- case 7:
260
- case "end":
261
- return _context3.stop();
262
- }
263
- }
264
- }, _callee3);
265
- })));
266
- });
267
- describe('selected media is a video', function () {
268
- beforeAll(function () {
269
- _checkMediaType.checkMediaType.mockReturnValue(Promise.resolve('video'));
270
- });
271
- it('does not call dispatch', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
272
- var _editor9, editorView, result;
273
-
274
- return _regenerator.default.wrap(function _callee4$(_context4) {
275
- while (1) {
276
- switch (_context4.prev = _context4.next) {
277
- case 0:
278
- _editor9 = editor(document), editorView = _editor9.editorView;
279
- result = showLinkingToolbarWithMediaTypeCheck(editorView.state, mockDispatch, editorView);
280
- _context4.next = 4;
281
- return (0, _mediaTestHelpers.flushPromises)();
282
-
283
- case 4:
284
- expect(result).toEqual(false);
285
- expect(mockDispatch).not.toHaveBeenCalled();
286
-
287
- case 6:
288
- case "end":
289
- return _context4.stop();
290
- }
291
- }
292
- }, _callee4);
293
- })));
294
- });
295
- });
296
- });
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _react = _interopRequireDefault(require("react"));
6
-
7
- var _react2 = require("@testing-library/react");
8
-
9
- var _reactIntl = require("react-intl");
10
-
11
- var _colors = require("@atlaskit/theme/colors");
12
-
13
- var _messages = require("./messages");
14
-
15
- var _index = _interopRequireDefault(require("./index"));
16
-
17
- var renderWithIntl = function renderWithIntl(component) {
18
- return (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_reactIntl.IntlProvider, {
19
- locale: "en"
20
- }, component));
21
- };
22
-
23
- var onClick = function onClick() {};
24
-
25
- describe('CaptionComponent', function () {
26
- it('should show a placeholder by default', function () {
27
- var _renderWithIntl = renderWithIntl( /*#__PURE__*/_react.default.createElement(_index.default, {
28
- onClick: onClick
29
- })),
30
- getByText = _renderWithIntl.getByText;
31
-
32
- expect(getByText(_messages.messages.placeholder.defaultMessage)).not.toBeNull();
33
- });
34
- it('should have the placeholder colour as N200', function () {
35
- var _renderWithIntl2 = renderWithIntl( /*#__PURE__*/_react.default.createElement(_index.default, {
36
- onClick: onClick
37
- })),
38
- container = _renderWithIntl2.container;
39
-
40
- expect(container.firstChild).toHaveStyle("color: ".concat(_colors.N200));
41
- });
42
- it('placeholder should be centered', function () {
43
- var _renderWithIntl3 = renderWithIntl( /*#__PURE__*/_react.default.createElement(_index.default, {
44
- onClick: onClick
45
- })),
46
- container = _renderWithIntl3.container;
47
-
48
- expect(container.firstChild).toHaveStyle("text-align: center");
49
- });
50
- });