@ohhwells/bridge 0.1.120 → 0.1.121

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
@@ -501,6 +501,40 @@ function applyBrandToDom(kit) {
501
501
  }
502
502
  }
503
503
 
504
+ // src/lib/custom-code.ts
505
+ var ALLOWED_HEAD_TAGS = /* @__PURE__ */ new Set(["style", "meta", "link", "script", "noscript", "base"]);
506
+ var CUSTOM_CODE_AFTER_HEAD_KEY = "__ohw_custom_code_after_head";
507
+ var CUSTOM_CODE_BEFORE_HEAD_KEY = "__ohw_custom_code_before_head";
508
+ function clearExisting(slot) {
509
+ document.querySelectorAll(`[data-ohw-custom-code="${slot}"]`).forEach((el) => el.remove());
510
+ }
511
+ function buildNodes(raw, slot) {
512
+ if (!raw || !raw.trim()) return [];
513
+ const parsed = new DOMParser().parseFromString(raw, "text/html");
514
+ const source = [...parsed.head.childNodes, ...parsed.body.childNodes];
515
+ const nodes = [];
516
+ for (const node of source) {
517
+ if (node.nodeType !== Node.ELEMENT_NODE) continue;
518
+ const el = node;
519
+ const tag = el.tagName.toLowerCase();
520
+ if (!ALLOWED_HEAD_TAGS.has(tag)) continue;
521
+ const built = document.createElement(tag);
522
+ for (const attr of Array.from(el.attributes)) built.setAttribute(attr.name, attr.value);
523
+ if (tag === "script" || tag === "style" || tag === "noscript") built.textContent = el.textContent;
524
+ built.dataset.ohwCustomCode = slot;
525
+ nodes.push(built);
526
+ }
527
+ return nodes;
528
+ }
529
+ function applyCustomCodeToHead(content) {
530
+ clearExisting("after");
531
+ clearExisting("before");
532
+ const afterNodes = buildNodes(content[CUSTOM_CODE_AFTER_HEAD_KEY], "after");
533
+ if (afterNodes.length > 0) document.head.prepend(...afterNodes);
534
+ const beforeNodes = buildNodes(content[CUSTOM_CODE_BEFORE_HEAD_KEY], "before");
535
+ if (beforeNodes.length > 0) document.head.append(...beforeNodes);
536
+ }
537
+
504
538
  // src/lib/section-styles.ts
505
539
  var STYLE_STORE_KEY = "__ohw_styles";
506
540
  var STYLE_SHEET_ID = "ohw-section-styles";
@@ -20994,6 +21028,7 @@ function OhhwellsBridge() {
20994
21028
  applyStylesToDom(parseStyleStore(content[STYLE_STORE_KEY]));
20995
21029
  }
20996
21030
  applyBrandChrome(content);
21031
+ applyCustomCodeToHead(content);
20997
21032
  initSectionInstancesFromContent(content, window.location.pathname);
20998
21033
  for (const [key, val] of Object.entries(content)) {
20999
21034
  if (key === "__ohw_sections") continue;
@@ -21002,6 +21037,7 @@ function OhhwellsBridge() {
21002
21037
  if (key === STYLE_STORE_KEY) continue;
21003
21038
  if (BRAND_CHROME_KEYS.has(key)) continue;
21004
21039
  if (key === LOGO_PLACEHOLDER_KEY) continue;
21040
+ if (key === CUSTOM_CODE_AFTER_HEAD_KEY || key === CUSTOM_CODE_BEFORE_HEAD_KEY) continue;
21005
21041
  if (LOGO_IMAGE_KEYS.includes(key)) continue;
21006
21042
  if (applyVideoSettingNode(key, val)) continue;
21007
21043
  if (applyCarouselNode(key, val)) continue;
@@ -23330,6 +23366,7 @@ function OhhwellsBridge() {
23330
23366
  applyStylesToDom(parseStyleStore(content[STYLE_STORE_KEY]));
23331
23367
  }
23332
23368
  applyBrandChrome(content);
23369
+ applyCustomCodeToHead(content);
23333
23370
  initSectionInstancesFromContent(content, window.location.pathname);
23334
23371
  let sectionsJson = null;
23335
23372
  for (const [key, val] of Object.entries(content)) {
@@ -23342,6 +23379,7 @@ function OhhwellsBridge() {
23342
23379
  if (key === STYLE_STORE_KEY) continue;
23343
23380
  if (BRAND_CHROME_KEYS.has(key)) continue;
23344
23381
  if (key === LOGO_PLACEHOLDER_KEY) continue;
23382
+ if (key === CUSTOM_CODE_AFTER_HEAD_KEY || key === CUSTOM_CODE_BEFORE_HEAD_KEY) continue;
23345
23383
  if (LOGO_IMAGE_KEYS.includes(key) && !String(val ?? "").trim()) continue;
23346
23384
  if (applyVideoSettingNode(key, val)) continue;
23347
23385
  if (applyCarouselNode(key, val)) continue;
@@ -24053,6 +24091,16 @@ function OhhwellsBridge() {
24053
24091
  if (brandKitRef.current) {
24054
24092
  nodes.push({ key: BRAND_KIT_KEY, type: "brand", text: brandKitRef.current });
24055
24093
  }
24094
+ nodes.push({
24095
+ key: CUSTOM_CODE_BEFORE_HEAD_KEY,
24096
+ type: "text",
24097
+ text: editContentRef.current[CUSTOM_CODE_BEFORE_HEAD_KEY] ?? ""
24098
+ });
24099
+ nodes.push({
24100
+ key: CUSTOM_CODE_AFTER_HEAD_KEY,
24101
+ type: "text",
24102
+ text: editContentRef.current[CUSTOM_CODE_AFTER_HEAD_KEY] ?? ""
24103
+ });
24056
24104
  document.querySelectorAll('[data-ohw-editable="form"]').forEach((form) => {
24057
24105
  const formKey = formKeyOf(form);
24058
24106
  if (!formKey) return;
@@ -24714,7 +24762,7 @@ function OhhwellsBridge() {
24714
24762
  postToParent2({
24715
24763
  type: "ow:ready",
24716
24764
  version: "1",
24717
- bridgeVersion: "0.1.119",
24765
+ bridgeVersion: "0.1.120",
24718
24766
  path: pathname,
24719
24767
  nodes: collectEditableNodes(editContentRef.current),
24720
24768
  sections