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