@atlaskit/editor-plugin-code-block-advanced 3.2.4 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/editor-plugin-code-block-advanced
2
2
 
3
+ ## 4.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 4.0.0
10
+
11
+ ### Patch Changes
12
+
13
+ - [`e882e86092666`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e882e86092666) -
14
+ [ux] Register expand, layout and code block itmes in block menu. Update panel item.
15
+ - Updated dependencies
16
+
3
17
  ## 3.2.4
4
18
 
5
19
  ### Patch Changes
@@ -22,6 +22,9 @@
22
22
  "../src/**/stories/**/*"
23
23
  ],
24
24
  "references": [
25
+ {
26
+ "path": "../../editor-plugin-block-menu/afm-cc/tsconfig.json"
27
+ },
25
28
  {
26
29
  "path": "../../editor-plugin-code-block/afm-cc/tsconfig.json"
27
30
  },
@@ -37,6 +40,12 @@
37
40
  {
38
41
  "path": "../../editor-plugin-selection-marker/afm-cc/tsconfig.json"
39
42
  },
43
+ {
44
+ "path": "../../editor-toolbar/afm-cc/tsconfig.json"
45
+ },
46
+ {
47
+ "path": "../../../design-system/icon/afm-cc/tsconfig.json"
48
+ },
40
49
  {
41
50
  "path": "../../../platform/feature-flags/afm-cc/tsconfig.json"
42
51
  },
@@ -22,6 +22,9 @@
22
22
  "../src/**/stories/**/*"
23
23
  ],
24
24
  "references": [
25
+ {
26
+ "path": "../../editor-plugin-block-menu/afm-jira/tsconfig.json"
27
+ },
25
28
  {
26
29
  "path": "../../editor-plugin-code-block/afm-jira/tsconfig.json"
27
30
  },
@@ -37,6 +40,12 @@
37
40
  {
38
41
  "path": "../../editor-plugin-selection-marker/afm-jira/tsconfig.json"
39
42
  },
43
+ {
44
+ "path": "../../editor-toolbar/afm-jira/tsconfig.json"
45
+ },
46
+ {
47
+ "path": "../../../design-system/icon/afm-jira/tsconfig.json"
48
+ },
40
49
  {
41
50
  "path": "../../../platform/feature-flags/afm-jira/tsconfig.json"
42
51
  },
@@ -22,6 +22,9 @@
22
22
  "../src/**/stories/**/*"
23
23
  ],
24
24
  "references": [
25
+ {
26
+ "path": "../../editor-plugin-block-menu/afm-post-office/tsconfig.json"
27
+ },
25
28
  {
26
29
  "path": "../../editor-plugin-code-block/afm-post-office/tsconfig.json"
27
30
  },
@@ -37,6 +40,12 @@
37
40
  {
38
41
  "path": "../../editor-plugin-selection-marker/afm-post-office/tsconfig.json"
39
42
  },
43
+ {
44
+ "path": "../../editor-toolbar/afm-post-office/tsconfig.json"
45
+ },
46
+ {
47
+ "path": "../../../design-system/icon/afm-post-office/tsconfig.json"
48
+ },
40
49
  {
41
50
  "path": "../../../platform/feature-flags/afm-post-office/tsconfig.json"
42
51
  },
@@ -22,6 +22,9 @@
22
22
  "../src/**/stories/**/*"
23
23
  ],
24
24
  "references": [
25
+ {
26
+ "path": "../../editor-plugin-block-menu/afm-townsquare/tsconfig.json"
27
+ },
25
28
  {
26
29
  "path": "../../editor-plugin-code-block/afm-townsquare/tsconfig.json"
27
30
  },
@@ -37,6 +40,12 @@
37
40
  {
38
41
  "path": "../../editor-plugin-selection-marker/afm-townsquare/tsconfig.json"
39
42
  },
43
+ {
44
+ "path": "../../editor-toolbar/afm-townsquare/tsconfig.json"
45
+ },
46
+ {
47
+ "path": "../../../design-system/icon/afm-townsquare/tsconfig.json"
48
+ },
40
49
  {
41
50
  "path": "../../../platform/feature-flags/afm-townsquare/tsconfig.json"
42
51
  },
@@ -4,11 +4,27 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.codeBlockAdvancedPlugin = void 0;
7
+ var _blockMenu = require("@atlaskit/editor-common/block-menu");
8
+ var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
7
9
  var _codeBlockNodeWithToDOMFixed = require("./nodeviews/codeBlockNodeWithToDOMFixed");
8
10
  var _main = require("./pm-plugins/main");
11
+ var _createCodeBlockMenuItem = require("./ui/createCodeBlockMenuItem");
9
12
  var codeBlockAdvancedPlugin = exports.codeBlockAdvancedPlugin = function codeBlockAdvancedPlugin(_ref) {
10
13
  var api = _ref.api,
11
14
  config = _ref.config;
15
+ if ((0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true)) {
16
+ var _api$blockMenu;
17
+ api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents([{
18
+ type: 'block-menu-item',
19
+ key: _blockMenu.FORMAT_CODE_BLOCK_MENU_ITEM.key,
20
+ parent: {
21
+ type: 'block-menu-section',
22
+ key: _blockMenu.FORMAT_MENU_ITEM.key,
23
+ rank: _blockMenu.FORMAT_NESTED_MENU_RANK[_blockMenu.FORMAT_CODE_BLOCK_MENU_ITEM.key]
24
+ },
25
+ component: (0, _createCodeBlockMenuItem.createCodeBlockMenuItem)(api)
26
+ }]);
27
+ }
12
28
  return {
13
29
  name: 'codeBlockAdvanced',
14
30
  nodes: function nodes() {
@@ -9,6 +9,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _adfSchema = require("@atlaskit/adf-schema");
10
10
  var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
11
11
  var _styles = require("@atlaskit/editor-common/styles");
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
13
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
14
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
15
  var codeBlockClassNames = {
@@ -67,12 +68,14 @@ var _toDOM = function toDOM(node, formattedAriaLabel, config) {
67
68
  'data-label': content
68
69
  }]], ['div', {
69
70
  class: codeBlockClassNames.content
70
- }, ['code', {
71
+ }, ['code', _objectSpread({
71
72
  'data-language': node.attrs.language || '',
72
73
  spellcheck: 'false',
73
74
  'data-testid': 'code-block--code',
74
75
  'aria-label': formattedAriaLabel
75
- }, 0]]], ['div', {
76
+ }, (0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid') && {
77
+ 'data-local-id': node.attrs.localId
78
+ }), 0]]], ['div', {
76
79
  class: codeBlockClassNames.end,
77
80
  contenteditable: 'false'
78
81
  }]];
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createCodeBlockMenuItem = void 0;
9
+ var _react = _interopRequireWildcard(require("react"));
10
+ var _reactIntlNext = require("react-intl-next");
11
+ var _messages = require("@atlaskit/editor-common/messages");
12
+ var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
13
+ var _state = require("@atlaskit/editor-prosemirror/state");
14
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
15
+ var _angleBrackets = _interopRequireDefault(require("@atlaskit/icon/core/angle-brackets"));
16
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
17
+ var nodeName = 'codeBlock';
18
+ var CodeBlockMenuItem = function CodeBlockMenuItem(_ref) {
19
+ var api = _ref.api;
20
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
21
+ formatMessage = _useIntl.formatMessage;
22
+ var selection = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'selection.selection');
23
+ var isCodeBlockSelected = (0, _react.useMemo)(function () {
24
+ if (!selection) {
25
+ return false;
26
+ }
27
+ if (selection instanceof _state.NodeSelection) {
28
+ // Note: we are checking for any type of panel, not just of type infopanel
29
+ return selection.node.type.name === nodeName;
30
+ }
31
+ return false;
32
+ }, [selection]);
33
+ var handleClick = function handleClick() {
34
+ var _api$blockMenu;
35
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.formatNode(nodeName));
36
+ };
37
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
38
+ onClick: handleClick,
39
+ isSelected: isCodeBlockSelected,
40
+ elemBefore: /*#__PURE__*/_react.default.createElement(_angleBrackets.default, {
41
+ label: ""
42
+ })
43
+ }, formatMessage(_messages.blockMenuMessages.codeBlock));
44
+ };
45
+ var createCodeBlockMenuItem = exports.createCodeBlockMenuItem = function createCodeBlockMenuItem(api) {
46
+ return function () {
47
+ return /*#__PURE__*/_react.default.createElement(CodeBlockMenuItem, {
48
+ api: api
49
+ });
50
+ };
51
+ };
@@ -1,33 +1,51 @@
1
+ import { FORMAT_MENU_ITEM, FORMAT_CODE_BLOCK_MENU_ITEM, FORMAT_NESTED_MENU_RANK } from '@atlaskit/editor-common/block-menu';
2
+ import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
1
3
  import { codeBlockNodeWithFixedToDOM } from './nodeviews/codeBlockNodeWithToDOMFixed';
2
4
  import { createPlugin } from './pm-plugins/main';
5
+ import { createCodeBlockMenuItem } from './ui/createCodeBlockMenuItem';
3
6
  export const codeBlockAdvancedPlugin = ({
4
7
  api,
5
8
  config
6
- }) => ({
7
- name: 'codeBlockAdvanced',
8
- nodes() {
9
- var _config$allowCodeFold;
10
- return [{
11
- name: 'codeBlock',
12
- node: codeBlockNodeWithFixedToDOM({
13
- allowCodeFolding: (_config$allowCodeFold = config === null || config === void 0 ? void 0 : config.allowCodeFolding) !== null && _config$allowCodeFold !== void 0 ? _config$allowCodeFold : false
14
- })
15
- }];
16
- },
17
- pmPlugins() {
18
- return [{
19
- name: 'codeBlockAdvancedPlugin',
20
- plugin: ({
21
- getIntl
22
- }) => {
23
- var _config$extensions, _config$allowCodeFold2;
24
- return createPlugin({
25
- api,
26
- extensions: (_config$extensions = config === null || config === void 0 ? void 0 : config.extensions) !== null && _config$extensions !== void 0 ? _config$extensions : [],
27
- allowCodeFolding: (_config$allowCodeFold2 = config === null || config === void 0 ? void 0 : config.allowCodeFolding) !== null && _config$allowCodeFold2 !== void 0 ? _config$allowCodeFold2 : false,
28
- getIntl
29
- });
30
- }
31
- }];
9
+ }) => {
10
+ if (expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true)) {
11
+ var _api$blockMenu;
12
+ api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.registerBlockMenuComponents([{
13
+ type: 'block-menu-item',
14
+ key: FORMAT_CODE_BLOCK_MENU_ITEM.key,
15
+ parent: {
16
+ type: 'block-menu-section',
17
+ key: FORMAT_MENU_ITEM.key,
18
+ rank: FORMAT_NESTED_MENU_RANK[FORMAT_CODE_BLOCK_MENU_ITEM.key]
19
+ },
20
+ component: createCodeBlockMenuItem(api)
21
+ }]);
32
22
  }
33
- });
23
+ return {
24
+ name: 'codeBlockAdvanced',
25
+ nodes() {
26
+ var _config$allowCodeFold;
27
+ return [{
28
+ name: 'codeBlock',
29
+ node: codeBlockNodeWithFixedToDOM({
30
+ allowCodeFolding: (_config$allowCodeFold = config === null || config === void 0 ? void 0 : config.allowCodeFolding) !== null && _config$allowCodeFold !== void 0 ? _config$allowCodeFold : false
31
+ })
32
+ }];
33
+ },
34
+ pmPlugins() {
35
+ return [{
36
+ name: 'codeBlockAdvancedPlugin',
37
+ plugin: ({
38
+ getIntl
39
+ }) => {
40
+ var _config$extensions, _config$allowCodeFold2;
41
+ return createPlugin({
42
+ api,
43
+ extensions: (_config$extensions = config === null || config === void 0 ? void 0 : config.extensions) !== null && _config$extensions !== void 0 ? _config$extensions : [],
44
+ allowCodeFolding: (_config$allowCodeFold2 = config === null || config === void 0 ? void 0 : config.allowCodeFolding) !== null && _config$allowCodeFold2 !== void 0 ? _config$allowCodeFold2 : false,
45
+ getIntl
46
+ });
47
+ }
48
+ }];
49
+ }
50
+ };
51
+ };
@@ -1,6 +1,7 @@
1
1
  import { codeBlock } from '@atlaskit/adf-schema';
2
2
  import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
3
3
  import { CodeBlockSharedCssClassName } from '@atlaskit/editor-common/styles';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
4
5
  const codeBlockClassNames = {
5
6
  container: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER,
6
7
  start: CodeBlockSharedCssClassName.CODEBLOCK_START,
@@ -59,7 +60,10 @@ const toDOM = (node, formattedAriaLabel, config) => {
59
60
  'data-language': node.attrs.language || '',
60
61
  spellcheck: 'false',
61
62
  'data-testid': 'code-block--code',
62
- 'aria-label': formattedAriaLabel
63
+ 'aria-label': formattedAriaLabel,
64
+ ...(fg('platform_editor_adf_with_localid') && {
65
+ 'data-local-id': node.attrs.localId
66
+ })
63
67
  }, 0]]], ['div', {
64
68
  class: codeBlockClassNames.end,
65
69
  contenteditable: 'false'
@@ -0,0 +1,42 @@
1
+ import React, { useMemo } from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { blockMenuMessages } from '@atlaskit/editor-common/messages';
4
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
5
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
6
+ import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
7
+ import AngleBracketsIcon from '@atlaskit/icon/core/angle-brackets';
8
+ const nodeName = 'codeBlock';
9
+ const CodeBlockMenuItem = ({
10
+ api
11
+ }) => {
12
+ const {
13
+ formatMessage
14
+ } = useIntl();
15
+ const selection = useSharedPluginStateSelector(api, 'selection.selection');
16
+ const isCodeBlockSelected = useMemo(() => {
17
+ if (!selection) {
18
+ return false;
19
+ }
20
+ if (selection instanceof NodeSelection) {
21
+ // Note: we are checking for any type of panel, not just of type infopanel
22
+ return selection.node.type.name === nodeName;
23
+ }
24
+ return false;
25
+ }, [selection]);
26
+ const handleClick = () => {
27
+ var _api$blockMenu;
28
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.formatNode(nodeName));
29
+ };
30
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
31
+ onClick: handleClick,
32
+ isSelected: isCodeBlockSelected,
33
+ elemBefore: /*#__PURE__*/React.createElement(AngleBracketsIcon, {
34
+ label: ""
35
+ })
36
+ }, formatMessage(blockMenuMessages.codeBlock));
37
+ };
38
+ export const createCodeBlockMenuItem = api => {
39
+ return () => /*#__PURE__*/React.createElement(CodeBlockMenuItem, {
40
+ api: api
41
+ });
42
+ };
@@ -1,8 +1,24 @@
1
+ import { FORMAT_MENU_ITEM, FORMAT_CODE_BLOCK_MENU_ITEM, FORMAT_NESTED_MENU_RANK } from '@atlaskit/editor-common/block-menu';
2
+ import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
1
3
  import { codeBlockNodeWithFixedToDOM } from './nodeviews/codeBlockNodeWithToDOMFixed';
2
4
  import { createPlugin } from './pm-plugins/main';
5
+ import { createCodeBlockMenuItem } from './ui/createCodeBlockMenuItem';
3
6
  export var codeBlockAdvancedPlugin = function codeBlockAdvancedPlugin(_ref) {
4
7
  var api = _ref.api,
5
8
  config = _ref.config;
9
+ if (expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true)) {
10
+ var _api$blockMenu;
11
+ api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents([{
12
+ type: 'block-menu-item',
13
+ key: FORMAT_CODE_BLOCK_MENU_ITEM.key,
14
+ parent: {
15
+ type: 'block-menu-section',
16
+ key: FORMAT_MENU_ITEM.key,
17
+ rank: FORMAT_NESTED_MENU_RANK[FORMAT_CODE_BLOCK_MENU_ITEM.key]
18
+ },
19
+ component: createCodeBlockMenuItem(api)
20
+ }]);
21
+ }
6
22
  return {
7
23
  name: 'codeBlockAdvanced',
8
24
  nodes: function nodes() {
@@ -4,6 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  import { codeBlock } from '@atlaskit/adf-schema';
5
5
  import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
6
6
  import { CodeBlockSharedCssClassName } from '@atlaskit/editor-common/styles';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
7
8
  var codeBlockClassNames = {
8
9
  container: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER,
9
10
  start: CodeBlockSharedCssClassName.CODEBLOCK_START,
@@ -60,12 +61,14 @@ var _toDOM = function toDOM(node, formattedAriaLabel, config) {
60
61
  'data-label': content
61
62
  }]], ['div', {
62
63
  class: codeBlockClassNames.content
63
- }, ['code', {
64
+ }, ['code', _objectSpread({
64
65
  'data-language': node.attrs.language || '',
65
66
  spellcheck: 'false',
66
67
  'data-testid': 'code-block--code',
67
68
  'aria-label': formattedAriaLabel
68
- }, 0]]], ['div', {
69
+ }, fg('platform_editor_adf_with_localid') && {
70
+ 'data-local-id': node.attrs.localId
71
+ }), 0]]], ['div', {
69
72
  class: codeBlockClassNames.end,
70
73
  contenteditable: 'false'
71
74
  }]];
@@ -0,0 +1,42 @@
1
+ import React, { useMemo } from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { blockMenuMessages } from '@atlaskit/editor-common/messages';
4
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
5
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
6
+ import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
7
+ import AngleBracketsIcon from '@atlaskit/icon/core/angle-brackets';
8
+ var nodeName = 'codeBlock';
9
+ var CodeBlockMenuItem = function CodeBlockMenuItem(_ref) {
10
+ var api = _ref.api;
11
+ var _useIntl = useIntl(),
12
+ formatMessage = _useIntl.formatMessage;
13
+ var selection = useSharedPluginStateSelector(api, 'selection.selection');
14
+ var isCodeBlockSelected = useMemo(function () {
15
+ if (!selection) {
16
+ return false;
17
+ }
18
+ if (selection instanceof NodeSelection) {
19
+ // Note: we are checking for any type of panel, not just of type infopanel
20
+ return selection.node.type.name === nodeName;
21
+ }
22
+ return false;
23
+ }, [selection]);
24
+ var handleClick = function handleClick() {
25
+ var _api$blockMenu;
26
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.formatNode(nodeName));
27
+ };
28
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
29
+ onClick: handleClick,
30
+ isSelected: isCodeBlockSelected,
31
+ elemBefore: /*#__PURE__*/React.createElement(AngleBracketsIcon, {
32
+ label: ""
33
+ })
34
+ }, formatMessage(blockMenuMessages.codeBlock));
35
+ };
36
+ export var createCodeBlockMenuItem = function createCodeBlockMenuItem(api) {
37
+ return function () {
38
+ return /*#__PURE__*/React.createElement(CodeBlockMenuItem, {
39
+ api: api
40
+ });
41
+ };
42
+ };
@@ -1,5 +1,6 @@
1
1
  import type { Extension } from '@codemirror/state';
2
2
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
+ import type { BlockMenuPlugin } from '@atlaskit/editor-plugin-block-menu';
3
4
  import type { CodeBlockPlugin } from '@atlaskit/editor-plugin-code-block';
4
5
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
5
6
  import type { FindReplacePlugin } from '@atlaskit/editor-plugin-find-replace';
@@ -11,7 +12,8 @@ export type CodeBlockAdvancedPlugin = NextEditorPlugin<'codeBlockAdvanced', {
11
12
  SelectionPlugin,
12
13
  OptionalPlugin<EditorDisabledPlugin>,
13
14
  OptionalPlugin<SelectionMarkerPlugin>,
14
- OptionalPlugin<FindReplacePlugin>
15
+ OptionalPlugin<FindReplacePlugin>,
16
+ OptionalPlugin<BlockMenuPlugin>
15
17
  ];
16
18
  pluginConfiguration: CodeBlockAdvancedPluginOptions | undefined;
17
19
  }>;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { CodeBlockAdvancedPlugin } from '../codeBlockAdvancedPluginType';
4
+ export declare const createCodeBlockMenuItem: (api: ExtractInjectionAPI<CodeBlockAdvancedPlugin>) => () => React.JSX.Element;
@@ -1,5 +1,6 @@
1
1
  import type { Extension } from '@codemirror/state';
2
2
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
+ import type { BlockMenuPlugin } from '@atlaskit/editor-plugin-block-menu';
3
4
  import type { CodeBlockPlugin } from '@atlaskit/editor-plugin-code-block';
4
5
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
5
6
  import type { FindReplacePlugin } from '@atlaskit/editor-plugin-find-replace';
@@ -11,7 +12,8 @@ export type CodeBlockAdvancedPlugin = NextEditorPlugin<'codeBlockAdvanced', {
11
12
  SelectionPlugin,
12
13
  OptionalPlugin<EditorDisabledPlugin>,
13
14
  OptionalPlugin<SelectionMarkerPlugin>,
14
- OptionalPlugin<FindReplacePlugin>
15
+ OptionalPlugin<FindReplacePlugin>,
16
+ OptionalPlugin<BlockMenuPlugin>
15
17
  ];
16
18
  pluginConfiguration: CodeBlockAdvancedPluginOptions | undefined;
17
19
  }>;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { CodeBlockAdvancedPlugin } from '../codeBlockAdvancedPluginType';
4
+ export declare const createCodeBlockMenuItem: (api: ExtractInjectionAPI<CodeBlockAdvancedPlugin>) => () => React.JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block-advanced",
3
- "version": "3.2.4",
3
+ "version": "4.0.1",
4
4
  "description": "CodeBlockAdvanced plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -29,14 +29,17 @@
29
29
  "atlaskit:src": "src/index.ts",
30
30
  "dependencies": {
31
31
  "@atlaskit/adf-schema": "^50.2.3",
32
- "@atlaskit/editor-plugin-code-block": "^5.0.0",
33
- "@atlaskit/editor-plugin-editor-disabled": "^3.0.0",
34
- "@atlaskit/editor-plugin-find-replace": "^3.2.0",
35
- "@atlaskit/editor-plugin-selection": "^3.2.0",
36
- "@atlaskit/editor-plugin-selection-marker": "^3.0.0",
32
+ "@atlaskit/editor-plugin-block-menu": "^1.0.0",
33
+ "@atlaskit/editor-plugin-code-block": "^6.0.0",
34
+ "@atlaskit/editor-plugin-editor-disabled": "^4.0.0",
35
+ "@atlaskit/editor-plugin-find-replace": "^4.0.0",
36
+ "@atlaskit/editor-plugin-selection": "^4.0.0",
37
+ "@atlaskit/editor-plugin-selection-marker": "^4.0.0",
37
38
  "@atlaskit/editor-prosemirror": "7.0.0",
39
+ "@atlaskit/editor-toolbar": "^0.7.0",
40
+ "@atlaskit/icon": "^28.1.0",
38
41
  "@atlaskit/platform-feature-flags": "^1.1.0",
39
- "@atlaskit/tmp-editor-statsig": "^11.9.0",
42
+ "@atlaskit/tmp-editor-statsig": "^12.2.0",
40
43
  "@atlaskit/tokens": "^6.1.0",
41
44
  "@babel/runtime": "^7.0.0",
42
45
  "@codemirror/autocomplete": "6.18.4",
@@ -52,8 +55,9 @@
52
55
  "codemirror-lang-elixir": "4.0.0"
53
56
  },
54
57
  "peerDependencies": {
55
- "@atlaskit/editor-common": "^107.33.0",
56
- "react": "^18.2.0"
58
+ "@atlaskit/editor-common": "^108.1.0",
59
+ "react": "^18.2.0",
60
+ "react-intl-next": "npm:react-intl@^5.18.1"
57
61
  },
58
62
  "devDependencies": {
59
63
  "@atlaskit/code": "^17.2.0"
@@ -100,6 +104,9 @@
100
104
  },
101
105
  "platform_editor_code_syntax_highlight_actionscript": {
102
106
  "type": "boolean"
107
+ },
108
+ "platform_editor_adf_with_localid": {
109
+ "type": "boolean"
103
110
  }
104
111
  }
105
112
  }
@@ -1,31 +1,58 @@
1
+ import {
2
+ FORMAT_MENU_ITEM,
3
+ FORMAT_CODE_BLOCK_MENU_ITEM,
4
+ FORMAT_NESTED_MENU_RANK,
5
+ } from '@atlaskit/editor-common/block-menu';
6
+ import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
7
+
1
8
  import type { CodeBlockAdvancedPlugin } from './codeBlockAdvancedPluginType';
2
9
  import { codeBlockNodeWithFixedToDOM } from './nodeviews/codeBlockNodeWithToDOMFixed';
3
10
  import { createPlugin } from './pm-plugins/main';
11
+ import { createCodeBlockMenuItem } from './ui/createCodeBlockMenuItem';
4
12
 
5
- export const codeBlockAdvancedPlugin: CodeBlockAdvancedPlugin = ({ api, config }) => ({
6
- name: 'codeBlockAdvanced',
7
-
8
- nodes() {
9
- return [
13
+ export const codeBlockAdvancedPlugin: CodeBlockAdvancedPlugin = ({ api, config }) => {
14
+ if (expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true)) {
15
+ api?.blockMenu?.actions.registerBlockMenuComponents([
10
16
  {
11
- name: 'codeBlock',
12
- node: codeBlockNodeWithFixedToDOM({ allowCodeFolding: config?.allowCodeFolding ?? false }),
17
+ type: 'block-menu-item',
18
+ key: FORMAT_CODE_BLOCK_MENU_ITEM.key,
19
+ parent: {
20
+ type: 'block-menu-section' as const,
21
+ key: FORMAT_MENU_ITEM.key,
22
+ rank: FORMAT_NESTED_MENU_RANK[FORMAT_CODE_BLOCK_MENU_ITEM.key],
23
+ },
24
+ component: createCodeBlockMenuItem(api),
13
25
  },
14
- ];
15
- },
26
+ ]);
27
+ }
16
28
 
17
- pmPlugins() {
18
- return [
19
- {
20
- name: 'codeBlockAdvancedPlugin',
21
- plugin: ({ getIntl }) =>
22
- createPlugin({
23
- api,
24
- extensions: config?.extensions ?? [],
29
+ return {
30
+ name: 'codeBlockAdvanced',
31
+
32
+ nodes() {
33
+ return [
34
+ {
35
+ name: 'codeBlock',
36
+ node: codeBlockNodeWithFixedToDOM({
25
37
  allowCodeFolding: config?.allowCodeFolding ?? false,
26
- getIntl,
27
38
  }),
28
- },
29
- ];
30
- },
31
- });
39
+ },
40
+ ];
41
+ },
42
+
43
+ pmPlugins() {
44
+ return [
45
+ {
46
+ name: 'codeBlockAdvancedPlugin',
47
+ plugin: ({ getIntl }) =>
48
+ createPlugin({
49
+ api,
50
+ extensions: config?.extensions ?? [],
51
+ allowCodeFolding: config?.allowCodeFolding ?? false,
52
+ getIntl,
53
+ }),
54
+ },
55
+ ];
56
+ },
57
+ };
58
+ };
@@ -1,6 +1,7 @@
1
1
  import type { Extension } from '@codemirror/state';
2
2
 
3
3
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
4
+ import type { BlockMenuPlugin } from '@atlaskit/editor-plugin-block-menu';
4
5
  import type { CodeBlockPlugin } from '@atlaskit/editor-plugin-code-block';
5
6
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
6
7
  import type { FindReplacePlugin } from '@atlaskit/editor-plugin-find-replace';
@@ -16,6 +17,7 @@ export type CodeBlockAdvancedPlugin = NextEditorPlugin<
16
17
  OptionalPlugin<EditorDisabledPlugin>,
17
18
  OptionalPlugin<SelectionMarkerPlugin>,
18
19
  OptionalPlugin<FindReplacePlugin>,
20
+ OptionalPlugin<BlockMenuPlugin>,
19
21
  ];
20
22
  pluginConfiguration: CodeBlockAdvancedPluginOptions | undefined;
21
23
  }
@@ -2,6 +2,7 @@ import { codeBlock } from '@atlaskit/adf-schema';
2
2
  import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
3
3
  import { CodeBlockSharedCssClassName } from '@atlaskit/editor-common/styles';
4
4
  import type { NodeSpec, DOMOutputSpec, Node } from '@atlaskit/editor-prosemirror/model';
5
+ import { fg } from '@atlaskit/platform-feature-flags';
5
6
  import { token } from '@atlaskit/tokens';
6
7
 
7
8
  interface Config {
@@ -94,6 +95,7 @@ const toDOM = (node: Node, formattedAriaLabel: string, config: Config): DOMOutpu
94
95
  spellcheck: 'false',
95
96
  'data-testid': 'code-block--code',
96
97
  'aria-label': formattedAriaLabel,
98
+ ...(fg('platform_editor_adf_with_localid') && { 'data-local-id': node.attrs.localId }),
97
99
  },
98
100
  0,
99
101
  ],
@@ -0,0 +1,54 @@
1
+ import React, { useMemo } from 'react';
2
+
3
+ import { useIntl } from 'react-intl-next';
4
+
5
+ import { blockMenuMessages } from '@atlaskit/editor-common/messages';
6
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
7
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
8
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
9
+ import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
10
+ import AngleBracketsIcon from '@atlaskit/icon/core/angle-brackets';
11
+
12
+ import type { CodeBlockAdvancedPlugin } from '../codeBlockAdvancedPluginType';
13
+
14
+ type Props = {
15
+ api: ExtractInjectionAPI<CodeBlockAdvancedPlugin> | undefined;
16
+ };
17
+
18
+ const nodeName = 'codeBlock';
19
+
20
+ const CodeBlockMenuItem = ({ api }: Props) => {
21
+ const { formatMessage } = useIntl();
22
+ const selection = useSharedPluginStateSelector(api, 'selection.selection');
23
+
24
+ const isCodeBlockSelected = useMemo(() => {
25
+ if (!selection) {
26
+ return false;
27
+ }
28
+
29
+ if (selection instanceof NodeSelection) {
30
+ // Note: we are checking for any type of panel, not just of type infopanel
31
+ return selection.node.type.name === nodeName;
32
+ }
33
+
34
+ return false;
35
+ }, [selection]);
36
+
37
+ const handleClick = () => {
38
+ api?.core.actions.execute(api?.blockMenu?.commands.formatNode(nodeName));
39
+ };
40
+
41
+ return (
42
+ <ToolbarDropdownItem
43
+ onClick={handleClick}
44
+ isSelected={isCodeBlockSelected}
45
+ elemBefore={<AngleBracketsIcon label="" />}
46
+ >
47
+ {formatMessage(blockMenuMessages.codeBlock)}
48
+ </ToolbarDropdownItem>
49
+ );
50
+ };
51
+
52
+ export const createCodeBlockMenuItem = (api: ExtractInjectionAPI<CodeBlockAdvancedPlugin>) => {
53
+ return () => <CodeBlockMenuItem api={api} />;
54
+ };
package/tsconfig.app.json CHANGED
@@ -37,6 +37,9 @@
37
37
  {
38
38
  "path": "../editor-common/tsconfig.app.json"
39
39
  },
40
+ {
41
+ "path": "../editor-plugin-block-menu/tsconfig.app.json"
42
+ },
40
43
  {
41
44
  "path": "../editor-plugin-code-block/tsconfig.app.json"
42
45
  },
@@ -52,6 +55,12 @@
52
55
  {
53
56
  "path": "../editor-plugin-selection-marker/tsconfig.app.json"
54
57
  },
58
+ {
59
+ "path": "../editor-toolbar/tsconfig.app.json"
60
+ },
61
+ {
62
+ "path": "../../design-system/icon/tsconfig.app.json"
63
+ },
55
64
  {
56
65
  "path": "../../platform/feature-flags/tsconfig.app.json"
57
66
  },