@superdoc-dev/react 1.0.0-next.6 → 1.0.0-next.7
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 +28 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +118 -115
- package/package.json +1 -1
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
|
-
|
|
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,className:s,style:u,onReady:f,onEditorCreate:p,onEditorDestroy:m,onEditorUpdate:h,onContentError:g,onException:_,document:v,user:y,users:b,modules:x,...S}=e,C=e.documentMode??`editing`,w=e.role??`editor`,T=(0,c.useRef)(null),E=(0,c.useRef)(null),D=d(),O=i??`superdoc${D}`,k=O,A=`${O}-toolbar`,[j,M]=(0,c.useState)(!0),N=(0,c.useRef)({onReady:f,onEditorCreate:p,onEditorDestroy:m,onEditorUpdate:h,onContentError:g,onException:_});(0,c.useEffect)(()=>{N.current={onReady:f,onEditorCreate:p,onEditorDestroy:m,onEditorUpdate:h,onContentError:g,onException:_}},[f,p,m,h,g,_]);let P=(0,c.useRef)(null),F=(0,c.useRef)(!1),I=(0,c.useRef)(C);(0,c.useEffect)(()=>{I.current!==C&&(T.current?T.current.setDocumentMode(C):F.current&&(P.current=C)),I.current=C},[C]),(0,c.useImperativeHandle)(t,()=>({getInstance:()=>T.current}),[]),(0,c.useEffect)(()=>{M(!0),r(!1),F.current=!0;let e=!1,t=null;return(async()=>{try{let n=(await import(`superdoc`)).SuperDoc;if(e)return;t=new n({...S,selector:`#${CSS.escape(k)}`,...!o&&E.current?{toolbar:`#${CSS.escape(A)}`}:{},documentMode:C,role:w,...v==null?{}:{document:v},...y?{user:y}:{},...b?{users:b}:{},...x?{modules:x}:{},onReady:t=>{e||(M(!1),F.current=!1,P.current&&P.current!==C&&(t.superdoc.setDocumentMode(P.current),P.current=null),N.current.onReady?.(t))},onEditorCreate:t=>{e||N.current.onEditorCreate?.(t)},onEditorDestroy:()=>{e||N.current.onEditorDestroy?.()},onEditorUpdate:t=>{e||N.current.onEditorUpdate?.(t)},onContentError:t=>{e||N.current.onContentError?.(t)},onException:t=>{e||N.current.onException?.(t)}}),T.current=t}catch(t){e||(F.current=!1,M(!1),r(!0),console.error(`[SuperDocEditor] Failed to initialize SuperDoc:`,t),N.current.onException?.({error:t}))}})(),()=>{F.current=!1,P.current=null,t&&(t.destroy(),T.current=null),e=!0}},[v,y,b,x,w,o,k,A]);let L=[`superdoc-wrapper`,s].filter(Boolean).join(` `),R=j?{display:`none`}:void 0;return(0,l.jsxs)(`div`,{className:L,style:u,children:[!o&&(0,l.jsx)(`div`,{ref:E,id:A,className:`superdoc-toolbar-container`,style:R}),(0,l.jsx)(`div`,{id:k,className:`superdoc-editor-container`,style:R}),j&&!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
|
@@ -107,9 +107,7 @@ export declare interface SuperDocEditorProps extends Omit<SuperDocConfig, Intern
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
/** Event passed to onEditorUpdate callback */
|
|
110
|
-
export declare
|
|
111
|
-
editor: Editor;
|
|
112
|
-
}
|
|
110
|
+
export declare type SuperDocEditorUpdateEvent = Parameters<NonNullable<SuperDocConstructorConfig['onEditorUpdate']>>[0];
|
|
113
111
|
|
|
114
112
|
/** Event passed to onException callback */
|
|
115
113
|
export declare interface SuperDocExceptionEvent {
|
|
@@ -135,6 +133,9 @@ export declare interface SuperDocRef {
|
|
|
135
133
|
getInstance(): SuperDocInstance | null;
|
|
136
134
|
}
|
|
137
135
|
|
|
136
|
+
/** Event passed to onTransaction callback */
|
|
137
|
+
export declare type SuperDocTransactionEvent = Parameters<NonNullable<SuperDocConstructorConfig['onTransaction']>>[0];
|
|
138
|
+
|
|
138
139
|
/** User object - extracted from Config.user */
|
|
139
140
|
export declare type SuperDocUser = NonNullable<SuperDocConstructorConfig['user']>;
|
|
140
141
|
|
package/dist/index.js
CHANGED
|
@@ -1,117 +1,120 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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, className: m, style: h, onReady: g, onEditorCreate: _, onEditorDestroy: v, onEditorUpdate: y, onContentError: b, onException: x, document: S, user: C, users: w, modules: T, ...E } = e, D = e.documentMode ?? "editing", O = e.role ?? "editor", k = useRef(null), A = useRef(null), j = useStableId(), M = d ?? `superdoc${j}`, N = M, P = `${M}-toolbar`, [F, I] = useState(!0), L = useRef({
|
|
11
|
+
onReady: g,
|
|
12
|
+
onEditorCreate: _,
|
|
13
|
+
onEditorDestroy: v,
|
|
14
|
+
onEditorUpdate: y,
|
|
15
|
+
onContentError: b,
|
|
16
|
+
onException: x
|
|
17
|
+
});
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
L.current = {
|
|
20
|
+
onReady: g,
|
|
21
|
+
onEditorCreate: _,
|
|
22
|
+
onEditorDestroy: v,
|
|
23
|
+
onEditorUpdate: y,
|
|
24
|
+
onContentError: b,
|
|
25
|
+
onException: x
|
|
26
|
+
};
|
|
27
|
+
}, [
|
|
28
|
+
g,
|
|
29
|
+
_,
|
|
30
|
+
v,
|
|
31
|
+
y,
|
|
32
|
+
b,
|
|
33
|
+
x
|
|
34
|
+
]);
|
|
35
|
+
let R = useRef(null), z = useRef(!1), B = useRef(D);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
B.current !== D && (k.current ? k.current.setDocumentMode(D) : z.current && (R.current = D)), B.current = D;
|
|
38
|
+
}, [D]), useImperativeHandle(s, () => ({ getInstance: () => k.current }), []), useEffect(() => {
|
|
39
|
+
I(!0), u(!1), z.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
|
+
...E,
|
|
47
|
+
selector: `#${CSS.escape(N)}`,
|
|
48
|
+
...!p && A.current ? { toolbar: `#${CSS.escape(P)}` } : {},
|
|
49
|
+
documentMode: D,
|
|
50
|
+
role: O,
|
|
51
|
+
...S == null ? {} : { document: S },
|
|
52
|
+
...C ? { user: C } : {},
|
|
53
|
+
...w ? { users: w } : {},
|
|
54
|
+
...T ? { modules: T } : {},
|
|
55
|
+
onReady: (s) => {
|
|
56
|
+
e || (I(!1), z.current = !1, R.current && R.current !== D && (s.superdoc.setDocumentMode(R.current), R.current = null), L.current.onReady?.(s));
|
|
57
|
+
},
|
|
58
|
+
onEditorCreate: (s) => {
|
|
59
|
+
e || L.current.onEditorCreate?.(s);
|
|
60
|
+
},
|
|
61
|
+
onEditorDestroy: () => {
|
|
62
|
+
e || L.current.onEditorDestroy?.();
|
|
63
|
+
},
|
|
64
|
+
onEditorUpdate: (s) => {
|
|
65
|
+
e || L.current.onEditorUpdate?.(s);
|
|
66
|
+
},
|
|
67
|
+
onContentError: (s) => {
|
|
68
|
+
e || L.current.onContentError?.(s);
|
|
69
|
+
},
|
|
70
|
+
onException: (s) => {
|
|
71
|
+
e || L.current.onException?.(s);
|
|
72
|
+
}
|
|
73
|
+
}), k.current = s;
|
|
74
|
+
} catch (s) {
|
|
75
|
+
e || (z.current = !1, I(!1), u(!0), console.error("[SuperDocEditor] Failed to initialize SuperDoc:", s), L.current.onException?.({ error: s }));
|
|
76
|
+
}
|
|
77
|
+
})(), () => {
|
|
78
|
+
z.current = !1, R.current = null, s && (s.destroy(), k.current = null), e = !0;
|
|
79
|
+
};
|
|
80
|
+
}, [
|
|
81
|
+
S,
|
|
82
|
+
C,
|
|
83
|
+
w,
|
|
84
|
+
T,
|
|
85
|
+
O,
|
|
86
|
+
p,
|
|
87
|
+
N,
|
|
88
|
+
P
|
|
89
|
+
]);
|
|
90
|
+
let V = ["superdoc-wrapper", m].filter(Boolean).join(" "), H = F ? { display: "none" } : void 0;
|
|
91
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
92
|
+
className: V,
|
|
93
|
+
style: h,
|
|
94
|
+
children: [
|
|
95
|
+
!p && /* @__PURE__ */ jsx("div", {
|
|
96
|
+
ref: A,
|
|
97
|
+
id: P,
|
|
98
|
+
className: "superdoc-toolbar-container",
|
|
99
|
+
style: H
|
|
100
|
+
}),
|
|
101
|
+
/* @__PURE__ */ jsx("div", {
|
|
102
|
+
id: N,
|
|
103
|
+
className: "superdoc-editor-container",
|
|
104
|
+
style: H
|
|
105
|
+
}),
|
|
106
|
+
F && !l && f && /* @__PURE__ */ jsx("div", {
|
|
107
|
+
className: "superdoc-loading-container",
|
|
108
|
+
children: f()
|
|
109
|
+
}),
|
|
110
|
+
l && /* @__PURE__ */ jsx("div", {
|
|
111
|
+
className: "superdoc-error-container",
|
|
112
|
+
children: "Failed to load editor. Check console for details."
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
});
|
|
111
116
|
}
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
_ as default
|
|
117
|
-
};
|
|
117
|
+
const SuperDocEditor = forwardRef(SuperDocEditorInner);
|
|
118
|
+
SuperDocEditor.displayName = "SuperDocEditor";
|
|
119
|
+
var SuperDocEditor_default = SuperDocEditor;
|
|
120
|
+
export { SuperDocEditor, SuperDocEditor_default as default };
|