@notionhq/custom-blocks 0.2.16 → 0.2.18
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 +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/protocol/messages/createPageResult.d.ts +1 -1
- package/dist/protocol/messages/getPage.d.ts +1 -1
- package/dist/protocol/messages/hostToSandbox.d.ts +10 -4
- package/dist/protocol/messages/init.d.ts +5 -2
- package/dist/protocol/messages/openPage.d.ts +1 -1
- package/dist/protocol/messages/pageChanged.d.ts +5 -2
- package/dist/protocol/messages/updatePageResult.d.ts +1 -1
- package/dist/protocol/pages/page.d.ts +5 -2
- package/dist/protocol/pages/page.js +15 -9
- package/dist/react/standalonePreview.d.ts.map +1 -1
- package/dist/react/standalonePreview.js +5 -1
- package/dist/version.js +1 -1
- package/docs/block-location.md +24 -11
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/react/standalonePreview.ts +5 -1
package/README.md
CHANGED
|
@@ -132,6 +132,8 @@ Import React hooks and components from `@notionhq/custom-blocks/react`.
|
|
|
132
132
|
|
|
133
133
|
## Limitations
|
|
134
134
|
|
|
135
|
+
Custom blocks do not render on pages published with Notion Sites.
|
|
136
|
+
|
|
135
137
|
Custom blocks run in sandboxed iframes. A block cannot navigate the top-level page, call
|
|
136
138
|
`window.open`, or start an authentication redirect.
|
|
137
139
|
|
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type { CustomBlockListUsersErrorCode, CustomBlockListUsersErrorInfo, } fr
|
|
|
27
27
|
export type { CustomBlockOpenPageErrorCode, CustomBlockOpenPageErrorInfo, OpenPageMode, } from "./protocol/messages/openPage.js";
|
|
28
28
|
export type { CustomBlockQueryDataSourceErrorCode, CustomBlockQueryDataSourceErrorInfo, } from "./protocol/messages/queryDataSourceResult.js";
|
|
29
29
|
export type { CustomBlockUpdatePageErrorCode, CustomBlockUpdatePageErrorInfo, } from "./protocol/messages/updatePageResult.js";
|
|
30
|
-
export type { NotionPage, NotionPageCover, NotionPageIcon, NotionPagePropertyValue, NotionPagePropertyWriteMap, } from "./protocol/pages/page.js";
|
|
30
|
+
export type { CustomBlockPage, NotionPage, NotionPageCover, NotionPageIcon, NotionPagePropertyValue, NotionPagePropertyWriteMap, } from "./protocol/pages/page.js";
|
|
31
31
|
export type { NotionParent } from "./protocol/parent.js";
|
|
32
32
|
export type { NotionTheme } from "./protocol/theme.js";
|
|
33
33
|
export { pages, users } from "./bridge/sandboxClient.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAA;AACtF,YAAY,EACX,sBAAsB,EACtB,gBAAgB,GAChB,MAAM,4DAA4D,CAAA;AACnE,YAAY,EAAE,qBAAqB,EAAE,MAAM,iEAAiE,CAAA;AAC5G,YAAY,EACX,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GAClB,MAAM,2DAA2D,CAAA;AAClE,YAAY,EACX,wCAAwC,EACxC,wCAAwC,EACxC,4BAA4B,EAC5B,4BAA4B,GAC5B,MAAM,wDAAwD,CAAA;AAC/D,YAAY,EACX,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,gEAAgE,CAAA;AACvE,OAAO,EACN,2BAA2B,EAC3B,qBAAqB,GACrB,MAAM,gEAAgE,CAAA;AACvE,YAAY,EAAE,mBAAmB,EAAE,MAAM,+DAA+D,CAAA;AACxG,YAAY,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAA;AACtF,YAAY,EACX,a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D,CAAA;AAC7D,YAAY,EACX,2BAA2B,EAC3B,2BAA2B,GAC3B,MAAM,sDAAsD,CAAA;AAC7D,YAAY,EACX,kCAAkC,EAClC,kCAAkC,GAClC,MAAM,mDAAmD,CAAA;AAC1D,OAAO,EAAE,8BAA8B,EAAE,MAAM,mDAAmD,CAAA;AAClG,YAAY,EACX,6BAA6B,EAC7B,6BAA6B,GAC7B,MAAM,wDAAwD,CAAA;AAC/D,YAAY,EACX,4BAA4B,EAC5B,4BAA4B,EAC5B,YAAY,GACZ,MAAM,uDAAuD,CAAA;AAC9D,YAAY,EACX,mCAAmC,EACnC,mCAAmC,GACnC,MAAM,oEAAoE,CAAA;AAC3E,YAAY,EACX,8BAA8B,EAC9B,8BAA8B,GAC9B,MAAM,+DAA+D,CAAA;AACtE,YAAY,EACX,eAAe,EACf,UAAU,EACV,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,0BAA0B,GAC1B,MAAM,gDAAgD,CAAA;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAA;AAC9E,YAAY,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAA;AAC5E,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EACN,KAAK,sBAAsB,EAC3B,eAAe,EACf,gBAAgB,GAChB,MAAM,WAAW,CAAA;AAClB,cAAc,YAAY,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
|
|
3
3
|
export declare const customBlockCreatePageErrorCodeSchema: v.StringSchema<undefined>;
|
|
4
|
-
export type CustomBlockCreatePageErrorCode = CustomBlockErrorCode<"create_page_failed" | "invalid_page_parent" | "
|
|
4
|
+
export type CustomBlockCreatePageErrorCode = CustomBlockErrorCode<"create_page_failed" | "invalid_page_parent" | "page_unavailable" | "collection_access_failed" | "unknown_data_source_key" | "unmapped_data_source" | "unmapped_property" | "property_id_mismatch" | "duplicate_property" | "invalid_property_value">;
|
|
5
5
|
export type CustomBlockCreatePageErrorInfo = CustomBlockErrorInfo<CustomBlockCreatePageErrorCode>;
|
|
6
6
|
export declare const customBlockCreatePageErrorInfoSchema: v.ObjectSchema<{
|
|
7
7
|
readonly code: v.StringSchema<undefined>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
|
|
3
3
|
export declare const customBlockGetPageErrorCodeSchema: v.StringSchema<undefined>;
|
|
4
|
-
export type CustomBlockGetPageErrorCode = CustomBlockErrorCode<"get_page_failed" | "
|
|
4
|
+
export type CustomBlockGetPageErrorCode = CustomBlockErrorCode<"get_page_failed" | "page_unavailable">;
|
|
5
5
|
export type CustomBlockGetPageErrorInfo = CustomBlockErrorInfo<CustomBlockGetPageErrorCode>;
|
|
6
6
|
export declare const customBlockGetPageErrorInfoSchema: v.ObjectSchema<{
|
|
7
7
|
readonly code: v.StringSchema<undefined>;
|
|
@@ -27,7 +27,10 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
27
27
|
}, undefined>, v.ObjectSchema<{
|
|
28
28
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
29
29
|
}, undefined>], undefined>;
|
|
30
|
-
readonly page: v.ObjectSchema<{
|
|
30
|
+
readonly page: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
31
|
+
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
32
|
+
}, undefined>, v.ObjectSchema<{
|
|
33
|
+
readonly type: v.LiteralSchema<"page", undefined>;
|
|
31
34
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
32
35
|
readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
33
36
|
readonly type: v.LiteralSchema<"page_id", undefined>;
|
|
@@ -47,7 +50,7 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
47
50
|
}, undefined>, v.ObjectSchema<{
|
|
48
51
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
49
52
|
}, undefined>], undefined>;
|
|
50
|
-
}, undefined>;
|
|
53
|
+
}, undefined>], undefined>;
|
|
51
54
|
readonly manifest: v.ObjectSchema<{
|
|
52
55
|
readonly version: v.LiteralSchema<1, undefined>;
|
|
53
56
|
readonly dataSources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
@@ -261,7 +264,10 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
261
264
|
}, undefined>], undefined>;
|
|
262
265
|
}, undefined>, v.ObjectSchema<{
|
|
263
266
|
readonly type: v.LiteralSchema<"pageChanged", undefined>;
|
|
264
|
-
readonly page: v.ObjectSchema<{
|
|
267
|
+
readonly page: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
268
|
+
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
269
|
+
}, undefined>, v.ObjectSchema<{
|
|
270
|
+
readonly type: v.LiteralSchema<"page", undefined>;
|
|
265
271
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
266
272
|
readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
267
273
|
readonly type: v.LiteralSchema<"page_id", undefined>;
|
|
@@ -281,7 +287,7 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
281
287
|
}, undefined>, v.ObjectSchema<{
|
|
282
288
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
283
289
|
}, undefined>], undefined>;
|
|
284
|
-
}, undefined>;
|
|
290
|
+
}, undefined>], undefined>;
|
|
285
291
|
}, undefined>, v.ObjectSchema<{
|
|
286
292
|
readonly type: v.LiteralSchema<"currentUserChanged", undefined>;
|
|
287
293
|
readonly currentUser: v.ObjectSchema<{
|
|
@@ -53,7 +53,10 @@ export declare const initMessageSchema: v.VariantSchema<"status", [v.ObjectSchem
|
|
|
53
53
|
}, undefined>, v.ObjectSchema<{
|
|
54
54
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
55
55
|
}, undefined>], undefined>;
|
|
56
|
-
readonly page: v.ObjectSchema<{
|
|
56
|
+
readonly page: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
57
|
+
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
58
|
+
}, undefined>, v.ObjectSchema<{
|
|
59
|
+
readonly type: v.LiteralSchema<"page", undefined>;
|
|
57
60
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
58
61
|
readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
59
62
|
readonly type: v.LiteralSchema<"page_id", undefined>;
|
|
@@ -73,7 +76,7 @@ export declare const initMessageSchema: v.VariantSchema<"status", [v.ObjectSchem
|
|
|
73
76
|
}, undefined>, v.ObjectSchema<{
|
|
74
77
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
75
78
|
}, undefined>], undefined>;
|
|
76
|
-
}, undefined>;
|
|
79
|
+
}, undefined>], undefined>;
|
|
77
80
|
readonly manifest: v.ObjectSchema<{
|
|
78
81
|
readonly version: v.LiteralSchema<1, undefined>;
|
|
79
82
|
readonly dataSources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
@@ -3,7 +3,7 @@ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
|
|
|
3
3
|
export declare const openPageModeSchema: v.PicklistSchema<["side_peek", "center_peek"], undefined>;
|
|
4
4
|
export type OpenPageMode = v.InferOutput<typeof openPageModeSchema>;
|
|
5
5
|
export declare const customBlockOpenPageErrorCodeSchema: v.StringSchema<undefined>;
|
|
6
|
-
export type CustomBlockOpenPageErrorCode = CustomBlockErrorCode<"open_page_failed" | "
|
|
6
|
+
export type CustomBlockOpenPageErrorCode = CustomBlockErrorCode<"open_page_failed" | "page_unavailable" | "navigation_unavailable">;
|
|
7
7
|
export type CustomBlockOpenPageErrorInfo = CustomBlockErrorInfo<CustomBlockOpenPageErrorCode>;
|
|
8
8
|
export declare const customBlockOpenPageErrorInfoSchema: v.ObjectSchema<{
|
|
9
9
|
readonly code: v.StringSchema<undefined>;
|
|
@@ -4,7 +4,10 @@ import * as v from "valibot";
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const pageChangedMessageSchema: v.ObjectSchema<{
|
|
6
6
|
readonly type: v.LiteralSchema<"pageChanged", undefined>;
|
|
7
|
-
readonly page: v.ObjectSchema<{
|
|
7
|
+
readonly page: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
8
|
+
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
9
|
+
}, undefined>, v.ObjectSchema<{
|
|
10
|
+
readonly type: v.LiteralSchema<"page", undefined>;
|
|
8
11
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
9
12
|
readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
10
13
|
readonly type: v.LiteralSchema<"page_id", undefined>;
|
|
@@ -24,6 +27,6 @@ export declare const pageChangedMessageSchema: v.ObjectSchema<{
|
|
|
24
27
|
}, undefined>, v.ObjectSchema<{
|
|
25
28
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
26
29
|
}, undefined>], undefined>;
|
|
27
|
-
}, undefined>;
|
|
30
|
+
}, undefined>], undefined>;
|
|
28
31
|
}, undefined>;
|
|
29
32
|
export type PageChangedMessage = v.InferOutput<typeof pageChangedMessageSchema>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
|
|
3
3
|
export declare const customBlockUpdatePageErrorCodeSchema: v.StringSchema<undefined>;
|
|
4
|
-
export type CustomBlockUpdatePageErrorCode = CustomBlockErrorCode<"update_page_failed" | "invalid_page_update" | "
|
|
4
|
+
export type CustomBlockUpdatePageErrorCode = CustomBlockErrorCode<"update_page_failed" | "invalid_page_update" | "page_unavailable" | "collection_access_failed" | "unmapped_property" | "property_id_mismatch" | "duplicate_property" | "invalid_property_value">;
|
|
5
5
|
export type CustomBlockUpdatePageErrorInfo = CustomBlockErrorInfo<CustomBlockUpdatePageErrorCode>;
|
|
6
6
|
export declare const customBlockUpdatePageErrorInfoSchema: v.ObjectSchema<{
|
|
7
7
|
readonly code: v.StringSchema<undefined>;
|
|
@@ -8,7 +8,10 @@ import * as v from "valibot";
|
|
|
8
8
|
/**
|
|
9
9
|
* The custom block's nearest enclosing page ancestor, carried in `init.page` and `pageChanged`.
|
|
10
10
|
*/
|
|
11
|
-
export declare const customBlockPageSchema: v.ObjectSchema<{
|
|
11
|
+
export declare const customBlockPageSchema: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
12
|
+
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
13
|
+
}, undefined>, v.ObjectSchema<{
|
|
14
|
+
readonly type: v.LiteralSchema<"page", undefined>;
|
|
12
15
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
13
16
|
/**
|
|
14
17
|
* The containing page's own parent. It lets a block distinguish a freestanding page from a
|
|
@@ -33,7 +36,7 @@ export declare const customBlockPageSchema: v.ObjectSchema<{
|
|
|
33
36
|
}, undefined>, v.ObjectSchema<{
|
|
34
37
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
35
38
|
}, undefined>], undefined>;
|
|
36
|
-
}, undefined>;
|
|
39
|
+
}, undefined>], undefined>;
|
|
37
40
|
export type CustomBlockPage = v.InferOutput<typeof customBlockPageSchema>;
|
|
38
41
|
export declare const notionEmojiIconSchema: v.ObjectSchema<{
|
|
39
42
|
readonly type: v.LiteralSchema<"emoji", undefined>;
|
|
@@ -10,15 +10,21 @@ import { notionParentSchema } from "../parent.js";
|
|
|
10
10
|
/**
|
|
11
11
|
* The custom block's nearest enclosing page ancestor, carried in `init.page` and `pageChanged`.
|
|
12
12
|
*/
|
|
13
|
-
export const customBlockPageSchema = v.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
export const customBlockPageSchema = v.variant("type", [
|
|
14
|
+
/** The viewer cannot access the containing page; its ID and parent are not exposed. */
|
|
15
|
+
v.object({ type: v.literal("unavailable") }),
|
|
16
|
+
/** The viewer can access the containing page; includes its ID and parent location. */
|
|
17
|
+
v.object({
|
|
18
|
+
type: v.literal("page"),
|
|
19
|
+
id: notionPageIdSchema,
|
|
20
|
+
/**
|
|
21
|
+
* The containing page's own parent. It lets a block distinguish a freestanding page from a
|
|
22
|
+
* database row without a round trip. Not to be confused with the top-level `parent` runtime
|
|
23
|
+
* value, which is the custom block's own parent.
|
|
24
|
+
*/
|
|
25
|
+
parent: notionParentSchema,
|
|
26
|
+
}),
|
|
27
|
+
]);
|
|
22
28
|
export const notionEmojiIconSchema = v.object({
|
|
23
29
|
type: v.literal("emoji"),
|
|
24
30
|
emoji: v.string(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standalonePreview.d.ts","sourceRoot":"","sources":["../../src/react/standalonePreview.ts"],"names":[],"mappings":"AAaA,wBAAgB,0BAA0B,
|
|
1
|
+
{"version":3,"file":"standalonePreview.d.ts","sourceRoot":"","sources":["../../src/react/standalonePreview.ts"],"names":[],"mappings":"AAaA,wBAAgB,0BAA0B,SA2BzC"}
|
|
@@ -15,7 +15,11 @@ export function seedStandalonePreviewState() {
|
|
|
15
15
|
contrastMode: DEFAULT_CONTRAST_MODE,
|
|
16
16
|
blockId: previewBlockId,
|
|
17
17
|
parent: { type: "page_id", page_id: previewPageId },
|
|
18
|
-
page: {
|
|
18
|
+
page: {
|
|
19
|
+
type: "page",
|
|
20
|
+
id: previewPageId,
|
|
21
|
+
parent: { type: "workspace", workspace: true },
|
|
22
|
+
},
|
|
19
23
|
manifest: { version: 1, dataSources: {} },
|
|
20
24
|
dataSources: { bindings: {} },
|
|
21
25
|
currentUser: {
|
package/dist/version.js
CHANGED
package/docs/block-location.md
CHANGED
|
@@ -100,10 +100,14 @@ Use `getPage()`, `subscribeToPage()`, and `usePage()` to access the nearest encl
|
|
|
100
100
|
database view page. The page's parent can change even when its ID stays the same.
|
|
101
101
|
|
|
102
102
|
```ts
|
|
103
|
-
type CustomBlockPage =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
type CustomBlockPage =
|
|
104
|
+
| {
|
|
105
|
+
type: "page"
|
|
106
|
+
id: NotionPageId
|
|
107
|
+
// The containing page's own parent.
|
|
108
|
+
parent: NotionParent
|
|
109
|
+
}
|
|
110
|
+
| { type: "unavailable" } // access denied; no ID or parent
|
|
107
111
|
```
|
|
108
112
|
|
|
109
113
|
`page.parent` allows determining if the custom block is in a freestanding page or part of a
|
|
@@ -111,14 +115,19 @@ database. Don't confuse it with `useParent()`, which is the custom block's own p
|
|
|
111
115
|
|
|
112
116
|
A containing page whose parent has `type: "data_source_id"` belongs to a data source.
|
|
113
117
|
|
|
114
|
-
For anything beyond location — title, icon, properties — fetch
|
|
115
|
-
`pages.get(page.id)`.
|
|
118
|
+
For anything beyond location — title, icon, properties — fetch an accessible page through the pages
|
|
119
|
+
API: `if (page.type === "page") pages.get(page.id)`. When the containing page itself is
|
|
120
|
+
inaccessible, `customBlock.getPage()` and `usePage()` return `{ type: "unavailable" }` without an
|
|
121
|
+
ID. These location APIs read host-provided context; they do not fetch page content. In contrast,
|
|
122
|
+
`pages.get(pageId)` sends a `getPage` request to fetch a specific page and returns a success or
|
|
123
|
+
error result. An unavailable containing page does not prevent the custom block from using its
|
|
124
|
+
accessible data sources.
|
|
116
125
|
|
|
117
126
|
When the viewer cannot access the parent resource, the host returns `{ type: "unavailable" }`,
|
|
118
|
-
including on `
|
|
119
|
-
when the readable child identifies the parent. Neither the parent's ID nor its
|
|
120
|
-
unavailable parent does not prevent initialization when the block and containing
|
|
121
|
-
other initialization requirements still apply.
|
|
127
|
+
including on `page.parent` when `page.type === "page"`. This applies to every parent kind, including
|
|
128
|
+
data sources, even when the readable child identifies the parent. Neither the parent's ID nor its
|
|
129
|
+
kind is exposed. An unavailable parent does not prevent initialization when the block and containing
|
|
130
|
+
page are readable; other initialization requirements still apply.
|
|
122
131
|
|
|
123
132
|
Treat `unavailable` as unknown when branching on location: it does not establish whether the
|
|
124
133
|
containing page is a database row. A parent that is still loading is not reported as access denied.
|
|
@@ -141,7 +150,11 @@ import { usePage, useTheme } from "@notionhq/custom-blocks/react"
|
|
|
141
150
|
export function Header() {
|
|
142
151
|
const page = usePage()
|
|
143
152
|
const theme = useTheme()
|
|
144
|
-
return
|
|
153
|
+
return (
|
|
154
|
+
<header data-display-mode={theme}>
|
|
155
|
+
Page: {page.type === "page" ? page.id : "Unavailable"}
|
|
156
|
+
</header>
|
|
157
|
+
)
|
|
145
158
|
}
|
|
146
159
|
```
|
|
147
160
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -20,7 +20,11 @@ export function seedStandalonePreviewState() {
|
|
|
20
20
|
contrastMode: DEFAULT_CONTRAST_MODE,
|
|
21
21
|
blockId: previewBlockId,
|
|
22
22
|
parent: { type: "page_id", page_id: previewPageId },
|
|
23
|
-
page: {
|
|
23
|
+
page: {
|
|
24
|
+
type: "page",
|
|
25
|
+
id: previewPageId,
|
|
26
|
+
parent: { type: "workspace", workspace: true },
|
|
27
|
+
},
|
|
24
28
|
manifest: { version: 1, dataSources: {} },
|
|
25
29
|
dataSources: { bindings: {} },
|
|
26
30
|
currentUser: {
|