@superdoc-dev/react 1.11.1 → 1.13.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/dist/index.cjs +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +42 -38
- package/package.json +1 -1
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,...
|
|
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,
|
|
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
|
-
|
|
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
|
|
58
|
+
let q = useRef(null), J = useRef(!1), Y = useRef(P);
|
|
59
59
|
useEffect(() => {
|
|
60
|
-
|
|
61
|
-
}, [
|
|
62
|
-
|
|
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
|
-
...
|
|
70
|
-
selector: `#${CSS.escape(
|
|
71
|
-
...!m &&
|
|
72
|
-
documentMode:
|
|
73
|
-
role:
|
|
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
|
-
...
|
|
77
|
-
...
|
|
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 || (
|
|
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 ||
|
|
85
|
+
e || K.current.onEditorCreate?.(s);
|
|
84
86
|
},
|
|
85
87
|
onEditorDestroy: () => {
|
|
86
|
-
e ||
|
|
88
|
+
e || K.current.onEditorDestroy?.();
|
|
87
89
|
},
|
|
88
90
|
onEditorUpdate: (s) => {
|
|
89
|
-
e ||
|
|
91
|
+
e || K.current.onEditorUpdate?.(s);
|
|
90
92
|
},
|
|
91
93
|
onTransaction: (s) => {
|
|
92
|
-
e ||
|
|
94
|
+
e || K.current.onTransaction?.(s);
|
|
93
95
|
},
|
|
94
96
|
onContentError: (s) => {
|
|
95
|
-
e ||
|
|
97
|
+
e || K.current.onContentError?.(s);
|
|
96
98
|
},
|
|
97
99
|
onException: (s) => {
|
|
98
|
-
e ||
|
|
100
|
+
e || K.current.onException?.(s);
|
|
99
101
|
},
|
|
100
102
|
onZoomChange: (s) => {
|
|
101
|
-
e ||
|
|
103
|
+
e || K.current.onZoomChange?.(s);
|
|
102
104
|
},
|
|
103
105
|
onViewportChange: (s) => {
|
|
104
|
-
e ||
|
|
106
|
+
e || K.current.onViewportChange?.(s);
|
|
105
107
|
}
|
|
106
|
-
}),
|
|
108
|
+
}), R.current = s;
|
|
107
109
|
} catch (s) {
|
|
108
|
-
e || (
|
|
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
|
-
|
|
113
|
+
J.current = !1, q.current = null, s && (s.destroy(), R.current = null), e = !0;
|
|
112
114
|
};
|
|
113
115
|
}, [
|
|
114
116
|
D,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
I,
|
|
118
|
+
L,
|
|
117
119
|
A,
|
|
118
|
-
|
|
120
|
+
F,
|
|
119
121
|
m,
|
|
120
122
|
h,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
j,
|
|
124
|
+
M,
|
|
125
|
+
H,
|
|
126
|
+
U
|
|
123
127
|
]);
|
|
124
|
-
let
|
|
128
|
+
let X = ["superdoc-wrapper", g].filter(Boolean).join(" "), Z = W ? { display: "none" } : void 0;
|
|
125
129
|
return /* @__PURE__ */ jsxs("div", {
|
|
126
|
-
className:
|
|
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:
|
|
137
|
-
id:
|
|
140
|
+
ref: z,
|
|
141
|
+
id: U,
|
|
138
142
|
className: "superdoc-toolbar-container",
|
|
139
|
-
style:
|
|
143
|
+
style: Z
|
|
140
144
|
}),
|
|
141
145
|
/* @__PURE__ */ jsx("div", {
|
|
142
|
-
id:
|
|
146
|
+
id: H,
|
|
143
147
|
className: "superdoc-editor-container",
|
|
144
148
|
style: {
|
|
145
|
-
...
|
|
149
|
+
...Z,
|
|
146
150
|
...h && {
|
|
147
151
|
flex: 1,
|
|
148
152
|
minHeight: 0
|
|
149
153
|
}
|
|
150
154
|
}
|
|
151
155
|
}),
|
|
152
|
-
|
|
156
|
+
W && !u && p && /* @__PURE__ */ jsx("div", {
|
|
153
157
|
className: "superdoc-loading-container",
|
|
154
158
|
children: p()
|
|
155
159
|
}),
|