@atlaskit/editor-plugin-code-block-advanced 7.0.0 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/editor-plugin-code-block-advanced
2
2
 
3
+ ## 7.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`77341edf4fd78`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/77341edf4fd78) -
8
+ [EDITOR-3786] Added a new plugin `@atlaskit/editor-plugin-content-format`, and made
9
+ `@atlaskit/editor-plugin-code-block-advanced` have a dependancy on it. Removed the ResizeObserver
10
+ from `@atlaskit/editor-plugin-code-block-advanced` and replaced it with a way to observe changes
11
+ to the `contentMode`. Updated examples to update the state of the new plugin so that examples work
12
+ with the new behaviour.
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+
3
18
  ## 7.0.0
4
19
 
5
20
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "../../../../tsconfig.entry-points.confluence.json",
2
+ "extends": "../../../../tsconfig.local-consumption.json",
3
3
  "compilerOptions": {
4
4
  "target": "es5",
5
5
  "outDir": "../../../../../confluence/tsDist/@atlaskit__editor-plugin-code-block-advanced",
@@ -43,28 +43,33 @@ var codeBlockHeights = new WeakMap();
43
43
  var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
44
44
  function CodeBlockAdvancedNodeView(node, view, getPos, innerDecorations, config) {
45
45
  var _config$api,
46
- _this = this,
46
+ _contentFormatSharedS,
47
47
  _config$api2,
48
- _config$api3;
48
+ _this = this,
49
+ _config$api3,
50
+ _config$api4;
49
51
  (0, _classCallCheck2.default)(this, CodeBlockAdvancedNodeView);
50
52
  (0, _defineProperty2.default)(this, "lineWrappingCompartment", new _state.Compartment());
51
53
  (0, _defineProperty2.default)(this, "languageCompartment", new _state.Compartment());
52
54
  (0, _defineProperty2.default)(this, "readOnlyCompartment", new _state.Compartment());
53
55
  (0, _defineProperty2.default)(this, "pmDecorationsCompartment", new _state.Compartment());
56
+ (0, _defineProperty2.default)(this, "themeCompartment", new _state.Compartment());
54
57
  (0, _defineProperty2.default)(this, "maybeTryingToReachNodeSelection", false);
55
58
  (0, _defineProperty2.default)(this, "pmFacet", _state.Facet.define());
56
59
  (0, _defineProperty2.default)(this, "wordWrappingEnabled", false);
57
60
  this.node = node;
58
61
  this.view = view;
59
62
  this.getPos = getPos;
60
- this.selectionAPI = (_config$api = config.api) === null || _config$api === void 0 || (_config$api = _config$api.selection) === null || _config$api === void 0 ? void 0 : _config$api.actions;
63
+ var contentFormatSharedState = (0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true) ? (_config$api = config.api) === null || _config$api === void 0 || (_config$api = _config$api.contentFormat) === null || _config$api === void 0 ? void 0 : _config$api.sharedState : undefined;
64
+ this.contentMode = (0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true) ? contentFormatSharedState === null || contentFormatSharedState === void 0 || (_contentFormatSharedS = contentFormatSharedState.currentState) === null || _contentFormatSharedS === void 0 || (_contentFormatSharedS = _contentFormatSharedS.call(contentFormatSharedState)) === null || _contentFormatSharedS === void 0 ? void 0 : _contentFormatSharedS.contentMode : undefined;
65
+ this.selectionAPI = (_config$api2 = config.api) === null || _config$api2 === void 0 || (_config$api2 = _config$api2.selection) === null || _config$api2 === void 0 ? void 0 : _config$api2.actions;
61
66
  var getNode = function getNode() {
62
67
  return _this.node;
63
68
  };
64
69
  var onMaybeNodeSelection = function onMaybeNodeSelection() {
65
70
  return _this.maybeTryingToReachNodeSelection = true;
66
71
  };
67
- this.cleanupDisabledState = (_config$api2 = config.api) === null || _config$api2 === void 0 || (_config$api2 = _config$api2.editorDisabled) === null || _config$api2 === void 0 ? void 0 : _config$api2.sharedState.onChange(function () {
72
+ this.cleanupDisabledState = (_config$api3 = config.api) === null || _config$api3 === void 0 || (_config$api3 = _config$api3.editorDisabled) === null || _config$api3 === void 0 ? void 0 : _config$api3.sharedState.onChange(function () {
68
73
  _this.updateReadonlyState();
69
74
  });
70
75
  this.languageLoader = new _loader.LanguageLoader(function (lang) {
@@ -91,10 +96,12 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
91
96
  getNode: getNode,
92
97
  selectCodeBlockNode: this.selectCodeBlockNode.bind(this),
93
98
  onMaybeNodeSelection: onMaybeNodeSelection,
94
- customFindReplace: Boolean((_config$api3 = config.api) === null || _config$api3 === void 0 ? void 0 : _config$api3.findReplace)
99
+ customFindReplace: Boolean((_config$api4 = config.api) === null || _config$api4 === void 0 ? void 0 : _config$api4.findReplace)
95
100
  }),
96
101
  // Goes before cmTheme to override styles
97
- config.allowCodeFolding ? [_theme.codeFoldingTheme] : [], _theme.cmTheme, (0, _language.syntaxHighlighting)(_syntaxHighlightingTheme.highlightStyle), (0, _language.bracketMatching)(), (0, _view.lineNumbers)({
102
+ config.allowCodeFolding ? [_theme.codeFoldingTheme] : [], this.themeCompartment.of((0, _theme.cmTheme)({
103
+ contentMode: (0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true) ? this.contentMode : undefined
104
+ })), (0, _language.syntaxHighlighting)(_syntaxHighlightingTheme.highlightStyle), (0, _language.bracketMatching)(), (0, _view.lineNumbers)({
98
105
  domEventHandlers: {
99
106
  click: function click() {
100
107
  selectNode();
@@ -123,18 +130,25 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
123
130
  }
124
131
  })] : []])
125
132
  });
126
-
127
- // We append an additional element that fixes a selection bug on chrome if the code block
128
- // is the first element followed by subsequent code blocks
129
- var spaceContainer = document.createElement('span');
130
- spaceContainer.innerText = _whitespace.ZERO_WIDTH_SPACE;
131
- spaceContainer.style.height = '0';
132
- // The editor's outer node is our DOM representation
133
- this.dom = this.cm.dom;
134
- this.dom.appendChild(spaceContainer);
133
+ if (contentFormatSharedState) {
134
+ this.unsubscribeContentFormat = contentFormatSharedState.onChange(function (_ref) {
135
+ var nextSharedState = _ref.nextSharedState,
136
+ prevSharedState = _ref.prevSharedState;
137
+ var prevMode = prevSharedState === null || prevSharedState === void 0 ? void 0 : prevSharedState.contentMode;
138
+ var nextMode = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.contentMode;
139
+ if (nextMode === prevMode) {
140
+ return;
141
+ }
142
+ _this.applyContentModeTheme(nextMode);
143
+ if (_this.updating || _this.cm.hasFocus) {
144
+ return;
145
+ }
146
+ _this.cm.requestMeasure();
147
+ });
148
+ }
135
149
 
136
150
  // Observe size changes of the CodeMirror DOM and request a measurement pass
137
- if ((0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true) || (0, _expValEquals.expValEquals)('cc_editor_ai_content_mode', 'variant', 'test') && (0, _platformFeatureFlags.fg)('platform_editor_content_mode_button_mvp')) {
151
+ if (!(0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true) && (0, _expValEquals.expValEquals)('cc_editor_ai_content_mode', 'variant', 'test') && (0, _platformFeatureFlags.fg)('platform_editor_content_mode_button_mvp')) {
138
152
  this.ro = new ResizeObserver(function (entries) {
139
153
  // Skip measurements when:
140
154
  // 1. Currently updating (prevents feedback loops)
@@ -156,6 +170,7 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
156
170
  }
157
171
  codeBlockHeights.set(_this.cm.contentDOM, currentHeight);
158
172
  }
173
+
159
174
  // CodeMirror to re-measure when its content size changes
160
175
  } catch (err) {
161
176
  _iterator.e(err);
@@ -167,6 +182,15 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
167
182
  this.ro.observe(this.cm.contentDOM);
168
183
  }
169
184
 
185
+ // We append an additional element that fixes a selection bug on chrome if the code block
186
+ // is the first element followed by subsequent code blocks
187
+ var spaceContainer = document.createElement('span');
188
+ spaceContainer.innerText = _whitespace.ZERO_WIDTH_SPACE;
189
+ spaceContainer.style.height = '0';
190
+ // The editor's outer node is our DOM representation
191
+ this.dom = this.cm.dom;
192
+ this.dom.appendChild(spaceContainer);
193
+
170
194
  // This flag is used to avoid an update loop between the outer and
171
195
  // inner editor
172
196
  this.updating = false;
@@ -188,7 +212,11 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
188
212
  // codemirror
189
213
  this.clearProseMirrorDecorations();
190
214
  (_this$cleanupDisabled = this.cleanupDisabledState) === null || _this$cleanupDisabled === void 0 || _this$cleanupDisabled.call(this);
191
- if ((0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true) || (0, _expValEquals.expValEquals)('cc_editor_ai_content_mode', 'variant', 'test') && (0, _platformFeatureFlags.fg)('platform_editor_content_mode_button_mvp')) {
215
+ if ((0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true)) {
216
+ var _this$unsubscribeCont;
217
+ (_this$unsubscribeCont = this.unsubscribeContentFormat) === null || _this$unsubscribeCont === void 0 || _this$unsubscribeCont.call(this);
218
+ }
219
+ if (!(0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true) && (0, _expValEquals.expValEquals)('cc_editor_ai_content_mode', 'variant', 'test') && (0, _platformFeatureFlags.fg)('platform_editor_content_mode_button_mvp')) {
192
220
  var _this$ro;
193
221
  (_this$ro = this.ro) === null || _this$ro === void 0 || _this$ro.disconnect();
194
222
  }
@@ -286,6 +314,21 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
286
314
  }
287
315
  this.updating = false;
288
316
  }
317
+ }, {
318
+ key: "applyContentModeTheme",
319
+ value: function applyContentModeTheme(contentMode) {
320
+ if (contentMode === this.contentMode) {
321
+ return;
322
+ }
323
+ this.contentMode = contentMode;
324
+ this.updating = true;
325
+ this.cm.dispatch({
326
+ effects: this.themeCompartment.reconfigure((0, _theme.cmTheme)({
327
+ contentMode: contentMode
328
+ }))
329
+ });
330
+ this.updating = false;
331
+ }
289
332
  }, {
290
333
  key: "update",
291
334
  value: function update(node, _, innerDecorations) {
@@ -7,80 +7,85 @@ exports.codeFoldingTheme = exports.cmTheme = void 0;
7
7
  var _view = require("@codemirror/view");
8
8
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
9
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
10
- var getLineHeight = function getLineHeight() {
11
- return (0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true) || (0, _expValEquals.expValEquals)('cc_editor_ai_content_mode', 'variant', 'test') && (0, _platformFeatureFlags.fg)('platform_editor_content_mode_button_mvp') ? '1.5em' : '1.5rem';
10
+ var shouldUseCompactTypography = function shouldUseCompactTypography(contentMode) {
11
+ return contentMode === 'compact' || (0, _expValEquals.expValEquals)('cc_editor_ai_content_mode', 'variant', 'test') && (0, _platformFeatureFlags.fg)('platform_editor_content_mode_button_mvp');
12
12
  };
13
- var getFontSize = function getFontSize() {
14
- return (0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true) || (0, _expValEquals.expValEquals)('cc_editor_ai_content_mode', 'variant', 'test') && (0, _platformFeatureFlags.fg)('platform_editor_content_mode_button_mvp') ? '0.875em' : '0.875rem';
13
+ var getLineHeight = function getLineHeight(contentMode) {
14
+ return shouldUseCompactTypography(contentMode) ? '1.5em' : '1.5rem';
15
+ };
16
+ var getFontSize = function getFontSize(contentMode) {
17
+ return shouldUseCompactTypography(contentMode) ? '0.875em' : '0.875rem';
18
+ };
19
+ var cmTheme = exports.cmTheme = function cmTheme(options) {
20
+ return _view.EditorView.theme({
21
+ '&': {
22
+ backgroundColor: "var(--ds-background-neutral, #0515240F)",
23
+ padding: '0',
24
+ marginTop: "var(--ds-space-100, 8px)",
25
+ marginBottom: "var(--ds-space-100, 8px)",
26
+ // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
27
+ fontSize: getFontSize(options === null || options === void 0 ? void 0 : options.contentMode),
28
+ // Custom syntax styling to match existing styling
29
+ // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
30
+ lineHeight: getLineHeight(options === null || options === void 0 ? void 0 : options.contentMode)
31
+ },
32
+ '&.cm-focused': {
33
+ outline: 'none'
34
+ },
35
+ '.cm-line': {
36
+ padding: '0'
37
+ },
38
+ '&.cm-editor.code-block.danger': {
39
+ backgroundColor: "var(--ds-background-danger, #FFECEB)"
40
+ },
41
+ '.cm-content[aria-readonly="true"]': {
42
+ caretColor: 'transparent'
43
+ },
44
+ '.cm-content': {
45
+ cursor: 'text',
46
+ caretColor: "var(--ds-text, #292A2E)",
47
+ margin: "var(--ds-space-100, 8px)",
48
+ padding: "var(--ds-space-0, 0px)"
49
+ },
50
+ '.cm-scroller': {
51
+ backgroundColor: "var(--ds-background-neutral, #0515240F)",
52
+ // Custom syntax styling to match existing styling
53
+ // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
54
+ lineHeight: 'unset',
55
+ fontFamily: "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)",
56
+ borderRadius: "var(--ds-radius-small, 4px)",
57
+ backgroundImage: overflowShadow({
58
+ leftCoverWidth: "var(--ds-space-300, 24px)"
59
+ }),
60
+ backgroundAttachment: 'local, local, local, local, scroll, scroll, scroll, scroll'
61
+ },
62
+ '&.cm-focused .cm-cursor': {
63
+ borderLeftColor: "var(--ds-text, #292A2E)"
64
+ },
65
+ '.cm-gutter': {
66
+ padding: "var(--ds-space-100, 8px)"
67
+ },
68
+ '.cm-gutters': {
69
+ backgroundColor: "var(--ds-background-neutral, #0515240F)",
70
+ border: 'none',
71
+ padding: "var(--ds-space-0, 0px)",
72
+ color: "var(--ds-text-subtlest, #6B6E76)"
73
+ },
74
+ '.cm-lineNumbers .cm-gutterElement': {
75
+ paddingLeft: "var(--ds-space-0, 0px)",
76
+ paddingRight: "var(--ds-space-0, 0px)",
77
+ minWidth: 'unset'
78
+ },
79
+ // Set the gutter element min height to prevent flicker of styling while
80
+ // codemirror is calculating (which happens after an animation frame).
81
+ // Example problem: https://github.com/codemirror/dev/issues/1076
82
+ // Ignore the first gutter element as it is a special hidden element.
83
+ '.cm-gutterElement:not(:first-child)': {
84
+ // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
85
+ minHeight: getLineHeight(options === null || options === void 0 ? void 0 : options.contentMode)
86
+ }
87
+ });
15
88
  };
16
- var cmTheme = exports.cmTheme = _view.EditorView.theme({
17
- '&': {
18
- backgroundColor: "var(--ds-background-neutral, #0515240F)",
19
- padding: '0',
20
- marginTop: "var(--ds-space-100, 8px)",
21
- marginBottom: "var(--ds-space-100, 8px)",
22
- // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
23
- fontSize: getFontSize(),
24
- // Custom syntax styling to match existing styling
25
- // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
26
- lineHeight: getLineHeight()
27
- },
28
- '&.cm-focused': {
29
- outline: 'none'
30
- },
31
- '.cm-line': {
32
- padding: '0'
33
- },
34
- '&.cm-editor.code-block.danger': {
35
- backgroundColor: "var(--ds-background-danger, #FFECEB)"
36
- },
37
- '.cm-content[aria-readonly="true"]': {
38
- caretColor: 'transparent'
39
- },
40
- '.cm-content': {
41
- cursor: 'text',
42
- caretColor: "var(--ds-text, #292A2E)",
43
- margin: "var(--ds-space-100, 8px)",
44
- padding: "var(--ds-space-0, 0px)"
45
- },
46
- '.cm-scroller': {
47
- backgroundColor: "var(--ds-background-neutral, #0515240F)",
48
- // Custom syntax styling to match existing styling
49
- // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
50
- lineHeight: 'unset',
51
- fontFamily: "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)",
52
- borderRadius: "var(--ds-radius-small, 4px)",
53
- backgroundImage: overflowShadow({
54
- leftCoverWidth: "var(--ds-space-300, 24px)"
55
- }),
56
- backgroundAttachment: 'local, local, local, local, scroll, scroll, scroll, scroll'
57
- },
58
- '&.cm-focused .cm-cursor': {
59
- borderLeftColor: "var(--ds-text, #292A2E)"
60
- },
61
- '.cm-gutter': {
62
- padding: "var(--ds-space-100, 8px)"
63
- },
64
- '.cm-gutters': {
65
- backgroundColor: "var(--ds-background-neutral, #0515240F)",
66
- border: 'none',
67
- padding: "var(--ds-space-0, 0px)",
68
- color: "var(--ds-text-subtlest, #6B6E76)"
69
- },
70
- '.cm-lineNumbers .cm-gutterElement': {
71
- paddingLeft: "var(--ds-space-0, 0px)",
72
- paddingRight: "var(--ds-space-0, 0px)",
73
- minWidth: 'unset'
74
- },
75
- // Set the gutter element min height to prevent flicker of styling while
76
- // codemirror is calculating (which happens after an animation frame).
77
- // Example problem: https://github.com/codemirror/dev/issues/1076
78
- // Ignore the first gutter element as it is a special hidden element.
79
- '.cm-gutterElement:not(:first-child)': {
80
- // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
81
- minHeight: getLineHeight()
82
- }
83
- });
84
89
  var codeFoldingTheme = exports.codeFoldingTheme = _view.EditorView.theme({
85
90
  '.cm-gutter': {
86
91
  paddingLeft: "var(--ds-space-075, 6px)",
@@ -13,9 +13,6 @@ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
13
13
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
14
14
  import { highlightStyle } from '../ui/syntaxHighlightingTheme';
15
15
  import { cmTheme, codeFoldingTheme } from '../ui/theme';
16
-
17
- // Store last observed heights of code blocks
18
- const codeBlockHeights = new WeakMap();
19
16
  import { syncCMWithPM } from './codemirrorSync/syncCMWithPM';
20
17
  import { getCMSelectionChanges } from './codemirrorSync/updateCMSelection';
21
18
  import { firstCodeBlockInDocument } from './extensions/firstCodeBlockInDocument';
@@ -25,24 +22,30 @@ import { manageSelectionMarker } from './extensions/manageSelectionMarker';
25
22
  import { prosemirrorDecorationPlugin } from './extensions/prosemirrorDecorations';
26
23
  import { tripleClickSelectAllExtension } from './extensions/tripleClickExtension';
27
24
  import { LanguageLoader } from './languages/loader';
25
+
26
+ // Store last observed heights of code blocks
27
+ const codeBlockHeights = new WeakMap();
28
28
  // Based on: https://prosemirror.net/examples/codemirror/
29
29
  class CodeBlockAdvancedNodeView {
30
30
  constructor(node, view, getPos, innerDecorations, config) {
31
- var _config$api, _config$api$selection, _config$api2, _config$api2$editorDi, _config$api3;
31
+ var _config$api, _config$api$contentFo, _contentFormatSharedS, _contentFormatSharedS2, _config$api2, _config$api2$selectio, _config$api3, _config$api3$editorDi, _config$api4;
32
32
  _defineProperty(this, "lineWrappingCompartment", new Compartment());
33
33
  _defineProperty(this, "languageCompartment", new Compartment());
34
34
  _defineProperty(this, "readOnlyCompartment", new Compartment());
35
35
  _defineProperty(this, "pmDecorationsCompartment", new Compartment());
36
+ _defineProperty(this, "themeCompartment", new Compartment());
36
37
  _defineProperty(this, "maybeTryingToReachNodeSelection", false);
37
38
  _defineProperty(this, "pmFacet", Facet.define());
38
39
  _defineProperty(this, "wordWrappingEnabled", false);
39
40
  this.node = node;
40
41
  this.view = view;
41
42
  this.getPos = getPos;
42
- this.selectionAPI = (_config$api = config.api) === null || _config$api === void 0 ? void 0 : (_config$api$selection = _config$api.selection) === null || _config$api$selection === void 0 ? void 0 : _config$api$selection.actions;
43
+ const contentFormatSharedState = expValEquals('confluence_compact_text_format', 'isEnabled', true) ? (_config$api = config.api) === null || _config$api === void 0 ? void 0 : (_config$api$contentFo = _config$api.contentFormat) === null || _config$api$contentFo === void 0 ? void 0 : _config$api$contentFo.sharedState : undefined;
44
+ this.contentMode = expValEquals('confluence_compact_text_format', 'isEnabled', true) ? contentFormatSharedState === null || contentFormatSharedState === void 0 ? void 0 : (_contentFormatSharedS = contentFormatSharedState.currentState) === null || _contentFormatSharedS === void 0 ? void 0 : (_contentFormatSharedS2 = _contentFormatSharedS.call(contentFormatSharedState)) === null || _contentFormatSharedS2 === void 0 ? void 0 : _contentFormatSharedS2.contentMode : undefined;
45
+ this.selectionAPI = (_config$api2 = config.api) === null || _config$api2 === void 0 ? void 0 : (_config$api2$selectio = _config$api2.selection) === null || _config$api2$selectio === void 0 ? void 0 : _config$api2$selectio.actions;
43
46
  const getNode = () => this.node;
44
47
  const onMaybeNodeSelection = () => this.maybeTryingToReachNodeSelection = true;
45
- this.cleanupDisabledState = (_config$api2 = config.api) === null || _config$api2 === void 0 ? void 0 : (_config$api2$editorDi = _config$api2.editorDisabled) === null || _config$api2$editorDi === void 0 ? void 0 : _config$api2$editorDi.sharedState.onChange(() => {
48
+ this.cleanupDisabledState = (_config$api3 = config.api) === null || _config$api3 === void 0 ? void 0 : (_config$api3$editorDi = _config$api3.editorDisabled) === null || _config$api3$editorDi === void 0 ? void 0 : _config$api3$editorDi.sharedState.onChange(() => {
46
49
  this.updateReadonlyState();
47
50
  });
48
51
  this.languageLoader = new LanguageLoader(lang => {
@@ -68,10 +71,12 @@ class CodeBlockAdvancedNodeView {
68
71
  getNode,
69
72
  selectCodeBlockNode: this.selectCodeBlockNode.bind(this),
70
73
  onMaybeNodeSelection,
71
- customFindReplace: Boolean((_config$api3 = config.api) === null || _config$api3 === void 0 ? void 0 : _config$api3.findReplace)
74
+ customFindReplace: Boolean((_config$api4 = config.api) === null || _config$api4 === void 0 ? void 0 : _config$api4.findReplace)
72
75
  }),
73
76
  // Goes before cmTheme to override styles
74
- config.allowCodeFolding ? [codeFoldingTheme] : [], cmTheme, syntaxHighlighting(highlightStyle), bracketMatching(), lineNumbers({
77
+ config.allowCodeFolding ? [codeFoldingTheme] : [], this.themeCompartment.of(cmTheme({
78
+ contentMode: expValEquals('confluence_compact_text_format', 'isEnabled', true) ? this.contentMode : undefined
79
+ })), syntaxHighlighting(highlightStyle), bracketMatching(), lineNumbers({
75
80
  domEventHandlers: {
76
81
  click: () => {
77
82
  selectNode();
@@ -97,18 +102,26 @@ class CodeBlockAdvancedNodeView {
97
102
  getNode: () => this.node
98
103
  })] : []]
99
104
  });
100
-
101
- // We append an additional element that fixes a selection bug on chrome if the code block
102
- // is the first element followed by subsequent code blocks
103
- const spaceContainer = document.createElement('span');
104
- spaceContainer.innerText = ZERO_WIDTH_SPACE;
105
- spaceContainer.style.height = '0';
106
- // The editor's outer node is our DOM representation
107
- this.dom = this.cm.dom;
108
- this.dom.appendChild(spaceContainer);
105
+ if (contentFormatSharedState) {
106
+ this.unsubscribeContentFormat = contentFormatSharedState.onChange(({
107
+ nextSharedState,
108
+ prevSharedState
109
+ }) => {
110
+ const prevMode = prevSharedState === null || prevSharedState === void 0 ? void 0 : prevSharedState.contentMode;
111
+ const nextMode = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.contentMode;
112
+ if (nextMode === prevMode) {
113
+ return;
114
+ }
115
+ this.applyContentModeTheme(nextMode);
116
+ if (this.updating || this.cm.hasFocus) {
117
+ return;
118
+ }
119
+ this.cm.requestMeasure();
120
+ });
121
+ }
109
122
 
110
123
  // Observe size changes of the CodeMirror DOM and request a measurement pass
111
- if (expValEquals('confluence_compact_text_format', 'isEnabled', true) || expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp')) {
124
+ if (!expValEquals('confluence_compact_text_format', 'isEnabled', true) && expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp')) {
112
125
  this.ro = new ResizeObserver(entries => {
113
126
  // Skip measurements when:
114
127
  // 1. Currently updating (prevents feedback loops)
@@ -126,12 +139,22 @@ class CodeBlockAdvancedNodeView {
126
139
  }
127
140
  codeBlockHeights.set(this.cm.contentDOM, currentHeight);
128
141
  }
142
+
129
143
  // CodeMirror to re-measure when its content size changes
130
144
  this.cm.requestMeasure();
131
145
  });
132
146
  this.ro.observe(this.cm.contentDOM);
133
147
  }
134
148
 
149
+ // We append an additional element that fixes a selection bug on chrome if the code block
150
+ // is the first element followed by subsequent code blocks
151
+ const spaceContainer = document.createElement('span');
152
+ spaceContainer.innerText = ZERO_WIDTH_SPACE;
153
+ spaceContainer.style.height = '0';
154
+ // The editor's outer node is our DOM representation
155
+ this.dom = this.cm.dom;
156
+ this.dom.appendChild(spaceContainer);
157
+
135
158
  // This flag is used to avoid an update loop between the outer and
136
159
  // inner editor
137
160
  this.updating = false;
@@ -151,7 +174,11 @@ class CodeBlockAdvancedNodeView {
151
174
  // codemirror
152
175
  this.clearProseMirrorDecorations();
153
176
  (_this$cleanupDisabled = this.cleanupDisabledState) === null || _this$cleanupDisabled === void 0 ? void 0 : _this$cleanupDisabled.call(this);
154
- if (expValEquals('confluence_compact_text_format', 'isEnabled', true) || expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp')) {
177
+ if (expValEquals('confluence_compact_text_format', 'isEnabled', true)) {
178
+ var _this$unsubscribeCont;
179
+ (_this$unsubscribeCont = this.unsubscribeContentFormat) === null || _this$unsubscribeCont === void 0 ? void 0 : _this$unsubscribeCont.call(this);
180
+ }
181
+ if (!expValEquals('confluence_compact_text_format', 'isEnabled', true) && expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp')) {
155
182
  var _this$ro;
156
183
  (_this$ro = this.ro) === null || _this$ro === void 0 ? void 0 : _this$ro.disconnect();
157
184
  }
@@ -233,6 +260,19 @@ class CodeBlockAdvancedNodeView {
233
260
  }
234
261
  this.updating = false;
235
262
  }
263
+ applyContentModeTheme(contentMode) {
264
+ if (contentMode === this.contentMode) {
265
+ return;
266
+ }
267
+ this.contentMode = contentMode;
268
+ this.updating = true;
269
+ this.cm.dispatch({
270
+ effects: this.themeCompartment.reconfigure(cmTheme({
271
+ contentMode
272
+ }))
273
+ });
274
+ this.updating = false;
275
+ }
236
276
  update(node, _, innerDecorations) {
237
277
  this.maybeTryingToReachNodeSelection = false;
238
278
  if (node.type !== this.node.type) {
@@ -1,19 +1,20 @@
1
1
  import { EditorView as CodeMirror } from '@codemirror/view';
2
2
  import { fg } from '@atlaskit/platform-feature-flags';
3
3
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
- const getLineHeight = () => expValEquals('confluence_compact_text_format', 'isEnabled', true) || expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp') ? '1.5em' : '1.5rem';
5
- const getFontSize = () => 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';
6
- export const cmTheme = CodeMirror.theme({
4
+ const shouldUseCompactTypography = contentMode => contentMode === 'compact' || expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp');
5
+ const getLineHeight = contentMode => shouldUseCompactTypography(contentMode) ? '1.5em' : '1.5rem';
6
+ const getFontSize = contentMode => shouldUseCompactTypography(contentMode) ? '0.875em' : '0.875rem';
7
+ export const cmTheme = options => CodeMirror.theme({
7
8
  '&': {
8
9
  backgroundColor: "var(--ds-background-neutral, #0515240F)",
9
10
  padding: '0',
10
11
  marginTop: "var(--ds-space-100, 8px)",
11
12
  marginBottom: "var(--ds-space-100, 8px)",
12
13
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
13
- fontSize: getFontSize(),
14
+ fontSize: getFontSize(options === null || options === void 0 ? void 0 : options.contentMode),
14
15
  // Custom syntax styling to match existing styling
15
16
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
16
- lineHeight: getLineHeight()
17
+ lineHeight: getLineHeight(options === null || options === void 0 ? void 0 : options.contentMode)
17
18
  },
18
19
  '&.cm-focused': {
19
20
  outline: 'none'
@@ -68,7 +69,7 @@ export const cmTheme = CodeMirror.theme({
68
69
  // Ignore the first gutter element as it is a special hidden element.
69
70
  '.cm-gutterElement:not(:first-child)': {
70
71
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
71
- minHeight: getLineHeight()
72
+ minHeight: getLineHeight(options === null || options === void 0 ? void 0 : options.contentMode)
72
73
  }
73
74
  });
74
75
  export const codeFoldingTheme = CodeMirror.theme({