@docx-editor.dev/pro 2.30.0 → 2.32.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.
Files changed (75) hide show
  1. package/README.md +24 -0
  2. package/dist/chunk-3WTOHPAB.js +1 -0
  3. package/dist/chunk-AVZO5ZHZ.js +1 -0
  4. package/dist/{chunk-CNXDNDD3.js → chunk-DLYVBBO7.js} +1 -1
  5. package/dist/chunk-GAGYRL3L.js +5 -0
  6. package/dist/chunk-HMSOWKXT.js +1 -0
  7. package/dist/chunk-I6HVINA4.cjs +1 -0
  8. package/dist/chunk-MHB6ID2P.cjs +1 -0
  9. package/dist/chunk-PMS3PGOE.cjs +1 -0
  10. package/dist/{chunk-N34IUO36.cjs → chunk-RYF4SNKX.cjs} +1 -1
  11. package/dist/chunk-YOWEY5F3.cjs +5 -0
  12. package/dist/collaboration/hocuspocus.cjs +1 -1
  13. package/dist/collaboration/hocuspocus.d.cts +3 -3
  14. package/dist/collaboration/hocuspocus.d.ts +3 -3
  15. package/dist/collaboration/hocuspocus.js +1 -1
  16. package/dist/collaboration/index.cjs +2 -2
  17. package/dist/collaboration/index.d.cts +63 -7
  18. package/dist/collaboration/index.d.ts +63 -7
  19. package/dist/collaboration/index.js +2 -2
  20. package/dist/collaboration/webrtc.cjs +2 -2
  21. package/dist/collaboration/webrtc.d.cts +34 -15
  22. package/dist/collaboration/webrtc.d.ts +34 -15
  23. package/dist/collaboration/webrtc.js +2 -2
  24. package/dist/{document-session-_v9vqiSX.d.cts → document-session-B-MlORjE.d.cts} +105 -9
  25. package/dist/{document-session-Bxs4_GgX.d.ts → document-session-B-iH-YCU.d.ts} +105 -9
  26. package/dist/document-session-B35ZX2W4.js +1 -0
  27. package/dist/document-session-V3O7XBJY.cjs +1 -0
  28. package/dist/{document-session-options-DelOC7PX.d.ts → document-session-options-CdOH-TNn.d.ts} +1 -1
  29. package/dist/{document-session-options-CfKypp9c.d.cts → document-session-options-CxR0F5xT.d.cts} +1 -1
  30. package/dist/index.cjs +1 -1
  31. package/dist/index.d.cts +2 -1
  32. package/dist/index.d.ts +2 -1
  33. package/dist/index.js +1 -1
  34. package/dist/react/hocuspocus.d.cts +2 -2
  35. package/dist/react/hocuspocus.d.ts +2 -2
  36. package/dist/react/index.cjs +2 -2
  37. package/dist/react/index.d.cts +283 -16
  38. package/dist/react/index.d.ts +283 -16
  39. package/dist/react/index.js +2 -2
  40. package/dist/react/webrtc.d.cts +9 -4
  41. package/dist/react/webrtc.d.ts +9 -4
  42. package/dist/{types-BQ1vBt5Q.d.ts → types-DvGpDOcZ.d.cts} +9 -1
  43. package/dist/{types-BQ1vBt5Q.d.cts → types-DvGpDOcZ.d.ts} +9 -1
  44. package/dist/{types-6EmrEn4n.d.cts → types-bt2k1VO0.d.cts} +9 -1
  45. package/dist/{types-6EmrEn4n.d.ts → types-bt2k1VO0.d.ts} +9 -1
  46. package/dist/vue/hocuspocus.cjs +1 -1
  47. package/dist/vue/hocuspocus.d.cts +2 -2
  48. package/dist/vue/hocuspocus.d.ts +2 -2
  49. package/dist/vue/hocuspocus.js +1 -1
  50. package/dist/vue/index.cjs +2 -2
  51. package/dist/vue/index.d.cts +285 -16
  52. package/dist/vue/index.d.ts +285 -16
  53. package/dist/vue/index.js +2 -2
  54. package/dist/vue/webrtc.cjs +1 -1
  55. package/dist/vue/webrtc.d.cts +9 -4
  56. package/dist/vue/webrtc.d.ts +9 -4
  57. package/dist/vue/webrtc.js +1 -1
  58. package/docs/accept-reject-without-scrolling.md +95 -0
  59. package/docs/comment-on-found-text.md +72 -0
  60. package/docs/custom-review-cards.md +178 -0
  61. package/docs/highlight-ranges.md +48 -0
  62. package/docs/index.md +36 -0
  63. package/docs/propose-rewrite.md +247 -0
  64. package/docs/tracked-replacement.md +68 -0
  65. package/package.json +5 -4
  66. package/dist/chunk-FD2KDBHX.cjs +0 -1
  67. package/dist/chunk-JRHEYVVY.cjs +0 -1
  68. package/dist/chunk-L567WP3J.js +0 -5
  69. package/dist/chunk-MJECUVHQ.cjs +0 -5
  70. package/dist/chunk-P2EF7WMV.js +0 -1
  71. package/dist/chunk-Q5JTCGJI.js +0 -1
  72. package/dist/chunk-SNQCYZLT.js +0 -1
  73. package/dist/chunk-ZSAAX6HV.cjs +0 -1
  74. package/dist/document-session-3VC43WNI.cjs +0 -1
  75. package/dist/document-session-J2YKWERI.js +0 -1
@@ -8,10 +8,10 @@
8
8
  import * as Y from 'yjs';
9
9
  import { WebrtcProvider } from 'y-webrtc';
10
10
  import { CollaborationIdentity } from '@docx-editor.dev/core/collaboration';
11
- import { D as DocumentCollaborationHandle } from '../document-session-Bxs4_GgX.js';
12
- import { a as CollaborationBootstrap } from '../types-BQ1vBt5Q.js';
11
+ import { D as DocumentCollaborationHandle } from '../document-session-B-iH-YCU.js';
12
+ import { a as CollaborationBootstrap } from '../types-DvGpDOcZ.js';
13
13
  export { c as createCollaborationRoomId, v as validateRoomId } from '../room-id-BfudXOZz.js';
14
- import '../document-session-options-DelOC7PX.js';
14
+ import '../document-session-options-CdOH-TNn.js';
15
15
  import 'y-protocols/awareness';
16
16
 
17
17
  /**
@@ -25,22 +25,25 @@ import 'y-protocols/awareness';
25
25
  /**
26
26
  * Public demo signaling endpoints. Use these endpoints for demos only.
27
27
  *
28
- * Production deployments must pass their own `signaling` URLs and TURN
29
- * servers. WebRTC peers cannot connect across many networks without TURN.
28
+ * The host is a shared, unauthenticated public service. It receives every room id and,
29
+ * without a `password`, every signaling message in plaintext. `createWebrtcCollaboration`
30
+ * never selects it for you: pass it as `signaling` to opt in. Production deployments pass
31
+ * their own `signaling` URLs and TURN servers. WebRTC peers cannot connect across many
32
+ * networks without TURN.
30
33
  * @public
31
34
  */
32
35
  declare const DEMO_SIGNALING_ENDPOINTS: readonly string[];
33
36
  /**
34
- * Warn once per process when a room silently falls back to the demo signaling endpoints.
37
+ * Refuse a room without explicit signaling endpoints.
35
38
  *
36
- * Passing `signaling: DEMO_SIGNALING_ENDPOINTS` is a deliberate choice and never warns —
37
- * only an omitted `signaling` does.
39
+ * A default would send room ids and signaling traffic to a host the integrator never chose,
40
+ * so a missing option fails before any connection opens. An empty list is explicit: it opens
41
+ * no signaling connection, and only tabs of the same browser find each other. Each entry
42
+ * must be a `ws://` or `wss://` URL, so a typo fails here and not inside the socket.
38
43
  *
39
44
  * @internal
40
45
  */
41
- declare function warnOnDemoSignalingFallback(signaling: readonly string[] | undefined): void;
42
- /** Test-only reset for the once-per-process demo signaling warning. @internal */
43
- declare function resetDemoSignalingWarningForTests(): void;
46
+ declare function requireSignaling(signaling: readonly string[] | undefined): readonly string[];
44
47
  /** Options for the owned WebRTC collaboration convenience wrapper. @public */
45
48
  interface CreateWebrtcCollaborationOptions {
46
49
  /** The room to join: a `createCollaborationRoomId` value every participant shares. */
@@ -55,8 +58,13 @@ interface CreateWebrtcCollaborationOptions {
55
58
  * {@link CreateDocumentCollaborationOptions.offlineEditing}.
56
59
  */
57
60
  readonly offlineEditing?: boolean;
58
- /** Signaling server URLs that introduce peers to each other. */
59
- readonly signaling?: readonly string[];
61
+ /**
62
+ * Signaling server URLs that introduce peers to each other. There is no default. Pass your
63
+ * own URLs in production, {@link DEMO_SIGNALING_ENDPOINTS} for demos, or `[]` to connect
64
+ * only tabs of the same browser. A call without this value rejects with a `TypeError`
65
+ * before any connection opens.
66
+ */
67
+ readonly signaling: readonly string[];
60
68
  /** STUN and TURN servers for the peer connections. Use TURN across restrictive networks. */
61
69
  readonly iceServers?: readonly RTCIceServer[];
62
70
  /**
@@ -103,8 +111,19 @@ declare function resolveWebrtcRoomPassword(options: {
103
111
  readonly password?: string;
104
112
  readonly href?: string;
105
113
  }): string | undefined;
106
- /** Create one owned `y-webrtc` room and provider-neutral collaboration session. @public */
114
+ /**
115
+ * Create one owned `y-webrtc` room and provider-neutral collaboration session.
116
+ *
117
+ * The room reaches only the signaling servers in `signaling`. It never falls back to public
118
+ * endpoints. The first room applies the same scoping to every `y-webrtc` provider in the
119
+ * page, including providers the host creates directly. A provider created before the first
120
+ * room keeps its own `destroy()`: call its `disconnect()` first to close its signaling.
121
+ *
122
+ * @throws `TypeError` (as a rejection) when `roomId` is invalid, or `signaling` is not an
123
+ * array of `ws://` or `wss://` URLs without a fragment. No connection opens.
124
+ * @public
125
+ */
107
126
  declare function createWebrtcCollaboration(options: CreateWebrtcCollaborationOptions): Promise<WebrtcCollaborationHandle>;
108
127
 
109
- export { DEMO_SIGNALING_ENDPOINTS, createWebrtcCollaboration, resetDemoSignalingWarningForTests, resolveWebrtcRoomPassword, warnOnDemoSignalingFallback };
128
+ export { DEMO_SIGNALING_ENDPOINTS, createWebrtcCollaboration, requireSignaling, resolveWebrtcRoomPassword };
110
129
  export type { CreateWebrtcCollaborationOptions, WebrtcCollaborationHandle };
@@ -1,2 +1,2 @@
1
- import {b}from'../chunk-6DEUT2RQ.js';export{a as createCollaborationRoomId,b as validateRoomId}from'../chunk-6DEUT2RQ.js';import {q}from'../chunk-L567WP3J.js';import*as H from'yjs';import {Awareness}from'y-protocols/awareness';import {WebrtcProvider}from'y-webrtc';function U(e,n){let t=0,r=null,i=new Set,l=()=>{r!==null&&clearInterval(r),r=null;},o=d=>{if(d!==t){t=d,t===0&&l();for(let b of [...i])b();}},c=()=>{let d=n.room;if(d===null)return false;if(d.bcConns.size>0)return true;for(let b of d.webrtcConns.values())if(b.connected&&b.synced)return true;return false},u=()=>{t>0&&c()&&o(0);},m=(d,b)=>{b===n.room||c()||(o(t+1),r??=setInterval(u,1e3));};return e.on("update",m),n.on("peers",u),n.on("synced",u),{count:()=>t,subscribe(d){return i.add(d),()=>{i.delete(d);}},destroy(){l(),e.off("update",m),n.off("peers",u),n.off("synced",u),i.clear();}}}var x=new WeakSet,R=(e,n)=>(e[n]<<24|e[n+1]<<16|e[n+2]<<8|e[n+3])>>>0,C=(e,n,t)=>{e[n]=t>>>24&255,e[n+1]=t>>>16&255,e[n+2]=t>>>8&255,e[n+3]=t&255;},G=e=>e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):null,K=e=>new Promise(n=>{setTimeout(n,e);});function B(e,n){if(x.has(e))return;x.add(e);let t=e.send.bind(e),r=e._onChannelMessage.bind(e),i=n?.partialTimeoutMs,l=typeof i=="number"&&Number.isFinite(i)&&i>0?i:3e4,o=n?.onAbandonedMessage,c=n?.onDeliveredMessage,u=Math.min(n?.maxPartialBytes??1/0,134111232),m=[],d=new Map,b=false,_=1,p=0,M=(s,a)=>{a.timer!==void 0&&clearTimeout(a.timer),d.delete(s),p-=a.bytes;},S=s=>{let a=d.get(s);a&&(M(s,a),e.destroyed!==true&&(o?.(),e.destroy?.()));},y=s=>{let a=d.get(s);a&&(a.timer!==void 0&&clearTimeout(a.timer),a.timer=setTimeout(()=>{S(s);},l));},v=()=>e._channel?.bufferedAmount??0,O=async()=>{let s=0;for(;v()>1048576;){if(e.destroyed===true||s>=3e4)return false;await K(20),s+=20;}return e.destroyed!==true},N=async s=>{let a=Math.ceil(s.byteLength/16371);if(a>8192)throw new Error(`collaboration message needs ${a} chunks, above the 8192 limit`);let h=_;_=_+1>>>0||1;for(let E=0;E<a;E+=1){if(!await O()){e.destroyed!==true&&e.destroy?.();return}let A=E*16371,f=s.subarray(A,Math.min(A+16371,s.byteLength)),g=new Uint8Array(13+f.byteLength);g[0]=251,C(g,1,h),C(g,5,E),C(g,9,a),g.set(f,13),t(g);}},W=async()=>{if(!b){b=true;try{for(;m.length>0;){let s=m.shift();if(s){if(e.destroyed===!0)return;await N(s);}}}finally{b=false;}}};e.send=s=>{if(typeof s=="string"||s.byteLength<=16371){t(s);return}m.push(s),W();},e._onChannelMessage=s=>{let a=G(s.data);if(!a||a.byteLength<13||a[0]!==251){r(s);return}let h=R(a,1),E=R(a,5),A=R(a,9);if(A===0||A>8192||E>=A)return;if(a.byteLength>16384){S(h);return}let f=d.get(h);if(!f){if(d.size>=4){let T=d.keys().next();T.done||S(T.value);}f={chunks:new Array(A),count:A,received:0,bytes:0,timer:void 0},d.set(h,f);}if(f.count!==A||f.chunks[E])return;let g=a.subarray(13);if(f.chunks[E]=g,f.received+=1,f.bytes+=g.byteLength,p+=g.byteLength,p>u){S(h);return}if(f.received!==f.count){y(h);return}M(h,f);let k=new Uint8Array(f.bytes),L=0;for(let T of f.chunks){if(!T)return;k.set(T,L),L+=T.byteLength;}e.destroyed!==true&&(e.push(k),c?.());};}function F(e,n){return t=>{n()&&(t?e.setTransportStatus("ready","transport-disconnected","a peer link cannot carry large updates"):e.setTransportStatus("ready"));}}var z=3,j=6e4;function Y(e,n={set:(t,r)=>setTimeout(t,r),clear:t=>clearTimeout(t)}){let t=new Map,r=new Map,i=new Set,l=o=>{t.delete(o);let c=r.get(o);c!==void 0&&n.clear(c),r.delete(o),i.delete(o)&&i.size===0&&e(false);};return {abandoned(o){let c=(t.get(o)??0)+1;t.set(o,c);let u=r.get(o);u!==void 0&&n.clear(u),r.set(o,n.set(()=>l(o),j)),!(c<z||i.has(o))&&(i.add(o),i.size===1&&e(true));},delivered:l,reset(){for(let o of [...t.keys(),...i])l(o);},destroy(){for(let o of r.values())n.clear(o);r.clear(),t.clear(),i.clear();}}}var Z=Object.freeze(["wss://turn.0docker.com/ws"]),P=false;function J(e){e===void 0&&(P||(P=true,console.warn("[docx-editor] createWebrtcCollaboration was called without `signaling`, so it uses the public demo endpoints. They are shared, unauthenticated, and can go away. Pass your own `signaling` URLs (and TURN `iceServers`) in production, or pass `signaling: DEMO_SIGNALING_ENDPOINTS` explicitly to accept the demo endpoints.")));}function fe(){P=false;}var Q=/^[A-Za-z0-9_-]{24,256}$/,I="#collab=";function V(e){let n=e.password?.trim()??"";return n.length>0?n:ee(e.href)}var ee=e=>{let n=e??(typeof globalThis.location=="object"&&globalThis.location!==null?String(globalThis.location.href??""):"");if(n.length===0)return;let t;try{t=new URL(n).hash;}catch{return}if(!t.startsWith(I))return;let r;try{r=decodeURIComponent(t.slice(I.length));}catch{return}if(Q.test(r))return r},ne=(e,n)=>{Promise.resolve(e.key).then(()=>{let t=e.room;if(!t)return;let r=t.webrtcConns,i=(o,c)=>{B(c.peer,{onAbandonedMessage:()=>n.abandoned(o),onDeliveredMessage:()=>n.delivered(o)});};for(let[o,c]of r)i(o,c);let l=r.set.bind(r);r.set=(o,c)=>(i(o,c),l(o,c));});};async function ye(e){let n=b(e.roomId);J(e.signaling);let t=V({password:e.password}),r=new H.Doc,i=new Awareness(r),l=null,o={abandoned(){},delivered(){}},c=()=>{let y=new WebrtcProvider(n,r,{awareness:i,signaling:[...e.signaling??Z],...t!==void 0?{password:t}:{},...e.iceServers?{peerOpts:{config:{iceServers:e.iceServers.map(v=>({...v}))}}}:{}});return ne(y,{abandoned:v=>o.abandoned(v),delivered:v=>o.delivered(v)}),y},u;try{e.bootstrap.kind!=="create"&&(l=c()),u=await q({ydoc:r,awareness:i,documentId:n,identity:e.identity,bootstrap:e.bootstrap,offlineEditing:e.offlineEditing}),l||(l=c());}catch(y){throw l?.destroy(),i.destroy(),r.destroy(),y}if(!l)throw u.destroy(),i.destroy(),r.destroy(),new Error("WebRTC provider did not initialize");let m=l,d=u.session,b$1=true,_=Y(F(d,()=>b$1));o=_;let p=y=>{b$1=y.connected,y.connected&&_.reset(),d.setTransportStatus(y.connected?"ready":"disconnected",y.connected?void 0:"transport-disconnected",y.connected?void 0:"webrtc disconnected");};m.on("status",p);let M=U(r,m),S=false;return Object.freeze({document:u.document,session:d,ydoc:r,provider:m,unsyncedChanges:()=>M.count(),subscribeUnsyncedChanges:y=>M.subscribe(y),destroy(){S||(S=true,m.off("status",p),M.destroy(),_.destroy(),u.destroy(),m.destroy(),i.destroy(),r.destroy());}})}
2
- export{Z as DEMO_SIGNALING_ENDPOINTS,ye as createWebrtcCollaboration,fe as resetDemoSignalingWarningForTests,V as resolveWebrtcRoomPassword,J as warnOnDemoSignalingFallback};
1
+ import {b}from'../chunk-6DEUT2RQ.js';export{a as createCollaborationRoomId,b as validateRoomId}from'../chunk-6DEUT2RQ.js';import {r}from'../chunk-GAGYRL3L.js';import*as Q from'yjs';import {Awareness}from'y-protocols/awareness';import {WebrtcProvider,SignalingConn,Room}from'y-webrtc';function N(e,n){let t=0,o=null,i=new Set,a=()=>{o!==null&&clearInterval(o),o=null;},r=l=>{if(l!==t){t=l,t===0&&a();for(let f of [...i])f();}},s=()=>{let l=n.room;if(l===null)return false;if(l.bcConns.size>0)return true;for(let f of l.webrtcConns.values())if(f.connected&&f.synced)return true;return false},b=()=>{t>0&&s()&&r(0);},g=(l,f)=>{f===n.room||s()||(r(t+1),o??=setInterval(b,1e3));};return e.on("update",g),n.on("peers",b),n.on("synced",b),{count:()=>t,subscribe(l){return i.add(l),()=>{i.delete(l);}},destroy(){a(),e.off("update",g),n.off("peers",b),n.off("synced",b),i.clear();}}}var O=new WeakSet,k=(e,n)=>(e[n]<<24|e[n+1]<<16|e[n+2]<<8|e[n+3])>>>0,P=(e,n,t)=>{e[n]=t>>>24&255,e[n+1]=t>>>16&255,e[n+2]=t>>>8&255,e[n+3]=t&255;},te=e=>e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):null,oe=e=>new Promise(n=>{setTimeout(n,e);});function W(e,n){if(O.has(e))return;O.add(e);let t=e.send.bind(e),o=e._onChannelMessage.bind(e),i=n?.partialTimeoutMs,a=typeof i=="number"&&Number.isFinite(i)&&i>0?i:3e4,r=n?.onAbandonedMessage,s=n?.onDeliveredMessage,b=Math.min(n?.maxPartialBytes??1/0,134111232),g=[],l=new Map,f=false,_=1,E=0,C=(c,d)=>{d.timer!==void 0&&clearTimeout(d.timer),l.delete(c),E-=d.bytes;},m=c=>{let d=l.get(c);d&&(C(c,d),e.destroyed!==true&&(r?.(),e.destroy?.()));},R=c=>{let d=l.get(c);d&&(d.timer!==void 0&&clearTimeout(d.timer),d.timer=setTimeout(()=>{m(c);},a));},y=()=>e._channel?.bufferedAmount??0,v=async()=>{let c=0;for(;y()>1048576;){if(e.destroyed===true||c>=3e4)return false;await oe(20),c+=20;}return e.destroyed!==true},V=async c=>{let d=Math.ceil(c.byteLength/16371);if(d>8192)throw new Error(`collaboration message needs ${d} chunks, above the 8192 limit`);let S=_;_=_+1>>>0||1;for(let A=0;A<d;A+=1){if(!await v()){e.destroyed!==true&&e.destroy?.();return}let h=A*16371,u=c.subarray(h,Math.min(h+16371,c.byteLength)),p=new Uint8Array(13+u.byteLength);p[0]=251,P(p,1,S),P(p,5,A),P(p,9,d),p.set(u,13),t(p);}},ee=async()=>{if(!f){f=true;try{for(;g.length>0;){let c=g.shift();if(c){if(e.destroyed===!0)return;await V(c);}}}finally{f=false;}}};e.send=c=>{if(typeof c=="string"||c.byteLength<=16371){t(c);return}g.push(c),ee();},e._onChannelMessage=c=>{let d=te(c.data);if(!d||d.byteLength<13||d[0]!==251){o(c);return}let S=k(d,1),A=k(d,5),h=k(d,9);if(h===0||h>8192||A>=h)return;if(d.byteLength>16384){m(S);return}let u=l.get(S);if(!u){if(l.size>=4){let M=l.keys().next();M.done||m(M.value);}u={chunks:new Array(h),count:h,received:0,bytes:0,timer:void 0},l.set(S,u);}if(u.count!==h||u.chunks[A])return;let p=d.subarray(13);if(u.chunks[A]=p,u.received+=1,u.bytes+=p.byteLength,E+=p.byteLength,E>b){m(S);return}if(u.received!==u.count){R(S);return}C(S,u);let Y=new Uint8Array(u.bytes),F=0;for(let M of u.chunks){if(!M)return;Y.set(M,F),F+=M.byteLength;}e.destroyed!==true&&(e.push(Y),s?.());};}function j(e,n){return t=>{n()&&(t?e.setTransportStatus("ready","transport-disconnected","a peer link cannot carry large updates"):e.setTransportStatus("ready"));}}var re=3,ie=6e4;function X(e,n={set:(t,o)=>setTimeout(t,o),clear:t=>clearTimeout(t)}){let t=new Map,o=new Map,i=new Set,a=r=>{t.delete(r);let s=o.get(r);s!==void 0&&n.clear(s),o.delete(r),i.delete(r)&&i.size===0&&e(false);};return {abandoned(r){let s=(t.get(r)??0)+1;t.set(r,s);let b=o.get(r);b!==void 0&&n.clear(b),o.set(r,n.set(()=>a(r),ie)),!(s<re||i.has(r))&&(i.add(r),i.size===1&&e(true));},delivered:a,reset(){for(let r of [...t.keys(),...i])a(r);},destroy(){for(let r of o.values())n.clear(r);o.clear(),t.clear(),i.clear();}}}var K=Symbol.for("docx-editor.webrtc-signaling-scope"),U=new WeakMap,I=new WeakSet,B=new WeakSet,z=new WeakSet,q=e=>{let n=U.get(e);return n||(n=new Set,U.set(e,n)),n};function se(e){B.add(e),I.add(e);}function ae(e){B.add(e),I.delete(e);}var ce=e=>e?B.has(e)?I.has(e):e.bcconnected===true:false;function x(e,n){if(typeof n!="string")return false;for(let t of e.providers)if(t.roomName===n&&t.shouldConnect!==false&&ce(t.room))return true;return false}var $=e=>Array.isArray(e)?e.filter(n=>typeof n=="string"):[];function de(e,n){if(n===null||typeof n!="object")return n;let{type:t,topic:o,topics:i}=n;switch(t){case "subscribe":{let a=$(i).filter(s=>x(e,s));if(a.length===0)return null;let r=q(e);for(let s of a)r.add(s);return {...n,topics:a}}case "unsubscribe":{let a=q(e),r=$(i).filter(s=>a.has(s));if(r.length===0)return null;for(let s of r)a.delete(s);return {...n,topics:r}}case "publish":return x(e,o)?n:null;default:return n}}function le(e,n){if(n===null||typeof n!="object")return true;let{type:t,topic:o}=n;return t!=="publish"||x(e,o)}function ue(e){U.delete(e);}var w=(e,n,t)=>{let o=e;o[n]=t(o[n]);};function Z(){let e=SignalingConn.prototype;e[K]||(e[K]=true,w(SignalingConn.prototype,"send",n=>function(o){let i=de(this,o);i!==null&&n.call(this,i);}),w(SignalingConn.prototype,"emit",n=>function(o,i){o==="disconnect"&&ue(this);let a=Array.isArray(i)?i[0]:void 0;if(!(o==="message"&&!le(this,a)))return n.call(this,o,i)}),w(Room.prototype,"connect",n=>function(){return se(this),n.call(this)}),w(Room.prototype,"disconnect",n=>function(){return ae(this),n.call(this)}),w(WebrtcProvider.prototype,"disconnect",n=>function(){this.shouldConnect&&(n.call(this),this.signalingConns=[...new Set(this.signalingConns.filter(o=>o.providers.has(this)))]);}),w(WebrtcProvider.prototype,"destroy",n=>function(){return z.add(this),this.shouldConnect&&this.disconnect(),n.call(this)}),w(WebrtcProvider.prototype,"connect",n=>function(){if(!z.has(this))return n.call(this)}));}var Ue=Object.freeze(["wss://turn.0docker.com/ws"]);function be(e){if(!Array.isArray(e))throw new TypeError("WebRTC collaboration requires `signaling`, an array of signaling server URLs. Pass your own URLs in production. For demos, pass `signaling: DEMO_SIGNALING_ENDPOINTS` from '@docx-editor.dev/pro/collaboration/webrtc'. To connect only tabs of the same browser, pass `signaling: []`.");return e.forEach((n,t)=>{if(!ge(n))throw new TypeError(`WebRTC collaboration needs signaling[${t}] to be a ws:// or wss:// URL without a #fragment.`)}),e}var ge=e=>{if(typeof e!="string")return false;try{let{protocol:n}=new URL(e);return (n==="ws:"||n==="wss:")&&!e.includes("#")}catch{return false}},pe=/^[A-Za-z0-9_-]{24,256}$/,J="#collab=";function he(e){let n=e.password?.trim()??"";return n.length>0?n:me(e.href)}var me=e=>{let n=e??(typeof globalThis.location=="object"&&globalThis.location!==null?String(globalThis.location.href??""):"");if(n.length===0)return;let t;try{t=new URL(n).hash;}catch{return}if(!t.startsWith(J))return;let o;try{o=decodeURIComponent(t.slice(J.length));}catch{return}if(pe.test(o))return o},Se=(e,n)=>{Promise.resolve(e.key).then(()=>{let t=e.room;if(!t)return;let o=t.webrtcConns,i=(r,s)=>{W(s.peer,{onAbandonedMessage:()=>n.abandoned(r),onDeliveredMessage:()=>n.delivered(r)});};for(let[r,s]of o)i(r,s);let a=o.set.bind(o);o.set=(r,s)=>(i(r,s),a(r,s));});};async function xe(e){let n=b(e.roomId),t=be(e.signaling);Z();let o=he({password:e.password}),i=new Q.Doc,a=new Awareness(i),r$1=null,s={abandoned(){},delivered(){}},b$1=()=>{let y=new WebrtcProvider(n,i,{awareness:a,signaling:[...t],...o!==void 0?{password:o}:{},...e.iceServers?{peerOpts:{config:{iceServers:e.iceServers.map(v=>({...v}))}}}:{}});return Se(y,{abandoned:v=>s.abandoned(v),delivered:v=>s.delivered(v)}),y},g;try{e.bootstrap.kind!=="create"&&(r$1=b$1()),g=await r({ydoc:i,awareness:a,documentId:n,identity:e.identity,bootstrap:e.bootstrap,offlineEditing:e.offlineEditing}),r$1||(r$1=b$1());}catch(y){throw r$1?.destroy(),a.destroy(),i.destroy(),y}if(!r$1)throw g.destroy(),a.destroy(),i.destroy(),new Error("WebRTC provider did not initialize");let l=r$1,f=g.session,_=true,E=X(j(f,()=>_));s=E;let C=y=>{_=y.connected,y.connected&&E.reset(),f.setTransportStatus(y.connected?"ready":"disconnected",y.connected?void 0:"transport-disconnected",y.connected?void 0:"webrtc disconnected");};l.on("status",C);let m=N(i,l),R=false;return Object.freeze({document:g.document,session:f,ydoc:i,provider:l,unsyncedChanges:()=>m.count(),subscribeUnsyncedChanges:y=>m.subscribe(y),destroy(){R||(R=true,l.off("status",C),m.destroy(),E.destroy(),g.destroy(),l.destroy(),a.destroy(),i.destroy());}})}
2
+ export{Ue as DEMO_SIGNALING_ENDPOINTS,xe as createWebrtcCollaboration,be as requireSignaling,he as resolveWebrtcRoomPassword};
@@ -1,7 +1,7 @@
1
+ import { b as CollaborationIdentityUpdate, c as CollaborationHandle } from './types-DvGpDOcZ.cjs';
1
2
  import { EditorCollaborationSession, CollaborationFailureCode } from '@docx-editor.dev/core/collaboration';
2
3
  import * as Y from 'yjs';
3
- import { c as CollaborationHandle, b as CollaborationIdentityUpdate } from './types-BQ1vBt5Q.cjs';
4
- import { C as CreateDocumentCollaborationOptions } from './document-session-options-CfKypp9c.cjs';
4
+ import { C as CreateDocumentCollaborationOptions } from './document-session-options-CxR0F5xT.cjs';
5
5
 
6
6
  /**
7
7
  * Room-size observability.
@@ -63,13 +63,48 @@ interface CollaborationResourceUsage {
63
63
  declare function readCollaborationResourceUsage(ydoc: Y.Doc): CollaborationResourceUsage;
64
64
 
65
65
  /**
66
- * Full-document collaboration over the canonical primitive journal.
66
+ * Why `beginUndoGroup` refused.
67
67
  *
68
- * Local direction: the canonical store commits, emits ONE journal, and the journal is applied
69
- * to shared state in one Yjs transaction. Remote direction: a shared-state change materializes
70
- * one canonical package, which the port publishes as one revision. The two never chase each
71
- * other, because a remote publication deliberately emits no journal.
68
+ * - `undo-group-already-open`: this session already has an open group. Groups do not nest
69
+ * and two operations cannot share one session's group. End the open group first, or give
70
+ * each concurrent operation its own session.
71
+ * - `editor-attached`: an editor that people edit through is attached to this session. Use
72
+ * the editor's own `beginHistoryGroup()` there.
73
+ * - `collaboration-session-destroyed`: the session was destroyed.
74
+ * @public
75
+ */
76
+ type CollaborationUndoGroupErrorCode = 'undo-group-already-open' | 'editor-attached' | 'collaboration-session-destroyed';
77
+ /**
78
+ * Thrown by `beginUndoGroup` when the session cannot open a group. Branch on `code`.
79
+ * @public
72
80
  */
81
+ declare class CollaborationUndoGroupError extends Error {
82
+ /** Stable refusal code. */
83
+ readonly code: CollaborationUndoGroupErrorCode;
84
+ constructor(
85
+ /** Stable refusal code. */
86
+ code: CollaborationUndoGroupErrorCode);
87
+ }
88
+ /**
89
+ * One open undo group of a collaboration session.
90
+ *
91
+ * Every local write the session publishes while the group is open becomes part of one undo
92
+ * step, however long the group stays open. `end()` closes the step, so the next write
93
+ * starts a new one, however soon it follows.
94
+ * @public
95
+ */
96
+ interface CollaborationUndoGroup {
97
+ /** `closed` after `end()`, after the session is destroyed, or after an editor attaches. */
98
+ readonly state: 'open' | 'closed';
99
+ /**
100
+ * Publish committed local writes into the group, then close it. Reverts nothing. Safe to
101
+ * call more than once, and after the session is destroyed.
102
+ *
103
+ * Commands a runtime still queues are not committed yet. Call `end()` after
104
+ * `runtime.run()` resolves, so its last `context.sync()` lands inside the group.
105
+ */
106
+ end(): void;
107
+ }
73
108
 
74
109
  /**
75
110
  * Full-document collaboration session: the engine-facing seam, the transport status a
@@ -105,7 +140,68 @@ interface DocumentCollaborationSession extends EditorCollaborationSession {
105
140
  * schedule rather than per keystroke.
106
141
  */
107
142
  resourceUsage(): CollaborationResourceUsage;
143
+ /**
144
+ * Open an explicit undo group: every local write this session publishes until `end()` is
145
+ * one undo step. For a server or headless replica, such as an agent's.
146
+ *
147
+ * Without a group, local writes that land within 500 ms of each other share one undo step.
148
+ * A group replaces that timing rule. Its first write starts a new step, however soon it
149
+ * follows the previous write. Its later writes join that step, however long the group
150
+ * stays open. The first write after `end()` starts a new step.
151
+ *
152
+ * Each boundary publishes the writes that are already committed. A runtime commits its
153
+ * queued commands only at `context.sync()`, so call `end()` after `runtime.run()` resolves,
154
+ * not inside the callback before its last sync.
155
+ *
156
+ * - Undo and redo refuse while the group is open: `undo()` and `redo()` return false, and
157
+ * `canUndo()` and `canRedo()` report false. {@link DocumentCollaborationSession.undoGroupOpen}
158
+ * tells this refusal apart from an empty history. End the group first.
159
+ * - A refused write does not end the group. Later writes join the same step as the
160
+ * earlier ones. To revert the whole operation, end the group and call `undo()` once.
161
+ * - Only local writes join the group. Other participants' edits stay out of it, and an
162
+ * undo of the group keeps them. It can also remove text that others typed in a
163
+ * paragraph the group inserted (#1398). When they removed everything the group wrote,
164
+ * its undo changes nothing and never reverts an older step.
165
+ * - An undo of an ungrouped step never reverts a group's step below it. Ungrouped history
166
+ * otherwise undoes as it does without groups. If a peer removed everything that the top
167
+ * ungrouped step wrote, that `undo()` changes nothing and returns true. Call `undo()`
168
+ * again to revert the group.
169
+ * - Destroying the session, or attaching an editor to it, closes an open group.
170
+ *
171
+ * @throws CollaborationUndoGroupError with `undo-group-already-open` when this session
172
+ * already has an open group, `editor-attached` when an editor that people edit through is
173
+ * attached (use the editor's `beginHistoryGroup()` there), or
174
+ * `collaboration-session-destroyed` after `destroy()`. Groups do not nest. Give each
175
+ * concurrent operation its own session.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * const group = session.beginUndoGroup();
180
+ * try {
181
+ * await runtime.run(async (context) => {
182
+ * context.document.body.insertParagraph('Task A', 'End');
183
+ * await context.sync();
184
+ * });
185
+ * } finally {
186
+ * group.end();
187
+ * }
188
+ * session.undo(); // reverts Task A only
189
+ * ```
190
+ */
191
+ beginUndoGroup(): CollaborationUndoGroup;
192
+ /** Whether an undo group from {@link DocumentCollaborationSession.beginUndoGroup} is open. */
193
+ readonly undoGroupOpen: boolean;
108
194
  }
195
+
196
+ /**
197
+ * Full-document collaboration over the canonical primitive journal.
198
+ *
199
+ * Local direction: the canonical store commits, emits ONE journal, and the journal is applied
200
+ * to shared state in one Yjs transaction. Remote direction: a shared-state change materializes
201
+ * one canonical package, which the port publishes as one revision. The two never chase each
202
+ * other, because a remote publication deliberately emits no journal.
203
+ */
204
+
109
205
  /** Owned full-document collaboration replica. @public */
110
206
  type DocumentCollaborationHandle = CollaborationHandle<DocumentCollaborationSession>;
111
207
 
@@ -142,5 +238,5 @@ type DocumentCollaborationHandle = CollaborationHandle<DocumentCollaborationSess
142
238
  */
143
239
  declare function createDocumentCollaboration(options: CreateDocumentCollaborationOptions): Promise<DocumentCollaborationHandle>;
144
240
 
145
- export { createDocumentCollaboration as c, readCollaborationResourceUsage as r };
146
- export type { CollaborationResourceUsage as C, DocumentCollaborationHandle as D, DocumentCollaborationSession as a };
241
+ export { CollaborationUndoGroupError as b, createDocumentCollaboration as e, readCollaborationResourceUsage as r };
242
+ export type { CollaborationResourceUsage as C, DocumentCollaborationHandle as D, CollaborationUndoGroup as a, CollaborationUndoGroupErrorCode as c, DocumentCollaborationSession as d };
@@ -1,7 +1,7 @@
1
+ import { b as CollaborationIdentityUpdate, c as CollaborationHandle } from './types-DvGpDOcZ.js';
1
2
  import { EditorCollaborationSession, CollaborationFailureCode } from '@docx-editor.dev/core/collaboration';
2
3
  import * as Y from 'yjs';
3
- import { c as CollaborationHandle, b as CollaborationIdentityUpdate } from './types-BQ1vBt5Q.js';
4
- import { C as CreateDocumentCollaborationOptions } from './document-session-options-DelOC7PX.js';
4
+ import { C as CreateDocumentCollaborationOptions } from './document-session-options-CdOH-TNn.js';
5
5
 
6
6
  /**
7
7
  * Room-size observability.
@@ -63,13 +63,48 @@ interface CollaborationResourceUsage {
63
63
  declare function readCollaborationResourceUsage(ydoc: Y.Doc): CollaborationResourceUsage;
64
64
 
65
65
  /**
66
- * Full-document collaboration over the canonical primitive journal.
66
+ * Why `beginUndoGroup` refused.
67
67
  *
68
- * Local direction: the canonical store commits, emits ONE journal, and the journal is applied
69
- * to shared state in one Yjs transaction. Remote direction: a shared-state change materializes
70
- * one canonical package, which the port publishes as one revision. The two never chase each
71
- * other, because a remote publication deliberately emits no journal.
68
+ * - `undo-group-already-open`: this session already has an open group. Groups do not nest
69
+ * and two operations cannot share one session's group. End the open group first, or give
70
+ * each concurrent operation its own session.
71
+ * - `editor-attached`: an editor that people edit through is attached to this session. Use
72
+ * the editor's own `beginHistoryGroup()` there.
73
+ * - `collaboration-session-destroyed`: the session was destroyed.
74
+ * @public
75
+ */
76
+ type CollaborationUndoGroupErrorCode = 'undo-group-already-open' | 'editor-attached' | 'collaboration-session-destroyed';
77
+ /**
78
+ * Thrown by `beginUndoGroup` when the session cannot open a group. Branch on `code`.
79
+ * @public
72
80
  */
81
+ declare class CollaborationUndoGroupError extends Error {
82
+ /** Stable refusal code. */
83
+ readonly code: CollaborationUndoGroupErrorCode;
84
+ constructor(
85
+ /** Stable refusal code. */
86
+ code: CollaborationUndoGroupErrorCode);
87
+ }
88
+ /**
89
+ * One open undo group of a collaboration session.
90
+ *
91
+ * Every local write the session publishes while the group is open becomes part of one undo
92
+ * step, however long the group stays open. `end()` closes the step, so the next write
93
+ * starts a new one, however soon it follows.
94
+ * @public
95
+ */
96
+ interface CollaborationUndoGroup {
97
+ /** `closed` after `end()`, after the session is destroyed, or after an editor attaches. */
98
+ readonly state: 'open' | 'closed';
99
+ /**
100
+ * Publish committed local writes into the group, then close it. Reverts nothing. Safe to
101
+ * call more than once, and after the session is destroyed.
102
+ *
103
+ * Commands a runtime still queues are not committed yet. Call `end()` after
104
+ * `runtime.run()` resolves, so its last `context.sync()` lands inside the group.
105
+ */
106
+ end(): void;
107
+ }
73
108
 
74
109
  /**
75
110
  * Full-document collaboration session: the engine-facing seam, the transport status a
@@ -105,7 +140,68 @@ interface DocumentCollaborationSession extends EditorCollaborationSession {
105
140
  * schedule rather than per keystroke.
106
141
  */
107
142
  resourceUsage(): CollaborationResourceUsage;
143
+ /**
144
+ * Open an explicit undo group: every local write this session publishes until `end()` is
145
+ * one undo step. For a server or headless replica, such as an agent's.
146
+ *
147
+ * Without a group, local writes that land within 500 ms of each other share one undo step.
148
+ * A group replaces that timing rule. Its first write starts a new step, however soon it
149
+ * follows the previous write. Its later writes join that step, however long the group
150
+ * stays open. The first write after `end()` starts a new step.
151
+ *
152
+ * Each boundary publishes the writes that are already committed. A runtime commits its
153
+ * queued commands only at `context.sync()`, so call `end()` after `runtime.run()` resolves,
154
+ * not inside the callback before its last sync.
155
+ *
156
+ * - Undo and redo refuse while the group is open: `undo()` and `redo()` return false, and
157
+ * `canUndo()` and `canRedo()` report false. {@link DocumentCollaborationSession.undoGroupOpen}
158
+ * tells this refusal apart from an empty history. End the group first.
159
+ * - A refused write does not end the group. Later writes join the same step as the
160
+ * earlier ones. To revert the whole operation, end the group and call `undo()` once.
161
+ * - Only local writes join the group. Other participants' edits stay out of it, and an
162
+ * undo of the group keeps them. It can also remove text that others typed in a
163
+ * paragraph the group inserted (#1398). When they removed everything the group wrote,
164
+ * its undo changes nothing and never reverts an older step.
165
+ * - An undo of an ungrouped step never reverts a group's step below it. Ungrouped history
166
+ * otherwise undoes as it does without groups. If a peer removed everything that the top
167
+ * ungrouped step wrote, that `undo()` changes nothing and returns true. Call `undo()`
168
+ * again to revert the group.
169
+ * - Destroying the session, or attaching an editor to it, closes an open group.
170
+ *
171
+ * @throws CollaborationUndoGroupError with `undo-group-already-open` when this session
172
+ * already has an open group, `editor-attached` when an editor that people edit through is
173
+ * attached (use the editor's `beginHistoryGroup()` there), or
174
+ * `collaboration-session-destroyed` after `destroy()`. Groups do not nest. Give each
175
+ * concurrent operation its own session.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * const group = session.beginUndoGroup();
180
+ * try {
181
+ * await runtime.run(async (context) => {
182
+ * context.document.body.insertParagraph('Task A', 'End');
183
+ * await context.sync();
184
+ * });
185
+ * } finally {
186
+ * group.end();
187
+ * }
188
+ * session.undo(); // reverts Task A only
189
+ * ```
190
+ */
191
+ beginUndoGroup(): CollaborationUndoGroup;
192
+ /** Whether an undo group from {@link DocumentCollaborationSession.beginUndoGroup} is open. */
193
+ readonly undoGroupOpen: boolean;
108
194
  }
195
+
196
+ /**
197
+ * Full-document collaboration over the canonical primitive journal.
198
+ *
199
+ * Local direction: the canonical store commits, emits ONE journal, and the journal is applied
200
+ * to shared state in one Yjs transaction. Remote direction: a shared-state change materializes
201
+ * one canonical package, which the port publishes as one revision. The two never chase each
202
+ * other, because a remote publication deliberately emits no journal.
203
+ */
204
+
109
205
  /** Owned full-document collaboration replica. @public */
110
206
  type DocumentCollaborationHandle = CollaborationHandle<DocumentCollaborationSession>;
111
207
 
@@ -142,5 +238,5 @@ type DocumentCollaborationHandle = CollaborationHandle<DocumentCollaborationSess
142
238
  */
143
239
  declare function createDocumentCollaboration(options: CreateDocumentCollaborationOptions): Promise<DocumentCollaborationHandle>;
144
240
 
145
- export { createDocumentCollaboration as c, readCollaborationResourceUsage as r };
146
- export type { CollaborationResourceUsage as C, DocumentCollaborationHandle as D, DocumentCollaborationSession as a };
241
+ export { CollaborationUndoGroupError as b, createDocumentCollaboration as e, readCollaborationResourceUsage as r };
242
+ export type { CollaborationResourceUsage as C, DocumentCollaborationHandle as D, CollaborationUndoGroup as a, CollaborationUndoGroupErrorCode as c, DocumentCollaborationSession as d };
@@ -0,0 +1 @@
1
+ export{q as ATTACH_WATCHDOG_MS_FOR_TESTS,r as createDocumentCollaboration,p as readCollaborationDocument}from'./chunk-GAGYRL3L.js';
@@ -0,0 +1 @@
1
+ 'use strict';var chunkYOWEY5F3_cjs=require('./chunk-YOWEY5F3.cjs');Object.defineProperty(exports,"ATTACH_WATCHDOG_MS_FOR_TESTS",{enumerable:true,get:function(){return chunkYOWEY5F3_cjs.q}});Object.defineProperty(exports,"createDocumentCollaboration",{enumerable:true,get:function(){return chunkYOWEY5F3_cjs.r}});Object.defineProperty(exports,"readCollaborationDocument",{enumerable:true,get:function(){return chunkYOWEY5F3_cjs.p}});
@@ -1,7 +1,7 @@
1
1
  import * as Y from 'yjs';
2
2
  import { Awareness } from 'y-protocols/awareness';
3
3
  import { CollaborationIdentity } from '@docx-editor.dev/core/collaboration';
4
- import { a as CollaborationBootstrap } from './types-BQ1vBt5Q.js';
4
+ import { a as CollaborationBootstrap } from './types-DvGpDOcZ.js';
5
5
 
6
6
  /**
7
7
  * Options for one full-document collaboration replica.
@@ -1,7 +1,7 @@
1
1
  import * as Y from 'yjs';
2
2
  import { Awareness } from 'y-protocols/awareness';
3
3
  import { CollaborationIdentity } from '@docx-editor.dev/core/collaboration';
4
- import { a as CollaborationBootstrap } from './types-BQ1vBt5Q.cjs';
4
+ import { a as CollaborationBootstrap } from './types-DvGpDOcZ.cjs';
5
5
 
6
6
  /**
7
7
  * Options for one full-document collaboration replica.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkFD2KDBHX_cjs=require('./chunk-FD2KDBHX.cjs'),chunkQLZH2Q2C_cjs=require('./chunk-QLZH2Q2C.cjs'),store=require('@docx-editor.dev/core/store');function U(t,n={}){let r=L(t);if(!r)return [];let o=n.nodes??t.getCustomNodeDefinitions().filter(chunkFD2KDBHX_cjs.j);if(o.length===0)return [];let s=r.session.currentPackage(),d=r.session.part().name,m=n.onDiagnostic??(e=>{t.reportCustomNodeDiagnostic(e);});return r.session.storyParts().flatMap(e=>chunkFD2KDBHX_cjs.n(e,o,{payloads:store.customNodePayloadsByControl(s,e.name,d),onDiagnostic:m}))}function L(t){return t.surface??null}function E(t,n,r={}){if(r.destination==="internal")return {ok:true,bytes:t,unwrapped:0,removed:0};let o=store.readOoxmlPackage(t);if(!o.ok)return {ok:false,reason:`the document could not be read: ${o.reason}`};let s=new Map;for(let i of n)s.set(`${i.tagPrefix}:${i.name}`,i);let d=i=>{let p=chunkFD2KDBHX_cjs.c(i);if(!p)return "keep";let x=s.get(`${p.prefix}:${p.name}`);return x?x.preserveOnExport==="text"?"text":x.preserveOnExport===false?"remove":"keep":"keep"},m=[...new Set(n.filter(i=>i.preserveOnExport!==void 0).filter(i=>i.preserveOnExport!==true).map(chunkFD2KDBHX_cjs.h))],e=o.package,u=0,c=0,g=V(e);for(let i of g){let p=store.withExportedCustomNodes(e,{storyPartName:i,namespaces:[],decide:d});if(!p.ok)return {ok:false,reason:p.reason};e=p.pkg,u+=p.unwrapped,c+=p.removed;}let l=store.withExportedCustomNodes(e,{storyPartName:e.mainDocumentPart,namespaces:m,decide:()=>"keep"});return l.ok?(e=l.pkg,{ok:true,bytes:store.writeOoxmlPackage(e),unwrapped:u,removed:c}):{ok:false,reason:l.reason}}function V(t){let n=[];for(let[r,o]of t.parts)r!==t.mainDocumentPart&&store.isStoryPart(o)&&n.push(r);return [t.mainDocumentPart,...n]}async function G(t,n={}){let r=n.nodes??t.getCustomNodeDefinitions().filter(chunkFD2KDBHX_cjs.j),o=await t.save();return E(new Uint8Array(o),r,{...n.destination===void 0?{}:{destination:n.destination}})}function a(t){return t.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g,"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function K(t,n,r,o={}){if(!chunkFD2KDBHX_cjs.k.test(t.tagPrefix)||!chunkFD2KDBHX_cjs.k.test(t.name))return {ok:false,code:"invalidArgs",reason:"the definition identity must match defineCustomNode\u2019s charset ([A-Za-z0-9_.-])"};let s=chunkFD2KDBHX_cjs.b(t.tagPrefix,t.name,n);if(!s.ok)return {ok:false,code:"invalidArgs",reason:`the encoded tag is ${s.length} characters; Word caps w:tag at 64 \u2014 shorten the attrs`};let d=o.lock===void 0?"contentLocked":o.lock,m=o.id!==void 0&&Number.isInteger(o.id)&&o.id>0?o.id:store.fnv1a32(`${s.tag}\0${r}`)&2147483647||1,e=o.data===void 0?null:Q(t,o,r);if(e&&"reason"in e)return {ok:false,code:"invalidArgs",reason:e.reason};let u=(o.alias!==void 0?`<w:alias w:val="${a(o.alias)}"/>`:"")+`<w:tag w:val="${a(s.tag)}"/><w:id w:val="${m}"/>`+(d===false?"":`<w:lock w:val="${d}"/>`)+(e?`<w:dataBinding w:prefixMappings="${a(e.binding.prefixMappings)}" w:xpath="${a(e.binding.xpath)}" w:storeItemID="${a(e.binding.storeItemId)}"/>`:""),c=`<w:r><w:t xml:space="preserve">${a(r)}</w:t></w:r>`;return {ok:true,xml:`<w:sdt><w:sdtPr>${u}</w:sdtPr><w:sdtContent>${c}</w:sdtContent></w:sdt>`,...e?{store:e.store}:{}}}function Q(t,n,r){let o=chunkFD2KDBHX_cjs.i(t,n.data);if(!o.ok)return {reason:o.reason};let s=chunkFD2KDBHX_cjs.h(t),d=n.storeIndex!==void 0&&Number.isInteger(n.storeIndex)&&n.storeIndex>0?n.storeIndex:1,m=n.nodeId??"cx1",e=`/customXml/item${String(d)}.xml`,u=`/customXml/itemProps${String(d)}.xml`,c=store.datastoreItemIdFor(`${s} ${e} ${m}`),g=store.customNodeBinding({partName:e,propsPartName:u,itemId:c,namespaceUri:s},chunkFD2KDBHX_cjs.g,m);if(!g)return {reason:`the payload cannot be addressed by an XPath: check nodeId (${m}) and payloadNamespace`};let l=r===r.trim()?`<label>${a(r)}</label>`:`<label xml:space="preserve">${a(r)}</label>`;return {binding:g,store:{itemPartName:e,itemXml:`<${chunkFD2KDBHX_cjs.g} xmlns="${a(s)}"><node id="${a(m)}">${l}<data>${a(o.data)}</data></node></${chunkFD2KDBHX_cjs.g}>`,propsPartName:u,propsXml:`<ds:datastoreItem ds:itemID="${a(c)}" xmlns:ds="${store.DATASTORE_NAMESPACE_URI}"><ds:schemaRefs><ds:schemaRef ds:uri="${a(s)}"/></ds:schemaRefs></ds:datastoreItem>`,storeItemId:c,relationships:[{from:"/word/document.xml",type:store.CUSTOM_XML_REL,target:`../customXml/item${String(d)}.xml`},{from:e,type:store.CUSTOM_XML_PROPS_REL,target:`itemProps${String(d)}.xml`}],contentTypeOverride:{partName:u,contentType:store.CUSTOM_XML_PROPS_TYPE}}}}Object.defineProperty(exports,"CUSTOM_NODE_STORE_ROOT",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.g}});Object.defineProperty(exports,"MAX_CUSTOM_NODE_DATA_LENGTH",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.d}});Object.defineProperty(exports,"MAX_TAG_LENGTH",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.a}});Object.defineProperty(exports,"customNodeNamespace",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.h}});Object.defineProperty(exports,"customNodesModule",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.m}});Object.defineProperty(exports,"decodeCustomNodeTag",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.c}});Object.defineProperty(exports,"defineCustomNode",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.l}});Object.defineProperty(exports,"encodeCustomNodeTag",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.b}});Object.defineProperty(exports,"insertCustomNode",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.p}});Object.defineProperty(exports,"isCustomNodeDefinition",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.j}});Object.defineProperty(exports,"parseCustomNodeData",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.e}});Object.defineProperty(exports,"recognizeCustomNodes",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.n}});Object.defineProperty(exports,"removeCustomNode",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.q}});Object.defineProperty(exports,"reviewModule",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.o}});Object.defineProperty(exports,"serializeCustomNodeData",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.f}});Object.defineProperty(exports,"updateCustomNode",{enumerable:true,get:function(){return chunkFD2KDBHX_cjs.r}});Object.defineProperty(exports,"collaborationModule",{enumerable:true,get:function(){return chunkQLZH2Q2C_cjs.b}});exports.customNodeXml=K;exports.customNodesOf=U;exports.prepareForExport=E;exports.saveForExport=G;
1
+ 'use strict';var chunkI6HVINA4_cjs=require('./chunk-I6HVINA4.cjs'),chunkQLZH2Q2C_cjs=require('./chunk-QLZH2Q2C.cjs'),store=require('@docx-editor.dev/core/store');function U(t,n={}){let r=L(t);if(!r)return [];let o=n.nodes??t.getCustomNodeDefinitions().filter(chunkI6HVINA4_cjs.j);if(o.length===0)return [];let s=r.session.currentPackage(),d=r.session.part().name,m=n.onDiagnostic??(e=>{t.reportCustomNodeDiagnostic(e);});return r.session.storyParts().flatMap(e=>chunkI6HVINA4_cjs.n(e,o,{payloads:store.customNodePayloadsByControl(s,e.name,d),onDiagnostic:m}))}function L(t){return t.surface??null}function E(t,n,r={}){if(r.destination==="internal")return {ok:true,bytes:t,unwrapped:0,removed:0};let o=store.readOoxmlPackage(t);if(!o.ok)return {ok:false,reason:`the document could not be read: ${o.reason}`};let s=new Map;for(let i of n)s.set(`${i.tagPrefix}:${i.name}`,i);let d=i=>{let p=chunkI6HVINA4_cjs.c(i);if(!p)return "keep";let x=s.get(`${p.prefix}:${p.name}`);return x?x.preserveOnExport==="text"?"text":x.preserveOnExport===false?"remove":"keep":"keep"},m=[...new Set(n.filter(i=>i.preserveOnExport!==void 0).filter(i=>i.preserveOnExport!==true).map(chunkI6HVINA4_cjs.h))],e=o.package,u=0,c=0,g=V(e);for(let i of g){let p=store.withExportedCustomNodes(e,{storyPartName:i,namespaces:[],decide:d});if(!p.ok)return {ok:false,reason:p.reason};e=p.pkg,u+=p.unwrapped,c+=p.removed;}let l=store.withExportedCustomNodes(e,{storyPartName:e.mainDocumentPart,namespaces:m,decide:()=>"keep"});return l.ok?(e=l.pkg,{ok:true,bytes:store.writeOoxmlPackage(e),unwrapped:u,removed:c}):{ok:false,reason:l.reason}}function V(t){let n=[];for(let[r,o]of t.parts)r!==t.mainDocumentPart&&store.isStoryPart(o)&&n.push(r);return [t.mainDocumentPart,...n]}async function G(t,n={}){let r=n.nodes??t.getCustomNodeDefinitions().filter(chunkI6HVINA4_cjs.j),o=await t.save();return E(new Uint8Array(o),r,{...n.destination===void 0?{}:{destination:n.destination}})}function a(t){return t.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g,"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function K(t,n,r,o={}){if(!chunkI6HVINA4_cjs.k.test(t.tagPrefix)||!chunkI6HVINA4_cjs.k.test(t.name))return {ok:false,code:"invalidArgs",reason:"the definition identity must match defineCustomNode\u2019s charset ([A-Za-z0-9_.-])"};let s=chunkI6HVINA4_cjs.b(t.tagPrefix,t.name,n);if(!s.ok)return {ok:false,code:"invalidArgs",reason:`the encoded tag is ${s.length} characters; Word caps w:tag at 64 \u2014 shorten the attrs`};let d=o.lock===void 0?"contentLocked":o.lock,m=o.id!==void 0&&Number.isInteger(o.id)&&o.id>0?o.id:store.fnv1a32(`${s.tag}\0${r}`)&2147483647||1,e=o.data===void 0?null:Q(t,o,r);if(e&&"reason"in e)return {ok:false,code:"invalidArgs",reason:e.reason};let u=(o.alias!==void 0?`<w:alias w:val="${a(o.alias)}"/>`:"")+`<w:tag w:val="${a(s.tag)}"/><w:id w:val="${m}"/>`+(d===false?"":`<w:lock w:val="${d}"/>`)+(e?`<w:dataBinding w:prefixMappings="${a(e.binding.prefixMappings)}" w:xpath="${a(e.binding.xpath)}" w:storeItemID="${a(e.binding.storeItemId)}"/>`:""),c=`<w:r><w:t xml:space="preserve">${a(r)}</w:t></w:r>`;return {ok:true,xml:`<w:sdt><w:sdtPr>${u}</w:sdtPr><w:sdtContent>${c}</w:sdtContent></w:sdt>`,...e?{store:e.store}:{}}}function Q(t,n,r){let o=chunkI6HVINA4_cjs.i(t,n.data);if(!o.ok)return {reason:o.reason};let s=chunkI6HVINA4_cjs.h(t),d=n.storeIndex!==void 0&&Number.isInteger(n.storeIndex)&&n.storeIndex>0?n.storeIndex:1,m=n.nodeId??"cx1",e=`/customXml/item${String(d)}.xml`,u=`/customXml/itemProps${String(d)}.xml`,c=store.datastoreItemIdFor(`${s} ${e} ${m}`),g=store.customNodeBinding({partName:e,propsPartName:u,itemId:c,namespaceUri:s},chunkI6HVINA4_cjs.g,m);if(!g)return {reason:`the payload cannot be addressed by an XPath: check nodeId (${m}) and payloadNamespace`};let l=r===r.trim()?`<label>${a(r)}</label>`:`<label xml:space="preserve">${a(r)}</label>`;return {binding:g,store:{itemPartName:e,itemXml:`<${chunkI6HVINA4_cjs.g} xmlns="${a(s)}"><node id="${a(m)}">${l}<data>${a(o.data)}</data></node></${chunkI6HVINA4_cjs.g}>`,propsPartName:u,propsXml:`<ds:datastoreItem ds:itemID="${a(c)}" xmlns:ds="${store.DATASTORE_NAMESPACE_URI}"><ds:schemaRefs><ds:schemaRef ds:uri="${a(s)}"/></ds:schemaRefs></ds:datastoreItem>`,storeItemId:c,relationships:[{from:"/word/document.xml",type:store.CUSTOM_XML_REL,target:`../customXml/item${String(d)}.xml`},{from:e,type:store.CUSTOM_XML_PROPS_REL,target:`itemProps${String(d)}.xml`}],contentTypeOverride:{partName:u,contentType:store.CUSTOM_XML_PROPS_TYPE}}}}Object.defineProperty(exports,"CUSTOM_NODE_STORE_ROOT",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.g}});Object.defineProperty(exports,"MAX_CUSTOM_NODE_DATA_LENGTH",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.d}});Object.defineProperty(exports,"MAX_TAG_LENGTH",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.a}});Object.defineProperty(exports,"customNodeNamespace",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.h}});Object.defineProperty(exports,"customNodesModule",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.m}});Object.defineProperty(exports,"decodeCustomNodeTag",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.c}});Object.defineProperty(exports,"defineCustomNode",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.l}});Object.defineProperty(exports,"encodeCustomNodeTag",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.b}});Object.defineProperty(exports,"insertCustomNode",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.p}});Object.defineProperty(exports,"isCustomNodeDefinition",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.j}});Object.defineProperty(exports,"parseCustomNodeData",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.e}});Object.defineProperty(exports,"recognizeCustomNodes",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.n}});Object.defineProperty(exports,"removeCustomNode",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.q}});Object.defineProperty(exports,"reviewModule",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.o}});Object.defineProperty(exports,"serializeCustomNodeData",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.f}});Object.defineProperty(exports,"updateCustomNode",{enumerable:true,get:function(){return chunkI6HVINA4_cjs.r}});Object.defineProperty(exports,"collaborationModule",{enumerable:true,get:function(){return chunkQLZH2Q2C_cjs.b}});exports.customNodeXml=K;exports.customNodesOf=U;exports.prepareForExport=E;exports.saveForExport=G;
package/dist/index.d.cts CHANGED
@@ -316,7 +316,8 @@ interface CustomNodeInput<Schema extends StandardSchemaV1 | undefined = any> {
316
316
  /**
317
317
  * The `w:lock` written on the control. Defaults to `contentLocked` — the text is locked so the
318
318
  * label cannot drift out of sync with the attrs by inline typing, while the node itself stays
319
- * DELETABLE as one unit, in the editor and in Word alike. `false` writes no lock;
319
+ * DELETABLE as one unit: the first Backspace or Delete beside it selects it, a second removes it.
320
+ * `false` writes no lock;
320
321
  * `sdtContentLocked` also forbids deleting the node.
321
322
  *
322
323
  * A node carrying a payload is uneditable whatever this says: the engine refuses content edits
package/dist/index.d.ts CHANGED
@@ -316,7 +316,8 @@ interface CustomNodeInput<Schema extends StandardSchemaV1 | undefined = any> {
316
316
  /**
317
317
  * The `w:lock` written on the control. Defaults to `contentLocked` — the text is locked so the
318
318
  * label cannot drift out of sync with the attrs by inline typing, while the node itself stays
319
- * DELETABLE as one unit, in the editor and in Word alike. `false` writes no lock;
319
+ * DELETABLE as one unit: the first Backspace or Delete beside it selects it, a second removes it.
320
+ * `false` writes no lock;
320
321
  * `sdtContentLocked` also forbids deleting the node.
321
322
  *
322
323
  * A node carrying a payload is uneditable whatever this says: the engine refuses content edits
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import {j,n,h,k,b,i,g,c}from'./chunk-Q5JTCGJI.js';export{g as CUSTOM_NODE_STORE_ROOT,d as MAX_CUSTOM_NODE_DATA_LENGTH,a as MAX_TAG_LENGTH,h as customNodeNamespace,m as customNodesModule,c as decodeCustomNodeTag,l as defineCustomNode,b as encodeCustomNodeTag,p as insertCustomNode,j as isCustomNodeDefinition,e as parseCustomNodeData,n as recognizeCustomNodes,q as removeCustomNode,o as reviewModule,f as serializeCustomNodeData,r as updateCustomNode}from'./chunk-Q5JTCGJI.js';export{b as collaborationModule}from'./chunk-Q2VBO66F.js';import {customNodePayloadsByControl,readOoxmlPackage,withExportedCustomNodes,writeOoxmlPackage,isStoryPart,fnv1a32,datastoreItemIdFor,customNodeBinding,CUSTOM_XML_PROPS_TYPE,CUSTOM_XML_REL,CUSTOM_XML_PROPS_REL,DATASTORE_NAMESPACE_URI}from'@docx-editor.dev/core/store';function U(t,n$1={}){let r=L(t);if(!r)return [];let o=n$1.nodes??t.getCustomNodeDefinitions().filter(j);if(o.length===0)return [];let s=r.session.currentPackage(),d=r.session.part().name,m=n$1.onDiagnostic??(e=>{t.reportCustomNodeDiagnostic(e);});return r.session.storyParts().flatMap(e=>n(e,o,{payloads:customNodePayloadsByControl(s,e.name,d),onDiagnostic:m}))}function L(t){return t.surface??null}function E(t,n,r={}){if(r.destination==="internal")return {ok:true,bytes:t,unwrapped:0,removed:0};let o=readOoxmlPackage(t);if(!o.ok)return {ok:false,reason:`the document could not be read: ${o.reason}`};let s=new Map;for(let i of n)s.set(`${i.tagPrefix}:${i.name}`,i);let d=i=>{let p=c(i);if(!p)return "keep";let x=s.get(`${p.prefix}:${p.name}`);return x?x.preserveOnExport==="text"?"text":x.preserveOnExport===false?"remove":"keep":"keep"},m=[...new Set(n.filter(i=>i.preserveOnExport!==void 0).filter(i=>i.preserveOnExport!==true).map(h))],e=o.package,u=0,c$1=0,g=V(e);for(let i of g){let p=withExportedCustomNodes(e,{storyPartName:i,namespaces:[],decide:d});if(!p.ok)return {ok:false,reason:p.reason};e=p.pkg,u+=p.unwrapped,c$1+=p.removed;}let l=withExportedCustomNodes(e,{storyPartName:e.mainDocumentPart,namespaces:m,decide:()=>"keep"});return l.ok?(e=l.pkg,{ok:true,bytes:writeOoxmlPackage(e),unwrapped:u,removed:c$1}):{ok:false,reason:l.reason}}function V(t){let n=[];for(let[r,o]of t.parts)r!==t.mainDocumentPart&&isStoryPart(o)&&n.push(r);return [t.mainDocumentPart,...n]}async function G(t,n={}){let r=n.nodes??t.getCustomNodeDefinitions().filter(j),o=await t.save();return E(new Uint8Array(o),r,{...n.destination===void 0?{}:{destination:n.destination}})}function a(t){return t.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g,"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function K(t,n,r,o={}){if(!k.test(t.tagPrefix)||!k.test(t.name))return {ok:false,code:"invalidArgs",reason:"the definition identity must match defineCustomNode\u2019s charset ([A-Za-z0-9_.-])"};let s=b(t.tagPrefix,t.name,n);if(!s.ok)return {ok:false,code:"invalidArgs",reason:`the encoded tag is ${s.length} characters; Word caps w:tag at 64 \u2014 shorten the attrs`};let d=o.lock===void 0?"contentLocked":o.lock,m=o.id!==void 0&&Number.isInteger(o.id)&&o.id>0?o.id:fnv1a32(`${s.tag}\0${r}`)&2147483647||1,e=o.data===void 0?null:Q(t,o,r);if(e&&"reason"in e)return {ok:false,code:"invalidArgs",reason:e.reason};let u=(o.alias!==void 0?`<w:alias w:val="${a(o.alias)}"/>`:"")+`<w:tag w:val="${a(s.tag)}"/><w:id w:val="${m}"/>`+(d===false?"":`<w:lock w:val="${d}"/>`)+(e?`<w:dataBinding w:prefixMappings="${a(e.binding.prefixMappings)}" w:xpath="${a(e.binding.xpath)}" w:storeItemID="${a(e.binding.storeItemId)}"/>`:""),c=`<w:r><w:t xml:space="preserve">${a(r)}</w:t></w:r>`;return {ok:true,xml:`<w:sdt><w:sdtPr>${u}</w:sdtPr><w:sdtContent>${c}</w:sdtContent></w:sdt>`,...e?{store:e.store}:{}}}function Q(t,n,r){let o=i(t,n.data);if(!o.ok)return {reason:o.reason};let s=h(t),d=n.storeIndex!==void 0&&Number.isInteger(n.storeIndex)&&n.storeIndex>0?n.storeIndex:1,m=n.nodeId??"cx1",e=`/customXml/item${String(d)}.xml`,u=`/customXml/itemProps${String(d)}.xml`,c=datastoreItemIdFor(`${s} ${e} ${m}`),g$1=customNodeBinding({partName:e,propsPartName:u,itemId:c,namespaceUri:s},g,m);if(!g$1)return {reason:`the payload cannot be addressed by an XPath: check nodeId (${m}) and payloadNamespace`};let l=r===r.trim()?`<label>${a(r)}</label>`:`<label xml:space="preserve">${a(r)}</label>`;return {binding:g$1,store:{itemPartName:e,itemXml:`<${g} xmlns="${a(s)}"><node id="${a(m)}">${l}<data>${a(o.data)}</data></node></${g}>`,propsPartName:u,propsXml:`<ds:datastoreItem ds:itemID="${a(c)}" xmlns:ds="${DATASTORE_NAMESPACE_URI}"><ds:schemaRefs><ds:schemaRef ds:uri="${a(s)}"/></ds:schemaRefs></ds:datastoreItem>`,storeItemId:c,relationships:[{from:"/word/document.xml",type:CUSTOM_XML_REL,target:`../customXml/item${String(d)}.xml`},{from:e,type:CUSTOM_XML_PROPS_REL,target:`itemProps${String(d)}.xml`}],contentTypeOverride:{partName:u,contentType:CUSTOM_XML_PROPS_TYPE}}}}export{K as customNodeXml,U as customNodesOf,E as prepareForExport,G as saveForExport};
1
+ import {j,n,h,k,b,i,g,c}from'./chunk-AVZO5ZHZ.js';export{g as CUSTOM_NODE_STORE_ROOT,d as MAX_CUSTOM_NODE_DATA_LENGTH,a as MAX_TAG_LENGTH,h as customNodeNamespace,m as customNodesModule,c as decodeCustomNodeTag,l as defineCustomNode,b as encodeCustomNodeTag,p as insertCustomNode,j as isCustomNodeDefinition,e as parseCustomNodeData,n as recognizeCustomNodes,q as removeCustomNode,o as reviewModule,f as serializeCustomNodeData,r as updateCustomNode}from'./chunk-AVZO5ZHZ.js';export{b as collaborationModule}from'./chunk-Q2VBO66F.js';import {customNodePayloadsByControl,readOoxmlPackage,withExportedCustomNodes,writeOoxmlPackage,isStoryPart,fnv1a32,datastoreItemIdFor,customNodeBinding,CUSTOM_XML_PROPS_TYPE,CUSTOM_XML_REL,CUSTOM_XML_PROPS_REL,DATASTORE_NAMESPACE_URI}from'@docx-editor.dev/core/store';function U(t,n$1={}){let r=L(t);if(!r)return [];let o=n$1.nodes??t.getCustomNodeDefinitions().filter(j);if(o.length===0)return [];let s=r.session.currentPackage(),d=r.session.part().name,m=n$1.onDiagnostic??(e=>{t.reportCustomNodeDiagnostic(e);});return r.session.storyParts().flatMap(e=>n(e,o,{payloads:customNodePayloadsByControl(s,e.name,d),onDiagnostic:m}))}function L(t){return t.surface??null}function E(t,n,r={}){if(r.destination==="internal")return {ok:true,bytes:t,unwrapped:0,removed:0};let o=readOoxmlPackage(t);if(!o.ok)return {ok:false,reason:`the document could not be read: ${o.reason}`};let s=new Map;for(let i of n)s.set(`${i.tagPrefix}:${i.name}`,i);let d=i=>{let p=c(i);if(!p)return "keep";let x=s.get(`${p.prefix}:${p.name}`);return x?x.preserveOnExport==="text"?"text":x.preserveOnExport===false?"remove":"keep":"keep"},m=[...new Set(n.filter(i=>i.preserveOnExport!==void 0).filter(i=>i.preserveOnExport!==true).map(h))],e=o.package,u=0,c$1=0,g=V(e);for(let i of g){let p=withExportedCustomNodes(e,{storyPartName:i,namespaces:[],decide:d});if(!p.ok)return {ok:false,reason:p.reason};e=p.pkg,u+=p.unwrapped,c$1+=p.removed;}let l=withExportedCustomNodes(e,{storyPartName:e.mainDocumentPart,namespaces:m,decide:()=>"keep"});return l.ok?(e=l.pkg,{ok:true,bytes:writeOoxmlPackage(e),unwrapped:u,removed:c$1}):{ok:false,reason:l.reason}}function V(t){let n=[];for(let[r,o]of t.parts)r!==t.mainDocumentPart&&isStoryPart(o)&&n.push(r);return [t.mainDocumentPart,...n]}async function G(t,n={}){let r=n.nodes??t.getCustomNodeDefinitions().filter(j),o=await t.save();return E(new Uint8Array(o),r,{...n.destination===void 0?{}:{destination:n.destination}})}function a(t){return t.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g,"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function K(t,n,r,o={}){if(!k.test(t.tagPrefix)||!k.test(t.name))return {ok:false,code:"invalidArgs",reason:"the definition identity must match defineCustomNode\u2019s charset ([A-Za-z0-9_.-])"};let s=b(t.tagPrefix,t.name,n);if(!s.ok)return {ok:false,code:"invalidArgs",reason:`the encoded tag is ${s.length} characters; Word caps w:tag at 64 \u2014 shorten the attrs`};let d=o.lock===void 0?"contentLocked":o.lock,m=o.id!==void 0&&Number.isInteger(o.id)&&o.id>0?o.id:fnv1a32(`${s.tag}\0${r}`)&2147483647||1,e=o.data===void 0?null:Q(t,o,r);if(e&&"reason"in e)return {ok:false,code:"invalidArgs",reason:e.reason};let u=(o.alias!==void 0?`<w:alias w:val="${a(o.alias)}"/>`:"")+`<w:tag w:val="${a(s.tag)}"/><w:id w:val="${m}"/>`+(d===false?"":`<w:lock w:val="${d}"/>`)+(e?`<w:dataBinding w:prefixMappings="${a(e.binding.prefixMappings)}" w:xpath="${a(e.binding.xpath)}" w:storeItemID="${a(e.binding.storeItemId)}"/>`:""),c=`<w:r><w:t xml:space="preserve">${a(r)}</w:t></w:r>`;return {ok:true,xml:`<w:sdt><w:sdtPr>${u}</w:sdtPr><w:sdtContent>${c}</w:sdtContent></w:sdt>`,...e?{store:e.store}:{}}}function Q(t,n,r){let o=i(t,n.data);if(!o.ok)return {reason:o.reason};let s=h(t),d=n.storeIndex!==void 0&&Number.isInteger(n.storeIndex)&&n.storeIndex>0?n.storeIndex:1,m=n.nodeId??"cx1",e=`/customXml/item${String(d)}.xml`,u=`/customXml/itemProps${String(d)}.xml`,c=datastoreItemIdFor(`${s} ${e} ${m}`),g$1=customNodeBinding({partName:e,propsPartName:u,itemId:c,namespaceUri:s},g,m);if(!g$1)return {reason:`the payload cannot be addressed by an XPath: check nodeId (${m}) and payloadNamespace`};let l=r===r.trim()?`<label>${a(r)}</label>`:`<label xml:space="preserve">${a(r)}</label>`;return {binding:g$1,store:{itemPartName:e,itemXml:`<${g} xmlns="${a(s)}"><node id="${a(m)}">${l}<data>${a(o.data)}</data></node></${g}>`,propsPartName:u,propsXml:`<ds:datastoreItem ds:itemID="${a(c)}" xmlns:ds="${DATASTORE_NAMESPACE_URI}"><ds:schemaRefs><ds:schemaRef ds:uri="${a(s)}"/></ds:schemaRefs></ds:datastoreItem>`,storeItemId:c,relationships:[{from:"/word/document.xml",type:CUSTOM_XML_REL,target:`../customXml/item${String(d)}.xml`},{from:e,type:CUSTOM_XML_PROPS_REL,target:`itemProps${String(d)}.xml`}],contentTypeOverride:{partName:u,contentType:CUSTOM_XML_PROPS_TYPE}}}}export{K as customNodeXml,U as customNodesOf,E as prepareForExport,G as saveForExport};
@@ -11,8 +11,8 @@ import * as Y from 'yjs';
11
11
  import { HocuspocusProvider } from '@hocuspocus/provider';
12
12
  import { CollaborationIdentity, CollaborationFailure } from '@docx-editor.dev/core/collaboration';
13
13
  import { EditorModule } from '@docx-editor.dev/core/editor';
14
- import { a as CollaborationBootstrap, C as CollaborationSession } from '../types-BQ1vBt5Q.cjs';
15
- export { b as CollaborationIdentityUpdate } from '../types-BQ1vBt5Q.cjs';
14
+ import { a as CollaborationBootstrap, C as CollaborationSession } from '../types-DvGpDOcZ.cjs';
15
+ export { b as CollaborationIdentityUpdate } from '../types-DvGpDOcZ.cjs';
16
16
 
17
17
  /** Bootstrap for one Hocuspocus room. @public */
18
18
  type UseHocuspocusCollaborationBootstrap = CollaborationBootstrap;
@@ -11,8 +11,8 @@ import * as Y from 'yjs';
11
11
  import { HocuspocusProvider } from '@hocuspocus/provider';
12
12
  import { CollaborationIdentity, CollaborationFailure } from '@docx-editor.dev/core/collaboration';
13
13
  import { EditorModule } from '@docx-editor.dev/core/editor';
14
- import { a as CollaborationBootstrap, C as CollaborationSession } from '../types-BQ1vBt5Q.js';
15
- export { b as CollaborationIdentityUpdate } from '../types-BQ1vBt5Q.js';
14
+ import { a as CollaborationBootstrap, C as CollaborationSession } from '../types-DvGpDOcZ.js';
15
+ export { b as CollaborationIdentityUpdate } from '../types-DvGpDOcZ.js';
16
16
 
17
17
  /** Bootstrap for one Hocuspocus room. @public */
18
18
  type UseHocuspocusCollaborationBootstrap = CollaborationBootstrap;