form-builder-pro 0.0.6 → 0.0.8

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
@@ -4448,6 +4448,11 @@ var ICONS = {
4448
4448
  "Undo": '<path stroke-linecap="round" stroke-linejoin="round" d="M9 15L3 9m0 0l6-6M3 9h12a6 6 0 010 12h-3" />',
4449
4449
  "Redo": '<path stroke-linecap="round" stroke-linejoin="round" d="M15 15l6-6m0 0l-6-6m6 6H9a6 6 0 000 12h3" />',
4450
4450
  "X": '<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />',
4451
+ "User": '<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 6a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0zM4.501 20.118a7.5 7.5 0 0114.998 0A17.933 17.933 0 0112 21.75c-2.676 0-5.216-.584-7.499-1.632z" />',
4452
+ "Lock": '<path stroke-linecap="round" stroke-linejoin="round" d="M16.5 10.5V6.75a4.5 4.5 0 10-9 0v3.75m-.75 11.25h10.5a2.25 2.25 0 002.25-2.25v-6.75a2.25 2.25 0 00-2.25-2.25H6.75a2.25 2.25 0 00-2.25 2.25v6.75a2.25 2.25 0 002.25 2.25z" />',
4453
+ "CreditCard": '<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 8.25h19.5M2.25 9h19.5m-16.5 5.25h6m-6 2.25h3m-3.75 3h15a2.25 2.25 0 002.25-2.25V6.75A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25v10.5A2.25 2.25 0 004.5 19.5z" />',
4454
+ "MapPin": '<path stroke-linecap="round" stroke-linejoin="round" d="M15 10.5a3 3 0 11-6 0 3 3 0 016 0z" /><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25S4.5 17.642 4.5 10.5a7.5 7.5 0 1115 0z" />',
4455
+ "Briefcase": '<path stroke-linecap="round" stroke-linejoin="round" d="M20.25 14.15v4.25c0 1.094-.787 2.036-1.872 2.18-2.087.277-4.216.42-6.378.42s-4.291-.143-6.378-.42c-1.085-.144-1.872-1.086-1.872-2.18v-4.25m16.5 0a2.18 2.18 0 00.75-1.661V8.706c0-1.081-.768-2.015-1.837-2.175a48.114 48.114 0 00-3.413-.387m4.5 8.006c-.194.165-.42.295-.67.38-1.053.33-2.177.58-3.345.726-.26.032-.52.05-.778.066m-13.882-6.626h.008v.008h-.008v-.008zm1.096-3.837a48.116 48.116 0 00-3.413.387c-1.069.16-1.837 1.094-1.837 2.175v4.784c0 .493.196.958.536 1.344m0 0a17.8 17.8 0 013.344.726c.25.085.476.215.67.38m13.784-5.32c-.34-.386-.536-.851-.536-1.344v-4.784c0-1.081-.768-2.015-1.837-2.175a48.041 48.041 0 01-3.413-.387m-4.5 8.006c.194.165.42.295.67.38 1.053.33 2.177.58 3.345.726.26.032.52.05.778.066m0-7.384V5.626a2.25 2.25 0 00-2.25-2.25h-4.5a2.25 2.25 0 00-2.25 2.25v2.247M16.5 6h-9" />',
4451
4456
  "Eye": '<path stroke-linecap="round" stroke-linejoin="round" d="M2.036 12.322a1.012 1.012 0 010-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178z" /><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />'
4452
4457
  };
4453
4458
  function getIcon(name, size = 20) {
@@ -6879,6 +6884,9 @@ var FormBuilder = class {
6879
6884
  __publicField(this, "unsubscribe");
6880
6885
  __publicField(this, "options");
6881
6886
  __publicField(this, "activeTab", "fields");
6887
+ if (!container) {
6888
+ throw new Error("Builder container not found. Please ensure the container element exists before initializing FormBuilder.");
6889
+ }
6882
6890
  this.container = container;
6883
6891
  this.options = options;
6884
6892
  if (options.existingForms) {
@@ -6915,6 +6923,10 @@ var FormBuilder = class {
6915
6923
  applyTemplate(template) {
6916
6924
  this.importSection(template);
6917
6925
  }
6926
+ updateExistingForms(forms) {
6927
+ formStore.getState().setExistingForms(forms);
6928
+ this.render();
6929
+ }
6918
6930
  setupSubscriptions() {
6919
6931
  this.unsubscribe = formStore.subscribe(() => {
6920
6932
  this.render();
@@ -7084,15 +7096,28 @@ var FormBuilder = class {
7084
7096
  if (templates.length === 0) {
7085
7097
  content.appendChild(createElement("div", { className: "text-sm text-gray-500 text-center mt-4", text: "No templates saved." }));
7086
7098
  } else {
7099
+ const templatesList = createElement("div", { id: "templates-list", className: "space-y-3" });
7087
7100
  templates.forEach((t) => {
7088
7101
  const item = createElement("div", {
7089
- className: "p-3 mb-2 bg-gray-50 dark:bg-gray-800 border rounded cursor-pointer hover:border-blue-500",
7090
- onclick: () => this.applyTemplate(t)
7102
+ className: "p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg cursor-move hover:border-blue-500 hover:shadow-sm transition-all template-item",
7103
+ "data-template-id": t.id,
7104
+ "data-type": "template-section"
7091
7105
  });
7092
- item.appendChild(createElement("div", { className: "font-medium text-sm", text: t.title }));
7093
- item.appendChild(createElement("div", { className: "text-xs text-gray-500", text: `${t.fields.length} fields` }));
7094
- content.appendChild(item);
7106
+ item.appendChild(createElement("div", {
7107
+ className: "font-semibold text-sm text-gray-800 dark:text-gray-200 mb-1 flex items-center gap-2"
7108
+ }, [
7109
+ getIcon("DocumentText", 16),
7110
+ // Small icon
7111
+ createElement("span", { text: t.title })
7112
+ ]));
7113
+ const fieldNames = t.fields.map((f) => f.label).join(", ");
7114
+ item.appendChild(createElement("div", {
7115
+ className: "text-xs text-gray-500 truncate",
7116
+ text: `Fields: ${fieldNames}`
7117
+ }));
7118
+ templatesList.appendChild(item);
7095
7119
  });
7120
+ content.appendChild(templatesList);
7096
7121
  }
7097
7122
  } else if (this.activeTab === "import") {
7098
7123
  const existingForms = formStore.getState().existingForms;
@@ -7151,7 +7176,11 @@ var FormBuilder = class {
7151
7176
  oninput: (e) => formStore.getState().setSchema({ ...state.schema, formName: e.target.value })
7152
7177
  });
7153
7178
  inner.appendChild(formNameInput);
7154
- const sectionsContainer = createElement("div", { className: "space-y-6 min-h-[200px]", id: "sections-list" });
7179
+ const sectionsContainer = createElement("div", {
7180
+ className: "space-y-6 min-h-[200px]",
7181
+ id: "sections-list",
7182
+ "data-drop-zone": "sections"
7183
+ });
7155
7184
  state.schema.sections.forEach((section) => {
7156
7185
  const sectionEl = createElement("div", {
7157
7186
  className: "mb-6 rounded-lg border bg-white dark:bg-gray-900 shadow-sm transition-all border-gray-200 dark:border-gray-800",
@@ -7439,13 +7468,45 @@ var FormBuilder = class {
7439
7468
  animation: 150
7440
7469
  });
7441
7470
  }
7471
+ const templatesList = document.getElementById("templates-list");
7472
+ if (templatesList) {
7473
+ new sortable_esm_default(templatesList, {
7474
+ group: {
7475
+ name: "shared",
7476
+ pull: "clone",
7477
+ put: false
7478
+ },
7479
+ sort: false,
7480
+ animation: 150,
7481
+ draggable: ".template-item",
7482
+ forceFallback: true
7483
+ });
7484
+ }
7442
7485
  const sectionsList = document.getElementById("sections-list");
7443
7486
  if (sectionsList) {
7444
7487
  new sortable_esm_default(sectionsList, {
7488
+ group: "shared",
7445
7489
  handle: ".section-handle",
7446
7490
  animation: 150,
7491
+ onAdd: (evt) => {
7492
+ const item = evt.item;
7493
+ const templateId = item.getAttribute("data-template-id");
7494
+ const isTemplate = item.getAttribute("data-type") === "template-section";
7495
+ if (templateId && isTemplate) {
7496
+ const templates = formStore.getState().templates;
7497
+ const template = templates.find((t) => t.id === templateId);
7498
+ if (template) {
7499
+ item.remove();
7500
+ formStore.getState().importSection(template);
7501
+ return;
7502
+ }
7503
+ }
7504
+ },
7447
7505
  onEnd: (evt) => {
7448
- if (evt.oldIndex !== void 0 && evt.newIndex !== void 0) {
7506
+ const item = evt.item;
7507
+ const templateId = item.getAttribute("data-template-id");
7508
+ const isTemplate = item.getAttribute("data-type") === "template-section";
7509
+ if (!templateId && !isTemplate && evt.oldIndex !== void 0 && evt.newIndex !== void 0 && evt.oldIndex !== evt.newIndex) {
7449
7510
  formStore.getState().moveSection(evt.oldIndex, evt.newIndex);
7450
7511
  }
7451
7512
  }