Skip to content

Commit 99a17cc

Browse files
Add inputType for InputEvent (#23)
* Add inputType for InputEvent * Add changelog message * Fix InputType related functions to fit conventions * Rename module InputTypes to InputType
1 parent 091ad1b commit 99a17cc

File tree

4 files changed

+170
-0
lines changed

4 files changed

+170
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88

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

1112
Bugfixes:
1213

src/Web/UIEvent/InputEvent.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ export function data_(e) {
55
export function isComposing(e) {
66
return e.isComposing;
77
}
8+
9+
export function _inputType(e) {
10+
return e.inputType;
11+
}

src/Web/UIEvent/InputEvent.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
module Web.UIEvent.InputEvent where
22

3+
import Prelude
4+
35
import Data.Maybe (Maybe)
46
import Unsafe.Coerce (unsafeCoerce)
57
import Web.Event.Event (Event)
68
import Web.Internal.FFI (unsafeReadProtoTagged)
9+
import Web.UIEvent.InputEvent.InputType (InputType, parse)
710
import Web.UIEvent.UIEvent (UIEvent)
811

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

2528
foreign import isComposing :: InputEvent -> Boolean
29+
30+
foreign import _inputType :: InputEvent -> String
31+
32+
inputType :: InputEvent -> InputType
33+
inputType = parse <<< _inputType
34+
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
module Web.UIEvent.InputEvent.InputType where
2+
3+
import Prelude
4+
5+
data InputType
6+
= InsertText
7+
| InsertReplacementText
8+
| InsertLineBreak
9+
| InsertParagraph
10+
| InsertOrderedList
11+
| InsertUnorderedList
12+
| InsertHorizontalRule
13+
| InsertFromYank
14+
| InsertFromDrop
15+
| InsertFromPaste
16+
| InsertFromPasteAsQuotation
17+
| InsertTranspose
18+
| InsertCompositionText
19+
| InsertLink
20+
| DeleteWordBackward
21+
| DeleteWordForward
22+
| DeleteSoftLineBackward
23+
| DeleteSoftLineForward
24+
| DeleteEntireSoftLine
25+
| DeleteHardLineBackward
26+
| DeleteHardLineForward
27+
| DeleteByDrag
28+
| DeleteByCut
29+
| DeleteContent
30+
| DeleteContentBackward
31+
| DeleteContentForward
32+
| HistoryUndo
33+
| HistoryRedo
34+
| FormatBold
35+
| FormatItalic
36+
| FormatUnderline
37+
| FormatStrikeThrough
38+
| FormatSuperscript
39+
| FormatSubscript
40+
| FormatJustifyFull
41+
| FormatJustifyCenter
42+
| FormatJustifyRight
43+
| FormatJustifyLeft
44+
| FormatIndent
45+
| FormatOutdent
46+
| FormatRemove
47+
| FormatSetBlockTextDirection
48+
| FormatSetInlineTextDirection
49+
| FormatBackColor
50+
| FormatFontColor
51+
| FormatFontName
52+
| Other String
53+
54+
derive instance eqInputType :: Eq InputType
55+
derive instance ordInputType :: Ord InputType
56+
57+
instance showInputType :: Show InputType where
58+
show = print
59+
60+
parse :: String -> InputType
61+
parse "insertText" = InsertText
62+
parse "insertReplacementText" = InsertReplacementText
63+
parse "insertLineBreak" = InsertLineBreak
64+
parse "insertParagraph" = InsertParagraph
65+
parse "insertOrderedList" = InsertOrderedList
66+
parse "insertUnorderedList" = InsertUnorderedList
67+
parse "insertHorizontalRule" = InsertHorizontalRule
68+
parse "insertFromYank" = InsertFromYank
69+
parse "insertFromDrop" = InsertFromDrop
70+
parse "insertFromPaste" = InsertFromPaste
71+
parse "insertFromPasteAsQuotation" = InsertFromPasteAsQuotation
72+
parse "insertTranspose" = InsertTranspose
73+
parse "insertCompositionText" = InsertCompositionText
74+
parse "insertLink" = InsertLink
75+
parse "deleteWordBackward" = DeleteWordBackward
76+
parse "deleteWordForward" = DeleteWordForward
77+
parse "deleteSoftLineBackward" = DeleteSoftLineBackward
78+
parse "deleteSoftLineForward" = DeleteSoftLineForward
79+
parse "deleteEntireSoftLine" = DeleteEntireSoftLine
80+
parse "deleteHardLineBackward" = DeleteHardLineBackward
81+
parse "deleteHardLineForward" = DeleteHardLineForward
82+
parse "deleteByDrag" = DeleteByDrag
83+
parse "deleteByCut" = DeleteByCut
84+
parse "deleteContent" = DeleteContent
85+
parse "deleteContentBackward" = DeleteContentBackward
86+
parse "deleteContentForward" = DeleteContentForward
87+
parse "historyUndo" = HistoryUndo
88+
parse "historyRedo" = HistoryRedo
89+
parse "formatBold" = FormatBold
90+
parse "formatItalic" = FormatItalic
91+
parse "formatUnderline" = FormatUnderline
92+
parse "formatStrikeThrough" = FormatStrikeThrough
93+
parse "formatSuperscript" = FormatSuperscript
94+
parse "formatSubscript" = FormatSubscript
95+
parse "formatJustifyFull" = FormatJustifyFull
96+
parse "formatJustifyCenter" = FormatJustifyCenter
97+
parse "formatJustifyRight" = FormatJustifyRight
98+
parse "formatJustifyLeft" = FormatJustifyLeft
99+
parse "formatIndent" = FormatIndent
100+
parse "formatOutdent" = FormatOutdent
101+
parse "formatRemove" = FormatRemove
102+
parse "formatSetBlockTextDirection" = FormatSetBlockTextDirection
103+
parse "formatSetInlineTextDirection" = FormatSetInlineTextDirection
104+
parse "formatBackColor" = FormatBackColor
105+
parse "formatFontColor" = FormatFontColor
106+
parse "formatFontName" = FormatFontName
107+
parse s = Other s
108+
109+
print :: InputType -> String
110+
print InsertText = "insertText"
111+
print InsertReplacementText = "insertReplacementText"
112+
print InsertLineBreak = "insertLineBreak"
113+
print InsertParagraph = "insertParagraph"
114+
print InsertOrderedList = "insertOrderedList"
115+
print InsertUnorderedList = "insertUnorderedList"
116+
print InsertHorizontalRule = "insertHorizontalRule"
117+
print InsertFromYank = "insertFromYank"
118+
print InsertFromDrop = "insertFromDrop"
119+
print InsertFromPaste = "insertFromPaste"
120+
print InsertFromPasteAsQuotation = "insertFromPasteAsQuotation"
121+
print InsertTranspose = "insertTranspose"
122+
print InsertCompositionText = "insertCompositionText"
123+
print InsertLink = "insertLink"
124+
print DeleteWordBackward = "deleteWordBackward"
125+
print DeleteWordForward = "deleteWordForward"
126+
print DeleteSoftLineBackward = "deleteSoftLineBackward"
127+
print DeleteSoftLineForward = "deleteSoftLineForward"
128+
print DeleteEntireSoftLine = "deleteEntireSoftLine"
129+
print DeleteHardLineBackward = "deleteHardLineBackward"
130+
print DeleteHardLineForward = "deleteHardLineForward"
131+
print DeleteByDrag = "deleteByDrag"
132+
print DeleteByCut = "deleteByCut"
133+
print DeleteContent = "deleteContent"
134+
print DeleteContentBackward = "deleteContentBackward"
135+
print DeleteContentForward = "deleteContentForward"
136+
print HistoryUndo = "historyUndo"
137+
print HistoryRedo = "historyRedo"
138+
print FormatBold = "formatBold"
139+
print FormatItalic = "formatItalic"
140+
print FormatUnderline = "formatUnderline"
141+
print FormatStrikeThrough = "formatStrikeThrough"
142+
print FormatSuperscript = "formatSuperscript"
143+
print FormatSubscript = "formatSubscript"
144+
print FormatJustifyFull = "formatJustifyFull"
145+
print FormatJustifyCenter = "formatJustifyCenter"
146+
print FormatJustifyRight = "formatJustifyRight"
147+
print FormatJustifyLeft = "formatJustifyLeft"
148+
print FormatIndent = "formatIndent"
149+
print FormatOutdent = "formatOutdent"
150+
print FormatRemove = "formatRemove"
151+
print FormatSetBlockTextDirection = "formatSetBlockTextDirection"
152+
print FormatSetInlineTextDirection = "formatSetInlineTextDirection"
153+
print FormatBackColor = "formatBackColor"
154+
print FormatFontColor = "formatFontColor"
155+
print FormatFontName = "formatFontName"
156+
print (Other s) = s

0 commit comments

Comments
 (0)