Skip to content

Commit 687f5b8

Browse files
committed
docs: Add Image and Files block documentation with examples
- Introduced detailed sections for Image Block and Files Block in the API reference. - Included JSON structure, attributes, and common use cases for both blocks. - Added recommended usage examples in Python for embedding images and attaching files. - Enhanced guides with practical examples for integrating images and files in documents.
1 parent e95ac31 commit 687f5b8

2 files changed

Lines changed: 590 additions & 2 deletions

File tree

docs-site/docs/api-reference/document-structure.md

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,231 @@ client.replace_json_document(document_id, content)
12421242

12431243
---
12441244

1245+
## Image Block
1246+
1247+
Embedded images in documents and task descriptions.
1248+
1249+
**Structure:**
1250+
```json
1251+
{
1252+
"type": "image-block",
1253+
"attrs": {
1254+
"uid": "uniqueIdXYZ",
1255+
"custom": 1,
1256+
"contenteditable": "false",
1257+
"widthPercent": 100
1258+
},
1259+
"content": [
1260+
{
1261+
"type": "text",
1262+
"text": "{\"id\":\"img123\",\"src\":\"https://...\",\"fileName\":\"screenshot.png\",\"fileType\":\"image/png\",\"extension\":\"png\",\"title\":\"screenshot.png\",\"fileSize\":123456,\"fileId\":\"file_id\",\"dimensions\":[800,600],\"aspectRatio\":1.33,\"caption\":\"Screenshot\"}"
1263+
}
1264+
]
1265+
}
1266+
```
1267+
1268+
**Image Data Fields:**
1269+
- `id` - Unique image ID (generated)
1270+
- `src` - Image URL (from upload_file)
1271+
- `fileName` - File name
1272+
- `fileType` - MIME type (e.g., "image/png", "image/jpeg")
1273+
- `extension` - File extension (e.g., "png", "jpg")
1274+
- `title` - Image title (usually same as fileName)
1275+
- `fileSize` - File size in bytes
1276+
- `fileId` - File ID from upload_file response
1277+
- `dimensions` - Optional [width, height] array
1278+
- `aspectRatio` - Optional aspect ratio (width/height)
1279+
- `caption` - Optional caption text
1280+
- `dominantColor` - Optional color object
1281+
1282+
**Attributes:**
1283+
- `uid` - Unique block identifier
1284+
- `custom` - Always 1 for custom blocks
1285+
- `contenteditable` - Should be "false"
1286+
- `widthPercent` - Display width percentage (1-100)
1287+
1288+
**Using Helper (Recommended):**
1289+
```python
1290+
from vaiz import image_block, heading, paragraph
1291+
1292+
# Upload image first
1293+
uploaded = client.upload_file("photo.jpg")
1294+
1295+
# Create image block
1296+
image = image_block(
1297+
file_id=uploaded.file.id,
1298+
src=uploaded.file.url,
1299+
file_name="photo.jpg",
1300+
file_size=uploaded.file.size,
1301+
extension="jpg",
1302+
file_type="image/jpeg",
1303+
dimensions=[1920, 1080],
1304+
caption="Product photo",
1305+
width_percent=75
1306+
)
1307+
1308+
content = [
1309+
heading(1, "Gallery"),
1310+
paragraph("Check out our latest product:"),
1311+
image
1312+
]
1313+
1314+
client.replace_json_document(document_id, content)
1315+
```
1316+
1317+
**Common Use Cases:**
1318+
- Screenshots in bug reports
1319+
- Product images in documentation
1320+
- Diagrams and flowcharts
1321+
- Photo galleries
1322+
- Visual examples in guides
1323+
1324+
---
1325+
1326+
## Files Block
1327+
1328+
File attachments (PDFs, documents, archives, etc.) in documents.
1329+
1330+
**Structure:**
1331+
```json
1332+
{
1333+
"type": "files",
1334+
"attrs": {
1335+
"uid": "uniqueIdDEF",
1336+
"custom": 1,
1337+
"contenteditable": "false"
1338+
},
1339+
"content": [
1340+
{
1341+
"type": "text",
1342+
"text": "{\"files\":[{\"id\":\"fileItem1\",\"fileId\":\"uploaded_file_id\",\"createAt\":1234567890000,\"url\":\"https://...\",\"extension\":\"pdf\",\"name\":\"Report.pdf\",\"size\":245678,\"type\":\"Pdf\"}]}"
1343+
}
1344+
]
1345+
}
1346+
```
1347+
1348+
**Files Data Structure:**
1349+
- `files` - Array of file items
1350+
1351+
**File Item Fields:**
1352+
- `id` - Unique file item ID (generated)
1353+
- `fileId` - File ID from upload_file response
1354+
- `createAt` - Timestamp in milliseconds
1355+
- `url` - File download URL
1356+
- `extension` - File extension
1357+
- `name` - Display name
1358+
- `size` - File size in bytes
1359+
- `type` - File type category (see below)
1360+
- `dominantColor` - Optional color object
1361+
1362+
**File Type Categories:**
1363+
- `Pdf` - PDF documents
1364+
- `Image` - Images (prefer image_block instead)
1365+
- `Video` - Video files
1366+
- `Excel` - Spreadsheets (.xlsx, .xls, .csv)
1367+
- `PowerPoint` - Presentations (.pptx, .ppt)
1368+
- `Word` - Word documents (.docx, .doc)
1369+
- `Archive` - Compressed files (.zip, .rar, .tar.gz)
1370+
- `Text` - Text files (.txt, .md)
1371+
- `Code` - Source code files
1372+
- `Other` - Generic files
1373+
1374+
**Using Helper (Recommended):**
1375+
```python
1376+
from vaiz import files_block, heading, paragraph
1377+
1378+
# Upload files
1379+
pdf = client.upload_file("report.pdf")
1380+
excel = client.upload_file("data.xlsx")
1381+
1382+
# Create file items
1383+
files = [
1384+
{
1385+
"fileId": pdf.file.id,
1386+
"url": pdf.file.url,
1387+
"name": "Q4 Report.pdf",
1388+
"size": pdf.file.size,
1389+
"extension": "pdf",
1390+
"type": "Pdf"
1391+
},
1392+
{
1393+
"fileId": excel.file.id,
1394+
"url": excel.file.url,
1395+
"name": "Sales Data.xlsx",
1396+
"size": excel.file.size,
1397+
"extension": "xlsx",
1398+
"type": "Excel"
1399+
}
1400+
]
1401+
1402+
content = [
1403+
heading(1, "Quarterly Report"),
1404+
paragraph("Attached documents:"),
1405+
files_block(*files)
1406+
]
1407+
1408+
client.replace_json_document(document_id, content)
1409+
```
1410+
1411+
**Common Use Cases:**
1412+
- Report attachments
1413+
- Source code archives
1414+
- Documentation PDFs
1415+
- Data exports (CSV, Excel)
1416+
- Log files
1417+
- Configuration files
1418+
1419+
**Combining Images and Files:**
1420+
```python
1421+
from vaiz import heading, paragraph, image_block, files_block, horizontal_rule
1422+
1423+
# Upload files
1424+
screenshot = client.upload_file("app.png")
1425+
manual = client.upload_file("manual.pdf")
1426+
source = client.upload_file("source.zip")
1427+
1428+
content = [
1429+
heading(1, "Release v2.0"),
1430+
1431+
# Image
1432+
paragraph("New interface:"),
1433+
image_block(
1434+
file_id=screenshot.file.id,
1435+
src=screenshot.file.url,
1436+
file_name="app.png",
1437+
file_size=screenshot.file.size,
1438+
caption="Main screen"
1439+
),
1440+
1441+
horizontal_rule(),
1442+
1443+
# Files
1444+
paragraph("Download resources:"),
1445+
files_block(
1446+
{
1447+
"fileId": manual.file.id,
1448+
"url": manual.file.url,
1449+
"name": "User Manual.pdf",
1450+
"size": manual.file.size,
1451+
"extension": "pdf",
1452+
"type": "Pdf"
1453+
},
1454+
{
1455+
"fileId": source.file.id,
1456+
"url": source.file.url,
1457+
"name": "Source Code.zip",
1458+
"size": source.file.size,
1459+
"extension": "zip",
1460+
"type": "Archive"
1461+
}
1462+
)
1463+
]
1464+
1465+
client.replace_json_document(document_id, content)
1466+
```
1467+
1468+
---
1469+
12451470
## Supported Elements
12461471

12471472
### Blocks

0 commit comments

Comments
 (0)