@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.cjs CHANGED
@@ -6969,14 +6969,23 @@ function setFormViewState(form, formKey, state, initialText) {
6969
6969
  success.style.display = state === "success" ? "" : "none";
6970
6970
  }
6971
6971
  var BOUND_ATTR = "data-ohw-form-bound";
6972
+ var publishedFormContext = {
6973
+ apiUrl: "",
6974
+ subdomain: "",
6975
+ content: {}
6976
+ };
6972
6977
  function bindPublishedForms(apiUrl, subdomain, content = {}) {
6973
- document.querySelectorAll(FORM_SELECTOR).forEach((form) => {
6974
- if (form.hasAttribute(BOUND_ATTR)) return;
6975
- if (!(form instanceof HTMLFormElement)) return;
6976
- const formKey = formKeyOf(form);
6977
- if (!formKey) return;
6978
- form.setAttribute(BOUND_ATTR, "");
6979
- form.addEventListener("submit", async (e) => {
6978
+ publishedFormContext = { apiUrl, subdomain, content };
6979
+ if (document.documentElement.hasAttribute(BOUND_ATTR)) return;
6980
+ document.documentElement.setAttribute(BOUND_ATTR, "");
6981
+ document.addEventListener(
6982
+ "submit",
6983
+ async (e) => {
6984
+ const target = e.target;
6985
+ const form = target?.closest(FORM_SELECTOR);
6986
+ if (!form || !(form instanceof HTMLFormElement)) return;
6987
+ const formKey = formKeyOf(form);
6988
+ if (!formKey) return;
6980
6989
  e.preventDefault();
6981
6990
  clearSubmitError(form);
6982
6991
  const submitButton = form.querySelector(
@@ -6984,7 +6993,8 @@ function bindPublishedForms(apiUrl, subdomain, content = {}) {
6984
6993
  );
6985
6994
  if (submitButton) submitButton.disabled = true;
6986
6995
  try {
6987
- const response = await fetch(`${apiUrl}/api/public/sites/${subdomain}/forms/submissions`, {
6996
+ const { apiUrl: api, subdomain: site, content: latest } = publishedFormContext;
6997
+ const response = await fetch(`${api}/api/public/sites/${site}/forms/submissions`, {
6988
6998
  method: "POST",
6989
6999
  headers: { "Content-Type": "application/json" },
6990
7000
  body: JSON.stringify({
@@ -6994,13 +7004,14 @@ function bindPublishedForms(apiUrl, subdomain, content = {}) {
6994
7004
  })
6995
7005
  });
6996
7006
  if (!response.ok) throw new Error(`submit failed: ${response.status}`);
6997
- showSuccess(form, content[formSuccessKey(formKey)]);
7007
+ showSuccess(form, latest[formSuccessKey(formKey)]);
6998
7008
  } catch {
6999
7009
  showSubmitError(form);
7000
7010
  if (submitButton) submitButton.disabled = false;
7001
7011
  }
7002
- });
7003
- });
7012
+ },
7013
+ true
7014
+ );
7004
7015
  }
7005
7016
 
7006
7017
  // src/lib/form-fields.ts
@@ -13410,8 +13421,10 @@ function getLinkHref3(el) {
13410
13421
  }
13411
13422
  function collectEditableNodes(extraContent, root = document) {
13412
13423
  const isScoped = root !== document;
13413
- const editableEls = Array.from(root.querySelectorAll("[data-ohw-editable]"));
13414
- if (isScoped && root instanceof HTMLElement && root.matches("[data-ohw-editable]")) {
13424
+ const editableEls = Array.from(
13425
+ root.querySelectorAll('[data-ohw-editable]:not([data-ohw-editable="form"])')
13426
+ );
13427
+ if (isScoped && root instanceof HTMLElement && root.matches('[data-ohw-editable]:not([data-ohw-editable="form"])')) {
13415
13428
  editableEls.unshift(root);
13416
13429
  }
13417
13430
  const nodes = editableEls.map((el) => {
@@ -16912,6 +16925,9 @@ function OhhwellsBridge() {
16912
16925
  reconcileSocialsFromContent(content);
16913
16926
  applySocialsDisplayFromContent(content);
16914
16927
  document.querySelectorAll('[data-ohw-editable="form"]').forEach((form) => {
16928
+ if (!form.querySelector("[data-ohw-form-success]")) {
16929
+ reconcileFieldsFromContent(form, content);
16930
+ }
16915
16931
  listFieldWrappers(form).forEach(syncRequiredMark);
16916
16932
  });
16917
16933
  } finally {