reflet-sdk 0.6.1 → 0.6.3

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.
@@ -809,7 +809,7 @@ function collectPageContext(options) {
809
809
  }
810
810
  //#endregion
811
811
  //#region src/feedback/types.ts
812
- const SDK_VERSION = "0.6.1";
812
+ const SDK_VERSION = "0.6.3";
813
813
  const DEFAULT_WIDGET_LABELS = {
814
814
  annotateHint: "Draw on the screenshot to point at the problem.",
815
815
  attachElement: "Attach this element",
@@ -1665,7 +1665,6 @@ function stepAim(from, key, backwards) {
1665
1665
  //#region src/feedback/ui/picker.tsx
1666
1666
  const LABEL_HEIGHT = 24;
1667
1667
  const LABEL_GAP = 6;
1668
- const NOTE_WIDTH = 300;
1669
1668
  const NOTE_GAP = 10;
1670
1669
  const EDGE_GAP = 12;
1671
1670
  function elementUnder(x, y) {
@@ -1682,35 +1681,69 @@ function describeTarget(element) {
1682
1681
  region: describeRegion(element)
1683
1682
  };
1684
1683
  }
1685
- /**
1686
- * Pins the note card to the element: below it, flipped above when the visible
1687
- * viewport — what is left of the screen once a mobile keyboard is up — has no
1688
- * room there. Measures against the part of the element actually on screen, so
1689
- * picking a full-height section still leaves the card in view.
1690
- */
1691
- function noteStyle(rect, view) {
1692
- const left = Math.min(Math.max(view.left + EDGE_GAP, rect.left), Math.max(view.left + EDGE_GAP, view.left + view.width - NOTE_WIDTH - EDGE_GAP));
1693
- const visibleTop = Math.max(rect.top, view.top + EDGE_GAP);
1694
- const visibleBottom = Math.min(rect.bottom, view.top + view.height - EDGE_GAP);
1695
- if (view.top + view.height - visibleBottom > visibleTop - view.top) return {
1684
+ function noteCardPosition(rect, view, card) {
1685
+ const viewLeft = view.left + EDGE_GAP;
1686
+ const viewRight = view.left + view.width - EDGE_GAP;
1687
+ const viewTop = view.top + EDGE_GAP;
1688
+ const viewBottom = view.top + view.height - EDGE_GAP;
1689
+ const fitLeft = (left) => Math.max(viewLeft, Math.min(left, viewRight - card.width));
1690
+ const fitTop = (top) => Math.max(viewTop, Math.min(top, viewBottom - card.height));
1691
+ const below = rect.bottom + NOTE_GAP;
1692
+ if (below >= viewTop && below + card.height <= viewBottom) return {
1693
+ left: fitLeft(rect.left),
1694
+ top: below
1695
+ };
1696
+ const above = rect.top - NOTE_GAP - card.height;
1697
+ if (above >= viewTop && rect.top <= viewBottom) return {
1698
+ left: fitLeft(rect.left),
1699
+ top: above
1700
+ };
1701
+ const besideTop = fitTop(rect.top);
1702
+ const right = rect.right + NOTE_GAP;
1703
+ if (right + card.width <= viewRight) return {
1704
+ left: right,
1705
+ top: besideTop
1706
+ };
1707
+ const left = rect.left - NOTE_GAP - card.width;
1708
+ if (left >= viewLeft) return {
1696
1709
  left,
1697
- top: visibleBottom + NOTE_GAP
1710
+ top: besideTop
1698
1711
  };
1699
1712
  return {
1700
- bottom: window.innerHeight - visibleTop + NOTE_GAP,
1701
- left
1713
+ left: fitLeft(rect.left),
1714
+ top: fitTop(Math.min(rect.bottom, viewBottom) - card.height)
1702
1715
  };
1703
1716
  }
1704
- function ElementPicker({ inspect, labels, onCancel, onPick }) {
1717
+ function labelTop(rect, view) {
1718
+ const above = rect.top - LABEL_HEIGHT - LABEL_GAP;
1719
+ if (above >= view.top) return above;
1720
+ const below = rect.bottom + LABEL_GAP;
1721
+ if (below + LABEL_HEIGHT <= view.top + view.height) return below;
1722
+ return Math.max(rect.top, view.top) + LABEL_GAP;
1723
+ }
1724
+ const APPLE_PLATFORM = /Mac|iPhone|iPad/;
1725
+ function ElementPicker({ copy, inspect, labels, onCancel, onPick }) {
1705
1726
  const [target, setTarget] = useState(null);
1706
1727
  const [pinned, setPinned] = useState(null);
1707
1728
  const [note, setNote] = useState("");
1729
+ const [noteSize, setNoteSize] = useState({
1730
+ height: 0,
1731
+ width: 0
1732
+ });
1708
1733
  const pickerRef = useRef(null);
1734
+ const noteCardRef = useRef(null);
1709
1735
  const noteRef = useRef(null);
1710
1736
  const pinnedRef = useRef(false);
1711
1737
  const [view, setView] = useState(visibleViewport);
1712
1738
  const aimRef = useRef(null);
1713
1739
  useEffect(() => onViewportChange(() => setView(visibleViewport())), []);
1740
+ useLayoutEffect(() => {
1741
+ const card = noteCardRef.current;
1742
+ if (pinned && card) setNoteSize({
1743
+ height: card.offsetHeight,
1744
+ width: card.offsetWidth
1745
+ });
1746
+ }, [pinned]);
1714
1747
  useEffect(() => {
1715
1748
  pinnedRef.current = pinned !== null;
1716
1749
  if (pinned) noteRef.current?.focus({ preventScroll: true });
@@ -1770,13 +1803,20 @@ function ElementPicker({ inspect, labels, onCancel, onPick }) {
1770
1803
  }
1771
1804
  onCancel();
1772
1805
  };
1806
+ const copyAimed = (event) => {
1807
+ const aimed = aimRef.current;
1808
+ if (!((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "c" && copy && aimed)) return false;
1809
+ swallow(event);
1810
+ copy.onCopy(aimed, "");
1811
+ return true;
1812
+ };
1773
1813
  const onKeyDown = (event) => {
1774
1814
  if (event.key === "Escape") {
1775
1815
  swallow(event);
1776
1816
  onEscape();
1777
1817
  return;
1778
1818
  }
1779
- if (pinnedRef.current || startsInWidget(event)) return;
1819
+ if (pinnedRef.current || startsInWidget(event) || copyAimed(event)) return;
1780
1820
  if (event.key === "Enter") {
1781
1821
  swallow(event);
1782
1822
  if (aimRef.current) pin(aimRef.current, event.shiftKey);
@@ -1820,10 +1860,14 @@ function ElementPicker({ inspect, labels, onCancel, onPick }) {
1820
1860
  window.removeEventListener("scroll", onScroll, true);
1821
1861
  document.body.style.cursor = previousCursor;
1822
1862
  };
1823
- }, [inspect, onCancel]);
1863
+ }, [
1864
+ copy,
1865
+ inspect,
1866
+ onCancel
1867
+ ]);
1824
1868
  const rect = (pinned ?? target)?.rect;
1825
- const labelAbove = rect ? rect.top > 30 : true;
1826
1869
  return /* @__PURE__ */ jsxs("div", {
1870
+ className: "picker",
1827
1871
  ref: pickerRef,
1828
1872
  children: [
1829
1873
  rect && /* @__PURE__ */ jsx("div", {
@@ -1837,7 +1881,7 @@ function ElementPicker({ inspect, labels, onCancel, onPick }) {
1837
1881
  }),
1838
1882
  rect && target && !pinned && /* @__PURE__ */ jsxs("div", {
1839
1883
  className: "picker-label",
1840
- style: { translate: `${Math.max(4, rect.left)}px ${labelAbove ? rect.top - LABEL_HEIGHT - LABEL_GAP : rect.bottom + LABEL_GAP}px` },
1884
+ style: { translate: `${Math.max(4, rect.left)}px ${labelTop(rect, view)}px` },
1841
1885
  children: [/* @__PURE__ */ jsx("strong", { children: target.componentName ? `<${target.componentName}>` : target.label }), target.region && /* @__PURE__ */ jsx("span", { children: target.region })]
1842
1886
  }),
1843
1887
  pinned ? /* @__PURE__ */ jsxs("form", {
@@ -1846,7 +1890,8 @@ function ElementPicker({ inspect, labels, onCancel, onPick }) {
1846
1890
  event.preventDefault();
1847
1891
  onPick(pinned.element, note.trim());
1848
1892
  },
1849
- style: noteStyle(pinned.rect, view),
1893
+ ref: noteCardRef,
1894
+ style: noteCardPosition(pinned.rect, view, noteSize),
1850
1895
  children: [
1851
1896
  /* @__PURE__ */ jsxs("p", {
1852
1897
  className: "picker-note-target",
@@ -1885,6 +1930,12 @@ function ElementPicker({ inspect, labels, onCancel, onPick }) {
1885
1930
  type: "button",
1886
1931
  children: inspect.label
1887
1932
  }),
1933
+ copy && /* @__PURE__ */ jsx("button", {
1934
+ className: "picker-cancel",
1935
+ onClick: () => copy.onCopy(pinned.element, note.trim()),
1936
+ type: "button",
1937
+ children: copy.label
1938
+ }),
1888
1939
  /* @__PURE__ */ jsx("button", {
1889
1940
  "aria-label": labels.attachElement,
1890
1941
  className: "submit",
@@ -1905,6 +1956,7 @@ function ElementPicker({ inspect, labels, onCancel, onPick }) {
1905
1956
  /* @__PURE__ */ jsx("kbd", { children: "Tab" }),
1906
1957
  /* @__PURE__ */ jsx("kbd", { children: "Enter" }),
1907
1958
  inspect && /* @__PURE__ */ jsx("kbd", { children: "⇧ Click" }),
1959
+ copy && /* @__PURE__ */ jsx("kbd", { children: APPLE_PLATFORM.test(navigator.userAgent) ? "⌘C" : "Ctrl C" }),
1908
1960
  /* @__PURE__ */ jsx("kbd", { children: "Esc" })
1909
1961
  ]
1910
1962
  }), /* @__PURE__ */ jsx("button", {
@@ -1920,4 +1972,4 @@ function ElementPicker({ inspect, labels, onCancel, onPick }) {
1920
1972
  //#endregion
1921
1973
  export { TargetIcon as A, buildElementSelection as B, GripIcon as C, SpotlightIcon as D, PencilIcon as E, normalizeRect as F, WIDGET_MARKER as G, getFiberFromNode as H, DEFAULT_WIDGET_LABELS as I, releaseCapture as J, captureViewport as K, SDK_VERSION as L, TrashIcon as M, UndoIcon as N, SquareIcon as O, isDegenerate as P, collectPageContext as R, CloseIcon as S, MoreIcon as T, resolveComponentStack as U, describeElement as V, shortenSourcePath as W, BlurIcon as _, deriveTitle as a, CheckIcon as b, useFloatingPosition as c, SelectionOutline as d, drawAnnotations as f, ArrowIcon as g, stopClicksAtHost as h, createFeedbackTransport as i, TextIcon as j, Svg as k, onViewportChange as l, listenToKeydown as m, isWidgetOwned as n, submitWidgetFeedback as o, listenOnPageAndWidget as p, capturedFromCanvas as q, attachPreparedScreenshots as r, uploadImageBlob as s, ElementPicker as t, visibleViewport as u, CameraIcon as v, HighlightIcon as w, ChevronDownIcon as x, ChatIcon as y, MAX_SELECTION_COMMENT_LENGTH as z };
1922
1974
 
1923
- //# sourceMappingURL=picker-C_apeUEq.js.map
1975
+ //# sourceMappingURL=picker-Rh-hsxyX.js.map