@atlaskit/editor-plugin-block-menu 4.0.4 → 4.0.5
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 +9 -0
- package/dist/cjs/blockMenuPlugin.js +2 -2
- package/dist/cjs/editor-commands/formatNode.js +74 -16
- package/dist/es2019/blockMenuPlugin.js +2 -2
- package/dist/es2019/editor-commands/formatNode.js +64 -6
- package/dist/esm/blockMenuPlugin.js +2 -2
- package/dist/esm/editor-commands/formatNode.js +74 -16
- package/dist/types/blockMenuPluginType.d.ts +2 -2
- package/dist/types/editor-commands/formatNode.d.ts +3 -2
- package/dist/types/editor-commands/transforms/types.d.ts +5 -0
- package/dist/types-ts4.5/blockMenuPluginType.d.ts +2 -2
- package/dist/types-ts4.5/editor-commands/formatNode.d.ts +3 -2
- package/dist/types-ts4.5/editor-commands/transforms/types.d.ts +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 4.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`51d46145cda56`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/51d46145cda56) -
|
|
8
|
+
Adds additional attributes to Element Converted event and fires the event for the empty line
|
|
9
|
+
transforms
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
3
12
|
## 4.0.4
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -37,8 +37,8 @@ var blockMenuPlugin = exports.blockMenuPlugin = function blockMenuPlugin(_ref) {
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
commands: {
|
|
40
|
-
formatNode: function formatNode(targetType) {
|
|
41
|
-
return (0, _formatNode2.formatNode)(api)(targetType);
|
|
40
|
+
formatNode: function formatNode(targetType, analyticsAttrs) {
|
|
41
|
+
return (0, _formatNode2.formatNode)(api)(targetType, analyticsAttrs);
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -8,6 +8,7 @@ var _analytics = require("@atlaskit/editor-common/analytics");
|
|
|
8
8
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
9
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
10
10
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
11
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
11
12
|
var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
|
|
12
13
|
var _selection = require("./selection");
|
|
13
14
|
var _layoutTransforms = require("./transforms/layout-transforms");
|
|
@@ -92,9 +93,10 @@ var formatNodeSelectEmptyList = exports.formatNodeSelectEmptyList = function for
|
|
|
92
93
|
* Formats the current node or selection to the specified target type
|
|
93
94
|
* @param api - The editor API injection that provides access to analytics and other plugin actions
|
|
94
95
|
* @param targetType - The target node type to convert to
|
|
96
|
+
* @param analyticsAttrs - Attributes required for formatNode analytics like: inputMethod and triggeredFrom
|
|
95
97
|
*/
|
|
96
98
|
var formatNode = exports.formatNode = function formatNode(api) {
|
|
97
|
-
return function (targetType) {
|
|
99
|
+
return function (targetType, analyticsAttrs) {
|
|
98
100
|
return function (_ref) {
|
|
99
101
|
var tr = _ref.tr;
|
|
100
102
|
var selection = tr.selection;
|
|
@@ -123,9 +125,64 @@ var formatNode = exports.formatNode = function formatNode(api) {
|
|
|
123
125
|
// can only select one list at a time, so we just need to find the first one
|
|
124
126
|
if (listNodes.length > 0 && (0, _platformFeatureFlags.fg)('platform_editor_block_menu_patch_2')) {
|
|
125
127
|
var firstChild = listNodes[0];
|
|
126
|
-
|
|
128
|
+
var newTr = formatNodeSelectEmptyList(tr, targetType, firstChild, schema);
|
|
129
|
+
if (newTr) {
|
|
130
|
+
var _api$analytics;
|
|
131
|
+
var sourceTypeName = firstChild.node.type.name;
|
|
132
|
+
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({
|
|
133
|
+
action: _analytics.ACTION.CONVERTED,
|
|
134
|
+
actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
|
|
135
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
136
|
+
attributes: {
|
|
137
|
+
from: sourceTypeName,
|
|
138
|
+
to: targetType,
|
|
139
|
+
inputMethod: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.inputMethod) || _analytics.INPUT_METHOD.MOUSE,
|
|
140
|
+
triggeredFrom: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.triggeredFrom) || _analytics.INPUT_METHOD.BLOCK_MENU,
|
|
141
|
+
conversionSource: 'emptyList'
|
|
142
|
+
}
|
|
143
|
+
})(newTr);
|
|
144
|
+
}
|
|
145
|
+
return newTr;
|
|
127
146
|
} else {
|
|
128
|
-
|
|
147
|
+
var _newTr = formatNodeWhenSelectionEmpty(tr, targetType, nodePos, schema);
|
|
148
|
+
var allowedNodes = [nodes.blockquote, nodes.panel, nodes.codeBlock];
|
|
149
|
+
if ((0, _expValEquals.expValEquals)('platform_editor_block_menu_layout_format', 'isEnabled', true)) {
|
|
150
|
+
allowedNodes.push(nodes.layoutSection);
|
|
151
|
+
}
|
|
152
|
+
if ((0, _expValEquals.expValEquals)('platform_editor_block_menu_expand_format', 'isEnabled', true)) {
|
|
153
|
+
allowedNodes.push(nodes.expand);
|
|
154
|
+
}
|
|
155
|
+
var _sourceTypeName = 'paragraph';
|
|
156
|
+
var conversionSource;
|
|
157
|
+
var containerNode = (0, _utils.findParentNodeOfType)(allowedNodes)(selection);
|
|
158
|
+
var paragraphOrHeading = (0, _utils.findParentNodeOfType)([nodes.heading, nodes.paragraph])(selection);
|
|
159
|
+
if (containerNode) {
|
|
160
|
+
// At the moment this branch is executed for converstions from an empty blockquote
|
|
161
|
+
_sourceTypeName = containerNode.node.type.name;
|
|
162
|
+
conversionSource = undefined; // could be 'emptyNode' or something else
|
|
163
|
+
} else if (paragraphOrHeading) {
|
|
164
|
+
_sourceTypeName = paragraphOrHeading.node.type.name;
|
|
165
|
+
if (_sourceTypeName === 'heading') {
|
|
166
|
+
_sourceTypeName = "heading".concat(paragraphOrHeading.node.attrs.level);
|
|
167
|
+
}
|
|
168
|
+
conversionSource = 'emptyLine';
|
|
169
|
+
}
|
|
170
|
+
if (_newTr) {
|
|
171
|
+
var _api$analytics2;
|
|
172
|
+
api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || (_api$analytics2 = _api$analytics2.actions) === null || _api$analytics2 === void 0 || _api$analytics2.attachAnalyticsEvent({
|
|
173
|
+
action: _analytics.ACTION.CONVERTED,
|
|
174
|
+
actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
|
|
175
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
176
|
+
attributes: {
|
|
177
|
+
from: _sourceTypeName,
|
|
178
|
+
to: targetType,
|
|
179
|
+
inputMethod: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.inputMethod) || _analytics.INPUT_METHOD.MOUSE,
|
|
180
|
+
triggeredFrom: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.triggeredFrom) || _analytics.INPUT_METHOD.BLOCK_MENU,
|
|
181
|
+
conversionSource: conversionSource
|
|
182
|
+
}
|
|
183
|
+
})(_newTr);
|
|
184
|
+
}
|
|
185
|
+
return _newTr;
|
|
129
186
|
}
|
|
130
187
|
}
|
|
131
188
|
|
|
@@ -161,28 +218,29 @@ var formatNode = exports.formatNode = function formatNode(api) {
|
|
|
161
218
|
}
|
|
162
219
|
try {
|
|
163
220
|
var _nodeToFormat$attrs;
|
|
164
|
-
var
|
|
165
|
-
var
|
|
166
|
-
if (
|
|
167
|
-
|
|
221
|
+
var _newTr2 = (0, _transformNodeToTargetType.transformNodeToTargetType)(tr, nodeToFormat, nodePos, targetType);
|
|
222
|
+
var _sourceTypeName2 = nodeToFormat.type.name;
|
|
223
|
+
if (_sourceTypeName2 === 'heading' && (_nodeToFormat$attrs = nodeToFormat.attrs) !== null && _nodeToFormat$attrs !== void 0 && _nodeToFormat$attrs.level) {
|
|
224
|
+
_sourceTypeName2 = "heading".concat(nodeToFormat.attrs.level);
|
|
168
225
|
}
|
|
169
|
-
if (
|
|
170
|
-
var _api$
|
|
171
|
-
api === null || api === void 0 || (_api$
|
|
226
|
+
if (_newTr2 && _sourceTypeName2 !== targetType) {
|
|
227
|
+
var _api$analytics3;
|
|
228
|
+
api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || (_api$analytics3 = _api$analytics3.actions) === null || _api$analytics3 === void 0 || _api$analytics3.attachAnalyticsEvent({
|
|
172
229
|
action: _analytics.ACTION.CONVERTED,
|
|
173
230
|
actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
|
|
174
231
|
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
175
232
|
attributes: {
|
|
176
|
-
from:
|
|
233
|
+
from: _sourceTypeName2,
|
|
177
234
|
to: targetType,
|
|
178
|
-
inputMethod: _analytics.INPUT_METHOD.
|
|
235
|
+
inputMethod: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.inputMethod) || _analytics.INPUT_METHOD.MOUSE,
|
|
236
|
+
triggeredFrom: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.triggeredFrom) || _analytics.INPUT_METHOD.BLOCK_MENU
|
|
179
237
|
}
|
|
180
|
-
})(
|
|
238
|
+
})(_newTr2);
|
|
181
239
|
}
|
|
182
|
-
if (
|
|
183
|
-
return (0, _selection.setSelectionAfterTransform)(
|
|
240
|
+
if (_newTr2 && (0, _platformFeatureFlags.fg)('platform_editor_block_menu_selection_fix')) {
|
|
241
|
+
return (0, _selection.setSelectionAfterTransform)(_newTr2, nodePos, targetType);
|
|
184
242
|
}
|
|
185
|
-
return
|
|
243
|
+
return _newTr2;
|
|
186
244
|
} catch (_unused) {
|
|
187
245
|
return null;
|
|
188
246
|
}
|
|
@@ -31,8 +31,8 @@ export const blockMenuPlugin = ({
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
commands: {
|
|
34
|
-
formatNode: targetType => {
|
|
35
|
-
return formatNode(api)(targetType);
|
|
34
|
+
formatNode: (targetType, analyticsAttrs) => {
|
|
35
|
+
return formatNode(api)(targetType, analyticsAttrs);
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
getSharedState(editorState) {
|
|
@@ -2,6 +2,7 @@ import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/edit
|
|
|
2
2
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { findParentNodeOfType, findSelectedNodeOfType, safeInsert as pmSafeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
4
4
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
5
6
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
6
7
|
import { setSelectionAfterTransform } from './selection';
|
|
7
8
|
import { createDefaultLayoutSection } from './transforms/layout-transforms';
|
|
@@ -93,8 +94,9 @@ export const formatNodeSelectEmptyList = (tr, targetType, listNode, schema) => {
|
|
|
93
94
|
* Formats the current node or selection to the specified target type
|
|
94
95
|
* @param api - The editor API injection that provides access to analytics and other plugin actions
|
|
95
96
|
* @param targetType - The target node type to convert to
|
|
97
|
+
* @param analyticsAttrs - Attributes required for formatNode analytics like: inputMethod and triggeredFrom
|
|
96
98
|
*/
|
|
97
|
-
export const formatNode = api => targetType => {
|
|
99
|
+
export const formatNode = api => (targetType, analyticsAttrs) => {
|
|
98
100
|
return ({
|
|
99
101
|
tr
|
|
100
102
|
}) => {
|
|
@@ -128,9 +130,64 @@ export const formatNode = api => targetType => {
|
|
|
128
130
|
// can only select one list at a time, so we just need to find the first one
|
|
129
131
|
if (listNodes.length > 0 && fg('platform_editor_block_menu_patch_2')) {
|
|
130
132
|
const firstChild = listNodes[0];
|
|
131
|
-
|
|
133
|
+
const newTr = formatNodeSelectEmptyList(tr, targetType, firstChild, schema);
|
|
134
|
+
if (newTr) {
|
|
135
|
+
var _api$analytics, _api$analytics$action;
|
|
136
|
+
const sourceTypeName = firstChild.node.type.name;
|
|
137
|
+
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({
|
|
138
|
+
action: ACTION.CONVERTED,
|
|
139
|
+
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
140
|
+
eventType: EVENT_TYPE.TRACK,
|
|
141
|
+
attributes: {
|
|
142
|
+
from: sourceTypeName,
|
|
143
|
+
to: targetType,
|
|
144
|
+
inputMethod: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.inputMethod) || INPUT_METHOD.MOUSE,
|
|
145
|
+
triggeredFrom: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.triggeredFrom) || INPUT_METHOD.BLOCK_MENU,
|
|
146
|
+
conversionSource: 'emptyList'
|
|
147
|
+
}
|
|
148
|
+
})(newTr);
|
|
149
|
+
}
|
|
150
|
+
return newTr;
|
|
132
151
|
} else {
|
|
133
|
-
|
|
152
|
+
const newTr = formatNodeWhenSelectionEmpty(tr, targetType, nodePos, schema);
|
|
153
|
+
const allowedNodes = [nodes.blockquote, nodes.panel, nodes.codeBlock];
|
|
154
|
+
if (expValEquals('platform_editor_block_menu_layout_format', 'isEnabled', true)) {
|
|
155
|
+
allowedNodes.push(nodes.layoutSection);
|
|
156
|
+
}
|
|
157
|
+
if (expValEquals('platform_editor_block_menu_expand_format', 'isEnabled', true)) {
|
|
158
|
+
allowedNodes.push(nodes.expand);
|
|
159
|
+
}
|
|
160
|
+
let sourceTypeName = 'paragraph';
|
|
161
|
+
let conversionSource;
|
|
162
|
+
const containerNode = findParentNodeOfType(allowedNodes)(selection);
|
|
163
|
+
const paragraphOrHeading = findParentNodeOfType([nodes.heading, nodes.paragraph])(selection);
|
|
164
|
+
if (containerNode) {
|
|
165
|
+
// At the moment this branch is executed for converstions from an empty blockquote
|
|
166
|
+
sourceTypeName = containerNode.node.type.name;
|
|
167
|
+
conversionSource = undefined; // could be 'emptyNode' or something else
|
|
168
|
+
} else if (paragraphOrHeading) {
|
|
169
|
+
sourceTypeName = paragraphOrHeading.node.type.name;
|
|
170
|
+
if (sourceTypeName === 'heading') {
|
|
171
|
+
sourceTypeName = `heading${paragraphOrHeading.node.attrs.level}`;
|
|
172
|
+
}
|
|
173
|
+
conversionSource = 'emptyLine';
|
|
174
|
+
}
|
|
175
|
+
if (newTr) {
|
|
176
|
+
var _api$analytics2, _api$analytics2$actio;
|
|
177
|
+
api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : (_api$analytics2$actio = _api$analytics2.actions) === null || _api$analytics2$actio === void 0 ? void 0 : _api$analytics2$actio.attachAnalyticsEvent({
|
|
178
|
+
action: ACTION.CONVERTED,
|
|
179
|
+
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
180
|
+
eventType: EVENT_TYPE.TRACK,
|
|
181
|
+
attributes: {
|
|
182
|
+
from: sourceTypeName,
|
|
183
|
+
to: targetType,
|
|
184
|
+
inputMethod: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.inputMethod) || INPUT_METHOD.MOUSE,
|
|
185
|
+
triggeredFrom: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.triggeredFrom) || INPUT_METHOD.BLOCK_MENU,
|
|
186
|
+
conversionSource
|
|
187
|
+
}
|
|
188
|
+
})(newTr);
|
|
189
|
+
}
|
|
190
|
+
return newTr;
|
|
134
191
|
}
|
|
135
192
|
}
|
|
136
193
|
|
|
@@ -172,15 +229,16 @@ export const formatNode = api => targetType => {
|
|
|
172
229
|
sourceTypeName = `heading${nodeToFormat.attrs.level}`;
|
|
173
230
|
}
|
|
174
231
|
if (newTr && sourceTypeName !== targetType) {
|
|
175
|
-
var _api$
|
|
176
|
-
api === null || api === void 0 ? void 0 : (_api$
|
|
232
|
+
var _api$analytics3, _api$analytics3$actio;
|
|
233
|
+
api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : (_api$analytics3$actio = _api$analytics3.actions) === null || _api$analytics3$actio === void 0 ? void 0 : _api$analytics3$actio.attachAnalyticsEvent({
|
|
177
234
|
action: ACTION.CONVERTED,
|
|
178
235
|
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
179
236
|
eventType: EVENT_TYPE.TRACK,
|
|
180
237
|
attributes: {
|
|
181
238
|
from: sourceTypeName,
|
|
182
239
|
to: targetType,
|
|
183
|
-
inputMethod: INPUT_METHOD.
|
|
240
|
+
inputMethod: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.inputMethod) || INPUT_METHOD.MOUSE,
|
|
241
|
+
triggeredFrom: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.triggeredFrom) || INPUT_METHOD.BLOCK_MENU
|
|
184
242
|
}
|
|
185
243
|
})(newTr);
|
|
186
244
|
}
|
|
@@ -30,8 +30,8 @@ export var blockMenuPlugin = function blockMenuPlugin(_ref) {
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
commands: {
|
|
33
|
-
formatNode: function formatNode(targetType) {
|
|
34
|
-
return _formatNode(api)(targetType);
|
|
33
|
+
formatNode: function formatNode(targetType, analyticsAttrs) {
|
|
34
|
+
return _formatNode(api)(targetType, analyticsAttrs);
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -2,6 +2,7 @@ import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/edit
|
|
|
2
2
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { findParentNodeOfType, findSelectedNodeOfType, safeInsert as pmSafeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
4
4
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
5
6
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
6
7
|
import { setSelectionAfterTransform } from './selection';
|
|
7
8
|
import { createDefaultLayoutSection } from './transforms/layout-transforms';
|
|
@@ -87,9 +88,10 @@ export var formatNodeSelectEmptyList = function formatNodeSelectEmptyList(tr, ta
|
|
|
87
88
|
* Formats the current node or selection to the specified target type
|
|
88
89
|
* @param api - The editor API injection that provides access to analytics and other plugin actions
|
|
89
90
|
* @param targetType - The target node type to convert to
|
|
91
|
+
* @param analyticsAttrs - Attributes required for formatNode analytics like: inputMethod and triggeredFrom
|
|
90
92
|
*/
|
|
91
93
|
export var formatNode = function formatNode(api) {
|
|
92
|
-
return function (targetType) {
|
|
94
|
+
return function (targetType, analyticsAttrs) {
|
|
93
95
|
return function (_ref) {
|
|
94
96
|
var tr = _ref.tr;
|
|
95
97
|
var selection = tr.selection;
|
|
@@ -118,9 +120,64 @@ export var formatNode = function formatNode(api) {
|
|
|
118
120
|
// can only select one list at a time, so we just need to find the first one
|
|
119
121
|
if (listNodes.length > 0 && fg('platform_editor_block_menu_patch_2')) {
|
|
120
122
|
var firstChild = listNodes[0];
|
|
121
|
-
|
|
123
|
+
var newTr = formatNodeSelectEmptyList(tr, targetType, firstChild, schema);
|
|
124
|
+
if (newTr) {
|
|
125
|
+
var _api$analytics;
|
|
126
|
+
var sourceTypeName = firstChild.node.type.name;
|
|
127
|
+
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({
|
|
128
|
+
action: ACTION.CONVERTED,
|
|
129
|
+
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
130
|
+
eventType: EVENT_TYPE.TRACK,
|
|
131
|
+
attributes: {
|
|
132
|
+
from: sourceTypeName,
|
|
133
|
+
to: targetType,
|
|
134
|
+
inputMethod: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.inputMethod) || INPUT_METHOD.MOUSE,
|
|
135
|
+
triggeredFrom: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.triggeredFrom) || INPUT_METHOD.BLOCK_MENU,
|
|
136
|
+
conversionSource: 'emptyList'
|
|
137
|
+
}
|
|
138
|
+
})(newTr);
|
|
139
|
+
}
|
|
140
|
+
return newTr;
|
|
122
141
|
} else {
|
|
123
|
-
|
|
142
|
+
var _newTr = formatNodeWhenSelectionEmpty(tr, targetType, nodePos, schema);
|
|
143
|
+
var allowedNodes = [nodes.blockquote, nodes.panel, nodes.codeBlock];
|
|
144
|
+
if (expValEquals('platform_editor_block_menu_layout_format', 'isEnabled', true)) {
|
|
145
|
+
allowedNodes.push(nodes.layoutSection);
|
|
146
|
+
}
|
|
147
|
+
if (expValEquals('platform_editor_block_menu_expand_format', 'isEnabled', true)) {
|
|
148
|
+
allowedNodes.push(nodes.expand);
|
|
149
|
+
}
|
|
150
|
+
var _sourceTypeName = 'paragraph';
|
|
151
|
+
var conversionSource;
|
|
152
|
+
var containerNode = findParentNodeOfType(allowedNodes)(selection);
|
|
153
|
+
var paragraphOrHeading = findParentNodeOfType([nodes.heading, nodes.paragraph])(selection);
|
|
154
|
+
if (containerNode) {
|
|
155
|
+
// At the moment this branch is executed for converstions from an empty blockquote
|
|
156
|
+
_sourceTypeName = containerNode.node.type.name;
|
|
157
|
+
conversionSource = undefined; // could be 'emptyNode' or something else
|
|
158
|
+
} else if (paragraphOrHeading) {
|
|
159
|
+
_sourceTypeName = paragraphOrHeading.node.type.name;
|
|
160
|
+
if (_sourceTypeName === 'heading') {
|
|
161
|
+
_sourceTypeName = "heading".concat(paragraphOrHeading.node.attrs.level);
|
|
162
|
+
}
|
|
163
|
+
conversionSource = 'emptyLine';
|
|
164
|
+
}
|
|
165
|
+
if (_newTr) {
|
|
166
|
+
var _api$analytics2;
|
|
167
|
+
api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || (_api$analytics2 = _api$analytics2.actions) === null || _api$analytics2 === void 0 || _api$analytics2.attachAnalyticsEvent({
|
|
168
|
+
action: ACTION.CONVERTED,
|
|
169
|
+
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
170
|
+
eventType: EVENT_TYPE.TRACK,
|
|
171
|
+
attributes: {
|
|
172
|
+
from: _sourceTypeName,
|
|
173
|
+
to: targetType,
|
|
174
|
+
inputMethod: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.inputMethod) || INPUT_METHOD.MOUSE,
|
|
175
|
+
triggeredFrom: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.triggeredFrom) || INPUT_METHOD.BLOCK_MENU,
|
|
176
|
+
conversionSource: conversionSource
|
|
177
|
+
}
|
|
178
|
+
})(_newTr);
|
|
179
|
+
}
|
|
180
|
+
return _newTr;
|
|
124
181
|
}
|
|
125
182
|
}
|
|
126
183
|
|
|
@@ -156,28 +213,29 @@ export var formatNode = function formatNode(api) {
|
|
|
156
213
|
}
|
|
157
214
|
try {
|
|
158
215
|
var _nodeToFormat$attrs;
|
|
159
|
-
var
|
|
160
|
-
var
|
|
161
|
-
if (
|
|
162
|
-
|
|
216
|
+
var _newTr2 = transformNodeToTargetType(tr, nodeToFormat, nodePos, targetType);
|
|
217
|
+
var _sourceTypeName2 = nodeToFormat.type.name;
|
|
218
|
+
if (_sourceTypeName2 === 'heading' && (_nodeToFormat$attrs = nodeToFormat.attrs) !== null && _nodeToFormat$attrs !== void 0 && _nodeToFormat$attrs.level) {
|
|
219
|
+
_sourceTypeName2 = "heading".concat(nodeToFormat.attrs.level);
|
|
163
220
|
}
|
|
164
|
-
if (
|
|
165
|
-
var _api$
|
|
166
|
-
api === null || api === void 0 || (_api$
|
|
221
|
+
if (_newTr2 && _sourceTypeName2 !== targetType) {
|
|
222
|
+
var _api$analytics3;
|
|
223
|
+
api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || (_api$analytics3 = _api$analytics3.actions) === null || _api$analytics3 === void 0 || _api$analytics3.attachAnalyticsEvent({
|
|
167
224
|
action: ACTION.CONVERTED,
|
|
168
225
|
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
169
226
|
eventType: EVENT_TYPE.TRACK,
|
|
170
227
|
attributes: {
|
|
171
|
-
from:
|
|
228
|
+
from: _sourceTypeName2,
|
|
172
229
|
to: targetType,
|
|
173
|
-
inputMethod: INPUT_METHOD.
|
|
230
|
+
inputMethod: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.inputMethod) || INPUT_METHOD.MOUSE,
|
|
231
|
+
triggeredFrom: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.triggeredFrom) || INPUT_METHOD.BLOCK_MENU
|
|
174
232
|
}
|
|
175
|
-
})(
|
|
233
|
+
})(_newTr2);
|
|
176
234
|
}
|
|
177
|
-
if (
|
|
178
|
-
return setSelectionAfterTransform(
|
|
235
|
+
if (_newTr2 && fg('platform_editor_block_menu_selection_fix')) {
|
|
236
|
+
return setSelectionAfterTransform(_newTr2, nodePos, targetType);
|
|
179
237
|
}
|
|
180
|
-
return
|
|
238
|
+
return _newTr2;
|
|
181
239
|
} catch (_unused) {
|
|
182
240
|
return null;
|
|
183
241
|
}
|
|
@@ -4,14 +4,14 @@ import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls
|
|
|
4
4
|
import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
5
5
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
6
6
|
import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
|
|
7
|
-
import type { FormatNodeTargetType } from './editor-commands/transforms/types';
|
|
7
|
+
import type { FormatNodeTargetType, FormatNodeAnalyticsAttrs } from './editor-commands/transforms/types';
|
|
8
8
|
export type BlockMenuPlugin = NextEditorPlugin<'blockMenu', {
|
|
9
9
|
actions: {
|
|
10
10
|
getBlockMenuComponents: () => Array<RegisterBlockMenuComponent>;
|
|
11
11
|
registerBlockMenuComponents: (blockMenuComponents: Array<RegisterBlockMenuComponent>) => void;
|
|
12
12
|
};
|
|
13
13
|
commands: {
|
|
14
|
-
formatNode: (targetType: FormatNodeTargetType) => EditorCommand;
|
|
14
|
+
formatNode: (targetType: FormatNodeTargetType, analyticsAttrs?: FormatNodeAnalyticsAttrs) => EditorCommand;
|
|
15
15
|
};
|
|
16
16
|
dependencies: [
|
|
17
17
|
OptionalPlugin<BlockControlsPlugin>,
|
|
@@ -2,7 +2,7 @@ import type { EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common
|
|
|
2
2
|
import { type Schema, type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import { type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { BlockMenuPlugin } from '../blockMenuPluginType';
|
|
5
|
-
import type { FormatNodeTargetType } from './transforms/types';
|
|
5
|
+
import type { FormatNodeAnalyticsAttrs, FormatNodeTargetType } from './transforms/types';
|
|
6
6
|
/**
|
|
7
7
|
* Handles formatting when an empty list is selected
|
|
8
8
|
* Converting an empty list to a target node, will remove the list and replace with an empty target node
|
|
@@ -15,5 +15,6 @@ export declare const formatNodeSelectEmptyList: (tr: Transaction, targetType: Fo
|
|
|
15
15
|
* Formats the current node or selection to the specified target type
|
|
16
16
|
* @param api - The editor API injection that provides access to analytics and other plugin actions
|
|
17
17
|
* @param targetType - The target node type to convert to
|
|
18
|
+
* @param analyticsAttrs - Attributes required for formatNode analytics like: inputMethod and triggeredFrom
|
|
18
19
|
*/
|
|
19
|
-
export declare const formatNode: (api?: ExtractInjectionAPI<BlockMenuPlugin>) => (targetType: FormatNodeTargetType) => EditorCommand;
|
|
20
|
+
export declare const formatNode: (api?: ExtractInjectionAPI<BlockMenuPlugin>) => (targetType: FormatNodeTargetType, analyticsAttrs?: FormatNodeAnalyticsAttrs) => EditorCommand;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
1
2
|
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
2
3
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
4
|
export type FormatNodeTargetType = 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'blockquote' | 'expand' | 'layoutSection' | 'panel' | 'codeBlock' | 'bulletList' | 'orderedList' | 'taskList';
|
|
5
|
+
export type FormatNodeAnalyticsAttrs = {
|
|
6
|
+
inputMethod: INPUT_METHOD.MOUSE | INPUT_METHOD.KEYBOARD;
|
|
7
|
+
triggeredFrom: INPUT_METHOD.BLOCK_MENU;
|
|
8
|
+
};
|
|
4
9
|
export type TransformFunction = (context: TransformContext) => Transaction | null;
|
|
@@ -4,14 +4,14 @@ import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls
|
|
|
4
4
|
import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
5
5
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
6
6
|
import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
|
|
7
|
-
import type { FormatNodeTargetType } from './editor-commands/transforms/types';
|
|
7
|
+
import type { FormatNodeTargetType, FormatNodeAnalyticsAttrs } from './editor-commands/transforms/types';
|
|
8
8
|
export type BlockMenuPlugin = NextEditorPlugin<'blockMenu', {
|
|
9
9
|
actions: {
|
|
10
10
|
getBlockMenuComponents: () => Array<RegisterBlockMenuComponent>;
|
|
11
11
|
registerBlockMenuComponents: (blockMenuComponents: Array<RegisterBlockMenuComponent>) => void;
|
|
12
12
|
};
|
|
13
13
|
commands: {
|
|
14
|
-
formatNode: (targetType: FormatNodeTargetType) => EditorCommand;
|
|
14
|
+
formatNode: (targetType: FormatNodeTargetType, analyticsAttrs?: FormatNodeAnalyticsAttrs) => EditorCommand;
|
|
15
15
|
};
|
|
16
16
|
dependencies: [
|
|
17
17
|
OptionalPlugin<BlockControlsPlugin>,
|
|
@@ -2,7 +2,7 @@ import type { EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common
|
|
|
2
2
|
import { type Schema, type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import { type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { BlockMenuPlugin } from '../blockMenuPluginType';
|
|
5
|
-
import type { FormatNodeTargetType } from './transforms/types';
|
|
5
|
+
import type { FormatNodeAnalyticsAttrs, FormatNodeTargetType } from './transforms/types';
|
|
6
6
|
/**
|
|
7
7
|
* Handles formatting when an empty list is selected
|
|
8
8
|
* Converting an empty list to a target node, will remove the list and replace with an empty target node
|
|
@@ -15,5 +15,6 @@ export declare const formatNodeSelectEmptyList: (tr: Transaction, targetType: Fo
|
|
|
15
15
|
* Formats the current node or selection to the specified target type
|
|
16
16
|
* @param api - The editor API injection that provides access to analytics and other plugin actions
|
|
17
17
|
* @param targetType - The target node type to convert to
|
|
18
|
+
* @param analyticsAttrs - Attributes required for formatNode analytics like: inputMethod and triggeredFrom
|
|
18
19
|
*/
|
|
19
|
-
export declare const formatNode: (api?: ExtractInjectionAPI<BlockMenuPlugin>) => (targetType: FormatNodeTargetType) => EditorCommand;
|
|
20
|
+
export declare const formatNode: (api?: ExtractInjectionAPI<BlockMenuPlugin>) => (targetType: FormatNodeTargetType, analyticsAttrs?: FormatNodeAnalyticsAttrs) => EditorCommand;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
1
2
|
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
2
3
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
4
|
export type FormatNodeTargetType = 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'blockquote' | 'expand' | 'layoutSection' | 'panel' | 'codeBlock' | 'bulletList' | 'orderedList' | 'taskList';
|
|
5
|
+
export type FormatNodeAnalyticsAttrs = {
|
|
6
|
+
inputMethod: INPUT_METHOD.MOUSE | INPUT_METHOD.KEYBOARD;
|
|
7
|
+
triggeredFrom: INPUT_METHOD.BLOCK_MENU;
|
|
8
|
+
};
|
|
4
9
|
export type TransformFunction = (context: TransformContext) => Transaction | null;
|