@atlaskit/editor-plugin-code-block-advanced 7.0.0 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/afm-cc/tsconfig.json +1 -1
- package/dist/cjs/nodeviews/codeBlockAdvanced.js +62 -18
- package/dist/cjs/nodeviews/extensions/lineSeparator.js +18 -0
- package/dist/cjs/ui/theme.js +77 -72
- package/dist/es2019/nodeviews/codeBlockAdvanced.js +61 -20
- package/dist/es2019/nodeviews/extensions/lineSeparator.js +13 -0
- package/dist/es2019/ui/theme.js +7 -6
- package/dist/esm/nodeviews/codeBlockAdvanced.js +65 -21
- package/dist/esm/nodeviews/extensions/lineSeparator.js +13 -0
- package/dist/esm/ui/theme.js +77 -72
- package/dist/types/codeBlockAdvancedPluginType.d.ts +3 -1
- package/dist/types/nodeviews/codeBlockAdvanced.d.ts +4 -0
- package/dist/types/nodeviews/extensions/lineSeparator.d.ts +5 -0
- package/dist/types/ui/theme.d.ts +6 -1
- package/dist/types-ts4.5/codeBlockAdvancedPluginType.d.ts +3 -1
- package/dist/types-ts4.5/nodeviews/codeBlockAdvanced.d.ts +4 -0
- package/dist/types-ts4.5/nodeviews/extensions/lineSeparator.d.ts +5 -0
- package/dist/types-ts4.5/ui/theme.d.ts +6 -1
- package/package.json +4 -4
- package/src/codeBlockAdvancedPluginType.ts +2 -0
- package/src/nodeviews/codeBlockAdvanced.ts +80 -20
- package/src/nodeviews/extensions/keymap/backspace.ts +1 -1
- package/src/nodeviews/extensions/lineSeparator.ts +14 -0
- package/src/pm-plugins/shiftArrowKeyWorkaround.ts +2 -2
- package/src/ui/theme.ts +82 -79
- package/tsconfig.app.json +3 -0
- package/build/tsconfig.json +0 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block-advanced
|
|
2
2
|
|
|
3
|
+
## 7.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`e91ea1cbba89a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e91ea1cbba89a) -
|
|
8
|
+
JRACLOUD-96830: Fix navigating and editing codeblocks with CRLF new lines.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 7.1.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [`77341edf4fd78`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/77341edf4fd78) -
|
|
16
|
+
[EDITOR-3786] Added a new plugin `@atlaskit/editor-plugin-content-format`, and made
|
|
17
|
+
`@atlaskit/editor-plugin-code-block-advanced` have a dependancy on it. Removed the ResizeObserver
|
|
18
|
+
from `@atlaskit/editor-plugin-code-block-advanced` and replaced it with a way to observe changes
|
|
19
|
+
to the `contentMode`. Updated examples to update the state of the new plugin so that examples work
|
|
20
|
+
with the new behaviour.
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies
|
|
25
|
+
|
|
3
26
|
## 7.0.0
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/afm-cc/tsconfig.json
CHANGED
|
@@ -28,6 +28,7 @@ var _updateCMSelection = require("./codemirrorSync/updateCMSelection");
|
|
|
28
28
|
var _firstCodeBlockInDocument = require("./extensions/firstCodeBlockInDocument");
|
|
29
29
|
var _foldGutter = require("./extensions/foldGutter");
|
|
30
30
|
var _keymap = require("./extensions/keymap");
|
|
31
|
+
var _lineSeparator = require("./extensions/lineSeparator");
|
|
31
32
|
var _manageSelectionMarker = require("./extensions/manageSelectionMarker");
|
|
32
33
|
var _prosemirrorDecorations = require("./extensions/prosemirrorDecorations");
|
|
33
34
|
var _tripleClickExtension = require("./extensions/tripleClickExtension");
|
|
@@ -43,28 +44,33 @@ var codeBlockHeights = new WeakMap();
|
|
|
43
44
|
var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
44
45
|
function CodeBlockAdvancedNodeView(node, view, getPos, innerDecorations, config) {
|
|
45
46
|
var _config$api,
|
|
46
|
-
|
|
47
|
+
_contentFormatSharedS,
|
|
47
48
|
_config$api2,
|
|
48
|
-
|
|
49
|
+
_this = this,
|
|
50
|
+
_config$api3,
|
|
51
|
+
_config$api4;
|
|
49
52
|
(0, _classCallCheck2.default)(this, CodeBlockAdvancedNodeView);
|
|
50
53
|
(0, _defineProperty2.default)(this, "lineWrappingCompartment", new _state.Compartment());
|
|
51
54
|
(0, _defineProperty2.default)(this, "languageCompartment", new _state.Compartment());
|
|
52
55
|
(0, _defineProperty2.default)(this, "readOnlyCompartment", new _state.Compartment());
|
|
53
56
|
(0, _defineProperty2.default)(this, "pmDecorationsCompartment", new _state.Compartment());
|
|
57
|
+
(0, _defineProperty2.default)(this, "themeCompartment", new _state.Compartment());
|
|
54
58
|
(0, _defineProperty2.default)(this, "maybeTryingToReachNodeSelection", false);
|
|
55
59
|
(0, _defineProperty2.default)(this, "pmFacet", _state.Facet.define());
|
|
56
60
|
(0, _defineProperty2.default)(this, "wordWrappingEnabled", false);
|
|
57
61
|
this.node = node;
|
|
58
62
|
this.view = view;
|
|
59
63
|
this.getPos = getPos;
|
|
60
|
-
|
|
64
|
+
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;
|
|
65
|
+
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;
|
|
66
|
+
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
67
|
var getNode = function getNode() {
|
|
62
68
|
return _this.node;
|
|
63
69
|
};
|
|
64
70
|
var onMaybeNodeSelection = function onMaybeNodeSelection() {
|
|
65
71
|
return _this.maybeTryingToReachNodeSelection = true;
|
|
66
72
|
};
|
|
67
|
-
this.cleanupDisabledState = (_config$
|
|
73
|
+
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
74
|
_this.updateReadonlyState();
|
|
69
75
|
});
|
|
70
76
|
this.languageLoader = new _loader.LanguageLoader(function (lang) {
|
|
@@ -91,10 +97,12 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
91
97
|
getNode: getNode,
|
|
92
98
|
selectCodeBlockNode: this.selectCodeBlockNode.bind(this),
|
|
93
99
|
onMaybeNodeSelection: onMaybeNodeSelection,
|
|
94
|
-
customFindReplace: Boolean((_config$
|
|
100
|
+
customFindReplace: Boolean((_config$api4 = config.api) === null || _config$api4 === void 0 ? void 0 : _config$api4.findReplace)
|
|
95
101
|
}),
|
|
96
102
|
// Goes before cmTheme to override styles
|
|
97
|
-
config.allowCodeFolding ? [_theme.codeFoldingTheme] : [],
|
|
103
|
+
config.allowCodeFolding ? [_theme.codeFoldingTheme] : [], this.themeCompartment.of((0, _theme.cmTheme)({
|
|
104
|
+
contentMode: (0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true) ? this.contentMode : undefined
|
|
105
|
+
})), (0, _language.syntaxHighlighting)(_syntaxHighlightingTheme.highlightStyle), (0, _language.bracketMatching)(), (0, _view.lineNumbers)({
|
|
98
106
|
domEventHandlers: {
|
|
99
107
|
click: function click() {
|
|
100
108
|
selectNode();
|
|
@@ -121,20 +129,27 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
121
129
|
getNode: function getNode() {
|
|
122
130
|
return _this.node;
|
|
123
131
|
}
|
|
124
|
-
})] : []])
|
|
132
|
+
})] : [], (0, _lineSeparator.lineSeparatorExtension)()])
|
|
125
133
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
if (contentFormatSharedState) {
|
|
135
|
+
this.unsubscribeContentFormat = contentFormatSharedState.onChange(function (_ref) {
|
|
136
|
+
var nextSharedState = _ref.nextSharedState,
|
|
137
|
+
prevSharedState = _ref.prevSharedState;
|
|
138
|
+
var prevMode = prevSharedState === null || prevSharedState === void 0 ? void 0 : prevSharedState.contentMode;
|
|
139
|
+
var nextMode = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.contentMode;
|
|
140
|
+
if (nextMode === prevMode) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
_this.applyContentModeTheme(nextMode);
|
|
144
|
+
if (_this.updating || _this.cm.hasFocus) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
_this.cm.requestMeasure();
|
|
148
|
+
});
|
|
149
|
+
}
|
|
135
150
|
|
|
136
151
|
// Observe size changes of the CodeMirror DOM and request a measurement pass
|
|
137
|
-
if ((0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true)
|
|
152
|
+
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
153
|
this.ro = new ResizeObserver(function (entries) {
|
|
139
154
|
// Skip measurements when:
|
|
140
155
|
// 1. Currently updating (prevents feedback loops)
|
|
@@ -156,6 +171,7 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
156
171
|
}
|
|
157
172
|
codeBlockHeights.set(_this.cm.contentDOM, currentHeight);
|
|
158
173
|
}
|
|
174
|
+
|
|
159
175
|
// CodeMirror to re-measure when its content size changes
|
|
160
176
|
} catch (err) {
|
|
161
177
|
_iterator.e(err);
|
|
@@ -167,6 +183,15 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
167
183
|
this.ro.observe(this.cm.contentDOM);
|
|
168
184
|
}
|
|
169
185
|
|
|
186
|
+
// We append an additional element that fixes a selection bug on chrome if the code block
|
|
187
|
+
// is the first element followed by subsequent code blocks
|
|
188
|
+
var spaceContainer = document.createElement('span');
|
|
189
|
+
spaceContainer.innerText = _whitespace.ZERO_WIDTH_SPACE;
|
|
190
|
+
spaceContainer.style.height = '0';
|
|
191
|
+
// The editor's outer node is our DOM representation
|
|
192
|
+
this.dom = this.cm.dom;
|
|
193
|
+
this.dom.appendChild(spaceContainer);
|
|
194
|
+
|
|
170
195
|
// This flag is used to avoid an update loop between the outer and
|
|
171
196
|
// inner editor
|
|
172
197
|
this.updating = false;
|
|
@@ -188,7 +213,11 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
188
213
|
// codemirror
|
|
189
214
|
this.clearProseMirrorDecorations();
|
|
190
215
|
(_this$cleanupDisabled = this.cleanupDisabledState) === null || _this$cleanupDisabled === void 0 || _this$cleanupDisabled.call(this);
|
|
191
|
-
if ((0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true)
|
|
216
|
+
if ((0, _expValEquals.expValEquals)('confluence_compact_text_format', 'isEnabled', true)) {
|
|
217
|
+
var _this$unsubscribeCont;
|
|
218
|
+
(_this$unsubscribeCont = this.unsubscribeContentFormat) === null || _this$unsubscribeCont === void 0 || _this$unsubscribeCont.call(this);
|
|
219
|
+
}
|
|
220
|
+
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
221
|
var _this$ro;
|
|
193
222
|
(_this$ro = this.ro) === null || _this$ro === void 0 || _this$ro.disconnect();
|
|
194
223
|
}
|
|
@@ -286,6 +315,21 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
286
315
|
}
|
|
287
316
|
this.updating = false;
|
|
288
317
|
}
|
|
318
|
+
}, {
|
|
319
|
+
key: "applyContentModeTheme",
|
|
320
|
+
value: function applyContentModeTheme(contentMode) {
|
|
321
|
+
if (contentMode === this.contentMode) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
this.contentMode = contentMode;
|
|
325
|
+
this.updating = true;
|
|
326
|
+
this.cm.dispatch({
|
|
327
|
+
effects: this.themeCompartment.reconfigure((0, _theme.cmTheme)({
|
|
328
|
+
contentMode: contentMode
|
|
329
|
+
}))
|
|
330
|
+
});
|
|
331
|
+
this.updating = false;
|
|
332
|
+
}
|
|
289
333
|
}, {
|
|
290
334
|
key: "update",
|
|
291
335
|
value: function update(node, _, innerDecorations) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.lineSeparatorExtension = void 0;
|
|
7
|
+
var _state = require("@codemirror/state");
|
|
8
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
9
|
+
/**
|
|
10
|
+
* To avoid issues with CRLF (\r\n) syncing with ProseMirror,
|
|
11
|
+
* we only consider \n for line separators.
|
|
12
|
+
*/
|
|
13
|
+
var lineSeparatorExtension = exports.lineSeparatorExtension = function lineSeparatorExtension() {
|
|
14
|
+
if ((0, _expValEquals.expValEquals)('platform_editor_fix_advanced_codeblocks_crlf', 'isEnabled', true)) {
|
|
15
|
+
return _state.EditorState.lineSeparator.of('\n');
|
|
16
|
+
}
|
|
17
|
+
return [];
|
|
18
|
+
};
|
package/dist/cjs/ui/theme.js
CHANGED
|
@@ -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
|
|
11
|
-
return
|
|
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
|
|
14
|
-
return (
|
|
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,36 +13,40 @@ 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';
|
|
22
19
|
import { foldGutterExtension, getCodeBlockFoldStateEffects } from './extensions/foldGutter';
|
|
23
20
|
import { keymapExtension } from './extensions/keymap';
|
|
21
|
+
import { lineSeparatorExtension } from './extensions/lineSeparator';
|
|
24
22
|
import { manageSelectionMarker } from './extensions/manageSelectionMarker';
|
|
25
23
|
import { prosemirrorDecorationPlugin } from './extensions/prosemirrorDecorations';
|
|
26
24
|
import { tripleClickSelectAllExtension } from './extensions/tripleClickExtension';
|
|
27
25
|
import { LanguageLoader } from './languages/loader';
|
|
26
|
+
|
|
27
|
+
// Store last observed heights of code blocks
|
|
28
|
+
const codeBlockHeights = new WeakMap();
|
|
28
29
|
// Based on: https://prosemirror.net/examples/codemirror/
|
|
29
30
|
class CodeBlockAdvancedNodeView {
|
|
30
31
|
constructor(node, view, getPos, innerDecorations, config) {
|
|
31
|
-
var _config$api, _config$api$
|
|
32
|
+
var _config$api, _config$api$contentFo, _contentFormatSharedS, _contentFormatSharedS2, _config$api2, _config$api2$selectio, _config$api3, _config$api3$editorDi, _config$api4;
|
|
32
33
|
_defineProperty(this, "lineWrappingCompartment", new Compartment());
|
|
33
34
|
_defineProperty(this, "languageCompartment", new Compartment());
|
|
34
35
|
_defineProperty(this, "readOnlyCompartment", new Compartment());
|
|
35
36
|
_defineProperty(this, "pmDecorationsCompartment", new Compartment());
|
|
37
|
+
_defineProperty(this, "themeCompartment", new Compartment());
|
|
36
38
|
_defineProperty(this, "maybeTryingToReachNodeSelection", false);
|
|
37
39
|
_defineProperty(this, "pmFacet", Facet.define());
|
|
38
40
|
_defineProperty(this, "wordWrappingEnabled", false);
|
|
39
41
|
this.node = node;
|
|
40
42
|
this.view = view;
|
|
41
43
|
this.getPos = getPos;
|
|
42
|
-
|
|
44
|
+
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;
|
|
45
|
+
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;
|
|
46
|
+
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
47
|
const getNode = () => this.node;
|
|
44
48
|
const onMaybeNodeSelection = () => this.maybeTryingToReachNodeSelection = true;
|
|
45
|
-
this.cleanupDisabledState = (_config$
|
|
49
|
+
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
50
|
this.updateReadonlyState();
|
|
47
51
|
});
|
|
48
52
|
this.languageLoader = new LanguageLoader(lang => {
|
|
@@ -68,10 +72,12 @@ class CodeBlockAdvancedNodeView {
|
|
|
68
72
|
getNode,
|
|
69
73
|
selectCodeBlockNode: this.selectCodeBlockNode.bind(this),
|
|
70
74
|
onMaybeNodeSelection,
|
|
71
|
-
customFindReplace: Boolean((_config$
|
|
75
|
+
customFindReplace: Boolean((_config$api4 = config.api) === null || _config$api4 === void 0 ? void 0 : _config$api4.findReplace)
|
|
72
76
|
}),
|
|
73
77
|
// Goes before cmTheme to override styles
|
|
74
|
-
config.allowCodeFolding ? [codeFoldingTheme] : [], cmTheme
|
|
78
|
+
config.allowCodeFolding ? [codeFoldingTheme] : [], this.themeCompartment.of(cmTheme({
|
|
79
|
+
contentMode: expValEquals('confluence_compact_text_format', 'isEnabled', true) ? this.contentMode : undefined
|
|
80
|
+
})), syntaxHighlighting(highlightStyle), bracketMatching(), lineNumbers({
|
|
75
81
|
domEventHandlers: {
|
|
76
82
|
click: () => {
|
|
77
83
|
selectNode();
|
|
@@ -95,20 +101,28 @@ class CodeBlockAdvancedNodeView {
|
|
|
95
101
|
}), config.allowCodeFolding ? [foldGutterExtension({
|
|
96
102
|
selectNode,
|
|
97
103
|
getNode: () => this.node
|
|
98
|
-
})] : []]
|
|
104
|
+
})] : [], lineSeparatorExtension()]
|
|
99
105
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
if (contentFormatSharedState) {
|
|
107
|
+
this.unsubscribeContentFormat = contentFormatSharedState.onChange(({
|
|
108
|
+
nextSharedState,
|
|
109
|
+
prevSharedState
|
|
110
|
+
}) => {
|
|
111
|
+
const prevMode = prevSharedState === null || prevSharedState === void 0 ? void 0 : prevSharedState.contentMode;
|
|
112
|
+
const nextMode = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.contentMode;
|
|
113
|
+
if (nextMode === prevMode) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.applyContentModeTheme(nextMode);
|
|
117
|
+
if (this.updating || this.cm.hasFocus) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.cm.requestMeasure();
|
|
121
|
+
});
|
|
122
|
+
}
|
|
109
123
|
|
|
110
124
|
// Observe size changes of the CodeMirror DOM and request a measurement pass
|
|
111
|
-
if (expValEquals('confluence_compact_text_format', 'isEnabled', true)
|
|
125
|
+
if (!expValEquals('confluence_compact_text_format', 'isEnabled', true) && expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp')) {
|
|
112
126
|
this.ro = new ResizeObserver(entries => {
|
|
113
127
|
// Skip measurements when:
|
|
114
128
|
// 1. Currently updating (prevents feedback loops)
|
|
@@ -126,12 +140,22 @@ class CodeBlockAdvancedNodeView {
|
|
|
126
140
|
}
|
|
127
141
|
codeBlockHeights.set(this.cm.contentDOM, currentHeight);
|
|
128
142
|
}
|
|
143
|
+
|
|
129
144
|
// CodeMirror to re-measure when its content size changes
|
|
130
145
|
this.cm.requestMeasure();
|
|
131
146
|
});
|
|
132
147
|
this.ro.observe(this.cm.contentDOM);
|
|
133
148
|
}
|
|
134
149
|
|
|
150
|
+
// We append an additional element that fixes a selection bug on chrome if the code block
|
|
151
|
+
// is the first element followed by subsequent code blocks
|
|
152
|
+
const spaceContainer = document.createElement('span');
|
|
153
|
+
spaceContainer.innerText = ZERO_WIDTH_SPACE;
|
|
154
|
+
spaceContainer.style.height = '0';
|
|
155
|
+
// The editor's outer node is our DOM representation
|
|
156
|
+
this.dom = this.cm.dom;
|
|
157
|
+
this.dom.appendChild(spaceContainer);
|
|
158
|
+
|
|
135
159
|
// This flag is used to avoid an update loop between the outer and
|
|
136
160
|
// inner editor
|
|
137
161
|
this.updating = false;
|
|
@@ -151,7 +175,11 @@ class CodeBlockAdvancedNodeView {
|
|
|
151
175
|
// codemirror
|
|
152
176
|
this.clearProseMirrorDecorations();
|
|
153
177
|
(_this$cleanupDisabled = this.cleanupDisabledState) === null || _this$cleanupDisabled === void 0 ? void 0 : _this$cleanupDisabled.call(this);
|
|
154
|
-
if (expValEquals('confluence_compact_text_format', 'isEnabled', true)
|
|
178
|
+
if (expValEquals('confluence_compact_text_format', 'isEnabled', true)) {
|
|
179
|
+
var _this$unsubscribeCont;
|
|
180
|
+
(_this$unsubscribeCont = this.unsubscribeContentFormat) === null || _this$unsubscribeCont === void 0 ? void 0 : _this$unsubscribeCont.call(this);
|
|
181
|
+
}
|
|
182
|
+
if (!expValEquals('confluence_compact_text_format', 'isEnabled', true) && expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp')) {
|
|
155
183
|
var _this$ro;
|
|
156
184
|
(_this$ro = this.ro) === null || _this$ro === void 0 ? void 0 : _this$ro.disconnect();
|
|
157
185
|
}
|
|
@@ -233,6 +261,19 @@ class CodeBlockAdvancedNodeView {
|
|
|
233
261
|
}
|
|
234
262
|
this.updating = false;
|
|
235
263
|
}
|
|
264
|
+
applyContentModeTheme(contentMode) {
|
|
265
|
+
if (contentMode === this.contentMode) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
this.contentMode = contentMode;
|
|
269
|
+
this.updating = true;
|
|
270
|
+
this.cm.dispatch({
|
|
271
|
+
effects: this.themeCompartment.reconfigure(cmTheme({
|
|
272
|
+
contentMode
|
|
273
|
+
}))
|
|
274
|
+
});
|
|
275
|
+
this.updating = false;
|
|
276
|
+
}
|
|
236
277
|
update(node, _, innerDecorations) {
|
|
237
278
|
this.maybeTryingToReachNodeSelection = false;
|
|
238
279
|
if (node.type !== this.node.type) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EditorState as CodeMirrorState } from '@codemirror/state';
|
|
2
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* To avoid issues with CRLF (\r\n) syncing with ProseMirror,
|
|
6
|
+
* we only consider \n for line separators.
|
|
7
|
+
*/
|
|
8
|
+
export const lineSeparatorExtension = () => {
|
|
9
|
+
if (expValEquals('platform_editor_fix_advanced_codeblocks_crlf', 'isEnabled', true)) {
|
|
10
|
+
return CodeMirrorState.lineSeparator.of('\n');
|
|
11
|
+
}
|
|
12
|
+
return [];
|
|
13
|
+
};
|
package/dist/es2019/ui/theme.js
CHANGED
|
@@ -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
|
|
5
|
-
const
|
|
6
|
-
|
|
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({
|