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