impaktapps-ui-builder 1.0.305 → 1.0.306-test.1

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.
@@ -7926,7 +7926,7 @@ const buildWrapper = (label, elements) => {
7926
7926
  elements: elements || []
7927
7927
  };
7928
7928
  };
7929
- const getTextArea = (scope, heading, hideButton, layout) => {
7929
+ const getTextArea = (scope, heading, hideButton, layout, defaultValue) => {
7930
7930
  return {
7931
7931
  type: "Control",
7932
7932
  scope: `#/properties/${scope}`,
@@ -7939,7 +7939,8 @@ const getTextArea = (scope, heading, hideButton, layout) => {
7939
7939
  label: heading,
7940
7940
  minRows: 8,
7941
7941
  hideButton,
7942
- enableCodeEditor: true
7942
+ enableCodeEditor: true,
7943
+ defaultValue
7943
7944
  }
7944
7945
  }
7945
7946
  };
@@ -8787,12 +8788,75 @@ const getFormdataFromSessionStorage = (path) => {
8787
8788
  }
8788
8789
  return returnValue || pageFormdata;
8789
8790
  };
8791
+ const collectScopeNames = (config2, scopeMap = {}) => {
8792
+ if (!config2 || typeof config2 !== "object")
8793
+ return scopeMap;
8794
+ if (Array.isArray(config2)) {
8795
+ config2.forEach((item) => collectScopeNames(item, scopeMap));
8796
+ return scopeMap;
8797
+ }
8798
+ if (config2.name) {
8799
+ scopeMap[config2.name] = true;
8800
+ }
8801
+ if (Array.isArray(config2.elements)) {
8802
+ collectScopeNames(config2.elements, scopeMap);
8803
+ }
8804
+ return scopeMap;
8805
+ };
8806
+ const initialiseScopeKey = () => {
8807
+ const config2 = sessionStorage.getItem("pageFormdata") ? JSON.parse(sessionStorage.getItem("pageFormdata")) : void 0;
8808
+ const names = config2 ? collectScopeNames(config2) : {};
8809
+ sessionStorage.setItem("scopeKey", JSON.stringify(names));
8810
+ };
8811
+ const getScopeKey = () => {
8812
+ const raw = sessionStorage.getItem("scopeKey");
8813
+ return raw ? JSON.parse(raw) : {};
8814
+ };
8815
+ const addToScopeKey = (name) => {
8816
+ if (!name)
8817
+ return;
8818
+ const scopeKey = getScopeKey();
8819
+ scopeKey[name] = true;
8820
+ sessionStorage.setItem("scopeKey", JSON.stringify(scopeKey));
8821
+ };
8822
+ const doesScopeNameExist = (name) => {
8823
+ if (!name)
8824
+ return false;
8825
+ const scopeKey = getScopeKey();
8826
+ return !!scopeKey[name];
8827
+ };
8828
+ const findDuplicateScopeNames = (config2) => {
8829
+ const scopeNameCount = {};
8830
+ const traverse = (currentNode) => {
8831
+ if (!currentNode || typeof currentNode !== "object")
8832
+ return;
8833
+ if (Array.isArray(currentNode)) {
8834
+ currentNode.forEach(traverse);
8835
+ return;
8836
+ }
8837
+ if (currentNode.name) {
8838
+ scopeNameCount[currentNode.name] = (scopeNameCount[currentNode.name] || 0) + 1;
8839
+ }
8840
+ if (Array.isArray(currentNode.elements))
8841
+ traverse(currentNode.elements);
8842
+ };
8843
+ traverse(config2);
8844
+ return Object.keys(scopeNameCount).filter((name) => scopeNameCount[name] > 1);
8845
+ };
8790
8846
  async function saveHandler(store2, service2, submitHandler) {
8791
- var _a, _b;
8792
- (_a = store2.searchParams) == null ? void 0 : _a.get("id");
8793
- const path = (_b = store2.searchParams) == null ? void 0 : _b.get("path");
8847
+ var _a;
8848
+ const path = (_a = store2.searchParams) == null ? void 0 : _a.get("path");
8794
8849
  saveFormdataInSessionStorage(store2.ctx.core.data, path);
8795
8850
  const config2 = JSON.parse(sessionStorage.getItem("pageFormdata"));
8851
+ const duplicates = findDuplicateScopeNames(config2);
8852
+ if (duplicates.length > 0) {
8853
+ store2.setValidation("ValidateAndShow");
8854
+ store2.setNotify({
8855
+ Fail: true,
8856
+ FailMessage: `Duplicate names found: ${duplicates.join(", ")}`
8857
+ });
8858
+ return;
8859
+ }
8796
8860
  if (_.isEmpty(store2.ctx.core.errors)) {
8797
8861
  try {
8798
8862
  const saveReturn = await submitHandler(store2, service2, config2);
@@ -8807,6 +8871,7 @@ async function saveHandler(store2, service2, submitHandler) {
8807
8871
  const navigateHandler = (store2, isSubmitted, pageName, errorMessage) => {
8808
8872
  if (isSubmitted) {
8809
8873
  sessionStorage.removeItem("pageFormdata");
8874
+ sessionStorage.removeItem("scopeKey");
8810
8875
  store2.navigate(pageName || -1);
8811
8876
  store2.setNotify({
8812
8877
  SuccessMessage: "Submit Successfully",
@@ -8825,6 +8890,7 @@ function okHandler(store2) {
8825
8890
  const path = (_a = store2.searchParams) == null ? void 0 : _a.get("path");
8826
8891
  if (_.isEmpty(store2.ctx.core.errors)) {
8827
8892
  saveFormdataInSessionStorage(store2.ctx.core.data, path);
8893
+ addToScopeKey(store2.ctx.core.data);
8828
8894
  store2.navigate(-1);
8829
8895
  store2.setNotify({
8830
8896
  SuccessMessage: "Save Successfully",
@@ -9026,6 +9092,15 @@ function refreshPage(type, store2) {
9026
9092
  }
9027
9093
  store2.setUiSchema(UiSchema);
9028
9094
  }
9095
+ const debouncedNameValidator = _.debounce((store2, newName) => {
9096
+ if (doesScopeNameExist(newName)) {
9097
+ store2.setValidation("ValidateAndShow");
9098
+ store2.setNotify({
9099
+ Fail: true,
9100
+ FailMessage: `Name "${newName}" already exists. Please use a unique name.`
9101
+ });
9102
+ }
9103
+ }, 400);
9029
9104
  var Component = (store2, dynamicData2, submitHandler, service2) => {
9030
9105
  return {
9031
9106
  setPage: async function() {
@@ -9072,13 +9147,19 @@ var Component = (store2, dynamicData2, submitHandler, service2) => {
9072
9147
  schema2.properties.pageName.path = pathArray;
9073
9148
  return schema2;
9074
9149
  },
9075
- okHandler: () => okHandler(store2),
9150
+ okHandler: () => {
9151
+ okHandler(store2);
9152
+ addToScopeKey(store2.ctx.core.data);
9153
+ },
9076
9154
  saveHandler: async () => await saveHandler(store2, service2, submitHandler),
9077
9155
  onChange: function() {
9078
- var _a, _b, _c, _d;
9156
+ var _a, _b, _c, _d, _e, _f, _g;
9079
9157
  if (((_a = store2 == null ? void 0 : store2.formData) == null ? void 0 : _a.type) !== ((_b = store2 == null ? void 0 : store2.newData) == null ? void 0 : _b.type) && ((_c = store2 == null ? void 0 : store2.newData) == null ? void 0 : _c.type) !== void 0) {
9080
9158
  this.refreshPage((_d = store2 == null ? void 0 : store2.newData) == null ? void 0 : _d.type, store2);
9081
9159
  }
9160
+ if (((_e = store2 == null ? void 0 : store2.formData) == null ? void 0 : _e.name) !== ((_f = store2 == null ? void 0 : store2.newData) == null ? void 0 : _f.name) && ((_g = store2 == null ? void 0 : store2.newData) == null ? void 0 : _g.name) !== void 0) {
9161
+ debouncedNameValidator(store2, store2.newData.name);
9162
+ }
9082
9163
  },
9083
9164
  editComponents: function() {
9084
9165
  var _a, _b, _c;
@@ -9088,6 +9169,7 @@ var Component = (store2, dynamicData2, submitHandler, service2) => {
9088
9169
  const path = (_a = store2.searchParams) == null ? void 0 : _a.get("path");
9089
9170
  const id = (_b = store2.searchParams) == null ? void 0 : _b.get("id");
9090
9171
  saveFormdataInSessionStorage(store2.ctx.core.data, path);
9172
+ addToScopeKey(store2.ctx.core.data);
9091
9173
  if (path) {
9092
9174
  const path2 = (_c = store2.searchParams) == null ? void 0 : _c.get("path");
9093
9175
  const finalPath = `${path2}.elements[${rowId}]`;
@@ -9132,6 +9214,7 @@ var Component = (store2, dynamicData2, submitHandler, service2) => {
9132
9214
  }
9133
9215
  const path = (_a = store2.searchParams) == null ? void 0 : _a.get("path");
9134
9216
  saveFormdataInSessionStorage(store2.ctx.core.data, path);
9217
+ addToScopeKey(store2.ctx.core.data);
9135
9218
  const finalPath = `${path}.elements[${store2.formData.elements.length}]`;
9136
9219
  store2.searchParams.set("path", finalPath);
9137
9220
  store2.setSearchParams(store2.searchParams);
@@ -9293,6 +9376,7 @@ var pageMaster = (funcParams) => {
9293
9376
  const schema2 = await this.getSchema();
9294
9377
  store2.setSchema(schema2);
9295
9378
  store2.setUiSchema(uiSchema);
9379
+ initialiseScopeKey();
9296
9380
  },
9297
9381
  getFormdata: async function() {
9298
9382
  var _a;
@@ -9321,6 +9405,7 @@ var pageMaster = (funcParams) => {
9321
9405
  },
9322
9406
  backHandler: () => {
9323
9407
  sessionStorage.removeItem("pageFormdata");
9408
+ sessionStorage.removeItem("scopeKey");
9324
9409
  store2.navigate("/PageMasterRecords");
9325
9410
  },
9326
9411
  onAddClickHandler: function() {
@@ -9332,6 +9417,7 @@ var pageMaster = (funcParams) => {
9332
9417
  store2.formData.elements = [];
9333
9418
  }
9334
9419
  const response = saveFormdataInSessionStorage(store2.ctx.core.data);
9420
+ addToScopeKey(store2.ctx.core.data);
9335
9421
  if (id) {
9336
9422
  store2.navigate(
9337
9423
  `/Component?path=${`elements[${response == null ? void 0 : response.elements.length}]`}&id=${id}`
@@ -9357,6 +9443,7 @@ var pageMaster = (funcParams) => {
9357
9443
  store2.formData.events = [];
9358
9444
  }
9359
9445
  saveFormdataInSessionStorage(store2.ctx.core.data);
9446
+ addToScopeKey(store2.ctx.core.data);
9360
9447
  const finalPath = `events[${store2.formData.events.length}]`;
9361
9448
  store2.navigate(`/ComponentEvents?path=${finalPath}&id=${id}`);
9362
9449
  },
@@ -9367,6 +9454,7 @@ var pageMaster = (funcParams) => {
9367
9454
  const rowId = dynamicData2.path.split(".")[1];
9368
9455
  const id = (_a = store2.searchParams) == null ? void 0 : _a.get("id");
9369
9456
  saveFormdataInSessionStorage(store2.ctx.core.data);
9457
+ addToScopeKey(store2.ctx.core.data);
9370
9458
  const finalPath = `events[${rowId}]`;
9371
9459
  store2.navigate(`/ComponentEvents?path=${finalPath}&id=${id}`);
9372
9460
  },
@@ -10119,7 +10207,7 @@ const APISection = {
10119
10207
  }
10120
10208
  ]
10121
10209
  },
10122
- getTextArea("apiBody", "Transformer", true, 12)
10210
+ getTextArea("apiBody", "Transformer", true, 12, boilerplate)
10123
10211
  ]
10124
10212
  };
10125
10213
  const refreshSectionUiSchema = {
@@ -10174,6 +10262,7 @@ const refreshSectionUiSchema = {
10174
10262
  }
10175
10263
  ]
10176
10264
  };
10265
+ const boilerplate = "(store, dynamicData, user, body, service) => {\n}";
10177
10266
  var event = (store2, dynamicData2, submitHandler, service2, functionsName) => {
10178
10267
  return {
10179
10268
  setPage: async function() {
@@ -10185,7 +10274,7 @@ var event = (store2, dynamicData2, submitHandler, service2, functionsName) => {
10185
10274
  this.refreshPage(formdata.Handler, store2);
10186
10275
  },
10187
10276
  refreshPage: (handlerType, store22) => {
10188
- var _a, _b, _c;
10277
+ var _a, _b, _c, _d, _e;
10189
10278
  const uiSchema = _.cloneDeep(EventUiSchema(store22.theme.myTheme));
10190
10279
  const schema2 = _.cloneDeep(EventSchema);
10191
10280
  if (handlerType) {
@@ -10210,8 +10299,12 @@ var event = (store2, dynamicData2, submitHandler, service2, functionsName) => {
10210
10299
  uiSchema.elements[0].elements[0].elements[4] = getTextArea(
10211
10300
  "eventCode",
10212
10301
  "Write Custom Code",
10213
- false
10302
+ false,
10303
+ void 0
10214
10304
  );
10305
+ if (!((_a = store22.formData) == null ? void 0 : _a.eventCode)) {
10306
+ store22.setFormdata((prev) => ({ ...prev, eventCode: boilerplate }));
10307
+ }
10215
10308
  schema2.required = ["eventType", "Handler", "eventCode"];
10216
10309
  } else if (handlerType === "api") {
10217
10310
  uiSchema.elements[0].elements[0].elements[2] = emptyBox$1("emptyBox", {
@@ -10221,6 +10314,9 @@ var event = (store2, dynamicData2, submitHandler, service2, functionsName) => {
10221
10314
  lg: 6
10222
10315
  });
10223
10316
  uiSchema.elements[0].elements[0].elements[3] = APISection;
10317
+ if (!((_b = store22.formData) == null ? void 0 : _b.apiBody)) {
10318
+ store22.setFormdata((prev) => ({ ...prev, apiBody: boilerplate }));
10319
+ }
10224
10320
  schema2.required = ["eventType", "Handler", "method", "path"];
10225
10321
  } else if (handlerType === "inBuiltFunction") {
10226
10322
  uiSchema.elements[0].elements[0].elements[2] = getSelectField(
@@ -10271,9 +10367,9 @@ var event = (store2, dynamicData2, submitHandler, service2, functionsName) => {
10271
10367
  schema2.properties.RemoveItemButton.disabled = false;
10272
10368
  }
10273
10369
  const config2 = JSON.parse(sessionStorage.getItem("pageFormdata"));
10274
- const path = (_a = store22.searchParams) == null ? void 0 : _a.get("path");
10275
- const id = (_b = store22.searchParams) == null ? void 0 : _b.get("id");
10276
- let pathArray = [{ label: (_c = config2.name) != null ? _c : "NewPage", path: `/PageMaster${id ? `?id=${id}` : ""}` }];
10370
+ const path = (_c = store22.searchParams) == null ? void 0 : _c.get("path");
10371
+ const id = (_d = store22.searchParams) == null ? void 0 : _d.get("id");
10372
+ let pathArray = [{ label: (_e = config2.name) != null ? _e : "NewPage", path: `/PageMaster${id ? `?id=${id}` : ""}` }];
10277
10373
  if (path) {
10278
10374
  const pathArrayAll = path.split(".");
10279
10375
  const arr = [];