@atlaskit/editor-plugin-code-block 3.3.11 → 3.3.13
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 +21 -0
- package/dist/cjs/nodeviews/code-block.js +7 -3
- package/dist/cjs/pm-plugins/decorators.js +12 -4
- package/dist/cjs/pm-plugins/main.js +19 -14
- package/dist/cjs/refresh-browser-selection.js +2 -2
- package/dist/es2019/nodeviews/code-block.js +5 -2
- package/dist/es2019/pm-plugins/decorators.js +11 -4
- package/dist/es2019/pm-plugins/main.js +10 -3
- package/dist/es2019/refresh-browser-selection.js +1 -1
- package/dist/esm/nodeviews/code-block.js +5 -2
- package/dist/esm/pm-plugins/decorators.js +11 -4
- package/dist/esm/pm-plugins/main.js +10 -3
- package/dist/esm/refresh-browser-selection.js +1 -1
- package/dist/types/pm-plugins/decorators.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/decorators.d.ts +1 -1
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block
|
|
2
2
|
|
|
3
|
+
## 3.3.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#136871](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/136871)
|
|
8
|
+
[`87a30d5cb3ffb`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/87a30d5cb3ffb) -
|
|
9
|
+
ED-24814 - Addressing a bug where changing the language on a wrapped code block caused the wrapped
|
|
10
|
+
decorator to disappear. Required changing the sequence in which we update the keys on the wrapped
|
|
11
|
+
states WeakMap. Due to the amount of changes, it has all be placed behind a bug fix feature gate
|
|
12
|
+
(editor_code_block_wrapping_language_change_bug) and the original feature gate
|
|
13
|
+
(editor_support_code_block_wrapping).
|
|
14
|
+
|
|
15
|
+
## 3.3.12
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#136348](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/136348)
|
|
20
|
+
[`fb4fb56f1da7c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/fb4fb56f1da7c) -
|
|
21
|
+
Use optimised entry-points on editor-common for browser.
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
|
|
3
24
|
## 3.3.11
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -9,13 +9,15 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
9
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
var _rafSchd = _interopRequireDefault(require("raf-schd"));
|
|
12
|
+
var _browser = require("@atlaskit/editor-common/browser");
|
|
12
13
|
var _codeBlock = require("@atlaskit/editor-common/code-block");
|
|
13
|
-
var _utils = require("@atlaskit/editor-common/utils");
|
|
14
14
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
15
15
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
16
16
|
var _actions = require("../actions");
|
|
17
17
|
var _mainState = require("../pm-plugins/main-state");
|
|
18
18
|
var _classNames = require("../ui/class-names");
|
|
19
|
+
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
20
|
+
|
|
19
21
|
var MATCH_NEWLINES = new RegExp('\n', 'g');
|
|
20
22
|
var toDOM = function toDOM(node, contentEditable, formattedAriaLabel) {
|
|
21
23
|
return ['div', {
|
|
@@ -167,7 +169,9 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
|
167
169
|
}
|
|
168
170
|
if (node !== this.node) {
|
|
169
171
|
if ((0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping')) {
|
|
170
|
-
(0,
|
|
172
|
+
if (!(0, _platformFeatureFlags.fg)('editor_code_block_wrapping_language_change_bug')) {
|
|
173
|
+
(0, _codeBlock.transferCodeBlockWrappedValue)(this.node, node);
|
|
174
|
+
}
|
|
171
175
|
}
|
|
172
176
|
if (node.attrs.language !== this.node.attrs.language) {
|
|
173
177
|
this.contentDOM.setAttribute('data-language', node.attrs.language || '');
|
|
@@ -178,7 +182,7 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
|
178
182
|
} else {
|
|
179
183
|
this.ensureLineNumbers();
|
|
180
184
|
}
|
|
181
|
-
if (
|
|
185
|
+
if (_browser.browser.android) {
|
|
182
186
|
this.coalesceDOMElements();
|
|
183
187
|
(0, _actions.resetShouldIgnoreFollowingMutations)(this.view.state, this.view.dispatch);
|
|
184
188
|
}
|
|
@@ -8,8 +8,11 @@ exports.validateWordWrappedDecorators = exports.updateDecorationSetWithWordWrapp
|
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _codeBlock = require("@atlaskit/editor-common/code-block");
|
|
10
10
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
11
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
11
12
|
var _classNames = require("../ui/class-names");
|
|
12
13
|
var _utils = require("../utils");
|
|
14
|
+
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
15
|
+
|
|
13
16
|
var DECORATION_WIDGET_TYPE = exports.DECORATION_WIDGET_TYPE = 'decorationWidgetType';
|
|
14
17
|
var DECORATION_WRAPPED_BLOCK_NODE_TYPE = exports.DECORATION_WRAPPED_BLOCK_NODE_TYPE = 'decorationNodeType';
|
|
15
18
|
|
|
@@ -26,9 +29,8 @@ var generateInitialDecorations = exports.generateInitialDecorations = function g
|
|
|
26
29
|
/**
|
|
27
30
|
* Update all the decorations used by the code block.
|
|
28
31
|
*/
|
|
29
|
-
var updateCodeBlockDecorations = exports.updateCodeBlockDecorations = function updateCodeBlockDecorations(tr,
|
|
32
|
+
var updateCodeBlockDecorations = exports.updateCodeBlockDecorations = function updateCodeBlockDecorations(tr, codeBlockNodes, decorationSet) {
|
|
30
33
|
var updatedDecorationSet = decorationSet;
|
|
31
|
-
var codeBlockNodes = (0, _utils.getAllCodeBlockNodesInDoc)(state);
|
|
32
34
|
|
|
33
35
|
// All the line numbers decorators are refreshed on doc change.
|
|
34
36
|
updatedDecorationSet = updateDecorationSetWithLineNumberDecorators(tr, codeBlockNodes, updatedDecorationSet);
|
|
@@ -129,8 +131,14 @@ var validateWordWrappedDecorators = exports.validateWordWrappedDecorators = func
|
|
|
129
131
|
codeBlockNodes.forEach(function (node) {
|
|
130
132
|
var isCodeBlockWrappedInState = (0, _codeBlock.isCodeBlockWordWrapEnabled)(node.node);
|
|
131
133
|
var isCodeBlockWrappedByDecorator = getWordWrapDecoratorsFromNodePos(node.pos, decorationSet).length !== 0;
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
+
if ((0, _platformFeatureFlags.fg)('editor_code_block_wrapping_language_change_bug')) {
|
|
135
|
+
if (isCodeBlockWrappedInState !== isCodeBlockWrappedByDecorator) {
|
|
136
|
+
updatedDecorationSet = updateDecorationSetWithWordWrappedDecorator(decorationSet, tr, node);
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
if (isCodeBlockWrappedInState && !isCodeBlockWrappedByDecorator) {
|
|
140
|
+
updatedDecorationSet = updateDecorationSetWithWordWrappedDecorator(decorationSet, tr, node);
|
|
141
|
+
}
|
|
134
142
|
}
|
|
135
143
|
});
|
|
136
144
|
return updatedDecorationSet;
|
|
@@ -6,22 +6,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createPlugin = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _browser = require("@atlaskit/editor-common/browser");
|
|
10
|
+
var _codeBlock = require("@atlaskit/editor-common/code-block");
|
|
9
11
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
10
12
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
13
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
12
|
-
var _utils = require("@atlaskit/editor-common/utils");
|
|
13
14
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
14
15
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
15
16
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
16
17
|
var _actions = require("../actions");
|
|
17
|
-
var
|
|
18
|
+
var _codeBlock2 = require("../nodeviews/code-block");
|
|
18
19
|
var _pluginKey = require("../plugin-key");
|
|
19
20
|
var _classNames = require("../ui/class-names");
|
|
20
|
-
var
|
|
21
|
+
var _utils = require("../utils");
|
|
21
22
|
var _actions2 = require("./actions");
|
|
22
23
|
var _decorators = require("./decorators");
|
|
23
24
|
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; }
|
|
24
|
-
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; }
|
|
25
|
+
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; } /* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
25
26
|
var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
26
27
|
var _ref$useLongPressSele = _ref.useLongPressSelection,
|
|
27
28
|
useLongPressSelection = _ref$useLongPressSele === void 0 ? false : _ref$useLongPressSele,
|
|
@@ -38,12 +39,12 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
38
39
|
var keyEvent = event;
|
|
39
40
|
var eventInputType = keyEvent.inputType;
|
|
40
41
|
var eventText = keyEvent.data;
|
|
41
|
-
if (
|
|
42
|
+
if (_browser.browser.ios && event.composed &&
|
|
42
43
|
// insertParagraph will be the input type when the enter key is pressed.
|
|
43
|
-
eventInputType === 'insertParagraph' && (0,
|
|
44
|
+
eventInputType === 'insertParagraph' && (0, _utils.findCodeBlock)(view.state, view.state.selection)) {
|
|
44
45
|
event.preventDefault();
|
|
45
46
|
return true;
|
|
46
|
-
} else if (
|
|
47
|
+
} else if (_browser.browser.android && event.composed && eventInputType === 'insertCompositionText' && eventText[(eventText === null || eventText === void 0 ? void 0 : eventText.length) - 1] === '\n' && (0, _utils.findCodeBlock)(view.state, view.state.selection)) {
|
|
47
48
|
var resultingText = event.target.outerText + '\n';
|
|
48
49
|
if (resultingText.endsWith(eventText)) {
|
|
49
50
|
// End of paragraph
|
|
@@ -63,7 +64,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
63
64
|
}
|
|
64
65
|
return true;
|
|
65
66
|
}
|
|
66
|
-
if (
|
|
67
|
+
if (_browser.browser.android) {
|
|
67
68
|
(0, _actions.resetShouldIgnoreFollowingMutations)(view.state, view.dispatch);
|
|
68
69
|
}
|
|
69
70
|
return false;
|
|
@@ -72,7 +73,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
72
73
|
return new _safePlugin.SafePlugin({
|
|
73
74
|
state: {
|
|
74
75
|
init: function init(_, state) {
|
|
75
|
-
var node = (0,
|
|
76
|
+
var node = (0, _utils.findCodeBlock)(state, state.selection);
|
|
76
77
|
var initialDecorations = (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping') ? (0, _decorators.generateInitialDecorations)(state) : [];
|
|
77
78
|
return {
|
|
78
79
|
pos: node ? node.pos : null,
|
|
@@ -85,19 +86,23 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
85
86
|
apply: function apply(tr, pluginState, _oldState, newState) {
|
|
86
87
|
var meta = tr.getMeta(_pluginKey.pluginKey);
|
|
87
88
|
if ((meta === null || meta === void 0 ? void 0 : meta.type) === _actions2.ACTIONS.SET_IS_WRAPPED && (0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping')) {
|
|
88
|
-
var node = (0,
|
|
89
|
+
var node = (0, _utils.findCodeBlock)(newState, tr.selection);
|
|
89
90
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
90
91
|
decorations: (0, _decorators.updateDecorationSetWithWordWrappedDecorator)(pluginState.decorations, tr, node)
|
|
91
92
|
});
|
|
92
93
|
}
|
|
93
94
|
if (tr.docChanged) {
|
|
94
|
-
var _node = (0,
|
|
95
|
+
var _node = (0, _utils.findCodeBlock)(newState, tr.selection);
|
|
95
96
|
|
|
96
97
|
// Updates mapping position of all existing decorations to new positions
|
|
97
98
|
// specifically used for updating word wrap node decorators (does not cover drag & drop, validateWordWrappedDecorators does).
|
|
98
99
|
var updatedDecorationSet = pluginState.decorations.map(tr.mapping, tr.doc);
|
|
99
100
|
if ((0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping')) {
|
|
100
|
-
|
|
101
|
+
var codeBlockNodes = (0, _utils.getAllCodeBlockNodesInDoc)(newState);
|
|
102
|
+
if ((0, _platformFeatureFlags.fg)('editor_code_block_wrapping_language_change_bug')) {
|
|
103
|
+
(0, _codeBlock.updateCodeBlockWrappedStateNodeKeys)(codeBlockNodes, _oldState);
|
|
104
|
+
}
|
|
105
|
+
updatedDecorationSet = (0, _decorators.updateCodeBlockDecorations)(tr, codeBlockNodes, updatedDecorationSet);
|
|
101
106
|
}
|
|
102
107
|
var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
103
108
|
pos: _node ? _node.pos : null,
|
|
@@ -107,7 +112,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
107
112
|
return newPluginState;
|
|
108
113
|
}
|
|
109
114
|
if (tr.selectionSet) {
|
|
110
|
-
var _node2 = (0,
|
|
115
|
+
var _node2 = (0, _utils.findCodeBlock)(newState, tr.selection);
|
|
111
116
|
var _newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
112
117
|
pos: _node2 ? _node2.pos : null,
|
|
113
118
|
isNodeSelected: tr.selection instanceof _state.NodeSelection
|
|
@@ -139,7 +144,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
139
144
|
var _getIntl = getIntl(),
|
|
140
145
|
formatMessage = _getIntl.formatMessage;
|
|
141
146
|
var formattedAriaLabel = formatMessage(_messages.blockTypeMessages.codeblock);
|
|
142
|
-
return (0,
|
|
147
|
+
return (0, _codeBlock2.codeBlockNodeView)(node, view, getPos, formattedAriaLabel, api);
|
|
143
148
|
}
|
|
144
149
|
},
|
|
145
150
|
handleClickOn: (0, _selection.createSelectionClickHandler)(['codeBlock'], function (target) {
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.refreshBrowserSelection = exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _browser = require("@atlaskit/editor-common/browser");
|
|
8
8
|
var _pluginKey = require("./plugin-key");
|
|
9
9
|
// Workaround for a firefox issue where dom selection is off sync
|
|
10
10
|
// https://product-fabric.atlassian.net/browse/ED-12442
|
|
@@ -20,7 +20,7 @@ var refreshBrowserSelection = exports.refreshBrowserSelection = function refresh
|
|
|
20
20
|
};
|
|
21
21
|
var refreshBrowserSelectionOnChange = function refreshBrowserSelectionOnChange(transaction, editorState) {
|
|
22
22
|
var _pluginKey$getState;
|
|
23
|
-
if (
|
|
23
|
+
if (_browser.browser.gecko && transaction.docChanged &&
|
|
24
24
|
// codeblockState.pos should be set if current selection is in a codeblock.
|
|
25
25
|
typeof ((_pluginKey$getState = _pluginKey.pluginKey.getState(editorState)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.pos) === 'number') {
|
|
26
26
|
refreshBrowserSelection();
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
2
3
|
import rafSchedule from 'raf-schd';
|
|
4
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
3
5
|
import { codeBlockWrappedStates, defaultWordWrapState, transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
|
|
4
|
-
import { browser } from '@atlaskit/editor-common/utils';
|
|
5
6
|
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
6
7
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
8
|
import { resetShouldIgnoreFollowingMutations } from '../actions';
|
|
@@ -144,7 +145,9 @@ export class CodeBlockView {
|
|
|
144
145
|
}
|
|
145
146
|
if (node !== this.node) {
|
|
146
147
|
if (fg('editor_support_code_block_wrapping')) {
|
|
147
|
-
|
|
148
|
+
if (!fg('editor_code_block_wrapping_language_change_bug')) {
|
|
149
|
+
transferCodeBlockWrappedValue(this.node, node);
|
|
150
|
+
}
|
|
148
151
|
}
|
|
149
152
|
if (node.attrs.language !== this.node.attrs.language) {
|
|
150
153
|
this.contentDOM.setAttribute('data-language', node.attrs.language || '');
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
1
2
|
import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
|
|
2
3
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
5
|
import { codeBlockClassNames } from '../ui/class-names';
|
|
4
6
|
import { getAllCodeBlockNodesInDoc } from '../utils';
|
|
5
7
|
export const DECORATION_WIDGET_TYPE = 'decorationWidgetType';
|
|
@@ -16,9 +18,8 @@ export const generateInitialDecorations = state => {
|
|
|
16
18
|
/**
|
|
17
19
|
* Update all the decorations used by the code block.
|
|
18
20
|
*/
|
|
19
|
-
export const updateCodeBlockDecorations = (tr,
|
|
21
|
+
export const updateCodeBlockDecorations = (tr, codeBlockNodes, decorationSet) => {
|
|
20
22
|
let updatedDecorationSet = decorationSet;
|
|
21
|
-
const codeBlockNodes = getAllCodeBlockNodesInDoc(state);
|
|
22
23
|
|
|
23
24
|
// All the line numbers decorators are refreshed on doc change.
|
|
24
25
|
updatedDecorationSet = updateDecorationSetWithLineNumberDecorators(tr, codeBlockNodes, updatedDecorationSet);
|
|
@@ -119,8 +120,14 @@ export const validateWordWrappedDecorators = (tr, codeBlockNodes, decorationSet)
|
|
|
119
120
|
codeBlockNodes.forEach(node => {
|
|
120
121
|
const isCodeBlockWrappedInState = isCodeBlockWordWrapEnabled(node.node);
|
|
121
122
|
const isCodeBlockWrappedByDecorator = getWordWrapDecoratorsFromNodePos(node.pos, decorationSet).length !== 0;
|
|
122
|
-
if (
|
|
123
|
-
|
|
123
|
+
if (fg('editor_code_block_wrapping_language_change_bug')) {
|
|
124
|
+
if (isCodeBlockWrappedInState !== isCodeBlockWrappedByDecorator) {
|
|
125
|
+
updatedDecorationSet = updateDecorationSetWithWordWrappedDecorator(decorationSet, tr, node);
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
if (isCodeBlockWrappedInState && !isCodeBlockWrappedByDecorator) {
|
|
129
|
+
updatedDecorationSet = updateDecorationSetWithWordWrappedDecorator(decorationSet, tr, node);
|
|
130
|
+
}
|
|
124
131
|
}
|
|
125
132
|
});
|
|
126
133
|
return updatedDecorationSet;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
2
|
+
|
|
3
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
4
|
+
import { updateCodeBlockWrappedStateNodeKeys } from '@atlaskit/editor-common/code-block';
|
|
1
5
|
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
2
6
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
7
|
import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
4
|
-
import { browser } from '@atlaskit/editor-common/utils';
|
|
5
8
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
6
9
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
7
10
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -9,7 +12,7 @@ import { ignoreFollowingMutations, resetShouldIgnoreFollowingMutations } from '.
|
|
|
9
12
|
import { codeBlockNodeView } from '../nodeviews/code-block';
|
|
10
13
|
import { pluginKey } from '../plugin-key';
|
|
11
14
|
import { codeBlockClassNames } from '../ui/class-names';
|
|
12
|
-
import { findCodeBlock } from '../utils';
|
|
15
|
+
import { findCodeBlock, getAllCodeBlockNodesInDoc } from '../utils';
|
|
13
16
|
import { ACTIONS } from './actions';
|
|
14
17
|
import { generateInitialDecorations, updateCodeBlockDecorations, updateDecorationSetWithWordWrappedDecorator } from './decorators';
|
|
15
18
|
export const createPlugin = ({
|
|
@@ -85,7 +88,11 @@ export const createPlugin = ({
|
|
|
85
88
|
// specifically used for updating word wrap node decorators (does not cover drag & drop, validateWordWrappedDecorators does).
|
|
86
89
|
let updatedDecorationSet = pluginState.decorations.map(tr.mapping, tr.doc);
|
|
87
90
|
if (fg('editor_support_code_block_wrapping')) {
|
|
88
|
-
|
|
91
|
+
const codeBlockNodes = getAllCodeBlockNodesInDoc(newState);
|
|
92
|
+
if (fg('editor_code_block_wrapping_language_change_bug')) {
|
|
93
|
+
updateCodeBlockWrappedStateNodeKeys(codeBlockNodes, _oldState);
|
|
94
|
+
}
|
|
95
|
+
updatedDecorationSet = updateCodeBlockDecorations(tr, codeBlockNodes, updatedDecorationSet);
|
|
89
96
|
}
|
|
90
97
|
const newPluginState = {
|
|
91
98
|
...pluginState,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
4
5
|
import rafSchedule from 'raf-schd';
|
|
6
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
5
7
|
import { codeBlockWrappedStates, defaultWordWrapState, transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
|
|
6
|
-
import { browser } from '@atlaskit/editor-common/utils';
|
|
7
8
|
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
8
9
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
9
10
|
import { resetShouldIgnoreFollowingMutations } from '../actions';
|
|
@@ -160,7 +161,9 @@ export var CodeBlockView = /*#__PURE__*/function () {
|
|
|
160
161
|
}
|
|
161
162
|
if (node !== this.node) {
|
|
162
163
|
if (fg('editor_support_code_block_wrapping')) {
|
|
163
|
-
|
|
164
|
+
if (!fg('editor_code_block_wrapping_language_change_bug')) {
|
|
165
|
+
transferCodeBlockWrappedValue(this.node, node);
|
|
166
|
+
}
|
|
164
167
|
}
|
|
165
168
|
if (node.attrs.language !== this.node.attrs.language) {
|
|
166
169
|
this.contentDOM.setAttribute('data-language', node.attrs.language || '');
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
2
3
|
import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
|
|
3
4
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
6
|
import { codeBlockClassNames } from '../ui/class-names';
|
|
5
7
|
import { getAllCodeBlockNodesInDoc } from '../utils';
|
|
6
8
|
export var DECORATION_WIDGET_TYPE = 'decorationWidgetType';
|
|
@@ -19,9 +21,8 @@ export var generateInitialDecorations = function generateInitialDecorations(stat
|
|
|
19
21
|
/**
|
|
20
22
|
* Update all the decorations used by the code block.
|
|
21
23
|
*/
|
|
22
|
-
export var updateCodeBlockDecorations = function updateCodeBlockDecorations(tr,
|
|
24
|
+
export var updateCodeBlockDecorations = function updateCodeBlockDecorations(tr, codeBlockNodes, decorationSet) {
|
|
23
25
|
var updatedDecorationSet = decorationSet;
|
|
24
|
-
var codeBlockNodes = getAllCodeBlockNodesInDoc(state);
|
|
25
26
|
|
|
26
27
|
// All the line numbers decorators are refreshed on doc change.
|
|
27
28
|
updatedDecorationSet = updateDecorationSetWithLineNumberDecorators(tr, codeBlockNodes, updatedDecorationSet);
|
|
@@ -122,8 +123,14 @@ export var validateWordWrappedDecorators = function validateWordWrappedDecorator
|
|
|
122
123
|
codeBlockNodes.forEach(function (node) {
|
|
123
124
|
var isCodeBlockWrappedInState = isCodeBlockWordWrapEnabled(node.node);
|
|
124
125
|
var isCodeBlockWrappedByDecorator = getWordWrapDecoratorsFromNodePos(node.pos, decorationSet).length !== 0;
|
|
125
|
-
if (
|
|
126
|
-
|
|
126
|
+
if (fg('editor_code_block_wrapping_language_change_bug')) {
|
|
127
|
+
if (isCodeBlockWrappedInState !== isCodeBlockWrappedByDecorator) {
|
|
128
|
+
updatedDecorationSet = updateDecorationSetWithWordWrappedDecorator(decorationSet, tr, node);
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
if (isCodeBlockWrappedInState && !isCodeBlockWrappedByDecorator) {
|
|
132
|
+
updatedDecorationSet = updateDecorationSetWithWordWrappedDecorator(decorationSet, tr, node);
|
|
133
|
+
}
|
|
127
134
|
}
|
|
128
135
|
});
|
|
129
136
|
return updatedDecorationSet;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
5
|
+
|
|
6
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
7
|
+
import { updateCodeBlockWrappedStateNodeKeys } from '@atlaskit/editor-common/code-block';
|
|
4
8
|
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
5
9
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
10
|
import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
7
|
-
import { browser } from '@atlaskit/editor-common/utils';
|
|
8
11
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
9
12
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
10
13
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -12,7 +15,7 @@ import { ignoreFollowingMutations, resetShouldIgnoreFollowingMutations } from '.
|
|
|
12
15
|
import { codeBlockNodeView } from '../nodeviews/code-block';
|
|
13
16
|
import { pluginKey } from '../plugin-key';
|
|
14
17
|
import { codeBlockClassNames } from '../ui/class-names';
|
|
15
|
-
import { findCodeBlock } from '../utils';
|
|
18
|
+
import { findCodeBlock, getAllCodeBlockNodesInDoc } from '../utils';
|
|
16
19
|
import { ACTIONS } from './actions';
|
|
17
20
|
import { generateInitialDecorations, updateCodeBlockDecorations, updateDecorationSetWithWordWrappedDecorator } from './decorators';
|
|
18
21
|
export var createPlugin = function createPlugin(_ref) {
|
|
@@ -90,7 +93,11 @@ export var createPlugin = function createPlugin(_ref) {
|
|
|
90
93
|
// specifically used for updating word wrap node decorators (does not cover drag & drop, validateWordWrappedDecorators does).
|
|
91
94
|
var updatedDecorationSet = pluginState.decorations.map(tr.mapping, tr.doc);
|
|
92
95
|
if (fg('editor_support_code_block_wrapping')) {
|
|
93
|
-
|
|
96
|
+
var codeBlockNodes = getAllCodeBlockNodesInDoc(newState);
|
|
97
|
+
if (fg('editor_code_block_wrapping_language_change_bug')) {
|
|
98
|
+
updateCodeBlockWrappedStateNodeKeys(codeBlockNodes, _oldState);
|
|
99
|
+
}
|
|
100
|
+
updatedDecorationSet = updateCodeBlockDecorations(tr, codeBlockNodes, updatedDecorationSet);
|
|
94
101
|
}
|
|
95
102
|
var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
96
103
|
pos: _node ? _node.pos : null,
|
|
@@ -11,7 +11,7 @@ export declare const generateInitialDecorations: (state: EditorState) => Decorat
|
|
|
11
11
|
/**
|
|
12
12
|
* Update all the decorations used by the code block.
|
|
13
13
|
*/
|
|
14
|
-
export declare const updateCodeBlockDecorations: (tr: ReadonlyTransaction,
|
|
14
|
+
export declare const updateCodeBlockDecorations: (tr: ReadonlyTransaction, codeBlockNodes: NodeWithPos[], decorationSet: DecorationSet) => DecorationSet;
|
|
15
15
|
/**
|
|
16
16
|
* Update the decorations set with the line number decorators.
|
|
17
17
|
*/
|
|
@@ -11,7 +11,7 @@ export declare const generateInitialDecorations: (state: EditorState) => Decorat
|
|
|
11
11
|
/**
|
|
12
12
|
* Update all the decorations used by the code block.
|
|
13
13
|
*/
|
|
14
|
-
export declare const updateCodeBlockDecorations: (tr: ReadonlyTransaction,
|
|
14
|
+
export declare const updateCodeBlockDecorations: (tr: ReadonlyTransaction, codeBlockNodes: NodeWithPos[], decorationSet: DecorationSet) => DecorationSet;
|
|
15
15
|
/**
|
|
16
16
|
* Update the decorations set with the line number decorators.
|
|
17
17
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-code-block",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.13",
|
|
4
4
|
"description": "Code block plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@atlaskit/adf-schema": "^40.9.0",
|
|
35
35
|
"@atlaskit/code": "^15.6.0",
|
|
36
|
-
"@atlaskit/editor-common": "^88.
|
|
36
|
+
"@atlaskit/editor-common": "^88.8.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^1.8.0",
|
|
38
38
|
"@atlaskit/editor-plugin-composition": "^1.2.0",
|
|
39
39
|
"@atlaskit/editor-plugin-decorations": "^1.3.0",
|
|
@@ -97,6 +97,9 @@
|
|
|
97
97
|
"code_block_auto_insertion_bug_fix": {
|
|
98
98
|
"type": "boolean"
|
|
99
99
|
},
|
|
100
|
+
"editor_code_block_wrapping_language_change_bug": {
|
|
101
|
+
"type": "boolean"
|
|
102
|
+
},
|
|
100
103
|
"platform.editor.live-view.disable-editing-in-view-mode_fi1rx": {
|
|
101
104
|
"type": "boolean"
|
|
102
105
|
}
|