@macrostrat/data-sheet 4.5.1 → 4.6.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.
@@ -1478,7 +1478,7 @@ span._sep_1r3aw_9:first-child, span._sep_1r3aw_9:last-child {
1478
1478
  --data-panel-content-padding: 0px;
1479
1479
  }
1480
1480
 
1481
- ._data-panel_gxz75_5 {
1481
+ ._data-panel_dd90z_5 {
1482
1482
  position: relative;
1483
1483
  display: flex;
1484
1484
  flex: 1 1 auto;
@@ -1493,13 +1493,13 @@ span._sep_1r3aw_9:first-child, span._sep_1r3aw_9:last-child {
1493
1493
  --data-panel-selected-background: rgba(45, 114, 210, 0.1);
1494
1494
  }
1495
1495
 
1496
- ._data-panel-main_gxz75_20 {
1496
+ ._data-panel-main_dd90z_20 {
1497
1497
  display: flex;
1498
1498
  flex-direction: column;
1499
1499
  flex: 1 1 auto;
1500
1500
  }
1501
1501
 
1502
- ._data-panel-sidebar-container_gxz75_26 {
1502
+ ._data-panel-sidebar-container_dd90z_26 {
1503
1503
  flex: 0 0 auto;
1504
1504
  width: var(--data-panel-sidebar-width, 240px);
1505
1505
  min-height: 0;
@@ -1508,7 +1508,7 @@ span._sep_1r3aw_9:first-child, span._sep_1r3aw_9:last-child {
1508
1508
  border-left: 1px solid var(--panel-rule-color);
1509
1509
  }
1510
1510
 
1511
- ._data-panel-body_gxz75_35 {
1511
+ ._data-panel-body_dd90z_35 {
1512
1512
  flex: 1 1 auto;
1513
1513
  min-height: 0;
1514
1514
  min-width: 0;
@@ -1516,19 +1516,19 @@ span._sep_1r3aw_9:first-child, span._sep_1r3aw_9:last-child {
1516
1516
  padding: var(--data-panel-content-padding);
1517
1517
  }
1518
1518
 
1519
- ._data-panel-main_gxz75_20 > * {
1519
+ ._data-panel-main_dd90z_20 > * {
1520
1520
  display: flex;
1521
1521
  flex-direction: column;
1522
1522
  align-items: center;
1523
1523
  }
1524
- ._data-panel-main_gxz75_20 > * > * {
1524
+ ._data-panel-main_dd90z_20 > * > * {
1525
1525
  flex: 1;
1526
1526
  max-width: var(--data-panel-content-width, 100%);
1527
1527
  width: var(--data-panel-content-width, 100%);
1528
1528
  min-width: 0;
1529
1529
  }
1530
1530
 
1531
- ._content-footer-holder_gxz75_55 {
1531
+ ._content-footer-holder_dd90z_55 {
1532
1532
  flex: 0 0 auto;
1533
1533
  min-height: 44px;
1534
1534
  display: flex;
@@ -1536,29 +1536,29 @@ span._sep_1r3aw_9:first-child, span._sep_1r3aw_9:last-child {
1536
1536
  justify-content: center;
1537
1537
  }
1538
1538
 
1539
- ._data-panel-item-container_gxz75_63._is-skeleton_gxz75_63 {
1539
+ ._data-panel-item-container_dd90z_63._is-skeleton_dd90z_63 {
1540
1540
  pointer-events: none;
1541
1541
  }
1542
1542
 
1543
- ._data-panel-skeleton_gxz75_67 {
1543
+ ._data-panel-skeleton_dd90z_67 {
1544
1544
  width: 100%;
1545
1545
  min-height: 3.25em;
1546
1546
  border-radius: 4px;
1547
1547
  }
1548
1548
 
1549
- ._data-panel-list_gxz75_73 {
1549
+ ._data-panel-list_dd90z_73 {
1550
1550
  display: flex;
1551
1551
  flex-direction: column;
1552
1552
  gap: var(--data-panel-item-gap, 8px);
1553
1553
  flex-grow: 1;
1554
1554
  }
1555
1555
 
1556
- ._data-panel-item_gxz75_63 {
1556
+ ._data-panel-item_dd90z_63 {
1557
1557
  user-select: none;
1558
1558
  break-inside: avoid;
1559
1559
  }
1560
1560
 
1561
- ._sentinel_gxz75_85 {
1561
+ ._sentinel_dd90z_85 {
1562
1562
  display: flex;
1563
1563
  align-items: center;
1564
1564
  justify-content: center;
@@ -1568,29 +1568,29 @@ span._sep_1r3aw_9:first-child, span._sep_1r3aw_9:last-child {
1568
1568
  font-size: 13px;
1569
1569
  }
1570
1570
 
1571
- ._data-panel-toolbar-content_gxz75_95 {
1571
+ ._data-panel-toolbar-content_dd90z_95 {
1572
1572
  max-width: var(--data-panel-content-width);
1573
1573
  }
1574
1574
 
1575
- ._data-panel-footer_gxz75_99 {
1575
+ ._data-panel-footer_dd90z_99 {
1576
1576
  color: var(--text-subtle, #738091);
1577
1577
  }
1578
1578
 
1579
- ._data-panel-footer-content_gxz75_103 {
1579
+ ._data-panel-footer-content_dd90z_103 {
1580
1580
  gap: var(--data-panel-item-gap, 8px);
1581
1581
  padding: 0.2em var(--data-panel-content-padding);
1582
1582
  }
1583
- ._data-panel-footer-content_gxz75_103 ._spacer_gxz75_107 {
1583
+ ._data-panel-footer-content_dd90z_103 ._spacer_dd90z_107 {
1584
1584
  flex: 1;
1585
1585
  }
1586
1586
 
1587
- ._data-panel-status-bar_gxz75_111 {
1587
+ ._data-panel-status-bar_dd90z_111 {
1588
1588
  display: flex;
1589
1589
  flex-direction: row;
1590
1590
  align-items: center;
1591
1591
  }
1592
1592
 
1593
- ._data-card_gxz75_117 {
1593
+ ._data-card_dd90z_117 {
1594
1594
  display: flex;
1595
1595
  gap: var(--data-panel-item-gap, 1em);
1596
1596
  padding: var(--data-panel-card-padding, 1em);
@@ -1599,36 +1599,36 @@ span._sep_1r3aw_9:first-child, span._sep_1r3aw_9:last-child {
1599
1599
  background: var(--card-background-color);
1600
1600
  cursor: pointer;
1601
1601
  }
1602
- ._data-card_gxz75_117._selected_gxz75_126 {
1602
+ ._data-card_dd90z_117._selected_dd90z_126 {
1603
1603
  background: var(--data-panel-selected-background);
1604
1604
  outline: 1.5px solid var(--data-panel-selected-color);
1605
1605
  }
1606
- ._data-card_gxz75_117._selected_gxz75_126:hover {
1606
+ ._data-card_dd90z_117._selected_dd90z_126:hover {
1607
1607
  background: var(--data-panel-selected-background);
1608
1608
  border-color: var(--data-panel-selected-color);
1609
1609
  outline-width: 2px;
1610
1610
  }
1611
- ._data-card_gxz75_117._selectable_gxz75_135:not(._selected_gxz75_126):hover {
1611
+ ._data-card_dd90z_117._selectable_dd90z_135:not(._selected_dd90z_126):hover {
1612
1612
  border-color: rgba(128, 128, 128, 0.5);
1613
1613
  background: rgba(128, 128, 128, 0.08);
1614
1614
  }
1615
1615
 
1616
- ._data-panel_gxz75_5._toolbar-style-bordered_gxz75_140 ._data-panel-toolbar_gxz75_95, ._data-panel_gxz75_5._toolbar-style-bordered_gxz75_140 ._data-panel-footer_gxz75_99 {
1616
+ ._data-panel_dd90z_5._toolbar-style-bordered_dd90z_140 ._data-panel-top-area_dd90z_140, ._data-panel_dd90z_5._toolbar-style-bordered_dd90z_140 ._data-panel-footer_dd90z_99 {
1617
1617
  background-color: var(--panel-secondary-background-color);
1618
1618
  }
1619
- ._data-panel_gxz75_5._toolbar-style-bordered_gxz75_140 ._data-panel-toolbar_gxz75_95 {
1619
+ ._data-panel_dd90z_5._toolbar-style-bordered_dd90z_140 ._data-panel-top-area_dd90z_140 {
1620
1620
  border-bottom: 1px solid var(--panel-rule-color);
1621
1621
  }
1622
- ._data-panel_gxz75_5._toolbar-style-bordered_gxz75_140 ._data-panel-toolbar-content_gxz75_95 {
1622
+ ._data-panel_dd90z_5._toolbar-style-bordered_dd90z_140 ._data-panel-toolbar-content_dd90z_95 {
1623
1623
  padding: 0.2em var(--data-panel-content-padding, 12px);
1624
1624
  }
1625
- ._data-panel_gxz75_5._toolbar-style-bordered_gxz75_140 ._data-panel-footer_gxz75_99 {
1625
+ ._data-panel_dd90z_5._toolbar-style-bordered_dd90z_140 ._data-panel-footer_dd90z_99 {
1626
1626
  border-top: 1px solid var(--panel-rule-color);
1627
1627
  }
1628
- ._data-panel_gxz75_5._toolbar-style-floating_gxz75_152 {
1628
+ ._data-panel_dd90z_5._toolbar-style-floating_dd90z_152 {
1629
1629
  --data-panel-top-margin: calc(var(--data-panel-toolbar-height, 40px) + 2 * var(--data-panel-content-padding, 12px));
1630
1630
  }
1631
- ._data-panel_gxz75_5._toolbar-style-floating_gxz75_152 ._data-panel-top-area_gxz75_155 {
1631
+ ._data-panel_dd90z_5._toolbar-style-floating_dd90z_152 ._data-panel-top-area_dd90z_140 {
1632
1632
  display: flex;
1633
1633
  flex-direction: row;
1634
1634
  justify-content: center;
@@ -1637,26 +1637,27 @@ span._sep_1r3aw_9:first-child, span._sep_1r3aw_9:last-child {
1637
1637
  position: absolute;
1638
1638
  top: 0;
1639
1639
  left: 0;
1640
+ right: 0;
1640
1641
  }
1641
- ._data-panel_gxz75_5._toolbar-style-floating_gxz75_152 ._data-panel-footer_gxz75_99, ._data-panel_gxz75_5._toolbar-style-floating_gxz75_152 ._data-panel-toolbar_gxz75_95 {
1642
+ ._data-panel_dd90z_5._toolbar-style-floating_dd90z_152 ._data-panel-footer_dd90z_99, ._data-panel_dd90z_5._toolbar-style-floating_dd90z_152 ._data-panel-toolbar_dd90z_95 {
1642
1643
  flex: unset;
1643
1644
  z-index: 10;
1644
1645
  min-width: 0;
1645
1646
  width: var(--data-panel-content-width, 100%);
1646
1647
  margin: 0;
1647
1648
  }
1648
- ._data-panel_gxz75_5._toolbar-style-floating_gxz75_152 ._data-panel-footer_gxz75_99 > *, ._data-panel_gxz75_5._toolbar-style-floating_gxz75_152 ._data-panel-toolbar_gxz75_95 > * {
1649
+ ._data-panel_dd90z_5._toolbar-style-floating_dd90z_152 ._data-panel-footer_dd90z_99 > *, ._data-panel_dd90z_5._toolbar-style-floating_dd90z_152 ._data-panel-toolbar_dd90z_95 > * {
1649
1650
  max-width: unset;
1650
1651
  flex-grow: unset;
1651
1652
  width: unset;
1652
1653
  }
1653
- ._data-panel_gxz75_5._toolbar-style-floating_gxz75_152 ._data-panel-toolbar_gxz75_95 {
1654
+ ._data-panel_dd90z_5._toolbar-style-floating_dd90z_152 ._data-panel-toolbar_dd90z_95 {
1654
1655
  display: flex;
1655
1656
  flex-direction: row;
1656
1657
  justify-content: start;
1657
1658
  pointer-events: none;
1658
1659
  }
1659
- ._data-panel_gxz75_5._toolbar-style-floating_gxz75_152 ._data-panel-toolbar-content_gxz75_95 {
1660
+ ._data-panel_dd90z_5._toolbar-style-floating_dd90z_152 ._data-panel-toolbar-content_dd90z_95 {
1660
1661
  background-color: var(--panel-secondary-background-color);
1661
1662
  box-shadow: 0 0 0 1px var(--panel-rule-color);
1662
1663
  border-radius: 4px;
@@ -1664,25 +1665,52 @@ span._sep_1r3aw_9:first-child, span._sep_1r3aw_9:last-child {
1664
1665
  padding-right: 6px;
1665
1666
  flex-grow: 1;
1666
1667
  max-width: fit-content;
1668
+ margin-left: var(--data-panel-toolbar-offset, -6px);
1669
+ margin-right: var(--data-panel-toolbar-offset, -6px);
1667
1670
  pointer-events: all;
1668
1671
  }
1669
- ._data-panel_gxz75_5._toolbar-style-floating_gxz75_152 ._data-panel-toolbar-content_gxz75_95 > *:empty {
1672
+ ._data-panel_dd90z_5._toolbar-style-floating_dd90z_152 ._data-panel-toolbar-content_dd90z_95 > *:empty {
1670
1673
  display: none;
1671
1674
  }
1672
- ._data-panel_gxz75_5._toolbar-style-floating_gxz75_152 ._data-panel-footer_gxz75_99 {
1675
+ ._data-panel_dd90z_5._toolbar-style-floating_dd90z_152 ._data-panel-footer_dd90z_99 {
1673
1676
  bottom: var(--data-panel-content-padding, 12px);
1674
1677
  height: fit-content;
1675
1678
  right: var(--data-panel-content-padding, 12px);
1676
1679
  background-color: var(--background-color);
1677
1680
  }
1678
- ._data-panel_gxz75_5._toolbar-style-floating_gxz75_152 ._data-panel-body_gxz75_35 {
1681
+ ._data-panel_dd90z_5._toolbar-style-floating_dd90z_152 ._data-panel-body_dd90z_35 {
1679
1682
  padding-top: var(--data-panel-top-margin);
1680
1683
  mask-image: linear-gradient(to bottom, transparent 4px, var(--background-color) var(--data-panel-top-margin));
1681
1684
  }
1682
- ._data-panel_gxz75_5._toolbar-style-fade_gxz75_206 ._data-panel-body_gxz75_35._is-scrolled_gxz75_206 {
1685
+ ._data-panel_dd90z_5._toolbar-style-fade_dd90z_209 ._data-panel-body_dd90z_35._is-scrolled_dd90z_209 {
1683
1686
  mask-image: linear-gradient(to bottom, transparent 0, var(--background-color) 20px);
1684
1687
  }
1685
1688
 
1686
- ._collapsed-controls_gxz75_210 {
1689
+ ._collapsed-controls_dd90z_213 {
1687
1690
  max-width: 360px;
1691
+ }._data-panel-masonry-body_1oiqg_1 {
1692
+ display: flex;
1693
+ flex-direction: column;
1694
+ flex-grow: 1;
1695
+ }
1696
+
1697
+ ._data-panel-masonry_1oiqg_1 {
1698
+ display: flex;
1699
+ align-items: flex-start;
1700
+ gap: var(--data-panel-item-gap, 8px);
1701
+ }
1702
+
1703
+ ._data-panel-masonry-column_1oiqg_13 {
1704
+ flex: 1 1 0;
1705
+ min-width: 0;
1706
+ display: flex;
1707
+ flex-direction: column;
1708
+ gap: var(--data-panel-masonry-row-gap, var(--data-panel-item-gap, 8px));
1709
+ }
1710
+
1711
+ ._data-panel-masonry-placeholders_1oiqg_21 {
1712
+ display: flex;
1713
+ flex-direction: column;
1714
+ gap: var(--data-panel-masonry-row-gap, var(--data-panel-item-gap, 8px));
1715
+ margin-top: var(--data-panel-masonry-row-gap, var(--data-panel-item-gap, 8px));
1688
1716
  }
package/dist/index.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const dataSheet = require("./data-sheet.cjs");
4
4
  const dataPanel = require("./data-panel.cjs");
5
+ const masonry = require("./masonry.cjs");
5
6
  const dataView = require("./data-view.cjs");
6
7
  const index = require("./postgrest-table/index.cjs");
7
8
  const operators = require("./filters/operators.cjs");
@@ -45,6 +46,8 @@ exports.DataPanel = dataPanel.DataPanel;
45
46
  exports.DataPanelRenderer = dataPanel.DataPanelRenderer;
46
47
  exports.DataPanelToolbarStyle = dataPanel.DataPanelToolbarStyle;
47
48
  exports.createDataCard = dataPanel.createDataCard;
49
+ exports.MasonryScrollBody = masonry.MasonryScrollBody;
50
+ exports.createMasonryScrollBody = masonry.createMasonryScrollBody;
48
51
  exports.DataView = dataView.DataView;
49
52
  exports.ExpandedLithologies = index.ExpandedLithologies;
50
53
  exports.IntervalCell = index.IntervalCell;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './data-sheet.ts';
2
2
  export * from './data-panel.ts';
3
+ export * from './masonry.ts';
3
4
  export * from './data-view';
4
5
  export * from './postgrest-table';
5
6
  export * from './components';
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { DataSheet, DataSheetRenderer } from "./data-sheet.js";
2
2
  import { DataCard, DataPanel, DataPanelRenderer, DataPanelToolbarStyle, createDataCard } from "./data-panel.js";
3
+ import { MasonryScrollBody, createMasonryScrollBody } from "./masonry.js";
3
4
  import { DataView } from "./data-view.js";
4
5
  import { ExpandedLithologies, IntervalCell, LongTextViewer, PostgRESTTableView, SearchAction, fullTextSearchAction, lithologyRenderer, notifyOnError, wrapWithErrorHandling } from "./postgrest-table/index.js";
5
6
  import { DEFAULT_FILTER_OPERATORS, OPERATOR_LABELS, getOperatorsForColumn, testFilterOperator } from "./filters/operators.js";
@@ -74,6 +75,7 @@ export {
74
75
  LoadProgressIndicator,
75
76
  LoadProgressLabel,
76
77
  LongTextViewer,
78
+ MasonryScrollBody,
77
79
  MenuDropdown,
78
80
  MenuFormItem,
79
81
  MenuInlineFilterItem,
@@ -107,6 +109,7 @@ export {
107
109
  copyAction,
108
110
  createDataCard,
109
111
  createLocalProvider,
112
+ createMasonryScrollBody,
110
113
  createPostgRESTFetchChunk,
111
114
  createPostgRESTProvider,
112
115
  createSaveAction,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const masonry_module = require("./masonry.module.sass.cjs");
4
+ const react = require("react");
5
+ const FALLBACK_ITEM_HEIGHT = 160;
6
+ function MasonryScrollBody(props) {
7
+ const { children, placeholders, columns = 2, minColumnWidth } = props;
8
+ const containerRef = react.useRef(null);
9
+ const nCols = useColumnCount(containerRef, columns, minColumnWidth);
10
+ const stateRef = react.useRef(null);
11
+ stateRef.current ??= {
12
+ columns: nCols,
13
+ assign: /* @__PURE__ */ new Map(),
14
+ heights: /* @__PURE__ */ new Map(),
15
+ els: /* @__PURE__ */ new Map(),
16
+ refs: /* @__PURE__ */ new Map()
17
+ };
18
+ const state = stateRef.current;
19
+ const [, bump] = react.useReducer((x) => x + 1, 0);
20
+ const items = react.Children.toArray(children).filter(
21
+ react.isValidElement
22
+ );
23
+ react.useLayoutEffect(() => {
24
+ if (state.columns !== nCols) {
25
+ state.columns = nCols;
26
+ state.assign.clear();
27
+ }
28
+ for (const [key, el] of state.els) state.heights.set(key, el.offsetHeight);
29
+ const present = new Set(items.map(keyOf));
30
+ for (const key of [...state.assign.keys()]) {
31
+ if (!present.has(key)) state.assign.delete(key);
32
+ }
33
+ for (const key of [...state.heights.keys()]) {
34
+ if (!present.has(key)) state.heights.delete(key);
35
+ }
36
+ const unassigned = items.filter((c) => !state.assign.has(keyOf(c)));
37
+ if (unassigned.length === 0) return;
38
+ const colHeights = new Array(nCols).fill(0);
39
+ for (const [key, col] of state.assign) {
40
+ colHeights[col] += state.heights.get(key) ?? 0;
41
+ }
42
+ for (const child of unassigned) {
43
+ const key = keyOf(child);
44
+ let col = 0;
45
+ for (let c = 1; c < nCols; c++) {
46
+ if (colHeights[c] < colHeights[col]) col = c;
47
+ }
48
+ state.assign.set(key, col);
49
+ colHeights[col] += state.heights.get(key) ?? FALLBACK_ITEM_HEIGHT;
50
+ }
51
+ bump();
52
+ });
53
+ const stale = state.columns !== nCols;
54
+ const columnItems = Array.from({ length: nCols }, () => []);
55
+ items.forEach((child, i) => {
56
+ const key = keyOf(child);
57
+ let assigned = void 0;
58
+ if (!stale) {
59
+ assigned = state.assign.get(key);
60
+ }
61
+ const col = assigned ?? i % nCols;
62
+ columnItems[col].push(
63
+ react.cloneElement(child, { ref: refFor(state, key) })
64
+ );
65
+ });
66
+ return masonry_module("div.data-panel-masonry-body", [
67
+ masonry_module(
68
+ "div.data-panel-masonry",
69
+ { ref: containerRef },
70
+ columnItems.map(
71
+ (col, c) => masonry_module("div.data-panel-masonry-column", { key: c }, col)
72
+ )
73
+ ),
74
+ masonry_module.if(placeholders != null)(
75
+ "div.data-panel-masonry-placeholders",
76
+ placeholders
77
+ )
78
+ ]);
79
+ }
80
+ function createMasonryScrollBody(options = {}) {
81
+ return function MasonryScrollBodyWithOptions(props) {
82
+ return masonry_module(MasonryScrollBody, { ...options, ...props });
83
+ };
84
+ }
85
+ function keyOf(child) {
86
+ return String(child.key);
87
+ }
88
+ function refFor(state, key) {
89
+ let cb = state.refs.get(key);
90
+ if (cb == null) {
91
+ cb = (el) => {
92
+ if (el == null) {
93
+ state.els.delete(key);
94
+ } else {
95
+ state.els.set(key, el);
96
+ }
97
+ };
98
+ state.refs.set(key, cb);
99
+ }
100
+ return cb;
101
+ }
102
+ function useColumnCount(ref, columns, minColumnWidth) {
103
+ const [width, setWidth] = react.useState(null);
104
+ react.useEffect(() => {
105
+ const el = ref.current;
106
+ if (minColumnWidth == null || el == null) return;
107
+ const obs = new ResizeObserver(([entry]) => {
108
+ setWidth(entry.contentRect.width);
109
+ });
110
+ obs.observe(el);
111
+ return () => obs.disconnect();
112
+ }, [minColumnWidth]);
113
+ if (minColumnWidth == null || width == null) return Math.max(1, columns);
114
+ return Math.max(1, Math.min(columns, Math.floor(width / minColumnWidth)));
115
+ }
116
+ exports.MasonryScrollBody = MasonryScrollBody;
117
+ exports.createMasonryScrollBody = createMasonryScrollBody;
118
+ //# sourceMappingURL=masonry.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"masonry.cjs","sources":["../src/masonry.ts"],"sourcesContent":["/**\n * Masonry scroll body for the `DataPanel` — variable-height cards laid out in\n * equal-width columns, balanced by *measured* height rather than a flat\n * estimate or CSS multi-column.\n *\n * The problem it solves is paging: CSS `columns` re-flows the whole list every\n * time a page is appended, so the cards under the user's cursor move. Here each\n * item is placed in the running-shortest column **once**, keyed by its React\n * key, and then frozen — appending a page never reshuffles what is on screen.\n *\n * Placement is measured: a freshly-appended batch mounts in provisional\n * columns, a `useLayoutEffect` reads each card's real `offsetHeight`, then the\n * batch is greedily assigned from those real heights and re-rendered — all\n * before paint, so only the balanced result is seen.\n *\n * Two things keep the balance honest over many pages:\n *\n * - **Placeholders are not items.** The panel's loading skeletons arrive as\n * `placeholders`, not `children`, and render below the columns. Freezing a\n * column assignment for a skeleton (measured at skeleton height, then\n * replaced by real content) is what makes a masonry drift, one page at a\n * time, into \"this whole page went into one column\".\n * - **Identity is the React key, not the array index.** A sort, filter or\n * refresh replaces the keys, and assignments for keys that are gone are\n * pruned — so column heights are always recomputed from items that are\n * actually on screen.\n */\nimport h from \"./masonry.module.sass\";\nimport {\n Children,\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n useEffect,\n useLayoutEffect,\n useReducer,\n useRef,\n useState,\n} from \"react\";\nimport type { ScrollBodyProps } from \"./data-panel\";\n\n/** Height assumed for an item that hasn't been measured yet (it always is, by\n * the time it matters — this only guards a torn-down/hidden container). */\nconst FALLBACK_ITEM_HEIGHT = 160;\n\nexport interface MasonryOptions {\n /** Number of columns (the maximum, when `minColumnWidth` is set). Default 2. */\n columns?: number;\n /** If set, the column count drops below `columns` when the container is too\n * narrow to give every column at least this many pixels. */\n minColumnWidth?: number;\n}\n\ninterface MasonryState {\n /** Column count the current assignments were computed for. */\n columns: number;\n /** Frozen key → column. */\n assign: Map<string, number>;\n /** Last measured height per key. */\n heights: Map<string, number>;\n /** Mounted element per key, for measurement. */\n els: Map<string, HTMLElement>;\n /** Stable ref callbacks, so an item isn't detached/reattached every render. */\n refs: Map<string, (el: HTMLElement | null) => void>;\n}\n\n/**\n * A `scrollBody` component for `DataPanel` with the default two columns. For\n * anything else — a different column count, or responsive columns — build one\n * with `createMasonryScrollBody`.\n */\nexport function MasonryScrollBody(props: ScrollBodyProps & MasonryOptions) {\n const { children, placeholders, columns = 2, minColumnWidth } = props;\n\n const containerRef = useRef<HTMLDivElement | null>(null);\n const nCols = useColumnCount(containerRef, columns, minColumnWidth);\n\n const stateRef = useRef<MasonryState | null>(null);\n stateRef.current ??= {\n columns: nCols,\n assign: new Map(),\n heights: new Map(),\n els: new Map(),\n refs: new Map(),\n };\n const state = stateRef.current;\n const [, bump] = useReducer((x: number) => x + 1, 0);\n\n const items = Children.toArray(children).filter(\n isValidElement,\n ) as ReactElement[];\n\n // Runs on every commit (no deps): measurement has to see the layout that was\n // just produced, including one caused by a resize or a card's own content\n // settling. It is cheap when nothing is unassigned, and re-renders only when\n // it actually assigns something — so there's no render loop.\n useLayoutEffect(() => {\n // A column-count change invalidates every assignment (a column may no\n // longer exist). Handled here, not in render, so render stays pure.\n if (state.columns !== nCols) {\n state.columns = nCols;\n state.assign.clear();\n }\n\n for (const [key, el] of state.els) state.heights.set(key, el.offsetHeight);\n\n const present = new Set(items.map(keyOf));\n for (const key of [...state.assign.keys()]) {\n if (!present.has(key)) state.assign.delete(key);\n }\n for (const key of [...state.heights.keys()]) {\n if (!present.has(key)) state.heights.delete(key);\n }\n\n const unassigned = items.filter((c) => !state.assign.has(keyOf(c)));\n if (unassigned.length === 0) return;\n\n // Column heights from the items already frozen into them…\n const colHeights = new Array(nCols).fill(0);\n for (const [key, col] of state.assign) {\n colHeights[col] += state.heights.get(key) ?? 0;\n }\n // …then greedily place the new batch by its just-measured real heights.\n for (const child of unassigned) {\n const key = keyOf(child);\n let col = 0;\n for (let c = 1; c < nCols; c++) {\n if (colHeights[c] < colHeights[col]) col = c;\n }\n state.assign.set(key, col);\n colHeights[col] += state.heights.get(key) ?? FALLBACK_ITEM_HEIGHT;\n }\n bump(); // move the new batch into its balanced columns, before paint\n });\n\n // Items without an assignment yet render in a provisional column so they\n // mount and can be measured; the layout effect above then places them.\n const stale = state.columns !== nCols;\n const columnItems: ReactNode[][] = Array.from({ length: nCols }, () => []);\n items.forEach((child, i) => {\n const key = keyOf(child);\n let assigned: number | undefined = undefined;\n if (!stale) {\n assigned = state.assign.get(key);\n }\n const col = assigned ?? i % nCols;\n columnItems[col].push(\n cloneElement(child, { ref: refFor(state, key) } as any),\n );\n });\n\n return h(\"div.data-panel-masonry-body\", [\n h(\n \"div.data-panel-masonry\",\n { ref: containerRef },\n columnItems.map((col, c) =>\n h(\"div.data-panel-masonry-column\", { key: c }, col),\n ),\n ),\n h.if(placeholders != null)(\n \"div.data-panel-masonry-placeholders\",\n placeholders,\n ),\n ]);\n}\n\n/** Build a `scrollBody` masonry component with a fixed or responsive column\n * count: `scrollBody: createMasonryScrollBody({ columns: 3 })`. */\nexport function createMasonryScrollBody(options: MasonryOptions = {}) {\n return function MasonryScrollBodyWithOptions(props: ScrollBodyProps) {\n return h(MasonryScrollBody, { ...options, ...props });\n };\n}\n\nfunction keyOf(child: ReactElement): string {\n return String(child.key);\n}\n\n/** One stable ref callback per key — a fresh closure each render would detach\n * and reattach every card on every render. */\nfunction refFor(state: MasonryState, key: string) {\n let cb = state.refs.get(key);\n if (cb == null) {\n cb = (el: HTMLElement | null) => {\n if (el == null) {\n state.els.delete(key);\n } else {\n state.els.set(key, el);\n }\n };\n state.refs.set(key, cb);\n }\n return cb;\n}\n\n/** The effective column count: `columns`, reduced to fit `minColumnWidth`. */\nfunction useColumnCount(\n ref: { current: HTMLElement | null },\n columns: number,\n minColumnWidth: number | undefined,\n): number {\n const [width, setWidth] = useState<number | null>(null);\n\n useEffect(() => {\n const el = ref.current;\n if (minColumnWidth == null || el == null) return;\n const obs = new ResizeObserver(([entry]) => {\n setWidth(entry.contentRect.width);\n });\n obs.observe(el);\n return () => obs.disconnect();\n }, [minColumnWidth]);\n\n if (minColumnWidth == null || width == null) return Math.max(1, columns);\n return Math.max(1, Math.min(columns, Math.floor(width / minColumnWidth)));\n}\n"],"names":["useRef","useReducer","Children","isValidElement","useLayoutEffect","cloneElement","h","useState","useEffect"],"mappings":";;;;AA4CA,MAAM,uBAAuB;AA4BtB,SAAS,kBAAkB,OAAyC;AACzE,QAAM,EAAE,UAAU,cAAc,UAAU,GAAG,mBAAmB;AAEhE,QAAM,eAAeA,MAAAA,OAA8B,IAAI;AACvD,QAAM,QAAQ,eAAe,cAAc,SAAS,cAAc;AAElE,QAAM,WAAWA,MAAAA,OAA4B,IAAI;AACjD,WAAS,YAAY;AAAA,IACnB,SAAS;AAAA,IACT,4BAAY,IAAA;AAAA,IACZ,6BAAa,IAAA;AAAA,IACb,yBAAS,IAAA;AAAA,IACT,0BAAU,IAAA;AAAA,EAAI;AAEhB,QAAM,QAAQ,SAAS;AACvB,QAAM,CAAA,EAAG,IAAI,IAAIC,MAAAA,WAAW,CAAC,MAAc,IAAI,GAAG,CAAC;AAEnD,QAAM,QAAQC,MAAAA,SAAS,QAAQ,QAAQ,EAAE;AAAA,IACvCC,MAAAA;AAAAA,EAAA;AAOFC,QAAAA,gBAAgB,MAAM;AAGpB,QAAI,M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K,IAAI;AACf,QAAI,kBAAkB,QAAQ,MAAM,KAAM;AAC1C,UAAM,MAAM,IAAI,eAAe,CAAC,CAAC,KAAK,MAAM;AAC1C,eAAS,MAAM,YAAY,KAAK;AAAA,IAClC,CAAC;AACD,QAAI,QAAQ,EAAE;AACd,WAAO,MAAM,IAAI,WAAA;AAAA,EACnB,GAAG,CAAC,cAAc,CAAC;AAEnB,MAAI,kBAAkB,QAAQ,SAAS,aAAa,KAAK,IAAI,GAAG,OAAO;AACvE,SAAO,KAAK,IAAI,GAAG,KAAK,IAAI,SAAS,KAAK,MAAM,QAAQ,cAAc,CAAC,CAAC;AAC1E;;;"}
@@ -0,0 +1,17 @@
1
+ import { ScrollBodyProps } from './data-panel';
2
+ export interface MasonryOptions {
3
+ /** Number of columns (the maximum, when `minColumnWidth` is set). Default 2. */
4
+ columns?: number;
5
+ /** If set, the column count drops below `columns` when the container is too
6
+ * narrow to give every column at least this many pixels. */
7
+ minColumnWidth?: number;
8
+ }
9
+ /**
10
+ * A `scrollBody` component for `DataPanel` with the default two columns. For
11
+ * anything else — a different column count, or responsive columns — build one
12
+ * with `createMasonryScrollBody`.
13
+ */
14
+ export declare function MasonryScrollBody(props: ScrollBodyProps & MasonryOptions): import('react').DOMElement<import('react').DOMAttributes<Element>, Element>;
15
+ /** Build a `scrollBody` masonry component with a fixed or responsive column
16
+ * count: `scrollBody: createMasonryScrollBody({ columns: 3 })`. */
17
+ export declare function createMasonryScrollBody(options?: MasonryOptions): (props: ScrollBodyProps) => import('react').FunctionComponentElement<ScrollBodyProps & MasonryOptions>;
@@ -0,0 +1,118 @@
1
+ import h from "./masonry.module.sass.js";
2
+ import { useRef, useReducer, Children, isValidElement, useLayoutEffect, cloneElement, useState, useEffect } from "react";
3
+ const FALLBACK_ITEM_HEIGHT = 160;
4
+ function MasonryScrollBody(props) {
5
+ const { children, placeholders, columns = 2, minColumnWidth } = props;
6
+ const containerRef = useRef(null);
7
+ const nCols = useColumnCount(containerRef, columns, minColumnWidth);
8
+ const stateRef = useRef(null);
9
+ stateRef.current ??= {
10
+ columns: nCols,
11
+ assign: /* @__PURE__ */ new Map(),
12
+ heights: /* @__PURE__ */ new Map(),
13
+ els: /* @__PURE__ */ new Map(),
14
+ refs: /* @__PURE__ */ new Map()
15
+ };
16
+ const state = stateRef.current;
17
+ const [, bump] = useReducer((x) => x + 1, 0);
18
+ const items = Children.toArray(children).filter(
19
+ isValidElement
20
+ );
21
+ useLayoutEffect(() => {
22
+ if (state.columns !== nCols) {
23
+ state.columns = nCols;
24
+ state.assign.clear();
25
+ }
26
+ for (const [key, el] of state.els) state.heights.set(key, el.offsetHeight);
27
+ const present = new Set(items.map(keyOf));
28
+ for (const key of [...state.assign.keys()]) {
29
+ if (!present.has(key)) state.assign.delete(key);
30
+ }
31
+ for (const key of [...state.heights.keys()]) {
32
+ if (!present.has(key)) state.heights.delete(key);
33
+ }
34
+ const unassigned = items.filter((c) => !state.assign.has(keyOf(c)));
35
+ if (unassigned.length === 0) return;
36
+ const colHeights = new Array(nCols).fill(0);
37
+ for (const [key, col] of state.assign) {
38
+ colHeights[col] += state.heights.get(key) ?? 0;
39
+ }
40
+ for (const child of unassigned) {
41
+ const key = keyOf(child);
42
+ let col = 0;
43
+ for (let c = 1; c < nCols; c++) {
44
+ if (colHeights[c] < colHeights[col]) col = c;
45
+ }
46
+ state.assign.set(key, col);
47
+ colHeights[col] += state.heights.get(key) ?? FALLBACK_ITEM_HEIGHT;
48
+ }
49
+ bump();
50
+ });
51
+ const stale = state.columns !== nCols;
52
+ const columnItems = Array.from({ length: nCols }, () => []);
53
+ items.forEach((child, i) => {
54
+ const key = keyOf(child);
55
+ let assigned = void 0;
56
+ if (!stale) {
57
+ assigned = state.assign.get(key);
58
+ }
59
+ const col = assigned ?? i % nCols;
60
+ columnItems[col].push(
61
+ cloneElement(child, { ref: refFor(state, key) })
62
+ );
63
+ });
64
+ return h("div.data-panel-masonry-body", [
65
+ h(
66
+ "div.data-panel-masonry",
67
+ { ref: containerRef },
68
+ columnItems.map(
69
+ (col, c) => h("div.data-panel-masonry-column", { key: c }, col)
70
+ )
71
+ ),
72
+ h.if(placeholders != null)(
73
+ "div.data-panel-masonry-placeholders",
74
+ placeholders
75
+ )
76
+ ]);
77
+ }
78
+ function createMasonryScrollBody(options = {}) {
79
+ return function MasonryScrollBodyWithOptions(props) {
80
+ return h(MasonryScrollBody, { ...options, ...props });
81
+ };
82
+ }
83
+ function keyOf(child) {
84
+ return String(child.key);
85
+ }
86
+ function refFor(state, key) {
87
+ let cb = state.refs.get(key);
88
+ if (cb == null) {
89
+ cb = (el) => {
90
+ if (el == null) {
91
+ state.els.delete(key);
92
+ } else {
93
+ state.els.set(key, el);
94
+ }
95
+ };
96
+ state.refs.set(key, cb);
97
+ }
98
+ return cb;
99
+ }
100
+ function useColumnCount(ref, columns, minColumnWidth) {
101
+ const [width, setWidth] = useState(null);
102
+ useEffect(() => {
103
+ const el = ref.current;
104
+ if (minColumnWidth == null || el == null) return;
105
+ const obs = new ResizeObserver(([entry]) => {
106
+ setWidth(entry.contentRect.width);
107
+ });
108
+ obs.observe(el);
109
+ return () => obs.disconnect();
110
+ }, [minColumnWidth]);
111
+ if (minColumnWidth == null || width == null) return Math.max(1, columns);
112
+ return Math.max(1, Math.min(columns, Math.floor(width / minColumnWidth)));
113
+ }
114
+ export {
115
+ MasonryScrollBody,
116
+ createMasonryScrollBody
117
+ };
118
+ //# sourceMappingURL=masonry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"masonry.js","sources":["../src/masonry.ts"],"sourcesContent":["/**\n * Masonry scroll body for the `DataPanel` — variable-height cards laid out in\n * equal-width columns, balanced by *measured* height rather than a flat\n * estimate or CSS multi-column.\n *\n * The problem it solves is paging: CSS `columns` re-flows the whole list every\n * time a page is appended, so the cards under the user's cursor move. Here each\n * item is placed in the running-shortest column **once**, keyed by its React\n * key, and then frozen — appending a page never reshuffles what is on screen.\n *\n * Placement is measured: a freshly-appended batch mounts in provisional\n * columns, a `useLayoutEffect` reads each card's real `offsetHeight`, then the\n * batch is greedily assigned from those real heights and re-rendered — all\n * before paint, so only the balanced result is seen.\n *\n * Two things keep the balance honest over many pages:\n *\n * - **Placeholders are not items.** The panel's loading skeletons arrive as\n * `placeholders`, not `children`, and render below the columns. Freezing a\n * column assignment for a skeleton (measured at skeleton height, then\n * replaced by real content) is what makes a masonry drift, one page at a\n * time, into \"this whole page went into one column\".\n * - **Identity is the React key, not the array index.** A sort, filter or\n * refresh replaces the keys, and assignments for keys that are gone are\n * pruned — so column heights are always recomputed from items that are\n * actually on screen.\n */\nimport h from \"./masonry.module.sass\";\nimport {\n Children,\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n useEffect,\n useLayoutEffect,\n useReducer,\n useRef,\n useState,\n} from \"react\";\nimport type { ScrollBodyProps } from \"./data-panel\";\n\n/** Height assumed for an item that hasn't been measured yet (it always is, by\n * the time it matters — this only guards a torn-down/hidden container). */\nconst FALLBACK_ITEM_HEIGHT = 160;\n\nexport interface MasonryOptions {\n /** Number of columns (the maximum, when `minColumnWidth` is set). Default 2. */\n columns?: number;\n /** If set, the column count drops below `columns` when the container is too\n * narrow to give every column at least this many pixels. */\n minColumnWidth?: number;\n}\n\ninterface MasonryState {\n /** Column count the current assignments were computed for. */\n columns: number;\n /** Frozen key → column. */\n assign: Map<string, number>;\n /** Last measured height per key. */\n heights: Map<string, number>;\n /** Mounted element per key, for measurement. */\n els: Map<string, HTMLElement>;\n /** Stable ref callbacks, so an item isn't detached/reattached every render. */\n refs: Map<string, (el: HTMLElement | null) => void>;\n}\n\n/**\n * A `scrollBody` component for `DataPanel` with the default two columns. For\n * anything else — a different column count, or responsive columns — build one\n * with `createMasonryScrollBody`.\n */\nexport function MasonryScrollBody(props: ScrollBodyProps & MasonryOptions) {\n const { children, placeholders, columns = 2, minColumnWidth } = props;\n\n const containerRef = useRef<HTMLDivElement | null>(null);\n const nCols = useColumnCount(containerRef, columns, minColumnWidth);\n\n const stateRef = useRef<MasonryState | null>(null);\n stateRef.current ??= {\n columns: nCols,\n assign: new Map(),\n heights: new Map(),\n els: new Map(),\n refs: new Map(),\n };\n const state = stateRef.current;\n const [, bump] = useReducer((x: number) => x + 1, 0);\n\n const items = Children.toArray(children).filter(\n isValidElement,\n ) as ReactElement[];\n\n // Runs on every commit (no deps): measurement has to see the layout that was\n // just produced, including one caused by a resize or a card's own content\n // settling. It is cheap when nothing is unassigned, and re-renders only when\n // it actually assigns something — so there's no render loop.\n useLayoutEffect(() => {\n // A column-count change invalidates every assignment (a column may no\n // longer exist). Handled here, not in render, so render stays pure.\n if (state.columns !== nCols) {\n state.columns = nCols;\n state.assign.clear();\n }\n\n for (const [key, el] of state.els) state.heights.set(key, el.offsetHeight);\n\n const present = new Set(items.map(keyOf));\n for (const key of [...state.assign.keys()]) {\n if (!present.has(key)) state.assign.delete(key);\n }\n for (const key of [...state.heights.keys()]) {\n if (!present.has(key)) state.heights.delete(key);\n }\n\n const unassigned = items.filter((c) => !state.assign.has(keyOf(c)));\n if (unassigned.length === 0) return;\n\n // Column heights from the items already frozen into them…\n const colHeights = new Array(nCols).fill(0);\n for (const [key, col] of state.assign) {\n colHeights[col] += state.heights.get(key) ?? 0;\n }\n // …then greedily place the new batch by its just-measured real heights.\n for (const child of unassigned) {\n const key = keyOf(child);\n let col = 0;\n for (let c = 1; c < nCols; c++) {\n if (colHeights[c] < colHeights[col]) col = c;\n }\n state.assign.set(key, col);\n colHeights[col] += state.heights.get(key) ?? FALLBACK_ITEM_HEIGHT;\n }\n bump(); // move the new batch into its balanced columns, before paint\n });\n\n // Items without an assignment yet render in a provisional column so they\n // mount and can be measured; the layout effect above then places them.\n const stale = state.columns !== nCols;\n const columnItems: ReactNode[][] = Array.from({ length: nCols }, () => []);\n items.forEach((child, i) => {\n const key = keyOf(child);\n let assigned: number | undefined = undefined;\n if (!stale) {\n assigned = state.assign.get(key);\n }\n const col = assigned ?? i % nCols;\n columnItems[col].push(\n cloneElement(child, { ref: refFor(state, key) } as any),\n );\n });\n\n return h(\"div.data-panel-masonry-body\", [\n h(\n \"div.data-panel-masonry\",\n { ref: containerRef },\n columnItems.map((col, c) =>\n h(\"div.data-panel-masonry-column\", { key: c }, col),\n ),\n ),\n h.if(placeholders != null)(\n \"div.data-panel-masonry-placeholders\",\n placeholders,\n ),\n ]);\n}\n\n/** Build a `scrollBody` masonry component with a fixed or responsive column\n * count: `scrollBody: createMasonryScrollBody({ columns: 3 })`. */\nexport function createMasonryScrollBody(options: MasonryOptions = {}) {\n return function MasonryScrollBodyWithOptions(props: ScrollBodyProps) {\n return h(MasonryScrollBody, { ...options, ...props });\n };\n}\n\nfunction keyOf(child: ReactElement): string {\n return String(child.key);\n}\n\n/** One stable ref callback per key — a fresh closure each render would detach\n * and reattach every card on every render. */\nfunction refFor(state: MasonryState, key: string) {\n let cb = state.refs.get(key);\n if (cb == null) {\n cb = (el: HTMLElement | null) => {\n if (el == null) {\n state.els.delete(key);\n } else {\n state.els.set(key, el);\n }\n };\n state.refs.set(key, cb);\n }\n return cb;\n}\n\n/** The effective column count: `columns`, reduced to fit `minColumnWidth`. */\nfunction useColumnCount(\n ref: { current: HTMLElement | null },\n columns: number,\n minColumnWidth: number | undefined,\n): number {\n const [width, setWidth] = useState<number | null>(null);\n\n useEffect(() => {\n const el = ref.current;\n if (minColumnWidth == null || el == null) return;\n const obs = new ResizeObserver(([entry]) => {\n setWidth(entry.contentRect.width);\n });\n obs.observe(el);\n return () => obs.disconnect();\n }, [minColumnWidth]);\n\n if (minColumnWidth == null || width == null) return Math.max(1, columns);\n return Math.max(1, Math.min(columns, Math.floor(width / minColumnWidth)));\n}\n"],"names":[],"mappings":";;AA4CA,MAAM,uBAAuB;AA4BtB,SAAS,kBAAkB,OAAyC;AACzE,QAAM,EAAE,UAAU,cAAc,UAAU,GAAG,mBAAmB;AAEhE,QAAM,eAAe,OAA8B,IAAI;AACvD,QAAM,QAAQ,eAAe,cAAc,SAAS,cAAc;AAElE,QAAM,WAAW,O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,SAAK,CAAC,OAA2B;AAC/B,UAAI,MAAM,MAAM;AACd,cAAM,IAAI,OAAO,GAAG;AAAA,MACtB,OAAO;AACL,cAAM,IAAI,IAAI,KAAK,EAAE;AAAA,MACvB;AAAA,IACF;AACA,UAAM,KAAK,IAAI,KAAK,EAAE;AAAA,EACxB;AACA,SAAO;AACT;AAGA,SAAS,eACP,KACA,SACA,gBACQ;AACR,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AAEtD,YAAU,MAAM;AACd,UAAM,KAAK,IAAI;AACf,QAAI,kBAAkB,QAAQ,MAAM,KAAM;AAC1C,UAAM,MAAM,IAAI,eAAe,CAAC,CAAC,KAAK,MAAM;AAC1C,eAAS,MAAM,YAAY,KAAK;AAAA,IAClC,CAAC;AACD,QAAI,QAAQ,EAAE;AACd,WAAO,MAAM,IAAI,WAAA;AAAA,EACnB,GAAG,CAAC,cAAc,CAAC;AAEnB,MAAI,kBAAkB,QAAQ,SAAS,aAAa,KAAK,IAAI,GAAG,OAAO;AACvE,SAAO,KAAK,IAAI,GAAG,KAAK,IAAI,SAAS,KAAK,MAAM,QAAQ,cAAc,CAAC,CAAC;AAC1E;"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ const h$1 = require("@macrostrat/hyper");
3
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
4
+ const h__default = /* @__PURE__ */ _interopDefault(h$1);
5
+ const styles = {
6
+ "data-panel-masonry-body": "_data-panel-masonry-body_1oiqg_1",
7
+ "data-panel-masonry": "_data-panel-masonry_1oiqg_1",
8
+ "data-panel-masonry-column": "_data-panel-masonry-column_1oiqg_13",
9
+ "data-panel-masonry-placeholders": "_data-panel-masonry-placeholders_1oiqg_21"
10
+ };
11
+ let h = h__default.default.styled(styles);
12
+ Object.assign(h, styles);
13
+ module.exports = h;
14
+ //# sourceMappingURL=masonry.module.sass.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"masonry.module.sass.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
@@ -0,0 +1,13 @@
1
+ import h$1 from "@macrostrat/hyper";
2
+ const styles = {
3
+ "data-panel-masonry-body": "_data-panel-masonry-body_1oiqg_1",
4
+ "data-panel-masonry": "_data-panel-masonry_1oiqg_1",
5
+ "data-panel-masonry-column": "_data-panel-masonry-column_1oiqg_13",
6
+ "data-panel-masonry-placeholders": "_data-panel-masonry-placeholders_1oiqg_21"
7
+ };
8
+ let h = h$1.styled(styles);
9
+ Object.assign(h, styles);
10
+ export {
11
+ h as default
12
+ };
13
+ //# sourceMappingURL=masonry.module.sass.js.map