@imerss/inat-components 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +23 -4
  2. package/dist/index.d.ts +87 -75
  3. package/dist/index.js +261 -173
  4. package/dist/standalone.min.js +1 -1
  5. package/package.json +10 -12
  6. package/PUBLISH.md +0 -13
  7. package/declaration.d.ts +0 -2
  8. package/public/favicon.ico +0 -0
  9. package/public/index.html +0 -20
  10. package/public/logo192.png +0 -0
  11. package/public/logo512.png +0 -0
  12. package/public/manifest.json +0 -25
  13. package/public/robots.txt +0 -3
  14. package/public/standalone.html +0 -55
  15. package/rollup.config.js +0 -47
  16. package/src/__shared/api/common-taxa.ts +0 -57
  17. package/src/__shared/api/favourites.ts +0 -57
  18. package/src/__shared/api/index.ts +0 -4
  19. package/src/__shared/api/recent-observations.ts +0 -44
  20. package/src/__shared/api/summary.ts +0 -86
  21. package/src/__shared/constants.ts +0 -6
  22. package/src/__shared/index.ts +0 -4
  23. package/src/__shared/typings.ts +0 -83
  24. package/src/__shared/utils/configUtils.ts +0 -25
  25. package/src/__shared/utils/dateUtils.ts +0 -14
  26. package/src/__shared/utils/index.ts +0 -3
  27. package/src/__shared/utils/numberUtils.ts +0 -1
  28. package/src/components/common-taxa/__tests__/common-taxa.test.tsx +0 -14
  29. package/src/components/common-taxa/common-taxa.tsx +0 -73
  30. package/src/components/error/__tests__/error.test.tsx +0 -9
  31. package/src/components/error/error.module.scss +0 -7
  32. package/src/components/error/error.tsx +0 -15
  33. package/src/components/favourites/__tests__/favourites.test.tsx +0 -13
  34. package/src/components/favourites/favourites.tsx +0 -73
  35. package/src/components/hooks/hooks.tsx +0 -34
  36. package/src/components/loader/__tests__/loader.test.tsx +0 -10
  37. package/src/components/loader/loader.tsx +0 -26
  38. package/src/components/no-results/__tests__/no-results.test.tsx +0 -9
  39. package/src/components/no-results/no-results.tsx +0 -9
  40. package/src/components/observation/__tests__/observation.test.tsx +0 -14
  41. package/src/components/observation/observation.module.scss +0 -20
  42. package/src/components/observation/observation.tsx +0 -30
  43. package/src/components/recent-observations/__tests__/recent-observations.test.tsx +0 -9
  44. package/src/components/recent-observations/recent-observations.tsx +0 -84
  45. package/src/components/seasonality-graph/__tests__/seasonality-graph.test.tsx +0 -9
  46. package/src/components/seasonality-graph/seasonality-graph.module.scss +0 -7
  47. package/src/components/seasonality-graph/seasonality-graph.tsx +0 -46
  48. package/src/components/shared/css/general.module.scss +0 -73
  49. package/src/components/summary/ObserverList.tsx +0 -24
  50. package/src/components/summary/__tests__/summary.test.tsx +0 -18
  51. package/src/components/summary/summary.module.scss +0 -88
  52. package/src/components/summary/summary.tsx +0 -91
  53. package/src/components/tabs/__tests__/tabs.test.tsx +0 -16
  54. package/src/components/tabs/tabs.module.scss +0 -28
  55. package/src/components/tabs/tabs.tsx +0 -65
  56. package/src/components/taxon-panel/__tests__/taxon-panel.test.tsx +0 -10
  57. package/src/components/taxon-panel/taxon-panel.module.scss +0 -7
  58. package/src/components/taxon-panel/taxon-panel.tsx +0 -110
  59. package/src/components/year-dropdown/__tests__/year-dropdown.test.tsx +0 -14
  60. package/src/components/year-dropdown/year-dropdown.module.scss +0 -3
  61. package/src/components/year-dropdown/year-dropdown.tsx +0 -37
  62. package/src/hooks/useLoadSourceData.ts +0 -81
  63. package/src/index.ts +0 -15
  64. package/src/types/index.d.ts +0 -17
  65. package/src/types/standalone.d.ts +0 -6
  66. package/tsconfig.json +0 -6
package/README.md CHANGED
@@ -1,12 +1,31 @@
1
1
  # @imerss/inat-components
2
2
 
3
3
  The [inat-components repo](https://github.com/IMERSS/inat-components) contains some pre-built React components to
4
- display iNaturalist data on your own sites. The original goal was to provide add an
4
+ display iNaturalist data on your own sites. The original goal was to add an
5
5
  [interactive page to the BC Lepidoptera website](https://bcleps.weebly.com/inat.html) so visitors could see some
6
6
  high-level information about lepidoptera (butterflies and moths) spotted in British Columbia. But the code
7
7
  was written to allow it to be re-used by any website and for any taxon or place.
8
8
 
9
- This specific package is only the React components, plus a standalone.min.js file for
9
+ This package holds the React components, with their typings, and `dist/standalone.min.js`, a single script holding
10
+ the components and React together, for sites which don't use React.
10
11
 
11
- Please see the [main documentation](https://github.com/IMERSS/inat-components) for more information on the script,
12
- including the standalone version.
12
+ ```
13
+ npm install @imerss/inat-components
14
+ ```
15
+
16
+ ```jsx
17
+ import TaxonPanel from "@imerss/inat-components";
18
+
19
+ <TaxonPanel
20
+ taxon={{ id: 47157, str: "leps" }}
21
+ place={{ id: 7085, str: "bc" }}
22
+ dataSource="url"
23
+ dataSourceBaseUrl="https://example.org/inat"
24
+ features={[{ feature: "recentObservations" }, { feature: "commonTaxa" }, { feature: "favourites" }, { feature: "stats" }]}
25
+ />
26
+ ```
27
+
28
+ See the [main documentation](https://github.com/IMERSS/inat-components) for every setting, the individual components,
29
+ the data files which [@imerss/inat-components-utils](https://www.npmjs.com/package/@imerss/inat-components-utils)
30
+ writes for the `"url"` data source, and the
31
+ [standalone version](https://github.com/IMERSS/inat-components/tree/main/packages/inat-components-standalone).
package/dist/index.d.ts CHANGED
@@ -1,50 +1,58 @@
1
- declare type CommonTaxaCallProps = {
1
+ import React from 'react';
2
+
3
+ type ObservationFilter = {
4
+ taxonId?: string | number;
5
+ placeId?: string | number;
6
+ projectId?: string | number;
7
+ };
8
+ /**
9
+ * Render a filter as query parameters, to be appended to a URL which already has a query.
10
+ * @param filter - The taxon, place and project of the observations
11
+ * @return The parameters, each beginning with "&", of those members of the filter which are supplied
12
+ */
13
+ declare const filterParams: (filter: ObservationFilter) => string;
14
+
15
+ type CommonTaxaCallProps = ObservationFilter & {
2
16
  year: string | number;
3
- taxonId: string | number;
4
- placeId: string | number;
5
17
  numResults: number;
6
18
  };
7
- declare type CommonTaxData = {
19
+ type CommonTaxData = {
8
20
  id: number;
9
21
  imageUrl: string;
10
22
  taxonName: string;
11
23
  taxonCommonName: string;
12
24
  obsCount: number;
13
25
  };
14
- declare type CommonTaxaRespData = {
26
+ type CommonTaxaRespData = {
15
27
  totalResults: number;
16
28
  results: [CommonTaxData];
17
29
  };
18
- declare const getCommonTaxa: ({ year, taxonId, placeId, numResults }: CommonTaxaCallProps) => Promise<CommonTaxaRespData>;
30
+ declare const getCommonTaxa: ({ year, taxonId, placeId, projectId, numResults }: CommonTaxaCallProps) => Promise<CommonTaxaRespData>;
19
31
 
20
- declare type FavouritesCallProps = {
32
+ type FavouritesCallProps = ObservationFilter & {
21
33
  year: string | number;
22
- taxonId: string | number;
23
- placeId: string | number;
24
34
  numResults: number;
25
35
  };
26
- declare type FavouritesData = {
36
+ type FavouritesData = {
27
37
  id: number;
28
38
  imageUrl: string;
29
39
  taxonName: string;
30
40
  taxonCommonName: string;
31
41
  obsDate: string;
32
- obsCount: number;
42
+ obsUrl: string;
33
43
  observerUsername: string;
34
44
  numFaves: number;
35
45
  };
36
- declare type FavouritesRespData = {
46
+ type FavouritesRespData = {
37
47
  totalResults: number;
38
48
  results: [FavouritesData];
39
49
  };
40
- declare const getFavourites: ({ year, taxonId, placeId, numResults }: FavouritesCallProps) => Promise<FavouritesRespData>;
50
+ declare const getFavourites: ({ year, taxonId, placeId, projectId, numResults }: FavouritesCallProps) => Promise<FavouritesRespData>;
41
51
 
42
- declare type RecentObservationsCallProps = {
43
- taxonId: string | number;
44
- placeId: string | number;
52
+ type RecentObservationsCallProps = ObservationFilter & {
45
53
  numResults: number;
46
54
  };
47
- declare type RecentObservationData = {
55
+ type RecentObservationData = {
48
56
  id: number;
49
57
  imageUrl: string;
50
58
  obsUrl: string;
@@ -53,38 +61,37 @@ declare type RecentObservationData = {
53
61
  taxonCommonName: string;
54
62
  observerUsername: string;
55
63
  };
56
- declare type RecentObservationsRespData = {
64
+ type RecentObservationsRespData = {
57
65
  totalResults: number;
58
66
  results: [RecentObservationData];
59
67
  };
60
- declare const getRecentObservations: ({ taxonId, placeId, numResults }: RecentObservationsCallProps) => Promise<RecentObservationsRespData>;
68
+ declare const getRecentObservations: ({ taxonId, placeId, projectId, numResults }: RecentObservationsCallProps) => Promise<RecentObservationsRespData>;
61
69
 
62
- declare type SummaryApiProps = {
63
- taxonId: number;
64
- placeId: number;
70
+ type SummaryApiProps = ObservationFilter & {
65
71
  year: string | number;
72
+ numTopObservers?: number;
66
73
  };
67
- declare const getSummary: ({ taxonId, placeId, year }: SummaryApiProps) => Promise<any>;
68
- declare type Observer = {
74
+ declare const getSummary: ({ taxonId, placeId, projectId, year, numTopObservers }: SummaryApiProps) => Promise<any>;
75
+ type Observer = {
69
76
  id: number;
70
77
  userName: string;
71
78
  numObservations: number;
72
79
  iconUrl: string | null;
73
80
  };
74
- declare type SummaryData = {
81
+ type SummaryData = {
75
82
  totalCount: number;
76
83
  top: [Observer];
77
84
  };
78
- declare const getObserverSummary: (taxonId: number, placeId: number, year: string | number) => Promise<SummaryData>;
79
- declare const getObservationSummary: (taxonId: number, placeId: number, year: string | number) => Promise<{
85
+ declare const getObserverSummary: (filter: ObservationFilter, year: string | number, numTopObservers?: number) => Promise<SummaryData>;
86
+ declare const getObservationSummary: (filter: ObservationFilter, year: string | number) => Promise<{
80
87
  totalCount: any;
81
88
  }>;
82
- declare type SeasonalityData = {
89
+ type SeasonalityData = {
83
90
  monthOfYear: {
84
91
  [monthNum: string]: number;
85
92
  };
86
93
  };
87
- declare const getSeasonalityData: (taxonId: number, placeId: number, year: string | number) => Promise<SeasonalityData>;
94
+ declare const getSeasonalityData: (filter: ObservationFilter, year: string | number) => Promise<SeasonalityData>;
88
95
 
89
96
  declare enum Feature {
90
97
  commonTaxa = "commonTaxa",
@@ -96,12 +103,12 @@ declare enum DataSourceEnum {
96
103
  autoLoad = "autoLoad",
97
104
  url = "url"
98
105
  }
99
- declare type DataSource = `${DataSourceEnum}`;
100
- declare type ItemConfig = {
101
- id: number;
106
+ type DataSource = `${DataSourceEnum}`;
107
+ type ItemConfig = {
108
+ id: number | string;
102
109
  str: string;
103
110
  };
104
- declare type GeneralClasses = {
111
+ type GeneralClasses = {
105
112
  tabsElement?: string;
106
113
  yearsDropdown?: string;
107
114
  pageHeadings?: string;
@@ -111,9 +118,10 @@ declare type GeneralClasses = {
111
118
  observationLabelName?: string;
112
119
  observationCount?: string;
113
120
  };
114
- declare type BaseComponentProps = {
115
- taxonId?: number;
116
- placeId?: number;
121
+ type BaseComponentProps = {
122
+ taxonId?: number | string;
123
+ placeId?: number | string;
124
+ projectId?: number | string;
117
125
  numResults?: number;
118
126
  source?: DataSource;
119
127
  dataUrl?: string;
@@ -127,14 +135,14 @@ declare type BaseComponentProps = {
127
135
  generalClasses?: GeneralClasses;
128
136
  tabDesc?: string;
129
137
  };
130
- declare type RecentObservationsConfig = {
138
+ type RecentObservationsConfig = {
131
139
  feature: Feature.recentObservations;
132
140
  title?: string;
133
141
  numResults?: number;
134
142
  desc?: string;
135
143
  className?: string;
136
144
  };
137
- declare type CommonTaxaConfig = {
145
+ type CommonTaxaConfig = {
138
146
  feature: Feature.commonTaxa;
139
147
  title?: string;
140
148
  numResults?: number;
@@ -142,7 +150,7 @@ declare type CommonTaxaConfig = {
142
150
  desc?: string;
143
151
  className?: string;
144
152
  };
145
- declare type FavouritesConfig = {
153
+ type FavouritesConfig = {
146
154
  feature: Feature.favourites;
147
155
  title?: string;
148
156
  numResults?: number;
@@ -150,7 +158,7 @@ declare type FavouritesConfig = {
150
158
  desc?: string;
151
159
  className?: string;
152
160
  };
153
- declare type StatsConfig = {
161
+ type StatsConfig = {
154
162
  feature: Feature.stats;
155
163
  title?: string;
156
164
  numTopObservers?: number;
@@ -160,9 +168,9 @@ declare type StatsConfig = {
160
168
  observersListClass?: string;
161
169
  statsCountSummaryClass?: string;
162
170
  };
163
- declare type TaxonPanelFeatures = (RecentObservationsConfig | CommonTaxaConfig | FavouritesConfig | StatsConfig)[];
171
+ type TaxonPanelFeatures = (RecentObservationsConfig | CommonTaxaConfig | FavouritesConfig | StatsConfig)[];
164
172
 
165
- declare const getSourceFile: (api: Feature, taxon: ItemConfig, place: ItemConfig, year?: string | number) => string;
173
+ declare const getSourceFile: (api: Feature, taxon: ItemConfig | undefined, place: ItemConfig | undefined, year?: string | number, project?: ItemConfig) => string;
166
174
 
167
175
  declare const getCurrentYear: () => number;
168
176
  declare const formatDate: (date: string, dateFormat?: string) => any;
@@ -173,78 +181,80 @@ declare const BASE_API_URL = "https://api.inaturalist.org";
173
181
  declare const NUM_RESULTS = 100;
174
182
  declare const DEFAULT_NUM_YEARS = 10;
175
183
  declare const BASE_URL = "https://www.inaturalist.org";
176
- declare const ERROR_LOG_FILENAME = "inat-components-error.log";
177
184
  declare const DEFAULT_ITEM_WIDTH = 150;
185
+ declare const DEFAULT_NUM_TOP_OBSERVERS = 10;
178
186
 
179
187
  declare const constants_BASE_API_URL: typeof BASE_API_URL;
180
188
  declare const constants_NUM_RESULTS: typeof NUM_RESULTS;
181
189
  declare const constants_DEFAULT_NUM_YEARS: typeof DEFAULT_NUM_YEARS;
182
190
  declare const constants_BASE_URL: typeof BASE_URL;
183
- declare const constants_ERROR_LOG_FILENAME: typeof ERROR_LOG_FILENAME;
184
191
  declare const constants_DEFAULT_ITEM_WIDTH: typeof DEFAULT_ITEM_WIDTH;
192
+ declare const constants_DEFAULT_NUM_TOP_OBSERVERS: typeof DEFAULT_NUM_TOP_OBSERVERS;
185
193
  declare namespace constants {
186
194
  export {
187
195
  constants_BASE_API_URL as BASE_API_URL,
188
196
  constants_NUM_RESULTS as NUM_RESULTS,
189
197
  constants_DEFAULT_NUM_YEARS as DEFAULT_NUM_YEARS,
190
198
  constants_BASE_URL as BASE_URL,
191
- constants_ERROR_LOG_FILENAME as ERROR_LOG_FILENAME,
192
199
  constants_DEFAULT_ITEM_WIDTH as DEFAULT_ITEM_WIDTH,
200
+ constants_DEFAULT_NUM_TOP_OBSERVERS as DEFAULT_NUM_TOP_OBSERVERS,
193
201
  };
194
202
  }
195
203
 
196
- declare type TaxonPanelProps = {
197
- taxon: {
198
- id: number;
199
- str: string;
200
- };
201
- place: {
202
- id: number;
203
- str: string;
204
- };
205
- dataSourceBaseUrl: string;
204
+ type TaxonPanelProps = {
205
+ taxon?: ItemConfig;
206
+ place?: ItemConfig;
207
+ project?: ItemConfig;
208
+ dataSourceBaseUrl?: string;
206
209
  dataSource: DataSource;
207
210
  features: TaxonPanelFeatures;
208
- generalClasses: GeneralClasses;
211
+ generalClasses?: GeneralClasses;
209
212
  itemWidth?: number;
210
213
  };
211
- declare const TaxonPanel: ({ taxon, place, features, dataSource, dataSourceBaseUrl, itemWidth, generalClasses }: TaxonPanelProps) => JSX.Element;
214
+ declare const TaxonPanel: ({ taxon, place, project, features, dataSource, dataSourceBaseUrl, itemWidth, generalClasses }: TaxonPanelProps) => React.JSX.Element;
212
215
 
213
- declare type ObservationProps = {
216
+ /**
217
+ * The columns of a grid of observations. Each is at least `itemWidth` wide, but no wider than allows two across a narrow
218
+ * screen, and a row of fewer results than fill it leaves the rest empty, rather than stretching them across it.
219
+ * @param itemWidth - The least width of a column, in pixels
220
+ * @return The value of the grid's `grid-template-columns`
221
+ */
222
+ declare const gridColumns: (itemWidth: number) => string;
223
+ type ObservationProps = {
214
224
  imageUrl: string;
215
225
  linkUrl: string;
216
- itemWidth: number;
217
226
  children: any;
218
227
  };
219
- declare const Observation: ({ imageUrl, linkUrl, itemWidth, children }: ObservationProps) => JSX.Element;
228
+ declare const Observation: ({ imageUrl, linkUrl, children }: ObservationProps) => React.JSX.Element;
220
229
 
221
- declare type CommonTaxaProps = BaseComponentProps & {
230
+ type CommonTaxaProps = BaseComponentProps & {
222
231
  year: number;
223
232
  };
224
233
  declare const CommonTaxaLabel: (data: CommonTaxData & {
225
234
  classes: GeneralClasses;
226
- }) => JSX.Element;
227
- declare const CommonTaxa: ({ year, source, taxonId, placeId, numResults, itemWidth, dataUrl, components, generalClasses, className, tabDesc }: CommonTaxaProps) => JSX.Element;
235
+ }) => React.JSX.Element;
236
+ declare const CommonTaxa: ({ year, source, taxonId, placeId, projectId, numResults, itemWidth, dataUrl, components, generalClasses, className, tabDesc }: CommonTaxaProps) => React.JSX.Element;
228
237
 
229
- declare type RecentObservationsProps = BaseComponentProps;
238
+ type RecentObservationsProps = BaseComponentProps;
230
239
  declare const RecentObservationLabel: (obs: RecentObservationData & {
231
240
  classes: GeneralClasses;
232
- }) => JSX.Element;
233
- declare const RecentObservations: ({ taxonId, placeId, dataUrl, components, className, generalClasses, tabDesc, source, numResults, itemWidth }: RecentObservationsProps) => JSX.Element;
241
+ }) => React.JSX.Element;
242
+ declare const RecentObservations: ({ taxonId, placeId, projectId, dataUrl, components, className, generalClasses, tabDesc, source, numResults, itemWidth }: RecentObservationsProps) => React.JSX.Element;
234
243
 
235
- declare type FavouritesProps = BaseComponentProps & {
244
+ type FavouritesProps = BaseComponentProps & {
236
245
  year: number | string;
237
246
  };
238
247
  declare const FavouritesLabel: (data: FavouritesData & {
239
248
  classes: GeneralClasses;
240
- }) => JSX.Element;
241
- declare const Favourites: ({ year, source, taxonId, placeId, dataUrl, components, className, tabDesc, generalClasses, itemWidth, numResults }: FavouritesProps) => JSX.Element;
249
+ }) => React.JSX.Element;
250
+ declare const Favourites: ({ year, source, taxonId, placeId, projectId, dataUrl, components, className, tabDesc, generalClasses, itemWidth, numResults }: FavouritesProps) => React.JSX.Element;
242
251
 
243
- declare const SeasonalityGraph: ({ data }: any) => JSX.Element;
252
+ declare const SeasonalityGraph: ({ data }: any) => React.JSX.Element;
244
253
 
245
- declare type SummaryProps = {
246
- taxonId: number;
247
- placeId: number;
254
+ type SummaryProps = {
255
+ taxonId?: number | string;
256
+ placeId?: number | string;
257
+ projectId?: number | string;
248
258
  year: number;
249
259
  source: DataSource;
250
260
  dataUrl?: string;
@@ -253,7 +263,9 @@ declare type SummaryProps = {
253
263
  tabDesc?: string;
254
264
  observersListClass?: string;
255
265
  statsCountSummaryClass?: string;
266
+ numTopObservers?: number;
267
+ components?: BaseComponentProps["components"];
256
268
  };
257
- declare const Summary: ({ source, dataUrl, taxonId, placeId, year, generalClasses, className, tabDesc, observersListClass, statsCountSummaryClass }: SummaryProps) => JSX.Element;
269
+ declare const Summary: ({ source, dataUrl, taxonId, placeId, projectId, year, generalClasses, className, tabDesc, observersListClass, statsCountSummaryClass, numTopObservers, components }: SummaryProps) => React.JSX.Element;
258
270
 
259
- export { BaseComponentProps, constants as C, CommonTaxData, CommonTaxa, CommonTaxaCallProps, CommonTaxaConfig, CommonTaxaLabel, CommonTaxaProps, CommonTaxaRespData, DataSource, DataSourceEnum, Favourites, FavouritesCallProps, FavouritesConfig, FavouritesData, FavouritesLabel, FavouritesProps, FavouritesRespData, Feature, GeneralClasses, ItemConfig, Observation, ObservationProps, Observer, RecentObservationData, RecentObservationLabel, RecentObservations, RecentObservationsCallProps, RecentObservationsConfig, RecentObservationsProps, RecentObservationsRespData, SeasonalityData, SeasonalityGraph, StatsConfig, Summary, SummaryApiProps, SummaryData, SummaryProps, TaxonPanelFeatures, TaxonPanelProps, TaxonPanel as default, formatDate, getCommonTaxa, getCurrentYear, getFavourites, getObservationSummary, getObserverSummary, getRecentObservations, getSeasonalityData, getSourceFile, getSummary, numberWithCommas };
271
+ export { BaseComponentProps, constants as C, CommonTaxData, CommonTaxa, CommonTaxaCallProps, CommonTaxaConfig, CommonTaxaLabel, CommonTaxaProps, CommonTaxaRespData, DataSource, DataSourceEnum, Favourites, FavouritesCallProps, FavouritesConfig, FavouritesData, FavouritesLabel, FavouritesProps, FavouritesRespData, Feature, GeneralClasses, ItemConfig, Observation, ObservationFilter, ObservationProps, Observer, RecentObservationData, RecentObservationLabel, RecentObservations, RecentObservationsCallProps, RecentObservationsConfig, RecentObservationsProps, RecentObservationsRespData, SeasonalityData, SeasonalityGraph, StatsConfig, Summary, SummaryApiProps, SummaryData, SummaryProps, TaxonPanelFeatures, TaxonPanelProps, TaxonPanel as default, filterParams, formatDate, getCommonTaxa, getCurrentYear, getFavourites, getObservationSummary, getObserverSummary, getRecentObservations, getSeasonalityData, getSourceFile, getSummary, gridColumns, numberWithCommas };