@atlaskit/editor-plugin-paste 31.0.4 → 31.1.0

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,24 @@
1
1
  # @atlaskit/editor-plugin-paste
2
2
 
3
+ ## 31.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`7821cf2be124c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7821cf2be124c) -
8
+ Keep pasted text inside panels, expands and lists when the copied paragraph has an alignment or
9
+ indentation the destination does not allow (behind
10
+ platform_editor_paste_strip_invalid_block_marks)
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
16
+ ## 31.0.5
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies
21
+
3
22
  ## 31.0.4
4
23
 
5
24
  ### Patch Changes
@@ -1136,6 +1136,17 @@ function getTopLevelMarkTypesInSlice(slice) {
1136
1136
  return markTypes;
1137
1137
  }
1138
1138
 
1139
+ /**
1140
+ * Whether the slice's top-level block marks (e.g. alignment, indentation) include one that the
1141
+ * node containing the destination textblock does not allow, such as alignment inside a panel.
1142
+ */
1143
+ function sliceHasBlockMarksDisallowedAtDestination(slice, $from) {
1144
+ var destinationContainer = $from.node(Math.max(0, $from.depth - 1));
1145
+ return (0, _toConsumableArray2.default)(getTopLevelMarkTypesInSlice(slice)).some(function (markType) {
1146
+ return !destinationContainer.type.allowsMarkType(markType);
1147
+ });
1148
+ }
1149
+
1139
1150
  /**
1140
1151
  * Peels container wrapper nodes (e.g. panel, expand) added by ProseMirror's addContext()
1141
1152
  * so that fontSize-marked paragraphs become top-level, preserving the mark on paste.
@@ -1273,7 +1284,13 @@ function handleParagraphBlockMarks(state, slice) {
1273
1284
  // so pasted content adopts the destination list state.
1274
1285
  var destinationHasContent = $from.parent.textContent.length > 0;
1275
1286
  if (slice.content.childCount === 1 && destinationHasContent && !shouldNormalizeFontSizeForTarget) {
1276
- return slice;
1287
+ var _slice$content$firstC4;
1288
+ // A paragraph keeping a block mark its destination container disallows cannot be placed
1289
+ // inside that container, so it is inserted after it instead. Drop those marks below.
1290
+ var mustDropDisallowedBlockMarks = (0, _fg.fg)('platform_editor_paste_strip_invalid_block_marks') && ((_slice$content$firstC4 = slice.content.firstChild) === null || _slice$content$firstC4 === void 0 ? void 0 : _slice$content$firstC4.type) === paragraph && sliceHasBlockMarksDisallowedAtDestination(slice, $from);
1291
+ if (!mustDropDisallowedBlockMarks) {
1292
+ return slice;
1293
+ }
1277
1294
  }
1278
1295
 
1279
1296
  // Check the parent of (paragraph -> text) because block marks are assigned to a wrapper
@@ -1608,8 +1625,8 @@ var handleSelectedTable = exports.handleSelectedTable = function handleSelectedT
1608
1625
  };
1609
1626
  };
1610
1627
  function checkTaskListInList(state, slice) {
1611
- var _slice$content$firstC4;
1612
- return Boolean((0, _utils.isInListItem)(state) && ['taskList', 'taskItem'].includes(((_slice$content$firstC4 = slice.content.firstChild) === null || _slice$content$firstC4 === void 0 || (_slice$content$firstC4 = _slice$content$firstC4.type) === null || _slice$content$firstC4 === void 0 ? void 0 : _slice$content$firstC4.name) || ''));
1628
+ var _slice$content$firstC5;
1629
+ return Boolean((0, _utils.isInListItem)(state) && ['taskList', 'taskItem'].includes(((_slice$content$firstC5 = slice.content.firstChild) === null || _slice$content$firstC5 === void 0 || (_slice$content$firstC5 = _slice$content$firstC5.type) === null || _slice$content$firstC5 === void 0 ? void 0 : _slice$content$firstC5.name) || ''));
1613
1630
  }
1614
1631
  function checkIfSelectionInNestedList(state) {
1615
1632
  var selection = state.selection,
@@ -1127,6 +1127,15 @@ function getTopLevelMarkTypesInSlice(slice) {
1127
1127
  return markTypes;
1128
1128
  }
1129
1129
 
1130
+ /**
1131
+ * Whether the slice's top-level block marks (e.g. alignment, indentation) include one that the
1132
+ * node containing the destination textblock does not allow, such as alignment inside a panel.
1133
+ */
1134
+ function sliceHasBlockMarksDisallowedAtDestination(slice, $from) {
1135
+ const destinationContainer = $from.node(Math.max(0, $from.depth - 1));
1136
+ return [...getTopLevelMarkTypesInSlice(slice)].some(markType => !destinationContainer.type.allowsMarkType(markType));
1137
+ }
1138
+
1130
1139
  /**
1131
1140
  * Peels container wrapper nodes (e.g. panel, expand) added by ProseMirror's addContext()
1132
1141
  * so that fontSize-marked paragraphs become top-level, preserving the mark on paste.
@@ -1265,7 +1274,13 @@ export function handleParagraphBlockMarks(state, slice) {
1265
1274
  // so pasted content adopts the destination list state.
1266
1275
  const destinationHasContent = $from.parent.textContent.length > 0;
1267
1276
  if (slice.content.childCount === 1 && destinationHasContent && !shouldNormalizeFontSizeForTarget) {
1268
- return slice;
1277
+ var _slice$content$firstC4;
1278
+ // A paragraph keeping a block mark its destination container disallows cannot be placed
1279
+ // inside that container, so it is inserted after it instead. Drop those marks below.
1280
+ const mustDropDisallowedBlockMarks = fg('platform_editor_paste_strip_invalid_block_marks') && ((_slice$content$firstC4 = slice.content.firstChild) === null || _slice$content$firstC4 === void 0 ? void 0 : _slice$content$firstC4.type) === paragraph && sliceHasBlockMarksDisallowedAtDestination(slice, $from);
1281
+ if (!mustDropDisallowedBlockMarks) {
1282
+ return slice;
1283
+ }
1269
1284
  }
1270
1285
 
1271
1286
  // Check the parent of (paragraph -> text) because block marks are assigned to a wrapper
@@ -1577,8 +1592,8 @@ export const handleSelectedTable = editorAnalyticsAPI => slice => (state, dispat
1577
1592
  return false;
1578
1593
  };
1579
1594
  export function checkTaskListInList(state, slice) {
1580
- var _slice$content$firstC4, _slice$content$firstC5;
1581
- return Boolean(isInListItem(state) && ['taskList', 'taskItem'].includes(((_slice$content$firstC4 = slice.content.firstChild) === null || _slice$content$firstC4 === void 0 ? void 0 : (_slice$content$firstC5 = _slice$content$firstC4.type) === null || _slice$content$firstC5 === void 0 ? void 0 : _slice$content$firstC5.name) || ''));
1595
+ var _slice$content$firstC5, _slice$content$firstC6;
1596
+ return Boolean(isInListItem(state) && ['taskList', 'taskItem'].includes(((_slice$content$firstC5 = slice.content.firstChild) === null || _slice$content$firstC5 === void 0 ? void 0 : (_slice$content$firstC6 = _slice$content$firstC5.type) === null || _slice$content$firstC6 === void 0 ? void 0 : _slice$content$firstC6.name) || ''));
1582
1597
  }
1583
1598
  export function checkIfSelectionInNestedList(state) {
1584
1599
  const {
@@ -1107,6 +1107,17 @@ function getTopLevelMarkTypesInSlice(slice) {
1107
1107
  return markTypes;
1108
1108
  }
1109
1109
 
1110
+ /**
1111
+ * Whether the slice's top-level block marks (e.g. alignment, indentation) include one that the
1112
+ * node containing the destination textblock does not allow, such as alignment inside a panel.
1113
+ */
1114
+ function sliceHasBlockMarksDisallowedAtDestination(slice, $from) {
1115
+ var destinationContainer = $from.node(Math.max(0, $from.depth - 1));
1116
+ return _toConsumableArray(getTopLevelMarkTypesInSlice(slice)).some(function (markType) {
1117
+ return !destinationContainer.type.allowsMarkType(markType);
1118
+ });
1119
+ }
1120
+
1110
1121
  /**
1111
1122
  * Peels container wrapper nodes (e.g. panel, expand) added by ProseMirror's addContext()
1112
1123
  * so that fontSize-marked paragraphs become top-level, preserving the mark on paste.
@@ -1244,7 +1255,13 @@ export function handleParagraphBlockMarks(state, slice) {
1244
1255
  // so pasted content adopts the destination list state.
1245
1256
  var destinationHasContent = $from.parent.textContent.length > 0;
1246
1257
  if (slice.content.childCount === 1 && destinationHasContent && !shouldNormalizeFontSizeForTarget) {
1247
- return slice;
1258
+ var _slice$content$firstC4;
1259
+ // A paragraph keeping a block mark its destination container disallows cannot be placed
1260
+ // inside that container, so it is inserted after it instead. Drop those marks below.
1261
+ var mustDropDisallowedBlockMarks = fg('platform_editor_paste_strip_invalid_block_marks') && ((_slice$content$firstC4 = slice.content.firstChild) === null || _slice$content$firstC4 === void 0 ? void 0 : _slice$content$firstC4.type) === paragraph && sliceHasBlockMarksDisallowedAtDestination(slice, $from);
1262
+ if (!mustDropDisallowedBlockMarks) {
1263
+ return slice;
1264
+ }
1248
1265
  }
1249
1266
 
1250
1267
  // Check the parent of (paragraph -> text) because block marks are assigned to a wrapper
@@ -1579,8 +1596,8 @@ export var handleSelectedTable = function handleSelectedTable(editorAnalyticsAPI
1579
1596
  };
1580
1597
  };
1581
1598
  export function checkTaskListInList(state, slice) {
1582
- var _slice$content$firstC4;
1583
- return Boolean(isInListItem(state) && ['taskList', 'taskItem'].includes(((_slice$content$firstC4 = slice.content.firstChild) === null || _slice$content$firstC4 === void 0 || (_slice$content$firstC4 = _slice$content$firstC4.type) === null || _slice$content$firstC4 === void 0 ? void 0 : _slice$content$firstC4.name) || ''));
1599
+ var _slice$content$firstC5;
1600
+ return Boolean(isInListItem(state) && ['taskList', 'taskItem'].includes(((_slice$content$firstC5 = slice.content.firstChild) === null || _slice$content$firstC5 === void 0 || (_slice$content$firstC5 = _slice$content$firstC5.type) === null || _slice$content$firstC5 === void 0 ? void 0 : _slice$content$firstC5.name) || ''));
1584
1601
  }
1585
1602
  export function checkIfSelectionInNestedList(state) {
1586
1603
  var selection = state.selection,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste",
3
- "version": "31.0.4",
3
+ "version": "31.1.0",
4
4
  "description": "Paste plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@
31
31
  "@atlaskit/editor-plugin-extension": "^33.0.0",
32
32
  "@atlaskit/editor-plugin-feature-flags": "^29.0.0",
33
33
  "@atlaskit/editor-plugin-list": "^32.0.0",
34
- "@atlaskit/editor-plugin-media": "^32.1.0",
34
+ "@atlaskit/editor-plugin-media": "^32.2.0",
35
35
  "@atlaskit/editor-plugin-mentions": "^32.0.0",
36
36
  "@atlaskit/editor-prosemirror": "^9.0.0",
37
37
  "@atlaskit/editor-tables": "^3.2.0",
@@ -44,14 +44,14 @@
44
44
  "@atlaskit/platform-feature-experiments": "^0.3.0",
45
45
  "@atlaskit/platform-feature-flags": "^2.2.0",
46
46
  "@atlaskit/prosemirror-history": "^1.3.0",
47
- "@atlaskit/tmp-editor-statsig": "^248.0.0",
48
- "@atlaskit/tokens": "^20.8.0",
47
+ "@atlaskit/tmp-editor-statsig": "^250.0.0",
48
+ "@atlaskit/tokens": "^20.9.0",
49
49
  "@babel/runtime": "^7.0.0",
50
50
  "lodash": "^4.17.21",
51
51
  "uuid": "^11.1.1"
52
52
  },
53
53
  "peerDependencies": {
54
- "@atlaskit/editor-common": "^134.2.0",
54
+ "@atlaskit/editor-common": "^134.3.0",
55
55
  "react": "^18.2.0 || ^19.2.0",
56
56
  "react-dom": "^18.2.0 || ^19.2.0",
57
57
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
@@ -73,6 +73,9 @@
73
73
  },
74
74
  "platform_media_cross_client_copy_with_auth": {
75
75
  "type": "boolean"
76
+ },
77
+ "platform_editor_paste_strip_invalid_block_marks": {
78
+ "type": "boolean"
76
79
  }
77
80
  },
78
81
  "platform-experiments": {