@imerss/inat-components 1.1.1 → 2.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 (34) hide show
  1. package/PUBLISH.md +13 -0
  2. package/README.md +20 -0
  3. package/dist/index.d.ts +118 -73
  4. package/dist/index.js +322 -389
  5. package/dist/standalone.min.js +3 -0
  6. package/package.json +17 -5
  7. package/public/standalone.html +55 -0
  8. package/rollup.config.js +15 -4
  9. package/src/__shared/api/common-taxa.ts +3 -3
  10. package/src/__shared/api/favourites.ts +6 -11
  11. package/src/__shared/api/recent-observations.ts +3 -3
  12. package/src/__shared/api/summary.ts +1 -0
  13. package/src/__shared/constants.ts +3 -1
  14. package/src/__shared/index.ts +1 -1
  15. package/src/__shared/typings.ts +58 -44
  16. package/src/__shared/utils/configUtils.ts +10 -6
  17. package/src/__shared/utils/dateUtils.ts +1 -1
  18. package/src/components/common-taxa/common-taxa.tsx +34 -60
  19. package/src/components/error/error.tsx +1 -1
  20. package/src/components/favourites/favourites.tsx +35 -60
  21. package/src/components/hooks/hooks.tsx +20 -10
  22. package/src/components/loader/loader.tsx +1 -1
  23. package/src/components/observation/observation.tsx +5 -4
  24. package/src/components/recent-observations/recent-observations.tsx +43 -60
  25. package/src/components/shared/css/general.module.scss +5 -1
  26. package/src/components/summary/ObserverList.tsx +21 -15
  27. package/src/components/summary/summary.tsx +59 -51
  28. package/src/components/tabs/tabs.tsx +48 -27
  29. package/src/components/taxon-panel/taxon-panel.tsx +83 -77
  30. package/src/components/year-dropdown/year-dropdown.tsx +11 -7
  31. package/src/hooks/useLoadSourceData.ts +81 -0
  32. package/src/index.ts +1 -1
  33. package/src/types/index.d.ts +17 -0
  34. package/src/types/standalone.d.ts +6 -0
package/PUBLISH.md ADDED
@@ -0,0 +1,13 @@
1
+ ### Publishing new versions
2
+
3
+ Here's how to publish a new version of this package.
4
+
5
+ 1. Go to the root of the monorepo and run `yarn install`, then `yarn boot`
6
+ 2. Update the version in `packages/inat-component`'s package.json
7
+ 3. Run `yarn build` to generate a fresh `/dist` folder (you can clean first, but the clean command currently also
8
+ deletes __shared, so you'll need to rebuild from the root if you do that)
9
+
10
+ Step 3 actually generates + copies over the result from the inat-components-standalone package, so in the dist folder
11
+ you should see a standalone.min.js file. All is good!
12
+
13
+ Now you can `npm publish`.
package/README.md CHANGED
@@ -0,0 +1,20 @@
1
+ # inat-components
2
+
3
+
4
+
5
+ ### Standalone app
6
+
7
+ From `@imerss/inat-components` 2.0.0 onwards, the package contains a `/dist/standalone.min.js` script which can be used
8
+ for any.
9
+
10
+ Usage:
11
+
12
+ 1. Download the package from npmjs.org either manually, or via `npm install @imerss/inat-components`.
13
+ 2. Copy the standalone.min.js file onto your site.
14
+ 3. Add it to your page:
15
+
16
+ ```
17
+ <script src="./path/to/standalone.min.js"></script>
18
+ ```
19
+
20
+ 4.
package/dist/index.d.ts CHANGED
@@ -1,17 +1,8 @@
1
- declare const TaxonPanel: ({ taxonId, placeId, dataSource, config, baseURL }: any) => JSX.Element;
2
-
3
- declare type ObservationProps = {
4
- imageUrl: string;
5
- linkUrl: string;
6
- children: any;
7
- };
8
- declare const Observation: ({ imageUrl, linkUrl, children }: ObservationProps) => JSX.Element;
9
-
10
1
  declare type CommonTaxaCallProps = {
11
2
  year: string | number;
12
3
  taxonId: string | number;
13
4
  placeId: string | number;
14
- perPage: number;
5
+ numResults: number;
15
6
  };
16
7
  declare type CommonTaxData = {
17
8
  id: number;
@@ -24,13 +15,13 @@ declare type CommonTaxaRespData = {
24
15
  totalResults: number;
25
16
  results: [CommonTaxData];
26
17
  };
27
- declare const getCommonTaxa: ({ year, taxonId, placeId, perPage }: CommonTaxaCallProps) => Promise<CommonTaxaRespData>;
18
+ declare const getCommonTaxa: ({ year, taxonId, placeId, numResults }: CommonTaxaCallProps) => Promise<CommonTaxaRespData>;
28
19
 
29
20
  declare type FavouritesCallProps = {
30
21
  year: string | number;
31
22
  taxonId: string | number;
32
23
  placeId: string | number;
33
- perPage: number;
24
+ numResults: number;
34
25
  };
35
26
  declare type FavouritesData = {
36
27
  id: number;
@@ -46,12 +37,12 @@ declare type FavouritesRespData = {
46
37
  totalResults: number;
47
38
  results: [FavouritesData];
48
39
  };
49
- declare const getFavourites: ({ year, taxonId, placeId, perPage }: FavouritesCallProps) => Promise<FavouritesRespData>;
40
+ declare const getFavourites: ({ year, taxonId, placeId, numResults }: FavouritesCallProps) => Promise<FavouritesRespData>;
50
41
 
51
42
  declare type RecentObservationsCallProps = {
52
43
  taxonId: string | number;
53
44
  placeId: string | number;
54
- perPage: number;
45
+ numResults: number;
55
46
  };
56
47
  declare type RecentObservationData = {
57
48
  id: number;
@@ -66,7 +57,7 @@ declare type RecentObservationsRespData = {
66
57
  totalResults: number;
67
58
  results: [RecentObservationData];
68
59
  };
69
- declare const getRecentObservations: ({ taxonId, placeId, perPage }: RecentObservationsCallProps) => Promise<RecentObservationsRespData>;
60
+ declare const getRecentObservations: ({ taxonId, placeId, numResults }: RecentObservationsCallProps) => Promise<RecentObservationsRespData>;
70
61
 
71
62
  declare type SummaryApiProps = {
72
63
  taxonId: number;
@@ -95,70 +86,83 @@ declare type SeasonalityData = {
95
86
  };
96
87
  declare const getSeasonalityData: (taxonId: number, placeId: number, year: string | number) => Promise<SeasonalityData>;
97
88
 
98
- declare type ConfigFile = {
99
- taxa: TaxaConfig[];
100
- places: PlaceConfig[];
101
- features: {
102
- [Feature.commonTaxa]?: {
103
- numResults?: number;
104
- };
105
- [Feature.favourites]?: {
106
- numResults?: number;
107
- numYears?: number;
108
- };
109
- [Feature.recentObservations]?: {
110
- numResults?: number;
111
- numYears?: number;
112
- };
113
- [Feature.stats]?: {
114
- numTopObservers?: number;
115
- };
116
- };
117
- };
118
- declare enum DataSource {
119
- autoLoad = "autoLoad",
120
- dataProp = "dataProp",
121
- url = "url"
122
- }
123
89
  declare enum Feature {
124
90
  commonTaxa = "commonTaxa",
125
91
  favourites = "favourites",
126
92
  recentObservations = "recentObservations",
127
93
  stats = "stats"
128
94
  }
129
- declare enum Tab {
130
- recent = "recent",
131
- commonTaxa = "commonTaxa",
132
- favourites = "favourites",
133
- stats = "stats"
95
+ declare enum DataSourceEnum {
96
+ autoLoad = "autoLoad",
97
+ url = "url"
134
98
  }
99
+ declare type DataSource = `${DataSourceEnum}`;
100
+ declare type ItemConfig = {
101
+ id: number;
102
+ str: string;
103
+ };
104
+ declare type GeneralClasses = {
105
+ tabsElement?: string;
106
+ yearsDropdown?: string;
107
+ pageHeadings?: string;
108
+ tabDesc?: string;
109
+ observationLabelTitle?: string;
110
+ observationLabelDate?: string;
111
+ observationLabelName?: string;
112
+ observationCount?: string;
113
+ };
135
114
  declare type BaseComponentProps = {
136
115
  taxonId?: number;
137
116
  placeId?: number;
138
- filename?: string;
139
- perPage?: number;
117
+ numResults?: number;
140
118
  source?: DataSource;
141
- data?: any;
142
119
  dataUrl?: string;
143
120
  className?: string;
121
+ itemWidth?: number;
144
122
  components?: {
145
123
  label?: any;
146
124
  error?: any;
147
125
  loader?: any;
148
126
  };
127
+ generalClasses?: GeneralClasses;
128
+ tabDesc?: string;
149
129
  };
150
- declare type TaxaConfig = {
151
- label: string;
152
- short: string;
153
- taxonId: number;
130
+ declare type RecentObservationsConfig = {
131
+ feature: Feature.recentObservations;
132
+ title?: string;
133
+ numResults?: number;
134
+ desc?: string;
135
+ className?: string;
154
136
  };
155
- declare type PlaceConfig = {
156
- label: string;
157
- short: string;
158
- placeId: number;
137
+ declare type CommonTaxaConfig = {
138
+ feature: Feature.commonTaxa;
139
+ title?: string;
140
+ numResults?: number;
141
+ numYears?: number;
142
+ desc?: string;
143
+ className?: string;
144
+ };
145
+ declare type FavouritesConfig = {
146
+ feature: Feature.favourites;
147
+ title?: string;
148
+ numResults?: number;
149
+ numYears?: number;
150
+ desc?: string;
151
+ className?: string;
152
+ };
153
+ declare type StatsConfig = {
154
+ feature: Feature.stats;
155
+ title?: string;
156
+ numTopObservers?: number;
157
+ numYears?: number;
158
+ desc?: string;
159
+ className?: string;
160
+ observersListClass?: string;
161
+ statsCountSummaryClass?: string;
159
162
  };
163
+ declare type TaxonPanelFeatures = (RecentObservationsConfig | CommonTaxaConfig | FavouritesConfig | StatsConfig)[];
160
164
 
161
- declare const getSourceFile: (api: Feature, taxonInfo: TaxaConfig, placeInfo: PlaceConfig, year?: string | number) => string;
165
+ declare const getSourceFile: (api: Feature, taxon: ItemConfig, place: ItemConfig, year?: string | number) => string;
162
166
 
163
167
  declare const getCurrentYear: () => number;
164
168
  declare const formatDate: (date: string, dateFormat?: string) => any;
@@ -166,49 +170,90 @@ declare const formatDate: (date: string, dateFormat?: string) => any;
166
170
  declare const numberWithCommas: (x: number) => string;
167
171
 
168
172
  declare const BASE_API_URL = "https://api.inaturalist.org";
169
- declare const PER_PAGE = 100;
173
+ declare const NUM_RESULTS = 100;
174
+ declare const DEFAULT_NUM_YEARS = 10;
170
175
  declare const BASE_URL = "https://www.inaturalist.org";
171
176
  declare const ERROR_LOG_FILENAME = "inat-components-error.log";
177
+ declare const DEFAULT_ITEM_WIDTH = 150;
172
178
 
173
179
  declare const constants_BASE_API_URL: typeof BASE_API_URL;
174
- declare const constants_PER_PAGE: typeof PER_PAGE;
180
+ declare const constants_NUM_RESULTS: typeof NUM_RESULTS;
181
+ declare const constants_DEFAULT_NUM_YEARS: typeof DEFAULT_NUM_YEARS;
175
182
  declare const constants_BASE_URL: typeof BASE_URL;
176
183
  declare const constants_ERROR_LOG_FILENAME: typeof ERROR_LOG_FILENAME;
184
+ declare const constants_DEFAULT_ITEM_WIDTH: typeof DEFAULT_ITEM_WIDTH;
177
185
  declare namespace constants {
178
186
  export {
179
187
  constants_BASE_API_URL as BASE_API_URL,
180
- constants_PER_PAGE as PER_PAGE,
188
+ constants_NUM_RESULTS as NUM_RESULTS,
189
+ constants_DEFAULT_NUM_YEARS as DEFAULT_NUM_YEARS,
181
190
  constants_BASE_URL as BASE_URL,
182
191
  constants_ERROR_LOG_FILENAME as ERROR_LOG_FILENAME,
192
+ constants_DEFAULT_ITEM_WIDTH as DEFAULT_ITEM_WIDTH,
183
193
  };
184
194
  }
185
195
 
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;
206
+ dataSource: DataSource;
207
+ features: TaxonPanelFeatures;
208
+ generalClasses: GeneralClasses;
209
+ itemWidth?: number;
210
+ };
211
+ declare const TaxonPanel: ({ taxon, place, features, dataSource, dataSourceBaseUrl, itemWidth, generalClasses }: TaxonPanelProps) => JSX.Element;
212
+
213
+ declare type ObservationProps = {
214
+ imageUrl: string;
215
+ linkUrl: string;
216
+ itemWidth: number;
217
+ children: any;
218
+ };
219
+ declare const Observation: ({ imageUrl, linkUrl, itemWidth, children }: ObservationProps) => JSX.Element;
220
+
186
221
  declare type CommonTaxaProps = BaseComponentProps & {
187
- year: string | number;
222
+ year: number;
188
223
  };
189
- declare const CommonTaxaLabel: (data: CommonTaxData) => JSX.Element;
190
- declare const CommonTaxa: ({ year, source, taxonId, placeId, perPage, data, dataUrl, components, className }: CommonTaxaProps) => JSX.Element;
224
+ declare const CommonTaxaLabel: (data: CommonTaxData & {
225
+ classes: GeneralClasses;
226
+ }) => JSX.Element;
227
+ declare const CommonTaxa: ({ year, source, taxonId, placeId, numResults, itemWidth, dataUrl, components, generalClasses, className, tabDesc }: CommonTaxaProps) => JSX.Element;
191
228
 
192
229
  declare type RecentObservationsProps = BaseComponentProps;
193
- declare const RecentObservationLabel: (obs: RecentObservationData) => JSX.Element;
194
- declare const RecentObservations: ({ taxonId, placeId, data, dataUrl, source, perPage, components, className }: RecentObservationsProps) => JSX.Element;
230
+ declare const RecentObservationLabel: (obs: RecentObservationData & {
231
+ classes: GeneralClasses;
232
+ }) => JSX.Element;
233
+ declare const RecentObservations: ({ taxonId, placeId, dataUrl, components, className, generalClasses, tabDesc, source, numResults, itemWidth }: RecentObservationsProps) => JSX.Element;
195
234
 
196
235
  declare type FavouritesProps = BaseComponentProps & {
197
- year: string | number;
236
+ year: number | string;
198
237
  };
199
- declare const FavouritesLabel: (data: FavouritesData) => JSX.Element;
200
- declare const Favourites: ({ year, source, taxonId, placeId, data, dataUrl, components, className, perPage }: FavouritesProps) => JSX.Element;
238
+ declare const FavouritesLabel: (data: FavouritesData & {
239
+ classes: GeneralClasses;
240
+ }) => JSX.Element;
241
+ declare const Favourites: ({ year, source, taxonId, placeId, dataUrl, components, className, tabDesc, generalClasses, itemWidth, numResults }: FavouritesProps) => JSX.Element;
201
242
 
202
243
  declare const SeasonalityGraph: ({ data }: any) => JSX.Element;
203
244
 
204
245
  declare type SummaryProps = {
205
- source: DataSource;
206
246
  taxonId: number;
207
247
  placeId: number;
208
- year: string | number;
209
- data?: FavouritesRespData;
248
+ year: number;
249
+ source: DataSource;
210
250
  dataUrl?: string;
251
+ generalClasses?: GeneralClasses;
252
+ className?: string;
253
+ tabDesc?: string;
254
+ observersListClass?: string;
255
+ statsCountSummaryClass?: string;
211
256
  };
212
- declare const Summary: ({ source, data, dataUrl, taxonId, placeId, year }: SummaryProps) => JSX.Element;
257
+ declare const Summary: ({ source, dataUrl, taxonId, placeId, year, generalClasses, className, tabDesc, observersListClass, statsCountSummaryClass }: SummaryProps) => JSX.Element;
213
258
 
214
- export { BaseComponentProps, constants as C, CommonTaxData, CommonTaxa, CommonTaxaCallProps, CommonTaxaLabel, CommonTaxaProps, CommonTaxaRespData, ConfigFile, DataSource, Favourites, FavouritesCallProps, FavouritesData, FavouritesLabel, FavouritesProps, FavouritesRespData, Feature, Observation, ObservationProps, Observer, PlaceConfig, RecentObservationData, RecentObservationLabel, RecentObservations, RecentObservationsCallProps, RecentObservationsProps, RecentObservationsRespData, SeasonalityData, SeasonalityGraph, Summary, SummaryApiProps, SummaryData, SummaryProps, Tab, TaxaConfig, TaxonPanel as default, formatDate, getCommonTaxa, getCurrentYear, getFavourites, getObservationSummary, getObserverSummary, getRecentObservations, getSeasonalityData, getSourceFile, getSummary, numberWithCommas };
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 };