@docx-editor.dev/pro 2.26.0 → 2.28.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 (85) hide show
  1. package/dist/chunk-CNXDNDD3.js +1 -0
  2. package/dist/chunk-FD2KDBHX.cjs +1 -0
  3. package/dist/chunk-JRHEYVVY.cjs +1 -0
  4. package/dist/chunk-L567WP3J.js +5 -0
  5. package/dist/chunk-MJECUVHQ.cjs +5 -0
  6. package/dist/chunk-MWO2ZUEJ.js +1 -0
  7. package/dist/chunk-N34IUO36.cjs +1 -0
  8. package/dist/chunk-OT5R3IYV.cjs +1 -0
  9. package/dist/chunk-P2EF7WMV.js +1 -0
  10. package/dist/chunk-Q5JTCGJI.js +1 -0
  11. package/dist/chunk-SNQCYZLT.js +1 -0
  12. package/dist/chunk-ZSAAX6HV.cjs +1 -0
  13. package/dist/collaboration/hocuspocus.cjs +1 -1
  14. package/dist/collaboration/hocuspocus.d.cts +18 -11
  15. package/dist/collaboration/hocuspocus.d.ts +18 -11
  16. package/dist/collaboration/hocuspocus.js +1 -1
  17. package/dist/collaboration/index.cjs +2 -2
  18. package/dist/collaboration/index.d.cts +333 -18
  19. package/dist/collaboration/index.d.ts +333 -18
  20. package/dist/collaboration/index.js +2 -2
  21. package/dist/collaboration/webrtc.cjs +2 -2
  22. package/dist/collaboration/webrtc.d.cts +26 -3
  23. package/dist/collaboration/webrtc.d.ts +26 -3
  24. package/dist/collaboration/webrtc.js +2 -2
  25. package/dist/{collaboration-module-DlSv0oAd.d.cts → collaboration-module-DWn2heE1.d.cts} +1 -0
  26. package/dist/{collaboration-module-DlSv0oAd.d.ts → collaboration-module-DWn2heE1.d.ts} +1 -0
  27. package/dist/{define-custom-node-DA6UEXID.d.ts → define-custom-node-CNRQG1TI.d.cts} +14 -4
  28. package/dist/{define-custom-node-CkjSwcxy.d.cts → define-custom-node-D0c36PpZ.d.ts} +14 -4
  29. package/dist/document-session-3VC43WNI.cjs +1 -0
  30. package/dist/{document-session-BKKfJzKB.d.cts → document-session-Bxs4_GgX.d.ts} +55 -33
  31. package/dist/document-session-J2YKWERI.js +1 -0
  32. package/dist/{document-session-BQ4nBDTd.d.ts → document-session-_v9vqiSX.d.cts} +55 -33
  33. package/dist/document-session-options-CfKypp9c.d.cts +37 -0
  34. package/dist/document-session-options-DelOC7PX.d.ts +37 -0
  35. package/dist/index.cjs +1 -1
  36. package/dist/index.d.cts +29 -4
  37. package/dist/index.d.ts +29 -4
  38. package/dist/index.js +1 -1
  39. package/dist/react/hocuspocus.cjs +1 -1
  40. package/dist/react/hocuspocus.d.cts +52 -8
  41. package/dist/react/hocuspocus.d.ts +52 -8
  42. package/dist/react/hocuspocus.js +1 -1
  43. package/dist/react/index.cjs +2 -2
  44. package/dist/react/index.d.cts +354 -156
  45. package/dist/react/index.d.ts +354 -156
  46. package/dist/react/index.js +2 -2
  47. package/dist/react/webrtc.cjs +1 -1
  48. package/dist/react/webrtc.d.cts +35 -7
  49. package/dist/react/webrtc.d.ts +35 -7
  50. package/dist/react/webrtc.js +1 -1
  51. package/dist/{session-okdqygLg.d.cts → types-6EmrEn4n.d.cts} +26 -4
  52. package/dist/{session-okdqygLg.d.ts → types-6EmrEn4n.d.ts} +26 -4
  53. package/dist/{session-B-ds4k64.d.cts → types-BQ1vBt5Q.d.cts} +32 -54
  54. package/dist/{session-B-ds4k64.d.ts → types-BQ1vBt5Q.d.ts} +32 -54
  55. package/dist/vue/hocuspocus.cjs +1 -1
  56. package/dist/vue/hocuspocus.d.cts +52 -7
  57. package/dist/vue/hocuspocus.d.ts +52 -7
  58. package/dist/vue/hocuspocus.js +1 -1
  59. package/dist/vue/index.cjs +2 -2
  60. package/dist/vue/index.d.cts +237 -24
  61. package/dist/vue/index.d.ts +237 -24
  62. package/dist/vue/index.js +2 -2
  63. package/dist/vue/webrtc.cjs +1 -1
  64. package/dist/vue/webrtc.d.cts +36 -6
  65. package/dist/vue/webrtc.d.ts +36 -6
  66. package/dist/vue/webrtc.js +1 -1
  67. package/package.json +4 -4
  68. package/dist/chunk-3JW4VNG5.js +0 -4
  69. package/dist/chunk-GDTCNTK7.cjs +0 -1
  70. package/dist/chunk-HJB77VBO.js +0 -1
  71. package/dist/chunk-JDLJS5RD.cjs +0 -4
  72. package/dist/chunk-MRW46GJW.js +0 -4
  73. package/dist/chunk-OMUXC73J.cjs +0 -1
  74. package/dist/chunk-PQNLQ2P2.js +0 -1
  75. package/dist/chunk-Q4YPX2DT.cjs +0 -1
  76. package/dist/chunk-VCMQFPO2.cjs +0 -4
  77. package/dist/chunk-W3V54DWZ.js +0 -1
  78. package/dist/document-session-6X24KXAM.js +0 -1
  79. package/dist/document-session-BDVKTCYX.js +0 -1
  80. package/dist/document-session-NECF3VT6.cjs +0 -1
  81. package/dist/document-session-RKQQLHEL.cjs +0 -1
  82. package/dist/hocuspocus-BCQPTL3M.cjs +0 -1
  83. package/dist/hocuspocus-QIIKEK6J.js +0 -1
  84. package/dist/webrtc-54VKWBFN.js +0 -2
  85. package/dist/webrtc-TIHZFB4K.cjs +0 -2
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import {j,n,h,k,b,i,g,c}from'./chunk-PQNLQ2P2.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-PQNLQ2P2.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-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 +1 @@
1
- 'use strict';var chunkGDTCNTK7_cjs=require('../chunk-GDTCNTK7.cjs');require('../chunk-QLZH2Q2C.cjs');var react=require('react');var i=Symbol("useHocuspocusCollaboration.createRoom");function u(o){return o?`${o.url}:${o.roomId}:${o.bootstrap.kind}:${o.identity.actorId}`:""}async function c(o){let{createHocuspocusCollaboration:n}=await import('../collaboration/hocuspocus.cjs');return n(o)}function p(o){return o[i]??c}function d(o={}){let n=react.useId(),e=chunkGDTCNTK7_cjs.b({ownerKey:`react-hocuspocus:${n}`,hookName:"useHocuspocusCollaboration",createRoom:p(o),hostModules:o.modules??chunkGDTCNTK7_cjs.a,autoRoom:o.room??null,autoKey:u(o.room??null),rejoinOptionsOf:t=>({...t,bootstrap:{kind:"join"}}),identityOf:t=>t.identity});return react.useMemo(()=>({document:e.document,modules:e.modules,session:e.session,ydoc:e.room?.ydoc??null,provider:e.room?.provider??null,pending:e.pending,error:e.error,connect:e.connect,leave:e.leave,rejoin:e.rejoin}),[e])}exports.useHocuspocusCollaboration=d;
1
+ 'use strict';var chunkOT5R3IYV_cjs=require('../chunk-OT5R3IYV.cjs');require('../chunk-QLZH2Q2C.cjs');var react=require('react');var y=Symbol("useHocuspocusCollaboration.createRoom");function C(o){return o?`${o.url}:${o.roomId}:${o.bootstrap.kind}:${o.identity.actorId}`:""}async function m(o){let{createHocuspocusCollaboration:t}=await import('../collaboration/hocuspocus.cjs');return t(o)}function b(o){return o[y]??m}function H(o={}){let t=react.useId(),e=chunkOT5R3IYV_cjs.b({ownerKey:`react-hocuspocus:${t}`,hookName:"useHocuspocusCollaboration",createRoom:b(o),hostModules:o.modules??chunkOT5R3IYV_cjs.a,autoRoom:o.room??null,autoKey:C(o.room??null),rejoinOptionsOf:n=>({...n,bootstrap:{kind:"join"}}),identityOf:n=>n.identity}),r=e.room?.provider??null,i=react.useCallback(n=>r?(r.on("unsyncedChanges",n),()=>{r.off("unsyncedChanges",n);}):()=>{},[r]),s=react.useSyncExternalStore(i,()=>r?.unsyncedChanges??0,()=>0);return react.useMemo(()=>({document:e.document,modules:e.modules,session:e.session,ydoc:e.room?.ydoc??null,provider:e.room?.provider??null,pending:e.pending,unsyncedChanges:s,error:e.error,connect:e.connect,leave:e.leave,rejoin:e.rejoin}),[e,s])}exports.useHocuspocusCollaboration=H;
@@ -1,10 +1,18 @@
1
+ /**
2
+ * `@docx-editor.dev/pro/react/hocuspocus` — React hook that owns a Hocuspocus room.
3
+ *
4
+ * Import this subpath only when you use Hocuspocus. `@docx-editor.dev/pro/react`
5
+ * does not load a network provider.
6
+ *
7
+ * @packageDocumentation
8
+ * @public
9
+ */
1
10
  import * as Y from 'yjs';
2
11
  import { HocuspocusProvider } from '@hocuspocus/provider';
3
12
  import { CollaborationIdentity, CollaborationFailure } from '@docx-editor.dev/core/collaboration';
4
13
  import { EditorModule } from '@docx-editor.dev/core/editor';
5
- import { a as CollaborationBootstrap, C as CollaborationSession } from '../session-B-ds4k64.cjs';
6
- export { b as CollaborationIdentityUpdate } from '../session-B-ds4k64.cjs';
7
- import 'y-protocols/awareness';
14
+ import { a as CollaborationBootstrap, C as CollaborationSession } from '../types-BQ1vBt5Q.cjs';
15
+ export { b as CollaborationIdentityUpdate } from '../types-BQ1vBt5Q.cjs';
8
16
 
9
17
  /** Bootstrap for one Hocuspocus room. @public */
10
18
  type UseHocuspocusCollaborationBootstrap = CollaborationBootstrap;
@@ -12,19 +20,23 @@ type UseHocuspocusCollaborationBootstrap = CollaborationBootstrap;
12
20
  interface UseHocuspocusCollaborationConnectOptions {
13
21
  /** Hocuspocus server WebSocket URL, for example `wss://collab.example.test`. */
14
22
  readonly url: string;
23
+ /** Room name on the server, also the document id. Make one with `createCollaborationRoomId`. */
15
24
  readonly roomId: string;
16
25
  /**
17
26
  * Authentication token the provider sends in its auth handshake. Pass a callback and the
18
27
  * provider re-evaluates it on every reconnect, which is how expiring JWTs renew.
19
28
  */
20
29
  readonly token?: string | (() => string | Promise<string>);
30
+ /** The local participant. Recorded as the author of this replica's changes. */
21
31
  readonly identity: CollaborationIdentity;
32
+ /** Whether to seed the room, join it, or let the peers decide. */
22
33
  readonly bootstrap: UseHocuspocusCollaborationBootstrap;
23
34
  /** Bound on the wait for the server's initial sync. Default 30000 ms. */
24
35
  readonly syncedTimeoutMs?: number;
25
36
  /**
26
37
  * Admit local edits while the transport is `disconnected`. Buffered updates merge on
27
- * reconnect. See {@link CreateDocumentCollaborationOptions.offlineEditing}.
38
+ * reconnect. On by default; pass `false` to pause editing while disconnected. See
39
+ * {@link CreateDocumentCollaborationOptions.offlineEditing}.
28
40
  */
29
41
  readonly offlineEditing?: boolean;
30
42
  }
@@ -38,13 +50,18 @@ interface UseHocuspocusCollaborationOptions {
38
50
  /**
39
51
  * Connect this room on mount. Omit it and call
40
52
  * {@link UseHocuspocusCollaborationReturn.connect} after the user chooses a room.
53
+ * A different room, server, bootstrap kind, or `actorId` leaves the old room and
54
+ * connects the new one, and `null` leaves. A room opened with `connect` stays.
41
55
  */
42
56
  readonly room?: UseHocuspocusCollaborationConnectOptions | null;
43
57
  }
44
58
  /** Values {@link useHocuspocusCollaboration} returns. @public */
45
59
  interface UseHocuspocusCollaborationReturn {
60
+ /** The room's document as `.docx` bytes to mount. Null until the room is ready. */
46
61
  readonly document: Uint8Array | null;
62
+ /** Modules to pass to the editor. They include the collaboration module once ready. */
47
63
  readonly modules: readonly EditorModule[];
64
+ /** The live session for status and presence. Null while no room is connected. */
48
65
  readonly session: CollaborationSession | null;
49
66
  /**
50
67
  * The room's shared Yjs document, owned by the hook. Null while no room is connected.
@@ -60,7 +77,25 @@ interface UseHocuspocusCollaborationReturn {
60
77
  * server events). The hook destroys it on leave and unmount.
61
78
  */
62
79
  readonly provider: HocuspocusProvider | null;
80
+ /** True while a connect is in progress. */
63
81
  readonly pending: boolean;
82
+ /**
83
+ * Local changes the server has not confirmed yet. More than zero while edits made offline
84
+ * wait for the connection, and for a moment after each edit while online. Warn before the
85
+ * page closes while it is above zero, or those edits are lost:
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * useEffect(() => {
90
+ * if (unsyncedChanges === 0) return;
91
+ * const warn = (event: BeforeUnloadEvent) => event.preventDefault();
92
+ * window.addEventListener('beforeunload', warn);
93
+ * return () => window.removeEventListener('beforeunload', warn);
94
+ * }, [unsyncedChanges]);
95
+ * ```
96
+ */
97
+ readonly unsyncedChanges: number;
98
+ /** The connect failure or session failure, or null. Check it before `document`. */
64
99
  readonly error: CollaborationFailure | null;
65
100
  /**
66
101
  * Connect a room. RESOLVES with the failure, or null on success — it does not reject.
@@ -74,8 +109,8 @@ interface UseHocuspocusCollaborationReturn {
74
109
  * Destroy the room and carry on editing locally.
75
110
  *
76
111
  * The current bytes live in the editor, not in this hook, so the argument is required:
77
- * pass `await editor.save()` to keep what the room typed. The hook remounts the editor
78
- * from exactly these bytes.
112
+ * pass the bytes `editor.save()` resolves with, as `new Uint8Array(saved)` after a `null`
113
+ * check, to keep what the room typed. The hook remounts the editor from exactly these bytes.
79
114
  */
80
115
  readonly leave: (nextDocument: Uint8Array) => void;
81
116
  /**
@@ -83,10 +118,19 @@ interface UseHocuspocusCollaborationReturn {
83
118
  * again to the same room with the same identity, url, and token.
84
119
  *
85
120
  * The reconnect always uses bootstrap `{ kind: 'join' }`, because the server still holds
86
- * the room. When the server no longer holds it, the join rejects with
121
+ * the room. When the server no longer holds it, the rejoin resolves with
87
122
  * `initialization-timeout` — nothing is lost, because `nextDocument` (your saved bytes)
88
123
  * stays mounted locally. A connect that failed also counts as the prior attempt, so
89
- * rejoin retries it as a joiner.
124
+ * rejoin retries it as a joiner. Resolves with the failure, or `null` on success.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * const saved = await editorRef.current?.save();
129
+ * if (saved) {
130
+ * const failure = await rejoin(new Uint8Array(saved));
131
+ * if (failure) console.warn(failure.code);
132
+ * }
133
+ * ```
90
134
  */
91
135
  readonly rejoin: (nextDocument: Uint8Array) => Promise<CollaborationFailure | null>;
92
136
  }
@@ -1,10 +1,18 @@
1
+ /**
2
+ * `@docx-editor.dev/pro/react/hocuspocus` — React hook that owns a Hocuspocus room.
3
+ *
4
+ * Import this subpath only when you use Hocuspocus. `@docx-editor.dev/pro/react`
5
+ * does not load a network provider.
6
+ *
7
+ * @packageDocumentation
8
+ * @public
9
+ */
1
10
  import * as Y from 'yjs';
2
11
  import { HocuspocusProvider } from '@hocuspocus/provider';
3
12
  import { CollaborationIdentity, CollaborationFailure } from '@docx-editor.dev/core/collaboration';
4
13
  import { EditorModule } from '@docx-editor.dev/core/editor';
5
- import { a as CollaborationBootstrap, C as CollaborationSession } from '../session-B-ds4k64.js';
6
- export { b as CollaborationIdentityUpdate } from '../session-B-ds4k64.js';
7
- import 'y-protocols/awareness';
14
+ import { a as CollaborationBootstrap, C as CollaborationSession } from '../types-BQ1vBt5Q.js';
15
+ export { b as CollaborationIdentityUpdate } from '../types-BQ1vBt5Q.js';
8
16
 
9
17
  /** Bootstrap for one Hocuspocus room. @public */
10
18
  type UseHocuspocusCollaborationBootstrap = CollaborationBootstrap;
@@ -12,19 +20,23 @@ type UseHocuspocusCollaborationBootstrap = CollaborationBootstrap;
12
20
  interface UseHocuspocusCollaborationConnectOptions {
13
21
  /** Hocuspocus server WebSocket URL, for example `wss://collab.example.test`. */
14
22
  readonly url: string;
23
+ /** Room name on the server, also the document id. Make one with `createCollaborationRoomId`. */
15
24
  readonly roomId: string;
16
25
  /**
17
26
  * Authentication token the provider sends in its auth handshake. Pass a callback and the
18
27
  * provider re-evaluates it on every reconnect, which is how expiring JWTs renew.
19
28
  */
20
29
  readonly token?: string | (() => string | Promise<string>);
30
+ /** The local participant. Recorded as the author of this replica's changes. */
21
31
  readonly identity: CollaborationIdentity;
32
+ /** Whether to seed the room, join it, or let the peers decide. */
22
33
  readonly bootstrap: UseHocuspocusCollaborationBootstrap;
23
34
  /** Bound on the wait for the server's initial sync. Default 30000 ms. */
24
35
  readonly syncedTimeoutMs?: number;
25
36
  /**
26
37
  * Admit local edits while the transport is `disconnected`. Buffered updates merge on
27
- * reconnect. See {@link CreateDocumentCollaborationOptions.offlineEditing}.
38
+ * reconnect. On by default; pass `false` to pause editing while disconnected. See
39
+ * {@link CreateDocumentCollaborationOptions.offlineEditing}.
28
40
  */
29
41
  readonly offlineEditing?: boolean;
30
42
  }
@@ -38,13 +50,18 @@ interface UseHocuspocusCollaborationOptions {
38
50
  /**
39
51
  * Connect this room on mount. Omit it and call
40
52
  * {@link UseHocuspocusCollaborationReturn.connect} after the user chooses a room.
53
+ * A different room, server, bootstrap kind, or `actorId` leaves the old room and
54
+ * connects the new one, and `null` leaves. A room opened with `connect` stays.
41
55
  */
42
56
  readonly room?: UseHocuspocusCollaborationConnectOptions | null;
43
57
  }
44
58
  /** Values {@link useHocuspocusCollaboration} returns. @public */
45
59
  interface UseHocuspocusCollaborationReturn {
60
+ /** The room's document as `.docx` bytes to mount. Null until the room is ready. */
46
61
  readonly document: Uint8Array | null;
62
+ /** Modules to pass to the editor. They include the collaboration module once ready. */
47
63
  readonly modules: readonly EditorModule[];
64
+ /** The live session for status and presence. Null while no room is connected. */
48
65
  readonly session: CollaborationSession | null;
49
66
  /**
50
67
  * The room's shared Yjs document, owned by the hook. Null while no room is connected.
@@ -60,7 +77,25 @@ interface UseHocuspocusCollaborationReturn {
60
77
  * server events). The hook destroys it on leave and unmount.
61
78
  */
62
79
  readonly provider: HocuspocusProvider | null;
80
+ /** True while a connect is in progress. */
63
81
  readonly pending: boolean;
82
+ /**
83
+ * Local changes the server has not confirmed yet. More than zero while edits made offline
84
+ * wait for the connection, and for a moment after each edit while online. Warn before the
85
+ * page closes while it is above zero, or those edits are lost:
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * useEffect(() => {
90
+ * if (unsyncedChanges === 0) return;
91
+ * const warn = (event: BeforeUnloadEvent) => event.preventDefault();
92
+ * window.addEventListener('beforeunload', warn);
93
+ * return () => window.removeEventListener('beforeunload', warn);
94
+ * }, [unsyncedChanges]);
95
+ * ```
96
+ */
97
+ readonly unsyncedChanges: number;
98
+ /** The connect failure or session failure, or null. Check it before `document`. */
64
99
  readonly error: CollaborationFailure | null;
65
100
  /**
66
101
  * Connect a room. RESOLVES with the failure, or null on success — it does not reject.
@@ -74,8 +109,8 @@ interface UseHocuspocusCollaborationReturn {
74
109
  * Destroy the room and carry on editing locally.
75
110
  *
76
111
  * The current bytes live in the editor, not in this hook, so the argument is required:
77
- * pass `await editor.save()` to keep what the room typed. The hook remounts the editor
78
- * from exactly these bytes.
112
+ * pass the bytes `editor.save()` resolves with, as `new Uint8Array(saved)` after a `null`
113
+ * check, to keep what the room typed. The hook remounts the editor from exactly these bytes.
79
114
  */
80
115
  readonly leave: (nextDocument: Uint8Array) => void;
81
116
  /**
@@ -83,10 +118,19 @@ interface UseHocuspocusCollaborationReturn {
83
118
  * again to the same room with the same identity, url, and token.
84
119
  *
85
120
  * The reconnect always uses bootstrap `{ kind: 'join' }`, because the server still holds
86
- * the room. When the server no longer holds it, the join rejects with
121
+ * the room. When the server no longer holds it, the rejoin resolves with
87
122
  * `initialization-timeout` — nothing is lost, because `nextDocument` (your saved bytes)
88
123
  * stays mounted locally. A connect that failed also counts as the prior attempt, so
89
- * rejoin retries it as a joiner.
124
+ * rejoin retries it as a joiner. Resolves with the failure, or `null` on success.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * const saved = await editorRef.current?.save();
129
+ * if (saved) {
130
+ * const failure = await rejoin(new Uint8Array(saved));
131
+ * if (failure) console.warn(failure.code);
132
+ * }
133
+ * ```
90
134
  */
91
135
  readonly rejoin: (nextDocument: Uint8Array) => Promise<CollaborationFailure | null>;
92
136
  }
@@ -1 +1 @@
1
- import {b,a}from'../chunk-HJB77VBO.js';import'../chunk-Q2VBO66F.js';import {useId,useMemo}from'react';var i=Symbol("useHocuspocusCollaboration.createRoom");function u(o){return o?`${o.url}:${o.roomId}:${o.bootstrap.kind}:${o.identity.actorId}`:""}async function c(o){let{createHocuspocusCollaboration:n}=await import('../collaboration/hocuspocus.js');return n(o)}function p(o){return o[i]??c}function d(o={}){let n=useId(),e=b({ownerKey:`react-hocuspocus:${n}`,hookName:"useHocuspocusCollaboration",createRoom:p(o),hostModules:o.modules??a,autoRoom:o.room??null,autoKey:u(o.room??null),rejoinOptionsOf:t=>({...t,bootstrap:{kind:"join"}}),identityOf:t=>t.identity});return useMemo(()=>({document:e.document,modules:e.modules,session:e.session,ydoc:e.room?.ydoc??null,provider:e.room?.provider??null,pending:e.pending,error:e.error,connect:e.connect,leave:e.leave,rejoin:e.rejoin}),[e])}export{d as useHocuspocusCollaboration};
1
+ import {b as b$1,a}from'../chunk-MWO2ZUEJ.js';import'../chunk-Q2VBO66F.js';import {useId,useCallback,useSyncExternalStore,useMemo}from'react';var y=Symbol("useHocuspocusCollaboration.createRoom");function C(o){return o?`${o.url}:${o.roomId}:${o.bootstrap.kind}:${o.identity.actorId}`:""}async function m(o){let{createHocuspocusCollaboration:t}=await import('../collaboration/hocuspocus.js');return t(o)}function b(o){return o[y]??m}function H(o={}){let t=useId(),e=b$1({ownerKey:`react-hocuspocus:${t}`,hookName:"useHocuspocusCollaboration",createRoom:b(o),hostModules:o.modules??a,autoRoom:o.room??null,autoKey:C(o.room??null),rejoinOptionsOf:n=>({...n,bootstrap:{kind:"join"}}),identityOf:n=>n.identity}),r=e.room?.provider??null,i=useCallback(n=>r?(r.on("unsyncedChanges",n),()=>{r.off("unsyncedChanges",n);}):()=>{},[r]),s=useSyncExternalStore(i,()=>r?.unsyncedChanges??0,()=>0);return useMemo(()=>({document:e.document,modules:e.modules,session:e.session,ydoc:e.room?.ydoc??null,provider:e.room?.provider??null,pending:e.pending,unsyncedChanges:s,error:e.error,connect:e.connect,leave:e.leave,rejoin:e.rejoin}),[e,s])}export{H as useHocuspocusCollaboration};