@atlaskit/editor-plugin-code-block-advanced 6.2.0 → 6.2.2
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 +16 -0
- package/dist/cjs/nodeviews/codeBlockAdvanced.js +44 -0
- package/dist/cjs/nodeviews/extensions/keymap/index.js +7 -6
- package/dist/cjs/ui/theme.js +2 -11
- package/dist/es2019/nodeviews/codeBlockAdvanced.js +33 -0
- package/dist/es2019/nodeviews/extensions/keymap/index.js +2 -1
- package/dist/es2019/ui/theme.js +1 -5
- package/dist/esm/nodeviews/codeBlockAdvanced.js +45 -0
- package/dist/esm/nodeviews/extensions/keymap/index.js +2 -1
- package/dist/esm/ui/theme.js +2 -10
- package/dist/types/nodeviews/codeBlockAdvanced.d.ts +1 -0
- package/dist/types-ts4.5/nodeviews/codeBlockAdvanced.d.ts +1 -0
- package/package.json +4 -4
- package/src/nodeviews/codeBlockAdvanced.ts +39 -0
- package/src/nodeviews/extensions/keymap/index.ts +4 -1
- package/src/ui/theme.ts +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block-advanced
|
|
2
2
|
|
|
3
|
+
## 6.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`b4284749422b0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b4284749422b0) -
|
|
8
|
+
[ux] Fix the code block gutter alignment issue when toggling content mode
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 6.2.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`2a658b46713fb`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2a658b46713fb) -
|
|
16
|
+
upgrade use of browser util
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 6.2.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -19,6 +19,7 @@ var _whitespace = require("@atlaskit/editor-common/whitespace");
|
|
|
19
19
|
var _state2 = require("@atlaskit/editor-prosemirror/state");
|
|
20
20
|
var _view2 = require("@atlaskit/editor-prosemirror/view");
|
|
21
21
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
22
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
22
23
|
var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
|
|
23
24
|
var _syntaxHighlightingTheme = require("../ui/syntaxHighlightingTheme");
|
|
24
25
|
var _theme = require("../ui/theme");
|
|
@@ -31,8 +32,13 @@ var _manageSelectionMarker = require("./extensions/manageSelectionMarker");
|
|
|
31
32
|
var _prosemirrorDecorations = require("./extensions/prosemirrorDecorations");
|
|
32
33
|
var _tripleClickExtension = require("./extensions/tripleClickExtension");
|
|
33
34
|
var _loader = require("./languages/loader");
|
|
35
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
36
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
37
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
34
38
|
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; }
|
|
35
39
|
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; }
|
|
40
|
+
// Store last observed heights of code blocks
|
|
41
|
+
var codeBlockHeights = new WeakMap();
|
|
36
42
|
// Based on: https://prosemirror.net/examples/codemirror/
|
|
37
43
|
var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
38
44
|
function CodeBlockAdvancedNodeView(node, view, getPos, innerDecorations, config) {
|
|
@@ -127,6 +133,40 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
127
133
|
this.dom = this.cm.dom;
|
|
128
134
|
this.dom.appendChild(spaceContainer);
|
|
129
135
|
|
|
136
|
+
// Observe size changes of the CodeMirror DOM and request a measurement pass
|
|
137
|
+
if ((0, _expValEquals.expValEquals)('cc_editor_ai_content_mode', 'variant', 'test') && (0, _platformFeatureFlags.fg)('platform_editor_content_mode_button_mvp')) {
|
|
138
|
+
this.ro = new ResizeObserver(function (entries) {
|
|
139
|
+
// Skip measurements when:
|
|
140
|
+
// 1. Currently updating (prevents feedback loops)
|
|
141
|
+
// 2. CodeMirror has focus (user is actively typing/editing)
|
|
142
|
+
if (_this.updating || _this.cm.hasFocus) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Only trigger on height changes, not width or other dimension changes
|
|
147
|
+
var _iterator = _createForOfIteratorHelper(entries),
|
|
148
|
+
_step;
|
|
149
|
+
try {
|
|
150
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
151
|
+
var entry = _step.value;
|
|
152
|
+
var currentHeight = entry.contentRect.height;
|
|
153
|
+
var lastHeight = codeBlockHeights.get(_this.cm.contentDOM);
|
|
154
|
+
if (lastHeight !== undefined && lastHeight === currentHeight) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
codeBlockHeights.set(_this.cm.contentDOM, currentHeight);
|
|
158
|
+
}
|
|
159
|
+
// CodeMirror to re-measure when its content size changes
|
|
160
|
+
} catch (err) {
|
|
161
|
+
_iterator.e(err);
|
|
162
|
+
} finally {
|
|
163
|
+
_iterator.f();
|
|
164
|
+
}
|
|
165
|
+
_this.cm.requestMeasure();
|
|
166
|
+
});
|
|
167
|
+
this.ro.observe(this.cm.contentDOM);
|
|
168
|
+
}
|
|
169
|
+
|
|
130
170
|
// This flag is used to avoid an update loop between the outer and
|
|
131
171
|
// inner editor
|
|
132
172
|
this.updating = false;
|
|
@@ -148,6 +188,10 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
148
188
|
// codemirror
|
|
149
189
|
this.clearProseMirrorDecorations();
|
|
150
190
|
(_this$cleanupDisabled = this.cleanupDisabledState) === null || _this$cleanupDisabled === void 0 || _this$cleanupDisabled.call(this);
|
|
191
|
+
if ((0, _expValEquals.expValEquals)('cc_editor_ai_content_mode', 'variant', 'test') && (0, _platformFeatureFlags.fg)('platform_editor_content_mode_button_mvp')) {
|
|
192
|
+
var _this$ro;
|
|
193
|
+
(_this$ro = this.ro) === null || _this$ro === void 0 || _this$ro.disconnect();
|
|
194
|
+
}
|
|
151
195
|
}
|
|
152
196
|
}, {
|
|
153
197
|
key: "forwardUpdate",
|
|
@@ -37,6 +37,7 @@ var codeBlockKeymap = function codeBlockKeymap(_ref2) {
|
|
|
37
37
|
selectCodeBlockNode = _ref2.selectCodeBlockNode,
|
|
38
38
|
onMaybeNodeSelection = _ref2.onMaybeNodeSelection,
|
|
39
39
|
customFindReplace = _ref2.customFindReplace;
|
|
40
|
+
var browser = (0, _expValEquals.expValEquals)('platform_editor_hydratable_ui', 'isEnabled', true) ? (0, _browser.getBrowserInfo)() : _browser.browser;
|
|
40
41
|
return [{
|
|
41
42
|
key: 'ArrowUp',
|
|
42
43
|
run: function run(cm) {
|
|
@@ -119,8 +120,8 @@ var codeBlockKeymap = function codeBlockKeymap(_ref2) {
|
|
|
119
120
|
view.dispatchEvent(new KeyboardEvent('keydown', {
|
|
120
121
|
key: 'f',
|
|
121
122
|
code: 'KeyF',
|
|
122
|
-
metaKey:
|
|
123
|
-
ctrlKey:
|
|
123
|
+
metaKey: browser.mac ? true : false,
|
|
124
|
+
ctrlKey: browser.mac ? false : true
|
|
124
125
|
}));
|
|
125
126
|
return true;
|
|
126
127
|
}
|
|
@@ -172,8 +173,8 @@ var codeBlockKeymap = function codeBlockKeymap(_ref2) {
|
|
|
172
173
|
view.dispatchEvent(new KeyboardEvent('keydown', {
|
|
173
174
|
key: ']',
|
|
174
175
|
code: 'BracketRight',
|
|
175
|
-
metaKey:
|
|
176
|
-
ctrlKey:
|
|
176
|
+
metaKey: browser.mac ? true : false,
|
|
177
|
+
ctrlKey: browser.mac ? false : true,
|
|
177
178
|
altKey: true
|
|
178
179
|
}));
|
|
179
180
|
return true;
|
|
@@ -189,8 +190,8 @@ var codeBlockKeymap = function codeBlockKeymap(_ref2) {
|
|
|
189
190
|
view.dispatchEvent(new KeyboardEvent('keydown', {
|
|
190
191
|
key: ']',
|
|
191
192
|
code: 'BracketLeft',
|
|
192
|
-
metaKey:
|
|
193
|
-
ctrlKey:
|
|
193
|
+
metaKey: browser.mac ? true : false,
|
|
194
|
+
ctrlKey: browser.mac ? false : true,
|
|
194
195
|
altKey: true
|
|
195
196
|
}));
|
|
196
197
|
return true;
|
package/dist/cjs/ui/theme.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.codeFoldingTheme = exports.cmTheme = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
7
|
var _view = require("@codemirror/view");
|
|
10
8
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
11
9
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
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; }
|
|
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; }
|
|
14
10
|
var getLineHeight = function getLineHeight() {
|
|
15
11
|
return (0, _expValEquals.expValEquals)('cc_editor_ai_content_mode', 'variant', 'test') && (0, _platformFeatureFlags.fg)('platform_editor_content_mode_button_mvp') ? '1.5em' : '1.5rem';
|
|
16
12
|
};
|
|
17
|
-
var getMaxGutterHeight = function getMaxGutterHeight() {
|
|
18
|
-
return (0, _expValEquals.expValEquals)('cc_editor_ai_content_mode', 'variant', 'test') && (0, _platformFeatureFlags.fg)('platform_editor_content_mode_button_mvp') ? '1.5em' : undefined;
|
|
19
|
-
};
|
|
20
13
|
var getFontSize = function getFontSize() {
|
|
21
14
|
return (0, _expValEquals.expValEquals)('cc_editor_ai_content_mode', 'variant', 'test') && (0, _platformFeatureFlags.fg)('platform_editor_content_mode_button_mvp') ? '0.875em' : '0.875rem';
|
|
22
15
|
};
|
|
@@ -83,12 +76,10 @@ var cmTheme = exports.cmTheme = _view.EditorView.theme({
|
|
|
83
76
|
// codemirror is calculating (which happens after an animation frame).
|
|
84
77
|
// Example problem: https://github.com/codemirror/dev/issues/1076
|
|
85
78
|
// Ignore the first gutter element as it is a special hidden element.
|
|
86
|
-
'.cm-gutterElement:not(:first-child)':
|
|
79
|
+
'.cm-gutterElement:not(:first-child)': {
|
|
87
80
|
// eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
|
|
88
81
|
minHeight: getLineHeight()
|
|
89
|
-
}
|
|
90
|
-
maxHeight: getMaxGutterHeight()
|
|
91
|
-
})
|
|
82
|
+
}
|
|
92
83
|
});
|
|
93
84
|
var codeFoldingTheme = exports.codeFoldingTheme = _view.EditorView.theme({
|
|
94
85
|
'.cm-gutter': {
|
|
@@ -9,9 +9,13 @@ import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
|
|
|
9
9
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
10
10
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
11
11
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
12
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
12
13
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
13
14
|
import { highlightStyle } from '../ui/syntaxHighlightingTheme';
|
|
14
15
|
import { cmTheme, codeFoldingTheme } from '../ui/theme';
|
|
16
|
+
|
|
17
|
+
// Store last observed heights of code blocks
|
|
18
|
+
const codeBlockHeights = new WeakMap();
|
|
15
19
|
import { syncCMWithPM } from './codemirrorSync/syncCMWithPM';
|
|
16
20
|
import { getCMSelectionChanges } from './codemirrorSync/updateCMSelection';
|
|
17
21
|
import { firstCodeBlockInDocument } from './extensions/firstCodeBlockInDocument';
|
|
@@ -103,6 +107,31 @@ class CodeBlockAdvancedNodeView {
|
|
|
103
107
|
this.dom = this.cm.dom;
|
|
104
108
|
this.dom.appendChild(spaceContainer);
|
|
105
109
|
|
|
110
|
+
// Observe size changes of the CodeMirror DOM and request a measurement pass
|
|
111
|
+
if (expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp')) {
|
|
112
|
+
this.ro = new ResizeObserver(entries => {
|
|
113
|
+
// Skip measurements when:
|
|
114
|
+
// 1. Currently updating (prevents feedback loops)
|
|
115
|
+
// 2. CodeMirror has focus (user is actively typing/editing)
|
|
116
|
+
if (this.updating || this.cm.hasFocus) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Only trigger on height changes, not width or other dimension changes
|
|
121
|
+
for (const entry of entries) {
|
|
122
|
+
const currentHeight = entry.contentRect.height;
|
|
123
|
+
const lastHeight = codeBlockHeights.get(this.cm.contentDOM);
|
|
124
|
+
if (lastHeight !== undefined && lastHeight === currentHeight) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
codeBlockHeights.set(this.cm.contentDOM, currentHeight);
|
|
128
|
+
}
|
|
129
|
+
// CodeMirror to re-measure when its content size changes
|
|
130
|
+
this.cm.requestMeasure();
|
|
131
|
+
});
|
|
132
|
+
this.ro.observe(this.cm.contentDOM);
|
|
133
|
+
}
|
|
134
|
+
|
|
106
135
|
// This flag is used to avoid an update loop between the outer and
|
|
107
136
|
// inner editor
|
|
108
137
|
this.updating = false;
|
|
@@ -122,6 +151,10 @@ class CodeBlockAdvancedNodeView {
|
|
|
122
151
|
// codemirror
|
|
123
152
|
this.clearProseMirrorDecorations();
|
|
124
153
|
(_this$cleanupDisabled = this.cleanupDisabledState) === null || _this$cleanupDisabled === void 0 ? void 0 : _this$cleanupDisabled.call(this);
|
|
154
|
+
if (expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp')) {
|
|
155
|
+
var _this$ro;
|
|
156
|
+
(_this$ro = this.ro) === null || _this$ro === void 0 ? void 0 : _this$ro.disconnect();
|
|
157
|
+
}
|
|
125
158
|
}
|
|
126
159
|
forwardUpdate(update) {
|
|
127
160
|
var _this$getPos, _this$getPos2;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defaultKeymap, indentWithTab } from '@codemirror/commands';
|
|
2
2
|
import { keymap as cmKeymap } from '@codemirror/view';
|
|
3
|
-
import { browser } from '@atlaskit/editor-common/browser';
|
|
3
|
+
import { browser as browserLegacy, getBrowserInfo } from '@atlaskit/editor-common/browser';
|
|
4
4
|
import { exitCode, selectAll } from '@atlaskit/editor-prosemirror/commands';
|
|
5
5
|
import { undo, redo } from '@atlaskit/prosemirror-history';
|
|
6
6
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
@@ -31,6 +31,7 @@ const codeBlockKeymap = ({
|
|
|
31
31
|
onMaybeNodeSelection,
|
|
32
32
|
customFindReplace
|
|
33
33
|
}) => {
|
|
34
|
+
const browser = expValEquals('platform_editor_hydratable_ui', 'isEnabled', true) ? getBrowserInfo() : browserLegacy;
|
|
34
35
|
return [{
|
|
35
36
|
key: 'ArrowUp',
|
|
36
37
|
run: cm => maybeEscapeKeymap({
|
package/dist/es2019/ui/theme.js
CHANGED
|
@@ -2,7 +2,6 @@ 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
4
|
const getLineHeight = () => expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp') ? '1.5em' : '1.5rem';
|
|
5
|
-
const getMaxGutterHeight = () => expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp') ? '1.5em' : undefined;
|
|
6
5
|
const getFontSize = () => expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp') ? '0.875em' : '0.875rem';
|
|
7
6
|
export const cmTheme = CodeMirror.theme({
|
|
8
7
|
'&': {
|
|
@@ -69,10 +68,7 @@ export const cmTheme = CodeMirror.theme({
|
|
|
69
68
|
// Ignore the first gutter element as it is a special hidden element.
|
|
70
69
|
'.cm-gutterElement:not(:first-child)': {
|
|
71
70
|
// eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
|
|
72
|
-
minHeight: getLineHeight()
|
|
73
|
-
...(getMaxGutterHeight() && {
|
|
74
|
-
maxHeight: getMaxGutterHeight()
|
|
75
|
-
})
|
|
71
|
+
minHeight: getLineHeight()
|
|
76
72
|
}
|
|
77
73
|
});
|
|
78
74
|
export const codeFoldingTheme = CodeMirror.theme({
|
|
@@ -2,6 +2,9 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
|
2
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
4
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
6
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
7
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
5
8
|
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; }
|
|
6
9
|
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; }
|
|
7
10
|
import { closeBrackets } from '@codemirror/autocomplete';
|
|
@@ -14,9 +17,13 @@ import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
|
|
|
14
17
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
15
18
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
16
19
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
20
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
17
21
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
18
22
|
import { highlightStyle } from '../ui/syntaxHighlightingTheme';
|
|
19
23
|
import { cmTheme, codeFoldingTheme } from '../ui/theme';
|
|
24
|
+
|
|
25
|
+
// Store last observed heights of code blocks
|
|
26
|
+
var codeBlockHeights = new WeakMap();
|
|
20
27
|
import { syncCMWithPM } from './codemirrorSync/syncCMWithPM';
|
|
21
28
|
import { getCMSelectionChanges } from './codemirrorSync/updateCMSelection';
|
|
22
29
|
import { firstCodeBlockInDocument } from './extensions/firstCodeBlockInDocument';
|
|
@@ -120,6 +127,40 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
120
127
|
this.dom = this.cm.dom;
|
|
121
128
|
this.dom.appendChild(spaceContainer);
|
|
122
129
|
|
|
130
|
+
// Observe size changes of the CodeMirror DOM and request a measurement pass
|
|
131
|
+
if (expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp')) {
|
|
132
|
+
this.ro = new ResizeObserver(function (entries) {
|
|
133
|
+
// Skip measurements when:
|
|
134
|
+
// 1. Currently updating (prevents feedback loops)
|
|
135
|
+
// 2. CodeMirror has focus (user is actively typing/editing)
|
|
136
|
+
if (_this.updating || _this.cm.hasFocus) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Only trigger on height changes, not width or other dimension changes
|
|
141
|
+
var _iterator = _createForOfIteratorHelper(entries),
|
|
142
|
+
_step;
|
|
143
|
+
try {
|
|
144
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
145
|
+
var entry = _step.value;
|
|
146
|
+
var currentHeight = entry.contentRect.height;
|
|
147
|
+
var lastHeight = codeBlockHeights.get(_this.cm.contentDOM);
|
|
148
|
+
if (lastHeight !== undefined && lastHeight === currentHeight) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
codeBlockHeights.set(_this.cm.contentDOM, currentHeight);
|
|
152
|
+
}
|
|
153
|
+
// CodeMirror to re-measure when its content size changes
|
|
154
|
+
} catch (err) {
|
|
155
|
+
_iterator.e(err);
|
|
156
|
+
} finally {
|
|
157
|
+
_iterator.f();
|
|
158
|
+
}
|
|
159
|
+
_this.cm.requestMeasure();
|
|
160
|
+
});
|
|
161
|
+
this.ro.observe(this.cm.contentDOM);
|
|
162
|
+
}
|
|
163
|
+
|
|
123
164
|
// This flag is used to avoid an update loop between the outer and
|
|
124
165
|
// inner editor
|
|
125
166
|
this.updating = false;
|
|
@@ -141,6 +182,10 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
141
182
|
// codemirror
|
|
142
183
|
this.clearProseMirrorDecorations();
|
|
143
184
|
(_this$cleanupDisabled = this.cleanupDisabledState) === null || _this$cleanupDisabled === void 0 || _this$cleanupDisabled.call(this);
|
|
185
|
+
if (expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp')) {
|
|
186
|
+
var _this$ro;
|
|
187
|
+
(_this$ro = this.ro) === null || _this$ro === void 0 || _this$ro.disconnect();
|
|
188
|
+
}
|
|
144
189
|
}
|
|
145
190
|
}, {
|
|
146
191
|
key: "forwardUpdate",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import { defaultKeymap, indentWithTab } from '@codemirror/commands';
|
|
3
3
|
import { keymap as cmKeymap } from '@codemirror/view';
|
|
4
|
-
import { browser } from '@atlaskit/editor-common/browser';
|
|
4
|
+
import { browser as browserLegacy, getBrowserInfo } from '@atlaskit/editor-common/browser';
|
|
5
5
|
import { exitCode, selectAll } from '@atlaskit/editor-prosemirror/commands';
|
|
6
6
|
import { undo, redo } from '@atlaskit/prosemirror-history';
|
|
7
7
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
@@ -30,6 +30,7 @@ var codeBlockKeymap = function codeBlockKeymap(_ref2) {
|
|
|
30
30
|
selectCodeBlockNode = _ref2.selectCodeBlockNode,
|
|
31
31
|
onMaybeNodeSelection = _ref2.onMaybeNodeSelection,
|
|
32
32
|
customFindReplace = _ref2.customFindReplace;
|
|
33
|
+
var browser = expValEquals('platform_editor_hydratable_ui', 'isEnabled', true) ? getBrowserInfo() : browserLegacy;
|
|
33
34
|
return [{
|
|
34
35
|
key: 'ArrowUp',
|
|
35
36
|
run: function run(cm) {
|
package/dist/esm/ui/theme.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
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
|
-
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
1
|
import { EditorView as CodeMirror } from '@codemirror/view';
|
|
5
2
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
3
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
7
4
|
var getLineHeight = function getLineHeight() {
|
|
8
5
|
return expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp') ? '1.5em' : '1.5rem';
|
|
9
6
|
};
|
|
10
|
-
var getMaxGutterHeight = function getMaxGutterHeight() {
|
|
11
|
-
return expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp') ? '1.5em' : undefined;
|
|
12
|
-
};
|
|
13
7
|
var getFontSize = function getFontSize() {
|
|
14
8
|
return expValEquals('cc_editor_ai_content_mode', 'variant', 'test') && fg('platform_editor_content_mode_button_mvp') ? '0.875em' : '0.875rem';
|
|
15
9
|
};
|
|
@@ -76,12 +70,10 @@ export var cmTheme = CodeMirror.theme({
|
|
|
76
70
|
// codemirror is calculating (which happens after an animation frame).
|
|
77
71
|
// Example problem: https://github.com/codemirror/dev/issues/1076
|
|
78
72
|
// Ignore the first gutter element as it is a special hidden element.
|
|
79
|
-
'.cm-gutterElement:not(:first-child)':
|
|
73
|
+
'.cm-gutterElement:not(:first-child)': {
|
|
80
74
|
// eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
|
|
81
75
|
minHeight: getLineHeight()
|
|
82
|
-
}
|
|
83
|
-
maxHeight: getMaxGutterHeight()
|
|
84
|
-
})
|
|
76
|
+
}
|
|
85
77
|
});
|
|
86
78
|
export var codeFoldingTheme = CodeMirror.theme({
|
|
87
79
|
'.cm-gutter': {
|
|
@@ -27,6 +27,7 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
27
27
|
private cleanupDisabledState;
|
|
28
28
|
private languageLoader;
|
|
29
29
|
private pmFacet;
|
|
30
|
+
private ro?;
|
|
30
31
|
constructor(node: PMNode, view: EditorView, getPos: getPosHandlerNode, innerDecorations: DecorationSource, config: ConfigProps);
|
|
31
32
|
destroy(): void;
|
|
32
33
|
forwardUpdate(update: ViewUpdate): void;
|
|
@@ -27,6 +27,7 @@ declare class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
27
27
|
private cleanupDisabledState;
|
|
28
28
|
private languageLoader;
|
|
29
29
|
private pmFacet;
|
|
30
|
+
private ro?;
|
|
30
31
|
constructor(node: PMNode, view: EditorView, getPos: getPosHandlerNode, innerDecorations: DecorationSource, config: ConfigProps);
|
|
31
32
|
destroy(): void;
|
|
32
33
|
forwardUpdate(update: ViewUpdate): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-code-block-advanced",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.2",
|
|
4
4
|
"description": "CodeBlockAdvanced plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"atlaskit:src": "src/index.ts",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atlaskit/adf-schema": "^51.3.0",
|
|
32
|
-
"@atlaskit/editor-plugin-block-menu": "^
|
|
32
|
+
"@atlaskit/editor-plugin-block-menu": "^5.0.0",
|
|
33
33
|
"@atlaskit/editor-plugin-code-block": "^8.1.0",
|
|
34
34
|
"@atlaskit/editor-plugin-editor-disabled": "^6.1.0",
|
|
35
35
|
"@atlaskit/editor-plugin-find-replace": "^6.0.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@atlaskit/icon": "^28.5.0",
|
|
41
41
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
42
42
|
"@atlaskit/prosemirror-history": "^0.2.0",
|
|
43
|
-
"@atlaskit/tmp-editor-statsig": "^13.
|
|
43
|
+
"@atlaskit/tmp-editor-statsig": "^13.16.0",
|
|
44
44
|
"@atlaskit/tokens": "^7.0.0",
|
|
45
45
|
"@babel/runtime": "^7.0.0",
|
|
46
46
|
"@codemirror/autocomplete": "6.18.4",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"codemirror-lang-elixir": "4.0.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@atlaskit/editor-common": "^110.
|
|
60
|
+
"@atlaskit/editor-common": "^110.15.0",
|
|
61
61
|
"react": "^18.2.0",
|
|
62
62
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
63
63
|
},
|
|
@@ -30,12 +30,16 @@ import type {
|
|
|
30
30
|
} from '@atlaskit/editor-prosemirror/view';
|
|
31
31
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
32
32
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
33
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
33
34
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
34
35
|
|
|
35
36
|
import type { CodeBlockAdvancedPlugin } from '../codeBlockAdvancedPluginType';
|
|
36
37
|
import { highlightStyle } from '../ui/syntaxHighlightingTheme';
|
|
37
38
|
import { cmTheme, codeFoldingTheme } from '../ui/theme';
|
|
38
39
|
|
|
40
|
+
// Store last observed heights of code blocks
|
|
41
|
+
const codeBlockHeights = new WeakMap<HTMLElement, number>();
|
|
42
|
+
|
|
39
43
|
import { syncCMWithPM } from './codemirrorSync/syncCMWithPM';
|
|
40
44
|
import { getCMSelectionChanges } from './codemirrorSync/updateCMSelection';
|
|
41
45
|
import { firstCodeBlockInDocument } from './extensions/firstCodeBlockInDocument';
|
|
@@ -70,6 +74,7 @@ class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
70
74
|
private cleanupDisabledState: (() => void) | undefined;
|
|
71
75
|
private languageLoader: LanguageLoader;
|
|
72
76
|
private pmFacet = Facet.define<DecorationSource>();
|
|
77
|
+
private ro?: ResizeObserver;
|
|
73
78
|
|
|
74
79
|
constructor(
|
|
75
80
|
node: PMNode,
|
|
@@ -167,6 +172,34 @@ class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
167
172
|
this.dom = this.cm.dom;
|
|
168
173
|
this.dom.appendChild(spaceContainer);
|
|
169
174
|
|
|
175
|
+
// Observe size changes of the CodeMirror DOM and request a measurement pass
|
|
176
|
+
if (
|
|
177
|
+
expValEquals('cc_editor_ai_content_mode', 'variant', 'test') &&
|
|
178
|
+
fg('platform_editor_content_mode_button_mvp')
|
|
179
|
+
) {
|
|
180
|
+
this.ro = new ResizeObserver((entries) => {
|
|
181
|
+
// Skip measurements when:
|
|
182
|
+
// 1. Currently updating (prevents feedback loops)
|
|
183
|
+
// 2. CodeMirror has focus (user is actively typing/editing)
|
|
184
|
+
if (this.updating || this.cm.hasFocus) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Only trigger on height changes, not width or other dimension changes
|
|
189
|
+
for (const entry of entries) {
|
|
190
|
+
const currentHeight = entry.contentRect.height;
|
|
191
|
+
const lastHeight = codeBlockHeights.get(this.cm.contentDOM);
|
|
192
|
+
if (lastHeight !== undefined && lastHeight === currentHeight) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
codeBlockHeights.set(this.cm.contentDOM, currentHeight);
|
|
196
|
+
}
|
|
197
|
+
// CodeMirror to re-measure when its content size changes
|
|
198
|
+
this.cm.requestMeasure();
|
|
199
|
+
});
|
|
200
|
+
this.ro.observe(this.cm.contentDOM);
|
|
201
|
+
}
|
|
202
|
+
|
|
170
203
|
// This flag is used to avoid an update loop between the outer and
|
|
171
204
|
// inner editor
|
|
172
205
|
this.updating = false;
|
|
@@ -186,6 +219,12 @@ class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
186
219
|
// codemirror
|
|
187
220
|
this.clearProseMirrorDecorations();
|
|
188
221
|
this.cleanupDisabledState?.();
|
|
222
|
+
if (
|
|
223
|
+
expValEquals('cc_editor_ai_content_mode', 'variant', 'test') &&
|
|
224
|
+
fg('platform_editor_content_mode_button_mvp')
|
|
225
|
+
) {
|
|
226
|
+
this.ro?.disconnect();
|
|
227
|
+
}
|
|
189
228
|
}
|
|
190
229
|
|
|
191
230
|
forwardUpdate(update: ViewUpdate) {
|
|
@@ -2,7 +2,7 @@ import { defaultKeymap, indentWithTab } from '@codemirror/commands';
|
|
|
2
2
|
import { type Extension } from '@codemirror/state';
|
|
3
3
|
import { type KeyBinding, keymap as cmKeymap } from '@codemirror/view';
|
|
4
4
|
|
|
5
|
-
import { browser } from '@atlaskit/editor-common/browser';
|
|
5
|
+
import { browser as browserLegacy, getBrowserInfo } from '@atlaskit/editor-common/browser';
|
|
6
6
|
import { type RelativeSelectionPos } from '@atlaskit/editor-common/selection';
|
|
7
7
|
import type { getPosHandlerNode } from '@atlaskit/editor-common/types';
|
|
8
8
|
import { exitCode, selectAll } from '@atlaskit/editor-prosemirror/commands';
|
|
@@ -51,6 +51,9 @@ const codeBlockKeymap = ({
|
|
|
51
51
|
onMaybeNodeSelection,
|
|
52
52
|
customFindReplace,
|
|
53
53
|
}: KeymapProps): readonly KeyBinding[] => {
|
|
54
|
+
const browser = expValEquals('platform_editor_hydratable_ui', 'isEnabled', true)
|
|
55
|
+
? getBrowserInfo()
|
|
56
|
+
: browserLegacy;
|
|
54
57
|
return [
|
|
55
58
|
{
|
|
56
59
|
key: 'ArrowUp',
|
package/src/ui/theme.ts
CHANGED
|
@@ -10,12 +10,6 @@ const getLineHeight = () =>
|
|
|
10
10
|
? '1.5em'
|
|
11
11
|
: '1.5rem';
|
|
12
12
|
|
|
13
|
-
const getMaxGutterHeight = () =>
|
|
14
|
-
expValEquals('cc_editor_ai_content_mode', 'variant', 'test') &&
|
|
15
|
-
fg('platform_editor_content_mode_button_mvp')
|
|
16
|
-
? '1.5em'
|
|
17
|
-
: undefined;
|
|
18
|
-
|
|
19
13
|
const getFontSize = () =>
|
|
20
14
|
expValEquals('cc_editor_ai_content_mode', 'variant', 'test') &&
|
|
21
15
|
fg('platform_editor_content_mode_button_mvp')
|
|
@@ -88,7 +82,6 @@ export const cmTheme = CodeMirror.theme({
|
|
|
88
82
|
'.cm-gutterElement:not(:first-child)': {
|
|
89
83
|
// eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
|
|
90
84
|
minHeight: getLineHeight(),
|
|
91
|
-
...(getMaxGutterHeight() && { maxHeight: getMaxGutterHeight() }),
|
|
92
85
|
},
|
|
93
86
|
});
|
|
94
87
|
|