@atlaskit/editor-plugin-paste 1.12.4 → 1.12.5
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 +9 -0
- package/dist/cjs/handlers.js +16 -1
- package/dist/cjs/pm-plugins/analytics.js +2 -2
- package/dist/cjs/pm-plugins/main.js +7 -3
- package/dist/es2019/handlers.js +16 -1
- package/dist/es2019/pm-plugins/analytics.js +2 -2
- package/dist/es2019/pm-plugins/main.js +7 -3
- package/dist/esm/handlers.js +16 -1
- package/dist/esm/pm-plugins/analytics.js +2 -2
- package/dist/esm/pm-plugins/main.js +7 -3
- package/dist/types/handlers.d.ts +1 -1
- package/dist/types/pm-plugins/analytics.d.ts +1 -1
- package/dist/types-ts4.5/handlers.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/analytics.d.ts +1 -1
- package/package.json +6 -3
- package/.eslintrc.js +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-paste
|
|
2
2
|
|
|
3
|
+
## 1.12.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#143700](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/143700)
|
|
8
|
+
[`9ef9b7e3bc1d7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9ef9b7e3bc1d7) -
|
|
9
|
+
[ux] [ED-24868] Paste gating for codeblock and media in quotes.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
3
12
|
## 1.12.4
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/cjs/handlers.js
CHANGED
|
@@ -41,6 +41,7 @@ var _utils3 = require("@atlaskit/editor-tables/utils");
|
|
|
41
41
|
var _commands = require("./commands");
|
|
42
42
|
var _edgeCases = require("./edge-cases");
|
|
43
43
|
var _lists = require("./edge-cases/lists");
|
|
44
|
+
var _main = require("./pm-plugins/main");
|
|
44
45
|
var _pluginFactory = require("./pm-plugins/plugin-factory");
|
|
45
46
|
var _util = require("./util");
|
|
46
47
|
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; } } }; }
|
|
@@ -905,10 +906,11 @@ function flattenNestedListInSlice(slice) {
|
|
|
905
906
|
var contentWithFlattenedList = slice.content.replaceChild(0, listToFlatten.type.createChecked(listToFlatten.attrs, leafListItems));
|
|
906
907
|
return new _model.Slice(contentWithFlattenedList, slice.openEnd, slice.openEnd);
|
|
907
908
|
}
|
|
908
|
-
function handleRichText(slice, queueCardsFromChangedTr) {
|
|
909
|
+
function handleRichText(slice, queueCardsFromChangedTr, isNestingMediaOrCodeblockSupported) {
|
|
909
910
|
return function (state, dispatch) {
|
|
910
911
|
var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre;
|
|
911
912
|
var _state$schema$nodes4 = state.schema.nodes,
|
|
913
|
+
blockquote = _state$schema$nodes4.blockquote,
|
|
912
914
|
codeBlock = _state$schema$nodes4.codeBlock,
|
|
913
915
|
heading = _state$schema$nodes4.heading,
|
|
914
916
|
paragraph = _state$schema$nodes4.paragraph,
|
|
@@ -943,12 +945,25 @@ function handleRichText(slice, queueCardsFromChangedTr) {
|
|
|
943
945
|
var noNeedForSafeInsert = selection.$to.node().type.validContent(slice.content) || textNodes.includes(selection.$to.node().type) && selectionParent.type.validContent(slice.content);
|
|
944
946
|
var panelParentOverCurrentSelection = (0, _utils2.findParentNodeOfType)(panel)(tr.selection);
|
|
945
947
|
var isTargetPanelEmpty = panelParentOverCurrentSelection && ((_panelParentOverCurre = panelParentOverCurrentSelection.node) === null || _panelParentOverCurre === void 0 ? void 0 : _panelParentOverCurre.content.size) === 2;
|
|
948
|
+
var sliceContainsCodeblockOrMedia = false;
|
|
949
|
+
var codeBlockAndMediaNodes = ['codeBlock', 'mediaSingle', 'mediaGroup'];
|
|
950
|
+
slice.content.forEach(function (child) {
|
|
951
|
+
if (codeBlockAndMediaNodes.includes(child.type.name)) {
|
|
952
|
+
sliceContainsCodeblockOrMedia = true;
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
var blockquoteNode = (0, _utils2.findParentNodeOfType)(blockquote)(tr.selection);
|
|
946
956
|
if (!isSliceContentTaskListNodes && (isSliceContentListNodes || isTargetPanelEmpty)) {
|
|
947
957
|
(0, _edgeCases.insertSliceForLists)({
|
|
948
958
|
tr: tr,
|
|
949
959
|
slice: slice,
|
|
950
960
|
schema: schema
|
|
951
961
|
});
|
|
962
|
+
} else if (
|
|
963
|
+
// If nesting media or codeblock in blockquote is not supported
|
|
964
|
+
// we want to insert slice after the blockquote.
|
|
965
|
+
(0, _main.isInsideBlockQuote)(state) && sliceContainsCodeblockOrMedia && !isNestingMediaOrCodeblockSupported && blockquoteNode) {
|
|
966
|
+
tr = (0, _utils2.safeInsert)(slice.content, blockquoteNode.start + blockquoteNode.node.nodeSize - 1)(tr);
|
|
952
967
|
} else if (noNeedForSafeInsert) {
|
|
953
968
|
var _firstChildOfSlice$ty2, _firstChildOfSlice$co, _firstChildOfSlice$co2;
|
|
954
969
|
if ((firstChildOfSlice === null || firstChildOfSlice === void 0 || (_firstChildOfSlice$ty2 = firstChildOfSlice.type) === null || _firstChildOfSlice$ty2 === void 0 ? void 0 : _firstChildOfSlice$ty2.name) === 'blockquote' && firstChildOfSlice !== null && firstChildOfSlice !== void 0 && (_firstChildOfSlice$co = firstChildOfSlice.content.firstChild) !== null && _firstChildOfSlice$co !== void 0 && _firstChildOfSlice$co.type.name && ['bulletList', 'orderedList', 'mediaSingle'].includes(firstChildOfSlice === null || firstChildOfSlice === void 0 || (_firstChildOfSlice$co2 = firstChildOfSlice.content.firstChild) === null || _firstChildOfSlice$co2 === void 0 ? void 0 : _firstChildOfSlice$co2.type.name)) {
|
|
@@ -314,11 +314,11 @@ var handleMarkdownWithAnalytics = exports.handleMarkdownWithAnalytics = function
|
|
|
314
314
|
type: _analytics.PasteTypes.markdown
|
|
315
315
|
}))((0, _handlers.handleMarkdown)(slice, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c3 = pluginInjectionApi.card) === null || _pluginInjectionApi$c3 === void 0 || (_pluginInjectionApi$c3 = _pluginInjectionApi$c3.actions) === null || _pluginInjectionApi$c3 === void 0 ? void 0 : _pluginInjectionApi$c3.queueCardsFromChangedTr));
|
|
316
316
|
};
|
|
317
|
-
var handleRichTextWithAnalytics = exports.handleRichTextWithAnalytics = function handleRichTextWithAnalytics(view, event, slice, pluginInjectionApi) {
|
|
317
|
+
var handleRichTextWithAnalytics = exports.handleRichTextWithAnalytics = function handleRichTextWithAnalytics(view, event, slice, pluginInjectionApi, isNestingMediaOrCodeblockSupported) {
|
|
318
318
|
var _pluginInjectionApi$a4, _pluginInjectionApi$c4;
|
|
319
319
|
return injectAnalyticsPayloadBeforeCommand(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a4 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.actions)(createPasteAnalyticsPayloadBySelection(event, slice, {
|
|
320
320
|
type: _analytics.PasteTypes.richText
|
|
321
|
-
}, pluginInjectionApi))((0, _handlers.handleRichText)(slice, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c4 = pluginInjectionApi.card) === null || _pluginInjectionApi$c4 === void 0 || (_pluginInjectionApi$c4 = _pluginInjectionApi$c4.actions) === null || _pluginInjectionApi$c4 === void 0 ? void 0 : _pluginInjectionApi$c4.queueCardsFromChangedTr));
|
|
321
|
+
}, pluginInjectionApi))((0, _handlers.handleRichText)(slice, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c4 = pluginInjectionApi.card) === null || _pluginInjectionApi$c4 === void 0 || (_pluginInjectionApi$c4 = _pluginInjectionApi$c4.actions) === null || _pluginInjectionApi$c4 === void 0 ? void 0 : _pluginInjectionApi$c4.queueCardsFromChangedTr, isNestingMediaOrCodeblockSupported));
|
|
322
322
|
};
|
|
323
323
|
var injectAnalyticsPayloadBeforeCommand = function injectAnalyticsPayloadBeforeCommand(editorAnalyticsAPI) {
|
|
324
324
|
return function (createPayloadByTransaction) {
|
|
@@ -173,8 +173,11 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
|
|
|
173
173
|
/**
|
|
174
174
|
* We want to return false for external copied image to allow
|
|
175
175
|
* it to be uploaded by the client.
|
|
176
|
+
*
|
|
177
|
+
* Scenario where we are pasting an external image inside a block quote
|
|
178
|
+
* is skipped and handled in handleRichText
|
|
176
179
|
*/
|
|
177
|
-
if ((0, _util.htmlContainsSingleFile)(html)) {
|
|
180
|
+
if ((0, _util.htmlContainsSingleFile)(html) && !isInsideBlockQuote(view.state)) {
|
|
178
181
|
return true;
|
|
179
182
|
}
|
|
180
183
|
|
|
@@ -370,7 +373,7 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
|
|
|
370
373
|
|
|
371
374
|
// finally, handle rich-text copy-paste
|
|
372
375
|
if (isRichText || isNestedMarkdownTable) {
|
|
373
|
-
var _pluginInjectionApi$c2, _pluginInjectionApi$e2, _pluginInjectionApi$f, _pluginInjectionApi$l;
|
|
376
|
+
var _pluginInjectionApi$c2, _pluginInjectionApi$e2, _pluginInjectionApi$f, _pluginInjectionApi$l, _pluginInjectionApi$f2;
|
|
374
377
|
// linkify the text where possible
|
|
375
378
|
slice = (0, _utils.linkifyContent)(state.schema)(slice);
|
|
376
379
|
if ((0, _analytics2.handlePasteLinkOnSelectedTextWithAnalytics)(editorAnalyticsAPI)(view, event, slice, _analytics.PasteTypes.richText)(state, dispatch)) {
|
|
@@ -447,7 +450,8 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
|
|
|
447
450
|
if ((0, _analytics2.handlePasteNonNestableBlockNodesIntoListWithAnalytics)(editorAnalyticsAPI)(view, event, slice)(state, dispatch)) {
|
|
448
451
|
return true;
|
|
449
452
|
}
|
|
450
|
-
|
|
453
|
+
var isNestingMediaOrCodeblockSupported = (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$f2 = pluginInjectionApi.featureFlags) === null || _pluginInjectionApi$f2 === void 0 || (_pluginInjectionApi$f2 = _pluginInjectionApi$f2.sharedState.currentState()) === null || _pluginInjectionApi$f2 === void 0 ? void 0 : _pluginInjectionApi$f2.nestMediaAndCodeblockInQuote) || (0, _platformFeatureFlags.fg)('editor_nest_media_and_codeblock_in_quotes_jira');
|
|
454
|
+
return (0, _analytics2.handleRichTextWithAnalytics)(view, event, slice, pluginInjectionApi, isNestingMediaOrCodeblockSupported)(state, dispatch);
|
|
451
455
|
}
|
|
452
456
|
return false;
|
|
453
457
|
},
|
package/dist/es2019/handlers.js
CHANGED
|
@@ -14,6 +14,7 @@ import { replaceSelectedTable } from '@atlaskit/editor-tables/utils';
|
|
|
14
14
|
import { startTrackingPastedMacroPositions, stopTrackingPastedMacroPositions } from './commands';
|
|
15
15
|
import { insertSliceForLists, insertSliceForTaskInsideList, insertSliceInsideBlockquote } from './edge-cases';
|
|
16
16
|
import { insertSliceInsideOfPanelNodeSelected } from './edge-cases/lists';
|
|
17
|
+
import { isInsideBlockQuote } from './pm-plugins/main';
|
|
17
18
|
import { getPluginState as getPastePluginState } from './pm-plugins/plugin-factory';
|
|
18
19
|
import { addReplaceSelectedTableAnalytics, applyTextMarksToSlice, hasOnlyNodesOfType, isEmptyNode, isSelectionInsidePanel } from './util';
|
|
19
20
|
const insideExpand = state => {
|
|
@@ -880,10 +881,11 @@ export function flattenNestedListInSlice(slice) {
|
|
|
880
881
|
const contentWithFlattenedList = slice.content.replaceChild(0, listToFlatten.type.createChecked(listToFlatten.attrs, leafListItems));
|
|
881
882
|
return new Slice(contentWithFlattenedList, slice.openEnd, slice.openEnd);
|
|
882
883
|
}
|
|
883
|
-
export function handleRichText(slice, queueCardsFromChangedTr) {
|
|
884
|
+
export function handleRichText(slice, queueCardsFromChangedTr, isNestingMediaOrCodeblockSupported) {
|
|
884
885
|
return (state, dispatch) => {
|
|
885
886
|
var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre;
|
|
886
887
|
const {
|
|
888
|
+
blockquote,
|
|
887
889
|
codeBlock,
|
|
888
890
|
heading,
|
|
889
891
|
paragraph,
|
|
@@ -921,12 +923,25 @@ export function handleRichText(slice, queueCardsFromChangedTr) {
|
|
|
921
923
|
const noNeedForSafeInsert = selection.$to.node().type.validContent(slice.content) || textNodes.includes(selection.$to.node().type) && selectionParent.type.validContent(slice.content);
|
|
922
924
|
let panelParentOverCurrentSelection = findParentNodeOfType(panel)(tr.selection);
|
|
923
925
|
const isTargetPanelEmpty = panelParentOverCurrentSelection && ((_panelParentOverCurre = panelParentOverCurrentSelection.node) === null || _panelParentOverCurre === void 0 ? void 0 : _panelParentOverCurre.content.size) === 2;
|
|
926
|
+
let sliceContainsCodeblockOrMedia = false;
|
|
927
|
+
const codeBlockAndMediaNodes = ['codeBlock', 'mediaSingle', 'mediaGroup'];
|
|
928
|
+
slice.content.forEach(child => {
|
|
929
|
+
if (codeBlockAndMediaNodes.includes(child.type.name)) {
|
|
930
|
+
sliceContainsCodeblockOrMedia = true;
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
const blockquoteNode = findParentNodeOfType(blockquote)(tr.selection);
|
|
924
934
|
if (!isSliceContentTaskListNodes && (isSliceContentListNodes || isTargetPanelEmpty)) {
|
|
925
935
|
insertSliceForLists({
|
|
926
936
|
tr,
|
|
927
937
|
slice,
|
|
928
938
|
schema
|
|
929
939
|
});
|
|
940
|
+
} else if (
|
|
941
|
+
// If nesting media or codeblock in blockquote is not supported
|
|
942
|
+
// we want to insert slice after the blockquote.
|
|
943
|
+
isInsideBlockQuote(state) && sliceContainsCodeblockOrMedia && !isNestingMediaOrCodeblockSupported && blockquoteNode) {
|
|
944
|
+
tr = safeInsert(slice.content, blockquoteNode.start + blockquoteNode.node.nodeSize - 1)(tr);
|
|
930
945
|
} else if (noNeedForSafeInsert) {
|
|
931
946
|
var _firstChildOfSlice$ty2, _firstChildOfSlice$co, _firstChildOfSlice$co2;
|
|
932
947
|
if ((firstChildOfSlice === null || firstChildOfSlice === void 0 ? void 0 : (_firstChildOfSlice$ty2 = firstChildOfSlice.type) === null || _firstChildOfSlice$ty2 === void 0 ? void 0 : _firstChildOfSlice$ty2.name) === 'blockquote' && firstChildOfSlice !== null && firstChildOfSlice !== void 0 && (_firstChildOfSlice$co = firstChildOfSlice.content.firstChild) !== null && _firstChildOfSlice$co !== void 0 && _firstChildOfSlice$co.type.name && ['bulletList', 'orderedList', 'mediaSingle'].includes(firstChildOfSlice === null || firstChildOfSlice === void 0 ? void 0 : (_firstChildOfSlice$co2 = firstChildOfSlice.content.firstChild) === null || _firstChildOfSlice$co2 === void 0 ? void 0 : _firstChildOfSlice$co2.type.name)) {
|
|
@@ -291,11 +291,11 @@ export const handleMarkdownWithAnalytics = (view, event, slice, pluginInjectionA
|
|
|
291
291
|
type: PasteTypes.markdown
|
|
292
292
|
}))(handleMarkdown(slice, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$c5 = pluginInjectionApi.card) === null || _pluginInjectionApi$c5 === void 0 ? void 0 : (_pluginInjectionApi$c6 = _pluginInjectionApi$c5.actions) === null || _pluginInjectionApi$c6 === void 0 ? void 0 : _pluginInjectionApi$c6.queueCardsFromChangedTr));
|
|
293
293
|
};
|
|
294
|
-
export const handleRichTextWithAnalytics = (view, event, slice, pluginInjectionApi) => {
|
|
294
|
+
export const handleRichTextWithAnalytics = (view, event, slice, pluginInjectionApi, isNestingMediaOrCodeblockSupported) => {
|
|
295
295
|
var _pluginInjectionApi$a4, _pluginInjectionApi$c7, _pluginInjectionApi$c8;
|
|
296
296
|
return injectAnalyticsPayloadBeforeCommand(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a4 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.actions)(createPasteAnalyticsPayloadBySelection(event, slice, {
|
|
297
297
|
type: PasteTypes.richText
|
|
298
|
-
}, pluginInjectionApi))(handleRichText(slice, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$c7 = pluginInjectionApi.card) === null || _pluginInjectionApi$c7 === void 0 ? void 0 : (_pluginInjectionApi$c8 = _pluginInjectionApi$c7.actions) === null || _pluginInjectionApi$c8 === void 0 ? void 0 : _pluginInjectionApi$c8.queueCardsFromChangedTr));
|
|
298
|
+
}, pluginInjectionApi))(handleRichText(slice, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$c7 = pluginInjectionApi.card) === null || _pluginInjectionApi$c7 === void 0 ? void 0 : (_pluginInjectionApi$c8 = _pluginInjectionApi$c7.actions) === null || _pluginInjectionApi$c8 === void 0 ? void 0 : _pluginInjectionApi$c8.queueCardsFromChangedTr, isNestingMediaOrCodeblockSupported));
|
|
299
299
|
};
|
|
300
300
|
const injectAnalyticsPayloadBeforeCommand = editorAnalyticsAPI => createPayloadByTransaction => {
|
|
301
301
|
return mainCommand => {
|
|
@@ -137,8 +137,11 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
137
137
|
/**
|
|
138
138
|
* We want to return false for external copied image to allow
|
|
139
139
|
* it to be uploaded by the client.
|
|
140
|
+
*
|
|
141
|
+
* Scenario where we are pasting an external image inside a block quote
|
|
142
|
+
* is skipped and handled in handleRichText
|
|
140
143
|
*/
|
|
141
|
-
if (htmlContainsSingleFile(html)) {
|
|
144
|
+
if (htmlContainsSingleFile(html) && !isInsideBlockQuote(view.state)) {
|
|
142
145
|
return true;
|
|
143
146
|
}
|
|
144
147
|
|
|
@@ -341,7 +344,7 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
341
344
|
|
|
342
345
|
// finally, handle rich-text copy-paste
|
|
343
346
|
if (isRichText || isNestedMarkdownTable) {
|
|
344
|
-
var _pluginInjectionApi$c3, _pluginInjectionApi$c4, _pluginInjectionApi$e3, _pluginInjectionApi$e4, _pluginInjectionApi$f, _pluginInjectionApi$f2, _pluginInjectionApi$l;
|
|
347
|
+
var _pluginInjectionApi$c3, _pluginInjectionApi$c4, _pluginInjectionApi$e3, _pluginInjectionApi$e4, _pluginInjectionApi$f, _pluginInjectionApi$f2, _pluginInjectionApi$l, _pluginInjectionApi$f3, _pluginInjectionApi$f4;
|
|
345
348
|
// linkify the text where possible
|
|
346
349
|
slice = linkifyContent(state.schema)(slice);
|
|
347
350
|
if (handlePasteLinkOnSelectedTextWithAnalytics(editorAnalyticsAPI)(view, event, slice, PasteTypes.richText)(state, dispatch)) {
|
|
@@ -416,7 +419,8 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
416
419
|
if (handlePasteNonNestableBlockNodesIntoListWithAnalytics(editorAnalyticsAPI)(view, event, slice)(state, dispatch)) {
|
|
417
420
|
return true;
|
|
418
421
|
}
|
|
419
|
-
|
|
422
|
+
const isNestingMediaOrCodeblockSupported = (pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$f3 = pluginInjectionApi.featureFlags) === null || _pluginInjectionApi$f3 === void 0 ? void 0 : (_pluginInjectionApi$f4 = _pluginInjectionApi$f3.sharedState.currentState()) === null || _pluginInjectionApi$f4 === void 0 ? void 0 : _pluginInjectionApi$f4.nestMediaAndCodeblockInQuote) || fg('editor_nest_media_and_codeblock_in_quotes_jira');
|
|
423
|
+
return handleRichTextWithAnalytics(view, event, slice, pluginInjectionApi, isNestingMediaOrCodeblockSupported)(state, dispatch);
|
|
420
424
|
}
|
|
421
425
|
return false;
|
|
422
426
|
},
|
package/dist/esm/handlers.js
CHANGED
|
@@ -22,6 +22,7 @@ import { replaceSelectedTable } from '@atlaskit/editor-tables/utils';
|
|
|
22
22
|
import { startTrackingPastedMacroPositions, stopTrackingPastedMacroPositions } from './commands';
|
|
23
23
|
import { insertSliceForLists, insertSliceForTaskInsideList, insertSliceInsideBlockquote } from './edge-cases';
|
|
24
24
|
import { insertSliceInsideOfPanelNodeSelected } from './edge-cases/lists';
|
|
25
|
+
import { isInsideBlockQuote } from './pm-plugins/main';
|
|
25
26
|
import { getPluginState as getPastePluginState } from './pm-plugins/plugin-factory';
|
|
26
27
|
import { addReplaceSelectedTableAnalytics, applyTextMarksToSlice, hasOnlyNodesOfType, isEmptyNode, isSelectionInsidePanel } from './util';
|
|
27
28
|
var insideExpand = function insideExpand(state) {
|
|
@@ -881,10 +882,11 @@ export function flattenNestedListInSlice(slice) {
|
|
|
881
882
|
var contentWithFlattenedList = slice.content.replaceChild(0, listToFlatten.type.createChecked(listToFlatten.attrs, leafListItems));
|
|
882
883
|
return new Slice(contentWithFlattenedList, slice.openEnd, slice.openEnd);
|
|
883
884
|
}
|
|
884
|
-
export function handleRichText(slice, queueCardsFromChangedTr) {
|
|
885
|
+
export function handleRichText(slice, queueCardsFromChangedTr, isNestingMediaOrCodeblockSupported) {
|
|
885
886
|
return function (state, dispatch) {
|
|
886
887
|
var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre;
|
|
887
888
|
var _state$schema$nodes4 = state.schema.nodes,
|
|
889
|
+
blockquote = _state$schema$nodes4.blockquote,
|
|
888
890
|
codeBlock = _state$schema$nodes4.codeBlock,
|
|
889
891
|
heading = _state$schema$nodes4.heading,
|
|
890
892
|
paragraph = _state$schema$nodes4.paragraph,
|
|
@@ -919,12 +921,25 @@ export function handleRichText(slice, queueCardsFromChangedTr) {
|
|
|
919
921
|
var noNeedForSafeInsert = selection.$to.node().type.validContent(slice.content) || textNodes.includes(selection.$to.node().type) && selectionParent.type.validContent(slice.content);
|
|
920
922
|
var panelParentOverCurrentSelection = findParentNodeOfType(panel)(tr.selection);
|
|
921
923
|
var isTargetPanelEmpty = panelParentOverCurrentSelection && ((_panelParentOverCurre = panelParentOverCurrentSelection.node) === null || _panelParentOverCurre === void 0 ? void 0 : _panelParentOverCurre.content.size) === 2;
|
|
924
|
+
var sliceContainsCodeblockOrMedia = false;
|
|
925
|
+
var codeBlockAndMediaNodes = ['codeBlock', 'mediaSingle', 'mediaGroup'];
|
|
926
|
+
slice.content.forEach(function (child) {
|
|
927
|
+
if (codeBlockAndMediaNodes.includes(child.type.name)) {
|
|
928
|
+
sliceContainsCodeblockOrMedia = true;
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
var blockquoteNode = findParentNodeOfType(blockquote)(tr.selection);
|
|
922
932
|
if (!isSliceContentTaskListNodes && (isSliceContentListNodes || isTargetPanelEmpty)) {
|
|
923
933
|
insertSliceForLists({
|
|
924
934
|
tr: tr,
|
|
925
935
|
slice: slice,
|
|
926
936
|
schema: schema
|
|
927
937
|
});
|
|
938
|
+
} else if (
|
|
939
|
+
// If nesting media or codeblock in blockquote is not supported
|
|
940
|
+
// we want to insert slice after the blockquote.
|
|
941
|
+
isInsideBlockQuote(state) && sliceContainsCodeblockOrMedia && !isNestingMediaOrCodeblockSupported && blockquoteNode) {
|
|
942
|
+
tr = safeInsert(slice.content, blockquoteNode.start + blockquoteNode.node.nodeSize - 1)(tr);
|
|
928
943
|
} else if (noNeedForSafeInsert) {
|
|
929
944
|
var _firstChildOfSlice$ty2, _firstChildOfSlice$co, _firstChildOfSlice$co2;
|
|
930
945
|
if ((firstChildOfSlice === null || firstChildOfSlice === void 0 || (_firstChildOfSlice$ty2 = firstChildOfSlice.type) === null || _firstChildOfSlice$ty2 === void 0 ? void 0 : _firstChildOfSlice$ty2.name) === 'blockquote' && firstChildOfSlice !== null && firstChildOfSlice !== void 0 && (_firstChildOfSlice$co = firstChildOfSlice.content.firstChild) !== null && _firstChildOfSlice$co !== void 0 && _firstChildOfSlice$co.type.name && ['bulletList', 'orderedList', 'mediaSingle'].includes(firstChildOfSlice === null || firstChildOfSlice === void 0 || (_firstChildOfSlice$co2 = firstChildOfSlice.content.firstChild) === null || _firstChildOfSlice$co2 === void 0 ? void 0 : _firstChildOfSlice$co2.type.name)) {
|
|
@@ -302,11 +302,11 @@ export var handleMarkdownWithAnalytics = function handleMarkdownWithAnalytics(vi
|
|
|
302
302
|
type: PasteTypes.markdown
|
|
303
303
|
}))(handleMarkdown(slice, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c3 = pluginInjectionApi.card) === null || _pluginInjectionApi$c3 === void 0 || (_pluginInjectionApi$c3 = _pluginInjectionApi$c3.actions) === null || _pluginInjectionApi$c3 === void 0 ? void 0 : _pluginInjectionApi$c3.queueCardsFromChangedTr));
|
|
304
304
|
};
|
|
305
|
-
export var handleRichTextWithAnalytics = function handleRichTextWithAnalytics(view, event, slice, pluginInjectionApi) {
|
|
305
|
+
export var handleRichTextWithAnalytics = function handleRichTextWithAnalytics(view, event, slice, pluginInjectionApi, isNestingMediaOrCodeblockSupported) {
|
|
306
306
|
var _pluginInjectionApi$a4, _pluginInjectionApi$c4;
|
|
307
307
|
return injectAnalyticsPayloadBeforeCommand(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a4 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.actions)(createPasteAnalyticsPayloadBySelection(event, slice, {
|
|
308
308
|
type: PasteTypes.richText
|
|
309
|
-
}, pluginInjectionApi))(handleRichText(slice, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c4 = pluginInjectionApi.card) === null || _pluginInjectionApi$c4 === void 0 || (_pluginInjectionApi$c4 = _pluginInjectionApi$c4.actions) === null || _pluginInjectionApi$c4 === void 0 ? void 0 : _pluginInjectionApi$c4.queueCardsFromChangedTr));
|
|
309
|
+
}, pluginInjectionApi))(handleRichText(slice, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c4 = pluginInjectionApi.card) === null || _pluginInjectionApi$c4 === void 0 || (_pluginInjectionApi$c4 = _pluginInjectionApi$c4.actions) === null || _pluginInjectionApi$c4 === void 0 ? void 0 : _pluginInjectionApi$c4.queueCardsFromChangedTr, isNestingMediaOrCodeblockSupported));
|
|
310
310
|
};
|
|
311
311
|
var injectAnalyticsPayloadBeforeCommand = function injectAnalyticsPayloadBeforeCommand(editorAnalyticsAPI) {
|
|
312
312
|
return function (createPayloadByTransaction) {
|
|
@@ -160,8 +160,11 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
160
160
|
/**
|
|
161
161
|
* We want to return false for external copied image to allow
|
|
162
162
|
* it to be uploaded by the client.
|
|
163
|
+
*
|
|
164
|
+
* Scenario where we are pasting an external image inside a block quote
|
|
165
|
+
* is skipped and handled in handleRichText
|
|
163
166
|
*/
|
|
164
|
-
if (htmlContainsSingleFile(html)) {
|
|
167
|
+
if (htmlContainsSingleFile(html) && !isInsideBlockQuote(view.state)) {
|
|
165
168
|
return true;
|
|
166
169
|
}
|
|
167
170
|
|
|
@@ -357,7 +360,7 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
357
360
|
|
|
358
361
|
// finally, handle rich-text copy-paste
|
|
359
362
|
if (isRichText || isNestedMarkdownTable) {
|
|
360
|
-
var _pluginInjectionApi$c2, _pluginInjectionApi$e2, _pluginInjectionApi$f, _pluginInjectionApi$l;
|
|
363
|
+
var _pluginInjectionApi$c2, _pluginInjectionApi$e2, _pluginInjectionApi$f, _pluginInjectionApi$l, _pluginInjectionApi$f2;
|
|
361
364
|
// linkify the text where possible
|
|
362
365
|
slice = linkifyContent(state.schema)(slice);
|
|
363
366
|
if (handlePasteLinkOnSelectedTextWithAnalytics(editorAnalyticsAPI)(view, event, slice, PasteTypes.richText)(state, dispatch)) {
|
|
@@ -434,7 +437,8 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
434
437
|
if (handlePasteNonNestableBlockNodesIntoListWithAnalytics(editorAnalyticsAPI)(view, event, slice)(state, dispatch)) {
|
|
435
438
|
return true;
|
|
436
439
|
}
|
|
437
|
-
|
|
440
|
+
var isNestingMediaOrCodeblockSupported = (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$f2 = pluginInjectionApi.featureFlags) === null || _pluginInjectionApi$f2 === void 0 || (_pluginInjectionApi$f2 = _pluginInjectionApi$f2.sharedState.currentState()) === null || _pluginInjectionApi$f2 === void 0 ? void 0 : _pluginInjectionApi$f2.nestMediaAndCodeblockInQuote) || fg('editor_nest_media_and_codeblock_in_quotes_jira');
|
|
441
|
+
return handleRichTextWithAnalytics(view, event, slice, pluginInjectionApi, isNestingMediaOrCodeblockSupported)(state, dispatch);
|
|
438
442
|
}
|
|
439
443
|
return false;
|
|
440
444
|
},
|
package/dist/types/handlers.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare function handleParagraphBlockMarks(state: EditorState, slice: Sli
|
|
|
51
51
|
* ┗━p -> "two"
|
|
52
52
|
*/
|
|
53
53
|
export declare function flattenNestedListInSlice(slice: Slice): Slice;
|
|
54
|
-
export declare function handleRichText(slice: Slice, queueCardsFromChangedTr: QueueCardsFromTransactionAction | undefined): Command;
|
|
54
|
+
export declare function handleRichText(slice: Slice, queueCardsFromChangedTr: QueueCardsFromTransactionAction | undefined, isNestingMediaOrCodeblockSupported?: boolean): Command;
|
|
55
55
|
export declare function handlePasteIntoCaption(slice: Slice): Command;
|
|
56
56
|
export declare const handleSelectedTable: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (slice: Slice) => Command;
|
|
57
57
|
export declare function checkTaskListInList(state: EditorState, slice: Slice): boolean;
|
|
@@ -28,7 +28,7 @@ export declare const handleCodeBlockWithAnalytics: (editorAnalyticsAPI: EditorAn
|
|
|
28
28
|
export declare const handleMediaSingleWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (view: EditorView, event: ClipboardEvent, slice: Slice, type: PasteType, insertMediaAsMediaSingle: InsertMediaAsMediaSingle | undefined) => Command;
|
|
29
29
|
export declare const handlePastePreservingMarksWithAnalytics: (view: EditorView, event: ClipboardEvent, slice: Slice, type: PasteType, pluginInjectionApi: ExtractInjectionAPI<PastePlugin> | undefined) => Command;
|
|
30
30
|
export declare const handleMarkdownWithAnalytics: (view: EditorView, event: ClipboardEvent, slice: Slice, pluginInjectionApi: ExtractInjectionAPI<PastePlugin> | undefined) => Command;
|
|
31
|
-
export declare const handleRichTextWithAnalytics: (view: EditorView, event: ClipboardEvent, slice: Slice, pluginInjectionApi: ExtractInjectionAPI<PastePlugin> | undefined) => Command;
|
|
31
|
+
export declare const handleRichTextWithAnalytics: (view: EditorView, event: ClipboardEvent, slice: Slice, pluginInjectionApi: ExtractInjectionAPI<PastePlugin> | undefined, isNestingMediaOrCodeblockSupported: boolean) => Command;
|
|
32
32
|
export declare const handlePastePanelOrDecisionIntoListWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (view: EditorView, event: ClipboardEvent, slice: Slice, findRootParentListNode: FindRootParentListNode | undefined) => Command;
|
|
33
33
|
export declare const handlePasteNonNestableBlockNodesIntoListWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (view: EditorView, event: ClipboardEvent, slice: Slice) => Command;
|
|
34
34
|
export declare const handleExpandWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, isNestingExpandsSupported: boolean) => (view: EditorView, event: ClipboardEvent, slice: Slice) => Command;
|
|
@@ -51,7 +51,7 @@ export declare function handleParagraphBlockMarks(state: EditorState, slice: Sli
|
|
|
51
51
|
* ┗━p -> "two"
|
|
52
52
|
*/
|
|
53
53
|
export declare function flattenNestedListInSlice(slice: Slice): Slice;
|
|
54
|
-
export declare function handleRichText(slice: Slice, queueCardsFromChangedTr: QueueCardsFromTransactionAction | undefined): Command;
|
|
54
|
+
export declare function handleRichText(slice: Slice, queueCardsFromChangedTr: QueueCardsFromTransactionAction | undefined, isNestingMediaOrCodeblockSupported?: boolean): Command;
|
|
55
55
|
export declare function handlePasteIntoCaption(slice: Slice): Command;
|
|
56
56
|
export declare const handleSelectedTable: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (slice: Slice) => Command;
|
|
57
57
|
export declare function checkTaskListInList(state: EditorState, slice: Slice): boolean;
|
|
@@ -28,7 +28,7 @@ export declare const handleCodeBlockWithAnalytics: (editorAnalyticsAPI: EditorAn
|
|
|
28
28
|
export declare const handleMediaSingleWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (view: EditorView, event: ClipboardEvent, slice: Slice, type: PasteType, insertMediaAsMediaSingle: InsertMediaAsMediaSingle | undefined) => Command;
|
|
29
29
|
export declare const handlePastePreservingMarksWithAnalytics: (view: EditorView, event: ClipboardEvent, slice: Slice, type: PasteType, pluginInjectionApi: ExtractInjectionAPI<PastePlugin> | undefined) => Command;
|
|
30
30
|
export declare const handleMarkdownWithAnalytics: (view: EditorView, event: ClipboardEvent, slice: Slice, pluginInjectionApi: ExtractInjectionAPI<PastePlugin> | undefined) => Command;
|
|
31
|
-
export declare const handleRichTextWithAnalytics: (view: EditorView, event: ClipboardEvent, slice: Slice, pluginInjectionApi: ExtractInjectionAPI<PastePlugin> | undefined) => Command;
|
|
31
|
+
export declare const handleRichTextWithAnalytics: (view: EditorView, event: ClipboardEvent, slice: Slice, pluginInjectionApi: ExtractInjectionAPI<PastePlugin> | undefined, isNestingMediaOrCodeblockSupported: boolean) => Command;
|
|
32
32
|
export declare const handlePastePanelOrDecisionIntoListWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (view: EditorView, event: ClipboardEvent, slice: Slice, findRootParentListNode: FindRootParentListNode | undefined) => Command;
|
|
33
33
|
export declare const handlePasteNonNestableBlockNodesIntoListWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (view: EditorView, event: ClipboardEvent, slice: Slice) => Command;
|
|
34
34
|
export declare const handleExpandWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, isNestingExpandsSupported: boolean) => (view: EditorView, event: ClipboardEvent, slice: Slice) => Command;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-paste",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.5",
|
|
4
4
|
"description": "Paste plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
".": "./src/index.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@atlaskit/editor-common": "^
|
|
34
|
+
"@atlaskit/editor-common": "^91.0.0",
|
|
35
35
|
"@atlaskit/editor-markdown-transformer": "^5.12.0",
|
|
36
36
|
"@atlaskit/editor-plugin-analytics": "^1.8.0",
|
|
37
37
|
"@atlaskit/editor-plugin-annotation": "^1.19.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@atlaskit/editor-plugin-card": "^3.0.0",
|
|
40
40
|
"@atlaskit/editor-plugin-feature-flags": "^1.2.0",
|
|
41
41
|
"@atlaskit/editor-plugin-list": "^3.8.0",
|
|
42
|
-
"@atlaskit/editor-plugin-media": "^1.
|
|
42
|
+
"@atlaskit/editor-plugin-media": "^1.32.0",
|
|
43
43
|
"@atlaskit/editor-plugin-mentions": "^2.6.0",
|
|
44
44
|
"@atlaskit/editor-prosemirror": "6.0.0",
|
|
45
45
|
"@atlaskit/editor-tables": "^2.8.0",
|
|
@@ -120,6 +120,9 @@
|
|
|
120
120
|
},
|
|
121
121
|
"platform_editor_nest_nested_expand_in_expand_jira": {
|
|
122
122
|
"type": "boolean"
|
|
123
|
+
},
|
|
124
|
+
"editor_nest_media_and_codeblock_in_quotes_jira": {
|
|
125
|
+
"type": "boolean"
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
128
|
}
|
package/.eslintrc.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
rules: {
|
|
3
|
-
'@typescript-eslint/no-duplicate-imports': 'error',
|
|
4
|
-
'@typescript-eslint/no-explicit-any': 'error',
|
|
5
|
-
'@typescript-eslint/ban-types': [
|
|
6
|
-
'error',
|
|
7
|
-
{
|
|
8
|
-
types: {
|
|
9
|
-
'React.FC':
|
|
10
|
-
'Please use types directly on props instead, and explicitly define children if required',
|
|
11
|
-
'React.FunctionalComponent':
|
|
12
|
-
'Please use types directly on props instead, and explicitly define children if required',
|
|
13
|
-
},
|
|
14
|
-
extendDefaults: false,
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
},
|
|
18
|
-
};
|