@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 CHANGED
@@ -1 +1 @@
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;
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 { 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);
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 Y = typeof v.useId == "function" ? v.useId : X;
9
- function Z(n, H) {
10
- const [x, w] = F(!1), {
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: B,
13
- renderLoading: $,
14
- hideToolbar: l = !1,
15
- className: T,
16
- style: W,
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: f,
19
- onEditorCreate: p,
20
- onEditorDestroy: m,
21
- onEditorUpdate: E,
22
+ onReady: E,
23
+ onEditorCreate: D,
24
+ onEditorDestroy: I,
25
+ onEditorUpdate: S,
22
26
  onContentError: y,
23
- onException: D,
27
+ onException: C,
24
28
  // Key props that trigger rebuild when changed
25
- document: S,
26
- user: I,
27
- users: R,
28
- modules: g,
29
+ document: R,
30
+ user: g,
31
+ users: h,
32
+ modules: b,
29
33
  // All other props passed through
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,
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: D
46
+ onException: C
38
47
  });
39
- N(() => {
40
- t.current = {
41
- onReady: f,
42
- onEditorCreate: p,
43
- onEditorDestroy: m,
44
- onEditorUpdate: E,
48
+ f(() => {
49
+ o.current = {
50
+ onReady: E,
51
+ onEditorCreate: D,
52
+ onEditorDestroy: I,
53
+ onEditorUpdate: S,
45
54
  onContentError: y,
46
- onException: D
55
+ onException: C
47
56
  };
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,
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: () => i.current
64
+ getInstance: () => u.current
56
65
  }),
57
66
  []
58
- ), N(() => {
59
- b(!0), w(!1), u.current = !0;
60
- let r = !1, d = null;
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 J = (await import("superdoc")).SuperDoc;
64
- if (r) return;
65
- const K = {
66
- ...q,
67
- selector: `#${CSS.escape(h)}`,
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
- ...!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 } : {},
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: (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));
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: (e) => {
81
- r || t.current.onEditorCreate?.(e);
90
+ onEditorCreate: (r) => {
91
+ e || o.current.onEditorCreate?.(r);
82
92
  },
83
93
  onEditorDestroy: () => {
84
- r || t.current.onEditorDestroy?.();
94
+ e || o.current.onEditorDestroy?.();
85
95
  },
86
- onEditorUpdate: (e) => {
87
- r || t.current.onEditorUpdate?.(e);
96
+ onEditorUpdate: (r) => {
97
+ e || o.current.onEditorUpdate?.(r);
88
98
  },
89
- onContentError: (e) => {
90
- r || t.current.onContentError?.(e);
99
+ onContentError: (r) => {
100
+ e || o.current.onContentError?.(r);
91
101
  },
92
- onException: (e) => {
93
- r || t.current.onException?.(e);
102
+ onException: (r) => {
103
+ e || o.current.onException?.(r);
94
104
  }
95
105
  };
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 }));
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
- u.current = !1, c.current = null, d && (d.destroy(), i.current = null), r = !0;
111
+ i.current = !1, s.current = null, l && (l.destroy(), u.current = null), e = !0;
102
112
  };
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
- ] });
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 _ = Q(Z);
113
- _.displayName = "SuperDocEditor";
122
+ const ee = W(_);
123
+ ee.displayName = "SuperDocEditor";
114
124
  export {
115
- _ as SuperDocEditor,
116
- _ as default
125
+ ee as SuperDocEditor,
126
+ ee as default
117
127
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/react",
3
- "version": "1.0.0-next.1",
3
+ "version": "1.0.0-rc.2",
4
4
  "description": "Official React wrapper for the SuperDoc document editor",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",