@ohhwells/bridge 0.1.109 → 0.1.111

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
@@ -8178,6 +8178,7 @@ var FIELD_TYPES = [
8178
8178
  var FIELD_ATTR = "data-ohw-form-field";
8179
8179
  var FIELD_TYPE_ATTR = "data-ohw-field-type";
8180
8180
  var PLACEHOLDER_EDIT_ATTR = "data-ohw-placeholder-edit";
8181
+ var seedFieldByForm = /* @__PURE__ */ new WeakMap();
8181
8182
  function fieldsKey(formKey) {
8182
8183
  return `${formKey}-fields`;
8183
8184
  }
@@ -8263,7 +8264,11 @@ function markFormFields(form) {
8263
8264
  ensureFieldLabel(wrapper, key);
8264
8265
  syncRequiredMark(wrapper);
8265
8266
  });
8266
- return listFieldWrappers(form);
8267
+ const wrappers = listFieldWrappers(form);
8268
+ if (wrappers.length > 0 && !seedFieldByForm.has(form)) {
8269
+ seedFieldByForm.set(form, wrappers[0].cloneNode(true));
8270
+ }
8271
+ return wrappers;
8267
8272
  }
8268
8273
  function readFieldsFromDom(form) {
8269
8274
  return listFieldWrappers(form).map((wrapper) => {
@@ -8407,12 +8412,27 @@ function insertField(form, type) {
8407
8412
  wrapper = source.cloneNode(true);
8408
8413
  source.after(wrapper);
8409
8414
  } else {
8410
- wrapper = document.createElement("div");
8411
- const label2 = document.createElement("label");
8412
- const input2 = document.createElement("input");
8413
- wrapper.append(label2, input2);
8415
+ const seed = seedFieldByForm.get(form);
8416
+ if (seed) {
8417
+ wrapper = seed.cloneNode(true);
8418
+ } else {
8419
+ wrapper = document.createElement("div");
8420
+ const input2 = document.createElement("input");
8421
+ input2.style.width = "100%";
8422
+ input2.style.boxSizing = "border-box";
8423
+ input2.style.padding = "12px";
8424
+ input2.style.border = "1px solid color-mix(in srgb, currentColor 35%, transparent)";
8425
+ input2.style.borderRadius = "8px";
8426
+ input2.style.background = "#fff";
8427
+ input2.style.fontFamily = "inherit";
8428
+ input2.style.fontSize = "inherit";
8429
+ input2.style.color = "inherit";
8430
+ wrapper.append(input2);
8431
+ }
8414
8432
  const submit = form.querySelector('button, input[type="submit"]');
8415
- if (submit) submit.before(wrapper);
8433
+ let anchor = submit;
8434
+ while (anchor && anchor.parentElement !== form) anchor = anchor.parentElement;
8435
+ if (anchor) anchor.before(wrapper);
8416
8436
  else form.appendChild(wrapper);
8417
8437
  }
8418
8438
  wrapper.setAttribute(FIELD_ATTR, key);
@@ -16853,6 +16873,10 @@ function getIframeVisibleClip(parentScroll) {
16853
16873
  );
16854
16874
  return { top: clipTop, bottom: Math.max(clipTop, clipBottom) };
16855
16875
  }
16876
+ function isRectOutsideClip(rect, clip) {
16877
+ if (!clip) return false;
16878
+ return rect.bottom < clip.top || rect.top > clip.bottom;
16879
+ }
16856
16880
  function applyVisibleViewport(el, parentScroll) {
16857
16881
  const clip = getIframeVisibleClip(parentScroll);
16858
16882
  const top = clip?.top ?? 0;
@@ -19592,8 +19616,10 @@ function OhhwellsBridge() {
19592
19616
  crushed its fields together (OHH-490). Not media (image/bg-image/video/icon/map)
19593
19617
  either: those can be their own flex containers centering fallback content (a
19594
19618
  placeholder label, a mascot emoji) \u2014 forcing block broke that centering while the
19595
- image was unset (OHH-758-ish). */
19596
- [data-ohw-editable]:not([data-ohw-editable="form"]):not([data-ohw-editable="image"]):not([data-ohw-editable="bg-image"]):not([data-ohw-editable="video"]):not([data-ohw-editable="icon"]):not([data-ohw-editable="map"]) {
19619
+ image was unset (OHH-758-ish). Not inside a container that declares its editables
19620
+ inline (data-ohw-inline-editables): a row of inline links \u2014 a footer's legal line \u2014
19621
+ keeps its line; blockified labels put each link on its own row in the editor only. */
19622
+ [data-ohw-editable]:not([data-ohw-editable="form"]):not([data-ohw-editable="image"]):not([data-ohw-editable="bg-image"]):not([data-ohw-editable="video"]):not([data-ohw-editable="icon"]):not([data-ohw-editable="map"]):not([data-ohw-inline-editables] *) {
19597
19623
  display: block;
19598
19624
  }
19599
19625
  /* The block-force above is an author rule, so it beats the browser's own
@@ -21336,6 +21362,7 @@ function OhhwellsBridge() {
21336
21362
  applyMapQuery(el, val);
21337
21363
  } else if (el.dataset.ohwEditable === "icon") {
21338
21364
  applyIconMarkup(el, val);
21365
+ } else if (el.dataset.ohwEditable === "form") {
21339
21366
  } else if (isIconMarkupValue(val)) {
21340
21367
  } else {
21341
21368
  el.innerHTML = val;
@@ -21345,6 +21372,9 @@ function OhhwellsBridge() {
21345
21372
  }
21346
21373
  applyLogoFromContent(content);
21347
21374
  applyLogoSizes(content);
21375
+ document.querySelectorAll('[data-ohw-editable="form"]').forEach((form) => {
21376
+ reconcileFieldsFromContent(form, content);
21377
+ });
21348
21378
  if (sectionsJson) {
21349
21379
  initSectionsFromContent({ __ohw_sections: sectionsJson }, true);
21350
21380
  sectionsLoadedRef.current = true;
@@ -22201,14 +22231,20 @@ function OhhwellsBridge() {
22201
22231
  };
22202
22232
  const applyToolbarPos = (rect) => {
22203
22233
  const ps = parentScrollRef.current;
22234
+ const hidden = isRectOutsideClip(rect, getIframeVisibleClip(ps));
22204
22235
  const measuredW = toolbarElRef.current?.offsetWidth || 330;
22205
22236
  if (toolbarElRef.current) {
22206
- const { top, left, transform } = calcToolbarPos(rect, ps, measuredW);
22207
- toolbarElRef.current.style.top = `${top}px`;
22208
- toolbarElRef.current.style.left = `${left}px`;
22209
- toolbarElRef.current.style.transform = transform;
22237
+ toolbarElRef.current.style.display = hidden ? "none" : "";
22238
+ if (!hidden) {
22239
+ const { top, left, transform } = calcToolbarPos(rect, ps, measuredW);
22240
+ toolbarElRef.current.style.top = `${top}px`;
22241
+ toolbarElRef.current.style.left = `${left}px`;
22242
+ toolbarElRef.current.style.transform = transform;
22243
+ }
22210
22244
  }
22211
22245
  if (glowElRef.current) {
22246
+ glowElRef.current.style.display = hidden ? "none" : "";
22247
+ if (hidden) return;
22212
22248
  const GAP = SELECTION_CHROME_GAP2;
22213
22249
  glowElRef.current.style.top = `${rect.top - GAP}px`;
22214
22250
  glowElRef.current.style.left = `${rect.left - GAP}px`;
@@ -22650,7 +22686,7 @@ function OhhwellsBridge() {
22650
22686
  postToParent2({
22651
22687
  type: "ow:ready",
22652
22688
  version: "1",
22653
- bridgeVersion: "0.1.108",
22689
+ bridgeVersion: "0.1.110",
22654
22690
  path: pathname,
22655
22691
  nodes: collectEditableNodes(editContentRef.current),
22656
22692
  sections
@@ -23438,7 +23474,7 @@ function OhhwellsBridge() {
23438
23474
  ) : void 0
23439
23475
  }
23440
23476
  ),
23441
- toolbarRect && toolbarVariant === "rich-text" && !linkPopover && /* @__PURE__ */ jsxs20(Fragment8, { children: [
23477
+ toolbarRect && toolbarVariant === "rich-text" && !linkPopover && !isRectOutsideClip(toolbarRect, getIframeVisibleClip(parentScrollRef.current)) && /* @__PURE__ */ jsxs20(Fragment8, { children: [
23442
23478
  /* @__PURE__ */ jsx33(
23443
23479
  EditGlowChrome,
23444
23480
  {