@superdoc-dev/react 1.10.0 → 1.11.0-next.10

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
- 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}var d=c.useId;const f=typeof d==`function`?d:u;function p(e){let t=c.useRef(e),n=c.useRef(e);return t.current!==e&&(m(n.current,e)||(n.current=e),t.current=e),n.current}function m(e,t){if(e===t)return!0;if(e==null||t==null)return e===t;try{return JSON.stringify(e)===JSON.stringify(t)}catch{return!1}}function h(e,t){let[n,r]=(0,c.useState)(!1),{id:i,renderLoading:a,hideToolbar:o=!1,contained:s=!1,className:u,style:d,onReady:m,onEditorCreate:h,onEditorDestroy:g,onEditorUpdate:_,onTransaction:v,onContentError:y,onException:b,document:x,user:S,users:C,modules:w,...T}=e,E=e.documentMode??`editing`,D=e.role??`editor`,O=p(S),k=p(C),A=(0,c.useRef)(null),j=(0,c.useRef)(null),M=f(),N=i??`superdoc${M}`,P=N,F=`${N}-toolbar`,[I,L]=(0,c.useState)(!0),R=(0,c.useRef)({onReady:m,onEditorCreate:h,onEditorDestroy:g,onEditorUpdate:_,onTransaction:v,onContentError:y,onException:b});(0,c.useEffect)(()=>{R.current={onReady:m,onEditorCreate:h,onEditorDestroy:g,onEditorUpdate:_,onTransaction:v,onContentError:y,onException:b}},[m,h,g,_,v,y,b]);let z=(0,c.useRef)(null),B=(0,c.useRef)(!1),V=(0,c.useRef)(E);(0,c.useEffect)(()=>{V.current!==E&&(A.current?A.current.setDocumentMode(E):B.current&&(z.current=E)),V.current=E},[E]),(0,c.useImperativeHandle)(t,()=>({getInstance:()=>A.current}),[]),(0,c.useEffect)(()=>{L(!0),r(!1),B.current=!0;let e=!1,t=null;return(async()=>{try{let n=(await import(`superdoc`)).SuperDoc;if(e)return;t=new n({...T,selector:`#${CSS.escape(P)}`,...!o&&j.current?{toolbar:`#${CSS.escape(F)}`}:{},documentMode:E,role:D,contained:s,...x==null?{}:{document:x},...O?{user:O}:{},...k?{users:k}:{},...w?{modules:w}:{},onReady:t=>{e||(L(!1),B.current=!1,z.current&&z.current!==E&&(t.superdoc.setDocumentMode(z.current),z.current=null),R.current.onReady?.(t))},onEditorCreate:t=>{e||R.current.onEditorCreate?.(t)},onEditorDestroy:()=>{e||R.current.onEditorDestroy?.()},onEditorUpdate:t=>{e||R.current.onEditorUpdate?.(t)},onTransaction:t=>{e||R.current.onTransaction?.(t)},onContentError:t=>{e||R.current.onContentError?.(t)},onException:t=>{e||R.current.onException?.(t)}}),A.current=t}catch(t){e||(B.current=!1,L(!1),r(!0),console.error(`[SuperDocEditor] Failed to initialize SuperDoc:`,t),R.current.onException?.({error:t}))}})(),()=>{B.current=!1,z.current=null,t&&(t.destroy(),A.current=null),e=!0}},[x,O,k,w,D,o,s,P,F]);let H=[`superdoc-wrapper`,u].filter(Boolean).join(` `),U=I?{display:`none`}:void 0;return(0,l.jsxs)(`div`,{className:H,style:{...d,...s&&{display:`flex`,flexDirection:`column`}},children:[!o&&(0,l.jsx)(`div`,{ref:j,id:F,className:`superdoc-toolbar-container`,style:U}),(0,l.jsx)(`div`,{id:P,className:`superdoc-editor-container`,style:{...U,...s&&{flex:1,minHeight:0}}}),I&&!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 g=(0,c.forwardRef)(h);g.displayName=`SuperDocEditor`;var _=g;exports.SuperDocEditor=g,exports.default=_;
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}var d=c.useId;const f=typeof d==`function`?d:u;function p(e){let t=c.useRef(e),n=c.useRef(e);return t.current!==e&&(m(n.current,e)||(n.current=e),t.current=e),n.current}function m(e,t){if(e===t)return!0;if(e==null||t==null)return e===t;try{return JSON.stringify(e)===JSON.stringify(t)}catch{return!1}}function h(e,t){let[n,r]=(0,c.useState)(!1),{id:i,renderLoading:a,hideToolbar:o=!1,contained:s=!1,className:u,style:d,onReady:m,onEditorCreate:h,onEditorDestroy:g,onEditorUpdate:_,onTransaction:v,onContentError:y,onException:b,onZoomChange:x,onViewportChange:S,document:C,user:w,users:T,modules:E,...D}=e,O=e.documentMode??`editing`,k=e.role??`editor`,A=p(w),j=p(T),M=(0,c.useRef)(null),N=(0,c.useRef)(null),P=f(),F=i??`superdoc${P}`,I=F,L=`${F}-toolbar`,[R,z]=(0,c.useState)(!0),B=(0,c.useRef)({onReady:m,onEditorCreate:h,onEditorDestroy:g,onEditorUpdate:_,onTransaction:v,onContentError:y,onException:b,onZoomChange:x,onViewportChange:S});(0,c.useEffect)(()=>{B.current={onReady:m,onEditorCreate:h,onEditorDestroy:g,onEditorUpdate:_,onTransaction:v,onContentError:y,onException:b,onZoomChange:x,onViewportChange:S}},[m,h,g,_,v,y,b,x,S]);let V=(0,c.useRef)(null),H=(0,c.useRef)(!1),U=(0,c.useRef)(O);(0,c.useEffect)(()=>{U.current!==O&&(M.current?M.current.setDocumentMode(O):H.current&&(V.current=O)),U.current=O},[O]),(0,c.useImperativeHandle)(t,()=>({getInstance:()=>M.current}),[]),(0,c.useEffect)(()=>{z(!0),r(!1),H.current=!0;let e=!1,t=null;return(async()=>{try{let n=(await import(`superdoc`)).SuperDoc;if(e)return;t=new n({...D,selector:`#${CSS.escape(I)}`,...!o&&N.current?{toolbar:`#${CSS.escape(L)}`}:{},documentMode:O,role:k,contained:s,...C==null?{}:{document:C},...A?{user:A}:{},...j?{users:j}:{},...E?{modules:E}:{},onReady:t=>{e||(z(!1),H.current=!1,V.current&&V.current!==O&&(t.superdoc.setDocumentMode(V.current),V.current=null),B.current.onReady?.(t))},onEditorCreate:t=>{e||B.current.onEditorCreate?.(t)},onEditorDestroy:()=>{e||B.current.onEditorDestroy?.()},onEditorUpdate:t=>{e||B.current.onEditorUpdate?.(t)},onTransaction:t=>{e||B.current.onTransaction?.(t)},onContentError:t=>{e||B.current.onContentError?.(t)},onException:t=>{e||B.current.onException?.(t)},onZoomChange:t=>{e||B.current.onZoomChange?.(t)},onViewportChange:t=>{e||B.current.onViewportChange?.(t)}}),M.current=t}catch(t){e||(H.current=!1,z(!1),r(!0),console.error(`[SuperDocEditor] Failed to initialize SuperDoc:`,t),B.current.onException?.({error:t}))}})(),()=>{H.current=!1,V.current=null,t&&(t.destroy(),M.current=null),e=!0}},[C,A,j,E,k,o,s,I,L]);let W=[`superdoc-wrapper`,u].filter(Boolean).join(` `),G=R?{display:`none`}:void 0;return(0,l.jsxs)(`div`,{className:W,style:{...d,...s&&{display:`flex`,flexDirection:`column`}},children:[!o&&(0,l.jsx)(`div`,{ref:N,id:L,className:`superdoc-toolbar-container`,style:G}),(0,l.jsx)(`div`,{id:I,className:`superdoc-editor-container`,style:{...G,...s&&{flex:1,minHeight:0}}}),R&&!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 g=(0,c.forwardRef)(h);g.displayName=`SuperDocEditor`;var _=g;exports.SuperDocEditor=g,exports.default=_;
package/dist/index.d.ts CHANGED
@@ -26,6 +26,10 @@ export declare interface CallbackProps {
26
26
  onContentError?: (event: SuperDocContentErrorEvent) => void;
27
27
  /** Callback when an exception is thrown */
28
28
  onException?: (event: SuperDocExceptionEvent) => void;
29
+ /** Callback when the zoom level changes (setZoom, toolbar, or fit-width mode) */
30
+ onZoomChange?: (event: SuperDocZoomChangeEvent) => void;
31
+ /** Callback when the implied fit changes (rounded fit zoom or base page width); see the core viewport-change event */
32
+ onViewportChange?: (event: SuperDocViewportChangeEvent) => void;
29
33
  }
30
34
 
31
35
  /** Document mode - extracted from Config.documentMode */
@@ -40,7 +44,7 @@ export declare type EditorSurface = 'body' | 'header' | 'footer';
40
44
  * Callback props that are explicitly typed in CallbackProps.
41
45
  * These are excluded from SuperDocConfig to avoid type conflicts.
42
46
  */
43
- declare type ExplicitCallbackProps = 'onReady' | 'onEditorCreate' | 'onEditorDestroy' | 'onEditorUpdate' | 'onTransaction' | 'onContentError' | 'onException';
47
+ declare type ExplicitCallbackProps = 'onReady' | 'onEditorCreate' | 'onEditorDestroy' | 'onEditorUpdate' | 'onTransaction' | 'onContentError' | 'onException' | 'onZoomChange' | 'onViewportChange';
44
48
 
45
49
  /**
46
50
  * Props managed internally by the React component (not exposed to users).
@@ -181,6 +185,20 @@ export declare interface SuperDocTransactionEvent {
181
185
  /** User object - extracted from Config.user */
182
186
  export declare type SuperDocUser = NonNullable<SuperDocConstructorConfig['user']>;
183
187
 
188
+ /**
189
+ * Event passed to onViewportChange callback. Re-derived from the core
190
+ * `Config.onViewportChange` parameter so the React wrapper cannot
191
+ * drift from the core contract.
192
+ */
193
+ export declare type SuperDocViewportChangeEvent = Parameters<NonNullable<SuperDocConfig['onViewportChange']>>[0];
194
+
195
+ /**
196
+ * Event passed to onZoomChange callback. Re-derived from the core
197
+ * `Config.onZoomChange` parameter so the React wrapper cannot drift
198
+ * from the core contract.
199
+ */
200
+ export declare type SuperDocZoomChangeEvent = Parameters<NonNullable<SuperDocConfig['onZoomChange']>>[0];
201
+
184
202
  /** User role - extracted from Config.role */
185
203
  export declare type UserRole = NonNullable<SuperDocConstructorConfig['role']>;
186
204
 
package/dist/index.js CHANGED
@@ -21,24 +21,28 @@ function shallowJsonEqual(e, s) {
21
21
  }
22
22
  }
23
23
  function SuperDocEditorInner(e, s) {
24
- let [u, d] = useState(!1), { id: f, renderLoading: p, hideToolbar: m = !1, contained: h = !1, className: g, style: _, onReady: v, onEditorCreate: y, onEditorDestroy: b, onEditorUpdate: x, onTransaction: S, onContentError: C, onException: w, document: T, user: E, users: D, modules: O, ...k } = e, A = e.documentMode ?? "editing", j = e.role ?? "editor", M = useMemoByValue(E), N = useMemoByValue(D), P = useRef(null), F = useRef(null), I = useStableId(), L = f ?? `superdoc${I}`, R = L, z = `${L}-toolbar`, [B, V] = useState(!0), H = useRef({
24
+ let [u, d] = useState(!1), { id: f, renderLoading: p, hideToolbar: m = !1, contained: h = !1, className: g, style: _, onReady: v, onEditorCreate: y, onEditorDestroy: b, onEditorUpdate: x, onTransaction: S, onContentError: C, onException: w, onZoomChange: T, onViewportChange: E, document: D, user: O, users: k, modules: A, ...j } = e, M = e.documentMode ?? "editing", N = e.role ?? "editor", P = useMemoByValue(O), F = useMemoByValue(k), I = useRef(null), L = useRef(null), R = useStableId(), z = f ?? `superdoc${R}`, B = z, V = `${z}-toolbar`, [H, U] = useState(!0), W = useRef({
25
25
  onReady: v,
26
26
  onEditorCreate: y,
27
27
  onEditorDestroy: b,
28
28
  onEditorUpdate: x,
29
29
  onTransaction: S,
30
30
  onContentError: C,
31
- onException: w
31
+ onException: w,
32
+ onZoomChange: T,
33
+ onViewportChange: E
32
34
  });
33
35
  useEffect(() => {
34
- H.current = {
36
+ W.current = {
35
37
  onReady: v,
36
38
  onEditorCreate: y,
37
39
  onEditorDestroy: b,
38
40
  onEditorUpdate: x,
39
41
  onTransaction: S,
40
42
  onContentError: C,
41
- onException: w
43
+ onException: w,
44
+ onZoomChange: T,
45
+ onViewportChange: E
42
46
  };
43
47
  }, [
44
48
  v,
@@ -47,71 +51,79 @@ function SuperDocEditorInner(e, s) {
47
51
  x,
48
52
  S,
49
53
  C,
50
- w
54
+ w,
55
+ T,
56
+ E
51
57
  ]);
52
- let U = useRef(null), W = useRef(!1), G = useRef(A);
58
+ let G = useRef(null), K = useRef(!1), q = useRef(M);
53
59
  useEffect(() => {
54
- G.current !== A && (P.current ? P.current.setDocumentMode(A) : W.current && (U.current = A)), G.current = A;
55
- }, [A]), useImperativeHandle(s, () => ({ getInstance: () => P.current }), []), useEffect(() => {
56
- V(!0), d(!1), W.current = !0;
60
+ q.current !== M && (I.current ? I.current.setDocumentMode(M) : K.current && (G.current = M)), q.current = M;
61
+ }, [M]), useImperativeHandle(s, () => ({ getInstance: () => I.current }), []), useEffect(() => {
62
+ U(!0), d(!1), K.current = !0;
57
63
  let e = !1, s = null;
58
64
  return (async () => {
59
65
  try {
60
66
  let c = (await import("superdoc")).SuperDoc;
61
67
  if (e) return;
62
68
  s = new c({
63
- ...k,
64
- selector: `#${CSS.escape(R)}`,
65
- ...!m && F.current ? { toolbar: `#${CSS.escape(z)}` } : {},
66
- documentMode: A,
67
- role: j,
69
+ ...j,
70
+ selector: `#${CSS.escape(B)}`,
71
+ ...!m && L.current ? { toolbar: `#${CSS.escape(V)}` } : {},
72
+ documentMode: M,
73
+ role: N,
68
74
  contained: h,
69
- ...T == null ? {} : { document: T },
70
- ...M ? { user: M } : {},
71
- ...N ? { users: N } : {},
72
- ...O ? { modules: O } : {},
75
+ ...D == null ? {} : { document: D },
76
+ ...P ? { user: P } : {},
77
+ ...F ? { users: F } : {},
78
+ ...A ? { modules: A } : {},
73
79
  onReady: (s) => {
74
- e || (V(!1), W.current = !1, U.current && U.current !== A && (s.superdoc.setDocumentMode(U.current), U.current = null), H.current.onReady?.(s));
80
+ e || (U(!1), K.current = !1, G.current && G.current !== M && (s.superdoc.setDocumentMode(G.current), G.current = null), W.current.onReady?.(s));
75
81
  },
76
82
  onEditorCreate: (s) => {
77
- e || H.current.onEditorCreate?.(s);
83
+ e || W.current.onEditorCreate?.(s);
78
84
  },
79
85
  onEditorDestroy: () => {
80
- e || H.current.onEditorDestroy?.();
86
+ e || W.current.onEditorDestroy?.();
81
87
  },
82
88
  onEditorUpdate: (s) => {
83
- e || H.current.onEditorUpdate?.(s);
89
+ e || W.current.onEditorUpdate?.(s);
84
90
  },
85
91
  onTransaction: (s) => {
86
- e || H.current.onTransaction?.(s);
92
+ e || W.current.onTransaction?.(s);
87
93
  },
88
94
  onContentError: (s) => {
89
- e || H.current.onContentError?.(s);
95
+ e || W.current.onContentError?.(s);
90
96
  },
91
97
  onException: (s) => {
92
- e || H.current.onException?.(s);
98
+ e || W.current.onException?.(s);
99
+ },
100
+ onZoomChange: (s) => {
101
+ e || W.current.onZoomChange?.(s);
102
+ },
103
+ onViewportChange: (s) => {
104
+ e || W.current.onViewportChange?.(s);
93
105
  }
94
- }), P.current = s;
106
+ }), I.current = s;
95
107
  } catch (s) {
96
- e || (W.current = !1, V(!1), d(!0), console.error("[SuperDocEditor] Failed to initialize SuperDoc:", s), H.current.onException?.({ error: s }));
108
+ e || (K.current = !1, U(!1), d(!0), console.error("[SuperDocEditor] Failed to initialize SuperDoc:", s), W.current.onException?.({ error: s }));
97
109
  }
98
110
  })(), () => {
99
- W.current = !1, U.current = null, s && (s.destroy(), P.current = null), e = !0;
111
+ K.current = !1, G.current = null, s && (s.destroy(), I.current = null), e = !0;
100
112
  };
101
113
  }, [
102
- T,
103
- M,
114
+ D,
115
+ P,
116
+ F,
117
+ A,
104
118
  N,
105
- O,
106
- j,
107
119
  m,
108
120
  h,
109
- R,
110
- z
121
+ B,
122
+ V
111
123
  ]);
112
- let K = ["superdoc-wrapper", g].filter(Boolean).join(" "), q = B ? { display: "none" } : void 0;
124
+ let J = ["superdoc-wrapper", g].filter(Boolean).join(" "), Y = H ? { display: "none" } : void 0;
113
125
  return /* @__PURE__ */ jsxs("div", {
114
- className: K,
126
+ className: J,
115
127
  style: {
116
128
  ..._,
117
129
  ...h && {
@@ -121,23 +133,23 @@ function SuperDocEditorInner(e, s) {
121
133
  },
122
134
  children: [
123
135
  !m && /* @__PURE__ */ jsx("div", {
124
- ref: F,
125
- id: z,
136
+ ref: L,
137
+ id: V,
126
138
  className: "superdoc-toolbar-container",
127
- style: q
139
+ style: Y
128
140
  }),
129
141
  /* @__PURE__ */ jsx("div", {
130
- id: R,
142
+ id: B,
131
143
  className: "superdoc-editor-container",
132
144
  style: {
133
- ...q,
145
+ ...Y,
134
146
  ...h && {
135
147
  flex: 1,
136
148
  minHeight: 0
137
149
  }
138
150
  }
139
151
  }),
140
- B && !u && p && /* @__PURE__ */ jsx("div", {
152
+ H && !u && p && /* @__PURE__ */ jsx("div", {
141
153
  className: "superdoc-loading-container",
142
154
  children: p()
143
155
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/react",
3
- "version": "1.10.0",
3
+ "version": "1.11.0-next.10",
4
4
  "description": "Official React wrapper for the SuperDoc document editor",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",