@atlaskit/editor-plugin-insert-block 7.0.27 → 7.0.29
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.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/ui/ToolbarInsertBlock/dropdown-button.js +2 -2
- package/dist/cjs/ui/ToolbarInsertBlock/index.js +3 -2
- package/dist/cjs/ui/ToolbarInsertBlock/item.js +29 -29
- package/dist/cjs/ui/toolbar-components/InsertButton.js +8 -3
- package/dist/cjs/ui/toolbar-components/hooks/filterDropdownItems.js +51 -0
- package/dist/cjs/ui/toolbar-components/hooks/useInsertButtonState.js +12 -2
- package/dist/cjs/ui/toolbar-components.js +167 -21
- package/dist/es2019/ui/ToolbarInsertBlock/dropdown-button.js +1 -1
- package/dist/es2019/ui/ToolbarInsertBlock/index.js +3 -2
- package/dist/es2019/ui/ToolbarInsertBlock/item.js +14 -14
- package/dist/es2019/ui/toolbar-components/InsertButton.js +8 -3
- package/dist/es2019/ui/toolbar-components/hooks/filterDropdownItems.js +44 -0
- package/dist/es2019/ui/toolbar-components/hooks/useInsertButtonState.js +12 -2
- package/dist/es2019/ui/toolbar-components.js +160 -21
- package/dist/esm/ui/ToolbarInsertBlock/dropdown-button.js +1 -1
- package/dist/esm/ui/ToolbarInsertBlock/index.js +3 -2
- package/dist/esm/ui/ToolbarInsertBlock/item.js +14 -14
- package/dist/esm/ui/toolbar-components/InsertButton.js +8 -3
- package/dist/esm/ui/toolbar-components/hooks/filterDropdownItems.js +44 -0
- package/dist/esm/ui/toolbar-components/hooks/useInsertButtonState.js +12 -2
- package/dist/esm/ui/toolbar-components.js +167 -21
- package/dist/types/ui/toolbar-components/InsertButton.d.ts +5 -1
- package/dist/types/ui/toolbar-components/TableSizePicker.d.ts +1 -1
- package/dist/types/ui/toolbar-components/hooks/filterDropdownItems.d.ts +5 -0
- package/dist/types/ui/toolbar-components/hooks/useInsertButtonState.d.ts +6 -2
- package/dist/types-ts4.5/ui/toolbar-components/InsertButton.d.ts +5 -1
- package/dist/types-ts4.5/ui/toolbar-components/TableSizePicker.d.ts +1 -1
- package/dist/types-ts4.5/ui/toolbar-components/hooks/filterDropdownItems.d.ts +5 -0
- package/dist/types-ts4.5/ui/toolbar-components/hooks/useInsertButtonState.d.ts +6 -2
- package/package.json +12 -9
|
@@ -11,6 +11,7 @@ import { ToolbarButton, ToolbarTooltip, AddIcon, useToolbarUI } from '@atlaskit/
|
|
|
11
11
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
12
12
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
13
13
|
import InsertMenu, { DEFAULT_HEIGHT } from '../ElementBrowser/InsertMenu';
|
|
14
|
+
import { LINK_BUTTON_KEY } from './hooks/filterDropdownItems';
|
|
14
15
|
import { useEmojiPickerPopup } from './hooks/useEmojiPickerPopup';
|
|
15
16
|
import { useInsertButtonState } from './hooks/useInsertButtonState';
|
|
16
17
|
import { useTableSelectorPopup } from './hooks/useTableSelectorPopup';
|
|
@@ -22,6 +23,7 @@ import { EmojiPickerPopup } from './popups/EmojiPickerPopup';
|
|
|
22
23
|
const FIT_HEIGHT_BUFFER = 100;
|
|
23
24
|
export const InsertButton = ({
|
|
24
25
|
api,
|
|
26
|
+
breakpoint,
|
|
25
27
|
showElementBrowserLink = false,
|
|
26
28
|
isFullPageAppearance = false,
|
|
27
29
|
tableSelectorSupported,
|
|
@@ -30,7 +32,8 @@ export const InsertButton = ({
|
|
|
30
32
|
expandEnabled,
|
|
31
33
|
insertMenuItems,
|
|
32
34
|
numberOfButtons,
|
|
33
|
-
onInsertBlockType
|
|
35
|
+
onInsertBlockType,
|
|
36
|
+
toolbarConfig
|
|
34
37
|
}) => {
|
|
35
38
|
const {
|
|
36
39
|
editorView
|
|
@@ -61,6 +64,7 @@ export const InsertButton = ({
|
|
|
61
64
|
isTypeAheadAllowed
|
|
62
65
|
} = useInsertButtonState({
|
|
63
66
|
api,
|
|
67
|
+
breakpoint,
|
|
64
68
|
editorView: editorView || undefined,
|
|
65
69
|
horizontalRuleEnabled,
|
|
66
70
|
insertMenuItems,
|
|
@@ -68,7 +72,8 @@ export const InsertButton = ({
|
|
|
68
72
|
numberOfButtons,
|
|
69
73
|
tableSelectorSupported,
|
|
70
74
|
expandEnabled,
|
|
71
|
-
showElementBrowserLink
|
|
75
|
+
showElementBrowserLink,
|
|
76
|
+
toolbarConfig
|
|
72
77
|
});
|
|
73
78
|
if (!(api !== null && api !== void 0 && api.insertBlock)) {
|
|
74
79
|
return null;
|
|
@@ -100,7 +105,7 @@ export const InsertButton = ({
|
|
|
100
105
|
editorView.focus();
|
|
101
106
|
}
|
|
102
107
|
switch (item.value.name) {
|
|
103
|
-
case
|
|
108
|
+
case LINK_BUTTON_KEY:
|
|
104
109
|
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$hyperlink = api.hyperlink) === null || _api$hyperlink === void 0 ? void 0 : _api$hyperlink.commands.showLinkToolbar(inputMethod));
|
|
105
110
|
break;
|
|
106
111
|
case 'table':
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const ITEM_TO_BUTTON_MAP = {
|
|
2
|
+
action: 'taskList',
|
|
3
|
+
media: 'media',
|
|
4
|
+
'image upload': 'media',
|
|
5
|
+
mention: 'mention',
|
|
6
|
+
emoji: 'emoji',
|
|
7
|
+
table: 'table',
|
|
8
|
+
layout: 'layout',
|
|
9
|
+
codeblock: 'codeBlock'
|
|
10
|
+
};
|
|
11
|
+
export const LINK_BUTTON_KEY = 'link';
|
|
12
|
+
const BREAKPOINT_ORDER = ['sm', 'md', 'lg', 'xl'];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Determines if a toolbar button is visible at the current breakpoint.
|
|
16
|
+
*/
|
|
17
|
+
function isButtonVisibleAtBreakpoint(buttonShowAt, currentBreakpoint) {
|
|
18
|
+
if (!currentBreakpoint) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const showAtIndex = BREAKPOINT_ORDER.indexOf(buttonShowAt);
|
|
22
|
+
const currentIndex = BREAKPOINT_ORDER.indexOf(currentBreakpoint);
|
|
23
|
+
return currentIndex >= showAtIndex;
|
|
24
|
+
}
|
|
25
|
+
export function filterDropdownItemsByBreakpoint(items, currentBreakpoint, toolbarConfig) {
|
|
26
|
+
return items.filter(item => {
|
|
27
|
+
const itemName = item.value.name;
|
|
28
|
+
// filter out link button because it's always visible on the toolbar
|
|
29
|
+
if (itemName === LINK_BUTTON_KEY) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const buttonKey = ITEM_TO_BUTTON_MAP[itemName];
|
|
33
|
+
if (!buttonKey) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
const buttonConfig = toolbarConfig[buttonKey];
|
|
37
|
+
if (!(buttonConfig !== null && buttonConfig !== void 0 && buttonConfig.enabled)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
const showAt = buttonConfig.showAt || 'lg';
|
|
41
|
+
const isVisible = isButtonVisibleAtBreakpoint(showAt, currentBreakpoint);
|
|
42
|
+
return !isVisible;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
1
2
|
import { useIntl } from 'react-intl-next';
|
|
2
3
|
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
3
4
|
import { createItems } from '../../ToolbarInsertBlock/create-items';
|
|
5
|
+
import { filterDropdownItemsByBreakpoint } from './filterDropdownItems';
|
|
4
6
|
export const useInsertButtonState = ({
|
|
5
7
|
api,
|
|
8
|
+
breakpoint,
|
|
6
9
|
editorView,
|
|
7
10
|
horizontalRuleEnabled,
|
|
8
11
|
insertMenuItems,
|
|
@@ -10,7 +13,8 @@ export const useInsertButtonState = ({
|
|
|
10
13
|
numberOfButtons,
|
|
11
14
|
tableSelectorSupported,
|
|
12
15
|
expandEnabled,
|
|
13
|
-
showElementBrowserLink
|
|
16
|
+
showElementBrowserLink,
|
|
17
|
+
toolbarConfig
|
|
14
18
|
}) => {
|
|
15
19
|
const {
|
|
16
20
|
formatMessage
|
|
@@ -40,7 +44,7 @@ export const useInsertButtonState = ({
|
|
|
40
44
|
const actionSupported = !!(editorView !== null && editorView !== void 0 && editorView.state.schema.nodes.taskItem);
|
|
41
45
|
const decisionSupported = !!(editorView !== null && editorView !== void 0 && editorView.state.schema.nodes.decisionItem);
|
|
42
46
|
const layoutSectionEnabled = !!(api !== null && api !== void 0 && api.layout);
|
|
43
|
-
const [,
|
|
47
|
+
const [, allDropdownItems] = editorView !== null && editorView !== void 0 && editorView.state.schema ? createItems({
|
|
44
48
|
isTypeAheadAllowed: isTypeAheadAllowed,
|
|
45
49
|
tableSupported: !!(editorView !== null && editorView !== void 0 && editorView.state.schema.nodes.table),
|
|
46
50
|
tableSelectorSupported,
|
|
@@ -73,6 +77,12 @@ export const useInsertButtonState = ({
|
|
|
73
77
|
numberOfButtons: numberOfButtons || 0,
|
|
74
78
|
formatMessage
|
|
75
79
|
}) : [, []];
|
|
80
|
+
const dropdownItems = useMemo(() => {
|
|
81
|
+
if (!breakpoint || !toolbarConfig) {
|
|
82
|
+
return allDropdownItems;
|
|
83
|
+
}
|
|
84
|
+
return filterDropdownItemsByBreakpoint(allDropdownItems, breakpoint, toolbarConfig);
|
|
85
|
+
}, [allDropdownItems, breakpoint, toolbarConfig]);
|
|
76
86
|
return {
|
|
77
87
|
dropdownItems,
|
|
78
88
|
emojiProvider,
|
|
@@ -240,25 +240,11 @@ export const getToolbarComponents = ({
|
|
|
240
240
|
|
|
241
241
|
// Insert Group
|
|
242
242
|
if ((_config$insert = config.insert) !== null && _config$insert !== void 0 && _config$insert.enabled) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
key: INSERT_GROUP.key,
|
|
246
|
-
parents: [{
|
|
247
|
-
type: INSERT_BLOCK_SECTION.type,
|
|
248
|
-
key: INSERT_BLOCK_SECTION.key,
|
|
249
|
-
rank: INSERT_BLOCK_SECTION_RANK[INSERT_GROUP.key]
|
|
250
|
-
}]
|
|
251
|
-
});
|
|
252
|
-
components.push({
|
|
253
|
-
type: INSERT_BUTTON.type,
|
|
254
|
-
key: INSERT_BUTTON.key,
|
|
255
|
-
parents: [{
|
|
256
|
-
type: INSERT_GROUP.type,
|
|
257
|
-
key: INSERT_GROUP.key,
|
|
258
|
-
rank: INSERT_GROUP_RANK[INSERT_BUTTON.key]
|
|
259
|
-
}],
|
|
260
|
-
component: () => /*#__PURE__*/React.createElement(InsertButton, {
|
|
243
|
+
const createInsertButtonComponent = breakpoint => {
|
|
244
|
+
return () => /*#__PURE__*/React.createElement(InsertButton, {
|
|
261
245
|
api: api,
|
|
246
|
+
breakpoint: breakpoint,
|
|
247
|
+
toolbarConfig: config,
|
|
262
248
|
showElementBrowserLink: options.showElementBrowserLink,
|
|
263
249
|
tableSelectorSupported: options.tableSelectorSupported,
|
|
264
250
|
onInsertBlockType: onInsertBlockType,
|
|
@@ -266,9 +252,162 @@ export const getToolbarComponents = ({
|
|
|
266
252
|
horizontalRuleEnabled: options.horizontalRuleEnabled,
|
|
267
253
|
expandEnabled: options.allowExpand,
|
|
268
254
|
insertMenuItems: options.insertMenuItems,
|
|
269
|
-
numberOfButtons:
|
|
270
|
-
})
|
|
271
|
-
}
|
|
255
|
+
numberOfButtons: 0
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
if (fg('platform_editor_toolbar_aifc_ga_blockers')) {
|
|
259
|
+
components.push({
|
|
260
|
+
type: INSERT_GROUP.type,
|
|
261
|
+
key: `${INSERT_GROUP.key}-none`,
|
|
262
|
+
parents: [{
|
|
263
|
+
type: INSERT_BLOCK_SECTION.type,
|
|
264
|
+
key: INSERT_BLOCK_SECTION.key,
|
|
265
|
+
rank: INSERT_BLOCK_SECTION_RANK[INSERT_GROUP.key]
|
|
266
|
+
}],
|
|
267
|
+
component: ({
|
|
268
|
+
children
|
|
269
|
+
}) => /*#__PURE__*/React.createElement(Show, {
|
|
270
|
+
below: "sm"
|
|
271
|
+
}, /*#__PURE__*/React.createElement(ToolbarButtonGroup, null, children))
|
|
272
|
+
});
|
|
273
|
+
components.push({
|
|
274
|
+
type: INSERT_BUTTON.type,
|
|
275
|
+
key: INSERT_BUTTON.key,
|
|
276
|
+
parents: [{
|
|
277
|
+
type: INSERT_GROUP.type,
|
|
278
|
+
key: `${INSERT_GROUP.key}-none`,
|
|
279
|
+
rank: INSERT_GROUP_RANK[INSERT_BUTTON.key]
|
|
280
|
+
}],
|
|
281
|
+
component: createInsertButtonComponent(null)
|
|
282
|
+
});
|
|
283
|
+
components.push({
|
|
284
|
+
type: INSERT_GROUP.type,
|
|
285
|
+
key: `${INSERT_GROUP.key}-sm`,
|
|
286
|
+
parents: [{
|
|
287
|
+
type: INSERT_BLOCK_SECTION.type,
|
|
288
|
+
key: INSERT_BLOCK_SECTION.key,
|
|
289
|
+
rank: INSERT_BLOCK_SECTION_RANK[INSERT_GROUP.key]
|
|
290
|
+
}],
|
|
291
|
+
component: ({
|
|
292
|
+
children
|
|
293
|
+
}) => /*#__PURE__*/React.createElement(Show, {
|
|
294
|
+
only: "sm"
|
|
295
|
+
}, /*#__PURE__*/React.createElement(ToolbarButtonGroup, null, children))
|
|
296
|
+
});
|
|
297
|
+
components.push({
|
|
298
|
+
type: INSERT_BUTTON.type,
|
|
299
|
+
key: INSERT_BUTTON.key,
|
|
300
|
+
parents: [{
|
|
301
|
+
type: INSERT_GROUP.type,
|
|
302
|
+
key: `${INSERT_GROUP.key}-sm`,
|
|
303
|
+
rank: INSERT_GROUP_RANK[INSERT_BUTTON.key]
|
|
304
|
+
}],
|
|
305
|
+
component: createInsertButtonComponent('sm')
|
|
306
|
+
});
|
|
307
|
+
components.push({
|
|
308
|
+
type: INSERT_GROUP.type,
|
|
309
|
+
key: `${INSERT_GROUP.key}-md`,
|
|
310
|
+
parents: [{
|
|
311
|
+
type: INSERT_BLOCK_SECTION.type,
|
|
312
|
+
key: INSERT_BLOCK_SECTION.key,
|
|
313
|
+
rank: INSERT_BLOCK_SECTION_RANK[INSERT_GROUP.key]
|
|
314
|
+
}],
|
|
315
|
+
component: ({
|
|
316
|
+
children
|
|
317
|
+
}) => /*#__PURE__*/React.createElement(Show, {
|
|
318
|
+
only: "md"
|
|
319
|
+
}, /*#__PURE__*/React.createElement(ToolbarButtonGroup, null, children))
|
|
320
|
+
});
|
|
321
|
+
components.push({
|
|
322
|
+
type: INSERT_BUTTON.type,
|
|
323
|
+
key: INSERT_BUTTON.key,
|
|
324
|
+
parents: [{
|
|
325
|
+
type: INSERT_GROUP.type,
|
|
326
|
+
key: `${INSERT_GROUP.key}-md`,
|
|
327
|
+
rank: INSERT_GROUP_RANK[INSERT_BUTTON.key]
|
|
328
|
+
}],
|
|
329
|
+
component: createInsertButtonComponent('md')
|
|
330
|
+
});
|
|
331
|
+
components.push({
|
|
332
|
+
type: INSERT_GROUP.type,
|
|
333
|
+
key: `${INSERT_GROUP.key}-lg`,
|
|
334
|
+
parents: [{
|
|
335
|
+
type: INSERT_BLOCK_SECTION.type,
|
|
336
|
+
key: INSERT_BLOCK_SECTION.key,
|
|
337
|
+
rank: INSERT_BLOCK_SECTION_RANK[INSERT_GROUP.key]
|
|
338
|
+
}],
|
|
339
|
+
component: ({
|
|
340
|
+
children
|
|
341
|
+
}) => /*#__PURE__*/React.createElement(Show, {
|
|
342
|
+
only: "lg"
|
|
343
|
+
}, /*#__PURE__*/React.createElement(ToolbarButtonGroup, null, children))
|
|
344
|
+
});
|
|
345
|
+
components.push({
|
|
346
|
+
type: INSERT_BUTTON.type,
|
|
347
|
+
key: INSERT_BUTTON.key,
|
|
348
|
+
parents: [{
|
|
349
|
+
type: INSERT_GROUP.type,
|
|
350
|
+
key: `${INSERT_GROUP.key}-lg`,
|
|
351
|
+
rank: INSERT_GROUP_RANK[INSERT_BUTTON.key]
|
|
352
|
+
}],
|
|
353
|
+
component: createInsertButtonComponent('lg')
|
|
354
|
+
});
|
|
355
|
+
components.push({
|
|
356
|
+
type: INSERT_GROUP.type,
|
|
357
|
+
key: `${INSERT_GROUP.key}-xl`,
|
|
358
|
+
parents: [{
|
|
359
|
+
type: INSERT_BLOCK_SECTION.type,
|
|
360
|
+
key: INSERT_BLOCK_SECTION.key,
|
|
361
|
+
rank: INSERT_BLOCK_SECTION_RANK[INSERT_GROUP.key]
|
|
362
|
+
}],
|
|
363
|
+
component: ({
|
|
364
|
+
children
|
|
365
|
+
}) => /*#__PURE__*/React.createElement(Show, {
|
|
366
|
+
only: "xl"
|
|
367
|
+
}, /*#__PURE__*/React.createElement(ToolbarButtonGroup, null, children))
|
|
368
|
+
});
|
|
369
|
+
components.push({
|
|
370
|
+
type: INSERT_BUTTON.type,
|
|
371
|
+
key: INSERT_BUTTON.key,
|
|
372
|
+
parents: [{
|
|
373
|
+
type: INSERT_GROUP.type,
|
|
374
|
+
key: `${INSERT_GROUP.key}-xl`,
|
|
375
|
+
rank: INSERT_GROUP_RANK[INSERT_BUTTON.key]
|
|
376
|
+
}],
|
|
377
|
+
component: createInsertButtonComponent('xl')
|
|
378
|
+
});
|
|
379
|
+
} else {
|
|
380
|
+
components.push({
|
|
381
|
+
type: INSERT_GROUP.type,
|
|
382
|
+
key: INSERT_GROUP.key,
|
|
383
|
+
parents: [{
|
|
384
|
+
type: INSERT_BLOCK_SECTION.type,
|
|
385
|
+
key: INSERT_BLOCK_SECTION.key,
|
|
386
|
+
rank: INSERT_BLOCK_SECTION_RANK[INSERT_GROUP.key]
|
|
387
|
+
}]
|
|
388
|
+
});
|
|
389
|
+
components.push({
|
|
390
|
+
type: INSERT_BUTTON.type,
|
|
391
|
+
key: INSERT_BUTTON.key,
|
|
392
|
+
parents: [{
|
|
393
|
+
type: INSERT_GROUP.type,
|
|
394
|
+
key: INSERT_GROUP.key,
|
|
395
|
+
rank: INSERT_GROUP_RANK[INSERT_BUTTON.key]
|
|
396
|
+
}],
|
|
397
|
+
component: () => /*#__PURE__*/React.createElement(InsertButton, {
|
|
398
|
+
api: api,
|
|
399
|
+
toolbarConfig: config,
|
|
400
|
+
showElementBrowserLink: options.showElementBrowserLink,
|
|
401
|
+
tableSelectorSupported: options.tableSelectorSupported,
|
|
402
|
+
onInsertBlockType: onInsertBlockType,
|
|
403
|
+
nativeStatusSupported: options.nativeStatusSupported,
|
|
404
|
+
horizontalRuleEnabled: options.horizontalRuleEnabled,
|
|
405
|
+
expandEnabled: options.allowExpand,
|
|
406
|
+
insertMenuItems: options.insertMenuItems,
|
|
407
|
+
numberOfButtons: 7 // TODO: ED-28759 - Default to 7 buttons - Remove this once we have a proper way to do toolbar responsiveness
|
|
408
|
+
})
|
|
409
|
+
});
|
|
410
|
+
}
|
|
272
411
|
}
|
|
273
412
|
return components;
|
|
274
413
|
};
|
|
@@ -8,7 +8,7 @@ import React from 'react';
|
|
|
8
8
|
import { jsx } from '@emotion/react';
|
|
9
9
|
import { ToolTipContent } from '@atlaskit/editor-common/keymaps';
|
|
10
10
|
import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
11
|
-
import AddIcon from '@atlaskit/icon/core/
|
|
11
|
+
import AddIcon from '@atlaskit/icon/core/add';
|
|
12
12
|
import ChevronDownIcon from '@atlaskit/icon/core/migration/chevron-down';
|
|
13
13
|
import { triggerWrapper } from './styles';
|
|
14
14
|
var DropDownButtonIcon = /*#__PURE__*/React.memo(function (props) {
|
|
@@ -38,6 +38,7 @@ import { EmojiPicker as AkEmojiPicker } from '@atlaskit/emoji/picker';
|
|
|
38
38
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
39
39
|
import { N20A, N30A } from '@atlaskit/theme/colors';
|
|
40
40
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
41
|
+
import { LINK_BUTTON_KEY } from '../toolbar-components/hooks/filterDropdownItems';
|
|
41
42
|
import { BlockInsertMenu } from './block-insert-menu';
|
|
42
43
|
import { createItems } from './create-items';
|
|
43
44
|
// Ignored via go/ees005
|
|
@@ -222,7 +223,7 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
222
223
|
}
|
|
223
224
|
});
|
|
224
225
|
_defineProperty(_this, "toggleTableSelector", function () {
|
|
225
|
-
var
|
|
226
|
+
var _inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INPUT_METHOD.TOOLBAR;
|
|
226
227
|
_this.setState(function (prevState) {
|
|
227
228
|
return {
|
|
228
229
|
isTableSelectorOpen: !prevState.isTableSelectorOpen
|
|
@@ -445,7 +446,7 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
445
446
|
editorView.focus();
|
|
446
447
|
}
|
|
447
448
|
switch (item.value.name) {
|
|
448
|
-
case
|
|
449
|
+
case LINK_BUTTON_KEY:
|
|
449
450
|
_this.toggleLinkPanel(inputMethod);
|
|
450
451
|
break;
|
|
451
452
|
case 'table':
|
|
@@ -11,21 +11,21 @@ import { addLink, getAriaKeyshortcuts, toggleTable, tooltip } from '@atlaskit/ed
|
|
|
11
11
|
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
12
12
|
import FieldTextIcon from '@atlaskit/icon-lab/core/field-text';
|
|
13
13
|
import LozengeIcon from '@atlaskit/icon-lab/core/lozenge';
|
|
14
|
-
import AngleBracketsIcon from '@atlaskit/icon/core/
|
|
15
|
-
import CalendarIcon from '@atlaskit/icon/core/
|
|
14
|
+
import AngleBracketsIcon from '@atlaskit/icon/core/angle-brackets';
|
|
15
|
+
import CalendarIcon from '@atlaskit/icon/core/calendar';
|
|
16
|
+
import ExpandNodeIcon from '@atlaskit/icon/core/chevron-right';
|
|
17
|
+
import DecisionIcon from '@atlaskit/icon/core/decision';
|
|
18
|
+
import EmojiIcon from '@atlaskit/icon/core/emoji';
|
|
19
|
+
import GridIcon from '@atlaskit/icon/core/grid';
|
|
20
|
+
import ImageIcon from '@atlaskit/icon/core/image';
|
|
21
|
+
import LayoutTwoColumnsIcon from '@atlaskit/icon/core/layout-two-columns';
|
|
22
|
+
import LinkIcon from '@atlaskit/icon/core/link';
|
|
23
|
+
import MentionIcon from '@atlaskit/icon/core/mention';
|
|
16
24
|
import ChevronDownIcon from '@atlaskit/icon/core/migration/chevron-down';
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import ImageIcon from '@atlaskit/icon/core/migration/image--editor-image';
|
|
22
|
-
import LayoutTwoColumnsIcon from '@atlaskit/icon/core/migration/layout-two-columns--editor-layout-two-equal';
|
|
23
|
-
import LinkIcon from '@atlaskit/icon/core/migration/link--editor-link';
|
|
24
|
-
import MentionIcon from '@atlaskit/icon/core/migration/mention--editor-mention';
|
|
25
|
-
import HorizontalRuleIcon from '@atlaskit/icon/core/migration/minus--editor-horizontal-rule';
|
|
26
|
-
import QuotationMarkIcon from '@atlaskit/icon/core/migration/quotation-mark--quote';
|
|
27
|
-
import ShowMoreHorizontalIcon from '@atlaskit/icon/core/migration/show-more-horizontal--editor-more';
|
|
28
|
-
import InformationIcon from '@atlaskit/icon/core/migration/status-information--editor-info';
|
|
25
|
+
import HorizontalRuleIcon from '@atlaskit/icon/core/minus';
|
|
26
|
+
import QuotationMarkIcon from '@atlaskit/icon/core/quotation-mark';
|
|
27
|
+
import ShowMoreHorizontalIcon from '@atlaskit/icon/core/show-more-horizontal';
|
|
28
|
+
import InformationIcon from '@atlaskit/icon/core/status-information';
|
|
29
29
|
import TaskIcon from '@atlaskit/icon/core/task';
|
|
30
30
|
import CheckboxCheckedIconLegacy from '@atlaskit/icon/glyph/editor/task';
|
|
31
31
|
import PlaceholderTextIcon from '@atlaskit/icon/glyph/media-services/text';
|
|
@@ -12,6 +12,7 @@ import { ToolbarButton, ToolbarTooltip, AddIcon, useToolbarUI } from '@atlaskit/
|
|
|
12
12
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
13
13
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
14
14
|
import InsertMenu, { DEFAULT_HEIGHT } from '../ElementBrowser/InsertMenu';
|
|
15
|
+
import { LINK_BUTTON_KEY } from './hooks/filterDropdownItems';
|
|
15
16
|
import { useEmojiPickerPopup } from './hooks/useEmojiPickerPopup';
|
|
16
17
|
import { useInsertButtonState } from './hooks/useInsertButtonState';
|
|
17
18
|
import { useTableSelectorPopup } from './hooks/useTableSelectorPopup';
|
|
@@ -23,6 +24,7 @@ import { EmojiPickerPopup } from './popups/EmojiPickerPopup';
|
|
|
23
24
|
var FIT_HEIGHT_BUFFER = 100;
|
|
24
25
|
export var InsertButton = function InsertButton(_ref) {
|
|
25
26
|
var api = _ref.api,
|
|
27
|
+
breakpoint = _ref.breakpoint,
|
|
26
28
|
_ref$showElementBrows = _ref.showElementBrowserLink,
|
|
27
29
|
showElementBrowserLink = _ref$showElementBrows === void 0 ? false : _ref$showElementBrows,
|
|
28
30
|
_ref$isFullPageAppear = _ref.isFullPageAppearance,
|
|
@@ -33,7 +35,8 @@ export var InsertButton = function InsertButton(_ref) {
|
|
|
33
35
|
expandEnabled = _ref.expandEnabled,
|
|
34
36
|
insertMenuItems = _ref.insertMenuItems,
|
|
35
37
|
numberOfButtons = _ref.numberOfButtons,
|
|
36
|
-
onInsertBlockType = _ref.onInsertBlockType
|
|
38
|
+
onInsertBlockType = _ref.onInsertBlockType,
|
|
39
|
+
toolbarConfig = _ref.toolbarConfig;
|
|
37
40
|
var _useEditorToolbar = useEditorToolbar(),
|
|
38
41
|
editorView = _useEditorToolbar.editorView;
|
|
39
42
|
var _useToolbarUI = useToolbarUI(),
|
|
@@ -59,6 +62,7 @@ export var InsertButton = function InsertButton(_ref) {
|
|
|
59
62
|
var showMediaPicker = useSharedPluginStateSelector(api, 'media.showMediaPicker');
|
|
60
63
|
var _useInsertButtonState = useInsertButtonState({
|
|
61
64
|
api: api,
|
|
65
|
+
breakpoint: breakpoint,
|
|
62
66
|
editorView: editorView || undefined,
|
|
63
67
|
horizontalRuleEnabled: horizontalRuleEnabled,
|
|
64
68
|
insertMenuItems: insertMenuItems,
|
|
@@ -66,7 +70,8 @@ export var InsertButton = function InsertButton(_ref) {
|
|
|
66
70
|
numberOfButtons: numberOfButtons,
|
|
67
71
|
tableSelectorSupported: tableSelectorSupported,
|
|
68
72
|
expandEnabled: expandEnabled,
|
|
69
|
-
showElementBrowserLink: showElementBrowserLink
|
|
73
|
+
showElementBrowserLink: showElementBrowserLink,
|
|
74
|
+
toolbarConfig: toolbarConfig
|
|
70
75
|
}),
|
|
71
76
|
dropdownItems = _useInsertButtonState.dropdownItems,
|
|
72
77
|
emojiProvider = _useInsertButtonState.emojiProvider,
|
|
@@ -100,7 +105,7 @@ export var InsertButton = function InsertButton(_ref) {
|
|
|
100
105
|
editorView.focus();
|
|
101
106
|
}
|
|
102
107
|
switch (item.value.name) {
|
|
103
|
-
case
|
|
108
|
+
case LINK_BUTTON_KEY:
|
|
104
109
|
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$hyperlink = api.hyperlink) === null || _api$hyperlink === void 0 ? void 0 : _api$hyperlink.commands.showLinkToolbar(inputMethod));
|
|
105
110
|
break;
|
|
106
111
|
case 'table':
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var ITEM_TO_BUTTON_MAP = {
|
|
2
|
+
action: 'taskList',
|
|
3
|
+
media: 'media',
|
|
4
|
+
'image upload': 'media',
|
|
5
|
+
mention: 'mention',
|
|
6
|
+
emoji: 'emoji',
|
|
7
|
+
table: 'table',
|
|
8
|
+
layout: 'layout',
|
|
9
|
+
codeblock: 'codeBlock'
|
|
10
|
+
};
|
|
11
|
+
export var LINK_BUTTON_KEY = 'link';
|
|
12
|
+
var BREAKPOINT_ORDER = ['sm', 'md', 'lg', 'xl'];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Determines if a toolbar button is visible at the current breakpoint.
|
|
16
|
+
*/
|
|
17
|
+
function isButtonVisibleAtBreakpoint(buttonShowAt, currentBreakpoint) {
|
|
18
|
+
if (!currentBreakpoint) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
var showAtIndex = BREAKPOINT_ORDER.indexOf(buttonShowAt);
|
|
22
|
+
var currentIndex = BREAKPOINT_ORDER.indexOf(currentBreakpoint);
|
|
23
|
+
return currentIndex >= showAtIndex;
|
|
24
|
+
}
|
|
25
|
+
export function filterDropdownItemsByBreakpoint(items, currentBreakpoint, toolbarConfig) {
|
|
26
|
+
return items.filter(function (item) {
|
|
27
|
+
var itemName = item.value.name;
|
|
28
|
+
// filter out link button because it's always visible on the toolbar
|
|
29
|
+
if (itemName === LINK_BUTTON_KEY) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
var buttonKey = ITEM_TO_BUTTON_MAP[itemName];
|
|
33
|
+
if (!buttonKey) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
var buttonConfig = toolbarConfig[buttonKey];
|
|
37
|
+
if (!(buttonConfig !== null && buttonConfig !== void 0 && buttonConfig.enabled)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
var showAt = buttonConfig.showAt || 'lg';
|
|
41
|
+
var isVisible = isButtonVisibleAtBreakpoint(showAt, currentBreakpoint);
|
|
42
|
+
return !isVisible;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { useMemo } from 'react';
|
|
2
3
|
import { useIntl } from 'react-intl-next';
|
|
3
4
|
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
4
5
|
import { createItems } from '../../ToolbarInsertBlock/create-items';
|
|
6
|
+
import { filterDropdownItemsByBreakpoint } from './filterDropdownItems';
|
|
5
7
|
export var useInsertButtonState = function useInsertButtonState(_ref) {
|
|
6
8
|
var api = _ref.api,
|
|
9
|
+
breakpoint = _ref.breakpoint,
|
|
7
10
|
editorView = _ref.editorView,
|
|
8
11
|
horizontalRuleEnabled = _ref.horizontalRuleEnabled,
|
|
9
12
|
insertMenuItems = _ref.insertMenuItems,
|
|
@@ -11,7 +14,8 @@ export var useInsertButtonState = function useInsertButtonState(_ref) {
|
|
|
11
14
|
numberOfButtons = _ref.numberOfButtons,
|
|
12
15
|
tableSelectorSupported = _ref.tableSelectorSupported,
|
|
13
16
|
expandEnabled = _ref.expandEnabled,
|
|
14
|
-
showElementBrowserLink = _ref.showElementBrowserLink
|
|
17
|
+
showElementBrowserLink = _ref.showElementBrowserLink,
|
|
18
|
+
toolbarConfig = _ref.toolbarConfig;
|
|
15
19
|
var _useIntl = useIntl(),
|
|
16
20
|
formatMessage = _useIntl.formatMessage;
|
|
17
21
|
var isTypeAheadAllowed = useSharedPluginStateSelector(api, 'typeAhead.isAllowed');
|
|
@@ -73,7 +77,13 @@ export var useInsertButtonState = function useInsertButtonState(_ref) {
|
|
|
73
77
|
formatMessage: formatMessage
|
|
74
78
|
}) : [, []],
|
|
75
79
|
_ref3 = _slicedToArray(_ref2, 2),
|
|
76
|
-
|
|
80
|
+
allDropdownItems = _ref3[1];
|
|
81
|
+
var dropdownItems = useMemo(function () {
|
|
82
|
+
if (!breakpoint || !toolbarConfig) {
|
|
83
|
+
return allDropdownItems;
|
|
84
|
+
}
|
|
85
|
+
return filterDropdownItemsByBreakpoint(allDropdownItems, breakpoint, toolbarConfig);
|
|
86
|
+
}, [allDropdownItems, breakpoint, toolbarConfig]);
|
|
77
87
|
return {
|
|
78
88
|
dropdownItems: dropdownItems,
|
|
79
89
|
emojiProvider: emojiProvider,
|