Skip to content

Commit

Permalink
Move MarkdownType and MarkdownRange to commonTypes.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw committed Aug 31, 2024
1 parent 7774946 commit bfb260e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 27 deletions.
4 changes: 1 addition & 3 deletions src/__tests__/webParser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {expect} from '@jest/globals';
import {parseRangesToHTMLNodes} from '../web/utils/parserUtils';
import type {MarkdownRange} from '../web/utils/parserUtils';

require('../../parser/react-native-live-markdown-parser.js');

Expand All @@ -16,8 +15,7 @@ const toBeParsedAsHTML = function (actual: string, expectedHTML: string) {
throw new Error('Actual value must be a string');
}
let expected = expectedHTML;
const ranges = global.parseExpensiMarkToRanges(actual);
const markdownRanges = ranges as MarkdownRange[];
const markdownRanges = global.parseExpensiMarkToRanges(actual);

const actualDOM = parseRangesToHTMLNodes(actual, markdownRanges, {}, true).dom;
const actualHTML = actualDOM.innerHTML;
Expand Down
10 changes: 10 additions & 0 deletions src/commonTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'mention-here' | 'mention-user' | 'mention-report' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax';

interface MarkdownRange {
type: MarkdownType;
start: number;
length: number;
depth?: number;
}

export type {MarkdownType, MarkdownRange};
15 changes: 2 additions & 13 deletions src/web/utils/parserUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@ import type {NodeType, TreeNode} from './treeUtils';
import type {PartialMarkdownStyle} from '../../styleUtils';
import {getCurrentCursorPosition, moveCursorToEnd, setCursorPosition} from './cursorUtils';
import {addStyleToBlock} from './blockUtils';

type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax' | 'mention-here' | 'mention-user' | 'mention-report';

type MarkdownRange = {
type: MarkdownType;
start: number;
length: number;
depth?: number;
};
import type {MarkdownRange} from '../../commonTypes';

type Paragraph = {
text: string;
Expand Down Expand Up @@ -271,8 +263,7 @@ function updateInputStructure(
const selection = getCurrentCursorPosition(target);
cursorPosition = selection ? selection.start : null;
}
const ranges = global.parseExpensiMarkToRanges(text);
const markdownRanges: MarkdownRange[] = ranges as MarkdownRange[];
const markdownRanges = global.parseExpensiMarkToRanges(text);
if (!text || targetElement.innerHTML === '<br>' || (targetElement && targetElement.innerHTML === '\n')) {
targetElement.innerHTML = '';
targetElement.innerText = '';
Expand All @@ -298,5 +289,3 @@ function updateInputStructure(
}

export {updateInputStructure, parseRangesToHTMLNodes};

export type {MarkdownRange, MarkdownType};
2 changes: 1 addition & 1 deletion src/web/utils/treeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {HTMLMarkdownElement} from '../../MarkdownTextInput.web';
import type {MarkdownRange, MarkdownType} from './parserUtils';
import type {MarkdownRange, MarkdownType} from '../../commonTypes';

type NodeType = MarkdownType | 'line' | 'text' | 'br' | 'root';

Expand Down
13 changes: 3 additions & 10 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
export {};

type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'mention-here' | 'mention-user' | 'mention-report' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax';
import type {MarkdownRange} from '../src/commonTypes';

type MarkdownRange = {
type: MarkdownType;
start: number;
length: number;
depth?: number;
};
export {};

declare global {
// eslint-disable-next-line no-var
var parseExpensiMarkToRanges: (markdown: string) => MarkdownMarkdownRange[];
var parseExpensiMarkToRanges: (markdown: string) => MarkdownRange[];
}

0 comments on commit bfb260e

Please sign in to comment.