Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"playground": true,
"docs": false,
"author": "",
"tags": ["Extension", "Custom Blocks"],
"dependencies": {
"@blocknote/embeds": "latest"
}
}
7 changes: 7 additions & 0 deletions examples/08-extensions/03-embeds-without-backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Embeds without a backend

Paste a sample URL into an empty paragraph, then choose URL, Bookmark or Embed. Pasting itself only inserts an ordinary link and never fetches a preview.

YouTube, Bluesky and the small typed custom CodePen React provider work directly after you choose Embed. The optional catch-all accepts other websites and honestly shows a source card without a resolver. No backend endpoint, provider catalog or automatic favicon service is used. Bookmarks save only the source URL unless you supply a metadata callback; saved bookmarks never resolve metadata on mount.

Run the playground and open `/extensions/embeds-without-backend`. Compare with [the endpoint-backed example](https://playground.blocknotejs.org/extensions/embeds-with-backend). Copy buttons write plain text and focus an empty paragraph; they do not fetch or insert previews. This example does not persist documents across reloads.
17 changes: 17 additions & 0 deletions examples/08-extensions/03-embeds-without-backend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, interactive-widget=resizes-content"
/>
<title>Embeds without a backend</title>
<script>
<!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY -->
</script>
</head>
<body>
<div id="root"></div>
<script type="module" src="./main.tsx"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions examples/08-extensions/03-embeds-without-backend/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY
import React from "react";
import { createRoot } from "react-dom/client";
import App from "./src/App.jsx";

const root = createRoot(document.getElementById("root")!);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
31 changes: 31 additions & 0 deletions examples/08-extensions/03-embeds-without-backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@blocknote/example-extensions-embeds-without-backend",
"description": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY",
"type": "module",
"private": true,
"version": "0.12.4",
"scripts": {
"start": "vite",
"dev": "vite",
"build:prod": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"@blocknote/ariakit": "latest",
"@blocknote/core": "latest",
"@blocknote/mantine": "latest",
"@blocknote/react": "latest",
"@blocknote/shadcn": "latest",
"@mantine/core": "^9.0.2",
"@mantine/hooks": "^9.0.2",
"react": "^19.2.3",
"react-dom": "^19.2.3",
"@blocknote/embeds": "latest"
},
"devDependencies": {
"@types/react": "^19.2.3",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^6.0.1",
"vite": "^8.0.0"
}
}
117 changes: 117 additions & 0 deletions examples/08-extensions/03-embeds-without-backend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { BlockNoteSchema } from "@blocknote/core";
import "@blocknote/core/fonts/inter.css";
import {
embedBlockSpecs,
withEmbeds,
PasteChoice,
createProvider,
SafeIframe,
type EmbedViewProps,
} from "@blocknote/embeds";
import { youtubeProvider } from "@blocknote/embeds/providers/youtube";
import { blueskyProvider } from "@blocknote/embeds/providers/bluesky";
import { createOEmbedProvider } from "@blocknote/embeds/providers/oembed";
import "@blocknote/embeds/style.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import { useCreateBlockNote } from "@blocknote/react";
import { useState } from "react";

const CODEPEN_URL = "https://codepen.io/team/codepen/pen/PNaGbb";

function CodePen({ url }: EmbedViewProps) {
const source = new URL(url);
return (
<SafeIframe
src={`https://codepen.io${source.pathname.replace("/pen/", "/embed/")}?default-tab=result`}
title="CodePen example"
aspectRatio={16 / 10}
/>
);
}

/** Custom providers are ordinary typed React components; configuration stays in the app. */
const codepenProvider = createProvider({
id: "codepen",
matches(url) {
return (
url.hostname === "codepen.io" &&
/^\/(?:team\/)?[\w-]+\/pen\/[\w-]+\/?$/.test(url.pathname)
);
},
component: CodePen,
});

const embeds = {
providers: [
youtubeProvider,
blueskyProvider,
codepenProvider,
createOEmbedProvider(),
],
};
const schema = BlockNoteSchema.create().extend({
blockSpecs: embedBlockSpecs,
});
const samples = [
["YouTube", "https://www.youtube.com/watch?v=jNQXAC9IVRw"],
["Bluesky", "https://bsky.app/profile/bsky.app/post/3kktuiwidw22d"],
["CodePen", CODEPEN_URL],
["Website", "https://www.blocknotejs.org"],
] as const;

export default function App() {
const [notice, setNotice] = useState(
"No backend: website metadata may be unavailable. Unsupported embeds show a source link.",
);
const editor = useCreateBlockNote(
withEmbeds({
schema,
embeds,
}),
);
async function copy(url: string) {
try {
await navigator.clipboard.writeText(url);
} catch {
setNotice(`Copy manually: ${url}`);
return;
}
const last = editor.document.at(-1);
if (last) {
const target =
last.type === "paragraph" && last.content.length === 0
? last
: editor.insertBlocks([{ type: "paragraph" }], last, "after")[0];
editor.setTextCursorPosition(target, "end");
}
editor.focus();
setNotice(
"URL copied. Paste into the empty paragraph to choose URL, Bookmark or Embed.",
);
}
return (
<>
<div
role="group"
aria-label="Copy sample URL"
style={{ display: "flex", flexWrap: "wrap", gap: 8, padding: 12 }}
>
{samples.map(([label, url]) => (
<button
key={label}
type="button"
title={url}
onClick={() => void copy(url)}
>
Copy {label} URL
</button>
))}
<span role="status">{notice}</span>
</div>
<BlockNoteView editor={editor}>
<PasteChoice />
</BlockNoteView>
</>
);
}
32 changes: 32 additions & 0 deletions examples/08-extensions/03-embeds-without-backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"__comment": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY",
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"composite": true,
"paths": {
"@shared/*": ["../../../shared/*"]
}
},
"include": ["."],
"__ADD_FOR_LOCAL_DEV_references": [
{
"path": "../../../packages/core/"
},
{
"path": "../../../packages/react/"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
35 changes: 35 additions & 0 deletions examples/08-extensions/03-embeds-without-backend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY
import react from "@vitejs/plugin-react";
import * as fs from "fs";
import * as path from "path";
import { defineConfig } from "vite";
// https://vitejs.dev/config/
export default defineConfig(((conf: { command: string }) => ({
plugins: [react()],
optimizeDeps: {},
build: {
sourcemap: true,
},
resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
? {}
: ({
// The repo-wide alias for the shared test-utils directory (private,
// so it only resolves inside the monorepo). Harmless for examples
// that don't use it.
"@shared": path.resolve(__dirname, "../../../shared/"),
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../../packages/core/src/",
),
"@blocknote/react": path.resolve(
__dirname,
"../../../packages/react/src/",
),
} as any),
},
})) as Parameters<typeof defineConfig>[0]);
9 changes: 9 additions & 0 deletions examples/08-extensions/04-embeds-with-backend/.bnexample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"playground": true,
"docs": false,
"author": "",
"tags": ["Extension", "Custom Blocks"],
"dependencies": {
"@blocknote/embeds": "latest"
}
}
11 changes: 11 additions & 0 deletions examples/08-extensions/04-embeds-with-backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Embeds with a backend

The same minimal paste-and-choose flow as [the browser-only example](https://playground.blocknotejs.org/extensions/embeds-without-backend), with a standard oEmbed endpoint for saved bookmark metadata and optional live generic previews. No request starts until Bookmark or Embed is chosen.

Run the playground and open `/extensions/embeds-with-backend`; its existing local-development resolver is connected automatically. For a standalone app, set `VITE_OEMBED_URL=https://your-app.example/oembed` in the serving Vite application's `.env.local` and restart it. Without an endpoint, direct providers and useful URL-only fallbacks still work.

The default client accepts raw oEmbed 1.0 JSON, including the existing `@blocknote/xl-embed-server` metadata extensions. Save bookmark metadata once through the small typed callback; mount and reload do not resolve it again. Live providers own their loading and rendering.

An oEmbed response is untrusted data, not authorization to run HTML. Generic iframe rendering is denied unless its exact HTTPS origin is explicitly approved; same-origin application frames are always denied. Unsupported rich HTML becomes a source/metadata card. No upstream scripts or HTML are inserted.

The existing reference server requires application-supplied protected outbound fetching: plain global fetch is not an SSRF-safe server transport. Authentication, CORS, rate limits and deployment remain application-owned. Keep secrets on the server. This example does not persist documents across reloads.
17 changes: 17 additions & 0 deletions examples/08-extensions/04-embeds-with-backend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, interactive-widget=resizes-content"
/>
<title>Embeds with a backend</title>
<script>
<!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY -->
</script>
</head>
<body>
<div id="root"></div>
<script type="module" src="./main.tsx"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions examples/08-extensions/04-embeds-with-backend/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY
import React from "react";
import { createRoot } from "react-dom/client";
import App from "./src/App.jsx";

const root = createRoot(document.getElementById("root")!);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
31 changes: 31 additions & 0 deletions examples/08-extensions/04-embeds-with-backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@blocknote/example-extensions-embeds-with-backend",
"description": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY",
"type": "module",
"private": true,
"version": "0.12.4",
"scripts": {
"start": "vite",
"dev": "vite",
"build:prod": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"@blocknote/ariakit": "latest",
"@blocknote/core": "latest",
"@blocknote/mantine": "latest",
"@blocknote/react": "latest",
"@blocknote/shadcn": "latest",
"@mantine/core": "^9.0.2",
"@mantine/hooks": "^9.0.2",
"react": "^19.2.3",
"react-dom": "^19.2.3",
"@blocknote/embeds": "latest"
},
"devDependencies": {
"@types/react": "^19.2.3",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^6.0.1",
"vite": "^8.0.0"
}
}
Loading
Loading