4.9.4 • Published 6 months ago

@yoopta/editor v4.9.4

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Core package

This is core package for Yoopta-Editor

Installation

yarn add @yoopta/editor

Usage

import YooptaEditor, { createYooptaEditor, YooEditor } from '@yoopta/editor';
// plugins
import Paragraph from '@yoopta/paragraph';

const plugins = [Paragraph];

const Editor = () => {
  // create instance
  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 = {
  /**
   * Instance of editor
   */
  editor: YooEditor;
  /**
   * Optional custom id. Useful for multiple instances
   */
  id?: string;
  /**
   * List of plugins
   */
  plugins: YooptaPlugin[];
  /**
   * List of marks from @yoopta/marks
   */
  marks?: YooptaMark<any>[];
  /**
   * Optional value of editor. DEFAULT - [undefined]
   */
  value?: YooptaContentValue;
  /**
   * Autofocus when editor is ready. DEFAULT - [true]
   */
  autoFocus?: boolean;
  /**
   * Additional className for your needs. DEFAULT - [.yoopta-editor]
   */
  className?: string;
  /**
   * Box for selection area to select by mouse several blocks. DEFAULT - [document]
   */
  selectionBoxRoot?: HTMLElement | React.MutableRefObject<HTMLElement | null> | false;
  children?: React.ReactNode;
  tools?: Partial<Tools>;
  placeholder?: string;
  readOnly?: boolean;
  /* Width. [Default] - 400px. Will be DEPRECATED, use style object  */
  width?: number | string;
  /* Style CSS Object. [Default] - { width: 400, paddingBottom: 100 }
   */
  style?: number | string;
  /* Change handler  */
  onChange?: (value: YooptaContentValue, options: YooptaOnChangeOptions) => void;
  /* Path change handler */
  onPathChange?: (path: YooptaPath) => void;
};

Editor API

export type YooEditor = {
  id: string;
  readOnly: boolean;
  isEmpty: () => boolean;

  // block handlers
  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 handlers
  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>;

  // core handlers
  applyTransforms: WithoutFirstArg<typeof applyTransforms>;
  batchOperations: (fn: () => void) => void;

  // events handlers
  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;

  // focus handlers
  isFocused: () => boolean;
  blur: (options?: EditorBlurOptions) => void;
  focus: () => void;

  // parser handlers
  getHTML: (content: YooptaContentValue) => string;
  getMarkdown: (content: YooptaContentValue) => string;
  getPlainText: (content: YooptaContentValue) => string;
  getEmail: (content: YooptaContentValue, templateOptions: EmailTemplateOptions) => string;

  // history
  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>;

  // ref to editor element
  refElement: HTMLElement | null;
};

Hooks from @yoopta/editor

/**
 * Hook to access the Yoopta editor instance. Must be used in children components of <YooptaEditor />.
 * @returns {YooEditor} The editor instance.
 */
useYooptaEditor();

/**
 * Hook to check if the editor is in read-only mode.
 * @returns {boolean} True if the editor is read-only.
 */
useYooptaReadOnly();

/**
 * Hook to check if the editor is focused.
 * @returns {boolean} True if the editor is focused.
 */
useYooptaFocused();

/**
 * Hook to get the data for a specific block by its ID.
 * @param {string} blockId The ID of the block.
 * @returns {YooptaBlockData | undefined} The data of the block, or undefined if not found.
 */
useBlockData(blockId);

/**
 * Hook to get the options for a plugin.
 * @template TOptions The type of options expected.
 * @param {string} blockType The block type associated with the plugin.
 * @returns {PluginOptions<TOptions>} The options of the plugin.
 */
useYooptaPluginOptions<TOptions>(blockType);
4.9.4

6 months ago

4.9.4-rc.1

6 months ago

4.9.4-rc.0

6 months ago

4.9.3

7 months ago

4.9.3-alpha.0

7 months ago

4.9.2

8 months ago

4.9.2-rc.0

8 months ago

4.9.2-rc.2

8 months ago

4.9.2-rc.1

8 months ago

4.9.0

9 months ago

4.9.1

9 months ago

4.8.5-rc.9

9 months ago

4.8.5-rc.10

9 months ago

4.8.5-rc.11

9 months ago

4.8.5-rc.7

9 months ago

4.8.5-rc.8

9 months ago

4.8.5-rc.6

9 months ago

4.8.5-rc.1

9 months ago

4.8.5-rc.2

9 months ago

4.8.5-rc.3

9 months ago

4.8.5-rc.4

9 months ago

4.8.5-rc.5

9 months ago

4.8.4-rc.0

9 months ago

4.8.4

9 months ago

4.8.3

10 months ago

4.8.3-rc.0

10 months ago

4.8.1

10 months ago

4.8.0

10 months ago

4.8.2

10 months ago

4.7.1-rc.8

10 months ago

4.7.1-rc.4

10 months ago

4.7.1-rc.6

10 months ago

4.7.1-rc.7

10 months ago

4.7.1-rc.0

10 months ago

4.7.1-rc.1

10 months ago

4.7.1-rc.3

10 months ago

4.6.10-rc.0

11 months ago

4.7.0

11 months ago

4.6.10-rc.1

11 months ago

4.6.9-rc.1

11 months ago

4.6.9-rc.0

11 months ago

4.6.9

11 months ago

4.6.8

11 months ago

4.6.8-rc.2

11 months ago

4.6.8-rc.1

11 months ago

4.6.8-rc.0

12 months ago

4.6.7

12 months ago

4.6.7-rc.0

12 months ago

4.6.5-rc.3

12 months ago

4.6.5-rc.2

12 months ago

4.6.6

12 months ago

4.6.5

12 months ago

4.5.2-rc.1

1 year ago

4.5.2-rc.2

1 year ago

4.6.3-rc.0

1 year ago

4.5.2-rc.0

1 year ago

4.5.2-rc.3

1 year ago

4.6.3-rc.1

1 year ago

4.6.4-rc.2

12 months ago

4.6.4-rc.1

12 months ago

4.6.4-rc.0

12 months ago

4.6.1

1 year ago

4.6.0

1 year ago

4.6.5-rc.1

12 months ago

4.6.5-rc.0

12 months ago

4.6.3

1 year ago

4.6.2

1 year ago

4.6.4

12 months ago

4.5.1

1 year ago

4.5.0

1 year ago

4.4.1

1 year ago

4.4.0

1 year ago

4.5.0-alpha.3

1 year ago

4.5.0-alpha.2

1 year ago

4.5.0-alpha.1

1 year ago

4.5.0-alpha.0

1 year ago

4.3.2

1 year ago

4.3.1

1 year ago

4.3.0-alpha.0

1 year ago

4.3.0

1 year ago

4.2.0

1 year ago

4.1.1

1 year ago

4.1.0

1 year ago

4.0.0

1 year ago

4.0.0-rc.38

1 year ago

4.0.0-rc.37

1 year ago

4.0.0-rc.36

1 year ago

4.0.0-rc.35

1 year ago

4.0.0-rc.34

1 year ago

4.0.0-rc.32

1 year ago

4.0.0-rc.31

1 year ago

4.0.0-rc.33

1 year ago

4.0.0-rc.30

1 year ago

4.0.0-rc.29

1 year ago

4.0.0-rc.27

1 year ago

4.0.0-rc.28

1 year ago

4.0.0-rc.26

1 year ago

4.0.0-rc.25

1 year ago

4.0.0-rc.24

1 year ago

4.0.0-rc.21

1 year ago

4.0.0-rc.23

1 year ago

4.0.0-rc.22

1 year ago

4.0.0-rc.18

1 year ago

4.0.0-rc.17

1 year ago

4.0.0-rc.19

1 year ago

4.0.0-rc.20

1 year ago

4.0.0-rc.16

1 year ago

4.0.0-rc.15

1 year ago

4.0.0-rc.14

1 year ago

4.0.0-rc.13

1 year ago

4.0.0-rc.12

1 year ago

4.0.0-rc.11

1 year ago

4.0.0-rc.10

1 year ago

4.0.0-rc.9

1 year ago

4.0.0-rc.8

1 year ago

4.0.0-rc.5

1 year ago

4.0.0-rc.4

1 year ago

4.0.0-rc.7

1 year ago

4.0.0-rc.6

1 year ago

4.0.0-rc.3

1 year ago

4.0.0-rc.2

1 year ago

4.0.0-rc.1

1 year ago

4.0.0-rc.0

1 year ago

3.9.0-rc

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

1.9.18-rc

2 years ago

1.9.16-rc

2 years ago

1.9.21-rc

2 years ago

1.9.25-rc

2 years ago

1.9.23-rc

2 years ago

1.9.17-rc

2 years ago

1.9.19-rc

2 years ago

1.9.20-rc

2 years ago

1.9.22-rc

2 years ago

1.9.26-rc

2 years ago

1.9.24-rc

2 years ago

1.9.10-rc

2 years ago

1.9.11-rc

2 years ago

1.9.14-rc

2 years ago

1.9.15-rc

2 years ago

1.9.13-rc

2 years ago

1.9.12-rc

2 years ago

1.9.9-rc

2 years ago

1.9.7-rc

2 years ago

1.9.8-rc

2 years ago

1.9.6-rc

2 years ago

1.9.5-rc

2 years ago

1.9.4-rc

2 years ago

1.9.3-rc

2 years ago

1.9.2-rc

2 years ago

1.9.1-rc

2 years ago

1.9.0-rc

2 years ago