@ohhwells/bridge 0.1.169-next.448 → 0.1.169-next.450

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
@@ -323,6 +323,7 @@ function softUnhide(el) {
323
323
  // src/lib/section-instances.ts
324
324
  var SECTION_ORDER_KEY = "__ohw_section_order";
325
325
  var REMOVED_ATTR = "data-ohw-section-removed";
326
+ var CLONE_ATTR = "data-ohw-section-clone";
326
327
  function isRemovedSection(el) {
327
328
  return el.hasAttribute(REMOVED_ATTR);
328
329
  }
@@ -451,6 +452,7 @@ function duplicateSectionInstance(instanceId, newId, currentPath, existingEntrie
451
452
  if (!original) return null;
452
453
  const clone = original.cloneNode(true);
453
454
  clone.setAttribute("data-ohw-instance", newId);
455
+ clone.setAttribute(CLONE_ATTR, "");
454
456
  const keyRekeys = rekeySectionSubtree(clone, newId);
455
457
  original.insertAdjacentElement("afterend", clone);
456
458
  const byId = new Map(existingEntries.map((e) => [e.instanceId, e]));
@@ -530,6 +532,10 @@ function initSectionInstancesFromContent(content, currentPath) {
530
532
  if (type) el.setAttribute("data-ohw-instance", type);
531
533
  });
532
534
  const entries = getPageSectionOrderEntries(content[SECTION_ORDER_KEY], currentPath);
535
+ const listed = new Set(entries.map((entry) => entry.instanceId));
536
+ document.querySelectorAll(`[${CLONE_ATTR}]`).forEach((clone) => {
537
+ if (!listed.has(instanceIdOf(clone))) clone.remove();
538
+ });
533
539
  for (const entry of entries) {
534
540
  if (entry.instanceId === entry.type) continue;
535
541
  if (document.querySelector(`[data-ohw-instance="${CSS.escape(entry.instanceId)}"]`)) continue;
@@ -539,6 +545,7 @@ function initSectionInstancesFromContent(content, currentPath) {
539
545
  if (!original) continue;
540
546
  const clone = original.cloneNode(true);
541
547
  clone.setAttribute("data-ohw-instance", entry.instanceId);
548
+ clone.setAttribute(CLONE_ATTR, "");
542
549
  rekeySectionSubtree(clone, entry.instanceId);
543
550
  original.insertAdjacentElement("afterend", clone);
544
551
  }
@@ -1696,6 +1703,8 @@ function brandTrackedFontFamily(doc, stack) {
1696
1703
  }
1697
1704
  var paintLockByEl = /* @__PURE__ */ new WeakMap();
1698
1705
  var paintObserverByEl = /* @__PURE__ */ new WeakMap();
1706
+ var prePaintByEl = /* @__PURE__ */ new WeakMap();
1707
+ var paintedEls = /* @__PURE__ */ new Set();
1699
1708
  var PAINT_GUARD_ATTRS = {
1700
1709
  attributes: true,
1701
1710
  attributeFilter: ["style", "class"]
@@ -1759,6 +1768,18 @@ function paintedTokensOf(el) {
1759
1768
  }
1760
1769
  function applyButtonStyle(el, assignment, tokens) {
1761
1770
  const doc = el.ownerDocument;
1771
+ if (!prePaintByEl.has(el)) {
1772
+ const label = labelElement(el);
1773
+ const ownLabel = label && label !== el ? label : null;
1774
+ prePaintByEl.set(el, {
1775
+ style: el.getAttribute("style"),
1776
+ variant: el.getAttribute("data-ohw-btn-variant"),
1777
+ size: el.getAttribute("data-ohw-btn-size"),
1778
+ label: ownLabel,
1779
+ labelStyle: ownLabel?.getAttribute("style") ?? null
1780
+ });
1781
+ }
1782
+ paintedEls.add(el);
1762
1783
  const tracked = {
1763
1784
  ...tokens,
1764
1785
  variants: {
@@ -1778,6 +1799,31 @@ function applyButtonStylesFromContent(doc, content) {
1778
1799
  if (!el) continue;
1779
1800
  applyButtonStyle(el, assignment, tokensFromButton(el));
1780
1801
  }
1802
+ for (const el of paintedEls) {
1803
+ if (!el.isConnected) {
1804
+ paintedEls.delete(el);
1805
+ continue;
1806
+ }
1807
+ const id = buttonId(el);
1808
+ if (el.ownerDocument === doc && (!id || !assignments[id])) unpaintButton(el);
1809
+ }
1810
+ }
1811
+ function unpaintButton(el) {
1812
+ paintObserverByEl.get(el)?.disconnect();
1813
+ paintObserverByEl.delete(el);
1814
+ paintLockByEl.delete(el);
1815
+ paintedEls.delete(el);
1816
+ const before = prePaintByEl.get(el);
1817
+ prePaintByEl.delete(el);
1818
+ if (!before) return;
1819
+ const restore = (target, name, value) => {
1820
+ if (value === null) target.removeAttribute(name);
1821
+ else target.setAttribute(name, value);
1822
+ };
1823
+ restore(el, "style", before.style);
1824
+ restore(el, "data-ohw-btn-variant", before.variant);
1825
+ restore(el, "data-ohw-btn-size", before.size);
1826
+ if (before.label?.isConnected) restore(before.label, "style", before.labelStyle);
1781
1827
  }
1782
1828
  function withAssignment(content, id, assignment) {
1783
1829
  return { ...readAssignments(content), [id]: assignment };
@@ -2328,6 +2374,7 @@ function reconcileButtonCollections(doc, content) {
2328
2374
  }
2329
2375
  const snapshots = readSnapshots(content);
2330
2376
  const collections = readCollections(content);
2377
+ dropUnsavedCopies(doc, snapshots, collections);
2331
2378
  for (const collectionState of Object.values(collections)) {
2332
2379
  const live = collectionState.members.map((id) => findButton(doc, id) ?? restoreSnapshot(doc, snapshots[id], content)).filter((el) => Boolean(el && !hidden.has(buttonId(el) ?? "")));
2333
2380
  if (live.length === 0) continue;
@@ -2352,6 +2399,18 @@ function reconcileButtonCollections(doc, content) {
2352
2399
  for (const member of live) setButtonDragAttr(member);
2353
2400
  }
2354
2401
  }
2402
+ function dropUnsavedCopies(doc, snapshots, collections) {
2403
+ const stale = Array.from(doc.querySelectorAll('[data-ohw-href-key*="-copy-"]')).filter((el) => {
2404
+ const id = buttonId(el);
2405
+ return Boolean(id && /-copy-\d+-href$/.test(id) && !snapshots[id]);
2406
+ });
2407
+ for (const el of stale) {
2408
+ const collection = buttonCollectionOf(el);
2409
+ el.remove();
2410
+ const id = collection?.getAttribute(COLLECTION_ATTR) ?? "";
2411
+ if (collection && !collections[id] && listCollectionMembers(collection).length <= 1) unwrapCollection(collection);
2412
+ }
2413
+ }
2355
2414
  function restoreSnapshot(doc, snapshot, content) {
2356
2415
  if (!snapshot) return null;
2357
2416
  const existing = findButton(doc, snapshot.id);
@@ -4886,6 +4945,9 @@ function reconcileNavbarItemsFromContent(content) {
4886
4945
  }
4887
4946
  }
4888
4947
  pruneNavbarItemsNotInOrder(allowed);
4948
+ for (const node of orderForest) {
4949
+ if (node.children.length === 0) collapseEmptyNavDropdownForParent(node.id);
4950
+ }
4889
4951
  applyNavForest(orderForest);
4890
4952
  for (const parentKey of openParentKeys) {
4891
4953
  const trigger = document.querySelector(
@@ -17818,7 +17880,7 @@ function apiBase() {
17818
17880
  function bridgeVersion() {
17819
17881
  try {
17820
17882
  if (true) {
17821
- return "0.1.169-next.448";
17883
+ return "0.1.169-next.450";
17822
17884
  }
17823
17885
  } catch {
17824
17886
  }
@@ -17832,7 +17894,7 @@ function stampBridgeVersionOnDocument() {
17832
17894
  return;
17833
17895
  }
17834
17896
  try {
17835
- const v = true ? "0.1.169-next.448" : "";
17897
+ const v = true ? "0.1.169-next.450" : "";
17836
17898
  if (v) {
17837
17899
  document.documentElement.setAttribute("data-ohw-bridge-version", v);
17838
17900
  window.__OHW_BRIDGE_VERSION__ = v;
@@ -31321,6 +31383,7 @@ function OhhwellsBridge() {
31321
31383
  reconcileNavbarItemsFromContent(editContentRef.current);
31322
31384
  reconcileFooterOrderFromContent(editContentRef.current);
31323
31385
  syncButtonsFromContent(document, editContentRef.current);
31386
+ if (selectedElRef.current && !selectedElRef.current.isConnected) deselectRef.current();
31324
31387
  syncNavigationDragCursorAttrs();
31325
31388
  if (typeof content[STYLE_STORE_KEY] === "string") {
31326
31389
  applyStylesToDom(parseStyleStore(content[STYLE_STORE_KEY]));
@@ -33078,7 +33141,7 @@ function OhhwellsBridge() {
33078
33141
  postToParent2({
33079
33142
  type: "ow:ready",
33080
33143
  version: "1",
33081
- bridgeVersion: "0.1.169-next.448",
33144
+ bridgeVersion: "0.1.169-next.450",
33082
33145
  path: pathname,
33083
33146
  nodes: collectEditableNodes(editContentRef.current),
33084
33147
  sections
@@ -33279,7 +33342,7 @@ function OhhwellsBridge() {
33279
33342
  const copyHref = result.copy.getAttribute("data-ohw-href-key");
33280
33343
  const copyHrefVal = copyHref ? result.content[copyHref] : void 0;
33281
33344
  if (copyHref && copyHrefVal !== void 0) applyLinkByKey(copyHref, copyHrefVal);
33282
- postToParent2({ type: "ow:change", nodes: result.nodes });
33345
+ postToParent2({ type: "ow:change", nodes: result.nodes, label: "Button duplicated" });
33283
33346
  enforceLinkHrefs();
33284
33347
  requestAnimationFrame(() => {
33285
33348
  selectRef.current(result.copy);
@@ -33328,7 +33391,7 @@ function OhhwellsBridge() {
33328
33391
  ...editContentRef.current,
33329
33392
  ...Object.fromEntries(nodes.map((node) => [node.key, node.text]))
33330
33393
  };
33331
- postToParent2({ type: "ow:change", nodes });
33394
+ postToParent2({ type: "ow:change", nodes, label: "Social icon duplicated" });
33332
33395
  enforceLinkHrefs();
33333
33396
  const copyRow = findSocialsRow(result.item);
33334
33397
  if (copyRow) applySocialsDisplayToRow(copyRow, socialsDisplayFor(copyRow, editContentRef.current));
@@ -33378,7 +33441,7 @@ function OhhwellsBridge() {
33378
33441
  [NAV_COUNT_KEY]: navCount,
33379
33442
  [NAV_ORDER_KEY]: result.orderJson
33380
33443
  };
33381
- postToParent2({ type: "ow:change", nodes });
33444
+ postToParent2({ type: "ow:change", nodes, label: "Link duplicated" });
33382
33445
  enforceLinkHrefs();
33383
33446
  if (isNestedNavChild(selected) || navItemOwnsDropdownPanel(selected)) {
33384
33447
  setNavGroupForceOpen(selected, true);
@@ -33418,7 +33481,8 @@ function OhhwellsBridge() {
33418
33481
  { key: result.hrefKey, text: result.href },
33419
33482
  { key: result.labelKey, text: result.label },
33420
33483
  { key: FOOTER_ORDER_KEY, text: orderJson }
33421
- ]
33484
+ ],
33485
+ label: "Link duplicated"
33422
33486
  });
33423
33487
  enforceLinkHrefs();
33424
33488
  requestAnimationFrame(() => {