@atlaskit/editor-plugin-code-block 3.5.11 → 3.5.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 +12 -0
- package/dist/cjs/editor-commands/index.js +2 -2
- package/dist/cjs/nodeviews/code-block.js +24 -3
- package/dist/cjs/pm-plugins/codeBlockAutoFullStopTransformPlugin.js +2 -2
- package/dist/cjs/pm-plugins/codeBlockCopySelectionPlugin.js +2 -0
- package/dist/cjs/pm-plugins/ide-ux/bracket-handling.js +4 -0
- package/dist/cjs/pm-plugins/ide-ux/line-handling.js +13 -0
- package/dist/cjs/pm-plugins/ide-ux/quote-handling.js +8 -0
- package/dist/cjs/pm-plugins/ide-ux.js +4 -0
- package/dist/cjs/pm-plugins/input-rule.js +16 -1
- package/dist/cjs/pm-plugins/main.js +11 -6
- package/dist/cjs/pm-plugins/toolbar.js +4 -0
- package/dist/cjs/pm-plugins/transform-to-code-block.js +6 -1
- package/dist/cjs/pm-plugins/utils.js +3 -19
- package/dist/es2019/editor-commands/index.js +4 -4
- package/dist/es2019/index.js +3 -0
- package/dist/es2019/nodeviews/code-block.js +24 -1
- package/dist/es2019/pm-plugins/codeBlockAutoFullStopTransformPlugin.js +1 -1
- package/dist/es2019/pm-plugins/codeBlockCopySelectionPlugin.js +2 -0
- package/dist/es2019/pm-plugins/ide-ux/bracket-handling.js +4 -0
- package/dist/es2019/pm-plugins/ide-ux/line-handling.js +13 -0
- package/dist/es2019/pm-plugins/ide-ux/quote-handling.js +8 -0
- package/dist/es2019/pm-plugins/ide-ux.js +6 -2
- package/dist/es2019/pm-plugins/input-rule.js +16 -1
- package/dist/es2019/pm-plugins/main.js +6 -1
- package/dist/es2019/pm-plugins/toolbar.js +4 -0
- package/dist/es2019/pm-plugins/transform-to-code-block.js +7 -1
- package/dist/es2019/pm-plugins/utils.js +3 -1
- package/dist/esm/editor-commands/index.js +1 -1
- package/dist/esm/index.js +3 -0
- package/dist/esm/nodeviews/code-block.js +25 -3
- package/dist/esm/pm-plugins/codeBlockAutoFullStopTransformPlugin.js +1 -1
- package/dist/esm/pm-plugins/codeBlockCopySelectionPlugin.js +2 -0
- package/dist/esm/pm-plugins/ide-ux/bracket-handling.js +4 -0
- package/dist/esm/pm-plugins/ide-ux/line-handling.js +13 -0
- package/dist/esm/pm-plugins/ide-ux/quote-handling.js +8 -0
- package/dist/esm/pm-plugins/ide-ux.js +4 -0
- package/dist/esm/pm-plugins/input-rule.js +16 -1
- package/dist/esm/pm-plugins/main.js +6 -1
- package/dist/esm/pm-plugins/toolbar.js +4 -0
- package/dist/esm/pm-plugins/transform-to-code-block.js +7 -1
- package/dist/esm/pm-plugins/utils.js +3 -1
- package/dist/types/pm-plugins/main.d.ts +1 -1
- package/dist/types/pm-plugins/utils.d.ts +0 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/utils.d.ts +0 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -13,13 +13,13 @@ var _clipboard = require("@atlaskit/editor-common/clipboard");
|
|
|
13
13
|
var _codeBlock = require("@atlaskit/editor-common/code-block");
|
|
14
14
|
var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
|
|
15
15
|
var _insert = require("@atlaskit/editor-common/insert");
|
|
16
|
+
var _transforms = require("@atlaskit/editor-common/transforms");
|
|
16
17
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
17
18
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
18
19
|
var _actions = require("../pm-plugins/actions");
|
|
19
20
|
var _codeBlockCopySelectionPlugin = require("../pm-plugins/codeBlockCopySelectionPlugin");
|
|
20
21
|
var _pluginKey = require("../pm-plugins/plugin-key");
|
|
21
22
|
var _transformToCodeBlock = require("../pm-plugins/transform-to-code-block");
|
|
22
|
-
var _utils2 = require("../pm-plugins/utils");
|
|
23
23
|
var removeCodeBlock = exports.removeCodeBlock = function removeCodeBlock(state, dispatch) {
|
|
24
24
|
var nodes = state.schema.nodes,
|
|
25
25
|
tr = state.tr;
|
|
@@ -197,7 +197,7 @@ function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI, isNestingInQuot
|
|
|
197
197
|
var toggleWordWrapStateForCodeBlockNode = exports.toggleWordWrapStateForCodeBlockNode = function toggleWordWrapStateForCodeBlockNode(editorAnalyticsAPI) {
|
|
198
198
|
return function (state, dispatch) {
|
|
199
199
|
var _findCodeBlock;
|
|
200
|
-
var codeBlockNode = (_findCodeBlock = (0,
|
|
200
|
+
var codeBlockNode = (_findCodeBlock = (0, _transforms.findCodeBlock)(state)) === null || _findCodeBlock === void 0 ? void 0 : _findCodeBlock.node;
|
|
201
201
|
var tr = state.tr;
|
|
202
202
|
if (!_codeBlock.codeBlockWrappedStates || !codeBlockNode) {
|
|
203
203
|
return false;
|
|
@@ -15,6 +15,8 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
|
15
15
|
var _editorCommands = require("../editor-commands");
|
|
16
16
|
var _mainState = require("../pm-plugins/main-state");
|
|
17
17
|
var _classNames = require("../ui/class-names");
|
|
18
|
+
// Ignored via go/ees005
|
|
19
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
18
20
|
var MATCH_NEWLINES = new RegExp('\n', 'g');
|
|
19
21
|
var toDOM = function toDOM(node, contentEditable, formattedAriaLabel) {
|
|
20
22
|
return ['div', {
|
|
@@ -41,6 +43,8 @@ var toDOM = function toDOM(node, contentEditable, formattedAriaLabel) {
|
|
|
41
43
|
}]];
|
|
42
44
|
};
|
|
43
45
|
var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
46
|
+
// Ignored via go/ees005
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
44
48
|
function CodeBlockView(_node, view, getPos, formattedAriaLabel, api, cleanupEditorDisabledListener) {
|
|
45
49
|
var _this = this,
|
|
46
50
|
_api$editorDisabled;
|
|
@@ -54,6 +58,8 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
|
54
58
|
_this.node.forEach(function (node) {
|
|
55
59
|
var text = node.text;
|
|
56
60
|
if (text) {
|
|
61
|
+
// Ignored via go/ees005
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
57
63
|
totalLineCount += (node.text.match(MATCH_NEWLINES) || []).length;
|
|
58
64
|
}
|
|
59
65
|
});
|
|
@@ -67,8 +73,14 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
|
67
73
|
this.getPos = getPos;
|
|
68
74
|
this.view = view;
|
|
69
75
|
this.node = _node;
|
|
76
|
+
// Ignored via go/ees005
|
|
77
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
70
78
|
this.dom = dom;
|
|
79
|
+
// Ignored via go/ees005
|
|
80
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
71
81
|
this.contentDOM = contentDOM;
|
|
82
|
+
// Ignored via go/ees005
|
|
83
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
72
84
|
this.lineNumberGutter = this.dom.querySelector(".".concat(_classNames.codeBlockClassNames.gutter));
|
|
73
85
|
this.api = api;
|
|
74
86
|
this.maintainDynamicGutterSize();
|
|
@@ -80,7 +92,7 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
|
80
92
|
}
|
|
81
93
|
this.handleEditorDisabledChanged();
|
|
82
94
|
}
|
|
83
|
-
(0, _createClass2.default)(CodeBlockView, [{
|
|
95
|
+
return (0, _createClass2.default)(CodeBlockView, [{
|
|
84
96
|
key: "handleEditorDisabledChanged",
|
|
85
97
|
value: function handleEditorDisabledChanged() {
|
|
86
98
|
var _this$api,
|
|
@@ -102,6 +114,8 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
|
102
114
|
var contentWrapper = this.dom.childNodes[1];
|
|
103
115
|
var contentView = contentWrapper === null || contentWrapper === void 0 ? void 0 : contentWrapper.childNodes[1];
|
|
104
116
|
if ((contentView === null || contentView === void 0 || (_contentView$childNod = contentView.childNodes) === null || _contentView$childNod === void 0 ? void 0 : _contentView$childNod.length) > 0) {
|
|
117
|
+
// Ignored via go/ees005
|
|
118
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
105
119
|
var codeElement = contentView.firstChild;
|
|
106
120
|
codeElement.innerHTML = savedInnerHTML;
|
|
107
121
|
|
|
@@ -128,10 +142,15 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
|
128
142
|
if (contentView !== null && contentView !== void 0 && contentView.childNodes && contentView.childNodes.length > 1) {
|
|
129
143
|
var savedInnerHTML = '';
|
|
130
144
|
while (contentView.childNodes.length > 1) {
|
|
145
|
+
// Ignored via go/ees005
|
|
146
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
131
147
|
var lastChild = contentView.lastChild;
|
|
132
148
|
savedInnerHTML = lastChild.innerHTML + savedInnerHTML;
|
|
133
149
|
contentView.removeChild(lastChild);
|
|
134
150
|
}
|
|
151
|
+
|
|
152
|
+
// Ignored via go/ees005
|
|
153
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
135
154
|
var firstChild = contentView.firstChild;
|
|
136
155
|
savedInnerHTML = firstChild.innerHTML + '\n' + savedInnerHTML;
|
|
137
156
|
var newCursorPosition = firstChild.innerHTML.length + 1;
|
|
@@ -181,8 +200,10 @@ var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
|
|
|
181
200
|
this.cleanupEditorDisabledListener = undefined;
|
|
182
201
|
}
|
|
183
202
|
}]);
|
|
184
|
-
return CodeBlockView;
|
|
185
203
|
}();
|
|
186
|
-
var codeBlockNodeView = exports.codeBlockNodeView = function codeBlockNodeView(node, view, getPos, formattedAriaLabel, api
|
|
204
|
+
var codeBlockNodeView = exports.codeBlockNodeView = function codeBlockNodeView(node, view, getPos, formattedAriaLabel, api
|
|
205
|
+
// Ignored via go/ees005
|
|
206
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
207
|
+
) {
|
|
187
208
|
return new CodeBlockView(node, view, getPos, formattedAriaLabel, api);
|
|
188
209
|
};
|
|
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.codeBlockAutoFullStopTransformPlugin = codeBlockAutoFullStopTransformPlugin;
|
|
7
7
|
exports.codeBlockAutoFullStopTransformPluginKey = void 0;
|
|
8
8
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
9
|
+
var _transforms = require("@atlaskit/editor-common/transforms");
|
|
9
10
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
10
11
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
11
12
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
12
|
-
var _utils2 = require("./utils");
|
|
13
13
|
var codeBlockAutoFullStopTransformPluginKey = exports.codeBlockAutoFullStopTransformPluginKey = new _state.PluginKey('codeBlockAutoFullStopTransformPluginKey');
|
|
14
14
|
function codeBlockAutoFullStopTransformPlugin() {
|
|
15
15
|
return new _safePlugin.SafePlugin({
|
|
@@ -26,7 +26,7 @@ function codeBlockAutoFullStopTransformPlugin() {
|
|
|
26
26
|
var _trNew$selection = trNew.selection,
|
|
27
27
|
fromNew = _trNew$selection.from,
|
|
28
28
|
toNew = _trNew$selection.to;
|
|
29
|
-
var isCodeBlock = !!(0,
|
|
29
|
+
var isCodeBlock = !!(0, _transforms.findCodeBlock)(oldState, trOld.selection) && !!(0, _transforms.findCodeBlock)(newState, trNew.selection);
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Mac will auto insert a fullstop when the user double taps the space key after some content.
|
|
@@ -40,6 +40,8 @@ function codeBlockCopySelectionPlugin() {
|
|
|
40
40
|
decorationStartAndEnd: undefined
|
|
41
41
|
};
|
|
42
42
|
},
|
|
43
|
+
// Ignored via go/ees005
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
43
45
|
apply: function apply(transaction, currentCodeBlockCopySelectionPluginState, _oldState, newState) {
|
|
44
46
|
switch (transaction.getMeta(copySelectionPluginKey)) {
|
|
45
47
|
case 'show-selection':
|
|
@@ -11,11 +11,15 @@ var BRACKET_MAP = exports.BRACKET_MAP = {
|
|
|
11
11
|
};
|
|
12
12
|
var shouldAutoCloseBracket = exports.shouldAutoCloseBracket = function shouldAutoCloseBracket(before, after) {
|
|
13
13
|
// when directly before a closing bracket
|
|
14
|
+
// Ignored via go/ees005
|
|
15
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
14
16
|
if (/^[}\])]/.test(after)) {
|
|
15
17
|
return true;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
// exclusion: when directly before a non-whitespace character
|
|
21
|
+
// Ignored via go/ees005
|
|
22
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
19
23
|
if (/^[^\s]/.test(after)) {
|
|
20
24
|
return false;
|
|
21
25
|
}
|
|
@@ -16,8 +16,12 @@ var isCursorInsideCodeBlock = exports.isCursorInsideCodeBlock = function isCurso
|
|
|
16
16
|
var getStartOfCurrentLine = exports.getStartOfCurrentLine = function getStartOfCurrentLine(state) {
|
|
17
17
|
var $from = state.selection.$from;
|
|
18
18
|
if ($from.nodeBefore && $from.nodeBefore.isText) {
|
|
19
|
+
// Ignored via go/ees005
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
19
21
|
var prevNewLineIndex = $from.nodeBefore.text.lastIndexOf('\n');
|
|
20
22
|
return {
|
|
23
|
+
// Ignored via go/ees005
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
21
25
|
text: $from.nodeBefore.text.substring(prevNewLineIndex + 1),
|
|
22
26
|
pos: $from.start() + prevNewLineIndex + 1
|
|
23
27
|
};
|
|
@@ -30,8 +34,12 @@ var getStartOfCurrentLine = exports.getStartOfCurrentLine = function getStartOfC
|
|
|
30
34
|
var getEndOfCurrentLine = exports.getEndOfCurrentLine = function getEndOfCurrentLine(state) {
|
|
31
35
|
var $to = state.selection.$to;
|
|
32
36
|
if ($to.nodeAfter && $to.nodeAfter.isText) {
|
|
37
|
+
// Ignored via go/ees005
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
33
39
|
var nextNewLineIndex = $to.nodeAfter.text.indexOf('\n');
|
|
34
40
|
return {
|
|
41
|
+
// Ignored via go/ees005
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
35
43
|
text: $to.nodeAfter.text.substring(0, nextNewLineIndex >= 0 ? nextNewLineIndex : undefined),
|
|
36
44
|
pos: nextNewLineIndex >= 0 ? $to.pos + nextNewLineIndex : $to.end()
|
|
37
45
|
};
|
|
@@ -60,11 +68,16 @@ var forEachLine = exports.forEachLine = function forEachLine(text, callback) {
|
|
|
60
68
|
offset += line.length + 1;
|
|
61
69
|
});
|
|
62
70
|
};
|
|
71
|
+
|
|
72
|
+
// Ignored via go/ees005
|
|
73
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
63
74
|
var SPACE = {
|
|
64
75
|
token: ' ',
|
|
65
76
|
size: 2,
|
|
66
77
|
regex: /[^ ]/
|
|
67
78
|
};
|
|
79
|
+
// Ignored via go/ees005
|
|
80
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
68
81
|
var TAB = {
|
|
69
82
|
token: '\t',
|
|
70
83
|
size: 1,
|
|
@@ -11,16 +11,24 @@ var QUOTE_MAP = exports.QUOTE_MAP = {
|
|
|
11
11
|
};
|
|
12
12
|
var shouldAutoCloseQuote = exports.shouldAutoCloseQuote = function shouldAutoCloseQuote(before, after) {
|
|
13
13
|
// when directly before a closing bracket
|
|
14
|
+
// Ignored via go/ees005
|
|
15
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
14
16
|
if (/^[}\])]/.test(after)) {
|
|
15
17
|
return true;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
// exclusion: when directly before a non-whitespace character
|
|
21
|
+
// Ignored via go/ees005
|
|
22
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
19
23
|
if (/^[^\s]/.test(after)) {
|
|
20
24
|
return false;
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
// exclusion: when directly after a letter or quote
|
|
28
|
+
// Ignored via go/ees005
|
|
29
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
30
|
+
// Ignored via go/ees005
|
|
31
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
24
32
|
if (/[A-Za-z0-9]$/.test(before) || /[\'\"\`]$/.test(before)) {
|
|
25
33
|
return false;
|
|
26
34
|
}
|
|
@@ -20,6 +20,8 @@ var ideUX = function ideUX(pluginInjectionApi) {
|
|
|
20
20
|
var editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
|
|
21
21
|
return new _safePlugin.SafePlugin({
|
|
22
22
|
props: {
|
|
23
|
+
// Ignored via go/ees005
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
23
25
|
handleTextInput: function handleTextInput(view, from, to, text) {
|
|
24
26
|
var _pluginInjectionApi$c;
|
|
25
27
|
var state = view.state,
|
|
@@ -66,6 +68,8 @@ var ideUX = function ideUX(pluginInjectionApi) {
|
|
|
66
68
|
handleKeyDown: (0, _keymap.keydownHandler)({
|
|
67
69
|
Backspace: function Backspace(state, dispatch) {
|
|
68
70
|
if ((0, _lineHandling.isCursorInsideCodeBlock)(state)) {
|
|
71
|
+
// Ignored via go/ees005
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
69
73
|
var $cursor = (0, _utils3.getCursor)(state.selection);
|
|
70
74
|
var beforeText = (0, _lineHandling.getStartOfCurrentLine)(state).text;
|
|
71
75
|
var afterText = (0, _lineHandling.getEndOfCurrentLine)(state).text;
|
|
@@ -37,10 +37,16 @@ function getCodeBlockRules(editorAnalyticsAPI, schema, isNestingInQuoteSupported
|
|
|
37
37
|
var validMatchLength = function validMatchLength(match) {
|
|
38
38
|
return match.length > 0 && match[0].length === 3;
|
|
39
39
|
};
|
|
40
|
+
|
|
41
|
+
// Ignored via go/ees005
|
|
42
|
+
// eslint-disable-next-line require-unicode-regexp, @typescript-eslint/max-params
|
|
40
43
|
var threeTildeRule = (0, _utils.createRule)(/(?!\s)(`{3,})$/, function (state, match, start, end) {
|
|
41
44
|
if (!validMatchLength(match)) {
|
|
42
45
|
return null;
|
|
43
46
|
}
|
|
47
|
+
|
|
48
|
+
// Ignored via go/ees005
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
50
|
var attributes = {};
|
|
45
51
|
if (match[4]) {
|
|
46
52
|
attributes.language = match[4];
|
|
@@ -54,10 +60,19 @@ function getCodeBlockRules(editorAnalyticsAPI, schema, isNestingInQuoteSupported
|
|
|
54
60
|
(0, _utils2.safeInsert)(codeBlock)(tr);
|
|
55
61
|
return tr;
|
|
56
62
|
});
|
|
57
|
-
var leftNodeReplacementThreeTildeRule = (0, _utils.createRule)(
|
|
63
|
+
var leftNodeReplacementThreeTildeRule = (0, _utils.createRule)(
|
|
64
|
+
// Ignored via go/ees005
|
|
65
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
66
|
+
new RegExp("((".concat(_prosemirrorInputRules.leafNodeReplacementCharacter, "`{3,})|^\\s(`{3,}))(\\S*)$")),
|
|
67
|
+
// Ignored via go/ees005
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
69
|
+
function (state, match, start, end) {
|
|
58
70
|
if (!validMatchLength(match)) {
|
|
59
71
|
return null;
|
|
60
72
|
}
|
|
73
|
+
|
|
74
|
+
// Ignored via go/ees005
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
76
|
var attributes = {};
|
|
62
77
|
if (match[4]) {
|
|
63
78
|
attributes.language = match[4];
|
|
@@ -11,6 +11,7 @@ var _codeBlock = require("@atlaskit/editor-common/code-block");
|
|
|
11
11
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
12
12
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
13
13
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
14
|
+
var _transforms = require("@atlaskit/editor-common/transforms");
|
|
14
15
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
15
16
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
16
17
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
@@ -41,10 +42,12 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
41
42
|
var eventText = keyEvent.data;
|
|
42
43
|
if (_browser.browser.ios && event.composed &&
|
|
43
44
|
// insertParagraph will be the input type when the enter key is pressed.
|
|
44
|
-
eventInputType === 'insertParagraph' && (0,
|
|
45
|
+
eventInputType === 'insertParagraph' && (0, _transforms.findCodeBlock)(view.state, view.state.selection)) {
|
|
45
46
|
event.preventDefault();
|
|
46
47
|
return true;
|
|
47
|
-
} else if (_browser.browser.android && event.composed && eventInputType === 'insertCompositionText' && eventText[(eventText === null || eventText === void 0 ? void 0 : eventText.length) - 1] === '\n' && (0,
|
|
48
|
+
} else if (_browser.browser.android && event.composed && eventInputType === 'insertCompositionText' && eventText[(eventText === null || eventText === void 0 ? void 0 : eventText.length) - 1] === '\n' && (0, _transforms.findCodeBlock)(view.state, view.state.selection)) {
|
|
49
|
+
// Ignored via go/ees005
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
51
|
var resultingText = event.target.outerText + '\n';
|
|
49
52
|
if (resultingText.endsWith(eventText)) {
|
|
50
53
|
// End of paragraph
|
|
@@ -73,7 +76,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
73
76
|
return new _safePlugin.SafePlugin({
|
|
74
77
|
state: {
|
|
75
78
|
init: function init(_, state) {
|
|
76
|
-
var node = (0,
|
|
79
|
+
var node = (0, _transforms.findCodeBlock)(state, state.selection);
|
|
77
80
|
var initialDecorations = (0, _decorators.generateInitialDecorations)(state);
|
|
78
81
|
return {
|
|
79
82
|
pos: node ? node.pos : null,
|
|
@@ -83,16 +86,18 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
83
86
|
decorations: _view.DecorationSet.create(state.doc, initialDecorations)
|
|
84
87
|
};
|
|
85
88
|
},
|
|
89
|
+
// Ignored via go/ees005
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
86
91
|
apply: function apply(tr, pluginState, _oldState, newState) {
|
|
87
92
|
var meta = tr.getMeta(_pluginKey.pluginKey);
|
|
88
93
|
if ((meta === null || meta === void 0 ? void 0 : meta.type) === _actions.ACTIONS.SET_IS_WRAPPED) {
|
|
89
|
-
var node = (0,
|
|
94
|
+
var node = (0, _transforms.findCodeBlock)(newState, tr.selection);
|
|
90
95
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
91
96
|
decorations: (0, _decorators.updateDecorationSetWithWordWrappedDecorator)(pluginState.decorations, tr, node)
|
|
92
97
|
});
|
|
93
98
|
}
|
|
94
99
|
if (tr.docChanged) {
|
|
95
|
-
var _node = (0,
|
|
100
|
+
var _node = (0, _transforms.findCodeBlock)(newState, tr.selection);
|
|
96
101
|
|
|
97
102
|
// Updates mapping position of all existing decorations to new positions
|
|
98
103
|
// specifically used for updating word wrap node decorators (does not cover drag & drop, validateWordWrappedDecorators does).
|
|
@@ -112,7 +117,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
112
117
|
return newPluginState;
|
|
113
118
|
}
|
|
114
119
|
if (tr.selectionSet) {
|
|
115
|
-
var _node2 = (0,
|
|
120
|
+
var _node2 = (0, _transforms.findCodeBlock)(newState, tr.selection);
|
|
116
121
|
var _newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
117
122
|
pos: _node2 ? _node2.pos : null,
|
|
118
123
|
isNodeSelected: tr.selection instanceof _state.NodeSelection
|
|
@@ -118,6 +118,8 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig() {
|
|
|
118
118
|
};
|
|
119
119
|
return {
|
|
120
120
|
title: 'CodeBlock floating controls',
|
|
121
|
+
// Ignored via go/ees005
|
|
122
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
121
123
|
getDomRef: function getDomRef(view) {
|
|
122
124
|
return (0, _utils.findDomRefAtPos)(pos, view.domAtPos.bind(view));
|
|
123
125
|
},
|
|
@@ -132,6 +134,8 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig() {
|
|
|
132
134
|
* Filters language list based on both name and alias properties.
|
|
133
135
|
*/
|
|
134
136
|
var languageListFilter = exports.languageListFilter = function languageListFilter(option, rawInput) {
|
|
137
|
+
// Ignored via go/ees005
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
135
139
|
var _ref3 = option,
|
|
136
140
|
data = _ref3.data;
|
|
137
141
|
var searchString = rawInput.toLowerCase();
|
|
@@ -10,7 +10,12 @@ var _utils = require("@atlaskit/editor-common/utils");
|
|
|
10
10
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
11
11
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
12
12
|
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
13
|
-
|
|
13
|
+
// Ignored via go/ees005
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
15
|
+
function transformToCodeBlockAction(state, start,
|
|
16
|
+
// Ignored via go/ees005
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
attrs, isNestingInQuoteSupported) {
|
|
14
19
|
var startOfCodeBlockText = state.selection.$from;
|
|
15
20
|
var endPosition = state.selection.empty && !(state.selection instanceof _selection.GapCursorSelection) ? startOfCodeBlockText.end() : state.selection.$to.pos;
|
|
16
21
|
var startLinePosition = startOfCodeBlockText.start();
|
|
@@ -3,28 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "findCodeBlock", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _transforms.findCodeBlock;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
6
|
exports.getAllChangedCodeBlocksInTransaction = getAllChangedCodeBlocksInTransaction;
|
|
13
7
|
exports.getAllCodeBlockNodesInDoc = getAllCodeBlockNodesInDoc;
|
|
14
8
|
exports.getCursor = getCursor;
|
|
15
|
-
Object.defineProperty(exports, "transformSingleLineCodeBlockToCodeMark", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function get() {
|
|
18
|
-
return _transforms.transformSingleLineCodeBlockToCodeMark;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(exports, "transformSliceToJoinAdjacentCodeBlocks", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function get() {
|
|
24
|
-
return _transforms.transformSliceToJoinAdjacentCodeBlocks;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
var _transforms = require("@atlaskit/editor-common/transforms");
|
|
28
9
|
function getCursor(selection) {
|
|
29
10
|
return selection.$cursor || undefined;
|
|
30
11
|
}
|
|
@@ -49,6 +30,9 @@ function getAllChangedCodeBlocksInTransaction(tr) {
|
|
|
49
30
|
var nodePositions = new Set();
|
|
50
31
|
tr.steps.forEach(function (step) {
|
|
51
32
|
var mapResult = step.getMap();
|
|
33
|
+
|
|
34
|
+
// Ignored via go/ees005
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
52
36
|
mapResult.forEach(function (oldStart, oldEnd, newStart, newEnd) {
|
|
53
37
|
tr.doc.nodesBetween(newStart, Math.min(newEnd, tr.doc.content.size), function (node, pos) {
|
|
54
38
|
if (node.type.name === 'codeBlock') {
|
|
@@ -3,13 +3,13 @@ import { copyToClipboard } from '@atlaskit/editor-common/clipboard';
|
|
|
3
3
|
import { codeBlockWrappedStates, isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
|
|
4
4
|
import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
|
|
5
5
|
import { contentAllowedInCodeBlock, shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
|
|
6
|
+
import { findCodeBlock } from '@atlaskit/editor-common/transforms';
|
|
6
7
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
7
8
|
import { findParentNodeOfType, findSelectedNodeOfType, isNodeSelection, removeParentNodeOfType, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
8
9
|
import { ACTIONS } from '../pm-plugins/actions';
|
|
9
10
|
import { copySelectionPluginKey } from '../pm-plugins/codeBlockCopySelectionPlugin';
|
|
10
11
|
import { pluginKey } from '../pm-plugins/plugin-key';
|
|
11
12
|
import { transformToCodeBlockAction } from '../pm-plugins/transform-to-code-block';
|
|
12
|
-
import { findCodeBlock } from '../pm-plugins/utils';
|
|
13
13
|
export const removeCodeBlock = (state, dispatch) => {
|
|
14
14
|
const {
|
|
15
15
|
schema: {
|
|
@@ -66,7 +66,7 @@ export const copyContentToClipboard = (state, dispatch) => {
|
|
|
66
66
|
const textContent = codeBlock && codeBlock.node.textContent;
|
|
67
67
|
if (textContent) {
|
|
68
68
|
copyToClipboard(textContent);
|
|
69
|
-
|
|
69
|
+
const copyToClipboardTr = tr;
|
|
70
70
|
copyToClipboardTr.setMeta(pluginKey, {
|
|
71
71
|
type: ACTIONS.SET_COPIED_TO_CLIPBOARD,
|
|
72
72
|
data: true
|
|
@@ -83,7 +83,7 @@ export const resetCopiedState = (state, dispatch) => {
|
|
|
83
83
|
tr
|
|
84
84
|
} = state;
|
|
85
85
|
const codeBlockState = pluginKey.getState(state);
|
|
86
|
-
|
|
86
|
+
const resetCopiedStateTr = tr;
|
|
87
87
|
if (codeBlockState && codeBlockState.contentCopied) {
|
|
88
88
|
resetCopiedStateTr.setMeta(pluginKey, {
|
|
89
89
|
type: ACTIONS.SET_COPIED_TO_CLIPBOARD,
|
|
@@ -188,7 +188,7 @@ export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI, isNestin
|
|
|
188
188
|
},
|
|
189
189
|
eventType: EVENT_TYPE.TRACK
|
|
190
190
|
})(function (state, dispatch) {
|
|
191
|
-
|
|
191
|
+
const tr = createInsertCodeBlockTransaction({
|
|
192
192
|
state,
|
|
193
193
|
isNestingInQuoteSupported
|
|
194
194
|
});
|
package/dist/es2019/index.js
CHANGED
|
@@ -6,6 +6,9 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
6
6
|
import { resetShouldIgnoreFollowingMutations } from '../editor-commands';
|
|
7
7
|
import { getPluginState } from '../pm-plugins/main-state';
|
|
8
8
|
import { codeBlockClassNames } from '../ui/class-names';
|
|
9
|
+
|
|
10
|
+
// Ignored via go/ees005
|
|
11
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
9
12
|
const MATCH_NEWLINES = new RegExp('\n', 'g');
|
|
10
13
|
const toDOM = (node, contentEditable, formattedAriaLabel) => ['div', {
|
|
11
14
|
class: codeBlockClassNames.container
|
|
@@ -30,6 +33,8 @@ const toDOM = (node, contentEditable, formattedAriaLabel) => ['div', {
|
|
|
30
33
|
contenteditable: 'false'
|
|
31
34
|
}]];
|
|
32
35
|
export class CodeBlockView {
|
|
36
|
+
// Ignored via go/ees005
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
33
38
|
constructor(_node, view, getPos, formattedAriaLabel, api, cleanupEditorDisabledListener) {
|
|
34
39
|
var _api$editorDisabled, _api$editorDisabled$s;
|
|
35
40
|
_defineProperty(this, "formattedAriaLabel", '');
|
|
@@ -41,6 +46,8 @@ export class CodeBlockView {
|
|
|
41
46
|
this.node.forEach(node => {
|
|
42
47
|
const text = node.text;
|
|
43
48
|
if (text) {
|
|
49
|
+
// Ignored via go/ees005
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
44
51
|
totalLineCount += (node.text.match(MATCH_NEWLINES) || []).length;
|
|
45
52
|
}
|
|
46
53
|
});
|
|
@@ -55,8 +62,14 @@ export class CodeBlockView {
|
|
|
55
62
|
this.getPos = getPos;
|
|
56
63
|
this.view = view;
|
|
57
64
|
this.node = _node;
|
|
65
|
+
// Ignored via go/ees005
|
|
66
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
58
67
|
this.dom = dom;
|
|
68
|
+
// Ignored via go/ees005
|
|
69
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
59
70
|
this.contentDOM = contentDOM;
|
|
71
|
+
// Ignored via go/ees005
|
|
72
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
60
73
|
this.lineNumberGutter = this.dom.querySelector(`.${codeBlockClassNames.gutter}`);
|
|
61
74
|
this.api = api;
|
|
62
75
|
this.maintainDynamicGutterSize();
|
|
@@ -85,6 +98,8 @@ export class CodeBlockView {
|
|
|
85
98
|
const contentWrapper = this.dom.childNodes[1];
|
|
86
99
|
const contentView = contentWrapper === null || contentWrapper === void 0 ? void 0 : contentWrapper.childNodes[1];
|
|
87
100
|
if ((contentView === null || contentView === void 0 ? void 0 : (_contentView$childNod = contentView.childNodes) === null || _contentView$childNod === void 0 ? void 0 : _contentView$childNod.length) > 0) {
|
|
101
|
+
// Ignored via go/ees005
|
|
102
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
88
103
|
const codeElement = contentView.firstChild;
|
|
89
104
|
codeElement.innerHTML = savedInnerHTML;
|
|
90
105
|
|
|
@@ -107,10 +122,15 @@ export class CodeBlockView {
|
|
|
107
122
|
if (contentView !== null && contentView !== void 0 && contentView.childNodes && contentView.childNodes.length > 1) {
|
|
108
123
|
let savedInnerHTML = '';
|
|
109
124
|
while (contentView.childNodes.length > 1) {
|
|
125
|
+
// Ignored via go/ees005
|
|
126
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
110
127
|
const lastChild = contentView.lastChild;
|
|
111
128
|
savedInnerHTML = lastChild.innerHTML + savedInnerHTML;
|
|
112
129
|
contentView.removeChild(lastChild);
|
|
113
130
|
}
|
|
131
|
+
|
|
132
|
+
// Ignored via go/ees005
|
|
133
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
114
134
|
const firstChild = contentView.firstChild;
|
|
115
135
|
savedInnerHTML = firstChild.innerHTML + '\n' + savedInnerHTML;
|
|
116
136
|
const newCursorPosition = firstChild.innerHTML.length + 1;
|
|
@@ -154,4 +174,7 @@ export class CodeBlockView {
|
|
|
154
174
|
this.cleanupEditorDisabledListener = undefined;
|
|
155
175
|
}
|
|
156
176
|
}
|
|
157
|
-
export const codeBlockNodeView = (node, view, getPos, formattedAriaLabel, api
|
|
177
|
+
export const codeBlockNodeView = (node, view, getPos, formattedAriaLabel, api
|
|
178
|
+
// Ignored via go/ees005
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
180
|
+
) => new CodeBlockView(node, view, getPos, formattedAriaLabel, api);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { findCodeBlock } from '@atlaskit/editor-common/transforms';
|
|
2
3
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
3
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
5
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
|
-
import { findCodeBlock } from './utils';
|
|
6
6
|
export const codeBlockAutoFullStopTransformPluginKey = new PluginKey('codeBlockAutoFullStopTransformPluginKey');
|
|
7
7
|
export function codeBlockAutoFullStopTransformPlugin() {
|
|
8
8
|
return new SafePlugin({
|
|
@@ -30,6 +30,8 @@ export function codeBlockCopySelectionPlugin() {
|
|
|
30
30
|
decorationStartAndEnd: undefined
|
|
31
31
|
};
|
|
32
32
|
},
|
|
33
|
+
// Ignored via go/ees005
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
33
35
|
apply(transaction, currentCodeBlockCopySelectionPluginState, _oldState, newState) {
|
|
34
36
|
switch (transaction.getMeta(copySelectionPluginKey)) {
|
|
35
37
|
case 'show-selection':
|
|
@@ -5,11 +5,15 @@ export const BRACKET_MAP = {
|
|
|
5
5
|
};
|
|
6
6
|
export const shouldAutoCloseBracket = (before, after) => {
|
|
7
7
|
// when directly before a closing bracket
|
|
8
|
+
// Ignored via go/ees005
|
|
9
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
8
10
|
if (/^[}\])]/.test(after)) {
|
|
9
11
|
return true;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
// exclusion: when directly before a non-whitespace character
|
|
15
|
+
// Ignored via go/ees005
|
|
16
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
13
17
|
if (/^[^\s]/.test(after)) {
|
|
14
18
|
return false;
|
|
15
19
|
}
|
|
@@ -6,8 +6,12 @@ export const getStartOfCurrentLine = state => {
|
|
|
6
6
|
$from
|
|
7
7
|
} = state.selection;
|
|
8
8
|
if ($from.nodeBefore && $from.nodeBefore.isText) {
|
|
9
|
+
// Ignored via go/ees005
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
9
11
|
const prevNewLineIndex = $from.nodeBefore.text.lastIndexOf('\n');
|
|
10
12
|
return {
|
|
13
|
+
// Ignored via go/ees005
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
11
15
|
text: $from.nodeBefore.text.substring(prevNewLineIndex + 1),
|
|
12
16
|
pos: $from.start() + prevNewLineIndex + 1
|
|
13
17
|
};
|
|
@@ -22,8 +26,12 @@ export const getEndOfCurrentLine = state => {
|
|
|
22
26
|
$to
|
|
23
27
|
} = state.selection;
|
|
24
28
|
if ($to.nodeAfter && $to.nodeAfter.isText) {
|
|
29
|
+
// Ignored via go/ees005
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
25
31
|
const nextNewLineIndex = $to.nodeAfter.text.indexOf('\n');
|
|
26
32
|
return {
|
|
33
|
+
// Ignored via go/ees005
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
27
35
|
text: $to.nodeAfter.text.substring(0, nextNewLineIndex >= 0 ? nextNewLineIndex : undefined),
|
|
28
36
|
pos: nextNewLineIndex >= 0 ? $to.pos + nextNewLineIndex : $to.end()
|
|
29
37
|
};
|
|
@@ -54,11 +62,16 @@ export const forEachLine = (text, callback) => {
|
|
|
54
62
|
offset += line.length + 1;
|
|
55
63
|
});
|
|
56
64
|
};
|
|
65
|
+
|
|
66
|
+
// Ignored via go/ees005
|
|
67
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
57
68
|
const SPACE = {
|
|
58
69
|
token: ' ',
|
|
59
70
|
size: 2,
|
|
60
71
|
regex: /[^ ]/
|
|
61
72
|
};
|
|
73
|
+
// Ignored via go/ees005
|
|
74
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
62
75
|
const TAB = {
|
|
63
76
|
token: '\t',
|
|
64
77
|
size: 1,
|