@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 +49 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -428,6 +428,40 @@ function applyBrandToDom(kit) {
|
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
+
// src/lib/custom-code.ts
|
|
432
|
+
var ALLOWED_HEAD_TAGS = /* @__PURE__ */ new Set(["style", "meta", "link", "script", "noscript", "base"]);
|
|
433
|
+
var CUSTOM_CODE_AFTER_HEAD_KEY = "__ohw_custom_code_after_head";
|
|
434
|
+
var CUSTOM_CODE_BEFORE_HEAD_KEY = "__ohw_custom_code_before_head";
|
|
435
|
+
function clearExisting(slot) {
|
|
436
|
+
document.querySelectorAll(`[data-ohw-custom-code="${slot}"]`).forEach((el) => el.remove());
|
|
437
|
+
}
|
|
438
|
+
function buildNodes(raw, slot) {
|
|
439
|
+
if (!raw || !raw.trim()) return [];
|
|
440
|
+
const parsed = new DOMParser().parseFromString(raw, "text/html");
|
|
441
|
+
const source = [...parsed.head.childNodes, ...parsed.body.childNodes];
|
|
442
|
+
const nodes = [];
|
|
443
|
+
for (const node of source) {
|
|
444
|
+
if (node.nodeType !== Node.ELEMENT_NODE) continue;
|
|
445
|
+
const el = node;
|
|
446
|
+
const tag = el.tagName.toLowerCase();
|
|
447
|
+
if (!ALLOWED_HEAD_TAGS.has(tag)) continue;
|
|
448
|
+
const built = document.createElement(tag);
|
|
449
|
+
for (const attr of Array.from(el.attributes)) built.setAttribute(attr.name, attr.value);
|
|
450
|
+
if (tag === "script" || tag === "style" || tag === "noscript") built.textContent = el.textContent;
|
|
451
|
+
built.dataset.ohwCustomCode = slot;
|
|
452
|
+
nodes.push(built);
|
|
453
|
+
}
|
|
454
|
+
return nodes;
|
|
455
|
+
}
|
|
456
|
+
function applyCustomCodeToHead(content) {
|
|
457
|
+
clearExisting("after");
|
|
458
|
+
clearExisting("before");
|
|
459
|
+
const afterNodes = buildNodes(content[CUSTOM_CODE_AFTER_HEAD_KEY], "after");
|
|
460
|
+
if (afterNodes.length > 0) document.head.prepend(...afterNodes);
|
|
461
|
+
const beforeNodes = buildNodes(content[CUSTOM_CODE_BEFORE_HEAD_KEY], "before");
|
|
462
|
+
if (beforeNodes.length > 0) document.head.append(...beforeNodes);
|
|
463
|
+
}
|
|
464
|
+
|
|
431
465
|
// src/lib/section-styles.ts
|
|
432
466
|
var STYLE_STORE_KEY = "__ohw_styles";
|
|
433
467
|
var STYLE_SHEET_ID = "ohw-section-styles";
|
|
@@ -20927,6 +20961,7 @@ function OhhwellsBridge() {
|
|
|
20927
20961
|
applyStylesToDom(parseStyleStore(content[STYLE_STORE_KEY]));
|
|
20928
20962
|
}
|
|
20929
20963
|
applyBrandChrome(content);
|
|
20964
|
+
applyCustomCodeToHead(content);
|
|
20930
20965
|
initSectionInstancesFromContent(content, window.location.pathname);
|
|
20931
20966
|
for (const [key, val] of Object.entries(content)) {
|
|
20932
20967
|
if (key === "__ohw_sections") continue;
|
|
@@ -20935,6 +20970,7 @@ function OhhwellsBridge() {
|
|
|
20935
20970
|
if (key === STYLE_STORE_KEY) continue;
|
|
20936
20971
|
if (BRAND_CHROME_KEYS.has(key)) continue;
|
|
20937
20972
|
if (key === LOGO_PLACEHOLDER_KEY) continue;
|
|
20973
|
+
if (key === CUSTOM_CODE_AFTER_HEAD_KEY || key === CUSTOM_CODE_BEFORE_HEAD_KEY) continue;
|
|
20938
20974
|
if (LOGO_IMAGE_KEYS.includes(key)) continue;
|
|
20939
20975
|
if (applyVideoSettingNode(key, val)) continue;
|
|
20940
20976
|
if (applyCarouselNode(key, val)) continue;
|
|
@@ -23263,6 +23299,7 @@ function OhhwellsBridge() {
|
|
|
23263
23299
|
applyStylesToDom(parseStyleStore(content[STYLE_STORE_KEY]));
|
|
23264
23300
|
}
|
|
23265
23301
|
applyBrandChrome(content);
|
|
23302
|
+
applyCustomCodeToHead(content);
|
|
23266
23303
|
initSectionInstancesFromContent(content, window.location.pathname);
|
|
23267
23304
|
let sectionsJson = null;
|
|
23268
23305
|
for (const [key, val] of Object.entries(content)) {
|
|
@@ -23275,6 +23312,7 @@ function OhhwellsBridge() {
|
|
|
23275
23312
|
if (key === STYLE_STORE_KEY) continue;
|
|
23276
23313
|
if (BRAND_CHROME_KEYS.has(key)) continue;
|
|
23277
23314
|
if (key === LOGO_PLACEHOLDER_KEY) continue;
|
|
23315
|
+
if (key === CUSTOM_CODE_AFTER_HEAD_KEY || key === CUSTOM_CODE_BEFORE_HEAD_KEY) continue;
|
|
23278
23316
|
if (LOGO_IMAGE_KEYS.includes(key) && !String(val ?? "").trim()) continue;
|
|
23279
23317
|
if (applyVideoSettingNode(key, val)) continue;
|
|
23280
23318
|
if (applyCarouselNode(key, val)) continue;
|
|
@@ -23986,6 +24024,16 @@ function OhhwellsBridge() {
|
|
|
23986
24024
|
if (brandKitRef.current) {
|
|
23987
24025
|
nodes.push({ key: BRAND_KIT_KEY, type: "brand", text: brandKitRef.current });
|
|
23988
24026
|
}
|
|
24027
|
+
nodes.push({
|
|
24028
|
+
key: CUSTOM_CODE_BEFORE_HEAD_KEY,
|
|
24029
|
+
type: "text",
|
|
24030
|
+
text: editContentRef.current[CUSTOM_CODE_BEFORE_HEAD_KEY] ?? ""
|
|
24031
|
+
});
|
|
24032
|
+
nodes.push({
|
|
24033
|
+
key: CUSTOM_CODE_AFTER_HEAD_KEY,
|
|
24034
|
+
type: "text",
|
|
24035
|
+
text: editContentRef.current[CUSTOM_CODE_AFTER_HEAD_KEY] ?? ""
|
|
24036
|
+
});
|
|
23989
24037
|
document.querySelectorAll('[data-ohw-editable="form"]').forEach((form) => {
|
|
23990
24038
|
const formKey = formKeyOf(form);
|
|
23991
24039
|
if (!formKey) return;
|
|
@@ -24647,7 +24695,7 @@ function OhhwellsBridge() {
|
|
|
24647
24695
|
postToParent2({
|
|
24648
24696
|
type: "ow:ready",
|
|
24649
24697
|
version: "1",
|
|
24650
|
-
bridgeVersion: "0.1.
|
|
24698
|
+
bridgeVersion: "0.1.120",
|
|
24651
24699
|
path: pathname,
|
|
24652
24700
|
nodes: collectEditableNodes(editContentRef.current),
|
|
24653
24701
|
sections
|