From 1a33254f14d5f898f06ae03047492e0c1984ed26 Mon Sep 17 00:00:00 2001 From: Krystian Sienkiewicz Date: Fri, 14 Aug 2026 20:59:55 +0200 Subject: [PATCH] refactor: cleaned up web/src structure --- src/web/EnrichedText.tsx | 12 +++++----- src/web/EnrichedTextInput.tsx | 22 +++++++++---------- .../assertBrowserEnvironment.dom.test.ts | 2 +- .../assertBrowserEnvironment.ssr.test.ts | 2 +- .../returnKeyTypeToEnterKeyHint.test.ts | 2 +- src/web/formats/EnrichedLink.ts | 2 +- .../formats/applyWrappingListToSelection.ts | 5 ++++- .../useImageErrorFallback.ts | 0 .../useOrderedListMarkerWidth.ts | 0 .../usePressInteractions.ts | 2 +- .../adaptWebToNativeEvent.ts | 0 .../{ => nativeMappers}/positionMapping.ts | 0 .../returnKeyTypeToEnterKeyHint.ts | 0 src/web/pmPlugins/AutolinkPlugin/index.ts | 4 ++-- .../{ => tiptapWatchers}/emitLinkDetected.ts | 2 +- .../{ => tiptapWatchers}/useOnChangeHtml.ts | 4 ++-- .../{ => tiptapWatchers}/useOnChangeState.ts | 8 +++---- .../{ => tiptapWatchers}/useOnChangeText.ts | 4 ++-- .../{ => tiptapWatchers}/useOnEditorChange.ts | 2 +- .../{ => tiptapWatchers}/useOnLinkDetected.ts | 2 +- .../{ => utils}/assertBrowserEnvironment.ts | 0 src/web/{ => utils}/pasteImages.ts | 6 ++--- src/web/{ => utils}/pastedImageDimensions.ts | 0 src/web/{ => utils}/useStableRef.ts | 0 24 files changed, 42 insertions(+), 39 deletions(-) rename src/web/{ => htmlExtensions}/useImageErrorFallback.ts (100%) rename src/web/{ => htmlExtensions}/useOrderedListMarkerWidth.ts (100%) rename src/web/{ => htmlExtensions}/usePressInteractions.ts (96%) rename src/web/{ => nativeMappers}/adaptWebToNativeEvent.ts (100%) rename src/web/{ => nativeMappers}/positionMapping.ts (100%) rename src/web/{ => nativeMappers}/returnKeyTypeToEnterKeyHint.ts (100%) rename src/web/{ => tiptapWatchers}/emitLinkDetected.ts (93%) rename src/web/{ => tiptapWatchers}/useOnChangeHtml.ts (75%) rename src/web/{ => tiptapWatchers}/useOnChangeState.ts (94%) rename src/web/{ => tiptapWatchers}/useOnChangeText.ts (78%) rename src/web/{ => tiptapWatchers}/useOnEditorChange.ts (91%) rename src/web/{ => tiptapWatchers}/useOnLinkDetected.ts (96%) rename src/web/{ => utils}/assertBrowserEnvironment.ts (100%) rename src/web/{ => utils}/pasteImages.ts (93%) rename src/web/{ => utils}/pastedImageDimensions.ts (100%) rename src/web/{ => utils}/useStableRef.ts (100%) diff --git a/src/web/EnrichedText.tsx b/src/web/EnrichedText.tsx index 6584c98c6..ecf2927af 100644 --- a/src/web/EnrichedText.tsx +++ b/src/web/EnrichedText.tsx @@ -17,13 +17,13 @@ import { buildMentionRulesCSS } from './styleConversion/buildMentionRulesCSS'; import { sanitizeHtml } from './sanitization/htmlSanitizer'; import { prepareHtmlForWeb } from './normalization/prepareHtmlForWeb'; import { INLINE_IMAGE_CSS_VARIABLES } from './styleConversion/inlineImageCSSVariables'; -import { useImageErrorFallback } from './useImageErrorFallback'; -import { usePressInteractions } from './usePressInteractions'; +import { useImageErrorFallback } from './htmlExtensions/useImageErrorFallback'; +import { usePressInteractions } from './htmlExtensions/usePressInteractions'; import { useEllipsizeMode } from './ellipsizeMode/useEllipsizeMode'; -import { adaptWebToNativeEvent } from './adaptWebToNativeEvent'; -import { useStableRef } from './useStableRef'; -import { assertBrowserEnvironment } from './assertBrowserEnvironment'; -import { useOrderedListMarkerWidth } from './useOrderedListMarkerWidth'; +import { adaptWebToNativeEvent } from './nativeMappers/adaptWebToNativeEvent'; +import { useStableRef } from './utils/useStableRef'; +import { assertBrowserEnvironment } from './utils/assertBrowserEnvironment'; +import { useOrderedListMarkerWidth } from './htmlExtensions/useOrderedListMarkerWidth'; export const EnrichedText = memo( ({ diff --git a/src/web/EnrichedTextInput.tsx b/src/web/EnrichedTextInput.tsx index 692dec9e7..fecc1ee74 100644 --- a/src/web/EnrichedTextInput.tsx +++ b/src/web/EnrichedTextInput.tsx @@ -12,12 +12,12 @@ import type { EnrichedTextInputInstance, EnrichedTextInputProps, } from '../types'; -import { adaptWebToNativeEvent } from './adaptWebToNativeEvent'; +import { adaptWebToNativeEvent } from './nativeMappers/adaptWebToNativeEvent'; import { tiptapPosToNativePos, nativePosToTiptapPos, nativeLeafText, -} from './positionMapping'; +} from './nativeMappers/positionMapping'; import { useEditor, EditorContent, @@ -29,11 +29,11 @@ import Paragraph from '@tiptap/extension-paragraph'; import Text from '@tiptap/extension-text'; import History from '@tiptap/extension-history'; import { Placeholder } from '@tiptap/extensions/placeholder'; -import { useOnChangeHtml } from './useOnChangeHtml'; -import { useOnChangeText } from './useOnChangeText'; -import { useOnChangeState } from './useOnChangeState'; -import { useOnLinkDetected } from './useOnLinkDetected'; -import type { LinkEmitterState } from './emitLinkDetected'; +import { useOnChangeHtml } from './tiptapWatchers/useOnChangeHtml'; +import { useOnChangeText } from './tiptapWatchers/useOnChangeText'; +import { useOnChangeState } from './tiptapWatchers/useOnChangeState'; +import { useOnLinkDetected } from './tiptapWatchers/useOnLinkDetected'; +import type { LinkEmitterState } from './tiptapWatchers/emitLinkDetected'; import { prepareHtmlForTiptap, normalizeHtmlFromTiptap, @@ -68,7 +68,7 @@ import { StrictMarksPlugin } from './pmPlugins/StrictMarksPlugin'; import { MergeAdjacentSameKindBlocksPlugin } from './pmPlugins/MergeAdjacentSameKindBlocksPlugin'; import { OrderedListMarkerWidthPlugin } from './pmPlugins/OrderedListMarkerWidthPlugin'; import { StripMarksInCodeBlockPlugin } from './pmPlugins/StripMarksInCodeBlockPlugin'; -import { handleClipboardPasteImages } from './pasteImages'; +import { handleClipboardPasteImages } from './utils/pasteImages'; import { MentionPlugin, setMention, @@ -78,15 +78,15 @@ import { import { StripMarksOnImagePlugin } from './pmPlugins/StripMarksOnImagePlugin'; import { ShortcutPlugin } from './pmPlugins/ShortcutPlugin'; import { TextShortcutsPlugin } from './pmPlugins/TextShortcutsPlugin'; -import { returnKeyTypeToEnterKeyHint } from './returnKeyTypeToEnterKeyHint'; +import { returnKeyTypeToEnterKeyHint } from './nativeMappers/returnKeyTypeToEnterKeyHint'; import { ENRICHED_TEXT_INPUT_CLASSNAME } from './constants/classNames'; import { AutolinkPlugin } from './pmPlugins/AutolinkPlugin'; -import { useStableRef } from './useStableRef'; +import { useStableRef } from './utils/useStableRef'; import { checkMentionAttributes, sanitizeMentionAttributes, } from './sanitization/htmlSanitizer'; -import { assertBrowserEnvironment } from './assertBrowserEnvironment'; +import { assertBrowserEnvironment } from './utils/assertBrowserEnvironment'; function runFocused( editor: Editor, diff --git a/src/web/__tests__/assertBrowserEnvironment.dom.test.ts b/src/web/__tests__/assertBrowserEnvironment.dom.test.ts index 5bb67f5d1..62fe881d9 100644 --- a/src/web/__tests__/assertBrowserEnvironment.dom.test.ts +++ b/src/web/__tests__/assertBrowserEnvironment.dom.test.ts @@ -1,4 +1,4 @@ -import { assertBrowserEnvironment } from '../assertBrowserEnvironment'; +import { assertBrowserEnvironment } from '../utils/assertBrowserEnvironment'; describe('assertBrowserEnvironment', () => { // jsdom provides a full DOM, so the browser APIs are present by default. diff --git a/src/web/__tests__/assertBrowserEnvironment.ssr.test.ts b/src/web/__tests__/assertBrowserEnvironment.ssr.test.ts index 6035147be..8c6e3bf81 100644 --- a/src/web/__tests__/assertBrowserEnvironment.ssr.test.ts +++ b/src/web/__tests__/assertBrowserEnvironment.ssr.test.ts @@ -2,7 +2,7 @@ * @jest-environment node */ // Because of the docblock above, jsdom test environment does not exist here -import { assertBrowserEnvironment } from '../assertBrowserEnvironment'; +import { assertBrowserEnvironment } from '../utils/assertBrowserEnvironment'; describe('assertBrowserEnvironment', () => { test('throws when DOM is missing', () => { diff --git a/src/web/__tests__/returnKeyTypeToEnterKeyHint.test.ts b/src/web/__tests__/returnKeyTypeToEnterKeyHint.test.ts index fe4489101..03c22c062 100644 --- a/src/web/__tests__/returnKeyTypeToEnterKeyHint.test.ts +++ b/src/web/__tests__/returnKeyTypeToEnterKeyHint.test.ts @@ -1,4 +1,4 @@ -import { returnKeyTypeToEnterKeyHint } from '../returnKeyTypeToEnterKeyHint'; +import { returnKeyTypeToEnterKeyHint } from '../nativeMappers/returnKeyTypeToEnterKeyHint'; describe('returnKeyTypeToEnterKeyHint', () => { test.each([ diff --git a/src/web/formats/EnrichedLink.ts b/src/web/formats/EnrichedLink.ts index 3e0476b8e..838708b34 100644 --- a/src/web/formats/EnrichedLink.ts +++ b/src/web/formats/EnrichedLink.ts @@ -2,7 +2,7 @@ import Link, { type LinkOptions } from '@tiptap/extension-link'; import { mergeAttributes, type CommandProps } from '@tiptap/core'; import type { Editor } from '@tiptap/react'; -import { nativePosToTiptapPos } from '../positionMapping'; +import { nativePosToTiptapPos } from '../nativeMappers/positionMapping'; import { isLinkBlocked } from './formatRules'; import { findAutolinkRangesInWord } from '../pmPlugins/AutolinkPlugin/autolinkRegex'; diff --git a/src/web/formats/applyWrappingListToSelection.ts b/src/web/formats/applyWrappingListToSelection.ts index fc06442b7..e0b6258d2 100644 --- a/src/web/formats/applyWrappingListToSelection.ts +++ b/src/web/formats/applyWrappingListToSelection.ts @@ -3,7 +3,10 @@ import type { Node } from '@tiptap/pm/model'; import { Fragment } from '@tiptap/pm/model'; import { TextSelection } from '@tiptap/pm/state'; -import { nativePosToTiptapPos, tiptapPosToNativePos } from '../positionMapping'; +import { + nativePosToTiptapPos, + tiptapPosToNativePos, +} from '../nativeMappers/positionMapping'; import { withPreservedAlignment } from './formatRules'; /** diff --git a/src/web/useImageErrorFallback.ts b/src/web/htmlExtensions/useImageErrorFallback.ts similarity index 100% rename from src/web/useImageErrorFallback.ts rename to src/web/htmlExtensions/useImageErrorFallback.ts diff --git a/src/web/useOrderedListMarkerWidth.ts b/src/web/htmlExtensions/useOrderedListMarkerWidth.ts similarity index 100% rename from src/web/useOrderedListMarkerWidth.ts rename to src/web/htmlExtensions/useOrderedListMarkerWidth.ts diff --git a/src/web/usePressInteractions.ts b/src/web/htmlExtensions/usePressInteractions.ts similarity index 96% rename from src/web/usePressInteractions.ts rename to src/web/htmlExtensions/usePressInteractions.ts index 9768b442e..9b0e5c179 100644 --- a/src/web/usePressInteractions.ts +++ b/src/web/htmlExtensions/usePressInteractions.ts @@ -1,5 +1,5 @@ import { useEffect, type RefObject } from 'react'; -import type { OnLinkPressEvent, OnMentionPressEvent } from '../types'; +import type { OnLinkPressEvent, OnMentionPressEvent } from '../../types'; type OnLinkPressEventRef = RefObject< ((event: OnLinkPressEvent) => void) | undefined diff --git a/src/web/adaptWebToNativeEvent.ts b/src/web/nativeMappers/adaptWebToNativeEvent.ts similarity index 100% rename from src/web/adaptWebToNativeEvent.ts rename to src/web/nativeMappers/adaptWebToNativeEvent.ts diff --git a/src/web/positionMapping.ts b/src/web/nativeMappers/positionMapping.ts similarity index 100% rename from src/web/positionMapping.ts rename to src/web/nativeMappers/positionMapping.ts diff --git a/src/web/returnKeyTypeToEnterKeyHint.ts b/src/web/nativeMappers/returnKeyTypeToEnterKeyHint.ts similarity index 100% rename from src/web/returnKeyTypeToEnterKeyHint.ts rename to src/web/nativeMappers/returnKeyTypeToEnterKeyHint.ts diff --git a/src/web/pmPlugins/AutolinkPlugin/index.ts b/src/web/pmPlugins/AutolinkPlugin/index.ts index 97f86db05..32d72203a 100644 --- a/src/web/pmPlugins/AutolinkPlugin/index.ts +++ b/src/web/pmPlugins/AutolinkPlugin/index.ts @@ -6,8 +6,8 @@ import type { OnLinkDetected } from '../../../types'; import { emitLinkDetected, type LinkEmitterState, -} from '../../emitLinkDetected'; -import { tiptapPosToNativePos } from '../../positionMapping'; +} from '../../tiptapWatchers/emitLinkDetected'; +import { tiptapPosToNativePos } from '../../nativeMappers/positionMapping'; import { findAutolinkRangesInWord } from './autolinkRegex'; interface Run { diff --git a/src/web/emitLinkDetected.ts b/src/web/tiptapWatchers/emitLinkDetected.ts similarity index 93% rename from src/web/emitLinkDetected.ts rename to src/web/tiptapWatchers/emitLinkDetected.ts index 0cc07a4a1..44d11586a 100644 --- a/src/web/emitLinkDetected.ts +++ b/src/web/tiptapWatchers/emitLinkDetected.ts @@ -1,5 +1,5 @@ import type { RefObject } from 'react'; -import type { OnLinkDetected } from '../types'; +import type { OnLinkDetected } from '../../types'; export interface LinkEmitterState { linkRegex?: RegExp | null; diff --git a/src/web/useOnChangeHtml.ts b/src/web/tiptapWatchers/useOnChangeHtml.ts similarity index 75% rename from src/web/useOnChangeHtml.ts rename to src/web/tiptapWatchers/useOnChangeHtml.ts index f3cb0991b..5939b8f42 100644 --- a/src/web/useOnChangeHtml.ts +++ b/src/web/tiptapWatchers/useOnChangeHtml.ts @@ -1,8 +1,8 @@ import { type Editor } from '@tiptap/react'; -import type { OnChangeHtmlEvent, SanitizationConfig } from '../types'; +import type { OnChangeHtmlEvent, SanitizationConfig } from '../../types'; import type { NativeSyntheticEvent } from 'react-native'; import { useOnEditorChange } from './useOnEditorChange'; -import { normalizeHtmlFromTiptap } from './normalization/tiptapHtmlNormalizer'; +import { normalizeHtmlFromTiptap } from '../normalization/tiptapHtmlNormalizer'; export const useOnChangeHtml = ( editor: Editor, diff --git a/src/web/useOnChangeState.ts b/src/web/tiptapWatchers/useOnChangeState.ts similarity index 94% rename from src/web/useOnChangeState.ts rename to src/web/tiptapWatchers/useOnChangeState.ts index 3d36dc8ee..cdee4b57b 100644 --- a/src/web/useOnChangeState.ts +++ b/src/web/tiptapWatchers/useOnChangeState.ts @@ -1,14 +1,14 @@ import { useEffect, useRef } from 'react'; import { type Editor } from '@tiptap/react'; -import type { OnChangeStateEvent } from '../types'; +import type { OnChangeStateEvent } from '../../types'; import type { NativeSyntheticEvent } from 'react-native'; -import { adaptWebToNativeEvent } from './adaptWebToNativeEvent'; +import { adaptWebToNativeEvent } from '../nativeMappers/adaptWebToNativeEvent'; import { getCurrentAlignment, isAnyParagraphFormatActive, isFormatBlocked, -} from './formats/formatRules'; -import type { HtmlStyle } from '../types'; +} from '../formats/formatRules'; +import type { HtmlStyle } from '../../types'; export const useOnChangeState = ( editor: Editor | null, diff --git a/src/web/useOnChangeText.ts b/src/web/tiptapWatchers/useOnChangeText.ts similarity index 78% rename from src/web/useOnChangeText.ts rename to src/web/tiptapWatchers/useOnChangeText.ts index f3a70bbc5..3d76d3984 100644 --- a/src/web/useOnChangeText.ts +++ b/src/web/tiptapWatchers/useOnChangeText.ts @@ -1,7 +1,7 @@ import { type Editor } from '@tiptap/react'; -import type { OnChangeTextEvent } from '../types'; +import type { OnChangeTextEvent } from '../../types'; import type { NativeSyntheticEvent } from 'react-native'; -import { nativeLeafText } from './positionMapping'; +import { nativeLeafText } from '../nativeMappers/positionMapping'; import { useOnEditorChange } from './useOnEditorChange'; export const useOnChangeText = ( diff --git a/src/web/useOnEditorChange.ts b/src/web/tiptapWatchers/useOnEditorChange.ts similarity index 91% rename from src/web/useOnEditorChange.ts rename to src/web/tiptapWatchers/useOnEditorChange.ts index db06ea3bc..5dbe5f105 100644 --- a/src/web/useOnEditorChange.ts +++ b/src/web/tiptapWatchers/useOnEditorChange.ts @@ -1,7 +1,7 @@ import { useEffect, useRef } from 'react'; import { type Editor } from '@tiptap/react'; import type { NativeSyntheticEvent } from 'react-native'; -import { adaptWebToNativeEvent } from './adaptWebToNativeEvent'; +import { adaptWebToNativeEvent } from '../nativeMappers/adaptWebToNativeEvent'; export const useOnEditorChange = ( editor: Editor, diff --git a/src/web/useOnLinkDetected.ts b/src/web/tiptapWatchers/useOnLinkDetected.ts similarity index 96% rename from src/web/useOnLinkDetected.ts rename to src/web/tiptapWatchers/useOnLinkDetected.ts index 4373faf36..ee081a108 100644 --- a/src/web/useOnLinkDetected.ts +++ b/src/web/tiptapWatchers/useOnLinkDetected.ts @@ -4,7 +4,7 @@ import { getMarkRange, getMarksBetween } from '@tiptap/core'; import type { EditorState } from '@tiptap/pm/state'; import type { MarkType } from '@tiptap/pm/model'; import { emitLinkDetected, type LinkEmitterRef } from './emitLinkDetected'; -import { tiptapPosToNativePos } from './positionMapping'; +import { tiptapPosToNativePos } from '../nativeMappers/positionMapping'; function findLinkRangeAt( state: EditorState, diff --git a/src/web/assertBrowserEnvironment.ts b/src/web/utils/assertBrowserEnvironment.ts similarity index 100% rename from src/web/assertBrowserEnvironment.ts rename to src/web/utils/assertBrowserEnvironment.ts diff --git a/src/web/pasteImages.ts b/src/web/utils/pasteImages.ts similarity index 93% rename from src/web/pasteImages.ts rename to src/web/utils/pasteImages.ts index 1f16f1dad..b1a9c3d4f 100644 --- a/src/web/pasteImages.ts +++ b/src/web/utils/pasteImages.ts @@ -5,9 +5,9 @@ import type { Editor } from '@tiptap/react'; import type { NativeSyntheticEvent } from 'react-native'; -import type { OnPasteImagesEvent } from '../types'; -import { adaptWebToNativeEvent } from './adaptWebToNativeEvent'; -import { isImageBlocked } from './formats/formatRules'; +import type { OnPasteImagesEvent } from '../../types'; +import { adaptWebToNativeEvent } from '../nativeMappers/adaptWebToNativeEvent'; +import { isImageBlocked } from '../formats/formatRules'; import { readImageDimensionsFromBlob } from './pastedImageDimensions'; const isImageLikeClipboardFile = (file: File, reportedMime: string) => diff --git a/src/web/pastedImageDimensions.ts b/src/web/utils/pastedImageDimensions.ts similarity index 100% rename from src/web/pastedImageDimensions.ts rename to src/web/utils/pastedImageDimensions.ts diff --git a/src/web/useStableRef.ts b/src/web/utils/useStableRef.ts similarity index 100% rename from src/web/useStableRef.ts rename to src/web/utils/useStableRef.ts