@superdoc-dev/react 1.2.0-next.35 → 1.2.0-next.37
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 +21 -1
- package/dist/index.js +49 -43
- 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){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:_,
|
|
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 */
|
|
@@ -36,7 +38,7 @@ export declare type EditorSurface = 'body' | 'header' | 'footer';
|
|
|
36
38
|
* Callback props that are explicitly typed in CallbackProps.
|
|
37
39
|
* These are excluded from SuperDocConfig to avoid type conflicts.
|
|
38
40
|
*/
|
|
39
|
-
declare type ExplicitCallbackProps = 'onReady' | 'onEditorCreate' | 'onEditorDestroy' | 'onEditorUpdate' | 'onContentError' | 'onException';
|
|
41
|
+
declare type ExplicitCallbackProps = 'onReady' | 'onEditorCreate' | 'onEditorDestroy' | 'onEditorUpdate' | 'onTransaction' | 'onContentError' | 'onException';
|
|
40
42
|
|
|
41
43
|
/**
|
|
42
44
|
* Props managed internally by the React component (not exposed to users).
|
|
@@ -152,6 +154,24 @@ export declare interface SuperDocRef {
|
|
|
152
154
|
getInstance(): SuperDocInstance | null;
|
|
153
155
|
}
|
|
154
156
|
|
|
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
|
+
}
|
|
174
|
+
|
|
155
175
|
/** User object - extracted from Config.user */
|
|
156
176
|
export declare type SuperDocUser = NonNullable<SuperDocConstructorConfig['user']>;
|
|
157
177
|
|
package/dist/index.js
CHANGED
|
@@ -20,22 +20,24 @@ function shallowJsonEqual(e, s) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
function SuperDocEditorInner(e, s) {
|
|
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,
|
|
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
24
|
onReady: v,
|
|
25
25
|
onEditorCreate: y,
|
|
26
26
|
onEditorDestroy: b,
|
|
27
27
|
onEditorUpdate: x,
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
onTransaction: S,
|
|
29
|
+
onContentError: C,
|
|
30
|
+
onException: w
|
|
30
31
|
});
|
|
31
32
|
useEffect(() => {
|
|
32
|
-
|
|
33
|
+
H.current = {
|
|
33
34
|
onReady: v,
|
|
34
35
|
onEditorCreate: y,
|
|
35
36
|
onEditorDestroy: b,
|
|
36
37
|
onEditorUpdate: x,
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
onTransaction: S,
|
|
39
|
+
onContentError: C,
|
|
40
|
+
onException: w
|
|
39
41
|
};
|
|
40
42
|
}, [
|
|
41
43
|
v,
|
|
@@ -43,68 +45,72 @@ function SuperDocEditorInner(e, s) {
|
|
|
43
45
|
b,
|
|
44
46
|
x,
|
|
45
47
|
S,
|
|
46
|
-
C
|
|
48
|
+
C,
|
|
49
|
+
w
|
|
47
50
|
]);
|
|
48
|
-
let
|
|
51
|
+
let U = useRef(null), W = useRef(!1), G = useRef(A);
|
|
49
52
|
useEffect(() => {
|
|
50
|
-
|
|
51
|
-
}, [
|
|
52
|
-
|
|
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;
|
|
53
56
|
let e = !1, s = null;
|
|
54
57
|
return (async () => {
|
|
55
58
|
try {
|
|
56
59
|
let c = (await import("superdoc")).SuperDoc;
|
|
57
60
|
if (e) return;
|
|
58
61
|
s = new c({
|
|
59
|
-
...
|
|
60
|
-
selector: `#${CSS.escape(
|
|
61
|
-
...!m &&
|
|
62
|
-
documentMode:
|
|
63
|
-
role:
|
|
62
|
+
...k,
|
|
63
|
+
selector: `#${CSS.escape(R)}`,
|
|
64
|
+
...!m && F.current ? { toolbar: `#${CSS.escape(z)}` } : {},
|
|
65
|
+
documentMode: A,
|
|
66
|
+
role: j,
|
|
64
67
|
contained: h,
|
|
65
|
-
...
|
|
66
|
-
...
|
|
67
|
-
...
|
|
68
|
-
...
|
|
68
|
+
...T == null ? {} : { document: T },
|
|
69
|
+
...M ? { user: M } : {},
|
|
70
|
+
...N ? { users: N } : {},
|
|
71
|
+
...O ? { modules: O } : {},
|
|
69
72
|
onReady: (s) => {
|
|
70
|
-
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));
|
|
71
74
|
},
|
|
72
75
|
onEditorCreate: (s) => {
|
|
73
|
-
e ||
|
|
76
|
+
e || H.current.onEditorCreate?.(s);
|
|
74
77
|
},
|
|
75
78
|
onEditorDestroy: () => {
|
|
76
|
-
e ||
|
|
79
|
+
e || H.current.onEditorDestroy?.();
|
|
77
80
|
},
|
|
78
81
|
onEditorUpdate: (s) => {
|
|
79
|
-
e ||
|
|
82
|
+
e || H.current.onEditorUpdate?.(s);
|
|
83
|
+
},
|
|
84
|
+
onTransaction: (s) => {
|
|
85
|
+
e || H.current.onTransaction?.(s);
|
|
80
86
|
},
|
|
81
87
|
onContentError: (s) => {
|
|
82
|
-
e ||
|
|
88
|
+
e || H.current.onContentError?.(s);
|
|
83
89
|
},
|
|
84
90
|
onException: (s) => {
|
|
85
|
-
e ||
|
|
91
|
+
e || H.current.onException?.(s);
|
|
86
92
|
}
|
|
87
|
-
}),
|
|
93
|
+
}), P.current = s;
|
|
88
94
|
} catch (s) {
|
|
89
|
-
e || (
|
|
95
|
+
e || (W.current = !1, V(!1), d(!0), console.error("[SuperDocEditor] Failed to initialize SuperDoc:", s), H.current.onException?.({ error: s }));
|
|
90
96
|
}
|
|
91
97
|
})(), () => {
|
|
92
|
-
|
|
98
|
+
W.current = !1, U.current = null, s && (s.destroy(), P.current = null), e = !0;
|
|
93
99
|
};
|
|
94
100
|
}, [
|
|
95
|
-
|
|
96
|
-
j,
|
|
101
|
+
T,
|
|
97
102
|
M,
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
N,
|
|
104
|
+
O,
|
|
105
|
+
j,
|
|
100
106
|
m,
|
|
101
107
|
h,
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
R,
|
|
109
|
+
z
|
|
104
110
|
]);
|
|
105
|
-
let
|
|
111
|
+
let K = ["superdoc-wrapper", g].filter(Boolean).join(" "), q = B ? { display: "none" } : void 0;
|
|
106
112
|
return /* @__PURE__ */ jsxs("div", {
|
|
107
|
-
className:
|
|
113
|
+
className: K,
|
|
108
114
|
style: {
|
|
109
115
|
..._,
|
|
110
116
|
...h && {
|
|
@@ -114,23 +120,23 @@ function SuperDocEditorInner(e, s) {
|
|
|
114
120
|
},
|
|
115
121
|
children: [
|
|
116
122
|
!m && /* @__PURE__ */ jsx("div", {
|
|
117
|
-
ref:
|
|
118
|
-
id:
|
|
123
|
+
ref: F,
|
|
124
|
+
id: z,
|
|
119
125
|
className: "superdoc-toolbar-container",
|
|
120
|
-
style:
|
|
126
|
+
style: q
|
|
121
127
|
}),
|
|
122
128
|
/* @__PURE__ */ jsx("div", {
|
|
123
|
-
id:
|
|
129
|
+
id: R,
|
|
124
130
|
className: "superdoc-editor-container",
|
|
125
131
|
style: {
|
|
126
|
-
...
|
|
132
|
+
...q,
|
|
127
133
|
...h && {
|
|
128
134
|
flex: 1,
|
|
129
135
|
minHeight: 0
|
|
130
136
|
}
|
|
131
137
|
}
|
|
132
138
|
}),
|
|
133
|
-
|
|
139
|
+
B && !u && p && /* @__PURE__ */ jsx("div", {
|
|
134
140
|
className: "superdoc-loading-container",
|
|
135
141
|
children: p()
|
|
136
142
|
}),
|