@atlaskit/editor-plugin-insert-block 7.0.1 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-insert-block
2
2
 
3
+ ## 7.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`2f81c0f3bf21d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2f81c0f3bf21d) -
8
+ [ux] ED-29318 [CR-6b] Add new toolbar icons to comment editor
9
+ - Updated dependencies
10
+
3
11
  ## 7.0.1
4
12
 
5
13
  ### Patch Changes
@@ -171,7 +171,7 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
171
171
  exposure: true
172
172
  })) {
173
173
  var _api$toolbar, _api$codeBlock, _api$panel, _api$blockType;
174
- api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents((0, _toolbarComponents.getToolbarComponents)({
174
+ api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents((0, _toolbarComponents.getToolbarComponentsWithConfig)({
175
175
  api: api,
176
176
  tableSelectorSupported: options.tableSelectorSupported,
177
177
  toolbarShowPlusInsertOnly: options.toolbarShowPlusInsertOnly,
@@ -180,7 +180,8 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
180
180
  nativeStatusSupported: options.nativeStatusSupported,
181
181
  horizontalRuleEnabled: options.horizontalRuleEnabled,
182
182
  expandEnabled: options.allowExpand,
183
- insertMenuItems: options.insertMenuItems
183
+ insertMenuItems: options.insertMenuItems,
184
+ options: options
184
185
  }));
185
186
  } else {
186
187
  var _api$primaryToolbar;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CodeBlockButton = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _analytics = require("@atlaskit/editor-common/analytics");
11
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
12
+ var _messages = require("@atlaskit/editor-common/messages");
13
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
14
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
15
+ var CodeBlockButton = exports.CodeBlockButton = function CodeBlockButton(_ref) {
16
+ var api = _ref.api;
17
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
18
+ formatMessage = _useIntl.formatMessage;
19
+ var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(),
20
+ editorView = _useEditorToolbar.editorView;
21
+ if (!(api !== null && api !== void 0 && api.codeBlock)) {
22
+ return null;
23
+ }
24
+ var onClick = function onClick() {
25
+ if (editorView) {
26
+ var _api$codeBlock;
27
+ api === null || api === void 0 || (_api$codeBlock = api.codeBlock) === null || _api$codeBlock === void 0 || _api$codeBlock.actions.insertCodeBlock(_analytics.INPUT_METHOD.TOOLBAR)(editorView.state, editorView.dispatch);
28
+ }
29
+ };
30
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarTooltip, {
31
+ content: /*#__PURE__*/_react.default.createElement(_keymaps.ToolTipContent, {
32
+ description: formatMessage(_messages.blockTypeMessages.codeblock),
33
+ keymap: _keymaps.toggleCodeBlock
34
+ })
35
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarButton, {
36
+ iconBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.CodeIcon, {
37
+ label: formatMessage(_messages.blockTypeMessages.codeblock),
38
+ size: "small"
39
+ }),
40
+ onClick: onClick,
41
+ ariaKeyshortcuts: (0, _keymaps.getAriaKeyshortcuts)(_keymaps.toggleCodeBlock)
42
+ }));
43
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resolveToolbarConfig = void 0;
7
+ /**
8
+ * Resolves toolbar configuration from plugin options, handling backward compatibility
9
+ * and providing sensible defaults.
10
+ */
11
+ var resolveToolbarConfig = exports.resolveToolbarConfig = function resolveToolbarConfig(options) {
12
+ var _options$toolbarButto, _options$toolbarButto2, _options$toolbarButto3, _options$toolbarButto4, _options$toolbarButto5, _options$toolbarButto6, _options$toolbarButto7, _options$toolbarButto8;
13
+ // Handle backward compatibility: toolbarShowPlusInsertOnly
14
+ if (options.toolbarShowPlusInsertOnly) {
15
+ return {
16
+ codeBlock: {
17
+ enabled: false
18
+ },
19
+ emoji: {
20
+ enabled: false
21
+ },
22
+ insert: {
23
+ enabled: true
24
+ },
25
+ layout: {
26
+ enabled: false
27
+ },
28
+ media: {
29
+ enabled: false
30
+ },
31
+ mention: {
32
+ enabled: false
33
+ },
34
+ table: {
35
+ enabled: false
36
+ },
37
+ taskList: {
38
+ enabled: false
39
+ }
40
+ };
41
+ }
42
+ if (!options.toolbarButtons) {
43
+ // disable code block by default if there's no toolbarButtons options provided, e.g on full page editor
44
+ return {
45
+ codeBlock: {
46
+ enabled: false
47
+ },
48
+ emoji: {
49
+ enabled: true
50
+ },
51
+ insert: {
52
+ enabled: true
53
+ },
54
+ layout: {
55
+ enabled: true
56
+ },
57
+ media: {
58
+ enabled: true
59
+ },
60
+ mention: {
61
+ enabled: true
62
+ },
63
+ table: {
64
+ enabled: true
65
+ },
66
+ taskList: {
67
+ enabled: true
68
+ }
69
+ };
70
+ }
71
+ var defaults = {
72
+ enabled: false
73
+ };
74
+ var resolveGroupConfig = function resolveGroupConfig(groupConfig) {
75
+ var _groupConfig$enabled;
76
+ return {
77
+ enabled: (_groupConfig$enabled = groupConfig === null || groupConfig === void 0 ? void 0 : groupConfig.enabled) !== null && _groupConfig$enabled !== void 0 ? _groupConfig$enabled : defaults.enabled
78
+ };
79
+ };
80
+ return {
81
+ codeBlock: resolveGroupConfig((_options$toolbarButto = options.toolbarButtons) === null || _options$toolbarButto === void 0 ? void 0 : _options$toolbarButto.codeBlock),
82
+ emoji: resolveGroupConfig((_options$toolbarButto2 = options.toolbarButtons) === null || _options$toolbarButto2 === void 0 ? void 0 : _options$toolbarButto2.emoji),
83
+ insert: resolveGroupConfig((_options$toolbarButto3 = options.toolbarButtons) === null || _options$toolbarButto3 === void 0 ? void 0 : _options$toolbarButto3.insert),
84
+ layout: resolveGroupConfig((_options$toolbarButto4 = options.toolbarButtons) === null || _options$toolbarButto4 === void 0 ? void 0 : _options$toolbarButto4.layout),
85
+ media: resolveGroupConfig((_options$toolbarButto5 = options.toolbarButtons) === null || _options$toolbarButto5 === void 0 ? void 0 : _options$toolbarButto5.media),
86
+ mention: resolveGroupConfig((_options$toolbarButto6 = options.toolbarButtons) === null || _options$toolbarButto6 === void 0 ? void 0 : _options$toolbarButto6.mention),
87
+ table: resolveGroupConfig((_options$toolbarButto7 = options.toolbarButtons) === null || _options$toolbarButto7 === void 0 ? void 0 : _options$toolbarButto7.table),
88
+ taskList: resolveGroupConfig((_options$toolbarButto8 = options.toolbarButtons) === null || _options$toolbarButto8 === void 0 ? void 0 : _options$toolbarButto8.taskList)
89
+ };
90
+ };
@@ -4,12 +4,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.getToolbarComponents = void 0;
7
+ exports.getToolbarComponentsWithConfig = exports.getToolbarComponentsUpdated = exports.getToolbarComponents = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _toolbar = require("@atlaskit/editor-common/toolbar");
11
11
  var _editorToolbar = require("@atlaskit/editor-toolbar");
12
12
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
13
+ var _CodeBlockButton = require("./toolbar-components/CodeBlockButton");
14
+ var _configResolver = require("./toolbar-components/config-resolver");
13
15
  var _EmojiButton = require("./toolbar-components/EmojiButton");
14
16
  var _ImageButton = require("./toolbar-components/ImageButton");
15
17
  var _InsertButton = require("./toolbar-components/InsertButton");
@@ -265,4 +267,293 @@ var getToolbarComponents = exports.getToolbarComponents = function getToolbarCom
265
267
  });
266
268
  }
267
269
  }]);
270
+ };
271
+
272
+ /**
273
+ * Updated toolbar components function that uses the new configuration resolver.
274
+ * This function replaces the hardcoded approach with a config-driven one.
275
+ */
276
+ var getToolbarComponentsUpdated = exports.getToolbarComponentsUpdated = function getToolbarComponentsUpdated(_ref8) {
277
+ var _config$taskList, _config$media, _config$codeBlock, _config$mention, _config$emoji, _config$layout, _config$table, _config$insert;
278
+ var api = _ref8.api,
279
+ options = _ref8.options,
280
+ onInsertBlockType = _ref8.onInsertBlockType;
281
+ var config = (0, _configResolver.resolveToolbarConfig)(options);
282
+ var components = [];
283
+
284
+ // Helper function to create responsive wrapper component
285
+ var createResponsiveComponent = function createResponsiveComponent() {
286
+ return (0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_responsive', 'isEnabled', true) ? function (_ref9) {
287
+ var children = _ref9.children;
288
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.Show, {
289
+ above: "lg"
290
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarButtonGroup, null, children));
291
+ } : undefined;
292
+ };
293
+
294
+ // TaskList Group
295
+ if ((_config$taskList = config.taskList) !== null && _config$taskList !== void 0 && _config$taskList.enabled) {
296
+ components.push({
297
+ type: _toolbar.TASK_LIST_GROUP.type,
298
+ key: _toolbar.TASK_LIST_GROUP.key,
299
+ parents: [{
300
+ type: _toolbar.INSERT_BLOCK_SECTION.type,
301
+ key: _toolbar.INSERT_BLOCK_SECTION.key,
302
+ rank: _toolbar.INSERT_BLOCK_SECTION_RANK[_toolbar.TASK_LIST_GROUP.key]
303
+ }],
304
+ component: createResponsiveComponent()
305
+ });
306
+ components.push({
307
+ type: _toolbar.TASK_LIST_BUTTON.type,
308
+ key: _toolbar.TASK_LIST_BUTTON.key,
309
+ parents: [{
310
+ type: _toolbar.TASK_LIST_GROUP.type,
311
+ key: _toolbar.TASK_LIST_GROUP.key,
312
+ rank: _toolbar.TASK_LIST_GROUP_RANK[_toolbar.TASK_LIST_BUTTON.key]
313
+ }],
314
+ component: function component() {
315
+ return /*#__PURE__*/_react.default.createElement(_TaskListButton.TaskListButton, {
316
+ api: api
317
+ });
318
+ }
319
+ });
320
+ }
321
+
322
+ // Media Group
323
+ if ((_config$media = config.media) !== null && _config$media !== void 0 && _config$media.enabled) {
324
+ components.push({
325
+ type: _toolbar.MEDIA_GROUP.type,
326
+ key: _toolbar.MEDIA_GROUP.key,
327
+ parents: [{
328
+ type: _toolbar.INSERT_BLOCK_SECTION.type,
329
+ key: _toolbar.INSERT_BLOCK_SECTION.key,
330
+ rank: _toolbar.INSERT_BLOCK_SECTION_RANK[_toolbar.MEDIA_GROUP.key]
331
+ }],
332
+ component: createResponsiveComponent()
333
+ });
334
+ components.push({
335
+ type: _toolbar.MEDIA_BUTTON.type,
336
+ key: _toolbar.MEDIA_BUTTON.key,
337
+ parents: [{
338
+ type: _toolbar.MEDIA_GROUP.type,
339
+ key: _toolbar.MEDIA_GROUP.key,
340
+ rank: _toolbar.MEDIA_GROUP_RANK[_toolbar.MEDIA_BUTTON.key]
341
+ }],
342
+ component: function component() {
343
+ return !!(api !== null && api !== void 0 && api.imageUpload) ? /*#__PURE__*/_react.default.createElement(_ImageButton.ImageButton, {
344
+ api: api
345
+ }) : /*#__PURE__*/_react.default.createElement(_MediaButton.MediaButton, {
346
+ api: api
347
+ });
348
+ }
349
+ });
350
+ }
351
+
352
+ // CodeBlock Group
353
+ if ((_config$codeBlock = config.codeBlock) !== null && _config$codeBlock !== void 0 && _config$codeBlock.enabled) {
354
+ components.push({
355
+ type: _toolbar.CODE_BLOCK_GROUP.type,
356
+ key: _toolbar.CODE_BLOCK_GROUP.key,
357
+ parents: [{
358
+ type: _toolbar.INSERT_BLOCK_SECTION.type,
359
+ key: _toolbar.INSERT_BLOCK_SECTION.key,
360
+ rank: _toolbar.INSERT_BLOCK_SECTION_RANK[_toolbar.CODE_BLOCK_GROUP.key]
361
+ }],
362
+ component: createResponsiveComponent()
363
+ });
364
+ components.push({
365
+ type: _toolbar.CODE_BLOCK_BUTTON.type,
366
+ key: _toolbar.CODE_BLOCK_BUTTON.key,
367
+ parents: [{
368
+ type: _toolbar.CODE_BLOCK_GROUP.type,
369
+ key: _toolbar.CODE_BLOCK_GROUP.key,
370
+ rank: _toolbar.CODE_BLOCK_GROUP_RANK[_toolbar.CODE_BLOCK_BUTTON.key]
371
+ }],
372
+ component: function component() {
373
+ return /*#__PURE__*/_react.default.createElement(_CodeBlockButton.CodeBlockButton, {
374
+ api: api
375
+ });
376
+ }
377
+ });
378
+ }
379
+
380
+ // Mention Group
381
+ if ((_config$mention = config.mention) !== null && _config$mention !== void 0 && _config$mention.enabled) {
382
+ components.push({
383
+ type: _toolbar.MENTION_GROUP.type,
384
+ key: _toolbar.MENTION_GROUP.key,
385
+ parents: [{
386
+ type: _toolbar.INSERT_BLOCK_SECTION.type,
387
+ key: _toolbar.INSERT_BLOCK_SECTION.key,
388
+ rank: _toolbar.INSERT_BLOCK_SECTION_RANK[_toolbar.MENTION_GROUP.key]
389
+ }],
390
+ component: createResponsiveComponent()
391
+ });
392
+ components.push({
393
+ type: _toolbar.MENTION_BUTTON.type,
394
+ key: _toolbar.MENTION_BUTTON.key,
395
+ parents: [{
396
+ type: _toolbar.MENTION_GROUP.type,
397
+ key: _toolbar.MENTION_GROUP.key,
398
+ rank: _toolbar.MENTION_GROUP_RANK[_toolbar.MENTION_BUTTON.key]
399
+ }],
400
+ component: function component() {
401
+ return /*#__PURE__*/_react.default.createElement(_MentionButton.MentionButton, {
402
+ api: api
403
+ });
404
+ }
405
+ });
406
+ }
407
+
408
+ // Emoji Group
409
+ if ((_config$emoji = config.emoji) !== null && _config$emoji !== void 0 && _config$emoji.enabled) {
410
+ components.push({
411
+ type: _toolbar.EMOJI_GROUP.type,
412
+ key: _toolbar.EMOJI_GROUP.key,
413
+ parents: [{
414
+ type: _toolbar.INSERT_BLOCK_SECTION.type,
415
+ key: _toolbar.INSERT_BLOCK_SECTION.key,
416
+ rank: _toolbar.INSERT_BLOCK_SECTION_RANK[_toolbar.EMOJI_GROUP.key]
417
+ }],
418
+ component: createResponsiveComponent()
419
+ });
420
+ components.push({
421
+ type: _toolbar.EMOJI_BUTTON.type,
422
+ key: _toolbar.EMOJI_BUTTON.key,
423
+ parents: [{
424
+ type: _toolbar.EMOJI_GROUP.type,
425
+ key: _toolbar.EMOJI_GROUP.key,
426
+ rank: _toolbar.EMOJI_GROUP_RANK[_toolbar.EMOJI_BUTTON.key]
427
+ }],
428
+ component: function component() {
429
+ return /*#__PURE__*/_react.default.createElement(_EmojiButton.EmojiButton, {
430
+ api: api
431
+ });
432
+ }
433
+ });
434
+ }
435
+
436
+ // Layout Group
437
+ if ((_config$layout = config.layout) !== null && _config$layout !== void 0 && _config$layout.enabled) {
438
+ components.push({
439
+ type: _toolbar.LAYOUT_GROUP.type,
440
+ key: _toolbar.LAYOUT_GROUP.key,
441
+ parents: [{
442
+ type: _toolbar.INSERT_BLOCK_SECTION.type,
443
+ key: _toolbar.INSERT_BLOCK_SECTION.key,
444
+ rank: _toolbar.INSERT_BLOCK_SECTION_RANK[_toolbar.LAYOUT_GROUP.key]
445
+ }],
446
+ component: createResponsiveComponent()
447
+ });
448
+ components.push({
449
+ type: _toolbar.LAYOUT_BUTTON.type,
450
+ key: _toolbar.LAYOUT_BUTTON.key,
451
+ parents: [{
452
+ type: _toolbar.LAYOUT_GROUP.type,
453
+ key: _toolbar.LAYOUT_GROUP.key,
454
+ rank: _toolbar.LAYOUT_GROUP_RANK[_toolbar.LAYOUT_BUTTON.key]
455
+ }],
456
+ component: function component() {
457
+ return /*#__PURE__*/_react.default.createElement(_LayoutButton.LayoutButton, {
458
+ api: api
459
+ });
460
+ }
461
+ });
462
+ }
463
+
464
+ // Table Group
465
+ if ((_config$table = config.table) !== null && _config$table !== void 0 && _config$table.enabled) {
466
+ components.push({
467
+ type: _toolbar.TABLE_GROUP.type,
468
+ key: _toolbar.TABLE_GROUP.key,
469
+ parents: [{
470
+ type: _toolbar.INSERT_BLOCK_SECTION.type,
471
+ key: _toolbar.INSERT_BLOCK_SECTION.key,
472
+ rank: _toolbar.INSERT_BLOCK_SECTION_RANK[_toolbar.TABLE_GROUP.key]
473
+ }],
474
+ component: createResponsiveComponent()
475
+ });
476
+ components.push({
477
+ type: _toolbar.TABLE_BUTTON.type,
478
+ key: _toolbar.TABLE_BUTTON.key,
479
+ parents: [{
480
+ type: _toolbar.TABLE_GROUP.type,
481
+ key: _toolbar.TABLE_GROUP.key,
482
+ rank: _toolbar.TABLE_GROUP_RANK[_toolbar.TABLE_BUTTON.key]
483
+ }],
484
+ component: function component() {
485
+ return /*#__PURE__*/_react.default.createElement(_TableButton.TableButton, {
486
+ api: api
487
+ });
488
+ }
489
+ });
490
+ if (options.tableSelectorSupported) {
491
+ components.push({
492
+ type: _toolbar.TABLE_SIZE_PICKER.type,
493
+ key: _toolbar.TABLE_SIZE_PICKER.key,
494
+ parents: [{
495
+ type: _toolbar.TABLE_GROUP.type,
496
+ key: _toolbar.TABLE_GROUP.key,
497
+ rank: _toolbar.TABLE_GROUP_RANK[_toolbar.TABLE_SIZE_PICKER.key]
498
+ }],
499
+ component: function component() {
500
+ return /*#__PURE__*/_react.default.createElement(_TableSizePicker.TableSizePicker, {
501
+ api: api,
502
+ tableSelectorSupported: options.tableSelectorSupported
503
+ });
504
+ }
505
+ });
506
+ }
507
+ }
508
+
509
+ // Insert Group
510
+ if ((_config$insert = config.insert) !== null && _config$insert !== void 0 && _config$insert.enabled) {
511
+ components.push({
512
+ type: _toolbar.INSERT_GROUP.type,
513
+ key: _toolbar.INSERT_GROUP.key,
514
+ parents: [{
515
+ type: _toolbar.INSERT_BLOCK_SECTION.type,
516
+ key: _toolbar.INSERT_BLOCK_SECTION.key,
517
+ rank: _toolbar.INSERT_BLOCK_SECTION_RANK[_toolbar.INSERT_GROUP.key]
518
+ }]
519
+ });
520
+ components.push({
521
+ type: _toolbar.INSERT_BUTTON.type,
522
+ key: _toolbar.INSERT_BUTTON.key,
523
+ parents: [{
524
+ type: _toolbar.INSERT_GROUP.type,
525
+ key: _toolbar.INSERT_GROUP.key,
526
+ rank: _toolbar.INSERT_GROUP_RANK[_toolbar.INSERT_BUTTON.key]
527
+ }],
528
+ component: function component() {
529
+ return /*#__PURE__*/_react.default.createElement(_InsertButton.InsertButton, {
530
+ api: api,
531
+ showElementBrowserLink: options.showElementBrowserLink,
532
+ tableSelectorSupported: options.tableSelectorSupported,
533
+ onInsertBlockType: onInsertBlockType,
534
+ nativeStatusSupported: options.nativeStatusSupported,
535
+ horizontalRuleEnabled: options.horizontalRuleEnabled,
536
+ expandEnabled: options.allowExpand,
537
+ insertMenuItems: options.insertMenuItems,
538
+ numberOfButtons: 7 // TODO: ED-28759 - Default to 7 buttons - Remove this once we have a proper way to do toolbar responsiveness
539
+ });
540
+ }
541
+ });
542
+ }
543
+ return components;
544
+ };
545
+
546
+ /**
547
+ * Main export that switches between old and new implementations based on experiment.
548
+ * This allows for gradual rollout of the new config-driven approach.
549
+ */
550
+ var getToolbarComponentsWithConfig = exports.getToolbarComponentsWithConfig = function getToolbarComponentsWithConfig(props) {
551
+ if ((0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_responsiveness_update', 'isEnabled', true) && 'options' in props) {
552
+ // Use new config-driven approach
553
+ return getToolbarComponentsUpdated(props);
554
+ }
555
+
556
+ // Use legacy approach
557
+ var legacyProps = props;
558
+ return getToolbarComponents(legacyProps);
268
559
  };
@@ -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';
@@ -156,7 +156,7 @@ export const insertBlockPlugin = ({
156
156
  exposure: true
157
157
  })) {
158
158
  var _api$toolbar, _api$codeBlock, _api$panel, _api$blockType;
159
- api === null || api === void 0 ? void 0 : (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.registerComponents(getToolbarComponents({
159
+ api === null || api === void 0 ? void 0 : (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.registerComponents(getToolbarComponentsWithConfig({
160
160
  api,
161
161
  tableSelectorSupported: options.tableSelectorSupported,
162
162
  toolbarShowPlusInsertOnly: options.toolbarShowPlusInsertOnly,
@@ -165,7 +165,8 @@ export const insertBlockPlugin = ({
165
165
  nativeStatusSupported: options.nativeStatusSupported,
166
166
  horizontalRuleEnabled: options.horizontalRuleEnabled,
167
167
  expandEnabled: options.allowExpand,
168
- insertMenuItems: options.insertMenuItems
168
+ insertMenuItems: options.insertMenuItems,
169
+ options
169
170
  }));
170
171
  } else {
171
172
  var _api$primaryToolbar;
@@ -0,0 +1,39 @@
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 const CodeBlockButton = ({
9
+ api
10
+ }) => {
11
+ const {
12
+ formatMessage
13
+ } = useIntl();
14
+ const {
15
+ editorView
16
+ } = useEditorToolbar();
17
+ if (!(api !== null && api !== void 0 && api.codeBlock)) {
18
+ return null;
19
+ }
20
+ const onClick = () => {
21
+ if (editorView) {
22
+ var _api$codeBlock;
23
+ api === null || api === void 0 ? void 0 : (_api$codeBlock = api.codeBlock) === null || _api$codeBlock === void 0 ? void 0 : _api$codeBlock.actions.insertCodeBlock(INPUT_METHOD.TOOLBAR)(editorView.state, editorView.dispatch);
24
+ }
25
+ };
26
+ return /*#__PURE__*/React.createElement(ToolbarTooltip, {
27
+ content: /*#__PURE__*/React.createElement(ToolTipContent, {
28
+ description: formatMessage(blockTypeMessages.codeblock),
29
+ keymap: toggleCodeBlock
30
+ })
31
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
32
+ iconBefore: /*#__PURE__*/React.createElement(CodeIcon, {
33
+ label: formatMessage(blockTypeMessages.codeblock),
34
+ size: "small"
35
+ }),
36
+ onClick: onClick,
37
+ ariaKeyshortcuts: getAriaKeyshortcuts(toggleCodeBlock)
38
+ }));
39
+ };
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Resolves toolbar configuration from plugin options, handling backward compatibility
3
+ * and providing sensible defaults.
4
+ */
5
+ export const 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
+ const defaults = {
66
+ enabled: false
67
+ };
68
+ const 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
+ };