@dxos/react-ui-masonry 0.10.0 → 0.11.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.
@@ -1 +1 @@
1
- {"version":3,"file":"Masonry.d.ts","sourceRoot":"","sources":["../../../src/Masonry.tsx"],"names":[],"mappings":"AAQA,OAAc,EACZ,KAAK,aAAa,EAElB,KAAK,GAAG,EACR,KAAK,iBAAiB,EACtB,KAAK,GAAG,EAGT,MAAM,OAAO,CAAC;AAGf,OAAO,EAAc,mBAAmB,EAAE,eAAe,EAAS,MAAM,gBAAgB,CAAC;AAQzF,KAAK,mBAAmB,GAAG;IACzB,8CAA8C;IAC9C,IAAI,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClD,6CAA6C;IAC7C,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,wCAAwC;IACxC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,mCAAmC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,mCAAmC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAiBF,KAAK,gBAAgB,GAAG,iBAAiB,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC;6BAEnD,EACnB,QAAQ,EACR,IAAI,EACJ,OAAmB,EACnB,UAAsB,EACtB,cAAkC,EAClC,cAAkC,EAClC,MAAa,EACd,EAAE,gBAAgB;;;;AAuBnB,KAAK,mBAAmB,GAAG,eAAe,CACxC,iBAAiB,CAAC,IAAI,CAAC,mBAAmB,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC,CAC7F,CAAC;AAuCF,KAAK,oBAAoB,CAAC,IAAI,IAAI,eAAe,CAAC;IAChD,2CAA2C;IAC3C,KAAK,EAAE,S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CAAC,IAAI,CAAC,GAAG;QAClC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;KAClC,KACE,GAAG,CAAC,OAAO;CAoDf,CAAC;AAEF,YAAY,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { type StoryObj } from '@storybook/react-vite';
2
2
  import React from 'react';
3
- import { MasonryRootProps } from './Masonry';
3
+ import { type MasonryRootProps } from './Masonry';
4
4
  declare const meta: {
5
5
  title: string;
6
6
  render: (props: MasonryRootProps) => React.JSX.Element;
@@ -8,6 +8,14 @@ declare const meta: {
8
8
  parameters: {
9
9
  layout: string;
10
10
  };
11
+ argTypes: {
12
+ animate: {
13
+ control: "boolean";
14
+ };
15
+ };
16
+ args: {
17
+ animate: true;
18
+ };
11
19
  };
12
20
  export default meta;
13
21
  type Story = StoryObj<typeof meta>;
@@ -1 +1 @@
1
- {"version":3,"file":"Masonry.stories.d.ts","sourceRoot":"","sources":["../../../src/Masonry.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,MAAM,OAAO,CAAC;AAW1B,OAAO,EAAW,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAkCtD,QAAA,MAAM,IAAI;;oBAbmB,gBAAgB;;;QA8BzC,MAAM;;CAEM,CAAC;eAEF,IAAI;AAEnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC"}
1
+ {"version":3,"file":"Masonry.stories.d.ts","sourceRoot":"","sources":["../../../src/Masonry.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAmB,MAAM,OAAO,CAAC;AAMxC,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AA6J3D,QAAA,MAAM,IAAI;;oBAlDmB,gBAAgB;;;QAuDzC,MAAM;;;;;;;;;;CAQ2B,CAAC;eAEvB,IAAI;AAEnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC"}
@@ -0,0 +1,50 @@
1
+ export type Rect = {
2
+ /** Horizontal offset (px) of the tile's left edge. */
3
+ x: number;
4
+ /** Vertical offset (px) of the tile's top edge. */
5
+ y: number;
6
+ /** Column the tile was assigned to. */
7
+ column: number;
8
+ };
9
+ export type LayoutResult = {
10
+ /** Position of each tile, in input order. */
11
+ rects: Rect[];
12
+ /** Width (px) shared by every column. */
13
+ columnWidth: number;
14
+ /** Total content height (px), including the perimeter gap. */
15
+ height: number;
16
+ };
17
+ export type LayoutOptions = {
18
+ /** Measured tile heights (px), in item order. Unmeasured tiles pass 0. */
19
+ heights: readonly number[];
20
+ /** Number of columns to lay out across. */
21
+ columnCount: number;
22
+ /** Available content width (px), already net of any scrollbar allowance. */
23
+ containerWidth: number;
24
+ /** Space (px) between tiles and, vertically, around the grid perimeter. */
25
+ gapPx: number;
26
+ /** Optional cap on column width (px); leftover width centers the columns. */
27
+ maxColumnWidthPx?: number;
28
+ /** Centre capped columns in the container. Off aligns them to the start, leaving the slack at the end. */
29
+ centered?: boolean;
30
+ };
31
+ /**
32
+ * Lay tiles out into balanced columns using column-major greedy assignment: each
33
+ * tile is placed in the currently shortest column (ties resolve to the lowest
34
+ * index for stable ordering). Pure and synchronous so column balancing is unit
35
+ * testable without a DOM.
36
+ *
37
+ * Columns are separated by a single gap. They stretch to fill `containerWidth`
38
+ * unless `maxColumnWidthPx` caps them narrower, in which case the leftover width
39
+ * is split evenly so the grid stays centred (the outer margin grows beyond the
40
+ * gap) — or, with `centered` off, left entirely at the end so the columns align to
41
+ * the start. The base left/right perimeter is owned by the scroll container (via
42
+ * its `--gutter`); the layout adds any centring offset plus the top/bottom perimeter.
43
+ */
44
+ /**
45
+ * Width every column gets, before any tile is placed. Independent of the tiles themselves — which is
46
+ * what lets a caller key cached tile heights by the width they were measured at.
47
+ */
48
+ export declare const getColumnWidth: ({ columnCount, containerWidth, gapPx, maxColumnWidthPx, }: Pick<LayoutOptions, 'columnCount' | 'containerWidth' | 'gapPx' | 'maxColumnWidthPx'>) => number;
49
+ export declare const layout: ({ heights, columnCount, containerWidth, gapPx, maxColumnWidthPx, centered, }: LayoutOptions) => LayoutResult;
50
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../src/layout.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,IAAI,GAAG;IACjB,sDAAsD;IACtD,CAAC,EAAE,MAAM,CAAC;IACV,mDAAmD;IACnD,CAAC,EAAE,MAAM,CAAC;IACV,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,6CAA6C;IAC7C,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,yCAAyC;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,0EAA0E;IAC1E,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,cAAc,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0GAA0G;IAC1G,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH;;;GAGG;AACH,eAAO,MAAM,cAAc,8DAKxB,IAAI,CAAC,aAAa,EAAE,aAAa,GAAG,gBAAgB,GAAG,OAAO,GAAG,kBAAkB,CAAC,KAAG,MAIzF,CAAC;AAEF,eAAO,MAAM,MAAM,iFAOhB,aAAa,KAAG,YAgClB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=layout.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.test.d.ts","sourceRoot":"","sources":["../../../src/layout.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,37 @@
1
+ import { type RefObject } from 'react';
2
+ import { type Rect } from './layout';
3
+ export declare const prefersReducedMotion: () => boolean;
4
+ /**
5
+ * Decide whether a layout transition should animate. Animate only genuine small
6
+ * incremental edits on a stable container: a resize snaps (the whole grid moves),
7
+ * and a zero add/remove delta means either the initial bulk render's height-settling
8
+ * pass or a pure resize — both snap so the grid never animates into place from the
9
+ * degenerate all-heights-zero layout.
10
+ */
11
+ export declare const shouldAnimateReflow: ({ added, removed, resized, maxDelta, }: {
12
+ added: number;
13
+ removed: number;
14
+ resized: boolean;
15
+ maxDelta?: number;
16
+ }) => boolean;
17
+ export type UseFlipOptions = {
18
+ /** Tile wrappers by id, kept live by the layout hook. */
19
+ nodes: RefObject<Map<string, HTMLElement>>;
20
+ /** Item ids in render order (aligned with `rects`). */
21
+ ids: readonly string[];
22
+ /** Target positions (aligned with `ids`). */
23
+ rects: readonly Rect[];
24
+ /** Current column count; a change marks a resize, which snaps rather than animates. */
25
+ columnCount: number;
26
+ /** Current content width (px); a change marks a resize, which snaps rather than animates. */
27
+ containerWidth: number;
28
+ /** Disable to snap without animating (also skipped under reduced-motion and on bulk reflows). */
29
+ enabled: boolean;
30
+ };
31
+ /**
32
+ * Animates tile position changes with FLIP: tiles that moved between layouts
33
+ * transition from their previous translate to the new one via the Web Animations
34
+ * API; freshly-added tiles fade/scale in. Respects `prefers-reduced-motion`.
35
+ */
36
+ export declare const useFlip: ({ nodes, ids, rects, columnCount, containerWidth, enabled }: UseFlipOptions) => void;
37
+ //# sourceMappingURL=useFlip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFlip.d.ts","sourceRoot":"","sources":["../../../src/useFlip.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAA2B,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,UAAU,CAAC;AAYrC,eAAO,MAAM,oBAAoB,eACiE,CAAC;AAEnG;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,2CAK7B;IACD,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,KAAG,OAAyE,CAAC;AAE9E,MAAM,MAAM,cAAc,GAAG;IAC3B,yDAAyD;IACzD,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAC3C,uDAAuD;IACvD,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IACvB,6CAA6C;IAC7C,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IACvB,uFAAuF;IACvF,WAAW,EAAE,MAAM,CAAC;IACpB,6FAA6F;IAC7F,cAAc,EAAE,MAAM,CAAC;IACvB,iGAAiG;IACjG,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,OAAO,gEAAiE,cAAc,KAAG,IA4ErG,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useFlip.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFlip.test.d.ts","sourceRoot":"","sources":["../../../src/useFlip.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ import { type RefObject } from 'react';
2
+ import { type LayoutResult } from './layout';
3
+ /** Clears the shared height cache. Exported for tests and for callers that recycle ids. */
4
+ export declare const clearHeightCache: () => void;
5
+ export type MasonryLayout = LayoutResult & {
6
+ /** True once every tile has a height measured at the current column width, so positions are final. */
7
+ measured: boolean;
8
+ /**
9
+ * Ids the layout has some height for — measured now, or remembered from a previous mount or width.
10
+ * Anything outside this set is sitting at a guess and should not be painted.
11
+ */
12
+ knownIds: ReadonlySet<string>;
13
+ /** Stable ref callback for the tile wrapper of `id` (measures + registers it). */
14
+ getTileRef: (id: string) => (element: HTMLElement | null) => void;
15
+ /** Live map of currently-mounted tile wrappers by id (for FLIP positioning). */
16
+ nodes: RefObject<Map<string, HTMLElement>>;
17
+ };
18
+ export type UseMasonryLayoutOptions = {
19
+ /** Ids of the items to lay out, in render order. */
20
+ ids: readonly string[];
21
+ columnCount: number;
22
+ /** Available content width (px), net of scrollbar allowance. */
23
+ containerWidth: number;
24
+ gapPx: number;
25
+ /** Optional cap on column width (px). */
26
+ maxColumnWidthPx?: number;
27
+ /** Centre capped columns in the container (see `layout`). */
28
+ centered?: boolean;
29
+ /**
30
+ * Scope for remembered tile heights, e.g. the collection's URI. Omit when ids are not stable and
31
+ * unique across the app (the default index ids are not) — heights are then per-instance, and a
32
+ * remount re-measures.
33
+ */
34
+ cacheKey?: string;
35
+ };
36
+ /**
37
+ * Measures tile heights via a shared ResizeObserver and computes balanced column
38
+ * positions. Heights are keyed by item id so reorders and removals reuse prior
39
+ * measurements; a version counter re-runs the pure layout when a height changes.
40
+ */
41
+ export declare const useMasonryLayout: ({ ids, columnCount, containerWidth, gapPx, maxColumnWidthPx, centered, cacheKey, }: UseMasonryLayoutOptions) => MasonryLayout;
42
+ //# sourceMappingURL=useMasonryLayout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMasonryLayout.d.ts","sourceRoot":"","sources":["../../../src/useMasonryLayout.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAqD,MAAM,OAAO,CAAC;AAE1F,OAAO,EAAE,KAAK,YAAY,EAA0B,MAAM,UAAU,CAAC;AA8CrE,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB,QAAO,IAA2B,CAAC;AAEhE,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG;IACzC,sGAAsG;IACtG,QAAQ,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9B,kFAAkF;IAClF,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAC;IAClE,gFAAgF;IAChF,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,oDAAoD;IACpD,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,gEAAgE;IAChE,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,uFAQ1B,uBAAuB,KAAG,aA2I5B,CAAC"}