@backmatter/next 0.0.59 → 0.0.60

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backmatter/next",
3
- "version": "0.0.59",
3
+ "version": "0.0.60",
4
4
  "description": "Experimental Next.js adapter for Backmatter. APIs will break. Not ready for production.",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -47,10 +47,10 @@
47
47
  "test": "bun test"
48
48
  },
49
49
  "dependencies": {
50
- "@backmatter/core": "^0.0.46",
50
+ "@backmatter/core": "^0.0.47",
51
51
  "@mdx-js/mdx": "^3.1.1",
52
52
  "remark-gfm": "^4.0.1",
53
- "@backmatter/studio": "^0.0.36"
53
+ "@backmatter/studio": "^0.0.37"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "next": ">=16.3.0",
@@ -4,13 +4,15 @@
4
4
  // Client side of the block gallery. The shell covers the host's layout (its
5
5
  // header, footer and dev bar) with a scrolling panel, so only blocks show
6
6
  // while the site's CSS still applies. It takes live props from Studio and
7
- // reports which example the editor wants to open. Each block is boxed so a
7
+ // reports which example the editor wants to open. The single view reports its
8
+ // height so Studio can size the frame to the block. Each block is boxed so a
8
9
  // fixed or full-height block stays in its own frame, and a block that throws
9
10
  // shows a note instead of breaking the page.
10
- import { Component, useEffect, useState, startTransition, type ReactNode } from "react";
11
+ import { Component, useEffect, useRef, useState, startTransition, type ReactNode } from "react";
11
12
  import { useRouter } from "next/navigation";
12
13
  import {
13
14
  BLOCK_GALLERY_OPEN_MESSAGE,
15
+ BLOCK_GALLERY_SIZE_MESSAGE,
14
16
  blockGalleryPath,
15
17
  isBlockGalleryPropsMessage,
16
18
  readBlockGalleryQuery,
@@ -40,6 +42,7 @@ export function BlockGalleryShell({
40
42
  }) {
41
43
  const router = useRouter();
42
44
  const [background, setBackground] = useState("#fff");
45
+ const content = useRef<HTMLDivElement>(null);
43
46
 
44
47
  useEffect(() => {
45
48
  const color = getComputedStyle(document.body).backgroundColor;
@@ -65,6 +68,22 @@ export function BlockGalleryShell({
65
68
  return () => window.removeEventListener("message", onMessage);
66
69
  }, [single, dashboardOrigins, router]);
67
70
 
71
+ useEffect(() => {
72
+ const el = content.current;
73
+ if (!single || !el || typeof ResizeObserver === "undefined") return;
74
+ let last = -1;
75
+ const report = () => {
76
+ const height = Math.ceil(el.getBoundingClientRect().height);
77
+ if (height === last) return;
78
+ last = height;
79
+ postToStudio({ type: BLOCK_GALLERY_SIZE_MESSAGE, height });
80
+ };
81
+ const observer = new ResizeObserver(report);
82
+ observer.observe(el);
83
+ report();
84
+ return () => observer.disconnect();
85
+ }, [single]);
86
+
68
87
  return (
69
88
  <div
70
89
  data-backmatter-block-gallery=""
@@ -77,7 +96,7 @@ export function BlockGalleryShell({
77
96
  background,
78
97
  }}
79
98
  >
80
- {children}
99
+ <div ref={content}>{children}</div>
81
100
  </div>
82
101
  );
83
102
  }