@notionhq/custom-blocks 0.0.58

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 (298) hide show
  1. package/HOST.md +171 -0
  2. package/README.md +57 -0
  3. package/bin/cli/attach.js +180 -0
  4. package/bin/cli/cli.js +248 -0
  5. package/bin/cli/create.js +106 -0
  6. package/bin/cli/datasources.js +255 -0
  7. package/bin/cli/deploy.js +109 -0
  8. package/bin/cli/ids.js +13 -0
  9. package/bin/cli/ntn.js +95 -0
  10. package/bin/cli/pullData.js +76 -0
  11. package/bin/cli/pullManifest.js +158 -0
  12. package/bin/cli/target.js +95 -0
  13. package/bin/src/bridge/dataSources/propertySchema.js +148 -0
  14. package/bin/src/bridge/manifest.js +40 -0
  15. package/dist/autoResize.d.ts +4 -0
  16. package/dist/autoResize.d.ts.map +1 -0
  17. package/dist/autoResize.js +71 -0
  18. package/dist/bridge/SandboxBridge.d.ts +92 -0
  19. package/dist/bridge/SandboxBridge.d.ts.map +1 -0
  20. package/dist/bridge/SandboxBridge.js +718 -0
  21. package/dist/bridge/dataSources/dataSource.d.ts +732 -0
  22. package/dist/bridge/dataSources/dataSource.d.ts.map +1 -0
  23. package/dist/bridge/dataSources/dataSource.js +37 -0
  24. package/dist/bridge/dataSources/dataSourcePage.d.ts +118 -0
  25. package/dist/bridge/dataSources/dataSourcePage.d.ts.map +1 -0
  26. package/dist/bridge/dataSources/dataSourcePage.js +14 -0
  27. package/dist/bridge/dataSources/dataSourceValue.d.ts +67 -0
  28. package/dist/bridge/dataSources/dataSourceValue.d.ts.map +1 -0
  29. package/dist/bridge/dataSources/dataSourceValue.js +14 -0
  30. package/dist/bridge/dataSources/dateValue.d.ts +158 -0
  31. package/dist/bridge/dataSources/dateValue.d.ts.map +1 -0
  32. package/dist/bridge/dataSources/dateValue.js +59 -0
  33. package/dist/bridge/dataSources/errors.d.ts +6 -0
  34. package/dist/bridge/dataSources/errors.d.ts.map +1 -0
  35. package/dist/bridge/dataSources/errors.js +4 -0
  36. package/dist/bridge/dataSources/propertySchema.d.ts +191 -0
  37. package/dist/bridge/dataSources/propertySchema.d.ts.map +1 -0
  38. package/dist/bridge/dataSources/propertySchema.js +148 -0
  39. package/dist/bridge/dataSources/recordPointer.d.ts +10 -0
  40. package/dist/bridge/dataSources/recordPointer.d.ts.map +1 -0
  41. package/dist/bridge/dataSources/recordPointer.js +8 -0
  42. package/dist/bridge/dataSources/resolve.d.ts +22 -0
  43. package/dist/bridge/dataSources/resolve.d.ts.map +1 -0
  44. package/dist/bridge/dataSources/resolve.js +65 -0
  45. package/dist/bridge/dataSources/resolveProperty.d.ts +41 -0
  46. package/dist/bridge/dataSources/resolveProperty.d.ts.map +1 -0
  47. package/dist/bridge/dataSources/resolveProperty.js +73 -0
  48. package/dist/bridge/errors.d.ts +12 -0
  49. package/dist/bridge/errors.d.ts.map +1 -0
  50. package/dist/bridge/errors.js +6 -0
  51. package/dist/bridge/hostState.d.ts +65 -0
  52. package/dist/bridge/hostState.d.ts.map +1 -0
  53. package/dist/bridge/hostState.js +65 -0
  54. package/dist/bridge/ids.d.ts +39 -0
  55. package/dist/bridge/ids.d.ts.map +1 -0
  56. package/dist/bridge/ids.js +5 -0
  57. package/dist/bridge/incomingType.d.ts +10 -0
  58. package/dist/bridge/incomingType.d.ts.map +1 -0
  59. package/dist/bridge/incomingType.js +17 -0
  60. package/dist/bridge/loadManifest.d.ts +25 -0
  61. package/dist/bridge/loadManifest.d.ts.map +1 -0
  62. package/dist/bridge/loadManifest.js +68 -0
  63. package/dist/bridge/manifest.d.ts +66 -0
  64. package/dist/bridge/manifest.d.ts.map +1 -0
  65. package/dist/bridge/manifest.js +40 -0
  66. package/dist/bridge/messages/createPage.d.ts +225 -0
  67. package/dist/bridge/messages/createPage.d.ts.map +1 -0
  68. package/dist/bridge/messages/createPage.js +46 -0
  69. package/dist/bridge/messages/createPageResult.d.ts +211 -0
  70. package/dist/bridge/messages/createPageResult.d.ts.map +1 -0
  71. package/dist/bridge/messages/createPageResult.js +28 -0
  72. package/dist/bridge/messages/currentUserChanged.d.ts +19 -0
  73. package/dist/bridge/messages/currentUserChanged.d.ts.map +1 -0
  74. package/dist/bridge/messages/currentUserChanged.js +9 -0
  75. package/dist/bridge/messages/dataSourcesChanged.d.ts +158 -0
  76. package/dist/bridge/messages/dataSourcesChanged.d.ts.map +1 -0
  77. package/dist/bridge/messages/dataSourcesChanged.js +13 -0
  78. package/dist/bridge/messages/getPage.d.ts +216 -0
  79. package/dist/bridge/messages/getPage.d.ts.map +1 -0
  80. package/dist/bridge/messages/getPage.js +33 -0
  81. package/dist/bridge/messages/getUser.d.ts +45 -0
  82. package/dist/bridge/messages/getUser.d.ts.map +1 -0
  83. package/dist/bridge/messages/getUser.js +32 -0
  84. package/dist/bridge/messages/hostToSandbox.d.ts +1089 -0
  85. package/dist/bridge/messages/hostToSandbox.d.ts.map +1 -0
  86. package/dist/bridge/messages/hostToSandbox.js +32 -0
  87. package/dist/bridge/messages/init.d.ts +209 -0
  88. package/dist/bridge/messages/init.d.ts.map +1 -0
  89. package/dist/bridge/messages/init.js +47 -0
  90. package/dist/bridge/messages/invalidHostMessage.d.ts +15 -0
  91. package/dist/bridge/messages/invalidHostMessage.d.ts.map +1 -0
  92. package/dist/bridge/messages/invalidHostMessage.js +13 -0
  93. package/dist/bridge/messages/invalidSandboxMessage.d.ts +15 -0
  94. package/dist/bridge/messages/invalidSandboxMessage.d.ts.map +1 -0
  95. package/dist/bridge/messages/invalidSandboxMessage.js +13 -0
  96. package/dist/bridge/messages/listUsers.d.ts +53 -0
  97. package/dist/bridge/messages/listUsers.d.ts.map +1 -0
  98. package/dist/bridge/messages/listUsers.js +33 -0
  99. package/dist/bridge/messages/pageChanged.d.ts +12 -0
  100. package/dist/bridge/messages/pageChanged.d.ts.map +1 -0
  101. package/dist/bridge/messages/pageChanged.js +9 -0
  102. package/dist/bridge/messages/parentChanged.d.ts +22 -0
  103. package/dist/bridge/messages/parentChanged.d.ts.map +1 -0
  104. package/dist/bridge/messages/parentChanged.js +9 -0
  105. package/dist/bridge/messages/queryDataSource.d.ts +20 -0
  106. package/dist/bridge/messages/queryDataSource.d.ts.map +1 -0
  107. package/dist/bridge/messages/queryDataSource.js +19 -0
  108. package/dist/bridge/messages/queryDataSourceResult.d.ts +90 -0
  109. package/dist/bridge/messages/queryDataSourceResult.d.ts.map +1 -0
  110. package/dist/bridge/messages/queryDataSourceResult.js +21 -0
  111. package/dist/bridge/messages/ready.d.ts +45 -0
  112. package/dist/bridge/messages/ready.d.ts.map +1 -0
  113. package/dist/bridge/messages/ready.js +37 -0
  114. package/dist/bridge/messages/resize.d.ts +12 -0
  115. package/dist/bridge/messages/resize.d.ts.map +1 -0
  116. package/dist/bridge/messages/resize.js +10 -0
  117. package/dist/bridge/messages/sandboxToHost.d.ts +410 -0
  118. package/dist/bridge/messages/sandboxToHost.d.ts.map +1 -0
  119. package/dist/bridge/messages/sandboxToHost.js +25 -0
  120. package/dist/bridge/messages/themeChanged.d.ts +11 -0
  121. package/dist/bridge/messages/themeChanged.d.ts.map +1 -0
  122. package/dist/bridge/messages/themeChanged.js +10 -0
  123. package/dist/bridge/messages/updatePage.d.ts +171 -0
  124. package/dist/bridge/messages/updatePage.d.ts.map +1 -0
  125. package/dist/bridge/messages/updatePage.js +15 -0
  126. package/dist/bridge/messages/updatePageResult.d.ts +210 -0
  127. package/dist/bridge/messages/updatePageResult.d.ts.map +1 -0
  128. package/dist/bridge/messages/updatePageResult.js +27 -0
  129. package/dist/bridge/pages/page.d.ts +600 -0
  130. package/dist/bridge/pages/page.d.ts.map +1 -0
  131. package/dist/bridge/pages/page.js +217 -0
  132. package/dist/bridge/parent.d.ts +25 -0
  133. package/dist/bridge/parent.d.ts.map +1 -0
  134. package/dist/bridge/parent.js +11 -0
  135. package/dist/bridge/pendingRequests.d.ts +14 -0
  136. package/dist/bridge/pendingRequests.d.ts.map +1 -0
  137. package/dist/bridge/pendingRequests.js +27 -0
  138. package/dist/bridge/sandboxClient.d.ts +63 -0
  139. package/dist/bridge/sandboxClient.d.ts.map +1 -0
  140. package/dist/bridge/sandboxClient.js +92 -0
  141. package/dist/bridge/theme.d.ts +4 -0
  142. package/dist/bridge/theme.d.ts.map +1 -0
  143. package/dist/bridge/theme.js +2 -0
  144. package/dist/bridge/users/user.d.ts +36 -0
  145. package/dist/bridge/users/user.d.ts.map +1 -0
  146. package/dist/bridge/users/user.js +19 -0
  147. package/dist/customBlock.d.ts +36 -0
  148. package/dist/customBlock.d.ts.map +1 -0
  149. package/dist/customBlock.js +65 -0
  150. package/dist/host/createCustomBlockHost.d.ts +34 -0
  151. package/dist/host/createCustomBlockHost.d.ts.map +1 -0
  152. package/dist/host/createCustomBlockHost.js +278 -0
  153. package/dist/host/lifecycle/initErrors.d.ts +10 -0
  154. package/dist/host/lifecycle/initErrors.d.ts.map +1 -0
  155. package/dist/host/lifecycle/initErrors.js +123 -0
  156. package/dist/host/lifecycle/ready.d.ts +8 -0
  157. package/dist/host/lifecycle/ready.d.ts.map +1 -0
  158. package/dist/host/lifecycle/ready.js +24 -0
  159. package/dist/host/lifecycle/types.d.ts +24 -0
  160. package/dist/host/lifecycle/types.d.ts.map +1 -0
  161. package/dist/host/lifecycle/types.js +1 -0
  162. package/dist/host/messages/invalidSandboxMessage.d.ts +7 -0
  163. package/dist/host/messages/invalidSandboxMessage.d.ts.map +1 -0
  164. package/dist/host/messages/invalidSandboxMessage.js +24 -0
  165. package/dist/host/messages/types.d.ts +60 -0
  166. package/dist/host/messages/types.d.ts.map +1 -0
  167. package/dist/host/messages/types.js +1 -0
  168. package/dist/host/queries/querySubscriptions.d.ts +20 -0
  169. package/dist/host/queries/querySubscriptions.d.ts.map +1 -0
  170. package/dist/host/queries/querySubscriptions.js +29 -0
  171. package/dist/host/queries/types.d.ts +9 -0
  172. package/dist/host/queries/types.d.ts.map +1 -0
  173. package/dist/host/queries/types.js +1 -0
  174. package/dist/host.d.ts +73 -0
  175. package/dist/host.d.ts.map +1 -0
  176. package/dist/host.js +42 -0
  177. package/dist/index.d.ts +37 -0
  178. package/dist/index.d.ts.map +1 -0
  179. package/dist/index.js +14 -0
  180. package/dist/init.d.ts +53 -0
  181. package/dist/init.d.ts.map +1 -0
  182. package/dist/init.js +87 -0
  183. package/dist/react/DebugMessageLog.d.ts +2 -0
  184. package/dist/react/DebugMessageLog.d.ts.map +1 -0
  185. package/dist/react/DebugMessageLog.js +22 -0
  186. package/dist/react/NotionCustomBlock.css +110 -0
  187. package/dist/react/NotionCustomBlock.d.ts +50 -0
  188. package/dist/react/NotionCustomBlock.d.ts.map +1 -0
  189. package/dist/react/NotionCustomBlock.js +81 -0
  190. package/dist/react/index.d.ts +14 -0
  191. package/dist/react/index.d.ts.map +1 -0
  192. package/dist/react/index.js +13 -0
  193. package/dist/react/standalonePreview.d.ts +2 -0
  194. package/dist/react/standalonePreview.d.ts.map +1 -0
  195. package/dist/react/standalonePreview.js +26 -0
  196. package/dist/react/useCustomBlockAutoResize.d.ts +30 -0
  197. package/dist/react/useCustomBlockAutoResize.d.ts.map +1 -0
  198. package/dist/react/useCustomBlockAutoResize.js +35 -0
  199. package/dist/react/useCustomBlockInit.d.ts +43 -0
  200. package/dist/react/useCustomBlockInit.d.ts.map +1 -0
  201. package/dist/react/useCustomBlockInit.js +60 -0
  202. package/dist/react/useDataSource.d.ts +13 -0
  203. package/dist/react/useDataSource.d.ts.map +1 -0
  204. package/dist/react/useDataSource.js +37 -0
  205. package/dist/react/useHostState.d.ts +2 -0
  206. package/dist/react/useHostState.d.ts.map +1 -0
  207. package/dist/react/useHostState.js +5 -0
  208. package/dist/react/useRuntimeState.d.ts +66 -0
  209. package/dist/react/useRuntimeState.d.ts.map +1 -0
  210. package/dist/react/useRuntimeState.js +73 -0
  211. package/dist/types.d.ts +154 -0
  212. package/dist/types.d.ts.map +1 -0
  213. package/dist/types.js +1 -0
  214. package/dist/utils.d.ts +9 -0
  215. package/dist/utils.d.ts.map +1 -0
  216. package/dist/utils.js +10 -0
  217. package/dist/version.d.ts +9 -0
  218. package/dist/version.d.ts.map +1 -0
  219. package/dist/version.js +7 -0
  220. package/docs/block-location.md +83 -0
  221. package/docs/data-sources.md +186 -0
  222. package/docs/lifecycle.md +172 -0
  223. package/docs/manifest.md +42 -0
  224. package/docs/pages.md +143 -0
  225. package/docs/users.md +92 -0
  226. package/package.json +69 -0
  227. package/src/autoResize.ts +84 -0
  228. package/src/bridge/SandboxBridge.ts +921 -0
  229. package/src/bridge/dataSources/dataSource.ts +63 -0
  230. package/src/bridge/dataSources/dataSourcePage.ts +71 -0
  231. package/src/bridge/dataSources/dataSourceValue.ts +19 -0
  232. package/src/bridge/dataSources/dateValue.ts +96 -0
  233. package/src/bridge/dataSources/errors.ts +14 -0
  234. package/src/bridge/dataSources/propertySchema.ts +186 -0
  235. package/src/bridge/dataSources/recordPointer.ts +13 -0
  236. package/src/bridge/dataSources/resolve.ts +99 -0
  237. package/src/bridge/dataSources/resolveProperty.ts +130 -0
  238. package/src/bridge/errors.ts +13 -0
  239. package/src/bridge/hostState.ts +154 -0
  240. package/src/bridge/ids.ts +58 -0
  241. package/src/bridge/incomingType.ts +19 -0
  242. package/src/bridge/loadManifest.ts +89 -0
  243. package/src/bridge/manifest.ts +53 -0
  244. package/src/bridge/messages/createPage.ts +67 -0
  245. package/src/bridge/messages/createPageResult.ts +52 -0
  246. package/src/bridge/messages/currentUserChanged.ts +14 -0
  247. package/src/bridge/messages/dataSourcesChanged.ts +18 -0
  248. package/src/bridge/messages/getPage.ts +52 -0
  249. package/src/bridge/messages/getUser.ts +48 -0
  250. package/src/bridge/messages/hostToSandbox.ts +37 -0
  251. package/src/bridge/messages/init.ts +81 -0
  252. package/src/bridge/messages/invalidHostMessage.ts +16 -0
  253. package/src/bridge/messages/invalidSandboxMessage.ts +18 -0
  254. package/src/bridge/messages/listUsers.ts +49 -0
  255. package/src/bridge/messages/pageChanged.ts +12 -0
  256. package/src/bridge/messages/parentChanged.ts +14 -0
  257. package/src/bridge/messages/queryDataSource.ts +24 -0
  258. package/src/bridge/messages/queryDataSourceResult.ts +38 -0
  259. package/src/bridge/messages/ready.ts +41 -0
  260. package/src/bridge/messages/resize.ts +13 -0
  261. package/src/bridge/messages/sandboxToHost.ts +30 -0
  262. package/src/bridge/messages/themeChanged.ts +15 -0
  263. package/src/bridge/messages/updatePage.ts +22 -0
  264. package/src/bridge/messages/updatePageResult.ts +49 -0
  265. package/src/bridge/pages/page.ts +281 -0
  266. package/src/bridge/parent.ts +27 -0
  267. package/src/bridge/pendingRequests.ts +28 -0
  268. package/src/bridge/sandboxClient.ts +137 -0
  269. package/src/bridge/theme.ts +5 -0
  270. package/src/bridge/users/user.ts +31 -0
  271. package/src/css.d.ts +1 -0
  272. package/src/customBlock.ts +102 -0
  273. package/src/host/createCustomBlockHost.ts +392 -0
  274. package/src/host/lifecycle/initErrors.ts +132 -0
  275. package/src/host/lifecycle/ready.ts +36 -0
  276. package/src/host/lifecycle/types.ts +28 -0
  277. package/src/host/messages/invalidSandboxMessage.ts +38 -0
  278. package/src/host/messages/types.ts +67 -0
  279. package/src/host/queries/querySubscriptions.ts +52 -0
  280. package/src/host/queries/types.ts +16 -0
  281. package/src/host.ts +167 -0
  282. package/src/index.ts +115 -0
  283. package/src/init.ts +143 -0
  284. package/src/react/DebugMessageLog.tsx +30 -0
  285. package/src/react/NotionCustomBlock.css +110 -0
  286. package/src/react/NotionCustomBlock.tsx +151 -0
  287. package/src/react/index.ts +28 -0
  288. package/src/react/standalonePreview.ts +28 -0
  289. package/src/react/useCustomBlockAutoResize.ts +46 -0
  290. package/src/react/useCustomBlockInit.ts +91 -0
  291. package/src/react/useDataSource.ts +47 -0
  292. package/src/react/useHostState.ts +9 -0
  293. package/src/react/useRuntimeState.ts +85 -0
  294. package/src/types.ts +175 -0
  295. package/src/utils.ts +13 -0
  296. package/src/version.ts +8 -0
  297. package/vite-plugin/index.d.ts +46 -0
  298. package/vite-plugin/index.js +115 -0
@@ -0,0 +1,81 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ import { NotInIframeError } from "../index.js";
4
+ import { DebugMessageLog } from "./DebugMessageLog.js";
5
+ import { seedStandalonePreviewState } from "./standalonePreview.js";
6
+ import { useCustomBlockAutoResize } from "./useCustomBlockAutoResize.js";
7
+ import { useCustomBlockInit } from "./useCustomBlockInit.js";
8
+ import { useCustomBlockHost } from "./useHostState.js";
9
+ import "./NotionCustomBlock.css";
10
+ /**
11
+ * Top-level wrapper that runs the SDK ↔ host handshake and gates `children`
12
+ * until it resolves. Passes `timeoutMs` straight through to
13
+ * {@link initCustomBlock}.
14
+ *
15
+ * Templates that prefer not to write a `Root` gating component (or top-level
16
+ * `await`) can mount their app entirely inside this provider:
17
+ *
18
+ * ```tsx
19
+ * ReactDOM.createRoot(root).render(
20
+ * <NotionCustomBlock>
21
+ * <App />
22
+ * </NotionCustomBlock>,
23
+ * )
24
+ * ```
25
+ *
26
+ * Inside `children`, every SDK hook is guaranteed to return a populated
27
+ * value. Outside the provider (or during the loading window), they throw.
28
+ */
29
+ export function NotionCustomBlock({ children, timeoutMs, fallback = null, errorFallback, autoResize = true, }) {
30
+ const init = useCustomBlockInit({ timeoutMs });
31
+ useCustomBlockAutoResize({ enabled: autoResize });
32
+ const isStandalone = init.error instanceof NotInIframeError;
33
+ const host = useCustomBlockHost();
34
+ const [debugOpen, setDebugOpen] = useState(false);
35
+ useEffect(() => {
36
+ const onKeyDown = (e) => {
37
+ if (e.key === "\\") {
38
+ setDebugOpen(prev => !prev);
39
+ }
40
+ };
41
+ window.addEventListener("keydown", onKeyDown);
42
+ return () => window.removeEventListener("keydown", onKeyDown);
43
+ }, []);
44
+ useEffect(() => {
45
+ if (!isStandalone) {
46
+ return;
47
+ }
48
+ console.warn(`[notion-custom-sdk] ${init.error?.message}`);
49
+ seedStandalonePreviewState();
50
+ }, [isStandalone, init.error]);
51
+ if (debugOpen) {
52
+ return _jsx(DebugMessageLog, {});
53
+ }
54
+ if (init.error && !isStandalone) {
55
+ if (errorFallback === undefined) {
56
+ return _jsx(DefaultInitErrorFallback, { error: init.error });
57
+ }
58
+ return (_jsx(_Fragment, { children: typeof errorFallback === "function"
59
+ ? errorFallback(init.error)
60
+ : errorFallback }));
61
+ }
62
+ if (isStandalone) {
63
+ // Wait for the effect to seed placeholder host state; otherwise hooks
64
+ // in `children` would throw.
65
+ if (host.status !== "initialized") {
66
+ return _jsx(_Fragment, { children: fallback });
67
+ }
68
+ return (_jsxs(_Fragment, { children: [_jsx("div", { role: "status", className: "ncblock-standalone-banner", children: "Notion host not detected \u2014 running in standalone preview. SDK hooks return placeholder values until embedded in Notion." }), children] }));
69
+ }
70
+ if (!init.isLoaded) {
71
+ return _jsx(_Fragment, { children: fallback });
72
+ }
73
+ return _jsx(_Fragment, { children: children });
74
+ }
75
+ // TODO(custom-blocks): Align the styling of this with the host-side error states.
76
+ function DefaultInitErrorFallback({ error }) {
77
+ useEffect(() => {
78
+ console.warn(`[notion-custom-sdk] Custom block init failed: ${error.message}`);
79
+ }, [error]);
80
+ return (_jsx("div", { role: "alert", className: "ncblock-default-init-error", children: _jsxs("div", { className: "ncblock-default-init-error__card", children: [_jsx("div", { className: "ncblock-default-init-error__eyebrow", children: "Custom block" }), _jsx("h2", { className: "ncblock-default-init-error__title", children: "Couldn't connect to Notion" }), _jsx("p", { className: "ncblock-default-init-error__body", children: "This custom block loaded, but the setup handshake didn't finish. Try again from Notion. If this keeps happening, check the browser console for SDK details." }), _jsxs("details", { className: "ncblock-default-init-error__details", children: [_jsx("summary", { children: "Developer details" }), _jsx("pre", { className: "ncblock-default-init-error__pre", children: error.message })] })] }) }));
81
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * React entrypoint for `@notionhq/custom-blocks/react`.
3
+ *
4
+ * Exposes only the React surface — components and hooks. Framework-neutral
5
+ * values and types (clients, manifest/data-source types, etc.) live on the
6
+ * `@notionhq/custom-blocks` entrypoint and are intentionally NOT re-exported
7
+ * here, so the two public surfaces stay disjoint.
8
+ */
9
+ export { NotionCustomBlock, type NotionCustomBlockProps, } from "./NotionCustomBlock.js";
10
+ export { useCustomBlockAutoResize } from "./useCustomBlockAutoResize.js";
11
+ export { type CustomBlockInitFailure, type UseCustomBlockInitResult, useCustomBlockInit, } from "./useCustomBlockInit.js";
12
+ export { useDataSource } from "./useDataSource.js";
13
+ export { useBlockId, useCurrentUser, useManifest, usePage, useParent, useTheme, } from "./useRuntimeState.js";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../Users/nsarkar/work/custom-blocks/sdk/src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,iBAAiB,EACjB,KAAK,sBAAsB,GAC3B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AACxE,OAAO,EACN,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,kBAAkB,GAClB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EACN,UAAU,EACV,cAAc,EACd,WAAW,EACX,OAAO,EACP,SAAS,EACT,QAAQ,GACR,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * React entrypoint for `@notionhq/custom-blocks/react`.
3
+ *
4
+ * Exposes only the React surface — components and hooks. Framework-neutral
5
+ * values and types (clients, manifest/data-source types, etc.) live on the
6
+ * `@notionhq/custom-blocks` entrypoint and are intentionally NOT re-exported
7
+ * here, so the two public surfaces stay disjoint.
8
+ */
9
+ export { NotionCustomBlock, } from "./NotionCustomBlock.js";
10
+ export { useCustomBlockAutoResize } from "./useCustomBlockAutoResize.js";
11
+ export { useCustomBlockInit, } from "./useCustomBlockInit.js";
12
+ export { useDataSource } from "./useDataSource.js";
13
+ export { useBlockId, useCurrentUser, useManifest, usePage, useParent, useTheme, } from "./useRuntimeState.js";
@@ -0,0 +1,2 @@
1
+ export declare function seedStandalonePreviewState(): void;
2
+ //# sourceMappingURL=standalonePreview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standalonePreview.d.ts","sourceRoot":"","sources":["../../../../../../../../Users/nsarkar/work/custom-blocks/sdk/src/react/standalonePreview.ts"],"names":[],"mappings":"AAOA,wBAAgB,0BAA0B,SAoBzC"}
@@ -0,0 +1,26 @@
1
+ import * as v from "valibot";
2
+ import { notionBlockIdSchema, notionPageIdSchema } from "../bridge/ids.js";
3
+ import { customBlockHost } from "../bridge/sandboxClient.js";
4
+ const previewBlockId = v.parse(notionBlockIdSchema, "");
5
+ const previewPageId = v.parse(notionPageIdSchema, "");
6
+ export function seedStandalonePreviewState() {
7
+ customBlockHost.setMockState({
8
+ type: "init",
9
+ status: "success",
10
+ theme: "light",
11
+ blockId: previewBlockId,
12
+ parent: { type: "page_id", page_id: previewPageId },
13
+ page: { id: previewPageId },
14
+ dataSources: { bindings: {} },
15
+ currentUser: {
16
+ object: "user",
17
+ id: "",
18
+ name: "Preview User",
19
+ avatar_url: null,
20
+ type: "person",
21
+ person: {
22
+ email: "preview@example.com",
23
+ },
24
+ },
25
+ });
26
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Measures the sandbox's `#root` element and posts `resize` messages so the host iframe
3
+ * matches the block's border-box height. Unchanged values are deduped.
4
+ *
5
+ * `<NotionCustomBlock>` calls this hook for you by default — only reach for it directly
6
+ * when you need to drive `enabled` yourself (e.g. behind a debug toggle). In that case,
7
+ * pass `autoResize={false}` to the provider to avoid running it twice. For full-bleed
8
+ * views that should fill their slot, pass `autoResize={false}` and skip the hook.
9
+ *
10
+ * @example
11
+ * <NotionCustomBlock autoResize={false}>
12
+ * <App />
13
+ * </NotionCustomBlock>
14
+ *
15
+ * function App() {
16
+ * const [enabled, setEnabled] = useState(true)
17
+ * useCustomBlockAutoResize({ enabled })
18
+ * return <div>…</div>
19
+ * }
20
+ */
21
+ export declare function useCustomBlockAutoResize(args?: {
22
+ /**
23
+ * Whether or not the hook is enabled. To disable this behavior, pass `false`. This is
24
+ * provided as an argument to allow for conditional disabling of the hook.
25
+ *
26
+ * @default true
27
+ */
28
+ enabled?: boolean;
29
+ }): void;
30
+ //# sourceMappingURL=useCustomBlockAutoResize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCustomBlockAutoResize.d.ts","sourceRoot":"","sources":["../../../../../../../../Users/nsarkar/work/custom-blocks/sdk/src/react/useCustomBlockAutoResize.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,wBAAwB,CACvC,IAAI,GAAE;IACL;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CACZ,GACJ,IAAI,CAYN"}
@@ -0,0 +1,35 @@
1
+ import { useEffect } from "react";
2
+ import { customBlock } from "../index.js";
3
+ /**
4
+ * Measures the sandbox's `#root` element and posts `resize` messages so the host iframe
5
+ * matches the block's border-box height. Unchanged values are deduped.
6
+ *
7
+ * `<NotionCustomBlock>` calls this hook for you by default — only reach for it directly
8
+ * when you need to drive `enabled` yourself (e.g. behind a debug toggle). In that case,
9
+ * pass `autoResize={false}` to the provider to avoid running it twice. For full-bleed
10
+ * views that should fill their slot, pass `autoResize={false}` and skip the hook.
11
+ *
12
+ * @example
13
+ * <NotionCustomBlock autoResize={false}>
14
+ * <App />
15
+ * </NotionCustomBlock>
16
+ *
17
+ * function App() {
18
+ * const [enabled, setEnabled] = useState(true)
19
+ * useCustomBlockAutoResize({ enabled })
20
+ * return <div>…</div>
21
+ * }
22
+ */
23
+ export function useCustomBlockAutoResize(args = {}) {
24
+ const { enabled = true } = args;
25
+ useEffect(() => {
26
+ if (!enabled) {
27
+ return;
28
+ }
29
+ if (typeof window === "undefined") {
30
+ return;
31
+ }
32
+ const target = document.getElementById("root");
33
+ return customBlock.autoResize({ target });
34
+ }, [enabled]);
35
+ }
@@ -0,0 +1,43 @@
1
+ import { CustomBlockInitError } from "../bridge/messages/init.js";
2
+ import { type CustomBlockInitial, type InitCustomBlockOptions, NotInIframeError } from "../init.js";
3
+ export type CustomBlockInitFailure = CustomBlockInitError | NotInIframeError;
4
+ /**
5
+ * Discriminated state returned by {@link useCustomBlockInit}.
6
+ *
7
+ * Branch on `isLoaded`/`error`:
8
+ * - `{ isLoaded: false, error: undefined }` — handshake in progress.
9
+ * - `{ isLoaded: false, error: CustomBlockInitFailure }` — handshake failed (most commonly a
10
+ * `CustomBlockInitError` with code `init_timeout` because the host never sent `init`).
11
+ * - `{ isLoaded: true, initial }` — handshake complete; safe to render
12
+ * children that call `useTheme`, `useBlockId`, etc.
13
+ */
14
+ export type UseCustomBlockInitResult = {
15
+ isLoaded: false;
16
+ error: undefined;
17
+ } | {
18
+ isLoaded: false;
19
+ error: CustomBlockInitFailure;
20
+ } | {
21
+ isLoaded: true;
22
+ error: undefined;
23
+ initial: CustomBlockInitial;
24
+ };
25
+ /**
26
+ * React wrapper around {@link initCustomBlock}. Kicks off the SDK ↔ host
27
+ * handshake on mount and returns a discriminated state object so the rest of
28
+ * the tree can render inside the `isLoaded === true` branch (where every
29
+ * other SDK hook is guaranteed to return a populated value).
30
+ *
31
+ * Idempotent — multiple components can call this; they share the same
32
+ * underlying handshake promise.
33
+ *
34
+ * @example
35
+ * function Root() {
36
+ * const init = useCustomBlockInit()
37
+ * if (init.error) return <p role="alert">Init failed: {init.error.message}</p>
38
+ * if (!init.isLoaded) return null
39
+ * return <App />
40
+ * }
41
+ */
42
+ export declare function useCustomBlockInit(opts?: InitCustomBlockOptions): UseCustomBlockInitResult;
43
+ //# sourceMappingURL=useCustomBlockInit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCustomBlockInit.d.ts","sourceRoot":"","sources":["../../../../../../../../Users/nsarkar/work/custom-blocks/sdk/src/react/useCustomBlockInit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,EACN,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAE3B,gBAAgB,EAChB,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,sBAAsB,GAAG,oBAAoB,GAAG,gBAAgB,CAAA;AAE5E;;;;;;;;;GASG;AACH,MAAM,MAAM,wBAAwB,GACjC;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GACrC;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,sBAAsB,CAAA;CAAE,GAClD;IAAE,QAAQ,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,kBAAkB,CAAA;CAAE,CAAA;AAEpE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CACjC,IAAI,CAAC,EAAE,sBAAsB,GAC3B,wBAAwB,CA8B1B"}
@@ -0,0 +1,60 @@
1
+ import { useEffect, useState } from "react";
2
+ import { CustomBlockInitError } from "../bridge/messages/init.js";
3
+ import { initCustomBlock, NotInIframeError, } from "../init.js";
4
+ /**
5
+ * React wrapper around {@link initCustomBlock}. Kicks off the SDK ↔ host
6
+ * handshake on mount and returns a discriminated state object so the rest of
7
+ * the tree can render inside the `isLoaded === true` branch (where every
8
+ * other SDK hook is guaranteed to return a populated value).
9
+ *
10
+ * Idempotent — multiple components can call this; they share the same
11
+ * underlying handshake promise.
12
+ *
13
+ * @example
14
+ * function Root() {
15
+ * const init = useCustomBlockInit()
16
+ * if (init.error) return <p role="alert">Init failed: {init.error.message}</p>
17
+ * if (!init.isLoaded) return null
18
+ * return <App />
19
+ * }
20
+ */
21
+ export function useCustomBlockInit(opts) {
22
+ const [state, setState] = useState({
23
+ isLoaded: false,
24
+ error: undefined,
25
+ });
26
+ useEffect(() => {
27
+ let cancelled = false;
28
+ initCustomBlock(opts).then(initial => {
29
+ if (!cancelled) {
30
+ setState({ isLoaded: true, error: undefined, initial });
31
+ }
32
+ }, err => {
33
+ if (!cancelled) {
34
+ setState({
35
+ isLoaded: false,
36
+ error: normalizeInitError(err),
37
+ });
38
+ }
39
+ });
40
+ return () => {
41
+ cancelled = true;
42
+ };
43
+ // `initCustomBlock` caches its result, so options after the first call
44
+ // are ignored — re-running on opts changes would be misleading.
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ }, []);
47
+ return state;
48
+ }
49
+ function normalizeInitError(error) {
50
+ if (error instanceof CustomBlockInitError ||
51
+ error instanceof NotInIframeError) {
52
+ return error;
53
+ }
54
+ const message = error instanceof Error ? error.message : String(error);
55
+ return new CustomBlockInitError({
56
+ code: "unknown_error",
57
+ message,
58
+ isRetryable: false,
59
+ });
60
+ }
@@ -0,0 +1,13 @@
1
+ import type { UseDataSourceOptions, UseDataSourceResult } from "../types.js";
2
+ /**
3
+ * Reads from the data source mapped to the given semantic `key`.
4
+ *
5
+ * @param key - The semantic data-source key the block is wired to (e.g. `"people"`).
6
+ * @param options - Optional live snapshot options. `limit` defaults to 20 and
7
+ * is capped at 999.
8
+ *
9
+ * @example
10
+ * const { items, isLoading, hasMore, error } = useDataSource("default", { limit: 25 })
11
+ */
12
+ export declare function useDataSource(key: string, options?: UseDataSourceOptions): UseDataSourceResult;
13
+ //# sourceMappingURL=useDataSource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDataSource.d.ts","sourceRoot":"","sources":["../../../../../../../../Users/nsarkar/work/custom-blocks/sdk/src/react/useDataSource.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAG5E;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC5B,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,oBAAoB,GAC5B,mBAAmB,CA4BrB"}
@@ -0,0 +1,37 @@
1
+ import { useEffect } from "react";
2
+ import { customBlockDataSources } from "../bridge/sandboxClient.js";
3
+ import { useCustomBlockHost } from "./useHostState.js";
4
+ /**
5
+ * Reads from the data source mapped to the given semantic `key`.
6
+ *
7
+ * @param key - The semantic data-source key the block is wired to (e.g. `"people"`).
8
+ * @param options - Optional live snapshot options. `limit` defaults to 20 and
9
+ * is capped at 999.
10
+ *
11
+ * @example
12
+ * const { items, isLoading, hasMore, error } = useDataSource("default", { limit: 25 })
13
+ */
14
+ export function useDataSource(key, options) {
15
+ const host = useCustomBlockHost();
16
+ const limit = options?.limit;
17
+ const matchingDataSource = host.status === "initialized"
18
+ ? host.dataSources.find(dataSource => dataSource.key === key)
19
+ : undefined;
20
+ const isInitialized = host.status === "initialized";
21
+ useEffect(() => {
22
+ if (!isInitialized) {
23
+ return;
24
+ }
25
+ customBlockDataSources.query(key, { limit });
26
+ }, [matchingDataSource, isInitialized, key, limit]);
27
+ const view = customBlockDataSources.getView(host, key);
28
+ return {
29
+ items: view.items,
30
+ collectionSchema: view.collectionSchema,
31
+ propertySchemasById: view.propertySchemasById,
32
+ propertySchemasByKey: view.propertySchemasByKey,
33
+ isLoading: view.isLoading,
34
+ hasMore: view.hasMore,
35
+ error: view.error,
36
+ };
37
+ }
@@ -0,0 +1,2 @@
1
+ export declare function useCustomBlockHost(): import("../bridge/hostState.js").CustomBlockHostState;
2
+ //# sourceMappingURL=useHostState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHostState.d.ts","sourceRoot":"","sources":["../../../../../../../../Users/nsarkar/work/custom-blocks/sdk/src/react/useHostState.ts"],"names":[],"mappings":"AAGA,wBAAgB,kBAAkB,0DAKjC"}
@@ -0,0 +1,5 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import { customBlockHost } from "../bridge/sandboxClient.js";
3
+ export function useCustomBlockHost() {
4
+ return useSyncExternalStore(customBlockHost.subscribe, customBlockHost.getState);
5
+ }
@@ -0,0 +1,66 @@
1
+ import type { NotionBlockId } from "../bridge/ids.js";
2
+ import type { CustomBlockManifest } from "../bridge/manifest.js";
3
+ import type { CustomBlockPage } from "../bridge/pages/page.js";
4
+ import type { NotionParent } from "../bridge/parent.js";
5
+ import type { NotionTheme } from "../bridge/theme.js";
6
+ import type { NotionUser } from "../bridge/users/user.js";
7
+ /**
8
+ * Returns this custom block's ID. This is stable throughout the block's lifetime.
9
+ *
10
+ * Throws if called before `initCustomBlock` has resolved.
11
+ *
12
+ * @example
13
+ * const blockId = useBlockId()
14
+ */
15
+ export declare function useBlockId(): NotionBlockId;
16
+ /**
17
+ * Returns the block's parent in the document tree. Re-renders when the host sends
18
+ * a parent location update (e.g. the block moves into a different container).
19
+ *
20
+ * Throws if called before `initCustomBlock` has resolved.
21
+ *
22
+ * @example
23
+ * const parent = useParent()
24
+ */
25
+ export declare function useParent(): NotionParent;
26
+ /**
27
+ * Returns the nearest enclosing page ancestor. Re-renders when the host sends
28
+ * a page location update.
29
+ *
30
+ * Throws if called before `initCustomBlock` has resolved.
31
+ *
32
+ * @example
33
+ * const page = usePage()
34
+ */
35
+ export declare function usePage(): CustomBlockPage;
36
+ /**
37
+ * Returns the host's current theme. Re-renders on every `themeChanged` message from the host.
38
+ *
39
+ * Throws if called before `initCustomBlock` has resolved.
40
+ *
41
+ * @example
42
+ * const theme = useTheme()
43
+ */
44
+ export declare function useTheme(): NotionTheme;
45
+ /**
46
+ * Returns the viewing user's Notion profile. Re-renders whenever the host sends a
47
+ * `currentUserChanged` message.
48
+ *
49
+ * Throws if called before `initCustomBlock` has resolved. `await` it before mounting.
50
+ *
51
+ * @example
52
+ * const me = useCurrentUser()
53
+ * console.log(me.id, me.name, me.person.email)
54
+ */
55
+ export declare function useCurrentUser(): NotionUser;
56
+ /**
57
+ * Returns the author-declared manifest loaded from `custom_blocks.json` — the semantic
58
+ * data-source keys plus their declared `name`, `description`, and property declarations.
59
+ * `null` when the block ships no manifest.
60
+ *
61
+ * This is the configuration the block declared, not host-resolved bindings: use
62
+ * `useDataSource(key)` for rows and resolved schema. Handy for enumerating the declared
63
+ * data-source keys (e.g. picking a default key, or rendering a key switcher).
64
+ */
65
+ export declare function useManifest(): CustomBlockManifest | null;
66
+ //# sourceMappingURL=useRuntimeState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRuntimeState.d.ts","sourceRoot":"","sources":["../../../../../../../../Users/nsarkar/work/custom-blocks/sdk/src/react/useRuntimeState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAGzD;;;;;;;GAOG;AACH,wBAAgB,UAAU,IAAI,aAAa,CAE1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,IAAI,YAAY,CAExC;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,IAAI,eAAe,CAEzC;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,IAAI,WAAW,CAEtC;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,IAAI,UAAU,CAE3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,IAAI,mBAAmB,GAAG,IAAI,CAExD"}
@@ -0,0 +1,73 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import { customBlock } from "../customBlock.js";
3
+ /**
4
+ * Returns this custom block's ID. This is stable throughout the block's lifetime.
5
+ *
6
+ * Throws if called before `initCustomBlock` has resolved.
7
+ *
8
+ * @example
9
+ * const blockId = useBlockId()
10
+ */
11
+ export function useBlockId() {
12
+ return useSyncExternalStore(customBlock.subscribe, customBlock.getBlockId);
13
+ }
14
+ /**
15
+ * Returns the block's parent in the document tree. Re-renders when the host sends
16
+ * a parent location update (e.g. the block moves into a different container).
17
+ *
18
+ * Throws if called before `initCustomBlock` has resolved.
19
+ *
20
+ * @example
21
+ * const parent = useParent()
22
+ */
23
+ export function useParent() {
24
+ return useSyncExternalStore(customBlock.subscribe, customBlock.getParent);
25
+ }
26
+ /**
27
+ * Returns the nearest enclosing page ancestor. Re-renders when the host sends
28
+ * a page location update.
29
+ *
30
+ * Throws if called before `initCustomBlock` has resolved.
31
+ *
32
+ * @example
33
+ * const page = usePage()
34
+ */
35
+ export function usePage() {
36
+ return useSyncExternalStore(customBlock.subscribe, customBlock.getPage);
37
+ }
38
+ /**
39
+ * Returns the host's current theme. Re-renders on every `themeChanged` message from the host.
40
+ *
41
+ * Throws if called before `initCustomBlock` has resolved.
42
+ *
43
+ * @example
44
+ * const theme = useTheme()
45
+ */
46
+ export function useTheme() {
47
+ return useSyncExternalStore(customBlock.subscribe, customBlock.getTheme);
48
+ }
49
+ /**
50
+ * Returns the viewing user's Notion profile. Re-renders whenever the host sends a
51
+ * `currentUserChanged` message.
52
+ *
53
+ * Throws if called before `initCustomBlock` has resolved. `await` it before mounting.
54
+ *
55
+ * @example
56
+ * const me = useCurrentUser()
57
+ * console.log(me.id, me.name, me.person.email)
58
+ */
59
+ export function useCurrentUser() {
60
+ return useSyncExternalStore(customBlock.subscribe, customBlock.getCurrentUser);
61
+ }
62
+ /**
63
+ * Returns the author-declared manifest loaded from `custom_blocks.json` — the semantic
64
+ * data-source keys plus their declared `name`, `description`, and property declarations.
65
+ * `null` when the block ships no manifest.
66
+ *
67
+ * This is the configuration the block declared, not host-resolved bindings: use
68
+ * `useDataSource(key)` for rows and resolved schema. Handy for enumerating the declared
69
+ * data-source keys (e.g. picking a default key, or rendering a key switcher).
70
+ */
71
+ export function useManifest() {
72
+ return useSyncExternalStore(customBlock.subscribe, customBlock.getManifest);
73
+ }