@superdoc-dev/react 1.11.0-next.36 → 1.11.0-next.37

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,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=_;
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,editorVersion:D,editorIntegration:O,...k}=e,A=e.documentMode??`editing`,j=e.role??`editor`,M=p(w),N=p(T),P=(0,c.useRef)(null),F=(0,c.useRef)(null),I=f(),L=i??`superdoc${I}`,R=L,z=`${L}-toolbar`,[B,V]=(0,c.useState)(!0),H=(0,c.useRef)({onReady:m,onEditorCreate:h,onEditorDestroy:g,onEditorUpdate:_,onTransaction:v,onContentError:y,onException:b,onZoomChange:x,onViewportChange:S});(0,c.useEffect)(()=>{H.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 U=(0,c.useRef)(null),W=(0,c.useRef)(!1),G=(0,c.useRef)(A);(0,c.useEffect)(()=>{G.current!==A&&(P.current?P.current.setDocumentMode(A):W.current&&(U.current=A)),G.current=A},[A]),(0,c.useImperativeHandle)(t,()=>({getInstance:()=>P.current}),[]),(0,c.useEffect)(()=>{V(!0),r(!1),W.current=!0;let e=!1,t=null;return(async()=>{try{let n=(await import(`superdoc`)).SuperDoc;if(e)return;t=new n({...k,selector:`#${CSS.escape(R)}`,...!o&&F.current?{toolbar:`#${CSS.escape(z)}`}:{},documentMode:A,role:j,contained:s,...C==null?{}:{document:C},...M?{user:M}:{},...N?{users:N}:{},...E?{modules:E}:{},...D==null?{}:{editorVersion:D},...O==null?{}:{editorIntegration:O},onReady:t=>{e||(V(!1),W.current=!1,U.current&&U.current!==A&&(t.superdoc.setDocumentMode(U.current),U.current=null),H.current.onReady?.(t))},onEditorCreate:t=>{e||H.current.onEditorCreate?.(t)},onEditorDestroy:()=>{e||H.current.onEditorDestroy?.()},onEditorUpdate:t=>{e||H.current.onEditorUpdate?.(t)},onTransaction:t=>{e||H.current.onTransaction?.(t)},onContentError:t=>{e||H.current.onContentError?.(t)},onException:t=>{e||H.current.onException?.(t)},onZoomChange:t=>{e||H.current.onZoomChange?.(t)},onViewportChange:t=>{e||H.current.onViewportChange?.(t)}}),P.current=t}catch(t){e||(W.current=!1,V(!1),r(!0),console.error(`[SuperDocEditor] Failed to initialize SuperDoc:`,t),H.current.onException?.({error:t}))}})(),()=>{W.current=!1,U.current=null,t&&(t.destroy(),P.current=null),e=!0}},[C,M,N,E,j,o,s,D,O,R,z]);let K=[`superdoc-wrapper`,u].filter(Boolean).join(` `),q=B?{display:`none`}:void 0;return(0,l.jsxs)(`div`,{className:K,style:{...d,...s&&{display:`flex`,flexDirection:`column`}},children:[!o&&(0,l.jsx)(`div`,{ref:F,id:z,className:`superdoc-toolbar-container`,style:q}),(0,l.jsx)(`div`,{id:R,className:`superdoc-editor-container`,style:{...q,...s&&{flex:1,minHeight:0}}}),B&&!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
@@ -37,6 +37,16 @@ export declare type DocumentMode = NonNullable<SuperDocConstructorConfig['docume
37
37
 
38
38
  export { Editor }
39
39
 
40
+ /**
41
+ * Explicitly typed editor implementation props.
42
+ */
43
+ declare interface EditorImplementationProps {
44
+ /** Select the DOCX editor implementation. @default 1 */
45
+ editorVersion?: 1 | 2;
46
+ /** Private editor integration object or factory. Required when editorVersion is 2. */
47
+ editorIntegration?: unknown;
48
+ }
49
+
40
50
  /** Surface where an editor event originated. */
41
51
  export declare type EditorSurface = 'body' | 'header' | 'footer';
42
52
 
@@ -119,7 +129,7 @@ export declare interface SuperDocEditorCreateEvent {
119
129
  *
120
130
  * Callback props are explicitly typed to ensure proper TypeScript inference.
121
131
  */
122
- export declare interface SuperDocEditorProps extends Omit<SuperDocConfig, InternalProps | OptionalInReact | ExplicitCallbackProps>, Partial<Pick<SuperDocConfig, OptionalInReact>>, CallbackProps, ReactProps {
132
+ export declare interface SuperDocEditorProps extends Omit<SuperDocConfig, InternalProps | OptionalInReact | ExplicitCallbackProps | keyof EditorImplementationProps>, Partial<Pick<SuperDocConfig, OptionalInReact>>, EditorImplementationProps, CallbackProps, ReactProps {
123
133
  }
124
134
 
125
135
  /** Event passed to onEditorUpdate callback. Mirrors superdoc's EditorUpdateEvent. */
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ 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, 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({
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, editorVersion: j, editorIntegration: M, ...N } = e, P = e.documentMode ?? "editing", F = e.role ?? "editor", I = useMemoByValue(O), L = useMemoByValue(k), R = useRef(null), z = useRef(null), B = useStableId(), V = f ?? `superdoc${B}`, H = V, U = `${V}-toolbar`, [W, G] = useState(!0), K = useRef({
25
25
  onReady: v,
26
26
  onEditorCreate: y,
27
27
  onEditorDestroy: b,
@@ -33,7 +33,7 @@ function SuperDocEditorInner(e, s) {
33
33
  onViewportChange: E
34
34
  });
35
35
  useEffect(() => {
36
- W.current = {
36
+ K.current = {
37
37
  onReady: v,
38
38
  onEditorCreate: y,
39
39
  onEditorDestroy: b,
@@ -55,75 +55,79 @@ function SuperDocEditorInner(e, s) {
55
55
  T,
56
56
  E
57
57
  ]);
58
- let G = useRef(null), K = useRef(!1), q = useRef(M);
58
+ let q = useRef(null), J = useRef(!1), Y = useRef(P);
59
59
  useEffect(() => {
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;
60
+ Y.current !== P && (R.current ? R.current.setDocumentMode(P) : J.current && (q.current = P)), Y.current = P;
61
+ }, [P]), useImperativeHandle(s, () => ({ getInstance: () => R.current }), []), useEffect(() => {
62
+ G(!0), d(!1), J.current = !0;
63
63
  let e = !1, s = null;
64
64
  return (async () => {
65
65
  try {
66
66
  let c = (await import("superdoc")).SuperDoc;
67
67
  if (e) return;
68
68
  s = new c({
69
- ...j,
70
- selector: `#${CSS.escape(B)}`,
71
- ...!m && L.current ? { toolbar: `#${CSS.escape(V)}` } : {},
72
- documentMode: M,
73
- role: N,
69
+ ...N,
70
+ selector: `#${CSS.escape(H)}`,
71
+ ...!m && z.current ? { toolbar: `#${CSS.escape(U)}` } : {},
72
+ documentMode: P,
73
+ role: F,
74
74
  contained: h,
75
75
  ...D == null ? {} : { document: D },
76
- ...P ? { user: P } : {},
77
- ...F ? { users: F } : {},
76
+ ...I ? { user: I } : {},
77
+ ...L ? { users: L } : {},
78
78
  ...A ? { modules: A } : {},
79
+ ...j == null ? {} : { editorVersion: j },
80
+ ...M == null ? {} : { editorIntegration: M },
79
81
  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));
82
+ e || (G(!1), J.current = !1, q.current && q.current !== P && (s.superdoc.setDocumentMode(q.current), q.current = null), K.current.onReady?.(s));
81
83
  },
82
84
  onEditorCreate: (s) => {
83
- e || W.current.onEditorCreate?.(s);
85
+ e || K.current.onEditorCreate?.(s);
84
86
  },
85
87
  onEditorDestroy: () => {
86
- e || W.current.onEditorDestroy?.();
88
+ e || K.current.onEditorDestroy?.();
87
89
  },
88
90
  onEditorUpdate: (s) => {
89
- e || W.current.onEditorUpdate?.(s);
91
+ e || K.current.onEditorUpdate?.(s);
90
92
  },
91
93
  onTransaction: (s) => {
92
- e || W.current.onTransaction?.(s);
94
+ e || K.current.onTransaction?.(s);
93
95
  },
94
96
  onContentError: (s) => {
95
- e || W.current.onContentError?.(s);
97
+ e || K.current.onContentError?.(s);
96
98
  },
97
99
  onException: (s) => {
98
- e || W.current.onException?.(s);
100
+ e || K.current.onException?.(s);
99
101
  },
100
102
  onZoomChange: (s) => {
101
- e || W.current.onZoomChange?.(s);
103
+ e || K.current.onZoomChange?.(s);
102
104
  },
103
105
  onViewportChange: (s) => {
104
- e || W.current.onViewportChange?.(s);
106
+ e || K.current.onViewportChange?.(s);
105
107
  }
106
- }), I.current = s;
108
+ }), R.current = s;
107
109
  } catch (s) {
108
- e || (K.current = !1, U(!1), d(!0), console.error("[SuperDocEditor] Failed to initialize SuperDoc:", s), W.current.onException?.({ error: s }));
110
+ e || (J.current = !1, G(!1), d(!0), console.error("[SuperDocEditor] Failed to initialize SuperDoc:", s), K.current.onException?.({ error: s }));
109
111
  }
110
112
  })(), () => {
111
- K.current = !1, G.current = null, s && (s.destroy(), I.current = null), e = !0;
113
+ J.current = !1, q.current = null, s && (s.destroy(), R.current = null), e = !0;
112
114
  };
113
115
  }, [
114
116
  D,
115
- P,
116
- F,
117
+ I,
118
+ L,
117
119
  A,
118
- N,
120
+ F,
119
121
  m,
120
122
  h,
121
- B,
122
- V
123
+ j,
124
+ M,
125
+ H,
126
+ U
123
127
  ]);
124
- let J = ["superdoc-wrapper", g].filter(Boolean).join(" "), Y = H ? { display: "none" } : void 0;
128
+ let X = ["superdoc-wrapper", g].filter(Boolean).join(" "), Z = W ? { display: "none" } : void 0;
125
129
  return /* @__PURE__ */ jsxs("div", {
126
- className: J,
130
+ className: X,
127
131
  style: {
128
132
  ..._,
129
133
  ...h && {
@@ -133,23 +137,23 @@ function SuperDocEditorInner(e, s) {
133
137
  },
134
138
  children: [
135
139
  !m && /* @__PURE__ */ jsx("div", {
136
- ref: L,
137
- id: V,
140
+ ref: z,
141
+ id: U,
138
142
  className: "superdoc-toolbar-container",
139
- style: Y
143
+ style: Z
140
144
  }),
141
145
  /* @__PURE__ */ jsx("div", {
142
- id: B,
146
+ id: H,
143
147
  className: "superdoc-editor-container",
144
148
  style: {
145
- ...Y,
149
+ ...Z,
146
150
  ...h && {
147
151
  flex: 1,
148
152
  minHeight: 0
149
153
  }
150
154
  }
151
155
  }),
152
- H && !u && p && /* @__PURE__ */ jsx("div", {
156
+ W && !u && p && /* @__PURE__ */ jsx("div", {
153
157
  className: "superdoc-loading-container",
154
158
  children: p()
155
159
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/react",
3
- "version": "1.11.0-next.36",
3
+ "version": "1.11.0-next.37",
4
4
  "description": "Official React wrapper for the SuperDoc document editor",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",