diff --git a/eslint.config.js b/eslint.config.js index 4f333977..2a8b5801 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -32,6 +32,18 @@ export default defineESLintConfig( 'react-hooks/refs': 'error', // https://github.com/facebook/react/blob/d083ec1da1e5252abd3ddfdde6dfbc09701a2c51/compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts#L981-L988 'react-hooks/todo': 'error', + 'react-hooks/capitalized-calls': 'error', + 'react-hooks/exhaustive-effect-dependencies': 'error', + 'react-hooks/fbt': 'error', + 'react-hooks/hooks': 'error', + 'react-hooks/incompatible-library': 'error', + 'react-hooks/invariant': 'error', + 'react-hooks/memo-dependencies': 'error', + 'react-hooks/memoized-effect-dependencies': 'error', + 'react-hooks/no-deriving-state-in-effects': 'error', + 'react-hooks/rule-suppression': 'error', + 'react-hooks/syntax': 'error', + 'react-hooks/unsupported-syntax': 'error', }, }, meowdownConfig, diff --git a/website/src/components/selection-demo.tsx b/website/src/components/selection-demo.tsx index b7a6f750..9a173627 100644 --- a/website/src/components/selection-demo.tsx +++ b/website/src/components/selection-demo.tsx @@ -86,6 +86,18 @@ interface DemoRun { cancelled: boolean } +function streamText(run: DemoRun, text: string, append: (chunk: string) => void): void { + let offset = 0 + const timer = setInterval(() => { + if (run.cancelled || offset >= text.length) { + clearInterval(timer) + return + } + append(text.slice(offset, offset + STREAM_CHUNK_SIZE)) + offset += STREAM_CHUNK_SIZE + }, STREAM_INTERVAL_MS) +} + const ACTION_BUTTON_CLASS = 'inline-flex cursor-pointer items-center rounded-lg border-0 bg-transparent px-2.5 py-1 [font:inherit] whitespace-nowrap text-stone-600 hover:bg-stone-100 dark:text-stone-300 dark:hover:bg-stone-800' @@ -143,18 +155,9 @@ export function useSelectionDemo(handleRef: RefObject): Sel const run: DemoRun = { command, context, cancelled: false } runRef.current = run - const result = command.transform(context.selectedText) - let offset = 0 - const timer = setInterval(() => { - if (run.cancelled || offset >= result.length) { - clearInterval(timer) - return - } - handleRef.current?.appendPendingReplacementText( - result.slice(offset, offset + STREAM_CHUNK_SIZE), - ) - offset += STREAM_CHUNK_SIZE - }, STREAM_INTERVAL_MS) + streamText(run, command.transform(context.selectedText), (chunk) => { + handleRef.current?.appendPendingReplacementText(chunk) + }) }, [handleRef], )