@atlaskit/editor-plugin-code-block-advanced 3.0.0 → 3.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,20 @@
1
1
  # @atlaskit/editor-plugin-code-block-advanced
2
2
 
3
+ ## 3.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 3.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#182587](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/182587)
14
+ [`ab1ee31f25e9c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ab1ee31f25e9c) -
15
+ Fixes issue where right click menu would select entire code block.
16
+ - Updated dependencies
17
+
3
18
  ## 3.0.0
4
19
 
5
20
  ### Major Changes
@@ -17,6 +17,7 @@ var _codeBlock = require("@atlaskit/editor-common/code-block");
17
17
  var _whitespace = require("@atlaskit/editor-common/whitespace");
18
18
  var _state2 = require("@atlaskit/editor-prosemirror/state");
19
19
  var _view2 = require("@atlaskit/editor-prosemirror/view");
20
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
20
21
  var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
21
22
  var _syntaxHighlightingTheme = require("../ui/syntaxHighlightingTheme");
22
23
  var _theme = require("../ui/theme");
@@ -74,7 +75,15 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
74
75
  selectCodeBlockNode: this.selectCodeBlockNode.bind(this),
75
76
  onMaybeNodeSelection: onMaybeNodeSelection,
76
77
  customFindReplace: Boolean((_config$api3 = config.api) === null || _config$api3 === void 0 ? void 0 : _config$api3.findReplace)
77
- }), _theme.cmTheme, (0, _language.syntaxHighlighting)(_syntaxHighlightingTheme.highlightStyle), (0, _language.bracketMatching)(), (0, _view.lineNumbers)(),
78
+ }), _theme.cmTheme, (0, _language.syntaxHighlighting)(_syntaxHighlightingTheme.highlightStyle), (0, _language.bracketMatching)(), (0, _view.lineNumbers)({
79
+ domEventHandlers: (0, _platformFeatureFlags.fg)('platform_editor_fix_right_click_paste') ? {
80
+ click: function click() {
81
+ _this.selectCodeBlockNode(undefined);
82
+ _this.view.focus();
83
+ return true;
84
+ }
85
+ } : undefined
86
+ }),
78
87
  // Explicitly disable "sticky" positioning on line numbers to match
79
88
  // Renderer behaviour
80
89
  (0, _view.gutters)({
@@ -243,23 +252,25 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
243
252
  value: function stopEvent(e) {
244
253
  var _this2 = this,
245
254
  _this$getPos5;
246
- if (e instanceof MouseEvent && e.type === 'mousedown') {
247
- // !Warning: Side effect!
248
- // CodeMirror on blur updates the dom observer with a `setTimeout(..., 10);`
249
- // We need to select the nodeview after this has taken place to ensure
250
- // ProseMirror takes over
251
- // https://github.com/codemirror/view/commit/70a9a253df04a57004247b9463198c17832f92f4#diff-cb8cbffa623ff0975389e7e8c315e69d5e10345239ffe2c9b4b7986a56ad95efR720
252
- setTimeout(function () {
253
- // Ensure the CM selection is reset - if we have a ranged selection when we do node selection can
254
- // cause funky behaviour
255
- _this2.updating = true;
256
- _this2.cm.dispatch({
257
- selection: _state.EditorSelection.create([_state.EditorSelection.cursor(0)], 0)
258
- });
259
- _this2.updating = false;
260
- _this2.selectCodeBlockNode(undefined);
261
- _this2.view.focus();
262
- }, 20);
255
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_fix_right_click_paste')) {
256
+ if (e instanceof MouseEvent && e.type === 'mousedown') {
257
+ // !Warning: Side effect!
258
+ // CodeMirror on blur updates the dom observer with a `setTimeout(..., 10);`
259
+ // We need to select the nodeview after this has taken place to ensure
260
+ // ProseMirror takes over
261
+ // https://github.com/codemirror/view/commit/70a9a253df04a57004247b9463198c17832f92f4#diff-cb8cbffa623ff0975389e7e8c315e69d5e10345239ffe2c9b4b7986a56ad95efR720
262
+ setTimeout(function () {
263
+ // Ensure the CM selection is reset - if we have a ranged selection when we do node selection can
264
+ // cause funky behaviour
265
+ _this2.updating = true;
266
+ _this2.cm.dispatch({
267
+ selection: _state.EditorSelection.create([_state.EditorSelection.cursor(0)], 0)
268
+ });
269
+ _this2.updating = false;
270
+ _this2.selectCodeBlockNode(undefined);
271
+ _this2.view.focus();
272
+ }, 20);
273
+ }
263
274
  }
264
275
  // If we have selected the node we should not stop these events
265
276
  if ((e instanceof KeyboardEvent || e instanceof ClipboardEvent) && this.view.state.selection instanceof _state2.NodeSelection && this.view.state.selection.from === ((_this$getPos5 = this.getPos) === null || _this$getPos5 === void 0 ? void 0 : _this$getPos5.call(this))) {
@@ -51,10 +51,13 @@ var cmTheme = exports.cmTheme = _view.EditorView.theme({
51
51
  '&.cm-focused .cm-cursor': {
52
52
  borderLeftColor: "var(--ds-text, #172B4D)"
53
53
  },
54
+ '.cm-gutter': {
55
+ padding: "var(--ds-space-100, 8px)"
56
+ },
54
57
  '.cm-gutters': {
55
58
  backgroundColor: "var(--ds-background-neutral, #091E420F)",
56
59
  border: 'none',
57
- padding: "var(--ds-space-100, 8px)",
60
+ padding: "var(--ds-space-0, 0px)",
58
61
  color: "var(--ds-text-subtlest, #626F86)"
59
62
  },
60
63
  '.cm-lineNumbers .cm-gutterElement': {
@@ -7,6 +7,7 @@ import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
7
7
  import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
8
8
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
9
9
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
10
+ import { fg } from '@atlaskit/platform-feature-flags';
10
11
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
11
12
  import { highlightStyle } from '../ui/syntaxHighlightingTheme';
12
13
  import { cmTheme } from '../ui/theme';
@@ -54,7 +55,15 @@ class CodeBlockAdvancedNodeView {
54
55
  selectCodeBlockNode: this.selectCodeBlockNode.bind(this),
55
56
  onMaybeNodeSelection,
56
57
  customFindReplace: Boolean((_config$api3 = config.api) === null || _config$api3 === void 0 ? void 0 : _config$api3.findReplace)
57
- }), cmTheme, syntaxHighlighting(highlightStyle), bracketMatching(), lineNumbers(),
58
+ }), cmTheme, syntaxHighlighting(highlightStyle), bracketMatching(), lineNumbers({
59
+ domEventHandlers: fg('platform_editor_fix_right_click_paste') ? {
60
+ click: () => {
61
+ this.selectCodeBlockNode(undefined);
62
+ this.view.focus();
63
+ return true;
64
+ }
65
+ } : undefined
66
+ }),
58
67
  // Explicitly disable "sticky" positioning on line numbers to match
59
68
  // Renderer behaviour
60
69
  gutters({
@@ -192,23 +201,25 @@ class CodeBlockAdvancedNodeView {
192
201
  }
193
202
  stopEvent(e) {
194
203
  var _this$getPos5;
195
- if (e instanceof MouseEvent && e.type === 'mousedown') {
196
- // !Warning: Side effect!
197
- // CodeMirror on blur updates the dom observer with a `setTimeout(..., 10);`
198
- // We need to select the nodeview after this has taken place to ensure
199
- // ProseMirror takes over
200
- // https://github.com/codemirror/view/commit/70a9a253df04a57004247b9463198c17832f92f4#diff-cb8cbffa623ff0975389e7e8c315e69d5e10345239ffe2c9b4b7986a56ad95efR720
201
- setTimeout(() => {
202
- // Ensure the CM selection is reset - if we have a ranged selection when we do node selection can
203
- // cause funky behaviour
204
- this.updating = true;
205
- this.cm.dispatch({
206
- selection: EditorSelection.create([EditorSelection.cursor(0)], 0)
207
- });
208
- this.updating = false;
209
- this.selectCodeBlockNode(undefined);
210
- this.view.focus();
211
- }, 20);
204
+ if (!fg('platform_editor_fix_right_click_paste')) {
205
+ if (e instanceof MouseEvent && e.type === 'mousedown') {
206
+ // !Warning: Side effect!
207
+ // CodeMirror on blur updates the dom observer with a `setTimeout(..., 10);`
208
+ // We need to select the nodeview after this has taken place to ensure
209
+ // ProseMirror takes over
210
+ // https://github.com/codemirror/view/commit/70a9a253df04a57004247b9463198c17832f92f4#diff-cb8cbffa623ff0975389e7e8c315e69d5e10345239ffe2c9b4b7986a56ad95efR720
211
+ setTimeout(() => {
212
+ // Ensure the CM selection is reset - if we have a ranged selection when we do node selection can
213
+ // cause funky behaviour
214
+ this.updating = true;
215
+ this.cm.dispatch({
216
+ selection: EditorSelection.create([EditorSelection.cursor(0)], 0)
217
+ });
218
+ this.updating = false;
219
+ this.selectCodeBlockNode(undefined);
220
+ this.view.focus();
221
+ }, 20);
222
+ }
212
223
  }
213
224
  // If we have selected the node we should not stop these events
214
225
  if ((e instanceof KeyboardEvent || e instanceof ClipboardEvent) && this.view.state.selection instanceof NodeSelection && this.view.state.selection.from === ((_this$getPos5 = this.getPos) === null || _this$getPos5 === void 0 ? void 0 : _this$getPos5.call(this))) {
@@ -45,10 +45,13 @@ export const cmTheme = CodeMirror.theme({
45
45
  '&.cm-focused .cm-cursor': {
46
46
  borderLeftColor: "var(--ds-text, #172B4D)"
47
47
  },
48
+ '.cm-gutter': {
49
+ padding: "var(--ds-space-100, 8px)"
50
+ },
48
51
  '.cm-gutters': {
49
52
  backgroundColor: "var(--ds-background-neutral, #091E420F)",
50
53
  border: 'none',
51
- padding: "var(--ds-space-100, 8px)",
54
+ padding: "var(--ds-space-0, 0px)",
52
55
  color: "var(--ds-text-subtlest, #626F86)"
53
56
  },
54
57
  '.cm-lineNumbers .cm-gutterElement': {
@@ -10,6 +10,7 @@ import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
10
10
  import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
11
11
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
12
12
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
13
+ import { fg } from '@atlaskit/platform-feature-flags';
13
14
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
14
15
  import { highlightStyle } from '../ui/syntaxHighlightingTheme';
15
16
  import { cmTheme } from '../ui/theme';
@@ -67,7 +68,15 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
67
68
  selectCodeBlockNode: this.selectCodeBlockNode.bind(this),
68
69
  onMaybeNodeSelection: onMaybeNodeSelection,
69
70
  customFindReplace: Boolean((_config$api3 = config.api) === null || _config$api3 === void 0 ? void 0 : _config$api3.findReplace)
70
- }), cmTheme, syntaxHighlighting(highlightStyle), bracketMatching(), lineNumbers(),
71
+ }), cmTheme, syntaxHighlighting(highlightStyle), bracketMatching(), lineNumbers({
72
+ domEventHandlers: fg('platform_editor_fix_right_click_paste') ? {
73
+ click: function click() {
74
+ _this.selectCodeBlockNode(undefined);
75
+ _this.view.focus();
76
+ return true;
77
+ }
78
+ } : undefined
79
+ }),
71
80
  // Explicitly disable "sticky" positioning on line numbers to match
72
81
  // Renderer behaviour
73
82
  gutters({
@@ -236,23 +245,25 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
236
245
  value: function stopEvent(e) {
237
246
  var _this2 = this,
238
247
  _this$getPos5;
239
- if (e instanceof MouseEvent && e.type === 'mousedown') {
240
- // !Warning: Side effect!
241
- // CodeMirror on blur updates the dom observer with a `setTimeout(..., 10);`
242
- // We need to select the nodeview after this has taken place to ensure
243
- // ProseMirror takes over
244
- // https://github.com/codemirror/view/commit/70a9a253df04a57004247b9463198c17832f92f4#diff-cb8cbffa623ff0975389e7e8c315e69d5e10345239ffe2c9b4b7986a56ad95efR720
245
- setTimeout(function () {
246
- // Ensure the CM selection is reset - if we have a ranged selection when we do node selection can
247
- // cause funky behaviour
248
- _this2.updating = true;
249
- _this2.cm.dispatch({
250
- selection: EditorSelection.create([EditorSelection.cursor(0)], 0)
251
- });
252
- _this2.updating = false;
253
- _this2.selectCodeBlockNode(undefined);
254
- _this2.view.focus();
255
- }, 20);
248
+ if (!fg('platform_editor_fix_right_click_paste')) {
249
+ if (e instanceof MouseEvent && e.type === 'mousedown') {
250
+ // !Warning: Side effect!
251
+ // CodeMirror on blur updates the dom observer with a `setTimeout(..., 10);`
252
+ // We need to select the nodeview after this has taken place to ensure
253
+ // ProseMirror takes over
254
+ // https://github.com/codemirror/view/commit/70a9a253df04a57004247b9463198c17832f92f4#diff-cb8cbffa623ff0975389e7e8c315e69d5e10345239ffe2c9b4b7986a56ad95efR720
255
+ setTimeout(function () {
256
+ // Ensure the CM selection is reset - if we have a ranged selection when we do node selection can
257
+ // cause funky behaviour
258
+ _this2.updating = true;
259
+ _this2.cm.dispatch({
260
+ selection: EditorSelection.create([EditorSelection.cursor(0)], 0)
261
+ });
262
+ _this2.updating = false;
263
+ _this2.selectCodeBlockNode(undefined);
264
+ _this2.view.focus();
265
+ }, 20);
266
+ }
256
267
  }
257
268
  // If we have selected the node we should not stop these events
258
269
  if ((e instanceof KeyboardEvent || e instanceof ClipboardEvent) && this.view.state.selection instanceof NodeSelection && this.view.state.selection.from === ((_this$getPos5 = this.getPos) === null || _this$getPos5 === void 0 ? void 0 : _this$getPos5.call(this))) {
@@ -45,10 +45,13 @@ export var cmTheme = CodeMirror.theme({
45
45
  '&.cm-focused .cm-cursor': {
46
46
  borderLeftColor: "var(--ds-text, #172B4D)"
47
47
  },
48
+ '.cm-gutter': {
49
+ padding: "var(--ds-space-100, 8px)"
50
+ },
48
51
  '.cm-gutters': {
49
52
  backgroundColor: "var(--ds-background-neutral, #091E420F)",
50
53
  border: 'none',
51
- padding: "var(--ds-space-100, 8px)",
54
+ padding: "var(--ds-space-0, 0px)",
52
55
  color: "var(--ds-text-subtlest, #626F86)"
53
56
  },
54
57
  '.cm-lineNumbers .cm-gutterElement': {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block-advanced",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "CodeBlockAdvanced plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -39,7 +39,7 @@
39
39
  "@atlaskit/editor-plugin-selection-marker": "^3.0.0",
40
40
  "@atlaskit/editor-prosemirror": "7.0.0",
41
41
  "@atlaskit/platform-feature-flags": "^1.1.0",
42
- "@atlaskit/tmp-editor-statsig": "^8.7.0",
42
+ "@atlaskit/tmp-editor-statsig": "^9.0.0",
43
43
  "@atlaskit/tokens": "^5.4.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@codemirror/autocomplete": "6.18.4",
@@ -54,7 +54,7 @@
54
54
  "codemirror-lang-elixir": "4.0.0"
55
55
  },
56
56
  "peerDependencies": {
57
- "@atlaskit/editor-common": "^107.6.0",
57
+ "@atlaskit/editor-common": "^107.7.0",
58
58
  "react": "^18.2.0"
59
59
  },
60
60
  "devDependencies": {
@@ -100,6 +100,9 @@
100
100
  "platform-feature-flags": {
101
101
  "platform_editor_breakout_resizing_hello_release": {
102
102
  "type": "boolean"
103
+ },
104
+ "platform_editor_fix_right_click_paste": {
105
+ "type": "boolean"
103
106
  }
104
107
  }
105
108
  }
@@ -28,6 +28,7 @@ import type {
28
28
  NodeView,
29
29
  } from '@atlaskit/editor-prosemirror/view';
30
30
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
31
+ import { fg } from '@atlaskit/platform-feature-flags';
31
32
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
32
33
 
33
34
  import type { CodeBlockAdvancedPlugin } from '../codeBlockAdvancedPluginType';
@@ -110,7 +111,17 @@ class CodeBlockAdvancedNodeView implements NodeView {
110
111
  cmTheme,
111
112
  syntaxHighlighting(highlightStyle),
112
113
  bracketMatching(),
113
- lineNumbers(),
114
+ lineNumbers({
115
+ domEventHandlers: fg('platform_editor_fix_right_click_paste')
116
+ ? {
117
+ click: () => {
118
+ this.selectCodeBlockNode(undefined);
119
+ this.view.focus();
120
+ return true;
121
+ },
122
+ }
123
+ : undefined,
124
+ }),
114
125
  // Explicitly disable "sticky" positioning on line numbers to match
115
126
  // Renderer behaviour
116
127
  gutters({ fixed: false }),
@@ -264,23 +275,25 @@ class CodeBlockAdvancedNodeView implements NodeView {
264
275
  }
265
276
 
266
277
  stopEvent(e: Event) {
267
- if (e instanceof MouseEvent && e.type === 'mousedown') {
268
- // !Warning: Side effect!
269
- // CodeMirror on blur updates the dom observer with a `setTimeout(..., 10);`
270
- // We need to select the nodeview after this has taken place to ensure
271
- // ProseMirror takes over
272
- // https://github.com/codemirror/view/commit/70a9a253df04a57004247b9463198c17832f92f4#diff-cb8cbffa623ff0975389e7e8c315e69d5e10345239ffe2c9b4b7986a56ad95efR720
273
- setTimeout(() => {
274
- // Ensure the CM selection is reset - if we have a ranged selection when we do node selection can
275
- // cause funky behaviour
276
- this.updating = true;
277
- this.cm.dispatch({
278
- selection: EditorSelection.create([EditorSelection.cursor(0)], 0),
279
- });
280
- this.updating = false;
281
- this.selectCodeBlockNode(undefined);
282
- this.view.focus();
283
- }, 20);
278
+ if (!fg('platform_editor_fix_right_click_paste')) {
279
+ if (e instanceof MouseEvent && e.type === 'mousedown') {
280
+ // !Warning: Side effect!
281
+ // CodeMirror on blur updates the dom observer with a `setTimeout(..., 10);`
282
+ // We need to select the nodeview after this has taken place to ensure
283
+ // ProseMirror takes over
284
+ // https://github.com/codemirror/view/commit/70a9a253df04a57004247b9463198c17832f92f4#diff-cb8cbffa623ff0975389e7e8c315e69d5e10345239ffe2c9b4b7986a56ad95efR720
285
+ setTimeout(() => {
286
+ // Ensure the CM selection is reset - if we have a ranged selection when we do node selection can
287
+ // cause funky behaviour
288
+ this.updating = true;
289
+ this.cm.dispatch({
290
+ selection: EditorSelection.create([EditorSelection.cursor(0)], 0),
291
+ });
292
+ this.updating = false;
293
+ this.selectCodeBlockNode(undefined);
294
+ this.view.focus();
295
+ }, 20);
296
+ }
284
297
  }
285
298
  // If we have selected the node we should not stop these events
286
299
  if (
package/src/ui/theme.ts CHANGED
@@ -49,10 +49,13 @@ export const cmTheme = CodeMirror.theme({
49
49
  '&.cm-focused .cm-cursor': {
50
50
  borderLeftColor: token('color.text'),
51
51
  },
52
+ '.cm-gutter': {
53
+ padding: token('space.100'),
54
+ },
52
55
  '.cm-gutters': {
53
56
  backgroundColor: token('color.background.neutral'),
54
57
  border: 'none',
55
- padding: token('space.100'),
58
+ padding: token('space.0'),
56
59
  color: token('color.text.subtlest'),
57
60
  },
58
61
  '.cm-lineNumbers .cm-gutterElement': {