Skip to content

Add HTMLDialogElement #77

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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:
- Added `HTMLDialogElement` module (#77 by @kgmt0)

Bugfixes:

Expand Down
53 changes: 53 additions & 0 deletions src/Web/HTML/HTMLDialogElement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export function open(dialog) {
return function () {
return dialog.open;
};
}

export function setOpen(value) {
return function (dialog) {
return function () {
dialog.open = value;
};
};
}

// ----------------------------------------------------------------------------

export function returnValue(dialog) {
return function () {
return dialog.returnValue;
};
}

export function setReturnValue(value) {
return function (dialog) {
return function () {
dialog.returnValue = value;
};
};
}

// ----------------------------------------------------------------------------

export function show(dialog) {
return function () {
return dialog.show();
};
}

export function showModal(dialog) {
return function () {
return dialog.showModal();
};
}

// ----------------------------------------------------------------------------

export function _close(value) {
return function (dialog) {
return function () {
dialog.close(value);
};
};
}
92 changes: 92 additions & 0 deletions src/Web/HTML/HTMLDialogElement.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
module Web.HTML.HTMLDialogElement
( HTMLDialogElement
, fromHTMLElement
, fromElement
, fromNode
, fromChildNode
, fromNonDocumentTypeChildNode
, fromParentNode
, fromEventTarget
, toHTMLElement
, toElement
, toNode
, toChildNode
, toNonDocumentTypeChildNode
, toParentNode
, toEventTarget
, open
, setOpen
, returnValue
, setReturnValue
, show
, showModal
, close
) where

import Data.Maybe (Maybe)
import Data.Nullable (Nullable, toNullable)
import Effect (Effect)
import Prelude (Unit, (<<<))
import Unsafe.Coerce (unsafeCoerce)
import Web.DOM (ChildNode, Element, Node, NonDocumentTypeChildNode, ParentNode)
import Web.Event.EventTarget (EventTarget)
import Web.HTML.HTMLElement (HTMLElement)
import Web.Internal.FFI (unsafeReadProtoTagged)

foreign import data HTMLDialogElement :: Type

fromHTMLElement :: HTMLElement -> Maybe HTMLDialogElement
fromHTMLElement = unsafeReadProtoTagged "HTMLDialogElement"

fromElement :: Element -> Maybe HTMLDialogElement
fromElement = unsafeReadProtoTagged "HTMLDialogElement"

fromNode :: Node -> Maybe HTMLDialogElement
fromNode = unsafeReadProtoTagged "HTMLDialogElement"

fromChildNode :: ChildNode -> Maybe HTMLDialogElement
fromChildNode = unsafeReadProtoTagged "HTMLDialogElement"

fromNonDocumentTypeChildNode :: NonDocumentTypeChildNode -> Maybe HTMLDialogElement
fromNonDocumentTypeChildNode = unsafeReadProtoTagged "HTMLDialogElement"

fromParentNode :: ParentNode -> Maybe HTMLDialogElement
fromParentNode = unsafeReadProtoTagged "HTMLDialogElement"

fromEventTarget :: EventTarget -> Maybe HTMLDialogElement
fromEventTarget = unsafeReadProtoTagged "HTMLDialogElement"

toHTMLElement :: HTMLDialogElement -> HTMLElement
toHTMLElement = unsafeCoerce

toElement :: HTMLDialogElement -> Element
toElement = unsafeCoerce

toNode :: HTMLDialogElement -> Node
toNode = unsafeCoerce

toChildNode :: HTMLDialogElement -> ChildNode
toChildNode = unsafeCoerce

toNonDocumentTypeChildNode :: HTMLDialogElement -> NonDocumentTypeChildNode
toNonDocumentTypeChildNode = unsafeCoerce

toParentNode :: HTMLDialogElement -> ParentNode
toParentNode = unsafeCoerce

toEventTarget :: HTMLDialogElement -> EventTarget
toEventTarget = unsafeCoerce

foreign import open :: HTMLDialogElement -> Effect Boolean
foreign import setOpen :: Boolean -> HTMLDialogElement -> Effect Unit

foreign import returnValue :: HTMLDialogElement -> Effect String
foreign import setReturnValue :: String -> HTMLDialogElement -> Effect Unit

foreign import show :: HTMLDialogElement -> Effect Unit
foreign import showModal :: HTMLDialogElement -> Effect Unit

foreign import _close :: Nullable String -> HTMLDialogElement -> Effect Unit

close :: Maybe String -> HTMLDialogElement -> Effect Unit
close = _close <<< toNullable