@select-org/select-post-builder 1.1.49 → 1.1.50

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.
@@ -169,7 +169,7 @@ self.addEventListener('message', async (e) => {
169
169
 
170
170
  If you want to hide the \`${n.titleName}\`, you can wrap it with our VisuallyHidden component.
171
171
 
172
- For more information, see https://radix-ui.com/primitives/docs/components/${n.docsSlug}`;return React__namespace.useEffect(()=>{if(u){const p=document.getElementById(u)}},[d,u]),null},DESCRIPTION_WARNING_NAME="DialogDescriptionWarning",DescriptionWarning=({contentRef:u,descriptionId:n})=>{const p=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${useWarningContext(DESCRIPTION_WARNING_NAME).contentName}}.`;return React__namespace.useEffect(()=>{const m=u.current?.getAttribute("aria-describedby");if(n&&m){const g=document.getElementById(n)}},[p,u,n]),null},Root$3=Dialog$1,Trigger$1=DialogTrigger$1,Portal$1=DialogPortal$1,Overlay=DialogOverlay$1,Content=DialogContent$1,Title=DialogTitle$1,Description=DialogDescription$1,Close=DialogClose$1;function Dialog({...u}){return jsxRuntime.jsx(Root$3,{"data-slot":"dialog",...u})}const DialogTrigger=React.forwardRef((u,n)=>jsxRuntime.jsx(Trigger$1,{ref:n,"data-slot":"dialog-trigger",...u}));function DialogPortal({...u}){return jsxRuntime.jsx(Portal$1,{"data-slot":"dialog-portal",...u})}const DialogClose=React.forwardRef((u,n)=>jsxRuntime.jsx(Close,{ref:n,"data-slot":"dialog-close",...u})),DialogOverlay=React.forwardRef(({className:u,...n},d)=>jsxRuntime.jsx(Overlay,{ref:d,"data-slot":"dialog-overlay",className:cn("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",u),...n})),DialogContent=React.forwardRef(({className:u,children:n,showCloseButton:d=!0,...p},m)=>jsxRuntime.jsxs(DialogPortal,{children:[jsxRuntime.jsx("div",{"data-theme":"select-post-builder",children:jsxRuntime.jsx(DialogOverlay,{className:"z-9999 backdrop-blur-sm"})}),jsxRuntime.jsx("div",{"data-theme":"select-post-builder",children:jsxRuntime.jsxs(Content,{ref:m,"data-slot":"dialog-content","data-theme":"select-post-builder",className:cn("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-99999 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",u),...p,children:[n,d&&jsxRuntime.jsxs(Close,{"data-slot":"dialog-close",className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[jsxRuntime.jsx(X,{}),jsxRuntime.jsx("span",{className:"sr-only",children:"Close"})]})]})})]})),DialogHeader=React.forwardRef(({className:u,...n},d)=>jsxRuntime.jsx("div",{ref:d,"data-slot":"dialog-header",className:cn("flex flex-col gap-2 text-center sm:text-left",u),...n})),DialogFooter=React.forwardRef(({className:u,...n},d)=>jsxRuntime.jsx("div",{ref:d,"data-slot":"dialog-footer",className:cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",u),...n})),DialogTitle=React.forwardRef((u,n)=>jsxRuntime.jsx(Title,{ref:n,"data-slot":"dialog-title",className:cn("text-lg leading-none font-semibold"),...u})),DialogDescription=React.forwardRef(({className:u,...n},d)=>jsxRuntime.jsx(Description,{ref:d,"data-slot":"dialog-description",className:cn("text-muted-foreground text-sm",u),...n}));var PostBuilderEvents=(u=>(u.POST_PUBLISH_ATTEMPTED="select:post_publish_attempted",u.POST_PUBLISH_SUCCESSFUL="select:post_publish_success",u.POST_PUBLISH_FAILED="select:post_publish_failed",u.POST_SESSION_ROTATED="select:post_session_rotated",u.DRAFT_REHYDRATE_REQUEST="select:draft_rehydrate_request",u))(PostBuilderEvents||{});function useEditorTracking({editor:u,editorType:n,idleTimeout:d=3e5}){const{sessionId:p}=useAnalyticsSession(),m=React.useRef(),g=React.useRef(!1),y=React.useRef(!1),b=getAnalyticsStore(),S=React.useCallback(()=>getEditorMetrics(u),[u]),E=React.useCallback(()=>{m.current&&clearTimeout(m.current),!(!u||!p||y.current)&&(m.current=setTimeout(()=>{const _=S();_&&!_.isEmpty&&(b.trackExplicitAbandon(p,{contentLength:_.characterCount,hasUnsavedChanges:_.hasUnsavedChanges,abandonReason:"idle_timeout"}),y.current=!0)},d))},[u,p,d,b,S]),T=React.useCallback(()=>{if(!u||!p)return;const _=S();_&&(_.wordCount>=1||_.mediaCount>0||_.linkCount>0||_?.pollCount>0)&&b.trackContentCreated(p,{editorType:n,wordCount:_.wordCount,mediaCount:_.mediaCount,linkCount:_.linkCount})},[u,p,b,n,S]);React.useEffect(()=>{if(!u||!p)return;const _=()=>{g.current||(b.trackEditorFocus(p),g.current=!0,T()),E()},R=()=>{T(),E()};return u.on("focus",_),u.on("update",R),()=>{u.off("focus",_),u.off("update",R)}},[u,p,b,E,T]),React.useEffect(()=>{if(!p)return;const _=()=>{if(y.current)return;const R=S();R&&!R.isEmpty&&(b.trackExplicitAbandon(p,{contentLength:R.characterCount,hasUnsavedChanges:R.hasUnsavedChanges,abandonReason:"navigation"}),y.current=!0)};return window.addEventListener("beforeunload",_),()=>{window.removeEventListener("beforeunload",_),m.current&&clearTimeout(m.current)}},[p,b,S]),React.useEffect(()=>()=>{m.current&&clearTimeout(m.current),b.deleteSession(p)},[b,p])}const useHostAnalyticsBridge=()=>{const{sessionId:u,editorType:n,placement:d}=useAnalyticsSession(),p=useAnalyticsStore(b=>b.trackPublish),m=useAnalyticsStore(b=>b.deleteSession),g=useAnalyticsStore(b=>b.createSession),y=React.useRef(new Set);React.useEffect(()=>{if(!u)return;const b=E=>{const{postId:T,postType:_,groupId:R}=E.detail;if(!T||y.current.has(T))return;y.current.add(T),p(u,{status:"success",editorType:n,postId:T,groupId:R,postType:_}),m(u);const A=g(n,d);window.dispatchEvent(new CustomEvent(PostBuilderEvents.POST_SESSION_ROTATED,{detail:{newSessionId:A,oldSessionId:u}}))},S=E=>{const{postId:T,postType:_,groupId:R,failureReason:A}=E.detail;if(!T||y.current.has(T))return;y.current.add(T),p(u,{status:"failed",editorType:n,postId:T,groupId:R,postType:_,failureReason:A}),m(u);const C=g(n,d);window.dispatchEvent(new CustomEvent(PostBuilderEvents.POST_SESSION_ROTATED,{detail:{newSessionId:C,oldSessionId:u}}))};return window.addEventListener(PostBuilderEvents.POST_PUBLISH_SUCCESSFUL,b),window.addEventListener(PostBuilderEvents.POST_PUBLISH_FAILED,S),()=>{window.removeEventListener(PostBuilderEvents.POST_PUBLISH_SUCCESSFUL,b),window.removeEventListener(PostBuilderEvents.POST_PUBLISH_FAILED,S)}},[u,n,d,p,m,g])},getSharedDraftKey=(u,n)=>{const d=["shared"];return u&&d.push(u),n&&d.push(n),d.join(":")+"-draft"},getPollDraftKey=(u,n)=>{const d=["Poll"];return u&&d.push(u),n&&d.push(n),d.join(":")+"-draft"},FORMATTING_MARKS=new Set(["bold","italic","strike","underline","code","superscript","subscript"]),extractTextContent=u=>{if(!u)return"";let n="";const d=p=>{p.type==="text"&&p.text&&(n+=p.text),p.content&&Array.isArray(p.content)&&p.content.forEach(m=>d(m))};return d(u),n.trim()},extractPollQuestion=u=>{if(!u?.content)return"";const n=u.content.filter(p=>p.type==="paragraph");let d="";return n.forEach(p=>{p.content&&p.content.forEach(m=>{m.type==="text"&&m.text&&(d+=m.text)})}),d.trim()},isPollEmpty=u=>{if(!u||!u.content)return!0;if(extractPollQuestion(u))return!1;const d=u.content.find(p=>p.type==="poll");return!(d?.attrs?.choices&&Array.isArray(d.attrs.choices)&&d.attrs.choices.length>0)},isSharedContentEmpty=u=>!u||!u.content?!0:!(extractTextContent(u).length>0||u.content.some(m=>m.type==="media"||m.type==="mediaGroup"&&m.content&&m.content.length>0)||u.content.some(m=>m.type==="linkPreview")),extractParagraphNodes=u=>u?.content?u.content.filter(n=>n.type==="paragraph"):[],collectMediaNodes=u=>{if(!u?.content)return[];const n=[];for(const d of u.content)d.type==="media"?n.push(d):d.type==="mediaGroup"&&d.content&&n.push(...d.content.filter(p=>p.type==="media"));return n},rewriteLinkMode=(u,n)=>{const d=p=>{const m=p.content?.map(d);if(p.type==="text"&&p.marks){const g=p.marks.map(y=>y.type==="customLink"?{...y,attrs:{...y.attrs,isLinkMode:n}}:y);return{...p,marks:g,content:m}}return m?{...p,content:m}:p};return d(u)},stripFormattingMarks=u=>u.content?{...u,content:u.content.map(n=>{if(n.type==="text"&&n.marks){const d=n.marks.filter(p=>!FORMATTING_MARKS.has(p.type??""));return{...n,marks:d.length>0?d:void 0}}return n.content?stripFormattingMarks(n):n})}:u,cleanParagraphsForPoll=u=>{const n=new Set(["linkPreview","media","mediaGroup","embed","image"]);return u.map(d=>d?.content?{...d,content:d.content.map(p=>{if(n.has(p?.type||""))return null;if(p?.type==="text"&&p?.marks){const m=p.marks.filter(g=>{const y=g?.type??"";return y==="link"||y==="customLink"||!FORMATTING_MARKS.has(y)}).map(g=>g.type==="customLink"?{...g,type:"link"}:g);return{...p,marks:m.length>0?m:void 0}}return p}).filter(p=>p!==null)}:d)},createPollContentFromNodes=(u,n)=>{const d=[];return u.length>0?d.push(...u):d.push({type:"paragraph"}),d.push(n||{type:"poll",attrs:{choices:[]}}),{type:"doc",content:d}},transformForPost=u=>{if(!u?.content)return{type:"doc",content:[{type:"paragraph"}]};const n=[],d=[];for(const m of u.content)switch(m.type){case"paragraph":n.push(stripFormattingMarks(m));break;case"media":d.push(m);break;case"mediaGroup":m.content&&d.push(...m.content.filter(g=>g.type==="media"));break;case"linkPreview":break;case"heading":n.push(stripFormattingMarks({...m,type:"paragraph",attrs:void 0}));break;case"blockquote":case"bulletList":case"orderedList":if(m.content){for(const g of m.content)if(g.type==="paragraph")n.push(stripFormattingMarks(g));else if(g.type==="listItem"&&g.content)for(const y of g.content)y.type==="paragraph"&&n.push(stripFormattingMarks(y))}break;case"codeBlock":m.content&&n.push({type:"paragraph",content:m.content});break}for(n.length===0&&n.push({type:"paragraph"});n.length>1;){const m=n[n.length-1];if(!m.content||m.content.length===0||m.content.every(y=>y.type==="text"&&!y.text?.trim()))n.pop();else break}const p=[...n];return d.length>0&&p.push({type:"mediaGroup",content:d.slice(0,MAX_FILES)}),rewriteLinkMode({type:"doc",content:p},!0)},transformForBlog=u=>{if(!u?.content)return{type:"doc",content:[{type:"paragraph"}]};const n=[];for(const d of u.content)d.type==="mediaGroup"&&d.content?n.push(...d.content.filter(p=>p.type==="media")):d.type==="linkPreview"||n.push(d);return n.length===0&&n.push({type:"paragraph"}),rewriteLinkMode({type:"doc",content:n},!1)},transformForPoll=(u,n)=>{let d=extractParagraphNodes(u);return d=cleanParagraphsForPoll(d),createPollContentFromNodes(d,n)},extractSharedTextFromPoll=u=>u?.content?u.content.filter(d=>d.type==="paragraph").map(d=>d?.content?{...d,content:d.content.map(p=>p?.type==="text"&&p?.marks?{...p,marks:p.marks.map(m=>m.type==="link"?{...m,type:"customLink"}:m)}:p)}:d):[],syncSharedToPollDraft=(u,n,d)=>{const p=getPollDraftKey(n,d),m=localStorage.getItem(p);let g;if(m)try{g=JSON.parse(m).content?.find(E=>E.type==="poll")}catch{}if(!extractTextContent(u)){if(!g||!g.attrs?.choices?.length)localStorage.removeItem(p);else{const S=createPollContentFromNodes([],g);localStorage.setItem(p,JSON.stringify(S))}return}const b=transformForPoll(u,g);localStorage.setItem(p,JSON.stringify(b))},syncPollToSharedDraft=(u,n,d)=>{const p=getSharedDraftKey(n,d),m=localStorage.getItem(p),g=extractSharedTextFromPoll(u);if(!extractTextContent({type:"doc",content:g}))return;let b=[],S=null;if(m)try{const _=JSON.parse(m);_.content&&(b=collectMediaNodes(_),S=_.content.find(R=>R.type==="linkPreview")??null)}catch{}const E=[...g];if(S&&E.push(S),b.length>0&&E.push(...b),E.length===0)return;const T={type:"doc",content:E};localStorage.setItem(p,JSON.stringify(T))},usePersistence=(u,n)=>{const d=React.useCallback(g=>{if(!n||typeof window>"u"||typeof localStorage>"u")return null;if(g===EditorTypes.Poll){const S=getPollDraftKey(u,n),E=localStorage.getItem(S);if(E)try{return JSON.parse(E)}catch{return null}const T=getSharedDraftKey(u,n),_=localStorage.getItem(T);if(_)try{const R=JSON.parse(_);if(extractTextContent(R))return transformForPoll(R)}catch{}return null}const y=getSharedDraftKey(u,n),b=localStorage.getItem(y);if(!b)return null;try{const S=JSON.parse(b);return g===EditorTypes.Media?transformForPost(S):g===EditorTypes.Blog?transformForBlog(S):S}catch{return null}},[u,n]),p=React.useCallback((g,y)=>{if(!n||typeof window>"u"||typeof localStorage>"u"||!y)return;const b=y.getJSON(),S=filterNodes(b,E=>!E?.attrs?.uploading);if(S)if(g===EditorTypes.Poll){if(isPollEmpty(S)&&y.isEmpty)return;const E=getPollDraftKey(u,n);localStorage.setItem(E,JSON.stringify(S)),syncPollToSharedDraft(S,u,n)}else{const E=y.isEmpty,T=getSharedDraftKey(u,n),_=!!localStorage.getItem(T);if(!(_||!E)||isSharedContentEmpty(S)&&!_)return;localStorage.setItem(T,JSON.stringify(S)),syncSharedToPollDraft(S,u,n)}},[u,n]),m=React.useCallback(()=>{n&&(typeof window>"u"||typeof localStorage>"u"||(localStorage.removeItem(getSharedDraftKey(u,n)),localStorage.removeItem(getPollDraftKey(u,n))))},[u,n]);return{saveCurrentTabContent:p,getTabContent:d,clearContent:m}},createPostBuilderStore=u=>{const n=u.postId&&u.groupId?"post":u.groupId?"group":"global";return createStore((d,p)=>({contextType:n,groupId:u.groupId??null,postId:u.postId??null,selectedGroupId:u.groupId??null,enableGroupSelector:!u.groupId,editor:null,setEditor:m=>d({editor:m}),setContext:m=>d({contextType:m,enableGroupSelector:m==="global"}),setGroupId:m=>d({groupId:m,selectedGroupId:m??null,enableGroupSelector:!m}),setPostId:m=>d({postId:m}),selectGroup:m=>d({selectedGroupId:m}),getMentionParams:()=>{const{contextType:m,groupId:g,postId:y,selectedGroupId:b}=p();if(m==="post"&&g&&y)return{groupId:g,postId:y};const S=b||g||void 0;return S?{groupId:S}:null}}))};var h=(u,n)=>{if(u==="slot")return 0;if(u instanceof Function)return u(n);const{children:d,...p}=n??{};if(u==="svg")throw new Error("SVG elements are not supported in the JSX syntax, use the array syntax instead");return[u,p,d]},inputRegex$3=/^\s*>\s$/,Blockquote=Node3.create({name:"blockquote",addOptions(){return{HTMLAttributes:{}}},content:"block+",group:"block",defining:!0,parseHTML(){return[{tag:"blockquote"}]},renderHTML({HTMLAttributes:u}){return h("blockquote",{...mergeAttributes(this.options.HTMLAttributes,u),children:h("slot",{})})},parseMarkdown:(u,n)=>n.createNode("blockquote",void 0,n.parseChildren(u.tokens||[])),renderMarkdown:(u,n)=>{if(!u.content)return"";const d=">",p=[];return u.content.forEach(m=>{const b=n.renderChildren([m]).split(`
172
+ For more information, see https://radix-ui.com/primitives/docs/components/${n.docsSlug}`;return React__namespace.useEffect(()=>{if(u){const p=document.getElementById(u)}},[d,u]),null},DESCRIPTION_WARNING_NAME="DialogDescriptionWarning",DescriptionWarning=({contentRef:u,descriptionId:n})=>{const p=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${useWarningContext(DESCRIPTION_WARNING_NAME).contentName}}.`;return React__namespace.useEffect(()=>{const m=u.current?.getAttribute("aria-describedby");if(n&&m){const g=document.getElementById(n)}},[p,u,n]),null},Root$3=Dialog$1,Trigger$1=DialogTrigger$1,Portal$1=DialogPortal$1,Overlay=DialogOverlay$1,Content=DialogContent$1,Title=DialogTitle$1,Description=DialogDescription$1,Close=DialogClose$1;function Dialog({...u}){return jsxRuntime.jsx(Root$3,{"data-slot":"dialog",...u})}const DialogTrigger=React.forwardRef((u,n)=>jsxRuntime.jsx(Trigger$1,{ref:n,"data-slot":"dialog-trigger",...u}));function DialogPortal({...u}){return jsxRuntime.jsx(Portal$1,{"data-slot":"dialog-portal",...u})}const DialogClose=React.forwardRef((u,n)=>jsxRuntime.jsx(Close,{ref:n,"data-slot":"dialog-close",...u})),DialogOverlay=React.forwardRef(({className:u,...n},d)=>jsxRuntime.jsx(Overlay,{ref:d,"data-slot":"dialog-overlay",className:cn("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",u),...n})),DialogContent=React.forwardRef(({className:u,children:n,showCloseButton:d=!0,...p},m)=>jsxRuntime.jsxs(DialogPortal,{children:[jsxRuntime.jsx("div",{"data-theme":"select-post-builder",children:jsxRuntime.jsx(DialogOverlay,{className:"z-9999 backdrop-blur-sm"})}),jsxRuntime.jsx("div",{"data-theme":"select-post-builder",children:jsxRuntime.jsxs(Content,{ref:m,"data-slot":"dialog-content","data-theme":"select-post-builder",className:cn("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-99999 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",u),...p,children:[n,d&&jsxRuntime.jsxs(Close,{"data-slot":"dialog-close",className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[jsxRuntime.jsx(X,{}),jsxRuntime.jsx("span",{className:"sr-only",children:"Close"})]})]})})]})),DialogHeader=React.forwardRef(({className:u,...n},d)=>jsxRuntime.jsx("div",{ref:d,"data-slot":"dialog-header",className:cn("flex flex-col gap-2 text-center sm:text-left",u),...n})),DialogFooter=React.forwardRef(({className:u,...n},d)=>jsxRuntime.jsx("div",{ref:d,"data-slot":"dialog-footer",className:cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",u),...n})),DialogTitle=React.forwardRef((u,n)=>jsxRuntime.jsx(Title,{ref:n,"data-slot":"dialog-title",className:cn("text-lg leading-none font-semibold"),...u})),DialogDescription=React.forwardRef(({className:u,...n},d)=>jsxRuntime.jsx(Description,{ref:d,"data-slot":"dialog-description",className:cn("text-muted-foreground text-sm",u),...n}));var PostBuilderEvents=(u=>(u.POST_PUBLISH_ATTEMPTED="select:post_publish_attempted",u.POST_PUBLISH_SUCCESSFUL="select:post_publish_success",u.POST_PUBLISH_FAILED="select:post_publish_failed",u.POST_SESSION_ROTATED="select:post_session_rotated",u.DRAFT_REHYDRATE_REQUEST="select:draft_rehydrate_request",u))(PostBuilderEvents||{});function useEditorTracking({editor:u,editorType:n,idleTimeout:d=3e5}){const{sessionId:p}=useAnalyticsSession(),m=React.useRef(),g=React.useRef(!1),y=React.useRef(!1),b=getAnalyticsStore(),S=React.useCallback(()=>getEditorMetrics(u),[u]),E=React.useCallback(()=>{m.current&&clearTimeout(m.current),!(!u||!p||y.current)&&(m.current=setTimeout(()=>{const _=S();_&&!_.isEmpty&&(b.trackExplicitAbandon(p,{contentLength:_.characterCount,hasUnsavedChanges:_.hasUnsavedChanges,abandonReason:"idle_timeout"}),y.current=!0)},d))},[u,p,d,b,S]),T=React.useCallback(()=>{if(!u||!p)return;const _=S();_&&(_.wordCount>=1||_.mediaCount>0||_.linkCount>0||_?.pollCount>0)&&b.trackContentCreated(p,{editorType:n,wordCount:_.wordCount,mediaCount:_.mediaCount,linkCount:_.linkCount})},[u,p,b,n,S]);React.useEffect(()=>{if(!u||!p)return;const _=()=>{g.current||(b.trackEditorFocus(p),g.current=!0,T()),E()},R=()=>{T(),E()};return u.on("focus",_),u.on("update",R),()=>{u.off("focus",_),u.off("update",R)}},[u,p,b,E,T]),React.useEffect(()=>{if(!p)return;const _=()=>{if(y.current)return;const R=S();R&&!R.isEmpty&&(b.trackExplicitAbandon(p,{contentLength:R.characterCount,hasUnsavedChanges:R.hasUnsavedChanges,abandonReason:"navigation"}),y.current=!0)};return window.addEventListener("beforeunload",_),()=>{window.removeEventListener("beforeunload",_),m.current&&clearTimeout(m.current)}},[p,b,S]),React.useEffect(()=>()=>{m.current&&clearTimeout(m.current),b.deleteSession(p)},[b,p])}const useHostAnalyticsBridge=()=>{const{sessionId:u,editorType:n,placement:d}=useAnalyticsSession(),p=useAnalyticsStore(b=>b.trackPublish),m=useAnalyticsStore(b=>b.deleteSession),g=useAnalyticsStore(b=>b.createSession),y=React.useRef(new Set);React.useEffect(()=>{if(!u)return;const b=E=>{const{postId:T,postType:_,groupId:R}=E.detail;if(!T||y.current.has(T))return;y.current.add(T),p(u,{status:"success",editorType:n,postId:T,groupId:R,postType:_}),m(u);const A=g(n,d);window.dispatchEvent(new CustomEvent(PostBuilderEvents.POST_SESSION_ROTATED,{detail:{newSessionId:A,oldSessionId:u}}))},S=E=>{const{postId:T,postType:_,groupId:R,failureReason:A}=E.detail;if(!T||y.current.has(T))return;y.current.add(T),p(u,{status:"failed",editorType:n,postId:T,groupId:R,postType:_,failureReason:A}),m(u);const C=g(n,d);window.dispatchEvent(new CustomEvent(PostBuilderEvents.POST_SESSION_ROTATED,{detail:{newSessionId:C,oldSessionId:u}}))};return window.addEventListener(PostBuilderEvents.POST_PUBLISH_SUCCESSFUL,b),window.addEventListener(PostBuilderEvents.POST_PUBLISH_FAILED,S),()=>{window.removeEventListener(PostBuilderEvents.POST_PUBLISH_SUCCESSFUL,b),window.removeEventListener(PostBuilderEvents.POST_PUBLISH_FAILED,S)}},[u,n,d,p,m,g])},getSharedDraftKey=(u,n)=>{const d=["shared"];return u&&d.push(u),n&&d.push(n),d.join(":")+"-draft"},getPollDraftKey=(u,n)=>{const d=["Poll"];return u&&d.push(u),n&&d.push(n),d.join(":")+"-draft"},FORMATTING_MARKS=new Set(["bold","italic","strike","underline","code","superscript","subscript"]),extractTextContent=u=>{if(!u)return"";let n="";const d=p=>{p.type==="text"&&p.text&&(n+=p.text),p.content&&Array.isArray(p.content)&&p.content.forEach(m=>d(m))};return d(u),n.trim()},extractPollQuestion=u=>{if(!u?.content)return"";const n=u.content.filter(p=>p.type==="paragraph");let d="";return n.forEach(p=>{p.content&&p.content.forEach(m=>{m.type==="text"&&m.text&&(d+=m.text)})}),d.trim()},isPollEmpty=u=>{if(!u||!u.content)return!0;if(extractPollQuestion(u))return!1;const d=u.content.find(p=>p.type==="poll");return!(d?.attrs?.choices&&Array.isArray(d.attrs.choices)&&d.attrs.choices.length>0)},isSharedContentEmpty=u=>!u||!u.content?!0:!(extractTextContent(u).length>0||u.content.some(m=>m.type==="media"||m.type==="mediaGroup"&&m.content&&m.content.length>0)||u.content.some(m=>m.type==="linkPreview")),extractParagraphNodes=u=>u?.content?u.content.filter(n=>n.type==="paragraph"):[],collectMediaNodes=u=>{if(!u?.content)return[];const n=[];for(const d of u.content)d.type==="media"?n.push(d):d.type==="mediaGroup"&&d.content&&n.push(...d.content.filter(p=>p.type==="media"));return n},rewriteLinkMode=(u,n)=>{const d=p=>{const m=p.content?.map(d);if(p.type==="text"&&p.marks){const g=p.marks.map(y=>y.type==="customLink"?{...y,attrs:{...y.attrs,isLinkMode:n}}:y);return{...p,marks:g,content:m}}return m?{...p,content:m}:p};return d(u)},stripFormattingMarks=u=>u.content?{...u,content:u.content.map(n=>{if(n.type==="text"&&n.marks){const d=n.marks.filter(p=>!FORMATTING_MARKS.has(p.type??""));return{...n,marks:d.length>0?d:void 0}}return n.content?stripFormattingMarks(n):n})}:u,cleanParagraphsForPoll=u=>{const n=new Set(["linkPreview","media","mediaGroup","embed","image"]);return u.map(d=>d?.content?{...d,content:d.content.map(p=>{if(n.has(p?.type||""))return null;if(p?.type==="text"&&p?.marks){const m=p.marks.filter(g=>{const y=g?.type??"";return y==="link"||y==="customLink"||!FORMATTING_MARKS.has(y)}).map(g=>g.type==="customLink"?{...g,type:"link"}:g);return{...p,marks:m.length>0?m:void 0}}return p}).filter(p=>p!==null)}:d)},createPollContentFromNodes=(u,n)=>{const d=[];return u.length>0?d.push(...u):d.push({type:"paragraph"}),d.push(n||{type:"poll",attrs:{choices:[]}}),{type:"doc",content:d}},transformForPost=u=>{if(!u?.content)return{type:"doc",content:[{type:"paragraph"}]};const n=[],d=[];for(const m of u.content)switch(m.type){case"paragraph":n.push(stripFormattingMarks(m));break;case"media":d.push(m);break;case"mediaGroup":m.content&&d.push(...m.content.filter(g=>g.type==="media"));break;case"linkPreview":break;case"heading":n.push(stripFormattingMarks({...m,type:"paragraph",attrs:void 0}));break;case"blockquote":case"bulletList":case"orderedList":if(m.content){for(const g of m.content)if(g.type==="paragraph")n.push(stripFormattingMarks(g));else if(g.type==="listItem"&&g.content)for(const y of g.content)y.type==="paragraph"&&n.push(stripFormattingMarks(y))}break;case"codeBlock":m.content&&n.push({type:"paragraph",content:m.content});break}for(n.length===0&&n.push({type:"paragraph"});n.length>1;){const m=n[n.length-1];if(!m.content||m.content.length===0||m.content.every(y=>y.type==="text"&&!y.text?.trim()))n.pop();else break}const p=[...n];return d.length>0&&p.push({type:"mediaGroup",content:d.slice(0,MAX_FILES)}),rewriteLinkMode({type:"doc",content:p},!0)},transformForBlog=u=>{if(!u?.content)return{type:"doc",content:[{type:"paragraph"}]};const n=[];for(const d of u.content)d.type==="mediaGroup"&&d.content?n.push(...d.content.filter(p=>p.type==="media")):d.type==="linkPreview"||n.push(d);return n.length===0&&n.push({type:"paragraph"}),rewriteLinkMode({type:"doc",content:n},!1)},transformForPoll=(u,n)=>{let d=extractParagraphNodes(u);return d=cleanParagraphsForPoll(d),createPollContentFromNodes(d,n)},extractSharedTextFromPoll=u=>u?.content?u.content.filter(d=>d.type==="paragraph").map(d=>d?.content?{...d,content:d.content.map(p=>p?.type==="text"&&p?.marks?{...p,marks:p.marks.map(m=>m.type==="link"?{...m,type:"customLink"}:m)}:p)}:d):[],syncSharedToPollDraft=(u,n,d)=>{const p=getPollDraftKey(n,d),m=localStorage.getItem(p);let g;if(m)try{g=JSON.parse(m).content?.find(E=>E.type==="poll")}catch{}if(!extractTextContent(u)){if(!g||!g.attrs?.choices?.length)localStorage.removeItem(p);else{const S=createPollContentFromNodes([],g);localStorage.setItem(p,JSON.stringify(S))}return}const b=transformForPoll(u,g);localStorage.setItem(p,JSON.stringify(b))},syncPollToSharedDraft=(u,n,d)=>{const p=getSharedDraftKey(n,d),m=localStorage.getItem(p),g=extractSharedTextFromPoll(u);if(!extractTextContent({type:"doc",content:g}))return;let b=[],S=null;if(m)try{const _=JSON.parse(m);_.content&&(b=collectMediaNodes(_),S=_.content.find(R=>R.type==="linkPreview")??null)}catch{}const E=[...g];if(S&&E.push(S),b.length>0&&E.push(...b),E.length===0)return;const T={type:"doc",content:E};localStorage.setItem(p,JSON.stringify(T))},usePersistence=(u,n)=>{const d=React.useCallback(g=>{if(!n||typeof window>"u"||typeof localStorage>"u")return null;if(g===EditorTypes.Poll){const S=getPollDraftKey(u,n),E=localStorage.getItem(S);if(E)try{return JSON.parse(E)}catch{return null}const T=getSharedDraftKey(u,n),_=localStorage.getItem(T);if(_)try{const R=JSON.parse(_);if(extractTextContent(R))return transformForPoll(R)}catch{}return null}const y=getSharedDraftKey(u,n),b=localStorage.getItem(y);if(!b)return null;try{const S=JSON.parse(b);return g===EditorTypes.Media?transformForPost(S):g===EditorTypes.Blog?transformForBlog(S):S}catch{return null}},[u,n]),p=React.useCallback((g,y)=>{if(!n||typeof window>"u"||typeof localStorage>"u"||!y)return;const b=y.getJSON(),S=filterNodes(b,E=>!E?.attrs?.uploading);if(S)if(g===EditorTypes.Poll){if(isPollEmpty(S))return;const E=getPollDraftKey(u,n);localStorage.setItem(E,JSON.stringify(S)),syncPollToSharedDraft(S,u,n)}else{const E=y.isEmpty,T=getSharedDraftKey(u,n),_=!!localStorage.getItem(T);if(!(_||!E)||isSharedContentEmpty(S)&&!_)return;localStorage.setItem(T,JSON.stringify(S)),syncSharedToPollDraft(S,u,n)}},[u,n]),m=React.useCallback(()=>{n&&(typeof window>"u"||typeof localStorage>"u"||(localStorage.removeItem(getSharedDraftKey(u,n)),localStorage.removeItem(getPollDraftKey(u,n))))},[u,n]);return{saveCurrentTabContent:p,getTabContent:d,clearContent:m}},createPostBuilderStore=u=>{const n=u.postId&&u.groupId?"post":u.groupId?"group":"global";return createStore((d,p)=>({contextType:n,groupId:u.groupId??null,postId:u.postId??null,selectedGroupId:u.groupId??null,enableGroupSelector:!u.groupId,editor:null,setEditor:m=>d({editor:m}),setContext:m=>d({contextType:m,enableGroupSelector:m==="global"}),setGroupId:m=>d({groupId:m,selectedGroupId:m??null,enableGroupSelector:!m}),setPostId:m=>d({postId:m}),selectGroup:m=>d({selectedGroupId:m}),getMentionParams:()=>{const{contextType:m,groupId:g,postId:y,selectedGroupId:b}=p();if(m==="post"&&g&&y)return{groupId:g,postId:y};const S=b||g||void 0;return S?{groupId:S}:null}}))};var h=(u,n)=>{if(u==="slot")return 0;if(u instanceof Function)return u(n);const{children:d,...p}=n??{};if(u==="svg")throw new Error("SVG elements are not supported in the JSX syntax, use the array syntax instead");return[u,p,d]},inputRegex$3=/^\s*>\s$/,Blockquote=Node3.create({name:"blockquote",addOptions(){return{HTMLAttributes:{}}},content:"block+",group:"block",defining:!0,parseHTML(){return[{tag:"blockquote"}]},renderHTML({HTMLAttributes:u}){return h("blockquote",{...mergeAttributes(this.options.HTMLAttributes,u),children:h("slot",{})})},parseMarkdown:(u,n)=>n.createNode("blockquote",void 0,n.parseChildren(u.tokens||[])),renderMarkdown:(u,n)=>{if(!u.content)return"";const d=">",p=[];return u.content.forEach(m=>{const b=n.renderChildren([m]).split(`
173
173
  `).map(S=>S.trim()===""?d:`${d} ${S}`);p.push(b.join(`
174
174
  `))}),p.join(`
175
175
  ${d}
@@ -39961,7 +39961,7 @@ const useHostAnalyticsBridge = () => {
39961
39961
  const b = y.getJSON(), S = filterNodes(b, (E) => !E?.attrs?.uploading);
39962
39962
  if (S)
39963
39963
  if (g === EditorTypes.Poll) {
39964
- if (isPollEmpty(S) && y.isEmpty) return;
39964
+ if (isPollEmpty(S)) return;
39965
39965
  const E = getPollDraftKey(u, n);
39966
39966
  localStorage.setItem(E, JSON.stringify(S)), syncPollToSharedDraft(S, u, n);
39967
39967
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@select-org/select-post-builder",
3
- "version": "1.1.49",
3
+ "version": "1.1.50",
4
4
  "description": "A reusable, extensible Post Builder widget for the Select platform and beyond.",
5
5
  "main": "./dist/post-builder.cjs.js",
6
6
  "module": "./dist/post-builder.js",