@uwdata/mosaic-inputs 0.12.1 → 0.13.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.
@@ -0,0 +1,79 @@
1
+ export function menu(options?: {
2
+ element?: HTMLElement;
3
+ filterBy?: Selection;
4
+ as?: Param;
5
+ field?: string;
6
+ options?: (any | {
7
+ value: any;
8
+ label?: string;
9
+ })[];
10
+ format?: (value: any) => string;
11
+ value?: any;
12
+ from?: string;
13
+ column?: string;
14
+ label?: string;
15
+ }): HTMLElement;
16
+ /**
17
+ * A HTML <select>-based dropdown menu input.
18
+ * @extends {Input}
19
+ */
20
+ export class Menu extends Input {
21
+ /**
22
+ * Create a new menu input.
23
+ * @param {object} [options] Options object
24
+ * @param {HTMLElement} [options.element] The parent DOM element in which to
25
+ * place the menu elements. If undefined, a new `div` element is created.
26
+ * @param {Selection} [options.filterBy] A selection to filter the database
27
+ * table indicated by the *from* option.
28
+ * @param {Param} [options.as] The output param or selection. A selection
29
+ * clause is added for the currently selected menu option.
30
+ * @param {string} [options.field] The database column name to use within
31
+ * generated selection clause predicates. Defaults to the *column* option.
32
+ * @param {(any | { value: any, label?: string })[]} [options.options] An
33
+ * array of menu options, as literal values or option objects. Option
34
+ * objects have a `value` property and an optional `label` property. If no
35
+ * label or *format* function is provided, the string-coerced value is used.
36
+ * @param {(value: any) => string} [options.format] A format function that
37
+ * takes an option value as input and generates a string label. The format
38
+ * function is not applied when an explicit label is provided in an option
39
+ * object.
40
+ * @param {*} [options.value] The initial selected menu value.
41
+ * @param {string} [options.from] The name of a database table to use as a data
42
+ * source for this widget. Used in conjunction with the *column* option.
43
+ * @param {string} [options.column] The name of a database column from which
44
+ * to pull menu options. The unique column values are used as menu options.
45
+ * Used in conjunction with the *from* option.
46
+ * @param {string} [options.label] A text label for this input.
47
+ */
48
+ constructor({ element, filterBy, as, from, column, label, format, options, value, field }?: {
49
+ element?: HTMLElement;
50
+ filterBy?: Selection;
51
+ as?: Param;
52
+ field?: string;
53
+ options?: (any | {
54
+ value: any;
55
+ label?: string;
56
+ })[];
57
+ format?: (value: any) => string;
58
+ value?: any;
59
+ from?: string;
60
+ column?: string;
61
+ label?: string;
62
+ });
63
+ from: string;
64
+ column: string;
65
+ format: (value: any) => string;
66
+ field: string;
67
+ selection: Param;
68
+ select: HTMLSelectElement;
69
+ data: any[];
70
+ selectedValue(value: any, ...args: any[]): any;
71
+ reset(): void;
72
+ publish(value: any): void;
73
+ query(filter?: any[]): import("@uwdata/mosaic-sql").SelectQuery;
74
+ queryResult(data: any): this;
75
+ update(): this;
76
+ }
77
+ import { Selection } from '@uwdata/mosaic-core';
78
+ import { Param } from '@uwdata/mosaic-core';
79
+ import { Input } from './input.js';
@@ -0,0 +1,69 @@
1
+ export function search(options?: {
2
+ element?: HTMLElement;
3
+ filterBy?: Selection;
4
+ as?: Param;
5
+ field?: string;
6
+ type?: "contains" | "prefix" | "suffix" | "regexp";
7
+ from?: string;
8
+ column?: string;
9
+ label?: string;
10
+ }): HTMLElement;
11
+ /**
12
+ * A HTML text search input.
13
+ * @extends {Input}
14
+ */
15
+ export class Search extends Input {
16
+ /**
17
+ * Create a new text search input.
18
+ * @param {object} [options] Options object
19
+ * @param {HTMLElement} [options.element] The parent DOM element in which to
20
+ * place the search elements. If undefined, a new `div` element is created.
21
+ * @param {Selection} [options.filterBy] A selection to filter the database
22
+ * table indicated by the *from* option.
23
+ * @param {Param} [options.as] The output param or selection. A selection
24
+ * clause is added based on the current text search query.
25
+ * @param {string} [options.field] The database column name to use within
26
+ * generated selection clause predicates. Defaults to the *column* option.
27
+ * @param {'contains' | 'prefix' | 'suffix' | 'regexp'} [options.type] The
28
+ * type of text search query to perform. One of:
29
+ * - `"contains"` (default): the query string may appear anywhere in the text
30
+ * - `"prefix"`: the query string must appear at the start of the text
31
+ * - `"suffix"`: the query string must appear at the end of the text
32
+ * - `"regexp"`: the query string is a regular expression the text must match
33
+ * @param {string} [options.from] The name of a database table to use as an
34
+ * autocomplete data source for this widget. Used in conjunction with the
35
+ * *column* option.
36
+ * @param {string} [options.column] The name of a database column from which
37
+ * to pull valid search results. The unique column values are used as search
38
+ * autocomplete values. Used in conjunction with the *from* option.
39
+ * @param {string} [options.label] A text label for this input.
40
+ */
41
+ constructor({ element, filterBy, from, column, label, type, field, as }?: {
42
+ element?: HTMLElement;
43
+ filterBy?: Selection;
44
+ as?: Param;
45
+ field?: string;
46
+ type?: "contains" | "prefix" | "suffix" | "regexp";
47
+ from?: string;
48
+ column?: string;
49
+ label?: string;
50
+ });
51
+ id: string;
52
+ type: "contains" | "prefix" | "suffix" | "regexp";
53
+ from: string;
54
+ column: string;
55
+ selection: Param;
56
+ field: string;
57
+ searchbox: HTMLInputElement;
58
+ reset(): void;
59
+ clause(value: any): import("@uwdata/mosaic-core").SelectionClause;
60
+ publish(value: any): void;
61
+ query(filter?: any[]): import("@uwdata/mosaic-sql").SelectQuery;
62
+ queryResult(data: any): this;
63
+ data: any;
64
+ update(): this;
65
+ datalist: HTMLDataListElement;
66
+ }
67
+ import { Selection } from '@uwdata/mosaic-core';
68
+ import { Param } from '@uwdata/mosaic-core';
69
+ import { Input } from './input.js';
@@ -0,0 +1,84 @@
1
+ export function slider(options?: {
2
+ element?: HTMLElement;
3
+ filterBy?: Selection;
4
+ as?: Param;
5
+ field?: string;
6
+ select?: "point" | "interval";
7
+ min?: number;
8
+ max?: number;
9
+ step?: number;
10
+ value?: number;
11
+ from?: string;
12
+ column?: string;
13
+ label?: string;
14
+ width?: number;
15
+ }): HTMLElement;
16
+ /**
17
+ * A HTML range-based slider input.
18
+ * @extends {Input}
19
+ */
20
+ export class Slider extends Input {
21
+ /**
22
+ * Create a new slider input.
23
+ * @param {object} [options] Options object
24
+ * @param {HTMLElement} [options.element] The parent DOM element in which to
25
+ * place the slider elements. If undefined, a new `div` element is created.
26
+ * @param {Selection} [options.filterBy] A selection to filter the database
27
+ * table indicated by the *from* option.
28
+ * @param {Param} [options.as] The output param or selection. A selection
29
+ * clause is added based on the currently selected slider option.
30
+ * @param {string} [options.field] The database column name to use within
31
+ * generated selection clause predicates. Defaults to the *column* option.
32
+ * @param {'point' | 'interval'} [options.select] The type of selection clause
33
+ * predicate to generate if the **as** option is a Selection. If `'point'`
34
+ * (the default), the selection predicate is an equality check for the slider
35
+ * value. If `'interval'`, the predicate checks an interval from the minimum
36
+ * to the current slider value.
37
+ * @param {number} [options.min] The minimum slider value.
38
+ * @param {number} [options.max] The maximum slider value.
39
+ * @param {number} [options.step] The slider step, the amount to increment
40
+ * between consecutive values.
41
+ * @param {number} [options.value] The initial slider value.
42
+ * @param {string} [options.from] The name of a database table to use as a data
43
+ * source for this widget. Used in conjunction with the *column* option.
44
+ * The minimum and maximum values of the column determine the slider range.
45
+ * @param {string} [options.column] The name of a database column whose values
46
+ * determine the slider range. Used in conjunction with the *from* option.
47
+ * The minimum and maximum values of the column determine the slider range.
48
+ * @param {string} [options.label] A text label for this input.
49
+ * @param {number} [options.width] The width of the slider in screen pixels.
50
+ */
51
+ constructor({ element, filterBy, as, min, max, step, from, column, label, value, select, field, width }?: {
52
+ element?: HTMLElement;
53
+ filterBy?: Selection;
54
+ as?: Param;
55
+ field?: string;
56
+ select?: "point" | "interval";
57
+ min?: number;
58
+ max?: number;
59
+ step?: number;
60
+ value?: number;
61
+ from?: string;
62
+ column?: string;
63
+ label?: string;
64
+ width?: number;
65
+ });
66
+ id: string;
67
+ from: string;
68
+ column: string;
69
+ selection: Param;
70
+ selectionType: "point" | "interval";
71
+ field: string;
72
+ min: number;
73
+ max: number;
74
+ step: number;
75
+ slider: HTMLInputElement;
76
+ curval: HTMLLabelElement;
77
+ query(filter?: any[]): import("@uwdata/mosaic-sql").SelectQuery;
78
+ queryResult(data: any): this;
79
+ clause(value: any): import("@uwdata/mosaic-core").SelectionClause;
80
+ publish(value: any): void;
81
+ }
82
+ import { Selection } from '@uwdata/mosaic-core';
83
+ import { Param } from '@uwdata/mosaic-core';
84
+ import { Input } from './input.js';
@@ -0,0 +1,116 @@
1
+ export function table(options: {
2
+ element?: HTMLElement;
3
+ filterBy?: Selection;
4
+ as?: Selection;
5
+ align?: {
6
+ [name: string]: "left" | "right" | "center";
7
+ };
8
+ format?: {
9
+ [name: string]: (value: any) => string;
10
+ };
11
+ from?: string;
12
+ columns?: string[];
13
+ width?: number | {
14
+ [name: string]: number;
15
+ };
16
+ maxWidth?: number;
17
+ height?: number;
18
+ rowBatch?: number;
19
+ }): HTMLElement;
20
+ /**
21
+ * A HTML table based table component.
22
+ * @extends {Input}
23
+ */
24
+ export class Table extends Input {
25
+ /**
26
+ * Create a new Table instance.
27
+ * @param {object} options Options object
28
+ * @param {HTMLElement} [options.element] The parent DOM element in which to
29
+ * place the table element. If undefined, a new `div` element is created.
30
+ * @param {Selection} [options.filterBy] A selection to filter the database
31
+ * table indicated by the *from* option.
32
+ * @param {Selection} [options.as] The output selection. A selection
33
+ * clause is added for the currently selected table row.
34
+ * @param {{ [name: string]: 'left' | 'right' | 'center' }} [options.align]
35
+ * An object that maps column names to horiztonal text alignment values. If
36
+ * unspecified, alignment is determined based on the column data type.
37
+ * @param {{ [name: string]: (value: any) => string }} [options.format] An
38
+ * object that maps column names to format functions to use for that
39
+ * column's data. Each format function takes a value as input and generates
40
+ * formatted text to show in the table.
41
+ * @param {string} [options.from] The name of a database table to use as a data
42
+ * source for this widget. Used in conjunction with the *columns* option.
43
+ * @param {string[]} [options.columns] The name of database columns to include
44
+ * in the table component. If unspecified, all columns are included.
45
+ * Used in conjunction with the *from* option.
46
+ * @param {number | { [name: string]: number }} [options.width] If a number,
47
+ * sets the desired width of the table, in pixels. If an object, is used to
48
+ * set explicit pixel widts for each named column included in the object.
49
+ * @param {number} [options.maxWidth] The maximum width of the table, in pixels.
50
+ * @param {number} [options.height] The desired height of the table, in pixels.
51
+ * @param {number} [options.rowBatch] The number of rows to request per query
52
+ * batch. The batch size will be used to prefetch data beyond the currently
53
+ * visible range.
54
+ */
55
+ constructor({ element, filterBy, from, columns, align, format, width, maxWidth, height, rowBatch, as }?: {
56
+ element?: HTMLElement;
57
+ filterBy?: Selection;
58
+ as?: Selection;
59
+ align?: {
60
+ [name: string]: "left" | "right" | "center";
61
+ };
62
+ format?: {
63
+ [name: string]: (value: any) => string;
64
+ };
65
+ from?: string;
66
+ columns?: string[];
67
+ width?: number | {
68
+ [name: string]: number;
69
+ };
70
+ maxWidth?: number;
71
+ height?: number;
72
+ rowBatch?: number;
73
+ });
74
+ id: string;
75
+ from: string;
76
+ columns: string[];
77
+ format: {
78
+ [name: string]: (value: any) => string;
79
+ };
80
+ align: {
81
+ [name: string]: "left" | "right" | "center";
82
+ };
83
+ widths: {
84
+ [name: string]: number;
85
+ };
86
+ offset: number;
87
+ limit: number;
88
+ isPending: boolean;
89
+ selection: Selection;
90
+ currentRow: number;
91
+ sortHeader: any;
92
+ sortColumn: any;
93
+ sortDesc: boolean;
94
+ tbl: HTMLTableElement;
95
+ head: HTMLTableSectionElement;
96
+ body: HTMLTableSectionElement;
97
+ style: HTMLStyleElement;
98
+ sourceTable(): any;
99
+ clause(rows?: any[]): import("@uwdata/mosaic-core").SelectionClause;
100
+ requestData(offset?: number): void;
101
+ fields(): {
102
+ column: string;
103
+ table: any;
104
+ }[];
105
+ fieldInfo(info: any): this;
106
+ schema: any;
107
+ formats: any;
108
+ query(filter?: any[]): import("@uwdata/mosaic-sql").SelectQuery;
109
+ queryResult(data: any): this;
110
+ loaded: boolean;
111
+ data: any[];
112
+ update(): this;
113
+ sort(event: any, column: any): void;
114
+ }
115
+ import { Selection } from '@uwdata/mosaic-core';
116
+ import { Input } from './input.js';
@@ -0,0 +1 @@
1
+ export * from './index.js';
@@ -0,0 +1,4 @@
1
+ export { Menu, menu } from "./Menu.js";
2
+ export { Search, search } from "./Search.js";
3
+ export { Slider, slider } from "./Slider.js";
4
+ export { Table, table } from "./Table.js";
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Instantiate an input, register it with the coordinator, and
3
+ * return the corresponding HTML element.
4
+ * @template {new (...args: any) => Input} T
5
+ * @param {T} InputClass
6
+ * @param {ConstructorParameters<T>} params
7
+ * @returns {HTMLElement} The container element of the input.
8
+ */
9
+ export function input<T extends new (...args: any) => Input>(InputClass: T, ...params: ConstructorParameters<T>): HTMLElement;
10
+ /**
11
+ * Base class for input components.
12
+ * @import {Activatable} from '@uwdata/mosaic-core'
13
+ * @implements {Activatable}
14
+ */
15
+ export class Input extends MosaicClient implements Activatable {
16
+ /**
17
+ * Create a new input instance.
18
+ * @param {import('@uwdata/mosaic-core').Selection} [filterBy] A selection
19
+ * with which to filter backing data that parameterizes this input.
20
+ * @param {HTMLElement} [element] Optional container HTML element to use.
21
+ * @param {string} [className] A class name to set on the container element.
22
+ */
23
+ constructor(filterBy?: import("@uwdata/mosaic-core").Selection, element?: HTMLElement, className?: string);
24
+ element: HTMLElement;
25
+ activate(): void;
26
+ }
27
+ import type { Activatable } from '@uwdata/mosaic-core';
28
+ import { MosaicClient } from '@uwdata/mosaic-core';
@@ -0,0 +1,8 @@
1
+ export function stringify(x: any): string;
2
+ export function formatTrim(value: any): any;
3
+ export function formatDate(date: any): any;
4
+ export function localize(f: any): (locale?: string) => any;
5
+ export function formatLocaleAuto(locale?: string): any;
6
+ export function formatLocaleNumber(locale?: string): any;
7
+ export const formatAuto: any;
8
+ export const formatNumber: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uwdata/mosaic-inputs",
3
- "version": "0.12.1",
3
+ "version": "0.13.0",
4
4
  "description": "Mosaic input components.",
5
5
  "keywords": [
6
6
  "inputs",
@@ -9,25 +9,22 @@
9
9
  "license": "BSD-3-Clause",
10
10
  "author": "Jeffrey Heer (https://idl.uw.edu)",
11
11
  "type": "module",
12
- "main": "src/index.js",
13
- "module": "src/index.js",
14
- "jsdelivr": "dist/mosaic-inputs.min.js",
15
- "unpkg": "dist/mosaic-inputs.min.js",
12
+ "exports": {
13
+ "default": "./src/index.js"
14
+ },
16
15
  "repository": {
17
16
  "type": "git",
18
17
  "url": "https://github.com/uwdata/mosaic.git"
19
18
  },
20
19
  "scripts": {
21
- "prebuild": "rimraf dist && mkdir dist",
22
- "build": "node ../../esbuild.js mosaic-inputs",
23
20
  "lint": "eslint src test",
24
21
  "test": "vitest run",
25
- "prepublishOnly": "npm run test && npm run lint && npm run build"
22
+ "prepublishOnly": "npm run test && npm run lint"
26
23
  },
27
24
  "dependencies": {
28
- "@uwdata/mosaic-core": "^0.12.1",
29
- "@uwdata/mosaic-sql": "^0.12.1",
25
+ "@uwdata/mosaic-core": "^0.13.0",
26
+ "@uwdata/mosaic-sql": "^0.13.0",
30
27
  "isoformat": "^0.2.1"
31
28
  },
32
- "gitHead": "fe3a7c34352da54ec36a1ebf557846f46a649782"
29
+ "gitHead": "b5a0e03e200c0f04c46562a288f084ffc9f6ad55"
33
30
  }
package/src/Menu.js CHANGED
@@ -1,14 +1,46 @@
1
- import { MosaicClient, Param, isParam, isSelection, clausePoint } from '@uwdata/mosaic-core';
1
+ import { Param, Selection, isParam, isSelection, clausePoint } from '@uwdata/mosaic-core';
2
2
  import { Query } from '@uwdata/mosaic-sql';
3
- import { input } from './input.js';
3
+ import { Input, input } from './input.js';
4
4
 
5
5
  const isObject = v => {
6
6
  return v && typeof v === 'object' && !Array.isArray(v);
7
7
  };
8
8
 
9
+ /**
10
+ * Create a new menu input instance.
11
+ * @param {object} [options] Options object
12
+ * @param {HTMLElement} [options.element] The parent DOM element in which to
13
+ * place the menu elements. If undefined, a new `div` element is created.
14
+ * @param {Selection} [options.filterBy] A selection to filter the database
15
+ * table indicated by the *from* option.
16
+ * @param {Param} [options.as] The output param or selection. A selection
17
+ * clause is added for the currently selected menu option.
18
+ * @param {string} [options.field] The database column name to use within
19
+ * generated selection clause predicates. Defaults to the *column* option.
20
+ * @param {(any | { value: any, label?: string })[]} [options.options] An
21
+ * array of menu options, as literal values or option objects. Option
22
+ * objects have a `value` property and an optional `label` property. If no
23
+ * label or *format* function is provided, the string-coerced value is used.
24
+ * @param {(value: any) => string} [options.format] A format function that
25
+ * takes an option value as input and generates a string label. The format
26
+ * function is not applied when an explicit label is provided in an option
27
+ * object.
28
+ * @param {*} [options.value] The initial selected menu value.
29
+ * @param {string} [options.from] The name of a database table to use as a data
30
+ * source for this widget. Used in conjunction with the *column* option.
31
+ * @param {string} [options.column] The name of a database column from which
32
+ * to pull menu options. The unique column values are used as menu options.
33
+ * Used in conjunction with the *from* option.
34
+ * @param {string} [options.label] A text label for this input.
35
+ * @returns {HTMLElement} The container element for a menu input.
36
+ */
9
37
  export const menu = options => input(Menu, options);
10
38
 
11
- export class Menu extends MosaicClient {
39
+ /**
40
+ * A HTML <select>-based dropdown menu input.
41
+ * @extends {Input}
42
+ */
43
+ export class Menu extends Input {
12
44
  /**
13
45
  * Create a new menu input.
14
46
  * @param {object} [options] Options object
@@ -39,26 +71,22 @@ export class Menu extends MosaicClient {
39
71
  constructor({
40
72
  element,
41
73
  filterBy,
74
+ as,
42
75
  from,
43
76
  column,
44
77
  label = column,
45
78
  format = x => x, // TODO
46
79
  options,
47
80
  value,
48
- field = column,
49
- as
81
+ field = column
50
82
  } = {}) {
51
- super(filterBy);
83
+ super(filterBy, element);
52
84
  this.from = from;
53
85
  this.column = column;
54
86
  this.format = format;
55
87
  this.field = field;
56
88
  const selection = this.selection = as;
57
89
 
58
- this.element = element ?? document.createElement('div');
59
- this.element.setAttribute('class', 'input');
60
- Object.defineProperty(this.element, 'value', { value: this });
61
-
62
90
  const lab = document.createElement('label');
63
91
  lab.innerText = label || column;
64
92
  this.element.appendChild(lab);
@@ -68,8 +96,8 @@ export class Menu extends MosaicClient {
68
96
 
69
97
  // if provided, populate menu options
70
98
  if (options) {
71
- this.data = options.map(value => isObject(value) ? value : { value });
72
- this.selectedValue(value ?? '');
99
+ this.data = options.map(opt => isObject(opt) ? opt : { value: opt });
100
+ this.selectedValue(value === undefined ? '' : value);
73
101
  this.update();
74
102
  }
75
103
 
@@ -125,8 +153,9 @@ export class Menu extends MosaicClient {
125
153
  }
126
154
 
127
155
  activate() {
128
- // @ts-ignore - activate is only called for a Selection
129
- this.selection.activate(clausePoint(this.field, 0, { source: this }));
156
+ if (isSelection(this.selection)) {
157
+ this.selection.activate(clausePoint(this.field, 0, { source: this }));
158
+ }
130
159
  }
131
160
 
132
161
  publish(value) {
@@ -174,7 +203,7 @@ export class Menu extends MosaicClient {
174
203
  const value = isSelection(selection)
175
204
  ? selection.valueFor(this)
176
205
  : selection.value;
177
- this.selectedValue(value ?? '');
206
+ this.selectedValue(value === undefined ? '' : value);
178
207
  }
179
208
 
180
209
  return this;
package/src/Search.js CHANGED
@@ -1,12 +1,42 @@
1
- import { MosaicClient, Param, isParam, isSelection, clauseMatch } from '@uwdata/mosaic-core';
1
+ import { Param, Selection, isParam, isSelection, clauseMatch } from '@uwdata/mosaic-core';
2
2
  import { Query } from '@uwdata/mosaic-sql';
3
- import { input } from './input.js';
3
+ import { Input, input } from './input.js';
4
4
 
5
5
  let _id = 0;
6
6
 
7
+ /**
8
+ * Create a new text search input instance.
9
+ * @param {object} [options] Options object
10
+ * @param {HTMLElement} [options.element] The parent DOM element in which to
11
+ * place the search elements. If undefined, a new `div` element is created.
12
+ * @param {Selection} [options.filterBy] A selection to filter the database
13
+ * table indicated by the *from* option.
14
+ * @param {Param} [options.as] The output param or selection. A selection
15
+ * clause is added based on the current text search query.
16
+ * @param {string} [options.field] The database column name to use within
17
+ * generated selection clause predicates. Defaults to the *column* option.
18
+ * @param {'contains' | 'prefix' | 'suffix' | 'regexp'} [options.type] The
19
+ * type of text search query to perform. One of:
20
+ * - `"contains"` (default): the query string may appear anywhere in the text
21
+ * - `"prefix"`: the query string must appear at the start of the text
22
+ * - `"suffix"`: the query string must appear at the end of the text
23
+ * - `"regexp"`: the query string is a regular expression the text must match
24
+ * @param {string} [options.from] The name of a database table to use as an
25
+ * autocomplete data source for this widget. Used in conjunction with the
26
+ * *column* option.
27
+ * @param {string} [options.column] The name of a database column from which
28
+ * to pull valid search results. The unique column values are used as search
29
+ * autocomplete values. Used in conjunction with the *from* option.
30
+ * @param {string} [options.label] A text label for this input.
31
+ * @returns {HTMLElement} The container element for a text search input.
32
+ */
7
33
  export const search = options => input(Search, options);
8
34
 
9
- export class Search extends MosaicClient {
35
+ /**
36
+ * A HTML text search input.
37
+ * @extends {Input}
38
+ */
39
+ export class Search extends Input {
10
40
  /**
11
41
  * Create a new text search input.
12
42
  * @param {object} [options] Options object
@@ -42,7 +72,7 @@ export class Search extends MosaicClient {
42
72
  field = column,
43
73
  as
44
74
  } = {}) {
45
- super(filterBy);
75
+ super(filterBy, element);
46
76
  this.id = 'search_' + (++_id);
47
77
  this.type = type;
48
78
  this.from = from;
@@ -50,10 +80,6 @@ export class Search extends MosaicClient {
50
80
  this.selection = as;
51
81
  this.field = field;
52
82
 
53
- this.element = element ?? document.createElement('div');
54
- this.element.setAttribute('class', 'input');
55
- Object.defineProperty(this.element, 'value', { value: this });
56
-
57
83
  if (label) {
58
84
  const lab = document.createElement('label');
59
85
  lab.setAttribute('for', this.id);
@@ -97,8 +123,9 @@ export class Search extends MosaicClient {
97
123
  }
98
124
 
99
125
  activate() {
100
- // @ts-ignore - activate is only called for a Selection
101
- this.selection.activate(this.clause(''));
126
+ if (isSelection(this.selection)) {
127
+ this.selection.activate(this.clause(''));
128
+ }
102
129
  }
103
130
 
104
131
  publish(value) {