@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 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 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 { 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 { 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 V(f, k) {
7
- const [p, B] = z(!1);
8
- l(() => {
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: F,
14
- renderLoading: u,
15
- hideToolbar: m = !1,
16
- className: H,
17
- style: x,
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: E,
20
- onEditorCreate: D,
21
- onEditorDestroy: S,
22
- onEditorUpdate: C,
18
+ onReady: f,
19
+ onEditorCreate: p,
20
+ onEditorDestroy: m,
21
+ onEditorUpdate: E,
23
22
  onContentError: y,
24
- onException: I,
23
+ onException: D,
25
24
  // Key props that trigger rebuild when changed
26
- document: R,
27
- user: g,
28
- users: b,
29
- modules: M,
25
+ document: S,
26
+ user: I,
27
+ users: R,
28
+ modules: g,
30
29
  // 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` };
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: I
37
+ onException: D
44
38
  });
45
- l(() => {
46
- n.current = {
47
- onReady: E,
48
- onEditorCreate: D,
49
- onEditorDestroy: S,
50
- onEditorUpdate: C,
39
+ N(() => {
40
+ t.current = {
41
+ onReady: f,
42
+ onEditorCreate: p,
43
+ onEditorDestroy: m,
44
+ onEditorUpdate: E,
51
45
  onContentError: y,
52
- onException: I
46
+ onException: D
53
47
  };
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,
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
- ), l(() => {
65
- if (!p) return;
66
- j(!0), s.current = !0;
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 A = (await import("superdoc")).SuperDoc;
71
- if (e) return;
72
- const G = {
73
- ...T,
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
- ...!m && w.current ? { toolbar: `#${CSS.escape(P)}` } : {},
77
- documentMode: t,
78
- role: v,
79
- ...R != null ? { document: R } : {},
80
- ...g ? { user: g } : {},
81
- ...b ? { users: b } : {},
82
- ...M ? { modules: M } : {},
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: (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));
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
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
- onEditorCreate: (r) => {
89
- e || n.current.onEditorCreate?.(r);
80
+ onEditorCreate: (e) => {
81
+ r || t.current.onEditorCreate?.(e);
90
82
  },
91
83
  onEditorDestroy: () => {
92
- e || n.current.onEditorDestroy?.();
84
+ r || t.current.onEditorDestroy?.();
93
85
  },
94
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
- onEditorUpdate: (r) => {
96
- e || n.current.onEditorUpdate?.(r);
86
+ onEditorUpdate: (e) => {
87
+ r || t.current.onEditorUpdate?.(e);
97
88
  },
98
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
- onContentError: (r) => {
100
- e || n.current.onContentError?.(r);
89
+ onContentError: (e) => {
90
+ r || t.current.onContentError?.(e);
101
91
  },
102
- onException: (r) => {
103
- e || n.current.onException?.(r);
92
+ onException: (e) => {
93
+ r || t.current.onException?.(e);
104
94
  }
105
95
  };
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 }));
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
- e = !0, s.current = !1, c.current = null, d && (d.destroy(), i.current = null);
101
+ u.current = !1, c.current = null, d && (d.destroy(), i.current = null), r = !0;
112
102
  };
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;
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 W = K(V);
122
- W.displayName = "SuperDocEditor";
112
+ const _ = Q(Z);
113
+ _.displayName = "SuperDocEditor";
123
114
  export {
124
- W as SuperDocEditor,
125
- W as default
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-canary.7",
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",