mktcms 0.1.41 → 0.1.43

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": "mktcms",
3
3
  "configKey": "mktcms",
4
- "version": "0.1.41",
4
+ "version": "0.1.43",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -24,7 +24,7 @@ async function saveMarkdown() {
24
24
  isSaving.value = false;
25
25
  savingSuccessful.value = true;
26
26
  }
27
- const mode = ref("edit");
27
+ const mode = ref("preview");
28
28
  </script>
29
29
 
30
30
  <template>
@@ -34,18 +34,18 @@ const mode = ref("edit");
34
34
  <button
35
35
  type="button"
36
36
  class="button secondary flex-1"
37
- :disabled="mode === 'edit'"
38
- @click="mode = 'edit'"
37
+ :disabled="mode === 'preview'"
38
+ @click="mode = 'preview'"
39
39
  >
40
- Bearbeiten
40
+ Vorschau
41
41
  </button>
42
42
  <button
43
43
  type="button"
44
44
  class="button secondary flex-1"
45
- :disabled="mode === 'preview'"
46
- @click="mode = 'preview'"
45
+ :disabled="mode === 'edit'"
46
+ @click="mode = 'edit'"
47
47
  >
48
- Vorschau
48
+ Bearbeiten
49
49
  </button>
50
50
  </div>
51
51
 
@@ -5,7 +5,9 @@ export declare function useForm(endpoint: string, successMessageText: string, er
5
5
  errorMessage: import("vue").Ref<string, string>;
6
6
  validationErrors: import("vue").Ref<Record<string, string[] | undefined>, Record<string, string[] | undefined>>;
7
7
  fieldsTouched: import("vue").Ref<Record<string, boolean>, Record<string, boolean>>;
8
+ isValid: import("vue").ComputedRef<boolean>;
8
9
  validationErrorsFor: (field: string) => string[];
9
10
  validate: (body: Record<string, any>) => boolean;
11
+ touchField: (field: string) => void;
10
12
  send: (body: Record<string, any>) => Promise<void>;
11
13
  };
@@ -1,11 +1,12 @@
1
1
  import { z } from "zod";
2
- import { ref } from "vue";
2
+ import { computed, ref } from "vue";
3
3
  export function useForm(endpoint, successMessageText, errorMessageText, validationSchema) {
4
4
  const isSending = ref(false);
5
5
  const successMessage = ref("");
6
6
  const errorMessage = ref("");
7
7
  const validationErrors = ref({});
8
8
  const fieldsTouched = ref({});
9
+ const isValid = computed(() => Object.keys(validationErrors.value).length === 0 && Object.keys(fieldsTouched.value).length > 0);
9
10
  function validate(body) {
10
11
  const parseResult = validationSchema.safeParse(body);
11
12
  if (parseResult.success) {
@@ -20,6 +21,12 @@ export function useForm(endpoint, successMessageText, errorMessageText, validati
20
21
  if (!fieldsTouched.value[field]) return [];
21
22
  return validationErrors.value[field] || [];
22
23
  }
24
+ function touchField(field) {
25
+ fieldsTouched.value = {
26
+ ...fieldsTouched.value,
27
+ [field]: true
28
+ };
29
+ }
23
30
  async function send(body) {
24
31
  if (isSending.value) return;
25
32
  successMessage.value = "";
@@ -46,8 +53,10 @@ export function useForm(endpoint, successMessageText, errorMessageText, validati
46
53
  errorMessage,
47
54
  validationErrors,
48
55
  fieldsTouched,
56
+ isValid,
49
57
  validationErrorsFor,
50
58
  validate,
59
+ touchField,
51
60
  send
52
61
  };
53
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mktcms",
3
- "version": "0.1.41",
3
+ "version": "0.1.43",
4
4
  "description": "Simple CMS module for Nuxt",
5
5
  "repository": "mktcode/mktcms",
6
6
  "license": "MIT",