@atlaskit/editor-core 150.0.1 → 151.1.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 (248) hide show
  1. package/CHANGELOG.md +69 -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 +8 -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-bidi-warning/index.js +25 -0
  17. package/dist/cjs/plugins/code-bidi-warning/plugin-key.js +11 -0
  18. package/dist/cjs/plugins/code-bidi-warning/pm-plugins/main.js +43 -0
  19. package/dist/cjs/plugins/code-bidi-warning/pm-plugins/plugin-factory.js +118 -0
  20. package/dist/cjs/plugins/code-bidi-warning/pm-plugins/reducer.js +12 -0
  21. package/dist/cjs/plugins/code-bidi-warning/pm-plugins/types.js +5 -0
  22. package/dist/cjs/plugins/code-block/index.js +10 -6
  23. package/dist/cjs/plugins/code-block/nodeviews/highlighting-code-block.js +16 -5
  24. package/dist/cjs/plugins/code-block/pm-plugins/main.js +12 -3
  25. package/dist/cjs/plugins/code-block/toolbar.js +1 -1
  26. package/dist/cjs/plugins/collab-edit/ui/to-avatar.js +4 -8
  27. package/dist/cjs/plugins/emoji/styles.js +1 -1
  28. package/dist/cjs/plugins/extension/pm-plugins/main.js +1 -4
  29. package/dist/cjs/plugins/extension/toolbar.js +28 -23
  30. package/dist/cjs/plugins/feature-flags-context/feature-flags-from-props.js +9 -3
  31. package/dist/cjs/plugins/find-replace/ui/Find.js +27 -7
  32. package/dist/cjs/plugins/hyperlink/pm-plugins/keymap.js +3 -3
  33. package/dist/cjs/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.js +7 -4
  34. package/dist/cjs/plugins/hyperlink/utils.js +6 -69
  35. package/dist/cjs/plugins/index.js +8 -0
  36. package/dist/cjs/plugins/media/index.js +14 -3
  37. package/dist/cjs/plugins/media/nodeviews/mediaGroup.js +24 -10
  38. package/dist/cjs/plugins/media/nodeviews/mediaInline.js +179 -0
  39. package/dist/cjs/plugins/media/pm-plugins/main.js +18 -9
  40. package/dist/cjs/plugins/media/toolbar/index.js +49 -17
  41. package/dist/cjs/plugins/media/toolbar/utils.js +20 -2
  42. package/dist/cjs/plugins/media/utils/media-files.js +67 -1
  43. package/dist/cjs/plugins/mentions/type-ahead/index.js +39 -3
  44. package/dist/cjs/plugins/panel/index.js +2 -3
  45. package/dist/cjs/plugins/panel/message.js +47 -0
  46. package/dist/cjs/plugins/panel/toolbar.js +64 -84
  47. package/dist/cjs/plugins/panel/utils.js +2 -2
  48. package/dist/cjs/plugins/paste/linkify-md-plugin.js +3 -3
  49. package/dist/cjs/plugins/rank.js +1 -1
  50. package/dist/cjs/plugins/status/styles.js +1 -1
  51. package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +18 -2
  52. package/dist/cjs/profiler/render-count.js +82 -0
  53. package/dist/cjs/ui/Appearance/Comment/Comment.js +6 -5
  54. package/dist/cjs/utils/react-hooks/use-component-renderer-tracking/index.js +55 -19
  55. package/dist/cjs/version-wrapper.js +1 -1
  56. package/dist/cjs/version.json +1 -1
  57. package/dist/es2019/actions/index.js +6 -28
  58. package/dist/es2019/create-editor/ErrorBoundary.js +73 -60
  59. package/dist/es2019/create-editor/ReactEditorView.js +130 -23
  60. package/dist/es2019/create-editor/create-plugins-list.js +9 -3
  61. package/dist/es2019/editor.js +74 -35
  62. package/dist/es2019/labs/next/presets/cxhtml.js +2 -1
  63. package/dist/es2019/plugins/analytics/types/enums.js +3 -1
  64. package/dist/es2019/plugins/base/index.js +4 -3
  65. package/dist/es2019/plugins/base/pm-plugins/frozen-editor.js +63 -35
  66. package/dist/es2019/plugins/block-type/ui/ToolbarBlockType/styled.js +2 -1
  67. package/dist/es2019/plugins/card/index.js +7 -2
  68. package/dist/es2019/plugins/card/nodeviews/embedCard.js +1 -0
  69. package/dist/es2019/plugins/card/pm-plugins/main.js +9 -2
  70. package/dist/es2019/plugins/card/pm-plugins/util/resolve.js +12 -5
  71. package/dist/es2019/plugins/code-bidi-warning/index.js +15 -0
  72. package/dist/es2019/plugins/code-bidi-warning/plugin-key.js +2 -0
  73. package/dist/es2019/plugins/code-bidi-warning/pm-plugins/main.js +31 -0
  74. package/dist/es2019/plugins/code-bidi-warning/pm-plugins/plugin-factory.js +88 -0
  75. package/dist/es2019/plugins/code-bidi-warning/pm-plugins/reducer.js +3 -0
  76. package/dist/es2019/plugins/code-bidi-warning/pm-plugins/types.js +1 -0
  77. package/dist/es2019/plugins/code-block/index.js +6 -1
  78. package/dist/es2019/plugins/code-block/nodeviews/highlighting-code-block.js +16 -4
  79. package/dist/es2019/plugins/code-block/pm-plugins/main.js +50 -39
  80. package/dist/es2019/plugins/code-block/toolbar.js +1 -1
  81. package/dist/es2019/plugins/collab-edit/ui/to-avatar.js +2 -6
  82. package/dist/es2019/plugins/emoji/styles.js +2 -0
  83. package/dist/es2019/plugins/extension/pm-plugins/main.js +1 -4
  84. package/dist/es2019/plugins/extension/toolbar.js +30 -25
  85. package/dist/es2019/plugins/feature-flags-context/feature-flags-from-props.js +9 -4
  86. package/dist/es2019/plugins/find-replace/ui/Find.js +27 -6
  87. package/dist/es2019/plugins/hyperlink/pm-plugins/keymap.js +1 -1
  88. package/dist/es2019/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.js +7 -4
  89. package/dist/es2019/plugins/hyperlink/utils.js +3 -59
  90. package/dist/es2019/plugins/index.js +2 -1
  91. package/dist/es2019/plugins/media/index.js +13 -4
  92. package/dist/es2019/plugins/media/nodeviews/mediaGroup.js +16 -7
  93. package/dist/es2019/plugins/media/nodeviews/mediaInline.js +88 -0
  94. package/dist/es2019/plugins/media/pm-plugins/main.js +20 -11
  95. package/dist/es2019/plugins/media/toolbar/index.js +44 -15
  96. package/dist/es2019/plugins/media/toolbar/utils.js +16 -0
  97. package/dist/es2019/plugins/media/utils/media-files.js +68 -2
  98. package/dist/es2019/plugins/mentions/type-ahead/index.js +21 -2
  99. package/dist/es2019/plugins/panel/index.js +3 -4
  100. package/dist/es2019/plugins/panel/message.js +38 -0
  101. package/dist/es2019/plugins/panel/toolbar.js +52 -71
  102. package/dist/es2019/plugins/panel/utils.js +2 -2
  103. package/dist/es2019/plugins/paste/linkify-md-plugin.js +2 -2
  104. package/dist/es2019/plugins/rank.js +1 -1
  105. package/dist/es2019/plugins/status/styles.js +2 -0
  106. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +18 -2
  107. package/dist/es2019/profiler/render-count.js +60 -0
  108. package/dist/es2019/ui/Appearance/Comment/Comment.js +4 -2
  109. package/dist/es2019/utils/react-hooks/use-component-renderer-tracking/index.js +51 -18
  110. package/dist/es2019/version-wrapper.js +1 -1
  111. package/dist/es2019/version.json +1 -1
  112. package/dist/esm/actions/index.js +6 -24
  113. package/dist/esm/create-editor/ErrorBoundary.js +113 -78
  114. package/dist/esm/create-editor/ReactEditorView.js +146 -31
  115. package/dist/esm/create-editor/create-plugins-list.js +9 -3
  116. package/dist/esm/editor.js +100 -40
  117. package/dist/esm/labs/next/presets/cxhtml.js +2 -1
  118. package/dist/esm/plugins/analytics/types/enums.js +3 -1
  119. package/dist/esm/plugins/base/index.js +4 -3
  120. package/dist/esm/plugins/base/pm-plugins/frozen-editor.js +64 -36
  121. package/dist/esm/plugins/block-type/ui/ToolbarBlockType/styled.js +3 -1
  122. package/dist/esm/plugins/card/index.js +13 -2
  123. package/dist/esm/plugins/card/nodeviews/embedCard.js +1 -0
  124. package/dist/esm/plugins/card/pm-plugins/main.js +7 -2
  125. package/dist/esm/plugins/card/pm-plugins/util/resolve.js +12 -5
  126. package/dist/esm/plugins/code-bidi-warning/index.js +17 -0
  127. package/dist/esm/plugins/code-bidi-warning/plugin-key.js +2 -0
  128. package/dist/esm/plugins/code-bidi-warning/pm-plugins/main.js +30 -0
  129. package/dist/esm/plugins/code-bidi-warning/pm-plugins/plugin-factory.js +96 -0
  130. package/dist/esm/plugins/code-bidi-warning/pm-plugins/reducer.js +3 -0
  131. package/dist/esm/plugins/code-bidi-warning/pm-plugins/types.js +1 -0
  132. package/dist/esm/plugins/code-block/index.js +10 -6
  133. package/dist/esm/plugins/code-block/nodeviews/highlighting-code-block.js +16 -5
  134. package/dist/esm/plugins/code-block/pm-plugins/main.js +11 -3
  135. package/dist/esm/plugins/code-block/toolbar.js +1 -1
  136. package/dist/esm/plugins/collab-edit/ui/to-avatar.js +4 -8
  137. package/dist/esm/plugins/emoji/styles.js +1 -1
  138. package/dist/esm/plugins/extension/pm-plugins/main.js +1 -4
  139. package/dist/esm/plugins/extension/toolbar.js +28 -23
  140. package/dist/esm/plugins/feature-flags-context/feature-flags-from-props.js +9 -4
  141. package/dist/esm/plugins/find-replace/ui/Find.js +27 -7
  142. package/dist/esm/plugins/hyperlink/pm-plugins/keymap.js +1 -1
  143. package/dist/esm/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.js +7 -4
  144. package/dist/esm/plugins/hyperlink/utils.js +3 -59
  145. package/dist/esm/plugins/index.js +2 -1
  146. package/dist/esm/plugins/media/index.js +14 -4
  147. package/dist/esm/plugins/media/nodeviews/mediaGroup.js +24 -10
  148. package/dist/esm/plugins/media/nodeviews/mediaInline.js +147 -0
  149. package/dist/esm/plugins/media/pm-plugins/main.js +19 -11
  150. package/dist/esm/plugins/media/toolbar/index.js +47 -19
  151. package/dist/esm/plugins/media/toolbar/utils.js +15 -1
  152. package/dist/esm/plugins/media/utils/media-files.js +60 -2
  153. package/dist/esm/plugins/mentions/type-ahead/index.js +39 -3
  154. package/dist/esm/plugins/panel/index.js +3 -4
  155. package/dist/esm/plugins/panel/message.js +38 -0
  156. package/dist/esm/plugins/panel/toolbar.js +57 -77
  157. package/dist/esm/plugins/panel/utils.js +2 -2
  158. package/dist/esm/plugins/paste/linkify-md-plugin.js +2 -2
  159. package/dist/esm/plugins/rank.js +1 -1
  160. package/dist/esm/plugins/status/styles.js +1 -1
  161. package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +18 -2
  162. package/dist/esm/profiler/render-count.js +57 -0
  163. package/dist/esm/ui/Appearance/Comment/Comment.js +6 -5
  164. package/dist/esm/utils/react-hooks/use-component-renderer-tracking/index.js +53 -20
  165. package/dist/esm/version-wrapper.js +1 -1
  166. package/dist/esm/version.json +1 -1
  167. package/dist/types/create-editor/ErrorBoundary.d.ts +6 -6
  168. package/dist/types/create-editor/ReactEditorView.d.ts +15 -3
  169. package/dist/types/editor.d.ts +3 -1
  170. package/dist/types/plugins/analytics/analytics-queue.d.ts +1 -1
  171. package/dist/types/plugins/analytics/index.d.ts +1 -1
  172. package/dist/types/plugins/analytics/types/enums.d.ts +4 -2
  173. package/dist/types/plugins/analytics/types/events.d.ts +7 -2
  174. package/dist/types/plugins/analytics/types/general-events.d.ts +4 -1
  175. package/dist/types/plugins/analytics/types/index.d.ts +1 -1
  176. package/dist/types/plugins/analytics/types/insert-events.d.ts +6 -1
  177. package/dist/types/plugins/analytics/types/link-tool-bar-events.d.ts +1 -0
  178. package/dist/types/plugins/base/index.d.ts +1 -0
  179. package/dist/types/plugins/base/pm-plugins/frozen-editor.d.ts +3 -2
  180. package/dist/types/plugins/card/pm-plugins/main.d.ts +2 -3
  181. package/dist/types/plugins/card/pm-plugins/util/resolve.d.ts +2 -1
  182. package/dist/types/plugins/card/types.d.ts +6 -0
  183. package/dist/types/plugins/code-bidi-warning/index.d.ts +3 -0
  184. package/dist/types/plugins/code-bidi-warning/plugin-key.d.ts +2 -0
  185. package/dist/types/plugins/code-bidi-warning/pm-plugins/main.d.ts +3 -0
  186. package/dist/types/plugins/code-bidi-warning/pm-plugins/plugin-factory.d.ts +7 -0
  187. package/dist/types/plugins/code-bidi-warning/pm-plugins/reducer.d.ts +3 -0
  188. package/dist/types/plugins/code-bidi-warning/pm-plugins/types.d.ts +5 -0
  189. package/dist/types/plugins/code-block/nodeviews/highlighting-code-block.d.ts +11 -2
  190. package/dist/types/plugins/code-block/pm-plugins/main.d.ts +5 -1
  191. package/dist/types/plugins/collab-edit/ui/to-avatar.d.ts +1 -1
  192. package/dist/types/plugins/extension/types.d.ts +0 -2
  193. package/dist/types/plugins/extension/ui/Extension/ExtensionComponent.d.ts +2 -2
  194. package/dist/types/plugins/feature-flags-context/get-enabled-feature-flag-keys.d.ts +1 -1
  195. package/dist/types/plugins/floating-toolbar/types.d.ts +1 -1
  196. package/dist/types/plugins/floating-toolbar/ui/Select.d.ts +1 -1
  197. package/dist/types/plugins/hyperlink/utils.d.ts +0 -21
  198. package/dist/types/plugins/index.d.ts +1 -0
  199. package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/create-items.d.ts +1 -1
  200. package/dist/types/plugins/media/nodeviews/mediaInline.d.ts +27 -0
  201. package/dist/types/plugins/media/pm-plugins/main.d.ts +2 -2
  202. package/dist/types/plugins/media/toolbar/utils.d.ts +2 -0
  203. package/dist/types/plugins/media/utils/media-files.d.ts +8 -0
  204. package/dist/types/plugins/panel/message.d.ts +37 -0
  205. package/dist/types/plugins/panel/toolbar.d.ts +4 -37
  206. package/dist/types/plugins/panel/types.d.ts +1 -0
  207. package/dist/types/plugins/quick-insert/index.d.ts +1 -1
  208. package/dist/types/profiler/render-count.d.ts +14 -0
  209. package/dist/types/types/feature-flags.d.ts +17 -0
  210. package/dist/types/ui/LinkSearch/types.d.ts +1 -0
  211. package/dist/types/utils/react-hooks/use-component-renderer-tracking/index.d.ts +17 -1
  212. package/package.json +22 -19
  213. package/dist/cjs/plugins/caption/nodeviews/index.test.js +0 -135
  214. package/dist/cjs/plugins/caption/pm-plugins/keymap.test.js +0 -203
  215. package/dist/cjs/plugins/caption/pm-plugins/main.test.js +0 -141
  216. package/dist/cjs/plugins/code-block/language-list.test.js +0 -74
  217. package/dist/cjs/plugins/extension/ui/SaveIndicator/SaveIndicator.test.js +0 -101
  218. package/dist/cjs/plugins/floating-toolbar/ui/EmojiPickerButton.test.js +0 -98
  219. package/dist/cjs/plugins/media/commands/captions.test.js +0 -149
  220. package/dist/cjs/plugins/media/commands/linking.test.js +0 -296
  221. package/dist/cjs/plugins/media/ui/CaptionPlaceholder/index.test.js +0 -50
  222. package/dist/cjs/plugins/panel/toolbar.test.js +0 -250
  223. package/dist/cjs/ui/ColorPickerButton/index.test.js +0 -123
  224. package/dist/cjs/ui/PortalProvider/index.test.js +0 -139
  225. package/dist/es2019/plugins/caption/nodeviews/index.test.js +0 -122
  226. package/dist/es2019/plugins/caption/pm-plugins/keymap.test.js +0 -193
  227. package/dist/es2019/plugins/caption/pm-plugins/main.test.js +0 -132
  228. package/dist/es2019/plugins/code-block/language-list.test.js +0 -69
  229. package/dist/es2019/plugins/extension/ui/SaveIndicator/SaveIndicator.test.js +0 -83
  230. package/dist/es2019/plugins/floating-toolbar/ui/EmojiPickerButton.test.js +0 -85
  231. package/dist/es2019/plugins/media/commands/captions.test.js +0 -126
  232. package/dist/es2019/plugins/media/commands/linking.test.js +0 -208
  233. package/dist/es2019/plugins/media/ui/CaptionPlaceholder/index.test.js +0 -41
  234. package/dist/es2019/plugins/panel/toolbar.test.js +0 -200
  235. package/dist/es2019/ui/ColorPickerButton/index.test.js +0 -88
  236. package/dist/es2019/ui/PortalProvider/index.test.js +0 -115
  237. package/dist/esm/plugins/caption/nodeviews/index.test.js +0 -125
  238. package/dist/esm/plugins/caption/pm-plugins/keymap.test.js +0 -195
  239. package/dist/esm/plugins/caption/pm-plugins/main.test.js +0 -124
  240. package/dist/esm/plugins/code-block/language-list.test.js +0 -71
  241. package/dist/esm/plugins/extension/ui/SaveIndicator/SaveIndicator.test.js +0 -92
  242. package/dist/esm/plugins/floating-toolbar/ui/EmojiPickerButton.test.js +0 -85
  243. package/dist/esm/plugins/media/commands/captions.test.js +0 -135
  244. package/dist/esm/plugins/media/commands/linking.test.js +0 -268
  245. package/dist/esm/plugins/media/ui/CaptionPlaceholder/index.test.js +0 -41
  246. package/dist/esm/plugins/panel/toolbar.test.js +0 -230
  247. package/dist/esm/ui/ColorPickerButton/index.test.js +0 -107
  248. package/dist/esm/ui/PortalProvider/index.test.js +0 -129
@@ -1,230 +0,0 @@
1
- import defaultSchema from '@atlaskit/editor-test-helpers/schema';
2
- import { ProviderFactory } from '@atlaskit/editor-common';
3
- import { getTestEmojiResource } from '@atlaskit/util-data-test/get-test-emoji-resource';
4
- import { getToolbarItems } from './toolbar';
5
- import * as actions from '../panel/actions';
6
- import { DEFAULT_BORDER_COLOR } from '../../ui/ColorPalette/Palettes';
7
- import { createProsemirrorEditorFactory, Preset } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
8
- import panelPlugin from '.';
9
- import { doc, p, panel } from '@atlaskit/editor-test-helpers/doc-builder';
10
- import { PanelType } from '@atlaskit/adf-schema';
11
- import analyticsPlugin from '../analytics';
12
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '../analytics';
13
- import { emojiPluginKey } from '../emoji';
14
-
15
- var dummyFormatMessage = function dummyFormatMessage(messageDescriptor) {
16
- return messageDescriptor.defaultMessage || '';
17
- };
18
-
19
- var changePanelTypespy = jest.spyOn(actions, 'changePanelType');
20
- describe('getToolbarItems', function () {
21
- var providerFactory = new ProviderFactory();
22
- providerFactory.setProvider('emojiProvider', Promise.resolve(getTestEmojiResource()));
23
- var panelPreset = new Preset().add([panelPlugin, {
24
- UNSAFE_allowCustomPanel: true
25
- }]);
26
- var itemsWithCustomPanelEnabled = getToolbarItems(dummyFormatMessage, defaultSchema.nodes.panel, true, providerFactory, PanelType.INFO);
27
- afterEach(function () {
28
- jest.clearAllMocks();
29
- });
30
- it('should return 7 items when isCustomPanelEnabled is false', function () {
31
- var items = getToolbarItems(dummyFormatMessage, defaultSchema.nodes.panel, false, providerFactory);
32
- expect(items).toHaveLength(7);
33
- });
34
- describe('if isCustomPanelEnabled is true', function () {
35
- it('should return 11 items', function () {
36
- expect(itemsWithCustomPanelEnabled).toHaveLength(11);
37
- });
38
- it('should contain emoji and color picker button', function () {
39
- var emojiButton = itemsWithCustomPanelEnabled.find(function (item) {
40
- return item.type === 'select' && item.selectType === 'emoji';
41
- });
42
- var colorButton = itemsWithCustomPanelEnabled.find(function (item) {
43
- return item.type === 'select' && item.selectType === 'color';
44
- });
45
- expect(emojiButton).not.toBeUndefined();
46
- expect(colorButton).not.toBeUndefined();
47
- });
48
- });
49
- describe('custom panel toolbar items', function () {
50
- var createEditor = createProsemirrorEditorFactory();
51
-
52
- var _createEditor = createEditor({
53
- doc: doc(panel({
54
- panelType: 'info'
55
- })(p('{<>}'))),
56
- preset: panelPreset,
57
- providerFactory: providerFactory
58
- }),
59
- editorView = _createEditor.editorView;
60
-
61
- it("should call changePanelType when clicked on emoji picker\n with changed emoji", function () {
62
- var emojiPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
63
- return item.type === 'select' && item.selectType === 'emoji';
64
- });
65
- emojiPickerConfig.onChange(':smiley:')(editorView.state);
66
- expect(changePanelTypespy).toBeCalledWith(PanelType.CUSTOM, {
67
- emoji: ':smiley:'
68
- }, true);
69
- });
70
- it("should call changePanelType when clicked on color picker\n with changed color", function () {
71
- var colorPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
72
- return item.type === 'select' && item.selectType === 'color';
73
- });
74
- colorPickerConfig.onChange({
75
- label: 'Mintie',
76
- value: '#ABF5D1',
77
- border: DEFAULT_BORDER_COLOR
78
- })(editorView.state);
79
- expect(changePanelTypespy).toBeCalledWith(PanelType.CUSTOM, {
80
- color: '#ABF5D1'
81
- }, true);
82
- });
83
- it("should call changePanelType when clicked on remove emoji", function () {
84
- var removeEmojiButton = itemsWithCustomPanelEnabled.find(function (item) {
85
- return item.type === 'button' && item.id === 'editor.panel.removeEmoji';
86
- });
87
- removeEmojiButton.onClick(editorView.state);
88
- expect(changePanelTypespy).toBeCalledWith(PanelType.CUSTOM, {
89
- emoji: undefined
90
- }, true);
91
- });
92
- it("should not call changePanelType when clicked on remove emoji when no emoji in panel", function () {
93
- var _createEditor2 = createEditor({
94
- doc: doc(panel({
95
- panelType: 'custom'
96
- })(p('{<>}'))),
97
- preset: panelPreset,
98
- providerFactory: providerFactory
99
- }),
100
- editorView = _createEditor2.editorView;
101
-
102
- var toolbarItems = getToolbarItems(dummyFormatMessage, defaultSchema.nodes.panel, true, providerFactory, PanelType.CUSTOM);
103
- var removeEmojiButton = toolbarItems.find(function (item) {
104
- return item.type === 'button' && item.id === 'editor.panel.removeEmoji';
105
- });
106
- changePanelTypespy.mockClear();
107
- removeEmojiButton.onClick(editorView.state);
108
- expect(changePanelTypespy).not.toBeCalled();
109
- });
110
- it("should have remove emoji button disabled when focus on panel without emoji", function () {
111
- var toolbarItems = getToolbarItems(dummyFormatMessage, defaultSchema.nodes.panel, true, providerFactory, PanelType.CUSTOM, '#ABF5D1', '');
112
- var removeEmojiButton = toolbarItems.find(function (item) {
113
- return item.type === 'button' && item.id === 'editor.panel.removeEmoji';
114
- });
115
- expect(removeEmojiButton.disabled).toBe(true);
116
- });
117
- it("should have remove emoji button enabled when focus on panel with emoji", function () {
118
- var toolbarItems = getToolbarItems(dummyFormatMessage, defaultSchema.nodes.panel, true, providerFactory, PanelType.CUSTOM, '#ABF5D1', ':smiley:');
119
- var removeEmojiButton = toolbarItems.find(function (item) {
120
- return item.type === 'button' && item.id === 'editor.panel.removeEmoji';
121
- });
122
- expect(removeEmojiButton.disabled).toBe(false);
123
- });
124
- });
125
- describe('analytics for custom panels', function () {
126
- var createEditor = createProsemirrorEditorFactory();
127
- var createAnalyticsEvent = jest.fn(function () {
128
- return {
129
- fire: function fire() {}
130
- };
131
- });
132
- var editorView;
133
- beforeEach(function () {
134
- var _createEditor3 = createEditor({
135
- doc: doc(panel({
136
- panelType: 'info'
137
- })(p('{<>}'))),
138
- preset: panelPreset.add([analyticsPlugin, {
139
- createAnalyticsEvent: createAnalyticsEvent
140
- }]),
141
- providerFactory: providerFactory,
142
- pluginKey: emojiPluginKey
143
- });
144
-
145
- editorView = _createEditor3.editorView;
146
- });
147
- it('Should trigger analytics when background color is changed', function () {
148
- var colorPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
149
- return item.type === 'select' && item.selectType === 'color';
150
- });
151
- colorPickerConfig.onChange({
152
- label: 'Mintie',
153
- value: '#ABF5D1',
154
- border: DEFAULT_BORDER_COLOR
155
- })(editorView.state, editorView.dispatch);
156
- var payload = {
157
- action: ACTION.CHANGED_BACKGROUND_COLOR,
158
- actionSubject: ACTION_SUBJECT.PANEL,
159
- actionSubjectId: ACTION_SUBJECT_ID.PANEL,
160
- attributes: expect.objectContaining({
161
- newColor: '#ABF5D1',
162
- previousColor: '#DEEBFF'
163
- }),
164
- eventType: EVENT_TYPE.TRACK
165
- };
166
- expect(createAnalyticsEvent).toHaveBeenCalledWith(payload);
167
- });
168
- it('Should trigger analytics when Icon is changed', function () {
169
- var emojiPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
170
- return item.type === 'select' && item.selectType === 'emoji';
171
- });
172
- emojiPickerConfig.onChange(':smiley:')(editorView.state, editorView.dispatch);
173
- var payload = {
174
- action: ACTION.CHANGED_ICON,
175
- actionSubject: ACTION_SUBJECT.PANEL,
176
- actionSubjectId: ACTION_SUBJECT_ID.PANEL,
177
- attributes: expect.objectContaining({
178
- newIcon: ':smiley:',
179
- previousIcon: ''
180
- }),
181
- eventType: EVENT_TYPE.TRACK
182
- };
183
- expect(createAnalyticsEvent).toHaveBeenCalledWith(payload);
184
- });
185
- it('Should trigger analytics when Icon is removed', function () {
186
- var removeEmojiButton = itemsWithCustomPanelEnabled.find(function (item) {
187
- return item.type === 'button' && item.id === 'editor.panel.removeEmoji';
188
- });
189
- var emojiPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
190
- return item.type === 'select' && item.selectType === 'emoji';
191
- });
192
- emojiPickerConfig.onChange(':smiley:')(editorView.state, editorView.dispatch);
193
- removeEmojiButton.onClick(editorView.state, editorView.dispatch);
194
- var payload = {
195
- action: ACTION.REMOVE_ICON,
196
- actionSubject: ACTION_SUBJECT.PANEL,
197
- actionSubjectId: ACTION_SUBJECT_ID.PANEL,
198
- attributes: expect.objectContaining({
199
- icon: ':smiley:'
200
- }),
201
- eventType: EVENT_TYPE.TRACK
202
- };
203
- expect(createAnalyticsEvent).nthCalledWith(4, payload);
204
- });
205
- it('Should not fire analytics when the same background color is selected', function () {
206
- var colorPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
207
- return item.type === 'select' && item.selectType === 'color';
208
- });
209
- colorPickerConfig.onChange({
210
- label: 'Mintie',
211
- value: '#ABF5D1',
212
- border: DEFAULT_BORDER_COLOR
213
- })(editorView.state, editorView.dispatch);
214
- colorPickerConfig.onChange({
215
- label: 'Mintie',
216
- value: '#ABF5D1',
217
- border: DEFAULT_BORDER_COLOR
218
- })(editorView.state, editorView.dispatch);
219
- expect(createAnalyticsEvent).toHaveBeenCalledTimes(3);
220
- });
221
- it('Should not fire analtyics when same emoji is selected', function () {
222
- var emojiPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
223
- return item.type === 'select' && item.selectType === 'emoji';
224
- });
225
- emojiPickerConfig.onChange(':smiley:')(editorView.state, editorView.dispatch);
226
- emojiPickerConfig.onChange(':smiley:')(editorView.state, editorView.dispatch);
227
- expect(createAnalyticsEvent).toHaveBeenCalledTimes(3);
228
- });
229
- });
230
- });
@@ -1,107 +0,0 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
- import React from 'react';
4
- import { mountWithIntl } from '@atlaskit/editor-test-helpers/enzyme'; // AFP-2532 TODO: Fix automatic suppressions below
5
- // eslint-disable-next-line @atlassian/tangerine/import/entry-points
6
-
7
- import { colors } from '@atlaskit/theme';
8
- import { DEFAULT_BORDER_COLOR } from '../ColorPalette/Palettes';
9
- import { panelBackgroundPalette } from '../ColorPalette/Palettes/panelBackgroundPalette';
10
- import { mockCreateAnalyticsEvent, mockFire } from '@atlaskit/editor-test-helpers/mock-analytics-next';
11
- import ColorPickerButton from './index';
12
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '../../plugins/analytics/types';
13
- import { editorAnalyticsChannel } from '../../plugins/analytics/consts';
14
- import { act } from 'react-dom/test-utils';
15
- describe('color-picker-button', function () {
16
- var onChangeMock = jest.fn();
17
-
18
- var getWrapper = function getWrapper() {
19
- var placement = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
20
- return mountWithIntl( /*#__PURE__*/React.createElement(ColorPickerButton, {
21
- onChange: onChangeMock,
22
- colorPalette: panelBackgroundPalette,
23
- placement: placement
24
- }));
25
- };
26
-
27
- var selectColor = function selectColor(wrapper, colorLabel) {
28
- // show popup
29
- wrapper.find('button').simulate('click'); // select purple
30
-
31
- wrapper.find('Color').findWhere(function (node) {
32
- return node.prop('label') === colorLabel;
33
- }).find('button').simulate('click');
34
- };
35
-
36
- afterEach(function () {
37
- jest.clearAllMocks();
38
- });
39
- it('should render a button', function () {
40
- var wrapper = getWrapper();
41
- expect(wrapper.find('button')).toHaveLength(1); // ensure no popup is rendered
42
-
43
- expect(wrapper.find('Popup')).toHaveLength(0);
44
- });
45
- it('should show a ColorPalette popup after clicking button', function () {
46
- var wrapper = getWrapper(); // show the popup
47
-
48
- wrapper.find('button').simulate('click');
49
- expect(wrapper.find('Popup')).toHaveLength(1);
50
- expect(wrapper.find('ColorPalette')).toHaveLength(1);
51
- expect(wrapper.find('Color')).toHaveLength(21);
52
- });
53
- it('should close ColorPalette popup after clicking outside', function () {
54
- var wrapper = getWrapper(); // show the popup
55
-
56
- wrapper.find('button').simulate('click'); // make sure the popup and picker are shown
57
-
58
- expect(wrapper.find('Popup')).toHaveLength(1);
59
- var colorPalette = wrapper.find('InjectIntl(ColorPalette)').instance();
60
- act(function () {
61
- colorPalette.props.handleClickOutside();
62
- });
63
- wrapper.update(); // make sure popup is hidden
64
-
65
- expect(wrapper.find('Popup')).toHaveLength(0);
66
- });
67
- it('should hide popup and call onChange after selecting a color', function () {
68
- var wrapper = getWrapper();
69
- selectColor(wrapper, 'Mintie'); // ensure popup is hidden
70
-
71
- expect(wrapper.find('Popup')).toHaveLength(0); // ensure callback was called
72
-
73
- expect(onChangeMock).toBeCalledWith({
74
- label: 'Mintie',
75
- value: colors.G75,
76
- border: DEFAULT_BORDER_COLOR
77
- });
78
- });
79
- it('analytics', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
80
- var wrapper;
81
- return _regeneratorRuntime.wrap(function _callee$(_context) {
82
- while (1) {
83
- switch (_context.prev = _context.next) {
84
- case 0:
85
- wrapper = getWrapper('ConfigPanel');
86
- selectColor(wrapper, 'Doctor');
87
- expect(mockCreateAnalyticsEvent).toHaveBeenCalledWith({
88
- action: ACTION.UPDATED,
89
- actionSubject: ACTION_SUBJECT.PICKER,
90
- actionSubjectId: ACTION_SUBJECT_ID.PICKER_COLOR,
91
- attributes: {
92
- color: '#FFFFFF',
93
- label: 'Doctor',
94
- placement: 'ConfigPanel'
95
- },
96
- eventType: EVENT_TYPE.TRACK
97
- });
98
- expect(mockFire).toHaveBeenCalledWith(editorAnalyticsChannel);
99
-
100
- case 4:
101
- case "end":
102
- return _context.stop();
103
- }
104
- }
105
- }, _callee);
106
- })));
107
- });
@@ -1,129 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
- 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; }
4
-
5
- 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; }
6
-
7
- jest.mock('react-dom', function () {
8
- return _objectSpread(_objectSpread({}, jest.requireActual('react-dom')), {}, {
9
- unmountComponentAtNode: jest.fn()
10
- });
11
- });
12
- import React from 'react';
13
- import { unmountComponentAtNode } from 'react-dom';
14
- import { mount } from 'enzyme';
15
- import { AnalyticsListener, useAnalyticsEvents } from '@atlaskit/analytics-next';
16
- import { PortalProvider, PortalRenderer } from './';
17
- import { ContextAdapter } from '../../nodeviews/context-adapter';
18
-
19
- var Component = function Component() {
20
- return /*#__PURE__*/React.createElement("div", {
21
- className: "component"
22
- }, "My component");
23
- };
24
-
25
- var Component2 = function Component2() {
26
- var _useAnalyticsEvents = useAnalyticsEvents(),
27
- createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
28
-
29
- var event = createAnalyticsEvent({});
30
- event.fire('portalprovidertest');
31
- return /*#__PURE__*/React.createElement("div", null, "Component 2");
32
- };
33
-
34
- var ComponentWithAnalytics = function ComponentWithAnalytics() {
35
- return /*#__PURE__*/React.createElement(Component2, null);
36
- };
37
-
38
- describe('PortalProvider', function () {
39
- var portalProviderAPI;
40
- var wrapper;
41
- var place;
42
- var place2;
43
- var handleAnalyticsEvent;
44
- var handleAnalyticsEventFromContext;
45
-
46
- var initPortalProvider = function initPortalProvider() {
47
- handleAnalyticsEvent = jest.fn();
48
- handleAnalyticsEventFromContext = jest.fn();
49
- wrapper = mount( /*#__PURE__*/React.createElement(AnalyticsListener, {
50
- channel: "portalprovidertest",
51
- onEvent: handleAnalyticsEventFromContext
52
- }, /*#__PURE__*/React.createElement(ContextAdapter, null, /*#__PURE__*/React.createElement(PortalProvider, {
53
- onAnalyticsEvent: handleAnalyticsEvent,
54
- useAnalyticsContext: true,
55
- render: function render(api) {
56
- portalProviderAPI = api;
57
- return /*#__PURE__*/React.createElement(PortalRenderer, {
58
- portalProviderAPI: api
59
- });
60
- }
61
- }))));
62
- portalProviderAPI.render(Component, place);
63
- wrapper.update();
64
- };
65
-
66
- beforeEach(function () {
67
- jest.resetAllMocks();
68
- place = document.body.appendChild(document.createElement('div'));
69
- place.classList.add('place');
70
- place2 = document.body.appendChild(document.createElement('div'));
71
- place2.classList.add('place2');
72
- initPortalProvider();
73
- });
74
- afterEach(function () {
75
- place.parentNode.removeChild(place);
76
- place2.parentNode.removeChild(place2);
77
- });
78
- it('should render a component successfully', function () {
79
- expect(mount( /*#__PURE__*/React.createElement(Component, null)).html()).toEqual(place.innerHTML);
80
- });
81
- it('should render several components successfully', function () {
82
- portalProviderAPI.render(Component, place2);
83
- wrapper.update();
84
- var component = mount( /*#__PURE__*/React.createElement(Component, null));
85
- expect(component.html()).toEqual(place.innerHTML);
86
- expect(component.html()).toEqual(place2.innerHTML);
87
- });
88
- it('should destroy a component successfully', function () {
89
- portalProviderAPI.remove(place);
90
- wrapper.update();
91
- expect(unmountComponentAtNode).toBeCalledWith(place);
92
- });
93
- describe('React throws an error while unmounting child component', function () {
94
- var error = new Error('Something happened...');
95
- beforeEach(function () {
96
- unmountComponentAtNode.mockImplementation(function () {
97
- throw error;
98
- });
99
- });
100
- it('should not throw error', function () {
101
- expect(function () {
102
- return portalProviderAPI.remove(place);
103
- }).not.toThrowError();
104
- });
105
- it('should fire analytics if React throws an error when unmounting', function () {
106
- portalProviderAPI.remove(place);
107
- expect(handleAnalyticsEvent).toHaveBeenCalledWith({
108
- payload: {
109
- action: 'failedToUnmount',
110
- actionSubject: 'editor',
111
- actionSubjectId: 'reactNodeView',
112
- attributes: {
113
- error: error,
114
- domNodes: {
115
- container: 'place',
116
- child: 'component'
117
- }
118
- },
119
- eventType: 'operational'
120
- }
121
- });
122
- });
123
- });
124
- it('should propogate events up from child component', function () {
125
- portalProviderAPI.render(ComponentWithAnalytics, place);
126
- wrapper.update();
127
- expect(handleAnalyticsEventFromContext).toBeCalledTimes(1);
128
- });
129
- });