Skip to content

Commit 0585b57

Browse files
authored
refactor(web): cleaned up web/src structure (#776)
# Summary A lot of files were just dropped were just dropped into `src/web` directory, which was messy. Grouped the files according to their existential purpose. ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ❌ | | Android | ❌ | | Web | ✅ | ## Checklist - [x] E2E tests are passing - [ ] Required E2E tests have been added (N/A)
1 parent 63d4eac commit 0585b57

24 files changed

Lines changed: 42 additions & 39 deletions

src/web/EnrichedText.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import { buildMentionRulesCSS } from './styleConversion/buildMentionRulesCSS';
1717
import { sanitizeHtml } from './sanitization/htmlSanitizer';
1818
import { prepareHtmlForWeb } from './normalization/prepareHtmlForWeb';
1919
import { INLINE_IMAGE_CSS_VARIABLES } from './styleConversion/inlineImageCSSVariables';
20-
import { useImageErrorFallback } from './useImageErrorFallback';
21-
import { usePressInteractions } from './usePressInteractions';
20+
import { useImageErrorFallback } from './htmlExtensions/useImageErrorFallback';
21+
import { usePressInteractions } from './htmlExtensions/usePressInteractions';
2222
import { useEllipsizeMode } from './ellipsizeMode/useEllipsizeMode';
23-
import { adaptWebToNativeEvent } from './adaptWebToNativeEvent';
24-
import { useStableRef } from './useStableRef';
25-
import { assertBrowserEnvironment } from './assertBrowserEnvironment';
26-
import { useOrderedListMarkerWidth } from './useOrderedListMarkerWidth';
23+
import { adaptWebToNativeEvent } from './nativeMappers/adaptWebToNativeEvent';
24+
import { useStableRef } from './utils/useStableRef';
25+
import { assertBrowserEnvironment } from './utils/assertBrowserEnvironment';
26+
import { useOrderedListMarkerWidth } from './htmlExtensions/useOrderedListMarkerWidth';
2727

2828
export const EnrichedText = memo(
2929
({

src/web/EnrichedTextInput.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import type {
1212
EnrichedTextInputInstance,
1313
EnrichedTextInputProps,
1414
} from '../types';
15-
import { adaptWebToNativeEvent } from './adaptWebToNativeEvent';
15+
import { adaptWebToNativeEvent } from './nativeMappers/adaptWebToNativeEvent';
1616
import {
1717
tiptapPosToNativePos,
1818
nativePosToTiptapPos,
1919
nativeLeafText,
20-
} from './positionMapping';
20+
} from './nativeMappers/positionMapping';
2121
import {
2222
useEditor,
2323
EditorContent,
@@ -29,11 +29,11 @@ import Paragraph from '@tiptap/extension-paragraph';
2929
import Text from '@tiptap/extension-text';
3030
import History from '@tiptap/extension-history';
3131
import { Placeholder } from '@tiptap/extensions/placeholder';
32-
import { useOnChangeHtml } from './useOnChangeHtml';
33-
import { useOnChangeText } from './useOnChangeText';
34-
import { useOnChangeState } from './useOnChangeState';
35-
import { useOnLinkDetected } from './useOnLinkDetected';
36-
import type { LinkEmitterState } from './emitLinkDetected';
32+
import { useOnChangeHtml } from './tiptapWatchers/useOnChangeHtml';
33+
import { useOnChangeText } from './tiptapWatchers/useOnChangeText';
34+
import { useOnChangeState } from './tiptapWatchers/useOnChangeState';
35+
import { useOnLinkDetected } from './tiptapWatchers/useOnLinkDetected';
36+
import type { LinkEmitterState } from './tiptapWatchers/emitLinkDetected';
3737
import {
3838
prepareHtmlForTiptap,
3939
normalizeHtmlFromTiptap,
@@ -68,7 +68,7 @@ import { StrictMarksPlugin } from './pmPlugins/StrictMarksPlugin';
6868
import { MergeAdjacentSameKindBlocksPlugin } from './pmPlugins/MergeAdjacentSameKindBlocksPlugin';
6969
import { OrderedListMarkerWidthPlugin } from './pmPlugins/OrderedListMarkerWidthPlugin';
7070
import { StripMarksInCodeBlockPlugin } from './pmPlugins/StripMarksInCodeBlockPlugin';
71-
import { handleClipboardPasteImages } from './pasteImages';
71+
import { handleClipboardPasteImages } from './utils/pasteImages';
7272
import {
7373
MentionPlugin,
7474
setMention,
@@ -78,15 +78,15 @@ import {
7878
import { StripMarksOnImagePlugin } from './pmPlugins/StripMarksOnImagePlugin';
7979
import { ShortcutPlugin } from './pmPlugins/ShortcutPlugin';
8080
import { TextShortcutsPlugin } from './pmPlugins/TextShortcutsPlugin';
81-
import { returnKeyTypeToEnterKeyHint } from './returnKeyTypeToEnterKeyHint';
81+
import { returnKeyTypeToEnterKeyHint } from './nativeMappers/returnKeyTypeToEnterKeyHint';
8282
import { ENRICHED_TEXT_INPUT_CLASSNAME } from './constants/classNames';
8383
import { AutolinkPlugin } from './pmPlugins/AutolinkPlugin';
84-
import { useStableRef } from './useStableRef';
84+
import { useStableRef } from './utils/useStableRef';
8585
import {
8686
checkMentionAttributes,
8787
sanitizeMentionAttributes,
8888
} from './sanitization/htmlSanitizer';
89-
import { assertBrowserEnvironment } from './assertBrowserEnvironment';
89+
import { assertBrowserEnvironment } from './utils/assertBrowserEnvironment';
9090

9191
function runFocused(
9292
editor: Editor,

src/web/__tests__/assertBrowserEnvironment.dom.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertBrowserEnvironment } from '../assertBrowserEnvironment';
1+
import { assertBrowserEnvironment } from '../utils/assertBrowserEnvironment';
22

33
describe('assertBrowserEnvironment', () => {
44
// jsdom provides a full DOM, so the browser APIs are present by default.

src/web/__tests__/assertBrowserEnvironment.ssr.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @jest-environment node
33
*/
44
// Because of the docblock above, jsdom test environment does not exist here
5-
import { assertBrowserEnvironment } from '../assertBrowserEnvironment';
5+
import { assertBrowserEnvironment } from '../utils/assertBrowserEnvironment';
66

77
describe('assertBrowserEnvironment', () => {
88
test('throws when DOM is missing', () => {

src/web/__tests__/returnKeyTypeToEnterKeyHint.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { returnKeyTypeToEnterKeyHint } from '../returnKeyTypeToEnterKeyHint';
1+
import { returnKeyTypeToEnterKeyHint } from '../nativeMappers/returnKeyTypeToEnterKeyHint';
22

33
describe('returnKeyTypeToEnterKeyHint', () => {
44
test.each([

src/web/formats/EnrichedLink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Link, { type LinkOptions } from '@tiptap/extension-link';
22
import { mergeAttributes, type CommandProps } from '@tiptap/core';
33
import type { Editor } from '@tiptap/react';
44

5-
import { nativePosToTiptapPos } from '../positionMapping';
5+
import { nativePosToTiptapPos } from '../nativeMappers/positionMapping';
66
import { isLinkBlocked } from './formatRules';
77
import { findAutolinkRangesInWord } from '../pmPlugins/AutolinkPlugin/autolinkRegex';
88

src/web/formats/applyWrappingListToSelection.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import type { Node } from '@tiptap/pm/model';
33
import { Fragment } from '@tiptap/pm/model';
44
import { TextSelection } from '@tiptap/pm/state';
55

6-
import { nativePosToTiptapPos, tiptapPosToNativePos } from '../positionMapping';
6+
import {
7+
nativePosToTiptapPos,
8+
tiptapPosToNativePos,
9+
} from '../nativeMappers/positionMapping';
710
import { withPreservedAlignment } from './formatRules';
811

912
/**
File renamed without changes.
File renamed without changes.

src/web/usePressInteractions.ts renamed to src/web/htmlExtensions/usePressInteractions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, type RefObject } from 'react';
2-
import type { OnLinkPressEvent, OnMentionPressEvent } from '../types';
2+
import type { OnLinkPressEvent, OnMentionPressEvent } from '../../types';
33

44
type OnLinkPressEventRef = RefObject<
55
((event: OnLinkPressEvent) => void) | undefined

0 commit comments

Comments
 (0)