@ramathibodi/nuxt-commons 0.1.41 → 0.1.42

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,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.1.41",
7
+ "version": "0.1.42",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.3",
10
10
  "unbuild": "2.0.0"
@@ -3,6 +3,7 @@ import {computed, ref, watch} from 'vue'
3
3
  import * as prettier from 'prettier'
4
4
  import prettierPluginHtml from 'prettier/plugins/html'
5
5
  import {useDocumentTemplate, validationRulesRegex,optionStringToChoiceObject} from '../../composables/document/template'
6
+ import {cloneDeep} from "lodash-es";
6
7
 
7
8
  interface Props {
8
9
  title?: string
@@ -13,10 +14,11 @@ const props = withDefaults(defineProps<Props>(), {
13
14
  })
14
15
 
15
16
  const emit = defineEmits(['update:modelValue'])
16
- const modelValue = defineModel<string>()
17
+ const modelValue = defineModel<string|Record<string, any>[]>()
17
18
 
19
+ const advanceModeCode = ref<string>()
18
20
  const isAdvanceMode = computed(() => {
19
- return modelValue.value && !isValidJsonArrayOfObjects(modelValue.value)
21
+ return modelValue.value && ((typeof modelValue.value === "string") && !isValidJsonArrayOfObjects(modelValue.value))
20
22
  })
21
23
 
22
24
  const templateItems = ref<Record<string, any>[]>([])
@@ -70,6 +72,11 @@ const formTableHeaders = ref([
70
72
  title: 'Width',
71
73
  key: 'width',
72
74
  },
75
+ {
76
+ title: 'Action',
77
+ key: 'action',
78
+ width: '120px',
79
+ },
73
80
  ])
74
81
 
75
82
  const choiceHeaders = ref([
@@ -81,6 +88,11 @@ const choiceHeaders = ref([
81
88
  title: 'Value',
82
89
  key: 'value',
83
90
  },
91
+ {
92
+ title: 'Action',
93
+ key: 'action',
94
+ width: '120px',
95
+ },
84
96
  ])
85
97
 
86
98
 
@@ -99,9 +111,15 @@ watch(templateItems, (newValue) => {
99
111
  }, { deep: true })
100
112
 
101
113
  watch(modelValue, (newValue) => {
102
- if (isValidJsonArrayOfObjects(newValue)) templateItems.value = JSON.parse(newValue as string)
114
+ if (typeof newValue === "string" && isValidJsonArrayOfObjects(newValue)) templateItems.value = JSON.parse(newValue as string)
115
+ else if (typeof newValue === "string") advanceModeCode.value = newValue
116
+ else if (newValue) templateItems.value = cloneDeep(newValue)
103
117
  }, { deep: true, immediate: true })
104
118
 
119
+ watch(advanceModeCode, (newValue)=>{
120
+ if (isAdvanceMode.value) modelValue.value = newValue
121
+ })
122
+
105
123
  async function convertToAdvanceMode() {
106
124
  if (!isAdvanceMode.value) {
107
125
  modelValue.value = await prettier.format(useDocumentTemplate(templateItems.value).replaceAll('>', '>\n'), { parser: 'html', plugins: [prettierPluginHtml] })
@@ -197,7 +215,7 @@ const ruleOptions = (inputType: string) => (value: any) => {
197
215
  :rules="[rules.require()]"
198
216
  type="number"
199
217
  />
200
- <form-hidden v-model="data.inputOptions" :item-value="data.inputType" :hook="()=>undefined"></form-hidden>
218
+ <form-hidden v-model="data.inputOptions" :item-value="data.inputType" :hook="(_result: any,model: any,newValue: any,oldValue: any)=>{return (newValue && oldValue) ? undefined : model}"></form-hidden>
201
219
  </v-col>
202
220
  <v-col cols="4" v-if="!notRequireLabel.includes(data.inputType)">
203
221
  <v-text-field
@@ -367,10 +385,22 @@ const ruleOptions = (inputType: string) => (value: any) => {
367
385
  <template v-if="props.item.inputAttributes">
368
386
  <b>Input Attributes :</b> {{ props.item.inputAttributes }}<br>
369
387
  </template>
388
+ <template v-if="props.item.columnAttributes">
389
+ <b>Column Attributes :</b> {{ props.item.columnAttributes }}<br>
390
+ </template>
391
+ <template v-if="props.item.conditionalDisplay">
392
+ <b>Conditional Display :</b> {{ props.item.conditionalDisplay }}<br>
393
+ </template>
394
+ <template v-if="props.item.computedValue">
395
+ <b>Computed Value :</b> {{ props.item.computedValue }}<br>
396
+ </template>
397
+ <template v-if="props.item.retrievedValue">
398
+ <b>Retrieved Value :</b> {{ props.item.retrievedValue }}<br>
399
+ </template>
370
400
  </template>
371
401
  </FormTable>
372
402
  <FormCodeEditor
373
403
  v-else
374
- v-model="modelValue"
404
+ v-model="advanceModeCode"
375
405
  />
376
406
  </template>
@@ -11,10 +11,10 @@ interface Props {
11
11
  const props = defineProps<Props>()
12
12
  const emit = defineEmits(['update:modelValue'])
13
13
 
14
- watch(() => props.itemValue, (newValue) => {
14
+ watch(() => props.itemValue, (newValue,oldValue) => {
15
15
  const resultValue = cloneDeep(newValue)
16
16
  if (props.hook) {
17
- Promise.resolve(props.hook(resultValue, props.modelValue)).then((result) => {
17
+ Promise.resolve(props.hook(resultValue, props.modelValue,newValue,oldValue)).then((result) => {
18
18
  emit('update:modelValue', result)
19
19
  }).catch(e => void e)
20
20
  }
@@ -41,15 +41,16 @@ function templateItemToString(item, parentTemplates) {
41
41
  item.inputAttributes = `${item.inputAttributes?.trim() || ""} dense`.trim();
42
42
  }
43
43
  let templateString;
44
+ const validationRules = item.validationRules ? buildValidationRules(item.validationRules) || "" : "";
44
45
  switch (item.inputType) {
45
46
  case "CustomCode":
46
47
  templateString = item.inputCustomCode || "";
47
48
  break;
48
49
  case "VRadio":
50
+ templateString = `<v-radio-group v-model="data.${item.variableName || ""}"${validationRules ? " " + validationRules.trim() : ""}>${item.inputLabel ? `<template #label>${item.inputLabel}</template>` : ""}${optionString ? " " + optionString.trim() : ""}</v-radio-group>`;
51
+ break;
49
52
  case "VRadioInline":
50
- const inlineAttr = item.inputType === "VRadioInline" ? " inline" : "";
51
- const validationRules = item.validationRules ? buildValidationRules(item.validationRules) || "" : "";
52
- templateString = `<v-radio-group v-model="data.${item.variableName || ""}"${inlineAttr}${validationRules ? " " + validationRules.trim() : ""}>${item.inputLabel ? `<template #prepend>${item.inputLabel}</template>` : ""}${optionString ? " " + optionString.trim() : ""}</v-radio-group>`;
53
+ templateString = `<v-radio-group v-model="data.${item.variableName || ""}" inline ${validationRules ? " " + validationRules.trim() : ""}>${item.inputLabel ? `<template #prepend><span class="opacity-60">${item.inputLabel}</span></template>` : ""}${optionString ? " " + optionString.trim() : ""}</v-radio-group>`;
53
54
  break;
54
55
  case "Separator":
55
56
  templateString = "</v-row><v-row dense>";
@@ -65,7 +66,7 @@ function templateItemToString(item, parentTemplates) {
65
66
  break;
66
67
  case "DocumentForm":
67
68
  const parentTemplatesString = typeof parentTemplates === "string" ? parentTemplates : parentTemplates.join("|");
68
- templateString = `<document-form v-model="data" templateCode="${item.inputOptions || ""}" parent-templates="${parentTemplatesString}"></document-form>`;
69
+ templateString = `<document-form :model-value="data" templateCode="${item.inputOptions || ""}" parent-templates="${parentTemplatesString}"></document-form>`;
69
70
  break;
70
71
  default:
71
72
  templateString = processDefaultTemplate(item, void 0, optionString);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "0.1.41",
3
+ "version": "0.1.42",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",