@ramathibodi/nuxt-commons 0.1.70 → 0.1.72

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.70",
7
+ "version": "0.1.72",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -53,6 +53,7 @@ const module = defineNuxtModule({
53
53
  _nuxt.options.vite.optimizeDeps.include.push("print-js");
54
54
  _nuxt.options.vite.optimizeDeps.include.push("gql-query-builder");
55
55
  _nuxt.options.vite.optimizeDeps.include.push("exif-rotate-js");
56
+ _nuxt.options.vite.optimizeDeps.include.push("localstorage-slim");
56
57
  }
57
58
  });
58
59
 
@@ -0,0 +1,27 @@
1
+ <script lang="ts" setup>
2
+ import Pad from './Pad.vue'
3
+ import { watch } from 'vue'
4
+ import { useGraphQlOperation } from '../../composables/graphqlOperation'
5
+
6
+ interface Props extends /* @vue-ignore */ InstanceType<typeof Pad['$props']> {
7
+ templateId: string;
8
+ cache?: boolean | number
9
+ }
10
+
11
+ const props = withDefaults(defineProps<Props>(),{
12
+ cache: false
13
+ })
14
+
15
+ const currentTemplate = ref<any>({})
16
+
17
+ watch(()=>props.templateId, (newValue) => {
18
+ useGraphQlOperation("Query","systemTemplateById",["template","templateScript"],{id: newValue},props.cache).then(result => {
19
+ currentTemplate.value = result
20
+ }).catch(_error => {
21
+ currentTemplate.value = {}
22
+ })
23
+ })
24
+ </script>
25
+ <template>
26
+ <FormPad v-bind="$attrs" :template="currentTemplate.template" :template-script="currentTemplate.templateScript" />
27
+ </template>
@@ -203,7 +203,8 @@ defineExpose({
203
203
  reset: ()=>inputRef.value?.reset(),
204
204
  resetValidation : ()=>inputRef.value?.resetValidation(),
205
205
  validate : ()=>inputRef.value?.validate(),
206
- operation
206
+ operation,
207
+ items
207
208
  })
208
209
  </script>
209
210
 
@@ -39,5 +39,9 @@ const computedItemTitle = computed(()=>{
39
39
  :not-found-text="computedNotFoundText"
40
40
  :placeholder="computedPlaceholder"
41
41
  :cache="props.cache"
42
- ></model-label>
42
+ >
43
+ <template v-for="(_, name, index) in ($slots as {})" :key="index" #[name]="slotData">
44
+ <slot :name="name" v-bind="((slotData || {}) as object)" />
45
+ </template>
46
+ </model-label>
43
47
  </template>
@@ -135,7 +135,7 @@ watch(()=>props.search,()=>{
135
135
  search.value = props.search
136
136
  },{immediate:true})
137
137
 
138
- defineExpose({ reload,operation })
138
+ defineExpose({ reload,operation,items })
139
139
  </script>
140
140
 
141
141
  <template>
@@ -2,6 +2,7 @@
2
2
  import { computedAsync } from '@vueuse/core'
3
3
  import { useGraphQlOperation } from '../../composables/graphqlOperation'
4
4
  import { concat } from "lodash-es";
5
+ import { ref } from 'vue'
5
6
 
6
7
  interface Props {
7
8
  modelName: string
@@ -18,6 +19,8 @@ const props = withDefaults(defineProps<Props>(), {
18
19
  cache: false,
19
20
  })
20
21
 
22
+ const modelItem = ref<Record<string, any>>({})
23
+
21
24
  const modelItemValue = computedAsync<string>(async () => {
22
25
  if (props.modelName && props.itemTitle) {
23
26
  let fields: any[] = (typeof props.itemTitle === "string") ? [props.itemTitle] : []
@@ -28,6 +31,7 @@ const modelItemValue = computedAsync<string>(async () => {
28
31
 
29
32
  try {
30
33
  if (result) {
34
+ modelItem.value = result
31
35
  if (typeof props.itemTitle === "string") return result[props.itemTitle]
32
36
  else return props.itemTitle(result)
33
37
  }
@@ -40,5 +44,7 @@ const modelItemValue = computedAsync<string>(async () => {
40
44
  </script>
41
45
 
42
46
  <template>
43
- <span>{{ modelItemValue }}</span>
47
+ <slot name="default" :data="modelItem">
48
+ <span>{{ modelItemValue }}</span>
49
+ </slot>
44
50
  </template>
@@ -4,6 +4,7 @@ import { useAlert } from "./alert.js";
4
4
  import { buildRequiredInputFields } from "./graphqlOperation.js";
5
5
  import { useGraphqlModelOperation } from "./graphqlModelOperation.js";
6
6
  import pLimit from "p-limit";
7
+ import { arrayWrap } from "../utils/array.js";
7
8
  export function useGraphqlModel(props) {
8
9
  const alert = useAlert();
9
10
  const items = ref([]);
@@ -130,6 +131,8 @@ export function useGraphqlModel(props) {
130
131
  items.value = result.data;
131
132
  itemsLength.value = result.meta.totalItems;
132
133
  }).catch((error) => {
134
+ items.value = [];
135
+ itemsLength.value = 0;
133
136
  alert?.addAlert({ alertType: "error", message: error });
134
137
  }).finally(() => {
135
138
  isLoading.value = false;
@@ -142,8 +145,9 @@ export function useGraphqlModel(props) {
142
145
  } else {
143
146
  isLoading.value = true;
144
147
  operationRead.value?.call(fields.value, props.modelBy).then((result) => {
145
- items.value = result;
148
+ items.value = arrayWrap(result);
146
149
  }).catch((error) => {
150
+ items.value = [];
147
151
  alert?.addAlert({ alertType: "error", message: error });
148
152
  }).finally(() => {
149
153
  isLoading.value = false;
@@ -0,0 +1 @@
1
+ export declare function arrayWrap<T>(value: T | T[] | null | undefined): T[];
@@ -0,0 +1,4 @@
1
+ export function arrayWrap(value) {
2
+ if (value === null || value === void 0) return [];
3
+ return Array.isArray(value) ? value : [value];
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "0.1.70",
3
+ "version": "0.1.72",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",