@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,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
- });