@atlaskit/editor-plugin-block-menu 5.2.0 → 5.2.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 +16 -0
- package/dist/cjs/editor-commands/transform-node-utils/transform.js +5 -1
- package/dist/cjs/editor-commands/transform-node-utils/utils.js +25 -19
- package/dist/cjs/ui/copy-link.js +35 -18
- package/dist/cjs/ui/utils/copyLink.js +30 -38
- package/dist/es2019/editor-commands/transform-node-utils/transform.js +5 -1
- package/dist/es2019/editor-commands/transform-node-utils/utils.js +25 -16
- package/dist/es2019/ui/copy-link.js +35 -15
- package/dist/es2019/ui/utils/copyLink.js +26 -25
- package/dist/esm/editor-commands/transform-node-utils/transform.js +5 -1
- package/dist/esm/editor-commands/transform-node-utils/utils.js +26 -20
- package/dist/esm/ui/copy-link.js +36 -19
- package/dist/esm/ui/utils/copyLink.js +31 -39
- package/dist/types/editor-commands/transform-node-utils/utils.d.ts +2 -2
- package/dist/types/ui/utils/copyLink.d.ts +10 -3
- package/dist/types-ts4.5/editor-commands/transform-node-utils/utils.d.ts +2 -2
- package/dist/types-ts4.5/ui/utils/copyLink.d.ts +10 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 5.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`8696c9d95fe26`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8696c9d95fe26) -
|
|
8
|
+
[ux] EDITOR-3382 Block menu copy link for multi select
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 5.2.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`e1a0f13fc5c83`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e1a0f13fc5c83) -
|
|
16
|
+
Editor-2778: Table transform to expand and layout
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 5.2.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -31,7 +31,7 @@ var wrapIntoPanelStep = function wrapIntoPanelStep(nodes, context) {
|
|
|
31
31
|
var TRANSFORM_STEPS = {
|
|
32
32
|
atomic: {
|
|
33
33
|
atomic: undefined,
|
|
34
|
-
container: [
|
|
34
|
+
container: [_wrapStep.wrapStep],
|
|
35
35
|
list: undefined,
|
|
36
36
|
text: undefined
|
|
37
37
|
},
|
|
@@ -115,6 +115,10 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
115
115
|
// Warning: Actuall transformation logic not complete (Likelly prosemirror-markdown to be used)
|
|
116
116
|
codeBlock: [_convertTaskListToTextStep.convertTaskListToTextStep, _flattenStep.flattenStep, _wrapStep.wrapStep],
|
|
117
117
|
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
|
|
118
|
+
},
|
|
119
|
+
table: {
|
|
120
|
+
expand: [_wrapStep.wrapStep],
|
|
121
|
+
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
|
|
118
122
|
}
|
|
119
123
|
};
|
|
120
124
|
var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
|
|
@@ -8,6 +8,7 @@ var _selection = require("@atlaskit/editor-common/selection");
|
|
|
8
8
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
9
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
10
10
|
var _editorTables = require("@atlaskit/editor-tables");
|
|
11
|
+
var _utils2 = require("@atlaskit/editor-tables/utils");
|
|
11
12
|
var getSelectedNode = exports.getSelectedNode = function getSelectedNode(selection) {
|
|
12
13
|
if (selection instanceof _state.NodeSelection) {
|
|
13
14
|
return {
|
|
@@ -58,29 +59,34 @@ var getTargetNodeTypeNameInContext = exports.getTargetNodeTypeNameInContext = fu
|
|
|
58
59
|
};
|
|
59
60
|
|
|
60
61
|
/**
|
|
61
|
-
* Use common expandToBlockRange function
|
|
62
|
-
*
|
|
62
|
+
* Use common expandToBlockRange function to get the correct range for the selection
|
|
63
|
+
* For example, if selection starts in a listItem, go find the bullet list or ordered list, their $from
|
|
63
64
|
* @param selection
|
|
64
65
|
* @param schema
|
|
65
66
|
* @returns
|
|
66
67
|
*/
|
|
67
68
|
var expandSelectionToBlockRange = exports.expandSelectionToBlockRange = function expandSelectionToBlockRange(selection, schema) {
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
69
|
+
var nodes = schema.nodes;
|
|
70
|
+
var nodesNeedToExpandRange = [nodes.listItem, nodes.taskItem];
|
|
71
|
+
|
|
72
|
+
// when adding nodes.tableRow, tableHeader, tableCell in nodesNeedToExpandRang,
|
|
73
|
+
// expandToBlockRange does not return expected table start position, sometimes even freeze editor
|
|
74
|
+
// so handle table in the below logic
|
|
75
|
+
if ((0, _utils2.isTableSelected)(selection)) {
|
|
76
|
+
var table = (0, _utils2.findTable)(selection);
|
|
77
|
+
if (table) {
|
|
78
|
+
var $from = selection.$from.doc.resolve(table.pos);
|
|
79
|
+
var $to = selection.$from.doc.resolve(table.pos + table.node.nodeSize - 1);
|
|
80
|
+
return {
|
|
81
|
+
$from: $from,
|
|
82
|
+
$to: $to
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return (0, _selection.expandToBlockRange)(selection.$from, selection.$to, function (node) {
|
|
87
|
+
if (nodesNeedToExpandRange.includes(node.type)) {
|
|
78
88
|
return false;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
$from: $from,
|
|
84
|
-
$to: $to
|
|
85
|
-
};
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
});
|
|
86
92
|
};
|
package/dist/cjs/ui/copy-link.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.CopyLinkDropdownItem = void 0;
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _reactIntlNext = require("react-intl-next");
|
|
11
11
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
12
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
12
13
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
13
14
|
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
14
15
|
var _link = _interopRequireDefault(require("@atlaskit/icon/core/link"));
|
|
@@ -21,18 +22,38 @@ var _copyLink = require("./utils/copyLink");
|
|
|
21
22
|
var _isNestedNode = require("./utils/isNestedNode");
|
|
22
23
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
23
24
|
var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
|
|
24
|
-
var _api$selection;
|
|
25
25
|
var api = _ref.api,
|
|
26
26
|
config = _ref.config;
|
|
27
27
|
var _useIntl = (0, _reactIntlNext.useIntl)(),
|
|
28
28
|
formatMessage = _useIntl.formatMessage;
|
|
29
29
|
var _useBlockMenu = (0, _blockMenuProvider.useBlockMenu)(),
|
|
30
30
|
onDropdownOpenChanged = _useBlockMenu.onDropdownOpenChanged;
|
|
31
|
-
var
|
|
31
|
+
var _ref2 = config || {},
|
|
32
|
+
getLinkPath = _ref2.getLinkPath,
|
|
33
|
+
blockLinkHashPrefix = _ref2.blockLinkHashPrefix;
|
|
34
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls', 'selection', 'core'], function (_ref3) {
|
|
35
|
+
var blockControlsState = _ref3.blockControlsState,
|
|
36
|
+
selectionState = _ref3.selectionState,
|
|
37
|
+
coreState = _ref3.coreState;
|
|
38
|
+
return {
|
|
39
|
+
menuTriggerBy: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.menuTriggerBy,
|
|
40
|
+
preservedSelection: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.preservedSelection,
|
|
41
|
+
defaultSelection: selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection,
|
|
42
|
+
schema: coreState === null || coreState === void 0 ? void 0 : coreState.schema
|
|
43
|
+
};
|
|
44
|
+
}),
|
|
45
|
+
preservedSelection = _useSharedPluginState.preservedSelection,
|
|
46
|
+
defaultSelection = _useSharedPluginState.defaultSelection,
|
|
47
|
+
menuTriggerBy = _useSharedPluginState.menuTriggerBy,
|
|
48
|
+
schema = _useSharedPluginState.schema;
|
|
49
|
+
var selection = preservedSelection || defaultSelection;
|
|
32
50
|
var handleClick = (0, _react.useCallback)(function () {
|
|
33
|
-
|
|
51
|
+
if (!selection || !schema) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref4) {
|
|
34
55
|
var _api$analytics, _api$blockControls;
|
|
35
|
-
var tr =
|
|
56
|
+
var tr = _ref4.tr;
|
|
36
57
|
var payload = {
|
|
37
58
|
action: _analytics.ACTION.CLICKED,
|
|
38
59
|
actionSubject: _analytics.ACTION_SUBJECT.BLOCK_MENU_ITEM,
|
|
@@ -50,10 +71,15 @@ var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
|
|
|
50
71
|
return tr;
|
|
51
72
|
});
|
|
52
73
|
onDropdownOpenChanged(false);
|
|
53
|
-
(0, _copyLink.copyLink)(
|
|
74
|
+
(0, _copyLink.copyLink)({
|
|
75
|
+
getLinkPath: getLinkPath,
|
|
76
|
+
blockLinkHashPrefix: blockLinkHashPrefix,
|
|
77
|
+
selection: selection,
|
|
78
|
+
schema: schema
|
|
79
|
+
}).then(function (success) {
|
|
54
80
|
if (success) {
|
|
55
|
-
api === null || api === void 0 || api.core.actions.execute(function (
|
|
56
|
-
var tr =
|
|
81
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref5) {
|
|
82
|
+
var tr = _ref5.tr;
|
|
57
83
|
tr.setMeta(_main.blockMenuPluginKey, {
|
|
58
84
|
showFlag: _blockMenuPluginType.FLAG_ID.LINK_COPIED_TO_CLIPBOARD
|
|
59
85
|
});
|
|
@@ -61,19 +87,10 @@ var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
|
|
|
61
87
|
});
|
|
62
88
|
}
|
|
63
89
|
});
|
|
64
|
-
}, [
|
|
65
|
-
var checkIsNestedNode = (0, _react.useCallback)(function () {
|
|
66
|
-
var _api$selection2, _api$blockControls2;
|
|
67
|
-
var selection = api === null || api === void 0 || (_api$selection2 = api.selection) === null || _api$selection2 === void 0 || (_api$selection2 = _api$selection2.sharedState) === null || _api$selection2 === void 0 || (_api$selection2 = _api$selection2.currentState()) === null || _api$selection2 === void 0 ? void 0 : _api$selection2.selection;
|
|
68
|
-
var menuTriggerBy = api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.sharedState) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.currentState()) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.menuTriggerBy;
|
|
69
|
-
if (!selection || !menuTriggerBy) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
return (0, _isNestedNode.isNestedNode)(selection, menuTriggerBy);
|
|
73
|
-
}, [api]);
|
|
90
|
+
}, [api, blockLinkHashPrefix, getLinkPath, onDropdownOpenChanged, schema, selection]);
|
|
74
91
|
|
|
75
92
|
// Hide copy link when `platform_editor_adf_with_localid` feature flag is off or when the node is nested or on empty line
|
|
76
|
-
if (!(0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid') ||
|
|
93
|
+
if (!(0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid') || !!menuTriggerBy && (0, _isNestedNode.isNestedNode)(selection, menuTriggerBy) || selection !== null && selection !== void 0 && selection.empty) {
|
|
77
94
|
return null;
|
|
78
95
|
}
|
|
79
96
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
|
|
@@ -9,33 +9,24 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
|
9
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
10
|
var _blockMenu = require("@atlaskit/editor-common/block-menu");
|
|
11
11
|
var _clipboard = require("@atlaskit/editor-common/clipboard");
|
|
12
|
-
var
|
|
13
|
-
var
|
|
12
|
+
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
13
|
+
var _utils = require("../../editor-commands/transform-node-utils/utils");
|
|
14
14
|
var copyLink = exports.copyLink = /*#__PURE__*/function () {
|
|
15
|
-
var
|
|
16
|
-
var blockLinkHashPrefix,
|
|
17
|
-
api,
|
|
18
|
-
_api$selection,
|
|
19
|
-
node,
|
|
20
|
-
selection,
|
|
21
|
-
path,
|
|
22
|
-
url,
|
|
23
|
-
href,
|
|
24
|
-
_args = arguments;
|
|
15
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
|
|
16
|
+
var getLinkPath, _ref$blockLinkHashPre, blockLinkHashPrefix, selection, schema, blockRange, node, path, url, href;
|
|
25
17
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
26
18
|
while (1) switch (_context.prev = _context.next) {
|
|
27
19
|
case 0:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
node = selection.node;
|
|
34
|
-
} else if (selection instanceof _state.TextSelection) {
|
|
35
|
-
node = selection.$from.node();
|
|
36
|
-
} else if (selection instanceof _editorTables.CellSelection) {
|
|
37
|
-
node = selection.$anchorCell.node(-1);
|
|
20
|
+
getLinkPath = _ref.getLinkPath, _ref$blockLinkHashPre = _ref.blockLinkHashPrefix, blockLinkHashPrefix = _ref$blockLinkHashPre === void 0 ? _blockMenu.DEFAULT_BLOCK_LINK_HASH_PREFIX : _ref$blockLinkHashPre, selection = _ref.selection, schema = _ref.schema;
|
|
21
|
+
blockRange = (0, _utils.expandSelectionToBlockRange)(selection, schema);
|
|
22
|
+
if (blockRange) {
|
|
23
|
+
_context.next = 4;
|
|
24
|
+
break;
|
|
38
25
|
}
|
|
26
|
+
return _context.abrupt("return", false);
|
|
27
|
+
case 4:
|
|
28
|
+
// get the link to the first node in the selection
|
|
29
|
+
node = blockRange.$from.nodeAfter;
|
|
39
30
|
if (!(!node || !node.attrs || !node.attrs.localId)) {
|
|
40
31
|
_context.next = 7;
|
|
41
32
|
break;
|
|
@@ -43,30 +34,31 @@ var copyLink = exports.copyLink = /*#__PURE__*/function () {
|
|
|
43
34
|
return _context.abrupt("return", false);
|
|
44
35
|
case 7:
|
|
45
36
|
path = (getLinkPath === null || getLinkPath === void 0 ? void 0 : getLinkPath()) || location.pathname;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
return _context.abrupt("return", false);
|
|
51
|
-
case 10:
|
|
52
|
-
url = new URL(location.origin + path); // append the localId as a hash fragment in the form #block-{localId}
|
|
53
|
-
url.hash = "".concat(blockLinkHashPrefix).concat(node.attrs.localId);
|
|
37
|
+
_context.prev = 8;
|
|
38
|
+
url = new URL(location.origin + path);
|
|
39
|
+
url.hash = (0, _blockMenu.createBlockLinkHashValue)(node.attrs.localId, blockLinkHashPrefix);
|
|
54
40
|
href = url.toString();
|
|
55
|
-
_context.next =
|
|
41
|
+
_context.next = 14;
|
|
56
42
|
return (0, _clipboard.copyToClipboard)(href);
|
|
57
|
-
case
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
_context.
|
|
43
|
+
case 14:
|
|
44
|
+
_context.next = 20;
|
|
45
|
+
break;
|
|
46
|
+
case 16:
|
|
47
|
+
_context.prev = 16;
|
|
48
|
+
_context.t0 = _context["catch"](8);
|
|
49
|
+
(0, _monitoring.logException)(_context.t0, {
|
|
50
|
+
location: 'editor-plugin-block-menu'
|
|
51
|
+
});
|
|
62
52
|
return _context.abrupt("return", false);
|
|
53
|
+
case 20:
|
|
54
|
+
return _context.abrupt("return", true);
|
|
63
55
|
case 21:
|
|
64
56
|
case "end":
|
|
65
57
|
return _context.stop();
|
|
66
58
|
}
|
|
67
|
-
}, _callee, null, [[
|
|
59
|
+
}, _callee, null, [[8, 16]]);
|
|
68
60
|
}));
|
|
69
61
|
return function copyLink(_x) {
|
|
70
|
-
return
|
|
62
|
+
return _ref2.apply(this, arguments);
|
|
71
63
|
};
|
|
72
64
|
}();
|
|
@@ -26,7 +26,7 @@ const wrapIntoPanelStep = (nodes, context) => {
|
|
|
26
26
|
const TRANSFORM_STEPS = {
|
|
27
27
|
atomic: {
|
|
28
28
|
atomic: undefined,
|
|
29
|
-
container: [
|
|
29
|
+
container: [wrapStep],
|
|
30
30
|
list: undefined,
|
|
31
31
|
text: undefined
|
|
32
32
|
},
|
|
@@ -110,6 +110,10 @@ const TRANSFORM_STEPS_OVERRIDE = {
|
|
|
110
110
|
// Warning: Actuall transformation logic not complete (Likelly prosemirror-markdown to be used)
|
|
111
111
|
codeBlock: [convertTaskListToTextStep, flattenStep, wrapStep],
|
|
112
112
|
layoutSection: [wrapIntoLayoutStep]
|
|
113
|
+
},
|
|
114
|
+
table: {
|
|
115
|
+
expand: [wrapStep],
|
|
116
|
+
layoutSection: [wrapIntoLayoutStep]
|
|
113
117
|
}
|
|
114
118
|
};
|
|
115
119
|
const getTransformStepsForNodeTypes = (selectedNodeTypeName, targetNodeTypeName) => {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { expandToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
2
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { findParentNodeOfType
|
|
3
|
+
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
4
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
5
|
+
import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
5
6
|
export const getSelectedNode = selection => {
|
|
6
7
|
if (selection instanceof NodeSelection) {
|
|
7
8
|
return {
|
|
@@ -53,28 +54,36 @@ export const getTargetNodeTypeNameInContext = (nodeTypeName, isNested) => {
|
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
|
-
* Use common expandToBlockRange function
|
|
57
|
-
*
|
|
57
|
+
* Use common expandToBlockRange function to get the correct range for the selection
|
|
58
|
+
* For example, if selection starts in a listItem, go find the bullet list or ordered list, their $from
|
|
58
59
|
* @param selection
|
|
59
60
|
* @param schema
|
|
60
61
|
* @returns
|
|
61
62
|
*/
|
|
62
63
|
export const expandSelectionToBlockRange = (selection, schema) => {
|
|
63
|
-
const isListInSelection = hasParentNode(node => node.type === schema.nodes.bulletList || node.type === schema.nodes.orderedList)(selection);
|
|
64
64
|
const {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
nodes
|
|
66
|
+
} = schema;
|
|
67
|
+
const nodesNeedToExpandRange = [nodes.listItem, nodes.taskItem];
|
|
68
|
+
|
|
69
|
+
// when adding nodes.tableRow, tableHeader, tableCell in nodesNeedToExpandRang,
|
|
70
|
+
// expandToBlockRange does not return expected table start position, sometimes even freeze editor
|
|
71
|
+
// so handle table in the below logic
|
|
72
|
+
if (isTableSelected(selection)) {
|
|
73
|
+
const table = findTable(selection);
|
|
74
|
+
if (table) {
|
|
75
|
+
const $from = selection.$from.doc.resolve(table.pos);
|
|
76
|
+
const $to = selection.$from.doc.resolve(table.pos + table.node.nodeSize - 1);
|
|
77
|
+
return {
|
|
78
|
+
$from,
|
|
79
|
+
$to
|
|
80
|
+
};
|
|
70
81
|
}
|
|
71
|
-
|
|
72
|
-
|
|
82
|
+
}
|
|
83
|
+
return expandToBlockRange(selection.$from, selection.$to, node => {
|
|
84
|
+
if (nodesNeedToExpandRange.includes(node.type)) {
|
|
85
|
+
return false;
|
|
73
86
|
}
|
|
74
|
-
return
|
|
87
|
+
return true;
|
|
75
88
|
});
|
|
76
|
-
return {
|
|
77
|
-
$from,
|
|
78
|
-
$to
|
|
79
|
-
};
|
|
80
89
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { injectIntl, useIntl } from 'react-intl-next';
|
|
3
3
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
4
5
|
import { blockMenuMessages as messages } from '@atlaskit/editor-common/messages';
|
|
5
6
|
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
6
7
|
import LinkIcon from '@atlaskit/icon/core/link';
|
|
@@ -15,15 +16,38 @@ const CopyLinkDropdownItemContent = ({
|
|
|
15
16
|
api,
|
|
16
17
|
config
|
|
17
18
|
}) => {
|
|
18
|
-
var _api$selection, _api$selection$shared, _api$selection$shared2;
|
|
19
19
|
const {
|
|
20
20
|
formatMessage
|
|
21
21
|
} = useIntl();
|
|
22
22
|
const {
|
|
23
23
|
onDropdownOpenChanged
|
|
24
24
|
} = useBlockMenu();
|
|
25
|
-
const
|
|
25
|
+
const {
|
|
26
|
+
getLinkPath,
|
|
27
|
+
blockLinkHashPrefix
|
|
28
|
+
} = config || {};
|
|
29
|
+
const {
|
|
30
|
+
preservedSelection,
|
|
31
|
+
defaultSelection,
|
|
32
|
+
menuTriggerBy,
|
|
33
|
+
schema
|
|
34
|
+
} = useSharedPluginStateWithSelector(api, ['blockControls', 'selection', 'core'], ({
|
|
35
|
+
blockControlsState,
|
|
36
|
+
selectionState,
|
|
37
|
+
coreState
|
|
38
|
+
}) => {
|
|
39
|
+
return {
|
|
40
|
+
menuTriggerBy: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.menuTriggerBy,
|
|
41
|
+
preservedSelection: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.preservedSelection,
|
|
42
|
+
defaultSelection: selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection,
|
|
43
|
+
schema: coreState === null || coreState === void 0 ? void 0 : coreState.schema
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
const selection = preservedSelection || defaultSelection;
|
|
26
47
|
const handleClick = useCallback(() => {
|
|
48
|
+
if (!selection || !schema) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
27
51
|
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
28
52
|
tr
|
|
29
53
|
}) => {
|
|
@@ -45,7 +69,12 @@ const CopyLinkDropdownItemContent = ({
|
|
|
45
69
|
return tr;
|
|
46
70
|
});
|
|
47
71
|
onDropdownOpenChanged(false);
|
|
48
|
-
copyLink(
|
|
72
|
+
copyLink({
|
|
73
|
+
getLinkPath,
|
|
74
|
+
blockLinkHashPrefix,
|
|
75
|
+
selection,
|
|
76
|
+
schema
|
|
77
|
+
}).then(success => {
|
|
49
78
|
if (success) {
|
|
50
79
|
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
51
80
|
tr
|
|
@@ -57,19 +86,10 @@ const CopyLinkDropdownItemContent = ({
|
|
|
57
86
|
});
|
|
58
87
|
}
|
|
59
88
|
});
|
|
60
|
-
}, [
|
|
61
|
-
const checkIsNestedNode = useCallback(() => {
|
|
62
|
-
var _api$selection2, _api$selection2$share, _api$selection2$share2, _api$blockControls2, _api$blockControls2$s, _api$blockControls2$s2;
|
|
63
|
-
const selection = api === null || api === void 0 ? void 0 : (_api$selection2 = api.selection) === null || _api$selection2 === void 0 ? void 0 : (_api$selection2$share = _api$selection2.sharedState) === null || _api$selection2$share === void 0 ? void 0 : (_api$selection2$share2 = _api$selection2$share.currentState()) === null || _api$selection2$share2 === void 0 ? void 0 : _api$selection2$share2.selection;
|
|
64
|
-
const menuTriggerBy = api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : (_api$blockControls2$s = _api$blockControls2.sharedState) === null || _api$blockControls2$s === void 0 ? void 0 : (_api$blockControls2$s2 = _api$blockControls2$s.currentState()) === null || _api$blockControls2$s2 === void 0 ? void 0 : _api$blockControls2$s2.menuTriggerBy;
|
|
65
|
-
if (!selection || !menuTriggerBy) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
return isNestedNode(selection, menuTriggerBy);
|
|
69
|
-
}, [api]);
|
|
89
|
+
}, [api, blockLinkHashPrefix, getLinkPath, onDropdownOpenChanged, schema, selection]);
|
|
70
90
|
|
|
71
91
|
// Hide copy link when `platform_editor_adf_with_localid` feature flag is off or when the node is nested or on empty line
|
|
72
|
-
if (!fg('platform_editor_adf_with_localid') ||
|
|
92
|
+
if (!fg('platform_editor_adf_with_localid') || !!menuTriggerBy && isNestedNode(selection, menuTriggerBy) || selection !== null && selection !== void 0 && selection.empty) {
|
|
73
93
|
return null;
|
|
74
94
|
}
|
|
75
95
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
import { DEFAULT_BLOCK_LINK_HASH_PREFIX } from '@atlaskit/editor-common/block-menu';
|
|
1
|
+
import { createBlockLinkHashValue, DEFAULT_BLOCK_LINK_HASH_PREFIX } from '@atlaskit/editor-common/block-menu';
|
|
2
2
|
import { copyToClipboard } from '@atlaskit/editor-common/clipboard';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export const copyLink = async (
|
|
3
|
+
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
4
|
+
import { expandSelectionToBlockRange } from '../../editor-commands/transform-node-utils/utils';
|
|
5
|
+
export const copyLink = async ({
|
|
6
|
+
getLinkPath,
|
|
7
|
+
blockLinkHashPrefix = DEFAULT_BLOCK_LINK_HASH_PREFIX,
|
|
8
|
+
selection,
|
|
9
|
+
schema
|
|
10
|
+
}) => {
|
|
11
|
+
const blockRange = expandSelectionToBlockRange(selection, schema);
|
|
12
|
+
if (!blockRange) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// get the link to the first node in the selection
|
|
17
|
+
const node = blockRange.$from.nodeAfter;
|
|
18
|
+
if (!node || !node.attrs || !node.attrs.localId) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const path = (getLinkPath === null || getLinkPath === void 0 ? void 0 : getLinkPath()) || location.pathname;
|
|
6
22
|
try {
|
|
7
|
-
var _api$selection, _api$selection$shared;
|
|
8
|
-
let node;
|
|
9
|
-
const selection = api === null || api === void 0 ? void 0 : (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : (_api$selection$shared = _api$selection.sharedState.currentState()) === null || _api$selection$shared === void 0 ? void 0 : _api$selection$shared.selection;
|
|
10
|
-
if (selection instanceof NodeSelection && selection.node) {
|
|
11
|
-
node = selection.node;
|
|
12
|
-
} else if (selection instanceof TextSelection) {
|
|
13
|
-
node = selection.$from.node();
|
|
14
|
-
} else if (selection instanceof CellSelection) {
|
|
15
|
-
node = selection.$anchorCell.node(-1);
|
|
16
|
-
}
|
|
17
|
-
if (!node || !node.attrs || !node.attrs.localId) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
const path = (getLinkPath === null || getLinkPath === void 0 ? void 0 : getLinkPath()) || location.pathname;
|
|
21
|
-
if (!path) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
23
|
const url = new URL(location.origin + path);
|
|
25
|
-
|
|
26
|
-
url.hash = `${blockLinkHashPrefix}${node.attrs.localId}`;
|
|
24
|
+
url.hash = createBlockLinkHashValue(node.attrs.localId, blockLinkHashPrefix);
|
|
27
25
|
const href = url.toString();
|
|
28
26
|
await copyToClipboard(href);
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
} catch (error) {
|
|
28
|
+
logException(error, {
|
|
29
|
+
location: 'editor-plugin-block-menu'
|
|
30
|
+
});
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
|
+
return true;
|
|
33
34
|
};
|
|
@@ -26,7 +26,7 @@ var wrapIntoPanelStep = function wrapIntoPanelStep(nodes, context) {
|
|
|
26
26
|
var TRANSFORM_STEPS = {
|
|
27
27
|
atomic: {
|
|
28
28
|
atomic: undefined,
|
|
29
|
-
container: [
|
|
29
|
+
container: [wrapStep],
|
|
30
30
|
list: undefined,
|
|
31
31
|
text: undefined
|
|
32
32
|
},
|
|
@@ -110,6 +110,10 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
110
110
|
// Warning: Actuall transformation logic not complete (Likelly prosemirror-markdown to be used)
|
|
111
111
|
codeBlock: [convertTaskListToTextStep, flattenStep, wrapStep],
|
|
112
112
|
layoutSection: [wrapIntoLayoutStep]
|
|
113
|
+
},
|
|
114
|
+
table: {
|
|
115
|
+
expand: [wrapStep],
|
|
116
|
+
layoutSection: [wrapIntoLayoutStep]
|
|
113
117
|
}
|
|
114
118
|
};
|
|
115
119
|
var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { expandToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
2
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { findParentNodeOfType
|
|
3
|
+
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
4
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
5
|
+
import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
5
6
|
export var getSelectedNode = function getSelectedNode(selection) {
|
|
6
7
|
if (selection instanceof NodeSelection) {
|
|
7
8
|
return {
|
|
@@ -52,29 +53,34 @@ export var getTargetNodeTypeNameInContext = function getTargetNodeTypeNameInCont
|
|
|
52
53
|
};
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
|
-
* Use common expandToBlockRange function
|
|
56
|
-
*
|
|
56
|
+
* Use common expandToBlockRange function to get the correct range for the selection
|
|
57
|
+
* For example, if selection starts in a listItem, go find the bullet list or ordered list, their $from
|
|
57
58
|
* @param selection
|
|
58
59
|
* @param schema
|
|
59
60
|
* @returns
|
|
60
61
|
*/
|
|
61
62
|
export var expandSelectionToBlockRange = function expandSelectionToBlockRange(selection, schema) {
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
var nodes = schema.nodes;
|
|
64
|
+
var nodesNeedToExpandRange = [nodes.listItem, nodes.taskItem];
|
|
65
|
+
|
|
66
|
+
// when adding nodes.tableRow, tableHeader, tableCell in nodesNeedToExpandRang,
|
|
67
|
+
// expandToBlockRange does not return expected table start position, sometimes even freeze editor
|
|
68
|
+
// so handle table in the below logic
|
|
69
|
+
if (isTableSelected(selection)) {
|
|
70
|
+
var table = findTable(selection);
|
|
71
|
+
if (table) {
|
|
72
|
+
var $from = selection.$from.doc.resolve(table.pos);
|
|
73
|
+
var $to = selection.$from.doc.resolve(table.pos + table.node.nodeSize - 1);
|
|
74
|
+
return {
|
|
75
|
+
$from: $from,
|
|
76
|
+
$to: $to
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return expandToBlockRange(selection.$from, selection.$to, function (node) {
|
|
81
|
+
if (nodesNeedToExpandRange.includes(node.type)) {
|
|
72
82
|
return false;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
$from: $from,
|
|
78
|
-
$to: $to
|
|
79
|
-
};
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
});
|
|
80
86
|
};
|
package/dist/esm/ui/copy-link.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { injectIntl, useIntl } from 'react-intl-next';
|
|
3
3
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
4
5
|
import { blockMenuMessages as messages } from '@atlaskit/editor-common/messages';
|
|
5
6
|
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
6
7
|
import LinkIcon from '@atlaskit/icon/core/link';
|
|
@@ -12,18 +13,38 @@ import { BLOCK_MENU_ITEM_NAME } from './consts';
|
|
|
12
13
|
import { copyLink } from './utils/copyLink';
|
|
13
14
|
import { isNestedNode } from './utils/isNestedNode';
|
|
14
15
|
var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
|
|
15
|
-
var _api$selection;
|
|
16
16
|
var api = _ref.api,
|
|
17
17
|
config = _ref.config;
|
|
18
18
|
var _useIntl = useIntl(),
|
|
19
19
|
formatMessage = _useIntl.formatMessage;
|
|
20
20
|
var _useBlockMenu = useBlockMenu(),
|
|
21
21
|
onDropdownOpenChanged = _useBlockMenu.onDropdownOpenChanged;
|
|
22
|
-
var
|
|
22
|
+
var _ref2 = config || {},
|
|
23
|
+
getLinkPath = _ref2.getLinkPath,
|
|
24
|
+
blockLinkHashPrefix = _ref2.blockLinkHashPrefix;
|
|
25
|
+
var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['blockControls', 'selection', 'core'], function (_ref3) {
|
|
26
|
+
var blockControlsState = _ref3.blockControlsState,
|
|
27
|
+
selectionState = _ref3.selectionState,
|
|
28
|
+
coreState = _ref3.coreState;
|
|
29
|
+
return {
|
|
30
|
+
menuTriggerBy: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.menuTriggerBy,
|
|
31
|
+
preservedSelection: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.preservedSelection,
|
|
32
|
+
defaultSelection: selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection,
|
|
33
|
+
schema: coreState === null || coreState === void 0 ? void 0 : coreState.schema
|
|
34
|
+
};
|
|
35
|
+
}),
|
|
36
|
+
preservedSelection = _useSharedPluginState.preservedSelection,
|
|
37
|
+
defaultSelection = _useSharedPluginState.defaultSelection,
|
|
38
|
+
menuTriggerBy = _useSharedPluginState.menuTriggerBy,
|
|
39
|
+
schema = _useSharedPluginState.schema;
|
|
40
|
+
var selection = preservedSelection || defaultSelection;
|
|
23
41
|
var handleClick = useCallback(function () {
|
|
24
|
-
|
|
42
|
+
if (!selection || !schema) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref4) {
|
|
25
46
|
var _api$analytics, _api$blockControls;
|
|
26
|
-
var tr =
|
|
47
|
+
var tr = _ref4.tr;
|
|
27
48
|
var payload = {
|
|
28
49
|
action: ACTION.CLICKED,
|
|
29
50
|
actionSubject: ACTION_SUBJECT.BLOCK_MENU_ITEM,
|
|
@@ -41,10 +62,15 @@ var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
|
|
|
41
62
|
return tr;
|
|
42
63
|
});
|
|
43
64
|
onDropdownOpenChanged(false);
|
|
44
|
-
copyLink(
|
|
65
|
+
copyLink({
|
|
66
|
+
getLinkPath: getLinkPath,
|
|
67
|
+
blockLinkHashPrefix: blockLinkHashPrefix,
|
|
68
|
+
selection: selection,
|
|
69
|
+
schema: schema
|
|
70
|
+
}).then(function (success) {
|
|
45
71
|
if (success) {
|
|
46
|
-
api === null || api === void 0 || api.core.actions.execute(function (
|
|
47
|
-
var tr =
|
|
72
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref5) {
|
|
73
|
+
var tr = _ref5.tr;
|
|
48
74
|
tr.setMeta(blockMenuPluginKey, {
|
|
49
75
|
showFlag: FLAG_ID.LINK_COPIED_TO_CLIPBOARD
|
|
50
76
|
});
|
|
@@ -52,19 +78,10 @@ var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
|
|
|
52
78
|
});
|
|
53
79
|
}
|
|
54
80
|
});
|
|
55
|
-
}, [
|
|
56
|
-
var checkIsNestedNode = useCallback(function () {
|
|
57
|
-
var _api$selection2, _api$blockControls2;
|
|
58
|
-
var selection = api === null || api === void 0 || (_api$selection2 = api.selection) === null || _api$selection2 === void 0 || (_api$selection2 = _api$selection2.sharedState) === null || _api$selection2 === void 0 || (_api$selection2 = _api$selection2.currentState()) === null || _api$selection2 === void 0 ? void 0 : _api$selection2.selection;
|
|
59
|
-
var menuTriggerBy = api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.sharedState) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.currentState()) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.menuTriggerBy;
|
|
60
|
-
if (!selection || !menuTriggerBy) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
return isNestedNode(selection, menuTriggerBy);
|
|
64
|
-
}, [api]);
|
|
81
|
+
}, [api, blockLinkHashPrefix, getLinkPath, onDropdownOpenChanged, schema, selection]);
|
|
65
82
|
|
|
66
83
|
// Hide copy link when `platform_editor_adf_with_localid` feature flag is off or when the node is nested or on empty line
|
|
67
|
-
if (!fg('platform_editor_adf_with_localid') ||
|
|
84
|
+
if (!fg('platform_editor_adf_with_localid') || !!menuTriggerBy && isNestedNode(selection, menuTriggerBy) || selection !== null && selection !== void 0 && selection.empty) {
|
|
68
85
|
return null;
|
|
69
86
|
}
|
|
70
87
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
-
import { DEFAULT_BLOCK_LINK_HASH_PREFIX } from '@atlaskit/editor-common/block-menu';
|
|
3
|
+
import { createBlockLinkHashValue, DEFAULT_BLOCK_LINK_HASH_PREFIX } from '@atlaskit/editor-common/block-menu';
|
|
4
4
|
import { copyToClipboard } from '@atlaskit/editor-common/clipboard';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
6
|
+
import { expandSelectionToBlockRange } from '../../editor-commands/transform-node-utils/utils';
|
|
7
7
|
export var copyLink = /*#__PURE__*/function () {
|
|
8
|
-
var
|
|
9
|
-
var blockLinkHashPrefix,
|
|
10
|
-
api,
|
|
11
|
-
_api$selection,
|
|
12
|
-
node,
|
|
13
|
-
selection,
|
|
14
|
-
path,
|
|
15
|
-
url,
|
|
16
|
-
href,
|
|
17
|
-
_args = arguments;
|
|
8
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
9
|
+
var getLinkPath, _ref$blockLinkHashPre, blockLinkHashPrefix, selection, schema, blockRange, node, path, url, href;
|
|
18
10
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
19
11
|
while (1) switch (_context.prev = _context.next) {
|
|
20
12
|
case 0:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
node = selection.node;
|
|
27
|
-
} else if (selection instanceof TextSelection) {
|
|
28
|
-
node = selection.$from.node();
|
|
29
|
-
} else if (selection instanceof CellSelection) {
|
|
30
|
-
node = selection.$anchorCell.node(-1);
|
|
13
|
+
getLinkPath = _ref.getLinkPath, _ref$blockLinkHashPre = _ref.blockLinkHashPrefix, blockLinkHashPrefix = _ref$blockLinkHashPre === void 0 ? DEFAULT_BLOCK_LINK_HASH_PREFIX : _ref$blockLinkHashPre, selection = _ref.selection, schema = _ref.schema;
|
|
14
|
+
blockRange = expandSelectionToBlockRange(selection, schema);
|
|
15
|
+
if (blockRange) {
|
|
16
|
+
_context.next = 4;
|
|
17
|
+
break;
|
|
31
18
|
}
|
|
19
|
+
return _context.abrupt("return", false);
|
|
20
|
+
case 4:
|
|
21
|
+
// get the link to the first node in the selection
|
|
22
|
+
node = blockRange.$from.nodeAfter;
|
|
32
23
|
if (!(!node || !node.attrs || !node.attrs.localId)) {
|
|
33
24
|
_context.next = 7;
|
|
34
25
|
break;
|
|
@@ -36,30 +27,31 @@ export var copyLink = /*#__PURE__*/function () {
|
|
|
36
27
|
return _context.abrupt("return", false);
|
|
37
28
|
case 7:
|
|
38
29
|
path = (getLinkPath === null || getLinkPath === void 0 ? void 0 : getLinkPath()) || location.pathname;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
return _context.abrupt("return", false);
|
|
44
|
-
case 10:
|
|
45
|
-
url = new URL(location.origin + path); // append the localId as a hash fragment in the form #block-{localId}
|
|
46
|
-
url.hash = "".concat(blockLinkHashPrefix).concat(node.attrs.localId);
|
|
30
|
+
_context.prev = 8;
|
|
31
|
+
url = new URL(location.origin + path);
|
|
32
|
+
url.hash = createBlockLinkHashValue(node.attrs.localId, blockLinkHashPrefix);
|
|
47
33
|
href = url.toString();
|
|
48
|
-
_context.next =
|
|
34
|
+
_context.next = 14;
|
|
49
35
|
return copyToClipboard(href);
|
|
50
|
-
case
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
_context.
|
|
36
|
+
case 14:
|
|
37
|
+
_context.next = 20;
|
|
38
|
+
break;
|
|
39
|
+
case 16:
|
|
40
|
+
_context.prev = 16;
|
|
41
|
+
_context.t0 = _context["catch"](8);
|
|
42
|
+
logException(_context.t0, {
|
|
43
|
+
location: 'editor-plugin-block-menu'
|
|
44
|
+
});
|
|
55
45
|
return _context.abrupt("return", false);
|
|
46
|
+
case 20:
|
|
47
|
+
return _context.abrupt("return", true);
|
|
56
48
|
case 21:
|
|
57
49
|
case "end":
|
|
58
50
|
return _context.stop();
|
|
59
51
|
}
|
|
60
|
-
}, _callee, null, [[
|
|
52
|
+
}, _callee, null, [[8, 16]]);
|
|
61
53
|
}));
|
|
62
54
|
return function copyLink(_x) {
|
|
63
|
-
return
|
|
55
|
+
return _ref2.apply(this, arguments);
|
|
64
56
|
};
|
|
65
57
|
}();
|
|
@@ -5,8 +5,8 @@ import type { NodeTypeName } from './types';
|
|
|
5
5
|
export declare const getSelectedNode: (selection: Selection) => ContentNodeWithPos | undefined;
|
|
6
6
|
export declare const getTargetNodeTypeNameInContext: (nodeTypeName: NodeTypeName | null, isNested?: boolean) => NodeTypeName | null;
|
|
7
7
|
/**
|
|
8
|
-
* Use common expandToBlockRange function
|
|
9
|
-
*
|
|
8
|
+
* Use common expandToBlockRange function to get the correct range for the selection
|
|
9
|
+
* For example, if selection starts in a listItem, go find the bullet list or ordered list, their $from
|
|
10
10
|
* @param selection
|
|
11
11
|
* @param schema
|
|
12
12
|
* @returns
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
type CopyLinkOptions = {
|
|
4
|
+
blockLinkHashPrefix?: string;
|
|
5
|
+
getLinkPath?: () => string | null;
|
|
6
|
+
schema: Schema;
|
|
7
|
+
selection: Selection;
|
|
8
|
+
};
|
|
9
|
+
export declare const copyLink: ({ getLinkPath, blockLinkHashPrefix, selection, schema, }: CopyLinkOptions) => Promise<boolean>;
|
|
10
|
+
export {};
|
|
@@ -5,8 +5,8 @@ import type { NodeTypeName } from './types';
|
|
|
5
5
|
export declare const getSelectedNode: (selection: Selection) => ContentNodeWithPos | undefined;
|
|
6
6
|
export declare const getTargetNodeTypeNameInContext: (nodeTypeName: NodeTypeName | null, isNested?: boolean) => NodeTypeName | null;
|
|
7
7
|
/**
|
|
8
|
-
* Use common expandToBlockRange function
|
|
9
|
-
*
|
|
8
|
+
* Use common expandToBlockRange function to get the correct range for the selection
|
|
9
|
+
* For example, if selection starts in a listItem, go find the bullet list or ordered list, their $from
|
|
10
10
|
* @param selection
|
|
11
11
|
* @param schema
|
|
12
12
|
* @returns
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
type CopyLinkOptions = {
|
|
4
|
+
blockLinkHashPrefix?: string;
|
|
5
|
+
getLinkPath?: () => string | null;
|
|
6
|
+
schema: Schema;
|
|
7
|
+
selection: Selection;
|
|
8
|
+
};
|
|
9
|
+
export declare const copyLink: ({ getLinkPath, blockLinkHashPrefix, selection, schema, }: CopyLinkOptions) => Promise<boolean>;
|
|
10
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-menu",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.2",
|
|
4
4
|
"description": "BlockMenu plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@atlaskit/editor-shared-styles": "^3.10.0",
|
|
40
40
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
41
41
|
"@atlaskit/editor-toolbar": "^0.18.0",
|
|
42
|
-
"@atlaskit/flag": "^17.
|
|
42
|
+
"@atlaskit/flag": "^17.6.0",
|
|
43
43
|
"@atlaskit/icon": "^29.0.0",
|
|
44
44
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
45
45
|
"@atlaskit/platform-feature-flags-react": "^0.4.0",
|