-
-
Notifications
You must be signed in to change notification settings - Fork 151
DOM Node APIs #844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Freddy03h
wants to merge
4
commits into
main
Choose a base branch
from
dom-node-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
DOM Node APIs #844
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| 'use strict'; | ||
|
|
||
| var DOMAPI$ReactNative = require("../types/DOMAPI.bs.js"); | ||
| var NativeMethods$ReactNative = require("./NativeMethods.bs.js"); | ||
|
|
||
| NativeMethods$ReactNative.Make({}); | ||
|
|
||
| DOMAPI$ReactNative.$$Element.Impl({}); | ||
|
|
||
| /* Not a pure module */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| type element | ||
| type element = DOMAPI.element | ||
| type ref = Ref.t<element> | ||
|
|
||
| include NativeMethods.Make({ | ||
| type t = element | ||
| }) | ||
|
|
||
| include DOMAPI.Element.Impl({ | ||
| type t = element | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| 'use strict'; | ||
|
|
||
|
|
||
| var $$NodeList = {}; | ||
|
|
||
| var $$HTMLCollection = {}; | ||
|
|
||
| function Impl(T) { | ||
| return {}; | ||
| } | ||
|
|
||
| var $$Node = { | ||
| Impl: Impl | ||
| }; | ||
|
|
||
| function Impl$1(T) { | ||
| return {}; | ||
| } | ||
|
|
||
| var $$Element = { | ||
| Impl: Impl$1 | ||
| }; | ||
|
|
||
| var $$Document = {}; | ||
|
|
||
| var $$Text = {}; | ||
|
|
||
| function classify(node) { | ||
| switch (node.nodeType) { | ||
| case 1 : | ||
| return { | ||
| TAG: "Element", | ||
| _0: node | ||
| }; | ||
| case 3 : | ||
| return { | ||
| TAG: "Text", | ||
| _0: node | ||
| }; | ||
| case 9 : | ||
| return { | ||
| TAG: "Document", | ||
| _0: node | ||
| }; | ||
| default: | ||
| return "Unknown"; | ||
| } | ||
| } | ||
|
|
||
| var NodeType = { | ||
| classify: classify | ||
| }; | ||
|
|
||
| exports.$$NodeList = $$NodeList; | ||
| exports.$$HTMLCollection = $$HTMLCollection; | ||
| exports.$$Node = $$Node; | ||
| exports.$$Element = $$Element; | ||
| exports.$$Document = $$Document; | ||
| exports.$$Text = $$Text; | ||
| exports.NodeType = NodeType; | ||
| /* No side effect */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| @@warning("-30") | ||
|
|
||
| type nodeList<'node> = {length: int} | ||
| type htmlCollection<'element> = {length: int} | ||
|
|
||
| type readOnlyNode<'node, 'document, 'element> = { | ||
| // Node | ||
| childNodes: nodeList<'node>, | ||
| firstChild: Js.Null.t<'node>, | ||
| isConnected: bool, | ||
| lastChild: Js.Null.t<'node>, | ||
| nextSibling: Js.Null.t<'node>, | ||
| nodeType: int, | ||
| nodeName: string, | ||
| nodeValue: Js.Null.t<string>, | ||
| ownerDocument: Js.Null.t<'document>, | ||
| parentElement: Js.Null.t<'element>, | ||
| parentNode: Js.Null.t<'node>, | ||
| previousSibling: Js.Null.t<'node>, | ||
| textContent: string, | ||
| } | ||
|
|
||
| type rec node = { | ||
| ...readOnlyNode<node, document, element>, | ||
| } | ||
|
|
||
| and element = { | ||
| // Node | ||
| ...readOnlyNode<node, document, element>, | ||
| // Element | ||
| childElementCount: int, | ||
| children: htmlCollection<element>, | ||
| clientHeight: int, | ||
| clientLeft: int, | ||
| clientTop: int, | ||
| clientWidth: int, | ||
| firstElementChild: Js.Null.t<element>, | ||
| id: string, | ||
| lastElementChild: Js.Null.t<element>, | ||
| nextElementSibling: Js.Null.t<element>, | ||
| previousElementSibling: Js.Null.t<element>, | ||
| scrollHeight: int, | ||
| scrollLeft: int, | ||
| scrollTop: int, | ||
| scrollWidth: int, | ||
| tagName: string, | ||
| // HTMLElement | ||
| offsetHeight: int, | ||
| offsetLeft: int, | ||
| offsetTop: int, | ||
| offsetWidth: int, | ||
| offsetParent: Js.Null.t<element>, | ||
| } | ||
|
|
||
| and text = { | ||
| // Node | ||
| ...readOnlyNode<node, document, element>, | ||
| // CharacterData | ||
| data: string, | ||
| length: int, | ||
| nextElementSibling: Js.Null.t<element>, | ||
| previousElementSibling: Js.Null.t<element>, | ||
| } | ||
|
|
||
| and document = { | ||
| ...readOnlyNode<node, document, element>, | ||
| childElementCount: int, | ||
| children: htmlCollection<element>, | ||
| documentElement: element, | ||
| firstElementChild: Js.Null.t<element>, | ||
| lastElementChild: Js.Null.t<element>, | ||
| } | ||
|
|
||
| module NodeList = { | ||
| @send | ||
| external item: (nodeList<'node>, int) => Js.Null.t<'node> = "item" | ||
| } | ||
|
|
||
| module HTMLCollection = { | ||
| @send | ||
| external item: (htmlCollection<'element>, int) => Js.Null.t<'element> = "item" | ||
|
|
||
| @send | ||
| external namedItem: (htmlCollection<'element>, string) => Js.Null.t<'element> = "namedItem" | ||
| } | ||
|
|
||
| module Node = { | ||
| module Impl = ( | ||
| T: { | ||
| type t | ||
| }, | ||
| ) => { | ||
| external asNode: T.t => node = "%identity" | ||
|
|
||
| @send | ||
| external compareDocumentPosition: (T.t, node) => int = "compareDocumentPosition" | ||
| @send external contains: (T.t, node) => bool = "contains" | ||
| @send external getRootNode: T.t => node = "getRootNode" | ||
| @send external hasChildNodes: T.t => bool = "hasChildNodes" | ||
| } | ||
|
|
||
| include Impl({ | ||
| type t = node | ||
| }) | ||
| } | ||
|
|
||
| module Element = { | ||
| module Impl = ( | ||
| T: { | ||
| type t | ||
| }, | ||
| ) => { | ||
| include Node.Impl({ | ||
| type t = T.t | ||
| }) | ||
|
|
||
| @send | ||
| external getBoundingClientRect: T.t => Rect.t = "getBoundingClientRect" | ||
| @send | ||
| external hasPointerCapture: (T.t, int) => bool = "hasPointerCapture" | ||
| @send | ||
| external releasePointerCapture: (T.t, int) => unit = "releasePointerCapture" | ||
| @send | ||
| external setPointerCapture: (T.t, int) => unit = "setPointerCapture" | ||
| @send external focus: T.t => unit = "focus" | ||
| @send external blur: T.t => unit = "blur" | ||
|
|
||
| @send external setNativeProps: (T.t, {..}) => unit = "setNativeProps" | ||
| } | ||
|
|
||
| include Impl({ | ||
| type t = element | ||
| }) | ||
| } | ||
|
|
||
| module Document = { | ||
| include Node.Impl({ | ||
| type t = document | ||
| }) | ||
|
|
||
| @send external getElementById: (document, string) => Js.Null.t<element> = "getElementById" | ||
| } | ||
|
|
||
| module Text = { | ||
| include Node.Impl({ | ||
| type t = text | ||
| }) | ||
|
|
||
| @send external substringData: (text, ~offset: int, ~count: int) => string = "substringData" | ||
| } | ||
|
|
||
| module NodeType = { | ||
| /* | ||
| Helper for handle NodeType | ||
| Waiting for this issue : | ||
| https://github.com/rescript-lang/rescript/issues/8280 | ||
| to use this type for node instead | ||
|
|
||
| @tag("nodeType") | ||
| type rec node = | ||
| | @as(1) Element(element) | ||
| | @as(3) Text(text) | ||
| | @as(9) Document(document) | ||
|
|
||
| and remove this helper | ||
| */ | ||
| type t = | ||
| | Element(element) | ||
| | Text(text) | ||
| | Document(document) | ||
| | Unknown | ||
|
|
||
| let classify = (node: node) => | ||
| switch node { | ||
| | {nodeType: 1} => Element(node->Obj.magic) | ||
| | {nodeType: 3} => Text(node->Obj.magic) | ||
| | {nodeType: 9} => Document(node->Obj.magic) | ||
| | _ => Unknown | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NativeElementnow includes the new DOM-style methods on every ref, but this package still advertisesreact-native >=0.81.0support. React Native only started returning DOM-like nodes from refs in 0.82, so an app that is still on 0.81 can compile against these bindings and then hitundefined is not a functionat runtime as soon as it calls one of the newly exposed methods.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be done before release