@hostlink/nuxt-light 1.67.3 → 1.67.5

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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "light",
3
3
  "configKey": "light",
4
- "version": "1.67.3",
4
+ "version": "1.67.5",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,10 +1,12 @@
1
1
  <script setup>
2
- import { computed } from "vue";
2
+ import { computed, ref } from "vue";
3
3
  import { useErrorMessage } from "./useErrorMessage";
4
4
  const props = defineProps({
5
5
  context: Object
6
6
  });
7
- const { error, errorMessage } = useErrorMessage(props.context.node);
7
+ const error = ref(false);
8
+ const errorMessage = ref("");
9
+ useErrorMessage(props.context.node, error, errorMessage);
8
10
  const value = computed({
9
11
  get: () => props.context.value,
10
12
  set: (val) => props.context.node.input(val)
@@ -1,3 +1 @@
1
- import type { Ref } from 'vue';
2
- import type { FormKitNode } from '@formkit/core';
3
- export declare function useErrorMessage(node: FormKitNode, error: Ref<boolean>, errorMessage: Ref<string>): () => void;
1
+ export declare function useErrorMessage(node: any, error: any, errorMessage: any): () => void;
@@ -1,28 +1,37 @@
1
1
  import { getValidationMessages } from "@formkit/validation";
2
+ import { onBeforeUnmount } from "vue";
2
3
  export function useErrorMessage(node, error, errorMessage) {
4
+ let unmounted = false;
5
+ const setErr = (ref, val) => {
6
+ if (unmounted || !ref) return;
7
+ try {
8
+ ref.value = val;
9
+ } catch (_e) {
10
+ }
11
+ };
3
12
  const showErrorMessage = (msg) => {
4
13
  if (msg.name === "message-updated") {
5
14
  if (msg.payload.type === "validation") {
6
- errorMessage.value = msg.payload.value;
15
+ setErr(errorMessage, msg.payload.value);
7
16
  }
8
17
  }
9
18
  if (msg.name === "message-removed") {
10
19
  if (msg.payload.type === "validation") {
11
- errorMessage.value = "";
12
- error.value = false;
20
+ setErr(errorMessage, "");
21
+ setErr(error, false);
13
22
  }
14
23
  if (msg.payload.type === "state") {
15
- error.value = false;
24
+ setErr(error, false);
16
25
  }
17
26
  }
18
27
  if (msg.name === "message-added") {
19
- errorMessage.value = "";
20
- error.value = false;
28
+ setErr(errorMessage, "");
29
+ setErr(error, false);
21
30
  const messages = getValidationMessages(node);
22
31
  for (const message of messages) {
23
32
  if (message[0]) {
24
- errorMessage.value = message[1][0].value;
25
- error.value = true;
33
+ setErr(errorMessage, message[1][0].value);
34
+ setErr(error, true);
26
35
  break;
27
36
  }
28
37
  }
@@ -30,5 +39,10 @@ export function useErrorMessage(node, error, errorMessage) {
30
39
  };
31
40
  const events = ["message-added", "message-removed", "message-updated"];
32
41
  const receipts = events.map((event) => node.on(event, showErrorMessage));
33
- return () => receipts.forEach((receipt) => node.off(receipt));
42
+ const cleanup = () => {
43
+ unmounted = true;
44
+ receipts.forEach((receipt) => node.off(receipt));
45
+ };
46
+ onBeforeUnmount(cleanup);
47
+ return cleanup;
34
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/nuxt-light",
3
- "version": "1.67.3",
3
+ "version": "1.67.5",
4
4
  "description": "HostLink Nuxt Light Framework",
5
5
  "repository": {
6
6
  "type": "git",