-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace flow + babel with tsc #15
Changes from 4 commits
a60d4f6
f131543
148d2ac
613f662
f55ba06
edd2575
76690ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
dist | ||
prettier.config.js | ||
*.config.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
{ | ||
"extends": [ | ||
"plugin:flowtype/recommended", | ||
"plugin:github/browser", | ||
"plugin:github/es6", | ||
"plugin:github/browser" | ||
], | ||
"parser": "babel-eslint" | ||
"plugin:github/typescript" | ||
] | ||
} |
This file was deleted.
This file was deleted.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
/* @flow strict */ | ||
|
||
import babel from 'rollup-plugin-babel' | ||
|
||
const pkg = require('./package.json') | ||
|
||
import typescript from 'rollup-plugin-typescript2' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am hoping that |
||
import pkg from './package.json' | ||
export default { | ||
input: 'src/index.js', | ||
input: 'src/index.ts', | ||
output: [ | ||
{ | ||
file: pkg['module'], | ||
|
@@ -18,8 +14,6 @@ export default { | |
} | ||
], | ||
plugins: [ | ||
babel({ | ||
presets: ['github'] | ||
}) | ||
typescript() | ||
] | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
/* @flow strict */ | ||
|
||
import {install as installLink, uninstall as uninstallLink} from './paste-markdown-image-link' | ||
import {install as installTable, uninstall as uninstallTable} from './paste-markdown-table' | ||
import {install as installText, uninstall as uninstallText} from './paste-markdown-text' | ||
|
||
type Subscription = {| | ||
interface Subscription { | ||
unsubscribe: () => void | ||
|} | ||
} | ||
|
||
export default function subscribe(el: Element): Subscription { | ||
export default function subscribe(el: HTMLElement): Subscription { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (1/2) This is to ensure event listeners are correctly typed. |
||
installTable(el) | ||
installLink(el) | ||
installText(el) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ | |
|
||
import {insertText} from './text' | ||
|
||
export function install(el: Element) { | ||
export function install(el: HTMLElement) { | ||
el.addEventListener('dragover', onDragover) | ||
el.addEventListener('drop', onDrop) | ||
el.addEventListener('paste', onPaste) | ||
} | ||
|
||
export function uninstall(el: Element) { | ||
export function uninstall(el: HTMLElement) { | ||
el.removeEventListener('dragover', onDragover) | ||
el.removeEventListener('drop', onDrop) | ||
el.removeEventListener('paste', onPaste) | ||
|
@@ -58,21 +58,23 @@ function hasFile(transfer: DataTransfer): boolean { | |
|
||
function columnText(column: Element): string { | ||
const noBreakSpace = '\u00A0' | ||
const text = column.textContent | ||
const text = (column.textContent || '') | ||
.trim() | ||
.replace(/\|/g, '\\|') | ||
.replace(/\n/g, ' ') | ||
return text || noBreakSpace | ||
} | ||
|
||
function tableHeaders(row: Element): Array<string> { | ||
function tableHeaders(row: Element): string[] { | ||
return Array.from(row.querySelectorAll('td, th')).map(columnText) | ||
} | ||
|
||
function tableMarkdown(node: Element): string { | ||
const rows = Array.from(node.querySelectorAll('tr')) | ||
|
||
const headers = tableHeaders(rows.shift()) | ||
const firstRow = rows.shift() | ||
if (!firstRow) return '' | ||
const headers = tableHeaders(firstRow) | ||
const spacers = headers.map(() => '--') | ||
const header = `${headers.join(' | ')}\n${spacers.join(' | ')}\n` | ||
|
||
|
@@ -87,13 +89,13 @@ function tableMarkdown(node: Element): string { | |
return `\n${header}${body}\n\n` | ||
} | ||
|
||
function parseTable(html: string): ?Element { | ||
function parseTable(html: string): HTMLElement | null { | ||
const el = document.createElement('div') | ||
el.innerHTML = html | ||
return el.querySelector('table') | ||
} | ||
|
||
function hasTable(transfer: DataTransfer): ?Element { | ||
function hasTable(transfer: DataTransfer): HTMLElement | null | void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can avoid the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is edited in the followup PR. |
||
if (Array.from(transfer.types).indexOf('text/html') === -1) return | ||
|
||
const html = transfer.getData('text/html') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
/* @flow strict */ | ||
|
||
export function insertText(textarea: HTMLInputElement | HTMLTextAreaElement, text: string): void { | ||
const beginning = textarea.value.substring(0, textarea.selectionStart) | ||
const remaining = textarea.value.substring(textarea.selectionEnd) | ||
const beginning = textarea.value.substring(0, textarea.selectionStart || 0) | ||
const remaining = textarea.value.substring(textarea.selectionEnd || 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (2/2) |
||
|
||
const newline = beginning.length === 0 || beginning.match(/\n$/) ? '' : '\n' | ||
const textBeforeCursor = beginning + newline + text | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
{ | ||
"rules": { | ||
"flowtype/require-valid-file-annotation": "off" | ||
}, | ||
"env": { | ||
"mocha": true | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"target": "es2017", | ||
"lib": [ | ||
"es2018", | ||
"dom" | ||
], | ||
"strict": true, | ||
"declaration": true, | ||
"outDir": "dist", | ||
"removeComments": true, | ||
"preserveConstEnums": true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not all of
dist/
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dist
contains*.d.ts
for all the*.ts
files even though we only outputted one.