@atlaskit/editor-plugin-insert-block 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/.eslintrc.js +26 -0
  2. package/CHANGELOG.md +6 -0
  3. package/dist/cjs/index.js +8 -1
  4. package/dist/cjs/plugin.js +164 -0
  5. package/dist/cjs/types.js +5 -0
  6. package/dist/cjs/ui/ElementBrowser/InsertMenu.js +166 -0
  7. package/dist/cjs/ui/ElementBrowser/types.js +5 -0
  8. package/dist/cjs/ui/ToolbarInsertBlock/block-insert-element-browser.js +42 -0
  9. package/dist/cjs/ui/ToolbarInsertBlock/block-insert-menu-legacy.js +42 -0
  10. package/dist/cjs/ui/ToolbarInsertBlock/block-insert-menu.js +66 -0
  11. package/dist/cjs/ui/ToolbarInsertBlock/create-items.js +217 -0
  12. package/dist/cjs/ui/ToolbarInsertBlock/dropdown-button.js +52 -0
  13. package/dist/cjs/ui/ToolbarInsertBlock/index.js +570 -0
  14. package/dist/cjs/ui/ToolbarInsertBlock/item.js +252 -0
  15. package/dist/cjs/ui/ToolbarInsertBlock/messages.js +12 -0
  16. package/dist/cjs/ui/ToolbarInsertBlock/shallow-equals.js +20 -0
  17. package/dist/cjs/ui/ToolbarInsertBlock/sort-items.js +30 -0
  18. package/dist/cjs/ui/ToolbarInsertBlock/styles.js +11 -0
  19. package/dist/cjs/ui/ToolbarInsertBlock/types.js +5 -0
  20. package/dist/es2019/index.js +1 -1
  21. package/dist/es2019/plugin.js +158 -0
  22. package/dist/es2019/types.js +1 -0
  23. package/dist/es2019/ui/ElementBrowser/InsertMenu.js +153 -0
  24. package/dist/es2019/ui/ElementBrowser/types.js +1 -0
  25. package/dist/es2019/ui/ToolbarInsertBlock/block-insert-element-browser.js +35 -0
  26. package/dist/es2019/ui/ToolbarInsertBlock/block-insert-menu-legacy.js +35 -0
  27. package/dist/es2019/ui/ToolbarInsertBlock/block-insert-menu.js +59 -0
  28. package/dist/es2019/ui/ToolbarInsertBlock/create-items.js +198 -0
  29. package/dist/es2019/ui/ToolbarInsertBlock/dropdown-button.js +39 -0
  30. package/dist/es2019/ui/ToolbarInsertBlock/index.js +562 -0
  31. package/dist/es2019/ui/ToolbarInsertBlock/item.js +202 -0
  32. package/dist/es2019/ui/ToolbarInsertBlock/messages.js +1 -0
  33. package/dist/es2019/ui/ToolbarInsertBlock/shallow-equals.js +8 -0
  34. package/dist/es2019/ui/ToolbarInsertBlock/sort-items.js +22 -0
  35. package/dist/es2019/ui/ToolbarInsertBlock/styles.js +16 -0
  36. package/dist/es2019/ui/ToolbarInsertBlock/types.js +1 -0
  37. package/dist/esm/index.js +1 -1
  38. package/dist/esm/plugin.js +157 -0
  39. package/dist/esm/types.js +1 -0
  40. package/dist/esm/ui/ElementBrowser/InsertMenu.js +160 -0
  41. package/dist/esm/ui/ElementBrowser/types.js +1 -0
  42. package/dist/esm/ui/ToolbarInsertBlock/block-insert-element-browser.js +35 -0
  43. package/dist/esm/ui/ToolbarInsertBlock/block-insert-menu-legacy.js +35 -0
  44. package/dist/esm/ui/ToolbarInsertBlock/block-insert-menu.js +59 -0
  45. package/dist/esm/ui/ToolbarInsertBlock/create-items.js +210 -0
  46. package/dist/esm/ui/ToolbarInsertBlock/dropdown-button.js +44 -0
  47. package/dist/esm/ui/ToolbarInsertBlock/index.js +564 -0
  48. package/dist/esm/ui/ToolbarInsertBlock/item.js +244 -0
  49. package/dist/esm/ui/ToolbarInsertBlock/messages.js +1 -0
  50. package/dist/esm/ui/ToolbarInsertBlock/shallow-equals.js +13 -0
  51. package/dist/esm/ui/ToolbarInsertBlock/sort-items.js +24 -0
  52. package/dist/esm/ui/ToolbarInsertBlock/styles.js +4 -0
  53. package/dist/esm/ui/ToolbarInsertBlock/types.js +1 -0
  54. package/dist/types/index.d.ts +2 -1
  55. package/dist/types/plugin.d.ts +16 -0
  56. package/dist/types/types.d.ts +45 -0
  57. package/dist/types/ui/ElementBrowser/InsertMenu.d.ts +4 -0
  58. package/dist/types/ui/ElementBrowser/types.d.ts +22 -0
  59. package/dist/types/ui/ToolbarInsertBlock/block-insert-element-browser.d.ts +28 -0
  60. package/dist/types/ui/ToolbarInsertBlock/block-insert-menu-legacy.d.ts +21 -0
  61. package/dist/types/ui/ToolbarInsertBlock/block-insert-menu.d.ts +33 -0
  62. package/dist/types/ui/ToolbarInsertBlock/create-items.d.ts +39 -0
  63. package/dist/types/ui/ToolbarInsertBlock/dropdown-button.d.ts +16 -0
  64. package/dist/types/ui/ToolbarInsertBlock/index.d.ts +46 -0
  65. package/dist/types/ui/ToolbarInsertBlock/item.d.ts +35 -0
  66. package/dist/types/ui/ToolbarInsertBlock/messages.d.ts +1 -0
  67. package/dist/types/ui/ToolbarInsertBlock/shallow-equals.d.ts +1 -0
  68. package/dist/types/ui/ToolbarInsertBlock/sort-items.d.ts +2 -0
  69. package/dist/types/ui/ToolbarInsertBlock/styles.d.ts +1 -0
  70. package/dist/types/ui/ToolbarInsertBlock/types.d.ts +59 -0
  71. package/dist/types-ts4.5/index.d.ts +2 -1
  72. package/dist/types-ts4.5/plugin.d.ts +16 -0
  73. package/dist/types-ts4.5/types.d.ts +45 -0
  74. package/dist/types-ts4.5/ui/ElementBrowser/InsertMenu.d.ts +4 -0
  75. package/dist/types-ts4.5/ui/ElementBrowser/types.d.ts +22 -0
  76. package/dist/types-ts4.5/ui/ToolbarInsertBlock/block-insert-element-browser.d.ts +28 -0
  77. package/dist/types-ts4.5/ui/ToolbarInsertBlock/block-insert-menu-legacy.d.ts +21 -0
  78. package/dist/types-ts4.5/ui/ToolbarInsertBlock/block-insert-menu.d.ts +33 -0
  79. package/dist/types-ts4.5/ui/ToolbarInsertBlock/create-items.d.ts +42 -0
  80. package/dist/types-ts4.5/ui/ToolbarInsertBlock/dropdown-button.d.ts +16 -0
  81. package/dist/types-ts4.5/ui/ToolbarInsertBlock/index.d.ts +46 -0
  82. package/dist/types-ts4.5/ui/ToolbarInsertBlock/item.d.ts +35 -0
  83. package/dist/types-ts4.5/ui/ToolbarInsertBlock/messages.d.ts +1 -0
  84. package/dist/types-ts4.5/ui/ToolbarInsertBlock/shallow-equals.d.ts +1 -0
  85. package/dist/types-ts4.5/ui/ToolbarInsertBlock/sort-items.d.ts +2 -0
  86. package/dist/types-ts4.5/ui/ToolbarInsertBlock/styles.d.ts +1 -0
  87. package/dist/types-ts4.5/ui/ToolbarInsertBlock/types.d.ts +59 -0
  88. package/package.json +37 -9
  89. package/report.api.md +82 -1
  90. package/tmp/api-report-tmp.d.ts +76 -0
@@ -0,0 +1,202 @@
1
+ /** @jsx jsx */
2
+ import React from 'react';
3
+ import { jsx } from '@emotion/react';
4
+ import memoizeOne from 'memoize-one';
5
+ import { addLink, getAriaKeyshortcuts, toggleTable, tooltip } from '@atlaskit/editor-common/keymaps';
6
+ import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
7
+ import ExpandNodeIcon from '@atlaskit/icon/glyph/chevron-right-circle';
8
+ import CodeIcon from '@atlaskit/icon/glyph/editor/code';
9
+ import DateIcon from '@atlaskit/icon/glyph/editor/date';
10
+ import DecisionIcon from '@atlaskit/icon/glyph/editor/decision';
11
+ import EmojiIcon from '@atlaskit/icon/glyph/editor/emoji';
12
+ import HorizontalRuleIcon from '@atlaskit/icon/glyph/editor/horizontal-rule';
13
+ import EditorImageIcon from '@atlaskit/icon/glyph/editor/image';
14
+ import InfoIcon from '@atlaskit/icon/glyph/editor/info';
15
+ import LayoutTwoEqualIcon from '@atlaskit/icon/glyph/editor/layout-two-equal';
16
+ import LinkIcon from '@atlaskit/icon/glyph/editor/link';
17
+ import MentionIcon from '@atlaskit/icon/glyph/editor/mention';
18
+ import EditorMoreIcon from '@atlaskit/icon/glyph/editor/more';
19
+ import TableIcon from '@atlaskit/icon/glyph/editor/table';
20
+ import TaskIcon from '@atlaskit/icon/glyph/editor/task';
21
+ import PlaceholderTextIcon from '@atlaskit/icon/glyph/media-services/text';
22
+ import QuoteIcon from '@atlaskit/icon/glyph/quote';
23
+ import StatusIcon from '@atlaskit/icon/glyph/status';
24
+ import { shallowEquals } from './shallow-equals';
25
+ const from = init => ({
26
+ content: init.content,
27
+ tooltipDescription: init.tooltipDescription,
28
+ value: {
29
+ name: init.name
30
+ },
31
+ elemBefore: jsx(init.Icon, {
32
+ label: init.content
33
+ }),
34
+ elemAfter: init.shortcut ?
35
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
36
+ jsx("div", {
37
+ css: shortcutStyle
38
+ }, init.shortcut) : undefined,
39
+ 'aria-label': init.shortcut ? init.content + ' ' + init.shortcut : init.content,
40
+ 'aria-haspopup': init['aria-haspopup'],
41
+ 'aria-keyshortcuts': init['aria-keyshortcuts'],
42
+ shortcut: init.shortcut,
43
+ isDisabled: init.disabled
44
+ });
45
+ const mem = fn => memoizeOne(fn, shallowEquals);
46
+ export const action = mem(init => {
47
+ return from({
48
+ content: init.content,
49
+ tooltipDescription: init.tooltipDescription,
50
+ disabled: init.disabled,
51
+ name: 'action',
52
+ shortcut: '[]',
53
+ Icon: TaskIcon,
54
+ 'aria-keyshortcuts': '[ ] Space'
55
+ });
56
+ });
57
+ export const link = mem(init => from({
58
+ content: init.content,
59
+ tooltipDescription: init.tooltipDescription,
60
+ disabled: init.disabled,
61
+ name: 'link',
62
+ shortcut: tooltip(addLink),
63
+ Icon: LinkIcon,
64
+ 'aria-haspopup': init['aria-haspopup'],
65
+ 'aria-keyshortcuts': getAriaKeyshortcuts(addLink)
66
+ }));
67
+ export const media = mem(init => from({
68
+ content: init.content,
69
+ tooltipDescription: init.tooltipDescription,
70
+ disabled: init.disabled,
71
+ name: 'media',
72
+ Icon: EditorImageIcon
73
+ }));
74
+ export const imageUpload = mem(init => from({
75
+ content: init.content,
76
+ tooltipDescription: init.tooltipDescription,
77
+ disabled: init.disabled,
78
+ name: 'image upload',
79
+ Icon: EditorImageIcon
80
+ }));
81
+ export const mention = mem(init => from({
82
+ content: init.content,
83
+ tooltipDescription: init.tooltipDescription,
84
+ disabled: init.disabled,
85
+ name: 'mention',
86
+ Icon: MentionIcon,
87
+ shortcut: '@',
88
+ 'aria-haspopup': init['aria-haspopup'],
89
+ 'aria-keyshortcuts': 'Shift+2 Space'
90
+ }));
91
+ export const emoji = mem(init => from({
92
+ content: init.content,
93
+ tooltipDescription: init.tooltipDescription,
94
+ disabled: init.disabled,
95
+ name: 'emoji',
96
+ Icon: EmojiIcon,
97
+ shortcut: ':',
98
+ 'aria-haspopup': init['aria-haspopup'],
99
+ 'aria-keyshortcuts': 'Shift+;'
100
+ }));
101
+ export const table = mem(init => from({
102
+ content: init.content,
103
+ tooltipDescription: init.tooltipDescription,
104
+ disabled: init.disabled,
105
+ name: 'table',
106
+ Icon: TableIcon,
107
+ shortcut: tooltip(toggleTable),
108
+ 'aria-keyshortcuts': getAriaKeyshortcuts(toggleTable)
109
+ }));
110
+ export const layout = mem(init => from({
111
+ content: init.content,
112
+ tooltipDescription: init.tooltipDescription,
113
+ disabled: init.disabled,
114
+ name: 'layout',
115
+ Icon: LayoutTwoEqualIcon
116
+ }));
117
+ export const codeblock = mem(init => from({
118
+ content: init.content,
119
+ tooltipDescription: init.tooltipDescription,
120
+ disabled: init.disabled,
121
+ name: 'codeblock',
122
+ Icon: CodeIcon,
123
+ shortcut: init.shortcut,
124
+ 'aria-keyshortcuts': getAriaKeyshortcuts(init.shortcut)
125
+ }));
126
+ export const panel = mem(init => from({
127
+ content: init.content,
128
+ tooltipDescription: init.tooltipDescription,
129
+ disabled: init.disabled,
130
+ name: 'panel',
131
+ Icon: InfoIcon,
132
+ shortcut: init.shortcut,
133
+ 'aria-keyshortcuts': getAriaKeyshortcuts(init.shortcut)
134
+ }));
135
+ export const blockquote = mem(init => from({
136
+ content: init.content,
137
+ tooltipDescription: init.tooltipDescription,
138
+ disabled: init.disabled,
139
+ name: 'blockquote',
140
+ Icon: QuoteIcon,
141
+ shortcut: init.shortcut,
142
+ 'aria-keyshortcuts': 'Shift+. Space'
143
+ }));
144
+ export const decision = mem(init => from({
145
+ content: init.content,
146
+ tooltipDescription: init.tooltipDescription,
147
+ disabled: init.disabled,
148
+ name: 'decision',
149
+ Icon: DecisionIcon,
150
+ shortcut: '<>',
151
+ 'aria-keyshortcuts': 'Shift+, Shift+. Space'
152
+ }));
153
+ export const horizontalrule = mem(init => from({
154
+ content: init.content,
155
+ tooltipDescription: init.tooltipDescription,
156
+ disabled: init.disabled,
157
+ name: 'horizontalrule',
158
+ Icon: HorizontalRuleIcon,
159
+ shortcut: '---',
160
+ 'aria-keyshortcuts': '- - -'
161
+ }));
162
+ export const expand = mem(init => from({
163
+ content: init.content,
164
+ tooltipDescription: init.tooltipDescription,
165
+ disabled: init.disabled,
166
+ name: 'expand',
167
+ Icon: ExpandNodeIcon
168
+ }));
169
+ export const date = mem(init => from({
170
+ content: init.content,
171
+ tooltipDescription: init.tooltipDescription,
172
+ disabled: init.disabled,
173
+ name: 'date',
174
+ Icon: DateIcon,
175
+ shortcut: '//',
176
+ 'aria-keyshortcuts': '/ / Enter'
177
+ }));
178
+ export const placeholder = mem(init => from({
179
+ content: init.content,
180
+ tooltipDescription: init.tooltipDescription,
181
+ disabled: init.disabled,
182
+ name: 'placeholder text',
183
+ Icon: () => jsx(PlaceholderTextIcon, {
184
+ label: ""
185
+ })
186
+ }));
187
+ export const status = mem(init => from({
188
+ content: init.content,
189
+ tooltipDescription: init.tooltipDescription,
190
+ disabled: init.disabled,
191
+ name: 'status',
192
+ Icon: StatusIcon
193
+ }));
194
+ export const more = mem(init => from({
195
+ content: init.content,
196
+ tooltipDescription: init.tooltipDescription,
197
+ disabled: init.disabled,
198
+ name: 'macro',
199
+ Icon: () => jsx(EditorMoreIcon, {
200
+ label: ""
201
+ })
202
+ }));
@@ -0,0 +1 @@
1
+ export { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
@@ -0,0 +1,8 @@
1
+ export const shallowEquals = ([aRaw], [bRaw]) => {
2
+ const a = aRaw;
3
+ const b = bRaw;
4
+ return !Object.keys(a).some(key => {
5
+ const k = key;
6
+ return a[k] !== b[k];
7
+ });
8
+ };
@@ -0,0 +1,22 @@
1
+ const endPositionNames = ['macro-browser', 'slash-onboarding'];
2
+ const isMacro = item => typeof item.content === 'string' && item.content.includes('macro');
3
+ export const sortItems = items => {
4
+ return items.sort((a, b) => {
5
+ if (endPositionNames.includes(a.value.name) && endPositionNames.includes(b.value.name)) {
6
+ return endPositionNames.indexOf(a.value.name) - endPositionNames.indexOf(b.value.name);
7
+ }
8
+ if (endPositionNames.includes(b.value.name)) {
9
+ return -1;
10
+ }
11
+ if (endPositionNames.includes(a.value.name)) {
12
+ return 1;
13
+ }
14
+ if (isMacro(a) && !isMacro(b)) {
15
+ return 1;
16
+ }
17
+ if (isMacro(b) && !isMacro(a)) {
18
+ return -1;
19
+ }
20
+ return a.content < b.content ? -1 : 1;
21
+ });
22
+ };
@@ -0,0 +1,16 @@
1
+ import { css } from '@emotion/react';
2
+ export const triggerWrapper = css`
3
+ width: 42px;
4
+
5
+ display: flex;
6
+ align-items: center;
7
+
8
+ > div,
9
+ > span {
10
+ display: flex;
11
+ }
12
+
13
+ > div > div {
14
+ display: flex;
15
+ }
16
+ `;
@@ -0,0 +1 @@
1
+ export {};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export { insertBlockPlugin } from './plugin';
@@ -0,0 +1,157 @@
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
+ var toolbarSizeToButtons = function 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 function (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 function () {
37
+ return false;
38
+ };
39
+ };
40
+ }
41
+ export var insertBlockPlugin = function insertBlockPlugin(_ref) {
42
+ var _api$featureFlags;
43
+ var _ref$config = _ref.config,
44
+ options = _ref$config === void 0 ? {} : _ref$config,
45
+ api = _ref.api;
46
+ var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
47
+ return {
48
+ name: 'insertBlock',
49
+ primaryToolbarComponent: function primaryToolbarComponent(_ref2) {
50
+ var editorView = _ref2.editorView,
51
+ editorActions = _ref2.editorActions,
52
+ dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent,
53
+ providerFactory = _ref2.providerFactory,
54
+ popupsMountPoint = _ref2.popupsMountPoint,
55
+ popupsBoundariesElement = _ref2.popupsBoundariesElement,
56
+ popupsScrollableElement = _ref2.popupsScrollableElement,
57
+ toolbarSize = _ref2.toolbarSize,
58
+ disabled = _ref2.disabled,
59
+ isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
60
+ isLastItem = _ref2.isLastItem;
61
+ var renderNode = function renderNode(providers) {
62
+ return /*#__PURE__*/React.createElement(ToolbarInsertBlockWithInjectionApi, {
63
+ pluginInjectionApi: api,
64
+ editorView: editorView,
65
+ editorActions: editorActions,
66
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
67
+ providerFactory: providerFactory,
68
+ popupsMountPoint: popupsMountPoint,
69
+ popupsBoundariesElement: popupsBoundariesElement,
70
+ popupsScrollableElement: popupsScrollableElement,
71
+ toolbarSize: toolbarSize,
72
+ disabled: disabled,
73
+ isToolbarReducedSpacing: isToolbarReducedSpacing,
74
+ isLastItem: isLastItem,
75
+ featureFlags: featureFlags,
76
+ providers: providers,
77
+ options: options
78
+ });
79
+ };
80
+ return /*#__PURE__*/React.createElement(WithProviders, {
81
+ providerFactory: providerFactory,
82
+ providers: ['emojiProvider'],
83
+ renderNode: renderNode
84
+ });
85
+ }
86
+ };
87
+ };
88
+ function ToolbarInsertBlockWithInjectionApi(_ref3) {
89
+ var _ref4, _ref5, _pluginInjectionApi$i, _pluginInjectionApi$c, _pluginInjectionApi$p, _pluginInjectionApi$b, _pluginInjectionApi$e;
90
+ var editorView = _ref3.editorView,
91
+ editorActions = _ref3.editorActions,
92
+ dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent,
93
+ popupsMountPoint = _ref3.popupsMountPoint,
94
+ popupsBoundariesElement = _ref3.popupsBoundariesElement,
95
+ popupsScrollableElement = _ref3.popupsScrollableElement,
96
+ toolbarSize = _ref3.toolbarSize,
97
+ disabled = _ref3.disabled,
98
+ isToolbarReducedSpacing = _ref3.isToolbarReducedSpacing,
99
+ isLastItem = _ref3.isLastItem,
100
+ providers = _ref3.providers,
101
+ pluginInjectionApi = _ref3.pluginInjectionApi,
102
+ options = _ref3.options,
103
+ featureFlags = _ref3.featureFlags;
104
+ var buttons = toolbarSizeToButtons(toolbarSize);
105
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload', 'mention', 'emoji', 'blockType', 'media', 'typeAhead', 'placeholderText']),
106
+ dateState = _useSharedPluginState.dateState,
107
+ hyperlinkState = _useSharedPluginState.hyperlinkState,
108
+ imageUploadState = _useSharedPluginState.imageUploadState,
109
+ mentionState = _useSharedPluginState.mentionState,
110
+ emojiState = _useSharedPluginState.emojiState,
111
+ blockTypeState = _useSharedPluginState.blockTypeState,
112
+ mediaState = _useSharedPluginState.mediaState,
113
+ typeAheadState = _useSharedPluginState.typeAheadState,
114
+ placeholderTextState = _useSharedPluginState.placeholderTextState;
115
+ return /*#__PURE__*/React.createElement(ToolbarInsertBlock, {
116
+ pluginInjectionApi: pluginInjectionApi,
117
+ buttons: buttons,
118
+ isReducedSpacing: isToolbarReducedSpacing,
119
+ isDisabled: disabled,
120
+ isTypeAheadAllowed: Boolean(typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isAllowed),
121
+ editorView: editorView,
122
+ tableSupported: !!editorView.state.schema.nodes.table,
123
+ actionSupported: !!editorView.state.schema.nodes.taskItem,
124
+ mentionsSupported: !!(mentionState && mentionState.mentionProvider),
125
+ mentionsDisabled: !!(mentionState && !mentionState.canInsertMention),
126
+ decisionSupported: !!editorView.state.schema.nodes.decisionItem,
127
+ dateEnabled: !!dateState,
128
+ placeholderTextEnabled: placeholderTextState && placeholderTextState.allowInserting,
129
+ layoutSectionEnabled: Boolean(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.layout),
130
+ expandEnabled: !!options.allowExpand,
131
+ mediaUploadsEnabled: (_ref4 = mediaState && mediaState.allowsUploads) !== null && _ref4 !== void 0 ? _ref4 : undefined,
132
+ onShowMediaPicker: (_ref5 = mediaState && mediaState.showMediaPicker) !== null && _ref5 !== void 0 ? _ref5 : undefined,
133
+ mediaSupported: !!mediaState,
134
+ imageUploadSupported: !!(pluginInjectionApi !== null && pluginInjectionApi !== void 0 && pluginInjectionApi.imageUpload),
135
+ imageUploadEnabled: imageUploadState === null || imageUploadState === void 0 ? void 0 : imageUploadState.enabled,
136
+ handleImageUpload: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$i = pluginInjectionApi.imageUpload) === null || _pluginInjectionApi$i === void 0 ? void 0 : _pluginInjectionApi$i.actions.startUpload,
137
+ availableWrapperBlockTypes: blockTypeState && blockTypeState.availableWrapperBlockTypes,
138
+ linkSupported: !!hyperlinkState,
139
+ linkDisabled: !hyperlinkState || !hyperlinkState.canInsertLink || !!hyperlinkState.activeLinkMark,
140
+ emojiDisabled: !emojiState || !emojiState.emojiProvider,
141
+ emojiProvider: providers.emojiProvider,
142
+ nativeStatusSupported: options.nativeStatusSupported,
143
+ horizontalRuleEnabled: options.horizontalRuleEnabled,
144
+ onInsertBlockType: handleInsertBlockType(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.codeBlock) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.actions.insertCodeBlock, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$p = pluginInjectionApi.panel) === null || _pluginInjectionApi$p === void 0 ? void 0 : _pluginInjectionApi$p.actions.insertPanel, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$b = pluginInjectionApi.blockType) === null || _pluginInjectionApi$b === void 0 ? void 0 : _pluginInjectionApi$b.actions.insertBlockQuote),
145
+ onInsertMacroFromMacroBrowser: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e = pluginInjectionApi.extension) === null || _pluginInjectionApi$e === void 0 ? void 0 : _pluginInjectionApi$e.actions.insertMacroFromMacroBrowser,
146
+ popupsMountPoint: popupsMountPoint,
147
+ popupsBoundariesElement: popupsBoundariesElement,
148
+ popupsScrollableElement: popupsScrollableElement,
149
+ insertMenuItems: options.insertMenuItems,
150
+ editorActions: editorActions,
151
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
152
+ replacePlusMenuWithElementBrowser: options.replacePlusMenuWithElementBrowser,
153
+ showElementBrowserLink: options.showElementBrowserLink,
154
+ showSeparator: !isLastItem && toolbarSize <= ToolbarSize.S,
155
+ featureFlags: featureFlags
156
+ });
157
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,160 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ var _excluded = ["children"];
5
+ /** @jsx jsx */
6
+
7
+ import { useCallback, useState } from 'react';
8
+ import { css, jsx } from '@emotion/react';
9
+ import { ELEMENT_ITEM_HEIGHT, ElementBrowser } from '@atlaskit/editor-common/element-browser';
10
+ import { IconCode, IconDate, IconDecision, IconDivider, IconExpand, IconPanel, IconQuote, IconStatus } from '@atlaskit/editor-common/quick-insert';
11
+ import { withReactEditorViewOuterListeners as withOuterListeners } from '@atlaskit/editor-common/ui-react';
12
+ // AFP-2532 TODO: Fix automatic suppressions below
13
+ // eslint-disable-next-line @atlassian/tangerine/import/entry-points
14
+ import { borderRadius } from '@atlaskit/theme';
15
+ import { N0, N30A, N60A } from '@atlaskit/theme/colors';
16
+ var InsertMenu = function InsertMenu(_ref) {
17
+ var _pluginInjectionApi$q6, _pluginInjectionApi$q7;
18
+ var editorView = _ref.editorView,
19
+ dropdownItems = _ref.dropdownItems,
20
+ showElementBrowserLink = _ref.showElementBrowserLink,
21
+ onInsert = _ref.onInsert,
22
+ toggleVisiblity = _ref.toggleVisiblity,
23
+ pluginInjectionApi = _ref.pluginInjectionApi;
24
+ var _useState = useState(0),
25
+ _useState2 = _slicedToArray(_useState, 2),
26
+ itemCount = _useState2[0],
27
+ setItemCount = _useState2[1];
28
+ var transform = useCallback(function (item) {
29
+ return {
30
+ title: item.content,
31
+ description: item.tooltipDescription,
32
+ keyshortcut: item.shortcut,
33
+ icon: function icon() {
34
+ return getSvgIconForItem({
35
+ name: item.value.name
36
+ }) || item.elemBefore;
37
+ },
38
+ /**
39
+ * @note This transformed items action is only used when a quick insert item has been
40
+ * called from the quick insert menu and a search has not been performed.
41
+ */
42
+ action: function action() {
43
+ return onInsert({
44
+ item: item
45
+ });
46
+ },
47
+ // "insertInsertMenuItem" expects these 2 properties.
48
+ onClick: item.onClick,
49
+ value: item.value
50
+ };
51
+ }, [onInsert]);
52
+ var quickInsertDropdownItems = dropdownItems.map(transform);
53
+ var viewMoreItem = showElementBrowserLink ? quickInsertDropdownItems.pop() : undefined;
54
+ var onInsertItem = useCallback(function (item) {
55
+ var _pluginInjectionApi$q;
56
+ toggleVisiblity();
57
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q === void 0 || _pluginInjectionApi$q.actions.insertItem(item)(editorView.state, editorView.dispatch);
58
+ }, [editorView, toggleVisiblity, pluginInjectionApi]);
59
+ var getItems = useCallback(function (query, category) {
60
+ var result;
61
+ /**
62
+ * @warning The results if there is a query are not the same as the results if there is no query.
63
+ * For example: If you have a typed panel and then select the panel item then it will call a different action
64
+ * than is specified on the editor plugins quick insert
65
+ * @see above transform function for more details.
66
+ */
67
+ if (query) {
68
+ var _pluginInjectionApi$q2, _pluginInjectionApi$q3;
69
+ result = (_pluginInjectionApi$q2 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q3 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q3 === void 0 ? void 0 : _pluginInjectionApi$q3.actions.getSuggestions({
70
+ query: query,
71
+ category: category
72
+ })) !== null && _pluginInjectionApi$q2 !== void 0 ? _pluginInjectionApi$q2 : [];
73
+ } else {
74
+ var _pluginInjectionApi$q4, _pluginInjectionApi$q5;
75
+ var featuredQuickInsertSuggestions = (_pluginInjectionApi$q4 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q5 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q5 === void 0 ? void 0 : _pluginInjectionApi$q5.actions.getSuggestions({
76
+ category: category,
77
+ featuredItems: true
78
+ })) !== null && _pluginInjectionApi$q4 !== void 0 ? _pluginInjectionApi$q4 : [];
79
+ result = quickInsertDropdownItems.concat(featuredQuickInsertSuggestions);
80
+ }
81
+ setItemCount(result.length);
82
+ return result;
83
+ }, [pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q6 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q6 === void 0 ? void 0 : _pluginInjectionApi$q6.actions, quickInsertDropdownItems]);
84
+ var emptyStateHandler = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q7 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q7 === void 0 || (_pluginInjectionApi$q7 = _pluginInjectionApi$q7.sharedState.currentState()) === null || _pluginInjectionApi$q7 === void 0 ? void 0 : _pluginInjectionApi$q7.emptyStateHandler;
85
+ return (
86
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
87
+ jsx("div", {
88
+ css: insertMenuWrapper(itemCount)
89
+ }, jsx(ElementBrowserWrapper, {
90
+ handleClickOutside: toggleVisiblity,
91
+ handleEscapeKeydown: toggleVisiblity,
92
+ closeOnTab: true
93
+ }, jsx(ElementBrowser, {
94
+ mode: "inline",
95
+ getItems: getItems,
96
+ emptyStateHandler: emptyStateHandler,
97
+ onInsertItem: onInsertItem,
98
+ showSearch: true,
99
+ showCategories: false
100
+ // On page resize we want the InlineElementBrowser to show updated tools/overflow items
101
+ ,
102
+ key: quickInsertDropdownItems.length,
103
+ viewMoreItem: viewMoreItem
104
+ })))
105
+ );
106
+ };
107
+ var getSvgIconForItem = function getSvgIconForItem(_ref2) {
108
+ var name = _ref2.name;
109
+ var Icon = {
110
+ codeblock: IconCode,
111
+ panel: IconPanel,
112
+ blockquote: IconQuote,
113
+ decision: IconDecision,
114
+ horizontalrule: IconDivider,
115
+ expand: IconExpand,
116
+ date: IconDate,
117
+ status: IconStatus
118
+ }[name];
119
+ return Icon ? jsx(Icon, {
120
+ label: ""
121
+ }) : undefined;
122
+ };
123
+ var getInsertMenuHeight = function getInsertMenuHeight(_ref3) {
124
+ var itemCount = _ref3.itemCount;
125
+ // Figure based on visuals to exclude the searchbar, padding/margin, and the ViewMore item.
126
+ var EXTRA_SPACE_EXCLUDING_ELEMENTLIST = 112;
127
+ if (itemCount > 0 && itemCount < 6) {
128
+ return itemCount * ELEMENT_ITEM_HEIGHT + EXTRA_SPACE_EXCLUDING_ELEMENTLIST;
129
+ }
130
+ return 560; // For showing 6 Elements.
131
+ };
132
+
133
+ var insertMenuWrapper = function insertMenuWrapper(itemCount) {
134
+ return css({
135
+ display: 'flex',
136
+ flexDirection: 'column',
137
+ width: '320px',
138
+ height: "".concat(getInsertMenuHeight({
139
+ itemCount: itemCount
140
+ }), "px"),
141
+ backgroundColor: "".concat("var(--ds-surface-overlay, ".concat(N0, ")")),
142
+ borderRadius: "".concat(borderRadius(), "px"),
143
+ boxShadow: "".concat("var(--ds-shadow-overlay, ".concat("0 0 0 1px ".concat(N30A, ",\n 0 2px 1px ").concat(N30A, ",\n 0 0 20px -6px ").concat(N60A), ")"))
144
+ });
145
+ };
146
+ var flexWrapperStyles = css({
147
+ display: 'flex',
148
+ flex: 1,
149
+ boxSizing: 'border-box',
150
+ overflow: 'hidden'
151
+ });
152
+ var FlexWrapper = function FlexWrapper(props) {
153
+ var children = props.children,
154
+ divProps = _objectWithoutProperties(props, _excluded);
155
+ return jsx("div", _extends({
156
+ css: flexWrapperStyles
157
+ }, divProps), children);
158
+ };
159
+ var ElementBrowserWrapper = withOuterListeners(FlexWrapper);
160
+ export default InsertMenu;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { Popup } from '@atlaskit/editor-common/ui';
3
+ import InsertMenu from '../ElementBrowser/InsertMenu';
4
+ import { DropDownButton } from './dropdown-button';
5
+ export var BlockInsertElementBrowser = function BlockInsertElementBrowser(props) {
6
+ return /*#__PURE__*/React.createElement(React.Fragment, null, props.open && /*#__PURE__*/React.createElement(Popup, {
7
+ target: props.plusButtonRef,
8
+ fitHeight: 500,
9
+ fitWidth: 350,
10
+ offset: [0, 3],
11
+ mountTo: props.popupsMountPoint,
12
+ boundariesElement: props.popupsBoundariesElement,
13
+ scrollableElement: props.popupsScrollableElement,
14
+ preventOverflow: true,
15
+ alignX: "right"
16
+ }, /*#__PURE__*/React.createElement(InsertMenu, {
17
+ editorView: props.editorView,
18
+ dropdownItems: props.items,
19
+ onInsert: props.onInsert,
20
+ toggleVisiblity: props.togglePlusMenuVisibility,
21
+ showElementBrowserLink: props.showElementBrowserLink,
22
+ pluginInjectionApi: props.pluginInjectionApi
23
+ })), /*#__PURE__*/React.createElement(DropDownButton, {
24
+ "aria-expanded": props.open,
25
+ "aria-haspopup": true,
26
+ handleRef: props.onRef,
27
+ selected: props.open,
28
+ disabled: props.disabled,
29
+ onClick: props.onClick,
30
+ onKeyDown: props.onKeyDown,
31
+ spacing: props.spacing,
32
+ label: props.label,
33
+ "aria-keyshortcuts": "/"
34
+ }));
35
+ };
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { DropdownMenuWithKeyboardNavigation as DropdownMenu } from '@atlaskit/editor-common/ui-menu';
3
+ import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
4
+ import { DropDownButton } from './dropdown-button';
5
+ export var BlockInsertMenuLegacy = function BlockInsertMenuLegacy(props) {
6
+ var items = props.items;
7
+ var dropdownItems = React.useMemo(function () {
8
+ return [{
9
+ items: items
10
+ }];
11
+ }, [items]);
12
+ return /*#__PURE__*/React.createElement(DropdownMenu, {
13
+ items: dropdownItems,
14
+ onItemActivated: props.onItemActivated,
15
+ onOpenChange: props.onOpenChange,
16
+ mountTo: props.popupsMountPoint,
17
+ boundariesElement: props.popupsBoundariesElement,
18
+ scrollableElement: props.popupsScrollableElement,
19
+ isOpen: props.open,
20
+ fitHeight: 188,
21
+ fitWidth: 175,
22
+ zIndex: akEditorMenuZIndex
23
+ }, /*#__PURE__*/React.createElement(DropDownButton, {
24
+ "aria-expanded": props.open,
25
+ "aria-haspopup": true,
26
+ handleRef: props.onRef,
27
+ selected: props.open,
28
+ disabled: props.disabled,
29
+ onClick: props.onClick,
30
+ onKeyDown: props.onKeyDown,
31
+ spacing: props.spacing,
32
+ label: props.label,
33
+ "aria-keyshortcuts": "/"
34
+ }));
35
+ };