@atlaskit/editor-core 187.43.11 → 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.
Files changed (84) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/labs/next/presets/default.js +2 -1
  3. package/dist/cjs/labs/next/presets/universal.js +1 -1
  4. package/dist/cjs/plugins/clipboard/pm-plugins/main.js +13 -54
  5. package/dist/cjs/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +1 -1
  6. package/dist/cjs/plugins/floating-toolbar/index.js +1 -2
  7. package/dist/cjs/plugins/index.js +0 -7
  8. package/dist/cjs/plugins/media/nodeviews/mediaSingle.js +1 -1
  9. package/dist/cjs/plugins/media/pm-plugins/main.js +6 -0
  10. package/dist/cjs/plugins/media/toolbar/index.js +3 -5
  11. package/dist/cjs/plugins/selection/utils.js +29 -80
  12. package/dist/cjs/utils/clipboard.js +19 -127
  13. package/dist/cjs/version-wrapper.js +1 -1
  14. package/dist/es2019/labs/next/presets/default.js +2 -1
  15. package/dist/es2019/labs/next/presets/universal.js +2 -2
  16. package/dist/es2019/plugins/clipboard/pm-plugins/main.js +3 -53
  17. package/dist/es2019/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +1 -1
  18. package/dist/es2019/plugins/floating-toolbar/index.js +1 -2
  19. package/dist/es2019/plugins/index.js +0 -1
  20. package/dist/es2019/plugins/media/nodeviews/mediaSingle.js +1 -1
  21. package/dist/es2019/plugins/media/pm-plugins/main.js +6 -0
  22. package/dist/es2019/plugins/media/toolbar/index.js +3 -7
  23. package/dist/es2019/plugins/selection/utils.js +3 -74
  24. package/dist/es2019/utils/clipboard.js +1 -53
  25. package/dist/es2019/version-wrapper.js +1 -1
  26. package/dist/esm/labs/next/presets/default.js +2 -1
  27. package/dist/esm/labs/next/presets/universal.js +2 -2
  28. package/dist/esm/plugins/clipboard/pm-plugins/main.js +3 -49
  29. package/dist/esm/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +1 -1
  30. package/dist/esm/plugins/floating-toolbar/index.js +1 -2
  31. package/dist/esm/plugins/index.js +0 -1
  32. package/dist/esm/plugins/media/nodeviews/mediaSingle.js +1 -1
  33. package/dist/esm/plugins/media/pm-plugins/main.js +6 -0
  34. package/dist/esm/plugins/media/toolbar/index.js +3 -5
  35. package/dist/esm/plugins/selection/utils.js +3 -72
  36. package/dist/esm/utils/clipboard.js +1 -119
  37. package/dist/esm/version-wrapper.js +1 -1
  38. package/dist/types/labs/next/presets/default.d.ts +68 -4
  39. package/dist/types/plugins/clipboard/pm-plugins/main.d.ts +2 -3
  40. package/dist/types/plugins/index.d.ts +0 -1
  41. package/dist/types/plugins/media/pm-plugins/main.d.ts +1 -0
  42. package/dist/types/plugins/media/pm-plugins/types.d.ts +1 -0
  43. package/dist/types/plugins/selection/utils.d.ts +2 -5
  44. package/dist/types/utils/clipboard.d.ts +1 -3
  45. package/dist/types-ts4.5/labs/next/presets/default.d.ts +86 -0
  46. package/dist/types-ts4.5/plugins/clipboard/pm-plugins/main.d.ts +2 -3
  47. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  48. package/dist/types-ts4.5/plugins/media/pm-plugins/main.d.ts +1 -0
  49. package/dist/types-ts4.5/plugins/media/pm-plugins/types.d.ts +1 -0
  50. package/dist/types-ts4.5/plugins/selection/utils.d.ts +2 -5
  51. package/dist/types-ts4.5/utils/clipboard.d.ts +1 -3
  52. package/package.json +7 -7
  53. package/report.api.md +2 -0
  54. package/tmp/api-report-tmp.d.ts +2 -0
  55. package/dist/cjs/plugins/copy-button/commands.js +0 -171
  56. package/dist/cjs/plugins/copy-button/index.js +0 -23
  57. package/dist/cjs/plugins/copy-button/pm-plugins/main.js +0 -104
  58. package/dist/cjs/plugins/copy-button/pm-plugins/plugin-key.js +0 -9
  59. package/dist/cjs/plugins/copy-button/toolbar.js +0 -99
  60. package/dist/cjs/plugins/copy-button/utils.js +0 -22
  61. package/dist/es2019/plugins/copy-button/commands.js +0 -157
  62. package/dist/es2019/plugins/copy-button/index.js +0 -11
  63. package/dist/es2019/plugins/copy-button/pm-plugins/main.js +0 -97
  64. package/dist/es2019/plugins/copy-button/pm-plugins/plugin-key.js +0 -2
  65. package/dist/es2019/plugins/copy-button/toolbar.js +0 -82
  66. package/dist/es2019/plugins/copy-button/utils.js +0 -15
  67. package/dist/esm/plugins/copy-button/commands.js +0 -159
  68. package/dist/esm/plugins/copy-button/index.js +0 -15
  69. package/dist/esm/plugins/copy-button/pm-plugins/main.js +0 -96
  70. package/dist/esm/plugins/copy-button/pm-plugins/plugin-key.js +0 -2
  71. package/dist/esm/plugins/copy-button/toolbar.js +0 -89
  72. package/dist/esm/plugins/copy-button/utils.js +0 -14
  73. package/dist/types/plugins/copy-button/commands.d.ts +0 -9
  74. package/dist/types/plugins/copy-button/index.d.ts +0 -3
  75. package/dist/types/plugins/copy-button/pm-plugins/main.d.ts +0 -4
  76. package/dist/types/plugins/copy-button/pm-plugins/plugin-key.d.ts +0 -2
  77. package/dist/types/plugins/copy-button/toolbar.d.ts +0 -13
  78. package/dist/types/plugins/copy-button/utils.d.ts +0 -8
  79. package/dist/types-ts4.5/plugins/copy-button/commands.d.ts +0 -9
  80. package/dist/types-ts4.5/plugins/copy-button/index.d.ts +0 -3
  81. package/dist/types-ts4.5/plugins/copy-button/pm-plugins/main.d.ts +0 -4
  82. package/dist/types-ts4.5/plugins/copy-button/pm-plugins/plugin-key.d.ts +0 -2
  83. package/dist/types-ts4.5/plugins/copy-button/toolbar.d.ts +0 -13
  84. package/dist/types-ts4.5/plugins/copy-button/utils.d.ts +0 -8
@@ -1172,6 +1172,8 @@ interface MediaPluginState {
1172
1172
  // (undocumented)
1173
1173
  allUploadsFinished: boolean;
1174
1174
  // (undocumented)
1175
+ currentMaxWidth?: number;
1176
+ // (undocumented)
1175
1177
  destroy(): void;
1176
1178
  // (undocumented)
1177
1179
  dispatch?: Dispatch;
@@ -1,171 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createToolbarCopyCommandForMark = createToolbarCopyCommandForMark;
7
- exports.createToolbarCopyCommandForNode = void 0;
8
- exports.getProvideMarkVisualFeedbackForCopyButtonCommand = getProvideMarkVisualFeedbackForCopyButtonCommand;
9
- exports.removeMarkVisualFeedbackForCopyButtonCommand = removeMarkVisualFeedbackForCopyButtonCommand;
10
- exports.resetCopiedState = void 0;
11
- var _pluginKey = require("./pm-plugins/plugin-key");
12
- var _state = require("@atlaskit/editor-prosemirror/state");
13
- var _clipboard = require("../../utils/clipboard");
14
- var _utils = require("./utils");
15
- var _analytics = require("../analytics");
16
- var _main = require("../clipboard/pm-plugins/main");
17
- var _utils2 = require("@atlaskit/editor-common/utils");
18
- function createToolbarCopyCommandForMark(markType) {
19
- function command(state, dispatch) {
20
- var textNode = state.tr.selection.$head.parent.maybeChild(state.tr.selection.$head.index());
21
- if (!textNode) {
22
- return false;
23
- }
24
- if (dispatch) {
25
- // As calling copyHTMLToClipboard causes side effects -- we only run this when
26
- // dispatch is provided -- as otherwise the consumer is only testing to see if
27
- // the action is availble.
28
- var domNode = (0, _utils.toDOM)(textNode, state.schema);
29
- if (domNode) {
30
- var div = document.createElement('div');
31
- var p = document.createElement('p');
32
- div.appendChild(p);
33
- p.appendChild(domNode);
34
- // The "1 1" refers to the start and end depth of the slice
35
- // since we're copying the text inside a paragraph, it will always be 1 1
36
- // https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
37
- div.firstChild.setAttribute('data-pm-slice', '1 1 []');
38
-
39
- // If we're copying a hyperlink, we'd copy the url as the fallback plain text
40
- var linkUrl = domNode.getAttribute('href');
41
- (0, _clipboard.copyHTMLToClipboard)(div, markType.name === 'link' && linkUrl ? linkUrl : undefined);
42
- }
43
- var copyToClipboardTr = state.tr;
44
- copyToClipboardTr.setMeta(_pluginKey.copyButtonPluginKey, {
45
- copied: true
46
- });
47
- var analyticsPayload = (0, _main.getAnalyticsPayload)(state, _analytics.ACTION.COPIED);
48
- if (analyticsPayload) {
49
- analyticsPayload.attributes.inputMethod = _analytics.INPUT_METHOD.FLOATING_TB;
50
- analyticsPayload.attributes.markType = markType.name;
51
- (0, _analytics.addAnalytics)(state, copyToClipboardTr, analyticsPayload);
52
- }
53
- dispatch(copyToClipboardTr);
54
- }
55
- return true;
56
- }
57
- return command;
58
- }
59
- function getProvideMarkVisualFeedbackForCopyButtonCommand(markType) {
60
- function provideMarkVisualFeedbackForCopyButtonCommand(state, dispatch) {
61
- var tr = state.tr;
62
- tr.setMeta(_pluginKey.copyButtonPluginKey, {
63
- showSelection: true,
64
- markType: markType
65
- });
66
- if (dispatch) {
67
- dispatch(tr);
68
- }
69
- return true;
70
- }
71
- return provideMarkVisualFeedbackForCopyButtonCommand;
72
- }
73
- function removeMarkVisualFeedbackForCopyButtonCommand(state, dispatch) {
74
- var tr = state.tr;
75
- tr.setMeta(_pluginKey.copyButtonPluginKey, {
76
- removeSelection: true
77
- });
78
- var copyButtonState = _pluginKey.copyButtonPluginKey.getState(state);
79
- if (copyButtonState !== null && copyButtonState !== void 0 && copyButtonState.copied) {
80
- tr.setMeta(_pluginKey.copyButtonPluginKey, {
81
- copied: false
82
- });
83
- }
84
- if (dispatch) {
85
- dispatch(tr);
86
- }
87
- return true;
88
- }
89
- var createToolbarCopyCommandForNode = function createToolbarCopyCommandForNode(nodeType) {
90
- return function (state, dispatch) {
91
- var tr = state.tr,
92
- schema = state.schema;
93
-
94
- // This command should only be triggered by the Copy button in the floating toolbar
95
- // which is only visible when selection is inside the target node
96
- var contentNodeWithPos = (0, _utils.getSelectedNodeOrNodeParentByNodeType)({
97
- nodeType: nodeType,
98
- selection: tr.selection
99
- });
100
- if (!contentNodeWithPos) {
101
- return false;
102
- }
103
- var copyToClipboardTr = tr;
104
- copyToClipboardTr.setMeta(_pluginKey.copyButtonPluginKey, {
105
- copied: true
106
- });
107
- var analyticsPayload = (0, _main.getAnalyticsPayload)(state, _analytics.ACTION.COPIED);
108
- if (analyticsPayload) {
109
- analyticsPayload.attributes.inputMethod = _analytics.INPUT_METHOD.FLOATING_TB;
110
- analyticsPayload.attributes.nodeType = contentNodeWithPos.node.type.name;
111
- (0, _analytics.addAnalytics)(state, copyToClipboardTr, analyticsPayload);
112
- }
113
- if (dispatch) {
114
- // As calling copyHTMLToClipboard causes side effects -- we only run this when
115
- // dispatch is provided -- as otherwise the consumer is only testing to see if
116
- // the action is availble.
117
- var domNode = (0, _utils.toDOM)(contentNodeWithPos.node, schema);
118
- if (domNode) {
119
- var div = document.createElement('div');
120
- div.appendChild(domNode);
121
-
122
- // if copying inline content
123
- if (contentNodeWithPos.node.type.inlineContent) {
124
- // The "1 1" refers to the start and end depth of the slice
125
- // since we're copying the text inside a paragraph, it will always be 1 1
126
- // https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
127
- div.firstChild.setAttribute('data-pm-slice', '1 1 []');
128
- } else {
129
- // The "0 0" refers to the start and end depth of the slice
130
- // since we're copying the block node only, it will always be 0 0
131
- // https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
132
- div.firstChild.setAttribute('data-pm-slice', '0 0 []');
133
- }
134
- // 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
135
- // 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
136
- if (_utils2.browser.safari && state.selection instanceof _state.NodeSelection && (state.selection.node.type === state.schema.nodes.extension || state.selection.node.type === state.schema.nodes.mediaSingle)) {
137
- (0, _clipboard.copyHTMLToClipboardPolyfill)(div);
138
- } else {
139
- (0, _clipboard.copyHTMLToClipboard)(div);
140
- }
141
- }
142
- copyToClipboardTr.setMeta('scrollIntoView', false);
143
- dispatch(copyToClipboardTr);
144
- }
145
- return true;
146
- };
147
- };
148
- exports.createToolbarCopyCommandForNode = createToolbarCopyCommandForNode;
149
- var resetCopiedState = function resetCopiedState(nodeType, hoverDecoration, onMouseLeave) {
150
- return function (state, dispatch) {
151
- var customTr = state.tr;
152
-
153
- // Avoid multipe dispatch
154
- // 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
155
- var customDispatch = function customDispatch(tr) {
156
- customTr = tr;
157
- };
158
- onMouseLeave ? onMouseLeave(state, customDispatch) : hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, false)(state, customDispatch);
159
- var copyButtonState = _pluginKey.copyButtonPluginKey.getState(state);
160
- if (copyButtonState !== null && copyButtonState !== void 0 && copyButtonState.copied) {
161
- customTr.setMeta(_pluginKey.copyButtonPluginKey, {
162
- copied: false
163
- });
164
- }
165
- if (dispatch) {
166
- dispatch(customTr);
167
- }
168
- return true;
169
- };
170
- };
171
- exports.resetCopiedState = resetCopiedState;
@@ -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,11 +0,0 @@
1
- import createPlugin from './pm-plugins/main';
2
- const copyButtonPlugin = () => ({
3
- name: 'copyButton',
4
- pmPlugins() {
5
- return [{
6
- name: 'copyButton',
7
- plugin: () => createPlugin()
8
- }];
9
- }
10
- });
11
- export default copyButtonPlugin;