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