@atlaskit/editor-plugin-code-block 12.0.16 → 12.0.18

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,20 @@
1
1
  # @atlaskit/editor-plugin-code-block
2
2
 
3
+ ## 12.0.18
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 12.0.17
10
+
11
+ ### Patch Changes
12
+
13
+ - [`ded95ac7efcc4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ded95ac7efcc4) -
14
+ Persist code block wrap state in ADF, default code blocks created across editor runtime paths to
15
+ wrapped, and update the wrap toolbar tooltip behind platform_editor_code_block_q4_lovability.
16
+ - Updated dependencies
17
+
3
18
  ## 12.0.16
4
19
 
5
20
  ### Patch Changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
@@ -8,6 +9,7 @@ exports.createInsertCodeBlockTransaction = createInsertCodeBlockTransaction;
8
9
  exports.ignoreFollowingMutations = void 0;
9
10
  exports.insertCodeBlockWithAnalytics = insertCodeBlockWithAnalytics;
10
11
  exports.toggleWordWrapStateForCodeBlockNode = exports.resetShouldIgnoreFollowingMutations = exports.resetCopiedState = exports.removeCodeBlockWithAnalytics = exports.removeCodeBlock = void 0;
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
13
  var _analytics = require("@atlaskit/editor-common/analytics");
12
14
  var _clipboard = require("@atlaskit/editor-common/clipboard");
13
15
  var _codeBlock = require("@atlaskit/editor-common/code-block");
@@ -16,10 +18,13 @@ var _insert = require("@atlaskit/editor-common/insert");
16
18
  var _transforms = require("@atlaskit/editor-common/transforms");
17
19
  var _state = require("@atlaskit/editor-prosemirror/state");
18
20
  var _utils = require("@atlaskit/editor-prosemirror/utils");
21
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
19
22
  var _actions = require("../pm-plugins/actions");
20
23
  var _codeBlockCopySelectionPlugin = require("../pm-plugins/codeBlockCopySelectionPlugin");
21
24
  var _pluginKey = require("../pm-plugins/plugin-key");
22
25
  var _transformToCodeBlock = require("../pm-plugins/transform-to-code-block");
26
+ 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; }
27
+ 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; }
23
28
  var removeCodeBlockWithAnalytics = exports.removeCodeBlockWithAnalytics = function removeCodeBlockWithAnalytics(editorAnalyticsAPI) {
24
29
  return (0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, {
25
30
  action: _analytics.ACTION.DELETED,
@@ -53,9 +58,10 @@ var changeLanguage = exports.changeLanguage = function changeLanguage(editorAnal
53
58
  if (typeof pos !== 'number') {
54
59
  return false;
55
60
  }
56
- var tr = state.tr.setNodeMarkup(pos, codeBlock, {
61
+ var node = state.doc.nodeAt(pos);
62
+ var tr = state.tr.setNodeMarkup(pos, codeBlock, _objectSpread(_objectSpread({}, node === null || node === void 0 ? void 0 : node.attrs), {}, {
57
63
  language: language
58
- }).setMeta('scrollIntoView', false);
64
+ })).setMeta('scrollIntoView', false);
59
65
  var selection = (0, _utils.isNodeSelection)(state.selection) ? _state.NodeSelection.create(tr.doc, pos) : tr.selection;
60
66
  var result = tr.setSelection(selection);
61
67
  if (dispatch) {
@@ -181,6 +187,7 @@ function createInsertCodeBlockTransaction(_ref) {
181
187
  var tr = state.tr;
182
188
  var from = state.selection.from;
183
189
  var codeBlock = state.schema.nodes.codeBlock;
190
+ var codeBlockAttrs = (0, _codeBlock.getDefaultCodeBlockAttrs)();
184
191
  var grandParentNode = state.selection.$from.node(-1);
185
192
  var grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type;
186
193
  var parentNodeType = state.selection.$from.parent.type;
@@ -196,9 +203,9 @@ function createInsertCodeBlockTransaction(_ref) {
196
203
  content: codeBlock.createAndFill()
197
204
  }) && (0, _insert.contentAllowedInCodeBlock)(state);
198
205
  if (canInsertCodeBlock) {
199
- tr = (0, _transformToCodeBlock.transformToCodeBlockAction)(state, from, undefined);
206
+ tr = (0, _transformToCodeBlock.transformToCodeBlockAction)(state, from, codeBlockAttrs);
200
207
  } else {
201
- (0, _utils.safeInsert)(codeBlock.createAndFill())(tr).scrollIntoView();
208
+ (0, _utils.safeInsert)(codeBlock.createAndFill(codeBlockAttrs))(tr).scrollIntoView();
202
209
  }
203
210
  return tr;
204
211
  }
@@ -227,14 +234,20 @@ function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
227
234
  */
228
235
  var toggleWordWrapStateForCodeBlockNode = exports.toggleWordWrapStateForCodeBlockNode = function toggleWordWrapStateForCodeBlockNode(editorAnalyticsAPI) {
229
236
  return function (state, dispatch) {
230
- var _findCodeBlock;
231
- var codeBlockNode = (_findCodeBlock = (0, _transforms.findCodeBlock)(state)) === null || _findCodeBlock === void 0 ? void 0 : _findCodeBlock.node;
237
+ var codeBlock = (0, _transforms.findCodeBlock)(state);
238
+ var codeBlockNode = codeBlock === null || codeBlock === void 0 ? void 0 : codeBlock.node;
232
239
  var tr = state.tr;
233
240
  if (!_codeBlock.codeBlockWrappedStates || !codeBlockNode) {
234
241
  return false;
235
242
  }
236
243
  var updatedToggleState = !(0, _codeBlock.isCodeBlockWordWrapEnabled)(codeBlockNode);
237
- _codeBlock.codeBlockWrappedStates.set(codeBlockNode, updatedToggleState);
244
+ if ((0, _expValEquals.expValEquals)('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
245
+ tr.setNodeMarkup(codeBlock.pos, undefined, _objectSpread(_objectSpread({}, codeBlockNode.attrs), {}, {
246
+ wrap: updatedToggleState
247
+ }));
248
+ } else {
249
+ _codeBlock.codeBlockWrappedStates.set(codeBlockNode, updatedToggleState);
250
+ }
238
251
  tr.setMeta(_pluginKey.pluginKey, {
239
252
  type: _actions.ACTIONS.SET_IS_WRAPPED,
240
253
  data: updatedToggleState
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createCodeBlockInputRule = createCodeBlockInputRule;
7
7
  var _analytics = require("@atlaskit/editor-common/analytics");
8
+ var _codeBlock = require("@atlaskit/editor-common/code-block");
8
9
  var _commands = require("@atlaskit/editor-common/commands");
9
10
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
11
  var _utils = require("@atlaskit/editor-common/utils");
@@ -43,19 +44,15 @@ function getCodeBlockRules(editorAnalyticsAPI, schema) {
43
44
  if (!validMatchLength(match)) {
44
45
  return null;
45
46
  }
46
-
47
- // Ignored via go/ees005
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
- var attributes = {};
50
- if (match[4]) {
51
- attributes.language = match[4];
52
- }
47
+ var attributes = (0, _codeBlock.getDefaultCodeBlockAttrs)(match[4] ? {
48
+ language: match[4]
49
+ } : {});
53
50
  if ((0, _transformToCodeBlock.isConvertableToCodeBlock)(state)) {
54
51
  return (0, _transformToCodeBlock.transformToCodeBlockAction)(state, start, attributes);
55
52
  }
56
53
  var tr = state.tr;
57
54
  tr.delete(start, end);
58
- var codeBlock = tr.doc.type.schema.nodes.codeBlock.createChecked();
55
+ var codeBlock = tr.doc.type.schema.nodes.codeBlock.createChecked(attributes);
59
56
  (0, _utils2.safeInsert)(codeBlock)(tr);
60
57
  return tr;
61
58
  });
@@ -66,13 +63,9 @@ function getCodeBlockRules(editorAnalyticsAPI, schema) {
66
63
  if (!validMatchLength(match)) {
67
64
  return null;
68
65
  }
69
-
70
- // Ignored via go/ees005
71
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
- var attributes = {};
73
- if (match[4]) {
74
- attributes.language = match[4];
75
- }
66
+ var attributes = (0, _codeBlock.getDefaultCodeBlockAttrs)(match[4] ? {
67
+ language: match[4]
68
+ } : {});
76
69
  var inlineStart = Math.max(match.index + state.selection.$from.start(), 1);
77
70
  return (0, _commands.insertBlock)(state, schema.nodes.codeBlock, inlineStart, end, attributes);
78
71
  });
@@ -15,6 +15,7 @@ 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
17
  var _textWrap = _interopRequireDefault(require("@atlaskit/icon/core/text-wrap"));
18
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
18
19
  var _editorCommands = require("../editor-commands");
19
20
  var _WrapIcon = require("../ui/icons/WrapIcon");
20
21
  var _codeBlockCopySelectionPlugin = require("./codeBlockCopySelectionPlugin");
@@ -153,6 +154,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig() {
153
154
  };
154
155
  copyAndDeleteButtonMenuItems = [separator].concat(copyToClipboardItems, [deleteButton]);
155
156
  }
157
+ var codeBlockWrapButtonTitle = (0, _expValEquals.expValEquals)('platform_editor_code_block_q4_lovability', 'isEnabled', true) ? formatMessage(isWrapped ? _messages.codeBlockButtonMessages.unwrapCodeLabel : _messages.codeBlockButtonMessages.wrapCodeLabel) : formatMessage(_messages.codeBlockButtonMessages.wrapCode);
156
158
  var codeBlockWrapButton = {
157
159
  id: 'editor.codeBlock.wrap',
158
160
  type: 'button',
@@ -160,7 +162,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig() {
160
162
  icon: _textWrap.default,
161
163
  iconFallback: _WrapIcon.WrapIcon,
162
164
  onClick: (0, _editorCommands.toggleWordWrapStateForCodeBlockNode)(editorAnalyticsAPI),
163
- title: formatMessage(_messages.codeBlockButtonMessages.wrapCode),
165
+ title: codeBlockWrapButtonTitle,
164
166
  tabIndex: null,
165
167
  selected: isWrapped
166
168
  };
@@ -1,11 +1,12 @@
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 } from '@atlaskit/editor-common/code-block';
3
+ import { codeBlockWrappedStates, isCodeBlockWordWrapEnabled, getDefaultCodeBlockAttrs } 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
6
  import { findCodeBlock } from '@atlaskit/editor-common/transforms';
7
7
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
8
8
  import { findParentNodeOfType, findSelectedNodeOfType, isNodeSelection, removeParentNodeOfType, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
9
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
10
  import { ACTIONS } from '../pm-plugins/actions';
10
11
  import { copySelectionPluginKey } from '../pm-plugins/codeBlockCopySelectionPlugin';
11
12
  import { pluginKey } from '../pm-plugins/plugin-key';
@@ -47,7 +48,9 @@ export const changeLanguage = editorAnalyticsAPI => language => (state, dispatch
47
48
  if (typeof pos !== 'number') {
48
49
  return false;
49
50
  }
51
+ const node = state.doc.nodeAt(pos);
50
52
  const tr = state.tr.setNodeMarkup(pos, codeBlock, {
53
+ ...(node === null || node === void 0 ? void 0 : node.attrs),
51
54
  language
52
55
  }).setMeta('scrollIntoView', false);
53
56
  const selection = isNodeSelection(state.selection) ? NodeSelection.create(tr.doc, pos) : tr.selection;
@@ -192,6 +195,7 @@ export function createInsertCodeBlockTransaction({
192
195
  const {
193
196
  codeBlock
194
197
  } = state.schema.nodes;
198
+ const codeBlockAttrs = getDefaultCodeBlockAttrs();
195
199
  const grandParentNode = state.selection.$from.node(-1);
196
200
  const grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type;
197
201
  const parentNodeType = state.selection.$from.parent.type;
@@ -207,9 +211,9 @@ export function createInsertCodeBlockTransaction({
207
211
  content: codeBlock.createAndFill()
208
212
  }) && contentAllowedInCodeBlock(state);
209
213
  if (canInsertCodeBlock) {
210
- tr = transformToCodeBlockAction(state, from, undefined);
214
+ tr = transformToCodeBlockAction(state, from, codeBlockAttrs);
211
215
  } else {
212
- safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
216
+ safeInsert(codeBlock.createAndFill(codeBlockAttrs))(tr).scrollIntoView();
213
217
  }
214
218
  return tr;
215
219
  }
@@ -237,8 +241,8 @@ export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
237
241
  * Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
238
242
  */
239
243
  export const toggleWordWrapStateForCodeBlockNode = editorAnalyticsAPI => (state, dispatch) => {
240
- var _findCodeBlock;
241
- const codeBlockNode = (_findCodeBlock = findCodeBlock(state)) === null || _findCodeBlock === void 0 ? void 0 : _findCodeBlock.node;
244
+ const codeBlock = findCodeBlock(state);
245
+ const codeBlockNode = codeBlock === null || codeBlock === void 0 ? void 0 : codeBlock.node;
242
246
  const {
243
247
  tr
244
248
  } = state;
@@ -246,7 +250,14 @@ export const toggleWordWrapStateForCodeBlockNode = editorAnalyticsAPI => (state,
246
250
  return false;
247
251
  }
248
252
  const updatedToggleState = !isCodeBlockWordWrapEnabled(codeBlockNode);
249
- codeBlockWrappedStates.set(codeBlockNode, updatedToggleState);
253
+ if (expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
254
+ tr.setNodeMarkup(codeBlock.pos, undefined, {
255
+ ...codeBlockNode.attrs,
256
+ wrap: updatedToggleState
257
+ });
258
+ } else {
259
+ codeBlockWrappedStates.set(codeBlockNode, updatedToggleState);
260
+ }
250
261
  tr.setMeta(pluginKey, {
251
262
  type: ACTIONS.SET_IS_WRAPPED,
252
263
  data: updatedToggleState
@@ -1,4 +1,5 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { getDefaultCodeBlockAttrs } from '@atlaskit/editor-common/code-block';
2
3
  import { insertBlock } from '@atlaskit/editor-common/commands';
3
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
5
  import { createRule, inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
@@ -35,19 +36,15 @@ function getCodeBlockRules(editorAnalyticsAPI, schema) {
35
36
  if (!validMatchLength(match)) {
36
37
  return null;
37
38
  }
38
-
39
- // Ignored via go/ees005
40
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
- const attributes = {};
42
- if (match[4]) {
43
- attributes.language = match[4];
44
- }
39
+ const attributes = getDefaultCodeBlockAttrs(match[4] ? {
40
+ language: match[4]
41
+ } : {});
45
42
  if (isConvertableToCodeBlock(state)) {
46
43
  return transformToCodeBlockAction(state, start, attributes);
47
44
  }
48
45
  const tr = state.tr;
49
46
  tr.delete(start, end);
50
- const codeBlock = tr.doc.type.schema.nodes.codeBlock.createChecked();
47
+ const codeBlock = tr.doc.type.schema.nodes.codeBlock.createChecked(attributes);
51
48
  safeInsert(codeBlock)(tr);
52
49
  return tr;
53
50
  });
@@ -58,13 +55,9 @@ function getCodeBlockRules(editorAnalyticsAPI, schema) {
58
55
  if (!validMatchLength(match)) {
59
56
  return null;
60
57
  }
61
-
62
- // Ignored via go/ees005
63
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
- const attributes = {};
65
- if (match[4]) {
66
- attributes.language = match[4];
67
- }
58
+ const attributes = getDefaultCodeBlockAttrs(match[4] ? {
59
+ language: match[4]
60
+ } : {});
68
61
  const inlineStart = Math.max(match.index + state.selection.$from.start(), 1);
69
62
  return insertBlock(state, schema.nodes.codeBlock, inlineStart, end, attributes);
70
63
  });
@@ -5,6 +5,7 @@ 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
7
  import TextWrapIcon from '@atlaskit/icon/core/text-wrap';
8
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
8
9
  import { changeLanguage, copyContentToClipboardWithAnalytics, removeCodeBlockWithAnalytics, resetCopiedState, toggleWordWrapStateForCodeBlockNode } from '../editor-commands';
9
10
  import { WrapIcon } from '../ui/icons/WrapIcon';
10
11
  import { provideVisualFeedbackForCopyButton, removeVisualFeedbackForCopyButton } from './codeBlockCopySelectionPlugin';
@@ -129,6 +130,7 @@ export const getToolbarConfig = (allowCopyToClipboard = false, api, overrideLang
129
130
  };
130
131
  copyAndDeleteButtonMenuItems = [separator, ...copyToClipboardItems, deleteButton];
131
132
  }
133
+ const codeBlockWrapButtonTitle = expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) ? formatMessage(isWrapped ? codeBlockButtonMessages.unwrapCodeLabel : codeBlockButtonMessages.wrapCodeLabel) : formatMessage(codeBlockButtonMessages.wrapCode);
132
134
  const codeBlockWrapButton = {
133
135
  id: 'editor.codeBlock.wrap',
134
136
  type: 'button',
@@ -136,7 +138,7 @@ export const getToolbarConfig = (allowCopyToClipboard = false, api, overrideLang
136
138
  icon: TextWrapIcon,
137
139
  iconFallback: WrapIcon,
138
140
  onClick: toggleWordWrapStateForCodeBlockNode(editorAnalyticsAPI),
139
- title: formatMessage(codeBlockButtonMessages.wrapCode),
141
+ title: codeBlockWrapButtonTitle,
140
142
  tabIndex: null,
141
143
  selected: isWrapped
142
144
  };
@@ -1,11 +1,15 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
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; }
1
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, MODE, PLATFORMS, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
5
  import { copyToClipboard, getAnalyticsPayload } from '@atlaskit/editor-common/clipboard';
3
- import { codeBlockWrappedStates, isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
6
+ import { codeBlockWrappedStates, isCodeBlockWordWrapEnabled, getDefaultCodeBlockAttrs } from '@atlaskit/editor-common/code-block';
4
7
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
5
8
  import { contentAllowedInCodeBlock, shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
6
9
  import { findCodeBlock } from '@atlaskit/editor-common/transforms';
7
10
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
8
11
  import { findParentNodeOfType, findSelectedNodeOfType, isNodeSelection, removeParentNodeOfType, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
12
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
13
  import { ACTIONS } from '../pm-plugins/actions';
10
14
  import { copySelectionPluginKey } from '../pm-plugins/codeBlockCopySelectionPlugin';
11
15
  import { pluginKey } from '../pm-plugins/plugin-key';
@@ -43,9 +47,10 @@ export var changeLanguage = function changeLanguage(editorAnalyticsAPI) {
43
47
  if (typeof pos !== 'number') {
44
48
  return false;
45
49
  }
46
- var tr = state.tr.setNodeMarkup(pos, codeBlock, {
50
+ var node = state.doc.nodeAt(pos);
51
+ var tr = state.tr.setNodeMarkup(pos, codeBlock, _objectSpread(_objectSpread({}, node === null || node === void 0 ? void 0 : node.attrs), {}, {
47
52
  language: language
48
- }).setMeta('scrollIntoView', false);
53
+ })).setMeta('scrollIntoView', false);
49
54
  var selection = isNodeSelection(state.selection) ? NodeSelection.create(tr.doc, pos) : tr.selection;
50
55
  var result = tr.setSelection(selection);
51
56
  if (dispatch) {
@@ -171,6 +176,7 @@ export function createInsertCodeBlockTransaction(_ref) {
171
176
  var tr = state.tr;
172
177
  var from = state.selection.from;
173
178
  var codeBlock = state.schema.nodes.codeBlock;
179
+ var codeBlockAttrs = getDefaultCodeBlockAttrs();
174
180
  var grandParentNode = state.selection.$from.node(-1);
175
181
  var grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type;
176
182
  var parentNodeType = state.selection.$from.parent.type;
@@ -186,9 +192,9 @@ export function createInsertCodeBlockTransaction(_ref) {
186
192
  content: codeBlock.createAndFill()
187
193
  }) && contentAllowedInCodeBlock(state);
188
194
  if (canInsertCodeBlock) {
189
- tr = transformToCodeBlockAction(state, from, undefined);
195
+ tr = transformToCodeBlockAction(state, from, codeBlockAttrs);
190
196
  } else {
191
- safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
197
+ safeInsert(codeBlock.createAndFill(codeBlockAttrs))(tr).scrollIntoView();
192
198
  }
193
199
  return tr;
194
200
  }
@@ -217,14 +223,20 @@ export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
217
223
  */
218
224
  export var toggleWordWrapStateForCodeBlockNode = function toggleWordWrapStateForCodeBlockNode(editorAnalyticsAPI) {
219
225
  return function (state, dispatch) {
220
- var _findCodeBlock;
221
- var codeBlockNode = (_findCodeBlock = findCodeBlock(state)) === null || _findCodeBlock === void 0 ? void 0 : _findCodeBlock.node;
226
+ var codeBlock = findCodeBlock(state);
227
+ var codeBlockNode = codeBlock === null || codeBlock === void 0 ? void 0 : codeBlock.node;
222
228
  var tr = state.tr;
223
229
  if (!codeBlockWrappedStates || !codeBlockNode) {
224
230
  return false;
225
231
  }
226
232
  var updatedToggleState = !isCodeBlockWordWrapEnabled(codeBlockNode);
227
- codeBlockWrappedStates.set(codeBlockNode, updatedToggleState);
233
+ if (expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
234
+ tr.setNodeMarkup(codeBlock.pos, undefined, _objectSpread(_objectSpread({}, codeBlockNode.attrs), {}, {
235
+ wrap: updatedToggleState
236
+ }));
237
+ } else {
238
+ codeBlockWrappedStates.set(codeBlockNode, updatedToggleState);
239
+ }
228
240
  tr.setMeta(pluginKey, {
229
241
  type: ACTIONS.SET_IS_WRAPPED,
230
242
  data: updatedToggleState
@@ -1,4 +1,5 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { getDefaultCodeBlockAttrs } from '@atlaskit/editor-common/code-block';
2
3
  import { insertBlock } from '@atlaskit/editor-common/commands';
3
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
5
  import { createRule, inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
@@ -37,19 +38,15 @@ function getCodeBlockRules(editorAnalyticsAPI, schema) {
37
38
  if (!validMatchLength(match)) {
38
39
  return null;
39
40
  }
40
-
41
- // Ignored via go/ees005
42
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- var attributes = {};
44
- if (match[4]) {
45
- attributes.language = match[4];
46
- }
41
+ var attributes = getDefaultCodeBlockAttrs(match[4] ? {
42
+ language: match[4]
43
+ } : {});
47
44
  if (isConvertableToCodeBlock(state)) {
48
45
  return transformToCodeBlockAction(state, start, attributes);
49
46
  }
50
47
  var tr = state.tr;
51
48
  tr.delete(start, end);
52
- var codeBlock = tr.doc.type.schema.nodes.codeBlock.createChecked();
49
+ var codeBlock = tr.doc.type.schema.nodes.codeBlock.createChecked(attributes);
53
50
  safeInsert(codeBlock)(tr);
54
51
  return tr;
55
52
  });
@@ -60,13 +57,9 @@ function getCodeBlockRules(editorAnalyticsAPI, schema) {
60
57
  if (!validMatchLength(match)) {
61
58
  return null;
62
59
  }
63
-
64
- // Ignored via go/ees005
65
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
- var attributes = {};
67
- if (match[4]) {
68
- attributes.language = match[4];
69
- }
60
+ var attributes = getDefaultCodeBlockAttrs(match[4] ? {
61
+ language: match[4]
62
+ } : {});
70
63
  var inlineStart = Math.max(match.index + state.selection.$from.start(), 1);
71
64
  return insertBlock(state, schema.nodes.codeBlock, inlineStart, end, attributes);
72
65
  });
@@ -9,6 +9,7 @@ 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
11
  import TextWrapIcon from '@atlaskit/icon/core/text-wrap';
12
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
12
13
  import { changeLanguage, copyContentToClipboardWithAnalytics, removeCodeBlockWithAnalytics, resetCopiedState, toggleWordWrapStateForCodeBlockNode } from '../editor-commands';
13
14
  import { WrapIcon } from '../ui/icons/WrapIcon';
14
15
  import { provideVisualFeedbackForCopyButton, removeVisualFeedbackForCopyButton } from './codeBlockCopySelectionPlugin';
@@ -144,6 +145,7 @@ export var getToolbarConfig = function getToolbarConfig() {
144
145
  };
145
146
  copyAndDeleteButtonMenuItems = [separator].concat(copyToClipboardItems, [deleteButton]);
146
147
  }
148
+ var codeBlockWrapButtonTitle = expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) ? formatMessage(isWrapped ? codeBlockButtonMessages.unwrapCodeLabel : codeBlockButtonMessages.wrapCodeLabel) : formatMessage(codeBlockButtonMessages.wrapCode);
147
149
  var codeBlockWrapButton = {
148
150
  id: 'editor.codeBlock.wrap',
149
151
  type: 'button',
@@ -151,7 +153,7 @@ export var getToolbarConfig = function getToolbarConfig() {
151
153
  icon: TextWrapIcon,
152
154
  iconFallback: WrapIcon,
153
155
  onClick: toggleWordWrapStateForCodeBlockNode(editorAnalyticsAPI),
154
- title: formatMessage(codeBlockButtonMessages.wrapCode),
156
+ title: codeBlockWrapButtonTitle,
155
157
  tabIndex: null,
156
158
  selected: isWrapped
157
159
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block",
3
- "version": "12.0.16",
3
+ "version": "12.0.18",
4
4
  "description": "Code block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -27,7 +27,7 @@
27
27
  "sideEffects": false,
28
28
  "atlaskit:src": "src/index.ts",
29
29
  "dependencies": {
30
- "@atlaskit/adf-schema": "^52.9.0",
30
+ "@atlaskit/adf-schema": "^52.10.0",
31
31
  "@atlaskit/code": "^17.5.0",
32
32
  "@atlaskit/editor-plugin-analytics": "^10.0.0",
33
33
  "@atlaskit/editor-plugin-block-menu": "^9.0.0",
@@ -37,17 +37,17 @@
37
37
  "@atlaskit/editor-plugin-editor-viewmode": "^12.0.0",
38
38
  "@atlaskit/editor-plugin-interaction": "^19.0.0",
39
39
  "@atlaskit/editor-plugin-selection": "^10.0.0",
40
- "@atlaskit/editor-plugin-toolbar": "^7.0.0",
40
+ "@atlaskit/editor-plugin-toolbar": "^7.1.0",
41
41
  "@atlaskit/editor-prosemirror": "^7.3.0",
42
42
  "@atlaskit/editor-toolbar": "^1.0.0",
43
- "@atlaskit/icon": "^34.4.0",
43
+ "@atlaskit/icon": "^34.5.0",
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
45
  "@atlaskit/prosemirror-input-rules": "^3.6.0",
46
- "@atlaskit/tmp-editor-statsig": "^77.0.0",
46
+ "@atlaskit/tmp-editor-statsig": "^78.0.0",
47
47
  "@babel/runtime": "^7.0.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "@atlaskit/editor-common": "^114.20.0",
50
+ "@atlaskit/editor-common": "^114.26.0",
51
51
  "react": "^18.2.0",
52
52
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
53
53
  },