@atlaskit/editor-plugin-paste 11.2.8 → 12.0.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,19 @@
1
1
  # @atlaskit/editor-plugin-paste
2
2
 
3
+ ## 12.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 11.2.9
10
+
11
+ ### Patch Changes
12
+
13
+ - [`52a08b0d14e39`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/52a08b0d14e39) -
14
+ Add code block language auto-detection experiment
15
+ - Updated dependencies
16
+
3
17
  ## 11.2.8
4
18
 
5
19
  ### Patch Changes
@@ -1,68 +1,17 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.normalizePastedCodeBlockAttrs = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
7
  var _codeBlock = require("@atlaskit/editor-common/code-block");
10
- var _transform = require("@atlaskit/editor-prosemirror/transform");
11
- var isReplaceStep = function isReplaceStep(step) {
12
- return step instanceof _transform.ReplaceStep || step instanceof _transform.ReplaceAroundStep;
8
+ var isCodeBlockWithUnsetWrap = function isCodeBlockWithUnsetWrap(node) {
9
+ return node.attrs.wrap === null;
13
10
  };
14
- var isCodeBlockWithUnsetWrap = function isCodeBlockWithUnsetWrap(node, codeBlockType) {
15
- return node.type === codeBlockType && node.attrs.wrap === null;
16
- };
17
- var collectInsertedCodeBlocksWithUnsetWrap = function collectInsertedCodeBlocksWithUnsetWrap(step, codeBlockType) {
18
- var insertedCodeBlocks = new Set();
19
- step.slice.content.descendants(function (node) {
20
- if (isCodeBlockWithUnsetWrap(node, codeBlockType)) {
21
- insertedCodeBlocks.add(node);
22
- return false;
23
- }
24
- return true;
25
- });
26
- return insertedCodeBlocks;
27
- };
28
- var collectMappedInsertedRanges = function collectMappedInsertedRanges(tr, stepIndex) {
29
- var ranges = [];
30
- var stepMap = tr.mapping.maps[stepIndex];
31
- var remainingMaps = tr.mapping.slice(stepIndex + 1);
32
- stepMap.forEach(function (_oldStart, _oldEnd, newStart, newEnd) {
33
- if (newStart === newEnd) {
34
- return;
35
- }
36
- var finalFrom = remainingMaps.map(newStart, 1);
37
- var finalTo = remainingMaps.map(newEnd, -1);
38
- if (finalFrom < finalTo) {
39
- ranges.push([finalFrom, finalTo]);
40
- }
41
- });
42
- return ranges;
43
- };
44
- var collectInsertedCodeBlockPositions = function collectInsertedCodeBlockPositions(tr, ranges, insertedCodeBlocks) {
45
- var positions = new Set();
46
- ranges.forEach(function (_ref) {
47
- var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
48
- from = _ref2[0],
49
- to = _ref2[1];
50
- tr.doc.nodesBetween(from, to, function (node, pos) {
51
- if (insertedCodeBlocks.has(node)) {
52
- positions.add(pos);
53
- return false;
54
- }
55
- return true;
56
- });
57
- });
58
- return positions;
59
- };
60
- var patchInsertedCodeBlocks = function patchInsertedCodeBlocks(tr, positionsToPatch, insertedCodeBlocks) {
61
- positionsToPatch.forEach(function (pos) {
62
- var node = tr.doc.nodeAt(pos);
63
- if (!node || !insertedCodeBlocks.has(node)) {
64
- return;
65
- }
11
+ var patchInsertedCodeBlocks = function patchInsertedCodeBlocks(tr, insertedCodeBlocks) {
12
+ insertedCodeBlocks.forEach(function (_ref) {
13
+ var node = _ref.node,
14
+ pos = _ref.pos;
66
15
  tr.setNodeMarkup(pos, undefined, (0, _codeBlock.getDefaultCodeBlockAttrs)(node.attrs), node.marks);
67
16
  });
68
17
  };
@@ -70,25 +19,11 @@ var normalizePastedCodeBlockAttrs = exports.normalizePastedCodeBlockAttrs = func
70
19
  if (!codeBlockType) {
71
20
  return tr;
72
21
  }
73
- var insertedCodeBlocks = new Set();
74
- var positionsToPatch = new Set();
75
- tr.steps.forEach(function (step, index) {
76
- if (!isReplaceStep(step)) {
77
- return;
78
- }
79
- var codeBlocksInsertedByStep = collectInsertedCodeBlocksWithUnsetWrap(step, codeBlockType);
80
- if (!codeBlocksInsertedByStep.size) {
81
- return;
82
- }
83
- codeBlocksInsertedByStep.forEach(function (node) {
84
- return insertedCodeBlocks.add(node);
85
- });
86
- collectInsertedCodeBlockPositions(tr, collectMappedInsertedRanges(tr, index), codeBlocksInsertedByStep).forEach(function (pos) {
87
- return positionsToPatch.add(pos);
88
- });
22
+ var insertedCodeBlocks = (0, _codeBlock.getInsertedCodeBlocksInTransaction)(tr, codeBlockType, {
23
+ filter: isCodeBlockWithUnsetWrap
89
24
  });
90
- if (positionsToPatch.size) {
91
- patchInsertedCodeBlocks(tr, positionsToPatch, insertedCodeBlocks);
25
+ if (insertedCodeBlocks.length) {
26
+ patchInsertedCodeBlocks(tr, insertedCodeBlocks);
92
27
  }
93
28
  return tr;
94
29
  };
@@ -1,53 +1,10 @@
1
- import { getDefaultCodeBlockAttrs } from '@atlaskit/editor-common/code-block';
2
- import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
3
- const isReplaceStep = step => step instanceof ReplaceStep || step instanceof ReplaceAroundStep;
4
- const isCodeBlockWithUnsetWrap = (node, codeBlockType) => node.type === codeBlockType && node.attrs.wrap === null;
5
- const collectInsertedCodeBlocksWithUnsetWrap = (step, codeBlockType) => {
6
- const insertedCodeBlocks = new Set();
7
- step.slice.content.descendants(node => {
8
- if (isCodeBlockWithUnsetWrap(node, codeBlockType)) {
9
- insertedCodeBlocks.add(node);
10
- return false;
11
- }
12
- return true;
13
- });
14
- return insertedCodeBlocks;
15
- };
16
- const collectMappedInsertedRanges = (tr, stepIndex) => {
17
- const ranges = [];
18
- const stepMap = tr.mapping.maps[stepIndex];
19
- const remainingMaps = tr.mapping.slice(stepIndex + 1);
20
- stepMap.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
21
- if (newStart === newEnd) {
22
- return;
23
- }
24
- const finalFrom = remainingMaps.map(newStart, 1);
25
- const finalTo = remainingMaps.map(newEnd, -1);
26
- if (finalFrom < finalTo) {
27
- ranges.push([finalFrom, finalTo]);
28
- }
29
- });
30
- return ranges;
31
- };
32
- const collectInsertedCodeBlockPositions = (tr, ranges, insertedCodeBlocks) => {
33
- const positions = new Set();
34
- ranges.forEach(([from, to]) => {
35
- tr.doc.nodesBetween(from, to, (node, pos) => {
36
- if (insertedCodeBlocks.has(node)) {
37
- positions.add(pos);
38
- return false;
39
- }
40
- return true;
41
- });
42
- });
43
- return positions;
44
- };
45
- const patchInsertedCodeBlocks = (tr, positionsToPatch, insertedCodeBlocks) => {
46
- positionsToPatch.forEach(pos => {
47
- const node = tr.doc.nodeAt(pos);
48
- if (!node || !insertedCodeBlocks.has(node)) {
49
- return;
50
- }
1
+ import { getDefaultCodeBlockAttrs, getInsertedCodeBlocksInTransaction } from '@atlaskit/editor-common/code-block';
2
+ const isCodeBlockWithUnsetWrap = node => node.attrs.wrap === null;
3
+ const patchInsertedCodeBlocks = (tr, insertedCodeBlocks) => {
4
+ insertedCodeBlocks.forEach(({
5
+ node,
6
+ pos
7
+ }) => {
51
8
  tr.setNodeMarkup(pos, undefined, getDefaultCodeBlockAttrs(node.attrs), node.marks);
52
9
  });
53
10
  };
@@ -55,21 +12,11 @@ export const normalizePastedCodeBlockAttrs = (tr, codeBlockType) => {
55
12
  if (!codeBlockType) {
56
13
  return tr;
57
14
  }
58
- const insertedCodeBlocks = new Set();
59
- const positionsToPatch = new Set();
60
- tr.steps.forEach((step, index) => {
61
- if (!isReplaceStep(step)) {
62
- return;
63
- }
64
- const codeBlocksInsertedByStep = collectInsertedCodeBlocksWithUnsetWrap(step, codeBlockType);
65
- if (!codeBlocksInsertedByStep.size) {
66
- return;
67
- }
68
- codeBlocksInsertedByStep.forEach(node => insertedCodeBlocks.add(node));
69
- collectInsertedCodeBlockPositions(tr, collectMappedInsertedRanges(tr, index), codeBlocksInsertedByStep).forEach(pos => positionsToPatch.add(pos));
15
+ const insertedCodeBlocks = getInsertedCodeBlocksInTransaction(tr, codeBlockType, {
16
+ filter: isCodeBlockWithUnsetWrap
70
17
  });
71
- if (positionsToPatch.size) {
72
- patchInsertedCodeBlocks(tr, positionsToPatch, insertedCodeBlocks);
18
+ if (insertedCodeBlocks.length) {
19
+ patchInsertedCodeBlocks(tr, insertedCodeBlocks);
73
20
  }
74
21
  return tr;
75
22
  };
@@ -1,61 +1,11 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import { getDefaultCodeBlockAttrs } from '@atlaskit/editor-common/code-block';
3
- import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
4
- var isReplaceStep = function isReplaceStep(step) {
5
- return step instanceof ReplaceStep || step instanceof ReplaceAroundStep;
1
+ import { getDefaultCodeBlockAttrs, getInsertedCodeBlocksInTransaction } from '@atlaskit/editor-common/code-block';
2
+ var isCodeBlockWithUnsetWrap = function isCodeBlockWithUnsetWrap(node) {
3
+ return node.attrs.wrap === null;
6
4
  };
7
- var isCodeBlockWithUnsetWrap = function isCodeBlockWithUnsetWrap(node, codeBlockType) {
8
- return node.type === codeBlockType && node.attrs.wrap === null;
9
- };
10
- var collectInsertedCodeBlocksWithUnsetWrap = function collectInsertedCodeBlocksWithUnsetWrap(step, codeBlockType) {
11
- var insertedCodeBlocks = new Set();
12
- step.slice.content.descendants(function (node) {
13
- if (isCodeBlockWithUnsetWrap(node, codeBlockType)) {
14
- insertedCodeBlocks.add(node);
15
- return false;
16
- }
17
- return true;
18
- });
19
- return insertedCodeBlocks;
20
- };
21
- var collectMappedInsertedRanges = function collectMappedInsertedRanges(tr, stepIndex) {
22
- var ranges = [];
23
- var stepMap = tr.mapping.maps[stepIndex];
24
- var remainingMaps = tr.mapping.slice(stepIndex + 1);
25
- stepMap.forEach(function (_oldStart, _oldEnd, newStart, newEnd) {
26
- if (newStart === newEnd) {
27
- return;
28
- }
29
- var finalFrom = remainingMaps.map(newStart, 1);
30
- var finalTo = remainingMaps.map(newEnd, -1);
31
- if (finalFrom < finalTo) {
32
- ranges.push([finalFrom, finalTo]);
33
- }
34
- });
35
- return ranges;
36
- };
37
- var collectInsertedCodeBlockPositions = function collectInsertedCodeBlockPositions(tr, ranges, insertedCodeBlocks) {
38
- var positions = new Set();
39
- ranges.forEach(function (_ref) {
40
- var _ref2 = _slicedToArray(_ref, 2),
41
- from = _ref2[0],
42
- to = _ref2[1];
43
- tr.doc.nodesBetween(from, to, function (node, pos) {
44
- if (insertedCodeBlocks.has(node)) {
45
- positions.add(pos);
46
- return false;
47
- }
48
- return true;
49
- });
50
- });
51
- return positions;
52
- };
53
- var patchInsertedCodeBlocks = function patchInsertedCodeBlocks(tr, positionsToPatch, insertedCodeBlocks) {
54
- positionsToPatch.forEach(function (pos) {
55
- var node = tr.doc.nodeAt(pos);
56
- if (!node || !insertedCodeBlocks.has(node)) {
57
- return;
58
- }
5
+ var patchInsertedCodeBlocks = function patchInsertedCodeBlocks(tr, insertedCodeBlocks) {
6
+ insertedCodeBlocks.forEach(function (_ref) {
7
+ var node = _ref.node,
8
+ pos = _ref.pos;
59
9
  tr.setNodeMarkup(pos, undefined, getDefaultCodeBlockAttrs(node.attrs), node.marks);
60
10
  });
61
11
  };
@@ -63,25 +13,11 @@ export var normalizePastedCodeBlockAttrs = function normalizePastedCodeBlockAttr
63
13
  if (!codeBlockType) {
64
14
  return tr;
65
15
  }
66
- var insertedCodeBlocks = new Set();
67
- var positionsToPatch = new Set();
68
- tr.steps.forEach(function (step, index) {
69
- if (!isReplaceStep(step)) {
70
- return;
71
- }
72
- var codeBlocksInsertedByStep = collectInsertedCodeBlocksWithUnsetWrap(step, codeBlockType);
73
- if (!codeBlocksInsertedByStep.size) {
74
- return;
75
- }
76
- codeBlocksInsertedByStep.forEach(function (node) {
77
- return insertedCodeBlocks.add(node);
78
- });
79
- collectInsertedCodeBlockPositions(tr, collectMappedInsertedRanges(tr, index), codeBlocksInsertedByStep).forEach(function (pos) {
80
- return positionsToPatch.add(pos);
81
- });
16
+ var insertedCodeBlocks = getInsertedCodeBlocksInTransaction(tr, codeBlockType, {
17
+ filter: isCodeBlockWithUnsetWrap
82
18
  });
83
- if (positionsToPatch.size) {
84
- patchInsertedCodeBlocks(tr, positionsToPatch, insertedCodeBlocks);
19
+ if (insertedCodeBlocks.length) {
20
+ patchInsertedCodeBlocks(tr, insertedCodeBlocks);
85
21
  }
86
22
  return tr;
87
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste",
3
- "version": "11.2.8",
3
+ "version": "12.0.0",
4
4
  "description": "Paste plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -30,15 +30,15 @@
30
30
  "@atlaskit/adf-schema": "^52.15.0",
31
31
  "@atlaskit/code": "^17.5.0",
32
32
  "@atlaskit/editor-markdown-transformer": "^5.21.0",
33
- "@atlaskit/editor-plugin-analytics": "^10.1.0",
34
- "@atlaskit/editor-plugin-annotation": "^10.5.0",
35
- "@atlaskit/editor-plugin-better-type-history": "^10.1.0",
36
- "@atlaskit/editor-plugin-card": "^16.11.0",
37
- "@atlaskit/editor-plugin-expand": "^11.2.0",
38
- "@atlaskit/editor-plugin-feature-flags": "^9.1.0",
39
- "@atlaskit/editor-plugin-list": "^12.1.0",
40
- "@atlaskit/editor-plugin-media": "^12.9.0",
41
- "@atlaskit/editor-plugin-mentions": "^12.3.0",
33
+ "@atlaskit/editor-plugin-analytics": "^11.0.0",
34
+ "@atlaskit/editor-plugin-annotation": "^11.0.0",
35
+ "@atlaskit/editor-plugin-better-type-history": "^11.0.0",
36
+ "@atlaskit/editor-plugin-card": "^17.0.0",
37
+ "@atlaskit/editor-plugin-expand": "^12.0.0",
38
+ "@atlaskit/editor-plugin-feature-flags": "^10.0.0",
39
+ "@atlaskit/editor-plugin-list": "^13.0.0",
40
+ "@atlaskit/editor-plugin-media": "^13.0.0",
41
+ "@atlaskit/editor-plugin-mentions": "^13.0.0",
42
42
  "@atlaskit/editor-prosemirror": "^7.3.0",
43
43
  "@atlaskit/editor-tables": "^2.10.0",
44
44
  "@atlaskit/flag": "^17.12.0",
@@ -48,14 +48,14 @@
48
48
  "@atlaskit/media-common": "^13.3.0",
49
49
  "@atlaskit/platform-feature-flags": "^1.1.0",
50
50
  "@atlaskit/prosemirror-history": "^0.2.0",
51
- "@atlaskit/tmp-editor-statsig": "^86.0.0",
51
+ "@atlaskit/tmp-editor-statsig": "^88.0.0",
52
52
  "@atlaskit/tokens": "^13.1.0",
53
53
  "@babel/runtime": "^7.0.0",
54
54
  "lodash": "^4.17.21",
55
55
  "uuid": "^3.1.0"
56
56
  },
57
57
  "peerDependencies": {
58
- "@atlaskit/editor-common": "^114.54.0",
58
+ "@atlaskit/editor-common": "^115.0.0",
59
59
  "react": "^18.2.0",
60
60
  "react-dom": "^18.2.0",
61
61
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"