v-sistec-features 1.16.0 → 1.17.0

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.
@@ -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-iwlNh_Mm.js";
2
2
  export {
3
3
  m as useIframeCommunicator,
4
4
  o as useTheme
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-iwlNh_Mm.js";
3
3
  export * from "@tabler/icons-vue";
4
4
  export {
5
5
  r as SistecPlugin,
@@ -0,0 +1,31 @@
1
+ import { ref as a, onMounted as r, onUnmounted as u, readonly as d } from "vue";
2
+ function h(t) {
3
+ const n = a(window.parent !== window);
4
+ function m(s, o = "*") {
5
+ n.value && window.parent.postMessage(s, o);
6
+ }
7
+ return r(() => {
8
+ t && window.addEventListener("message", t);
9
+ }), u(() => {
10
+ t && window.removeEventListener("message", t);
11
+ }), {
12
+ isInIframe: d(n),
13
+ // readonly para evitar modificação externa
14
+ sendMessage: m
15
+ };
16
+ }
17
+ function c() {
18
+ const t = a("light"), n = a("slate"), m = a("");
19
+ function s(i) {
20
+ const e = i.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), n.value = e.themeBase), e.type === "reload" && location.reload());
22
+ }
23
+ const { sendMessage: o } = h(s);
24
+ r(() => {
25
+ o({ type: "iframeReady" });
26
+ });
27
+ }
28
+ export {
29
+ c as a,
30
+ h as u
31
+ };
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.0",
5
5
  "author": "Márlon Bento Azevedo (https://github.com/marlon-bento)",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,32 +1,48 @@
1
1
  import { useIframeCommunicator } from './useIframeCommunicator';
2
- import { onMounted } from 'vue';
2
+ import { onMounted, ref } 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
+ });
32
48
  }
@@ -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
- };