kempo-ui 0.0.7 → 0.0.8

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.
Files changed (58) hide show
  1. package/dist/src/components/Icon.js +1 -1
  2. package/dist/src/components/ShadowComponent.js +1 -1
  3. package/dist/src/components/Tree.js +37 -0
  4. package/docs/components/accordion.html +3 -9
  5. package/docs/components/card.html +3 -9
  6. package/docs/components/collapsible.html +3 -9
  7. package/docs/components/content-slider.html +3 -9
  8. package/docs/components/dialog.html +4 -151
  9. package/docs/components/focus-capture.html +3 -7
  10. package/docs/components/hybrid-component.html +3 -7
  11. package/docs/components/icon.html +1 -6
  12. package/docs/components/import.html +1 -6
  13. package/docs/components/init.js +7 -0
  14. package/docs/components/light-component.html +3 -7
  15. package/docs/components/persistant-collapsible.html +1 -8
  16. package/docs/components/photo-viewer.html +1 -8
  17. package/docs/components/resize.html +3 -9
  18. package/docs/components/shadow-component.html +3 -7
  19. package/docs/components/show-more.html +3 -9
  20. package/docs/components/side-menu.html +1 -6
  21. package/docs/components/sortable.html +3 -7
  22. package/docs/components/split.html +3 -7
  23. package/docs/components/table.html +3 -7
  24. package/docs/components/tableControls.html +3 -7
  25. package/docs/components/tableCustomFields.html +3 -7
  26. package/docs/components/tableFetchRecords.html +3 -7
  27. package/docs/components/tableFieldSortHide.html +3 -7
  28. package/docs/components/tablePagination.html +3 -7
  29. package/docs/components/tableRecordEditing.html +3 -7
  30. package/docs/components/tableRecordFiltering.html +3 -7
  31. package/docs/components/tableRecordHiding.html +3 -7
  32. package/docs/components/tableRecordSearching.html +3 -7
  33. package/docs/components/tableRecordSelection.html +3 -7
  34. package/docs/components/tableRowControls.html +3 -7
  35. package/docs/components/tableSorting.html +3 -7
  36. package/docs/components/tabs.html +3 -9
  37. package/docs/components/tags.html +3 -9
  38. package/docs/components/theme-switcher.html +3 -9
  39. package/docs/components/timestamp.html +3 -9
  40. package/docs/components/toast.html +4 -272
  41. package/docs/components/toggle.html +3 -9
  42. package/docs/components/tree.html +108 -21
  43. package/docs/index.html +10 -6
  44. package/docs/init.js +7 -0
  45. package/docs/src/components/Icon.js +1 -1
  46. package/docs/src/components/ShadowComponent.js +1 -1
  47. package/docs/src/components/Tree.js +37 -0
  48. package/docs/utils/debounce.html +1 -6
  49. package/docs/utils/drag.html +1 -6
  50. package/docs/utils/formatTimestamp.html +1 -6
  51. package/docs/utils/init.js +7 -0
  52. package/docs/utils/propConverters.html +1 -6
  53. package/docs/utils/toTitleCase.html +1 -6
  54. package/docs/utils/watchWindowSize.html +1 -6
  55. package/package.json +1 -1
  56. package/scripts/build.js +12 -2
  57. package/scripts/fix-docs-paths.js +62 -0
  58. package/src/components/Tree.js +64 -72
@@ -1,17 +1,20 @@
1
1
  import ShadowComponent from './ShadowComponent.js';
2
- import { html, css } from '../lit-all.min.js';
2
+ import { html, css, render } from '../lit-all.min.js';
3
3
  import { boolExists } from '../utils/propConverters.js';
4
+ import './Icon.js';
4
5
 
5
6
  export default class Tree extends ShadowComponent {
6
7
  /* Properties */
7
8
  static properties = {
8
9
  data: { type: Object },
10
+ depth: { type: Number, reflect: true },
9
11
  editable: { type: Boolean, converter: boolExists, attribute: 'editable', reflect: true }
10
12
  }
11
13
 
12
14
  constructor(){
13
15
  super();
14
16
  this.data = null;
17
+ this.depth = 0;
15
18
  this.editable = false;
16
19
  }
17
20
 
@@ -27,14 +30,14 @@ export default class Tree extends ShadowComponent {
27
30
  ${(Array.isArray(this.data)
28
31
  ? this.data.map((v, i) => [i, v])
29
32
  : Object.entries(this.data)
30
- ).map(([key, value]) => Tree.renderValue(value, key))}
33
+ ).map(([key, value]) => Tree.renderValue(value, key, 1, this.depth))}
31
34
  </div>
32
35
  `;
33
36
  }
34
37
 
35
38
  return html`
36
39
  <div class="tree-root">
37
- ${Tree.renderValue(this.data)}
40
+ ${Tree.renderValue(this.data, null, 0, this.depth)}
38
41
  </div>
39
42
  `;
40
43
  }
@@ -47,24 +50,40 @@ export default class Tree extends ShadowComponent {
47
50
  };
48
51
 
49
52
  /* Static Methods */
50
- static renderValue(value, key = null){
53
+ static renderValue(value, key = null, currentDepth = 0, maxDepth = 0){
51
54
  const LeafClass = Tree.leafs.find(leaf => leaf.detect(value));
52
55
 
53
56
  if(LeafClass){
54
- const leaf = document.createElement(LeafClass.tagName);
55
- leaf.value = value;
56
- leaf.key = key;
57
- return leaf;
57
+ const wrapper = document.createElement('span');
58
+ wrapper.className = 'd-b';
59
+ if(key !== null){
60
+ const keyLabel = document.createElement('span');
61
+ keyLabel.className = typeof key === 'number' ? 'tc-muted' : '';
62
+ keyLabel.textContent = `${key}: `;
63
+ wrapper.appendChild(keyLabel);
64
+ }
65
+ const leaf = new LeafClass(value);
66
+ const rendered = leaf.render();
67
+ if(rendered instanceof Node){
68
+ wrapper.appendChild(rendered);
69
+ } else {
70
+ const span = document.createElement('span');
71
+ render(rendered, span);
72
+ wrapper.appendChild(span);
73
+ }
74
+ return wrapper;
58
75
  }
59
76
 
60
77
  if(typeof value === 'object' && value !== null){
61
- const branch = document.createElement('k-tree-branch');
78
+ const branch = new TreeBranch();
62
79
  branch.value = value;
63
80
  branch.key = key;
81
+ branch.currentDepth = currentDepth;
82
+ branch.maxDepth = maxDepth;
64
83
  return branch;
65
84
  }
66
85
 
67
- return html`<span class="primitive">${key !== null ? `${key}: ` : ''}${value}</span>`;
86
+ return html`<span class="d-b primitive">${key !== null ? html`<span class="${typeof key === 'number' ? 'tc-muted' : ''}">${key}: </span>` : ''}${value}</span>`;
68
87
  }
69
88
  }
70
89
 
@@ -75,6 +94,8 @@ export class TreeBranch extends ShadowComponent {
75
94
  static properties = {
76
95
  value: { type: Object },
77
96
  key: { type: String },
97
+ currentDepth: { type: Number },
98
+ maxDepth: { type: Number },
78
99
  opened: { type: Boolean, converter: boolExists, reflect: true }
79
100
  };
80
101
 
@@ -82,9 +103,19 @@ export class TreeBranch extends ShadowComponent {
82
103
  super();
83
104
  this.value = null;
84
105
  this.key = null;
106
+ this.currentDepth = 0;
107
+ this.maxDepth = 0;
85
108
  this.opened = false;
86
109
  }
87
110
 
111
+ /* Lifecycle */
112
+ connectedCallback(){
113
+ super.connectedCallback();
114
+ if(this.currentDepth <= this.maxDepth){
115
+ this.opened = true;
116
+ }
117
+ }
118
+
88
119
  /* Members */
89
120
  get tree(){
90
121
  return this.closest('k-tree');
@@ -101,17 +132,17 @@ export class TreeBranch extends ShadowComponent {
101
132
  const type = Array.isArray(this.value) ? 'Array' : 'Object';
102
133
 
103
134
  return html`
104
- <div class="branch">
135
+ <div>
105
136
  <div class="branch-label" @click=${this.toggle}>
106
- <span class="toggle">${this.opened ? '' : ''}</span>
137
+ <k-icon name="chevron-right" class="toggle-icon ${this.opened ? 'opened' : ''}"></k-icon>
107
138
  ${label}${type}
108
139
  </div>
109
140
  ${this.opened ? html`
110
- <div class="branch-content">
141
+ <div class="pl">
111
142
  ${this.value ? (Array.isArray(this.value)
112
143
  ? this.value.map((v, i) => [i, v])
113
144
  : Object.entries(this.value)
114
- ).map(([key, value]) => Tree.renderValue(value, key)) : ''}
145
+ ).map(([key, value]) => Tree.renderValue(value, key, this.currentDepth + 1, this.maxDepth)) : ''}
115
146
  </div>
116
147
  ` : ''}
117
148
  </div>
@@ -124,46 +155,29 @@ export class TreeBranch extends ShadowComponent {
124
155
  }
125
156
  .branch-label{
126
157
  cursor: pointer;
127
- padding: 2px 4px;
128
158
  }
129
159
  .branch-label:hover{
130
160
  background-color: var(--c_bg__alt, #f5f5f5);
131
161
  }
132
- .toggle{
133
- display: inline-block;
134
- width: 1rem;
162
+ .toggle-icon{
163
+ transition: transform var(--animation_ms, 200ms);
135
164
  }
136
- .branch-content{
137
- margin-left: 1.5rem;
165
+ .toggle-icon.opened{
166
+ transform: rotate(90deg);
138
167
  }
139
168
  `;
140
169
  }
141
170
 
142
171
  window.customElements.define('k-tree-branch', TreeBranch);
143
- export class TreeLeaf extends ShadowComponent {
144
- /* Properties */
145
- static properties = {
146
- value: {},
147
- key: { type: String },
148
- opened: { reflect: true, type: Boolean, converter: boolExists }
149
- };
150
172
 
151
- constructor(){
152
- super();
153
- this.value = null;
154
- this.key = null;
155
- this.opened = false;
156
- }
157
-
158
- /* Members */
159
- get tree(){
160
- return this.closest('k-tree');
173
+ export class TreeLeaf {
174
+ constructor(value = null){
175
+ this.value = value;
161
176
  }
162
177
 
163
178
  /* Rendering */
164
179
  render(){
165
- const label = this.key !== null ? html`<span class="tc-muted">${this.key}: </span>` : '';
166
- return html`${label}<slot></slot>`;
180
+ return html`${this.value}`;
167
181
  }
168
182
 
169
183
  /* Static Methods */
@@ -172,76 +186,54 @@ export class TreeLeaf extends ShadowComponent {
172
186
  };
173
187
  }
174
188
 
175
- window.customElements.define('k-tree-leaf', TreeLeaf);
176
-
177
189
  export class StringLeaf extends TreeLeaf {
178
190
  /* Rendering */
179
191
  render(){
180
- const label = this.key !== null ? html`<span class="tc-muted">${this.key}: </span>` : '';
181
- return html`<span class="d-b">${label}<span class="tc-success">"${this.value}"</span></span>`;
192
+ return html`<span class="tc-success">"${this.value}"</span>`;
182
193
  }
183
194
 
195
+ /* Static Methods */
184
196
  static detect = value => typeof value === 'string';
185
-
186
- static tagName = 'k-tree-string-leaf';
187
197
  }
188
198
 
189
- window.customElements.define(StringLeaf.tagName, StringLeaf);
190
-
191
199
  export class NumberLeaf extends TreeLeaf {
192
200
  /* Rendering */
193
201
  render(){
194
- const label = this.key !== null ? html`<span class="tc-muted">${this.key}: </span>` : '';
195
- return html`<span class="d-b">${label}<span class="tc-primary">${this.value}</span></span>`;
202
+ return html`<span class="tc-primary">${this.value}</span>`;
196
203
  }
197
204
 
205
+ /* Static Methods */
198
206
  static detect = value => typeof value === 'number';
199
-
200
- static tagName = 'k-tree-number-leaf';
201
207
  }
202
208
 
203
- window.customElements.define(NumberLeaf.tagName, NumberLeaf);
204
-
205
209
  export class BooleanLeaf extends TreeLeaf {
206
210
  /* Rendering */
207
211
  render(){
208
- const label = this.key !== null ? html`<span class="tc-muted">${this.key}: </span>` : '';
209
- return html`<span class="d-b">${label}<span class="${this.value ? 'tc-success' : 'tc-danger'}">${this.value}</span></span>`;
212
+ return html`<span class="${this.value ? 'tc-success' : 'tc-danger'}">${this.value}</span>`;
210
213
  }
211
214
 
215
+ /* Static Methods */
212
216
  static detect = value => typeof value === 'boolean';
213
-
214
- static tagName = 'k-tree-boolean-leaf';
215
217
  }
216
218
 
217
- window.customElements.define(BooleanLeaf.tagName, BooleanLeaf);
218
-
219
219
  export class NullLeaf extends TreeLeaf {
220
220
  /* Rendering */
221
221
  render(){
222
- const label = this.key !== null ? html`<span class="tc-muted">${this.key}: </span>` : '';
223
- return html`<span class="d-b">${label}<span class="tc-muted">null</span></span>`;
222
+ return html`<span class="tc-muted">null</span>`;
224
223
  }
225
-
224
+
225
+ /* Static Methods */
226
226
  static detect = value => value === null;
227
-
228
- static tagName = 'k-tree-null-leaf';
229
227
  }
230
228
 
231
- window.customElements.define(NullLeaf.tagName, NullLeaf);
232
-
233
229
  export class UndefinedLeaf extends TreeLeaf {
234
230
  /* Rendering */
235
231
  render(){
236
- const label = this.key !== null ? html`<span class="tc-muted">${this.key}: </span>` : '';
237
- return html`<span class="d-b">${label}<span class="tc-muted">undefined</span></span>`;
232
+ return html`<span class="tc-muted">undefined</span>`;
238
233
  }
239
234
 
235
+ /* Static Methods */
240
236
  static detect = value => value === undefined;
241
-
242
- static tagName = 'k-tree-undefined-leaf';
243
237
  }
244
238
 
245
- window.customElements.define(UndefinedLeaf.tagName, UndefinedLeaf);
246
-
247
239
  Tree.addLeaf(UndefinedLeaf, NullLeaf, BooleanLeaf, NumberLeaf, StringLeaf);