@spectric/ui 0.0.20 → 0.0.22
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/components/Banner.d.ts +1 -1
- package/dist/components/dialog/dialog.d.ts +2 -1
- package/dist/components/pagination/pagination.d.ts +1 -1
- package/dist/components/query_bar/QueryBar.d.ts +31 -11
- package/dist/components/query_bar/dateTimePopup.d.ts +2 -0
- package/dist/components/query_bar/geojsonPopup.d.ts +2 -0
- package/dist/components/query_bar/querylanguage/kuery/functions/geospatial.d.ts +19 -0
- package/dist/components/query_bar/querylanguage/outputTypes/toCQL.d.ts +2 -1
- package/dist/components/query_bar/querylanguage/outputTypes/toMongo.d.ts +6 -1
- package/dist/components/symbols.d.ts +6 -0
- package/dist/components/table/cell.d.ts +2 -2
- package/dist/components/table/header.d.ts +2 -1
- package/dist/components/table/table.d.ts +14 -7
- package/dist/custom-elements.json +8 -8
- package/dist/index.d.ts +4 -0
- package/dist/index.es.js +4556 -2834
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +424 -248
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +6 -1
- package/src/components/Banner.ts +46 -31
- package/src/components/dialog/dialog.css.ts +29 -29
- package/src/components/dialog/dialog.ts +165 -135
- package/src/components/input.ts +49 -39
- package/src/components/pagination/pagination.ts +167 -113
- package/src/components/query_bar/QueryBar.ts +441 -185
- package/src/components/query_bar/dateTimePopup.ts +54 -0
- package/src/components/query_bar/geojsonPopup.ts +44 -0
- package/src/components/query_bar/querylanguage/kuery/ast/_generated_/kuery.js +1836 -2745
- package/src/components/query_bar/querylanguage/kuery/ast/ast.ts +15 -13
- package/src/components/query_bar/querylanguage/kuery/ast/kuery.peg +92 -126
- package/src/components/query_bar/querylanguage/kuery/functions/geospatial.ts +25 -0
- package/src/components/query_bar/querylanguage/kuery/functions/index.ts +9 -7
- package/src/components/query_bar/querylanguage/outputTypes/toCQL.ts +56 -34
- package/src/components/query_bar/querylanguage/outputTypes/toMongo.ts +46 -34
- package/src/components/symbols.ts +6 -0
- package/src/components/table/__tests__/table.spec.ts +143 -55
- package/src/components/table/cell.ts +188 -145
- package/src/components/table/header.ts +163 -152
- package/src/components/table/table.css +4 -2
- package/src/components/table/table.ts +415 -262
- package/src/components/table/virtualBody.ts +170 -115
- package/src/components/tooltip/popover.ts +263 -225
- package/src/stories/Dialog.stories.ts +59 -0
- package/src/stories/QueryBar.stories.ts +46 -37
- package/src/stories/fixtures/data.ts +195 -36
- package/src/stories/table.stories.ts +70 -22
|
@@ -1,139 +1,194 @@
|
|
|
1
|
-
import { html } from
|
|
2
|
-
import { customElement, property
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
import
|
|
1
|
+
import { html } from "lit";
|
|
2
|
+
import { customElement, property } from "lit/decorators.js";
|
|
3
|
+
import {
|
|
4
|
+
HTMLElementTagWithEvents,
|
|
5
|
+
ReactElementWithPropsAndEvents,
|
|
6
|
+
} from "../types";
|
|
7
|
+
export const TableBodyElementTag = "spectric-table-virtual-body";
|
|
8
|
+
import "./cell";
|
|
9
|
+
import {
|
|
10
|
+
ColumnSettings,
|
|
11
|
+
SpectricTableElement,
|
|
12
|
+
TD_BorderAndPadding,
|
|
13
|
+
} from "./table";
|
|
14
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
15
|
+
import { DisposableElement } from "../../classes/DisposibleElement";
|
|
16
|
+
import "./virtualBody.css";
|
|
10
17
|
interface BodyProps<T> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
columns: ColumnSettings<T>[];
|
|
19
|
+
data: T[];
|
|
20
|
+
rowHeight: number;
|
|
14
21
|
}
|
|
15
22
|
|
|
16
|
-
|
|
17
23
|
/**
|
|
18
24
|
* Table Body Element
|
|
19
25
|
*/
|
|
20
26
|
@customElement(TableBodyElementTag)
|
|
21
|
-
export class TableVirtualBodyElement<T>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
export class TableVirtualBodyElement<T>
|
|
28
|
+
extends DisposableElement
|
|
29
|
+
implements BodyProps<T>
|
|
30
|
+
{
|
|
31
|
+
@property({ type: Array, attribute: false })
|
|
32
|
+
data: T[] = [];
|
|
33
|
+
@property({ type: Array, attribute: false })
|
|
34
|
+
columns: ColumnSettings<T>[] = [];
|
|
35
|
+
@property({ type: Number, attribute: false })
|
|
36
|
+
rowHeight: number = 30;
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
@property({ type: Number, state: true })
|
|
39
|
+
startIndex: number = 0;
|
|
31
40
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
41
|
+
@property({ type: Object, attribute: false })
|
|
42
|
+
table!: SpectricTableElement<T>;
|
|
43
|
+
columnsMeasured: boolean = false;
|
|
44
|
+
constructor() {
|
|
45
|
+
super();
|
|
46
|
+
let lastScroll = 0;
|
|
47
|
+
this.addDisposableListener(
|
|
48
|
+
() => this.table.querySelector(".table-wrapper")!,
|
|
49
|
+
"scroll",
|
|
50
|
+
() => {
|
|
51
|
+
const scrollTop = this.table.querySelector(".table-wrapper")!.scrollTop;
|
|
52
|
+
// Prevent changing the start index if the scroll hasn't changed more than at at least 1/4 a row
|
|
53
|
+
// I think I have bad math that is causing a new scroll event due to a couple pixel height difference after I create the spacers
|
|
54
|
+
if (Math.abs(lastScroll - scrollTop) <= this.rowHeight / 4) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
lastScroll = scrollTop;
|
|
58
|
+
this.startIndex = Math.floor(scrollTop / this.rowHeight);
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
protected updated(): void {
|
|
63
|
+
if (this.columnsMeasured === false) {
|
|
64
|
+
let tr = this.querySelector("tr");
|
|
65
|
+
let cells = tr?.querySelectorAll("spectric-table-cell td");
|
|
66
|
+
if (tr && cells && cells.length) {
|
|
67
|
+
this.columns.forEach((col, index) => {
|
|
68
|
+
if (!col.width || col.width === 0) {
|
|
69
|
+
let rect = cells[index].getBoundingClientRect();
|
|
70
|
+
if (rect.width > 0) {
|
|
71
|
+
this.columnsMeasured = true;
|
|
72
|
+
col.width = rect.width - TD_BorderAndPadding;
|
|
58
73
|
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (this.columnsMeasured) {
|
|
77
|
+
this.columns = [...this.columns];
|
|
59
78
|
}
|
|
79
|
+
}
|
|
60
80
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
let spacerElementAfter = html`
|
|
85
|
-
<tr style="height:${afterHeight}px" class="virtual-scroll-spacer">
|
|
86
|
-
<td colspan="${this.columns.length}"></td></tr>`
|
|
87
|
-
return html`
|
|
88
|
-
<div style="height:${totalHeight}px;position: absolute;overflow-x: hidden;overflow-y: hidden;z-index:-1;width:1px;"></div>
|
|
89
|
-
<tbody>
|
|
90
|
-
${spacerElementBefore}
|
|
91
|
-
</tbody>
|
|
92
|
-
<div style="display:table-row-group;max-height:${visibleHeight}px; overflow:hidden;">
|
|
93
|
-
|
|
94
|
-
${repeat(this.data.slice(Math.max(startIndex, 0), endIndex), (row, index) => html`
|
|
95
|
-
<tr class="${(index + startIndex) % 2 === 0 ? "odd" : ""}">
|
|
96
|
-
${repeat(this.columns, (col) => {
|
|
97
|
-
return html`<spectric-table-cell .column=${col} .row=${row} .index=${index + startIndex} .columns=${this.columns}></spectric-table-cell>`
|
|
98
|
-
})}
|
|
99
|
-
</tr>`)
|
|
100
|
-
}
|
|
101
|
-
</div>
|
|
102
|
-
<tbody>
|
|
103
|
-
${afterHeight > 0 ? spacerElementAfter : null}
|
|
104
|
-
</tbody>
|
|
105
|
-
|
|
106
|
-
`
|
|
107
|
-
|
|
81
|
+
}
|
|
82
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment {
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
protected render(): unknown {
|
|
86
|
+
let totalRows = this.data.length;
|
|
87
|
+
let buffer = 10; // Have a buffer of rows to prevent column jitter
|
|
88
|
+
let headerHeight = this.table.querySelector(
|
|
89
|
+
"spectric-table-header"
|
|
90
|
+
)!.clientHeight;
|
|
91
|
+
let viewport = this.table.querySelector(".table-wrapper")!;
|
|
92
|
+
let startIndex = Math.max(this.startIndex, 0);
|
|
93
|
+
const rowsThatFit = Math.ceil(
|
|
94
|
+
(viewport.clientHeight - headerHeight) / this.rowHeight
|
|
95
|
+
);
|
|
96
|
+
const endIndex = Math.min(startIndex + rowsThatFit + buffer, totalRows);
|
|
97
|
+
const visibleRows = endIndex - startIndex;
|
|
98
|
+
let totalHeight = totalRows * this.rowHeight;
|
|
99
|
+
let beforeHeight =
|
|
100
|
+
startIndex * this.rowHeight +
|
|
101
|
+
(viewport.scrollTop - startIndex * this.rowHeight);
|
|
102
|
+
if (endIndex === totalRows) {
|
|
103
|
+
beforeHeight = startIndex * this.rowHeight;
|
|
108
104
|
}
|
|
105
|
+
let visibleHeight = visibleRows * this.rowHeight;
|
|
106
|
+
let afterHeight = totalHeight - beforeHeight - visibleHeight;
|
|
107
|
+
let spacerElementBefore =
|
|
108
|
+
startIndex != 0
|
|
109
|
+
? html` <tr
|
|
110
|
+
style="height:${beforeHeight}px"
|
|
111
|
+
class="virtual-scroll-spacer"
|
|
112
|
+
>
|
|
113
|
+
<td colspan="${this.columns.length}"></td>
|
|
114
|
+
</tr>`
|
|
115
|
+
: null;
|
|
109
116
|
|
|
117
|
+
let spacerElementAfter = html` <tr
|
|
118
|
+
style="height:${afterHeight}px"
|
|
119
|
+
class="virtual-scroll-spacer"
|
|
120
|
+
>
|
|
121
|
+
<td colspan="${this.columns.length}"></td>
|
|
122
|
+
</tr>`;
|
|
123
|
+
return html`
|
|
124
|
+
<div
|
|
125
|
+
style="height:${totalHeight}px;position: absolute;overflow-x: hidden;overflow-y: hidden;z-index:-1;width:1px;"
|
|
126
|
+
></div>
|
|
127
|
+
<tbody>
|
|
128
|
+
${spacerElementBefore}
|
|
129
|
+
</tbody>
|
|
130
|
+
<div
|
|
131
|
+
style="display:table-row-group;max-height:${visibleHeight}px; overflow:hidden;"
|
|
132
|
+
>
|
|
133
|
+
${repeat(
|
|
134
|
+
this.data.slice(Math.max(startIndex, 0), endIndex),
|
|
135
|
+
(row, index) => html` <tr
|
|
136
|
+
class="${(index + startIndex) % 2 === 0 ? "odd" : ""}"
|
|
137
|
+
>
|
|
138
|
+
${repeat(this.columns, (col) => {
|
|
139
|
+
return html`<spectric-table-cell
|
|
140
|
+
.column=${col}
|
|
141
|
+
.row=${row}
|
|
142
|
+
.index=${index + startIndex}
|
|
143
|
+
.columns=${this.columns}
|
|
144
|
+
.table=${this.table}
|
|
145
|
+
></spectric-table-cell>`;
|
|
146
|
+
})}
|
|
147
|
+
</tr>`
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
<tbody>
|
|
151
|
+
${afterHeight > 0 ? spacerElementAfter : null}
|
|
152
|
+
</tbody>
|
|
153
|
+
`;
|
|
154
|
+
}
|
|
110
155
|
}
|
|
111
156
|
|
|
112
157
|
interface TableBodyEvents {
|
|
113
|
-
|
|
158
|
+
//'sort': (event: CustomEvent<ColumnSettings<any>>) => void; //TODO sort events
|
|
114
159
|
}
|
|
115
160
|
|
|
116
161
|
declare global {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
162
|
+
interface HTMLElementTagNameMap {
|
|
163
|
+
[TableBodyElementTag]: HTMLElementTagWithEvents<
|
|
164
|
+
TableVirtualBodyElement<any>,
|
|
165
|
+
TableBodyEvents
|
|
166
|
+
>;
|
|
167
|
+
}
|
|
168
|
+
namespace JSX {
|
|
169
|
+
interface IntrinsicElements {
|
|
170
|
+
/**
|
|
171
|
+
* @see {@link DialogElement}
|
|
172
|
+
*/
|
|
173
|
+
[TableBodyElementTag]: ReactElementWithPropsAndEvents<
|
|
174
|
+
TableVirtualBodyElement<any>,
|
|
175
|
+
BodyProps<any>,
|
|
176
|
+
TableBodyEvents
|
|
177
|
+
>;
|
|
120
178
|
}
|
|
179
|
+
}
|
|
180
|
+
namespace React {
|
|
121
181
|
namespace JSX {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* @see {@link DialogElement}
|
|
134
|
-
*/
|
|
135
|
-
[TableBodyElementTag]: ReactElementWithPropsAndEvents<TableVirtualBodyElement<any>, BodyProps<any>, TableBodyEvents>
|
|
136
|
-
}
|
|
137
|
-
}
|
|
182
|
+
interface IntrinsicElements {
|
|
183
|
+
/**
|
|
184
|
+
* @see {@link DialogElement}
|
|
185
|
+
*/
|
|
186
|
+
[TableBodyElementTag]: ReactElementWithPropsAndEvents<
|
|
187
|
+
TableVirtualBodyElement<any>,
|
|
188
|
+
BodyProps<any>,
|
|
189
|
+
TableBodyEvents
|
|
190
|
+
>;
|
|
191
|
+
}
|
|
138
192
|
}
|
|
193
|
+
}
|
|
139
194
|
}
|