@atlaskit/editor-plugin-code-block 3.4.3 → 3.4.4

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,15 @@
1
1
  # @atlaskit/editor-plugin-code-block
2
2
 
3
+ ## 3.4.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#149910](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/149910)
8
+ [`bfb321d2bd9fd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bfb321d2bd9fd) -
9
+ ED-25141 - state.doc.nodesBetween was being called and could go beyond the range of the document
10
+ and therefore throw an error. Occured when entering an inline code snippet with the back quote
11
+ shortcut. See HOT-112305 for more details.
12
+
3
13
  ## 3.4.3
4
14
 
5
15
  ### Patch Changes
@@ -98,7 +98,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
98
98
  // specifically used for updating word wrap node decorators (does not cover drag & drop, validateWordWrappedDecorators does).
99
99
  var updatedDecorationSet = pluginState.decorations.map(tr.mapping, tr.doc);
100
100
  if ((0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping')) {
101
- var codeBlockNodes = (0, _platformFeatureFlags.fg)('editor_code_wrapping_perf_improvement_ed-25141') ? (0, _utils.getAllChangedCodeBlocksInTransaction)(tr, newState) : (0, _utils.getAllCodeBlockNodesInDoc)(newState);
101
+ var codeBlockNodes = (0, _platformFeatureFlags.fg)('editor_code_wrapping_perf_improvement_ed-25141') ? (0, _utils.getAllChangedCodeBlocksInTransaction)(tr) : (0, _utils.getAllCodeBlockNodesInDoc)(newState);
102
102
  if (codeBlockNodes) {
103
103
  if ((0, _platformFeatureFlags.fg)('editor_code_block_wrapping_language_change_bug')) {
104
104
  (0, _codeBlock.updateCodeBlockWrappedStateNodeKeys)(codeBlockNodes, _oldState);
package/dist/cjs/utils.js CHANGED
@@ -44,13 +44,13 @@ function getAllCodeBlockNodesInDoc(state) {
44
44
  });
45
45
  return codeBlockNodes;
46
46
  }
47
- function getAllChangedCodeBlocksInTransaction(tr, state) {
47
+ function getAllChangedCodeBlocksInTransaction(tr) {
48
48
  var changedCodeBlocks = [];
49
49
  var nodePositions = new Set();
50
50
  tr.steps.forEach(function (step) {
51
51
  var mapResult = step.getMap();
52
52
  mapResult.forEach(function (oldStart, oldEnd, newStart, newEnd) {
53
- state.doc.nodesBetween(newStart, newEnd, function (node, pos) {
53
+ tr.doc.nodesBetween(newStart, Math.min(newEnd, tr.doc.content.size), function (node, pos) {
54
54
  if (node.type.name === 'codeBlock') {
55
55
  if (!nodePositions.has(pos)) {
56
56
  nodePositions.add(pos);
@@ -88,7 +88,7 @@ export const createPlugin = ({
88
88
  // specifically used for updating word wrap node decorators (does not cover drag & drop, validateWordWrappedDecorators does).
89
89
  let updatedDecorationSet = pluginState.decorations.map(tr.mapping, tr.doc);
90
90
  if (fg('editor_support_code_block_wrapping')) {
91
- const codeBlockNodes = fg('editor_code_wrapping_perf_improvement_ed-25141') ? getAllChangedCodeBlocksInTransaction(tr, newState) : getAllCodeBlockNodesInDoc(newState);
91
+ const codeBlockNodes = fg('editor_code_wrapping_perf_improvement_ed-25141') ? getAllChangedCodeBlocksInTransaction(tr) : getAllCodeBlockNodesInDoc(newState);
92
92
  if (codeBlockNodes) {
93
93
  if (fg('editor_code_block_wrapping_language_change_bug')) {
94
94
  updateCodeBlockWrappedStateNodeKeys(codeBlockNodes, _oldState);
@@ -18,13 +18,13 @@ export function getAllCodeBlockNodesInDoc(state) {
18
18
  });
19
19
  return codeBlockNodes;
20
20
  }
21
- export function getAllChangedCodeBlocksInTransaction(tr, state) {
21
+ export function getAllChangedCodeBlocksInTransaction(tr) {
22
22
  const changedCodeBlocks = [];
23
23
  const nodePositions = new Set();
24
24
  tr.steps.forEach(step => {
25
25
  const mapResult = step.getMap();
26
26
  mapResult.forEach((oldStart, oldEnd, newStart, newEnd) => {
27
- state.doc.nodesBetween(newStart, newEnd, (node, pos) => {
27
+ tr.doc.nodesBetween(newStart, Math.min(newEnd, tr.doc.content.size), (node, pos) => {
28
28
  if (node.type.name === 'codeBlock') {
29
29
  if (!nodePositions.has(pos)) {
30
30
  nodePositions.add(pos);
@@ -93,7 +93,7 @@ export var createPlugin = function createPlugin(_ref) {
93
93
  // specifically used for updating word wrap node decorators (does not cover drag & drop, validateWordWrappedDecorators does).
94
94
  var updatedDecorationSet = pluginState.decorations.map(tr.mapping, tr.doc);
95
95
  if (fg('editor_support_code_block_wrapping')) {
96
- var codeBlockNodes = fg('editor_code_wrapping_perf_improvement_ed-25141') ? getAllChangedCodeBlocksInTransaction(tr, newState) : getAllCodeBlockNodesInDoc(newState);
96
+ var codeBlockNodes = fg('editor_code_wrapping_perf_improvement_ed-25141') ? getAllChangedCodeBlocksInTransaction(tr) : getAllCodeBlockNodesInDoc(newState);
97
97
  if (codeBlockNodes) {
98
98
  if (fg('editor_code_block_wrapping_language_change_bug')) {
99
99
  updateCodeBlockWrappedStateNodeKeys(codeBlockNodes, _oldState);
package/dist/esm/utils.js CHANGED
@@ -18,13 +18,13 @@ export function getAllCodeBlockNodesInDoc(state) {
18
18
  });
19
19
  return codeBlockNodes;
20
20
  }
21
- export function getAllChangedCodeBlocksInTransaction(tr, state) {
21
+ export function getAllChangedCodeBlocksInTransaction(tr) {
22
22
  var changedCodeBlocks = [];
23
23
  var nodePositions = new Set();
24
24
  tr.steps.forEach(function (step) {
25
25
  var mapResult = step.getMap();
26
26
  mapResult.forEach(function (oldStart, oldEnd, newStart, newEnd) {
27
- state.doc.nodesBetween(newStart, newEnd, function (node, pos) {
27
+ tr.doc.nodesBetween(newStart, Math.min(newEnd, tr.doc.content.size), function (node, pos) {
28
28
  if (node.type.name === 'codeBlock') {
29
29
  if (!nodePositions.has(pos)) {
30
30
  nodePositions.add(pos);
@@ -4,4 +4,4 @@ import type { EditorState, ReadonlyTransaction, Selection } from '@atlaskit/edit
4
4
  import type { NodeWithPos } from '@atlaskit/editor-prosemirror/utils';
5
5
  export declare function getCursor(selection: Selection): ResolvedPos | undefined;
6
6
  export declare function getAllCodeBlockNodesInDoc(state: EditorState): NodeWithPos[];
7
- export declare function getAllChangedCodeBlocksInTransaction(tr: ReadonlyTransaction, state: EditorState): NodeWithPos[] | null;
7
+ export declare function getAllChangedCodeBlocksInTransaction(tr: ReadonlyTransaction): NodeWithPos[] | null;
@@ -4,4 +4,4 @@ import type { EditorState, ReadonlyTransaction, Selection } from '@atlaskit/edit
4
4
  import type { NodeWithPos } from '@atlaskit/editor-prosemirror/utils';
5
5
  export declare function getCursor(selection: Selection): ResolvedPos | undefined;
6
6
  export declare function getAllCodeBlockNodesInDoc(state: EditorState): NodeWithPos[];
7
- export declare function getAllChangedCodeBlocksInTransaction(tr: ReadonlyTransaction, state: EditorState): NodeWithPos[] | null;
7
+ export declare function getAllChangedCodeBlocksInTransaction(tr: ReadonlyTransaction): NodeWithPos[] | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block",
3
- "version": "3.4.3",
3
+ "version": "3.4.4",
4
4
  "description": "Code block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -39,7 +39,7 @@
39
39
  "@atlaskit/editor-plugin-decorations": "^1.3.0",
40
40
  "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
41
41
  "@atlaskit/editor-prosemirror": "6.0.0",
42
- "@atlaskit/icon": "^22.20.0",
42
+ "@atlaskit/icon": "^22.22.0",
43
43
  "@atlaskit/platform-feature-flags": "^0.3.0",
44
44
  "@atlaskit/prosemirror-input-rules": "^3.2.0",
45
45
  "@babel/runtime": "^7.0.0",