@notionhq/custom-blocks 0.1.21 → 0.1.23
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/bin/notion-custom-blocks/build.js +2 -2
- package/bin/notion-custom-blocks/tar.js +1 -1
- package/dist/bridge/dataSources/resolveProperty.d.ts +0 -1
- package/dist/bridge/dataSources/resolveProperty.d.ts.map +1 -1
- package/dist/bridge/sandboxClient.d.ts +0 -1
- package/dist/bridge/sandboxClient.d.ts.map +1 -1
- package/dist/react/useRuntimeState.d.ts +7 -5
- package/dist/react/useRuntimeState.d.ts.map +1 -1
- package/dist/react/useRuntimeState.js +7 -5
- package/dist/version.js +1 -1
- package/docs/data-sources.md +5 -5
- package/package.json +1 -1
- package/src/bridge/dataSources/resolveProperty.ts +0 -5
- package/src/bridge/sandboxClient.ts +0 -2
- package/src/react/useRuntimeState.ts +7 -5
|
@@ -3,8 +3,8 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { packDirToTarGz } from "./tar.js";
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const BUILD_OUTPUT_SENTINEL = "<__notion_custom_block__>";
|
|
7
|
+
const BUILD_OUTPUT_SENTINEL_CLOSE = "</__notion_custom_block__>";
|
|
8
8
|
const WORKER_ENTRY = "dist/index.js";
|
|
9
9
|
/**
|
|
10
10
|
* Build every `_tag: "custom_block"` view declared by the worker.
|
|
@@ -26,7 +26,7 @@ export function packDirToTarGz(dir) {
|
|
|
26
26
|
return { tarGz, checksumCrc32: crc32Base64(tarGz) };
|
|
27
27
|
}
|
|
28
28
|
/** Base64-encoded big-endian crc32, matching the server's `CRC32_BASE64_REGEX`. */
|
|
29
|
-
|
|
29
|
+
function crc32Base64(data) {
|
|
30
30
|
const checksum = zlib.crc32(data) >>> 0;
|
|
31
31
|
const buf = Buffer.alloc(4);
|
|
32
32
|
buf.writeUInt32BE(checksum);
|
|
@@ -2,7 +2,6 @@ import type { NotionDataSource } from "../../protocol/dataSources/dataSource.js"
|
|
|
2
2
|
import type { CustomBlockPropertyErrorInfo } from "../../protocol/dataSources/errors.js";
|
|
3
3
|
import type { NotionPagePropertyWriteMap } from "../../protocol/pages/page.js";
|
|
4
4
|
import type { NotionPagePropertyInputMap } from "../../types.js";
|
|
5
|
-
export type { CustomBlockPropertyErrorCode, CustomBlockPropertyErrorInfo, } from "../../protocol/dataSources/errors.js";
|
|
6
5
|
export type PropertyWriteMapResolutionResult = {
|
|
7
6
|
status: "success";
|
|
8
7
|
properties: NotionPagePropertyWriteMap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveProperty.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/dataSources/resolveProperty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,EAEX,4BAA4B,EAC5B,MAAM,wDAAwD,CAAA;AAC/D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAA;AAGhG,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAEhE,
|
|
1
|
+
{"version":3,"file":"resolveProperty.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/dataSources/resolveProperty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,EAEX,4BAA4B,EAC5B,MAAM,wDAAwD,CAAA;AAC/D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAA;AAGhG,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAEhE,MAAM,MAAM,gCAAgC,GACzC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,0BAA0B,CAAA;CAAE,GAC7D;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,4BAA4B,CAAA;CAAE,CAAA;AAS3D;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAAC,IAAI,EAAE;IAC1D,UAAU,EAAE,gBAAgB,GAAG,SAAS,CAAA;IACxC,UAAU,EAAE,0BAA0B,CAAA;IACtC,aAAa,EAAE,MAAM,CAAA;CACrB,GAAG,gCAAgC,CAwDnC;AAED;;;GAGG;AACH,wBAAgB,sCAAsC,CAAC,IAAI,EAAE;IAC5D,UAAU,EAAE,gBAAgB,GAAG,SAAS,CAAA;IACxC,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;CACrB,GACE;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,4BAA4B,CAAA;CAAE,CAsB1D"}
|
|
@@ -3,7 +3,6 @@ import type { CreatePageArgs, CreatePageResult, GetPageResult, GetUserResult, Li
|
|
|
3
3
|
import { type CustomBlockHostState, type DataSourceQueryView } from "./hostState.js";
|
|
4
4
|
import type { ManifestLoadResult } from "./loadManifest.js";
|
|
5
5
|
import { type MessageLogEntry } from "./SandboxBridge.js";
|
|
6
|
-
export type { MessageLogEntry };
|
|
7
6
|
export declare const customBlockHost: {
|
|
8
7
|
start: () => void;
|
|
9
8
|
sendConnect: (manifestResult: ManifestLoadResult) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandboxClient.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/sandboxClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAA;AACpF,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,aAAa,CAAA;AACpB,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EAExB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"sandboxClient.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/sandboxClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAA;AACpF,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,aAAa,CAAA;AACpB,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EAExB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,oBAAoB,CAAA;AAWxE,eAAO,MAAM,eAAe;;kCAKG,kBAAkB;yBAI3B,WAAW,KAAG,OAAO,CAAC,IAAI,CAAC;0BAI1B,MAAM,IAAI;oBAIlB,oBAAoB;IAIlC;;;OAGG;4BACqB,WAAW;;yBAQd,MAAM;CAG3B,CAAA;AAED,eAAO,MAAM,sBAAsB;iBACrB,MAAM,YAAY,oBAAoB;yBAKvC,oBAAoB,OAC1B,MAAM,KACT,mBAAmB;CAKtB,CAAA;AAED,eAAO,MAAM,UAAU;uBACL,SAAS,eAAe,EAAE;0BAIrB,MAAM,IAAI;CAGhC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,KAAK;IACjB;;OAEG;oBACa,cAAc,KAAG,OAAO,CAAC,gBAAgB,CAAC;IAI1D;;OAEG;kBACW,YAAY,KAAG,OAAO,CAAC,aAAa,CAAC;IAInD;;OAEG;oBACa,cAAc,KAAG,OAAO,CAAC,gBAAgB,CAAC;IAI1D;;OAEG;qBACc,YAAY,KAAG,OAAO,CAAC,gBAAgB,CAAC;CAGzD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,KAAK;IACjB;;OAEG;mBACY,aAAa,KAAG,OAAO,CAAC,eAAe,CAAC;IAIvD;;OAEG;kBACW,YAAY,KAAG,OAAO,CAAC,aAAa,CAAC;CAGnD,CAAA"}
|
|
@@ -65,14 +65,16 @@ export declare function useContrastMode(): NotionContrastMode;
|
|
|
65
65
|
*/
|
|
66
66
|
export declare function useCurrentUser(): NotionUser;
|
|
67
67
|
/**
|
|
68
|
-
* Returns the
|
|
69
|
-
* data source
|
|
68
|
+
* Returns the manifest that the block declared and the host provided during initialization.
|
|
69
|
+
* It lists each semantic data source key with its declared name, description, icon, and
|
|
70
|
+
* property definitions. Use this hook to list keys when the UI supports multiple data sources,
|
|
71
|
+
* such as in a data source selector.
|
|
70
72
|
*
|
|
71
73
|
* Throws if called before `initCustomBlock` has resolved.
|
|
72
74
|
*
|
|
73
|
-
*
|
|
74
|
-
* `useDataSource(key)`
|
|
75
|
-
*
|
|
75
|
+
* The manifest does not include the concrete Notion data source IDs mapped to those keys or
|
|
76
|
+
* any row data. Use `useDataSource(key)` with a declared key to read rows and access the
|
|
77
|
+
* resolved property IDs and schemas.
|
|
76
78
|
*/
|
|
77
79
|
export declare function useManifest(): CustomBlockManifest;
|
|
78
80
|
//# sourceMappingURL=useRuntimeState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRuntimeState.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/react/useRuntimeState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAA;AACtF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAA;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAA;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAA;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gDAAgD,CAAA;AAIhF;;;;;;;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;;;;;;;;GAQG;AACH,wBAAgB,eAAe,IAAI,kBAAkB,CAKpD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,IAAI,UAAU,CAE3C;AAED
|
|
1
|
+
{"version":3,"file":"useRuntimeState.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/react/useRuntimeState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAA;AACtF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAA;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAA;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAA;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gDAAgD,CAAA;AAIhF;;;;;;;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;;;;;;;;GAQG;AACH,wBAAgB,eAAe,IAAI,kBAAkB,CAKpD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,IAAI,UAAU,CAE3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,IAAI,mBAAmB,CAEjD"}
|
|
@@ -72,14 +72,16 @@ export function useCurrentUser() {
|
|
|
72
72
|
return useSyncExternalStore(customBlock.subscribe, customBlock.getCurrentUser);
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
|
-
* Returns the
|
|
76
|
-
* data source
|
|
75
|
+
* Returns the manifest that the block declared and the host provided during initialization.
|
|
76
|
+
* It lists each semantic data source key with its declared name, description, icon, and
|
|
77
|
+
* property definitions. Use this hook to list keys when the UI supports multiple data sources,
|
|
78
|
+
* such as in a data source selector.
|
|
77
79
|
*
|
|
78
80
|
* Throws if called before `initCustomBlock` has resolved.
|
|
79
81
|
*
|
|
80
|
-
*
|
|
81
|
-
* `useDataSource(key)`
|
|
82
|
-
*
|
|
82
|
+
* The manifest does not include the concrete Notion data source IDs mapped to those keys or
|
|
83
|
+
* any row data. Use `useDataSource(key)` with a declared key to read rows and access the
|
|
84
|
+
* resolved property IDs and schemas.
|
|
83
85
|
*/
|
|
84
86
|
export function useManifest() {
|
|
85
87
|
return useSyncExternalStore(customBlock.subscribe, customBlock.getManifest);
|
package/dist/version.js
CHANGED
package/docs/data-sources.md
CHANGED
|
@@ -6,7 +6,7 @@ The mapping from those semantic keys to concrete Notion data sources is stored o
|
|
|
6
6
|
|
|
7
7
|
Use `ManifestDataSource`, `ManifestProperty`, and `ManifestIcon` when code needs the corresponding definition metadata types.
|
|
8
8
|
|
|
9
|
-
At runtime, your code references the semantic key and the SDK handles the lookup for you. Use `useDataSource(key)` for the rows themselves (it also exposes the resolved schema), and `useManifest()` when
|
|
9
|
+
At runtime, your code references the semantic key and the SDK handles the lookup for you. Use `useDataSource(key)` for the rows themselves (it also exposes the resolved schema), and use `useManifest()` when the UI must enumerate declared data sources, such as a dynamic key switcher. For non-React renderers, `customBlock.getManifest()` exposes the same manifest, but row querying is currently only exposed through the React `useDataSource` hook.
|
|
10
10
|
|
|
11
11
|
## Pages within a data source
|
|
12
12
|
|
|
@@ -66,14 +66,14 @@ Query failures follow the SDK's [error-handling contract](./errors.md).
|
|
|
66
66
|
function useManifest(): CustomBlockManifest;
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
Returns the authoritative block manifest received from the host during initialization, including the semantic data source keys plus their declared `name`, `description`, and property declarations.
|
|
69
|
+
Returns the authoritative block manifest received from the host during initialization, including the semantic data source keys plus their declared `name`, `description`, and property declarations. Most blocks should query a declared key directly:
|
|
70
70
|
|
|
71
71
|
```tsx
|
|
72
|
-
const
|
|
73
|
-
const keys = Object.keys(manifest.dataSources);
|
|
74
|
-
const activeKey = keys[0] ?? "default";
|
|
72
|
+
const query = useDataSource("tasks");
|
|
75
73
|
```
|
|
76
74
|
|
|
75
|
+
Use `useManifest()` when the UI must enumerate declarations, such as a switcher that supports multiple data sources.
|
|
76
|
+
|
|
77
77
|
This API throws if called before initialization. This does not include host-resolved bindings nor does it include any actual data rows.
|
|
78
78
|
|
|
79
79
|
### `customBlock.getManifest()`
|
package/package.json
CHANGED
|
@@ -8,11 +8,6 @@ import { notionPagePropertyValueSchema } from "@notionhq/custom-blocks-protocol/
|
|
|
8
8
|
import * as v from "valibot"
|
|
9
9
|
import type { NotionPagePropertyInputMap } from "../../types.js"
|
|
10
10
|
|
|
11
|
-
export type {
|
|
12
|
-
CustomBlockPropertyErrorCode,
|
|
13
|
-
CustomBlockPropertyErrorInfo,
|
|
14
|
-
} from "@notionhq/custom-blocks-protocol/dataSources/errors.js"
|
|
15
|
-
|
|
16
11
|
export type PropertyWriteMapResolutionResult =
|
|
17
12
|
| { status: "success"; properties: NotionPagePropertyWriteMap }
|
|
18
13
|
| { status: "error"; error: CustomBlockPropertyErrorInfo }
|
|
@@ -20,8 +20,6 @@ import {
|
|
|
20
20
|
import type { ManifestLoadResult } from "./loadManifest.js"
|
|
21
21
|
import { type MessageLogEntry, SandboxBridge } from "./SandboxBridge.js"
|
|
22
22
|
|
|
23
|
-
export type { MessageLogEntry }
|
|
24
|
-
|
|
25
23
|
let bridge: SandboxBridge | undefined
|
|
26
24
|
|
|
27
25
|
function getBridge(): SandboxBridge {
|
|
@@ -89,14 +89,16 @@ export function useCurrentUser(): NotionUser {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
|
-
* Returns the
|
|
93
|
-
* data source
|
|
92
|
+
* Returns the manifest that the block declared and the host provided during initialization.
|
|
93
|
+
* It lists each semantic data source key with its declared name, description, icon, and
|
|
94
|
+
* property definitions. Use this hook to list keys when the UI supports multiple data sources,
|
|
95
|
+
* such as in a data source selector.
|
|
94
96
|
*
|
|
95
97
|
* Throws if called before `initCustomBlock` has resolved.
|
|
96
98
|
*
|
|
97
|
-
*
|
|
98
|
-
* `useDataSource(key)`
|
|
99
|
-
*
|
|
99
|
+
* The manifest does not include the concrete Notion data source IDs mapped to those keys or
|
|
100
|
+
* any row data. Use `useDataSource(key)` with a declared key to read rows and access the
|
|
101
|
+
* resolved property IDs and schemas.
|
|
100
102
|
*/
|
|
101
103
|
export function useManifest(): CustomBlockManifest {
|
|
102
104
|
return useSyncExternalStore(customBlock.subscribe, customBlock.getManifest)
|