@superdoc-dev/react 1.0.0-canary.7 → 1.0.0-next.2
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/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -7
- package/dist/index.js +85 -94
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("react/jsx-runtime"),e=require("react");function G(r){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const s in r)if(s!=="default"){const a=Object.getOwnPropertyDescriptor(r,s);Object.defineProperty(i,s,a.get?a:{enumerable:!0,get:()=>r[s]})}}return i.default=r,Object.freeze(i)}const N=G(e);function J(){const r=N.useRef(null);return r.current===null&&(r.current=`-${Date.now()}-${Math.random().toString(36).slice(2,9)}`),r.current}const K=typeof N.useId=="function"?N.useId:J;function Q(r,i){const[s,a]=e.useState(!1),{id:T,renderLoading:w,hideToolbar:m=!1,className:U,style:q,onReady:E,onEditorCreate:S,onEditorDestroy:y,onEditorUpdate:R,onContentError:g,onException:D,document:b,user:I,users:h,modules:j,...F}=r,n=r.documentMode??"editing",O=r.role??"editor",d=e.useRef(null),$=e.useRef(null),H=K(),_=T??`superdoc${H}`,C=_,M=`${_}-toolbar`,[L,v]=e.useState(!0),c=e.useRef({onReady:E,onEditorCreate:S,onEditorDestroy:y,onEditorUpdate:R,onContentError:g,onException:D});e.useEffect(()=>{c.current={onReady:E,onEditorCreate:S,onEditorDestroy:y,onEditorUpdate:R,onContentError:g,onException:D}},[E,S,y,R,g,D]);const u=e.useRef(null),l=e.useRef(!1),k=e.useRef(n);e.useEffect(()=>{k.current!==n&&(d.current?d.current.setDocumentMode(n):l.current&&(u.current=n)),k.current=n},[n]),e.useImperativeHandle(i,()=>({getInstance:()=>d.current}),[]),e.useEffect(()=>{v(!0),a(!1),l.current=!0;let o=!1,p=null;return(async()=>{try{const W=(await import("superdoc")).SuperDoc;if(o)return;const A={...F,selector:`#${CSS.escape(C)}`,...!m&&$.current?{toolbar:`#${CSS.escape(M)}`}:{},documentMode:n,role:O,...b!=null?{document:b}:{},...I?{user:I}:{},...h?{users:h}:{},...j?{modules:j}:{},onReady:t=>{o||(v(!1),l.current=!1,u.current&&u.current!==n&&(t.superdoc.setDocumentMode(u.current),u.current=null),c.current.onReady?.(t))},onEditorCreate:t=>{o||c.current.onEditorCreate?.(t)},onEditorDestroy:()=>{o||c.current.onEditorDestroy?.()},onEditorUpdate:t=>{o||c.current.onEditorUpdate?.(t)},onContentError:t=>{o||c.current.onContentError?.(t)},onException:t=>{o||c.current.onException?.(t)}};p=new W(A),d.current=p}catch(x){o||(l.current=!1,v(!1),a(!0),console.error("[SuperDocEditor] Failed to initialize SuperDoc:",x),c.current.onException?.({error:x}))}})(),()=>{l.current=!1,u.current=null,p&&(p.destroy(),d.current=null),o=!0}},[b,I,h,j,O,m,C,M]);const B=["superdoc-wrapper",U].filter(Boolean).join(" "),z=L?{display:"none"}:void 0;return f.jsxs("div",{className:B,style:q,children:[!m&&f.jsx("div",{ref:$,id:M,className:"superdoc-toolbar-container",style:z}),f.jsx("div",{id:C,className:"superdoc-editor-container",style:z}),L&&!s&&w&&f.jsx("div",{className:"superdoc-loading-container",children:w()}),s&&f.jsx("div",{className:"superdoc-error-container",children:"Failed to load editor. Check console for details."})]})}const P=e.forwardRef(Q);P.displayName="SuperDocEditor";exports.SuperDocEditor=P;exports.default=P;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @superdoc-dev/react - Official React wrapper for SuperDoc
|
|
3
|
-
* @packageDocumentation
|
|
4
|
-
* @version 1.0.0
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
1
|
import { CSSProperties } from 'react';
|
|
8
2
|
import { Editor } from 'superdoc';
|
|
9
3
|
import { ForwardRefExoticComponent } from 'react';
|
|
@@ -15,7 +9,7 @@ import { SuperDoc } from 'superdoc';
|
|
|
15
9
|
* Explicitly typed callback props to ensure proper TypeScript inference.
|
|
16
10
|
* These override any loosely-typed callbacks from SuperDocConfig.
|
|
17
11
|
*/
|
|
18
|
-
declare interface CallbackProps {
|
|
12
|
+
export declare interface CallbackProps {
|
|
19
13
|
/** Callback when SuperDoc is ready */
|
|
20
14
|
onReady?: (event: SuperDocReadyEvent) => void;
|
|
21
15
|
/** Callback after an editor is created */
|
package/dist/index.js
CHANGED
|
@@ -1,126 +1,117 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { jsxs as O, jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import * as v from "react";
|
|
3
|
+
import { forwardRef as Q, useState as F, useRef as s, useEffect as N, useImperativeHandle as V } from "react";
|
|
4
|
+
function X() {
|
|
5
|
+
const n = v.useRef(null);
|
|
6
|
+
return n.current === null && (n.current = `-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`), n.current;
|
|
5
7
|
}
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
B(!0);
|
|
10
|
-
}, []);
|
|
11
|
-
const {
|
|
8
|
+
const Y = typeof v.useId == "function" ? v.useId : X;
|
|
9
|
+
function Z(n, H) {
|
|
10
|
+
const [x, w] = F(!1), {
|
|
12
11
|
// React-specific
|
|
13
|
-
id:
|
|
14
|
-
renderLoading:
|
|
15
|
-
hideToolbar:
|
|
16
|
-
className:
|
|
17
|
-
style:
|
|
12
|
+
id: B,
|
|
13
|
+
renderLoading: $,
|
|
14
|
+
hideToolbar: l = !1,
|
|
15
|
+
className: T,
|
|
16
|
+
style: W,
|
|
18
17
|
// Callbacks (stored in ref to avoid triggering rebuilds)
|
|
19
|
-
onReady:
|
|
20
|
-
onEditorCreate:
|
|
21
|
-
onEditorDestroy:
|
|
22
|
-
onEditorUpdate:
|
|
18
|
+
onReady: f,
|
|
19
|
+
onEditorCreate: p,
|
|
20
|
+
onEditorDestroy: m,
|
|
21
|
+
onEditorUpdate: E,
|
|
23
22
|
onContentError: y,
|
|
24
|
-
onException:
|
|
23
|
+
onException: D,
|
|
25
24
|
// Key props that trigger rebuild when changed
|
|
26
|
-
document:
|
|
27
|
-
user:
|
|
28
|
-
users:
|
|
29
|
-
modules:
|
|
25
|
+
document: S,
|
|
26
|
+
user: I,
|
|
27
|
+
users: R,
|
|
28
|
+
modules: g,
|
|
30
29
|
// All other props passed through
|
|
31
|
-
...
|
|
32
|
-
} =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const { containerId: $, toolbarId: P } = h.current, [q, j] = z(!0), n = o({
|
|
38
|
-
onReady: E,
|
|
39
|
-
onEditorCreate: D,
|
|
40
|
-
onEditorDestroy: S,
|
|
41
|
-
onEditorUpdate: C,
|
|
30
|
+
...q
|
|
31
|
+
} = n, o = n.documentMode ?? "editing", P = n.role ?? "editor", i = s(null), L = s(null), A = Y(), j = B ?? `superdoc${A}`, h = j, C = `${j}-toolbar`, [U, b] = F(!0), t = s({
|
|
32
|
+
onReady: f,
|
|
33
|
+
onEditorCreate: p,
|
|
34
|
+
onEditorDestroy: m,
|
|
35
|
+
onEditorUpdate: E,
|
|
42
36
|
onContentError: y,
|
|
43
|
-
onException:
|
|
37
|
+
onException: D
|
|
44
38
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
onReady:
|
|
48
|
-
onEditorCreate:
|
|
49
|
-
onEditorDestroy:
|
|
50
|
-
onEditorUpdate:
|
|
39
|
+
N(() => {
|
|
40
|
+
t.current = {
|
|
41
|
+
onReady: f,
|
|
42
|
+
onEditorCreate: p,
|
|
43
|
+
onEditorDestroy: m,
|
|
44
|
+
onEditorUpdate: E,
|
|
51
45
|
onContentError: y,
|
|
52
|
-
onException:
|
|
46
|
+
onException: D
|
|
53
47
|
};
|
|
54
|
-
}, [
|
|
55
|
-
const c =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}, [
|
|
59
|
-
|
|
48
|
+
}, [f, p, m, E, y, D]);
|
|
49
|
+
const c = s(null), u = s(!1), k = s(o);
|
|
50
|
+
N(() => {
|
|
51
|
+
k.current !== o && (i.current ? i.current.setDocumentMode(o) : u.current && (c.current = o)), k.current = o;
|
|
52
|
+
}, [o]), V(
|
|
53
|
+
H,
|
|
60
54
|
() => ({
|
|
61
55
|
getInstance: () => i.current
|
|
62
56
|
}),
|
|
63
57
|
[]
|
|
64
|
-
),
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
let e = !1, d = null;
|
|
58
|
+
), N(() => {
|
|
59
|
+
b(!0), w(!1), u.current = !0;
|
|
60
|
+
let r = !1, d = null;
|
|
68
61
|
return (async () => {
|
|
69
62
|
try {
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
const
|
|
73
|
-
...
|
|
74
|
-
selector: `#${CSS.escape(
|
|
63
|
+
const J = (await import("superdoc")).SuperDoc;
|
|
64
|
+
if (r) return;
|
|
65
|
+
const K = {
|
|
66
|
+
...q,
|
|
67
|
+
selector: `#${CSS.escape(h)}`,
|
|
75
68
|
// Use internal toolbar container unless hideToolbar is true
|
|
76
|
-
...!
|
|
77
|
-
documentMode:
|
|
78
|
-
role:
|
|
79
|
-
...
|
|
80
|
-
...
|
|
81
|
-
...
|
|
82
|
-
...
|
|
69
|
+
...!l && L.current ? { toolbar: `#${CSS.escape(C)}` } : {},
|
|
70
|
+
documentMode: o,
|
|
71
|
+
role: P,
|
|
72
|
+
...S != null ? { document: S } : {},
|
|
73
|
+
...I ? { user: I } : {},
|
|
74
|
+
...R ? { users: R } : {},
|
|
75
|
+
...g ? { modules: g } : {},
|
|
83
76
|
// Wire up callbacks with lifecycle guards
|
|
84
|
-
onReady: (
|
|
85
|
-
|
|
77
|
+
onReady: (e) => {
|
|
78
|
+
r || (b(!1), u.current = !1, c.current && c.current !== o && (e.superdoc.setDocumentMode(c.current), c.current = null), t.current.onReady?.(e));
|
|
86
79
|
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
e || n.current.onEditorCreate?.(r);
|
|
80
|
+
onEditorCreate: (e) => {
|
|
81
|
+
r || t.current.onEditorCreate?.(e);
|
|
90
82
|
},
|
|
91
83
|
onEditorDestroy: () => {
|
|
92
|
-
|
|
84
|
+
r || t.current.onEditorDestroy?.();
|
|
93
85
|
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
e || n.current.onEditorUpdate?.(r);
|
|
86
|
+
onEditorUpdate: (e) => {
|
|
87
|
+
r || t.current.onEditorUpdate?.(e);
|
|
97
88
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
e || n.current.onContentError?.(r);
|
|
89
|
+
onContentError: (e) => {
|
|
90
|
+
r || t.current.onContentError?.(e);
|
|
101
91
|
},
|
|
102
|
-
onException: (
|
|
103
|
-
|
|
92
|
+
onException: (e) => {
|
|
93
|
+
r || t.current.onException?.(e);
|
|
104
94
|
}
|
|
105
95
|
};
|
|
106
|
-
d = new
|
|
107
|
-
} catch (
|
|
108
|
-
|
|
96
|
+
d = new J(K), i.current = d;
|
|
97
|
+
} catch (M) {
|
|
98
|
+
r || (u.current = !1, b(!1), w(!0), console.error("[SuperDocEditor] Failed to initialize SuperDoc:", M), t.current.onException?.({ error: M }));
|
|
109
99
|
}
|
|
110
100
|
})(), () => {
|
|
111
|
-
|
|
101
|
+
u.current = !1, c.current = null, d && (d.destroy(), i.current = null), r = !0;
|
|
112
102
|
};
|
|
113
|
-
}, [
|
|
114
|
-
const
|
|
115
|
-
return
|
|
116
|
-
!
|
|
117
|
-
/* @__PURE__ */ a("div", { id:
|
|
118
|
-
|
|
119
|
-
|
|
103
|
+
}, [S, I, R, g, P, l, h, C]);
|
|
104
|
+
const G = ["superdoc-wrapper", T].filter(Boolean).join(" "), z = U ? { display: "none" } : void 0;
|
|
105
|
+
return /* @__PURE__ */ O("div", { className: G, style: W, children: [
|
|
106
|
+
!l && /* @__PURE__ */ a("div", { ref: L, id: C, className: "superdoc-toolbar-container", style: z }),
|
|
107
|
+
/* @__PURE__ */ a("div", { id: h, className: "superdoc-editor-container", style: z }),
|
|
108
|
+
U && !x && $ && /* @__PURE__ */ a("div", { className: "superdoc-loading-container", children: $() }),
|
|
109
|
+
x && /* @__PURE__ */ a("div", { className: "superdoc-error-container", children: "Failed to load editor. Check console for details." })
|
|
110
|
+
] });
|
|
120
111
|
}
|
|
121
|
-
const
|
|
122
|
-
|
|
112
|
+
const _ = Q(Z);
|
|
113
|
+
_.displayName = "SuperDocEditor";
|
|
123
114
|
export {
|
|
124
|
-
|
|
125
|
-
|
|
115
|
+
_ as SuperDocEditor,
|
|
116
|
+
_ as default
|
|
126
117
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdoc-dev/react",
|
|
3
|
-
"version": "1.0.0-
|
|
4
|
-
"description": "Official React wrapper for SuperDoc document editor",
|
|
3
|
+
"version": "1.0.0-next.2",
|
|
4
|
+
"description": "Official React wrapper for the SuperDoc document editor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|