@superdoc-dev/react 1.2.0-next.34 → 1.2.0-next.36

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}const d=typeof c.useId==`function`?c.useId:u;function f(e){let t=c.useRef(e),n=c.useRef(e);return t.current!==e&&(p(n.current,e)||(n.current=e),t.current=e),n.current}function p(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 m(e,t){let[n,r]=(0,c.useState)(!1),{id:i,renderLoading:a,hideToolbar:o=!1,contained:s=!1,className:u,style:p,onReady:m,onEditorCreate:h,onEditorDestroy:g,onEditorUpdate:_,onContentError:v,onException:y,document:b,user:x,users:S,modules:C,...w}=e,T=e.documentMode??`editing`,E=e.role??`editor`,D=f(x),O=f(S),k=(0,c.useRef)(null),A=(0,c.useRef)(null),j=d(),M=i??`superdoc${j}`,N=M,P=`${M}-toolbar`,[F,I]=(0,c.useState)(!0),L=(0,c.useRef)({onReady:m,onEditorCreate:h,onEditorDestroy:g,onEditorUpdate:_,onContentError:v,onException:y});(0,c.useEffect)(()=>{L.current={onReady:m,onEditorCreate:h,onEditorDestroy:g,onEditorUpdate:_,onContentError:v,onException:y}},[m,h,g,_,v,y]);let R=(0,c.useRef)(null),z=(0,c.useRef)(!1),B=(0,c.useRef)(T);(0,c.useEffect)(()=>{B.current!==T&&(k.current?k.current.setDocumentMode(T):z.current&&(R.current=T)),B.current=T},[T]),(0,c.useImperativeHandle)(t,()=>({getInstance:()=>k.current}),[]),(0,c.useEffect)(()=>{I(!0),r(!1),z.current=!0;let e=!1,t=null;return(async()=>{try{let n=(await import(`superdoc`)).SuperDoc;if(e)return;t=new n({...w,selector:`#${CSS.escape(N)}`,...!o&&A.current?{toolbar:`#${CSS.escape(P)}`}:{},documentMode:T,role:E,contained:s,...b==null?{}:{document:b},...D?{user:D}:{},...O?{users:O}:{},...C?{modules:C}:{},onReady:t=>{e||(I(!1),z.current=!1,R.current&&R.current!==T&&(t.superdoc.setDocumentMode(R.current),R.current=null),L.current.onReady?.(t))},onEditorCreate:t=>{e||L.current.onEditorCreate?.(t)},onEditorDestroy:()=>{e||L.current.onEditorDestroy?.()},onEditorUpdate:t=>{e||L.current.onEditorUpdate?.(t)},onContentError:t=>{e||L.current.onContentError?.(t)},onException:t=>{e||L.current.onException?.(t)}}),k.current=t}catch(t){e||(z.current=!1,I(!1),r(!0),console.error(`[SuperDocEditor] Failed to initialize SuperDoc:`,t),L.current.onException?.({error:t}))}})(),()=>{z.current=!1,R.current=null,t&&(t.destroy(),k.current=null),e=!0}},[b,D,O,C,E,o,s,N,P]);let V=[`superdoc-wrapper`,u].filter(Boolean).join(` `),H=F?{display:`none`}:void 0;return(0,l.jsxs)(`div`,{className:V,style:{...p,...s&&{display:`flex`,flexDirection:`column`}},children:[!o&&(0,l.jsx)(`div`,{ref:A,id:P,className:`superdoc-toolbar-container`,style:H}),(0,l.jsx)(`div`,{id:N,className:`superdoc-editor-container`,style:{...H,...s&&{flex:1,minHeight:0}}}),F&&!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 h=(0,c.forwardRef)(m);h.displayName=`SuperDocEditor`;var g=h;exports.SuperDocEditor=h,exports.default=g;
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){let t=c.useRef(e),n=c.useRef(e);return t.current!==e&&(p(n.current,e)||(n.current=e),t.current=e),n.current}function p(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 m(e,t){let[n,r]=(0,c.useState)(!1),{id:i,renderLoading:a,hideToolbar:o=!1,contained:s=!1,className:u,style:p,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=f(S),k=f(C),A=(0,c.useRef)(null),j=(0,c.useRef)(null),M=d(),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:{...p,...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 h=(0,c.forwardRef)(m);h.displayName=`SuperDocEditor`;var g=h;exports.SuperDocEditor=h,exports.default=g;
package/dist/index.d.ts CHANGED
@@ -18,6 +18,8 @@ export declare interface CallbackProps {
18
18
  onEditorDestroy?: () => void;
19
19
  /** Callback when document content is updated */
20
20
  onEditorUpdate?: (event: SuperDocEditorUpdateEvent) => void;
21
+ /** Callback when a transaction is emitted */
22
+ onTransaction?: (event: SuperDocTransactionEvent) => void;
21
23
  /** Callback when there is a content parsing error */
22
24
  onContentError?: (event: SuperDocContentErrorEvent) => void;
23
25
  /** Callback when an exception is thrown */
@@ -36,7 +38,7 @@ export declare type EditorSurface = 'body' | 'header' | 'footer';
36
38
  * Callback props that are explicitly typed in CallbackProps.
37
39
  * These are excluded from SuperDocConfig to avoid type conflicts.
38
40
  */
39
- declare type ExplicitCallbackProps = 'onReady' | 'onEditorCreate' | 'onEditorDestroy' | 'onEditorUpdate' | 'onContentError' | 'onException';
41
+ declare type ExplicitCallbackProps = 'onReady' | 'onEditorCreate' | 'onEditorDestroy' | 'onEditorUpdate' | 'onTransaction' | 'onContentError' | 'onException';
40
42
 
41
43
  /**
42
44
  * Props managed internally by the React component (not exposed to users).
@@ -152,6 +154,24 @@ export declare interface SuperDocRef {
152
154
  getInstance(): SuperDocInstance | null;
153
155
  }
154
156
 
157
+ /** Event passed to onTransaction callback. Mirrors superdoc's EditorTransactionEvent. */
158
+ export declare interface SuperDocTransactionEvent {
159
+ /** The primary editor associated with the transaction. For header/footer edits, this is the main body editor. */
160
+ editor: Editor;
161
+ /** The editor instance that emitted the transaction. For body edits, this matches `editor`. */
162
+ sourceEditor: Editor;
163
+ /** The ProseMirror transaction or transaction-like payload emitted by the source editor. */
164
+ transaction: any;
165
+ /** Time spent applying the transaction, in milliseconds. */
166
+ duration?: number;
167
+ /** The surface where the transaction originated. */
168
+ surface: EditorSurface;
169
+ /** Relationship ID for header/footer edits. */
170
+ headerId?: string | null;
171
+ /** Header/footer variant (`default`, `first`, `even`, `odd`) when available. */
172
+ sectionType?: string | null;
173
+ }
174
+
155
175
  /** User object - extracted from Config.user */
156
176
  export declare type SuperDocUser = NonNullable<SuperDocConstructorConfig['user']>;
157
177
 
package/dist/index.js CHANGED
@@ -20,22 +20,24 @@ function shallowJsonEqual(e, s) {
20
20
  }
21
21
  }
22
22
  function SuperDocEditorInner(e, s) {
23
- 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, onContentError: S, onException: C, document: w, user: T, users: E, modules: D, ...O } = e, k = e.documentMode ?? "editing", A = e.role ?? "editor", j = useMemoByValue(T), M = useMemoByValue(E), N = useRef(null), P = useRef(null), F = useStableId(), I = f ?? `superdoc${F}`, L = I, R = `${I}-toolbar`, [z, B] = useState(!0), V = useRef({
23
+ 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
24
  onReady: v,
25
25
  onEditorCreate: y,
26
26
  onEditorDestroy: b,
27
27
  onEditorUpdate: x,
28
- onContentError: S,
29
- onException: C
28
+ onTransaction: S,
29
+ onContentError: C,
30
+ onException: w
30
31
  });
31
32
  useEffect(() => {
32
- V.current = {
33
+ H.current = {
33
34
  onReady: v,
34
35
  onEditorCreate: y,
35
36
  onEditorDestroy: b,
36
37
  onEditorUpdate: x,
37
- onContentError: S,
38
- onException: C
38
+ onTransaction: S,
39
+ onContentError: C,
40
+ onException: w
39
41
  };
40
42
  }, [
41
43
  v,
@@ -43,68 +45,72 @@ function SuperDocEditorInner(e, s) {
43
45
  b,
44
46
  x,
45
47
  S,
46
- C
48
+ C,
49
+ w
47
50
  ]);
48
- let H = useRef(null), U = useRef(!1), W = useRef(k);
51
+ let U = useRef(null), W = useRef(!1), G = useRef(A);
49
52
  useEffect(() => {
50
- W.current !== k && (N.current ? N.current.setDocumentMode(k) : U.current && (H.current = k)), W.current = k;
51
- }, [k]), useImperativeHandle(s, () => ({ getInstance: () => N.current }), []), useEffect(() => {
52
- B(!0), d(!1), U.current = !0;
53
+ G.current !== A && (P.current ? P.current.setDocumentMode(A) : W.current && (U.current = A)), G.current = A;
54
+ }, [A]), useImperativeHandle(s, () => ({ getInstance: () => P.current }), []), useEffect(() => {
55
+ V(!0), d(!1), W.current = !0;
53
56
  let e = !1, s = null;
54
57
  return (async () => {
55
58
  try {
56
59
  let c = (await import("superdoc")).SuperDoc;
57
60
  if (e) return;
58
61
  s = new c({
59
- ...O,
60
- selector: `#${CSS.escape(L)}`,
61
- ...!m && P.current ? { toolbar: `#${CSS.escape(R)}` } : {},
62
- documentMode: k,
63
- role: A,
62
+ ...k,
63
+ selector: `#${CSS.escape(R)}`,
64
+ ...!m && F.current ? { toolbar: `#${CSS.escape(z)}` } : {},
65
+ documentMode: A,
66
+ role: j,
64
67
  contained: h,
65
- ...w == null ? {} : { document: w },
66
- ...j ? { user: j } : {},
67
- ...M ? { users: M } : {},
68
- ...D ? { modules: D } : {},
68
+ ...T == null ? {} : { document: T },
69
+ ...M ? { user: M } : {},
70
+ ...N ? { users: N } : {},
71
+ ...O ? { modules: O } : {},
69
72
  onReady: (s) => {
70
- e || (B(!1), U.current = !1, H.current && H.current !== k && (s.superdoc.setDocumentMode(H.current), H.current = null), V.current.onReady?.(s));
73
+ e || (V(!1), W.current = !1, U.current && U.current !== A && (s.superdoc.setDocumentMode(U.current), U.current = null), H.current.onReady?.(s));
71
74
  },
72
75
  onEditorCreate: (s) => {
73
- e || V.current.onEditorCreate?.(s);
76
+ e || H.current.onEditorCreate?.(s);
74
77
  },
75
78
  onEditorDestroy: () => {
76
- e || V.current.onEditorDestroy?.();
79
+ e || H.current.onEditorDestroy?.();
77
80
  },
78
81
  onEditorUpdate: (s) => {
79
- e || V.current.onEditorUpdate?.(s);
82
+ e || H.current.onEditorUpdate?.(s);
83
+ },
84
+ onTransaction: (s) => {
85
+ e || H.current.onTransaction?.(s);
80
86
  },
81
87
  onContentError: (s) => {
82
- e || V.current.onContentError?.(s);
88
+ e || H.current.onContentError?.(s);
83
89
  },
84
90
  onException: (s) => {
85
- e || V.current.onException?.(s);
91
+ e || H.current.onException?.(s);
86
92
  }
87
- }), N.current = s;
93
+ }), P.current = s;
88
94
  } catch (s) {
89
- e || (U.current = !1, B(!1), d(!0), console.error("[SuperDocEditor] Failed to initialize SuperDoc:", s), V.current.onException?.({ error: s }));
95
+ e || (W.current = !1, V(!1), d(!0), console.error("[SuperDocEditor] Failed to initialize SuperDoc:", s), H.current.onException?.({ error: s }));
90
96
  }
91
97
  })(), () => {
92
- U.current = !1, H.current = null, s && (s.destroy(), N.current = null), e = !0;
98
+ W.current = !1, U.current = null, s && (s.destroy(), P.current = null), e = !0;
93
99
  };
94
100
  }, [
95
- w,
96
- j,
101
+ T,
97
102
  M,
98
- D,
99
- A,
103
+ N,
104
+ O,
105
+ j,
100
106
  m,
101
107
  h,
102
- L,
103
- R
108
+ R,
109
+ z
104
110
  ]);
105
- let G = ["superdoc-wrapper", g].filter(Boolean).join(" "), K = z ? { display: "none" } : void 0;
111
+ let K = ["superdoc-wrapper", g].filter(Boolean).join(" "), q = B ? { display: "none" } : void 0;
106
112
  return /* @__PURE__ */ jsxs("div", {
107
- className: G,
113
+ className: K,
108
114
  style: {
109
115
  ..._,
110
116
  ...h && {
@@ -114,23 +120,23 @@ function SuperDocEditorInner(e, s) {
114
120
  },
115
121
  children: [
116
122
  !m && /* @__PURE__ */ jsx("div", {
117
- ref: P,
118
- id: R,
123
+ ref: F,
124
+ id: z,
119
125
  className: "superdoc-toolbar-container",
120
- style: K
126
+ style: q
121
127
  }),
122
128
  /* @__PURE__ */ jsx("div", {
123
- id: L,
129
+ id: R,
124
130
  className: "superdoc-editor-container",
125
131
  style: {
126
- ...K,
132
+ ...q,
127
133
  ...h && {
128
134
  flex: 1,
129
135
  minHeight: 0
130
136
  }
131
137
  }
132
138
  }),
133
- z && !u && p && /* @__PURE__ */ jsx("div", {
139
+ B && !u && p && /* @__PURE__ */ jsx("div", {
134
140
  className: "superdoc-loading-container",
135
141
  children: p()
136
142
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/react",
3
- "version": "1.2.0-next.34",
3
+ "version": "1.2.0-next.36",
4
4
  "description": "Official React wrapper for the SuperDoc document editor",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",