@ramathibodi/nuxt-commons 0.1.14 → 0.1.16

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 (54) hide show
  1. package/README.md +96 -96
  2. package/dist/module.json +1 -1
  3. package/dist/runtime/components/Alert.vue +53 -53
  4. package/dist/runtime/components/BarcodeReader.vue +98 -98
  5. package/dist/runtime/components/ExportCSV.vue +55 -55
  6. package/dist/runtime/components/FileBtn.vue +62 -62
  7. package/dist/runtime/components/ImportCSV.vue +64 -64
  8. package/dist/runtime/components/SplitterPanel.vue +59 -59
  9. package/dist/runtime/components/TabsGroup.vue +32 -32
  10. package/dist/runtime/components/TextBarcode.vue +52 -52
  11. package/dist/runtime/components/dialog/Confirm.vue +100 -100
  12. package/dist/runtime/components/dialog/Index.vue +72 -72
  13. package/dist/runtime/components/dialog/Loading.vue +39 -39
  14. package/dist/runtime/components/document/TemplateBuilder.vue +203 -216
  15. package/dist/runtime/components/form/Birthdate.vue +216 -216
  16. package/dist/runtime/components/form/CodeEditor.vue +37 -37
  17. package/dist/runtime/components/form/Date.vue +163 -163
  18. package/dist/runtime/components/form/DateTime.vue +107 -107
  19. package/dist/runtime/components/form/Dialog.vue +138 -138
  20. package/dist/runtime/components/form/File.vue +187 -187
  21. package/dist/runtime/components/form/Hidden.vue +32 -32
  22. package/dist/runtime/components/form/Login.vue +131 -131
  23. package/dist/runtime/components/form/Pad.vue +217 -217
  24. package/dist/runtime/components/form/SignPad.vue +186 -186
  25. package/dist/runtime/components/form/Table.vue +294 -266
  26. package/dist/runtime/components/form/Time.vue +158 -158
  27. package/dist/runtime/components/form/images/Capture.vue +230 -230
  28. package/dist/runtime/components/form/images/Edit.vue +114 -114
  29. package/dist/runtime/components/label/Date.vue +29 -29
  30. package/dist/runtime/components/label/Field.vue +42 -42
  31. package/dist/runtime/components/label/FormatMoney.vue +29 -29
  32. package/dist/runtime/components/label/Mask.vue +38 -38
  33. package/dist/runtime/components/master/Autocomplete.vue +159 -159
  34. package/dist/runtime/components/master/Combobox.vue +84 -84
  35. package/dist/runtime/components/master/RadioGroup.vue +78 -78
  36. package/dist/runtime/components/master/Select.vue +82 -82
  37. package/dist/runtime/components/model/Pad.vue +122 -122
  38. package/dist/runtime/components/model/Table.vue +242 -240
  39. package/dist/runtime/components/model/iterator.vue +312 -312
  40. package/dist/runtime/components/pdf/Print.vue +63 -63
  41. package/dist/runtime/components/pdf/View.vue +104 -104
  42. package/dist/runtime/composables/graphqlModel.mjs +1 -1
  43. package/dist/runtime/labs/Calendar.vue +99 -99
  44. package/dist/runtime/labs/form/EditMobile.vue +152 -152
  45. package/dist/runtime/labs/form/TextFieldMask.vue +43 -43
  46. package/dist/runtime/types/alert.d.ts +11 -11
  47. package/dist/runtime/types/formDialog.d.ts +4 -4
  48. package/dist/runtime/types/graphqlOperation.d.ts +23 -23
  49. package/dist/runtime/types/menu.d.ts +25 -25
  50. package/dist/runtime/types/modules.d.ts +7 -7
  51. package/package.json +120 -119
  52. package/scripts/postInstall.cjs +70 -70
  53. package/templates/.codegen/codegen.ts +32 -32
  54. package/templates/.codegen/plugin-schema-object.js +161 -154
@@ -1,266 +1,294 @@
1
- <script lang="ts" setup>
2
- import {VDataTable} from 'vuetify/components/VDataTable'
3
- import {computed, defineOptions, nextTick, ref, useAttrs, watch} from 'vue'
4
- import {omit} from 'lodash-es'
5
- import type {FormDialogCallback} from '../../types/formDialog'
6
-
7
- defineOptions({
8
- inheritAttrs: false,
9
- })
10
-
11
- interface Props extends /* @vue-ignore */ InstanceType<typeof VDataTable['$props']> {
12
- title: string
13
- noDataText?: string
14
- modelValue?: Record<string, any>[]
15
- modelKey?: string
16
- dialogFullscreen?: boolean
17
- initialData?: Record<string, any>
18
- toolbarColor?: string
19
- importable?: boolean
20
- exportable?: boolean
21
- }
22
-
23
- const props = withDefaults(defineProps<Props>(), {
24
- noDataText: 'ไม่พบข้อมูล',
25
- dialogFullscreen: false,
26
- modelKey: 'id',
27
- toolbarColor: 'primary',
28
- importable: true,
29
- exportable: true,
30
- })
31
-
32
- const emit = defineEmits(['update:modelValue'])
33
-
34
- const attrs = useAttrs()
35
- const plainAttrs = computed(() => {
36
- return omit(attrs, ['modelValue', 'onUpdate:modelValue'])
37
- })
38
-
39
- const items = ref<Record<string, any>[]>([])
40
- const search = ref<string>()
41
- const currentItem = ref<Record<string, any> | undefined>(undefined)
42
-
43
- const isDialogOpen = ref<boolean>(false)
44
-
45
- watch(() => props.modelValue, (newValue) => {
46
- if (!Array.isArray(newValue) || !newValue.every(item => typeof item === 'object')) {
47
- items.value = []
48
- }
49
- else {
50
- let maxKey = 0
51
-
52
- newValue.forEach((item) => {
53
- if (!item.hasOwnProperty(props.modelKey)) {
54
- maxKey = Math.max(maxKey, ...newValue.map(i => i[props.modelKey] || 0))
55
- item[props.modelKey] = maxKey + 1
56
- }
57
- })
58
-
59
- items.value = newValue
60
- }
61
- }, { immediate: true })
62
-
63
- watch(items, (newValue) => {
64
- emit('update:modelValue', newValue)
65
- }, { deep: true })
66
-
67
- function createItem(item: Record<string, any>, callback?: FormDialogCallback) {
68
- if (items.value.length > 0) item[props.modelKey] = Math.max(...items.value.map(i => i[props.modelKey] || 0)) + 1
69
- else item[props.modelKey] = 1
70
-
71
- items.value.push(item)
72
-
73
- if (callback) callback.done()
74
- }
75
-
76
- function importItems(importItems: Record<string, any>[], callback?: FormDialogCallback) {
77
- importItems.forEach((item) => {
78
- createItem(item)
79
- })
80
- if (callback) callback.done()
81
- }
82
-
83
- function updateItem(newItem: Record<string, any>, callback?: FormDialogCallback) {
84
- const index = items.value.findIndex(item => item[props.modelKey] === newItem[props.modelKey])
85
-
86
- if (index !== -1) {
87
- items.value[index] = newItem
88
- }
89
-
90
- if (callback) callback.done()
91
- }
92
-
93
- function moveUpItem(currentItem: Record<string, any>, callback?: FormDialogCallback) {
94
- const index = items.value.findIndex(item => item[props.modelKey] === currentItem[props.modelKey])
95
-
96
- if (index > 0) {
97
- const temp = items.value[index - 1]
98
- items.value[index - 1] = items.value[index]
99
- items.value[index] = temp
100
- }
101
-
102
- if (callback) callback.done()
103
- }
104
-
105
- function moveDownItem(currentItem: Record<string, any>, callback?: FormDialogCallback) {
106
- const index = items.value.findIndex(item => item[props.modelKey] === currentItem[props.modelKey])
107
-
108
- if (index < items.value.length - 1) {
109
- const temp = items.value[index + 1]
110
- items.value[index + 1] = items.value[index]
111
- items.value[index] = temp
112
- }
113
-
114
- if (callback) callback.done()
115
- }
116
-
117
- function deleteItem(deleteItem: Record<string, any>, callback?: FormDialogCallback) {
118
- const index = items.value.findIndex(item => item[props.modelKey] === deleteItem[props.modelKey])
119
-
120
- if (index !== -1) {
121
- items.value.splice(index, 1)
122
- }
123
-
124
- if (callback) callback.done()
125
- }
126
-
127
- function openDialog(item?: object) {
128
- currentItem.value = item
129
- nextTick(() => {
130
- isDialogOpen.value = true
131
- })
132
- }
133
-
134
- const operation = ref({ openDialog, createItem, updateItem, deleteItem, moveUpItem, moveDownItem })
135
- </script>
136
-
137
- <template>
138
- <v-card>
139
- <VToolbar :color="toolbarColor">
140
- <v-row
141
- justify="end"
142
- class="ma-1"
143
- dense
144
- no-gutters
145
- align="center"
146
- >
147
- <v-col cols="7">
148
- <VToolbarTitle class="pl-3">
149
- <slot name="title">
150
- {{ title }}
151
- </slot>
152
- </VToolbarTitle>
153
- </v-col>
154
- <v-col cols="5">
155
- <slot name="search">
156
- <VTextField
157
- v-model="search"
158
- class="justify-end w-100"
159
- density="compact"
160
- hide-details
161
- placeholder="ค้นหา"
162
- clearable
163
- variant="solo"
164
- />
165
- </slot>
166
- </v-col>
167
- </v-row>
168
-
169
- <VToolbarItems>
170
- <slot name="toolbarItems" />
171
- <ImportCSV
172
- v-if="props.importable"
173
- icon="mdi mdi-file-upload"
174
- variant="flat"
175
- @import="importItems"
176
- />
177
- <ExportCSV
178
- v-if="props.exportable && items.length"
179
- icon="mdi mdi-file-download"
180
- variant="flat"
181
- :file-name="title"
182
- :model-value="items"
183
- />
184
- <VBtn
185
- :color="toolbarColor"
186
- prepend-icon="mdi mdi-plus"
187
- variant="flat"
188
- @click="openDialog()"
189
- >
190
- add
191
- </VBtn>
192
- </VToolbarItems>
193
- </VToolbar>
194
- <v-data-table
195
- v-bind="plainAttrs"
196
- color="primary"
197
- :items="items"
198
- :search="search"
199
- >
200
- <!-- @ts-ignore -->
201
- <template
202
- v-for="(_, name, index) in ($slots as {})"
203
- :key="index"
204
- #[name]="slotData"
205
- >
206
- <slot
207
- :name="name"
208
- v-bind="((slotData || {}) as object)"
209
- :operation="operation"
210
- />
211
- </template>
212
- <template
213
- v-if="!$slots['item.operation']"
214
- #item.operation="props"
215
- >
216
- <v-btn
217
- :disabled="props.index==0"
218
- variant="flat"
219
- density="compact"
220
- icon="mdi mdi-arrow-up-thick"
221
- @click="moveUpItem(props.item)"
222
- />
223
- <v-btn
224
- :disabled="props.index==items.length-1"
225
- variant="flat"
226
- density="compact"
227
- icon="mdi mdi-arrow-down-thick"
228
- @click="moveDownItem(props.item)"
229
- />
230
- </template>
231
- <template
232
- v-if="!$slots['item.action']"
233
- #item.action="{ item }"
234
- >
235
- <v-btn
236
- variant="flat"
237
- density="compact"
238
- icon="mdi mdi-note-edit"
239
- @click="openDialog(item)"
240
- />
241
- <v-btn
242
- variant="flat"
243
- density="compact"
244
- icon="mdi mdi-delete"
245
- @click="deleteItem(item)"
246
- />
247
- </template>
248
- </v-data-table>
249
- <FormDialog
250
- v-model="isDialogOpen"
251
- :title="title"
252
- :fullscreen="dialogFullscreen"
253
- :initial-data="initialData"
254
- :form-data="currentItem"
255
- @create="createItem"
256
- @update="updateItem"
257
- >
258
- <template #default="slotData">
259
- <slot
260
- name="form"
261
- v-bind="slotData"
262
- />
263
- </template>
264
- </FormDialog>
265
- </v-card>
266
- </template>
1
+ <script lang="ts" setup>
2
+ import {VDataTable} from 'vuetify/components/VDataTable'
3
+ import {computed, defineOptions, nextTick, ref, useAttrs, watch} from 'vue'
4
+ import {omit} from 'lodash-es'
5
+ import type {FormDialogCallback} from '../../types/formDialog'
6
+
7
+ defineOptions({
8
+ inheritAttrs: false,
9
+ })
10
+
11
+ interface Props extends /* @vue-ignore */ InstanceType<typeof VDataTable['$props']> {
12
+ title: string
13
+ noDataText?: string
14
+ modelValue?: Record<string, any>[]
15
+ modelKey?: string
16
+ dialogFullscreen?: boolean
17
+ initialData?: Record<string, any>
18
+ toolbarColor?: string
19
+ importable?: boolean
20
+ exportable?: boolean
21
+ }
22
+
23
+ const props = withDefaults(defineProps<Props>(), {
24
+ noDataText: 'ไม่พบข้อมูล',
25
+ dialogFullscreen: false,
26
+ modelKey: 'id',
27
+ toolbarColor: 'primary',
28
+ importable: true,
29
+ exportable: true,
30
+ })
31
+
32
+ const emit = defineEmits(['update:modelValue'])
33
+
34
+ const attrs = useAttrs()
35
+ const plainAttrs = computed(() => {
36
+ return omit(attrs, ['modelValue', 'onUpdate:modelValue'])
37
+ })
38
+
39
+ const items = ref<Record<string, any>[]>([])
40
+ const search = ref<string>()
41
+ const currentItem = ref<Record<string, any> | undefined>(undefined)
42
+
43
+ const isDialogOpen = ref<boolean>(false)
44
+
45
+ watch(() => props.modelValue, (newValue) => {
46
+ if (!Array.isArray(newValue) || !newValue.every(item => typeof item === 'object')) {
47
+ items.value = []
48
+ }
49
+ else {
50
+ let maxKey = 0
51
+
52
+ newValue.forEach((item) => {
53
+ if (!item.hasOwnProperty(props.modelKey)) {
54
+ maxKey = Math.max(maxKey, ...newValue.map(i => i[props.modelKey] || 0))
55
+ item[props.modelKey] = maxKey + 1
56
+ }
57
+ })
58
+
59
+ items.value = newValue
60
+ }
61
+ }, { immediate: true })
62
+
63
+ watch(items, (newValue) => {
64
+ emit('update:modelValue', newValue)
65
+ }, { deep: true })
66
+
67
+ function createItem(item: Record<string, any>, callback?: FormDialogCallback) {
68
+ if (items.value.length > 0) item[props.modelKey] = Math.max(...items.value.map(i => i[props.modelKey] || 0)) + 1
69
+ else item[props.modelKey] = 1
70
+
71
+ items.value.push(item)
72
+
73
+ if (callback) callback.done()
74
+ }
75
+
76
+ function importItems(importItems: Record<string, any>[], callback?: FormDialogCallback) {
77
+ importItems.forEach((item) => {
78
+ createItem(item)
79
+ })
80
+ if (callback) callback.done()
81
+ }
82
+
83
+ function updateItem(newItem: Record<string, any>, callback?: FormDialogCallback) {
84
+ const index = items.value.findIndex(item => item[props.modelKey] === newItem[props.modelKey])
85
+
86
+ if (index !== -1) {
87
+ items.value[index] = newItem
88
+ }
89
+
90
+ if (callback) callback.done()
91
+ }
92
+
93
+ function moveUpItem(currentItem: Record<string, any>, callback?: FormDialogCallback) {
94
+ const index = items.value.findIndex(item => item[props.modelKey] === currentItem[props.modelKey])
95
+
96
+ if (index > 0) {
97
+ const temp = items.value[index - 1]
98
+ items.value[index - 1] = items.value[index]
99
+ items.value[index] = temp
100
+ }
101
+
102
+ if (callback) callback.done()
103
+ }
104
+
105
+ function moveDownItem(currentItem: Record<string, any>, callback?: FormDialogCallback) {
106
+ const index = items.value.findIndex(item => item[props.modelKey] === currentItem[props.modelKey])
107
+
108
+ if (index >= 0 && index < items.value.length - 1) {
109
+ const temp = items.value[index + 1]
110
+ items.value[index + 1] = items.value[index]
111
+ items.value[index] = temp
112
+ }
113
+
114
+ if (callback) callback.done()
115
+ }
116
+
117
+ function moveToItem(currentItem: Record<string, any>, callback?: FormDialogCallback) {
118
+ const index = items.value.findIndex(item => item[props.modelKey] === currentItem[props.modelKey]);
119
+
120
+ if (index !== -1) {
121
+ const newPosition = prompt("Enter the new position (0-based index):");
122
+ const parsedPosition = parseInt(<string>newPosition, 10);
123
+
124
+ if (isNaN(parsedPosition) || parsedPosition < 0 || parsedPosition >= items.value.length) {
125
+ alert("Invalid position entered. Please enter a number between 0 and " + (items.value.length - 1));
126
+ return
127
+ }
128
+
129
+ const [temp] = items.value.splice(index, 1);
130
+
131
+ items.value.splice(parsedPosition, 0, temp);
132
+ }
133
+
134
+ if (callback) callback.done();
135
+ }
136
+
137
+ function deleteItem(deleteItem: Record<string, any>, callback?: FormDialogCallback) {
138
+ const index = items.value.findIndex(item => item[props.modelKey] === deleteItem[props.modelKey])
139
+
140
+ if (index !== -1) {
141
+ items.value.splice(index, 1)
142
+ }
143
+
144
+ if (callback) callback.done()
145
+ }
146
+
147
+ function openDialog(item?: object) {
148
+ currentItem.value = item
149
+ nextTick(() => {
150
+ isDialogOpen.value = true
151
+ })
152
+ }
153
+
154
+ const operation = ref({ openDialog, createItem, updateItem, deleteItem, moveUpItem, moveDownItem,moveToItem })
155
+ </script>
156
+
157
+ <template>
158
+ <v-card>
159
+ <VToolbar :color="toolbarColor">
160
+ <v-row
161
+ justify="end"
162
+ class="ma-1"
163
+ dense
164
+ no-gutters
165
+ align="center"
166
+ >
167
+ <v-col cols="7">
168
+ <VToolbarTitle class="pl-3">
169
+ <slot name="title">
170
+ {{ title }}
171
+ </slot>
172
+ </VToolbarTitle>
173
+ </v-col>
174
+ <v-col cols="5">
175
+ <slot name="search">
176
+ <VTextField
177
+ v-model="search"
178
+ class="justify-end w-100"
179
+ density="compact"
180
+ hide-details
181
+ placeholder="ค้นหา"
182
+ clearable
183
+ variant="solo"
184
+ />
185
+ </slot>
186
+ </v-col>
187
+ </v-row>
188
+
189
+ <VToolbarItems>
190
+ <slot name="toolbarItems" />
191
+ <ImportCSV
192
+ v-if="props.importable"
193
+ icon="mdi mdi-file-upload"
194
+ variant="flat"
195
+ @import="importItems"
196
+ :color="toolbarColor"
197
+ />
198
+ <ExportCSV
199
+ v-if="props.exportable && items.length"
200
+ icon="mdi mdi-file-download"
201
+ variant="flat"
202
+ :file-name="title"
203
+ :model-value="items"
204
+ :color="toolbarColor"
205
+ />
206
+ <VBtn
207
+ :color="toolbarColor"
208
+ prepend-icon="mdi mdi-plus"
209
+ variant="flat"
210
+ @click="openDialog()"
211
+ >
212
+ add
213
+ </VBtn>
214
+ </VToolbarItems>
215
+ </VToolbar>
216
+ <v-data-table
217
+ v-bind="plainAttrs"
218
+ color="primary"
219
+ :items="items"
220
+ :search="search"
221
+ >
222
+ <!-- @ts-ignore -->
223
+ <template
224
+ v-for="(_, name, index) in ($slots as {})"
225
+ :key="index"
226
+ #[name]="slotData"
227
+ >
228
+ <slot
229
+ :name="name"
230
+ v-bind="((slotData || {}) as object)"
231
+ :operation="operation"
232
+ />
233
+ </template>
234
+ <template
235
+ v-if="!$slots['item.operation']"
236
+ #item.operation="props"
237
+ >
238
+ <v-btn
239
+ :disabled="props.index==0"
240
+ variant="flat"
241
+ density="compact"
242
+ icon="mdi mdi-arrow-up-thick"
243
+ @click="moveUpItem(props.item)"
244
+ />
245
+ <v-btn
246
+ variant="flat"
247
+ density="compact"
248
+ icon="fa fa-arrow-right-to-bracket"
249
+ @click="moveToItem(props.item)"
250
+ />
251
+ <v-btn
252
+ :disabled="props.index==items.length-1"
253
+ variant="flat"
254
+ density="compact"
255
+ icon="mdi mdi-arrow-down-thick"
256
+ @click="moveDownItem(props.item)"
257
+ />
258
+ </template>
259
+ <template
260
+ v-if="!$slots['item.action']"
261
+ #item.action="{ item }"
262
+ >
263
+ <v-btn
264
+ variant="flat"
265
+ density="compact"
266
+ icon="mdi mdi-note-edit"
267
+ @click="openDialog(item)"
268
+ />
269
+ <v-btn
270
+ variant="flat"
271
+ density="compact"
272
+ icon="mdi mdi-delete"
273
+ @click="deleteItem(item)"
274
+ />
275
+ </template>
276
+ </v-data-table>
277
+ <FormDialog
278
+ v-model="isDialogOpen"
279
+ :title="title"
280
+ :fullscreen="dialogFullscreen"
281
+ :initial-data="initialData"
282
+ :form-data="currentItem"
283
+ @create="createItem"
284
+ @update="updateItem"
285
+ >
286
+ <template #default="slotData">
287
+ <slot
288
+ name="form"
289
+ v-bind="slotData"
290
+ />
291
+ </template>
292
+ </FormDialog>
293
+ </v-card>
294
+ </template>