@ramathibodi/nuxt-commons 0.1.6 → 0.1.7

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.6"
7
+ "version": "0.1.7"
8
8
  }
@@ -184,10 +184,9 @@ const ruleOptions = (inputType: string) => (value: any) => {
184
184
  v-if="data.inputType=='CustomCode'"
185
185
  cols="12"
186
186
  >
187
- <v-textarea
187
+ <FormCodeEditor
188
188
  v-model="data.inputCustomCode"
189
189
  label="Custom Code"
190
- auto-grow
191
190
  :rules="[rules.require()]"
192
191
  />
193
192
  </v-col>
@@ -210,7 +209,7 @@ const ruleOptions = (inputType: string) => (value: any) => {
210
209
  </template>
211
210
  </template>
212
211
  </FormTable>
213
- <v-textarea
212
+ <FormCodeEditor
214
213
  v-else
215
214
  v-model="templateAdvanceCode"
216
215
  />
@@ -0,0 +1,37 @@
1
+ <script setup lang="ts">
2
+ import { Codemirror } from 'vue-codemirror'
3
+ import { oneDark } from '@codemirror/theme-one-dark'
4
+ import { javascript } from '@codemirror/lang-javascript'
5
+ import { html } from '@codemirror/lang-html'
6
+ import { vue } from '@codemirror/lang-vue'
7
+
8
+ interface Props {
9
+ height?: string | number
10
+ minHeight?: string | number
11
+ lang?: 'html' | 'javascript' | 'vue'
12
+ }
13
+
14
+ const props = withDefaults(defineProps<Props>(), {
15
+ height: '100%',
16
+ minHeight: '20em',
17
+ lang: 'vue',
18
+ })
19
+
20
+ const extensions = [oneDark]
21
+ if (props.lang == 'vue') {
22
+ extensions.push(vue({ base: html({ autoCloseTags: true, matchClosingTags: true, selfClosingTags: true }) }))
23
+ }
24
+ else {
25
+ extensions.push(javascript({ typescript: true }))
26
+ }
27
+
28
+ const model = defineModel<string>()
29
+ </script>
30
+
31
+ <template>
32
+ <codemirror
33
+ v-model="model"
34
+ :extensions="extensions"
35
+ :style="{ height: height, minHeight: minHeight }"
36
+ />
37
+ </template>
@@ -32,7 +32,7 @@ const emit = defineEmits(['create', 'update'])
32
32
  function save() {
33
33
  if (formPadRef.value.isValid) {
34
34
  isSaving.value = true
35
- emit((isCreating.value) ? 'create' : 'update', formData.value, callback)
35
+ emit((isCreating.value) ? 'create' : 'update', cloneDeep(formData.value) , callback)
36
36
  }
37
37
  }
38
38
 
@@ -62,17 +62,19 @@ const createOriginalValue = computed(() => {
62
62
  return Object.assign({}, props.initialData)
63
63
  })
64
64
 
65
- watchEffect(() => {
65
+ const loadFormData = () => {
66
66
  if (props.formData) {
67
67
  formData.value = cloneDeep(props.formData)
68
- }
69
- else {
68
+ } else {
70
69
  formData.value = Object.assign({}, props.initialData)
71
70
  }
72
- })
71
+ }
72
+
73
+ watchEffect(loadFormData)
73
74
 
74
75
  watch(() => isShowing.value, (newValue) => {
75
76
  if (!newValue) formPadRef.value.reset()
77
+ else loadFormData()
76
78
  })
77
79
  </script>
78
80
 
@@ -103,6 +105,7 @@ watch(() => isShowing.value, (newValue) => {
103
105
  <form-pad
104
106
  ref="formPadRef"
105
107
  v-model="formData"
108
+ isolated
106
109
  >
107
110
  <template #default="slotData">
108
111
  <slot
@@ -17,11 +17,13 @@ interface Props {
17
17
  templateScript?: string
18
18
  disabled?: boolean
19
19
  readonly?: boolean
20
+ isolated?: boolean
20
21
  }
21
22
 
22
23
  const props = withDefaults(defineProps<Props>(), {
23
24
  disabled: false,
24
25
  readonly: false,
26
+ isolated: false,
25
27
  })
26
28
 
27
29
  const emit = defineEmits(['update:modelValue'])
@@ -71,7 +73,7 @@ function buildFormComponent() {
71
73
  const originalConsoleError = console.warn
72
74
  console.warn = (error) => { throw new Error(error) } // eslint-disable-line
73
75
  try {
74
- const componentTemplate = '<form-pad ref="formPadTemplate" v-model="formComponentData" :disabled="disabled" :readonly="readonly"><template v-slot="{ data,isDisabled,isReadonly,rules,formProvided }">' + trimmedTemplate.value + '</template></form-pad>'
76
+ const componentTemplate = '<form-pad ref="formPadTemplate" v-model="formComponentData" :disabled="disabled" :readonly="readonly" :isolated="isolated"><template v-slot="{ data,isDisabled,isReadonly,rules,formProvided }">' + trimmedTemplate.value + '</template></form-pad>'
75
77
  compile(componentTemplate)
76
78
  formComponent.value = defineComponent({
77
79
  components: { FormPad },
@@ -79,6 +81,7 @@ function buildFormComponent() {
79
81
  modelValue: { type: Object, default: undefined },
80
82
  disabled: { type: Boolean, default: false },
81
83
  readonly: { type: Boolean, default: false },
84
+ isolated: { type: Boolean, default: false },
82
85
  },
83
86
  emits: ['update:modelValue'],
84
87
  setup(props, ctx) {
@@ -113,17 +116,17 @@ function buildFormComponent() {
113
116
 
114
117
  function reset() {
115
118
  if (!formInjected.value) formPad.value.reset()
116
- else formInjected.value.reset()
119
+ else formInjected.value.items.forEach((item: any)=>item.reset())
117
120
  }
118
121
 
119
122
  function validate() {
120
123
  if (!formInjected.value) formPad.value.validate()
121
- else formInjected.value.validate()
124
+ else formInjected.value.items.forEach((item: any)=>item.validate())
122
125
  }
123
126
 
124
127
  function resetValidate() {
125
128
  if (!formInjected.value) formPad.value.resetValidate()
126
- else formInjected.value.resetValidate()
129
+ else formInjected.value.items.forEach((item: any)=>item.resetValidate())
127
130
  }
128
131
 
129
132
  const isValid = computed(() => {
@@ -132,7 +135,7 @@ const isValid = computed(() => {
132
135
  })
133
136
 
134
137
  onMounted(() => {
135
- formInjected.value = inject(formInjectKey, false)
138
+ if (!props.isolated) formInjected.value = inject(formInjectKey, false)
136
139
  buildFormComponent()
137
140
  })
138
141
 
@@ -186,6 +189,7 @@ defineExpose({
186
189
  v-model="formData"
187
190
  :disabled="disabled"
188
191
  :readonly="readonly"
192
+ :isolated="isolated"
189
193
  :class="$attrs.class"
190
194
  />
191
195
  </template>
@@ -2,7 +2,7 @@
2
2
  import { VDataTable } from 'vuetify/components/VDataTable'
3
3
  import { ref, watch, nextTick, defineOptions,computed,useAttrs } from 'vue'
4
4
  import type { FormDialogCallback } from './Dialog.vue'
5
- import {omit} from 'lodash-es'
5
+ import { omit } from 'lodash-es'
6
6
  defineOptions({
7
7
  inheritAttrs: false,
8
8
  })
@@ -64,7 +64,8 @@ watch(items, (newValue) => {
64
64
  }, { deep: true })
65
65
 
66
66
  function createItem(item: Record<string, any>, callback?: FormDialogCallback) {
67
- item[props.modelKey] = Math.max(...items.value.map(i => i[props.modelKey] || 0)) + 1
67
+ if (items.value.length>0) item[props.modelKey] = Math.max(...items.value.map(i => i[props.modelKey] || 0)) + 1
68
+ else item[props.modelKey] = 1
68
69
 
69
70
  items.value.push(item)
70
71
 
@@ -23,9 +23,8 @@ function templateItemToString(item) {
23
23
  if (item.inputType == "MasterAutocomplete") {
24
24
  optionString += 'groupKey="' + item.inputOptions + '" ';
25
25
  }
26
- if (item.inputType == "VSelect") {
26
+ if (item.inputType == "VSelect" || item.inputType == "VAutocomplete" || item.inputType == "VCombobox") {
27
27
  const choice = optionStringToChoiceObject(item.inputOptions);
28
- console.log(choice);
29
28
  optionString = `item-value="value" item-title="label" :items='` + JSON.stringify(choice).replaceAll("'", "&#39;") + "' ";
30
29
  }
31
30
  if (item.inputType == "VRadio" || item.inputType == "VRadioInline") {
@@ -40,7 +39,7 @@ function templateItemToString(item) {
40
39
  item.inputAttributes = (item.inputAttributes?.trim() + " dense").trim();
41
40
  if (item.validationRules)
42
41
  validationRules = buildValidationRules(item.validationRules);
43
- let templateString = "";
42
+ let templateString;
44
43
  switch (item.inputType) {
45
44
  case "CustomCode":
46
45
  templateString = `${item.inputCustomCode}`;
@@ -3,5 +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"
6
+ declare module 'prettier'
7
+ declare module 'prettier/plugins/html'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",
@@ -39,6 +39,10 @@
39
39
  "test:watch": "vitest watch"
40
40
  },
41
41
  "dependencies": {
42
+ "@codemirror/lang-html": "^6.4.9",
43
+ "@codemirror/lang-javascript": "^6.2.2",
44
+ "@codemirror/lang-vue": "^0.1.3",
45
+ "@codemirror/theme-one-dark": "^6.1.2",
42
46
  "@fortawesome/fontawesome-free": "^6.5.2",
43
47
  "@fullcalendar/core": "^6.1.11",
44
48
  "@fullcalendar/daygrid": "^6.1.11",
@@ -65,6 +69,7 @@
65
69
  "print-js": "^1.6.0",
66
70
  "uid": "^2.0.2",
67
71
  "vue": "^3.4.25",
72
+ "vue-codemirror": "^6.1.1",
68
73
  "vue-signature-pad": "^3.0.2",
69
74
  "vuetify": "^3.6.8",
70
75
  "prettier": "3.3.2",