@superdoc-dev/react 1.2.0-next.3 → 1.2.0-next.30

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