@atlaskit/editor-plugin-paste 0.2.13 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-paste
2
2
 
3
+ ## 0.2.15
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 0.2.14
10
+
11
+ ### Patch Changes
12
+
13
+ - [#68219](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/68219) [`39c60998e4d7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/39c60998e4d7) - ED-21894 Allow partial taskLists to be copied and pasted into a listItem
14
+
3
15
  ## 0.2.13
4
16
 
5
17
  ### Patch Changes
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.insertSliceForLists = insertSliceForLists;
7
7
  exports.insertSliceForListsInsideBlockquote = insertSliceForListsInsideBlockquote;
8
+ exports.insertSliceForTaskInsideList = insertSliceForTaskInsideList;
8
9
  exports.updateSelectionAfterReplace = updateSelectionAfterReplace;
9
10
  var _utils = require("@atlaskit/editor-common/utils");
10
11
  var _model = require("@atlaskit/editor-prosemirror/model");
@@ -97,4 +98,15 @@ function updateSelectionAfterReplace(_ref4) {
97
98
  if (nextSelection) {
98
99
  tr.setSelection(nextSelection);
99
100
  }
101
+ }
102
+ function insertSliceForTaskInsideList(_ref5) {
103
+ var tr = _ref5.tr,
104
+ slice = _ref5.slice;
105
+ var schema = tr.doc.type.schema;
106
+ //To avoid the list being replaced with the tasklist, enclose the slice within a taskItem.
107
+ tr.replaceSelection(new _model.Slice(_model.Fragment.from(schema.nodes.taskItem.createAndFill()), 0, 0));
108
+ updateSelectionAfterReplace({
109
+ tr: tr
110
+ });
111
+ tr.replaceSelection(slice);
100
112
  }
@@ -4,6 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.checkTaskListInList = checkTaskListInList;
7
8
  exports.doesSelectionWhichStartsOrEndsInListContainEntireList = void 0;
8
9
  exports.flattenNestedListInSlice = flattenNestedListInSlice;
9
10
  exports.handleCodeBlock = handleCodeBlock;
@@ -842,7 +843,7 @@ function flattenNestedListInSlice(slice) {
842
843
  }
843
844
  function handleRichText(slice, queueCardsFromChangedTr) {
844
845
  return function (state, dispatch) {
845
- var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre, _slice$content$firstC3;
846
+ var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre;
846
847
  var _state$schema$nodes3 = state.schema.nodes,
847
848
  codeBlock = _state$schema$nodes3.codeBlock,
848
849
  heading = _state$schema$nodes3.heading,
@@ -915,6 +916,11 @@ function handleRichText(slice, queueCardsFromChangedTr) {
915
916
  });
916
917
  if ((0, _utils.insideTableCell)(state) && (0, _utils.isInListItem)(state) && (0, _utils2.canInsert)(selection.$from, slice.content) && (0, _utils2.canInsert)(selection.$to, slice.content) || sliceHasList) {
917
918
  tr.replaceSelection(slice);
919
+ } else if (checkTaskListInList(state, slice)) {
920
+ (0, _edgeCases.insertSliceForTaskInsideList)({
921
+ tr: tr,
922
+ slice: slice
923
+ });
918
924
  } else {
919
925
  // need safeInsert rather than replaceSelection, so that nodes aren't split in half
920
926
  // e.g. when pasting a layout into a table, replaceSelection splits the table in half and adds the layout in the middle
@@ -925,11 +931,6 @@ function handleRichText(slice, queueCardsFromChangedTr) {
925
931
  if (tr.selection.empty && tr.selection.$from.parent.type === codeBlock) {
926
932
  tr.setSelection(_state.TextSelection.near(tr.selection.$from, 1));
927
933
  }
928
- if ((0, _utils.isInListItem)(state) && ['taskList', 'taskItem'].includes(((_slice$content$firstC3 = slice.content.firstChild) === null || _slice$content$firstC3 === void 0 || (_slice$content$firstC3 = _slice$content$firstC3.type) === null || _slice$content$firstC3 === void 0 ? void 0 : _slice$content$firstC3.name) || '')) {
929
- (0, _edgeCases.updateSelectionAfterReplace)({
930
- tr: tr
931
- });
932
- }
933
934
  tr.scrollIntoView();
934
935
 
935
936
  // queue link cards, ignoring any errors
@@ -973,4 +974,8 @@ var handleSelectedTable = exports.handleSelectedTable = function handleSelectedT
973
974
  return false;
974
975
  };
975
976
  };
976
- };
977
+ };
978
+ function checkTaskListInList(state, slice) {
979
+ var _slice$content$firstC3;
980
+ return Boolean((0, _utils.isInListItem)(state) && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.allow-action-in-list') && ['taskList', 'taskItem'].includes(((_slice$content$firstC3 = slice.content.firstChild) === null || _slice$content$firstC3 === void 0 || (_slice$content$firstC3 = _slice$content$firstC3.type) === null || _slice$content$firstC3 === void 0 ? void 0 : _slice$content$firstC3.name) || ''));
981
+ }
@@ -98,4 +98,18 @@ export function updateSelectionAfterReplace({
98
98
  if (nextSelection) {
99
99
  tr.setSelection(nextSelection);
100
100
  }
101
+ }
102
+ export function insertSliceForTaskInsideList({
103
+ tr,
104
+ slice
105
+ }) {
106
+ const {
107
+ schema
108
+ } = tr.doc.type;
109
+ //To avoid the list being replaced with the tasklist, enclose the slice within a taskItem.
110
+ tr.replaceSelection(new Slice(Fragment.from(schema.nodes.taskItem.createAndFill()), 0, 0));
111
+ updateSelectionAfterReplace({
112
+ tr
113
+ });
114
+ tr.replaceSelection(slice);
101
115
  }
@@ -13,7 +13,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
13
13
  // TODO: ED-20519 Needs Macro extraction
14
14
 
15
15
  import { startTrackingPastedMacroPositions, stopTrackingPastedMacroPositions } from './commands';
16
- import { insertSliceForLists, insertSliceForListsInsideBlockquote, updateSelectionAfterReplace } from './edge-cases';
16
+ import { insertSliceForLists, insertSliceForListsInsideBlockquote, insertSliceForTaskInsideList } from './edge-cases';
17
17
  import { getPluginState as getPastePluginState } from './pm-plugins/plugin-factory';
18
18
  import { addReplaceSelectedTableAnalytics, applyTextMarksToSlice, hasOnlyNodesOfType } from './util';
19
19
 
@@ -821,7 +821,7 @@ export function flattenNestedListInSlice(slice) {
821
821
  }
822
822
  export function handleRichText(slice, queueCardsFromChangedTr) {
823
823
  return (state, dispatch) => {
824
- var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre, _slice$content$firstC3, _slice$content$firstC4;
824
+ var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre;
825
825
  const {
826
826
  codeBlock,
827
827
  heading,
@@ -897,6 +897,11 @@ export function handleRichText(slice, queueCardsFromChangedTr) {
897
897
  });
898
898
  if (insideTableCell(state) && isInListItem(state) && canInsert(selection.$from, slice.content) && canInsert(selection.$to, slice.content) || sliceHasList) {
899
899
  tr.replaceSelection(slice);
900
+ } else if (checkTaskListInList(state, slice)) {
901
+ insertSliceForTaskInsideList({
902
+ tr,
903
+ slice
904
+ });
900
905
  } else {
901
906
  // need safeInsert rather than replaceSelection, so that nodes aren't split in half
902
907
  // e.g. when pasting a layout into a table, replaceSelection splits the table in half and adds the layout in the middle
@@ -907,11 +912,6 @@ export function handleRichText(slice, queueCardsFromChangedTr) {
907
912
  if (tr.selection.empty && tr.selection.$from.parent.type === codeBlock) {
908
913
  tr.setSelection(TextSelection.near(tr.selection.$from, 1));
909
914
  }
910
- if (isInListItem(state) && ['taskList', 'taskItem'].includes(((_slice$content$firstC3 = slice.content.firstChild) === null || _slice$content$firstC3 === void 0 ? void 0 : (_slice$content$firstC4 = _slice$content$firstC3.type) === null || _slice$content$firstC4 === void 0 ? void 0 : _slice$content$firstC4.name) || '')) {
911
- updateSelectionAfterReplace({
912
- tr
913
- });
914
- }
915
915
  tr.scrollIntoView();
916
916
 
917
917
  // queue link cards, ignoring any errors
@@ -953,4 +953,8 @@ export const handleSelectedTable = editorAnalyticsAPI => slice => (state, dispat
953
953
  return true;
954
954
  }
955
955
  return false;
956
- };
956
+ };
957
+ export function checkTaskListInList(state, slice) {
958
+ var _slice$content$firstC3, _slice$content$firstC4;
959
+ return Boolean(isInListItem(state) && getBooleanFF('platform.editor.allow-action-in-list') && ['taskList', 'taskItem'].includes(((_slice$content$firstC3 = slice.content.firstChild) === null || _slice$content$firstC3 === void 0 ? void 0 : (_slice$content$firstC4 = _slice$content$firstC3.type) === null || _slice$content$firstC4 === void 0 ? void 0 : _slice$content$firstC4.name) || ''));
960
+ }
@@ -89,4 +89,15 @@ export function updateSelectionAfterReplace(_ref4) {
89
89
  if (nextSelection) {
90
90
  tr.setSelection(nextSelection);
91
91
  }
92
+ }
93
+ export function insertSliceForTaskInsideList(_ref5) {
94
+ var tr = _ref5.tr,
95
+ slice = _ref5.slice;
96
+ var schema = tr.doc.type.schema;
97
+ //To avoid the list being replaced with the tasklist, enclose the slice within a taskItem.
98
+ tr.replaceSelection(new Slice(Fragment.from(schema.nodes.taskItem.createAndFill()), 0, 0));
99
+ updateSelectionAfterReplace({
100
+ tr: tr
101
+ });
102
+ tr.replaceSelection(slice);
92
103
  }
@@ -21,7 +21,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
21
21
  // TODO: ED-20519 Needs Macro extraction
22
22
 
23
23
  import { startTrackingPastedMacroPositions, stopTrackingPastedMacroPositions } from './commands';
24
- import { insertSliceForLists, insertSliceForListsInsideBlockquote, updateSelectionAfterReplace } from './edge-cases';
24
+ import { insertSliceForLists, insertSliceForListsInsideBlockquote, insertSliceForTaskInsideList } from './edge-cases';
25
25
  import { getPluginState as getPastePluginState } from './pm-plugins/plugin-factory';
26
26
  import { addReplaceSelectedTableAnalytics, applyTextMarksToSlice, hasOnlyNodesOfType } from './util';
27
27
 
@@ -821,7 +821,7 @@ export function flattenNestedListInSlice(slice) {
821
821
  }
822
822
  export function handleRichText(slice, queueCardsFromChangedTr) {
823
823
  return function (state, dispatch) {
824
- var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre, _slice$content$firstC3;
824
+ var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre;
825
825
  var _state$schema$nodes3 = state.schema.nodes,
826
826
  codeBlock = _state$schema$nodes3.codeBlock,
827
827
  heading = _state$schema$nodes3.heading,
@@ -894,6 +894,11 @@ export function handleRichText(slice, queueCardsFromChangedTr) {
894
894
  });
895
895
  if (insideTableCell(state) && isInListItem(state) && canInsert(selection.$from, slice.content) && canInsert(selection.$to, slice.content) || sliceHasList) {
896
896
  tr.replaceSelection(slice);
897
+ } else if (checkTaskListInList(state, slice)) {
898
+ insertSliceForTaskInsideList({
899
+ tr: tr,
900
+ slice: slice
901
+ });
897
902
  } else {
898
903
  // need safeInsert rather than replaceSelection, so that nodes aren't split in half
899
904
  // e.g. when pasting a layout into a table, replaceSelection splits the table in half and adds the layout in the middle
@@ -904,11 +909,6 @@ export function handleRichText(slice, queueCardsFromChangedTr) {
904
909
  if (tr.selection.empty && tr.selection.$from.parent.type === codeBlock) {
905
910
  tr.setSelection(TextSelection.near(tr.selection.$from, 1));
906
911
  }
907
- if (isInListItem(state) && ['taskList', 'taskItem'].includes(((_slice$content$firstC3 = slice.content.firstChild) === null || _slice$content$firstC3 === void 0 || (_slice$content$firstC3 = _slice$content$firstC3.type) === null || _slice$content$firstC3 === void 0 ? void 0 : _slice$content$firstC3.name) || '')) {
908
- updateSelectionAfterReplace({
909
- tr: tr
910
- });
911
- }
912
912
  tr.scrollIntoView();
913
913
 
914
914
  // queue link cards, ignoring any errors
@@ -952,4 +952,8 @@ export var handleSelectedTable = function handleSelectedTable(editorAnalyticsAPI
952
952
  return false;
953
953
  };
954
954
  };
955
- };
955
+ };
956
+ export function checkTaskListInList(state, slice) {
957
+ var _slice$content$firstC3;
958
+ return Boolean(isInListItem(state) && getBooleanFF('platform.editor.allow-action-in-list') && ['taskList', 'taskItem'].includes(((_slice$content$firstC3 = slice.content.firstChild) === null || _slice$content$firstC3 === void 0 || (_slice$content$firstC3 = _slice$content$firstC3.type) === null || _slice$content$firstC3 === void 0 ? void 0 : _slice$content$firstC3.name) || ''));
959
+ }
@@ -12,3 +12,7 @@ export declare function insertSliceForListsInsideBlockquote({ tr, slice, }: {
12
12
  export declare function updateSelectionAfterReplace({ tr }: {
13
13
  tr: Transaction;
14
14
  }): Transaction | undefined;
15
+ export declare function insertSliceForTaskInsideList({ tr, slice, }: {
16
+ tr: Transaction;
17
+ slice: PMSlice;
18
+ }): void;
@@ -53,3 +53,4 @@ export declare function flattenNestedListInSlice(slice: Slice): Slice;
53
53
  export declare function handleRichText(slice: Slice, queueCardsFromChangedTr: QueueCardsFromTransactionAction | undefined): Command;
54
54
  export declare function handlePasteIntoCaption(slice: Slice): Command;
55
55
  export declare const handleSelectedTable: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (slice: Slice) => Command;
56
+ export declare function checkTaskListInList(state: EditorState, slice: Slice): boolean;
@@ -12,3 +12,7 @@ export declare function insertSliceForListsInsideBlockquote({ tr, slice, }: {
12
12
  export declare function updateSelectionAfterReplace({ tr }: {
13
13
  tr: Transaction;
14
14
  }): Transaction | undefined;
15
+ export declare function insertSliceForTaskInsideList({ tr, slice, }: {
16
+ tr: Transaction;
17
+ slice: PMSlice;
18
+ }): void;
@@ -53,3 +53,4 @@ export declare function flattenNestedListInSlice(slice: Slice): Slice;
53
53
  export declare function handleRichText(slice: Slice, queueCardsFromChangedTr: QueueCardsFromTransactionAction | undefined): Command;
54
54
  export declare function handlePasteIntoCaption(slice: Slice): Command;
55
55
  export declare const handleSelectedTable: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (slice: Slice) => Command;
56
+ export declare function checkTaskListInList(state: EditorState, slice: Slice): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "description": "Paste plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,17 +33,17 @@
33
33
  ".": "./src/index.ts"
34
34
  },
35
35
  "dependencies": {
36
- "@atlaskit/editor-common": "^77.0.0",
36
+ "@atlaskit/editor-common": "^77.1.0",
37
37
  "@atlaskit/editor-markdown-transformer": "^5.3.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^0.4.0",
39
- "@atlaskit/editor-plugin-annotation": "^0.1.0",
39
+ "@atlaskit/editor-plugin-annotation": "^0.2.0",
40
40
  "@atlaskit/editor-plugin-better-type-history": "^0.1.0",
41
41
  "@atlaskit/editor-plugin-card": "^0.16.0",
42
42
  "@atlaskit/editor-plugin-feature-flags": "^1.0.0",
43
43
  "@atlaskit/editor-plugin-list": "^3.1.0",
44
44
  "@atlaskit/editor-plugin-media": "^0.12.0",
45
45
  "@atlaskit/editor-prosemirror": "1.1.0",
46
- "@atlaskit/editor-tables": "^2.4.0",
46
+ "@atlaskit/editor-tables": "^2.5.0",
47
47
  "@atlaskit/media-client": "^26.1.0",
48
48
  "@atlaskit/media-common": "^11.0.0",
49
49
  "@atlaskit/platform-feature-flags": "^0.2.0",
@@ -119,6 +119,9 @@
119
119
  },
120
120
  "platform.editor.allow-extended-panel": {
121
121
  "type": "boolean"
122
+ },
123
+ "platform.editor.allow-action-in-list": {
124
+ "type": "boolean"
122
125
  }
123
126
  }
124
127
  }