@mantine/hooks
Version:
A collection of 50+ hooks for state and UI management
1 lines • 1.15 kB
Source Map (JSON)
{"version":3,"file":"use-text-selection.mjs","names":[],"sources":["../../src/use-text-selection/use-text-selection.ts"],"sourcesContent":["import { useEffect, useEffectEvent, useState } from 'react';\nimport { useForceUpdate } from '../use-force-update/use-force-update';\n\nexport function useTextSelection(): Selection | null {\n const forceUpdate = useForceUpdate();\n const [selection, setSelection] = useState<Selection | null>(null);\n\n const handleSelectionChange = useEffectEvent(() => {\n setSelection(document.getSelection());\n forceUpdate();\n });\n\n useEffect(() => {\n setSelection(document.getSelection());\n document.addEventListener('selectionchange', handleSelectionChange);\n return () => document.removeEventListener('selectionchange', handleSelectionChange);\n }, []);\n\n return selection;\n}\n"],"mappings":";;;;AAGA,SAAgB,mBAAqC;CACnD,MAAM,cAAc,eAAe;CACnC,MAAM,CAAC,WAAW,gBAAgB,SAA2B,IAAI;CAEjE,MAAM,wBAAwB,qBAAqB;EACjD,aAAa,SAAS,aAAa,CAAC;EACpC,YAAY;CACd,CAAC;CAED,gBAAgB;EACd,aAAa,SAAS,aAAa,CAAC;EACpC,SAAS,iBAAiB,mBAAmB,qBAAqB;EAClE,aAAa,SAAS,oBAAoB,mBAAmB,qBAAqB;CACpF,GAAG,CAAC,CAAC;CAEL,OAAO;AACT"}