Embed the editor
This page is for developers. The Editor is available as a React component, so you can open it inside your own application instead of sending people to a separate address. The component loads a document, lets the user edit it, and gives control back to your code when the user publishes or discards.
The document does not start in the component. Your system creates it through the Pages service, as described in Editor integration and Create documents with the Web Editor, and that call returns the values the component needs.
Your application -> the Editor component -> the Editor API -> Doxis InteractInstall and render
The package is @metaforcelabs/metaforce-webeditor. It is restricted, so install it with an npm token that
can read the @metaforcelabs scope.
import { createRoot } from "react-dom/client";
import { MetaforceProvider, WebEditorDesign } from "@metaforcelabs/metaforce-webeditor";
const configurations = {
startParameter: "START_PARAMETER",
apiBaseUrl: "API_BASE_URL",
internalApiKey: "INTERNAL_API_KEY",
docId: "DOC_ID",
};
createRoot(document.getElementById("root")).render(
<MetaforceProvider configurations={configurations}>
<WebEditorDesign nav="edit" />
</MetaforceProvider>
);- Always pass
nav="edit"toWebEditorDesign. Without it you get the attachment table instead of the editor. - Render one
MetaforceProviderper page. It writes the API address and key to a shared global object, so two providers on one page overwrite each other.
The configurations object
| Field | Required | What it is |
|---|---|---|
startParameter | Yes | The token of the document session. It is part of the address of every call the component makes. |
apiBaseUrl | Yes | The base address of the Editor API. Metaforce gives you this for each environment. |
internalApiKey | Yes | A key for your environment, provided by Metaforce. It is not a key for a single user, but keep it out of public source control. |
docId | Yes | The id of the document. |
jobId | No | The id of a local print job. |
publishedAttachmentId | No | The id for previewing a published attachment. |
jwt | No | A one-time token for the first load of the document. |
startParameter, docId, jobId and jwt belong to one document, and your backend produces them. The
component never fetches them. A missing required value shows up as a visible text such as
NO START PARAMETER SET in the requests the component makes, which makes the mistake easy to find.
The one-time token
When you pass jwt, the component sends it on the first load only. The Editor API answers with a session
token that the component keeps for the rest of the session. Right after the first load the component calls
onOneTimeJwtUsed. Use it to remove jwt from the address so that it cannot be used again. Treat the token as a
secret: never log it and never leave it in an address that can be shared.
MetaforceProvider properties
| Property | What it does |
|---|---|
configurations | The object above. Required. |
publish | Optional. When you pass it, the component saves the document, sets the status to OK, calls your function, and does not open its own Distribution window. Your application then owns the delivery. Distribution must be switched off for the environment in Pages Manager. If it is on, the Editor shows (507) and does not publish. |
discard | Optional. Called after the document has been discarded. |
toastHandler | (message, type, event). Shows success and error messages. type is "success" or "error", and event is "publishSucceeded" or "publishFailed" for the outcome of a publish. |
customErrorHandler | Receives structured errors, with message, customErrorMessage, validationErrors and error, for your own error display. |
successAfterFailedToSaveHandler | Called when a save works after an earlier save failed. Use it to turn on anything you turned off. |
themeAndStyle | Shows, hides and restyles parts of the editor. See below. |
onOneTimeJwtUsed | Called right after the one-time token was used. |
Publish and discard are final. After either, the document is locked.
Change how the editor looks
themeAndStyle is optional, and so is every field in it.
| Field | Default | What it does |
|---|---|---|
hideTopBar | false | Hides the whole top bar, with the Editor title and the Edit and Attachment tabs. |
hideContextMenu | false | Hides the Edit and Attachment tabs and keeps the rest of the top bar. |
removeMarginAndPadding | false | Removes the outer space, for tight layouts. |
hideActionButtonText | false | Shows icons without labels. |
actionButtons | Settings for single buttons. |
actionButtons has one entry for each of predefined, library, preview, publish, discard, undo and
redo. Each entry can set hide, text (the label), icon and className. The entry splitScreen can set
hide, onText, offText, onIcon, offIcon and className.
themeAndStyle={{
hideActionButtonText: true,
actionButtons: {
predefined: { hide: true },
publish: { text: "Send" },
},
}}Note:
classNameis applied to the editor’s own elements, and their class names can change in any release. Usetextandiconfor branding andclassNameonly when you have to.
Other screens
The package also exports HtmlPreview, PdfPreview, AttachmentPreview, LocalprintDynamoPdf and
LocalprintViewpointPdf. Render them inside the same MetaforceProvider.
Get the result
Your own code calls the public API, not the component’s internal routes. Use an OAuth bearer token, as described in
Authentication. {customerEnvironment} and {environmentGroupNameOrId} come from your
setup, and {dxmlUID} is the id the document was created with.
| Purpose | Call |
|---|---|
| Read the status | GET {customerEnvironment}/status/{dxmlUID}/{environmentGroupNameOrId} returns Draft, OK, Discarded or Deleted as plain text. |
| Get the PDF | GET {customerEnvironment}/pdf/dxml/{dxmlUID}/{environmentGroupNameOrId} returns the PDF, or 404 if there is no document. |
| Read up to 50 statuses | POST {customerEnvironment}/status/{environmentGroupNameOrId} with a list of ids. |
| Discard from your side | PUT {customerEnvironment}/status/discard/{dxmlUID}/{environmentGroupNameOrId} |
| List documents | GET {customerEnvironment}/status returns the documents of your company, each with its id, status, created time and modified time. |
| List draft or OK documents | GET {customerEnvironment}/status/draft/{startUtcTime}/{endUtcTime}/{environmentGroupNameOrId} and GET {customerEnvironment}/status/ok/{startUtcTime}/{endUtcTime}/{environmentGroupNameOrId} return the ids of the documents that were created in the period and have that status now. |
List documents takes optional query parameters. status can be repeated, for example status=OK&status=Draft,
and accepts Draft, OK, Discarded and Deleted. createdStart, createdEnd, modifiedStart and modifiedEnd limit
the list to a period, both ends included. When your setup has extra environment groups in Pages Manager, pass the
group as environmentGroupNameOrId. Without parameters you get every document.
For both kinds of list, a start that is later than its end is refused. The API widens every period by five minutes at each end, so a document just outside it can be in the result.
For example, to list the documents that are still drafts, send a GET request with the header
Authorization: Bearer <token> to this address:
https://api.webeditor-v4.metaforce.net/{customerEnvironment}/status?status=Draft
Get the PDF does not look at the status. A discarded document still returns a PDF. If you need to tell the difference, read the status first.
To create documents, see Create documents with the Web Editor. To get a callback when a document is finished, see Editor integration. For the full list of calls, see the Pages v4 (webeditor-v4) API documentation under Available APIs.
Troubleshooting
| What you see | Why | What to do |
|---|---|---|
| The attachment table instead of the editor | nav is missing or is not "edit" | Pass nav="edit". |
Requests go to an address that ends in NO START PARAMETER SET | A required value is missing in configurations | Set startParameter, apiBaseUrl, internalApiKey and docId. |
| The first load works and later loads fail with 401 | The one-time token was used again | Remove jwt in onOneTimeJwtUsed and use the session token. |
| Two editors on one page behave strangely | Two providers share one global object | Render one MetaforceProvider. |