@ramathibodi/nuxt-commons 0.1.51 → 0.1.52

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
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.1.51",
7
+ "version": "0.1.52",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
@@ -2,14 +2,16 @@
2
2
  import {computed, defineExpose, ref, watchEffect} from 'vue'
3
3
  import {cloneDeep, isEqual} from 'lodash-es'
4
4
  import type {FormDialogCallback} from '../../types/formDialog'
5
+ import FormPadComponent from './Pad.vue'
5
6
 
6
- interface Props {
7
+ interface Props extends /* @vue-ignore */ InstanceType<typeof FormPadComponent['$props']> {
7
8
  title?: string
8
9
  initialData?: object
9
10
  saveCaption?: string
10
11
  cancelCaption?: string
11
12
  readonly?: boolean
12
13
  showTitle?: boolean
14
+ skipValidation?:boolean
13
15
  }
14
16
 
15
17
  const props = withDefaults(defineProps<Props>(), {
@@ -17,6 +19,7 @@ const props = withDefaults(defineProps<Props>(), {
17
19
  cancelCaption: 'ยกเลิก',
18
20
  readonly: false,
19
21
  showTitle: false,
22
+ skipValidation:false
20
23
  })
21
24
 
22
25
  const isSaving = ref<boolean>(false)
@@ -27,7 +30,7 @@ const formDataOriginalValue = ref<object>()
27
30
  const emit = defineEmits(['create', 'update'])
28
31
 
29
32
  function save() {
30
- if (formPadRef.value.isValid) {
33
+ if (props.skipValidation || formPadRef.value?.isValid) {
31
34
  isSaving.value = true
32
35
  emit((isCreating.value) ? 'create' : 'update', cloneDeep(formData.value), callback)
33
36
  }
@@ -39,7 +42,7 @@ function cancel() {
39
42
 
40
43
  function reset() {
41
44
  formDataOriginalValue.value = undefined
42
- formPadRef.value.reset()
45
+ formPadRef.value?.reset()
43
46
  loadFormData()
44
47
  }
45
48
 
@@ -82,7 +85,7 @@ function setOriginalData(originalData?: object) {
82
85
  formDataOriginalValue.value = originalData
83
86
  }
84
87
 
85
- defineExpose({setOriginalData,operation})
88
+ defineExpose({setOriginalData,operation,formPad: formPadRef})
86
89
  </script>
87
90
 
88
91
  <template>
@@ -102,6 +105,7 @@ defineExpose({setOriginalData,operation})
102
105
  v-model="formData"
103
106
  :readonly="readonly"
104
107
  isolated
108
+ v-bind="$attrs"
105
109
  >
106
110
  <template #default="slotData">
107
111
  <slot
@@ -1,9 +1,10 @@
1
1
  <script lang="ts" setup>
2
- import {computed, ref, watchEffect} from 'vue'
2
+ import {computed, defineExpose, ref, watchEffect} from 'vue'
3
3
  import {cloneDeep, isEqual} from 'lodash-es'
4
4
  import type {FormDialogCallback} from '../../types/formDialog'
5
+ import FormPadComponent from './Pad.vue'
5
6
 
6
- interface Props {
7
+ interface Props extends /* @vue-ignore */ InstanceType<typeof FormPadComponent['$props']> {
7
8
  title?: string
8
9
  initialData?: object
9
10
  formData?: object
@@ -11,6 +12,7 @@ interface Props {
11
12
  cancelCaption?: string
12
13
  readonly?: boolean
13
14
  showTitle?: boolean
15
+ skipValidation?:boolean
14
16
  }
15
17
 
16
18
  const props = withDefaults(defineProps<Props>(), {
@@ -18,6 +20,7 @@ const props = withDefaults(defineProps<Props>(), {
18
20
  cancelCaption: 'ยกเลิก',
19
21
  readonly: false,
20
22
  showTitle: false,
23
+ skipValidation:false
21
24
  })
22
25
 
23
26
  const isSaving = ref<boolean>(false)
@@ -28,7 +31,7 @@ const formDataOriginalValue = ref<object>()
28
31
  const emit = defineEmits(['create', 'update'])
29
32
 
30
33
  function save() {
31
- if (formPadRef.value.isValid) {
34
+ if (props.skipValidation || formPadRef.value?.isValid) {
32
35
  isSaving.value = true
33
36
  emit((isCreating.value) ? 'create' : 'update', cloneDeep(formData.value), callback)
34
37
  }
@@ -40,7 +43,7 @@ function cancel() {
40
43
 
41
44
  function reset() {
42
45
  formDataOriginalValue.value = undefined
43
- formPadRef.value.reset()
46
+ formPadRef.value?.reset()
44
47
  loadFormData()
45
48
  }
46
49
 
@@ -83,7 +86,7 @@ const operation = ref({ isDataChange, isCreating, isSaving, save, cancel })
83
86
 
84
87
  watchEffect(loadFormData)
85
88
 
86
- defineExpose({operation})
89
+ defineExpose({operation,formPad:formPadRef})
87
90
  </script>
88
91
 
89
92
  <template>
@@ -103,6 +106,7 @@ defineExpose({operation})
103
106
  v-model="formData"
104
107
  :readonly="readonly"
105
108
  isolated
109
+ v-bind="$attrs"
106
110
  >
107
111
  <template #default="slotData">
108
112
  <slot
@@ -1,5 +1,5 @@
1
1
  <script lang="ts" setup>
2
- import { computed, useTemplateRef } from 'vue'
2
+ import { computed, useTemplateRef, defineExpose } from 'vue'
3
3
  import { type GraphqlModelItemProps, useGraphqlModelItem } from '../../composables/graphqlModelItem'
4
4
  import EditPad from '../form/EditPad.vue'
5
5
 
@@ -11,8 +11,6 @@ interface Props extends /* @vue-ignore */ InstanceType<typeof EditPad['$props']>
11
11
  }
12
12
 
13
13
  const props = withDefaults(defineProps<Props & GraphqlModelItemProps>(), {
14
- saveCaption: 'บันทึก',
15
- cancelCaption: 'ยกเลิก',
16
14
  fields: () => ['*'],
17
15
  })
18
16
 
@@ -29,12 +27,12 @@ const operation : any = computed(()=>{
29
27
  return Object.assign({},editPad.value?.operation,{canSave,reload,item})
30
28
  })
31
29
 
32
- defineExpose({ operation })
30
+ defineExpose({ operation, formPad: editPad.value?.formPad })
33
31
  </script>
34
32
 
35
33
  <template>
36
- <FormEditPad :form-data="item" ref="editPadRef" @create="createItem" @update="updateItem">
37
- <template #titleToolbar="slotData">
34
+ <FormEditPad v-bind="$attrs" :form-data="item" ref="editPadRef" @create="createItem" @update="updateItem">
35
+ <template #titleToolbar>
38
36
  <slot name="titleToolbar" :operation="operation">
39
37
  <VToolbarTitle>
40
38
  <slot name="title" :operation="operation">
@@ -1 +1 @@
1
- export declare const useUserPermission: () => unknown;
1
+ export declare const useUserPermission: () => import("../types/permission").PermissionPlugin;
@@ -11,18 +11,18 @@ export default defineNuxtPlugin((nuxtApp) => {
11
11
  const arr = normalize(input);
12
12
  return arr.length === 0 || arr.every((v) => v.trim() === "");
13
13
  }
14
- function check(permissionIds) {
14
+ const check = (permissionIds) => {
15
15
  if (isBlank(permissionIds)) return true;
16
16
  const auth = useAuthentication();
17
17
  const perms = normalize(permissionIds);
18
18
  return perms.some((id) => auth?.hasPermission(id));
19
- }
20
- function checkAll(permissionIds) {
19
+ };
20
+ const checkAll = (permissionIds) => {
21
21
  if (isBlank(permissionIds)) return true;
22
22
  const auth = useAuthentication();
23
23
  const perms = normalize(permissionIds);
24
24
  return perms.every((id) => auth?.hasPermission(id));
25
- }
25
+ };
26
26
  nuxtApp.vueApp.directive("permission", (el, binding, vnode) => {
27
27
  if (!check(binding.value)) {
28
28
  vnode?.um?.forEach?.((um) => um());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "0.1.51",
3
+ "version": "0.1.52",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",