@ramathibodi/nuxt-commons 0.1.47 → 0.1.48

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.47",
7
+ "version": "0.1.48",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
@@ -112,13 +112,27 @@ export function escapeObjectForInlineBinding(obj) {
112
112
  export function buildValidationRules(validationString) {
113
113
  validationString = validationString.replace(/^\[|]$/g, "").trim();
114
114
  if (!validationRulesRegex.test(validationString)) return "";
115
- const rules = validationString.split(",").map((rule) => {
115
+ const rules = [];
116
+ let current = "";
117
+ let depth = 0;
118
+ for (let char of validationString) {
119
+ if (char === "," && depth === 0) {
120
+ if (current.trim()) rules.push(current.trim());
121
+ current = "";
122
+ } else {
123
+ if (char === "(") depth++;
124
+ if (char === ")") depth--;
125
+ current += char;
126
+ }
127
+ }
128
+ if (current.trim()) rules.push(current.trim());
129
+ const formatted = rules.map((rule) => {
116
130
  rule = rule.trim();
117
131
  if (!rule.startsWith("rules.")) rule = `rules.${rule}`;
118
132
  if (!/\(.+\)$/.test(rule)) rule += "()";
119
133
  return rule.replace(/"/g, "'");
120
134
  });
121
- return `:rules="[${rules.join(",")}]"`;
135
+ return `:rules="[${formatted.join(",")}]"`;
122
136
  }
123
137
  export function processDefaultTemplate(item, insideTemplate, optionString, validationRules) {
124
138
  if (!validationRules) validationRules = item.validationRules ? buildValidationRules(item.validationRules) || "" : "";
@@ -5,5 +5,7 @@ import {
5
5
  } from "./template.js";
6
6
  export function processTemplateFormTable(item, parentTemplates) {
7
7
  let tableOptions = Object.assign({ title: item.inputLabel || "", formTemplate: "" }, item.inputOptions);
8
- return processDefaultTemplate(item, `<template #form="{data,rules}">${useDocumentTemplate(tableOptions.formTemplate)}</template>`, `title="${tableOptions.title}" :headers='${escapeObjectForInlineBinding(tableOptions.headers || {})}'`);
8
+ let tableHeader = tableOptions.headers || [];
9
+ if (!tableHeader.some((h) => h.key === "action")) tableHeader.push({ title: "Action", key: "action", width: "100px" });
10
+ return processDefaultTemplate(item, `<template #form="{data,rules}">${useDocumentTemplate(tableOptions.formTemplate)}</template>`, `title="${tableOptions.title}" :headers='${escapeObjectForInlineBinding(tableHeader)}'`);
9
11
  }
@@ -7,7 +7,7 @@ export function useRules() {
7
7
  const requireIf = (conditionIf, customError = "This field is required") => (value) => condition(!!value || value === false || value === 0 || !conditionIf, customError);
8
8
  const requireTrue = (customError = "This field must be true") => (value) => condition(!!value, customError);
9
9
  const requireTrueIf = (conditionIf, customError = "This field must be true") => (value) => condition(!!value || !conditionIf, customError);
10
- const numeric = (customError = "This field must be a number") => (value) => condition(!value || !Number.isNaN(value), customError);
10
+ const numeric = (customError = "This field must be a number") => (value) => condition(!value || !isNaN(Number(value)), customError);
11
11
  const range = (minValue, maxValue, customError = `Value is out of range (${minValue}-${maxValue})`) => (value) => condition(!value || value >= minValue && value <= maxValue, customError);
12
12
  const integer = (customError = "This field must be an integer") => (value) => condition(!value || isInteger(value) || /^\+?-?\d+$/.test(value), customError);
13
13
  const unique = (data, fieldName, customError = "This field must be unique") => (value) => condition(!value || !data || !find(data, [fieldName, value]), customError);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",