@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.
- package/README.md +32 -18
- package/dist/bridge/SandboxBridge.d.ts +7 -8
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +39 -114
- package/dist/bridge/applyHostStateMessage.d.ts.map +1 -1
- package/dist/bridge/createBrowserSandboxBridge.d.ts +3 -0
- package/dist/bridge/createBrowserSandboxBridge.d.ts.map +1 -0
- package/dist/bridge/createBrowserSandboxBridge.js +54 -0
- package/dist/bridge/getBridge.d.ts +1 -1
- package/dist/bridge/getBridge.d.ts.map +1 -1
- package/dist/bridge/getBridge.js +2 -2
- package/dist/bridge/getInitializedHostState.d.ts.map +1 -1
- package/dist/bridge/hostState.d.ts +2 -2
- package/dist/bridge/hostState.d.ts.map +1 -1
- package/dist/bridge/initialization/SandboxInitialization.d.ts +6 -0
- package/dist/bridge/initialization/SandboxInitialization.d.ts.map +1 -1
- package/dist/bridge/initialization/SandboxInitialization.js +13 -10
- package/dist/bridge/messageInterceptor.d.ts.map +1 -1
- package/dist/bridge/requests.d.ts.map +1 -1
- package/dist/bridge/sandboxEnvironment.d.ts +30 -0
- package/dist/bridge/sandboxEnvironment.d.ts.map +1 -0
- package/dist/bridge/sandboxEnvironment.js +1 -0
- package/dist/bridge/subscribeToHostStateField.d.ts.map +1 -1
- package/dist/bridge.d.ts.map +1 -1
- package/dist/data-sources.d.ts.map +1 -1
- package/dist/dataSources/NotionDataSource.d.ts.map +1 -1
- package/dist/dataSources/bridge/DataSourceCache.d.ts +18 -0
- package/dist/dataSources/bridge/DataSourceCache.d.ts.map +1 -0
- package/dist/dataSources/bridge/DataSourceCache.js +75 -0
- package/dist/dataSources/bridge/applyDataSourceBindings.d.ts.map +1 -1
- package/dist/dataSources/bridge/makeDataSourceReadResponseSchema.d.ts.map +1 -1
- package/dist/dataSources/bridge/resolveDataSourceQuery.d.ts.map +1 -1
- package/dist/dataSources/bridge/resolveDataSources.d.ts.map +1 -1
- package/dist/dataSources/bridge/resolveSorts.d.ts.map +1 -1
- package/dist/dataSources/bridge/reuseDataSourcesForUnchangedBindings.d.ts +0 -3
- package/dist/dataSources/bridge/reuseDataSourcesForUnchangedBindings.d.ts.map +1 -1
- package/dist/dataSources/bridge/reuseDataSourcesForUnchangedBindings.js +2 -5
- package/dist/dataSources/dataSourceInaccessibleError.d.ts.map +1 -1
- package/dist/dataSources/dataSourceState.d.ts.map +1 -1
- package/dist/dataSources/ensureDataSource.d.ts.map +1 -1
- package/dist/dataSources/filters/resolveFilter.d.ts.map +1 -1
- package/dist/dataSources/filters/types.d.ts.map +1 -1
- package/dist/dataSources/getDataSourcePage.d.ts.map +1 -1
- package/dist/dataSources/observeDataSource.d.ts.map +1 -1
- package/dist/dataSources/properties/resolvePropertyAddress.d.ts.map +1 -1
- package/dist/dataSources/properties/resolvePropertyWriteMapForDataSource.d.ts.map +1 -1
- package/dist/dataSources/properties/resolvePropertyWriteMapForDataSource.js +2 -2
- package/dist/dataSources/resolvePageDataSource.d.ts.map +1 -1
- package/dist/dataSources/subscribeToDataSource.d.ts.map +1 -1
- package/dist/dataSources/types.d.ts.map +1 -1
- package/dist/files/files.d.ts +1 -1
- package/dist/files/files.d.ts.map +1 -1
- package/dist/files/icons.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/initialization/NotInIframeError.d.ts.map +1 -1
- package/dist/initialization/initCustomBlock.d.ts.map +1 -1
- package/dist/initialization/notifyReady.d.ts.map +1 -1
- package/dist/initialization/react/useCustomBlockInit.d.ts.map +1 -1
- package/dist/initialization/resolveInitialState.d.ts.map +1 -1
- package/dist/initialization/types.d.ts.map +1 -1
- package/dist/layout/autoResize.d.ts.map +1 -1
- package/dist/layout/getInitialContentHeight.d.ts.map +1 -1
- package/dist/location/getContainingPage.d.ts.map +1 -1
- package/dist/location/getInstance.d.ts.map +1 -1
- package/dist/location/getParent.d.ts.map +1 -1
- package/dist/location/mapContainingPage.d.ts +2 -2
- package/dist/location/mapContainingPage.d.ts.map +1 -1
- package/dist/location/mapParent.d.ts.map +1 -1
- package/dist/location/subscribeToContainingPage.d.ts.map +1 -1
- package/dist/location/subscribeToParent.d.ts.map +1 -1
- package/dist/location/types.d.ts.map +1 -1
- package/dist/manifest/getManifest.d.ts.map +1 -1
- package/dist/manifest/readLocalManifest.d.ts.map +1 -1
- package/dist/manifest/types.d.ts.map +1 -1
- package/dist/navigation/openExternalUrl.d.ts.map +1 -1
- package/dist/navigation/types.d.ts.map +1 -1
- package/dist/navigation.d.ts.map +1 -1
- package/dist/pages/NotionPage.d.ts.map +1 -1
- package/dist/pages/bridge/buildCreatePageRequest.d.ts.map +1 -1
- package/dist/pages/bridge/getPageForDataSource.d.ts.map +1 -1
- package/dist/pages/bridge/resolveCreatePageDestination.d.ts.map +1 -1
- package/dist/pages/bridge/sendCreatePageRequest.d.ts.map +1 -1
- package/dist/pages/bridge/toNotionPageFromBridgePage.d.ts.map +1 -1
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts +2 -2
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts.map +1 -1
- package/dist/pages/bridge/updatePage.d.ts.map +1 -1
- package/dist/pages/createPage.d.ts.map +1 -1
- package/dist/pages/getPage.d.ts.map +1 -1
- package/dist/pages/identityBlockKey.d.ts.map +1 -1
- package/dist/pages/identityPageKey.d.ts.map +1 -1
- package/dist/pages/openPage.d.ts.map +1 -1
- package/dist/pages/parent.d.ts.map +1 -1
- package/dist/pages/types.d.ts +5 -3
- package/dist/pages/types.d.ts.map +1 -1
- package/dist/pages.d.ts.map +1 -1
- package/dist/preferences/backgroundColors.d.ts.map +1 -1
- package/dist/preferences/getContrastMode.d.ts.map +1 -1
- package/dist/preferences/getTheme.d.ts.map +1 -1
- package/dist/preferences/react/useContrastMode.d.ts.map +1 -1
- package/dist/preferences/react/useTheme.d.ts.map +1 -1
- package/dist/preferences/subscribeToContrastMode.d.ts.map +1 -1
- package/dist/preferences/subscribeToTheme.d.ts.map +1 -1
- package/dist/preferences/syncDocumentAppearance.d.ts +1 -1
- package/dist/preferences/syncDocumentAppearance.d.ts.map +1 -1
- package/dist/preferences/syncDocumentAppearance.js +2 -1
- package/dist/preferences.d.ts.map +1 -1
- package/dist/protocol/compatibility/protocol12/hostToSandbox.d.ts +3356 -0
- package/dist/protocol/compatibility/protocol12/hostToSandbox.js +38 -0
- package/dist/protocol/compatibility/protocol12/page.d.ts +296 -0
- package/dist/protocol/compatibility/protocol12/page.js +7 -0
- package/dist/protocol/context/containingPage.d.ts +4 -2
- package/dist/protocol/context/containingPage.js +1 -1
- package/dist/protocol/context/messages/pageChanged.js +2 -2
- package/dist/protocol/dataSources/areDataSourceBindingsEqual.d.ts +3 -0
- package/dist/protocol/dataSources/areDataSourceBindingsEqual.js +26 -0
- package/dist/protocol/dataSources/messages/queryDataSource.d.ts +24 -19
- package/dist/protocol/dataSources/messages/queryDataSource.js +2 -0
- package/dist/protocol/files.d.ts +18 -0
- package/dist/protocol/files.js +9 -0
- package/dist/protocol/messages/hostToSandbox.d.ts +2200 -68
- package/dist/protocol/messages/hostToSandbox.js +6 -2
- package/dist/protocol/messages/sandboxToHost.d.ts +51 -51
- package/dist/protocol/pages/bridgePage.d.ts +20 -17
- package/dist/protocol/pages/messages/createPage.d.ts +88 -85
- package/dist/protocol/pages/messages/getPage.d.ts +24 -19
- package/dist/protocol/pages/messages/getPage.js +2 -0
- package/dist/protocol/pages/messages/updatePage.d.ts +37 -34
- package/dist/protocol/pages/properties/bridgePagePropertyMaps.d.ts +37 -34
- package/dist/protocol/pages/properties/bridgePagePropertyMaps.js +3 -3
- package/dist/protocol/pages/properties/bridgePagePropertyValue.d.ts +236 -2
- package/dist/protocol/pages/properties/bridgePagePropertyValue.js +20 -7
- package/dist/protocol/utils/errors.d.ts +6 -0
- package/dist/protocol/utils/errors.js +8 -0
- package/dist/protocol/utils/protocolVersion.d.ts +4 -2
- package/dist/protocol/utils/protocolVersion.js +4 -2
- package/dist/react/InitializationErrorDetails.d.ts.map +1 -1
- package/dist/react/MissingHostCommand.d.ts.map +1 -1
- package/dist/react/MissingHostScreen.d.ts.map +1 -1
- package/dist/react/NotionCustomBlock.d.ts.map +1 -1
- package/dist/react/index.d.ts +0 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +0 -1
- package/dist/react/useAsyncRead.d.ts.map +1 -1
- package/dist/react/useContainingPage.d.ts.map +1 -1
- package/dist/react/useLiveLocationRead.d.ts.map +1 -1
- package/dist/react/usePage.d.ts.map +1 -1
- package/dist/react/useParent.d.ts.map +1 -1
- package/dist/react/useQuerySubscription.d.ts.map +1 -1
- package/dist/react/useUserFields.d.ts.map +1 -1
- package/dist/react/useViewer.d.ts.map +1 -1
- package/dist/styles/scrollbars.css +18 -0
- package/dist/users/NotionUser.d.ts.map +1 -1
- package/dist/users/bridge/toNotionUserDataFromBridgeUser.d.ts.map +1 -1
- package/dist/users/getUser.d.ts.map +1 -1
- package/dist/users/getViewer.d.ts.map +1 -1
- package/dist/users/listUsers.d.ts.map +1 -1
- package/dist/users/types.d.ts.map +1 -1
- package/dist/users.d.ts.map +1 -1
- package/dist/utils/makeUuid.d.ts.map +1 -1
- package/dist/utils/notifyListener.d.ts.map +1 -1
- package/dist/utils/typeUtils.d.ts.map +1 -1
- package/dist/utils/unreachable.d.ts.map +1 -1
- package/dist/utils/version.d.ts.map +1 -1
- package/dist/utils/version.js +1 -1
- package/docs/block-location.md +22 -9
- package/docs/deployment.md +5 -11
- package/docs/errors.md +4 -0
- package/docs/grants.md +7 -2
- package/docs/local-development.md +39 -0
- package/docs/pages.md +97 -62
- package/package.json +2 -1
- package/src/bridge/SandboxBridge.ts +49 -144
- package/src/bridge/createBrowserSandboxBridge.ts +64 -0
- package/src/bridge/getBridge.ts +3 -2
- package/src/bridge/hostState.ts +2 -2
- package/src/bridge/initialization/SandboxInitialization.ts +24 -10
- package/src/bridge/sandboxEnvironment.ts +38 -0
- package/src/dataSources/bridge/DataSourceCache.ts +94 -0
- package/src/dataSources/bridge/reuseDataSourcesForUnchangedBindings.ts +5 -5
- package/src/dataSources/properties/resolvePropertyWriteMapForDataSource.ts +2 -2
- package/src/files/files.ts +1 -1
- package/src/location/mapContainingPage.ts +2 -2
- package/src/pages/bridge/toNotionPagePropertyFromBridgeProperty.ts +2 -2
- package/src/pages/types.ts +9 -3
- package/src/preferences/syncDocumentAppearance.ts +2 -1
- package/src/react/index.ts +0 -2
- package/src/styles/scrollbars.css +18 -0
- package/dist/react/NotionTokenScope.d.ts +0 -10
- package/dist/react/NotionTokenScope.d.ts.map +0 -1
- package/dist/react/NotionTokenScope.js +0 -12
- package/src/react/NotionTokenScope.tsx +0 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","
|
|
1
|
+
{"version":3,"file":"types.d.ts","sources":["../../src/users/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4DAA4D,CAAA;AAC7G,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,8DAA8D,CAAA;AACjH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kDAAkD,CAAA;AAEpF,YAAY,EAAE,YAAY,EAAE,MAAM,kDAAkD,CAAA;AAEpF,0EAA0E;AAC1E,MAAM,MAAM,cAAc,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,EAAE,EAAE,YAAY,CAAA;IAChB,6DAA6D;IAC7D,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,IAAI,EAAE,QAAQ,CAAA;IACd,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,cAAc,EAAE,CAAA;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,eAAe,GACxB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,GAC3C;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,6BAA6B,CAAA;CAAE,CAAA;AAE5D,MAAM,MAAM,aAAa,GACtB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,GAC3C;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,2BAA2B,CAAA;CAAE,CAAA","sourceRoot":""}
|
package/dist/users.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.d.ts","
|
|
1
|
+
{"version":3,"file":"users.d.ts","sources":["../src/users.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,2BAA2B,EAC3B,2BAA2B,GAC3B,MAAM,4DAA4D,CAAA;AACnE,YAAY,EACX,6BAA6B,EAC7B,6BAA6B,GAC7B,MAAM,8DAA8D,CAAA;AACrE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,YAAY,EACX,aAAa,EACb,eAAe,EACf,cAAc,EACd,YAAY,EACZ,cAAc,GACd,MAAM,kBAAkB,CAAA","sourceRoot":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeUuid.d.ts","
|
|
1
|
+
{"version":3,"file":"makeUuid.d.ts","sources":["../../src/utils/makeUuid.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,IAAI,MAAM,CAEjC","sourceRoot":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifyListener.d.ts","
|
|
1
|
+
{"version":3,"file":"notifyListener.d.ts","sources":["../../src/utils/notifyListener.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAYzD","sourceRoot":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeUtils.d.ts","
|
|
1
|
+
{"version":3,"file":"typeUtils.d.ts","sources":["../../src/utils/typeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,GAAG,MAAM,CAAC,GAAG,KAAK,CAAA;AAE9D,2EAA2E;AAC3E,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,IAAI,CAAC,SAAS,OAAO,GACzD,CAAC,GAAG;KAAG,CAAC,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK;CAAE,GACzD,KAAK,CAAA","sourceRoot":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unreachable.d.ts","
|
|
1
|
+
{"version":3,"file":"unreachable.d.ts","sources":["../../src/utils/unreachable.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAI/C","sourceRoot":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","
|
|
1
|
+
{"version":3,"file":"version.d.ts","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,EAAE,MAAgB,CAAA","sourceRoot":""}
|
package/dist/utils/version.js
CHANGED
package/docs/block-location.md
CHANGED
|
@@ -138,15 +138,28 @@ identity without a host request.
|
|
|
138
138
|
|
|
139
139
|
## Preferences
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
141
|
+
For styling, the SDK provides a set of [Notion design tokens](../README.md#notion-design-tokens).
|
|
142
|
+
Using these tokens is recommended. CSS that uses them follows Notionβs theme and contrast settings
|
|
143
|
+
automatically.
|
|
144
|
+
|
|
145
|
+
If your code needs to know whether Notion is in light or dark mode, use `getTheme()` or `useTheme()`
|
|
146
|
+
in React. The browserβs `prefers-color-scheme` can differ from the theme selected in Notion. Use
|
|
147
|
+
`getContrastMode()` or `useContrastMode()` to read the contrast setting.
|
|
148
|
+
|
|
149
|
+
The getters and their subscriptions are exported from `@notionhq/custom-blocks/preferences`. The
|
|
150
|
+
hooks are exported from `@notionhq/custom-blocks/react`. Both getters throw if called before SDK
|
|
151
|
+
initialization succeeds.
|
|
152
|
+
|
|
153
|
+
The initial setup snapshot includes these values under `preferences`.
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
preferences: {
|
|
157
|
+
theme: "light" | "dark"
|
|
158
|
+
contrastMode: "standard" | "high"
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The SDK keeps both values current as Notionβs settings change, even when no code is subscribed.
|
|
150
163
|
|
|
151
164
|
## Manifest
|
|
152
165
|
|
package/docs/deployment.md
CHANGED
|
@@ -11,9 +11,9 @@ manifest's single source of truth:
|
|
|
11
11
|
|
|
12
12
|
- **Deployed**: deploying persists the manifest on the block's definition record in Notion. The host
|
|
13
13
|
reads it from there and sends it to the SDK during initialization.
|
|
14
|
-
- **Local development**: dev
|
|
15
|
-
block HTML as a JSON script with ID `notion-custom-block-manifest` and type
|
|
16
|
-
The SDK reads the manifest from this metadata and sends it in `connect`.
|
|
14
|
+
- **Local development**: at startup, the dev shell extracts the same worker declaration and injects
|
|
15
|
+
the manifest into the block HTML as a JSON script with ID `notion-custom-block-manifest` and type
|
|
16
|
+
`application/json`. The SDK reads the manifest from this metadata and sends it in `connect`.
|
|
17
17
|
|
|
18
18
|
Notion reconciles custom block definitions by their Worker capability keys during deployment.
|
|
19
19
|
|
|
@@ -27,14 +27,8 @@ Keep packages that the Worker's server code imports in `dependencies`.
|
|
|
27
27
|
|
|
28
28
|
## Local development
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
localhost subdomain for each block. Open the shell URL printed by the command. The default port is
|
|
33
|
-
`9873`. The launcher selects another port when needed. Vite provides source transforms and hot
|
|
34
|
-
reload.
|
|
35
|
-
|
|
36
|
-
Worker declarations are read when the dev shell starts. Restart it after changing a declaration to
|
|
37
|
-
regenerate the injected metadata, then reload the block. Block source files hot reload.
|
|
30
|
+
Before you deploy, [verify your block locally](local-development.md) with the dev shell and sample
|
|
31
|
+
data.
|
|
38
32
|
|
|
39
33
|
## Types
|
|
40
34
|
|
package/docs/errors.md
CHANGED
|
@@ -26,6 +26,10 @@ type CustomBlockErrorInfo<TCode extends string = string> = {
|
|
|
26
26
|
API-specific error types list known codes for autocomplete and accept other strings. Keep a default
|
|
27
27
|
branch when switching on `code`.
|
|
28
28
|
|
|
29
|
+
Some errors include a `details` object with extra debugging context. Before using a detail, check
|
|
30
|
+
that it exists and has the shape you expect. Use `code` and `isRetryable` to decide how to handle
|
|
31
|
+
the error.
|
|
32
|
+
|
|
29
33
|
## Initialization errors
|
|
30
34
|
|
|
31
35
|
`initCustomBlock()` rejects with `CustomBlockInitializationError`. The React wrapper displays its
|
package/docs/grants.md
CHANGED
|
@@ -93,7 +93,7 @@ connect to that origin, for example
|
|
|
93
93
|
connections, plus images, media, fonts, stylesheets, and frames loaded from the origin. An
|
|
94
94
|
`https://*.example.com` resource covers subdomains. Deploys reject resources that are not bare HTTPS
|
|
95
95
|
origins. Notion allows an approved origin only while it is also on the workspace's custom block
|
|
96
|
-
network allowlist.
|
|
96
|
+
network allowlist.
|
|
97
97
|
|
|
98
98
|
The declared origins, written as a JSON array such as `["https://api.example.com"]`, can use at most
|
|
99
99
|
2,048 characters. Deploys reject longer lists. Combine origins that share a domain into one
|
|
@@ -107,7 +107,12 @@ nothing.
|
|
|
107
107
|
|
|
108
108
|
## Dev shell
|
|
109
109
|
|
|
110
|
-
The dev shell
|
|
110
|
+
The dev shell treats each declared `network.fetch` origin as approved. It blocks other external
|
|
111
|
+
origins. The block's own origin, hot reload, Notion-hosted media, and Google Fonts work without
|
|
112
|
+
grants.
|
|
113
|
+
|
|
114
|
+
The same grants govern writes of external HTTPS URLs to Files properties, page icons, and covers.
|
|
115
|
+
Restart the dev shell after changing grants.
|
|
111
116
|
|
|
112
117
|
## Types
|
|
113
118
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Verify a custom block locally
|
|
2
|
+
|
|
3
|
+
Use the dev shell to check how your custom block renders and responds to changes in sample data. The
|
|
4
|
+
dev shell runs the block in a mock Notion host.
|
|
5
|
+
|
|
6
|
+
## Start the dev shell
|
|
7
|
+
|
|
8
|
+
From your Worker project, run:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
ntn workers customblocks dev
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The command prints the dev shell URL and keeps running. Use the printed URL each time because the
|
|
15
|
+
port can change.
|
|
16
|
+
|
|
17
|
+
## Verify in the dev shell
|
|
18
|
+
|
|
19
|
+
1. Open the dev shell URL.
|
|
20
|
+
2. Select the block.
|
|
21
|
+
3. If the block declares data sources, add sample rows and complete the property mappings.
|
|
22
|
+
4. Try the interaction you changed with a sample value you can recognize. Check that the block shows
|
|
23
|
+
the expected result.
|
|
24
|
+
|
|
25
|
+
Use a deployed block to verify Notion permissions, persistence, and production browser restrictions.
|
|
26
|
+
|
|
27
|
+
## Allow external origins
|
|
28
|
+
|
|
29
|
+
If your block needs to fetch an external URL, add a
|
|
30
|
+
[`network.fetch` grant](grants.md#network-access) for the HTTPS origin in the block declaration.
|
|
31
|
+
|
|
32
|
+
## Iterate and diagnose
|
|
33
|
+
|
|
34
|
+
The dev shell hot reloads changes to block source files. Restart the dev shell after changing a
|
|
35
|
+
Worker declaration, including its grants.
|
|
36
|
+
|
|
37
|
+
If the block fails, check the launcher logs, selected sample files, and property mappings. If a
|
|
38
|
+
browser request fails, check the browser console for a content security policy error. In React
|
|
39
|
+
blocks, press `\` to open the SDK debug console.
|
package/docs/pages.md
CHANGED
|
@@ -117,7 +117,8 @@ guidance. See [mutation save failures](errors.md#mutation-save-failures).
|
|
|
117
117
|
|
|
118
118
|
Invalid values, duplicate targets, mismatched IDs, and unresolved keys fail before dispatch. An
|
|
119
119
|
update needs at least one property or metadata change. See
|
|
120
|
-
[local update errors](errors.md#local-page-update-errors) and
|
|
120
|
+
[local update errors](errors.md#local-page-update-errors) and
|
|
121
|
+
[files, page icons, and covers](#files-page-icons-and-covers).
|
|
121
122
|
|
|
122
123
|
## React
|
|
123
124
|
|
|
@@ -166,32 +167,32 @@ Property values can be `null` when empty or unavailable.
|
|
|
166
167
|
- π **Read-only:** Notion sets this value. You cannot set it when creating or updating a page.
|
|
167
168
|
- π΄ **Unavailable:** The SDK does not support this operation.
|
|
168
169
|
|
|
169
|
-
| Property type | Read page | Create page
|
|
170
|
-
| ------------------ | ----------------------------------------- |
|
|
171
|
-
| `title` | π‘ Plain text array | π‘ Plain text only
|
|
172
|
-
| `rich_text` | π‘ Plain text array | π‘ Plain text only
|
|
173
|
-
| `number` | π’ Number | π’ Supported
|
|
174
|
-
| `checkbox` | π’ Boolean | π’ Supported
|
|
175
|
-
| `url` | π’ String | π’ Supported
|
|
176
|
-
| `email` | π’ String | π’ Supported
|
|
177
|
-
| `phone_number` | π’ String | π’ Supported
|
|
178
|
-
| `select` | π’ Selected option | π’ Supported
|
|
179
|
-
| `multi_select` | π’ Selected options | π’ Supported
|
|
180
|
-
| `status` | π’ Selected option | π’ Supported
|
|
181
|
-
| `date` | π’ `start` and optional `end` strings | π’ Supported
|
|
182
|
-
| `people` | π’ Array of user or group ID objects | π’ Supported
|
|
183
|
-
| `relation` | π’ Array of page ID objects | π‘ Replaces value
|
|
184
|
-
| `place` | π’ Coordinates and optional place details | π’ Supported
|
|
185
|
-
| `files` | π’ External links and hosted files |
|
|
186
|
-
| `unique_id` | π‘ Formatted ID | π΄ Unavailable
|
|
187
|
-
| `formula` | π‘ Stored text | π΄ Unavailable
|
|
188
|
-
| `rollup` | π‘ Stored text | π΄ Unavailable
|
|
189
|
-
| `button` | π‘ Button label | π΄ Unavailable
|
|
190
|
-
| `verification` | π‘ Status text | π΄ Unavailable
|
|
191
|
-
| `created_time` | π’ Timestamp | π Read-only
|
|
192
|
-
| `last_edited_time` | π’ Timestamp | π Read-only
|
|
193
|
-
| `created_by` | π’ Actor reference | π Read-only
|
|
194
|
-
| `last_edited_by` | π’ Actor reference | π Read-only
|
|
170
|
+
| Property type | Read page | Create page | Update page |
|
|
171
|
+
| ------------------ | ----------------------------------------- | --------------------------------------------------------- | --------------------------------------------------------- |
|
|
172
|
+
| `title` | π‘ Plain text array | π‘ Plain text only | π‘ Plain text only |
|
|
173
|
+
| `rich_text` | π‘ Plain text array | π‘ Plain text only | π‘ Plain text only |
|
|
174
|
+
| `number` | π’ Number | π’ Supported | π’ Supported |
|
|
175
|
+
| `checkbox` | π’ Boolean | π’ Supported | π’ Supported |
|
|
176
|
+
| `url` | π’ String | π’ Supported | π’ Supported |
|
|
177
|
+
| `email` | π’ String | π’ Supported | π’ Supported |
|
|
178
|
+
| `phone_number` | π’ String | π’ Supported | π’ Supported |
|
|
179
|
+
| `select` | π’ Selected option | π’ Supported | π’ Supported |
|
|
180
|
+
| `multi_select` | π’ Selected options | π’ Supported | π’ Supported |
|
|
181
|
+
| `status` | π’ Selected option | π’ Supported | π’ Supported |
|
|
182
|
+
| `date` | π’ `start` and optional `end` strings | π’ Supported | π’ Supported |
|
|
183
|
+
| `people` | π’ Array of user or group ID objects | π’ Supported | π’ Supported |
|
|
184
|
+
| `relation` | π’ Array of page ID objects | π‘ Replaces value | π‘ Replaces value |
|
|
185
|
+
| `place` | π’ Coordinates and optional place details | π’ Supported | π’ Supported |
|
|
186
|
+
| `files` | π’ External links and hosted files | π‘ Existing Notion-hosted file URLs only<br>π΄ No uploads | π‘ Existing Notion-hosted file URLs only<br>π΄ No uploads |
|
|
187
|
+
| `unique_id` | π‘ Formatted ID | π΄ Unavailable | π΄ Unavailable |
|
|
188
|
+
| `formula` | π‘ Stored text | π΄ Unavailable | π΄ Unavailable |
|
|
189
|
+
| `rollup` | π‘ Stored text | π΄ Unavailable | π΄ Unavailable |
|
|
190
|
+
| `button` | π‘ Button label | π΄ Unavailable | π΄ Unavailable |
|
|
191
|
+
| `verification` | π‘ Status text | π΄ Unavailable | π΄ Unavailable |
|
|
192
|
+
| `created_time` | π’ Timestamp | π Read-only | π Read-only |
|
|
193
|
+
| `last_edited_time` | π’ Timestamp | π Read-only | π Read-only |
|
|
194
|
+
| `created_by` | π’ Actor reference | π Read-only | π Read-only |
|
|
195
|
+
| `last_edited_by` | π’ Actor reference | π Read-only | π Read-only |
|
|
195
196
|
|
|
196
197
|
### Notes
|
|
197
198
|
|
|
@@ -212,7 +213,7 @@ Property values can be `null` when empty or unavailable.
|
|
|
212
213
|
- Date-time writes support minute precision. Seconds and milliseconds are not preserved.
|
|
213
214
|
- Title and rich text use text arrays, but reads and writes preserve only plain text. Reads and
|
|
214
215
|
writes do not preserve formatting, links, mentions, or equations as structured rich text.
|
|
215
|
-
- Files
|
|
216
|
+
- See [Files properties](#files-properties) for supported file references.
|
|
216
217
|
- Relation writes replace the value and reject `has_more: true`.
|
|
217
218
|
- Top-level `created_time` and `last_edited_time` do not depend on the data source schema.
|
|
218
219
|
|
|
@@ -234,50 +235,84 @@ handing the request to navigation; it does not wait for the new page to load. No
|
|
|
234
235
|
page if the current surface cannot display the requested peek. Navigating inside a peek can unmount
|
|
235
236
|
the block before the result arrives.
|
|
236
237
|
|
|
237
|
-
|
|
238
|
+
## Files, page icons, and covers
|
|
238
239
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
entry fails the read rather than returning a partial list.
|
|
240
|
+
You can read both Notion-hosted files and external URLs. **File writes can only reference existing
|
|
241
|
+
Notion-hosted files.** The SDK has no file upload API. If you pass an external URL or an upload
|
|
242
|
+
reference when creating or updating a page, the write fails.
|
|
243
243
|
|
|
244
|
-
|
|
244
|
+
| Value | SDK type | Files property | Page icon | Page cover |
|
|
245
|
+
| ---------------------- | -------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
|
|
246
|
+
| Notion-hosted file | `NotionHostedFile` | π’ Read<br>π‘ Reference an existing file | π’ Read<br>π‘ Reference an existing file | π’ Read<br>π‘ Reference an existing file |
|
|
247
|
+
| External URL | `NotionExternalFile` | π‘ Read only | π‘ Read only | π‘ Read only |
|
|
248
|
+
| Built-in icon | `NotionIcon` | β | π’ Read / Write | β |
|
|
249
|
+
| Unicode emoji | `NotionEmoji` | β | π’ Read / Write | β |
|
|
250
|
+
| Workspace custom emoji | `NotionCustomEmoji` | β | π’ Read / Write | β |
|
|
245
251
|
|
|
246
|
-
The
|
|
247
|
-
accept different combinations of these types. Import them from `@notionhq/custom-blocks`.
|
|
252
|
+
The `β` indicates that the value doesnβt apply to that field.
|
|
248
253
|
|
|
249
|
-
###
|
|
254
|
+
### Files properties
|
|
250
255
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
URL.
|
|
255
|
-
- `NotionExternalFile`: a file hosted outside Notion, referenced by URL.
|
|
256
|
-
- `NotionHostedFile`: a file hosted by Notion, referenced by a URL with an optional expiration time.
|
|
256
|
+
A Files property holds files and links. Reads return entries in order. If a file is unavailable,
|
|
257
|
+
render a placeholder using its name when present. The host includes a name when it can read the
|
|
258
|
+
stored display label.
|
|
257
259
|
|
|
258
|
-
|
|
260
|
+
```ts
|
|
261
|
+
type NotionFilePropertyItem =
|
|
262
|
+
| (NotionHostedFile & { name: string })
|
|
263
|
+
| (NotionExternalFile & { name: string })
|
|
264
|
+
| { type: "unavailable"; name?: string }
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Placeholders appear only in reads. To set the property to an existing Notion-hosted PDF, pass its
|
|
268
|
+
URL and display name. Replace `aB9z` with the ID of your Files property.
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
await page.updateById({
|
|
272
|
+
properties: {
|
|
273
|
+
aB9z: {
|
|
274
|
+
type: "files",
|
|
275
|
+
files: [{ type: "file", name: "Report.pdf", file: { url: reportUrl } }],
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
})
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Hosted `file.url` values returned by reads are signed and expire at `file.expiry_time` when that
|
|
282
|
+
field is present. Call `page.get()` again for a fresh URL. An empty Files property returns `[]`.
|
|
283
|
+
|
|
284
|
+
### Page icons
|
|
285
|
+
|
|
286
|
+
A page icon is the small image next to the page title.
|
|
259
287
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
288
|
+
```ts
|
|
289
|
+
type NotionPageIcon =
|
|
290
|
+
NotionIcon | NotionEmoji | NotionCustomEmoji | NotionHostedFile | NotionExternalFile
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
To set a blue star, pass its name and color. If you omit `color`, it defaults to `"gray"`.
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
await page.updateById({
|
|
297
|
+
icon: { type: "icon", icon: { name: "star", color: "blue" } },
|
|
298
|
+
})
|
|
299
|
+
```
|
|
268
300
|
|
|
269
|
-
|
|
301
|
+
Icon aliases are supported. `NotionIconName` and `NotionIconColor` accept strings. `NotionIconColor`
|
|
302
|
+
suggests known colors in autocomplete. Unsupported icons read as `null`.
|
|
270
303
|
|
|
271
|
-
###
|
|
304
|
+
### Page covers
|
|
272
305
|
|
|
273
|
-
|
|
274
|
-
`{ type: "icon", icon: { name: "star", color: "blue" } }` in the `icon` field.
|
|
306
|
+
A page cover is the banner image at the top of a page.
|
|
275
307
|
|
|
276
|
-
|
|
277
|
-
|
|
308
|
+
```ts
|
|
309
|
+
type NotionPageCover = NotionHostedFile | NotionExternalFile
|
|
310
|
+
```
|
|
278
311
|
|
|
279
|
-
|
|
312
|
+
To set a cover, use the URL of an existing Notion-hosted image.
|
|
280
313
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
314
|
+
```ts
|
|
315
|
+
await page.updateById({
|
|
316
|
+
cover: { type: "file", file: { url: coverUrl } },
|
|
317
|
+
})
|
|
318
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notionhq/custom-blocks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"types": "./dist/index.d.ts"
|
|
15
15
|
},
|
|
16
16
|
"./nds.css": "./dist/styles/nds.css",
|
|
17
|
+
"./scrollbars.css": "./dist/styles/scrollbars.css",
|
|
17
18
|
"./react": {
|
|
18
19
|
"import": "./dist/react/index.js",
|
|
19
20
|
"types": "./dist/react/index.d.ts"
|