@camunda/form-playground

中文文档
0.28.0发布于 2026/10/20MITESM + CJS近 30 天下载 1.8万

Camunda Form Playground.

原始使用文档
文档目录24 节
  1. Usage
  2. Styling
  3. API
  4. createCamundaFormPlayground => Promise<Result, Error>
  5. CamundaFormPlayground
  6. Options
  7. CamundaFormPlayground#open(containers?: string[]) => void
  8. CamundaFormPlayground#collapse(containers?: string[]) => vo…
  9. CamundaFormPlayground#get(type: String, strict: Boolean) =>…
  10. CamundaFormPlayground#getDataEditor() => JSONEditor
  11. CamundaFormPlayground#getEditor() => FormEditor
  12. CamundaFormPlayground#getForm() => Form
  13. CamundaFormPlayground#getResultView() => JSONEditor
  14. CamundaFormPlayground#getSchema() => any
  15. CamundaFormPlayground#setSchema(schema: any) => void
  16. CamundaFormPlayground#saveSchema() => any
  17. CamundaFormPlayground#attachTo(parent: HTMLElement) => void
  18. CamundaFormPlayground#detach() => void
  19. CamundaFormPlayground#fire(event) => void
  20. CamundaFormPlayground#on(event, fn) => void
  21. CamundaFormPlayground#off(event, fn) => void
  22. CamundaFormPlayground#destroy() => void
  23. Hacking the Project
  24. License

@camunda/form-playground

CI

Camunda Form Playground.

Usage

Integrate the playground into your application:

import { createCamundaFormPlayground } from 'camunda/form-playground';

const formPlayground = await createCamundaFormPlayground({
  container: document.querySelector('#container'),
  data,
  schema
});

// open preview
formPlayground.open();

// close preview
formPlayground.collapse();

// listen on editor events
const formEditor = formPlayground.getEditor();

formEditor.on('selection.changed', () => { ... });

Styling

For proper styling include the necessary stylesheets, and font used:

<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,600;1,400&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&display=swap" rel="stylesheet">

<link rel="stylesheet" href="https://unpkg.com/@camunda/[email protected]/dist/assets/form-js.css">
<link rel="stylesheet" href="https://unpkg.com/@camunda/[email protected]/dist/assets/form-js-editor.css">
<link rel="stylesheet" href="https://unpkg.com/@camunda/[email protected]/dist/assets/camunda-form-playground.css">

API

createCamundaFormPlayground => Promise<Result, Error>

Create a fully rendered form playground with options.

import { createFormPlayground } from '@camunda/form-playground';

const formPlayground = await createFormPlayground({
  container: document.querySelector('#form-playground'),
  data,
  schema
});

CamundaFormPlayground

Create a new form playground with options.

import { CamundaFormPlayground } from '@camunda/form-playground';

const formPlayground = new CamundaFormPlayground({
  container: document.querySelector('#form-playground'),
  data,
  schema
});

Options

There are several options that can be passed to the createFormPlayground or CamundaFormPlayground:

{
  container: HTMLElement,               // optional - the container to render the form playground into
  data: {},                             // required - set the initial form data
  schema: {},                           // required - set the initial form schema
  exporter: { name: '', version: '' },  // optional - set the schema exporter name and version
  layout: {},                           // optional - set the initial form layout
  editorAdditionalModules: [],          // optional - add additional modules to the form editor
  viewerAdditionalModules: [],          // optional - add additional modules to the form preview
  editorProperties: {},                 // optional - set the initial form editor properties
  viewerProperties: {},                 // optional - set the initial form preview properties
}

As an example, you can use the viewerProperties to override the default behavior to open external links in a new tab:

viewerProperties: {
  textLinkTarget: '_blank'
}

CamundaFormPlayground#open(containers?: string[]) => void

Open all or specific playground containers.

// open all
formPlayground.open();

// open specific
formPlayground.open([ 'form-preview' ]);

CamundaFormPlayground#collapse(containers?: string[]) => void

Collapse all or specific playground containers.

// collapse all
formPlayground.collapse();

// collapse specific
formPlayground.collapse([ 'form-preview' ]);

CamundaFormPlayground#get(type: String, strict: Boolean) => any

Get a service from the embedded form editor.

const eventBus = formPlayground.get('eventBus');

CamundaFormPlayground#getDataEditor() => JSONEditor

Get the embedded input data editor.

const dataEditor = formPlayground.getDataEditor();

const data = dataEditor.getValue();

CamundaFormPlayground#getEditor() => FormEditor

Get the embedded form editor.

const editor = formPlayground.getEditor();

editor.on('selection.changed', () => { ... });

CamundaFormPlayground#getForm() => Form

Get the embedded preview form.

const form = formPlayground.getForm();

form.on('submit', event => {
  console.log('Form <submit>', event);
});

CamundaFormPlayground#getResultView() => JSONEditor

Get the embedded output data view.

const resultView = formPlayground.getResultView();

const data = resultView.getValue();

CamundaFormPlayground#getSchema() => any

Get the current form schema.

CamundaFormPlayground#setSchema(schema: any) => void

Set the form schema.

CamundaFormPlayground#saveSchema() => any

Export the form schema from the embedded form editor.

const schema = formPlayground.saveSchema(schema);

console.log('exported schema', schema);

CamundaFormPlayground#attachTo(parent: HTMLElement) => void

Attach the form playground to a parent node.

CamundaFormPlayground#detach() => void

Detach the form playground from its parent node.

CamundaFormPlayground#fire(event) => void

Fire an event.

CamundaFormPlayground#on(event, fn) => void

Subscribe to an event.

CamundaFormPlayground#off(event, fn) => void

Unsubscribe from an event.

CamundaFormPlayground#destroy() => void

Remove form playground from the document.

Hacking the Project

To get the development setup make sure to have NodeJS installed. As soon as you are set up, clone the project and execute

npm install
npm start

License

MIT

版本与发布记录

@camunda/form-playground 共发布 54 个版本,首次发布于 2022/09/30;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.28.0latest2026/10/2020 天前
0.27.02026/09/181 个月前
0.26.02026/08/242 个月前
0.25.02026/07/074 个月前
0.24.02026/02/098 个月前
0.23.02025/10/251 年前

其他发布通道:next → 0.13.0-alpha.1。

关于 @camunda/form-playground 的常见问题

@camunda/form-playground 是什么?

Camunda Form Playground.

如何安装 @camunda/form-playground?

在项目目录运行 npm install @camunda/form-playground,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@bpmn-io/form-js(^2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@camunda/form-playground 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/camunda__form-playground 是否存在。

@camunda/form-playground 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@camunda/form-playground 可以商用吗?

@camunda/form-playground 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@camunda/form-playground 的下载量有多少?

根据 npm 官方下载统计,@camunda/form-playground 在 2026/10/09 – 2026/11/07 这 30 天内被下载 17,526 次,日均约 584 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@camunda/form-playground 还在维护吗?

最新版本 0.28.0 发布于 2026/10/20(20 天前);至今共发布 54 个版本,其中过去 12 个月发布了 5 个;首次发布于 2022/09/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。