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

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
@@ -6914,7 +6914,7 @@ function showSuccess(form, message) {
6914
6914
  note.innerHTML = text;
6915
6915
  form.replaceChildren(note);
6916
6916
  }
6917
- function showSubmitError(form) {
6917
+ function showSubmitError(form, message = "Something went wrong. Please try again.") {
6918
6918
  let note = form.querySelector("[data-ohw-form-error]");
6919
6919
  if (!note) {
6920
6920
  note = document.createElement("p");
@@ -6923,7 +6923,7 @@ function showSubmitError(form) {
6923
6923
  note.style.marginTop = "8px";
6924
6924
  form.appendChild(note);
6925
6925
  }
6926
- note.textContent = "Something went wrong. Please try again.";
6926
+ note.textContent = message;
6927
6927
  note.style.display = "";
6928
6928
  }
6929
6929
  function clearSubmitError(form) {
@@ -6988,6 +6988,11 @@ function bindPublishedForms(apiUrl, subdomain, content = {}) {
6988
6988
  if (!formKey) return;
6989
6989
  e.preventDefault();
6990
6990
  clearSubmitError(form);
6991
+ const filled = collectFormFields(form);
6992
+ if (!Object.values(filled).some((value) => value.trim() !== "")) {
6993
+ showSubmitError(form, "Please fill in at least one field.");
6994
+ return;
6995
+ }
6991
6996
  const submitButton = form.querySelector(
6992
6997
  'button[type="submit"], input[type="submit"], button:not([type])'
6993
6998
  );
@@ -6999,7 +7004,7 @@ function bindPublishedForms(apiUrl, subdomain, content = {}) {
6999
7004
  headers: { "Content-Type": "application/json" },
7000
7005
  body: JSON.stringify({
7001
7006
  formKey,
7002
- fields: collectFormFields(form),
7007
+ fields: filled,
7003
7008
  hasLongText: formHasLongText(form)
7004
7009
  })
7005
7010
  });
@@ -14299,7 +14304,8 @@ function isNavItemPointerTarget(el) {
14299
14304
  function getNavigationItemAnchor(el) {
14300
14305
  const anchor = el.matches("[data-ohw-href-key]") ? el : el.closest("[data-ohw-href-key]");
14301
14306
  if (!anchor) return null;
14302
- if (!anchor.querySelector('[data-ohw-editable="text"]') && !getSocialItem(anchor)) return null;
14307
+ if (!anchor.matches('[data-ohw-editable="text"], [data-ohw-editable="plain"]') && !anchor.querySelector('[data-ohw-editable="text"], [data-ohw-editable="plain"]') && !getSocialItem(anchor))
14308
+ return null;
14303
14309
  if (!isNavItemPointerTarget(anchor)) return null;
14304
14310
  return anchor;
14305
14311
  }
@@ -15325,17 +15331,37 @@ function OhhwellsBridge() {
15325
15331
  [persistFields, selectField]
15326
15332
  );
15327
15333
  const fieldDragRef = (0, import_react16.useRef)(null);
15334
+ const buildFieldDropSlots = (0, import_react16.useCallback)((form, draggedKey) => {
15335
+ const others = listFieldWrappers(form).filter((el) => fieldKeyOf(el) !== draggedKey);
15336
+ const slots = others.map((el) => {
15337
+ const rect = el.getBoundingClientRect();
15338
+ return { top: rect.top, left: rect.left, width: rect.width };
15339
+ });
15340
+ const last = others[others.length - 1];
15341
+ if (last) {
15342
+ const rect = last.getBoundingClientRect();
15343
+ slots.push({ top: rect.bottom, left: rect.left, width: rect.width });
15344
+ }
15345
+ return slots;
15346
+ }, []);
15328
15347
  const handleFieldDragStart = (0, import_react16.useCallback)(() => {
15329
15348
  const wrapper = fieldPickElRef.current;
15330
15349
  const form = formPickElRef.current;
15331
15350
  if (!wrapper || !form) return;
15332
- fieldDragRef.current = { key: fieldKeyOf(wrapper), form };
15333
- }, []);
15351
+ const key = fieldKeyOf(wrapper);
15352
+ fieldDragRef.current = { key, form };
15353
+ setFieldDragging(true);
15354
+ setFieldDropSlots(buildFieldDropSlots(form, key));
15355
+ }, [buildFieldDropSlots]);
15334
15356
  const handleFieldDragEnd = (0, import_react16.useCallback)(() => {
15335
15357
  fieldDragRef.current = null;
15336
15358
  setFieldDropIndex(null);
15359
+ setFieldDropSlots([]);
15360
+ setFieldDragging(false);
15337
15361
  }, []);
15338
15362
  const [fieldDropIndex, setFieldDropIndex] = (0, import_react16.useState)(null);
15363
+ const [fieldDropSlots, setFieldDropSlots] = (0, import_react16.useState)([]);
15364
+ const [fieldDragging, setFieldDragging] = (0, import_react16.useState)(false);
15339
15365
  const clearFormPickRef = (0, import_react16.useRef)(clearFormPick);
15340
15366
  clearFormPickRef.current = clearFormPick;
15341
15367
  (0, import_react16.useEffect)(() => {
@@ -16796,6 +16822,7 @@ function OhhwellsBridge() {
16796
16822
  e.preventDefault();
16797
16823
  e.stopPropagation();
16798
16824
  if (e.dataTransfer) e.dataTransfer.dropEffect = "move";
16825
+ setFieldDropSlots(buildFieldDropSlots(session.form, session.key));
16799
16826
  setFieldDropIndex(resolveIndex(session.form, e.clientY));
16800
16827
  };
16801
16828
  const onDrop = (e) => {
@@ -16810,6 +16837,8 @@ function OhhwellsBridge() {
16810
16837
  setFormPickRect(session.form.getBoundingClientRect());
16811
16838
  fieldDragRef.current = null;
16812
16839
  setFieldDropIndex(null);
16840
+ setFieldDropSlots([]);
16841
+ setFieldDragging(false);
16813
16842
  };
16814
16843
  window.addEventListener("dragover", onDragOver, true);
16815
16844
  window.addEventListener("drop", onDrop, true);
@@ -16817,7 +16846,7 @@ function OhhwellsBridge() {
16817
16846
  window.removeEventListener("dragover", onDragOver, true);
16818
16847
  window.removeEventListener("drop", onDrop, true);
16819
16848
  };
16820
- }, [isEditMode, persistFields, selectField]);
16849
+ }, [buildFieldDropSlots, isEditMode, persistFields, selectField]);
16821
16850
  (0, import_react16.useEffect)(() => {
16822
16851
  if (!isEditMode) return;
16823
16852
  const mark = () => document.querySelectorAll('[data-ohw-editable="form"]').forEach((form) => {
@@ -20243,7 +20272,7 @@ function OhhwellsBridge() {
20243
20272
  ItemInteractionLayer,
20244
20273
  {
20245
20274
  rect: fieldPickRect,
20246
- state: "active-top",
20275
+ state: fieldDragging ? "dragging" : "active-top",
20247
20276
  itemDragSurface: false,
20248
20277
  toolbarAlign: "left",
20249
20278
  chromeGap: 10,
@@ -20264,23 +20293,22 @@ function OhhwellsBridge() {
20264
20293
  )
20265
20294
  }
20266
20295
  ),
20267
- fieldDropIndex !== null && formPickElRef.current ? (() => {
20268
- const wrappers = listFieldWrappers(formPickElRef.current).filter(
20269
- (el) => fieldKeyOf(el) !== fieldDragRef.current?.key
20270
- );
20271
- const anchor = wrappers[Math.min(fieldDropIndex, wrappers.length - 1)];
20272
- if (!anchor) return null;
20273
- const rect = anchor.getBoundingClientRect();
20274
- const atEnd = fieldDropIndex >= wrappers.length;
20275
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
20276
- "div",
20277
- {
20278
- className: "pointer-events-none fixed z-[2147483644]",
20279
- style: { top: atEnd ? rect.bottom : rect.top, left: rect.left, width: rect.width },
20280
- children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(DropIndicator, { direction: "horizontal", state: "dragActive" })
20281
- }
20282
- );
20283
- })() : null,
20296
+ fieldDragging ? fieldDropSlots.map((slot, i) => /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
20297
+ "div",
20298
+ {
20299
+ className: "pointer-events-none fixed z-[2147483644]",
20300
+ style: { top: slot.top, left: slot.left, width: slot.width },
20301
+ children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
20302
+ DropIndicator,
20303
+ {
20304
+ direction: "horizontal",
20305
+ state: fieldDropIndex === i ? "dragActive" : "dragIdle",
20306
+ className: "!w-full"
20307
+ }
20308
+ )
20309
+ },
20310
+ `field-drop-${i}`
20311
+ )) : null,
20284
20312
  fieldTypePickerOpen && formPickRect && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
20285
20313
  "div",
20286
20314
  {