UNPKG

@wangeditor-next/yjs-for-react

Version:

React specific components/utils for wangeditor-next-yjs.

1 lines 32 kB
{"version":3,"file":"index.mjs","sources":["../src/hooks/use-editor-static.tsx","../src/utils/getCursorRange.ts","../src/utils/getOverlayPosition.ts","../src/utils/react-editor-to-dom-range-safe.ts","../src/hooks/useRemoteCursorEditor.ts","../../../node_modules/.pnpm/use-sync-external-store@1.6.0_react@17.0.2/node_modules/use-sync-external-store/shim/index.js","../../../node_modules/.pnpm/use-sync-external-store@1.6.0_react@17.0.2/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js","../../../node_modules/.pnpm/use-sync-external-store@1.6.0_react@17.0.2/node_modules/use-sync-external-store/shim/with-selector.js","../../../node_modules/.pnpm/use-sync-external-store@1.6.0_react@17.0.2/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js","../src/hooks/useRemoteCursorStateStore.ts","../src/hooks/useRemoteCursorStates.ts","../src/hooks/useRemoteCursorOverlayPositions.tsx","../src/hooks/utils.ts"],"sourcesContent":["import type { IDomEditor } from '@wangeditor-next/editor'\nimport { createContext, useContext } from 'react'\n\nexport const EditorContext = createContext<IDomEditor | null>(null)\n\nexport const useEditorStatic = (): IDomEditor | null => {\n const editor = useContext(EditorContext)\n\n if (!editor) {\n // throw new Error(\n // `The \\`useEditorStatic\\` hook must be used inside the <EditorContext> component's context.`\n // )\n console.warn(\n \"The `useEditorStatic` hook must be used inside the <EditorContext> component's context.\",\n )\n }\n\n return editor\n}\n","import { CursorEditor, CursorState, relativeRangeToSlateRange } from '@wangeditor-next/yjs'\nimport { BaseRange, Descendant, Range } from 'slate'\n\nconst CHILDREN_TO_CURSOR_STATE_TO_RANGE: WeakMap<\n Descendant[],\n WeakMap<CursorState, Range | null>\n> = new WeakMap()\n\nexport function getCursorRange<\n TCursorData extends Record<string, unknown> = Record<string, unknown>,\n>(editor: CursorEditor<TCursorData>, cursorState: CursorState<TCursorData>): BaseRange | null {\n if (!cursorState.relativeSelection) {\n return null\n }\n\n let cursorStates = CHILDREN_TO_CURSOR_STATE_TO_RANGE.get(editor.children)\n\n if (!cursorStates) {\n cursorStates = new WeakMap()\n CHILDREN_TO_CURSOR_STATE_TO_RANGE.set(editor.children, cursorStates)\n }\n\n let range = cursorStates.get(cursorState)\n\n if (range === undefined) {\n try {\n range = relativeRangeToSlateRange(editor.sharedRoot, editor, cursorState.relativeSelection)\n\n cursorStates.set(cursorState, range)\n } catch (e) {\n return null\n }\n }\n\n return range\n}\n","import type { IDomEditor } from '@wangeditor-next/editor'\nimport { DomEditor } from '@wangeditor-next/editor'\nimport {\n BaseRange, Editor, Path, Range, Text,\n} from 'slate'\n\nimport { reactEditorToDomRangeSafe } from './react-editor-to-dom-range-safe'\n\nexport type SelectionRect = {\n width: number\n height: number\n top: number\n left: number\n}\n\nexport type CaretPosition = {\n height: number\n top: number\n left: number\n}\n\nexport type OverlayPosition = {\n caretPosition: CaretPosition | null\n selectionRects: SelectionRect[]\n}\n\nexport type GetSelectionRectsOptions = {\n xOffset: number\n yOffset: number\n shouldGenerateOverlay?: (node: Text, path: Path) => boolean\n}\n\nexport function getOverlayPosition(\n editor: IDomEditor,\n range: BaseRange,\n { yOffset, xOffset, shouldGenerateOverlay }: GetSelectionRectsOptions,\n): OverlayPosition {\n const [start, end] = Range.edges(range)\n const domRange = reactEditorToDomRangeSafe(editor, range)\n\n if (!domRange) {\n return {\n caretPosition: null,\n selectionRects: [],\n }\n }\n\n const selectionRects: SelectionRect[] = []\n const nodeIterator = Editor.nodes(editor, {\n at: range,\n match: (n, p) => Text.isText(n) && (!shouldGenerateOverlay || shouldGenerateOverlay(n, p)),\n })\n\n let caretPosition: CaretPosition | null = null\n const isBackward = Range.isBackward(range)\n\n for (const [node, path] of nodeIterator) {\n const domNode = DomEditor.toDOMNode(editor, node)\n\n const isStartNode = Path.equals(path, start.path)\n const isEndNode = Path.equals(path, end.path)\n\n let clientRects: DOMRectList | null = null\n\n if (isStartNode || isEndNode) {\n const nodeRange = document.createRange()\n\n nodeRange.selectNode(domNode)\n\n if (isStartNode) {\n nodeRange.setStart(domRange.startContainer, domRange.startOffset)\n }\n if (isEndNode) {\n nodeRange.setEnd(domRange.endContainer, domRange.endOffset)\n }\n\n clientRects = nodeRange.getClientRects()\n } else {\n clientRects = domNode.getClientRects()\n }\n\n const isCaret = isBackward ? isStartNode : isEndNode\n\n for (let i = 0; i < clientRects.length; i += 1) {\n const clientRect = clientRects.item(i)\n\n if (!clientRect) {\n continue\n }\n\n const isCaretRect = isCaret && (isBackward ? i === 0 : i === clientRects.length - 1)\n\n const top = clientRect.top - yOffset\n const left = clientRect.left - xOffset\n\n if (isCaretRect) {\n caretPosition = {\n height: clientRect.height,\n top,\n left: left + (isBackward || Range.isCollapsed(range) ? 0 : clientRect.width),\n }\n }\n\n selectionRects.push({\n width: clientRect.width,\n height: clientRect.height,\n top,\n left,\n })\n }\n }\n\n return {\n selectionRects,\n caretPosition,\n }\n}\n","import type { IDomEditor } from '@wangeditor-next/editor'\nimport { DomEditor } from '@wangeditor-next/editor'\nimport { BaseRange } from 'slate'\n\nexport function reactEditorToDomRangeSafe(editor: IDomEditor, range: BaseRange): Range | null {\n try {\n return DomEditor.toDOMRange(editor, range)\n } catch (e) {\n return null\n }\n}\n","import type { IDomEditor } from '@wangeditor-next/editor'\nimport { CursorEditor } from '@wangeditor-next/yjs'\n\nimport { useEditorStatic } from './use-editor-static'\n\nexport function useRemoteCursorEditor<\n TCursorData extends Record<string, unknown> = Record<string, unknown>,\n>(): CursorEditor<TCursorData> & IDomEditor {\n const editor = useEditorStatic()\n\n if (!CursorEditor.isCursorEditor(editor)) {\n console.warn('Cannot use useSyncExternalStore outside the context of a RemoteCursorEditor')\n }\n\n return editor as CursorEditor & IDomEditor\n}\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('../cjs/use-sync-external-store-shim.production.js');\n} else {\n module.exports = require('../cjs/use-sync-external-store-shim.development.js');\n}\n","/**\n * @license React\n * use-sync-external-store-shim.production.js\n *\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n\"use strict\";\nvar React = require(\"react\");\nfunction is(x, y) {\n return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);\n}\nvar objectIs = \"function\" === typeof Object.is ? Object.is : is,\n useState = React.useState,\n useEffect = React.useEffect,\n useLayoutEffect = React.useLayoutEffect,\n useDebugValue = React.useDebugValue;\nfunction useSyncExternalStore$2(subscribe, getSnapshot) {\n var value = getSnapshot(),\n _useState = useState({ inst: { value: value, getSnapshot: getSnapshot } }),\n inst = _useState[0].inst,\n forceUpdate = _useState[1];\n useLayoutEffect(\n function () {\n inst.value = value;\n inst.getSnapshot = getSnapshot;\n checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });\n },\n [subscribe, value, getSnapshot]\n );\n useEffect(\n function () {\n checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });\n return subscribe(function () {\n checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });\n });\n },\n [subscribe]\n );\n useDebugValue(value);\n return value;\n}\nfunction checkIfSnapshotChanged(inst) {\n var latestGetSnapshot = inst.getSnapshot;\n inst = inst.value;\n try {\n var nextValue = latestGetSnapshot();\n return !objectIs(inst, nextValue);\n } catch (error) {\n return !0;\n }\n}\nfunction useSyncExternalStore$1(subscribe, getSnapshot) {\n return getSnapshot();\n}\nvar shim =\n \"undefined\" === typeof window ||\n \"undefined\" === typeof window.document ||\n \"undefined\" === typeof window.document.createElement\n ? useSyncExternalStore$1\n : useSyncExternalStore$2;\nexports.useSyncExternalStore =\n void 0 !== React.useSyncExternalStore ? React.useSyncExternalStore : shim;\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('../cjs/use-sync-external-store-shim/with-selector.production.js');\n} else {\n module.exports = require('../cjs/use-sync-external-store-shim/with-selector.development.js');\n}\n","/**\n * @license React\n * use-sync-external-store-shim/with-selector.production.js\n *\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n\"use strict\";\nvar React = require(\"react\"),\n shim = require(\"use-sync-external-store/shim\");\nfunction is(x, y) {\n return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);\n}\nvar objectIs = \"function\" === typeof Object.is ? Object.is : is,\n useSyncExternalStore = shim.useSyncExternalStore,\n useRef = React.useRef,\n useEffect = React.useEffect,\n useMemo = React.useMemo,\n useDebugValue = React.useDebugValue;\nexports.useSyncExternalStoreWithSelector = function (\n subscribe,\n getSnapshot,\n getServerSnapshot,\n selector,\n isEqual\n) {\n var instRef = useRef(null);\n if (null === instRef.current) {\n var inst = { hasValue: !1, value: null };\n instRef.current = inst;\n } else inst = instRef.current;\n instRef = useMemo(\n function () {\n function memoizedSelector(nextSnapshot) {\n if (!hasMemo) {\n hasMemo = !0;\n memoizedSnapshot = nextSnapshot;\n nextSnapshot = selector(nextSnapshot);\n if (void 0 !== isEqual && inst.hasValue) {\n var currentSelection = inst.value;\n if (isEqual(currentSelection, nextSnapshot))\n return (memoizedSelection = currentSelection);\n }\n return (memoizedSelection = nextSnapshot);\n }\n currentSelection = memoizedSelection;\n if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;\n var nextSelection = selector(nextSnapshot);\n if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))\n return (memoizedSnapshot = nextSnapshot), currentSelection;\n memoizedSnapshot = nextSnapshot;\n return (memoizedSelection = nextSelection);\n }\n var hasMemo = !1,\n memoizedSnapshot,\n memoizedSelection,\n maybeGetServerSnapshot =\n void 0 === getServerSnapshot ? null : getServerSnapshot;\n return [\n function () {\n return memoizedSelector(getSnapshot());\n },\n null === maybeGetServerSnapshot\n ? void 0\n : function () {\n return memoizedSelector(maybeGetServerSnapshot());\n }\n ];\n },\n [getSnapshot, getServerSnapshot, selector, isEqual]\n );\n var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);\n useEffect(\n function () {\n inst.hasValue = !0;\n inst.value = value;\n },\n [value]\n );\n useDebugValue(value);\n return value;\n};\n","import { CursorEditor, CursorState, RemoteCursorChangeEventListener } from '@wangeditor-next/yjs'\nimport { BaseEditor } from 'slate'\n\nimport { Store } from '../types'\nimport { useRemoteCursorEditor } from './useRemoteCursorEditor'\n\nexport type CursorStore<TCursorData extends Record<string, unknown> = Record<string, unknown>> =\n Store<Record<string, CursorState<TCursorData>>>\n\nconst EDITOR_TO_CURSOR_STORE: WeakMap<BaseEditor, CursorStore> = new WeakMap()\n\nfunction createRemoteCursorStateStore<TCursorData extends Record<string, unknown>>(\n editor: CursorEditor<TCursorData>,\n): CursorStore<TCursorData> {\n let cursors: Record<string, CursorState<TCursorData>> = {}\n\n const changed = new Set<number>()\n const addChanged = changed.add.bind(changed)\n const onStoreChangeListeners: Set<() => void> = new Set()\n\n let changeHandler: RemoteCursorChangeEventListener | null = null\n\n const subscribe = (onStoreChange: () => void) => {\n onStoreChangeListeners.add(onStoreChange)\n if (!changeHandler) {\n changeHandler = event => {\n event.added.forEach(addChanged)\n event.removed.forEach(addChanged)\n event.updated.forEach(addChanged)\n onStoreChangeListeners.forEach(listener => listener())\n }\n CursorEditor.on(editor, 'change', changeHandler)\n }\n\n return () => {\n onStoreChangeListeners.delete(onStoreChange)\n if (changeHandler && onStoreChangeListeners.size === 0) {\n CursorEditor.off(editor, 'change', changeHandler)\n changeHandler = null\n }\n }\n }\n\n const getSnapshot = () => {\n if (changed.size === 0) {\n return cursors\n }\n\n changed.forEach(clientId => {\n const state = CursorEditor.cursorState(editor, clientId)\n\n if (state === null) {\n delete cursors[clientId.toString()]\n return\n }\n\n cursors[clientId] = state\n })\n\n changed.clear()\n cursors = { ...cursors }\n return cursors\n }\n\n return [subscribe, getSnapshot]\n}\n\nfunction getCursorStateStore<TCursorData extends Record<string, unknown>>(\n editor: CursorEditor<TCursorData>,\n): CursorStore<TCursorData> {\n const existing = EDITOR_TO_CURSOR_STORE.get(editor)\n\n if (existing) {\n return existing as CursorStore<TCursorData>\n }\n\n const store = createRemoteCursorStateStore(editor)\n\n if (editor) { EDITOR_TO_CURSOR_STORE.set(editor, store) }\n return store\n}\n\nexport function useRemoteCursorStateStore<\n TCursorData extends Record<string, unknown> = Record<string, unknown>,\n>() {\n const editor = useRemoteCursorEditor<TCursorData>()\n\n return getCursorStateStore(editor)\n}\n","import { CursorState } from '@wangeditor-next/yjs'\nimport { useSyncExternalStore } from 'use-sync-external-store/shim'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nimport { useRemoteCursorStateStore } from './useRemoteCursorStateStore'\n\nexport function useRemoteCursorStates<\n TCursorData extends Record<string, unknown> = Record<string, unknown>,\n>() {\n const [subscribe, getSnapshot] = useRemoteCursorStateStore<TCursorData>()\n\n return useSyncExternalStore(subscribe, getSnapshot)\n}\n\nexport function useRemoteCursorStatesSelector<\n TCursorData extends Record<string, unknown> = Record<string, unknown>,\n TSelection = unknown,\n>(\n selector: (cursors: Record<string, CursorState<TCursorData>>) => TSelection,\n isEqual?: (a: TSelection, b: TSelection) => boolean,\n): TSelection {\n const [subscribe, getSnapshot] = useRemoteCursorStateStore<TCursorData>()\n\n return useSyncExternalStoreWithSelector(subscribe, getSnapshot, null, selector, isEqual)\n}\n","import type { CursorState } from '@wangeditor-next/yjs'\nimport type { RefObject } from 'react'\nimport {\n useCallback, useLayoutEffect, useMemo, useRef, useState,\n} from 'react'\nimport type { BaseRange, NodeMatch, Text } from 'slate'\n\nimport { getCursorRange } from '../utils/getCursorRange'\nimport {\n CaretPosition,\n getOverlayPosition,\n OverlayPosition,\n SelectionRect,\n} from '../utils/getOverlayPosition'\nimport { useRemoteCursorEditor } from './useRemoteCursorEditor'\nimport { useRemoteCursorStates } from './useRemoteCursorStates'\nimport { useOnResize, useRequestRerender } from './utils'\n\nconst FROZEN_EMPTY_ARRAY = Object.freeze([])\n\nexport type UseRemoteCursorOverlayPositionsOptions<T extends HTMLElement> = {\n shouldGenerateOverlay?: NodeMatch<Text>\n} & (\n | {\n // Container the overlay will be rendered in. If set, all returned overlay positions\n // will be relative to this container and the cursor positions will be automatically\n // updated on container resize.\n containerRef?: undefined\n }\n | {\n containerRef: RefObject<T>\n\n // Whether to refresh the cursor overlay positions on container resize. Defaults\n // to true. If set to 'debounced', the remote cursor positions will be updated\n // each animation frame.\n refreshOnResize?: boolean | 'debounced'\n }\n)\n\nexport type CursorOverlayData<TCursorData extends Record<string, unknown>> =\n CursorState<TCursorData> & {\n range: BaseRange | null\n caretPosition: CaretPosition | null\n selectionRects: SelectionRect[]\n }\n\nexport function useRemoteCursorOverlayPositions<\n TCursorData extends Record<string, unknown>,\n TContainer extends HTMLElement = HTMLDivElement,\n>({\n containerRef,\n shouldGenerateOverlay,\n ...opts\n}: UseRemoteCursorOverlayPositionsOptions<TContainer> = {}) {\n const editor = useRemoteCursorEditor<TCursorData>()\n const cursorStates = useRemoteCursorStates<TCursorData>()\n const requestRerender = useRequestRerender()\n\n const overlayPositionCache = useRef(new WeakMap<BaseRange, OverlayPosition>())\n const [overlayPositions, setOverlayPositions] = useState<Record<string, OverlayPosition>>({})\n\n const refreshOnResize = 'refreshOnResize' in opts ? opts.refreshOnResize ?? true : true\n\n useOnResize(refreshOnResize ? containerRef : undefined, () => {\n overlayPositionCache.current = new WeakMap()\n requestRerender(refreshOnResize !== 'debounced')\n })\n\n // Update selection rects after paint\n useLayoutEffect(() => {\n // We have a container ref but the ref is null => container\n // isn't mounted to we can't calculate the selection rects.\n if (containerRef && !containerRef.current) {\n return\n }\n\n const containerRect = containerRef?.current?.getBoundingClientRect()\n const xOffset = containerRect?.x ?? 0\n const yOffset = containerRect?.y ?? 0\n\n let overlayPositionsChanged = Object.keys(overlayPositions).length !== Object.keys(cursorStates).length\n\n const updated = Object.fromEntries(\n Object.entries(cursorStates).map(([key, state]) => {\n const range = state.relativeSelection && getCursorRange(editor, state)\n\n if (!range) {\n return [key, FROZEN_EMPTY_ARRAY]\n }\n\n const cached = overlayPositionCache.current.get(range)\n\n if (cached) {\n return [key, cached]\n }\n\n const overlayPosition = getOverlayPosition(editor, range, {\n xOffset,\n yOffset,\n shouldGenerateOverlay,\n })\n\n overlayPositionsChanged = true\n overlayPositionCache.current.set(range, overlayPosition)\n return [key, overlayPosition]\n }),\n )\n\n if (overlayPositionsChanged) {\n setOverlayPositions(updated)\n }\n })\n\n const overlayData = useMemo<CursorOverlayData<TCursorData>[]>(\n () => Object.entries(cursorStates).map(([clientId, state]) => {\n const range = state.relativeSelection && getCursorRange(editor, state)\n const overlayPosition = overlayPositions[clientId]\n\n return {\n ...state,\n range,\n caretPosition: overlayPosition?.caretPosition ?? null,\n selectionRects: overlayPosition?.selectionRects ?? FROZEN_EMPTY_ARRAY,\n }\n }),\n [cursorStates, editor, overlayPositions],\n )\n\n const refresh = useCallback(() => {\n overlayPositionCache.current = new WeakMap()\n requestRerender(true)\n }, [requestRerender])\n\n return [overlayData, refresh] as const\n}\n","import {\n RefObject, useCallback, useEffect, useReducer, useRef, useState,\n} from 'react'\n\nexport function useRequestRerender() {\n const [, rerender] = useReducer(s => s + 1, 0)\n const animationFrameIdRef = useRef<number | null>(null)\n\n const clearAnimationFrame = () => {\n if (animationFrameIdRef.current) {\n cancelAnimationFrame(animationFrameIdRef.current)\n animationFrameIdRef.current = 0\n }\n }\n\n useEffect(clearAnimationFrame)\n useEffect(() => clearAnimationFrame, [])\n\n return useCallback((immediately = false) => {\n if (immediately) {\n rerender()\n return\n }\n\n if (animationFrameIdRef.current) {\n return\n }\n\n animationFrameIdRef.current = requestAnimationFrame(rerender)\n }, [])\n}\n\nexport function useOnResize<T extends HTMLElement>(\n ref: RefObject<T> | undefined,\n onResize: () => void,\n) {\n const onResizeRef = useRef(onResize)\n\n onResizeRef.current = onResize\n\n const [observer] = useState(\n () => new ResizeObserver(() => {\n onResizeRef.current()\n }),\n )\n\n useEffect(() => {\n if (!ref?.current) {\n return\n }\n\n const { current: element } = ref\n\n observer.observe(element)\n return () => observer.unobserve(element)\n }, [observer, ref])\n}\n"],"names":["EditorContext","createContext","useEditorStatic","editor","useContext","console","warn","CHILDREN_TO_CURSOR_STATE_TO_RANGE","WeakMap","getCursorRange","cursorState","relativeSelection","cursorStates","get","children","set","range","undefined","relativeRangeToSlateRange","sharedRoot","e","getOverlayPosition","_a","yOffset","xOffset","shouldGenerateOverlay","_c","__read","Range","edges","start","end","domRange","DomEditor","toDOMRange","reactEditorToDomRangeSafe","caretPosition","selectionRects","nodeIterator","Editor","nodes","at","match","n","p","Text","isText","isBackward","nodeIterator_1","__values","nodeIterator_1_1","next","_d","value","node","path","domNode","toDOMNode","isStartNode","Path","equals","isEndNode","clientRects","nodeRange","document","createRange","selectNode","setStart","startContainer","startOffset","setEnd","endContainer","endOffset","getClientRects","isCaret","i","length","clientRect","item","isCaretRect","top_1","top","left","height","isCollapsed","width","push","useRemoteCursorEditor","CursorEditor","isCursorEditor","shimModule","exports","React","require$$0","objectIs","Object","is","x","y","useState","useEffect","useLayoutEffect","useDebugValue","checkIfSnapshotChanged","inst","latestGetSnapshot","getSnapshot","nextValue","error","shim","window","createElement","subscribe","_useState","forceUpdate","useSyncExternalStoreShim_production","useSyncExternalStore","withSelectorModule","require$$1","useRef","useMemo","withSelector_production","useSyncExternalStoreWithSelector","getServerSnapshot","selector","isEqual","instRef","current","hasValue","memoizedSelector","nextSnapshot","hasMemo","memoizedSnapshot","currentSelection","memoizedSelection","nextSelection","maybeGetServerSnapshot","EDITOR_TO_CURSOR_STORE","getCursorStateStore","existing","store","cursors","changed","Set","addChanged","add","bind","onStoreChangeListeners","changeHandler","onStoreChange","event","added","forEach","removed","updated","listener","on","delete","size","off","clientId","state","toString","clear","__assign","createRemoteCursorStateStore","useRemoteCursorStateStore","useRemoteCursorStates","useRemoteCursorStatesSelector","FROZEN_EMPTY_ARRAY","freeze","useRemoteCursorOverlayPositions","rerender","animationFrameIdRef","clearAnimationFrame","containerRef","opts","__rest","requestRerender","useReducer","s","cancelAnimationFrame","useCallback","immediately","requestAnimationFrame","overlayPositionCache","overlayPositions","setOverlayPositions","refreshOnResize","_b","ref","onResize","onResizeRef","observer","ResizeObserver","element","observe","unobserve","useOnResize","containerRect","getBoundingClientRect","overlayPositionsChanged","keys","fromEntries","entries","map","key","cached","overlayPosition","overlayData"],"mappings":"8WAGaA,EAAgBC,EAAiC,MAEjDC,EAAkB,WAC7B,IAAMC,EAASC,EAAWJ,GAW1B,OATKG,GAIHE,QAAQC,KACN,2FAIGH,CACT,+hBCfA,IAAMI,EAGF,IAAIC,QAEF,SAAUC,EAEdN,EAAmCO,GACnC,IAAKA,EAAYC,kBACf,OAAO,KAGT,IAAIC,EAAeL,EAAkCM,IAAIV,EAAOW,UAE3DF,IACHA,EAAe,IAAIJ,QACnBD,EAAkCQ,IAAIZ,EAAOW,SAAUF,IAGzD,IAAII,EAAQJ,EAAaC,IAAIH,GAE7B,QAAcO,IAAVD,EACF,IACEA,EAAQE,EAA0Bf,EAAOgB,WAAYhB,EAAQO,EAAYC,mBAEzEC,EAAaG,IAAIL,EAAaM,EAChC,CAAE,MAAOI,GACP,OAAO,IACT,CAGF,OAAOJ,CACT,UCHgBK,EACdlB,EACAa,EACAM,WAAEC,YAASC,EAAOF,EAAAE,QAAEC,EAAqBH,EAAAG,sBAEnCC,EAAAC,EAAeC,EAAMC,MAAMb,GAAM,GAAhCc,EAAKJ,EAAA,GAAEK,OACRC,EClCF,SAAoC7B,EAAoBa,GAC5D,IACE,OAAOiB,EAAUC,WAAW/B,EAAQa,EACtC,CAAE,MAAOI,GACP,OAAO,IACT,CACF,CD4BmBe,CAA0BhC,EAAQa,GAEnD,IAAKgB,EACH,MAAO,CACLI,cAAe,KACfC,eAAgB,IAIpB,IAAMA,EAAkC,GAClCC,EAAeC,EAAOC,MAAMrC,EAAQ,CACxCsC,GAAIzB,EACJ0B,MAAO,SAACC,EAAGC,GAAM,OAAAC,EAAKC,OAAOH,MAAQlB,GA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