@superdoc-dev/react 1.0.0-test.1 → 1.1.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 +28 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.js +132 -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,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
|
|
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
|
|
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, 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
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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 };
|