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