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