@ohhwells/bridge 0.1.117-next.324 → 0.1.117-next.325

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
@@ -572,6 +572,40 @@ function applyBrandToDom(kit) {
572
572
  }
573
573
  }
574
574
 
575
+ // src/lib/custom-code.ts
576
+ var ALLOWED_HEAD_TAGS = /* @__PURE__ */ new Set(["style", "meta", "link", "script", "noscript", "base"]);
577
+ var CUSTOM_CODE_AFTER_HEAD_KEY = "__ohw_custom_code_after_head";
578
+ var CUSTOM_CODE_BEFORE_HEAD_KEY = "__ohw_custom_code_before_head";
579
+ function clearExisting(slot) {
580
+ document.querySelectorAll(`[data-ohw-custom-code="${slot}"]`).forEach((el) => el.remove());
581
+ }
582
+ function buildNodes(raw, slot) {
583
+ if (!raw || !raw.trim()) return [];
584
+ const parsed = new DOMParser().parseFromString(raw, "text/html");
585
+ const source = [...parsed.head.childNodes, ...parsed.body.childNodes];
586
+ const nodes = [];
587
+ for (const node of source) {
588
+ if (node.nodeType !== Node.ELEMENT_NODE) continue;
589
+ const el = node;
590
+ const tag = el.tagName.toLowerCase();
591
+ if (!ALLOWED_HEAD_TAGS.has(tag)) continue;
592
+ const built = document.createElement(tag);
593
+ for (const attr of Array.from(el.attributes)) built.setAttribute(attr.name, attr.value);
594
+ if (tag === "script" || tag === "style" || tag === "noscript") built.textContent = el.textContent;
595
+ built.dataset.ohwCustomCode = slot;
596
+ nodes.push(built);
597
+ }
598
+ return nodes;
599
+ }
600
+ function applyCustomCodeToHead(content) {
601
+ clearExisting("after");
602
+ clearExisting("before");
603
+ const afterNodes = buildNodes(content[CUSTOM_CODE_AFTER_HEAD_KEY], "after");
604
+ if (afterNodes.length > 0) document.head.prepend(...afterNodes);
605
+ const beforeNodes = buildNodes(content[CUSTOM_CODE_BEFORE_HEAD_KEY], "before");
606
+ if (beforeNodes.length > 0) document.head.append(...beforeNodes);
607
+ }
608
+
575
609
  // src/lib/section-styles.ts
576
610
  var STYLE_STORE_KEY = "__ohw_styles";
577
611
  var STYLE_SHEET_ID = "ohw-section-styles";
@@ -22206,6 +22240,7 @@ function OhhwellsBridge() {
22206
22240
  applyStylesToDom(parseStyleStore(content[STYLE_STORE_KEY]));
22207
22241
  }
22208
22242
  applyBrandChrome(content);
22243
+ applyCustomCodeToHead(content);
22209
22244
  initSectionInstancesFromContent(content, window.location.pathname);
22210
22245
  for (const [key, val] of Object.entries(content)) {
22211
22246
  if (key === "__ohw_sections") continue;
@@ -22215,6 +22250,7 @@ function OhhwellsBridge() {
22215
22250
  if (key === BRAND_KIT_KEY) continue;
22216
22251
  if (key === STYLE_STORE_KEY) continue;
22217
22252
  if (BRAND_CHROME_KEYS.has(key)) continue;
22253
+ if (key === CUSTOM_CODE_AFTER_HEAD_KEY || key === CUSTOM_CODE_BEFORE_HEAD_KEY) continue;
22218
22254
  if (applyVideoSettingNode(key, val)) continue;
22219
22255
  if (applyCarouselNode(key, val)) continue;
22220
22256
  document.querySelectorAll(`[data-ohw-key="${key}"]`).forEach((el) => {
@@ -24626,6 +24662,7 @@ function OhhwellsBridge() {
24626
24662
  applyStylesToDom(parseStyleStore(content[STYLE_STORE_KEY]));
24627
24663
  }
24628
24664
  applyBrandChrome(content);
24665
+ applyCustomCodeToHead(content);
24629
24666
  initSectionInstancesFromContent(content, window.location.pathname);
24630
24667
  let sectionsJson = null;
24631
24668
  for (const [key, val] of Object.entries(content)) {
@@ -24639,6 +24676,7 @@ function OhhwellsBridge() {
24639
24676
  if (key === BRAND_KIT_KEY) continue;
24640
24677
  if (key === STYLE_STORE_KEY) continue;
24641
24678
  if (BRAND_CHROME_KEYS.has(key)) continue;
24679
+ if (key === CUSTOM_CODE_AFTER_HEAD_KEY || key === CUSTOM_CODE_BEFORE_HEAD_KEY) continue;
24642
24680
  if (applyVideoSettingNode(key, val)) continue;
24643
24681
  if (applyCarouselNode(key, val)) continue;
24644
24682
  document.querySelectorAll(`[data-ohw-key="${key}"]`).forEach((el) => {
@@ -25356,6 +25394,16 @@ function OhhwellsBridge() {
25356
25394
  if (brandKitRef.current) {
25357
25395
  nodes.push({ key: BRAND_KIT_KEY, type: "brand", text: brandKitRef.current });
25358
25396
  }
25397
+ nodes.push({
25398
+ key: CUSTOM_CODE_BEFORE_HEAD_KEY,
25399
+ type: "text",
25400
+ text: editContentRef.current[CUSTOM_CODE_BEFORE_HEAD_KEY] ?? ""
25401
+ });
25402
+ nodes.push({
25403
+ key: CUSTOM_CODE_AFTER_HEAD_KEY,
25404
+ type: "text",
25405
+ text: editContentRef.current[CUSTOM_CODE_AFTER_HEAD_KEY] ?? ""
25406
+ });
25359
25407
  document.querySelectorAll('[data-ohw-editable="form"]').forEach((form) => {
25360
25408
  const formKey = formKeyOf(form);
25361
25409
  if (!formKey) return;