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