jqtree 1.7.5 → 1.8.1

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.
Files changed (119) hide show
  1. package/.eslintrc +13 -3
  2. package/.github/workflows/ci.yml +6 -6
  3. package/.github/workflows/codeql-analysis.yml +4 -4
  4. package/.github/workflows/size.yml +3 -3
  5. package/.github/workflows/static.yml +1 -1
  6. package/bower.json +1 -1
  7. package/config/babel.config.json +1 -1
  8. package/config/jest.config.js +4 -0
  9. package/config/jest.polyfills.js +14 -0
  10. package/config/production +2 -0
  11. package/devserver/devserver_scroll.js +8 -0
  12. package/devserver/test_index.html +9 -0
  13. package/devserver/test_scroll.html +28 -0
  14. package/devserver/test_scroll_container.html +39 -0
  15. package/docs/.ruby-version +1 -1
  16. package/docs/_config.yml +1 -1
  17. package/docs/_entries/general/changelog.md +11 -0
  18. package/docs/_entries/multiple_selection/get-selected-nodes.md +1 -1
  19. package/docs/_entries/node/getnextnode.md +3 -6
  20. package/docs/_entries/node/getnextsibling.md +1 -1
  21. package/docs/_entries/node/getnextvisiblenode.md +8 -5
  22. package/docs/_entries/node/getpreviousnode.md +12 -0
  23. package/docs/_entries/node/getprevioussibling.md +1 -1
  24. package/docs/_entries/node/getpreviousvisiblenode.md +6 -5
  25. package/package.json +35 -29
  26. package/src/dataLoader.ts +57 -34
  27. package/src/dragAndDropHandler/dragElement.ts +54 -0
  28. package/src/dragAndDropHandler/generateHitAreas.ts +176 -0
  29. package/src/dragAndDropHandler/index.ts +454 -0
  30. package/src/dragAndDropHandler/iterateVisibleNodes.ts +91 -0
  31. package/src/dragAndDropHandler/types.ts +13 -0
  32. package/src/elementsRenderer.ts +75 -40
  33. package/src/jqtreeMethodTypes.ts +40 -0
  34. package/src/jqtreeOptions.ts +43 -25
  35. package/src/keyHandler.ts +59 -30
  36. package/src/mouseHandler.ts +385 -0
  37. package/src/mouseUtils.ts +23 -0
  38. package/src/node.ts +1 -29
  39. package/src/nodeElement/borderDropHint.ts +32 -0
  40. package/src/nodeElement/folderElement.ts +133 -0
  41. package/src/nodeElement/ghostDropHint.ts +69 -0
  42. package/src/nodeElement/index.ts +102 -0
  43. package/src/playwright/coverage.ts +4 -7
  44. package/src/playwright/playwright.test.ts +150 -53
  45. package/src/playwright/testUtils.ts +28 -5
  46. package/src/position.ts +28 -0
  47. package/src/saveStateHandler.ts +75 -26
  48. package/src/scrollHandler/containerScrollParent.ts +13 -23
  49. package/src/scrollHandler/createScrollParent.ts +22 -22
  50. package/src/scrollHandler/documentScrollParent.ts +16 -13
  51. package/src/scrollHandler.ts +13 -15
  52. package/src/selectNodeHandler.ts +10 -16
  53. package/src/test/jqTree/events.test.ts +97 -30
  54. package/src/test/jqTree/keyboard.test.ts +18 -23
  55. package/src/test/jqTree/loadOnDemand.test.ts +22 -15
  56. package/src/test/jqTree/methods.test.ts +40 -14
  57. package/src/test/jqTree/mouse.test.ts +82 -0
  58. package/src/test/jqTree/options.test.ts +24 -12
  59. package/src/test/node.test.ts +3 -2
  60. package/src/test/{nodeUtil.test.ts → position.test.ts} +1 -1
  61. package/src/tree.jquery.ts +314 -208
  62. package/src/util.ts +12 -0
  63. package/src/version.ts +1 -1
  64. package/tree.jquery.debug.js +2594 -3419
  65. package/tree.jquery.debug.js.map +1 -1
  66. package/tree.jquery.js +3 -3
  67. package/tree.jquery.js.map +1 -1
  68. package/tsconfig.json +5 -3
  69. package/docs/_entries/functions/get-selected-nodes.md +0 -10
  70. package/lib/dataLoader.js +0 -123
  71. package/lib/dragAndDropHandler.js +0 -588
  72. package/lib/elementsRenderer.js +0 -267
  73. package/lib/jqtreeOptions.js +0 -1
  74. package/lib/keyHandler.js +0 -111
  75. package/lib/mouse.widget.js +0 -255
  76. package/lib/node.js +0 -708
  77. package/lib/nodeElement.js +0 -274
  78. package/lib/nodeUtils.js +0 -10
  79. package/lib/playwright/coverage.js +0 -99
  80. package/lib/playwright/playwright.test.js +0 -606
  81. package/lib/playwright/testUtils.js +0 -210
  82. package/lib/saveStateHandler.js +0 -277
  83. package/lib/scrollHandler/containerScrollParent.js +0 -160
  84. package/lib/scrollHandler/createScrollParent.js +0 -57
  85. package/lib/scrollHandler/documentScrollParent.js +0 -169
  86. package/lib/scrollHandler/scrollParent.js +0 -58
  87. package/lib/scrollHandler/types.js +0 -1
  88. package/lib/scrollHandler.js +0 -71
  89. package/lib/selectNodeHandler.js +0 -128
  90. package/lib/simple.widget.js +0 -158
  91. package/lib/test/global.d.js +0 -3
  92. package/lib/test/jqTree/accessibility.test.js +0 -37
  93. package/lib/test/jqTree/create.test.js +0 -48
  94. package/lib/test/jqTree/events.test.js +0 -210
  95. package/lib/test/jqTree/keyboard.test.js +0 -225
  96. package/lib/test/jqTree/loadOnDemand.test.js +0 -218
  97. package/lib/test/jqTree/methods.test.js +0 -1348
  98. package/lib/test/jqTree/options.test.js +0 -548
  99. package/lib/test/jqTree/scrollHandler/containerScrollParent.test.js +0 -94
  100. package/lib/test/node.test.js +0 -1202
  101. package/lib/test/nodeUtil.test.js +0 -27
  102. package/lib/test/nodeUtils.test.js +0 -20
  103. package/lib/test/support/exampleData.js +0 -35
  104. package/lib/test/support/jqTreeMatchers.js +0 -70
  105. package/lib/test/support/matchers.d.js +0 -1
  106. package/lib/test/support/setupTests.js +0 -7
  107. package/lib/test/support/testUtil.js +0 -29
  108. package/lib/test/support/treeStructure.js +0 -38
  109. package/lib/test/util.test.js +0 -26
  110. package/lib/tree.jquery.d.js +0 -1
  111. package/lib/tree.jquery.js +0 -1105
  112. package/lib/types.js +0 -1
  113. package/lib/typings.d.js +0 -2
  114. package/lib/util.js +0 -15
  115. package/lib/version.js +0 -8
  116. package/src/dragAndDropHandler.ts +0 -713
  117. package/src/mouse.widget.ts +0 -266
  118. package/src/nodeElement.ts +0 -272
  119. package/src/types.ts +0 -19
package/.eslintrc CHANGED
@@ -6,8 +6,7 @@
6
6
  "plugin:@typescript-eslint/eslint-recommended",
7
7
  "plugin:@typescript-eslint/recommended",
8
8
  "plugin:@typescript-eslint/recommended-requiring-type-checking",
9
- "plugin:import/errors",
10
- "plugin:import/warnings",
9
+ "plugin:import/recommended",
11
10
  "plugin:import/typescript"
12
11
  ],
13
12
  "rules": {
@@ -33,6 +32,17 @@
33
32
  ]
34
33
  },
35
34
  "parserOptions": {
36
- "project": "./tsconfig.json",
35
+ "project": "./tsconfig.json"
36
+ },
37
+ "settings": {
38
+ "import/parsers": {
39
+ "@typescript-eslint/parser": [".ts"]
40
+ },
41
+ "import/resolver": {
42
+ "typescript": {
43
+ "alwaysTryTypes": true,
44
+ "project": "./tsconfig.json"
45
+ }
46
+ }
37
47
  }
38
48
  }
@@ -8,25 +8,25 @@ jobs:
8
8
 
9
9
  steps:
10
10
  - name: Check out repository code
11
- uses: actions/checkout@v3
11
+ uses: actions/checkout@v4
12
12
  - name: Setup node
13
- uses: actions/setup-node@v3
13
+ uses: actions/setup-node@v4
14
14
  with:
15
- node-version: 16
15
+ node-version: "20"
16
16
  - name: Install pnpm
17
17
  run: npm install -g pnpm
18
18
  - name: Get pnpm store directory
19
19
  id: pnpm-cache
20
20
  run: |
21
21
  echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
22
- - uses: actions/cache@v3
22
+ - uses: actions/cache@v4
23
23
  name: Setup pnpm cache
24
24
  with:
25
25
  path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
26
26
  key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
27
27
  restore-keys: |
28
28
  ${{ runner.os }}-pnpm-store-
29
- - uses: actions/cache@v3
29
+ - uses: actions/cache@v4
30
30
  name: Setup Playwright browsers cache
31
31
  with:
32
32
  path: /home/runner/.cache/ms-playwright/
@@ -55,7 +55,7 @@ jobs:
55
55
  run: pnpm run playwright
56
56
  - name: Screenshots artifact
57
57
  if: always()
58
- uses: actions/upload-artifact@v3
58
+ uses: actions/upload-artifact@v4
59
59
  with:
60
60
  name: screenshots
61
61
  path: src/playwright/playwright.test.ts-snapshots/
@@ -18,15 +18,15 @@ jobs:
18
18
 
19
19
  steps:
20
20
  - name: Checkout repository
21
- uses: actions/checkout@v3
21
+ uses: actions/checkout@v4
22
22
 
23
23
  - name: Initialize CodeQL
24
- uses: github/codeql-action/init@v2
24
+ uses: github/codeql-action/init@v3
25
25
  with:
26
26
  languages: ${{ matrix.language }}
27
27
 
28
28
  - name: Autobuild
29
- uses: github/codeql-action/autobuild@v2
29
+ uses: github/codeql-action/autobuild@v3
30
30
 
31
31
  - name: Perform CodeQL Analysis
32
- uses: github/codeql-action/analyze@v2
32
+ uses: github/codeql-action/analyze@v3
@@ -7,11 +7,11 @@ jobs:
7
7
 
8
8
  steps:
9
9
  - name: Check out repository code
10
- uses: actions/checkout@v3
10
+ uses: actions/checkout@v4
11
11
  - name: Setup node
12
- uses: actions/setup-node@v3
12
+ uses: actions/setup-node@v4
13
13
  with:
14
- node-version: 16
14
+ node-version: "20"
15
15
  - name: Install pnpm
16
16
  run: npm install -g pnpm
17
17
  - name: Install packages
@@ -31,7 +31,7 @@ jobs:
31
31
  - name: Setup node
32
32
  uses: actions/setup-node@v3
33
33
  with:
34
- node-version: 16
34
+ node-version: 20
35
35
  - name: Install pnpm
36
36
  run: npm install -g pnpm
37
37
  - name: Install ruby packages
package/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jqTree",
3
- "version": "1.7.5",
3
+ "version": "1.8.1",
4
4
  "main": [
5
5
  "jqtree.css",
6
6
  "jqtree-circle.png",
@@ -4,7 +4,7 @@
4
4
  "test": {
5
5
  "presets": [
6
6
  "@babel/preset-typescript",
7
- ["@babel/preset-env", { "targets": { "node": "current" } }]
7
+ "@babel/preset-env"
8
8
  ]
9
9
  }
10
10
  }
@@ -12,7 +12,11 @@ module.exports = {
12
12
  "givens/setup.js",
13
13
  "jest-extended/all",
14
14
  ],
15
+ setupFiles: ["<rootDir>/config/jest.polyfills.js"],
15
16
  testEnvironment: "jsdom",
17
+ testEnvironmentOptions: {
18
+ customExportConditions: [""],
19
+ },
16
20
  testRegex: "\\/src\\/test\\/.*\\.test\\.ts",
17
21
  transform: {
18
22
  "\\.tsx?$": ["babel-jest", { root: __dirname }],
@@ -0,0 +1,14 @@
1
+ const { TextEncoder, TextDecoder } = require("node:util");
2
+
3
+ Reflect.set(globalThis, "TextEncoder", TextEncoder);
4
+ Reflect.set(globalThis, "TextDecoder", TextDecoder);
5
+
6
+ const { Blob } = require("node:buffer");
7
+ const { fetch, Request, Response, Headers, FormData } = require("undici");
8
+
9
+ Reflect.set(globalThis, "fetch", fetch);
10
+ Reflect.set(globalThis, "Blob", Blob);
11
+ Reflect.set(globalThis, "Request", Request);
12
+ Reflect.set(globalThis, "Response", Response);
13
+ Reflect.set(globalThis, "Headers", Headers);
14
+ Reflect.set(globalThis, "FormData", FormData);
package/config/production CHANGED
@@ -1,3 +1,5 @@
1
+ rm -rf ./lib &&
2
+ mkdir lib &&
1
3
  rollup -c config/rollup.config.mjs &&
2
4
  DEBUG_BUILD=true rollup -c config/rollup.config.mjs &&
3
5
  babel src --config-file ./config/babel.config.json --out-dir lib --extensions .ts &&
@@ -0,0 +1,8 @@
1
+ const $tree = $("#tree1");
2
+
3
+ $tree.tree({
4
+ autoOpen: true,
5
+ data: ExampleData.exampleData,
6
+ dragAndDrop: true,
7
+ useContextMenu: false,
8
+ });
@@ -6,6 +6,15 @@
6
6
  <script src="/bower_components/jquery/dist/jquery.min.js"></script>
7
7
  <script src="tree.jquery.js"></script>
8
8
  <script src="/example_data.js"></script>
9
+ <style>
10
+ .wide-tree {
11
+ font-size: 20px;
12
+ }
13
+
14
+ .wide-tree ul.jqtree-tree ul.jqtree_common {
15
+ margin-left: 128px;
16
+ }
17
+ </style>
9
18
  </head>
10
19
  <body>
11
20
  <div id="tree1"></div>
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>JqTree devserver</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <meta
8
+ name="description"
9
+ content="JqTree is a jQuery widget for displaying a tree structure in html"
10
+ />
11
+ <link rel="stylesheet" href="/jqtree.css" />
12
+ <style>
13
+ body {
14
+ font-size: 20px;
15
+ }
16
+ ul.jqtree-tree ul.jqtree_common {
17
+ margin-left: 128px;
18
+ }
19
+ </style>
20
+ </head>
21
+ <body>
22
+ <div id="tree1"></div>
23
+ </body>
24
+ <script src="/bower_components/jquery/dist/jquery.min.js"></script>
25
+ <script src="/tree.jquery.js"></script>
26
+ <script src="/example_data.js"></script>
27
+ <script src="/devserver_scroll.js"></script>
28
+ </html>
@@ -0,0 +1,39 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>JqTree devserver</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <meta
8
+ name="description"
9
+ content="JqTree is a jQuery widget for displaying a tree structure in html"
10
+ />
11
+ <link rel="stylesheet" href="/jqtree.css" />
12
+ <style>
13
+ body {
14
+ font-size: 20px;
15
+ }
16
+ ul.jqtree-tree ul.jqtree_common {
17
+ margin-left: 128px;
18
+ }
19
+ #scroll-container {
20
+ height: 200px;
21
+ width: 400px;
22
+ overflow-y: scroll;
23
+ user-select: none;
24
+ background-color: #eee;
25
+ margin: 128px;
26
+ padding: 8px;
27
+ }
28
+ </style>
29
+ </head>
30
+ <body>
31
+ <div id="scroll-container">
32
+ <div id="tree1"></div>
33
+ </div>
34
+ </body>
35
+ <script src="/bower_components/jquery/dist/jquery.min.js"></script>
36
+ <script src="/tree.jquery.js"></script>
37
+ <script src="/example_data.js"></script>
38
+ <script src="/devserver_scroll.js"></script>
39
+ </html>
@@ -1 +1 @@
1
- 3.2.2
1
+ 3.2.3
package/docs/_config.yml CHANGED
@@ -118,7 +118,7 @@ defaults:
118
118
  values:
119
119
  layout: "example"
120
120
 
121
- jqtree_version: 1.7.5
121
+ jqtree_version: 1.8.1
122
122
 
123
123
  # Build settings
124
124
  markdown: kramdown
@@ -3,6 +3,17 @@ title: Changelog
3
3
  name: changelog
4
4
  ---
5
5
 
6
+ #### 1.8.1 (march 16 2024)
7
+
8
+ - Issue #791: fix onCanMoveTo (thanks to Christophe Caron)
9
+
10
+ #### 1.8.0 (november 26 2023)
11
+
12
+ This release drops support for very old browsers (like IE 11).
13
+
14
+ - Issue #735: compile to es6. This decreases the file size to 49K (from 62K). This is the minified (not gzipped) version.
15
+ - Issue #766: open parent nodes in the addToSelection method (thanks to Tmgarcia)
16
+
6
17
  #### 1.7.5 (october 21 2023)
7
18
 
8
19
  - Issue #734: fix autoscroll issue (thanks to WriterStat)
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: getSelectedNodes
3
- name: multiple-get-selected-nodes
3
+ name: multiple-selection-get-selected-nodes
4
4
  ---
5
5
 
6
6
  Get the selected nodes. Return an array of nodes
@@ -3,13 +3,10 @@ title: getNextNode
3
3
  name: node-functions-getnextnode
4
4
  ---
5
5
 
6
- Get the next node in the tree.
6
+ Get the next node in the tree. This is the next sibling, if there is one. Or, if there is no next sibling, a node further down in the tree.
7
7
 
8
- - If the node has children, return the first child.
9
- - If the node is the last child, return the next sibling of the parent.
10
-
11
- Returns a node or null.
8
+ - Returns a node or null.
12
9
 
13
10
  {% highlight js %}
14
- var node = node.getNextNode();
11
+ const nextNode = node.getNextNode();
15
12
  {% endhighlight %}
@@ -6,5 +6,5 @@ name: node-functions-getnextsibling
6
6
  Get the next sibling of this node. Returns a node or null.
7
7
 
8
8
  {% highlight js %}
9
- var node = node.getNextSibling();
9
+ const nextSibling = node.getNextSibling();
10
10
  {% endhighlight %}
@@ -1,12 +1,15 @@
1
1
  ---
2
- title: getPreviousNode
3
- name: node-functions-getpreviousnode
2
+ title: getNextVisibleNode
3
+ name: node-functions-getnextvisiblenode
4
4
  ---
5
5
 
6
- Return the previous node in the tree.
6
+ Get the next visible node in the tree. Does the same as using the _down_ key.
7
7
 
8
- Returns a node or null.
8
+ This is the previous sibling, if there is one. Or, if there is no previous sibling, a node further up in the tree that is visible.
9
+
10
+ - Returns a node or null.
11
+ - A node is visible if all its parents are open.
9
12
 
10
13
  {% highlight js %}
11
- var node = node.getPreviousNode();
14
+ const nextNode = node.getNextVisibleNode();
12
15
  {% endhighlight %}
@@ -0,0 +1,12 @@
1
+ ---
2
+ title: getPreviousNode
3
+ name: node-functions-getpreviousnode
4
+ ---
5
+
6
+ Return the previous node in the tree. This is the previous sibling, if there is one. Or, if there is no previous sibling, a node further up in the tree.
7
+
8
+ - Returns a node or null.
9
+
10
+ {% highlight js %}
11
+ const previousNode = node.getPreviousNode();
12
+ {% endhighlight %}
@@ -6,5 +6,5 @@ name: node-functions-getprevioussibling
6
6
  Get the previous sibling of this node. Returns a node or null.
7
7
 
8
8
  {% highlight js %}
9
- var node = node.getPreviousSibling();
9
+ const previousSibling = node.getPreviousSibling();
10
10
  {% endhighlight %}
@@ -3,12 +3,13 @@ title: getPreviousVisibleNode
3
3
  name: node-functions-getpreviousvisiblenode
4
4
  ---
5
5
 
6
- - Get the previous visible node in the tree. Does the same as using the _up_ key.
7
- - If the previous node is an open parent: return the last child of the node.
8
- - If the previous node is a closed parent: skip the child nodes of the previous parent, return the previous parent node.
6
+ Get the previous visible node in the tree. Does the same as using the _up_ key.
9
7
 
10
- Returns a node or null.
8
+ This is the previous sibling, if there is one. Or, if there is no previous sibling, a node further up in the tree that is visible.
9
+
10
+ - Returns a node or null.
11
+ - A node is visible if all its parents are open.
11
12
 
12
13
  {% highlight js %}
13
- var node = node.getPreviousVisibleNode();
14
+ const previousNode = node.getPreviousVisibleNode();
14
15
  {% endhighlight %}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jqtree",
3
- "version": "1.7.5",
3
+ "version": "1.8.1",
4
4
  "description": "Tree widget for jQuery",
5
5
  "keywords": [
6
6
  "jquery-plugin",
@@ -28,34 +28,39 @@
28
28
  "playwright": "pnpm build-with-coverage && playwright test --config config/playwright.config.js",
29
29
  "test": "pnpm jest && pnpm playwright"
30
30
  },
31
+ "browserslist": [
32
+ "defaults"
33
+ ],
31
34
  "peerDependencies": {
32
35
  "jquery": "^3"
33
36
  },
34
37
  "devDependencies": {
35
- "@babel/cli": "^7.23.0",
36
- "@babel/core": "^7.23.2",
37
- "@babel/preset-env": "^7.23.2",
38
- "@babel/preset-typescript": "^7.23.2",
39
- "@playwright/test": "^1.39.0",
38
+ "@babel/cli": "^7.23.9",
39
+ "@babel/core": "^7.23.9",
40
+ "@babel/preset-env": "^7.23.9",
41
+ "@babel/preset-typescript": "^7.23.3",
42
+ "@playwright/test": "^1.41.2",
40
43
  "@rollup/plugin-babel": "^6.0.4",
41
44
  "@rollup/plugin-node-resolve": "^15.2.3",
42
45
  "@rollup/plugin-terser": "^0.4.4",
43
- "@testing-library/dom": "^9.3.3",
44
- "@types/debug": "^4.1.10",
45
- "@types/jest": "^29.5.6",
46
- "@types/jest-axe": "^3.5.7",
47
- "@types/jquery": "^3.5.24",
48
- "@types/node": "^20.8.7",
49
- "@typescript-eslint/eslint-plugin": "^6.8.0",
50
- "@typescript-eslint/parser": "^6.8.0",
51
- "autoprefixer": "^10.4.16",
46
+ "@testing-library/dom": "^9.3.4",
47
+ "@testing-library/user-event": "^14.5.2",
48
+ "@types/debug": "^4.1.12",
49
+ "@types/jest": "^29.5.12",
50
+ "@types/jest-axe": "^3.5.9",
51
+ "@types/jquery": "^3.5.29",
52
+ "@types/node": "^20.11.19",
53
+ "@typescript-eslint/eslint-plugin": "^7.0.1",
54
+ "@typescript-eslint/parser": "^7.0.1",
55
+ "autoprefixer": "^10.4.17",
52
56
  "babel-jest": "^29.7.0",
53
57
  "babel-plugin-istanbul": "^6.1.1",
54
- "eslint": "^8.52.0",
55
- "eslint-plugin-import": "^2.28.1",
56
- "eslint-plugin-jest": "^27.4.3",
57
- "eslint-plugin-playwright": "^0.17.0",
58
- "eslint-plugin-testing-library": "^6.1.0",
58
+ "eslint": "^8.56.0",
59
+ "eslint-import-resolver-typescript": "^3.6.1",
60
+ "eslint-plugin-import": "^2.29.1",
61
+ "eslint-plugin-jest": "^27.9.0",
62
+ "eslint-plugin-playwright": "^1.1.2",
63
+ "eslint-plugin-testing-library": "^6.2.0",
59
64
  "givens": "^1.3.9",
60
65
  "graphql": "^16.8.1",
61
66
  "jest": "^29.7.0",
@@ -64,16 +69,17 @@
64
69
  "jest-extended": "^4.0.2",
65
70
  "jsonfile": "^6.1.0",
66
71
  "lodash.template": "^4.5.0",
67
- "msw": "^1.3.2",
68
- "postcss": "^8.4.31",
69
- "postcss-cli": "^10.1.0",
70
- "postcss-import": "^15.1.0",
71
- "postcss-load-config": "^4.0.1",
72
+ "msw": "^2.2.1",
73
+ "postcss": "^8.4.35",
74
+ "postcss-cli": "^11.0.0",
75
+ "postcss-import": "^16.0.1",
76
+ "postcss-load-config": "^5.0.3",
72
77
  "postcss-nested": "^6.0.1",
73
- "prettier": "^3.0.3",
74
- "rollup": "^4.1.4",
75
- "rollup-plugin-serve": "^2.0.2",
78
+ "prettier": "^3.2.5",
79
+ "rollup": "^4.12.0",
80
+ "rollup-plugin-serve": "^3.0.0",
76
81
  "tslib": "^2.6.2",
77
- "typescript": "^5.2.2"
82
+ "typescript": "^5.3.3",
83
+ "undici": "^5.28.3"
78
84
  }
79
85
  }
package/src/dataLoader.ts CHANGED
@@ -1,36 +1,63 @@
1
1
  import { Node } from "./node";
2
- import { JqTreeWidget } from "./tree.jquery";
2
+ import { DataFilter, OnLoadFailed, OnLoading } from "./jqtreeOptions";
3
+ import { LoadData, TriggerEvent } from "./jqtreeMethodTypes";
3
4
 
4
5
  export type HandleFinishedLoading = () => void;
5
6
 
6
- export default class DataLoader {
7
- private treeWidget: JqTreeWidget;
7
+ interface DataLoaderParams {
8
+ dataFilter?: DataFilter;
9
+ loadData: LoadData;
10
+ onLoadFailed?: OnLoadFailed;
11
+ onLoading?: OnLoading;
12
+ treeElement: HTMLElement;
13
+ triggerEvent: TriggerEvent;
14
+ }
8
15
 
9
- constructor(treeWidget: JqTreeWidget) {
10
- this.treeWidget = treeWidget;
16
+ export default class DataLoader {
17
+ private dataFilter?: DataFilter;
18
+ private loadData: LoadData;
19
+ private onLoadFailed?: OnLoadFailed;
20
+ private onLoading?: OnLoading;
21
+ private treeElement: HTMLElement;
22
+ private triggerEvent: TriggerEvent;
23
+
24
+ constructor({
25
+ dataFilter,
26
+ loadData,
27
+ onLoadFailed,
28
+ onLoading,
29
+ treeElement,
30
+ triggerEvent,
31
+ }: DataLoaderParams) {
32
+ this.dataFilter = dataFilter;
33
+ this.loadData = loadData;
34
+ this.onLoadFailed = onLoadFailed;
35
+ this.onLoading = onLoading;
36
+ this.treeElement = treeElement;
37
+ this.triggerEvent = triggerEvent;
11
38
  }
12
39
 
13
40
  public loadFromUrl(
14
41
  urlInfo: string | JQuery.AjaxSettings | null,
15
42
  parentNode: Node | null,
16
- onFinished: HandleFinishedLoading | null
43
+ onFinished: HandleFinishedLoading | null,
17
44
  ): void {
18
45
  if (!urlInfo) {
19
46
  return;
20
47
  }
21
48
 
22
- const $el = this.getDomElement(parentNode);
23
- this.addLoadingClass($el);
24
- this.notifyLoading(true, parentNode, $el);
49
+ const element = this.getDomElement(parentNode);
50
+ this.addLoadingClass(element);
51
+ this.notifyLoading(true, parentNode, element);
25
52
 
26
53
  const stopLoading = (): void => {
27
- this.removeLoadingClass($el);
28
- this.notifyLoading(false, parentNode, $el);
54
+ this.removeLoadingClass(element);
55
+ this.notifyLoading(false, parentNode, element);
29
56
  };
30
57
 
31
58
  const handleSuccess = (data: string | NodeData[]): void => {
32
59
  stopLoading();
33
- this.treeWidget.loadData(this.parseData(data), parentNode);
60
+ this.loadData(this.parseData(data), parentNode);
34
61
 
35
62
  if (onFinished && typeof onFinished === "function") {
36
63
  onFinished();
@@ -40,44 +67,42 @@ export default class DataLoader {
40
67
  const handleError = (jqXHR: JQuery.jqXHR): void => {
41
68
  stopLoading();
42
69
 
43
- if (this.treeWidget.options.onLoadFailed) {
44
- this.treeWidget.options.onLoadFailed(jqXHR);
70
+ if (this.onLoadFailed) {
71
+ this.onLoadFailed(jqXHR);
45
72
  }
46
73
  };
47
74
 
48
75
  this.submitRequest(urlInfo, handleSuccess, handleError);
49
76
  }
50
77
 
51
- private addLoadingClass($el: JQuery<HTMLElement>): void {
52
- if ($el) {
53
- $el.addClass("jqtree-loading");
54
- }
78
+ private addLoadingClass(element: HTMLElement): void {
79
+ element.classList.add("jqtree-loading");
55
80
  }
56
81
 
57
- private removeLoadingClass($el: JQuery<HTMLElement>): void {
58
- if ($el) {
59
- $el.removeClass("jqtree-loading");
60
- }
82
+ private removeLoadingClass(element: HTMLElement): void {
83
+ element.classList.remove("jqtree-loading");
61
84
  }
62
85
 
63
- private getDomElement(parentNode: Node | null): JQuery<HTMLElement> {
86
+ private getDomElement(parentNode: Node | null): HTMLElement {
64
87
  if (parentNode) {
65
- return jQuery(parentNode.element);
88
+ return parentNode.element;
66
89
  } else {
67
- return this.treeWidget.element;
90
+ return this.treeElement;
68
91
  }
69
92
  }
70
93
 
71
94
  private notifyLoading(
72
95
  isLoading: boolean,
73
96
  node: Node | null,
74
- $el: JQuery
97
+ element: HTMLElement,
75
98
  ): void {
76
- if (this.treeWidget.options.onLoading) {
77
- this.treeWidget.options.onLoading(isLoading, node, $el);
99
+ const $el = jQuery(element);
100
+
101
+ if (this.onLoading) {
102
+ this.onLoading(isLoading, node, $el);
78
103
  }
79
104
 
80
- this.treeWidget._triggerEvent("tree.loading_data", {
105
+ this.triggerEvent("tree.loading_data", {
81
106
  isLoading,
82
107
  node,
83
108
  $el,
@@ -87,7 +112,7 @@ export default class DataLoader {
87
112
  private submitRequest(
88
113
  urlInfoInput: string | JQuery.AjaxSettings,
89
114
  handleSuccess: JQuery.Ajax.SuccessCallback<any>,
90
- handleError: JQuery.Ajax.ErrorCallback<any>
115
+ handleError: JQuery.Ajax.ErrorCallback<any>,
91
116
  ): void {
92
117
  const urlInfo =
93
118
  typeof urlInfoInput === "string"
@@ -109,8 +134,6 @@ export default class DataLoader {
109
134
  }
110
135
 
111
136
  private parseData(data: string | NodeData[]): NodeData[] {
112
- const { dataFilter } = this.treeWidget.options;
113
-
114
137
  const getParsedData = () => {
115
138
  if (typeof data === "string") {
116
139
  return JSON.parse(data) as NodeData[];
@@ -121,8 +144,8 @@ export default class DataLoader {
121
144
 
122
145
  const parsedData = getParsedData();
123
146
 
124
- if (dataFilter) {
125
- return dataFilter(parsedData);
147
+ if (this.dataFilter) {
148
+ return this.dataFilter(parsedData);
126
149
  } else {
127
150
  return parsedData;
128
151
  }