@ohhwells/bridge 0.1.36-next.45 → 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.js CHANGED
@@ -4405,7 +4405,7 @@ function ItemActionToolbar({
4405
4405
  /* @__PURE__ */ jsx8(
4406
4406
  ToolbarActionTooltip,
4407
4407
  {
4408
- label: "Add link",
4408
+ label: "Edit link",
4409
4409
  side: tooltipSide,
4410
4410
  buttonProps: {
4411
4411
  onMouseDown: (e) => {
@@ -5951,6 +5951,71 @@ function clearHrefKeyHover(anchor) {
5951
5951
  function isInsideNavigationItem(el) {
5952
5952
  return getNavigationItemAnchor(el) !== null;
5953
5953
  }
5954
+ function getNavigationRoot(el) {
5955
+ const explicit = el.closest("[data-ohw-nav-root]");
5956
+ if (explicit) return explicit;
5957
+ return el.closest("nav, footer, aside");
5958
+ }
5959
+ function findFooterItemGroup(item) {
5960
+ const footer = item.closest("footer");
5961
+ if (!footer) return null;
5962
+ let node = item.parentElement;
5963
+ while (node && node !== footer) {
5964
+ const hasDirectNavItems = Array.from(
5965
+ node.querySelectorAll(":scope > [data-ohw-href-key]")
5966
+ ).some(isNavigationItem);
5967
+ if (hasDirectNavItems) return node;
5968
+ node = node.parentElement;
5969
+ }
5970
+ return null;
5971
+ }
5972
+ function isNavigationRoot(el) {
5973
+ return el.hasAttribute("data-ohw-nav-root") || el.matches("nav, footer, aside");
5974
+ }
5975
+ function isInferredFooterGroup(el) {
5976
+ const footer = el.closest("footer");
5977
+ if (!footer || el === footer) return false;
5978
+ return Array.from(el.querySelectorAll(":scope > [data-ohw-href-key]")).some(isNavigationItem);
5979
+ }
5980
+ function isNavigationContainer(el) {
5981
+ return el.hasAttribute("data-ohw-nav-container") || isNavigationRoot(el) || isInferredFooterGroup(el);
5982
+ }
5983
+ function getNavigationSelectionParent(el) {
5984
+ if (isNavigationItem(el)) {
5985
+ const explicit = el.closest("[data-ohw-nav-container]");
5986
+ if (explicit) return explicit;
5987
+ const footerGroup = findFooterItemGroup(el);
5988
+ if (footerGroup) return footerGroup;
5989
+ return getNavigationRoot(el);
5990
+ }
5991
+ if (el.hasAttribute("data-ohw-nav-container") || isInferredFooterGroup(el)) {
5992
+ return getNavigationRoot(el);
5993
+ }
5994
+ return null;
5995
+ }
5996
+ function placeCaretAtPoint(el, x, y) {
5997
+ const selection = window.getSelection();
5998
+ if (!selection) return;
5999
+ if (typeof document.caretRangeFromPoint === "function") {
6000
+ const range = document.caretRangeFromPoint(x, y);
6001
+ if (range && el.contains(range.startContainer)) {
6002
+ selection.removeAllRanges();
6003
+ selection.addRange(range);
6004
+ return;
6005
+ }
6006
+ }
6007
+ const caretPositionFromPoint = document.caretPositionFromPoint;
6008
+ if (typeof caretPositionFromPoint === "function") {
6009
+ const position = caretPositionFromPoint(x, y);
6010
+ if (position && el.contains(position.offsetNode)) {
6011
+ const range = document.createRange();
6012
+ range.setStart(position.offsetNode, position.offset);
6013
+ range.collapse(true);
6014
+ selection.removeAllRanges();
6015
+ selection.addRange(range);
6016
+ }
6017
+ }
6018
+ }
5954
6019
  function collectSections() {
5955
6020
  return collectSectionsFromDom();
5956
6021
  }
@@ -6431,6 +6496,8 @@ function OhhwellsBridge() {
6431
6496
  });
6432
6497
  const selectRef = useRef3(() => {
6433
6498
  });
6499
+ const selectFrameRef = useRef3(() => {
6500
+ });
6434
6501
  const deselectRef = useRef3(() => {
6435
6502
  });
6436
6503
  const reselectNavigationItemRef = useRef3(() => {
@@ -6721,7 +6788,24 @@ function OhhwellsBridge() {
6721
6788
  setToolbarShowEditLink(false);
6722
6789
  setActiveCommands(/* @__PURE__ */ new Set());
6723
6790
  }, [deactivate]);
6724
- const activate = useCallback3((el) => {
6791
+ const selectFrame = useCallback3((el) => {
6792
+ if (!isNavigationContainer(el)) return;
6793
+ if (activeElRef.current) deactivate();
6794
+ selectedElRef.current = el;
6795
+ clearHrefKeyHover(el);
6796
+ setHoveredItemRect(null);
6797
+ hoveredItemElRef.current = null;
6798
+ siblingHintElRef.current = null;
6799
+ setSiblingHintRect(null);
6800
+ setIsItemDragging(false);
6801
+ setReorderHrefKey(null);
6802
+ setReorderDragDisabled(false);
6803
+ setToolbarVariant("select-frame");
6804
+ setToolbarRect(el.getBoundingClientRect());
6805
+ setToolbarShowEditLink(false);
6806
+ setActiveCommands(/* @__PURE__ */ new Set());
6807
+ }, [deactivate]);
6808
+ const activate = useCallback3((el, options) => {
6725
6809
  if (activeElRef.current === el) return;
6726
6810
  selectedElRef.current = null;
6727
6811
  deactivate();
@@ -6739,6 +6823,9 @@ function OhhwellsBridge() {
6739
6823
  activeElRef.current = el;
6740
6824
  originalContentRef.current = el.innerHTML;
6741
6825
  el.focus();
6826
+ if (options?.caretX !== void 0 && options?.caretY !== void 0) {
6827
+ placeCaretAtPoint(el, options.caretX, options.caretY);
6828
+ }
6742
6829
  setToolbarShowEditLink(Boolean(getHrefKeyFromElement(el)));
6743
6830
  const navAnchor = getNavigationItemAnchor(el);
6744
6831
  if (navAnchor) {
@@ -6756,6 +6843,7 @@ function OhhwellsBridge() {
6756
6843
  activateRef.current = activate;
6757
6844
  deactivateRef.current = deactivate;
6758
6845
  selectRef.current = select;
6846
+ selectFrameRef.current = selectFrame;
6759
6847
  deselectRef.current = deselect;
6760
6848
  useLayoutEffect2(() => {
6761
6849
  if (!subdomain || isEditMode) {
@@ -7017,7 +7105,7 @@ function OhhwellsBridge() {
7017
7105
  e.preventDefault();
7018
7106
  e.stopPropagation();
7019
7107
  if (selectedElRef.current === navAnchor) {
7020
- activateRef.current(editable);
7108
+ activateRef.current(editable, { caretX: e.clientX, caretY: e.clientY });
7021
7109
  return;
7022
7110
  }
7023
7111
  selectRef.current(navAnchor);
@@ -7036,6 +7124,15 @@ function OhhwellsBridge() {
7036
7124
  selectRef.current(hrefAnchor);
7037
7125
  return;
7038
7126
  }
7127
+ const selectedContainer = selectedElRef.current;
7128
+ if (selectedContainer && isNavigationContainer(selectedContainer)) {
7129
+ const navItem = getNavigationItemAnchor(target);
7130
+ if (!navItem && (selectedContainer === target || selectedContainer.contains(target))) {
7131
+ e.preventDefault();
7132
+ e.stopPropagation();
7133
+ return;
7134
+ }
7135
+ }
7039
7136
  if (activeElRef.current) {
7040
7137
  const sel = window.getSelection();
7041
7138
  if (sel && !sel.isCollapsed) {
@@ -7639,7 +7736,12 @@ function OhhwellsBridge() {
7639
7736
  return;
7640
7737
  }
7641
7738
  if (e.key === "Escape" && selectedElRef.current && !activeElRef.current) {
7642
- deselectRef.current();
7739
+ const parent = getNavigationSelectionParent(selectedElRef.current);
7740
+ if (parent) {
7741
+ selectFrameRef.current(parent);
7742
+ } else {
7743
+ deselectRef.current();
7744
+ }
7643
7745
  return;
7644
7746
  }
7645
7747
  if (e.key === "Escape" && activeElRef.current) {
@@ -7878,7 +7980,17 @@ function OhhwellsBridge() {
7878
7980
  return clientX >= r2.left && clientX <= r2.right && clientY >= r2.top && clientY <= r2.bottom;
7879
7981
  });
7880
7982
  if (textEditable) {
7881
- activateRef.current(textEditable);
7983
+ const hrefCtx = getHrefKeyFromElement(textEditable);
7984
+ const navAnchor = hrefCtx ? getNavigationItemAnchor(hrefCtx.anchor) : null;
7985
+ if (navAnchor) {
7986
+ if (selectedElRef.current === navAnchor) {
7987
+ activateRef.current(textEditable, { caretX: clientX, caretY: clientY });
7988
+ } else {
7989
+ selectRef.current(navAnchor);
7990
+ }
7991
+ return;
7992
+ }
7993
+ activateRef.current(textEditable, { caretX: clientX, caretY: clientY });
7882
7994
  return;
7883
7995
  }
7884
7996
  deactivateRef.current();
@@ -8060,25 +8172,25 @@ function OhhwellsBridge() {
8060
8172
  /* @__PURE__ */ jsx21("div", { ref: attachVisibleViewport, "data-ohw-visible-viewport": "", "aria-hidden": true }),
8061
8173
  siblingHintRect && !isItemDragging && /* @__PURE__ */ jsx21(ItemInteractionLayer, { rect: siblingHintRect, state: "sibling-hint" }),
8062
8174
  hoveredItemRect && !siblingHintRect && !isItemDragging && hoveredItemElRef.current !== selectedElRef.current && /* @__PURE__ */ jsx21(ItemInteractionLayer, { rect: hoveredItemRect, state: "hover" }),
8063
- toolbarRect && toolbarVariant === "link-action" && /* @__PURE__ */ jsx21(
8175
+ toolbarRect && (toolbarVariant === "link-action" || toolbarVariant === "select-frame") && /* @__PURE__ */ jsx21(
8064
8176
  ItemInteractionLayer,
8065
8177
  {
8066
8178
  rect: toolbarRect,
8067
8179
  elRef: glowElRef,
8068
8180
  state: isItemDragging ? "dragging" : resolveItemInteractionState(toolbarRect, parentScrollRef.current),
8069
- showHandle: Boolean(reorderHrefKey),
8181
+ showHandle: toolbarVariant === "link-action" && Boolean(reorderHrefKey),
8070
8182
  dragDisabled: reorderDragDisabled,
8071
8183
  dragHandleLabel: reorderHrefKey ? `Reorder ${reorderHrefKey}` : "Reorder item",
8072
8184
  onDragHandleDragStart: handleItemDragStart,
8073
8185
  onDragHandleDragEnd: handleItemDragEnd,
8074
- toolbar: isItemDragging ? void 0 : /* @__PURE__ */ jsx21(
8186
+ toolbar: toolbarVariant === "link-action" && !isItemDragging ? /* @__PURE__ */ jsx21(
8075
8187
  ItemActionToolbar,
8076
8188
  {
8077
8189
  onEditLink: openLinkPopoverForSelected,
8078
8190
  onAddItem: handleAddNavigationItem,
8079
8191
  addItemDisabled: false
8080
8192
  }
8081
- )
8193
+ ) : void 0
8082
8194
  }
8083
8195
  ),
8084
8196
  toolbarRect && toolbarVariant === "rich-text" && /* @__PURE__ */ jsxs11(Fragment3, { children: [