Skip to content

Commit c7e6d3a

Browse files
authored
Merge pull request #35 from tinymce/fix_elementFromPoint
Document.elementFromPoint is now optional (and nullable)
2 parents 7e161e3 + 331ff76 commit c7e6d3a

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Done:
99
* Added `IntersectionObserver` and `IntersectionObserverEntry` bindings (#27)
1010
* Imported `bs-fetch` and converted it to "t-first" (#31)
1111
* Added `WebSocket` bindings (#34)
12+
* Updated `Document.elementFromPoint` api to account for null return values (#35)
1213

1314
Todo:
1415
* Convert more input types to `node_like` and `element_like` to improve usability

lib/js/tests/Webapi/Dom/Webapi__Dom__Document__test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ document.createTreeWalker(el, Webapi__Dom__Types.WhatToShow.many({
6464
return 0;
6565
}));
6666

67-
document.elementFromPoint(0, 0);
67+
var el$1 = document.elementFromPoint(0, 0);
68+
69+
if (!(el$1 == null)) {
70+
console.log(el$1);
71+
}
6872

6973
document.elementsFromPoint(0, 0);
7074

src/Webapi/Dom/Webapi__Dom__Document.res

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ module Impl = (
9595
Webapi__Dom__Types.WhatToShow.t,
9696
Dom.nodeFilter,
9797
) => Dom.treeWalker = "createTreeWalker"
98-
@send
99-
external elementFromPoint: (T.t, int, int) => Dom.element =
100-
"" /* experimental, but widely supported */
98+
@send @return(nullable)
99+
external elementFromPoint: (T.t, int, int) => option<Dom.element> = "elementFromPoint"
101100
@send external elementsFromPoint: (T.t, int, int) => array<Dom.element> = "" /* experimental */
102101
@send external enableStyleSheetsForSet: (T.t, string) => unit = ""
103102
@send external exitPointerLock: T.t => unit = "" /* experimental */

tests/Webapi/Dom/Webapi__Dom__Document__test.res

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ let _ = document->createTreeWalkerWithWhatToShowFilter(
6161
},
6262
NodeFilter.make(_ => 0),
6363
)
64-
let _ = document->elementFromPoint(0, 0)
64+
switch (document->elementFromPoint(0, 0)) {
65+
| Some(el) => Js.log(el)
66+
| None => ()
67+
}
6568
let _ = document->elementsFromPoint(0, 0)
6669
let _ = document->enableStyleSheetsForSet("my-stylesheet-set")
6770
let _ = document->exitPointerLock

0 commit comments

Comments
 (0)