@ohhwells/bridge 0.1.168-next.447 → 0.1.169-next.448
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 +71 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +71 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -307,6 +307,19 @@ function parseSectionsFromHtml(html) {
|
|
|
307
307
|
return parseSectionsFromRoot(doc);
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
// src/lib/soft-hide.ts
|
|
311
|
+
var PREV_DISPLAY_ATTR = "data-ohw-prev-display";
|
|
312
|
+
function softHide(el) {
|
|
313
|
+
if (!el.hasAttribute(PREV_DISPLAY_ATTR)) el.setAttribute(PREV_DISPLAY_ATTR, el.style.display);
|
|
314
|
+
el.style.display = "none";
|
|
315
|
+
}
|
|
316
|
+
function softUnhide(el) {
|
|
317
|
+
const prev = el.getAttribute(PREV_DISPLAY_ATTR);
|
|
318
|
+
el.removeAttribute(PREV_DISPLAY_ATTR);
|
|
319
|
+
if (prev) el.style.display = prev;
|
|
320
|
+
else el.style.removeProperty("display");
|
|
321
|
+
}
|
|
322
|
+
|
|
310
323
|
// src/lib/section-instances.ts
|
|
311
324
|
var SECTION_ORDER_KEY = "__ohw_section_order";
|
|
312
325
|
var REMOVED_ATTR = "data-ohw-section-removed";
|
|
@@ -378,14 +391,14 @@ function syncRemovedFlags(entries) {
|
|
|
378
391
|
const removedIds = new Set(entries.filter((e) => e.removed).map((e) => e.instanceId));
|
|
379
392
|
document.querySelectorAll(`[${REMOVED_ATTR}]`).forEach((el) => {
|
|
380
393
|
if (!removedIds.has(instanceIdOf(el))) {
|
|
381
|
-
el
|
|
394
|
+
softUnhide(el);
|
|
382
395
|
el.removeAttribute(REMOVED_ATTR);
|
|
383
396
|
}
|
|
384
397
|
});
|
|
385
398
|
for (const id of removedIds) {
|
|
386
399
|
const el = findByInstanceId(id);
|
|
387
400
|
if (el) {
|
|
388
|
-
el
|
|
401
|
+
softHide(el);
|
|
389
402
|
el.setAttribute(REMOVED_ATTR, "");
|
|
390
403
|
}
|
|
391
404
|
}
|
|
@@ -457,6 +470,15 @@ function duplicateSectionInstance(instanceId, newId, currentPath, existingEntrie
|
|
|
457
470
|
function newInstanceId() {
|
|
458
471
|
return typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `instance-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
459
472
|
}
|
|
473
|
+
function orderBeforeMove(raw, currentPath) {
|
|
474
|
+
const entries = topLevelSections().map((el, order) => ({
|
|
475
|
+
instanceId: instanceIdOf(el),
|
|
476
|
+
type: sectionTypeOf(el),
|
|
477
|
+
order,
|
|
478
|
+
pagePath: currentPath
|
|
479
|
+
}));
|
|
480
|
+
return JSON.stringify(mergePageSectionOrder(raw, currentPath, entries));
|
|
481
|
+
}
|
|
460
482
|
function getPageSectionOrderEntries(raw, currentPath) {
|
|
461
483
|
if (!raw) return [];
|
|
462
484
|
try {
|
|
@@ -5783,10 +5805,10 @@ function rekeyItemClone(clone, source, sibling, group, newIndex) {
|
|
|
5783
5805
|
function setRemoved(el, removed) {
|
|
5784
5806
|
if (removed) {
|
|
5785
5807
|
el.setAttribute(ITEM_REMOVED_ATTR, "");
|
|
5786
|
-
el
|
|
5808
|
+
softHide(el);
|
|
5787
5809
|
} else if (el.hasAttribute(ITEM_REMOVED_ATTR)) {
|
|
5788
5810
|
el.removeAttribute(ITEM_REMOVED_ATTR);
|
|
5789
|
-
el
|
|
5811
|
+
softUnhide(el);
|
|
5790
5812
|
}
|
|
5791
5813
|
}
|
|
5792
5814
|
function seedState(group) {
|
|
@@ -17796,7 +17818,7 @@ function apiBase() {
|
|
|
17796
17818
|
function bridgeVersion() {
|
|
17797
17819
|
try {
|
|
17798
17820
|
if (true) {
|
|
17799
|
-
return "0.1.
|
|
17821
|
+
return "0.1.169-next.448";
|
|
17800
17822
|
}
|
|
17801
17823
|
} catch {
|
|
17802
17824
|
}
|
|
@@ -17810,7 +17832,7 @@ function stampBridgeVersionOnDocument() {
|
|
|
17810
17832
|
return;
|
|
17811
17833
|
}
|
|
17812
17834
|
try {
|
|
17813
|
-
const v = true ? "0.1.
|
|
17835
|
+
const v = true ? "0.1.169-next.448" : "";
|
|
17814
17836
|
if (v) {
|
|
17815
17837
|
document.documentElement.setAttribute("data-ohw-bridge-version", v);
|
|
17816
17838
|
window.__OHW_BRIDGE_VERSION__ = v;
|
|
@@ -18798,7 +18820,7 @@ function highlightedRect() {
|
|
|
18798
18820
|
const rect = first.getBoundingClientRect();
|
|
18799
18821
|
return { top: rect.top + window.scrollY, bottom: rect.bottom + window.scrollY };
|
|
18800
18822
|
}
|
|
18801
|
-
function installAiChangeHighlight() {
|
|
18823
|
+
function installAiChangeHighlight(select) {
|
|
18802
18824
|
const onMessage = (e) => {
|
|
18803
18825
|
const data = e.data;
|
|
18804
18826
|
if (data?.type !== "ow:ai-highlight") return;
|
|
@@ -18807,6 +18829,8 @@ function installAiChangeHighlight() {
|
|
|
18807
18829
|
const item = raw && typeof raw.sectionId === "string" && typeof raw.group === "string" && typeof raw.index === "number" ? { sectionId: raw.sectionId, group: raw.group, index: raw.index } : void 0;
|
|
18808
18830
|
const sectionId = typeof data.sectionId === "string" ? data.sectionId : void 0;
|
|
18809
18831
|
const found = highlightChangedElements(keys, item, sectionId);
|
|
18832
|
+
const first = data.select === true ? document.querySelector(`[${MARK_ATTR}]`) : null;
|
|
18833
|
+
if (first) select?.(first);
|
|
18810
18834
|
const rect = data.reveal === true && found > 0 ? highlightedRect() : null;
|
|
18811
18835
|
window.parent?.postMessage({ type: "ow:ai-highlight-done", found, ...rect ? { rect } : {} }, "*");
|
|
18812
18836
|
};
|
|
@@ -18814,6 +18838,28 @@ function installAiChangeHighlight() {
|
|
|
18814
18838
|
return () => window.removeEventListener("message", onMessage);
|
|
18815
18839
|
}
|
|
18816
18840
|
|
|
18841
|
+
// src/lib/history-key-relay.ts
|
|
18842
|
+
var isMac = () => typeof navigator !== "undefined" && /Mac|iPhone|iPad/i.test(navigator.platform || navigator.userAgent);
|
|
18843
|
+
function historyActionFor(e, mac = isMac()) {
|
|
18844
|
+
const mod = mac ? e.metaKey : e.ctrlKey;
|
|
18845
|
+
if (!mod || e.altKey) return null;
|
|
18846
|
+
const key = e.key.toLowerCase();
|
|
18847
|
+
if (key === "z") return e.shiftKey ? "redo" : "undo";
|
|
18848
|
+
if (key === "y" && !mac) return "redo";
|
|
18849
|
+
return null;
|
|
18850
|
+
}
|
|
18851
|
+
var isEditingText = (el) => !!el && (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLElement && el.isContentEditable);
|
|
18852
|
+
function installHistoryKeyRelay() {
|
|
18853
|
+
const onKeyDown = (e) => {
|
|
18854
|
+
const action = historyActionFor(e);
|
|
18855
|
+
if (!action || isEditingText(document.activeElement)) return;
|
|
18856
|
+
e.preventDefault();
|
|
18857
|
+
window.parent?.postMessage({ type: "ow:history-key", action }, "*");
|
|
18858
|
+
};
|
|
18859
|
+
window.addEventListener("keydown", onKeyDown);
|
|
18860
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
18861
|
+
}
|
|
18862
|
+
|
|
18817
18863
|
// src/ui/ai-section/AiSectionOverlay.tsx
|
|
18818
18864
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
18819
18865
|
var findSectionElement = findByInstanceId;
|
|
@@ -19066,7 +19112,8 @@ function AiSectionOverlay({
|
|
|
19066
19112
|
window.addEventListener("message", onMessage);
|
|
19067
19113
|
return () => window.removeEventListener("message", onMessage);
|
|
19068
19114
|
}, [postToParent2]);
|
|
19069
|
-
(0, import_react12.useEffect)(() => installAiChangeHighlight(), []);
|
|
19115
|
+
(0, import_react12.useEffect)(() => installAiChangeHighlight((el) => selectFromElement(el)), [selectFromElement]);
|
|
19116
|
+
(0, import_react12.useEffect)(() => installHistoryKeyRelay(), []);
|
|
19070
19117
|
const [hoveredId, setHoveredId] = (0, import_react12.useState)(null);
|
|
19071
19118
|
(0, import_react12.useEffect)(() => {
|
|
19072
19119
|
const onMove = (e) => {
|
|
@@ -24180,12 +24227,19 @@ function useSectionDrag({
|
|
|
24180
24227
|
clearSectionDragVisuals();
|
|
24181
24228
|
return;
|
|
24182
24229
|
}
|
|
24230
|
+
const previous = orderBeforeMove(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname);
|
|
24183
24231
|
const orderJson = JSON.stringify(
|
|
24184
24232
|
mergePageSectionOrder(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname, entries)
|
|
24185
24233
|
);
|
|
24186
24234
|
editContentRef.current = { ...editContentRef.current, [SECTION_ORDER_KEY]: orderJson };
|
|
24187
24235
|
setAiSectionOrder(orderJson, window.location.pathname);
|
|
24188
|
-
postToParentRef.current({
|
|
24236
|
+
postToParentRef.current({
|
|
24237
|
+
type: "ow:change",
|
|
24238
|
+
nodes: [{ key: SECTION_ORDER_KEY, text: orderJson }],
|
|
24239
|
+
previous: { [SECTION_ORDER_KEY]: previous },
|
|
24240
|
+
// Undo scrolls to this section; a one-place move swaps two, so the order alone can't say which.
|
|
24241
|
+
moved: session.instanceId
|
|
24242
|
+
});
|
|
24189
24243
|
applyPersistedOrder(getPageSectionOrderEntries(orderJson, window.location.pathname));
|
|
24190
24244
|
clearSectionDragVisuals();
|
|
24191
24245
|
requestAnimationFrame(() => {
|
|
@@ -31698,6 +31752,7 @@ function OhhwellsBridge() {
|
|
|
31698
31752
|
const instanceId = typeof e.data.instanceId === "string" ? e.data.instanceId : "";
|
|
31699
31753
|
const direction = e.data.direction === "up" || e.data.direction === "down" ? e.data.direction : null;
|
|
31700
31754
|
if (!instanceId || !direction) return;
|
|
31755
|
+
const previous = orderBeforeMove(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname);
|
|
31701
31756
|
const entries = moveSectionInstance(instanceId, direction, window.location.pathname);
|
|
31702
31757
|
if (!entries) return;
|
|
31703
31758
|
const orderJson = JSON.stringify(
|
|
@@ -31706,7 +31761,12 @@ function OhhwellsBridge() {
|
|
|
31706
31761
|
editContentRef.current = { ...editContentRef.current, [SECTION_ORDER_KEY]: orderJson };
|
|
31707
31762
|
applyPersistedOrder(getPageSectionOrderEntries(orderJson, window.location.pathname));
|
|
31708
31763
|
setAiSectionOrder(orderJson, window.location.pathname);
|
|
31709
|
-
postToParentRef.current({
|
|
31764
|
+
postToParentRef.current({
|
|
31765
|
+
type: "ow:change",
|
|
31766
|
+
nodes: [{ key: SECTION_ORDER_KEY, text: orderJson }],
|
|
31767
|
+
previous: { [SECTION_ORDER_KEY]: previous },
|
|
31768
|
+
moved: instanceId
|
|
31769
|
+
});
|
|
31710
31770
|
window.dispatchEvent(new Event("resize"));
|
|
31711
31771
|
};
|
|
31712
31772
|
window.addEventListener("message", handleMoveSection);
|
|
@@ -32075,12 +32135,6 @@ function OhhwellsBridge() {
|
|
|
32075
32135
|
return;
|
|
32076
32136
|
}
|
|
32077
32137
|
}
|
|
32078
|
-
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "z" && !activeElRef.current) {
|
|
32079
|
-
if (runPendingDeleteUndoRef.current()) {
|
|
32080
|
-
e.preventDefault();
|
|
32081
|
-
return;
|
|
32082
|
-
}
|
|
32083
|
-
}
|
|
32084
32138
|
if (e.key !== "Escape") return;
|
|
32085
32139
|
const el = activeElRef.current;
|
|
32086
32140
|
if (el && originalContentRef.current !== null) {
|
|
@@ -33024,7 +33078,7 @@ function OhhwellsBridge() {
|
|
|
33024
33078
|
postToParent2({
|
|
33025
33079
|
type: "ow:ready",
|
|
33026
33080
|
version: "1",
|
|
33027
|
-
bridgeVersion: "0.1.
|
|
33081
|
+
bridgeVersion: "0.1.169-next.448",
|
|
33028
33082
|
path: pathname,
|
|
33029
33083
|
nodes: collectEditableNodes(editContentRef.current),
|
|
33030
33084
|
sections
|