Skip to content
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

Generating bindings with TypeScript-DOM-lib-generator #1

Open
nojaf opened this issue Oct 23, 2024 · 1 comment
Open

Generating bindings with TypeScript-DOM-lib-generator #1

nojaf opened this issue Oct 23, 2024 · 1 comment

Comments

@nojaf
Copy link
Collaborator

nojaf commented Oct 23, 2024

It might be possible to generate some bindings via microsoft/TypeScript-DOM-lib-generator.

In my fork, I've started exploring how we can generate ReScript instead of TypeScript.

It's still early to report any substantial progress, but here’s what I have so far:

// do ReScript stuff here
type event = {
    type: string,
    target: string,
    srcElement: string,
    currentTarget: string,
    eventPhase: string,
    cancelBubble: string,
    bubbles: string,
    cancelable: string,
    returnValue: string,
    defaultPrevented: string,
    composed: string,
    isTrusted: string,
    timeStamp: string,
}
type uIEvent = {
    view: string,
    detail: string,
    which: string,
    ...event,
}
type mouseEvent = {
    screenX: string,
    screenY: string,
    clientX: string,
    clientY: string,
    layerX: string,
    layerY: string,
    ctrlKey: string,
    shiftKey: string,
    altKey: string,
    metaKey: string,
    button: string,
    buttons: string,
    relatedTarget: string,
    movementX: string,
    movementY: string,
    pageX: string,
    pageY: string,
    x: string,
    y: string,
    offsetX: string,
    offsetY: string,
    ...uIEvent,
}

I’d like to use this issue to discuss the generation work.

One thought I have is that the generated content will most likely need manual updates afterward. There has been an idea to use the APIs listed at https://developer.mozilla.org/en-US/docs/Web/API. However, right now, the generator consolidates everything into a single file. It may be beneficial to manually split things up after the generation process is complete.

@zth
Copy link

zth commented Oct 23, 2024

Great stuff!

It's likely that some of the definitions will have to live in the same file because of recursiveness. In that case though, the main definition can live in a general file (imagine type htmlElement = {...}), but we can still have a file for HtmlElement.res:

type t = Webapi.htmlElement

Worth thinking about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants