@atlaskit/editor-plugin-code-block-advanced 2.2.8 → 2.2.10

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 (36) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/nodeviews/codeBlockAdvanced.js +34 -31
  3. package/dist/cjs/nodeviews/codemirrorSync/updateCMSelection.js +8 -10
  4. package/dist/cjs/nodeviews/extensions/manageSelectionMarker.js +1 -0
  5. package/dist/cjs/nodeviews/languages/loader.js +61 -29
  6. package/dist/cjs/ui/syntaxHighlightingTheme.js +8 -2
  7. package/dist/es2019/nodeviews/codeBlockAdvanced.js +21 -21
  8. package/dist/es2019/nodeviews/codemirrorSync/updateCMSelection.js +7 -9
  9. package/dist/es2019/nodeviews/extensions/manageSelectionMarker.js +1 -0
  10. package/dist/es2019/nodeviews/languages/loader.js +8 -5
  11. package/dist/es2019/ui/syntaxHighlightingTheme.js +8 -2
  12. package/dist/esm/nodeviews/codeBlockAdvanced.js +35 -32
  13. package/dist/esm/nodeviews/codemirrorSync/updateCMSelection.js +7 -9
  14. package/dist/esm/nodeviews/extensions/manageSelectionMarker.js +1 -0
  15. package/dist/esm/nodeviews/languages/loader.js +61 -29
  16. package/dist/esm/ui/syntaxHighlightingTheme.js +8 -2
  17. package/dist/types/nodeviews/codeBlockAdvanced.d.ts +5 -3
  18. package/dist/types/nodeviews/codemirrorSync/updateCMSelection.d.ts +3 -3
  19. package/dist/types/nodeviews/extensions/keymap/index.d.ts +1 -1
  20. package/dist/types/nodeviews/extensions/manageSelectionMarker.d.ts +3 -2
  21. package/dist/types/nodeviews/languages/loader.d.ts +1 -1
  22. package/dist/types/nodeviews/lazyCodeBlockAdvanced.d.ts +1 -1
  23. package/dist/types-ts4.5/nodeviews/codeBlockAdvanced.d.ts +5 -3
  24. package/dist/types-ts4.5/nodeviews/codemirrorSync/updateCMSelection.d.ts +3 -3
  25. package/dist/types-ts4.5/nodeviews/extensions/keymap/index.d.ts +1 -1
  26. package/dist/types-ts4.5/nodeviews/extensions/manageSelectionMarker.d.ts +3 -2
  27. package/dist/types-ts4.5/nodeviews/languages/loader.d.ts +1 -1
  28. package/dist/types-ts4.5/nodeviews/lazyCodeBlockAdvanced.d.ts +1 -1
  29. package/package.json +4 -4
  30. package/src/nodeviews/codeBlockAdvanced.ts +31 -28
  31. package/src/nodeviews/codemirrorSync/updateCMSelection.ts +8 -14
  32. package/src/nodeviews/extensions/keymap/index.ts +2 -2
  33. package/src/nodeviews/extensions/manageSelectionMarker.ts +3 -2
  34. package/src/nodeviews/languages/loader.ts +18 -17
  35. package/src/nodeviews/lazyCodeBlockAdvanced.ts +1 -1
  36. package/src/ui/syntaxHighlightingTheme.ts +9 -2
@@ -5,9 +5,9 @@
5
5
  *
6
6
  * @param curText string - the current CodeMirror text
7
7
  * @param newText string - the new CodeMirror text
8
- * @param updateCallback Callback to process the CodeMirror transaction
8
+ * @returns The changes or undefined if no change
9
9
  */
10
- export var updateCMSelection = function updateCMSelection(curText, newText, updateCallback) {
10
+ export var getCMSelectionChanges = function getCMSelectionChanges(curText, newText) {
11
11
  if (newText !== curText) {
12
12
  var start = 0,
13
13
  curEnd = curText.length,
@@ -19,12 +19,10 @@ export var updateCMSelection = function updateCMSelection(curText, newText, upda
19
19
  curEnd--;
20
20
  newEnd--;
21
21
  }
22
- updateCallback({
23
- changes: {
24
- from: start,
25
- to: curEnd,
26
- insert: newText.slice(start, newEnd)
27
- }
28
- });
22
+ return {
23
+ from: start,
24
+ to: curEnd,
25
+ insert: newText.slice(start, newEnd)
26
+ };
29
27
  }
30
28
  };
@@ -4,6 +4,7 @@ import { EditorView as CodeMirror } from '@codemirror/view';
4
4
  *
5
5
  * @param api
6
6
  * @returns CodeMirror Extension
7
+ * @example
7
8
  */
8
9
  export var manageSelectionMarker = function manageSelectionMarker(api) {
9
10
  var decoHide;
@@ -1,6 +1,8 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
1
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
3
  import _createClass from "@babel/runtime/helpers/createClass";
3
4
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
6
  import { syntaxHighlighting } from '@codemirror/language';
5
7
  import { languageStyling } from '../../ui/syntaxHighlightingTheme';
6
8
  import { mapLanguageToCodeMirror } from './languageMap';
@@ -17,35 +19,65 @@ export var LanguageLoader = /*#__PURE__*/function () {
17
19
  }
18
20
  return _createClass(LanguageLoader, [{
19
21
  key: "updateLanguage",
20
- value: function updateLanguage(languageName) {
21
- var _this = this;
22
- if (languageName === this.languageName) {
23
- return;
24
- }
25
- var language = mapLanguageToCodeMirror(languageName);
26
- var configureEmpty = function configureEmpty() {
27
- _this.updateLanguageCompartment([]);
28
- _this.languageName = '';
29
- };
30
- if (!language) {
31
- configureEmpty();
32
- return;
33
- }
34
- language.load().then(function (lang) {
35
- if (lang) {
36
- var styling = languageStyling(lang.language);
37
- if (styling) {
38
- _this.updateLanguageCompartment([lang, syntaxHighlighting(styling)]);
39
- } else {
40
- _this.updateLanguageCompartment(lang);
22
+ value: function () {
23
+ var _updateLanguage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(languageName) {
24
+ var _this = this;
25
+ var language, configureEmpty, lang, styling;
26
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
27
+ while (1) switch (_context.prev = _context.next) {
28
+ case 0:
29
+ if (!(languageName === this.languageName)) {
30
+ _context.next = 2;
31
+ break;
32
+ }
33
+ return _context.abrupt("return");
34
+ case 2:
35
+ language = mapLanguageToCodeMirror(languageName);
36
+ configureEmpty = function configureEmpty() {
37
+ if (_this.languageName) {
38
+ _this.updateLanguageCompartment([]);
39
+ }
40
+ _this.languageName = '';
41
+ };
42
+ if (language) {
43
+ _context.next = 7;
44
+ break;
45
+ }
46
+ configureEmpty();
47
+ return _context.abrupt("return");
48
+ case 7:
49
+ _context.prev = 7;
50
+ _context.next = 10;
51
+ return language.load();
52
+ case 10:
53
+ lang = _context.sent;
54
+ if (lang) {
55
+ styling = languageStyling(lang.language);
56
+ if (styling) {
57
+ this.updateLanguageCompartment([lang, syntaxHighlighting(styling)]);
58
+ } else {
59
+ this.updateLanguageCompartment(lang);
60
+ }
61
+ this.languageName = languageName;
62
+ } else {
63
+ configureEmpty();
64
+ }
65
+ _context.next = 17;
66
+ break;
67
+ case 14:
68
+ _context.prev = 14;
69
+ _context.t0 = _context["catch"](7);
70
+ configureEmpty();
71
+ case 17:
72
+ case "end":
73
+ return _context.stop();
41
74
  }
42
- _this.languageName = languageName;
43
- } else {
44
- configureEmpty();
45
- }
46
- }).catch(function () {
47
- configureEmpty();
48
- });
49
- }
75
+ }, _callee, this, [[7, 14]]);
76
+ }));
77
+ function updateLanguage(_x) {
78
+ return _updateLanguage.apply(this, arguments);
79
+ }
80
+ return updateLanguage;
81
+ }()
50
82
  }]);
51
83
  }();
@@ -34,11 +34,17 @@ export var highlightStyle = HighlightStyle.define([{
34
34
  tag: [tags.atom, tags.bool, tags.url, tags.contentSeparator, tags.labelName],
35
35
  color: "var(--ds-text-accent-blue, #0055CC)"
36
36
  }, {
37
- tag: [tags.literal, tags.inserted],
37
+ tag: [tags.literal],
38
38
  color: "var(--ds-text-accent-blue, #0055CC)"
39
39
  }, {
40
- tag: [tags.string, tags.deleted],
40
+ tag: tags.inserted,
41
41
  color: "var(--ds-text-accent-green, #216E4E)"
42
+ }, {
43
+ tag: [tags.string],
44
+ color: "var(--ds-text-accent-green, #216E4E)"
45
+ }, {
46
+ tag: [tags.deleted],
47
+ color: "var(--ds-text-accent-red, #AE2E24)"
42
48
  }, {
43
49
  tag: [tags.special(tags.string)],
44
50
  color: "var(--ds-text-accent-green, #216E4E)"
@@ -1,4 +1,4 @@
1
- import { Extension } from '@codemirror/state';
1
+ import { type Extension } from '@codemirror/state';
2
2
  import { ViewUpdate } from '@codemirror/view';
3
3
  import type { getPosHandler, getPosHandlerNode, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
4
  import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
@@ -32,14 +32,16 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
32
32
  private updateLanguage;
33
33
  private selectCodeBlockNode;
34
34
  private wordWrappingEnabled;
35
- private updateWordWrap;
35
+ private getWordWrapEffects;
36
36
  update(node: PMNode, _: readonly Decoration[], innerDecorations: DecorationSource): boolean;
37
37
  /**
38
38
  * Updates a facet which stores information on the prosemirror decorations
39
39
  *
40
40
  * This then gets translated to codemirror decorations in `prosemirrorDecorationPlugin`
41
+ * @param decorationSource
42
+ * @example
41
43
  */
42
- private updateProseMirrorDecorations;
44
+ private getProseMirrorDecorationEffects;
43
45
  private clearProseMirrorDecorations;
44
46
  stopEvent(e: Event): boolean;
45
47
  }
@@ -1,4 +1,4 @@
1
- import { TransactionSpec as CMTransactionSpec } from '@codemirror/state';
1
+ import { ChangeSpec } from '@codemirror/state';
2
2
  /**
3
3
  *
4
4
  * Compares the updated text with the current to determine the transaction to fire
@@ -6,6 +6,6 @@ import { TransactionSpec as CMTransactionSpec } from '@codemirror/state';
6
6
  *
7
7
  * @param curText string - the current CodeMirror text
8
8
  * @param newText string - the new CodeMirror text
9
- * @param updateCallback Callback to process the CodeMirror transaction
9
+ * @returns The changes or undefined if no change
10
10
  */
11
- export declare const updateCMSelection: (curText: string, newText: string, updateCallback: (value: CMTransactionSpec) => void) => void;
11
+ export declare const getCMSelectionChanges: (curText: string, newText: string) => ChangeSpec | undefined;
@@ -1,4 +1,4 @@
1
- import { Extension } from '@codemirror/state';
1
+ import { type Extension } from '@codemirror/state';
2
2
  import { RelativeSelectionPos } from '@atlaskit/editor-common/selection';
3
3
  import type { getPosHandlerNode } from '@atlaskit/editor-common/types';
4
4
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
@@ -1,10 +1,11 @@
1
- import { Extension } from '@codemirror/state';
1
+ import { type Extension } from '@codemirror/state';
2
2
  import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
- import { CodeBlockAdvancedPlugin } from '../../codeBlockAdvancedPluginType';
3
+ import type { CodeBlockAdvancedPlugin } from '../../codeBlockAdvancedPluginType';
4
4
  /**
5
5
  * Hides selection marker decoration when focused on codemirror editor and re-enables on blur
6
6
  *
7
7
  * @param api
8
8
  * @returns CodeMirror Extension
9
+ * @example
9
10
  */
10
11
  export declare const manageSelectionMarker: (api: ExtractInjectionAPI<CodeBlockAdvancedPlugin> | undefined) => Extension;
@@ -8,5 +8,5 @@ export declare class LanguageLoader {
8
8
  private updateLanguageCompartment;
9
9
  private languageName;
10
10
  constructor(updateLanguageCompartment: (value: LanguageSupport | [LanguageSupport, Extension] | []) => void);
11
- updateLanguage(languageName: string): void;
11
+ updateLanguage(languageName: string): Promise<void>;
12
12
  }
@@ -1,4 +1,4 @@
1
- import { Extension } from '@codemirror/state';
1
+ import { type Extension } from '@codemirror/state';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import type { CodeBlockAdvancedPlugin } from '../codeBlockAdvancedPluginType';
4
4
  interface Props {
@@ -1,4 +1,4 @@
1
- import { Extension } from '@codemirror/state';
1
+ import { type Extension } from '@codemirror/state';
2
2
  import { ViewUpdate } from '@codemirror/view';
3
3
  import type { getPosHandler, getPosHandlerNode, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
4
  import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
@@ -32,14 +32,16 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
32
32
  private updateLanguage;
33
33
  private selectCodeBlockNode;
34
34
  private wordWrappingEnabled;
35
- private updateWordWrap;
35
+ private getWordWrapEffects;
36
36
  update(node: PMNode, _: readonly Decoration[], innerDecorations: DecorationSource): boolean;
37
37
  /**
38
38
  * Updates a facet which stores information on the prosemirror decorations
39
39
  *
40
40
  * This then gets translated to codemirror decorations in `prosemirrorDecorationPlugin`
41
+ * @param decorationSource
42
+ * @example
41
43
  */
42
- private updateProseMirrorDecorations;
44
+ private getProseMirrorDecorationEffects;
43
45
  private clearProseMirrorDecorations;
44
46
  stopEvent(e: Event): boolean;
45
47
  }
@@ -1,4 +1,4 @@
1
- import { TransactionSpec as CMTransactionSpec } from '@codemirror/state';
1
+ import { ChangeSpec } from '@codemirror/state';
2
2
  /**
3
3
  *
4
4
  * Compares the updated text with the current to determine the transaction to fire
@@ -6,6 +6,6 @@ import { TransactionSpec as CMTransactionSpec } from '@codemirror/state';
6
6
  *
7
7
  * @param curText string - the current CodeMirror text
8
8
  * @param newText string - the new CodeMirror text
9
- * @param updateCallback Callback to process the CodeMirror transaction
9
+ * @returns The changes or undefined if no change
10
10
  */
11
- export declare const updateCMSelection: (curText: string, newText: string, updateCallback: (value: CMTransactionSpec) => void) => void;
11
+ export declare const getCMSelectionChanges: (curText: string, newText: string) => ChangeSpec | undefined;
@@ -1,4 +1,4 @@
1
- import { Extension } from '@codemirror/state';
1
+ import { type Extension } from '@codemirror/state';
2
2
  import { RelativeSelectionPos } from '@atlaskit/editor-common/selection';
3
3
  import type { getPosHandlerNode } from '@atlaskit/editor-common/types';
4
4
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
@@ -1,10 +1,11 @@
1
- import { Extension } from '@codemirror/state';
1
+ import { type Extension } from '@codemirror/state';
2
2
  import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
- import { CodeBlockAdvancedPlugin } from '../../codeBlockAdvancedPluginType';
3
+ import type { CodeBlockAdvancedPlugin } from '../../codeBlockAdvancedPluginType';
4
4
  /**
5
5
  * Hides selection marker decoration when focused on codemirror editor and re-enables on blur
6
6
  *
7
7
  * @param api
8
8
  * @returns CodeMirror Extension
9
+ * @example
9
10
  */
10
11
  export declare const manageSelectionMarker: (api: ExtractInjectionAPI<CodeBlockAdvancedPlugin> | undefined) => Extension;
@@ -12,5 +12,5 @@ export declare class LanguageLoader {
12
12
  Extension
13
13
  ] | [
14
14
  ]) => void);
15
- updateLanguage(languageName: string): void;
15
+ updateLanguage(languageName: string): Promise<void>;
16
16
  }
@@ -1,4 +1,4 @@
1
- import { Extension } from '@codemirror/state';
1
+ import { type Extension } from '@codemirror/state';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import type { CodeBlockAdvancedPlugin } from '../codeBlockAdvancedPluginType';
4
4
  interface Props {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block-advanced",
3
- "version": "2.2.8",
3
+ "version": "2.2.10",
4
4
  "description": "CodeBlockAdvanced plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,14 +33,14 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@atlaskit/adf-schema": "^47.6.0",
36
- "@atlaskit/editor-common": "^105.0.0",
36
+ "@atlaskit/editor-common": "^105.6.0",
37
37
  "@atlaskit/editor-plugin-code-block": "^4.4.0",
38
38
  "@atlaskit/editor-plugin-editor-disabled": "^2.0.0",
39
39
  "@atlaskit/editor-plugin-find-replace": "^2.2.0",
40
40
  "@atlaskit/editor-plugin-selection": "^2.2.0",
41
41
  "@atlaskit/editor-plugin-selection-marker": "^2.3.0",
42
42
  "@atlaskit/editor-prosemirror": "7.0.0",
43
- "@atlaskit/tokens": "^4.8.0",
43
+ "@atlaskit/tokens": "^4.9.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@codemirror/autocomplete": "6.18.4",
46
46
  "@codemirror/commands": "6.7.1",
@@ -57,7 +57,7 @@
57
57
  "react": "^18.2.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@atlaskit/code": "^17.1.0",
60
+ "@atlaskit/code": "^17.2.0",
61
61
  "typescript": "~5.4.2"
62
62
  },
63
63
  "techstack": {
@@ -2,10 +2,11 @@ import { closeBrackets } from '@codemirror/autocomplete';
2
2
  import { syntaxHighlighting, bracketMatching } from '@codemirror/language';
3
3
  import {
4
4
  Compartment,
5
- Extension,
5
+ type Extension,
6
6
  EditorSelection,
7
7
  Facet,
8
8
  EditorState as CodeMirrorState,
9
+ StateEffect,
9
10
  } from '@codemirror/state';
10
11
  import { EditorView as CodeMirror, lineNumbers, ViewUpdate, gutters } from '@codemirror/view';
11
12
 
@@ -17,7 +18,7 @@ import type {
17
18
  ExtractInjectionAPI,
18
19
  } from '@atlaskit/editor-common/types';
19
20
  import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
20
- import { EditorSelectionAPI } from '@atlaskit/editor-plugin-selection';
21
+ import { type EditorSelectionAPI } from '@atlaskit/editor-plugin-selection';
21
22
  import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
22
23
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
23
24
  import type {
@@ -33,7 +34,7 @@ import { highlightStyle } from '../ui/syntaxHighlightingTheme';
33
34
  import { cmTheme } from '../ui/theme';
34
35
 
35
36
  import { syncCMWithPM } from './codemirrorSync/syncCMWithPM';
36
- import { updateCMSelection } from './codemirrorSync/updateCMSelection';
37
+ import { getCMSelectionChanges } from './codemirrorSync/updateCMSelection';
37
38
  import { keymapExtension } from './extensions/keymap';
38
39
  import { manageSelectionMarker } from './extensions/manageSelectionMarker';
39
40
  import { prosemirrorDecorationPlugin } from './extensions/prosemirrorDecorations';
@@ -90,9 +91,11 @@ class CodeBlockAdvancedNodeView implements NodeView {
90
91
  doc: this.node.textContent,
91
92
  extensions: [
92
93
  ...config.extensions,
93
- this.lineWrappingCompartment.of([]),
94
+ this.lineWrappingCompartment.of(
95
+ isCodeBlockWordWrapEnabled(node) ? CodeMirror.lineWrapping : [],
96
+ ),
94
97
  this.languageCompartment.of([]),
95
- this.pmDecorationsCompartment.of([]),
98
+ this.pmDecorationsCompartment.of(this.pmFacet.compute([], () => innerDecorations)),
96
99
  keymapExtension({
97
100
  view,
98
101
  getPos,
@@ -133,8 +136,7 @@ class CodeBlockAdvancedNodeView implements NodeView {
133
136
  // inner editor
134
137
  this.updating = false;
135
138
  this.updateLanguage();
136
- this.updateWordWrap(node);
137
- this.updateProseMirrorDecorations(innerDecorations);
139
+ this.wordWrappingEnabled = isCodeBlockWordWrapEnabled(node);
138
140
  }
139
141
 
140
142
  destroy() {
@@ -194,19 +196,14 @@ class CodeBlockAdvancedNodeView implements NodeView {
194
196
 
195
197
  private wordWrappingEnabled = false;
196
198
 
197
- private updateWordWrap(node: PMNode) {
199
+ private getWordWrapEffects(node: PMNode) {
198
200
  if (this.wordWrappingEnabled !== isCodeBlockWordWrapEnabled(node)) {
199
- this.updating = true;
200
- this.cm.dispatch({
201
- effects: [
202
- this.lineWrappingCompartment.reconfigure(
203
- isCodeBlockWordWrapEnabled(node) ? CodeMirror.lineWrapping : [],
204
- ),
205
- ],
206
- });
207
- this.updating = false;
208
201
  this.wordWrappingEnabled = !this.wordWrappingEnabled;
202
+ return this.lineWrappingCompartment.reconfigure(
203
+ isCodeBlockWordWrapEnabled(node) ? CodeMirror.lineWrapping : [],
204
+ );
209
205
  }
206
+ return undefined;
210
207
  }
211
208
 
212
209
  update(node: PMNode, _: readonly Decoration[], innerDecorations: DecorationSource) {
@@ -215,7 +212,6 @@ class CodeBlockAdvancedNodeView implements NodeView {
215
212
  if (node.type !== this.node.type) {
216
213
  return false;
217
214
  }
218
- this.updateWordWrap(node);
219
215
  this.node = node;
220
216
  if (this.updating) {
221
217
  return true;
@@ -223,12 +219,21 @@ class CodeBlockAdvancedNodeView implements NodeView {
223
219
  this.updateLanguage();
224
220
  const newText = node.textContent,
225
221
  curText = this.cm.state.doc.toString();
226
- updateCMSelection(curText, newText, (tr) => {
222
+
223
+ // Updates bundled for performance (to avoid multiple-dispatches)
224
+ const changes = getCMSelectionChanges(curText, newText);
225
+ const wordWrapEffect = this.getWordWrapEffects(node);
226
+ const prosemirrorDecorationsEffect = this.getProseMirrorDecorationEffects(innerDecorations);
227
+ if (changes || wordWrapEffect || prosemirrorDecorationsEffect) {
227
228
  this.updating = true;
228
- this.cm.dispatch(tr);
229
+ this.cm.dispatch({
230
+ effects: [wordWrapEffect, prosemirrorDecorationsEffect].filter(
231
+ (effect): effect is StateEffect<unknown> => !!effect,
232
+ ),
233
+ changes,
234
+ });
229
235
  this.updating = false;
230
- });
231
- this.updateProseMirrorDecorations(innerDecorations);
236
+ }
232
237
  return true;
233
238
  }
234
239
 
@@ -236,14 +241,12 @@ class CodeBlockAdvancedNodeView implements NodeView {
236
241
  * Updates a facet which stores information on the prosemirror decorations
237
242
  *
238
243
  * This then gets translated to codemirror decorations in `prosemirrorDecorationPlugin`
244
+ * @param decorationSource
245
+ * @example
239
246
  */
240
- private updateProseMirrorDecorations(decorationSource: DecorationSource) {
241
- this.updating = true;
247
+ private getProseMirrorDecorationEffects(decorationSource: DecorationSource) {
242
248
  const computedFacet = this.pmFacet.compute([], () => decorationSource);
243
- this.cm.dispatch({
244
- effects: this.pmDecorationsCompartment.reconfigure(computedFacet),
245
- });
246
- this.updating = false;
249
+ return this.pmDecorationsCompartment.reconfigure(computedFacet);
247
250
  }
248
251
 
249
252
  private clearProseMirrorDecorations() {
@@ -1,4 +1,4 @@
1
- import { TransactionSpec as CMTransactionSpec } from '@codemirror/state';
1
+ import { ChangeSpec } from '@codemirror/state';
2
2
 
3
3
  /**
4
4
  *
@@ -7,13 +7,9 @@ import { TransactionSpec as CMTransactionSpec } from '@codemirror/state';
7
7
  *
8
8
  * @param curText string - the current CodeMirror text
9
9
  * @param newText string - the new CodeMirror text
10
- * @param updateCallback Callback to process the CodeMirror transaction
10
+ * @returns The changes or undefined if no change
11
11
  */
12
- export const updateCMSelection = (
13
- curText: string,
14
- newText: string,
15
- updateCallback: (value: CMTransactionSpec) => void,
16
- ) => {
12
+ export const getCMSelectionChanges = (curText: string, newText: string): ChangeSpec | undefined => {
17
13
  if (newText !== curText) {
18
14
  let start = 0,
19
15
  curEnd = curText.length,
@@ -29,12 +25,10 @@ export const updateCMSelection = (
29
25
  curEnd--;
30
26
  newEnd--;
31
27
  }
32
- updateCallback({
33
- changes: {
34
- from: start,
35
- to: curEnd,
36
- insert: newText.slice(start, newEnd),
37
- },
38
- });
28
+ return {
29
+ from: start,
30
+ to: curEnd,
31
+ insert: newText.slice(start, newEnd),
32
+ };
39
33
  }
40
34
  };
@@ -1,6 +1,6 @@
1
1
  import { defaultKeymap, indentWithTab } from '@codemirror/commands';
2
- import { Extension } from '@codemirror/state';
3
- import { KeyBinding, keymap as cmKeymap } from '@codemirror/view';
2
+ import { type Extension } from '@codemirror/state';
3
+ import { type KeyBinding, keymap as cmKeymap } from '@codemirror/view';
4
4
 
5
5
  import { browser } from '@atlaskit/editor-common/browser';
6
6
  import { RelativeSelectionPos } from '@atlaskit/editor-common/selection';
@@ -1,15 +1,16 @@
1
- import { Extension } from '@codemirror/state';
1
+ import { type Extension } from '@codemirror/state';
2
2
  import { EditorView as CodeMirror } from '@codemirror/view';
3
3
 
4
4
  import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
5
5
 
6
- import { CodeBlockAdvancedPlugin } from '../../codeBlockAdvancedPluginType';
6
+ import type { CodeBlockAdvancedPlugin } from '../../codeBlockAdvancedPluginType';
7
7
 
8
8
  /**
9
9
  * Hides selection marker decoration when focused on codemirror editor and re-enables on blur
10
10
  *
11
11
  * @param api
12
12
  * @returns CodeMirror Extension
13
+ * @example
13
14
  */
14
15
  export const manageSelectionMarker = (
15
16
  api: ExtractInjectionAPI<CodeBlockAdvancedPlugin> | undefined,
@@ -18,14 +18,16 @@ export class LanguageLoader {
18
18
  ) => void,
19
19
  ) {}
20
20
 
21
- updateLanguage(languageName: string) {
21
+ async updateLanguage(languageName: string) {
22
22
  if (languageName === this.languageName) {
23
23
  return;
24
24
  }
25
25
  const language = mapLanguageToCodeMirror(languageName);
26
26
 
27
27
  const configureEmpty = () => {
28
- this.updateLanguageCompartment([]);
28
+ if (this.languageName) {
29
+ this.updateLanguageCompartment([]);
30
+ }
29
31
  this.languageName = '';
30
32
  };
31
33
 
@@ -34,23 +36,22 @@ export class LanguageLoader {
34
36
  return;
35
37
  }
36
38
 
37
- language
38
- .load()
39
- .then((lang) => {
40
- if (lang) {
41
- const styling = languageStyling(lang.language);
42
- if (styling) {
43
- this.updateLanguageCompartment([lang, syntaxHighlighting(styling)]);
44
- } else {
45
- this.updateLanguageCompartment(lang);
46
- }
47
- this.languageName = languageName;
39
+ try {
40
+ const lang = await language.load();
41
+
42
+ if (lang) {
43
+ const styling = languageStyling(lang.language);
44
+ if (styling) {
45
+ this.updateLanguageCompartment([lang, syntaxHighlighting(styling)]);
48
46
  } else {
49
- configureEmpty();
47
+ this.updateLanguageCompartment(lang);
50
48
  }
51
- })
52
- .catch(() => {
49
+ this.languageName = languageName;
50
+ } else {
53
51
  configureEmpty();
54
- });
52
+ }
53
+ } catch (e) {
54
+ configureEmpty();
55
+ }
55
56
  }
56
57
  }
@@ -1,4 +1,4 @@
1
- import { Extension } from '@codemirror/state';
1
+ import { type Extension } from '@codemirror/state';
2
2
 
3
3
  import { withLazyLoading } from '@atlaskit/editor-common/lazy-node-view';
4
4
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
@@ -34,10 +34,17 @@ export const highlightStyle = HighlightStyle.define([
34
34
  color: token('color.text.accent.blue'),
35
35
  },
36
36
  {
37
- tag: [tags.literal, tags.inserted],
37
+ tag: [tags.literal],
38
38
  color: token('color.text.accent.blue'),
39
39
  },
40
- { tag: [tags.string, tags.deleted], color: token('color.text.accent.green') },
40
+ {
41
+ tag: tags.inserted,
42
+ color: token('color.text.accent.green')
43
+ },
44
+ { tag: [tags.string], color: token('color.text.accent.green') },
45
+ {
46
+ tag: [tags.deleted], color: token('color.text.accent.red')
47
+ },
41
48
  {
42
49
  tag: [tags.special(tags.string)],
43
50
  color: token('color.text.accent.green'),