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