diff --git a/src/Webapi/Dom/Webapi__Dom__DedicatedWorkerGlobalScope.re b/src/Webapi/Dom/Webapi__Dom__DedicatedWorkerGlobalScope.re new file mode 100644 index 0000000..eb53748 --- /dev/null +++ b/src/Webapi/Dom/Webapi__Dom__DedicatedWorkerGlobalScope.re @@ -0,0 +1,15 @@ +type t = Dom.dedicatedWorkerGlobalScope; + +include Webapi__Dom__WorkerGlobalScope.Impl({ + type nonrec t = t; +}); + +[@mel.get] external name: t => string = "name"; + +[@mel.send.pipe: t] external close: unit = "name"; + +[@mel.send.pipe: t] external postMessage: 'a => unit = "postMessage"; + +[@mel.send.pipe: t] +external postMessageWithTransfers: ('a, array(Webapi__Dom__Window.transferable)) => unit = + "postMessage"; diff --git a/src/Webapi/Dom/Webapi__Dom__MessageChannel.re b/src/Webapi/Dom/Webapi__Dom__MessageChannel.re new file mode 100644 index 0000000..dcf4c05 --- /dev/null +++ b/src/Webapi/Dom/Webapi__Dom__MessageChannel.re @@ -0,0 +1,5 @@ +type t = Dom.messageChannel; + +[@mel.new] external make: unit => t = "MessageChannel"; +[@mel.get] external port1: t => Webapi__Dom__MessagePort.t = "port1"; +[@mel.get] external port2: t => Webapi__Dom__MessagePort.t = "port2"; diff --git a/src/Webapi/Dom/Webapi__Dom__MessageEvent.re b/src/Webapi/Dom/Webapi__Dom__MessageEvent.re new file mode 100644 index 0000000..f548747 --- /dev/null +++ b/src/Webapi/Dom/Webapi__Dom__MessageEvent.re @@ -0,0 +1,23 @@ +type t = Dom.messageEvent; + +include Webapi__Dom__Event.Impl({ + type nonrec t = t; +}); + +[@mel.new] external make: string => t = "MessageEvent"; +[@mel.new] +external makeWithOptions: (string, Js.t({..})) => t = "MessageEvent"; + +[@mel.get] external data: t => 'a = "data"; +[@mel.get] external origin: t => string = "origin"; +[@mel.get] external lastEventId: t => string = "lastEventId"; +[@mel.get] +external source: + t => + [@mel.unwrap] [ + | `Window(Dom.window) + | `MessagePort(Dom.messagePort) + | `ServiceWorker(Dom.serviceWorker) + ] = + "source"; +[@mel.get] external ports: t => array(Dom.messagePort) = "ports"; diff --git a/src/Webapi/Dom/Webapi__Dom__MessagePort.re b/src/Webapi/Dom/Webapi__Dom__MessagePort.re new file mode 100644 index 0000000..0205e74 --- /dev/null +++ b/src/Webapi/Dom/Webapi__Dom__MessagePort.re @@ -0,0 +1,27 @@ +type t = Dom.messagePort; + +include Webapi__Dom__EventTarget.Impl({ + type nonrec t = t; +}); + +[@mel.send.pipe: t] external start: unit => unit = "start"; +[@mel.send.pipe: t] external close: unit => unit = "close"; + +[@mel.send.pipe: t] external postMessage: 'a => unit = "postMessage"; +[@mel.send.pipe: t] external postMessageWithTransfers: ('a, array(Webapi__Dom__Window.transferable)) => unit = "postMessage"; + +[@mel.send.pipe: t] + external addMessageEventListener: + ([@mel.as "message"] _, Dom.messageEvent => unit) => unit = + "addEventListener"; + +[@mel.send.pipe: t] + external removeMessageEventListener: + ([@mel.as "message"] _, Dom.messageEvent => unit) => unit = + "removeEventListener"; + +[@mel.set] +external setOnMessage: (t, Dom.messageEvent => unit) => unit = "onmessage"; +[@mel.set] +external setOnMessageError: (t, Dom.messageEvent => unit) => unit = + "onmessageerror"; diff --git a/src/Webapi/Dom/Webapi__Dom__Worker.re b/src/Webapi/Dom/Webapi__Dom__Worker.re new file mode 100644 index 0000000..0b8c446 --- /dev/null +++ b/src/Webapi/Dom/Webapi__Dom__Worker.re @@ -0,0 +1,38 @@ +type t = Dom.worker; + +include Webapi__Dom__EventTarget.Impl({ + type nonrec t = t; +}); + +[@mel.new] external make: string => t = "Worker"; +[@mel.new] external makeWithUrl: Webapi__Url.t => t = "Worker"; +[@mel.send.pipe: t] external postMessage: 'a => unit = "postMessage"; +[@mel.send.pipe: t] external terminate: unit = "terminate"; + +[@mel.send.pipe: t] +external addMessageEventListener: + ([@mel.as "message"] _, Dom.messageEvent => unit) => unit = + "addEventListener"; + +[@mel.send.pipe: t] +external removeMessageEventListener: + ([@mel.as "message"] _, Dom.messageEvent => unit) => unit = + "removeEventListener"; + +[@mel.send.pipe: t] +external addMessageErrorEventListener: + ([@mel.as "message"] _, Dom.messageEvent => unit) => unit = + "addEventListener"; + +[@mel.send.pipe: t] +external removeMessageErrorEventListener: + ([@mel.as "message"] _, Dom.messageEvent => unit) => unit = + "removeEventListener"; + +[@mel.set] +external setOnError: (t, Dom.errorEvent => unit) => unit = "onerror"; +[@mel.set] +external setOnMessage: (t, Dom.messageEvent => unit) => unit = "onmessage"; +[@mel.set] +external setOnMessageError: (t, Dom.messageEvent => unit) => unit = + "onmessageerror"; diff --git a/src/Webapi/Dom/Webapi__Dom__WorkerGlobalScope.re b/src/Webapi/Dom/Webapi__Dom__WorkerGlobalScope.re new file mode 100644 index 0000000..16e9e52 --- /dev/null +++ b/src/Webapi/Dom/Webapi__Dom__WorkerGlobalScope.re @@ -0,0 +1,41 @@ +type t = Dom.workerGlobalScope; + +module Impl = (T: { + type t; + }) => { + [@mel.get] external self: T.t => T.t = "self"; + + [@mel.send.pipe: T.t] + external addErrorEventListener: + ([@mel.as "error"] _, Dom.messageEvent => unit) => unit = + "addEventListener"; + + [@mel.send.pipe: T.t] + external removeErrorEventListener: + ([@mel.as "error"] _, Dom.messageEvent => unit) => unit = + "removeEventListener"; + + [@mel.send.pipe: T.t] + external addMessageEventListener: + ([@mel.as "message"] _, Dom.messageEvent => unit) => unit = + "addEventListener"; + + [@mel.send.pipe: T.t] + external removeMessageEventListener: + ([@mel.as "message"] _, Dom.messageEvent => unit) => unit = + "removeEventListener"; + + [@mel.send.pipe: T.t] + external addMessageErrorEventListener: + ([@mel.as "messageerror"] _, Dom.messageEvent => unit) => unit = + "addEventListener"; + + [@mel.send.pipe: T.t] + external removeMessageErrorEventListener: + ([@mel.as "messageerror"] _, Dom.messageEvent => unit) => unit = + "removeEventListener"; +}; + +include Webapi__Dom__EventTarget.Impl({ + type nonrec t = t; +}); diff --git a/src/Webapi/Webapi__Dom.re b/src/Webapi/Webapi__Dom.re index 9daa789..5750cae 100644 --- a/src/Webapi/Webapi__Dom.re +++ b/src/Webapi/Webapi__Dom.re @@ -34,6 +34,9 @@ module Image = Webapi__Dom__Image; module InputEvent = Webapi__Dom__InputEvent; module KeyboardEvent = Webapi__Dom__KeyboardEvent; module Location = Webapi__Dom__Location; +module MessageEvent = Webapi__Dom__MessageEvent; +module MessageChannel = Webapi__Dom__MessageChannel; +module MessagePort = Webapi__Dom__MessagePort; module MouseEvent = Webapi__Dom__MouseEvent; module MutationObserver = Webapi__Dom__MutationObserver; module MutationRecord = Webapi__Dom__MutationRecord; @@ -64,10 +67,14 @@ module ValidityState = Webapi__Dom__ValidityState; module WebGlContextEvent = Webapi__Dom__WebGlContextEvent; module WheelEvent = Webapi__Dom__WheelEvent; module Window = Webapi__Dom__Window; +module Worker = Webapi__Dom__Worker; +module WorkerGlobalScope = Webapi__Dom__WorkerGlobalScope; +module DedicatedWorkerGlobalScope = Webapi__Dom__DedicatedWorkerGlobalScope; include Webapi__Dom__Types; external window: Dom.window = "window"; +external dedicatedWorkerGlobalScope: Dom.dedicatedWorkerGlobalScope = "self"; external document: Dom.document = "document"; [@mel.scope "window"] external history: Dom.history = "history"; [@mel.scope "window"] external location: Dom.location = "location";