@formio/core

中文文档
2.9.1发布于 2026/11/14MITCommonJS近 30 天下载 22.1万

The core Form.io renderering framework.

原始使用文档
文档目录5 节
  1. Form.io Core Data Processing Engine
  2. Official Documentation
  3. Usage
  4. Development
  5. Experimental

Form.io Core Data Processing Engine

This library is the core data processing engine behind the Form.io platform. It is a set of isomorphic APIs that allow for complex orchestration (e.g. calculated values, conditionally hidden components, complex logic, etc.) of JSON form and submission definitions.

Official Documentation

For the latest documentation, release information, and guides, always refer to the official Form.io Help Documentation available here:

https://help.form.io

Usage

@formio/core is available as an npm package. You can install it using the package manager of your choice:

# npm
npm install --save @formio/core

# yarn
yarn add @formio/core

Development

Processing form and submission data efficiently has two distinct requirements:

  1. A form- and data-aware traversal of the form JSON; and
  2. A set of processing functions to derive (and occasionally mutate) form state.

The first requirement is accomplished via the eachComponentData and eachComponentDataAsync functions, which traverse each form component JSON and provide a callback parameter by which to interact with the component and it's corresponding submission data parameter(s).

The second requirement is accomplished via "processors" (e.g. calculate, validate, or hideChildren) which are functions that, given an evaluation context, operate on, derive state from, and occasionally mutate the form state and submission values depending on the internal form logic, resulting in a scope object that contains the results of each processor keyed by component path.

To run a suite of processor functions on a form and a submission, the process family of functions take a form JSON definition, a submission JSON definition, and an array of processor function as an arguments (encapsulated as a context object which is passed through to each callback processor function).

import { processSync } from '@formio/core';

const form = {
  display: 'form',
  components: [
    {
      type: 'textfield',
      key: 'firstName',
      label: 'First Name',
      input: true,
    },
    {
      type: 'textfield',
      key: 'lastName',
      label: 'Last Name',
      input: true,
    },
    {
      type: 'button',
      key: 'submit',
      action: 'submit',
      label: 'Submit',
    },
  ],
};

const submission = {
  data: {
    firstName: 'John',
    lastName: 'Doe',
  },
};

const addExclamationSync = (context) => {
  const { component, data, scope, path, value } = context;

  if (!scope.addExclamation) scope.addExclamation = {};
  let newValue = `${value}!`;

  // The scope is a rolling "results" object that tracks which components have been operated on by which processor functions
  scope.addExclamation[path] = true;
  _.set(data, path, newValue);
  return;
};

// The context object is mutated depending on which component is being processed; after `processSync` it will contain the processed components and data
const context = {
  components: form.components,
  data: submission.data,
  processors: [{ processSync: addExclamationSync }],
  scope: {},
};

// The `process` family of functions returns the scope object
const resultScope = processSync(context);

console.assert(resultScope['addExclamation']?.firstName === true);
console.assert(resultScope['addExclamation']?.lastName === true);
console.assert(submission.data.firstName === 'John!');
console.assert(submission.data.lastName === 'Doe!');

Experimental

This library contains experimental code (found in the src/experimental directory or via an import, e.g. import { Components } from @formio/core/experimental) that was designed to update and replace the core rendering engine behind the Form.io platform. It is a tiny (12k gzipped) rendering framework that allows for the rendering of complex components as well as managing the data models controlled by each component.

Usage

To use this experimental framework, you will first need to install the parent library into your application.

# npm
npm install --save @formio/core
# yarn
yarn add @formio/core

Next, you can create a new component as follows.

import { Components } from '@formio/core/experimental';
Components.addComponent({
  type: 'h3',
  template: (ctx) => `<h3>${ctx.component.header}</h3>`,
});

And now this component will render using the following.

const header = Components.createComponent({
  type: 'h3',
  header: 'This is a test',
});
console.log(header.render()); // Outputs <h3>This is a test</h3>

You can also use this library by including it in your webpage scripts by including the following.

<script src="https://cdn.jsdelivr.net/npm/@formio/base@latest/dist/formio.core.min.js"></script>

After you do this, you can then do the following to create a Data Table in your website.

FormioCore.render(
  document.getElementById('data-table'),
  {
    type: 'datatable',
    key: 'customers',
    components: [
      {
        type: 'datavalue',
        key: 'firstName',
        label: 'First Name',
      },
      {
        type: 'datavalue',
        key: 'lastName',
        label: 'First Name',
      },
    ],
  },
  {},
  {
    customers: [
      { firstName: 'Joe', lastName: 'Smith' },
      { firstName: 'Sally', lastName: 'Thompson' },
      { firstName: 'Mary', lastName: 'Bono' },
    ],
  },
);

版本与发布记录

@formio/core 共发布 587 个版本,首次发布于 2020/06/13;过去 12 个月发布了 24 个版本。

版本发布日期距今
2.9.1latest2026/11/142 天前
2.3.42_3_x2026/10/011 个月前
2.9.02026/09/231 个月前
2.8.32026/09/171 个月前
2.8.22026/08/272 个月前
2.8.1-pdf515.02026/08/113 个月前

其他发布通道:2_6_x → 2.6.0-rc.3,2_5_x → 2.5.3,rc → 2.8.1-api99.0,2_3_x → 2.3.4。

关于 @formio/core 的常见问题

@formio/core 是什么?

The core Form.io renderering framework.

如何安装 @formio/core?

在项目目录运行 npm install @formio/core,或使用 pnpm add / yarn add / bun add。

@formio/core 支持 TypeScript 吗?

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

@formio/core 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@formio/core 可以商用吗?

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

@formio/core 的下载量有多少?

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

@formio/core 还在维护吗?

最新版本 2.9.1 发布于 2026/11/14(2 天前);至今共发布 587 个版本,其中过去 12 个月发布了 24 个;首次发布于 2020/06/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。