@atlaskit/editor-plugin-insert-block 0.1.1 → 0.2.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 (90) hide show
  1. package/.eslintrc.js +26 -0
  2. package/CHANGELOG.md +6 -0
  3. package/dist/cjs/index.js +8 -1
  4. package/dist/cjs/plugin.js +164 -0
  5. package/dist/cjs/types.js +5 -0
  6. package/dist/cjs/ui/ElementBrowser/InsertMenu.js +166 -0
  7. package/dist/cjs/ui/ElementBrowser/types.js +5 -0
  8. package/dist/cjs/ui/ToolbarInsertBlock/block-insert-element-browser.js +42 -0
  9. package/dist/cjs/ui/ToolbarInsertBlock/block-insert-menu-legacy.js +42 -0
  10. package/dist/cjs/ui/ToolbarInsertBlock/block-insert-menu.js +66 -0
  11. package/dist/cjs/ui/ToolbarInsertBlock/create-items.js +217 -0
  12. package/dist/cjs/ui/ToolbarInsertBlock/dropdown-button.js +52 -0
  13. package/dist/cjs/ui/ToolbarInsertBlock/index.js +570 -0
  14. package/dist/cjs/ui/ToolbarInsertBlock/item.js +252 -0
  15. package/dist/cjs/ui/ToolbarInsertBlock/messages.js +12 -0
  16. package/dist/cjs/ui/ToolbarInsertBlock/shallow-equals.js +20 -0
  17. package/dist/cjs/ui/ToolbarInsertBlock/sort-items.js +30 -0
  18. package/dist/cjs/ui/ToolbarInsertBlock/styles.js +11 -0
  19. package/dist/cjs/ui/ToolbarInsertBlock/types.js +5 -0
  20. package/dist/es2019/index.js +1 -1
  21. package/dist/es2019/plugin.js +158 -0
  22. package/dist/es2019/types.js +1 -0
  23. package/dist/es2019/ui/ElementBrowser/InsertMenu.js +153 -0
  24. package/dist/es2019/ui/ElementBrowser/types.js +1 -0
  25. package/dist/es2019/ui/ToolbarInsertBlock/block-insert-element-browser.js +35 -0
  26. package/dist/es2019/ui/ToolbarInsertBlock/block-insert-menu-legacy.js +35 -0
  27. package/dist/es2019/ui/ToolbarInsertBlock/block-insert-menu.js +59 -0
  28. package/dist/es2019/ui/ToolbarInsertBlock/create-items.js +198 -0
  29. package/dist/es2019/ui/ToolbarInsertBlock/dropdown-button.js +39 -0
  30. package/dist/es2019/ui/ToolbarInsertBlock/index.js +562 -0
  31. package/dist/es2019/ui/ToolbarInsertBlock/item.js +202 -0
  32. package/dist/es2019/ui/ToolbarInsertBlock/messages.js +1 -0
  33. package/dist/es2019/ui/ToolbarInsertBlock/shallow-equals.js +8 -0
  34. package/dist/es2019/ui/ToolbarInsertBlock/sort-items.js +22 -0
  35. package/dist/es2019/ui/ToolbarInsertBlock/styles.js +16 -0
  36. package/dist/es2019/ui/ToolbarInsertBlock/types.js +1 -0
  37. package/dist/esm/index.js +1 -1
  38. package/dist/esm/plugin.js +157 -0
  39. package/dist/esm/types.js +1 -0
  40. package/dist/esm/ui/ElementBrowser/InsertMenu.js +160 -0
  41. package/dist/esm/ui/ElementBrowser/types.js +1 -0
  42. package/dist/esm/ui/ToolbarInsertBlock/block-insert-element-browser.js +35 -0
  43. package/dist/esm/ui/ToolbarInsertBlock/block-insert-menu-legacy.js +35 -0
  44. package/dist/esm/ui/ToolbarInsertBlock/block-insert-menu.js +59 -0
  45. package/dist/esm/ui/ToolbarInsertBlock/create-items.js +210 -0
  46. package/dist/esm/ui/ToolbarInsertBlock/dropdown-button.js +44 -0
  47. package/dist/esm/ui/ToolbarInsertBlock/index.js +564 -0
  48. package/dist/esm/ui/ToolbarInsertBlock/item.js +244 -0
  49. package/dist/esm/ui/ToolbarInsertBlock/messages.js +1 -0
  50. package/dist/esm/ui/ToolbarInsertBlock/shallow-equals.js +13 -0
  51. package/dist/esm/ui/ToolbarInsertBlock/sort-items.js +24 -0
  52. package/dist/esm/ui/ToolbarInsertBlock/styles.js +4 -0
  53. package/dist/esm/ui/ToolbarInsertBlock/types.js +1 -0
  54. package/dist/types/index.d.ts +2 -1
  55. package/dist/types/plugin.d.ts +16 -0
  56. package/dist/types/types.d.ts +45 -0
  57. package/dist/types/ui/ElementBrowser/InsertMenu.d.ts +4 -0
  58. package/dist/types/ui/ElementBrowser/types.d.ts +22 -0
  59. package/dist/types/ui/ToolbarInsertBlock/block-insert-element-browser.d.ts +28 -0
  60. package/dist/types/ui/ToolbarInsertBlock/block-insert-menu-legacy.d.ts +21 -0
  61. package/dist/types/ui/ToolbarInsertBlock/block-insert-menu.d.ts +33 -0
  62. package/dist/types/ui/ToolbarInsertBlock/create-items.d.ts +39 -0
  63. package/dist/types/ui/ToolbarInsertBlock/dropdown-button.d.ts +16 -0
  64. package/dist/types/ui/ToolbarInsertBlock/index.d.ts +46 -0
  65. package/dist/types/ui/ToolbarInsertBlock/item.d.ts +35 -0
  66. package/dist/types/ui/ToolbarInsertBlock/messages.d.ts +1 -0
  67. package/dist/types/ui/ToolbarInsertBlock/shallow-equals.d.ts +1 -0
  68. package/dist/types/ui/ToolbarInsertBlock/sort-items.d.ts +2 -0
  69. package/dist/types/ui/ToolbarInsertBlock/styles.d.ts +1 -0
  70. package/dist/types/ui/ToolbarInsertBlock/types.d.ts +59 -0
  71. package/dist/types-ts4.5/index.d.ts +2 -1
  72. package/dist/types-ts4.5/plugin.d.ts +16 -0
  73. package/dist/types-ts4.5/types.d.ts +45 -0
  74. package/dist/types-ts4.5/ui/ElementBrowser/InsertMenu.d.ts +4 -0
  75. package/dist/types-ts4.5/ui/ElementBrowser/types.d.ts +22 -0
  76. package/dist/types-ts4.5/ui/ToolbarInsertBlock/block-insert-element-browser.d.ts +28 -0
  77. package/dist/types-ts4.5/ui/ToolbarInsertBlock/block-insert-menu-legacy.d.ts +21 -0
  78. package/dist/types-ts4.5/ui/ToolbarInsertBlock/block-insert-menu.d.ts +33 -0
  79. package/dist/types-ts4.5/ui/ToolbarInsertBlock/create-items.d.ts +42 -0
  80. package/dist/types-ts4.5/ui/ToolbarInsertBlock/dropdown-button.d.ts +16 -0
  81. package/dist/types-ts4.5/ui/ToolbarInsertBlock/index.d.ts +46 -0
  82. package/dist/types-ts4.5/ui/ToolbarInsertBlock/item.d.ts +35 -0
  83. package/dist/types-ts4.5/ui/ToolbarInsertBlock/messages.d.ts +1 -0
  84. package/dist/types-ts4.5/ui/ToolbarInsertBlock/shallow-equals.d.ts +1 -0
  85. package/dist/types-ts4.5/ui/ToolbarInsertBlock/sort-items.d.ts +2 -0
  86. package/dist/types-ts4.5/ui/ToolbarInsertBlock/styles.d.ts +1 -0
  87. package/dist/types-ts4.5/ui/ToolbarInsertBlock/types.d.ts +59 -0
  88. package/package.json +37 -9
  89. package/report.api.md +82 -1
  90. package/tmp/api-report-tmp.d.ts +76 -0
@@ -0,0 +1,562 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ /** @jsx jsx */
3
+ import React from 'react';
4
+ import { jsx } from '@emotion/react';
5
+ import ReactDOM from 'react-dom';
6
+ import { injectIntl } from 'react-intl-next';
7
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
8
+ import { buttonGroupStyle, separatorStyles, wrapperStyle } from '@atlaskit/editor-common/styles';
9
+ import { Popup } from '@atlaskit/editor-common/ui';
10
+ import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
11
+ import { withReactEditorViewOuterListeners as withOuterListeners } from '@atlaskit/editor-common/ui-react';
12
+ import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
13
+ import { EmojiPicker as AkEmojiPicker } from '@atlaskit/emoji/picker';
14
+ import { BlockInsertMenu } from './block-insert-menu';
15
+ import { createItems } from './create-items';
16
+ import { messages } from './messages';
17
+ /**
18
+ * Checks if an element is detached (i.e. not in the current document)
19
+ */
20
+ const isDetachedElement = el => !document.body.contains(el);
21
+ const noop = () => {};
22
+ const EmojiPickerWithListeners = withOuterListeners(AkEmojiPicker);
23
+
24
+ // eslint-disable-next-line @repo/internal/react/no-class-components
25
+ export class ToolbarInsertBlock extends React.PureComponent {
26
+ constructor(...args) {
27
+ super(...args);
28
+ _defineProperty(this, "state", {
29
+ isPlusMenuOpen: false,
30
+ emojiPickerOpen: false,
31
+ isOpenedByKeyboard: false,
32
+ buttons: [],
33
+ dropdownItems: []
34
+ });
35
+ _defineProperty(this, "onOpenChange", attrs => {
36
+ const state = {
37
+ isPlusMenuOpen: attrs.isPlusMenuOpen,
38
+ emojiPickerOpen: this.state.emojiPickerOpen
39
+ };
40
+ if (this.state.emojiPickerOpen && !attrs.open) {
41
+ state.emojiPickerOpen = false;
42
+ }
43
+ this.setState(state, () => {
44
+ const {
45
+ dispatchAnalyticsEvent
46
+ } = this.props;
47
+ if (!dispatchAnalyticsEvent) {
48
+ return;
49
+ }
50
+ const {
51
+ isPlusMenuOpen
52
+ } = this.state;
53
+ if (isPlusMenuOpen) {
54
+ return dispatchAnalyticsEvent({
55
+ action: ACTION.OPENED,
56
+ actionSubject: ACTION_SUBJECT.PLUS_MENU,
57
+ eventType: EVENT_TYPE.UI
58
+ });
59
+ }
60
+ return dispatchAnalyticsEvent({
61
+ action: ACTION.CLOSED,
62
+ actionSubject: ACTION_SUBJECT.PLUS_MENU,
63
+ eventType: EVENT_TYPE.UI
64
+ });
65
+ });
66
+ });
67
+ _defineProperty(this, "togglePlusMenuVisibility", event => {
68
+ const {
69
+ isPlusMenuOpen
70
+ } = this.state;
71
+ this.onOpenChange({
72
+ isPlusMenuOpen: !isPlusMenuOpen
73
+ });
74
+ if ((event === null || event === void 0 ? void 0 : event.key) === 'Escape') {
75
+ var _ref;
76
+ (_ref = this.plusButtonRef || this.dropdownButtonRef) === null || _ref === void 0 ? void 0 : _ref.focus();
77
+ }
78
+ });
79
+ _defineProperty(this, "toggleEmojiPicker", (inputMethod = INPUT_METHOD.TOOLBAR) => {
80
+ this.setState(prevState => ({
81
+ emojiPickerOpen: !prevState.emojiPickerOpen
82
+ }), () => {
83
+ if (this.state.emojiPickerOpen) {
84
+ const {
85
+ dispatchAnalyticsEvent
86
+ } = this.props;
87
+ if (dispatchAnalyticsEvent) {
88
+ dispatchAnalyticsEvent({
89
+ action: ACTION.OPENED,
90
+ actionSubject: ACTION_SUBJECT.PICKER,
91
+ actionSubjectId: ACTION_SUBJECT_ID.PICKER_EMOJI,
92
+ attributes: {
93
+ inputMethod
94
+ },
95
+ eventType: EVENT_TYPE.UI
96
+ });
97
+ }
98
+ }
99
+ });
100
+ });
101
+ _defineProperty(this, "handleEmojiPressEscape", () => {
102
+ var _this$emojiButtonRef;
103
+ this.toggleEmojiPicker(INPUT_METHOD.KEYBOARD);
104
+ (_this$emojiButtonRef = this.emojiButtonRef) === null || _this$emojiButtonRef === void 0 ? void 0 : _this$emojiButtonRef.focus();
105
+ });
106
+ _defineProperty(this, "handleEmojiClickOutside", e => {
107
+ // Ignore click events for detached elements.
108
+ // Workaround for FS-1322 - where two onClicks fire - one when the upload button is
109
+ // still in the document, and one once it's detached. Does not always occur, and
110
+ // may be a side effect of a react render optimisation
111
+ if (e.target && !isDetachedElement(e.target)) {
112
+ this.toggleEmojiPicker(INPUT_METHOD.TOOLBAR);
113
+ }
114
+ });
115
+ _defineProperty(this, "handleEmojiButtonRef", button => {
116
+ const ref = ReactDOM.findDOMNode(button);
117
+ if (ref) {
118
+ this.emojiButtonRef = ref;
119
+ }
120
+ });
121
+ _defineProperty(this, "handlePlusButtonRef", button => {
122
+ const ref = ReactDOM.findDOMNode(button);
123
+ if (ref) {
124
+ this.plusButtonRef = ref;
125
+ }
126
+ });
127
+ _defineProperty(this, "handleDropDownButtonRef", button => {
128
+ const ref = ReactDOM.findDOMNode(button);
129
+ if (ref) {
130
+ this.dropdownButtonRef = ref;
131
+ }
132
+ });
133
+ _defineProperty(this, "handleClick", () => {
134
+ this.togglePlusMenuVisibility();
135
+ });
136
+ _defineProperty(this, "handleOpenByKeyboard", event => {
137
+ if (event.key === 'Enter' || event.key === ' ') {
138
+ this.setState({
139
+ ...this.state,
140
+ isOpenedByKeyboard: true
141
+ });
142
+ event.preventDefault();
143
+ this.togglePlusMenuVisibility();
144
+ }
145
+ });
146
+ _defineProperty(this, "toggleLinkPanel", inputMethod => {
147
+ var _pluginInjectionApi$c, _pluginInjectionApi$h;
148
+ const {
149
+ pluginInjectionApi
150
+ } = this.props;
151
+ return (_pluginInjectionApi$c = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$h = pluginInjectionApi.hyperlink) === null || _pluginInjectionApi$h === void 0 ? void 0 : _pluginInjectionApi$h.commands.showLinkToolbar(inputMethod))) !== null && _pluginInjectionApi$c !== void 0 ? _pluginInjectionApi$c : false;
152
+ });
153
+ _defineProperty(this, "insertMention", inputMethod => {
154
+ var _pluginInjectionApi$m, _pluginInjectionApi$m2, _pluginInjectionApi$m3;
155
+ const {
156
+ editorView,
157
+ pluginInjectionApi
158
+ } = this.props;
159
+ if (!editorView) {
160
+ return true;
161
+ }
162
+ const pluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$m = pluginInjectionApi.mention) === null || _pluginInjectionApi$m === void 0 ? void 0 : _pluginInjectionApi$m.sharedState.currentState();
163
+ if (pluginState && pluginState.canInsertMention === false) {
164
+ return false;
165
+ }
166
+ return Boolean(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$m2 = pluginInjectionApi.mention) === null || _pluginInjectionApi$m2 === void 0 ? void 0 : (_pluginInjectionApi$m3 = _pluginInjectionApi$m2.actions) === null || _pluginInjectionApi$m3 === void 0 ? void 0 : _pluginInjectionApi$m3.openTypeAhead(inputMethod));
167
+ });
168
+ _defineProperty(this, "insertTable", inputMethod => {
169
+ var _pluginInjectionApi$t, _pluginInjectionApi$t2, _pluginInjectionApi$t3, _pluginInjectionApi$t4;
170
+ const {
171
+ pluginInjectionApi,
172
+ editorView
173
+ } = this.props;
174
+ const {
175
+ state,
176
+ dispatch
177
+ } = editorView;
178
+ return (_pluginInjectionApi$t = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$t2 = pluginInjectionApi.table) === null || _pluginInjectionApi$t2 === void 0 ? void 0 : (_pluginInjectionApi$t3 = (_pluginInjectionApi$t4 = _pluginInjectionApi$t2.actions).insertTable) === null || _pluginInjectionApi$t3 === void 0 ? void 0 : _pluginInjectionApi$t3.call(_pluginInjectionApi$t4, {
179
+ action: ACTION.INSERTED,
180
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
181
+ actionSubjectId: ACTION_SUBJECT_ID.TABLE,
182
+ attributes: {
183
+ inputMethod
184
+ },
185
+ eventType: EVENT_TYPE.TRACK
186
+ })(state, dispatch)) !== null && _pluginInjectionApi$t !== void 0 ? _pluginInjectionApi$t : false;
187
+ });
188
+ _defineProperty(this, "createDate", inputMethod => {
189
+ var _pluginInjectionApi$d, _pluginInjectionApi$d2;
190
+ const {
191
+ pluginInjectionApi
192
+ } = this.props;
193
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.date) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.commands) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.insertDate({
194
+ inputMethod
195
+ }));
196
+ return true;
197
+ });
198
+ _defineProperty(this, "createPlaceholderText", () => {
199
+ var _pluginInjectionApi$p;
200
+ const {
201
+ editorView,
202
+ pluginInjectionApi
203
+ } = this.props;
204
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$p = pluginInjectionApi.placeholderText) === null || _pluginInjectionApi$p === void 0 ? void 0 : _pluginInjectionApi$p.actions.showPlaceholderFloatingToolbar(editorView.state, editorView.dispatch);
205
+ return true;
206
+ });
207
+ _defineProperty(this, "insertLayoutColumns", inputMethod => {
208
+ var _pluginInjectionApi$l;
209
+ const {
210
+ editorView,
211
+ pluginInjectionApi
212
+ } = this.props;
213
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$l = pluginInjectionApi.layout) === null || _pluginInjectionApi$l === void 0 ? void 0 : _pluginInjectionApi$l.actions.insertLayoutColumns(inputMethod)(editorView.state, editorView.dispatch);
214
+ return true;
215
+ });
216
+ _defineProperty(this, "createStatus", inputMethod => {
217
+ var _pluginInjectionApi$s, _pluginInjectionApi$s2, _pluginInjectionApi$s3;
218
+ const {
219
+ pluginInjectionApi,
220
+ editorView
221
+ } = this.props;
222
+ return (_pluginInjectionApi$s = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$s2 = pluginInjectionApi.status) === null || _pluginInjectionApi$s2 === void 0 ? void 0 : (_pluginInjectionApi$s3 = _pluginInjectionApi$s2.actions) === null || _pluginInjectionApi$s3 === void 0 ? void 0 : _pluginInjectionApi$s3.updateStatus(inputMethod)(editorView.state, editorView.dispatch)) !== null && _pluginInjectionApi$s !== void 0 ? _pluginInjectionApi$s : false;
223
+ });
224
+ _defineProperty(this, "openMediaPicker", inputMethod => {
225
+ const {
226
+ onShowMediaPicker,
227
+ dispatchAnalyticsEvent
228
+ } = this.props;
229
+ if (onShowMediaPicker) {
230
+ onShowMediaPicker();
231
+ if (dispatchAnalyticsEvent) {
232
+ dispatchAnalyticsEvent({
233
+ action: ACTION.OPENED,
234
+ actionSubject: ACTION_SUBJECT.PICKER,
235
+ actionSubjectId: ACTION_SUBJECT_ID.PICKER_CLOUD,
236
+ attributes: {
237
+ inputMethod
238
+ },
239
+ eventType: EVENT_TYPE.UI
240
+ });
241
+ }
242
+ }
243
+ return true;
244
+ });
245
+ _defineProperty(this, "insertTaskDecision", (name, inputMethod) => () => {
246
+ var _pluginInjectionApi$t5, _pluginInjectionApi$t6;
247
+ const {
248
+ editorView: {
249
+ state,
250
+ dispatch
251
+ },
252
+ pluginInjectionApi
253
+ } = this.props;
254
+ const listType = name === 'action' ? 'taskList' : 'decisionList';
255
+ return (_pluginInjectionApi$t5 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$t6 = pluginInjectionApi.taskDecision) === null || _pluginInjectionApi$t6 === void 0 ? void 0 : _pluginInjectionApi$t6.actions.insertTaskDecision(listType, inputMethod)(state, dispatch)) !== null && _pluginInjectionApi$t5 !== void 0 ? _pluginInjectionApi$t5 : false;
256
+ });
257
+ _defineProperty(this, "insertHorizontalRule", inputMethod => {
258
+ var _pluginInjectionApi$r, _pluginInjectionApi$r2;
259
+ const {
260
+ editorView: {
261
+ state,
262
+ dispatch
263
+ },
264
+ pluginInjectionApi
265
+ } = this.props;
266
+ return (_pluginInjectionApi$r = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$r2 = pluginInjectionApi.rule) === null || _pluginInjectionApi$r2 === void 0 ? void 0 : _pluginInjectionApi$r2.actions.insertHorizontalRule(inputMethod)(state, dispatch)) !== null && _pluginInjectionApi$r !== void 0 ? _pluginInjectionApi$r : false;
267
+ });
268
+ _defineProperty(this, "insertExpand", () => {
269
+ var _pluginInjectionApi$e, _pluginInjectionApi$e2;
270
+ const {
271
+ editorView: {
272
+ state,
273
+ dispatch
274
+ },
275
+ pluginInjectionApi
276
+ } = this.props;
277
+ return (_pluginInjectionApi$e = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$e2 = pluginInjectionApi.expand) === null || _pluginInjectionApi$e2 === void 0 ? void 0 : _pluginInjectionApi$e2.actions.insertExpand(state, dispatch)) !== null && _pluginInjectionApi$e !== void 0 ? _pluginInjectionApi$e : false;
278
+ });
279
+ _defineProperty(this, "insertBlockType", itemName => () => {
280
+ const {
281
+ editorView,
282
+ onInsertBlockType
283
+ } = this.props;
284
+ const {
285
+ state,
286
+ dispatch
287
+ } = editorView;
288
+ onInsertBlockType(itemName)(state, dispatch);
289
+ return true;
290
+ });
291
+ _defineProperty(this, "handleSelectedEmoji", emojiId => {
292
+ var _pluginInjectionApi$e3;
293
+ const {
294
+ pluginInjectionApi
295
+ } = this.props;
296
+ this.props.editorView.focus();
297
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.core.actions.execute((_pluginInjectionApi$e3 = pluginInjectionApi.emoji) === null || _pluginInjectionApi$e3 === void 0 ? void 0 : _pluginInjectionApi$e3.commands.insertEmoji(emojiId, INPUT_METHOD.PICKER));
298
+ this.toggleEmojiPicker();
299
+ return true;
300
+ });
301
+ _defineProperty(this, "openElementBrowser", () => {
302
+ var _pluginInjectionApi$q;
303
+ const {
304
+ pluginInjectionApi
305
+ } = this.props;
306
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$q = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q === void 0 ? void 0 : _pluginInjectionApi$q.commands.openElementBrowserModal);
307
+ });
308
+ _defineProperty(this, "onItemActivated", ({
309
+ item,
310
+ inputMethod
311
+ }) => {
312
+ const {
313
+ editorView,
314
+ editorActions,
315
+ handleImageUpload,
316
+ expandEnabled
317
+ } = this.props;
318
+
319
+ // need to do this before inserting nodes so scrollIntoView works properly
320
+ if (!editorView.hasFocus()) {
321
+ editorView.focus();
322
+ }
323
+ switch (item.value.name) {
324
+ case 'link':
325
+ this.toggleLinkPanel(inputMethod);
326
+ break;
327
+ case 'table':
328
+ this.insertTable(inputMethod);
329
+ break;
330
+ case 'image upload':
331
+ if (handleImageUpload) {
332
+ const {
333
+ state,
334
+ dispatch
335
+ } = editorView;
336
+ handleImageUpload()(state, dispatch);
337
+ }
338
+ break;
339
+ case 'media':
340
+ this.openMediaPicker(inputMethod);
341
+ break;
342
+ case 'mention':
343
+ this.insertMention(inputMethod);
344
+ break;
345
+ case 'emoji':
346
+ this.toggleEmojiPicker(inputMethod);
347
+ break;
348
+ case 'codeblock':
349
+ case 'blockquote':
350
+ case 'panel':
351
+ this.insertBlockType(item.value.name)();
352
+ break;
353
+ case 'action':
354
+ case 'decision':
355
+ this.insertTaskDecision(item.value.name, inputMethod)();
356
+ break;
357
+ case 'horizontalrule':
358
+ this.insertHorizontalRule(inputMethod);
359
+ break;
360
+ case 'macro':
361
+ this.openElementBrowser();
362
+ break;
363
+ case 'date':
364
+ this.createDate(inputMethod);
365
+ break;
366
+ case 'placeholder text':
367
+ this.createPlaceholderText();
368
+ break;
369
+ case 'layout':
370
+ this.insertLayoutColumns(inputMethod);
371
+ break;
372
+ case 'status':
373
+ this.createStatus(inputMethod);
374
+ break;
375
+
376
+ // https://product-fabric.atlassian.net/browse/ED-8053
377
+ // @ts-ignore: OK to fallthrough to default
378
+ case 'expand':
379
+ if (expandEnabled) {
380
+ this.insertExpand();
381
+ break;
382
+ }
383
+
384
+ // eslint-disable-next-line no-fallthrough
385
+ default:
386
+ if (item && item.onClick && editorActions) {
387
+ item.onClick(editorActions);
388
+ break;
389
+ }
390
+ }
391
+ this.setState({
392
+ isPlusMenuOpen: false
393
+ });
394
+ });
395
+ _defineProperty(this, "insertToolbarMenuItem", btn => this.onItemActivated({
396
+ item: btn,
397
+ inputMethod: INPUT_METHOD.TOOLBAR
398
+ }));
399
+ _defineProperty(this, "insertInsertMenuItem", ({
400
+ item
401
+ }) => this.onItemActivated({
402
+ item,
403
+ inputMethod: INPUT_METHOD.INSERT_MENU
404
+ }));
405
+ }
406
+ static getDerivedStateFromProps(props, state) {
407
+ const [buttons, dropdownItems] = createItems({
408
+ isTypeAheadAllowed: props.isTypeAheadAllowed,
409
+ tableSupported: props.tableSupported,
410
+ mediaUploadsEnabled: props.mediaUploadsEnabled,
411
+ mediaSupported: props.mediaSupported,
412
+ imageUploadSupported: props.imageUploadSupported,
413
+ imageUploadEnabled: props.imageUploadEnabled,
414
+ mentionsSupported: props.mentionsSupported,
415
+ mentionsDisabled: props.mentionsDisabled,
416
+ actionSupported: props.actionSupported,
417
+ decisionSupported: props.decisionSupported,
418
+ linkSupported: props.linkSupported,
419
+ linkDisabled: props.linkDisabled,
420
+ emojiDisabled: props.emojiDisabled,
421
+ nativeStatusSupported: props.nativeStatusSupported,
422
+ dateEnabled: props.dateEnabled,
423
+ placeholderTextEnabled: props.placeholderTextEnabled,
424
+ horizontalRuleEnabled: props.horizontalRuleEnabled,
425
+ layoutSectionEnabled: props.layoutSectionEnabled,
426
+ expandEnabled: props.expandEnabled,
427
+ showElementBrowserLink: props.showElementBrowserLink,
428
+ emojiProvider: props.emojiProvider,
429
+ availableWrapperBlockTypes: props.availableWrapperBlockTypes,
430
+ insertMenuItems: props.insertMenuItems,
431
+ schema: props.editorView.state.schema,
432
+ numberOfButtons: props.buttons,
433
+ formatMessage: props.intl.formatMessage,
434
+ isNewMenuEnabled: props.replacePlusMenuWithElementBrowser
435
+ });
436
+ return {
437
+ ...state,
438
+ buttons,
439
+ dropdownItems
440
+ };
441
+ }
442
+ componentDidUpdate(prevProps) {
443
+ // If number of visible buttons changed, close emoji picker
444
+ if (prevProps.buttons !== this.props.buttons) {
445
+ this.setState({
446
+ emojiPickerOpen: false
447
+ });
448
+ }
449
+ if (this.state.isOpenedByKeyboard) {
450
+ var _this$dropdownButtonR;
451
+ const downArrowEvent = new KeyboardEvent('keydown', {
452
+ bubbles: true,
453
+ key: 'ArrowDown'
454
+ });
455
+ (_this$dropdownButtonR = this.dropdownButtonRef) === null || _this$dropdownButtonR === void 0 ? void 0 : _this$dropdownButtonR.dispatchEvent(downArrowEvent);
456
+ this.setState({
457
+ ...this.state,
458
+ isOpenedByKeyboard: false
459
+ });
460
+ }
461
+ }
462
+ renderPopup() {
463
+ const {
464
+ emojiPickerOpen
465
+ } = this.state;
466
+ const {
467
+ popupsMountPoint,
468
+ popupsBoundariesElement,
469
+ popupsScrollableElement,
470
+ emojiProvider,
471
+ replacePlusMenuWithElementBrowser
472
+ } = this.props;
473
+ const dropdownEmoji = this.state.dropdownItems.some(({
474
+ value: {
475
+ name
476
+ }
477
+ }) => name === 'emoji');
478
+ const dropDownButtonRef = replacePlusMenuWithElementBrowser ? this.plusButtonRef : this.dropdownButtonRef;
479
+ const ref = dropdownEmoji ? dropDownButtonRef : this.emojiButtonRef;
480
+ if (!emojiPickerOpen || !ref || !emojiProvider) {
481
+ return null;
482
+ }
483
+ return jsx(Popup, {
484
+ target: ref,
485
+ fitHeight: 350,
486
+ fitWidth: 350,
487
+ offset: [0, 3],
488
+ mountTo: popupsMountPoint,
489
+ boundariesElement: popupsBoundariesElement,
490
+ scrollableElement: popupsScrollableElement,
491
+ focusTrap: true,
492
+ zIndex: akEditorMenuZIndex
493
+ }, jsx(EmojiPickerWithListeners, {
494
+ emojiProvider: emojiProvider,
495
+ onSelection: this.handleSelectedEmoji,
496
+ handleClickOutside: this.handleEmojiClickOutside,
497
+ handleEscapeKeydown: this.handleEmojiPressEscape
498
+ }));
499
+ }
500
+ render() {
501
+ var _this$props$isDisable, _this$props$replacePl;
502
+ const {
503
+ buttons,
504
+ dropdownItems,
505
+ emojiPickerOpen
506
+ } = this.state;
507
+ const {
508
+ isDisabled,
509
+ isReducedSpacing
510
+ } = this.props;
511
+ if (buttons.length === 0 && dropdownItems.length === 0) {
512
+ return null;
513
+ }
514
+ return (
515
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
516
+ jsx("span", {
517
+ css: buttonGroupStyle
518
+ }, buttons.map(btn => jsx(ToolbarButton, {
519
+ item: btn,
520
+ testId: String(btn.content),
521
+ ref: btn.value.name === 'emoji' ? this.handleEmojiButtonRef : noop,
522
+ key: btn.value.name,
523
+ spacing: isReducedSpacing ? 'none' : 'default',
524
+ disabled: isDisabled || btn.isDisabled,
525
+ iconBefore: btn.elemBefore,
526
+ selected: btn.value.name === 'emoji' && emojiPickerOpen || btn.isActive,
527
+ title: btn.title,
528
+ "aria-label": btn['aria-label'],
529
+ "aria-haspopup": btn['aria-haspopup'],
530
+ "aria-keyshortcuts": btn['aria-keyshortcuts'],
531
+ onItemClick: this.insertToolbarMenuItem
532
+ })), jsx("span", {
533
+ css: wrapperStyle
534
+ }, this.renderPopup(), jsx(BlockInsertMenu, {
535
+ popupsMountPoint: this.props.popupsMountPoint,
536
+ popupsBoundariesElement: this.props.popupsBoundariesElement,
537
+ popupsScrollableElement: this.props.popupsScrollableElement,
538
+ disabled: (_this$props$isDisable = this.props.isDisabled) !== null && _this$props$isDisable !== void 0 ? _this$props$isDisable : false,
539
+ editorView: this.props.editorView,
540
+ spacing: this.props.isReducedSpacing ? 'none' : 'default',
541
+ label: this.props.intl.formatMessage(messages.insertMenu),
542
+ open: this.state.isPlusMenuOpen,
543
+ plusButtonRef: this.plusButtonRef,
544
+ items: this.state.dropdownItems,
545
+ onRef: this.handleDropDownButtonRef,
546
+ onPlusButtonRef: this.handlePlusButtonRef,
547
+ onClick: this.handleClick,
548
+ onKeyDown: this.handleOpenByKeyboard,
549
+ onItemActivated: this.insertInsertMenuItem,
550
+ onInsert: this.insertInsertMenuItem,
551
+ onOpenChange: this.onOpenChange,
552
+ togglePlusMenuVisibility: this.togglePlusMenuVisibility,
553
+ replacePlusMenuWithElementBrowser: (_this$props$replacePl = this.props.replacePlusMenuWithElementBrowser) !== null && _this$props$replacePl !== void 0 ? _this$props$replacePl : false,
554
+ showElementBrowserLink: this.props.showElementBrowserLink || false,
555
+ pluginInjectionApi: this.props.pluginInjectionApi
556
+ })), this.props.showSeparator && jsx("span", {
557
+ css: separatorStyles
558
+ }))
559
+ );
560
+ }
561
+ }
562
+ export default injectIntl(ToolbarInsertBlock);