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

Commit 7f2387a

Browse files
author
rob
committed
feat: add bindings for HTMLFormControlsCollection, RadioNodeList, etc
1 parent faa6bf3 commit 7f2387a

16 files changed

+120
-40
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
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.1
212

313
* Removed dev dependency on `bsdoc` to allow smooth installs on non-Mac

lib/js/tests/Webapi/Webapi__Blob__test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33

44
function test_arrayBuffer(blob) {
5-
return blob.arrayBuffer().then((function (buffer) {
6-
return Promise.resolve((console.log(buffer.byteLength), undefined));
7-
}));
5+
return blob.arrayBuffer().then(function (buffer) {
6+
return Promise.resolve((console.log(buffer.byteLength), undefined));
7+
});
88
}
99

1010
function test_size(blob) {
@@ -23,9 +23,9 @@ function test_stream(blob) {
2323
}
2424

2525
function test_text(blob) {
26-
return blob.text().then((function (string) {
27-
return Promise.resolve((console.log(string), undefined));
28-
}));
26+
return blob.text().then(function (string) {
27+
return Promise.resolve((console.log(string), undefined));
28+
});
2929
}
3030

3131
function test_type(blob) {

lib/js/tests/Webapi/Webapi__ReadableStream__test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ function test_closed(reader) {
88
}
99

1010
function test_cancel(reader) {
11-
return reader.cancel().then((function (param) {
12-
return Promise.resolve((console.log("cancelled"), undefined));
13-
}));
11+
return reader.cancel().then(function (param) {
12+
return Promise.resolve((console.log("cancelled"), undefined));
13+
});
1414
}
1515

1616
function test_cancelWith(reader) {
17-
return reader.cancel("reason").then((function (reason) {
18-
return Promise.resolve((console.log(reason), undefined));
19-
}));
17+
return reader.cancel("reason").then(function (reason) {
18+
return Promise.resolve((console.log(reason), undefined));
19+
});
2020
}
2121

2222
function test_releaseLock(reader) {
@@ -25,13 +25,13 @@ function test_releaseLock(reader) {
2525
}
2626

2727
function test_read(reader) {
28-
return reader.read().then((function (next) {
29-
var __x = next.value;
30-
return Promise.resolve(Belt_Option.forEach((__x == null) ? undefined : Caml_option.some(__x), (function (prim) {
31-
console.log(prim);
32-
33-
})));
34-
}));
28+
return reader.read().then(function (next) {
29+
var __x = next.value;
30+
return Promise.resolve(Belt_Option.forEach((__x == null) ? undefined : Caml_option.some(__x), (function (prim) {
31+
console.log(prim);
32+
33+
})));
34+
});
3535
}
3636

3737
var DefaultReader__test = {
@@ -59,7 +59,7 @@ function test_getReader(stream) {
5959
}
6060

6161
function test_getReaderBYOB(stream) {
62-
return stream.getReader(({"mode": "byob"}));
62+
return stream.getReader({"mode": "byob"});
6363
}
6464

6565
function test_tee(stream) {

lib/js/tests/Webapi/Webapi__ResizeObserver__test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var Caml_array = require("bs-platform/lib/js/caml_array.js");
55
var el = document.createElement("strong");
66

77
function handler(entries) {
8-
var entry = Caml_array.caml_array_get(entries, 0);
8+
var entry = Caml_array.get(entries, 0);
99
entry.contentRect;
1010
entry.target;
1111

lib/js/tests/Webapi/Webapi__Url__test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
var params = new URLSearchParams("key1=value1&key2=value2");
55

6-
params.forEach((function (prim, prim$1) {
7-
console.log(prim, prim$1);
8-
9-
}));
6+
params.forEach(function (prim, prim$1) {
7+
console.log(prim, prim$1);
8+
9+
});
1010

1111
function test_entries(params) {
1212
return Array.from(params.entries());

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bs-webapi",
3-
"version": "0.19.1",
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"

src/Webapi/Dom/Webapi__Dom__Document.re

Lines changed: 2 additions & 0 deletions
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) = "";
Lines changed: 10 additions & 5 deletions
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; });
Lines changed: 40 additions & 0 deletions
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+
};

src/Webapi/Dom/Webapi__Dom__HtmlFormElement.re

Lines changed: 2 additions & 1 deletion
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";

0 commit comments

Comments
 (0)