@ohhwells/bridge 0.1.90 → 0.1.91
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 +31 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +31 -78
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8046,9 +8046,6 @@ var LINK_PICKER_EXCLUDED_IDS = /* @__PURE__ */ new Set(["navbar", "footer"]);
|
|
|
8046
8046
|
function isChromeSection(el) {
|
|
8047
8047
|
return el.matches("header, nav, footer, aside");
|
|
8048
8048
|
}
|
|
8049
|
-
function isSchedulingSection(el) {
|
|
8050
|
-
return (el.dataset.ohwSection ?? "").startsWith("scheduling-");
|
|
8051
|
-
}
|
|
8052
8049
|
function titleCaseSectionId(id) {
|
|
8053
8050
|
return id.split("-").filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
8054
8051
|
}
|
|
@@ -8084,50 +8081,12 @@ function isRemovedSection(el) {
|
|
|
8084
8081
|
}
|
|
8085
8082
|
function topLevelSections() {
|
|
8086
8083
|
return Array.from(document.querySelectorAll("[data-ohw-section]")).filter(
|
|
8087
|
-
(el) => !el.parentElement?.closest("[data-ohw-section]") && !isChromeSection(el) && !
|
|
8084
|
+
(el) => !el.parentElement?.closest("[data-ohw-section]") && !isChromeSection(el) && !isRemovedSection(el)
|
|
8088
8085
|
);
|
|
8089
8086
|
}
|
|
8090
8087
|
function instanceIdOf(el) {
|
|
8091
8088
|
return el.dataset.ohwInstance ?? el.dataset.ohwSection ?? "";
|
|
8092
8089
|
}
|
|
8093
|
-
function moveableSequence() {
|
|
8094
|
-
const scheduling = Array.from(
|
|
8095
|
-
document.querySelectorAll('[data-ohw-section-container="scheduling"]')
|
|
8096
|
-
);
|
|
8097
|
-
return [...topLevelSections(), ...scheduling].sort((a, b) => {
|
|
8098
|
-
const pos = a.compareDocumentPosition(b);
|
|
8099
|
-
if (pos & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
|
|
8100
|
-
if (pos & Node.DOCUMENT_POSITION_PRECEDING) return 1;
|
|
8101
|
-
return 0;
|
|
8102
|
-
});
|
|
8103
|
-
}
|
|
8104
|
-
function planSchedulingMoveTarget(instanceId, direction) {
|
|
8105
|
-
const inner = document.querySelector(`[data-ohw-section="${CSS.escape(instanceId)}"]`);
|
|
8106
|
-
const wrapper = inner?.closest('[data-ohw-section-container="scheduling"]');
|
|
8107
|
-
if (!wrapper) return null;
|
|
8108
|
-
const sequence = moveableSequence();
|
|
8109
|
-
const index = sequence.indexOf(wrapper);
|
|
8110
|
-
if (index === -1) return null;
|
|
8111
|
-
const siblingIndex = direction === "up" ? index - 1 : index + 1;
|
|
8112
|
-
if (siblingIndex < 0 || siblingIndex >= sequence.length) return null;
|
|
8113
|
-
const others = sequence.filter((_, i) => i !== index);
|
|
8114
|
-
const clamped = Math.max(0, Math.min(siblingIndex, others.length));
|
|
8115
|
-
if (clamped === 0) return null;
|
|
8116
|
-
const newPrev = others[clamped - 1];
|
|
8117
|
-
if (newPrev.hasAttribute("data-ohw-section-container")) return null;
|
|
8118
|
-
const newAnchorId = instanceIdOf(newPrev);
|
|
8119
|
-
if (!newAnchorId) return null;
|
|
8120
|
-
return { wrapper, others, clamped, newAnchorId };
|
|
8121
|
-
}
|
|
8122
|
-
function canMoveSchedulingSection(instanceId, direction) {
|
|
8123
|
-
return planSchedulingMoveTarget(instanceId, direction) !== null;
|
|
8124
|
-
}
|
|
8125
|
-
function planSchedulingMove(instanceId, direction) {
|
|
8126
|
-
const plan = planSchedulingMoveTarget(instanceId, direction);
|
|
8127
|
-
if (!plan) return null;
|
|
8128
|
-
plan.others[plan.clamped - 1].after(plan.wrapper);
|
|
8129
|
-
return { newAnchorId: plan.newAnchorId };
|
|
8130
|
-
}
|
|
8131
8090
|
function findByInstanceId(instanceId) {
|
|
8132
8091
|
const escapedId = CSS.escape(instanceId);
|
|
8133
8092
|
return document.querySelector(`[data-ohw-instance="${escapedId}"]`) ?? document.querySelector(`[data-ohw-section="${escapedId}"]:not([data-ohw-instance])`);
|
|
@@ -8333,12 +8292,6 @@ function useLiveSectionRect(sectionId) {
|
|
|
8333
8292
|
return rect;
|
|
8334
8293
|
}
|
|
8335
8294
|
function computeSectionBoundaryFlags(instanceId) {
|
|
8336
|
-
if (instanceId.startsWith("scheduling-")) {
|
|
8337
|
-
return {
|
|
8338
|
-
isFirst: !canMoveSchedulingSection(instanceId, "up"),
|
|
8339
|
-
isLast: !canMoveSchedulingSection(instanceId, "down")
|
|
8340
|
-
};
|
|
8341
|
-
}
|
|
8342
8295
|
const topLevel = topLevelSections();
|
|
8343
8296
|
const index = topLevel.findIndex((el) => (el.dataset.ohwInstance ?? el.dataset.ohwSection) === instanceId);
|
|
8344
8297
|
if (index === -1) return { isFirst: true, isLast: true };
|
|
@@ -14934,21 +14887,14 @@ function updateSectionScheduleId(insertAfter, scheduleId) {
|
|
|
14934
14887
|
tracker.textContent = JSON.stringify(updated);
|
|
14935
14888
|
return tracker.textContent ?? "[]";
|
|
14936
14889
|
}
|
|
14937
|
-
|
|
14938
|
-
|
|
14939
|
-
|
|
14940
|
-
|
|
14941
|
-
|
|
14942
|
-
|
|
14890
|
+
var schedulingRoots = /* @__PURE__ */ new WeakMap();
|
|
14891
|
+
function unmountSchedulingWrapper(wrapper) {
|
|
14892
|
+
const root = schedulingRoots.get(wrapper);
|
|
14893
|
+
if (root) {
|
|
14894
|
+
schedulingRoots.delete(wrapper);
|
|
14895
|
+
setTimeout(() => root.unmount(), 0);
|
|
14943
14896
|
}
|
|
14944
|
-
|
|
14945
|
-
const updated = sections.map((s) => {
|
|
14946
|
-
if (s.type !== "scheduling" || s.insertAfter !== oldInsertAfter) return s;
|
|
14947
|
-
if (s.pagePath && s.pagePath !== currentPath) return s;
|
|
14948
|
-
return { ...s, insertAfter: newInsertAfter };
|
|
14949
|
-
});
|
|
14950
|
-
tracker.textContent = JSON.stringify(updated);
|
|
14951
|
-
return tracker.textContent ?? "[]";
|
|
14897
|
+
wrapper.remove();
|
|
14952
14898
|
}
|
|
14953
14899
|
function schedulingSectionId(insertAfter) {
|
|
14954
14900
|
return `scheduling-${insertAfter}`;
|
|
@@ -15003,12 +14949,12 @@ function retryMissingSchedulingMounts(entries, notifyOnConnect = false) {
|
|
|
15003
14949
|
if (!hasMissingSchedulingWidgets(entries)) return;
|
|
15004
14950
|
mountSchedulingEntries(entries, notifyOnConnect);
|
|
15005
14951
|
}
|
|
15006
|
-
function initSectionsFromContent(content, removeExisting = false) {
|
|
14952
|
+
function initSectionsFromContent(content, removeExisting = false, currentPath = typeof window !== "undefined" ? window.location.pathname : "/") {
|
|
15007
14953
|
const raw = content["__ohw_sections"];
|
|
15008
14954
|
if (!raw) return;
|
|
15009
14955
|
try {
|
|
15010
14956
|
if (removeExisting) {
|
|
15011
|
-
document.querySelectorAll('[data-ohw-section-container="scheduling"]').forEach((el) => el
|
|
14957
|
+
document.querySelectorAll('[data-ohw-section-container="scheduling"]').forEach((el) => unmountSchedulingWrapper(el));
|
|
15012
14958
|
}
|
|
15013
14959
|
const inEditor = typeof window !== "undefined" && window.self !== window.top;
|
|
15014
14960
|
if (inEditor) getSectionsTracker().textContent = raw;
|
|
@@ -15016,8 +14962,16 @@ function initSectionsFromContent(content, removeExisting = false) {
|
|
|
15016
14962
|
const preExisting = pageEntries.filter((e) => !isSchedulingWidgetMissing(e));
|
|
15017
14963
|
const notifyForEntry = inEditor ? (e) => !e.scheduleId : false;
|
|
15018
14964
|
mountSchedulingEntries(pageEntries, notifyForEntry);
|
|
15019
|
-
|
|
15020
|
-
|
|
14965
|
+
const reapplyOrder = () => applyPersistedOrder(getPageSectionOrderEntries(content[SECTION_ORDER_KEY], currentPath));
|
|
14966
|
+
reapplyOrder();
|
|
14967
|
+
requestAnimationFrame(() => {
|
|
14968
|
+
retryMissingSchedulingMounts(pageEntries, notifyForEntry);
|
|
14969
|
+
reapplyOrder();
|
|
14970
|
+
});
|
|
14971
|
+
setTimeout(() => {
|
|
14972
|
+
retryMissingSchedulingMounts(pageEntries, notifyForEntry);
|
|
14973
|
+
reapplyOrder();
|
|
14974
|
+
}, 250);
|
|
15021
14975
|
for (const entry of preExisting) {
|
|
15022
14976
|
window.postMessage({ type: "ow:schedule-config", insertAfter: entry.insertAfter, scheduleId: entry.scheduleId ?? null }, "*");
|
|
15023
14977
|
}
|
|
@@ -15032,6 +14986,8 @@ function mountSchedulingWidget(insertAfter, notifyOnConnect = false, scheduleId,
|
|
|
15032
14986
|
if (!mountPoint) return false;
|
|
15033
14987
|
const container = document.createElement("div");
|
|
15034
14988
|
container.dataset.ohwSectionContainer = "scheduling";
|
|
14989
|
+
container.dataset.ohwSection = sectionId;
|
|
14990
|
+
container.dataset.ohwInstance = sectionId;
|
|
15035
14991
|
if (insertBefore) {
|
|
15036
14992
|
const beforeAnchor = document.querySelector(`[data-ohw-section="${insertBefore}"]`);
|
|
15037
14993
|
const beforePoint = beforeAnchor?.closest('[data-ohw-section-container="scheduling"]') ?? beforeAnchor;
|
|
@@ -15045,6 +15001,7 @@ function mountSchedulingWidget(insertAfter, notifyOnConnect = false, scheduleId,
|
|
|
15045
15001
|
tail.insertAdjacentElement("afterend", container);
|
|
15046
15002
|
}
|
|
15047
15003
|
const root = createRoot2(container);
|
|
15004
|
+
schedulingRoots.set(container, root);
|
|
15048
15005
|
flushSync2(() => {
|
|
15049
15006
|
root.render(
|
|
15050
15007
|
/* @__PURE__ */ jsx33(
|
|
@@ -20320,15 +20277,6 @@ function OhhwellsBridge() {
|
|
|
20320
20277
|
const instanceId = typeof e.data.instanceId === "string" ? e.data.instanceId : "";
|
|
20321
20278
|
const direction = e.data.direction === "up" || e.data.direction === "down" ? e.data.direction : null;
|
|
20322
20279
|
if (!instanceId || !direction) return;
|
|
20323
|
-
if (instanceId.startsWith("scheduling-")) {
|
|
20324
|
-
const result = planSchedulingMove(instanceId, direction);
|
|
20325
|
-
if (!result) return;
|
|
20326
|
-
const oldInsertAfter = instanceId.slice("scheduling-".length);
|
|
20327
|
-
const sectionsJson = updateSchedulingInsertAfter(oldInsertAfter, result.newAnchorId);
|
|
20328
|
-
postToParentRef.current({ type: "ow:change", nodes: [{ key: "__ohw_sections", text: sectionsJson }] });
|
|
20329
|
-
window.dispatchEvent(new Event("resize"));
|
|
20330
|
-
return;
|
|
20331
|
-
}
|
|
20332
20280
|
const entries = moveSectionInstance(instanceId, direction, window.location.pathname);
|
|
20333
20281
|
if (!entries) return;
|
|
20334
20282
|
const orderJson = JSON.stringify(entries);
|
|
@@ -20350,8 +20298,13 @@ function OhhwellsBridge() {
|
|
|
20350
20298
|
if (!instanceId) return;
|
|
20351
20299
|
if (instanceId.startsWith("scheduling-")) {
|
|
20352
20300
|
const insertAfter = instanceId.slice("scheduling-".length);
|
|
20353
|
-
const
|
|
20354
|
-
|
|
20301
|
+
const el = document.querySelector(`[data-ohw-section="${CSS.escape(instanceId)}"]`);
|
|
20302
|
+
const wrapper = el?.closest('[data-ohw-section-container="scheduling"]') ?? null;
|
|
20303
|
+
if (wrapper) {
|
|
20304
|
+
unmountSchedulingWrapper(wrapper);
|
|
20305
|
+
} else {
|
|
20306
|
+
el?.setAttribute("style", "display:none");
|
|
20307
|
+
}
|
|
20355
20308
|
const tracker = getSectionsTracker();
|
|
20356
20309
|
let sections = [];
|
|
20357
20310
|
try {
|
|
@@ -21330,7 +21283,7 @@ function OhhwellsBridge() {
|
|
|
21330
21283
|
postToParent2({
|
|
21331
21284
|
type: "ow:ready",
|
|
21332
21285
|
version: "1",
|
|
21333
|
-
bridgeVersion: "0.1.
|
|
21286
|
+
bridgeVersion: "0.1.90",
|
|
21334
21287
|
path: pathname,
|
|
21335
21288
|
nodes: collectEditableNodes(editContentRef.current),
|
|
21336
21289
|
sections
|