@atlaskit/editor-plugin-code-block-advanced 3.2.4 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/afm-cc/tsconfig.json +9 -0
- package/afm-jira/tsconfig.json +9 -0
- package/afm-post-office/tsconfig.json +9 -0
- package/afm-townsquare/tsconfig.json +9 -0
- package/dist/cjs/codeBlockAdvancedPlugin.js +16 -0
- package/dist/cjs/ui/createCodeBlockMenuItem.js +51 -0
- package/dist/es2019/codeBlockAdvancedPlugin.js +45 -27
- package/dist/es2019/ui/createCodeBlockMenuItem.js +42 -0
- package/dist/esm/codeBlockAdvancedPlugin.js +16 -0
- package/dist/esm/ui/createCodeBlockMenuItem.js +42 -0
- package/dist/types/codeBlockAdvancedPluginType.d.ts +3 -1
- package/dist/types/ui/createCodeBlockMenuItem.d.ts +4 -0
- package/dist/types-ts4.5/codeBlockAdvancedPluginType.d.ts +3 -1
- package/dist/types-ts4.5/ui/createCodeBlockMenuItem.d.ts +4 -0
- package/package.json +13 -9
- package/src/codeBlockAdvancedPlugin.tsx +49 -22
- package/src/codeBlockAdvancedPluginType.ts +2 -0
- package/src/ui/createCodeBlockMenuItem.tsx +54 -0
- package/tsconfig.app.json +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block-advanced
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`e882e86092666`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e882e86092666) -
|
|
8
|
+
[ux] Register expand, layout and code block itmes in block menu. Update panel item.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 3.2.4
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/afm-cc/tsconfig.json
CHANGED
|
@@ -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
|
},
|
package/afm-jira/tsconfig.json
CHANGED
|
@@ -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() {
|
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
};
|
|
@@ -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() {
|
|
@@ -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
|
+
"version": "4.0.0",
|
|
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-
|
|
33
|
-
"@atlaskit/editor-plugin-
|
|
34
|
-
"@atlaskit/editor-plugin-
|
|
35
|
-
"@atlaskit/editor-plugin-
|
|
36
|
-
"@atlaskit/editor-plugin-selection
|
|
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.6.0",
|
|
40
|
+
"@atlaskit/icon": "^28.1.0",
|
|
38
41
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
39
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
42
|
+
"@atlaskit/tmp-editor-statsig": "^12.0.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": "^
|
|
56
|
-
"react": "^18.2.0"
|
|
58
|
+
"@atlaskit/editor-common": "^108.0.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"
|
|
@@ -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
|
-
|
|
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
|
-
|
|
12
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
}
|
|
@@ -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
|
},
|