@atlaskit/editor-plugin-code-block-advanced 12.0.0 → 12.0.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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-plugin-code-block-advanced
2
2
 
3
+ ## 12.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 12.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`4543a53261907`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4543a53261907) -
14
+ Fix code block language picker behaviour for auto-detection state, cap the picker trigger width,
15
+ keep detected labels stable across toolbar updates, and avoid selecting the whole code block when
16
+ dragging across multiple code lines.
17
+ - Updated dependencies
18
+
3
19
  ## 12.0.0
4
20
 
5
21
  ### Major Changes
@@ -61,6 +61,7 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
61
61
  (0, _defineProperty2.default)(this, "pmDecorationsCompartment", new _state.Compartment());
62
62
  (0, _defineProperty2.default)(this, "themeCompartment", new _state.Compartment());
63
63
  (0, _defineProperty2.default)(this, "maybeTryingToReachNodeSelection", false);
64
+ (0, _defineProperty2.default)(this, "mouseDownInsideCodeMirror", false);
64
65
  (0, _defineProperty2.default)(this, "pmFacet", _state.Facet.define());
65
66
  (0, _defineProperty2.default)(this, "wordWrappingEnabled", false);
66
67
  (0, _defineProperty2.default)(this, "lineNumbersHidden", false);
@@ -68,10 +69,22 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
68
69
  _this.selectCodeBlockNode(undefined);
69
70
  _this.view.focus();
70
71
  });
72
+ (0, _defineProperty2.default)(this, "handleBorderAreaMouseDown", function (event) {
73
+ var isBorderArea = _this.isBorderAreaClick(event);
74
+ // Later click can follow a drag; remember where the interaction began.
75
+ _this.mouseDownInsideCodeMirror = !isBorderArea;
76
+ if (isBorderArea && event.target === _this.cm.scrollDOM) {
77
+ // Stop CodeMirror from restoring stale inner selection before node selection.
78
+ event.preventDefault();
79
+ }
80
+ });
71
81
  (0, _defineProperty2.default)(this, "handleBorderAreaClick", function (event) {
72
- if (!_this.isBorderAreaClick(event)) {
82
+ // Dragging across lines leaves a CodeMirror selection; keep it instead of selecting the node.
83
+ if (_this.mouseDownInsideCodeMirror && _this.hasCodeMirrorTextSelection() || !_this.isBorderAreaClick(event)) {
84
+ _this.mouseDownInsideCodeMirror = false;
73
85
  return;
74
86
  }
87
+ _this.mouseDownInsideCodeMirror = false;
75
88
 
76
89
  // Prevent CodeMirror from restoring its inner selection after we hand focus and selection
77
90
  // back to ProseMirror
@@ -207,6 +220,10 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
207
220
  this.ro.observe(this.cm.contentDOM);
208
221
  }
209
222
  if ((0, _expValEquals.expValEquals)('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
223
+ this.cleanupBorderAreaMouseDown = (0, _bindEventListener.bind)(this.cm.scrollDOM, {
224
+ type: 'mousedown',
225
+ listener: this.handleBorderAreaMouseDown
226
+ });
210
227
  this.cleanupBorderAreaClick = (0, _bindEventListener.bind)(this.cm.scrollDOM, {
211
228
  type: 'click',
212
229
  listener: this.handleBorderAreaClick
@@ -245,12 +262,13 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
245
262
  return (0, _createClass2.default)(CodeBlockAdvancedNodeView, [{
246
263
  key: "destroy",
247
264
  value: function destroy() {
248
- var _this$cleanupBorderAr, _this$cleanupDisabled;
265
+ var _this$cleanupBorderAr, _this$cleanupBorderAr2, _this$cleanupDisabled;
249
266
  // ED-27428: CodeMirror gets into an infinite loop as it detects mutations on removed
250
267
  // decorations. When we change the breakout we destroy the node and cleanup these decorations from
251
268
  // codemirror
252
269
  this.clearProseMirrorDecorations();
253
- (_this$cleanupBorderAr = this.cleanupBorderAreaClick) === null || _this$cleanupBorderAr === void 0 || _this$cleanupBorderAr.call(this);
270
+ (_this$cleanupBorderAr = this.cleanupBorderAreaMouseDown) === null || _this$cleanupBorderAr === void 0 || _this$cleanupBorderAr.call(this);
271
+ (_this$cleanupBorderAr2 = this.cleanupBorderAreaClick) === null || _this$cleanupBorderAr2 === void 0 || _this$cleanupBorderAr2.call(this);
254
272
  (_this$cleanupDisabled = this.cleanupDisabledState) === null || _this$cleanupDisabled === void 0 || _this$cleanupDisabled.call(this);
255
273
  if ((0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true)) {
256
274
  var _this$unsubscribeCont;
@@ -482,6 +500,13 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
482
500
  });
483
501
  this.updating = false;
484
502
  }
503
+ }, {
504
+ key: "hasCodeMirrorTextSelection",
505
+ value: function hasCodeMirrorTextSelection() {
506
+ return this.cm.state.selection.ranges.some(function (range) {
507
+ return !range.empty;
508
+ });
509
+ }
485
510
  }, {
486
511
  key: "isBorderAreaClick",
487
512
  value: function isBorderAreaClick(event) {
@@ -41,6 +41,7 @@ class CodeBlockAdvancedNodeView {
41
41
  _defineProperty(this, "pmDecorationsCompartment", new Compartment());
42
42
  _defineProperty(this, "themeCompartment", new Compartment());
43
43
  _defineProperty(this, "maybeTryingToReachNodeSelection", false);
44
+ _defineProperty(this, "mouseDownInsideCodeMirror", false);
44
45
  _defineProperty(this, "pmFacet", Facet.define());
45
46
  _defineProperty(this, "wordWrappingEnabled", false);
46
47
  _defineProperty(this, "lineNumbersHidden", false);
@@ -48,10 +49,22 @@ class CodeBlockAdvancedNodeView {
48
49
  this.selectCodeBlockNode(undefined);
49
50
  this.view.focus();
50
51
  });
52
+ _defineProperty(this, "handleBorderAreaMouseDown", event => {
53
+ const isBorderArea = this.isBorderAreaClick(event);
54
+ // Later click can follow a drag; remember where the interaction began.
55
+ this.mouseDownInsideCodeMirror = !isBorderArea;
56
+ if (isBorderArea && event.target === this.cm.scrollDOM) {
57
+ // Stop CodeMirror from restoring stale inner selection before node selection.
58
+ event.preventDefault();
59
+ }
60
+ });
51
61
  _defineProperty(this, "handleBorderAreaClick", event => {
52
- if (!this.isBorderAreaClick(event)) {
62
+ // Dragging across lines leaves a CodeMirror selection; keep it instead of selecting the node.
63
+ if (this.mouseDownInsideCodeMirror && this.hasCodeMirrorTextSelection() || !this.isBorderAreaClick(event)) {
64
+ this.mouseDownInsideCodeMirror = false;
53
65
  return;
54
66
  }
67
+ this.mouseDownInsideCodeMirror = false;
55
68
 
56
69
  // Prevent CodeMirror from restoring its inner selection after we hand focus and selection
57
70
  // back to ProseMirror
@@ -175,6 +188,10 @@ class CodeBlockAdvancedNodeView {
175
188
  this.ro.observe(this.cm.contentDOM);
176
189
  }
177
190
  if (expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
191
+ this.cleanupBorderAreaMouseDown = bind(this.cm.scrollDOM, {
192
+ type: 'mousedown',
193
+ listener: this.handleBorderAreaMouseDown
194
+ });
178
195
  this.cleanupBorderAreaClick = bind(this.cm.scrollDOM, {
179
196
  type: 'click',
180
197
  listener: this.handleBorderAreaClick
@@ -211,12 +228,13 @@ class CodeBlockAdvancedNodeView {
211
228
  }
212
229
  }
213
230
  destroy() {
214
- var _this$cleanupBorderAr, _this$cleanupDisabled;
231
+ var _this$cleanupBorderAr, _this$cleanupBorderAr2, _this$cleanupDisabled;
215
232
  // ED-27428: CodeMirror gets into an infinite loop as it detects mutations on removed
216
233
  // decorations. When we change the breakout we destroy the node and cleanup these decorations from
217
234
  // codemirror
218
235
  this.clearProseMirrorDecorations();
219
- (_this$cleanupBorderAr = this.cleanupBorderAreaClick) === null || _this$cleanupBorderAr === void 0 ? void 0 : _this$cleanupBorderAr.call(this);
236
+ (_this$cleanupBorderAr = this.cleanupBorderAreaMouseDown) === null || _this$cleanupBorderAr === void 0 ? void 0 : _this$cleanupBorderAr.call(this);
237
+ (_this$cleanupBorderAr2 = this.cleanupBorderAreaClick) === null || _this$cleanupBorderAr2 === void 0 ? void 0 : _this$cleanupBorderAr2.call(this);
220
238
  (_this$cleanupDisabled = this.cleanupDisabledState) === null || _this$cleanupDisabled === void 0 ? void 0 : _this$cleanupDisabled.call(this);
221
239
  if (expValEquals('confluence_compact_text_format', 'isEnabled', true)) {
222
240
  var _this$unsubscribeCont;
@@ -410,6 +428,9 @@ class CodeBlockAdvancedNodeView {
410
428
  });
411
429
  this.updating = false;
412
430
  }
431
+ hasCodeMirrorTextSelection() {
432
+ return this.cm.state.selection.ranges.some(range => !range.empty);
433
+ }
413
434
  isBorderAreaClick(event) {
414
435
  const target = event.target;
415
436
  if (!(target instanceof HTMLElement)) {
@@ -55,6 +55,7 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
55
55
  _defineProperty(this, "pmDecorationsCompartment", new Compartment());
56
56
  _defineProperty(this, "themeCompartment", new Compartment());
57
57
  _defineProperty(this, "maybeTryingToReachNodeSelection", false);
58
+ _defineProperty(this, "mouseDownInsideCodeMirror", false);
58
59
  _defineProperty(this, "pmFacet", Facet.define());
59
60
  _defineProperty(this, "wordWrappingEnabled", false);
60
61
  _defineProperty(this, "lineNumbersHidden", false);
@@ -62,10 +63,22 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
62
63
  _this.selectCodeBlockNode(undefined);
63
64
  _this.view.focus();
64
65
  });
66
+ _defineProperty(this, "handleBorderAreaMouseDown", function (event) {
67
+ var isBorderArea = _this.isBorderAreaClick(event);
68
+ // Later click can follow a drag; remember where the interaction began.
69
+ _this.mouseDownInsideCodeMirror = !isBorderArea;
70
+ if (isBorderArea && event.target === _this.cm.scrollDOM) {
71
+ // Stop CodeMirror from restoring stale inner selection before node selection.
72
+ event.preventDefault();
73
+ }
74
+ });
65
75
  _defineProperty(this, "handleBorderAreaClick", function (event) {
66
- if (!_this.isBorderAreaClick(event)) {
76
+ // Dragging across lines leaves a CodeMirror selection; keep it instead of selecting the node.
77
+ if (_this.mouseDownInsideCodeMirror && _this.hasCodeMirrorTextSelection() || !_this.isBorderAreaClick(event)) {
78
+ _this.mouseDownInsideCodeMirror = false;
67
79
  return;
68
80
  }
81
+ _this.mouseDownInsideCodeMirror = false;
69
82
 
70
83
  // Prevent CodeMirror from restoring its inner selection after we hand focus and selection
71
84
  // back to ProseMirror
@@ -201,6 +214,10 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
201
214
  this.ro.observe(this.cm.contentDOM);
202
215
  }
203
216
  if (expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
217
+ this.cleanupBorderAreaMouseDown = bind(this.cm.scrollDOM, {
218
+ type: 'mousedown',
219
+ listener: this.handleBorderAreaMouseDown
220
+ });
204
221
  this.cleanupBorderAreaClick = bind(this.cm.scrollDOM, {
205
222
  type: 'click',
206
223
  listener: this.handleBorderAreaClick
@@ -239,12 +256,13 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
239
256
  return _createClass(CodeBlockAdvancedNodeView, [{
240
257
  key: "destroy",
241
258
  value: function destroy() {
242
- var _this$cleanupBorderAr, _this$cleanupDisabled;
259
+ var _this$cleanupBorderAr, _this$cleanupBorderAr2, _this$cleanupDisabled;
243
260
  // ED-27428: CodeMirror gets into an infinite loop as it detects mutations on removed
244
261
  // decorations. When we change the breakout we destroy the node and cleanup these decorations from
245
262
  // codemirror
246
263
  this.clearProseMirrorDecorations();
247
- (_this$cleanupBorderAr = this.cleanupBorderAreaClick) === null || _this$cleanupBorderAr === void 0 || _this$cleanupBorderAr.call(this);
264
+ (_this$cleanupBorderAr = this.cleanupBorderAreaMouseDown) === null || _this$cleanupBorderAr === void 0 || _this$cleanupBorderAr.call(this);
265
+ (_this$cleanupBorderAr2 = this.cleanupBorderAreaClick) === null || _this$cleanupBorderAr2 === void 0 || _this$cleanupBorderAr2.call(this);
248
266
  (_this$cleanupDisabled = this.cleanupDisabledState) === null || _this$cleanupDisabled === void 0 || _this$cleanupDisabled.call(this);
249
267
  if (expValEquals('confluence_compact_text_format', 'isEnabled', true)) {
250
268
  var _this$unsubscribeCont;
@@ -476,6 +494,13 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
476
494
  });
477
495
  this.updating = false;
478
496
  }
497
+ }, {
498
+ key: "hasCodeMirrorTextSelection",
499
+ value: function hasCodeMirrorTextSelection() {
500
+ return this.cm.state.selection.ranges.some(function (range) {
501
+ return !range.empty;
502
+ });
503
+ }
479
504
  }, {
480
505
  key: "isBorderAreaClick",
481
506
  value: function isBorderAreaClick(event) {
@@ -27,6 +27,7 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
27
27
  private contentMode;
28
28
  private selectionAPI;
29
29
  private maybeTryingToReachNodeSelection;
30
+ private mouseDownInsideCodeMirror;
30
31
  private cleanupDisabledState;
31
32
  private languageLoader;
32
33
  private pmFacet;
@@ -35,6 +36,7 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
35
36
  private invisibleAriaDescription?;
36
37
  private config;
37
38
  private cleanupBorderAreaClick;
39
+ private cleanupBorderAreaMouseDown;
38
40
  constructor(node: PMNode, view: EditorView, getPos: getPosHandlerNode, innerDecorations: DecorationSource, config: ConfigProps);
39
41
  destroy(): void;
40
42
  forwardUpdate(update: ViewUpdate): void;
@@ -63,7 +65,9 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
63
65
  */
64
66
  private getProseMirrorDecorationEffects;
65
67
  private clearProseMirrorDecorations;
68
+ private handleBorderAreaMouseDown;
66
69
  private handleBorderAreaClick;
70
+ private hasCodeMirrorTextSelection;
67
71
  private isBorderAreaClick;
68
72
  stopEvent(e: Event): boolean;
69
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block-advanced",
3
- "version": "12.0.0",
3
+ "version": "12.0.2",
4
4
  "description": "CodeBlockAdvanced plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -30,7 +30,7 @@
30
30
  "@atlaskit/editor-prosemirror": "^8.0.0",
31
31
  "@atlaskit/platform-feature-flags": "^2.0.0",
32
32
  "@atlaskit/prosemirror-history": "^1.0.0",
33
- "@atlaskit/tmp-editor-statsig": "^104.0.0",
33
+ "@atlaskit/tmp-editor-statsig": "^106.0.0",
34
34
  "@atlaskit/tokens": "^14.0.0",
35
35
  "@babel/runtime": "^7.0.0",
36
36
  "@codemirror/autocomplete": "6.18.4",
@@ -48,7 +48,7 @@
48
48
  "codemirror-lang-elixir": "4.0.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "@atlaskit/editor-common": "^116.0.0",
51
+ "@atlaskit/editor-common": "^116.2.0",
52
52
  "react": "^18.2.0",
53
53
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
54
54
  },
@@ -83,6 +83,7 @@ class CodeBlockAdvancedNodeView implements NodeView {
83
83
  private contentMode: EditorContentMode | undefined;
84
84
  private selectionAPI: EditorSelectionAPI | undefined;
85
85
  private maybeTryingToReachNodeSelection = false;
86
+ private mouseDownInsideCodeMirror = false;
86
87
  private cleanupDisabledState: (() => void) | undefined;
87
88
  private languageLoader: LanguageLoader;
88
89
  private pmFacet = Facet.define<DecorationSource>();
@@ -91,6 +92,7 @@ class CodeBlockAdvancedNodeView implements NodeView {
91
92
  private invisibleAriaDescription?: HTMLSpanElement;
92
93
  private config: ConfigProps;
93
94
  private cleanupBorderAreaClick: (() => void) | undefined;
95
+ private cleanupBorderAreaMouseDown: (() => void) | undefined;
94
96
 
95
97
  constructor(
96
98
  node: PMNode,
@@ -268,6 +270,10 @@ class CodeBlockAdvancedNodeView implements NodeView {
268
270
  }
269
271
 
270
272
  if (expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
273
+ this.cleanupBorderAreaMouseDown = bind(this.cm.scrollDOM, {
274
+ type: 'mousedown',
275
+ listener: this.handleBorderAreaMouseDown,
276
+ });
271
277
  this.cleanupBorderAreaClick = bind(this.cm.scrollDOM, {
272
278
  type: 'click',
273
279
  listener: this.handleBorderAreaClick,
@@ -314,6 +320,7 @@ class CodeBlockAdvancedNodeView implements NodeView {
314
320
  // decorations. When we change the breakout we destroy the node and cleanup these decorations from
315
321
  // codemirror
316
322
  this.clearProseMirrorDecorations();
323
+ this.cleanupBorderAreaMouseDown?.();
317
324
  this.cleanupBorderAreaClick?.();
318
325
  this.cleanupDisabledState?.();
319
326
  if (expValEquals('confluence_compact_text_format', 'isEnabled', true)) {
@@ -543,10 +550,27 @@ class CodeBlockAdvancedNodeView implements NodeView {
543
550
  this.updating = false;
544
551
  }
545
552
 
553
+ private handleBorderAreaMouseDown = (event: MouseEvent) => {
554
+ const isBorderArea = this.isBorderAreaClick(event);
555
+ // Later click can follow a drag; remember where the interaction began.
556
+ this.mouseDownInsideCodeMirror = !isBorderArea;
557
+
558
+ if (isBorderArea && event.target === this.cm.scrollDOM) {
559
+ // Stop CodeMirror from restoring stale inner selection before node selection.
560
+ event.preventDefault();
561
+ }
562
+ };
563
+
546
564
  private handleBorderAreaClick = (event: MouseEvent) => {
547
- if (!this.isBorderAreaClick(event)) {
565
+ // Dragging across lines leaves a CodeMirror selection; keep it instead of selecting the node.
566
+ if (
567
+ (this.mouseDownInsideCodeMirror && this.hasCodeMirrorTextSelection()) ||
568
+ !this.isBorderAreaClick(event)
569
+ ) {
570
+ this.mouseDownInsideCodeMirror = false;
548
571
  return;
549
572
  }
573
+ this.mouseDownInsideCodeMirror = false;
550
574
 
551
575
  // Prevent CodeMirror from restoring its inner selection after we hand focus and selection
552
576
  // back to ProseMirror
@@ -557,6 +581,10 @@ class CodeBlockAdvancedNodeView implements NodeView {
557
581
  this.selectCodeBlockNode(undefined);
558
582
  };
559
583
 
584
+ private hasCodeMirrorTextSelection(): boolean {
585
+ return this.cm.state.selection.ranges.some((range) => !range.empty);
586
+ }
587
+
560
588
  private isBorderAreaClick(event: MouseEvent): boolean {
561
589
  const target = event.target;
562
590
  if (!(target instanceof HTMLElement)) {