@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 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
- <style>
27
- .actions { display: flex; }
28
- .open { flex: auto; }
29
- .pathToNode {
30
- max-width: 320px;
31
- overflow: hidden;
32
- text-overflow: ellipsis;
33
- white-space: nowrap;
34
- direction: rtl;
35
- text-align: left;
36
- }
37
- /* Safari only css fix */
38
- @media not all and (min-resolution:.001dpcm) { @supports (-webkit-appearance:none) {
39
- .pathToNode span { display: inline-block;}
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
- #chips {
43
- display: flex;
44
- flex-wrap: wrap;
45
- max-width: 90%;
46
- padding: 20px;
47
- }
48
- .chip {
49
- border-radius: 500px;
50
- background-color: #e0e0e0;
51
- margin: 1px 4px 1px 0;
52
- white-space: nowrap;
53
- overflow: hidden;
54
- display: flex;
55
- align-items: center;
56
- }
57
- .chip > span {
58
- color: #424242;
59
- margin-left: 10px;
60
- font-size: 13px;
61
- overflow: hidden;
62
- text-overflow: ellipsis;
63
- }
64
- .chip iron-icon {
65
- margin: 2px 4px;
66
- color: #cdcdcd;
67
- background-color: #a6a6a6;
68
- border-radius: 500px;
69
- cursor: pointer;
70
- min-width: 16px;
71
- width: 16px;
72
- min-height: 16px;
73
- height: 16px;
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
- #dialogTree {
77
- min-width: 250px !important;
78
- width: 450px;
79
- }
80
- </style>
81
- <div class="actions">
82
- <paper-button class="open" raised on-click="openDialogTree" title="[[ buttonText ]]">
83
- <div class="pathToNode">&lrm;<span>[[ buttonText ]]</span></div>
84
- </paper-button>
85
- <paper-icon-button icon="clear" on-click="reset" hidden$="[[ !_enableReset(nodePath, noReset) ]]"></paper-icon-button>
86
- </div>
87
- <template is="dom-if" if="[[ _showSelectedNodes(multiSelection, selectedNodes.length) ]]">
88
- <div id="chips" class="row">
89
- <template is="dom-repeat" items="[[ selectedNodes ]]">
90
- <div class="chip"><span>[[ _getChipText(item, tree) ]]</span><iron-icon icon="clear" on-click="_clearItemSelection"></iron-icon></div>
91
- </template>
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">&lrm;<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
- </template>
94
-
95
- <cosmoz-dialog id="dialogTree" class="treeDialog" on-iron-overlay-opened="focusSearch" modal prerender>
96
- <template>
97
- <h2>[[ dialogText ]]</h2>
98
- <cosmoz-treenode-navigator id="treeNavigator" class="no-padding" tree="[[ tree ]]" selected-node="{{ selectedNode }}"
99
- on-data-plane-changed="refit" highlighted-node-path="{{ highlightedNodePath }}"
100
- search-placeholder="[[ searchPlaceholder ]]" search-global-placeholder="[[ searchGlobalPlaceholder ]]"
101
- search-min-length="[[ searchMinLength ]]" node-path="{{ nodePath }}" nodes-on-node-path="{{ nodesOnNodePath }}"
102
- on-node-dblclicked="_selectNodeAndCloseDialog">
103
- <slot></slot>
104
- </cosmoz-treenode-navigator>
105
- <div class="buttons">
106
- <paper-button disabled="[[!highlightedNodePath]]" dialog-confirm autofocus on-click="selectNode">[[ _('Select', t) ]]</paper-button>
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
- </cosmoz-dialog>
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
- * The main node structure
128
- */
180
+ * The main node structure
181
+ */
129
182
  tree: {
130
183
  type: Tree
131
184
  },
132
185
  /*
133
- * Currently selected node object
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
- * Placeholder for the search field
159
- */
211
+ * Placeholder for the search field
212
+ */
160
213
  searchPlaceholder: {
161
214
  type: String
162
215
  },
163
216
  /*
164
- * Placeholder for button text
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
- * The path of the selected node
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
- * The nodes on the path of the selected node
185
- */
237
+ * The nodes on the path of the selected node
238
+ */
186
239
  nodesOnNodePath: {
187
240
  type: Array
188
241
  },
189
242
  /*
190
- * Text displayed when local search has finished
191
- * to suggest a search on the entire tree
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
- * Settable text for dialog title.
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
- * Minimum length before an search
205
- * starts.
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
- * Path string of highlighted (focused) node
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 ? this._('Select a node') : this._('No selection made');
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.filter(n => n).map(part => part[this.tree.searchProperty]).join(' / ');
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
- this.nodePath = this.highlightedNodePath;
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 (!this.selectedNodes.some(node => node.pathLocator === this.highlightedNodePath)) {
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 multiSelection && selectedNodesLength > 0;
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(this._debouncer,
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);