@atlaskit/editor-core 189.4.0 → 189.4.1

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