Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 5a2beff

Browse files
author
rob
committed
feat: add bindings for HTMLFormControlsCollection, RadioNodeList, etc
1 parent 31fdb22 commit 5a2beff

12 files changed

+95
-15
lines changed

Diff for: CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
### 0.20.0
2+
3+
* Upgraded to [email protected]
4+
* Added bindings for `HTMLFormControlsCollection`
5+
* Added binding for `HTMLOptionsCollection`
6+
* Added bindings for `RadioNodeList`
7+
* Added binding for `Document.forms`
8+
* Added binding for `HTMLFormElement.elements`
9+
* ResizeObserver and ResizeObserverEntry now use the rescript Dom phantom type
10+
111
### 0.19.0
212

313
* Added bindings to `ReadableStream`

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bs-webapi",
3-
"version": "0.19.0",
3+
"version": "0.20.0",
44
"description": "Reason + BuckleScript bindings to DOM",
55
"repository": {
66
"type": "git",
@@ -26,7 +26,7 @@
2626
"author": "chenglou",
2727
"license": "MIT",
2828
"devDependencies": {
29-
"bs-platform": "^7.1.0"
29+
"bs-platform": "^8.2.0"
3030
},
3131
"dependencies": {
3232
"bs-fetch": "^0.6.2"

Diff for: src/Webapi/Dom/Webapi__Dom__Document.re

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ module Impl = (T: {type t;}) => {
3434
[@bs.get] external implementation : T.t => Dom.domImplementation = "";
3535
[@bs.get] external lastStyleSheetSet : T.t => string = "";
3636
[@bs.get] [@bs.return nullable] external pointerLockElement : T.t => option(Dom.element) = ""; /* experimental */
37+
/** @since 0.20.0 */
38+
[@bs.get] external forms : T.t => Dom.htmlCollection = "";
3739

3840
[@bs.get] external preferredStyleSheetSet : T.t => string = "";
3941
[@bs.get] [@bs.return nullable] external scrollingElement : T.t => option(Dom.element) = "";

Diff for: src/Webapi/Dom/Webapi__Dom__HtmlCollection.re

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
type t = Dom.htmlCollection;
1+
module Impl = (T: { type t;}) => {
2+
type t_htmlCollection = T.t;
3+
[@bs.val] [@bs.scope ("Array", "prototype", "slice")] external toArray : t_htmlCollection => array(Dom.element) = "call";
4+
5+
[@bs.get] external length : t_htmlCollection => int = "";
6+
[@bs.send.pipe : t_htmlCollection] [@bs.return nullable] external item : int => option(Dom.element) = "";
7+
[@bs.send.pipe : t_htmlCollection] [@bs.return nullable] external namedItem : string => option(Dom.element) = "";
8+
};
29

3-
[@bs.val] [@bs.scope ("Array", "prototype", "slice")] external toArray : t => array(Dom.element) = "call";
10+
type t = Dom.htmlCollection;
411

5-
[@bs.get] external length : t => int = "";
6-
[@bs.send.pipe : t] [@bs.return nullable] external item : int => option(Dom.element) = "";
7-
[@bs.send.pipe : t] [@bs.return nullable] external namedItem : string => option(Dom.element) = "";
12+
include Impl({ type nonrec t = t; });
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
type t = Dom.htmlFormControlsCollection;
2+
3+
type t_namedItem = [
4+
| `RadioNodeList(Dom.radioNodeList)
5+
| `Button(Dom.htmlButtonElement)
6+
| `Fieldset(Dom.htmlFieldSetElement)
7+
| `Input(Dom.htmlInputElement)
8+
| `Object(Dom.htmlObjectElement)
9+
| `Output(Dom.htmlOutputElement)
10+
| `Select(Dom.htmlSelectElement)
11+
| `Textarea(Dom.htmlTextAreaElement)
12+
];
13+
14+
include Webapi__Dom__HtmlCollection.Impl({ type nonrec t = t; });
15+
16+
let isRadioNodeList: 'a => bool = [%raw {|
17+
function(x) { return x instanceof RadioNodeList; }
18+
|}];
19+
20+
[@bs.send] [@bs.return nullable] external _namedItem: (t, string) => option('a) = "namedItem";
21+
let namedItem = (t, string) =>
22+
switch (_namedItem(t, string)) {
23+
| Some(el) =>
24+
if (Webapi__Dom__RadioNodeList.unsafeAsRadioNodeList(el)->isRadioNodeList) {
25+
el->Obj.magic->`RadioNodeList->Some;
26+
} else {
27+
switch (Webapi__Dom__Element.tagName(el)) {
28+
// fixme: this should be a classify function in Webapi__Dom__HtmlElement
29+
| "button" => el->Obj.magic->`Button->Some
30+
| "fieldset" => el->Obj.magic->`Fieldset->Some
31+
| "input" => el->Obj.magic->`Input->Some
32+
| "object" => el->Obj.magic->`Object->Some
33+
| "output" => el->Obj.magic->`Output->Some
34+
| "select" => el->Obj.magic->`Select->Some
35+
| "textarea" => el->Obj.magic->`Textarea->Some
36+
| _ => None
37+
};
38+
}
39+
| None => None
40+
};

Diff for: src/Webapi/Dom/Webapi__Dom__HtmlFormElement.re

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
module Impl = (T: {type t;}) => {
77
type t_htmlFormElement = T.t;
88

9-
/* TODO: elements: HTMLFormControlsCollection */
9+
/** @since 0.20.0 */
10+
[@bs.get] external elements : t_htmlFormElement => Webapi__Dom__HtmlFormControlsCollection.t = "elements";
1011
[@bs.get] external length : t_htmlFormElement => int = "";
1112
[@bs.get] external name : t_htmlFormElement => string = "";
1213
[@bs.set] external setName : (t_htmlFormElement, string) => unit = "name";

Diff for: src/Webapi/Dom/Webapi__Dom__HtmlOptionsCollection.re

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type t = Dom.htmlOptionsCollection;
2+
include Webapi__Dom__HtmlCollection.Impl({ type nonrec t = t; });

Diff for: src/Webapi/Dom/Webapi__Dom__NodeList.re

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
type t = Dom.nodeList;
1+
module Impl = (T: {type t;}) => {
2+
type t_nodeList = T.t;
3+
4+
[@bs.val] external toArray : t_nodeList => array(Dom.node) = "Array.prototype.slice.call";
25

3-
[@bs.val] external toArray : t => array(Dom.node) = "Array.prototype.slice.call";
6+
[@bs.send.pipe : t_nodeList] external forEach : ((Dom.node, int) => unit) => unit = "";
47

5-
[@bs.send.pipe : t] external forEach : ((Dom.node, int) => unit) => unit = "";
8+
[@bs.get] external length : t_nodeList => int = "";
69

7-
[@bs.get] external length : t => int = "";
10+
[@bs.send.pipe : t_nodeList] [@bs.return nullable] external item : int => option(Dom.node) = "";
11+
};
12+
13+
type t = Dom.nodeList;
814

9-
[@bs.send.pipe : t] [@bs.return nullable] external item : int => option(Dom.node) = "";
15+
include Impl({ type nonrec t = t; });

Diff for: src/Webapi/Dom/Webapi__Dom__RadioNodeList.re

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Impl = (T: {type t;}) => {
2+
type t_radioNodeList = T.t;
3+
[@bs.get] external value: t_radioNodeList => string = "value";
4+
5+
external unsafeAsRadioNodeList: 'a => t_radioNodeList = "%identity";
6+
};
7+
8+
type t = Dom.radioNodeList;
9+
10+
include Webapi__Dom__NodeList.Impl({type nonrec t = t;});
11+
include Impl({type nonrec t = t;});
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type t;
1+
type t = Dom.resizeObserverEntry;
22

33
[@bs.get] external contentRect: t => Dom.domRect = "";
44
[@bs.get] external target: t => Dom.element = "";

Diff for: src/Webapi/Webapi__Dom.re

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ module EventTarget = Webapi__Dom__EventTarget;
2424
module FocusEvent = Webapi__Dom__FocusEvent;
2525
module History = Webapi__Dom__History;
2626
module HtmlCollection = Webapi__Dom__HtmlCollection;
27+
module HtmlFormControlsCollection = Webapi__Dom__HtmlFormControlsCollection;
28+
module HtmlOptionsCollection = Webapi__Dom__HtmlOptionsCollection;
2729
module HtmlDocument = Webapi__Dom__HtmlDocument;
2830
module HtmlElement = Webapi__Dom__HtmlElement;
2931
module HtmlFormElement = Webapi__Dom__HtmlFormElement;
@@ -42,6 +44,7 @@ module Node = Webapi__Dom__Node;
4244
module NodeFilter = Webapi__Dom__NodeFilter;
4345
module NodeIterator = Webapi__Dom__NodeIterator;
4446
module NodeList = Webapi__Dom__NodeList;
47+
module RadioNodeList = Webapi__Dom__RadioNodeList;
4548
module PageTransitionEvent = Webapi__Dom__PageTransitionEvent;
4649
module PointerEvent = Webapi__Dom__PointerEvent;
4750
module PopStateEvent = Webapi__Dom__PopStateEvent;

Diff for: src/Webapi/Webapi__ResizeObserver.re

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ResizeObserverEntry = Webapi__ResizeObserver__ResizeObserverEntry;
22

3-
type t;
3+
type t = Dom.resizeObserver;
44

55
[@bs.new]
66
external make: (array(ResizeObserverEntry.t) => unit) => t = "ResizeObserver";

0 commit comments

Comments
 (0)