@atlaskit/editor-plugin-block-menu 5.2.1 → 5.2.3

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.
Files changed (28) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/editor-commands/transform-node-utils/{flattenListStep.js → steps/flattenListStep.js} +3 -5
  3. package/dist/cjs/editor-commands/transform-node-utils/steps/listToListStep.js +232 -0
  4. package/dist/cjs/editor-commands/transform-node-utils/transform.js +4 -3
  5. package/dist/cjs/ui/copy-link.js +35 -18
  6. package/dist/cjs/ui/utils/copyLink.js +30 -38
  7. package/dist/es2019/editor-commands/transform-node-utils/{flattenListStep.js → steps/flattenListStep.js} +3 -5
  8. package/dist/es2019/editor-commands/transform-node-utils/steps/listToListStep.js +225 -0
  9. package/dist/es2019/editor-commands/transform-node-utils/transform.js +4 -3
  10. package/dist/es2019/ui/copy-link.js +35 -15
  11. package/dist/es2019/ui/utils/copyLink.js +26 -25
  12. package/dist/esm/editor-commands/transform-node-utils/{flattenListStep.js → steps/flattenListStep.js} +3 -5
  13. package/dist/esm/editor-commands/transform-node-utils/steps/listToListStep.js +226 -0
  14. package/dist/esm/editor-commands/transform-node-utils/transform.js +4 -3
  15. package/dist/esm/ui/copy-link.js +36 -19
  16. package/dist/esm/ui/utils/copyLink.js +31 -39
  17. package/dist/{types-ts4.5/editor-commands/transform-node-utils → types/editor-commands/transform-node-utils/steps}/flattenListStep.d.ts +1 -1
  18. package/dist/types/editor-commands/transform-node-utils/steps/listToListStep.d.ts +65 -0
  19. package/dist/{types-ts4.5/editor-commands/transform-node-utils → types/editor-commands/transform-node-utils/steps}/unwrapListStep.d.ts +1 -1
  20. package/dist/types/ui/utils/copyLink.d.ts +10 -3
  21. package/dist/{types/editor-commands/transform-node-utils → types-ts4.5/editor-commands/transform-node-utils/steps}/flattenListStep.d.ts +1 -1
  22. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/listToListStep.d.ts +65 -0
  23. package/dist/{types/editor-commands/transform-node-utils → types-ts4.5/editor-commands/transform-node-utils/steps}/unwrapListStep.d.ts +1 -1
  24. package/dist/types-ts4.5/ui/utils/copyLink.d.ts +10 -3
  25. package/package.json +2 -2
  26. /package/dist/cjs/editor-commands/transform-node-utils/{unwrapListStep.js → steps/unwrapListStep.js} +0 -0
  27. /package/dist/es2019/editor-commands/transform-node-utils/{unwrapListStep.js → steps/unwrapListStep.js} +0 -0
  28. /package/dist/esm/editor-commands/transform-node-utils/{unwrapListStep.js → steps/unwrapListStep.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 5.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`d0857f52fd866`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d0857f52fd866) -
8
+ Add list-to-list transformation support in block menu
9
+
10
+ ## 5.2.2
11
+
12
+ ### Patch Changes
13
+
14
+ - [`8696c9d95fe26`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8696c9d95fe26) -
15
+ [ux] EDITOR-3382 Block menu copy link for multi select
16
+ - Updated dependencies
17
+
3
18
  ## 5.2.1
4
19
 
5
20
  ### Patch Changes
@@ -20,12 +20,10 @@ var extractNestedLists = function extractNestedLists(node, listTypes, itemTypes,
20
20
  return grandChild.type === type;
21
21
  })) {
22
22
  nestedLists.push(grandChild);
23
+ } else if (grandChild.isText) {
24
+ contentWithoutNestedLists.push(paragraph.createAndFill({}, grandChild));
23
25
  } else {
24
- if (grandChild.isText) {
25
- contentWithoutNestedLists.push(paragraph.createAndFill({}, grandChild));
26
- } else {
27
- contentWithoutNestedLists.push(grandChild);
28
- }
26
+ contentWithoutNestedLists.push(grandChild);
29
27
  }
30
28
  });
31
29
  items.push(child.copy(_model.Fragment.from(contentWithoutNestedLists)));
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.listToListStep = void 0;
7
+ var _model = require("@atlaskit/editor-prosemirror/model");
8
+ var isListType = function isListType(node, schema) {
9
+ var lists = [schema.nodes.taskList, schema.nodes.bulletList, schema.nodes.orderedList];
10
+ return lists.some(function (list) {
11
+ return list === node.type;
12
+ });
13
+ };
14
+
15
+ /**
16
+ * Converts FROM taskList structure TO bulletList/orderedList structure.
17
+ */
18
+ var convertFromTaskListStructure = function convertFromTaskListStructure(node, targetListType, targetItemType) {
19
+ var schema = node.type.schema;
20
+ var targetListNodeType = schema.nodes[targetListType];
21
+ var convertedItems = [];
22
+ node.content.forEach(function (child) {
23
+ if (isListType(child, schema)) {
24
+ // This is a nested list - it should become a child of the previous item
25
+ if (convertedItems.length > 0) {
26
+ var previousItem = convertedItems[convertedItems.length - 1];
27
+ // Convert the nested list and add it to the previous item's content
28
+ var convertedNestedList = _transformList(child, targetListType, targetItemType);
29
+ var newContent = previousItem.content.append(_model.Fragment.from([convertedNestedList]));
30
+ var updatedItem = previousItem.type.create(previousItem.attrs, newContent);
31
+ convertedItems[convertedItems.length - 1] = updatedItem;
32
+ }
33
+ // If there's no previous item, skip this nested list (orphaned)
34
+ } else {
35
+ var convertedItem = transformListItem(child, targetItemType, targetListType);
36
+ if (convertedItem) {
37
+ convertedItems.push(convertedItem);
38
+ }
39
+ }
40
+ });
41
+ return targetListNodeType.create(node.attrs, _model.Fragment.from(convertedItems));
42
+ };
43
+
44
+ /**
45
+ * Converts FROM bulletList/orderedList structure TO taskList structure.
46
+ */
47
+ var convertToTaskListStructure = function convertToTaskListStructure(node, targetListType, targetItemType) {
48
+ var schema = node.type.schema;
49
+ var targetListNodeType = schema.nodes[targetListType];
50
+ var transformedContent = [];
51
+ node.content.forEach(function (itemNode) {
52
+ var transformedItem = transformListItem(itemNode, targetItemType, targetListType, true);
53
+ if (transformedItem) {
54
+ transformedContent.push(transformedItem);
55
+ }
56
+ itemNode.content.forEach(function (child) {
57
+ if (isListType(child, schema)) {
58
+ var transformedNestedList = _transformList(child, targetListType, targetItemType);
59
+ transformedContent.push(transformedNestedList);
60
+ }
61
+ });
62
+ });
63
+ return targetListNodeType.create(node.attrs, _model.Fragment.from(transformedContent));
64
+ };
65
+
66
+ /**
67
+ * Converts a single list item (listItem or taskItem) to the target item type.
68
+ * Handles content transformation based on the target type's requirements.
69
+ * @param itemNode - The list item node to convert
70
+ * @param targetItemType - The target item type (listItem or taskItem)
71
+ * @param targetListType - The target list type (bulletList, orderedList, or taskList)
72
+ * @param excludeNestedLists - When true, nested lists are excluded from the item's content
73
+ * (used when converting to taskList where nested lists become siblings)
74
+ */
75
+ var transformListItem = function transformListItem(itemNode, targetItemType, targetListType) {
76
+ var excludeNestedLists = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
77
+ var schema = itemNode.type.schema;
78
+ var targetItemNodeType = schema.nodes[targetItemType];
79
+ var isTargetTaskItem = targetItemType === 'taskItem';
80
+ var isSourceTaskItem = itemNode.type.name === 'taskItem';
81
+ var paragraphType = schema.nodes.paragraph;
82
+ if (!targetItemNodeType) {
83
+ return null;
84
+ }
85
+ if (isTargetTaskItem) {
86
+ var inlineContent = [];
87
+ itemNode.content.forEach(function (child) {
88
+ if (child.type === paragraphType) {
89
+ child.content.forEach(function (inline) {
90
+ inlineContent.push(inline);
91
+ });
92
+ }
93
+ if (child.isText) {
94
+ inlineContent.push(child);
95
+ }
96
+ // TODO: EDITOR-3887 - Skip mediaSingle, codeBlock, and nested lists
97
+ // Nested lists will be extracted and placed as siblings in the taskList
98
+ });
99
+ return targetItemNodeType.create({}, _model.Fragment.from(inlineContent));
100
+ } else {
101
+ var newContent = [];
102
+ if (isSourceTaskItem) {
103
+ newContent.push(paragraphType.create(null, itemNode.content));
104
+ } else {
105
+ itemNode.content.forEach(function (child) {
106
+ if (isListType(child, schema)) {
107
+ if (excludeNestedLists) {
108
+ // Skip nested lists - they will be handled separately as siblings
109
+ return;
110
+ }
111
+ newContent.push(_transformList(child, targetListType, targetItemType));
112
+ } else {
113
+ newContent.push(child);
114
+ }
115
+ });
116
+ }
117
+ if (newContent.length === 0) {
118
+ newContent.push(paragraphType.create());
119
+ }
120
+ return targetItemNodeType.create({}, _model.Fragment.from(newContent));
121
+ }
122
+ };
123
+
124
+ /**
125
+ * Recursively converts nested lists to the target list type.
126
+ * This function handles the conversion of both the list container and its items,
127
+ * including any nested lists within those items.
128
+ *
129
+ * Important: taskList has a different nesting structure than bulletList/orderedList:
130
+ * - taskList: nested taskLists are SIBLINGS of taskItems in the parent taskList
131
+ * - bulletList/orderedList: nested lists are CHILDREN of listItems
132
+ */
133
+ var _transformList = function transformList(node, targetListType, targetItemType) {
134
+ var schema = node.type.schema;
135
+ var targetListNodeType = schema.nodes[targetListType];
136
+ var targetItemNodeType = schema.nodes[targetItemType];
137
+ var taskListType = schema.nodes.taskList;
138
+ if (!targetListNodeType || !targetItemNodeType) {
139
+ return node;
140
+ }
141
+ var isSourceTaskList = node.type === taskListType;
142
+ var isTargetTaskList = targetListType === 'taskList';
143
+ if (isSourceTaskList && !isTargetTaskList) {
144
+ return convertFromTaskListStructure(node, targetListType, targetItemType);
145
+ } else if (!isSourceTaskList && isTargetTaskList) {
146
+ return convertToTaskListStructure(node, targetListType, targetItemType);
147
+ } else {
148
+ var transformedItems = [];
149
+ node.content.forEach(function (childNode) {
150
+ var transformedItem = isListType(childNode, schema) ? _transformList(childNode, targetListType, targetItemType) : transformListItem(childNode, targetItemType, targetListType);
151
+ if (transformedItem) {
152
+ transformedItems.push(transformedItem);
153
+ }
154
+ });
155
+ return targetListNodeType.create(node.attrs, _model.Fragment.from(transformedItems));
156
+ }
157
+ };
158
+
159
+ /**
160
+ * Transform step that converts between bulletList, orderedList, and taskList types.
161
+ * This step maintains the order and indentation of the list by recursively
162
+ * converting all nested lists while preserving the structure. It also handles
163
+ * conversion between listItem and taskItem types.
164
+ *
165
+ * When converting to taskList/taskItem, unsupported content (images, codeBlocks) is filtered out.
166
+ *
167
+ * @example
168
+ * Input (bulletList with nested bulletList):
169
+ * - bulletList
170
+ * - listItem "1"
171
+ * - bulletList
172
+ * - listItem "1.1"
173
+ * - bulletList
174
+ * - listItem "1.1.1"
175
+ * - listItem "1.2"
176
+ * - listItem "2"
177
+ *
178
+ * Output (orderedList with nested orderedList):
179
+ * 1. orderedList
180
+ * 1. listItem "1"
181
+ * 1. orderedList
182
+ * 1. listItem "1.1"
183
+ * 1. orderedList
184
+ * 1. listItem "1.1.1"
185
+ * 2. listItem "1.2"
186
+ * 2. listItem "2"
187
+ *
188
+ * @example
189
+ * Input (bulletList with nested taskList):
190
+ * - bulletList
191
+ * - listItem "Regular item"
192
+ * - taskList
193
+ * - taskItem "Task 1" (checked)
194
+ * - taskItem "Task 2" (unchecked)
195
+ *
196
+ * Output (orderedList with nested orderedList, taskItems converted to listItems):
197
+ * 1. orderedList
198
+ * 1. listItem "Regular item"
199
+ * 1. orderedList
200
+ * 1. listItem "Task 1"
201
+ * 2. listItem "Task 2"
202
+ *
203
+ * @example
204
+ * Input (bulletList to taskList, with paragraph extraction):
205
+ * - bulletList
206
+ * - listItem
207
+ * - paragraph "Text content"
208
+ * - listItem
209
+ * - paragraph "Text"
210
+ * - codeBlock "code"
211
+ * - mediaSingle (image)
212
+ *
213
+ * Output (taskList with text extracted from paragraphs, unsupported content filtered):
214
+ * - taskList
215
+ * - taskItem "Text content" (text extracted from paragraph)
216
+ * - taskItem "Text" (text extracted, codeBlock and image filtered out)
217
+ *
218
+ * @param nodes - The nodes to transform
219
+ * @param context - The transformation context containing schema and target node type
220
+ * @returns The transformed nodes
221
+ */
222
+ var listToListStep = exports.listToListStep = function listToListStep(nodes, context) {
223
+ var schema = context.schema,
224
+ targetNodeTypeName = context.targetNodeTypeName;
225
+ return nodes.map(function (node) {
226
+ if (isListType(node, schema)) {
227
+ var targetItemType = targetNodeTypeName === 'taskList' ? 'taskItem' : 'listItem';
228
+ return _transformList(node, targetNodeTypeName, targetItemType);
229
+ }
230
+ return node;
231
+ });
232
+ };
@@ -5,16 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getOutputNodes = void 0;
7
7
  var _utils = require("../transform-node-utils/utils");
8
- var _flattenListStep = require("./flattenListStep");
9
8
  var _flattenStep = require("./flattenStep");
10
9
  var _convertBulletListToTextStep = require("./steps/convertBulletListToTextStep");
11
10
  var _convertOrderedListToTextStep = require("./steps/convertOrderedListToTextStep");
12
11
  var _convertTaskListToTextStep = require("./steps/convertTaskListToTextStep");
12
+ var _flattenListStep = require("./steps/flattenListStep");
13
+ var _listToListStep = require("./steps/listToListStep");
13
14
  var _unwrapLayoutStep = require("./steps/unwrapLayoutStep");
15
+ var _unwrapListStep = require("./steps/unwrapListStep");
14
16
  var _stubStep = require("./stubStep");
15
17
  var _types = require("./types");
16
18
  var _unwrapExpandStep = require("./unwrapExpandStep");
17
- var _unwrapListStep = require("./unwrapListStep");
18
19
  var _unwrapStep = require("./unwrapStep");
19
20
  var _wrapIntoLayoutStep = require("./wrapIntoLayoutStep");
20
21
  var _wrapMixedContentStep = require("./wrapMixedContentStep");
@@ -44,7 +45,7 @@ var TRANSFORM_STEPS = {
44
45
  list: {
45
46
  atomic: undefined,
46
47
  container: [_wrapStep.wrapStep],
47
- list: [_stubStep.stubStep],
48
+ list: [_listToListStep.listToListStep],
48
49
  text: [_flattenListStep.flattenListStep, _unwrapListStep.unwrapListStep]
49
50
  },
50
51
  text: {
@@ -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 selection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.sharedState) === null || _api$selection === void 0 || (_api$selection = _api$selection.currentState()) === null || _api$selection === void 0 ? void 0 : _api$selection.selection;
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
- api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
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 = _ref2.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)(config === null || config === void 0 ? void 0 : config.getLinkPath, config === null || config === void 0 ? void 0 : config.blockLinkHashPrefix, api).then(function (success) {
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 (_ref3) {
56
- var tr = _ref3.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
- }, [config === null || config === void 0 ? void 0 : config.getLinkPath, config === null || config === void 0 ? void 0 : config.blockLinkHashPrefix, api, onDropdownOpenChanged]);
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') || checkIsNestedNode() || !!(selection !== null && selection !== void 0 && selection.empty)) {
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 _state = require("@atlaskit/editor-prosemirror/state");
13
- var _editorTables = require("@atlaskit/editor-tables");
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 _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(getLinkPath) {
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
- blockLinkHashPrefix = _args.length > 1 && _args[1] !== undefined ? _args[1] : _blockMenu.DEFAULT_BLOCK_LINK_HASH_PREFIX;
29
- api = _args.length > 2 ? _args[2] : undefined;
30
- _context.prev = 2;
31
- selection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.sharedState.currentState()) === null || _api$selection === void 0 ? void 0 : _api$selection.selection;
32
- if (selection instanceof _state.NodeSelection && selection.node) {
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
- if (path) {
47
- _context.next = 10;
48
- break;
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 = 15;
41
+ _context.next = 14;
56
42
  return (0, _clipboard.copyToClipboard)(href);
57
- case 15:
58
- return _context.abrupt("return", true);
59
- case 18:
60
- _context.prev = 18;
61
- _context.t0 = _context["catch"](2);
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, [[2, 18]]);
59
+ }, _callee, null, [[8, 16]]);
68
60
  }));
69
61
  return function copyLink(_x) {
70
- return _ref.apply(this, arguments);
62
+ return _ref2.apply(this, arguments);
71
63
  };
72
64
  }();
@@ -10,12 +10,10 @@ const extractNestedLists = (node, listTypes, itemTypes, schema) => {
10
10
  child.forEach(grandChild => {
11
11
  if (listTypes.some(type => grandChild.type === type)) {
12
12
  nestedLists.push(grandChild);
13
+ } else if (grandChild.isText) {
14
+ contentWithoutNestedLists.push(paragraph.createAndFill({}, grandChild));
13
15
  } else {
14
- if (grandChild.isText) {
15
- contentWithoutNestedLists.push(paragraph.createAndFill({}, grandChild));
16
- } else {
17
- contentWithoutNestedLists.push(grandChild);
18
- }
16
+ contentWithoutNestedLists.push(grandChild);
19
17
  }
20
18
  });
21
19
  items.push(child.copy(Fragment.from(contentWithoutNestedLists)));