@operato/data-tree 9.0.1 → 9.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,23 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ### [9.0.34](https://github.com/hatiolab/operato/compare/v9.0.33...v9.0.34) (2025-09-15)
7
+
8
+ **Note:** Version bump only for package @operato/data-tree
9
+
10
+
11
+
12
+
13
+
14
+ ### [9.0.2](https://github.com/hatiolab/operato/compare/v9.0.1...v9.0.2) (2025-07-01)
15
+
16
+
17
+ ### :bug: Bug Fix
18
+
19
+ * invalid package configuration ([ccde20b](https://github.com/hatiolab/operato/commit/ccde20b75e6cbd1f881e5bac631e361aebfd21c3))
20
+
21
+
22
+
6
23
  ### [9.0.1](https://github.com/hatiolab/operato/compare/v9.0.0...v9.0.1) (2025-07-01)
7
24
 
8
25
  **Note:** Version bump only for package @operato/data-tree
@@ -0,0 +1,3 @@
1
+ export * from './ox-tree.js';
2
+ export * from './ox-tree-vertical.js';
3
+ export * from './ox-tree-horizontal.js';
@@ -0,0 +1,4 @@
1
+ export * from './ox-tree.js';
2
+ export * from './ox-tree-vertical.js';
3
+ export * from './ox-tree-horizontal.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,yBAAyB,CAAA","sourcesContent":["export * from './ox-tree.js'\nexport * from './ox-tree-vertical.js'\nexport * from './ox-tree-horizontal.js'\n"]}
@@ -0,0 +1,21 @@
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ type TreeItem = {
3
+ [key: string]: any;
4
+ __status__?: {
5
+ [state: string]: boolean | string;
6
+ };
7
+ };
8
+ export declare class TreeViewHorizontal extends LitElement {
9
+ static styles: import("lit").CSSResult[];
10
+ data?: TreeItem | TreeItem[];
11
+ selected?: TreeItem;
12
+ idProperty: string;
13
+ labelProperty: string;
14
+ descriptionProperty?: string;
15
+ childrenProperty: string;
16
+ render(): TemplateResult<1>;
17
+ renderItem(item: TreeItem): TemplateResult;
18
+ onClickSelect(e: MouseEvent): void;
19
+ onClickSelectConfirm(e: MouseEvent): void;
20
+ }
21
+ export {};
@@ -0,0 +1,262 @@
1
+ import { __decorate } from "tslib";
2
+ import { html, css, LitElement, nothing } from 'lit';
3
+ import { customElement, property } from 'lit/decorators.js';
4
+ import { ScrollbarStyles } from '@operato/styles';
5
+ let TreeViewHorizontal = class TreeViewHorizontal extends LitElement {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.idProperty = 'id';
9
+ this.labelProperty = 'label';
10
+ this.childrenProperty = 'children';
11
+ }
12
+ render() {
13
+ if (!this.data)
14
+ return html ``;
15
+ const dataArray = Array.isArray(this.data) ? this.data : [this.data];
16
+ return html `
17
+ ${dataArray.map(root => html `
18
+ <ul root>
19
+ ${this.renderItem(root)}
20
+ </ul>
21
+ `)}
22
+ `;
23
+ }
24
+ renderItem(item) {
25
+ var _a;
26
+ const id = item[this.idProperty];
27
+ const label = item[this.labelProperty];
28
+ const children = item[this.childrenProperty];
29
+ const expandable = children && children.length > 0;
30
+ const selected = id === ((_a = this.selected) === null || _a === void 0 ? void 0 : _a[this.idProperty]);
31
+ return html `
32
+ <li .item=${item}>
33
+ <span
34
+ ?selected=${selected}
35
+ @click=${this.onClickSelect.bind(this)}
36
+ @dblclick=${this.onClickSelectConfirm.bind(this)}
37
+ >
38
+ <div header>${id}</div>
39
+ <div label>${label}</div>
40
+ ${this.descriptionProperty ? html ` <div description>${item[this.descriptionProperty]}&nbsp;</div>` : nothing}
41
+ </span>
42
+
43
+ ${expandable
44
+ ? html `
45
+ <ul>
46
+ ${children.map(child => this.renderItem(child))}
47
+ </ul>
48
+ `
49
+ : html ``}
50
+ </li>
51
+ `;
52
+ }
53
+ onClickSelect(e) {
54
+ var _a;
55
+ e.stopPropagation();
56
+ const target = e.target;
57
+ this.selected = (_a = target.closest('li')) === null || _a === void 0 ? void 0 : _a.item;
58
+ this.dispatchEvent(new CustomEvent('select', {
59
+ detail: this.selected
60
+ }));
61
+ }
62
+ onClickSelectConfirm(e) {
63
+ var _a;
64
+ e.stopPropagation();
65
+ const target = e.target;
66
+ this.selected = (_a = target.closest('li')) === null || _a === void 0 ? void 0 : _a.item;
67
+ this.dispatchEvent(new CustomEvent('select-confirm', {
68
+ detail: this.selected
69
+ }));
70
+ }
71
+ };
72
+ TreeViewHorizontal.styles = [
73
+ ScrollbarStyles,
74
+ css `
75
+ :host {
76
+ display: block;
77
+ overflow: auto;
78
+ padding: 1em;
79
+ }
80
+
81
+ ul,
82
+ li {
83
+ list-style: none;
84
+ margin: 0;
85
+ padding: 0;
86
+ position: relative;
87
+ }
88
+
89
+ ul[root] {
90
+ margin: 0 0 1em;
91
+ text-align: left;
92
+ }
93
+
94
+ ul[root]:before {
95
+ display: none;
96
+ }
97
+
98
+ ul {
99
+ display: flex;
100
+ flex-direction: column;
101
+ align-items: flex-start;
102
+ justify-content: center;
103
+ }
104
+
105
+ ul {
106
+ width: 100%;
107
+ }
108
+
109
+ li {
110
+ display: flex;
111
+ flex-direction: row;
112
+ position: relative;
113
+ align-items: center;
114
+ }
115
+
116
+ li:before,
117
+ li:after {
118
+ content: '';
119
+ position: absolute;
120
+ left: -1em;
121
+ border-left: 1px solid #666;
122
+ }
123
+
124
+ li:before {
125
+ top: 0;
126
+ bottom: 50%;
127
+ }
128
+
129
+ li:after {
130
+ top: 50%;
131
+ bottom: 0;
132
+ border-top: 1px solid #666;
133
+ width: 1em;
134
+ }
135
+
136
+ ul[root] > li:after {
137
+ content: none;
138
+ }
139
+
140
+ li:first-child:before {
141
+ top: 50%;
142
+ }
143
+
144
+ li:last-child:after {
145
+ bottom: 50%;
146
+ }
147
+
148
+ li > ul {
149
+ padding-left: 2em;
150
+ position: relative;
151
+ }
152
+
153
+ li > ul:before {
154
+ content: '';
155
+ position: absolute;
156
+ top: 0;
157
+ bottom: -2px;
158
+ left: 0;
159
+ border-bottom: 1px solid #666;
160
+ }
161
+
162
+ code,
163
+ span {
164
+ border: solid 0.1em #666;
165
+ border-radius: 0.2em;
166
+ display: inline-block;
167
+ margin: 0.3em 0;
168
+ position: relative;
169
+ min-width: 120px;
170
+ background-color: #f9f9f9;
171
+ }
172
+
173
+ span[selected] {
174
+ color: var(--md-sys-color-on-tertiary);
175
+ background-color: var(--md-sys-color-tertiary);
176
+ }
177
+
178
+ ul:before,
179
+ code:before,
180
+ span:before {
181
+ content: '';
182
+ width: 1em;
183
+ top: 50%;
184
+ position: absolute;
185
+ transform: translateY(-50%);
186
+ }
187
+
188
+ ul:before {
189
+ left: -1em;
190
+ }
191
+
192
+ code:before,
193
+ span:before {
194
+ left: -1.1em;
195
+ }
196
+
197
+ ul[root] > li {
198
+ margin-left: 0;
199
+ }
200
+
201
+ ul[root] > li:before,
202
+ ul[root] > li:after,
203
+ ul[root] > li > code:before,
204
+ ul[root] > li > span:before {
205
+ outline: none;
206
+ }
207
+
208
+ span {
209
+ display: inline-block;
210
+ background-color: var(--md-sys-color-surface);
211
+
212
+ div[header] {
213
+ font-weight: bold;
214
+ font-size: 0.8em;
215
+ color: var(--md-sys-color-on-primary, #fff);
216
+ background-color: var(--md-sys-color-primary, #333);
217
+ padding: 0.5em 1em;
218
+ text-align: center;
219
+ width: 100%;
220
+ box-sizing: border-box;
221
+ border-bottom: 1px solid rgba(0, 0, 0, 0.1);
222
+ }
223
+
224
+ div[label] {
225
+ font-size: 1em;
226
+ background-color: transparent;
227
+ padding: 0.5em;
228
+ text-align: left;
229
+ }
230
+
231
+ div[description] {
232
+ font-size: 0.8em;
233
+ background-color: transparent;
234
+ padding: 0.5em;
235
+ text-align: left;
236
+ }
237
+ }
238
+ `
239
+ ];
240
+ __decorate([
241
+ property({ type: Object })
242
+ ], TreeViewHorizontal.prototype, "data", void 0);
243
+ __decorate([
244
+ property({ type: Object })
245
+ ], TreeViewHorizontal.prototype, "selected", void 0);
246
+ __decorate([
247
+ property({ type: String, attribute: 'id-property' })
248
+ ], TreeViewHorizontal.prototype, "idProperty", void 0);
249
+ __decorate([
250
+ property({ type: String, attribute: 'label-property' })
251
+ ], TreeViewHorizontal.prototype, "labelProperty", void 0);
252
+ __decorate([
253
+ property({ type: String, attribute: 'description-property' })
254
+ ], TreeViewHorizontal.prototype, "descriptionProperty", void 0);
255
+ __decorate([
256
+ property({ type: String, attribute: 'children-property' })
257
+ ], TreeViewHorizontal.prototype, "childrenProperty", void 0);
258
+ TreeViewHorizontal = __decorate([
259
+ customElement('ox-tree-horizontal')
260
+ ], TreeViewHorizontal);
261
+ export { TreeViewHorizontal };
262
+ //# sourceMappingURL=ox-tree-horizontal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ox-tree-horizontal.js","sourceRoot":"","sources":["../../src/ox-tree-horizontal.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAkB,OAAO,EAAE,MAAM,KAAK,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAQ1C,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,UAAU;IAA3C;;QA4KiD,eAAU,GAAW,IAAI,CAAA;QACtB,kBAAa,GAAW,OAAO,CAAA;QAE5B,qBAAgB,GAAW,UAAU,CAAA;IA0EnG,CAAC;IAxEC,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAA,EAAE,CAAA;QAE7B,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CA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Q,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,sBAAsB,EAAE,CAAC;+DAA6B;AAC/B;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC;4DAAsC;AA/KtF,kBAAkB;IAD9B,aAAa,CAAC,oBAAoB,CAAC;GACvB,kBAAkB,CAyP9B","sourcesContent":["import { html, css, LitElement, TemplateResult, nothing } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { ScrollbarStyles } from '@operato/styles'\n\ntype TreeItem = {\n [key: string]: any\n __status__?: { [state: string]: boolean | string }\n}\n\n@customElement('ox-tree-horizontal')\nexport class TreeViewHorizontal extends LitElement {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n display: block;\n overflow: auto;\n padding: 1em;\n }\n\n ul,\n li {\n list-style: none;\n margin: 0;\n padding: 0;\n position: relative;\n }\n\n ul[root] {\n margin: 0 0 1em;\n text-align: left;\n }\n\n ul[root]:before {\n display: none;\n }\n\n ul {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n justify-content: center;\n }\n\n ul {\n width: 100%;\n }\n\n li {\n display: flex;\n flex-direction: row;\n position: relative;\n align-items: center;\n }\n\n li:before,\n li:after {\n content: '';\n position: absolute;\n left: -1em;\n border-left: 1px solid #666;\n }\n\n li:before {\n top: 0;\n bottom: 50%;\n }\n\n li:after {\n top: 50%;\n bottom: 0;\n border-top: 1px solid #666;\n width: 1em;\n }\n\n ul[root] > li:after {\n content: none;\n }\n\n li:first-child:before {\n top: 50%;\n }\n\n li:last-child:after {\n bottom: 50%;\n }\n\n li > ul {\n padding-left: 2em;\n position: relative;\n }\n\n li > ul:before {\n content: '';\n position: absolute;\n top: 0;\n bottom: -2px;\n left: 0;\n border-bottom: 1px solid #666;\n }\n\n code,\n span {\n border: solid 0.1em #666;\n border-radius: 0.2em;\n display: inline-block;\n margin: 0.3em 0;\n position: relative;\n min-width: 120px;\n background-color: #f9f9f9;\n }\n\n span[selected] {\n color: var(--md-sys-color-on-tertiary);\n background-color: var(--md-sys-color-tertiary);\n }\n\n ul:before,\n code:before,\n span:before {\n content: '';\n width: 1em;\n top: 50%;\n position: absolute;\n transform: translateY(-50%);\n }\n\n ul:before {\n left: -1em;\n }\n\n code:before,\n span:before {\n left: -1.1em;\n }\n\n ul[root] > li {\n margin-left: 0;\n }\n\n ul[root] > li:before,\n ul[root] > li:after,\n ul[root] > li > code:before,\n ul[root] > li > span:before {\n outline: none;\n }\n\n span {\n display: inline-block;\n background-color: var(--md-sys-color-surface);\n\n div[header] {\n font-weight: bold;\n font-size: 0.8em;\n color: var(--md-sys-color-on-primary, #fff);\n background-color: var(--md-sys-color-primary, #333);\n padding: 0.5em 1em;\n text-align: center;\n width: 100%;\n box-sizing: border-box;\n border-bottom: 1px solid rgba(0, 0, 0, 0.1);\n }\n\n div[label] {\n font-size: 1em;\n background-color: transparent;\n padding: 0.5em;\n text-align: left;\n }\n\n div[description] {\n font-size: 0.8em;\n background-color: transparent;\n padding: 0.5em;\n text-align: left;\n }\n }\n `\n ]\n\n @property({ type: Object }) data?: TreeItem | TreeItem[]\n @property({ type: Object }) selected?: TreeItem\n @property({ type: String, attribute: 'id-property' }) idProperty: string = 'id'\n @property({ type: String, attribute: 'label-property' }) labelProperty: string = 'label'\n @property({ type: String, attribute: 'description-property' }) descriptionProperty?: string\n @property({ type: String, attribute: 'children-property' }) childrenProperty: string = 'children'\n\n render() {\n if (!this.data) return html``\n\n const dataArray = Array.isArray(this.data) ? this.data : [this.data]\n\n return html`\n ${dataArray.map(\n root => html`\n <ul root>\n ${this.renderItem(root)}\n </ul>\n `\n )}\n `\n }\n\n renderItem(item: TreeItem): TemplateResult {\n const id = item[this.idProperty]\n const label = item[this.labelProperty]\n const children = item[this.childrenProperty] as TreeItem[]\n\n const expandable = children && children.length > 0\n const selected = id === this.selected?.[this.idProperty]\n\n return html`\n <li .item=${item}>\n <span\n ?selected=${selected}\n @click=${this.onClickSelect.bind(this)}\n @dblclick=${this.onClickSelectConfirm.bind(this)}\n >\n <div header>${id}</div>\n <div label>${label}</div>\n ${this.descriptionProperty ? html` <div description>${item[this.descriptionProperty]}&nbsp;</div>` : nothing}\n </span>\n\n ${expandable\n ? html`\n <ul>\n ${children.map(child => this.renderItem(child))}\n </ul>\n `\n : html``}\n </li>\n `\n }\n\n onClickSelect(e: MouseEvent) {\n e.stopPropagation()\n\n const target = e.target as HTMLElement\n this.selected = (target.closest('li') as any)?.item\n\n this.dispatchEvent(\n new CustomEvent('select', {\n detail: this.selected\n })\n )\n }\n\n onClickSelectConfirm(e: MouseEvent) {\n e.stopPropagation()\n\n const target = e.target as HTMLElement\n this.selected = (target.closest('li') as any)?.item\n\n this.dispatchEvent(\n new CustomEvent('select-confirm', {\n detail: this.selected\n })\n )\n }\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ type TreeItem = {
3
+ [key: string]: any;
4
+ __status__?: {
5
+ [state: string]: boolean | string;
6
+ };
7
+ };
8
+ export declare class TreeViewVertical extends LitElement {
9
+ static styles: import("lit").CSSResult[];
10
+ data?: TreeItem | TreeItem[];
11
+ selected?: TreeItem;
12
+ idProperty: string;
13
+ labelProperty: string;
14
+ descriptionProperty?: string;
15
+ childrenProperty: string;
16
+ render(): TemplateResult<1>;
17
+ renderItem(item: TreeItem): TemplateResult;
18
+ onClickSelect(e: MouseEvent): void;
19
+ onClickSelectConfirm(e: MouseEvent): void;
20
+ }
21
+ export {};
@@ -0,0 +1,229 @@
1
+ /* Inspired by https://www.cssscript.com/clean-tree-diagram/ */
2
+ import { __decorate } from "tslib";
3
+ import { html, css, LitElement, nothing } from 'lit';
4
+ import { customElement, property } from 'lit/decorators.js';
5
+ import { ScrollbarStyles } from '@operato/styles';
6
+ let TreeViewVertical = class TreeViewVertical extends LitElement {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.idProperty = 'id';
10
+ this.labelProperty = 'label';
11
+ this.childrenProperty = 'children';
12
+ }
13
+ render() {
14
+ if (!this.data)
15
+ return html ``;
16
+ const dataArray = Array.isArray(this.data) ? this.data : [this.data];
17
+ return html `
18
+ ${dataArray.map(root => html `
19
+ <ul root>
20
+ ${this.renderItem(root)}
21
+ </ul>
22
+ `)}
23
+ `;
24
+ }
25
+ renderItem(item) {
26
+ var _a;
27
+ const id = item[this.idProperty];
28
+ const label = item[this.labelProperty];
29
+ const children = item[this.childrenProperty];
30
+ const expandable = children && children.length > 0;
31
+ const selected = id === ((_a = this.selected) === null || _a === void 0 ? void 0 : _a[this.idProperty]);
32
+ return html `
33
+ <li .item=${item}>
34
+ <span
35
+ ?selected=${selected}
36
+ @click=${this.onClickSelect.bind(this)}
37
+ @dblclick=${this.onClickSelectConfirm.bind(this)}
38
+ >
39
+ <div header>${id}</div>
40
+ <div label>${label}</div>
41
+ ${this.descriptionProperty ? html ` <div description>${item[this.descriptionProperty]}&nbsp;</div>` : nothing}
42
+ </span>
43
+
44
+ ${expandable
45
+ ? html `
46
+ <ul>
47
+ ${children.map(child => this.renderItem(child))}
48
+ </ul>
49
+ `
50
+ : html ``}
51
+ </li>
52
+ `;
53
+ }
54
+ onClickSelect(e) {
55
+ var _a;
56
+ e.stopPropagation();
57
+ const target = e.target;
58
+ this.selected = (_a = target.closest('li')) === null || _a === void 0 ? void 0 : _a.item;
59
+ this.dispatchEvent(new CustomEvent('select', {
60
+ detail: this.selected
61
+ }));
62
+ }
63
+ onClickSelectConfirm(e) {
64
+ var _a;
65
+ e.stopPropagation();
66
+ const target = e.target;
67
+ this.selected = (_a = target.closest('li')) === null || _a === void 0 ? void 0 : _a.item;
68
+ this.dispatchEvent(new CustomEvent('select-confirm', {
69
+ detail: this.selected
70
+ }));
71
+ }
72
+ };
73
+ TreeViewVertical.styles = [
74
+ ScrollbarStyles,
75
+ css `
76
+ :host {
77
+ display: block;
78
+ overflow: auto;
79
+ }
80
+
81
+ ul,
82
+ li {
83
+ list-style: none;
84
+ margin: 0;
85
+ padding: 0;
86
+ position: relative;
87
+ }
88
+
89
+ ul[root] {
90
+ margin: 0 0 1em;
91
+ text-align: center;
92
+ }
93
+
94
+ ul[root]:before,
95
+ ul[root]:after {
96
+ display: none;
97
+ }
98
+
99
+ ul {
100
+ display: table;
101
+ }
102
+
103
+ ul {
104
+ width: 100%;
105
+ }
106
+
107
+ li {
108
+ display: table-cell;
109
+ padding: 1em 0;
110
+ vertical-align: top;
111
+ }
112
+
113
+ li:before {
114
+ outline: solid 1px #666;
115
+ content: '';
116
+ left: 0;
117
+ position: absolute;
118
+ right: 0;
119
+ top: 0;
120
+ }
121
+
122
+ li:first-child:before {
123
+ left: 50%;
124
+ }
125
+
126
+ li:last-child:before {
127
+ right: 50%;
128
+ }
129
+
130
+ code,
131
+ span {
132
+ border: solid 0.1em #666;
133
+ border-radius: 0.2em;
134
+ display: inline-block;
135
+ margin: 0 0.2em 1em;
136
+ position: relative;
137
+ min-width: 120px;
138
+ }
139
+
140
+ span[selected] {
141
+ color: var(--md-sys-color-on-tertiary);
142
+ background-color: var(--md-sys-color-tertiary);
143
+ }
144
+
145
+ ul:before,
146
+ code:before,
147
+ span:before {
148
+ outline: solid 1px #666;
149
+ content: '';
150
+ height: 1em;
151
+ left: 50%;
152
+ position: absolute;
153
+ }
154
+
155
+ ul:before {
156
+ top: -1em;
157
+ }
158
+
159
+ code:before,
160
+ span:before {
161
+ top: -1.1em;
162
+ }
163
+
164
+ ul[root] > li {
165
+ margin-top: 0;
166
+ }
167
+
168
+ ul[root] > li:before,
169
+ ul[root] > li:after,
170
+ ul[root] > li > code:before,
171
+ ul[root] > li > span:before {
172
+ outline: none;
173
+ }
174
+
175
+ span {
176
+ display: inline-block;
177
+ background-color: var(--md-sys-color-surface);
178
+
179
+ div[header] {
180
+ font-weight: bold;
181
+ font-size: 0.8em;
182
+ color: var(--md-sys-color-on-primary, #fff);
183
+ background-color: var(--md-sys-color-primary, #333);
184
+ padding: 0.5em 1em;
185
+ text-align: center;
186
+ width: 100%;
187
+ box-sizing: border-box;
188
+ border-bottom: 1px solid rgba(0, 0, 0, 0.1);
189
+ }
190
+
191
+ div[label] {
192
+ font-size: 1em;
193
+ background-color: transparent;
194
+ padding: 0.5em;
195
+ text-align: left;
196
+ }
197
+
198
+ div[description] {
199
+ font-size: 0.8em;
200
+ background-color: transparent;
201
+ padding: 0.5em;
202
+ text-align: left;
203
+ }
204
+ }
205
+ `
206
+ ];
207
+ __decorate([
208
+ property({ type: Object })
209
+ ], TreeViewVertical.prototype, "data", void 0);
210
+ __decorate([
211
+ property({ type: Object })
212
+ ], TreeViewVertical.prototype, "selected", void 0);
213
+ __decorate([
214
+ property({ type: String, attribute: 'id-property' })
215
+ ], TreeViewVertical.prototype, "idProperty", void 0);
216
+ __decorate([
217
+ property({ type: String, attribute: 'label-property' })
218
+ ], TreeViewVertical.prototype, "labelProperty", void 0);
219
+ __decorate([
220
+ property({ type: String, attribute: 'description-property' })
221
+ ], TreeViewVertical.prototype, "descriptionProperty", void 0);
222
+ __decorate([
223
+ property({ type: String, attribute: 'children-property' })
224
+ ], TreeViewVertical.prototype, "childrenProperty", void 0);
225
+ TreeViewVertical = __decorate([
226
+ customElement('ox-tree-vertical')
227
+ ], TreeViewVertical);
228
+ export { TreeViewVertical };
229
+ //# sourceMappingURL=ox-tree-vertical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ox-tree-vertical.js","sourceRoot":"","sources":["../../src/ox-tree-vertical.ts"],"names":[],"mappings":"AAAA,+DAA+D;;AAE/D,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAkB,OAAO,EAAE,MAAM,KAAK,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAO1C,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,UAAU;IAAzC;;QA0IiD,eAAU,GAAW,IAAI,CA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AE,MAAM,EAAE,CAAC;kDAAoB;AACO;IAArD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;oDAA0B;AACtB;IAAxD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;uDAAgC;AACzB;IAA9D,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,sBAAsB,EAAE,CAAC;6DAA6B;AAC/B;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC;0DAAsC;AA7ItF,gBAAgB;IAD5B,aAAa,CAAC,kBAAkB,CAAC;GACrB,gBAAgB,CAuN5B","sourcesContent":["/* Inspired by https://www.cssscript.com/clean-tree-diagram/ */\n\nimport { html, css, LitElement, TemplateResult, nothing } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { ScrollbarStyles } from '@operato/styles'\ntype TreeItem = {\n [key: string]: any\n __status__?: { [state: string]: boolean | string }\n}\n\n@customElement('ox-tree-vertical')\nexport class TreeViewVertical extends LitElement {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n display: block;\n overflow: auto;\n }\n\n ul,\n li {\n list-style: none;\n margin: 0;\n padding: 0;\n position: relative;\n }\n\n ul[root] {\n margin: 0 0 1em;\n text-align: center;\n }\n\n ul[root]:before,\n ul[root]:after {\n display: none;\n }\n\n ul {\n display: table;\n }\n\n ul {\n width: 100%;\n }\n\n li {\n display: table-cell;\n padding: 1em 0;\n vertical-align: top;\n }\n\n li:before {\n outline: solid 1px #666;\n content: '';\n left: 0;\n position: absolute;\n right: 0;\n top: 0;\n }\n\n li:first-child:before {\n left: 50%;\n }\n\n li:last-child:before {\n right: 50%;\n }\n\n code,\n span {\n border: solid 0.1em #666;\n border-radius: 0.2em;\n display: inline-block;\n margin: 0 0.2em 1em;\n position: relative;\n min-width: 120px;\n }\n\n span[selected] {\n color: var(--md-sys-color-on-tertiary);\n background-color: var(--md-sys-color-tertiary);\n }\n\n ul:before,\n code:before,\n span:before {\n outline: solid 1px #666;\n content: '';\n height: 1em;\n left: 50%;\n position: absolute;\n }\n\n ul:before {\n top: -1em;\n }\n\n code:before,\n span:before {\n top: -1.1em;\n }\n\n ul[root] > li {\n margin-top: 0;\n }\n\n ul[root] > li:before,\n ul[root] > li:after,\n ul[root] > li > code:before,\n ul[root] > li > span:before {\n outline: none;\n }\n\n span {\n display: inline-block;\n background-color: var(--md-sys-color-surface);\n\n div[header] {\n font-weight: bold;\n font-size: 0.8em;\n color: var(--md-sys-color-on-primary, #fff);\n background-color: var(--md-sys-color-primary, #333);\n padding: 0.5em 1em;\n text-align: center;\n width: 100%;\n box-sizing: border-box;\n border-bottom: 1px solid rgba(0, 0, 0, 0.1);\n }\n\n div[label] {\n font-size: 1em;\n background-color: transparent;\n padding: 0.5em;\n text-align: left;\n }\n\n div[description] {\n font-size: 0.8em;\n background-color: transparent;\n padding: 0.5em;\n text-align: left;\n }\n }\n `\n ]\n\n @property({ type: Object }) data?: TreeItem | TreeItem[]\n @property({ type: Object }) selected?: TreeItem\n @property({ type: String, attribute: 'id-property' }) idProperty: string = 'id'\n @property({ type: String, attribute: 'label-property' }) labelProperty: string = 'label'\n @property({ type: String, attribute: 'description-property' }) descriptionProperty?: string\n @property({ type: String, attribute: 'children-property' }) childrenProperty: string = 'children'\n\n render() {\n if (!this.data) return html``\n\n const dataArray = Array.isArray(this.data) ? this.data : [this.data]\n\n return html`\n ${dataArray.map(\n root => html`\n <ul root>\n ${this.renderItem(root)}\n </ul>\n `\n )}\n `\n }\n\n renderItem(item: TreeItem): TemplateResult {\n const id = item[this.idProperty]\n const label = item[this.labelProperty]\n const children = item[this.childrenProperty] as TreeItem[]\n\n const expandable = children && children.length > 0\n const selected = id === this.selected?.[this.idProperty]\n\n return html`\n <li .item=${item}>\n <span\n ?selected=${selected}\n @click=${this.onClickSelect.bind(this)}\n @dblclick=${this.onClickSelectConfirm.bind(this)}\n >\n <div header>${id}</div>\n <div label>${label}</div>\n ${this.descriptionProperty ? html` <div description>${item[this.descriptionProperty]}&nbsp;</div>` : nothing}\n </span>\n\n ${expandable\n ? html`\n <ul>\n ${children.map(child => this.renderItem(child))}\n </ul>\n `\n : html``}\n </li>\n `\n }\n\n onClickSelect(e: MouseEvent) {\n e.stopPropagation()\n\n const target = e.target as HTMLElement\n this.selected = (target.closest('li') as any)?.item\n\n this.dispatchEvent(\n new CustomEvent('select', {\n detail: this.selected\n })\n )\n }\n\n onClickSelectConfirm(e: MouseEvent) {\n e.stopPropagation()\n\n const target = e.target as HTMLElement\n this.selected = (target.closest('li') as any)?.item\n\n this.dispatchEvent(\n new CustomEvent('select-confirm', {\n detail: this.selected\n })\n )\n }\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ type TreeItem = {
3
+ [key: string]: any;
4
+ __status__?: {
5
+ [state: string]: boolean | string;
6
+ };
7
+ };
8
+ export declare class OxTree extends LitElement {
9
+ static styles: import("lit").CSSResult[];
10
+ data?: TreeItem;
11
+ selected?: TreeItem;
12
+ idProperty: string;
13
+ labelProperty: string;
14
+ childrenProperty: string;
15
+ direction: 'ltr' | 'rtl';
16
+ labelExtends: boolean;
17
+ checkable: boolean;
18
+ render(): TemplateResult<1>;
19
+ renderItem(item: TreeItem): TemplateResult;
20
+ onPointerDown(e: MouseEvent): void;
21
+ onClickExpander(e: MouseEvent): void;
22
+ onClickItem(e: MouseEvent): void;
23
+ walkTreeCheckedUpdate(item: TreeItem, checked?: string): void;
24
+ updateCheckedAll(item: TreeItem): void;
25
+ findNodeBounds(nodeId: string): {
26
+ left: number;
27
+ top: number;
28
+ width: number;
29
+ height: number;
30
+ } | undefined;
31
+ findNodeSelfBounds(nodeId: string): {
32
+ left: number;
33
+ top: number;
34
+ width: number;
35
+ height: number;
36
+ } | undefined;
37
+ private findNodePath;
38
+ }
39
+ export {};