@mosaicajs/react 0.1.0-rc.4
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 +202 -0
- package/README.md +22 -0
- package/dist/components.d.ts +449 -0
- package/dist/components.js +175 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +50 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @mosaicajs/react
|
|
2
|
+
|
|
3
|
+
React bindings for [Mosaica](https://github.com/mosaicadb/mosaica), which serves an interactive map over billions of points from one machine, with every count, cluster and sample computed over what the signed-in viewer may see. `useMosaicaStore` and `useProjection` hold a [`@mosaicajs/client`](https://www.npmjs.com/package/@mosaicajs/client) store in a component. `@mosaicajs/react/components` wraps each `mosaica-*` element of [`@mosaicajs/components`](https://www.npmjs.com/package/@mosaicajs/components) as a React component; it needs `@mosaicajs/components` and `@lit/react`, which the hooks alone do not.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @mosaicajs/react @mosaicajs/components @lit/react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import {useMosaicaStore, useProjection} from '@mosaicajs/react';
|
|
11
|
+
import {MosaicaExplorer} from '@mosaicajs/react/components';
|
|
12
|
+
|
|
13
|
+
function Map({authorise}: {authorise: () => Promise<{token: string; expiresAt: number}>}) {
|
|
14
|
+
// `authorise` asks your own server for a viewer token, and is called again to renew it.
|
|
15
|
+
const store = useMosaicaStore({viewerUrl: 'http://localhost:8080', authorise});
|
|
16
|
+
const status = useProjection(store, 'status');
|
|
17
|
+
if (!store) return null;
|
|
18
|
+
return <MosaicaExplorer store={store} title={status?.status} />;
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Documentation: [TypeScript client reference](https://github.com/mosaicadb/mosaica/blob/main/docs/reference/typescript.md). Licence: Apache-2.0.
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every `mosaica-*` element as a React component with typed props and event handlers, made with
|
|
3
|
+
* `@lit/react`. `MosaicaMap` wraps `<mosaica-map>`, and so on. A prop that names an element
|
|
4
|
+
* property is set as that property, so an object such as `store` reaches the element under React
|
|
5
|
+
* 18, which sets a custom element's props as attributes. Each element's events are handler props, such as `onPick` for
|
|
6
|
+
* `mosaica-pick`. The element classes are exported as types with an `Element` suffix, such as
|
|
7
|
+
* `MapElement`, for typing a ref. Each element's attributes, properties, events, slots and parts
|
|
8
|
+
* are on its page in the Components reference, which each wrapper's type links to.
|
|
9
|
+
*
|
|
10
|
+
* `MosaicaStore`, `MosaicaMap` and `MosaicaExplorer` read their `authorise` prop through a ref, so
|
|
11
|
+
* an inline function does not build a new store on every render. To show the map to another
|
|
12
|
+
* viewer, change `token` or `viewerUrl`, or give the component a new `key`.
|
|
13
|
+
*
|
|
14
|
+
* This entry imports `@mosaicajs/components`, and with it Lit and deck.gl. The hooks are in the
|
|
15
|
+
* package root, `@mosaicajs/react`, which imports neither.
|
|
16
|
+
*
|
|
17
|
+
* @module @mosaicajs/react/components
|
|
18
|
+
*/
|
|
19
|
+
import { type EventName } from '@lit/react';
|
|
20
|
+
import { MosaicaArtifactCard as ArtifactCardElement, MosaicaClusterFilter as ClusterFilterElement, MosaicaColourEditor as ColourEditorElement, MosaicaCount as CountElement, MosaicaExplorer as ExplorerElement, MosaicaFieldCard as FieldCardElement, MosaicaFilter as FilterElement, MosaicaFilterPanel as FilterPanelElement, MosaicaHierarchy as HierarchyElement, MosaicaItemCard as ItemCardElement, MosaicaKeyPicker as KeyPickerElement, MosaicaLayerPicker as LayerPickerElement, MosaicaMap as MapElement, MosaicaSelection as SelectionElement, MosaicaStatus as StatusElement, MosaicaStore as StoreElement, MosaicaViewPicker as ViewPickerElement, type MosaicaEventMap } from '@mosaicajs/components';
|
|
21
|
+
/**
|
|
22
|
+
* The events the elements emit, by name, each a `CustomEvent` with its detail: `MosaicaEventMap`
|
|
23
|
+
* from `@mosaicajs/components`.
|
|
24
|
+
*/
|
|
25
|
+
export type MosaicaEvents = MosaicaEventMap;
|
|
26
|
+
/** `<mosaica-store>` as a React component. It has no event props. */
|
|
27
|
+
export declare const MosaicaStore: import("@lit/react").ReactWebComponent<StoreElement, {}>;
|
|
28
|
+
/**
|
|
29
|
+
* `<mosaica-explorer>` as a React component. It has a handler prop for every event, since the
|
|
30
|
+
* elements inside it emit them and each event bubbles out of it: `onPick`, `onItemOpen`, `onMiss`, `onHover`,
|
|
31
|
+
* `onViewChange`, `onSelectChange`, `onArtifactOpen`, `onLayerChange`, `onArtifactFit`,
|
|
32
|
+
* `onColourChange`, `onLevelChange`, `onValueColour`, `onClusterColour`, `onPaletteChange`, `onClusterPaletteChange`,
|
|
33
|
+
* `onDisplayChange`, `onSizeChange`, `onBudgetChange`, `onClusterBudgetChange`, `onFold`,
|
|
34
|
+
* `onFilterChange`, `onStateChange`, `onExpired`, `onOpen`, `onClose`, `onClauseChange`,
|
|
35
|
+
* `onViewSwitch` and `onViewFollow`, each for the `mosaica-` event of the same name in lower case.
|
|
36
|
+
* The `open` prop is the function the item card's Open calls, and `openUrl` the address it goes
|
|
37
|
+
* to; `onOpen` hears every press.
|
|
38
|
+
*/
|
|
39
|
+
export declare const MosaicaExplorer: import("@lit/react").ReactWebComponent<ExplorerElement, {
|
|
40
|
+
onArtifactFit: EventName<CustomEvent<{
|
|
41
|
+
id: string;
|
|
42
|
+
}>>;
|
|
43
|
+
onColourChange: EventName<CustomEvent<{
|
|
44
|
+
colourBy: string | null;
|
|
45
|
+
}>>;
|
|
46
|
+
onLevelChange: EventName<CustomEvent<{
|
|
47
|
+
level: number | null;
|
|
48
|
+
}>>;
|
|
49
|
+
onValueColour: EventName<CustomEvent<{
|
|
50
|
+
column: string;
|
|
51
|
+
changes: {
|
|
52
|
+
value: string;
|
|
53
|
+
colour: string | null;
|
|
54
|
+
}[];
|
|
55
|
+
}>>;
|
|
56
|
+
onClusterColour: EventName<CustomEvent<{
|
|
57
|
+
layer: string;
|
|
58
|
+
changes: {
|
|
59
|
+
mosaicaId: string;
|
|
60
|
+
colour: string | null;
|
|
61
|
+
}[];
|
|
62
|
+
}>>;
|
|
63
|
+
onPaletteChange: EventName<CustomEvent<{
|
|
64
|
+
palette: import("@mosaicajs/deck").CategoryPaletteName;
|
|
65
|
+
ramp: import("@mosaicajs/deck").RampName;
|
|
66
|
+
scale: import("@mosaicajs/deck").RampScale;
|
|
67
|
+
reverse: boolean;
|
|
68
|
+
}>>;
|
|
69
|
+
onClusterPaletteChange: EventName<CustomEvent<{
|
|
70
|
+
palette: import("@mosaicajs/client").PaletteName;
|
|
71
|
+
}>>;
|
|
72
|
+
onDisplayChange: EventName<CustomEvent<{
|
|
73
|
+
points: boolean;
|
|
74
|
+
radius: number | null;
|
|
75
|
+
pointOpacity: number | null;
|
|
76
|
+
density: import("@mosaicajs/deck").DensityMode;
|
|
77
|
+
densityColours: import("@mosaicajs/deck").DensityColours | null;
|
|
78
|
+
densityStrength: number;
|
|
79
|
+
densityResolution: number;
|
|
80
|
+
densityScale: import("@mosaicajs/deck").DensityScale;
|
|
81
|
+
}>>;
|
|
82
|
+
onSizeChange: EventName<CustomEvent<{
|
|
83
|
+
sizeBy: string | null;
|
|
84
|
+
min: number;
|
|
85
|
+
max: number;
|
|
86
|
+
scale: import("@mosaicajs/deck").SizeScale;
|
|
87
|
+
}>>;
|
|
88
|
+
onBudgetChange: EventName<CustomEvent<{
|
|
89
|
+
budget: number;
|
|
90
|
+
}>>;
|
|
91
|
+
onClusterBudgetChange: EventName<CustomEvent<{
|
|
92
|
+
budget: number;
|
|
93
|
+
}>>;
|
|
94
|
+
onFold: EventName<CustomEvent<{
|
|
95
|
+
field: string;
|
|
96
|
+
folded: boolean;
|
|
97
|
+
}>>;
|
|
98
|
+
onFilterChange: EventName<CustomEvent<{
|
|
99
|
+
column: string | null;
|
|
100
|
+
expr?: import("@mosaicajs/client").FilterExpr | null;
|
|
101
|
+
verb?: import("@mosaicajs/client").ClauseVerb;
|
|
102
|
+
}>>;
|
|
103
|
+
onStateChange: EventName<CustomEvent<{
|
|
104
|
+
from: import("@mosaicajs/components").PanelState | null;
|
|
105
|
+
to: import("@mosaicajs/components").PanelState;
|
|
106
|
+
refusal: import("@mosaicajs/client").Refusal | null;
|
|
107
|
+
}>>;
|
|
108
|
+
onExpired: EventName<CustomEvent<{
|
|
109
|
+
refusal: import("@mosaicajs/client").Refusal | null;
|
|
110
|
+
}>>;
|
|
111
|
+
onOpen: EventName<CustomEvent<{
|
|
112
|
+
id: string;
|
|
113
|
+
fields: Record<string, unknown>;
|
|
114
|
+
}>>;
|
|
115
|
+
onClose: EventName<CustomEvent<{
|
|
116
|
+
what: "item" | "artifact";
|
|
117
|
+
}>>;
|
|
118
|
+
onClauseChange: EventName<CustomEvent<{
|
|
119
|
+
id: string;
|
|
120
|
+
layer: string;
|
|
121
|
+
outside: boolean;
|
|
122
|
+
verb: import("@mosaicajs/client").ClauseVerb;
|
|
123
|
+
on: boolean;
|
|
124
|
+
}>>;
|
|
125
|
+
onViewSwitch: EventName<CustomEvent<{
|
|
126
|
+
from: string;
|
|
127
|
+
to: string;
|
|
128
|
+
sameFrame: boolean;
|
|
129
|
+
}>>;
|
|
130
|
+
onViewFollow: EventName<CustomEvent<{
|
|
131
|
+
view: string;
|
|
132
|
+
x: number;
|
|
133
|
+
y: number;
|
|
134
|
+
}>>;
|
|
135
|
+
onPick: EventName<CustomEvent<{
|
|
136
|
+
id: string;
|
|
137
|
+
}>>;
|
|
138
|
+
onItemOpen: EventName<CustomEvent<{
|
|
139
|
+
id: string;
|
|
140
|
+
record: import("@mosaicajs/client").ItemDetail;
|
|
141
|
+
}>>;
|
|
142
|
+
onMiss: EventName<CustomEvent<Record<string, never>>>;
|
|
143
|
+
onHover: EventName<CustomEvent<{
|
|
144
|
+
id: string;
|
|
145
|
+
x: number;
|
|
146
|
+
y: number;
|
|
147
|
+
}>>;
|
|
148
|
+
onViewChange: EventName<CustomEvent<{
|
|
149
|
+
bbox: [number, number, number, number];
|
|
150
|
+
zoom: number;
|
|
151
|
+
width: number;
|
|
152
|
+
height: number;
|
|
153
|
+
}>>;
|
|
154
|
+
onSelectChange: EventName<CustomEvent<{
|
|
155
|
+
shape: import("@mosaicajs/components").SelectionShapeDetail | null;
|
|
156
|
+
status?: import("@mosaicajs/client").RegionProjection["status"] | "cleared";
|
|
157
|
+
visible?: import("@mosaicajs/client").Masked | null;
|
|
158
|
+
matched?: import("@mosaicajs/client").Masked;
|
|
159
|
+
served?: import("@mosaicajs/client").Count;
|
|
160
|
+
verdict?: import("@mosaicajs/client").RegionProjection["verdict"];
|
|
161
|
+
}>>;
|
|
162
|
+
onArtifactOpen: EventName<CustomEvent<{
|
|
163
|
+
id: string;
|
|
164
|
+
detail: Omit<import("@mosaicajs/client").ArtifactDetail, "maskedCount"> & {
|
|
165
|
+
maskedCount: string;
|
|
166
|
+
};
|
|
167
|
+
}>>;
|
|
168
|
+
onLayerChange: EventName<CustomEvent<{
|
|
169
|
+
layers: string[];
|
|
170
|
+
}>>;
|
|
171
|
+
}>;
|
|
172
|
+
/**
|
|
173
|
+
* `<mosaica-map>` as a React component. Event props: `onPick` (`mosaica-pick`), `onItemOpen`
|
|
174
|
+
* (`mosaica-itemopen`), `onMiss`
|
|
175
|
+
* (`mosaica-miss`), `onHover` (`mosaica-hover`), `onViewChange` (`mosaica-viewchange`), `onSelectChange`
|
|
176
|
+
* (`mosaica-selectchange`), `onArtifactOpen` (`mosaica-artifactopen`) and `onLayerChange`
|
|
177
|
+
* (`mosaica-layerchange`).
|
|
178
|
+
*/
|
|
179
|
+
export declare const MosaicaMap: import("@lit/react").ReactWebComponent<MapElement, {
|
|
180
|
+
onPick: EventName<CustomEvent<{
|
|
181
|
+
id: string;
|
|
182
|
+
}>>;
|
|
183
|
+
onItemOpen: EventName<CustomEvent<{
|
|
184
|
+
id: string;
|
|
185
|
+
record: import("@mosaicajs/client").ItemDetail;
|
|
186
|
+
}>>;
|
|
187
|
+
onMiss: EventName<CustomEvent<Record<string, never>>>;
|
|
188
|
+
onHover: EventName<CustomEvent<{
|
|
189
|
+
id: string;
|
|
190
|
+
x: number;
|
|
191
|
+
y: number;
|
|
192
|
+
}>>;
|
|
193
|
+
onViewChange: EventName<CustomEvent<{
|
|
194
|
+
bbox: [number, number, number, number];
|
|
195
|
+
zoom: number;
|
|
196
|
+
width: number;
|
|
197
|
+
height: number;
|
|
198
|
+
}>>;
|
|
199
|
+
onSelectChange: EventName<CustomEvent<{
|
|
200
|
+
shape: import("@mosaicajs/components").SelectionShapeDetail | null;
|
|
201
|
+
status?: import("@mosaicajs/client").RegionProjection["status"] | "cleared";
|
|
202
|
+
visible?: import("@mosaicajs/client").Masked | null;
|
|
203
|
+
matched?: import("@mosaicajs/client").Masked;
|
|
204
|
+
served?: import("@mosaicajs/client").Count;
|
|
205
|
+
verdict?: import("@mosaicajs/client").RegionProjection["verdict"];
|
|
206
|
+
}>>;
|
|
207
|
+
onArtifactOpen: EventName<CustomEvent<{
|
|
208
|
+
id: string;
|
|
209
|
+
detail: Omit<import("@mosaicajs/client").ArtifactDetail, "maskedCount"> & {
|
|
210
|
+
maskedCount: string;
|
|
211
|
+
};
|
|
212
|
+
}>>;
|
|
213
|
+
onLayerChange: EventName<CustomEvent<{
|
|
214
|
+
layers: string[];
|
|
215
|
+
}>>;
|
|
216
|
+
}>;
|
|
217
|
+
/** `<mosaica-status>` as a React component. Event props: `onStateChange` (`mosaica-statechange`) and `onExpired` (`mosaica-expired`). */
|
|
218
|
+
export declare const MosaicaStatus: import("@lit/react").ReactWebComponent<StatusElement, {
|
|
219
|
+
onStateChange: EventName<CustomEvent<{
|
|
220
|
+
from: import("@mosaicajs/components").PanelState | null;
|
|
221
|
+
to: import("@mosaicajs/components").PanelState;
|
|
222
|
+
refusal: import("@mosaicajs/client").Refusal | null;
|
|
223
|
+
}>>;
|
|
224
|
+
onExpired: EventName<CustomEvent<{
|
|
225
|
+
refusal: import("@mosaicajs/client").Refusal | null;
|
|
226
|
+
}>>;
|
|
227
|
+
}>;
|
|
228
|
+
/** `<mosaica-count>` as a React component. It has no event props. */
|
|
229
|
+
export declare const MosaicaCount: import("@lit/react").ReactWebComponent<CountElement, {}>;
|
|
230
|
+
/**
|
|
231
|
+
* `<mosaica-item-card>` as a React component. Event props: `onOpen` (`mosaica-open`), `onClose`
|
|
232
|
+
* (`mosaica-close`) and `onViewFollow` (`mosaica-viewfollow`). The `open` prop is the function
|
|
233
|
+
* Open calls, and `openUrl` the address it goes to; `onOpen` hears every press.
|
|
234
|
+
*/
|
|
235
|
+
export declare const MosaicaItemCard: import("@lit/react").ReactWebComponent<ItemCardElement, {
|
|
236
|
+
onOpen: EventName<CustomEvent<{
|
|
237
|
+
id: string;
|
|
238
|
+
fields: Record<string, unknown>;
|
|
239
|
+
}>>;
|
|
240
|
+
onClose: EventName<CustomEvent<{
|
|
241
|
+
what: "item" | "artifact";
|
|
242
|
+
}>>;
|
|
243
|
+
onViewFollow: EventName<CustomEvent<{
|
|
244
|
+
view: string;
|
|
245
|
+
x: number;
|
|
246
|
+
y: number;
|
|
247
|
+
}>>;
|
|
248
|
+
}>;
|
|
249
|
+
/**
|
|
250
|
+
* `<mosaica-filter-panel>` as a React component. Event props: `onFilterChange`
|
|
251
|
+
* (`mosaica-filterchange`), `onChipOpen` (`mosaica-chipopen`), and from its cards
|
|
252
|
+
* `onClauseChange` (`mosaica-clausechange`), `onColourChange` (`mosaica-colourchange`),
|
|
253
|
+
* `onLevelChange` (`mosaica-levelchange`), `onValueColour` (`mosaica-valuecolour`),
|
|
254
|
+
* `onClusterColour` (`mosaica-clustercolour`) and `onFold` (`mosaica-fold`).
|
|
255
|
+
*/
|
|
256
|
+
export declare const MosaicaFilterPanel: import("@lit/react").ReactWebComponent<FilterPanelElement, {
|
|
257
|
+
onFilterChange: EventName<CustomEvent<{
|
|
258
|
+
column: string | null;
|
|
259
|
+
expr?: import("@mosaicajs/client").FilterExpr | null;
|
|
260
|
+
verb?: import("@mosaicajs/client").ClauseVerb;
|
|
261
|
+
}>>;
|
|
262
|
+
onChipOpen: EventName<CustomEvent<{
|
|
263
|
+
column: string;
|
|
264
|
+
verb: import("@mosaicajs/client").ClauseVerb;
|
|
265
|
+
}>>;
|
|
266
|
+
onClauseChange: EventName<CustomEvent<{
|
|
267
|
+
id: string;
|
|
268
|
+
layer: string;
|
|
269
|
+
outside: boolean;
|
|
270
|
+
verb: import("@mosaicajs/client").ClauseVerb;
|
|
271
|
+
on: boolean;
|
|
272
|
+
}>>;
|
|
273
|
+
onColourChange: EventName<CustomEvent<{
|
|
274
|
+
colourBy: string | null;
|
|
275
|
+
}>>;
|
|
276
|
+
onLevelChange: EventName<CustomEvent<{
|
|
277
|
+
level: number | null;
|
|
278
|
+
}>>;
|
|
279
|
+
onValueColour: EventName<CustomEvent<{
|
|
280
|
+
column: string;
|
|
281
|
+
changes: {
|
|
282
|
+
value: string;
|
|
283
|
+
colour: string | null;
|
|
284
|
+
}[];
|
|
285
|
+
}>>;
|
|
286
|
+
onClusterColour: EventName<CustomEvent<{
|
|
287
|
+
layer: string;
|
|
288
|
+
changes: {
|
|
289
|
+
mosaicaId: string;
|
|
290
|
+
colour: string | null;
|
|
291
|
+
}[];
|
|
292
|
+
}>>;
|
|
293
|
+
onFold: EventName<CustomEvent<{
|
|
294
|
+
field: string;
|
|
295
|
+
folded: boolean;
|
|
296
|
+
}>>;
|
|
297
|
+
}>;
|
|
298
|
+
/** `<mosaica-filter>` as a React component. Event prop: `onFilterChange` (`mosaica-filterchange`). */
|
|
299
|
+
export declare const MosaicaFilter: import("@lit/react").ReactWebComponent<FilterElement, {
|
|
300
|
+
onFilterChange: EventName<CustomEvent<{
|
|
301
|
+
column: string | null;
|
|
302
|
+
expr?: import("@mosaicajs/client").FilterExpr | null;
|
|
303
|
+
verb?: import("@mosaicajs/client").ClauseVerb;
|
|
304
|
+
}>>;
|
|
305
|
+
}>;
|
|
306
|
+
/** `<mosaica-cluster-filter>` as a React component. Event prop: `onClauseChange` (`mosaica-clausechange`). */
|
|
307
|
+
export declare const MosaicaClusterFilter: import("@lit/react").ReactWebComponent<ClusterFilterElement, {
|
|
308
|
+
onClauseChange: EventName<CustomEvent<{
|
|
309
|
+
id: string;
|
|
310
|
+
layer: string;
|
|
311
|
+
outside: boolean;
|
|
312
|
+
verb: import("@mosaicajs/client").ClauseVerb;
|
|
313
|
+
on: boolean;
|
|
314
|
+
}>>;
|
|
315
|
+
}>;
|
|
316
|
+
/** `<mosaica-selection>` as a React component. Event prop: `onSelectChange` (`mosaica-selectchange`). */
|
|
317
|
+
export declare const MosaicaSelection: import("@lit/react").ReactWebComponent<SelectionElement, {
|
|
318
|
+
onSelectChange: EventName<CustomEvent<{
|
|
319
|
+
shape: import("@mosaicajs/components").SelectionShapeDetail | null;
|
|
320
|
+
status?: import("@mosaicajs/client").RegionProjection["status"] | "cleared";
|
|
321
|
+
visible?: import("@mosaicajs/client").Masked | null;
|
|
322
|
+
matched?: import("@mosaicajs/client").Masked;
|
|
323
|
+
served?: import("@mosaicajs/client").Count;
|
|
324
|
+
verdict?: import("@mosaicajs/client").RegionProjection["verdict"];
|
|
325
|
+
}>>;
|
|
326
|
+
}>;
|
|
327
|
+
/** `<mosaica-layer-picker>` as a React component. Event prop: `onLayerChange` (`mosaica-layerchange`). */
|
|
328
|
+
export declare const MosaicaLayerPicker: import("@lit/react").ReactWebComponent<LayerPickerElement, {
|
|
329
|
+
onLayerChange: EventName<CustomEvent<{
|
|
330
|
+
layers: string[];
|
|
331
|
+
}>>;
|
|
332
|
+
}>;
|
|
333
|
+
/** `<mosaica-view-picker>` as a React component. Event prop: `onViewSwitch` (`mosaica-viewswitch`). */
|
|
334
|
+
export declare const MosaicaViewPicker: import("@lit/react").ReactWebComponent<ViewPickerElement, {
|
|
335
|
+
onViewSwitch: EventName<CustomEvent<{
|
|
336
|
+
from: string;
|
|
337
|
+
to: string;
|
|
338
|
+
sameFrame: boolean;
|
|
339
|
+
}>>;
|
|
340
|
+
}>;
|
|
341
|
+
/** `<mosaica-key-picker>` as a React component. Event prop: `onViewSwitch` (`mosaica-viewswitch`). */
|
|
342
|
+
export declare const MosaicaKeyPicker: import("@lit/react").ReactWebComponent<KeyPickerElement, {
|
|
343
|
+
onViewSwitch: EventName<CustomEvent<{
|
|
344
|
+
from: string;
|
|
345
|
+
to: string;
|
|
346
|
+
sameFrame: boolean;
|
|
347
|
+
}>>;
|
|
348
|
+
}>;
|
|
349
|
+
/**
|
|
350
|
+
* `<mosaica-artifact-card>` as a React component. Event props: `onArtifactFit`
|
|
351
|
+
* (`mosaica-artifactfit`), `onClauseChange` (`mosaica-clausechange`) and `onClose`
|
|
352
|
+
* (`mosaica-close`).
|
|
353
|
+
*/
|
|
354
|
+
export declare const MosaicaArtifactCard: import("@lit/react").ReactWebComponent<ArtifactCardElement, {
|
|
355
|
+
onArtifactFit: EventName<CustomEvent<{
|
|
356
|
+
id: string;
|
|
357
|
+
}>>;
|
|
358
|
+
onClauseChange: EventName<CustomEvent<{
|
|
359
|
+
id: string;
|
|
360
|
+
layer: string;
|
|
361
|
+
outside: boolean;
|
|
362
|
+
verb: import("@mosaicajs/client").ClauseVerb;
|
|
363
|
+
on: boolean;
|
|
364
|
+
}>>;
|
|
365
|
+
onClose: EventName<CustomEvent<{
|
|
366
|
+
what: "item" | "artifact";
|
|
367
|
+
}>>;
|
|
368
|
+
}>;
|
|
369
|
+
/**
|
|
370
|
+
* `<mosaica-field-card>` as a React component. Event props: `onFilterChange`
|
|
371
|
+
* (`mosaica-filterchange`), `onClauseChange` (`mosaica-clausechange`), `onColourChange`
|
|
372
|
+
* (`mosaica-colourchange`), `onLevelChange` (`mosaica-levelchange`), `onValueColour`
|
|
373
|
+
* (`mosaica-valuecolour`), `onClusterColour` (`mosaica-clustercolour`) and `onFold` (`mosaica-fold`).
|
|
374
|
+
*/
|
|
375
|
+
export declare const MosaicaFieldCard: import("@lit/react").ReactWebComponent<FieldCardElement, {
|
|
376
|
+
onFold: EventName<CustomEvent<{
|
|
377
|
+
field: string;
|
|
378
|
+
folded: boolean;
|
|
379
|
+
}>>;
|
|
380
|
+
onFilterChange: EventName<CustomEvent<{
|
|
381
|
+
column: string | null;
|
|
382
|
+
expr?: import("@mosaicajs/client").FilterExpr | null;
|
|
383
|
+
verb?: import("@mosaicajs/client").ClauseVerb;
|
|
384
|
+
}>>;
|
|
385
|
+
onClauseChange: EventName<CustomEvent<{
|
|
386
|
+
id: string;
|
|
387
|
+
layer: string;
|
|
388
|
+
outside: boolean;
|
|
389
|
+
verb: import("@mosaicajs/client").ClauseVerb;
|
|
390
|
+
on: boolean;
|
|
391
|
+
}>>;
|
|
392
|
+
onColourChange: EventName<CustomEvent<{
|
|
393
|
+
colourBy: string | null;
|
|
394
|
+
}>>;
|
|
395
|
+
onLevelChange: EventName<CustomEvent<{
|
|
396
|
+
level: number | null;
|
|
397
|
+
}>>;
|
|
398
|
+
onValueColour: EventName<CustomEvent<{
|
|
399
|
+
column: string;
|
|
400
|
+
changes: {
|
|
401
|
+
value: string;
|
|
402
|
+
colour: string | null;
|
|
403
|
+
}[];
|
|
404
|
+
}>>;
|
|
405
|
+
onClusterColour: EventName<CustomEvent<{
|
|
406
|
+
layer: string;
|
|
407
|
+
changes: {
|
|
408
|
+
mosaicaId: string;
|
|
409
|
+
colour: string | null;
|
|
410
|
+
}[];
|
|
411
|
+
}>>;
|
|
412
|
+
}>;
|
|
413
|
+
/**
|
|
414
|
+
* `<mosaica-colour-editor>` as a React component. Event props: `onValueColour`
|
|
415
|
+
* (`mosaica-valuecolour`) and `onClusterColour` (`mosaica-clustercolour`).
|
|
416
|
+
*/
|
|
417
|
+
export declare const MosaicaColourEditor: import("@lit/react").ReactWebComponent<ColourEditorElement, {
|
|
418
|
+
onValueColour: EventName<CustomEvent<{
|
|
419
|
+
column: string;
|
|
420
|
+
changes: {
|
|
421
|
+
value: string;
|
|
422
|
+
colour: string | null;
|
|
423
|
+
}[];
|
|
424
|
+
}>>;
|
|
425
|
+
onClusterColour: EventName<CustomEvent<{
|
|
426
|
+
layer: string;
|
|
427
|
+
changes: {
|
|
428
|
+
mosaicaId: string;
|
|
429
|
+
colour: string | null;
|
|
430
|
+
}[];
|
|
431
|
+
}>>;
|
|
432
|
+
}>;
|
|
433
|
+
/**
|
|
434
|
+
* `<mosaica-hierarchy>` as a React component. Event props: `onClauseChange` (`mosaica-clausechange`)
|
|
435
|
+
* and `onArtifactFit` (`mosaica-artifactfit`).
|
|
436
|
+
*/
|
|
437
|
+
export declare const MosaicaHierarchy: import("@lit/react").ReactWebComponent<HierarchyElement, {
|
|
438
|
+
onClauseChange: EventName<CustomEvent<{
|
|
439
|
+
id: string;
|
|
440
|
+
layer: string;
|
|
441
|
+
outside: boolean;
|
|
442
|
+
verb: import("@mosaicajs/client").ClauseVerb;
|
|
443
|
+
on: boolean;
|
|
444
|
+
}>>;
|
|
445
|
+
onArtifactFit: EventName<CustomEvent<{
|
|
446
|
+
id: string;
|
|
447
|
+
}>>;
|
|
448
|
+
}>;
|
|
449
|
+
export type { ArtifactCardElement, ClusterFilterElement, ColourEditorElement, CountElement, ExplorerElement, FieldCardElement, FilterElement, FilterPanelElement, HierarchyElement, ItemCardElement, KeyPickerElement, LayerPickerElement, MapElement, SelectionElement, StatusElement, StoreElement, ViewPickerElement };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every `mosaica-*` element as a React component with typed props and event handlers, made with
|
|
3
|
+
* `@lit/react`. `MosaicaMap` wraps `<mosaica-map>`, and so on. A prop that names an element
|
|
4
|
+
* property is set as that property, so an object such as `store` reaches the element under React
|
|
5
|
+
* 18, which sets a custom element's props as attributes. Each element's events are handler props, such as `onPick` for
|
|
6
|
+
* `mosaica-pick`. The element classes are exported as types with an `Element` suffix, such as
|
|
7
|
+
* `MapElement`, for typing a ref. Each element's attributes, properties, events, slots and parts
|
|
8
|
+
* are on its page in the Components reference, which each wrapper's type links to.
|
|
9
|
+
*
|
|
10
|
+
* `MosaicaStore`, `MosaicaMap` and `MosaicaExplorer` read their `authorise` prop through a ref, so
|
|
11
|
+
* an inline function does not build a new store on every render. To show the map to another
|
|
12
|
+
* viewer, change `token` or `viewerUrl`, or give the component a new `key`.
|
|
13
|
+
*
|
|
14
|
+
* This entry imports `@mosaicajs/components`, and with it Lit and deck.gl. The hooks are in the
|
|
15
|
+
* package root, `@mosaicajs/react`, which imports neither.
|
|
16
|
+
*
|
|
17
|
+
* @module @mosaicajs/react/components
|
|
18
|
+
*/
|
|
19
|
+
import { createComponent } from '@lit/react';
|
|
20
|
+
import * as React from 'react';
|
|
21
|
+
import { MosaicaArtifactCard as ArtifactCardElement, MosaicaClusterFilter as ClusterFilterElement, MosaicaColourEditor as ColourEditorElement, MosaicaCount as CountElement, MosaicaExplorer as ExplorerElement, MosaicaFieldCard as FieldCardElement, MosaicaFilter as FilterElement, MosaicaFilterPanel as FilterPanelElement, MosaicaHierarchy as HierarchyElement, MosaicaItemCard as ItemCardElement, MosaicaKeyPicker as KeyPickerElement, MosaicaLayerPicker as LayerPickerElement, MosaicaMap as MapElement, MosaicaSelection as SelectionElement, MosaicaStatus as StatusElement, MosaicaStore as StoreElement, MosaicaViewPicker as ViewPickerElement } from '@mosaicajs/components';
|
|
22
|
+
const ev = (name) => name;
|
|
23
|
+
const wrap = (tagName, elementClass, events) => createComponent({ react: React, tagName, elementClass, events, displayName: elementClass.name });
|
|
24
|
+
/**
|
|
25
|
+
* Hands the element one function per mount in place of the `authorise` prop, and calls the latest
|
|
26
|
+
* prop through a ref, as `useMosaicaStore` does. An element builds a new store when its `authorise`
|
|
27
|
+
* function changes, so an inline arrow passed straight through would build one on every render.
|
|
28
|
+
* The store is built again when `authorise` is given or removed; to show another viewer, change
|
|
29
|
+
* `token`, `viewerUrl` or the component's `key`.
|
|
30
|
+
*/
|
|
31
|
+
const withStableAuthorise = (Inner) => {
|
|
32
|
+
const Outer = React.forwardRef((props, ref) => {
|
|
33
|
+
const latest = React.useRef(props.authorise);
|
|
34
|
+
React.useLayoutEffect(() => {
|
|
35
|
+
latest.current = props.authorise;
|
|
36
|
+
});
|
|
37
|
+
const given = props.authorise != null;
|
|
38
|
+
const authorise = React.useMemo(() => (given ? () => latest.current() : null), [given]);
|
|
39
|
+
return React.createElement(Inner, { ...props, authorise, ref });
|
|
40
|
+
});
|
|
41
|
+
Outer.displayName = Inner.displayName;
|
|
42
|
+
return Outer;
|
|
43
|
+
};
|
|
44
|
+
/** The handler props for events a map emits, which the explorer also carries. */
|
|
45
|
+
const mapEvents = {
|
|
46
|
+
onPick: ev('mosaica-pick'),
|
|
47
|
+
onItemOpen: ev('mosaica-itemopen'),
|
|
48
|
+
onMiss: ev('mosaica-miss'),
|
|
49
|
+
onHover: ev('mosaica-hover'),
|
|
50
|
+
onViewChange: ev('mosaica-viewchange'),
|
|
51
|
+
onSelectChange: ev('mosaica-selectchange'),
|
|
52
|
+
onArtifactOpen: ev('mosaica-artifactopen'),
|
|
53
|
+
onLayerChange: ev('mosaica-layerchange')
|
|
54
|
+
};
|
|
55
|
+
/** `<mosaica-store>` as a React component. It has no event props. */
|
|
56
|
+
export const MosaicaStore = withStableAuthorise(wrap('mosaica-store', StoreElement, {}));
|
|
57
|
+
/**
|
|
58
|
+
* `<mosaica-explorer>` as a React component. It has a handler prop for every event, since the
|
|
59
|
+
* elements inside it emit them and each event bubbles out of it: `onPick`, `onItemOpen`, `onMiss`, `onHover`,
|
|
60
|
+
* `onViewChange`, `onSelectChange`, `onArtifactOpen`, `onLayerChange`, `onArtifactFit`,
|
|
61
|
+
* `onColourChange`, `onLevelChange`, `onValueColour`, `onClusterColour`, `onPaletteChange`, `onClusterPaletteChange`,
|
|
62
|
+
* `onDisplayChange`, `onSizeChange`, `onBudgetChange`, `onClusterBudgetChange`, `onFold`,
|
|
63
|
+
* `onFilterChange`, `onStateChange`, `onExpired`, `onOpen`, `onClose`, `onClauseChange`,
|
|
64
|
+
* `onViewSwitch` and `onViewFollow`, each for the `mosaica-` event of the same name in lower case.
|
|
65
|
+
* The `open` prop is the function the item card's Open calls, and `openUrl` the address it goes
|
|
66
|
+
* to; `onOpen` hears every press.
|
|
67
|
+
*/
|
|
68
|
+
export const MosaicaExplorer = withStableAuthorise(wrap('mosaica-explorer', ExplorerElement, {
|
|
69
|
+
...mapEvents,
|
|
70
|
+
onArtifactFit: ev('mosaica-artifactfit'),
|
|
71
|
+
onColourChange: ev('mosaica-colourchange'),
|
|
72
|
+
onLevelChange: ev('mosaica-levelchange'),
|
|
73
|
+
onValueColour: ev('mosaica-valuecolour'),
|
|
74
|
+
onClusterColour: ev('mosaica-clustercolour'),
|
|
75
|
+
onPaletteChange: ev('mosaica-palettechange'),
|
|
76
|
+
onClusterPaletteChange: ev('mosaica-clusterpalettechange'),
|
|
77
|
+
onDisplayChange: ev('mosaica-displaychange'),
|
|
78
|
+
onSizeChange: ev('mosaica-sizechange'),
|
|
79
|
+
onBudgetChange: ev('mosaica-budgetchange'),
|
|
80
|
+
onClusterBudgetChange: ev('mosaica-clusterbudgetchange'),
|
|
81
|
+
onFold: ev('mosaica-fold'),
|
|
82
|
+
onFilterChange: ev('mosaica-filterchange'),
|
|
83
|
+
onStateChange: ev('mosaica-statechange'),
|
|
84
|
+
onExpired: ev('mosaica-expired'),
|
|
85
|
+
onOpen: ev('mosaica-open'),
|
|
86
|
+
onClose: ev('mosaica-close'),
|
|
87
|
+
onClauseChange: ev('mosaica-clausechange'),
|
|
88
|
+
onViewSwitch: ev('mosaica-viewswitch'),
|
|
89
|
+
onViewFollow: ev('mosaica-viewfollow')
|
|
90
|
+
}));
|
|
91
|
+
/**
|
|
92
|
+
* `<mosaica-map>` as a React component. Event props: `onPick` (`mosaica-pick`), `onItemOpen`
|
|
93
|
+
* (`mosaica-itemopen`), `onMiss`
|
|
94
|
+
* (`mosaica-miss`), `onHover` (`mosaica-hover`), `onViewChange` (`mosaica-viewchange`), `onSelectChange`
|
|
95
|
+
* (`mosaica-selectchange`), `onArtifactOpen` (`mosaica-artifactopen`) and `onLayerChange`
|
|
96
|
+
* (`mosaica-layerchange`).
|
|
97
|
+
*/
|
|
98
|
+
export const MosaicaMap = withStableAuthorise(wrap('mosaica-map', MapElement, mapEvents));
|
|
99
|
+
/** `<mosaica-status>` as a React component. Event props: `onStateChange` (`mosaica-statechange`) and `onExpired` (`mosaica-expired`). */
|
|
100
|
+
export const MosaicaStatus = wrap('mosaica-status', StatusElement, { onStateChange: ev('mosaica-statechange'), onExpired: ev('mosaica-expired') });
|
|
101
|
+
/** `<mosaica-count>` as a React component. It has no event props. */
|
|
102
|
+
export const MosaicaCount = wrap('mosaica-count', CountElement, {});
|
|
103
|
+
/**
|
|
104
|
+
* `<mosaica-item-card>` as a React component. Event props: `onOpen` (`mosaica-open`), `onClose`
|
|
105
|
+
* (`mosaica-close`) and `onViewFollow` (`mosaica-viewfollow`). The `open` prop is the function
|
|
106
|
+
* Open calls, and `openUrl` the address it goes to; `onOpen` hears every press.
|
|
107
|
+
*/
|
|
108
|
+
export const MosaicaItemCard = wrap('mosaica-item-card', ItemCardElement, { onOpen: ev('mosaica-open'), onClose: ev('mosaica-close'), onViewFollow: ev('mosaica-viewfollow') });
|
|
109
|
+
/**
|
|
110
|
+
* `<mosaica-filter-panel>` as a React component. Event props: `onFilterChange`
|
|
111
|
+
* (`mosaica-filterchange`), `onChipOpen` (`mosaica-chipopen`), and from its cards
|
|
112
|
+
* `onClauseChange` (`mosaica-clausechange`), `onColourChange` (`mosaica-colourchange`),
|
|
113
|
+
* `onLevelChange` (`mosaica-levelchange`), `onValueColour` (`mosaica-valuecolour`),
|
|
114
|
+
* `onClusterColour` (`mosaica-clustercolour`) and `onFold` (`mosaica-fold`).
|
|
115
|
+
*/
|
|
116
|
+
export const MosaicaFilterPanel = wrap('mosaica-filter-panel', FilterPanelElement, {
|
|
117
|
+
onFilterChange: ev('mosaica-filterchange'),
|
|
118
|
+
onChipOpen: ev('mosaica-chipopen'),
|
|
119
|
+
onClauseChange: ev('mosaica-clausechange'),
|
|
120
|
+
onColourChange: ev('mosaica-colourchange'),
|
|
121
|
+
onLevelChange: ev('mosaica-levelchange'),
|
|
122
|
+
onValueColour: ev('mosaica-valuecolour'),
|
|
123
|
+
onClusterColour: ev('mosaica-clustercolour'),
|
|
124
|
+
onFold: ev('mosaica-fold')
|
|
125
|
+
});
|
|
126
|
+
/** `<mosaica-filter>` as a React component. Event prop: `onFilterChange` (`mosaica-filterchange`). */
|
|
127
|
+
export const MosaicaFilter = wrap('mosaica-filter', FilterElement, { onFilterChange: ev('mosaica-filterchange') });
|
|
128
|
+
/** `<mosaica-cluster-filter>` as a React component. Event prop: `onClauseChange` (`mosaica-clausechange`). */
|
|
129
|
+
export const MosaicaClusterFilter = wrap('mosaica-cluster-filter', ClusterFilterElement, { onClauseChange: ev('mosaica-clausechange') });
|
|
130
|
+
/** `<mosaica-selection>` as a React component. Event prop: `onSelectChange` (`mosaica-selectchange`). */
|
|
131
|
+
export const MosaicaSelection = wrap('mosaica-selection', SelectionElement, { onSelectChange: ev('mosaica-selectchange') });
|
|
132
|
+
/** `<mosaica-layer-picker>` as a React component. Event prop: `onLayerChange` (`mosaica-layerchange`). */
|
|
133
|
+
export const MosaicaLayerPicker = wrap('mosaica-layer-picker', LayerPickerElement, { onLayerChange: ev('mosaica-layerchange') });
|
|
134
|
+
/** `<mosaica-view-picker>` as a React component. Event prop: `onViewSwitch` (`mosaica-viewswitch`). */
|
|
135
|
+
export const MosaicaViewPicker = wrap('mosaica-view-picker', ViewPickerElement, { onViewSwitch: ev('mosaica-viewswitch') });
|
|
136
|
+
/** `<mosaica-key-picker>` as a React component. Event prop: `onViewSwitch` (`mosaica-viewswitch`). */
|
|
137
|
+
export const MosaicaKeyPicker = wrap('mosaica-key-picker', KeyPickerElement, { onViewSwitch: ev('mosaica-viewswitch') });
|
|
138
|
+
/**
|
|
139
|
+
* `<mosaica-artifact-card>` as a React component. Event props: `onArtifactFit`
|
|
140
|
+
* (`mosaica-artifactfit`), `onClauseChange` (`mosaica-clausechange`) and `onClose`
|
|
141
|
+
* (`mosaica-close`).
|
|
142
|
+
*/
|
|
143
|
+
export const MosaicaArtifactCard = wrap('mosaica-artifact-card', ArtifactCardElement, {
|
|
144
|
+
onArtifactFit: ev('mosaica-artifactfit'),
|
|
145
|
+
onClauseChange: ev('mosaica-clausechange'),
|
|
146
|
+
onClose: ev('mosaica-close')
|
|
147
|
+
});
|
|
148
|
+
/**
|
|
149
|
+
* `<mosaica-field-card>` as a React component. Event props: `onFilterChange`
|
|
150
|
+
* (`mosaica-filterchange`), `onClauseChange` (`mosaica-clausechange`), `onColourChange`
|
|
151
|
+
* (`mosaica-colourchange`), `onLevelChange` (`mosaica-levelchange`), `onValueColour`
|
|
152
|
+
* (`mosaica-valuecolour`), `onClusterColour` (`mosaica-clustercolour`) and `onFold` (`mosaica-fold`).
|
|
153
|
+
*/
|
|
154
|
+
export const MosaicaFieldCard = wrap('mosaica-field-card', FieldCardElement, {
|
|
155
|
+
onFold: ev('mosaica-fold'),
|
|
156
|
+
onFilterChange: ev('mosaica-filterchange'),
|
|
157
|
+
onClauseChange: ev('mosaica-clausechange'),
|
|
158
|
+
onColourChange: ev('mosaica-colourchange'),
|
|
159
|
+
onLevelChange: ev('mosaica-levelchange'),
|
|
160
|
+
onValueColour: ev('mosaica-valuecolour'),
|
|
161
|
+
onClusterColour: ev('mosaica-clustercolour')
|
|
162
|
+
});
|
|
163
|
+
/**
|
|
164
|
+
* `<mosaica-colour-editor>` as a React component. Event props: `onValueColour`
|
|
165
|
+
* (`mosaica-valuecolour`) and `onClusterColour` (`mosaica-clustercolour`).
|
|
166
|
+
*/
|
|
167
|
+
export const MosaicaColourEditor = wrap('mosaica-colour-editor', ColourEditorElement, {
|
|
168
|
+
onValueColour: ev('mosaica-valuecolour'),
|
|
169
|
+
onClusterColour: ev('mosaica-clustercolour')
|
|
170
|
+
});
|
|
171
|
+
/**
|
|
172
|
+
* `<mosaica-hierarchy>` as a React component. Event props: `onClauseChange` (`mosaica-clausechange`)
|
|
173
|
+
* and `onArtifactFit` (`mosaica-artifactfit`).
|
|
174
|
+
*/
|
|
175
|
+
export const MosaicaHierarchy = wrap('mosaica-hierarchy', HierarchyElement, { onClauseChange: ev('mosaica-clausechange'), onArtifactFit: ev('mosaica-artifactfit') });
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ProjectionName, type Projections, type Store, type StoreOptions, type TokenSupplier } from '@mosaicajs/client';
|
|
2
|
+
/** The options of {@link useMosaicaStore}: the options of {@link createStore}, with `authorise` read through a ref. */
|
|
3
|
+
export type UseMosaicaStoreOptions = Omit<StoreOptions, 'authorise'> & {
|
|
4
|
+
/**
|
|
5
|
+
* A function the store calls for a new token before the current one expires. The hook reads it
|
|
6
|
+
* through a ref, so an inline function neither rebuilds the store nor goes stale. A store serves
|
|
7
|
+
* one viewer: to show another, call `clear()` on the store or give the component a new `key`.
|
|
8
|
+
*/
|
|
9
|
+
authorise?: TokenSupplier;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Creates a store with {@link createStore} for the component's lifetime, and disposes of it on
|
|
13
|
+
* unmount. The store is rebuilt when `viewerUrl`, `client`, `token` or `view` changes, or when
|
|
14
|
+
* `authorise` is given or removed. A change to any other option takes effect at the next rebuild.
|
|
15
|
+
* With a `client`, `viewerUrl` may be left out, as `createStore` allows. Keep the `client` the
|
|
16
|
+
* same object across renders, such as with `useMemo`: a new client each render rebuilds the store
|
|
17
|
+
* each render.
|
|
18
|
+
*
|
|
19
|
+
* The store is built in an effect, so the first render returns `null`. Options `createStore`
|
|
20
|
+
* refuses, such as neither `viewerUrl` nor `client`, throw from that effect.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useMosaicaStore(options: UseMosaicaStoreOptions): Store | null;
|
|
23
|
+
/**
|
|
24
|
+
* Reads one projection of `store` through `useSyncExternalStore`, and re-renders the component
|
|
25
|
+
* when that projection is replaced. A change to another projection does not re-render it.
|
|
26
|
+
*
|
|
27
|
+
* @param store - The store, such as the one {@link useMosaicaStore} returns.
|
|
28
|
+
* @param name - The projection to read, such as `marks` or `legend`.
|
|
29
|
+
* @returns The projection, or `null` while `store` is `null`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useProjection<K extends ProjectionName>(store: Store, name: K): Projections[K];
|
|
32
|
+
export declare function useProjection<K extends ProjectionName>(store: Store | null, name: K): Projections[K] | null;
|
|
33
|
+
export type { ProjectionName, Projections, Store, StoreOptions, TokenSupplier } from '@mosaicajs/client';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hooks for the headless store. {@link useMosaicaStore} creates a store for a component's
|
|
3
|
+
* lifetime, and {@link useProjection} reads one of its projections and re-renders when it changes.
|
|
4
|
+
* The React components for the elements are in the `@mosaicajs/react/components` entry. This
|
|
5
|
+
* entry imports neither Lit nor deck.gl.
|
|
6
|
+
*
|
|
7
|
+
* @module @mosaicajs/react
|
|
8
|
+
*/
|
|
9
|
+
import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
10
|
+
import { createStore } from '@mosaicajs/client';
|
|
11
|
+
/**
|
|
12
|
+
* Creates a store with {@link createStore} for the component's lifetime, and disposes of it on
|
|
13
|
+
* unmount. The store is rebuilt when `viewerUrl`, `client`, `token` or `view` changes, or when
|
|
14
|
+
* `authorise` is given or removed. A change to any other option takes effect at the next rebuild.
|
|
15
|
+
* With a `client`, `viewerUrl` may be left out, as `createStore` allows. Keep the `client` the
|
|
16
|
+
* same object across renders, such as with `useMemo`: a new client each render rebuilds the store
|
|
17
|
+
* each render.
|
|
18
|
+
*
|
|
19
|
+
* The store is built in an effect, so the first render returns `null`. Options `createStore`
|
|
20
|
+
* refuses, such as neither `viewerUrl` nor `client`, throw from that effect.
|
|
21
|
+
*/
|
|
22
|
+
export function useMosaicaStore(options) {
|
|
23
|
+
const [store, setStore] = useState(null);
|
|
24
|
+
const latest = useRef(options);
|
|
25
|
+
useLayoutEffect(() => {
|
|
26
|
+
latest.current = options;
|
|
27
|
+
});
|
|
28
|
+
const { viewerUrl, client, token, view } = options;
|
|
29
|
+
const hasAuthorise = options.authorise !== undefined;
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const opts = latest.current;
|
|
32
|
+
const built = createStore({
|
|
33
|
+
...opts,
|
|
34
|
+
...(hasAuthorise ? { authorise: () => latest.current.authorise() } : {})
|
|
35
|
+
});
|
|
36
|
+
setStore(built);
|
|
37
|
+
return () => {
|
|
38
|
+
built.dispose();
|
|
39
|
+
setStore((current) => (current === built ? null : current));
|
|
40
|
+
};
|
|
41
|
+
}, [viewerUrl, client, token, view, hasAuthorise]);
|
|
42
|
+
return store;
|
|
43
|
+
}
|
|
44
|
+
const noop = () => { };
|
|
45
|
+
const unsubscribed = () => noop;
|
|
46
|
+
export function useProjection(store, name) {
|
|
47
|
+
const subscribe = store ? (onChange) => store.subscribe(name, onChange) : unsubscribed;
|
|
48
|
+
const getSnapshot = store ? () => store.get(name) : () => null;
|
|
49
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
50
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mosaicajs/react",
|
|
3
|
+
"version": "0.1.0-rc.4",
|
|
4
|
+
"description": "React hooks over the headless store, and typed wrappers for the mosaica-* elements behind a separate entry.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mosaica",
|
|
7
|
+
"react",
|
|
8
|
+
"hooks",
|
|
9
|
+
"map",
|
|
10
|
+
"visualisation"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/mosaicadb/mosaica/tree/main/clients/ts/react#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/mosaicadb/mosaica/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/mosaicadb/mosaica.git",
|
|
19
|
+
"directory": "clients/ts/react"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"author": "Joe Ennis",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./components": {
|
|
32
|
+
"types": "./dist/components.d.ts",
|
|
33
|
+
"default": "./dist/components.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"sideEffects": false,
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "node ../scripts/build-package.mjs",
|
|
42
|
+
"prepack": "node ../scripts/pack.mjs before",
|
|
43
|
+
"postpack": "node ../scripts/pack.mjs after",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@mosaicajs/client": "^0.1.0-rc.4"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@lit/react": "^1.0.0",
|
|
52
|
+
"@mosaicajs/components": "^0.1.0-rc.4",
|
|
53
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"@lit/react": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"@mosaicajs/components": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@lit/react": "^1.0.8",
|
|
65
|
+
"@mosaicajs/components": "^0.1.0-rc.4",
|
|
66
|
+
"@types/react": "^19.2.0",
|
|
67
|
+
"@types/react-dom": "^19.2.0",
|
|
68
|
+
"happy-dom": "^20.0.0",
|
|
69
|
+
"react": "^19.2.0",
|
|
70
|
+
"react-dom": "^19.2.0",
|
|
71
|
+
"typescript": "^5.9.0",
|
|
72
|
+
"vitest": "^3.2.0"
|
|
73
|
+
},
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"access": "public"
|
|
76
|
+
}
|
|
77
|
+
}
|