Skip to content

Add inputType for InputEvent #23

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

Merged
merged 4 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
Breaking changes:

New features:
- Add support for inputType on InputEvents (#23 by @MonaMayrhofer)

Bugfixes:

Expand Down
4 changes: 4 additions & 0 deletions src/Web/UIEvent/InputEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ export function data_(e) {
export function isComposing(e) {
return e.isComposing;
}

export function _inputType(e) {
return e.inputType;
}
9 changes: 9 additions & 0 deletions src/Web/UIEvent/InputEvent.purs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
module Web.UIEvent.InputEvent where

import Prelude

import Data.Maybe (Maybe)
import Unsafe.Coerce (unsafeCoerce)
import Web.Event.Event (Event)
import Web.Internal.FFI (unsafeReadProtoTagged)
import Web.UIEvent.InputEvent.InputType (InputType, parse)
import Web.UIEvent.UIEvent (UIEvent)

foreign import data InputEvent :: Type
Expand All @@ -23,3 +26,9 @@ toEvent = unsafeCoerce
foreign import data_ :: InputEvent -> String

foreign import isComposing :: InputEvent -> Boolean

foreign import _inputType :: InputEvent -> String

inputType :: InputEvent -> InputType
inputType = parse <<< _inputType

156 changes: 156 additions & 0 deletions src/Web/UIEvent/InputEvent/InputType.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
module Web.UIEvent.InputEvent.InputType where

import Prelude

data InputType
= InsertText
| InsertReplacementText
| InsertLineBreak
| InsertParagraph
| InsertOrderedList
| InsertUnorderedList
| InsertHorizontalRule
| InsertFromYank
| InsertFromDrop
| InsertFromPaste
| InsertFromPasteAsQuotation
| InsertTranspose
| InsertCompositionText
| InsertLink
| DeleteWordBackward
| DeleteWordForward
| DeleteSoftLineBackward
| DeleteSoftLineForward
| DeleteEntireSoftLine
| DeleteHardLineBackward
| DeleteHardLineForward
| DeleteByDrag
| DeleteByCut
| DeleteContent
| DeleteContentBackward
| DeleteContentForward
| HistoryUndo
| HistoryRedo
| FormatBold
| FormatItalic
| FormatUnderline
| FormatStrikeThrough
| FormatSuperscript
| FormatSubscript
| FormatJustifyFull
| FormatJustifyCenter
| FormatJustifyRight
| FormatJustifyLeft
| FormatIndent
| FormatOutdent
| FormatRemove
| FormatSetBlockTextDirection
| FormatSetInlineTextDirection
| FormatBackColor
| FormatFontColor
| FormatFontName
| Other String

derive instance eqInputType :: Eq InputType
derive instance ordInputType :: Ord InputType

instance showInputType :: Show InputType where
show = print

parse :: String -> InputType
parse "insertText" = InsertText
parse "insertReplacementText" = InsertReplacementText
parse "insertLineBreak" = InsertLineBreak
parse "insertParagraph" = InsertParagraph
parse "insertOrderedList" = InsertOrderedList
parse "insertUnorderedList" = InsertUnorderedList
parse "insertHorizontalRule" = InsertHorizontalRule
parse "insertFromYank" = InsertFromYank
parse "insertFromDrop" = InsertFromDrop
parse "insertFromPaste" = InsertFromPaste
parse "insertFromPasteAsQuotation" = InsertFromPasteAsQuotation
parse "insertTranspose" = InsertTranspose
parse "insertCompositionText" = InsertCompositionText
parse "insertLink" = InsertLink
parse "deleteWordBackward" = DeleteWordBackward
parse "deleteWordForward" = DeleteWordForward
parse "deleteSoftLineBackward" = DeleteSoftLineBackward
parse "deleteSoftLineForward" = DeleteSoftLineForward
parse "deleteEntireSoftLine" = DeleteEntireSoftLine
parse "deleteHardLineBackward" = DeleteHardLineBackward
parse "deleteHardLineForward" = DeleteHardLineForward
parse "deleteByDrag" = DeleteByDrag
parse "deleteByCut" = DeleteByCut
parse "deleteContent" = DeleteContent
parse "deleteContentBackward" = DeleteContentBackward
parse "deleteContentForward" = DeleteContentForward
parse "historyUndo" = HistoryUndo
parse "historyRedo" = HistoryRedo
parse "formatBold" = FormatBold
parse "formatItalic" = FormatItalic
parse "formatUnderline" = FormatUnderline
parse "formatStrikeThrough" = FormatStrikeThrough
parse "formatSuperscript" = FormatSuperscript
parse "formatSubscript" = FormatSubscript
parse "formatJustifyFull" = FormatJustifyFull
parse "formatJustifyCenter" = FormatJustifyCenter
parse "formatJustifyRight" = FormatJustifyRight
parse "formatJustifyLeft" = FormatJustifyLeft
parse "formatIndent" = FormatIndent
parse "formatOutdent" = FormatOutdent
parse "formatRemove" = FormatRemove
parse "formatSetBlockTextDirection" = FormatSetBlockTextDirection
parse "formatSetInlineTextDirection" = FormatSetInlineTextDirection
parse "formatBackColor" = FormatBackColor
parse "formatFontColor" = FormatFontColor
parse "formatFontName" = FormatFontName
parse s = Other s

print :: InputType -> String
print InsertText = "insertText"
print InsertReplacementText = "insertReplacementText"
print InsertLineBreak = "insertLineBreak"
print InsertParagraph = "insertParagraph"
print InsertOrderedList = "insertOrderedList"
print InsertUnorderedList = "insertUnorderedList"
print InsertHorizontalRule = "insertHorizontalRule"
print InsertFromYank = "insertFromYank"
print InsertFromDrop = "insertFromDrop"
print InsertFromPaste = "insertFromPaste"
print InsertFromPasteAsQuotation = "insertFromPasteAsQuotation"
print InsertTranspose = "insertTranspose"
print InsertCompositionText = "insertCompositionText"
print InsertLink = "insertLink"
print DeleteWordBackward = "deleteWordBackward"
print DeleteWordForward = "deleteWordForward"
print DeleteSoftLineBackward = "deleteSoftLineBackward"
print DeleteSoftLineForward = "deleteSoftLineForward"
print DeleteEntireSoftLine = "deleteEntireSoftLine"
print DeleteHardLineBackward = "deleteHardLineBackward"
print DeleteHardLineForward = "deleteHardLineForward"
print DeleteByDrag = "deleteByDrag"
print DeleteByCut = "deleteByCut"
print DeleteContent = "deleteContent"
print DeleteContentBackward = "deleteContentBackward"
print DeleteContentForward = "deleteContentForward"
print HistoryUndo = "historyUndo"
print HistoryRedo = "historyRedo"
print FormatBold = "formatBold"
print FormatItalic = "formatItalic"
print FormatUnderline = "formatUnderline"
print FormatStrikeThrough = "formatStrikeThrough"
print FormatSuperscript = "formatSuperscript"
print FormatSubscript = "formatSubscript"
print FormatJustifyFull = "formatJustifyFull"
print FormatJustifyCenter = "formatJustifyCenter"
print FormatJustifyRight = "formatJustifyRight"
print FormatJustifyLeft = "formatJustifyLeft"
print FormatIndent = "formatIndent"
print FormatOutdent = "formatOutdent"
print FormatRemove = "formatRemove"
print FormatSetBlockTextDirection = "formatSetBlockTextDirection"
print FormatSetInlineTextDirection = "formatSetInlineTextDirection"
print FormatBackColor = "formatBackColor"
print FormatFontColor = "formatFontColor"
print FormatFontName = "formatFontName"
print (Other s) = s