@orbe-agro/client-core 5.6.362 → 5.6.364
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/@ecme/components/template/Footer.js +1 -1
- package/dist/@ecme/store/localeStore.js +6 -1
- package/dist/@ecme/store/localeStore.js.map +1 -1
- package/dist/@ecme/store/themeStore.js +3 -0
- package/dist/@ecme/store/themeStore.js.map +1 -1
- package/dist/@types/@ecme/store/localeStore.d.ts.map +1 -1
- package/dist/@types/@ecme/store/themeStore.d.ts +2 -38
- package/dist/@types/@ecme/store/themeStore.d.ts.map +1 -1
- package/dist/@types/base/@types/clientCoreAxios.d.ts +16 -0
- package/dist/@types/base/@types/clientCoreAxios.d.ts.map +1 -0
- package/dist/@types/base/@types/globalLoadingDisplay.d.ts +16 -0
- package/dist/@types/base/@types/globalLoadingDisplay.d.ts.map +1 -0
- package/dist/@types/base/@types/index.d.ts +3 -0
- package/dist/@types/base/@types/index.d.ts.map +1 -1
- package/dist/@types/base/@types/requestFeedback/index.d.ts +80 -0
- package/dist/@types/base/@types/requestFeedback/index.d.ts.map +1 -0
- package/dist/@types/base/components/backgrounds/ParticleNetworkBackground.d.ts +4 -0
- package/dist/@types/base/components/backgrounds/ParticleNetworkBackground.d.ts.map +1 -1
- package/dist/@types/base/components/backgrounds/particleField.d.ts +33 -0
- package/dist/@types/base/components/backgrounds/particleField.d.ts.map +1 -0
- package/dist/@types/base/configs/endpoints.config/Ticket/ticket.endpoint.config.d.ts +1 -0
- package/dist/@types/base/configs/endpoints.config/Ticket/ticket.endpoint.config.d.ts.map +1 -1
- package/dist/@types/base/configs/navigation.config/modules.submenu/Ticket/ticket.navigation.d.ts.map +1 -1
- package/dist/@types/base/configs/navigation.config/submenu/ticket/config/monitorNfeTransporteNaoUtilizadas.submenu.d.ts +4 -0
- package/dist/@types/base/configs/navigation.config/submenu/ticket/config/monitorNfeTransporteNaoUtilizadas.submenu.d.ts.map +1 -0
- package/dist/@types/base/locales/lang/ptBR/modules/Ticket/ticket.nav.d.ts +1 -0
- package/dist/@types/base/locales/lang/ptBR/modules/Ticket/ticket.nav.d.ts.map +1 -1
- package/dist/@types/base/services/axios/inheritClientCoreAxios.d.ts +2 -15
- package/dist/@types/base/services/axios/inheritClientCoreAxios.d.ts.map +1 -1
- package/dist/@types/base/services/modules/Ticket/TicketService.d.ts +1 -0
- package/dist/@types/base/services/modules/Ticket/TicketService.d.ts.map +1 -1
- package/dist/@types/base/services/requestFeedback/requestFeedbackTypes.d.ts +1 -38
- package/dist/@types/base/services/requestFeedback/requestFeedbackTypes.d.ts.map +1 -1
- package/dist/@types/base/services/requestFeedback/retryPolicy.d.ts +2 -11
- package/dist/@types/base/services/requestFeedback/retryPolicy.d.ts.map +1 -1
- package/dist/@types/base/store/globalLoadingDisplayStore.d.ts +2 -16
- package/dist/@types/base/store/globalLoadingDisplayStore.d.ts.map +1 -1
- package/dist/@types/base/store/loadingConfigStore.d.ts.map +1 -1
- package/dist/@types/base/store/preferences/animatedBackgroundStore.d.ts.map +1 -1
- package/dist/@types/base/store/requestFeedbackStore.d.ts +2 -30
- package/dist/@types/base/store/requestFeedbackStore.d.ts.map +1 -1
- package/dist/@types/base/utils/index.d.ts +1 -0
- package/dist/@types/base/utils/index.d.ts.map +1 -1
- package/dist/@types/base/utils/storage/index.d.ts +2 -0
- package/dist/@types/base/utils/storage/index.d.ts.map +1 -0
- package/dist/@types/base/utils/storage/persistVersion.d.ts +29 -0
- package/dist/@types/base/utils/storage/persistVersion.d.ts.map +1 -0
- package/dist/base/@types/clientCoreAxios.js +2 -0
- package/dist/base/@types/clientCoreAxios.js.map +1 -0
- package/dist/base/@types/globalLoadingDisplay.js +2 -0
- package/dist/base/@types/globalLoadingDisplay.js.map +1 -0
- package/dist/base/@types/index.js +3 -0
- package/dist/base/@types/index.js.map +1 -1
- package/dist/base/@types/requestFeedback/index.js +2 -0
- package/dist/base/@types/requestFeedback/index.js.map +1 -0
- package/dist/base/assets/styles/app.css +12 -7
- package/dist/base/assets/styles/init.css +12 -7
- package/dist/base/components/backgrounds/ParticleNetworkBackground.js +12 -18
- package/dist/base/components/backgrounds/ParticleNetworkBackground.js.map +1 -1
- package/dist/base/components/backgrounds/particleField.js +76 -0
- package/dist/base/components/backgrounds/particleField.js.map +1 -0
- package/dist/base/configs/endpoints.config/Ticket/ticket.endpoint.config.js +1 -0
- package/dist/base/configs/endpoints.config/Ticket/ticket.endpoint.config.js.map +1 -1
- package/dist/base/configs/navigation.config/modules.submenu/Ticket/ticket.navigation.js +2 -0
- package/dist/base/configs/navigation.config/modules.submenu/Ticket/ticket.navigation.js.map +1 -1
- package/dist/base/configs/navigation.config/submenu/ticket/config/monitorNfeTransporteNaoUtilizadas.submenu.js +16 -0
- package/dist/base/configs/navigation.config/submenu/ticket/config/monitorNfeTransporteNaoUtilizadas.submenu.js.map +1 -0
- package/dist/base/index.js +210 -208
- package/dist/base/index.js.map +1 -1
- package/dist/base/locales/lang/ptBR/modules/Ticket/ticket.nav.js +1 -0
- package/dist/base/locales/lang/ptBR/modules/Ticket/ticket.nav.js.map +1 -1
- package/dist/base/services/axios/inheritClientCoreAxios.js.map +1 -1
- package/dist/base/services/modules/Ticket/TicketService.js +8 -0
- package/dist/base/services/modules/Ticket/TicketService.js.map +1 -1
- package/dist/base/services/requestFeedback/requestFeedbackTypes.js +1 -1
- package/dist/base/services/requestFeedback/requestFeedbackTypes.js.map +1 -1
- package/dist/base/services/requestFeedback/retryPolicy.js.map +1 -1
- package/dist/base/store/globalLoadingDisplayStore.js.map +1 -1
- package/dist/base/store/loadingConfigStore.js +4 -1
- package/dist/base/store/loadingConfigStore.js.map +1 -1
- package/dist/base/store/preferences/animatedBackgroundStore.js +9 -2
- package/dist/base/store/preferences/animatedBackgroundStore.js.map +1 -1
- package/dist/base/store/requestFeedbackStore.js.map +1 -1
- package/dist/base/utils/index.js +3 -0
- package/dist/base/utils/index.js.map +1 -1
- package/dist/base/utils/storage/index.js +5 -0
- package/dist/base/utils/storage/index.js.map +1 -0
- package/dist/base/utils/storage/persistVersion.js +11 -0
- package/dist/base/utils/storage/persistVersion.js.map +1 -0
- package/lib/@ecme/store/localeStore.ts +7 -1
- package/lib/@ecme/store/themeStore.ts +4 -0
- package/lib/base/@types/clientCoreAxios.ts +15 -0
- package/lib/base/@types/globalLoadingDisplay.ts +15 -0
- package/lib/base/@types/index.ts +5 -0
- package/lib/base/@types/requestFeedback/index.ts +87 -0
- package/lib/base/assets/styles/app.css +12 -7
- package/lib/base/components/backgrounds/ParticleNetworkBackground.tsx +27 -22
- package/lib/base/components/backgrounds/particleField.test.ts +83 -0
- package/lib/base/components/backgrounds/particleField.ts +132 -0
- package/lib/base/configs/endpoints.config/Ticket/ticket.endpoint.config.ts +1 -0
- package/lib/base/configs/navigation.config/modules.submenu/Ticket/ticket.navigation.ts +2 -0
- package/lib/base/configs/navigation.config/submenu/ticket/config/monitorNfeTransporteNaoUtilizadas.submenu.ts +16 -0
- package/lib/base/locales/lang/ptBR/modules/Ticket/ticket.nav.ts +1 -0
- package/lib/base/services/axios/inheritClientCoreAxios.ts +2 -15
- package/lib/base/services/modules/Ticket/TicketService.ts +8 -0
- package/lib/base/services/requestFeedback/requestFeedbackTypes.ts +3 -40
- package/lib/base/services/requestFeedback/retryPolicy.ts +9 -12
- package/lib/base/store/globalLoadingDisplayStore.ts +2 -15
- package/lib/base/store/loadingConfigStore.ts +3 -0
- package/lib/base/store/preferences/animatedBackgroundStore.ts +9 -2
- package/lib/base/store/requestFeedbackStore.ts +13 -33
- package/lib/base/utils/index.ts +3 -0
- package/lib/base/utils/storage/index.ts +2 -0
- package/lib/base/utils/storage/persistVersion.test.ts +80 -0
- package/lib/base/utils/storage/persistVersion.ts +35 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryPolicy.js","sources":["../../../../lib/base/services/requestFeedback/retryPolicy.ts"],"sourcesContent":["import type { AxiosError } from 'axios'\n\n/**\n * Regras de nova tentativa para quem chama a API. A decisão de repetir continua\n * na chamada (hook do SWR ou do React Query); estas funções só montam a regra.\n *\n * Por padrão não repetem 400 (requisição inválida: repetir dá o mesmo erro) nem\n * 404 (o recurso não existe). Os dois viram avisos próprios no plug-in de\n * feedback das requisições.\n */\n\nexport const NON_RETRYABLE_STATUSES = [400, 404]\n\
|
|
1
|
+
{"version":3,"file":"retryPolicy.js","sources":["../../../../lib/base/services/requestFeedback/retryPolicy.ts"],"sourcesContent":["import type { AxiosError } from 'axios'\nimport type {\n TRetryPolicyOptions,\n TSwrRetryPolicyOptions,\n} from '@base/@types/requestFeedback'\n\nexport type {\n TRetryPolicyOptions,\n TSwrRetryPolicyOptions,\n} from '@base/@types/requestFeedback'\n\n/**\n * Regras de nova tentativa para quem chama a API. A decisão de repetir continua\n * na chamada (hook do SWR ou do React Query); estas funções só montam a regra.\n *\n * Por padrão não repetem 400 (requisição inválida: repetir dá o mesmo erro) nem\n * 404 (o recurso não existe). Os dois viram avisos próprios no plug-in de\n * feedback das requisições.\n */\n\nexport const NON_RETRYABLE_STATUSES = [400, 404]\n\n/** Status HTTP do erro, quando houver resposta do servidor. */\nexport function getErrorStatus(error: unknown): number | undefined {\n return (error as AxiosError | undefined)?.response?.status\n}\n\n/** `false` quando o status do erro está em `nonRetryableStatuses`. */\nexport function isRetryableError(\n error: unknown,\n nonRetryableStatuses: number[] = NON_RETRYABLE_STATUSES,\n): boolean {\n const status = getErrorStatus(error)\n return status === undefined || !nonRetryableStatuses.includes(status)\n}\n\n/**\n * Regra para o `retry` do React Query (`useQuery({ retry: queryRetryPolicy() })`).\n * Padrão de 3 novas tentativas, igual ao do React Query.\n */\nexport function queryRetryPolicy({\n maxRetries = 3,\n nonRetryableStatuses = NON_RETRYABLE_STATUSES,\n}: TRetryPolicyOptions = {}) {\n return (failureCount: number, error: unknown) =>\n failureCount < maxRetries &&\n isRetryableError(error, nonRetryableStatuses)\n}\n\ntype TSwrRetryConfig = { errorRetryInterval: number }\ntype TSwrRevalidate = (options: { retryCount: number }) => unknown\n\n/**\n * Regra para o `onErrorRetry` do SWR\n * (`useSWR(key, fetcher, { ...swrRetryPolicy({ maxRetries: 2 }) })`).\n *\n * Intervalo exponencial com variação aleatória de ±50%: a 1ª nova tentativa sai\n * em ~`intervalMs`, a 2ª em ~2×, a 3ª em ~4×... Como no SWR, não repete com a\n * aba escondida (o SWR revalida ao voltar o foco). A diferença é o limite de\n * tentativas e não repetir os status de `nonRetryableStatuses`: sem esta regra,\n * o SWR repete sem limite, inclusive 400 e 404.\n */\nexport function swrRetryPolicy({\n maxRetries = 2,\n nonRetryableStatuses = NON_RETRYABLE_STATUSES,\n intervalMs,\n}: TSwrRetryPolicyOptions = {}) {\n return {\n onErrorRetry: (\n error: unknown,\n _key: unknown,\n config: TSwrRetryConfig,\n revalidate: TSwrRevalidate,\n { retryCount }: { retryCount: number },\n ) => {\n if (!isRetryableError(error, nonRetryableStatuses)) return\n if (retryCount > maxRetries) return\n if (\n typeof document !== 'undefined' &&\n document.visibilityState === 'hidden'\n ) {\n return\n }\n\n const interval = intervalMs ?? config.errorRetryInterval\n const exponent = Math.min(retryCount, 8)\n const timeout = Math.floor(\n (Math.random() + 0.5) * (1 << exponent) * (interval / 2),\n )\n setTimeout(revalidate, timeout, { retryCount })\n },\n }\n}\n"],"names":[],"mappings":"AAoBO,MAAM,yBAAyB,CAAC,KAAK,GAAG;AAGxC,SAAS,eAAe,OAAoC;AAC/D,SAAQ,OAAkC,UAAU;AACxD;AAGO,SAAS,iBACZ,OACA,uBAAiC,wBAC1B;AACP,QAAM,SAAS,eAAe,KAAK;AACnC,SAAO,WAAW,UAAa,CAAC,qBAAqB,SAAS,MAAM;AACxE;AAMO,SAAS,iBAAiB;AAAA,EAC7B,aAAa;AAAA,EACb,uBAAuB;AAC3B,IAAyB,IAAI;AACzB,SAAO,CAAC,cAAsB,UAC1B,eAAe,cACf,iBAAiB,OAAO,oBAAoB;AACpD;AAeO,SAAS,eAAe;AAAA,EAC3B,aAAa;AAAA,EACb,uBAAuB;AAAA,EACvB;AACJ,IAA4B,IAAI;AAC5B,SAAO;AAAA,IACH,cAAc,CACV,OACA,MACA,QACA,YACA,EAAE,iBACD;AACD,UAAI,CAAC,iBAAiB,OAAO,oBAAoB,EAAG;AACpD,UAAI,aAAa,WAAY;AAC7B,UACI,OAAO,aAAa,eACpB,SAAS,oBAAoB,UAC/B;AACE;AAAA,MACJ;AAEA,YAAM,WAAW,cAAc,OAAO;AACtC,YAAM,WAAW,KAAK,IAAI,YAAY,CAAC;AACvC,YAAM,UAAU,KAAK;AAAA,SAChB,KAAK,WAAW,QAAQ,KAAK,aAAa,WAAW;AAAA,MAAA;AAE1D,iBAAW,YAAY,SAAS,EAAE,WAAA,CAAY;AAAA,IAClD;AAAA,EAAA;AAER;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalLoadingDisplayStore.js","sources":["../../../lib/base/store/globalLoadingDisplayStore.ts"],"sourcesContent":["import { create } from 'zustand'\
|
|
1
|
+
{"version":3,"file":"globalLoadingDisplayStore.js","sources":["../../../lib/base/store/globalLoadingDisplayStore.ts"],"sourcesContent":["import { create } from 'zustand'\nimport type { TGlobalLoadingDisplayConfig } from '@base/@types/globalLoadingDisplay'\n\nexport type { TGlobalLoadingDisplayConfig } from '@base/@types/globalLoadingDisplay'\n\nexport const DEFAULT_GLOBAL_LOADING_DISPLAY_CONFIG: TGlobalLoadingDisplayConfig =\n {\n showDelayMs: 0,\n minVisibleMs: 0,\n }\n\ntype TGlobalLoadingDisplayState = {\n config: TGlobalLoadingDisplayConfig\n configure: (config: Partial<TGlobalLoadingDisplayConfig>) => void\n}\n\nexport const useGlobalLoadingDisplayStore = create<TGlobalLoadingDisplayState>()(\n (set) => ({\n config: { ...DEFAULT_GLOBAL_LOADING_DISPLAY_CONFIG },\n configure: (config) =>\n set((state) => ({ config: { ...state.config, ...config } })),\n }),\n)\n\n/**\n * Configura a exibição do loading global neste frontend. Chame uma vez, na\n * inicialização: `configureGlobalLoadingDisplay({ showDelayMs: 300, minVisibleMs: 400 })`.\n */\nexport function configureGlobalLoadingDisplay(\n config: Partial<TGlobalLoadingDisplayConfig>,\n) {\n useGlobalLoadingDisplayStore.getState().configure(config)\n}\n"],"names":[],"mappings":";AAKO,MAAM,wCACT;AAAA,EACI,aAAa;AAAA,EACb,cAAc;AAClB;AAOG,MAAM,+BAA+B,OAAA;AAAA,EACxC,CAAC,SAAS;AAAA,IACN,QAAQ,EAAE,GAAG,sCAAA;AAAA,IACb,WAAW,CAAC,WACR,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,GAAG,MAAM,QAAQ,GAAG,OAAA,IAAW;AAAA,EAAA;AAEvE;AAMO,SAAS,8BACZ,QACF;AACE,+BAA6B,SAAA,EAAW,UAAU,MAAM;AAC5D;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { create } from "zustand";
|
|
2
2
|
import { persist } from "zustand/middleware";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
|
+
import persistVersion from "../utils/storage/persistVersion.js";
|
|
4
5
|
const initialState = {
|
|
5
6
|
microfrontendConfigs: {}
|
|
6
7
|
};
|
|
@@ -22,7 +23,9 @@ const useLoadingConfigStore = create()(
|
|
|
22
23
|
}
|
|
23
24
|
}),
|
|
24
25
|
{
|
|
25
|
-
name: "loading-config"
|
|
26
|
+
name: "loading-config",
|
|
27
|
+
// Versão 1 mantém o que foi gravado antes de haver versão (0)
|
|
28
|
+
...persistVersion(1, { keepFrom: [0] })
|
|
26
29
|
}
|
|
27
30
|
)
|
|
28
31
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadingConfigStore.js","sources":["../../../lib/base/store/loadingConfigStore.ts"],"sourcesContent":["import { create } from \"zustand\";\nimport { persist } from \"zustand/middleware\";\nimport { useMemo } from \"react\";\n\n// Configurações por microfrontend\ninterface MicrofrontendLoadingConfig {\n [microfrontendId: string]: boolean;\n}\n\ninterface LoadingConfigState {\n microfrontendConfigs: MicrofrontendLoadingConfig;\n}\n\ninterface LoadingConfigActions {\n setGlobalLoadingEnabled: (enabled: boolean, microfrontendId: string) => void;\n enableGlobalLoading: (microfrontendId: string) => void;\n disableGlobalLoading: (microfrontendId: string) => void;\n getGlobalLoadingEnabled: (microfrontendId: string) => boolean;\n}\n\nconst initialState: LoadingConfigState = {\n microfrontendConfigs: {},\n};\n\nexport const useLoadingConfigStore = create<LoadingConfigState & LoadingConfigActions>()(\n persist(\n (set, get) => ({\n ...initialState,\n \n setGlobalLoadingEnabled: (enabled, microfrontendId) => \n set((state) => ({\n microfrontendConfigs: {\n ...state.microfrontendConfigs,\n [microfrontendId]: enabled,\n }\n })),\n \n enableGlobalLoading: (microfrontendId) => \n get().setGlobalLoadingEnabled(true, microfrontendId),\n \n disableGlobalLoading: (microfrontendId) => \n get().setGlobalLoadingEnabled(false, microfrontendId),\n \n getGlobalLoadingEnabled: (microfrontendId) => {\n const state = get();\n // Por padrão, retorna true se não foi configurado (compatibilidade)\n return state.microfrontendConfigs[microfrontendId] ?? true;\n },\n }),\n {\n name: \"loading-config\",\n }\n )\n);\n\n// Hook para configuração específica de um microfrontend\nexport const useLoadingConfigForMicrofrontend = (microfrontendId: string) => {\n const globalLoadingEnabled = useLoadingConfigStore((state) => \n state.microfrontendConfigs[microfrontendId] ?? true\n );\n \n // Usa funções estáveis do store diretamente\n const setGlobalLoadingEnabled = useLoadingConfigStore((state) => state.setGlobalLoadingEnabled);\n const enableGlobalLoading = useLoadingConfigStore((state) => state.enableGlobalLoading);\n const disableGlobalLoading = useLoadingConfigStore((state) => state.disableGlobalLoading);\n \n // Memoiza apenas as funções bound\n return useMemo(() => ({\n globalLoadingEnabled,\n setGlobalLoadingEnabled: (enabled: boolean) => setGlobalLoadingEnabled(enabled, microfrontendId),\n enableGlobalLoading: () => enableGlobalLoading(microfrontendId),\n disableGlobalLoading: () => disableGlobalLoading(microfrontendId),\n }), [globalLoadingEnabled, setGlobalLoadingEnabled, enableGlobalLoading, disableGlobalLoading, microfrontendId]);\n};\n\n// Função para detectar automaticamente o microfrontend baseado na URL ou contexto\nexport const getCurrentMicrofrontendId = (): string => {\n // Tenta detectar pelo hostname, pathname ou contexto\n if (typeof window !== 'undefined') {\n const hostname = window.location.hostname;\n const pathname = window.location.pathname;\n \n if (hostname.includes('originacao') || pathname.includes('/originacao')) return 'originacao';\n \n // Tenta extrair do primeiro segmento da URL\n const segments = pathname.split('/').filter(Boolean);\n if (segments.length > 0) {\n return segments[0];\n }\n }\n \n // Fallback para um ID padrão\n return 'default';\n};\n\n// Hook principal com detecção automática (versão corrigida)\nexport const useAutoLoadingConfig = () => {\n // Memoiza o ID para evitar recálculos desnecessários\n const microfrontendId = useMemo(() => getCurrentMicrofrontendId(), []);\n \n // Retorna diretamente a configuração para o microfrontend detectado\n return useLoadingConfigForMicrofrontend(microfrontendId);\n};"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadingConfigStore.js","sources":["../../../lib/base/store/loadingConfigStore.ts"],"sourcesContent":["import { create } from \"zustand\";\nimport { persist } from \"zustand/middleware\";\nimport { useMemo } from \"react\";\nimport persistVersion from \"@base/utils/storage/persistVersion\";\n\n// Configurações por microfrontend\ninterface MicrofrontendLoadingConfig {\n [microfrontendId: string]: boolean;\n}\n\ninterface LoadingConfigState {\n microfrontendConfigs: MicrofrontendLoadingConfig;\n}\n\ninterface LoadingConfigActions {\n setGlobalLoadingEnabled: (enabled: boolean, microfrontendId: string) => void;\n enableGlobalLoading: (microfrontendId: string) => void;\n disableGlobalLoading: (microfrontendId: string) => void;\n getGlobalLoadingEnabled: (microfrontendId: string) => boolean;\n}\n\nconst initialState: LoadingConfigState = {\n microfrontendConfigs: {},\n};\n\nexport const useLoadingConfigStore = create<LoadingConfigState & LoadingConfigActions>()(\n persist(\n (set, get) => ({\n ...initialState,\n \n setGlobalLoadingEnabled: (enabled, microfrontendId) => \n set((state) => ({\n microfrontendConfigs: {\n ...state.microfrontendConfigs,\n [microfrontendId]: enabled,\n }\n })),\n \n enableGlobalLoading: (microfrontendId) => \n get().setGlobalLoadingEnabled(true, microfrontendId),\n \n disableGlobalLoading: (microfrontendId) => \n get().setGlobalLoadingEnabled(false, microfrontendId),\n \n getGlobalLoadingEnabled: (microfrontendId) => {\n const state = get();\n // Por padrão, retorna true se não foi configurado (compatibilidade)\n return state.microfrontendConfigs[microfrontendId] ?? true;\n },\n }),\n {\n name: \"loading-config\",\n // Versão 1 mantém o que foi gravado antes de haver versão (0)\n ...persistVersion<LoadingConfigState & LoadingConfigActions>(1, { keepFrom: [0] }),\n }\n )\n);\n\n// Hook para configuração específica de um microfrontend\nexport const useLoadingConfigForMicrofrontend = (microfrontendId: string) => {\n const globalLoadingEnabled = useLoadingConfigStore((state) => \n state.microfrontendConfigs[microfrontendId] ?? true\n );\n \n // Usa funções estáveis do store diretamente\n const setGlobalLoadingEnabled = useLoadingConfigStore((state) => state.setGlobalLoadingEnabled);\n const enableGlobalLoading = useLoadingConfigStore((state) => state.enableGlobalLoading);\n const disableGlobalLoading = useLoadingConfigStore((state) => state.disableGlobalLoading);\n \n // Memoiza apenas as funções bound\n return useMemo(() => ({\n globalLoadingEnabled,\n setGlobalLoadingEnabled: (enabled: boolean) => setGlobalLoadingEnabled(enabled, microfrontendId),\n enableGlobalLoading: () => enableGlobalLoading(microfrontendId),\n disableGlobalLoading: () => disableGlobalLoading(microfrontendId),\n }), [globalLoadingEnabled, setGlobalLoadingEnabled, enableGlobalLoading, disableGlobalLoading, microfrontendId]);\n};\n\n// Função para detectar automaticamente o microfrontend baseado na URL ou contexto\nexport const getCurrentMicrofrontendId = (): string => {\n // Tenta detectar pelo hostname, pathname ou contexto\n if (typeof window !== 'undefined') {\n const hostname = window.location.hostname;\n const pathname = window.location.pathname;\n \n if (hostname.includes('originacao') || pathname.includes('/originacao')) return 'originacao';\n \n // Tenta extrair do primeiro segmento da URL\n const segments = pathname.split('/').filter(Boolean);\n if (segments.length > 0) {\n return segments[0];\n }\n }\n \n // Fallback para um ID padrão\n return 'default';\n};\n\n// Hook principal com detecção automática (versão corrigida)\nexport const useAutoLoadingConfig = () => {\n // Memoiza o ID para evitar recálculos desnecessários\n const microfrontendId = useMemo(() => getCurrentMicrofrontendId(), []);\n \n // Retorna diretamente a configuração para o microfrontend detectado\n return useLoadingConfigForMicrofrontend(microfrontendId);\n};"],"names":[],"mappings":";;;;AAqBA,MAAM,eAAmC;AAAA,EACvC,sBAAsB,CAAA;AACxB;AAEO,MAAM,wBAAwB,OAAA;AAAA,EACnC;AAAA,IACE,CAAC,KAAK,SAAS;AAAA,MACb,GAAG;AAAA,MAEH,yBAAyB,CAAC,SAAS,oBACjC,IAAI,CAAC,WAAW;AAAA,QACd,sBAAsB;AAAA,UACpB,GAAG,MAAM;AAAA,UACT,CAAC,eAAe,GAAG;AAAA,QAAA;AAAA,MACrB,EACA;AAAA,MAEJ,qBAAqB,CAAC,oBACpB,MAAM,wBAAwB,MAAM,eAAe;AAAA,MAErD,sBAAsB,CAAC,oBACrB,MAAM,wBAAwB,OAAO,eAAe;AAAA,MAEtD,yBAAyB,CAAC,oBAAoB;AAC5C,cAAM,QAAQ,IAAA;AAEd,eAAO,MAAM,qBAAqB,eAAe,KAAK;AAAA,MACxD;AAAA,IAAA;AAAA,IAEF;AAAA,MACE,MAAM;AAAA;AAAA,MAEN,GAAG,eAA0D,GAAG,EAAE,UAAU,CAAC,CAAC,GAAG;AAAA,IAAA;AAAA,EACnF;AAEJ;AAGO,MAAM,mCAAmC,CAAC,oBAA4B;AAC3E,QAAM,uBAAuB;AAAA,IAAsB,CAAC,UAClD,MAAM,qBAAqB,eAAe,KAAK;AAAA,EAAA;AAIjD,QAAM,0BAA0B,sBAAsB,CAAC,UAAU,MAAM,uBAAuB;AAC9F,QAAM,sBAAsB,sBAAsB,CAAC,UAAU,MAAM,mBAAmB;AACtF,QAAM,uBAAuB,sBAAsB,CAAC,UAAU,MAAM,oBAAoB;AAGxF,SAAO,QAAQ,OAAO;AAAA,IACpB;AAAA,IACA,yBAAyB,CAAC,YAAqB,wBAAwB,SAAS,eAAe;AAAA,IAC/F,qBAAqB,MAAM,oBAAoB,eAAe;AAAA,IAC9D,sBAAsB,MAAM,qBAAqB,eAAe;AAAA,EAAA,IAC9D,CAAC,sBAAsB,yBAAyB,qBAAqB,sBAAsB,eAAe,CAAC;AACjH;AAGO,MAAM,4BAA4B,MAAc;AAErD,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,WAAW,OAAO,SAAS;AACjC,UAAM,WAAW,OAAO,SAAS;AAEjC,QAAI,SAAS,SAAS,YAAY,KAAK,SAAS,SAAS,aAAa,EAAG,QAAO;AAGhF,UAAM,WAAW,SAAS,MAAM,GAAG,EAAE,OAAO,OAAO;AACnD,QAAI,SAAS,SAAS,GAAG;AACvB,aAAO,SAAS,CAAC;AAAA,IACnB;AAAA,EACF;AAGA,SAAO;AACT;AAGO,MAAM,uBAAuB,MAAM;AAExC,QAAM,kBAAkB,QAAQ,MAAM,0BAAA,GAA6B,CAAA,CAAE;AAGrE,SAAO,iCAAiC,eAAe;AACzD;"}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { create } from "zustand";
|
|
2
2
|
import { persist } from "zustand/middleware";
|
|
3
|
+
import persistVersion from "../../utils/storage/persistVersion.js";
|
|
3
4
|
const useAnimatedBackgroundStore = create()(
|
|
4
5
|
persist(
|
|
5
6
|
(set) => ({
|
|
6
|
-
backgroundId: "
|
|
7
|
+
backgroundId: "none",
|
|
7
8
|
setBackgroundId: (backgroundId) => set(() => ({ backgroundId }))
|
|
8
9
|
}),
|
|
9
|
-
{
|
|
10
|
+
{
|
|
11
|
+
name: "animatedBackground",
|
|
12
|
+
// Versão 1 mantém o que foi gravado antes de haver versão (0)
|
|
13
|
+
...persistVersion(1, {
|
|
14
|
+
keepFrom: [0]
|
|
15
|
+
})
|
|
16
|
+
}
|
|
10
17
|
)
|
|
11
18
|
);
|
|
12
19
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"animatedBackgroundStore.js","sources":["../../../../lib/base/store/preferences/animatedBackgroundStore.ts"],"sourcesContent":["import { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\n\n/** Fundos animados disponíveis no `AnimatedBackground`. `nenhum` desliga a animação. */\nexport type TAnimatedBackgroundId = 'none' | 'network' | 'particles'\n\ntype TAnimatedBackgroundState = {\n backgroundId: TAnimatedBackgroundId\n}\n\ntype TAnimatedBackgroundAction = {\n setBackgroundId: (backgroundId: TAnimatedBackgroundId) => void\n}\n\n/** Fundo animado escolhido pelo usuário, guardado entre os acessos. */\nexport const useAnimatedBackgroundStore = create<\n TAnimatedBackgroundState & TAnimatedBackgroundAction\n>()(\n persist(\n (set) => ({\n backgroundId: '
|
|
1
|
+
{"version":3,"file":"animatedBackgroundStore.js","sources":["../../../../lib/base/store/preferences/animatedBackgroundStore.ts"],"sourcesContent":["import { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\nimport persistVersion from '@base/utils/storage/persistVersion'\n\n/** Fundos animados disponíveis no `AnimatedBackground`. `nenhum` desliga a animação. */\nexport type TAnimatedBackgroundId = 'none' | 'network' | 'particles'\n\ntype TAnimatedBackgroundState = {\n backgroundId: TAnimatedBackgroundId\n}\n\ntype TAnimatedBackgroundAction = {\n setBackgroundId: (backgroundId: TAnimatedBackgroundId) => void\n}\n\n/** Fundo animado escolhido pelo usuário, guardado entre os acessos. */\nexport const useAnimatedBackgroundStore = create<\n TAnimatedBackgroundState & TAnimatedBackgroundAction\n>()(\n persist(\n (set) => ({\n backgroundId: 'none',\n setBackgroundId: (backgroundId) => set(() => ({ backgroundId })),\n }),\n {\n name: 'animatedBackground',\n // Versão 1 mantém o que foi gravado antes de haver versão (0)\n ...persistVersion<TAnimatedBackgroundState & TAnimatedBackgroundAction>(1, {\n keepFrom: [0],\n }),\n },\n ),\n)\n"],"names":[],"mappings":";;;AAgBO,MAAM,6BAA6B,OAAA;AAAA,EAGtC;AAAA,IACI,CAAC,SAAS;AAAA,MACN,cAAc;AAAA,MACd,iBAAiB,CAAC,iBAAiB,IAAI,OAAO,EAAE,eAAe;AAAA,IAAA;AAAA,IAEnE;AAAA,MACI,MAAM;AAAA;AAAA,MAEN,GAAG,eAAqE,GAAG;AAAA,QACvE,UAAU,CAAC,CAAC;AAAA,MAAA,CACf;AAAA,IAAA;AAAA,EACL;AAER;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestFeedbackStore.js","sources":["../../../lib/base/store/requestFeedbackStore.ts"],"sourcesContent":["import { create } from 'zustand'\nimport type { TRequestNoticeKind } from '@base/services/requestFeedback/requestFeedbackTypes'\n\n/**\n * Estado do plug-in de feedback das requisições (`installRequestFeedback`).\n *\n * Não é persistido: é estado da página. Cada microfrontend tem a sua cópia do\n * client-core, então a configuração vale só para quem chamou\n * `configureRequestFeedback`.\n */\n\nexport type TRequestFeedbackConfig = {\n /** Liga o plug-in neste frontend. Desligado por padrão. */\n enabled: boolean\n /**\n * Quanto tempo (ms) o aviso de nova tentativa espera pela próxima tentativa\n * depois de uma falha. Sem nova tentativa nesse tempo, o aviso some e a\n * próxima chamada volta a ser tratada como primeira tentativa.\n */\n retryLingerMs: number\n /** Quanto tempo (ms) os avisos de 400 e 404 ficam visíveis. `0` mantém até fechar. */\n noticeDurationMs: number\n /** Quantos avisos de 400 e 404 ficam visíveis ao mesmo tempo. */\n maxNotices: number\n}\n\nexport type TRetryEntryStatus = 'retrying' | 'waiting'\n\nexport type TRetryEntry = {\n key: string\n label?: string\n /** Tentativa atual: 1 é a primeira chamada, 2 a primeira nova tentativa... */\n attempt: number\n /** `retrying`: tentativa em andamento; `waiting`: falhou e aguarda a próxima. */\n status: TRetryEntryStatus\n}\n\nexport type TRequestNotice = {\n id: number\n kind: TRequestNoticeKind\n label?: string\n}\n\ntype TRequestFeedbackState = {\n config: TRequestFeedbackConfig\n retries: Record<string, TRetryEntry>\n notices: TRequestNotice[]\n}\n\ntype TRequestFeedbackActions = {\n configure: (config: Partial<TRequestFeedbackConfig>) => void\n /** Registra a falha de uma tentativa que pode ser repetida. */\n registerFailure: (key: string, label?: string) => void\n /**\n * Marca o início de uma tentativa. Devolve `true` se a requisição já tinha\n * falhado (é uma nova tentativa).\n */\n startAttempt: (key: string, label?: string) => boolean\n /** Requisição concluída (ou que não adianta repetir): remove o aviso. */\n resolve: (key: string) => void\n /** Tentativa interrompida (ex.: cancelada): volta a aguardar, sem contar falha. */\n pause: (key: string) => void\n pushNotice: (kind: TRequestNoticeKind, label?: string) => void\n dismissNotice: (id: number) => void\n /** Limpa avisos e timers (usado nos testes). */\n reset: () => void\n}\n\nexport const DEFAULT_REQUEST_FEEDBACK_CONFIG: TRequestFeedbackConfig = {\n enabled: false,\n retryLingerMs: 10000,\n noticeDurationMs: 6000,\n maxNotices: 3,\n}\n\nconst retryTimers = new Map<string, ReturnType<typeof setTimeout>>()\nconst noticeTimers = new Map<number, ReturnType<typeof setTimeout>>()\nlet nextNoticeId = 1\n\nfunction clearRetryTimer(key: string) {\n const timer = retryTimers.get(key)\n if (timer) clearTimeout(timer)\n retryTimers.delete(key)\n}\n\nfunction clearNoticeTimer(id: number) {\n const timer = noticeTimers.get(id)\n if (timer) clearTimeout(timer)\n noticeTimers.delete(id)\n}\n\nexport const useRequestFeedbackStore = create<\n TRequestFeedbackState & TRequestFeedbackActions\n>()((set, get) => {\n /** Depois de uma falha, o aviso espera a próxima tentativa por `retryLingerMs`. */\n const scheduleExpiry = (key: string) => {\n clearRetryTimer(key)\n retryTimers.set(\n key,\n setTimeout(() => get().resolve(key), get().config.retryLingerMs),\n )\n }\n\n const scheduleNoticeDismiss = (id: number) => {\n clearNoticeTimer(id)\n const duration = get().config.noticeDurationMs\n if (duration > 0) {\n noticeTimers.set(\n id,\n setTimeout(() => get().dismissNotice(id), duration),\n )\n }\n }\n\n return {\n config: { ...DEFAULT_REQUEST_FEEDBACK_CONFIG },\n retries: {},\n notices: [],\n\n configure: (config) =>\n set((state) => ({ config: { ...state.config, ...config } })),\n\n registerFailure: (key, label) => {\n set((state) => {\n const current = state.retries[key]\n return {\n retries: {\n ...state.retries,\n [key]: {\n key,\n label: label ?? current?.label,\n attempt: current?.attempt ?? 1,\n status: 'waiting',\n },\n },\n }\n })\n scheduleExpiry(key)\n },\n\n startAttempt: (key, label) => {\n const current = get().retries[key]\n if (!current) return false\n\n clearRetryTimer(key)\n set((state) => ({\n retries: {\n ...state.retries,\n [key]: {\n key,\n label: label ?? current.label,\n attempt: current.attempt + 1,\n status: 'retrying',\n },\n },\n }))\n return true\n },\n\n resolve: (key) => {\n clearRetryTimer(key)\n if (!get().retries[key]) return\n set((state) => {\n const retries = { ...state.retries }\n delete retries[key]\n return { retries }\n })\n },\n\n pause: (key) => {\n const current = get().retries[key]\n if (!current) return\n set((state) => ({\n retries: {\n ...state.retries,\n [key]: { ...current, status: 'waiting' },\n },\n }))\n scheduleExpiry(key)\n },\n\n pushNotice: (kind, label) => {\n const existing = get().notices.find(\n (notice) => notice.kind === kind && notice.label === label,\n )\n // Mesmo aviso de novo (ex.: outro componente pediu o mesmo recurso): só renova o tempo\n if (existing) {\n scheduleNoticeDismiss(existing.id)\n return\n }\n\n const notice: TRequestNotice = { id: nextNoticeId++, kind, label }\n const { maxNotices } = get().config\n set((state) => {\n const notices = [...state.notices, notice]\n const overflow = notices.slice(\n 0,\n Math.max(0, notices.length - maxNotices),\n )\n overflow.forEach((old) => clearNoticeTimer(old.id))\n return { notices: notices.slice(overflow.length) }\n })\n scheduleNoticeDismiss(notice.id)\n },\n\n dismissNotice: (id) => {\n clearNoticeTimer(id)\n set((state) => ({\n notices: state.notices.filter((notice) => notice.id !== id),\n }))\n },\n\n reset: () => {\n retryTimers.forEach((timer) => clearTimeout(timer))\n noticeTimers.forEach((timer) => clearTimeout(timer))\n retryTimers.clear()\n noticeTimers.clear()\n set({\n config: { ...DEFAULT_REQUEST_FEEDBACK_CONFIG },\n retries: {},\n notices: [],\n })\n },\n }\n})\n\n/**\n * Configura o plug-in de feedback das requisições neste frontend. Chame uma vez,\n * na inicialização (ex.: `App.tsx`): `configureRequestFeedback({ enabled: true })`.\n */\nexport function configureRequestFeedback(\n config: Partial<TRequestFeedbackConfig>,\n) {\n useRequestFeedbackStore.getState().configure(config)\n}\n\n/**\n * Tentativas visíveis no aviso: só a partir da primeira nova tentativa. Recebe\n * o `retries` do store (selecione o objeto e derive com `useMemo`, para não\n * criar um array novo a cada leitura do store).\n */\nexport function getVisibleRetries(retries: Record<string, TRetryEntry>) {\n return Object.values(retries).filter((entry) => entry.attempt > 1)\n}\n"],"names":["notice"],"mappings":";AAoEO,MAAM,kCAA0D;AAAA,EACnE,SAAS;AAAA,EACT,eAAe;AAAA,EACf,kBAAkB;AAAA,EAClB,YAAY;AAChB;AAEA,MAAM,kCAAkB,IAAA;AACxB,MAAM,mCAAmB,IAAA;AACzB,IAAI,eAAe;AAEnB,SAAS,gBAAgB,KAAa;AAClC,QAAM,QAAQ,YAAY,IAAI,GAAG;AACjC,MAAI,oBAAoB,KAAK;AAC7B,cAAY,OAAO,GAAG;AAC1B;AAEA,SAAS,iBAAiB,IAAY;AAClC,QAAM,QAAQ,aAAa,IAAI,EAAE;AACjC,MAAI,oBAAoB,KAAK;AAC7B,eAAa,OAAO,EAAE;AAC1B;AAEO,MAAM,0BAA0B,OAAA,EAEnC,CAAC,KAAK,QAAQ;AAEd,QAAM,iBAAiB,CAAC,QAAgB;AACpC,oBAAgB,GAAG;AACnB,gBAAY;AAAA,MACR;AAAA,MACA,WAAW,MAAM,IAAA,EAAM,QAAQ,GAAG,GAAG,IAAA,EAAM,OAAO,aAAa;AAAA,IAAA;AAAA,EAEvE;AAEA,QAAM,wBAAwB,CAAC,OAAe;AAC1C,qBAAiB,EAAE;AACnB,UAAM,WAAW,MAAM,OAAO;AAC9B,QAAI,WAAW,GAAG;AACd,mBAAa;AAAA,QACT;AAAA,QACA,WAAW,MAAM,IAAA,EAAM,cAAc,EAAE,GAAG,QAAQ;AAAA,MAAA;AA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AQ,EAAE,GAAG,gCAAA;AAAA,QACb,SAAS,CAAA;AAAA,QACT,SAAS,CAAA;AAAA,MAAC,CACb;AAAA,IACL;AAAA,EAAA;AAER,CAAC;AAMM,SAAS,yBACZ,QACF;AACE,0BAAwB,SAAA,EAAW,UAAU,MAAM;AACvD;AAOO,SAAS,kBAAkB,SAAsC;AACpE,SAAO,OAAO,OAAO,OAAO,EAAE,OAAO,CAAC,UAAU,MAAM,UAAU,CAAC;AACrE;"}
|
|
1
|
+
{"version":3,"file":"requestFeedbackStore.js","sources":["../../../lib/base/store/requestFeedbackStore.ts"],"sourcesContent":["import { create } from 'zustand'\nimport type {\n TRequestFeedbackConfig,\n TRequestNotice,\n TRequestNoticeKind,\n TRetryEntry,\n} from '@base/@types/requestFeedback'\n\nexport type {\n TRequestFeedbackConfig,\n TRequestNotice,\n TRetryEntry,\n TRetryEntryStatus,\n} from '@base/@types/requestFeedback'\n\n/**\n * Estado do plug-in de feedback das requisições (`installRequestFeedback`).\n *\n * Não é persistido: é estado da página. Cada microfrontend tem a sua cópia do\n * client-core, então a configuração vale só para quem chamou\n * `configureRequestFeedback`.\n */\n\ntype TRequestFeedbackState = {\n config: TRequestFeedbackConfig\n retries: Record<string, TRetryEntry>\n notices: TRequestNotice[]\n}\n\ntype TRequestFeedbackActions = {\n configure: (config: Partial<TRequestFeedbackConfig>) => void\n /** Registra a falha de uma tentativa que pode ser repetida. */\n registerFailure: (key: string, label?: string) => void\n /**\n * Marca o início de uma tentativa. Devolve `true` se a requisição já tinha\n * falhado (é uma nova tentativa).\n */\n startAttempt: (key: string, label?: string) => boolean\n /** Requisição concluída (ou que não adianta repetir): remove o aviso. */\n resolve: (key: string) => void\n /** Tentativa interrompida (ex.: cancelada): volta a aguardar, sem contar falha. */\n pause: (key: string) => void\n pushNotice: (kind: TRequestNoticeKind, label?: string) => void\n dismissNotice: (id: number) => void\n /** Limpa avisos e timers (usado nos testes). */\n reset: () => void\n}\n\nexport const DEFAULT_REQUEST_FEEDBACK_CONFIG: TRequestFeedbackConfig = {\n enabled: false,\n retryLingerMs: 10000,\n noticeDurationMs: 6000,\n maxNotices: 3,\n}\n\nconst retryTimers = new Map<string, ReturnType<typeof setTimeout>>()\nconst noticeTimers = new Map<number, ReturnType<typeof setTimeout>>()\nlet nextNoticeId = 1\n\nfunction clearRetryTimer(key: string) {\n const timer = retryTimers.get(key)\n if (timer) clearTimeout(timer)\n retryTimers.delete(key)\n}\n\nfunction clearNoticeTimer(id: number) {\n const timer = noticeTimers.get(id)\n if (timer) clearTimeout(timer)\n noticeTimers.delete(id)\n}\n\nexport const useRequestFeedbackStore = create<\n TRequestFeedbackState & TRequestFeedbackActions\n>()((set, get) => {\n /** Depois de uma falha, o aviso espera a próxima tentativa por `retryLingerMs`. */\n const scheduleExpiry = (key: string) => {\n clearRetryTimer(key)\n retryTimers.set(\n key,\n setTimeout(() => get().resolve(key), get().config.retryLingerMs),\n )\n }\n\n const scheduleNoticeDismiss = (id: number) => {\n clearNoticeTimer(id)\n const duration = get().config.noticeDurationMs\n if (duration > 0) {\n noticeTimers.set(\n id,\n setTimeout(() => get().dismissNotice(id), duration),\n )\n }\n }\n\n return {\n config: { ...DEFAULT_REQUEST_FEEDBACK_CONFIG },\n retries: {},\n notices: [],\n\n configure: (config) =>\n set((state) => ({ config: { ...state.config, ...config } })),\n\n registerFailure: (key, label) => {\n set((state) => {\n const current = state.retries[key]\n return {\n retries: {\n ...state.retries,\n [key]: {\n key,\n label: label ?? current?.label,\n attempt: current?.attempt ?? 1,\n status: 'waiting',\n },\n },\n }\n })\n scheduleExpiry(key)\n },\n\n startAttempt: (key, label) => {\n const current = get().retries[key]\n if (!current) return false\n\n clearRetryTimer(key)\n set((state) => ({\n retries: {\n ...state.retries,\n [key]: {\n key,\n label: label ?? current.label,\n attempt: current.attempt + 1,\n status: 'retrying',\n },\n },\n }))\n return true\n },\n\n resolve: (key) => {\n clearRetryTimer(key)\n if (!get().retries[key]) return\n set((state) => {\n const retries = { ...state.retries }\n delete retries[key]\n return { retries }\n })\n },\n\n pause: (key) => {\n const current = get().retries[key]\n if (!current) return\n set((state) => ({\n retries: {\n ...state.retries,\n [key]: { ...current, status: 'waiting' },\n },\n }))\n scheduleExpiry(key)\n },\n\n pushNotice: (kind, label) => {\n const existing = get().notices.find(\n (notice) => notice.kind === kind && notice.label === label,\n )\n // Mesmo aviso de novo (ex.: outro componente pediu o mesmo recurso): só renova o tempo\n if (existing) {\n scheduleNoticeDismiss(existing.id)\n return\n }\n\n const notice: TRequestNotice = { id: nextNoticeId++, kind, label }\n const { maxNotices } = get().config\n set((state) => {\n const notices = [...state.notices, notice]\n const overflow = notices.slice(\n 0,\n Math.max(0, notices.length - maxNotices),\n )\n overflow.forEach((old) => clearNoticeTimer(old.id))\n return { notices: notices.slice(overflow.length) }\n })\n scheduleNoticeDismiss(notice.id)\n },\n\n dismissNotice: (id) => {\n clearNoticeTimer(id)\n set((state) => ({\n notices: state.notices.filter((notice) => notice.id !== id),\n }))\n },\n\n reset: () => {\n retryTimers.forEach((timer) => clearTimeout(timer))\n noticeTimers.forEach((timer) => clearTimeout(timer))\n retryTimers.clear()\n noticeTimers.clear()\n set({\n config: { ...DEFAULT_REQUEST_FEEDBACK_CONFIG },\n retries: {},\n notices: [],\n })\n },\n }\n})\n\n/**\n * Configura o plug-in de feedback das requisições neste frontend. Chame uma vez,\n * na inicialização (ex.: `App.tsx`): `configureRequestFeedback({ enabled: true })`.\n */\nexport function configureRequestFeedback(\n config: Partial<TRequestFeedbackConfig>,\n) {\n useRequestFeedbackStore.getState().configure(config)\n}\n\n/**\n * Tentativas visíveis no aviso: só a partir da primeira nova tentativa. Recebe\n * o `retries` do store (selecione o objeto e derive com `useMemo`, para não\n * criar um array novo a cada leitura do store).\n */\nexport function getVisibleRetries(retries: Record<string, TRetryEntry>) {\n return Object.values(retries).filter((entry) => entry.attempt > 1)\n}\n"],"names":["notice"],"mappings":";AAgDO,MAAM,kCAA0D;AAAA,EACnE,SAAS;AAAA,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AACjC;AAAA,MACJ;AAEA,YAAM,SAAyB,EAAE,IAAI,gBAAgB,MAAM,MAAA;AAC3D,YAAM,EAAE,WAAA,IAAe,IAAA,EAAM;AAC7B,UAAI,CAAC,UAAU;AACX,cAAM,UAAU,CAAC,GAAG,MAAM,SAAS,MAAM;AACzC,cAAM,WAAW,QAAQ;AAAA,UACrB;AAAA,UACA,KAAK,IAAI,GAAG,QAAQ,SAAS,UAAU;AAAA,QAAA;AAE3C,iBAAS,QAAQ,CAAC,QAAQ,iBAAiB,IAAI,EAAE,CAAC;AAClD,eAAO,EAAE,SAAS,QAAQ,MAAM,SAAS,MAAM,EAAA;AAAA,MACnD,CAAC;AACD,4BAAsB,OAAO,EAAE;AAAA,IACnC;AAAA,IAEA,eAAe,CAAC,OAAO;AACnB,uBAAiB,EAAE;AACnB,UAAI,CAAC,WAAW;AAAA,QACZ,SAAS,MAAM,QAAQ,OAAO,CAAC,WAAW,OAAO,OAAO,EAAE;AAAA,MAAA,EAC5D;AAAA,IACN;AAAA,IAEA,OAAO,MAAM;AACT,kBAAY,QAAQ,CAAC,UAAU,aAAa,KAAK,CAAC;AAClD,mBAAa,QAAQ,CAAC,UAAU,aAAa,KAAK,CAAC;AACnD,kBAAY,MAAA;AACZ,mBAAa,MAAA;AACb,UAAI;AAAA,QACA,QAAQ,EAAE,GAAG,gCAAA;AAAA,QACb,SAAS,CAAA;AAAA,QACT,SAAS,CAAA;AAAA,MAAC,CACb;AAAA,IACL;AAAA,EAAA;AAER,CAAC;AAMM,SAAS,yBACZ,QACF;AACE,0BAAwB,SAAA,EAAW,UAAU,MAAM;AACvD;AAOO,SAAS,kBAAkB,SAAsC;AACpE,SAAO,OAAO,OAAO,OAAO,EAAE,OAAO,CAAC,UAAU,MAAM,UAAU,CAAC;AACrE;"}
|
package/dist/base/utils/index.js
CHANGED
|
@@ -3,8 +3,10 @@ import { validateEmail } from "./validateEmail/validateEmail.js";
|
|
|
3
3
|
import { groupFilterFields } from "./filters/groupFilterFields.js";
|
|
4
4
|
import "./auth/index.js";
|
|
5
5
|
import { DOCUMENTO_PRODUTOR_ACCEPT, DOCUMENTO_PRODUTOR_EXTENSIONS, DOCUMENTO_PRODUTOR_MAX_FILE_SIZE, OPERACAO_DOCUMENTO_PRODUTOR_LABELS, isDocumentoProdutorViewable, validateDocumentoProdutorFile } from "./modules/crm/documentoProdutor.js";
|
|
6
|
+
import "./storage/index.js";
|
|
6
7
|
import { CSRF_COOKIE_NAME, CSRF_HEADER_NAME, credentialsSessaoCookie, forgetRememberedLogin, headersSessaoCookie, isSessaoCookie, limparSessaoCookie, marcarSessaoCookie, readRememberedLogin, rememberLogin } from "./auth/sessaoCookie.js";
|
|
7
8
|
import { DEFAULT_SIGN_IN_MODE, parseSignInMode } from "./auth/signInMode.js";
|
|
9
|
+
import { default as default2 } from "./storage/persistVersion.js";
|
|
8
10
|
export {
|
|
9
11
|
CSRF_COOKIE_NAME,
|
|
10
12
|
CSRF_HEADER_NAME,
|
|
@@ -23,6 +25,7 @@ export {
|
|
|
23
25
|
limparSessaoCookie,
|
|
24
26
|
marcarSessaoCookie,
|
|
25
27
|
parseSignInMode,
|
|
28
|
+
default2 as persistVersion,
|
|
26
29
|
readRememberedLogin,
|
|
27
30
|
rememberLogin,
|
|
28
31
|
validateDocumentoProdutorFile,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function persistVersion(version, { keepFrom = [] } = {}) {
|
|
2
|
+
return {
|
|
3
|
+
version,
|
|
4
|
+
migrate: (persistedState, persistedVersion) => keepFrom.includes(persistedVersion) ? persistedState : void 0
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
persistVersion as default,
|
|
9
|
+
persistVersion
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=persistVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistVersion.js","sources":["../../../../lib/base/utils/storage/persistVersion.ts"],"sourcesContent":["/**\n * Opções `version` e `migrate` para o `persist` do zustand.\n *\n * O zustand compara o `version` gravado no localStorage com o do store. Quando\n * são diferentes, chama `migrate`; aqui, o estado gravado é mantido se veio de\n * uma versão em `keepFrom` e descartado (o store começa do padrão) nos outros\n * casos.\n *\n * Para uma mudança que quebra o formato gravado, suba `version` e deixe a\n * versão antiga fora de `keepFrom`: na próxima carga, o dado antigo é\n * descartado.\n *\n * ```ts\n * persist(creator, { name: 'theme', ...persistVersion(1, { keepFrom: [0] }) })\n * ```\n *\n * Os microfrontends compartilham o localStorage e não são publicados ao mesmo\n * tempo. Um microfrontend com um client-core mais antigo (versão menor, sem\n * `migrate` para a nova) ignora o estado gravado na versão nova e usa o padrão\n * até ser publicado de novo. Por isso, os stores de sessão ainda não têm versão.\n */\nexport function persistVersion<TState>(\n version: number,\n { keepFrom = [] }: { keepFrom?: number[] } = {},\n) {\n return {\n version,\n migrate: (persistedState: unknown, persistedVersion: number) =>\n (keepFrom.includes(persistedVersion)\n ? persistedState\n : undefined) as TState,\n }\n}\n\nexport default persistVersion\n"],"names":[],"mappings":"AAqBO,SAAS,eACZ,SACA,EAAE,WAAW,CAAA,EAAC,IAA+B,CAAA,GAC/C;AACE,SAAO;AAAA,IACH;AAAA,IACA,SAAS,CAAC,gBAAyB,qBAC9B,SAAS,SAAS,gBAAgB,IAC7B,iBACA;AAAA,EAAA;AAElB;"}
|
|
@@ -4,6 +4,8 @@ import { devtools, persist } from 'zustand/middleware'
|
|
|
4
4
|
import i18n from 'i18next'
|
|
5
5
|
import { dateLocales } from '@/locales/locales'
|
|
6
6
|
import dayjs from 'dayjs'
|
|
7
|
+
// ORBE: versão do estado gravado no localStorage
|
|
8
|
+
import persistVersion from '@base/utils/storage/persistVersion'
|
|
7
9
|
|
|
8
10
|
type LocaleState = {
|
|
9
11
|
currentLang: string
|
|
@@ -32,7 +34,11 @@ export const useLocaleStore = create<LocaleState>()(
|
|
|
32
34
|
return set({ currentLang: lang })
|
|
33
35
|
},
|
|
34
36
|
}),
|
|
35
|
-
{
|
|
37
|
+
{
|
|
38
|
+
name: 'locale',
|
|
39
|
+
// ORBE: versão 1 mantém o que foi gravado antes de haver versão (0)
|
|
40
|
+
...persistVersion<LocaleState>(1, { keepFrom: [0] }),
|
|
41
|
+
},
|
|
36
42
|
),
|
|
37
43
|
),
|
|
38
44
|
)
|
|
@@ -2,6 +2,8 @@ import { themeConfig } from "@/configs/theme.config";
|
|
|
2
2
|
import { create } from "zustand";
|
|
3
3
|
import { persist } from "zustand/middleware";
|
|
4
4
|
import type { Theme, LayoutType, Direction } from "@/@types/theme";
|
|
5
|
+
// ORBE: versão do estado gravado no localStorage
|
|
6
|
+
import persistVersion from "@base/utils/storage/persistVersion";
|
|
5
7
|
|
|
6
8
|
type ThemeState = Theme & {
|
|
7
9
|
loading?: boolean;
|
|
@@ -45,6 +47,8 @@ export const useThemeStore = create<ThemeState & ThemeAction>()(
|
|
|
45
47
|
}),
|
|
46
48
|
{
|
|
47
49
|
name: "theme",
|
|
50
|
+
// ORBE: versão 1 mantém o que foi gravado antes de haver versão (0)
|
|
51
|
+
...persistVersion<Partial<ThemeState>>(1, { keepFrom: [0] }),
|
|
48
52
|
// ORBE: `loading` é estado da página (requisições em andamento), não
|
|
49
53
|
// preferência de tema. Persistido, um reload no meio de uma requisição
|
|
50
54
|
// reabria a tela com o loading global ligado e nada o desligava.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comportamentos do axios do client-core que uma instância própria do projeto
|
|
3
|
+
* (ex.: o `AppAxiosBase` de um microfrontend) pode herdar. Cada projeto mantém
|
|
4
|
+
* a sua instância, para recursos e decisões próprios, e escolhe o que herda
|
|
5
|
+
* por uma variável de configuração.
|
|
6
|
+
*/
|
|
7
|
+
export type TClientCoreAxiosInheritance = {
|
|
8
|
+
/**
|
|
9
|
+
* Autenticação: headers da sessão em toda requisição, sessão em cookies
|
|
10
|
+
* (refresh e repetição), 401/403 (encerra a sessão ou vai para acesso negado).
|
|
11
|
+
*/
|
|
12
|
+
auth?: boolean
|
|
13
|
+
/** Plug-in de feedback das requisições (ver `installRequestFeedback`). */
|
|
14
|
+
requestFeedback?: boolean
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exibição do loading global de tela cheia (`GlobalLoading`). Não é persistido.
|
|
3
|
+
*
|
|
4
|
+
* Com os padrões (`0`), o loading aparece e some junto com as requisições,
|
|
5
|
+
* como sempre foi. Os atrasos são opt-in por frontend.
|
|
6
|
+
*/
|
|
7
|
+
export type TGlobalLoadingDisplayConfig = {
|
|
8
|
+
/**
|
|
9
|
+
* Só mostra o loading se as requisições passarem deste tempo (ms). Evita o
|
|
10
|
+
* piscar em requisições rápidas, inclusive nas que falham na hora.
|
|
11
|
+
*/
|
|
12
|
+
showDelayMs: number
|
|
13
|
+
/** Depois de aparecer, o loading fica pelo menos este tempo (ms). */
|
|
14
|
+
minVisibleMs: number
|
|
15
|
+
}
|
package/lib/base/@types/index.ts
CHANGED
|
@@ -4,3 +4,8 @@ export * from './filters';
|
|
|
4
4
|
export * from './forms';
|
|
5
5
|
export * from './models';
|
|
6
6
|
export * from './store';
|
|
7
|
+
|
|
8
|
+
// Feedback das requisições, exibição do loading global e herança do axios
|
|
9
|
+
export * from './requestFeedback';
|
|
10
|
+
export * from './globalLoadingDisplay';
|
|
11
|
+
export * from './clientCoreAxios';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plug-in de feedback das requisições: opções que cada requisição pode ligar.
|
|
3
|
+
*
|
|
4
|
+
* O plug-in não repete requisições. Quem repete é quem chama (SWR, React Query,
|
|
5
|
+
* um botão de recarregar), seguindo a regra de negócio da chamada. O plug-in só
|
|
6
|
+
* percebe que a mesma requisição está sendo tentada de novo e troca o loading
|
|
7
|
+
* de tela cheia por um aviso que não bloqueia a tela.
|
|
8
|
+
*/
|
|
9
|
+
export type TRequestFeedbackOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* Novas tentativas não bloqueiam a tela e mostram "Tentando novamente".
|
|
12
|
+
* Padrão: `true`.
|
|
13
|
+
*/
|
|
14
|
+
retry?: boolean
|
|
15
|
+
/** Aviso de "não encontrado" quando a resposta é 404. Padrão: `true`. */
|
|
16
|
+
notFound?: boolean
|
|
17
|
+
/** Aviso de "requisição inválida" quando a resposta é 400. Padrão: `true`. */
|
|
18
|
+
badRequest?: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Tipos de aviso exibidos para respostas que não adianta repetir */
|
|
22
|
+
export type TRequestNoticeKind = 'notFound' | 'badRequest'
|
|
23
|
+
|
|
24
|
+
declare module 'axios' {
|
|
25
|
+
interface AxiosRequestConfig {
|
|
26
|
+
/**
|
|
27
|
+
* Nome amigável da requisição, exibido ao usuário (ex.: "Documentos do
|
|
28
|
+
* produtor"). É só um dado: sozinho não muda nenhum comportamento.
|
|
29
|
+
*/
|
|
30
|
+
label?: string
|
|
31
|
+
/**
|
|
32
|
+
* Liga o plug-in de feedback nesta requisição (opt-in). Só tem efeito
|
|
33
|
+
* nas instâncias com `installRequestFeedback` e com o plug-in ligado no
|
|
34
|
+
* frontend (`configureRequestFeedback({ enabled: true })`).
|
|
35
|
+
*/
|
|
36
|
+
requestFeedback?: boolean | TRequestFeedbackOptions
|
|
37
|
+
/** Uso interno do plug-in: identifica a requisição entre tentativas. */
|
|
38
|
+
requestFeedbackKey?: string
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Configuração do plug-in num frontend (`configureRequestFeedback`). */
|
|
43
|
+
export type TRequestFeedbackConfig = {
|
|
44
|
+
/** Liga o plug-in neste frontend. Desligado por padrão. */
|
|
45
|
+
enabled: boolean
|
|
46
|
+
/**
|
|
47
|
+
* Quanto tempo (ms) o aviso de nova tentativa espera pela próxima tentativa
|
|
48
|
+
* depois de uma falha. Sem nova tentativa nesse tempo, o aviso some e a
|
|
49
|
+
* próxima chamada volta a ser tratada como primeira tentativa.
|
|
50
|
+
*/
|
|
51
|
+
retryLingerMs: number
|
|
52
|
+
/** Quanto tempo (ms) os avisos de 400 e 404 ficam visíveis. `0` mantém até fechar. */
|
|
53
|
+
noticeDurationMs: number
|
|
54
|
+
/** Quantos avisos de 400 e 404 ficam visíveis ao mesmo tempo. */
|
|
55
|
+
maxNotices: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type TRetryEntryStatus = 'retrying' | 'waiting'
|
|
59
|
+
|
|
60
|
+
export type TRetryEntry = {
|
|
61
|
+
key: string
|
|
62
|
+
label?: string
|
|
63
|
+
/** Tentativa atual: 1 é a primeira chamada, 2 a primeira nova tentativa... */
|
|
64
|
+
attempt: number
|
|
65
|
+
/** `retrying`: tentativa em andamento; `waiting`: falhou e aguarda a próxima. */
|
|
66
|
+
status: TRetryEntryStatus
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type TRequestNotice = {
|
|
70
|
+
id: number
|
|
71
|
+
kind: TRequestNoticeKind
|
|
72
|
+
label?: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Opções das regras de nova tentativa (`queryRetryPolicy`). */
|
|
76
|
+
export type TRetryPolicyOptions = {
|
|
77
|
+
/** Quantas novas tentativas, além da primeira chamada. */
|
|
78
|
+
maxRetries?: number
|
|
79
|
+
/** Status HTTP que não são repetidos. Padrão: 400 e 404. */
|
|
80
|
+
nonRetryableStatuses?: number[]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Opções da regra de nova tentativa do SWR (`swrRetryPolicy`). */
|
|
84
|
+
export type TSwrRetryPolicyOptions = TRetryPolicyOptions & {
|
|
85
|
+
/** Intervalo base entre tentativas (ms). Padrão: `errorRetryInterval` do SWR. */
|
|
86
|
+
intervalMs?: number
|
|
87
|
+
}
|
|
@@ -29,11 +29,12 @@
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
.glass-control {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
/* Claro: borda cinza e sombra curta; borda branca sobre o gray-100 ficava em 1,05:1 e sumia */
|
|
33
|
+
background: color-mix(in srgb, #ffffff 72%, transparent);
|
|
34
|
+
border: 1px solid color-mix(in srgb, var(--gray-300) 85%, transparent);
|
|
34
35
|
-webkit-backdrop-filter: blur(16px) saturate(140%);
|
|
35
36
|
backdrop-filter: blur(16px) saturate(140%);
|
|
36
|
-
box-shadow: 0 8px 24px -
|
|
37
|
+
box-shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 8px 24px -12px rgb(0 0 0 / 0.18);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
.dark .glass-control {
|
|
@@ -66,7 +67,11 @@
|
|
|
66
67
|
0 12px 32px -18px rgb(0 0 0 / 0.5);
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
/*
|
|
70
|
+
/*
|
|
71
|
+
* Borda de vidro fosco: aro em degradê, cinza no topo e tingido pela cor
|
|
72
|
+
* primária na base. No claro o aro é cinza: branco sobre o fundo claro não
|
|
73
|
+
* aparecia.
|
|
74
|
+
*/
|
|
70
75
|
.authorization-glass::before {
|
|
71
76
|
content: '';
|
|
72
77
|
position: absolute;
|
|
@@ -76,9 +81,9 @@
|
|
|
76
81
|
border-radius: inherit;
|
|
77
82
|
background: linear-gradient(
|
|
78
83
|
150deg,
|
|
79
|
-
color-mix(in srgb,
|
|
80
|
-
color-mix(in srgb,
|
|
81
|
-
color-mix(in srgb, var(--primary)
|
|
84
|
+
color-mix(in srgb, var(--gray-300) 70%, transparent) 0%,
|
|
85
|
+
color-mix(in srgb, var(--gray-200) 60%, transparent) 45%,
|
|
86
|
+
color-mix(in srgb, var(--primary) 30%, transparent) 100%
|
|
82
87
|
);
|
|
83
88
|
-webkit-mask:
|
|
84
89
|
linear-gradient(#000 0 0) content-box,
|
|
@@ -2,6 +2,12 @@ import { useEffect, useRef } from 'react'
|
|
|
2
2
|
import classNames from '@/utils/classNames'
|
|
3
3
|
import { useThemeStore } from '@/store/themeStore'
|
|
4
4
|
import type { CommonProps } from '@/@types/common'
|
|
5
|
+
import {
|
|
6
|
+
fitParticles,
|
|
7
|
+
rescaleSpeed,
|
|
8
|
+
type TFieldSize,
|
|
9
|
+
type TParticle,
|
|
10
|
+
} from './particleField'
|
|
5
11
|
import { prefersReducedMotion, readThemeColor } from './themeColor'
|
|
6
12
|
import type { TRgb } from './themeColor'
|
|
7
13
|
|
|
@@ -34,25 +40,9 @@ export interface ParticleNetworkBackgroundProps extends CommonProps {
|
|
|
34
40
|
const AREA_PER_PARTICLE = 12000
|
|
35
41
|
/** Teto de partículas: as ligações são O(n²) por quadro. */
|
|
36
42
|
const MAX_PARTICLES = 320
|
|
37
|
-
/** Velocidade máxima de deriva com `speed = 1`, em px por quadro a 60 fps. */
|
|
38
|
-
const BASE_SPEED = 0.3
|
|
39
|
-
|
|
40
|
-
type TParticle = { x: number; y: number; vx: number; vy: number }
|
|
41
|
-
|
|
42
43
|
const rgba = ([r, g, b]: TRgb, alpha: number) =>
|
|
43
44
|
`rgba(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)}, ${alpha})`
|
|
44
45
|
|
|
45
|
-
const createParticle = (width: number, height: number, speed: number): TParticle => {
|
|
46
|
-
const angle = Math.random() * Math.PI * 2
|
|
47
|
-
const velocity = (0.3 + Math.random() * 0.7) * BASE_SPEED * speed
|
|
48
|
-
return {
|
|
49
|
-
x: Math.random() * width,
|
|
50
|
-
y: Math.random() * height,
|
|
51
|
-
vx: Math.cos(angle) * velocity,
|
|
52
|
-
vy: Math.sin(angle) * velocity,
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
46
|
/**
|
|
57
47
|
* Fundo "particle network": partículas que derivam devagar e se ligam por
|
|
58
48
|
* linhas quando estão próximas, mais fortes quanto mais perto. Cores do tema
|
|
@@ -61,6 +51,10 @@ const createParticle = (width: number, height: number, speed: number): TParticle
|
|
|
61
51
|
*
|
|
62
52
|
* Canvas 2D, sem dependências. Com `speed = 0` ou `prefers-reduced-motion`
|
|
63
53
|
* desenha um quadro parado.
|
|
54
|
+
*
|
|
55
|
+
* As partículas sobrevivem a mudanças de tamanho, tema e opções: ao
|
|
56
|
+
* redimensionar, as que existem ficam no lugar e só entram ou saem
|
|
57
|
+
* partículas onde a área mudou (`fitParticles`).
|
|
64
58
|
*/
|
|
65
59
|
const ParticleNetworkBackground = ({
|
|
66
60
|
className,
|
|
@@ -72,6 +66,13 @@ const ParticleNetworkBackground = ({
|
|
|
72
66
|
...options,
|
|
73
67
|
}
|
|
74
68
|
const canvasRef = useRef<HTMLCanvasElement>(null)
|
|
69
|
+
// Fora do efeito: o efeito roda de novo ao trocar tema ou opções, e
|
|
70
|
+
// recriar as partículas aí faria a animação recomeçar.
|
|
71
|
+
const fieldRef = useRef<{
|
|
72
|
+
particles: TParticle[]
|
|
73
|
+
size: TFieldSize
|
|
74
|
+
speed: number
|
|
75
|
+
}>({ particles: [], size: { width: 0, height: 0 }, speed })
|
|
75
76
|
const mode = useThemeStore((state) => state.mode)
|
|
76
77
|
const themeSchema = useThemeStore((state) => state.themeSchema)
|
|
77
78
|
|
|
@@ -95,13 +96,17 @@ const ParticleNetworkBackground = ({
|
|
|
95
96
|
readColors()
|
|
96
97
|
const lineOpacity = isDark ? 0.5 : 0.4
|
|
97
98
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
const field = fieldRef.current
|
|
100
|
+
field.particles = rescaleSpeed(field.particles, field.speed, speed)
|
|
101
|
+
field.speed = speed
|
|
102
|
+
let particles = field.particles
|
|
103
|
+
let width = field.size.width
|
|
104
|
+
let height = field.size.height
|
|
101
105
|
let frame = 0
|
|
102
106
|
|
|
103
107
|
const resize = () => {
|
|
104
108
|
const ratio = Math.min(window.devicePixelRatio, 2)
|
|
109
|
+
const previous = field.size
|
|
105
110
|
width = canvas.clientWidth
|
|
106
111
|
height = canvas.clientHeight
|
|
107
112
|
canvas.width = Math.round(width * ratio)
|
|
@@ -112,9 +117,9 @@ const ParticleNetworkBackground = ({
|
|
|
112
117
|
MAX_PARTICLES,
|
|
113
118
|
Math.round(((width * height) / AREA_PER_PARTICLE) * Math.max(density, 0)),
|
|
114
119
|
)
|
|
115
|
-
particles =
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
particles = fitParticles(particles, previous, { width, height }, count, speed)
|
|
121
|
+
field.particles = particles
|
|
122
|
+
field.size = { width, height }
|
|
118
123
|
if (!animated) draw()
|
|
119
124
|
}
|
|
120
125
|
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { createParticle, fitParticles, rescaleSpeed, type TParticle } from './particleField'
|
|
3
|
+
|
|
4
|
+
const field = (count: number, width = 1000, height = 800) =>
|
|
5
|
+
Array.from({ length: count }, () => createParticle({ width, height }, 1))
|
|
6
|
+
|
|
7
|
+
describe('fitParticles', () => {
|
|
8
|
+
it('na primeira vez, cria todas as partículas na área inteira', () => {
|
|
9
|
+
const particles = fitParticles([], { width: 0, height: 0 }, { width: 500, height: 400 }, 30, 1)
|
|
10
|
+
|
|
11
|
+
expect(particles).toHaveLength(30)
|
|
12
|
+
for (const p of particles) {
|
|
13
|
+
expect(p.x).toBeGreaterThanOrEqual(0)
|
|
14
|
+
expect(p.x).toBeLessThanOrEqual(500)
|
|
15
|
+
expect(p.y).toBeGreaterThanOrEqual(0)
|
|
16
|
+
expect(p.y).toBeLessThanOrEqual(400)
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('ao crescer, mantém as existentes no lugar e cria as novas só na faixa que apareceu', () => {
|
|
21
|
+
const previous = { width: 1000, height: 800 }
|
|
22
|
+
const before = field(50)
|
|
23
|
+
const snapshot = before.map((p) => ({ ...p }))
|
|
24
|
+
|
|
25
|
+
const after = fitParticles(before, previous, { width: 1400, height: 800 }, 70, 1)
|
|
26
|
+
|
|
27
|
+
expect(after).toHaveLength(70)
|
|
28
|
+
expect(after.slice(0, 50)).toEqual(snapshot)
|
|
29
|
+
for (const p of after.slice(50)) {
|
|
30
|
+
expect(p.x).toBeGreaterThanOrEqual(1000)
|
|
31
|
+
expect(p.x).toBeLessThanOrEqual(1400)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('ao crescer para baixo, as novas ficam na faixa de baixo', () => {
|
|
36
|
+
const after = fitParticles(field(50), { width: 1000, height: 800 }, { width: 1000, height: 1000 }, 62, 1)
|
|
37
|
+
|
|
38
|
+
for (const p of after.slice(50)) {
|
|
39
|
+
expect(p.y).toBeGreaterThanOrEqual(800)
|
|
40
|
+
expect(p.y).toBeLessThanOrEqual(1000)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('ao diminuir, tira primeiro as que ficaram fora e mantém as de dentro intactas', () => {
|
|
45
|
+
const inside: TParticle[] = Array.from({ length: 20 }, (_, i) => ({ x: i * 10, y: 10, vx: 0, vy: 0 }))
|
|
46
|
+
const outside: TParticle[] = Array.from({ length: 20 }, (_, i) => ({ x: 900 + i, y: 10, vx: 0, vy: 0 }))
|
|
47
|
+
|
|
48
|
+
const after = fitParticles([...inside, ...outside], { width: 1000, height: 800 }, { width: 500, height: 800 }, 20, 1)
|
|
49
|
+
|
|
50
|
+
expect(after).toEqual(inside)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('se ainda sobram, remove ao acaso entre as de dentro', () => {
|
|
54
|
+
const before = field(40, 500, 400)
|
|
55
|
+
const after = fitParticles(before, { width: 500, height: 400 }, { width: 500, height: 400 }, 25, 1)
|
|
56
|
+
|
|
57
|
+
expect(after).toHaveLength(25)
|
|
58
|
+
for (const p of after) expect(before).toContain(p)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('mesmo tamanho e mesma quantidade: nada muda', () => {
|
|
62
|
+
const before = field(30)
|
|
63
|
+
const after = fitParticles(before, { width: 1000, height: 800 }, { width: 1000, height: 800 }, 30, 1)
|
|
64
|
+
|
|
65
|
+
expect(after).toEqual(before)
|
|
66
|
+
expect(after).not.toBe(before)
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
describe('rescaleSpeed', () => {
|
|
71
|
+
it('mantém a direção e escala a velocidade', () => {
|
|
72
|
+
const [p] = rescaleSpeed([{ x: 1, y: 2, vx: 0.2, vy: -0.1 }], 1, 2)
|
|
73
|
+
|
|
74
|
+
expect(p).toEqual({ x: 1, y: 2, vx: 0.4, vy: -0.2 })
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('saindo de parado, sorteia velocidades novas', () => {
|
|
78
|
+
const [p] = rescaleSpeed([{ x: 1, y: 2, vx: 0, vy: 0 }], 0, 1)
|
|
79
|
+
|
|
80
|
+
expect(Math.hypot(p.vx, p.vy)).toBeGreaterThan(0)
|
|
81
|
+
expect(p.x).toBe(1)
|
|
82
|
+
})
|
|
83
|
+
})
|