@atlaskit/editor-plugin-code-block 3.3.1 → 3.3.3

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,26 @@
1
1
  # @atlaskit/editor-plugin-code-block
2
2
 
3
+ ## 3.3.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`0f58d3a82867c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0f58d3a82867c) -
8
+ ED-24500 Add decorators on init of code block and on document updates
9
+
10
+ ## 3.3.2
11
+
12
+ ### Patch Changes
13
+
14
+ - [#128111](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/128111)
15
+ [`9863ffeb3e73e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9863ffeb3e73e) -
16
+ remove codeblock preserve newlines ff
17
+ - [#129049](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/129049)
18
+ [`6b1533d389c9d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6b1533d389c9d) -
19
+ [ux] ED-24511 - Convert code block line numbers inline decorations to widget decorations. The line
20
+ number gutter on editor code blocks should now reflect the number of lines of code, including when
21
+ the code block has word wrap enabled. Minor for editor-common as new analytics attribute added.
22
+ - Updated dependencies
23
+
3
24
  ## 3.3.1
4
25
 
5
26
  ### Patch Changes
@@ -230,7 +230,8 @@ var toggleWordWrapStateForCodeBlockNode = exports.toggleWordWrapStateForCodeBloc
230
230
  attributes: {
231
231
  platform: _analytics.PLATFORMS.WEB,
232
232
  mode: _analytics.MODE.EDITOR,
233
- wordWrapEnabled: updatedToggleState
233
+ wordWrapEnabled: updatedToggleState,
234
+ codeBlockNodeSize: codeBlockNode.nodeSize
234
235
  },
235
236
  eventType: _analytics.EVENT_TYPE.TRACK
236
237
  })(tr);
package/dist/cjs/index.js CHANGED
@@ -10,17 +10,4 @@ Object.defineProperty(exports, "codeBlockPlugin", {
10
10
  return _plugin.default;
11
11
  }
12
12
  });
13
- Object.defineProperty(exports, "createDecorationSetFromTextPositions", {
14
- enumerable: true,
15
- get: function get() {
16
- return _decorators.createDecorationSetFromTextPositions;
17
- }
18
- });
19
- Object.defineProperty(exports, "generateTextPositionsFromNode", {
20
- enumerable: true,
21
- get: function get() {
22
- return _decorators.generateTextPositionsFromNode;
23
- }
24
- });
25
- var _plugin = _interopRequireDefault(require("./plugin"));
26
- var _decorators = require("./pm-plugins/decorators");
13
+ var _plugin = _interopRequireDefault(require("./plugin"));
@@ -24,12 +24,12 @@ var toDOM = function toDOM(node, contentEditable) {
24
24
  class: _classNames.codeBlockClassNames.start,
25
25
  contenteditable: 'false'
26
26
  }], ['div', {
27
- class: _classNames.codeBlockClassNames.contentWrapper
27
+ class: "".concat(_classNames.codeBlockClassNames.contentWrapper, " ").concat((0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') && _classNames.codeBlockClassNames.contentWrapperFg)
28
28
  }, ['div', {
29
- class: (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? _classNames.codeBlockClassNames.gutterFgWrap : _classNames.codeBlockClassNames.gutter,
29
+ class: (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? _classNames.codeBlockClassNames.gutterFg : _classNames.codeBlockClassNames.gutter,
30
30
  contenteditable: 'false'
31
31
  }], ['div', {
32
- class: _classNames.codeBlockClassNames.content
32
+ class: (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? "".concat(_classNames.codeBlockClassNames.contentFg) : _classNames.codeBlockClassNames.content
33
33
  }, ['code', {
34
34
  'data-language': node.attrs.language || '',
35
35
  spellcheck: 'false',
@@ -69,7 +69,7 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
69
69
  this.node = _node;
70
70
  this.dom = dom;
71
71
  this.contentDOM = contentDOM;
72
- this.lineNumberGutter = this.dom.querySelector(".".concat((0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? _classNames.codeBlockClassNames.gutterFgWrap : _classNames.codeBlockClassNames.gutter));
72
+ this.lineNumberGutter = this.dom.querySelector(".".concat((0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? _classNames.codeBlockClassNames.gutterFg : _classNames.codeBlockClassNames.gutter));
73
73
  this.api = api;
74
74
  if (!(0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping')) {
75
75
  this.ensureLineNumbers();
@@ -4,49 +4,66 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.generateTextPositionsFromNode = exports.createLineNumbersDecorations = exports.createDecorationSetFromTextPositions = void 0;
7
+ exports.generateLineAttributesFromNode = exports.createLineNumbersDecorations = exports.createDecorationSetFromLineAttributes = exports.DECORATION_WIDGET_TYPE = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _view = require("@atlaskit/editor-prosemirror/view");
10
10
  var _classNames = require("../ui/class-names");
11
- var DECORATION_INLINE_TYPE = 'decorationInlineType';
12
- var generateTextPositionsFromNode = exports.generateTextPositionsFromNode = function generateTextPositionsFromNode(pos, node) {
11
+ var DECORATION_WIDGET_TYPE = exports.DECORATION_WIDGET_TYPE = 'decorationWidgetType';
12
+ var generateLineAttributesFromNode = exports.generateLineAttributesFromNode = function generateLineAttributesFromNode(pos, node) {
13
13
  // Get content node
14
14
  var contentNode = node.content;
15
15
 
16
16
  // Get node text content
17
- var textPositions = [];
17
+ var lineAttributes = [];
18
+
19
+ // Early exit if content size is 0
20
+ if (contentNode.size === 0) {
21
+ return [{
22
+ lineStart: pos + 1,
23
+ lineNumber: 1
24
+ }];
25
+ }
18
26
  contentNode.forEach(function (child) {
19
27
  var nodeTextContent = child.textContent;
20
28
  var nodeStartPos = pos;
21
29
  var lineStartIndex = nodeStartPos;
22
- var newLinePositions = nodeTextContent.split('\n').map(function (line) {
30
+ var newLineAttributes = nodeTextContent.split('\n').map(function (line, index) {
23
31
  var lineLength = line.length;
24
32
  var lineStart = lineStartIndex + 1;
25
- var lineEnd = lineStart + lineLength;
33
+ var lineNumber = index + 1;
26
34
 
27
35
  // Include the newline character and increment to keep tabs on line position
28
36
  lineStartIndex += lineLength + 1;
29
37
  return {
30
38
  lineStart: lineStart,
31
- lineEnd: lineEnd
39
+ lineNumber: lineNumber
32
40
  };
33
41
  });
34
- textPositions = [].concat((0, _toConsumableArray2.default)(textPositions), (0, _toConsumableArray2.default)(newLinePositions));
42
+ lineAttributes = [].concat((0, _toConsumableArray2.default)(lineAttributes), (0, _toConsumableArray2.default)(newLineAttributes));
35
43
  });
36
- return textPositions;
44
+ return lineAttributes;
37
45
  };
38
- var createDecorationSetFromTextPositions = exports.createDecorationSetFromTextPositions = function createDecorationSetFromTextPositions(textPositions) {
39
- var decorations = textPositions.map(function (textPosition) {
40
- var lineStart = textPosition.lineStart,
41
- lineEnd = textPosition.lineEnd;
42
- return _view.Decoration.inline(lineStart, lineEnd, {
43
- class: _classNames.codeBlockClassNames.lineNumberWrapped
44
- }, {
45
- type: DECORATION_INLINE_TYPE
46
+ var createDecorationSetFromLineAttributes = exports.createDecorationSetFromLineAttributes = function createDecorationSetFromLineAttributes(lineAttributes) {
47
+ var widgetDecorations = lineAttributes.map(function (lineAttribute) {
48
+ var lineStart = lineAttribute.lineStart,
49
+ lineNumber = lineAttribute.lineNumber;
50
+
51
+ // Passing a function to create the widget rather than directly passing a widget, as per ProseMirror docs.
52
+ var createLineNumberWidget = function createLineNumberWidget() {
53
+ var widget = document.createElement('span');
54
+ widget.textContent = "".concat(lineNumber);
55
+ widget.classList.add(_classNames.codeBlockClassNames.lineNumberWidget);
56
+ return widget;
57
+ };
58
+
59
+ // side -1 is used so the line numbers are the first thing to the left of the lines of code.
60
+ return _view.Decoration.widget(lineStart, createLineNumberWidget, {
61
+ type: DECORATION_WIDGET_TYPE,
62
+ side: -1
46
63
  });
47
64
  });
48
- return decorations;
65
+ return widgetDecorations;
49
66
  };
50
67
  var createLineNumbersDecorations = exports.createLineNumbersDecorations = function createLineNumbersDecorations(pos, node) {
51
- return createDecorationSetFromTextPositions(generateTextPositionsFromNode(pos, node));
68
+ return createDecorationSetFromLineAttributes(generateLineAttributesFromNode(pos, node));
52
69
  };
@@ -9,7 +9,6 @@ var _utils = require("@atlaskit/editor-common/utils");
9
9
  var _keymap = require("@atlaskit/editor-prosemirror/keymap");
10
10
  var _state = require("@atlaskit/editor-prosemirror/state");
11
11
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
12
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
12
  var _utils3 = require("../utils");
14
13
  var deleteCurrentItem = function deleteCurrentItem($from) {
15
14
  return function (tr) {
@@ -58,7 +57,6 @@ function keymapPlugin(schema) {
58
57
  var _state$schema$nodes2 = state.schema.nodes,
59
58
  codeBlock = _state$schema$nodes2.codeBlock,
60
59
  listItem = _state$schema$nodes2.listItem,
61
- paragraph = _state$schema$nodes2.paragraph,
62
60
  table = _state$schema$nodes2.table,
63
61
  layoutColumn = _state$schema$nodes2.layoutColumn;
64
62
  if (!$cursor || $cursor.parent.type !== codeBlock || !dispatch) {
@@ -69,11 +67,7 @@ function keymapPlugin(schema) {
69
67
  if (!node) {
70
68
  return false;
71
69
  }
72
- if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.codeblock-preserve-newlines_54r3m')) {
73
- replaceWithParagraph(node.node, node.pos, $cursor, state, dispatch);
74
- } else {
75
- dispatch(state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, []).setBlockType($cursor.pos, $cursor.pos, paragraph));
76
- }
70
+ replaceWithParagraph(node.node, node.pos, $cursor, state, dispatch);
77
71
  return true;
78
72
  }
79
73
  if ($cursor.node && (0, _utils.isEmptyNode)(schema)($cursor.node()) && ((0, _utils2.hasParentNodeOfType)(layoutColumn)(state.selection) || (0, _utils2.hasParentNodeOfType)(table)(state.selection))) {
@@ -32,6 +32,17 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
32
32
  allowCompositionInputOverride = _ref$allowComposition === void 0 ? false : _ref$allowComposition,
33
33
  api = _ref.api;
34
34
  var handleDOMEvents = {};
35
+ var createLineNumberDecoratorsFromDecendants = function createLineNumberDecoratorsFromDecendants(editorState) {
36
+ var lineNumberDecorators = [];
37
+ editorState.doc.descendants(function (node, pos) {
38
+ if (node.type === editorState.schema.nodes.codeBlock) {
39
+ lineNumberDecorators.push.apply(lineNumberDecorators, (0, _toConsumableArray2.default)((0, _decorators.createLineNumbersDecorations)(pos, node)));
40
+ return false;
41
+ }
42
+ return true;
43
+ });
44
+ return lineNumberDecorators;
45
+ };
35
46
  var createWordWrappedDecoratorPluginState = function createWordWrappedDecoratorPluginState(pluginState, tr, node) {
36
47
  var decorationSetFromState = pluginState.decorations;
37
48
  if (node) {
@@ -48,7 +59,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
48
59
  decorationSetFromState = decorationSetFromState.remove(currentWrappedBlockDecorationSet);
49
60
  } else {
50
61
  var wrappedBlock = _view.Decoration.node(pos, pos + innerNode.nodeSize, {
51
- class: _classNames.codeBlockClassNames.wrapped
62
+ class: _classNames.codeBlockClassNames.contentFgWrapped
52
63
  }, {
53
64
  type: DECORATION_WRAPPED_BLOCK_NODE_TYPE
54
65
  } // Allows for quick filtering of decorations while using `find`
@@ -59,19 +70,19 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
59
70
  }
60
71
  return decorationSetFromState;
61
72
  };
62
- var createLineDecoratorPluginState = function createLineDecoratorPluginState(pluginState, tr, node) {
73
+ var createLineDecoratorPluginState = function createLineDecoratorPluginState(pluginState, tr, state) {
63
74
  var decorationSetFromState = pluginState.decorations;
64
- if (node) {
65
- var pos = node.pos,
66
- innerNode = node.node;
67
- if (pos !== undefined) {
68
- // Reset the decorations for the children of the code block node. Wipes all line number decorations.
69
- // @ts-ignore
70
- decorationSetFromState.children = [];
71
- var lineDecorators = (0, _decorators.createLineNumbersDecorations)(pos, innerNode);
72
- decorationSetFromState = decorationSetFromState.add(tr.doc, (0, _toConsumableArray2.default)(lineDecorators));
73
- }
74
- }
75
+ // remove all the line number children from the decorations set. 'undefined, undefined' is used to find() the whole doc.
76
+ var children = decorationSetFromState.find(undefined, undefined, function (spec) {
77
+ return spec.type === _decorators.DECORATION_WIDGET_TYPE;
78
+ });
79
+ decorationSetFromState = decorationSetFromState.remove(children);
80
+
81
+ // regenerate all the line number for the documents code blocks
82
+ var lineDecorators = createLineNumberDecoratorsFromDecendants(state);
83
+
84
+ // add the newly generated line numbers to the decorations set
85
+ decorationSetFromState = decorationSetFromState.add(tr.doc, (0, _toConsumableArray2.default)(lineDecorators));
75
86
  return decorationSetFromState;
76
87
  };
77
88
 
@@ -117,12 +128,13 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
117
128
  state: {
118
129
  init: function init(_, state) {
119
130
  var node = (0, _utils2.findCodeBlock)(state, state.selection);
131
+ var lineNumberDecorators = (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? createLineNumberDecoratorsFromDecendants(state) : [];
120
132
  return {
121
133
  pos: node ? node.pos : null,
122
134
  contentCopied: false,
123
135
  isNodeSelected: false,
124
136
  shouldIgnoreFollowingMutations: false,
125
- decorations: _view.DecorationSet.empty
137
+ decorations: _view.DecorationSet.create(state.doc, lineNumberDecorators)
126
138
  };
127
139
  },
128
140
  apply: function apply(tr, pluginState, _oldState, newState) {
@@ -138,7 +150,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
138
150
  var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
139
151
  pos: _node ? _node.pos : null,
140
152
  isNodeSelected: tr.selection instanceof _state.NodeSelection,
141
- decorations: (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? createLineDecoratorPluginState(pluginState, tr, _node) : _view.DecorationSet.empty
153
+ decorations: (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? createLineDecoratorPluginState(pluginState, tr, newState) : _view.DecorationSet.empty
142
154
  });
143
155
  return newPluginState;
144
156
  }
@@ -11,9 +11,11 @@ var codeBlockClassNames = exports.codeBlockClassNames = {
11
11
  end: _styles.CodeBlockSharedCssClassName.CODEBLOCK_END,
12
12
  contentWrapper: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER,
13
13
  gutter: _styles.CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER,
14
- gutterFgWrap: _styles.CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER_FG_WRAP,
15
14
  content: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT,
16
- contentWrapped: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPED,
17
- lineNumberWrapped: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER_LINE_NUMBER_WRAPPED,
18
- wrapped: _styles.CodeBlockSharedCssClassName.CODEBLOCK_WRAPPED
15
+ // Feature Gate editor_support_code_block_wrapping:
16
+ contentWrapperFg: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER_FG,
17
+ contentFg: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_FG,
18
+ contentFgWrapped: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_FG_WRAPPED,
19
+ lineNumberWidget: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER_LINE_NUMBER_WIDGET,
20
+ gutterFg: _styles.CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER_FG
19
21
  };
@@ -241,7 +241,8 @@ export const toggleWordWrapStateForCodeBlockNode = editorAnalyticsAPI => (state,
241
241
  attributes: {
242
242
  platform: PLATFORMS.WEB,
243
243
  mode: MODE.EDITOR,
244
- wordWrapEnabled: updatedToggleState
244
+ wordWrapEnabled: updatedToggleState,
245
+ codeBlockNodeSize: codeBlockNode.nodeSize
245
246
  },
246
247
  eventType: EVENT_TYPE.TRACK
247
248
  })(tr);
@@ -1,2 +1 @@
1
- export { default as codeBlockPlugin } from './plugin';
2
- export { createDecorationSetFromTextPositions, generateTextPositionsFromNode } from './pm-plugins/decorators';
1
+ export { default as codeBlockPlugin } from './plugin';
@@ -14,12 +14,12 @@ const toDOM = (node, contentEditable) => ['div', {
14
14
  class: codeBlockClassNames.start,
15
15
  contenteditable: 'false'
16
16
  }], ['div', {
17
- class: codeBlockClassNames.contentWrapper
17
+ class: `${codeBlockClassNames.contentWrapper} ${fg('editor_support_code_block_wrapping') && codeBlockClassNames.contentWrapperFg}`
18
18
  }, ['div', {
19
- class: fg('editor_support_code_block_wrapping') ? codeBlockClassNames.gutterFgWrap : codeBlockClassNames.gutter,
19
+ class: fg('editor_support_code_block_wrapping') ? codeBlockClassNames.gutterFg : codeBlockClassNames.gutter,
20
20
  contenteditable: 'false'
21
21
  }], ['div', {
22
- class: codeBlockClassNames.content
22
+ class: fg('editor_support_code_block_wrapping') ? `${codeBlockClassNames.contentFg}` : codeBlockClassNames.content
23
23
  }, ['code', {
24
24
  'data-language': node.attrs.language || '',
25
25
  spellcheck: 'false',
@@ -57,7 +57,7 @@ export class CodeBlockView {
57
57
  this.node = _node;
58
58
  this.dom = dom;
59
59
  this.contentDOM = contentDOM;
60
- this.lineNumberGutter = this.dom.querySelector(`.${fg('editor_support_code_block_wrapping') ? codeBlockClassNames.gutterFgWrap : codeBlockClassNames.gutter}`);
60
+ this.lineNumberGutter = this.dom.querySelector(`.${fg('editor_support_code_block_wrapping') ? codeBlockClassNames.gutterFg : codeBlockClassNames.gutter}`);
61
61
  this.api = api;
62
62
  if (!fg('editor_support_code_block_wrapping')) {
63
63
  this.ensureLineNumbers();
@@ -1,44 +1,61 @@
1
1
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
2
2
  import { codeBlockClassNames } from '../ui/class-names';
3
- const DECORATION_INLINE_TYPE = 'decorationInlineType';
4
- export const generateTextPositionsFromNode = (pos, node) => {
3
+ export const DECORATION_WIDGET_TYPE = 'decorationWidgetType';
4
+ export const generateLineAttributesFromNode = (pos, node) => {
5
5
  // Get content node
6
6
  const contentNode = node.content;
7
7
 
8
8
  // Get node text content
9
- let textPositions = [];
9
+ let lineAttributes = [];
10
+
11
+ // Early exit if content size is 0
12
+ if (contentNode.size === 0) {
13
+ return [{
14
+ lineStart: pos + 1,
15
+ lineNumber: 1
16
+ }];
17
+ }
10
18
  contentNode.forEach(child => {
11
19
  const nodeTextContent = child.textContent;
12
20
  const nodeStartPos = pos;
13
21
  let lineStartIndex = nodeStartPos;
14
- const newLinePositions = nodeTextContent.split('\n').map(line => {
22
+ const newLineAttributes = nodeTextContent.split('\n').map((line, index) => {
15
23
  const lineLength = line.length;
16
24
  const lineStart = lineStartIndex + 1;
17
- const lineEnd = lineStart + lineLength;
25
+ const lineNumber = index + 1;
18
26
 
19
27
  // Include the newline character and increment to keep tabs on line position
20
28
  lineStartIndex += lineLength + 1;
21
29
  return {
22
30
  lineStart,
23
- lineEnd
31
+ lineNumber
24
32
  };
25
33
  });
26
- textPositions = [...textPositions, ...newLinePositions];
34
+ lineAttributes = [...lineAttributes, ...newLineAttributes];
27
35
  });
28
- return textPositions;
36
+ return lineAttributes;
29
37
  };
30
- export const createDecorationSetFromTextPositions = textPositions => {
31
- const decorations = textPositions.map(textPosition => {
38
+ export const createDecorationSetFromLineAttributes = lineAttributes => {
39
+ const widgetDecorations = lineAttributes.map(lineAttribute => {
32
40
  const {
33
41
  lineStart,
34
- lineEnd
35
- } = textPosition;
36
- return Decoration.inline(lineStart, lineEnd, {
37
- class: codeBlockClassNames.lineNumberWrapped
38
- }, {
39
- type: DECORATION_INLINE_TYPE
42
+ lineNumber
43
+ } = lineAttribute;
44
+
45
+ // Passing a function to create the widget rather than directly passing a widget, as per ProseMirror docs.
46
+ const createLineNumberWidget = () => {
47
+ const widget = document.createElement('span');
48
+ widget.textContent = `${lineNumber}`;
49
+ widget.classList.add(codeBlockClassNames.lineNumberWidget);
50
+ return widget;
51
+ };
52
+
53
+ // side -1 is used so the line numbers are the first thing to the left of the lines of code.
54
+ return Decoration.widget(lineStart, createLineNumberWidget, {
55
+ type: DECORATION_WIDGET_TYPE,
56
+ side: -1
40
57
  });
41
58
  });
42
- return decorations;
59
+ return widgetDecorations;
43
60
  };
44
- export const createLineNumbersDecorations = (pos, node) => createDecorationSetFromTextPositions(generateTextPositionsFromNode(pos, node));
61
+ export const createLineNumbersDecorations = (pos, node) => createDecorationSetFromLineAttributes(generateLineAttributesFromNode(pos, node));
@@ -2,7 +2,6 @@ import { isEmptyNode } from '@atlaskit/editor-common/utils';
2
2
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
3
3
  import { Selection } from '@atlaskit/editor-prosemirror/state';
4
4
  import { findParentNodeOfTypeClosestToPos, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
5
  import { getCursor } from '../utils';
7
6
  const deleteCurrentItem = $from => tr => {
8
7
  return tr.delete($from.before($from.depth), $from.after($from.depth));
@@ -50,7 +49,6 @@ export function keymapPlugin(schema) {
50
49
  const {
51
50
  codeBlock,
52
51
  listItem,
53
- paragraph,
54
52
  table,
55
53
  layoutColumn
56
54
  } = state.schema.nodes;
@@ -62,11 +60,7 @@ export function keymapPlugin(schema) {
62
60
  if (!node) {
63
61
  return false;
64
62
  }
65
- if (getBooleanFF('platform.editor.codeblock-preserve-newlines_54r3m')) {
66
- replaceWithParagraph(node.node, node.pos, $cursor, state, dispatch);
67
- } else {
68
- dispatch(state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, []).setBlockType($cursor.pos, $cursor.pos, paragraph));
69
- }
63
+ replaceWithParagraph(node.node, node.pos, $cursor, state, dispatch);
70
64
  return true;
71
65
  }
72
66
  if ($cursor.node && isEmptyNode(schema)($cursor.node()) && (hasParentNodeOfType(layoutColumn)(state.selection) || hasParentNodeOfType(table)(state.selection))) {
@@ -11,7 +11,7 @@ import { pluginKey } from '../plugin-key';
11
11
  import { codeBlockClassNames } from '../ui/class-names';
12
12
  import { findCodeBlock } from '../utils';
13
13
  import { ACTIONS } from './actions';
14
- import { createLineNumbersDecorations } from './decorators';
14
+ import { createLineNumbersDecorations, DECORATION_WIDGET_TYPE } from './decorators';
15
15
  const DECORATION_WRAPPED_BLOCK_NODE_TYPE = 'decorationNodeType';
16
16
  export const createPlugin = ({
17
17
  useLongPressSelection = false,
@@ -20,6 +20,17 @@ export const createPlugin = ({
20
20
  api
21
21
  }) => {
22
22
  const handleDOMEvents = {};
23
+ const createLineNumberDecoratorsFromDecendants = editorState => {
24
+ let lineNumberDecorators = [];
25
+ editorState.doc.descendants((node, pos) => {
26
+ if (node.type === editorState.schema.nodes.codeBlock) {
27
+ lineNumberDecorators.push(...createLineNumbersDecorations(pos, node));
28
+ return false;
29
+ }
30
+ return true;
31
+ });
32
+ return lineNumberDecorators;
33
+ };
23
34
  const createWordWrappedDecoratorPluginState = (pluginState, tr, node) => {
24
35
  let decorationSetFromState = pluginState.decorations;
25
36
  if (node) {
@@ -36,7 +47,7 @@ export const createPlugin = ({
36
47
  decorationSetFromState = decorationSetFromState.remove(currentWrappedBlockDecorationSet);
37
48
  } else {
38
49
  const wrappedBlock = Decoration.node(pos, pos + innerNode.nodeSize, {
39
- class: codeBlockClassNames.wrapped
50
+ class: codeBlockClassNames.contentFgWrapped
40
51
  }, {
41
52
  type: DECORATION_WRAPPED_BLOCK_NODE_TYPE
42
53
  } // Allows for quick filtering of decorations while using `find`
@@ -47,21 +58,17 @@ export const createPlugin = ({
47
58
  }
48
59
  return decorationSetFromState;
49
60
  };
50
- const createLineDecoratorPluginState = (pluginState, tr, node) => {
61
+ const createLineDecoratorPluginState = (pluginState, tr, state) => {
51
62
  let decorationSetFromState = pluginState.decorations;
52
- if (node) {
53
- const {
54
- pos,
55
- node: innerNode
56
- } = node;
57
- if (pos !== undefined) {
58
- // Reset the decorations for the children of the code block node. Wipes all line number decorations.
59
- // @ts-ignore
60
- decorationSetFromState.children = [];
61
- const lineDecorators = createLineNumbersDecorations(pos, innerNode);
62
- decorationSetFromState = decorationSetFromState.add(tr.doc, [...lineDecorators]);
63
- }
64
- }
63
+ // remove all the line number children from the decorations set. 'undefined, undefined' is used to find() the whole doc.
64
+ const children = decorationSetFromState.find(undefined, undefined, spec => spec.type === DECORATION_WIDGET_TYPE);
65
+ decorationSetFromState = decorationSetFromState.remove(children);
66
+
67
+ // regenerate all the line number for the documents code blocks
68
+ const lineDecorators = createLineNumberDecoratorsFromDecendants(state);
69
+
70
+ // add the newly generated line numbers to the decorations set
71
+ decorationSetFromState = decorationSetFromState.add(tr.doc, [...lineDecorators]);
65
72
  return decorationSetFromState;
66
73
  };
67
74
 
@@ -105,12 +112,13 @@ export const createPlugin = ({
105
112
  state: {
106
113
  init(_, state) {
107
114
  const node = findCodeBlock(state, state.selection);
115
+ const lineNumberDecorators = fg('editor_support_code_block_wrapping') ? createLineNumberDecoratorsFromDecendants(state) : [];
108
116
  return {
109
117
  pos: node ? node.pos : null,
110
118
  contentCopied: false,
111
119
  isNodeSelected: false,
112
120
  shouldIgnoreFollowingMutations: false,
113
- decorations: DecorationSet.empty
121
+ decorations: DecorationSet.create(state.doc, lineNumberDecorators)
114
122
  };
115
123
  },
116
124
  apply(tr, pluginState, _oldState, newState) {
@@ -128,7 +136,7 @@ export const createPlugin = ({
128
136
  ...pluginState,
129
137
  pos: node ? node.pos : null,
130
138
  isNodeSelected: tr.selection instanceof NodeSelection,
131
- decorations: fg('editor_support_code_block_wrapping') ? createLineDecoratorPluginState(pluginState, tr, node) : DecorationSet.empty
139
+ decorations: fg('editor_support_code_block_wrapping') ? createLineDecoratorPluginState(pluginState, tr, newState) : DecorationSet.empty
132
140
  };
133
141
  return newPluginState;
134
142
  }
@@ -5,9 +5,11 @@ export const codeBlockClassNames = {
5
5
  end: CodeBlockSharedCssClassName.CODEBLOCK_END,
6
6
  contentWrapper: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER,
7
7
  gutter: CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER,
8
- gutterFgWrap: CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER_FG_WRAP,
9
8
  content: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT,
10
- contentWrapped: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPED,
11
- lineNumberWrapped: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER_LINE_NUMBER_WRAPPED,
12
- wrapped: CodeBlockSharedCssClassName.CODEBLOCK_WRAPPED
9
+ // Feature Gate editor_support_code_block_wrapping:
10
+ contentWrapperFg: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER_FG,
11
+ contentFg: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_FG,
12
+ contentFgWrapped: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_FG_WRAPPED,
13
+ lineNumberWidget: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER_LINE_NUMBER_WIDGET,
14
+ gutterFg: CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER_FG
13
15
  };
@@ -220,7 +220,8 @@ export var toggleWordWrapStateForCodeBlockNode = function toggleWordWrapStateFor
220
220
  attributes: {
221
221
  platform: PLATFORMS.WEB,
222
222
  mode: MODE.EDITOR,
223
- wordWrapEnabled: updatedToggleState
223
+ wordWrapEnabled: updatedToggleState,
224
+ codeBlockNodeSize: codeBlockNode.nodeSize
224
225
  },
225
226
  eventType: EVENT_TYPE.TRACK
226
227
  })(tr);
package/dist/esm/index.js CHANGED
@@ -1,2 +1 @@
1
- export { default as codeBlockPlugin } from './plugin';
2
- export { createDecorationSetFromTextPositions, generateTextPositionsFromNode } from './pm-plugins/decorators';
1
+ export { default as codeBlockPlugin } from './plugin';
@@ -17,12 +17,12 @@ var toDOM = function toDOM(node, contentEditable) {
17
17
  class: codeBlockClassNames.start,
18
18
  contenteditable: 'false'
19
19
  }], ['div', {
20
- class: codeBlockClassNames.contentWrapper
20
+ class: "".concat(codeBlockClassNames.contentWrapper, " ").concat(fg('editor_support_code_block_wrapping') && codeBlockClassNames.contentWrapperFg)
21
21
  }, ['div', {
22
- class: fg('editor_support_code_block_wrapping') ? codeBlockClassNames.gutterFgWrap : codeBlockClassNames.gutter,
22
+ class: fg('editor_support_code_block_wrapping') ? codeBlockClassNames.gutterFg : codeBlockClassNames.gutter,
23
23
  contenteditable: 'false'
24
24
  }], ['div', {
25
- class: codeBlockClassNames.content
25
+ class: fg('editor_support_code_block_wrapping') ? "".concat(codeBlockClassNames.contentFg) : codeBlockClassNames.content
26
26
  }, ['code', {
27
27
  'data-language': node.attrs.language || '',
28
28
  spellcheck: 'false',
@@ -62,7 +62,7 @@ export var CodeBlockView = /*#__PURE__*/function () {
62
62
  this.node = _node;
63
63
  this.dom = dom;
64
64
  this.contentDOM = contentDOM;
65
- this.lineNumberGutter = this.dom.querySelector(".".concat(fg('editor_support_code_block_wrapping') ? codeBlockClassNames.gutterFgWrap : codeBlockClassNames.gutter));
65
+ this.lineNumberGutter = this.dom.querySelector(".".concat(fg('editor_support_code_block_wrapping') ? codeBlockClassNames.gutterFg : codeBlockClassNames.gutter));
66
66
  this.api = api;
67
67
  if (!fg('editor_support_code_block_wrapping')) {
68
68
  this.ensureLineNumbers();
@@ -1,45 +1,62 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
3
  import { codeBlockClassNames } from '../ui/class-names';
4
- var DECORATION_INLINE_TYPE = 'decorationInlineType';
5
- export var generateTextPositionsFromNode = function generateTextPositionsFromNode(pos, node) {
4
+ export var DECORATION_WIDGET_TYPE = 'decorationWidgetType';
5
+ export var generateLineAttributesFromNode = function generateLineAttributesFromNode(pos, node) {
6
6
  // Get content node
7
7
  var contentNode = node.content;
8
8
 
9
9
  // Get node text content
10
- var textPositions = [];
10
+ var lineAttributes = [];
11
+
12
+ // Early exit if content size is 0
13
+ if (contentNode.size === 0) {
14
+ return [{
15
+ lineStart: pos + 1,
16
+ lineNumber: 1
17
+ }];
18
+ }
11
19
  contentNode.forEach(function (child) {
12
20
  var nodeTextContent = child.textContent;
13
21
  var nodeStartPos = pos;
14
22
  var lineStartIndex = nodeStartPos;
15
- var newLinePositions = nodeTextContent.split('\n').map(function (line) {
23
+ var newLineAttributes = nodeTextContent.split('\n').map(function (line, index) {
16
24
  var lineLength = line.length;
17
25
  var lineStart = lineStartIndex + 1;
18
- var lineEnd = lineStart + lineLength;
26
+ var lineNumber = index + 1;
19
27
 
20
28
  // Include the newline character and increment to keep tabs on line position
21
29
  lineStartIndex += lineLength + 1;
22
30
  return {
23
31
  lineStart: lineStart,
24
- lineEnd: lineEnd
32
+ lineNumber: lineNumber
25
33
  };
26
34
  });
27
- textPositions = [].concat(_toConsumableArray(textPositions), _toConsumableArray(newLinePositions));
35
+ lineAttributes = [].concat(_toConsumableArray(lineAttributes), _toConsumableArray(newLineAttributes));
28
36
  });
29
- return textPositions;
37
+ return lineAttributes;
30
38
  };
31
- export var createDecorationSetFromTextPositions = function createDecorationSetFromTextPositions(textPositions) {
32
- var decorations = textPositions.map(function (textPosition) {
33
- var lineStart = textPosition.lineStart,
34
- lineEnd = textPosition.lineEnd;
35
- return Decoration.inline(lineStart, lineEnd, {
36
- class: codeBlockClassNames.lineNumberWrapped
37
- }, {
38
- type: DECORATION_INLINE_TYPE
39
+ export var createDecorationSetFromLineAttributes = function createDecorationSetFromLineAttributes(lineAttributes) {
40
+ var widgetDecorations = lineAttributes.map(function (lineAttribute) {
41
+ var lineStart = lineAttribute.lineStart,
42
+ lineNumber = lineAttribute.lineNumber;
43
+
44
+ // Passing a function to create the widget rather than directly passing a widget, as per ProseMirror docs.
45
+ var createLineNumberWidget = function createLineNumberWidget() {
46
+ var widget = document.createElement('span');
47
+ widget.textContent = "".concat(lineNumber);
48
+ widget.classList.add(codeBlockClassNames.lineNumberWidget);
49
+ return widget;
50
+ };
51
+
52
+ // side -1 is used so the line numbers are the first thing to the left of the lines of code.
53
+ return Decoration.widget(lineStart, createLineNumberWidget, {
54
+ type: DECORATION_WIDGET_TYPE,
55
+ side: -1
39
56
  });
40
57
  });
41
- return decorations;
58
+ return widgetDecorations;
42
59
  };
43
60
  export var createLineNumbersDecorations = function createLineNumbersDecorations(pos, node) {
44
- return createDecorationSetFromTextPositions(generateTextPositionsFromNode(pos, node));
61
+ return createDecorationSetFromLineAttributes(generateLineAttributesFromNode(pos, node));
45
62
  };
@@ -2,7 +2,6 @@ import { isEmptyNode } from '@atlaskit/editor-common/utils';
2
2
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
3
3
  import { Selection } from '@atlaskit/editor-prosemirror/state';
4
4
  import { findParentNodeOfTypeClosestToPos, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
5
  import { getCursor } from '../utils';
7
6
  var deleteCurrentItem = function deleteCurrentItem($from) {
8
7
  return function (tr) {
@@ -51,7 +50,6 @@ export function keymapPlugin(schema) {
51
50
  var _state$schema$nodes2 = state.schema.nodes,
52
51
  codeBlock = _state$schema$nodes2.codeBlock,
53
52
  listItem = _state$schema$nodes2.listItem,
54
- paragraph = _state$schema$nodes2.paragraph,
55
53
  table = _state$schema$nodes2.table,
56
54
  layoutColumn = _state$schema$nodes2.layoutColumn;
57
55
  if (!$cursor || $cursor.parent.type !== codeBlock || !dispatch) {
@@ -62,11 +60,7 @@ export function keymapPlugin(schema) {
62
60
  if (!node) {
63
61
  return false;
64
62
  }
65
- if (getBooleanFF('platform.editor.codeblock-preserve-newlines_54r3m')) {
66
- replaceWithParagraph(node.node, node.pos, $cursor, state, dispatch);
67
- } else {
68
- dispatch(state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, []).setBlockType($cursor.pos, $cursor.pos, paragraph));
69
- }
63
+ replaceWithParagraph(node.node, node.pos, $cursor, state, dispatch);
70
64
  return true;
71
65
  }
72
66
  if ($cursor.node && isEmptyNode(schema)($cursor.node()) && (hasParentNodeOfType(layoutColumn)(state.selection) || hasParentNodeOfType(table)(state.selection))) {
@@ -15,7 +15,7 @@ import { pluginKey } from '../plugin-key';
15
15
  import { codeBlockClassNames } from '../ui/class-names';
16
16
  import { findCodeBlock } from '../utils';
17
17
  import { ACTIONS } from './actions';
18
- import { createLineNumbersDecorations } from './decorators';
18
+ import { createLineNumbersDecorations, DECORATION_WIDGET_TYPE } from './decorators';
19
19
  var DECORATION_WRAPPED_BLOCK_NODE_TYPE = 'decorationNodeType';
20
20
  export var createPlugin = function createPlugin(_ref) {
21
21
  var _ref$useLongPressSele = _ref.useLongPressSelection,
@@ -25,6 +25,17 @@ export var createPlugin = function createPlugin(_ref) {
25
25
  allowCompositionInputOverride = _ref$allowComposition === void 0 ? false : _ref$allowComposition,
26
26
  api = _ref.api;
27
27
  var handleDOMEvents = {};
28
+ var createLineNumberDecoratorsFromDecendants = function createLineNumberDecoratorsFromDecendants(editorState) {
29
+ var lineNumberDecorators = [];
30
+ editorState.doc.descendants(function (node, pos) {
31
+ if (node.type === editorState.schema.nodes.codeBlock) {
32
+ lineNumberDecorators.push.apply(lineNumberDecorators, _toConsumableArray(createLineNumbersDecorations(pos, node)));
33
+ return false;
34
+ }
35
+ return true;
36
+ });
37
+ return lineNumberDecorators;
38
+ };
28
39
  var createWordWrappedDecoratorPluginState = function createWordWrappedDecoratorPluginState(pluginState, tr, node) {
29
40
  var decorationSetFromState = pluginState.decorations;
30
41
  if (node) {
@@ -41,7 +52,7 @@ export var createPlugin = function createPlugin(_ref) {
41
52
  decorationSetFromState = decorationSetFromState.remove(currentWrappedBlockDecorationSet);
42
53
  } else {
43
54
  var wrappedBlock = Decoration.node(pos, pos + innerNode.nodeSize, {
44
- class: codeBlockClassNames.wrapped
55
+ class: codeBlockClassNames.contentFgWrapped
45
56
  }, {
46
57
  type: DECORATION_WRAPPED_BLOCK_NODE_TYPE
47
58
  } // Allows for quick filtering of decorations while using `find`
@@ -52,19 +63,19 @@ export var createPlugin = function createPlugin(_ref) {
52
63
  }
53
64
  return decorationSetFromState;
54
65
  };
55
- var createLineDecoratorPluginState = function createLineDecoratorPluginState(pluginState, tr, node) {
66
+ var createLineDecoratorPluginState = function createLineDecoratorPluginState(pluginState, tr, state) {
56
67
  var decorationSetFromState = pluginState.decorations;
57
- if (node) {
58
- var pos = node.pos,
59
- innerNode = node.node;
60
- if (pos !== undefined) {
61
- // Reset the decorations for the children of the code block node. Wipes all line number decorations.
62
- // @ts-ignore
63
- decorationSetFromState.children = [];
64
- var lineDecorators = createLineNumbersDecorations(pos, innerNode);
65
- decorationSetFromState = decorationSetFromState.add(tr.doc, _toConsumableArray(lineDecorators));
66
- }
67
- }
68
+ // remove all the line number children from the decorations set. 'undefined, undefined' is used to find() the whole doc.
69
+ var children = decorationSetFromState.find(undefined, undefined, function (spec) {
70
+ return spec.type === DECORATION_WIDGET_TYPE;
71
+ });
72
+ decorationSetFromState = decorationSetFromState.remove(children);
73
+
74
+ // regenerate all the line number for the documents code blocks
75
+ var lineDecorators = createLineNumberDecoratorsFromDecendants(state);
76
+
77
+ // add the newly generated line numbers to the decorations set
78
+ decorationSetFromState = decorationSetFromState.add(tr.doc, _toConsumableArray(lineDecorators));
68
79
  return decorationSetFromState;
69
80
  };
70
81
 
@@ -110,12 +121,13 @@ export var createPlugin = function createPlugin(_ref) {
110
121
  state: {
111
122
  init: function init(_, state) {
112
123
  var node = findCodeBlock(state, state.selection);
124
+ var lineNumberDecorators = fg('editor_support_code_block_wrapping') ? createLineNumberDecoratorsFromDecendants(state) : [];
113
125
  return {
114
126
  pos: node ? node.pos : null,
115
127
  contentCopied: false,
116
128
  isNodeSelected: false,
117
129
  shouldIgnoreFollowingMutations: false,
118
- decorations: DecorationSet.empty
130
+ decorations: DecorationSet.create(state.doc, lineNumberDecorators)
119
131
  };
120
132
  },
121
133
  apply: function apply(tr, pluginState, _oldState, newState) {
@@ -131,7 +143,7 @@ export var createPlugin = function createPlugin(_ref) {
131
143
  var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
132
144
  pos: _node ? _node.pos : null,
133
145
  isNodeSelected: tr.selection instanceof NodeSelection,
134
- decorations: fg('editor_support_code_block_wrapping') ? createLineDecoratorPluginState(pluginState, tr, _node) : DecorationSet.empty
146
+ decorations: fg('editor_support_code_block_wrapping') ? createLineDecoratorPluginState(pluginState, tr, newState) : DecorationSet.empty
135
147
  });
136
148
  return newPluginState;
137
149
  }
@@ -5,9 +5,11 @@ export var codeBlockClassNames = {
5
5
  end: CodeBlockSharedCssClassName.CODEBLOCK_END,
6
6
  contentWrapper: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER,
7
7
  gutter: CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER,
8
- gutterFgWrap: CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER_FG_WRAP,
9
8
  content: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT,
10
- contentWrapped: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPED,
11
- lineNumberWrapped: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER_LINE_NUMBER_WRAPPED,
12
- wrapped: CodeBlockSharedCssClassName.CODEBLOCK_WRAPPED
9
+ // Feature Gate editor_support_code_block_wrapping:
10
+ contentWrapperFg: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER_FG,
11
+ contentFg: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_FG,
12
+ contentFgWrapped: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_FG_WRAPPED,
13
+ lineNumberWidget: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER_LINE_NUMBER_WIDGET,
14
+ gutterFg: CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER_FG
13
15
  };
@@ -1,4 +1,3 @@
1
1
  export { default as codeBlockPlugin } from './plugin';
2
2
  export type { CodeBlockPlugin } from './plugin';
3
3
  export type { CodeBlockOptions } from './types';
4
- export { createDecorationSetFromTextPositions, generateTextPositionsFromNode, } from './pm-plugins/decorators';
@@ -1,6 +1,7 @@
1
1
  import type { Node } from '@atlaskit/editor-prosemirror/model';
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
- import type { CodeBlockTextPosition } from '../types';
4
- export declare const generateTextPositionsFromNode: (pos: number, node: Node) => CodeBlockTextPosition[];
5
- export declare const createDecorationSetFromTextPositions: (textPositions: CodeBlockTextPosition[]) => Decoration[];
3
+ import type { CodeBlockLineAttributes } from '../types';
4
+ export declare const DECORATION_WIDGET_TYPE = "decorationWidgetType";
5
+ export declare const generateLineAttributesFromNode: (pos: number, node: Node) => CodeBlockLineAttributes[];
6
+ export declare const createDecorationSetFromLineAttributes: (lineAttributes: CodeBlockLineAttributes[]) => Decoration[];
6
7
  export declare const createLineNumbersDecorations: (pos: number, node: Node) => Decoration[];
@@ -3,7 +3,7 @@ export interface CodeBlockOptions extends LongPressSelectionPluginOptions {
3
3
  allowCopyToClipboard?: boolean;
4
4
  allowCompositionInputOverride?: boolean;
5
5
  }
6
- export type CodeBlockTextPosition = {
6
+ export type CodeBlockLineAttributes = {
7
7
  lineStart: number;
8
- lineEnd: number;
8
+ lineNumber: number;
9
9
  };
@@ -4,9 +4,10 @@ export declare const codeBlockClassNames: {
4
4
  end: string;
5
5
  contentWrapper: string;
6
6
  gutter: string;
7
- gutterFgWrap: string;
8
7
  content: string;
9
- contentWrapped: string;
10
- lineNumberWrapped: string;
11
- wrapped: string;
8
+ contentWrapperFg: string;
9
+ contentFg: string;
10
+ contentFgWrapped: string;
11
+ lineNumberWidget: string;
12
+ gutterFg: string;
12
13
  };
@@ -1,4 +1,3 @@
1
1
  export { default as codeBlockPlugin } from './plugin';
2
2
  export type { CodeBlockPlugin } from './plugin';
3
3
  export type { CodeBlockOptions } from './types';
4
- export { createDecorationSetFromTextPositions, generateTextPositionsFromNode, } from './pm-plugins/decorators';
@@ -1,6 +1,7 @@
1
1
  import type { Node } from '@atlaskit/editor-prosemirror/model';
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
- import type { CodeBlockTextPosition } from '../types';
4
- export declare const generateTextPositionsFromNode: (pos: number, node: Node) => CodeBlockTextPosition[];
5
- export declare const createDecorationSetFromTextPositions: (textPositions: CodeBlockTextPosition[]) => Decoration[];
3
+ import type { CodeBlockLineAttributes } from '../types';
4
+ export declare const DECORATION_WIDGET_TYPE = "decorationWidgetType";
5
+ export declare const generateLineAttributesFromNode: (pos: number, node: Node) => CodeBlockLineAttributes[];
6
+ export declare const createDecorationSetFromLineAttributes: (lineAttributes: CodeBlockLineAttributes[]) => Decoration[];
6
7
  export declare const createLineNumbersDecorations: (pos: number, node: Node) => Decoration[];
@@ -3,7 +3,7 @@ export interface CodeBlockOptions extends LongPressSelectionPluginOptions {
3
3
  allowCopyToClipboard?: boolean;
4
4
  allowCompositionInputOverride?: boolean;
5
5
  }
6
- export type CodeBlockTextPosition = {
6
+ export type CodeBlockLineAttributes = {
7
7
  lineStart: number;
8
- lineEnd: number;
8
+ lineNumber: number;
9
9
  };
@@ -4,9 +4,10 @@ export declare const codeBlockClassNames: {
4
4
  end: string;
5
5
  contentWrapper: string;
6
6
  gutter: string;
7
- gutterFgWrap: string;
8
7
  content: string;
9
- contentWrapped: string;
10
- lineNumberWrapped: string;
11
- wrapped: string;
8
+ contentWrapperFg: string;
9
+ contentFg: string;
10
+ contentFgWrapped: string;
11
+ lineNumberWidget: string;
12
+ gutterFg: string;
12
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block",
3
- "version": "3.3.1",
3
+ "version": "3.3.3",
4
4
  "description": "Code block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,14 +34,14 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@atlaskit/adf-schema": "^40.8.1",
37
- "@atlaskit/code": "^15.4.0",
38
- "@atlaskit/editor-common": "^87.6.0",
37
+ "@atlaskit/code": "^15.5.0",
38
+ "@atlaskit/editor-common": "^87.10.0",
39
39
  "@atlaskit/editor-plugin-analytics": "^1.7.0",
40
40
  "@atlaskit/editor-plugin-composition": "^1.2.0",
41
41
  "@atlaskit/editor-plugin-decorations": "^1.2.0",
42
42
  "@atlaskit/editor-plugin-editor-disabled": "^1.2.0",
43
43
  "@atlaskit/editor-prosemirror": "5.0.1",
44
- "@atlaskit/icon": "^22.11.0",
44
+ "@atlaskit/icon": "^22.13.0",
45
45
  "@atlaskit/platform-feature-flags": "^0.3.0",
46
46
  "@atlaskit/prosemirror-input-rules": "^3.2.0",
47
47
  "@babel/runtime": "^7.0.0",
@@ -98,9 +98,6 @@
98
98
  },
99
99
  "platform.editor.live-view.disable-editing-in-view-mode_fi1rx": {
100
100
  "type": "boolean"
101
- },
102
- "platform.editor.codeblock-preserve-newlines_54r3m": {
103
- "type": "boolean"
104
101
  }
105
102
  }
106
103
  }