@atlaskit/editor-core 187.43.12 → 187.43.17

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 (92) 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/selection/utils.js +29 -80
  9. package/dist/cjs/plugins/type-ahead/index.js +2 -2
  10. package/dist/cjs/plugins/type-ahead/pm-plugins/main.js +4 -4
  11. package/dist/cjs/plugins/type-ahead/ui/TypeAheadListItem.js +2 -2
  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/selection/utils.js +3 -74
  21. package/dist/es2019/plugins/type-ahead/index.js +1 -1
  22. package/dist/es2019/plugins/type-ahead/pm-plugins/main.js +1 -1
  23. package/dist/es2019/plugins/type-ahead/ui/TypeAheadListItem.js +1 -1
  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/selection/utils.js +3 -72
  33. package/dist/esm/plugins/type-ahead/index.js +1 -1
  34. package/dist/esm/plugins/type-ahead/pm-plugins/main.js +1 -1
  35. package/dist/esm/plugins/type-ahead/ui/TypeAheadListItem.js +1 -1
  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/selection/utils.d.ts +2 -5
  42. package/dist/types/plugins/type-ahead/api.d.ts +1 -1
  43. package/dist/types/plugins/type-ahead/commands/update-list-items.d.ts +1 -1
  44. package/dist/types/plugins/type-ahead/commands/update-query.d.ts +1 -1
  45. package/dist/types/plugins/type-ahead/commands/update-selected-index.d.ts +1 -1
  46. package/dist/types/plugins/type-ahead/pm-plugins/main.d.ts +1 -1
  47. package/dist/types/plugins/type-ahead/types.d.ts +1 -1
  48. package/dist/types/utils/clipboard.d.ts +1 -3
  49. package/dist/types-ts4.5/labs/next/presets/default.d.ts +86 -0
  50. package/dist/types-ts4.5/plugins/clipboard/pm-plugins/main.d.ts +2 -3
  51. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  52. package/dist/types-ts4.5/plugins/selection/utils.d.ts +2 -5
  53. package/dist/types-ts4.5/plugins/type-ahead/api.d.ts +1 -1
  54. package/dist/types-ts4.5/plugins/type-ahead/commands/update-list-items.d.ts +1 -1
  55. package/dist/types-ts4.5/plugins/type-ahead/commands/update-query.d.ts +1 -1
  56. package/dist/types-ts4.5/plugins/type-ahead/commands/update-selected-index.d.ts +1 -1
  57. package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/main.d.ts +1 -1
  58. package/dist/types-ts4.5/plugins/type-ahead/types.d.ts +1 -1
  59. package/dist/types-ts4.5/utils/clipboard.d.ts +1 -3
  60. package/package.json +12 -8
  61. package/report.api.md +1 -1
  62. package/tmp/api-report-tmp.d.ts +1 -1
  63. package/dist/cjs/plugins/copy-button/commands.js +0 -171
  64. package/dist/cjs/plugins/copy-button/index.js +0 -23
  65. package/dist/cjs/plugins/copy-button/pm-plugins/main.js +0 -104
  66. package/dist/cjs/plugins/copy-button/pm-plugins/plugin-key.js +0 -9
  67. package/dist/cjs/plugins/copy-button/toolbar.js +0 -99
  68. package/dist/cjs/plugins/copy-button/utils.js +0 -22
  69. package/dist/es2019/plugins/copy-button/commands.js +0 -157
  70. package/dist/es2019/plugins/copy-button/index.js +0 -11
  71. package/dist/es2019/plugins/copy-button/pm-plugins/main.js +0 -97
  72. package/dist/es2019/plugins/copy-button/pm-plugins/plugin-key.js +0 -2
  73. package/dist/es2019/plugins/copy-button/toolbar.js +0 -82
  74. package/dist/es2019/plugins/copy-button/utils.js +0 -15
  75. package/dist/esm/plugins/copy-button/commands.js +0 -159
  76. package/dist/esm/plugins/copy-button/index.js +0 -15
  77. package/dist/esm/plugins/copy-button/pm-plugins/main.js +0 -96
  78. package/dist/esm/plugins/copy-button/pm-plugins/plugin-key.js +0 -2
  79. package/dist/esm/plugins/copy-button/toolbar.js +0 -89
  80. package/dist/esm/plugins/copy-button/utils.js +0 -14
  81. package/dist/types/plugins/copy-button/commands.d.ts +0 -9
  82. package/dist/types/plugins/copy-button/index.d.ts +0 -3
  83. package/dist/types/plugins/copy-button/pm-plugins/main.d.ts +0 -4
  84. package/dist/types/plugins/copy-button/pm-plugins/plugin-key.d.ts +0 -2
  85. package/dist/types/plugins/copy-button/toolbar.d.ts +0 -13
  86. package/dist/types/plugins/copy-button/utils.d.ts +0 -8
  87. package/dist/types-ts4.5/plugins/copy-button/commands.d.ts +0 -9
  88. package/dist/types-ts4.5/plugins/copy-button/index.d.ts +0 -3
  89. package/dist/types-ts4.5/plugins/copy-button/pm-plugins/main.d.ts +0 -4
  90. package/dist/types-ts4.5/plugins/copy-button/pm-plugins/plugin-key.d.ts +0 -2
  91. package/dist/types-ts4.5/plugins/copy-button/toolbar.d.ts +0 -13
  92. package/dist/types-ts4.5/plugins/copy-button/utils.d.ts +0 -8
@@ -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;
@@ -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,2 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- export const copyButtonPluginKey = new PluginKey('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
- };
@@ -1,159 +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
- var 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
- var domNode = toDOM(textNode, state.schema);
19
- if (domNode) {
20
- var div = document.createElement('div');
21
- var 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
- var linkUrl = domNode.getAttribute('href');
31
- copyHTMLToClipboard(div, markType.name === 'link' && linkUrl ? linkUrl : undefined);
32
- }
33
- var copyToClipboardTr = state.tr;
34
- copyToClipboardTr.setMeta(copyButtonPluginKey, {
35
- copied: true
36
- });
37
- var 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
- var tr = state.tr;
52
- tr.setMeta(copyButtonPluginKey, {
53
- showSelection: true,
54
- markType: markType
55
- });
56
- if (dispatch) {
57
- dispatch(tr);
58
- }
59
- return true;
60
- }
61
- return provideMarkVisualFeedbackForCopyButtonCommand;
62
- }
63
- export function removeMarkVisualFeedbackForCopyButtonCommand(state, dispatch) {
64
- var tr = state.tr;
65
- tr.setMeta(copyButtonPluginKey, {
66
- removeSelection: true
67
- });
68
- var 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 var createToolbarCopyCommandForNode = function createToolbarCopyCommandForNode(nodeType) {
80
- return function (state, dispatch) {
81
- var tr = state.tr,
82
- schema = state.schema;
83
-
84
- // This command should only be triggered by the Copy button in the floating toolbar
85
- // which is only visible when selection is inside the target node
86
- var contentNodeWithPos = getSelectedNodeOrNodeParentByNodeType({
87
- nodeType: nodeType,
88
- selection: tr.selection
89
- });
90
- if (!contentNodeWithPos) {
91
- return false;
92
- }
93
- var copyToClipboardTr = tr;
94
- copyToClipboardTr.setMeta(copyButtonPluginKey, {
95
- copied: true
96
- });
97
- var analyticsPayload = getAnalyticsPayload(state, ACTION.COPIED);
98
- if (analyticsPayload) {
99
- analyticsPayload.attributes.inputMethod = INPUT_METHOD.FLOATING_TB;
100
- analyticsPayload.attributes.nodeType = contentNodeWithPos.node.type.name;
101
- addAnalytics(state, copyToClipboardTr, analyticsPayload);
102
- }
103
- if (dispatch) {
104
- // As calling copyHTMLToClipboard causes side effects -- we only run this when
105
- // dispatch is provided -- as otherwise the consumer is only testing to see if
106
- // the action is availble.
107
- var domNode = toDOM(contentNodeWithPos.node, schema);
108
- if (domNode) {
109
- var div = document.createElement('div');
110
- div.appendChild(domNode);
111
-
112
- // if copying inline content
113
- if (contentNodeWithPos.node.type.inlineContent) {
114
- // The "1 1" refers to the start and end depth of the slice
115
- // since we're copying the text inside a paragraph, it will always be 1 1
116
- // https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
117
- div.firstChild.setAttribute('data-pm-slice', '1 1 []');
118
- } else {
119
- // The "0 0" refers to the start and end depth of the slice
120
- // since we're copying the block node only, it will always be 0 0
121
- // https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
122
- div.firstChild.setAttribute('data-pm-slice', '0 0 []');
123
- }
124
- // 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
125
- // 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
126
- if (browser.safari && state.selection instanceof NodeSelection && (state.selection.node.type === state.schema.nodes.extension || state.selection.node.type === state.schema.nodes.mediaSingle)) {
127
- copyHTMLToClipboardPolyfill(div);
128
- } else {
129
- copyHTMLToClipboard(div);
130
- }
131
- }
132
- copyToClipboardTr.setMeta('scrollIntoView', false);
133
- dispatch(copyToClipboardTr);
134
- }
135
- return true;
136
- };
137
- };
138
- export var resetCopiedState = function resetCopiedState(nodeType, hoverDecoration, onMouseLeave) {
139
- return function (state, dispatch) {
140
- var customTr = state.tr;
141
-
142
- // Avoid multipe dispatch
143
- // 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
144
- var customDispatch = function customDispatch(tr) {
145
- customTr = tr;
146
- };
147
- onMouseLeave ? onMouseLeave(state, customDispatch) : hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, false)(state, customDispatch);
148
- var copyButtonState = copyButtonPluginKey.getState(state);
149
- if (copyButtonState !== null && copyButtonState !== void 0 && copyButtonState.copied) {
150
- customTr.setMeta(copyButtonPluginKey, {
151
- copied: false
152
- });
153
- }
154
- if (dispatch) {
155
- dispatch(customTr);
156
- }
157
- return true;
158
- };
159
- };
@@ -1,15 +0,0 @@
1
- import createPlugin from './pm-plugins/main';
2
- var copyButtonPlugin = function copyButtonPlugin() {
3
- return {
4
- name: 'copyButton',
5
- pmPlugins: function pmPlugins() {
6
- return [{
7
- name: 'copyButton',
8
- plugin: function plugin() {
9
- return createPlugin();
10
- }
11
- }];
12
- }
13
- };
14
- };
15
- export default copyButtonPlugin;
@@ -1,96 +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(_ref) {
5
- var markType = _ref.markType,
6
- transaction = _ref.transaction;
7
- var headResolvedPos = transaction.selection.$head;
8
- var textNodeIndex = transaction.selection.$head.index();
9
- var textNode = headResolvedPos.parent.maybeChild(textNodeIndex);
10
- var textNodeOffset = 0;
11
- headResolvedPos.parent.forEach(function (_node, nodeOffset, index) {
12
- if (index === textNodeIndex) {
13
- textNodeOffset = nodeOffset;
14
- }
15
- });
16
- var start = headResolvedPos.start(headResolvedPos.depth) + textNodeOffset;
17
- var end = start + textNode.text.length;
18
- return {
19
- start: start,
20
- end: end,
21
- markType: markType
22
- };
23
- }
24
- export function copyButtonPlugin() {
25
- return new SafePlugin({
26
- key: copyButtonPluginKey,
27
- state: {
28
- init: function init() {
29
- return {
30
- copied: false,
31
- markSelection: undefined
32
- };
33
- },
34
- apply: function apply(tr, currentPluginState) {
35
- var meta = tr.getMeta(copyButtonPluginKey);
36
- if ((meta === null || meta === void 0 ? void 0 : meta.copied) !== undefined) {
37
- return {
38
- copied: meta.copied,
39
- markSelection: undefined
40
- };
41
- }
42
- if (meta !== null && meta !== void 0 && meta.showSelection) {
43
- return {
44
- copied: currentPluginState.copied,
45
- markSelection: getMarkSelectionDecorationStartAndEnd({
46
- markType: meta.markType,
47
- transaction: tr
48
- })
49
- };
50
- }
51
- if (meta !== null && meta !== void 0 && meta.removeSelection) {
52
- return {
53
- copied: currentPluginState.copied,
54
- markSelection: undefined
55
- };
56
- }
57
- if (currentPluginState.markSelection) {
58
- return {
59
- copied: currentPluginState.copied,
60
- markSelection: getMarkSelectionDecorationStartAndEnd({
61
- markType: currentPluginState.markSelection.markType,
62
- transaction: tr
63
- })
64
- };
65
- }
66
- return currentPluginState;
67
- }
68
- },
69
- props: {
70
- decorations: function decorations(_state) {
71
- // Showing visual hints for the hyperlink copy button has been disabled
72
- // due to an issue where invalid hyperlink marks cause the floating toolbar
73
- // to jump around when the copy button is hovered.
74
- // See the following bug for details -- once that is resolved -- the visual
75
- // hints can be re enabled.
76
- // https://product-fabric.atlassian.net/browse/DTR-722
77
-
78
- // const copyButtonPluginState = copyButtonPluginKey.getState(
79
- // state,
80
- // ) as CopyButtonPluginState;
81
- // if (copyButtonPluginState.markSelection) {
82
- // const { start, end } = copyButtonPluginState.markSelection;
83
-
84
- // return DecorationSet.create(state.doc, [
85
- // Decoration.inline(start, end, {
86
- // class: 'ProseMirror-fake-text-selection',
87
- // }),
88
- // ]);
89
- // }
90
-
91
- return DecorationSet.empty;
92
- }
93
- }
94
- });
95
- }
96
- export default copyButtonPlugin;
@@ -1,2 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- export var copyButtonPluginKey = new PluginKey('copyButtonPlugin');