col-browser 2.0.1 → 2.2.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 (74) hide show
  1. package/es/bibtex.js +8 -0
  2. package/es/bibtex.js.map +1 -0
  3. package/es/chunks/AntdIcon-B1nMlqyh.js +984 -0
  4. package/es/chunks/AntdIcon-B1nMlqyh.js.map +1 -0
  5. package/es/chunks/BibTex-BqzD3qLB.js +13 -0
  6. package/es/chunks/BibTex-BqzD3qLB.js.map +1 -0
  7. package/es/chunks/DatasetCitation-bkPmDDYB.js +119 -0
  8. package/es/chunks/DatasetCitation-bkPmDDYB.js.map +1 -0
  9. package/es/chunks/DatasetlogoWithFallback-CbP7vRs_.js +823 -0
  10. package/es/chunks/DatasetlogoWithFallback-CbP7vRs_.js.map +1 -0
  11. package/es/chunks/Distributions-CXIEJ6e6.js +1131 -0
  12. package/es/chunks/Distributions-CXIEJ6e6.js.map +1 -0
  13. package/es/chunks/ErrorMsg-K8k5PPTp.js +26 -0
  14. package/es/chunks/ErrorMsg-K8k5PPTp.js.map +1 -0
  15. package/es/chunks/LinkOutlined-2IkQWTV7.js +22 -0
  16. package/es/chunks/LinkOutlined-2IkQWTV7.js.map +1 -0
  17. package/es/chunks/MergedDataBadge-DsTsn5Xu.js +134 -0
  18. package/es/chunks/MergedDataBadge-DsTsn5Xu.js.map +1 -0
  19. package/es/chunks/MetricsPresentation-U_CO8JoH.js +66 -0
  20. package/es/chunks/MetricsPresentation-U_CO8JoH.js.map +1 -0
  21. package/es/chunks/TaxonBreakdown-BzDHojmp.js +210 -0
  22. package/es/chunks/TaxonBreakdown-BzDHojmp.js.map +1 -0
  23. package/es/chunks/config-BPRXv9x8.js +31 -0
  24. package/es/chunks/config-BPRXv9x8.js.map +1 -0
  25. package/es/chunks/dataset-DvQG4NjA.js +30 -0
  26. package/es/chunks/dataset-DvQG4NjA.js.map +1 -0
  27. package/es/chunks/enumeration-yDQXSZsf.js +12 -0
  28. package/es/chunks/enumeration-yDQXSZsf.js.map +1 -0
  29. package/es/chunks/index-CNK3JADR.js +95 -0
  30. package/es/chunks/index-CNK3JADR.js.map +1 -0
  31. package/es/chunks/jsx-runtime-BzflLqGi.js +283 -0
  32. package/es/chunks/jsx-runtime-BzflLqGi.js.map +1 -0
  33. package/es/chunks/router-CssZk5qZ.js +109 -0
  34. package/es/chunks/router-CssZk5qZ.js.map +1 -0
  35. package/es/chunks/sector-BnVzMnMO.js +9 -0
  36. package/es/chunks/sector-BnVzMnMO.js.map +1 -0
  37. package/es/chunks/storage-BgdCo9fV.js +20 -0
  38. package/es/chunks/storage-BgdCo9fV.js.map +1 -0
  39. package/es/chunks/withDatasetKey-BgMY05XE.js +48 -0
  40. package/es/chunks/withDatasetKey-BgMY05XE.js.map +1 -0
  41. package/es/col-browser.css +1 -1
  42. package/es/index.js +18 -7964
  43. package/es/index.js.map +1 -1
  44. package/es/routing.js +5 -0
  45. package/es/routing.js.map +1 -0
  46. package/es/search.js +810 -0
  47. package/es/search.js.map +1 -0
  48. package/es/sourceDataset.js +453 -0
  49. package/es/sourceDataset.js.map +1 -0
  50. package/es/sourceDatasetList.js +366 -0
  51. package/es/sourceDatasetList.js.map +1 -0
  52. package/es/taxon.js +1643 -0
  53. package/es/taxon.js.map +1 -0
  54. package/es/taxonBreakdown.js +44 -0
  55. package/es/taxonBreakdown.js.map +1 -0
  56. package/es/taxonDistribution.js +50 -0
  57. package/es/taxonDistribution.js.map +1 -0
  58. package/es/tree.js +823 -0
  59. package/es/tree.js.map +1 -0
  60. package/package.json +48 -7
  61. package/types/bibtex.d.ts +1 -0
  62. package/types/index.d.ts +162 -0
  63. package/types/routing.d.ts +1 -0
  64. package/types/search.d.ts +1 -0
  65. package/types/sourceDataset.d.ts +1 -0
  66. package/types/sourceDatasetList.d.ts +1 -0
  67. package/types/taxon.d.ts +1 -0
  68. package/types/taxonBreakdown.d.ts +1 -0
  69. package/types/taxonDistribution.d.ts +1 -0
  70. package/types/tree.d.ts +1 -0
  71. package/umd/col-browser.js +8830 -15340
  72. package/umd/col-browser.js.map +1 -1
  73. package/umd/col-browser.min.js +5 -13
  74. package/umd/col-browser.min.js.map +1 -1
package/es/tree.js ADDED
@@ -0,0 +1,823 @@
1
+ var J = Object.defineProperty;
2
+ var Q = (C, y, e) => y in C ? J(C, y, { enumerable: !0, configurable: !0, writable: !0, value: e }) : C[y] = e;
3
+ var c = (C, y, e) => Q(C, typeof y != "symbol" ? y + "" : y, e);
4
+ import { a as X } from "./chunks/withDatasetKey-BgMY05XE.js";
5
+ import { c as S, w as Y } from "./chunks/config-BPRXv9x8.js";
6
+ import { j as t } from "./chunks/jsx-runtime-BzflLqGi.js";
7
+ import j, { createContext as ee } from "react";
8
+ import { Popover as te, Divider as se, Spin as R, Tag as ae, Alert as b, Skeleton as oe, Tree as ie, Button as ne, Row as re, Col as v, Checkbox as $ } from "antd";
9
+ import { sortBy as N, get as m, isUndefined as I, flatten as le, isArray as A } from "lodash-es";
10
+ import { L, c as D, R as U, s as de, b as he } from "./chunks/router-CssZk5qZ.js";
11
+ import T from "dataloader";
12
+ import { c as W, b as H, g as ce } from "./chunks/dataset-DvQG4NjA.js";
13
+ import { M as pe } from "./chunks/MergedDataBadge-DsTsn5Xu.js";
14
+ import { E as ue } from "./chunks/ErrorMsg-K8k5PPTp.js";
15
+ import { g as fe } from "./chunks/sector-BnVzMnMO.js";
16
+ import { C as F, N as xe } from "./chunks/DatasetCitation-bkPmDDYB.js";
17
+ import { r as O, w as M } from "./chunks/storage-BgdCo9fV.js";
18
+ const w = ee({
19
+ datasetLoader: null,
20
+ publisherLoader: null
21
+ }), B = (C) => ({
22
+ datasetLoader: new T((y) => H(y, C)),
23
+ publisherLoader: new T(
24
+ (y) => W(y, C)
25
+ )
26
+ });
27
+ class V extends j.Component {
28
+ constructor(e) {
29
+ super(e);
30
+ // Returns the shared cache from TreeCacheContext if available, or a
31
+ // throwaway local DataLoader so the popover still works even if context
32
+ // doesn't reach this instance (which used to leave the spinner stuck
33
+ // because getData early-returned with no loading state set).
34
+ c(this, "getDatasetLoader", () => {
35
+ var s;
36
+ const { datasetKey: e } = this.props;
37
+ return (s = this.context) != null && s.datasetLoader ? this.context.datasetLoader : (this._localDatasetLoader || (this._localDatasetLoader = new T(
38
+ (o) => H(o, e)
39
+ )), this._localDatasetLoader);
40
+ });
41
+ c(this, "getPublisherLoader", () => {
42
+ var s;
43
+ const { datasetKey: e } = this.props;
44
+ return (s = this.context) != null && s.publisherLoader ? this.context.publisherLoader : (this._localPublisherLoader || (this._localPublisherLoader = new T(
45
+ (o) => W(o, e)
46
+ )), this._localPublisherLoader);
47
+ });
48
+ c(this, "componentDidMount", () => {
49
+ const { sourceDatasetKeys: e } = this.props;
50
+ e && e.length < 4 && this.setState({ showInNode: !0 }, this.getData);
51
+ });
52
+ c(this, "getData", () => {
53
+ const { sourceDatasetKeys: e } = this.props;
54
+ if (!(e != null && e.length)) return;
55
+ this.setState({ loading: !0 });
56
+ const s = this.getDatasetLoader();
57
+ Promise.all(
58
+ e.map((o) => s.load(o).catch(() => null))
59
+ ).then((o) => {
60
+ this.setState({ data: N(o, ["alias"]), loading: !1 });
61
+ }).catch(() => {
62
+ this.setState({ data: [], loading: !1 });
63
+ });
64
+ });
65
+ c(this, "getPublisherData", () => {
66
+ const { publisherDatasetKeys: e } = this.props;
67
+ if (!e) return;
68
+ const s = this.getPublisherLoader();
69
+ Promise.all(
70
+ Object.keys(e).map(
71
+ (o) => s.load(o).then((r) => ({
72
+ ...r,
73
+ datasets: e[o]
74
+ })).catch(() => null)
75
+ )
76
+ ).then((o) => {
77
+ this.setState({ publishers: N(o.filter(Boolean), ["alias"]) });
78
+ }).catch(() => {
79
+ this.setState({ publishers: [] });
80
+ });
81
+ });
82
+ c(this, "render", () => {
83
+ const { data: e, showInNode: s, popOverVisible: o, loading: r } = this.state, { taxon: l, datasetKey: h } = this.props, n = { color: "orange", fontSize: "11px" }, u = (a) => `${S.clbPortal}/dataset/${h}/publisher/${a}`;
84
+ return s ? e.filter((a) => !!a).map((a, d) => /* @__PURE__ */ t.jsx(
85
+ L,
86
+ {
87
+ to: "source",
88
+ args: a.key,
89
+ className: "col-tree-data-source",
90
+ style: n,
91
+ children: (d ? ", " : "") + (a.alias || a.key)
92
+ },
93
+ a.key
94
+ )) : /* @__PURE__ */ t.jsx("div", { style: { display: "inline" }, id: `taxon_sources_${l.id}`, children: /* @__PURE__ */ t.jsx(
95
+ te,
96
+ {
97
+ getPopupContainer: () => document.getElementById(`taxon_sources_${l.id}`),
98
+ content: r || e.length === 0 ? /* @__PURE__ */ t.jsx(
99
+ "div",
100
+ {
101
+ style: { minWidth: "200px", textAlign: "center", padding: "8px 0" },
102
+ children: /* @__PURE__ */ t.jsx(R, { size: "small" })
103
+ }
104
+ ) : /* @__PURE__ */ t.jsxs("div", { style: { maxWidth: "500px" }, children: [
105
+ e.length > 0 && /* @__PURE__ */ t.jsx("div", { children: e.filter((a) => !!a).map((a, d) => /* @__PURE__ */ t.jsx(
106
+ L,
107
+ {
108
+ to: "source",
109
+ args: a.key,
110
+ className: "col-tree-data-source",
111
+ style: n,
112
+ children: (d ? ", " : "") + (a.alias || a.key)
113
+ },
114
+ a.key
115
+ )) }),
116
+ this.state.publishers && this.state.publishers.length > 0 && /* @__PURE__ */ t.jsxs("div", { style: { marginTop: "12px" }, children: [
117
+ /* @__PURE__ */ t.jsx("strong", { children: "Publishers" }),
118
+ /* @__PURE__ */ t.jsx("div", { children: this.state.publishers.filter((a) => !!a).map((a, d) => {
119
+ var f;
120
+ return /* @__PURE__ */ t.jsxs(
121
+ "a",
122
+ {
123
+ href: u(a.id),
124
+ target: "_blank",
125
+ rel: "noopener noreferrer",
126
+ style: n,
127
+ children: [
128
+ (d ? ", " : "") + (a.alias || a.id),
129
+ (f = a.datasets) != null && f.length ? ` (${a.datasets.length.toLocaleString("en-GB")})` : ""
130
+ ]
131
+ },
132
+ a.id
133
+ );
134
+ }) })
135
+ ] })
136
+ ] }),
137
+ title: /* @__PURE__ */ t.jsxs("div", { style: { padding: "4px 0" }, children: [
138
+ /* @__PURE__ */ t.jsx("span", { style: { fontWeight: 500 }, children: "Sources for " }),
139
+ /* @__PURE__ */ t.jsx("em", { children: l == null ? void 0 : l.name }),
140
+ /* @__PURE__ */ t.jsx(se, { style: { margin: "8px 0 0" } })
141
+ ] }),
142
+ open: o,
143
+ onOpenChange: (a) => this.setState({ popOverVisible: a }, () => {
144
+ a && this.state.data.length === 0 && this.getData(), a && this.props.publisherDatasetKeys && !this.state.publishers && this.getPublisherData();
145
+ }),
146
+ trigger: "click",
147
+ placement: "rightTop",
148
+ children: /* @__PURE__ */ t.jsx(
149
+ "a",
150
+ {
151
+ className: "col-tree-data-source",
152
+ role: "button",
153
+ tabIndex: 0,
154
+ style: { cursor: "pointer", color: "orange", fontSize: "11px" },
155
+ onClick: (a) => a.preventDefault(),
156
+ children: "Multiple sources"
157
+ }
158
+ )
159
+ }
160
+ ) });
161
+ });
162
+ this.state = {
163
+ data: [],
164
+ showInNode: !1,
165
+ loading: !1
166
+ };
167
+ }
168
+ }
169
+ c(V, "contextType", w);
170
+ const z = j.createContext();
171
+ class k extends j.Component {
172
+ constructor(e) {
173
+ super(e);
174
+ c(this, "rankIsAboveSpecies", (e) => this.props.rank.indexOf(e) < this.props.rank.indexOf("species"));
175
+ c(this, "render", () => {
176
+ const {
177
+ taxon: e,
178
+ taxon: { sector: s, sourceDatasetKeys: o, publisherDatasetKeys: r },
179
+ datasetKey: l
180
+ } = this.props, h = m(s, "dataset"), n = (o || []).filter((a) => (s == null ? void 0 : s.subjectDatasetKey) !== a).length > 0;
181
+ e.estimate && e.estimates && e.estimates.find((a) => a.estimate === e.estimate);
182
+ const u = typeof e.id == "string" && e.id.indexOf("incertae-sedis") > -1;
183
+ return /* @__PURE__ */ t.jsx(z.Consumer, { children: ({ showInfo: a }) => /* @__PURE__ */ t.jsxs("div", { id: e.id, children: [
184
+ /* @__PURE__ */ t.jsxs("span", { children: [
185
+ /* @__PURE__ */ t.jsxs("span", { className: "tree-node-rank", children: [
186
+ e.rank,
187
+ ": "
188
+ ] }),
189
+ u ? /* @__PURE__ */ t.jsx("span", { dangerouslySetInnerHTML: { __html: e.labelHtml } }) : /* @__PURE__ */ t.jsx(L, { to: "taxon", args: e.id, children: /* @__PURE__ */ t.jsx("span", { dangerouslySetInnerHTML: { __html: e.labelHtml } }) }),
190
+ (e == null ? void 0 : e.merged) && /* @__PURE__ */ t.jsx(pe, { style: { marginLeft: "4px" }, datasetKey: e == null ? void 0 : e.datasetKey, verbatimSourceKey: e == null ? void 0 : e.verbatimSourceKey })
191
+ ] }),
192
+ a && e.status === "provisionally accepted" && /* @__PURE__ */ t.jsxs(j.Fragment, { children: [
193
+ " • ",
194
+ /* @__PURE__ */ t.jsx(ae, { color: "warning", style: { marginRight: 0 }, children: "prov." })
195
+ ] }),
196
+ !I(e.count) && this.rankIsAboveSpecies(e == null ? void 0 : e.rank) && /* @__PURE__ */ t.jsxs("span", { children: [
197
+ " ",
198
+ "• ",
199
+ Number(e.count).toLocaleString(),
200
+ " ",
201
+ a && !I(e.speciesEstimate) && /* @__PURE__ */ t.jsxs("span", { children: [
202
+ " ",
203
+ "of",
204
+ " ",
205
+ Number(
206
+ e.speciesEstimate
207
+ ).toLocaleString(),
208
+ " ",
209
+ "est.",
210
+ " "
211
+ ] }),
212
+ "spp."
213
+ ] }),
214
+ a && s && /* @__PURE__ */ t.jsxs("span", { children: [
215
+ /* @__PURE__ */ t.jsx("span", { children: " • " }),
216
+ /* @__PURE__ */ t.jsxs(
217
+ L,
218
+ {
219
+ to: "source",
220
+ args: s.subjectDatasetKey,
221
+ style: n ? { fontWeight: "bold" } : null,
222
+ className: "col-tree-data-source",
223
+ children: [
224
+ m(h, "alias") || s.subjectDatasetKey,
225
+ n && ", "
226
+ ]
227
+ }
228
+ )
229
+ ] }),
230
+ a && n && /* @__PURE__ */ t.jsxs(j.Fragment, { children: [
231
+ " ",
232
+ /* @__PURE__ */ t.jsx(
233
+ V,
234
+ {
235
+ sourceDatasetKeys: o,
236
+ publisherDatasetKeys: r,
237
+ taxon: e,
238
+ datasetKey: l
239
+ }
240
+ )
241
+ ] })
242
+ ] }) });
243
+ });
244
+ this.state = {
245
+ style: {},
246
+ provisional: this.props.taxon.status === "provisionally accepted",
247
+ loading: !1
248
+ };
249
+ }
250
+ }
251
+ const K = 1e3;
252
+ class ge extends j.Component {
253
+ constructor(e) {
254
+ super(e);
255
+ c(this, "onClick", () => {
256
+ this.setState(
257
+ { loading: !0 },
258
+ () => this.props.onClick().then(() => this.setState({ loading: !1 }))
259
+ );
260
+ });
261
+ c(this, "render", () => {
262
+ const { loading: e } = this.state;
263
+ return /* @__PURE__ */ t.jsxs(j.Fragment, { children: [
264
+ e && /* @__PURE__ */ t.jsx(R, {}),
265
+ !e && /* @__PURE__ */ t.jsx("a", { onClick: this.onClick, children: /* @__PURE__ */ t.jsx("strong", { children: "Load more..." }) })
266
+ ] });
267
+ });
268
+ this.state = { loading: !1 };
269
+ }
270
+ }
271
+ class G extends j.Component {
272
+ constructor(e) {
273
+ super(e);
274
+ c(this, "componentDidMount", () => {
275
+ const { datasetKey: e } = this.props;
276
+ this.loadRoot(), this.sectorLoader = new T(
277
+ (o) => fe(o, e)
278
+ ), this.getRank();
279
+ const { treeRef: s } = this.props;
280
+ s(this);
281
+ });
282
+ c(this, "componentDidUpdate", (e) => {
283
+ (e.defaultExpandKey !== this.props.defaultExpandKey || e.hideExtinct !== this.props.hideExtinct || e.insertPlaceholder !== this.props.insertPlaceholder) && this.reloadRoot();
284
+ });
285
+ c(this, "getRank", () => {
286
+ D(`${S.dataApi}vocab/rank`).then(
287
+ (e) => this.setState({ rank: e.data.map((s) => s.name) })
288
+ );
289
+ });
290
+ c(this, "reloadRoot", () => this.setState(
291
+ {
292
+ rootLoading: !0,
293
+ treeData: [],
294
+ loadedKeys: [],
295
+ rootTotal: 0,
296
+ error: null,
297
+ nodeNotFoundErr: null
298
+ },
299
+ this.loadRoot
300
+ ));
301
+ c(this, "loadRoot", async () => {
302
+ const {
303
+ showSourceTaxon: e,
304
+ datasetKey: s,
305
+ hideExtinct: o,
306
+ insertPlaceholder: r,
307
+ type: l,
308
+ expandedTaxonKey: h
309
+ } = this.props, n = h, { defaultTaxonKey: u } = this.props;
310
+ return this.setState({ rootLoading: !0, treeData: [] }), D(
311
+ `${S.dataApi}dataset/${s}/tree?projectKey=${s}${l ? "&type=" + l : ""}&limit=${K}&offset=${this.state.treeData.length}${o ? "&extinct=false&extinct=" : ""}${r ? "&insertPlaceholder=true" : ""}`
312
+ ).then(this.decorateWithSectorsAndDataset).then((a) => {
313
+ const d = a.data.result || [], f = a.data.total, x = d.map((p) => {
314
+ let i = {
315
+ taxon: p,
316
+ key: p.id,
317
+ datasetKey: s,
318
+ childCount: p.childCount,
319
+ isLeaf: p.childCount === 0,
320
+ childOffset: 0
321
+ };
322
+ return i.title = /* @__PURE__ */ t.jsx(
323
+ k,
324
+ {
325
+ taxon: p,
326
+ datasetKey: s,
327
+ showSourceTaxon: e,
328
+ reloadChildren: () => this.fetchChildPage(i, !0),
329
+ rank: this.state.rank
330
+ }
331
+ ), i.ref = i, i;
332
+ });
333
+ this.setState(
334
+ {
335
+ rootTotal: f,
336
+ rootLoading: !1,
337
+ treeData: [...this.state.treeData, ...x],
338
+ expandedKeys: x.length < 10 ? x.map((p) => p.taxon.id).filter((p) => p === "CS5HF") : [],
339
+ error: null
340
+ },
341
+ () => {
342
+ if (n)
343
+ return this.expandToTaxon(n);
344
+ if (u)
345
+ return this.expandToTaxon(u);
346
+ }
347
+ ), x.length === 1 && this.fetchChildPage(x[x.length - 1]);
348
+ }).catch((a) => {
349
+ this.setState({
350
+ treeData: [],
351
+ rootLoading: !1,
352
+ expandedKeys: [],
353
+ error: a
354
+ });
355
+ });
356
+ });
357
+ c(this, "expandToTaxon", async (e) => {
358
+ const {
359
+ showSourceTaxon: s,
360
+ datasetKey: o,
361
+ hideExtinct: r,
362
+ type: l
363
+ } = this.props;
364
+ this.setState({
365
+ rootLoading: !0
366
+ /* , treeData: [] */
367
+ });
368
+ const { data: h } = await D(
369
+ `${S.dataApi}dataset/${o}/tree/${e}?projectKey=${o}&insertPlaceholder=true${l ? "&type=" + l : ""}${r ? "&extinct=false" : ""}`
370
+ ).then(
371
+ (p) => this.decorateWithSectorsAndDataset({
372
+ data: { result: p.data }
373
+ }).then(() => p)
374
+ );
375
+ if (h.length === 0)
376
+ return this.setState(
377
+ {
378
+ error: {
379
+ message: `No classification found for Taxon ID: ${e}`
380
+ }
381
+ },
382
+ this.loadRoot
383
+ );
384
+ const n = h[h.length - 1];
385
+ let u = {
386
+ taxon: n,
387
+ key: n.id,
388
+ datasetKey: o,
389
+ childCount: n.childCount,
390
+ isLeaf: n.childCount === 0,
391
+ childOffset: 0
392
+ };
393
+ u.title = /* @__PURE__ */ t.jsx(
394
+ k,
395
+ {
396
+ taxon: n,
397
+ datasetKey: o,
398
+ showSourceTaxon: s,
399
+ rank: this.state.rank,
400
+ reloadChildren: () => this.fetchChildPage(u, !0)
401
+ }
402
+ ), u.ref = u;
403
+ const a = u;
404
+ for (let p = h.length - 2; p >= 0; p--) {
405
+ const i = h[p], g = {
406
+ taxon: i,
407
+ key: i.id,
408
+ datasetKey: o,
409
+ childCount: i.childCount,
410
+ isLeaf: i.childCount === 0,
411
+ childOffset: 0
412
+ };
413
+ g.ref = g, g.title = /* @__PURE__ */ t.jsx(
414
+ k,
415
+ {
416
+ taxon: i,
417
+ datasetKey: o,
418
+ showSourceTaxon: s,
419
+ rank: this.state.rank,
420
+ reloadChildren: () => this.fetchChildPage(g, !0)
421
+ }
422
+ ), u.children = [g], u = g;
423
+ }
424
+ const { treeData: d } = this.state;
425
+ var f = d.findIndex((p) => p.key == a.key);
426
+ d[f] = a;
427
+ const x = [...h.map((p) => p.id).reverse()];
428
+ this.setState(
429
+ { treeData: d },
430
+ () => this.reloadLoadedKeys(x, e)
431
+ );
432
+ });
433
+ c(this, "fetchChildPage", async (e, s, o) => {
434
+ const {
435
+ showSourceTaxon: r,
436
+ datasetKey: l,
437
+ hideExtinct: h,
438
+ insertPlaceholder: n,
439
+ type: u
440
+ } = this.props, { treeData: a } = this.state;
441
+ m(e, "childCount");
442
+ const d = K, f = m(e, "childOffset"), x = await D(
443
+ `${S.dataApi}dataset/${l}/tree/${e.taxon.id}/children?limit=${d}&offset=${f}&projectKey=${l}${u ? "&type=" + u : ""}${h ? "&extinct=false" : ""}${n ? "&insertPlaceholder=true" : ""}`
444
+ );
445
+ await this.decorateWithSectorsAndDataset(x);
446
+ const p = x.data.result ? x.data.result.map((i) => {
447
+ let g = {
448
+ taxon: i,
449
+ key: i.id,
450
+ datasetKey: l,
451
+ childCount: i.childCount,
452
+ isLeaf: i.childCount === 0,
453
+ childOffset: 0,
454
+ parent: e,
455
+ name: i.name
456
+ };
457
+ return g.title = /* @__PURE__ */ t.jsx(
458
+ k,
459
+ {
460
+ taxon: i,
461
+ datasetKey: l,
462
+ showSourceTaxon: r,
463
+ rank: this.state.rank,
464
+ reloadChildren: () => this.fetchChildPage(g, !0)
465
+ }
466
+ ), g.ref = g, g;
467
+ }) : [];
468
+ if (e.children = e.children && f !== 0 && !s ? [...e.children, ...p] : p, x.data.last && e.childCount > e.children.length && (e.childCount = e.children.length), !x.data.last) {
469
+ const i = () => (e.childOffset += K, e.children[e.children.length - 1].key === "__loadMoreBTN__" && (e.children = e.children.slice(0, -1)), this.fetchChildPage(e, !1));
470
+ e.children = [
471
+ ...e.children,
472
+ {
473
+ title: /* @__PURE__ */ t.jsx(
474
+ ge,
475
+ {
476
+ onClick: i
477
+ },
478
+ "__loadMoreBTN__"
479
+ ),
480
+ key: "__loadMoreBTN__",
481
+ childCount: 0,
482
+ isLeaf: !0
483
+ }
484
+ ];
485
+ }
486
+ o || this.setState({
487
+ treeData: [...a],
488
+ loadedKeys: [.../* @__PURE__ */ new Set([...this.state.loadedKeys, e.key])]
489
+ });
490
+ });
491
+ c(this, "decorateWithSectorsAndDataset", (e) => e.data.result ? Promise.all(
492
+ e.data.result.filter((s) => !!s.sectorDatasetKey).map(
493
+ (s) => this.datasetLoader.load(s.sectorDatasetKey).then(
494
+ (o) => s.sector = {
495
+ id: s.sectorKey,
496
+ subjectDatasetKey: s.sectorDatasetKey,
497
+ dataset: o
498
+ }
499
+ )
500
+ )
501
+ ).then(() => e) : e);
502
+ c(this, "onLoadData", (e, s = !1) => (s && (e.childOffset = 0), this.fetchChildPage(e.ref, s)));
503
+ c(this, "findNode", (e, s) => {
504
+ let o = null;
505
+ if (o = s.find((r) => m(r, "taxon.id") === e), o)
506
+ return o;
507
+ {
508
+ const r = s.map((h) => m(h, "children") || []), l = le(r);
509
+ return l.length === 0 ? null : this.findNode(e, l);
510
+ }
511
+ });
512
+ c(this, "pageThroughChildrenUntilTaxonFound", async (e, s) => {
513
+ let o;
514
+ for (; !o && e.children.length < e.childCount; )
515
+ e.childOffset += K, e.children[e.children.length - 1].key === "__loadMoreBTN__" && (e.children = e.children.slice(0, -1)), await this.fetchChildPage(e, !1, !0), o = this.findNode(s, e.children);
516
+ return o || (o = e.children.find(
517
+ (r) => m(r, "taxon.id") ? r.taxon.id.indexOf("incertae-sedis") > -1 : !1
518
+ )), o;
519
+ });
520
+ c(this, "reloadLoadedKeys", async (e, s, o = !0) => {
521
+ this.setState({ rootLoading: !0 });
522
+ const { loadedKeys: r } = this.state;
523
+ let { treeData: l } = this.state;
524
+ const h = s ? this.findNode(s, l) : null, n = e ? [...e] : [...r];
525
+ for (let a = 0; a < n.length; a++) {
526
+ let d = this.findNode(n[a], l);
527
+ if (!d && h && n[a - 1]) {
528
+ const f = this.findNode(n[a - 1], l);
529
+ f && A(m(f, "children")) && f.children.length > 0 && (d = await this.pageThroughChildrenUntilTaxonFound(
530
+ f,
531
+ n[a]
532
+ ), d ? n.splice(a, 0, d.taxon.id) : this.setState(
533
+ {
534
+ nodeNotFoundErr: /* @__PURE__ */ t.jsxs("span", { children: [
535
+ "Cannot find taxon ",
536
+ s,
537
+ " in tree 😥"
538
+ ] }),
539
+ rootLoading: !1
540
+ }
541
+ /* ,
542
+ () => {
543
+ if (
544
+ this.props.treeType === "CATALOGUE" &&
545
+ typeof this.props.addMissingTargetKey === "function"
546
+ ) {
547
+ this.props.addMissingTargetKey(expandKey);
548
+ }
549
+ } */
550
+ ));
551
+ }
552
+ if (d) {
553
+ await this.fetchChildPage(d, !0, !0);
554
+ let f = d.children.find(
555
+ (x) => m(x, "taxon.id") === m(h, "taxon.id")
556
+ );
557
+ h && a === n.length - 2 && m(d, "taxon.id") !== m(h, "taxon.id") && A(d.children) && !f && d.children.length < d.childCount && (f = await this.pageThroughChildrenUntilTaxonFound(
558
+ d,
559
+ m(h, "taxon.id")
560
+ ), f ? this.setState({ treeData: [...this.state.treeData] }, () => {
561
+ setTimeout(() => {
562
+ document.getElementById(s).scrollIntoView({ behavior: "smooth", block: "center" });
563
+ }, 100);
564
+ }) : this.setState(
565
+ {
566
+ nodeNotFoundErr: /* @__PURE__ */ t.jsxs("span", { children: [
567
+ "Cannot find taxon ",
568
+ s,
569
+ " in tree 😥"
570
+ ] }),
571
+ rootLoading: !1
572
+ },
573
+ () => {
574
+ this.props.treeType === "CATALOGUE" && typeof this.props.addMissingTargetKey == "function" && this.props.addMissingTargetKey(s);
575
+ }
576
+ ));
577
+ }
578
+ }
579
+ const u = { loadedKeys: n, rootLoading: !1 };
580
+ o && (u.expandedKeys = n), this.setState(u, () => {
581
+ s && setTimeout(() => {
582
+ document.getElementById(s).scrollIntoView({ behavior: "smooth", block: "center" });
583
+ }, 100);
584
+ });
585
+ });
586
+ this.state = {
587
+ rootLoading: !0,
588
+ treeData: [],
589
+ loadedKeys: [],
590
+ expandedKeys: [],
591
+ rootTotal: 0,
592
+ error: null,
593
+ nodeNotFoundErr: null,
594
+ rank: []
595
+ }, this.treeRef = j.createRef();
596
+ }
597
+ // datasetLoader comes from the shared TreeCacheContext so multiple tree
598
+ // nodes (and TaxonSources instances) share one in-memory cache instead
599
+ // of each re-fetching the same source datasets.
600
+ get datasetLoader() {
601
+ return this.context.datasetLoader;
602
+ }
603
+ render() {
604
+ const {
605
+ error: e,
606
+ rootTotal: s,
607
+ rootLoading: o,
608
+ treeData: r,
609
+ defaultExpandAll: l,
610
+ nodeNotFoundErr: h,
611
+ loadedKeys: n,
612
+ expandedKeys: u
613
+ } = this.state, { treeType: a, dataset: d, height: f, expandedTaxonKey: x } = this.props, p = x;
614
+ return /* @__PURE__ */ t.jsxs("div", { children: [
615
+ e && /* @__PURE__ */ t.jsx(j.Fragment, { children: m(e, "response.data.code") !== 404 ? /* @__PURE__ */ t.jsx(
616
+ b,
617
+ {
618
+ closable: !0,
619
+ onClose: () => this.setState({ error: null }),
620
+ style: { marginTop: "8px" },
621
+ message: /* @__PURE__ */ t.jsx(ue, { error: e }),
622
+ type: "error"
623
+ }
624
+ ) : /* @__PURE__ */ t.jsx(
625
+ b,
626
+ {
627
+ closable: !0,
628
+ onClose: () => this.setState({ error: null }),
629
+ style: { marginTop: "8px" },
630
+ message: /* @__PURE__ */ t.jsx(
631
+ Custom404,
632
+ {
633
+ error: e,
634
+ treeType: a,
635
+ dataset: d,
636
+ loadRoot: this.loadRoot
637
+ }
638
+ ),
639
+ type: "warning"
640
+ }
641
+ ) }),
642
+ h && /* @__PURE__ */ t.jsx(
643
+ b,
644
+ {
645
+ closable: !0,
646
+ onClose: () => this.setState({ nodeNotFoundErr: null }),
647
+ style: { marginTop: "8px" },
648
+ message: h,
649
+ type: "warning"
650
+ }
651
+ ),
652
+ o && /* @__PURE__ */ t.jsx(oe, { paragraph: { rows: 10 }, active: !0 }),
653
+ !o && r.length > 0 && /* @__PURE__ */ t.jsx(
654
+ ie,
655
+ {
656
+ ref: this.treeRef,
657
+ defaultExpandAll: l,
658
+ loadData: this.onLoadData,
659
+ onLoad: (i) => this.setState({ loadedKeys: i }),
660
+ loadedKeys: n,
661
+ expandedKeys: u,
662
+ treeData: r,
663
+ filterTreeNode: (i) => i.key === p,
664
+ onExpand: (i, g) => {
665
+ this.setState({ expandedKeys: i }), this.props.onExpandedTaxonKeyChange && this.props.onExpandedTaxonKeyChange(
666
+ g.expanded ? g.node.key : null
667
+ );
668
+ }
669
+ }
670
+ ),
671
+ !e && r.length < s && /* @__PURE__ */ t.jsxs(ne, { loading: o, onClick: this.loadRoot, children: [
672
+ "Load more",
673
+ " "
674
+ ] })
675
+ ] });
676
+ }
677
+ }
678
+ c(G, "contextType", w);
679
+ const ye = [
680
+ "infraspecific name",
681
+ "species",
682
+ "variety",
683
+ "form"
684
+ ];
685
+ class Z extends j.Component {
686
+ constructor(e) {
687
+ super(e);
688
+ c(this, "componentDidMount", async () => {
689
+ const { datasetKey: e, citation: s } = this.props;
690
+ if (s)
691
+ try {
692
+ const { data: o } = await ce(e);
693
+ this.setState({ dataset: o });
694
+ } catch {
695
+ }
696
+ });
697
+ c(this, "render", () => {
698
+ const {
699
+ datasetKey: e,
700
+ defaultTaxonKey: s,
701
+ expandedTaxonKey: o,
702
+ onExpandedTaxonKeyChange: r,
703
+ showTreeOptions: l,
704
+ linkToSpeciesPage: h,
705
+ citation: n,
706
+ type: u,
707
+ insertPlaceholder: a = !0
708
+ } = this.props, { hideExtinct: d, dataset: f } = this.state, x = (i) => {
709
+ var P, _;
710
+ const g = m(i, "key");
711
+ if (!g) return;
712
+ const q = m(i, "rank");
713
+ if (h && ye.includes(q)) {
714
+ const E = (_ = (P = this.context) == null ? void 0 : P.taxon) == null ? void 0 : _.onNavigate;
715
+ E && E(g);
716
+ } else r && (r(g), this.treeRef && this.treeRef.reloadRoot && this.treeRef.reloadRoot());
717
+ }, p = () => {
718
+ r && r(null);
719
+ };
720
+ return /* @__PURE__ */ t.jsxs("div", { className: "catalogue-of-life", children: [
721
+ n === "top" && f && /* @__PURE__ */ t.jsx(F, { dataset: f }),
722
+ /* @__PURE__ */ t.jsx(w.Provider, { value: this.cache, children: /* @__PURE__ */ t.jsxs(z.Provider, { value: this.state, children: [
723
+ /* @__PURE__ */ t.jsxs(re, { children: [
724
+ /* @__PURE__ */ t.jsx(v, { flex: "auto", children: /* @__PURE__ */ t.jsx(
725
+ xe,
726
+ {
727
+ hideExtinct: d,
728
+ datasetKey: e,
729
+ style: {
730
+ width: "100%",
731
+ paddingTop: "5px",
732
+ paddingBottom: "5px"
733
+ },
734
+ defaultTaxonKey: o || null,
735
+ onSelectName: x,
736
+ onResetSearch: p
737
+ }
738
+ ) }),
739
+ l && /* @__PURE__ */ t.jsxs(v, { style: { paddingLeft: "8px" }, children: [
740
+ /* @__PURE__ */ t.jsx(
741
+ $,
742
+ {
743
+ defaultChecked: this.state.showInfo,
744
+ onChange: ({ target: { checked: i } }) => {
745
+ this.setState({ showInfo: i }), M("tree-show-source", i);
746
+ },
747
+ children: "Source"
748
+ }
749
+ ),
750
+ /* @__PURE__ */ t.jsx(
751
+ $,
752
+ {
753
+ defaultChecked: this.state.hideExtinct,
754
+ onChange: ({ target: { checked: i } }) => {
755
+ this.setState({ hideExtinct: i }), M("tree-extant-only", i);
756
+ },
757
+ children: "Extant only"
758
+ }
759
+ )
760
+ ] })
761
+ ] }),
762
+ /* @__PURE__ */ t.jsx(
763
+ G,
764
+ {
765
+ insertPlaceholder: a,
766
+ hideExtinct: d,
767
+ datasetKey: e,
768
+ defaultTaxonKey: s,
769
+ expandedTaxonKey: o,
770
+ onExpandedTaxonKeyChange: r,
771
+ treeRef: (i) => this.treeRef = i,
772
+ type: u
773
+ }
774
+ )
775
+ ] }) }),
776
+ n === "bottom" && f && /* @__PURE__ */ t.jsx(F, { dataset: f })
777
+ ] });
778
+ });
779
+ de(this.props.auth), this.state = {
780
+ hideExtinct: O("tree-extant-only", !1),
781
+ showInfo: O("tree-show-source", !1),
782
+ dataset: null
783
+ }, this.cache = B(this.props.datasetKey);
784
+ }
785
+ componentDidUpdate(e) {
786
+ e.datasetKey !== this.props.datasetKey && (this.cache = B(this.props.datasetKey));
787
+ }
788
+ }
789
+ c(Z, "contextType", U);
790
+ function me({
791
+ datasetKey: C,
792
+ defaultTaxonKey: y,
793
+ expandedTaxonKey: e,
794
+ onExpandedTaxonKeyChange: s,
795
+ showTreeOptions: o,
796
+ linkToSpeciesPage: r,
797
+ citation: l,
798
+ type: h,
799
+ insertPlaceholder: n,
800
+ auth: u,
801
+ ...a
802
+ }) {
803
+ return /* @__PURE__ */ t.jsx(U.Provider, { value: he(a), children: /* @__PURE__ */ t.jsx(
804
+ Z,
805
+ {
806
+ datasetKey: C,
807
+ defaultTaxonKey: y,
808
+ expandedTaxonKey: e,
809
+ onExpandedTaxonKeyChange: s,
810
+ showTreeOptions: o,
811
+ linkToSpeciesPage: r,
812
+ citation: l,
813
+ type: h,
814
+ insertPlaceholder: n,
815
+ auth: u
816
+ }
817
+ ) });
818
+ }
819
+ const Ne = Y(X(me));
820
+ export {
821
+ Ne as Tree
822
+ };
823
+ //# sourceMappingURL=tree.js.map