@ohhwells/bridge 0.1.65-next.183 → 0.1.65-next.185

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.js CHANGED
@@ -6895,14 +6895,23 @@ function setFormViewState(form, formKey, state, initialText) {
6895
6895
  success.style.display = state === "success" ? "" : "none";
6896
6896
  }
6897
6897
  var BOUND_ATTR = "data-ohw-form-bound";
6898
+ var publishedFormContext = {
6899
+ apiUrl: "",
6900
+ subdomain: "",
6901
+ content: {}
6902
+ };
6898
6903
  function bindPublishedForms(apiUrl, subdomain, content = {}) {
6899
- document.querySelectorAll(FORM_SELECTOR).forEach((form) => {
6900
- if (form.hasAttribute(BOUND_ATTR)) return;
6901
- if (!(form instanceof HTMLFormElement)) return;
6902
- const formKey = formKeyOf(form);
6903
- if (!formKey) return;
6904
- form.setAttribute(BOUND_ATTR, "");
6905
- form.addEventListener("submit", async (e) => {
6904
+ publishedFormContext = { apiUrl, subdomain, content };
6905
+ if (document.documentElement.hasAttribute(BOUND_ATTR)) return;
6906
+ document.documentElement.setAttribute(BOUND_ATTR, "");
6907
+ document.addEventListener(
6908
+ "submit",
6909
+ async (e) => {
6910
+ const target = e.target;
6911
+ const form = target?.closest(FORM_SELECTOR);
6912
+ if (!form || !(form instanceof HTMLFormElement)) return;
6913
+ const formKey = formKeyOf(form);
6914
+ if (!formKey) return;
6906
6915
  e.preventDefault();
6907
6916
  clearSubmitError(form);
6908
6917
  const submitButton = form.querySelector(
@@ -6910,7 +6919,8 @@ function bindPublishedForms(apiUrl, subdomain, content = {}) {
6910
6919
  );
6911
6920
  if (submitButton) submitButton.disabled = true;
6912
6921
  try {
6913
- const response = await fetch(`${apiUrl}/api/public/sites/${subdomain}/forms/submissions`, {
6922
+ const { apiUrl: api, subdomain: site, content: latest } = publishedFormContext;
6923
+ const response = await fetch(`${api}/api/public/sites/${site}/forms/submissions`, {
6914
6924
  method: "POST",
6915
6925
  headers: { "Content-Type": "application/json" },
6916
6926
  body: JSON.stringify({
@@ -6920,13 +6930,14 @@ function bindPublishedForms(apiUrl, subdomain, content = {}) {
6920
6930
  })
6921
6931
  });
6922
6932
  if (!response.ok) throw new Error(`submit failed: ${response.status}`);
6923
- showSuccess(form, content[formSuccessKey(formKey)]);
6933
+ showSuccess(form, latest[formSuccessKey(formKey)]);
6924
6934
  } catch {
6925
6935
  showSubmitError(form);
6926
6936
  if (submitButton) submitButton.disabled = false;
6927
6937
  }
6928
- });
6929
- });
6938
+ },
6939
+ true
6940
+ );
6930
6941
  }
6931
6942
 
6932
6943
  // src/lib/form-fields.ts
@@ -13342,8 +13353,10 @@ function getLinkHref3(el) {
13342
13353
  }
13343
13354
  function collectEditableNodes(extraContent, root = document) {
13344
13355
  const isScoped = root !== document;
13345
- const editableEls = Array.from(root.querySelectorAll("[data-ohw-editable]"));
13346
- if (isScoped && root instanceof HTMLElement && root.matches("[data-ohw-editable]")) {
13356
+ const editableEls = Array.from(
13357
+ root.querySelectorAll('[data-ohw-editable]:not([data-ohw-editable="form"])')
13358
+ );
13359
+ if (isScoped && root instanceof HTMLElement && root.matches('[data-ohw-editable]:not([data-ohw-editable="form"])')) {
13347
13360
  editableEls.unshift(root);
13348
13361
  }
13349
13362
  const nodes = editableEls.map((el) => {
@@ -16844,6 +16857,9 @@ function OhhwellsBridge() {
16844
16857
  reconcileSocialsFromContent(content);
16845
16858
  applySocialsDisplayFromContent(content);
16846
16859
  document.querySelectorAll('[data-ohw-editable="form"]').forEach((form) => {
16860
+ if (!form.querySelector("[data-ohw-form-success]")) {
16861
+ reconcileFieldsFromContent(form, content);
16862
+ }
16847
16863
  listFieldWrappers(form).forEach(syncRequiredMark);
16848
16864
  });
16849
16865
  } finally {