@atlaskit/editor-plugin-copy-button 7.0.12 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-copy-button
2
2
 
3
+ ## 7.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`71321772bd9a7`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/71321772bd9a7) -
8
+ [ux] EDITOR-4932 - Copy extension text content when clicking copy button for unsupported content
9
+ extension.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 7.0.12
4
16
 
5
17
  ### Patch Changes
@@ -20,6 +20,28 @@ function isSeparator(item) {
20
20
  function isNodeOptions(options) {
21
21
  return 'nodeType' in options && options.nodeType !== undefined;
22
22
  }
23
+
24
+ /**
25
+ * Performs the actions after a copy operation.
26
+ * - Sets the copied state in the editor state
27
+ * - Announces the copied message to the user
28
+ */
29
+ function afterCopy(_ref) {
30
+ var _api$accessibilityUti;
31
+ var api = _ref.api,
32
+ dispatch = _ref.dispatch,
33
+ editorState = _ref.editorState,
34
+ message = _ref.message;
35
+ var copyToClipboardTr = editorState.tr;
36
+ copyToClipboardTr.setMeta(_pluginKey.copyButtonPluginKey, {
37
+ copied: true
38
+ });
39
+ copyToClipboardTr.setMeta('scrollIntoView', false);
40
+ dispatch === null || dispatch === void 0 || dispatch(copyToClipboardTr);
41
+ api === null || api === void 0 || (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 || _api$accessibilityUti.actions.ariaNotify(message, {
42
+ priority: 'important'
43
+ });
44
+ }
23
45
  function getCopyButtonConfig(options, hoverDecoration, editorAnalyticsApi, api) {
24
46
  var state = options.state,
25
47
  formatMessage = options.formatMessage,
@@ -30,6 +52,7 @@ function getCopyButtonConfig(options, hoverDecoration, editorAnalyticsApi, api)
30
52
  var copyButtonState = _pluginKey.copyButtonPluginKey.getState(state);
31
53
  var buttonActionHandlers;
32
54
  if (isNodeOptions(options)) {
55
+ var onClick = options.onClick;
33
56
  buttonActionHandlers = {
34
57
  onClick: (0, _commands.createToolbarCopyCommandForNode)(options.nodeType, editorAnalyticsApi, api, formatMessage(_messages.default.copiedToClipboard)),
35
58
  // Note for future changes: these two handlers should perform
@@ -41,6 +64,20 @@ function getCopyButtonConfig(options, hoverDecoration, editorAnalyticsApi, api)
41
64
  onMouseLeave: (0, _commands.resetCopiedState)(options.nodeType, hoverDecoration, onMouseLeave),
42
65
  onBlur: (0, _commands.resetCopiedState)(options.nodeType, hoverDecoration, onBlur)
43
66
  };
67
+ if (onClick) {
68
+ buttonActionHandlers.onClick = function (editorState, dispatch, editorView) {
69
+ if (onClick(editorState, dispatch, editorView)) {
70
+ afterCopy({
71
+ api: api,
72
+ dispatch: dispatch,
73
+ editorState: editorState,
74
+ message: formatMessage(_messages.default.copiedToClipboard)
75
+ });
76
+ return true;
77
+ }
78
+ return false;
79
+ };
80
+ }
44
81
  } else {
45
82
  buttonActionHandlers = {
46
83
  onClick: (0, _commands.createToolbarCopyCommandForMark)(options.markType, editorAnalyticsApi),
@@ -66,7 +103,7 @@ function getCopyButtonConfig(options, hoverDecoration, editorAnalyticsApi, api)
66
103
  * Process floatingToolbar items for copyButton
67
104
  */
68
105
  var processCopyButtonItems = exports.processCopyButtonItems = function processCopyButtonItems(editorAnalyticsApi, api) {
69
- return function (state) {
106
+ return function (_state) {
70
107
  return function (items, hoverDecoration) {
71
108
  return items.flatMap(function (item) {
72
109
  switch (item.type) {
@@ -10,6 +10,29 @@ function isSeparator(item) {
10
10
  function isNodeOptions(options) {
11
11
  return 'nodeType' in options && options.nodeType !== undefined;
12
12
  }
13
+
14
+ /**
15
+ * Performs the actions after a copy operation.
16
+ * - Sets the copied state in the editor state
17
+ * - Announces the copied message to the user
18
+ */
19
+ function afterCopy({
20
+ api,
21
+ dispatch,
22
+ editorState,
23
+ message
24
+ }) {
25
+ var _api$accessibilityUti;
26
+ const copyToClipboardTr = editorState.tr;
27
+ copyToClipboardTr.setMeta(copyButtonPluginKey, {
28
+ copied: true
29
+ });
30
+ copyToClipboardTr.setMeta('scrollIntoView', false);
31
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch(copyToClipboardTr);
32
+ api === null || api === void 0 ? void 0 : (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify(message, {
33
+ priority: 'important'
34
+ });
35
+ }
13
36
  export function getCopyButtonConfig(options, hoverDecoration, editorAnalyticsApi, api) {
14
37
  const {
15
38
  state,
@@ -22,6 +45,9 @@ export function getCopyButtonConfig(options, hoverDecoration, editorAnalyticsApi
22
45
  const copyButtonState = copyButtonPluginKey.getState(state);
23
46
  let buttonActionHandlers;
24
47
  if (isNodeOptions(options)) {
48
+ const {
49
+ onClick
50
+ } = options;
25
51
  buttonActionHandlers = {
26
52
  onClick: createToolbarCopyCommandForNode(options.nodeType, editorAnalyticsApi, api, formatMessage(commonMessages.copiedToClipboard)),
27
53
  // Note for future changes: these two handlers should perform
@@ -33,6 +59,20 @@ export function getCopyButtonConfig(options, hoverDecoration, editorAnalyticsApi
33
59
  onMouseLeave: resetCopiedState(options.nodeType, hoverDecoration, onMouseLeave),
34
60
  onBlur: resetCopiedState(options.nodeType, hoverDecoration, onBlur)
35
61
  };
62
+ if (onClick) {
63
+ buttonActionHandlers.onClick = (editorState, dispatch, editorView) => {
64
+ if (onClick(editorState, dispatch, editorView)) {
65
+ afterCopy({
66
+ api,
67
+ dispatch,
68
+ editorState,
69
+ message: formatMessage(commonMessages.copiedToClipboard)
70
+ });
71
+ return true;
72
+ }
73
+ return false;
74
+ };
75
+ }
36
76
  } else {
37
77
  buttonActionHandlers = {
38
78
  onClick: createToolbarCopyCommandForMark(options.markType, editorAnalyticsApi),
@@ -57,7 +97,7 @@ export function getCopyButtonConfig(options, hoverDecoration, editorAnalyticsApi
57
97
  /**
58
98
  * Process floatingToolbar items for copyButton
59
99
  */
60
- export const processCopyButtonItems = (editorAnalyticsApi, api) => state => {
100
+ export const processCopyButtonItems = (editorAnalyticsApi, api) => _state => {
61
101
  return (items, hoverDecoration) => items.flatMap(item => {
62
102
  switch (item.type) {
63
103
  case 'copy-button':
@@ -13,6 +13,28 @@ function isSeparator(item) {
13
13
  function isNodeOptions(options) {
14
14
  return 'nodeType' in options && options.nodeType !== undefined;
15
15
  }
16
+
17
+ /**
18
+ * Performs the actions after a copy operation.
19
+ * - Sets the copied state in the editor state
20
+ * - Announces the copied message to the user
21
+ */
22
+ function afterCopy(_ref) {
23
+ var _api$accessibilityUti;
24
+ var api = _ref.api,
25
+ dispatch = _ref.dispatch,
26
+ editorState = _ref.editorState,
27
+ message = _ref.message;
28
+ var copyToClipboardTr = editorState.tr;
29
+ copyToClipboardTr.setMeta(copyButtonPluginKey, {
30
+ copied: true
31
+ });
32
+ copyToClipboardTr.setMeta('scrollIntoView', false);
33
+ dispatch === null || dispatch === void 0 || dispatch(copyToClipboardTr);
34
+ api === null || api === void 0 || (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 || _api$accessibilityUti.actions.ariaNotify(message, {
35
+ priority: 'important'
36
+ });
37
+ }
16
38
  export function getCopyButtonConfig(options, hoverDecoration, editorAnalyticsApi, api) {
17
39
  var state = options.state,
18
40
  formatMessage = options.formatMessage,
@@ -23,6 +45,7 @@ export function getCopyButtonConfig(options, hoverDecoration, editorAnalyticsApi
23
45
  var copyButtonState = copyButtonPluginKey.getState(state);
24
46
  var buttonActionHandlers;
25
47
  if (isNodeOptions(options)) {
48
+ var onClick = options.onClick;
26
49
  buttonActionHandlers = {
27
50
  onClick: createToolbarCopyCommandForNode(options.nodeType, editorAnalyticsApi, api, formatMessage(commonMessages.copiedToClipboard)),
28
51
  // Note for future changes: these two handlers should perform
@@ -34,6 +57,20 @@ export function getCopyButtonConfig(options, hoverDecoration, editorAnalyticsApi
34
57
  onMouseLeave: resetCopiedState(options.nodeType, hoverDecoration, onMouseLeave),
35
58
  onBlur: resetCopiedState(options.nodeType, hoverDecoration, onBlur)
36
59
  };
60
+ if (onClick) {
61
+ buttonActionHandlers.onClick = function (editorState, dispatch, editorView) {
62
+ if (onClick(editorState, dispatch, editorView)) {
63
+ afterCopy({
64
+ api: api,
65
+ dispatch: dispatch,
66
+ editorState: editorState,
67
+ message: formatMessage(commonMessages.copiedToClipboard)
68
+ });
69
+ return true;
70
+ }
71
+ return false;
72
+ };
73
+ }
37
74
  } else {
38
75
  buttonActionHandlers = {
39
76
  onClick: createToolbarCopyCommandForMark(options.markType, editorAnalyticsApi),
@@ -59,7 +96,7 @@ export function getCopyButtonConfig(options, hoverDecoration, editorAnalyticsApi
59
96
  * Process floatingToolbar items for copyButton
60
97
  */
61
98
  export var processCopyButtonItems = function processCopyButtonItems(editorAnalyticsApi, api) {
62
- return function (state) {
99
+ return function (_state) {
63
100
  return function (items, hoverDecoration) {
64
101
  return items.flatMap(function (item) {
65
102
  switch (item.type) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-copy-button",
3
- "version": "7.0.12",
3
+ "version": "7.1.0",
4
4
  "description": "editor-plugin-copy-button for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,11 +32,11 @@
32
32
  "@atlaskit/editor-plugin-decorations": "^7.0.0",
33
33
  "@atlaskit/editor-prosemirror": "^7.3.0",
34
34
  "@atlaskit/icon": "^31.0.0",
35
- "@atlaskit/tmp-editor-statsig": "^25.0.0",
35
+ "@atlaskit/tmp-editor-statsig": "^25.2.0",
36
36
  "@babel/runtime": "^7.0.0"
37
37
  },
38
38
  "peerDependencies": {
39
- "@atlaskit/editor-common": "^111.12.0",
39
+ "@atlaskit/editor-common": "^111.13.0",
40
40
  "react": "^18.2.0",
41
41
  "react-dom": "^18.2.0"
42
42
  },