@uwdata/mosaic-inputs 0.1.0 → 0.2.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/dist/mosaic-inputs.js +1602 -954
- package/dist/mosaic-inputs.min.js +4 -4
- package/package.json +4 -4
- package/src/Menu.js +12 -5
- package/src/Search.js +4 -0
- package/src/Slider.js +3 -1
- package/src/Table.js +38 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uwdata/mosaic-inputs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Mosaic input components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"inputs",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"prepublishOnly": "npm run test && npm run lint && npm run build"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@uwdata/mosaic-core": "^0.
|
|
29
|
-
"@uwdata/mosaic-sql": "^0.
|
|
28
|
+
"@uwdata/mosaic-core": "^0.2.0",
|
|
29
|
+
"@uwdata/mosaic-sql": "^0.2.0",
|
|
30
30
|
"isoformat": "^0.2.1"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "e53cd914c807f99aabe78dcbe618dd9543e2f438"
|
|
33
33
|
}
|
package/src/Menu.js
CHANGED
|
@@ -36,13 +36,12 @@ export class Menu extends MosaicClient {
|
|
|
36
36
|
this.update();
|
|
37
37
|
}
|
|
38
38
|
value = value ?? this.selection?.value ?? this.data?.[0]?.value;
|
|
39
|
-
this.select.value = value;
|
|
40
39
|
if (this.selection?.value === undefined) this.publish(value);
|
|
41
40
|
this.element.appendChild(this.select);
|
|
42
41
|
|
|
43
42
|
if (this.selection) {
|
|
44
43
|
this.select.addEventListener('input', () => {
|
|
45
|
-
this.publish(this.selectedValue()
|
|
44
|
+
this.publish(this.selectedValue() ?? null);
|
|
46
45
|
});
|
|
47
46
|
if (!isSelection(this.selection)) {
|
|
48
47
|
this.selection.addEventListener('value', value => {
|
|
@@ -59,11 +58,19 @@ export class Menu extends MosaicClient {
|
|
|
59
58
|
const index = this.select.selectedIndex;
|
|
60
59
|
return this.data[index].value;
|
|
61
60
|
} else {
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const index = this.data?.findIndex(opt => opt.value === value);
|
|
62
|
+
if (index >= 0) {
|
|
63
|
+
this.select.selectedIndex = index;
|
|
64
|
+
} else {
|
|
65
|
+
this.select.value = String(value);
|
|
66
|
+
}
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
69
|
|
|
70
|
+
reset() {
|
|
71
|
+
this.select.selectedIndex = this.from ? 0 : -1;
|
|
72
|
+
}
|
|
73
|
+
|
|
67
74
|
publish(value) {
|
|
68
75
|
const { selection, column } = this;
|
|
69
76
|
if (isSelection(selection)) {
|
|
@@ -104,7 +111,7 @@ export class Menu extends MosaicClient {
|
|
|
104
111
|
this.select.appendChild(opt);
|
|
105
112
|
}
|
|
106
113
|
if (this.selection) {
|
|
107
|
-
this.
|
|
114
|
+
this.selectedValue(this.selection?.value ?? '');
|
|
108
115
|
}
|
|
109
116
|
return this;
|
|
110
117
|
}
|
package/src/Search.js
CHANGED
package/src/Slider.js
CHANGED
|
@@ -13,7 +13,8 @@ export class Slider extends MosaicClient {
|
|
|
13
13
|
from,
|
|
14
14
|
column,
|
|
15
15
|
label = column,
|
|
16
|
-
value = as?.value
|
|
16
|
+
value = as?.value,
|
|
17
|
+
width
|
|
17
18
|
} = {}) {
|
|
18
19
|
super(filterBy);
|
|
19
20
|
this.id = 'slider_' + (++_id);
|
|
@@ -38,6 +39,7 @@ export class Slider extends MosaicClient {
|
|
|
38
39
|
this.slider = document.createElement('input');
|
|
39
40
|
this.slider.setAttribute('id', this.id);
|
|
40
41
|
this.slider.setAttribute('type', 'range');
|
|
42
|
+
if (width != null) this.slider.style.width = `${+width}px`;
|
|
41
43
|
if (min != null) this.slider.setAttribute('min', min);
|
|
42
44
|
if (max != null) this.slider.setAttribute('max', max);
|
|
43
45
|
if (step != null) this.slider.setAttribute('step', step);
|
package/src/Table.js
CHANGED
|
@@ -9,16 +9,21 @@ export class Table extends MosaicClient {
|
|
|
9
9
|
filterBy,
|
|
10
10
|
from,
|
|
11
11
|
columns = ['*'],
|
|
12
|
+
align = {},
|
|
12
13
|
format,
|
|
13
|
-
rowBatch = 100,
|
|
14
14
|
width,
|
|
15
|
-
|
|
15
|
+
maxWidth,
|
|
16
|
+
height = 500,
|
|
17
|
+
rowBatch = 100,
|
|
16
18
|
} = {}) {
|
|
17
19
|
super(filterBy);
|
|
18
20
|
this.id = `table-${++_id}`;
|
|
19
21
|
this.from = from;
|
|
20
22
|
this.columns = columns;
|
|
21
23
|
this.format = format;
|
|
24
|
+
this.align = align;
|
|
25
|
+
this.widths = typeof width === 'object' ? width : {};
|
|
26
|
+
|
|
22
27
|
this.offset = 0;
|
|
23
28
|
this.limit = +rowBatch;
|
|
24
29
|
this.pending = false;
|
|
@@ -30,9 +35,8 @@ export class Table extends MosaicClient {
|
|
|
30
35
|
this.element = document.createElement('div');
|
|
31
36
|
this.element.setAttribute('id', this.id);
|
|
32
37
|
this.element.value = this;
|
|
33
|
-
if (width) {
|
|
34
|
-
|
|
35
|
-
}
|
|
38
|
+
if (typeof width === 'number') this.element.style.width = `${width}px`;
|
|
39
|
+
if (maxWidth) this.element.style.maxWidth = `${maxWidth}px`;
|
|
36
40
|
this.element.style.maxHeight = `${height}px`;
|
|
37
41
|
this.element.style.overflow = 'auto';
|
|
38
42
|
|
|
@@ -70,13 +74,13 @@ export class Table extends MosaicClient {
|
|
|
70
74
|
return this.columns.map(name => column(this.from, name));
|
|
71
75
|
}
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
this.
|
|
77
|
+
fieldInfo(info) {
|
|
78
|
+
this.schema = info;
|
|
75
79
|
|
|
76
80
|
const thead = this.head;
|
|
77
81
|
thead.innerHTML = '';
|
|
78
82
|
const tr = document.createElement('tr');
|
|
79
|
-
for (const { column } of
|
|
83
|
+
for (const { column } of info) {
|
|
80
84
|
const th = document.createElement('th');
|
|
81
85
|
th.addEventListener('click', evt => this.sort(evt, column));
|
|
82
86
|
th.appendChild(document.createElement('span'));
|
|
@@ -86,10 +90,14 @@ export class Table extends MosaicClient {
|
|
|
86
90
|
thead.appendChild(tr);
|
|
87
91
|
|
|
88
92
|
// get column formatters
|
|
89
|
-
this.formats = formatof(this.format,
|
|
93
|
+
this.formats = formatof(this.format, info);
|
|
90
94
|
|
|
91
95
|
// get column alignment style
|
|
92
|
-
this.style.innerText = tableCSS(
|
|
96
|
+
this.style.innerText = tableCSS(
|
|
97
|
+
this.id,
|
|
98
|
+
alignof(this.align, info),
|
|
99
|
+
widthof(this.widths, info)
|
|
100
|
+
);
|
|
93
101
|
|
|
94
102
|
return this;
|
|
95
103
|
}
|
|
@@ -100,9 +108,9 @@ export class Table extends MosaicClient {
|
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
queryInternal(filter = []) {
|
|
103
|
-
const { from, limit, offset,
|
|
111
|
+
const { from, limit, offset, schema, sortColumn, sortDesc } = this;
|
|
104
112
|
return Query.from(from)
|
|
105
|
-
.select(
|
|
113
|
+
.select(schema.map(s => s.column))
|
|
106
114
|
.where(filter)
|
|
107
115
|
.orderby(sortColumn ? (sortDesc ? desc(sortColumn) : sortColumn) : [])
|
|
108
116
|
.limit(limit)
|
|
@@ -120,15 +128,15 @@ export class Table extends MosaicClient {
|
|
|
120
128
|
}
|
|
121
129
|
|
|
122
130
|
update() {
|
|
123
|
-
const { body, formats, data,
|
|
124
|
-
const nf =
|
|
131
|
+
const { body, formats, data, schema, limit } = this;
|
|
132
|
+
const nf = schema.length;
|
|
125
133
|
|
|
126
134
|
let count = 0;
|
|
127
135
|
for (const row of data) {
|
|
128
136
|
++count;
|
|
129
137
|
const tr = document.createElement('tr');
|
|
130
138
|
for (let i = 0; i < nf; ++i) {
|
|
131
|
-
const value = row[
|
|
139
|
+
const value = row[schema[i].column];
|
|
132
140
|
const td = document.createElement('td');
|
|
133
141
|
td.innerText = value == null ? '' : formats[i](value);
|
|
134
142
|
tr.appendChild(td);
|
|
@@ -171,8 +179,8 @@ export class Table extends MosaicClient {
|
|
|
171
179
|
}
|
|
172
180
|
}
|
|
173
181
|
|
|
174
|
-
function formatof(base = {},
|
|
175
|
-
return
|
|
182
|
+
function formatof(base = {}, schema, locale) {
|
|
183
|
+
return schema.map(({ column, type }) => {
|
|
176
184
|
if (column in base) {
|
|
177
185
|
return base[column];
|
|
178
186
|
} else {
|
|
@@ -185,8 +193,8 @@ function formatof(base = {}, stats, locale) {
|
|
|
185
193
|
});
|
|
186
194
|
}
|
|
187
195
|
|
|
188
|
-
function alignof(base = {},
|
|
189
|
-
return
|
|
196
|
+
function alignof(base = {}, schema) {
|
|
197
|
+
return schema.map(({ column, type }) => {
|
|
190
198
|
if (column in base) {
|
|
191
199
|
return base[column];
|
|
192
200
|
} else if (type === 'number') {
|
|
@@ -197,11 +205,18 @@ function alignof(base = {}, stats) {
|
|
|
197
205
|
});
|
|
198
206
|
}
|
|
199
207
|
|
|
200
|
-
function
|
|
208
|
+
function widthof(base = {}, schema) {
|
|
209
|
+
return schema.map(({ column }) => base[column]);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function tableCSS(id, aligns, widths) {
|
|
201
213
|
const styles = [];
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
214
|
+
aligns.forEach((a, i) => {
|
|
215
|
+
const w = +widths[i];
|
|
216
|
+
if (a !== 'left' || w) {
|
|
217
|
+
const align = a !== 'left' ? `text-align:${a};` : '';
|
|
218
|
+
const width = w ? `width:${w}px;max-width:${w}px;` : '';
|
|
219
|
+
styles.push(`#${id} tr>:nth-child(${i+1}) {${align}${width}}`);
|
|
205
220
|
}
|
|
206
221
|
});
|
|
207
222
|
return styles.join(' ');
|