@atlaskit/editor-plugin-clipboard 1.0.2 → 1.1.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-clipboard
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#91934](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/91934) [`b76a78c6a199`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b76a78c6a199) - bumped editor-prosemirror version to 4.0.0
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 1.0.3
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#91894](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/91894) [`37320d5b95e8`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/37320d5b95e8) - [ED-22945] Don't copy paste comments on media nodes
|
|
18
|
+
|
|
3
19
|
## 1.0.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -4,14 +4,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.createPlugin = exports.createClipboardSerializer = void 0;
|
|
7
|
+
exports.createPlugin = exports.createClipboardSerializer = exports.ClipboardEventType = void 0;
|
|
8
8
|
Object.defineProperty(exports, "getAnalyticsPayload", {
|
|
9
9
|
enumerable: true,
|
|
10
10
|
get: function get() {
|
|
11
11
|
return _clipboard.getAnalyticsPayload;
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
exports.sendClipboardAnalytics = void 0;
|
|
14
|
+
exports.setLastEventType = exports.sendClipboardAnalytics = void 0;
|
|
15
15
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
16
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
17
17
|
var _clipboard = require("@atlaskit/editor-common/clipboard");
|
|
@@ -21,6 +21,12 @@ var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
|
21
21
|
var _pluginKey = require("../plugin-key");
|
|
22
22
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
23
23
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
24
|
+
var ClipboardEventType = exports.ClipboardEventType = /*#__PURE__*/function (ClipboardEventType) {
|
|
25
|
+
ClipboardEventType["CUT"] = "CUT";
|
|
26
|
+
ClipboardEventType["COPY"] = "COPY";
|
|
27
|
+
return ClipboardEventType;
|
|
28
|
+
}({});
|
|
29
|
+
var lastEventType = null;
|
|
24
30
|
var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
25
31
|
var dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
26
32
|
schema = _ref.schema;
|
|
@@ -41,9 +47,11 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
41
47
|
props: {
|
|
42
48
|
handleDOMEvents: {
|
|
43
49
|
cut: function cut(view) {
|
|
50
|
+
setLastEventType(ClipboardEventType.CUT);
|
|
44
51
|
return sendClipboardAnalytics(view, dispatchAnalyticsEvent, _analytics.ACTION.CUT);
|
|
45
52
|
},
|
|
46
53
|
copy: function copy(view) {
|
|
54
|
+
setLastEventType(ClipboardEventType.COPY);
|
|
47
55
|
return sendClipboardAnalytics(view, dispatchAnalyticsEvent, _analytics.ACTION.COPIED);
|
|
48
56
|
}
|
|
49
57
|
},
|
|
@@ -63,7 +71,7 @@ var createClipboardSerializer = exports.createClipboardSerializer = function cre
|
|
|
63
71
|
var newSerializer = new _model.DOMSerializer(oldSerializer.nodes, oldSerializer.marks);
|
|
64
72
|
var originalSerializeFragment = newSerializer.serializeFragment.bind(newSerializer);
|
|
65
73
|
newSerializer.serializeFragment = function (content) {
|
|
66
|
-
var _content$firstChild;
|
|
74
|
+
var _content$firstChild, _content$firstChild2;
|
|
67
75
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
68
76
|
var target = arguments.length > 2 ? arguments[2] : undefined;
|
|
69
77
|
var editorView = getEditorView();
|
|
@@ -106,7 +114,20 @@ var createClipboardSerializer = exports.createClipboardSerializer = function cre
|
|
|
106
114
|
return originalSerializeFragment(newContent, options, target);
|
|
107
115
|
}
|
|
108
116
|
|
|
109
|
-
//
|
|
117
|
+
// Remove annotations from media nodes when copying to clipboard, only do this for copy operations
|
|
118
|
+
if (lastEventType === ClipboardEventType.COPY && ((_content$firstChild2 = content.firstChild) === null || _content$firstChild2 === void 0 ? void 0 : _content$firstChild2.type.name) === 'media') {
|
|
119
|
+
var _mediaNode$marks;
|
|
120
|
+
var mediaNode = content.firstChild;
|
|
121
|
+
var strippedMediaNode = schema.nodes.media.createChecked(mediaNode.attrs, mediaNode.content, (_mediaNode$marks = mediaNode.marks) === null || _mediaNode$marks === void 0 ? void 0 : _mediaNode$marks.filter(function (mark) {
|
|
122
|
+
return mark.type.name !== 'annotation';
|
|
123
|
+
}));
|
|
124
|
+
var _newContent = _model.Fragment.from(strippedMediaNode);
|
|
125
|
+
// Currently incorrectly typed, see comment above
|
|
126
|
+
//@ts-ignore
|
|
127
|
+
return originalSerializeFragment(_newContent, options, target);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// If we're not copying any rows or media nodes, just run default serializeFragment function.
|
|
110
131
|
// Currently incorrectly typed in @Types. See this GitHub thread: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/57668
|
|
111
132
|
//@ts-ignore
|
|
112
133
|
return originalSerializeFragment(content, options, target);
|
|
@@ -121,4 +142,7 @@ var sendClipboardAnalytics = exports.sendClipboardAnalytics = function sendClipb
|
|
|
121
142
|
// return false so we don't block any other plugins' cut or copy handlers
|
|
122
143
|
// from running just because we are sending an analytics event
|
|
123
144
|
return false;
|
|
145
|
+
};
|
|
146
|
+
var setLastEventType = exports.setLastEventType = function setLastEventType(eventType) {
|
|
147
|
+
return lastEventType = eventType;
|
|
124
148
|
};
|
|
@@ -4,6 +4,12 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
4
4
|
import { DOMSerializer, Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
5
5
|
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
6
6
|
import { clipboardPluginKey } from '../plugin-key';
|
|
7
|
+
export let ClipboardEventType = /*#__PURE__*/function (ClipboardEventType) {
|
|
8
|
+
ClipboardEventType["CUT"] = "CUT";
|
|
9
|
+
ClipboardEventType["COPY"] = "COPY";
|
|
10
|
+
return ClipboardEventType;
|
|
11
|
+
}({});
|
|
12
|
+
let lastEventType = null;
|
|
7
13
|
export const createPlugin = ({
|
|
8
14
|
dispatchAnalyticsEvent,
|
|
9
15
|
schema
|
|
@@ -22,8 +28,14 @@ export const createPlugin = ({
|
|
|
22
28
|
},
|
|
23
29
|
props: {
|
|
24
30
|
handleDOMEvents: {
|
|
25
|
-
cut: view =>
|
|
26
|
-
|
|
31
|
+
cut: view => {
|
|
32
|
+
setLastEventType(ClipboardEventType.CUT);
|
|
33
|
+
return sendClipboardAnalytics(view, dispatchAnalyticsEvent, ACTION.CUT);
|
|
34
|
+
},
|
|
35
|
+
copy: view => {
|
|
36
|
+
setLastEventType(ClipboardEventType.COPY);
|
|
37
|
+
return sendClipboardAnalytics(view, dispatchAnalyticsEvent, ACTION.COPIED);
|
|
38
|
+
}
|
|
27
39
|
},
|
|
28
40
|
clipboardSerializer: createClipboardSerializer(schema, getEditorView)
|
|
29
41
|
}
|
|
@@ -41,7 +53,7 @@ export const createClipboardSerializer = (schema, getEditorView) => {
|
|
|
41
53
|
const newSerializer = new DOMSerializer(oldSerializer.nodes, oldSerializer.marks);
|
|
42
54
|
const originalSerializeFragment = newSerializer.serializeFragment.bind(newSerializer);
|
|
43
55
|
newSerializer.serializeFragment = (content, options = {}, target) => {
|
|
44
|
-
var _content$firstChild;
|
|
56
|
+
var _content$firstChild, _content$firstChild2;
|
|
45
57
|
const editorView = getEditorView();
|
|
46
58
|
const selection = editorView.state.selection;
|
|
47
59
|
|
|
@@ -83,7 +95,18 @@ export const createClipboardSerializer = (schema, getEditorView) => {
|
|
|
83
95
|
return originalSerializeFragment(newContent, options, target);
|
|
84
96
|
}
|
|
85
97
|
|
|
86
|
-
//
|
|
98
|
+
// Remove annotations from media nodes when copying to clipboard, only do this for copy operations
|
|
99
|
+
if (lastEventType === ClipboardEventType.COPY && ((_content$firstChild2 = content.firstChild) === null || _content$firstChild2 === void 0 ? void 0 : _content$firstChild2.type.name) === 'media') {
|
|
100
|
+
var _mediaNode$marks;
|
|
101
|
+
const mediaNode = content.firstChild;
|
|
102
|
+
const strippedMediaNode = schema.nodes.media.createChecked(mediaNode.attrs, mediaNode.content, (_mediaNode$marks = mediaNode.marks) === null || _mediaNode$marks === void 0 ? void 0 : _mediaNode$marks.filter(mark => mark.type.name !== 'annotation'));
|
|
103
|
+
const newContent = Fragment.from(strippedMediaNode);
|
|
104
|
+
// Currently incorrectly typed, see comment above
|
|
105
|
+
//@ts-ignore
|
|
106
|
+
return originalSerializeFragment(newContent, options, target);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// If we're not copying any rows or media nodes, just run default serializeFragment function.
|
|
87
110
|
// Currently incorrectly typed in @Types. See this GitHub thread: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/57668
|
|
88
111
|
//@ts-ignore
|
|
89
112
|
return originalSerializeFragment(content, options, target);
|
|
@@ -99,4 +122,5 @@ export const sendClipboardAnalytics = (view, dispatchAnalyticsEvent, action) =>
|
|
|
99
122
|
// from running just because we are sending an analytics event
|
|
100
123
|
return false;
|
|
101
124
|
};
|
|
125
|
+
export const setLastEventType = eventType => lastEventType = eventType;
|
|
102
126
|
export { getAnalyticsPayload };
|
|
@@ -7,6 +7,12 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
7
7
|
import { DOMSerializer, Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
8
8
|
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
9
9
|
import { clipboardPluginKey } from '../plugin-key';
|
|
10
|
+
export var ClipboardEventType = /*#__PURE__*/function (ClipboardEventType) {
|
|
11
|
+
ClipboardEventType["CUT"] = "CUT";
|
|
12
|
+
ClipboardEventType["COPY"] = "COPY";
|
|
13
|
+
return ClipboardEventType;
|
|
14
|
+
}({});
|
|
15
|
+
var lastEventType = null;
|
|
10
16
|
export var createPlugin = function createPlugin(_ref) {
|
|
11
17
|
var dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
12
18
|
schema = _ref.schema;
|
|
@@ -27,9 +33,11 @@ export var createPlugin = function createPlugin(_ref) {
|
|
|
27
33
|
props: {
|
|
28
34
|
handleDOMEvents: {
|
|
29
35
|
cut: function cut(view) {
|
|
36
|
+
setLastEventType(ClipboardEventType.CUT);
|
|
30
37
|
return sendClipboardAnalytics(view, dispatchAnalyticsEvent, ACTION.CUT);
|
|
31
38
|
},
|
|
32
39
|
copy: function copy(view) {
|
|
40
|
+
setLastEventType(ClipboardEventType.COPY);
|
|
33
41
|
return sendClipboardAnalytics(view, dispatchAnalyticsEvent, ACTION.COPIED);
|
|
34
42
|
}
|
|
35
43
|
},
|
|
@@ -49,7 +57,7 @@ export var createClipboardSerializer = function createClipboardSerializer(schema
|
|
|
49
57
|
var newSerializer = new DOMSerializer(oldSerializer.nodes, oldSerializer.marks);
|
|
50
58
|
var originalSerializeFragment = newSerializer.serializeFragment.bind(newSerializer);
|
|
51
59
|
newSerializer.serializeFragment = function (content) {
|
|
52
|
-
var _content$firstChild;
|
|
60
|
+
var _content$firstChild, _content$firstChild2;
|
|
53
61
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
54
62
|
var target = arguments.length > 2 ? arguments[2] : undefined;
|
|
55
63
|
var editorView = getEditorView();
|
|
@@ -92,7 +100,20 @@ export var createClipboardSerializer = function createClipboardSerializer(schema
|
|
|
92
100
|
return originalSerializeFragment(newContent, options, target);
|
|
93
101
|
}
|
|
94
102
|
|
|
95
|
-
//
|
|
103
|
+
// Remove annotations from media nodes when copying to clipboard, only do this for copy operations
|
|
104
|
+
if (lastEventType === ClipboardEventType.COPY && ((_content$firstChild2 = content.firstChild) === null || _content$firstChild2 === void 0 ? void 0 : _content$firstChild2.type.name) === 'media') {
|
|
105
|
+
var _mediaNode$marks;
|
|
106
|
+
var mediaNode = content.firstChild;
|
|
107
|
+
var strippedMediaNode = schema.nodes.media.createChecked(mediaNode.attrs, mediaNode.content, (_mediaNode$marks = mediaNode.marks) === null || _mediaNode$marks === void 0 ? void 0 : _mediaNode$marks.filter(function (mark) {
|
|
108
|
+
return mark.type.name !== 'annotation';
|
|
109
|
+
}));
|
|
110
|
+
var _newContent = Fragment.from(strippedMediaNode);
|
|
111
|
+
// Currently incorrectly typed, see comment above
|
|
112
|
+
//@ts-ignore
|
|
113
|
+
return originalSerializeFragment(_newContent, options, target);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// If we're not copying any rows or media nodes, just run default serializeFragment function.
|
|
96
117
|
// Currently incorrectly typed in @Types. See this GitHub thread: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/57668
|
|
97
118
|
//@ts-ignore
|
|
98
119
|
return originalSerializeFragment(content, options, target);
|
|
@@ -108,4 +129,7 @@ export var sendClipboardAnalytics = function sendClipboardAnalytics(view, dispat
|
|
|
108
129
|
// from running just because we are sending an analytics event
|
|
109
130
|
return false;
|
|
110
131
|
};
|
|
132
|
+
export var setLastEventType = function setLastEventType(eventType) {
|
|
133
|
+
return lastEventType = eventType;
|
|
134
|
+
};
|
|
111
135
|
export { getAnalyticsPayload };
|
|
@@ -6,6 +6,10 @@ import type { PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
|
6
6
|
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
7
7
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
8
8
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
9
|
+
export declare enum ClipboardEventType {
|
|
10
|
+
CUT = "CUT",
|
|
11
|
+
COPY = "COPY"
|
|
12
|
+
}
|
|
9
13
|
export declare const createPlugin: ({ dispatchAnalyticsEvent, schema, }: PMPluginFactoryParams) => SafePlugin<any>;
|
|
10
14
|
/**
|
|
11
15
|
* Overrides Prosemirror's default clipboardSerializer, in order to fix table row copy/paste bug raised in ED-13003.
|
|
@@ -15,4 +19,5 @@ export declare const createPlugin: ({ dispatchAnalyticsEvent, schema, }: PMPlugi
|
|
|
15
19
|
*/
|
|
16
20
|
export declare const createClipboardSerializer: (schema: Schema, getEditorView: () => EditorView) => DOMSerializer;
|
|
17
21
|
export declare const sendClipboardAnalytics: (view: EditorView, dispatchAnalyticsEvent: DispatchAnalyticsEvent, action: ACTION.CUT | ACTION.COPIED) => boolean;
|
|
22
|
+
export declare const setLastEventType: (eventType: ClipboardEventType) => ClipboardEventType;
|
|
18
23
|
export { getAnalyticsPayload };
|
|
@@ -6,6 +6,10 @@ import type { PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
|
6
6
|
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
7
7
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
8
8
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
9
|
+
export declare enum ClipboardEventType {
|
|
10
|
+
CUT = "CUT",
|
|
11
|
+
COPY = "COPY"
|
|
12
|
+
}
|
|
9
13
|
export declare const createPlugin: ({ dispatchAnalyticsEvent, schema, }: PMPluginFactoryParams) => SafePlugin<any>;
|
|
10
14
|
/**
|
|
11
15
|
* Overrides Prosemirror's default clipboardSerializer, in order to fix table row copy/paste bug raised in ED-13003.
|
|
@@ -15,4 +19,5 @@ export declare const createPlugin: ({ dispatchAnalyticsEvent, schema, }: PMPlugi
|
|
|
15
19
|
*/
|
|
16
20
|
export declare const createClipboardSerializer: (schema: Schema, getEditorView: () => EditorView) => DOMSerializer;
|
|
17
21
|
export declare const sendClipboardAnalytics: (view: EditorView, dispatchAnalyticsEvent: DispatchAnalyticsEvent, action: ACTION.CUT | ACTION.COPIED) => boolean;
|
|
22
|
+
export declare const setLastEventType: (eventType: ClipboardEventType) => ClipboardEventType;
|
|
18
23
|
export { getAnalyticsPayload };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-clipboard",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Clipboard plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
".": "./src/index.ts"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@atlaskit/editor-common": "^78.
|
|
36
|
-
"@atlaskit/editor-prosemirror": "
|
|
35
|
+
"@atlaskit/editor-common": "^78.31.0",
|
|
36
|
+
"@atlaskit/editor-prosemirror": "4.0.0",
|
|
37
37
|
"@babel/runtime": "^7.0.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|