1 |
|
2 | import * as React from 'react'
|
3 | import * as valueTypes from './constants/value_types'
|
4 | import type { Observation, Preset } from 'mapeo-schema'
|
5 |
|
6 |
|
7 | import type {
|
8 |
|
9 | Bbox,
|
10 | Point2D,
|
11 | Point3D
|
12 | } from 'flow-geojson'
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | export type Attachment = $ElementType<
|
18 | $NonMaybeType<$ElementType<Observation, 'attachments'>>,
|
19 | number
|
20 | >
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export type JSONValue =
|
26 | | void
|
27 | | null
|
28 | | number
|
29 | | string
|
30 | | boolean
|
31 | | JSONObject
|
32 | | JSONArray
|
33 | export type JSONObject = { [key: string]: JSONValue }
|
34 | type JSONArray = Array<JSONValue>
|
35 | type Properties = JSONObject | null
|
36 |
|
37 | type FlattenedProperties = {
|
38 | [key: string]: null | number | string | boolean
|
39 | } | null
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | type FeatureTemplate<G, P> = {
|
45 | id?: string | number,
|
46 | type: 'Feature',
|
47 | bbox?: Bbox,
|
48 | properties: P,
|
49 | geometry: G
|
50 | }
|
51 |
|
52 | type FeatureTemplateWithId<G, Properties> = FeatureTemplate<G, Properties> & {
|
53 | id: string | number
|
54 | }
|
55 |
|
56 | export type PointFeature = FeatureTemplate<Point2D | Point3D | null, Properties>
|
57 |
|
58 | export type PointFeatureWithId = FeatureTemplateWithId<
|
59 | Point2D | Point3D | null,
|
60 | Properties
|
61 | >
|
62 |
|
63 | export type FlattenedPointFeature = FeatureTemplate<
|
64 | Point2D | Point3D | null,
|
65 | FlattenedProperties
|
66 | >
|
67 |
|
68 |
|
69 |
|
70 | export type PaperSize = 'a4' | 'letter'
|
71 |
|
72 |
|
73 | export type FieldState = Array<{|
|
74 | id: string,
|
75 | hidden: boolean,
|
76 | label: React.Node
|
77 | |}>
|
78 | export type Filter = Array<number | string | boolean | null | Array<Filter>>
|
79 |
|
80 | export type ValueTypes = { [fieldkey: string]: $Values<typeof valueTypes> }
|
81 |
|
82 | export type FieldOrder = { [fieldkey: string]: number }
|
83 |
|
84 | export type Classes<S> = { [className: $Keys<S>]: string }
|
85 |
|
86 | export type StringStatistic = {|
|
87 | count: number,
|
88 | lengthMin?: number,
|
89 | lengthMax?: number,
|
90 | lengthVariance?: number,
|
91 | lengthMean?: number,
|
92 | wordsMin?: number,
|
93 | wordsMax?: number,
|
94 | wordsVariance?: number,
|
95 | wordsMean?: number,
|
96 | values: Map<string, number>
|
97 | |}
|
98 |
|
99 | export type NumberStatistic = {|
|
100 | count: number,
|
101 | min?: number,
|
102 | max?: number,
|
103 | variance?: number,
|
104 | mean?: number,
|
105 | values: Map<number, number>
|
106 | |}
|
107 |
|
108 | export type DateStatistic = {|
|
109 | count: number,
|
110 | min?: string,
|
111 | max?: string,
|
112 | mean?: string,
|
113 | values: Map<string, number>
|
114 | |}
|
115 |
|
116 | export type NonArrayFieldStatistic = {|
|
117 | string: StringStatistic,
|
118 | boolean: {|
|
119 | count: number,
|
120 | values: Map<boolean, number>
|
121 | |},
|
122 | number: NumberStatistic,
|
123 | date: DateStatistic,
|
124 | datetime: DateStatistic,
|
125 | url: number,
|
126 | image: number,
|
127 | video: number,
|
128 | audio: number,
|
129 | null: number,
|
130 | undefined: number,
|
131 | location: number
|
132 | |}
|
133 |
|
134 | export type FieldStatistic = {|
|
135 | ...$Exact<NonArrayFieldStatistic>,
|
136 | array?: {|
|
137 | count: number,
|
138 | lengthMin: number,
|
139 | lengthMax: number,
|
140 | valueStats: FieldStatistic
|
141 | |}
|
142 | |}
|
143 |
|
144 | export type Statistics = { [fieldname: string]: FieldStatistic }
|
145 |
|
146 | type MediaType =
|
147 | | typeof valueTypes.IMAGE_URL
|
148 | | typeof valueTypes.AUDIO_URL
|
149 | | typeof valueTypes.VIDEO_URL
|
150 | export type MediaArray = Array<{ src: string, type: MediaType }>
|
151 |
|
152 | export type Coordinates = {
|
153 | altitude?: number,
|
154 | heading?: number,
|
155 | longitude: number,
|
156 | speed?: number,
|
157 | latitude: number,
|
158 | accuracy?: number
|
159 | }
|
160 |
|
161 | export type Key = string | Array<string | number>
|
162 |
|
163 | type BaseField = {|
|
164 |
|
165 | id: string,
|
166 |
|
167 |
|
168 |
|
169 | key: Key,
|
170 | label?: string,
|
171 |
|
172 |
|
173 | placeholder?: string,
|
174 |
|
175 | universal?: boolean,
|
176 |
|
177 | readonly?: boolean
|
178 | |}
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | export type TextField = {
|
189 | ...BaseField,
|
190 | type: 'text' | 'textarea' | 'localized',
|
191 | appearance?: 'singleline' | 'multiline',
|
192 |
|
193 | snake_case?: boolean
|
194 | }
|
195 |
|
196 | export type LinkField = {
|
197 | ...BaseField,
|
198 | type: 'link'
|
199 | }
|
200 |
|
201 | export type NumberField = {
|
202 | ...BaseField,
|
203 | type: 'number',
|
204 | min_value?: number,
|
205 | max_value?: number
|
206 | }
|
207 |
|
208 | export type SelectableFieldValue = number | string | boolean | null
|
209 |
|
210 | export type LabeledSelectOption = {|
|
211 | value: SelectableFieldValue,
|
212 | label: string
|
213 | |}
|
214 |
|
215 | export type SelectOptions = Array<SelectableFieldValue | LabeledSelectOption>
|
216 |
|
217 | export type SelectOneField = {
|
218 | ...BaseField,
|
219 | type: 'select_one',
|
220 | options: SelectOptions,
|
221 |
|
222 |
|
223 | other?: boolean,
|
224 |
|
225 | snake_case?: boolean
|
226 | }
|
227 |
|
228 | export type SelectMultipleField = {
|
229 | ...$Exact<SelectOneField>,
|
230 | type: 'select_multiple'
|
231 | }
|
232 |
|
233 | export type DateField = {
|
234 | ...BaseField,
|
235 | type: 'date',
|
236 | min_value?: string,
|
237 | max_value?: string
|
238 | }
|
239 |
|
240 | export type DateTimeField = {
|
241 | ...BaseField,
|
242 | type: 'datetime',
|
243 | min_value?: string,
|
244 | max_value?: string
|
245 | }
|
246 |
|
247 | export type Field =
|
248 | | TextField
|
249 | | NumberField
|
250 | | SelectOneField
|
251 | | SelectMultipleField
|
252 | | DateField
|
253 | | DateTimeField
|
254 | | LinkField
|
255 |
|
256 | export type MessageDescriptor = {
|
257 | id: string,
|
258 | description?: string | {},
|
259 | defaultMessage?: string
|
260 | }
|
261 |
|
262 | type IntlConfig = {|
|
263 | locale?: string,
|
264 | timeZone?: string,
|
265 | textComponent?: any,
|
266 | messages?: { [key: string]: string },
|
267 | defaultLocale: string,
|
268 | onError?: (err: string) => void
|
269 | |}
|
270 |
|
271 | type FormatDateOptions = {|
|
272 | localeMatcher?: 'lookup' | 'best fit',
|
273 | timeZone?: string,
|
274 | hour12?: boolean,
|
275 | hourCycle?: 'h11' | 'h12' | 'h23' | 'h24',
|
276 | formatMatcher?: 'basic' | 'best fit',
|
277 | weekday?: 'long' | 'short' | 'narrow',
|
278 | era?: 'long' | 'short' | 'narrow',
|
279 | year?: 'numeric' | '2-digit',
|
280 | month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow',
|
281 | day?: 'numeric' | '2-digit',
|
282 | hour?: 'numeric' | '2-digit',
|
283 | minute?: 'numeric' | '2-digit',
|
284 | second?: 'numeric' | '2-digit',
|
285 | timeZoneName?: 'long' | 'short'
|
286 | |}
|
287 |
|
288 | type oneToTwenty =
|
289 | | 1
|
290 | | 2
|
291 | | 3
|
292 | | 4
|
293 | | 5
|
294 | | 6
|
295 | | 7
|
296 | | 8
|
297 | | 9
|
298 | | 10
|
299 | | 11
|
300 | | 12
|
301 | | 13
|
302 | | 14
|
303 | | 15
|
304 | | 16
|
305 | | 17
|
306 | | 18
|
307 | | 19
|
308 | | 20
|
309 |
|
310 | type FormatNumberOptions = {|
|
311 | localeMatcher?: 'lookup' | 'best fit',
|
312 | style?: 'decimal' | 'currency' | 'percent',
|
313 | currenty?: string,
|
314 | currencyDisplay?: 'symbol' | 'code' | 'name',
|
315 | useGrouping?: boolean,
|
316 | minimumIntegerDigits?: oneToTwenty | 21,
|
317 | minimumFractionDigits?: 0 | oneToTwenty,
|
318 | maximumFractionDigits?: 0 | oneToTwenty,
|
319 | minimumSignificantDigits?: oneToTwenty | 21,
|
320 | maximumSignificantDigits?: oneToTwenty | 21
|
321 | |}
|
322 |
|
323 | type FormatRelativeOptions = {|
|
324 | localeMatcher?: 'lookup' | 'best fit',
|
325 | numeric?: 'always' | 'auto',
|
326 | type?: 'long' | 'short' | 'narrow'
|
327 | |}
|
328 |
|
329 | type Unit =
|
330 | | 'second'
|
331 | | 'minute'
|
332 | | 'hour'
|
333 | | 'day'
|
334 | | 'week'
|
335 | | 'month'
|
336 | | 'quarter'
|
337 | | 'year'
|
338 |
|
339 | type FormatPluralOptions = {
|
340 | type?: 'cardinal' | 'ordinal'
|
341 | }
|
342 |
|
343 | export type Primitive = string | boolean | null | void | number
|
344 |
|
345 | type MessageValues = { [key: string]: Primitive }
|
346 | type IntlFormatters = {|
|
347 | formatDate: (value: number | Date, opts?: FormatDateOptions) => string,
|
348 | formatTime: (value: number | Date, opts?: FormatDateOptions) => string,
|
349 | formatRelativeTime: (
|
350 | value: number,
|
351 | unit: Unit,
|
352 | opts?: FormatRelativeOptions
|
353 | ) => string,
|
354 | formatNumber: (value: number, opts?: FormatNumberOptions) => string,
|
355 | formatPlural: (value: number, opts?: FormatPluralOptions) => string,
|
356 | formatMessage: (
|
357 | descriptor: MessageDescriptor,
|
358 | values?: MessageValues
|
359 | ) => string,
|
360 | formatHTMLMessage: (
|
361 | descriptor: MessageDescriptor,
|
362 | values?: MessageValues
|
363 | ) => string
|
364 | |}
|
365 |
|
366 | export type IntlShape = {|
|
367 | ...IntlConfig,
|
368 | ...IntlFormatters
|
369 | |}
|
370 |
|
371 |
|
372 |
|
373 | export type GetMedia = (
|
374 | attachment: Attachment,
|
375 | options?: { width: number, height: number }
|
376 | ) => { src: string, type: 'image' | 'video' | 'audio' } | void
|
377 |
|
378 | export type GetMediaUrl = (
|
379 | attachmentId: string,
|
380 | size: 'thumbnail' | 'preview' | 'original'
|
381 | ) => string
|
382 |
|
383 | export type GetIconUrl = (iconId: string) => string
|
384 |
|
385 | export type PresetWithFields = {
|
386 | ...$Exact<Preset>,
|
387 | fields: Field[]
|
388 | }
|
389 |
|
390 | export type PresetWithAdditionalFields = {
|
391 | ...$Exact<PresetWithFields>,
|
392 | additionalFields: Field[]
|
393 | }
|
394 |
|
395 | export type CameraOptions = {
|
396 | center: [number, number],
|
397 | zoom: number,
|
398 | bearing: number,
|
399 | pitch: number
|
400 | }
|
401 |
|
402 | export type CommonViewContentProps = {
|
403 |
|
404 | observations: Array<Observation>,
|
405 |
|
406 | onClick: (id: string, imageIndex?: number) => void,
|
407 | getPreset: Observation => PresetWithAdditionalFields,
|
408 | |
409 |
|
410 |
|
411 | getMedia: GetMedia
|
412 | }
|