@uwdata/mosaic-inputs 0.14.1 → 0.16.1

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.
@@ -74,6 +74,6 @@ export class Menu extends Input {
74
74
  queryResult(data: any): this;
75
75
  update(): this;
76
76
  }
77
- import { Selection } from '@uwdata/mosaic-core';
78
- import { Param } from '@uwdata/mosaic-core';
77
+ import type { Selection } from '@uwdata/mosaic-core';
78
+ import type { Param } from '@uwdata/mosaic-core';
79
79
  import { Input } from './input.js';
@@ -64,6 +64,6 @@ export class Search extends Input {
64
64
  update(): this;
65
65
  datalist: HTMLDataListElement;
66
66
  }
67
- import { Selection } from '@uwdata/mosaic-core';
68
- import { Param } from '@uwdata/mosaic-core';
67
+ import type { Selection } from '@uwdata/mosaic-core';
68
+ import type { Param } from '@uwdata/mosaic-core';
69
69
  import { Input } from './input.js';
@@ -79,6 +79,6 @@ export class Slider extends Input {
79
79
  clause(value: any): import("@uwdata/mosaic-core").SelectionClause;
80
80
  publish(value: any): void;
81
81
  }
82
- import { Selection } from '@uwdata/mosaic-core';
83
- import { Param } from '@uwdata/mosaic-core';
82
+ import type { Selection } from '@uwdata/mosaic-core';
83
+ import type { Param } from '@uwdata/mosaic-core';
84
84
  import { Input } from './input.js';
@@ -98,12 +98,7 @@ export class Table extends Input {
98
98
  sourceTable(): any;
99
99
  clause(rows?: any[]): import("@uwdata/mosaic-core").SelectionClause;
100
100
  requestData(offset?: number): void;
101
- fields(): {
102
- column: string;
103
- table: any;
104
- }[];
105
- fieldInfo(info: any): this;
106
- schema: any;
101
+ schema: import("@uwdata/mosaic-core").FieldInfo[];
107
102
  formats: any;
108
103
  query(filter?: any[]): import("@uwdata/mosaic-sql").SelectQuery;
109
104
  queryResult(data: any): this;
@@ -112,5 +107,5 @@ export class Table extends Input {
112
107
  update(): this;
113
108
  sort(event: any, column: any): void;
114
109
  }
115
- import { Selection } from '@uwdata/mosaic-core';
110
+ import type { Selection } from '@uwdata/mosaic-core';
116
111
  import { Input } from './input.js';
@@ -1,6 +1,6 @@
1
1
  export function stringify(x: any): string;
2
2
  export function formatTrim(value: any): any;
3
- export function formatDate(date: any): any;
3
+ export function formatDate(date: any): string;
4
4
  export function localize(f: any): (locale?: string) => any;
5
5
  export function formatLocaleAuto(locale?: string): any;
6
6
  export function formatLocaleNumber(locale?: string): any;
package/jsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "include": ["src/**/*"],
3
+ "compilerOptions": {
4
+ "checkJs": true,
5
+ "noEmit": true,
6
+ "noImplicitAny": false,
7
+ "module": "node16",
8
+ "skipLibCheck": true,
9
+ "types": []
10
+ }
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uwdata/mosaic-inputs",
3
- "version": "0.14.1",
3
+ "version": "0.16.1",
4
4
  "description": "Mosaic input components.",
5
5
  "keywords": [
6
6
  "inputs",
@@ -10,6 +10,7 @@
10
10
  "author": "Jeffrey Heer (https://idl.uw.edu)",
11
11
  "type": "module",
12
12
  "exports": {
13
+ "types": "./dist/types/index.d.ts",
13
14
  "default": "./src/index.js"
14
15
  },
15
16
  "repository": {
@@ -17,14 +18,17 @@
17
18
  "url": "https://github.com/uwdata/mosaic.git"
18
19
  },
19
20
  "scripts": {
21
+ "prebuild": "rimraf dist && mkdir dist",
22
+ "build": "npm run types",
23
+ "types": "tsc -p tsconfig.json",
20
24
  "lint": "eslint src test",
21
- "test": "vitest run",
22
- "prepublishOnly": "npm run test && npm run lint"
25
+ "test": "vitest run && npm run tsc",
26
+ "tsc": "tsc -p jsconfig.json",
27
+ "prepublishOnly": "npm run test && npm run lint && npm run build"
23
28
  },
24
29
  "dependencies": {
25
- "@uwdata/mosaic-core": "^0.14.1",
26
- "@uwdata/mosaic-sql": "^0.14.1",
27
- "isoformat": "^0.2.1"
30
+ "@uwdata/mosaic-core": "^0.16.1",
31
+ "@uwdata/mosaic-sql": "^0.16.1"
28
32
  },
29
- "gitHead": "5959cb169e95bd8467e1e5d7a9b98954f09474f3"
33
+ "gitHead": "e12af9927b0a35a0e3194850ef569d0d24a022ce"
30
34
  }
package/src/Menu.js CHANGED
@@ -1,4 +1,5 @@
1
- import { Param, Selection, isParam, isSelection, clausePoint } from '@uwdata/mosaic-core';
1
+ /** @import { Param, Selection } from '@uwdata/mosaic-core' */
2
+ import { isParam, isSelection, clausePoint } from '@uwdata/mosaic-core';
2
3
  import { Query } from '@uwdata/mosaic-sql';
3
4
  import { Input, input } from './input.js';
4
5
 
package/src/Search.js CHANGED
@@ -1,4 +1,5 @@
1
- import { Param, Selection, isParam, isSelection, clauseMatch } from '@uwdata/mosaic-core';
1
+ /** @import { Param, Selection } from '@uwdata/mosaic-core' */
2
+ import { isParam, isSelection, clauseMatch } from '@uwdata/mosaic-core';
2
3
  import { Query } from '@uwdata/mosaic-sql';
3
4
  import { Input, input } from './input.js';
4
5
 
package/src/Slider.js CHANGED
@@ -1,4 +1,5 @@
1
- import { Param, Selection, clauseInterval, clausePoint, isParam, isSelection } from '@uwdata/mosaic-core';
1
+ /** @import { Param, Selection } from '@uwdata/mosaic-core' */
2
+ import { clauseInterval, clausePoint, isParam, isSelection } from '@uwdata/mosaic-core';
2
3
  import { Query, max, min } from '@uwdata/mosaic-sql';
3
4
  import { Input, input } from './input.js';
4
5
 
package/src/Table.js CHANGED
@@ -1,4 +1,5 @@
1
- import { Selection, clausePoints, coordinator, isParam, isSelection, toDataColumns } from '@uwdata/mosaic-core';
1
+ /** @import { Selection } from '@uwdata/mosaic-core' */
2
+ import { clausePoints, coordinator, isParam, isSelection, queryFieldInfo, toDataColumns } from '@uwdata/mosaic-core';
2
3
  import { Query, desc } from '@uwdata/mosaic-sql';
3
4
  import { formatDate, formatLocaleAuto, formatLocaleNumber } from './util/format.js';
4
5
  import { Input, input } from './input.js';
@@ -186,18 +187,18 @@ export class Table extends Input {
186
187
  coordinator().prefetch(query.clone().offset(offset + this.limit));
187
188
  }
188
189
 
189
- fields() {
190
+ async prepare() {
191
+ // query for column scheam information
190
192
  const table = this.sourceTable();
191
- return this.columns.map(column => ({ column, table }));
192
- }
193
-
194
- fieldInfo(info) {
195
- this.schema = info;
193
+ const fields = this.columns.map(column => ({ column, table }));
194
+ const schema = await queryFieldInfo(this.coordinator, fields);
195
+ this.schema = schema;
196
196
 
197
+ // create table header row
197
198
  const thead = this.head;
198
199
  thead.innerHTML = '';
199
200
  const tr = document.createElement('tr');
200
- for (const { column } of info) {
201
+ for (const { column } of schema) {
201
202
  const th = document.createElement('th');
202
203
  th.addEventListener('click', evt => this.sort(evt, column));
203
204
  th.appendChild(document.createElement('span'));
@@ -207,16 +208,14 @@ export class Table extends Input {
207
208
  thead.appendChild(tr);
208
209
 
209
210
  // get column formatters
210
- this.formats = formatof(this.format, info);
211
+ this.formats = formatof(this.format, schema);
211
212
 
212
213
  // get column alignment style
213
214
  this.style.innerText = tableCSS(
214
215
  this.id,
215
- alignof(this.align, info),
216
- widthof(this.widths, info)
216
+ alignof(this.align, schema),
217
+ widthof(this.widths, schema)
217
218
  );
218
-
219
- return this;
220
219
  }
221
220
 
222
221
  query(filter = []) {
@@ -1,4 +1,3 @@
1
- import { format as isoformat } from 'isoformat';
2
1
 
3
2
  // Note: use formatAuto (or any other localized format) to present values to the
4
3
  // user; stringify is only intended for machine values.
@@ -48,3 +47,52 @@ export function localize(f) {
48
47
  ? value
49
48
  : (value = f(key = locale));
50
49
  }
50
+
51
+ // Code below modified from https://github.com/mbostock/isoformat/
52
+ // Added here due to longstanding unmerged fixes on original package
53
+ //
54
+ // Copyright 2021 Mike Bostock
55
+ //
56
+ // Permission to use, copy, modify, and/or distribute this software for any purpose
57
+ // with or without fee is hereby granted, provided that the above copyright notice
58
+ // and this permission notice appear in all copies.
59
+ //
60
+ // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
61
+ // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
62
+ // FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
63
+ // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
64
+ // OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65
+ // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
66
+ // THIS SOFTWARE.
67
+
68
+ /**
69
+ * Format a Date in ISO format.
70
+ * @param {Date} date The date to format
71
+ * @param {string | ((date: Date) => string)} fallback Fallback value or function.
72
+ * @returns {string}
73
+ */
74
+ function isoformat(date, fallback) {
75
+ if (!(date instanceof Date)) date = new Date(+date);
76
+ if (isNaN(+date)) return typeof fallback === "function" ? fallback(date) : fallback;
77
+ const hours = date.getUTCHours();
78
+ const minutes = date.getUTCMinutes();
79
+ const seconds = date.getUTCSeconds();
80
+ const milliseconds = date.getUTCMilliseconds();
81
+ return `${formatYear(date.getUTCFullYear())}-${pad(date.getUTCMonth() + 1, 2)}-${pad(date.getUTCDate(), 2)}${
82
+ hours || minutes || seconds || milliseconds ? `T${pad(hours, 2)}:${pad(minutes, 2)}${
83
+ seconds || milliseconds ? `:${pad(seconds, 2)}${
84
+ milliseconds ? `.${pad(milliseconds, 3)}` : ``
85
+ }` : ``
86
+ }Z` : ``
87
+ }`;
88
+ }
89
+
90
+ function formatYear(year) {
91
+ return year < 0 ? `-${pad(-year, 6)}`
92
+ : year > 9999 ? `+${pad(year, 6)}`
93
+ : pad(year, 4);
94
+ }
95
+
96
+ function pad(value, width) {
97
+ return `${value}`.padStart(width, "0");
98
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "include": ["src/**/*.js", "src/**/*.ts"],
3
+ "compilerOptions": {
4
+ "allowJs": true,
5
+ "declaration": true,
6
+ "emitDeclarationOnly": true,
7
+ "outDir": "dist/types",
8
+ "module": "node16",
9
+ "skipLibCheck": true
10
+ }
11
+ }
@@ -1 +0,0 @@
1
- export * from './index.js';