@atlaskit/editor-plugin-code-block 12.1.0 → 12.1.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
+ ## 12.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`7e8145e6a7ce6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7e8145e6a7ce6) -
8
+ Add ADF-backed code block line number visibility
9
+ - Updated dependencies
10
+
3
11
  ## 12.1.0
4
12
 
5
13
  ### Minor Changes
@@ -8,13 +8,14 @@ exports.copyContentToClipboardWithAnalytics = exports.copyContentToClipboard = e
8
8
  exports.createInsertCodeBlockTransaction = createInsertCodeBlockTransaction;
9
9
  exports.ignoreFollowingMutations = void 0;
10
10
  exports.insertCodeBlockWithAnalytics = insertCodeBlockWithAnalytics;
11
- exports.toggleWordWrapStateForCodeBlockNode = exports.resetShouldIgnoreFollowingMutations = exports.resetCopiedState = exports.removeCodeBlockWithAnalytics = exports.removeCodeBlock = void 0;
11
+ exports.toggleWordWrapStateForCodeBlockNode = exports.toggleLineNumbersForCodeBlockNodeEditorCommand = exports.toggleLineNumbersForCodeBlockNode = exports.resetShouldIgnoreFollowingMutations = exports.resetCopiedState = exports.removeCodeBlockWithAnalytics = exports.removeCodeBlock = void 0;
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
13
  var _analytics = require("@atlaskit/editor-common/analytics");
14
14
  var _clipboard = require("@atlaskit/editor-common/clipboard");
15
15
  var _codeBlock = require("@atlaskit/editor-common/code-block");
16
16
  var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
17
17
  var _insert = require("@atlaskit/editor-common/insert");
18
+ var _preset = require("@atlaskit/editor-common/preset");
18
19
  var _transforms = require("@atlaskit/editor-common/transforms");
19
20
  var _state = require("@atlaskit/editor-prosemirror/state");
20
21
  var _utils = require("@atlaskit/editor-prosemirror/utils");
@@ -268,4 +269,33 @@ var toggleWordWrapStateForCodeBlockNode = exports.toggleWordWrapStateForCodeBloc
268
269
  }
269
270
  return true;
270
271
  };
272
+ };
273
+ var toggleLineNumbersForCodeBlockNodeEditorCommand = exports.toggleLineNumbersForCodeBlockNodeEditorCommand = function toggleLineNumbersForCodeBlockNodeEditorCommand(editorAnalyticsAPI) {
274
+ return function (_ref2) {
275
+ var tr = _ref2.tr;
276
+ var codeBlockType = tr.doc.type.schema.nodes.codeBlock;
277
+ var codeBlock = (0, _utils.findSelectedNodeOfType)(codeBlockType)(tr.selection) || (0, _utils.findParentNodeOfType)(codeBlockType)(tr.selection);
278
+ if (!codeBlock) {
279
+ return null;
280
+ }
281
+ var codeBlockNode = codeBlock.node;
282
+ var lineNumbersHidden = !Boolean(codeBlockNode.attrs.hideLineNumbers);
283
+ tr.setNodeMarkup(codeBlock.pos, undefined, _objectSpread(_objectSpread({}, codeBlockNode.attrs), {}, {
284
+ hideLineNumbers: lineNumbersHidden
285
+ }));
286
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
287
+ action: _analytics.ACTION.TOGGLE_CODE_BLOCK_LINE_NUMBERS,
288
+ actionSubject: _analytics.ACTION_SUBJECT.CODE_BLOCK,
289
+ attributes: {
290
+ platform: _analytics.PLATFORMS.WEB,
291
+ lineNumbersHidden: lineNumbersHidden,
292
+ codeBlockNodeSize: codeBlockNode.nodeSize
293
+ },
294
+ eventType: _analytics.EVENT_TYPE.TRACK
295
+ })(tr);
296
+ return tr;
297
+ };
298
+ };
299
+ var toggleLineNumbersForCodeBlockNode = exports.toggleLineNumbersForCodeBlockNode = function toggleLineNumbersForCodeBlockNode(editorAnalyticsAPI) {
300
+ return (0, _preset.editorCommandToPMCommand)(toggleLineNumbersForCodeBlockNodeEditorCommand(editorAnalyticsAPI));
271
301
  };
@@ -14,7 +14,9 @@ var _toolbarFlagCheck = require("@atlaskit/editor-common/toolbar-flag-check");
14
14
  var _utils = require("@atlaskit/editor-prosemirror/utils");
15
15
  var _copy = _interopRequireDefault(require("@atlaskit/icon/core/copy"));
16
16
  var _delete = _interopRequireDefault(require("@atlaskit/icon/core/delete"));
17
+ var _listNumbered = _interopRequireDefault(require("@atlaskit/icon/core/list-numbered"));
17
18
  var _textWrap = _interopRequireDefault(require("@atlaskit/icon/core/text-wrap"));
19
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
18
20
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
19
21
  var _editorCommands = require("../editor-commands");
20
22
  var _WrapIcon = require("../ui/icons/WrapIcon");
@@ -46,6 +48,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig() {
46
48
  return;
47
49
  }
48
50
  var isWrapped = (0, _codeBlock.isCodeBlockWordWrapEnabled)(node);
51
+ var areLineNumbersVisible = (0, _codeBlock.areCodeBlockLineNumbersVisible)(node);
49
52
  var language = node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.language;
50
53
  var languageList = (0, _languageList.createLanguageList)(overrideLanguageName ? _languageList.DEFAULT_LANGUAGES.map(function (language) {
51
54
  return _objectSpread(_objectSpread({}, language), {}, {
@@ -158,7 +161,8 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig() {
158
161
  var codeBlockWrapButton = {
159
162
  id: 'editor.codeBlock.wrap',
160
163
  type: 'button',
161
- supportsViewMode: true,
164
+ // Toggling button now writes to ADF, hence it should be available in view mode
165
+ supportsViewMode: !(0, _expValEquals.expValEquals)('platform_editor_code_block_q4_lovability', 'isEnabled', true),
162
166
  icon: _textWrap.default,
163
167
  iconFallback: _WrapIcon.WrapIcon,
164
168
  onClick: (0, _editorCommands.toggleWordWrapStateForCodeBlockNode)(editorAnalyticsAPI),
@@ -166,6 +170,16 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig() {
166
170
  tabIndex: null,
167
171
  selected: isWrapped
168
172
  };
173
+ var codeBlockLineNumbersButton = {
174
+ id: 'editor.codeBlock.lineNumbers',
175
+ type: 'button',
176
+ supportsViewMode: false,
177
+ icon: _listNumbered.default,
178
+ onClick: (0, _editorCommands.toggleLineNumbersForCodeBlockNode)(editorAnalyticsAPI),
179
+ title: formatMessage(areLineNumbersVisible ? _messages.codeBlockButtonMessages.hideLineNumbersLabel : _messages.codeBlockButtonMessages.showLineNumbersLabel),
180
+ tabIndex: null,
181
+ selected: areLineNumbersVisible
182
+ };
169
183
  return {
170
184
  title: 'CodeBlock floating controls',
171
185
  // Ignored via go/ees005
@@ -174,7 +188,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig() {
174
188
  return (0, _utils.findDomRefAtPos)(pos, view.domAtPos.bind(view));
175
189
  },
176
190
  nodeType: nodeType,
177
- items: [languageSelect].concat((0, _toConsumableArray2.default)(areAnyNewToolbarFlagsEnabled ? [] : [separator]), [codeBlockWrapButton], (0, _toConsumableArray2.default)(copyAndDeleteButtonMenuItems)),
191
+ items: [languageSelect].concat((0, _toConsumableArray2.default)(areAnyNewToolbarFlagsEnabled ? [] : [separator]), [codeBlockWrapButton], (0, _toConsumableArray2.default)((0, _expValEquals.expValEquals)('platform_editor_code_block_q4_lovability', 'isEnabled', true) && (0, _platformFeatureFlags.fg)('platform_editor_code_block_add_line_number_button') ? [codeBlockLineNumbersButton] : []), (0, _toConsumableArray2.default)(copyAndDeleteButtonMenuItems)),
178
192
  scrollable: true
179
193
  };
180
194
  };
@@ -1,8 +1,9 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, MODE, PLATFORMS, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import { copyToClipboard, getAnalyticsPayload } from '@atlaskit/editor-common/clipboard';
3
- import { codeBlockWrappedStates, isCodeBlockWordWrapEnabled, getDefaultCodeBlockAttrs } from '@atlaskit/editor-common/code-block';
3
+ import { codeBlockWrappedStates, getDefaultCodeBlockAttrs, isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
4
4
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
5
5
  import { contentAllowedInCodeBlock, shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
6
+ import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
6
7
  import { findCodeBlock } from '@atlaskit/editor-common/transforms';
7
8
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
8
9
  import { findParentNodeOfType, findSelectedNodeOfType, isNodeSelection, removeParentNodeOfType, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
@@ -277,4 +278,33 @@ export const toggleWordWrapStateForCodeBlockNode = editorAnalyticsAPI => (state,
277
278
  dispatch(tr);
278
279
  }
279
280
  return true;
280
- };
281
+ };
282
+ export const toggleLineNumbersForCodeBlockNodeEditorCommand = editorAnalyticsAPI => ({
283
+ tr
284
+ }) => {
285
+ const {
286
+ codeBlock: codeBlockType
287
+ } = tr.doc.type.schema.nodes;
288
+ const codeBlock = findSelectedNodeOfType(codeBlockType)(tr.selection) || findParentNodeOfType(codeBlockType)(tr.selection);
289
+ if (!codeBlock) {
290
+ return null;
291
+ }
292
+ const codeBlockNode = codeBlock.node;
293
+ const lineNumbersHidden = !Boolean(codeBlockNode.attrs.hideLineNumbers);
294
+ tr.setNodeMarkup(codeBlock.pos, undefined, {
295
+ ...codeBlockNode.attrs,
296
+ hideLineNumbers: lineNumbersHidden
297
+ });
298
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
299
+ action: ACTION.TOGGLE_CODE_BLOCK_LINE_NUMBERS,
300
+ actionSubject: ACTION_SUBJECT.CODE_BLOCK,
301
+ attributes: {
302
+ platform: PLATFORMS.WEB,
303
+ lineNumbersHidden,
304
+ codeBlockNodeSize: codeBlockNode.nodeSize
305
+ },
306
+ eventType: EVENT_TYPE.TRACK
307
+ })(tr);
308
+ return tr;
309
+ };
310
+ export const toggleLineNumbersForCodeBlockNode = editorAnalyticsAPI => editorCommandToPMCommand(toggleLineNumbersForCodeBlockNodeEditorCommand(editorAnalyticsAPI));
@@ -1,12 +1,14 @@
1
- import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
1
+ import { areCodeBlockLineNumbersVisible, isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
2
2
  import commonMessages, { codeBlockButtonMessages } from '@atlaskit/editor-common/messages';
3
3
  import { areToolbarFlagsEnabled } from '@atlaskit/editor-common/toolbar-flag-check';
4
4
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
5
5
  import CopyIcon from '@atlaskit/icon/core/copy';
6
6
  import DeleteIcon from '@atlaskit/icon/core/delete';
7
+ import ListNumberedIcon from '@atlaskit/icon/core/list-numbered';
7
8
  import TextWrapIcon from '@atlaskit/icon/core/text-wrap';
9
+ import { fg } from '@atlaskit/platform-feature-flags';
8
10
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
- import { changeLanguage, copyContentToClipboardWithAnalytics, removeCodeBlockWithAnalytics, resetCopiedState, toggleWordWrapStateForCodeBlockNode } from '../editor-commands';
11
+ import { changeLanguage, copyContentToClipboardWithAnalytics, removeCodeBlockWithAnalytics, resetCopiedState, toggleLineNumbersForCodeBlockNode, toggleWordWrapStateForCodeBlockNode } from '../editor-commands';
10
12
  import { WrapIcon } from '../ui/icons/WrapIcon';
11
13
  import { provideVisualFeedbackForCopyButton, removeVisualFeedbackForCopyButton } from './codeBlockCopySelectionPlugin';
12
14
  import { createLanguageList, DEFAULT_LANGUAGES, getLanguageIdentifier } from './language-list';
@@ -31,6 +33,7 @@ export const getToolbarConfig = (allowCopyToClipboard = false, api, overrideLang
31
33
  return;
32
34
  }
33
35
  const isWrapped = isCodeBlockWordWrapEnabled(node);
36
+ const areLineNumbersVisible = areCodeBlockLineNumbersVisible(node);
34
37
  const language = node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.language;
35
38
  const languageList = createLanguageList(overrideLanguageName ? DEFAULT_LANGUAGES.map(language => ({
36
39
  ...language,
@@ -134,7 +137,8 @@ export const getToolbarConfig = (allowCopyToClipboard = false, api, overrideLang
134
137
  const codeBlockWrapButton = {
135
138
  id: 'editor.codeBlock.wrap',
136
139
  type: 'button',
137
- supportsViewMode: true,
140
+ // Toggling button now writes to ADF, hence it should be available in view mode
141
+ supportsViewMode: !expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true),
138
142
  icon: TextWrapIcon,
139
143
  iconFallback: WrapIcon,
140
144
  onClick: toggleWordWrapStateForCodeBlockNode(editorAnalyticsAPI),
@@ -142,13 +146,23 @@ export const getToolbarConfig = (allowCopyToClipboard = false, api, overrideLang
142
146
  tabIndex: null,
143
147
  selected: isWrapped
144
148
  };
149
+ const codeBlockLineNumbersButton = {
150
+ id: 'editor.codeBlock.lineNumbers',
151
+ type: 'button',
152
+ supportsViewMode: false,
153
+ icon: ListNumberedIcon,
154
+ onClick: toggleLineNumbersForCodeBlockNode(editorAnalyticsAPI),
155
+ title: formatMessage(areLineNumbersVisible ? codeBlockButtonMessages.hideLineNumbersLabel : codeBlockButtonMessages.showLineNumbersLabel),
156
+ tabIndex: null,
157
+ selected: areLineNumbersVisible
158
+ };
145
159
  return {
146
160
  title: 'CodeBlock floating controls',
147
161
  // Ignored via go/ees005
148
162
  // eslint-disable-next-line @atlaskit/editor/no-as-casting
149
163
  getDomRef: view => findDomRefAtPos(pos, view.domAtPos.bind(view)),
150
164
  nodeType,
151
- items: [languageSelect, ...(areAnyNewToolbarFlagsEnabled ? [] : [separator]), codeBlockWrapButton, ...copyAndDeleteButtonMenuItems],
165
+ items: [languageSelect, ...(areAnyNewToolbarFlagsEnabled ? [] : [separator]), codeBlockWrapButton, ...(expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) && fg('platform_editor_code_block_add_line_number_button') ? [codeBlockLineNumbersButton] : []), ...copyAndDeleteButtonMenuItems],
152
166
  scrollable: true
153
167
  };
154
168
  };
@@ -3,9 +3,10 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
3
  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) { _defineProperty(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; }
4
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, MODE, PLATFORMS, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
5
  import { copyToClipboard, getAnalyticsPayload } from '@atlaskit/editor-common/clipboard';
6
- import { codeBlockWrappedStates, isCodeBlockWordWrapEnabled, getDefaultCodeBlockAttrs } from '@atlaskit/editor-common/code-block';
6
+ import { codeBlockWrappedStates, getDefaultCodeBlockAttrs, isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
7
7
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
8
8
  import { contentAllowedInCodeBlock, shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
9
+ import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
9
10
  import { findCodeBlock } from '@atlaskit/editor-common/transforms';
10
11
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
11
12
  import { findParentNodeOfType, findSelectedNodeOfType, isNodeSelection, removeParentNodeOfType, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
@@ -257,4 +258,33 @@ export var toggleWordWrapStateForCodeBlockNode = function toggleWordWrapStateFor
257
258
  }
258
259
  return true;
259
260
  };
261
+ };
262
+ export var toggleLineNumbersForCodeBlockNodeEditorCommand = function toggleLineNumbersForCodeBlockNodeEditorCommand(editorAnalyticsAPI) {
263
+ return function (_ref2) {
264
+ var tr = _ref2.tr;
265
+ var codeBlockType = tr.doc.type.schema.nodes.codeBlock;
266
+ var codeBlock = findSelectedNodeOfType(codeBlockType)(tr.selection) || findParentNodeOfType(codeBlockType)(tr.selection);
267
+ if (!codeBlock) {
268
+ return null;
269
+ }
270
+ var codeBlockNode = codeBlock.node;
271
+ var lineNumbersHidden = !Boolean(codeBlockNode.attrs.hideLineNumbers);
272
+ tr.setNodeMarkup(codeBlock.pos, undefined, _objectSpread(_objectSpread({}, codeBlockNode.attrs), {}, {
273
+ hideLineNumbers: lineNumbersHidden
274
+ }));
275
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
276
+ action: ACTION.TOGGLE_CODE_BLOCK_LINE_NUMBERS,
277
+ actionSubject: ACTION_SUBJECT.CODE_BLOCK,
278
+ attributes: {
279
+ platform: PLATFORMS.WEB,
280
+ lineNumbersHidden: lineNumbersHidden,
281
+ codeBlockNodeSize: codeBlockNode.nodeSize
282
+ },
283
+ eventType: EVENT_TYPE.TRACK
284
+ })(tr);
285
+ return tr;
286
+ };
287
+ };
288
+ export var toggleLineNumbersForCodeBlockNode = function toggleLineNumbersForCodeBlockNode(editorAnalyticsAPI) {
289
+ return editorCommandToPMCommand(toggleLineNumbersForCodeBlockNodeEditorCommand(editorAnalyticsAPI));
260
290
  };
@@ -2,15 +2,17 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  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; }
4
4
  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) { _defineProperty(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; }
5
- import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
5
+ import { areCodeBlockLineNumbersVisible, isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
6
6
  import commonMessages, { codeBlockButtonMessages } from '@atlaskit/editor-common/messages';
7
7
  import { areToolbarFlagsEnabled } from '@atlaskit/editor-common/toolbar-flag-check';
8
8
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
9
9
  import CopyIcon from '@atlaskit/icon/core/copy';
10
10
  import DeleteIcon from '@atlaskit/icon/core/delete';
11
+ import ListNumberedIcon from '@atlaskit/icon/core/list-numbered';
11
12
  import TextWrapIcon from '@atlaskit/icon/core/text-wrap';
13
+ import { fg } from '@atlaskit/platform-feature-flags';
12
14
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
13
- import { changeLanguage, copyContentToClipboardWithAnalytics, removeCodeBlockWithAnalytics, resetCopiedState, toggleWordWrapStateForCodeBlockNode } from '../editor-commands';
15
+ import { changeLanguage, copyContentToClipboardWithAnalytics, removeCodeBlockWithAnalytics, resetCopiedState, toggleLineNumbersForCodeBlockNode, toggleWordWrapStateForCodeBlockNode } from '../editor-commands';
14
16
  import { WrapIcon } from '../ui/icons/WrapIcon';
15
17
  import { provideVisualFeedbackForCopyButton, removeVisualFeedbackForCopyButton } from './codeBlockCopySelectionPlugin';
16
18
  import { createLanguageList, DEFAULT_LANGUAGES, getLanguageIdentifier } from './language-list';
@@ -37,6 +39,7 @@ export var getToolbarConfig = function getToolbarConfig() {
37
39
  return;
38
40
  }
39
41
  var isWrapped = isCodeBlockWordWrapEnabled(node);
42
+ var areLineNumbersVisible = areCodeBlockLineNumbersVisible(node);
40
43
  var language = node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.language;
41
44
  var languageList = createLanguageList(overrideLanguageName ? DEFAULT_LANGUAGES.map(function (language) {
42
45
  return _objectSpread(_objectSpread({}, language), {}, {
@@ -149,7 +152,8 @@ export var getToolbarConfig = function getToolbarConfig() {
149
152
  var codeBlockWrapButton = {
150
153
  id: 'editor.codeBlock.wrap',
151
154
  type: 'button',
152
- supportsViewMode: true,
155
+ // Toggling button now writes to ADF, hence it should be available in view mode
156
+ supportsViewMode: !expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true),
153
157
  icon: TextWrapIcon,
154
158
  iconFallback: WrapIcon,
155
159
  onClick: toggleWordWrapStateForCodeBlockNode(editorAnalyticsAPI),
@@ -157,6 +161,16 @@ export var getToolbarConfig = function getToolbarConfig() {
157
161
  tabIndex: null,
158
162
  selected: isWrapped
159
163
  };
164
+ var codeBlockLineNumbersButton = {
165
+ id: 'editor.codeBlock.lineNumbers',
166
+ type: 'button',
167
+ supportsViewMode: false,
168
+ icon: ListNumberedIcon,
169
+ onClick: toggleLineNumbersForCodeBlockNode(editorAnalyticsAPI),
170
+ title: formatMessage(areLineNumbersVisible ? codeBlockButtonMessages.hideLineNumbersLabel : codeBlockButtonMessages.showLineNumbersLabel),
171
+ tabIndex: null,
172
+ selected: areLineNumbersVisible
173
+ };
160
174
  return {
161
175
  title: 'CodeBlock floating controls',
162
176
  // Ignored via go/ees005
@@ -165,7 +179,7 @@ export var getToolbarConfig = function getToolbarConfig() {
165
179
  return findDomRefAtPos(pos, view.domAtPos.bind(view));
166
180
  },
167
181
  nodeType: nodeType,
168
- items: [languageSelect].concat(_toConsumableArray(areAnyNewToolbarFlagsEnabled ? [] : [separator]), [codeBlockWrapButton], _toConsumableArray(copyAndDeleteButtonMenuItems)),
182
+ items: [languageSelect].concat(_toConsumableArray(areAnyNewToolbarFlagsEnabled ? [] : [separator]), [codeBlockWrapButton], _toConsumableArray(expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) && fg('platform_editor_code_block_add_line_number_button') ? [codeBlockLineNumbersButton] : []), _toConsumableArray(copyAndDeleteButtonMenuItems)),
169
183
  scrollable: true
170
184
  };
171
185
  };
@@ -1,6 +1,6 @@
1
1
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
- import type { Command } from '@atlaskit/editor-common/types';
3
+ import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
4
4
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
5
5
  export declare const removeCodeBlockWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
6
6
  export declare const removeCodeBlock: Command;
@@ -23,3 +23,5 @@ export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD,
23
23
  * Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
24
24
  */
25
25
  export declare const toggleWordWrapStateForCodeBlockNode: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
26
+ export declare const toggleLineNumbersForCodeBlockNodeEditorCommand: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => EditorCommand;
27
+ export declare const toggleLineNumbersForCodeBlockNode: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
@@ -1,6 +1,6 @@
1
1
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
- import type { Command } from '@atlaskit/editor-common/types';
3
+ import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
4
4
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
5
5
  export declare const removeCodeBlockWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
6
6
  export declare const removeCodeBlock: Command;
@@ -23,3 +23,5 @@ export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD,
23
23
  * Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
24
24
  */
25
25
  export declare const toggleWordWrapStateForCodeBlockNode: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
26
+ export declare const toggleLineNumbersForCodeBlockNodeEditorCommand: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => EditorCommand;
27
+ export declare const toggleLineNumbersForCodeBlockNode: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block",
3
- "version": "12.1.0",
3
+ "version": "12.1.1",
4
4
  "description": "Code block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -47,7 +47,7 @@
47
47
  "@babel/runtime": "^7.0.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "@atlaskit/editor-common": "^114.30.0",
50
+ "@atlaskit/editor-common": "^114.32.0",
51
51
  "react": "^18.2.0",
52
52
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
53
53
  },
@@ -98,6 +98,9 @@
98
98
  },
99
99
  "platform_editor_adf_with_localid": {
100
100
  "type": "boolean"
101
+ },
102
+ "platform_editor_code_block_add_line_number_button": {
103
+ "type": "boolean"
101
104
  }
102
105
  },
103
106
  "devDependencies": {