Skip to content

Commit

Permalink
Merge branch 'improved_types'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpyder committed May 22, 2024
2 parents 40e4b6f + 6cd9a71 commit 4e836b6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
## main


#### :boom: Breaking Change

- Corrected return type of `getPropertyValue` for CSS style attributes (it's nullable and now returns an option).

#### :bug: Bug Fix

- Widened input type of `Window.getComputedStyle`, allowing subclasses of Element (such as HtmlElement).

# 0.9.1

#### :bug: Bug Fix
Expand Down
7 changes: 7 additions & 0 deletions lib/js/tests/Webapi/Dom/Webapi__Dom__Window__test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ window.focus();

window.getComputedStyle(el);

window.getComputedStyle(el);

window.getComputedStyle(el, "hover");

window.getComputedStyle(el, "hover");

window.getSelection();
Expand Down Expand Up @@ -83,7 +87,10 @@ window.onload = (function (param) {
console.log("load");
});

var htmlEl = el;

exports.el = el;
exports.htmlEl = htmlEl;
exports.$$event = $$event;
exports.handleClick = handleClick;
exports.idleId = idleId;
Expand Down
5 changes: 3 additions & 2 deletions src/Webapi/Dom/Webapi__Dom__CssStyleDeclaration.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ type cssRule /* TODO: Move to Webapi__Dom */
@get external parentRule: t => cssRule = "parentRule"

@send external getPropertyPriority: (t, string) => string = "getPropertyPriority"
@send external getPropertyValue: (t, string) => string = "getPropertyValue"
@send @return(nullable)
external getPropertyValue: (t, string) => option<string> = "getPropertyValue"
@send external item: (t, int) => string = "item"
@send external removeProperty: (t, string) => string = "removeProperty"
@send external setProperty: (t, string, string, string) => unit = "setProperty"
Expand Down Expand Up @@ -135,4 +136,4 @@ type cssRule /* TODO: Move to Webapi__Dom */
@get external widows: t => string = "widows"
@get external width: t => string = "width"
@get external wordSpacing: t => string = "wordSpacing"
@get external zIndex: t => string = "zIndex"
@get external zIndex: t => string = "zIndex"
6 changes: 4 additions & 2 deletions src/Webapi/Dom/Webapi__Dom__Window.res
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ module Impl = (
@send external close: t_window => unit = "close"
@send external confirm: (t_window, string) => bool = "confirm"
@send external focus: t_window => unit = "focus"
@send external getComputedStyle: (t_window, Dom.element) => Dom.cssStyleDeclaration = "getComputedStyle"
@send
external getComputedStyle: (t_window, Dom.element_like<'a>) => Dom.cssStyleDeclaration =
"getComputedStyle"
@send
external getComputedStyleWithPseudoElement: (
t_window,
Dom.element,
Dom.element_like<'a>,
string,
) => Dom.cssStyleDeclaration = "getComputedStyle"
@send @return(nullable) external getSelection: t_window => option<Dom.selection> = "getSelection"
Expand Down
3 changes: 3 additions & 0 deletions tests/Webapi/Dom/Webapi__Dom__Window__test.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
open Webapi.Dom

let el = document->Document.createElement("strong")
let htmlEl = el->Element.unsafeAsHtmlElement
let event = document->Document.createEvent("my-event")
let handleClick = _ => print_endline("asd")

Expand Down Expand Up @@ -53,7 +54,9 @@ Window.close(window)
let _ = window->Window.confirm("is ok?")
Window.focus(window)
let _ = window->Window.getComputedStyle(el)
let _ = window->Window.getComputedStyle(htmlEl)
let _ = window->Window.getComputedStyleWithPseudoElement(el, "hover")
let _ = window->Window.getComputedStyleWithPseudoElement(htmlEl, "hover")
let _ = Window.getSelection(window)
let _ = window->Window.matchMedia("max-height: 400")
let _ = window->Window.moveBy(10, -10)
Expand Down

0 comments on commit 4e836b6

Please sign in to comment.