@atlaskit/node-data-provider 6.4.0 → 7.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,23 @@
1
1
  # @atlaskit/node-data-provider
2
2
 
3
+ ## 7.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`be97f10bf8de4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/be97f10bf8de4) -
8
+ [https://product-fabric.atlassian.net/browse/ED-29464](ED-29464) - change findNodesToPrefetch
9
+ algorithm to DFS
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 7.0.0
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+
3
21
  ## 6.4.0
4
22
 
5
23
  ### Minor Changes
@@ -1,13 +1,12 @@
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.findNodesToPrefetch = findNodesToPrefetch;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
7
  /**
10
8
  * Finds nodes in the document that are supported by the given providers, up to a maximum number of nodes.
9
+ * Uses iterative Depth-First Search (DFS) to traverse the document.
11
10
  *
12
11
  * @param doc The document to search for nodes.
13
12
  * @param providers An array of providers with their maximum nodes to prefetch.
@@ -44,15 +43,19 @@ function findNodesToPrefetch(doc, providers, maxNodesToVisit) {
44
43
  };
45
44
  });
46
45
 
47
- // Queue for the breadth-first search (BFS), starting with the root document node.
46
+ // Stack for the depth-first search (DFS), starting with the root document node.
48
47
  var nodesToVisit = [doc];
49
- var currentIndex = 0;
48
+
50
49
  // The loop continues as long as there are nodes to visit, providers to look for,
51
50
  // and the visited nodes limit has not been reached.
52
- while (currentIndex < nodesToVisit.length && providersToLookup.length > 0 && totalVisitedNodesCount < maxNodesToVisit) {
51
+ while (nodesToVisit.length > 0 && providersToLookup.length > 0 && totalVisitedNodesCount < maxNodesToVisit) {
53
52
  totalVisitedNodesCount += 1;
54
- var currentNode = nodesToVisit[currentIndex];
55
- currentIndex++;
53
+ // Pop from the end to maintain DFS order (LIFO - Last In, First Out)
54
+ var currentNode = nodesToVisit.pop();
55
+ if (!currentNode) {
56
+ // This should never happen because of the loop condition, but we check to satisfy TypeScript.
57
+ continue;
58
+ }
56
59
 
57
60
  // Using a reverse loop to avoid issues with array mutation (when removing elements).
58
61
  for (var i = providersToLookup.length - 1; i >= 0; i--) {
@@ -72,11 +75,17 @@ function findNodesToPrefetch(doc, providers, maxNodesToVisit) {
72
75
  }
73
76
  }
74
77
 
75
- // If the current node has children, add them to the queue to be visited.
78
+ // If the current node has children, add them to the stack in reverse order
79
+ // to maintain left-to-right traversal when popping from the stack,
80
+ // because it's LIFO.
76
81
  if (currentNode.content) {
77
- nodesToVisit.push.apply(nodesToVisit, (0, _toConsumableArray2.default)(currentNode.content.filter(function (node) {
78
- return node !== undefined;
79
- })));
82
+ // Push children in reverse order to maintain correct DFS traversal order
83
+ for (var _i = currentNode.content.length - 1; _i >= 0; _i--) {
84
+ var node = currentNode.content[_i];
85
+ if (node) {
86
+ nodesToVisit.push(node);
87
+ }
88
+ }
80
89
  }
81
90
  }
82
91
 
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Finds nodes in the document that are supported by the given providers, up to a maximum number of nodes.
3
+ * Uses iterative Depth-First Search (DFS) to traverse the document.
3
4
  *
4
5
  * @param doc The document to search for nodes.
5
6
  * @param providers An array of providers with their maximum nodes to prefetch.
@@ -35,15 +36,19 @@ export function findNodesToPrefetch(doc, providers, maxNodesToVisit) {
35
36
  foundNodes: 0 // Counter for nodes found for each provider.
36
37
  }));
37
38
 
38
- // Queue for the breadth-first search (BFS), starting with the root document node.
39
+ // Stack for the depth-first search (DFS), starting with the root document node.
39
40
  const nodesToVisit = [doc];
40
- let currentIndex = 0;
41
+
41
42
  // The loop continues as long as there are nodes to visit, providers to look for,
42
43
  // and the visited nodes limit has not been reached.
43
- while (currentIndex < nodesToVisit.length && providersToLookup.length > 0 && totalVisitedNodesCount < maxNodesToVisit) {
44
+ while (nodesToVisit.length > 0 && providersToLookup.length > 0 && totalVisitedNodesCount < maxNodesToVisit) {
44
45
  totalVisitedNodesCount += 1;
45
- const currentNode = nodesToVisit[currentIndex];
46
- currentIndex++;
46
+ // Pop from the end to maintain DFS order (LIFO - Last In, First Out)
47
+ const currentNode = nodesToVisit.pop();
48
+ if (!currentNode) {
49
+ // This should never happen because of the loop condition, but we check to satisfy TypeScript.
50
+ continue;
51
+ }
47
52
 
48
53
  // Using a reverse loop to avoid issues with array mutation (when removing elements).
49
54
  for (let i = providersToLookup.length - 1; i >= 0; i--) {
@@ -63,9 +68,17 @@ export function findNodesToPrefetch(doc, providers, maxNodesToVisit) {
63
68
  }
64
69
  }
65
70
 
66
- // If the current node has children, add them to the queue to be visited.
71
+ // If the current node has children, add them to the stack in reverse order
72
+ // to maintain left-to-right traversal when popping from the stack,
73
+ // because it's LIFO.
67
74
  if (currentNode.content) {
68
- nodesToVisit.push(...currentNode.content.filter(node => node !== undefined));
75
+ // Push children in reverse order to maintain correct DFS traversal order
76
+ for (let i = currentNode.content.length - 1; i >= 0; i--) {
77
+ const node = currentNode.content[i];
78
+ if (node) {
79
+ nodesToVisit.push(node);
80
+ }
81
+ }
69
82
  }
70
83
  }
71
84
 
@@ -1,6 +1,6 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
1
  /**
3
2
  * Finds nodes in the document that are supported by the given providers, up to a maximum number of nodes.
3
+ * Uses iterative Depth-First Search (DFS) to traverse the document.
4
4
  *
5
5
  * @param doc The document to search for nodes.
6
6
  * @param providers An array of providers with their maximum nodes to prefetch.
@@ -37,15 +37,19 @@ export function findNodesToPrefetch(doc, providers, maxNodesToVisit) {
37
37
  };
38
38
  });
39
39
 
40
- // Queue for the breadth-first search (BFS), starting with the root document node.
40
+ // Stack for the depth-first search (DFS), starting with the root document node.
41
41
  var nodesToVisit = [doc];
42
- var currentIndex = 0;
42
+
43
43
  // The loop continues as long as there are nodes to visit, providers to look for,
44
44
  // and the visited nodes limit has not been reached.
45
- while (currentIndex < nodesToVisit.length && providersToLookup.length > 0 && totalVisitedNodesCount < maxNodesToVisit) {
45
+ while (nodesToVisit.length > 0 && providersToLookup.length > 0 && totalVisitedNodesCount < maxNodesToVisit) {
46
46
  totalVisitedNodesCount += 1;
47
- var currentNode = nodesToVisit[currentIndex];
48
- currentIndex++;
47
+ // Pop from the end to maintain DFS order (LIFO - Last In, First Out)
48
+ var currentNode = nodesToVisit.pop();
49
+ if (!currentNode) {
50
+ // This should never happen because of the loop condition, but we check to satisfy TypeScript.
51
+ continue;
52
+ }
49
53
 
50
54
  // Using a reverse loop to avoid issues with array mutation (when removing elements).
51
55
  for (var i = providersToLookup.length - 1; i >= 0; i--) {
@@ -65,11 +69,17 @@ export function findNodesToPrefetch(doc, providers, maxNodesToVisit) {
65
69
  }
66
70
  }
67
71
 
68
- // If the current node has children, add them to the queue to be visited.
72
+ // If the current node has children, add them to the stack in reverse order
73
+ // to maintain left-to-right traversal when popping from the stack,
74
+ // because it's LIFO.
69
75
  if (currentNode.content) {
70
- nodesToVisit.push.apply(nodesToVisit, _toConsumableArray(currentNode.content.filter(function (node) {
71
- return node !== undefined;
72
- })));
76
+ // Push children in reverse order to maintain correct DFS traversal order
77
+ for (var _i = currentNode.content.length - 1; _i >= 0; _i--) {
78
+ var node = currentNode.content[_i];
79
+ if (node) {
80
+ nodesToVisit.push(node);
81
+ }
82
+ }
73
83
  }
74
84
  }
75
85
 
@@ -8,6 +8,7 @@ interface ProviderWithNodes {
8
8
  }
9
9
  /**
10
10
  * Finds nodes in the document that are supported by the given providers, up to a maximum number of nodes.
11
+ * Uses iterative Depth-First Search (DFS) to traverse the document.
11
12
  *
12
13
  * @param doc The document to search for nodes.
13
14
  * @param providers An array of providers with their maximum nodes to prefetch.
@@ -8,6 +8,7 @@ interface ProviderWithNodes {
8
8
  }
9
9
  /**
10
10
  * Finds nodes in the document that are supported by the given providers, up to a maximum number of nodes.
11
+ * Uses iterative Depth-First Search (DFS) to traverse the document.
11
12
  *
12
13
  * @param doc The document to search for nodes.
13
14
  * @param providers An array of providers with their maximum nodes to prefetch.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/node-data-provider",
3
- "version": "6.4.0",
3
+ "version": "7.1.0",
4
4
  "description": "Node data provider for @atlaskit/editor-core plugins and @atlaskit/renderer",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -26,7 +26,7 @@
26
26
  "@babel/runtime": "^7.0.0"
27
27
  },
28
28
  "peerDependencies": {
29
- "@atlaskit/editor-common": "^109.16.0"
29
+ "@atlaskit/editor-common": "^110.4.0"
30
30
  },
31
31
  "techstack": {
32
32
  "@atlassian/frontend": {