@atlaskit/editor-plugin-code-block-advanced 10.0.20 → 10.1.1

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/codeBlockAdvancedPlugin/package.json +15 -0
  3. package/codeBlockAdvancedPluginType/package.json +15 -0
  4. package/dist/cjs/entry-points/codeBlockAdvancedPlugin.js +12 -0
  5. package/dist/cjs/entry-points/codeBlockAdvancedPluginType.js +1 -0
  6. package/dist/cjs/nodeviews/codeBlockAdvanced.js +47 -19
  7. package/dist/cjs/nodeviews/codeBlockNodeWithToDOMFixed.js +61 -27
  8. package/dist/cjs/ui/theme.js +12 -2
  9. package/dist/es2019/entry-points/codeBlockAdvancedPlugin.js +2 -0
  10. package/dist/es2019/entry-points/codeBlockAdvancedPluginType.js +0 -0
  11. package/dist/es2019/nodeviews/codeBlockAdvanced.js +39 -18
  12. package/dist/es2019/nodeviews/codeBlockNodeWithToDOMFixed.js +53 -25
  13. package/dist/es2019/ui/theme.js +8 -1
  14. package/dist/esm/entry-points/codeBlockAdvancedPlugin.js +2 -0
  15. package/dist/esm/entry-points/codeBlockAdvancedPluginType.js +0 -0
  16. package/dist/esm/nodeviews/codeBlockAdvanced.js +48 -20
  17. package/dist/esm/nodeviews/codeBlockNodeWithToDOMFixed.js +61 -27
  18. package/dist/esm/ui/theme.js +11 -2
  19. package/dist/types/entry-points/codeBlockAdvancedPlugin.d.ts +1 -0
  20. package/dist/types/entry-points/codeBlockAdvancedPluginType.d.ts +1 -0
  21. package/dist/types/nodeviews/codeBlockAdvanced.d.ts +6 -0
  22. package/dist/types-ts4.5/entry-points/codeBlockAdvancedPlugin.d.ts +1 -0
  23. package/dist/types-ts4.5/entry-points/codeBlockAdvancedPluginType.d.ts +1 -0
  24. package/dist/types-ts4.5/nodeviews/codeBlockAdvanced.d.ts +6 -0
  25. package/docs/0-intro.tsx +1 -1
  26. package/package.json +8 -8
  27. package/src/entry-points/codeBlockAdvancedPlugin.tsx +2 -0
  28. package/src/entry-points/codeBlockAdvancedPluginType.ts +5 -0
  29. package/src/nodeviews/codeBlockAdvanced.ts +64 -19
  30. package/src/nodeviews/codeBlockNodeWithToDOMFixed.ts +74 -33
  31. package/src/ui/theme.ts +7 -0
@@ -12,7 +12,7 @@ import { syntaxHighlighting, bracketMatching } from '@codemirror/language';
12
12
  import { Compartment, Facet, EditorState as CodeMirrorState } from '@codemirror/state';
13
13
  import { EditorView as CodeMirror, lineNumbers, gutters } from '@codemirror/view';
14
14
  import { getBrowserInfo } from '@atlaskit/editor-common/browser';
15
- import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
15
+ import { areCodeBlockLineNumbersHidden, isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
16
16
  import { messages as floatingToolbarMessages } from '@atlaskit/editor-common/floating-toolbar';
17
17
  import { blockTypeMessages, codeBlockMessages, roleDescriptionMessages } from '@atlaskit/editor-common/messages';
18
18
  import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
@@ -40,14 +40,15 @@ var codeBlockHeights = new WeakMap();
40
40
  // Based on: https://prosemirror.net/examples/codemirror/
41
41
  var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
42
42
  function CodeBlockAdvancedNodeView(node, view, getPos, innerDecorations, config) {
43
- var _config$api,
43
+ var _this = this,
44
+ _config$api,
44
45
  _contentFormatSharedS,
45
46
  _config$api2,
46
- _this = this,
47
47
  _config$api3,
48
48
  _config$api4;
49
49
  _classCallCheck(this, CodeBlockAdvancedNodeView);
50
50
  _defineProperty(this, "lineWrappingCompartment", new Compartment());
51
+ _defineProperty(this, "lineNumbersCompartment", new Compartment());
51
52
  _defineProperty(this, "languageCompartment", new Compartment());
52
53
  _defineProperty(this, "readOnlyCompartment", new Compartment());
53
54
  _defineProperty(this, "pmDecorationsCompartment", new Compartment());
@@ -55,6 +56,11 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
55
56
  _defineProperty(this, "maybeTryingToReachNodeSelection", false);
56
57
  _defineProperty(this, "pmFacet", Facet.define());
57
58
  _defineProperty(this, "wordWrappingEnabled", false);
59
+ _defineProperty(this, "lineNumbersHidden", false);
60
+ _defineProperty(this, "selectCodeBlockNodeAndFocus", function () {
61
+ _this.selectCodeBlockNode(undefined);
62
+ _this.view.focus();
63
+ });
58
64
  this.config = config;
59
65
  this.node = node;
60
66
  this.view = view;
@@ -81,10 +87,6 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
81
87
  var _config$getIntl = config.getIntl(),
82
88
  formatMessage = _config$getIntl.formatMessage;
83
89
  var formattedAriaLabel = formatMessage(blockTypeMessages.codeblock);
84
- var selectNode = function selectNode() {
85
- _this.selectCodeBlockNode(undefined);
86
- _this.view.focus();
87
- };
88
90
  var isMacOS = getBrowserInfo().mac;
89
91
  this.cm = new CodeMirror({
90
92
  doc: this.node.textContent,
@@ -101,16 +103,9 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
101
103
  // Goes before cmTheme to override styles
102
104
  config.allowCodeFolding ? [codeFoldingTheme] : [], this.themeCompartment.of(cmTheme({
103
105
  contentMode: expValEquals('confluence_compact_text_format', 'isEnabled', true) ? this.contentMode : undefined
104
- })), syntaxHighlighting(highlightStyle), bracketMatching(), lineNumbers({
105
- domEventHandlers: {
106
- click: function click() {
107
- selectNode();
108
- return true;
109
- }
110
- }
111
- }),
112
- // Explicitly disable "sticky" positioning on line numbers to match
113
- // Renderer behaviour
106
+ })), syntaxHighlighting(highlightStyle), bracketMatching(), expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) ? this.lineNumbersCompartment.of(this.getLineNumberVisibilityExtensions(node)) : this.getLineNumberExtensions(),
107
+ // Explicitly disable "sticky" positioning on all gutters to match
108
+ // Renderer behaviour.
114
109
  gutters({
115
110
  fixed: false
116
111
  }), CodeMirror.updateListener.of(function (update) {
@@ -133,7 +128,7 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
133
128
  'aria-label': formattedAriaLabel,
134
129
  'aria-describedby': "codesnippet-".concat(this.node.attrs.localId)
135
130
  })), config.allowCodeFolding ? [foldGutterExtension({
136
- selectNode: selectNode,
131
+ selectNode: this.selectCodeBlockNodeAndFocus,
137
132
  getNode: function getNode() {
138
133
  return _this.node;
139
134
  }
@@ -215,6 +210,7 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
215
210
  this.updateLanguage();
216
211
  this.updateLocalIdAttribute();
217
212
  this.wordWrappingEnabled = isCodeBlockWordWrapEnabled(node);
213
+ this.lineNumbersHidden = areCodeBlockLineNumbersHidden(node);
218
214
 
219
215
  // Restore fold state after initialization
220
216
  if (config.allowCodeFolding) {
@@ -329,6 +325,37 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
329
325
  this.view.dispatch(tr);
330
326
  }
331
327
  }
328
+ }, {
329
+ key: "getLineNumberExtensions",
330
+ value: function getLineNumberExtensions() {
331
+ var _this2 = this;
332
+ return [lineNumbers({
333
+ domEventHandlers: {
334
+ click: function click() {
335
+ _this2.selectCodeBlockNodeAndFocus();
336
+ return true;
337
+ }
338
+ }
339
+ })];
340
+ }
341
+ }, {
342
+ key: "getLineNumberVisibilityExtensions",
343
+ value: function getLineNumberVisibilityExtensions(node) {
344
+ if (areCodeBlockLineNumbersHidden(node)) {
345
+ return [];
346
+ }
347
+ return this.getLineNumberExtensions();
348
+ }
349
+ }, {
350
+ key: "getLineNumbersEffects",
351
+ value: function getLineNumbersEffects(node) {
352
+ var lineNumbersHidden = areCodeBlockLineNumbersHidden(node);
353
+ if (this.lineNumbersHidden !== lineNumbersHidden) {
354
+ this.lineNumbersHidden = lineNumbersHidden;
355
+ return this.lineNumbersCompartment.reconfigure(this.getLineNumberVisibilityExtensions(node));
356
+ }
357
+ return undefined;
358
+ }
332
359
  }, {
333
360
  key: "getWordWrapEffects",
334
361
  value: function getWordWrapEffects(node) {
@@ -387,11 +414,12 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
387
414
  // Updates bundled for performance (to avoid multiple-dispatches)
388
415
  var changes = getCMSelectionChanges(curText, newText);
389
416
  var wordWrapEffect = this.getWordWrapEffects(node);
417
+ var lineNumbersEffect = expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) ? this.getLineNumbersEffects(node) : undefined;
390
418
  var prosemirrorDecorationsEffect = this.getProseMirrorDecorationEffects(innerDecorations);
391
- if (changes || wordWrapEffect || prosemirrorDecorationsEffect) {
419
+ if (changes || wordWrapEffect || lineNumbersEffect || prosemirrorDecorationsEffect) {
392
420
  this.updating = true;
393
421
  this.cm.dispatch({
394
- effects: [wordWrapEffect, prosemirrorDecorationsEffect].filter(function (effect) {
422
+ effects: [wordWrapEffect, lineNumbersEffect, prosemirrorDecorationsEffect].filter(function (effect) {
395
423
  return !!effect;
396
424
  }),
397
425
  changes: changes
@@ -1,7 +1,9 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
5
  import { codeBlock, codeBlockWithExtendedAttributes, codeBlockWithLocalId } from '@atlaskit/adf-schema';
6
+ import { areCodeBlockLineNumbersHidden } from '@atlaskit/editor-common/code-block';
5
7
  import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
6
8
  import { CodeBlockSharedCssClassName } from '@atlaskit/editor-common/styles';
7
9
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -17,6 +19,57 @@ var MATCH_NEWLINES = new RegExp('\n', 'gu');
17
19
  var getFontSize = function getFontSize() {
18
20
  return expValEquals('confluence_compact_text_format', 'isEnabled', true) || expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp') ? '0.875em' : '0.875rem';
19
21
  };
22
+ var getGutterBaseStyle = function getGutterBaseStyle() {
23
+ return {
24
+ backgroundColor: "var(--ds-background-neutral, #0515240F)",
25
+ position: 'relative',
26
+ flexShrink: 0,
27
+ // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
28
+ fontSize: getFontSize(),
29
+ boxSizing: 'content-box'
30
+ };
31
+ };
32
+ var getGutterPadding = function getGutterPadding(allowCodeFolding) {
33
+ return allowCodeFolding ? "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-250, 20px)", " ", "var(--ds-space-100, 8px)", " ", "var(--ds-space-075, 6px)") : "var(--ds-space-100, 8px)";
34
+ };
35
+ var getGuttersWithLineNumbers = function getGuttersWithLineNumbers(content, config) {
36
+ return ['div', {
37
+ // Based on packages/editor/editor-common/src/styles/shared/code-block.ts
38
+ // But we can't reuse that class as it adds a ::before that intefers with this approach
39
+ style: convertToInlineCss(_objectSpread(_objectSpread({}, getGutterBaseStyle()), {}, {
40
+ width: 'var(--lineNumberGutterWidth, 2rem)',
41
+ /* top and bottom | left and right */
42
+ padding: getGutterPadding(config.allowCodeFolding)
43
+ })),
44
+ contenteditable: 'false'
45
+ }, ['div', {
46
+ class: 'code-block-gutter-pseudo-element',
47
+ style: convertToInlineCss({
48
+ textAlign: 'right',
49
+ color: "var(--ds-text-subtlest, #6B6E76)",
50
+ fontFamily: "var(--ds-font-family-code, \"Atlassian Mono\", ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)",
51
+ whiteSpace: 'pre-wrap'
52
+ }),
53
+ 'data-label': content
54
+ }]];
55
+ };
56
+ var getFoldOnlyGutter = function getFoldOnlyGutter() {
57
+ return ['div', {
58
+ style: convertToInlineCss(_objectSpread(_objectSpread({}, getGutterBaseStyle()), {}, {
59
+ padding: "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-150, 12px)", " ", "var(--ds-space-100, 8px)", " ", "var(--ds-space-100, 8px)")
60
+ })),
61
+ contenteditable: 'false'
62
+ }];
63
+ };
64
+ var getGutters = function getGutters(content, config, hideLineNumbers) {
65
+ if (!hideLineNumbers) {
66
+ return [getGuttersWithLineNumbers(content, config)];
67
+ }
68
+ if (config.allowCodeFolding) {
69
+ return [getFoldOnlyGutter()];
70
+ }
71
+ return [];
72
+ };
20
73
 
21
74
  // Based on: `packages/editor/editor-plugin-code-block/src/nodeviews/code-block.ts`
22
75
  var _toDOM = function toDOM(node, formattedAriaLabel, config) {
@@ -27,45 +80,26 @@ var _toDOM = function toDOM(node, formattedAriaLabel, config) {
27
80
  totalLineCount += (node.text.match(MATCH_NEWLINES) || []).length;
28
81
  }
29
82
  });
83
+ var hideLineNumbers = areCodeBlockLineNumbersHidden(node);
30
84
  var maxDigits = totalLineCount.toString().length;
31
85
  var content = node.textContent.split('\n').map(function (_, i) {
32
86
  return i + 1;
33
87
  }).join('\n');
88
+ var gutters = getGutters(content, config, hideLineNumbers);
34
89
  return ['pre', _objectSpread({
35
90
  class: codeBlockClassNames.container,
36
91
  style: "--lineNumberGutterWidth:".concat(maxDigits, "ch;"),
37
92
  'data-language': node.attrs.language || ''
38
- }, expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) && {
93
+ }, expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) && _objectSpread({
39
94
  'data-wrap': node.attrs.wrap ? 'true' : 'false'
40
- }), ['div', {
95
+ }, hideLineNumbers && {
96
+ 'data-hide-line-numbers': 'true'
97
+ })), ['div', {
41
98
  class: codeBlockClassNames.start,
42
99
  contenteditable: 'false'
43
100
  }], ['div', {
44
101
  class: codeBlockClassNames.contentWrapper
45
- }, ['div', {
46
- // Based on packages/editor/editor-common/src/styles/shared/code-block.ts
47
- // But we can't reuse that class as it adds a ::before that intefers with this approach
48
- style: convertToInlineCss({
49
- backgroundColor: "var(--ds-background-neutral, #0515240F)",
50
- position: 'relative',
51
- width: 'var(--lineNumberGutterWidth, 2rem)',
52
- /* top and bottom | left and right */
53
- padding: config.allowCodeFolding ? "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-250, 20px)", " ", "var(--ds-space-100, 8px)", " ", "var(--ds-space-075, 6px)") : "var(--ds-space-100, 8px)",
54
- flexShrink: 0,
55
- fontSize: getFontSize(),
56
- boxSizing: 'content-box'
57
- }),
58
- contenteditable: 'false'
59
- }, ['div', {
60
- class: 'code-block-gutter-pseudo-element',
61
- style: convertToInlineCss({
62
- textAlign: 'right',
63
- color: "var(--ds-text-subtlest, #6B6E76)",
64
- fontFamily: "var(--ds-font-family-code, \"Atlassian Mono\", ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)",
65
- whiteSpace: 'pre-wrap'
66
- }),
67
- 'data-label': content
68
- }]], ['div', {
102
+ }].concat(_toConsumableArray(gutters), [['div', {
69
103
  class: codeBlockClassNames.content
70
104
  }, ['code', _objectSpread({
71
105
  'data-language': node.attrs.language || '',
@@ -74,7 +108,7 @@ var _toDOM = function toDOM(node, formattedAriaLabel, config) {
74
108
  'aria-label': formattedAriaLabel
75
109
  }, fg('platform_editor_adf_with_localid') && {
76
110
  'data-local-id': node.attrs.localId
77
- }), 0]]], ['div', {
111
+ }), 0]]]), ['div', {
78
112
  class: codeBlockClassNames.end,
79
113
  contenteditable: 'false'
80
114
  }]];
@@ -1,3 +1,6 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1
4
  import { EditorView as CodeMirror } from '@codemirror/view';
2
5
  import { fg } from '@atlaskit/platform-feature-flags';
3
6
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
@@ -59,12 +62,18 @@ export var cmTheme = function cmTheme(options) {
59
62
  '.cm-gutter': {
60
63
  padding: "var(--ds-space-100, 8px)"
61
64
  },
62
- '.cm-gutters': {
65
+ '.cm-gutters': _objectSpread({
63
66
  backgroundColor: "var(--ds-background-neutral, #0515240F)",
64
67
  border: 'none',
65
68
  padding: "var(--ds-space-0, 0px)",
66
69
  color: "var(--ds-text-subtlest, #6B6E76)"
67
- },
70
+ }, expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) && {
71
+ // CodeMirror defaults this to height: 100%, which can resolve against an indefinite
72
+ // parent height in content-height editor and prevent flex stretching when gutter
73
+ // content is sparse, such as fold-only gutters.
74
+ height: 'unset',
75
+ alignSelf: 'stretch'
76
+ }),
68
77
  '.cm-lineNumbers .cm-gutterElement': {
69
78
  paddingLeft: "var(--ds-space-0, 0px)",
70
79
  paddingRight: "var(--ds-space-0, 0px)",
@@ -0,0 +1 @@
1
+ export { codeBlockAdvancedPlugin } from '../codeBlockAdvancedPlugin';
@@ -0,0 +1 @@
1
+ export type { CodeBlockAdvancedPlugin, CodeBlockAdvancedPluginOptions, } from '../codeBlockAdvancedPluginType';
@@ -16,6 +16,7 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
16
16
  private updating;
17
17
  private view;
18
18
  private lineWrappingCompartment;
19
+ private lineNumbersCompartment;
19
20
  private languageCompartment;
20
21
  private readOnlyCompartment;
21
22
  private pmDecorationsCompartment;
@@ -43,6 +44,11 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
43
44
  private updateLocalIdAttribute;
44
45
  private selectCodeBlockNode;
45
46
  private wordWrappingEnabled;
47
+ private lineNumbersHidden;
48
+ private selectCodeBlockNodeAndFocus;
49
+ private getLineNumberExtensions;
50
+ private getLineNumberVisibilityExtensions;
51
+ private getLineNumbersEffects;
46
52
  private getWordWrapEffects;
47
53
  private restoreFoldState;
48
54
  private applyContentModeTheme;
@@ -0,0 +1 @@
1
+ export { codeBlockAdvancedPlugin } from '../codeBlockAdvancedPlugin';
@@ -0,0 +1 @@
1
+ export type { CodeBlockAdvancedPlugin, CodeBlockAdvancedPluginOptions, } from '../codeBlockAdvancedPluginType';
@@ -16,6 +16,7 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
16
16
  private updating;
17
17
  private view;
18
18
  private lineWrappingCompartment;
19
+ private lineNumbersCompartment;
19
20
  private languageCompartment;
20
21
  private readOnlyCompartment;
21
22
  private pmDecorationsCompartment;
@@ -43,6 +44,11 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
43
44
  private updateLocalIdAttribute;
44
45
  private selectCodeBlockNode;
45
46
  private wordWrappingEnabled;
47
+ private lineNumbersHidden;
48
+ private selectCodeBlockNodeAndFocus;
49
+ private getLineNumberExtensions;
50
+ private getLineNumberVisibilityExtensions;
51
+ private getLineNumbersEffects;
46
52
  private getWordWrapEffects;
47
53
  private restoreFoldState;
48
54
  private applyContentModeTheme;
package/docs/0-intro.tsx CHANGED
@@ -20,7 +20,7 @@ ${createEditorUseOnlyNotice('Editor Plugin Code Block Advanced', [
20
20
  <AtlassianInternalWarning />
21
21
  </div>
22
22
  </>
23
- )}
23
+ )}
24
24
 
25
25
  This package includes the code block advanced plugin used by \`@atlaskit/editor-core\`.
26
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block-advanced",
3
- "version": "10.0.20",
3
+ "version": "10.1.1",
4
4
  "description": "CodeBlockAdvanced plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -30,15 +30,15 @@
30
30
  "dependencies": {
31
31
  "@atlaskit/adf-schema": "^52.11.0",
32
32
  "@atlaskit/code": "^17.5.0",
33
- "@atlaskit/editor-plugin-code-block": "^12.0.0",
34
- "@atlaskit/editor-plugin-editor-disabled": "^10.0.0",
35
- "@atlaskit/editor-plugin-find-replace": "^10.1.0",
36
- "@atlaskit/editor-plugin-selection": "^10.0.0",
37
- "@atlaskit/editor-plugin-selection-marker": "^10.1.0",
33
+ "@atlaskit/editor-plugin-code-block": "^12.1.0",
34
+ "@atlaskit/editor-plugin-editor-disabled": "^10.1.0",
35
+ "@atlaskit/editor-plugin-find-replace": "^10.2.0",
36
+ "@atlaskit/editor-plugin-selection": "^10.1.0",
37
+ "@atlaskit/editor-plugin-selection-marker": "^10.2.0",
38
38
  "@atlaskit/editor-prosemirror": "^7.3.0",
39
39
  "@atlaskit/platform-feature-flags": "^1.1.0",
40
40
  "@atlaskit/prosemirror-history": "^0.2.0",
41
- "@atlaskit/tmp-editor-statsig": "^80.0.0",
41
+ "@atlaskit/tmp-editor-statsig": "^80.3.0",
42
42
  "@atlaskit/tokens": "^13.0.0",
43
43
  "@babel/runtime": "^7.0.0",
44
44
  "@codemirror/autocomplete": "6.18.4",
@@ -55,7 +55,7 @@
55
55
  "codemirror-lang-elixir": "4.0.0"
56
56
  },
57
57
  "peerDependencies": {
58
- "@atlaskit/editor-common": "^114.30.0",
58
+ "@atlaskit/editor-common": "^114.32.0",
59
59
  "react": "^18.2.0",
60
60
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
61
61
  },
@@ -0,0 +1,2 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+ export { codeBlockAdvancedPlugin } from '../codeBlockAdvancedPlugin';
@@ -0,0 +1,5 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+ export type {
3
+ CodeBlockAdvancedPlugin,
4
+ CodeBlockAdvancedPluginOptions,
5
+ } from '../codeBlockAdvancedPluginType';
@@ -7,7 +7,10 @@ import type { ViewUpdate } from '@codemirror/view';
7
7
  import type { IntlShape } from 'react-intl';
8
8
 
9
9
  import { getBrowserInfo } from '@atlaskit/editor-common/browser';
10
- import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
10
+ import {
11
+ areCodeBlockLineNumbersHidden,
12
+ isCodeBlockWordWrapEnabled,
13
+ } from '@atlaskit/editor-common/code-block';
11
14
  import { messages as floatingToolbarMessages } from '@atlaskit/editor-common/floating-toolbar';
12
15
  import {
13
16
  blockTypeMessages,
@@ -68,6 +71,7 @@ class CodeBlockAdvancedNodeView implements NodeView {
68
71
  private updating: boolean;
69
72
  private view: EditorView;
70
73
  private lineWrappingCompartment = new Compartment();
74
+ private lineNumbersCompartment = new Compartment();
71
75
  private languageCompartment = new Compartment();
72
76
  private readOnlyCompartment = new Compartment();
73
77
  private pmDecorationsCompartment = new Compartment();
@@ -126,11 +130,6 @@ class CodeBlockAdvancedNodeView implements NodeView {
126
130
  const { formatMessage } = config.getIntl();
127
131
  const formattedAriaLabel = formatMessage(blockTypeMessages.codeblock);
128
132
 
129
- const selectNode = () => {
130
- this.selectCodeBlockNode(undefined);
131
- this.view.focus();
132
- };
133
-
134
133
  const isMacOS = getBrowserInfo().mac;
135
134
 
136
135
  this.cm = new CodeMirror({
@@ -161,16 +160,11 @@ class CodeBlockAdvancedNodeView implements NodeView {
161
160
  ),
162
161
  syntaxHighlighting(highlightStyle),
163
162
  bracketMatching(),
164
- lineNumbers({
165
- domEventHandlers: {
166
- click: () => {
167
- selectNode();
168
- return true;
169
- },
170
- },
171
- }),
172
- // Explicitly disable "sticky" positioning on line numbers to match
173
- // Renderer behaviour
163
+ expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true)
164
+ ? this.lineNumbersCompartment.of(this.getLineNumberVisibilityExtensions(node))
165
+ : this.getLineNumberExtensions(),
166
+ // Explicitly disable "sticky" positioning on all gutters to match
167
+ // Renderer behaviour.
174
168
  gutters({ fixed: false }),
175
169
  CodeMirror.updateListener.of((update) => this.forwardUpdate(update)),
176
170
  this.readOnlyCompartment.of([
@@ -207,7 +201,12 @@ class CodeBlockAdvancedNodeView implements NodeView {
207
201
  }),
208
202
  }),
209
203
  config.allowCodeFolding
210
- ? [foldGutterExtension({ selectNode, getNode: () => this.node })]
204
+ ? [
205
+ foldGutterExtension({
206
+ selectNode: this.selectCodeBlockNodeAndFocus,
207
+ getNode: () => this.node,
208
+ }),
209
+ ]
211
210
  : [],
212
211
  // With platform_editor_fix_advanced_codeblocks_crlf_patch the lineSeparatorExtension is not needed
213
212
  expValEquals('platform_editor_fix_advanced_codeblocks_crlf_patch', 'isEnabled', true)
@@ -293,6 +292,7 @@ class CodeBlockAdvancedNodeView implements NodeView {
293
292
  this.updateLanguage();
294
293
  this.updateLocalIdAttribute();
295
294
  this.wordWrappingEnabled = isCodeBlockWordWrapEnabled(node);
295
+ this.lineNumbersHidden = areCodeBlockLineNumbersHidden(node);
296
296
 
297
297
  // Restore fold state after initialization
298
298
  if (config.allowCodeFolding) {
@@ -405,6 +405,44 @@ class CodeBlockAdvancedNodeView implements NodeView {
405
405
  }
406
406
 
407
407
  private wordWrappingEnabled = false;
408
+ private lineNumbersHidden = false;
409
+
410
+ private selectCodeBlockNodeAndFocus = () => {
411
+ this.selectCodeBlockNode(undefined);
412
+ this.view.focus();
413
+ };
414
+
415
+ private getLineNumberExtensions(): Extension[] {
416
+ return [
417
+ lineNumbers({
418
+ domEventHandlers: {
419
+ click: () => {
420
+ this.selectCodeBlockNodeAndFocus();
421
+ return true;
422
+ },
423
+ },
424
+ }),
425
+ ];
426
+ }
427
+
428
+ private getLineNumberVisibilityExtensions(node: PMNode): Extension[] {
429
+ if (areCodeBlockLineNumbersHidden(node)) {
430
+ return [];
431
+ }
432
+
433
+ return this.getLineNumberExtensions();
434
+ }
435
+
436
+ private getLineNumbersEffects(node: PMNode) {
437
+ const lineNumbersHidden = areCodeBlockLineNumbersHidden(node);
438
+ if (this.lineNumbersHidden !== lineNumbersHidden) {
439
+ this.lineNumbersHidden = lineNumbersHidden;
440
+ return this.lineNumbersCompartment.reconfigure(
441
+ this.getLineNumberVisibilityExtensions(node),
442
+ );
443
+ }
444
+ return undefined;
445
+ }
408
446
 
409
447
  private getWordWrapEffects(node: PMNode) {
410
448
  if (this.wordWrappingEnabled !== isCodeBlockWordWrapEnabled(node)) {
@@ -455,11 +493,18 @@ class CodeBlockAdvancedNodeView implements NodeView {
455
493
  // Updates bundled for performance (to avoid multiple-dispatches)
456
494
  const changes = getCMSelectionChanges(curText, newText);
457
495
  const wordWrapEffect = this.getWordWrapEffects(node);
496
+ const lineNumbersEffect = expValEquals(
497
+ 'platform_editor_code_block_q4_lovability',
498
+ 'isEnabled',
499
+ true,
500
+ )
501
+ ? this.getLineNumbersEffects(node)
502
+ : undefined;
458
503
  const prosemirrorDecorationsEffect = this.getProseMirrorDecorationEffects(innerDecorations);
459
- if (changes || wordWrapEffect || prosemirrorDecorationsEffect) {
504
+ if (changes || wordWrapEffect || lineNumbersEffect || prosemirrorDecorationsEffect) {
460
505
  this.updating = true;
461
506
  this.cm.dispatch({
462
- effects: [wordWrapEffect, prosemirrorDecorationsEffect].filter(
507
+ effects: [wordWrapEffect, lineNumbersEffect, prosemirrorDecorationsEffect].filter(
463
508
  (effect): effect is StateEffect<unknown> => !!effect,
464
509
  ),
465
510
  changes,