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.
- package/.eslintrc +13 -3
- package/.github/workflows/ci.yml +6 -6
- package/.github/workflows/codeql-analysis.yml +4 -4
- package/.github/workflows/size.yml +3 -3
- package/.github/workflows/static.yml +1 -1
- package/bower.json +1 -1
- package/config/babel.config.json +1 -1
- package/config/jest.config.js +4 -0
- package/config/jest.polyfills.js +14 -0
- package/config/production +2 -0
- package/devserver/devserver_scroll.js +8 -0
- package/devserver/test_index.html +9 -0
- package/devserver/test_scroll.html +28 -0
- package/devserver/test_scroll_container.html +39 -0
- package/docs/.ruby-version +1 -1
- package/docs/_config.yml +1 -1
- package/docs/_entries/general/changelog.md +11 -0
- package/docs/_entries/multiple_selection/get-selected-nodes.md +1 -1
- package/docs/_entries/node/getnextnode.md +3 -6
- package/docs/_entries/node/getnextsibling.md +1 -1
- package/docs/_entries/node/getnextvisiblenode.md +8 -5
- package/docs/_entries/node/getpreviousnode.md +12 -0
- package/docs/_entries/node/getprevioussibling.md +1 -1
- package/docs/_entries/node/getpreviousvisiblenode.md +6 -5
- package/package.json +35 -29
- package/src/dataLoader.ts +57 -34
- package/src/dragAndDropHandler/dragElement.ts +54 -0
- package/src/dragAndDropHandler/generateHitAreas.ts +176 -0
- package/src/dragAndDropHandler/index.ts +454 -0
- package/src/dragAndDropHandler/iterateVisibleNodes.ts +91 -0
- package/src/dragAndDropHandler/types.ts +13 -0
- package/src/elementsRenderer.ts +75 -40
- package/src/jqtreeMethodTypes.ts +40 -0
- package/src/jqtreeOptions.ts +43 -25
- package/src/keyHandler.ts +59 -30
- package/src/mouseHandler.ts +385 -0
- package/src/mouseUtils.ts +23 -0
- package/src/node.ts +1 -29
- package/src/nodeElement/borderDropHint.ts +32 -0
- package/src/nodeElement/folderElement.ts +133 -0
- package/src/nodeElement/ghostDropHint.ts +69 -0
- package/src/nodeElement/index.ts +102 -0
- package/src/playwright/coverage.ts +4 -7
- package/src/playwright/playwright.test.ts +150 -53
- package/src/playwright/testUtils.ts +28 -5
- package/src/position.ts +28 -0
- package/src/saveStateHandler.ts +75 -26
- package/src/scrollHandler/containerScrollParent.ts +13 -23
- package/src/scrollHandler/createScrollParent.ts +22 -22
- package/src/scrollHandler/documentScrollParent.ts +16 -13
- package/src/scrollHandler.ts +13 -15
- package/src/selectNodeHandler.ts +10 -16
- package/src/test/jqTree/events.test.ts +97 -30
- package/src/test/jqTree/keyboard.test.ts +18 -23
- package/src/test/jqTree/loadOnDemand.test.ts +22 -15
- package/src/test/jqTree/methods.test.ts +40 -14
- package/src/test/jqTree/mouse.test.ts +82 -0
- package/src/test/jqTree/options.test.ts +24 -12
- package/src/test/node.test.ts +3 -2
- package/src/test/{nodeUtil.test.ts → position.test.ts} +1 -1
- package/src/tree.jquery.ts +314 -208
- package/src/util.ts +12 -0
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +2594 -3419
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +3 -3
- package/tree.jquery.js.map +1 -1
- package/tsconfig.json +5 -3
- package/docs/_entries/functions/get-selected-nodes.md +0 -10
- package/lib/dataLoader.js +0 -123
- package/lib/dragAndDropHandler.js +0 -588
- package/lib/elementsRenderer.js +0 -267
- package/lib/jqtreeOptions.js +0 -1
- package/lib/keyHandler.js +0 -111
- package/lib/mouse.widget.js +0 -255
- package/lib/node.js +0 -708
- package/lib/nodeElement.js +0 -274
- package/lib/nodeUtils.js +0 -10
- package/lib/playwright/coverage.js +0 -99
- package/lib/playwright/playwright.test.js +0 -606
- package/lib/playwright/testUtils.js +0 -210
- package/lib/saveStateHandler.js +0 -277
- package/lib/scrollHandler/containerScrollParent.js +0 -160
- package/lib/scrollHandler/createScrollParent.js +0 -57
- package/lib/scrollHandler/documentScrollParent.js +0 -169
- package/lib/scrollHandler/scrollParent.js +0 -58
- package/lib/scrollHandler/types.js +0 -1
- package/lib/scrollHandler.js +0 -71
- package/lib/selectNodeHandler.js +0 -128
- package/lib/simple.widget.js +0 -158
- package/lib/test/global.d.js +0 -3
- package/lib/test/jqTree/accessibility.test.js +0 -37
- package/lib/test/jqTree/create.test.js +0 -48
- package/lib/test/jqTree/events.test.js +0 -210
- package/lib/test/jqTree/keyboard.test.js +0 -225
- package/lib/test/jqTree/loadOnDemand.test.js +0 -218
- package/lib/test/jqTree/methods.test.js +0 -1348
- package/lib/test/jqTree/options.test.js +0 -548
- package/lib/test/jqTree/scrollHandler/containerScrollParent.test.js +0 -94
- package/lib/test/node.test.js +0 -1202
- package/lib/test/nodeUtil.test.js +0 -27
- package/lib/test/nodeUtils.test.js +0 -20
- package/lib/test/support/exampleData.js +0 -35
- package/lib/test/support/jqTreeMatchers.js +0 -70
- package/lib/test/support/matchers.d.js +0 -1
- package/lib/test/support/setupTests.js +0 -7
- package/lib/test/support/testUtil.js +0 -29
- package/lib/test/support/treeStructure.js +0 -38
- package/lib/test/util.test.js +0 -26
- package/lib/tree.jquery.d.js +0 -1
- package/lib/tree.jquery.js +0 -1105
- package/lib/types.js +0 -1
- package/lib/typings.d.js +0 -2
- package/lib/util.js +0 -15
- package/lib/version.js +0 -8
- package/src/dragAndDropHandler.ts +0 -713
- package/src/mouse.widget.ts +0 -266
- package/src/nodeElement.ts +0 -272
- 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/
|
|
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
|
}
|
package/.github/workflows/ci.yml
CHANGED
|
@@ -8,25 +8,25 @@ jobs:
|
|
|
8
8
|
|
|
9
9
|
steps:
|
|
10
10
|
- name: Check out repository code
|
|
11
|
-
uses: actions/checkout@
|
|
11
|
+
uses: actions/checkout@v4
|
|
12
12
|
- name: Setup node
|
|
13
|
-
uses: actions/setup-node@
|
|
13
|
+
uses: actions/setup-node@v4
|
|
14
14
|
with:
|
|
15
|
-
|
|
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@
|
|
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@
|
|
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@
|
|
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@
|
|
21
|
+
uses: actions/checkout@v4
|
|
22
22
|
|
|
23
23
|
- name: Initialize CodeQL
|
|
24
|
-
uses: github/codeql-action/init@
|
|
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@
|
|
29
|
+
uses: github/codeql-action/autobuild@v3
|
|
30
30
|
|
|
31
31
|
- name: Perform CodeQL Analysis
|
|
32
|
-
uses: github/codeql-action/analyze@
|
|
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@
|
|
10
|
+
uses: actions/checkout@v4
|
|
11
11
|
- name: Setup node
|
|
12
|
-
uses: actions/setup-node@
|
|
12
|
+
uses: actions/setup-node@v4
|
|
13
13
|
with:
|
|
14
|
-
node-version:
|
|
14
|
+
node-version: "20"
|
|
15
15
|
- name: Install pnpm
|
|
16
16
|
run: npm install -g pnpm
|
|
17
17
|
- name: Install packages
|
package/bower.json
CHANGED
package/config/babel.config.json
CHANGED
package/config/jest.config.js
CHANGED
|
@@ -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
|
@@ -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>
|
package/docs/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.2.
|
|
1
|
+
3.2.3
|
package/docs/_config.yml
CHANGED
|
@@ -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)
|
|
@@ -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
|
-
-
|
|
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
|
-
|
|
11
|
+
const nextNode = node.getNextNode();
|
|
15
12
|
{% endhighlight %}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
---
|
|
2
|
-
title:
|
|
3
|
-
name: node-functions-
|
|
2
|
+
title: getNextVisibleNode
|
|
3
|
+
name: node-functions-getnextvisiblenode
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Get the next visible node in the tree. Does the same as using the _down_ key.
|
|
7
7
|
|
|
8
|
-
|
|
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
|
-
|
|
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 %}
|
|
@@ -3,12 +3,13 @@ title: getPreviousVisibleNode
|
|
|
3
3
|
name: node-functions-getpreviousvisiblenode
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
36
|
-
"@babel/core": "^7.23.
|
|
37
|
-
"@babel/preset-env": "^7.23.
|
|
38
|
-
"@babel/preset-typescript": "^7.23.
|
|
39
|
-
"@playwright/test": "^1.
|
|
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.
|
|
44
|
-
"@
|
|
45
|
-
"@types/
|
|
46
|
-
"@types/jest
|
|
47
|
-
"@types/
|
|
48
|
-
"@types/
|
|
49
|
-
"@
|
|
50
|
-
"@typescript-eslint/
|
|
51
|
-
"
|
|
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.
|
|
55
|
-
"eslint-
|
|
56
|
-
"eslint-plugin-
|
|
57
|
-
"eslint-plugin-
|
|
58
|
-
"eslint-plugin-
|
|
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": "^
|
|
68
|
-
"postcss": "^8.4.
|
|
69
|
-
"postcss-cli": "^
|
|
70
|
-
"postcss-import": "^
|
|
71
|
-
"postcss-load-config": "^
|
|
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.
|
|
74
|
-
"rollup": "^4.
|
|
75
|
-
"rollup-plugin-serve": "^
|
|
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.
|
|
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 {
|
|
2
|
+
import { DataFilter, OnLoadFailed, OnLoading } from "./jqtreeOptions";
|
|
3
|
+
import { LoadData, TriggerEvent } from "./jqtreeMethodTypes";
|
|
3
4
|
|
|
4
5
|
export type HandleFinishedLoading = () => void;
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
|
|
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
|
|
23
|
-
this.addLoadingClass(
|
|
24
|
-
this.notifyLoading(true, parentNode,
|
|
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(
|
|
28
|
-
this.notifyLoading(false, parentNode,
|
|
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.
|
|
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.
|
|
44
|
-
this.
|
|
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(
|
|
52
|
-
|
|
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(
|
|
58
|
-
|
|
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):
|
|
86
|
+
private getDomElement(parentNode: Node | null): HTMLElement {
|
|
64
87
|
if (parentNode) {
|
|
65
|
-
return
|
|
88
|
+
return parentNode.element;
|
|
66
89
|
} else {
|
|
67
|
-
return this.
|
|
90
|
+
return this.treeElement;
|
|
68
91
|
}
|
|
69
92
|
}
|
|
70
93
|
|
|
71
94
|
private notifyLoading(
|
|
72
95
|
isLoading: boolean,
|
|
73
96
|
node: Node | null,
|
|
74
|
-
|
|
97
|
+
element: HTMLElement,
|
|
75
98
|
): void {
|
|
76
|
-
|
|
77
|
-
|
|
99
|
+
const $el = jQuery(element);
|
|
100
|
+
|
|
101
|
+
if (this.onLoading) {
|
|
102
|
+
this.onLoading(isLoading, node, $el);
|
|
78
103
|
}
|
|
79
104
|
|
|
80
|
-
this.
|
|
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
|
}
|