form-builder-pro 1.0.15 → 1.0.17

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.d.mts CHANGED
@@ -186,11 +186,6 @@ declare class FormBuilder {
186
186
  private container;
187
187
  private unsubscribe;
188
188
  private options;
189
- private requestedMasterTypesCache;
190
- private isTriggeringApiCalls;
191
- private previewRenderer;
192
- private lastPreviewSchema;
193
- private wasInPreviewMode;
194
189
  constructor(container: HTMLElement, options?: FormBuilderOptions);
195
190
  loadForm(json: FormSchema): void;
196
191
  cloneForm(json: FormSchema): void;
package/dist/index.d.ts CHANGED
@@ -186,11 +186,6 @@ declare class FormBuilder {
186
186
  private container;
187
187
  private unsubscribe;
188
188
  private options;
189
- private requestedMasterTypesCache;
190
- private isTriggeringApiCalls;
191
- private previewRenderer;
192
- private lastPreviewSchema;
193
- private wasInPreviewMode;
194
189
  constructor(container: HTMLElement, options?: FormBuilderOptions);
195
190
  loadForm(json: FormSchema): void;
196
191
  cloneForm(json: FormSchema): void;
package/dist/index.js CHANGED
@@ -7566,20 +7566,10 @@ var SectionList = class {
7566
7566
 
7567
7567
  // src/builder/FormBuilder.ts
7568
7568
  var FormBuilder = class {
7569
- // Track previous preview state to detect mode changes
7570
7569
  constructor(container, options = {}) {
7571
7570
  __publicField(this, "container");
7572
7571
  __publicField(this, "unsubscribe");
7573
7572
  __publicField(this, "options");
7574
- __publicField(this, "requestedMasterTypesCache", /* @__PURE__ */ new Set());
7575
- // Cache to track requested master types
7576
- __publicField(this, "isTriggeringApiCalls", false);
7577
- // Flag to prevent concurrent API triggers
7578
- __publicField(this, "previewRenderer", null);
7579
- // Store FormRenderer instance to preserve selections
7580
- __publicField(this, "lastPreviewSchema", null);
7581
- // Track last preview schema to detect changes
7582
- __publicField(this, "wasInPreviewMode", false);
7583
7573
  __publicField(this, "activeTab", "fields");
7584
7574
  if (!container) {
7585
7575
  throw new Error("Builder container not found. Please ensure the container element exists before initializing FormBuilder.");
@@ -7660,9 +7650,6 @@ var FormBuilder = class {
7660
7650
  }
7661
7651
  updateDropdownOptionsMap(dropdownOptionsMap) {
7662
7652
  formStore.getState().setDropdownOptionsMap(dropdownOptionsMap);
7663
- Object.keys(dropdownOptionsMap).forEach((groupEnumName) => {
7664
- if (dropdownOptionsMap[groupEnumName] && dropdownOptionsMap[groupEnumName].length > 0) ;
7665
- });
7666
7653
  this.render();
7667
7654
  }
7668
7655
  updateMasterTypeGroups(masterTypeGroups) {
@@ -7714,162 +7701,110 @@ var FormBuilder = class {
7714
7701
  };
7715
7702
  }
7716
7703
  }
7704
+ const canvasWrapper = this.container.querySelector(".form-builder-canvas");
7705
+ const previewContainer = this.container.querySelector(".flex-1.overflow-y-auto.bg-white");
7706
+ const scrollContainer = canvasWrapper || previewContainer;
7707
+ const savedScrollTop = scrollContainer ? scrollContainer.scrollTop : 0;
7717
7708
  this.container.innerHTML = "";
7718
7709
  const wrapper = createElement("div", { className: "flex flex-col h-screen " });
7719
7710
  wrapper.appendChild(this.renderToolbar(state));
7720
7711
  const main = createElement("div", { className: "flex flex-col md:flex-row flex-1 overflow-hidden" });
7721
7712
  if (state.isPreviewMode) {
7722
- const masterTypes = state.masterTypes || [];
7713
+ const masterTypes = state.masterTypes;
7723
7714
  const dropdownOptionsMap = state.dropdownOptionsMap;
7724
- if (state.schema.sections) {
7725
- let previewSchema = state.schema;
7726
- if (masterTypes && masterTypes.length > 0) {
7727
- const convertIndexesToOptions = (indexes) => {
7728
- if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
7729
- return [];
7715
+ if (masterTypes && masterTypes.length > 0 && state.schema.sections) {
7716
+ const convertIndexesToOptions = (indexes) => {
7717
+ if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
7718
+ return [];
7719
+ }
7720
+ return indexes.map((item, index2) => {
7721
+ if (typeof item === "string") {
7722
+ return { label: item, value: item };
7730
7723
  }
7731
- return indexes.map((item, index2) => {
7732
- if (typeof item === "string") {
7733
- return { label: item, value: item };
7734
- }
7735
- if (typeof item === "object" && item !== null) {
7736
- const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
7737
- const value = item.value || item.id || item.name || String(index2);
7738
- return { label, value };
7739
- }
7740
- return { label: String(item), value: String(item) };
7741
- });
7742
- };
7743
- const areDefaultOptions = (options) => {
7744
- if (!options || options.length === 0)
7745
- return true;
7746
- return options.every(
7747
- (opt, idx) => opt.label === `Option ${idx + 1}` && (opt.value === `opt${idx + 1}` || opt.value === `Option ${idx + 1}`)
7748
- );
7749
- };
7750
- const fieldsNeedingApiCall = [];
7751
- previewSchema = {
7752
- ...state.schema,
7753
- sections: state.schema.sections.map((section) => ({
7754
- ...section,
7755
- fields: section.fields.map((field) => {
7756
- if (field.type === "select") {
7757
- let masterType;
7758
- if (field.masterTypeName) {
7759
- masterType = masterTypes.find(
7760
- (mt) => mt.active === true && mt.enumName === field.masterTypeName
7761
- );
7762
- if (masterType && masterType.enumName) {
7763
- const hasOptionsInMap = dropdownOptionsMap && dropdownOptionsMap[masterType.enumName] && dropdownOptionsMap[masterType.enumName].length > 0;
7764
- const hasOptionsInIndexes = masterType.indexes && masterType.indexes.length > 0;
7765
- const alreadyRequested = this.requestedMasterTypesCache.has(masterType.enumName);
7766
- if (!hasOptionsInMap && !hasOptionsInIndexes && !alreadyRequested) {
7767
- this.requestedMasterTypesCache.add(masterType.enumName);
7768
- fieldsNeedingApiCall.push({
7769
- fieldId: field.id,
7770
- groupEnumName: masterType.enumName
7771
- });
7772
- }
7773
- }
7774
- } else if (field.groupName) {
7775
- masterType = masterTypes.find(
7776
- (mt) => mt.active === true && (mt.id === field.groupName?.id || mt.name === field.groupName?.name)
7777
- );
7724
+ if (typeof item === "object" && item !== null) {
7725
+ const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
7726
+ const value = item.value || item.id || item.name || String(index2);
7727
+ return { label, value };
7728
+ }
7729
+ return { label: String(item), value: String(item) };
7730
+ });
7731
+ };
7732
+ const areDefaultOptions = (options) => {
7733
+ if (!options || options.length === 0)
7734
+ return true;
7735
+ return options.every(
7736
+ (opt, idx) => opt.label === `Option ${idx + 1}` && (opt.value === `opt${idx + 1}` || opt.value === `Option ${idx + 1}`)
7737
+ );
7738
+ };
7739
+ const previewSchema = {
7740
+ ...state.schema,
7741
+ sections: state.schema.sections.map((section) => ({
7742
+ ...section,
7743
+ fields: section.fields.map((field) => {
7744
+ if (field.type === "select") {
7745
+ let masterType;
7746
+ if (field.masterTypeName) {
7747
+ masterType = masterTypes.find(
7748
+ (mt) => mt.active === true && mt.enumName === field.masterTypeName
7749
+ );
7750
+ } else if (field.groupName) {
7751
+ masterType = masterTypes.find(
7752
+ (mt) => mt.active === true && (mt.id === field.groupName?.id || mt.name === field.groupName?.name)
7753
+ );
7754
+ }
7755
+ if (masterType) {
7756
+ let options = [];
7757
+ if (masterType.enumName && dropdownOptionsMap && dropdownOptionsMap[masterType.enumName]) {
7758
+ options = dropdownOptionsMap[masterType.enumName];
7759
+ } else if (masterType.indexes && masterType.indexes.length > 0) {
7760
+ options = convertIndexesToOptions(masterType.indexes);
7778
7761
  }
7779
- if (masterType) {
7780
- let options = [];
7781
- if (masterType.enumName && dropdownOptionsMap && dropdownOptionsMap[masterType.enumName]) {
7782
- options = dropdownOptionsMap[masterType.enumName];
7783
- } else if (masterType.indexes && masterType.indexes.length > 0) {
7784
- options = convertIndexesToOptions(masterType.indexes);
7785
- }
7786
- if (options.length > 0) {
7787
- if (field.masterTypeName || !field.options || field.options.length === 0 || areDefaultOptions(field.options)) {
7788
- return { ...field, options };
7789
- }
7762
+ if (options.length > 0) {
7763
+ if (field.masterTypeName || !field.options || field.options.length === 0 || areDefaultOptions(field.options)) {
7764
+ return { ...field, options };
7790
7765
  }
7791
7766
  }
7792
7767
  }
7793
- return field;
7794
- })
7795
- }))
7796
- };
7797
- if (fieldsNeedingApiCall.length > 0 && this.options.onGroupSelectionChange && !this.isTriggeringApiCalls) {
7798
- this.isTriggeringApiCalls = true;
7799
- setTimeout(() => {
7800
- const uniqueApiCalls = /* @__PURE__ */ new Map();
7801
- fieldsNeedingApiCall.forEach(({ fieldId, groupEnumName }) => {
7802
- if (!uniqueApiCalls.has(groupEnumName)) {
7803
- uniqueApiCalls.set(groupEnumName, []);
7804
- }
7805
- uniqueApiCalls.get(groupEnumName).push(fieldId);
7806
- });
7807
- uniqueApiCalls.forEach((fieldIds, groupEnumName) => {
7808
- if (process.env.NODE_ENV === "development") {
7809
- console.log(`[FormBuilder] Preview: Triggering API call for masterTypeName "${groupEnumName}" (affects ${fieldIds.length} field(s))`);
7810
- }
7811
- this.options.onGroupSelectionChange({
7812
- fieldId: fieldIds[0],
7813
- groupEnumName
7814
- });
7815
- });
7816
- setTimeout(() => {
7817
- this.isTriggeringApiCalls = false;
7818
- }, 100);
7819
- }, 0);
7820
- }
7821
- }
7822
- const previewContainer = createElement("div", { className: "flex-1 p-8 overflow-y-auto bg-white dark:bg-gray-900 flex justify-center" });
7768
+ }
7769
+ return field;
7770
+ })
7771
+ }))
7772
+ };
7773
+ const previewContainer2 = createElement("div", { className: "flex-1 p-8 overflow-y-auto bg-white dark:bg-gray-900 flex justify-center" });
7823
7774
  const inner = createElement("div", { className: "w-full max-w-3xl" });
7824
- const structureChanged = !this.lastPreviewSchema || this.lastPreviewSchema.id !== previewSchema.id || this.lastPreviewSchema.sections.length !== previewSchema.sections.length || JSON.stringify(this.lastPreviewSchema.sections.map((s) => ({ id: s.id, fields: s.fields.map((f) => ({ id: f.id, type: f.type })) }))) !== JSON.stringify(previewSchema.sections.map((s) => ({ id: s.id, fields: s.fields.map((f) => ({ id: f.id, type: f.type })) })));
7825
- if (!this.previewRenderer || structureChanged) {
7826
- if (this.previewRenderer) {
7827
- inner.innerHTML = "";
7828
- }
7829
- this.previewRenderer = new FormRenderer(inner, previewSchema, (data) => alert(JSON.stringify(data, null, 2)), this.options.onDropdownValueChange);
7830
- this.lastPreviewSchema = previewSchema;
7831
- } else {
7832
- if (this.lastPreviewSchema) {
7833
- const optionsChanged = JSON.stringify(this.lastPreviewSchema.sections.flatMap((s) => s.fields.map((f) => f.options))) !== JSON.stringify(previewSchema.sections.flatMap((s) => s.fields.map((f) => f.options)));
7834
- if (optionsChanged && this.previewRenderer) {
7835
- this.previewRenderer.setSchema(previewSchema);
7836
- this.lastPreviewSchema = previewSchema;
7837
- }
7838
- }
7839
- }
7840
- previewContainer.appendChild(inner);
7841
- main.appendChild(previewContainer);
7775
+ new FormRenderer(inner, previewSchema, (data) => alert(JSON.stringify(data, null, 2)), this.options.onDropdownValueChange);
7776
+ previewContainer2.appendChild(inner);
7777
+ main.appendChild(previewContainer2);
7842
7778
  } else {
7843
- const previewContainer = createElement("div", { className: "flex-1 p-8 overflow-y-auto bg-white dark:bg-gray-900 flex justify-center" });
7779
+ const previewContainer2 = createElement("div", { className: "flex-1 p-8 overflow-y-auto bg-white dark:bg-gray-900 flex justify-center" });
7844
7780
  const inner = createElement("div", { className: "w-full max-w-3xl" });
7845
- if (!this.previewRenderer) {
7846
- this.previewRenderer = new FormRenderer(inner, state.schema, (data) => alert(JSON.stringify(data, null, 2)), this.options.onDropdownValueChange);
7847
- this.lastPreviewSchema = state.schema;
7848
- } else {
7849
- this.previewRenderer.setSchema(state.schema);
7850
- this.lastPreviewSchema = state.schema;
7851
- }
7852
- previewContainer.appendChild(inner);
7853
- main.appendChild(previewContainer);
7781
+ new FormRenderer(inner, state.schema, (data) => alert(JSON.stringify(data, null, 2)), this.options.onDropdownValueChange);
7782
+ previewContainer2.appendChild(inner);
7783
+ main.appendChild(previewContainer2);
7854
7784
  }
7855
7785
  } else {
7856
- if (this.wasInPreviewMode) {
7857
- this.previewRenderer = null;
7858
- this.lastPreviewSchema = null;
7859
- }
7860
- this.wasInPreviewMode = false;
7861
7786
  const toolboxWrapper = createElement("div", { className: "form-builder-toolbox-wrapper w-full md:w-80 bg-white dark:bg-gray-900 border-r md:border-r border-b md:border-b-0 border-gray-200 dark:border-gray-800" });
7862
7787
  toolboxWrapper.appendChild(this.renderToolbox());
7863
7788
  main.appendChild(toolboxWrapper);
7864
- const canvasWrapper = createElement("div", { className: "form-builder-canvas flex-1 overflow-y-auto" });
7865
- canvasWrapper.appendChild(this.renderCanvas(state));
7866
- main.appendChild(canvasWrapper);
7789
+ const canvasWrapper2 = createElement("div", { className: "form-builder-canvas flex-1 overflow-y-auto" });
7790
+ canvasWrapper2.appendChild(this.renderCanvas(state));
7791
+ main.appendChild(canvasWrapper2);
7867
7792
  const configWrapper = createElement("div", { className: "form-builder-config-wrapper w-full md:w-80 bg-white dark:bg-gray-900 border-l md:border-l border-t md:border-t-0 border-gray-200 dark:border-gray-800" });
7868
7793
  configWrapper.appendChild(this.renderConfigPanel(state));
7869
7794
  main.appendChild(configWrapper);
7870
7795
  }
7871
7796
  wrapper.appendChild(main);
7872
7797
  this.container.appendChild(wrapper);
7798
+ if (savedScrollTop > 0) {
7799
+ requestAnimationFrame(() => {
7800
+ const newCanvasWrapper = this.container.querySelector(".form-builder-canvas");
7801
+ const newPreviewContainer = this.container.querySelector(".flex-1.overflow-y-auto.bg-white");
7802
+ const newScrollContainer = newCanvasWrapper || newPreviewContainer;
7803
+ if (newScrollContainer) {
7804
+ newScrollContainer.scrollTop = savedScrollTop;
7805
+ }
7806
+ });
7807
+ }
7873
7808
  if (focusState) {
7874
7809
  setTimeout(() => {
7875
7810
  const elementToFocus = document.querySelector(`[data-focus-id="${focusState.id}"]`);