@inkandswitch/patchwork-pkg-base 0.0.42 → 0.0.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkandswitch/patchwork-pkg-base",
3
- "version": "0.0.42",
3
+ "version": "0.0.43",
4
4
  "type": "module",
5
5
  "description": "Base packages for the Patchwork system",
6
6
  "repository": {
@@ -743,10 +743,25 @@ function CodeMirrorOverlay(props) {
743
743
  view?.destroy()
744
744
  })
745
745
 
746
+ // Anchor coordinates are relative to the wrapper (our offset parent). Clamp
747
+ // after CodeMirror has laid out, so the overlay can't hang off the bottom or
748
+ // the right edge of the tool.
749
+ function place(el) {
750
+ requestAnimationFrame(() => {
751
+ let parent = el.offsetParent
752
+ if (!parent) return
753
+ let top = Math.min(props.anchorRect.top, parent.clientHeight - el.offsetHeight - 8)
754
+ let left = Math.min(props.anchorRect.left, parent.clientWidth - el.offsetWidth - 8)
755
+ el.style.top = Math.max(8, top) + "px"
756
+ el.style.left = Math.max(8, left) + "px"
757
+ })
758
+ }
759
+
746
760
  let r = props.anchorRect
747
761
  let style = `top:${r.top}px;left:${r.left}px`
748
762
 
749
- return html`<div class="re-cm-overlay" style=${style}>
763
+ return html`<div class="re-cm-overlay" style=${style} ref=${place}
764
+ onKeyDown=${e => e.stopPropagation()}>
750
765
  <div class="re-cm-host" ref=${mount}></div>
751
766
  <div class="re-text-overlay-buttons">
752
767
  <span style="font-size:0.7em;opacity:0.5">Live · Esc to close</span>
@@ -839,7 +854,9 @@ function RawEditorApp(props) {
839
854
 
840
855
  // ── keyboard ──
841
856
  function onKeyDown(e) {
842
- if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "z") {
857
+ if (!element.contains(e.target)) return
858
+ let inOverlay = e.target.closest?.(".re-cm-overlay")
859
+ if (!inOverlay && (e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "z") {
843
860
  e.preventDefault()
844
861
  e.shiftKey ? redo() : undo()
845
862
  }
@@ -860,9 +877,8 @@ function RawEditorApp(props) {
860
877
  let el = anchorEl || wrapperEl
861
878
  let valRect = el.getBoundingClientRect()
862
879
  let wrapRect = wrapperEl.getBoundingClientRect()
863
- let st = scrollEl ? scrollEl.scrollTop : 0
864
880
  setEditing({pk: row.id, path: row.path, value: row.value, mode: "text",
865
- anchorRect: {top: valRect.top - wrapRect.top + st, left: valRect.left - wrapRect.left}})
881
+ anchorRect: {top: valRect.top - wrapRect.top, left: valRect.left - wrapRect.left}})
866
882
  } else {
867
883
  setEditing({pk: row.id, path: row.path, value: row.value, mode: "value"})
868
884
  }
@@ -1099,15 +1115,14 @@ function RawEditorApp(props) {
1099
1115
  </button>
1100
1116
  </div>
1101
1117
  </div>
1102
- ${() => !doc() ? html`<div class="re-loading">Loading...</div>` : html`
1103
- <div class="re-scroll" onScroll=${onScroll} ref=${setupScroll}>
1104
- <div style=${() => `height:${totalH()}px;position:relative`}>
1105
- <div style=${() => `position:absolute;top:${slabTop()}px;left:0;right:0`}>
1106
- ${() => visibleRows().map(row => renderRow(row))}
1107
- </div>
1118
+ ${() => !doc() ? html`<div class="re-loading">Loading...</div>` : ""}
1119
+ <div class="re-scroll" onScroll=${onScroll} ref=${setupScroll}>
1120
+ <div style=${() => `height:${totalH()}px;position:relative`}>
1121
+ <div style=${() => `position:absolute;top:${slabTop()}px;left:0;right:0`}>
1122
+ ${() => visibleRows().map(row => renderRow(row))}
1108
1123
  </div>
1109
1124
  </div>
1110
- `}
1125
+ </div>
1111
1126
  ${() => {
1112
1127
  let ed = editing()
1113
1128
  return ed && ed.mode === "text" ? html`<${CodeMirrorOverlay}