UNPKG

@lobehub/editor

Version:

A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.

43 lines 1.5 kB
import { debounce } from 'es-toolkit/compat'; import { isHTMLElement } from 'lexical'; import { useMemo, useRef } from 'react'; export function getThemeSelector(iEditor, name) { var _iEditor$getTheme; var className = (_iEditor$getTheme = iEditor.getTheme()) === null || _iEditor$getTheme === void 0 ? void 0 : _iEditor$getTheme[name]; if (typeof className !== 'string') { throw new Error("getThemeClass: required theme property ".concat(name, " not defined")); } return className.split(/\s+/g).map(function (cls) { return ".".concat(cls); }).join(','); } export function getMouseInfo(event, iEditor) { var target = event.target; var tableCellClass = getThemeSelector(iEditor, 'tableCell'); if (isHTMLElement(target)) { var tableDOMNode = target.closest("td".concat(tableCellClass, ", th").concat(tableCellClass)); var isOutside = !(tableDOMNode || target.closest("div.tableAddRows") || target.closest("div.tableAddColumns") || target.closest('div.TableCellResizer__resizer')); return { isOutside: isOutside, tableDOMNode: tableDOMNode }; } else { return { isOutside: true, tableDOMNode: null }; } } export function useDebounce(fn, ms, maxWait) { var funcRef = useRef(null); funcRef.current = fn; return useMemo(function () { return debounce(function () { if (funcRef.current) { funcRef.current.apply(funcRef, arguments); } }, ms, { maxWait: maxWait }); }, [ms, maxWait]); }