@atlaskit/editor-plugin-insert-block 7.0.0 → 7.0.2

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.
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
- import { INSERT_BLOCK_SECTION, TASK_LIST_GROUP, MEDIA_GROUP, INSERT_BLOCK_SECTION_RANK, TASK_LIST_BUTTON, TASK_LIST_GROUP_RANK, MEDIA_BUTTON, MENTION_GROUP, MEDIA_GROUP_RANK, MENTION_BUTTON, MENTION_GROUP_RANK, EMOJI_GROUP, EMOJI_BUTTON, EMOJI_GROUP_RANK, LAYOUT_GROUP, LAYOUT_BUTTON, LAYOUT_GROUP_RANK, TABLE_GROUP_RANK, TABLE_BUTTON, TABLE_GROUP, TABLE_SIZE_PICKER, INSERT_GROUP, INSERT_BUTTON, INSERT_GROUP_RANK } from '@atlaskit/editor-common/toolbar';
2
+ import { INSERT_BLOCK_SECTION, TASK_LIST_GROUP, MEDIA_GROUP, INSERT_BLOCK_SECTION_RANK, TASK_LIST_BUTTON, TASK_LIST_GROUP_RANK, MEDIA_BUTTON, MENTION_GROUP, MEDIA_GROUP_RANK, MENTION_BUTTON, MENTION_GROUP_RANK, EMOJI_GROUP, EMOJI_BUTTON, EMOJI_GROUP_RANK, LAYOUT_GROUP, LAYOUT_BUTTON, LAYOUT_GROUP_RANK, TABLE_GROUP_RANK, TABLE_BUTTON, TABLE_GROUP, TABLE_SIZE_PICKER, INSERT_GROUP, INSERT_BUTTON, INSERT_GROUP_RANK, CODE_BLOCK_GROUP, CODE_BLOCK_BUTTON, CODE_BLOCK_GROUP_RANK } from '@atlaskit/editor-common/toolbar';
3
3
  import { Show, ToolbarButtonGroup } from '@atlaskit/editor-toolbar';
4
4
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
5
+ import { CodeBlockButton } from './toolbar-components/CodeBlockButton';
6
+ import { resolveToolbarConfig } from './toolbar-components/config-resolver';
5
7
  import { EmojiButton } from './toolbar-components/EmojiButton';
6
8
  import { ImageButton } from './toolbar-components/ImageButton';
7
9
  import { InsertButton } from './toolbar-components/InsertButton';
@@ -234,4 +236,275 @@ export const getToolbarComponents = ({
234
236
  numberOfButtons: 7 // TODO: ED-28759 - Default to 7 buttons - Remove this once we have a proper way to do toolbar responsiveness
235
237
  })
236
238
  }])];
239
+ };
240
+
241
+ /**
242
+ * Updated toolbar components function that uses the new configuration resolver.
243
+ * This function replaces the hardcoded approach with a config-driven one.
244
+ */
245
+ export const getToolbarComponentsUpdated = ({
246
+ api,
247
+ options,
248
+ onInsertBlockType
249
+ }) => {
250
+ var _config$taskList, _config$media, _config$codeBlock, _config$mention, _config$emoji, _config$layout, _config$table, _config$insert;
251
+ const config = resolveToolbarConfig(options);
252
+ const components = [];
253
+
254
+ // Helper function to create responsive wrapper component
255
+ const createResponsiveComponent = () => {
256
+ return expValEquals('platform_editor_toolbar_aifc_responsive', 'isEnabled', true) ? ({
257
+ children
258
+ }) => /*#__PURE__*/React.createElement(Show, {
259
+ above: "lg"
260
+ }, /*#__PURE__*/React.createElement(ToolbarButtonGroup, null, children)) : undefined;
261
+ };
262
+
263
+ // TaskList Group
264
+ if ((_config$taskList = config.taskList) !== null && _config$taskList !== void 0 && _config$taskList.enabled) {
265
+ components.push({
266
+ type: TASK_LIST_GROUP.type,
267
+ key: TASK_LIST_GROUP.key,
268
+ parents: [{
269
+ type: INSERT_BLOCK_SECTION.type,
270
+ key: INSERT_BLOCK_SECTION.key,
271
+ rank: INSERT_BLOCK_SECTION_RANK[TASK_LIST_GROUP.key]
272
+ }],
273
+ component: createResponsiveComponent()
274
+ });
275
+ components.push({
276
+ type: TASK_LIST_BUTTON.type,
277
+ key: TASK_LIST_BUTTON.key,
278
+ parents: [{
279
+ type: TASK_LIST_GROUP.type,
280
+ key: TASK_LIST_GROUP.key,
281
+ rank: TASK_LIST_GROUP_RANK[TASK_LIST_BUTTON.key]
282
+ }],
283
+ component: () => /*#__PURE__*/React.createElement(TaskListButton, {
284
+ api: api
285
+ })
286
+ });
287
+ }
288
+
289
+ // Media Group
290
+ if ((_config$media = config.media) !== null && _config$media !== void 0 && _config$media.enabled) {
291
+ components.push({
292
+ type: MEDIA_GROUP.type,
293
+ key: MEDIA_GROUP.key,
294
+ parents: [{
295
+ type: INSERT_BLOCK_SECTION.type,
296
+ key: INSERT_BLOCK_SECTION.key,
297
+ rank: INSERT_BLOCK_SECTION_RANK[MEDIA_GROUP.key]
298
+ }],
299
+ component: createResponsiveComponent()
300
+ });
301
+ components.push({
302
+ type: MEDIA_BUTTON.type,
303
+ key: MEDIA_BUTTON.key,
304
+ parents: [{
305
+ type: MEDIA_GROUP.type,
306
+ key: MEDIA_GROUP.key,
307
+ rank: MEDIA_GROUP_RANK[MEDIA_BUTTON.key]
308
+ }],
309
+ component: () => !!(api !== null && api !== void 0 && api.imageUpload) ? /*#__PURE__*/React.createElement(ImageButton, {
310
+ api: api
311
+ }) : /*#__PURE__*/React.createElement(MediaButton, {
312
+ api: api
313
+ })
314
+ });
315
+ }
316
+
317
+ // CodeBlock Group
318
+ if ((_config$codeBlock = config.codeBlock) !== null && _config$codeBlock !== void 0 && _config$codeBlock.enabled) {
319
+ components.push({
320
+ type: CODE_BLOCK_GROUP.type,
321
+ key: CODE_BLOCK_GROUP.key,
322
+ parents: [{
323
+ type: INSERT_BLOCK_SECTION.type,
324
+ key: INSERT_BLOCK_SECTION.key,
325
+ rank: INSERT_BLOCK_SECTION_RANK[CODE_BLOCK_GROUP.key]
326
+ }],
327
+ component: createResponsiveComponent()
328
+ });
329
+ components.push({
330
+ type: CODE_BLOCK_BUTTON.type,
331
+ key: CODE_BLOCK_BUTTON.key,
332
+ parents: [{
333
+ type: CODE_BLOCK_GROUP.type,
334
+ key: CODE_BLOCK_GROUP.key,
335
+ rank: CODE_BLOCK_GROUP_RANK[CODE_BLOCK_BUTTON.key]
336
+ }],
337
+ component: () => /*#__PURE__*/React.createElement(CodeBlockButton, {
338
+ api: api
339
+ })
340
+ });
341
+ }
342
+
343
+ // Mention Group
344
+ if ((_config$mention = config.mention) !== null && _config$mention !== void 0 && _config$mention.enabled) {
345
+ components.push({
346
+ type: MENTION_GROUP.type,
347
+ key: MENTION_GROUP.key,
348
+ parents: [{
349
+ type: INSERT_BLOCK_SECTION.type,
350
+ key: INSERT_BLOCK_SECTION.key,
351
+ rank: INSERT_BLOCK_SECTION_RANK[MENTION_GROUP.key]
352
+ }],
353
+ component: createResponsiveComponent()
354
+ });
355
+ components.push({
356
+ type: MENTION_BUTTON.type,
357
+ key: MENTION_BUTTON.key,
358
+ parents: [{
359
+ type: MENTION_GROUP.type,
360
+ key: MENTION_GROUP.key,
361
+ rank: MENTION_GROUP_RANK[MENTION_BUTTON.key]
362
+ }],
363
+ component: () => /*#__PURE__*/React.createElement(MentionButton, {
364
+ api: api
365
+ })
366
+ });
367
+ }
368
+
369
+ // Emoji Group
370
+ if ((_config$emoji = config.emoji) !== null && _config$emoji !== void 0 && _config$emoji.enabled) {
371
+ components.push({
372
+ type: EMOJI_GROUP.type,
373
+ key: EMOJI_GROUP.key,
374
+ parents: [{
375
+ type: INSERT_BLOCK_SECTION.type,
376
+ key: INSERT_BLOCK_SECTION.key,
377
+ rank: INSERT_BLOCK_SECTION_RANK[EMOJI_GROUP.key]
378
+ }],
379
+ component: createResponsiveComponent()
380
+ });
381
+ components.push({
382
+ type: EMOJI_BUTTON.type,
383
+ key: EMOJI_BUTTON.key,
384
+ parents: [{
385
+ type: EMOJI_GROUP.type,
386
+ key: EMOJI_GROUP.key,
387
+ rank: EMOJI_GROUP_RANK[EMOJI_BUTTON.key]
388
+ }],
389
+ component: () => /*#__PURE__*/React.createElement(EmojiButton, {
390
+ api: api
391
+ })
392
+ });
393
+ }
394
+
395
+ // Layout Group
396
+ if ((_config$layout = config.layout) !== null && _config$layout !== void 0 && _config$layout.enabled) {
397
+ components.push({
398
+ type: LAYOUT_GROUP.type,
399
+ key: LAYOUT_GROUP.key,
400
+ parents: [{
401
+ type: INSERT_BLOCK_SECTION.type,
402
+ key: INSERT_BLOCK_SECTION.key,
403
+ rank: INSERT_BLOCK_SECTION_RANK[LAYOUT_GROUP.key]
404
+ }],
405
+ component: createResponsiveComponent()
406
+ });
407
+ components.push({
408
+ type: LAYOUT_BUTTON.type,
409
+ key: LAYOUT_BUTTON.key,
410
+ parents: [{
411
+ type: LAYOUT_GROUP.type,
412
+ key: LAYOUT_GROUP.key,
413
+ rank: LAYOUT_GROUP_RANK[LAYOUT_BUTTON.key]
414
+ }],
415
+ component: () => /*#__PURE__*/React.createElement(LayoutButton, {
416
+ api: api
417
+ })
418
+ });
419
+ }
420
+
421
+ // Table Group
422
+ if ((_config$table = config.table) !== null && _config$table !== void 0 && _config$table.enabled) {
423
+ components.push({
424
+ type: TABLE_GROUP.type,
425
+ key: TABLE_GROUP.key,
426
+ parents: [{
427
+ type: INSERT_BLOCK_SECTION.type,
428
+ key: INSERT_BLOCK_SECTION.key,
429
+ rank: INSERT_BLOCK_SECTION_RANK[TABLE_GROUP.key]
430
+ }],
431
+ component: createResponsiveComponent()
432
+ });
433
+ components.push({
434
+ type: TABLE_BUTTON.type,
435
+ key: TABLE_BUTTON.key,
436
+ parents: [{
437
+ type: TABLE_GROUP.type,
438
+ key: TABLE_GROUP.key,
439
+ rank: TABLE_GROUP_RANK[TABLE_BUTTON.key]
440
+ }],
441
+ component: () => /*#__PURE__*/React.createElement(TableButton, {
442
+ api: api
443
+ })
444
+ });
445
+ if (options.tableSelectorSupported) {
446
+ components.push({
447
+ type: TABLE_SIZE_PICKER.type,
448
+ key: TABLE_SIZE_PICKER.key,
449
+ parents: [{
450
+ type: TABLE_GROUP.type,
451
+ key: TABLE_GROUP.key,
452
+ rank: TABLE_GROUP_RANK[TABLE_SIZE_PICKER.key]
453
+ }],
454
+ component: () => /*#__PURE__*/React.createElement(TableSizePicker, {
455
+ api: api,
456
+ tableSelectorSupported: options.tableSelectorSupported
457
+ })
458
+ });
459
+ }
460
+ }
461
+
462
+ // Insert Group
463
+ if ((_config$insert = config.insert) !== null && _config$insert !== void 0 && _config$insert.enabled) {
464
+ components.push({
465
+ type: INSERT_GROUP.type,
466
+ key: INSERT_GROUP.key,
467
+ parents: [{
468
+ type: INSERT_BLOCK_SECTION.type,
469
+ key: INSERT_BLOCK_SECTION.key,
470
+ rank: INSERT_BLOCK_SECTION_RANK[INSERT_GROUP.key]
471
+ }]
472
+ });
473
+ components.push({
474
+ type: INSERT_BUTTON.type,
475
+ key: INSERT_BUTTON.key,
476
+ parents: [{
477
+ type: INSERT_GROUP.type,
478
+ key: INSERT_GROUP.key,
479
+ rank: INSERT_GROUP_RANK[INSERT_BUTTON.key]
480
+ }],
481
+ component: () => /*#__PURE__*/React.createElement(InsertButton, {
482
+ api: api,
483
+ showElementBrowserLink: options.showElementBrowserLink,
484
+ tableSelectorSupported: options.tableSelectorSupported,
485
+ onInsertBlockType: onInsertBlockType,
486
+ nativeStatusSupported: options.nativeStatusSupported,
487
+ horizontalRuleEnabled: options.horizontalRuleEnabled,
488
+ expandEnabled: options.allowExpand,
489
+ insertMenuItems: options.insertMenuItems,
490
+ numberOfButtons: 7 // TODO: ED-28759 - Default to 7 buttons - Remove this once we have a proper way to do toolbar responsiveness
491
+ })
492
+ });
493
+ }
494
+ return components;
495
+ };
496
+
497
+ /**
498
+ * Main export that switches between old and new implementations based on experiment.
499
+ * This allows for gradual rollout of the new config-driven approach.
500
+ */
501
+ export const getToolbarComponentsWithConfig = props => {
502
+ if (expValEquals('platform_editor_toolbar_aifc_responsiveness_update', 'isEnabled', true) && 'options' in props) {
503
+ // Use new config-driven approach
504
+ return getToolbarComponentsUpdated(props);
505
+ }
506
+
507
+ // Use legacy approach
508
+ const legacyProps = props;
509
+ return getToolbarComponents(legacyProps);
237
510
  };
@@ -9,7 +9,7 @@ import { BLOCK_QUOTE, CODE_BLOCK, PANEL } from '@atlaskit/editor-plugin-block-ty
9
9
  import { fg } from '@atlaskit/platform-feature-flags';
10
10
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
11
11
  import { toggleInsertBlockPmKey, toggleInsertBlockPmPlugin } from './pm-plugins/toggleInsertBlock';
12
- import { getToolbarComponents } from './ui/toolbar-components';
12
+ import { getToolbarComponentsWithConfig } from './ui/toolbar-components';
13
13
  // Ignored via go/ees005
14
14
  // eslint-disable-next-line import/no-named-as-default
15
15
  import ToolbarInsertBlock from './ui/ToolbarInsertBlock';
@@ -161,7 +161,7 @@ export var insertBlockPlugin = function insertBlockPlugin(_ref) {
161
161
  exposure: true
162
162
  })) {
163
163
  var _api$toolbar, _api$codeBlock, _api$panel, _api$blockType;
164
- api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents(getToolbarComponents({
164
+ api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents(getToolbarComponentsWithConfig({
165
165
  api: api,
166
166
  tableSelectorSupported: options.tableSelectorSupported,
167
167
  toolbarShowPlusInsertOnly: options.toolbarShowPlusInsertOnly,
@@ -170,7 +170,8 @@ export var insertBlockPlugin = function insertBlockPlugin(_ref) {
170
170
  nativeStatusSupported: options.nativeStatusSupported,
171
171
  horizontalRuleEnabled: options.horizontalRuleEnabled,
172
172
  expandEnabled: options.allowExpand,
173
- insertMenuItems: options.insertMenuItems
173
+ insertMenuItems: options.insertMenuItems,
174
+ options: options
174
175
  }));
175
176
  } else {
176
177
  var _api$primaryToolbar;
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { ToolTipContent, getAriaKeyshortcuts, toggleCodeBlock } from '@atlaskit/editor-common/keymaps';
5
+ import { blockTypeMessages } from '@atlaskit/editor-common/messages';
6
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
7
+ import { ToolbarButton, ToolbarTooltip, CodeIcon } from '@atlaskit/editor-toolbar';
8
+ export var CodeBlockButton = function CodeBlockButton(_ref) {
9
+ var api = _ref.api;
10
+ var _useIntl = useIntl(),
11
+ formatMessage = _useIntl.formatMessage;
12
+ var _useEditorToolbar = useEditorToolbar(),
13
+ editorView = _useEditorToolbar.editorView;
14
+ if (!(api !== null && api !== void 0 && api.codeBlock)) {
15
+ return null;
16
+ }
17
+ var onClick = function onClick() {
18
+ if (editorView) {
19
+ var _api$codeBlock;
20
+ api === null || api === void 0 || (_api$codeBlock = api.codeBlock) === null || _api$codeBlock === void 0 || _api$codeBlock.actions.insertCodeBlock(INPUT_METHOD.TOOLBAR)(editorView.state, editorView.dispatch);
21
+ }
22
+ };
23
+ return /*#__PURE__*/React.createElement(ToolbarTooltip, {
24
+ content: /*#__PURE__*/React.createElement(ToolTipContent, {
25
+ description: formatMessage(blockTypeMessages.codeblock),
26
+ keymap: toggleCodeBlock
27
+ })
28
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
29
+ iconBefore: /*#__PURE__*/React.createElement(CodeIcon, {
30
+ label: formatMessage(blockTypeMessages.codeblock),
31
+ size: "small"
32
+ }),
33
+ onClick: onClick,
34
+ ariaKeyshortcuts: getAriaKeyshortcuts(toggleCodeBlock)
35
+ }));
36
+ };
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Resolves toolbar configuration from plugin options, handling backward compatibility
3
+ * and providing sensible defaults.
4
+ */
5
+ export var resolveToolbarConfig = function resolveToolbarConfig(options) {
6
+ var _options$toolbarButto, _options$toolbarButto2, _options$toolbarButto3, _options$toolbarButto4, _options$toolbarButto5, _options$toolbarButto6, _options$toolbarButto7, _options$toolbarButto8;
7
+ // Handle backward compatibility: toolbarShowPlusInsertOnly
8
+ if (options.toolbarShowPlusInsertOnly) {
9
+ return {
10
+ codeBlock: {
11
+ enabled: false
12
+ },
13
+ emoji: {
14
+ enabled: false
15
+ },
16
+ insert: {
17
+ enabled: true
18
+ },
19
+ layout: {
20
+ enabled: false
21
+ },
22
+ media: {
23
+ enabled: false
24
+ },
25
+ mention: {
26
+ enabled: false
27
+ },
28
+ table: {
29
+ enabled: false
30
+ },
31
+ taskList: {
32
+ enabled: false
33
+ }
34
+ };
35
+ }
36
+ if (!options.toolbarButtons) {
37
+ // disable code block by default if there's no toolbarButtons options provided, e.g on full page editor
38
+ return {
39
+ codeBlock: {
40
+ enabled: false
41
+ },
42
+ emoji: {
43
+ enabled: true
44
+ },
45
+ insert: {
46
+ enabled: true
47
+ },
48
+ layout: {
49
+ enabled: true
50
+ },
51
+ media: {
52
+ enabled: true
53
+ },
54
+ mention: {
55
+ enabled: true
56
+ },
57
+ table: {
58
+ enabled: true
59
+ },
60
+ taskList: {
61
+ enabled: true
62
+ }
63
+ };
64
+ }
65
+ var defaults = {
66
+ enabled: false
67
+ };
68
+ var resolveGroupConfig = function resolveGroupConfig(groupConfig) {
69
+ var _groupConfig$enabled;
70
+ return {
71
+ enabled: (_groupConfig$enabled = groupConfig === null || groupConfig === void 0 ? void 0 : groupConfig.enabled) !== null && _groupConfig$enabled !== void 0 ? _groupConfig$enabled : defaults.enabled
72
+ };
73
+ };
74
+ return {
75
+ codeBlock: resolveGroupConfig((_options$toolbarButto = options.toolbarButtons) === null || _options$toolbarButto === void 0 ? void 0 : _options$toolbarButto.codeBlock),
76
+ emoji: resolveGroupConfig((_options$toolbarButto2 = options.toolbarButtons) === null || _options$toolbarButto2 === void 0 ? void 0 : _options$toolbarButto2.emoji),
77
+ insert: resolveGroupConfig((_options$toolbarButto3 = options.toolbarButtons) === null || _options$toolbarButto3 === void 0 ? void 0 : _options$toolbarButto3.insert),
78
+ layout: resolveGroupConfig((_options$toolbarButto4 = options.toolbarButtons) === null || _options$toolbarButto4 === void 0 ? void 0 : _options$toolbarButto4.layout),
79
+ media: resolveGroupConfig((_options$toolbarButto5 = options.toolbarButtons) === null || _options$toolbarButto5 === void 0 ? void 0 : _options$toolbarButto5.media),
80
+ mention: resolveGroupConfig((_options$toolbarButto6 = options.toolbarButtons) === null || _options$toolbarButto6 === void 0 ? void 0 : _options$toolbarButto6.mention),
81
+ table: resolveGroupConfig((_options$toolbarButto7 = options.toolbarButtons) === null || _options$toolbarButto7 === void 0 ? void 0 : _options$toolbarButto7.table),
82
+ taskList: resolveGroupConfig((_options$toolbarButto8 = options.toolbarButtons) === null || _options$toolbarButto8 === void 0 ? void 0 : _options$toolbarButto8.taskList)
83
+ };
84
+ };