@superdoc-dev/react 1.2.0-next.15 → 1.2.0-next.151
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 +37 -5
- package/dist/index.js +81 -61
- package/package.json +4 -2
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}
|
|
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,document:x,user:S,users:C,modules:w,...T}=e,E=e.documentMode??`editing`,D=e.role??`editor`,O=p(S),k=p(C),A=(0,c.useRef)(null),j=(0,c.useRef)(null),M=f(),N=i??`superdoc${M}`,P=N,F=`${N}-toolbar`,[I,L]=(0,c.useState)(!0),R=(0,c.useRef)({onReady:m,onEditorCreate:h,onEditorDestroy:g,onEditorUpdate:_,onTransaction:v,onContentError:y,onException:b});(0,c.useEffect)(()=>{R.current={onReady:m,onEditorCreate:h,onEditorDestroy:g,onEditorUpdate:_,onTransaction:v,onContentError:y,onException:b}},[m,h,g,_,v,y,b]);let z=(0,c.useRef)(null),B=(0,c.useRef)(!1),V=(0,c.useRef)(E);(0,c.useEffect)(()=>{V.current!==E&&(A.current?A.current.setDocumentMode(E):B.current&&(z.current=E)),V.current=E},[E]),(0,c.useImperativeHandle)(t,()=>({getInstance:()=>A.current}),[]),(0,c.useEffect)(()=>{L(!0),r(!1),B.current=!0;let e=!1,t=null;return(async()=>{try{let n=(await import(`superdoc`)).SuperDoc;if(e)return;t=new n({...T,selector:`#${CSS.escape(P)}`,...!o&&j.current?{toolbar:`#${CSS.escape(F)}`}:{},documentMode:E,role:D,contained:s,...x==null?{}:{document:x},...O?{user:O}:{},...k?{users:k}:{},...w?{modules:w}:{},onReady:t=>{e||(L(!1),B.current=!1,z.current&&z.current!==E&&(t.superdoc.setDocumentMode(z.current),z.current=null),R.current.onReady?.(t))},onEditorCreate:t=>{e||R.current.onEditorCreate?.(t)},onEditorDestroy:()=>{e||R.current.onEditorDestroy?.()},onEditorUpdate:t=>{e||R.current.onEditorUpdate?.(t)},onTransaction:t=>{e||R.current.onTransaction?.(t)},onContentError:t=>{e||R.current.onContentError?.(t)},onException:t=>{e||R.current.onException?.(t)}}),A.current=t}catch(t){e||(B.current=!1,L(!1),r(!0),console.error(`[SuperDocEditor] Failed to initialize SuperDoc:`,t),R.current.onException?.({error:t}))}})(),()=>{B.current=!1,z.current=null,t&&(t.destroy(),A.current=null),e=!0}},[x,O,k,w,D,o,s,P,F]);let H=[`superdoc-wrapper`,u].filter(Boolean).join(` `),U=I?{display:`none`}:void 0;return(0,l.jsxs)(`div`,{className:H,style:{...d,...s&&{display:`flex`,flexDirection:`column`}},children:[!o&&(0,l.jsx)(`div`,{ref:j,id:F,className:`superdoc-toolbar-container`,style:U}),(0,l.jsx)(`div`,{id:P,className:`superdoc-editor-container`,style:{...U,...s&&{flex:1,minHeight:0}}}),I&&!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
|
@@ -4,6 +4,7 @@ import { ForwardRefExoticComponent } from 'react';
|
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
import { RefAttributes } from 'react';
|
|
6
6
|
import { SuperDoc } from 'superdoc';
|
|
7
|
+
import { Transaction } from 'superdoc';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Explicitly typed callback props to ensure proper TypeScript inference.
|
|
@@ -18,6 +19,8 @@ export declare interface CallbackProps {
|
|
|
18
19
|
onEditorDestroy?: () => void;
|
|
19
20
|
/** Callback when document content is updated */
|
|
20
21
|
onEditorUpdate?: (event: SuperDocEditorUpdateEvent) => void;
|
|
22
|
+
/** Callback when a transaction is emitted */
|
|
23
|
+
onTransaction?: (event: SuperDocTransactionEvent) => void;
|
|
21
24
|
/** Callback when there is a content parsing error */
|
|
22
25
|
onContentError?: (event: SuperDocContentErrorEvent) => void;
|
|
23
26
|
/** Callback when an exception is thrown */
|
|
@@ -29,11 +32,14 @@ export declare type DocumentMode = NonNullable<SuperDocConstructorConfig['docume
|
|
|
29
32
|
|
|
30
33
|
export { Editor }
|
|
31
34
|
|
|
35
|
+
/** Surface where an editor event originated. */
|
|
36
|
+
export declare type EditorSurface = 'body' | 'header' | 'footer';
|
|
37
|
+
|
|
32
38
|
/**
|
|
33
39
|
* Callback props that are explicitly typed in CallbackProps.
|
|
34
40
|
* These are excluded from SuperDocConfig to avoid type conflicts.
|
|
35
41
|
*/
|
|
36
|
-
declare type ExplicitCallbackProps = 'onReady' | 'onEditorCreate' | 'onEditorDestroy' | 'onEditorUpdate' | 'onContentError' | 'onException';
|
|
42
|
+
declare type ExplicitCallbackProps = 'onReady' | 'onEditorCreate' | 'onEditorDestroy' | 'onEditorUpdate' | 'onTransaction' | 'onContentError' | 'onException';
|
|
37
43
|
|
|
38
44
|
/**
|
|
39
45
|
* Props managed internally by the React component (not exposed to users).
|
|
@@ -109,8 +115,19 @@ export declare interface SuperDocEditorCreateEvent {
|
|
|
109
115
|
export declare interface SuperDocEditorProps extends Omit<SuperDocConfig, InternalProps | OptionalInReact | ExplicitCallbackProps>, Partial<Pick<SuperDocConfig, OptionalInReact>>, CallbackProps, ReactProps {
|
|
110
116
|
}
|
|
111
117
|
|
|
112
|
-
/** Event passed to onEditorUpdate callback */
|
|
113
|
-
export declare
|
|
118
|
+
/** Event passed to onEditorUpdate callback. Mirrors superdoc's EditorUpdateEvent. */
|
|
119
|
+
export declare interface SuperDocEditorUpdateEvent {
|
|
120
|
+
/** The primary editor associated with the update. For header/footer edits, this is the main body editor. */
|
|
121
|
+
editor: Editor;
|
|
122
|
+
/** The editor instance that emitted the update. For body edits, this matches `editor`. */
|
|
123
|
+
sourceEditor: Editor;
|
|
124
|
+
/** The surface where the edit originated. */
|
|
125
|
+
surface: EditorSurface;
|
|
126
|
+
/** Relationship ID for header/footer edits. */
|
|
127
|
+
headerId?: string | null;
|
|
128
|
+
/** Header/footer variant (`default`, `first`, `even`, `odd`) when available. */
|
|
129
|
+
sectionType?: string | null;
|
|
130
|
+
}
|
|
114
131
|
|
|
115
132
|
/** Event passed to onException callback */
|
|
116
133
|
export declare interface SuperDocExceptionEvent {
|
|
@@ -138,8 +155,23 @@ export declare interface SuperDocRef {
|
|
|
138
155
|
getInstance(): SuperDocInstance | null;
|
|
139
156
|
}
|
|
140
157
|
|
|
141
|
-
/** Event passed to onTransaction callback */
|
|
142
|
-
export declare
|
|
158
|
+
/** Event passed to onTransaction callback. Mirrors superdoc's EditorTransactionEvent. */
|
|
159
|
+
export declare interface SuperDocTransactionEvent {
|
|
160
|
+
/** The primary editor associated with the transaction. For header/footer edits, this is the main body editor. */
|
|
161
|
+
editor: Editor;
|
|
162
|
+
/** The editor instance that emitted the transaction. For body edits, this matches `editor`. */
|
|
163
|
+
sourceEditor: Editor;
|
|
164
|
+
/** The ProseMirror transaction emitted by the source editor. */
|
|
165
|
+
transaction: Transaction;
|
|
166
|
+
/** Time spent applying the transaction, in milliseconds. */
|
|
167
|
+
duration?: number;
|
|
168
|
+
/** The surface where the transaction originated. */
|
|
169
|
+
surface: EditorSurface;
|
|
170
|
+
/** Relationship ID for header/footer edits. */
|
|
171
|
+
headerId?: string | null;
|
|
172
|
+
/** Header/footer variant (`default`, `first`, `even`, `odd`) when available. */
|
|
173
|
+
sectionType?: string | null;
|
|
174
|
+
}
|
|
143
175
|
|
|
144
176
|
/** User object - extracted from Config.user */
|
|
145
177
|
export declare type SuperDocUser = NonNullable<SuperDocConstructorConfig['user']>;
|
package/dist/index.js
CHANGED
|
@@ -5,123 +5,143 @@ function useIdPolyfill() {
|
|
|
5
5
|
let s = React.useRef(null);
|
|
6
6
|
return s.current === null && (s.current = `-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`), s.current;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
var reactUseId = React.useId;
|
|
9
|
+
const useStableId = typeof reactUseId == "function" ? reactUseId : useIdPolyfill;
|
|
10
|
+
function useMemoByValue(s) {
|
|
11
|
+
let c = React.useRef(s), l = React.useRef(s);
|
|
12
|
+
return c.current !== s && (shallowJsonEqual(l.current, s) || (l.current = s), c.current = s), l.current;
|
|
13
|
+
}
|
|
14
|
+
function shallowJsonEqual(e, s) {
|
|
15
|
+
if (e === s) return !0;
|
|
16
|
+
if (e == null || s == null) return e === s;
|
|
17
|
+
try {
|
|
18
|
+
return JSON.stringify(e) === JSON.stringify(s);
|
|
19
|
+
} catch {
|
|
20
|
+
return !1;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
9
23
|
function SuperDocEditorInner(e, s) {
|
|
10
|
-
let [
|
|
11
|
-
onReady:
|
|
12
|
-
onEditorCreate:
|
|
13
|
-
onEditorDestroy:
|
|
14
|
-
onEditorUpdate:
|
|
15
|
-
|
|
16
|
-
|
|
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, document: T, user: E, users: D, modules: O, ...k } = e, A = e.documentMode ?? "editing", j = e.role ?? "editor", M = useMemoByValue(E), N = useMemoByValue(D), P = useRef(null), F = useRef(null), I = useStableId(), L = f ?? `superdoc${I}`, R = L, z = `${L}-toolbar`, [B, V] = useState(!0), H = useRef({
|
|
25
|
+
onReady: v,
|
|
26
|
+
onEditorCreate: y,
|
|
27
|
+
onEditorDestroy: b,
|
|
28
|
+
onEditorUpdate: x,
|
|
29
|
+
onTransaction: S,
|
|
30
|
+
onContentError: C,
|
|
31
|
+
onException: w
|
|
17
32
|
});
|
|
18
33
|
useEffect(() => {
|
|
19
|
-
|
|
20
|
-
onReady:
|
|
21
|
-
onEditorCreate:
|
|
22
|
-
onEditorDestroy:
|
|
23
|
-
onEditorUpdate:
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
H.current = {
|
|
35
|
+
onReady: v,
|
|
36
|
+
onEditorCreate: y,
|
|
37
|
+
onEditorDestroy: b,
|
|
38
|
+
onEditorUpdate: x,
|
|
39
|
+
onTransaction: S,
|
|
40
|
+
onContentError: C,
|
|
41
|
+
onException: w
|
|
26
42
|
};
|
|
27
43
|
}, [
|
|
28
|
-
_,
|
|
29
44
|
v,
|
|
30
45
|
y,
|
|
31
46
|
b,
|
|
32
47
|
x,
|
|
33
|
-
S
|
|
48
|
+
S,
|
|
49
|
+
C,
|
|
50
|
+
w
|
|
34
51
|
]);
|
|
35
|
-
let
|
|
52
|
+
let U = useRef(null), W = useRef(!1), G = useRef(A);
|
|
36
53
|
useEffect(() => {
|
|
37
|
-
|
|
38
|
-
}, [
|
|
39
|
-
|
|
54
|
+
G.current !== A && (P.current ? P.current.setDocumentMode(A) : W.current && (U.current = A)), G.current = A;
|
|
55
|
+
}, [A]), useImperativeHandle(s, () => ({ getInstance: () => P.current }), []), useEffect(() => {
|
|
56
|
+
V(!0), d(!1), W.current = !0;
|
|
40
57
|
let e = !1, s = null;
|
|
41
58
|
return (async () => {
|
|
42
59
|
try {
|
|
43
60
|
let c = (await import("superdoc")).SuperDoc;
|
|
44
61
|
if (e) return;
|
|
45
62
|
s = new c({
|
|
46
|
-
...
|
|
47
|
-
selector: `#${CSS.escape(
|
|
48
|
-
...!
|
|
49
|
-
documentMode:
|
|
50
|
-
role:
|
|
51
|
-
contained:
|
|
52
|
-
...
|
|
53
|
-
...
|
|
54
|
-
...
|
|
55
|
-
...
|
|
63
|
+
...k,
|
|
64
|
+
selector: `#${CSS.escape(R)}`,
|
|
65
|
+
...!m && F.current ? { toolbar: `#${CSS.escape(z)}` } : {},
|
|
66
|
+
documentMode: A,
|
|
67
|
+
role: j,
|
|
68
|
+
contained: h,
|
|
69
|
+
...T == null ? {} : { document: T },
|
|
70
|
+
...M ? { user: M } : {},
|
|
71
|
+
...N ? { users: N } : {},
|
|
72
|
+
...O ? { modules: O } : {},
|
|
56
73
|
onReady: (s) => {
|
|
57
|
-
e || (
|
|
74
|
+
e || (V(!1), W.current = !1, U.current && U.current !== A && (s.superdoc.setDocumentMode(U.current), U.current = null), H.current.onReady?.(s));
|
|
58
75
|
},
|
|
59
76
|
onEditorCreate: (s) => {
|
|
60
|
-
e ||
|
|
77
|
+
e || H.current.onEditorCreate?.(s);
|
|
61
78
|
},
|
|
62
79
|
onEditorDestroy: () => {
|
|
63
|
-
e ||
|
|
80
|
+
e || H.current.onEditorDestroy?.();
|
|
64
81
|
},
|
|
65
82
|
onEditorUpdate: (s) => {
|
|
66
|
-
e ||
|
|
83
|
+
e || H.current.onEditorUpdate?.(s);
|
|
84
|
+
},
|
|
85
|
+
onTransaction: (s) => {
|
|
86
|
+
e || H.current.onTransaction?.(s);
|
|
67
87
|
},
|
|
68
88
|
onContentError: (s) => {
|
|
69
|
-
e ||
|
|
89
|
+
e || H.current.onContentError?.(s);
|
|
70
90
|
},
|
|
71
91
|
onException: (s) => {
|
|
72
|
-
e ||
|
|
92
|
+
e || H.current.onException?.(s);
|
|
73
93
|
}
|
|
74
|
-
}),
|
|
94
|
+
}), P.current = s;
|
|
75
95
|
} catch (s) {
|
|
76
|
-
e || (
|
|
96
|
+
e || (W.current = !1, V(!1), d(!0), console.error("[SuperDocEditor] Failed to initialize SuperDoc:", s), H.current.onException?.({ error: s }));
|
|
77
97
|
}
|
|
78
98
|
})(), () => {
|
|
79
|
-
|
|
99
|
+
W.current = !1, U.current = null, s && (s.destroy(), P.current = null), e = !0;
|
|
80
100
|
};
|
|
81
101
|
}, [
|
|
82
|
-
C,
|
|
83
|
-
w,
|
|
84
102
|
T,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
103
|
+
M,
|
|
104
|
+
N,
|
|
105
|
+
O,
|
|
106
|
+
j,
|
|
88
107
|
m,
|
|
89
|
-
|
|
90
|
-
|
|
108
|
+
h,
|
|
109
|
+
R,
|
|
110
|
+
z
|
|
91
111
|
]);
|
|
92
|
-
let
|
|
112
|
+
let K = ["superdoc-wrapper", g].filter(Boolean).join(" "), q = B ? { display: "none" } : void 0;
|
|
93
113
|
return /* @__PURE__ */ jsxs("div", {
|
|
94
|
-
className:
|
|
114
|
+
className: K,
|
|
95
115
|
style: {
|
|
96
|
-
...
|
|
97
|
-
...
|
|
116
|
+
..._,
|
|
117
|
+
...h && {
|
|
98
118
|
display: "flex",
|
|
99
119
|
flexDirection: "column"
|
|
100
120
|
}
|
|
101
121
|
},
|
|
102
122
|
children: [
|
|
103
|
-
!
|
|
104
|
-
ref:
|
|
105
|
-
id:
|
|
123
|
+
!m && /* @__PURE__ */ jsx("div", {
|
|
124
|
+
ref: F,
|
|
125
|
+
id: z,
|
|
106
126
|
className: "superdoc-toolbar-container",
|
|
107
|
-
style:
|
|
127
|
+
style: q
|
|
108
128
|
}),
|
|
109
129
|
/* @__PURE__ */ jsx("div", {
|
|
110
|
-
id:
|
|
130
|
+
id: R,
|
|
111
131
|
className: "superdoc-editor-container",
|
|
112
132
|
style: {
|
|
113
|
-
...
|
|
114
|
-
...
|
|
133
|
+
...q,
|
|
134
|
+
...h && {
|
|
115
135
|
flex: 1,
|
|
116
136
|
minHeight: 0
|
|
117
137
|
}
|
|
118
138
|
}
|
|
119
139
|
}),
|
|
120
|
-
|
|
140
|
+
B && !u && p && /* @__PURE__ */ jsx("div", {
|
|
121
141
|
className: "superdoc-loading-container",
|
|
122
|
-
children:
|
|
142
|
+
children: p()
|
|
123
143
|
}),
|
|
124
|
-
|
|
144
|
+
u && /* @__PURE__ */ jsx("div", {
|
|
125
145
|
className: "superdoc-error-container",
|
|
126
146
|
children: "Failed to load editor. Check console for details."
|
|
127
147
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdoc-dev/react",
|
|
3
|
-
"version": "1.2.0-next.
|
|
3
|
+
"version": "1.2.0-next.151",
|
|
4
4
|
"description": "Official React wrapper for the SuperDoc document editor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": ">=16.8.0",
|
|
34
|
-
"react-dom": ">=16.8.0"
|
|
34
|
+
"react-dom": ">=16.8.0",
|
|
35
|
+
"superdoc": ">=1.0.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@testing-library/react": "^16.3.0",
|
|
@@ -71,6 +72,7 @@
|
|
|
71
72
|
"build": "vite build",
|
|
72
73
|
"dev": "vite build --watch",
|
|
73
74
|
"test": "vitest run",
|
|
75
|
+
"pretype-check": "node ../../apps/cli/scripts/ensure-superdoc-build.js --types",
|
|
74
76
|
"type-check": "tsc --noEmit",
|
|
75
77
|
"lint": "eslint src --ext .ts,.tsx"
|
|
76
78
|
}
|