@atlaskit/editor-plugin-paste 0.1.22 → 0.2.0
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/.eslintrc.js +18 -0
- package/CHANGELOG.md +6 -0
- package/dist/cjs/actions.js +12 -0
- package/dist/cjs/commands.js +255 -0
- package/dist/cjs/edge-cases/index.js +88 -0
- package/dist/cjs/edge-cases/lists.js +107 -0
- package/dist/cjs/handlers.js +939 -0
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/plugin.js +43 -0
- package/dist/cjs/plugins/media.js +207 -0
- package/dist/cjs/pm-plugins/analytics.js +376 -0
- package/dist/cjs/pm-plugins/clipboard-text-serializer.js +43 -0
- package/dist/cjs/pm-plugins/main.js +484 -0
- package/dist/cjs/pm-plugins/plugin-factory.js +42 -0
- package/dist/cjs/reducer.js +41 -0
- package/dist/cjs/util/index.js +214 -0
- package/dist/cjs/util/tinyMCE.js +183 -0
- package/dist/es2019/actions.js +6 -0
- package/dist/es2019/commands.js +236 -0
- package/dist/es2019/edge-cases/index.js +87 -0
- package/dist/es2019/edge-cases/lists.js +113 -0
- package/dist/es2019/handlers.js +919 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/plugin.js +38 -0
- package/dist/es2019/plugins/media.js +204 -0
- package/dist/es2019/pm-plugins/analytics.js +332 -0
- package/dist/es2019/pm-plugins/clipboard-text-serializer.js +37 -0
- package/dist/es2019/pm-plugins/main.js +453 -0
- package/dist/es2019/pm-plugins/plugin-factory.js +30 -0
- package/dist/es2019/reducer.js +32 -0
- package/dist/es2019/util/index.js +209 -0
- package/dist/es2019/util/tinyMCE.js +168 -0
- package/dist/esm/actions.js +6 -0
- package/dist/esm/commands.js +249 -0
- package/dist/esm/edge-cases/index.js +81 -0
- package/dist/esm/edge-cases/lists.js +98 -0
- package/dist/esm/handlers.js +918 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/plugin.js +37 -0
- package/dist/esm/plugins/media.js +199 -0
- package/dist/esm/pm-plugins/analytics.js +364 -0
- package/dist/esm/pm-plugins/clipboard-text-serializer.js +37 -0
- package/dist/esm/pm-plugins/main.js +471 -0
- package/dist/esm/pm-plugins/plugin-factory.js +36 -0
- package/dist/esm/reducer.js +34 -0
- package/dist/esm/util/index.js +194 -0
- package/dist/esm/util/tinyMCE.js +176 -0
- package/dist/types/actions.d.ts +21 -0
- package/dist/types/commands.d.ts +29 -0
- package/dist/types/edge-cases/index.d.ts +11 -0
- package/dist/types/edge-cases/lists.d.ts +18 -0
- package/dist/types/handlers.d.ts +55 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/plugin.d.ts +2 -0
- package/dist/types/plugins/media.d.ts +23 -0
- package/dist/types/pm-plugins/analytics.d.ts +44 -0
- package/dist/types/pm-plugins/clipboard-text-serializer.d.ts +13 -0
- package/dist/types/pm-plugins/main.d.ts +12 -0
- package/dist/types/pm-plugins/plugin-factory.d.ts +3 -0
- package/dist/types/reducer.d.ts +3 -0
- package/dist/types/util/index.d.ts +21 -0
- package/dist/types/util/tinyMCE.d.ts +32 -0
- package/dist/types-ts4.5/actions.d.ts +21 -0
- package/dist/types-ts4.5/commands.d.ts +29 -0
- package/dist/types-ts4.5/edge-cases/index.d.ts +11 -0
- package/dist/types-ts4.5/edge-cases/lists.d.ts +18 -0
- package/dist/types-ts4.5/handlers.d.ts +55 -0
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/plugin.d.ts +2 -0
- package/dist/types-ts4.5/plugins/media.d.ts +23 -0
- package/dist/types-ts4.5/pm-plugins/analytics.d.ts +44 -0
- package/dist/types-ts4.5/pm-plugins/clipboard-text-serializer.d.ts +13 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +12 -0
- package/dist/types-ts4.5/pm-plugins/plugin-factory.d.ts +3 -0
- package/dist/types-ts4.5/reducer.d.ts +3 -0
- package/dist/types-ts4.5/util/index.d.ts +21 -0
- package/dist/types-ts4.5/util/tinyMCE.d.ts +32 -0
- package/package.json +17 -5
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { isListNode } from '@atlaskit/editor-common/utils';
|
|
2
|
+
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
+
import { findParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
5
|
+
import { isCursorSelectionAtTextStartOrEnd, isEmptyNode, isSelectionInsidePanel } from '../util';
|
|
6
|
+
import { insertSliceAtNodeEdge, insertSliceInsideOfPanelNodeSelected, insertSliceIntoEmptyNode, insertSliceIntoRangeSelectionInsideList } from './lists';
|
|
7
|
+
export function insertSliceForLists(_ref) {
|
|
8
|
+
var _slice$content$firstC;
|
|
9
|
+
var tr = _ref.tr,
|
|
10
|
+
slice = _ref.slice,
|
|
11
|
+
schema = _ref.schema;
|
|
12
|
+
var selection = tr.selection,
|
|
13
|
+
_tr$selection = tr.selection,
|
|
14
|
+
$to = _tr$selection.$to,
|
|
15
|
+
$from = _tr$selection.$from;
|
|
16
|
+
var _ref2 = selection,
|
|
17
|
+
$cursor = _ref2.$cursor;
|
|
18
|
+
var panelNode = isSelectionInsidePanel(selection);
|
|
19
|
+
var selectionIsInsideList = $from.blockRange($to, isListNode);
|
|
20
|
+
if (!$cursor && selectionIsInsideList) {
|
|
21
|
+
return insertSliceIntoRangeSelectionInsideList({
|
|
22
|
+
tr: tr,
|
|
23
|
+
slice: slice
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// if inside an empty panel, try and insert content inside it rather than replace it
|
|
28
|
+
if (panelNode && isEmptyNode(panelNode) && $from.node() === $to.node()) {
|
|
29
|
+
return insertSliceInsideOfPanelNodeSelected(panelNode)({
|
|
30
|
+
tr: tr,
|
|
31
|
+
slice: slice
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (!$cursor || selectionIsInsideList) {
|
|
35
|
+
return tr.replaceSelection(slice);
|
|
36
|
+
}
|
|
37
|
+
if (isEmptyNode(tr.doc.resolve($cursor.pos).node())) {
|
|
38
|
+
return insertSliceIntoEmptyNode({
|
|
39
|
+
tr: tr,
|
|
40
|
+
slice: slice
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// When pasting a single list item into an action or decision, we skip the special "insert at node edge"
|
|
45
|
+
// logic so that prosemirror pastes the list's content into the action/decision, rather than
|
|
46
|
+
// pasting a whole list node directly after the action/decision item. (But we still preserve the
|
|
47
|
+
// existing "insert at" node edge" behaviour if dealing with a list with more than one item, so that
|
|
48
|
+
// it still inserts whole list node after the action/decision item).
|
|
49
|
+
var pastingIntoActionOrDecision = Boolean(findParentNodeOfType([schema.nodes.taskList, schema.nodes.decisionList])(selection));
|
|
50
|
+
var oneListItem = slice.content.childCount === 1 && isListNode(slice.content.firstChild) && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.childCount) === 1;
|
|
51
|
+
if (!(pastingIntoActionOrDecision && oneListItem) && isCursorSelectionAtTextStartOrEnd(selection)) {
|
|
52
|
+
return insertSliceAtNodeEdge({
|
|
53
|
+
tr: tr,
|
|
54
|
+
slice: slice
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
tr.replaceSelection(slice);
|
|
58
|
+
}
|
|
59
|
+
export function insertSliceForListsInsideBlockquote(_ref3) {
|
|
60
|
+
var tr = _ref3.tr,
|
|
61
|
+
slice = _ref3.slice;
|
|
62
|
+
safeInsert(slice.content, tr.selection.$to.pos)(tr).scrollIntoView();
|
|
63
|
+
// ProseMirror doesn't give a proper way to tell us where something was inserted.
|
|
64
|
+
// However, we can know "how" it inserted something.
|
|
65
|
+
//
|
|
66
|
+
// So, instead of weird depth calculations, we can use the step produced by the transform.
|
|
67
|
+
// For instance:
|
|
68
|
+
// The `replaceStep.to and replaceStep.from`, tell us the real position
|
|
69
|
+
// where the content will be insert.
|
|
70
|
+
// Then, we can use the `tr.mapping.map` to the updated position after the replace operation
|
|
71
|
+
var replaceStep = tr.steps[0];
|
|
72
|
+
if (!(replaceStep instanceof ReplaceStep)) {
|
|
73
|
+
return tr;
|
|
74
|
+
}
|
|
75
|
+
var nextPosition = tr.mapping.map(replaceStep.to);
|
|
76
|
+
// The findFrom will make search for both: TextSelection and NodeSelections.
|
|
77
|
+
var nextSelection = Selection.findFrom(tr.doc.resolve(Math.min(nextPosition, tr.doc.content.size)), -1);
|
|
78
|
+
if (nextSelection) {
|
|
79
|
+
tr.setSelection(nextSelection);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
2
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import { Transform } from '@atlaskit/editor-prosemirror/transform';
|
|
5
|
+
export function insertSliceIntoEmptyNode(_ref) {
|
|
6
|
+
var tr = _ref.tr,
|
|
7
|
+
slice = _ref.slice;
|
|
8
|
+
tr.replaceSelection(slice);
|
|
9
|
+
}
|
|
10
|
+
export function insertSliceAtNodeEdge(_ref2) {
|
|
11
|
+
var tr = _ref2.tr,
|
|
12
|
+
slice = _ref2.slice;
|
|
13
|
+
var selection = tr.selection;
|
|
14
|
+
var _ref3 = selection,
|
|
15
|
+
$cursor = _ref3.$cursor;
|
|
16
|
+
if (!$cursor) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
var position = !$cursor.nodeBefore ? $cursor.before() : $cursor.after();
|
|
20
|
+
tr.replaceRange(position, position, slice);
|
|
21
|
+
var startSlicePosition = tr.doc.resolve(Math.min(position + slice.content.size - slice.openEnd, tr.doc.content.size));
|
|
22
|
+
var direction = -1;
|
|
23
|
+
tr.setSelection(TextSelection.near(startSlicePosition, direction));
|
|
24
|
+
}
|
|
25
|
+
export function insertSliceIntoRangeSelectionInsideList(_ref4) {
|
|
26
|
+
var tr = _ref4.tr,
|
|
27
|
+
slice = _ref4.slice;
|
|
28
|
+
var _tr$selection = tr.selection,
|
|
29
|
+
$to = _tr$selection.$to,
|
|
30
|
+
$from = _tr$selection.$from,
|
|
31
|
+
to = _tr$selection.to,
|
|
32
|
+
from = _tr$selection.from;
|
|
33
|
+
|
|
34
|
+
// when the selection is inside of the same list item
|
|
35
|
+
// we can use a normal replace
|
|
36
|
+
if ($from.sameParent($to) || $from.depth === $to.depth) {
|
|
37
|
+
return tr.replaceSelection(slice);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// if pasting a list inside another list, ensure no empty list items get added
|
|
41
|
+
var newRange = $from.blockRange($to);
|
|
42
|
+
if (!newRange) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var startPos = from;
|
|
46
|
+
var endPos = $to.nodeAfter ? to : to + 2;
|
|
47
|
+
var newSlice = tr.doc.slice(endPos, newRange.end);
|
|
48
|
+
tr.deleteRange(startPos, newRange.end);
|
|
49
|
+
var mapped = tr.mapping.map(startPos);
|
|
50
|
+
tr.replaceRange(mapped, mapped, slice);
|
|
51
|
+
if (newSlice.size <= 0) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
var newSelection = TextSelection.near(tr.doc.resolve(tr.mapping.map(mapped)), -1);
|
|
55
|
+
// @ts-ignore - [unblock prosemirror bump] assigning to readonly prop
|
|
56
|
+
newSlice.openEnd = newSlice.openStart;
|
|
57
|
+
tr.replaceRange(newSelection.from, newSelection.from, newSlice);
|
|
58
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(newSelection.from), -1));
|
|
59
|
+
}
|
|
60
|
+
export function insertSliceInsideOfPanelNodeSelected(panelNode) {
|
|
61
|
+
return function (_ref5) {
|
|
62
|
+
var tr = _ref5.tr,
|
|
63
|
+
slice = _ref5.slice;
|
|
64
|
+
var selection = tr.selection,
|
|
65
|
+
_tr$selection2 = tr.selection,
|
|
66
|
+
$to = _tr$selection2.$to,
|
|
67
|
+
$from = _tr$selection2.$from;
|
|
68
|
+
var panelPosition = selection.from;
|
|
69
|
+
|
|
70
|
+
// if content of slice isn't valid for a panel node, insert the invalid node and following content after
|
|
71
|
+
if (panelNode && !panelNode.type.validContent(Fragment.from(slice.content))) {
|
|
72
|
+
var _parentNode$firstChil;
|
|
73
|
+
var insertPosition = $to.pos + 1;
|
|
74
|
+
tr.replaceRange(insertPosition, insertPosition, slice);
|
|
75
|
+
// need to delete the empty paragraph at the top of the panel
|
|
76
|
+
var parentNode = tr.doc.resolve($from.before()).node();
|
|
77
|
+
if (parentNode && parentNode.childCount > 1 && ((_parentNode$firstChil = parentNode.firstChild) === null || _parentNode$firstChil === void 0 ? void 0 : _parentNode$firstChil.type.name) === 'paragraph' && isEmptyParagraph(parentNode.firstChild)) {
|
|
78
|
+
var startPosDelete = tr.doc.resolve($from.before()).posAtIndex(0);
|
|
79
|
+
var endPosDelete = tr.doc.resolve($from.before()).posAtIndex(1);
|
|
80
|
+
var SIZE_OF_EMPTY_PARAGRAPH = 2; // {startPos}<p>{startPos + 1}</p>{endPos}
|
|
81
|
+
if (endPosDelete - startPosDelete === SIZE_OF_EMPTY_PARAGRAPH) {
|
|
82
|
+
tr.delete(startPosDelete, endPosDelete);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(insertPosition + slice.content.size - slice.openStart - slice.openEnd + 1)));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
var temporaryDoc = new Transform(tr.doc.type.createAndFill());
|
|
89
|
+
temporaryDoc.replaceRange(0, temporaryDoc.doc.content.size, slice);
|
|
90
|
+
var sliceWithoutInvalidListSurrounding = temporaryDoc.doc.slice(0);
|
|
91
|
+
var newPanel = panelNode.copy(sliceWithoutInvalidListSurrounding.content);
|
|
92
|
+
var panelNodeSelected = selection instanceof NodeSelection ? selection.node : null;
|
|
93
|
+
var replaceFrom = panelNodeSelected ? panelPosition : tr.doc.resolve(panelPosition).start();
|
|
94
|
+
var replaceTo = panelNodeSelected ? panelPosition + panelNodeSelected.nodeSize : replaceFrom;
|
|
95
|
+
tr.replaceRangeWith(replaceFrom, replaceTo, newPanel);
|
|
96
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve($from.pos + newPanel.content.size), -1));
|
|
97
|
+
};
|
|
98
|
+
}
|