@notionhq/custom-blocks 0.0.63 → 0.0.65
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/HOST.md +16 -16
- package/README.md +2 -2
- package/bin/cli/create.js +3 -3
- package/dist/bridge/SandboxBridge.js +17 -17
- package/dist/bridge/loadManifest.d.ts +2 -7
- package/dist/bridge/loadManifest.d.ts.map +1 -1
- package/dist/bridge/loadManifest.js +36 -18
- package/dist/bridge/messages/ready.d.ts +1 -0
- package/dist/bridge/messages/ready.d.ts.map +1 -1
- package/dist/bridge/messages/ready.js +8 -2
- package/dist/bridge/messages/sandboxToHost.d.ts +1 -0
- package/dist/bridge/messages/sandboxToHost.d.ts.map +1 -1
- package/dist/host/createCustomBlockHost.d.ts.map +1 -1
- package/dist/host/createCustomBlockHost.js +24 -13
- package/dist/host/lifecycle/initErrors.d.ts +4 -1
- package/dist/host/lifecycle/initErrors.d.ts.map +1 -1
- package/dist/host/lifecycle/initErrors.js +16 -5
- package/dist/host/lifecycle/ready.d.ts +1 -7
- package/dist/host/lifecycle/ready.d.ts.map +1 -1
- package/dist/host/lifecycle/ready.js +1 -22
- package/dist/init.js +1 -1
- package/dist/react/NotionCustomBlock.css +47 -47
- package/dist/react/NotionCustomBlock.js +4 -4
- package/dist/utils.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/block-location.md +1 -1
- package/docs/manifest.md +2 -2
- package/docs/pages.md +1 -1
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +17 -17
- package/src/bridge/loadManifest.ts +44 -23
- package/src/bridge/messages/ready.ts +9 -2
- package/src/host/createCustomBlockHost.ts +30 -14
- package/src/host/lifecycle/initErrors.ts +19 -4
- package/src/host/lifecycle/ready.ts +1 -34
- package/src/init.ts +1 -1
- package/src/react/NotionCustomBlock.css +47 -47
- package/src/react/NotionCustomBlock.tsx +14 -10
- package/src/utils.ts +1 -1
- package/src/version.ts +1 -1
|
@@ -15,6 +15,10 @@ const UNKNOWN_ERROR_MESSAGE =
|
|
|
15
15
|
*/
|
|
16
16
|
export function initErrorForFailureReason(
|
|
17
17
|
reason: CustomBlockInitErrorCode,
|
|
18
|
+
data: {
|
|
19
|
+
minBridgeProtocolVersion?: number
|
|
20
|
+
currentBridgeProtocolVersion?: number
|
|
21
|
+
} = {},
|
|
18
22
|
): CustomBlockInitErrorInfo {
|
|
19
23
|
switch (reason) {
|
|
20
24
|
case "no_ready":
|
|
@@ -43,20 +47,31 @@ export function initErrorForFailureReason(
|
|
|
43
47
|
// The sandbox must be updated to a valid manifest.
|
|
44
48
|
isRetryable: false,
|
|
45
49
|
}
|
|
46
|
-
case "invalid_protocol_version":
|
|
50
|
+
case "invalid_protocol_version": {
|
|
51
|
+
const versionText = data.currentBridgeProtocolVersion
|
|
52
|
+
? `: ${data.currentBridgeProtocolVersion}`
|
|
53
|
+
: "."
|
|
47
54
|
return {
|
|
48
55
|
code: reason,
|
|
49
|
-
message:
|
|
56
|
+
message: `Sandbox reported an invalid bridge protocol version ${versionText}`,
|
|
50
57
|
// The sandbox must be updated to a supported protocol version.
|
|
51
58
|
isRetryable: false,
|
|
52
59
|
}
|
|
53
|
-
|
|
60
|
+
}
|
|
61
|
+
case "unsupported_protocol_version": {
|
|
62
|
+
const currentVersionText = data.currentBridgeProtocolVersion
|
|
63
|
+
? `${data.currentBridgeProtocolVersion} `
|
|
64
|
+
: ""
|
|
65
|
+
const minVersionText = data.minBridgeProtocolVersion
|
|
66
|
+
? ` Minimum supported version is ${data.minBridgeProtocolVersion}.`
|
|
67
|
+
: ""
|
|
54
68
|
return {
|
|
55
69
|
code: reason,
|
|
56
|
-
message:
|
|
70
|
+
message: `Sandbox bridge protocol version ${currentVersionText}is not supported.${minVersionText}`,
|
|
57
71
|
// The sandbox must be updated to a supported protocol version.
|
|
58
72
|
isRetryable: false,
|
|
59
73
|
}
|
|
74
|
+
}
|
|
60
75
|
case "context_unavailable":
|
|
61
76
|
return {
|
|
62
77
|
code: reason,
|
|
@@ -1,36 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import type { ReadyMessage } from "../../bridge/messages/ready.js"
|
|
3
|
-
|
|
4
|
-
export type ReadyInitFailure = {
|
|
5
|
-
code: CustomBlockInitErrorCode
|
|
6
|
-
message?: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function getReadyInitFailure(
|
|
10
|
-
message: ReadyMessage,
|
|
11
|
-
minBridgeProtocolVersion: number,
|
|
12
|
-
): ReadyInitFailure | undefined {
|
|
13
|
-
if (!isValidBridgeProtocolVersion(message.bridgeProtocolVersion)) {
|
|
14
|
-
return {
|
|
15
|
-
code: "invalid_protocol_version",
|
|
16
|
-
message: `Sandbox reported invalid bridge protocol version ${message.bridgeProtocolVersion}.`,
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
if (message.bridgeProtocolVersion < minBridgeProtocolVersion) {
|
|
20
|
-
return {
|
|
21
|
-
code: "unsupported_protocol_version",
|
|
22
|
-
message: `Sandbox bridge protocol version ${message.bridgeProtocolVersion} is below the host minimum ${minBridgeProtocolVersion}.`,
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (message.status === "error") {
|
|
26
|
-
return {
|
|
27
|
-
code: message.error.code,
|
|
28
|
-
message: message.error.message,
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return undefined
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function isValidBridgeProtocolVersion(version: number): boolean {
|
|
1
|
+
export function isValidBridgeProtocolVersion(version: number): boolean {
|
|
35
2
|
return Number.isFinite(version) && Number.isInteger(version) && version >= 1
|
|
36
3
|
}
|
package/src/init.ts
CHANGED
|
@@ -106,7 +106,7 @@ export function initCustomBlock(
|
|
|
106
106
|
}
|
|
107
107
|
if (message.status === "error") {
|
|
108
108
|
console.error(
|
|
109
|
-
`[
|
|
109
|
+
`[custom-blocks-sdk] host reported init error (${message.error.code}): ${message.error.message}`,
|
|
110
110
|
)
|
|
111
111
|
throw new CustomBlockInitError(message.error)
|
|
112
112
|
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
.
|
|
2
|
-
--
|
|
3
|
-
--
|
|
4
|
-
--
|
|
1
|
+
.custom-blocks-standalone-banner {
|
|
2
|
+
--custom-blocks-standalone-banner-background: #fff8e1;
|
|
3
|
+
--custom-blocks-standalone-banner-border: #f0d77b;
|
|
4
|
+
--custom-blocks-standalone-banner-text: #5d4200;
|
|
5
5
|
|
|
6
6
|
padding: 8px 12px;
|
|
7
|
-
background: var(--
|
|
8
|
-
color: var(--
|
|
9
|
-
border-bottom: 1px solid var(--
|
|
7
|
+
background: var(--custom-blocks-standalone-banner-background);
|
|
8
|
+
color: var(--custom-blocks-standalone-banner-text);
|
|
9
|
+
border-bottom: 1px solid var(--custom-blocks-standalone-banner-border);
|
|
10
10
|
font-size: 13px;
|
|
11
11
|
font-family: system-ui, sans-serif;
|
|
12
12
|
line-height: 1.4;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
.
|
|
16
|
-
--
|
|
17
|
-
--
|
|
18
|
-
--
|
|
19
|
-
--
|
|
20
|
-
--
|
|
21
|
-
--
|
|
22
|
-
--
|
|
23
|
-
--
|
|
24
|
-
--
|
|
15
|
+
.custom-blocks-default-init-error {
|
|
16
|
+
--custom-blocks-init-error-background: #f7f7f5;
|
|
17
|
+
--custom-blocks-init-error-card-background: #ffffff;
|
|
18
|
+
--custom-blocks-init-error-border: #e5e5e1;
|
|
19
|
+
--custom-blocks-init-error-text: #1f1f1d;
|
|
20
|
+
--custom-blocks-init-error-muted-text: #5f5e5b;
|
|
21
|
+
--custom-blocks-init-error-eyebrow-text: #787774;
|
|
22
|
+
--custom-blocks-init-error-pre-background: #f1f1ef;
|
|
23
|
+
--custom-blocks-init-error-pre-text: #37352f;
|
|
24
|
+
--custom-blocks-init-error-shadow: rgba(0, 0, 0, 0.08);
|
|
25
25
|
|
|
26
26
|
box-sizing: border-box;
|
|
27
27
|
min-height: 240px;
|
|
@@ -29,81 +29,81 @@
|
|
|
29
29
|
align-items: center;
|
|
30
30
|
justify-content: center;
|
|
31
31
|
padding: 24px;
|
|
32
|
-
background: var(--
|
|
33
|
-
color: var(--
|
|
32
|
+
background: var(--custom-blocks-init-error-background);
|
|
33
|
+
color: var(--custom-blocks-init-error-text);
|
|
34
34
|
font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
|
|
35
35
|
color-scheme: light;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
.
|
|
38
|
+
.custom-blocks-default-init-error__card {
|
|
39
39
|
box-sizing: border-box;
|
|
40
40
|
width: 100%;
|
|
41
41
|
max-width: 420px;
|
|
42
42
|
padding: 20px;
|
|
43
|
-
border: 1px solid var(--
|
|
43
|
+
border: 1px solid var(--custom-blocks-init-error-border);
|
|
44
44
|
border-radius: 12px;
|
|
45
|
-
background: var(--
|
|
46
|
-
box-shadow: 0 8px 24px var(--
|
|
45
|
+
background: var(--custom-blocks-init-error-card-background);
|
|
46
|
+
box-shadow: 0 8px 24px var(--custom-blocks-init-error-shadow);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
.
|
|
49
|
+
.custom-blocks-default-init-error__eyebrow {
|
|
50
50
|
margin-bottom: 8px;
|
|
51
51
|
font-size: 11px;
|
|
52
52
|
font-weight: 600;
|
|
53
53
|
letter-spacing: 0.08em;
|
|
54
54
|
text-transform: uppercase;
|
|
55
|
-
color: var(--
|
|
55
|
+
color: var(--custom-blocks-init-error-eyebrow-text);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
.
|
|
58
|
+
.custom-blocks-default-init-error__title {
|
|
59
59
|
margin: 0;
|
|
60
60
|
font-size: 18px;
|
|
61
61
|
line-height: 1.3;
|
|
62
62
|
font-weight: 650;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
.
|
|
65
|
+
.custom-blocks-default-init-error__body {
|
|
66
66
|
margin: 8px 0 0;
|
|
67
67
|
font-size: 14px;
|
|
68
68
|
line-height: 1.5;
|
|
69
|
-
color: var(--
|
|
69
|
+
color: var(--custom-blocks-init-error-muted-text);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
.
|
|
72
|
+
.custom-blocks-default-init-error__details {
|
|
73
73
|
margin-top: 14px;
|
|
74
74
|
font-size: 12px;
|
|
75
|
-
color: var(--
|
|
75
|
+
color: var(--custom-blocks-init-error-muted-text);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
.
|
|
78
|
+
.custom-blocks-default-init-error__pre {
|
|
79
79
|
margin: 8px 0 0;
|
|
80
80
|
padding: 10px;
|
|
81
81
|
overflow: auto;
|
|
82
82
|
border-radius: 8px;
|
|
83
|
-
background: var(--
|
|
84
|
-
color: var(--
|
|
83
|
+
background: var(--custom-blocks-init-error-pre-background);
|
|
84
|
+
color: var(--custom-blocks-init-error-pre-text);
|
|
85
85
|
font-size: 12px;
|
|
86
86
|
line-height: 1.4;
|
|
87
87
|
white-space: pre-wrap;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
@media (prefers-color-scheme: dark) {
|
|
91
|
-
.
|
|
92
|
-
--
|
|
93
|
-
--
|
|
94
|
-
--
|
|
91
|
+
.custom-blocks-standalone-banner {
|
|
92
|
+
--custom-blocks-standalone-banner-background: #3b2f0b;
|
|
93
|
+
--custom-blocks-standalone-banner-border: #6f5713;
|
|
94
|
+
--custom-blocks-standalone-banner-text: #f5d36c;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
.
|
|
98
|
-
--
|
|
99
|
-
--
|
|
100
|
-
--
|
|
101
|
-
--
|
|
102
|
-
--
|
|
103
|
-
--
|
|
104
|
-
--
|
|
105
|
-
--
|
|
106
|
-
--
|
|
97
|
+
.custom-blocks-default-init-error {
|
|
98
|
+
--custom-blocks-init-error-background: #191918;
|
|
99
|
+
--custom-blocks-init-error-card-background: #20201f;
|
|
100
|
+
--custom-blocks-init-error-border: #373633;
|
|
101
|
+
--custom-blocks-init-error-text: #f1f1ef;
|
|
102
|
+
--custom-blocks-init-error-muted-text: #b9b8b3;
|
|
103
|
+
--custom-blocks-init-error-eyebrow-text: #9b9a97;
|
|
104
|
+
--custom-blocks-init-error-pre-background: #2a2a28;
|
|
105
|
+
--custom-blocks-init-error-pre-text: #e8e8e4;
|
|
106
|
+
--custom-blocks-init-error-shadow: rgba(0, 0, 0, 0.35);
|
|
107
107
|
|
|
108
108
|
color-scheme: dark;
|
|
109
109
|
}
|
|
@@ -80,7 +80,7 @@ export function NotionCustomBlock({
|
|
|
80
80
|
if (!isStandalone) {
|
|
81
81
|
return
|
|
82
82
|
}
|
|
83
|
-
console.warn(`[
|
|
83
|
+
console.warn(`[custom-blocks-sdk] ${init.error?.message}`)
|
|
84
84
|
seedStandalonePreviewState()
|
|
85
85
|
}, [isStandalone, init.error])
|
|
86
86
|
|
|
@@ -107,7 +107,7 @@ export function NotionCustomBlock({
|
|
|
107
107
|
}
|
|
108
108
|
return (
|
|
109
109
|
<>
|
|
110
|
-
<div role="status" className="
|
|
110
|
+
<div role="status" className="custom-blocks-standalone-banner">
|
|
111
111
|
Notion host not detected — running in standalone preview. SDK hooks
|
|
112
112
|
return placeholder values until embedded in Notion.
|
|
113
113
|
</div>
|
|
@@ -125,25 +125,29 @@ export function NotionCustomBlock({
|
|
|
125
125
|
function DefaultInitErrorFallback({ error }: { error: Error }) {
|
|
126
126
|
useEffect(() => {
|
|
127
127
|
console.warn(
|
|
128
|
-
`[
|
|
128
|
+
`[custom-blocks-sdk] Custom block init failed: ${error.message}`,
|
|
129
129
|
)
|
|
130
130
|
}, [error])
|
|
131
131
|
|
|
132
132
|
return (
|
|
133
|
-
<div role="alert" className="
|
|
134
|
-
<div className="
|
|
135
|
-
<div className="
|
|
136
|
-
|
|
133
|
+
<div role="alert" className="custom-blocks-default-init-error">
|
|
134
|
+
<div className="custom-blocks-default-init-error__card">
|
|
135
|
+
<div className="custom-blocks-default-init-error__eyebrow">
|
|
136
|
+
Custom block
|
|
137
|
+
</div>
|
|
138
|
+
<h2 className="custom-blocks-default-init-error__title">
|
|
137
139
|
Couldn't connect to Notion
|
|
138
140
|
</h2>
|
|
139
|
-
<p className="
|
|
141
|
+
<p className="custom-blocks-default-init-error__body">
|
|
140
142
|
This custom block loaded, but the setup handshake didn't finish.
|
|
141
143
|
Try again from Notion. If this keeps happening, check the browser
|
|
142
144
|
console for SDK details.
|
|
143
145
|
</p>
|
|
144
|
-
<details className="
|
|
146
|
+
<details className="custom-blocks-default-init-error__details">
|
|
145
147
|
<summary>Developer details</summary>
|
|
146
|
-
<pre className="
|
|
148
|
+
<pre className="custom-blocks-default-init-error__pre">
|
|
149
|
+
{error.message}
|
|
150
|
+
</pre>
|
|
147
151
|
</details>
|
|
148
152
|
</div>
|
|
149
153
|
</div>
|
package/src/utils.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* This checked-in value intentionally stays generic for local development. The SDK publish build
|
|
6
6
|
* overwrites the compiled runtime module with package.json's semver before publishing.
|
|
7
7
|
*/
|
|
8
|
-
export const
|
|
8
|
+
export const CUSTOM_BLOCKS_SDK_VERSION: string = "0.0.0"
|