@atlaskit/editor-plugin-paste 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/pm-plugins/analytics.js +2 -2
- package/dist/cjs/pm-plugins/main.js +7 -0
- package/dist/cjs/pm-plugins/util/edge-cases/handleVSCodeBlock.js +42 -0
- package/dist/es2019/pm-plugins/main.js +7 -0
- package/dist/es2019/pm-plugins/util/edge-cases/handleVSCodeBlock.js +37 -0
- package/dist/esm/pm-plugins/analytics.js +4 -3
- package/dist/esm/pm-plugins/main.js +7 -0
- package/dist/esm/pm-plugins/util/edge-cases/handleVSCodeBlock.js +36 -0
- package/dist/types/pm-plugins/util/edge-cases/handleVSCodeBlock.d.ts +10 -0
- package/dist/types-ts4.5/pm-plugins/util/edge-cases/handleVSCodeBlock.d.ts +10 -0
- package/package.json +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -410,12 +410,12 @@ var createPasteMeasurePayload = exports.createPasteMeasurePayload = function cre
|
|
|
410
410
|
}
|
|
411
411
|
};
|
|
412
412
|
};
|
|
413
|
-
var
|
|
413
|
+
var _getContentNodeTypes = exports.getContentNodeTypes = function getContentNodeTypes(content) {
|
|
414
414
|
var nodeTypes = new Set();
|
|
415
415
|
if (content.size) {
|
|
416
416
|
content.forEach(function (node) {
|
|
417
417
|
if (node.content && node.content.size) {
|
|
418
|
-
nodeTypes = new Set([].concat((0, _toConsumableArray2.default)(nodeTypes), (0, _toConsumableArray2.default)(
|
|
418
|
+
nodeTypes = new Set([].concat((0, _toConsumableArray2.default)(nodeTypes), (0, _toConsumableArray2.default)(_getContentNodeTypes(node.content))));
|
|
419
419
|
}
|
|
420
420
|
nodeTypes.add(node.type.name);
|
|
421
421
|
});
|
|
@@ -30,6 +30,7 @@ var _analytics2 = require("./analytics");
|
|
|
30
30
|
var _clipboardTextSerializer = require("./clipboard-text-serializer");
|
|
31
31
|
var _pluginFactory = require("./plugin-factory");
|
|
32
32
|
var _util = require("./util");
|
|
33
|
+
var _handleVSCodeBlock = require("./util/edge-cases/handleVSCodeBlock");
|
|
33
34
|
var _handlers = require("./util/handlers");
|
|
34
35
|
var _tinyMCE = require("./util/tinyMCE");
|
|
35
36
|
var isInsideBlockQuote = exports.isInsideBlockQuote = function isInsideBlockQuote(state) {
|
|
@@ -275,6 +276,12 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
|
|
|
275
276
|
view.dispatch(tr.setMeta('uiEvent', 'paste'));
|
|
276
277
|
};
|
|
277
278
|
slice = (0, _handlers.handleParagraphBlockMarks)(state, slice);
|
|
279
|
+
slice = (0, _handleVSCodeBlock.handleVSCodeBlock)({
|
|
280
|
+
state: state,
|
|
281
|
+
slice: slice,
|
|
282
|
+
event: event,
|
|
283
|
+
text: text
|
|
284
|
+
});
|
|
278
285
|
var plainTextPasteSlice = (0, _utils.linkifyContent)(state.schema)(slice);
|
|
279
286
|
if ((0, _analytics2.handlePasteAsPlainTextWithAnalytics)(editorAnalyticsAPI)(view, event, plainTextPasteSlice)(state, dispatch, view)) {
|
|
280
287
|
return true;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.handleVSCodeBlock = handleVSCodeBlock;
|
|
7
|
+
var _constants = require("@atlaskit/code/constants");
|
|
8
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
9
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
10
|
+
function safelyGetVSCodeLanguage(editorData) {
|
|
11
|
+
try {
|
|
12
|
+
var vscodeData = editorData ? JSON.parse(editorData) : undefined;
|
|
13
|
+
return vscodeData === null || vscodeData === void 0 ? void 0 : vscodeData.mode;
|
|
14
|
+
} catch (_e) {}
|
|
15
|
+
}
|
|
16
|
+
function handleVSCodeBlock(_ref) {
|
|
17
|
+
var _event$clipboardData;
|
|
18
|
+
var state = _ref.state,
|
|
19
|
+
slice = _ref.slice,
|
|
20
|
+
text = _ref.text,
|
|
21
|
+
event = _ref.event;
|
|
22
|
+
if (!(0, _platformFeatureFlags.fg)('platform_editor_vs_code_block_paste')) {
|
|
23
|
+
return slice;
|
|
24
|
+
}
|
|
25
|
+
var vscodeData = event === null || event === void 0 || (_event$clipboardData = event.clipboardData) === null || _event$clipboardData === void 0 ? void 0 : _event$clipboardData.getData('vscode-editor-data');
|
|
26
|
+
var language = safelyGetVSCodeLanguage(vscodeData);
|
|
27
|
+
if (text && language && _constants.SUPPORTED_LANGUAGES.some(function (l) {
|
|
28
|
+
return l.alias[0] === language;
|
|
29
|
+
})) {
|
|
30
|
+
var schema = state.schema;
|
|
31
|
+
slice = (0, _utils.mapSlice)(slice, function (node) {
|
|
32
|
+
var _schema$nodes$codeBlo;
|
|
33
|
+
if (node.type.name === ((_schema$nodes$codeBlo = schema.nodes.codeBlock) === null || _schema$nodes$codeBlo === void 0 ? void 0 : _schema$nodes$codeBlo.name)) {
|
|
34
|
+
return schema.nodes.codeBlock.createChecked({
|
|
35
|
+
language: language
|
|
36
|
+
}, schema.text(text));
|
|
37
|
+
}
|
|
38
|
+
return node;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return slice;
|
|
42
|
+
}
|
|
@@ -20,6 +20,7 @@ import { createPasteMeasurePayload, getContentNodeTypes, handleCodeBlockWithAnal
|
|
|
20
20
|
import { clipboardTextSerializer } from './clipboard-text-serializer';
|
|
21
21
|
import { createPluginState, pluginKey as stateKey } from './plugin-factory';
|
|
22
22
|
import { escapeLinks, getPasteSource, htmlContainsSingleFile, htmlHasInvalidLinkTags, isPastedFromExcel, isPastedFromWord, removeDuplicateInvalidLinks, transformUnsupportedBlockCardToInline } from './util';
|
|
23
|
+
import { handleVSCodeBlock } from './util/edge-cases/handleVSCodeBlock';
|
|
23
24
|
import { handleMacroAutoConvert, handleMention, handleParagraphBlockMarks, handleTableContentPasteInBodiedExtension } from './util/handlers';
|
|
24
25
|
import { htmlHasIncompleteTable, isPastedFromTinyMCEConfluence, tryRebuildCompleteTableHtml } from './util/tinyMCE';
|
|
25
26
|
export const isInsideBlockQuote = state => {
|
|
@@ -249,6 +250,12 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
249
250
|
view.dispatch(tr.setMeta('uiEvent', 'paste'));
|
|
250
251
|
};
|
|
251
252
|
slice = handleParagraphBlockMarks(state, slice);
|
|
253
|
+
slice = handleVSCodeBlock({
|
|
254
|
+
state,
|
|
255
|
+
slice,
|
|
256
|
+
event,
|
|
257
|
+
text
|
|
258
|
+
});
|
|
252
259
|
const plainTextPasteSlice = linkifyContent(state.schema)(slice);
|
|
253
260
|
if (handlePasteAsPlainTextWithAnalytics(editorAnalyticsAPI)(view, event, plainTextPasteSlice)(state, dispatch, view)) {
|
|
254
261
|
return true;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SUPPORTED_LANGUAGES } from '@atlaskit/code/constants';
|
|
2
|
+
import { mapSlice } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
|
+
function safelyGetVSCodeLanguage(editorData) {
|
|
5
|
+
try {
|
|
6
|
+
const vscodeData = editorData ? JSON.parse(editorData) : undefined;
|
|
7
|
+
return vscodeData === null || vscodeData === void 0 ? void 0 : vscodeData.mode;
|
|
8
|
+
} catch (_e) {}
|
|
9
|
+
}
|
|
10
|
+
export function handleVSCodeBlock({
|
|
11
|
+
state,
|
|
12
|
+
slice,
|
|
13
|
+
text,
|
|
14
|
+
event
|
|
15
|
+
}) {
|
|
16
|
+
var _event$clipboardData;
|
|
17
|
+
if (!fg('platform_editor_vs_code_block_paste')) {
|
|
18
|
+
return slice;
|
|
19
|
+
}
|
|
20
|
+
const vscodeData = event === null || event === void 0 ? void 0 : (_event$clipboardData = event.clipboardData) === null || _event$clipboardData === void 0 ? void 0 : _event$clipboardData.getData('vscode-editor-data');
|
|
21
|
+
const language = safelyGetVSCodeLanguage(vscodeData);
|
|
22
|
+
if (text && language && SUPPORTED_LANGUAGES.some(l => l.alias[0] === language)) {
|
|
23
|
+
const {
|
|
24
|
+
schema
|
|
25
|
+
} = state;
|
|
26
|
+
slice = mapSlice(slice, node => {
|
|
27
|
+
var _schema$nodes$codeBlo;
|
|
28
|
+
if (node.type.name === ((_schema$nodes$codeBlo = schema.nodes.codeBlock) === null || _schema$nodes$codeBlo === void 0 ? void 0 : _schema$nodes$codeBlo.name)) {
|
|
29
|
+
return schema.nodes.codeBlock.createChecked({
|
|
30
|
+
language
|
|
31
|
+
}, schema.text(text));
|
|
32
|
+
}
|
|
33
|
+
return node;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return slice;
|
|
37
|
+
}
|
|
@@ -398,15 +398,16 @@ export var createPasteMeasurePayload = function createPasteMeasurePayload(_ref3)
|
|
|
398
398
|
}
|
|
399
399
|
};
|
|
400
400
|
};
|
|
401
|
-
|
|
401
|
+
var _getContentNodeTypes = function getContentNodeTypes(content) {
|
|
402
402
|
var nodeTypes = new Set();
|
|
403
403
|
if (content.size) {
|
|
404
404
|
content.forEach(function (node) {
|
|
405
405
|
if (node.content && node.content.size) {
|
|
406
|
-
nodeTypes = new Set([].concat(_toConsumableArray(nodeTypes), _toConsumableArray(
|
|
406
|
+
nodeTypes = new Set([].concat(_toConsumableArray(nodeTypes), _toConsumableArray(_getContentNodeTypes(node.content))));
|
|
407
407
|
}
|
|
408
408
|
nodeTypes.add(node.type.name);
|
|
409
409
|
});
|
|
410
410
|
}
|
|
411
411
|
return Array.from(nodeTypes);
|
|
412
|
-
};
|
|
412
|
+
};
|
|
413
|
+
export { _getContentNodeTypes as getContentNodeTypes };
|
|
@@ -22,6 +22,7 @@ import { createPasteMeasurePayload, getContentNodeTypes, handleCodeBlockWithAnal
|
|
|
22
22
|
import { clipboardTextSerializer } from './clipboard-text-serializer';
|
|
23
23
|
import { createPluginState, pluginKey as stateKey } from './plugin-factory';
|
|
24
24
|
import { escapeLinks, getPasteSource, htmlContainsSingleFile, htmlHasInvalidLinkTags, isPastedFromExcel, isPastedFromWord, removeDuplicateInvalidLinks, transformUnsupportedBlockCardToInline } from './util';
|
|
25
|
+
import { handleVSCodeBlock } from './util/edge-cases/handleVSCodeBlock';
|
|
25
26
|
import { handleMacroAutoConvert, handleMention, handleParagraphBlockMarks, handleTableContentPasteInBodiedExtension } from './util/handlers';
|
|
26
27
|
import { htmlHasIncompleteTable, isPastedFromTinyMCEConfluence, tryRebuildCompleteTableHtml } from './util/tinyMCE';
|
|
27
28
|
export var isInsideBlockQuote = function isInsideBlockQuote(state) {
|
|
@@ -267,6 +268,12 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
267
268
|
view.dispatch(tr.setMeta('uiEvent', 'paste'));
|
|
268
269
|
};
|
|
269
270
|
slice = handleParagraphBlockMarks(state, slice);
|
|
271
|
+
slice = handleVSCodeBlock({
|
|
272
|
+
state: state,
|
|
273
|
+
slice: slice,
|
|
274
|
+
event: event,
|
|
275
|
+
text: text
|
|
276
|
+
});
|
|
270
277
|
var plainTextPasteSlice = linkifyContent(state.schema)(slice);
|
|
271
278
|
if (handlePasteAsPlainTextWithAnalytics(editorAnalyticsAPI)(view, event, plainTextPasteSlice)(state, dispatch, view)) {
|
|
272
279
|
return true;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SUPPORTED_LANGUAGES } from '@atlaskit/code/constants';
|
|
2
|
+
import { mapSlice } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
|
+
function safelyGetVSCodeLanguage(editorData) {
|
|
5
|
+
try {
|
|
6
|
+
var vscodeData = editorData ? JSON.parse(editorData) : undefined;
|
|
7
|
+
return vscodeData === null || vscodeData === void 0 ? void 0 : vscodeData.mode;
|
|
8
|
+
} catch (_e) {}
|
|
9
|
+
}
|
|
10
|
+
export function handleVSCodeBlock(_ref) {
|
|
11
|
+
var _event$clipboardData;
|
|
12
|
+
var state = _ref.state,
|
|
13
|
+
slice = _ref.slice,
|
|
14
|
+
text = _ref.text,
|
|
15
|
+
event = _ref.event;
|
|
16
|
+
if (!fg('platform_editor_vs_code_block_paste')) {
|
|
17
|
+
return slice;
|
|
18
|
+
}
|
|
19
|
+
var vscodeData = event === null || event === void 0 || (_event$clipboardData = event.clipboardData) === null || _event$clipboardData === void 0 ? void 0 : _event$clipboardData.getData('vscode-editor-data');
|
|
20
|
+
var language = safelyGetVSCodeLanguage(vscodeData);
|
|
21
|
+
if (text && language && SUPPORTED_LANGUAGES.some(function (l) {
|
|
22
|
+
return l.alias[0] === language;
|
|
23
|
+
})) {
|
|
24
|
+
var schema = state.schema;
|
|
25
|
+
slice = mapSlice(slice, function (node) {
|
|
26
|
+
var _schema$nodes$codeBlo;
|
|
27
|
+
if (node.type.name === ((_schema$nodes$codeBlo = schema.nodes.codeBlock) === null || _schema$nodes$codeBlo === void 0 ? void 0 : _schema$nodes$codeBlo.name)) {
|
|
28
|
+
return schema.nodes.codeBlock.createChecked({
|
|
29
|
+
language: language
|
|
30
|
+
}, schema.text(text));
|
|
31
|
+
}
|
|
32
|
+
return node;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return slice;
|
|
36
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
interface VSCodeBlockParams {
|
|
4
|
+
state: EditorState;
|
|
5
|
+
slice: Slice;
|
|
6
|
+
text: string;
|
|
7
|
+
event: ClipboardEvent;
|
|
8
|
+
}
|
|
9
|
+
export declare function handleVSCodeBlock({ state, slice, text, event }: VSCodeBlockParams): Slice;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
interface VSCodeBlockParams {
|
|
4
|
+
state: EditorState;
|
|
5
|
+
slice: Slice;
|
|
6
|
+
text: string;
|
|
7
|
+
event: ClipboardEvent;
|
|
8
|
+
}
|
|
9
|
+
export declare function handleVSCodeBlock({ state, slice, text, event }: VSCodeBlockParams): Slice;
|
|
10
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-paste",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Paste plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@atlaskit/adf-schema": "^46.1.0",
|
|
35
|
-
"@atlaskit/
|
|
35
|
+
"@atlaskit/code": "^15.6.9",
|
|
36
|
+
"@atlaskit/editor-common": "^99.7.0",
|
|
36
37
|
"@atlaskit/editor-markdown-transformer": "^5.14.0",
|
|
37
38
|
"@atlaskit/editor-plugin-analytics": "^1.11.0",
|
|
38
39
|
"@atlaskit/editor-plugin-annotation": "^1.27.0",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"@atlaskit/editor-tables": "^2.8.0",
|
|
47
48
|
"@atlaskit/media-client": "^31.1.0",
|
|
48
49
|
"@atlaskit/media-common": "^11.8.0",
|
|
49
|
-
"@atlaskit/platform-feature-flags": "^0.
|
|
50
|
+
"@atlaskit/platform-feature-flags": "^1.0.0",
|
|
50
51
|
"@atlaskit/tmp-editor-statsig": "^2.41.0",
|
|
51
52
|
"@babel/runtime": "^7.0.0",
|
|
52
53
|
"lodash": "^4.17.21",
|
|
@@ -119,6 +120,9 @@
|
|
|
119
120
|
"platform_editor_use_nested_table_pm_nodes": {
|
|
120
121
|
"type": "boolean"
|
|
121
122
|
},
|
|
123
|
+
"platform_editor_vs_code_block_paste": {
|
|
124
|
+
"type": "boolean"
|
|
125
|
+
},
|
|
122
126
|
"platform_editor_advanced_layouts_post_fix_patch_2": {
|
|
123
127
|
"type": "boolean"
|
|
124
128
|
},
|