@atlaskit/editor-plugin-code-block-advanced 2.2.1 → 2.2.3

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,22 @@
1
1
  # @atlaskit/editor-plugin-code-block-advanced
2
2
 
3
+ ## 2.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#142712](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/142712)
8
+ [`6eb10c572bdad`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6eb10c572bdad) -
9
+ [ux] Improve syntax highlighting for yaml.
10
+ - Updated dependencies
11
+
12
+ ## 2.2.2
13
+
14
+ ### Patch Changes
15
+
16
+ - [#139592](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/139592)
17
+ [`fe3dc07ed6ab8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/fe3dc07ed6ab8) -
18
+ Fixes a selection bug on chrome if there are multiple code blocks at the start of a document
19
+
3
20
  ## 2.2.1
4
21
 
5
22
  ### Patch Changes
@@ -14,6 +14,7 @@ var _language = require("@codemirror/language");
14
14
  var _state = require("@codemirror/state");
15
15
  var _view = require("@codemirror/view");
16
16
  var _codeBlock = require("@atlaskit/editor-common/code-block");
17
+ var _whitespace = require("@atlaskit/editor-common/whitespace");
17
18
  var _state2 = require("@atlaskit/editor-prosemirror/state");
18
19
  var _view2 = require("@atlaskit/editor-prosemirror/view");
19
20
  var _syntaxHighlightingTheme = require("../ui/syntaxHighlightingTheme");
@@ -80,8 +81,14 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
80
81
  }), (0, _manageSelectionMarker.manageSelectionMarker)(config.api), (0, _prosemirrorDecorations.prosemirrorDecorationPlugin)(this.pmFacet, view, getPos)])
81
82
  });
82
83
 
84
+ // We append an additional element that fixes a selection bug on chrome if the code block
85
+ // is the first element followed by subsequent code blocks
86
+ var spaceContainer = document.createElement('span');
87
+ spaceContainer.innerText = _whitespace.ZERO_WIDTH_SPACE;
88
+ spaceContainer.style.height = '0';
83
89
  // The editor's outer node is our DOM representation
84
90
  this.dom = this.cm.dom;
91
+ this.dom.appendChild(spaceContainer);
85
92
 
86
93
  // This flag is used to avoid an update loop between the outer and
87
94
  // inner editor
@@ -8,6 +8,8 @@ exports.LanguageLoader = void 0;
8
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _language = require("@codemirror/language");
12
+ var _syntaxHighlightingTheme = require("../../ui/syntaxHighlightingTheme");
11
13
  var _languageMap = require("./languageMap");
12
14
  /**
13
15
  * Manages loading the languages (for syntax highlighting, etc.)
@@ -37,7 +39,12 @@ var LanguageLoader = exports.LanguageLoader = /*#__PURE__*/function () {
37
39
  }
38
40
  language.load().then(function (lang) {
39
41
  if (lang) {
40
- _this.updateLanguageCompartment(lang);
42
+ var styling = (0, _syntaxHighlightingTheme.languageStyling)(lang.language);
43
+ if (styling) {
44
+ _this.updateLanguageCompartment([lang, (0, _language.syntaxHighlighting)(styling)]);
45
+ } else {
46
+ _this.updateLanguageCompartment(lang);
47
+ }
41
48
  _this.languageName = languageName;
42
49
  } else {
43
50
  configureEmpty();
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.highlightStyle = void 0;
6
+ exports.languageStyling = exports.highlightStyle = void 0;
7
7
  var _language = require("@codemirror/language");
8
8
  var _highlight = require("@lezer/highlight");
9
9
  // Based on `platform/packages/design-system/code/src/internal/theme/styles.tsx`
@@ -76,4 +76,28 @@ var highlightStyle = exports.highlightStyle = _language.HighlightStyle.define([{
76
76
  }, {
77
77
  tag: _highlight.tags.invalid,
78
78
  color: "var(--ds-text, #172B4D)"
79
- }]);
79
+ }]);
80
+
81
+ /**
82
+ * Prismjs (renderer) and codemirror (editor) tokenise slightly differently,
83
+ * Occasionally we may want to override tokens for certain languages to
84
+ * get closer to renderer.
85
+ *
86
+ * Note the way that codemirror works - these styles get added on top of the styling above
87
+ * (and override existing tags).
88
+ *
89
+ * @param language Codemirror language to scope the changes to a specific language
90
+ * @returns Highlight style which can be used with the syntax highlighting extension
91
+ */
92
+ var languageStyling = exports.languageStyling = function languageStyling(language) {
93
+ switch (language.name) {
94
+ case 'yaml':
95
+ return _language.HighlightStyle.define([{
96
+ tag: _highlight.tags.definition(_highlight.tags.propertyName),
97
+ color: "var(--ds-text-accent-green, #216E4E)",
98
+ fontWeight: "var(--ds-font-weight-bold, 700)"
99
+ }], {
100
+ scope: language
101
+ });
102
+ }
103
+ };
@@ -4,6 +4,7 @@ import { syntaxHighlighting, bracketMatching } from '@codemirror/language';
4
4
  import { Compartment, EditorSelection, Facet } from '@codemirror/state';
5
5
  import { EditorView as CodeMirror, lineNumbers, gutters } from '@codemirror/view';
6
6
  import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
7
+ import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
7
8
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
8
9
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
9
10
  import { highlightStyle } from '../ui/syntaxHighlightingTheme';
@@ -60,8 +61,14 @@ class CodeBlockAdvancedNodeView {
60
61
  }), manageSelectionMarker(config.api), prosemirrorDecorationPlugin(this.pmFacet, view, getPos)]
61
62
  });
62
63
 
64
+ // We append an additional element that fixes a selection bug on chrome if the code block
65
+ // is the first element followed by subsequent code blocks
66
+ const spaceContainer = document.createElement('span');
67
+ spaceContainer.innerText = ZERO_WIDTH_SPACE;
68
+ spaceContainer.style.height = '0';
63
69
  // The editor's outer node is our DOM representation
64
70
  this.dom = this.cm.dom;
71
+ this.dom.appendChild(spaceContainer);
65
72
 
66
73
  // This flag is used to avoid an update loop between the outer and
67
74
  // inner editor
@@ -1,4 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { syntaxHighlighting } from '@codemirror/language';
3
+ import { languageStyling } from '../../ui/syntaxHighlightingTheme';
2
4
  import { mapLanguageToCodeMirror } from './languageMap';
3
5
 
4
6
  /**
@@ -25,7 +27,12 @@ export class LanguageLoader {
25
27
  }
26
28
  language.load().then(lang => {
27
29
  if (lang) {
28
- this.updateLanguageCompartment(lang);
30
+ const styling = languageStyling(lang.language);
31
+ if (styling) {
32
+ this.updateLanguageCompartment([lang, syntaxHighlighting(styling)]);
33
+ } else {
34
+ this.updateLanguageCompartment(lang);
35
+ }
29
36
  this.languageName = languageName;
30
37
  } else {
31
38
  configureEmpty();
@@ -70,4 +70,28 @@ export const highlightStyle = HighlightStyle.define([{
70
70
  }, {
71
71
  tag: tags.invalid,
72
72
  color: "var(--ds-text, #172B4D)"
73
- }]);
73
+ }]);
74
+
75
+ /**
76
+ * Prismjs (renderer) and codemirror (editor) tokenise slightly differently,
77
+ * Occasionally we may want to override tokens for certain languages to
78
+ * get closer to renderer.
79
+ *
80
+ * Note the way that codemirror works - these styles get added on top of the styling above
81
+ * (and override existing tags).
82
+ *
83
+ * @param language Codemirror language to scope the changes to a specific language
84
+ * @returns Highlight style which can be used with the syntax highlighting extension
85
+ */
86
+ export const languageStyling = language => {
87
+ switch (language.name) {
88
+ case 'yaml':
89
+ return HighlightStyle.define([{
90
+ tag: tags.definition(tags.propertyName),
91
+ color: "var(--ds-text-accent-green, #216E4E)",
92
+ fontWeight: "var(--ds-font-weight-bold, 700)"
93
+ }], {
94
+ scope: language
95
+ });
96
+ }
97
+ };
@@ -7,6 +7,7 @@ import { syntaxHighlighting, bracketMatching } from '@codemirror/language';
7
7
  import { Compartment, EditorSelection, Facet } from '@codemirror/state';
8
8
  import { EditorView as CodeMirror, lineNumbers, gutters } from '@codemirror/view';
9
9
  import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
10
+ import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
10
11
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
11
12
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
12
13
  import { highlightStyle } from '../ui/syntaxHighlightingTheme';
@@ -73,8 +74,14 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
73
74
  }), manageSelectionMarker(config.api), prosemirrorDecorationPlugin(this.pmFacet, view, getPos)])
74
75
  });
75
76
 
77
+ // We append an additional element that fixes a selection bug on chrome if the code block
78
+ // is the first element followed by subsequent code blocks
79
+ var spaceContainer = document.createElement('span');
80
+ spaceContainer.innerText = ZERO_WIDTH_SPACE;
81
+ spaceContainer.style.height = '0';
76
82
  // The editor's outer node is our DOM representation
77
83
  this.dom = this.cm.dom;
84
+ this.dom.appendChild(spaceContainer);
78
85
 
79
86
  // This flag is used to avoid an update loop between the outer and
80
87
  // inner editor
@@ -1,6 +1,8 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ import { syntaxHighlighting } from '@codemirror/language';
5
+ import { languageStyling } from '../../ui/syntaxHighlightingTheme';
4
6
  import { mapLanguageToCodeMirror } from './languageMap';
5
7
 
6
8
  /**
@@ -31,7 +33,12 @@ export var LanguageLoader = /*#__PURE__*/function () {
31
33
  }
32
34
  language.load().then(function (lang) {
33
35
  if (lang) {
34
- _this.updateLanguageCompartment(lang);
36
+ var styling = languageStyling(lang.language);
37
+ if (styling) {
38
+ _this.updateLanguageCompartment([lang, syntaxHighlighting(styling)]);
39
+ } else {
40
+ _this.updateLanguageCompartment(lang);
41
+ }
35
42
  _this.languageName = languageName;
36
43
  } else {
37
44
  configureEmpty();
@@ -70,4 +70,28 @@ export var highlightStyle = HighlightStyle.define([{
70
70
  }, {
71
71
  tag: tags.invalid,
72
72
  color: "var(--ds-text, #172B4D)"
73
- }]);
73
+ }]);
74
+
75
+ /**
76
+ * Prismjs (renderer) and codemirror (editor) tokenise slightly differently,
77
+ * Occasionally we may want to override tokens for certain languages to
78
+ * get closer to renderer.
79
+ *
80
+ * Note the way that codemirror works - these styles get added on top of the styling above
81
+ * (and override existing tags).
82
+ *
83
+ * @param language Codemirror language to scope the changes to a specific language
84
+ * @returns Highlight style which can be used with the syntax highlighting extension
85
+ */
86
+ export var languageStyling = function languageStyling(language) {
87
+ switch (language.name) {
88
+ case 'yaml':
89
+ return HighlightStyle.define([{
90
+ tag: tags.definition(tags.propertyName),
91
+ color: "var(--ds-text-accent-green, #216E4E)",
92
+ fontWeight: "var(--ds-font-weight-bold, 700)"
93
+ }], {
94
+ scope: language
95
+ });
96
+ }
97
+ };
@@ -1,4 +1,5 @@
1
1
  import { LanguageSupport } from '@codemirror/language';
2
+ import type { Extension } from '@codemirror/state';
2
3
  /**
3
4
  * Manages loading the languages (for syntax highlighting, etc.)
4
5
  * from CodeMirror and updating the language in the CodeMirror view
@@ -6,6 +7,6 @@ import { LanguageSupport } from '@codemirror/language';
6
7
  export declare class LanguageLoader {
7
8
  private updateLanguageCompartment;
8
9
  private languageName;
9
- constructor(updateLanguageCompartment: (value: LanguageSupport | []) => void);
10
+ constructor(updateLanguageCompartment: (value: LanguageSupport | [LanguageSupport, Extension] | []) => void);
10
11
  updateLanguage(languageName: string): void;
11
12
  }
@@ -1,2 +1,14 @@
1
- import { HighlightStyle } from '@codemirror/language';
1
+ import { HighlightStyle, Language } from '@codemirror/language';
2
2
  export declare const highlightStyle: HighlightStyle;
3
+ /**
4
+ * Prismjs (renderer) and codemirror (editor) tokenise slightly differently,
5
+ * Occasionally we may want to override tokens for certain languages to
6
+ * get closer to renderer.
7
+ *
8
+ * Note the way that codemirror works - these styles get added on top of the styling above
9
+ * (and override existing tags).
10
+ *
11
+ * @param language Codemirror language to scope the changes to a specific language
12
+ * @returns Highlight style which can be used with the syntax highlighting extension
13
+ */
14
+ export declare const languageStyling: (language: Language) => HighlightStyle | undefined;
@@ -1,4 +1,5 @@
1
1
  import { LanguageSupport } from '@codemirror/language';
2
+ import type { Extension } from '@codemirror/state';
2
3
  /**
3
4
  * Manages loading the languages (for syntax highlighting, etc.)
4
5
  * from CodeMirror and updating the language in the CodeMirror view
@@ -7,6 +8,9 @@ export declare class LanguageLoader {
7
8
  private updateLanguageCompartment;
8
9
  private languageName;
9
10
  constructor(updateLanguageCompartment: (value: LanguageSupport | [
11
+ LanguageSupport,
12
+ Extension
13
+ ] | [
10
14
  ]) => void);
11
15
  updateLanguage(languageName: string): void;
12
16
  }
@@ -1,2 +1,14 @@
1
- import { HighlightStyle } from '@codemirror/language';
1
+ import { HighlightStyle, Language } from '@codemirror/language';
2
2
  export declare const highlightStyle: HighlightStyle;
3
+ /**
4
+ * Prismjs (renderer) and codemirror (editor) tokenise slightly differently,
5
+ * Occasionally we may want to override tokens for certain languages to
6
+ * get closer to renderer.
7
+ *
8
+ * Note the way that codemirror works - these styles get added on top of the styling above
9
+ * (and override existing tags).
10
+ *
11
+ * @param language Codemirror language to scope the changes to a specific language
12
+ * @returns Highlight style which can be used with the syntax highlighting extension
13
+ */
14
+ export declare const languageStyling: (language: Language) => HighlightStyle | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block-advanced",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
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": "^103.0.0",
37
- "@atlaskit/editor-plugin-code-block": "^4.2.0",
36
+ "@atlaskit/editor-common": "^103.9.0",
37
+ "@atlaskit/editor-plugin-code-block": "^4.4.0",
38
38
  "@atlaskit/editor-plugin-editor-disabled": "^2.0.0",
39
- "@atlaskit/editor-plugin-find-replace": "^2.0.0",
39
+ "@atlaskit/editor-plugin-find-replace": "^2.2.0",
40
40
  "@atlaskit/editor-plugin-selection": "^2.1.0",
41
- "@atlaskit/editor-plugin-selection-marker": "^2.1.0",
41
+ "@atlaskit/editor-plugin-selection-marker": "^2.2.0",
42
42
  "@atlaskit/editor-prosemirror": "7.0.0",
43
- "@atlaskit/tokens": "^4.7.0",
43
+ "@atlaskit/tokens": "^4.8.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@codemirror/autocomplete": "6.18.4",
46
46
  "@codemirror/commands": "6.7.1",
@@ -10,6 +10,7 @@ import type {
10
10
  getPosHandlerNode,
11
11
  ExtractInjectionAPI,
12
12
  } from '@atlaskit/editor-common/types';
13
+ import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
13
14
  import { EditorSelectionAPI } from '@atlaskit/editor-plugin-selection';
14
15
  import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
15
16
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
@@ -110,8 +111,14 @@ class CodeBlockAdvancedNodeView implements NodeView {
110
111
  ],
111
112
  });
112
113
 
114
+ // We append an additional element that fixes a selection bug on chrome if the code block
115
+ // is the first element followed by subsequent code blocks
116
+ const spaceContainer = document.createElement('span');
117
+ spaceContainer.innerText = ZERO_WIDTH_SPACE;
118
+ spaceContainer.style.height = '0';
113
119
  // The editor's outer node is our DOM representation
114
120
  this.dom = this.cm.dom;
121
+ this.dom.appendChild(spaceContainer);
115
122
 
116
123
  // This flag is used to avoid an update loop between the outer and
117
124
  // inner editor
@@ -1,4 +1,7 @@
1
- import { LanguageSupport } from '@codemirror/language';
1
+ import { LanguageSupport, syntaxHighlighting } from '@codemirror/language';
2
+ import type { Extension } from '@codemirror/state';
3
+
4
+ import { languageStyling } from '../../ui/syntaxHighlightingTheme';
2
5
 
3
6
  import { mapLanguageToCodeMirror } from './languageMap';
4
7
 
@@ -9,7 +12,11 @@ import { mapLanguageToCodeMirror } from './languageMap';
9
12
  export class LanguageLoader {
10
13
  private languageName: string = '';
11
14
 
12
- constructor(private updateLanguageCompartment: (value: LanguageSupport | []) => void) {}
15
+ constructor(
16
+ private updateLanguageCompartment: (
17
+ value: LanguageSupport | [LanguageSupport, Extension] | [],
18
+ ) => void,
19
+ ) {}
13
20
 
14
21
  updateLanguage(languageName: string) {
15
22
  if (languageName === this.languageName) {
@@ -31,7 +38,12 @@ export class LanguageLoader {
31
38
  .load()
32
39
  .then((lang) => {
33
40
  if (lang) {
34
- this.updateLanguageCompartment(lang);
41
+ const styling = languageStyling(lang.language);
42
+ if (styling) {
43
+ this.updateLanguageCompartment([lang, syntaxHighlighting(styling)]);
44
+ } else {
45
+ this.updateLanguageCompartment(lang);
46
+ }
35
47
  this.languageName = languageName;
36
48
  } else {
37
49
  configureEmpty();
@@ -1,4 +1,4 @@
1
- import { HighlightStyle } from '@codemirror/language';
1
+ import { HighlightStyle, Language } from '@codemirror/language';
2
2
  import { tags } from '@lezer/highlight';
3
3
 
4
4
  import { token } from '@atlaskit/tokens';
@@ -55,3 +55,32 @@ export const highlightStyle = HighlightStyle.define([
55
55
  { tag: tags.comment, color: token('color.text.subtlest'), fontStyle: 'italic' },
56
56
  { tag: tags.invalid, color: token('color.text') },
57
57
  ]);
58
+
59
+ /**
60
+ * Prismjs (renderer) and codemirror (editor) tokenise slightly differently,
61
+ * Occasionally we may want to override tokens for certain languages to
62
+ * get closer to renderer.
63
+ *
64
+ * Note the way that codemirror works - these styles get added on top of the styling above
65
+ * (and override existing tags).
66
+ *
67
+ * @param language Codemirror language to scope the changes to a specific language
68
+ * @returns Highlight style which can be used with the syntax highlighting extension
69
+ */
70
+ export const languageStyling = (language: Language): HighlightStyle | undefined => {
71
+ switch (language.name) {
72
+ case 'yaml':
73
+ return HighlightStyle.define(
74
+ [
75
+ {
76
+ tag: tags.definition(tags.propertyName),
77
+ color: token('color.text.accent.green'),
78
+ fontWeight: token('font.weight.bold'),
79
+ },
80
+ ],
81
+ {
82
+ scope: language,
83
+ },
84
+ );
85
+ }
86
+ };