@digital-realty/ix-tree 1.0.16 → 1.0.18

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.
@@ -1,10 +1,10 @@
1
- export interface IIxTreeNode {
2
- children?: Array<IIxTreeNode>;
3
- expanded?: boolean;
4
- icon?: string;
5
- id: string;
6
- label: string;
7
- parentId?: string;
8
- checked?: boolean;
9
- indeterminate?: boolean;
10
- }
1
+ export interface IIxTreeNode {
2
+ children?: Array<IIxTreeNode>;
3
+ expanded?: boolean;
4
+ icon?: string;
5
+ id: string;
6
+ label: string;
7
+ parentId?: string;
8
+ checked?: boolean;
9
+ indeterminate?: boolean;
10
+ }
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=IIxTreeNode.js.map
package/dist/IxTree.d.ts CHANGED
@@ -1,28 +1,28 @@
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 type Appearance = 'filled' | 'filled-tonal' | 'outlined' | 'default';
7
- export declare class IxTree extends LitElement {
8
- static readonly styles: import("lit").CSSResult[];
9
- connectedCallback(): void;
10
- ariaLabel: string;
11
- rootNode: IIxTreeNode;
12
- selectedNodeId: string;
13
- checkboxesEnabled: boolean;
14
- appearance: Appearance;
15
- private _activeItemId;
16
- private _rootNode;
17
- private _selectedNodeId;
18
- private onTreeNodeClick;
19
- private dispatchTreeNodeExpandToggle;
20
- private onTreeNodeToggle;
21
- private onTreeNodeCheck;
22
- private renderNodes;
23
- /**
24
- * Expand the active tree node and all of its parent nodes.
25
- */
26
- private expandActiveTreeNode;
27
- protected render(): TemplateResult<1>;
28
- }
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 type Appearance = 'filled' | 'filled-tonal' | 'outlined' | 'default';
7
+ export declare class IxTree extends LitElement {
8
+ static readonly styles: import("lit").CSSResult[];
9
+ connectedCallback(): void;
10
+ ariaLabel: string;
11
+ rootNode: IIxTreeNode;
12
+ selectedNodeId: string;
13
+ checkboxesEnabled: boolean;
14
+ appearance: Appearance;
15
+ private _activeItemId;
16
+ private _rootNode;
17
+ private _selectedNodeId;
18
+ private onTreeNodeClick;
19
+ private dispatchTreeNodeExpandToggle;
20
+ private onTreeNodeToggle;
21
+ private onTreeNodeCheck;
22
+ private renderNodes;
23
+ /**
24
+ * Expand the active tree node and all of its parent nodes.
25
+ */
26
+ private expandActiveTreeNode;
27
+ protected render(): TemplateResult<1>;
28
+ }
package/dist/IxTree.js CHANGED
@@ -1,64 +1,64 @@
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 { findChildNodeById, updateNodeCheckedStatus } from './tree-utils.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.checkboxesEnabled = false;
15
- this.appearance = 'default';
16
- this._activeItemId = '';
17
- this._selectedNodeId = '';
18
- }
19
- connectedCallback() {
20
- super.connectedCallback();
21
- this._activeItemId = this.selectedNodeId; // store in state
22
- this._selectedNodeId = this.selectedNodeId; // store in state
23
- this._rootNode = this.rootNode;
24
- }
25
- onTreeNodeClick(e) {
26
- this.dispatchEvent(new CustomEvent('on-tree-node-selected', {
27
- detail: {
28
- message: e.detail.message,
29
- },
30
- }));
31
- this._selectedNodeId = e.detail.message.id;
32
- }
33
- dispatchTreeNodeExpandToggle(e) {
34
- this.dispatchEvent(new CustomEvent('on-tree-node-expand-toggle', {
35
- detail: {
36
- message: e.detail.message,
37
- },
38
- }));
39
- }
40
- onTreeNodeToggle(e) {
41
- const newRootNode = { ...this._rootNode };
42
- const { node } = e.detail.message;
43
- node.expanded = !node.expanded;
44
- this._rootNode = newRootNode;
45
- this._activeItemId = node.id;
46
- this.dispatchTreeNodeExpandToggle(e);
47
- this.requestUpdate();
48
- }
49
- onTreeNodeCheck(e) {
50
- const { node } = e.detail.message;
51
- updateNodeCheckedStatus(node, this._rootNode);
52
- this._rootNode = structuredClone(this._rootNode);
53
- this.dispatchEvent(new CustomEvent('on-tree-node-checked', {
54
- detail: {
55
- message: e.detail.message,
56
- },
57
- }));
58
- }
59
- renderNodes(nodes = [], level = 0) {
60
- const renderedNodes = [];
61
- for (const node of nodes) {
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 { findChildNodeById, updateNodeCheckedStatus } from './tree-utils.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.checkboxesEnabled = false;
15
+ this.appearance = 'default';
16
+ this._activeItemId = '';
17
+ this._selectedNodeId = '';
18
+ }
19
+ connectedCallback() {
20
+ super.connectedCallback();
21
+ this._activeItemId = this.selectedNodeId; // store in state
22
+ this._selectedNodeId = this.selectedNodeId; // store in state
23
+ this._rootNode = this.rootNode;
24
+ }
25
+ onTreeNodeClick(e) {
26
+ this.dispatchEvent(new CustomEvent('on-tree-node-selected', {
27
+ detail: {
28
+ message: e.detail.message,
29
+ },
30
+ }));
31
+ this._selectedNodeId = e.detail.message.id;
32
+ }
33
+ dispatchTreeNodeExpandToggle(e) {
34
+ this.dispatchEvent(new CustomEvent('on-tree-node-expand-toggle', {
35
+ detail: {
36
+ message: e.detail.message,
37
+ },
38
+ }));
39
+ }
40
+ onTreeNodeToggle(e) {
41
+ const newRootNode = { ...this._rootNode };
42
+ const { node } = e.detail.message;
43
+ node.expanded = !node.expanded;
44
+ this._rootNode = newRootNode;
45
+ this._activeItemId = node.id;
46
+ this.dispatchTreeNodeExpandToggle(e);
47
+ this.requestUpdate();
48
+ }
49
+ onTreeNodeCheck(e) {
50
+ const { node } = e.detail.message;
51
+ updateNodeCheckedStatus(node, this._rootNode);
52
+ this._rootNode = structuredClone(this._rootNode);
53
+ this.dispatchEvent(new CustomEvent('on-tree-node-checked', {
54
+ detail: {
55
+ message: e.detail.message,
56
+ },
57
+ }));
58
+ }
59
+ renderNodes(nodes = [], level = 0) {
60
+ const renderedNodes = [];
61
+ for (const node of nodes) {
62
62
  const renderedNode = html `<ix-tree-node
63
63
  .isActiveTreeNode=${this._activeItemId === node.id}
64
64
  .isExpanded=${!!node.expanded}
@@ -72,65 +72,65 @@ export class IxTree extends LitElement {
72
72
  @on-tree-node-check=${this.onTreeNodeCheck}
73
73
  >
74
74
  ${node.expanded ? this.renderNodes(node.children, level + 1) : nothing}
75
- </ix-tree-node>`;
76
- renderedNodes.push(renderedNode);
77
- }
78
- return renderedNodes;
79
- }
80
- /**
81
- * Expand the active tree node and all of its parent nodes.
82
- */
83
- expandActiveTreeNode() {
84
- const nodeToSelect = findChildNodeById(this._rootNode, this._activeItemId) || this._rootNode;
85
- let iteration = 0;
86
- const MAX_ITERATIONS = 1000;
87
- if (!nodeToSelect.parentId) {
88
- return;
89
- }
90
- let node = findChildNodeById(this._rootNode, nodeToSelect.parentId);
91
- while (node && iteration < MAX_ITERATIONS) {
92
- node.expanded = true;
93
- if (!node.parentId) {
94
- break;
95
- }
96
- node = findChildNodeById(this._rootNode, node.parentId);
97
- iteration += 1;
98
- }
99
- }
100
- render() {
101
- this.expandActiveTreeNode();
75
+ </ix-tree-node>`;
76
+ renderedNodes.push(renderedNode);
77
+ }
78
+ return renderedNodes;
79
+ }
80
+ /**
81
+ * Expand the active tree node and all of its parent nodes.
82
+ */
83
+ expandActiveTreeNode() {
84
+ const nodeToSelect = findChildNodeById(this._rootNode, this._activeItemId) || this._rootNode;
85
+ let iteration = 0;
86
+ const MAX_ITERATIONS = 1000;
87
+ if (!nodeToSelect.parentId) {
88
+ return;
89
+ }
90
+ let node = findChildNodeById(this._rootNode, nodeToSelect.parentId);
91
+ while (node && iteration < MAX_ITERATIONS) {
92
+ node.expanded = true;
93
+ if (!node.parentId) {
94
+ break;
95
+ }
96
+ node = findChildNodeById(this._rootNode, node.parentId);
97
+ iteration += 1;
98
+ }
99
+ }
100
+ render() {
101
+ this.expandActiveTreeNode();
102
102
  return html `<div
103
103
  aria-label=${this.ariaLabel}
104
104
  class="ix-tree-container"
105
105
  role="tree"
106
106
  >
107
107
  ${this.renderNodes(this._rootNode.children, 0)}
108
- </div>`;
109
- }
110
- }
111
- IxTree.styles = [IxTreeStyles];
112
- __decorate([
113
- property()
114
- ], IxTree.prototype, "ariaLabel", void 0);
115
- __decorate([
116
- property({ type: Object })
117
- ], IxTree.prototype, "rootNode", void 0);
118
- __decorate([
119
- property()
120
- ], IxTree.prototype, "selectedNodeId", void 0);
121
- __decorate([
122
- property({ type: Boolean })
123
- ], IxTree.prototype, "checkboxesEnabled", void 0);
124
- __decorate([
125
- property({ type: String })
126
- ], IxTree.prototype, "appearance", void 0);
127
- __decorate([
128
- state()
129
- ], IxTree.prototype, "_activeItemId", void 0);
130
- __decorate([
131
- state()
132
- ], IxTree.prototype, "_rootNode", void 0);
133
- __decorate([
134
- state()
135
- ], IxTree.prototype, "_selectedNodeId", void 0);
108
+ </div>`;
109
+ }
110
+ }
111
+ IxTree.styles = [IxTreeStyles];
112
+ __decorate([
113
+ property()
114
+ ], IxTree.prototype, "ariaLabel", void 0);
115
+ __decorate([
116
+ property({ type: Object })
117
+ ], IxTree.prototype, "rootNode", void 0);
118
+ __decorate([
119
+ property()
120
+ ], IxTree.prototype, "selectedNodeId", void 0);
121
+ __decorate([
122
+ property({ type: Boolean })
123
+ ], IxTree.prototype, "checkboxesEnabled", void 0);
124
+ __decorate([
125
+ property({ type: String })
126
+ ], IxTree.prototype, "appearance", void 0);
127
+ __decorate([
128
+ state()
129
+ ], IxTree.prototype, "_activeItemId", void 0);
130
+ __decorate([
131
+ state()
132
+ ], IxTree.prototype, "_rootNode", void 0);
133
+ __decorate([
134
+ state()
135
+ ], IxTree.prototype, "_selectedNodeId", void 0);
136
136
  //# sourceMappingURL=IxTree.js.map
@@ -1,24 +1,24 @@
1
- import '@digital-realty/ix-icon-button/ix-icon-button.js';
2
- import '@digital-realty/ix-checkbox/ix-checkbox.js';
3
- import '@digital-realty/theme';
4
- import { LitElement, TemplateResult } from 'lit';
5
- import { IIxTreeNode } from './IIxTreeNode.js';
6
- import { Appearance } from './IxTree.js';
7
- export declare class IxTreeNode extends LitElement {
8
- static readonly styles: import("lit").CSSResult[];
9
- isActiveTreeNode: boolean;
10
- isExpanded: boolean;
11
- isSelected: boolean;
12
- level: number;
13
- node: IIxTreeNode;
14
- checkboxEnabled: boolean;
15
- appearance: Appearance;
16
- private _hasScrolledToActive;
17
- private hasChildren;
18
- private getIcon;
19
- private onNodeClick;
20
- private onNodeToggle;
21
- private onNodeCheck;
22
- protected render(): TemplateResult<1>;
23
- protected updated(): void;
24
- }
1
+ import '@digital-realty/ix-icon-button/ix-icon-button.js';
2
+ import '@digital-realty/ix-checkbox/ix-checkbox.js';
3
+ import '@digital-realty/theme';
4
+ import { LitElement, TemplateResult } from 'lit';
5
+ import { IIxTreeNode } from './IIxTreeNode.js';
6
+ import { Appearance } from './IxTree.js';
7
+ export declare class IxTreeNode extends LitElement {
8
+ static readonly styles: import("lit").CSSResult[];
9
+ isActiveTreeNode: boolean;
10
+ isExpanded: boolean;
11
+ isSelected: boolean;
12
+ level: number;
13
+ node: IIxTreeNode;
14
+ checkboxEnabled: boolean;
15
+ appearance: Appearance;
16
+ private _hasScrolledToActive;
17
+ private hasChildren;
18
+ private getIcon;
19
+ private onNodeClick;
20
+ private onNodeToggle;
21
+ private onNodeCheck;
22
+ protected render(): TemplateResult<1>;
23
+ protected updated(): void;
24
+ }
@@ -1,30 +1,30 @@
1
- import { __decorate } from "tslib";
2
- import '@digital-realty/ix-icon-button/ix-icon-button.js';
3
- import '@digital-realty/ix-checkbox/ix-checkbox.js';
4
- import '@digital-realty/theme';
5
- import { html, LitElement, nothing } from 'lit';
6
- import { property, state } from 'lit/decorators.js';
7
- import { IxTreeStyles } from './ix-tree-styles.js';
8
- // 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.
9
- // They need to remain in synchronization with the CSS variables defined in ix-tree-styles.ts.
10
- const TREE_NODE_SPACER_REM = 0.6;
11
- const TREE_NODE_ICON_SIZE_REM = TREE_NODE_SPACER_REM * 4;
12
- export class IxTreeNode extends LitElement {
13
- constructor() {
14
- super(...arguments);
15
- this.isActiveTreeNode = false;
16
- this.isExpanded = false;
17
- this.isSelected = false;
18
- this.level = 0;
19
- this.checkboxEnabled = false;
20
- this.appearance = 'default';
21
- this._hasScrolledToActive = false;
22
- }
23
- hasChildren() {
24
- return this.node.children !== undefined && this.node.children.length > 0;
25
- }
26
- getIcon() {
27
- const icon = this.isExpanded ? 'arrow_drop_down' : 'arrow_right';
1
+ import { __decorate } from "tslib";
2
+ import '@digital-realty/ix-icon-button/ix-icon-button.js';
3
+ import '@digital-realty/ix-checkbox/ix-checkbox.js';
4
+ import '@digital-realty/theme';
5
+ import { html, LitElement, nothing } from 'lit';
6
+ import { property, state } from 'lit/decorators.js';
7
+ import { IxTreeStyles } from './ix-tree-styles.js';
8
+ // 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.
9
+ // They need to remain in synchronization with the CSS variables defined in ix-tree-styles.ts.
10
+ const TREE_NODE_SPACER_REM = 0.6;
11
+ const TREE_NODE_ICON_SIZE_REM = TREE_NODE_SPACER_REM * 4;
12
+ export class IxTreeNode extends LitElement {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.isActiveTreeNode = false;
16
+ this.isExpanded = false;
17
+ this.isSelected = false;
18
+ this.level = 0;
19
+ this.checkboxEnabled = false;
20
+ this.appearance = 'default';
21
+ this._hasScrolledToActive = false;
22
+ }
23
+ hasChildren() {
24
+ return this.node.children !== undefined && this.node.children.length > 0;
25
+ }
26
+ getIcon() {
27
+ const icon = this.isExpanded ? 'arrow_drop_down' : 'arrow_right';
28
28
  return html `<div
29
29
  style=${`${this.hasChildren() ? '' : 'visibility:hidden'}`}
30
30
  >
@@ -34,58 +34,58 @@ export class IxTreeNode extends LitElement {
34
34
  test-id="tree-node-expand-toggle"
35
35
  >
36
36
  </ix-icon-button>
37
- </div>`;
38
- }
39
- onNodeClick(node) {
40
- const event = new CustomEvent('on-tree-node-click', {
41
- detail: {
42
- message: {
43
- node,
44
- id: node.id,
45
- label: node.label,
46
- parentId: node.parentId,
47
- },
48
- },
49
- });
50
- this.dispatchEvent(event);
51
- }
52
- onNodeToggle(node) {
53
- const event = new CustomEvent('on-tree-node-toggle', {
54
- detail: {
55
- message: {
56
- node,
57
- id: node.id,
58
- label: node.label,
59
- parentId: node.parentId,
60
- },
61
- },
62
- });
63
- this.dispatchEvent(event);
64
- }
65
- onNodeCheck(node) {
66
- /* eslint-disable no-param-reassign */
67
- if (node.checked) {
68
- node.checked = false;
69
- node.indeterminate = false;
70
- }
71
- else {
72
- node.checked = true;
73
- node.indeterminate = false;
74
- }
75
- /* eslint-enable no-param-reassign */
76
- const event = new CustomEvent('on-tree-node-check', {
77
- detail: {
78
- message: {
79
- node,
80
- id: node.id,
81
- },
82
- },
83
- });
84
- this.dispatchEvent(event);
85
- }
86
- render() {
87
- const selectedClass = this.isSelected ? ' ix-tree-node__selected' : '';
88
- const icon = this.node.icon ? this.node.icon : 'account_box';
37
+ </div>`;
38
+ }
39
+ onNodeClick(node) {
40
+ const event = new CustomEvent('on-tree-node-click', {
41
+ detail: {
42
+ message: {
43
+ node,
44
+ id: node.id,
45
+ label: node.label,
46
+ parentId: node.parentId,
47
+ },
48
+ },
49
+ });
50
+ this.dispatchEvent(event);
51
+ }
52
+ onNodeToggle(node) {
53
+ const event = new CustomEvent('on-tree-node-toggle', {
54
+ detail: {
55
+ message: {
56
+ node,
57
+ id: node.id,
58
+ label: node.label,
59
+ parentId: node.parentId,
60
+ },
61
+ },
62
+ });
63
+ this.dispatchEvent(event);
64
+ }
65
+ onNodeCheck(node) {
66
+ /* eslint-disable no-param-reassign */
67
+ if (node.checked) {
68
+ node.checked = false;
69
+ node.indeterminate = false;
70
+ }
71
+ else {
72
+ node.checked = true;
73
+ node.indeterminate = false;
74
+ }
75
+ /* eslint-enable no-param-reassign */
76
+ const event = new CustomEvent('on-tree-node-check', {
77
+ detail: {
78
+ message: {
79
+ node,
80
+ id: node.id,
81
+ },
82
+ },
83
+ });
84
+ this.dispatchEvent(event);
85
+ }
86
+ render() {
87
+ const selectedClass = this.isSelected ? ' ix-tree-node__selected' : '';
88
+ const icon = this.node.icon ? this.node.icon : 'account_box';
89
89
  return html `<div
90
90
  ?active-tree-node=${this.isActiveTreeNode}
91
91
  aria-expanded=${!!this.node.expanded}
@@ -98,73 +98,72 @@ export class IxTreeNode extends LitElement {
98
98
  style="padding-left: ${this.level * TREE_NODE_ICON_SIZE_REM}rem"
99
99
  >
100
100
  <div>${this.getIcon()}</div>
101
- ${this.checkboxEnabled
101
+ ${this.checkboxEnabled
102
102
  ? html `<ix-checkbox
103
103
  @click=${() => this.onNodeCheck(this.node)}
104
104
  label=""
105
105
  style="margin: 6px 12px 0px 12px"
106
106
  .checked=${this.node.checked}
107
107
  .indeterminate=${this.node.indeterminate}
108
- ></ix-checkbox>`
108
+ ></ix-checkbox>`
109
109
  : nothing}
110
110
  <ix-icon-button
111
111
  icon=${icon}
112
112
  appearance=${this.appearance}
113
113
  test-id=${`${this.node.id}-on-node-click-icon-button`}
114
- style=${this.hasChildren() ? '' : 'padding-left:2px;'}
115
114
  @click=${() => this.onNodeClick(this.node)}
116
115
  ></ix-icon-button>
117
116
  <div
118
117
  class="ix-tree-node__label"
119
- @click=${() => {
120
- this.checkboxEnabled
121
- ? this.onNodeToggle(this.node)
122
- : this.onNodeClick(this.node);
118
+ @click=${() => {
119
+ this.checkboxEnabled
120
+ ? this.onNodeToggle(this.node)
121
+ : this.onNodeClick(this.node);
123
122
  }}
124
- @keyup=${() => {
125
- this.checkboxEnabled
126
- ? this.onNodeToggle(this.node)
127
- : this.onNodeClick(this.node);
123
+ @keyup=${() => {
124
+ this.checkboxEnabled
125
+ ? this.onNodeToggle(this.node)
126
+ : this.onNodeClick(this.node);
128
127
  }}
129
128
  >
130
129
  ${this.node.label}
131
130
  </div>
132
131
  </div>
133
132
  <slot></slot>
134
- </div>`;
135
- }
136
- updated() {
137
- var _a;
138
- if (!this._hasScrolledToActive) {
139
- const el = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('[active-tree-node]');
140
- el === null || el === void 0 ? void 0 : el.scrollIntoView({ behavior: 'smooth', block: 'start' });
141
- this._hasScrolledToActive = true;
142
- }
143
- }
144
- }
145
- IxTreeNode.styles = [IxTreeStyles];
146
- __decorate([
147
- property({ type: Boolean })
148
- ], IxTreeNode.prototype, "isActiveTreeNode", void 0);
149
- __decorate([
150
- property({ type: Boolean })
151
- ], IxTreeNode.prototype, "isExpanded", void 0);
152
- __decorate([
153
- property({ type: Boolean })
154
- ], IxTreeNode.prototype, "isSelected", void 0);
155
- __decorate([
156
- property({ type: Number })
157
- ], IxTreeNode.prototype, "level", void 0);
158
- __decorate([
159
- property({ type: Object })
160
- ], IxTreeNode.prototype, "node", void 0);
161
- __decorate([
162
- property({ type: Boolean })
163
- ], IxTreeNode.prototype, "checkboxEnabled", void 0);
164
- __decorate([
165
- property({ type: String })
166
- ], IxTreeNode.prototype, "appearance", void 0);
167
- __decorate([
168
- state()
169
- ], IxTreeNode.prototype, "_hasScrolledToActive", void 0);
133
+ </div>`;
134
+ }
135
+ updated() {
136
+ var _a;
137
+ if (!this._hasScrolledToActive) {
138
+ const el = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('[active-tree-node]');
139
+ el === null || el === void 0 ? void 0 : el.scrollIntoView({ behavior: 'smooth', block: 'start' });
140
+ this._hasScrolledToActive = true;
141
+ }
142
+ }
143
+ }
144
+ IxTreeNode.styles = [IxTreeStyles];
145
+ __decorate([
146
+ property({ type: Boolean })
147
+ ], IxTreeNode.prototype, "isActiveTreeNode", void 0);
148
+ __decorate([
149
+ property({ type: Boolean })
150
+ ], IxTreeNode.prototype, "isExpanded", void 0);
151
+ __decorate([
152
+ property({ type: Boolean })
153
+ ], IxTreeNode.prototype, "isSelected", void 0);
154
+ __decorate([
155
+ property({ type: Number })
156
+ ], IxTreeNode.prototype, "level", void 0);
157
+ __decorate([
158
+ property({ type: Object })
159
+ ], IxTreeNode.prototype, "node", void 0);
160
+ __decorate([
161
+ property({ type: Boolean })
162
+ ], IxTreeNode.prototype, "checkboxEnabled", void 0);
163
+ __decorate([
164
+ property({ type: String })
165
+ ], IxTreeNode.prototype, "appearance", void 0);
166
+ __decorate([
167
+ state()
168
+ ], IxTreeNode.prototype, "_hasScrolledToActive", void 0);
170
169
  //# sourceMappingURL=IxTreeNode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IxTreeNode.js","sourceRoot":"","sources":["../src/IxTreeNode.ts"],"names":[],"mappings":";AAAA,OAAO,kDAAkD,CAAC;AAC1D,OAAO,4CAA4C,CAAC;AACpD,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAkB,MAAM,KAAK,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,wIAAwI;AACxI,8FAA8F;AAC9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AE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;YAC3D,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;SAClC;IACH,CAAC;;AAlJe,iBAAM,GAAG,CAAC,YAAY,CAAC,CAAC;AAEX;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;oDAAmC;AAElC;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;8CAA6B;AAE5B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;8CAA6B;AAE7B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yCAAmB;AAElB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCAAoB;AAElB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;mDAAkC;AAElC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8CAAoC;AAEtD;IAAR,KAAK,EAAE;wDAA+C","sourcesContent":["import '@digital-realty/ix-icon-button/ix-icon-button.js';\nimport '@digital-realty/ix-checkbox/ix-checkbox.js';\nimport '@digital-realty/theme';\nimport { html, LitElement, nothing, TemplateResult } from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { IIxTreeNode } from './IIxTreeNode.js';\nimport { IxTreeStyles } from './ix-tree-styles.js';\nimport { Appearance } from './IxTree.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.6;\nconst TREE_NODE_ICON_SIZE_REM = TREE_NODE_SPACER_REM * 4;\n\nexport class IxTreeNode extends LitElement {\n static readonly styles = [IxTreeStyles];\n\n @property({ type: Boolean }) isActiveTreeNode: boolean = false;\n\n @property({ type: Boolean }) isExpanded: boolean = false;\n\n @property({ type: Boolean }) isSelected: boolean = false;\n\n @property({ type: Number }) level: number = 0;\n\n @property({ type: Object }) node!: IIxTreeNode;\n\n @property({ type: Boolean }) checkboxEnabled: boolean = false;\n\n @property({ type: String }) appearance: Appearance = 'default';\n\n @state() private _hasScrolledToActive: boolean = false;\n\n private hasChildren() {\n return this.node.children !== undefined && this.node.children.length > 0;\n }\n\n private getIcon(): TemplateResult<1> | typeof nothing {\n const icon = this.isExpanded ? 'arrow_drop_down' : 'arrow_right';\n return html`<div\n style=${`${this.hasChildren() ? '' : 'visibility:hidden'}`}\n >\n <ix-icon-button\n @click=${() => this.onNodeToggle(this.node)}\n icon=${icon}\n test-id=\"tree-node-expand-toggle\"\n >\n </ix-icon-button>\n </div>`;\n }\n\n private onNodeClick(node: IIxTreeNode): void {\n const event = new CustomEvent('on-tree-node-click', {\n detail: {\n message: {\n node,\n id: node.id,\n label: node.label,\n parentId: node.parentId,\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 node,\n id: node.id,\n label: node.label,\n parentId: node.parentId,\n },\n },\n });\n\n this.dispatchEvent(event);\n }\n\n private onNodeCheck(node: IIxTreeNode): void {\n /* eslint-disable no-param-reassign */\n if (node.checked) {\n node.checked = false;\n node.indeterminate = false;\n } else {\n node.checked = true;\n node.indeterminate = false;\n }\n /* eslint-enable no-param-reassign */\n const event = new CustomEvent('on-tree-node-check', {\n detail: {\n message: {\n node,\n id: node.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 data-id=${this.node.id}\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>${this.getIcon()}</div>\n ${this.checkboxEnabled\n ? html`<ix-checkbox\n @click=${() => this.onNodeCheck(this.node)}\n label=\"\"\n style=\"margin: 6px 12px 0px 12px\"\n .checked=${this.node.checked}\n .indeterminate=${this.node.indeterminate}\n ></ix-checkbox>`\n : nothing}\n <ix-icon-button\n icon=${icon}\n appearance=${this.appearance}\n test-id=${`${this.node.id}-on-node-click-icon-button`}\n style=${this.hasChildren() ? '' : 'padding-left:2px;'}\n @click=${() => this.onNodeClick(this.node)}\n ></ix-icon-button>\n <div\n class=\"ix-tree-node__label\"\n @click=${() => {\n this.checkboxEnabled\n ? this.onNodeToggle(this.node)\n : this.onNodeClick(this.node);\n }}\n @keyup=${() => {\n this.checkboxEnabled\n ? this.onNodeToggle(this.node)\n : this.onNodeClick(this.node);\n }}\n >\n ${this.node.label}\n </div>\n </div>\n <slot></slot>\n </div>`;\n }\n\n protected updated(): void {\n if (!this._hasScrolledToActive) {\n const el = this.shadowRoot?.querySelector('[active-tree-node]');\n el?.scrollIntoView({ behavior: 'smooth', block: 'start' });\n this._hasScrolledToActive = true;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"IxTreeNode.js","sourceRoot":"","sources":["../src/IxTreeNode.ts"],"names":[],"mappings":";AAAA,OAAO,kDAAkD,CAAC;AAC1D,OAAO,4CAA4C,CAAC;AACpD,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAkB,MAAM,KAAK,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,wIAAwI;AACxI,8FAA8F;AAC9F,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,uBAA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G,CAAC,YAAY,CAAC,CAAC;AAEX;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;oDAAmC;AAElC;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;8CAA6B;AAE5B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;8CAA6B;AAE7B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yCAAmB;AAElB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCAAoB;AAElB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;mDAAkC;AAElC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8CAAoC;AAEtD;IAAR,KAAK,EAAE;wDAA+C","sourcesContent":["import '@digital-realty/ix-icon-button/ix-icon-button.js';\nimport '@digital-realty/ix-checkbox/ix-checkbox.js';\nimport '@digital-realty/theme';\nimport { html, LitElement, nothing, TemplateResult } from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { IIxTreeNode } from './IIxTreeNode.js';\nimport { IxTreeStyles } from './ix-tree-styles.js';\nimport { Appearance } from './IxTree.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.6;\nconst TREE_NODE_ICON_SIZE_REM = TREE_NODE_SPACER_REM * 4;\n\nexport class IxTreeNode extends LitElement {\n static readonly styles = [IxTreeStyles];\n\n @property({ type: Boolean }) isActiveTreeNode: boolean = false;\n\n @property({ type: Boolean }) isExpanded: boolean = false;\n\n @property({ type: Boolean }) isSelected: boolean = false;\n\n @property({ type: Number }) level: number = 0;\n\n @property({ type: Object }) node!: IIxTreeNode;\n\n @property({ type: Boolean }) checkboxEnabled: boolean = false;\n\n @property({ type: String }) appearance: Appearance = 'default';\n\n @state() private _hasScrolledToActive: boolean = false;\n\n private hasChildren() {\n return this.node.children !== undefined && this.node.children.length > 0;\n }\n\n private getIcon(): TemplateResult<1> | typeof nothing {\n const icon = this.isExpanded ? 'arrow_drop_down' : 'arrow_right';\n return html`<div\n style=${`${this.hasChildren() ? '' : 'visibility:hidden'}`}\n >\n <ix-icon-button\n @click=${() => this.onNodeToggle(this.node)}\n icon=${icon}\n test-id=\"tree-node-expand-toggle\"\n >\n </ix-icon-button>\n </div>`;\n }\n\n private onNodeClick(node: IIxTreeNode): void {\n const event = new CustomEvent('on-tree-node-click', {\n detail: {\n message: {\n node,\n id: node.id,\n label: node.label,\n parentId: node.parentId,\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 node,\n id: node.id,\n label: node.label,\n parentId: node.parentId,\n },\n },\n });\n\n this.dispatchEvent(event);\n }\n\n private onNodeCheck(node: IIxTreeNode): void {\n /* eslint-disable no-param-reassign */\n if (node.checked) {\n node.checked = false;\n node.indeterminate = false;\n } else {\n node.checked = true;\n node.indeterminate = false;\n }\n /* eslint-enable no-param-reassign */\n const event = new CustomEvent('on-tree-node-check', {\n detail: {\n message: {\n node,\n id: node.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 data-id=${this.node.id}\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>${this.getIcon()}</div>\n ${this.checkboxEnabled\n ? html`<ix-checkbox\n @click=${() => this.onNodeCheck(this.node)}\n label=\"\"\n style=\"margin: 6px 12px 0px 12px\"\n .checked=${this.node.checked}\n .indeterminate=${this.node.indeterminate}\n ></ix-checkbox>`\n : nothing}\n <ix-icon-button\n icon=${icon}\n appearance=${this.appearance}\n test-id=${`${this.node.id}-on-node-click-icon-button`}\n @click=${() => this.onNodeClick(this.node)}\n ></ix-icon-button>\n <div\n class=\"ix-tree-node__label\"\n @click=${() => {\n this.checkboxEnabled\n ? this.onNodeToggle(this.node)\n : this.onNodeClick(this.node);\n }}\n @keyup=${() => {\n this.checkboxEnabled\n ? this.onNodeToggle(this.node)\n : this.onNodeClick(this.node);\n }}\n >\n ${this.node.label}\n </div>\n </div>\n <slot></slot>\n </div>`;\n }\n\n protected updated(): void {\n if (!this._hasScrolledToActive) {\n const el = this.shadowRoot?.querySelector('[active-tree-node]');\n el?.scrollIntoView({ behavior: 'smooth', block: 'start' });\n this._hasScrolledToActive = true;\n }\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { IxTree } from './IxTree.js';
2
- export { IxTreeNode } from './IxTreeNode.js';
3
- export { IIxTreeNode } from './IIxTreeNode.js';
1
+ export { IxTree } from './IxTree.js';
2
+ export { IxTreeNode } from './IxTreeNode.js';
3
+ export { IIxTreeNode } from './IIxTreeNode.js';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { IxTree } from './IxTree.js';
2
- export { IxTreeNode } from './IxTreeNode.js';
1
+ export { IxTree } from './IxTree.js';
2
+ export { IxTreeNode } from './IxTreeNode.js';
3
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,3 +1,3 @@
1
- import { IxTreeNode } from './IxTreeNode.js';
2
- customElements.define('ix-tree-node', IxTreeNode);
1
+ import { IxTreeNode } from './IxTreeNode.js';
2
+ customElements.define('ix-tree-node', IxTreeNode);
3
3
  //# sourceMappingURL=ix-tree-node.js.map
@@ -1 +1 @@
1
- export declare const IxTreeStyles: import("lit").CSSResult;
1
+ export declare const IxTreeStyles: import("lit").CSSResult;
@@ -1,4 +1,4 @@
1
- import { css } from 'lit';
1
+ import { css } from 'lit';
2
2
  export const IxTreeStyles = css `
3
3
  :root,
4
4
  :host :root,
@@ -54,5 +54,5 @@ export const IxTreeStyles = css `
54
54
  background-color: rgba(20, 86, 224, 0.1);
55
55
  border-left: 3px solid #1456e0;
56
56
  }
57
- `;
57
+ `;
58
58
  //# sourceMappingURL=ix-tree-styles.js.map
package/dist/ix-tree.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/dist/ix-tree.js CHANGED
@@ -1,3 +1,3 @@
1
- import { IxTree } from './IxTree.js';
2
- customElements.define('ix-tree', IxTree);
1
+ import { IxTree } from './IxTree.js';
2
+ customElements.define('ix-tree', IxTree);
3
3
  //# sourceMappingURL=ix-tree.js.map
@@ -1,3 +1,3 @@
1
- import { IIxTreeNode } from './IIxTreeNode.js';
2
- export declare function findChildNodeById(node: IIxTreeNode, id: string): IIxTreeNode | null;
3
- export declare function updateNodeCheckedStatus(node: IIxTreeNode, rootNode: IIxTreeNode): void;
1
+ import { IIxTreeNode } from './IIxTreeNode.js';
2
+ export declare function findChildNodeById(node: IIxTreeNode, id: string): IIxTreeNode | null;
3
+ export declare function updateNodeCheckedStatus(node: IIxTreeNode, rootNode: IIxTreeNode): void;
@@ -1,56 +1,56 @@
1
- export function findChildNodeById(node, id) {
2
- if (node.id === id) {
3
- return node;
4
- }
5
- if (!node.children) {
6
- return null;
7
- }
8
- for (const childNode of node.children) {
9
- const foundNode = findChildNodeById(childNode, id);
10
- if (foundNode) {
11
- return foundNode;
12
- }
13
- }
14
- return null;
15
- }
16
- export function updateNodeCheckedStatus(node, rootNode) {
17
- /* eslint-disable no-param-reassign */
18
- function updateChildren(n, checked = false) {
19
- n.checked = checked;
20
- n.indeterminate = false;
21
- if (n.children) {
22
- n.children.forEach(child => {
23
- updateChildren(child, checked);
24
- });
25
- }
26
- }
27
- function updateParents(n) {
28
- if (n.parentId) {
29
- const currentParent = findChildNodeById(rootNode, n.parentId);
30
- if (currentParent && currentParent.children) {
31
- if (currentParent.children.every(child => child.checked)) {
32
- currentParent.checked = true;
33
- currentParent.indeterminate = false;
34
- }
35
- else if (currentParent.children.some(child => child.checked)) {
36
- currentParent.checked = false;
37
- currentParent.indeterminate = true;
38
- }
39
- else if (currentParent.children.some(c => c.indeterminate)) {
40
- currentParent.checked = false;
41
- currentParent.indeterminate = true;
42
- }
43
- else {
44
- currentParent.checked = false;
45
- currentParent.indeterminate = false;
46
- }
47
- updateParents(currentParent);
48
- }
49
- }
50
- }
51
- // update all children to match current node checked status
52
- updateChildren(node, node.checked);
53
- // update all parents checked and indeterminate status
54
- updateParents(node);
55
- }
1
+ export function findChildNodeById(node, id) {
2
+ if (node.id === id) {
3
+ return node;
4
+ }
5
+ if (!node.children) {
6
+ return null;
7
+ }
8
+ for (const childNode of node.children) {
9
+ const foundNode = findChildNodeById(childNode, id);
10
+ if (foundNode) {
11
+ return foundNode;
12
+ }
13
+ }
14
+ return null;
15
+ }
16
+ export function updateNodeCheckedStatus(node, rootNode) {
17
+ /* eslint-disable no-param-reassign */
18
+ function updateChildren(n, checked = false) {
19
+ n.checked = checked;
20
+ n.indeterminate = false;
21
+ if (n.children) {
22
+ n.children.forEach(child => {
23
+ updateChildren(child, checked);
24
+ });
25
+ }
26
+ }
27
+ function updateParents(n) {
28
+ if (n.parentId) {
29
+ const currentParent = findChildNodeById(rootNode, n.parentId);
30
+ if (currentParent && currentParent.children) {
31
+ if (currentParent.children.every(child => child.checked)) {
32
+ currentParent.checked = true;
33
+ currentParent.indeterminate = false;
34
+ }
35
+ else if (currentParent.children.some(child => child.checked)) {
36
+ currentParent.checked = false;
37
+ currentParent.indeterminate = true;
38
+ }
39
+ else if (currentParent.children.some(c => c.indeterminate)) {
40
+ currentParent.checked = false;
41
+ currentParent.indeterminate = true;
42
+ }
43
+ else {
44
+ currentParent.checked = false;
45
+ currentParent.indeterminate = false;
46
+ }
47
+ updateParents(currentParent);
48
+ }
49
+ }
50
+ }
51
+ // update all children to match current node checked status
52
+ updateChildren(node, node.checked);
53
+ // update all parents checked and indeterminate status
54
+ updateParents(node);
55
+ }
56
56
  //# sourceMappingURL=tree-utils.js.map
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent ix-tree following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "Digital Realty",
6
- "version": "1.0.16",
6
+ "version": "1.0.18",
7
7
  "type": "module",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.js",
@@ -26,12 +26,12 @@
26
26
  "test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --watch\""
27
27
  },
28
28
  "dependencies": {
29
- "@digital-realty/ix-checkbox": "^1.1.9",
30
- "@digital-realty/ix-icon": "*",
31
- "@digital-realty/ix-icon-button": "^1.0.19",
32
- "@digital-realty/theme": "^1.0.9",
29
+ "@digital-realty/ix-checkbox": "^1.1.11",
30
+ "@digital-realty/ix-icon": "^1.0.3",
31
+ "@digital-realty/ix-icon-button": "^1.0.21",
32
+ "@digital-realty/theme": "*",
33
33
  "@lit-labs/react": "^2.1.0",
34
- "@material/web": "^1.0.0",
34
+ "@material/web": "1.2.0",
35
35
  "lit": "^2.0.2",
36
36
  "react": "^18.2.0"
37
37
  },
@@ -100,5 +100,6 @@
100
100
  "package.json",
101
101
  "README.md",
102
102
  "LICENSE"
103
- ]
103
+ ],
104
+ "gitHead": "a93ad0076764dc26321faa51bc504ff6b534d836"
104
105
  }