@formcrafts/embed

中文文档
1.0.40发布于 2026/09/21MITTypeScriptESM + CJS零依赖近 30 天下载 9809

Library to embed Formcrafts forms

原始使用文档
文档目录9 节
  1. Introduction
  2. Installation
  3. Importing the library
  4. Embed - Inline
  5. Initialize the form
  6. Available methods
  7. Embed - Popup
  8. Initialize the form
  9. Available methods

Introduction

You can use Formcrafts' embed library @formcrafts/embed to embed forms using vanilla JavaScript. The library is available as an npm package, and works well with frameworks like Svelte, React, Vue, and Angular.

Installation

To add the Formcrafts JavaScript library to your project, install it using npm:

npm install @formcrafts/embed --save

Importing the library

To make the library available in your code, import the necessary modules:

import { createInlineForm, createPopup } from "@formcrafts/embed"

Embed - Inline

Initialize the form

const myInlineForm = createInlineForm({
  form: "form_key", // Your form key
  target: document.getElementById("element_id"), // Target element
  seamless: true, // Removes form border, shadow, and padding
  width: 500, // Max width of the form
  redirectWithin: true, // Keep redirect within form frame
  values: {
    field1: "Jack Smith",
    field2: ["Chocolate", "Vanilla"],
  }, // Prefill values
})

Available methods

You can use the following methods to interact with the inline form:

myInlineForm.on("load", (height: number) => {}) // Fires when the form loads
myInlineForm.on("submit:success", () => {}) // Fires on a successful form submit
myInlineForm.destroy() // Remove the form instance
myInlineForm.values({
  field1: "New value",
}) // Update the values of the form

Embed - Popup

Initialize the form

const myPopupForm = createPopup({
  form: "form_key", // Your form key
  width: 500, // Max width of the form
  redirectWithin: true, // Keep redirect within form frame
  values: {
    field1: "Jack Smith",
    field2: ["Chocolate", "Vanilla"],
  }, // Prefill values
})

Available methods

You can use the following methods to interact with the popup form:

myPopupForm.on("load", (height: number) => {}) // Fires when the form loads
myPopupForm.on("submit:success", () => {}) // Fires on a successful form submit
myPopupForm.load() // Load the form. Can be used to load the form before showing it. Optional.
myPopupForm.open() // Open the popup
myPopupForm.close() // Close the popup
myPopupForm.destroy() // Destroy the popup and the form instance
myPopupForm.values({
  field1: "New value",
}) // Update the values of the form

版本与发布记录

@formcrafts/embed 共发布 48 个版本,首次发布于 2024/02/01;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.0.40latest2026/09/211 个月前
1.0.392026/09/032 个月前
1.0.382025/10/301 年前
1.0.372025/09/181.2 年前
1.0.362025/09/181.2 年前
1.0.352025/08/201.2 年前

关于 @formcrafts/embed 的常见问题

@formcrafts/embed 是什么?

Library to embed Formcrafts forms

如何安装 @formcrafts/embed?

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

@formcrafts/embed 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@formcrafts/embed 支持 ESM 还是 CommonJS?

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

@formcrafts/embed 可以商用吗?

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

@formcrafts/embed 的下载量有多少?

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

@formcrafts/embed 还在维护吗?

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