@ohhwells/bridge 0.1.36-next.46 → 0.1.36-next.47
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 +121 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +121 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4464,7 +4464,7 @@ function ItemActionToolbar({
|
|
|
4464
4464
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
4465
4465
|
ToolbarActionTooltip,
|
|
4466
4466
|
{
|
|
4467
|
-
label: "
|
|
4467
|
+
label: "Edit link",
|
|
4468
4468
|
side: tooltipSide,
|
|
4469
4469
|
buttonProps: {
|
|
4470
4470
|
onMouseDown: (e) => {
|
|
@@ -6010,6 +6010,71 @@ function clearHrefKeyHover(anchor) {
|
|
|
6010
6010
|
function isInsideNavigationItem(el) {
|
|
6011
6011
|
return getNavigationItemAnchor(el) !== null;
|
|
6012
6012
|
}
|
|
6013
|
+
function getNavigationRoot(el) {
|
|
6014
|
+
const explicit = el.closest("[data-ohw-nav-root]");
|
|
6015
|
+
if (explicit) return explicit;
|
|
6016
|
+
return el.closest("nav, footer, aside");
|
|
6017
|
+
}
|
|
6018
|
+
function findFooterItemGroup(item) {
|
|
6019
|
+
const footer = item.closest("footer");
|
|
6020
|
+
if (!footer) return null;
|
|
6021
|
+
let node = item.parentElement;
|
|
6022
|
+
while (node && node !== footer) {
|
|
6023
|
+
const hasDirectNavItems = Array.from(
|
|
6024
|
+
node.querySelectorAll(":scope > [data-ohw-href-key]")
|
|
6025
|
+
).some(isNavigationItem);
|
|
6026
|
+
if (hasDirectNavItems) return node;
|
|
6027
|
+
node = node.parentElement;
|
|
6028
|
+
}
|
|
6029
|
+
return null;
|
|
6030
|
+
}
|
|
6031
|
+
function isNavigationRoot(el) {
|
|
6032
|
+
return el.hasAttribute("data-ohw-nav-root") || el.matches("nav, footer, aside");
|
|
6033
|
+
}
|
|
6034
|
+
function isInferredFooterGroup(el) {
|
|
6035
|
+
const footer = el.closest("footer");
|
|
6036
|
+
if (!footer || el === footer) return false;
|
|
6037
|
+
return Array.from(el.querySelectorAll(":scope > [data-ohw-href-key]")).some(isNavigationItem);
|
|
6038
|
+
}
|
|
6039
|
+
function isNavigationContainer(el) {
|
|
6040
|
+
return el.hasAttribute("data-ohw-nav-container") || isNavigationRoot(el) || isInferredFooterGroup(el);
|
|
6041
|
+
}
|
|
6042
|
+
function getNavigationSelectionParent(el) {
|
|
6043
|
+
if (isNavigationItem(el)) {
|
|
6044
|
+
const explicit = el.closest("[data-ohw-nav-container]");
|
|
6045
|
+
if (explicit) return explicit;
|
|
6046
|
+
const footerGroup = findFooterItemGroup(el);
|
|
6047
|
+
if (footerGroup) return footerGroup;
|
|
6048
|
+
return getNavigationRoot(el);
|
|
6049
|
+
}
|
|
6050
|
+
if (el.hasAttribute("data-ohw-nav-container") || isInferredFooterGroup(el)) {
|
|
6051
|
+
return getNavigationRoot(el);
|
|
6052
|
+
}
|
|
6053
|
+
return null;
|
|
6054
|
+
}
|
|
6055
|
+
function placeCaretAtPoint(el, x, y) {
|
|
6056
|
+
const selection = window.getSelection();
|
|
6057
|
+
if (!selection) return;
|
|
6058
|
+
if (typeof document.caretRangeFromPoint === "function") {
|
|
6059
|
+
const range = document.caretRangeFromPoint(x, y);
|
|
6060
|
+
if (range && el.contains(range.startContainer)) {
|
|
6061
|
+
selection.removeAllRanges();
|
|
6062
|
+
selection.addRange(range);
|
|
6063
|
+
return;
|
|
6064
|
+
}
|
|
6065
|
+
}
|
|
6066
|
+
const caretPositionFromPoint = document.caretPositionFromPoint;
|
|
6067
|
+
if (typeof caretPositionFromPoint === "function") {
|
|
6068
|
+
const position = caretPositionFromPoint(x, y);
|
|
6069
|
+
if (position && el.contains(position.offsetNode)) {
|
|
6070
|
+
const range = document.createRange();
|
|
6071
|
+
range.setStart(position.offsetNode, position.offset);
|
|
6072
|
+
range.collapse(true);
|
|
6073
|
+
selection.removeAllRanges();
|
|
6074
|
+
selection.addRange(range);
|
|
6075
|
+
}
|
|
6076
|
+
}
|
|
6077
|
+
}
|
|
6013
6078
|
function collectSections() {
|
|
6014
6079
|
return collectSectionsFromDom();
|
|
6015
6080
|
}
|
|
@@ -6490,6 +6555,8 @@ function OhhwellsBridge() {
|
|
|
6490
6555
|
});
|
|
6491
6556
|
const selectRef = (0, import_react6.useRef)(() => {
|
|
6492
6557
|
});
|
|
6558
|
+
const selectFrameRef = (0, import_react6.useRef)(() => {
|
|
6559
|
+
});
|
|
6493
6560
|
const deselectRef = (0, import_react6.useRef)(() => {
|
|
6494
6561
|
});
|
|
6495
6562
|
const reselectNavigationItemRef = (0, import_react6.useRef)(() => {
|
|
@@ -6780,7 +6847,24 @@ function OhhwellsBridge() {
|
|
|
6780
6847
|
setToolbarShowEditLink(false);
|
|
6781
6848
|
setActiveCommands(/* @__PURE__ */ new Set());
|
|
6782
6849
|
}, [deactivate]);
|
|
6783
|
-
const
|
|
6850
|
+
const selectFrame = (0, import_react6.useCallback)((el) => {
|
|
6851
|
+
if (!isNavigationContainer(el)) return;
|
|
6852
|
+
if (activeElRef.current) deactivate();
|
|
6853
|
+
selectedElRef.current = el;
|
|
6854
|
+
clearHrefKeyHover(el);
|
|
6855
|
+
setHoveredItemRect(null);
|
|
6856
|
+
hoveredItemElRef.current = null;
|
|
6857
|
+
siblingHintElRef.current = null;
|
|
6858
|
+
setSiblingHintRect(null);
|
|
6859
|
+
setIsItemDragging(false);
|
|
6860
|
+
setReorderHrefKey(null);
|
|
6861
|
+
setReorderDragDisabled(false);
|
|
6862
|
+
setToolbarVariant("select-frame");
|
|
6863
|
+
setToolbarRect(el.getBoundingClientRect());
|
|
6864
|
+
setToolbarShowEditLink(false);
|
|
6865
|
+
setActiveCommands(/* @__PURE__ */ new Set());
|
|
6866
|
+
}, [deactivate]);
|
|
6867
|
+
const activate = (0, import_react6.useCallback)((el, options) => {
|
|
6784
6868
|
if (activeElRef.current === el) return;
|
|
6785
6869
|
selectedElRef.current = null;
|
|
6786
6870
|
deactivate();
|
|
@@ -6798,6 +6882,9 @@ function OhhwellsBridge() {
|
|
|
6798
6882
|
activeElRef.current = el;
|
|
6799
6883
|
originalContentRef.current = el.innerHTML;
|
|
6800
6884
|
el.focus();
|
|
6885
|
+
if (options?.caretX !== void 0 && options?.caretY !== void 0) {
|
|
6886
|
+
placeCaretAtPoint(el, options.caretX, options.caretY);
|
|
6887
|
+
}
|
|
6801
6888
|
setToolbarShowEditLink(Boolean(getHrefKeyFromElement(el)));
|
|
6802
6889
|
const navAnchor = getNavigationItemAnchor(el);
|
|
6803
6890
|
if (navAnchor) {
|
|
@@ -6815,6 +6902,7 @@ function OhhwellsBridge() {
|
|
|
6815
6902
|
activateRef.current = activate;
|
|
6816
6903
|
deactivateRef.current = deactivate;
|
|
6817
6904
|
selectRef.current = select;
|
|
6905
|
+
selectFrameRef.current = selectFrame;
|
|
6818
6906
|
deselectRef.current = deselect;
|
|
6819
6907
|
(0, import_react6.useLayoutEffect)(() => {
|
|
6820
6908
|
if (!subdomain || isEditMode) {
|
|
@@ -7076,7 +7164,7 @@ function OhhwellsBridge() {
|
|
|
7076
7164
|
e.preventDefault();
|
|
7077
7165
|
e.stopPropagation();
|
|
7078
7166
|
if (selectedElRef.current === navAnchor) {
|
|
7079
|
-
activateRef.current(editable);
|
|
7167
|
+
activateRef.current(editable, { caretX: e.clientX, caretY: e.clientY });
|
|
7080
7168
|
return;
|
|
7081
7169
|
}
|
|
7082
7170
|
selectRef.current(navAnchor);
|
|
@@ -7095,6 +7183,15 @@ function OhhwellsBridge() {
|
|
|
7095
7183
|
selectRef.current(hrefAnchor);
|
|
7096
7184
|
return;
|
|
7097
7185
|
}
|
|
7186
|
+
const selectedContainer = selectedElRef.current;
|
|
7187
|
+
if (selectedContainer && isNavigationContainer(selectedContainer)) {
|
|
7188
|
+
const navItem = getNavigationItemAnchor(target);
|
|
7189
|
+
if (!navItem && (selectedContainer === target || selectedContainer.contains(target))) {
|
|
7190
|
+
e.preventDefault();
|
|
7191
|
+
e.stopPropagation();
|
|
7192
|
+
return;
|
|
7193
|
+
}
|
|
7194
|
+
}
|
|
7098
7195
|
if (activeElRef.current) {
|
|
7099
7196
|
const sel = window.getSelection();
|
|
7100
7197
|
if (sel && !sel.isCollapsed) {
|
|
@@ -7698,7 +7795,12 @@ function OhhwellsBridge() {
|
|
|
7698
7795
|
return;
|
|
7699
7796
|
}
|
|
7700
7797
|
if (e.key === "Escape" && selectedElRef.current && !activeElRef.current) {
|
|
7701
|
-
|
|
7798
|
+
const parent = getNavigationSelectionParent(selectedElRef.current);
|
|
7799
|
+
if (parent) {
|
|
7800
|
+
selectFrameRef.current(parent);
|
|
7801
|
+
} else {
|
|
7802
|
+
deselectRef.current();
|
|
7803
|
+
}
|
|
7702
7804
|
return;
|
|
7703
7805
|
}
|
|
7704
7806
|
if (e.key === "Escape" && activeElRef.current) {
|
|
@@ -7937,7 +8039,17 @@ function OhhwellsBridge() {
|
|
|
7937
8039
|
return clientX >= r2.left && clientX <= r2.right && clientY >= r2.top && clientY <= r2.bottom;
|
|
7938
8040
|
});
|
|
7939
8041
|
if (textEditable) {
|
|
7940
|
-
|
|
8042
|
+
const hrefCtx = getHrefKeyFromElement(textEditable);
|
|
8043
|
+
const navAnchor = hrefCtx ? getNavigationItemAnchor(hrefCtx.anchor) : null;
|
|
8044
|
+
if (navAnchor) {
|
|
8045
|
+
if (selectedElRef.current === navAnchor) {
|
|
8046
|
+
activateRef.current(textEditable, { caretX: clientX, caretY: clientY });
|
|
8047
|
+
} else {
|
|
8048
|
+
selectRef.current(navAnchor);
|
|
8049
|
+
}
|
|
8050
|
+
return;
|
|
8051
|
+
}
|
|
8052
|
+
activateRef.current(textEditable, { caretX: clientX, caretY: clientY });
|
|
7941
8053
|
return;
|
|
7942
8054
|
}
|
|
7943
8055
|
deactivateRef.current();
|
|
@@ -8119,25 +8231,25 @@ function OhhwellsBridge() {
|
|
|
8119
8231
|
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { ref: attachVisibleViewport, "data-ohw-visible-viewport": "", "aria-hidden": true }),
|
|
8120
8232
|
siblingHintRect && !isItemDragging && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ItemInteractionLayer, { rect: siblingHintRect, state: "sibling-hint" }),
|
|
8121
8233
|
hoveredItemRect && !siblingHintRect && !isItemDragging && hoveredItemElRef.current !== selectedElRef.current && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ItemInteractionLayer, { rect: hoveredItemRect, state: "hover" }),
|
|
8122
|
-
toolbarRect && toolbarVariant === "link-action" && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
8234
|
+
toolbarRect && (toolbarVariant === "link-action" || toolbarVariant === "select-frame") && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
8123
8235
|
ItemInteractionLayer,
|
|
8124
8236
|
{
|
|
8125
8237
|
rect: toolbarRect,
|
|
8126
8238
|
elRef: glowElRef,
|
|
8127
8239
|
state: isItemDragging ? "dragging" : resolveItemInteractionState(toolbarRect, parentScrollRef.current),
|
|
8128
|
-
showHandle: Boolean(reorderHrefKey),
|
|
8240
|
+
showHandle: toolbarVariant === "link-action" && Boolean(reorderHrefKey),
|
|
8129
8241
|
dragDisabled: reorderDragDisabled,
|
|
8130
8242
|
dragHandleLabel: reorderHrefKey ? `Reorder ${reorderHrefKey}` : "Reorder item",
|
|
8131
8243
|
onDragHandleDragStart: handleItemDragStart,
|
|
8132
8244
|
onDragHandleDragEnd: handleItemDragEnd,
|
|
8133
|
-
toolbar:
|
|
8245
|
+
toolbar: toolbarVariant === "link-action" && !isItemDragging ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
8134
8246
|
ItemActionToolbar,
|
|
8135
8247
|
{
|
|
8136
8248
|
onEditLink: openLinkPopoverForSelected,
|
|
8137
8249
|
onAddItem: handleAddNavigationItem,
|
|
8138
8250
|
addItemDisabled: false
|
|
8139
8251
|
}
|
|
8140
|
-
)
|
|
8252
|
+
) : void 0
|
|
8141
8253
|
}
|
|
8142
8254
|
),
|
|
8143
8255
|
toolbarRect && toolbarVariant === "rich-text" && /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
|