form-builder-pro 0.0.2 → 0.0.3

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
@@ -4469,7 +4469,7 @@ var FormRenderer = class {
4469
4469
  this.schema.sections.forEach((section) => {
4470
4470
  const sectionEl = createElement("div", { className: "space-y-4" });
4471
4471
  sectionEl.appendChild(createElement("h2", { className: "text-xl font-semibold text-gray-800 dark:text-gray-200 border-b pb-2", text: section.title }));
4472
- const grid = createElement("div", { className: "grid grid-cols-4 gap-4" });
4472
+ const grid = createElement("div", { className: "form-builder-grid" });
4473
4473
  section.fields.forEach((field) => {
4474
4474
  const fieldWrapper = createElement("div");
4475
4475
  const span = field.width === "100%" ? "col-span-4" : field.width === "50%" ? "col-span-2" : "col-span-1";
@@ -25148,10 +25148,12 @@ var createIcons = ({
25148
25148
 
25149
25149
  // src/builder/FormBuilder.ts
25150
25150
  var FormBuilder = class {
25151
- constructor(container) {
25151
+ constructor(container, options) {
25152
25152
  __publicField(this, "container");
25153
25153
  __publicField(this, "unsubscribe");
25154
+ __publicField(this, "onSave");
25154
25155
  this.container = container;
25156
+ this.onSave = options?.onSave;
25155
25157
  this.render();
25156
25158
  this.setupSubscriptions();
25157
25159
  }
@@ -25166,6 +25168,18 @@ var FormBuilder = class {
25166
25168
  }
25167
25169
  render() {
25168
25170
  const state = formStore.getState();
25171
+ const activeElement = document.activeElement;
25172
+ let focusState = null;
25173
+ if (activeElement && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA")) {
25174
+ const focusId = activeElement.getAttribute("data-focus-id");
25175
+ if (focusId) {
25176
+ focusState = {
25177
+ id: focusId,
25178
+ selectionStart: activeElement.selectionStart,
25179
+ selectionEnd: activeElement.selectionEnd
25180
+ };
25181
+ }
25182
+ }
25169
25183
  this.container.innerHTML = "";
25170
25184
  const wrapper = createElement("div", { className: "flex flex-col h-screen bg-gray-100 dark:bg-gray-950" });
25171
25185
  wrapper.appendChild(this.renderToolbar(state));
@@ -25183,6 +25197,17 @@ var FormBuilder = class {
25183
25197
  }
25184
25198
  wrapper.appendChild(main);
25185
25199
  this.container.appendChild(wrapper);
25200
+ if (focusState) {
25201
+ setTimeout(() => {
25202
+ const elementToFocus = document.querySelector(`[data-focus-id="${focusState.id}"]`);
25203
+ if (elementToFocus) {
25204
+ elementToFocus.focus();
25205
+ if (focusState.selectionStart !== null && focusState.selectionEnd !== null) {
25206
+ elementToFocus.setSelectionRange(focusState.selectionStart, focusState.selectionEnd);
25207
+ }
25208
+ }
25209
+ }, 0);
25210
+ }
25186
25211
  createIcons({ icons: iconsAndAliases_exports });
25187
25212
  if (!state.isPreviewMode) {
25188
25213
  this.initSortable();
@@ -25223,8 +25248,11 @@ var FormBuilder = class {
25223
25248
  const saveBtn = createElement("button", {
25224
25249
  className: "flex items-center px-4 py-2 text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-md shadow-sm transition-colors",
25225
25250
  onclick: () => {
25226
- console.log(formStore.getState().schema);
25227
- alert("Schema saved to console");
25251
+ const schema = formStore.getState().schema;
25252
+ console.log("Schema saved:", schema);
25253
+ if (this.onSave) {
25254
+ this.onSave(schema);
25255
+ }
25228
25256
  }
25229
25257
  }, [getIcon("Save", 16), createElement("span", { className: "ml-2", text: "Save" })]);
25230
25258
  right.appendChild(clearBtn);
@@ -25263,6 +25291,7 @@ var FormBuilder = class {
25263
25291
  className: "text-3xl font-bold text-center bg-transparent border-none focus:outline-none focus:ring-0 w-full text-gray-900 dark:text-white mb-8",
25264
25292
  value: state.schema.title,
25265
25293
  placeholder: "Form Title",
25294
+ "data-focus-id": "form-title",
25266
25295
  oninput: (e) => formStore.getState().setSchema({ ...state.schema, title: e.target.value })
25267
25296
  });
25268
25297
  inner.appendChild(titleInput);
@@ -25278,6 +25307,7 @@ var FormBuilder = class {
25278
25307
  headerLeft.appendChild(createElement("input", {
25279
25308
  className: "bg-transparent font-semibold text-gray-700 dark:text-gray-200 focus:outline-none focus:border-b border-blue-500",
25280
25309
  value: section.title,
25310
+ "data-focus-id": `section-title-${section.id}`,
25281
25311
  oninput: (e) => formStore.getState().updateSection(section.id, { title: e.target.value })
25282
25312
  }));
25283
25313
  header.appendChild(headerLeft);
@@ -25287,14 +25317,14 @@ var FormBuilder = class {
25287
25317
  }, [getIcon("Trash2", 18)]));
25288
25318
  sectionEl.appendChild(header);
25289
25319
  const fieldsGrid = createElement("div", {
25290
- className: "p-4 min-h-[100px] grid grid-cols-4 gap-4 fields-list",
25320
+ className: "form-builder-grid p-4 min-h-[100px] fields-list",
25291
25321
  "data-section-id": section.id
25292
25322
  });
25293
25323
  section.fields.forEach((field) => {
25294
25324
  const isSelected = state.selectedFieldId === field.id;
25295
25325
  const span = field.width === "100%" ? "col-span-4" : field.width === "50%" ? "col-span-2" : "col-span-1";
25296
25326
  const fieldWrapper = createElement("div", {
25297
- className: `relative group rounded-lg border-2 transition-all bg-white dark:bg-gray-800 ${isSelected ? "border-blue-500 ring-2 ring-blue-200" : "border-transparent hover:border-gray-300 dark:hover:border-gray-600"} ${span}`,
25327
+ className: `form-builder-field-wrapper ${isSelected ? "selected" : ""} ${span}`,
25298
25328
  "data-id": field.id,
25299
25329
  onclick: (e) => {
25300
25330
  e.stopPropagation();
@@ -25348,6 +25378,7 @@ var FormBuilder = class {
25348
25378
  labelGroup.appendChild(createElement("input", {
25349
25379
  className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent",
25350
25380
  value: selectedField.label,
25381
+ "data-focus-id": `field-label-${selectedField.id}`,
25351
25382
  oninput: (e) => formStore.getState().updateField(selectedField.id, { label: e.target.value })
25352
25383
  }));
25353
25384
  body.appendChild(labelGroup);
@@ -25356,6 +25387,7 @@ var FormBuilder = class {
25356
25387
  placeholderGroup.appendChild(createElement("input", {
25357
25388
  className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent",
25358
25389
  value: selectedField.placeholder || "",
25390
+ "data-focus-id": `field-placeholder-${selectedField.id}`,
25359
25391
  oninput: (e) => formStore.getState().updateField(selectedField.id, { placeholder: e.target.value })
25360
25392
  }));
25361
25393
  body.appendChild(placeholderGroup);