Встраивание
Интеграция редактора или рендерера Clepit в любое приложение проста: контейнер DOM является единственной точкой управления.
Монтирование редактора
Присвойте элементу-контейнеру id, вызовите `Editor.create({ containerId, ... })`, сохраните возвращённый `EditorAPI` и вызовите `Editor.destroy(containerId)` при очистке.
import { Editor } from '@clepit/core';
import type { EditorAPI } from '@clepit/core';
// 1. Give your container a stable id
// <div id="my-editor"></div>
// 2. Create the editor and hold the returned API
const editor: EditorAPI = Editor.create({
containerId: 'my-editor',
minHeight: 400,
placeholder: 'Start writing...',
theme: 'auto',
onChange: data => console.log(data),
onReady: () => console.log('Editor ready'),
});
// 3. Extract content any time
const data = editor.data.extract();
// 4. Destroy on teardown (e.g. component unmount)
Editor.destroy('my-editor');Рендеринг вывода только для чтения
Вызовите `Renderer.render({ containerId, data })`. Пример ниже показывает реальный React-паттерн из компонента `DocsRenderer`: `useId` генерирует уникальный id контейнера, а `useEffect` запускает рендеринг.
import { Renderer } from '@clepit/core';
import type { EditorData } from '@clepit/core';
import { useEffect, useId } from 'react';
type Props = { content: EditorData };
const ReadOnlyView = ({ content }: Props) => {
// useId produces a stable, unique id per component instance
const containerId = useId().replace(/[^a-z0-9]/gi, '');
useEffect(() => {
Renderer.render({
containerId,
data: content,
margins: { bottom: 0, top: 0 },
});
}, [containerId, content]);
return <div id={containerId} />;
};Рендеринг только на клиенте / SSR
И Editor, и Renderer работают с DOM, поэтому они запускаются только в браузере: используйте effects (`useEffect`) или директиву `'use client'`. Во время SSR они не работают.
Независим от фреймворка
Основной пакет @clepit/core: чистый TypeScript без зависимости от React. Независимо от того, используете ли вы React, Vue, Svelte, Angular или чистый TS/JS, все работают с одним и тем же API.