@select-org/select-post-builder 1.1.39 → 1.1.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -281,17 +281,6 @@ declare type WithoutModalProps = BaseProps & {
281
281
  export { }
282
282
 
283
283
 
284
- declare module '@tiptap/core' {
285
- interface Commands<ReturnType> {
286
- poll: {
287
- insertPoll: (attrs: {
288
- choices: PollChoiceItem[];
289
- }) => ReturnType;
290
- };
291
- }
292
- }
293
-
294
-
295
284
  declare module '@tiptap/core' {
296
285
  interface Commands<ReturnType> {
297
286
  media: {
@@ -320,6 +309,17 @@ declare module '@tiptap/core' {
320
309
  }
321
310
 
322
311
 
312
+ declare module '@tiptap/core' {
313
+ interface Commands<ReturnType> {
314
+ poll: {
315
+ insertPoll: (attrs: {
316
+ choices: PollChoiceItem[];
317
+ }) => ReturnType;
318
+ };
319
+ }
320
+ }
321
+
322
+
323
323
  declare module '@tiptap/core' {
324
324
  interface Commands<ReturnType> {
325
325
  customLink: {
@@ -106,4 +106,4 @@ Defaulting to \`null\`.`}var Root$1=Progress$1,Indicator=ProgressIndicator;funct
106
106
 
107
107
 
108
108
  prose-figcaption:text-xs prose-code:text-sm
109
- prose-codeblock:text-sm prose-a:text-blue-500 focus:outline-none`)}}),createEditorActions=n=>({undo:()=>n?.chain().focus().undo().run(),redo:()=>n?.chain().focus().redo().run(),toggleHeading:u=>n?.chain().focus().toggleHeading({level:u}).run(),setParagraph:()=>n?.chain().focus().setParagraph().run(),toggleBold:()=>n?.chain().focus().toggleBold().run(),toggleItalic:()=>n?.chain().focus().toggleItalic().run(),toggleStrikethrough:()=>n?.chain().focus().toggleStrike().run(),toggleUnderline:()=>n?.chain().focus().toggleUnderline().run(),insertLink:u=>n?.chain().focus().setLink({href:u}).run(),toggleBulletList:()=>n?.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>n?.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>n?.chain().focus().toggleBlockquote().run(),toggleCode:()=>n?.chain().focus().toggleCode().run(),toggleCodeBlock:()=>n?.chain().focus().toggleCodeBlock().run(),toggleTextAlign:u=>n?.chain().focus().setTextAlign(u).run(),insertPoll:()=>n?.chain().focus().insertContent({type:"poll"}).run(),insertMedia:(u,d)=>{n?.chain()?.focus()?.insertContent([{type:"media",attrs:{src:u,type:d}},{type:"paragraph"}])?.run()}}),initializePollEditor=n=>{n.chain().focus().insertContent({type:"paragraph"}).insertContent({type:"poll"}).command(({tr:u})=>{const{doc:d}=u;let p=-1;if(d.descendants((m,g)=>{if(m.type.name==="paragraph"&&p===-1)return p=g,!1}),p>=0){const m=d.nodeAt(p);if(m){const g=p+m.nodeSize-1,y=u.doc.resolve(g);u.setSelection(state.TextSelection.near(y))}}return!0}).run()},usePostBuilderEditor=({editorType:n,placement:u,groupId:d,postId:p,user:m,disableNavigationWarning:g})=>{const[,y]=React.useState(0),[b,_]=React.useState(!1),S=useApi(),E=React.useMemo(()=>createPostBuilderStore({groupId:d,postId:p}),[d,p]),{getTabContent:T,saveCurrentTabContent:R}=usePersistence(u,d),C=React.useRef(!1),A=React.useRef(!1);React.useEffect(()=>{_(!0),y(D=>D+1)},[]);const P=React.useMemo(()=>!!T(n),[n,T]),O=react.useEditor({extensions:getExtensions({editorType:n,api:S,store:E,user:m}),content:T(n)??"",editorProps:getEditorProps(),onCreate:({editor:D})=>{E.getState().setEditor(D),n===EditorTypes.Blog&&D?.chain()?.focus("end")?.run(),n===EditorTypes.Media&&D?.chain()?.focus("end")?.run(),n===EditorTypes.Poll&&!P&&initializePollEditor(D),n===EditorTypes.Poll&&P&&D?.chain()?.focus("end")?.run()},onUnmount:({editor:D})=>{if(A.current||C.current){C.current=!1,A.current=!1;return}R(n,D)},immediatelyRender:!1,shouldRerenderOnTransaction:!1},[n,u,b]);React.useEffect(()=>{if(g)return;const D=W=>{O&&!O.isEmpty&&W.preventDefault()};return window.addEventListener("beforeunload",D),()=>window.removeEventListener("beforeunload",D)},[O,g]),React.useEffect(()=>{let D;if(!b||!O||!O?.view||n===EditorTypes.Poll)return;const W=T(n);return W&&O?.isEditable&&(D=setTimeout(()=>{O.commands.setContent(W),O.commands.rehydrateLinkPreviews()},0)),()=>{D&&clearTimeout(D)}},[O,n,u,T,b]);const k=React.useMemo(()=>O?createEditorActions(O):null,[O]),L=React.useCallback(()=>{O&&!O.isDestroyed&&(R(n,O),C.current=!0)},[O,n,R]),N=React.useCallback(()=>{O&&!O.isDestroyed&&R(n,O)},[O,n,R]),I=React.useCallback(()=>{A.current=!0},[]),B=React.useCallback(()=>{O&&!O.isDestroyed&&O?.commands?.focus("end")},[O]);return{editor:O,actions:k,store:E,isMounted:b,saveBeforeSwitch:L,saveDraft:N,discardDraft:I,keepEditing:B}},getEditorData=n=>({html:n?.getHTML(),json:n?.getJSON(),text:n?.getText()}),getCommonPayload=n=>({postId:v4(),timestamp:new Date().getTime(),specialType:SpecialType.POST,...n&&{conversationId:n}}),getMentionDataPayload=n=>({mentionData:findByType(n,"mention")?.map(p=>omit(omitBy(p.attrs,isNil),["mentionSuggestionChar","label"]))?.filter(p=>Object.keys(p).length>0)}),getMediaItemsPayload=n=>({items:findByType(n,"media").map(p=>p.attrs?.payload).filter(Boolean)}),isLinkMark=n=>!!n.marks?.some(u=>u.type==="customLink"),getLinkItemsPayload=n=>{const d=find(n,m=>isLinkMark(m))?.flatMap(m=>m?.marks?.filter(g=>g?.type==="customLink"&&g?.attrs?.previewPayload));return{items:Array.of(d?.at(-1)?.attrs?.previewPayload).filter(Boolean)}},getPollItemsPayload=n=>({items:findByType(n,"poll")[0].attrs?.choices}),isValidItem=n=>{if(!n)return!1;const u=n,d=n,p=u?.linkUrl,m=d?.sources,g=m?.original?.url||m?.thumbnail?.url;return!!(p||g)},generateHtmlPostPayload=({editor:n,sendCrossMention:u,groupId:d})=>{const{html:p,json:m}=getEditorData(n),g=getCommonPayload(d),{mentionData:y}=getMentionDataPayload(m),b=findFirstByType(m,"media"),_=findFirstByType(m,"iframe"),S=findFirstByType(m,"text"),T=S?.marks?.some(k=>k.type==="customLink")?S?.marks?.find(k=>k.type==="customLink")?.attrs?.previewPayload:null,R=find(m,k=>k?.type==="text"&&(k?.marks?.some(L=>L?.type!=="customLink")??!0))?.at(0),A=isOnlyContentNode(m,"iframe")?_?.attrs?.previewPayload?.linkTitle??_?.attrs?.src??"":R?.text??S?.text??"",P=[b?.attrs?.payload,_?.attrs?.previewPayload,T].filter(isValidItem)?.filter((k,L)=>L===0),O=p;return{...g,type:P?.length>0?NewPostType.NEW_POST_MEDIA:NewPostType.NEW_POST_MESSAGE,body:A,items:P,htmlBody:O,sendCrossMention:u,mentionData:y}},generateMediaPostPayload=({editor:n,sendCrossMention:u,groupId:d})=>{const{json:p,text:m}=getEditorData(n),g=getCommonPayload(d),y=m?.trim()??"",{mentionData:b}=getMentionDataPayload(p),{items:_}=getMediaItemsPayload(p),{items:S}=getLinkItemsPayload(p),E=_?.length>0?_:S?.length>0?S:[];return!y&&_.length===0?{error:"Your post is empty. Add text or media to share your thoughts."}:{...g,type:_?.length>0?NewPostType.NEW_POST_MEDIA:S?.length>0?NewPostType.NEW_POST_LINK:NewPostType.NEW_POST_MESSAGE,body:y,items:E,mentionData:b,sendCrossMention:u}},generatePollPostPayload=({editor:n,sendCrossMention:u,groupId:d})=>{const{json:p,text:m}=getEditorData(n),g=getCommonPayload(d),y=m,{mentionData:b}=getMentionDataPayload(p),{items:_}=getPollItemsPayload(p),S=_.length===1?_.concat(_).map((E,T)=>({...E,key:E?.key??v4(),option_id:T===0?E.option_id:v4(),option_color:OPTION_COLORS[T%OPTION_COLORS.length]})):_;return{...g,type:NewPostType.NEW_POST_POLL,body:y,items:S,mentionData:b,sendCrossMention:u}},generateCreatePostPayload=(n,u)=>{switch(n){case EditorTypes.Blog:return generateHtmlPostPayload(u);case EditorTypes.Media:return generateMediaPostPayload(u);case EditorTypes.Poll:return generatePollPostPayload(u);default:return null}},PostBuilderEditorInstance=({editor:n,actions:u,editorTab:d,onSwitchEditor:p,isSubmitting:m,clearOnSuccess:g,onCreatePost:y,onVoiceComment:b,className:_,store:S,placement:E})=>{const[T,R]=React.useState(!1),[C,A]=React.useState(!0),[P,O]=React.useState(null),{trackPublish:k}=useAnalyticsTracking(),{t:L}=usePostBuilder(),N=useStore(S,Y=>Y.groupId)??void 0,{clearContent:I}=usePersistence(E,N);useHostAnalyticsBridge(),useEditorTracking({editor:n,editorType:d});const B=React.useRef(null),[D,W]=React.useState(),F=React.useCallback(Y=>{if(n&&hasActiveUploads(n)){O(Y);return}B.current&&W(B.current.offsetHeight),p(Y)},[n,p]);React.useEffect(()=>{if(D&&n){const Y=()=>W(void 0),te=setTimeout(Y,50);return n.once("update",Y),()=>{clearTimeout(te),n.off("update",Y)}}},[D,n]),React.useEffect(()=>{const Y=()=>{const{groupId:j,selectedGroupId:H}=S.getState();A(!!(j||H))};Y();const te=S.subscribe(Y);return()=>te()},[S]);const K=Y=>{Y.preventDefault(),R(!0)},Z=Y=>{Y.preventDefault(),R(!1)},ee=Y=>{Y.preventDefault(),R(!1)},q=()=>{const Y=document.querySelector('[aria-label="Select group"]');Y&&Y.click()},Q=React.useCallback(Y=>{if(!n)return;const te=n?.getHTML(),j=n?.getJSON(),H=n?.getText(),{selectedGroupId:$,groupId:V}=S.getState(),re=generateCreatePostPayload(d,{editor:n,sendCrossMention:Y,groupId:$||V||void 0}),ie=re?.type===NewPostType.NEW_POST_POLL;if(re?.error){toast.error(re.error);return}if(!re?.postId)return;if(ie&&re.items?.length===0)return toast.warning(`At least ${POLL_LIMITS.MIN} option is mandatory to create a poll post`);typeof window<"u"&&window.dispatchEvent(new CustomEvent(PostBuilderEvents.POST_PUBLISH_ATTEMPTED,{detail:{postId:re.postId,postType:re.type}}));const se=getEditorMetrics(n);k({editorType:d,status:"attempted",postId:re?.postId,postType:re?.type,...se}),y?.({payload:re,html:te,json:j,text:H}),g&&(I(),d===EditorTypes.Poll?n?.chain()?.focus()?.setContent({type:"doc",content:[{type:"paragraph"},{type:"poll"}]})?.run():n?.chain()?.focus()?.clearContent()?.run())},[I,g,n,d,y,S,k]);return React.useEffect(()=>{const Y=te=>{if((te.ctrlKey||te.metaKey)&&te.key==="Enter"){if(!n?.isFocused)return;if(te.preventDefault(),n&&hasActiveUploads(n)){toast.error(L("uploadsInProgressKey"));return}Q(!1)}};return window.addEventListener("keydown",Y),()=>window.removeEventListener("keydown",Y)},[n,Q]),jsxRuntime.jsxs("div",{ref:B,style:{minHeight:D?`${D}px`:void 0},className:cn("post-builder-editor bg-background border rounded-md overflow-hidden max-h-full grow flex flex-col transition-all duration-300 ease-in-out relative",E===EditorPlacement.Comment&&"min-h-32",_),children:[!C&&jsxRuntime.jsx("div",{className:"z-50 absolute inset-0 bg-foreground/30 backdrop-blur-xs flex items-center justify-center rounded-md pointer-events-none",children:jsxRuntime.jsx(Button,{variant:"outline",size:"lg",onClick:q,className:"pointer-events-auto cursor-pointer hover:animate-none animate-pulse",children:"Please select a group first"})}),E!==EditorPlacement.Comment&&jsxRuntime.jsx(EditorTypeTabs,{editorTab:d,onSwitchEditorTab:F}),jsxRuntime.jsx(Toolbar,{editor:n,actions:u,isSubmitting:m,onSubmit:Q,editorType:d,placement:E,onVoiceComment:b,children:jsxRuntime.jsxs("div",{className:"relative flex flex-col grow overflow-y-auto",children:[T&&jsxRuntime.jsx("div",{className:"pointer-events-none z-50 absolute inset-0 bg-accent/10 border border-dashed flex items-center justify-center",children:jsxRuntime.jsx("h2",{children:"Drop Here"})}),jsxRuntime.jsxs("div",{onDragOver:K,onDragLeave:Z,onDrop:ee,className:"flex flex-col grow",children:[jsxRuntime.jsx(DragHandle__default.default,{editor:n,className:cn("pr-2",d!==EditorTypes.Blog&&"hidden size-0 overflow-hidden pointer-events-none"),children:jsxRuntime.jsx(Button,{variant:"ghost",className:"bg-white cursor-grab py-0.5 px-0 border size-auto",children:jsxRuntime.jsx(GripVertical,{className:"text-muted-foreground"})})}),jsxRuntime.jsx(react.EditorContent,{className:"grow","data-theme":"select-post-builder",editor:n})]})]})}),jsxRuntime.jsx(Dialog,{open:!!P,onOpenChange:Y=>!Y&&O(null),children:jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:L("cancelUploadTitleKey")}),jsxRuntime.jsx(DialogDescription,{children:L("cancelUploadDescriptionKey")})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(DialogClose,{asChild:!0,children:jsxRuntime.jsx(Button,{variant:"outline",children:L("stayKey")})}),jsxRuntime.jsx(Button,{variant:"destructive",onClick:()=>{P&&(n.commands.deleteAllUploadingMedia(),B.current&&W(B.current.offsetHeight),p(P),O(null))},children:L("continueKey")})]})]})})]})},PostBuilderEditorInstanceWithDialog=({user:n,store:u,hideGroupSelector:d,open:p,onOpenChange:m,onGroupSelect:g,placement:y,...b})=>{const{trackAbandon:_}=useAnalyticsTracking(),S=E=>{if(m(E),E)return;const T=getEditorMetrics(b.editor);_({editorType:b.editorTab,abandonReason:"user_closed",contentLength:T?.characterCount??0,hasUnsavedChanges:T?.hasUnsavedChanges??!1})};return jsxRuntime.jsxs(Dialog,{modal:!1,open:p,onOpenChange:S,children:[jsxRuntime.jsx("div",{className:"z-999 fixed inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>S(!1)}),jsxRuntime.jsxs(DialogContent,{onInteractOutside:E=>E.preventDefault(),onOpenAutoFocus:E=>E.preventDefault(),className:"z-9999 bg-transparent shadow-none border-0 p-3 lg:max-w-4xl shrink-0 max-h-[calc(100dvh-7rem)]! flex flex-col overflow-y-auto -translate-1/2",showCloseButton:!1,children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{className:"sr-only",children:"Post Builder Modal"}),!d&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-3",children:[jsxRuntime.jsx(GroupSelector,{user:n,store:u,onGroupSelect:g}),jsxRuntime.jsx(DialogClose,{asChild:!0,children:jsxRuntime.jsx(Button,{variant:"outline",size:"icon",children:jsxRuntime.jsx(X,{})})})]})]}),jsxRuntime.jsx(PostBuilderEditorInstance,{...b,store:u,placement:y})]})]})};var M=(n,u,d,p,m,g,y,b)=>{let _=document.documentElement,S=["light","dark"];function E(C){(Array.isArray(n)?n:[n]).forEach(A=>{let P=A==="class",O=P&&g?m.map(k=>g[k]||k):m;P?(_.classList.remove(...O),_.classList.add(g&&g[C]?g[C]:C)):_.setAttribute(A,C)}),T(C)}function T(C){b&&S.includes(C)&&(_.style.colorScheme=C)}function R(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(p)E(p);else try{let C=localStorage.getItem(u)||d,A=y&&C==="system"?R():C;E(A)}catch{}},x=React__namespace.createContext(void 0),U={setTheme:n=>{},themes:[]},z=()=>{var n;return(n=React__namespace.useContext(x))!=null?n:U};React__namespace.memo(({forcedTheme:n,storageKey:u,attribute:d,enableSystem:p,enableColorScheme:m,defaultTheme:g,value:y,themes:b,nonce:_,scriptProps:S})=>{let E=JSON.stringify([d,u,g,n,b,y,p,m]).slice(1,-1);return React__namespace.createElement("script",{...S,suppressHydrationWarning:!0,nonce:typeof window>"u"?_:"",dangerouslySetInnerHTML:{__html:`(${M.toString()})(${E})`}})});const Toaster=({...n})=>{const{theme:u="system"}=z();return jsxRuntime.jsx(Toaster$1,{theme:u,className:"toaster group",style:{"--normal-bg":"var(--popover)","--normal-text":"var(--popover-foreground)","--normal-border":"var(--border)"},...n})};function AnalyticsSessionProvider({editorType:n,placement:u,sessionId:d,children:p}){return jsxRuntime.jsx(AnalyticsSessionContext.Provider,{value:{sessionId:d,editorType:n,placement:u},children:p})}const PostBuilderEditor=({placement:n=EditorPlacement.Feed,groupId:u,postId:d,user:p,hideGroupSelector:m=!1,clearOnSuccess:g=!0,openModal:y,onModalOpenChange:b,isSubmitting:_,onCreatePost:S,onVoiceComment:E,onGroupSelect:T,onDirtyStateChange:R,onReady:C,disableNavigationWarning:A})=>{const[P,O]=React.useState(EditorTypes.Media),[k,L]=React.useState(""),N=useAnalyticsStore($=>$.createSession),I=useAnalyticsStore($=>$.deleteSession),B=useAnalyticsStore($=>$.trackEditorFocus),{editor:D,actions:W,store:F,isMounted:K,saveBeforeSwitch:Z,keepEditing:ee,saveDraft:q,discardDraft:Q}=usePostBuilderEditor({editorType:P,placement:n,groupId:u,postId:d,user:p,disableNavigationWarning:A}),Y=React.useCallback($=>{Z(),O($)},[Z]),te=React.useMemo(()=>({editor:D}),[D]);React.useEffect(()=>{if(n===EditorPlacement.Modal&&!y)return;const $=N(EditorTypes.Media,n);return L($),()=>{I($)}},[N,I,y,n]),React.useEffect(()=>{const $=V=>{if(!D)return;const{newSessionId:J}=V.detail;L(J),D.isFocused&&B(J)};return window.addEventListener(PostBuilderEvents.POST_SESSION_ROTATED,$),()=>{window.removeEventListener(PostBuilderEvents.POST_SESSION_ROTATED,$)}},[D,B]),React.useEffect(()=>{if(!D||!k)return;const $=requestAnimationFrame(()=>{D.view?.dom&&(D.view.dom.setAttribute("data-session-id",k),D.view.dom.setAttribute("data-editor-type",P))});return()=>cancelAnimationFrame($)},[D,k,P]);const j=React.useRef(!1);React.useEffect(()=>{if(!D||!R)return;const $=()=>{const V=P===EditorTypes.Poll?!isPollEmpty(D.getJSON()):!D.isEmpty;V!==j.current&&(j.current=V,R(V))};return D.on("update",$),()=>{D.off("update",$)}},[D,R,P]);const H=React.useRef(!1);return React.useEffect(()=>{!D||H.current||!C||(H.current=!0,C({saveDraft:q,discardDraft:Q,keepEditing:ee}))},[D,C,q,Q,ee]),!K||!D?jsxRuntime.jsx(EditorSkeleton,{}):jsxRuntime.jsx(AnalyticsSessionProvider,{sessionId:k,editorType:P,placement:n,children:jsxRuntime.jsxs("div",{className:"max-w-full w-full","data-theme":"select-post-builder",children:[jsxRuntime.jsx(react.EditorContext.Provider,{value:te,children:y?jsxRuntime.jsx(PostBuilderEditorInstanceWithDialog,{placement:n,hideGroupSelector:m,user:p,editor:D,editorTab:P,onSwitchEditor:Y,store:F,actions:W,open:y,onOpenChange:b,onCreatePost:S,onVoiceComment:E,isSubmitting:_,clearOnSuccess:g,onGroupSelect:T}):jsxRuntime.jsxs("div",{className:"prose-blockquote: flex-1 flex flex-col space-y-3 max-w-full max-h-[calc(100dvh-7rem)]",children:[!m&&jsxRuntime.jsx(GroupSelector,{user:p,store:F,onGroupSelect:T}),jsxRuntime.jsx(PostBuilderEditorInstance,{editor:D,actions:W,editorTab:P,onSwitchEditor:Y,store:F,isSubmitting:_,onCreatePost:S,onVoiceComment:E,clearOnSuccess:g,placement:n})]})}),jsxRuntime.jsx(Toaster,{position:"top-center"})]})})},EditorSkeleton=()=>jsxRuntime.jsx("div",{className:"max-w-full w-full","data-theme":"select-post-builder",children:jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-8 w-48"}),jsxRuntime.jsxs("div",{className:"min-h-60 w-full flex flex-col overflow-hidden rounded-lg border",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 rounded-b-none"}),jsxRuntime.jsx(Separator,{}),jsxRuntime.jsx(Skeleton,{className:"h-44 rounded-none"}),jsxRuntime.jsx(Separator,{}),jsxRuntime.jsx(Skeleton,{className:"h-[47px] rounded-t-none flex items-center justify-end p-2",children:jsxRuntime.jsx(Skeleton,{className:"h-full w-20 bg-accent-foreground/20"})})]})]})}),translationFallback={addKey:"Add",cancelKey:"Cancel",deleteKey:"Delete",editKey:"Edit",updateKey:"Update",insertKey:"Insert",uploadKey:"Upload",postKey:"Post",crossPostKey:"Cross-post to groups you #mention?",postTabKey:"Post",blogTabKey:"Blog",pollTabKey:"Poll",alignLeftKey:"Align Left",alignCenterKey:"Align Center",alignRightKey:"Align Right",undoKey:"Undo",redoKey:"Redo",headingOptionsKey:"Heading Options",paragraphKey:"Paragraph",heading1Key:"Heading 1",heading2Key:"Heading 2",heading3Key:"Heading 3",boldKey:"Bold",italicKey:"Italic",strikethroughKey:"Strikethrough",bulletListKey:"Bullet List",orderedListKey:"Ordered List",blockquoteKey:"BlockQuote",codeKey:"Code",codeBlockKey:"Codeblock",moreOptionsKey:"More formatting options",insertImageKey:"Insert Image",insertVideoKey:"Insert Video",insertAudioKey:"Insert Audio",searchGifOrImagesKey:"Search Gif/Images Online",mediaSearchTitleKey:"Search Media",gifSearchKey:"GIF Search",imageSearchKey:"Image Search",searchGifPlaceholder:"Search GIFs...",searchIMagePlaceholder:"Search Images...",addLinkPreviewKey:"Add link with preview",editLinkKey:"Edit Link",visitLinkKey:"Visit Link",unsetLinkKey:"Unset Link",linkInputLabelKey:"Link URL",linkTextInputLabelKey:"Text to display",invalidLinkKey:"Please enter a valid URL",insertLinkKey:"Insert Link",updateLinkKey:"Update Link",removeLinkPreviewKey:"Remove Link Preview",fetchingMetadataKey:"Fetching Link Metadata...",addTextOptionKey:"Add text option",enterTextOptionKey:"Enter a text option...",pressEnterToAddKey:"Press Enter to add",cancelUploadTitleKey:"Cancel upload?",cancelUploadDescriptionKey:"Switching tabs will cancel your current upload and remove the media from your post.",stayKey:"Stay",continueKey:"Continue",uploadsInProgressKey:"Please wait for all uploads to finish"},defaultTranslationKeyMappings={addKey:"general_add",cancelKey:"cancel",deleteKey:"general_delete",editKey:"general_edit",updateKey:"general_update",insertKey:"general_insert",uploadKey:"general_upload",postKey:"general_send_post",crossPostKey:"cross_mention_title",postTabKey:"post_builder_tab_post_title",blogTabKey:"post_builder_tab_blog_title",pollTabKey:"post_builder_tab_poll_title",alignLeftKey:"post_builder_formatting_tooltip_align_left",alignCenterKey:"post_builder_formatting_tooltip_align_center",alignRightKey:"post_builder_formatting_tooltip_align_right",undoKey:"post_builder_formatting_tooltip_undo",redoKey:"post_builder_formatting_tooltip_redo",headingOptionsKey:"post_builder_formatting_tooltip_heading_options",paragraphKey:"post_builder_formatting_tooltip_paragraph",heading1Key:"post_builder_formatting_tooltip_heading_one",heading2Key:"post_builder_formatting_tooltip_heading_two",heading3Key:"post_builder_formatting_tooltip_heading_three",boldKey:"post_builder_formatting_tooltip_bold",italicKey:"post_builder_formatting_tooltip_italic",strikethroughKey:"post_builder_formatting_tooltip_strikethrough",bulletListKey:"post_builder_formatting_tooltip_list_bullet",orderedListKey:"post_builder_formatting_tooltip_list_ordered",blockquoteKey:"post_builder_formatting_tooltip_blockquote",codeKey:"post_builder_formatting_tooltip_code",codeBlockKey:"post_builder_formatting_tooltip_codeblock",moreOptionsKey:"post_builder_formatting_tooltip_more_options",insertImageKey:"post_builder_tooltip_insert_image",insertVideoKey:"post_builder_tooltip_insert_video",insertAudioKey:"post_builder_tooltip_insert_audio",searchGifOrImagesKey:"post_builder_tooltip_search_gif_or_image",mediaSearchTitleKey:"post_builder_media_search_modal_title",gifSearchKey:"post_builder_media_search_tab_gif_title",imageSearchKey:"post_builder_media_search_tab_image_title",searchGifPlaceholder:"post_builder_media_search_input_gif_placeholder",searchIMagePlaceholder:"post_builder_media_search_input_image_placeholder",addLinkPreviewKey:"post_builder_tooltip_link_add",editLinkKey:"post_builder_tooltip_link_edit",visitLinkKey:"post_builder_tooltip_link_visit",unsetLinkKey:"post_builder_tooltip_link_unset",linkInputLabelKey:"post_builder_link_input_label",linkTextInputLabelKey:"post_builder_link_text_input_label",invalidLinkKey:"post_builder_link_input_invalid",insertLinkKey:"post_builder_link_insert_modal_title",updateLinkKey:"post_builder_link_update_modal_title",removeLinkPreviewKey:"post_builder_tooltip_link_remove_preview",fetchingMetadataKey:"post_builder_link_loading_metadata_placeholder",addTextOptionKey:"post_builder_poll_add_text_option_input_label",enterTextOptionKey:"post_builder_poll_add_text_option_input_placeholder",pressEnterToAddKey:"post_builder_poll_add_text_option_input_command",cancelUploadTitleKey:"post_builder_upload_guard_cancel_title",cancelUploadDescriptionKey:"post_builder_upload_guard_cancel_description",stayKey:"post_builder_upload_guard_stay",continueKey:"post_builder_upload_guard_continue",uploadsInProgressKey:"post_builder_upload_guard_in_progress"},PostBuilderProvider=({children:n,apiBaseURL:u,authToken:d,toI18N:p,i18nKeys:m=defaultTranslationKeyMappings,logEvent:g})=>{const y=useAnalyticsStore(E=>E.initialize),b=React.useCallback((E,T)=>{const C={...defaultTranslationKeyMappings,...m}[E],A=p(C);if(A!==C)return A;const P=translationFallback[E];return P||T||E},[p,m]),_=React.useMemo(()=>{const E=new CoreApi(u.core,d,p),T=new MFSApi(u.mfs,d,p),R=new FilestoreApi(u.fileStore,d,p);return E.initApi(),T.initApi(),R.initApi(),{core:E,mfs:T,fileStore:R}},[d,u,p]);React.useEffect(()=>{y(g,{debug:!0,enabled:!0})},[y,g]);const S=React.useMemo(()=>({authToken:d,t:b,i18nKeys:m,api:_,logEvent:g}),[d,b,m,_,g]);return jsxRuntime.jsx(PostBuilderContext.Provider,{value:S,children:n})};exports.EditorPlacement=EditorPlacement;exports.PostBuilderEditor=PostBuilderEditor;exports.PostBuilderEvents=PostBuilderEvents;exports.PostBuilderProvider=PostBuilderProvider;
109
+ prose-codeblock:text-sm prose-a:text-blue-500 focus:outline-none`)}}),createEditorActions=n=>({undo:()=>n?.chain().focus().undo().run(),redo:()=>n?.chain().focus().redo().run(),toggleHeading:u=>n?.chain().focus().toggleHeading({level:u}).run(),setParagraph:()=>n?.chain().focus().setParagraph().run(),toggleBold:()=>n?.chain().focus().toggleBold().run(),toggleItalic:()=>n?.chain().focus().toggleItalic().run(),toggleStrikethrough:()=>n?.chain().focus().toggleStrike().run(),toggleUnderline:()=>n?.chain().focus().toggleUnderline().run(),insertLink:u=>n?.chain().focus().setLink({href:u}).run(),toggleBulletList:()=>n?.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>n?.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>n?.chain().focus().toggleBlockquote().run(),toggleCode:()=>n?.chain().focus().toggleCode().run(),toggleCodeBlock:()=>n?.chain().focus().toggleCodeBlock().run(),toggleTextAlign:u=>n?.chain().focus().setTextAlign(u).run(),insertPoll:()=>n?.chain().focus().insertContent({type:"poll"}).run(),insertMedia:(u,d)=>{n?.chain()?.focus()?.insertContent([{type:"media",attrs:{src:u,type:d}},{type:"paragraph"}])?.run()}}),initializePollEditor=n=>{n.chain().focus().insertContent({type:"paragraph"}).insertContent({type:"poll"}).command(({tr:u})=>{const{doc:d}=u;let p=-1;if(d.descendants((m,g)=>{if(m.type.name==="paragraph"&&p===-1)return p=g,!1}),p>=0){const m=d.nodeAt(p);if(m){const g=p+m.nodeSize-1,y=u.doc.resolve(g);u.setSelection(state.TextSelection.near(y))}}return!0}).run()},usePostBuilderEditor=({editorType:n,placement:u,groupId:d,postId:p,user:m,disableNavigationWarning:g})=>{const[,y]=React.useState(0),[b,_]=React.useState(!1),S=useApi(),E=React.useMemo(()=>createPostBuilderStore({groupId:d,postId:p}),[d,p]),{getTabContent:T,saveCurrentTabContent:R,clearContent:C}=usePersistence(u,d),A=React.useRef(!1),P=React.useRef(!1);React.useEffect(()=>{_(!0),y(W=>W+1)},[]);const O=React.useMemo(()=>!!T(n),[n,T]),k=react.useEditor({extensions:getExtensions({editorType:n,api:S,store:E,user:m}),content:T(n)??"",editorProps:getEditorProps(),onCreate:({editor:W})=>{E.getState().setEditor(W),n===EditorTypes.Blog&&W?.chain()?.focus("end")?.run(),n===EditorTypes.Media&&W?.chain()?.focus("end")?.run(),n===EditorTypes.Poll&&!O&&initializePollEditor(W),n===EditorTypes.Poll&&O&&W?.chain()?.focus("end")?.run()},onUnmount:({editor:W})=>{if(P.current||A.current){A.current=!1,P.current=!1;return}R(n,W)},immediatelyRender:!1,shouldRerenderOnTransaction:!1},[n,u,b]);React.useEffect(()=>{if(g)return;const W=F=>{k&&!k.isEmpty&&F.preventDefault()};return window.addEventListener("beforeunload",W),()=>window.removeEventListener("beforeunload",W)},[k,g]),React.useEffect(()=>{let W;if(!b||!k||!k?.view||n===EditorTypes.Poll)return;const F=T(n);return F&&k?.isEditable&&(W=setTimeout(()=>{k.commands.setContent(F),k.commands.rehydrateLinkPreviews()},0)),()=>{W&&clearTimeout(W)}},[k,n,u,T,b]);const L=React.useMemo(()=>k?createEditorActions(k):null,[k]),N=React.useCallback(()=>{k&&!k.isDestroyed&&(R(n,k),A.current=!0)},[k,n,R]),I=React.useCallback(()=>{k&&!k.isDestroyed&&R(n,k)},[k,n,R]),B=React.useCallback(()=>{P.current=!0,C()},[C]),D=React.useCallback(()=>{k&&!k.isDestroyed&&k?.commands?.focus("end")},[k]);return{editor:k,actions:L,store:E,isMounted:b,saveBeforeSwitch:N,saveDraft:I,discardDraft:B,keepEditing:D}},getEditorData=n=>({html:n?.getHTML(),json:n?.getJSON(),text:n?.getText()}),getCommonPayload=n=>({postId:v4(),timestamp:new Date().getTime(),specialType:SpecialType.POST,...n&&{conversationId:n}}),getMentionDataPayload=n=>({mentionData:findByType(n,"mention")?.map(p=>omit(omitBy(p.attrs,isNil),["mentionSuggestionChar","label"]))?.filter(p=>Object.keys(p).length>0)}),getMediaItemsPayload=n=>({items:findByType(n,"media").map(p=>p.attrs?.payload).filter(Boolean)}),isLinkMark=n=>!!n.marks?.some(u=>u.type==="customLink"),getLinkItemsPayload=n=>{const d=find(n,m=>isLinkMark(m))?.flatMap(m=>m?.marks?.filter(g=>g?.type==="customLink"&&g?.attrs?.previewPayload));return{items:Array.of(d?.at(-1)?.attrs?.previewPayload).filter(Boolean)}},getPollItemsPayload=n=>({items:findByType(n,"poll")[0].attrs?.choices}),isValidItem=n=>{if(!n)return!1;const u=n,d=n,p=u?.linkUrl,m=d?.sources,g=m?.original?.url||m?.thumbnail?.url;return!!(p||g)},generateHtmlPostPayload=({editor:n,sendCrossMention:u,groupId:d})=>{const{html:p,json:m}=getEditorData(n),g=getCommonPayload(d),{mentionData:y}=getMentionDataPayload(m),b=findFirstByType(m,"media"),_=findFirstByType(m,"iframe"),S=findFirstByType(m,"text"),T=S?.marks?.some(k=>k.type==="customLink")?S?.marks?.find(k=>k.type==="customLink")?.attrs?.previewPayload:null,R=find(m,k=>k?.type==="text"&&(k?.marks?.some(L=>L?.type!=="customLink")??!0))?.at(0),A=isOnlyContentNode(m,"iframe")?_?.attrs?.previewPayload?.linkTitle??_?.attrs?.src??"":R?.text??S?.text??"",P=[b?.attrs?.payload,_?.attrs?.previewPayload,T].filter(isValidItem)?.filter((k,L)=>L===0),O=p;return{...g,type:P?.length>0?NewPostType.NEW_POST_MEDIA:NewPostType.NEW_POST_MESSAGE,body:A,items:P,htmlBody:O,sendCrossMention:u,mentionData:y}},generateMediaPostPayload=({editor:n,sendCrossMention:u,groupId:d})=>{const{json:p,text:m}=getEditorData(n),g=getCommonPayload(d),y=m?.trim()??"",{mentionData:b}=getMentionDataPayload(p),{items:_}=getMediaItemsPayload(p),{items:S}=getLinkItemsPayload(p),E=_?.length>0?_:S?.length>0?S:[];return!y&&_.length===0?{error:"Your post is empty. Add text or media to share your thoughts."}:{...g,type:_?.length>0?NewPostType.NEW_POST_MEDIA:S?.length>0?NewPostType.NEW_POST_LINK:NewPostType.NEW_POST_MESSAGE,body:y,items:E,mentionData:b,sendCrossMention:u}},generatePollPostPayload=({editor:n,sendCrossMention:u,groupId:d})=>{const{json:p,text:m}=getEditorData(n),g=getCommonPayload(d),y=m,{mentionData:b}=getMentionDataPayload(p),{items:_}=getPollItemsPayload(p),S=_.length===1?_.concat(_).map((E,T)=>({...E,key:E?.key??v4(),option_id:T===0?E.option_id:v4(),option_color:OPTION_COLORS[T%OPTION_COLORS.length]})):_;return{...g,type:NewPostType.NEW_POST_POLL,body:y,items:S,mentionData:b,sendCrossMention:u}},generateCreatePostPayload=(n,u)=>{switch(n){case EditorTypes.Blog:return generateHtmlPostPayload(u);case EditorTypes.Media:return generateMediaPostPayload(u);case EditorTypes.Poll:return generatePollPostPayload(u);default:return null}},PostBuilderEditorInstance=({editor:n,actions:u,editorTab:d,onSwitchEditor:p,isSubmitting:m,clearOnSuccess:g,onCreatePost:y,onVoiceComment:b,className:_,store:S,placement:E})=>{const[T,R]=React.useState(!1),[C,A]=React.useState(!0),[P,O]=React.useState(null),{trackPublish:k}=useAnalyticsTracking(),{t:L}=usePostBuilder(),N=useStore(S,Y=>Y.groupId)??void 0,{clearContent:I}=usePersistence(E,N);useHostAnalyticsBridge(),useEditorTracking({editor:n,editorType:d});const B=React.useRef(null),[D,W]=React.useState(),F=React.useCallback(Y=>{if(n&&hasActiveUploads(n)){O(Y);return}B.current&&W(B.current.offsetHeight),p(Y)},[n,p]);React.useEffect(()=>{if(D&&n){const Y=()=>W(void 0),te=setTimeout(Y,50);return n.once("update",Y),()=>{clearTimeout(te),n.off("update",Y)}}},[D,n]),React.useEffect(()=>{const Y=()=>{const{groupId:j,selectedGroupId:H}=S.getState();A(!!(j||H))};Y();const te=S.subscribe(Y);return()=>te()},[S]);const K=Y=>{Y.preventDefault(),R(!0)},Z=Y=>{Y.preventDefault(),R(!1)},ee=Y=>{Y.preventDefault(),R(!1)},q=()=>{const Y=document.querySelector('[aria-label="Select group"]');Y&&Y.click()},Q=React.useCallback(Y=>{if(!n)return;const te=n?.getHTML(),j=n?.getJSON(),H=n?.getText(),{selectedGroupId:$,groupId:V}=S.getState(),re=generateCreatePostPayload(d,{editor:n,sendCrossMention:Y,groupId:$||V||void 0}),ie=re?.type===NewPostType.NEW_POST_POLL;if(re?.error){toast.error(re.error);return}if(!re?.postId)return;if(ie&&re.items?.length===0)return toast.warning(`At least ${POLL_LIMITS.MIN} option is mandatory to create a poll post`);typeof window<"u"&&window.dispatchEvent(new CustomEvent(PostBuilderEvents.POST_PUBLISH_ATTEMPTED,{detail:{postId:re.postId,postType:re.type}}));const se=getEditorMetrics(n);k({editorType:d,status:"attempted",postId:re?.postId,postType:re?.type,...se}),y?.({payload:re,html:te,json:j,text:H}),g&&(I(),d===EditorTypes.Poll?n?.chain()?.focus()?.setContent({type:"doc",content:[{type:"paragraph"},{type:"poll"}]})?.run():n?.chain()?.focus()?.clearContent()?.run())},[I,g,n,d,y,S,k]);return React.useEffect(()=>{const Y=te=>{if((te.ctrlKey||te.metaKey)&&te.key==="Enter"){if(!n?.isFocused)return;if(te.preventDefault(),n&&hasActiveUploads(n)){toast.error(L("uploadsInProgressKey"));return}Q(!1)}};return window.addEventListener("keydown",Y),()=>window.removeEventListener("keydown",Y)},[n,Q]),jsxRuntime.jsxs("div",{ref:B,style:{minHeight:D?`${D}px`:void 0},className:cn("post-builder-editor bg-background border rounded-md overflow-hidden max-h-full grow flex flex-col transition-all duration-300 ease-in-out relative",E===EditorPlacement.Comment&&"min-h-32",_),children:[!C&&jsxRuntime.jsx("div",{className:"z-50 absolute inset-0 bg-foreground/30 backdrop-blur-xs flex items-center justify-center rounded-md pointer-events-none",children:jsxRuntime.jsx(Button,{variant:"outline",size:"lg",onClick:q,className:"pointer-events-auto cursor-pointer hover:animate-none animate-pulse",children:"Please select a group first"})}),E!==EditorPlacement.Comment&&jsxRuntime.jsx(EditorTypeTabs,{editorTab:d,onSwitchEditorTab:F}),jsxRuntime.jsx(Toolbar,{editor:n,actions:u,isSubmitting:m,onSubmit:Q,editorType:d,placement:E,onVoiceComment:b,children:jsxRuntime.jsxs("div",{className:"relative flex flex-col grow overflow-y-auto",children:[T&&jsxRuntime.jsx("div",{className:"pointer-events-none z-50 absolute inset-0 bg-accent/10 border border-dashed flex items-center justify-center",children:jsxRuntime.jsx("h2",{children:"Drop Here"})}),jsxRuntime.jsxs("div",{onDragOver:K,onDragLeave:Z,onDrop:ee,className:"flex flex-col grow",children:[jsxRuntime.jsx(DragHandle__default.default,{editor:n,className:cn("pr-2",d!==EditorTypes.Blog&&"hidden size-0 overflow-hidden pointer-events-none"),children:jsxRuntime.jsx(Button,{variant:"ghost",className:"bg-white cursor-grab py-0.5 px-0 border size-auto",children:jsxRuntime.jsx(GripVertical,{className:"text-muted-foreground"})})}),jsxRuntime.jsx(react.EditorContent,{className:"grow","data-theme":"select-post-builder",editor:n})]})]})}),jsxRuntime.jsx(Dialog,{open:!!P,onOpenChange:Y=>!Y&&O(null),children:jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:L("cancelUploadTitleKey")}),jsxRuntime.jsx(DialogDescription,{children:L("cancelUploadDescriptionKey")})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(DialogClose,{asChild:!0,children:jsxRuntime.jsx(Button,{variant:"outline",children:L("stayKey")})}),jsxRuntime.jsx(Button,{variant:"destructive",onClick:()=>{P&&(n.commands.deleteAllUploadingMedia(),B.current&&W(B.current.offsetHeight),p(P),O(null))},children:L("continueKey")})]})]})})]})},PostBuilderEditorInstanceWithDialog=({user:n,store:u,hideGroupSelector:d,open:p,onOpenChange:m,onGroupSelect:g,placement:y,...b})=>{const{trackAbandon:_}=useAnalyticsTracking(),S=E=>{if(m(E),E)return;const T=getEditorMetrics(b.editor);_({editorType:b.editorTab,abandonReason:"user_closed",contentLength:T?.characterCount??0,hasUnsavedChanges:T?.hasUnsavedChanges??!1})};return jsxRuntime.jsxs(Dialog,{modal:!1,open:p,onOpenChange:S,children:[jsxRuntime.jsx("div",{className:"z-999 fixed inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>S(!1)}),jsxRuntime.jsxs(DialogContent,{onInteractOutside:E=>E.preventDefault(),onOpenAutoFocus:E=>E.preventDefault(),className:"z-9999 bg-transparent shadow-none border-0 p-3 lg:max-w-4xl shrink-0 max-h-[calc(100dvh-7rem)]! flex flex-col overflow-y-auto -translate-1/2",showCloseButton:!1,children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{className:"sr-only",children:"Post Builder Modal"}),!d&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-3",children:[jsxRuntime.jsx(GroupSelector,{user:n,store:u,onGroupSelect:g}),jsxRuntime.jsx(DialogClose,{asChild:!0,children:jsxRuntime.jsx(Button,{variant:"outline",size:"icon",children:jsxRuntime.jsx(X,{})})})]})]}),jsxRuntime.jsx(PostBuilderEditorInstance,{...b,store:u,placement:y})]})]})};var M=(n,u,d,p,m,g,y,b)=>{let _=document.documentElement,S=["light","dark"];function E(C){(Array.isArray(n)?n:[n]).forEach(A=>{let P=A==="class",O=P&&g?m.map(k=>g[k]||k):m;P?(_.classList.remove(...O),_.classList.add(g&&g[C]?g[C]:C)):_.setAttribute(A,C)}),T(C)}function T(C){b&&S.includes(C)&&(_.style.colorScheme=C)}function R(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(p)E(p);else try{let C=localStorage.getItem(u)||d,A=y&&C==="system"?R():C;E(A)}catch{}},x=React__namespace.createContext(void 0),U={setTheme:n=>{},themes:[]},z=()=>{var n;return(n=React__namespace.useContext(x))!=null?n:U};React__namespace.memo(({forcedTheme:n,storageKey:u,attribute:d,enableSystem:p,enableColorScheme:m,defaultTheme:g,value:y,themes:b,nonce:_,scriptProps:S})=>{let E=JSON.stringify([d,u,g,n,b,y,p,m]).slice(1,-1);return React__namespace.createElement("script",{...S,suppressHydrationWarning:!0,nonce:typeof window>"u"?_:"",dangerouslySetInnerHTML:{__html:`(${M.toString()})(${E})`}})});const Toaster=({...n})=>{const{theme:u="system"}=z();return jsxRuntime.jsx(Toaster$1,{theme:u,className:"toaster group",style:{"--normal-bg":"var(--popover)","--normal-text":"var(--popover-foreground)","--normal-border":"var(--border)"},...n})};function AnalyticsSessionProvider({editorType:n,placement:u,sessionId:d,children:p}){return jsxRuntime.jsx(AnalyticsSessionContext.Provider,{value:{sessionId:d,editorType:n,placement:u},children:p})}const PostBuilderEditor=({placement:n=EditorPlacement.Feed,groupId:u,postId:d,user:p,hideGroupSelector:m=!1,clearOnSuccess:g=!0,openModal:y,onModalOpenChange:b,isSubmitting:_,onCreatePost:S,onVoiceComment:E,onGroupSelect:T,onDirtyStateChange:R,onReady:C,disableNavigationWarning:A})=>{const[P,O]=React.useState(EditorTypes.Media),[k,L]=React.useState(""),N=useAnalyticsStore($=>$.createSession),I=useAnalyticsStore($=>$.deleteSession),B=useAnalyticsStore($=>$.trackEditorFocus),{editor:D,actions:W,store:F,isMounted:K,saveBeforeSwitch:Z,keepEditing:ee,saveDraft:q,discardDraft:Q}=usePostBuilderEditor({editorType:P,placement:n,groupId:u,postId:d,user:p,disableNavigationWarning:A}),Y=React.useCallback($=>{Z(),O($)},[Z]),te=React.useMemo(()=>({editor:D}),[D]);React.useEffect(()=>{if(n===EditorPlacement.Modal&&!y)return;const $=N(EditorTypes.Media,n);return L($),()=>{I($)}},[N,I,y,n]),React.useEffect(()=>{const $=V=>{if(!D)return;const{newSessionId:J}=V.detail;L(J),D.isFocused&&B(J)};return window.addEventListener(PostBuilderEvents.POST_SESSION_ROTATED,$),()=>{window.removeEventListener(PostBuilderEvents.POST_SESSION_ROTATED,$)}},[D,B]),React.useEffect(()=>{if(!D||!k)return;const $=requestAnimationFrame(()=>{D.view?.dom&&(D.view.dom.setAttribute("data-session-id",k),D.view.dom.setAttribute("data-editor-type",P))});return()=>cancelAnimationFrame($)},[D,k,P]);const j=React.useRef(!1);React.useEffect(()=>{if(!D||!R)return;const $=()=>{const V=P===EditorTypes.Poll?!isPollEmpty(D.getJSON()):!D.isEmpty;V!==j.current&&(j.current=V,R(V))};return D.on("update",$),()=>{D.off("update",$)}},[D,R,P]);const H=React.useRef(!1);return React.useEffect(()=>{!D||H.current||!C||(H.current=!0,C({saveDraft:q,discardDraft:Q,keepEditing:ee}))},[D,C,q,Q,ee]),!K||!D?jsxRuntime.jsx(EditorSkeleton,{}):jsxRuntime.jsx(AnalyticsSessionProvider,{sessionId:k,editorType:P,placement:n,children:jsxRuntime.jsxs("div",{className:"max-w-full w-full","data-theme":"select-post-builder",children:[jsxRuntime.jsx(react.EditorContext.Provider,{value:te,children:y?jsxRuntime.jsx(PostBuilderEditorInstanceWithDialog,{placement:n,hideGroupSelector:m,user:p,editor:D,editorTab:P,onSwitchEditor:Y,store:F,actions:W,open:y,onOpenChange:b,onCreatePost:S,onVoiceComment:E,isSubmitting:_,clearOnSuccess:g,onGroupSelect:T}):jsxRuntime.jsxs("div",{className:"prose-blockquote: flex-1 flex flex-col space-y-3 max-w-full max-h-[calc(100dvh-7rem)]",children:[!m&&jsxRuntime.jsx(GroupSelector,{user:p,store:F,onGroupSelect:T}),jsxRuntime.jsx(PostBuilderEditorInstance,{editor:D,actions:W,editorTab:P,onSwitchEditor:Y,store:F,isSubmitting:_,onCreatePost:S,onVoiceComment:E,clearOnSuccess:g,placement:n})]})}),jsxRuntime.jsx(Toaster,{position:"top-center"})]})})},EditorSkeleton=()=>jsxRuntime.jsx("div",{className:"max-w-full w-full","data-theme":"select-post-builder",children:jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-8 w-48"}),jsxRuntime.jsxs("div",{className:"min-h-60 w-full flex flex-col overflow-hidden rounded-lg border",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 rounded-b-none"}),jsxRuntime.jsx(Separator,{}),jsxRuntime.jsx(Skeleton,{className:"h-44 rounded-none"}),jsxRuntime.jsx(Separator,{}),jsxRuntime.jsx(Skeleton,{className:"h-[47px] rounded-t-none flex items-center justify-end p-2",children:jsxRuntime.jsx(Skeleton,{className:"h-full w-20 bg-accent-foreground/20"})})]})]})}),translationFallback={addKey:"Add",cancelKey:"Cancel",deleteKey:"Delete",editKey:"Edit",updateKey:"Update",insertKey:"Insert",uploadKey:"Upload",postKey:"Post",crossPostKey:"Cross-post to groups you #mention?",postTabKey:"Post",blogTabKey:"Blog",pollTabKey:"Poll",alignLeftKey:"Align Left",alignCenterKey:"Align Center",alignRightKey:"Align Right",undoKey:"Undo",redoKey:"Redo",headingOptionsKey:"Heading Options",paragraphKey:"Paragraph",heading1Key:"Heading 1",heading2Key:"Heading 2",heading3Key:"Heading 3",boldKey:"Bold",italicKey:"Italic",strikethroughKey:"Strikethrough",bulletListKey:"Bullet List",orderedListKey:"Ordered List",blockquoteKey:"BlockQuote",codeKey:"Code",codeBlockKey:"Codeblock",moreOptionsKey:"More formatting options",insertImageKey:"Insert Image",insertVideoKey:"Insert Video",insertAudioKey:"Insert Audio",searchGifOrImagesKey:"Search Gif/Images Online",mediaSearchTitleKey:"Search Media",gifSearchKey:"GIF Search",imageSearchKey:"Image Search",searchGifPlaceholder:"Search GIFs...",searchIMagePlaceholder:"Search Images...",addLinkPreviewKey:"Add link with preview",editLinkKey:"Edit Link",visitLinkKey:"Visit Link",unsetLinkKey:"Unset Link",linkInputLabelKey:"Link URL",linkTextInputLabelKey:"Text to display",invalidLinkKey:"Please enter a valid URL",insertLinkKey:"Insert Link",updateLinkKey:"Update Link",removeLinkPreviewKey:"Remove Link Preview",fetchingMetadataKey:"Fetching Link Metadata...",addTextOptionKey:"Add text option",enterTextOptionKey:"Enter a text option...",pressEnterToAddKey:"Press Enter to add",cancelUploadTitleKey:"Cancel upload?",cancelUploadDescriptionKey:"Switching tabs will cancel your current upload and remove the media from your post.",stayKey:"Stay",continueKey:"Continue",uploadsInProgressKey:"Please wait for all uploads to finish"},defaultTranslationKeyMappings={addKey:"general_add",cancelKey:"cancel",deleteKey:"general_delete",editKey:"general_edit",updateKey:"general_update",insertKey:"general_insert",uploadKey:"general_upload",postKey:"general_send_post",crossPostKey:"cross_mention_title",postTabKey:"post_builder_tab_post_title",blogTabKey:"post_builder_tab_blog_title",pollTabKey:"post_builder_tab_poll_title",alignLeftKey:"post_builder_formatting_tooltip_align_left",alignCenterKey:"post_builder_formatting_tooltip_align_center",alignRightKey:"post_builder_formatting_tooltip_align_right",undoKey:"post_builder_formatting_tooltip_undo",redoKey:"post_builder_formatting_tooltip_redo",headingOptionsKey:"post_builder_formatting_tooltip_heading_options",paragraphKey:"post_builder_formatting_tooltip_paragraph",heading1Key:"post_builder_formatting_tooltip_heading_one",heading2Key:"post_builder_formatting_tooltip_heading_two",heading3Key:"post_builder_formatting_tooltip_heading_three",boldKey:"post_builder_formatting_tooltip_bold",italicKey:"post_builder_formatting_tooltip_italic",strikethroughKey:"post_builder_formatting_tooltip_strikethrough",bulletListKey:"post_builder_formatting_tooltip_list_bullet",orderedListKey:"post_builder_formatting_tooltip_list_ordered",blockquoteKey:"post_builder_formatting_tooltip_blockquote",codeKey:"post_builder_formatting_tooltip_code",codeBlockKey:"post_builder_formatting_tooltip_codeblock",moreOptionsKey:"post_builder_formatting_tooltip_more_options",insertImageKey:"post_builder_tooltip_insert_image",insertVideoKey:"post_builder_tooltip_insert_video",insertAudioKey:"post_builder_tooltip_insert_audio",searchGifOrImagesKey:"post_builder_tooltip_search_gif_or_image",mediaSearchTitleKey:"post_builder_media_search_modal_title",gifSearchKey:"post_builder_media_search_tab_gif_title",imageSearchKey:"post_builder_media_search_tab_image_title",searchGifPlaceholder:"post_builder_media_search_input_gif_placeholder",searchIMagePlaceholder:"post_builder_media_search_input_image_placeholder",addLinkPreviewKey:"post_builder_tooltip_link_add",editLinkKey:"post_builder_tooltip_link_edit",visitLinkKey:"post_builder_tooltip_link_visit",unsetLinkKey:"post_builder_tooltip_link_unset",linkInputLabelKey:"post_builder_link_input_label",linkTextInputLabelKey:"post_builder_link_text_input_label",invalidLinkKey:"post_builder_link_input_invalid",insertLinkKey:"post_builder_link_insert_modal_title",updateLinkKey:"post_builder_link_update_modal_title",removeLinkPreviewKey:"post_builder_tooltip_link_remove_preview",fetchingMetadataKey:"post_builder_link_loading_metadata_placeholder",addTextOptionKey:"post_builder_poll_add_text_option_input_label",enterTextOptionKey:"post_builder_poll_add_text_option_input_placeholder",pressEnterToAddKey:"post_builder_poll_add_text_option_input_command",cancelUploadTitleKey:"post_builder_upload_guard_cancel_title",cancelUploadDescriptionKey:"post_builder_upload_guard_cancel_description",stayKey:"post_builder_upload_guard_stay",continueKey:"post_builder_upload_guard_continue",uploadsInProgressKey:"post_builder_upload_guard_in_progress"},PostBuilderProvider=({children:n,apiBaseURL:u,authToken:d,toI18N:p,i18nKeys:m=defaultTranslationKeyMappings,logEvent:g})=>{const y=useAnalyticsStore(E=>E.initialize),b=React.useCallback((E,T)=>{const C={...defaultTranslationKeyMappings,...m}[E],A=p(C);if(A!==C)return A;const P=translationFallback[E];return P||T||E},[p,m]),_=React.useMemo(()=>{const E=new CoreApi(u.core,d,p),T=new MFSApi(u.mfs,d,p),R=new FilestoreApi(u.fileStore,d,p);return E.initApi(),T.initApi(),R.initApi(),{core:E,mfs:T,fileStore:R}},[d,u,p]);React.useEffect(()=>{y(g,{debug:!0,enabled:!0})},[y,g]);const S=React.useMemo(()=>({authToken:d,t:b,i18nKeys:m,api:_,logEvent:g}),[d,b,m,_,g]);return jsxRuntime.jsx(PostBuilderContext.Provider,{value:S,children:n})};exports.EditorPlacement=EditorPlacement;exports.PostBuilderEditor=PostBuilderEditor;exports.PostBuilderEvents=PostBuilderEvents;exports.PostBuilderProvider=PostBuilderProvider;
@@ -34758,25 +34758,25 @@ const getStarterKitConfig = ({
34758
34758
  user: m,
34759
34759
  disableNavigationWarning: g
34760
34760
  }) => {
34761
- const [, y] = useState(0), [b, E] = useState(!1), T = useApi(), S = useMemo(() => createPostBuilderStore({ groupId: d, postId: p }), [d, p]), { getTabContent: A, saveCurrentTabContent: _ } = usePersistence(u, d), P = useRef(!1), C = useRef(!1);
34761
+ const [, y] = useState(0), [b, E] = useState(!1), T = useApi(), S = useMemo(() => createPostBuilderStore({ groupId: d, postId: p }), [d, p]), { getTabContent: A, saveCurrentTabContent: _, clearContent: P } = usePersistence(u, d), C = useRef(!1), R = useRef(!1);
34762
34762
  useEffect(() => {
34763
- E(!0), y((D) => D + 1);
34763
+ E(!0), y((W) => W + 1);
34764
34764
  }, []);
34765
- const R = useMemo(() => !!A(n), [n, A]), O = useEditor(
34765
+ const O = useMemo(() => !!A(n), [n, A]), k = useEditor(
34766
34766
  {
34767
34767
  extensions: getExtensions({ editorType: n, api: T, store: S, user: m }),
34768
34768
  content: A(n) ?? "",
34769
34769
  editorProps: getEditorProps(),
34770
- onCreate: ({ editor: D }) => {
34771
- S.getState().setEditor(D), n === EditorTypes.Blog && D?.chain()?.focus("end")?.run(), n === EditorTypes.Media && D?.chain()?.focus("end")?.run(), n === EditorTypes.Poll && !R && initializePollEditor(D), n === EditorTypes.Poll && R && D?.chain()?.focus("end")?.run();
34770
+ onCreate: ({ editor: W }) => {
34771
+ S.getState().setEditor(W), n === EditorTypes.Blog && W?.chain()?.focus("end")?.run(), n === EditorTypes.Media && W?.chain()?.focus("end")?.run(), n === EditorTypes.Poll && !O && initializePollEditor(W), n === EditorTypes.Poll && O && W?.chain()?.focus("end")?.run();
34772
34772
  },
34773
34773
  // onBlur: ({ editor }) => saveCurrentTabContent(editorType, editor),
34774
- onUnmount: ({ editor: D }) => {
34775
- if (C.current || P.current) {
34776
- P.current = !1, C.current = !1;
34774
+ onUnmount: ({ editor: W }) => {
34775
+ if (R.current || C.current) {
34776
+ C.current = !1, R.current = !1;
34777
34777
  return;
34778
34778
  }
34779
- _(n, D);
34779
+ _(n, W);
34780
34780
  },
34781
34781
  immediatelyRender: !1,
34782
34782
  // Important: Only render after mount to avoid SSR issues
@@ -34787,38 +34787,38 @@ const getStarterKitConfig = ({
34787
34787
  );
34788
34788
  useEffect(() => {
34789
34789
  if (g) return;
34790
- const D = (W) => {
34791
- O && !O.isEmpty && W.preventDefault();
34790
+ const W = ($) => {
34791
+ k && !k.isEmpty && $.preventDefault();
34792
34792
  };
34793
- return window.addEventListener("beforeunload", D), () => window.removeEventListener("beforeunload", D);
34794
- }, [O, g]), useEffect(() => {
34795
- let D;
34796
- if (!b || !O || !O?.view || n === EditorTypes.Poll) return;
34797
- const W = A(n);
34798
- return W && O?.isEditable && (D = setTimeout(() => {
34799
- O.commands.setContent(W), O.commands.rehydrateLinkPreviews();
34793
+ return window.addEventListener("beforeunload", W), () => window.removeEventListener("beforeunload", W);
34794
+ }, [k, g]), useEffect(() => {
34795
+ let W;
34796
+ if (!b || !k || !k?.view || n === EditorTypes.Poll) return;
34797
+ const $ = A(n);
34798
+ return $ && k?.isEditable && (W = setTimeout(() => {
34799
+ k.commands.setContent($), k.commands.rehydrateLinkPreviews();
34800
34800
  }, 0)), () => {
34801
- D && clearTimeout(D);
34801
+ W && clearTimeout(W);
34802
34802
  };
34803
- }, [O, n, u, A, b]);
34804
- const k = useMemo(() => O ? createEditorActions(O) : null, [O]), L = useCallback(() => {
34805
- O && !O.isDestroyed && (_(n, O), P.current = !0);
34806
- }, [O, n, _]), N = useCallback(() => {
34807
- O && !O.isDestroyed && _(n, O);
34808
- }, [O, n, _]), I = useCallback(() => {
34809
- C.current = !0;
34810
- }, []), j = useCallback(() => {
34811
- O && !O.isDestroyed && O?.commands?.focus("end");
34812
- }, [O]);
34803
+ }, [k, n, u, A, b]);
34804
+ const L = useMemo(() => k ? createEditorActions(k) : null, [k]), N = useCallback(() => {
34805
+ k && !k.isDestroyed && (_(n, k), C.current = !0);
34806
+ }, [k, n, _]), I = useCallback(() => {
34807
+ k && !k.isDestroyed && _(n, k);
34808
+ }, [k, n, _]), j = useCallback(() => {
34809
+ R.current = !0, P();
34810
+ }, [P]), D = useCallback(() => {
34811
+ k && !k.isDestroyed && k?.commands?.focus("end");
34812
+ }, [k]);
34813
34813
  return {
34814
- editor: O,
34815
- actions: k,
34814
+ editor: k,
34815
+ actions: L,
34816
34816
  store: S,
34817
34817
  isMounted: b,
34818
- saveBeforeSwitch: L,
34819
- saveDraft: N,
34820
- discardDraft: I,
34821
- keepEditing: j
34818
+ saveBeforeSwitch: N,
34819
+ saveDraft: I,
34820
+ discardDraft: j,
34821
+ keepEditing: D
34822
34822
  };
34823
34823
  }, getEditorData = (n) => ({
34824
34824
  html: n?.getHTML(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@select-org/select-post-builder",
3
- "version": "1.1.39",
3
+ "version": "1.1.40",
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",