@atlaskit/editor-plugin-insert-block 0.1.1 → 0.2.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 (90) hide show
  1. package/.eslintrc.js +26 -0
  2. package/CHANGELOG.md +12 -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 +169 -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 +156 -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 +163 -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 +0 -9
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.table = exports.status = exports.placeholder = exports.panel = exports.more = exports.mention = exports.media = exports.link = exports.layout = exports.imageUpload = exports.horizontalrule = exports.expand = exports.emoji = exports.decision = exports.date = exports.codeblock = exports.blockquote = exports.action = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _react2 = require("@emotion/react");
10
+ var _memoizeOne = _interopRequireDefault(require("memoize-one"));
11
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
12
+ var _shortcut = require("@atlaskit/editor-shared-styles/shortcut");
13
+ var _chevronRightCircle = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-right-circle"));
14
+ var _code = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/code"));
15
+ var _date = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/date"));
16
+ var _decision = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/decision"));
17
+ var _emoji = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/emoji"));
18
+ var _horizontalRule = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/horizontal-rule"));
19
+ var _image = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/image"));
20
+ var _info = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/info"));
21
+ var _layoutTwoEqual = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/layout-two-equal"));
22
+ var _link = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/link"));
23
+ var _mention = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/mention"));
24
+ var _more = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/more"));
25
+ var _table = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/table"));
26
+ var _task = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/task"));
27
+ var _text = _interopRequireDefault(require("@atlaskit/icon/glyph/media-services/text"));
28
+ var _quote = _interopRequireDefault(require("@atlaskit/icon/glyph/quote"));
29
+ var _status = _interopRequireDefault(require("@atlaskit/icon/glyph/status"));
30
+ var _shallowEquals = require("./shallow-equals");
31
+ /** @jsx jsx */
32
+
33
+ var from = function from(init) {
34
+ return {
35
+ content: init.content,
36
+ tooltipDescription: init.tooltipDescription,
37
+ value: {
38
+ name: init.name
39
+ },
40
+ elemBefore: (0, _react2.jsx)(init.Icon, {
41
+ label: init.content
42
+ }),
43
+ elemAfter: init.shortcut ?
44
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
45
+ (0, _react2.jsx)("div", {
46
+ css: _shortcut.shortcutStyle
47
+ }, init.shortcut) : undefined,
48
+ 'aria-label': init.shortcut ? init.content + ' ' + init.shortcut : init.content,
49
+ 'aria-haspopup': init['aria-haspopup'],
50
+ 'aria-keyshortcuts': init['aria-keyshortcuts'],
51
+ shortcut: init.shortcut,
52
+ isDisabled: init.disabled
53
+ };
54
+ };
55
+ var mem = function mem(fn) {
56
+ return (0, _memoizeOne.default)(fn, _shallowEquals.shallowEquals);
57
+ };
58
+ var action = exports.action = mem(function (init) {
59
+ return from({
60
+ content: init.content,
61
+ tooltipDescription: init.tooltipDescription,
62
+ disabled: init.disabled,
63
+ name: 'action',
64
+ shortcut: '[]',
65
+ Icon: _task.default,
66
+ 'aria-keyshortcuts': '[ ] Space'
67
+ });
68
+ });
69
+ var link = exports.link = mem(function (init) {
70
+ return from({
71
+ content: init.content,
72
+ tooltipDescription: init.tooltipDescription,
73
+ disabled: init.disabled,
74
+ name: 'link',
75
+ shortcut: (0, _keymaps.tooltip)(_keymaps.addLink),
76
+ Icon: _link.default,
77
+ 'aria-haspopup': init['aria-haspopup'],
78
+ 'aria-keyshortcuts': (0, _keymaps.getAriaKeyshortcuts)(_keymaps.addLink)
79
+ });
80
+ });
81
+ var media = exports.media = mem(function (init) {
82
+ return from({
83
+ content: init.content,
84
+ tooltipDescription: init.tooltipDescription,
85
+ disabled: init.disabled,
86
+ name: 'media',
87
+ Icon: _image.default
88
+ });
89
+ });
90
+ var imageUpload = exports.imageUpload = mem(function (init) {
91
+ return from({
92
+ content: init.content,
93
+ tooltipDescription: init.tooltipDescription,
94
+ disabled: init.disabled,
95
+ name: 'image upload',
96
+ Icon: _image.default
97
+ });
98
+ });
99
+ var mention = exports.mention = mem(function (init) {
100
+ return from({
101
+ content: init.content,
102
+ tooltipDescription: init.tooltipDescription,
103
+ disabled: init.disabled,
104
+ name: 'mention',
105
+ Icon: _mention.default,
106
+ shortcut: '@',
107
+ 'aria-haspopup': init['aria-haspopup'],
108
+ 'aria-keyshortcuts': 'Shift+2 Space'
109
+ });
110
+ });
111
+ var emoji = exports.emoji = mem(function (init) {
112
+ return from({
113
+ content: init.content,
114
+ tooltipDescription: init.tooltipDescription,
115
+ disabled: init.disabled,
116
+ name: 'emoji',
117
+ Icon: _emoji.default,
118
+ shortcut: ':',
119
+ 'aria-haspopup': init['aria-haspopup'],
120
+ 'aria-keyshortcuts': 'Shift+;'
121
+ });
122
+ });
123
+ var table = exports.table = mem(function (init) {
124
+ return from({
125
+ content: init.content,
126
+ tooltipDescription: init.tooltipDescription,
127
+ disabled: init.disabled,
128
+ name: 'table',
129
+ Icon: _table.default,
130
+ shortcut: (0, _keymaps.tooltip)(_keymaps.toggleTable),
131
+ 'aria-keyshortcuts': (0, _keymaps.getAriaKeyshortcuts)(_keymaps.toggleTable)
132
+ });
133
+ });
134
+ var layout = exports.layout = mem(function (init) {
135
+ return from({
136
+ content: init.content,
137
+ tooltipDescription: init.tooltipDescription,
138
+ disabled: init.disabled,
139
+ name: 'layout',
140
+ Icon: _layoutTwoEqual.default
141
+ });
142
+ });
143
+ var codeblock = exports.codeblock = mem(function (init) {
144
+ return from({
145
+ content: init.content,
146
+ tooltipDescription: init.tooltipDescription,
147
+ disabled: init.disabled,
148
+ name: 'codeblock',
149
+ Icon: _code.default,
150
+ shortcut: init.shortcut,
151
+ 'aria-keyshortcuts': (0, _keymaps.getAriaKeyshortcuts)(init.shortcut)
152
+ });
153
+ });
154
+ var panel = exports.panel = mem(function (init) {
155
+ return from({
156
+ content: init.content,
157
+ tooltipDescription: init.tooltipDescription,
158
+ disabled: init.disabled,
159
+ name: 'panel',
160
+ Icon: _info.default,
161
+ shortcut: init.shortcut,
162
+ 'aria-keyshortcuts': (0, _keymaps.getAriaKeyshortcuts)(init.shortcut)
163
+ });
164
+ });
165
+ var blockquote = exports.blockquote = mem(function (init) {
166
+ return from({
167
+ content: init.content,
168
+ tooltipDescription: init.tooltipDescription,
169
+ disabled: init.disabled,
170
+ name: 'blockquote',
171
+ Icon: _quote.default,
172
+ shortcut: init.shortcut,
173
+ 'aria-keyshortcuts': 'Shift+. Space'
174
+ });
175
+ });
176
+ var decision = exports.decision = mem(function (init) {
177
+ return from({
178
+ content: init.content,
179
+ tooltipDescription: init.tooltipDescription,
180
+ disabled: init.disabled,
181
+ name: 'decision',
182
+ Icon: _decision.default,
183
+ shortcut: '<>',
184
+ 'aria-keyshortcuts': 'Shift+, Shift+. Space'
185
+ });
186
+ });
187
+ var horizontalrule = exports.horizontalrule = mem(function (init) {
188
+ return from({
189
+ content: init.content,
190
+ tooltipDescription: init.tooltipDescription,
191
+ disabled: init.disabled,
192
+ name: 'horizontalrule',
193
+ Icon: _horizontalRule.default,
194
+ shortcut: '---',
195
+ 'aria-keyshortcuts': '- - -'
196
+ });
197
+ });
198
+ var expand = exports.expand = mem(function (init) {
199
+ return from({
200
+ content: init.content,
201
+ tooltipDescription: init.tooltipDescription,
202
+ disabled: init.disabled,
203
+ name: 'expand',
204
+ Icon: _chevronRightCircle.default
205
+ });
206
+ });
207
+ var date = exports.date = mem(function (init) {
208
+ return from({
209
+ content: init.content,
210
+ tooltipDescription: init.tooltipDescription,
211
+ disabled: init.disabled,
212
+ name: 'date',
213
+ Icon: _date.default,
214
+ shortcut: '//',
215
+ 'aria-keyshortcuts': '/ / Enter'
216
+ });
217
+ });
218
+ var placeholder = exports.placeholder = mem(function (init) {
219
+ return from({
220
+ content: init.content,
221
+ tooltipDescription: init.tooltipDescription,
222
+ disabled: init.disabled,
223
+ name: 'placeholder text',
224
+ Icon: function Icon() {
225
+ return (0, _react2.jsx)(_text.default, {
226
+ label: ""
227
+ });
228
+ }
229
+ });
230
+ });
231
+ var status = exports.status = mem(function (init) {
232
+ return from({
233
+ content: init.content,
234
+ tooltipDescription: init.tooltipDescription,
235
+ disabled: init.disabled,
236
+ name: 'status',
237
+ Icon: _status.default
238
+ });
239
+ });
240
+ var more = exports.more = mem(function (init) {
241
+ return from({
242
+ content: init.content,
243
+ tooltipDescription: init.tooltipDescription,
244
+ disabled: init.disabled,
245
+ name: 'macro',
246
+ Icon: function Icon() {
247
+ return (0, _react2.jsx)(_more.default, {
248
+ label: ""
249
+ });
250
+ }
251
+ });
252
+ });
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "messages", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _messages.toolbarInsertBlockMessages;
10
+ }
11
+ });
12
+ var _messages = require("@atlaskit/editor-common/messages");
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.shallowEquals = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var shallowEquals = exports.shallowEquals = function shallowEquals(_ref, _ref2) {
10
+ var _ref3 = (0, _slicedToArray2.default)(_ref, 1),
11
+ aRaw = _ref3[0];
12
+ var _ref4 = (0, _slicedToArray2.default)(_ref2, 1),
13
+ bRaw = _ref4[0];
14
+ var a = aRaw;
15
+ var b = bRaw;
16
+ return !Object.keys(a).some(function (key) {
17
+ var k = key;
18
+ return a[k] !== b[k];
19
+ });
20
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sortItems = void 0;
7
+ var endPositionNames = ['macro-browser', 'slash-onboarding'];
8
+ var isMacro = function isMacro(item) {
9
+ return typeof item.content === 'string' && item.content.includes('macro');
10
+ };
11
+ var sortItems = exports.sortItems = function sortItems(items) {
12
+ return items.sort(function (a, b) {
13
+ if (endPositionNames.includes(a.value.name) && endPositionNames.includes(b.value.name)) {
14
+ return endPositionNames.indexOf(a.value.name) - endPositionNames.indexOf(b.value.name);
15
+ }
16
+ if (endPositionNames.includes(b.value.name)) {
17
+ return -1;
18
+ }
19
+ if (endPositionNames.includes(a.value.name)) {
20
+ return 1;
21
+ }
22
+ if (isMacro(a) && !isMacro(b)) {
23
+ return 1;
24
+ }
25
+ if (isMacro(b) && !isMacro(a)) {
26
+ return -1;
27
+ }
28
+ return a.content < b.content ? -1 : 1;
29
+ });
30
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.triggerWrapper = void 0;
8
+ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
9
+ var _react = require("@emotion/react");
10
+ var _templateObject;
11
+ var triggerWrapper = exports.triggerWrapper = (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n width: 42px;\n\n display: flex;\n align-items: center;\n\n > div,\n > span {\n display: flex;\n }\n\n > div > div {\n display: flex;\n }\n"])));
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -1 +1 @@
1
- export {};
1
+ export { insertBlockPlugin } from './plugin';
@@ -0,0 +1,158 @@
1
+ import React from 'react';
2
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
+ import { WithProviders } from '@atlaskit/editor-common/provider-factory';
5
+ import { ToolbarSize } from '@atlaskit/editor-common/types';
6
+ import { BLOCK_QUOTE, CODE_BLOCK, PANEL } from '@atlaskit/editor-plugin-block-type/consts';
7
+ import ToolbarInsertBlock from './ui/ToolbarInsertBlock';
8
+ const toolbarSizeToButtons = toolbarSize => {
9
+ switch (toolbarSize) {
10
+ case ToolbarSize.XXL:
11
+ case ToolbarSize.XL:
12
+ case ToolbarSize.L:
13
+ case ToolbarSize.M:
14
+ return 7;
15
+ case ToolbarSize.S:
16
+ return 2;
17
+ default:
18
+ return 0;
19
+ }
20
+ };
21
+ /**
22
+ * Wrapper over insertBlockTypeWithAnalytics to autobind toolbar input method
23
+ * @param name Block name
24
+ */
25
+ function handleInsertBlockType(insertCodeBlock, insertPanel, insertBlockQuote) {
26
+ return name => {
27
+ if (name === CODE_BLOCK.name && insertCodeBlock) {
28
+ return insertCodeBlock(INPUT_METHOD.TOOLBAR);
29
+ }
30
+ if (name === PANEL.name && insertPanel) {
31
+ return insertPanel(INPUT_METHOD.TOOLBAR);
32
+ }
33
+ if (name === BLOCK_QUOTE.name && insertBlockQuote) {
34
+ return insertBlockQuote(INPUT_METHOD.TOOLBAR);
35
+ }
36
+ return () => false;
37
+ };
38
+ }
39
+ export const insertBlockPlugin = ({
40
+ config: options = {},
41
+ api
42
+ }) => {
43
+ var _api$featureFlags;
44
+ const featureFlags = (api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
45
+ return {
46
+ name: 'insertBlock',
47
+ primaryToolbarComponent({
48
+ editorView,
49
+ editorActions,
50
+ dispatchAnalyticsEvent,
51
+ providerFactory,
52
+ popupsMountPoint,
53
+ popupsBoundariesElement,
54
+ popupsScrollableElement,
55
+ toolbarSize,
56
+ disabled,
57
+ isToolbarReducedSpacing,
58
+ isLastItem
59
+ }) {
60
+ const renderNode = providers => {
61
+ return /*#__PURE__*/React.createElement(ToolbarInsertBlockWithInjectionApi, {
62
+ pluginInjectionApi: api,
63
+ editorView: editorView,
64
+ editorActions: editorActions,
65
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
66
+ providerFactory: providerFactory,
67
+ popupsMountPoint: popupsMountPoint,
68
+ popupsBoundariesElement: popupsBoundariesElement,
69
+ popupsScrollableElement: popupsScrollableElement,
70
+ toolbarSize: toolbarSize,
71
+ disabled: disabled,
72
+ isToolbarReducedSpacing: isToolbarReducedSpacing,
73
+ isLastItem: isLastItem,
74
+ featureFlags: featureFlags,
75
+ providers: providers,
76
+ options: options
77
+ });
78
+ };
79
+ return /*#__PURE__*/React.createElement(WithProviders, {
80
+ providerFactory: providerFactory,
81
+ providers: ['emojiProvider'],
82
+ renderNode: renderNode
83
+ });
84
+ }
85
+ };
86
+ };
87
+ function ToolbarInsertBlockWithInjectionApi({
88
+ editorView,
89
+ editorActions,
90
+ dispatchAnalyticsEvent,
91
+ popupsMountPoint,
92
+ popupsBoundariesElement,
93
+ popupsScrollableElement,
94
+ toolbarSize,
95
+ disabled,
96
+ isToolbarReducedSpacing,
97
+ isLastItem,
98
+ providers,
99
+ pluginInjectionApi,
100
+ options,
101
+ featureFlags
102
+ }) {
103
+ var _ref, _ref2, _pluginInjectionApi$i, _pluginInjectionApi$c, _pluginInjectionApi$p, _pluginInjectionApi$b, _pluginInjectionApi$e;
104
+ const buttons = toolbarSizeToButtons(toolbarSize);
105
+ const {
106
+ dateState,
107
+ hyperlinkState,
108
+ imageUploadState,
109
+ mentionState,
110
+ emojiState,
111
+ blockTypeState,
112
+ mediaState,
113
+ typeAheadState,
114
+ placeholderTextState
115
+ } = useSharedPluginState(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload', 'mention', 'emoji', 'blockType', 'media', 'typeAhead', 'placeholderText']);
116
+ return /*#__PURE__*/React.createElement(ToolbarInsertBlock, {
117
+ pluginInjectionApi: pluginInjectionApi,
118
+ buttons: buttons,
119
+ isReducedSpacing: isToolbarReducedSpacing,
120
+ isDisabled: disabled,
121
+ isTypeAheadAllowed: Boolean(typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isAllowed),
122
+ editorView: editorView,
123
+ tableSupported: !!editorView.state.schema.nodes.table,
124
+ actionSupported: !!editorView.state.schema.nodes.taskItem,
125
+ mentionsSupported: !!(mentionState && mentionState.mentionProvider),
126
+ mentionsDisabled: !!(mentionState && !mentionState.canInsertMention),
127
+ decisionSupported: !!editorView.state.schema.nodes.decisionItem,
128
+ dateEnabled: !!dateState,
129
+ placeholderTextEnabled: placeholderTextState && placeholderTextState.allowInserting,
130
+ layoutSectionEnabled: Boolean(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.layout),
131
+ expandEnabled: !!options.allowExpand,
132
+ mediaUploadsEnabled: (_ref = mediaState && mediaState.allowsUploads) !== null && _ref !== void 0 ? _ref : undefined,
133
+ onShowMediaPicker: (_ref2 = mediaState && mediaState.showMediaPicker) !== null && _ref2 !== void 0 ? _ref2 : undefined,
134
+ mediaSupported: !!mediaState,
135
+ imageUploadSupported: !!(pluginInjectionApi !== null && pluginInjectionApi !== void 0 && pluginInjectionApi.imageUpload),
136
+ imageUploadEnabled: imageUploadState === null || imageUploadState === void 0 ? void 0 : imageUploadState.enabled,
137
+ handleImageUpload: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$i = pluginInjectionApi.imageUpload) === null || _pluginInjectionApi$i === void 0 ? void 0 : _pluginInjectionApi$i.actions.startUpload,
138
+ availableWrapperBlockTypes: blockTypeState && blockTypeState.availableWrapperBlockTypes,
139
+ linkSupported: !!hyperlinkState,
140
+ linkDisabled: !hyperlinkState || !hyperlinkState.canInsertLink || !!hyperlinkState.activeLinkMark,
141
+ emojiDisabled: !emojiState || !emojiState.emojiProvider,
142
+ emojiProvider: providers.emojiProvider,
143
+ nativeStatusSupported: options.nativeStatusSupported,
144
+ horizontalRuleEnabled: options.horizontalRuleEnabled,
145
+ onInsertBlockType: handleInsertBlockType(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$c = pluginInjectionApi.codeBlock) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.actions.insertCodeBlock, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$p = pluginInjectionApi.panel) === null || _pluginInjectionApi$p === void 0 ? void 0 : _pluginInjectionApi$p.actions.insertPanel, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$b = pluginInjectionApi.blockType) === null || _pluginInjectionApi$b === void 0 ? void 0 : _pluginInjectionApi$b.actions.insertBlockQuote),
146
+ onInsertMacroFromMacroBrowser: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$e = pluginInjectionApi.extension) === null || _pluginInjectionApi$e === void 0 ? void 0 : _pluginInjectionApi$e.actions.insertMacroFromMacroBrowser,
147
+ popupsMountPoint: popupsMountPoint,
148
+ popupsBoundariesElement: popupsBoundariesElement,
149
+ popupsScrollableElement: popupsScrollableElement,
150
+ insertMenuItems: options.insertMenuItems,
151
+ editorActions: editorActions,
152
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
153
+ replacePlusMenuWithElementBrowser: options.replacePlusMenuWithElementBrowser,
154
+ showElementBrowserLink: options.showElementBrowserLink,
155
+ showSeparator: !isLastItem && toolbarSize <= ToolbarSize.S,
156
+ featureFlags: featureFlags
157
+ });
158
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,156 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
3
+
4
+ import { useCallback, useState } from 'react';
5
+ import { css, jsx } from '@emotion/react';
6
+ import { ELEMENT_ITEM_HEIGHT, ElementBrowser } from '@atlaskit/editor-common/element-browser';
7
+ import { IconCode, IconDate, IconDecision, IconDivider, IconExpand, IconPanel, IconQuote, IconStatus } from '@atlaskit/editor-common/quick-insert';
8
+ import { withReactEditorViewOuterListeners as withOuterListeners } from '@atlaskit/editor-common/ui-react';
9
+ // AFP-2532 TODO: Fix automatic suppressions below
10
+ // eslint-disable-next-line @atlassian/tangerine/import/entry-points
11
+ import { borderRadius } from '@atlaskit/theme';
12
+ import { N0, N30A, N60A } from '@atlaskit/theme/colors';
13
+ const InsertMenu = ({
14
+ editorView,
15
+ dropdownItems,
16
+ showElementBrowserLink,
17
+ onInsert,
18
+ toggleVisiblity,
19
+ pluginInjectionApi
20
+ }) => {
21
+ var _pluginInjectionApi$q6, _pluginInjectionApi$q7, _pluginInjectionApi$q8;
22
+ const [itemCount, setItemCount] = useState(0);
23
+ const transform = useCallback(item => ({
24
+ title: item.content,
25
+ description: item.tooltipDescription,
26
+ keyshortcut: item.shortcut,
27
+ icon: () => getSvgIconForItem({
28
+ name: item.value.name
29
+ }) || item.elemBefore,
30
+ /**
31
+ * @note This transformed items action is only used when a quick insert item has been
32
+ * called from the quick insert menu and a search has not been performed.
33
+ */
34
+ action: () => onInsert({
35
+ item
36
+ }),
37
+ // "insertInsertMenuItem" expects these 2 properties.
38
+ onClick: item.onClick,
39
+ value: item.value
40
+ }), [onInsert]);
41
+ const quickInsertDropdownItems = dropdownItems.map(transform);
42
+ const viewMoreItem = showElementBrowserLink ? quickInsertDropdownItems.pop() : undefined;
43
+ const onInsertItem = useCallback(item => {
44
+ var _pluginInjectionApi$q;
45
+ toggleVisiblity();
46
+ if (!editorView.hasFocus()) {
47
+ editorView.focus();
48
+ }
49
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$q = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q === void 0 ? void 0 : _pluginInjectionApi$q.actions.insertItem(item)(editorView.state, editorView.dispatch);
50
+ }, [editorView, toggleVisiblity, pluginInjectionApi]);
51
+ const getItems = useCallback((query, category) => {
52
+ let result;
53
+ /**
54
+ * @warning The results if there is a query are not the same as the results if there is no query.
55
+ * For example: If you have a typed panel and then select the panel item then it will call a different action
56
+ * than is specified on the editor plugins quick insert
57
+ * @see above transform function for more details.
58
+ */
59
+ if (query) {
60
+ var _pluginInjectionApi$q2, _pluginInjectionApi$q3;
61
+ result = (_pluginInjectionApi$q2 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$q3 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q3 === void 0 ? void 0 : _pluginInjectionApi$q3.actions.getSuggestions({
62
+ query,
63
+ category
64
+ })) !== null && _pluginInjectionApi$q2 !== void 0 ? _pluginInjectionApi$q2 : [];
65
+ } else {
66
+ var _pluginInjectionApi$q4, _pluginInjectionApi$q5;
67
+ const featuredQuickInsertSuggestions = (_pluginInjectionApi$q4 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$q5 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q5 === void 0 ? void 0 : _pluginInjectionApi$q5.actions.getSuggestions({
68
+ category,
69
+ featuredItems: true
70
+ })) !== null && _pluginInjectionApi$q4 !== void 0 ? _pluginInjectionApi$q4 : [];
71
+ result = quickInsertDropdownItems.concat(featuredQuickInsertSuggestions);
72
+ }
73
+ setItemCount(result.length);
74
+ return result;
75
+ }, [pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$q6 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q6 === void 0 ? void 0 : _pluginInjectionApi$q6.actions, quickInsertDropdownItems]);
76
+ const emptyStateHandler = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$q7 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q7 === void 0 ? void 0 : (_pluginInjectionApi$q8 = _pluginInjectionApi$q7.sharedState.currentState()) === null || _pluginInjectionApi$q8 === void 0 ? void 0 : _pluginInjectionApi$q8.emptyStateHandler;
77
+ return (
78
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
79
+ jsx("div", {
80
+ css: insertMenuWrapper(itemCount)
81
+ }, jsx(ElementBrowserWrapper, {
82
+ handleClickOutside: toggleVisiblity,
83
+ handleEscapeKeydown: toggleVisiblity,
84
+ closeOnTab: true
85
+ }, jsx(ElementBrowser, {
86
+ mode: "inline",
87
+ getItems: getItems,
88
+ emptyStateHandler: emptyStateHandler,
89
+ onInsertItem: onInsertItem,
90
+ showSearch: true,
91
+ showCategories: false
92
+ // On page resize we want the InlineElementBrowser to show updated tools/overflow items
93
+ ,
94
+ key: quickInsertDropdownItems.length,
95
+ viewMoreItem: viewMoreItem
96
+ })))
97
+ );
98
+ };
99
+ const getSvgIconForItem = ({
100
+ name
101
+ }) => {
102
+ const Icon = {
103
+ codeblock: IconCode,
104
+ panel: IconPanel,
105
+ blockquote: IconQuote,
106
+ decision: IconDecision,
107
+ horizontalrule: IconDivider,
108
+ expand: IconExpand,
109
+ date: IconDate,
110
+ status: IconStatus
111
+ }[name];
112
+ return Icon ? jsx(Icon, {
113
+ label: ""
114
+ }) : undefined;
115
+ };
116
+ const getInsertMenuHeight = ({
117
+ itemCount
118
+ }) => {
119
+ // Figure based on visuals to exclude the searchbar, padding/margin, and the ViewMore item.
120
+ const EXTRA_SPACE_EXCLUDING_ELEMENTLIST = 112;
121
+ if (itemCount > 0 && itemCount < 6) {
122
+ return itemCount * ELEMENT_ITEM_HEIGHT + EXTRA_SPACE_EXCLUDING_ELEMENTLIST;
123
+ }
124
+ return 560; // For showing 6 Elements.
125
+ };
126
+
127
+ const insertMenuWrapper = itemCount => css({
128
+ display: 'flex',
129
+ flexDirection: 'column',
130
+ width: '320px',
131
+ height: `${getInsertMenuHeight({
132
+ itemCount
133
+ })}px`,
134
+ backgroundColor: `${`var(--ds-surface-overlay, ${N0})`}`,
135
+ borderRadius: `${borderRadius()}px`,
136
+ boxShadow: `${`var(--ds-shadow-overlay, ${`0 0 0 1px ${N30A},
137
+ 0 2px 1px ${N30A},
138
+ 0 0 20px -6px ${N60A}`})`}`
139
+ });
140
+ const flexWrapperStyles = css({
141
+ display: 'flex',
142
+ flex: 1,
143
+ boxSizing: 'border-box',
144
+ overflow: 'hidden'
145
+ });
146
+ const FlexWrapper = props => {
147
+ const {
148
+ children,
149
+ ...divProps
150
+ } = props;
151
+ return jsx("div", _extends({
152
+ css: flexWrapperStyles
153
+ }, divProps), children);
154
+ };
155
+ const ElementBrowserWrapper = withOuterListeners(FlexWrapper);
156
+ export default InsertMenu;
@@ -0,0 +1 @@
1
+ export {};