Editor embedding
Configuration reference
Every config field: document, editor, ui, token and events, with types, defaults, the document.key rules and the invalid_config error.
new O3O.Editor(elementId, config) takes the container id (or the DOM element itself) and a config object with four groups: document, editor, ui, token, plus events, which stays in the browser. The constructor returns at once; the session is created asynchronously and errors go through onError.
- Element not found: the constructor throws
Error("O3O.Editor: không tìm thấy phần tử ..."). - Each container holds ONE editor. Calling the constructor again on the same element before
destroy()throws. - The container needs a real height (for example
height: 100vh) because the frame defaults to100%.
const config = {
document: {
url: "https://files.example.com/contracts/42.docx", // the gate downloads the source file from here
title: "Contract 42.docx",
fileType: "docx",
key: "contract-42-v7" // identifies a content VERSION
},
editor: {
mode: "edit", // "edit" | "view"
lang: "en-US",
user: { id: "u-1001", name: "Jane Doe" },
callbackUrl: "https://app.example.com/o3o/callback"
},
ui: {
width: "100%",
height: "100%",
mode: "tabbed", // "tabbed" | "compact"
closeButton: true,
saveButton: true,
print: true,
export: true,
copy: true,
userList: true,
statusbar: true,
menubar: false,
limitBanner: true
},
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", // required when the server sets O3O_EMBED_JWT_SECRET
events: {
onSaved: (e) => console.log(e.version)
}
};
const editor = new O3O.Editor("o3o-editor", config);document#
document (required)
document.urlstring (URL)requiredhttporhttpsURL the GATE downloads the source file from. Subject to the SSRF rules. The browser never fetches it.document.titlestring, 1–255 charsrequiredDisplay name. Without an extension the gate appends.+fileType. The nine characters forbidden in Windows file names and control characters become_.document.fileTypestringrequiredOne ofdocx,doc,odt,rtf,txt,xlsx,xls,ods,csv,pptx,ppt,odp. Lower case, no dot.document.keystringrequiredIdentifies a content VERSION, matches^[A-Za-z0-9._-]{1,128}$. Everyone opening the samekeyedits one shared document. See the rules below.
Rules for document.key#
- The gate downloads
document.urlonly for the FIRST user of akey; later users join the open copy and theirurlis ignored. - After the
closedcallback, the next open MUST use a newkey(append a version number or the file's modification time). - Reusing an old
keywithin the retention time (24 hours) reopens the last working copy the gate holds, WITHOUT downloadingurlagain. - Internal document id:
doc_id = "doc_" + first 32 hex chars of SHA-256(key).
editor#
editor (required)
editor.mode"edit" | "view"optionalDefault:"edit"viewis read-only and is NOT counted as a connection.editor.langstringoptionalDefault:"vi"Interface language code, e.g.vi,en-US.editor.user.idstring, 1–64 charsrequiredUser id in your system.editor.user.namestring, 1–128 charsoptionalDefault:"Khách"Display name in the co-editor list.editor.callbackUrlstring (URL)optionalWhere the gate sends callbacks when a new version is saved (see saving and callbacks). Subject to the SSRF rules. Without it, edited copies stay on the gate for the retention time and the page gets them throughonSaved.
ui#
Optional. Leaving a field out keeps the editor server default. The table lists only what v1 actually implements.
ui (optional)
ui.widthCSS stringoptionalDefault:"100%"Frame width.ui.heightCSS stringoptionalDefault:"100%"Frame height. The container must have a real height.ui.mode"tabbed" | "compact"optionalDefault:"tabbed"Tabbed or compact toolbar.ui.closeButtonbooleanoptionalDefault:falseShows a close button; clicking it firesonClose.ui.saveButtonbooleanoptionalDefault:truefalsehides the save command (autosave still runs).ui.printbooleanoptionalDefault:truefalsehides and blocks printing.ui.exportbooleanoptionalDefault:truefalsehides and blocks downloading in other formats.ui.copybooleanoptionalDefault:truefalseblocks copying content out of the frame.ui.userListbooleanoptionalDefault:trueShows the co-editor list.ui.statusbarbooleanoptionalDefault:server defaultStatus bar, applied once the document has loaded.ui.menubarbooleanoptionalDefault:server defaultMenu bar, only meaningful withmode: "compact"; applied after loading.ui.limitBannerbooleanoptionalDefault:trueVietnamese banner thatapi.jsdraws above the frame when a session is downgraded to read-only by the cap.
theme (light, dark), logo, productName, primaryColor (white label, enterprise edition with the source-built O3O image), watermark, per-button visibility, ruler, sidebar. v1 ignores these fields and prints a console warning.
token and events#
Remaining fields
tokenstring (JWT)optionalOptional on DEV machines, REQUIRED when the server setsO3O_EMBED_JWT_SECRET. With a valid token the gate usesdocument,editor,uiFROM the token. See signing the config.eventsobjectoptionalCallback functions, see events. Never sent to the server.
When the config is invalid#
The gate validates the config before anything else. Missing or wrong fields give 400 invalid_config with a list in detail.errors shaped as {path, message}, and onError fires with the same code. The message wording below is illustrative.
{
"error": {
"code": "invalid_config",
"message": "Cấu hình trình soạn thảo không hợp lệ.",
"detail": {
"errors": [
{
"path": "document.key",
"message": "Chỉ gồm chữ, số, dấu chấm, gạch dưới, gạch nối; tối đa 128 ký tự."
}
]
},
"request_id": "req_0123456789abcdef"
}
}