@notionhq/custom-blocks 0.1.40 → 0.1.42
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 +40 -18
- package/dist/bridge/hostState.d.ts.map +1 -1
- package/dist/bridge/hostState.js +2 -0
- package/dist/protocol/dataSources/dataSourcePage.d.ts +4 -0
- package/dist/protocol/dataSources/dataSourcePage.js +5 -0
- package/dist/protocol/messages/createPageResult.d.ts +1 -0
- package/dist/protocol/messages/getPage.d.ts +1 -0
- package/dist/protocol/messages/hostToSandbox.d.ts +5 -0
- package/dist/protocol/messages/queryDataSourceResult.d.ts +2 -0
- package/dist/protocol/messages/updatePageResult.d.ts +1 -0
- package/dist/protocol/pages/page.d.ts +3 -0
- package/dist/protocol/pages/page.js +4 -0
- package/dist/react/NotionCustomBlock.js +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/block-location.md +2 -2
- package/docs/data-sources.md +5 -7
- package/docs/deployment.md +3 -1
- package/docs/pages.md +14 -2
- package/package.json +1 -1
- package/src/bridge/hostState.ts +2 -0
- package/src/react/NotionCustomBlock.tsx +1 -1
- package/src/types.ts +5 -0
package/README.md
CHANGED
|
@@ -5,7 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
SDK for building Notion custom blocks.
|
|
7
7
|
|
|
8
|
-
A custom block runs
|
|
8
|
+
A custom block runs in a sandboxed `<iframe>` inside Notion. It has no direct
|
|
9
|
+
access to the internet. A local `postMessage` bridge connects the block to
|
|
10
|
+
Notion.
|
|
11
|
+
|
|
12
|
+
This package provides the sandbox side of the bridge. It exports a
|
|
13
|
+
framework-neutral TypeScript API and typed React hooks.
|
|
9
14
|
|
|
10
15
|
## Bundle tooling
|
|
11
16
|
|
|
@@ -14,17 +19,18 @@ Node build tools can import `build` and `upload` from
|
|
|
14
19
|
|
|
15
20
|
## Install
|
|
16
21
|
|
|
17
|
-
Create a worker project with `ntn workers new --template custom
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
`@notionhq/custom-blocks/react
|
|
22
|
+
Create a worker project with `ntn workers new --template custom`. Use the
|
|
23
|
+
dependencies and entrypoint that the Notion CLI generates.
|
|
24
|
+
|
|
25
|
+
React is optional. Blocks that import `@notionhq/custom-blocks/react` need
|
|
26
|
+
`react` and `react-dom`. This repository's fixtures use the workspace SDK.
|
|
21
27
|
|
|
22
|
-
For local preview, run `ntn customblocks dev` from the worker project
|
|
23
|
-
open `http://localhost:9873`. Install
|
|
28
|
+
For local preview, run `ntn workers customblocks dev` from the worker project.
|
|
29
|
+
Then open `http://localhost:9873`. Install
|
|
24
30
|
[`@notionhq/custom-blocks-dev-shell`](https://www.npmjs.com/package/@notionhq/custom-blocks-dev-shell)
|
|
25
31
|
as a devDependency to pin the shell and get its reference docs in
|
|
26
|
-
`node_modules
|
|
27
|
-
serving
|
|
32
|
+
`node_modules`. See [`docs/deployment.md`](./docs/deployment.md) for local
|
|
33
|
+
serving details.
|
|
28
34
|
|
|
29
35
|
## Quick start
|
|
30
36
|
|
|
@@ -43,7 +49,7 @@ worker.customBlock("hello", {
|
|
|
43
49
|
});
|
|
44
50
|
```
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
Wrap your React app in `<NotionCustomBlock>` at the block's entry point:
|
|
47
53
|
|
|
48
54
|
```tsx
|
|
49
55
|
// blocks/hello/src/index.tsx
|
|
@@ -52,10 +58,14 @@ import {
|
|
|
52
58
|
NotionCustomBlock,
|
|
53
59
|
NotionTokenScope,
|
|
54
60
|
} from "@notionhq/custom-blocks/react";
|
|
55
|
-
import
|
|
61
|
+
import { createRoot } from "react-dom/client";
|
|
56
62
|
import { App } from "./App";
|
|
63
|
+
import "./style.css";
|
|
57
64
|
|
|
58
|
-
|
|
65
|
+
const root = document.getElementById("root");
|
|
66
|
+
if (!root) throw new Error("The root element is missing.");
|
|
67
|
+
|
|
68
|
+
createRoot(root).render(
|
|
59
69
|
<NotionCustomBlock>
|
|
60
70
|
<NotionTokenScope>
|
|
61
71
|
<App />
|
|
@@ -76,6 +86,8 @@ export function App() {
|
|
|
76
86
|
}
|
|
77
87
|
```
|
|
78
88
|
|
|
89
|
+
Save these styles in `blocks/hello/src/style.css`:
|
|
90
|
+
|
|
79
91
|
```css
|
|
80
92
|
.app {
|
|
81
93
|
color: var(--content-primary);
|
|
@@ -86,24 +98,34 @@ export function App() {
|
|
|
86
98
|
}
|
|
87
99
|
```
|
|
88
100
|
|
|
89
|
-
`<NotionCustomBlock>`
|
|
101
|
+
`<NotionCustomBlock>` connects the SDK to the host and waits for host state before rendering its children.
|
|
102
|
+
It reports the initial content height so the host can size the iframe before displaying it.
|
|
103
|
+
It also reports later height changes automatically.
|
|
90
104
|
|
|
91
105
|
## Notion design tokens
|
|
92
106
|
|
|
93
|
-
The optional `@notionhq/custom-blocks/nds.css` stylesheet provides
|
|
107
|
+
The optional `@notionhq/custom-blocks/nds.css` stylesheet provides Notion CSS variables for matching Notion's UI.
|
|
108
|
+
These variables cover colors, spacing, typography, and borders.
|
|
109
|
+
Import the stylesheet once. Place components that use the variables inside `<NotionTokenScope>`, as shown above.
|
|
94
110
|
|
|
95
|
-
`<NotionTokenScope>` applies the display and contrast modes
|
|
111
|
+
`<NotionTokenScope>` applies the host's display and contrast modes to these variables.
|
|
112
|
+
Hosts that omit a contrast mode use standard contrast.
|
|
96
113
|
|
|
97
114
|
`NotionTokenScopeProps` has one required `children` prop.
|
|
98
115
|
|
|
99
|
-
The
|
|
116
|
+
The CSS variables apply within the scope, not globally.
|
|
117
|
+
Place portal containers inside `<NotionTokenScope>`, or wrap the portal content in another `<NotionTokenScope>`.
|
|
118
|
+
Framework-neutral renderers can read the current appearance with `customBlock.getTheme()` and `customBlock.getContrastMode()`.
|
|
119
|
+
See [Block location and appearance](./docs/block-location.md).
|
|
100
120
|
|
|
101
121
|
## Reference
|
|
102
122
|
|
|
103
|
-
|
|
123
|
+
Each page covers one API category. Import framework-neutral APIs from
|
|
124
|
+
`@notionhq/custom-blocks`. Import React hooks and components from
|
|
125
|
+
`@notionhq/custom-blocks/react`.
|
|
104
126
|
|
|
105
127
|
- [`docs/lifecycle.md`](./docs/lifecycle.md) — `<NotionCustomBlock>`, `useCustomBlockInit`, `initCustomBlock`, `NotInIframeError`, `useCustomBlockAutoResize`. The handshake, the React wrapper, sizing.
|
|
106
|
-
- [`docs/block-location.md`](./docs/block-location.md) — `useBlockId`, `useParent`, `usePage`, `useTheme`, and `
|
|
128
|
+
- [`docs/block-location.md`](./docs/block-location.md) — `useBlockId`, `useParent`, `usePage`, `useTheme`, `useContrastMode`, `NotionTokenScope`, and `NotionTokenScopeProps`. Where the block sits and how to read the host's appearance.
|
|
107
129
|
- [`docs/data-sources.md`](./docs/data-sources.md) — `useDataSource`, `useManifest`, `customBlock.getManifest`, the row, property, and date-value types, plus a worked example.
|
|
108
130
|
- [`docs/pages.md`](./docs/pages.md) — `pages.create / get / update / delete`, parent variants (including the recommended `data_source_key`), property input shapes.
|
|
109
131
|
- [`docs/users.md`](./docs/users.md) — `users.list / get`, the `NotionUser` shape, paging.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostState.d.ts","sourceRoot":"","sources":["../../src/bridge/hostState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAA;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gEAAgE,CAAA;AAEhH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gEAAgE,CAAA;AAC1G,OAAO,KAAK,EACX,aAAa,EACb,YAAY,EACZ,MAAM,yCAAyC,CAAA;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AACvF,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,oEAAoE,CAAA;AAC7H,OAAO,KAAK,E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46
|
return {
|
|
47
47
|
id: entry.id,
|
|
48
|
+
is_archived: entry.is_archived,
|
|
49
|
+
in_trash: entry.in_trash,
|
|
48
50
|
propertiesById: entry.propertiesById,
|
|
49
51
|
propertiesByKey,
|
|
50
52
|
update: args => updateDataSourcePage({
|
|
@@ -6,6 +6,10 @@ import * as v from "valibot";
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const notionDataSourcePageBridgeSchema: v.ObjectSchema<{
|
|
8
8
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
9
|
+
/** Whether the page or an ancestor is archived. */
|
|
10
|
+
readonly is_archived: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
11
|
+
/** Whether the page or an ancestor is in Trash. */
|
|
12
|
+
readonly in_trash: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
9
13
|
readonly propertiesById: v.RecordSchema<v.StringSchema<undefined>, v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.VariantSchema<"type", [v.ObjectSchema<{
|
|
10
14
|
readonly type: v.LiteralSchema<"date", undefined>;
|
|
11
15
|
readonly start_date: v.StringSchema<undefined>;
|
|
@@ -8,5 +8,10 @@ import { notionDataSourceValueSchema } from "./dataSourceValue.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export const notionDataSourcePageBridgeSchema = v.object({
|
|
10
10
|
id: notionPageIdSchema,
|
|
11
|
+
// TODO(custom-blocks): Require is_archived and in_trash in bridge protocol v4.
|
|
12
|
+
/** Whether the page or an ancestor is archived. */
|
|
13
|
+
is_archived: v.optional(v.boolean()),
|
|
14
|
+
/** Whether the page or an ancestor is in Trash. */
|
|
15
|
+
in_trash: v.optional(v.boolean()),
|
|
11
16
|
propertiesById: v.record(v.string(), v.optional(notionDataSourceValueSchema)),
|
|
12
17
|
});
|
|
@@ -200,6 +200,7 @@ export declare const createPageResultMessageSchema: v.VariantSchema<"status", [v
|
|
|
200
200
|
}, undefined>], undefined>, undefined>;
|
|
201
201
|
readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
202
202
|
readonly public_url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
203
|
+
readonly is_archived: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
203
204
|
readonly in_trash: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
204
205
|
}, undefined>;
|
|
205
206
|
}, undefined>, v.ObjectSchema<{
|
|
@@ -205,6 +205,7 @@ export declare const getPageResultMessageSchema: v.VariantSchema<"status", [v.Ob
|
|
|
205
205
|
}, undefined>], undefined>, undefined>;
|
|
206
206
|
readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
207
207
|
readonly public_url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
208
|
+
readonly is_archived: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
208
209
|
readonly in_trash: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
209
210
|
}, undefined>;
|
|
210
211
|
}, undefined>, v.ObjectSchema<{
|
|
@@ -449,6 +449,8 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
449
449
|
readonly status: v.LiteralSchema<"success", undefined>;
|
|
450
450
|
readonly items: v.ArraySchema<v.ObjectSchema<{
|
|
451
451
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
452
|
+
readonly is_archived: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
453
|
+
readonly in_trash: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
452
454
|
readonly propertiesById: v.RecordSchema<v.StringSchema<undefined>, v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.VariantSchema<"type", [v.ObjectSchema<{
|
|
453
455
|
readonly type: v.LiteralSchema<"date", undefined>;
|
|
454
456
|
readonly start_date: v.StringSchema<undefined>;
|
|
@@ -709,6 +711,7 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
709
711
|
}, undefined>], undefined>, undefined>;
|
|
710
712
|
readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
711
713
|
readonly public_url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
714
|
+
readonly is_archived: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
712
715
|
readonly in_trash: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
713
716
|
}, undefined>;
|
|
714
717
|
}, undefined>, v.ObjectSchema<{
|
|
@@ -908,6 +911,7 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
908
911
|
}, undefined>], undefined>, undefined>;
|
|
909
912
|
readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
910
913
|
readonly public_url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
914
|
+
readonly is_archived: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
911
915
|
readonly in_trash: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
912
916
|
}, undefined>;
|
|
913
917
|
}, undefined>, v.ObjectSchema<{
|
|
@@ -1160,6 +1164,7 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
1160
1164
|
}, undefined>], undefined>, undefined>;
|
|
1161
1165
|
readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1162
1166
|
readonly public_url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1167
|
+
readonly is_archived: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
1163
1168
|
readonly in_trash: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
1164
1169
|
}, undefined>;
|
|
1165
1170
|
}, undefined>, v.ObjectSchema<{
|
|
@@ -17,6 +17,8 @@ export declare const queryDataSourceResultMessageSchema: v.VariantSchema<"status
|
|
|
17
17
|
readonly status: v.LiteralSchema<"success", undefined>;
|
|
18
18
|
readonly items: v.ArraySchema<v.ObjectSchema<{
|
|
19
19
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
20
|
+
readonly is_archived: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
21
|
+
readonly in_trash: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
20
22
|
readonly propertiesById: v.RecordSchema<v.StringSchema<undefined>, v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.VariantSchema<"type", [v.ObjectSchema<{
|
|
21
23
|
readonly type: v.LiteralSchema<"date", undefined>;
|
|
22
24
|
readonly start_date: v.StringSchema<undefined>;
|
|
@@ -199,6 +199,7 @@ export declare const updatePageResultMessageSchema: v.VariantSchema<"status", [v
|
|
|
199
199
|
}, undefined>], undefined>, undefined>;
|
|
200
200
|
readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
201
201
|
readonly public_url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
202
|
+
readonly is_archived: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
202
203
|
readonly in_trash: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
203
204
|
}, undefined>;
|
|
204
205
|
}, undefined>, v.ObjectSchema<{
|
|
@@ -595,6 +595,9 @@ export declare const notionPageSchema: v.ObjectSchema<{
|
|
|
595
595
|
}, undefined>], undefined>, undefined>;
|
|
596
596
|
readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
597
597
|
readonly public_url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
598
|
+
/** Whether the page or an ancestor is archived. */
|
|
599
|
+
readonly is_archived: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
600
|
+
/** Whether the page or an ancestor is in Trash. */
|
|
598
601
|
readonly in_trash: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
599
602
|
}, undefined>;
|
|
600
603
|
export type NotionPage = v.InferOutput<typeof notionPageSchema>;
|
|
@@ -207,5 +207,9 @@ export const notionPageSchema = v.object({
|
|
|
207
207
|
cover: v.optional(notionPageCoverSchema),
|
|
208
208
|
url: v.optional(v.string()),
|
|
209
209
|
public_url: v.optional(v.string()),
|
|
210
|
+
// TODO(custom-blocks): Require is_archived and in_trash in bridge protocol v4.
|
|
211
|
+
/** Whether the page or an ancestor is archived. */
|
|
212
|
+
is_archived: v.optional(v.boolean()),
|
|
213
|
+
/** Whether the page or an ancestor is in Trash. */
|
|
210
214
|
in_trash: v.optional(v.boolean()),
|
|
211
215
|
});
|
|
@@ -75,7 +75,7 @@ export function NotionCustomBlock({ children, timeoutMs, fallback = null, errorF
|
|
|
75
75
|
if (host.status !== "initialized") {
|
|
76
76
|
return _jsx(_Fragment, { children: fallback });
|
|
77
77
|
}
|
|
78
|
-
return (_jsxs(_Fragment, { children: [_jsx("div", { role: "status", className: "custom-blocks-standalone-banner", children: "Host not detected \u2014 running in standalone preview. Try `ntn customblocks dev` to run the block in a local development environment." }), children] }));
|
|
78
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { role: "status", className: "custom-blocks-standalone-banner", children: "Host not detected \u2014 running in standalone preview. Try `ntn workers customblocks dev` to run the block in a local development environment." }), children] }));
|
|
79
79
|
}
|
|
80
80
|
if (!init.isLoaded) {
|
|
81
81
|
return _jsx(_Fragment, { children: fallback });
|
package/dist/types.d.ts
CHANGED
|
@@ -36,6 +36,10 @@ export type NotionPagePropertyInputMap = {
|
|
|
36
36
|
*/
|
|
37
37
|
export type NotionDataSourcePage = {
|
|
38
38
|
id: NotionPageId;
|
|
39
|
+
/** Whether the page or an ancestor is archived. */
|
|
40
|
+
is_archived?: boolean;
|
|
41
|
+
/** Whether the page or an ancestor is in Trash. */
|
|
42
|
+
in_trash?: boolean;
|
|
39
43
|
/**
|
|
40
44
|
* Keyed mapping of raw property IDs to their value. Includes all properties on the data source,
|
|
41
45
|
* including the four built-ins (`created_time`, `last_edited_time`, `created_by`,
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4DAA4D,CAAA;AACxG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iEAAiE,CAAA;AAC5G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gEAAgE,CAAA;AAC1G,OAAO,KAAK,EACX,kBAAkB,EAClB,YAAY,EACZ,MAAM,yCAAyC,CAAA;AAChD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAA;AAC9F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yDAAyD,CAAA;AACvG,OAAO,KAAK,EACX,uBAAuB,EACvB,8BAA8B,EAC9B,MAAM,+DAA+D,CAAA;AACtE,OAAO,KAAK,EACX,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,sDAAsD,CAAA;AAC7D,OAAO,KAAK,EACX,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,sDAAsD,CAAA;AAC7D,OAAO,KAAK,EACX,6BAA6B,EAC7B,gBAAgB,EAChB,sBAAsB,EACtB,MAAM,wDAAwD,CAAA;AAC/D,OAAO,KAAK,EACX,iCAAiC,EACjC,iCAAiC,EACjC,6BAA6B,EAC7B,+BAA+B,EAC/B,+BAA+B,EAC/B,6BAA6B,EAC7B,MAAM,8DAA8D,CAAA;AACrE,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,oEAAoE,CAAA;AAC7H,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,C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AAW,CAAC,CAAA;AAE1E;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,cAAc,CAAA;AAE5C;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,oBAAoB,CAC/C,oBAAoB,EACpB,2BAA2B,CAC3B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,CAClD,uBAAuB,EACvB,8BAA8B,CAC9B,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,WAAW,CAAC,CAAA;AAExE;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,aAAa,CAAA;AAE1C,MAAM,MAAM,eAAe,GAAG,oBAAoB,CACjD,sBAAsB,EACtB,6BAA6B,CAC7B,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,oBAAoB,CAC/C,oBAAoB,EACpB,2BAA2B,CAC3B,CAAA"}
|
package/dist/version.js
CHANGED
package/docs/block-location.md
CHANGED
|
@@ -118,7 +118,7 @@ const theme = customBlock.getTheme();
|
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
```tsx
|
|
121
|
-
import { usePage, useTheme } from "@notionhq/custom-blocks";
|
|
121
|
+
import { usePage, useTheme } from "@notionhq/custom-blocks/react";
|
|
122
122
|
|
|
123
123
|
export function Header() {
|
|
124
124
|
const page = usePage();
|
|
@@ -137,4 +137,4 @@ function useContrastMode(): NotionContrastMode; // "standard" | "high"
|
|
|
137
137
|
|
|
138
138
|
For non-React renderers, use `customBlock.getContrastMode()` after `initCustomBlock()` resolves.
|
|
139
139
|
|
|
140
|
-
For React apps, `<NotionTokenScope>` applies both appearance values to the bundled Notion
|
|
140
|
+
For React apps, `<NotionTokenScope>` applies both appearance values to the bundled Notion CSS variables automatically.
|
package/docs/data-sources.md
CHANGED
|
@@ -137,9 +137,10 @@ renderManifest(customBlock.getManifest());
|
|
|
137
137
|
|
|
138
138
|
## Example: querying a data source
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
This example calls `useDataSource` with a declared key. It validates each row’s values before rendering:
|
|
141
141
|
|
|
142
142
|
```tsx
|
|
143
|
+
import { useState } from "react";
|
|
143
144
|
import type { NotionDataSourcePage } from "@notionhq/custom-blocks";
|
|
144
145
|
import { useDataSource } from "@notionhq/custom-blocks/react";
|
|
145
146
|
|
|
@@ -163,10 +164,7 @@ export function ScoreList() {
|
|
|
163
164
|
const displayItems = items.filter(isComplete);
|
|
164
165
|
if (displayItems.length === 0) {
|
|
165
166
|
return (
|
|
166
|
-
<div>
|
|
167
|
-
Map a data source with key <code>{KEY}</code> exposing <code>name</code>{" "}
|
|
168
|
-
(text) and <code>score</code> (number).
|
|
169
|
-
</div>
|
|
167
|
+
<div>No rows have both a text name and a finite score.</div>
|
|
170
168
|
);
|
|
171
169
|
}
|
|
172
170
|
|
|
@@ -198,9 +196,9 @@ export function ScoreList() {
|
|
|
198
196
|
|
|
199
197
|
### Rows & values
|
|
200
198
|
|
|
201
|
-
- `NotionDataSource` — a resolved data source: semantic key, `collectionSchema`, `propertyIdsByKey`, `propertySchemasById`.
|
|
199
|
+
- `NotionDataSource` — a resolved data source: semantic key, optional `collectionSchema`, `propertyIdsByKey`, and `propertySchemasById`.
|
|
202
200
|
- `NotionDataSourcePage` — a single row exposed to app code: `{ id, propertiesById, propertiesByKey, update }`.
|
|
203
|
-
- `NotionDataSourceValue` — the
|
|
201
|
+
- `NotionDataSourceValue` — the value union for `propertiesById` and `propertiesByKey`.
|
|
204
202
|
- `NotionDataSourcePageUpdateArgs` / `UpdatePageResult` — arguments and result for the per-page `update` helper.
|
|
205
203
|
- `NotionDataSourcePageUpdateInput` — deprecated alias for `NotionDataSourcePageUpdateArgs`.
|
|
206
204
|
- `NotionDataSourcePageUpdateResult` — deprecated alias for `UpdatePageResult`.
|
package/docs/deployment.md
CHANGED
|
@@ -7,9 +7,11 @@ A custom block manifest describes the data sources a block requires, including t
|
|
|
7
7
|
- **Deployed** — deploying persists the manifest on the block's definition record in Notion. The host reads it from there and sends it to the SDK during initialization.
|
|
8
8
|
- **Local development** — the dev shell extracts the same worker declaration at runtime and serves the selected block's manifest dynamically at `/manifest`.
|
|
9
9
|
|
|
10
|
+
Notion reconciles custom block definitions by their Worker capability keys during deployment.
|
|
11
|
+
|
|
10
12
|
## Local development
|
|
11
13
|
|
|
12
|
-
Run `ntn customblocks dev` from a worker. It builds the worker, extracts its custom block declarations, starts one localhost Vite server per block, and renders them in the mock host at http://localhost:9873.
|
|
14
|
+
Run `ntn workers customblocks dev` from a worker. It builds the worker, extracts its custom block declarations, starts one localhost Vite server per block, and renders them in the mock host at http://localhost:9873.
|
|
13
15
|
|
|
14
16
|
At startup, the SDK fetches the page-relative `manifest` path only when the bundle's hostname is exactly `localhost`, then forwards the response in `connect`. On every other hostname, the SDK skips this fetch and relies on the host-provided manifest from `init`.
|
|
15
17
|
|
package/docs/pages.md
CHANGED
|
@@ -83,6 +83,18 @@ console.log(page.properties);
|
|
|
83
83
|
|
|
84
84
|
`page` mirrors Notion's public API shape, with `id`, `parent`, `properties`, optional `icon` / `cover`, etc. — see `NotionPage` in the types list below.
|
|
85
85
|
|
|
86
|
+
### Archive
|
|
87
|
+
|
|
88
|
+
Archiving keeps content you no longer actively use without deleting it. [Learn about Archive](https://www.notion.com/help/archive-pages).
|
|
89
|
+
|
|
90
|
+
Read `is_archived` on a page or data source row. It is `true` when the page or an ancestor is archived.
|
|
91
|
+
|
|
92
|
+
### Trash
|
|
93
|
+
|
|
94
|
+
Pages in Trash are scheduled for permanent deletion. By default, Notion permanently deletes them 30 days after they enter Trash, unless you restore them first. Enterprise workspaces can configure a different retention period. [Learn about Trash retention](https://www.notion.com/help/custom-data-retention-settings).
|
|
95
|
+
|
|
96
|
+
Read `in_trash` on a page or data source row. It is `true` when the page or an ancestor is in Trash.
|
|
97
|
+
|
|
86
98
|
## Updating pages
|
|
87
99
|
|
|
88
100
|
`pages.update` writes back to a page. The optional fields (`properties`, `icon`, `cover`, `archived`) are independent — supply only what you want to change:
|
|
@@ -107,13 +119,13 @@ If you call `pages.update` with no fields to change, it short-circuits and resol
|
|
|
107
119
|
|
|
108
120
|
## Deleting (archiving) pages
|
|
109
121
|
|
|
110
|
-
`pages.delete(pageId)`
|
|
122
|
+
`pages.delete(pageId)` archives the page. It does not move the page to Trash.
|
|
111
123
|
|
|
112
124
|
```ts
|
|
113
125
|
await pages.delete(pageId);
|
|
114
126
|
```
|
|
115
127
|
|
|
116
|
-
To
|
|
128
|
+
To unarchive a page, call `pages.update({ pageId, archived: false })`.
|
|
117
129
|
|
|
118
130
|
## Icons, covers, and file uploads
|
|
119
131
|
|
package/package.json
CHANGED
package/src/bridge/hostState.ts
CHANGED
|
@@ -119,7 +119,7 @@ export function NotionCustomBlock({
|
|
|
119
119
|
return (
|
|
120
120
|
<>
|
|
121
121
|
<div role="status" className="custom-blocks-standalone-banner">
|
|
122
|
-
Host not detected — running in standalone preview. Try `ntn
|
|
122
|
+
Host not detected — running in standalone preview. Try `ntn workers
|
|
123
123
|
customblocks dev` to run the block in a local development environment.
|
|
124
124
|
</div>
|
|
125
125
|
{children}
|
package/src/types.ts
CHANGED
|
@@ -85,6 +85,11 @@ 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
|
+
/** Whether the page or an ancestor is archived. */
|
|
90
|
+
is_archived?: boolean
|
|
91
|
+
/** Whether the page or an ancestor is in Trash. */
|
|
92
|
+
in_trash?: boolean
|
|
88
93
|
/**
|
|
89
94
|
* Keyed mapping of raw property IDs to their value. Includes all properties on the data source,
|
|
90
95
|
* including the four built-ins (`created_time`, `last_edited_time`, `created_by`,
|