@bildvitta/quasar-ui-asteroid 3.20.0-beta.16 → 3.20.0-beta.17

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bildvitta/quasar-ui-asteroid",
3
3
  "description": "Asteroid",
4
- "version": "3.20.0-beta.16",
4
+ "version": "3.20.0-beta.17",
5
5
  "author": "Bild & Vitta <systemteam@bild.com.br>",
6
6
  "license": "MIT",
7
7
  "main": "./src/asteroid.js",
@@ -17,22 +17,62 @@ const historyRoute = ref({
17
17
  const canLeaveOverlay = ref(true)
18
18
 
19
19
  /**
20
- * Definição de callbacks locais para esta instância.
21
- * Obs: são arrays para permitir múltiplos callbacks, ex se você usa "onCloseOverlay" em 2 componentes diferentes,
22
- * ambos serão executados.
20
+ * Cria o estado de callbacks para uma entidade (ou para o modo padrão sem entidade).
21
+ *
22
+ * Definição de callbacks para a entidade.
23
+ * Obs: são arrays para permitir múltiplos callbacks, ex se você usa "onCloseOverlay" em 2 componentes
24
+ * diferentes da mesma entidade, ambos serão executados.
25
+ * @private
23
26
  */
24
- const callbackFunctions = {
25
- onCloseOverlay: [],
26
- onExpandOverlay: [],
27
- onHideOverlay: [],
28
- onBackgroundChange: [],
29
- onOverlayChange: []
27
+ function createCallbackFunctionsByEntity () {
28
+ return {
29
+ onCloseOverlay: [],
30
+ onExpandOverlay: [],
31
+ onHideOverlay: [],
32
+ onBackgroundChange: [],
33
+ onOverlayChange: []
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Registro de callbacks por entidade.
39
+ * A chave 'default' representa o modo padrão (sem entidade).
40
+ * @type {Map<string, ReturnType<typeof createCallbackFunctionsByEntity>>}
41
+ */
42
+ const callbackFunctionsByEntity = new Map()
43
+
44
+ /**
45
+ * Retorna (ou cria) o estado compartilhado para a entidade informada.
46
+ * @private
47
+ * @param {string|undefined} entity
48
+ */
49
+ function getCallbackFunctionsByEntity (entity) {
50
+ const entityKey = entity ?? 'default'
51
+
52
+ if (!callbackFunctionsByEntity.has(entityKey)) {
53
+ callbackFunctionsByEntity.set(entityKey, createCallbackFunctionsByEntity())
54
+ }
55
+
56
+ return callbackFunctionsByEntity.get(entityKey)
30
57
  }
31
58
 
32
59
  /**
33
60
  * Composable para gerenciar navegação em overlays, sempre que for lidar com overlays utilize esse composable.
61
+ *
62
+ * @example
63
+ * Modo padrão — comportamento legado, estado global compartilhado
64
+ * const nav = useOverlayNavigation()
65
+ *
66
+ * Modo com entidade — página A e componente B compartilham 'activities', isolado de 'funnels'
67
+ * const nav = useOverlayNavigation('activities')
68
+ *
69
+ * @param {string} [entity] - Nome da entidade para isolar os callbacks.
70
+ * Quando informado, instâncias com a mesma entidade compartilham os callbacks entre si, mas são isoladas de
71
+ * instâncias com entidades diferentes.
34
72
  */
35
- export default function useOverlayNavigation () {
73
+ export default function useOverlayNavigation (entity) {
74
+ const callbackFunctions = getCallbackFunctionsByEntity(entity)
75
+
36
76
  // composables
37
77
  const route = useRoute()
38
78
  const router = useRouter()
@@ -255,6 +295,71 @@ export default function useOverlayNavigation () {
255
295
  callbackFunctions[callbackName].forEach(fn => fn(payload))
256
296
  }
257
297
 
298
+ /**
299
+ * Remove listeners registrados no composable.
300
+ *
301
+ * @param {Function|Function[]|string} [target] - Função, array de funções, nome da entidade ou vazio para limpar
302
+ * a entidade `default`.
303
+ *
304
+ * @example
305
+ * ```js
306
+ * const { onCloseOverlay, removeListeners } = useOverlayNavigation('activities')
307
+ *
308
+ * function handleClose () { ... }
309
+ * onCloseOverlay(handleClose)
310
+ *
311
+ * removeListeners(handleClose) - Remove apenas handleClose da entidade atual
312
+ *
313
+ * removeListeners([handleClose, handleExpand]) - Remove handleClose e handleExpand da entidade atual
314
+ *
315
+ * removeListeners('activities') - Remove todas as funções registradas na entidade 'activities'
316
+ *
317
+ * removeListeners() - Remove todas as funções das instâncias sem entidade (entity 'default')
318
+ * ```
319
+ */
320
+ function removeListeners (target) {
321
+ // remove todos os callbacks da entidade 'default' (modo padrão sem entidade)
322
+ if (!target) {
323
+ const defaultCallbackFunctions = callbackFunctionsByEntity.get('default')
324
+
325
+ if (!defaultCallbackFunctions) return
326
+
327
+ for (const functionKey of Object.keys(defaultCallbackFunctions)) {
328
+ defaultCallbackFunctions[functionKey] = []
329
+ }
330
+
331
+ return
332
+ }
333
+
334
+ // Remove todos os callbacks de uma entidade pelo nome
335
+ if (typeof target === 'string') {
336
+ // Pego o estado da entidade informada.
337
+ const callbackFunctions = callbackFunctionsByEntity.get(target)
338
+
339
+ if (!callbackFunctions) return
340
+
341
+ // Reseto as funções de callback para a entidade, mantendo a estrutura mas limpando os arrays.
342
+ for (const functionKey of Object.keys(callbackFunctions)) {
343
+ callbackFunctions[functionKey] = []
344
+ }
345
+
346
+ return
347
+ }
348
+
349
+ // Normaliza para array e remove as funções da entidade atual
350
+ const functionsToRemove = Array.isArray(target) ? target : [target]
351
+
352
+ const callbackFunctionsKeys = Object.keys(callbackFunctions)
353
+
354
+ /**
355
+ * Percorro cada função de callback registrada na entidade atual e filtro as funções que devem ser removidas,
356
+ * mantendo as que não devem ser removidas.
357
+ */
358
+ for (const key of callbackFunctionsKeys) {
359
+ callbackFunctions[key] = callbackFunctions[key].filter(fn => !functionsToRemove.includes(fn))
360
+ }
361
+ }
362
+
258
363
  /**
259
364
  * Função para disparar mudanças no background componente.
260
365
  *
@@ -404,6 +509,7 @@ export default function useOverlayNavigation () {
404
509
  triggerOverlayChange,
405
510
  getNormalizedRoute,
406
511
  toggleCanLeaveOverlay,
512
+ removeListeners,
407
513
 
408
514
  // callbacks functions
409
515
  onBackgroundChange,