MCPcopy Create free account
hub / github.com/pacexy/flow / TextSelectionMenuRenderer

Function TextSelectionMenuRenderer

apps/reader/src/components/TextSelectionMenu.tsx:117–324  ·  view source on GitHub ↗
({
  tab,
  range,
  anchorRect,
  containerRect,
  viewRect,
  forward,
  text,
  hide,
})

Source from the content-addressed store, hash-verified

115 hide: () => void
116}
117const TextSelectionMenuRenderer: React.FC<TextSelectionMenuRendererProps> = ({
118 tab,
119 range,
120 anchorRect,
121 containerRect,
122 viewRect,
123 forward,
124 text,
125 hide,
126}) => {
127 const setAction = useSetAction()
128 const ref = useRef<HTMLInputElement>(null)
129 const [width, setWidth] = useState(0)
130 const [height, setHeight] = useState(0)
131 const mobile = useMobile()
132 const t = useTranslation('menu')
133
134 const cfi = tab.rangeToCfi(range)
135 const annotation = tab.book.annotations.find((a) => a.cfi === cfi)
136 const [annotate, setAnnotate] = useState(!!annotation)
137
138 const position = forward
139 ? LayoutAnchorPosition.Before
140 : LayoutAnchorPosition.After
141
142 const { zoom } = useTypography(tab)
143 const endContainer = forward ? range.endContainer : range.startContainer
144 const _lineHeight = parseFloat(
145 getComputedStyle(endContainer.parentElement!).lineHeight,
146 )
147 // no custom line height and the origin is keyword, e.g. 'normal'.
148 const lineHeight = isNaN(_lineHeight)
149 ? anchorRect.height
150 : _lineHeight * (zoom ?? 1)
151
152 return (
153 <FocusLock disabled={mobile}>
154 <Overlay
155 // cover `sash`
156 className="!z-50 !bg-transparent"
157 onMouseDown={hide}
158 />
159 <div
160 ref={(el) => {
161 if (!el) return
162 setWidth(el.clientWidth)
163 setHeight(el.clientHeight)
164 if (!mobile) {
165 el.focus()
166 }
167 }}
168 className={clsx(
169 'bg-surface text-on-surface-variant shadow-1 absolute z-50 p-2 focus:outline-none',
170 )}
171 style={{
172 left: layout(containerRect.width, width, {
173 offset: anchorRect.left + viewRect.left - containerRect.left,
174 size: anchorRect.width,

Callers

nothing calls this directly

Calls 15

useSetActionFunction · 0.90
useMobileFunction · 0.90
useTranslationFunction · 0.90
useTypographyFunction · 0.90
layoutFunction · 0.90
copyFunction · 0.90
keysFunction · 0.90
scaleFunction · 0.90
rangeToCfiMethod · 0.80
setKeywordMethod · 0.80
isDefinedMethod · 0.80
undefineMethod · 0.80

Tested by

no test coverage detected