@superdoc-dev/react 1.0.0-next.1 → 1.0.0-rc.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.js +95 -85
- 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
|
|
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.js
CHANGED
|
@@ -1,117 +1,127 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as
|
|
3
|
-
import { forwardRef as
|
|
4
|
-
function
|
|
5
|
-
const n =
|
|
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
6
|
return n.current === null && (n.current = `-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`), n.current;
|
|
7
7
|
}
|
|
8
|
-
const
|
|
9
|
-
function
|
|
10
|
-
const [
|
|
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);
|
|
13
|
+
}, []);
|
|
14
|
+
const {
|
|
11
15
|
// React-specific
|
|
12
|
-
id:
|
|
13
|
-
renderLoading:
|
|
14
|
-
hideToolbar:
|
|
15
|
-
className:
|
|
16
|
-
style:
|
|
16
|
+
id: q,
|
|
17
|
+
renderLoading: d,
|
|
18
|
+
hideToolbar: m = !1,
|
|
19
|
+
className: A,
|
|
20
|
+
style: U,
|
|
17
21
|
// Callbacks (stored in ref to avoid triggering rebuilds)
|
|
18
|
-
onReady:
|
|
19
|
-
onEditorCreate:
|
|
20
|
-
onEditorDestroy:
|
|
21
|
-
onEditorUpdate:
|
|
22
|
+
onReady: E,
|
|
23
|
+
onEditorCreate: D,
|
|
24
|
+
onEditorDestroy: I,
|
|
25
|
+
onEditorUpdate: S,
|
|
22
26
|
onContentError: y,
|
|
23
|
-
onException:
|
|
27
|
+
onException: C,
|
|
24
28
|
// Key props that trigger rebuild when changed
|
|
25
|
-
document:
|
|
26
|
-
user:
|
|
27
|
-
users:
|
|
28
|
-
modules:
|
|
29
|
+
document: R,
|
|
30
|
+
user: g,
|
|
31
|
+
users: h,
|
|
32
|
+
modules: b,
|
|
29
33
|
// All other props passed through
|
|
30
|
-
...
|
|
31
|
-
} = n,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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` };
|
|
39
|
+
}
|
|
40
|
+
const { containerId: N, toolbarId: v } = M.current, [K, x] = $(!0), o = c({
|
|
41
|
+
onReady: E,
|
|
42
|
+
onEditorCreate: D,
|
|
43
|
+
onEditorDestroy: I,
|
|
44
|
+
onEditorUpdate: S,
|
|
36
45
|
onContentError: y,
|
|
37
|
-
onException:
|
|
46
|
+
onException: C
|
|
38
47
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
onReady:
|
|
42
|
-
onEditorCreate:
|
|
43
|
-
onEditorDestroy:
|
|
44
|
-
onEditorUpdate:
|
|
48
|
+
f(() => {
|
|
49
|
+
o.current = {
|
|
50
|
+
onReady: E,
|
|
51
|
+
onEditorCreate: D,
|
|
52
|
+
onEditorDestroy: I,
|
|
53
|
+
onEditorUpdate: S,
|
|
45
54
|
onContentError: y,
|
|
46
|
-
onException:
|
|
55
|
+
onException: C
|
|
47
56
|
};
|
|
48
|
-
}, [
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}, [
|
|
53
|
-
|
|
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,
|
|
54
63
|
() => ({
|
|
55
|
-
getInstance: () =>
|
|
64
|
+
getInstance: () => u.current
|
|
56
65
|
}),
|
|
57
66
|
[]
|
|
58
|
-
),
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
), f(() => {
|
|
68
|
+
if (!p) return;
|
|
69
|
+
x(!0), L(!1), i.current = !0;
|
|
70
|
+
let e = !1, l = null;
|
|
61
71
|
return (async () => {
|
|
62
72
|
try {
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
const
|
|
66
|
-
...
|
|
67
|
-
selector: `#${CSS.escape(
|
|
73
|
+
const O = (await import("superdoc")).SuperDoc;
|
|
74
|
+
if (e) return;
|
|
75
|
+
const Q = {
|
|
76
|
+
...G,
|
|
77
|
+
selector: `#${CSS.escape(N)}`,
|
|
68
78
|
// Use internal toolbar container unless hideToolbar is true
|
|
69
|
-
...!
|
|
70
|
-
documentMode:
|
|
71
|
-
role:
|
|
72
|
-
...
|
|
73
|
-
...
|
|
74
|
-
...
|
|
75
|
-
...
|
|
79
|
+
...!m && z.current ? { toolbar: `#${CSS.escape(v)}` } : {},
|
|
80
|
+
documentMode: t,
|
|
81
|
+
role: k,
|
|
82
|
+
...R != null ? { document: R } : {},
|
|
83
|
+
...g ? { user: g } : {},
|
|
84
|
+
...h ? { users: h } : {},
|
|
85
|
+
...b ? { modules: b } : {},
|
|
76
86
|
// Wire up callbacks with lifecycle guards
|
|
77
|
-
onReady: (
|
|
78
|
-
|
|
87
|
+
onReady: (r) => {
|
|
88
|
+
e || (x(!1), i.current = !1, s.current && s.current !== t && (r.superdoc.setDocumentMode(s.current), s.current = null), o.current.onReady?.(r));
|
|
79
89
|
},
|
|
80
|
-
onEditorCreate: (
|
|
81
|
-
|
|
90
|
+
onEditorCreate: (r) => {
|
|
91
|
+
e || o.current.onEditorCreate?.(r);
|
|
82
92
|
},
|
|
83
93
|
onEditorDestroy: () => {
|
|
84
|
-
|
|
94
|
+
e || o.current.onEditorDestroy?.();
|
|
85
95
|
},
|
|
86
|
-
onEditorUpdate: (
|
|
87
|
-
|
|
96
|
+
onEditorUpdate: (r) => {
|
|
97
|
+
e || o.current.onEditorUpdate?.(r);
|
|
88
98
|
},
|
|
89
|
-
onContentError: (
|
|
90
|
-
|
|
99
|
+
onContentError: (r) => {
|
|
100
|
+
e || o.current.onContentError?.(r);
|
|
91
101
|
},
|
|
92
|
-
onException: (
|
|
93
|
-
|
|
102
|
+
onException: (r) => {
|
|
103
|
+
e || o.current.onException?.(r);
|
|
94
104
|
}
|
|
95
105
|
};
|
|
96
|
-
|
|
97
|
-
} catch (
|
|
98
|
-
|
|
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 }));
|
|
99
109
|
}
|
|
100
110
|
})(), () => {
|
|
101
|
-
|
|
111
|
+
i.current = !1, s.current = null, l && (l.destroy(), u.current = null), e = !0;
|
|
102
112
|
};
|
|
103
|
-
}, [
|
|
104
|
-
const
|
|
105
|
-
return /* @__PURE__ */
|
|
106
|
-
!
|
|
107
|
-
/* @__PURE__ */ a("div", { id:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
] });
|
|
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;
|
|
111
121
|
}
|
|
112
|
-
const
|
|
113
|
-
|
|
122
|
+
const ee = W(_);
|
|
123
|
+
ee.displayName = "SuperDocEditor";
|
|
114
124
|
export {
|
|
115
|
-
|
|
116
|
-
|
|
125
|
+
ee as SuperDocEditor,
|
|
126
|
+
ee as default
|
|
117
127
|
};
|