Skip to content

Commit 832b8ef

Browse files
authored
Add HTMLDialogElement (#77)
1 parent 40e9a0c commit 832b8ef

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-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+
- Added `HTMLDialogElement` module (#77 by @kgmt0)
1011

1112
Bugfixes:
1213

src/Web/HTML/HTMLDialogElement.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
export function open(dialog) {
2+
return function () {
3+
return dialog.open;
4+
};
5+
}
6+
7+
export function setOpen(value) {
8+
return function (dialog) {
9+
return function () {
10+
dialog.open = value;
11+
};
12+
};
13+
}
14+
15+
// ----------------------------------------------------------------------------
16+
17+
export function returnValue(dialog) {
18+
return function () {
19+
return dialog.returnValue;
20+
};
21+
}
22+
23+
export function setReturnValue(value) {
24+
return function (dialog) {
25+
return function () {
26+
dialog.returnValue = value;
27+
};
28+
};
29+
}
30+
31+
// ----------------------------------------------------------------------------
32+
33+
export function show(dialog) {
34+
return function () {
35+
return dialog.show();
36+
};
37+
}
38+
39+
export function showModal(dialog) {
40+
return function () {
41+
return dialog.showModal();
42+
};
43+
}
44+
45+
// ----------------------------------------------------------------------------
46+
47+
export function _close(value) {
48+
return function (dialog) {
49+
return function () {
50+
dialog.close(value);
51+
};
52+
};
53+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
module Web.HTML.HTMLDialogElement
2+
( HTMLDialogElement
3+
, fromHTMLElement
4+
, fromElement
5+
, fromNode
6+
, fromChildNode
7+
, fromNonDocumentTypeChildNode
8+
, fromParentNode
9+
, fromEventTarget
10+
, toHTMLElement
11+
, toElement
12+
, toNode
13+
, toChildNode
14+
, toNonDocumentTypeChildNode
15+
, toParentNode
16+
, toEventTarget
17+
, open
18+
, setOpen
19+
, returnValue
20+
, setReturnValue
21+
, show
22+
, showModal
23+
, close
24+
) where
25+
26+
import Data.Maybe (Maybe)
27+
import Data.Nullable (Nullable, toNullable)
28+
import Effect (Effect)
29+
import Prelude (Unit, (<<<))
30+
import Unsafe.Coerce (unsafeCoerce)
31+
import Web.DOM (ChildNode, Element, Node, NonDocumentTypeChildNode, ParentNode)
32+
import Web.Event.EventTarget (EventTarget)
33+
import Web.HTML.HTMLElement (HTMLElement)
34+
import Web.Internal.FFI (unsafeReadProtoTagged)
35+
36+
foreign import data HTMLDialogElement :: Type
37+
38+
fromHTMLElement :: HTMLElement -> Maybe HTMLDialogElement
39+
fromHTMLElement = unsafeReadProtoTagged "HTMLDialogElement"
40+
41+
fromElement :: Element -> Maybe HTMLDialogElement
42+
fromElement = unsafeReadProtoTagged "HTMLDialogElement"
43+
44+
fromNode :: Node -> Maybe HTMLDialogElement
45+
fromNode = unsafeReadProtoTagged "HTMLDialogElement"
46+
47+
fromChildNode :: ChildNode -> Maybe HTMLDialogElement
48+
fromChildNode = unsafeReadProtoTagged "HTMLDialogElement"
49+
50+
fromNonDocumentTypeChildNode :: NonDocumentTypeChildNode -> Maybe HTMLDialogElement
51+
fromNonDocumentTypeChildNode = unsafeReadProtoTagged "HTMLDialogElement"
52+
53+
fromParentNode :: ParentNode -> Maybe HTMLDialogElement
54+
fromParentNode = unsafeReadProtoTagged "HTMLDialogElement"
55+
56+
fromEventTarget :: EventTarget -> Maybe HTMLDialogElement
57+
fromEventTarget = unsafeReadProtoTagged "HTMLDialogElement"
58+
59+
toHTMLElement :: HTMLDialogElement -> HTMLElement
60+
toHTMLElement = unsafeCoerce
61+
62+
toElement :: HTMLDialogElement -> Element
63+
toElement = unsafeCoerce
64+
65+
toNode :: HTMLDialogElement -> Node
66+
toNode = unsafeCoerce
67+
68+
toChildNode :: HTMLDialogElement -> ChildNode
69+
toChildNode = unsafeCoerce
70+
71+
toNonDocumentTypeChildNode :: HTMLDialogElement -> NonDocumentTypeChildNode
72+
toNonDocumentTypeChildNode = unsafeCoerce
73+
74+
toParentNode :: HTMLDialogElement -> ParentNode
75+
toParentNode = unsafeCoerce
76+
77+
toEventTarget :: HTMLDialogElement -> EventTarget
78+
toEventTarget = unsafeCoerce
79+
80+
foreign import open :: HTMLDialogElement -> Effect Boolean
81+
foreign import setOpen :: Boolean -> HTMLDialogElement -> Effect Unit
82+
83+
foreign import returnValue :: HTMLDialogElement -> Effect String
84+
foreign import setReturnValue :: String -> HTMLDialogElement -> Effect Unit
85+
86+
foreign import show :: HTMLDialogElement -> Effect Unit
87+
foreign import showModal :: HTMLDialogElement -> Effect Unit
88+
89+
foreign import _close :: Nullable String -> HTMLDialogElement -> Effect Unit
90+
91+
close :: Maybe String -> HTMLDialogElement -> Effect Unit
92+
close = _close <<< toNullable

0 commit comments

Comments
 (0)