create-ncblock 0.0.20 → 0.0.22
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/package.json +1 -1
- package/scripts/utils/templates.ts +1 -1
- package/sdk-version.json +1 -1
- package/templates/debug/src/index.tsx +174 -3
package/package.json
CHANGED
package/sdk-version.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.0.
|
|
1
|
+
{"version":"0.0.20"}
|
|
@@ -33,6 +33,11 @@ type LogEntry = {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
type ThemeOverride = "host" | "light" | "dark"
|
|
36
|
+
type NotionInitFixture =
|
|
37
|
+
| "normal"
|
|
38
|
+
| "no-ready"
|
|
39
|
+
| "invalid-ready"
|
|
40
|
+
| "invalid-manifest"
|
|
36
41
|
type TrackedPage = {
|
|
37
42
|
page: NotionPage
|
|
38
43
|
draftTitle: string
|
|
@@ -45,6 +50,7 @@ const labelClass =
|
|
|
45
50
|
"text-[10px] font-semibold uppercase tracking-[0.06em] text-(--muted)"
|
|
46
51
|
const metaTextClass =
|
|
47
52
|
"font-mono text-[11px] font-normal normal-case tracking-normal text-(--muted)"
|
|
53
|
+
const HOST_NO_READY_ERROR_DELAY_SECONDS = 5
|
|
48
54
|
|
|
49
55
|
function App() {
|
|
50
56
|
const ctx = useCustomBlockContext()
|
|
@@ -198,6 +204,162 @@ function App() {
|
|
|
198
204
|
)
|
|
199
205
|
}
|
|
200
206
|
|
|
207
|
+
function DevOnlyNoReadyFixture() {
|
|
208
|
+
return (
|
|
209
|
+
<div className="min-h-screen bg-(--app-bg) p-8 text-(--foreground)">
|
|
210
|
+
<div className={cardClass}>
|
|
211
|
+
<div className={labelClass}>Local init fixture</div>
|
|
212
|
+
<h1 className="mt-2 text-[24px] font-semibold">No ready message</h1>
|
|
213
|
+
<p className="mt-2 text-sm leading-6 text-(--muted)">
|
|
214
|
+
This dev-only fixture intentionally skips the SDK provider, so the
|
|
215
|
+
sandbox loads but never sends the initial <code>ready</code> message.
|
|
216
|
+
Use it only for local manual testing of Notion host init error UI.
|
|
217
|
+
</p>
|
|
218
|
+
<DevOnlyHostErrorExpectation>
|
|
219
|
+
This page is the pre-error fixture, not the Notion error state. In the
|
|
220
|
+
Notion host, wait about {HOST_NO_READY_ERROR_DELAY_SECONDS} seconds
|
|
221
|
+
after the iframe loads; the host-owned{" "}
|
|
222
|
+
<span className="font-mono">Custom block didn't connect</span> error
|
|
223
|
+
should then cover this page.
|
|
224
|
+
</DevOnlyHostErrorExpectation>
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function DevOnlyInvalidReadyFixture() {
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
if (window.parent === window) {
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Dev-only fixture for local manual testing of Notion host init error UI.
|
|
237
|
+
// This intentionally bypasses the SDK so the host receives a malformed
|
|
238
|
+
// ready message that is missing the manifest and protocol fields.
|
|
239
|
+
window.parent.postMessage({ type: "ready" }, "*")
|
|
240
|
+
}, [])
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<div className="min-h-screen bg-(--app-bg) p-8 text-(--foreground)">
|
|
244
|
+
<div className={cardClass}>
|
|
245
|
+
<div className={labelClass}>Local init fixture</div>
|
|
246
|
+
<h1 className="mt-2 text-[24px] font-semibold">
|
|
247
|
+
Invalid ready message
|
|
248
|
+
</h1>
|
|
249
|
+
<p className="mt-2 text-sm leading-6 text-(--muted)">
|
|
250
|
+
This dev-only fixture posts malformed{" "}
|
|
251
|
+
<code>{'{ type: "ready" }'}</code> to the parent window and does not
|
|
252
|
+
mount the SDK provider. Use it only for local manual testing of Notion
|
|
253
|
+
host init error UI.
|
|
254
|
+
</p>
|
|
255
|
+
<DevOnlyHostErrorExpectation>
|
|
256
|
+
This page is the pre-error fixture, not the Notion error state. In the
|
|
257
|
+
Notion host, the host-owned invalid setup message error should cover
|
|
258
|
+
this page as soon as Notion processes the malformed <code>ready</code>{" "}
|
|
259
|
+
message.
|
|
260
|
+
</DevOnlyHostErrorExpectation>
|
|
261
|
+
</div>
|
|
262
|
+
</div>
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function DevOnlyInvalidManifestFixture() {
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
if (window.parent === window) {
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Dev-only fixture for local manual testing of Notion host init error UI.
|
|
273
|
+
// This intentionally bypasses the SDK so the host receives a ready message
|
|
274
|
+
// with a manifest schema the bridge validator must reject.
|
|
275
|
+
window.parent.postMessage(
|
|
276
|
+
{
|
|
277
|
+
type: "ready",
|
|
278
|
+
bridgeProtocolVersion: 1,
|
|
279
|
+
manifest: {
|
|
280
|
+
version: 1,
|
|
281
|
+
dataSources: {
|
|
282
|
+
default: {
|
|
283
|
+
name: "Invalid fixture data source",
|
|
284
|
+
properties: {
|
|
285
|
+
unsupportedProperty: {
|
|
286
|
+
name: "Unsupported property",
|
|
287
|
+
type: "unsupported_manual_fixture_property_type",
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
"*",
|
|
295
|
+
)
|
|
296
|
+
}, [])
|
|
297
|
+
|
|
298
|
+
return (
|
|
299
|
+
<div className="min-h-screen bg-(--app-bg) p-8 text-(--foreground)">
|
|
300
|
+
<div className={cardClass}>
|
|
301
|
+
<div className={labelClass}>Local init fixture</div>
|
|
302
|
+
<h1 className="mt-2 text-[24px] font-semibold">Invalid manifest</h1>
|
|
303
|
+
<p className="mt-2 text-sm leading-6 text-(--muted)">
|
|
304
|
+
This dev-only fixture posts a <code>ready</code> message with an
|
|
305
|
+
unsupported manifest property type and does not mount the SDK
|
|
306
|
+
provider. Use it only for local manual testing of Notion host init
|
|
307
|
+
error UI.
|
|
308
|
+
</p>
|
|
309
|
+
<DevOnlyHostErrorExpectation>
|
|
310
|
+
This page is the pre-error fixture, not the Notion error state. In the
|
|
311
|
+
Notion host, the host-owned invalid manifest error should cover this
|
|
312
|
+
page as soon as Notion validates the <code>ready</code> message.
|
|
313
|
+
</DevOnlyHostErrorExpectation>
|
|
314
|
+
</div>
|
|
315
|
+
</div>
|
|
316
|
+
)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function DevOnlyHostErrorExpectation(props: { children: React.ReactNode }) {
|
|
320
|
+
return (
|
|
321
|
+
<div className="mt-3 rounded-md border border-(--border) bg-(--app-bg) px-3 py-2 text-sm leading-6 text-(--foreground)">
|
|
322
|
+
<span className="font-semibold">Expected host behavior: </span>
|
|
323
|
+
{props.children}
|
|
324
|
+
</div>
|
|
325
|
+
)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function DebugInitErrorFallback(error: Error) {
|
|
329
|
+
return (
|
|
330
|
+
<div className="min-h-screen bg-(--app-bg) p-8 text-(--foreground)">
|
|
331
|
+
<div className={cardClass} role="alert">
|
|
332
|
+
<div className={labelClass}>Custom block init</div>
|
|
333
|
+
<h1 className="mt-2 text-[24px] font-semibold">
|
|
334
|
+
Couldn't connect to Notion
|
|
335
|
+
</h1>
|
|
336
|
+
<p className="mt-2 text-sm leading-6 text-(--muted)">
|
|
337
|
+
The debug template waited for the host handshake, but it did not
|
|
338
|
+
complete. This fallback is only for local manual testing; host-owned
|
|
339
|
+
error UI should normally cover known Notion init failures first.
|
|
340
|
+
</p>
|
|
341
|
+
<pre className="mt-3 overflow-auto rounded-md border border-(--border) bg-(--app-bg) p-3 font-mono text-[11px] text-(--muted)">
|
|
342
|
+
{error.message}
|
|
343
|
+
</pre>
|
|
344
|
+
</div>
|
|
345
|
+
</div>
|
|
346
|
+
)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function getNotionInitFixture(): NotionInitFixture {
|
|
350
|
+
const fixture = new URLSearchParams(window.location.search).get(
|
|
351
|
+
"notionInitFixture",
|
|
352
|
+
)
|
|
353
|
+
if (
|
|
354
|
+
fixture === "no-ready" ||
|
|
355
|
+
fixture === "invalid-ready" ||
|
|
356
|
+
fixture === "invalid-manifest"
|
|
357
|
+
) {
|
|
358
|
+
return fixture
|
|
359
|
+
}
|
|
360
|
+
return "normal"
|
|
361
|
+
}
|
|
362
|
+
|
|
201
363
|
// --- Hooks ---
|
|
202
364
|
|
|
203
365
|
function useMessageLog(isPaused: boolean) {
|
|
@@ -1960,10 +2122,19 @@ function CreatePageCard({ context, dataSources }: CreatePageCardProps) {
|
|
|
1960
2122
|
|
|
1961
2123
|
// --- Mount ---
|
|
1962
2124
|
|
|
2125
|
+
const notionInitFixture = getNotionInitFixture()
|
|
2126
|
+
|
|
1963
2127
|
ReactDOM.createRoot(document.getElementById("root")!).render(
|
|
1964
2128
|
<ErrorBoundary>
|
|
1965
|
-
<
|
|
1966
|
-
|
|
1967
|
-
|
|
2129
|
+
{notionInitFixture === "no-ready" && <DevOnlyNoReadyFixture />}
|
|
2130
|
+
{notionInitFixture === "invalid-ready" && <DevOnlyInvalidReadyFixture />}
|
|
2131
|
+
{notionInitFixture === "invalid-manifest" && (
|
|
2132
|
+
<DevOnlyInvalidManifestFixture />
|
|
2133
|
+
)}
|
|
2134
|
+
{notionInitFixture === "normal" && (
|
|
2135
|
+
<NotionCustomBlock errorFallback={DebugInitErrorFallback}>
|
|
2136
|
+
<App />
|
|
2137
|
+
</NotionCustomBlock>
|
|
2138
|
+
)}
|
|
1968
2139
|
</ErrorBoundary>,
|
|
1969
2140
|
)
|