const text = {
text: "Bold",
bold: true,
};const text = {
text: "Bold",
bold: true,
};Plite treats bold as your data. The editor only requires the text string.
Elements contain child nodes and any product fields your schema needs.
interface Element {
readonly children: readonly Descendant[];
readonly type: string;
readonly [key: string]: unknown;
}interface Element {
readonly children: readonly Descendant[];
readonly type: string;
readonly [key: string]: unknown;
}const paragraph = {
type: "paragraph",
children: [{ text: "Body" }],
};
const link = {
type: "link",
url: "https://example.com",
children: [{ text: "Example" }],
};const paragraph = {
type: "paragraph",
children: [{ text: "Body" }],
};
const link = {
type: "link",
url: "https://example.com",
children: [{ text: "Example" }],
};Plite requires a type string on every element and uses it to resolve schema
behavior. Your app defines the element types and custom fields such as url.
const LinkElement = ({ attributes, children, element }) => {
return (
<a {...attributes} href={element.url}>
{children}
</a>
);
};const LinkElement = ({ attributes, children, element }) => {
return (
<a {...attributes} href={element.url}>
{children}
</a>
);
};Runtime values use plain objects. Static helper functions live on *Api
namespaces such as NodeApi, ElementApi, TextApi, PathApi, PointApi,
RangeApi, and SelectionApi.
import { ElementApi, NodeApi, RangeApi } from "plitejs";
const string = NodeApi.string(element);
const isElement = ElementApi.isElement(value);
const collapsed = RangeApi.isCollapsed(range);import { ElementApi, NodeApi, RangeApi } from "plitejs";
const string = NodeApi.string(element);
const isElement = ElementApi.isElement(value);
const collapsed = RangeApi.isCollapsed(range);Use the helper namespace when you need structural checks, path math, range direction, or text extraction outside an editor read/update callback.
Inside editor.read(...) and editor.update(...), prefer the grouped runtime
helpers because they understand the current root, schema, and transaction.
const linkEntry = editor.read((state) =>
state.nodes.above({
match: (node) => ElementApi.isElement(node) && node.type === "link",
})
);const linkEntry = editor.read((state) =>
state.nodes.above({
match: (node) => ElementApi.isElement(node) && node.type === "link",
})
);Keep domain helpers as normal functions or expose them from an plugin when they need editor state.
import { ElementApi, type Element } from "plitejs";
type ImageElement = Element & {
type: "image";
url: string;
};
const isImageElement = (value: unknown): value is ImageElement =>
ElementApi.isElement(value) &&
value.type === "image" &&
typeof value.url === "string";import { ElementApi, type Element } from "plitejs";
type ImageElement = Element & {
type: "image";
url: string;
};
const isImageElement = (value: unknown): value is ImageElement =>
ElementApi.isElement(value) &&
value.type === "image" &&
typeof value.url === "string";Use Plugins when a helper should become a typed state,
tx, or api namespace installed on the editor.