@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.
Files changed (48) hide show
  1. package/dist/components/Banner.d.ts +1 -1
  2. package/dist/components/dialog/dialog.d.ts +2 -1
  3. package/dist/components/pagination/pagination.d.ts +1 -1
  4. package/dist/components/query_bar/QueryBar.d.ts +31 -11
  5. package/dist/components/query_bar/dateTimePopup.d.ts +2 -0
  6. package/dist/components/query_bar/geojsonPopup.d.ts +2 -0
  7. package/dist/components/query_bar/querylanguage/kuery/functions/geospatial.d.ts +19 -0
  8. package/dist/components/query_bar/querylanguage/outputTypes/toCQL.d.ts +2 -1
  9. package/dist/components/query_bar/querylanguage/outputTypes/toMongo.d.ts +6 -1
  10. package/dist/components/symbols.d.ts +6 -0
  11. package/dist/components/table/cell.d.ts +2 -2
  12. package/dist/components/table/header.d.ts +2 -1
  13. package/dist/components/table/table.d.ts +14 -7
  14. package/dist/custom-elements.json +8 -8
  15. package/dist/index.d.ts +4 -0
  16. package/dist/index.es.js +4556 -2834
  17. package/dist/index.es.js.map +1 -1
  18. package/dist/index.umd.js +424 -248
  19. package/dist/index.umd.js.map +1 -1
  20. package/dist/style.css +1 -1
  21. package/package.json +6 -1
  22. package/src/components/Banner.ts +46 -31
  23. package/src/components/dialog/dialog.css.ts +29 -29
  24. package/src/components/dialog/dialog.ts +165 -135
  25. package/src/components/input.ts +49 -39
  26. package/src/components/pagination/pagination.ts +167 -113
  27. package/src/components/query_bar/QueryBar.ts +441 -185
  28. package/src/components/query_bar/dateTimePopup.ts +54 -0
  29. package/src/components/query_bar/geojsonPopup.ts +44 -0
  30. package/src/components/query_bar/querylanguage/kuery/ast/_generated_/kuery.js +1836 -2745
  31. package/src/components/query_bar/querylanguage/kuery/ast/ast.ts +15 -13
  32. package/src/components/query_bar/querylanguage/kuery/ast/kuery.peg +92 -126
  33. package/src/components/query_bar/querylanguage/kuery/functions/geospatial.ts +25 -0
  34. package/src/components/query_bar/querylanguage/kuery/functions/index.ts +9 -7
  35. package/src/components/query_bar/querylanguage/outputTypes/toCQL.ts +56 -34
  36. package/src/components/query_bar/querylanguage/outputTypes/toMongo.ts +46 -34
  37. package/src/components/symbols.ts +6 -0
  38. package/src/components/table/__tests__/table.spec.ts +143 -55
  39. package/src/components/table/cell.ts +188 -145
  40. package/src/components/table/header.ts +163 -152
  41. package/src/components/table/table.css +4 -2
  42. package/src/components/table/table.ts +415 -262
  43. package/src/components/table/virtualBody.ts +170 -115
  44. package/src/components/tooltip/popover.ts +263 -225
  45. package/src/stories/Dialog.stories.ts +59 -0
  46. package/src/stories/QueryBar.stories.ts +46 -37
  47. package/src/stories/fixtures/data.ts +195 -36
  48. package/src/stories/table.stories.ts +70 -22
@@ -1,139 +1,194 @@
1
- import { html } from 'lit';
2
- import { customElement, property, } from 'lit/decorators.js';
3
- import { HTMLElementTagWithEvents, ReactElementWithPropsAndEvents } from '../types';
4
- export const TableBodyElementTag = "spectric-table-virtual-body"
5
- import "./cell"
6
- import { ColumnSettings, SpectricTableElement, TD_BorderAndPadding } from './table';
7
- import { repeat } from 'lit/directives/repeat.js';
8
- import { DisposableElement } from '../../classes/DisposibleElement';
9
- import "./virtualBody.css"
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
- columns: ColumnSettings<T>[]
12
- data: T[]
13
- rowHeight: number
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> extends DisposableElement implements BodyProps<T> {
22
- @property({ type: Array, attribute: false })
23
- data: T[] = [];
24
- @property({ type: Array, attribute: false })
25
- columns: ColumnSettings<T>[] = [];
26
- @property({ type: Number, attribute: false })
27
- rowHeight: number = 30;
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
- @property({ type: Number, state: true })
30
- startIndex: number = 0
38
+ @property({ type: Number, state: true })
39
+ startIndex: number = 0;
31
40
 
32
- table!: SpectricTableElement<T>
33
- columnsMeasured: boolean = false;
34
- constructor() {
35
- super()
36
- this.addDisposableListener(() => this.table.querySelector(".table-wrapper")!, "scroll", () => {
37
- const scrollTop = this.table.querySelector(".table-wrapper")!.scrollTop;
38
- requestAnimationFrame(() => {
39
- this.startIndex = Math.floor(scrollTop / this.rowHeight);
40
- })
41
- })
42
- }
43
- protected updated(): void {
44
- if (this.columnsMeasured === false) {
45
- let tr = this.querySelector("tr");
46
- let cells = tr?.querySelectorAll("spectric-table-cell td")
47
- if (tr && cells && cells.length) {
48
- this.columns.forEach((col, index) => {
49
- if (!col.width || col.width === 0) {
50
- let rect = cells[index].getBoundingClientRect()
51
- if (rect.width > 0) {
52
- this.columnsMeasured = true
53
- col.width = rect.width - TD_BorderAndPadding
54
- }
55
- }
56
- })
57
- this.columns = [...this.columns]
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
- protected createRenderRoot(): HTMLElement | DocumentFragment {
62
- return this
63
- }
64
- protected render(): unknown {
65
- let totalRows = this.data.length
66
- let buffer = 10 // Have a buffer of rows to prevent column jitter
67
- let headerHeight = this.table.querySelector("spectric-table-header")!.clientHeight
68
- let viewport = this.table.querySelector(".table-wrapper")!
69
- let startIndex = Math.max(this.startIndex, 0)
70
- const rowsThatFit = Math.ceil((viewport.clientHeight - headerHeight) / this.rowHeight);
71
- const endIndex = Math.min(startIndex + rowsThatFit + buffer, totalRows);
72
- const visibleRows = endIndex - startIndex
73
- let totalHeight = totalRows * this.rowHeight
74
- let beforeHeight = (startIndex * this.rowHeight) + (viewport.scrollTop - (startIndex * this.rowHeight))
75
- if (endIndex === totalRows) {
76
- beforeHeight = (startIndex * this.rowHeight)
77
- }
78
- let visibleHeight = (visibleRows * this.rowHeight)
79
- let afterHeight = totalHeight - beforeHeight - visibleHeight
80
- let spacerElementBefore = startIndex != 0 ? html`
81
- <tr style="height:${beforeHeight}px" class="virtual-scroll-spacer">
82
- <td colspan="${this.columns.length}"></td></tr>` : null
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
- //'sort': (event: CustomEvent<ColumnSettings<any>>) => void; //TODO sort events
158
+ //'sort': (event: CustomEvent<ColumnSettings<any>>) => void; //TODO sort events
114
159
  }
115
160
 
116
161
  declare global {
117
- interface HTMLElementTagNameMap {
118
- [TableBodyElementTag]: HTMLElementTagWithEvents<TableVirtualBodyElement<any>, TableBodyEvents>
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
- interface IntrinsicElements {
123
- /**
124
- * @see {@link DialogElement}
125
- */
126
- [TableBodyElementTag]: ReactElementWithPropsAndEvents<TableVirtualBodyElement<any>, BodyProps<any>, TableBodyEvents>;
127
- }
128
- }
129
- namespace React {
130
- namespace JSX {
131
- interface IntrinsicElements {
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
  }