@superdoc-dev/react 1.0.0-test.1 → 1.0.0

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,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;
package/dist/index.d.ts CHANGED
@@ -57,6 +57,9 @@ declare interface ReactProps {
57
57
  renderLoading?: () => ReactNode;
58
58
  /** Hide the toolbar container. When true, no toolbar is rendered. @default false */
59
59
  hideToolbar?: boolean;
60
+ /** Enable contained mode for fixed-height container embedding. When true, SuperDoc
61
+ * fits within its parent's height and scrolls internally. @default false */
62
+ contained?: boolean;
60
63
  /** Additional CSS class name for the wrapper element */
61
64
  className?: string;
62
65
  /** Additional inline styles for the wrapper element */
@@ -107,13 +110,13 @@ export declare interface SuperDocEditorProps extends Omit<SuperDocConfig, Intern
107
110
  }
108
111
 
109
112
  /** Event passed to onEditorUpdate callback */
110
- export declare interface SuperDocEditorUpdateEvent {
111
- editor: Editor;
112
- }
113
+ export declare type SuperDocEditorUpdateEvent = Parameters<NonNullable<SuperDocConstructorConfig['onEditorUpdate']>>[0];
113
114
 
114
115
  /** Event passed to onException callback */
115
116
  export declare interface SuperDocExceptionEvent {
116
117
  error: Error;
118
+ editor?: Editor | null;
119
+ code?: string;
117
120
  }
118
121
 
119
122
  /** SuperDoc instance type - from superdoc package */
@@ -135,6 +138,9 @@ export declare interface SuperDocRef {
135
138
  getInstance(): SuperDocInstance | null;
136
139
  }
137
140
 
141
+ /** Event passed to onTransaction callback */
142
+ export declare type SuperDocTransactionEvent = Parameters<NonNullable<SuperDocConstructorConfig['onTransaction']>>[0];
143
+
138
144
  /** User object - extracted from Config.user */
139
145
  export declare type SuperDocUser = NonNullable<SuperDocConstructorConfig['user']>;
140
146
 
package/dist/index.js CHANGED
@@ -1,117 +1,134 @@
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, 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
17
+ });
18
+ useEffect(() => {
19
+ R.current = {
20
+ onReady: _,
21
+ onEditorCreate: v,
22
+ onEditorDestroy: y,
23
+ onEditorUpdate: b,
24
+ onContentError: x,
25
+ onException: S
26
+ };
27
+ }, [
28
+ _,
29
+ v,
30
+ y,
31
+ b,
32
+ x,
33
+ S
34
+ ]);
35
+ let z = useRef(null), B = useRef(!1), V = useRef(O);
36
+ 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;
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
+ ...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 } : {},
56
+ 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));
58
+ },
59
+ onEditorCreate: (s) => {
60
+ e || R.current.onEditorCreate?.(s);
61
+ },
62
+ onEditorDestroy: () => {
63
+ e || R.current.onEditorDestroy?.();
64
+ },
65
+ onEditorUpdate: (s) => {
66
+ e || R.current.onEditorUpdate?.(s);
67
+ },
68
+ onContentError: (s) => {
69
+ e || R.current.onContentError?.(s);
70
+ },
71
+ onException: (s) => {
72
+ e || R.current.onException?.(s);
73
+ }
74
+ }), A.current = s;
75
+ } catch (s) {
76
+ e || (B.current = !1, L(!1), u(!0), console.error("[SuperDocEditor] Failed to initialize SuperDoc:", s), R.current.onException?.({ error: s }));
77
+ }
78
+ })(), () => {
79
+ B.current = !1, z.current = null, s && (s.destroy(), A.current = null), e = !0;
80
+ };
81
+ }, [
82
+ C,
83
+ w,
84
+ T,
85
+ E,
86
+ k,
87
+ p,
88
+ m,
89
+ P,
90
+ F
91
+ ]);
92
+ let H = ["superdoc-wrapper", h].filter(Boolean).join(" "), U = I ? { display: "none" } : void 0;
93
+ return /* @__PURE__ */ jsxs("div", {
94
+ className: H,
95
+ style: {
96
+ ...g,
97
+ ...m && {
98
+ display: "flex",
99
+ flexDirection: "column"
100
+ }
101
+ },
102
+ children: [
103
+ !p && /* @__PURE__ */ jsx("div", {
104
+ ref: j,
105
+ id: F,
106
+ className: "superdoc-toolbar-container",
107
+ style: U
108
+ }),
109
+ /* @__PURE__ */ jsx("div", {
110
+ id: P,
111
+ className: "superdoc-editor-container",
112
+ style: {
113
+ ...U,
114
+ ...m && {
115
+ flex: 1,
116
+ minHeight: 0
117
+ }
118
+ }
119
+ }),
120
+ I && !l && f && /* @__PURE__ */ jsx("div", {
121
+ className: "superdoc-loading-container",
122
+ children: f()
123
+ }),
124
+ l && /* @__PURE__ */ jsx("div", {
125
+ className: "superdoc-error-container",
126
+ children: "Failed to load editor. Check console for details."
127
+ })
128
+ ]
129
+ });
111
130
  }
112
- const _ = Q(Z);
113
- _.displayName = "SuperDocEditor";
114
- export {
115
- _ as SuperDocEditor,
116
- _ as default
117
- };
131
+ const SuperDocEditor = forwardRef(SuperDocEditorInner);
132
+ SuperDocEditor.displayName = "SuperDocEditor";
133
+ var SuperDocEditor_default = SuperDocEditor;
134
+ 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-test.1",
3
+ "version": "1.0.0",
4
4
  "description": "Official React wrapper for the SuperDoc document editor",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",