-
Notifications
You must be signed in to change notification settings - Fork 161
Add Façade Types to Support ResizeObserver #694
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
Merged
armanbilge
merged 11 commits into
scala-js:main
from
chrisshafer:cs/add-resize-observer
Apr 21, 2022
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
53832c8
Adding facade for ResizeObserver and required types
chrisshafer 57e739c
Adding api change set for ResizeObserver
chrisshafer d84ef7d
Extend DomRect with DomRectReadOnly
chrisshafer ac754a5
Apply suggestions from code review
chrisshafer b865f65
Remove MDN attributions and ResizeObserverOptions factory
chrisshafer 70ce65f
Adding type facades for ResizeObserverBoxOption
chrisshafer 67d46af
Merge branch 'cs/add-resize-observer' of github.com:chrisshafer/scala…
chrisshafer 7aa2eb0
account for formatting
chrisshafer 837567a
Apply suggestions from code review
chrisshafer 6d45039
Update API reports to reflect interface changes
chrisshafer a0b2346
Overload observer function instead of default, update api-reports
chrisshafer 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
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
13 changes: 13 additions & 0 deletions
13
dom/src/main/scala-2/org/scalajs/dom/ResizeObserverBoxOption.scala
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,13 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
/** ResizeObserverOptions [[https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe]] */ | ||
@js.native | ||
sealed trait ResizeObserverBoxOption extends js.Any | ||
|
||
object ResizeObserverBoxOption { | ||
val `content-box`: ResizeObserverBoxOption = "content-box".asInstanceOf[ResizeObserverBoxOption] | ||
val `border-box`: ResizeObserverBoxOption = "border-box".asInstanceOf[ResizeObserverBoxOption] | ||
val `device-pixel-content-box`: ResizeObserverBoxOption = "device-pixel-content-box".asInstanceOf[ResizeObserverBoxOption] | ||
} |
12 changes: 12 additions & 0 deletions
12
dom/src/main/scala-3/org/scalajs/dom/ResizeObserverBoxOption.scala
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,12 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
/** ResizeObserverOptions [[https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe]] */ | ||
opaque type ResizeObserverBoxOption <: String = String | ||
|
||
object ResizeObserverBoxOption { | ||
val `content-box`: ResizeObserverBoxOption = "content-box" | ||
val `border-box`: ResizeObserverBoxOption = "border-box" | ||
val `device-pixel-content-box`: ResizeObserverBoxOption = "device-pixel-content-box" | ||
} |
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
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,31 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
@js.native | ||
trait DOMRectReadOnly extends js.Object { | ||
|
||
/** The x coordinate of the DOMRect's origin. */ | ||
def x: Double = js.native | ||
|
||
/** The y coordinate of the DOMRect's origin. */ | ||
def y: Double = js.native | ||
|
||
/** The width of the DOMRect. */ | ||
def width: Double = js.native | ||
|
||
/** The height of the DOMRect. */ | ||
def height: Double = js.native | ||
|
||
/** Returns the top coordinate value of the DOMRect (usually the same as y.) */ | ||
def top: Double = js.native | ||
|
||
/** Returns the right coordinate value of the DOMRect (usually the same as x + width). */ | ||
def right: Double = js.native | ||
|
||
/** Returns the bottom coordinate value of the DOMRect (usually the same as y + height) */ | ||
def bottom: Double = js.native | ||
|
||
/** Returns the left coordinate value of the DOMRect (usually the same as x) */ | ||
def left: Double = js.native | ||
} |
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,25 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSGlobal | ||
|
||
/** The ResizeObserver constructor creates a new ResizeObserver object, which can be used to report changes to the | ||
* content or border box of an Element or the bounding box of an SVGElement | ||
* | ||
* @param callback | ||
* The function called whenever an observed resize occurs. | ||
*/ | ||
@js.native | ||
@JSGlobal | ||
class ResizeObserver(callback: js.Function2[js.Array[ResizeObserverEntry], ResizeObserver, _]) extends js.Object { | ||
|
||
/** Starts observing the specified Element or SVGElement. */ | ||
def observe(target: Element): Unit = js.native | ||
def observe(target: Element, options: ResizeObserverOptions): Unit = js.native | ||
|
||
/** Unobserves all observed Element or SVGElement targets. */ | ||
def disconnect(): Unit = js.native | ||
|
||
/** Ends the observing of a specified Element or SVGElement. */ | ||
def unobserve(target: Element): Unit = js.native | ||
} |
30 changes: 30 additions & 0 deletions
30
dom/src/main/scala/org/scalajs/dom/ResizeObserverEntry.scala
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,30 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
/** The ResizeObserverEntry interface represents the object passedto the ResizeObserver() constructor's callback | ||
* function, which allows you to access the new dimensions of the Element or SVGElement being observed. | ||
*/ | ||
@js.native | ||
trait ResizeObserverEntry extends js.Object { | ||
|
||
/** A reference to the Element or SVGElement being observed */ | ||
def target: Element = js.native | ||
|
||
/** An array containing objects with the new border box size of the observed element. The array is necessary to | ||
* support elements that have multiple fragments, which occur in multi-column scenarios. | ||
*/ | ||
def borderBoxSize: js.Array[ResizeObserverSize] = js.native | ||
|
||
/** An array containing objects with the new content box size of the observed element. The array is necessary to | ||
* support elements that have multiple fragments, which occur in multi-column scenarios. | ||
*/ | ||
def contentBoxSize: js.Array[ResizeObserverSize] = js.native | ||
|
||
/** A [[DOMRectReadOnly]] object containing the new size of the observed element when the callback is run. Note that | ||
* this is better supported than the above two properties, but it is left over from an earlier implementation of the | ||
* Resize Observer API, is still included in the spec for web compat reasons, and may be deprecated in future | ||
* versions. | ||
*/ | ||
def contentRect: DOMRectReadOnly = js.native | ||
} |
7 changes: 7 additions & 0 deletions
7
dom/src/main/scala/org/scalajs/dom/ResizeObserverOptions.scala
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,7 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
trait ResizeObserverOptions extends js.Object { | ||
var box: js.UndefOr[ResizeObserverBoxOption] = js.undefined | ||
} |
19 changes: 19 additions & 0 deletions
19
dom/src/main/scala/org/scalajs/dom/ResizeObserverSize.scala
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,19 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
@js.native | ||
trait ResizeObserverSize extends js.Object { | ||
|
||
/** The length of the observed element's border box in the block dimension. For boxes with a horizontal writing-mode, | ||
* this is the vertical dimension, or height; if the writing-mode is vertical, this is the horizontal dimension, or | ||
* width. | ||
*/ | ||
def blockSize: Double = js.native | ||
|
||
/** The length of the observed element's border box in the inline dimension. For boxes with a horizontal writing-mode, | ||
* this is the horizontal dimension, or width; if the writing-mode is vertical, this is the vertical dimension, or | ||
* height. | ||
*/ | ||
def inlineSize: Double = js.native | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.