@notionhq/custom-blocks 0.6.0 → 0.7.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 (191) hide show
  1. package/README.md +32 -18
  2. package/dist/bridge/SandboxBridge.d.ts +7 -8
  3. package/dist/bridge/SandboxBridge.d.ts.map +1 -1
  4. package/dist/bridge/SandboxBridge.js +39 -114
  5. package/dist/bridge/applyHostStateMessage.d.ts.map +1 -1
  6. package/dist/bridge/createBrowserSandboxBridge.d.ts +3 -0
  7. package/dist/bridge/createBrowserSandboxBridge.d.ts.map +1 -0
  8. package/dist/bridge/createBrowserSandboxBridge.js +54 -0
  9. package/dist/bridge/getBridge.d.ts +1 -1
  10. package/dist/bridge/getBridge.d.ts.map +1 -1
  11. package/dist/bridge/getBridge.js +2 -2
  12. package/dist/bridge/getInitializedHostState.d.ts.map +1 -1
  13. package/dist/bridge/hostState.d.ts +2 -2
  14. package/dist/bridge/hostState.d.ts.map +1 -1
  15. package/dist/bridge/initialization/SandboxInitialization.d.ts +6 -0
  16. package/dist/bridge/initialization/SandboxInitialization.d.ts.map +1 -1
  17. package/dist/bridge/initialization/SandboxInitialization.js +13 -10
  18. package/dist/bridge/messageInterceptor.d.ts.map +1 -1
  19. package/dist/bridge/requests.d.ts.map +1 -1
  20. package/dist/bridge/sandboxEnvironment.d.ts +30 -0
  21. package/dist/bridge/sandboxEnvironment.d.ts.map +1 -0
  22. package/dist/bridge/sandboxEnvironment.js +1 -0
  23. package/dist/bridge/subscribeToHostStateField.d.ts.map +1 -1
  24. package/dist/bridge.d.ts.map +1 -1
  25. package/dist/data-sources.d.ts.map +1 -1
  26. package/dist/dataSources/NotionDataSource.d.ts.map +1 -1
  27. package/dist/dataSources/bridge/DataSourceCache.d.ts +18 -0
  28. package/dist/dataSources/bridge/DataSourceCache.d.ts.map +1 -0
  29. package/dist/dataSources/bridge/DataSourceCache.js +75 -0
  30. package/dist/dataSources/bridge/applyDataSourceBindings.d.ts.map +1 -1
  31. package/dist/dataSources/bridge/makeDataSourceReadResponseSchema.d.ts.map +1 -1
  32. package/dist/dataSources/bridge/resolveDataSourceQuery.d.ts.map +1 -1
  33. package/dist/dataSources/bridge/resolveDataSources.d.ts.map +1 -1
  34. package/dist/dataSources/bridge/resolveSorts.d.ts.map +1 -1
  35. package/dist/dataSources/bridge/reuseDataSourcesForUnchangedBindings.d.ts +0 -3
  36. package/dist/dataSources/bridge/reuseDataSourcesForUnchangedBindings.d.ts.map +1 -1
  37. package/dist/dataSources/bridge/reuseDataSourcesForUnchangedBindings.js +2 -5
  38. package/dist/dataSources/dataSourceInaccessibleError.d.ts.map +1 -1
  39. package/dist/dataSources/dataSourceState.d.ts.map +1 -1
  40. package/dist/dataSources/ensureDataSource.d.ts.map +1 -1
  41. package/dist/dataSources/filters/resolveFilter.d.ts.map +1 -1
  42. package/dist/dataSources/filters/types.d.ts.map +1 -1
  43. package/dist/dataSources/getDataSourcePage.d.ts.map +1 -1
  44. package/dist/dataSources/observeDataSource.d.ts.map +1 -1
  45. package/dist/dataSources/properties/resolvePropertyAddress.d.ts.map +1 -1
  46. package/dist/dataSources/properties/resolvePropertyWriteMapForDataSource.d.ts.map +1 -1
  47. package/dist/dataSources/properties/resolvePropertyWriteMapForDataSource.js +2 -2
  48. package/dist/dataSources/resolvePageDataSource.d.ts.map +1 -1
  49. package/dist/dataSources/subscribeToDataSource.d.ts.map +1 -1
  50. package/dist/dataSources/types.d.ts.map +1 -1
  51. package/dist/files/files.d.ts +1 -1
  52. package/dist/files/files.d.ts.map +1 -1
  53. package/dist/files/icons.d.ts.map +1 -1
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/initialization/NotInIframeError.d.ts.map +1 -1
  56. package/dist/initialization/initCustomBlock.d.ts.map +1 -1
  57. package/dist/initialization/notifyReady.d.ts.map +1 -1
  58. package/dist/initialization/react/useCustomBlockInit.d.ts.map +1 -1
  59. package/dist/initialization/resolveInitialState.d.ts.map +1 -1
  60. package/dist/initialization/types.d.ts.map +1 -1
  61. package/dist/layout/autoResize.d.ts.map +1 -1
  62. package/dist/layout/getInitialContentHeight.d.ts.map +1 -1
  63. package/dist/location/getContainingPage.d.ts.map +1 -1
  64. package/dist/location/getInstance.d.ts.map +1 -1
  65. package/dist/location/getParent.d.ts.map +1 -1
  66. package/dist/location/mapContainingPage.d.ts +2 -2
  67. package/dist/location/mapContainingPage.d.ts.map +1 -1
  68. package/dist/location/mapParent.d.ts.map +1 -1
  69. package/dist/location/subscribeToContainingPage.d.ts.map +1 -1
  70. package/dist/location/subscribeToParent.d.ts.map +1 -1
  71. package/dist/location/types.d.ts.map +1 -1
  72. package/dist/manifest/getManifest.d.ts.map +1 -1
  73. package/dist/manifest/readLocalManifest.d.ts.map +1 -1
  74. package/dist/manifest/types.d.ts.map +1 -1
  75. package/dist/navigation/openExternalUrl.d.ts.map +1 -1
  76. package/dist/navigation/types.d.ts.map +1 -1
  77. package/dist/navigation.d.ts.map +1 -1
  78. package/dist/pages/NotionPage.d.ts.map +1 -1
  79. package/dist/pages/bridge/buildCreatePageRequest.d.ts.map +1 -1
  80. package/dist/pages/bridge/getPageForDataSource.d.ts.map +1 -1
  81. package/dist/pages/bridge/resolveCreatePageDestination.d.ts.map +1 -1
  82. package/dist/pages/bridge/sendCreatePageRequest.d.ts.map +1 -1
  83. package/dist/pages/bridge/toNotionPageFromBridgePage.d.ts.map +1 -1
  84. package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts +2 -2
  85. package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts.map +1 -1
  86. package/dist/pages/bridge/updatePage.d.ts.map +1 -1
  87. package/dist/pages/createPage.d.ts.map +1 -1
  88. package/dist/pages/getPage.d.ts.map +1 -1
  89. package/dist/pages/identityBlockKey.d.ts.map +1 -1
  90. package/dist/pages/identityPageKey.d.ts.map +1 -1
  91. package/dist/pages/openPage.d.ts.map +1 -1
  92. package/dist/pages/parent.d.ts.map +1 -1
  93. package/dist/pages/types.d.ts +5 -3
  94. package/dist/pages/types.d.ts.map +1 -1
  95. package/dist/pages.d.ts.map +1 -1
  96. package/dist/preferences/backgroundColors.d.ts.map +1 -1
  97. package/dist/preferences/getContrastMode.d.ts.map +1 -1
  98. package/dist/preferences/getTheme.d.ts.map +1 -1
  99. package/dist/preferences/react/useContrastMode.d.ts.map +1 -1
  100. package/dist/preferences/react/useTheme.d.ts.map +1 -1
  101. package/dist/preferences/subscribeToContrastMode.d.ts.map +1 -1
  102. package/dist/preferences/subscribeToTheme.d.ts.map +1 -1
  103. package/dist/preferences/syncDocumentAppearance.d.ts +1 -1
  104. package/dist/preferences/syncDocumentAppearance.d.ts.map +1 -1
  105. package/dist/preferences/syncDocumentAppearance.js +2 -1
  106. package/dist/preferences.d.ts.map +1 -1
  107. package/dist/protocol/compatibility/protocol12/hostToSandbox.d.ts +3356 -0
  108. package/dist/protocol/compatibility/protocol12/hostToSandbox.js +38 -0
  109. package/dist/protocol/compatibility/protocol12/page.d.ts +296 -0
  110. package/dist/protocol/compatibility/protocol12/page.js +7 -0
  111. package/dist/protocol/context/containingPage.d.ts +4 -2
  112. package/dist/protocol/context/containingPage.js +1 -1
  113. package/dist/protocol/context/messages/pageChanged.js +2 -2
  114. package/dist/protocol/dataSources/areDataSourceBindingsEqual.d.ts +3 -0
  115. package/dist/protocol/dataSources/areDataSourceBindingsEqual.js +26 -0
  116. package/dist/protocol/dataSources/messages/queryDataSource.d.ts +24 -19
  117. package/dist/protocol/dataSources/messages/queryDataSource.js +2 -0
  118. package/dist/protocol/files.d.ts +18 -0
  119. package/dist/protocol/files.js +9 -0
  120. package/dist/protocol/messages/hostToSandbox.d.ts +2200 -68
  121. package/dist/protocol/messages/hostToSandbox.js +6 -2
  122. package/dist/protocol/messages/sandboxToHost.d.ts +51 -51
  123. package/dist/protocol/pages/bridgePage.d.ts +20 -17
  124. package/dist/protocol/pages/messages/createPage.d.ts +88 -85
  125. package/dist/protocol/pages/messages/getPage.d.ts +24 -19
  126. package/dist/protocol/pages/messages/getPage.js +2 -0
  127. package/dist/protocol/pages/messages/updatePage.d.ts +37 -34
  128. package/dist/protocol/pages/properties/bridgePagePropertyMaps.d.ts +37 -34
  129. package/dist/protocol/pages/properties/bridgePagePropertyMaps.js +3 -3
  130. package/dist/protocol/pages/properties/bridgePagePropertyValue.d.ts +236 -2
  131. package/dist/protocol/pages/properties/bridgePagePropertyValue.js +20 -7
  132. package/dist/protocol/utils/errors.d.ts +6 -0
  133. package/dist/protocol/utils/errors.js +8 -0
  134. package/dist/protocol/utils/protocolVersion.d.ts +4 -2
  135. package/dist/protocol/utils/protocolVersion.js +4 -2
  136. package/dist/react/InitializationErrorDetails.d.ts.map +1 -1
  137. package/dist/react/MissingHostCommand.d.ts.map +1 -1
  138. package/dist/react/MissingHostScreen.d.ts.map +1 -1
  139. package/dist/react/NotionCustomBlock.d.ts.map +1 -1
  140. package/dist/react/index.d.ts +0 -2
  141. package/dist/react/index.d.ts.map +1 -1
  142. package/dist/react/index.js +0 -1
  143. package/dist/react/useAsyncRead.d.ts.map +1 -1
  144. package/dist/react/useContainingPage.d.ts.map +1 -1
  145. package/dist/react/useLiveLocationRead.d.ts.map +1 -1
  146. package/dist/react/usePage.d.ts.map +1 -1
  147. package/dist/react/useParent.d.ts.map +1 -1
  148. package/dist/react/useQuerySubscription.d.ts.map +1 -1
  149. package/dist/react/useUserFields.d.ts.map +1 -1
  150. package/dist/react/useViewer.d.ts.map +1 -1
  151. package/dist/styles/scrollbars.css +18 -0
  152. package/dist/users/NotionUser.d.ts.map +1 -1
  153. package/dist/users/bridge/toNotionUserDataFromBridgeUser.d.ts.map +1 -1
  154. package/dist/users/getUser.d.ts.map +1 -1
  155. package/dist/users/getViewer.d.ts.map +1 -1
  156. package/dist/users/listUsers.d.ts.map +1 -1
  157. package/dist/users/types.d.ts.map +1 -1
  158. package/dist/users.d.ts.map +1 -1
  159. package/dist/utils/makeUuid.d.ts.map +1 -1
  160. package/dist/utils/notifyListener.d.ts.map +1 -1
  161. package/dist/utils/typeUtils.d.ts.map +1 -1
  162. package/dist/utils/unreachable.d.ts.map +1 -1
  163. package/dist/utils/version.d.ts.map +1 -1
  164. package/dist/utils/version.js +1 -1
  165. package/docs/block-location.md +22 -9
  166. package/docs/deployment.md +5 -11
  167. package/docs/errors.md +4 -0
  168. package/docs/grants.md +7 -2
  169. package/docs/local-development.md +39 -0
  170. package/docs/pages.md +97 -62
  171. package/package.json +2 -1
  172. package/src/bridge/SandboxBridge.ts +49 -144
  173. package/src/bridge/createBrowserSandboxBridge.ts +64 -0
  174. package/src/bridge/getBridge.ts +3 -2
  175. package/src/bridge/hostState.ts +2 -2
  176. package/src/bridge/initialization/SandboxInitialization.ts +24 -10
  177. package/src/bridge/sandboxEnvironment.ts +38 -0
  178. package/src/dataSources/bridge/DataSourceCache.ts +94 -0
  179. package/src/dataSources/bridge/reuseDataSourcesForUnchangedBindings.ts +5 -5
  180. package/src/dataSources/properties/resolvePropertyWriteMapForDataSource.ts +2 -2
  181. package/src/files/files.ts +1 -1
  182. package/src/location/mapContainingPage.ts +2 -2
  183. package/src/pages/bridge/toNotionPagePropertyFromBridgeProperty.ts +2 -2
  184. package/src/pages/types.ts +9 -3
  185. package/src/preferences/syncDocumentAppearance.ts +2 -1
  186. package/src/react/index.ts +0 -2
  187. package/src/styles/scrollbars.css +18 -0
  188. package/dist/react/NotionTokenScope.d.ts +0 -10
  189. package/dist/react/NotionTokenScope.d.ts.map +0 -1
  190. package/dist/react/NotionTokenScope.js +0 -12
  191. package/src/react/NotionTokenScope.tsx +0 -26
@@ -4,7 +4,7 @@ import type {
4
4
  } from "@notionhq/custom-blocks-protocol/dataSources/errors.js"
5
5
  import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
6
6
  import type { CreatePageMessage } from "@notionhq/custom-blocks-protocol/pages/messages/createPage.js"
7
- import { bridgePagePropertyValueSchema } from "@notionhq/custom-blocks-protocol/pages/properties/bridgePagePropertyValue.js"
7
+ import { bridgePagePropertyWriteValueSchema } from "@notionhq/custom-blocks-protocol/pages/properties/bridgePagePropertyValue.js"
8
8
  import * as v from "valibot"
9
9
  import type { NotionPagePropertyInputMap } from "../../pages/types.js"
10
10
 
@@ -79,7 +79,7 @@ export function resolvePropertyWriteMapForDataSource(args: {
79
79
  }
80
80
  }
81
81
 
82
- const parsedValue = v.safeParse(bridgePagePropertyValueSchema, {
82
+ const parsedValue = v.safeParse(bridgePagePropertyWriteValueSchema, {
83
83
  ...value,
84
84
  id: propertyId,
85
85
  })
@@ -1,5 +1,5 @@
1
1
  export type {
2
2
  BridgeExternalFile as NotionExternalFile,
3
- BridgeFilePropertyItem as NotionFilePropertyItem,
3
+ BridgeFilePropertyReadItem as NotionFilePropertyItem,
4
4
  BridgeNotionHostedFile as NotionHostedFile,
5
5
  } from "@notionhq/custom-blocks-protocol/files.js"
@@ -1,8 +1,8 @@
1
- import type { CustomBlockPage } from "@notionhq/custom-blocks-protocol/context/containingPage.js"
1
+ import type { ContainingPage } from "@notionhq/custom-blocks-protocol/context/containingPage.js"
2
2
  import { NotionPage } from "../pages/NotionPage.js"
3
3
  import type { NotionContainingPage } from "./types.js"
4
4
 
5
- export function mapContainingPage(page: CustomBlockPage): NotionContainingPage {
5
+ export function mapContainingPage(page: ContainingPage): NotionContainingPage {
6
6
  return page.type === "unavailable"
7
7
  ? { type: "unavailable" }
8
8
  : {
@@ -1,9 +1,9 @@
1
- import type { BridgePagePropertyValue } from "@notionhq/custom-blocks-protocol/pages/properties/bridgePagePropertyValue.js"
1
+ import type { BridgePagePropertyReadValue } from "@notionhq/custom-blocks-protocol/pages/properties/bridgePagePropertyValue.js"
2
2
  import { unreachable } from "../../utils/unreachable.js"
3
3
  import type { NotionPagePropertyValue } from "../types.js"
4
4
 
5
5
  export function toNotionPagePropertyFromBridgeProperty(
6
- value: BridgePagePropertyValue,
6
+ value: BridgePagePropertyReadValue,
7
7
  ): NotionPagePropertyValue {
8
8
  switch (value.type) {
9
9
  case "title":
@@ -3,6 +3,7 @@ import type {
3
3
  PageParent,
4
4
  } from "@notionhq/custom-blocks-protocol/context/parent.js"
5
5
  import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
6
+ import type { BridgeFilePropertyItem } from "@notionhq/custom-blocks-protocol/files.js"
6
7
  import type {
7
8
  CustomBlockCreatePageErrorInfo,
8
9
  NotionCreatePagePosition,
@@ -33,7 +34,7 @@ export type NotionPageIcon = BridgePageIcon
33
34
 
34
35
  export type NotionPageCover = BridgePageCover
35
36
 
36
- export type NotionPagePropertyValue = { id: string } & (
37
+ type PagePropertyValue<FileItem> = { id: string } & (
37
38
  | { type: "title"; title: NotionRichTextItem[] }
38
39
  | { type: "rich_text"; rich_text: NotionRichTextItem[] }
39
40
  | { type: "number"; number: number | null }
@@ -47,7 +48,7 @@ export type NotionPagePropertyValue = { id: string } & (
47
48
  | { type: "date"; date: NotionDateInput | null }
48
49
  | { type: "people"; people: NotionUserInput[] }
49
50
  | { type: "relation"; relation: NotionRelationInput[]; has_more?: boolean }
50
- | { type: "files"; files: NotionFilePropertyItem[] }
51
+ | { type: "files"; files: FileItem[] }
51
52
  | { type: "place"; place: NotionPlaceInput | null }
52
53
  | { type: "created_time"; created_time: string | null }
53
54
  | { type: "last_edited_time"; last_edited_time: string | null }
@@ -60,12 +61,17 @@ export type NotionPagePropertyValue = { id: string } & (
60
61
  | { type: "verification"; verification: string }
61
62
  )
62
63
 
64
+ export type NotionPagePropertyValue = PagePropertyValue<NotionFilePropertyItem>
65
+
63
66
  export type NotionPagePropertyReadMap = Record<
64
67
  string,
65
68
  NotionPagePropertyValue | null
66
69
  >
67
70
 
68
- export type NotionPagePropertyWriteMap = Record<string, NotionPagePropertyValue>
71
+ export type NotionPagePropertyWriteMap = Record<
72
+ string,
73
+ PagePropertyValue<BridgeFilePropertyItem>
74
+ >
69
75
 
70
76
  /**
71
77
  * Public SDK page property write input. Keys may be raw property IDs or data source
@@ -7,7 +7,7 @@ import {
7
7
 
8
8
  /**
9
9
  * Applies the host's theme and contrast to the document before the application renders.
10
- * Styling the canvas before a token scope mounts prevents a flash of the default white background.
10
+ * Styling the canvas before the application mounts prevents a flash of the default white background.
11
11
  */
12
12
  export function syncDocumentAppearance(args: {
13
13
  theme: NotionTheme
@@ -18,6 +18,7 @@ export function syncDocumentAppearance(args: {
18
18
  }
19
19
  const { theme, contrastMode } = args
20
20
  const root = document.documentElement
21
+ root.classList.add("nds")
21
22
  root.dataset.displayMode = theme
22
23
  root.dataset.contrastMode = contrastMode
23
24
  root.style.colorScheme = theme
@@ -10,8 +10,6 @@ export { useContrastMode } from "../preferences/react/useContrastMode.js"
10
10
  export { useTheme } from "../preferences/react/useTheme.js"
11
11
  export type { NotionCustomBlockProps } from "./NotionCustomBlock.js"
12
12
  export { NotionCustomBlock } from "./NotionCustomBlock.js"
13
- export type { NotionTokenScopeProps } from "./NotionTokenScope.js"
14
- export { NotionTokenScope } from "./NotionTokenScope.js"
15
13
  export { useContainingPage } from "./useContainingPage.js"
16
14
  export { usePage } from "./usePage.js"
17
15
  export { useParent } from "./useParent.js"
@@ -0,0 +1,18 @@
1
+ /* Use the scroll area's text tokens so locally themed surfaces get matching colors. */
2
+ :where(:root, *) {
3
+ scrollbar-color: var(
4
+ --notion-scrollbar-thumb,
5
+ color-mix(in srgb, var(--content-interactive-tertiary) 50%, transparent)
6
+ )
7
+ transparent;
8
+ }
9
+
10
+ :where([data-contrast-mode="high"], [data-contrast-mode="high"] *) {
11
+ scrollbar-color: auto;
12
+ }
13
+
14
+ @media (forced-colors: active) {
15
+ :where(:root, *) {
16
+ scrollbar-color: auto;
17
+ }
18
+ }
@@ -1,10 +0,0 @@
1
- import type { ReactNode } from "react";
2
- export type NotionTokenScopeProps = {
3
- children: ReactNode;
4
- };
5
- /**
6
- * Makes Notion design tokens available to descendants and keeps their
7
- * host-controlled appearance in sync.
8
- */
9
- export declare function NotionTokenScope({ children }: NotionTokenScopeProps): import("react").JSX.Element;
10
- //# sourceMappingURL=NotionTokenScope.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NotionTokenScope.d.ts","sourceRoot":"","sources":["../../src/react/NotionTokenScope.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAItC,MAAM,MAAM,qBAAqB,GAAG;IACnC,QAAQ,EAAE,SAAS,CAAA;CACnB,CAAA;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,QAAQ,EAAE,EAAE,qBAAqB,+BAanE"}
@@ -1,12 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useContrastMode } from "../preferences/react/useContrastMode.js";
3
- import { useTheme } from "../preferences/react/useTheme.js";
4
- /**
5
- * Makes Notion design tokens available to descendants and keeps their
6
- * host-controlled appearance in sync.
7
- */
8
- export function NotionTokenScope({ children }) {
9
- const theme = useTheme();
10
- const contrastMode = useContrastMode();
11
- return (_jsx("div", { className: "nds", "data-display-mode": theme, "data-contrast-mode": contrastMode, children: children }));
12
- }
@@ -1,26 +0,0 @@
1
- import type { ReactNode } from "react"
2
- import { useContrastMode } from "../preferences/react/useContrastMode.js"
3
- import { useTheme } from "../preferences/react/useTheme.js"
4
-
5
- export type NotionTokenScopeProps = {
6
- children: ReactNode
7
- }
8
-
9
- /**
10
- * Makes Notion design tokens available to descendants and keeps their
11
- * host-controlled appearance in sync.
12
- */
13
- export function NotionTokenScope({ children }: NotionTokenScopeProps) {
14
- const theme = useTheme()
15
- const contrastMode = useContrastMode()
16
-
17
- return (
18
- <div
19
- className="nds"
20
- data-display-mode={theme}
21
- data-contrast-mode={contrastMode}
22
- >
23
- {children}
24
- </div>
25
- )
26
- }