@atlaskit/editor-plugin-code-block 17.0.0 → 17.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,13 @@
1
1
  # @atlaskit/editor-plugin-code-block
2
2
 
3
+ ## 17.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`4273da2e1a648`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4273da2e1a648) -
8
+ Register native Quick Insert items behind `platform_editor_slash_command`.
9
+ - Updated dependencies
10
+
3
11
  ## 17.0.0
4
12
 
5
13
  ### Patch Changes
@@ -12,8 +12,9 @@ var _adfSchema = require("@atlaskit/adf-schema");
12
12
  var _analytics = require("@atlaskit/editor-common/analytics");
13
13
  var _blockMenu = require("@atlaskit/editor-common/block-menu");
14
14
  var _messages = require("@atlaskit/editor-common/messages");
15
- var _quickInsert = require("@atlaskit/editor-common/quick-insert");
16
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
15
+ var _assets = require("@atlaskit/editor-common/assets");
16
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
17
+ var _fg = require("@atlaskit/platform-feature-flags/fg");
17
18
  var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
18
19
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
19
20
  var _editorCommands = require("./editor-commands");
@@ -29,12 +30,14 @@ var _refreshBrowserSelection = _interopRequireDefault(require("./pm-plugins/refr
29
30
  var _toolbar = require("./pm-plugins/toolbar");
30
31
  var _CodeBlockMenuItem = require("./ui/CodeBlockMenuItem");
31
32
  var _FormatCodeErrorFlag = require("./ui/FormatCodeErrorFlag");
33
+ var _getCodeBlockQuickInsertComponents = require("./ui/quick-insert/getCodeBlockQuickInsertComponents");
32
34
  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; }
33
35
  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; }
34
36
  var CODE_BLOCK_NODE_NAME = 'codeBlock';
35
37
  var codeBlockPlugin = function codeBlockPlugin(_ref) {
36
38
  var options = _ref.config,
37
39
  api = _ref.api;
40
+ var isRegisteredSlashCommandEnabled = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_slash_command');
38
41
  if ((0, _experiments.editorExperiment)('platform_editor_block_menu', true)) {
39
42
  var _api$blockMenu;
40
43
  api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents([{
@@ -52,12 +55,18 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
52
55
  }
53
56
  }]);
54
57
  }
55
- return {
58
+ if (isRegisteredSlashCommandEnabled) {
59
+ var _api$uiControlRegistr;
60
+ api === null || api === void 0 || (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 || _api$uiControlRegistr.actions.register((0, _getCodeBlockQuickInsertComponents.getCodeBlockQuickInsertComponents)({
61
+ api: api
62
+ }));
63
+ }
64
+ var plugin = {
56
65
  name: 'codeBlock',
57
66
  nodes: function nodes() {
58
67
  return [{
59
68
  name: 'codeBlock',
60
- node: (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_code_block_q4_lovability', 'isEnabled', true) ? _adfSchema.codeBlock : (0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid') ? _adfSchema.codeBlockWithLocalId : _adfSchema.codeBlock
69
+ node: (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_code_block_q4_lovability', 'isEnabled', true) ? _adfSchema.codeBlock : (0, _fg.fg)('platform_editor_adf_with_localid') ? _adfSchema.codeBlockWithLocalId : _adfSchema.codeBlock
61
70
  }];
62
71
  },
63
72
  getSharedState: function getSharedState(state) {
@@ -89,7 +98,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
89
98
  var schema = _ref3.schema;
90
99
  return (0, _inputRule.createCodeBlockInputRule)(schema, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
91
100
  }
92
- }].concat((0, _toConsumableArray2.default)((0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_code_block_q4_lovability', 'isEnabled', true) && (0, _platformFeatureFlags.fg)('platform_editor_code_block_language_detection_flow') ? [{
101
+ }].concat((0, _toConsumableArray2.default)((0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_code_block_q4_lovability', 'isEnabled', true) && (0, _fg.fg)('platform_editor_code_block_language_detection_flow') ? [{
93
102
  name: 'codeBlockAutoDetect',
94
103
  plugin: function plugin() {
95
104
  return (0, _autoDetect.createAutoDetectPlugin)(api);
@@ -131,7 +140,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
131
140
  return (0, _editorCommands.insertCodeBlockWithAnalytics)(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
132
141
  }
133
142
  },
134
- pluginsOptions: {
143
+ pluginsOptions: _objectSpread(_objectSpread({}, !isRegisteredSlashCommandEnabled && {
135
144
  quickInsert: function quickInsert(_ref5) {
136
145
  var formatMessage = _ref5.formatMessage;
137
146
  return [{
@@ -142,7 +151,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
142
151
  priority: 700,
143
152
  keyshortcut: '```',
144
153
  icon: function icon() {
145
- return /*#__PURE__*/_react.default.createElement(_quickInsert.IconCode, null);
154
+ return /*#__PURE__*/_react.default.createElement(_assets.IconCode, null);
146
155
  },
147
156
  action: function action(_insert, state, source) {
148
157
  var _api$analytics3;
@@ -161,14 +170,16 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
161
170
  return tr;
162
171
  }
163
172
  }];
164
- },
173
+ }
174
+ }), {}, {
165
175
  floatingToolbar: (0, _toolbar.getToolbarConfig)(options === null || options === void 0 ? void 0 : options.allowCopyToClipboard, api, options === null || options === void 0 ? void 0 : options.overrideLanguageName, options === null || options === void 0 ? void 0 : options.formatCodeProvider)
166
- },
176
+ }),
167
177
  contentComponent: function contentComponent() {
168
178
  return (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_code_block_q4_lovability', 'isEnabled', true) ? /*#__PURE__*/_react.default.createElement(_FormatCodeErrorFlag.FormatCodeErrorFlag, {
169
179
  api: api
170
180
  }) : null;
171
181
  }
172
182
  };
183
+ return plugin;
173
184
  };
174
185
  var _default = exports.default = codeBlockPlugin;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.createFormatCodeOnClick = exports.copyContentToClipboardWithAnalytics = exports.copyContentToClipboard = exports.changeLanguage = void 0;
8
8
  exports.createInsertCodeBlockTransaction = createInsertCodeBlockTransaction;
9
+ exports.createInsertCodeBlockTransactionWithAnalytics = createInsertCodeBlockTransactionWithAnalytics;
9
10
  exports.ignoreFollowingMutations = exports.detectLanguage = void 0;
10
11
  exports.insertCodeBlockWithAnalytics = insertCodeBlockWithAnalytics;
11
12
  exports.toggleWordWrapStateForCodeBlockNode = exports.toggleLineNumbersForCodeBlockNodeEditorCommand = exports.toggleLineNumbersForCodeBlockNode = exports.resetShouldIgnoreFollowingMutations = exports.resetCopiedState = exports.removeCodeBlockWithAnalytics = exports.removeCodeBlock = void 0;
@@ -448,6 +449,24 @@ function createInsertCodeBlockTransaction(_ref8) {
448
449
  }
449
450
  return tr;
450
451
  }
452
+ function createInsertCodeBlockTransactionWithAnalytics(_ref9) {
453
+ var analyticsAPI = _ref9.analyticsAPI,
454
+ inputMethod = _ref9.inputMethod,
455
+ state = _ref9.state;
456
+ var tr = createInsertCodeBlockTransaction({
457
+ state: state
458
+ });
459
+ analyticsAPI === null || analyticsAPI === void 0 || analyticsAPI.attachAnalyticsEvent({
460
+ action: _analytics.ACTION.INSERTED,
461
+ actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
462
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.CODE_BLOCK,
463
+ attributes: {
464
+ inputMethod: inputMethod
465
+ },
466
+ eventType: _analytics.EVENT_TYPE.TRACK
467
+ })(tr);
468
+ return tr;
469
+ }
451
470
  function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
452
471
  return (0, _editorAnalytics.withAnalytics)(analyticsAPI, {
453
472
  action: _analytics.ACTION.INSERTED,
@@ -509,8 +528,8 @@ var toggleWordWrapStateForCodeBlockNode = exports.toggleWordWrapStateForCodeBloc
509
528
  };
510
529
  };
511
530
  var toggleLineNumbersForCodeBlockNodeEditorCommand = exports.toggleLineNumbersForCodeBlockNodeEditorCommand = function toggleLineNumbersForCodeBlockNodeEditorCommand(editorAnalyticsAPI) {
512
- return function (_ref9) {
513
- var tr = _ref9.tr;
531
+ return function (_ref0) {
532
+ var tr = _ref0.tr;
514
533
  var codeBlockType = tr.doc.type.schema.nodes.codeBlock;
515
534
  var codeBlock = (0, _utils.findSelectedNodeOfType)(codeBlockType)(tr.selection) || (0, _utils.findParentNodeOfType)(codeBlockType)(tr.selection);
516
535
  if (!codeBlock) {
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CodeBlockQuickInsertMenuItem = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _reactIntl = require("react-intl");
10
+ var _hooks = require("@atlaskit/editor-common/hooks");
11
+ var _messages = require("@atlaskit/editor-common/messages");
12
+ var _assets = require("@atlaskit/editor-common/assets");
13
+ var _menuItem = require("@atlaskit/editor-common/quick-insert/menu-item");
14
+ var _editorCommands = require("../../editor-commands");
15
+ 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); }
16
+ var CodeBlockQuickInsertMenuItem = exports.CodeBlockQuickInsertMenuItem = function CodeBlockQuickInsertMenuItem(_ref) {
17
+ var api = _ref.api;
18
+ var _useIntl = (0, _reactIntl.useIntl)(),
19
+ formatMessage = _useIntl.formatMessage;
20
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['editorDisabled'], function (states) {
21
+ var _states$editorDisable;
22
+ return {
23
+ editorDisabled: (_states$editorDisable = states.editorDisabledState) === null || _states$editorDisable === void 0 ? void 0 : _states$editorDisable.editorDisabled
24
+ };
25
+ }),
26
+ editorDisabled = _useSharedPluginState.editorDisabled;
27
+ var onSelect = (0, _react.useCallback)(function (_ref2) {
28
+ var _api$analytics;
29
+ var editorView = _ref2.editorView,
30
+ source = _ref2.source;
31
+ return (0, _editorCommands.createInsertCodeBlockTransactionWithAnalytics)({
32
+ analyticsAPI: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions,
33
+ inputMethod: source,
34
+ state: editorView.state
35
+ });
36
+ }, [api]);
37
+ return /*#__PURE__*/_react.default.createElement(_menuItem.QuickInsertMenuItem, {
38
+ iconBefore: /*#__PURE__*/_react.default.createElement(_assets.IconCode, null),
39
+ isDisabled: editorDisabled,
40
+ onSelect: onSelect,
41
+ shortcut: "```",
42
+ title: formatMessage(_messages.blockTypeMessages.codeblock)
43
+ });
44
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getCodeBlockQuickInsertComponents = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _messages = require("@atlaskit/editor-common/messages");
10
+ var _createQuickInsertMatcher = require("@atlaskit/editor-common/quick-insert/create-quick-insert-matcher");
11
+ var _keys = require("@atlaskit/editor-common/quick-insert/keys");
12
+ var _rank = require("@atlaskit/editor-common/quick-insert/rank");
13
+ var _CodeBlockQuickInsertMenuItem = require("./CodeBlockQuickInsertMenuItem");
14
+ var getCodeBlockQuickInsertComponents = exports.getCodeBlockQuickInsertComponents = function getCodeBlockQuickInsertComponents(_ref) {
15
+ var api = _ref.api;
16
+ return [{
17
+ key: _keys.CODE_BLOCK_MENU_ITEM.key,
18
+ type: _keys.CODE_BLOCK_MENU_ITEM.type,
19
+ parents: [{
20
+ key: _keys.STRUCTURE_SECTION.key,
21
+ type: _keys.STRUCTURE_SECTION.type,
22
+ rank: _rank.STRUCTURE_SECTION_RANK[_keys.CODE_BLOCK_MENU_ITEM.key]
23
+ }],
24
+ match: (0, _createQuickInsertMatcher.createQuickInsertMatcher)(function (_ref2) {
25
+ var formatMessage = _ref2.formatMessage;
26
+ return {
27
+ description: formatMessage(_messages.blockTypeMessages.codeblockDescription),
28
+ keywords: ['code block'],
29
+ shortcut: '```',
30
+ title: formatMessage(_messages.blockTypeMessages.codeblock)
31
+ };
32
+ }),
33
+ component: function component() {
34
+ return /*#__PURE__*/_react.default.createElement(_CodeBlockQuickInsertMenuItem.CodeBlockQuickInsertMenuItem, {
35
+ api: api
36
+ });
37
+ }
38
+ }];
39
+ };
@@ -3,8 +3,9 @@ import { codeBlock, codeBlockWithLocalId } from '@atlaskit/adf-schema';
3
3
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { TRANSFORM_STRUCTURE_MENU_SECTION, TRANSFORM_STRUCTURE_CODE_BLOCK_MENU_ITEM, TRANSFORM_STRUCTURE_MENU_SECTION_RANK } from '@atlaskit/editor-common/block-menu';
5
5
  import { blockTypeMessages } from '@atlaskit/editor-common/messages';
6
- import { IconCode } from '@atlaskit/editor-common/quick-insert';
7
- import { fg } from '@atlaskit/platform-feature-flags';
6
+ import { IconCode } from '@atlaskit/editor-common/assets';
7
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
8
+ import { fg } from '@atlaskit/platform-feature-flags/fg';
8
9
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
9
10
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
11
  import { createInsertCodeBlockTransaction, insertCodeBlockWithAnalytics } from './editor-commands';
@@ -20,11 +21,13 @@ import refreshBrowserSelectionOnChange from './pm-plugins/refresh-browser-select
20
21
  import { getToolbarConfig } from './pm-plugins/toolbar';
21
22
  import { createCodeBlockMenuItem } from './ui/CodeBlockMenuItem';
22
23
  import { FormatCodeErrorFlag } from './ui/FormatCodeErrorFlag';
24
+ import { getCodeBlockQuickInsertComponents } from './ui/quick-insert/getCodeBlockQuickInsertComponents';
23
25
  const CODE_BLOCK_NODE_NAME = 'codeBlock';
24
26
  const codeBlockPlugin = ({
25
27
  config: options,
26
28
  api
27
29
  }) => {
30
+ const isRegisteredSlashCommandEnabled = isExperimentEnabled('platform_editor_slash_command');
28
31
  if (editorExperiment('platform_editor_block_menu', true)) {
29
32
  var _api$blockMenu;
30
33
  api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.registerBlockMenuComponents([{
@@ -42,7 +45,13 @@ const codeBlockPlugin = ({
42
45
  }
43
46
  }]);
44
47
  }
45
- return {
48
+ if (isRegisteredSlashCommandEnabled) {
49
+ var _api$uiControlRegistr;
50
+ api === null || api === void 0 ? void 0 : (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 ? void 0 : _api$uiControlRegistr.actions.register(getCodeBlockQuickInsertComponents({
51
+ api
52
+ }));
53
+ }
54
+ const plugin = {
46
55
  name: 'codeBlock',
47
56
  nodes() {
48
57
  return [{
@@ -114,38 +123,41 @@ const codeBlockPlugin = ({
114
123
  }
115
124
  },
116
125
  pluginsOptions: {
117
- quickInsert: ({
118
- formatMessage
119
- }) => [{
120
- id: 'codeblock',
121
- title: formatMessage(blockTypeMessages.codeblock),
122
- description: formatMessage(blockTypeMessages.codeblockDescription),
123
- keywords: ['code block'],
124
- priority: 700,
125
- keyshortcut: '```',
126
- icon: () => /*#__PURE__*/React.createElement(IconCode, null),
127
- action(_insert, state, source) {
128
- var _api$analytics3;
129
- const tr = createInsertCodeBlockTransaction({
130
- state
131
- });
132
- api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.attachAnalyticsEvent({
133
- action: ACTION.INSERTED,
134
- actionSubject: ACTION_SUBJECT.DOCUMENT,
135
- actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
136
- attributes: {
137
- inputMethod: source || INPUT_METHOD.QUICK_INSERT
138
- },
139
- eventType: EVENT_TYPE.TRACK
140
- })(tr);
141
- return tr;
142
- }
143
- }],
126
+ ...(!isRegisteredSlashCommandEnabled && {
127
+ quickInsert: ({
128
+ formatMessage
129
+ }) => [{
130
+ id: 'codeblock',
131
+ title: formatMessage(blockTypeMessages.codeblock),
132
+ description: formatMessage(blockTypeMessages.codeblockDescription),
133
+ keywords: ['code block'],
134
+ priority: 700,
135
+ keyshortcut: '```',
136
+ icon: () => /*#__PURE__*/React.createElement(IconCode, null),
137
+ action(_insert, state, source) {
138
+ var _api$analytics3;
139
+ const tr = createInsertCodeBlockTransaction({
140
+ state
141
+ });
142
+ api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.attachAnalyticsEvent({
143
+ action: ACTION.INSERTED,
144
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
145
+ actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
146
+ attributes: {
147
+ inputMethod: source || INPUT_METHOD.QUICK_INSERT
148
+ },
149
+ eventType: EVENT_TYPE.TRACK
150
+ })(tr);
151
+ return tr;
152
+ }
153
+ }]
154
+ }),
144
155
  floatingToolbar: getToolbarConfig(options === null || options === void 0 ? void 0 : options.allowCopyToClipboard, api, options === null || options === void 0 ? void 0 : options.overrideLanguageName, options === null || options === void 0 ? void 0 : options.formatCodeProvider)
145
156
  },
146
157
  contentComponent: () => expValEqualsNoExposure('platform_editor_code_block_q4_lovability', 'isEnabled', true) ? /*#__PURE__*/React.createElement(FormatCodeErrorFlag, {
147
158
  api: api
148
159
  }) : null
149
160
  };
161
+ return plugin;
150
162
  };
151
163
  export default codeBlockPlugin;
@@ -457,6 +457,25 @@ export function createInsertCodeBlockTransaction({
457
457
  }
458
458
  return tr;
459
459
  }
460
+ export function createInsertCodeBlockTransactionWithAnalytics({
461
+ analyticsAPI,
462
+ inputMethod,
463
+ state
464
+ }) {
465
+ const tr = createInsertCodeBlockTransaction({
466
+ state
467
+ });
468
+ analyticsAPI === null || analyticsAPI === void 0 ? void 0 : analyticsAPI.attachAnalyticsEvent({
469
+ action: ACTION.INSERTED,
470
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
471
+ actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
472
+ attributes: {
473
+ inputMethod
474
+ },
475
+ eventType: EVENT_TYPE.TRACK
476
+ })(tr);
477
+ return tr;
478
+ }
460
479
  export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
461
480
  return withAnalytics(analyticsAPI, {
462
481
  action: ACTION.INSERTED,
@@ -0,0 +1,40 @@
1
+ import React, { useCallback } from 'react';
2
+ import { useIntl } from 'react-intl';
3
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
+ import { blockTypeMessages } from '@atlaskit/editor-common/messages';
5
+ import { IconCode } from '@atlaskit/editor-common/assets';
6
+ import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item';
7
+ import { createInsertCodeBlockTransactionWithAnalytics } from '../../editor-commands';
8
+ export const CodeBlockQuickInsertMenuItem = ({
9
+ api
10
+ }) => {
11
+ const {
12
+ formatMessage
13
+ } = useIntl();
14
+ const {
15
+ editorDisabled
16
+ } = useSharedPluginStateWithSelector(api, ['editorDisabled'], states => {
17
+ var _states$editorDisable;
18
+ return {
19
+ editorDisabled: (_states$editorDisable = states.editorDisabledState) === null || _states$editorDisable === void 0 ? void 0 : _states$editorDisable.editorDisabled
20
+ };
21
+ });
22
+ const onSelect = useCallback(({
23
+ editorView,
24
+ source
25
+ }) => {
26
+ var _api$analytics;
27
+ return createInsertCodeBlockTransactionWithAnalytics({
28
+ analyticsAPI: api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions,
29
+ inputMethod: source,
30
+ state: editorView.state
31
+ });
32
+ }, [api]);
33
+ return /*#__PURE__*/React.createElement(QuickInsertMenuItem, {
34
+ iconBefore: /*#__PURE__*/React.createElement(IconCode, null),
35
+ isDisabled: editorDisabled,
36
+ onSelect: onSelect,
37
+ shortcut: "```",
38
+ title: formatMessage(blockTypeMessages.codeblock)
39
+ });
40
+ };
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { blockTypeMessages } from '@atlaskit/editor-common/messages';
3
+ import { createQuickInsertMatcher } from '@atlaskit/editor-common/quick-insert/create-quick-insert-matcher';
4
+ import { CODE_BLOCK_MENU_ITEM, STRUCTURE_SECTION } from '@atlaskit/editor-common/quick-insert/keys';
5
+ import { STRUCTURE_SECTION_RANK } from '@atlaskit/editor-common/quick-insert/rank';
6
+ import { CodeBlockQuickInsertMenuItem } from './CodeBlockQuickInsertMenuItem';
7
+ export const getCodeBlockQuickInsertComponents = ({
8
+ api
9
+ }) => [{
10
+ key: CODE_BLOCK_MENU_ITEM.key,
11
+ type: CODE_BLOCK_MENU_ITEM.type,
12
+ parents: [{
13
+ key: STRUCTURE_SECTION.key,
14
+ type: STRUCTURE_SECTION.type,
15
+ rank: STRUCTURE_SECTION_RANK[CODE_BLOCK_MENU_ITEM.key]
16
+ }],
17
+ match: createQuickInsertMatcher(({
18
+ formatMessage
19
+ }) => ({
20
+ description: formatMessage(blockTypeMessages.codeblockDescription),
21
+ keywords: ['code block'],
22
+ shortcut: '```',
23
+ title: formatMessage(blockTypeMessages.codeblock)
24
+ })),
25
+ component: () => /*#__PURE__*/React.createElement(CodeBlockQuickInsertMenuItem, {
26
+ api: api
27
+ })
28
+ }];
@@ -7,8 +7,9 @@ import { codeBlock, codeBlockWithLocalId } from '@atlaskit/adf-schema';
7
7
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
8
8
  import { TRANSFORM_STRUCTURE_MENU_SECTION, TRANSFORM_STRUCTURE_CODE_BLOCK_MENU_ITEM, TRANSFORM_STRUCTURE_MENU_SECTION_RANK } from '@atlaskit/editor-common/block-menu';
9
9
  import { blockTypeMessages } from '@atlaskit/editor-common/messages';
10
- import { IconCode } from '@atlaskit/editor-common/quick-insert';
11
- import { fg } from '@atlaskit/platform-feature-flags';
10
+ import { IconCode } from '@atlaskit/editor-common/assets';
11
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
12
+ import { fg } from '@atlaskit/platform-feature-flags/fg';
12
13
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
13
14
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
14
15
  import { createInsertCodeBlockTransaction, insertCodeBlockWithAnalytics } from './editor-commands';
@@ -24,10 +25,12 @@ import refreshBrowserSelectionOnChange from './pm-plugins/refresh-browser-select
24
25
  import { getToolbarConfig } from './pm-plugins/toolbar';
25
26
  import { createCodeBlockMenuItem } from './ui/CodeBlockMenuItem';
26
27
  import { FormatCodeErrorFlag } from './ui/FormatCodeErrorFlag';
28
+ import { getCodeBlockQuickInsertComponents } from './ui/quick-insert/getCodeBlockQuickInsertComponents';
27
29
  var CODE_BLOCK_NODE_NAME = 'codeBlock';
28
30
  var codeBlockPlugin = function codeBlockPlugin(_ref) {
29
31
  var options = _ref.config,
30
32
  api = _ref.api;
33
+ var isRegisteredSlashCommandEnabled = isExperimentEnabled('platform_editor_slash_command');
31
34
  if (editorExperiment('platform_editor_block_menu', true)) {
32
35
  var _api$blockMenu;
33
36
  api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents([{
@@ -45,7 +48,13 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
45
48
  }
46
49
  }]);
47
50
  }
48
- return {
51
+ if (isRegisteredSlashCommandEnabled) {
52
+ var _api$uiControlRegistr;
53
+ api === null || api === void 0 || (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 || _api$uiControlRegistr.actions.register(getCodeBlockQuickInsertComponents({
54
+ api: api
55
+ }));
56
+ }
57
+ var plugin = {
49
58
  name: 'codeBlock',
50
59
  nodes: function nodes() {
51
60
  return [{
@@ -124,7 +133,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
124
133
  return insertCodeBlockWithAnalytics(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
125
134
  }
126
135
  },
127
- pluginsOptions: {
136
+ pluginsOptions: _objectSpread(_objectSpread({}, !isRegisteredSlashCommandEnabled && {
128
137
  quickInsert: function quickInsert(_ref5) {
129
138
  var formatMessage = _ref5.formatMessage;
130
139
  return [{
@@ -154,14 +163,16 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
154
163
  return tr;
155
164
  }
156
165
  }];
157
- },
166
+ }
167
+ }), {}, {
158
168
  floatingToolbar: getToolbarConfig(options === null || options === void 0 ? void 0 : options.allowCopyToClipboard, api, options === null || options === void 0 ? void 0 : options.overrideLanguageName, options === null || options === void 0 ? void 0 : options.formatCodeProvider)
159
- },
169
+ }),
160
170
  contentComponent: function contentComponent() {
161
171
  return expValEqualsNoExposure('platform_editor_code_block_q4_lovability', 'isEnabled', true) ? /*#__PURE__*/React.createElement(FormatCodeErrorFlag, {
162
172
  api: api
163
173
  }) : null;
164
174
  }
165
175
  };
176
+ return plugin;
166
177
  };
167
178
  export default codeBlockPlugin;
@@ -437,6 +437,24 @@ export function createInsertCodeBlockTransaction(_ref8) {
437
437
  }
438
438
  return tr;
439
439
  }
440
+ export function createInsertCodeBlockTransactionWithAnalytics(_ref9) {
441
+ var analyticsAPI = _ref9.analyticsAPI,
442
+ inputMethod = _ref9.inputMethod,
443
+ state = _ref9.state;
444
+ var tr = createInsertCodeBlockTransaction({
445
+ state: state
446
+ });
447
+ analyticsAPI === null || analyticsAPI === void 0 || analyticsAPI.attachAnalyticsEvent({
448
+ action: ACTION.INSERTED,
449
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
450
+ actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
451
+ attributes: {
452
+ inputMethod: inputMethod
453
+ },
454
+ eventType: EVENT_TYPE.TRACK
455
+ })(tr);
456
+ return tr;
457
+ }
440
458
  export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
441
459
  return withAnalytics(analyticsAPI, {
442
460
  action: ACTION.INSERTED,
@@ -498,8 +516,8 @@ export var toggleWordWrapStateForCodeBlockNode = function toggleWordWrapStateFor
498
516
  };
499
517
  };
500
518
  export var toggleLineNumbersForCodeBlockNodeEditorCommand = function toggleLineNumbersForCodeBlockNodeEditorCommand(editorAnalyticsAPI) {
501
- return function (_ref9) {
502
- var tr = _ref9.tr;
519
+ return function (_ref0) {
520
+ var tr = _ref0.tr;
503
521
  var codeBlockType = tr.doc.type.schema.nodes.codeBlock;
504
522
  var codeBlock = findSelectedNodeOfType(codeBlockType)(tr.selection) || findParentNodeOfType(codeBlockType)(tr.selection);
505
523
  if (!codeBlock) {
@@ -0,0 +1,36 @@
1
+ import React, { useCallback } from 'react';
2
+ import { useIntl } from 'react-intl';
3
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
+ import { blockTypeMessages } from '@atlaskit/editor-common/messages';
5
+ import { IconCode } from '@atlaskit/editor-common/assets';
6
+ import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item';
7
+ import { createInsertCodeBlockTransactionWithAnalytics } from '../../editor-commands';
8
+ export var CodeBlockQuickInsertMenuItem = function CodeBlockQuickInsertMenuItem(_ref) {
9
+ var api = _ref.api;
10
+ var _useIntl = useIntl(),
11
+ formatMessage = _useIntl.formatMessage;
12
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['editorDisabled'], function (states) {
13
+ var _states$editorDisable;
14
+ return {
15
+ editorDisabled: (_states$editorDisable = states.editorDisabledState) === null || _states$editorDisable === void 0 ? void 0 : _states$editorDisable.editorDisabled
16
+ };
17
+ }),
18
+ editorDisabled = _useSharedPluginState.editorDisabled;
19
+ var onSelect = useCallback(function (_ref2) {
20
+ var _api$analytics;
21
+ var editorView = _ref2.editorView,
22
+ source = _ref2.source;
23
+ return createInsertCodeBlockTransactionWithAnalytics({
24
+ analyticsAPI: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions,
25
+ inputMethod: source,
26
+ state: editorView.state
27
+ });
28
+ }, [api]);
29
+ return /*#__PURE__*/React.createElement(QuickInsertMenuItem, {
30
+ iconBefore: /*#__PURE__*/React.createElement(IconCode, null),
31
+ isDisabled: editorDisabled,
32
+ onSelect: onSelect,
33
+ shortcut: "```",
34
+ title: formatMessage(blockTypeMessages.codeblock)
35
+ });
36
+ };
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { blockTypeMessages } from '@atlaskit/editor-common/messages';
3
+ import { createQuickInsertMatcher } from '@atlaskit/editor-common/quick-insert/create-quick-insert-matcher';
4
+ import { CODE_BLOCK_MENU_ITEM, STRUCTURE_SECTION } from '@atlaskit/editor-common/quick-insert/keys';
5
+ import { STRUCTURE_SECTION_RANK } from '@atlaskit/editor-common/quick-insert/rank';
6
+ import { CodeBlockQuickInsertMenuItem } from './CodeBlockQuickInsertMenuItem';
7
+ export var getCodeBlockQuickInsertComponents = function getCodeBlockQuickInsertComponents(_ref) {
8
+ var api = _ref.api;
9
+ return [{
10
+ key: CODE_BLOCK_MENU_ITEM.key,
11
+ type: CODE_BLOCK_MENU_ITEM.type,
12
+ parents: [{
13
+ key: STRUCTURE_SECTION.key,
14
+ type: STRUCTURE_SECTION.type,
15
+ rank: STRUCTURE_SECTION_RANK[CODE_BLOCK_MENU_ITEM.key]
16
+ }],
17
+ match: createQuickInsertMatcher(function (_ref2) {
18
+ var formatMessage = _ref2.formatMessage;
19
+ return {
20
+ description: formatMessage(blockTypeMessages.codeblockDescription),
21
+ keywords: ['code block'],
22
+ shortcut: '```',
23
+ title: formatMessage(blockTypeMessages.codeblock)
24
+ };
25
+ }),
26
+ component: function component() {
27
+ return /*#__PURE__*/React.createElement(CodeBlockQuickInsertMenuItem, {
28
+ api: api
29
+ });
30
+ }
31
+ }];
32
+ };
@@ -10,6 +10,7 @@ import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
10
10
  import type { InteractionPlugin } from '@atlaskit/editor-plugin-interaction';
11
11
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
12
12
  import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
13
+ import type { UiControlRegistryPlugin } from '@atlaskit/editor-plugin-ui-control-registry';
13
14
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
14
15
  import type { CodeBlockState } from './pm-plugins/main-state';
15
16
  import type { CodeBlockPluginOptions } from './types';
@@ -23,7 +24,8 @@ type CodeBlockDependencies = [
23
24
  OptionalPlugin<EditorViewModePlugin>,
24
25
  OptionalPlugin<BlockMenuPlugin>,
25
26
  OptionalPlugin<SelectionPlugin>,
26
- OptionalPlugin<ToolbarPlugin>
27
+ OptionalPlugin<ToolbarPlugin>,
28
+ OptionalPlugin<UiControlRegistryPlugin>
27
29
  ];
28
30
  export type CodeBlockPlugin = NextEditorPlugin<'codeBlock', {
29
31
  actions: {
@@ -28,6 +28,11 @@ export declare const resetShouldIgnoreFollowingMutations: Command;
28
28
  export declare function createInsertCodeBlockTransaction({ state }: {
29
29
  state: EditorState;
30
30
  }): Transaction;
31
+ export declare function createInsertCodeBlockTransactionWithAnalytics({ analyticsAPI, inputMethod, state, }: {
32
+ analyticsAPI?: EditorAnalyticsAPI;
33
+ inputMethod: INPUT_METHOD.FORMATTING | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.ELEMENT_BROWSER;
34
+ state: EditorState;
35
+ }): Transaction;
31
36
  export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI): Command;
32
37
  /**
33
38
  * Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { CodeBlockPlugin } from '../../codeBlockPluginType';
4
+ export declare const CodeBlockQuickInsertMenuItem: ({ api, }: {
5
+ api: ExtractInjectionAPI<CodeBlockPlugin> | undefined;
6
+ }) => React.JSX.Element;
@@ -0,0 +1,6 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { RegisterMenuItem } from '@atlaskit/editor-ui-control-model/types';
3
+ import type { CodeBlockPlugin } from '../../codeBlockPluginType';
4
+ export declare const getCodeBlockQuickInsertComponents: ({ api, }: {
5
+ api: ExtractInjectionAPI<CodeBlockPlugin> | undefined;
6
+ }) => RegisterMenuItem[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block",
3
- "version": "17.0.0",
3
+ "version": "17.0.1",
4
4
  "description": "Code block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,9 +35,11 @@
35
35
  "@atlaskit/editor-prosemirror": "^8.0.0",
36
36
  "@atlaskit/editor-shared-styles": "^4.0.0",
37
37
  "@atlaskit/editor-toolbar": "^2.4.0",
38
+ "@atlaskit/editor-ui-control-model": "^2.6.0",
38
39
  "@atlaskit/flag": "^18.2.0",
39
40
  "@atlaskit/frontend-utilities": "^4.1.0",
40
41
  "@atlaskit/icon": "^37.3.0",
42
+ "@atlaskit/platform-feature-experiments": "^0.3.0",
41
43
  "@atlaskit/platform-feature-flags": "^2.1.0",
42
44
  "@atlaskit/primitives": "^22.2.0",
43
45
  "@atlaskit/prosemirror-input-rules": "^4.0.0",
@@ -48,7 +50,7 @@
48
50
  "@compiled/react": "^1.0.2"
49
51
  },
50
52
  "peerDependencies": {
51
- "@atlaskit/editor-common": "^119.0.0",
53
+ "@atlaskit/editor-common": "^119.1.0",
52
54
  "react": "^18.2.0 || ^19.2.0",
53
55
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
54
56
  },