Base concepts
What BlockWriteAI gives your app
BlockWriteAI is a block-style editor for products that need structured content. Instead of treating one large HTML string as the saved document, the editor returns clean JSON made of independent blocks such as paragraphs, headings, tables, media, code, charts, columns, signatures, and premium tools.
Block-styled editing
Each content unit is handled as a separate block, making editing, reordering, previews, and backend processing easier.
Clean data output
Save JSON in MySQL, SQLite, your API, or any CMS table. Render it later with `BlockWriteAI.renderPreview()`.
Plugin-ready workflow
Load core tools, advanced free tools, and premium tools through clear asset and API boundaries.
{
"time": 1782159209888,
"version": "1.2.6",
"blocks": [
{ "type": "paragraph", "data": { "text": "Hello BlockWriteAI" } },
{ "type": "heading", "data": { "text": "Structured content", "level": 2 } }
]
}
Quick start
Choose your integration path
PHP/MySQL CDN app
Best for a classic PHP CRUD product. Load assets from `cdn.blockwriteai.in`, store editor JSON in MySQL, and protect premium calls behind `premium_proxy.php`.
JavaScript demo with PHP APIs
Best for a Vite or SPA-style UI. Keep the local API for documents and use the BlockWriteAI platform API for premium features.
Python/SQLite CRUD
Best for Python prototypes. Use `pip install blockwriteai-editor`, copy package assets locally, and proxy premium APIs through same-origin Python routes.
- Create storage. Add a `documents` table with `title`, `content_json`, `created_at`, and `updated_at`.
- Load assets. Add BlockWriteAI CSS, core JS, code assist, and advanced blocks before your app script.
- Initialize editor. Mount `new BlockWriteAI({ holder, data, onSave, upload })` into your page.
- Save JSON. Send `editor.save()` output to your backend and store it exactly as JSON.
- Render previews. Load saved JSON and call `BlockWriteAI.renderPreview()` for read-only output.
- Add premium safely. Keep the real license key on the server and expose only a short-lived browser token.
Assets
Load BlockWriteAI from the distribution CDN
For protected production builds, build every asset URL from the distribution origin. The protected JavaScript file replaces `blockwriteai.min.js` when `BLOCKWRITEAI_USE_PROTECTED_BUILD` is true.
const BLOCKWRITEAI_DISTRIBUTION_BASE = 'https://cdn.blockwriteai.in';
const BLOCKWRITEAI_CDN_BASE = BLOCKWRITEAI_DISTRIBUTION_BASE . '/cdn/latest';
const BLOCKWRITEAI_DISTRIBUTION_BUILD = '1.2.6-protected-v1';
const BLOCKWRITEAI_USE_PROTECTED_BUILD = true;
function blockwriteai_asset_url(string $asset): string
{
if (BLOCKWRITEAI_USE_PROTECTED_BUILD && $asset === 'blockwriteai.min.js') {
$asset = 'blockwriteai.protected.min.js';
}
return rtrim(BLOCKWRITEAI_CDN_BASE, '/') . '/' . ltrim($asset, '/') . '?v=' . rawurlencode(BLOCKWRITEAI_DISTRIBUTION_BUILD);
}
define('BLOCKWRITEAI_CSS', blockwriteai_asset_url('blockwriteai.min.css'));
define('BLOCKWRITEAI_JS', blockwriteai_asset_url('blockwriteai.min.js'));
define('BLOCKWRITEAI_CODE_ASSIST', blockwriteai_asset_url('blockwriteai-code-assist.min.js'));
define('BLOCKWRITEAI_ADVANCED', blockwriteai_asset_url('blockwriteai-advanced-blocks.min.js'));
Load CSS in the page head, then load JavaScript before your initialization script.
<link rel="stylesheet" href="<?= htmlspecialchars(BLOCKWRITEAI_CSS) ?>">
<script src="<?= htmlspecialchars(BLOCKWRITEAI_JS) ?>"></script>
<script src="<?= htmlspecialchars(BLOCKWRITEAI_CODE_ASSIST) ?>"></script>
<script src="<?= htmlspecialchars(BLOCKWRITEAI_ADVANCED) ?>"></script>
Editor setup
Initialize the editor with existing JSON or an empty document
When editing an existing document, decode `content_json` from your database. For a new document, pass an empty `blocks` array.
const initialData = {
time: Date.now(),
version: "1.2.6",
blocks: []
};
window.editor = new BlockWriteAI({
holder: "#editor",
data: initialData,
placeholder: "Start writing or press / for blocks",
minHeight: "520px",
autofocus: true,
saveButton: true,
uploadOutput: ["upload", "base64"]
});
Common tool groups
| Group | Tools |
|---|---|
| Core/free | paragraph, heading, quote, list, checklist, code, image, table, embed, callout, delimiter, button, toggle, linkPreview, raw, attaches |
| Advanced free | chart, latex, audio, columns |
| Premium | drawing, mermaid, signature, signatureFlow, AI actions |
CRUD
Save and manage documents
A minimal CRUD app needs list, create/edit, save, preview, delete, and upload endpoints. In PHP, the classic structure is:
index.php -> list documents
editor.php -> create or edit
save.php -> save JSON
view.php -> render saved JSON
delete.php -> delete document
upload.php -> receive files/images
Use a document table that stores the exact editor JSON:
CREATE TABLE documents (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
content_json LONGTEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
On save, validate the title and editor data, encode JSON, then insert or update.
const content = await editor.save();
await fetch("save.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: documentId,
title,
data: content
})
});
Uploads
Connect image and file blocks to your backend
Configure upload callbacks in the editor and return a JSON object with `url`, `name`, `size`, and `type` from your server.
upload: {
file: (file) => uploadFile(file, "file"),
image: (file) => uploadFile(file, "image")
}
async function uploadFile(file, kind) {
const body = new FormData();
body.append("file", file);
body.append("kind", kind);
const response = await fetch("upload.php", { method: "POST", body });
const result = await response.json();
if (!response.ok || !result.url) throw new Error(result.error || "Upload failed.");
return result;
}
Image extensions
jpg, jpeg, png, gif, webp, svg
File extensions
mp3, wav, ogg, m4a, aac, flac, webm, mp4, pdf, doc, docx, xls, xlsx, ppt, pptx, csv, txt, rtf, odt, ods, odp
Preview
Render saved JSON as a read-only document
Load the saved JSON from your backend and pass it to `BlockWriteAI.renderPreview()`.
<div id="preview"></div>
BlockWriteAI.renderPreview("#preview", data, {
shell: false
});
If premium blocks are used in the saved document, load premium plugins first and pass the same premium endpoints used by the editor.
Signatures
Store completed signature events locally
The platform `signature_event` endpoint is required by the premium signature plugin. Your local database can also store completed signature events for audit/history.
document.addEventListener("blockwriteai:signature-signed", (event) => {
const box = event.target.closest(".rbe-output-signature");
const key = box ? (box.dataset.signatureStorageKey || box.dataset.signatureId || "") : "";
if (!key) return;
fetch("signature_save.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
document_id: documentId,
signature_type: "signature",
signature_key: key,
payload: event.detail || {}
})
});
});
For signature flow, listen for `blockwriteai:signature-flow-signed` and store `flowId`, `stepId`, signer details, IP address, signature hash, signed timestamp, and the full payload JSON.
API reference
Use the right endpoint for the right responsibility
| Endpoint | Purpose |
|---|---|
| premium_plugins.php | Returns authorized premium plugin JavaScript. |
| license_verify.php | Validates premium license and can return a fresh browser token through your proxy. |
| ai_generate.php | Generates AI-assisted editor content. |
| ai_usage.php | Checks or tracks AI usage limits. |
| premium_usage.php | Tracks premium feature usage. |
| premium_event.php | Records premium audit/events. |
| signature_event.php | Handles signature and signature-flow platform events. |
All platform APIs use `https://blockwriteai.in`. Your local document APIs stay separate and should only manage your app data.
Python
Build a Python/SQLite CRUD app
The Python example uses `pip install blockwriteai-editor`, copies static assets into your app, stores documents in SQLite, and proxies premium requests through same-origin routes.
py -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install blockwriteai-editor
python app.py
from blockwriteai_editor import copy_static
BLOCKWRITEAI_DIR = STATIC_DIR / "blockwriteai"
copy_static(BLOCKWRITEAI_DIR)
Recommended `.env` keys:
PORT=8766
BLOCKWRITEAI_SERVICE_BASE=https://blockwriteai.in
BLOCKWRITEAI_PUBLIC_ORIGIN=http://127.0.0.1:8766
AUTH_TOKEN_TTL_SECONDS=3600
BLOCKWRITEAI_LICENSE_KEY=bwai_live_your_license_key_here
BLOCKWRITEAI_TOKEN_SECRET=replace-this-with-a-long-random-secret
Examples
Sample project README references
Choose a sample project to view its complete README as formatted HTML. Every fenced code block includes a copy button for commands, CDN snippets, API code, and configuration examples.
Troubleshooting
Common problems and fixes
Premium tools do not load
Confirm the license key exists on the server, the proxy points to `https://blockwriteai.in`, and `premium_plugins` returns JavaScript.
Authorization token is invalid
The token normally expires after one hour. Refresh the editor and confirm the token secret did not change.
Advanced tools are missing
Load `blockwriteai-advanced-blocks.min.js` and include chart, latex, audio, or columns in your tool configuration.
Uploads fail
Check write permission for the uploads directory and verify the file extension is allowed by your upload endpoint.
Signature is not saved locally
Use the platform signature endpoint for the plugin, then separately listen for browser signature events and post to your local save endpoint.
PHP OpenSSL warning
If PHP says OpenSSL is already loaded, it is a local PHP configuration issue and not caused by BlockWriteAI project code.
Checklist
Production integration checklist
- Create document storage and save editor JSON exactly as returned.
- Load CSS, protected core JS, code assist, and advanced blocks from the CDN.
- Initialize the editor with `holder`, `data`, `placeholder`, upload callbacks, and save callback.
- Implement create, read, update, delete, preview, upload, and local signature save endpoints.
- Keep premium license keys in server config or `.env`, never in public JavaScript.
- Issue and validate short-lived browser authorization tokens.
- Proxy premium plugins, license verification, AI, premium usage, premium events, and signature events.
- Render previews from saved JSON and replay saved signatures where needed.
- Use HTTPS, restrict upload size/types, add authentication, and protect secrets before production.