@ohhwells/bridge 0.1.65-next.184 → 0.1.65-next.186

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
@@ -7252,7 +7263,6 @@ function insertField(form, type) {
7252
7263
  const input = fieldInputOf(wrapper);
7253
7264
  if (input) {
7254
7265
  input.setAttribute("name", key);
7255
- input.setAttribute("data-ohw-key", key);
7256
7266
  input.removeAttribute("required");
7257
7267
  input.setAttribute("placeholder", defaults.placeholder);
7258
7268
  input.value = "";
@@ -7269,9 +7279,11 @@ function duplicateField(form, wrapper) {
7269
7279
  const input = fieldInputOf(copy);
7270
7280
  if (input) {
7271
7281
  input.setAttribute("name", key);
7272
- input.setAttribute("data-ohw-key", key);
7282
+ input.removeAttribute("data-ohw-key");
7273
7283
  input.value = "";
7274
7284
  }
7285
+ const label = fieldLabelOf(copy);
7286
+ if (label) label.setAttribute("data-ohw-key", `${key}-label`);
7275
7287
  wrapper.after(copy);
7276
7288
  return copy;
7277
7289
  }
@@ -7314,8 +7326,8 @@ function reconcileFieldsFromContent(form, content) {
7314
7326
  const input = fieldInputOf(wrapper);
7315
7327
  if (input) {
7316
7328
  input.setAttribute("name", spec.key);
7317
- input.setAttribute("data-ohw-key", spec.key);
7318
7329
  }
7330
+ fieldLabelOf(wrapper)?.setAttribute("data-ohw-key", `${spec.key}-label`);
7319
7331
  byKey.set(spec.key, wrapper);
7320
7332
  }
7321
7333
  applyFieldType(wrapper, spec.type);
@@ -16914,6 +16926,9 @@ function OhhwellsBridge() {
16914
16926
  reconcileSocialsFromContent(content);
16915
16927
  applySocialsDisplayFromContent(content);
16916
16928
  document.querySelectorAll('[data-ohw-editable="form"]').forEach((form) => {
16929
+ if (!form.querySelector("[data-ohw-form-success]")) {
16930
+ reconcileFieldsFromContent(form, content);
16931
+ }
16917
16932
  listFieldWrappers(form).forEach(syncRequiredMark);
16918
16933
  });
16919
16934
  } finally {