@kerebron/editor-react 0.4.27 → 0.4.28
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/esm/EditorContent.d.ts +26 -0
- package/esm/EditorContent.d.ts.map +1 -0
- package/esm/EditorContent.js +31 -0
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/mod.d.ts +24 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +24 -0
- package/esm/package.json +3 -0
- package/esm/useEditor.d.ts +38 -0
- package/esm/useEditor.d.ts.map +1 -0
- package/esm/useEditor.js +69 -0
- package/package.json +2 -3
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { CoreEditor } from '@kerebron/editor';
|
|
3
|
+
export interface EditorContentProps {
|
|
4
|
+
/** The editor instance from useEditor */
|
|
5
|
+
editor: CoreEditor | null;
|
|
6
|
+
/** Additional class name */
|
|
7
|
+
className?: string;
|
|
8
|
+
/** Additional inline styles */
|
|
9
|
+
style?: React.CSSProperties;
|
|
10
|
+
}
|
|
11
|
+
export interface EditorContentRef {
|
|
12
|
+
/** Get the container element */
|
|
13
|
+
getElement: () => HTMLDivElement | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* EditorContent renders the Kerebron editor.
|
|
17
|
+
* Use with the useEditor hook.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const editor = useEditor({ extensions: [StarterKit] })
|
|
22
|
+
* return <EditorContent editor={editor} />
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const EditorContent: React.ForwardRefExoticComponent<EditorContentProps & React.RefAttributes<EditorContentRef>>;
|
|
26
|
+
//# sourceMappingURL=EditorContent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditorContent.d.ts","sourceRoot":"","sources":["../src/EditorContent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAKN,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,kBAAkB;IACjC,yCAAyC;IACzC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1B,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,gCAAgC;IAChC,UAAU,EAAE,MAAM,cAAc,GAAG,IAAI,CAAC;CACzC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,6FAkCzB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useRef, } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* EditorContent renders the Kerebron editor.
|
|
4
|
+
* Use with the useEditor hook.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const editor = useEditor({ extensions: [StarterKit] })
|
|
9
|
+
* return <EditorContent editor={editor} />
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export const EditorContent = forwardRef(function EditorContent({ editor, className = '', style }, ref) {
|
|
13
|
+
const containerRef = useRef(null);
|
|
14
|
+
useImperativeHandle(ref, () => ({
|
|
15
|
+
getElement: () => containerRef.current,
|
|
16
|
+
}));
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const container = containerRef.current;
|
|
19
|
+
if (!container || !editor)
|
|
20
|
+
return;
|
|
21
|
+
// Get the editor's DOM element and append it to our container
|
|
22
|
+
const editorDom = editor.view?.dom;
|
|
23
|
+
if (editorDom && editorDom.parentElement !== container) {
|
|
24
|
+
container.appendChild(editorDom);
|
|
25
|
+
}
|
|
26
|
+
return () => {
|
|
27
|
+
// Don't remove on cleanup - editor.destroy() handles this
|
|
28
|
+
};
|
|
29
|
+
}, [editor]);
|
|
30
|
+
return (React.createElement("div", { ref: containerRef, className: `kb-component ${className}`.trim(), style: style }));
|
|
31
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const dntGlobals = {};
|
|
2
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
3
|
+
function createMergeProxy(baseObj, extObj) {
|
|
4
|
+
return new Proxy(baseObj, {
|
|
5
|
+
get(_target, prop, _receiver) {
|
|
6
|
+
if (prop in extObj) {
|
|
7
|
+
return extObj[prop];
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return baseObj[prop];
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
set(_target, prop, value) {
|
|
14
|
+
if (prop in extObj) {
|
|
15
|
+
delete extObj[prop];
|
|
16
|
+
}
|
|
17
|
+
baseObj[prop] = value;
|
|
18
|
+
return true;
|
|
19
|
+
},
|
|
20
|
+
deleteProperty(_target, prop) {
|
|
21
|
+
let success = false;
|
|
22
|
+
if (prop in extObj) {
|
|
23
|
+
delete extObj[prop];
|
|
24
|
+
success = true;
|
|
25
|
+
}
|
|
26
|
+
if (prop in baseObj) {
|
|
27
|
+
delete baseObj[prop];
|
|
28
|
+
success = true;
|
|
29
|
+
}
|
|
30
|
+
return success;
|
|
31
|
+
},
|
|
32
|
+
ownKeys(_target) {
|
|
33
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
34
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
35
|
+
const extKeysSet = new Set(extKeys);
|
|
36
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
37
|
+
},
|
|
38
|
+
defineProperty(_target, prop, desc) {
|
|
39
|
+
if (prop in extObj) {
|
|
40
|
+
delete extObj[prop];
|
|
41
|
+
}
|
|
42
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
43
|
+
return true;
|
|
44
|
+
},
|
|
45
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
46
|
+
if (prop in extObj) {
|
|
47
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
has(_target, prop) {
|
|
54
|
+
return prop in extObj || prop in baseObj;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
package/esm/mod.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React bindings for Kerebron Editor
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```tsx
|
|
6
|
+
* import { useEditor, EditorContent } from '@kerebron/editor-react'
|
|
7
|
+
* import { StarterKit } from '@kerebron/editor-kits/StarterKit'
|
|
8
|
+
*
|
|
9
|
+
* const MyEditor = () => {
|
|
10
|
+
* const editor = useEditor({
|
|
11
|
+
* extensions: [StarterKit],
|
|
12
|
+
* content: '<p>Hello World!</p>',
|
|
13
|
+
* })
|
|
14
|
+
*
|
|
15
|
+
* return <EditorContent editor={editor} />
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
export { useEditor, type UseEditorOptions } from './useEditor.js';
|
|
22
|
+
export { EditorContent, type EditorContentProps, type EditorContentRef, } from './EditorContent.js';
|
|
23
|
+
export { CoreEditor } from '@kerebron/editor';
|
|
24
|
+
//# sourceMappingURL=mod.d.ts.map
|
package/esm/mod.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EACL,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,GACtB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
package/esm/mod.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React bindings for Kerebron Editor
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```tsx
|
|
6
|
+
* import { useEditor, EditorContent } from '@kerebron/editor-react'
|
|
7
|
+
* import { StarterKit } from '@kerebron/editor-kits/StarterKit'
|
|
8
|
+
*
|
|
9
|
+
* const MyEditor = () => {
|
|
10
|
+
* const editor = useEditor({
|
|
11
|
+
* extensions: [StarterKit],
|
|
12
|
+
* content: '<p>Hello World!</p>',
|
|
13
|
+
* })
|
|
14
|
+
*
|
|
15
|
+
* return <EditorContent editor={editor} />
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
export { useEditor } from './useEditor.js';
|
|
22
|
+
export { EditorContent, } from './EditorContent.js';
|
|
23
|
+
// Re-export CoreEditor for convenience
|
|
24
|
+
export { CoreEditor } from '@kerebron/editor';
|
package/esm/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type DependencyList } from 'react';
|
|
2
|
+
import { CoreEditor } from '@kerebron/editor';
|
|
3
|
+
import type { AnyExtensionOrReq, Content } from '@kerebron/editor';
|
|
4
|
+
export interface UseEditorOptions {
|
|
5
|
+
/** Array of extensions to use */
|
|
6
|
+
extensions?: AnyExtensionOrReq[];
|
|
7
|
+
/** Initial HTML content */
|
|
8
|
+
content?: string;
|
|
9
|
+
/** Initial JSON content */
|
|
10
|
+
initialContent?: Content;
|
|
11
|
+
/** CDN URL for WASM files */
|
|
12
|
+
cdnUrl?: string;
|
|
13
|
+
/** Document URI */
|
|
14
|
+
uri?: string;
|
|
15
|
+
/** Called when editor is ready */
|
|
16
|
+
onReady?: (editor: CoreEditor) => void;
|
|
17
|
+
/** Called on every transaction */
|
|
18
|
+
onTransaction?: (editor: CoreEditor) => void;
|
|
19
|
+
/** Called when content changes */
|
|
20
|
+
onChange?: (editor: CoreEditor) => void;
|
|
21
|
+
/** Prevent immediate render (useful for SSR) */
|
|
22
|
+
immediatelyRender?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* React hook for creating and managing a Kerebron editor instance.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* const editor = useEditor({
|
|
30
|
+
* extensions: [StarterKit],
|
|
31
|
+
* content: '<p>Hello World!</p>',
|
|
32
|
+
* })
|
|
33
|
+
*
|
|
34
|
+
* return <EditorContent editor={editor} />
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function useEditor(options?: UseEditorOptions, deps?: DependencyList): CoreEditor | null;
|
|
38
|
+
//# sourceMappingURL=useEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditor.d.ts","sourceRoot":"","sources":["../src/useEditor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEnE,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,UAAU,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACjC,2BAA2B;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,6BAA6B;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mBAAmB;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACvC,kCAAkC;IAClC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IAC7C,kCAAkC;IAClC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACxC,gDAAgD;IAChD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CACvB,OAAO,GAAE,gBAAqB,EAC9B,IAAI,GAAE,cAAmB,GACxB,UAAU,GAAG,IAAI,CAyEnB"}
|
package/esm/useEditor.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as dntShim from "./_dnt.shims.js";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { CoreEditor } from '@kerebron/editor';
|
|
4
|
+
/**
|
|
5
|
+
* React hook for creating and managing a Kerebron editor instance.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* const editor = useEditor({
|
|
10
|
+
* extensions: [StarterKit],
|
|
11
|
+
* content: '<p>Hello World!</p>',
|
|
12
|
+
* })
|
|
13
|
+
*
|
|
14
|
+
* return <EditorContent editor={editor} />
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function useEditor(options = {}, deps = []) {
|
|
18
|
+
const [editor, setEditor] = useState(null);
|
|
19
|
+
const editorContainerRef = useRef(null);
|
|
20
|
+
const optionsRef = useRef(options);
|
|
21
|
+
// Keep options ref updated
|
|
22
|
+
optionsRef.current = options;
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
// Skip if SSR and immediatelyRender is false
|
|
25
|
+
if (options.immediatelyRender === false && typeof dntShim.dntGlobalThis === 'undefined') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const { extensions = [], content, initialContent, cdnUrl, uri, onReady, onTransaction, onChange, } = optionsRef.current;
|
|
29
|
+
// Create a container element for the editor
|
|
30
|
+
const container = document.createElement('div');
|
|
31
|
+
editorContainerRef.current = container;
|
|
32
|
+
const editorInstance = new CoreEditor({
|
|
33
|
+
element: container,
|
|
34
|
+
extensions,
|
|
35
|
+
content: initialContent,
|
|
36
|
+
cdnUrl,
|
|
37
|
+
uri,
|
|
38
|
+
});
|
|
39
|
+
// Set up event listeners
|
|
40
|
+
if (onTransaction) {
|
|
41
|
+
editorInstance.addEventListener('transaction', () => {
|
|
42
|
+
onTransaction(editorInstance);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (onChange) {
|
|
46
|
+
editorInstance.addEventListener('changed', () => {
|
|
47
|
+
onChange(editorInstance);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
// Load HTML content if provided
|
|
51
|
+
if (content) {
|
|
52
|
+
const buffer = new TextEncoder().encode(content);
|
|
53
|
+
editorInstance.loadDocument('text/html', buffer).catch(() => {
|
|
54
|
+
// If HTML loading fails, try setting as plain text
|
|
55
|
+
console.warn('Failed to load HTML content');
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
setEditor(editorInstance);
|
|
59
|
+
if (onReady) {
|
|
60
|
+
onReady(editorInstance);
|
|
61
|
+
}
|
|
62
|
+
// Cleanup
|
|
63
|
+
return () => {
|
|
64
|
+
editorInstance.destroy();
|
|
65
|
+
setEditor(null);
|
|
66
|
+
};
|
|
67
|
+
}, deps); // eslint-disable-line react-hooks/exhaustive-deps
|
|
68
|
+
return editor;
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kerebron/editor-react",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.28",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"module": "./esm/mod.js",
|
|
6
6
|
"exports": {
|
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
11
|
"scripts": {},
|
|
12
|
-
"files": [],
|
|
13
12
|
"dependencies": {
|
|
14
|
-
"@kerebron/editor": "0.4.
|
|
13
|
+
"@kerebron/editor": "0.4.28",
|
|
15
14
|
"react": "^19"
|
|
16
15
|
},
|
|
17
16
|
"devDependencies": {
|