@nickaux/form-configurator 1.1.219 → 1.1.220

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.
@@ -39043,7 +39043,15 @@ if (process.env.NODE_ENV === "production") {
39043
39043
  m$1.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
39044
39044
  }
39045
39045
  const checkUserRole = (p_user, p_role) => {
39046
- return true;
39046
+ var _a, _b;
39047
+ if (p_user === null) {
39048
+ return false;
39049
+ }
39050
+ const userRole = ((_b = (_a = p_user == null ? void 0 : p_user.appUser) == null ? void 0 : _a.roles) == null ? void 0 : _b.length) ? p_user.appUser.roles : ["user"];
39051
+ if (userRole) {
39052
+ return userRole.includes(p_role);
39053
+ }
39054
+ return false;
39047
39055
  };
39048
39056
  const autoFormatValue = (p_value) => {
39049
39057
  let r_value = p_value;
@@ -39765,7 +39773,7 @@ const Field = forwardRef(({ field, children }, ref2) => {
39765
39773
  var _a, _b, _c, _d, _e2, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
39766
39774
  const [renderCounter, setRenderCounter] = useState(0);
39767
39775
  let previousFocusedElement = null;
39768
- const isUserAdmin = checkUserRole(field.formManager.options.user);
39776
+ const isUserAdmin = checkUserRole(field.formManager.options.user, "admin");
39769
39777
  useImperativeHandle(ref2, () => ({
39770
39778
  updateField: () => {
39771
39779
  previousFocusedElement = document.activeElement;
@@ -148851,6 +148859,7 @@ class FormManager {
148851
148859
  });
148852
148860
  }
148853
148861
  });
148862
+ // loop on all fields in fieldsByNode and get value if visible ( recursive )
148854
148863
  __publicField(this, "getVisibleValue", (field = {
148855
148864
  id: "__result__",
148856
148865
  children: this.formElements.map((o2) => this.fieldsByPath[o2.id]),
@@ -148951,6 +148960,7 @@ class FormManager {
148951
148960
  });
148952
148961
  }
148953
148962
  }
148963
+ // use for repeater
148954
148964
  createDynamicField(field, p_position, p_data = null) {
148955
148965
  const uniqueId = v4();
148956
148966
  this.dynamicPathPart[uniqueId] = p_position;
@@ -149011,6 +149021,11 @@ class FormManager {
149011
149021
  delete this.dynamicPathPart[p_itemId];
149012
149022
  delete this.fields[p_itemId];
149013
149023
  }
149024
+ //
149025
+ // removeDynamicField(p_uniqueId){
149026
+ // this.dynamicPathPart[p_uniqueId] =false;
149027
+ // }
149028
+ //
149014
149029
  getField(p_item, v_item, custom_id, parentUid) {
149015
149030
  if (typeField[v_item.format]) {
149016
149031
  const currentTypeField = new typeField[v_item.format](
@@ -149035,6 +149050,7 @@ class FormManager {
149035
149050
  return false;
149036
149051
  }
149037
149052
  }
149053
+ // get field path like path for data
149038
149054
  getNormalizedFieldPath(path) {
149039
149055
  const normalizedFieldPath = [];
149040
149056
  var paths = ("" + path).split("__");
@@ -149151,6 +149167,8 @@ class FormManager {
149151
149167
  return newField;
149152
149168
  }) : [];
149153
149169
  }
149170
+ initValueForm() {
149171
+ }
149154
149172
  resolveFieldRefs(formJson, fieldsRefJson) {
149155
149173
  const resolveRefsInForm = (formItem) => {
149156
149174
  if (formItem.fieldRef && fieldsRefJson[formItem.fieldRef]) {
@@ -149186,6 +149204,45 @@ class FormManager {
149186
149204
  }
149187
149205
  return formData;
149188
149206
  }
149207
+ // getMaxContentLevel(p_item) {
149208
+ // let maxContentLevel = 0;
149209
+ // let rootItem = p_item;
149210
+ // // Vérifier si l'élément est un tableau
149211
+ // if (p_item && Array.isArray(p_item)) {
149212
+ // p_item.forEach((item) => {
149213
+ // if (item?.content) {
149214
+ // // Appeler récursivement pour trouver le niveau maximum
149215
+ // const currentContent = this.getMaxContentLevel(item.content);
149216
+ // if (currentContent.lvl > maxContentLevel) {
149217
+ // maxContentLevel = currentContent.lvl;
149218
+ // rootItem = item;
149219
+ // }
149220
+ // }
149221
+ // });
149222
+ // }
149223
+ // // Retourner le niveau de contenu maximum et l'élément racine associé
149224
+ // return { lvl: maxContentLevel + 1, rootItem: rootItem };
149225
+ // }
149226
+ // getMaxDepthOfContent(content) {
149227
+ // let maxDepth = 0;
149228
+ // const traverse = (items, depth = 1) => {
149229
+ // if (Array.isArray(items)) {
149230
+ // items.forEach((item) => {
149231
+ // if (item?.content && Array.isArray(item.content)) {
149232
+ // traverse(item.content, depth + 1);
149233
+ // }
149234
+ // if (item?.forms?.content && Array.isArray(item.forms.content)) {
149235
+ // traverse(item.forms.content, depth + 1);
149236
+ // }
149237
+ // });
149238
+ // }
149239
+ // if (depth > maxDepth) {
149240
+ // maxDepth = depth;
149241
+ // }
149242
+ // };
149243
+ // traverse(content);
149244
+ // return maxDepth;
149245
+ // }
149189
149246
  /**
149190
149247
  * Charge et fusionne un nœud JSON représentant un formulaire ou une structure de données.
149191
149248
  *
@@ -149200,7 +149257,7 @@ class FormManager {
149200
149257
  if (p_item == null ? void 0 : p_item._fieldRefLinked) {
149201
149258
  return p_item;
149202
149259
  }
149203
- if (p_item.fieldRef) {
149260
+ if (p_item.fieldRef && !(p_item == null ? void 0 : p_item._fieldRefLinked)) {
149204
149261
  if ((_a = this.fieldsRef) == null ? void 0 : _a[p_item.fieldRef]) {
149205
149262
  p_item.id = (p_item == null ? void 0 : p_item.id) ?? p_item.fieldRef;
149206
149263
  p_item = _.merge(
@@ -149208,6 +149265,7 @@ class FormManager {
149208
149265
  this.fieldsRef[p_item.fieldRef],
149209
149266
  _.cloneDeep(p_item)
149210
149267
  );
149268
+ p_item.content = this.fieldsRef[p_item.fieldRef].content;
149211
149269
  const refContent = (_b = this.fieldsRef[p_item.fieldRef]) == null ? void 0 : _b.content;
149212
149270
  if (refContent) {
149213
149271
  if (((_c = p_item.content) == null ? void 0 : _c.length) && Array.isArray(p_item.content)) {
@@ -149247,6 +149305,8 @@ class FormManager {
149247
149305
  }
149248
149306
  return p_item;
149249
149307
  }
149308
+ //initNodevValue: (p_node) => {},
149309
+ // check value of current field from validity param
149250
149310
  checkValidity(item, p_TreeId = null, p_data = null) {
149251
149311
  let resultCheckValidity = { type: "success", message: "" };
149252
149312
  if (item["validity"] && Array.isArray(item["validity"]) && item["validity"].length) {
@@ -149296,7 +149356,8 @@ class FormManager {
149296
149356
  resultCheckValidity = regex.test(testFieldValue) ? { type: "success", message: "" } : { type: "error", message: condition["message"] };
149297
149357
  break;
149298
149358
  case "mandatory":
149299
- resultCheckValidity = testFieldValue !== "" && testFieldValue !== null && testFieldValue !== void 0 && testFieldValue !== false && (typeof testFieldValue !== "object" || typeof testFieldValue === "object" && Object.keys(testFieldValue).length !== 0) ? { type: "success", message: "" } : { type: "error", message: condition["message"] };
149359
+ resultCheckValidity = testFieldValue !== "" && testFieldValue !== null && testFieldValue !== void 0 && testFieldValue !== false && // and test empty object or empty array
149360
+ (typeof testFieldValue !== "object" || typeof testFieldValue === "object" && Object.keys(testFieldValue).length !== 0) ? { type: "success", message: "" } : { type: "error", message: condition["message"] };
149300
149361
  break;
149301
149362
  case "compare":
149302
149363
  resultCheckValidity = testValue(
@@ -149324,6 +149385,7 @@ class FormManager {
149324
149385
  this.validityResult[item.id] = resultCheckValidity;
149325
149386
  return resultCheckValidity;
149326
149387
  }
149388
+ // check only first condition
149327
149389
  checkCondition(item, p_TreeId = null, p_data = null) {
149328
149390
  const evaluateCondition = (condition, treeId) => {
149329
149391
  const operator = condition["operator"];