@ramathibodi/nuxt-commons 0.1.56 → 0.1.57

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.
Files changed (30) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/components/document/TemplateBuilder.vue +133 -122
  3. package/dist/runtime/components/form/Pad.vue +39 -0
  4. package/dist/runtime/components/form/TableData.vue +180 -41
  5. package/dist/runtime/components/label/Object.vue +14 -0
  6. package/dist/runtime/components/master/Autocomplete.vue +25 -108
  7. package/dist/runtime/components/master/Combobox.vue +59 -83
  8. package/dist/runtime/components/model/Autocomplete.vue +23 -234
  9. package/dist/runtime/components/model/Combobox.vue +70 -0
  10. package/dist/runtime/composables/document/template.d.ts +4 -1
  11. package/dist/runtime/composables/document/template.js +22 -15
  12. package/dist/runtime/composables/document/templateFormHidden.d.ts +1 -1
  13. package/dist/runtime/composables/document/templateFormHidden.js +5 -2
  14. package/dist/runtime/composables/document/templateFormTable.d.ts +3 -2
  15. package/dist/runtime/composables/document/templateFormTable.js +36 -40
  16. package/dist/runtime/composables/document/templateFormTableData.d.ts +2 -0
  17. package/dist/runtime/composables/document/templateFormTableData.js +21 -0
  18. package/dist/runtime/composables/graphqlModel.d.ts +6 -6
  19. package/dist/runtime/composables/graphqlModelItem.d.ts +4 -4
  20. package/dist/runtime/composables/graphqlModelOperation.d.ts +6 -6
  21. package/dist/runtime/composables/lookupList.d.ts +44 -0
  22. package/dist/runtime/composables/lookupList.js +194 -0
  23. package/dist/runtime/composables/lookupListMaster.d.ts +28 -0
  24. package/dist/runtime/composables/lookupListMaster.js +61 -0
  25. package/dist/runtime/types/menu.d.ts +7 -4
  26. package/dist/runtime/utils/formatter.d.ts +1 -0
  27. package/dist/runtime/utils/formatter.js +19 -0
  28. package/dist/runtime/utils/object.d.ts +1 -0
  29. package/dist/runtime/utils/object.js +46 -1
  30. package/package.json +2 -1
@@ -0,0 +1,28 @@
1
+ export type Lang = 'TH' | 'EN';
2
+ export type MasterSortBy = 'itemCode' | 'itemValue';
3
+ export interface MasterLikeProps {
4
+ sortBy?: MasterSortBy;
5
+ showCode?: boolean;
6
+ groupKey: string;
7
+ itemCodes?: string[];
8
+ lang?: Lang;
9
+ fields?: Array<string | object>;
10
+ noDataText?: string;
11
+ filterText?: string;
12
+ waitForFilter?: boolean;
13
+ waitForFilterText?: string;
14
+ meilisearch?: boolean;
15
+ cache?: boolean | number;
16
+ }
17
+ export declare function useLookupListMaster(props: MasterLikeProps): {
18
+ computedModelName: import("vue").ComputedRef<string>;
19
+ computedModelBy: import("vue").ComputedRef<Record<string, any>>;
20
+ computedModelSelectedItemBy: import("vue").ComputedRef<{
21
+ groupKey: string;
22
+ }>;
23
+ computedFields: import("vue").ComputedRef<(string | object)[]>;
24
+ itemTitleField: import("vue").ComputedRef<"itemValue" | "itemValueAlternative">;
25
+ computedNoDataText: import("vue").ComputedRef<string | undefined>;
26
+ computedSortBy: import("vue").ComputedRef<string[]>;
27
+ formatItemTitle: (item: any) => string;
28
+ };
@@ -0,0 +1,61 @@
1
+ import { computed } from "vue";
2
+ import { union } from "lodash-es";
3
+ export function useLookupListMaster(props) {
4
+ const computedModelName = computed(() => {
5
+ let operation = "masterItemByGroupKey";
6
+ if (props.filterText) operation = "masterItemByGroupKeyAndFilterText";
7
+ if (props.itemCodes && props.itemCodes.length > 0) operation = "masterItemByGroupKeyAndItemCodeIn";
8
+ if (props.meilisearch) operation = "masterItemByGroupKeyAndFilterTextAndKeyword";
9
+ if (props.waitForFilter && !props.filterText) operation = "";
10
+ return operation;
11
+ });
12
+ const computedModelBy = computed(() => {
13
+ const modelBy = { groupKey: props.groupKey };
14
+ if (props.filterText) modelBy["filterText"] = props.filterText;
15
+ if (props.itemCodes && props.itemCodes.length > 0) modelBy["itemCodes"] = props.itemCodes;
16
+ return modelBy;
17
+ });
18
+ const computedModelSelectedItemBy = computed(() => ({ groupKey: props.groupKey }));
19
+ const computedFields = computed(() => {
20
+ const extra = [];
21
+ if (props.filterText) extra.push("filterText");
22
+ if (props.meilisearch) extra.push("_formatted");
23
+ return union(["itemCode", "itemValue", "itemValueAlternative"], extra, props.fields || []);
24
+ });
25
+ const itemTitleField = computed(() => props.lang === "TH" ? "itemValue" : "itemValueAlternative");
26
+ const formatItemTitle = (item) => {
27
+ if (props.meilisearch) {
28
+ const raw = item.raw?._formatted ?? {};
29
+ const code = raw?.itemCode;
30
+ const title = raw?.[itemTitleField.value] ?? raw?.itemValue ?? raw?.itemCode;
31
+ return (props.showCode ? (code ?? "") + "-" : "") + (title ?? "");
32
+ } else {
33
+ const code = item.raw?.itemCode;
34
+ const title = item.title ?? item.raw?.itemValue ?? item.raw?.itemCode;
35
+ return (props.showCode ? (code ?? "") + "-" : "") + (title ?? "");
36
+ }
37
+ };
38
+ const computedNoDataText = computed(() => {
39
+ if (props.waitForFilter && !props.filterText) return props.waitForFilterText;
40
+ return props.noDataText;
41
+ });
42
+ const computedSortBy = computed(() => {
43
+ if ((props.sortBy ?? "itemValue") === "itemValue") {
44
+ if (props.showCode) return ["itemCode"];
45
+ return [itemTitleField.value, "itemValue", "itemCode"];
46
+ }
47
+ return [props.sortBy ?? "itemValue"];
48
+ });
49
+ return {
50
+ // for <model-*> props
51
+ computedModelName,
52
+ computedModelBy,
53
+ computedModelSelectedItemBy,
54
+ computedFields,
55
+ itemTitleField,
56
+ computedNoDataText,
57
+ computedSortBy,
58
+ // helpers
59
+ formatItemTitle
60
+ };
61
+ }
@@ -9,8 +9,8 @@ declare global {
9
9
  title: string
10
10
  icon: string
11
11
  role?: string
12
- image? : string
13
- active? : boolean
12
+ image?: string
13
+ active?: boolean
14
14
  }
15
15
 
16
16
  interface MenuItem {
@@ -21,8 +21,11 @@ declare global {
21
21
  menuItems: Array<MenuItem>
22
22
  active: boolean
23
23
  name: string
24
- image? : string
24
+ image?: string
25
25
  }
26
26
  }
27
27
 
28
- export { MenuMeta, MenuItem }
28
+ export type MenuMeta = globalThis.MenuMeta
29
+ export type MenuItem = globalThis.MenuItem
30
+
31
+ export {}
@@ -0,0 +1 @@
1
+ export declare const joinObject: (obj: any, attribute?: string, separator?: string) => string;
@@ -0,0 +1,19 @@
1
+ import { get } from "lodash-es";
2
+ export const joinObject = (obj, attribute, separator = ",") => {
3
+ if (!Array.isArray(obj)) {
4
+ return obj != null ? obj.toString() : "";
5
+ }
6
+ return obj.map((item) => {
7
+ if (item && typeof item === "object") {
8
+ if (attribute) {
9
+ const val = get(item, attribute);
10
+ if (val !== void 0) return val;
11
+ }
12
+ if (item.label !== void 0) return item.label;
13
+ if (item.value !== void 0) return item.value;
14
+ return item.toString();
15
+ } else {
16
+ return item != null ? item.toString() : "";
17
+ }
18
+ }).join(separator);
19
+ };
@@ -7,3 +7,4 @@ export declare function classAttributes<T extends Record<string, any>>(cls: Clas
7
7
  export declare function onlyAttributes(keys: string[], object: Record<string, any>): Record<string, any>;
8
8
  export declare function renameAttributes(object: Record<string, any>, mapper: Record<string, string>): Record<string, any>;
9
9
  export declare function stableStringify(obj: any): string;
10
+ export declare function safeParseJSONDeep<T = any>(input: T, childKeys?: string[], keysToParse?: string[]): T;
@@ -1,4 +1,4 @@
1
- import { cloneDeep } from "lodash-es";
1
+ import { cloneDeep, isArray, isString, isPlainObject, forOwn } from "lodash-es";
2
2
  export function isClassConstructor(arg) {
3
3
  return typeof arg === "function" && /^class\s/.test(arg.toString());
4
4
  }
@@ -50,3 +50,48 @@ export function stableStringify(obj) {
50
50
  };
51
51
  return inner(obj);
52
52
  }
53
+ export function safeParseJSONDeep(input, childKeys = ["children"], keysToParse) {
54
+ const shouldParseKey = !keysToParse || keysToParse.length === 0 ? () => true : (k) => keysToParse.includes(k);
55
+ const looksLikeJSON = (s) => {
56
+ const t = s.trim();
57
+ if (t.length === 0) return false;
58
+ const c = t[0];
59
+ return c === "{" || c === "[" || c === '"' || c === "-" || c >= "0" && c <= "9" || t.startsWith("true") || t.startsWith("false") || t.startsWith("null");
60
+ };
61
+ const tryParse = (s) => {
62
+ try {
63
+ return JSON.parse(s);
64
+ } catch {
65
+ return s;
66
+ }
67
+ };
68
+ const walk = (node) => {
69
+ if (isString(node)) {
70
+ return looksLikeJSON(node) ? tryParse(node) : node;
71
+ }
72
+ if (isArray(node)) {
73
+ return node.map(walk);
74
+ }
75
+ if (isPlainObject(node)) {
76
+ const out = {};
77
+ forOwn(node, (val, key) => {
78
+ if (isString(val) && shouldParseKey(key)) {
79
+ const parsed = looksLikeJSON(val) ? tryParse(val) : val;
80
+ out[key] = walk(parsed);
81
+ } else if (isArray(val) || isPlainObject(val)) {
82
+ out[key] = walk(val);
83
+ } else {
84
+ out[key] = val;
85
+ }
86
+ });
87
+ childKeys.forEach((ck) => {
88
+ if (isArray(out[ck])) {
89
+ out[ck] = out[ck].map(walk);
90
+ }
91
+ });
92
+ return out;
93
+ }
94
+ return node;
95
+ };
96
+ return walk(cloneDeep(input));
97
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "0.1.56",
3
+ "version": "0.1.57",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",
@@ -92,6 +92,7 @@
92
92
  "uid": "^2.0.2",
93
93
  "vue": "^3.5.13",
94
94
  "vue-codemirror": "^6.1.1",
95
+ "vue-json-pretty": "^2.5.0",
95
96
  "vue-signature-pad": "^3.0.2",
96
97
  "vuetify": "^3.8.0",
97
98
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"