@ramathibodi/nuxt-commons 0.1.3 → 0.1.4

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,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.1.3"
7
+ "version": "0.1.4"
8
8
  }
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { ref } from 'vue'
3
- import { VCard } from 'vuetify/components/VCard'
3
+ import { VCard } from 'vuetify/components/VCard'
4
4
 
5
5
  const isResizing = ref(false)
6
6
  const pane1Width = ref('50%')
@@ -29,31 +29,31 @@ const resize = (event: MouseEvent) => {
29
29
 
30
30
  <template>
31
31
  <v-card :="$attrs">
32
- <v-sheet
33
- border
34
- :height="height"
32
+ <v-sheet
33
+ border
34
+ :height="height"
35
35
  >
36
- <div
37
- ref="containerRef"
38
- class="d-flex"
39
- @mouseup="stopResize"
40
- @mousemove="resize"
36
+ <div
37
+ ref="containerRef"
38
+ class="d-flex"
39
+ @mouseup="stopResize"
40
+ @mousemove="resize"
41
41
  >
42
42
  <v-sheet :width="pane1Width">
43
43
  <slot name="left" />
44
44
  </v-sheet>
45
- <v-divider
46
- :thickness="3"
47
- vertical
48
- class="cursor-move"
49
- @mousedown="startResize"
45
+ <v-divider
46
+ :thickness="3"
47
+ vertical
48
+ class="cursor-move"
49
+ @mousedown="startResize"
50
50
  />
51
51
  <v-sheet :width="`calc(100% - ${pane1Width})`">
52
52
  <slot name="right" />
53
53
  </v-sheet>
54
54
  </div>
55
- </v-sheet>
56
- </v-card>
55
+ </v-sheet>
56
+ </v-card>
57
57
  </template>
58
58
 
59
59
  <style scoped>
@@ -23,8 +23,7 @@ export function createAlert() {
23
23
  },
24
24
  takeAlert(location = "default") {
25
25
  const item = head(items.value.filter((i) => i.alertLocation === location));
26
- if (item)
27
- remove(items.value, (i) => i === item);
26
+ if (item) remove(items.value, (i) => i === item);
28
27
  return item;
29
28
  },
30
29
  hasAlert(location = "default") {
@@ -5,16 +5,13 @@ export function useApi() {
5
5
  function urlBuilder(url) {
6
6
  let returnUrl = "";
7
7
  if (Array.isArray(url)) {
8
- if (url[0].toLowerCase() == "agent")
9
- url[0] = config?.public.WS_AGENT;
8
+ if (url[0].toLowerCase() == "agent") url[0] = config?.public.WS_AGENT;
10
9
  returnUrl = url.join("/");
11
10
  } else {
12
11
  returnUrl = url;
13
12
  }
14
- if (returnUrl.startsWith("http://") || returnUrl.startsWith("https://"))
15
- return returnUrl;
16
- else
17
- return trimEnd(config?.public.WS_API, "/") + "/" + trimStart(returnUrl, "/");
13
+ if (returnUrl.startsWith("http://") || returnUrl.startsWith("https://")) return returnUrl;
14
+ else return trimEnd(config?.public.WS_API, "/") + "/" + trimStart(returnUrl, "/");
18
15
  }
19
16
  function optionBuilder(method, body, params, options) {
20
17
  let returnOption = {
@@ -28,10 +25,8 @@ export function useApi() {
28
25
  };
29
26
  if (options) {
30
27
  options = Object.assign(options, returnOption);
31
- if (options.headers)
32
- options.headers = Object.assign(options.headers, headers);
33
- else
34
- options.headers = headers;
28
+ if (options.headers) options.headers = Object.assign(options.headers, headers);
29
+ else options.headers = headers;
35
30
  }
36
31
  returnOption = Object.assign(returnOption, options);
37
32
  return returnOption;
@@ -42,10 +37,8 @@ export function useApi() {
42
37
  function getPromise(url, body, params, options) {
43
38
  return new Promise(async (resolve, reject) => {
44
39
  const { data, error } = await get(url, body, params, options);
45
- if (!error.value)
46
- resolve(data.value);
47
- else
48
- reject(error.value);
40
+ if (!error.value) resolve(data.value);
41
+ else reject(error.value);
49
42
  });
50
43
  }
51
44
  function post(url, body, params, options) {
@@ -54,10 +47,8 @@ export function useApi() {
54
47
  function postPromise(url, body, params, options) {
55
48
  return new Promise(async (resolve, reject) => {
56
49
  const { data, error } = await post(url, body, params, options);
57
- if (!error.value)
58
- resolve(data.value);
59
- else
60
- reject(error.value);
50
+ if (!error.value) resolve(data.value);
51
+ else reject(error.value);
61
52
  });
62
53
  }
63
54
  return { urlBuilder, get, getPromise, post, postPromise };
@@ -1,7 +1,6 @@
1
1
  export const validationRulesRegex = /^(require(?:\([^)]*\))?|requireIf(?:\([^)]*\))?|requireTrue(?:\([^)]*\))?|requireTrueIf(?:\([^)]*\))?|numeric(?:\([^)]*\))?|range(?:\([^)]*\))?|integer(?:\([^)]*\))?|unique(?:\([^)]*\))?|length(?:\([^)]*\))?|lengthGreater(?:\([^)]*\))?|lengthLess(?:\([^)]*\))?|telephone(?:\([^)]*\))?|email(?:\([^)]*\))?|regex(?:\([^)]*\))?)(,(require(?:\([^)]*\))?|requireIf(?:\([^)]*\))?|requireTrue(?:\([^)]*\))?|requireTrueIf(?:\([^)]*\))?|numeric(?:\([^)]*\))?|range(?:\([^)]*\))?|integer(?:\([^)]*\))?|unique(?:\([^)]*\))?|length(?:\([^)]*\))?|lengthGreater(?:\([^)]*\))?|lengthLess(?:\([^)]*\))?|telephone(?:\([^)]*\))?|email(?:\([^)]*\))?|regex(?:\([^)]*\))?))*$/;
2
2
  export function useDocumentTemplate(items) {
3
- if (!items)
4
- return "";
3
+ if (!items) return "";
5
4
  if (typeof items === "string") {
6
5
  try {
7
6
  items = JSON.parse(items);
@@ -36,10 +35,8 @@ function templateItemToString(item) {
36
35
  optionString = item.inputOptions.split(",").join(" ");
37
36
  }
38
37
  }
39
- if (item.inputType == "FormDateTime" && !item.inputAttributes?.includes("dense"))
40
- item.inputAttributes = (item.inputAttributes?.trim() + " dense").trim();
41
- if (item.validationRules)
42
- validationRules = buildValidationRules(item.validationRules);
38
+ if (item.inputType == "FormDateTime" && !item.inputAttributes?.includes("dense")) item.inputAttributes = (item.inputAttributes?.trim() + " dense").trim();
39
+ if (item.validationRules) validationRules = buildValidationRules(item.validationRules);
43
40
  let templateString = "";
44
41
  switch (item.inputType) {
45
42
  case "CustomCode":
@@ -60,10 +57,8 @@ function templateItemToString(item) {
60
57
  default:
61
58
  templateString = `<${item.inputType} v-model="data.${item.variableName}" label="${item.inputLabel || item.variableName}"${item.inputAttributes ? " " + item.inputAttributes : ""}${optionString ? " " + optionString.trim() : ""}${validationRules ? " " + validationRules.trim() : ""}></${item.inputType}>`;
62
59
  }
63
- if (!["Separator", "Header"].includes(item.inputType))
64
- templateString = `<v-col${item.width ? ' cols="' + item.width + '"' : ""}${item.columnAttributes ? " " + item.columnAttributes : ""}>${templateString}</v-col>`;
65
- if (["Header"].includes(item.inputType))
66
- templateString = `</v-row><v-row dense><v-col${item.columnAttributes ? " " + item.columnAttributes : ""}>${templateString}</v-col></v-row><v-row dense>`;
60
+ if (!["Separator", "Header"].includes(item.inputType)) templateString = `<v-col${item.width ? ' cols="' + item.width + '"' : ""}${item.columnAttributes ? " " + item.columnAttributes : ""}>${templateString}</v-col>`;
61
+ if (["Header"].includes(item.inputType)) templateString = `</v-row><v-row dense><v-col${item.columnAttributes ? " " + item.columnAttributes : ""}>${templateString}</v-col></v-row><v-row dense>`;
67
62
  return templateString;
68
63
  }
69
64
  function optionStringToChoiceObject(option) {
@@ -84,12 +79,9 @@ function optionStringToChoiceObject(option) {
84
79
  }
85
80
  function buildValidationRules(validationString) {
86
81
  validationString = validationString.trim();
87
- if (validationString.startsWith("["))
88
- validationString = validationString.substring(1);
89
- if (validationString.endsWith("]"))
90
- validationString = validationString.substring(0, validationString.length - 1);
91
- if (!validationRulesRegex.test(validationString))
92
- return "";
82
+ if (validationString.startsWith("[")) validationString = validationString.substring(1);
83
+ if (validationString.endsWith("]")) validationString = validationString.substring(0, validationString.length - 1);
84
+ if (!validationRulesRegex.test(validationString)) return "";
93
85
  validationString = validationString.split(",").map((rule) => {
94
86
  rule = rule.trim();
95
87
  if (!rule.startsWith("rules.")) {
@@ -10,8 +10,8 @@ declare type VariableOptions = {
10
10
  };
11
11
  export declare function useGraphQl(): {
12
12
  query: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions, cache?: boolean) => any;
13
- queryPromise: <T_1>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions, cache?: boolean) => Promise<T_1>;
14
- mutation: <T_2>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions) => any;
15
- mutationPromise: <T_3>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions) => Promise<T_3>;
13
+ queryPromise: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions, cache?: boolean) => Promise<T>;
14
+ mutation: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions) => any;
15
+ mutationPromise: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions) => Promise<T>;
16
16
  };
17
17
  export {};
@@ -4,8 +4,7 @@ import { classAttributes, isClassConstructor } from "../utils/object.mjs";
4
4
  import { gql, useAsyncQuery, useMutation } from "#imports";
5
5
  export function useGraphQl() {
6
6
  function query(operation, fields, variables, cache = false) {
7
- if (isClassConstructor(fields))
8
- fields = classAttributes(fields);
7
+ if (isClassConstructor(fields)) fields = classAttributes(fields);
9
8
  const builder = gqlQuery({ operation, fields, variables });
10
9
  const options = {
11
10
  query: gql(builder.query),
@@ -15,8 +14,7 @@ export function useGraphQl() {
15
14
  return useAsyncQuery(options);
16
15
  }
17
16
  function queryPromise(operation, fields, variables, cache = false) {
18
- if (isClassConstructor(fields))
19
- fields = classAttributes(fields);
17
+ if (isClassConstructor(fields)) fields = classAttributes(fields);
20
18
  const builder = gqlQuery({ operation, fields, variables });
21
19
  return new Promise((resolve, reject) => {
22
20
  const { onResult, onError } = useQuery(gql(builder.query), builder.variables, { fetchPolicy: cache ? "cache-first" : "no-cache" });
@@ -34,14 +32,12 @@ export function useGraphQl() {
34
32
  });
35
33
  }
36
34
  function mutation(operation, fields, variables) {
37
- if (isClassConstructor(fields))
38
- fields = classAttributes(fields);
35
+ if (isClassConstructor(fields)) fields = classAttributes(fields);
39
36
  const builder = gqlMutation({ operation, fields, variables });
40
37
  return useMutation(gql(builder.query), { variables: builder.variables });
41
38
  }
42
39
  function mutationPromise(operation, fields, variables) {
43
- if (isClassConstructor(fields))
44
- fields = classAttributes(fields);
40
+ if (isClassConstructor(fields)) fields = classAttributes(fields);
45
41
  const builder = gqlMutation({ operation, fields, variables });
46
42
  return new Promise(async (resolve, reject) => {
47
43
  const { mutate, error } = useMutation(gql(builder.query), { variables: builder.variables });
@@ -21,8 +21,7 @@ export function routeToMenuItem(route) {
21
21
  const menuItems = new Array();
22
22
  for (const children of route.children) {
23
23
  const childMenuItem = routeToMenuItem(children);
24
- if (childMenuItem)
25
- menuItems.push(childMenuItem);
24
+ if (childMenuItem) menuItems.push(childMenuItem);
26
25
  menuItem.menuItems = menuItems;
27
26
  }
28
27
  }
@@ -37,8 +36,7 @@ export function createMenu() {
37
36
  if (paths.length == 2) {
38
37
  if (route.path != "/login" && route.path != "/") {
39
38
  const menuItem = routeToMenuItem(route);
40
- if (menuItem)
41
- menuAll.value.push(menuItem);
39
+ if (menuItem) menuAll.value.push(menuItem);
42
40
  }
43
41
  }
44
42
  }
@@ -2,8 +2,7 @@ import { defineNuxtPlugin } from "nuxt/app";
2
2
  import { useAuthentication } from "#imports";
3
3
  export default defineNuxtPlugin(async (nuxtApp) => {
4
4
  function permission(permissionId) {
5
- if (!permissionId || useAuthentication()?.hasPermission(permissionId) === void 0)
6
- return true;
5
+ if (!permissionId || useAuthentication()?.hasPermission(permissionId) === void 0) return true;
7
6
  return useAuthentication()?.hasPermission(permissionId);
8
7
  }
9
8
  nuxtApp.vueApp.config.globalProperties.$permission = permission;
@@ -15,8 +14,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
15
14
  um();
16
15
  });
17
16
  }
18
- if (el.parentElement)
19
- el.parentElement.removeChild(el);
17
+ if (el.parentElement) el.parentElement.removeChild(el);
20
18
  }
21
19
  }
22
20
  });
@@ -3,3 +3,5 @@ declare module '@zxing/browser'
3
3
  declare module 'vue-signature-pad'
4
4
  declare module 'accounting'
5
5
  declare module 'pdf-vue3'
6
+ declare module "prettier"
7
+ declare module "prettier/plugins/html"
@@ -2,13 +2,10 @@ import { DateTime } from "luxon";
2
2
  export const Datetime = () => ({
3
3
  luxonDateTime: DateTime.invalid("Uninitialized"),
4
4
  fromString: function(dateTime, formatDate, locale = "EN") {
5
- if (!dateTime)
6
- return this.setDateTime(DateTime.invalid("No datetime string provided"), locale);
5
+ if (!dateTime) return this.setDateTime(DateTime.invalid("No datetime string provided"), locale);
7
6
  let inputDate = void 0;
8
- if (formatDate)
9
- inputDate = DateTime.fromFormat(dateTime, formatDate, { locale });
10
- if (!inputDate?.isValid)
11
- inputDate = DateTime.fromISO(dateTime, { locale });
7
+ if (formatDate) inputDate = DateTime.fromFormat(dateTime, formatDate, { locale });
8
+ if (!inputDate?.isValid) inputDate = DateTime.fromISO(dateTime, { locale });
12
9
  if (!inputDate?.isValid) {
13
10
  const formats = [
14
11
  "ddMMyyyy",
@@ -26,18 +23,15 @@ export const Datetime = () => ({
26
23
  ];
27
24
  for (let i = 0; i < formats.length; ++i) {
28
25
  inputDate = DateTime.fromFormat(dateTime, formats[i], { locale });
29
- if (inputDate.isValid)
30
- break;
26
+ if (inputDate.isValid) break;
31
27
  }
32
28
  }
33
29
  return this.setDateTime(inputDate, locale);
34
30
  },
35
31
  fromStringTime: function(time, formatTime, locale = "EN") {
36
- if (!time)
37
- return this.setDateTime(DateTime.invalid("No datetime string provided"), locale);
32
+ if (!time) return this.setDateTime(DateTime.invalid("No datetime string provided"), locale);
38
33
  let inputTime = void 0;
39
- if (formatTime)
40
- inputTime = DateTime.fromFormat(time, formatTime, { locale });
34
+ if (formatTime) inputTime = DateTime.fromFormat(time, formatTime, { locale });
41
35
  if (!inputTime?.isValid) {
42
36
  const formats = [
43
37
  "HHmm",
@@ -49,12 +43,10 @@ export const Datetime = () => ({
49
43
  ];
50
44
  for (let i = 0; i < formats.length; ++i) {
51
45
  inputTime = DateTime.fromFormat(time, formats[i], { locale });
52
- if (inputTime.isValid)
53
- break;
46
+ if (inputTime.isValid) break;
54
47
  }
55
48
  }
56
- if (!inputTime?.isValid)
57
- inputTime = DateTime.fromISO(time, { locale });
49
+ if (!inputTime?.isValid) inputTime = DateTime.fromISO(time, { locale });
58
50
  return this.setDateTime(inputTime, locale);
59
51
  },
60
52
  fromISO: function(dateTime, locale = "EN") {
@@ -67,45 +59,31 @@ export const Datetime = () => ({
67
59
  },
68
60
  setDateTime: function(inputDate, locale = "EN") {
69
61
  if (inputDate.isValid) {
70
- if (inputDate.year - DateTime.now().year > 300)
71
- inputDate = inputDate.set({ year: inputDate.year - 543 });
62
+ if (inputDate.year - DateTime.now().year > 300) inputDate = inputDate.set({ year: inputDate.year - 543 });
72
63
  }
73
64
  this.luxonDateTime = inputDate;
74
- if (locale == "TH")
75
- this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "buddhist" });
76
- else
77
- this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "gregory" });
65
+ if (locale == "TH") this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "buddhist" });
66
+ else this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "gregory" });
78
67
  return this;
79
68
  },
80
69
  toFormat: function(format, locale = "EN") {
81
- if (format == "tinyDate")
82
- return this.toTinyDate(locale);
83
- if (format == "monthShortDate")
84
- return this.toMonthShortDate(locale);
85
- if (format == "shortDate")
86
- return this.toShortDate(locale);
87
- if (format == "longDate")
88
- return this.toLongDate(locale);
89
- if (format == "tinyDateTime")
90
- return this.toTinyDateTime(locale);
91
- if (format == "shortDateTime")
92
- return this.toShortDateTime(locale);
93
- if (format == "longDateTime")
94
- return this.toLongDateTime(locale);
95
- if (locale == "TH")
96
- this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "buddhist" });
97
- else
98
- this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "gregory" });
70
+ if (format == "tinyDate") return this.toTinyDate(locale);
71
+ if (format == "monthShortDate") return this.toMonthShortDate(locale);
72
+ if (format == "shortDate") return this.toShortDate(locale);
73
+ if (format == "longDate") return this.toLongDate(locale);
74
+ if (format == "tinyDateTime") return this.toTinyDateTime(locale);
75
+ if (format == "shortDateTime") return this.toShortDateTime(locale);
76
+ if (format == "longDateTime") return this.toLongDateTime(locale);
77
+ if (locale == "TH") this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "buddhist" });
78
+ else this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "gregory" });
99
79
  return this.luxonDateTime.toFormat(format);
100
80
  },
101
81
  toISO: function() {
102
82
  return this.luxonDateTime.toISO();
103
83
  },
104
84
  toLocaleFormat: function(locale, format) {
105
- if (locale == "TH")
106
- this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "buddhist" });
107
- else
108
- this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "gregory" });
85
+ if (locale == "TH") this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "buddhist" });
86
+ else this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "gregory" });
109
87
  return this.luxonDateTime.setLocale(locale).toLocaleString(format);
110
88
  },
111
89
  toTinyDate: function(locale = "EN") {
@@ -11,8 +11,7 @@ export function classAttributes(cls) {
11
11
  export function onlyAttributes(keys, object) {
12
12
  const returnObject = cloneDeep(object);
13
13
  Object.keys(object).forEach((localKey) => {
14
- if (!keys.includes(localKey))
15
- delete returnObject[localKey];
14
+ if (!keys.includes(localKey)) delete returnObject[localKey];
16
15
  });
17
16
  return returnObject;
18
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",