@atlaskit/editor-plugin-block-menu 4.0.21 → 4.0.22
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 +8 -0
- package/dist/cjs/editor-commands/formatNode.js +29 -1
- package/dist/cjs/editor-commands/transforms/transformNodeToTargetType.js +29 -24
- package/dist/cjs/ui/block-menu.js +8 -2
- package/dist/es2019/editor-commands/formatNode.js +30 -2
- package/dist/es2019/editor-commands/transforms/transformNodeToTargetType.js +30 -24
- package/dist/es2019/ui/block-menu.js +8 -2
- package/dist/esm/editor-commands/formatNode.js +30 -2
- package/dist/esm/editor-commands/transforms/transformNodeToTargetType.js +30 -24
- package/dist/esm/ui/block-menu.js +8 -2
- package/dist/types/editor-commands/transforms/transformNodeToTargetType.d.ts +10 -0
- package/dist/types-ts4.5/editor-commands/transforms/transformNodeToTargetType.d.ts +10 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 4.0.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`3c7b7f4449751`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3c7b7f4449751) -
|
|
8
|
+
Add error observability for block menu
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 4.0.21
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.formatNodeSelectEmptyList = exports.formatNode = void 0;
|
|
7
7
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
|
+
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
8
9
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
10
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
10
11
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
@@ -244,7 +245,34 @@ var formatNode = exports.formatNode = function formatNode(api) {
|
|
|
244
245
|
return (0, _selection.setSelectionAfterTransform)(_newTr2, nodePos, targetType);
|
|
245
246
|
}
|
|
246
247
|
return _newTr2;
|
|
247
|
-
} catch (
|
|
248
|
+
} catch (error) {
|
|
249
|
+
var _nodeToFormat$attrs2, _api$analytics4;
|
|
250
|
+
(0, _monitoring.logException)(error, {
|
|
251
|
+
location: 'editor-plugin-block-menu'
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// Fire error analytics event
|
|
255
|
+
var _sourceTypeName3 = nodeToFormat.type.name;
|
|
256
|
+
if (_sourceTypeName3 === 'heading' && (_nodeToFormat$attrs2 = nodeToFormat.attrs) !== null && _nodeToFormat$attrs2 !== void 0 && _nodeToFormat$attrs2.level) {
|
|
257
|
+
_sourceTypeName3 = "heading".concat(nodeToFormat.attrs.level);
|
|
258
|
+
}
|
|
259
|
+
api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 || (_api$analytics4 = _api$analytics4.actions) === null || _api$analytics4 === void 0 || _api$analytics4.fireAnalyticsEvent({
|
|
260
|
+
action: _analytics.ACTION.ERRORED,
|
|
261
|
+
actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
|
|
262
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.TRANSFORM,
|
|
263
|
+
eventType: _analytics.EVENT_TYPE.OPERATIONAL,
|
|
264
|
+
attributes: {
|
|
265
|
+
error: error.message,
|
|
266
|
+
errorStack: error.stack,
|
|
267
|
+
docSize: tr.doc.nodeSize,
|
|
268
|
+
from: _sourceTypeName3,
|
|
269
|
+
to: targetType,
|
|
270
|
+
position: tr.selection.from,
|
|
271
|
+
selection: tr.selection.toJSON(),
|
|
272
|
+
inputMethod: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.inputMethod) || _analytics.INPUT_METHOD.BLOCK_MENU,
|
|
273
|
+
triggeredFrom: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.triggeredFrom) || _analytics.INPUT_METHOD.MOUSE
|
|
274
|
+
}
|
|
275
|
+
});
|
|
248
276
|
return null;
|
|
249
277
|
}
|
|
250
278
|
};
|
|
@@ -9,6 +9,16 @@ var _containerTransforms = require("./container-transforms");
|
|
|
9
9
|
var _layoutTransforms = require("./layout-transforms");
|
|
10
10
|
var _listTransforms = require("./list-transforms");
|
|
11
11
|
var _utils = require("./utils");
|
|
12
|
+
/**
|
|
13
|
+
* Transforms a source node to the specified target type.
|
|
14
|
+
* Throws errors on failure which should be caught at the command level.
|
|
15
|
+
*
|
|
16
|
+
* @param tr - The transaction to apply transformations to
|
|
17
|
+
* @param sourceNode - The node to transform
|
|
18
|
+
* @param sourcePos - The position of the source node in the document
|
|
19
|
+
* @param targetType - The target node type to transform to
|
|
20
|
+
* @returns The modified transaction if successful, null if transformation is not possible
|
|
21
|
+
*/
|
|
12
22
|
function transformNodeToTargetType(tr, sourceNode, sourcePos, targetType) {
|
|
13
23
|
var nodes = tr.doc.type.schema.nodes;
|
|
14
24
|
var targetNodeInfo = (0, _utils.getTargetNodeInfo)(targetType, nodes);
|
|
@@ -43,30 +53,25 @@ function transformNodeToTargetType(tr, sourceNode, sourcePos, targetType) {
|
|
|
43
53
|
};
|
|
44
54
|
|
|
45
55
|
// Route to appropriate transformation strategy based on source node type
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
56
|
+
if ((0, _utils.isLayoutNodeType)(targetNodeType)) {
|
|
57
|
+
return (0, _layoutTransforms.convertToLayout)(transformationContext);
|
|
58
|
+
}
|
|
50
59
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
} catch (_unused) {
|
|
69
|
-
// Node transformation failed
|
|
70
|
-
return null;
|
|
60
|
+
// special case codeblock to listType
|
|
61
|
+
if (sourceNode.type.name === 'codeBlock' && (0, _utils.isListNodeType)(targetNodeType)) {
|
|
62
|
+
return (0, _containerTransforms.unwrapAndConvertToList)(transformationContext);
|
|
63
|
+
}
|
|
64
|
+
if ((0, _utils.isLayoutNode)(sourceNode)) {
|
|
65
|
+
return (0, _layoutTransforms.transformLayoutNode)(transformationContext);
|
|
66
|
+
}
|
|
67
|
+
if ((0, _utils.isBlockNode)(sourceNode)) {
|
|
68
|
+
return (0, _blockTransforms.transformBlockNode)(transformationContext);
|
|
69
|
+
}
|
|
70
|
+
if ((0, _utils.isListNode)(sourceNode)) {
|
|
71
|
+
return (0, _listTransforms.transformListNode)(transformationContext);
|
|
72
|
+
}
|
|
73
|
+
if ((0, _utils.isContainerNode)(sourceNode)) {
|
|
74
|
+
return (0, _containerTransforms.transformContainerNode)(transformationContext);
|
|
71
75
|
}
|
|
76
|
+
return null;
|
|
72
77
|
}
|
|
@@ -12,6 +12,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
12
12
|
var _reactIntlNext = require("react-intl-next");
|
|
13
13
|
var _css = require("@atlaskit/css");
|
|
14
14
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
15
|
+
var _errorBoundary = require("@atlaskit/editor-common/error-boundary");
|
|
15
16
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
16
17
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
17
18
|
var _ui = require("@atlaskit/editor-common/ui");
|
|
@@ -147,7 +148,12 @@ var BlockMenu = function BlockMenu(_ref2) {
|
|
|
147
148
|
}
|
|
148
149
|
};
|
|
149
150
|
if (targetHandleRef instanceof HTMLElement) {
|
|
150
|
-
|
|
151
|
+
var _api$analytics2;
|
|
152
|
+
return /*#__PURE__*/_react.default.createElement(_errorBoundary.ErrorBoundary, {
|
|
153
|
+
component: _analytics.ACTION_SUBJECT.BLOCK_MENU,
|
|
154
|
+
dispatchAnalyticsEvent: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent,
|
|
155
|
+
fallbackComponent: null
|
|
156
|
+
}, /*#__PURE__*/_react.default.createElement(PopupWithListeners, {
|
|
151
157
|
alignX: 'right',
|
|
152
158
|
alignY: 'start' // respected when forcePlacement is true
|
|
153
159
|
,
|
|
@@ -170,7 +176,7 @@ var BlockMenu = function BlockMenu(_ref2) {
|
|
|
170
176
|
}, /*#__PURE__*/_react.default.createElement(BlockMenuContent, {
|
|
171
177
|
api: api,
|
|
172
178
|
setRef: (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu_keyboard_navigation', 'isEnabled', true) ? setRef : undefined
|
|
173
|
-
}));
|
|
179
|
+
})));
|
|
174
180
|
} else {
|
|
175
181
|
return null;
|
|
176
182
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
2
3
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
4
|
import { findParentNodeOfType, findSelectedNodeOfType, safeInsert as pmSafeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
4
5
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -249,7 +250,34 @@ export const formatNode = api => (targetType, analyticsAttrs) => {
|
|
|
249
250
|
return setSelectionAfterTransform(newTr, nodePos, targetType);
|
|
250
251
|
}
|
|
251
252
|
return newTr;
|
|
252
|
-
} catch {
|
|
253
|
+
} catch (error) {
|
|
254
|
+
var _nodeToFormat$attrs2, _api$analytics4, _api$analytics4$actio;
|
|
255
|
+
logException(error, {
|
|
256
|
+
location: 'editor-plugin-block-menu'
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// Fire error analytics event
|
|
260
|
+
let sourceTypeName = nodeToFormat.type.name;
|
|
261
|
+
if (sourceTypeName === 'heading' && (_nodeToFormat$attrs2 = nodeToFormat.attrs) !== null && _nodeToFormat$attrs2 !== void 0 && _nodeToFormat$attrs2.level) {
|
|
262
|
+
sourceTypeName = `heading${nodeToFormat.attrs.level}`;
|
|
263
|
+
}
|
|
264
|
+
api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : (_api$analytics4$actio = _api$analytics4.actions) === null || _api$analytics4$actio === void 0 ? void 0 : _api$analytics4$actio.fireAnalyticsEvent({
|
|
265
|
+
action: ACTION.ERRORED,
|
|
266
|
+
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
267
|
+
actionSubjectId: ACTION_SUBJECT_ID.TRANSFORM,
|
|
268
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
269
|
+
attributes: {
|
|
270
|
+
error: error.message,
|
|
271
|
+
errorStack: error.stack,
|
|
272
|
+
docSize: tr.doc.nodeSize,
|
|
273
|
+
from: sourceTypeName,
|
|
274
|
+
to: targetType,
|
|
275
|
+
position: tr.selection.from,
|
|
276
|
+
selection: tr.selection.toJSON(),
|
|
277
|
+
inputMethod: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.inputMethod) || INPUT_METHOD.BLOCK_MENU,
|
|
278
|
+
triggeredFrom: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.triggeredFrom) || INPUT_METHOD.MOUSE
|
|
279
|
+
}
|
|
280
|
+
});
|
|
253
281
|
return null;
|
|
254
282
|
}
|
|
255
283
|
};
|
|
@@ -3,6 +3,17 @@ import { transformContainerNode, unwrapAndConvertToList } from './container-tran
|
|
|
3
3
|
import { convertToLayout, transformLayoutNode } from './layout-transforms';
|
|
4
4
|
import { transformListNode } from './list-transforms';
|
|
5
5
|
import { getTargetNodeInfo, isBlockNode, isListNode, isListNodeType, isContainerNode, isLayoutNodeType, isLayoutNode } from './utils';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Transforms a source node to the specified target type.
|
|
9
|
+
* Throws errors on failure which should be caught at the command level.
|
|
10
|
+
*
|
|
11
|
+
* @param tr - The transaction to apply transformations to
|
|
12
|
+
* @param sourceNode - The node to transform
|
|
13
|
+
* @param sourcePos - The position of the source node in the document
|
|
14
|
+
* @param targetType - The target node type to transform to
|
|
15
|
+
* @returns The modified transaction if successful, null if transformation is not possible
|
|
16
|
+
*/
|
|
6
17
|
export function transformNodeToTargetType(tr, sourceNode, sourcePos, targetType) {
|
|
7
18
|
const {
|
|
8
19
|
nodes
|
|
@@ -41,30 +52,25 @@ export function transformNodeToTargetType(tr, sourceNode, sourcePos, targetType)
|
|
|
41
52
|
};
|
|
42
53
|
|
|
43
54
|
// Route to appropriate transformation strategy based on source node type
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
55
|
+
if (isLayoutNodeType(targetNodeType)) {
|
|
56
|
+
return convertToLayout(transformationContext);
|
|
57
|
+
}
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
} catch {
|
|
67
|
-
// Node transformation failed
|
|
68
|
-
return null;
|
|
59
|
+
// special case codeblock to listType
|
|
60
|
+
if (sourceNode.type.name === 'codeBlock' && isListNodeType(targetNodeType)) {
|
|
61
|
+
return unwrapAndConvertToList(transformationContext);
|
|
62
|
+
}
|
|
63
|
+
if (isLayoutNode(sourceNode)) {
|
|
64
|
+
return transformLayoutNode(transformationContext);
|
|
65
|
+
}
|
|
66
|
+
if (isBlockNode(sourceNode)) {
|
|
67
|
+
return transformBlockNode(transformationContext);
|
|
68
|
+
}
|
|
69
|
+
if (isListNode(sourceNode)) {
|
|
70
|
+
return transformListNode(transformationContext);
|
|
71
|
+
}
|
|
72
|
+
if (isContainerNode(sourceNode)) {
|
|
73
|
+
return transformContainerNode(transformationContext);
|
|
69
74
|
}
|
|
75
|
+
return null;
|
|
70
76
|
}
|
|
@@ -5,6 +5,7 @@ import React, { useContext, useEffect, useRef } from 'react';
|
|
|
5
5
|
import { injectIntl } from 'react-intl-next';
|
|
6
6
|
import { cx } from '@atlaskit/css';
|
|
7
7
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
8
|
+
import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
|
|
8
9
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
9
10
|
import { DRAG_HANDLE_SELECTOR, DRAG_HANDLE_WIDTH } from '@atlaskit/editor-common/styles';
|
|
10
11
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
@@ -138,7 +139,12 @@ const BlockMenu = ({
|
|
|
138
139
|
}
|
|
139
140
|
};
|
|
140
141
|
if (targetHandleRef instanceof HTMLElement) {
|
|
141
|
-
|
|
142
|
+
var _api$analytics2;
|
|
143
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
144
|
+
component: ACTION_SUBJECT.BLOCK_MENU,
|
|
145
|
+
dispatchAnalyticsEvent: api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent,
|
|
146
|
+
fallbackComponent: null
|
|
147
|
+
}, /*#__PURE__*/React.createElement(PopupWithListeners, {
|
|
142
148
|
alignX: 'right',
|
|
143
149
|
alignY: 'start' // respected when forcePlacement is true
|
|
144
150
|
,
|
|
@@ -161,7 +167,7 @@ const BlockMenu = ({
|
|
|
161
167
|
}, /*#__PURE__*/React.createElement(BlockMenuContent, {
|
|
162
168
|
api: api,
|
|
163
169
|
setRef: expValEqualsNoExposure('platform_editor_block_menu_keyboard_navigation', 'isEnabled', true) ? setRef : undefined
|
|
164
|
-
}));
|
|
170
|
+
})));
|
|
165
171
|
} else {
|
|
166
172
|
return null;
|
|
167
173
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
2
3
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
4
|
import { findParentNodeOfType, findSelectedNodeOfType, safeInsert as pmSafeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
4
5
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -239,7 +240,34 @@ export var formatNode = function formatNode(api) {
|
|
|
239
240
|
return setSelectionAfterTransform(_newTr2, nodePos, targetType);
|
|
240
241
|
}
|
|
241
242
|
return _newTr2;
|
|
242
|
-
} catch (
|
|
243
|
+
} catch (error) {
|
|
244
|
+
var _nodeToFormat$attrs2, _api$analytics4;
|
|
245
|
+
logException(error, {
|
|
246
|
+
location: 'editor-plugin-block-menu'
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// Fire error analytics event
|
|
250
|
+
var _sourceTypeName3 = nodeToFormat.type.name;
|
|
251
|
+
if (_sourceTypeName3 === 'heading' && (_nodeToFormat$attrs2 = nodeToFormat.attrs) !== null && _nodeToFormat$attrs2 !== void 0 && _nodeToFormat$attrs2.level) {
|
|
252
|
+
_sourceTypeName3 = "heading".concat(nodeToFormat.attrs.level);
|
|
253
|
+
}
|
|
254
|
+
api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 || (_api$analytics4 = _api$analytics4.actions) === null || _api$analytics4 === void 0 || _api$analytics4.fireAnalyticsEvent({
|
|
255
|
+
action: ACTION.ERRORED,
|
|
256
|
+
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
257
|
+
actionSubjectId: ACTION_SUBJECT_ID.TRANSFORM,
|
|
258
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
259
|
+
attributes: {
|
|
260
|
+
error: error.message,
|
|
261
|
+
errorStack: error.stack,
|
|
262
|
+
docSize: tr.doc.nodeSize,
|
|
263
|
+
from: _sourceTypeName3,
|
|
264
|
+
to: targetType,
|
|
265
|
+
position: tr.selection.from,
|
|
266
|
+
selection: tr.selection.toJSON(),
|
|
267
|
+
inputMethod: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.inputMethod) || INPUT_METHOD.BLOCK_MENU,
|
|
268
|
+
triggeredFrom: (analyticsAttrs === null || analyticsAttrs === void 0 ? void 0 : analyticsAttrs.triggeredFrom) || INPUT_METHOD.MOUSE
|
|
269
|
+
}
|
|
270
|
+
});
|
|
243
271
|
return null;
|
|
244
272
|
}
|
|
245
273
|
};
|
|
@@ -3,6 +3,17 @@ import { transformContainerNode, unwrapAndConvertToList } from './container-tran
|
|
|
3
3
|
import { convertToLayout, transformLayoutNode } from './layout-transforms';
|
|
4
4
|
import { transformListNode } from './list-transforms';
|
|
5
5
|
import { getTargetNodeInfo, isBlockNode, isListNode, isListNodeType, isContainerNode, isLayoutNodeType, isLayoutNode } from './utils';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Transforms a source node to the specified target type.
|
|
9
|
+
* Throws errors on failure which should be caught at the command level.
|
|
10
|
+
*
|
|
11
|
+
* @param tr - The transaction to apply transformations to
|
|
12
|
+
* @param sourceNode - The node to transform
|
|
13
|
+
* @param sourcePos - The position of the source node in the document
|
|
14
|
+
* @param targetType - The target node type to transform to
|
|
15
|
+
* @returns The modified transaction if successful, null if transformation is not possible
|
|
16
|
+
*/
|
|
6
17
|
export function transformNodeToTargetType(tr, sourceNode, sourcePos, targetType) {
|
|
7
18
|
var nodes = tr.doc.type.schema.nodes;
|
|
8
19
|
var targetNodeInfo = getTargetNodeInfo(targetType, nodes);
|
|
@@ -37,30 +48,25 @@ export function transformNodeToTargetType(tr, sourceNode, sourcePos, targetType)
|
|
|
37
48
|
};
|
|
38
49
|
|
|
39
50
|
// Route to appropriate transformation strategy based on source node type
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
51
|
+
if (isLayoutNodeType(targetNodeType)) {
|
|
52
|
+
return convertToLayout(transformationContext);
|
|
53
|
+
}
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
} catch (_unused) {
|
|
63
|
-
// Node transformation failed
|
|
64
|
-
return null;
|
|
55
|
+
// special case codeblock to listType
|
|
56
|
+
if (sourceNode.type.name === 'codeBlock' && isListNodeType(targetNodeType)) {
|
|
57
|
+
return unwrapAndConvertToList(transformationContext);
|
|
58
|
+
}
|
|
59
|
+
if (isLayoutNode(sourceNode)) {
|
|
60
|
+
return transformLayoutNode(transformationContext);
|
|
61
|
+
}
|
|
62
|
+
if (isBlockNode(sourceNode)) {
|
|
63
|
+
return transformBlockNode(transformationContext);
|
|
64
|
+
}
|
|
65
|
+
if (isListNode(sourceNode)) {
|
|
66
|
+
return transformListNode(transformationContext);
|
|
67
|
+
}
|
|
68
|
+
if (isContainerNode(sourceNode)) {
|
|
69
|
+
return transformContainerNode(transformationContext);
|
|
65
70
|
}
|
|
71
|
+
return null;
|
|
66
72
|
}
|
|
@@ -5,6 +5,7 @@ import React, { useContext, useEffect, useRef } from 'react';
|
|
|
5
5
|
import { injectIntl } from 'react-intl-next';
|
|
6
6
|
import { cx } from '@atlaskit/css';
|
|
7
7
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
8
|
+
import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
|
|
8
9
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
9
10
|
import { DRAG_HANDLE_SELECTOR, DRAG_HANDLE_WIDTH } from '@atlaskit/editor-common/styles';
|
|
10
11
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
@@ -139,7 +140,12 @@ var BlockMenu = function BlockMenu(_ref2) {
|
|
|
139
140
|
}
|
|
140
141
|
};
|
|
141
142
|
if (targetHandleRef instanceof HTMLElement) {
|
|
142
|
-
|
|
143
|
+
var _api$analytics2;
|
|
144
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
145
|
+
component: ACTION_SUBJECT.BLOCK_MENU,
|
|
146
|
+
dispatchAnalyticsEvent: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent,
|
|
147
|
+
fallbackComponent: null
|
|
148
|
+
}, /*#__PURE__*/React.createElement(PopupWithListeners, {
|
|
143
149
|
alignX: 'right',
|
|
144
150
|
alignY: 'start' // respected when forcePlacement is true
|
|
145
151
|
,
|
|
@@ -162,7 +168,7 @@ var BlockMenu = function BlockMenu(_ref2) {
|
|
|
162
168
|
}, /*#__PURE__*/React.createElement(BlockMenuContent, {
|
|
163
169
|
api: api,
|
|
164
170
|
setRef: expValEqualsNoExposure('platform_editor_block_menu_keyboard_navigation', 'isEnabled', true) ? setRef : undefined
|
|
165
|
-
}));
|
|
171
|
+
})));
|
|
166
172
|
} else {
|
|
167
173
|
return null;
|
|
168
174
|
}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import type { FormatNodeTargetType } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Transforms a source node to the specified target type.
|
|
6
|
+
* Throws errors on failure which should be caught at the command level.
|
|
7
|
+
*
|
|
8
|
+
* @param tr - The transaction to apply transformations to
|
|
9
|
+
* @param sourceNode - The node to transform
|
|
10
|
+
* @param sourcePos - The position of the source node in the document
|
|
11
|
+
* @param targetType - The target node type to transform to
|
|
12
|
+
* @returns The modified transaction if successful, null if transformation is not possible
|
|
13
|
+
*/
|
|
4
14
|
export declare function transformNodeToTargetType(tr: Transaction, sourceNode: PMNode, sourcePos: number, targetType: FormatNodeTargetType): Transaction | null;
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import type { FormatNodeTargetType } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Transforms a source node to the specified target type.
|
|
6
|
+
* Throws errors on failure which should be caught at the command level.
|
|
7
|
+
*
|
|
8
|
+
* @param tr - The transaction to apply transformations to
|
|
9
|
+
* @param sourceNode - The node to transform
|
|
10
|
+
* @param sourcePos - The position of the source node in the document
|
|
11
|
+
* @param targetType - The target node type to transform to
|
|
12
|
+
* @returns The modified transaction if successful, null if transformation is not possible
|
|
13
|
+
*/
|
|
4
14
|
export declare function transformNodeToTargetType(tr: Transaction, sourceNode: PMNode, sourcePos: number, targetType: FormatNodeTargetType): Transaction | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-menu",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.22",
|
|
4
4
|
"description": "BlockMenu plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"@atlaskit/editor-plugin-selection": "^6.1.0",
|
|
37
37
|
"@atlaskit/editor-plugin-user-intent": "^4.0.0",
|
|
38
38
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
39
|
-
"@atlaskit/editor-shared-styles": "^3.
|
|
39
|
+
"@atlaskit/editor-shared-styles": "^3.7.0",
|
|
40
40
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
41
41
|
"@atlaskit/editor-toolbar": "^0.15.0",
|
|
42
42
|
"@atlaskit/icon": "^28.5.0",
|
|
43
43
|
"@atlaskit/icon-lab": "^5.10.0",
|
|
44
44
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
45
45
|
"@atlaskit/primitives": "^14.15.0",
|
|
46
|
-
"@atlaskit/tmp-editor-statsig": "^13.
|
|
46
|
+
"@atlaskit/tmp-editor-statsig": "^13.10.0",
|
|
47
47
|
"@atlaskit/tokens": "^6.4.0",
|
|
48
48
|
"@babel/runtime": "^7.0.0"
|
|
49
49
|
},
|