@atlaskit/editor-plugin-paste 1.1.7 → 1.1.9

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,21 @@
1
1
  # @atlaskit/editor-plugin-paste
2
2
 
3
+ ## 1.1.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#97599](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/97599)
8
+ [`32c3130b08fe`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/32c3130b08fe) -
9
+ [ED-22282] Bump adf-schema to 36.1.0
10
+
11
+ ## 1.1.8
12
+
13
+ ### Patch Changes
14
+
15
+ - [#98593](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/98593)
16
+ [`1180c4cbf39b`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1180c4cbf39b) -
17
+ ED-23263: Fixed pasting lose texts aligment
18
+
3
19
  ## 1.1.7
4
20
 
5
21
  ### Patch Changes
@@ -47,7 +47,7 @@ var stopTrackingPastedMacroPositions = exports.stopTrackingPastedMacroPositions
47
47
  var bullets = /^\s*[\*\-\u2022](\s+|\s+$)/;
48
48
  var numbers = /^\s*\d[\.\)](\s+|$)/;
49
49
  var getListType = function getListType(node, schema) {
50
- if (!node.text) {
50
+ if (!node || !node.text) {
51
51
  return null;
52
52
  }
53
53
  var _schema$nodes = schema.nodes,
@@ -97,6 +97,11 @@ var _extractListFromParagraphV2 = exports._extractListFromParagraphV2 = function
97
97
  return node;
98
98
  });
99
99
  var linesSplitByHardbreaks = _contentSplitByHardBreaks(content, schema);
100
+ var _schema$nodes2 = schema.nodes,
101
+ paragraph = _schema$nodes2.paragraph,
102
+ hardBreak = _schema$nodes2.hardBreak,
103
+ listItem = _schema$nodes2.listItem,
104
+ orderedList = _schema$nodes2.orderedList;
100
105
  var splitListsAndParagraphs = [];
101
106
  var paragraphParts = [];
102
107
  for (var index = 0; index < linesSplitByHardbreaks.length; index = index + 1) {
@@ -105,7 +110,7 @@ var _extractListFromParagraphV2 = exports._extractListFromParagraphV2 = function
105
110
  var listMatch = void 0;
106
111
  if (index === 0) {
107
112
  var _line$;
108
- if (((_line$ = line[0]) === null || _line$ === void 0 ? void 0 : _line$.type) === schema.nodes.hardbreak) {
113
+ if (((_line$ = line[0]) === null || _line$ === void 0 ? void 0 : _line$.type) === hardBreak) {
109
114
  paragraphParts.push(line);
110
115
  continue;
111
116
  } else {
@@ -131,10 +136,10 @@ var _extractListFromParagraphV2 = exports._extractListFromParagraphV2 = function
131
136
  nodeType = _listMatch2[0],
132
137
  length = _listMatch2[1];
133
138
  var firstNonHardBreakNode = line.find(function (node) {
134
- return node.type !== schema.nodes.hardBreak;
139
+ return node.type !== hardBreak;
135
140
  });
136
141
  var chunksWithoutLeadingHardBreaks = line.slice(line.findIndex(function (node) {
137
- return node.type !== schema.nodes.hardBreak;
142
+ return node.type !== hardBreak;
138
143
  }));
139
144
 
140
145
  // retain text after bullet or number-dot e.g. 1. Hello
@@ -143,23 +148,23 @@ var _extractListFromParagraphV2 = exports._extractListFromParagraphV2 = function
143
148
  [schema.text(startingText, firstNonHardBreakNode === null || firstNonHardBreakNode === void 0 ? void 0 : firstNonHardBreakNode.marks)].concat((0, _toConsumableArray2.default)(chunksWithoutLeadingHardBreaks.slice(1))) : chunksWithoutLeadingHardBreaks.slice(1);
144
149
 
145
150
  // convert to list
146
- var listItemNode = schema.nodes.listItem.createAndFill(undefined, schema.nodes.paragraph.createChecked(undefined, restOfChunk));
151
+ var listItemNode = listItem.createAndFill(undefined, paragraph.createChecked(undefined, restOfChunk));
147
152
  if (!listItemNode) {
148
153
  paragraphParts.push(line);
149
154
  continue;
150
155
  }
151
- var attrs = nodeType === schema.nodes.orderedList ? {
156
+ var attrs = nodeType === orderedList ? {
152
157
  order: parseInt(firstNonHardBreakNode.text.split('.')[0])
153
158
  } : undefined;
154
159
  var newList = nodeType.createChecked(attrs, [listItemNode]);
155
- if (paragraphParts.length !== 0) {
156
- splitListsAndParagraphs.push(schema.nodes.paragraph.createAndFill(undefined, paragraphParts.flat()));
160
+ if (paragraphParts.length !== 0 && paragraph.validContent(_model.Fragment.from(paragraphParts.flat()))) {
161
+ splitListsAndParagraphs.push(paragraph.createAndFill(node.attrs, paragraphParts.flat(), node.marks));
157
162
  paragraphParts = [];
158
163
  }
159
164
  splitListsAndParagraphs.push(newList);
160
165
  }
161
- if (paragraphParts.length !== 0) {
162
- splitListsAndParagraphs.push(schema.nodes.paragraph.createAndFill(undefined, paragraphParts.flat()));
166
+ if (paragraphParts.length !== 0 && paragraph.validContent(_model.Fragment.from(paragraphParts.flat()))) {
167
+ splitListsAndParagraphs.push(schema.nodes.paragraph.createAndFill(node.attrs, paragraphParts.flat(), node.marks));
163
168
  }
164
169
  var result = splitListsAndParagraphs.flat();
165
170
  // try to join
@@ -197,10 +202,10 @@ var _extractListFromParagraphV2 = exports._extractListFromParagraphV2 = function
197
202
  return fragment;
198
203
  };
199
204
  var extractListFromParagraph = function extractListFromParagraph(node, parent, schema) {
200
- var _schema$nodes2 = schema.nodes,
201
- hardBreak = _schema$nodes2.hardBreak,
202
- bulletList = _schema$nodes2.bulletList,
203
- orderedList = _schema$nodes2.orderedList;
205
+ var _schema$nodes3 = schema.nodes,
206
+ hardBreak = _schema$nodes3.hardBreak,
207
+ bulletList = _schema$nodes3.bulletList,
208
+ orderedList = _schema$nodes3.orderedList;
204
209
  var content = (0, _utils.mapChildren)(node.content, function (node) {
205
210
  return node;
206
211
  });
@@ -351,9 +356,9 @@ var splitIntoParagraphs = exports.splitIntoParagraphs = function splitIntoParagr
351
356
  var paragraphs = [];
352
357
  var curChildren = [];
353
358
  var lastNode = null;
354
- var _schema$nodes3 = schema.nodes,
355
- hardBreak = _schema$nodes3.hardBreak,
356
- paragraph = _schema$nodes3.paragraph;
359
+ var _schema$nodes4 = schema.nodes,
360
+ hardBreak = _schema$nodes4.hardBreak,
361
+ paragraph = _schema$nodes4.paragraph;
357
362
  fragment.forEach(function (node, i) {
358
363
  var isNodeValidContentForParagraph = schema.nodes.paragraph.validContent(_model.Fragment.from(node));
359
364
  if (!isNodeValidContentForParagraph) {
@@ -35,7 +35,7 @@ export const stopTrackingPastedMacroPositions = pastedMacroPositionKeys => creat
35
35
  const bullets = /^\s*[\*\-\u2022](\s+|\s+$)/;
36
36
  const numbers = /^\s*\d[\.\)](\s+|$)/;
37
37
  const getListType = (node, schema) => {
38
- if (!node.text) {
38
+ if (!node || !node.text) {
39
39
  return null;
40
40
  }
41
41
  const {
@@ -84,6 +84,12 @@ export const _contentSplitByHardBreaks = (content, schema) => {
84
84
  export const _extractListFromParagraphV2 = (node, parent, schema) => {
85
85
  const content = mapChildren(node.content, node => node);
86
86
  const linesSplitByHardbreaks = _contentSplitByHardBreaks(content, schema);
87
+ const {
88
+ paragraph,
89
+ hardBreak,
90
+ listItem,
91
+ orderedList
92
+ } = schema.nodes;
87
93
  const splitListsAndParagraphs = [];
88
94
  let paragraphParts = [];
89
95
  for (var index = 0; index < linesSplitByHardbreaks.length; index = index + 1) {
@@ -92,7 +98,7 @@ export const _extractListFromParagraphV2 = (node, parent, schema) => {
92
98
  let listMatch;
93
99
  if (index === 0) {
94
100
  var _line$;
95
- if (((_line$ = line[0]) === null || _line$ === void 0 ? void 0 : _line$.type) === schema.nodes.hardbreak) {
101
+ if (((_line$ = line[0]) === null || _line$ === void 0 ? void 0 : _line$.type) === hardBreak) {
96
102
  paragraphParts.push(line);
97
103
  continue;
98
104
  } else {
@@ -114,8 +120,8 @@ export const _extractListFromParagraphV2 = (node, parent, schema) => {
114
120
  continue;
115
121
  }
116
122
  const [nodeType, length] = listMatch;
117
- const firstNonHardBreakNode = line.find(node => node.type !== schema.nodes.hardBreak);
118
- const chunksWithoutLeadingHardBreaks = line.slice(line.findIndex(node => node.type !== schema.nodes.hardBreak));
123
+ const firstNonHardBreakNode = line.find(node => node.type !== hardBreak);
124
+ const chunksWithoutLeadingHardBreaks = line.slice(line.findIndex(node => node.type !== hardBreak));
119
125
 
120
126
  // retain text after bullet or number-dot e.g. 1. Hello
121
127
  const startingText = firstNonHardBreakNode === null || firstNonHardBreakNode === void 0 ? void 0 : (_firstNonHardBreakNod = firstNonHardBreakNode.text) === null || _firstNonHardBreakNod === void 0 ? void 0 : _firstNonHardBreakNod.substr(length);
@@ -124,23 +130,23 @@ export const _extractListFromParagraphV2 = (node, parent, schema) => {
124
130
  [schema.text(startingText, firstNonHardBreakNode === null || firstNonHardBreakNode === void 0 ? void 0 : firstNonHardBreakNode.marks), ...chunksWithoutLeadingHardBreaks.slice(1)] : chunksWithoutLeadingHardBreaks.slice(1);
125
131
 
126
132
  // convert to list
127
- const listItemNode = schema.nodes.listItem.createAndFill(undefined, schema.nodes.paragraph.createChecked(undefined, restOfChunk));
133
+ const listItemNode = listItem.createAndFill(undefined, paragraph.createChecked(undefined, restOfChunk));
128
134
  if (!listItemNode) {
129
135
  paragraphParts.push(line);
130
136
  continue;
131
137
  }
132
- const attrs = nodeType === schema.nodes.orderedList ? {
138
+ const attrs = nodeType === orderedList ? {
133
139
  order: parseInt(firstNonHardBreakNode.text.split('.')[0])
134
140
  } : undefined;
135
141
  const newList = nodeType.createChecked(attrs, [listItemNode]);
136
- if (paragraphParts.length !== 0) {
137
- splitListsAndParagraphs.push(schema.nodes.paragraph.createAndFill(undefined, paragraphParts.flat()));
142
+ if (paragraphParts.length !== 0 && paragraph.validContent(Fragment.from(paragraphParts.flat()))) {
143
+ splitListsAndParagraphs.push(paragraph.createAndFill(node.attrs, paragraphParts.flat(), node.marks));
138
144
  paragraphParts = [];
139
145
  }
140
146
  splitListsAndParagraphs.push(newList);
141
147
  }
142
- if (paragraphParts.length !== 0) {
143
- splitListsAndParagraphs.push(schema.nodes.paragraph.createAndFill(undefined, paragraphParts.flat()));
148
+ if (paragraphParts.length !== 0 && paragraph.validContent(Fragment.from(paragraphParts.flat()))) {
149
+ splitListsAndParagraphs.push(schema.nodes.paragraph.createAndFill(node.attrs, paragraphParts.flat(), node.marks));
144
150
  }
145
151
  const result = splitListsAndParagraphs.flat();
146
152
  // try to join
@@ -41,7 +41,7 @@ export var stopTrackingPastedMacroPositions = function stopTrackingPastedMacroPo
41
41
  var bullets = /^\s*[\*\-\u2022](\s+|\s+$)/;
42
42
  var numbers = /^\s*\d[\.\)](\s+|$)/;
43
43
  var getListType = function getListType(node, schema) {
44
- if (!node.text) {
44
+ if (!node || !node.text) {
45
45
  return null;
46
46
  }
47
47
  var _schema$nodes = schema.nodes,
@@ -91,6 +91,11 @@ export var _extractListFromParagraphV2 = function _extractListFromParagraphV2(no
91
91
  return node;
92
92
  });
93
93
  var linesSplitByHardbreaks = _contentSplitByHardBreaks(content, schema);
94
+ var _schema$nodes2 = schema.nodes,
95
+ paragraph = _schema$nodes2.paragraph,
96
+ hardBreak = _schema$nodes2.hardBreak,
97
+ listItem = _schema$nodes2.listItem,
98
+ orderedList = _schema$nodes2.orderedList;
94
99
  var splitListsAndParagraphs = [];
95
100
  var paragraphParts = [];
96
101
  for (var index = 0; index < linesSplitByHardbreaks.length; index = index + 1) {
@@ -99,7 +104,7 @@ export var _extractListFromParagraphV2 = function _extractListFromParagraphV2(no
99
104
  var listMatch = void 0;
100
105
  if (index === 0) {
101
106
  var _line$;
102
- if (((_line$ = line[0]) === null || _line$ === void 0 ? void 0 : _line$.type) === schema.nodes.hardbreak) {
107
+ if (((_line$ = line[0]) === null || _line$ === void 0 ? void 0 : _line$.type) === hardBreak) {
103
108
  paragraphParts.push(line);
104
109
  continue;
105
110
  } else {
@@ -125,10 +130,10 @@ export var _extractListFromParagraphV2 = function _extractListFromParagraphV2(no
125
130
  nodeType = _listMatch2[0],
126
131
  length = _listMatch2[1];
127
132
  var firstNonHardBreakNode = line.find(function (node) {
128
- return node.type !== schema.nodes.hardBreak;
133
+ return node.type !== hardBreak;
129
134
  });
130
135
  var chunksWithoutLeadingHardBreaks = line.slice(line.findIndex(function (node) {
131
- return node.type !== schema.nodes.hardBreak;
136
+ return node.type !== hardBreak;
132
137
  }));
133
138
 
134
139
  // retain text after bullet or number-dot e.g. 1. Hello
@@ -137,23 +142,23 @@ export var _extractListFromParagraphV2 = function _extractListFromParagraphV2(no
137
142
  [schema.text(startingText, firstNonHardBreakNode === null || firstNonHardBreakNode === void 0 ? void 0 : firstNonHardBreakNode.marks)].concat(_toConsumableArray(chunksWithoutLeadingHardBreaks.slice(1))) : chunksWithoutLeadingHardBreaks.slice(1);
138
143
 
139
144
  // convert to list
140
- var listItemNode = schema.nodes.listItem.createAndFill(undefined, schema.nodes.paragraph.createChecked(undefined, restOfChunk));
145
+ var listItemNode = listItem.createAndFill(undefined, paragraph.createChecked(undefined, restOfChunk));
141
146
  if (!listItemNode) {
142
147
  paragraphParts.push(line);
143
148
  continue;
144
149
  }
145
- var attrs = nodeType === schema.nodes.orderedList ? {
150
+ var attrs = nodeType === orderedList ? {
146
151
  order: parseInt(firstNonHardBreakNode.text.split('.')[0])
147
152
  } : undefined;
148
153
  var newList = nodeType.createChecked(attrs, [listItemNode]);
149
- if (paragraphParts.length !== 0) {
150
- splitListsAndParagraphs.push(schema.nodes.paragraph.createAndFill(undefined, paragraphParts.flat()));
154
+ if (paragraphParts.length !== 0 && paragraph.validContent(Fragment.from(paragraphParts.flat()))) {
155
+ splitListsAndParagraphs.push(paragraph.createAndFill(node.attrs, paragraphParts.flat(), node.marks));
151
156
  paragraphParts = [];
152
157
  }
153
158
  splitListsAndParagraphs.push(newList);
154
159
  }
155
- if (paragraphParts.length !== 0) {
156
- splitListsAndParagraphs.push(schema.nodes.paragraph.createAndFill(undefined, paragraphParts.flat()));
160
+ if (paragraphParts.length !== 0 && paragraph.validContent(Fragment.from(paragraphParts.flat()))) {
161
+ splitListsAndParagraphs.push(schema.nodes.paragraph.createAndFill(node.attrs, paragraphParts.flat(), node.marks));
157
162
  }
158
163
  var result = splitListsAndParagraphs.flat();
159
164
  // try to join
@@ -191,10 +196,10 @@ export var _extractListFromParagraphV2 = function _extractListFromParagraphV2(no
191
196
  return fragment;
192
197
  };
193
198
  var extractListFromParagraph = function extractListFromParagraph(node, parent, schema) {
194
- var _schema$nodes2 = schema.nodes,
195
- hardBreak = _schema$nodes2.hardBreak,
196
- bulletList = _schema$nodes2.bulletList,
197
- orderedList = _schema$nodes2.orderedList;
199
+ var _schema$nodes3 = schema.nodes,
200
+ hardBreak = _schema$nodes3.hardBreak,
201
+ bulletList = _schema$nodes3.bulletList,
202
+ orderedList = _schema$nodes3.orderedList;
198
203
  var content = mapChildren(node.content, function (node) {
199
204
  return node;
200
205
  });
@@ -345,9 +350,9 @@ export var splitIntoParagraphs = function splitIntoParagraphs(_ref) {
345
350
  var paragraphs = [];
346
351
  var curChildren = [];
347
352
  var lastNode = null;
348
- var _schema$nodes3 = schema.nodes,
349
- hardBreak = _schema$nodes3.hardBreak,
350
- paragraph = _schema$nodes3.paragraph;
353
+ var _schema$nodes4 = schema.nodes,
354
+ hardBreak = _schema$nodes4.hardBreak,
355
+ paragraph = _schema$nodes4.paragraph;
351
356
  fragment.forEach(function (node, i) {
352
357
  var isNodeValidContentForParagraph = schema.nodes.paragraph.validContent(Fragment.from(node));
353
358
  if (!isNodeValidContentForParagraph) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "Paste plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "devDependencies": {
58
58
  "@af/visual-regression": "*",
59
- "@atlaskit/adf-schema": "^35.12.2",
59
+ "@atlaskit/adf-schema": "^36.1.0",
60
60
  "@atlaskit/editor-plugin-block-type": "^3.1.0",
61
61
  "@atlaskit/editor-plugin-history": "^1.1.0",
62
62
  "@atlaskit/editor-plugin-type-ahead": "^1.1.0",