@notionhq/custom-blocks 0.1.45 → 0.1.47
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 +3 -4
- package/dist/bridge/SandboxBridge.d.ts +1 -1
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +3 -20
- package/dist/bridge/sandboxClient.d.ts +1 -1
- package/dist/bridge/sandboxClient.d.ts.map +1 -1
- package/dist/bridge/sandboxClient.js +2 -2
- package/dist/customBlock.d.ts +76 -3
- package/dist/customBlock.d.ts.map +1 -1
- package/dist/customBlock.js +120 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/init.d.ts +2 -14
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +7 -30
- package/dist/protocol/index.d.ts +3 -2
- package/dist/protocol/index.js +3 -2
- package/dist/protocol/messages/init.d.ts +2 -2
- package/dist/protocol/messages/isInitHandshakeMessage.d.ts +4 -0
- package/dist/protocol/messages/isInitHandshakeMessage.js +11 -0
- package/dist/protocol/{messagePayload.d.ts → messages/messagePayload.d.ts} +1 -1
- package/dist/react/NotionCustomBlock.d.ts +3 -5
- package/dist/react/NotionCustomBlock.d.ts.map +1 -1
- package/dist/react/NotionCustomBlock.js +3 -4
- package/dist/react/useCustomBlockInit.d.ts +4 -4
- package/dist/react/useCustomBlockInit.d.ts.map +1 -1
- package/dist/react/useCustomBlockInit.js +3 -4
- package/dist/react/useRuntimeState.d.ts +3 -5
- package/dist/react/useRuntimeState.d.ts.map +1 -1
- package/dist/react/useRuntimeState.js +10 -12
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/block-location.md +51 -55
- package/docs/data-sources.md +3 -3
- package/docs/errors.md +1 -1
- package/docs/lifecycle.md +60 -25
- package/docs/users.md +4 -3
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +3 -23
- package/src/bridge/sandboxClient.ts +2 -2
- package/src/customBlock.ts +139 -3
- package/src/index.ts +0 -1
- package/src/init.ts +7 -52
- package/src/react/NotionCustomBlock.tsx +4 -6
- package/src/react/useCustomBlockInit.ts +5 -12
- package/src/react/useRuntimeState.ts +25 -12
- package/src/types.ts +1 -1
- /package/dist/protocol/{incomingType.d.ts → messages/incomingType.d.ts} +0 -0
- /package/dist/protocol/{incomingType.js → messages/incomingType.js} +0 -0
- /package/dist/protocol/{messagePayload.js → messages/messagePayload.js} +0 -0
package/README.md
CHANGED
|
@@ -113,10 +113,9 @@ Hosts that omit a contrast mode use standard contrast.
|
|
|
113
113
|
|
|
114
114
|
`NotionTokenScopeProps` has one required `children` prop.
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
See [Block location and appearance](./docs/block-location.md).
|
|
116
|
+
CSS variables apply only within `<NotionTokenScope>`. Place portal containers inside that scope, or wrap the portal content in another `<NotionTokenScope>`.
|
|
117
|
+
|
|
118
|
+
Outside React, use `customBlock.getTheme()` and `customBlock.getContrastMode()` to read the current appearance, or `customBlock.subscribeToTheme()` and `customBlock.subscribeToContrastMode()` to follow changes. See [Block location and appearance](./docs/block-location.md) for details.
|
|
120
119
|
|
|
121
120
|
## Reference
|
|
122
121
|
|
|
@@ -47,7 +47,7 @@ export declare class SandboxBridge {
|
|
|
47
47
|
private logMessage;
|
|
48
48
|
getMessageLog(): readonly MessageLogEntry[];
|
|
49
49
|
subscribeToMessageLog(listener: () => void): () => boolean;
|
|
50
|
-
awaitInit(
|
|
50
|
+
awaitInit(): Promise<void>;
|
|
51
51
|
sendConnect(manifestResult: ManifestLoadResult): void;
|
|
52
52
|
private postToHost;
|
|
53
53
|
private sendToHost;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SandboxBridge.d.ts","sourceRoot":"","sources":["../../src/bridge/SandboxBridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,gBAAgB,EAEhB,MA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AG,OAAO,CAAC,gBAAgB,CAAC,CAqB5B;IAED;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CAkE/B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_CONTRAST_MODE } from "../protocol/contrast.js";
|
|
2
|
-
import { readIncomingType } from "../protocol/incomingType.js";
|
|
3
2
|
import { hostToSandboxMessageSchema, } from "../protocol/messages/hostToSandbox.js";
|
|
3
|
+
import { readIncomingType } from "../protocol/messages/incomingType.js";
|
|
4
4
|
import { CustomBlockInitializationError, initMessageSchema, } from "../protocol/messages/init.js";
|
|
5
5
|
import { CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION } from "../protocol/protocolVersion.js";
|
|
6
6
|
import * as v from "valibot";
|
|
@@ -80,25 +80,8 @@ export class SandboxBridge {
|
|
|
80
80
|
this.messageLogListeners.add(listener);
|
|
81
81
|
return () => this.messageLogListeners.delete(listener);
|
|
82
82
|
}
|
|
83
|
-
awaitInit(
|
|
84
|
-
|
|
85
|
-
return this.initMessage;
|
|
86
|
-
}
|
|
87
|
-
return new Promise((resolve, reject) => {
|
|
88
|
-
if (signal.aborted) {
|
|
89
|
-
reject(signal.reason);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const onAbort = () => reject(signal.reason);
|
|
93
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
94
|
-
this.initMessage.then(() => {
|
|
95
|
-
signal.removeEventListener("abort", onAbort);
|
|
96
|
-
resolve();
|
|
97
|
-
}, err => {
|
|
98
|
-
signal.removeEventListener("abort", onAbort);
|
|
99
|
-
reject(err);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
83
|
+
awaitInit() {
|
|
84
|
+
return this.initMessage;
|
|
102
85
|
}
|
|
103
86
|
sendConnect(manifestResult) {
|
|
104
87
|
if (typeof window === "undefined") {
|
|
@@ -7,7 +7,7 @@ import { type MessageLogEntry, type QueryDataSourceArgs } from "./SandboxBridge.
|
|
|
7
7
|
export declare const customBlockHost: {
|
|
8
8
|
start: () => void;
|
|
9
9
|
sendConnect: (manifestResult: ManifestLoadResult) => void;
|
|
10
|
-
awaitInit: (
|
|
10
|
+
awaitInit: () => Promise<void>;
|
|
11
11
|
subscribe: (listener: () => void) => () => boolean;
|
|
12
12
|
getState: () => CustomBlockHostState;
|
|
13
13
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandboxClient.d.ts","sourceRoot":"","sources":["../../src/bridge/sandboxClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AAC3E,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,cAAc,EACd,gBAAgB,EAChB,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,EACN,KAAK,eAAe,EACpB,KAAK,mBAAmB,EAExB,MAAM,oBAAoB,CAAA;AAY3B,eAAO,MAAM,eAAe;IAC3B,KAAK;IAIL,WAAW,mBAAmB,kBAAkB;IAIhD,SAAS,
|
|
1
|
+
{"version":3,"file":"sandboxClient.d.ts","sourceRoot":"","sources":["../../src/bridge/sandboxClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AAC3E,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,cAAc,EACd,gBAAgB,EAChB,MAAM,aAAa,CAAA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,eAAO,MAAM,KAAK;IACjB;;OAEG;IACH,IAAI,WAAW,aAAa,KAAG,OAAO,CAAC,eAAe,CAAC;IAIvD;;OAEG;IACH,GAAG,WAAW,YAAY,KAAG,OAAO,CAAC,aAAa,CAAC;CAGnD,CAAA"}
|
|
@@ -15,8 +15,8 @@ export const customBlockHost = {
|
|
|
15
15
|
sendConnect: (manifestResult) => {
|
|
16
16
|
getBridge().sendConnect(manifestResult);
|
|
17
17
|
},
|
|
18
|
-
awaitInit: (
|
|
19
|
-
return getBridge().awaitInit(
|
|
18
|
+
awaitInit: () => {
|
|
19
|
+
return getBridge().awaitInit();
|
|
20
20
|
},
|
|
21
21
|
subscribe: (listener) => {
|
|
22
22
|
return getBridge().subscribe(listener);
|
package/dist/customBlock.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { NotionTheme } from "./protocol/theme.js";
|
|
|
8
8
|
import type { NotionUser } from "./protocol/users/user.js";
|
|
9
9
|
import { autoResize } from "./autoResize.js";
|
|
10
10
|
import { subscribeToDataSource } from "./bridge/dataSources/subscribe.js";
|
|
11
|
+
/** @deprecated Use individual context types and getters after `initCustomBlock` resolves. */
|
|
11
12
|
export type CustomBlockState = {
|
|
12
13
|
status: "uninitialized";
|
|
13
14
|
theme: NotionTheme;
|
|
@@ -22,20 +23,91 @@ export type CustomBlockState = {
|
|
|
22
23
|
currentUser: NotionUser;
|
|
23
24
|
dataSources: NotionDataSource[];
|
|
24
25
|
};
|
|
26
|
+
type Unsubscribe = () => void;
|
|
25
27
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
+
* Read block and app context with getters, or follow changes with subscriptions.
|
|
29
|
+
* Getters throw if called before `initCustomBlock()` completes. Subscriptions
|
|
30
|
+
* can be registered before initialization and deliver the initial value once
|
|
31
|
+
* initialization completes, followed by changes to that value.
|
|
32
|
+
*
|
|
33
|
+
* Each subscription returns an unsubscribe function. Call it when the
|
|
34
|
+
* subscription is no longer needed.
|
|
28
35
|
*/
|
|
29
36
|
export declare const customBlock: {
|
|
30
|
-
|
|
37
|
+
/** @deprecated Use an individual subscription method, such as `subscribeToTheme()` or `subscribeToCurrentUser()`. */
|
|
38
|
+
subscribe(listener: () => void): Unsubscribe;
|
|
39
|
+
/** @deprecated Use an individual getter method, such as `getTheme()` or `getCurrentUser()`, after `initCustomBlock()` resolves. */
|
|
31
40
|
getState(): CustomBlockState;
|
|
41
|
+
/**
|
|
42
|
+
* Get the current user viewing the block.
|
|
43
|
+
* Throws if called before SDK initialization completes.
|
|
44
|
+
*/
|
|
32
45
|
getCurrentUser(): NotionUser;
|
|
46
|
+
/**
|
|
47
|
+
* Subscribes to the current `currentUser` and future changes.
|
|
48
|
+
* Waits for initialization before delivering the initial value.
|
|
49
|
+
*/
|
|
50
|
+
subscribeToCurrentUser(listener: (value: NotionUser) => void): Unsubscribe;
|
|
51
|
+
/**
|
|
52
|
+
* Get the host's current theme.
|
|
53
|
+
* Throws if called before SDK initialization completes.
|
|
54
|
+
*/
|
|
33
55
|
getTheme(): NotionTheme;
|
|
56
|
+
/**
|
|
57
|
+
* Subscribes to the current `theme` and future changes.
|
|
58
|
+
* Waits for initialization before delivering the initial value.
|
|
59
|
+
*/
|
|
60
|
+
subscribeToTheme(listener: (value: NotionTheme) => void): Unsubscribe;
|
|
61
|
+
/**
|
|
62
|
+
* Get the host's current contrast mode.
|
|
63
|
+
* Throws if called before SDK initialization completes.
|
|
64
|
+
*/
|
|
34
65
|
getContrastMode(): NotionContrastMode;
|
|
66
|
+
/**
|
|
67
|
+
* Subscribes to the current `contrastMode` and future changes.
|
|
68
|
+
* Waits for initialization before delivering the initial value.
|
|
69
|
+
*/
|
|
70
|
+
subscribeToContrastMode(listener: (value: NotionContrastMode) => void): Unsubscribe;
|
|
71
|
+
/**
|
|
72
|
+
* Get the custom block's ID. The ID is stable for the lifetime of the block.
|
|
73
|
+
* Throws if called before SDK initialization completes.
|
|
74
|
+
*/
|
|
35
75
|
getBlockId(): NotionBlockId;
|
|
76
|
+
/**
|
|
77
|
+
* Delivers the block ID once. The ID is stable for the lifetime of the block.
|
|
78
|
+
* Waits for initialization before delivering the initial value.
|
|
79
|
+
*/
|
|
80
|
+
subscribeToBlockId(listener: (value: NotionBlockId) => void): Unsubscribe;
|
|
81
|
+
/**
|
|
82
|
+
* Get the custom block's parent.
|
|
83
|
+
* Throws if called before SDK initialization completes.
|
|
84
|
+
*/
|
|
36
85
|
getParent(): NotionParent;
|
|
86
|
+
/**
|
|
87
|
+
* Subscribes to the current `parent` and future changes.
|
|
88
|
+
* Waits for initialization before delivering the initial value.
|
|
89
|
+
*/
|
|
90
|
+
subscribeToParent(listener: (value: NotionParent) => void): Unsubscribe;
|
|
91
|
+
/**
|
|
92
|
+
* Get the containing page and its parent.
|
|
93
|
+
* Throws if called before SDK initialization completes.
|
|
94
|
+
*/
|
|
37
95
|
getPage(): CustomBlockPage;
|
|
96
|
+
/**
|
|
97
|
+
* Subscribes to the current `page` and future changes.
|
|
98
|
+
* Waits for initialization before delivering the initial value.
|
|
99
|
+
*/
|
|
100
|
+
subscribeToPage(listener: (value: CustomBlockPage) => void): Unsubscribe;
|
|
101
|
+
/**
|
|
102
|
+
* Get the block's declared data source manifest.
|
|
103
|
+
* Throws if called before SDK initialization completes.
|
|
104
|
+
*/
|
|
38
105
|
getManifest(): CustomBlockManifest;
|
|
106
|
+
/**
|
|
107
|
+
* Subscribes to the current `manifest` and future changes.
|
|
108
|
+
* Waits for initialization before delivering the initial value.
|
|
109
|
+
*/
|
|
110
|
+
subscribeToManifest(listener: (value: CustomBlockManifest) => void): Unsubscribe;
|
|
39
111
|
autoResize: typeof autoResize;
|
|
40
112
|
/**
|
|
41
113
|
* Registers a listener that receives the current query snapshot and later updates.
|
|
@@ -43,4 +115,5 @@ export declare const customBlock: {
|
|
|
43
115
|
*/
|
|
44
116
|
subscribeToDataSource: typeof subscribeToDataSource;
|
|
45
117
|
};
|
|
118
|
+
export {};
|
|
46
119
|
//# sourceMappingURL=customBlock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customBlock.d.ts","sourceRoot":"","sources":["../src/customBlock.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,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;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"customBlock.d.ts","sourceRoot":"","sources":["../src/customBlock.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,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;AAChF,OAAO,EAAE,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EAAE,eAAe,KAAK,IAAI,GAAG,WAAW;IAIxE;;;OAGG;mBACY,mBAAmB;IAIlC;;;OAGG;kCAEQ,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,GAC5C,WAAW;;IAMd;;;OAGG;;CAEH,CAAA"}
|
package/dist/customBlock.js
CHANGED
|
@@ -1,38 +1,123 @@
|
|
|
1
1
|
import { autoResize } from "./autoResize.js";
|
|
2
2
|
import { subscribeToDataSource } from "./bridge/dataSources/subscribe.js";
|
|
3
|
+
import { notifyListener } from "./bridge/notifyListener.js";
|
|
3
4
|
import { customBlockHost } from "./bridge/sandboxClient.js";
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* Read block and app context with getters, or follow changes with subscriptions.
|
|
7
|
+
* Getters throw if called before `initCustomBlock()` completes. Subscriptions
|
|
8
|
+
* can be registered before initialization and deliver the initial value once
|
|
9
|
+
* initialization completes, followed by changes to that value.
|
|
10
|
+
*
|
|
11
|
+
* Each subscription returns an unsubscribe function. Call it when the
|
|
12
|
+
* subscription is no longer needed.
|
|
7
13
|
*/
|
|
8
14
|
export const customBlock = {
|
|
15
|
+
/** @deprecated Use an individual subscription method, such as `subscribeToTheme()` or `subscribeToCurrentUser()`. */
|
|
9
16
|
subscribe(listener) {
|
|
10
17
|
return customBlockHost.subscribe(listener);
|
|
11
18
|
},
|
|
19
|
+
/** @deprecated Use an individual getter method, such as `getTheme()` or `getCurrentUser()`, after `initCustomBlock()` resolves. */
|
|
12
20
|
getState() {
|
|
13
21
|
return toPublicState(customBlockHost.getState());
|
|
14
22
|
},
|
|
23
|
+
/**
|
|
24
|
+
* Get the current user viewing the block.
|
|
25
|
+
* Throws if called before SDK initialization completes.
|
|
26
|
+
*/
|
|
15
27
|
getCurrentUser() {
|
|
16
28
|
return getInitializedHostState("getCurrentUser").currentUser;
|
|
17
29
|
},
|
|
30
|
+
/**
|
|
31
|
+
* Subscribes to the current `currentUser` and future changes.
|
|
32
|
+
* Waits for initialization before delivering the initial value.
|
|
33
|
+
*/
|
|
34
|
+
subscribeToCurrentUser(listener) {
|
|
35
|
+
return subscribeToContext({ key: "currentUser", listener });
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* Get the host's current theme.
|
|
39
|
+
* Throws if called before SDK initialization completes.
|
|
40
|
+
*/
|
|
18
41
|
getTheme() {
|
|
19
42
|
return getInitializedHostState("getTheme").theme;
|
|
20
43
|
},
|
|
44
|
+
/**
|
|
45
|
+
* Subscribes to the current `theme` and future changes.
|
|
46
|
+
* Waits for initialization before delivering the initial value.
|
|
47
|
+
*/
|
|
48
|
+
subscribeToTheme(listener) {
|
|
49
|
+
return subscribeToContext({ key: "theme", listener });
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* Get the host's current contrast mode.
|
|
53
|
+
* Throws if called before SDK initialization completes.
|
|
54
|
+
*/
|
|
21
55
|
getContrastMode() {
|
|
22
56
|
return getInitializedHostState("getContrastMode").contrastMode;
|
|
23
57
|
},
|
|
58
|
+
/**
|
|
59
|
+
* Subscribes to the current `contrastMode` and future changes.
|
|
60
|
+
* Waits for initialization before delivering the initial value.
|
|
61
|
+
*/
|
|
62
|
+
subscribeToContrastMode(listener) {
|
|
63
|
+
return subscribeToContext({ key: "contrastMode", listener });
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Get the custom block's ID. The ID is stable for the lifetime of the block.
|
|
67
|
+
* Throws if called before SDK initialization completes.
|
|
68
|
+
*/
|
|
24
69
|
getBlockId() {
|
|
25
70
|
return getInitializedHostState("getBlockId").blockId;
|
|
26
71
|
},
|
|
72
|
+
/**
|
|
73
|
+
* Delivers the block ID once. The ID is stable for the lifetime of the block.
|
|
74
|
+
* Waits for initialization before delivering the initial value.
|
|
75
|
+
*/
|
|
76
|
+
subscribeToBlockId(listener) {
|
|
77
|
+
return subscribeToContext({ key: "blockId", listener });
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* Get the custom block's parent.
|
|
81
|
+
* Throws if called before SDK initialization completes.
|
|
82
|
+
*/
|
|
27
83
|
getParent() {
|
|
28
84
|
return getInitializedHostState("getParent").parent;
|
|
29
85
|
},
|
|
86
|
+
/**
|
|
87
|
+
* Subscribes to the current `parent` and future changes.
|
|
88
|
+
* Waits for initialization before delivering the initial value.
|
|
89
|
+
*/
|
|
90
|
+
subscribeToParent(listener) {
|
|
91
|
+
return subscribeToContext({ key: "parent", listener });
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Get the containing page and its parent.
|
|
95
|
+
* Throws if called before SDK initialization completes.
|
|
96
|
+
*/
|
|
30
97
|
getPage() {
|
|
31
98
|
return getInitializedHostState("getPage").page;
|
|
32
99
|
},
|
|
100
|
+
/**
|
|
101
|
+
* Subscribes to the current `page` and future changes.
|
|
102
|
+
* Waits for initialization before delivering the initial value.
|
|
103
|
+
*/
|
|
104
|
+
subscribeToPage(listener) {
|
|
105
|
+
return subscribeToContext({ key: "page", listener });
|
|
106
|
+
},
|
|
107
|
+
/**
|
|
108
|
+
* Get the block's declared data source manifest.
|
|
109
|
+
* Throws if called before SDK initialization completes.
|
|
110
|
+
*/
|
|
33
111
|
getManifest() {
|
|
34
112
|
return getInitializedHostState("getManifest").manifest;
|
|
35
113
|
},
|
|
114
|
+
/**
|
|
115
|
+
* Subscribes to the current `manifest` and future changes.
|
|
116
|
+
* Waits for initialization before delivering the initial value.
|
|
117
|
+
*/
|
|
118
|
+
subscribeToManifest(listener) {
|
|
119
|
+
return subscribeToContext({ key: "manifest", listener });
|
|
120
|
+
},
|
|
36
121
|
autoResize,
|
|
37
122
|
/**
|
|
38
123
|
* Registers a listener that receives the current query snapshot and later updates.
|
|
@@ -74,3 +159,36 @@ function getInitializedHostState(methodName) {
|
|
|
74
159
|
}
|
|
75
160
|
return hostState;
|
|
76
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Subscribe to one context value. Wait for initialization before delivering
|
|
164
|
+
* the initial value, then deliver updates when that value changes.
|
|
165
|
+
* Return a function that stops delivery, including before initialization.
|
|
166
|
+
*/
|
|
167
|
+
function subscribeToContext(args) {
|
|
168
|
+
const { key, listener } = args;
|
|
169
|
+
let active = true;
|
|
170
|
+
let delivered = false;
|
|
171
|
+
let previous;
|
|
172
|
+
const deliverIfChanged = () => {
|
|
173
|
+
const state = customBlockHost.getState();
|
|
174
|
+
if (!active || state.status !== "initialized") {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const next = state[key];
|
|
178
|
+
// Use referential equality to keep the implementation simple.
|
|
179
|
+
// Callbacks can receive different objects with the same contents.
|
|
180
|
+
// We have not benchmarked this choice. Deep equality may also be suitable.
|
|
181
|
+
if (delivered && Object.is(previous, next)) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
previous = next;
|
|
185
|
+
delivered = true;
|
|
186
|
+
notifyListener(() => listener(next));
|
|
187
|
+
};
|
|
188
|
+
const unsubscribe = customBlockHost.subscribe(deliverIfChanged);
|
|
189
|
+
deliverIfChanged();
|
|
190
|
+
return () => {
|
|
191
|
+
active = false;
|
|
192
|
+
unsubscribe();
|
|
193
|
+
};
|
|
194
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,6 @@ export type { NotionParent } from "./protocol/parent.js";
|
|
|
31
31
|
export type { NotionTheme } from "./protocol/theme.js";
|
|
32
32
|
export { pages, users } from "./bridge/sandboxClient.js";
|
|
33
33
|
export { type CustomBlockState, customBlock } from "./customBlock.js";
|
|
34
|
-
export { type CustomBlockInitPayload,
|
|
34
|
+
export { type CustomBlockInitPayload, initCustomBlock, NotInIframeError, } from "./init.js";
|
|
35
35
|
export * from "./types.js";
|
|
36
36
|
//# sourceMappingURL=index.d.ts.map
|
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,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KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,KAAK,gBAAgB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,EACN,KAAK,sBAAsB,EAC3B,eAAe,EACf,gBAAgB,GAChB,MAAM,WAAW,CAAA;AAClB,cAAc,YAAY,CAAA"}
|
package/dist/init.d.ts
CHANGED
|
@@ -28,18 +28,6 @@ export declare class NotInIframeError extends CustomBlockInitializationError {
|
|
|
28
28
|
constructor(message?: string);
|
|
29
29
|
code: "not_in_iframe";
|
|
30
30
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Options for {@link initCustomBlock}.
|
|
33
|
-
*/
|
|
34
|
-
export type InitCustomBlockOptions = {
|
|
35
|
-
/**
|
|
36
|
-
* How long to wait for the host's `init` response before rejecting with an error.
|
|
37
|
-
*
|
|
38
|
-
* @default 15000 - Intentionally longer than Notion's 10s host-dependency watchdog
|
|
39
|
-
* so host-owned init errors can arrive before the SDK's generic fallback appears.
|
|
40
|
-
*/
|
|
41
|
-
timeoutMs?: number;
|
|
42
|
-
};
|
|
43
31
|
/**
|
|
44
32
|
* Initializes the custom block by running the SDK <-> host handshake.
|
|
45
33
|
*
|
|
@@ -47,8 +35,8 @@ export type InitCustomBlockOptions = {
|
|
|
47
35
|
* user, data sources) once the host has initialized the block. Rejects with a
|
|
48
36
|
* `CustomBlockInitializationError` if initialization fails.
|
|
49
37
|
*
|
|
50
|
-
* Idempotent: subsequent calls return the same promise as the first
|
|
38
|
+
* Idempotent: subsequent calls return the same promise as the first.
|
|
51
39
|
* Mount your React tree (or call any SDK hook) only after the returned promise resolves.
|
|
52
40
|
*/
|
|
53
|
-
export declare function initCustomBlock(
|
|
41
|
+
export declare function initCustomBlock(): Promise<CustomBlockInitPayload>;
|
|
54
42
|
//# sourceMappingURL=init.d.ts.map
|
package/dist/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","s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Ae,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;AAKhF;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACpC,KAAK,EAAE,WAAW,CAAA;IAClB,YAAY,EAAE,kBAAkB,CAAA;IAChC,OAAO,EAAE,aAAa,CAAA;IACtB,MAAM,EAAE,YAAY,CAAA;IACpB,IAAI,EAAE,eAAe,CAAA;IACrB,WAAW,EAAE,UAAU,CAAA;IACvB,WAAW,EAAE,gBAAgB,EAAE,CAAA;CAC/B,CAAA;AAED;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,8BAA8B;IACnE,YAAY,OAAO,GAAE,MAA8B,EAOlD;IAEO,IAAI,EAAE,eAAe,CAAA;CAC7B;AAOD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAMjE"}
|
package/dist/init.js
CHANGED
|
@@ -18,7 +18,6 @@ export class NotInIframeError extends CustomBlockInitializationError {
|
|
|
18
18
|
this.name = "NotInIframeError";
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
const DEFAULT_INIT_TIMEOUT_MS = 15_000;
|
|
22
21
|
const NOT_IN_IFRAME_MESSAGE = "<NotionCustomBlock> only works inside an iframe — use the dev shell or deploy to Notion.";
|
|
23
22
|
let initPromise;
|
|
24
23
|
/**
|
|
@@ -28,13 +27,13 @@ let initPromise;
|
|
|
28
27
|
* user, data sources) once the host has initialized the block. Rejects with a
|
|
29
28
|
* `CustomBlockInitializationError` if initialization fails.
|
|
30
29
|
*
|
|
31
|
-
* Idempotent: subsequent calls return the same promise as the first
|
|
30
|
+
* Idempotent: subsequent calls return the same promise as the first.
|
|
32
31
|
* Mount your React tree (or call any SDK hook) only after the returned promise resolves.
|
|
33
32
|
*/
|
|
34
|
-
export function initCustomBlock(
|
|
33
|
+
export function initCustomBlock() {
|
|
35
34
|
if (initPromise === undefined) {
|
|
36
35
|
customBlockHost.start();
|
|
37
|
-
initPromise = performHandshake(
|
|
36
|
+
initPromise = performHandshake();
|
|
38
37
|
}
|
|
39
38
|
return initPromise;
|
|
40
39
|
}
|
|
@@ -49,19 +48,18 @@ export function initCustomBlock(opts = {}) {
|
|
|
49
48
|
* Resolves with the `init` payload after the process above. Rejects with a
|
|
50
49
|
* `CustomBlockInitializationError` if any step fails.
|
|
51
50
|
*/
|
|
52
|
-
async function performHandshake(
|
|
51
|
+
async function performHandshake() {
|
|
53
52
|
try {
|
|
54
53
|
// Fail fast with a typed error when rendered as a standalone tab and not in a parent frame.
|
|
55
|
-
// Otherwise,
|
|
56
|
-
//
|
|
54
|
+
// Otherwise, `postMessage` to `window.parent` would just hit the same window and never
|
|
55
|
+
// arrive.
|
|
57
56
|
if (typeof window !== "undefined" && window.parent === window) {
|
|
58
57
|
throw new NotInIframeError();
|
|
59
58
|
}
|
|
60
59
|
// Load the manifest and send it to the host.
|
|
61
60
|
const manifestResult = await attemptToLoadSelfHostedManifest();
|
|
62
61
|
customBlockHost.sendConnect(manifestResult);
|
|
63
|
-
|
|
64
|
-
await awaitHostInitWithTimeout(timeoutMs);
|
|
62
|
+
await customBlockHost.awaitInit();
|
|
65
63
|
const hostState = customBlockHost.getState();
|
|
66
64
|
switch (hostState.status) {
|
|
67
65
|
case "initialized":
|
|
@@ -96,24 +94,3 @@ async function performHandshake(opts) {
|
|
|
96
94
|
});
|
|
97
95
|
}
|
|
98
96
|
}
|
|
99
|
-
async function awaitHostInitWithTimeout(timeoutMs) {
|
|
100
|
-
try {
|
|
101
|
-
await customBlockHost.awaitInit(AbortSignal.timeout(timeoutMs));
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
if (isTimeoutError(error)) {
|
|
105
|
-
throw new CustomBlockInitializationError({
|
|
106
|
-
code: "init_timeout",
|
|
107
|
-
message: "Host did not respond to the `connect` message before the timeout.",
|
|
108
|
-
isRetryable: true,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
throw error;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function isTimeoutError(error) {
|
|
115
|
-
return (typeof error === "object" &&
|
|
116
|
-
error !== null &&
|
|
117
|
-
"name" in error &&
|
|
118
|
-
(error.name === "TimeoutError" || error.name === "AbortError"));
|
|
119
|
-
}
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -15,9 +15,7 @@ export * from "./dataSources/propertySchema.js";
|
|
|
15
15
|
export * from "./dataSources/recordPointer.js";
|
|
16
16
|
export * from "./errors.js";
|
|
17
17
|
export * from "./ids.js";
|
|
18
|
-
export * from "./incomingType.js";
|
|
19
18
|
export * from "./manifest.js";
|
|
20
|
-
export * from "./messagePayload.js";
|
|
21
19
|
export * from "./messages/connect.js";
|
|
22
20
|
export * from "./messages/contrastModeChanged.js";
|
|
23
21
|
export * from "./messages/createPage.js";
|
|
@@ -27,11 +25,14 @@ export * from "./messages/dataSourcesChanged.js";
|
|
|
27
25
|
export * from "./messages/getPage.js";
|
|
28
26
|
export * from "./messages/getUser.js";
|
|
29
27
|
export * from "./messages/hostToSandbox.js";
|
|
28
|
+
export * from "./messages/incomingType.js";
|
|
30
29
|
export * from "./messages/init.js";
|
|
31
30
|
export * from "./messages/initResult.js";
|
|
32
31
|
export * from "./messages/invalidHostMessage.js";
|
|
33
32
|
export * from "./messages/invalidSandboxMessage.js";
|
|
33
|
+
export * from "./messages/isInitHandshakeMessage.js";
|
|
34
34
|
export * from "./messages/listUsers.js";
|
|
35
|
+
export * from "./messages/messagePayload.js";
|
|
35
36
|
export * from "./messages/pageChanged.js";
|
|
36
37
|
export * from "./messages/parentChanged.js";
|
|
37
38
|
export * from "./messages/queryDataSource.js";
|
package/dist/protocol/index.js
CHANGED
|
@@ -15,9 +15,7 @@ export * from "./dataSources/propertySchema.js";
|
|
|
15
15
|
export * from "./dataSources/recordPointer.js";
|
|
16
16
|
export * from "./errors.js";
|
|
17
17
|
export * from "./ids.js";
|
|
18
|
-
export * from "./incomingType.js";
|
|
19
18
|
export * from "./manifest.js";
|
|
20
|
-
export * from "./messagePayload.js";
|
|
21
19
|
export * from "./messages/connect.js";
|
|
22
20
|
export * from "./messages/contrastModeChanged.js";
|
|
23
21
|
export * from "./messages/createPage.js";
|
|
@@ -27,11 +25,14 @@ export * from "./messages/dataSourcesChanged.js";
|
|
|
27
25
|
export * from "./messages/getPage.js";
|
|
28
26
|
export * from "./messages/getUser.js";
|
|
29
27
|
export * from "./messages/hostToSandbox.js";
|
|
28
|
+
export * from "./messages/incomingType.js";
|
|
30
29
|
export * from "./messages/init.js";
|
|
31
30
|
export * from "./messages/initResult.js";
|
|
32
31
|
export * from "./messages/invalidHostMessage.js";
|
|
33
32
|
export * from "./messages/invalidSandboxMessage.js";
|
|
33
|
+
export * from "./messages/isInitHandshakeMessage.js";
|
|
34
34
|
export * from "./messages/listUsers.js";
|
|
35
|
+
export * from "./messages/messagePayload.js";
|
|
35
36
|
export * from "./messages/pageChanged.js";
|
|
36
37
|
export * from "./messages/parentChanged.js";
|
|
37
38
|
export * from "./messages/queryDataSource.js";
|
|
@@ -2,14 +2,14 @@ import * as v from "valibot";
|
|
|
2
2
|
import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
|
|
3
3
|
import type { CustomBlockInitResultErrorCode } from "./initResult.js";
|
|
4
4
|
export declare const customBlockInitErrorCodeSchema: v.StringSchema<undefined>;
|
|
5
|
-
export type CustomBlockInitErrorCode = CustomBlockErrorCode<"manifest_unavailable" | "manifest_invalid" | "invalid_connect_payload" | "invalid_protocol_version" | "unsupported_protocol_version" | "context_unavailable" | "current_user_unavailable" | "missing_data_source_binding" | "data_source_unavailable" | "missing_property_binding" | "invalid_property_binding">;
|
|
5
|
+
export type CustomBlockInitErrorCode = CustomBlockErrorCode<"manifest_unavailable" | "manifest_invalid" | "invalid_connect_payload" | "invalid_protocol_version" | "unsupported_protocol_version" | "init_timeout" | "context_unavailable" | "current_user_unavailable" | "missing_data_source_binding" | "data_source_unavailable" | "missing_property_binding" | "invalid_property_binding">;
|
|
6
6
|
export type CustomBlockInitErrorInfo = CustomBlockErrorInfo<CustomBlockInitErrorCode>;
|
|
7
7
|
/**
|
|
8
8
|
* Every initialization failure visible to block code. This combines errors
|
|
9
9
|
* received in `init`, errors the sandbox reports in `initResult`, and failures
|
|
10
10
|
* detected locally while running `initCustomBlock()`.
|
|
11
11
|
*/
|
|
12
|
-
export type CustomBlockInitializationErrorCode = CustomBlockInitErrorCode | CustomBlockInitResultErrorCode | CustomBlockErrorCode<"not_in_iframe"
|
|
12
|
+
export type CustomBlockInitializationErrorCode = CustomBlockInitErrorCode | CustomBlockInitResultErrorCode | CustomBlockErrorCode<"not_in_iframe">;
|
|
13
13
|
export type CustomBlockInitializationErrorInfo = CustomBlockErrorInfo<CustomBlockInitializationErrorCode>;
|
|
14
14
|
export declare const customBlockInitErrorInfoSchema: v.ObjectSchema<{
|
|
15
15
|
readonly code: v.StringSchema<undefined>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HostToSandboxMessage } from "./hostToSandbox.js";
|
|
2
|
+
import type { SandboxToHostMessage } from "./sandboxToHost.js";
|
|
3
|
+
/** Returns whether a message belongs to the initialization handshake. */
|
|
4
|
+
export declare function isInitHandshakeMessage(message: SandboxToHostMessage | HostToSandboxMessage): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CustomBlockErrorInfo } from "
|
|
1
|
+
import type { CustomBlockErrorInfo } from "../errors.js";
|
|
2
2
|
type WithTypedErrorInfo<T, TErrorInfo extends CustomBlockErrorInfo | undefined> = TErrorInfo extends CustomBlockErrorInfo ? T extends {
|
|
3
3
|
error: CustomBlockErrorInfo;
|
|
4
4
|
} ? Omit<T, "error"> & {
|