@atlaskit/editor-plugin-block-menu 4.0.1 → 4.0.2

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,14 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 4.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`9cf29da7572b3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9cf29da7572b3) -
8
+ [ux] Fires Element converted event when Turn into menu is used to transform a node from one node
9
+ type to another.
10
+ - Updated dependencies
11
+
3
12
  ## 4.0.1
4
13
 
5
14
  ### Patch Changes
@@ -23,6 +23,9 @@
23
23
  {
24
24
  "path": "../../../design-system/dropdown-menu/afm-cc/tsconfig.json"
25
25
  },
26
+ {
27
+ "path": "../../editor-plugin-analytics/afm-cc/tsconfig.json"
28
+ },
26
29
  {
27
30
  "path": "../../editor-plugin-block-controls/afm-cc/tsconfig.json"
28
31
  },
@@ -38,7 +38,7 @@ var blockMenuPlugin = exports.blockMenuPlugin = function blockMenuPlugin(_ref) {
38
38
  },
39
39
  commands: {
40
40
  formatNode: function formatNode(targetType) {
41
- return (0, _formatNode2.formatNode)(targetType);
41
+ return (0, _formatNode2.formatNode)(api)(targetType);
42
42
  }
43
43
  },
44
44
  getSharedState: function getSharedState(editorState) {
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.formatNode = void 0;
7
+ var _analytics = require("@atlaskit/editor-common/analytics");
7
8
  var _utils = require("@atlaskit/editor-prosemirror/utils");
8
9
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
10
  var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
@@ -51,62 +52,83 @@ var formatNodeWhenSelectionEmpty = function formatNodeWhenSelectionEmpty(tr, tar
51
52
 
52
53
  /**
53
54
  * Formats the current node or selection to the specified target type
55
+ * @param api - The editor API injection that provides access to analytics and other plugin actions
54
56
  * @param targetType - The target node type to convert to
55
57
  */
56
- var formatNode = exports.formatNode = function formatNode(targetType) {
57
- return function (_ref) {
58
- var tr = _ref.tr;
59
- var selection = tr.selection;
60
- var schema = tr.doc.type.schema;
61
- var nodes = schema.nodes;
58
+ var formatNode = exports.formatNode = function formatNode(api) {
59
+ return function (targetType) {
60
+ return function (_ref) {
61
+ var tr = _ref.tr;
62
+ var selection = tr.selection;
63
+ var schema = tr.doc.type.schema;
64
+ var nodes = schema.nodes;
62
65
 
63
- // Find the node to format from the current selection
64
- var nodeToFormat;
65
- var nodePos = selection.from;
66
+ // Find the node to format from the current selection
67
+ var nodeToFormat;
68
+ var nodePos = selection.from;
66
69
 
67
- // when selection is empty, we insert a empty target node
68
- if (selection.empty && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu_empty_line', 'isEnabled', true)) {
69
- return formatNodeWhenSelectionEmpty(tr, targetType, nodePos, schema);
70
- }
70
+ // when selection is empty, we insert a empty target node
71
+ if (selection.empty && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu_empty_line', 'isEnabled', true)) {
72
+ return formatNodeWhenSelectionEmpty(tr, targetType, nodePos, schema);
73
+ }
71
74
 
72
- // Try to find the current node from selection
73
- var selectedNode = (0, _utils.findSelectedNodeOfType)([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection])(selection);
74
- if (selectedNode) {
75
- nodeToFormat = selectedNode.node;
76
- nodePos = selectedNode.pos;
77
- } else {
78
- // Try to find parent node (including list parents)
79
- var parentNode = (0, _utils.findParentNodeOfType)([nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.listItem, nodes.taskItem, nodes.layoutSection])(selection);
80
- if (parentNode) {
81
- nodeToFormat = parentNode.node;
82
- nodePos = parentNode.pos;
83
- var paragraphOrHeadingNode = (0, _utils.findParentNodeOfType)([nodes.paragraph, nodes.heading])(selection);
84
- // Special case: if we found a listItem, check if we need the parent list instead
85
- if (parentNode.node.type === nodes.listItem || parentNode.node.type === nodes.taskItem) {
86
- var listParent = (0, _utils.findParentNodeOfType)([nodes.bulletList, nodes.orderedList, nodes.taskList])(selection);
87
- if (listParent) {
88
- // For list transformations, we want the list parent, not the listItem
89
- nodeToFormat = listParent.node;
90
- nodePos = listParent.pos;
75
+ // Try to find the current node from selection
76
+ var selectedNode = (0, _utils.findSelectedNodeOfType)([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection])(selection);
77
+ if (selectedNode) {
78
+ nodeToFormat = selectedNode.node;
79
+ nodePos = selectedNode.pos;
80
+ } else {
81
+ // Try to find parent node (including list parents)
82
+ var parentNode = (0, _utils.findParentNodeOfType)([nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.listItem, nodes.taskItem, nodes.layoutSection])(selection);
83
+ if (parentNode) {
84
+ nodeToFormat = parentNode.node;
85
+ nodePos = parentNode.pos;
86
+ var paragraphOrHeadingNode = (0, _utils.findParentNodeOfType)([nodes.paragraph, nodes.heading])(selection);
87
+ // Special case: if we found a listItem, check if we need the parent list instead
88
+ if (parentNode.node.type === nodes.listItem || parentNode.node.type === nodes.taskItem) {
89
+ var listParent = (0, _utils.findParentNodeOfType)([nodes.bulletList, nodes.orderedList, nodes.taskList])(selection);
90
+ if (listParent) {
91
+ // For list transformations, we want the list parent, not the listItem
92
+ nodeToFormat = listParent.node;
93
+ nodePos = listParent.pos;
94
+ }
95
+ } else if (parentNode.node.type !== nodes.blockquote && paragraphOrHeadingNode) {
96
+ nodeToFormat = paragraphOrHeadingNode.node;
97
+ nodePos = paragraphOrHeadingNode.pos;
91
98
  }
92
- } else if (parentNode.node.type !== nodes.blockquote && paragraphOrHeadingNode) {
93
- nodeToFormat = paragraphOrHeadingNode.node;
94
- nodePos = paragraphOrHeadingNode.pos;
95
99
  }
96
100
  }
97
- }
98
- if (!nodeToFormat) {
99
- nodeToFormat = selection.$from.node();
100
- nodePos = selection.$from.pos;
101
- }
102
- try {
103
- var newTr = (0, _transformNodeToTargetType.transformNodeToTargetType)(tr, nodeToFormat, nodePos, targetType);
104
- if (newTr && (0, _platformFeatureFlags.fg)('platform_editor_block_menu_selection_fix')) {
105
- return (0, _selection.setSelectionAfterTransform)(newTr, nodePos, targetType);
101
+ if (!nodeToFormat) {
102
+ nodeToFormat = selection.$from.node();
103
+ nodePos = selection.$from.pos;
106
104
  }
107
- return newTr;
108
- } catch (_unused) {
109
- return null;
110
- }
105
+ try {
106
+ var _nodeToFormat$attrs;
107
+ var newTr = (0, _transformNodeToTargetType.transformNodeToTargetType)(tr, nodeToFormat, nodePos, targetType);
108
+ var sourceTypeName = nodeToFormat.type.name;
109
+ if (sourceTypeName === 'heading' && (_nodeToFormat$attrs = nodeToFormat.attrs) !== null && _nodeToFormat$attrs !== void 0 && _nodeToFormat$attrs.level) {
110
+ sourceTypeName = "heading".concat(nodeToFormat.attrs.level);
111
+ }
112
+ if (newTr && sourceTypeName !== targetType) {
113
+ var _api$analytics;
114
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent({
115
+ action: _analytics.ACTION.CONVERTED,
116
+ actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
117
+ eventType: _analytics.EVENT_TYPE.TRACK,
118
+ attributes: {
119
+ from: sourceTypeName,
120
+ to: targetType,
121
+ inputMethod: _analytics.INPUT_METHOD.BLOCK_MENU
122
+ }
123
+ })(newTr);
124
+ }
125
+ if (newTr && (0, _platformFeatureFlags.fg)('platform_editor_block_menu_selection_fix')) {
126
+ return (0, _selection.setSelectionAfterTransform)(newTr, nodePos, targetType);
127
+ }
128
+ return newTr;
129
+ } catch (_unused) {
130
+ return null;
131
+ }
132
+ };
111
133
  };
112
134
  };
@@ -32,7 +32,7 @@ export const blockMenuPlugin = ({
32
32
  },
33
33
  commands: {
34
34
  formatNode: targetType => {
35
- return formatNode(targetType);
35
+ return formatNode(api)(targetType);
36
36
  }
37
37
  },
38
38
  getSharedState(editorState) {
@@ -1,3 +1,4 @@
1
+ import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
1
2
  import { findParentNodeOfType, findSelectedNodeOfType, safeInsert as pmSafeInsert } from '@atlaskit/editor-prosemirror/utils';
2
3
  import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
@@ -49,9 +50,10 @@ const formatNodeWhenSelectionEmpty = (tr, targetType, nodePos, schema) => {
49
50
 
50
51
  /**
51
52
  * Formats the current node or selection to the specified target type
53
+ * @param api - The editor API injection that provides access to analytics and other plugin actions
52
54
  * @param targetType - The target node type to convert to
53
55
  */
54
- export const formatNode = targetType => {
56
+ export const formatNode = api => targetType => {
55
57
  return ({
56
58
  tr
57
59
  }) => {
@@ -103,7 +105,25 @@ export const formatNode = targetType => {
103
105
  nodePos = selection.$from.pos;
104
106
  }
105
107
  try {
108
+ var _nodeToFormat$attrs;
106
109
  const newTr = transformNodeToTargetType(tr, nodeToFormat, nodePos, targetType);
110
+ let sourceTypeName = nodeToFormat.type.name;
111
+ if (sourceTypeName === 'heading' && (_nodeToFormat$attrs = nodeToFormat.attrs) !== null && _nodeToFormat$attrs !== void 0 && _nodeToFormat$attrs.level) {
112
+ sourceTypeName = `heading${nodeToFormat.attrs.level}`;
113
+ }
114
+ if (newTr && sourceTypeName !== targetType) {
115
+ var _api$analytics, _api$analytics$action;
116
+ api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : (_api$analytics$action = _api$analytics.actions) === null || _api$analytics$action === void 0 ? void 0 : _api$analytics$action.attachAnalyticsEvent({
117
+ action: ACTION.CONVERTED,
118
+ actionSubject: ACTION_SUBJECT.ELEMENT,
119
+ eventType: EVENT_TYPE.TRACK,
120
+ attributes: {
121
+ from: sourceTypeName,
122
+ to: targetType,
123
+ inputMethod: INPUT_METHOD.BLOCK_MENU
124
+ }
125
+ })(newTr);
126
+ }
107
127
  if (newTr && fg('platform_editor_block_menu_selection_fix')) {
108
128
  return setSelectionAfterTransform(newTr, nodePos, targetType);
109
129
  }
@@ -31,7 +31,7 @@ export var blockMenuPlugin = function blockMenuPlugin(_ref) {
31
31
  },
32
32
  commands: {
33
33
  formatNode: function formatNode(targetType) {
34
- return _formatNode(targetType);
34
+ return _formatNode(api)(targetType);
35
35
  }
36
36
  },
37
37
  getSharedState: function getSharedState(editorState) {
@@ -1,3 +1,4 @@
1
+ import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
1
2
  import { findParentNodeOfType, findSelectedNodeOfType, safeInsert as pmSafeInsert } from '@atlaskit/editor-prosemirror/utils';
2
3
  import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
@@ -45,62 +46,83 @@ var formatNodeWhenSelectionEmpty = function formatNodeWhenSelectionEmpty(tr, tar
45
46
 
46
47
  /**
47
48
  * Formats the current node or selection to the specified target type
49
+ * @param api - The editor API injection that provides access to analytics and other plugin actions
48
50
  * @param targetType - The target node type to convert to
49
51
  */
50
- export var formatNode = function formatNode(targetType) {
51
- return function (_ref) {
52
- var tr = _ref.tr;
53
- var selection = tr.selection;
54
- var schema = tr.doc.type.schema;
55
- var nodes = schema.nodes;
52
+ export var formatNode = function formatNode(api) {
53
+ return function (targetType) {
54
+ return function (_ref) {
55
+ var tr = _ref.tr;
56
+ var selection = tr.selection;
57
+ var schema = tr.doc.type.schema;
58
+ var nodes = schema.nodes;
56
59
 
57
- // Find the node to format from the current selection
58
- var nodeToFormat;
59
- var nodePos = selection.from;
60
+ // Find the node to format from the current selection
61
+ var nodeToFormat;
62
+ var nodePos = selection.from;
60
63
 
61
- // when selection is empty, we insert a empty target node
62
- if (selection.empty && expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true)) {
63
- return formatNodeWhenSelectionEmpty(tr, targetType, nodePos, schema);
64
- }
64
+ // when selection is empty, we insert a empty target node
65
+ if (selection.empty && expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true)) {
66
+ return formatNodeWhenSelectionEmpty(tr, targetType, nodePos, schema);
67
+ }
65
68
 
66
- // Try to find the current node from selection
67
- var selectedNode = findSelectedNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection])(selection);
68
- if (selectedNode) {
69
- nodeToFormat = selectedNode.node;
70
- nodePos = selectedNode.pos;
71
- } else {
72
- // Try to find parent node (including list parents)
73
- var parentNode = findParentNodeOfType([nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.listItem, nodes.taskItem, nodes.layoutSection])(selection);
74
- if (parentNode) {
75
- nodeToFormat = parentNode.node;
76
- nodePos = parentNode.pos;
77
- var paragraphOrHeadingNode = findParentNodeOfType([nodes.paragraph, nodes.heading])(selection);
78
- // Special case: if we found a listItem, check if we need the parent list instead
79
- if (parentNode.node.type === nodes.listItem || parentNode.node.type === nodes.taskItem) {
80
- var listParent = findParentNodeOfType([nodes.bulletList, nodes.orderedList, nodes.taskList])(selection);
81
- if (listParent) {
82
- // For list transformations, we want the list parent, not the listItem
83
- nodeToFormat = listParent.node;
84
- nodePos = listParent.pos;
69
+ // Try to find the current node from selection
70
+ var selectedNode = findSelectedNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection])(selection);
71
+ if (selectedNode) {
72
+ nodeToFormat = selectedNode.node;
73
+ nodePos = selectedNode.pos;
74
+ } else {
75
+ // Try to find parent node (including list parents)
76
+ var parentNode = findParentNodeOfType([nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.listItem, nodes.taskItem, nodes.layoutSection])(selection);
77
+ if (parentNode) {
78
+ nodeToFormat = parentNode.node;
79
+ nodePos = parentNode.pos;
80
+ var paragraphOrHeadingNode = findParentNodeOfType([nodes.paragraph, nodes.heading])(selection);
81
+ // Special case: if we found a listItem, check if we need the parent list instead
82
+ if (parentNode.node.type === nodes.listItem || parentNode.node.type === nodes.taskItem) {
83
+ var listParent = findParentNodeOfType([nodes.bulletList, nodes.orderedList, nodes.taskList])(selection);
84
+ if (listParent) {
85
+ // For list transformations, we want the list parent, not the listItem
86
+ nodeToFormat = listParent.node;
87
+ nodePos = listParent.pos;
88
+ }
89
+ } else if (parentNode.node.type !== nodes.blockquote && paragraphOrHeadingNode) {
90
+ nodeToFormat = paragraphOrHeadingNode.node;
91
+ nodePos = paragraphOrHeadingNode.pos;
85
92
  }
86
- } else if (parentNode.node.type !== nodes.blockquote && paragraphOrHeadingNode) {
87
- nodeToFormat = paragraphOrHeadingNode.node;
88
- nodePos = paragraphOrHeadingNode.pos;
89
93
  }
90
94
  }
91
- }
92
- if (!nodeToFormat) {
93
- nodeToFormat = selection.$from.node();
94
- nodePos = selection.$from.pos;
95
- }
96
- try {
97
- var newTr = transformNodeToTargetType(tr, nodeToFormat, nodePos, targetType);
98
- if (newTr && fg('platform_editor_block_menu_selection_fix')) {
99
- return setSelectionAfterTransform(newTr, nodePos, targetType);
95
+ if (!nodeToFormat) {
96
+ nodeToFormat = selection.$from.node();
97
+ nodePos = selection.$from.pos;
100
98
  }
101
- return newTr;
102
- } catch (_unused) {
103
- return null;
104
- }
99
+ try {
100
+ var _nodeToFormat$attrs;
101
+ var newTr = transformNodeToTargetType(tr, nodeToFormat, nodePos, targetType);
102
+ var sourceTypeName = nodeToFormat.type.name;
103
+ if (sourceTypeName === 'heading' && (_nodeToFormat$attrs = nodeToFormat.attrs) !== null && _nodeToFormat$attrs !== void 0 && _nodeToFormat$attrs.level) {
104
+ sourceTypeName = "heading".concat(nodeToFormat.attrs.level);
105
+ }
106
+ if (newTr && sourceTypeName !== targetType) {
107
+ var _api$analytics;
108
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent({
109
+ action: ACTION.CONVERTED,
110
+ actionSubject: ACTION_SUBJECT.ELEMENT,
111
+ eventType: EVENT_TYPE.TRACK,
112
+ attributes: {
113
+ from: sourceTypeName,
114
+ to: targetType,
115
+ inputMethod: INPUT_METHOD.BLOCK_MENU
116
+ }
117
+ })(newTr);
118
+ }
119
+ if (newTr && fg('platform_editor_block_menu_selection_fix')) {
120
+ return setSelectionAfterTransform(newTr, nodePos, targetType);
121
+ }
122
+ return newTr;
123
+ } catch (_unused) {
124
+ return null;
125
+ }
126
+ };
105
127
  };
106
128
  };
@@ -1,7 +1,9 @@
1
- import type { EditorCommand } from '@atlaskit/editor-common/types';
1
+ import type { EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { BlockMenuPlugin } from '../blockMenuPluginType';
2
3
  import type { FormatNodeTargetType } from './transforms/types';
3
4
  /**
4
5
  * Formats the current node or selection to the specified target type
6
+ * @param api - The editor API injection that provides access to analytics and other plugin actions
5
7
  * @param targetType - The target node type to convert to
6
8
  */
7
- export declare const formatNode: (targetType: FormatNodeTargetType) => EditorCommand;
9
+ export declare const formatNode: (api?: ExtractInjectionAPI<BlockMenuPlugin>) => (targetType: FormatNodeTargetType) => EditorCommand;
@@ -1,7 +1,9 @@
1
- import type { EditorCommand } from '@atlaskit/editor-common/types';
1
+ import type { EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { BlockMenuPlugin } from '../blockMenuPluginType';
2
3
  import type { FormatNodeTargetType } from './transforms/types';
3
4
  /**
4
5
  * Formats the current node or selection to the specified target type
6
+ * @param api - The editor API injection that provides access to analytics and other plugin actions
5
7
  * @param targetType - The target node type to convert to
6
8
  */
7
- export declare const formatNode: (targetType: FormatNodeTargetType) => EditorCommand;
9
+ export declare const formatNode: (api?: ExtractInjectionAPI<BlockMenuPlugin>) => (targetType: FormatNodeTargetType) => EditorCommand;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -30,6 +30,7 @@
30
30
  "dependencies": {
31
31
  "@atlaskit/css": "^0.14.0",
32
32
  "@atlaskit/dropdown-menu": "^16.3.0",
33
+ "@atlaskit/editor-plugin-analytics": "^6.0.0",
33
34
  "@atlaskit/editor-plugin-block-controls": "^7.1.0",
34
35
  "@atlaskit/editor-plugin-decorations": "^6.1.0",
35
36
  "@atlaskit/editor-plugin-selection": "^6.0.0",
@@ -43,11 +44,11 @@
43
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
44
45
  "@atlaskit/primitives": "^14.15.0",
45
46
  "@atlaskit/tmp-editor-statsig": "^12.32.0",
46
- "@atlaskit/tokens": "^6.3.0",
47
+ "@atlaskit/tokens": "^6.4.0",
47
48
  "@babel/runtime": "^7.0.0"
48
49
  },
49
50
  "peerDependencies": {
50
- "@atlaskit/editor-common": "^110.1.0",
51
+ "@atlaskit/editor-common": "^110.2.0",
51
52
  "react": "^18.2.0",
52
53
  "react-intl-next": "npm:react-intl@^5.18.1"
53
54
  },