@deephaven/jsapi-components 0.13.7
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 +176 -0
- package/README.md +17 -0
- package/dist/ColumnNameError.d.ts +5 -0
- package/dist/ColumnNameError.d.ts.map +1 -0
- package/dist/ColumnNameError.js +13 -0
- package/dist/ColumnNameError.js.map +1 -0
- package/dist/TableDisconnectError.d.ts +5 -0
- package/dist/TableDisconnectError.d.ts.map +1 -0
- package/dist/TableDisconnectError.js +13 -0
- package/dist/TableDisconnectError.js.map +1 -0
- package/dist/TableInput.css +13 -0
- package/dist/TableInput.css.map +1 -0
- package/dist/TableInput.d.ts +34 -0
- package/dist/TableInput.d.ts.map +1 -0
- package/dist/TableInput.js +233 -0
- package/dist/TableInput.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/useTable.d.ts +8 -0
- package/dist/useTable.d.ts.map +1 -0
- package/dist/useTable.js +67 -0
- package/dist/useTable.js.map +1 -0
- package/dist/useTableColumn.d.ts +16 -0
- package/dist/useTableColumn.d.ts.map +1 -0
- package/dist/useTableColumn.js +27 -0
- package/dist/useTableColumn.js.map +1 -0
- package/dist/useTableListener.d.ts +4 -0
- package/dist/useTableListener.d.ts.map +1 -0
- package/dist/useTableListener.js +14 -0
- package/dist/useTableListener.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @deephaven/jsapi-components
|
|
2
|
+
|
|
3
|
+
This is a component library of Deephaven React components dependent on JSAPI. See [./src/index.ts](./src/index.ts) for a list of components that can be imported into your package.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save @deephaven/jsapi-components
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
import { TableInput } from '@deephaven/jsapi-components';
|
|
15
|
+
|
|
16
|
+
<TableInput table={table} />
|
|
17
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColumnNameError.d.ts","sourceRoot":"","sources":["../src/ColumnNameError.ts"],"names":[],"mappings":"AAAA,cAAM,eAAgB,SAAQ,KAAK;IACjC,iBAAiB,UAAQ;CAC1B;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
class ColumnNameError extends Error {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
|
|
7
|
+
_defineProperty(this, "isColumnNameError", true);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default ColumnNameError;
|
|
13
|
+
//# sourceMappingURL=ColumnNameError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ColumnNameError.ts"],"names":["ColumnNameError","Error"],"mappings":";;AAAA,MAAMA,eAAN,SAA8BC,KAA9B,CAAoC;AAAA;AAAA;;AAAA,+CACd,IADc;AAAA;;AAAA;;AAIpC,eAAeD,eAAf","sourcesContent":["class ColumnNameError extends Error {\n isColumnNameError = true;\n}\n\nexport default ColumnNameError;\n"],"file":"ColumnNameError.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableDisconnectError.d.ts","sourceRoot":"","sources":["../src/TableDisconnectError.ts"],"names":[],"mappings":"AAAA,cAAM,oBAAqB,SAAQ,KAAK;IACtC,sBAAsB,UAAQ;CAC/B;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
class TableDisconnectError extends Error {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
|
|
7
|
+
_defineProperty(this, "isTableDisconnectError", true);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default TableDisconnectError;
|
|
13
|
+
//# sourceMappingURL=TableDisconnectError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/TableDisconnectError.ts"],"names":["TableDisconnectError","Error"],"mappings":";;AAAA,MAAMA,oBAAN,SAAmCC,KAAnC,CAAyC;AAAA;AAAA;;AAAA,oDACd,IADc;AAAA;;AAAA;;AAIzC,eAAeD,oBAAf","sourcesContent":["class TableDisconnectError extends Error {\n isTableDisconnectError = true;\n}\n\nexport default TableDisconnectError;\n"],"file":"TableDisconnectError.js"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
.table-input-container .select-value-list-scroll-pane {
|
|
2
|
+
min-height: 2.4rem;
|
|
3
|
+
max-height: 12rem;
|
|
4
|
+
z-index: 0;
|
|
5
|
+
}
|
|
6
|
+
.table-input-container .meta-row {
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-wrap: wrap;
|
|
9
|
+
justify-content: space-between;
|
|
10
|
+
padding-top: 0.25rem;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/*# sourceMappingURL=TableInput.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sourceRoot":"","sources":["../src/TableInput.scss","../../components/scss/new_variables.scss"],"names":[],"mappings":"AAGE;EACE;EACA;EACA;;AAEF;EACE;EACA;EACA;EACA,aCVO","file":"TableInput.css"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { LongWrapper, Table } from '@deephaven/jsapi-shim';
|
|
3
|
+
import { DecimalColumnFormatterOptions, FormattingRule, IntegerColumnFormatterOptions } from '@deephaven/jsapi-utils';
|
|
4
|
+
import './TableInput.scss';
|
|
5
|
+
declare type Value = LongWrapper | string;
|
|
6
|
+
interface Settings {
|
|
7
|
+
formatter: FormattingRule[];
|
|
8
|
+
timeZone: string;
|
|
9
|
+
defaultDateTimeFormat: string;
|
|
10
|
+
showTimeZone: boolean;
|
|
11
|
+
showTSeparator: boolean;
|
|
12
|
+
defaultDecimalFormatOptions?: DecimalColumnFormatterOptions;
|
|
13
|
+
defaultIntegerFormatOptions?: IntegerColumnFormatterOptions;
|
|
14
|
+
}
|
|
15
|
+
interface TableInputProps {
|
|
16
|
+
className?: string;
|
|
17
|
+
columnName: string;
|
|
18
|
+
settings: Settings;
|
|
19
|
+
defaultValue: Value[];
|
|
20
|
+
isInvalid?: boolean;
|
|
21
|
+
table: Promise<Table>;
|
|
22
|
+
onChange(items: Value[]): void;
|
|
23
|
+
onBlur?: () => void;
|
|
24
|
+
}
|
|
25
|
+
declare function TableInput(props: TableInputProps): JSX.Element;
|
|
26
|
+
declare namespace TableInput {
|
|
27
|
+
var displayName: string;
|
|
28
|
+
var defaultProps: {
|
|
29
|
+
isInvalid: boolean;
|
|
30
|
+
className: undefined;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export default TableInput;
|
|
34
|
+
//# sourceMappingURL=TableInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableInput.d.ts","sourceRoot":"","sources":["../src/TableInput.tsx"],"names":[],"mappings":";AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGhE,OAAO,EACL,6BAA6B,EAG7B,cAAc,EACd,6BAA6B,EAC9B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,mBAAmB,CAAC;AAI3B,aAAK,KAAK,GAAG,WAAW,GAAG,MAAM,CAAC;AAQlC,UAAU,QAAQ;IAChB,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,2BAA2B,CAAC,EAAE,6BAA6B,CAAC;IAC5D,2BAA2B,CAAC,EAAE,6BAA6B,CAAC;CAC7D;AAED,UAAU,eAAe;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE,KAAK,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAID,iBAAS,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,GAAG,CAAC,OAAO,CA+PvD;kBA/PQ,UAAU;;;;;;;AAwQnB,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
2
|
+
|
|
3
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
4
|
+
|
|
5
|
+
import React, { useCallback, useState, useRef, useEffect, useMemo } from 'react';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import { LoadingOverlay, SearchInput, SelectValueList } from '@deephaven/components';
|
|
8
|
+
import { PromiseUtils } from '@deephaven/utils';
|
|
9
|
+
import Log from '@deephaven/log';
|
|
10
|
+
import { Formatter, FormatterUtils } from '@deephaven/jsapi-utils';
|
|
11
|
+
import useTableColumn from "./useTableColumn.js";
|
|
12
|
+
import "./TableInput.css";
|
|
13
|
+
var log = Log.module('TableInput');
|
|
14
|
+
var SIZE_LIMIT = 250;
|
|
15
|
+
|
|
16
|
+
function TableInput(props) {
|
|
17
|
+
var _table$size, _error$message;
|
|
18
|
+
|
|
19
|
+
var {
|
|
20
|
+
className = undefined,
|
|
21
|
+
columnName,
|
|
22
|
+
settings,
|
|
23
|
+
defaultValue = [],
|
|
24
|
+
isInvalid = false,
|
|
25
|
+
onChange = () => false,
|
|
26
|
+
onBlur = () => false,
|
|
27
|
+
table: tablePromise
|
|
28
|
+
} = props;
|
|
29
|
+
var parentRef = useRef(null);
|
|
30
|
+
var formatter = useMemo(() => {
|
|
31
|
+
var columnFormats = FormatterUtils.getColumnFormats(settings);
|
|
32
|
+
var dateTimeFormatterOptions = FormatterUtils.getDateTimeFormatterOptions(settings);
|
|
33
|
+
var {
|
|
34
|
+
defaultDecimalFormatOptions = {},
|
|
35
|
+
defaultIntegerFormatOptions = {}
|
|
36
|
+
} = settings;
|
|
37
|
+
return new Formatter(columnFormats, dateTimeFormatterOptions, defaultDecimalFormatOptions, defaultIntegerFormatOptions);
|
|
38
|
+
}, [settings]);
|
|
39
|
+
var [searchValue, setSearchValue] = useState('');
|
|
40
|
+
var [selection, setSelection] = useState(new Set(defaultValue));
|
|
41
|
+
var [table, setTable] = useState();
|
|
42
|
+
var listRef = useRef(null);
|
|
43
|
+
var itemCount = Math.min((_table$size = table === null || table === void 0 ? void 0 : table.size) !== null && _table$size !== void 0 ? _table$size : 0, SIZE_LIMIT);
|
|
44
|
+
var {
|
|
45
|
+
column,
|
|
46
|
+
data,
|
|
47
|
+
error
|
|
48
|
+
} = useTableColumn(table, 0, SIZE_LIMIT - 1, columnName);
|
|
49
|
+
var formatValue = useCallback(value => column ? formatter.getFormattedString(value, column.type, column.name) : "".concat(value), [column, formatter]);
|
|
50
|
+
var [items, updatedSelection] = useMemo(() => {
|
|
51
|
+
var removedItems = new Set(selection);
|
|
52
|
+
var result = [];
|
|
53
|
+
|
|
54
|
+
if (data == null) {
|
|
55
|
+
// Viewport not initialized
|
|
56
|
+
return [result, null];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
data.forEach(v => {
|
|
60
|
+
var value = "".concat(v);
|
|
61
|
+
var isSelected = selection.has(value);
|
|
62
|
+
|
|
63
|
+
if (isSelected) {
|
|
64
|
+
removedItems.delete(value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
result.push({
|
|
68
|
+
value,
|
|
69
|
+
displayValue: formatValue(v),
|
|
70
|
+
isSelected
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (removedItems.size > 0) {
|
|
75
|
+
log.debug2('Selection has items that are missing from the viewport');
|
|
76
|
+
var newSelection = new Set(selection);
|
|
77
|
+
Array.from(removedItems).forEach(value => {
|
|
78
|
+
newSelection.delete(value);
|
|
79
|
+
});
|
|
80
|
+
return [result, newSelection];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return [result, null];
|
|
84
|
+
}, [data, selection, formatValue]);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (updatedSelection !== null) {
|
|
87
|
+
setSelection(updatedSelection);
|
|
88
|
+
onChange(Array.from(updatedSelection));
|
|
89
|
+
}
|
|
90
|
+
}, [onChange, updatedSelection]);
|
|
91
|
+
var initTable = useCallback( /*#__PURE__*/function () {
|
|
92
|
+
var _ref = _asyncToGenerator(function* (promise) {
|
|
93
|
+
try {
|
|
94
|
+
var resolved = yield promise;
|
|
95
|
+
log.debug('Table resolved', resolved);
|
|
96
|
+
setTable(resolved);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
if (PromiseUtils.isCanceled(e)) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
log.error(e);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return function (_x) {
|
|
107
|
+
return _ref.apply(this, arguments);
|
|
108
|
+
};
|
|
109
|
+
}(), []);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
var cancelablePromise = PromiseUtils.makeCancelable(tablePromise);
|
|
112
|
+
initTable(cancelablePromise);
|
|
113
|
+
return () => {
|
|
114
|
+
log.debug2('Cancel table promise');
|
|
115
|
+
cancelablePromise.cancel();
|
|
116
|
+
};
|
|
117
|
+
}, [tablePromise, initTable]); // Scroll the item matching the input into view
|
|
118
|
+
|
|
119
|
+
var handleSearchChange = useCallback(e => {
|
|
120
|
+
var {
|
|
121
|
+
value
|
|
122
|
+
} = e.target;
|
|
123
|
+
setSearchValue(value);
|
|
124
|
+
var index = items.findIndex(item => item.displayValue.includes(value));
|
|
125
|
+
|
|
126
|
+
if (index > -1) {
|
|
127
|
+
var _listRef$current;
|
|
128
|
+
|
|
129
|
+
log.debug2("Found ".concat(value, " at index ").concat(index));
|
|
130
|
+
(_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.scrollIntoView(index);
|
|
131
|
+
} else {
|
|
132
|
+
log.debug2("".concat(value, " not found"));
|
|
133
|
+
}
|
|
134
|
+
}, [items, listRef]);
|
|
135
|
+
var handleSelect = useCallback(index => {
|
|
136
|
+
log.debug('handleSelect', index);
|
|
137
|
+
|
|
138
|
+
if (index >= items.length) {
|
|
139
|
+
log.error('Invalid index', index);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
var selectedValue = items[index].value;
|
|
144
|
+
var newSelection = new Set(selection);
|
|
145
|
+
|
|
146
|
+
if (items[index].isSelected) {
|
|
147
|
+
newSelection.delete(selectedValue);
|
|
148
|
+
} else {
|
|
149
|
+
newSelection.add(selectedValue);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
setSelection(newSelection);
|
|
153
|
+
onChange(Array.from(newSelection));
|
|
154
|
+
}, [onChange, items, selection]);
|
|
155
|
+
var handleSelectAll = useCallback(() => {
|
|
156
|
+
var values = items.map(item => item.value);
|
|
157
|
+
var newSelection = new Set(values);
|
|
158
|
+
setSelection(newSelection);
|
|
159
|
+
onChange(values);
|
|
160
|
+
}, [items, onChange]);
|
|
161
|
+
var handleClearSelection = useCallback(() => {
|
|
162
|
+
setSelection(new Set());
|
|
163
|
+
onChange([]);
|
|
164
|
+
}, [onChange]);
|
|
165
|
+
var handleViewportChange = useCallback(() => {// no-op
|
|
166
|
+
}, []);
|
|
167
|
+
var handleChildBlur = useCallback(e => {
|
|
168
|
+
var _parentRef$current;
|
|
169
|
+
|
|
170
|
+
var {
|
|
171
|
+
relatedTarget
|
|
172
|
+
} = e;
|
|
173
|
+
log.debug('handleChildBlur', relatedTarget, relatedTarget instanceof HTMLElement, parentRef.current, (_parentRef$current = parentRef.current) === null || _parentRef$current === void 0 ? void 0 : _parentRef$current.contains(relatedTarget));
|
|
174
|
+
|
|
175
|
+
if (!relatedTarget || parentRef.current && relatedTarget instanceof HTMLElement && !parentRef.current.contains(relatedTarget)) {
|
|
176
|
+
onBlur();
|
|
177
|
+
}
|
|
178
|
+
}, [onBlur]);
|
|
179
|
+
var isEmpty = items.length === 0;
|
|
180
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
181
|
+
ref: parentRef,
|
|
182
|
+
className: classNames('table-input-container d-flex flex-column position-relative', className)
|
|
183
|
+
}, /*#__PURE__*/React.createElement(SearchInput, {
|
|
184
|
+
disabled: !!error || isEmpty,
|
|
185
|
+
value: searchValue,
|
|
186
|
+
placeholder: "Search",
|
|
187
|
+
onChange: handleSearchChange,
|
|
188
|
+
className: "mb-2 d-flex",
|
|
189
|
+
onBlur: handleChildBlur
|
|
190
|
+
}), /*#__PURE__*/React.createElement(SelectValueList, {
|
|
191
|
+
className: "table-input-list",
|
|
192
|
+
disabled: table === undefined || isEmpty,
|
|
193
|
+
isInvalid: isInvalid,
|
|
194
|
+
items: isEmpty ? [{
|
|
195
|
+
value: 'Empty',
|
|
196
|
+
isSelected: false
|
|
197
|
+
}] : items,
|
|
198
|
+
itemCount: itemCount,
|
|
199
|
+
offset: 0,
|
|
200
|
+
onSelect: handleSelect,
|
|
201
|
+
onViewportChange: handleViewportChange,
|
|
202
|
+
ref: listRef,
|
|
203
|
+
onBlur: handleChildBlur
|
|
204
|
+
}), table && /*#__PURE__*/React.createElement("div", {
|
|
205
|
+
className: "meta-row"
|
|
206
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
207
|
+
className: "d-flex align-items-center text-muted small"
|
|
208
|
+
}, table && table.size > itemCount && /*#__PURE__*/React.createElement(React.Fragment, null, "Table is too large, showing the first ", SIZE_LIMIT, " items.")), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("button", {
|
|
209
|
+
type: "button",
|
|
210
|
+
className: "btn btn-link",
|
|
211
|
+
onBlur: handleChildBlur,
|
|
212
|
+
onClick: handleSelectAll
|
|
213
|
+
}, "Select All"), /*#__PURE__*/React.createElement("button", {
|
|
214
|
+
type: "button",
|
|
215
|
+
className: "btn btn-link mr-a",
|
|
216
|
+
onBlur: handleChildBlur,
|
|
217
|
+
onClick: handleClearSelection
|
|
218
|
+
}, "Clear"))), !table || error && /*#__PURE__*/React.createElement("div", {
|
|
219
|
+
className: "h-100 w-100 position-absolute"
|
|
220
|
+
}, /*#__PURE__*/React.createElement(LoadingOverlay, {
|
|
221
|
+
isLoaded: !!table,
|
|
222
|
+
isLoading: !table && !error,
|
|
223
|
+
errorMessage: (_error$message = error === null || error === void 0 ? void 0 : error.message) !== null && _error$message !== void 0 ? _error$message : null
|
|
224
|
+
})));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
TableInput.displayName = 'TableInput';
|
|
228
|
+
TableInput.defaultProps = {
|
|
229
|
+
isInvalid: false,
|
|
230
|
+
className: undefined
|
|
231
|
+
};
|
|
232
|
+
export default TableInput;
|
|
233
|
+
//# sourceMappingURL=TableInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/TableInput.tsx"],"names":["React","useCallback","useState","useRef","useEffect","useMemo","classNames","LoadingOverlay","SearchInput","SelectValueList","PromiseUtils","Log","Formatter","FormatterUtils","useTableColumn","log","module","SIZE_LIMIT","TableInput","props","className","undefined","columnName","settings","defaultValue","isInvalid","onChange","onBlur","table","tablePromise","parentRef","formatter","columnFormats","getColumnFormats","dateTimeFormatterOptions","getDateTimeFormatterOptions","defaultDecimalFormatOptions","defaultIntegerFormatOptions","searchValue","setSearchValue","selection","setSelection","Set","setTable","listRef","itemCount","Math","min","size","column","data","error","formatValue","value","getFormattedString","type","name","items","updatedSelection","removedItems","result","forEach","v","isSelected","has","delete","push","displayValue","debug2","newSelection","Array","from","initTable","promise","resolved","debug","e","isCanceled","cancelablePromise","makeCancelable","cancel","handleSearchChange","target","index","findIndex","item","includes","current","scrollIntoView","handleSelect","length","selectedValue","add","handleSelectAll","values","map","handleClearSelection","handleViewportChange","handleChildBlur","relatedTarget","HTMLElement","contains","isEmpty","message","displayName","defaultProps"],"mappings":";;;;AAAA,OAAOA,KAAP,IACEC,WADF,EAEEC,QAFF,EAGEC,MAHF,EAIEC,SAJF,EAKEC,OALF,QAMO,OANP;AAOA,OAAOC,UAAP,MAAuB,YAAvB;AACA,SACEC,cADF,EAEEC,WAFF,EAGEC,eAHF,QAIO,uBAJP;AAMA,SAASC,YAAT,QAA6B,kBAA7B;AACA,OAAOC,GAAP,MAAgB,gBAAhB;AACA,SAEEC,SAFF,EAGEC,cAHF,QAMO,wBANP;OAOOC,c;;AAIP,IAAMC,GAAG,GAAGJ,GAAG,CAACK,MAAJ,CAAW,YAAX,CAAZ;AA+BA,IAAMC,UAAU,GAAG,GAAnB;;AAEA,SAASC,UAAT,CAAoBC,KAApB,EAAyD;AAAA;;AACvD,MAAM;AACJC,IAAAA,SAAS,GAAGC,SADR;AAEJC,IAAAA,UAFI;AAGJC,IAAAA,QAHI;AAIJC,IAAAA,YAAY,GAAG,EAJX;AAKJC,IAAAA,SAAS,GAAG,KALR;AAMJC,IAAAA,QAAQ,GAAG,MAAM,KANb;AAOJC,IAAAA,MAAM,GAAG,MAAM,KAPX;AAQJC,IAAAA,KAAK,EAAEC;AARH,MASFV,KATJ;AAUA,MAAMW,SAAS,GAAG3B,MAAM,CAAiB,IAAjB,CAAxB;AACA,MAAM4B,SAAS,GAAG1B,OAAO,CAAC,MAAM;AAC9B,QAAM2B,aAAa,GAAGnB,cAAc,CAACoB,gBAAf,CAAgCV,QAAhC,CAAtB;AACA,QAA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AAA,YAAY,oBAAEA,KAAF,aAAEA,KAAF,uBAAEA,KAAK,CAAEoD,OAAT,2DAAoB;AAHlC,IADF,CA1DN,CADF;AAqED;;AAEDrF,UAAU,CAACsF,WAAX,GAAyB,YAAzB;AAEAtF,UAAU,CAACuF,YAAX,GAA0B;AACxBhF,EAAAA,SAAS,EAAE,KADa;AAExBL,EAAAA,SAAS,EAAEC;AAFa,CAA1B;AAKA,eAAeH,UAAf","sourcesContent":["import React, {\n useCallback,\n useState,\n useRef,\n useEffect,\n useMemo,\n} from 'react';\nimport classNames from 'classnames';\nimport {\n LoadingOverlay,\n SearchInput,\n SelectValueList,\n} from '@deephaven/components';\nimport type { LongWrapper, Table } from '@deephaven/jsapi-shim';\nimport { PromiseUtils } from '@deephaven/utils';\nimport Log from '@deephaven/log';\nimport {\n DecimalColumnFormatterOptions,\n Formatter,\n FormatterUtils,\n FormattingRule,\n IntegerColumnFormatterOptions,\n} from '@deephaven/jsapi-utils';\nimport useTableColumn from './useTableColumn';\n\nimport './TableInput.scss';\n\nconst log = Log.module('TableInput');\n\ntype Value = LongWrapper | string;\n\ninterface SelectValueItem {\n displayValue: string;\n value: Value;\n isSelected: boolean;\n}\n\ninterface Settings {\n formatter: FormattingRule[];\n timeZone: string;\n defaultDateTimeFormat: string;\n showTimeZone: boolean;\n showTSeparator: boolean;\n defaultDecimalFormatOptions?: DecimalColumnFormatterOptions;\n defaultIntegerFormatOptions?: IntegerColumnFormatterOptions;\n}\n\ninterface TableInputProps {\n className?: string;\n columnName: string;\n settings: Settings;\n defaultValue: Value[];\n isInvalid?: boolean;\n table: Promise<Table>;\n onChange(items: Value[]): void;\n onBlur?: () => void;\n}\n\nconst SIZE_LIMIT = 250;\n\nfunction TableInput(props: TableInputProps): JSX.Element {\n const {\n className = undefined,\n columnName,\n settings,\n defaultValue = [],\n isInvalid = false,\n onChange = () => false,\n onBlur = () => false,\n table: tablePromise,\n } = props;\n const parentRef = useRef<HTMLDivElement>(null);\n const formatter = useMemo(() => {\n const columnFormats = FormatterUtils.getColumnFormats(settings);\n const dateTimeFormatterOptions = FormatterUtils.getDateTimeFormatterOptions(\n settings\n );\n const {\n defaultDecimalFormatOptions = {},\n defaultIntegerFormatOptions = {},\n } = settings;\n return new Formatter(\n columnFormats,\n dateTimeFormatterOptions,\n defaultDecimalFormatOptions,\n defaultIntegerFormatOptions\n );\n }, [settings]);\n const [searchValue, setSearchValue] = useState('');\n const [selection, setSelection] = useState(new Set(defaultValue));\n const [table, setTable] = useState<Table | undefined>();\n const listRef = useRef<SelectValueList<Value>>(null);\n\n const itemCount = Math.min(table?.size ?? 0, SIZE_LIMIT);\n\n const { column, data, error } = useTableColumn(\n table,\n 0,\n SIZE_LIMIT - 1,\n columnName\n );\n\n const formatValue = useCallback(\n value =>\n column\n ? formatter.getFormattedString(value, column.type, column.name)\n : `${value}`,\n [column, formatter]\n );\n\n const [items, updatedSelection] = useMemo(() => {\n const removedItems = new Set(selection);\n const result: SelectValueItem[] = [];\n if (data == null) {\n // Viewport not initialized\n return [result, null];\n }\n (data as Value[]).forEach(v => {\n const value = `${v}`;\n const isSelected = selection.has(value);\n if (isSelected) {\n removedItems.delete(value);\n }\n result.push({\n value,\n displayValue: formatValue(v),\n isSelected,\n });\n });\n\n if (removedItems.size > 0) {\n log.debug2('Selection has items that are missing from the viewport');\n const newSelection = new Set(selection);\n Array.from(removedItems).forEach(value => {\n newSelection.delete(value);\n });\n return [result, newSelection];\n }\n return [result, null];\n }, [data, selection, formatValue]);\n\n useEffect(() => {\n if (updatedSelection !== null) {\n setSelection(updatedSelection);\n onChange(Array.from(updatedSelection));\n }\n }, [onChange, updatedSelection]);\n\n const initTable = useCallback(async promise => {\n try {\n const resolved = await promise;\n log.debug('Table resolved', resolved);\n setTable(resolved);\n } catch (e) {\n if (PromiseUtils.isCanceled(e)) {\n return;\n }\n log.error(e);\n }\n }, []);\n\n useEffect(() => {\n const cancelablePromise = PromiseUtils.makeCancelable(tablePromise);\n initTable(cancelablePromise);\n return () => {\n log.debug2('Cancel table promise');\n cancelablePromise.cancel();\n };\n }, [tablePromise, initTable]);\n\n // Scroll the item matching the input into view\n const handleSearchChange = useCallback(\n e => {\n const { value } = e.target;\n setSearchValue(value);\n const index = items.findIndex(item => item.displayValue.includes(value));\n if (index > -1) {\n log.debug2(`Found ${value} at index ${index}`);\n listRef.current?.scrollIntoView(index);\n } else {\n log.debug2(`${value} not found`);\n }\n },\n [items, listRef]\n );\n\n const handleSelect = useCallback(\n index => {\n log.debug('handleSelect', index);\n if (index >= items.length) {\n log.error('Invalid index', index);\n return;\n }\n const selectedValue = items[index].value;\n const newSelection = new Set(selection);\n if (items[index].isSelected) {\n newSelection.delete(selectedValue);\n } else {\n newSelection.add(selectedValue);\n }\n setSelection(newSelection);\n onChange(Array.from(newSelection));\n },\n [onChange, items, selection]\n );\n\n const handleSelectAll = useCallback(() => {\n const values = items.map(item => item.value);\n const newSelection = new Set(values);\n setSelection(newSelection);\n onChange(values);\n }, [items, onChange]);\n\n const handleClearSelection = useCallback(() => {\n setSelection(new Set());\n onChange([]);\n }, [onChange]);\n\n const handleViewportChange = useCallback(() => {\n // no-op\n }, []);\n\n const handleChildBlur = useCallback(\n (e: React.FocusEvent<Element>) => {\n const { relatedTarget } = e;\n log.debug(\n 'handleChildBlur',\n relatedTarget,\n relatedTarget instanceof HTMLElement,\n parentRef.current,\n parentRef.current?.contains(relatedTarget)\n );\n if (\n !relatedTarget ||\n (parentRef.current &&\n relatedTarget instanceof HTMLElement &&\n !parentRef.current.contains(relatedTarget))\n ) {\n onBlur();\n }\n },\n [onBlur]\n );\n\n const isEmpty = items.length === 0;\n\n return (\n <div\n ref={parentRef}\n className={classNames(\n 'table-input-container d-flex flex-column position-relative',\n className\n )}\n >\n <SearchInput\n disabled={!!error || isEmpty}\n value={searchValue}\n placeholder=\"Search\"\n onChange={handleSearchChange}\n className=\"mb-2 d-flex\"\n onBlur={handleChildBlur}\n />\n <SelectValueList\n className=\"table-input-list\"\n disabled={table === undefined || isEmpty}\n isInvalid={isInvalid}\n items={isEmpty ? [{ value: 'Empty', isSelected: false }] : items}\n itemCount={itemCount}\n offset={0}\n onSelect={handleSelect}\n onViewportChange={handleViewportChange}\n ref={listRef}\n onBlur={handleChildBlur}\n />\n\n {table && (\n <div className=\"meta-row\">\n <div className=\"d-flex align-items-center text-muted small\">\n {table && table.size > itemCount && (\n <>Table is too large, showing the first {SIZE_LIMIT} items.</>\n )}\n </div>\n <div>\n <button\n type=\"button\"\n className=\"btn btn-link\"\n onBlur={handleChildBlur}\n onClick={handleSelectAll}\n >\n Select All\n </button>\n <button\n type=\"button\"\n className=\"btn btn-link mr-a\"\n onBlur={handleChildBlur}\n onClick={handleClearSelection}\n >\n Clear\n </button>\n </div>\n </div>\n )}\n\n {!table ||\n (error && (\n <div className=\"h-100 w-100 position-absolute\">\n <LoadingOverlay\n isLoaded={!!table}\n isLoading={!table && !error}\n errorMessage={error?.message ?? null}\n />\n </div>\n ))}\n </div>\n );\n}\n\nTableInput.displayName = 'TableInput';\n\nTableInput.defaultProps = {\n isInvalid: false,\n className: undefined,\n};\n\nexport default TableInput;\n"],"file":"TableInput.js"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as TableInput } from './TableInput';
|
|
2
|
+
export { default as useTable } from './useTable';
|
|
3
|
+
export { default as useTableColumn } from './useTableColumn';
|
|
4
|
+
export { default as useTableListener } from './useTableListener';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as TableInput } from "./TableInput.js";
|
|
2
|
+
export { default as useTable } from "./useTable.js";
|
|
3
|
+
export { default as useTableColumn } from "./useTableColumn.js";
|
|
4
|
+
export { default as useTableListener } from "./useTableListener.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["default","TableInput","useTable","useTableColumn","useTableListener"],"mappings":"SAASA,OAAO,IAAIC,U;SACXD,OAAO,IAAIE,Q;SACXF,OAAO,IAAIG,c;SACXH,OAAO,IAAII,gB","sourcesContent":["export { default as TableInput } from './TableInput';\nexport { default as useTable } from './useTable';\nexport { default as useTableColumn } from './useTableColumn';\nexport { default as useTableListener } from './useTableListener';\n"],"file":"index.js"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Column, Table } from '@deephaven/jsapi-shim';
|
|
2
|
+
declare const useTable: (table: Table | undefined, firstRow: number, lastRow: number, columnNames?: string[] | undefined) => {
|
|
3
|
+
columns: Column[] | undefined;
|
|
4
|
+
data: unknown[][];
|
|
5
|
+
error: Error | null;
|
|
6
|
+
};
|
|
7
|
+
export default useTable;
|
|
8
|
+
//# sourceMappingURL=useTable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTable.d.ts","sourceRoot":"","sources":["../src/useTable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAQ3D,QAAA,MAAM,QAAQ,UACL,KAAK,GAAG,SAAS,YACd,MAAM,WACP,MAAM;aAGN,MAAM,EAAE,GAAG,SAAS;UACvB,OAAO,EAAE,EAAE;WACV,KAAK,GAAG,IAAI;CA0DpB,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
package/dist/useTable.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import Log from '@deephaven/log';
|
|
3
|
+
import useTableListener from "./useTableListener.js";
|
|
4
|
+
import ColumnNameError from "./ColumnNameError.js";
|
|
5
|
+
import TableDisconnectError from "./TableDisconnectError.js";
|
|
6
|
+
var log = Log.module('useTable');
|
|
7
|
+
|
|
8
|
+
var useTable = (table, firstRow, lastRow, columnNames) => {
|
|
9
|
+
var [columns, setColumns] = useState(undefined);
|
|
10
|
+
var [data, setData] = useState([]);
|
|
11
|
+
var [columnError, setColumnError] = useState(null);
|
|
12
|
+
var [tableError, setTableError] = useState(null);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (columnNames === undefined) {
|
|
15
|
+
setColumns(table === null || table === void 0 ? void 0 : table.columns);
|
|
16
|
+
setColumnError(null);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
setColumns(table === null || table === void 0 ? void 0 : table.findColumns(columnNames));
|
|
22
|
+
setColumnError(null);
|
|
23
|
+
} catch (e) {
|
|
24
|
+
log.error("Column not found", e, columnNames);
|
|
25
|
+
setColumnError(new ColumnNameError('Invalid columnNames argument'));
|
|
26
|
+
}
|
|
27
|
+
}, [table, columnNames]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!columns || !table) {
|
|
30
|
+
log.debug2('Table or column not initialized, skip viewport update.');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
log.debug2('Setting viewport', firstRow, lastRow);
|
|
35
|
+
table.setViewport(firstRow, lastRow, columns);
|
|
36
|
+
}, [columns, table, firstRow, lastRow]);
|
|
37
|
+
var handleUpdate = useCallback(_ref => {
|
|
38
|
+
var {
|
|
39
|
+
detail
|
|
40
|
+
} = _ref;
|
|
41
|
+
|
|
42
|
+
if (!columns) {
|
|
43
|
+
log.error('Columns not initialized.');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var viewportData = columns.map(column => detail.rows.map(r => r.get(column)));
|
|
48
|
+
setData(viewportData);
|
|
49
|
+
}, [columns]);
|
|
50
|
+
var handleDisconnect = useCallback(() => {
|
|
51
|
+
setTableError(new TableDisconnectError('Table disconnected'));
|
|
52
|
+
}, []);
|
|
53
|
+
var handleReconnect = useCallback(() => {
|
|
54
|
+
setTableError(null);
|
|
55
|
+
}, []);
|
|
56
|
+
useTableListener(table, dh.Table.EVENT_UPDATED, handleUpdate);
|
|
57
|
+
useTableListener(table, dh.Table.EVENT_DISCONNECT, handleDisconnect);
|
|
58
|
+
useTableListener(table, dh.Table.EVENT_RECONNECT, handleReconnect);
|
|
59
|
+
return {
|
|
60
|
+
columns,
|
|
61
|
+
data,
|
|
62
|
+
error: tableError !== null && tableError !== void 0 ? tableError : columnError
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default useTable;
|
|
67
|
+
//# sourceMappingURL=useTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useTable.ts"],"names":["useCallback","useEffect","useState","Log","useTableListener","ColumnNameError","TableDisconnectError","log","module","useTable","table","firstRow","lastRow","columnNames","columns","setColumns","undefined","data","setData","columnError","setColumnError","tableError","setTableError","findColumns","e","error","debug2","setViewport","handleUpdate","detail","viewportData","map","column","rows","r","get","handleDisconnect","handleReconnect","dh","Table","EVENT_UPDATED","EVENT_DISCONNECT","EVENT_RECONNECT"],"mappings":"AAAA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,QAAjC,QAAiD,OAAjD;AAEA,OAAOC,GAAP,MAAgB,gBAAhB;OACOC,gB;OACAC,e;OACAC,oB;AAEP,IAAMC,GAAG,GAAGJ,GAAG,CAACK,MAAJ,CAAW,UAAX,CAAZ;;AAEA,IAAMC,QAAQ,GAAG,CACfC,KADe,EAEfC,QAFe,EAGfC,OAHe,EAIfC,WAJe,KASZ;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 'react';\nimport { Column, Row, Table } from '@deephaven/jsapi-shim';\nimport Log from '@deephaven/log';\nimport useTableListener from './useTableListener';\nimport ColumnNameError from './ColumnNameError';\nimport TableDisconnectError from './TableDisconnectError';\n\nconst log = Log.module('useTable');\n\nconst useTable = (\n table: Table | undefined,\n firstRow: number,\n lastRow: number,\n columnNames?: string[]\n): {\n columns: Column[] | undefined;\n data: unknown[][];\n error: Error | null;\n} => {\n const [columns, setColumns] = useState<Column[] | undefined>(undefined);\n const [data, setData] = useState<unknown[][]>([]);\n const [columnError, setColumnError] = useState<Error | null>(null);\n const [tableError, setTableError] = useState<Error | null>(null);\n\n useEffect(() => {\n if (columnNames === undefined) {\n setColumns(table?.columns);\n setColumnError(null);\n return;\n }\n try {\n setColumns(table?.findColumns(columnNames));\n setColumnError(null);\n } catch (e) {\n log.error(`Column not found`, e, columnNames);\n setColumnError(new ColumnNameError('Invalid columnNames argument'));\n }\n }, [table, columnNames]);\n\n useEffect(() => {\n if (!columns || !table) {\n log.debug2('Table or column not initialized, skip viewport update.');\n return;\n }\n log.debug2('Setting viewport', firstRow, lastRow);\n table.setViewport(firstRow, lastRow, columns);\n }, [columns, table, firstRow, lastRow]);\n\n const handleUpdate = useCallback(\n ({ detail }) => {\n if (!columns) {\n log.error('Columns not initialized.');\n return;\n }\n const viewportData = columns.map(column =>\n (detail.rows as Row[]).map(r => r.get(column))\n );\n setData(viewportData);\n },\n [columns]\n );\n\n const handleDisconnect = useCallback(() => {\n setTableError(new TableDisconnectError('Table disconnected'));\n }, []);\n\n const handleReconnect = useCallback(() => {\n setTableError(null);\n }, []);\n\n useTableListener(table, dh.Table.EVENT_UPDATED, handleUpdate);\n useTableListener(table, dh.Table.EVENT_DISCONNECT, handleDisconnect);\n useTableListener(table, dh.Table.EVENT_RECONNECT, handleReconnect);\n\n return { columns, data, error: tableError ?? columnError };\n};\n\nexport default useTable;\n"],"file":"useTable.js"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Column, Table } from '@deephaven/jsapi-shim';
|
|
2
|
+
/**
|
|
3
|
+
* Subscribe to viewport updates on a single table column
|
|
4
|
+
* @param table Table to get the data from
|
|
5
|
+
* @param firstRow First viewport row
|
|
6
|
+
* @param lastRow Last viewport row
|
|
7
|
+
* @param columnName Column to get the data from
|
|
8
|
+
* @returns Column object, data array for the column, error, setViewport method
|
|
9
|
+
*/
|
|
10
|
+
declare const useTableColumn: (table: Table | undefined, firstRow: number, lastRow: number, columnName: string) => {
|
|
11
|
+
column: Column | undefined;
|
|
12
|
+
data: unknown[];
|
|
13
|
+
error: Error | null;
|
|
14
|
+
};
|
|
15
|
+
export default useTableColumn;
|
|
16
|
+
//# sourceMappingURL=useTableColumn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTableColumn.d.ts","sourceRoot":"","sources":["../src/useTableColumn.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGtD;;;;;;;GAOG;AACH,QAAA,MAAM,cAAc,UACX,KAAK,GAAG,SAAS,YACd,MAAM,WACP,MAAM,cACH,MAAM;YAEV,MAAM,GAAG,SAAS;UACpB,OAAO,EAAE;WACR,KAAK,GAAG,IAAI;CAcpB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import useTable from "./useTable.js";
|
|
3
|
+
/**
|
|
4
|
+
* Subscribe to viewport updates on a single table column
|
|
5
|
+
* @param table Table to get the data from
|
|
6
|
+
* @param firstRow First viewport row
|
|
7
|
+
* @param lastRow Last viewport row
|
|
8
|
+
* @param columnName Column to get the data from
|
|
9
|
+
* @returns Column object, data array for the column, error, setViewport method
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var useTableColumn = (table, firstRow, lastRow, columnName) => {
|
|
13
|
+
var columnNames = useMemo(() => [columnName], [columnName]);
|
|
14
|
+
var {
|
|
15
|
+
columns = [],
|
|
16
|
+
data = [],
|
|
17
|
+
error
|
|
18
|
+
} = useTable(table, firstRow, lastRow, columnNames);
|
|
19
|
+
return {
|
|
20
|
+
column: columns[0],
|
|
21
|
+
data: data[0],
|
|
22
|
+
error
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default useTableColumn;
|
|
27
|
+
//# sourceMappingURL=useTableColumn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useTableColumn.ts"],"names":["useMemo","useTable","useTableColumn","table","firstRow","lastRow","columnName","columnNames","columns","data","error","column"],"mappings":"AAAA,SAASA,OAAT,QAAwB,OAAxB;OAEOC,Q;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,cAAc,GAAG,CACrBC,KADqB,EAErBC,QAFqB,EAGrBC,OAHqB,EAIrBC,UAJqB,KASlB;AACH,MAAMC,WAAW,GAAGP,OAAO,CAAC,MAAM,CAACM,UAAD,CAAP,EAAqB,CAACA,UAAD,CAArB,CAA3B;AACA,MAAM;AAAEE,IAAAA,OAAO,GAAG,EAAZ;AAAgBC,IAAAA,IAAI,GAAG,EAAvB;AAA2BC,IAAAA;AAA3B,MAAqCT,QAAQ,CACjDE,KADiD,EAEjDC,QAFiD,EAGjDC,OAHiD,EAIjDE,WAJiD,CAAnD;AAMA,SAAO;AACLI,IAAAA,MAAM,EAAEH,OAAO,CAAC,CAAD,CADV;AAELC,IAAAA,IAAI,EAAEA,IAAI,CAAC,CAAD,CAFL;AAGLC,IAAAA;AAHK,GAAP;AAKD,CAtBD;;AAwBA,eAAeR,cAAf","sourcesContent":["import { useMemo } from 'react';\nimport { Column, Table } from '@deephaven/jsapi-shim';\nimport useTable from './useTable';\n\n/**\n * Subscribe to viewport updates on a single table column\n * @param table Table to get the data from\n * @param firstRow First viewport row\n * @param lastRow Last viewport row\n * @param columnName Column to get the data from\n * @returns Column object, data array for the column, error, setViewport method\n */\nconst useTableColumn = (\n table: Table | undefined,\n firstRow: number,\n lastRow: number,\n columnName: string\n): {\n column: Column | undefined;\n data: unknown[];\n error: Error | null;\n} => {\n const columnNames = useMemo(() => [columnName], [columnName]);\n const { columns = [], data = [], error } = useTable(\n table,\n firstRow,\n lastRow,\n columnNames\n );\n return {\n column: columns[0],\n data: data[0],\n error,\n };\n};\n\nexport default useTableColumn;\n"],"file":"useTableColumn.js"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Evented, EventListener } from '@deephaven/jsapi-shim';
|
|
2
|
+
export declare const useTableListener: (eventEmitter: Evented | undefined, eventName: string, callback: EventListener) => void;
|
|
3
|
+
export default useTableListener;
|
|
4
|
+
//# sourceMappingURL=useTableListener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTableListener.d.ts","sourceRoot":"","sources":["../src/useTableListener.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAK/D,eAAO,MAAM,gBAAgB,iBACb,OAAO,GAAG,SAAS,aACtB,MAAM,YACP,aAAa,KACtB,IAWA,CAAC;AAEJ,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import Log from '@deephaven/log';
|
|
3
|
+
var log = Log.module('useTableListener');
|
|
4
|
+
export var useTableListener = (eventEmitter, eventName, callback) => useEffect(function initEventEmitter() {
|
|
5
|
+
if (eventEmitter === undefined) {
|
|
6
|
+
log.debug2('Emitter undefined, skipping addEventListener', eventName);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
log.debug2('Adding listener', eventName);
|
|
11
|
+
return eventEmitter.addEventListener(eventName, callback);
|
|
12
|
+
}, [eventEmitter, eventName, callback]);
|
|
13
|
+
export default useTableListener;
|
|
14
|
+
//# sourceMappingURL=useTableListener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useTableListener.ts"],"names":["useEffect","Log","log","module","useTableListener","eventEmitter","eventName","callback","initEventEmitter","undefined","debug2","addEventListener"],"mappings":"AAAA,SAASA,SAAT,QAA0B,OAA1B;AAEA,OAAOC,GAAP,MAAgB,gBAAhB;AAEA,IAAMC,GAAG,GAAGD,GAAG,CAACE,MAAJ,CAAW,kBAAX,CAAZ;AAEA,OAAO,IAAMC,gBAAgB,GAAG,CAC9BC,YAD8B,EAE9BC,SAF8B,EAG9BC,QAH8B,KAK9BP,SAAS,CACP,SAASQ,gBAAT,GAA4B;AAC1B,MAAIH,YAAY,KAAKI,SAArB,EAAgC;AAC9BP,IAAAA,GAAG,CAACQ,MAAJ,CAAW,8CAAX,EAA2DJ,SAA3D;AACA;AACD;;AACDJ,EAAAA,GAAG,CAACQ,MAAJ,CAAW,iBAAX,EAA8BJ,SAA9B;AACA,SAAOD,YAAY,CAACM,gBAAb,CAA8BL,SAA9B,EAAyCC,QAAzC,CAAP;AACD,CARM,EASP,CAACF,YAAD,EAAeC,SAAf,EAA0BC,QAA1B,CATO,CALJ;AAiBP,eAAeH,gBAAf","sourcesContent":["import { useEffect } from 'react';\nimport { Evented, EventListener } from '@deephaven/jsapi-shim';\nimport Log from '@deephaven/log';\n\nconst log = Log.module('useTableListener');\n\nexport const useTableListener = (\n eventEmitter: Evented | undefined,\n eventName: string,\n callback: EventListener\n): void =>\n useEffect(\n function initEventEmitter() {\n if (eventEmitter === undefined) {\n log.debug2('Emitter undefined, skipping addEventListener', eventName);\n return;\n }\n log.debug2('Adding listener', eventName);\n return eventEmitter.addEventListener(eventName, callback);\n },\n [eventEmitter, eventName, callback]\n );\n\nexport default useTableListener;\n"],"file":"useTableListener.js"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deephaven/jsapi-components",
|
|
3
|
+
"version": "0.13.7",
|
|
4
|
+
"description": "Deephaven JSAPI Components",
|
|
5
|
+
"author": "Deephaven Data Labs LLC",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/deephaven/web-client-ui.git",
|
|
11
|
+
"directory": "packages/jsapi-components"
|
|
12
|
+
},
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"source": "src/index.ts",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=16"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "cross-env NODE_ENV=production run-p build:*",
|
|
21
|
+
"build-dev": "cross-env NODE_ENV=development run-p build:*",
|
|
22
|
+
"babel": "babel ./src --out-dir ./dist --extensions \".ts,.tsx,.js,.jsx\" --source-maps --root-mode upward",
|
|
23
|
+
"sass": "sass ./src:./dist",
|
|
24
|
+
"build:babel": "npm run babel",
|
|
25
|
+
"build:sass": "npm run sass",
|
|
26
|
+
"watch": "run-p watch:*",
|
|
27
|
+
"watch:babel": "npm run babel -- -w --skip-initial-build",
|
|
28
|
+
"watch:sass": "npm run sass -- --watch --update",
|
|
29
|
+
"prestart": "npm run build-dev",
|
|
30
|
+
"start": "cross-env NODE_ENV=development npm run watch"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@deephaven/components": "^0.13.7",
|
|
34
|
+
"@deephaven/jsapi-shim": "^0.13.0",
|
|
35
|
+
"@deephaven/jsapi-utils": "^0.13.7",
|
|
36
|
+
"@deephaven/log": "^0.13.0",
|
|
37
|
+
"@deephaven/utils": "^0.13.0",
|
|
38
|
+
"classnames": "^2.3.2",
|
|
39
|
+
"prop-types": "^15.8.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@deephaven/tsconfig": "^0.13.0",
|
|
43
|
+
"@testing-library/react-hooks": "^8.0.1",
|
|
44
|
+
"react-test-renderer": "^17.0.2"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": "^17.x"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"gitHead": "0f9ce526883e2d117359ccc232c10aaa09405554"
|
|
56
|
+
}
|