@zydon/common 2.7.17 → 2.7.19
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.
|
@@ -8,25 +8,24 @@ import 'react-easy-crop';
|
|
|
8
8
|
import '@dnd-kit/core';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Tipo para
|
|
12
|
-
*
|
|
11
|
+
* Tipo para lazy query trigger do RTK Query
|
|
12
|
+
* Aceita um ID e retorna uma promise com unwrap
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```tsx
|
|
16
|
-
* const getFileQuery =
|
|
17
|
-
* const response = await api.get(`/files/${id}`);
|
|
18
|
-
* return response.data;
|
|
19
|
-
* };
|
|
16
|
+
* const [getFileQuery] = useLazyGetFileQuery();
|
|
20
17
|
* ```
|
|
21
18
|
*/
|
|
22
|
-
type
|
|
19
|
+
type LazyQueryTrigger = (id: string) => {
|
|
20
|
+
unwrap: () => Promise<FileGetResponse>;
|
|
21
|
+
};
|
|
23
22
|
/**
|
|
24
23
|
* Props base para componentes de upload integrados ao form
|
|
25
24
|
*/
|
|
26
25
|
interface BaseFormUploadProps {
|
|
27
26
|
name: string;
|
|
28
27
|
rules?: RegisterOptions;
|
|
29
|
-
getFileQuery:
|
|
28
|
+
getFileQuery: LazyQueryTrigger;
|
|
30
29
|
disableRemove?: boolean;
|
|
31
30
|
disableReorder?: boolean;
|
|
32
31
|
}
|
|
@@ -235,6 +234,6 @@ declare const SingleFileUpload: ({ name, rules, createFilesMutation, getFileQuer
|
|
|
235
234
|
* };
|
|
236
235
|
* ```
|
|
237
236
|
*/
|
|
238
|
-
declare const SingleImageUpload: ({ name, rules, createFilesMutation, getFileQuery, disableRemove, ...other }: FormSingleImageUploadProps) => react_jsx_runtime.JSX.Element;
|
|
237
|
+
declare const SingleImageUpload: ({ name, rules, createFilesMutation, getFileQuery, disableRemove, hoverAlt, ...other }: FormSingleImageUploadProps) => react_jsx_runtime.JSX.Element;
|
|
239
238
|
|
|
240
|
-
export { AvatarUpload, FileGetResponse, FormMultiFileUploadProps, FormMultiImageUploadProps, FormSingleFileUploadProps, FormSingleImageUploadProps,
|
|
239
|
+
export { AvatarUpload, FileGetResponse, FormMultiFileUploadProps, FormMultiImageUploadProps, FormSingleFileUploadProps, FormSingleImageUploadProps, LazyQueryTrigger, MultiFileUpload, MultiImageUpload, SingleFileUpload, SingleImageUpload };
|
|
@@ -20,6 +20,6 @@ import { useFormContext, Controller } from 'react-hook-form';
|
|
|
20
20
|
import { useState, useEffect, useMemo, useRef } from 'react';
|
|
21
21
|
import { jsx } from 'react/jsx-runtime';
|
|
22
22
|
|
|
23
|
-
var h=(e,r)=>{let{setValue:l,watch:
|
|
23
|
+
var h=(e,r)=>{let{setValue:l,watch:s}=useFormContext(),t=s(e),[o,i]=useState();return useEffect(()=>{if(!t){i(void 0);return}(async()=>{try{let a=await r(t).unwrap();i({id:a.id,url:a.url,name:a.name});}catch{i({id:t,url:""});}})();},[t,r]),{fileDetails:o,handleFileSelect:d=>{l(e,d.id,{shouldValidate:!0,shouldDirty:!0});},handleRemove:()=>{l(e,null,{shouldValidate:!0,shouldDirty:!0});}}},R=(e,r)=>{let{setValue:l,watch:s}=useFormContext(),t=s(e),o=useMemo(()=>t||[],[t]),[i,n]=useState([]),u=useRef(new Map);return useEffect(()=>{if(!o||o.length===0){n([]);return}(async()=>{try{let p=[...new Set(o)],c=u.current,F=p.filter(S=>!c.has(S));if(F.length>0){let S=F.map(async U=>{try{let g=await r(U).unwrap(),M={id:g.id,url:g.url,name:g.name};return c.set(U,M),M}catch{let g={id:U,url:""};return c.set(U,g),g}});await Promise.all(S);}let T=p.map(S=>c.get(S));n(T);}catch{n(o.map(p=>({id:p,url:""})));}})();},[o,r]),{currentValue:o,filesDetails:i,handleFilesSelect:m=>{let p=m.map(F=>F.id),c=[...new Set([...o,...p])];l(e,c,{shouldValidate:!0,shouldDirty:!0});},handleRemove:m=>{if(!m)return;let p=o.filter(c=>c!==m.id);l(e,p,{shouldValidate:!0,shouldDirty:!0});},handleReorder:(m,p)=>{let c=[...o],[F]=c.splice(m,1);c.splice(p,0,F),l(e,c,{shouldValidate:!0,shouldDirty:!0});}}};var E=({name:e,rules:r,createFilesMutation:l,getFileQuery:s,disableRemove:t,aspectRatio:o=1,enableCrop:i=!0,maxSize:n=5242880,...u})=>{let{control:d}=useFormContext(),{fileDetails:a,handleFileSelect:f,handleRemove:m}=h(e,s);return jsx(Controller,{name:e,control:d,rules:r,render:({fieldState:{error:p}})=>jsx(v,{name:e,fileDetails:a,createFilesMutation:l,onFileSelect:f,onRemove:t?void 0:m,aspectRatio:o,enableCrop:i,maxSize:n,error:p?.message,...u})})},G=E;var J=({name:e,rules:r,createFilesMutation:l,getFileQuery:s$1,disableRemove:t,disableReorder:o,...i})=>{let{control:n}=useFormContext(),{filesDetails:u,handleFilesSelect:d,handleRemove:a,handleReorder:f}=R(e,s$1);return jsx(Controller,{name:e,control:n,rules:r,render:({fieldState:{error:m}})=>jsx(s,{name:e,filesDetails:u,createFilesMutation:l,onFilesSelect:d,onRemove:t?void 0:a,onReorder:o?void 0:f,error:m?.message,...i})})},K=J;var W=({name:e,rules:r,createFilesMutation:l,getFileQuery:s,disableRemove:t$1,disableReorder:o,...i})=>{let{control:n}=useFormContext(),{filesDetails:u,handleFilesSelect:d,handleRemove:a,handleReorder:f}=R(e,s);return jsx(Controller,{name:e,control:n,rules:r,render:({fieldState:{error:m}})=>jsx(t,{name:e,filesDetails:u,createFilesMutation:l,onFilesSelect:d,onRemove:t$1?void 0:a,onReorder:o?void 0:f,error:m?.message,...i})})},X=W;var _=({name:e,rules:r,createFilesMutation:l,getFileQuery:s,disableRemove:t,...o})=>{let{control:i}=useFormContext(),{fileDetails:n,handleFileSelect:u$1,handleRemove:d}=h(e,s);return jsx(Controller,{name:e,control:i,rules:r,render:({fieldState:{error:a}})=>jsx(u,{name:e,fileDetails:n,createFilesMutation:l,onFileSelect:u$1,onRemove:t?void 0:d,error:a?.message,...o})})},$=_;var oe=({name:e,rules:r,createFilesMutation:l,getFileQuery:s,disableRemove:t,hoverAlt:o,...i})=>{let{control:n}=useFormContext(),{fileDetails:u,handleFileSelect:d,handleRemove:a}=h(e,s);return jsx(Controller,{name:e,control:n,rules:r,render:({fieldState:{error:f}})=>jsx(v,{name:e,fileDetails:u,createFilesMutation:l,onFileSelect:d,onRemove:t?void 0:a,error:f?.message,hoverAlt:o,...i})})},te=oe;
|
|
24
24
|
|
|
25
|
-
export {
|
|
25
|
+
export { G as AvatarUpload, K as MultiFileUpload, X as MultiImageUpload, $ as SingleFileUpload, te as SingleImageUpload };
|
|
@@ -3,6 +3,6 @@ import '../../chunk-IHAHXNLH.js';
|
|
|
3
3
|
import { createContext, useState, useMemo, useEffect, useCallback, useContext } from 'react';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
|
-
var Q=createContext(void 0),re=({children:g,originId:
|
|
6
|
+
var Q=createContext(void 0),re=({children:g,originId:M,originType:E,bearerToken:S,vapidKey:T,serviceWorkerPath:N="/",serviceWorkerFile:k="service-worker.js",pollingInterval:x=1e3,apiAdapters:r,onMessageReceived:d,onError:o})=>{let[t,h]=useState(null),[D,L]=useState(null),[B,w]=useState(0),[I,P]=useState(!1),[R,b]=useState(!1),[W,X]=useState({subscriptions:[]}),[z,O]=useState(!1),V=useMemo(()=>!t||z,[t,z]);useEffect(()=>{if(!R||!t||!r.fetchMessages)return;let e=setInterval(async()=>{try{let a=(await r.fetchMessages(t))?.messages?.[0];a?.payload&&(L(a.payload),w(i=>i+1),d?.(a.payload));}catch(s){console.error("Erro ao buscar mensagens:",s);}},x);return ()=>clearInterval(e)},[R,t,x,r,d]);let v=useCallback(async(e,s)=>{try{let a=e?.toJSON().keys,i={origin_type:E,origin_id:M,...s&&e?{endpoint:e.endpoint,auth:a?.auth,p256dh:a?.p256dh}:{}},n=await r.registerClient(i);return h(n.id),P(!1),s||b(!0),n.id}catch(a){return console.error("Erro ao registrar cliente:",a),P(!0),o?.(a),null}},[r,M,E,o]);useEffect(()=>{let e=!0,s=null;async function a$1(){if(!("serviceWorker"in navigator)||!("PushManager"in window)){console.warn("Push notifications n\xE3o suportadas, criando cliente ativo com polling");try{let i=await v(null,!1);e&&i&&(h(i),b(!0));}catch(i){console.error("Erro ao registrar cliente ativo:",i),o?.(i);}return}try{let i=await Notification.requestPermission(),n=null,f=!1;if(i==="granted")try{let m=await navigator.serviceWorker.register(`${N}${k}`);if(!e||(await navigator.serviceWorker.ready,!e))return;n=await m.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:a(T)}),s=async U=>{let p=U.data?.payload;p&&(L(p),w(y=>y+1),d?.(p));let j=U.data?.id?.value;if(j)try{await r.updateMessageStatus(j,{status:"DELIVERED"});}catch(y){console.error("Erro ao atualizar status da mensagem:",y),P(!0),o?.(y);}},navigator.serviceWorker.addEventListener("message",s),f=!0,console.log("Permiss\xE3o concedida, criando cliente passivo (aguarda webpush)");}catch(m){console.warn("Falha ao configurar push subscription, criando cliente ativo:",m),f=!1;}else console.warn("Permiss\xE3o de notifica\xE7\xE3o negada, criando cliente ativo com polling"),f=!1;let J=await v(n,f);e&&J&&(h(J),f||b(!0));}catch(i){console.error("Erro ao inicializar notifica\xE7\xF5es:",i),o?.(i);try{let n=await v(null,!1);e&&n&&(h(n),b(!0));}catch(n){console.error("Erro ao criar cliente ativo como fallback:",n);}}}return S&&a$1(),()=>{e=!1,s&&"serviceWorker"in navigator&&navigator.serviceWorker.removeEventListener("message",s);}},[S,v,r,T,N,k,d,o]);let c=useCallback(async()=>{if(t){O(!0);try{let e=await r.listSubscriptions(t);X(e);}catch(e){console.error("Erro ao listar inscri\xE7\xF5es:",e),o?.(e);}finally{O(!1);}}},[t,r,o]);useEffect(()=>{t&&c();},[t]);let _=useCallback(async e=>{if(t)try{await r.subscribeTopic(t,e),await c();}catch(s){console.error("Erro ao inscrever em t\xF3pico:",s),o?.(s);}},[t,r,c,o]),$=useCallback(async e=>{if(t)try{await r.unsubscribeTopic(t,e),await c();}catch(s){console.error("Erro ao desinscrever de t\xF3pico:",s),o?.(s);}},[t,r,c,o]),q=useCallback(async e=>{if(!(!t||e.length===0))try{await r.subscribeTopicsBatch(t,e),await c();}catch(s){console.error("Erro ao inscrever em t\xF3picos:",s),o?.(s);}},[t,r,c,o]),F=useCallback(async e=>{if(!(!t||e.length===0))try{await r.unsubscribeTopicsBatch(t,e),await c();}catch(s){console.error("Erro ao desinscrever de t\xF3picos:",s),o?.(s);}},[t,r,c,o]),H=useCallback(()=>{w(0);},[]),Y=useMemo(()=>({clientId:t,subscribedTopics:W,isRegisterError:I,isLoading:V,lastMessage:D,newMessageCount:B,subscribeToTopic:_,unsubscribeFromTopic:$,subscribeTopicsBatch:q,unsubscribeTopicsBatch:F,resetMessageCount:H}),[t,W,I,V,D,B,_,$,q,F,H]);return jsx(Q.Provider,{value:Y,children:g})};function oe(){let g=useContext(Q);if(!g)throw new Error("usePushNotifications precisa estar dentro de PushNotificationProvider");return g}
|
|
7
7
|
|
|
8
8
|
export { re as PushNotificationProvider, oe as usePushNotifications };
|
|
@@ -445,7 +445,7 @@ declare function paper({ theme, color, dropdown }: PaperProps): {
|
|
|
445
445
|
zIndex?: readonly ((string & {}) | csstype.Globals | "auto")[] | csstype.Property.ZIndex | readonly NonNullable<csstype.Property.ZIndex | undefined>[] | undefined;
|
|
446
446
|
zoom?: csstype.Property.Zoom | readonly NonNullable<csstype.Property.Zoom | undefined>[] | readonly ((string & {}) | csstype.Globals | "reset" | "normal")[] | undefined;
|
|
447
447
|
all?: csstype.Globals | readonly NonNullable<csstype.Globals | undefined>[] | readonly csstype.Globals[] | undefined;
|
|
448
|
-
animation?: csstype.Property.Animation<string & {}> | readonly NonNullable<csstype.Property.Animation<string & {}> | undefined>[] | readonly ((string & {}) | csstype.Globals | "auto" | "none" | "normal" | "alternate" | "alternate-reverse" | "
|
|
448
|
+
animation?: csstype.Property.Animation<string & {}> | readonly NonNullable<csstype.Property.Animation<string & {}> | undefined>[] | readonly ("reverse" | (string & {}) | csstype.Globals | "auto" | "none" | "normal" | "alternate" | "alternate-reverse" | "backwards" | "both" | "forwards" | "infinite" | "paused" | "running" | "ease" | "ease-in" | "ease-in-out" | "ease-out" | "step-end" | "step-start" | "linear")[] | undefined;
|
|
449
449
|
animationRange?: readonly (string | (string & {}))[] | csstype.Property.AnimationRange<string | number> | readonly NonNullable<csstype.Property.AnimationRange<string | number> | undefined>[] | undefined;
|
|
450
450
|
background?: readonly (string | (string & {}))[] | csstype.Property.Background<string | number> | readonly NonNullable<csstype.Property.Background<string | number> | undefined>[] | undefined;
|
|
451
451
|
border?: readonly (string | (string & {}))[] | csstype.Property.Border<string | number> | readonly NonNullable<csstype.Property.Border<string | number> | undefined>[] | undefined;
|
|
@@ -729,7 +729,7 @@ declare function paper({ theme, color, dropdown }: PaperProps): {
|
|
|
729
729
|
WebkitUserModify?: csstype.Property.WebkitUserModify | readonly NonNullable<csstype.Property.WebkitUserModify | undefined>[] | readonly csstype.Property.WebkitUserModify[] | undefined;
|
|
730
730
|
WebkitUserSelect?: csstype.Property.UserSelect | readonly NonNullable<csstype.Property.UserSelect | undefined>[] | readonly csstype.Property.UserSelect[] | undefined;
|
|
731
731
|
WebkitWritingMode?: csstype.Property.WritingMode | readonly NonNullable<csstype.Property.WritingMode | undefined>[] | readonly csstype.Property.WritingMode[] | undefined;
|
|
732
|
-
MozAnimation?: csstype.Property.Animation<string & {}> | readonly NonNullable<csstype.Property.Animation<string & {}> | undefined>[] | readonly ((string & {}) | csstype.Globals | "auto" | "none" | "normal" | "alternate" | "alternate-reverse" | "
|
|
732
|
+
MozAnimation?: csstype.Property.Animation<string & {}> | readonly NonNullable<csstype.Property.Animation<string & {}> | undefined>[] | readonly ("reverse" | (string & {}) | csstype.Globals | "auto" | "none" | "normal" | "alternate" | "alternate-reverse" | "backwards" | "both" | "forwards" | "infinite" | "paused" | "running" | "ease" | "ease-in" | "ease-in-out" | "ease-out" | "step-end" | "step-start" | "linear")[] | undefined;
|
|
733
733
|
MozBorderImage?: csstype.Property.BorderImage | readonly NonNullable<csstype.Property.BorderImage | undefined>[] | readonly ("repeat" | (string & {}) | csstype.Globals | "none" | "round" | "space" | "stretch")[] | undefined;
|
|
734
734
|
MozColumnRule?: readonly (string | (string & {}))[] | csstype.Property.ColumnRule<string | number> | readonly NonNullable<csstype.Property.ColumnRule<string | number> | undefined>[] | undefined;
|
|
735
735
|
MozColumns?: readonly (string | (string & {}))[] | csstype.Property.Columns<string | number> | readonly NonNullable<csstype.Property.Columns<string | number> | undefined>[] | undefined;
|
|
@@ -741,7 +741,7 @@ declare function paper({ theme, color, dropdown }: PaperProps): {
|
|
|
741
741
|
msScrollSnapX?: readonly string[] | csstype.Property.MsScrollSnapX | readonly csstype.Property.MsScrollSnapX[] | undefined;
|
|
742
742
|
msScrollSnapY?: readonly string[] | csstype.Property.MsScrollSnapY | readonly csstype.Property.MsScrollSnapY[] | undefined;
|
|
743
743
|
msTransition?: readonly string[] | csstype.Property.Transition<string & {}> | readonly csstype.Property.Transition<string & {}>[] | undefined;
|
|
744
|
-
WebkitAnimation?: csstype.Property.Animation<string & {}> | readonly NonNullable<csstype.Property.Animation<string & {}> | undefined>[] | readonly ((string & {}) | csstype.Globals | "auto" | "none" | "normal" | "alternate" | "alternate-reverse" | "
|
|
744
|
+
WebkitAnimation?: csstype.Property.Animation<string & {}> | readonly NonNullable<csstype.Property.Animation<string & {}> | undefined>[] | readonly ("reverse" | (string & {}) | csstype.Globals | "auto" | "none" | "normal" | "alternate" | "alternate-reverse" | "backwards" | "both" | "forwards" | "infinite" | "paused" | "running" | "ease" | "ease-in" | "ease-in-out" | "ease-out" | "step-end" | "step-start" | "linear")[] | undefined;
|
|
745
745
|
WebkitBorderBefore?: readonly (string | (string & {}))[] | csstype.Property.WebkitBorderBefore<string | number> | readonly NonNullable<csstype.Property.WebkitBorderBefore<string | number> | undefined>[] | undefined;
|
|
746
746
|
WebkitBorderImage?: csstype.Property.BorderImage | readonly NonNullable<csstype.Property.BorderImage | undefined>[] | readonly ("repeat" | (string & {}) | csstype.Globals | "none" | "round" | "space" | "stretch")[] | undefined;
|
|
747
747
|
WebkitBorderRadius?: readonly (string | (string & {}))[] | csstype.Property.BorderRadius<string | number> | readonly NonNullable<csstype.Property.BorderRadius<string | number> | undefined>[] | undefined;
|
|
@@ -831,7 +831,7 @@ declare function paper({ theme, color, dropdown }: PaperProps): {
|
|
|
831
831
|
MozTransitionTimingFunction?: readonly string[] | csstype.Property.TransitionTimingFunction | readonly csstype.Property.TransitionTimingFunction[] | undefined;
|
|
832
832
|
MozUserInput?: csstype.Property.MozUserInput | readonly NonNullable<csstype.Property.MozUserInput | undefined>[] | readonly csstype.Property.MozUserInput[] | undefined;
|
|
833
833
|
msImeMode?: csstype.Property.ImeMode | readonly NonNullable<csstype.Property.ImeMode | undefined>[] | readonly csstype.Property.ImeMode[] | undefined;
|
|
834
|
-
OAnimation?: csstype.Property.Animation<string & {}> | readonly NonNullable<csstype.Property.Animation<string & {}> | undefined>[] | readonly ((string & {}) | csstype.Globals | "auto" | "none" | "normal" | "alternate" | "alternate-reverse" | "
|
|
834
|
+
OAnimation?: csstype.Property.Animation<string & {}> | readonly NonNullable<csstype.Property.Animation<string & {}> | undefined>[] | readonly ("reverse" | (string & {}) | csstype.Globals | "auto" | "none" | "normal" | "alternate" | "alternate-reverse" | "backwards" | "both" | "forwards" | "infinite" | "paused" | "running" | "ease" | "ease-in" | "ease-in-out" | "ease-out" | "step-end" | "step-start" | "linear")[] | undefined;
|
|
835
835
|
OAnimationDelay?: readonly string[] | csstype.Property.AnimationDelay<string & {}> | readonly csstype.Property.AnimationDelay<string & {}>[] | undefined;
|
|
836
836
|
OAnimationDirection?: readonly string[] | csstype.Property.AnimationDirection | readonly csstype.Property.AnimationDirection[] | undefined;
|
|
837
837
|
OAnimationDuration?: readonly string[] | csstype.Property.AnimationDuration<string & {}> | readonly csstype.Property.AnimationDuration<string & {}>[] | undefined;
|
|
@@ -56,14 +56,14 @@ interface PushNotificationProviderProps<TMessage = unknown> {
|
|
|
56
56
|
serviceWorkerFile?: string;
|
|
57
57
|
pollingInterval?: number;
|
|
58
58
|
apiAdapters: PushNotificationApiAdapters<TMessage>;
|
|
59
|
-
onMessageReceived?: (message:
|
|
59
|
+
onMessageReceived?: (message: TMessage) => void;
|
|
60
60
|
onError?: (error: Error) => void;
|
|
61
61
|
}
|
|
62
62
|
interface PushNotificationContextData<TMessage = unknown> {
|
|
63
63
|
clientId: string | null;
|
|
64
64
|
subscribedTopics: SubscriptionsData;
|
|
65
65
|
isLoading: boolean;
|
|
66
|
-
lastMessage:
|
|
66
|
+
lastMessage: TMessage | null;
|
|
67
67
|
newMessageCount: number;
|
|
68
68
|
isRegisterError: boolean;
|
|
69
69
|
subscribeToTopic: (topic: string) => Promise<void>;
|