@atlaskit/editor-core 187.43.12 → 187.43.13
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 +7 -0
- package/dist/cjs/labs/next/presets/default.js +2 -1
- package/dist/cjs/labs/next/presets/universal.js +1 -1
- package/dist/cjs/plugins/clipboard/pm-plugins/main.js +13 -54
- package/dist/cjs/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +1 -1
- package/dist/cjs/plugins/floating-toolbar/index.js +1 -2
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/plugins/selection/utils.js +29 -80
- package/dist/cjs/utils/clipboard.js +19 -127
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/labs/next/presets/default.js +2 -1
- package/dist/es2019/labs/next/presets/universal.js +2 -2
- package/dist/es2019/plugins/clipboard/pm-plugins/main.js +3 -53
- package/dist/es2019/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +1 -1
- package/dist/es2019/plugins/floating-toolbar/index.js +1 -2
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/plugins/selection/utils.js +3 -74
- package/dist/es2019/utils/clipboard.js +1 -53
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/labs/next/presets/default.js +2 -1
- package/dist/esm/labs/next/presets/universal.js +2 -2
- package/dist/esm/plugins/clipboard/pm-plugins/main.js +3 -49
- package/dist/esm/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +1 -1
- package/dist/esm/plugins/floating-toolbar/index.js +1 -2
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/plugins/selection/utils.js +3 -72
- package/dist/esm/utils/clipboard.js +1 -119
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/labs/next/presets/default.d.ts +68 -4
- package/dist/types/plugins/clipboard/pm-plugins/main.d.ts +2 -3
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/plugins/selection/utils.d.ts +2 -5
- package/dist/types/utils/clipboard.d.ts +1 -3
- package/dist/types-ts4.5/labs/next/presets/default.d.ts +86 -0
- package/dist/types-ts4.5/plugins/clipboard/pm-plugins/main.d.ts +2 -3
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/selection/utils.d.ts +2 -5
- package/dist/types-ts4.5/utils/clipboard.d.ts +1 -3
- package/package.json +7 -7
- package/dist/cjs/plugins/copy-button/commands.js +0 -171
- package/dist/cjs/plugins/copy-button/index.js +0 -23
- package/dist/cjs/plugins/copy-button/pm-plugins/main.js +0 -104
- package/dist/cjs/plugins/copy-button/pm-plugins/plugin-key.js +0 -9
- package/dist/cjs/plugins/copy-button/toolbar.js +0 -99
- package/dist/cjs/plugins/copy-button/utils.js +0 -22
- package/dist/es2019/plugins/copy-button/commands.js +0 -157
- package/dist/es2019/plugins/copy-button/index.js +0 -11
- package/dist/es2019/plugins/copy-button/pm-plugins/main.js +0 -97
- package/dist/es2019/plugins/copy-button/pm-plugins/plugin-key.js +0 -2
- package/dist/es2019/plugins/copy-button/toolbar.js +0 -82
- package/dist/es2019/plugins/copy-button/utils.js +0 -15
- package/dist/esm/plugins/copy-button/commands.js +0 -159
- package/dist/esm/plugins/copy-button/index.js +0 -15
- package/dist/esm/plugins/copy-button/pm-plugins/main.js +0 -96
- package/dist/esm/plugins/copy-button/pm-plugins/plugin-key.js +0 -2
- package/dist/esm/plugins/copy-button/toolbar.js +0 -89
- package/dist/esm/plugins/copy-button/utils.js +0 -14
- package/dist/types/plugins/copy-button/commands.d.ts +0 -9
- package/dist/types/plugins/copy-button/index.d.ts +0 -3
- package/dist/types/plugins/copy-button/pm-plugins/main.d.ts +0 -4
- package/dist/types/plugins/copy-button/pm-plugins/plugin-key.d.ts +0 -2
- package/dist/types/plugins/copy-button/toolbar.d.ts +0 -13
- package/dist/types/plugins/copy-button/utils.d.ts +0 -8
- package/dist/types-ts4.5/plugins/copy-button/commands.d.ts +0 -9
- package/dist/types-ts4.5/plugins/copy-button/index.d.ts +0 -3
- package/dist/types-ts4.5/plugins/copy-button/pm-plugins/main.d.ts +0 -4
- package/dist/types-ts4.5/plugins/copy-button/pm-plugins/plugin-key.d.ts +0 -2
- package/dist/types-ts4.5/plugins/copy-button/toolbar.d.ts +0 -13
- package/dist/types-ts4.5/plugins/copy-button/utils.d.ts +0 -8
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _main = _interopRequireDefault(require("./pm-plugins/main"));
|
|
9
|
-
var copyButtonPlugin = function copyButtonPlugin() {
|
|
10
|
-
return {
|
|
11
|
-
name: 'copyButton',
|
|
12
|
-
pmPlugins: function pmPlugins() {
|
|
13
|
-
return [{
|
|
14
|
-
name: 'copyButton',
|
|
15
|
-
plugin: function plugin() {
|
|
16
|
-
return (0, _main.default)();
|
|
17
|
-
}
|
|
18
|
-
}];
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
var _default = copyButtonPlugin;
|
|
23
|
-
exports.default = _default;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.copyButtonPlugin = copyButtonPlugin;
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
9
|
-
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
10
|
-
var _pluginKey = require("./plugin-key");
|
|
11
|
-
function getMarkSelectionDecorationStartAndEnd(_ref) {
|
|
12
|
-
var markType = _ref.markType,
|
|
13
|
-
transaction = _ref.transaction;
|
|
14
|
-
var headResolvedPos = transaction.selection.$head;
|
|
15
|
-
var textNodeIndex = transaction.selection.$head.index();
|
|
16
|
-
var textNode = headResolvedPos.parent.maybeChild(textNodeIndex);
|
|
17
|
-
var textNodeOffset = 0;
|
|
18
|
-
headResolvedPos.parent.forEach(function (_node, nodeOffset, index) {
|
|
19
|
-
if (index === textNodeIndex) {
|
|
20
|
-
textNodeOffset = nodeOffset;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
var start = headResolvedPos.start(headResolvedPos.depth) + textNodeOffset;
|
|
24
|
-
var end = start + textNode.text.length;
|
|
25
|
-
return {
|
|
26
|
-
start: start,
|
|
27
|
-
end: end,
|
|
28
|
-
markType: markType
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function copyButtonPlugin() {
|
|
32
|
-
return new _safePlugin.SafePlugin({
|
|
33
|
-
key: _pluginKey.copyButtonPluginKey,
|
|
34
|
-
state: {
|
|
35
|
-
init: function init() {
|
|
36
|
-
return {
|
|
37
|
-
copied: false,
|
|
38
|
-
markSelection: undefined
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
apply: function apply(tr, currentPluginState) {
|
|
42
|
-
var meta = tr.getMeta(_pluginKey.copyButtonPluginKey);
|
|
43
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.copied) !== undefined) {
|
|
44
|
-
return {
|
|
45
|
-
copied: meta.copied,
|
|
46
|
-
markSelection: undefined
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
if (meta !== null && meta !== void 0 && meta.showSelection) {
|
|
50
|
-
return {
|
|
51
|
-
copied: currentPluginState.copied,
|
|
52
|
-
markSelection: getMarkSelectionDecorationStartAndEnd({
|
|
53
|
-
markType: meta.markType,
|
|
54
|
-
transaction: tr
|
|
55
|
-
})
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
if (meta !== null && meta !== void 0 && meta.removeSelection) {
|
|
59
|
-
return {
|
|
60
|
-
copied: currentPluginState.copied,
|
|
61
|
-
markSelection: undefined
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
if (currentPluginState.markSelection) {
|
|
65
|
-
return {
|
|
66
|
-
copied: currentPluginState.copied,
|
|
67
|
-
markSelection: getMarkSelectionDecorationStartAndEnd({
|
|
68
|
-
markType: currentPluginState.markSelection.markType,
|
|
69
|
-
transaction: tr
|
|
70
|
-
})
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return currentPluginState;
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
props: {
|
|
77
|
-
decorations: function decorations(_state) {
|
|
78
|
-
// Showing visual hints for the hyperlink copy button has been disabled
|
|
79
|
-
// due to an issue where invalid hyperlink marks cause the floating toolbar
|
|
80
|
-
// to jump around when the copy button is hovered.
|
|
81
|
-
// See the following bug for details -- once that is resolved -- the visual
|
|
82
|
-
// hints can be re enabled.
|
|
83
|
-
// https://product-fabric.atlassian.net/browse/DTR-722
|
|
84
|
-
|
|
85
|
-
// const copyButtonPluginState = copyButtonPluginKey.getState(
|
|
86
|
-
// state,
|
|
87
|
-
// ) as CopyButtonPluginState;
|
|
88
|
-
// if (copyButtonPluginState.markSelection) {
|
|
89
|
-
// const { start, end } = copyButtonPluginState.markSelection;
|
|
90
|
-
|
|
91
|
-
// return DecorationSet.create(state.doc, [
|
|
92
|
-
// Decoration.inline(start, end, {
|
|
93
|
-
// class: 'ProseMirror-fake-text-selection',
|
|
94
|
-
// }),
|
|
95
|
-
// ]);
|
|
96
|
-
// }
|
|
97
|
-
|
|
98
|
-
return _view.DecorationSet.empty;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
var _default = copyButtonPlugin;
|
|
104
|
-
exports.default = _default;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.copyButtonPluginKey = void 0;
|
|
7
|
-
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
-
var copyButtonPluginKey = new _state.PluginKey('copyButtonPlugin');
|
|
9
|
-
exports.copyButtonPluginKey = copyButtonPluginKey;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.getCopyButtonConfig = getCopyButtonConfig;
|
|
8
|
-
exports.processCopyButtonItems = processCopyButtonItems;
|
|
9
|
-
exports.showCopyButton = void 0;
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
var _copy = _interopRequireDefault(require("@atlaskit/icon/glyph/copy"));
|
|
12
|
-
var _messages = _interopRequireDefault(require("../../messages"));
|
|
13
|
-
var _commands = require("./commands");
|
|
14
|
-
var _pluginKey = require("./pm-plugins/plugin-key");
|
|
15
|
-
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; }
|
|
16
|
-
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; }
|
|
17
|
-
function isSeparator(item) {
|
|
18
|
-
return (item === null || item === void 0 ? void 0 : item.type) === 'separator';
|
|
19
|
-
}
|
|
20
|
-
function isNodeOptions(options) {
|
|
21
|
-
return 'nodeType' in options && options.nodeType !== undefined;
|
|
22
|
-
}
|
|
23
|
-
function getCopyButtonConfig(options, hoverDecoration) {
|
|
24
|
-
var state = options.state,
|
|
25
|
-
formatMessage = options.formatMessage,
|
|
26
|
-
onMouseEnter = options.onMouseEnter,
|
|
27
|
-
onMouseLeave = options.onMouseLeave,
|
|
28
|
-
onFocus = options.onFocus,
|
|
29
|
-
onBlur = options.onBlur;
|
|
30
|
-
var copyButtonState = _pluginKey.copyButtonPluginKey.getState(state);
|
|
31
|
-
var buttonActionHandlers;
|
|
32
|
-
if (isNodeOptions(options)) {
|
|
33
|
-
buttonActionHandlers = {
|
|
34
|
-
onClick: (0, _commands.createToolbarCopyCommandForNode)(options.nodeType),
|
|
35
|
-
// Note for future changes: these two handlers should perform
|
|
36
|
-
// the same action.
|
|
37
|
-
onMouseEnter: onMouseEnter || (hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(options.nodeType, true, 'ak-editor-selected-node')),
|
|
38
|
-
onFocus: onFocus || (hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(options.nodeType, true, 'ak-editor-selected-node')),
|
|
39
|
-
// Note for future changes: these two handlers should perform
|
|
40
|
-
// the same action.
|
|
41
|
-
onMouseLeave: (0, _commands.resetCopiedState)(options.nodeType, hoverDecoration, onMouseLeave),
|
|
42
|
-
onBlur: (0, _commands.resetCopiedState)(options.nodeType, hoverDecoration, onBlur)
|
|
43
|
-
};
|
|
44
|
-
} else {
|
|
45
|
-
buttonActionHandlers = {
|
|
46
|
-
onClick: (0, _commands.createToolbarCopyCommandForMark)(options.markType),
|
|
47
|
-
onMouseEnter: (0, _commands.getProvideMarkVisualFeedbackForCopyButtonCommand)(options.markType),
|
|
48
|
-
onFocus: (0, _commands.getProvideMarkVisualFeedbackForCopyButtonCommand)(options.markType),
|
|
49
|
-
onMouseLeave: _commands.removeMarkVisualFeedbackForCopyButtonCommand,
|
|
50
|
-
onBlur: _commands.removeMarkVisualFeedbackForCopyButtonCommand
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return _objectSpread(_objectSpread({
|
|
54
|
-
id: 'editor.floatingToolbar.copy',
|
|
55
|
-
type: 'button',
|
|
56
|
-
appearance: 'subtle',
|
|
57
|
-
icon: _copy.default,
|
|
58
|
-
title: formatMessage(copyButtonState !== null && copyButtonState !== void 0 && copyButtonState.copied ? _messages.default.copiedToClipboard : _messages.default.copyToClipboard)
|
|
59
|
-
}, buttonActionHandlers), {}, {
|
|
60
|
-
hideTooltipOnClick: false,
|
|
61
|
-
tabIndex: null
|
|
62
|
-
// TODO select and delete styling needs to be removed when keyboard cursor moves away
|
|
63
|
-
// problem already exist with delete as well
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
var showCopyButton = function showCopyButton(state) {
|
|
68
|
-
return state &&
|
|
69
|
-
// Check if the Copy button plugin is enabled
|
|
70
|
-
// @ts-ignore copyButtonPluginKey.key
|
|
71
|
-
state.plugins.find(function (p) {
|
|
72
|
-
return p.key === _pluginKey.copyButtonPluginKey.key;
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Process floatingToolbar items for copyButton
|
|
78
|
-
*
|
|
79
|
-
* If copy button plugin not enabled, remove copy button item from toolbar items
|
|
80
|
-
* else process copy button to standard floatingtoobarbutton
|
|
81
|
-
*/
|
|
82
|
-
exports.showCopyButton = showCopyButton;
|
|
83
|
-
function processCopyButtonItems(state) {
|
|
84
|
-
return function (items, hoverDecoration) {
|
|
85
|
-
return items.flatMap(function (item) {
|
|
86
|
-
switch (item.type) {
|
|
87
|
-
case 'copy-button':
|
|
88
|
-
if (item !== null && item !== void 0 && item.hidden || !showCopyButton(state)) {
|
|
89
|
-
return [];
|
|
90
|
-
}
|
|
91
|
-
return item === null || item === void 0 ? void 0 : item.items.map(function (copyButtonItem) {
|
|
92
|
-
return isSeparator(copyButtonItem) ? copyButtonItem : getCopyButtonConfig(copyButtonItem, hoverDecoration);
|
|
93
|
-
});
|
|
94
|
-
default:
|
|
95
|
-
return [item];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getSelectedNodeOrNodeParentByNodeType = getSelectedNodeOrNodeParentByNodeType;
|
|
7
|
-
exports.toDOM = void 0;
|
|
8
|
-
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
9
|
-
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
10
|
-
function getSelectedNodeOrNodeParentByNodeType(_ref) {
|
|
11
|
-
var nodeType = _ref.nodeType,
|
|
12
|
-
selection = _ref.selection;
|
|
13
|
-
var node = (0, _utils.findSelectedNodeOfType)(nodeType)(selection);
|
|
14
|
-
if (!node) {
|
|
15
|
-
node = (0, _utils.findParentNodeOfType)(nodeType)(selection);
|
|
16
|
-
}
|
|
17
|
-
return node;
|
|
18
|
-
}
|
|
19
|
-
var toDOM = function toDOM(node, schema) {
|
|
20
|
-
return _model.DOMSerializer.fromSchema(schema).serializeNode(node);
|
|
21
|
-
};
|
|
22
|
-
exports.toDOM = toDOM;
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { copyButtonPluginKey } from './pm-plugins/plugin-key';
|
|
2
|
-
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { copyHTMLToClipboard, copyHTMLToClipboardPolyfill } from '../../utils/clipboard';
|
|
4
|
-
import { getSelectedNodeOrNodeParentByNodeType, toDOM } from './utils';
|
|
5
|
-
import { addAnalytics, ACTION, INPUT_METHOD } from '../analytics';
|
|
6
|
-
import { getAnalyticsPayload } from '../clipboard/pm-plugins/main';
|
|
7
|
-
import { browser } from '@atlaskit/editor-common/utils';
|
|
8
|
-
export function createToolbarCopyCommandForMark(markType) {
|
|
9
|
-
function command(state, dispatch) {
|
|
10
|
-
const textNode = state.tr.selection.$head.parent.maybeChild(state.tr.selection.$head.index());
|
|
11
|
-
if (!textNode) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
if (dispatch) {
|
|
15
|
-
// As calling copyHTMLToClipboard causes side effects -- we only run this when
|
|
16
|
-
// dispatch is provided -- as otherwise the consumer is only testing to see if
|
|
17
|
-
// the action is availble.
|
|
18
|
-
const domNode = toDOM(textNode, state.schema);
|
|
19
|
-
if (domNode) {
|
|
20
|
-
const div = document.createElement('div');
|
|
21
|
-
const p = document.createElement('p');
|
|
22
|
-
div.appendChild(p);
|
|
23
|
-
p.appendChild(domNode);
|
|
24
|
-
// The "1 1" refers to the start and end depth of the slice
|
|
25
|
-
// since we're copying the text inside a paragraph, it will always be 1 1
|
|
26
|
-
// https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
|
|
27
|
-
div.firstChild.setAttribute('data-pm-slice', '1 1 []');
|
|
28
|
-
|
|
29
|
-
// If we're copying a hyperlink, we'd copy the url as the fallback plain text
|
|
30
|
-
const linkUrl = domNode.getAttribute('href');
|
|
31
|
-
copyHTMLToClipboard(div, markType.name === 'link' && linkUrl ? linkUrl : undefined);
|
|
32
|
-
}
|
|
33
|
-
const copyToClipboardTr = state.tr;
|
|
34
|
-
copyToClipboardTr.setMeta(copyButtonPluginKey, {
|
|
35
|
-
copied: true
|
|
36
|
-
});
|
|
37
|
-
const analyticsPayload = getAnalyticsPayload(state, ACTION.COPIED);
|
|
38
|
-
if (analyticsPayload) {
|
|
39
|
-
analyticsPayload.attributes.inputMethod = INPUT_METHOD.FLOATING_TB;
|
|
40
|
-
analyticsPayload.attributes.markType = markType.name;
|
|
41
|
-
addAnalytics(state, copyToClipboardTr, analyticsPayload);
|
|
42
|
-
}
|
|
43
|
-
dispatch(copyToClipboardTr);
|
|
44
|
-
}
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
return command;
|
|
48
|
-
}
|
|
49
|
-
export function getProvideMarkVisualFeedbackForCopyButtonCommand(markType) {
|
|
50
|
-
function provideMarkVisualFeedbackForCopyButtonCommand(state, dispatch) {
|
|
51
|
-
const tr = state.tr;
|
|
52
|
-
tr.setMeta(copyButtonPluginKey, {
|
|
53
|
-
showSelection: true,
|
|
54
|
-
markType
|
|
55
|
-
});
|
|
56
|
-
if (dispatch) {
|
|
57
|
-
dispatch(tr);
|
|
58
|
-
}
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
return provideMarkVisualFeedbackForCopyButtonCommand;
|
|
62
|
-
}
|
|
63
|
-
export function removeMarkVisualFeedbackForCopyButtonCommand(state, dispatch) {
|
|
64
|
-
const tr = state.tr;
|
|
65
|
-
tr.setMeta(copyButtonPluginKey, {
|
|
66
|
-
removeSelection: true
|
|
67
|
-
});
|
|
68
|
-
const copyButtonState = copyButtonPluginKey.getState(state);
|
|
69
|
-
if (copyButtonState !== null && copyButtonState !== void 0 && copyButtonState.copied) {
|
|
70
|
-
tr.setMeta(copyButtonPluginKey, {
|
|
71
|
-
copied: false
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
if (dispatch) {
|
|
75
|
-
dispatch(tr);
|
|
76
|
-
}
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
export const createToolbarCopyCommandForNode = nodeType => (state, dispatch) => {
|
|
80
|
-
const {
|
|
81
|
-
tr,
|
|
82
|
-
schema
|
|
83
|
-
} = state;
|
|
84
|
-
|
|
85
|
-
// This command should only be triggered by the Copy button in the floating toolbar
|
|
86
|
-
// which is only visible when selection is inside the target node
|
|
87
|
-
let contentNodeWithPos = getSelectedNodeOrNodeParentByNodeType({
|
|
88
|
-
nodeType,
|
|
89
|
-
selection: tr.selection
|
|
90
|
-
});
|
|
91
|
-
if (!contentNodeWithPos) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
const copyToClipboardTr = tr;
|
|
95
|
-
copyToClipboardTr.setMeta(copyButtonPluginKey, {
|
|
96
|
-
copied: true
|
|
97
|
-
});
|
|
98
|
-
const analyticsPayload = getAnalyticsPayload(state, ACTION.COPIED);
|
|
99
|
-
if (analyticsPayload) {
|
|
100
|
-
analyticsPayload.attributes.inputMethod = INPUT_METHOD.FLOATING_TB;
|
|
101
|
-
analyticsPayload.attributes.nodeType = contentNodeWithPos.node.type.name;
|
|
102
|
-
addAnalytics(state, copyToClipboardTr, analyticsPayload);
|
|
103
|
-
}
|
|
104
|
-
if (dispatch) {
|
|
105
|
-
// As calling copyHTMLToClipboard causes side effects -- we only run this when
|
|
106
|
-
// dispatch is provided -- as otherwise the consumer is only testing to see if
|
|
107
|
-
// the action is availble.
|
|
108
|
-
const domNode = toDOM(contentNodeWithPos.node, schema);
|
|
109
|
-
if (domNode) {
|
|
110
|
-
const div = document.createElement('div');
|
|
111
|
-
div.appendChild(domNode);
|
|
112
|
-
|
|
113
|
-
// if copying inline content
|
|
114
|
-
if (contentNodeWithPos.node.type.inlineContent) {
|
|
115
|
-
// The "1 1" refers to the start and end depth of the slice
|
|
116
|
-
// since we're copying the text inside a paragraph, it will always be 1 1
|
|
117
|
-
// https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
|
|
118
|
-
div.firstChild.setAttribute('data-pm-slice', '1 1 []');
|
|
119
|
-
} else {
|
|
120
|
-
// The "0 0" refers to the start and end depth of the slice
|
|
121
|
-
// since we're copying the block node only, it will always be 0 0
|
|
122
|
-
// https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
|
|
123
|
-
div.firstChild.setAttribute('data-pm-slice', '0 0 []');
|
|
124
|
-
}
|
|
125
|
-
// ED-17083 safari seems have bugs for extension copy because exntension do not have a child text(innerText) and it will not recognized as html in clipboard, this could be merge into one if this extension fixed children issue or safari fix the copy bug
|
|
126
|
-
// MEX-2528 safari has a bug related to the mediaSingle node with border or link. The image tag within the clipboard is not recognized as HTML when using the ClipboardItem API. To address this, we have to switch to ClipboardPolyfill
|
|
127
|
-
if (browser.safari && state.selection instanceof NodeSelection && (state.selection.node.type === state.schema.nodes.extension || state.selection.node.type === state.schema.nodes.mediaSingle)) {
|
|
128
|
-
copyHTMLToClipboardPolyfill(div);
|
|
129
|
-
} else {
|
|
130
|
-
copyHTMLToClipboard(div);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
copyToClipboardTr.setMeta('scrollIntoView', false);
|
|
134
|
-
dispatch(copyToClipboardTr);
|
|
135
|
-
}
|
|
136
|
-
return true;
|
|
137
|
-
};
|
|
138
|
-
export const resetCopiedState = (nodeType, hoverDecoration, onMouseLeave) => (state, dispatch) => {
|
|
139
|
-
let customTr = state.tr;
|
|
140
|
-
|
|
141
|
-
// Avoid multipe dispatch
|
|
142
|
-
// https://product-fabric.atlassian.net/wiki/spaces/E/pages/2241659456/All+about+dispatch+and+why+there+shouldn+t+be+multiple#How-do-I-avoid-them%3F
|
|
143
|
-
const customDispatch = tr => {
|
|
144
|
-
customTr = tr;
|
|
145
|
-
};
|
|
146
|
-
onMouseLeave ? onMouseLeave(state, customDispatch) : hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, false)(state, customDispatch);
|
|
147
|
-
const copyButtonState = copyButtonPluginKey.getState(state);
|
|
148
|
-
if (copyButtonState !== null && copyButtonState !== void 0 && copyButtonState.copied) {
|
|
149
|
-
customTr.setMeta(copyButtonPluginKey, {
|
|
150
|
-
copied: false
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
if (dispatch) {
|
|
154
|
-
dispatch(customTr);
|
|
155
|
-
}
|
|
156
|
-
return true;
|
|
157
|
-
};
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
-
import { copyButtonPluginKey } from './plugin-key';
|
|
4
|
-
function getMarkSelectionDecorationStartAndEnd({
|
|
5
|
-
markType,
|
|
6
|
-
transaction
|
|
7
|
-
}) {
|
|
8
|
-
const headResolvedPos = transaction.selection.$head;
|
|
9
|
-
const textNodeIndex = transaction.selection.$head.index();
|
|
10
|
-
const textNode = headResolvedPos.parent.maybeChild(textNodeIndex);
|
|
11
|
-
let textNodeOffset = 0;
|
|
12
|
-
headResolvedPos.parent.forEach((_node, nodeOffset, index) => {
|
|
13
|
-
if (index === textNodeIndex) {
|
|
14
|
-
textNodeOffset = nodeOffset;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
const start = headResolvedPos.start(headResolvedPos.depth) + textNodeOffset;
|
|
18
|
-
const end = start + textNode.text.length;
|
|
19
|
-
return {
|
|
20
|
-
start,
|
|
21
|
-
end,
|
|
22
|
-
markType
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
export function copyButtonPlugin() {
|
|
26
|
-
return new SafePlugin({
|
|
27
|
-
key: copyButtonPluginKey,
|
|
28
|
-
state: {
|
|
29
|
-
init() {
|
|
30
|
-
return {
|
|
31
|
-
copied: false,
|
|
32
|
-
markSelection: undefined
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
apply(tr, currentPluginState) {
|
|
36
|
-
const meta = tr.getMeta(copyButtonPluginKey);
|
|
37
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.copied) !== undefined) {
|
|
38
|
-
return {
|
|
39
|
-
copied: meta.copied,
|
|
40
|
-
markSelection: undefined
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
if (meta !== null && meta !== void 0 && meta.showSelection) {
|
|
44
|
-
return {
|
|
45
|
-
copied: currentPluginState.copied,
|
|
46
|
-
markSelection: getMarkSelectionDecorationStartAndEnd({
|
|
47
|
-
markType: meta.markType,
|
|
48
|
-
transaction: tr
|
|
49
|
-
})
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
if (meta !== null && meta !== void 0 && meta.removeSelection) {
|
|
53
|
-
return {
|
|
54
|
-
copied: currentPluginState.copied,
|
|
55
|
-
markSelection: undefined
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
if (currentPluginState.markSelection) {
|
|
59
|
-
return {
|
|
60
|
-
copied: currentPluginState.copied,
|
|
61
|
-
markSelection: getMarkSelectionDecorationStartAndEnd({
|
|
62
|
-
markType: currentPluginState.markSelection.markType,
|
|
63
|
-
transaction: tr
|
|
64
|
-
})
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return currentPluginState;
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
props: {
|
|
71
|
-
decorations(_state) {
|
|
72
|
-
// Showing visual hints for the hyperlink copy button has been disabled
|
|
73
|
-
// due to an issue where invalid hyperlink marks cause the floating toolbar
|
|
74
|
-
// to jump around when the copy button is hovered.
|
|
75
|
-
// See the following bug for details -- once that is resolved -- the visual
|
|
76
|
-
// hints can be re enabled.
|
|
77
|
-
// https://product-fabric.atlassian.net/browse/DTR-722
|
|
78
|
-
|
|
79
|
-
// const copyButtonPluginState = copyButtonPluginKey.getState(
|
|
80
|
-
// state,
|
|
81
|
-
// ) as CopyButtonPluginState;
|
|
82
|
-
// if (copyButtonPluginState.markSelection) {
|
|
83
|
-
// const { start, end } = copyButtonPluginState.markSelection;
|
|
84
|
-
|
|
85
|
-
// return DecorationSet.create(state.doc, [
|
|
86
|
-
// Decoration.inline(start, end, {
|
|
87
|
-
// class: 'ProseMirror-fake-text-selection',
|
|
88
|
-
// }),
|
|
89
|
-
// ]);
|
|
90
|
-
// }
|
|
91
|
-
|
|
92
|
-
return DecorationSet.empty;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
export default copyButtonPlugin;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import CopyIcon from '@atlaskit/icon/glyph/copy';
|
|
2
|
-
import commonMessages from '../../messages';
|
|
3
|
-
import { createToolbarCopyCommandForNode, createToolbarCopyCommandForMark, resetCopiedState, getProvideMarkVisualFeedbackForCopyButtonCommand, removeMarkVisualFeedbackForCopyButtonCommand } from './commands';
|
|
4
|
-
import { copyButtonPluginKey } from './pm-plugins/plugin-key';
|
|
5
|
-
function isSeparator(item) {
|
|
6
|
-
return (item === null || item === void 0 ? void 0 : item.type) === 'separator';
|
|
7
|
-
}
|
|
8
|
-
function isNodeOptions(options) {
|
|
9
|
-
return 'nodeType' in options && options.nodeType !== undefined;
|
|
10
|
-
}
|
|
11
|
-
export function getCopyButtonConfig(options, hoverDecoration) {
|
|
12
|
-
const {
|
|
13
|
-
state,
|
|
14
|
-
formatMessage,
|
|
15
|
-
onMouseEnter,
|
|
16
|
-
onMouseLeave,
|
|
17
|
-
onFocus,
|
|
18
|
-
onBlur
|
|
19
|
-
} = options;
|
|
20
|
-
const copyButtonState = copyButtonPluginKey.getState(state);
|
|
21
|
-
let buttonActionHandlers;
|
|
22
|
-
if (isNodeOptions(options)) {
|
|
23
|
-
buttonActionHandlers = {
|
|
24
|
-
onClick: createToolbarCopyCommandForNode(options.nodeType),
|
|
25
|
-
// Note for future changes: these two handlers should perform
|
|
26
|
-
// the same action.
|
|
27
|
-
onMouseEnter: onMouseEnter || (hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(options.nodeType, true, 'ak-editor-selected-node')),
|
|
28
|
-
onFocus: onFocus || (hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(options.nodeType, true, 'ak-editor-selected-node')),
|
|
29
|
-
// Note for future changes: these two handlers should perform
|
|
30
|
-
// the same action.
|
|
31
|
-
onMouseLeave: resetCopiedState(options.nodeType, hoverDecoration, onMouseLeave),
|
|
32
|
-
onBlur: resetCopiedState(options.nodeType, hoverDecoration, onBlur)
|
|
33
|
-
};
|
|
34
|
-
} else {
|
|
35
|
-
buttonActionHandlers = {
|
|
36
|
-
onClick: createToolbarCopyCommandForMark(options.markType),
|
|
37
|
-
onMouseEnter: getProvideMarkVisualFeedbackForCopyButtonCommand(options.markType),
|
|
38
|
-
onFocus: getProvideMarkVisualFeedbackForCopyButtonCommand(options.markType),
|
|
39
|
-
onMouseLeave: removeMarkVisualFeedbackForCopyButtonCommand,
|
|
40
|
-
onBlur: removeMarkVisualFeedbackForCopyButtonCommand
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
id: 'editor.floatingToolbar.copy',
|
|
45
|
-
type: 'button',
|
|
46
|
-
appearance: 'subtle',
|
|
47
|
-
icon: CopyIcon,
|
|
48
|
-
title: formatMessage(copyButtonState !== null && copyButtonState !== void 0 && copyButtonState.copied ? commonMessages.copiedToClipboard : commonMessages.copyToClipboard),
|
|
49
|
-
...buttonActionHandlers,
|
|
50
|
-
hideTooltipOnClick: false,
|
|
51
|
-
tabIndex: null
|
|
52
|
-
// TODO select and delete styling needs to be removed when keyboard cursor moves away
|
|
53
|
-
// problem already exist with delete as well
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export const showCopyButton = state => {
|
|
58
|
-
return state &&
|
|
59
|
-
// Check if the Copy button plugin is enabled
|
|
60
|
-
// @ts-ignore copyButtonPluginKey.key
|
|
61
|
-
state.plugins.find(p => p.key === copyButtonPluginKey.key);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Process floatingToolbar items for copyButton
|
|
66
|
-
*
|
|
67
|
-
* If copy button plugin not enabled, remove copy button item from toolbar items
|
|
68
|
-
* else process copy button to standard floatingtoobarbutton
|
|
69
|
-
*/
|
|
70
|
-
export function processCopyButtonItems(state) {
|
|
71
|
-
return (items, hoverDecoration) => items.flatMap(item => {
|
|
72
|
-
switch (item.type) {
|
|
73
|
-
case 'copy-button':
|
|
74
|
-
if (item !== null && item !== void 0 && item.hidden || !showCopyButton(state)) {
|
|
75
|
-
return [];
|
|
76
|
-
}
|
|
77
|
-
return item === null || item === void 0 ? void 0 : item.items.map(copyButtonItem => isSeparator(copyButtonItem) ? copyButtonItem : getCopyButtonConfig(copyButtonItem, hoverDecoration));
|
|
78
|
-
default:
|
|
79
|
-
return [item];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { findSelectedNodeOfType, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
2
|
-
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
export function getSelectedNodeOrNodeParentByNodeType({
|
|
4
|
-
nodeType,
|
|
5
|
-
selection
|
|
6
|
-
}) {
|
|
7
|
-
let node = findSelectedNodeOfType(nodeType)(selection);
|
|
8
|
-
if (!node) {
|
|
9
|
-
node = findParentNodeOfType(nodeType)(selection);
|
|
10
|
-
}
|
|
11
|
-
return node;
|
|
12
|
-
}
|
|
13
|
-
export const toDOM = (node, schema) => {
|
|
14
|
-
return DOMSerializer.fromSchema(schema).serializeNode(node);
|
|
15
|
-
};
|