@uwdata/mosaic-inputs 0.0.1 → 0.1.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/LICENSE +28 -0
- package/README.md +1 -1
- package/dist/mosaic-inputs.js +12330 -105
- package/dist/mosaic-inputs.min.js +10 -1
- package/package.json +5 -4
- package/src/Menu.js +20 -13
- package/src/Search.js +3 -8
- package/src/Slider.js +28 -4
- package/src/Table.js +4 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uwdata/mosaic-inputs",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Mosaic input components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"inputs",
|
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
"prepublishOnly": "npm run test && npm run lint && npm run build"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@uwdata/mosaic-core": "^0.0
|
|
29
|
-
"@uwdata/mosaic-sql": "^0.0
|
|
28
|
+
"@uwdata/mosaic-core": "^0.1.0",
|
|
29
|
+
"@uwdata/mosaic-sql": "^0.1.0",
|
|
30
30
|
"isoformat": "^0.2.1"
|
|
31
|
-
}
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "a7967c35349bdf7f00abb113ce1dd9abb233cd62"
|
|
32
33
|
}
|
package/src/Menu.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Query,
|
|
1
|
+
import { MosaicClient, isParam, isSelection } from '@uwdata/mosaic-core';
|
|
2
|
+
import { Query, eq, literal } from '@uwdata/mosaic-sql';
|
|
3
3
|
|
|
4
4
|
const isObject = v => {
|
|
5
5
|
return v && typeof v === 'object' && !Array.isArray(v);
|
|
@@ -11,6 +11,7 @@ export class Menu extends MosaicClient {
|
|
|
11
11
|
from,
|
|
12
12
|
column,
|
|
13
13
|
label = column,
|
|
14
|
+
format = x => x, // TODO
|
|
14
15
|
options,
|
|
15
16
|
value,
|
|
16
17
|
as
|
|
@@ -19,6 +20,7 @@ export class Menu extends MosaicClient {
|
|
|
19
20
|
this.from = from;
|
|
20
21
|
this.column = column;
|
|
21
22
|
this.selection = as;
|
|
23
|
+
this.format = format;
|
|
22
24
|
|
|
23
25
|
this.element = document.createElement('div');
|
|
24
26
|
this.element.setAttribute('class', 'input');
|
|
@@ -40,18 +42,28 @@ export class Menu extends MosaicClient {
|
|
|
40
42
|
|
|
41
43
|
if (this.selection) {
|
|
42
44
|
this.select.addEventListener('input', () => {
|
|
43
|
-
this.publish(this.
|
|
45
|
+
this.publish(this.selectedValue() || null);
|
|
44
46
|
});
|
|
45
47
|
if (!isSelection(this.selection)) {
|
|
46
48
|
this.selection.addEventListener('value', value => {
|
|
47
49
|
if (value !== this.select.value) {
|
|
48
|
-
this.
|
|
50
|
+
this.selectedValue(value);
|
|
49
51
|
}
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
|
|
57
|
+
selectedValue(value) {
|
|
58
|
+
if (arguments.length === 0) {
|
|
59
|
+
const index = this.select.selectedIndex;
|
|
60
|
+
return this.data[index].value;
|
|
61
|
+
} else {
|
|
62
|
+
// TODO make more robust
|
|
63
|
+
this.select.value = String(value);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
55
67
|
publish(value) {
|
|
56
68
|
const { selection, column } = this;
|
|
57
69
|
if (isSelection(selection)) {
|
|
@@ -61,16 +73,11 @@ export class Menu extends MosaicClient {
|
|
|
61
73
|
value,
|
|
62
74
|
predicate: value ? eq(column, literal(value)) : null
|
|
63
75
|
});
|
|
64
|
-
} else if (
|
|
76
|
+
} else if (isParam(selection)) {
|
|
65
77
|
selection.update(value);
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
80
|
|
|
69
|
-
fields() {
|
|
70
|
-
const { from, column } = this;
|
|
71
|
-
return from ? [ columnRef(from, column) ] : null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
81
|
query(filter = []) {
|
|
75
82
|
const { from, column } = this;
|
|
76
83
|
if (!from) return null;
|
|
@@ -88,12 +95,12 @@ export class Menu extends MosaicClient {
|
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
update() {
|
|
91
|
-
const { data, select } = this;
|
|
98
|
+
const { data, format, select } = this;
|
|
92
99
|
select.replaceChildren();
|
|
93
|
-
for (const { value, label
|
|
100
|
+
for (const { value, label } of data) {
|
|
94
101
|
const opt = document.createElement('option');
|
|
95
102
|
opt.setAttribute('value', value);
|
|
96
|
-
opt.innerText = label
|
|
103
|
+
opt.innerText = label ?? format(value);
|
|
97
104
|
this.select.appendChild(opt);
|
|
98
105
|
}
|
|
99
106
|
if (this.selection) {
|
package/src/Search.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MosaicClient, isParam, isSelection } from '@uwdata/mosaic-core';
|
|
2
2
|
import {
|
|
3
|
-
Query,
|
|
3
|
+
Query, regexp_matches, contains, prefix, suffix, literal
|
|
4
4
|
} from '@uwdata/mosaic-sql';
|
|
5
5
|
|
|
6
6
|
const FUNCTIONS = { contains, prefix, suffix, regexp: regexp_matches };
|
|
@@ -62,16 +62,11 @@ export class Search extends MosaicClient {
|
|
|
62
62
|
value,
|
|
63
63
|
predicate: value ? FUNCTIONS[type](column, literal(value)) : null
|
|
64
64
|
});
|
|
65
|
-
} else if (
|
|
65
|
+
} else if (isParam(selection)) {
|
|
66
66
|
selection.update(value);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
fields() {
|
|
71
|
-
const { from, column } = this;
|
|
72
|
-
return from ? [ columnRef(from, column) ] : null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
70
|
query(filter = []) {
|
|
76
71
|
const { from, column } = this;
|
|
77
72
|
if (!from) return null;
|
package/src/Slider.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { eq, literal } from '@uwdata/mosaic-sql';
|
|
1
|
+
import { MosaicClient, isParam, isSelection } from '@uwdata/mosaic-core';
|
|
2
|
+
import { Query, eq, literal, max, min } from '@uwdata/mosaic-sql';
|
|
3
3
|
|
|
4
4
|
let _id = 0;
|
|
5
5
|
|
|
6
|
-
export class Slider {
|
|
6
|
+
export class Slider extends MosaicClient {
|
|
7
7
|
constructor({
|
|
8
|
+
filterBy,
|
|
8
9
|
as,
|
|
9
10
|
min,
|
|
10
11
|
max,
|
|
11
12
|
step,
|
|
13
|
+
from,
|
|
12
14
|
column,
|
|
13
15
|
label = column,
|
|
14
16
|
value = as?.value
|
|
15
17
|
} = {}) {
|
|
18
|
+
super(filterBy);
|
|
16
19
|
this.id = 'slider_' + (++_id);
|
|
20
|
+
this.from = from;
|
|
17
21
|
this.column = column || 'value';
|
|
18
22
|
this.selection = as;
|
|
23
|
+
this.min = min;
|
|
24
|
+
this.max = max;
|
|
25
|
+
this.step = step;
|
|
19
26
|
|
|
20
27
|
this.element = document.createElement('div');
|
|
21
28
|
this.element.setAttribute('class', 'input');
|
|
@@ -54,6 +61,23 @@ export class Slider {
|
|
|
54
61
|
}
|
|
55
62
|
}
|
|
56
63
|
|
|
64
|
+
query(filter = []) {
|
|
65
|
+
const { from, column } = this;
|
|
66
|
+
if (!from || (this.min != null && this.max != null)) return null;
|
|
67
|
+
return Query
|
|
68
|
+
.select({ min: min(column), max: max(column) })
|
|
69
|
+
.from(from)
|
|
70
|
+
.where(filter);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
queryResult(data) {
|
|
74
|
+
const { min, max } = Array.from(data)[0];
|
|
75
|
+
if (this.min == null) this.slider.setAttribute('min', min);
|
|
76
|
+
if (this.max == null) this.slider.setAttribute('max', max);
|
|
77
|
+
if (this.step == null) this.slider.setAttribute('step', (max - min) / 500);
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
|
|
57
81
|
publish(value) {
|
|
58
82
|
const { selection, column } = this;
|
|
59
83
|
if (isSelection(selection)) {
|
|
@@ -63,7 +87,7 @@ export class Slider {
|
|
|
63
87
|
value,
|
|
64
88
|
predicate: eq(column, literal(value))
|
|
65
89
|
});
|
|
66
|
-
} else if (
|
|
90
|
+
} else if (isParam(this.selection)) {
|
|
67
91
|
selection.update(value);
|
|
68
92
|
}
|
|
69
93
|
}
|
package/src/Table.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MosaicClient
|
|
1
|
+
import { MosaicClient } from '@uwdata/mosaic-core';
|
|
2
2
|
import { Query, column, desc } from '@uwdata/mosaic-sql';
|
|
3
3
|
import { formatDate, formatLocaleAuto, formatLocaleNumber } from './util/format.js';
|
|
4
4
|
|
|
@@ -21,7 +21,6 @@ export class Table extends MosaicClient {
|
|
|
21
21
|
this.format = format;
|
|
22
22
|
this.offset = 0;
|
|
23
23
|
this.limit = +rowBatch;
|
|
24
|
-
this.request = new Signal();
|
|
25
24
|
this.pending = false;
|
|
26
25
|
|
|
27
26
|
this.sortHeader = null;
|
|
@@ -50,7 +49,7 @@ export class Table extends MosaicClient {
|
|
|
50
49
|
this.pending = true;
|
|
51
50
|
this.offset += this.limit;
|
|
52
51
|
const query = this.queryInternal(this.filterBy?.predicate(this));
|
|
53
|
-
this.
|
|
52
|
+
this.requestQuery(query);
|
|
54
53
|
}
|
|
55
54
|
});
|
|
56
55
|
|
|
@@ -68,8 +67,7 @@ export class Table extends MosaicClient {
|
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
fields() {
|
|
71
|
-
|
|
72
|
-
return columns.map(name => column(from, name));
|
|
70
|
+
return this.columns.map(name => column(this.from, name));
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
fieldStats(stats) {
|
|
@@ -169,7 +167,7 @@ export class Table extends MosaicClient {
|
|
|
169
167
|
|
|
170
168
|
// issue query for sorted data
|
|
171
169
|
const query = this.query(this.filterBy?.predicate(this));
|
|
172
|
-
this.
|
|
170
|
+
this.requestQuery(query);
|
|
173
171
|
}
|
|
174
172
|
}
|
|
175
173
|
|