@frontlit/page-builder

中文文档
0.1.0-alpha.9发布于 2026/11/15MITTypeScriptES Module构建来源已验证近 30 天下载 1990

Block-based WYSIWYG page builder and renderer for React

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. Optional: client-side routing
  4. Server rendering (React Server Components)
  5. What's inside
  6. License

@frontlit/page-builder

Block-based page builder and renderer for React. Self-contained — no backend and no framework lock-in. Themes, blocks, and the WYSIWYG builder all run client-side.

You and your agents can collaborate on the same pages. People edit visually in the WYSIWYG builder. AI agents edit the same page data, which is plain JSON (blocks plus their settings), with no screenshots or browser automation involved. Both kinds of edit go through the same draft and publish flow, so you can review an agent's changes in the builder before they go live, and an agent can pick up where you left off.

  • In FrontLit, agents use the MCP server's page and theme tools: list_pages, get_page, create_page, update_page, publish_page, discard_page_draft, list_themes, create_theme, update_theme and the matching delete tools.
  • To teach a coding agent to write good FrontLit pages, install frontlit-skills.
  • In your own app, the layout the builder emits through onChange is the same JSON your agent reads and writes. See docs/ai-editing.md for the planned in-builder AI editing design.

Rich text editing and rendering live in @frontlit/text-editor, which this package depends on and installs automatically.

Installation

npm i @frontlit/page-builder
# or
pnpm add @frontlit/page-builder

Peer dependencies: react and react-dom (^18 or ^19). Next.js is not required. Tailwind is not required — import the compiled stylesheet:

import "@frontlit/page-builder/styles.css";

That file includes the utilities, default tokens, the theme-picker fonts (Inter, Playfair, and the rest), and the TipTap prose styles from @frontlit/text-editor. Hosts that already inject those faces via next/font keep working: --font-inter on the document still wins.

Future: split the theme-picker faces out of styles.css into an opt-in @frontlit/page-builder/fonts.css. Hosts that already load Inter, Playfair, and the rest (for example via next/font) can skip that file; everyone else imports it next to styles.css. --font-* on the document and the system-font fallbacks in theme.css stay as they are.

If the host already runs Tailwind CSS v4, you can skip styles.css and scan the packages instead. Import the prose sheet so rich-text lists and code blocks survive Tailwind preflight:

@import "@frontlit/page-builder/theme.css";
@import "@frontlit/text-editor/prose.css";
@source "./node_modules/@frontlit/page-builder";
@source "./node_modules/@frontlit/text-editor";

Usage

import {
    PageRenderer,
    PageBuilder,
    createDefaultLayout,
    getDefaultTheme,
} from "@frontlit/page-builder";
import "@frontlit/page-builder/styles.css";

// Read-only rendering (a published page, a marketing site, a preview):
<PageRenderer
    layout={createDefaultLayout()}
    theme={getDefaultTheme()}
    pageData={{ pageType: "landing" }}
/>;

// The interactive editor — persist however you like:
<PageBuilder
    onChange={({ layout, theme }) => {
        /* save */
    }}
/>;

Both PageRenderer and PageBuilder are client components (this package ships with a "use client" directive on UI entries).

Optional: client-side routing

Internal /... links render as native <a> tags by default, so the package works in Vite, Remix, Astro, or any other React host. Next.js (or any other router) can inject its own link:

import Link from "next/link";
import {
    PageRenderer,
    type PageBuilderLinkProps,
} from "@frontlit/page-builder";

function AppLink(props: PageBuilderLinkProps) {
    return <Link {...props} />;
}

<PageRenderer layout={layout} theme={theme} linkComponent={AppLink} />;

PageBuilder accepts the same linkComponent prop and forwards it to the live preview.

Server rendering (React Server Components)

PageRenderer is a client component. To render published pages on the server, use ServerPageRenderer from @frontlit/page-builder/server: static blocks render on the server and ship no JavaScript; only the interactive parts (mobile menu, marquee, email/support forms, copy buttons, links) are client islands.

import { ServerPageRenderer } from "@frontlit/page-builder/server";
import { resolveTheme } from "@frontlit/page-builder/theme";

const theme = resolveTheme(themeId, themeStyle);

<ServerPageRenderer layout={layout} theme={theme} pageData={pageData} />;

Because nothing crosses the server/client boundary as a function, it takes no callbacks. Instead:

  • Links — wrap the page in a client component that renders PageBuilderLinkProvider (from @frontlit/page-builder/islands/nav-link) with your router's link.
  • Light/dark control — pass a ready client element as themeSwitcher (e.g. one built on @frontlit/page-builder/islands/theme-mode-switcher); it is shown in the footer.
  • Images — call setImageAttributesResolver once at start-up to swap an image's src/srcSet for your optimizer's URLs (the sites app uses Next's getImageProps).
  • Dark mode — section backgrounds switch with the dark class on an ancestor, so the server needs no colour mode.

The server build is separate from the main bundle (tsup.server.config.ts): its client islands are listed in tsup.islands.ts, built on their own with a "use client" banner, and imported — not bundled — by the server entry. A block that needs state or effects must either live in that list or be split so only its interactive part does. The block lookup used by the server renderer is src/server/registry.ts; keep it in step with src/registry.ts when adding a block.

What's inside

SubpathWhat it exports
@frontlit/page-builderEverything below, re-exported from one place
@frontlit/page-builder/modelsTheme, WidgetInstance, Widget<T>, Page, Media, etc. (re-exports TextEditorContent from @frontlit/text-editor)
@frontlit/page-builder/primitivesThemed UI atoms (Button, Header1-4, Section, PageCard, ...) + built-in themes
@frontlit/page-builder/componentsShared presentational bits: Image, NavLink, VideoWithPreview (re-exports TextRenderer from @frontlit/text-editor)
@frontlit/page-builder/blocksThe block library: Header, Hero, Content, Featured, Faq, Pricing, Banner, EmailForm, Footer, …
@frontlit/page-builder/rendererPageRenderer — renders a page's WidgetInstance[] layout, with an editing mode for use inside the builder
@frontlit/page-builder/builderPageBuilder — the full WYSIWYG editor (add/remove/reorder blocks, edit settings, switch themes)
@frontlit/page-builder/data-slotsServer-safe helper for hosts to resolve named data slots before rendering
@frontlit/page-builder/serverServerPageRenderer, setImageAttributesResolver — server-component page rendering (see above)
@frontlit/page-builder/themeresolveTheme, themes, generateThemeStyles — server-callable and light enough for client components
@frontlit/page-builder/primitives/serverThe hook-free primitives, callable from server components
@frontlit/page-builder/islands/*Small client islands (nav-link, theme-mode-switcher) hosts can import without the full client bundle

createDefaultLayout() / getDefaultTheme() (exported from the root) build a ready-to-render starter landing page.

header and footer are required layout-level blocks. The builder repairs legacy or empty initial layouts by adding them, keeps them at the outer edges, and never permits moving or deleting them.

License

MIT

版本与发布记录

@frontlit/page-builder 共发布 10 个版本,首次发布于 2026/08/19;过去 12 个月发布了 10 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.0-alpha.9latest2026/11/15今天
0.1.0-alpha.82026/10/3115 天前
0.1.0-alpha.72026/10/3116 天前
0.1.0-alpha.62026/10/2521 天前
0.1.0-alpha.52026/10/2522 天前
0.1.0-alpha.42026/10/2422 天前

关于 @frontlit/page-builder 的常见问题

@frontlit/page-builder 是什么?

Block-based WYSIWYG page builder and renderer for React

如何安装 @frontlit/page-builder?

在项目目录运行 npm install @frontlit/page-builder,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0 || ^19.0.0)、react-dom(^18.0.0 || ^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@frontlit/page-builder 支持 TypeScript 吗?

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

@frontlit/page-builder 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@frontlit/page-builder 可以商用吗?

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

@frontlit/page-builder 的下载量有多少?

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

@frontlit/page-builder 还在维护吗?

最新版本 0.1.0-alpha.9 发布于 2026/11/15(今天);至今共发布 10 个版本,其中过去 12 个月发布了 10 个;首次发布于 2026/08/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。