@atlaskit/editor-plugin-paste 11.1.11 → 11.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/cjs/entry-points/paste-plugin-type.js +1 -0
- package/dist/cjs/entry-points/paste-plugin.js +12 -0
- package/dist/cjs/pm-plugins/main.js +5 -2
- package/dist/cjs/pm-plugins/util/edge-cases/handleVSCodeBlock.js +2 -3
- package/dist/cjs/pm-plugins/util/normalize-pasted-code-block-attrs.js +94 -0
- package/dist/es2019/entry-points/paste-plugin-type.js +0 -0
- package/dist/es2019/entry-points/paste-plugin.js +2 -0
- package/dist/es2019/pm-plugins/main.js +5 -2
- package/dist/es2019/pm-plugins/util/edge-cases/handleVSCodeBlock.js +2 -3
- package/dist/es2019/pm-plugins/util/normalize-pasted-code-block-attrs.js +75 -0
- package/dist/esm/entry-points/paste-plugin-type.js +0 -0
- package/dist/esm/entry-points/paste-plugin.js +2 -0
- package/dist/esm/pm-plugins/main.js +5 -2
- package/dist/esm/pm-plugins/util/edge-cases/handleVSCodeBlock.js +2 -3
- package/dist/esm/pm-plugins/util/normalize-pasted-code-block-attrs.js +87 -0
- package/dist/types/entry-points/paste-plugin-type.d.ts +1 -0
- package/dist/types/entry-points/paste-plugin.d.ts +1 -0
- package/dist/types/pm-plugins/util/normalize-pasted-code-block-attrs.d.ts +3 -0
- package/dist/types-ts4.5/entry-points/paste-plugin-type.d.ts +1 -0
- package/dist/types-ts4.5/entry-points/paste-plugin.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/util/normalize-pasted-code-block-attrs.d.ts +3 -0
- package/package.json +6 -6
- package/paste-plugin/package.json +15 -0
- package/paste-plugin-type/package.json +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-paste
|
|
2
2
|
|
|
3
|
+
## 11.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`d93fb5f6f6ced`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d93fb5f6f6ced) -
|
|
8
|
+
[EDITOR-7014] Preserve explicit code block wrap values during paste and ADF serialization
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 11.2.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [`a94a013546f69`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a94a013546f69) -
|
|
16
|
+
Autofix: add explicit package exports (barrel removal)
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
|
|
3
22
|
## 11.1.11
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "pastePlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _pastePlugin.pastePlugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _pastePlugin = require("../pastePlugin");
|
|
@@ -12,7 +12,6 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
12
12
|
var _uuid = _interopRequireDefault(require("uuid"));
|
|
13
13
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
14
14
|
var _card = require("@atlaskit/editor-common/card");
|
|
15
|
-
var _codeBlock = require("@atlaskit/editor-common/code-block");
|
|
16
15
|
var _coreUtils = require("@atlaskit/editor-common/core-utils");
|
|
17
16
|
var _extensions = require("@atlaskit/editor-common/extensions");
|
|
18
17
|
var _nesting = require("@atlaskit/editor-common/nesting");
|
|
@@ -41,6 +40,7 @@ var _pluginFactory = require("./plugin-factory");
|
|
|
41
40
|
var _util = require("./util");
|
|
42
41
|
var _handleVSCodeBlock = require("./util/edge-cases/handleVSCodeBlock");
|
|
43
42
|
var _handlers = require("./util/handlers");
|
|
43
|
+
var _normalizePastedCodeBlockAttrs = require("./util/normalize-pasted-code-block-attrs");
|
|
44
44
|
var _syncBlock2 = require("./util/sync-block");
|
|
45
45
|
var _tinyMCE = require("./util/tinyMCE");
|
|
46
46
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
@@ -91,7 +91,7 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
|
|
|
91
91
|
var escapedTextInput = (0, _util.escapeBackslashAndLinksExceptCodeBlock)(text);
|
|
92
92
|
var doc = atlassianMarkDownParser.parse(escapedTextInput);
|
|
93
93
|
if (doc && doc.content) {
|
|
94
|
-
return
|
|
94
|
+
return new _model.Slice(doc.content, openStart, openEnd);
|
|
95
95
|
}
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
@@ -322,6 +322,9 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
|
|
|
322
322
|
var _pluginInjectionApi$b;
|
|
323
323
|
tr = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$b = pluginInjectionApi.betterTypeHistory) === null || _pluginInjectionApi$b === void 0 ? void 0 : _pluginInjectionApi$b.actions.flagPasteEvent(tr);
|
|
324
324
|
}
|
|
325
|
+
if ((0, _expValEquals.expValEquals)('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
|
|
326
|
+
tr = (0, _normalizePastedCodeBlockAttrs.normalizePastedCodeBlockAttrs)(tr, schema.nodes.codeBlock);
|
|
327
|
+
}
|
|
325
328
|
var isDocChanged = tr.docChanged;
|
|
326
329
|
(0, _card.addLinkMetadata)(view.state.selection, tr, {
|
|
327
330
|
action: isPlainText ? _analytics.ACTION.PASTED_AS_PLAIN : _analytics.ACTION.PASTED,
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.handleVSCodeBlock = handleVSCodeBlock;
|
|
7
7
|
var _constants = require("@atlaskit/code/constants");
|
|
8
|
-
var _codeBlock = require("@atlaskit/editor-common/code-block");
|
|
9
8
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
10
9
|
function safelyGetVSCodeLanguage(editorData) {
|
|
11
10
|
try {
|
|
@@ -28,9 +27,9 @@ function handleVSCodeBlock(_ref) {
|
|
|
28
27
|
slice = (0, _utils.mapSlice)(slice, function (node) {
|
|
29
28
|
var _schema$nodes$codeBlo;
|
|
30
29
|
if (node.type.name === ((_schema$nodes$codeBlo = schema.nodes.codeBlock) === null || _schema$nodes$codeBlo === void 0 ? void 0 : _schema$nodes$codeBlo.name)) {
|
|
31
|
-
return schema.nodes.codeBlock.createChecked(
|
|
30
|
+
return schema.nodes.codeBlock.createChecked({
|
|
32
31
|
language: language
|
|
33
|
-
}
|
|
32
|
+
}, schema.text(text));
|
|
34
33
|
}
|
|
35
34
|
return node;
|
|
36
35
|
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.normalizePastedCodeBlockAttrs = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _codeBlock = require("@atlaskit/editor-common/code-block");
|
|
10
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
11
|
+
var isReplaceStep = function isReplaceStep(step) {
|
|
12
|
+
return step instanceof _transform.ReplaceStep || step instanceof _transform.ReplaceAroundStep;
|
|
13
|
+
};
|
|
14
|
+
var isCodeBlockWithUnsetWrap = function isCodeBlockWithUnsetWrap(node, codeBlockType) {
|
|
15
|
+
return node.type === codeBlockType && node.attrs.wrap === null;
|
|
16
|
+
};
|
|
17
|
+
var collectInsertedCodeBlocksWithUnsetWrap = function collectInsertedCodeBlocksWithUnsetWrap(step, codeBlockType) {
|
|
18
|
+
var insertedCodeBlocks = new Set();
|
|
19
|
+
step.slice.content.descendants(function (node) {
|
|
20
|
+
if (isCodeBlockWithUnsetWrap(node, codeBlockType)) {
|
|
21
|
+
insertedCodeBlocks.add(node);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
});
|
|
26
|
+
return insertedCodeBlocks;
|
|
27
|
+
};
|
|
28
|
+
var collectMappedInsertedRanges = function collectMappedInsertedRanges(tr, stepIndex) {
|
|
29
|
+
var ranges = [];
|
|
30
|
+
var stepMap = tr.mapping.maps[stepIndex];
|
|
31
|
+
var remainingMaps = tr.mapping.slice(stepIndex + 1);
|
|
32
|
+
stepMap.forEach(function (_oldStart, _oldEnd, newStart, newEnd) {
|
|
33
|
+
if (newStart === newEnd) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
var finalFrom = remainingMaps.map(newStart, 1);
|
|
37
|
+
var finalTo = remainingMaps.map(newEnd, -1);
|
|
38
|
+
if (finalFrom < finalTo) {
|
|
39
|
+
ranges.push([finalFrom, finalTo]);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return ranges;
|
|
43
|
+
};
|
|
44
|
+
var collectInsertedCodeBlockPositions = function collectInsertedCodeBlockPositions(tr, ranges, insertedCodeBlocks) {
|
|
45
|
+
var positions = new Set();
|
|
46
|
+
ranges.forEach(function (_ref) {
|
|
47
|
+
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
48
|
+
from = _ref2[0],
|
|
49
|
+
to = _ref2[1];
|
|
50
|
+
tr.doc.nodesBetween(from, to, function (node, pos) {
|
|
51
|
+
if (insertedCodeBlocks.has(node)) {
|
|
52
|
+
positions.add(pos);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
return positions;
|
|
59
|
+
};
|
|
60
|
+
var patchInsertedCodeBlocks = function patchInsertedCodeBlocks(tr, positionsToPatch, insertedCodeBlocks) {
|
|
61
|
+
positionsToPatch.forEach(function (pos) {
|
|
62
|
+
var node = tr.doc.nodeAt(pos);
|
|
63
|
+
if (!node || !insertedCodeBlocks.has(node)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
tr.setNodeMarkup(pos, undefined, (0, _codeBlock.getDefaultCodeBlockAttrs)(node.attrs), node.marks);
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
var normalizePastedCodeBlockAttrs = exports.normalizePastedCodeBlockAttrs = function normalizePastedCodeBlockAttrs(tr, codeBlockType) {
|
|
70
|
+
if (!codeBlockType) {
|
|
71
|
+
return tr;
|
|
72
|
+
}
|
|
73
|
+
var insertedCodeBlocks = new Set();
|
|
74
|
+
var positionsToPatch = new Set();
|
|
75
|
+
tr.steps.forEach(function (step, index) {
|
|
76
|
+
if (!isReplaceStep(step)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
var codeBlocksInsertedByStep = collectInsertedCodeBlocksWithUnsetWrap(step, codeBlockType);
|
|
80
|
+
if (!codeBlocksInsertedByStep.size) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
codeBlocksInsertedByStep.forEach(function (node) {
|
|
84
|
+
return insertedCodeBlocks.add(node);
|
|
85
|
+
});
|
|
86
|
+
collectInsertedCodeBlockPositions(tr, collectMappedInsertedRanges(tr, index), codeBlocksInsertedByStep).forEach(function (pos) {
|
|
87
|
+
return positionsToPatch.add(pos);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
if (positionsToPatch.size) {
|
|
91
|
+
patchInsertedCodeBlocks(tr, positionsToPatch, insertedCodeBlocks);
|
|
92
|
+
}
|
|
93
|
+
return tr;
|
|
94
|
+
};
|
|
File without changes
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import uuid from 'uuid';
|
|
3
3
|
import { ACTION, INPUT_METHOD, PasteTypes } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { addLinkMetadata } from '@atlaskit/editor-common/card';
|
|
5
|
-
import { defaultWrapForMarkdownCodeBlocksInSlice } from '@atlaskit/editor-common/code-block';
|
|
6
5
|
import { insideTable } from '@atlaskit/editor-common/core-utils';
|
|
7
6
|
import { getExtensionAutoConvertersFromProvider } from '@atlaskit/editor-common/extensions';
|
|
8
7
|
import { isNestedTablesSupported } from '@atlaskit/editor-common/nesting';
|
|
@@ -31,6 +30,7 @@ import { createPluginState, pluginKey as stateKey } from './plugin-factory';
|
|
|
31
30
|
import { escapeBackslashAndLinksExceptCodeBlock, getPasteSource, htmlContainsSingleFile, htmlHasInvalidLinkTags, isPastedFromExcel, isPastedFromWord, removeDuplicateInvalidLinks, transformUnsupportedBlockCardToInline } from './util';
|
|
32
31
|
import { handleVSCodeBlock } from './util/edge-cases/handleVSCodeBlock';
|
|
33
32
|
import { handleMacroAutoConvert, handleMention, handleParagraphBlockMarks, handlePasteExpand, handleTableContentPasteInBodiedExtension } from './util/handlers';
|
|
33
|
+
import { normalizePastedCodeBlockAttrs } from './util/normalize-pasted-code-block-attrs';
|
|
34
34
|
import { handleSyncBlocksPaste } from './util/sync-block';
|
|
35
35
|
import { htmlHasIncompleteTable, isPastedFromTinyMCEConfluence, tryRebuildCompleteTableHtml } from './util/tinyMCE';
|
|
36
36
|
export const isInsideBlockQuote = state => {
|
|
@@ -80,7 +80,7 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
80
80
|
const escapedTextInput = escapeBackslashAndLinksExceptCodeBlock(text);
|
|
81
81
|
const doc = atlassianMarkDownParser.parse(escapedTextInput);
|
|
82
82
|
if (doc && doc.content) {
|
|
83
|
-
return
|
|
83
|
+
return new Slice(doc.content, openStart, openEnd);
|
|
84
84
|
}
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
@@ -282,6 +282,9 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
282
282
|
var _pluginInjectionApi$b;
|
|
283
283
|
tr = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$b = pluginInjectionApi.betterTypeHistory) === null || _pluginInjectionApi$b === void 0 ? void 0 : _pluginInjectionApi$b.actions.flagPasteEvent(tr);
|
|
284
284
|
}
|
|
285
|
+
if (expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
|
|
286
|
+
tr = normalizePastedCodeBlockAttrs(tr, schema.nodes.codeBlock);
|
|
287
|
+
}
|
|
285
288
|
const isDocChanged = tr.docChanged;
|
|
286
289
|
addLinkMetadata(view.state.selection, tr, {
|
|
287
290
|
action: isPlainText ? ACTION.PASTED_AS_PLAIN : ACTION.PASTED,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SUPPORTED_LANGUAGES } from '@atlaskit/code/constants';
|
|
2
|
-
import { getDefaultCodeBlockAttrs } from '@atlaskit/editor-common/code-block';
|
|
3
2
|
import { mapSlice } from '@atlaskit/editor-common/utils';
|
|
4
3
|
function safelyGetVSCodeLanguage(editorData) {
|
|
5
4
|
try {
|
|
@@ -23,9 +22,9 @@ export function handleVSCodeBlock({
|
|
|
23
22
|
slice = mapSlice(slice, node => {
|
|
24
23
|
var _schema$nodes$codeBlo;
|
|
25
24
|
if (node.type.name === ((_schema$nodes$codeBlo = schema.nodes.codeBlock) === null || _schema$nodes$codeBlo === void 0 ? void 0 : _schema$nodes$codeBlo.name)) {
|
|
26
|
-
return schema.nodes.codeBlock.createChecked(
|
|
25
|
+
return schema.nodes.codeBlock.createChecked({
|
|
27
26
|
language
|
|
28
|
-
}
|
|
27
|
+
}, schema.text(text));
|
|
29
28
|
}
|
|
30
29
|
return node;
|
|
31
30
|
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { getDefaultCodeBlockAttrs } from '@atlaskit/editor-common/code-block';
|
|
2
|
+
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
3
|
+
const isReplaceStep = step => step instanceof ReplaceStep || step instanceof ReplaceAroundStep;
|
|
4
|
+
const isCodeBlockWithUnsetWrap = (node, codeBlockType) => node.type === codeBlockType && node.attrs.wrap === null;
|
|
5
|
+
const collectInsertedCodeBlocksWithUnsetWrap = (step, codeBlockType) => {
|
|
6
|
+
const insertedCodeBlocks = new Set();
|
|
7
|
+
step.slice.content.descendants(node => {
|
|
8
|
+
if (isCodeBlockWithUnsetWrap(node, codeBlockType)) {
|
|
9
|
+
insertedCodeBlocks.add(node);
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
});
|
|
14
|
+
return insertedCodeBlocks;
|
|
15
|
+
};
|
|
16
|
+
const collectMappedInsertedRanges = (tr, stepIndex) => {
|
|
17
|
+
const ranges = [];
|
|
18
|
+
const stepMap = tr.mapping.maps[stepIndex];
|
|
19
|
+
const remainingMaps = tr.mapping.slice(stepIndex + 1);
|
|
20
|
+
stepMap.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
|
|
21
|
+
if (newStart === newEnd) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const finalFrom = remainingMaps.map(newStart, 1);
|
|
25
|
+
const finalTo = remainingMaps.map(newEnd, -1);
|
|
26
|
+
if (finalFrom < finalTo) {
|
|
27
|
+
ranges.push([finalFrom, finalTo]);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return ranges;
|
|
31
|
+
};
|
|
32
|
+
const collectInsertedCodeBlockPositions = (tr, ranges, insertedCodeBlocks) => {
|
|
33
|
+
const positions = new Set();
|
|
34
|
+
ranges.forEach(([from, to]) => {
|
|
35
|
+
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
36
|
+
if (insertedCodeBlocks.has(node)) {
|
|
37
|
+
positions.add(pos);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
return positions;
|
|
44
|
+
};
|
|
45
|
+
const patchInsertedCodeBlocks = (tr, positionsToPatch, insertedCodeBlocks) => {
|
|
46
|
+
positionsToPatch.forEach(pos => {
|
|
47
|
+
const node = tr.doc.nodeAt(pos);
|
|
48
|
+
if (!node || !insertedCodeBlocks.has(node)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
tr.setNodeMarkup(pos, undefined, getDefaultCodeBlockAttrs(node.attrs), node.marks);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
export const normalizePastedCodeBlockAttrs = (tr, codeBlockType) => {
|
|
55
|
+
if (!codeBlockType) {
|
|
56
|
+
return tr;
|
|
57
|
+
}
|
|
58
|
+
const insertedCodeBlocks = new Set();
|
|
59
|
+
const positionsToPatch = new Set();
|
|
60
|
+
tr.steps.forEach((step, index) => {
|
|
61
|
+
if (!isReplaceStep(step)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const codeBlocksInsertedByStep = collectInsertedCodeBlocksWithUnsetWrap(step, codeBlockType);
|
|
65
|
+
if (!codeBlocksInsertedByStep.size) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
codeBlocksInsertedByStep.forEach(node => insertedCodeBlocks.add(node));
|
|
69
|
+
collectInsertedCodeBlockPositions(tr, collectMappedInsertedRanges(tr, index), codeBlocksInsertedByStep).forEach(pos => positionsToPatch.add(pos));
|
|
70
|
+
});
|
|
71
|
+
if (positionsToPatch.size) {
|
|
72
|
+
patchInsertedCodeBlocks(tr, positionsToPatch, insertedCodeBlocks);
|
|
73
|
+
}
|
|
74
|
+
return tr;
|
|
75
|
+
};
|
|
File without changes
|
|
@@ -7,7 +7,6 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
7
7
|
import uuid from 'uuid';
|
|
8
8
|
import { ACTION, INPUT_METHOD, PasteTypes } from '@atlaskit/editor-common/analytics';
|
|
9
9
|
import { addLinkMetadata } from '@atlaskit/editor-common/card';
|
|
10
|
-
import { defaultWrapForMarkdownCodeBlocksInSlice } from '@atlaskit/editor-common/code-block';
|
|
11
10
|
import { insideTable } from '@atlaskit/editor-common/core-utils';
|
|
12
11
|
import { getExtensionAutoConvertersFromProvider } from '@atlaskit/editor-common/extensions';
|
|
13
12
|
import { isNestedTablesSupported } from '@atlaskit/editor-common/nesting';
|
|
@@ -36,6 +35,7 @@ import { createPluginState, pluginKey as stateKey } from './plugin-factory';
|
|
|
36
35
|
import { escapeBackslashAndLinksExceptCodeBlock, getPasteSource, htmlContainsSingleFile, htmlHasInvalidLinkTags, isPastedFromExcel, isPastedFromWord, removeDuplicateInvalidLinks, transformUnsupportedBlockCardToInline } from './util';
|
|
37
36
|
import { handleVSCodeBlock } from './util/edge-cases/handleVSCodeBlock';
|
|
38
37
|
import { handleMacroAutoConvert, handleMention, handleParagraphBlockMarks, handlePasteExpand, handleTableContentPasteInBodiedExtension } from './util/handlers';
|
|
38
|
+
import { normalizePastedCodeBlockAttrs } from './util/normalize-pasted-code-block-attrs';
|
|
39
39
|
import { handleSyncBlocksPaste } from './util/sync-block';
|
|
40
40
|
import { htmlHasIncompleteTable, isPastedFromTinyMCEConfluence, tryRebuildCompleteTableHtml } from './util/tinyMCE';
|
|
41
41
|
export var isInsideBlockQuote = function isInsideBlockQuote(state) {
|
|
@@ -83,7 +83,7 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
83
83
|
var escapedTextInput = escapeBackslashAndLinksExceptCodeBlock(text);
|
|
84
84
|
var doc = atlassianMarkDownParser.parse(escapedTextInput);
|
|
85
85
|
if (doc && doc.content) {
|
|
86
|
-
return
|
|
86
|
+
return new Slice(doc.content, openStart, openEnd);
|
|
87
87
|
}
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
@@ -314,6 +314,9 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
314
314
|
var _pluginInjectionApi$b;
|
|
315
315
|
tr = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$b = pluginInjectionApi.betterTypeHistory) === null || _pluginInjectionApi$b === void 0 ? void 0 : _pluginInjectionApi$b.actions.flagPasteEvent(tr);
|
|
316
316
|
}
|
|
317
|
+
if (expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
|
|
318
|
+
tr = normalizePastedCodeBlockAttrs(tr, schema.nodes.codeBlock);
|
|
319
|
+
}
|
|
317
320
|
var isDocChanged = tr.docChanged;
|
|
318
321
|
addLinkMetadata(view.state.selection, tr, {
|
|
319
322
|
action: isPlainText ? ACTION.PASTED_AS_PLAIN : ACTION.PASTED,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SUPPORTED_LANGUAGES } from '@atlaskit/code/constants';
|
|
2
|
-
import { getDefaultCodeBlockAttrs } from '@atlaskit/editor-common/code-block';
|
|
3
2
|
import { mapSlice } from '@atlaskit/editor-common/utils';
|
|
4
3
|
function safelyGetVSCodeLanguage(editorData) {
|
|
5
4
|
try {
|
|
@@ -22,9 +21,9 @@ export function handleVSCodeBlock(_ref) {
|
|
|
22
21
|
slice = mapSlice(slice, function (node) {
|
|
23
22
|
var _schema$nodes$codeBlo;
|
|
24
23
|
if (node.type.name === ((_schema$nodes$codeBlo = schema.nodes.codeBlock) === null || _schema$nodes$codeBlo === void 0 ? void 0 : _schema$nodes$codeBlo.name)) {
|
|
25
|
-
return schema.nodes.codeBlock.createChecked(
|
|
24
|
+
return schema.nodes.codeBlock.createChecked({
|
|
26
25
|
language: language
|
|
27
|
-
}
|
|
26
|
+
}, schema.text(text));
|
|
28
27
|
}
|
|
29
28
|
return node;
|
|
30
29
|
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { getDefaultCodeBlockAttrs } from '@atlaskit/editor-common/code-block';
|
|
3
|
+
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
+
var isReplaceStep = function isReplaceStep(step) {
|
|
5
|
+
return step instanceof ReplaceStep || step instanceof ReplaceAroundStep;
|
|
6
|
+
};
|
|
7
|
+
var isCodeBlockWithUnsetWrap = function isCodeBlockWithUnsetWrap(node, codeBlockType) {
|
|
8
|
+
return node.type === codeBlockType && node.attrs.wrap === null;
|
|
9
|
+
};
|
|
10
|
+
var collectInsertedCodeBlocksWithUnsetWrap = function collectInsertedCodeBlocksWithUnsetWrap(step, codeBlockType) {
|
|
11
|
+
var insertedCodeBlocks = new Set();
|
|
12
|
+
step.slice.content.descendants(function (node) {
|
|
13
|
+
if (isCodeBlockWithUnsetWrap(node, codeBlockType)) {
|
|
14
|
+
insertedCodeBlocks.add(node);
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
});
|
|
19
|
+
return insertedCodeBlocks;
|
|
20
|
+
};
|
|
21
|
+
var collectMappedInsertedRanges = function collectMappedInsertedRanges(tr, stepIndex) {
|
|
22
|
+
var ranges = [];
|
|
23
|
+
var stepMap = tr.mapping.maps[stepIndex];
|
|
24
|
+
var remainingMaps = tr.mapping.slice(stepIndex + 1);
|
|
25
|
+
stepMap.forEach(function (_oldStart, _oldEnd, newStart, newEnd) {
|
|
26
|
+
if (newStart === newEnd) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
var finalFrom = remainingMaps.map(newStart, 1);
|
|
30
|
+
var finalTo = remainingMaps.map(newEnd, -1);
|
|
31
|
+
if (finalFrom < finalTo) {
|
|
32
|
+
ranges.push([finalFrom, finalTo]);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return ranges;
|
|
36
|
+
};
|
|
37
|
+
var collectInsertedCodeBlockPositions = function collectInsertedCodeBlockPositions(tr, ranges, insertedCodeBlocks) {
|
|
38
|
+
var positions = new Set();
|
|
39
|
+
ranges.forEach(function (_ref) {
|
|
40
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
41
|
+
from = _ref2[0],
|
|
42
|
+
to = _ref2[1];
|
|
43
|
+
tr.doc.nodesBetween(from, to, function (node, pos) {
|
|
44
|
+
if (insertedCodeBlocks.has(node)) {
|
|
45
|
+
positions.add(pos);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
return positions;
|
|
52
|
+
};
|
|
53
|
+
var patchInsertedCodeBlocks = function patchInsertedCodeBlocks(tr, positionsToPatch, insertedCodeBlocks) {
|
|
54
|
+
positionsToPatch.forEach(function (pos) {
|
|
55
|
+
var node = tr.doc.nodeAt(pos);
|
|
56
|
+
if (!node || !insertedCodeBlocks.has(node)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
tr.setNodeMarkup(pos, undefined, getDefaultCodeBlockAttrs(node.attrs), node.marks);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
export var normalizePastedCodeBlockAttrs = function normalizePastedCodeBlockAttrs(tr, codeBlockType) {
|
|
63
|
+
if (!codeBlockType) {
|
|
64
|
+
return tr;
|
|
65
|
+
}
|
|
66
|
+
var insertedCodeBlocks = new Set();
|
|
67
|
+
var positionsToPatch = new Set();
|
|
68
|
+
tr.steps.forEach(function (step, index) {
|
|
69
|
+
if (!isReplaceStep(step)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
var codeBlocksInsertedByStep = collectInsertedCodeBlocksWithUnsetWrap(step, codeBlockType);
|
|
73
|
+
if (!codeBlocksInsertedByStep.size) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
codeBlocksInsertedByStep.forEach(function (node) {
|
|
77
|
+
return insertedCodeBlocks.add(node);
|
|
78
|
+
});
|
|
79
|
+
collectInsertedCodeBlockPositions(tr, collectMappedInsertedRanges(tr, index), codeBlocksInsertedByStep).forEach(function (pos) {
|
|
80
|
+
return positionsToPatch.add(pos);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
if (positionsToPatch.size) {
|
|
84
|
+
patchInsertedCodeBlocks(tr, positionsToPatch, insertedCodeBlocks);
|
|
85
|
+
}
|
|
86
|
+
return tr;
|
|
87
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { PastePlugin, PastePluginOptions, PastePluginState, LastContentPasted, PastePluginDependencies, ActiveFlag, } from '../pastePluginType';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { pastePlugin } from '../pastePlugin';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { PastePlugin, PastePluginOptions, PastePluginState, LastContentPasted, PastePluginDependencies, ActiveFlag, } from '../pastePluginType';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { pastePlugin } from '../pastePlugin';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-paste",
|
|
3
|
-
"version": "11.1
|
|
3
|
+
"version": "11.2.1",
|
|
4
4
|
"description": "Paste plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"@atlaskit/editor-plugin-annotation": "^10.3.0",
|
|
35
35
|
"@atlaskit/editor-plugin-better-type-history": "^10.0.0",
|
|
36
36
|
"@atlaskit/editor-plugin-card": "^16.7.0",
|
|
37
|
-
"@atlaskit/editor-plugin-expand": "^11.
|
|
38
|
-
"@atlaskit/editor-plugin-feature-flags": "^9.
|
|
39
|
-
"@atlaskit/editor-plugin-list": "^12.
|
|
40
|
-
"@atlaskit/editor-plugin-media": "^12.
|
|
41
|
-
"@atlaskit/editor-plugin-mentions": "^12.
|
|
37
|
+
"@atlaskit/editor-plugin-expand": "^11.2.0",
|
|
38
|
+
"@atlaskit/editor-plugin-feature-flags": "^9.1.0",
|
|
39
|
+
"@atlaskit/editor-plugin-list": "^12.1.0",
|
|
40
|
+
"@atlaskit/editor-plugin-media": "^12.7.0",
|
|
41
|
+
"@atlaskit/editor-plugin-mentions": "^12.2.0",
|
|
42
42
|
"@atlaskit/editor-prosemirror": "^7.3.0",
|
|
43
43
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
44
44
|
"@atlaskit/flag": "^17.11.0",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-plugin-paste/paste-plugin",
|
|
3
|
+
"main": "../dist/cjs/entry-points/paste-plugin.js",
|
|
4
|
+
"module": "../dist/esm/entry-points/paste-plugin.js",
|
|
5
|
+
"module:es2019": "../dist/es2019/entry-points/paste-plugin.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"types": "../dist/types/entry-points/paste-plugin.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
">=4.5 <5.9": {
|
|
10
|
+
"*": [
|
|
11
|
+
"../dist/types-ts4.5/entry-points/paste-plugin.d.ts"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-plugin-paste/paste-plugin-type",
|
|
3
|
+
"main": "../dist/cjs/entry-points/paste-plugin-type.js",
|
|
4
|
+
"module": "../dist/esm/entry-points/paste-plugin-type.js",
|
|
5
|
+
"module:es2019": "../dist/es2019/entry-points/paste-plugin-type.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"types": "../dist/types/entry-points/paste-plugin-type.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
">=4.5 <5.9": {
|
|
10
|
+
"*": [
|
|
11
|
+
"../dist/types-ts4.5/entry-points/paste-plugin-type.d.ts"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|