@contentful/experiences-visual-editor-react

中文文档
4.0.2发布于 2026/11/12TypeScriptES Module近 30 天下载 10.8万

Note: This package is not meant to be used directly by the end user. It is a dependency for the Studio Experiences packages. Changes to this package are not guaranteed to follow semantic versioning and may break without notice if used directly.

原始使用文档
文档目录4 节
  1. Private Package Notice
  2. Purpose
  3. Concepts
  4. Relevant Contentful documentation links

@contentful/experiences-visual-editor-react

Private Package Notice

Note: This package is not meant to be used directly by the end user. It is a dependency for the Studio Experiences packages. Changes to this package are not guaranteed to follow semantic versioning and may break without notice if used directly.

Purpose

  • Handles the canvas interaction logic with dragging, hitboxes, dropzones, reparenting, and communicating with the parent frame to ensure a smooth drag and drop experience.
  • Note that this package is framework specific to React.

Concepts

  • Structure components: Represents components that pertain to the layout of a user's experience such as containers, sections, and columns.
  • Built-in components: Contentful-provided components on behalf of the user that are considered universally useful such as an image, text, and the divider component or to get a user quickly started such as a button. Note that these components are not meant to cover every possible component that the user may want to have. Instead users are generally expected to provide their own set of components to build their customized experiences. The exceptions will generally be based on how universally desired such components are, such as Cards or Carousel components in the future.
  • Custom components: User-provided components built through a definition provided by the Experiences SDK.
  • Post messages: In order for an iFrame to communicate with its parent frame, post messaging is required so that the two frames can communicate with each other. Examples of what information gets shared would be mouse coordinates or what component got picked up and dropped.
  • Browser limitations: Currently only Chrome supports both Click/Drag and Drop while Safari and Firefox only allows for Click and Drop.
  • Trees: Experiences store their own version of the tree that is separate from the source of truth which is stored as a Contentful entry. This is because by storing its own tree version it can provide UI optimizations and manipulations to the tree to maximize performance-related tasks such as when performing drag and drop or re-ordering of components. A concrete example where this optimization is necessary is when you drop a component onto the canvas. Without its own version, the component would flicker to its original pre-drag spot before being placed on the intended area based on the mouse's location.
  • Updating the source of truth: On drag end, the iFrame will update its own tree before sending a post message to the parent frame in useCanvasInteractions. Then the parent frame will update its tree which is the source of truth before sending a post msg back in useEditorSubscriber to the iFrame ensuring that both trees are the same and any discovered discrepancies are resolved.
  • @hello-pangea/dnd: Library providing HOC (higher order components) that Experiences leverages for Drag and Drop. The two components being used from this library is the Droppable and Draggable component.
  • Dropzones: Div wrappers that represent areas for other components to be dropped in. Note that only one can be activated at a time via a hitbox and is a separate div from Draggables.
  • Draggables: Div wrappers that allow component to be picked up and dropped. Note that this is a separate div from Dropzones.
  • SimulateDnD: Custom-built DND component which is needed as a visual trick for dragging a component from the sidebar onto the iFrame. Since the drag is initiated in the parent frame when clicking and dragging a new component, a simulated action in the iFrame is also triggered so the iFrame is in a drag state just like the parent frame. Then when the mouse crosses over from the parent frame into the iFrame, post messaging is required where the iFrame will send mouse coordinates to the parentFrame so that the dragged component icon is placed in the correct position while the iFrame will trigger the appropriate hitboxes and dropzones since all the hitboxes and dropzones live in the iFrame.
  • Component wrapper: There are several types of div wrappers such as Dropzones and Draggables. However, there is a third wrapper that is provided as a custom boolean option with Custom Components. When this boolean is true, all style options selected from the UI will be applied to this wrapping div. This is done so that the user's CSS styles on their own components are preserved and shielded from the style options chosen in the UI.

版本与发布记录

@contentful/experiences-visual-editor-react 共发布 853 个版本,首次发布于 2024/03/05;过去 12 个月发布了 95 个版本。

版本发布日期距今
4.0.2latest2026/11/12今天
4.0.2-beta.0next2026/11/12今天
4.0.2-dev-20261112T1003-b5f3a8b.0dev2026/11/12今天
4.0.2-dev-20261112T0939-ee64328.02026/11/12今天
4.0.2-dev-20261016T2337-3cf6f10.02026/10/1726 天前
4.0.2-dev-20261016T0059-6677253.02026/10/1627 天前

其他发布通道:alpha → 3.0.0-alpha-20250805T1527-42cce69.0,prerelease → 3.8.0-prerelease-20251001T1442-021a279.0,dev → 4.0.2-dev-20261112T1003-b5f3a8b.0,next → 4.0.2-beta.0。

关于 @contentful/experiences-visual-editor-react 的常见问题

@contentful/experiences-visual-editor-react 是什么?

Note: This package is not meant to be used directly by the end user. It is a dependency for the Studio Experiences packages. Changes to this package are not guaranteed to follow semantic versioning and may break without notice if used directly.

如何安装 @contentful/experiences-visual-editor-react?

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

@contentful/experiences-visual-editor-react 支持 TypeScript 吗?

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

@contentful/experiences-visual-editor-react 支持 ESM 还是 CommonJS?

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

@contentful/experiences-visual-editor-react 可以商用吗?

@contentful/experiences-visual-editor-react 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@contentful/experiences-visual-editor-react 的下载量有多少?

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

@contentful/experiences-visual-editor-react 还在维护吗?

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