@kerebron/editor-react 0.4.28 → 0.4.29

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.
@@ -29,3 +29,4 @@ export const EditorContent = forwardRef(function EditorContent({ editor, classNa
29
29
  }, [editor]);
30
30
  return (React.createElement("div", { ref: containerRef, className: `kb-component ${className}`.trim(), style: style }));
31
31
  });
32
+ //# sourceMappingURL=EditorContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EditorContent.js","sourceRoot":"","sources":["../src/EditorContent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,UAAU,EACV,SAAS,EACT,mBAAmB,EACnB,MAAM,GACP,MAAM,OAAO,CAAC;AAiBf;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CACrC,SAAS,aAAa,CACpB,EAAE,MAAM,EAAE,SAAS,GAAG,EAAE,EAAE,KAAK,EAAsB,EACrD,GAAyC;IAEzC,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAElD,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;QAC9B,UAAU,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO;KACvC,CAAC,CAAC,CAAC;IAEJ,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC;QACvC,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM;YAAE,OAAO;QAElC,8DAA8D;QAC9D,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,EAAE,GAA8B,CAAC;QAC9D,IAAI,SAAS,IAAI,SAAS,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;YACvD,SAAS,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QACnC,CAAC;QAED,OAAO,GAAG,EAAE;YACV,0DAA0D;QAC5D,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO,CACL,6BACE,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,gBAAgB,SAAS,EAAE,CAAC,IAAI,EAAE,EAC7C,KAAK,EAAE,KAAK,GACZ,CACH,CAAC;AACJ,CAAC,CACF,CAAC"}
package/esm/_dnt.shims.js CHANGED
@@ -55,3 +55,4 @@ function createMergeProxy(baseObj, extObj) {
55
55
  },
56
56
  });
57
57
  }
58
+ //# sourceMappingURL=_dnt.shims.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.shims.js","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,EAClB,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AAEtE,SAAS,gBAAgB,CACvB,OAAU,EACV,MAAS;IAET,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE;QACxB,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS;YAC1B,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACnB,OAAQ,MAAc,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;iBAAM,CAAC;gBACN,OAAQ,OAAe,CAAC,IAAI,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;QACD,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK;YACtB,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACnB,OAAQ,MAAc,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YACA,OAAe,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,cAAc,CAAC,OAAO,EAAE,IAAI;YAC1B,IAAI,OAAO,GAAG,KAAK,CAAC;YACpB,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACnB,OAAQ,MAAc,CAAC,IAAI,CAAC,CAAC;gBAC7B,OAAO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,CAAC"}
package/esm/mod.js CHANGED
@@ -22,3 +22,4 @@ export { useEditor } from './useEditor.js';
22
22
  export { EditorContent, } from './EditorContent.js';
23
23
  // Re-export CoreEditor for convenience
24
24
  export { CoreEditor } from '@kerebron/editor';
25
+ //# sourceMappingURL=mod.js.map
package/esm/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,SAAS,EAAyB,MAAM,gBAAgB,CAAC;AAClE,OAAO,EACL,aAAa,GAGd,MAAM,oBAAoB,CAAC;AAE5B,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
package/esm/useEditor.js CHANGED
@@ -67,3 +67,4 @@ export function useEditor(options = {}, deps = []) {
67
67
  }, deps); // eslint-disable-line react-hooks/exhaustive-deps
68
68
  return editor;
69
69
  }
70
+ //# sourceMappingURL=useEditor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEditor.js","sourceRoot":"","sources":["../src/useEditor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAuB,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAwB9C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS,CACvB,UAA4B,EAAE,EAC9B,OAAuB,EAAE;IAEzB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAoB,IAAI,CAAC,CAAC;IAC9D,MAAM,kBAAkB,GAAG,MAAM,CAAqB,IAAI,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAEnC,2BAA2B;IAC3B,UAAU,CAAC,OAAO,GAAG,OAAO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CAAC;QAED,SAAS,CAAC,cAAc,CAAC,CAAC;QAE1B,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC;QAED,UAAU;QACV,OAAO,GAAG,EAAE;YACV,cAAc,CAAC,OAAO,EAAE,CAAC;YACzB,SAAS,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC;IACJ,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,kDAAkD;IAE5D,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kerebron/editor-react",
3
- "version": "0.4.28",
3
+ "version": "0.4.29",
4
4
  "license": "MIT",
5
5
  "module": "./esm/mod.js",
6
6
  "exports": {
@@ -9,8 +9,12 @@
9
9
  }
10
10
  },
11
11
  "scripts": {},
12
+ "files": [
13
+ "esm",
14
+ "src"
15
+ ],
12
16
  "dependencies": {
13
- "@kerebron/editor": "0.4.28",
17
+ "@kerebron/editor": "0.4.29",
14
18
  "react": "^19"
15
19
  },
16
20
  "devDependencies": {
@@ -0,0 +1,67 @@
1
+ import React, {
2
+ forwardRef,
3
+ useEffect,
4
+ useImperativeHandle,
5
+ useRef,
6
+ } from 'react';
7
+ import type { CoreEditor } from '@kerebron/editor';
8
+
9
+ export interface EditorContentProps {
10
+ /** The editor instance from useEditor */
11
+ editor: CoreEditor | null;
12
+ /** Additional class name */
13
+ className?: string;
14
+ /** Additional inline styles */
15
+ style?: React.CSSProperties;
16
+ }
17
+
18
+ export interface EditorContentRef {
19
+ /** Get the container element */
20
+ getElement: () => HTMLDivElement | null;
21
+ }
22
+
23
+ /**
24
+ * EditorContent renders the Kerebron editor.
25
+ * Use with the useEditor hook.
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * const editor = useEditor({ extensions: [StarterKit] })
30
+ * return <EditorContent editor={editor} />
31
+ * ```
32
+ */
33
+ export const EditorContent = forwardRef<EditorContentRef, EditorContentProps>(
34
+ function EditorContent(
35
+ { editor, className = '', style }: EditorContentProps,
36
+ ref: React.ForwardedRef<EditorContentRef>,
37
+ ) {
38
+ const containerRef = useRef<HTMLDivElement>(null);
39
+
40
+ useImperativeHandle(ref, () => ({
41
+ getElement: () => containerRef.current,
42
+ }));
43
+
44
+ useEffect(() => {
45
+ const container = containerRef.current;
46
+ if (!container || !editor) return;
47
+
48
+ // Get the editor's DOM element and append it to our container
49
+ const editorDom = editor.view?.dom as HTMLElement | undefined;
50
+ if (editorDom && editorDom.parentElement !== container) {
51
+ container.appendChild(editorDom);
52
+ }
53
+
54
+ return () => {
55
+ // Don't remove on cleanup - editor.destroy() handles this
56
+ };
57
+ }, [editor]);
58
+
59
+ return (
60
+ <div
61
+ ref={containerRef}
62
+ className={`kb-component ${className}`.trim()}
63
+ style={style}
64
+ />
65
+ );
66
+ },
67
+ );
@@ -0,0 +1,60 @@
1
+ const dntGlobals = {
2
+ };
3
+ export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
4
+
5
+ function createMergeProxy<T extends object, U extends object>(
6
+ baseObj: T,
7
+ extObj: U,
8
+ ): Omit<T, keyof U> & U {
9
+ return new Proxy(baseObj, {
10
+ get(_target, prop, _receiver) {
11
+ if (prop in extObj) {
12
+ return (extObj as any)[prop];
13
+ } else {
14
+ return (baseObj as any)[prop];
15
+ }
16
+ },
17
+ set(_target, prop, value) {
18
+ if (prop in extObj) {
19
+ delete (extObj as any)[prop];
20
+ }
21
+ (baseObj as any)[prop] = value;
22
+ return true;
23
+ },
24
+ deleteProperty(_target, prop) {
25
+ let success = false;
26
+ if (prop in extObj) {
27
+ delete (extObj as any)[prop];
28
+ success = true;
29
+ }
30
+ if (prop in baseObj) {
31
+ delete (baseObj as any)[prop];
32
+ success = true;
33
+ }
34
+ return success;
35
+ },
36
+ ownKeys(_target) {
37
+ const baseKeys = Reflect.ownKeys(baseObj);
38
+ const extKeys = Reflect.ownKeys(extObj);
39
+ const extKeysSet = new Set(extKeys);
40
+ return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
41
+ },
42
+ defineProperty(_target, prop, desc) {
43
+ if (prop in extObj) {
44
+ delete (extObj as any)[prop];
45
+ }
46
+ Reflect.defineProperty(baseObj, prop, desc);
47
+ return true;
48
+ },
49
+ getOwnPropertyDescriptor(_target, prop) {
50
+ if (prop in extObj) {
51
+ return Reflect.getOwnPropertyDescriptor(extObj, prop);
52
+ } else {
53
+ return Reflect.getOwnPropertyDescriptor(baseObj, prop);
54
+ }
55
+ },
56
+ has(_target, prop) {
57
+ return prop in extObj || prop in baseObj;
58
+ },
59
+ }) as any;
60
+ }
package/src/mod.ts ADDED
@@ -0,0 +1,30 @@
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
+
22
+ export { useEditor, type UseEditorOptions } from './useEditor.js';
23
+ export {
24
+ EditorContent,
25
+ type EditorContentProps,
26
+ type EditorContentRef,
27
+ } from './EditorContent.js';
28
+
29
+ // Re-export CoreEditor for convenience
30
+ export { CoreEditor } from '@kerebron/editor';
@@ -0,0 +1,116 @@
1
+ import * as dntShim from "./_dnt.shims.js";
2
+ import { type DependencyList, useEffect, useRef, useState } from 'react';
3
+ import { CoreEditor } from '@kerebron/editor';
4
+ import type { AnyExtensionOrReq, Content } from '@kerebron/editor';
5
+
6
+ export interface UseEditorOptions {
7
+ /** Array of extensions to use */
8
+ extensions?: AnyExtensionOrReq[];
9
+ /** Initial HTML content */
10
+ content?: string;
11
+ /** Initial JSON content */
12
+ initialContent?: Content;
13
+ /** CDN URL for WASM files */
14
+ cdnUrl?: string;
15
+ /** Document URI */
16
+ uri?: string;
17
+ /** Called when editor is ready */
18
+ onReady?: (editor: CoreEditor) => void;
19
+ /** Called on every transaction */
20
+ onTransaction?: (editor: CoreEditor) => void;
21
+ /** Called when content changes */
22
+ onChange?: (editor: CoreEditor) => void;
23
+ /** Prevent immediate render (useful for SSR) */
24
+ immediatelyRender?: boolean;
25
+ }
26
+
27
+ /**
28
+ * React hook for creating and managing a Kerebron editor instance.
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * const editor = useEditor({
33
+ * extensions: [StarterKit],
34
+ * content: '<p>Hello World!</p>',
35
+ * })
36
+ *
37
+ * return <EditorContent editor={editor} />
38
+ * ```
39
+ */
40
+ export function useEditor(
41
+ options: UseEditorOptions = {},
42
+ deps: DependencyList = [],
43
+ ): CoreEditor | null {
44
+ const [editor, setEditor] = useState<CoreEditor | null>(null);
45
+ const editorContainerRef = useRef<HTMLElement | null>(null);
46
+ const optionsRef = useRef(options);
47
+
48
+ // Keep options ref updated
49
+ optionsRef.current = options;
50
+
51
+ useEffect(() => {
52
+ // Skip if SSR and immediatelyRender is false
53
+ if (options.immediatelyRender === false && typeof dntShim.dntGlobalThis === 'undefined') {
54
+ return;
55
+ }
56
+
57
+ const {
58
+ extensions = [],
59
+ content,
60
+ initialContent,
61
+ cdnUrl,
62
+ uri,
63
+ onReady,
64
+ onTransaction,
65
+ onChange,
66
+ } = optionsRef.current;
67
+
68
+ // Create a container element for the editor
69
+ const container = document.createElement('div');
70
+ editorContainerRef.current = container;
71
+
72
+ const editorInstance = new CoreEditor({
73
+ element: container,
74
+ extensions,
75
+ content: initialContent,
76
+ cdnUrl,
77
+ uri,
78
+ });
79
+
80
+ // Set up event listeners
81
+ if (onTransaction) {
82
+ editorInstance.addEventListener('transaction', () => {
83
+ onTransaction(editorInstance);
84
+ });
85
+ }
86
+
87
+ if (onChange) {
88
+ editorInstance.addEventListener('changed', () => {
89
+ onChange(editorInstance);
90
+ });
91
+ }
92
+
93
+ // Load HTML content if provided
94
+ if (content) {
95
+ const buffer = new TextEncoder().encode(content);
96
+ editorInstance.loadDocument('text/html', buffer).catch(() => {
97
+ // If HTML loading fails, try setting as plain text
98
+ console.warn('Failed to load HTML content');
99
+ });
100
+ }
101
+
102
+ setEditor(editorInstance);
103
+
104
+ if (onReady) {
105
+ onReady(editorInstance);
106
+ }
107
+
108
+ // Cleanup
109
+ return () => {
110
+ editorInstance.destroy();
111
+ setEditor(null);
112
+ };
113
+ }, deps); // eslint-disable-line react-hooks/exhaustive-deps
114
+
115
+ return editor;
116
+ }