@notionhq/custom-blocks 0.1.48 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +2 -3
  2. package/dist/bridge/SandboxBridge.d.ts.map +1 -1
  3. package/dist/bridge/SandboxBridge.js +2 -4
  4. package/dist/bridge/sandboxClient.d.ts +0 -5
  5. package/dist/bridge/sandboxClient.d.ts.map +1 -1
  6. package/dist/bridge/sandboxClient.js +0 -12
  7. package/dist/customBlock.d.ts +0 -22
  8. package/dist/customBlock.d.ts.map +1 -1
  9. package/dist/customBlock.js +0 -37
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/protocol/dataSources/dataSourcePage.d.ts +2 -2
  13. package/dist/protocol/dataSources/dataSourcePage.js +2 -3
  14. package/dist/protocol/messages/createPageResult.d.ts +2 -2
  15. package/dist/protocol/messages/getPage.d.ts +2 -2
  16. package/dist/protocol/messages/hostToSandbox.d.ts +9 -9
  17. package/dist/protocol/messages/init.d.ts +1 -1
  18. package/dist/protocol/messages/init.js +2 -3
  19. package/dist/protocol/messages/queryDataSourceResult.d.ts +2 -2
  20. package/dist/protocol/messages/updatePageResult.d.ts +2 -2
  21. package/dist/protocol/pages/page.d.ts +2 -2
  22. package/dist/protocol/pages/page.js +2 -3
  23. package/dist/protocol/protocolVersion.d.ts +1 -1
  24. package/dist/protocol/protocolVersion.js +1 -1
  25. package/dist/react/NotionCustomBlock.d.ts +1 -9
  26. package/dist/react/NotionCustomBlock.d.ts.map +1 -1
  27. package/dist/react/NotionCustomBlock.js +9 -3
  28. package/dist/react/index.d.ts +0 -1
  29. package/dist/react/index.d.ts.map +1 -1
  30. package/dist/react/index.js +0 -1
  31. package/dist/types.d.ts +4 -38
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/version.js +1 -1
  34. package/docs/data-sources.md +100 -52
  35. package/docs/lifecycle.md +1 -14
  36. package/docs/pages.md +55 -0
  37. package/docs/users.md +97 -26
  38. package/package.json +1 -6
  39. package/src/bridge/SandboxBridge.ts +2 -4
  40. package/src/bridge/sandboxClient.ts +0 -15
  41. package/src/customBlock.ts +1 -65
  42. package/src/index.ts +1 -1
  43. package/src/react/NotionCustomBlock.tsx +9 -11
  44. package/src/react/index.ts +0 -1
  45. package/src/types.ts +4 -46
  46. package/dist/react/useCustomBlockAutoResize.d.ts +0 -26
  47. package/dist/react/useCustomBlockAutoResize.d.ts.map +0 -1
  48. package/dist/react/useCustomBlockAutoResize.js +0 -31
  49. package/src/react/useCustomBlockAutoResize.ts +0 -42
  50. package/vite-plugin/index.d.ts +0 -12
  51. package/vite-plugin/index.js +0 -11
@@ -1,38 +1,15 @@
1
1
  import type { NotionContrastMode } from "@notionhq/custom-blocks-protocol/contrast.js"
2
- import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/dataSource.js"
3
2
  import type { NotionBlockId } from "@notionhq/custom-blocks-protocol/ids.js"
4
3
  import type { CustomBlockManifest } from "@notionhq/custom-blocks-protocol/manifest.js"
5
4
  import type { CustomBlockPage } from "@notionhq/custom-blocks-protocol/pages/page.js"
6
5
  import type { NotionParent } from "@notionhq/custom-blocks-protocol/parent.js"
7
6
  import type { NotionTheme } from "@notionhq/custom-blocks-protocol/theme.js"
8
7
  import type { NotionUser } from "@notionhq/custom-blocks-protocol/users/user.js"
9
- import { autoResize } from "./autoResize.js"
10
8
  import { subscribeToDataSource } from "./bridge/dataSources/subscribe.js"
11
- import type {
12
- CustomBlockHostState,
13
- InitializedHostState,
14
- } from "./bridge/hostState.js"
9
+ import type { InitializedHostState } from "./bridge/hostState.js"
15
10
  import { notifyListener } from "./bridge/notifyListener.js"
16
11
  import { customBlockHost } from "./bridge/sandboxClient.js"
17
12
 
18
- /** @deprecated Use individual context types and getters after `initCustomBlock` resolves. */
19
- export type CustomBlockState =
20
- | {
21
- status: "uninitialized"
22
- theme: NotionTheme
23
- contrastMode: NotionContrastMode
24
- }
25
- | {
26
- status: "initialized"
27
- theme: NotionTheme
28
- contrastMode: NotionContrastMode
29
- blockId: NotionBlockId
30
- parent: NotionParent
31
- page: CustomBlockPage
32
- currentUser: NotionUser
33
- dataSources: NotionDataSource[]
34
- }
35
-
36
13
  type Unsubscribe = () => void
37
14
 
38
15
  /**
@@ -45,16 +22,6 @@ type Unsubscribe = () => void
45
22
  * subscription is no longer needed.
46
23
  */
47
24
  export const customBlock = {
48
- /** @deprecated Use an individual subscription method, such as `subscribeToTheme()` or `subscribeToCurrentUser()`. */
49
- subscribe(listener: () => void): Unsubscribe {
50
- return customBlockHost.subscribe(listener)
51
- },
52
-
53
- /** @deprecated Use an individual getter method, such as `getTheme()` or `getCurrentUser()`, after `initCustomBlock()` resolves. */
54
- getState(): CustomBlockState {
55
- return toPublicState(customBlockHost.getState())
56
- },
57
-
58
25
  /**
59
26
  * Get the current user viewing the block.
60
27
  * Throws if called before SDK initialization completes.
@@ -171,8 +138,6 @@ export const customBlock = {
171
138
  return subscribeToContext({ key: "manifest", listener })
172
139
  },
173
140
 
174
- autoResize,
175
-
176
141
  /**
177
142
  * Registers a listener that receives the current query snapshot and later updates.
178
143
  * Returns a function that removes this listener. Other listeners remain subscribed.
@@ -180,35 +145,6 @@ export const customBlock = {
180
145
  subscribeToDataSource,
181
146
  }
182
147
 
183
- let lastHostState: CustomBlockHostState | undefined
184
- let lastPublicState: CustomBlockState | undefined
185
-
186
- function toPublicState(hostState: CustomBlockHostState): CustomBlockState {
187
- if (hostState === lastHostState && lastPublicState !== undefined) {
188
- return lastPublicState
189
- }
190
- lastHostState = hostState
191
- if (hostState.status === "uninitialized") {
192
- lastPublicState = {
193
- status: "uninitialized",
194
- theme: hostState.theme,
195
- contrastMode: hostState.contrastMode,
196
- }
197
- return lastPublicState
198
- }
199
- lastPublicState = {
200
- status: "initialized",
201
- theme: hostState.theme,
202
- contrastMode: hostState.contrastMode,
203
- blockId: hostState.blockId,
204
- parent: hostState.parent,
205
- page: hostState.page,
206
- currentUser: hostState.currentUser,
207
- dataSources: hostState.dataSources,
208
- }
209
- return lastPublicState
210
- }
211
-
212
148
  function getInitializedHostState(methodName: string): InitializedHostState {
213
149
  const hostState = customBlockHost.getState()
214
150
  if (hostState.status !== "initialized") {
package/src/index.ts CHANGED
@@ -98,7 +98,7 @@ export type {
98
98
  export type { NotionParent } from "@notionhq/custom-blocks-protocol/parent.js"
99
99
  export type { NotionTheme } from "@notionhq/custom-blocks-protocol/theme.js"
100
100
  export { pages, users } from "./bridge/sandboxClient.js"
101
- export { type CustomBlockState, customBlock } from "./customBlock.js"
101
+ export { customBlock } from "./customBlock.js"
102
102
  export {
103
103
  type CustomBlockInitPayload,
104
104
  initCustomBlock,
@@ -1,10 +1,10 @@
1
1
  import type { CustomBlockInitializationError } from "@notionhq/custom-blocks-protocol/messages/init.js"
2
2
  import { type ReactNode, useEffect, useLayoutEffect, useState } from "react"
3
+ import { autoResize } from "../autoResize.js"
3
4
  import { customBlockHost } from "../bridge/sandboxClient.js"
4
5
  import { NotInIframeError } from "../init.js"
5
6
  import { DebugMessageLog } from "./DebugMessageLog.js"
6
7
  import { seedStandalonePreviewState } from "./standalonePreview.js"
7
- import { useCustomBlockAutoResize } from "./useCustomBlockAutoResize.js"
8
8
  import { useCustomBlockInit } from "./useCustomBlockInit.js"
9
9
  import { useCustomBlockHost } from "./useHostState.js"
10
10
  import "./NotionCustomBlock.css"
@@ -25,14 +25,6 @@ export type NotionCustomBlockProps = {
25
25
  * rendered with developer details — replace it for production templates.
26
26
  */
27
27
  errorFallback?: ReactNode | ((error: Error) => ReactNode)
28
- /**
29
- * Whether to post resize messages after initialization and dynamically resize the block.
30
- *
31
- * @deprecated TODO(custom-blocks): Remove this prop when bumping the SDK version to 0.2.0.
32
- *
33
- * @default true
34
- */
35
- autoResize?: boolean
36
28
  }
37
29
 
38
30
  /**
@@ -57,15 +49,21 @@ export function NotionCustomBlock({
57
49
  children,
58
50
  fallback = null,
59
51
  errorFallback,
60
- autoResize = true,
61
52
  }: NotionCustomBlockProps) {
62
53
  const init = useCustomBlockInit()
63
- useCustomBlockAutoResize({ enabled: init.isLoaded && autoResize })
64
54
  // True if the block has no host (i.e. it's running in standalone preview).
65
55
  const isStandalone = init.error instanceof NotInIframeError
66
56
  const host = useCustomBlockHost()
67
57
  const [debugOpen, setDebugOpen] = useState(false)
68
58
 
59
+ // Keep the host iframe height in sync with the block's content after initialization.
60
+ useEffect(() => {
61
+ if (!init.isLoaded || typeof window === "undefined") {
62
+ return
63
+ }
64
+ return autoResize({ target: document.getElementById("root") })
65
+ }, [init.isLoaded])
66
+
69
67
  useEffect(() => {
70
68
  const onKeyDown = (e: KeyboardEvent) => {
71
69
  if (e.key === "\\") {
@@ -15,7 +15,6 @@ export {
15
15
  NotionTokenScope,
16
16
  type NotionTokenScopeProps,
17
17
  } from "./NotionTokenScope.js"
18
- export { useCustomBlockAutoResize } from "./useCustomBlockAutoResize.js"
19
18
  export {
20
19
  type UseCustomBlockInitResult,
21
20
  useCustomBlockInit,
package/src/types.ts CHANGED
@@ -85,11 +85,10 @@ export type NotionPagePropertyInputMap = {
85
85
  */
86
86
  export type NotionDataSourcePage = {
87
87
  id: NotionPageId
88
- // TODO(custom-blocks): Require is_archived and in_trash in bridge protocol v4.
89
88
  /** Whether the page or an ancestor is archived. */
90
- is_archived?: boolean
89
+ is_archived: boolean
91
90
  /** Whether the page or an ancestor is in Trash. */
92
- in_trash?: boolean
91
+ in_trash: boolean
93
92
  /**
94
93
  * Keyed mapping of raw property IDs to their value. Includes all properties on the data source,
95
94
  * including the four built-ins (`created_time`, `last_edited_time`, `created_by`,
@@ -116,27 +115,10 @@ export type NotionDataSourcePageUpdateArgs = {
116
115
  properties?: NotionPagePropertyInputMap
117
116
  icon?: NotionPageIcon
118
117
  cover?: NotionPageCover
119
- /** Whether to archive this page. Takes precedence over archived. */
118
+ /** Whether to archive this page. */
120
119
  is_archived?: boolean
121
- /** @deprecated Use is_archived instead. */
122
- // TODO(custom-blocks): Remove archived when upgrading to bridge protocol v4.
123
- archived?: boolean
124
120
  }
125
121
 
126
- /**
127
- * @deprecated Use `NotionDataSourcePageUpdateArgs` instead.
128
- *
129
- * TODO(custom-blocks): Remove this alias when bumping the SDK version to 0.2.0.
130
- */
131
- export type NotionDataSourcePageUpdateInput = NotionDataSourcePageUpdateArgs
132
-
133
- /**
134
- * @deprecated Use `UpdatePageResult` instead.
135
- *
136
- * TODO(custom-blocks): Remove this alias when bumping the SDK version to 0.2.0.
137
- */
138
- export type NotionDataSourcePageUpdateResult = UpdatePageResult
139
-
140
122
  export type NotionDataSourceTextFilterOperator = CustomBlockTextFilterOperator
141
123
  export type NotionDataSourceNumberFilterOperator =
142
124
  CustomBlockNumberFilterOperator
@@ -256,13 +238,6 @@ export type CreatePageArgs = {
256
238
  position?: NotionCreatePagePosition
257
239
  }
258
240
 
259
- /**
260
- * @deprecated Use `CreatePageArgs` instead.
261
- *
262
- * TODO(custom-blocks): Remove this alias when bumping the SDK version to 0.2.0.
263
- */
264
- export type CreatePageInput = CreatePageArgs
265
-
266
241
  /**
267
242
  * The result of a `sdk.pages.create` API call.
268
243
  */
@@ -275,20 +250,10 @@ export type UpdatePageArgs = Omit<
275
250
  UpdatePageMessage,
276
251
  "type" | "requestId" | "archived"
277
252
  > & {
278
- /** Whether to archive this page. Takes precedence over archived. */
253
+ /** Whether to archive this page. */
279
254
  is_archived?: boolean
280
- /** @deprecated Use is_archived instead. */
281
- // TODO(custom-blocks): Remove archived when upgrading to bridge protocol v4.
282
- archived?: boolean
283
255
  }
284
256
 
285
- /**
286
- * @deprecated Use `UpdatePageArgs` instead.
287
- *
288
- * TODO(custom-blocks): Remove this alias when bumping the SDK version to 0.2.0.
289
- */
290
- export type UpdatePageInput = UpdatePageArgs
291
-
292
257
  /**
293
258
  * Result of `sdk.pages.get`.
294
259
  */
@@ -307,13 +272,6 @@ export type UpdatePageResult = BridgeMessagePayload<
307
272
 
308
273
  export type ListUsersArgs = Omit<ListUsersMessage, "type" | "requestId">
309
274
 
310
- /**
311
- * @deprecated Use `ListUsersArgs` instead.
312
- *
313
- * TODO(custom-blocks): Remove this alias when bumping the SDK version to 0.2.0.
314
- */
315
- export type ListUsersInput = ListUsersArgs
316
-
317
275
  export type ListUsersResult = BridgeMessagePayload<
318
276
  ListUsersResultMessage,
319
277
  CustomBlockListUsersErrorInfo
@@ -1,26 +0,0 @@
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. Only use it directly in a custom
6
- * initialization wrapper that does not render `<NotionCustomBlock>`.
7
- *
8
- * @deprecated Use CSS `max-height` and `overflow` to constrain block content instead.
9
- *
10
- * @example
11
- * function App() {
12
- * const [enabled, setEnabled] = useState(true)
13
- * useCustomBlockAutoResize({ enabled })
14
- * return <div>…</div>
15
- * }
16
- */
17
- export declare function useCustomBlockAutoResize(args?: {
18
- /**
19
- * Whether or not the hook is enabled. To disable this behavior, pass `false`. This is
20
- * provided as an argument to allow for conditional disabling of the hook.
21
- *
22
- * @default true
23
- */
24
- enabled?: boolean;
25
- }): void;
26
- //# sourceMappingURL=useCustomBlockAutoResize.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useCustomBlockAutoResize.d.ts","sourceRoot":"","sources":["../../src/react/useCustomBlockAutoResize.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACvC,IAAI,GAAE;IACL;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CACZ,GACJ,IAAI,CAYN"}
@@ -1,31 +0,0 @@
1
- import { useEffect } from "react";
2
- import { customBlock } from "../customBlock.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. Only use it directly in a custom
8
- * initialization wrapper that does not render `<NotionCustomBlock>`.
9
- *
10
- * @deprecated Use CSS `max-height` and `overflow` to constrain block content instead.
11
- *
12
- * @example
13
- * function App() {
14
- * const [enabled, setEnabled] = useState(true)
15
- * useCustomBlockAutoResize({ enabled })
16
- * return <div>…</div>
17
- * }
18
- */
19
- export function useCustomBlockAutoResize(args = {}) {
20
- const { enabled = true } = args;
21
- useEffect(() => {
22
- if (!enabled) {
23
- return;
24
- }
25
- if (typeof window === "undefined") {
26
- return;
27
- }
28
- const target = document.getElementById("root");
29
- return customBlock.autoResize({ target });
30
- }, [enabled]);
31
- }
@@ -1,42 +0,0 @@
1
- import { useEffect } from "react"
2
- import { customBlock } from "../customBlock.js"
3
-
4
- /**
5
- * Measures the sandbox's `#root` element and posts `resize` messages so the host iframe
6
- * matches the block's border-box height. Unchanged values are deduped.
7
- *
8
- * `<NotionCustomBlock>` calls this hook for you. Only use it directly in a custom
9
- * initialization wrapper that does not render `<NotionCustomBlock>`.
10
- *
11
- * @deprecated Use CSS `max-height` and `overflow` to constrain block content instead.
12
- *
13
- * @example
14
- * function App() {
15
- * const [enabled, setEnabled] = useState(true)
16
- * useCustomBlockAutoResize({ enabled })
17
- * return <div>…</div>
18
- * }
19
- */
20
- export function useCustomBlockAutoResize(
21
- 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
- } = {},
30
- ): void {
31
- const { enabled = true } = args
32
- useEffect(() => {
33
- if (!enabled) {
34
- return
35
- }
36
- if (typeof window === "undefined") {
37
- return
38
- }
39
- const target = document.getElementById("root")
40
- return customBlock.autoResize({ target })
41
- }, [enabled])
42
- }
@@ -1,12 +0,0 @@
1
- export type NotionCustomBlockPlugin = {
2
- name: string
3
- }
4
-
5
- /**
6
- * Vite plugin for Notion custom blocks.
7
- *
8
- * @deprecated This compatibility stub does nothing. Remove it from Vite config when possible.
9
- *
10
- * TODO(custom-blocks): Remove this when bumping bridge SDK version to 0.2.0.
11
- */
12
- export function notionCustomBlock(): NotionCustomBlockPlugin
@@ -1,11 +0,0 @@
1
- /**
2
- * Vite plugin for Notion custom blocks.
3
- *
4
- * @deprecated This is just a compatibility stub to ensure existing block code can continue to work
5
- * with the new SDK.
6
- *
7
- * TODO(custom-blocks): Remove this when bumping bridge SDK version to 0.2.0.
8
- */
9
- export function notionCustomBlock() {
10
- return { name: "custom-blocks:legacy-vite-plugin" }
11
- }