@mouseless/baked 1.6.0 → 1.6.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.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mouseless/baked",
3
3
  "configKey": "baked",
4
- "version": "1.6.0",
4
+ "version": "1.6.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
@@ -73,7 +73,7 @@ const errorHandled = context.provideError(rawError);
73
73
  const error = normalizeError(rawError);
74
74
  context.providePath(path);
75
75
  context.provideDataDescriptor(descriptor.data);
76
- context.provideParentContext({ ...contextData.parent, data });
76
+ context.provideParentContext({ ...contextData.parent, data, grand: contextData.parent });
77
77
  if (shouldLoad) {
78
78
  context.provideLoading(loading);
79
79
  }
@@ -74,6 +74,7 @@
74
74
  >
75
75
  <Inputs
76
76
  :inputs="inputGroup.inputs"
77
+ form-mode
77
78
  input-class="w-full"
78
79
  @ready="(value) => onReady(`${section.key}_${inputGroup.key}`, value)"
79
80
  @changed="onChanged"
@@ -5,6 +5,9 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
5
5
  type: ObjectConstructor;
6
6
  required: true;
7
7
  };
8
+ formMode: {
9
+ type: BooleanConstructor;
10
+ };
8
11
  modelValue: {
9
12
  type: import("vue").PropType<any>;
10
13
  required: true;
@@ -16,10 +19,15 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
16
19
  type: ObjectConstructor;
17
20
  required: true;
18
21
  };
22
+ formMode: {
23
+ type: BooleanConstructor;
24
+ };
19
25
  modelValue: {
20
26
  type: import("vue").PropType<any>;
21
27
  required: true;
22
28
  };
23
29
  }>> & Readonly<{
24
30
  "onUpdate:modelValue"?: ((value: any) => any) | undefined;
25
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
31
+ }>, {
32
+ formMode: boolean;
33
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -3,11 +3,13 @@
3
3
  v-model="model"
4
4
  :name="schema.name"
5
5
  :descriptor="schema.component"
6
+ :invalid
7
+ @blur="onBlur"
6
8
  />
7
9
  </template>
8
10
 
9
11
  <script setup>
10
- import { computed, watch } from "vue";
12
+ import { computed, ref, watch } from "vue";
11
13
  import { useRoute, useRouter } from "#app";
12
14
  import { useDataMounter, useContext } from "#imports";
13
15
  import { Bake } from "#components";
@@ -15,15 +17,32 @@ const context = useContext();
15
17
  const { mount: mountData, onAfterMount: onAfterMountData } = useDataMounter();
16
18
  const route = useRoute();
17
19
  const router = useRouter();
18
- const { schema } = defineProps({
19
- schema: { type: Object, required: true }
20
+ const { schema, formMode } = defineProps({
21
+ schema: { type: Object, required: true },
22
+ formMode: { type: Boolean }
20
23
  });
21
24
  const model = defineModel({ type: null, required: true });
22
25
  const validations = context.injectValidations();
26
+ const mutableValidations = context.injectMutableValidations();
23
27
  const defaultValue = mountData(schema.default);
24
28
  const query = schema.queryBound ? computed(() => route.query[schema.name]) : void 0;
25
- const validation = computed(() => validations.value[schema.name] || {});
26
- context.provideValidation(validation);
29
+ let validation = void 0;
30
+ let mutableValidation = void 0;
31
+ let touched = void 0;
32
+ let invalidInForm = void 0;
33
+ let invalid = void 0;
34
+ let onBlur = void 0;
35
+ if (validations) {
36
+ validation = computed(() => validations.value[schema.name]);
37
+ mutableValidation = ref({ valid: true });
38
+ touched = ref(false);
39
+ invalidInForm = computed(() => !validation.value?.valid && (validation.value?.persist || touched.value));
40
+ invalid = computed(() => !mutableValidation.value.valid || invalidInForm.value);
41
+ onBlur = () => touched.value = true;
42
+ mutableValidations[schema.name] = mutableValidation;
43
+ context.provideValidation(validation);
44
+ context.provideMutableValidation(mutableValidation);
45
+ }
27
46
  onAfterMountData(async () => {
28
47
  if (!checkValue(model.value)) {
29
48
  if (schema.queryBound && checkValue(query.value)) {
@@ -43,7 +62,7 @@ onAfterMountData(async () => {
43
62
  }, { immediate: true });
44
63
  }
45
64
  watch(model, async (newValue) => {
46
- if (!checkValue(newValue)) {
65
+ if (!checkValue(newValue) && !formMode) {
47
66
  newValue = schema.required ? defaultValue.value : void 0;
48
67
  }
49
68
  await set(newValue);
@@ -5,6 +5,9 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
5
5
  type: ObjectConstructor;
6
6
  required: true;
7
7
  };
8
+ formMode: {
9
+ type: BooleanConstructor;
10
+ };
8
11
  modelValue: {
9
12
  type: import("vue").PropType<any>;
10
13
  required: true;
@@ -16,10 +19,15 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
16
19
  type: ObjectConstructor;
17
20
  required: true;
18
21
  };
22
+ formMode: {
23
+ type: BooleanConstructor;
24
+ };
19
25
  modelValue: {
20
26
  type: import("vue").PropType<any>;
21
27
  required: true;
22
28
  };
23
29
  }>> & Readonly<{
24
30
  "onUpdate:modelValue"?: ((value: any) => any) | undefined;
25
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
31
+ }>, {
32
+ formMode: boolean;
33
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -1,10 +1,10 @@
1
1
  <template>
2
- <AwaitLoading>
3
- <template #loading>
4
- <div class="min-w-60">
5
- <Skeleton class="min-h-10" />
6
- </div>
7
- </template>
2
+ <AwaitLoading
3
+ :skeleton="{
4
+ height: label?.mode === 'ifta' ? '3.6rem' : '2.6rem',
5
+ class: 'min-w-60'
6
+ }"
7
+ >
8
8
  <Validation>
9
9
  <Labeler
10
10
  :label
@@ -23,7 +23,7 @@
23
23
  </template>
24
24
 
25
25
  <script setup>
26
- import { InputNumber, Skeleton } from "primevue";
26
+ import { InputNumber } from "primevue";
27
27
  import { useContext } from "#imports";
28
28
  import { AwaitLoading, Labeler, Validation } from "#components";
29
29
  const context = useContext();
@@ -1,10 +1,10 @@
1
1
  <template>
2
- <AwaitLoading>
3
- <template #loading>
4
- <div class="min-w-60">
5
- <Skeleton class="min-h-10" />
6
- </div>
7
- </template>
2
+ <AwaitLoading
3
+ :skeleton="{
4
+ height: label?.mode === 'ifta' ? '3.6rem' : '2.6rem',
5
+ class: 'min-w-60'
6
+ }"
7
+ >
8
8
  <Validation>
9
9
  <Labeler
10
10
  :label
@@ -23,7 +23,7 @@
23
23
 
24
24
  <script setup>
25
25
  import { ref, watch } from "vue";
26
- import { InputText, Skeleton } from "primevue";
26
+ import { InputText } from "primevue";
27
27
  import { useContext } from "#imports";
28
28
  import { AwaitLoading, Labeler, Validation } from "#components";
29
29
  const context = useContext();
@@ -5,6 +5,9 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
5
5
  type: ArrayConstructor;
6
6
  required: true;
7
7
  };
8
+ formMode: {
9
+ type: BooleanConstructor;
10
+ };
8
11
  inputClass: {
9
12
  type: StringConstructor;
10
13
  default: string;
@@ -17,6 +20,9 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
17
20
  type: ArrayConstructor;
18
21
  required: true;
19
22
  };
23
+ formMode: {
24
+ type: BooleanConstructor;
25
+ };
20
26
  inputClass: {
21
27
  type: StringConstructor;
22
28
  default: string;
@@ -25,5 +31,6 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
25
31
  onReady?: ((...args: any[]) => any) | undefined;
26
32
  onChanged?: ((...args: any[]) => any) | undefined;
27
33
  }>, {
34
+ formMode: boolean;
28
35
  inputClass: string;
29
36
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -4,26 +4,24 @@
4
4
  :key="input.name"
5
5
  v-model="models[input.name]"
6
6
  :schema="input"
7
+ :form-mode
7
8
  :class="inputClass"
8
- :invalid="invalid(input.name)"
9
- @blur="() => touched(input.name)"
10
9
  />
11
10
  </template>
12
11
 
13
12
  <script setup>
14
- import { computed, reactive, ref, watch } from "vue";
13
+ import { computed, reactive, watch } from "vue";
15
14
  import { useContext, useRoute } from "#imports";
16
15
  import { Input } from "#components";
17
16
  const context = useContext();
18
17
  const route = useRoute();
19
- const { inputs } = defineProps({
18
+ const { inputs, formMode } = defineProps({
20
19
  inputs: { type: Array, required: true },
20
+ formMode: { type: Boolean },
21
21
  inputClass: { type: String, default: "" }
22
22
  });
23
23
  const emit = defineEmits(["ready", "changed"]);
24
24
  const parentPath = context.injectPath();
25
- const validations = context.injectValidations();
26
- const inputEvents = ref({});
27
25
  const models = reactive({});
28
26
  const values = computed(
29
27
  () => inputs.reduce((result, input) => {
@@ -33,7 +31,7 @@ const values = computed(
33
31
  );
34
32
  context.providePath(`${parentPath}/inputs`);
35
33
  watch(values, (newValues) => {
36
- if (inputs.filter((i) => i.default || i.defaultSelfManaged).some((i) => !checkValue(newValues[i.name]))) {
34
+ if (!formMode && inputs.filter((i) => i.default || i.defaultSelfManaged).some((i) => !checkValue(newValues[i.name]))) {
37
35
  return;
38
36
  }
39
37
  emitChanged();
@@ -64,16 +62,4 @@ function getValue(input) {
64
62
  return models[input.name];
65
63
  }
66
64
  }
67
- function touched(key) {
68
- inputEvents.value[key] = { touched: true };
69
- }
70
- function invalid(input) {
71
- if (!Object.values(validations.value).length) {
72
- return;
73
- }
74
- if (!validations.value[input]?.valid && validations.value[input]?.persist) {
75
- return true;
76
- }
77
- return !validations.value[input]?.valid && inputEvents.value[input]?.touched || false;
78
- }
79
65
  </script>
@@ -5,6 +5,9 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
5
5
  type: ArrayConstructor;
6
6
  required: true;
7
7
  };
8
+ formMode: {
9
+ type: BooleanConstructor;
10
+ };
8
11
  inputClass: {
9
12
  type: StringConstructor;
10
13
  default: string;
@@ -17,6 +20,9 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
17
20
  type: ArrayConstructor;
18
21
  required: true;
19
22
  };
23
+ formMode: {
24
+ type: BooleanConstructor;
25
+ };
20
26
  inputClass: {
21
27
  type: StringConstructor;
22
28
  default: string;
@@ -25,5 +31,6 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
25
31
  onReady?: ((...args: any[]) => any) | undefined;
26
32
  onChanged?: ((...args: any[]) => any) | undefined;
27
33
  }>, {
34
+ formMode: boolean;
28
35
  inputClass: string;
29
36
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -12,10 +12,7 @@
12
12
  >
13
13
  <template #default>
14
14
  <slot />
15
- <label
16
- class="max-sm:truncate max-sm:w-5/6"
17
- :for="path"
18
- >
15
+ <label :for="path">
19
16
  {{ localizedText }}
20
17
  </label>
21
18
  </template>
@@ -1,13 +1,15 @@
1
1
  <template>
2
2
  <AwaitLoading :skeleton="{ height: '1.5rem' }">
3
3
  <Button
4
+ v-if="data"
4
5
  :icon
5
- :label="data"
6
+ :label
6
7
  :to
7
8
  as="router-link"
8
9
  link
9
10
  class="m-0 p-0"
10
11
  />
12
+ <span v-else>-</span>
11
13
  </AwaitLoading>
12
14
  </template>
13
15
 
@@ -22,9 +24,10 @@ const { schema, data } = defineProps({
22
24
  schema: { type: null, required: true },
23
25
  data: { type: null, required: true }
24
26
  });
25
- const { icon, path, query: queryData, params: paramsData } = schema;
27
+ const { icon, labelProp, path, query: queryData, params: paramsData } = schema;
26
28
  const query = mountData(queryData);
27
29
  const params = mountData(paramsData);
30
+ const label = computed(() => labelProp ? data?.[labelProp] : data);
28
31
  const to = computed(() => ({
29
32
  path: params.value ? pathBuilder.build(path, params.value, { forRoute: true }) : path,
30
33
  query: query.value
@@ -1,10 +1,10 @@
1
1
  <template>
2
- <AwaitLoading>
3
- <template #loading>
4
- <div class="min-w-40">
5
- <Skeleton class="min-h-10" />
6
- </div>
7
- </template>
2
+ <AwaitLoading
3
+ :skeleton="{
4
+ height: label?.mode === 'ifta' ? '3.6rem' : '2.6rem',
5
+ class: 'min-w-40'
6
+ }"
7
+ >
8
8
  <Validation>
9
9
  <Labeler
10
10
  :label
@@ -21,7 +21,6 @@
21
21
  :auto-filter-focus="filter"
22
22
  :filter-fields="[optionLabel]"
23
23
  reset-filter-on-hide
24
- class="w-full"
25
24
  >
26
25
  <template #value="slotProps">
27
26
  <span>{{ getValueLabel(slotProps) }}</span>
@@ -37,7 +36,7 @@
37
36
 
38
37
  <script setup>
39
38
  import { ref, watch } from "vue";
40
- import { Select, Skeleton } from "primevue";
39
+ import { Select } from "primevue";
41
40
  import { useContext, useUiStates, useLocalization } from "#imports";
42
41
  import { AwaitLoading, Labeler, Validation } from "#components";
43
42
  const context = useContext();
@@ -97,5 +96,5 @@ function setSelected(value) {
97
96
  </script>
98
97
 
99
98
  <style>
100
- .b-component--Select .p-placeholder{opacity:0}.b-component--Select .p-select-label{font-size:inherit}
99
+ .b-component--Select .p-placeholder{opacity:0}.b-component--Select .p-select-label{font-size:inherit}.p-popover-content .b-component--Select{@apply max-md:w-full}
101
100
  </style>
@@ -1,10 +1,10 @@
1
1
  <template>
2
- <AwaitLoading>
3
- <template #loading>
4
- <div class="min-w-60">
5
- <Skeleton class="min-h-10" />
6
- </div>
7
- </template>
2
+ <AwaitLoading
3
+ :skeleton="{
4
+ height: label?.mode === 'ifta' ? '3.6rem' : '2.6rem',
5
+ class: 'min-w-60'
6
+ }"
7
+ >
8
8
  <Validation>
9
9
  <Labeler
10
10
  :label="{
@@ -46,7 +46,7 @@
46
46
 
47
47
  <script setup>
48
48
  import { ref, watch } from "vue";
49
- import { SelectButton, Skeleton } from "primevue";
49
+ import { SelectButton } from "primevue";
50
50
  import { useContext, useLocalization, useUiStates } from "#imports";
51
51
  import { AwaitLoading, Labeler, Validation } from "#components";
52
52
  const context = useContext();
@@ -109,7 +109,7 @@ function setSelected(value) {
109
109
  </script>
110
110
 
111
111
  <style>
112
- .p-togglebutton-content{@apply whitespace-nowrap}.p-popover-content .b-component--SelectButton .p-selectbutton{@apply max-sm:flex max-sm:flex-col}.p-popover-content .b-component--SelectButton .p-selectbutton .p-togglebutton:first-child{@apply max-sm:rounded-t-lg max-sm:rounded-es-none}.p-popover-content .b-component--SelectButton .p-selectbutton .p-togglebutton:last-child{@apply max-sm:rounded-b-lg max-sm:rounded-se-none}
112
+ .p-togglebutton-content{@apply whitespace-nowrap}.p-popover-content .b-component--SelectButton .p-selectbutton,.p-popover-content .b-component--SelectButton.p-selectbutton{@apply max-sm:flex max-sm:flex-col}.p-popover-content .b-component--SelectButton .p-selectbutton .p-togglebutton:first-child,.p-popover-content .b-component--SelectButton.p-selectbutton .p-togglebutton:first-child{@apply max-sm:rounded-t-lg max-sm:rounded-es-none}.p-popover-content .b-component--SelectButton .p-selectbutton .p-togglebutton:last-child,.p-popover-content .b-component--SelectButton.p-selectbutton .p-togglebutton:last-child{@apply max-sm:rounded-b-lg max-sm:rounded-se-none}
113
113
  </style>
114
114
 
115
115
  <style scoped>
@@ -64,6 +64,7 @@
64
64
  <Inputs
65
65
  v-if="inputs"
66
66
  :inputs
67
+ form-mode
67
68
  input-class="w-full"
68
69
  @ready="onReady"
69
70
  @changed="onChanged"
@@ -71,7 +72,7 @@
71
72
  </div>
72
73
  <Button
73
74
  ref="submitRef"
74
- v-tooltip.left="{
75
+ v-tooltip.top="{
75
76
  disabled: !showValidationSummary,
76
77
  value: messages,
77
78
  pt: { text: 'text-sm' }
@@ -12,5 +12,6 @@ type __VLS_Slots = {
12
12
  } & {
13
13
  message?: ((props: {
14
14
  validation: any;
15
+ mutableValidation: any;
15
16
  }) => any) | undefined;
16
17
  };
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <template v-if="!validation">
2
+ <template v-if="validationHandled || !validation">
3
3
  <slot />
4
4
  </template>
5
5
  <div
@@ -10,15 +10,16 @@
10
10
  <slot
11
11
  name="message"
12
12
  :validation
13
+ :mutable-validation
13
14
  >
14
15
  <Message
15
- v-if="validation.message && validation.persist"
16
+ v-if="message"
16
17
  :schema="{
17
- severity: validation.severity,
18
+ severity: severity,
18
19
  variant: 'simple',
19
20
  size: 'small'
20
21
  }"
21
- :data="validation.message || ''"
22
+ :data="message || ''"
22
23
  class="ml-3"
23
24
  />
24
25
  </slot>
@@ -26,8 +27,22 @@
26
27
  </template>
27
28
 
28
29
  <script setup>
30
+ import { computed } from "vue";
29
31
  import { useContext } from "#imports";
30
32
  import { Message } from "#components";
31
33
  const context = useContext();
34
+ const validationHandled = context.injectValidationHandled();
32
35
  const validation = context.injectValidation();
36
+ const mutableValidation = context.injectMutableValidation();
37
+ context.provideValidationHandled(true);
38
+ const message = computed(() => {
39
+ if (mutableValidation?.value.message) {
40
+ return mutableValidation.value.message;
41
+ }
42
+ if (validation.value?.message && validation.value?.persist) {
43
+ return validation.value.message;
44
+ }
45
+ return null;
46
+ });
47
+ const severity = computed(() => mutableValidation?.value.severity || validation?.value.severity);
33
48
  </script>
@@ -12,5 +12,6 @@ type __VLS_Slots = {
12
12
  } & {
13
13
  message?: ((props: {
14
14
  validation: any;
15
+ mutableValidation: any;
15
16
  }) => any) | undefined;
16
17
  };
@@ -17,12 +17,18 @@ export default function _default(): {
17
17
  provideExecuting: (value: any) => void;
18
18
  injectLoading: () => import("vue").Ref<boolean, boolean>;
19
19
  provideLoading: (value: any) => void;
20
+ injectMutableValidations: () => {};
21
+ provideMutableValidations: (value: any) => void;
22
+ injectMutableValidation: () => null;
23
+ provideMutableValidation: (value: any) => void;
20
24
  injectPageContext: () => any;
21
25
  providePageContext: (value: any) => void;
22
26
  injectParentContext: () => null;
23
27
  provideParentContext: (value: any) => void;
24
- injectValidations: () => import("vue").Ref<{}, {}>;
28
+ injectValidations: () => null;
25
29
  provideValidations: (value: any) => void;
26
30
  injectValidation: () => null;
27
31
  provideValidation: (value: any) => void;
32
+ injectValidationHandled: () => boolean;
33
+ provideValidationHandled: (value: any) => void;
28
34
  };
@@ -71,6 +71,22 @@ export default function() {
71
71
  provide("__bake_loading", value);
72
72
  }
73
73
 
74
+ function injectMutableValidations() {
75
+ return inject("__bake_mutable_validations", {});
76
+ }
77
+
78
+ function provideMutableValidations(value) {
79
+ provide("__bake_mutable_validations", value);
80
+ }
81
+
82
+ function injectMutableValidation() {
83
+ return inject("__bake_mutable_validation", null);
84
+ }
85
+
86
+ function provideMutableValidation(value) {
87
+ provide("__bake_mutable_validation", value);
88
+ }
89
+
74
90
  function injectPageContext() {
75
91
  return inject("__bake_page_context");
76
92
  }
@@ -88,7 +104,7 @@ export default function() {
88
104
  }
89
105
 
90
106
  function injectValidations() {
91
- return inject("__bake_validations", ref({}));
107
+ return inject("__bake_validations", null);
92
108
  }
93
109
 
94
110
  function provideValidations(value) {
@@ -103,6 +119,14 @@ export default function() {
103
119
  provide("__bake_validation", value);
104
120
  }
105
121
 
122
+ function injectValidationHandled() {
123
+ return inject("__bake_validation_handled", false);
124
+ }
125
+
126
+ function provideValidationHandled(value) {
127
+ provide("__bake_validation_handled", value);
128
+ }
129
+
106
130
  return {
107
131
  injectPath,
108
132
  providePath,
@@ -117,6 +141,10 @@ export default function() {
117
141
  provideExecuting,
118
142
  injectLoading,
119
143
  provideLoading,
144
+ injectMutableValidations,
145
+ provideMutableValidations,
146
+ injectMutableValidation,
147
+ provideMutableValidation,
120
148
  injectPageContext,
121
149
  providePageContext,
122
150
  injectParentContext,
@@ -124,6 +152,8 @@ export default function() {
124
152
  injectValidations,
125
153
  provideValidations,
126
154
  injectValidation,
127
- provideValidation
155
+ provideValidation,
156
+ injectValidationHandled,
157
+ provideValidationHandled
128
158
  };
129
159
  }
@@ -1,3 +1,3 @@
1
1
  export default function _default(): {
2
- run: ({ route, back, expected, actual }?: {}) => Promise<void>;
2
+ run: ({ route, back, expected, actual, ...params }?: {}) => Promise<void>;
3
3
  };
@@ -1,11 +1,17 @@
1
1
  import { useRouter } from "#app";
2
+ import { usePathBuilder } from "#imports";
2
3
 
3
4
  export default function() {
4
5
  const router = useRouter();
6
+ const { build } = usePathBuilder();
5
7
 
6
- async function run({ route, back, expected, actual } = {}) {
8
+ async function run({ route, back, expected, actual, ...params } = {}) {
7
9
  if(expected && actual !== expected) { return; }
8
10
 
11
+ if(route && Object.keys(params).length > 0) {
12
+ route = build(route, params, { forRoute: true });
13
+ }
14
+
9
15
  if(back) {
10
16
  router.back();
11
17
  } else {
@@ -8,4 +8,8 @@ export default function _default(): {
8
8
  messages: import("vue").ComputedRef<string>;
9
9
  validations: import("vue").ComputedRef<any>;
10
10
  };
11
+ injectMutable: () => {
12
+ clear: () => void;
13
+ setError: (message: any) => void;
14
+ } | null;
11
15
  };
@@ -26,14 +26,18 @@ export default function() {
26
26
  }), {})
27
27
  );
28
28
 
29
+ const mutableValidations = {};
30
+
29
31
  context.provideValidations(validations);
32
+ context.provideMutableValidations(mutableValidations);
30
33
 
31
34
  const isValid = computed(() =>
32
- Object.values(validations.value).every(v => v.valid)
35
+ Object.values(validations.value).every(v => v.valid) &&
36
+ Object.values(mutableValidations).every(v => v.value.valid)
33
37
  );
34
38
 
35
39
  const messages = computed(() =>
36
- Object.values(validations.value)
40
+ [...Object.values(validations.value), ...Object.values(mutableValidations).map(v => v.value)]
37
41
  .filter(v => v.message)
38
42
  .map((v, i) => `${i > 0 ? "\n" : ""} - ${v.message}`)
39
43
  .join("")
@@ -42,7 +46,34 @@ export default function() {
42
46
  return { isValid, messages, validations };
43
47
  }
44
48
 
49
+ function injectMutable() {
50
+ const ref = context.injectMutableValidation();
51
+ if(!ref) { return null; }
52
+
53
+ return MutableValidation(ref);
54
+ }
55
+
56
+ return {
57
+ validate,
58
+ injectMutable
59
+ };
60
+ }
61
+
62
+ function MutableValidation(ref) {
63
+ function clear() {
64
+ ref.value.valid = true;
65
+ delete ref.value.message;
66
+ delete ref.value.severity;
67
+ }
68
+
69
+ function setError(message) {
70
+ ref.value.valid = false;
71
+ ref.value.message = message;
72
+ ref.value.severity = "error";
73
+ }
74
+
45
75
  return {
46
- validate
76
+ clear,
77
+ setError
47
78
  };
48
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mouseless/baked",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Baked is an opinionated framework for .NET and Vue. This is the UI package of Baked project.",
5
5
  "keywords": [
6
6
  "baked",