@atlaskit/editor-plugin-code-block 3.3.3 → 3.3.4
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 +10 -0
- package/dist/cjs/nodeviews/code-block.js +20 -2
- package/dist/cjs/pm-plugins/main.js +1 -1
- package/dist/es2019/nodeviews/code-block.js +20 -2
- package/dist/es2019/pm-plugins/main.js +1 -1
- package/dist/esm/nodeviews/code-block.js +20 -2
- package/dist/esm/pm-plugins/main.js +1 -1
- package/dist/types/nodeviews/code-block.d.ts +4 -0
- package/dist/types-ts4.5/nodeviews/code-block.d.ts +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block
|
|
2
2
|
|
|
3
|
+
## 3.3.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#128388](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/128388)
|
|
8
|
+
[`0ea0f81d30dcc`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0ea0f81d30dcc) -
|
|
9
|
+
ED-24501 Add a CSS var to maintain a dynamic line number gutter size on the code block based on
|
|
10
|
+
the max number length. ED-24573 update handleClickOn in the code block plugin to work with new
|
|
11
|
+
line number gutter.
|
|
12
|
+
|
|
3
13
|
## 3.3.3
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -60,6 +60,20 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
|
60
60
|
_this.lineNumberGutter.removeChild(_this.lineNumberGutter.lastChild);
|
|
61
61
|
}
|
|
62
62
|
}));
|
|
63
|
+
/**
|
|
64
|
+
* As the code block updates we get the maximum amount of digits in a line number and expand the number gutter to reflect this.
|
|
65
|
+
*/
|
|
66
|
+
(0, _defineProperty2.default)(this, "maintainDynamicGutterSize", function () {
|
|
67
|
+
var totalLineCount = 1;
|
|
68
|
+
_this.node.forEach(function (node) {
|
|
69
|
+
var text = node.text;
|
|
70
|
+
if (text) {
|
|
71
|
+
totalLineCount += (node.text.match(MATCH_NEWLINES) || []).length;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
var maxDigits = totalLineCount.toString().length;
|
|
75
|
+
_this.dom.style.setProperty('--lineNumberGutterWidth', "".concat(maxDigits, "ch"));
|
|
76
|
+
});
|
|
63
77
|
this.cleanupEditorDisabledListener = cleanupEditorDisabledListener;
|
|
64
78
|
var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, toDOM(_node, !(api !== null && api !== void 0 && (_api$editorDisabled = api.editorDisabled) !== null && _api$editorDisabled !== void 0 && (_api$editorDisabled = _api$editorDisabled.sharedState.currentState()) !== null && _api$editorDisabled !== void 0 && _api$editorDisabled.editorDisabled))),
|
|
65
79
|
dom = _DOMSerializer$render.dom,
|
|
@@ -71,7 +85,9 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
|
71
85
|
this.contentDOM = contentDOM;
|
|
72
86
|
this.lineNumberGutter = this.dom.querySelector(".".concat((0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? _classNames.codeBlockClassNames.gutterFg : _classNames.codeBlockClassNames.gutter));
|
|
73
87
|
this.api = api;
|
|
74
|
-
if (
|
|
88
|
+
if ((0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping')) {
|
|
89
|
+
this.maintainDynamicGutterSize();
|
|
90
|
+
} else {
|
|
75
91
|
this.ensureLineNumbers();
|
|
76
92
|
}
|
|
77
93
|
this.handleEditorDisabledChanged();
|
|
@@ -149,7 +165,9 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
|
149
165
|
this.contentDOM.setAttribute('data-language', node.attrs.language || '');
|
|
150
166
|
}
|
|
151
167
|
this.node = node;
|
|
152
|
-
if (
|
|
168
|
+
if ((0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping')) {
|
|
169
|
+
this.maintainDynamicGutterSize();
|
|
170
|
+
} else {
|
|
153
171
|
this.ensureLineNumbers();
|
|
154
172
|
}
|
|
155
173
|
if (_utils.browser.android) {
|
|
@@ -188,7 +188,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
188
188
|
}
|
|
189
189
|
},
|
|
190
190
|
handleClickOn: (0, _selection.createSelectionClickHandler)(['codeBlock'], function (target) {
|
|
191
|
-
return !!(target.closest(".".concat(_classNames.codeBlockClassNames.gutter)) || target.classList.contains(_classNames.codeBlockClassNames.content));
|
|
191
|
+
return (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? !!(target.classList.contains(_classNames.codeBlockClassNames.lineNumberWidget) || target.classList.contains(_classNames.codeBlockClassNames.gutterFg)) : !!(target.closest(".".concat(_classNames.codeBlockClassNames.gutter)) || target.classList.contains(_classNames.codeBlockClassNames.content));
|
|
192
192
|
}, {
|
|
193
193
|
useLongPressSelection: useLongPressSelection
|
|
194
194
|
}),
|
|
@@ -47,6 +47,20 @@ export class CodeBlockView {
|
|
|
47
47
|
this.lineNumberGutter.removeChild(this.lineNumberGutter.lastChild);
|
|
48
48
|
}
|
|
49
49
|
}));
|
|
50
|
+
/**
|
|
51
|
+
* As the code block updates we get the maximum amount of digits in a line number and expand the number gutter to reflect this.
|
|
52
|
+
*/
|
|
53
|
+
_defineProperty(this, "maintainDynamicGutterSize", () => {
|
|
54
|
+
let totalLineCount = 1;
|
|
55
|
+
this.node.forEach(node => {
|
|
56
|
+
const text = node.text;
|
|
57
|
+
if (text) {
|
|
58
|
+
totalLineCount += (node.text.match(MATCH_NEWLINES) || []).length;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const maxDigits = totalLineCount.toString().length;
|
|
62
|
+
this.dom.style.setProperty('--lineNumberGutterWidth', `${maxDigits}ch`);
|
|
63
|
+
});
|
|
50
64
|
this.cleanupEditorDisabledListener = cleanupEditorDisabledListener;
|
|
51
65
|
const {
|
|
52
66
|
dom,
|
|
@@ -59,7 +73,9 @@ export class CodeBlockView {
|
|
|
59
73
|
this.contentDOM = contentDOM;
|
|
60
74
|
this.lineNumberGutter = this.dom.querySelector(`.${fg('editor_support_code_block_wrapping') ? codeBlockClassNames.gutterFg : codeBlockClassNames.gutter}`);
|
|
61
75
|
this.api = api;
|
|
62
|
-
if (
|
|
76
|
+
if (fg('editor_support_code_block_wrapping')) {
|
|
77
|
+
this.maintainDynamicGutterSize();
|
|
78
|
+
} else {
|
|
63
79
|
this.ensureLineNumbers();
|
|
64
80
|
}
|
|
65
81
|
this.handleEditorDisabledChanged();
|
|
@@ -126,7 +142,9 @@ export class CodeBlockView {
|
|
|
126
142
|
this.contentDOM.setAttribute('data-language', node.attrs.language || '');
|
|
127
143
|
}
|
|
128
144
|
this.node = node;
|
|
129
|
-
if (
|
|
145
|
+
if (fg('editor_support_code_block_wrapping')) {
|
|
146
|
+
this.maintainDynamicGutterSize();
|
|
147
|
+
} else {
|
|
130
148
|
this.ensureLineNumbers();
|
|
131
149
|
}
|
|
132
150
|
if (browser.android) {
|
|
@@ -174,7 +174,7 @@ export const createPlugin = ({
|
|
|
174
174
|
nodeViews: {
|
|
175
175
|
codeBlock: (node, view, getPos) => codeBlockNodeView(node, view, getPos, api)
|
|
176
176
|
},
|
|
177
|
-
handleClickOn: createSelectionClickHandler(['codeBlock'], target => !!(target.closest(`.${codeBlockClassNames.gutter}`) || target.classList.contains(codeBlockClassNames.content)), {
|
|
177
|
+
handleClickOn: createSelectionClickHandler(['codeBlock'], target => fg('editor_support_code_block_wrapping') ? !!(target.classList.contains(codeBlockClassNames.lineNumberWidget) || target.classList.contains(codeBlockClassNames.gutterFg)) : !!(target.closest(`.${codeBlockClassNames.gutter}`) || target.classList.contains(codeBlockClassNames.content)), {
|
|
178
178
|
useLongPressSelection
|
|
179
179
|
}),
|
|
180
180
|
handleDOMEvents
|
|
@@ -53,6 +53,20 @@ export var CodeBlockView = /*#__PURE__*/function () {
|
|
|
53
53
|
_this.lineNumberGutter.removeChild(_this.lineNumberGutter.lastChild);
|
|
54
54
|
}
|
|
55
55
|
}));
|
|
56
|
+
/**
|
|
57
|
+
* As the code block updates we get the maximum amount of digits in a line number and expand the number gutter to reflect this.
|
|
58
|
+
*/
|
|
59
|
+
_defineProperty(this, "maintainDynamicGutterSize", function () {
|
|
60
|
+
var totalLineCount = 1;
|
|
61
|
+
_this.node.forEach(function (node) {
|
|
62
|
+
var text = node.text;
|
|
63
|
+
if (text) {
|
|
64
|
+
totalLineCount += (node.text.match(MATCH_NEWLINES) || []).length;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
var maxDigits = totalLineCount.toString().length;
|
|
68
|
+
_this.dom.style.setProperty('--lineNumberGutterWidth', "".concat(maxDigits, "ch"));
|
|
69
|
+
});
|
|
56
70
|
this.cleanupEditorDisabledListener = cleanupEditorDisabledListener;
|
|
57
71
|
var _DOMSerializer$render = DOMSerializer.renderSpec(document, toDOM(_node, !(api !== null && api !== void 0 && (_api$editorDisabled = api.editorDisabled) !== null && _api$editorDisabled !== void 0 && (_api$editorDisabled = _api$editorDisabled.sharedState.currentState()) !== null && _api$editorDisabled !== void 0 && _api$editorDisabled.editorDisabled))),
|
|
58
72
|
dom = _DOMSerializer$render.dom,
|
|
@@ -64,7 +78,9 @@ export var CodeBlockView = /*#__PURE__*/function () {
|
|
|
64
78
|
this.contentDOM = contentDOM;
|
|
65
79
|
this.lineNumberGutter = this.dom.querySelector(".".concat(fg('editor_support_code_block_wrapping') ? codeBlockClassNames.gutterFg : codeBlockClassNames.gutter));
|
|
66
80
|
this.api = api;
|
|
67
|
-
if (
|
|
81
|
+
if (fg('editor_support_code_block_wrapping')) {
|
|
82
|
+
this.maintainDynamicGutterSize();
|
|
83
|
+
} else {
|
|
68
84
|
this.ensureLineNumbers();
|
|
69
85
|
}
|
|
70
86
|
this.handleEditorDisabledChanged();
|
|
@@ -142,7 +158,9 @@ export var CodeBlockView = /*#__PURE__*/function () {
|
|
|
142
158
|
this.contentDOM.setAttribute('data-language', node.attrs.language || '');
|
|
143
159
|
}
|
|
144
160
|
this.node = node;
|
|
145
|
-
if (
|
|
161
|
+
if (fg('editor_support_code_block_wrapping')) {
|
|
162
|
+
this.maintainDynamicGutterSize();
|
|
163
|
+
} else {
|
|
146
164
|
this.ensureLineNumbers();
|
|
147
165
|
}
|
|
148
166
|
if (browser.android) {
|
|
@@ -181,7 +181,7 @@ export var createPlugin = function createPlugin(_ref) {
|
|
|
181
181
|
}
|
|
182
182
|
},
|
|
183
183
|
handleClickOn: createSelectionClickHandler(['codeBlock'], function (target) {
|
|
184
|
-
return !!(target.closest(".".concat(codeBlockClassNames.gutter)) || target.classList.contains(codeBlockClassNames.content));
|
|
184
|
+
return fg('editor_support_code_block_wrapping') ? !!(target.classList.contains(codeBlockClassNames.lineNumberWidget) || target.classList.contains(codeBlockClassNames.gutterFg)) : !!(target.closest(".".concat(codeBlockClassNames.gutter)) || target.classList.contains(codeBlockClassNames.content));
|
|
185
185
|
}, {
|
|
186
186
|
useLongPressSelection: useLongPressSelection
|
|
187
187
|
}),
|
|
@@ -16,6 +16,10 @@ export declare class CodeBlockView {
|
|
|
16
16
|
updateDOMAndSelection(savedInnerHTML: string, newCursorPosition: number): void;
|
|
17
17
|
coalesceDOMElements(): void;
|
|
18
18
|
private ensureLineNumbers;
|
|
19
|
+
/**
|
|
20
|
+
* As the code block updates we get the maximum amount of digits in a line number and expand the number gutter to reflect this.
|
|
21
|
+
*/
|
|
22
|
+
private maintainDynamicGutterSize;
|
|
19
23
|
update(node: Node): boolean;
|
|
20
24
|
ignoreMutation(record: MutationRecord | {
|
|
21
25
|
type: 'selection';
|
|
@@ -16,6 +16,10 @@ export declare class CodeBlockView {
|
|
|
16
16
|
updateDOMAndSelection(savedInnerHTML: string, newCursorPosition: number): void;
|
|
17
17
|
coalesceDOMElements(): void;
|
|
18
18
|
private ensureLineNumbers;
|
|
19
|
+
/**
|
|
20
|
+
* As the code block updates we get the maximum amount of digits in a line number and expand the number gutter to reflect this.
|
|
21
|
+
*/
|
|
22
|
+
private maintainDynamicGutterSize;
|
|
19
23
|
update(node: Node): boolean;
|
|
20
24
|
ignoreMutation(record: MutationRecord | {
|
|
21
25
|
type: 'selection';
|