@neovici/cosmoz-treenode-navigator 3.0.8 → 4.0.0
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 +26 -0
- package/cc-test-reporter +0 -0
- package/cosmoz-treenode-button-view.js +199 -113
- package/cosmoz-treenode-navigator.js +295 -496
- package/helpers.js +252 -0
- package/package.json +22 -8
- package/test/cosmoz-treenode-navigator.test.js +62 -28
- package/test/data/basicTree.js +98 -41
- package/web-test-runner.config.mjs +1 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
# [4.0.0](https://github.com/neovici/cosmoz-treenode-navigator/compare/v3.1.1...v4.0.0) (2022-07-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Code Refactoring
|
|
5
|
+
|
|
6
|
+
* **migration:** index.html - Remove formatting changes ([c12af88](https://github.com/neovici/cosmoz-treenode-navigator/commit/c12af889c5b4f5f3b191538e2280c4b29b185b3e))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* **migration:** migration to haunted.js and Lit
|
|
12
|
+
|
|
13
|
+
## [3.1.1](https://github.com/neovici/cosmoz-treenode-navigator/compare/v3.1.0...v3.1.1) (2022-06-02)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **chips:** scrollbar for many chips ([dc68de6](https://github.com/neovici/cosmoz-treenode-navigator/commit/dc68de694ebedc8a78b4df8ecdf13d108a82f1f8))
|
|
19
|
+
|
|
20
|
+
# [3.1.0](https://github.com/neovici/cosmoz-treenode-navigator/compare/v3.0.8...v3.1.0) (2021-12-07)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* add button and icon slots ([d7ea96d](https://github.com/neovici/cosmoz-treenode-navigator/commit/d7ea96dc06bf01e3dc33cbf76fa523524d67ba2c))
|
|
26
|
+
|
|
1
27
|
## [3.0.8](https://github.com/neovici/cosmoz-treenode-navigator/compare/v3.0.7...v3.0.8) (2021-10-17)
|
|
2
28
|
|
|
3
29
|
|
package/cc-test-reporter
CHANGED
|
Binary file
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import '@polymer/paper-icon-button/paper-icon-button';
|
|
2
2
|
import '@polymer/paper-button/paper-button';
|
|
3
|
+
import '@polymer/iron-icons/iron-icons';
|
|
3
4
|
|
|
4
5
|
import { Debouncer } from '@polymer/polymer/lib/utils/debounce';
|
|
5
6
|
import { timeOut } from '@polymer/polymer/lib/utils/async';
|
|
@@ -12,6 +13,7 @@ import { Tree } from '@neovici/cosmoz-tree';
|
|
|
12
13
|
import { translatable } from '@neovici/cosmoz-i18next';
|
|
13
14
|
|
|
14
15
|
import './cosmoz-treenode-navigator';
|
|
16
|
+
import { getNode, getTreePathParts } from './helpers';
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
`cosmoz-treenode-navigator`
|
|
@@ -23,92 +25,144 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
|
|
|
23
25
|
/* eslint-disable-next-line max-lines-per-function */
|
|
24
26
|
static get template() {
|
|
25
27
|
return html`
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
<style>
|
|
29
|
+
.actions {
|
|
30
|
+
display: flex;
|
|
31
|
+
}
|
|
32
|
+
.open {
|
|
33
|
+
flex: auto;
|
|
34
|
+
}
|
|
35
|
+
.pathToNode {
|
|
36
|
+
max-width: 320px;
|
|
37
|
+
overflow: hidden;
|
|
38
|
+
text-overflow: ellipsis;
|
|
39
|
+
white-space: nowrap;
|
|
40
|
+
direction: rtl;
|
|
41
|
+
text-align: left;
|
|
42
|
+
}
|
|
43
|
+
/* Safari only css fix */
|
|
44
|
+
@media not all and (min-resolution: 0.001dpcm) {
|
|
45
|
+
@supports (-webkit-appearance: none) {
|
|
46
|
+
.pathToNode span {
|
|
47
|
+
display: inline-block;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
41
51
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
52
|
+
#chips {
|
|
53
|
+
display: flex;
|
|
54
|
+
flex-wrap: wrap;
|
|
55
|
+
max-width: 90%;
|
|
56
|
+
padding: 20px;
|
|
57
|
+
overflow-y: auto;
|
|
58
|
+
max-height: 30vh;
|
|
59
|
+
}
|
|
60
|
+
.chip {
|
|
61
|
+
border-radius: 500px;
|
|
62
|
+
background-color: #e0e0e0;
|
|
63
|
+
margin: 1px 4px 1px 0;
|
|
64
|
+
white-space: nowrap;
|
|
65
|
+
overflow: hidden;
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
}
|
|
69
|
+
.chip > span {
|
|
70
|
+
color: #424242;
|
|
71
|
+
margin-left: 10px;
|
|
72
|
+
font-size: 13px;
|
|
73
|
+
overflow: hidden;
|
|
74
|
+
text-overflow: ellipsis;
|
|
75
|
+
}
|
|
76
|
+
.chip iron-icon {
|
|
77
|
+
margin: 2px 4px;
|
|
78
|
+
color: #cdcdcd;
|
|
79
|
+
background-color: #a6a6a6;
|
|
80
|
+
border-radius: 500px;
|
|
81
|
+
cursor: pointer;
|
|
82
|
+
min-width: 16px;
|
|
83
|
+
width: 16px;
|
|
84
|
+
min-height: 16px;
|
|
85
|
+
height: 16px;
|
|
86
|
+
}
|
|
75
87
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
#dialogTree {
|
|
89
|
+
min-width: 250px !important;
|
|
90
|
+
width: 450px;
|
|
91
|
+
}
|
|
92
|
+
</style>
|
|
93
|
+
<div class="actions">
|
|
94
|
+
<paper-button
|
|
95
|
+
part="button"
|
|
96
|
+
class="open"
|
|
97
|
+
raised
|
|
98
|
+
on-click="openDialogTree"
|
|
99
|
+
title="[[ buttonText ]]"
|
|
100
|
+
>
|
|
101
|
+
<div class="pathToNode">‎<span>[[ buttonText ]]</span></div>
|
|
102
|
+
</paper-button>
|
|
103
|
+
<paper-icon-button
|
|
104
|
+
part="clear"
|
|
105
|
+
icon="clear"
|
|
106
|
+
on-click="reset"
|
|
107
|
+
hidden$="[[ !_enableReset(nodePath, noReset) ]]"
|
|
108
|
+
></paper-icon-button>
|
|
92
109
|
</div>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
<
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
<paper-button dialog-dismiss>[[ _('Cancel', t) ]]</paper-button>
|
|
110
|
+
<template
|
|
111
|
+
is="dom-if"
|
|
112
|
+
if="[[ _showSelectedNodes(multiSelection, selectedNodes.length) ]]"
|
|
113
|
+
>
|
|
114
|
+
<div id="chips" class="row">
|
|
115
|
+
<template is="dom-repeat" items="[[ selectedNodes ]]">
|
|
116
|
+
<div class="chip">
|
|
117
|
+
<span>[[ _getChipText(item, tree) ]]</span
|
|
118
|
+
><iron-icon
|
|
119
|
+
icon="clear"
|
|
120
|
+
on-click="_clearItemSelection"
|
|
121
|
+
></iron-icon>
|
|
122
|
+
</div>
|
|
123
|
+
</template>
|
|
108
124
|
</div>
|
|
109
125
|
</template>
|
|
110
|
-
|
|
111
|
-
|
|
126
|
+
|
|
127
|
+
<cosmoz-dialog
|
|
128
|
+
id="dialogTree"
|
|
129
|
+
class="treeDialog"
|
|
130
|
+
on-iron-overlay-opened="focusSearch"
|
|
131
|
+
modal
|
|
132
|
+
prerender
|
|
133
|
+
>
|
|
134
|
+
<template>
|
|
135
|
+
<h2>[[ dialogText ]]</h2>
|
|
136
|
+
<cosmoz-treenode-navigator
|
|
137
|
+
id="treeNavigator"
|
|
138
|
+
class="no-padding"
|
|
139
|
+
tree="[[ tree ]]"
|
|
140
|
+
selected-node="{{ selectedNode }}"
|
|
141
|
+
on-data-plane-changed="refit"
|
|
142
|
+
highlighted-node-path="{{ highlightedNodePath }}"
|
|
143
|
+
search-placeholder="[[ searchPlaceholder ]]"
|
|
144
|
+
search-global-placeholder="[[ searchGlobalPlaceholder ]]"
|
|
145
|
+
search-min-length="[[ searchMinLength ]]"
|
|
146
|
+
node-path="{{ nodePath }}"
|
|
147
|
+
nodes-on-node-path="{{ nodesOnNodePath }}"
|
|
148
|
+
on-node-dblclicked="_selectNodeAndCloseDialog"
|
|
149
|
+
on-select-node="selectNode"
|
|
150
|
+
>
|
|
151
|
+
<slot></slot>
|
|
152
|
+
</cosmoz-treenode-navigator>
|
|
153
|
+
<div class="buttons">
|
|
154
|
+
<paper-button
|
|
155
|
+
disabled="[[!highlightedNodePath]]"
|
|
156
|
+
dialog-confirm
|
|
157
|
+
autofocus
|
|
158
|
+
on-click="selectNode"
|
|
159
|
+
>[[ _('Select', t) ]]</paper-button
|
|
160
|
+
>
|
|
161
|
+
<paper-button dialog-dismiss>[[ _('Cancel', t) ]]</paper-button>
|
|
162
|
+
</div>
|
|
163
|
+
</template>
|
|
164
|
+
</cosmoz-dialog>
|
|
165
|
+
`;
|
|
112
166
|
}
|
|
113
167
|
|
|
114
168
|
static get is() {
|
|
@@ -118,20 +172,19 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
|
|
|
118
172
|
/* eslint-disable-next-line max-lines-per-function */
|
|
119
173
|
static get properties() {
|
|
120
174
|
return {
|
|
121
|
-
|
|
122
175
|
multiSelection: {
|
|
123
176
|
type: Boolean,
|
|
124
177
|
value: false
|
|
125
178
|
},
|
|
126
179
|
/*
|
|
127
|
-
|
|
128
|
-
|
|
180
|
+
* The main node structure
|
|
181
|
+
*/
|
|
129
182
|
tree: {
|
|
130
183
|
type: Tree
|
|
131
184
|
},
|
|
132
185
|
/*
|
|
133
|
-
|
|
134
|
-
|
|
186
|
+
* Currently selected node object
|
|
187
|
+
*/
|
|
135
188
|
selectedNode: {
|
|
136
189
|
type: Object,
|
|
137
190
|
value() {
|
|
@@ -155,14 +208,14 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
|
|
|
155
208
|
value: false
|
|
156
209
|
},
|
|
157
210
|
/*
|
|
158
|
-
|
|
159
|
-
|
|
211
|
+
* Placeholder for the search field
|
|
212
|
+
*/
|
|
160
213
|
searchPlaceholder: {
|
|
161
214
|
type: String
|
|
162
215
|
},
|
|
163
216
|
/*
|
|
164
|
-
|
|
165
|
-
|
|
217
|
+
* Placeholder for button text
|
|
218
|
+
*/
|
|
166
219
|
buttonTextPlaceholder: {
|
|
167
220
|
type: String,
|
|
168
221
|
computed: 'getButtonTextPlaceholder(multiSelection)'
|
|
@@ -174,42 +227,44 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
|
|
|
174
227
|
},
|
|
175
228
|
|
|
176
229
|
/*
|
|
177
|
-
|
|
178
|
-
|
|
230
|
+
* The path of the selected node
|
|
231
|
+
*/
|
|
179
232
|
nodePath: {
|
|
180
233
|
type: String,
|
|
181
234
|
notify: true
|
|
182
235
|
},
|
|
183
236
|
/*
|
|
184
|
-
|
|
185
|
-
|
|
237
|
+
* The nodes on the path of the selected node
|
|
238
|
+
*/
|
|
186
239
|
nodesOnNodePath: {
|
|
187
240
|
type: Array
|
|
188
241
|
},
|
|
189
242
|
/*
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
243
|
+
* Text displayed when local search has finished
|
|
244
|
+
* to suggest a search on the entire tree
|
|
245
|
+
*/
|
|
193
246
|
searchGlobalPlaceholder: {
|
|
194
|
-
type: String
|
|
247
|
+
type: String,
|
|
248
|
+
value: 'Click to search again but globally.'
|
|
195
249
|
},
|
|
196
250
|
/*
|
|
197
|
-
|
|
198
|
-
|
|
251
|
+
* Settable text for dialog title.
|
|
252
|
+
*/
|
|
199
253
|
dialogText: {
|
|
200
254
|
type: String,
|
|
201
255
|
value: 'Search or navigate to chosen destination'
|
|
202
256
|
},
|
|
203
257
|
/*
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
258
|
+
* Minimum length before an search
|
|
259
|
+
* starts.
|
|
260
|
+
*/
|
|
207
261
|
searchMinLength: {
|
|
208
|
-
type: Number
|
|
262
|
+
type: Number,
|
|
263
|
+
value: 1
|
|
209
264
|
},
|
|
210
265
|
/*
|
|
211
|
-
|
|
212
|
-
|
|
266
|
+
* Path string of highlighted (focused) node
|
|
267
|
+
*/
|
|
213
268
|
highlightedNodePath: {
|
|
214
269
|
type: String
|
|
215
270
|
}
|
|
@@ -228,6 +283,11 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
|
|
|
228
283
|
this.splice('selectedNodes', selectedIndex, 1);
|
|
229
284
|
// ... so we must prevent further propagation of this event, because its source is now invalid.
|
|
230
285
|
// (This has caused troubles in app-drawer-layout click event handler).
|
|
286
|
+
|
|
287
|
+
if (!this.selectedNodes.length) {
|
|
288
|
+
this.reset();
|
|
289
|
+
}
|
|
290
|
+
|
|
231
291
|
event.preventDefault();
|
|
232
292
|
event.stopPropagation();
|
|
233
293
|
}
|
|
@@ -237,7 +297,9 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
|
|
|
237
297
|
* @returns {string} Text label.
|
|
238
298
|
*/
|
|
239
299
|
getButtonTextPlaceholder(multiSelection) {
|
|
240
|
-
return multiSelection
|
|
300
|
+
return multiSelection
|
|
301
|
+
? this._('Select a node')
|
|
302
|
+
: this._('No selection made');
|
|
241
303
|
}
|
|
242
304
|
/**
|
|
243
305
|
* Whether the reset button should be enabled or not.
|
|
@@ -261,7 +323,10 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
|
|
|
261
323
|
if (!Array.isArray(pathParts) || pathParts.length === 0) {
|
|
262
324
|
return placeholder;
|
|
263
325
|
}
|
|
264
|
-
return pathParts
|
|
326
|
+
return pathParts
|
|
327
|
+
.filter(n => n)
|
|
328
|
+
.map(part => part[this.tree.searchProperty])
|
|
329
|
+
.join(' / ');
|
|
265
330
|
}
|
|
266
331
|
/**
|
|
267
332
|
* Get text from a node to set on a node chip.
|
|
@@ -291,7 +356,10 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
|
|
|
291
356
|
*/
|
|
292
357
|
reset() {
|
|
293
358
|
this.nodePath = '';
|
|
359
|
+
this.selectedNode = {};
|
|
360
|
+
this.nodesOnNodePath = [];
|
|
294
361
|
this.selectedNodes = [];
|
|
362
|
+
this.highlightedNodePath = '';
|
|
295
363
|
}
|
|
296
364
|
/**
|
|
297
365
|
* Select the node in the treenode navigator.
|
|
@@ -299,9 +367,25 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
|
|
|
299
367
|
*/
|
|
300
368
|
selectNode() {
|
|
301
369
|
// nodePath selects the node, without it no selectedNode
|
|
302
|
-
|
|
370
|
+
|
|
371
|
+
this.selectedNode = getNode(
|
|
372
|
+
this.highlightedNodePath || this.nodePath,
|
|
373
|
+
this.tree
|
|
374
|
+
);
|
|
375
|
+
if (this.highlightedNodePath) {
|
|
376
|
+
this.nodePath = this.highlightedNodePath;
|
|
377
|
+
}
|
|
378
|
+
this.nodesOnNodePath = getTreePathParts(
|
|
379
|
+
this.highlightedNodePath || this.nodePath,
|
|
380
|
+
this.tree
|
|
381
|
+
);
|
|
382
|
+
|
|
303
383
|
if (this.multiSelection) {
|
|
304
|
-
if (
|
|
384
|
+
if (
|
|
385
|
+
!this.selectedNodes.some(
|
|
386
|
+
node => node.pathLocator === this.highlightedNodePath
|
|
387
|
+
)
|
|
388
|
+
) {
|
|
305
389
|
this.push('selectedNodes', this.selectedNode);
|
|
306
390
|
}
|
|
307
391
|
this.nodePath = '';
|
|
@@ -323,7 +407,7 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
|
|
|
323
407
|
* @returns {boolean} Whether the selected nodes container should be visible or not.
|
|
324
408
|
*/
|
|
325
409
|
_showSelectedNodes(multiSelection, selectedNodesLength) {
|
|
326
|
-
return
|
|
410
|
+
return multiSelection && selectedNodesLength > 0;
|
|
327
411
|
}
|
|
328
412
|
/**
|
|
329
413
|
* Callback event handler to refit the treenode navigator dialog when
|
|
@@ -331,11 +415,13 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
|
|
|
331
415
|
* @returns {void}
|
|
332
416
|
*/
|
|
333
417
|
refit() {
|
|
334
|
-
this._debouncer = Debouncer.debounce(
|
|
418
|
+
this._debouncer = Debouncer.debounce(
|
|
419
|
+
this._debouncer,
|
|
335
420
|
timeOut.after(50), // 5 was enough during test
|
|
336
421
|
() => {
|
|
337
422
|
this.$.dialogTree.fit();
|
|
338
|
-
}
|
|
423
|
+
}
|
|
424
|
+
);
|
|
339
425
|
}
|
|
340
426
|
}
|
|
341
427
|
customElements.define(CosmozTreenodeButtonView.is, CosmozTreenodeButtonView);
|