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

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
@@ -1696,6 +1696,8 @@ function brandTrackedFontFamily(doc, stack) {
1696
1696
  }
1697
1697
  var paintLockByEl = /* @__PURE__ */ new WeakMap();
1698
1698
  var paintObserverByEl = /* @__PURE__ */ new WeakMap();
1699
+ var prePaintByEl = /* @__PURE__ */ new WeakMap();
1700
+ var paintedEls = /* @__PURE__ */ new Set();
1699
1701
  var PAINT_GUARD_ATTRS = {
1700
1702
  attributes: true,
1701
1703
  attributeFilter: ["style", "class"]
@@ -1759,6 +1761,18 @@ function paintedTokensOf(el) {
1759
1761
  }
1760
1762
  function applyButtonStyle(el, assignment, tokens) {
1761
1763
  const doc = el.ownerDocument;
1764
+ if (!prePaintByEl.has(el)) {
1765
+ const label = labelElement(el);
1766
+ const ownLabel = label && label !== el ? label : null;
1767
+ prePaintByEl.set(el, {
1768
+ style: el.getAttribute("style"),
1769
+ variant: el.getAttribute("data-ohw-btn-variant"),
1770
+ size: el.getAttribute("data-ohw-btn-size"),
1771
+ label: ownLabel,
1772
+ labelStyle: ownLabel?.getAttribute("style") ?? null
1773
+ });
1774
+ }
1775
+ paintedEls.add(el);
1762
1776
  const tracked = {
1763
1777
  ...tokens,
1764
1778
  variants: {
@@ -1778,6 +1792,31 @@ function applyButtonStylesFromContent(doc, content) {
1778
1792
  if (!el) continue;
1779
1793
  applyButtonStyle(el, assignment, tokensFromButton(el));
1780
1794
  }
1795
+ for (const el of paintedEls) {
1796
+ if (!el.isConnected) {
1797
+ paintedEls.delete(el);
1798
+ continue;
1799
+ }
1800
+ const id = buttonId(el);
1801
+ if (el.ownerDocument === doc && (!id || !assignments[id])) unpaintButton(el);
1802
+ }
1803
+ }
1804
+ function unpaintButton(el) {
1805
+ paintObserverByEl.get(el)?.disconnect();
1806
+ paintObserverByEl.delete(el);
1807
+ paintLockByEl.delete(el);
1808
+ paintedEls.delete(el);
1809
+ const before = prePaintByEl.get(el);
1810
+ prePaintByEl.delete(el);
1811
+ if (!before) return;
1812
+ const restore = (target, name, value) => {
1813
+ if (value === null) target.removeAttribute(name);
1814
+ else target.setAttribute(name, value);
1815
+ };
1816
+ restore(el, "style", before.style);
1817
+ restore(el, "data-ohw-btn-variant", before.variant);
1818
+ restore(el, "data-ohw-btn-size", before.size);
1819
+ if (before.label?.isConnected) restore(before.label, "style", before.labelStyle);
1781
1820
  }
1782
1821
  function withAssignment(content, id, assignment) {
1783
1822
  return { ...readAssignments(content), [id]: assignment };
@@ -2328,6 +2367,7 @@ function reconcileButtonCollections(doc, content) {
2328
2367
  }
2329
2368
  const snapshots = readSnapshots(content);
2330
2369
  const collections = readCollections(content);
2370
+ dropUnsavedCopies(doc, snapshots, collections);
2331
2371
  for (const collectionState of Object.values(collections)) {
2332
2372
  const live = collectionState.members.map((id) => findButton(doc, id) ?? restoreSnapshot(doc, snapshots[id], content)).filter((el) => Boolean(el && !hidden.has(buttonId(el) ?? "")));
2333
2373
  if (live.length === 0) continue;
@@ -2352,6 +2392,18 @@ function reconcileButtonCollections(doc, content) {
2352
2392
  for (const member of live) setButtonDragAttr(member);
2353
2393
  }
2354
2394
  }
2395
+ function dropUnsavedCopies(doc, snapshots, collections) {
2396
+ const stale = Array.from(doc.querySelectorAll('[data-ohw-href-key*="-copy-"]')).filter((el) => {
2397
+ const id = buttonId(el);
2398
+ return Boolean(id && /-copy-\d+-href$/.test(id) && !snapshots[id]);
2399
+ });
2400
+ for (const el of stale) {
2401
+ const collection = buttonCollectionOf(el);
2402
+ el.remove();
2403
+ const id = collection?.getAttribute(COLLECTION_ATTR) ?? "";
2404
+ if (collection && !collections[id] && listCollectionMembers(collection).length <= 1) unwrapCollection(collection);
2405
+ }
2406
+ }
2355
2407
  function restoreSnapshot(doc, snapshot, content) {
2356
2408
  if (!snapshot) return null;
2357
2409
  const existing = findButton(doc, snapshot.id);
@@ -17818,7 +17870,7 @@ function apiBase() {
17818
17870
  function bridgeVersion() {
17819
17871
  try {
17820
17872
  if (true) {
17821
- return "0.1.169-next.448";
17873
+ return "0.1.169-next.449";
17822
17874
  }
17823
17875
  } catch {
17824
17876
  }
@@ -17832,7 +17884,7 @@ function stampBridgeVersionOnDocument() {
17832
17884
  return;
17833
17885
  }
17834
17886
  try {
17835
- const v = true ? "0.1.169-next.448" : "";
17887
+ const v = true ? "0.1.169-next.449" : "";
17836
17888
  if (v) {
17837
17889
  document.documentElement.setAttribute("data-ohw-bridge-version", v);
17838
17890
  window.__OHW_BRIDGE_VERSION__ = v;
@@ -31321,6 +31373,7 @@ function OhhwellsBridge() {
31321
31373
  reconcileNavbarItemsFromContent(editContentRef.current);
31322
31374
  reconcileFooterOrderFromContent(editContentRef.current);
31323
31375
  syncButtonsFromContent(document, editContentRef.current);
31376
+ if (selectedElRef.current && !selectedElRef.current.isConnected) deselectRef.current();
31324
31377
  syncNavigationDragCursorAttrs();
31325
31378
  if (typeof content[STYLE_STORE_KEY] === "string") {
31326
31379
  applyStylesToDom(parseStyleStore(content[STYLE_STORE_KEY]));
@@ -33078,7 +33131,7 @@ function OhhwellsBridge() {
33078
33131
  postToParent2({
33079
33132
  type: "ow:ready",
33080
33133
  version: "1",
33081
- bridgeVersion: "0.1.169-next.448",
33134
+ bridgeVersion: "0.1.169-next.449",
33082
33135
  path: pathname,
33083
33136
  nodes: collectEditableNodes(editContentRef.current),
33084
33137
  sections
@@ -33279,7 +33332,7 @@ function OhhwellsBridge() {
33279
33332
  const copyHref = result.copy.getAttribute("data-ohw-href-key");
33280
33333
  const copyHrefVal = copyHref ? result.content[copyHref] : void 0;
33281
33334
  if (copyHref && copyHrefVal !== void 0) applyLinkByKey(copyHref, copyHrefVal);
33282
- postToParent2({ type: "ow:change", nodes: result.nodes });
33335
+ postToParent2({ type: "ow:change", nodes: result.nodes, label: "Button duplicated" });
33283
33336
  enforceLinkHrefs();
33284
33337
  requestAnimationFrame(() => {
33285
33338
  selectRef.current(result.copy);
@@ -33328,7 +33381,7 @@ function OhhwellsBridge() {
33328
33381
  ...editContentRef.current,
33329
33382
  ...Object.fromEntries(nodes.map((node) => [node.key, node.text]))
33330
33383
  };
33331
- postToParent2({ type: "ow:change", nodes });
33384
+ postToParent2({ type: "ow:change", nodes, label: "Social icon duplicated" });
33332
33385
  enforceLinkHrefs();
33333
33386
  const copyRow = findSocialsRow(result.item);
33334
33387
  if (copyRow) applySocialsDisplayToRow(copyRow, socialsDisplayFor(copyRow, editContentRef.current));
@@ -33378,7 +33431,7 @@ function OhhwellsBridge() {
33378
33431
  [NAV_COUNT_KEY]: navCount,
33379
33432
  [NAV_ORDER_KEY]: result.orderJson
33380
33433
  };
33381
- postToParent2({ type: "ow:change", nodes });
33434
+ postToParent2({ type: "ow:change", nodes, label: "Link duplicated" });
33382
33435
  enforceLinkHrefs();
33383
33436
  if (isNestedNavChild(selected) || navItemOwnsDropdownPanel(selected)) {
33384
33437
  setNavGroupForceOpen(selected, true);
@@ -33418,7 +33471,8 @@ function OhhwellsBridge() {
33418
33471
  { key: result.hrefKey, text: result.href },
33419
33472
  { key: result.labelKey, text: result.label },
33420
33473
  { key: FOOTER_ORDER_KEY, text: orderJson }
33421
- ]
33474
+ ],
33475
+ label: "Link duplicated"
33422
33476
  });
33423
33477
  enforceLinkHrefs();
33424
33478
  requestAnimationFrame(() => {