{"version":3,"file":"useMessageComposerPreviewState.mjs","names":[],"sources":["../../../../../src/components/MessageComposer/hooks/useMessageComposerPreviewState.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type {\n  AttachmentManagerState,\n  CustomDataManagerState,\n  LinkPreview,\n  LinkPreviewsManagerState,\n  LocationComposerState,\n  MessageComposerState,\n} from 'stream-chat';\nimport { LinkPreviewsManager } from 'stream-chat';\n\nimport { useStateStore } from '../../../store';\nimport { useMessageComposerController } from './useMessageComposerController';\n\nconst messageComposerStateSelector = ({\n  editedMessage,\n  pollId,\n  quotedMessage,\n}: MessageComposerState) => ({\n  editedMessage,\n  pollId,\n  quotedMessage,\n});\n\nconst attachmentManagerStateSelector = (state: AttachmentManagerState) => ({\n  attachments: state.attachments,\n});\n\nconst linkPreviewsManagerStateSelector = (state: LinkPreviewsManagerState) => ({\n  previews: state.previews,\n});\n\nconst locationComposerStateSelector = (state: LocationComposerState) => ({\n  location: state.location,\n});\n\nconst customDataManagerStateSelector = (state: CustomDataManagerState) => ({\n  customData: state.custom,\n});\n\n/**\n * The composer state that decides which previews show. Each item of a\n * `messageComposerPreviewSet` reads it in `isVisible`.\n */\nexport type MessageComposerPreviewVisibilityFilterParams = {\n  attachments: AttachmentManagerState['attachments'];\n  /** The composer's custom data (`messageComposer.customDataManager`). */\n  customData: CustomDataManagerState['custom'];\n  editedMessage: MessageComposerState['editedMessage'];\n  /** Link previews that are loading or loaded. */\n  linkPreviews: LinkPreview[];\n  location: LocationComposerState['location'];\n  /**\n   * A poll created with `messageComposer.createPoll()` and not sent yet. No default preview shows\n   * it; an app that attaches polls to the message adds an item for it.\n   */\n  pollId: MessageComposerState['pollId'];\n  quotedMessage: MessageComposerState['quotedMessage'];\n};\n\n/**\n * Subscribes to the composer state that decides which previews show, for the composer\n * `useMessageComposerController()` resolves.\n */\nexport const useMessageComposerPreviewState =\n  (): MessageComposerPreviewVisibilityFilterParams => {\n    const messageComposer = useMessageComposerController();\n    const { editedMessage, pollId, quotedMessage } = useStateStore(\n      messageComposer.state,\n      messageComposerStateSelector,\n    );\n    const { attachments } = useStateStore(\n      messageComposer.attachmentManager.state,\n      attachmentManagerStateSelector,\n    );\n    const { previews } = useStateStore(\n      messageComposer.linkPreviewsManager.state,\n      linkPreviewsManagerStateSelector,\n    );\n    const { location } = useStateStore(\n      messageComposer.locationComposer.state,\n      locationComposerStateSelector,\n    );\n    const { customData } = useStateStore(\n      messageComposer.customDataManager.state,\n      customDataManagerStateSelector,\n    );\n\n    const linkPreviews = useMemo(\n      () =>\n        Array.from(previews.values()).filter(\n          (preview) =>\n            LinkPreviewsManager.previewIsLoaded(preview) ||\n            LinkPreviewsManager.previewIsLoading(preview),\n        ),\n      [previews],\n    );\n\n    return useMemo(\n      () => ({\n        attachments,\n        customData,\n        editedMessage,\n        linkPreviews,\n        location,\n        pollId,\n        quotedMessage,\n      }),\n      [\n        attachments,\n        customData,\n        editedMessage,\n        linkPreviews,\n        location,\n        pollId,\n        quotedMessage,\n      ],\n    );\n  };\n"],"mappings":";;;;;AAcA,IAAM,gCAAgC,EACpC,eACA,QACA,qBAC2B;CAC3B;CACA;CACA;AACF;AAEA,IAAM,kCAAkC,WAAmC,EACzE,aAAa,MAAM,YACrB;AAEA,IAAM,oCAAoC,WAAqC,EAC7E,UAAU,MAAM,SAClB;AAEA,IAAM,iCAAiC,WAAkC,EACvE,UAAU,MAAM,SAClB;AAEA,IAAM,kCAAkC,WAAmC,EACzE,YAAY,MAAM,OACpB;;;;;AA0BA,IAAa,uCACyC;CAClD,MAAM,kBAAkB,6BAA6B;CACrD,MAAM,EAAE,eAAe,QAAQ,kBAAkB,cAC/C,gBAAgB,OAChB,4BACF;CACA,MAAM,EAAE,gBAAgB,cACtB,gBAAgB,kBAAkB,OAClC,8BACF;CACA,MAAM,EAAE,aAAa,cACnB,gBAAgB,oBAAoB,OACpC,gCACF;CACA,MAAM,EAAE,aAAa,cACnB,gBAAgB,iBAAiB,OACjC,6BACF;CACA,MAAM,EAAE,eAAe,cACrB,gBAAgB,kBAAkB,OAClC,8BACF;CAEA,MAAM,eAAe,cAEjB,MAAM,KAAK,SAAS,OAAO,CAAC,CAAC,CAAC,QAC3B,YACC,oBAAoB,gBAAgB,OAAO,KAC3C,oBAAoB,iBAAiB,OAAO,CAChD,GACF,CAAC,QAAQ,CACX;CAEA,OAAO,eACE;EACL;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;AACF"}