form-builder-pro 1.2.9 → 1.3.0

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/index.mjs CHANGED
@@ -4608,10 +4608,12 @@ function transformField(field) {
4608
4608
  transformed.optionsSource = field.optionsSource;
4609
4609
  if (field.customOptionsEnabled !== void 0)
4610
4610
  transformed.customOptionsEnabled = field.customOptionsEnabled;
4611
- if (field.groupName !== void 0)
4612
- transformed.groupName = field.groupName;
4613
- if (field.masterTypeName !== void 0)
4614
- transformed.masterTypeName = field.masterTypeName;
4611
+ if (transformed.optionSource === "MASTER") {
4612
+ if (field.groupName !== void 0)
4613
+ transformed.groupName = field.groupName;
4614
+ if (field.masterTypeName !== void 0)
4615
+ transformed.masterTypeName = field.masterTypeName;
4616
+ }
4615
4617
  if ((normalizedType === "select" || normalizedType === "radio" || normalizedType === "checkbox") && field.options && Array.isArray(field.options)) {
4616
4618
  transformed.options = field.options.map((opt, idx) => {
4617
4619
  if (opt && typeof opt === "object" && "label" in opt && "value" in opt) {
@@ -4776,10 +4778,12 @@ function fieldToPayload(field) {
4776
4778
  payload.optionSource = field.optionSource;
4777
4779
  if (field.customOptionsEnabled !== void 0)
4778
4780
  payload.customOptionsEnabled = field.customOptionsEnabled;
4779
- if (field.groupName !== void 0)
4780
- payload.groupName = field.groupName;
4781
- if (field.masterTypeName !== void 0)
4782
- payload.masterTypeName = field.masterTypeName;
4781
+ if (field.optionSource === "MASTER") {
4782
+ if (field.groupName !== void 0)
4783
+ payload.groupName = field.groupName;
4784
+ if (field.masterTypeName !== void 0)
4785
+ payload.masterTypeName = field.masterTypeName;
4786
+ }
4783
4787
  if (field.lookupSourceType !== void 0)
4784
4788
  payload.lookupSourceType = field.lookupSourceType;
4785
4789
  if (field.lookupSource !== void 0)
@@ -10159,112 +10163,6 @@ var FormBuilder = class {
10159
10163
  `show-country-name-${selectedField.id}`
10160
10164
  ));
10161
10165
  }
10162
- if (selectedField.type === "select" && selectedField.optionSource === "MASTER") {
10163
- const masterTypes = formStore.getState().masterTypes;
10164
- const activeMasterTypes = masterTypes.filter((mt) => mt.active === true);
10165
- const dropdownOptionsMap = formStore.getState().dropdownOptionsMap;
10166
- const convertIndexesToOptions = (indexes) => {
10167
- if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
10168
- return [];
10169
- }
10170
- return indexes.map((item, index2) => {
10171
- if (typeof item === "string") {
10172
- return { label: item, value: item };
10173
- }
10174
- if (typeof item === "object" && item !== null) {
10175
- const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
10176
- const value = item.value || item.id || item.name || String(index2);
10177
- return { label, value };
10178
- }
10179
- return { label: String(item), value: String(item) };
10180
- });
10181
- };
10182
- if (activeMasterTypes.length > 0) {
10183
- const groupNameGroup = createElement("div", { className: "mb-4" });
10184
- groupNameGroup.appendChild(createElement("label", { className: "block text-sm font-normal text-gray-700 dark:text-gray-300 mb-1", text: "Master List" }));
10185
- const groupNameSelect = createElement("select", {
10186
- className: "w-full px-3 py-2 border border-gray-200 dark:border-gray-700 rounded-md bg-transparent",
10187
- onchange: (e) => {
10188
- const selectedEnumName = e.target.value;
10189
- if (selectedEnumName) {
10190
- const selectedMasterType = activeMasterTypes.find((mt) => mt.enumName === selectedEnumName);
10191
- if (selectedMasterType) {
10192
- let options = [];
10193
- if (dropdownOptionsMap && dropdownOptionsMap[selectedEnumName]) {
10194
- options = dropdownOptionsMap[selectedEnumName];
10195
- } else if (selectedMasterType.indexes && selectedMasterType.indexes.length > 0) {
10196
- options = convertIndexesToOptions(selectedMasterType.indexes);
10197
- }
10198
- formStore.getState().updateField(selectedField.id, {
10199
- groupName: {
10200
- id: selectedMasterType.id,
10201
- name: selectedMasterType.name
10202
- },
10203
- masterTypeName: selectedEnumName,
10204
- options: options.length > 0 ? options : void 0
10205
- });
10206
- if (this.options.onGroupSelectionChange) {
10207
- this.options.onGroupSelectionChange({
10208
- fieldId: selectedField.id,
10209
- groupEnumName: selectedEnumName
10210
- });
10211
- }
10212
- }
10213
- } else {
10214
- formStore.getState().updateField(selectedField.id, {
10215
- groupName: void 0,
10216
- masterTypeName: void 0,
10217
- options: void 0
10218
- // Clear options when groupName is cleared
10219
- });
10220
- }
10221
- }
10222
- });
10223
- let currentMasterType;
10224
- if (selectedField.masterTypeName) {
10225
- currentMasterType = activeMasterTypes.find((mt) => mt.enumName === selectedField.masterTypeName);
10226
- } else if (selectedField.groupName) {
10227
- currentMasterType = activeMasterTypes.find(
10228
- (mt) => mt.id === selectedField.groupName?.id || mt.name === selectedField.groupName?.name
10229
- );
10230
- }
10231
- groupNameSelect.appendChild(createElement("option", {
10232
- value: "",
10233
- text: "None",
10234
- selected: !currentMasterType
10235
- }));
10236
- activeMasterTypes.forEach((mt) => {
10237
- const isSelected = currentMasterType && (selectedField.masterTypeName && mt.enumName === selectedField.masterTypeName || selectedField.groupName && (mt.id === selectedField.groupName?.id || mt.name === selectedField.groupName?.name));
10238
- const optionValue = mt.enumName || mt.id || mt.name;
10239
- groupNameSelect.appendChild(createElement("option", {
10240
- value: optionValue,
10241
- text: mt.displayName || mt.name,
10242
- selected: !!isSelected
10243
- }));
10244
- });
10245
- groupNameGroup.appendChild(groupNameSelect);
10246
- body.appendChild(groupNameGroup);
10247
- if (currentMasterType && (!selectedField.options || selectedField.options.length === 0)) {
10248
- let options = [];
10249
- if (currentMasterType.enumName && dropdownOptionsMap && dropdownOptionsMap[currentMasterType.enumName]) {
10250
- options = dropdownOptionsMap[currentMasterType.enumName];
10251
- } else if (currentMasterType.indexes && currentMasterType.indexes.length > 0) {
10252
- options = convertIndexesToOptions(currentMasterType.indexes);
10253
- }
10254
- if (options.length > 0) {
10255
- formStore.getState().updateField(selectedField.id, { options });
10256
- }
10257
- if (selectedField.masterTypeName && !selectedField.groupName) {
10258
- formStore.getState().updateField(selectedField.id, {
10259
- groupName: {
10260
- id: currentMasterType.id,
10261
- name: currentMasterType.name
10262
- }
10263
- });
10264
- }
10265
- }
10266
- }
10267
- }
10268
10166
  if (["select", "checkbox", "radio"].includes(selectedField.type)) {
10269
10167
  const optionSourceHeader = createElement("h3", { className: "text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3 mt-6", text: "Option Source" });
10270
10168
  body.appendChild(optionSourceHeader);
@@ -10276,12 +10174,18 @@ var FormBuilder = class {
10276
10174
  onchange: (e) => {
10277
10175
  const source = e.target.value;
10278
10176
  const updates = { optionSource: source };
10279
- if (source === "MASTER" && !selectedField.masterTypeName && !selectedField.groupName) ; else if (source === "STATIC") {
10177
+ if (source === "MASTER") ; else if (source === "STATIC") {
10280
10178
  updates.customOptionsEnabled = true;
10179
+ updates.groupName = void 0;
10180
+ updates.masterTypeName = void 0;
10181
+ updates.options = void 0;
10281
10182
  } else if (source === "LOOKUP") {
10282
10183
  if (!selectedField.lookupSourceType) {
10283
10184
  updates.lookupSourceType = "MODULE";
10284
10185
  }
10186
+ updates.groupName = void 0;
10187
+ updates.masterTypeName = void 0;
10188
+ updates.options = void 0;
10285
10189
  }
10286
10190
  formStore.getState().updateField(selectedField.id, updates);
10287
10191
  this.render();
@@ -10294,6 +10198,101 @@ var FormBuilder = class {
10294
10198
  }
10295
10199
  optionSourceGroup.appendChild(optionSourceSelect);
10296
10200
  body.appendChild(optionSourceGroup);
10201
+ if (selectedField.type === "select" && selectedField.optionSource === "MASTER") {
10202
+ const masterTypes = formStore.getState().masterTypes;
10203
+ const activeMasterTypes = masterTypes.filter((mt) => mt.active === true);
10204
+ const dropdownOptionsMap = formStore.getState().dropdownOptionsMap;
10205
+ const convertIndexesToOptions = (indexes) => {
10206
+ if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
10207
+ return [];
10208
+ }
10209
+ return indexes.map((item, index2) => {
10210
+ if (typeof item === "string") {
10211
+ return { label: item, value: item };
10212
+ }
10213
+ if (typeof item === "object" && item !== null) {
10214
+ const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
10215
+ const value = item.value || item.id || item.name || String(index2);
10216
+ return { label, value };
10217
+ }
10218
+ return { label: String(item), value: String(item) };
10219
+ });
10220
+ };
10221
+ if (activeMasterTypes.length > 0) {
10222
+ const groupNameGroup = createElement("div", { className: "mb-4" });
10223
+ groupNameGroup.appendChild(createElement("label", { className: "block text-sm font-normal text-gray-700 dark:text-gray-300 mb-1", text: "Master List" }));
10224
+ const groupNameSelect = createElement("select", {
10225
+ className: "w-full px-3 py-2 border border-gray-200 dark:border-gray-700 rounded-md bg-transparent",
10226
+ onchange: (e) => {
10227
+ const selectedEnumName = e.target.value;
10228
+ if (selectedEnumName) {
10229
+ const selectedMasterType = activeMasterTypes.find((mt) => mt.enumName === selectedEnumName);
10230
+ if (selectedMasterType) {
10231
+ let options = [];
10232
+ if (dropdownOptionsMap && dropdownOptionsMap[selectedEnumName]) {
10233
+ options = dropdownOptionsMap[selectedEnumName];
10234
+ } else if (selectedMasterType.indexes && selectedMasterType.indexes.length > 0) {
10235
+ options = convertIndexesToOptions(selectedMasterType.indexes);
10236
+ }
10237
+ formStore.getState().updateField(selectedField.id, {
10238
+ groupName: { id: selectedMasterType.id, name: selectedMasterType.name },
10239
+ masterTypeName: selectedEnumName,
10240
+ options: options.length > 0 ? options : void 0
10241
+ });
10242
+ if (this.options.onGroupSelectionChange) {
10243
+ this.options.onGroupSelectionChange({
10244
+ fieldId: selectedField.id,
10245
+ groupEnumName: selectedEnumName
10246
+ });
10247
+ }
10248
+ }
10249
+ } else {
10250
+ formStore.getState().updateField(selectedField.id, {
10251
+ groupName: void 0,
10252
+ masterTypeName: void 0,
10253
+ options: void 0
10254
+ });
10255
+ }
10256
+ }
10257
+ });
10258
+ let currentMasterType;
10259
+ if (selectedField.masterTypeName) {
10260
+ currentMasterType = activeMasterTypes.find((mt) => mt.enumName === selectedField.masterTypeName);
10261
+ } else if (selectedField.groupName) {
10262
+ currentMasterType = activeMasterTypes.find(
10263
+ (mt) => mt.id === selectedField.groupName?.id || mt.name === selectedField.groupName?.name
10264
+ );
10265
+ }
10266
+ groupNameSelect.appendChild(createElement("option", { value: "", text: "None", selected: !currentMasterType }));
10267
+ activeMasterTypes.forEach((mt) => {
10268
+ const isSelected = currentMasterType && (selectedField.masterTypeName && mt.enumName === selectedField.masterTypeName || selectedField.groupName && (mt.id === selectedField.groupName?.id || mt.name === selectedField.groupName?.name));
10269
+ const optionValue = mt.enumName || mt.id || mt.name;
10270
+ groupNameSelect.appendChild(createElement("option", {
10271
+ value: optionValue,
10272
+ text: mt.displayName || mt.name,
10273
+ selected: !!isSelected
10274
+ }));
10275
+ });
10276
+ groupNameGroup.appendChild(groupNameSelect);
10277
+ body.appendChild(groupNameGroup);
10278
+ if (currentMasterType && (!selectedField.options || selectedField.options.length === 0)) {
10279
+ let options = [];
10280
+ if (currentMasterType.enumName && dropdownOptionsMap && dropdownOptionsMap[currentMasterType.enumName]) {
10281
+ options = dropdownOptionsMap[currentMasterType.enumName];
10282
+ } else if (currentMasterType.indexes && currentMasterType.indexes.length > 0) {
10283
+ options = convertIndexesToOptions(currentMasterType.indexes);
10284
+ }
10285
+ if (options.length > 0) {
10286
+ formStore.getState().updateField(selectedField.id, { options });
10287
+ }
10288
+ if (selectedField.masterTypeName && !selectedField.groupName) {
10289
+ formStore.getState().updateField(selectedField.id, {
10290
+ groupName: { id: currentMasterType.id, name: currentMasterType.name }
10291
+ });
10292
+ }
10293
+ }
10294
+ }
10295
+ }
10297
10296
  if (selectedField.type === "select" && selectedField.optionSource === "LOOKUP") {
10298
10297
  const lookupSourceTypeGroup = createElement("div", { className: "mb-4" });
10299
10298
  lookupSourceTypeGroup.appendChild(createElement("label", { className: "block text-sm font-normal text-gray-700 dark:text-gray-300 mb-1", text: "Lookup Source Type" }));