UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

43 lines (42 loc) 1.34 kB
// biome-ignore lint: React is used for JSX import * as React from 'react'; import { rule, keyframes } from 'nano-theme'; import { Char } from '../../web/constants'; import { DefaultRendererColors } from './constants'; import { usePeritext } from '../../web/react'; import { useSyncStoreOpt } from '../../web/react/hooks'; export const fadeInAnimation = keyframes({ from: { tr: 'scale(0)', }, to: { tr: 'scale(1)', }, }); const blockClass = rule({ pos: 'relative', d: 'inline-block', pe: 'none', us: 'none', w: '0px', h: '100%', va: 'center', }); const innerClass = rule({ pos: 'absolute', l: 'calc(max(-6px,-0.2em))', t: '-0.05em', w: 'calc(min(12px,0.4em))', h: 'calc(min(16px,0.5em))', bdrad: '50%/20%', bg: DefaultRendererColors.ActiveCursor, an: fadeInAnimation + ' .25s ease-out', animationFillMode: 'forwards', }); export const RenderAnchor = () => { const { dom } = usePeritext(); const focus = useSyncStoreOpt(dom?.cursor.focus) || false; const style = focus ? undefined : { background: DefaultRendererColors.InactiveCursor }; return (React.createElement("span", { className: blockClass, contentEditable: false }, React.createElement("span", { className: innerClass, style: style }, Char.ZeroLengthSpace))); };