Skip to content

Commit

Permalink
Merge pull request #35 from tinymce/fix_elementFromPoint
Browse files Browse the repository at this point in the history
Document.elementFromPoint is now optional (and nullable)
  • Loading branch information
TheSpyder authored Oct 31, 2021
2 parents 7e161e3 + 331ff76 commit c7e6d3a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Done:
* Added `IntersectionObserver` and `IntersectionObserverEntry` bindings (#27)
* Imported `bs-fetch` and converted it to "t-first" (#31)
* Added `WebSocket` bindings (#34)
* Updated `Document.elementFromPoint` api to account for null return values (#35)

Todo:
* Convert more input types to `node_like` and `element_like` to improve usability
Expand Down
6 changes: 5 additions & 1 deletion lib/js/tests/Webapi/Dom/Webapi__Dom__Document__test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ document.createTreeWalker(el, Webapi__Dom__Types.WhatToShow.many({
return 0;
}));

document.elementFromPoint(0, 0);
var el$1 = document.elementFromPoint(0, 0);

if (!(el$1 == null)) {
console.log(el$1);
}

document.elementsFromPoint(0, 0);

Expand Down
5 changes: 2 additions & 3 deletions src/Webapi/Dom/Webapi__Dom__Document.res
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ module Impl = (
Webapi__Dom__Types.WhatToShow.t,
Dom.nodeFilter,
) => Dom.treeWalker = "createTreeWalker"
@send
external elementFromPoint: (T.t, int, int) => Dom.element =
"" /* experimental, but widely supported */
@send @return(nullable)
external elementFromPoint: (T.t, int, int) => option<Dom.element> = "elementFromPoint"
@send external elementsFromPoint: (T.t, int, int) => array<Dom.element> = "" /* experimental */
@send external enableStyleSheetsForSet: (T.t, string) => unit = ""
@send external exitPointerLock: T.t => unit = "" /* experimental */
Expand Down
5 changes: 4 additions & 1 deletion tests/Webapi/Dom/Webapi__Dom__Document__test.res
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ let _ = document->createTreeWalkerWithWhatToShowFilter(
},
NodeFilter.make(_ => 0),
)
let _ = document->elementFromPoint(0, 0)
switch (document->elementFromPoint(0, 0)) {
| Some(el) => Js.log(el)
| None => ()
}
let _ = document->elementsFromPoint(0, 0)
let _ = document->enableStyleSheetsForSet("my-stylesheet-set")
let _ = document->exitPointerLock
Expand Down

0 comments on commit c7e6d3a

Please sign in to comment.