@atlaskit/editor-plugin-content-format

中文文档
24.0.0发布于 2026/10/27Apache-2.0TypeScriptESM + CJS近 30 天下载 2.2万

ContentFormat plugin for @atlaskit/editor-core

原始使用文档
文档目录12 节
  1. Overview
  2. Key features
  3. Install
  4. Usage
  5. Accessing Content Mode State
  6. Updating Content Mode
  7. Plugin API
  8. Configuration Options
  9. Shared State
  10. Commands
  11. Support
  12. License

Editor Plugin Content Format

ContentFormat plugin for @atlaskit/editor-core

Note: This component is designed for internal Atlassian development. External contributors will be able to use this component but will not be able to submit issues.

Overview

The Content Format plugin provides centralized state management for tracking the editor's content mode/format. It enables plugins and products to monitor and update the current editor content format state.

Key features

  • Content mode tracking - Maintains the current content mode of the editor (e.g., standard, compact, etc.)
  • Shared state management - Provides a centralized state accessible to all dependent plugins
  • Command API - Simple command interface for updating content mode
  • Optimized updates - Prevents unnecessary state updates when mode hasn't changed

Install


Usage


Internal use only

Accessing Content Mode State

You will need to add the plugin as an optional dependancy wherever you are going to need to access the state:

import type {
    OptionalPlugin,
} from '@atlaskit/editor-common/types';
// ...
import type { ContentFormatPlugin } from '@atlaskit/editor-plugin-content-format';
// ...



export type YourPluginDependencies = [
    // ...
    OptionalPlugin<ContentFormatPlugin>,
    // ...
];

Accessing Content Mode State in your plugin

In your plugins access state like so:

const contentMode = api?.contentFormat?.sharedState?.currentState()?.contentMode

Accessing Content Mode State in React Components

In React components that need to react to content mode changes, use the useSharedPluginStateWithSelector hook:

import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
import type { PublicPluginAPI } from '@atlaskit/editor-common/types';
import type { ContentFormatPlugin } from '@atlaskit/editor-plugin-content-format';

type Props = {
  editorApi?: PublicPluginAPI<[ContentFormatPlugin]>;
};

export const MyComponent = ({ editorApi }: Props) => {
  const { contentMode } = useSharedPluginStateWithSelector(
    editorApi,
    ['contentFormat'],
    (states) => ({
      contentMode: states.contentFormatState?.contentMode,
    })
  );

  return <div>Current mode: {contentMode}</div>;
};

Updating Content Mode

Products and plugins can update the content mode using the updateContentMode command:

api.contentFormat?.commands.updateContentMode('compact');

Plugin API

Configuration Options

type ContentFormatPluginOptions = {
  initialContentMode?: EditorContentMode; // Defaults to 'standard'
};

Shared State

type ContentFormatPluginState = {
  contentMode: EditorContentMode;
};

Commands

updateContentMode(mode: EditorContentMode)

Updates the current content mode. The command will:

  • Return null if the new mode is identical to the previous mode (no-op for performance)
  • Set the meta on the transaction with the new content mode
  • Trigger state updates across all dependent plugins

Parameters:

  • mode (EditorContentMode): The new content mode to set

Returns: EditorCommand (null if no change needed, or the transaction with meta)

Example:

api.contentFormat?.commands.updateContentMode('dense');

Support


For internal Atlassian, visit the slack channel #help-editor for support or visit go/editor-help to submit a bug.

License


Please see Atlassian Frontend - License for more licensing information.

版本与发布记录

@atlaskit/editor-plugin-content-format 共发布 29 个版本,首次发布于 2026/01/14;过去 12 个月发布了 29 个版本。

版本发布日期距今
24.0.0latest2026/10/2711 天前
23.0.02026/10/2018 天前
22.0.02026/10/1622 天前
21.0.02026/10/1425 天前
20.0.02026/10/0830 天前
19.0.02026/10/071 个月前

关于 @atlaskit/editor-plugin-content-format 的常见问题

@atlaskit/editor-plugin-content-format 是什么?

ContentFormat plugin for @atlaskit/editor-core

如何安装 @atlaskit/editor-plugin-content-format?

在项目目录运行 npm install @atlaskit/editor-plugin-content-format,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.2.0 || ^19.2.0)、@atlaskit/editor-common(^134.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@atlaskit/editor-plugin-content-format 支持 TypeScript 吗?

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

@atlaskit/editor-plugin-content-format 支持 ESM 还是 CommonJS?

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

@atlaskit/editor-plugin-content-format 可以商用吗?

@atlaskit/editor-plugin-content-format 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@atlaskit/editor-plugin-content-format 的下载量有多少?

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

@atlaskit/editor-plugin-content-format 还在维护吗?

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