v-sistec-features 1.16.0 → 1.17.1

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.
@@ -13,6 +13,10 @@ export declare function useIframeCommunicator(onMessageReceived?: (event: Messag
13
13
  * Um composable "tudo-em-um" que configura a comunicação de temas com a janela pai.
14
14
  * para usar, bastar importar e chamar useTheme() na raiz do component app do iframe
15
15
  */
16
- export declare function useTheme(): void;
16
+ export declare function useTheme(): {
17
+ theme: Readonly<Ref<string, string>>;
18
+ themePalette: Readonly<Ref<string, string>>;
19
+ themePrimary: Readonly<Ref<string, string>>;
20
+ };
17
21
 
18
22
  export { }
@@ -1,4 +1,4 @@
1
- import { u as m, a as o } from "./useThemeFromParent-Bk-du0-V.js";
1
+ import { u as m, a as o } from "./useThemeFromParent-DVAilJ4B.js";
2
2
  export {
3
3
  m as useIframeCommunicator,
4
4
  o as useTheme
package/dist/index.d.ts CHANGED
@@ -18,7 +18,11 @@ export declare function useIframeCommunicator(onMessageReceived?: (event: Messag
18
18
  * Um composable "tudo-em-um" que configura a comunicação de temas com a janela pai.
19
19
  * para usar, bastar importar e chamar useTheme() na raiz do component app do iframe
20
20
  */
21
- export declare function useTheme(): void;
21
+ export declare function useTheme(): {
22
+ theme: Readonly<Ref<string, string>>;
23
+ themePalette: Readonly<Ref<string, string>>;
24
+ themePrimary: Readonly<Ref<string, string>>;
25
+ };
22
26
 
23
27
 
24
28
  export * from "@tabler/icons-vue";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { S as r } from "./plugin-C0f4EPnK.js";
2
- import { u as a, a as s } from "./useThemeFromParent-Bk-du0-V.js";
2
+ import { u as a, a as s } from "./useThemeFromParent-DVAilJ4B.js";
3
3
  export * from "@tabler/icons-vue";
4
4
  export {
5
5
  r as SistecPlugin,
@@ -0,0 +1,35 @@
1
+ import { ref as n, onMounted as i, onUnmounted as d, readonly as r } from "vue";
2
+ function h(t) {
3
+ const a = n(window.parent !== window);
4
+ function m(s, o = "*") {
5
+ a.value && window.parent.postMessage(s, o);
6
+ }
7
+ return i(() => {
8
+ t && window.addEventListener("message", t);
9
+ }), d(() => {
10
+ t && window.removeEventListener("message", t);
11
+ }), {
12
+ isInIframe: r(a),
13
+ // readonly para evitar modificação externa
14
+ sendMessage: m
15
+ };
16
+ }
17
+ function l() {
18
+ const t = n("light"), a = n("slate"), m = n("");
19
+ function s(u) {
20
+ const e = u.data;
21
+ e && (e.type === "setTheme" && (document.documentElement.setAttribute("data-bs-theme", e.theme), t.value = e.theme), e.type === "setThemePrimary" && (document.documentElement.setAttribute("data-bs-theme-primary", e.themePrimary), m.value = e.themePrimary), e.type === "setThemeBase" && (document.documentElement.setAttribute("data-bs-theme-base", e.themeBase), a.value = e.themeBase), e.type === "reload" && location.reload());
22
+ }
23
+ const { sendMessage: o } = h(s);
24
+ return i(() => {
25
+ o({ type: "iframeReady" });
26
+ }), {
27
+ theme: r(t),
28
+ themePalette: r(a),
29
+ themePrimary: r(m)
30
+ };
31
+ }
32
+ export {
33
+ l as a,
34
+ h as u
35
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "v-sistec-features",
3
3
  "private": false,
4
- "version": "1.16.0",
4
+ "version": "1.17.1",
5
5
  "author": "Márlon Bento Azevedo (https://github.com/marlon-bento)",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,32 +1,53 @@
1
1
  import { useIframeCommunicator } from './useIframeCommunicator';
2
- import { onMounted } from 'vue';
2
+ import { onMounted, ref, readonly } from 'vue';
3
3
 
4
- function handleThemeMessage(event: MessageEvent) {
5
- if (event.data.type === 'setTheme') {
6
- document.documentElement.setAttribute('data-bs-theme', event.data.theme);
7
- }
8
- if (event.data.type === 'setThemePrimary') {
9
- document.documentElement.setAttribute('data-bs-theme-primary', event.data.themePrimary);
10
- }
11
- if (event.data.type === 'setThemeBase') {
12
- document.documentElement.setAttribute('data-bs-theme-base', event.data.themeBase);
13
- }
14
- if (event.data.type === 'reload') {
15
- location.reload();
16
- }
17
- }
18
4
 
19
5
  /**
20
6
  * Um composable "tudo-em-um" que configura a comunicação de temas com a janela pai.
21
7
  * para usar, bastar importar e chamar useTheme() na raiz do component app do iframe
22
8
  */
23
9
  export function useTheme() {
24
- // Usa o composable genérico, passando o handler de temas, assim ele já configura
25
- // o listener e o que é feito quando receber uma mensagem do pai referente a tema
26
- const { sendMessage } = useIframeCommunicator(handleThemeMessage);
27
-
28
- // passa uma mensagem para o pai avisando que o iframe está pronto para receber temas
29
- onMounted(() => {
30
- sendMessage({ type: 'iframeReady' });
31
- });
10
+
11
+ // Usa o composable genérico, passando o handler de temas, assim ele configura
12
+ // o listener e o que é feito quando receber uma mensagem do pai referente a tema
13
+ const theme = ref('light');
14
+ const themePalette = ref('slate');
15
+ const themePrimary = ref('');
16
+
17
+ function handleThemeMessage(event: MessageEvent) {
18
+ const data = event.data;
19
+
20
+ // Validação básica para evitar erros se data for nulo
21
+ if (!data) return;
22
+
23
+ if (data.type === 'setTheme') {
24
+ document.documentElement.setAttribute('data-bs-theme', data.theme);
25
+ theme.value = data.theme;
26
+ }
27
+
28
+ if (data.type === 'setThemePrimary') {
29
+ document.documentElement.setAttribute('data-bs-theme-primary', data.themePrimary);
30
+ themePrimary.value = data.themePrimary;
31
+ }
32
+
33
+ if (data.type === 'setThemeBase') {
34
+ document.documentElement.setAttribute('data-bs-theme-base', data.themeBase);
35
+ themePalette.value = data.themeBase;
36
+ }
37
+
38
+ if (data.type === 'reload') {
39
+ location.reload();
40
+ }
41
+ }
42
+ const { sendMessage } = useIframeCommunicator(handleThemeMessage);
43
+
44
+ // passa uma mensagem para o pai avisando que o iframe está pronto para receber temas
45
+ onMounted(() => {
46
+ sendMessage({ type: 'iframeReady' });
47
+ });
48
+ return {
49
+ theme: readonly(theme),
50
+ themePalette: readonly(themePalette),
51
+ themePrimary: readonly(themePrimary)
52
+ };
32
53
  }
@@ -1,29 +0,0 @@
1
- import { ref as o, onMounted as a, onUnmounted as d, readonly as r } from "vue";
2
- function i(e) {
3
- const t = o(window.parent !== window);
4
- function m(n, s = "*") {
5
- t.value && window.parent.postMessage(n, s);
6
- }
7
- return a(() => {
8
- e && window.addEventListener("message", e);
9
- }), d(() => {
10
- e && window.removeEventListener("message", e);
11
- }), {
12
- isInIframe: r(t),
13
- // readonly para evitar modificação externa
14
- sendMessage: m
15
- };
16
- }
17
- function u(e) {
18
- e.data.type === "setTheme" && document.documentElement.setAttribute("data-bs-theme", e.data.theme), e.data.type === "setThemePrimary" && document.documentElement.setAttribute("data-bs-theme-primary", e.data.themePrimary), e.data.type === "setThemeBase" && document.documentElement.setAttribute("data-bs-theme-base", e.data.themeBase), e.data.type === "reload" && location.reload();
19
- }
20
- function h() {
21
- const { sendMessage: e } = i(u);
22
- a(() => {
23
- e({ type: "iframeReady" });
24
- });
25
- }
26
- export {
27
- h as a,
28
- i as u
29
- };