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