@arbidocs/react 0.4.105 → 0.4.107

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.cjs CHANGED
@@ -2719,6 +2719,47 @@ function useSendMail(fallback) {
2719
2719
  }
2720
2720
  });
2721
2721
  }
2722
+ function useMailDraftEditor() {
2723
+ const { client } = useMailClient();
2724
+ const queryClient = reactQuery.useQueryClient();
2725
+ return React.useMemo(() => {
2726
+ const call = (roomId, path, payload) => mailJson(client.fetch, `/drafts/editor/${encodeURIComponent(roomId)}${path}`, {
2727
+ method: "POST",
2728
+ body: JSON.stringify(payload)
2729
+ });
2730
+ return {
2731
+ /** Save as the draft: suggestions still waiting stay out of it. */
2732
+ save: async (roomId, compose, state) => {
2733
+ const saved = await call(roomId, "/save", { compose, state });
2734
+ void queryClient.invalidateQueries({ queryKey: mailQueryKeys.allMessages() });
2735
+ return saved;
2736
+ },
2737
+ /** Send (refused, `status` 409, while suggestions wait). */
2738
+ send: async (roomId, compose, state) => {
2739
+ const sent = await call(roomId, "/send", { compose, state });
2740
+ void queryClient.invalidateQueries({ queryKey: mailQueryKeys.all() });
2741
+ return sent;
2742
+ },
2743
+ /** The body as text and HTML (`final`: refused while suggestions wait). */
2744
+ body: (roomId, final, state) => call(roomId, "/body", { final, state }),
2745
+ /** Bill ARBI's work on this email to another project the person may bill (null: their own). */
2746
+ setProject: (roomId, projectExtId) => mailJson(
2747
+ client.fetch,
2748
+ `/drafts/editor/${encodeURIComponent(roomId)}/project`,
2749
+ { method: "PUT", body: JSON.stringify({ project_ext_id: projectExtId }) }
2750
+ )
2751
+ };
2752
+ }, [client, queryClient]);
2753
+ }
2754
+ function useMailProjects(options = {}) {
2755
+ const { client } = useMailClient();
2756
+ return reactQuery.useQuery({
2757
+ queryKey: ["mail", "projects"],
2758
+ queryFn: () => mailJson(client.fetch, "/drafts/editor/projects"),
2759
+ enabled: options.enabled ?? true,
2760
+ staleTime: 6e4
2761
+ });
2762
+ }
2722
2763
  function useMailDraftCompose(account, draftId, prepare, options = {}) {
2723
2764
  return reactQuery.useQuery({
2724
2765
  queryKey: ["mail", "draft-compose", account?.id, draftId],
@@ -2729,6 +2770,27 @@ function useMailDraftCompose(account, draftId, prepare, options = {}) {
2729
2770
  staleTime: Infinity
2730
2771
  });
2731
2772
  }
2773
+ var MAIL_DRAFT_REPLACED_EVENT = "arbi:mail-draft-replaced";
2774
+ function announceMailDraftReplaced(oldId, newId) {
2775
+ window.dispatchEvent(
2776
+ new CustomEvent(MAIL_DRAFT_REPLACED_EVENT, { detail: { oldId, newId } })
2777
+ );
2778
+ }
2779
+ function useMailDraftReplaced(draftId, onReplaced) {
2780
+ const latest = React.useRef(onReplaced);
2781
+ React.useEffect(() => {
2782
+ latest.current = onReplaced;
2783
+ });
2784
+ React.useEffect(() => {
2785
+ if (!draftId) return;
2786
+ const listener = (event) => {
2787
+ const { oldId, newId } = event.detail;
2788
+ if (oldId === draftId) latest.current(newId);
2789
+ };
2790
+ window.addEventListener(MAIL_DRAFT_REPLACED_EVENT, listener);
2791
+ return () => window.removeEventListener(MAIL_DRAFT_REPLACED_EVENT, listener);
2792
+ }, [draftId]);
2793
+ }
2732
2794
  function useWorkspaceDocs(workspaceId) {
2733
2795
  const { data: docs = [], isLoading, isError } = chunkX2KOIXHA_cjs.useDocuments(workspaceId);
2734
2796
  const docIds = React.useMemo(
@@ -7901,6 +7963,7 @@ exports.GoogleIcon = GoogleIcon;
7901
7963
  exports.ImageCropModal = ImageCropModal;
7902
7964
  exports.ImageCropper = ImageCropper;
7903
7965
  exports.LinkedInIcon = LinkedInIcon;
7966
+ exports.MAIL_DRAFT_REPLACED_EVENT = MAIL_DRAFT_REPLACED_EVENT;
7904
7967
  exports.MAX_AVATAR_FILE_BYTES = MAX_AVATAR_FILE_BYTES;
7905
7968
  exports.MailClientProvider = MailClientProvider;
7906
7969
  exports.MailOfflineUnavailableError = MailOfflineUnavailableError;
@@ -7919,6 +7982,7 @@ exports.VoiceNoteRecorder = VoiceNoteRecorder;
7919
7982
  exports.accountPath = accountPath;
7920
7983
  exports.aliasTakenMessage = aliasTakenMessage;
7921
7984
  exports.annotateThread = annotateThread;
7985
+ exports.announceMailDraftReplaced = announceMailDraftReplaced;
7922
7986
  exports.arbiMailClient = arbiMailClient;
7923
7987
  exports.captureFrameAsBlob = captureFrameAsBlob;
7924
7988
  exports.createMailClient = createMailClient;
@@ -8006,11 +8070,14 @@ exports.useMailAccounts = useMailAccounts;
8006
8070
  exports.useMailCache = useMailCache;
8007
8071
  exports.useMailClient = useMailClient;
8008
8072
  exports.useMailDraftCompose = useMailDraftCompose;
8073
+ exports.useMailDraftEditor = useMailDraftEditor;
8074
+ exports.useMailDraftReplaced = useMailDraftReplaced;
8009
8075
  exports.useMailFolders = useMailFolders;
8010
8076
  exports.useMailMessage = useMailMessage;
8011
8077
  exports.useMailMessages = useMailMessages;
8012
8078
  exports.useMailOnline = useMailOnline;
8013
8079
  exports.useMailPolicy = useMailPolicy;
8080
+ exports.useMailProjects = useMailProjects;
8014
8081
  exports.useMailUnlock = useMailUnlock;
8015
8082
  exports.useNameEditor = useNameEditor;
8016
8083
  exports.useNotificationPreferences = useNotificationPreferences;