Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Base/BaseCSSFontLoading.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type fontFaceSetLoadStatus =
*/
@editor.completeFrom(BaseCSSFontLoading.FontFaceSet)
type rec fontFaceSet = private {
...BaseEvent.eventTarget,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just spreading an empty object and creating a circular dependency.

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/FontFaceSet/ready)
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Base/BaseEncryptedMediaExtensions.res
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ This WebApiEncryptedMediaExtensions API interface represents a context for mess
*/
@editor.completeFrom(BaseEncryptedMediaExtensions.MediaKeySession)
type mediaKeySession = private {
...BaseEvent.eventTarget,
...DOM.eventTarget,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/MediaKeySession/sessionId)
*/
Expand Down
6 changes: 0 additions & 6 deletions src/Base/BaseEvent.res

This file was deleted.

131 changes: 127 additions & 4 deletions src/Base/DOM.res
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,135 @@ type barProp = {
visible: bool,
}

/**
EventTarget is a WebApiDOM interface implemented by objects that can receive events and may have listeners for them.
[See EventTarget on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget)
*/
@editor.completeFrom(EventTarget)
type eventTarget = private {}

/**
An event which takes place in the DOM.
[See WebApiEvent on MDN](https://developer.mozilla.org/docs/Web/API/Event)
*/
@editor.completeFrom(Event)
type event = private {
/**
Returns the type of event, e.g. "click", "hashchange", or "submit".
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Event/type)
*/
@as("type")
type_: EventType.t,
/**
Returns the object to which event is dispatched (its target).
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Event/target)
*/
target: Null.t<eventTarget>,
/**
Returns the object whose event listener's callback is currently being invoked.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Event/currentTarget)
*/
currentTarget: Null.t<eventTarget>,
/**
Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Event/eventPhase)
*/
eventPhase: int,
/**
Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Event/bubbles)
*/
bubbles: bool,
/**
Returns true or false depending on how event was initialized. Its return value does not always carry meaning, but true can indicate that part of the operation during which event was dispatched, can be canceled by invoking the preventDefault() method.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Event/cancelable)
*/
cancelable: bool,
/**
Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Event/defaultPrevented)
*/
defaultPrevented: bool,
/**
Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Event/composed)
*/
composed: bool,
/**
Returns true if event was dispatched by the user agent, and false otherwise.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Event/isTrusted)
*/
isTrusted: bool,
/**
Returns the event's timestamp as the number of milliseconds measured relative to the time origin.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Event/timeStamp)
*/
timeStamp: float,
}

type eventInit = {
mutable bubbles?: bool,
mutable cancelable?: bool,
mutable composed?: bool,
}

/**
The ExtendableEvent interface extends the lifetime of the install and activate events dispatched on the global scope as part of the service worker lifecycle.
[See ExtendableEvent on MDN](https://developer.mozilla.org/docs/Web/API/ExtendableEvent)
*/
@editor.completeFrom(ExtendableEvent)
type extendableEvent = private {
...event,
}

/**
A controller object that allows you to abort one or more WebApiDOM requests as and when desired.
[See AbortController on MDN](https://developer.mozilla.org/docs/Web/API/AbortController)
*/
@editor.completeFrom(AbortController)
type rec abortController = private {
/**
Returns the AbortSignal object associated with this object.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AbortController/signal)
*/
signal: abortSignal,
}
/**
A signal object that allows you to communicate with a WebApiDOM request (such as a WebApiFetch) and abort it if required via an AbortController object.
[See AbortSignal on MDN](https://developer.mozilla.org/docs/Web/API/AbortSignal)
*/
@editor.completeFrom(AbortSignal) and abortSignal = private {
...eventTarget,
/**
Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AbortSignal/aborted)
*/
aborted: bool,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AbortSignal/reason)
*/
reason: JSON.t,
}

module EventListener = {
type t<'event> = 'event => unit

type options = {mutable capture?: bool}

type addEventListenerOptions = {
...options,
mutable passive?: bool,
mutable once?: bool,
mutable signal?: abortSignal,
}
}

/**
[See ScreenOrientation on MDN](https://developer.mozilla.org/docs/Web/API/ScreenOrientation)
*/
@editor.completeFrom(ScreenOrientation)
type screenOrientation = private {
...BaseEvent.eventTarget,
...eventTarget,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/ScreenOrientation/type)
*/
Expand Down Expand Up @@ -2310,7 +2433,7 @@ TODO: mark as private once mutating fields of private records is allowed
*/
@editor.completeFrom(Node)
type rec node = {
...BaseEvent.eventTarget,
...eventTarget,
/**
Returns the type of node.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Node/nodeType)
Expand Down Expand Up @@ -6972,7 +7095,7 @@ Stores information on a media query applied to a document, and handles sending n
*/
@editor.completeFrom(MediaQueryList)
type mediaQueryList = private {
...BaseEvent.eventTarget,
...eventTarget,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/MediaQueryList/media)
*/
Expand Down Expand Up @@ -7045,7 +7168,7 @@ type timeRanges = private {
*/
@editor.completeFrom(TextTrackList)
type textTrackList = private {
...BaseEvent.eventTarget,
...eventTarget,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextTrackList/length)
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Canvas/CanvasTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ TODO: mark as private once mutating fields of private records is allowed
*/
@editor.completeFrom(OffscreenCanvas)
type offscreenCanvas = {
...EventTypes.eventTarget,
...DOM.eventTarget,
/**
These attributes return the dimensions of the OffscreenCanvas object's bitmap.

Expand Down
2 changes: 1 addition & 1 deletion src/ChannelMessaging/ChannelMessagingTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This Channel Messaging API interface represents one of the two ports of a Messag
*/
@editor.completeFrom(MessagePort)
type messagePort = private {
...EventTypes.eventTarget,
...DOM.eventTarget,
}

type structuredSerializeOptions = {mutable transfer?: array<Dict.t<string>>}
2 changes: 1 addition & 1 deletion src/Clipboard/ClipboardTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type clipboardItem = private {
*/
@editor.completeFrom(WebApiClipboard)
type clipboard = private {
...EventTypes.eventTarget,
...DOM.eventTarget,
}

type clipboardItemOptions = {mutable presentationStyle?: presentationStyle}
4 changes: 2 additions & 2 deletions src/CredentialManagement/CredentialManagementTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type publicKeyCredentialRequestOptions = {

type credentialRequestOptions = {
mutable mediation?: credentialMediationRequirement,
mutable signal?: EventTypes.abortSignal,
mutable signal?: DOM.abortSignal,
mutable publicKey?: publicKeyCredentialRequestOptions,
}

Expand Down Expand Up @@ -133,6 +133,6 @@ type publicKeyCredentialCreationOptions = {
}

type credentialCreationOptions = {
mutable signal?: EventTypes.abortSignal,
mutable signal?: DOM.abortSignal,
mutable publicKey?: publicKeyCredentialCreationOptions,
}
2 changes: 1 addition & 1 deletion src/DOM/Document.res
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ external createAttributeNS: (
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Document/createEvent)
*/
@send
external createEvent: (DomTypes.document, string) => EventTypes.event = "createEvent"
external createEvent: (DomTypes.document, string) => DOM.event = "createEvent"

/**
Returns an empty range object that has both of its boundary points positioned at the beginning of the document.
Expand Down
70 changes: 0 additions & 70 deletions src/DOM/DomGlobal.res
Comment thread
jderochervlk marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -294,76 +294,6 @@ external requestAnimationFrame: (float => unit) => int = "requestAnimationFrame"
*/
external cancelAnimationFrame: int => unit = "cancelAnimationFrame"

/**
Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
*/
external addEventListener: (
EventType.t,
EventTypes.eventListener<'event>,
~options: EventTypes.addEventListenerOptions=?,
) => unit = "addEventListener"

/**
Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
*/
external addEventListenerWithCapture: (
EventType.t,
EventTypes.eventListener<'event>,
@as(json`true`) _,
) => unit = "addEventListener"

/**
Removes the event listener in target's event listener list with the same type, callback, and options.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
*/
external removeEventListener: (
EventType.t,
EventTypes.eventListener<'event>,
~options: EventTypes.eventListenerOptions=?,
) => unit = "removeEventListener"

/**
Removes the event listener in target's event listener list with the same type, callback, and options.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
*/
external removeEventListenerUseCapture: (
EventType.t,
EventTypes.eventListener<'event>,
@as(json`true`) _,
) => unit = "removeEventListener"

/**
Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
*/
external dispatchEvent: EventTypes.event => bool = "dispatchEvent"

/**
Closes the window.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/close)
Expand Down
6 changes: 2 additions & 4 deletions src/DOM/DomTypes.res
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
@@warning("-30")

type domStringList = DOM.domStringList
type eventTarget = EventTypes.eventTarget
type eventType = EventType.t
type file = FileTypes.file
type blob = FileTypes.blob
type fileSystemEntry = FileAndDirectoryEntriesTypes.fileSystemEntry
Expand Down Expand Up @@ -336,7 +334,7 @@ type barProp = {
*/
@editor.completeFrom(ScreenOrientation)
type screenOrientation = private {
...eventTarget,
...DOM.eventTarget,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/ScreenOrientation/type)
*/
Expand Down Expand Up @@ -1806,7 +1804,7 @@ The CanvasRenderingContext2D interface, part of the WebApiCanvas API, provides t
type canvasRenderingContext2D

type rec animation = {
...eventTarget,
...DOM.eventTarget,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Animation/id)
*/
Expand Down
7 changes: 2 additions & 5 deletions src/Event/AbortController.res
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AbortController)
*/
@new
external make: unit => EventTypes.abortController = "AbortController"
external make: unit => DOM.abortController = "AbortController"

/**
Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AbortController/abort)
*/
@send
external abort: (EventTypes.abortController, ~reason: JSON.t=?) => unit = "abort"
external abort: (DOM.abortController, ~reason: JSON.t=?) => unit = "abort"
10 changes: 5 additions & 5 deletions src/Event/AbortSignal.res
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
include EventTarget.Impl({type t = EventTypes.abortSignal})
include EventTarget.Impl({type t = DOM.abortSignal})

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AbortSignal/abort_static)
*/
@scope("AbortSignal")
external abort: (~reason: JSON.t=?) => EventTypes.abortSignal = "abort"
external abort: (~reason: JSON.t=?) => DOM.abortSignal = "abort"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AbortSignal/timeout_static)
*/
@scope("AbortSignal")
external timeout: int => EventTypes.abortSignal = "timeout"
external timeout: int => DOM.abortSignal = "timeout"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AbortSignal/any_static)
*/
@scope("AbortSignal")
external any: array<EventTypes.abortSignal> => EventTypes.abortSignal = "any"
external any: array<DOM.abortSignal> => DOM.abortSignal = "any"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AbortSignal/throwIfAborted)
*/
@send
external throwIfAborted: EventTypes.abortSignal => unit = "throwIfAborted"
external throwIfAborted: DOM.abortSignal => unit = "throwIfAborted"
Loading