@superdoc-dev/react 1.10.0-next.9 → 1.11.0-next.1
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 +19 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +54 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,6 +49,25 @@ function App() {
|
|
|
49
49
|
}
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
## File prop component
|
|
53
|
+
|
|
54
|
+
When an agent needs to create a React wrapper around a DOCX `File`, use this shape:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { SuperDocEditor } from '@superdoc-dev/react';
|
|
58
|
+
import '@superdoc-dev/react/style.css';
|
|
59
|
+
|
|
60
|
+
export function ContractEditor({ file }: { file: File }) {
|
|
61
|
+
return (
|
|
62
|
+
<SuperDocEditor
|
|
63
|
+
document={file}
|
|
64
|
+
documentMode="editing"
|
|
65
|
+
onReady={({ superdoc }) => console.log('Ready', superdoc)}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
52
71
|
## Changing Mode
|
|
53
72
|
|
|
54
73
|
Just update the `documentMode` prop - the component handles it efficiently (no rebuild):
|
|
@@ -209,4 +228,3 @@ Types are extracted from the `superdoc` package, ensuring they stay in sync.
|
|
|
209
228
|
## License
|
|
210
229
|
|
|
211
230
|
AGPL-3.0
|
|
212
|
-
|
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,
|
|
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,
|
|
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
|
-
|
|
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
|
|
58
|
+
let G = useRef(null), K = useRef(!1), q = useRef(M);
|
|
53
59
|
useEffect(() => {
|
|
54
|
-
|
|
55
|
-
}, [
|
|
56
|
-
|
|
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
|
-
...
|
|
64
|
-
selector: `#${CSS.escape(
|
|
65
|
-
...!m &&
|
|
66
|
-
documentMode:
|
|
67
|
-
role:
|
|
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
|
-
...
|
|
70
|
-
...
|
|
71
|
-
...
|
|
72
|
-
...
|
|
75
|
+
...D == null ? {} : { document: D },
|
|
76
|
+
...P ? { user: P } : {},
|
|
77
|
+
...F ? { users: F } : {},
|
|
78
|
+
...A ? { modules: A } : {},
|
|
73
79
|
onReady: (s) => {
|
|
74
|
-
e || (
|
|
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 ||
|
|
83
|
+
e || W.current.onEditorCreate?.(s);
|
|
78
84
|
},
|
|
79
85
|
onEditorDestroy: () => {
|
|
80
|
-
e ||
|
|
86
|
+
e || W.current.onEditorDestroy?.();
|
|
81
87
|
},
|
|
82
88
|
onEditorUpdate: (s) => {
|
|
83
|
-
e ||
|
|
89
|
+
e || W.current.onEditorUpdate?.(s);
|
|
84
90
|
},
|
|
85
91
|
onTransaction: (s) => {
|
|
86
|
-
e ||
|
|
92
|
+
e || W.current.onTransaction?.(s);
|
|
87
93
|
},
|
|
88
94
|
onContentError: (s) => {
|
|
89
|
-
e ||
|
|
95
|
+
e || W.current.onContentError?.(s);
|
|
90
96
|
},
|
|
91
97
|
onException: (s) => {
|
|
92
|
-
e ||
|
|
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
|
-
}),
|
|
106
|
+
}), I.current = s;
|
|
95
107
|
} catch (s) {
|
|
96
|
-
e || (
|
|
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
|
-
|
|
111
|
+
K.current = !1, G.current = null, s && (s.destroy(), I.current = null), e = !0;
|
|
100
112
|
};
|
|
101
113
|
}, [
|
|
102
|
-
|
|
103
|
-
|
|
114
|
+
D,
|
|
115
|
+
P,
|
|
116
|
+
F,
|
|
117
|
+
A,
|
|
104
118
|
N,
|
|
105
|
-
O,
|
|
106
|
-
j,
|
|
107
119
|
m,
|
|
108
120
|
h,
|
|
109
|
-
|
|
110
|
-
|
|
121
|
+
B,
|
|
122
|
+
V
|
|
111
123
|
]);
|
|
112
|
-
let
|
|
124
|
+
let J = ["superdoc-wrapper", g].filter(Boolean).join(" "), Y = H ? { display: "none" } : void 0;
|
|
113
125
|
return /* @__PURE__ */ jsxs("div", {
|
|
114
|
-
className:
|
|
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:
|
|
125
|
-
id:
|
|
136
|
+
ref: L,
|
|
137
|
+
id: V,
|
|
126
138
|
className: "superdoc-toolbar-container",
|
|
127
|
-
style:
|
|
139
|
+
style: Y
|
|
128
140
|
}),
|
|
129
141
|
/* @__PURE__ */ jsx("div", {
|
|
130
|
-
id:
|
|
142
|
+
id: B,
|
|
131
143
|
className: "superdoc-editor-container",
|
|
132
144
|
style: {
|
|
133
|
-
...
|
|
145
|
+
...Y,
|
|
134
146
|
...h && {
|
|
135
147
|
flex: 1,
|
|
136
148
|
minHeight: 0
|
|
137
149
|
}
|
|
138
150
|
}
|
|
139
151
|
}),
|
|
140
|
-
|
|
152
|
+
H && !u && p && /* @__PURE__ */ jsx("div", {
|
|
141
153
|
className: "superdoc-loading-container",
|
|
142
154
|
children: p()
|
|
143
155
|
}),
|