@ramathibodi/nuxt-commons 0.1.13 → 0.1.15

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 (59) 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 -199
  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 +266 -266
  26. package/dist/runtime/components/form/Time.vue +158 -158
  27. package/dist/runtime/components/form/images/Capture.vue +231 -0
  28. package/dist/runtime/components/form/images/Edit.vue +117 -143
  29. package/dist/runtime/components/label/Date.vue +29 -29
  30. package/dist/runtime/components/label/Field.vue +42 -29
  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.d.ts +4 -1
  43. package/dist/runtime/composables/graphqlModel.mjs +5 -5
  44. package/dist/runtime/composables/graphqlModelOperation.mjs +7 -4
  45. package/dist/runtime/labs/Calendar.vue +99 -99
  46. package/dist/runtime/labs/form/EditMobile.vue +152 -152
  47. package/dist/runtime/labs/form/TextFieldMask.vue +43 -43
  48. package/dist/runtime/types/alert.d.ts +11 -11
  49. package/dist/runtime/types/formDialog.d.ts +4 -4
  50. package/dist/runtime/types/graphqlOperation.d.ts +23 -23
  51. package/dist/runtime/types/menu.d.ts +25 -25
  52. package/dist/runtime/types/modules.d.ts +7 -7
  53. package/package.json +120 -118
  54. package/scripts/postInstall.cjs +70 -70
  55. package/templates/.codegen/codegen.ts +32 -32
  56. package/templates/.codegen/plugin-schema-object.js +154 -154
  57. package/dist/runtime/components/Camera.vue +0 -129
  58. package/dist/runtime/components/form/images/CameraCrop.vue +0 -58
  59. package/dist/runtime/components/form/images/Preview.vue +0 -48
@@ -1,266 +1,266 @@
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 < 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>