@superdoc-dev/react 1.0.0-next.6 → 1.0.0-next.8

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/README.md CHANGED
@@ -10,6 +10,34 @@ npm install @superdoc-dev/react
10
10
 
11
11
  > `superdoc` is included as a dependency - no need to install it separately.
12
12
 
13
+ ## Pinning SuperDoc Version (Optional)
14
+
15
+ If you need to force a specific `superdoc` version (for example, to align multiple apps or test a local build), pin it in your app's `package.json` using overrides.
16
+
17
+ ### npm
18
+
19
+ ```json
20
+ {
21
+ "overrides": {
22
+ "superdoc": "1.14.1"
23
+ }
24
+ }
25
+ ```
26
+
27
+ ### pnpm
28
+
29
+ ```json
30
+ {
31
+ "pnpm": {
32
+ "overrides": {
33
+ "superdoc": "1.14.1"
34
+ }
35
+ }
36
+ }
37
+ ```
38
+
39
+ Then run your package manager install command again.
40
+
13
41
  ## Quick Start
14
42
 
15
43
  ```tsx
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
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react`);c=s(c);let l=require(`react/jsx-runtime`);function u(){let e=c.useRef(null);return e.current===null&&(e.current=`-${Date.now()}-${Math.random().toString(36).slice(2,9)}`),e.current}const d=typeof c.useId==`function`?c.useId:u;function f(e,t){let[n,r]=(0,c.useState)(!1),{id:i,renderLoading:a,hideToolbar:o=!1,className:s,style:u,onReady:f,onEditorCreate:p,onEditorDestroy:m,onEditorUpdate:h,onContentError:g,onException:_,document:v,user:y,users:b,modules:x,...S}=e,C=e.documentMode??`editing`,w=e.role??`editor`,T=(0,c.useRef)(null),E=(0,c.useRef)(null),D=d(),O=i??`superdoc${D}`,k=O,A=`${O}-toolbar`,[j,M]=(0,c.useState)(!0),N=(0,c.useRef)({onReady:f,onEditorCreate:p,onEditorDestroy:m,onEditorUpdate:h,onContentError:g,onException:_});(0,c.useEffect)(()=>{N.current={onReady:f,onEditorCreate:p,onEditorDestroy:m,onEditorUpdate:h,onContentError:g,onException:_}},[f,p,m,h,g,_]);let P=(0,c.useRef)(null),F=(0,c.useRef)(!1),I=(0,c.useRef)(C);(0,c.useEffect)(()=>{I.current!==C&&(T.current?T.current.setDocumentMode(C):F.current&&(P.current=C)),I.current=C},[C]),(0,c.useImperativeHandle)(t,()=>({getInstance:()=>T.current}),[]),(0,c.useEffect)(()=>{M(!0),r(!1),F.current=!0;let e=!1,t=null;return(async()=>{try{let n=(await import(`superdoc`)).SuperDoc;if(e)return;t=new n({...S,selector:`#${CSS.escape(k)}`,...!o&&E.current?{toolbar:`#${CSS.escape(A)}`}:{},documentMode:C,role:w,...v==null?{}:{document:v},...y?{user:y}:{},...b?{users:b}:{},...x?{modules:x}:{},onReady:t=>{e||(M(!1),F.current=!1,P.current&&P.current!==C&&(t.superdoc.setDocumentMode(P.current),P.current=null),N.current.onReady?.(t))},onEditorCreate:t=>{e||N.current.onEditorCreate?.(t)},onEditorDestroy:()=>{e||N.current.onEditorDestroy?.()},onEditorUpdate:t=>{e||N.current.onEditorUpdate?.(t)},onContentError:t=>{e||N.current.onContentError?.(t)},onException:t=>{e||N.current.onException?.(t)}}),T.current=t}catch(t){e||(F.current=!1,M(!1),r(!0),console.error(`[SuperDocEditor] Failed to initialize SuperDoc:`,t),N.current.onException?.({error:t}))}})(),()=>{F.current=!1,P.current=null,t&&(t.destroy(),T.current=null),e=!0}},[v,y,b,x,w,o,k,A]);let L=[`superdoc-wrapper`,s].filter(Boolean).join(` `),R=j?{display:`none`}:void 0;return(0,l.jsxs)(`div`,{className:L,style:u,children:[!o&&(0,l.jsx)(`div`,{ref:E,id:A,className:`superdoc-toolbar-container`,style:R}),(0,l.jsx)(`div`,{id:k,className:`superdoc-editor-container`,style:R}),j&&!n&&a&&(0,l.jsx)(`div`,{className:`superdoc-loading-container`,children:a()}),n&&(0,l.jsx)(`div`,{className:`superdoc-error-container`,children:`Failed to load editor. Check console for details.`})]})}const p=(0,c.forwardRef)(f);p.displayName=`SuperDocEditor`;var m=p;exports.SuperDocEditor=p,exports.default=m;
package/dist/index.d.ts CHANGED
@@ -107,9 +107,7 @@ export declare interface SuperDocEditorProps extends Omit<SuperDocConfig, Intern
107
107
  }
108
108
 
109
109
  /** Event passed to onEditorUpdate callback */
110
- export declare interface SuperDocEditorUpdateEvent {
111
- editor: Editor;
112
- }
110
+ export declare type SuperDocEditorUpdateEvent = Parameters<NonNullable<SuperDocConstructorConfig['onEditorUpdate']>>[0];
113
111
 
114
112
  /** Event passed to onException callback */
115
113
  export declare interface SuperDocExceptionEvent {
@@ -135,6 +133,9 @@ export declare interface SuperDocRef {
135
133
  getInstance(): SuperDocInstance | null;
136
134
  }
137
135
 
136
+ /** Event passed to onTransaction callback */
137
+ export declare type SuperDocTransactionEvent = Parameters<NonNullable<SuperDocConstructorConfig['onTransaction']>>[0];
138
+
138
139
  /** User object - extracted from Config.user */
139
140
  export declare type SuperDocUser = NonNullable<SuperDocConstructorConfig['user']>;
140
141
 
package/dist/index.js CHANGED
@@ -1,117 +1,120 @@
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;
1
+ import * as React from "react";
2
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ function useIdPolyfill() {
5
+ let s = React.useRef(null);
6
+ return s.current === null && (s.current = `-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`), s.current;
7
7
  }
8
- const Y = typeof v.useId == "function" ? v.useId : X;
9
- function Z(n, H) {
10
- const [x, w] = F(!1), {
11
- // React-specific
12
- id: B,
13
- renderLoading: $,
14
- hideToolbar: l = !1,
15
- className: T,
16
- style: W,
17
- // Callbacks (stored in ref to avoid triggering rebuilds)
18
- onReady: f,
19
- onEditorCreate: p,
20
- onEditorDestroy: m,
21
- onEditorUpdate: E,
22
- onContentError: y,
23
- onException: D,
24
- // Key props that trigger rebuild when changed
25
- document: S,
26
- user: I,
27
- users: R,
28
- modules: g,
29
- // 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,
36
- onContentError: y,
37
- onException: D
38
- });
39
- N(() => {
40
- t.current = {
41
- onReady: f,
42
- onEditorCreate: p,
43
- onEditorDestroy: m,
44
- onEditorUpdate: E,
45
- onContentError: y,
46
- onException: D
47
- };
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,
54
- () => ({
55
- getInstance: () => i.current
56
- }),
57
- []
58
- ), N(() => {
59
- b(!0), w(!1), u.current = !0;
60
- let r = !1, d = null;
61
- return (async () => {
62
- try {
63
- const J = (await import("superdoc")).SuperDoc;
64
- if (r) return;
65
- const K = {
66
- ...q,
67
- selector: `#${CSS.escape(h)}`,
68
- // 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 } : {},
76
- // 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));
79
- },
80
- onEditorCreate: (e) => {
81
- r || t.current.onEditorCreate?.(e);
82
- },
83
- onEditorDestroy: () => {
84
- r || t.current.onEditorDestroy?.();
85
- },
86
- onEditorUpdate: (e) => {
87
- r || t.current.onEditorUpdate?.(e);
88
- },
89
- onContentError: (e) => {
90
- r || t.current.onContentError?.(e);
91
- },
92
- onException: (e) => {
93
- r || t.current.onException?.(e);
94
- }
95
- };
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 }));
99
- }
100
- })(), () => {
101
- u.current = !1, c.current = null, d && (d.destroy(), i.current = null), r = !0;
102
- };
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
- ] });
8
+ const useStableId = typeof React.useId == "function" ? React.useId : useIdPolyfill;
9
+ function SuperDocEditorInner(e, s) {
10
+ let [l, u] = useState(!1), { id: d, renderLoading: f, hideToolbar: p = !1, className: m, style: h, onReady: g, onEditorCreate: _, onEditorDestroy: v, onEditorUpdate: y, onContentError: b, onException: x, document: S, user: C, users: w, modules: T, ...E } = e, D = e.documentMode ?? "editing", O = e.role ?? "editor", k = useRef(null), A = useRef(null), j = useStableId(), M = d ?? `superdoc${j}`, N = M, P = `${M}-toolbar`, [F, I] = useState(!0), L = useRef({
11
+ onReady: g,
12
+ onEditorCreate: _,
13
+ onEditorDestroy: v,
14
+ onEditorUpdate: y,
15
+ onContentError: b,
16
+ onException: x
17
+ });
18
+ useEffect(() => {
19
+ L.current = {
20
+ onReady: g,
21
+ onEditorCreate: _,
22
+ onEditorDestroy: v,
23
+ onEditorUpdate: y,
24
+ onContentError: b,
25
+ onException: x
26
+ };
27
+ }, [
28
+ g,
29
+ _,
30
+ v,
31
+ y,
32
+ b,
33
+ x
34
+ ]);
35
+ let R = useRef(null), z = useRef(!1), B = useRef(D);
36
+ useEffect(() => {
37
+ B.current !== D && (k.current ? k.current.setDocumentMode(D) : z.current && (R.current = D)), B.current = D;
38
+ }, [D]), useImperativeHandle(s, () => ({ getInstance: () => k.current }), []), useEffect(() => {
39
+ I(!0), u(!1), z.current = !0;
40
+ let e = !1, s = null;
41
+ return (async () => {
42
+ try {
43
+ let c = (await import("superdoc")).SuperDoc;
44
+ if (e) return;
45
+ s = new c({
46
+ ...E,
47
+ selector: `#${CSS.escape(N)}`,
48
+ ...!p && A.current ? { toolbar: `#${CSS.escape(P)}` } : {},
49
+ documentMode: D,
50
+ role: O,
51
+ ...S == null ? {} : { document: S },
52
+ ...C ? { user: C } : {},
53
+ ...w ? { users: w } : {},
54
+ ...T ? { modules: T } : {},
55
+ onReady: (s) => {
56
+ e || (I(!1), z.current = !1, R.current && R.current !== D && (s.superdoc.setDocumentMode(R.current), R.current = null), L.current.onReady?.(s));
57
+ },
58
+ onEditorCreate: (s) => {
59
+ e || L.current.onEditorCreate?.(s);
60
+ },
61
+ onEditorDestroy: () => {
62
+ e || L.current.onEditorDestroy?.();
63
+ },
64
+ onEditorUpdate: (s) => {
65
+ e || L.current.onEditorUpdate?.(s);
66
+ },
67
+ onContentError: (s) => {
68
+ e || L.current.onContentError?.(s);
69
+ },
70
+ onException: (s) => {
71
+ e || L.current.onException?.(s);
72
+ }
73
+ }), k.current = s;
74
+ } catch (s) {
75
+ e || (z.current = !1, I(!1), u(!0), console.error("[SuperDocEditor] Failed to initialize SuperDoc:", s), L.current.onException?.({ error: s }));
76
+ }
77
+ })(), () => {
78
+ z.current = !1, R.current = null, s && (s.destroy(), k.current = null), e = !0;
79
+ };
80
+ }, [
81
+ S,
82
+ C,
83
+ w,
84
+ T,
85
+ O,
86
+ p,
87
+ N,
88
+ P
89
+ ]);
90
+ let V = ["superdoc-wrapper", m].filter(Boolean).join(" "), H = F ? { display: "none" } : void 0;
91
+ return /* @__PURE__ */ jsxs("div", {
92
+ className: V,
93
+ style: h,
94
+ children: [
95
+ !p && /* @__PURE__ */ jsx("div", {
96
+ ref: A,
97
+ id: P,
98
+ className: "superdoc-toolbar-container",
99
+ style: H
100
+ }),
101
+ /* @__PURE__ */ jsx("div", {
102
+ id: N,
103
+ className: "superdoc-editor-container",
104
+ style: H
105
+ }),
106
+ F && !l && f && /* @__PURE__ */ jsx("div", {
107
+ className: "superdoc-loading-container",
108
+ children: f()
109
+ }),
110
+ l && /* @__PURE__ */ jsx("div", {
111
+ className: "superdoc-error-container",
112
+ children: "Failed to load editor. Check console for details."
113
+ })
114
+ ]
115
+ });
111
116
  }
112
- const _ = Q(Z);
113
- _.displayName = "SuperDocEditor";
114
- export {
115
- _ as SuperDocEditor,
116
- _ as default
117
- };
117
+ const SuperDocEditor = forwardRef(SuperDocEditorInner);
118
+ SuperDocEditor.displayName = "SuperDocEditor";
119
+ var SuperDocEditor_default = SuperDocEditor;
120
+ export { SuperDocEditor, SuperDocEditor_default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/react",
3
- "version": "1.0.0-next.6",
3
+ "version": "1.0.0-next.8",
4
4
  "description": "Official React wrapper for the SuperDoc document editor",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",