@macrostrat/column-views 3.3.5 → 3.4.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 (62) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/column.cjs +2 -1
  3. package/dist/column.cjs.map +1 -1
  4. package/dist/column.js +2 -1
  5. package/dist/column.js.map +1 -1
  6. package/dist/data-provider/unit-selection.cjs +7 -3
  7. package/dist/data-provider/unit-selection.cjs.map +1 -1
  8. package/dist/data-provider/unit-selection.d.ts +1 -0
  9. package/dist/data-provider/unit-selection.js +7 -3
  10. package/dist/data-provider/unit-selection.js.map +1 -1
  11. package/dist/index.cjs +13 -8
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.js +7 -2
  14. package/dist/index.js.map +1 -1
  15. package/dist/prepare-units/helpers.cjs +83 -49
  16. package/dist/prepare-units/helpers.cjs.map +1 -1
  17. package/dist/prepare-units/helpers.d.ts +19 -2
  18. package/dist/prepare-units/helpers.js +84 -50
  19. package/dist/prepare-units/helpers.js.map +1 -1
  20. package/dist/prepare-units/index.cjs.map +1 -1
  21. package/dist/prepare-units/index.js.map +1 -1
  22. package/dist/section.cjs +1 -2
  23. package/dist/section.cjs.map +1 -1
  24. package/dist/section.js +1 -2
  25. package/dist/section.js.map +1 -1
  26. package/dist/unit-details/identifiers.cjs +56 -0
  27. package/dist/unit-details/identifiers.cjs.map +1 -0
  28. package/dist/unit-details/identifiers.d.ts +31 -0
  29. package/dist/unit-details/identifiers.js +54 -0
  30. package/dist/unit-details/identifiers.js.map +1 -0
  31. package/dist/unit-details/index.d.ts +2 -0
  32. package/dist/unit-details/panel.cjs +11 -88
  33. package/dist/unit-details/panel.cjs.map +1 -1
  34. package/dist/unit-details/panel.d.ts +3 -19
  35. package/dist/unit-details/panel.js +10 -87
  36. package/dist/unit-details/panel.js.map +1 -1
  37. package/dist/unit-details/popover.cjs +1 -2
  38. package/dist/unit-details/popover.cjs.map +1 -1
  39. package/dist/unit-details/popover.js +2 -3
  40. package/dist/unit-details/popover.js.map +1 -1
  41. package/dist/unit-details/strat-names.cjs +44 -0
  42. package/dist/unit-details/strat-names.cjs.map +1 -0
  43. package/dist/unit-details/strat-names.d.ts +14 -0
  44. package/dist/unit-details/strat-names.js +42 -0
  45. package/dist/unit-details/strat-names.js.map +1 -0
  46. package/dist/units/index.cjs +20 -6
  47. package/dist/units/index.cjs.map +1 -1
  48. package/dist/units/index.d.ts +11 -20
  49. package/dist/units/index.js +20 -6
  50. package/dist/units/index.js.map +1 -1
  51. package/package.json +14 -14
  52. package/src/column.ts +1 -1
  53. package/src/data-provider/unit-selection.ts +8 -4
  54. package/src/prepare-units/helpers.ts +121 -72
  55. package/src/prepare-units/index.ts +1 -1
  56. package/src/section.ts +0 -1
  57. package/src/unit-details/identifiers.ts +67 -0
  58. package/src/unit-details/index.ts +2 -0
  59. package/src/unit-details/panel.ts +13 -126
  60. package/src/unit-details/popover.ts +2 -7
  61. package/src/unit-details/strat-names.ts +57 -0
  62. package/src/units/index.ts +31 -8
@@ -4,8 +4,6 @@ import { ReactNode, useMemo, useState } from "react";
4
4
  import {
5
5
  DataField,
6
6
  EnvironmentsList,
7
- isClickable,
8
- ItemInteractionProps,
9
7
  ItemList,
10
8
  LithologyList,
11
9
  LithologyTagFeature,
@@ -14,7 +12,6 @@ import {
14
12
  MacrostratItemIdentifier,
15
13
  Parenthetical,
16
14
  useInteractionManager,
17
- useInteractionProps,
18
15
  Value,
19
16
  } from "@macrostrat/data-components";
20
17
  import { useColumnUnitsMap } from "../data-provider";
@@ -22,13 +19,12 @@ import {
22
19
  useMacrostratColumnInfo,
23
20
  useMacrostratData,
24
21
  useMacrostratDefs,
25
- useStratNames,
26
22
  } from "@macrostrat/data-provider";
27
23
  import type {
28
24
  Environment,
25
+ EnvironmentIdentifier,
29
26
  Interval,
30
27
  Lithology,
31
- UnitLithology,
32
28
  UnitLong,
33
29
  UnitLongFull,
34
30
  } from "@macrostrat/api-types";
@@ -37,6 +33,9 @@ import classNames from "classnames";
37
33
  import { AgeField, Duration, IntervalProportions } from "./age-range";
38
34
  import { formatRange, formatSignificance } from "./utils.ts";
39
35
  import h from "./panel.module.sass";
36
+ import { StratNameField } from "./strat-names.ts";
37
+ import { Identifier, UnitIdentifier, UnitInfo } from "./identifiers.ts";
38
+ import { LithologyIdentifier } from "@macrostrat/api-types/src/lithologies";
40
39
 
41
40
  export interface UnitDetailsPanelProps {
42
41
  unit: any;
@@ -49,6 +48,7 @@ export interface UnitDetailsPanelProps {
49
48
  onSelectUnit?: (unitID: number) => void;
50
49
  onClickItem?: MacrostratItemClickHandler;
51
50
  interactionManager?: MacrostratInteractionManager;
51
+ showJSON?: boolean;
52
52
  }
53
53
 
54
54
  export function UnitDetailsPanel({
@@ -66,11 +66,12 @@ export function UnitDetailsPanel({
66
66
  hiddenActions = null,
67
67
  onSelectUnit,
68
68
  onClickItem,
69
+ showJSON,
69
70
  }: UnitDetailsPanelProps) {
70
- const [showJSON, setShowJSON] = useState(false);
71
+ const [_showJSON, setShowJSON] = useState(false);
71
72
 
72
73
  let content: ReactNode = null;
73
- if (showJSON) {
74
+ if (showJSON ?? _showJSON) {
74
75
  content = h(JSONView, { data: unit, showRoot: false });
75
76
  } else {
76
77
  content = h(UnitDetailsContent, {
@@ -113,7 +114,7 @@ export function UnitDetailsPanel({
113
114
 
114
115
  /** Handle unit selection clicks */
115
116
  const clickHandlerForItem = useMemo(() => {
116
- if (onSelectUnit == null || onClickItem == null) return null;
117
+ if (onSelectUnit == null && onClickItem == null) return null;
117
118
  return (item: MacrostratItemIdentifier) => {
118
119
  if ("unit_id" in item && !("col_id" in item)) {
119
120
  // We are selecting a unit within the column
@@ -367,53 +368,7 @@ export function ReferencesField({ refs, className = null, ...rest }) {
367
368
  );
368
369
  }
369
370
 
370
- function useStratNameData(strat_name_id: number) {
371
- const stratNames = useStratNames([strat_name_id]);
372
- return stratNames?.[0];
373
- }
374
-
375
- function StratNameField(
376
- props: {
377
- strat_name_id: number;
378
- className?: string;
379
- } & ItemInteractionProps,
380
- ) {
381
- /** Handling for stratigraphic name field */
382
- const { strat_name_id, className, ...rest } = props;
383
- const data = useStratNameData(strat_name_id);
384
-
385
- const baseInteractionProps = useInteractionProps({ strat_name_id });
386
-
387
- const coreProps = {
388
- ...baseInteractionProps,
389
- ...rest,
390
- };
391
-
392
- let inner: any = h(Identifier, { id: strat_name_id });
393
- const name = data?.strat_name_long;
394
- if (name != null) {
395
- inner = h("span.strat-name", name);
396
- }
397
-
398
- const clickable = isClickable(coreProps);
399
-
400
- return h(
401
- DataField,
402
- {
403
- label: "Stratigraphic name",
404
- },
405
- h(
406
- clickable ? "a" : "span",
407
- {
408
- className: classNames({ clickable }, className),
409
- ...coreProps,
410
- },
411
- inner,
412
- ),
413
- );
414
- }
415
-
416
- function getThickness(unit): [string, string] {
371
+ function getThickness(unit): [string, string | null] {
417
372
  let minThickness = unit.min_thick ?? 0;
418
373
  let maxThickness = unit.max_thick ?? unit.min_thick ?? 0;
419
374
  let _unit = "m";
@@ -484,7 +439,7 @@ function Citation({ data, tag = "p" }) {
484
439
  }
485
440
 
486
441
  function enhanceEnvironments(
487
- environments?: Partial<Environment>[] | null,
442
+ environments?: EnvironmentIdentifier[] | null,
488
443
  envMap?: Map<number, Environment> | null,
489
444
  ) {
490
445
  return environments?.map((env) => {
@@ -495,13 +450,8 @@ function enhanceEnvironments(
495
450
  });
496
451
  }
497
452
 
498
- type LithID =
499
- | (Partial<Lithology> & Pick<Lithology, "lith_id">)
500
- | UnitLithology
501
- | Lithology;
502
-
503
453
  function enhanceLithologies(
504
- lithologies?: LithID[] | null,
454
+ lithologies?: LithologyIdentifier[] | null,
505
455
  lithMap?: Map<number, any> | null,
506
456
  ) {
507
457
  return lithologies?.map((lith) => {
@@ -512,44 +462,6 @@ function enhanceLithologies(
512
462
  });
513
463
  }
514
464
 
515
- export function ClickableText({
516
- className,
517
- ...rest
518
- }: {
519
- className?: string;
520
- children: ReactNode;
521
- } & ItemInteractionProps) {
522
- /** An optionally clickable text element */
523
- const clickable = isClickable(rest);
524
- const tag = clickable ? "a" : "span";
525
- return h(tag, { className: classNames(className, { clickable }), ...rest });
526
- }
527
-
528
- export function Identifier({
529
- id,
530
- className,
531
- ...rest
532
- }: {
533
- id: number | string;
534
- className?: string;
535
- } & ItemInteractionProps) {
536
- /** An item that displays a numeric identifier, optionally clickable */
537
- return h(
538
- ClickableText,
539
- {
540
- className: classNames("identifier", className),
541
- ...rest,
542
- },
543
- id,
544
- );
545
- }
546
-
547
- type UnitInfo = {
548
- unitID: number;
549
- colID?: number;
550
- name?: string;
551
- };
552
-
553
465
  function UnitIDList({ units, showNames = false }) {
554
466
  const unitsMap = useColumnUnitsMap();
555
467
 
@@ -560,7 +472,7 @@ function UnitIDList({ units, showNames = false }) {
560
472
  if (showNames) {
561
473
  return u1.map((unitID) => {
562
474
  const unitData = unitsMap?.get(unitID);
563
- let name: string = undefined;
475
+ let name: string | null = null;
564
476
  if (unitData != null) {
565
477
  name = defaultNameFunction(unitData);
566
478
  }
@@ -595,28 +507,3 @@ function UnitIDList({ units, showNames = false }) {
595
507
  }),
596
508
  );
597
509
  }
598
-
599
- function UnitIdentifier({
600
- unitID,
601
- colID,
602
- name,
603
- ...interactionProps
604
- }: UnitInfo & ItemInteractionProps) {
605
- if (name != null) {
606
- return h(
607
- ClickableText,
608
- {
609
- className: "unit-name",
610
- ...interactionProps,
611
- },
612
- name,
613
- );
614
- }
615
-
616
- return h(Identifier, {
617
- className: "unit-id",
618
- key: unitID,
619
- id: unitID,
620
- ...interactionProps,
621
- });
622
- }
@@ -1,11 +1,7 @@
1
1
  import hyper from "@macrostrat/hyper";
2
2
  import { Popover } from "@blueprintjs/core";
3
3
  import styles from "./popover.module.sass";
4
- import {
5
- useAtomOverlayPosition,
6
- useSelectedUnit,
7
- useUnitSelectionDispatch,
8
- } from "../data-provider";
4
+ import { useAtomOverlayPosition, useUnitSelection } from "../data-provider";
9
5
  import {
10
6
  UnitDetailsFeature,
11
7
  UnitDetailsPanel,
@@ -66,8 +62,7 @@ function InteractionBarrier({ children }) {
66
62
  export function UnitSelectionPopover(
67
63
  props: Omit<UnitDetailsPanelProps, "onSelectUnit" | "unit">,
68
64
  ) {
69
- const unit = useSelectedUnit();
70
- const selectUnit = useUnitSelectionDispatch();
65
+ const [unit, selectUnit] = useUnitSelection();
71
66
  const position = useAtomOverlayPosition();
72
67
  if (unit == null) {
73
68
  return null;
@@ -0,0 +1,57 @@
1
+ import {
2
+ DataField,
3
+ isClickable,
4
+ ItemInteractionProps,
5
+ useInteractionProps,
6
+ } from "@macrostrat/data-components";
7
+ import h from "./panel.module.sass";
8
+ import classNames from "classnames";
9
+ import { useStratNames } from "@macrostrat/data-provider";
10
+ import { Identifier } from "./identifiers.ts";
11
+
12
+ function useStratNameData(strat_name_id: number) {
13
+ const stratNames = useStratNames([strat_name_id]);
14
+ return stratNames?.[0];
15
+ }
16
+
17
+ export function StratNameField(
18
+ props: {
19
+ strat_name_id: number;
20
+ className?: string;
21
+ } & ItemInteractionProps,
22
+ ) {
23
+ /** Handling for stratigraphic name field */
24
+ const { strat_name_id, className, ...rest } = props;
25
+
26
+ const data = useStratNameData(strat_name_id);
27
+
28
+ const baseInteractionProps = useInteractionProps({ strat_name_id });
29
+
30
+ const coreProps = {
31
+ ...baseInteractionProps,
32
+ ...rest,
33
+ };
34
+
35
+ let inner: any = h(Identifier, { id: strat_name_id });
36
+ const name = data?.strat_name_long;
37
+ if (name != null) {
38
+ inner = h("span.strat-name", name);
39
+ }
40
+
41
+ const clickable = isClickable(coreProps);
42
+
43
+ return h(
44
+ DataField,
45
+ {
46
+ label: "Stratigraphic name",
47
+ },
48
+ h(
49
+ clickable ? "a" : "span",
50
+ {
51
+ className: classNames({ clickable }, className),
52
+ ...coreProps,
53
+ },
54
+ inner,
55
+ ),
56
+ );
57
+ }
@@ -13,7 +13,8 @@ import { TrackedLabeledUnit } from "./composite";
13
13
  import { useEnvironments, useLithologies } from "@macrostrat/data-provider";
14
14
  import { useMemo } from "react";
15
15
  import { resolveID } from "./resolvers";
16
- import { Lithology } from "@macrostrat/api-types";
16
+ import { BaseUnit, Lithology } from "@macrostrat/api-types";
17
+ import { UnitWithDefinedOverlap } from "../prepare-units/helpers.ts";
17
18
 
18
19
  export * from "./composite";
19
20
  export * from "./types";
@@ -56,15 +57,37 @@ export function BasicUnitComponent({ division, ...rest }) {
56
57
  });
57
58
  }
58
59
 
59
- export function UnitComponent({ division, nColumns = 2, ...rest }) {
60
- const width = rest.width ?? useColumnLayout()?.width;
60
+ interface UnitComponentProps<T extends BaseUnit> {
61
+ division: UnitWithDefinedOverlap<T> | T;
62
+ nColumns: number;
63
+ width?: number;
64
+ }
61
65
 
62
- const nOverlappingUnits = division.overlappingUnits?.length ?? 0;
63
- const _nColumns = nOverlappingUnits == 0 ? 1 : nColumns;
64
- const columnIx = (division.column ?? 0) % _nColumns;
65
- const reducedWidth = width / _nColumns;
66
- const x = (columnIx * width) / _nColumns;
66
+ export function UnitComponent<T extends BaseUnit>({
67
+ division,
68
+ nColumns = 2,
69
+ ...rest
70
+ }: UnitComponentProps<T>) {
71
+ const width = rest.width ?? useColumnLayout()?.width;
67
72
 
73
+ let _nColumns = nColumns;
74
+ if (isNaN(_nColumns)) {
75
+ _nColumns = 2;
76
+ }
77
+ let columnIx = 0;
78
+ let x = 0;
79
+
80
+ console.log(rest, _nColumns, width);
81
+
82
+ let reducedWidth = _nColumns;
83
+ //const nOverlappingUnits = division.overlappingUnits?.length ?? 0;
84
+ if ("overlap" in division) {
85
+ const overlap = division.overlap;
86
+ _nColumns = Math.min(_nColumns, overlap.nColumns);
87
+ columnIx = overlap.column;
88
+ reducedWidth = width / _nColumns;
89
+ x = (columnIx * width) / _nColumns;
90
+ }
68
91
  return h(TrackedLabeledUnit, {
69
92
  division,
70
93
  ...rest,