UNPKG

@yoopta/editor

Version:

<h2 align="center">Yoopta-Editor v1 🎉</h2> <p align="center">Yoopta-Editor - is an open source notion-like editor 💥</p> <div align="center"> <img width="574" alt="Screen Shot 2023-01-25 at 16 04 29" src="https://user-images.githubusercontent.com/2909311

179 lines • 8.99 kB
import type { Descendant, NodeEntry, Path, Point, Range as SlateRange, Selection } from 'slate'; import type { ReactEditor } from 'slate-react'; import type { YooptaMark } from '../marks'; import type { decreaseBlockDepth } from './blocks/decreaseBlockDepth'; import type { deleteBlock } from './blocks/deleteBlock'; import type { duplicateBlock } from './blocks/duplicateBlock'; import type { focusBlock } from './blocks/focusBlock'; import type { GetBlockOptions } from './blocks/getBlock'; import type { increaseBlockDepth } from './blocks/increaseBlockDepth'; import type { insertBlock } from './blocks/insertBlock'; import type { mergeBlock } from './blocks/mergeBlock'; import type { toggleBlock } from './blocks/toggleBlock'; import type { EditorBlurOptions } from './core/blur'; import type { HistoryStack, HistoryStackName, YooptaHistory } from './core/history'; import type { getEmail } from '../parsers/getEmail'; import type { getHTML } from '../parsers/getHTML'; import type { getYooptaJSON } from '../parsers/getYooptaJSON'; import type { WithoutFirstArg } from '../utils/types'; import type { moveBlock } from './blocks/moveBlock'; import type { SplitBlockOptions } from './blocks/splitBlock'; import type { updateBlock } from './blocks/updateBlock'; import type { YooptaOperation, applyTransforms } from './core/applyTransforms'; import type { setEditorValue } from './core/setEditorValue'; import type { getMarkdown } from '../parsers/getMarkdown'; import type { getPlainText } from '../parsers/getPlainText'; import type { Plugin, PluginElementProps, PluginElementsMap, PluginOptions } from '../plugins/types'; import type { ElementStructureOptions, TextNodeOptions } from './elements/create-element-structure'; import type { deleteElement } from './elements/deleteElement'; import type { getElement } from './elements/getElement'; import type { getElementChildren } from './elements/getElementChildren'; import type { getElementEntry } from './elements/getElementEntry'; import type { getElementPath } from './elements/getElementPath'; import type { getElementRect } from './elements/getElementRect'; import type { getElements } from './elements/getElements'; import type { getParentElementPath } from './elements/getParentElementPath'; import type { insertElement } from './elements/insertElement'; import type { isElementEmpty } from './elements/isElementEmpty'; import type { updateElement } from './elements/updateElement'; export type YooptaBlockData<T = Descendant | SlateElement> = { id: string; value: T[]; type: string; meta: YooptaBlockBaseMeta; }; export type YooptaBlockBaseMeta = { order: number; depth: number; align?: 'left' | 'center' | 'right' | undefined; }; export type YooptaContentValue = Record<string, YooptaBlockData>; export type SlateEditor = ReactEditor; export type FocusAt = Path | Point; export type YooptaPluginsEditorMap = Record<string, SlateEditor>; export type YooptaPathIndex = number | null; export type YooptaPath = { current: YooptaPathIndex; selected?: number[] | null; selection?: Selection | null; source?: null | 'selection-box' | 'native-selection' | 'mousemove' | 'keyboard' | 'copy-paste'; }; export type TextFormat = { type: string; hotkey?: string; getValue: () => null | any; isActive: () => boolean; toggle: () => void; update: (props?: any) => void; }; export type YooptaBlock = { type: string; options?: PluginOptions<any>; elements: PluginElementsMap; isActive: () => boolean; }; export type YooptaBlocks = Record<string, YooptaBlock>; export type YooptaFormats = Record<string, TextFormat>; export type YooptaEditorEventKeys = 'change' | 'focus' | 'blur' | 'block:copy' | 'path-change' | 'decorations:change'; export type YooptaEventChangePayload = { operations: YooptaOperation[]; value: YooptaContentValue; }; export type YooptaEventsMap = { change: YooptaEventChangePayload; focus: boolean; blur: boolean; 'block:copy': YooptaBlockData; 'path-change': YooptaPath; 'decorations:change': undefined; }; export type DecoratorFn = (blockId: string, entry: NodeEntry) => SlateRange[]; export type LeafDecoratorRenderFn = (leaf: Record<string, unknown>, children: unknown) => unknown; export type BaseCommands = Record<string, (...args: any[]) => any>; 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: WithoutFirstArg<typeof mergeBlock>; splitBlock: (options?: SplitBlockOptions) => string | undefined; getBlock: (options: GetBlockOptions) => YooptaBlockData | null; insertElement: WithoutFirstArg<typeof insertElement>; updateElement: WithoutFirstArg<typeof updateElement>; deleteElement: WithoutFirstArg<typeof deleteElement>; getElement: WithoutFirstArg<typeof getElement>; getElements: WithoutFirstArg<typeof getElements>; getElementEntry: WithoutFirstArg<typeof getElementEntry>; getElementPath: WithoutFirstArg<typeof getElementPath>; getElementRect: WithoutFirstArg<typeof getElementRect>; getParentElementPath: WithoutFirstArg<typeof getParentElementPath>; getElementChildren: WithoutFirstArg<typeof getElementChildren>; isElementEmpty: WithoutFirstArg<typeof isElementEmpty>; y: ((type: string, options?: ElementStructureOptions) => SlateElement) & { text: (text: string, marks?: TextNodeOptions) => SlateElementTextNode; inline: (type: string, options?: ElementStructureOptions) => SlateElement; }; path: YooptaPath; setPath: (path: YooptaPath) => void; children: YooptaContentValue; getEditorValue: () => YooptaContentValue; setEditorValue: WithoutFirstArg<typeof setEditorValue>; blockEditorsMap: YooptaPluginsEditorMap; /** Optional factory override for building Slate editors — used by collaboration to inject withYjs */ buildSlateEditorFn?: (blockId: string) => SlateEditor; /** Returns true if the given Slate editor is currently applying a remote collaborative change */ isRemoteSlateOp?: (slate: SlateEditor) => boolean; formats: YooptaFormats; marks: YooptaMark<any>[]; plugins: Record<string, Plugin<Record<string, SlateElement>, unknown>>; 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: WithoutFirstArg<typeof getHTML>; getMarkdown: WithoutFirstArg<typeof getMarkdown>; getPlainText: WithoutFirstArg<typeof getPlainText>; getEmail: WithoutFirstArg<typeof getEmail>; getYooptaJSON: WithoutFirstArg<typeof getYooptaJSON>; 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; decorators: Map<string, DecoratorFn>; leafDecorators: Map<string, LeafDecoratorRenderFn>; }; export type SlateElementTextNode = { text: string; bold?: boolean; italic?: boolean; underline?: boolean; code?: boolean; strike?: boolean; highlight?: any; }; export type SlateElement<K extends string = string, T = any> = { id: string; type: K; children: Descendant[]; props?: PluginElementProps<T>; }; //# sourceMappingURL=types.d.ts.map