@atlaskit/editor-plugin-code-block-advanced 1.0.0 → 1.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-code-block-advanced
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#102828](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/102828)
8
+ [`e9e0bd7d3c706`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e9e0bd7d3c706) -
9
+ [ux] Ensure lazy node view matches code block advanced snippet so there is no layout shift.
10
+
3
11
  ## 1.0.0
4
12
 
5
13
  ### Major Changes
@@ -0,0 +1,36 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.jira.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../tsDist/@atlaskit__editor-plugin-code-block-advanced/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*"
18
+ ],
19
+ "references": [
20
+ {
21
+ "path": "../../editor-common/afm-jira/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-plugin-code-block/afm-jira/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../editor-plugin-editor-disabled/afm-jira/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../editor-plugin-selection/afm-jira/tsconfig.json"
31
+ },
32
+ {
33
+ "path": "../../../design-system/tokens/afm-jira/tsconfig.json"
34
+ }
35
+ ]
36
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.post-office.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../post-office/tsDist/@atlaskit__editor-plugin-code-block-advanced/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*"
18
+ ],
19
+ "references": [
20
+ {
21
+ "path": "../../editor-common/afm-post-office/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-plugin-code-block/afm-post-office/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../editor-plugin-editor-disabled/afm-post-office/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../editor-plugin-selection/afm-post-office/tsconfig.json"
31
+ },
32
+ {
33
+ "path": "../../../design-system/tokens/afm-post-office/tsconfig.json"
34
+ }
35
+ ]
36
+ }
@@ -63,7 +63,12 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
63
63
  getNode: getNode,
64
64
  selectCodeBlockNode: this.selectCodeBlockNode.bind(this),
65
65
  onMaybeNodeSelection: onMaybeNodeSelection
66
- }), _theme.cmTheme, (0, _language.syntaxHighlighting)(_syntaxHighlightingTheme.highlightStyle), (0, _view.lineNumbers)(), _view.EditorView.updateListener.of(function (update) {
66
+ }), _theme.cmTheme, (0, _language.syntaxHighlighting)(_syntaxHighlightingTheme.highlightStyle), (0, _view.lineNumbers)(),
67
+ // Explicitly disable "sticky" positioning on line numbers to match
68
+ // Renderer behaviour
69
+ (0, _view.gutters)({
70
+ fixed: false
71
+ }), _view.EditorView.updateListener.of(function (update) {
67
72
  return _this.forwardUpdate(update);
68
73
  }), this.readOnlyCompartment.of(_view.EditorView.editable.of(this.view.editable)), (0, _autocomplete.closeBrackets)(), _view.EditorView.editorAttributes.of({
69
74
  class: 'code-block'
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.codeBlockNodeWithFixedToDOM = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _adfSchema = require("@atlaskit/adf-schema");
10
+ var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
10
11
  var _styles = require("@atlaskit/editor-common/styles");
11
12
  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; }
12
13
  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) { (0, _defineProperty2.default)(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; }
@@ -15,30 +16,58 @@ var codeBlockClassNames = {
15
16
  start: _styles.CodeBlockSharedCssClassName.CODEBLOCK_START,
16
17
  end: _styles.CodeBlockSharedCssClassName.CODEBLOCK_END,
17
18
  contentWrapper: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER,
18
- contentWrapped: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPED,
19
- gutter: _styles.CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER,
20
- content: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT,
21
- lineNumberWidget: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER_LINE_NUMBER_WIDGET
19
+ content: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT
22
20
  };
21
+ var MATCH_NEWLINES = new RegExp('\n', 'gu');
23
22
 
24
- // From: `packages/editor/editor-plugin-code-block/src/nodeviews/code-block.ts`
25
- var _toDOM = function toDOM(node, contentEditable, formattedAriaLabel) {
26
- return ['div', {
27
- class: codeBlockClassNames.container
23
+ // Based on: `packages/editor/editor-plugin-code-block/src/nodeviews/code-block.ts`
24
+ var _toDOM = function toDOM(node, formattedAriaLabel) {
25
+ var totalLineCount = 1;
26
+ node.forEach(function (node) {
27
+ var text = node.text;
28
+ if (text) {
29
+ totalLineCount += (node.text.match(MATCH_NEWLINES) || []).length;
30
+ }
31
+ });
32
+ var maxDigits = totalLineCount.toString().length;
33
+ var content = node.textContent.split('\n').map(function (_, i) {
34
+ return i + 1;
35
+ }).join('\n');
36
+ return ['pre', {
37
+ class: codeBlockClassNames.container,
38
+ style: "--lineNumberGutterWidth:".concat(maxDigits, "ch;"),
39
+ 'data-language': node.attrs.language || ''
28
40
  }, ['div', {
29
41
  class: codeBlockClassNames.start,
30
42
  contenteditable: 'false'
31
43
  }], ['div', {
32
44
  class: codeBlockClassNames.contentWrapper
33
45
  }, ['div', {
34
- class: codeBlockClassNames.gutter,
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: (0, _lazyNodeView.convertToInlineCss)({
49
+ backgroundColor: "var(--ds-background-neutral, #091E420F)",
50
+ position: 'relative',
51
+ width: 'var(--lineNumberGutterWidth, 2rem)',
52
+ padding: "var(--ds-space-100, 8px)",
53
+ flexShrink: 0,
54
+ fontSize: '0.875rem',
55
+ boxSizing: 'content-box'
56
+ }),
35
57
  contenteditable: 'false'
36
- }], ['div', {
58
+ }, ['div', {
59
+ class: 'code-block-gutter-pseudo-element',
60
+ style: (0, _lazyNodeView.convertToInlineCss)({
61
+ textAlign: 'right',
62
+ color: "var(--ds-text-subtlest, #626F86)",
63
+ fontFamily: "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)"
64
+ }),
65
+ 'data-label': content
66
+ }]], ['div', {
37
67
  class: codeBlockClassNames.content
38
68
  }, ['code', {
39
69
  'data-language': node.attrs.language || '',
40
70
  spellcheck: 'false',
41
- contenteditable: contentEditable ? 'true' : 'false',
42
71
  'data-testid': 'code-block--code',
43
72
  'aria-label': formattedAriaLabel
44
73
  }, 0]]], ['div', {
@@ -49,7 +78,7 @@ var _toDOM = function toDOM(node, contentEditable, formattedAriaLabel) {
49
78
  var codeBlockNodeWithFixedToDOM = exports.codeBlockNodeWithFixedToDOM = function codeBlockNodeWithFixedToDOM() {
50
79
  return _objectSpread(_objectSpread({}, _adfSchema.codeBlock), {}, {
51
80
  toDOM: function toDOM(node) {
52
- return _toDOM(node, false, '');
81
+ return _toDOM(node, '');
53
82
  }
54
83
  });
55
84
  };
@@ -46,8 +46,11 @@ var highlightStyle = exports.highlightStyle = _language.HighlightStyle.define([{
46
46
  tag: [_highlight.tags.string, _highlight.tags.deleted],
47
47
  color: "var(--ds-text-accent-green, #216E4E)"
48
48
  }, {
49
- tag: [_highlight.tags.regexp, _highlight.tags.escape, _highlight.tags.special(_highlight.tags.string)],
50
- color: "var(--ds-text, #172B4D)"
49
+ tag: [_highlight.tags.special(_highlight.tags.string)],
50
+ color: "var(--ds-text-accent-green, #216E4E)"
51
+ }, {
52
+ tag: [_highlight.tags.regexp, _highlight.tags.escape],
53
+ color: "var(--ds-text-accent-teal, #206A83)"
51
54
  }, {
52
55
  tag: _highlight.tags.definition(_highlight.tags.variableName),
53
56
  color: "var(--ds-text, #172B4D)"
@@ -11,7 +11,6 @@ var cmTheme = exports.cmTheme = _view.EditorView.theme({
11
11
  padding: '0',
12
12
  marginTop: "var(--ds-space-100, 8px)",
13
13
  marginBottom: "var(--ds-space-100, 8px)",
14
- borderRadius: "var(--ds-border-radius, 4px)",
15
14
  fontSize: '0.875rem',
16
15
  // Custom syntax styling to match existing styling
17
16
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
@@ -37,7 +36,8 @@ var cmTheme = exports.cmTheme = _view.EditorView.theme({
37
36
  // Custom syntax styling to match existing styling
38
37
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
39
38
  lineHeight: 'unset',
40
- fontFamily: "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)"
39
+ fontFamily: "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)",
40
+ borderRadius: "var(--ds-border-radius, 4px)"
41
41
  },
42
42
  '&.cm-focused .cm-cursor': {
43
43
  borderLeftColor: "var(--ds-text, #172B4D)"
@@ -45,7 +45,8 @@ var cmTheme = exports.cmTheme = _view.EditorView.theme({
45
45
  '.cm-gutters': {
46
46
  backgroundColor: "var(--ds-background-neutral, #091E420F)",
47
47
  border: 'none',
48
- padding: "var(--ds-space-100, 8px)"
48
+ padding: "var(--ds-space-100, 8px)",
49
+ color: "var(--ds-text-subtlest, #626F86)"
49
50
  },
50
51
  '.cm-lineNumbers .cm-gutterElement': {
51
52
  paddingLeft: "var(--ds-space-0, 0px)",
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { closeBrackets } from '@codemirror/autocomplete';
3
3
  import { syntaxHighlighting } from '@codemirror/language';
4
4
  import { Compartment, EditorSelection } from '@codemirror/state';
5
- import { EditorView as CodeMirror, lineNumbers } from '@codemirror/view';
5
+ import { EditorView as CodeMirror, lineNumbers, gutters } from '@codemirror/view';
6
6
  import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
7
7
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
8
8
  import { highlightStyle } from '../ui/syntaxHighlightingTheme';
@@ -46,7 +46,12 @@ class CodeBlockAdvancedNodeView {
46
46
  getNode,
47
47
  selectCodeBlockNode: this.selectCodeBlockNode.bind(this),
48
48
  onMaybeNodeSelection
49
- }), cmTheme, syntaxHighlighting(highlightStyle), lineNumbers(), CodeMirror.updateListener.of(update => this.forwardUpdate(update)), this.readOnlyCompartment.of(CodeMirror.editable.of(this.view.editable)), closeBrackets(), CodeMirror.editorAttributes.of({
49
+ }), cmTheme, syntaxHighlighting(highlightStyle), lineNumbers(),
50
+ // Explicitly disable "sticky" positioning on line numbers to match
51
+ // Renderer behaviour
52
+ gutters({
53
+ fixed: false
54
+ }), CodeMirror.updateListener.of(update => this.forwardUpdate(update)), this.readOnlyCompartment.of(CodeMirror.editable.of(this.view.editable)), closeBrackets(), CodeMirror.editorAttributes.of({
50
55
  class: 'code-block'
51
56
  }), bidiCharWarningExtension]
52
57
  });
@@ -1,42 +1,71 @@
1
1
  import { codeBlock } from '@atlaskit/adf-schema';
2
+ import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
2
3
  import { CodeBlockSharedCssClassName } from '@atlaskit/editor-common/styles';
3
4
  const codeBlockClassNames = {
4
5
  container: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER,
5
6
  start: CodeBlockSharedCssClassName.CODEBLOCK_START,
6
7
  end: CodeBlockSharedCssClassName.CODEBLOCK_END,
7
8
  contentWrapper: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER,
8
- contentWrapped: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPED,
9
- gutter: CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER,
10
- content: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT,
11
- lineNumberWidget: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER_LINE_NUMBER_WIDGET
9
+ content: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT
12
10
  };
11
+ const MATCH_NEWLINES = new RegExp('\n', 'gu');
13
12
 
14
- // From: `packages/editor/editor-plugin-code-block/src/nodeviews/code-block.ts`
15
- const toDOM = (node, contentEditable, formattedAriaLabel) => ['div', {
16
- class: codeBlockClassNames.container
17
- }, ['div', {
18
- class: codeBlockClassNames.start,
19
- contenteditable: 'false'
20
- }], ['div', {
21
- class: codeBlockClassNames.contentWrapper
22
- }, ['div', {
23
- class: codeBlockClassNames.gutter,
24
- contenteditable: 'false'
25
- }], ['div', {
26
- class: codeBlockClassNames.content
27
- }, ['code', {
28
- 'data-language': node.attrs.language || '',
29
- spellcheck: 'false',
30
- contenteditable: contentEditable ? 'true' : 'false',
31
- 'data-testid': 'code-block--code',
32
- 'aria-label': formattedAriaLabel
33
- }, 0]]], ['div', {
34
- class: codeBlockClassNames.end,
35
- contenteditable: 'false'
36
- }]];
13
+ // Based on: `packages/editor/editor-plugin-code-block/src/nodeviews/code-block.ts`
14
+ const toDOM = (node, formattedAriaLabel) => {
15
+ let totalLineCount = 1;
16
+ node.forEach(node => {
17
+ const text = node.text;
18
+ if (text) {
19
+ totalLineCount += (node.text.match(MATCH_NEWLINES) || []).length;
20
+ }
21
+ });
22
+ const maxDigits = totalLineCount.toString().length;
23
+ const content = node.textContent.split('\n').map((_, i) => i + 1).join('\n');
24
+ return ['pre', {
25
+ class: codeBlockClassNames.container,
26
+ style: `--lineNumberGutterWidth:${maxDigits}ch;`,
27
+ 'data-language': node.attrs.language || ''
28
+ }, ['div', {
29
+ class: codeBlockClassNames.start,
30
+ contenteditable: 'false'
31
+ }], ['div', {
32
+ class: codeBlockClassNames.contentWrapper
33
+ }, ['div', {
34
+ // Based on packages/editor/editor-common/src/styles/shared/code-block.ts
35
+ // But we can't reuse that class as it adds a ::before that intefers with this approach
36
+ style: convertToInlineCss({
37
+ backgroundColor: "var(--ds-background-neutral, #091E420F)",
38
+ position: 'relative',
39
+ width: 'var(--lineNumberGutterWidth, 2rem)',
40
+ padding: "var(--ds-space-100, 8px)",
41
+ flexShrink: 0,
42
+ fontSize: '0.875rem',
43
+ boxSizing: 'content-box'
44
+ }),
45
+ contenteditable: 'false'
46
+ }, ['div', {
47
+ class: 'code-block-gutter-pseudo-element',
48
+ style: convertToInlineCss({
49
+ textAlign: 'right',
50
+ color: "var(--ds-text-subtlest, #626F86)",
51
+ fontFamily: "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)"
52
+ }),
53
+ 'data-label': content
54
+ }]], ['div', {
55
+ class: codeBlockClassNames.content
56
+ }, ['code', {
57
+ 'data-language': node.attrs.language || '',
58
+ spellcheck: 'false',
59
+ 'data-testid': 'code-block--code',
60
+ 'aria-label': formattedAriaLabel
61
+ }, 0]]], ['div', {
62
+ class: codeBlockClassNames.end,
63
+ contenteditable: 'false'
64
+ }]];
65
+ };
37
66
  export const codeBlockNodeWithFixedToDOM = () => {
38
67
  return {
39
68
  ...codeBlock,
40
- toDOM: node => toDOM(node, false, '')
69
+ toDOM: node => toDOM(node, '')
41
70
  };
42
71
  };
@@ -40,8 +40,11 @@ export const highlightStyle = HighlightStyle.define([{
40
40
  tag: [tags.string, tags.deleted],
41
41
  color: "var(--ds-text-accent-green, #216E4E)"
42
42
  }, {
43
- tag: [tags.regexp, tags.escape, tags.special(tags.string)],
44
- color: "var(--ds-text, #172B4D)"
43
+ tag: [tags.special(tags.string)],
44
+ color: "var(--ds-text-accent-green, #216E4E)"
45
+ }, {
46
+ tag: [tags.regexp, tags.escape],
47
+ color: "var(--ds-text-accent-teal, #206A83)"
45
48
  }, {
46
49
  tag: tags.definition(tags.variableName),
47
50
  color: "var(--ds-text, #172B4D)"
@@ -5,7 +5,6 @@ export const cmTheme = CodeMirror.theme({
5
5
  padding: '0',
6
6
  marginTop: "var(--ds-space-100, 8px)",
7
7
  marginBottom: "var(--ds-space-100, 8px)",
8
- borderRadius: "var(--ds-border-radius, 4px)",
9
8
  fontSize: '0.875rem',
10
9
  // Custom syntax styling to match existing styling
11
10
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
@@ -31,7 +30,8 @@ export const cmTheme = CodeMirror.theme({
31
30
  // Custom syntax styling to match existing styling
32
31
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
33
32
  lineHeight: 'unset',
34
- fontFamily: "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)"
33
+ fontFamily: "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)",
34
+ borderRadius: "var(--ds-border-radius, 4px)"
35
35
  },
36
36
  '&.cm-focused .cm-cursor': {
37
37
  borderLeftColor: "var(--ds-text, #172B4D)"
@@ -39,7 +39,8 @@ export const cmTheme = CodeMirror.theme({
39
39
  '.cm-gutters': {
40
40
  backgroundColor: "var(--ds-background-neutral, #091E420F)",
41
41
  border: 'none',
42
- padding: "var(--ds-space-100, 8px)"
42
+ padding: "var(--ds-space-100, 8px)",
43
+ color: "var(--ds-text-subtlest, #626F86)"
43
44
  },
44
45
  '.cm-lineNumbers .cm-gutterElement': {
45
46
  paddingLeft: "var(--ds-space-0, 0px)",
@@ -5,7 +5,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
5
  import { closeBrackets } from '@codemirror/autocomplete';
6
6
  import { syntaxHighlighting } from '@codemirror/language';
7
7
  import { Compartment, EditorSelection } from '@codemirror/state';
8
- import { EditorView as CodeMirror, lineNumbers } from '@codemirror/view';
8
+ import { EditorView as CodeMirror, lineNumbers, gutters } from '@codemirror/view';
9
9
  import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
10
10
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
11
11
  import { highlightStyle } from '../ui/syntaxHighlightingTheme';
@@ -56,7 +56,12 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
56
56
  getNode: getNode,
57
57
  selectCodeBlockNode: this.selectCodeBlockNode.bind(this),
58
58
  onMaybeNodeSelection: onMaybeNodeSelection
59
- }), cmTheme, syntaxHighlighting(highlightStyle), lineNumbers(), CodeMirror.updateListener.of(function (update) {
59
+ }), cmTheme, syntaxHighlighting(highlightStyle), lineNumbers(),
60
+ // Explicitly disable "sticky" positioning on line numbers to match
61
+ // Renderer behaviour
62
+ gutters({
63
+ fixed: false
64
+ }), CodeMirror.updateListener.of(function (update) {
60
65
  return _this.forwardUpdate(update);
61
66
  }), this.readOnlyCompartment.of(CodeMirror.editable.of(this.view.editable)), closeBrackets(), CodeMirror.editorAttributes.of({
62
67
  class: 'code-block'
@@ -2,36 +2,65 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
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
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; }
4
4
  import { codeBlock } from '@atlaskit/adf-schema';
5
+ import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
5
6
  import { CodeBlockSharedCssClassName } from '@atlaskit/editor-common/styles';
6
7
  var codeBlockClassNames = {
7
8
  container: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER,
8
9
  start: CodeBlockSharedCssClassName.CODEBLOCK_START,
9
10
  end: CodeBlockSharedCssClassName.CODEBLOCK_END,
10
11
  contentWrapper: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER,
11
- contentWrapped: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPED,
12
- gutter: CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER,
13
- content: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT,
14
- lineNumberWidget: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER_LINE_NUMBER_WIDGET
12
+ content: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT
15
13
  };
14
+ var MATCH_NEWLINES = new RegExp('\n', 'gu');
16
15
 
17
- // From: `packages/editor/editor-plugin-code-block/src/nodeviews/code-block.ts`
18
- var _toDOM = function toDOM(node, contentEditable, formattedAriaLabel) {
19
- return ['div', {
20
- class: codeBlockClassNames.container
16
+ // Based on: `packages/editor/editor-plugin-code-block/src/nodeviews/code-block.ts`
17
+ var _toDOM = function toDOM(node, formattedAriaLabel) {
18
+ var totalLineCount = 1;
19
+ node.forEach(function (node) {
20
+ var text = node.text;
21
+ if (text) {
22
+ totalLineCount += (node.text.match(MATCH_NEWLINES) || []).length;
23
+ }
24
+ });
25
+ var maxDigits = totalLineCount.toString().length;
26
+ var content = node.textContent.split('\n').map(function (_, i) {
27
+ return i + 1;
28
+ }).join('\n');
29
+ return ['pre', {
30
+ class: codeBlockClassNames.container,
31
+ style: "--lineNumberGutterWidth:".concat(maxDigits, "ch;"),
32
+ 'data-language': node.attrs.language || ''
21
33
  }, ['div', {
22
34
  class: codeBlockClassNames.start,
23
35
  contenteditable: 'false'
24
36
  }], ['div', {
25
37
  class: codeBlockClassNames.contentWrapper
26
38
  }, ['div', {
27
- class: codeBlockClassNames.gutter,
39
+ // Based on packages/editor/editor-common/src/styles/shared/code-block.ts
40
+ // But we can't reuse that class as it adds a ::before that intefers with this approach
41
+ style: convertToInlineCss({
42
+ backgroundColor: "var(--ds-background-neutral, #091E420F)",
43
+ position: 'relative',
44
+ width: 'var(--lineNumberGutterWidth, 2rem)',
45
+ padding: "var(--ds-space-100, 8px)",
46
+ flexShrink: 0,
47
+ fontSize: '0.875rem',
48
+ boxSizing: 'content-box'
49
+ }),
28
50
  contenteditable: 'false'
29
- }], ['div', {
51
+ }, ['div', {
52
+ class: 'code-block-gutter-pseudo-element',
53
+ style: convertToInlineCss({
54
+ textAlign: 'right',
55
+ color: "var(--ds-text-subtlest, #626F86)",
56
+ fontFamily: "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)"
57
+ }),
58
+ 'data-label': content
59
+ }]], ['div', {
30
60
  class: codeBlockClassNames.content
31
61
  }, ['code', {
32
62
  'data-language': node.attrs.language || '',
33
63
  spellcheck: 'false',
34
- contenteditable: contentEditable ? 'true' : 'false',
35
64
  'data-testid': 'code-block--code',
36
65
  'aria-label': formattedAriaLabel
37
66
  }, 0]]], ['div', {
@@ -42,7 +71,7 @@ var _toDOM = function toDOM(node, contentEditable, formattedAriaLabel) {
42
71
  export var codeBlockNodeWithFixedToDOM = function codeBlockNodeWithFixedToDOM() {
43
72
  return _objectSpread(_objectSpread({}, codeBlock), {}, {
44
73
  toDOM: function toDOM(node) {
45
- return _toDOM(node, false, '');
74
+ return _toDOM(node, '');
46
75
  }
47
76
  });
48
77
  };
@@ -40,8 +40,11 @@ export var highlightStyle = HighlightStyle.define([{
40
40
  tag: [tags.string, tags.deleted],
41
41
  color: "var(--ds-text-accent-green, #216E4E)"
42
42
  }, {
43
- tag: [tags.regexp, tags.escape, tags.special(tags.string)],
44
- color: "var(--ds-text, #172B4D)"
43
+ tag: [tags.special(tags.string)],
44
+ color: "var(--ds-text-accent-green, #216E4E)"
45
+ }, {
46
+ tag: [tags.regexp, tags.escape],
47
+ color: "var(--ds-text-accent-teal, #206A83)"
45
48
  }, {
46
49
  tag: tags.definition(tags.variableName),
47
50
  color: "var(--ds-text, #172B4D)"
@@ -5,7 +5,6 @@ export var cmTheme = CodeMirror.theme({
5
5
  padding: '0',
6
6
  marginTop: "var(--ds-space-100, 8px)",
7
7
  marginBottom: "var(--ds-space-100, 8px)",
8
- borderRadius: "var(--ds-border-radius, 4px)",
9
8
  fontSize: '0.875rem',
10
9
  // Custom syntax styling to match existing styling
11
10
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
@@ -31,7 +30,8 @@ export var cmTheme = CodeMirror.theme({
31
30
  // Custom syntax styling to match existing styling
32
31
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
33
32
  lineHeight: 'unset',
34
- fontFamily: "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)"
33
+ fontFamily: "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)",
34
+ borderRadius: "var(--ds-border-radius, 4px)"
35
35
  },
36
36
  '&.cm-focused .cm-cursor': {
37
37
  borderLeftColor: "var(--ds-text, #172B4D)"
@@ -39,7 +39,8 @@ export var cmTheme = CodeMirror.theme({
39
39
  '.cm-gutters': {
40
40
  backgroundColor: "var(--ds-background-neutral, #091E420F)",
41
41
  border: 'none',
42
- padding: "var(--ds-space-100, 8px)"
42
+ padding: "var(--ds-space-100, 8px)",
43
+ color: "var(--ds-text-subtlest, #626F86)"
43
44
  },
44
45
  '.cm-lineNumbers .cm-gutterElement': {
45
46
  paddingLeft: "var(--ds-space-0, 0px)",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block-advanced",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "CodeBlockAdvanced plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,12 +33,12 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@atlaskit/adf-schema": "^46.1.0",
36
- "@atlaskit/editor-common": "^99.1.0",
36
+ "@atlaskit/editor-common": "^99.4.0",
37
37
  "@atlaskit/editor-plugin-code-block": "^3.5.0",
38
38
  "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
39
39
  "@atlaskit/editor-plugin-selection": "^1.6.0",
40
40
  "@atlaskit/editor-prosemirror": "6.2.1",
41
- "@atlaskit/tokens": "^3.0.0",
41
+ "@atlaskit/tokens": "^3.1.0",
42
42
  "@babel/runtime": "^7.0.0",
43
43
  "@codemirror/autocomplete": "6.18.4",
44
44
  "@codemirror/commands": "6.7.1",
@@ -1,7 +1,7 @@
1
1
  import { closeBrackets } from '@codemirror/autocomplete';
2
2
  import { syntaxHighlighting } from '@codemirror/language';
3
3
  import { Compartment, Extension, EditorSelection } from '@codemirror/state';
4
- import { EditorView as CodeMirror, lineNumbers, ViewUpdate } from '@codemirror/view';
4
+ import { EditorView as CodeMirror, lineNumbers, ViewUpdate, gutters } from '@codemirror/view';
5
5
 
6
6
  import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
7
7
  import { RelativeSelectionPos } from '@atlaskit/editor-common/selection';
@@ -81,6 +81,9 @@ class CodeBlockAdvancedNodeView implements NodeView {
81
81
  cmTheme,
82
82
  syntaxHighlighting(highlightStyle),
83
83
  lineNumbers(),
84
+ // Explicitly disable "sticky" positioning on line numbers to match
85
+ // Renderer behaviour
86
+ gutters({ fixed: false }),
84
87
  CodeMirror.updateListener.of((update) => this.forwardUpdate(update)),
85
88
  this.readOnlyCompartment.of(CodeMirror.editable.of(this.view.editable)),
86
89
  closeBrackets(),
@@ -1,59 +1,103 @@
1
1
  import { codeBlock } from '@atlaskit/adf-schema';
2
+ import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
2
3
  import { CodeBlockSharedCssClassName } from '@atlaskit/editor-common/styles';
3
4
  import type { NodeSpec, DOMOutputSpec, Node } from '@atlaskit/editor-prosemirror/model';
5
+ import { token } from '@atlaskit/tokens';
4
6
 
5
7
  const codeBlockClassNames = {
6
8
  container: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER,
7
9
  start: CodeBlockSharedCssClassName.CODEBLOCK_START,
8
10
  end: CodeBlockSharedCssClassName.CODEBLOCK_END,
9
11
  contentWrapper: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER,
10
- contentWrapped: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPED,
11
- gutter: CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER,
12
12
  content: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT,
13
- lineNumberWidget: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER_LINE_NUMBER_WIDGET,
14
13
  };
15
14
 
16
- // From: `packages/editor/editor-plugin-code-block/src/nodeviews/code-block.ts`
17
- const toDOM = (node: Node, contentEditable: boolean, formattedAriaLabel: string): DOMOutputSpec => [
18
- 'div',
19
- { class: codeBlockClassNames.container },
20
- ['div', { class: codeBlockClassNames.start, contenteditable: 'false' }],
21
- [
22
- 'div',
15
+ const MATCH_NEWLINES = new RegExp('\n', 'gu');
16
+
17
+ // Based on: `packages/editor/editor-plugin-code-block/src/nodeviews/code-block.ts`
18
+ const toDOM = (node: Node, formattedAriaLabel: string): DOMOutputSpec => {
19
+ let totalLineCount = 1;
20
+
21
+ node.forEach((node) => {
22
+ const text = node.text;
23
+ if (text) {
24
+ totalLineCount += (node.text.match(MATCH_NEWLINES) || []).length;
25
+ }
26
+ });
27
+
28
+ const maxDigits = totalLineCount.toString().length;
29
+
30
+ const content = node.textContent
31
+ .split('\n')
32
+ .map((_, i) => i + 1)
33
+ .join('\n');
34
+
35
+ return [
36
+ 'pre',
23
37
  {
24
- class: codeBlockClassNames.contentWrapper,
38
+ class: codeBlockClassNames.container,
39
+ style: `--lineNumberGutterWidth:${maxDigits}ch;`,
40
+ 'data-language': node.attrs.language || '',
25
41
  },
42
+ ['div', { class: codeBlockClassNames.start, contenteditable: 'false' }],
26
43
  [
27
44
  'div',
28
45
  {
29
- class: codeBlockClassNames.gutter,
30
- contenteditable: 'false',
31
- },
32
- ],
33
- [
34
- 'div',
35
- {
36
- class: codeBlockClassNames.content,
46
+ class: codeBlockClassNames.contentWrapper,
37
47
  },
38
48
  [
39
- 'code',
49
+ 'div',
40
50
  {
41
- 'data-language': node.attrs.language || '',
42
- spellcheck: 'false',
43
- contenteditable: contentEditable ? 'true' : 'false',
44
- 'data-testid': 'code-block--code',
45
- 'aria-label': formattedAriaLabel,
51
+ // Based on packages/editor/editor-common/src/styles/shared/code-block.ts
52
+ // But we can't reuse that class as it adds a ::before that intefers with this approach
53
+ style: convertToInlineCss({
54
+ backgroundColor: token('color.background.neutral'),
55
+ position: 'relative',
56
+ width: 'var(--lineNumberGutterWidth, 2rem)',
57
+ padding: token('space.100'),
58
+ flexShrink: 0,
59
+ fontSize: '0.875rem',
60
+ boxSizing: 'content-box',
61
+ }),
62
+ contenteditable: 'false',
46
63
  },
47
- 0,
64
+ [
65
+ 'div',
66
+ {
67
+ class: 'code-block-gutter-pseudo-element',
68
+ style: convertToInlineCss({
69
+ textAlign: 'right',
70
+ color: token('color.text.subtlest'),
71
+ fontFamily: token('font.family.code'),
72
+ }),
73
+ 'data-label': content,
74
+ },
75
+ ],
76
+ ],
77
+ [
78
+ 'div',
79
+ {
80
+ class: codeBlockClassNames.content,
81
+ },
82
+ [
83
+ 'code',
84
+ {
85
+ 'data-language': node.attrs.language || '',
86
+ spellcheck: 'false',
87
+ 'data-testid': 'code-block--code',
88
+ 'aria-label': formattedAriaLabel,
89
+ },
90
+ 0,
91
+ ],
48
92
  ],
49
93
  ],
50
- ],
51
- ['div', { class: codeBlockClassNames.end, contenteditable: 'false' }],
52
- ];
94
+ ['div', { class: codeBlockClassNames.end, contenteditable: 'false' }],
95
+ ];
96
+ };
53
97
 
54
98
  export const codeBlockNodeWithFixedToDOM = (): NodeSpec => {
55
99
  return {
56
100
  ...codeBlock,
57
- toDOM: (node) => toDOM(node, false, ''),
101
+ toDOM: (node) => toDOM(node, ''),
58
102
  };
59
103
  };
@@ -5,7 +5,6 @@ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
5
5
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
 
8
-
9
8
  import type { CodeBlockAdvancedPlugin } from '../codeBlockAdvancedPluginType';
10
9
 
11
10
  interface Props {
@@ -38,7 +38,14 @@ export const highlightStyle = HighlightStyle.define([
38
38
  color: token('color.text.accent.blue'),
39
39
  },
40
40
  { tag: [tags.string, tags.deleted], color: token('color.text.accent.green') },
41
- { tag: [tags.regexp, tags.escape, tags.special(tags.string)], color: token('color.text') },
41
+ {
42
+ tag: [tags.special(tags.string)],
43
+ color: token('color.text.accent.green'),
44
+ },
45
+ {
46
+ tag: [tags.regexp, tags.escape],
47
+ color: token('color.text.accent.teal'),
48
+ },
42
49
  { tag: tags.definition(tags.variableName), color: token('color.text') },
43
50
  { tag: tags.local(tags.variableName), color: token('color.text') },
44
51
  { tag: [tags.typeName, tags.namespace], color: token('color.text.accent.blue') },
package/src/ui/theme.ts CHANGED
@@ -8,7 +8,6 @@ export const cmTheme = CodeMirror.theme({
8
8
  padding: '0',
9
9
  marginTop: token('space.100'),
10
10
  marginBottom: token('space.100'),
11
- borderRadius: token('border.radius'),
12
11
  fontSize: '0.875rem',
13
12
  // Custom syntax styling to match existing styling
14
13
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
@@ -35,6 +34,7 @@ export const cmTheme = CodeMirror.theme({
35
34
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
36
35
  lineHeight: 'unset',
37
36
  fontFamily: token('font.family.code'),
37
+ borderRadius: token('border.radius'),
38
38
  },
39
39
  '&.cm-focused .cm-cursor': {
40
40
  borderLeftColor: token('color.text'),
@@ -43,6 +43,7 @@ export const cmTheme = CodeMirror.theme({
43
43
  backgroundColor: token('color.background.neutral'),
44
44
  border: 'none',
45
45
  padding: token('space.100'),
46
+ color: token('color.text.subtlest'),
46
47
  },
47
48
  '.cm-lineNumbers .cm-gutterElement': {
48
49
  paddingLeft: token('space.0'),
@@ -0,0 +1,53 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["./src/**/*.ts", "./src/**/*.tsx"],
4
+ "exclude": [
5
+ "**/docs/**/*",
6
+ "**/__tests__/**/*",
7
+ "**/vr-tests/**/*",
8
+ "**/__perf__/**/*",
9
+ "**/*.test.*",
10
+ "**/test.*",
11
+ "**/test-*",
12
+ "**/examples.ts",
13
+ "**/examples.tsx",
14
+ "**/examples/*.ts",
15
+ "**/examples/*.tsx",
16
+ "**/examples/**/*.ts",
17
+ "**/examples/**/*.tsx",
18
+ "**/storybook/**/*",
19
+ "**/constellation/**/*",
20
+ ".storybook/*",
21
+ "./__fixtures__/**/*",
22
+ "./__generated__/**/*",
23
+ "./mocks/**/*",
24
+ "./__mocks__/**/*",
25
+ "**/mock.*",
26
+ "**/codemods/**/*.ts",
27
+ "**/codemods/**/*.tsx"
28
+ ],
29
+ "compilerOptions": {
30
+ "composite": true,
31
+ "outDir": "../../../tsDist/@atlaskit__editor-plugin-code-block-advanced/app"
32
+ },
33
+ "references": [
34
+ {
35
+ "path": "../../design-system/code/tsconfig.app.json"
36
+ },
37
+ {
38
+ "path": "../editor-common/tsconfig.app.json"
39
+ },
40
+ {
41
+ "path": "../editor-plugin-code-block/tsconfig.app.json"
42
+ },
43
+ {
44
+ "path": "../editor-plugin-editor-disabled/tsconfig.app.json"
45
+ },
46
+ {
47
+ "path": "../editor-plugin-selection/tsconfig.app.json"
48
+ },
49
+ {
50
+ "path": "../../design-system/tokens/tsconfig.app.json"
51
+ }
52
+ ]
53
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": [
4
+ "**/docs/**/*",
5
+ "**/__tests__/**/*",
6
+ "**/vr-tests/**/*",
7
+ "**/__perf__/**/*",
8
+ "**/*.test.*",
9
+ "**/test.*",
10
+ "**/test-*",
11
+ "**/examples.ts",
12
+ "**/examples.tsx",
13
+ "**/examples/*.ts",
14
+ "**/examples/*.tsx",
15
+ "**/examples/**/*.ts",
16
+ "**/examples/**/*.tsx",
17
+ "**/storybook/**/*",
18
+ "**/constellation/**/*",
19
+ ".storybook/*",
20
+ "./__fixtures__/**/*",
21
+ "./__generated__/**/*",
22
+ "./mocks/**/*",
23
+ "./__mocks__/**/*",
24
+ "**/mock.*",
25
+ "**/codemods/**/*.ts",
26
+ "**/codemods/**/*.tsx"
27
+ ],
28
+ "exclude": ["./dist/**/*", "./build/**/*", "./node_modules/**/*"],
29
+ "compilerOptions": {
30
+ "composite": true,
31
+ "outDir": "../../../tsDist/@atlaskit__editor-plugin-code-block-advanced/dev"
32
+ },
33
+ "references": [
34
+ {
35
+ "path": "./tsconfig.app.json"
36
+ },
37
+ {
38
+ "path": "../../../build/website/docs/tsconfig.app.json"
39
+ },
40
+ {
41
+ "path": "../editor-common/tsconfig.app.json"
42
+ },
43
+ {
44
+ "path": "../../design-system/tokens/tsconfig.app.json"
45
+ }
46
+ ]
47
+ }