@atlaskit/editor-plugin-code-block 3.3.1 → 3.3.2
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 +14 -0
- package/dist/cjs/actions.js +2 -1
- package/dist/cjs/index.js +1 -14
- package/dist/cjs/nodeviews/code-block.js +4 -4
- package/dist/cjs/pm-plugins/decorators.js +28 -19
- package/dist/cjs/pm-plugins/keymaps.js +1 -7
- package/dist/cjs/pm-plugins/main.js +1 -1
- package/dist/cjs/ui/class-names.js +6 -4
- package/dist/es2019/actions.js +2 -1
- package/dist/es2019/index.js +1 -2
- package/dist/es2019/nodeviews/code-block.js +4 -4
- package/dist/es2019/pm-plugins/decorators.js +27 -18
- package/dist/es2019/pm-plugins/keymaps.js +1 -7
- package/dist/es2019/pm-plugins/main.js +1 -1
- package/dist/es2019/ui/class-names.js +6 -4
- package/dist/esm/actions.js +2 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/nodeviews/code-block.js +4 -4
- package/dist/esm/pm-plugins/decorators.js +27 -18
- package/dist/esm/pm-plugins/keymaps.js +1 -7
- package/dist/esm/pm-plugins/main.js +1 -1
- package/dist/esm/ui/class-names.js +6 -4
- package/dist/types/index.d.ts +0 -1
- package/dist/types/pm-plugins/decorators.d.ts +3 -3
- package/dist/types/types.d.ts +2 -2
- package/dist/types/ui/class-names.d.ts +5 -4
- package/dist/types-ts4.5/index.d.ts +0 -1
- package/dist/types-ts4.5/pm-plugins/decorators.d.ts +3 -3
- package/dist/types-ts4.5/types.d.ts +2 -2
- package/dist/types-ts4.5/ui/class-names.d.ts +5 -4
- package/package.json +4 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block
|
|
2
2
|
|
|
3
|
+
## 3.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#128111](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/128111)
|
|
8
|
+
[`9863ffeb3e73e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9863ffeb3e73e) -
|
|
9
|
+
remove codeblock preserve newlines ff
|
|
10
|
+
- [#129049](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/129049)
|
|
11
|
+
[`6b1533d389c9d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6b1533d389c9d) -
|
|
12
|
+
[ux] ED-24511 - Convert code block line numbers inline decorations to widget decorations. The line
|
|
13
|
+
number gutter on editor code blocks should now reflect the number of lines of code, including when
|
|
14
|
+
the code block has word wrap enabled. Minor for editor-common as new analytics attribute added.
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 3.3.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/cjs/actions.js
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
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.
|
|
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,58 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.generateLineAttributesFromNode = exports.createLineNumbersDecorations = exports.createDecorationSetFromLineAttributes = 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
|
|
12
|
-
var
|
|
11
|
+
var 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
|
|
17
|
+
var lineAttributes = [];
|
|
18
18
|
contentNode.forEach(function (child) {
|
|
19
19
|
var nodeTextContent = child.textContent;
|
|
20
20
|
var nodeStartPos = pos;
|
|
21
21
|
var lineStartIndex = nodeStartPos;
|
|
22
|
-
var
|
|
22
|
+
var newLineAttributes = nodeTextContent.split('\n').map(function (line, index) {
|
|
23
23
|
var lineLength = line.length;
|
|
24
24
|
var lineStart = lineStartIndex + 1;
|
|
25
|
-
var
|
|
25
|
+
var lineNumber = index + 1;
|
|
26
26
|
|
|
27
27
|
// Include the newline character and increment to keep tabs on line position
|
|
28
28
|
lineStartIndex += lineLength + 1;
|
|
29
29
|
return {
|
|
30
30
|
lineStart: lineStart,
|
|
31
|
-
|
|
31
|
+
lineNumber: lineNumber
|
|
32
32
|
};
|
|
33
33
|
});
|
|
34
|
-
|
|
34
|
+
lineAttributes = [].concat((0, _toConsumableArray2.default)(lineAttributes), (0, _toConsumableArray2.default)(newLineAttributes));
|
|
35
35
|
});
|
|
36
|
-
return
|
|
36
|
+
return lineAttributes;
|
|
37
37
|
};
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var lineStart =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
var createDecorationSetFromLineAttributes = exports.createDecorationSetFromLineAttributes = function createDecorationSetFromLineAttributes(lineAttributes) {
|
|
39
|
+
var widgetDecorations = lineAttributes.map(function (lineAttribute) {
|
|
40
|
+
var lineStart = lineAttribute.lineStart,
|
|
41
|
+
lineNumber = lineAttribute.lineNumber;
|
|
42
|
+
|
|
43
|
+
// Passing a function to create the widget rather than directly passing a widget, as per ProseMirror docs.
|
|
44
|
+
var createLineNumberWidget = function createLineNumberWidget() {
|
|
45
|
+
var widget = document.createElement('span');
|
|
46
|
+
widget.textContent = "".concat(lineNumber);
|
|
47
|
+
widget.classList.add(_classNames.codeBlockClassNames.lineNumberWidget);
|
|
48
|
+
return widget;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// side -1 is used so the line numbers are the first thing to the left of the lines of code.
|
|
52
|
+
return _view.Decoration.widget(lineStart, createLineNumberWidget, {
|
|
53
|
+
type: DECORATION_WIDGET_TYPE,
|
|
54
|
+
side: -1
|
|
46
55
|
});
|
|
47
56
|
});
|
|
48
|
-
return
|
|
57
|
+
return widgetDecorations;
|
|
49
58
|
};
|
|
50
59
|
var createLineNumbersDecorations = exports.createLineNumbersDecorations = function createLineNumbersDecorations(pos, node) {
|
|
51
|
-
return
|
|
60
|
+
return createDecorationSetFromLineAttributes(generateLineAttributesFromNode(pos, node));
|
|
52
61
|
};
|
|
@@ -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
|
-
|
|
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))) {
|
|
@@ -48,7 +48,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
48
48
|
decorationSetFromState = decorationSetFromState.remove(currentWrappedBlockDecorationSet);
|
|
49
49
|
} else {
|
|
50
50
|
var wrappedBlock = _view.Decoration.node(pos, pos + innerNode.nodeSize, {
|
|
51
|
-
class: _classNames.codeBlockClassNames.
|
|
51
|
+
class: _classNames.codeBlockClassNames.contentFgWrapped
|
|
52
52
|
}, {
|
|
53
53
|
type: DECORATION_WRAPPED_BLOCK_NODE_TYPE
|
|
54
54
|
} // Allows for quick filtering of decorations while using `find`
|
|
@@ -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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
};
|
package/dist/es2019/actions.js
CHANGED
|
@@ -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);
|
package/dist/es2019/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';
|
|
@@ -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.
|
|
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.
|
|
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,53 @@
|
|
|
1
1
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
2
2
|
import { codeBlockClassNames } from '../ui/class-names';
|
|
3
|
-
const
|
|
4
|
-
export const
|
|
3
|
+
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
|
|
9
|
+
let lineAttributes = [];
|
|
10
10
|
contentNode.forEach(child => {
|
|
11
11
|
const nodeTextContent = child.textContent;
|
|
12
12
|
const nodeStartPos = pos;
|
|
13
13
|
let lineStartIndex = nodeStartPos;
|
|
14
|
-
const
|
|
14
|
+
const newLineAttributes = nodeTextContent.split('\n').map((line, index) => {
|
|
15
15
|
const lineLength = line.length;
|
|
16
16
|
const lineStart = lineStartIndex + 1;
|
|
17
|
-
const
|
|
17
|
+
const lineNumber = index + 1;
|
|
18
18
|
|
|
19
19
|
// Include the newline character and increment to keep tabs on line position
|
|
20
20
|
lineStartIndex += lineLength + 1;
|
|
21
21
|
return {
|
|
22
22
|
lineStart,
|
|
23
|
-
|
|
23
|
+
lineNumber
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
|
-
|
|
26
|
+
lineAttributes = [...lineAttributes, ...newLineAttributes];
|
|
27
27
|
});
|
|
28
|
-
return
|
|
28
|
+
return lineAttributes;
|
|
29
29
|
};
|
|
30
|
-
export const
|
|
31
|
-
const
|
|
30
|
+
export const createDecorationSetFromLineAttributes = lineAttributes => {
|
|
31
|
+
const widgetDecorations = lineAttributes.map(lineAttribute => {
|
|
32
32
|
const {
|
|
33
33
|
lineStart,
|
|
34
|
-
|
|
35
|
-
} =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
lineNumber
|
|
35
|
+
} = lineAttribute;
|
|
36
|
+
|
|
37
|
+
// Passing a function to create the widget rather than directly passing a widget, as per ProseMirror docs.
|
|
38
|
+
const createLineNumberWidget = () => {
|
|
39
|
+
const widget = document.createElement('span');
|
|
40
|
+
widget.textContent = `${lineNumber}`;
|
|
41
|
+
widget.classList.add(codeBlockClassNames.lineNumberWidget);
|
|
42
|
+
return widget;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// side -1 is used so the line numbers are the first thing to the left of the lines of code.
|
|
46
|
+
return Decoration.widget(lineStart, createLineNumberWidget, {
|
|
47
|
+
type: DECORATION_WIDGET_TYPE,
|
|
48
|
+
side: -1
|
|
40
49
|
});
|
|
41
50
|
});
|
|
42
|
-
return
|
|
51
|
+
return widgetDecorations;
|
|
43
52
|
};
|
|
44
|
-
export const createLineNumbersDecorations = (pos, node) =>
|
|
53
|
+
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
|
-
|
|
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))) {
|
|
@@ -36,7 +36,7 @@ export const createPlugin = ({
|
|
|
36
36
|
decorationSetFromState = decorationSetFromState.remove(currentWrappedBlockDecorationSet);
|
|
37
37
|
} else {
|
|
38
38
|
const wrappedBlock = Decoration.node(pos, pos + innerNode.nodeSize, {
|
|
39
|
-
class: codeBlockClassNames.
|
|
39
|
+
class: codeBlockClassNames.contentFgWrapped
|
|
40
40
|
}, {
|
|
41
41
|
type: DECORATION_WRAPPED_BLOCK_NODE_TYPE
|
|
42
42
|
} // Allows for quick filtering of decorations while using `find`
|
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
};
|
package/dist/esm/actions.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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,54 @@
|
|
|
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
|
|
5
|
-
export var
|
|
4
|
+
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
|
|
10
|
+
var lineAttributes = [];
|
|
11
11
|
contentNode.forEach(function (child) {
|
|
12
12
|
var nodeTextContent = child.textContent;
|
|
13
13
|
var nodeStartPos = pos;
|
|
14
14
|
var lineStartIndex = nodeStartPos;
|
|
15
|
-
var
|
|
15
|
+
var newLineAttributes = nodeTextContent.split('\n').map(function (line, index) {
|
|
16
16
|
var lineLength = line.length;
|
|
17
17
|
var lineStart = lineStartIndex + 1;
|
|
18
|
-
var
|
|
18
|
+
var lineNumber = index + 1;
|
|
19
19
|
|
|
20
20
|
// Include the newline character and increment to keep tabs on line position
|
|
21
21
|
lineStartIndex += lineLength + 1;
|
|
22
22
|
return {
|
|
23
23
|
lineStart: lineStart,
|
|
24
|
-
|
|
24
|
+
lineNumber: lineNumber
|
|
25
25
|
};
|
|
26
26
|
});
|
|
27
|
-
|
|
27
|
+
lineAttributes = [].concat(_toConsumableArray(lineAttributes), _toConsumableArray(newLineAttributes));
|
|
28
28
|
});
|
|
29
|
-
return
|
|
29
|
+
return lineAttributes;
|
|
30
30
|
};
|
|
31
|
-
export var
|
|
32
|
-
var
|
|
33
|
-
var lineStart =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
export var createDecorationSetFromLineAttributes = function createDecorationSetFromLineAttributes(lineAttributes) {
|
|
32
|
+
var widgetDecorations = lineAttributes.map(function (lineAttribute) {
|
|
33
|
+
var lineStart = lineAttribute.lineStart,
|
|
34
|
+
lineNumber = lineAttribute.lineNumber;
|
|
35
|
+
|
|
36
|
+
// Passing a function to create the widget rather than directly passing a widget, as per ProseMirror docs.
|
|
37
|
+
var createLineNumberWidget = function createLineNumberWidget() {
|
|
38
|
+
var widget = document.createElement('span');
|
|
39
|
+
widget.textContent = "".concat(lineNumber);
|
|
40
|
+
widget.classList.add(codeBlockClassNames.lineNumberWidget);
|
|
41
|
+
return widget;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// side -1 is used so the line numbers are the first thing to the left of the lines of code.
|
|
45
|
+
return Decoration.widget(lineStart, createLineNumberWidget, {
|
|
46
|
+
type: DECORATION_WIDGET_TYPE,
|
|
47
|
+
side: -1
|
|
39
48
|
});
|
|
40
49
|
});
|
|
41
|
-
return
|
|
50
|
+
return widgetDecorations;
|
|
42
51
|
};
|
|
43
52
|
export var createLineNumbersDecorations = function createLineNumbersDecorations(pos, node) {
|
|
44
|
-
return
|
|
53
|
+
return createDecorationSetFromLineAttributes(generateLineAttributesFromNode(pos, node));
|
|
45
54
|
};
|
|
@@ -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
|
-
|
|
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))) {
|
|
@@ -41,7 +41,7 @@ export var createPlugin = function createPlugin(_ref) {
|
|
|
41
41
|
decorationSetFromState = decorationSetFromState.remove(currentWrappedBlockDecorationSet);
|
|
42
42
|
} else {
|
|
43
43
|
var wrappedBlock = Decoration.node(pos, pos + innerNode.nodeSize, {
|
|
44
|
-
class: codeBlockClassNames.
|
|
44
|
+
class: codeBlockClassNames.contentFgWrapped
|
|
45
45
|
}, {
|
|
46
46
|
type: DECORATION_WRAPPED_BLOCK_NODE_TYPE
|
|
47
47
|
} // Allows for quick filtering of decorations while using `find`
|
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Node } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
-
import type {
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
3
|
+
import type { CodeBlockLineAttributes } from '../types';
|
|
4
|
+
export declare const generateLineAttributesFromNode: (pos: number, node: Node) => CodeBlockLineAttributes[];
|
|
5
|
+
export declare const createDecorationSetFromLineAttributes: (lineAttributes: CodeBlockLineAttributes[]) => Decoration[];
|
|
6
6
|
export declare const createLineNumbersDecorations: (pos: number, node: Node) => Decoration[];
|
package/dist/types/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export interface CodeBlockOptions extends LongPressSelectionPluginOptions {
|
|
|
3
3
|
allowCopyToClipboard?: boolean;
|
|
4
4
|
allowCompositionInputOverride?: boolean;
|
|
5
5
|
}
|
|
6
|
-
export type
|
|
6
|
+
export type CodeBlockLineAttributes = {
|
|
7
7
|
lineStart: number;
|
|
8
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
contentWrapperFg: string;
|
|
9
|
+
contentFg: string;
|
|
10
|
+
contentFgWrapped: string;
|
|
11
|
+
lineNumberWidget: string;
|
|
12
|
+
gutterFg: string;
|
|
12
13
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Node } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
-
import type {
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
3
|
+
import type { CodeBlockLineAttributes } from '../types';
|
|
4
|
+
export declare const generateLineAttributesFromNode: (pos: number, node: Node) => CodeBlockLineAttributes[];
|
|
5
|
+
export declare const createDecorationSetFromLineAttributes: (lineAttributes: CodeBlockLineAttributes[]) => Decoration[];
|
|
6
6
|
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
|
|
6
|
+
export type CodeBlockLineAttributes = {
|
|
7
7
|
lineStart: number;
|
|
8
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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.
|
|
3
|
+
"version": "3.3.2",
|
|
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.
|
|
38
|
-
"@atlaskit/editor-common": "^87.
|
|
37
|
+
"@atlaskit/code": "^15.5.0",
|
|
38
|
+
"@atlaskit/editor-common": "^87.8.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.
|
|
44
|
+
"@atlaskit/icon": "^22.12.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
|
}
|