@digital-realty/ix-tree 1.0.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/LICENSE +21 -0
- package/README.md +69 -0
- package/dist/IIxTreeNode.d.ts +8 -0
- package/dist/IIxTreeNode.js +2 -0
- package/dist/IIxTreeNode.js.map +1 -0
- package/dist/IxTree.d.ts +24 -0
- package/dist/IxTree.js +116 -0
- package/dist/IxTree.js.map +1 -0
- package/dist/IxTreeNode.d.ts +17 -0
- package/dist/IxTreeNode.js +111 -0
- package/dist/IxTreeNode.js.map +1 -0
- package/dist/find-node-by-id.d.ts +3 -0
- package/dist/find-node-by-id.js +17 -0
- package/dist/find-node-by-id.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/ix-tree-node.d.ts +1 -0
- package/dist/ix-tree-node.js +3 -0
- package/dist/ix-tree-node.js.map +1 -0
- package/dist/ix-tree-styles.d.ts +1 -0
- package/dist/ix-tree-styles.js +57 -0
- package/dist/ix-tree-styles.js.map +1 -0
- package/dist/ix-tree.d.ts +1 -0
- package/dist/ix-tree.js +3 -0
- package/dist/ix-tree.js.map +1 -0
- package/package.json +101 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 ix-treeivew
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# \<ix-tree>
|
|
2
|
+
|
|
3
|
+
This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i @digital-realty/ix-tree
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<script type="module">
|
|
15
|
+
import '@digital-realty/ix-tree/ix-tree.js';
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<ix-tree></ix-tree>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### In React
|
|
22
|
+
```html
|
|
23
|
+
<script type="module">
|
|
24
|
+
import { IxTree } from '@digital-realty/ix-tree/IxTree'
|
|
25
|
+
</script>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Linting and formatting
|
|
29
|
+
|
|
30
|
+
To scan the project for linting and formatting errors, run
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm run lint
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
To automatically fix linting and formatting errors, run
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm run format
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Testing with Web Test Runner
|
|
43
|
+
|
|
44
|
+
To execute a single test run:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm run test
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
To run the tests in interactive watch mode run:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm run test:watch
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## Tooling configs
|
|
58
|
+
|
|
59
|
+
For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
|
|
60
|
+
|
|
61
|
+
If you customize the configuration a lot, you can consider moving them to individual files.
|
|
62
|
+
|
|
63
|
+
## Local Demo with `web-dev-server`
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm start
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
To run a local development server that serves the basic demo located in `demo/index.html`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IIxTreeNode.js","sourceRoot":"","sources":["../src/IIxTreeNode.ts"],"names":[],"mappings":"","sourcesContent":["export interface IIxTreeNode {\n children?: Array<IIxTreeNode>;\n\n expanded: boolean;\n\n icon?: string;\n\n id: string;\n\n label: string;\n\n parentNode: IIxTreeNode | null;\n}\n"]}
|
package/dist/IxTree.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import '@digital-realty/ix-icon/ix-icon.js';
|
|
2
|
+
import '@digital-realty/theme';
|
|
3
|
+
import { LitElement, TemplateResult } from 'lit';
|
|
4
|
+
import { IIxTreeNode } from './IIxTreeNode.js';
|
|
5
|
+
import './ix-tree-node.js';
|
|
6
|
+
export declare class IxTree extends LitElement {
|
|
7
|
+
static readonly styles: import("lit").CSSResult[];
|
|
8
|
+
connectedCallback(): void;
|
|
9
|
+
ariaLabel: string;
|
|
10
|
+
rootNode: IIxTreeNode;
|
|
11
|
+
selectedNodeId: string;
|
|
12
|
+
_activeItemId: string;
|
|
13
|
+
_rootNode: IIxTreeNode;
|
|
14
|
+
_selectedNodeId: string;
|
|
15
|
+
private setParentNodes;
|
|
16
|
+
private onTreeNodeClick;
|
|
17
|
+
private onTreeNodeToggle;
|
|
18
|
+
private renderNodes;
|
|
19
|
+
/**
|
|
20
|
+
* Expand the active tree node and all of its parent nodes.
|
|
21
|
+
*/
|
|
22
|
+
private expandActiveTreeNode;
|
|
23
|
+
protected render(): TemplateResult<1>;
|
|
24
|
+
}
|
package/dist/IxTree.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import '@digital-realty/ix-icon/ix-icon.js';
|
|
3
|
+
import '@digital-realty/theme';
|
|
4
|
+
import { nothing, html, LitElement } from 'lit';
|
|
5
|
+
import { property, state } from 'lit/decorators.js';
|
|
6
|
+
import findNodeById from './find-node-by-id.js';
|
|
7
|
+
import { IxTreeStyles } from './ix-tree-styles.js';
|
|
8
|
+
import './ix-tree-node.js';
|
|
9
|
+
export class IxTree extends LitElement {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.ariaLabel = 'tree';
|
|
13
|
+
this.selectedNodeId = '';
|
|
14
|
+
this._activeItemId = '';
|
|
15
|
+
this._selectedNodeId = '';
|
|
16
|
+
}
|
|
17
|
+
connectedCallback() {
|
|
18
|
+
super.connectedCallback();
|
|
19
|
+
this._activeItemId = this.selectedNodeId; // store in state
|
|
20
|
+
this._selectedNodeId = this.selectedNodeId; // store in state
|
|
21
|
+
// update the parent nodes on each node in the tree and store the new root node in state
|
|
22
|
+
const newRootNode = { ...this.rootNode };
|
|
23
|
+
this.setParentNodes(newRootNode);
|
|
24
|
+
this._rootNode = newRootNode;
|
|
25
|
+
}
|
|
26
|
+
// Set the parent nodes on each node in the tree.
|
|
27
|
+
// This is needed when we have a selected id and need to expand each parent node to show the selected node.
|
|
28
|
+
setParentNodes(node) {
|
|
29
|
+
if (node.children) {
|
|
30
|
+
node.children.forEach(child => {
|
|
31
|
+
// eslint-disable-next-line no-param-reassign
|
|
32
|
+
child.parentNode = node;
|
|
33
|
+
this.setParentNodes(child);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
onTreeNodeClick(e) {
|
|
38
|
+
this.dispatchEvent(new CustomEvent('on-tree-node-selected', {
|
|
39
|
+
detail: {
|
|
40
|
+
message: e.detail.message,
|
|
41
|
+
},
|
|
42
|
+
}));
|
|
43
|
+
this._selectedNodeId = e.detail.message.id;
|
|
44
|
+
}
|
|
45
|
+
onTreeNodeToggle(e) {
|
|
46
|
+
const { id } = e.detail.message;
|
|
47
|
+
const newRootNode = { ...this._rootNode };
|
|
48
|
+
const nodeToToggle = findNodeById(newRootNode, id);
|
|
49
|
+
nodeToToggle.expanded = !(nodeToToggle === null || nodeToToggle === void 0 ? void 0 : nodeToToggle.expanded);
|
|
50
|
+
this._rootNode = newRootNode;
|
|
51
|
+
this._activeItemId = nodeToToggle.id;
|
|
52
|
+
this.requestUpdate();
|
|
53
|
+
}
|
|
54
|
+
renderNodes(nodes = [], level = 0) {
|
|
55
|
+
const rendredNodes = [];
|
|
56
|
+
for (const node of nodes) {
|
|
57
|
+
const renderedNode = html `<ix-tree-node
|
|
58
|
+
.isActiveTreeNode=${this._activeItemId === node.id}
|
|
59
|
+
.isExpanded=${node.expanded}
|
|
60
|
+
.isSelected=${this._selectedNodeId === node.id}
|
|
61
|
+
.level=${level}
|
|
62
|
+
.node=${node}
|
|
63
|
+
@on-tree-node-click=${this.onTreeNodeClick}
|
|
64
|
+
@on-tree-node-toggle=${this.onTreeNodeToggle}
|
|
65
|
+
>
|
|
66
|
+
${node.expanded ? this.renderNodes(node.children, level + 1) : nothing}
|
|
67
|
+
</ix-tree-node>`;
|
|
68
|
+
rendredNodes.push(renderedNode);
|
|
69
|
+
}
|
|
70
|
+
return rendredNodes;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Expand the active tree node and all of its parent nodes.
|
|
74
|
+
*/
|
|
75
|
+
expandActiveTreeNode() {
|
|
76
|
+
const nodeToSelect = findNodeById(this._rootNode, this._activeItemId) || this._rootNode;
|
|
77
|
+
let iteration = 0;
|
|
78
|
+
const MAX_ITERATIONS = 1000;
|
|
79
|
+
let node = nodeToSelect.parentNode;
|
|
80
|
+
while (node && iteration < MAX_ITERATIONS) {
|
|
81
|
+
node.expanded = true;
|
|
82
|
+
node = node.parentNode;
|
|
83
|
+
iteration += 1;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
render() {
|
|
87
|
+
this.expandActiveTreeNode();
|
|
88
|
+
return html `<div
|
|
89
|
+
aria-label=${this.ariaLabel}
|
|
90
|
+
class="ix-tree-container"
|
|
91
|
+
role="tree"
|
|
92
|
+
>
|
|
93
|
+
${this.renderNodes(this._rootNode.children, 0)}
|
|
94
|
+
</div>`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
IxTree.styles = [IxTreeStyles];
|
|
98
|
+
__decorate([
|
|
99
|
+
property()
|
|
100
|
+
], IxTree.prototype, "ariaLabel", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
property({ type: Object })
|
|
103
|
+
], IxTree.prototype, "rootNode", void 0);
|
|
104
|
+
__decorate([
|
|
105
|
+
property()
|
|
106
|
+
], IxTree.prototype, "selectedNodeId", void 0);
|
|
107
|
+
__decorate([
|
|
108
|
+
state()
|
|
109
|
+
], IxTree.prototype, "_activeItemId", void 0);
|
|
110
|
+
__decorate([
|
|
111
|
+
state()
|
|
112
|
+
], IxTree.prototype, "_rootNode", void 0);
|
|
113
|
+
__decorate([
|
|
114
|
+
state()
|
|
115
|
+
], IxTree.prototype, "_selectedNodeId", void 0);
|
|
116
|
+
//# sourceMappingURL=IxTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IxTree.js","sourceRoot":"","sources":["../src/IxTree.ts"],"names":[],"mappings":";AAAA,OA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,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SACjC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAED;;OAEG;IACK,oBAAoB;QAC1B,MAAM,YAAY,GAChB,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;QAErE,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,MAAM,cAAc,GAAG,IAAI,CAAC;QAC5B,IAAI,IAAI,GAAuB,YAAY,CAAC,UAAU,CAAC;QACvD,OAAO,IAAI,IAAI,SAAS,GAAG,cAAc,EAAE;YACzC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC;YACvB,SAAS,IAAI,CAAC,CAAC;SAChB;IACH,CAAC;IAES,MAAM;QACd,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAE5B,OAAO,IAAI,CAAA;mBACI,IAAI,CAAC,SAAS;;;;QAIzB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;WACzC,CAAC;IACV,CAAC;;AAnHe,aAAM,GAAG,CAAC,YAAY,CAAC,CAAC;AAc5B;IAAX,QAAQ,EAAE;yCAA4B;AAEX;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCAAwB;AAEvC;IAAX,QAAQ,EAAE;8CAA6B;AAE/B;IAAR,KAAK,EAAE;6CAA4B;AAE3B;IAAR,KAAK,EAAE;yCAAyB;AAExB;IAAR,KAAK,EAAE;+CAA8B","sourcesContent":["import '@digital-realty/ix-icon/ix-icon.js';\nimport '@digital-realty/theme';\nimport { nothing, html, LitElement, TemplateResult } from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport findNodeById from './find-node-by-id.js';\nimport { IIxTreeNode } from './IIxTreeNode.js';\nimport { IxTreeStyles } from './ix-tree-styles.js';\nimport './ix-tree-node.js';\n\nexport class IxTree extends LitElement {\n static readonly styles = [IxTreeStyles];\n\n connectedCallback() {\n super.connectedCallback();\n\n this._activeItemId = this.selectedNodeId; // store in state\n this._selectedNodeId = this.selectedNodeId; // store in state\n\n // update the parent nodes on each node in the tree and store the new root node in state\n const newRootNode = { ...this.rootNode };\n this.setParentNodes(newRootNode);\n this._rootNode = newRootNode;\n }\n\n @property() ariaLabel: string = 'tree';\n\n @property({ type: Object }) rootNode!: IIxTreeNode;\n\n @property() selectedNodeId: string = '';\n\n @state() _activeItemId: string = '';\n\n @state() _rootNode!: IIxTreeNode;\n\n @state() _selectedNodeId: string = '';\n\n // Set the parent nodes on each node in the tree.\n // This is needed when we have a selected id and need to expand each parent node to show the selected node.\n private setParentNodes(node: IIxTreeNode) {\n if (node.children) {\n node.children.forEach(child => {\n // eslint-disable-next-line no-param-reassign\n child.parentNode = node;\n this.setParentNodes(child);\n });\n }\n }\n\n private onTreeNodeClick(e: CustomEvent): void {\n this.dispatchEvent(\n new CustomEvent('on-tree-node-selected', {\n detail: {\n message: e.detail.message,\n },\n })\n );\n\n this._selectedNodeId = e.detail.message.id;\n }\n\n private onTreeNodeToggle(e: CustomEvent): void {\n const { id } = e.detail.message;\n\n const newRootNode = { ...this._rootNode };\n\n const nodeToToggle = findNodeById(newRootNode, id)!;\n nodeToToggle.expanded = !nodeToToggle?.expanded;\n this._rootNode = newRootNode;\n\n this._activeItemId = nodeToToggle.id;\n\n this.requestUpdate();\n }\n\n private renderNodes(\n nodes: Array<IIxTreeNode> = [],\n level: number = 0\n ): Array<TemplateResult<1>> {\n const rendredNodes: Array<TemplateResult<1>> = [];\n\n for (const node of nodes) {\n const renderedNode = html`<ix-tree-node\n .isActiveTreeNode=${this._activeItemId === node.id}\n .isExpanded=${node.expanded}\n .isSelected=${this._selectedNodeId === node.id}\n .level=${level}\n .node=${node}\n @on-tree-node-click=${this.onTreeNodeClick}\n @on-tree-node-toggle=${this.onTreeNodeToggle}\n >\n ${node.expanded ? this.renderNodes(node.children, level + 1) : nothing}\n </ix-tree-node>`;\n rendredNodes.push(renderedNode);\n }\n\n return rendredNodes;\n }\n\n /**\n * Expand the active tree node and all of its parent nodes.\n */\n private expandActiveTreeNode(): void {\n const nodeToSelect =\n findNodeById(this._rootNode, this._activeItemId) || this._rootNode;\n\n let iteration = 0;\n const MAX_ITERATIONS = 1000;\n let node: IIxTreeNode | null = nodeToSelect.parentNode;\n while (node && iteration < MAX_ITERATIONS) {\n node.expanded = true;\n node = node.parentNode;\n iteration += 1;\n }\n }\n\n protected render(): TemplateResult<1> {\n this.expandActiveTreeNode();\n\n return html`<div\n aria-label=${this.ariaLabel}\n class=\"ix-tree-container\"\n role=\"tree\"\n >\n ${this.renderNodes(this._rootNode.children, 0)}\n </div>`;\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import '@digital-realty/ix-icon/ix-icon.js';
|
|
2
|
+
import '@digital-realty/theme';
|
|
3
|
+
import { LitElement, TemplateResult } from 'lit';
|
|
4
|
+
import { IIxTreeNode } from './IIxTreeNode.js';
|
|
5
|
+
export declare class IxTreeNode extends LitElement {
|
|
6
|
+
static readonly styles: import("lit").CSSResult[];
|
|
7
|
+
isActiveTreeNode: boolean;
|
|
8
|
+
isExpanded: boolean;
|
|
9
|
+
isSelected: boolean;
|
|
10
|
+
level: number;
|
|
11
|
+
node: IIxTreeNode;
|
|
12
|
+
private getIcon;
|
|
13
|
+
private onNodeClick;
|
|
14
|
+
private onNodeToggle;
|
|
15
|
+
protected render(): TemplateResult<1>;
|
|
16
|
+
protected updated(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import '@digital-realty/ix-icon/ix-icon.js';
|
|
3
|
+
import '@digital-realty/theme';
|
|
4
|
+
import { html, LitElement, nothing } from 'lit';
|
|
5
|
+
import { property } from 'lit/decorators.js';
|
|
6
|
+
import { IxTreeStyles } from './ix-tree-styles.js';
|
|
7
|
+
// TREE_NODE_SPACER_REM and TREE_NODE_ICON_SIZE_REM are used to calculate the left padding for each node in the tree based on its level.
|
|
8
|
+
// They need to remain in synchronization with the CSS variables defined in ix-tree-styles.ts.
|
|
9
|
+
const TREE_NODE_SPACER_REM = 0.5;
|
|
10
|
+
const TREE_NODE_ICON_SIZE_REM = TREE_NODE_SPACER_REM * 3;
|
|
11
|
+
export class IxTreeNode extends LitElement {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.isActiveTreeNode = false;
|
|
15
|
+
this.isExpanded = false;
|
|
16
|
+
this.isSelected = false;
|
|
17
|
+
this.level = 0;
|
|
18
|
+
}
|
|
19
|
+
getIcon(node, isExpanded) {
|
|
20
|
+
if (!node.children || node.children.length === 0) {
|
|
21
|
+
// This node does not have children; no icon is needed.
|
|
22
|
+
return nothing;
|
|
23
|
+
}
|
|
24
|
+
const icon = isExpanded ? 'arrow_drop_down' : 'arrow_right';
|
|
25
|
+
return html `<ix-icon @click=${() => this.onNodeToggle(this.node)}>
|
|
26
|
+
<span class="material-icons ${icon}">${icon}</span>
|
|
27
|
+
</ix-icon>`;
|
|
28
|
+
}
|
|
29
|
+
onNodeClick(node) {
|
|
30
|
+
var _a;
|
|
31
|
+
const event = new CustomEvent('on-tree-node-click', {
|
|
32
|
+
detail: {
|
|
33
|
+
message: {
|
|
34
|
+
id: node.id,
|
|
35
|
+
label: node.label,
|
|
36
|
+
parentId: (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.id,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
this.dispatchEvent(event);
|
|
41
|
+
}
|
|
42
|
+
onNodeToggle(node) {
|
|
43
|
+
var _a;
|
|
44
|
+
const event = new CustomEvent('on-tree-node-toggle', {
|
|
45
|
+
detail: {
|
|
46
|
+
message: {
|
|
47
|
+
id: node.id,
|
|
48
|
+
label: node.label,
|
|
49
|
+
parentId: (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.id,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
this.dispatchEvent(event);
|
|
54
|
+
}
|
|
55
|
+
render() {
|
|
56
|
+
const selectedClass = this.isSelected ? ' ix-tree-node__selected' : '';
|
|
57
|
+
const icon = this.node.icon ? this.node.icon : 'account_box';
|
|
58
|
+
return html `<div
|
|
59
|
+
?active-tree-node=${this.isActiveTreeNode}
|
|
60
|
+
aria-expanded=${this.node.expanded}
|
|
61
|
+
aria-selected=${this.isSelected}
|
|
62
|
+
role="treeitem"
|
|
63
|
+
>
|
|
64
|
+
<div
|
|
65
|
+
class="ix-tree-node__wrapper ix-tree-node${selectedClass}"
|
|
66
|
+
style="padding-left: ${this.level * TREE_NODE_ICON_SIZE_REM}rem"
|
|
67
|
+
>
|
|
68
|
+
<div class="ix-tree-node__icon-size">
|
|
69
|
+
${this.getIcon(this.node, this.isExpanded)}
|
|
70
|
+
</div>
|
|
71
|
+
<div
|
|
72
|
+
class="ix-tree-node__icon ix-tree-node__icon-size material-icons ${icon}"
|
|
73
|
+
@click=${() => this.onNodeClick(this.node)}
|
|
74
|
+
@keyup=${() => this.onNodeClick(this.node)}
|
|
75
|
+
>
|
|
76
|
+
${this.node.icon ? this.node.icon : 'account_box'}
|
|
77
|
+
</div>
|
|
78
|
+
<div
|
|
79
|
+
class="ix-tree-node__label"
|
|
80
|
+
@click=${() => this.onNodeClick(this.node)}
|
|
81
|
+
@keyup=${() => this.onNodeClick(this.node)}
|
|
82
|
+
>
|
|
83
|
+
${this.node.label}
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
<slot></slot>
|
|
87
|
+
</div>`;
|
|
88
|
+
}
|
|
89
|
+
updated() {
|
|
90
|
+
var _a;
|
|
91
|
+
const el = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('[active-tree-node]');
|
|
92
|
+
el === null || el === void 0 ? void 0 : el.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
IxTreeNode.styles = [IxTreeStyles];
|
|
96
|
+
__decorate([
|
|
97
|
+
property()
|
|
98
|
+
], IxTreeNode.prototype, "isActiveTreeNode", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
property()
|
|
101
|
+
], IxTreeNode.prototype, "isExpanded", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
property()
|
|
104
|
+
], IxTreeNode.prototype, "isSelected", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
property()
|
|
107
|
+
], IxTreeNode.prototype, "level", void 0);
|
|
108
|
+
__decorate([
|
|
109
|
+
property({ type: Object })
|
|
110
|
+
], IxTreeNode.prototype, "node", void 0);
|
|
111
|
+
//# sourceMappingURL=IxTreeNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IxTreeNode.js","sourceRoot":"","sources":["../src/IxTreeNode.ts"],"names":[],"mappings":";AAAA,OAAO,oCAAoC,CAAC;AAC5C,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAkB,MAAM,KAAK,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,wIAAwI;AACxI,8FAA8F;AAC9F,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,uBAAuB,GAAG,oBAAoB,GAAG,CAAC,CAAC;AAEzD,MAAM,OAAO,UAAW,SAAQ,UAAU;IAA1C;;QAGc,qBAAgB,GAAY,KAAK,CAAC;QAElC,eAAU,GAAY,KAAK,CAAC;QAE5B,eAAU,GAAY,KAAK,CAAC;QAE5B,UAAK,GAAW,CAAC,CAAC;IAuFhC,CAAC;IAnFS,OAAO,CACb,IAAiB,EACjB,UAAmB;QAEnB,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,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,EAAE,CAAC;wCAAoB","sourcesContent":["import '@digital-realty/ix-icon/ix-icon.js';\nimport '@digital-realty/theme';\nimport { html, LitElement, nothing, TemplateResult } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { IIxTreeNode } from './IIxTreeNode.js';\nimport { IxTreeStyles } from './ix-tree-styles.js';\n\n// TREE_NODE_SPACER_REM and TREE_NODE_ICON_SIZE_REM are used to calculate the left padding for each node in the tree based on its level.\n// They need to remain in synchronization with the CSS variables defined in ix-tree-styles.ts.\nconst TREE_NODE_SPACER_REM = 0.5;\nconst TREE_NODE_ICON_SIZE_REM = TREE_NODE_SPACER_REM * 3;\n\nexport class IxTreeNode extends LitElement {\n static readonly styles = [IxTreeStyles];\n\n @property() isActiveTreeNode: boolean = false;\n\n @property() isExpanded: boolean = false;\n\n @property() isSelected: boolean = false;\n\n @property() level: number = 0;\n\n @property({ type: Object }) node!: IIxTreeNode;\n\n private getIcon(\n node: IIxTreeNode,\n isExpanded: boolean\n ): TemplateResult<1> | typeof nothing {\n if (!node.children || node.children.length === 0) {\n // This node does not have children; no icon is needed.\n return nothing;\n }\n\n const icon = isExpanded ? 'arrow_drop_down' : 'arrow_right';\n return html`<ix-icon @click=${() => this.onNodeToggle(this.node)}>\n <span class=\"material-icons ${icon}\">${icon}</span>\n </ix-icon>`;\n }\n\n private onNodeClick(node: IIxTreeNode): void {\n const event = new CustomEvent('on-tree-node-click', {\n detail: {\n message: {\n id: node.id,\n label: node.label,\n parentId: node.parentNode?.id,\n },\n },\n });\n\n this.dispatchEvent(event);\n }\n\n private onNodeToggle(node: IIxTreeNode): void {\n const event = new CustomEvent('on-tree-node-toggle', {\n detail: {\n message: {\n id: node.id,\n label: node.label,\n parentId: node.parentNode?.id,\n },\n },\n });\n\n this.dispatchEvent(event);\n }\n\n protected render(): TemplateResult<1> {\n const selectedClass = this.isSelected ? ' ix-tree-node__selected' : '';\n const icon = this.node.icon ? this.node.icon : 'account_box';\n\n return html`<div\n ?active-tree-node=${this.isActiveTreeNode}\n aria-expanded=${this.node.expanded}\n aria-selected=${this.isSelected}\n role=\"treeitem\"\n >\n <div\n class=\"ix-tree-node__wrapper ix-tree-node${selectedClass}\"\n style=\"padding-left: ${this.level * TREE_NODE_ICON_SIZE_REM}rem\"\n >\n <div class=\"ix-tree-node__icon-size\">\n ${this.getIcon(this.node, this.isExpanded)}\n </div>\n <div\n class=\"ix-tree-node__icon ix-tree-node__icon-size material-icons ${icon}\"\n @click=${() => this.onNodeClick(this.node)}\n @keyup=${() => this.onNodeClick(this.node)}\n >\n ${this.node.icon ? this.node.icon : 'account_box'}\n </div>\n <div\n class=\"ix-tree-node__label\"\n @click=${() => this.onNodeClick(this.node)}\n @keyup=${() => this.onNodeClick(this.node)}\n >\n ${this.node.label}\n </div>\n </div>\n <slot></slot>\n </div>`;\n }\n\n protected updated(): void {\n const el = this.shadowRoot?.querySelector('[active-tree-node]');\n el?.scrollIntoView({ behavior: 'smooth', block: 'start' });\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const findNodeById = (node, id) => {
|
|
2
|
+
if (!node || !node.children) {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
if (node.id === id) {
|
|
6
|
+
return node;
|
|
7
|
+
}
|
|
8
|
+
for (const childNode of node.children) {
|
|
9
|
+
const foundNode = findNodeById(childNode, id);
|
|
10
|
+
if (foundNode) {
|
|
11
|
+
return foundNode;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
};
|
|
16
|
+
export default findNodeById;
|
|
17
|
+
//# sourceMappingURL=find-node-by-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-node-by-id.js","sourceRoot":"","sources":["../src/find-node-by-id.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG,CAAC,IAAiB,EAAE,EAAU,EAAsB,EAAE;IACzE,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;QAC3B,OAAO,IAAI,CAAC;KACb;IAED,IAAI,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE;QAClB,OAAO,IAAI,CAAC;KACb;IAED,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,QAAQ,EAAE;QACrC,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAE9C,IAAI,SAAS,EAAE;YACb,OAAO,SAAS,CAAC;SAClB;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { IIxTreeNode } from './IIxTreeNode.js';\n\nconst findNodeById = (node: IIxTreeNode, id: string): IIxTreeNode | null => {\n if (!node || !node.children) {\n return null;\n }\n\n if (node.id === id) {\n return node;\n }\n\n for (const childNode of node.children) {\n const foundNode = findNodeById(childNode, id);\n\n if (foundNode) {\n return foundNode;\n }\n }\n\n return null;\n};\n\nexport default findNodeById;\n"]}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["export { IxTree } from './IxTree.js';\nexport { IxTreeNode } from './IxTreeNode.js';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ix-tree-node.js","sourceRoot":"","sources":["../src/ix-tree-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,cAAc,CAAC,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC","sourcesContent":["import { IxTreeNode } from './IxTreeNode.js';\n\ncustomElements.define('ix-tree-node', IxTreeNode);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const IxTreeStyles: import("lit").CSSResult;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
export const IxTreeStyles = css `
|
|
3
|
+
:root,
|
|
4
|
+
:host :root,
|
|
5
|
+
:host {
|
|
6
|
+
--tree-node-spacer: var(--ix-sys-spacer, 0.5rem);
|
|
7
|
+
--tree-node-icon-size: calc(var(--tree-node-spacer) * 3);
|
|
8
|
+
}
|
|
9
|
+
@font-face {
|
|
10
|
+
font-family: 'Material Icons';
|
|
11
|
+
font-style: normal;
|
|
12
|
+
font-weight: 400;
|
|
13
|
+
src: url(https://fonts.gstatic.com/s/materialicons/v140/flUhRq6tzZclQEJ-Vdg-IuiaDsNZ.ttf)
|
|
14
|
+
format('truetype');
|
|
15
|
+
}
|
|
16
|
+
.material-icons {
|
|
17
|
+
color: #09224199;
|
|
18
|
+
direction: ltr;
|
|
19
|
+
display: inline-block;
|
|
20
|
+
font-family: 'Material Icons';
|
|
21
|
+
font-size: 24px;
|
|
22
|
+
font-style: normal;
|
|
23
|
+
font-weight: normal;
|
|
24
|
+
letter-spacing: normal;
|
|
25
|
+
line-height: 1;
|
|
26
|
+
text-transform: none;
|
|
27
|
+
white-space: nowrap;
|
|
28
|
+
word-wrap: normal;
|
|
29
|
+
}
|
|
30
|
+
.ix-tree-container {
|
|
31
|
+
height: 100%;
|
|
32
|
+
overflow: auto;
|
|
33
|
+
width: 100%;
|
|
34
|
+
}
|
|
35
|
+
.ix-tree-node__wrapper{
|
|
36
|
+
align-items: center;
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
display: flex;
|
|
39
|
+
padding: 0.5rem;
|
|
40
|
+
}
|
|
41
|
+
.ix-tree-node__icon-size {
|
|
42
|
+
height: var(--tree-node-icon-size);
|
|
43
|
+
width: var(--tree-node-icon-size);
|
|
44
|
+
}
|
|
45
|
+
.ix-tree-node__label {
|
|
46
|
+
color: #092241;
|
|
47
|
+
display: flex;
|
|
48
|
+
flex-grow: 1;
|
|
49
|
+
padding: 0.25rem;
|
|
50
|
+
white-space: nowrap;
|
|
51
|
+
}
|
|
52
|
+
.ix-tree-node__selected {
|
|
53
|
+
background-color: rgba(20, 86, 224, 0.1);
|
|
54
|
+
border-left: 3px solid #1456e0;
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
//# sourceMappingURL=ix-tree-styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ix-tree-styles.js","sourceRoot":"","sources":["../src/ix-tree-styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsD9B,CAAC","sourcesContent":["import { css } from 'lit';\n\nexport const IxTreeStyles = css`\n :root,\n :host :root,\n :host {\n --tree-node-spacer: var(--ix-sys-spacer, 0.5rem);\n --tree-node-icon-size: calc(var(--tree-node-spacer) * 3);\n }\n @font-face {\n font-family: 'Material Icons';\n font-style: normal;\n font-weight: 400;\n src: url(https://fonts.gstatic.com/s/materialicons/v140/flUhRq6tzZclQEJ-Vdg-IuiaDsNZ.ttf)\n format('truetype');\n }\n .material-icons {\n color: #09224199;\n direction: ltr;\n display: inline-block;\n font-family: 'Material Icons';\n font-size: 24px;\n font-style: normal;\n font-weight: normal;\n letter-spacing: normal;\n line-height: 1;\n text-transform: none;\n white-space: nowrap;\n word-wrap: normal;\n }\n .ix-tree-container {\n height: 100%;\n overflow: auto;\n width: 100%;\n }\n .ix-tree-node__wrapper{\n align-items: center;\n cursor: pointer;\n display: flex;\n padding: 0.5rem;\n }\n .ix-tree-node__icon-size {\n height: var(--tree-node-icon-size);\n width: var(--tree-node-icon-size);\n }\n .ix-tree-node__label {\n color: #092241;\n display: flex;\n flex-grow: 1;\n padding: 0.25rem;\n white-space: nowrap;\n }\n .ix-tree-node__selected {\n background-color: rgba(20, 86, 224, 0.1);\n border-left: 3px solid #1456e0;\n }\n`;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/ix-tree.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ix-tree.js","sourceRoot":"","sources":["../src/ix-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import { IxTree } from './IxTree.js';\n\ncustomElements.define('ix-tree', IxTree);\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@digital-realty/ix-tree",
|
|
3
|
+
"description": "Webcomponent ix-tree following open-wc recommendations",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Digital Realty",
|
|
6
|
+
"version": "1.0.1",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"module": "dist/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/index.js",
|
|
12
|
+
"./ix-tree.js": "./dist/ix-tree.js",
|
|
13
|
+
"./IxTree": "./dist/react/IxTree.js"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"analyze": "cem analyze --litelement",
|
|
20
|
+
"build": "tsc && npm run analyze -- --exclude dist",
|
|
21
|
+
"format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore",
|
|
22
|
+
"lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",
|
|
23
|
+
"prepublish": "tsc && npm run analyze -- --exclude dist",
|
|
24
|
+
"start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
|
|
25
|
+
"test": "tsc && wtr --coverage",
|
|
26
|
+
"test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --watch\""
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@digital-realty/ix-icon": "^0.0.3",
|
|
30
|
+
"@digital-realty/theme": "^1.0.6",
|
|
31
|
+
"@lit-labs/react": "^2.1.0",
|
|
32
|
+
"@material/web": "^1.0.0",
|
|
33
|
+
"lit": "^2.0.2",
|
|
34
|
+
"react": "^18.2.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@custom-elements-manifest/analyzer": "^0.4.17",
|
|
38
|
+
"@open-wc/eslint-config": "^9.2.1",
|
|
39
|
+
"@open-wc/testing": "^3.1.6",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.48.0",
|
|
41
|
+
"@typescript-eslint/parser": "^5.48.0",
|
|
42
|
+
"@web/dev-server": "^0.1.34",
|
|
43
|
+
"@web/test-runner": "^0.14.0",
|
|
44
|
+
"concurrently": "^5.3.0",
|
|
45
|
+
"eslint": "^8.31.0",
|
|
46
|
+
"eslint-config-prettier": "^8.3.0",
|
|
47
|
+
"husky": "^4.3.8",
|
|
48
|
+
"lint-staged": "^10.5.4",
|
|
49
|
+
"prettier": "^2.4.1",
|
|
50
|
+
"tslib": "^2.3.1",
|
|
51
|
+
"typescript": "^4.5.2"
|
|
52
|
+
},
|
|
53
|
+
"customElements": "custom-elements.json",
|
|
54
|
+
"eslintConfig": {
|
|
55
|
+
"parser": "@typescript-eslint/parser",
|
|
56
|
+
"extends": [
|
|
57
|
+
"@open-wc",
|
|
58
|
+
"prettier"
|
|
59
|
+
],
|
|
60
|
+
"plugins": [
|
|
61
|
+
"@typescript-eslint"
|
|
62
|
+
],
|
|
63
|
+
"rules": {
|
|
64
|
+
"@typescript-eslint/no-unused-vars": [
|
|
65
|
+
"error"
|
|
66
|
+
],
|
|
67
|
+
"import/extensions": [
|
|
68
|
+
"error",
|
|
69
|
+
"always",
|
|
70
|
+
{
|
|
71
|
+
"ignorePackages": true
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
"import/no-unresolved": "off",
|
|
75
|
+
"no-unused-vars": "error"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"prettier": {
|
|
79
|
+
"arrowParens": "avoid",
|
|
80
|
+
"singleQuote": true
|
|
81
|
+
},
|
|
82
|
+
"husky": {
|
|
83
|
+
"hooks": {
|
|
84
|
+
"pre-commit": "lint-staged"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"lint-staged": {
|
|
88
|
+
"*.ts": [
|
|
89
|
+
"eslint --fix",
|
|
90
|
+
"prettier --write"
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
"files": [
|
|
94
|
+
"/dist",
|
|
95
|
+
"!/dist/test",
|
|
96
|
+
"package.json",
|
|
97
|
+
"README.md",
|
|
98
|
+
"LICENSE"
|
|
99
|
+
],
|
|
100
|
+
"gitHead": "b6fdbd2bfccc8368b957adc302239e06b2e54e70"
|
|
101
|
+
}
|