Core package
This is core package for Yoopta-Editor
Installation
yarn add @yoopta/editor
Usage
import YooptaEditor, { createYooptaEditor, YooEditor } from '@yoopta/editor';
import Paragraph from '@yoopta/paragraph';
const plugins = [Paragraph];
const Editor = () => {
const editor: YooEditor = useMemo(() => createYooptaEditor(), []);
const [value, setValue] = useState();
const onChange = (newValue) => setValue(newValue);
return <YooptaEditor editor={editor} plugins={plugins} value={value} onChange={onChange} />;
};
YooptaEditor component props
type Props = {
editor: YooEditor;
id?: string;
plugins: YooptaPlugin[];
marks?: YooptaMark<any>[];
value?: YooptaContentValue;
autoFocus?: boolean;
className?: string;
selectionBoxRoot?: HTMLElement | React.MutableRefObject<HTMLElement | null> | false;
children?: React.ReactNode;
tools?: Partial<Tools>;
placeholder?: string;
readOnly?: boolean;
width?: number | string;
style?: number | string;
onChange?: (value: YooptaContentValue, options: YooptaOnChangeOptions) => void;
onPathChange?: (path: YooptaPath) => void;
};
Editor API
export type YooEditor = {
id: string;
readOnly: boolean;
isEmpty: () => boolean;
insertBlock: WithoutFirstArg<typeof insertBlock>;
updateBlock: WithoutFirstArg<typeof updateBlock>;
deleteBlock: WithoutFirstArg<typeof deleteBlock>;
duplicateBlock: WithoutFirstArg<typeof duplicateBlock>;
toggleBlock: WithoutFirstArg<typeof toggleBlock>;
increaseBlockDepth: WithoutFirstArg<typeof increaseBlockDepth>;
decreaseBlockDepth: WithoutFirstArg<typeof decreaseBlockDepth>;
moveBlock: WithoutFirstArg<typeof moveBlock>;
focusBlock: WithoutFirstArg<typeof focusBlock>;
mergeBlock: () => void;
splitBlock: (options?: SplitBlockOptions) => void;
getBlock: (options: GetBlockOptions) => YooptaBlockData | null;
path: YooptaPath;
setPath: (path: YooptaPath) => void;
children: YooptaContentValue;
getEditorValue: () => YooptaContentValue;
setEditorValue: WithoutFirstArg<typeof setEditorValue>;
blockEditorsMap: YooptaPluginsEditorMap;
blocks: YooptaBlocks;
formats: YooptaFormats;
shortcuts: Record<string, YooptaBlock>;
plugins: Record<string, Plugin<Record<string, SlateElement>, unknown>>;
commands: Record<string, (...args: any[]) => any>;
applyTransforms: WithoutFirstArg<typeof applyTransforms>;
batchOperations: (fn: () => void) => void;
on: <K extends keyof YooptaEventsMap>(event: K, fn: (payload: YooptaEventsMap[K]) => void) => void;
once: <K extends keyof YooptaEventsMap>(event: K, fn: (payload: YooptaEventsMap[K]) => void) => void;
off: <K extends keyof YooptaEventsMap>(event: K, fn: (payload: YooptaEventsMap[K]) => void) => void;
emit: <K extends keyof YooptaEventsMap>(event: K, payload: YooptaEventsMap[K]) => void;
isFocused: () => boolean;
blur: (options?: EditorBlurOptions) => void;
focus: () => void;
getHTML: (content: YooptaContentValue) => string;
getMarkdown: (content: YooptaContentValue) => string;
getPlainText: (content: YooptaContentValue) => string;
getEmail: (content: YooptaContentValue, templateOptions: EmailTemplateOptions) => string;
historyStack: Record<HistoryStackName, HistoryStack[]>;
isSavingHistory: WithoutFirstArg<typeof YooptaHistory.isSavingHistory>;
isMergingHistory: WithoutFirstArg<typeof YooptaHistory.isMergingHistory>;
withoutSavingHistory: WithoutFirstArg<typeof YooptaHistory.withoutSavingHistory>;
withoutMergingHistory: WithoutFirstArg<typeof YooptaHistory.withoutMergingHistory>;
withMergingHistory: WithoutFirstArg<typeof YooptaHistory.withMergingHistory>;
withSavingHistory: WithoutFirstArg<typeof YooptaHistory.withSavingHistory>;
redo: WithoutFirstArg<typeof YooptaHistory.redo>;
undo: WithoutFirstArg<typeof YooptaHistory.undo>;
refElement: HTMLElement | null;
};
Hooks from @yoopta/editor
useYooptaEditor();
useYooptaReadOnly();
useYooptaFocused();
useBlockData(blockId);
useYooptaPluginOptions<TOptions>(blockType);