@yoopta/editor 6.0.0-beta.17 → 6.0.0-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,199 +1,136 @@
1
- # Core package
1
+ # @yoopta/editor
2
2
 
3
- This is core package for Yoopta-Editor
3
+ Core headless package for Yoopta Editor. Provides the editor instance, block/element/mark logic, and React component. Plugins and marks are passed to `createYooptaEditor`; UI (toolbars, slash menu, block actions) is rendered as **children** of `<YooptaEditor>` from `@yoopta/ui`.
4
4
 
5
- ### Installation
5
+ ## Installation
6
6
 
7
7
  ```bash
8
- yarn add @yoopta/editor
8
+ yarn add slate slate-react slate-dom @yoopta/editor
9
9
  ```
10
10
 
11
- ### Usage
11
+ Peer dependencies: `slate`, `slate-react`, `slate-dom`.
12
+
13
+ ## Quick Start
14
+
15
+ Plugins, marks, and optional initial value are passed to `createYooptaEditor`. The component receives only the `editor` instance and callbacks.
12
16
 
13
17
  ```tsx
14
- import YooptaEditor, { createYooptaEditor, YooEditor } from '@yoopta/editor';
15
- // plugins
18
+ import { useMemo } from 'react';
19
+ import YooptaEditor, { createYooptaEditor, type YooptaContentValue } from '@yoopta/editor';
16
20
  import Paragraph from '@yoopta/paragraph';
21
+ import { Bold, Italic } from '@yoopta/marks';
17
22
 
18
23
  const plugins = [Paragraph];
24
+ const marks = [Bold, Italic];
25
+ const initialValue = {} as YooptaContentValue;
26
+
27
+ export default function Editor() {
28
+ const editor = useMemo(
29
+ () => createYooptaEditor({ plugins, marks, value: initialValue }),
30
+ [],
31
+ );
32
+
33
+ return (
34
+ <YooptaEditor
35
+ editor={editor}
36
+ placeholder="Type / to open menu"
37
+ onChange={(value) => console.log(value)}
38
+ />
39
+ );
40
+ }
41
+ ```
19
42
 
20
- const Editor = () => {
21
- // create instance
22
- const editor: YooEditor = useMemo(() => createYooptaEditor(), []);
23
- const [value, setValue] = useState();
43
+ To add toolbar and slash menu, install `@yoopta/ui` and render them as **children** of `<YooptaEditor>`:
24
44
 
25
- const onChange = (newValue) => setValue(newValue);
45
+ ```tsx
46
+ import { FloatingToolbar, FloatingBlockActions, SlashCommandMenu } from '@yoopta/ui';
26
47
 
27
- return <YooptaEditor editor={editor} plugins={plugins} value={value} onChange={onChange} />;
28
- };
48
+ <YooptaEditor editor={editor} onChange={onChange} placeholder="Type / to open menu">
49
+ <FloatingToolbar />
50
+ <FloatingBlockActions />
51
+ <SlashCommandMenu />
52
+ </YooptaEditor>
29
53
  ```
30
54
 
31
- ### YooptaEditor component props
55
+ ## YooptaEditor props
56
+
57
+ | Prop | Type | Description |
58
+ |------|------|-------------|
59
+ | `editor` | `YooEditor` | **Required.** Instance from `createYooptaEditor`. |
60
+ | `onChange` | `(value, options) => void` | Called when content changes. |
61
+ | `onPathChange` | `(path) => void` | Called when the current block path changes. |
62
+ | `autoFocus` | `boolean` | Focus editor on mount. Default: `true`. |
63
+ | `className` | `string` | Additional CSS class (default: `.yoopta-editor`). |
64
+ | `style` | `CSSProperties` | Inline styles (e.g. `{ width: 750, paddingBottom: 100 }`). |
65
+ | `placeholder` | `string` | Placeholder when the editor is empty. |
66
+ | `children` | `ReactNode` | UI components (toolbar, slash menu, block actions, etc.). |
67
+ | `renderBlock` | `(props) => ReactNode` | Custom wrapper per block (e.g. for drag-and-drop). |
68
+
69
+ Initial content is set via `createYooptaEditor({ value })` or later with `editor.setEditorValue(value)`. Do not pass `plugins`, `marks`, or `value` to `<YooptaEditor>`.
70
+
71
+ ## createYooptaEditor options
32
72
 
33
73
  ```ts
34
- type Props = {
35
- /**
36
- * Instance of editor
37
- */
38
- editor: YooEditor;
39
- /**
40
- * Optional custom id. Useful for multiple instances
41
- */
42
- id?: string;
43
- /**
44
- * List of plugins
45
- */
46
- plugins: YooptaPlugin[];
47
- /**
48
- * List of marks from @yoopta/marks
49
- */
50
- marks?: YooptaMark<any>[];
51
- /**
52
- * Optional value of editor. DEFAULT - [undefined]
53
- */
74
+ createYooptaEditor({
75
+ plugins: YooptaPlugin[]; // required
76
+ marks?: YooptaMark[]; // optional
54
77
  value?: YooptaContentValue;
55
- /**
56
- * Autofocus when editor is ready. DEFAULT - [true]
57
- */
58
- autoFocus?: boolean;
59
- /**
60
- * Additional className for your needs. DEFAULT - [.yoopta-editor]
61
- */
62
- className?: string;
63
- /**
64
- * Box for selection area to select by mouse several blocks. DEFAULT - [document]
65
- */
66
- selectionBoxElement?: HTMLElement | React.MutableRefObject<HTMLElement | null> | false;
67
- children?: React.ReactNode;
68
- placeholder?: string;
69
78
  readOnly?: boolean;
70
- /* Width. [Default] - 400px. Will be DEPRECATED, use style object */
71
- width?: number | string;
72
- /* Style CSS Object. [Default] - { width: 400, paddingBottom: 100 }
73
- */
74
- style?: number | string;
75
- /* Change handler */
76
- onChange?: (value: YooptaContentValue, options: YooptaOnChangeOptions) => void;
77
- /* Path change handler */
78
- onPathChange?: (path: YooptaPath) => void;
79
- };
79
+ id?: string;
80
+ });
80
81
  ```
81
82
 
82
- ### Editor API
83
+ ## Editor API (YooEditor)
83
84
 
84
- ```tsx
85
- export type YooEditor = {
86
- id: string;
87
- readOnly: boolean;
88
- isEmpty: () => boolean;
89
-
90
- // block handlers
91
- insertBlock: WithoutFirstArg<typeof insertBlock>;
92
- updateBlock: WithoutFirstArg<typeof updateBlock>;
93
- deleteBlock: WithoutFirstArg<typeof deleteBlock>;
94
- duplicateBlock: WithoutFirstArg<typeof duplicateBlock>;
95
- toggleBlock: WithoutFirstArg<typeof toggleBlock>;
96
- increaseBlockDepth: WithoutFirstArg<typeof increaseBlockDepth>;
97
- decreaseBlockDepth: WithoutFirstArg<typeof decreaseBlockDepth>;
98
- moveBlock: WithoutFirstArg<typeof moveBlock>;
99
- focusBlock: WithoutFirstArg<typeof focusBlock>;
100
- mergeBlock: () => void;
101
- splitBlock: (options?: SplitBlockOptions) => void;
102
- getBlock: (options: GetBlockOptions) => YooptaBlockData | null;
103
-
104
- // path handlers
105
- path: YooptaPath;
106
- setPath: (path: YooptaPath) => void;
107
-
108
- children: YooptaContentValue;
109
- getEditorValue: () => YooptaContentValue;
110
- setEditorValue: WithoutFirstArg<typeof setEditorValue>;
111
- blockEditorsMap: YooptaPluginsEditorMap;
112
- blocks: YooptaBlocks;
113
- formats: YooptaFormats;
114
- shortcuts: Record<string, YooptaBlock>;
115
- plugins: Record<string, Plugin<Record<string, SlateElement>, unknown>>;
116
- commands: Record<string, (...args: any[]) => any>;
117
-
118
- // core handlers
119
- applyTransforms: WithoutFirstArg<typeof applyTransforms>;
120
- batchOperations: (fn: () => void) => void;
121
-
122
- // events handlers
123
- on: <K extends keyof YooptaEventsMap>(
124
- event: K,
125
- fn: (payload: YooptaEventsMap[K]) => void,
126
- ) => void;
127
- once: <K extends keyof YooptaEventsMap>(
128
- event: K,
129
- fn: (payload: YooptaEventsMap[K]) => void,
130
- ) => void;
131
- off: <K extends keyof YooptaEventsMap>(
132
- event: K,
133
- fn: (payload: YooptaEventsMap[K]) => void,
134
- ) => void;
135
- emit: <K extends keyof YooptaEventsMap>(event: K, payload: YooptaEventsMap[K]) => void;
136
-
137
- // focus handlers
138
- isFocused: () => boolean;
139
- blur: (options?: EditorBlurOptions) => void;
140
- focus: () => void;
141
-
142
- // parser handlers
143
- getHTML: (content: YooptaContentValue) => string;
144
- getMarkdown: (content: YooptaContentValue) => string;
145
- getPlainText: (content: YooptaContentValue) => string;
146
- getEmail: (content: YooptaContentValue, templateOptions: EmailTemplateOptions) => string;
147
-
148
- // history
149
- historyStack: Record<HistoryStackName, HistoryStack[]>;
150
- isSavingHistory: WithoutFirstArg<typeof YooptaHistory.isSavingHistory>;
151
- isMergingHistory: WithoutFirstArg<typeof YooptaHistory.isMergingHistory>;
152
- withoutSavingHistory: WithoutFirstArg<typeof YooptaHistory.withoutSavingHistory>;
153
- withoutMergingHistory: WithoutFirstArg<typeof YooptaHistory.withoutMergingHistory>;
154
- withMergingHistory: WithoutFirstArg<typeof YooptaHistory.withMergingHistory>;
155
- withSavingHistory: WithoutFirstArg<typeof YooptaHistory.withSavingHistory>;
156
- redo: WithoutFirstArg<typeof YooptaHistory.redo>;
157
- undo: WithoutFirstArg<typeof YooptaHistory.undo>;
158
-
159
- // ref to editor element
160
- refElement: HTMLElement | null;
161
- };
162
- ```
85
+ - **Content:** `getEditorValue()`, `setEditorValue(value)`
86
+ - **Blocks:** `insertBlock`, `updateBlock`, `deleteBlock`, `duplicateBlock`, `toggleBlock`, `moveBlock`, `focusBlock`, `mergeBlock`, `splitBlock`, `increaseBlockDepth`, `decreaseBlockDepth`, `getBlock`
87
+ - **Transforms:** `applyTransforms([{ type: 'validate_block_paths' }])`
88
+ - **History:** `undo()`, `redo()`, `batchOperations(fn)`
89
+ - **Events:** `on`, `off`, `once`, `emit` — events: `change`, `focus`, `blur`, `path-change`, `block:copy`
90
+ - **Parsers:** `getHTML(value)`, `getMarkdown(value)`, `getPlainText(value)`, `getEmail(value, options)`
91
+ - **Focus:** `focus()`, `blur()`, `isFocused()`
92
+ - **Element builder:** `editor.y` for building block/element structures programmatically
93
+
94
+ ## Namespace APIs
163
95
 
164
- ### Hooks from @yoopta/editor
96
+ Use these for programmatic control (e.g. inside toolbar or custom UI):
165
97
 
166
98
  ```ts
167
- /**
168
- * Hook to access the Yoopta editor instance. Must be used in children components of <YooptaEditor />.
169
- * @returns {YooEditor} The editor instance.
170
- */
171
- useYooptaEditor();
172
-
173
- /**
174
- * Hook to check if the editor is in read-only mode.
175
- * @returns {boolean} True if the editor is read-only.
176
- */
177
- useYooptaReadOnly();
178
-
179
- /**
180
- * Hook to check if the editor is focused.
181
- * @returns {boolean} True if the editor is focused.
182
- */
183
- useYooptaFocused();
184
-
185
- /**
186
- * Hook to get the data for a specific block by its ID.
187
- * @param {string} blockId The ID of the block.
188
- * @returns {YooptaBlockData | undefined} The data of the block, or undefined if not found.
189
- */
190
- useBlockData(blockId);
191
-
192
- /**
193
- * Hook to get the options for a plugin.
194
- * @template TOptions The type of options expected.
195
- * @param {string} blockType The block type associated with the plugin.
196
- * @returns {PluginOptions<TOptions>} The options of the plugin.
197
- */
198
- useYooptaPluginOptions<TOptions>(blockType);
99
+ import { Blocks, Elements, Marks, Selection } from '@yoopta/editor';
100
+
101
+ // Block operations
102
+ Blocks.insertBlock(editor, { ... });
103
+ Blocks.updateBlock(editor, { ... });
104
+ Blocks.deleteBlock(editor, { ... });
105
+ Blocks.getBlock(editor, { id: blockId });
106
+
107
+ // Element operations (within a block)
108
+ Elements.insertElement(editor, { ... });
109
+ Elements.updateElement(editor, { ... });
110
+ Elements.getElement(editor, { ... });
111
+
112
+ // Text formatting (marks)
113
+ Marks.toggle(editor, { type: 'bold' });
114
+ Marks.isActive(editor, { type: 'bold' });
199
115
  ```
116
+
117
+ ## Hooks
118
+
119
+ Must be used inside a component that is a **child** of `<YooptaEditor>` (e.g. inside toolbar or block actions).
120
+
121
+ | Hook | Description |
122
+ |------|-------------|
123
+ | `useYooptaEditor()` | Returns the editor instance. |
124
+ | `useYooptaReadOnly()` | Returns whether the editor is read-only. |
125
+ | `useYooptaFocused()` | Returns whether the editor is focused. |
126
+ | `useBlockData(blockId)` | Returns block data for the given `blockId`. |
127
+ | `useYooptaPluginOptions(blockType)` | Returns options for the plugin of the given block type. |
128
+
129
+ ## Related packages
130
+
131
+ - **@yoopta/ui** — FloatingToolbar, SlashCommandMenu, FloatingBlockActions, BlockOptions, SelectionBox, BlockDndContext, SortableBlock
132
+ - **@yoopta/themes-shadcn** — Styled block UI; use `applyTheme(plugins)` or extend a single plugin with theme elements
133
+ - **@yoopta/marks** — Bold, Italic, Underline, Strike, CodeMark, Highlight, etc.
134
+ - **@yoopta/paragraph**, **@yoopta/headings**, **@yoopta/code**, etc. — Block plugins
135
+
136
+ See the [main README](https://github.com/Darginec05/Yoopta-Editor) and [Quickstart](https://docs.yoopta.dev/quickstart) for full setup with themes and UI.
@@ -1 +1 @@
1
- {"version":3,"file":"yoopta-editor.d.ts","sourceRoot":"","sources":["../src/yoopta-editor.tsx"],"names":[],"mappings":"A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E,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjG,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,eAAe,EAAE,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAC/E,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IAC1C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,kFAAkF;IAClF,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,SAAS,CAAC;CACtD,CAAC;AAQF,QAAA,MAAM,YAAY,yGAUf,iBAAiB,4CAiDnB,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoopta/editor",
3
- "version": "6.0.0-beta.17",
3
+ "version": "6.0.0-beta.19",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -68,5 +68,5 @@
68
68
  "registry": "https://registry.npmjs.org",
69
69
  "access": "public"
70
70
  },
71
- "gitHead": "1197e0459eb2009570e150ef0f054e4dc3a2e39b"
71
+ "gitHead": "88eeca5f42d499d7190e958c8537b19b2330457f"
72
72
  }