-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add architecture for granual pasteAsPlainText support #68
Changes from 5 commits
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export interface OptionConfig { | ||
defaultPlainTextPaste?: PlainTextParams | ||
} | ||
|
||
interface PlainTextParams { | ||
urlLinks?: boolean | ||
|
||
// Not currently implemented behavior | ||
/*imageLinks?: boolean | ||
html?: boolean | ||
table?: boolean | ||
text?: boolean*/ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import {OptionConfig} from './option-config' | ||
|
||
const skipFormattingMap = new WeakMap<HTMLElement, boolean>() | ||
|
||
function setSkipFormattingFlag(event: KeyboardEvent): void { | ||
|
@@ -21,13 +23,22 @@ export function shouldSkipFormatting(el: HTMLElement): boolean { | |
return shouldSkipFormattingState | ||
} | ||
|
||
export function installAround(el: HTMLElement, ...installCallbacks: Array<(el: HTMLElement) => void>): void { | ||
export function installAround( | ||
el: HTMLElement, | ||
installCallbacks: Array<(el: HTMLElement) => void>, | ||
installCallbacksWithOptions: Array<(el: HTMLElement, optionConfig?: OptionConfig) => 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. rather than have two arrays here, why not just pass options to all the callbacks? 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 was hoping to avoid confusion given we export the individual installation functions, too, but the documentation update would be sufficient. Let me tackle this now 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. |
||
optionConfig?: OptionConfig | ||
): void { | ||
el.addEventListener('keydown', setSkipFormattingFlag) | ||
|
||
for (const installCallback of installCallbacks) { | ||
installCallback(el) | ||
} | ||
|
||
for (const installCallback of installCallbacksWithOptions) { | ||
installCallback(el, optionConfig) | ||
} | ||
|
||
el.addEventListener('paste', unsetSkipFormattedFlag) | ||
} | ||
|
||
|
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.
great!