Plate
PlateEditorsTemplates
GitHub16kGitHub
DiscordDiscord
  • Plate
  • Editor API
  • Editor Transforms
  • Node
  • Element
  • Text
  • Path
  • Point
  • Range
  • Location
  • Anchor
  • Selection
  • Document Change
  • DOM API
  • React Hooks
  • Plate Core
    • Plate Components
    • Plate Editor
    • Plate Plugin
    • Editor Context
    • Plate Controller
  • Plate Utils
  • Resizable

Plate Utilities

PreviousNext

Plate-owned utility functions, types, identities, and plugins.

platejs contains Plate's shared framework utilities and plugin identities. platejs/react contains React-only hooks and utility plugins.

Installation

pnpm add platejs @tanstack/react-virtual
pnpm add platejs @tanstack/react-virtual

Import headless utilities from platejs and React utilities from platejs/react.

Import paths

Plate ControllerResizable

On This Page

InstallationImport pathsShared utilitiesPlugin identitiesSchema-derived typesUtility plugins and kitsReact hooksReact pluginsRelated APIs
Build your editor
Production-ready AI template and reusable components.
Get all-access
ImportExportsUse
platejsURL helpers, shared object types, PLUGINS, utility pluginsFramework-wide headless contracts and first-party identities.
platejs/reactRef/effect hooks, useSelectionFragmentProp, BlockPlaceholderPluginReact-only framework and registry behavior.

Shared utilities

ExportContract
isDefined(value)Narrows null and undefined out of a value.
isUrl(value)Loosely validates URL strings with a recognized protocol and domain.
sanitizeUrl(url, options)Rejects disallowed schemes and returns a normalized URL, internal path, fragment, or null.
IS_APPLEReports whether the current browser user agent is macOS.
AnyObjectString-keyed object whose values are intentionally unchecked.
UnknownObjectString-keyed object whose values require narrowing.
Nullable<T>Adds null to every property of T.
validate-link.ts
import { isUrl, sanitizeUrl } from 'platejs';
 
export function getSafeLink(value: string) {
  if (!isUrl(value)) return null;
 
  return sanitizeUrl(value, {
    allowedSchemes: ['http', 'https'],
  });
}
validate-link.ts
import { isUrl, sanitizeUrl } from 'platejs';
 
export function getSafeLink(value: string) {
  if (!isUrl(value)) return null;
 
  return sanitizeUrl(value, {
    allowedSchemes: ['http', 'https'],
  });
}

Plugin identities

PLUGINS is the first-party capability-name catalog used by copied registry code. An element plugin separately exposes its persisted type; a property plugin exposes its persisted key. Both default to the plugin name, but a plugin author can declare a different value at creation.

ExportContainsUse
PLUGINSFirst-party capability names such as paragraph, codeBlock, bold, and fixedToolbarPlugin lookup, dependencies, targets, and copied registry plugin references. Persisted identities come from editor.plugin(Plugin).schema.type, editor.plugin(Plugin).schema.key, generated schema handles, or explicit document literals.
PluginNameUnion of all values in PLUGINSAPIs that accept any first-party plugin identity.
Use one identity
const value = [
  {
    type: 'paragraph',
    children: [{ bold: true, text: 'Hello' }],
  },
];
Use one identity
const value = [
  {
    type: 'paragraph',
    children: [{ bold: true, text: 'Hello' }],
  },
];

Behavior-only plugins such as PLUGINS.fixedToolbar still have a name but do not create a document node or property.

Configure a target identity
import { PLUGINS, TrailingBlockPlugin } from 'platejs';
 
export const trailingBlock = TrailingBlockPlugin.configure({
  initialState: {
    type: 'paragraph',
  },
});
Configure a target identity
import { PLUGINS, TrailingBlockPlugin } from 'platejs';
 
export const trailingBlock = TrailingBlockPlugin.configure({
  initialState: {
    type: 'paragraph',
  },
});

Schema-derived types

Feature packages own their persisted types. Their readable aliases are derived from the same plugin schema used at runtime, so platejs does not carry a central AST map.

Use an owner-derived element type
import type { ImageElement } from 'platejs/media';
 
export function getImageUrl(element: ImageElement) {
  return element.url;
}
Use an owner-derived element type
import type { ImageElement } from 'platejs/media';
 
export function getImageUrl(element: ImageElement) {
  return element.url;
}

Use ElementOf<typeof Plugin> for one descriptor-owned element shape and ValueOf<Editor> for the complete installed document vocabulary.

The Editor below is generated from the app's authored plugin module; it is not installed by @plate/editor-plugins. Follow Exact Generated Editor Types and enforce plate generate --check <entry> in CI.

Derive an editor value
import type { ValueOf } from 'platejs';
import type { Editor } from '@/components/editor/plugins.generated';
 
type MyValue = ValueOf<Editor>;
Derive an editor value
import type { ValueOf } from 'platejs';
import type { Editor } from '@/components/editor/plugins.generated';
 
type MyValue = ValueOf<Editor>;

Utility plugins and kits

ExportNameBehavior
ExitBreakPluginPLUGINS.exitBreakAdds transaction commands around insertExitBreak.
NormalizeTypesPluginPLUGINS.normalizeTypesNormalizes configured root paths to a required type or strictType.
SingleBlockPluginPLUGINS.singleBlockForces the editor value into one block and turns hard breaks into soft breaks.
SingleLinePluginPLUGINS.singleLineForces one block and strips line-break characters from text nodes.
TrailingBlockPluginPLUGINS.trailingBlockEnsures a trailing block exists at the configured level and type.
withTrailingBlockOverride editor helperImplements the trailing block normalization logic used by TrailingBlockPlugin.

Use the plugin guide pages for options and examples: Exit Break, Forced Layout, Single Block, and Trailing Block.

React hooks

HookReturnsUse
useComposedRef(...refs)React.RefCallback<T>Assigns one node to callback refs and ref objects, including React 19 cleanup callbacks.
useIsomorphicLayoutEffectReact effect hookUses useLayoutEffect in the browser and useEffect during SSR.
useSelectionFragmentProp(options?)unknownReads a property from the selected fragment.

React plugins

PluginNameBehavior
BlockPlaceholderPluginPLUGINS.blockPlaceholderTracks the current empty block and injects placeholder and optional className props into matching block components.

BlockPlaceholderPlugin defaults to paragraph placeholders and only targets a focused, editable, collapsed selection. Configure placeholders by plugin name and query by node/path.

components/editor/block-placeholder.tsx
import { PLUGINS } from "platejs";
import { BlockPlaceholderPlugin } from "platejs/react";
 
export const blockPlaceholderPlugin = BlockPlaceholderPlugin.configure({
  initialState: {
    placeholders: {
      [PLUGINS.paragraph]: "Type something...",
    },
    query: ({ path }) => path.length === 1,
  },
});
components/editor/block-placeholder.tsx
import { PLUGINS } from "platejs";
import { BlockPlaceholderPlugin } from "platejs/react";
 
export const blockPlaceholderPlugin = BlockPlaceholderPlugin.configure({
  initialState: {
    placeholders: {
      [PLUGINS.paragraph]: "Type something...",
    },
    query: ({ path }) => path.length === 1,
  },
});

Related APIs

  • Plate covers the umbrella package that re-exports these APIs.
  • Plate Core covers editor creation, plugin contracts, and stores.
  • Toolbar covers registry controls that use the React hook helpers.