@atlaskit/editor-plugin-code-block 8.0.11 → 8.0.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 +15 -5
- package/dist/cjs/codeBlockPlugin.js +14 -3
- package/dist/cjs/pm-plugins/decorators.js +12 -25
- package/dist/cjs/pm-plugins/main.js +2 -3
- package/dist/cjs/pm-plugins/utils.js +0 -2
- package/dist/es2019/codeBlockPlugin.js +14 -3
- package/dist/es2019/pm-plugins/decorators.js +9 -20
- package/dist/es2019/pm-plugins/main.js +2 -5
- package/dist/es2019/pm-plugins/utils.js +0 -2
- package/dist/esm/codeBlockPlugin.js +14 -3
- package/dist/esm/pm-plugins/decorators.js +11 -24
- package/dist/esm/pm-plugins/main.js +2 -5
- package/dist/esm/pm-plugins/utils.js +0 -2
- package/package.json +4 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block
|
|
2
2
|
|
|
3
|
+
## 8.0.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`9674ede5cd0bf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9674ede5cd0bf) -
|
|
8
|
+
ED-29547 fg cleanup editor_code_wrapping_perf_improvement_ed-25141
|
|
9
|
+
|
|
10
|
+
## 8.0.12
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`b6824e1dfce8e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b6824e1dfce8e) -
|
|
15
|
+
ED-29505 Add analytics for plain text code block inserted
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
3
18
|
## 8.0.11
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -302,7 +317,6 @@
|
|
|
302
317
|
shared context or singletons.
|
|
303
318
|
|
|
304
319
|
**HOW TO ADJUST:**
|
|
305
|
-
|
|
306
320
|
- Consumers must now explicitly install `@atlaskit/editor-common` in their own project if they use
|
|
307
321
|
any of these editor plugins.
|
|
308
322
|
- Ensure the version you install matches the version required by the plugins.
|
|
@@ -922,7 +936,6 @@
|
|
|
922
936
|
|
|
923
937
|
- [`193f8c85e1a39`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/193f8c85e1a39) -
|
|
924
938
|
[ux] [ED-24635]
|
|
925
|
-
|
|
926
939
|
- Disable Turn into dropdown options when wrapping is not supported
|
|
927
940
|
- Update expand icon so that it can show disabled status
|
|
928
941
|
- Update Turn into icon to show active status when dropdown is open
|
|
@@ -1383,7 +1396,6 @@
|
|
|
1383
1396
|
|
|
1384
1397
|
These are no longer available via `@atlaskit/prosemirror-input-rules` but are available from
|
|
1385
1398
|
`@atlaskit/editor-common/types`:
|
|
1386
|
-
|
|
1387
1399
|
- InputRuleWrapper
|
|
1388
1400
|
- InputRuleHandler
|
|
1389
1401
|
- OnHandlerApply
|
|
@@ -1393,7 +1405,6 @@
|
|
|
1393
1405
|
need to instantiate a `SafePlugin` (ie. `new SafePlugin(createPlugin( ... ))`).
|
|
1394
1406
|
|
|
1395
1407
|
`SafePlugin` exists in `@atlaskit/editor-common/safe-plugin`.
|
|
1396
|
-
|
|
1397
1408
|
- createPlugin
|
|
1398
1409
|
- createInputRulePlugin
|
|
1399
1410
|
|
|
@@ -1560,7 +1571,6 @@
|
|
|
1560
1571
|
- [#43646](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43646)
|
|
1561
1572
|
[`d43f8e9402f`](https://bitbucket.org/atlassian/atlassian-frontend/commits/d43f8e9402f) - Make
|
|
1562
1573
|
feature flags plugin optional in all plugins including:
|
|
1563
|
-
|
|
1564
1574
|
- analytics
|
|
1565
1575
|
- base
|
|
1566
1576
|
- card
|
|
@@ -126,7 +126,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
126
126
|
icon: function icon() {
|
|
127
127
|
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconCode, null);
|
|
128
128
|
},
|
|
129
|
-
action: function action(_insert, state) {
|
|
129
|
+
action: function action(_insert, state, source) {
|
|
130
130
|
var _api$analytics3;
|
|
131
131
|
var tr = (0, _editorCommands.createInsertCodeBlockTransaction)({
|
|
132
132
|
state: state
|
|
@@ -136,7 +136,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
136
136
|
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
137
137
|
actionSubjectId: _analytics.ACTION_SUBJECT_ID.CODE_BLOCK,
|
|
138
138
|
attributes: {
|
|
139
|
-
inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
|
|
139
|
+
inputMethod: (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_plain_text_support', 'isEnabled', true) ? source || _analytics.INPUT_METHOD.QUICK_INSERT : _analytics.INPUT_METHOD.QUICK_INSERT
|
|
140
140
|
},
|
|
141
141
|
eventType: _analytics.EVENT_TYPE.TRACK
|
|
142
142
|
})(tr);
|
|
@@ -152,13 +152,24 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
152
152
|
icon: function icon() {
|
|
153
153
|
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconCode, null);
|
|
154
154
|
},
|
|
155
|
-
action: function action(_insert, state) {
|
|
155
|
+
action: function action(_insert, state, source) {
|
|
156
|
+
var _api$analytics4;
|
|
156
157
|
var tr = (0, _editorCommands.createInsertCodeBlockTransaction)({
|
|
157
158
|
state: state,
|
|
158
159
|
attributes: {
|
|
159
160
|
language: 'text'
|
|
160
161
|
}
|
|
161
162
|
});
|
|
163
|
+
api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 || _api$analytics4.actions.attachAnalyticsEvent({
|
|
164
|
+
action: _analytics.ACTION.INSERTED,
|
|
165
|
+
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
166
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.CODE_BLOCK,
|
|
167
|
+
attributes: {
|
|
168
|
+
inputMethod: source || _analytics.INPUT_METHOD.QUICK_INSERT,
|
|
169
|
+
language: 'text'
|
|
170
|
+
},
|
|
171
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
172
|
+
})(tr);
|
|
162
173
|
return tr;
|
|
163
174
|
}
|
|
164
175
|
});
|
|
@@ -8,11 +8,8 @@ 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");
|
|
12
11
|
var _classNames = require("../ui/class-names");
|
|
13
12
|
var _utils = require("./utils");
|
|
14
|
-
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
15
|
-
|
|
16
13
|
var DECORATION_WIDGET_TYPE = exports.DECORATION_WIDGET_TYPE = 'decorationWidgetType';
|
|
17
14
|
var DECORATION_WRAPPED_BLOCK_NODE_TYPE = exports.DECORATION_WRAPPED_BLOCK_NODE_TYPE = 'decorationNodeType';
|
|
18
15
|
|
|
@@ -45,29 +42,19 @@ var updateCodeBlockDecorations = exports.updateCodeBlockDecorations = function u
|
|
|
45
42
|
*/
|
|
46
43
|
var updateDecorationSetWithLineNumberDecorators = exports.updateDecorationSetWithLineNumberDecorators = function updateDecorationSetWithLineNumberDecorators(tr, codeBlockNodes, decorationSet) {
|
|
47
44
|
var updatedDecorationSet = decorationSet;
|
|
48
|
-
if (!(0, _platformFeatureFlags.fg)('editor_code_wrapping_perf_improvement_ed-25141')) {
|
|
49
|
-
var children = updatedDecorationSet.find(undefined, undefined, function (spec) {
|
|
50
|
-
return spec.type === DECORATION_WIDGET_TYPE;
|
|
51
|
-
});
|
|
52
|
-
updatedDecorationSet = updatedDecorationSet.remove(children);
|
|
53
|
-
}
|
|
54
45
|
var lineNumberDecorators = [];
|
|
55
46
|
codeBlockNodes.forEach(function (node) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
lineNumberDecorators.push.apply(lineNumberDecorators, (0, _toConsumableArray2.default)(createDecorationSetFromLineAttributes(newLineAttributes)));
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
lineNumberDecorators.push.apply(lineNumberDecorators, (0, _toConsumableArray2.default)(createDecorationSetFromLineAttributes(generateLineAttributesFromNode(node))));
|
|
47
|
+
var existingWidgetsOnNode = updatedDecorationSet.find(node.pos, node.pos + node.node.nodeSize, function (spec) {
|
|
48
|
+
return spec.type === DECORATION_WIDGET_TYPE;
|
|
49
|
+
});
|
|
50
|
+
var newLineAttributes = generateLineAttributesFromNode(node);
|
|
51
|
+
|
|
52
|
+
// There will be no widgets on initialisation. If the number of existing widgets does not equal the amount of lines, regenerate the widgets.
|
|
53
|
+
// There may be a case where the number of existing widgets and the number of lines are the same, that's why we track totalLineCount. This allows
|
|
54
|
+
// us to know how many lines there were when the widget was created. It avoids a break in line numbers, e.g. "1, 2, 3, 5, 6". Happens on line removal.
|
|
55
|
+
if (existingWidgetsOnNode.length === 0 || existingWidgetsOnNode.length !== newLineAttributes.length || existingWidgetsOnNode[0].spec.totalLineCount !== newLineAttributes.length) {
|
|
56
|
+
updatedDecorationSet = updatedDecorationSet.remove(existingWidgetsOnNode);
|
|
57
|
+
lineNumberDecorators.push.apply(lineNumberDecorators, (0, _toConsumableArray2.default)(createDecorationSetFromLineAttributes(newLineAttributes)));
|
|
71
58
|
}
|
|
72
59
|
});
|
|
73
60
|
return updatedDecorationSet.add(tr.doc, [].concat(lineNumberDecorators));
|
|
@@ -126,7 +113,7 @@ var createDecorationSetFromLineAttributes = exports.createDecorationSetFromLineA
|
|
|
126
113
|
return _view.Decoration.widget(lineStart, createLineNumberWidget, {
|
|
127
114
|
type: DECORATION_WIDGET_TYPE,
|
|
128
115
|
side: -1,
|
|
129
|
-
totalLineCount:
|
|
116
|
+
totalLineCount: lineAttributes.length
|
|
130
117
|
});
|
|
131
118
|
});
|
|
132
119
|
return widgetDecorations;
|
|
@@ -14,7 +14,6 @@ var _selection = require("@atlaskit/editor-common/selection");
|
|
|
14
14
|
var _transforms = require("@atlaskit/editor-common/transforms");
|
|
15
15
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
16
16
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
17
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
18
17
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
19
18
|
var _editorCommands = require("../editor-commands");
|
|
20
19
|
var _codeBlock2 = require("../nodeviews/code-block");
|
|
@@ -24,7 +23,7 @@ var _decorators = require("./decorators");
|
|
|
24
23
|
var _pluginKey = require("./plugin-key");
|
|
25
24
|
var _utils = require("./utils");
|
|
26
25
|
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; }
|
|
27
|
-
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; }
|
|
26
|
+
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; }
|
|
28
27
|
var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
29
28
|
var _ref$useLongPressSele = _ref.useLongPressSelection,
|
|
30
29
|
useLongPressSelection = _ref$useLongPressSele === void 0 ? false : _ref$useLongPressSele,
|
|
@@ -113,7 +112,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
113
112
|
// Updates mapping position of all existing decorations to new positions
|
|
114
113
|
// specifically used for updating word wrap node decorators (does not cover drag & drop, validateWordWrappedDecorators does).
|
|
115
114
|
var updatedDecorationSet = pluginState.decorations.map(tr.mapping, tr.doc);
|
|
116
|
-
var codeBlockNodes = (0,
|
|
115
|
+
var codeBlockNodes = (0, _utils.getAllChangedCodeBlocksInTransaction)(tr);
|
|
117
116
|
if (codeBlockNodes) {
|
|
118
117
|
(0, _codeBlock.updateCodeBlockWrappedStateNodeKeys)(codeBlockNodes, _oldState);
|
|
119
118
|
// Disabled when using advanced code block for performance reasons
|
|
@@ -9,8 +9,6 @@ exports.getCursor = getCursor;
|
|
|
9
9
|
function getCursor(selection) {
|
|
10
10
|
return selection.$cursor || undefined;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
// Replaced by getAllChangedCodeBlocksInTransaction with FG editor_code_wrapping_perf_improvement_ed-25141.
|
|
14
12
|
function getAllCodeBlockNodesInDoc(state) {
|
|
15
13
|
var codeBlockNodes = [];
|
|
16
14
|
state.doc.descendants(function (node, pos) {
|
|
@@ -110,7 +110,7 @@ const codeBlockPlugin = ({
|
|
|
110
110
|
priority: 700,
|
|
111
111
|
keyshortcut: '```',
|
|
112
112
|
icon: () => /*#__PURE__*/React.createElement(IconCode, null),
|
|
113
|
-
action(_insert, state) {
|
|
113
|
+
action(_insert, state, source) {
|
|
114
114
|
var _api$analytics3;
|
|
115
115
|
const tr = createInsertCodeBlockTransaction({
|
|
116
116
|
state
|
|
@@ -120,7 +120,7 @@ const codeBlockPlugin = ({
|
|
|
120
120
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
121
121
|
actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
|
|
122
122
|
attributes: {
|
|
123
|
-
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
123
|
+
inputMethod: expValEqualsNoExposure('platform_editor_plain_text_support', 'isEnabled', true) ? source || INPUT_METHOD.QUICK_INSERT : INPUT_METHOD.QUICK_INSERT
|
|
124
124
|
},
|
|
125
125
|
eventType: EVENT_TYPE.TRACK
|
|
126
126
|
})(tr);
|
|
@@ -134,13 +134,24 @@ const codeBlockPlugin = ({
|
|
|
134
134
|
description: formatMessage(blockTypeMessages.plainTextCodeblockDescription),
|
|
135
135
|
keywords: ['plain text'],
|
|
136
136
|
icon: () => /*#__PURE__*/React.createElement(IconCode, null),
|
|
137
|
-
action(_insert, state) {
|
|
137
|
+
action(_insert, state, source) {
|
|
138
|
+
var _api$analytics4;
|
|
138
139
|
const tr = createInsertCodeBlockTransaction({
|
|
139
140
|
state,
|
|
140
141
|
attributes: {
|
|
141
142
|
language: 'text'
|
|
142
143
|
}
|
|
143
144
|
});
|
|
145
|
+
api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions.attachAnalyticsEvent({
|
|
146
|
+
action: ACTION.INSERTED,
|
|
147
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
148
|
+
actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
|
|
149
|
+
attributes: {
|
|
150
|
+
inputMethod: source || INPUT_METHOD.QUICK_INSERT,
|
|
151
|
+
language: 'text'
|
|
152
|
+
},
|
|
153
|
+
eventType: EVENT_TYPE.TRACK
|
|
154
|
+
})(tr);
|
|
144
155
|
return tr;
|
|
145
156
|
}
|
|
146
157
|
});
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
2
|
-
|
|
3
1
|
import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
|
|
4
2
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
3
|
import { codeBlockClassNames } from '../ui/class-names';
|
|
7
4
|
import { getAllCodeBlockNodesInDoc } from './utils';
|
|
8
5
|
export const DECORATION_WIDGET_TYPE = 'decorationWidgetType';
|
|
@@ -35,25 +32,17 @@ export const updateCodeBlockDecorations = (tr, codeBlockNodes, decorationSet) =>
|
|
|
35
32
|
*/
|
|
36
33
|
export const updateDecorationSetWithLineNumberDecorators = (tr, codeBlockNodes, decorationSet) => {
|
|
37
34
|
let updatedDecorationSet = decorationSet;
|
|
38
|
-
if (!fg('editor_code_wrapping_perf_improvement_ed-25141')) {
|
|
39
|
-
const children = updatedDecorationSet.find(undefined, undefined, spec => spec.type === DECORATION_WIDGET_TYPE);
|
|
40
|
-
updatedDecorationSet = updatedDecorationSet.remove(children);
|
|
41
|
-
}
|
|
42
35
|
const lineNumberDecorators = [];
|
|
43
36
|
codeBlockNodes.forEach(node => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const newLineAttributes = generateLineAttributesFromNode(node);
|
|
37
|
+
const existingWidgetsOnNode = updatedDecorationSet.find(node.pos, node.pos + node.node.nodeSize, spec => spec.type === DECORATION_WIDGET_TYPE);
|
|
38
|
+
const newLineAttributes = generateLineAttributesFromNode(node);
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
lineNumberDecorators.push(...createDecorationSetFromLineAttributes(generateLineAttributesFromNode(node)));
|
|
40
|
+
// There will be no widgets on initialisation. If the number of existing widgets does not equal the amount of lines, regenerate the widgets.
|
|
41
|
+
// There may be a case where the number of existing widgets and the number of lines are the same, that's why we track totalLineCount. This allows
|
|
42
|
+
// us to know how many lines there were when the widget was created. It avoids a break in line numbers, e.g. "1, 2, 3, 5, 6". Happens on line removal.
|
|
43
|
+
if (existingWidgetsOnNode.length === 0 || existingWidgetsOnNode.length !== newLineAttributes.length || existingWidgetsOnNode[0].spec.totalLineCount !== newLineAttributes.length) {
|
|
44
|
+
updatedDecorationSet = updatedDecorationSet.remove(existingWidgetsOnNode);
|
|
45
|
+
lineNumberDecorators.push(...createDecorationSetFromLineAttributes(newLineAttributes));
|
|
57
46
|
}
|
|
58
47
|
});
|
|
59
48
|
return updatedDecorationSet.add(tr.doc, [...lineNumberDecorators]);
|
|
@@ -116,7 +105,7 @@ export const createDecorationSetFromLineAttributes = lineAttributes => {
|
|
|
116
105
|
return Decoration.widget(lineStart, createLineNumberWidget, {
|
|
117
106
|
type: DECORATION_WIDGET_TYPE,
|
|
118
107
|
side: -1,
|
|
119
|
-
totalLineCount:
|
|
108
|
+
totalLineCount: lineAttributes.length
|
|
120
109
|
});
|
|
121
110
|
});
|
|
122
111
|
return widgetDecorations;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
2
|
-
|
|
3
1
|
import { browser } from '@atlaskit/editor-common/browser';
|
|
4
2
|
import { updateCodeBlockWrappedStateNodeKeys } from '@atlaskit/editor-common/code-block';
|
|
5
3
|
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
@@ -8,7 +6,6 @@ import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
|
8
6
|
import { findCodeBlock } from '@atlaskit/editor-common/transforms';
|
|
9
7
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
10
8
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
11
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
12
9
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
13
10
|
import { ignoreFollowingMutations, resetShouldIgnoreFollowingMutations } from '../editor-commands';
|
|
14
11
|
import { codeBlockNodeView } from '../nodeviews/code-block';
|
|
@@ -16,7 +13,7 @@ import { codeBlockClassNames } from '../ui/class-names';
|
|
|
16
13
|
import { ACTIONS } from './actions';
|
|
17
14
|
import { generateInitialDecorations, updateCodeBlockDecorations, updateDecorationSetWithWordWrappedDecorator } from './decorators';
|
|
18
15
|
import { pluginKey } from './plugin-key';
|
|
19
|
-
import { getAllChangedCodeBlocksInTransaction
|
|
16
|
+
import { getAllChangedCodeBlocksInTransaction } from './utils';
|
|
20
17
|
export const createPlugin = ({
|
|
21
18
|
useLongPressSelection = false,
|
|
22
19
|
getIntl,
|
|
@@ -103,7 +100,7 @@ export const createPlugin = ({
|
|
|
103
100
|
// Updates mapping position of all existing decorations to new positions
|
|
104
101
|
// specifically used for updating word wrap node decorators (does not cover drag & drop, validateWordWrappedDecorators does).
|
|
105
102
|
let updatedDecorationSet = pluginState.decorations.map(tr.mapping, tr.doc);
|
|
106
|
-
const codeBlockNodes =
|
|
103
|
+
const codeBlockNodes = getAllChangedCodeBlocksInTransaction(tr);
|
|
107
104
|
if (codeBlockNodes) {
|
|
108
105
|
updateCodeBlockWrappedStateNodeKeys(codeBlockNodes, _oldState);
|
|
109
106
|
// Disabled when using advanced code block for performance reasons
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export function getCursor(selection) {
|
|
2
2
|
return selection.$cursor || undefined;
|
|
3
3
|
}
|
|
4
|
-
|
|
5
|
-
// Replaced by getAllChangedCodeBlocksInTransaction with FG editor_code_wrapping_perf_improvement_ed-25141.
|
|
6
4
|
export function getAllCodeBlockNodesInDoc(state) {
|
|
7
5
|
const codeBlockNodes = [];
|
|
8
6
|
state.doc.descendants((node, pos) => {
|
|
@@ -119,7 +119,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
119
119
|
icon: function icon() {
|
|
120
120
|
return /*#__PURE__*/React.createElement(IconCode, null);
|
|
121
121
|
},
|
|
122
|
-
action: function action(_insert, state) {
|
|
122
|
+
action: function action(_insert, state, source) {
|
|
123
123
|
var _api$analytics3;
|
|
124
124
|
var tr = createInsertCodeBlockTransaction({
|
|
125
125
|
state: state
|
|
@@ -129,7 +129,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
129
129
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
130
130
|
actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
|
|
131
131
|
attributes: {
|
|
132
|
-
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
132
|
+
inputMethod: expValEqualsNoExposure('platform_editor_plain_text_support', 'isEnabled', true) ? source || INPUT_METHOD.QUICK_INSERT : INPUT_METHOD.QUICK_INSERT
|
|
133
133
|
},
|
|
134
134
|
eventType: EVENT_TYPE.TRACK
|
|
135
135
|
})(tr);
|
|
@@ -145,13 +145,24 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
145
145
|
icon: function icon() {
|
|
146
146
|
return /*#__PURE__*/React.createElement(IconCode, null);
|
|
147
147
|
},
|
|
148
|
-
action: function action(_insert, state) {
|
|
148
|
+
action: function action(_insert, state, source) {
|
|
149
|
+
var _api$analytics4;
|
|
149
150
|
var tr = createInsertCodeBlockTransaction({
|
|
150
151
|
state: state,
|
|
151
152
|
attributes: {
|
|
152
153
|
language: 'text'
|
|
153
154
|
}
|
|
154
155
|
});
|
|
156
|
+
api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 || _api$analytics4.actions.attachAnalyticsEvent({
|
|
157
|
+
action: ACTION.INSERTED,
|
|
158
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
159
|
+
actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
|
|
160
|
+
attributes: {
|
|
161
|
+
inputMethod: source || INPUT_METHOD.QUICK_INSERT,
|
|
162
|
+
language: 'text'
|
|
163
|
+
},
|
|
164
|
+
eventType: EVENT_TYPE.TRACK
|
|
165
|
+
})(tr);
|
|
155
166
|
return tr;
|
|
156
167
|
}
|
|
157
168
|
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
3
|
-
|
|
4
2
|
import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
|
|
5
3
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
4
|
import { codeBlockClassNames } from '../ui/class-names';
|
|
8
5
|
import { getAllCodeBlockNodesInDoc } from './utils';
|
|
9
6
|
export var DECORATION_WIDGET_TYPE = 'decorationWidgetType';
|
|
@@ -38,29 +35,19 @@ export var updateCodeBlockDecorations = function updateCodeBlockDecorations(tr,
|
|
|
38
35
|
*/
|
|
39
36
|
export var updateDecorationSetWithLineNumberDecorators = function updateDecorationSetWithLineNumberDecorators(tr, codeBlockNodes, decorationSet) {
|
|
40
37
|
var updatedDecorationSet = decorationSet;
|
|
41
|
-
if (!fg('editor_code_wrapping_perf_improvement_ed-25141')) {
|
|
42
|
-
var children = updatedDecorationSet.find(undefined, undefined, function (spec) {
|
|
43
|
-
return spec.type === DECORATION_WIDGET_TYPE;
|
|
44
|
-
});
|
|
45
|
-
updatedDecorationSet = updatedDecorationSet.remove(children);
|
|
46
|
-
}
|
|
47
38
|
var lineNumberDecorators = [];
|
|
48
39
|
codeBlockNodes.forEach(function (node) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var newLineAttributes = generateLineAttributesFromNode(node);
|
|
40
|
+
var existingWidgetsOnNode = updatedDecorationSet.find(node.pos, node.pos + node.node.nodeSize, function (spec) {
|
|
41
|
+
return spec.type === DECORATION_WIDGET_TYPE;
|
|
42
|
+
});
|
|
43
|
+
var newLineAttributes = generateLineAttributesFromNode(node);
|
|
54
44
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
} else {
|
|
63
|
-
lineNumberDecorators.push.apply(lineNumberDecorators, _toConsumableArray(createDecorationSetFromLineAttributes(generateLineAttributesFromNode(node))));
|
|
45
|
+
// There will be no widgets on initialisation. If the number of existing widgets does not equal the amount of lines, regenerate the widgets.
|
|
46
|
+
// There may be a case where the number of existing widgets and the number of lines are the same, that's why we track totalLineCount. This allows
|
|
47
|
+
// us to know how many lines there were when the widget was created. It avoids a break in line numbers, e.g. "1, 2, 3, 5, 6". Happens on line removal.
|
|
48
|
+
if (existingWidgetsOnNode.length === 0 || existingWidgetsOnNode.length !== newLineAttributes.length || existingWidgetsOnNode[0].spec.totalLineCount !== newLineAttributes.length) {
|
|
49
|
+
updatedDecorationSet = updatedDecorationSet.remove(existingWidgetsOnNode);
|
|
50
|
+
lineNumberDecorators.push.apply(lineNumberDecorators, _toConsumableArray(createDecorationSetFromLineAttributes(newLineAttributes)));
|
|
64
51
|
}
|
|
65
52
|
});
|
|
66
53
|
return updatedDecorationSet.add(tr.doc, [].concat(lineNumberDecorators));
|
|
@@ -119,7 +106,7 @@ export var createDecorationSetFromLineAttributes = function createDecorationSetF
|
|
|
119
106
|
return Decoration.widget(lineStart, createLineNumberWidget, {
|
|
120
107
|
type: DECORATION_WIDGET_TYPE,
|
|
121
108
|
side: -1,
|
|
122
|
-
totalLineCount:
|
|
109
|
+
totalLineCount: lineAttributes.length
|
|
123
110
|
});
|
|
124
111
|
});
|
|
125
112
|
return widgetDecorations;
|
|
@@ -1,8 +1,6 @@
|
|
|
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
4
|
import { browser } from '@atlaskit/editor-common/browser';
|
|
7
5
|
import { updateCodeBlockWrappedStateNodeKeys } from '@atlaskit/editor-common/code-block';
|
|
8
6
|
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
@@ -11,7 +9,6 @@ import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
|
11
9
|
import { findCodeBlock } from '@atlaskit/editor-common/transforms';
|
|
12
10
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
13
11
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
14
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
15
12
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
16
13
|
import { ignoreFollowingMutations, resetShouldIgnoreFollowingMutations } from '../editor-commands';
|
|
17
14
|
import { codeBlockNodeView } from '../nodeviews/code-block';
|
|
@@ -19,7 +16,7 @@ import { codeBlockClassNames } from '../ui/class-names';
|
|
|
19
16
|
import { ACTIONS } from './actions';
|
|
20
17
|
import { generateInitialDecorations, updateCodeBlockDecorations, updateDecorationSetWithWordWrappedDecorator } from './decorators';
|
|
21
18
|
import { pluginKey } from './plugin-key';
|
|
22
|
-
import { getAllChangedCodeBlocksInTransaction
|
|
19
|
+
import { getAllChangedCodeBlocksInTransaction } from './utils';
|
|
23
20
|
export var createPlugin = function createPlugin(_ref) {
|
|
24
21
|
var _ref$useLongPressSele = _ref.useLongPressSelection,
|
|
25
22
|
useLongPressSelection = _ref$useLongPressSele === void 0 ? false : _ref$useLongPressSele,
|
|
@@ -108,7 +105,7 @@ export var createPlugin = function createPlugin(_ref) {
|
|
|
108
105
|
// Updates mapping position of all existing decorations to new positions
|
|
109
106
|
// specifically used for updating word wrap node decorators (does not cover drag & drop, validateWordWrappedDecorators does).
|
|
110
107
|
var updatedDecorationSet = pluginState.decorations.map(tr.mapping, tr.doc);
|
|
111
|
-
var codeBlockNodes =
|
|
108
|
+
var codeBlockNodes = getAllChangedCodeBlocksInTransaction(tr);
|
|
112
109
|
if (codeBlockNodes) {
|
|
113
110
|
updateCodeBlockWrappedStateNodeKeys(codeBlockNodes, _oldState);
|
|
114
111
|
// Disabled when using advanced code block for performance reasons
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export function getCursor(selection) {
|
|
2
2
|
return selection.$cursor || undefined;
|
|
3
3
|
}
|
|
4
|
-
|
|
5
|
-
// Replaced by getAllChangedCodeBlocksInTransaction with FG editor_code_wrapping_perf_improvement_ed-25141.
|
|
6
4
|
export function getAllCodeBlockNodesInDoc(state) {
|
|
7
5
|
var codeBlockNodes = [];
|
|
8
6
|
state.doc.descendants(function (node, pos) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-code-block",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.13",
|
|
4
4
|
"description": "Code block plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,17 +37,17 @@
|
|
|
37
37
|
"@atlaskit/editor-plugin-editor-viewmode": "^8.0.0",
|
|
38
38
|
"@atlaskit/editor-plugin-interaction": "^8.0.0",
|
|
39
39
|
"@atlaskit/editor-plugin-selection": "^6.1.0",
|
|
40
|
-
"@atlaskit/editor-plugin-toolbar": "^3.
|
|
40
|
+
"@atlaskit/editor-plugin-toolbar": "^3.3.0",
|
|
41
41
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
42
42
|
"@atlaskit/editor-toolbar": "^0.15.0",
|
|
43
43
|
"@atlaskit/icon": "^28.5.0",
|
|
44
44
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
45
45
|
"@atlaskit/prosemirror-input-rules": "^3.5.0",
|
|
46
|
-
"@atlaskit/tmp-editor-statsig": "^13.
|
|
46
|
+
"@atlaskit/tmp-editor-statsig": "^13.12.0",
|
|
47
47
|
"@babel/runtime": "^7.0.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@atlaskit/editor-common": "^110.
|
|
50
|
+
"@atlaskit/editor-common": "^110.13.0",
|
|
51
51
|
"react": "^18.2.0",
|
|
52
52
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
53
53
|
},
|
|
@@ -96,9 +96,6 @@
|
|
|
96
96
|
"code_block_auto_insertion_bug_fix": {
|
|
97
97
|
"type": "boolean"
|
|
98
98
|
},
|
|
99
|
-
"editor_code_wrapping_perf_improvement_ed-25141": {
|
|
100
|
-
"type": "boolean"
|
|
101
|
-
},
|
|
102
99
|
"editor_a11y_remove_unwrap_button": {
|
|
103
100
|
"type": "boolean"
|
|
104
101
|
},
|