Skip to content

Commit

Permalink
Remove references in options
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleHuisman committed Mar 27, 2024
1 parent da6c1cb commit 565b174
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 172 deletions.
20 changes: 4 additions & 16 deletions packages/core/src/detect_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use crate::types::{
};

/// Options for [`detect_overflow`].
#[derive(Debug)]
pub struct DetectOverflowOptions<'a, Element> {
#[derive(Clone, Debug)]
pub struct DetectOverflowOptions<Element> {
/// The clipping element(s) or area in which overflow will be checked.
///
/// Defaults to [`Boundary::ClippingAncestors`].
pub boundary: Option<Boundary<'a, Element>>,
pub boundary: Option<Boundary<Element>>,

/// The root clipping area in which overflow will be checked.
///
Expand All @@ -37,19 +37,7 @@ pub struct DetectOverflowOptions<'a, Element> {
pub padding: Option<Padding>,
}

impl<'a, Element> Clone for DetectOverflowOptions<'a, Element> {
fn clone(&self) -> Self {
Self {
boundary: self.boundary.clone(),
root_boundary: self.root_boundary.clone(),
element_context: self.element_context,
alt_boundary: self.alt_boundary,
padding: self.padding.clone(),
}
}
}

impl<'a, Element> Default for DetectOverflowOptions<'a, Element> {
impl<Element> Default for DetectOverflowOptions<Element> {
fn default() -> Self {
Self {
boundary: Default::default(),
Expand Down
40 changes: 15 additions & 25 deletions packages/core/src/middleware/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use crate::types::{
pub const ARROW_NAME: &str = "arrow";

/// Options for [`Arrow`].
pub struct ArrowOptions<'a, Element> {
#[derive(Clone, Debug)]
pub struct ArrowOptions<Element: Clone> {
/// The arrow element to be positioned.
pub element: &'a Element,
pub element: Element,

/// The padding between the arrow element and the floating element edges.
/// Useful when the floating element has rounded corners.
Expand All @@ -23,15 +24,6 @@ pub struct ArrowOptions<'a, Element> {
pub padding: Option<Padding>,
}

impl<'a, Element> Clone for ArrowOptions<'a, Element> {
fn clone(&self) -> Self {
Self {
element: self.element,
padding: self.padding.clone(),
}
}
}

/// Data stored by [`Arrow`] middleware.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ArrowData {
Expand All @@ -44,37 +36,35 @@ pub struct ArrowData {
/// Provides data to position an inner element of the floating element so that it appears centered to the reference element.
///
/// See <https://floating-ui.com/docs/arrow> for the original documentation.
pub struct Arrow<'a, Element, Window> {
options: Derivable<'a, Element, Window, ArrowOptions<'a, Element>>,
pub struct Arrow<'a, Element: Clone, Window: Clone> {
options: Derivable<'a, Element, Window, ArrowOptions<Element>>,
}

impl<'a, Element, Window> Arrow<'a, Element, Window> {
impl<'a, Element: Clone, Window: Clone> Arrow<'a, Element, Window> {
/// Constructs a new instance of this middleware.
pub fn new(options: ArrowOptions<'a, Element>) -> Self {
pub fn new(options: ArrowOptions<Element>) -> Self {
Arrow {
options: options.into(),
}
}

/// Constructs a new instance of this middleware with derivable options.
pub fn new_derivable(
options: DerivableFn<'a, Element, Window, ArrowOptions<'a, Element>>,
) -> Self {
pub fn new_derivable(options: DerivableFn<'a, Element, Window, ArrowOptions<Element>>) -> Self {
Arrow {
options: options.into(),
}
}
}

impl<'a, Element, Window> Clone for Arrow<'a, Element, Window> {
impl<'a, Element: Clone, Window: Clone> Clone for Arrow<'a, Element, Window> {
fn clone(&self) -> Self {
Self {
options: self.options.clone(),
}
}
}

impl<'a, Element, Window> Middleware<Element, Window> for Arrow<'a, Element, Window> {
impl<'a, Element: Clone, Window: Clone> Middleware<Element, Window> for Arrow<'a, Element, Window> {
fn name(&self) -> &'static str {
ARROW_NAME
}
Expand All @@ -99,7 +89,7 @@ impl<'a, Element, Window> Middleware<Element, Window> for Arrow<'a, Element, Win
let coords = Coords { x, y };
let axis = get_alignment_axis(placement);
let length = get_axis_length(axis);
let arrow_dimensions = platform.get_dimensions(options.element);
let arrow_dimensions = platform.get_dimensions(&options.element);
let min_prop = match axis {
Axis::X => Side::Left,
Axis::Y => Side::Top,
Expand All @@ -114,7 +104,7 @@ impl<'a, Element, Window> Middleware<Element, Window> for Arrow<'a, Element, Win
- coords.get_axis(axis)
- rects.floating.get_length(length);

let arrow_offset_parent = platform.get_offset_parent(options.element);
let arrow_offset_parent = platform.get_offset_parent(&options.element);
let client_size = arrow_offset_parent
.and_then(|arrow_offset_parent| match arrow_offset_parent {
OwnedElementOrWindow::Element(element) => {
Expand Down Expand Up @@ -197,10 +187,10 @@ impl<'a, Element, Window> Middleware<Element, Window> for Arrow<'a, Element, Win
}
}

impl<'a, Element, Window> MiddlewareWithOptions<Element, Window, ArrowOptions<'a, Element>>
for Arrow<'a, Element, Window>
impl<'a, Element: Clone, Window: Clone>
MiddlewareWithOptions<Element, Window, ArrowOptions<Element>> for Arrow<'a, Element, Window>
{
fn options(&self) -> &Derivable<Element, Window, ArrowOptions<'a, Element>> {
fn options(&self) -> &Derivable<Element, Window, ArrowOptions<Element>> {
&self.options
}
}
41 changes: 16 additions & 25 deletions packages/core/src/middleware/auto_placement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ fn get_placement_list(
}

/// Options for [`AutoPlacement`] middleware.
#[derive(Debug)]
pub struct AutoPlacementOptions<'a, Element> {
#[derive(Clone, Debug)]
pub struct AutoPlacementOptions<Element: Clone> {
/// Options for [`detect_overflow`].
///
/// Defaults to [`DetectOverflowOptions::default`].
pub detect_overflow: Option<DetectOverflowOptions<'a, Element>>,
pub detect_overflow: Option<DetectOverflowOptions<Element>>,

/// The axis that runs along the alignment of the floating element. Determines whether to check for most space along this axis.
///
Expand All @@ -92,19 +92,7 @@ pub struct AutoPlacementOptions<'a, Element> {
pub allowed_placements: Option<Vec<Placement>>,
}

impl<'a, Element> Clone for AutoPlacementOptions<'a, Element> {
fn clone(&self) -> Self {
Self {
detect_overflow: self.detect_overflow.clone(),
cross_axis: self.cross_axis,
alignment: self.alignment,
auto_alignment: self.auto_alignment,
allowed_placements: self.allowed_placements.clone(),
}
}
}

impl<'a, Element> Default for AutoPlacementOptions<'a, Element> {
impl<Element: Clone> Default for AutoPlacementOptions<Element> {
fn default() -> Self {
Self {
detect_overflow: Default::default(),
Expand Down Expand Up @@ -134,37 +122,39 @@ pub struct AutoPlacementData {
/// Alternative to [`Flip`][`crate::middleware::Flip`].
///
/// See <https://floating-ui.com/docs/autoPlacement> for the original documentation.
pub struct AutoPlacement<'a, Element, Window> {
options: Derivable<'a, Element, Window, AutoPlacementOptions<'a, Element>>,
pub struct AutoPlacement<'a, Element: Clone, Window: Clone> {
options: Derivable<'a, Element, Window, AutoPlacementOptions<Element>>,
}

impl<'a, Element, Window> Clone for AutoPlacement<'a, Element, Window> {
impl<'a, Element: Clone, Window: Clone> Clone for AutoPlacement<'a, Element, Window> {
fn clone(&self) -> Self {
Self {
options: self.options.clone(),
}
}
}

impl<'a, Element, Window> AutoPlacement<'a, Element, Window> {
impl<'a, Element: Clone, Window: Clone> AutoPlacement<'a, Element, Window> {
/// Constructs a new instance of this middleware.
pub fn new(options: AutoPlacementOptions<'a, Element>) -> Self {
pub fn new(options: AutoPlacementOptions<Element>) -> Self {
AutoPlacement {
options: options.into(),
}
}

/// Constructs a new instance of this middleware with derivable options.
pub fn new_derivable(
options: DerivableFn<'a, Element, Window, AutoPlacementOptions<'a, Element>>,
options: DerivableFn<'a, Element, Window, AutoPlacementOptions<Element>>,
) -> Self {
AutoPlacement {
options: options.into(),
}
}
}

impl<'a, Element, Window> Middleware<Element, Window> for AutoPlacement<'a, Element, Window> {
impl<'a, Element: Clone, Window: Clone> Middleware<Element, Window>
for AutoPlacement<'a, Element, Window>
{
fn name(&self) -> &'static str {
AUTO_PLACEMENT_NAME
}
Expand Down Expand Up @@ -333,10 +323,11 @@ impl<'a, Element, Window> Middleware<Element, Window> for AutoPlacement<'a, Elem
}
}

impl<'a, Element, Window> MiddlewareWithOptions<Element, Window, AutoPlacementOptions<'a, Element>>
impl<'a, Element: Clone, Window: Clone>
MiddlewareWithOptions<Element, Window, AutoPlacementOptions<Element>>
for AutoPlacement<'a, Element, Window>
{
fn options(&self) -> &Derivable<Element, Window, AutoPlacementOptions<'a, Element>> {
fn options(&self) -> &Derivable<Element, Window, AutoPlacementOptions<Element>> {
&self.options
}
}
Expand Down
42 changes: 13 additions & 29 deletions packages/core/src/middleware/flip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ pub enum FallbackStrategy {
}

/// Options for [`Flip`] middleware.
#[derive(Debug)]
pub struct FlipOptions<'a, Element> {
#[derive(Clone, Debug)]
pub struct FlipOptions<Element: Clone> {
/// Options for [`detect_overflow`].
///
/// Defaults to [`DetectOverflowOptions::default`].
pub detect_overflow: Option<DetectOverflowOptions<'a, Element>>,
pub detect_overflow: Option<DetectOverflowOptions<Element>>,

/// The axis that runs along the side of the floating element. Determines whether overflow along this axis is checked to perform a flip.
///
Expand Down Expand Up @@ -63,21 +63,7 @@ pub struct FlipOptions<'a, Element> {
pub flip_alignment: Option<bool>,
}

impl<'a, Element> Clone for FlipOptions<'a, Element> {
fn clone(&self) -> Self {
Self {
detect_overflow: self.detect_overflow.clone(),
main_axis: self.main_axis,
cross_axis: self.cross_axis,
fallback_placements: self.fallback_placements.clone(),
fallback_strategy: self.fallback_strategy,
fallback_axis_side_direction: self.fallback_axis_side_direction,
flip_alignment: self.flip_alignment,
}
}
}

impl<'a, Element> Default for FlipOptions<'a, Element> {
impl<Element: Clone> Default for FlipOptions<Element> {
fn default() -> Self {
Self {
detect_overflow: Default::default(),
Expand Down Expand Up @@ -109,37 +95,35 @@ pub struct FlipData {
/// Alternative to [`AutoPlacement`][`crate::middleware::AutoPlacement`].
///
/// See <https://floating-ui.com/docs/flip> for the original documentation.
pub struct Flip<'a, Element, Window> {
options: Derivable<'a, Element, Window, FlipOptions<'a, Element>>,
pub struct Flip<'a, Element: Clone, Window: Clone> {
options: Derivable<'a, Element, Window, FlipOptions<Element>>,
}

impl<'a, Element, Window> Flip<'a, Element, Window> {
impl<'a, Element: Clone, Window: Clone> Flip<'a, Element, Window> {
/// Constructs a new instance of this middleware.
pub fn new(options: FlipOptions<'a, Element>) -> Self {
pub fn new(options: FlipOptions<Element>) -> Self {
Flip {
options: options.into(),
}
}

/// Constructs a new instance of this middleware with derivable options.
pub fn new_derivable(
options: DerivableFn<'a, Element, Window, FlipOptions<'a, Element>>,
) -> Self {
pub fn new_derivable(options: DerivableFn<'a, Element, Window, FlipOptions<Element>>) -> Self {
Flip {
options: options.into(),
}
}
}

impl<'a, Element, Window> Clone for Flip<'a, Element, Window> {
impl<'a, Element: Clone, Window: Clone> Clone for Flip<'a, Element, Window> {
fn clone(&self) -> Self {
Self {
options: self.options.clone(),
}
}
}

impl<'a, Element, Window> Middleware<Element, Window> for Flip<'a, Element, Window> {
impl<'a, Element: Clone, Window: Clone> Middleware<Element, Window> for Flip<'a, Element, Window> {
fn name(&self) -> &'static str {
FLIP_NAME
}
Expand Down Expand Up @@ -313,10 +297,10 @@ impl<'a, Element, Window> Middleware<Element, Window> for Flip<'a, Element, Wind
}
}

impl<'a, Element, Window> MiddlewareWithOptions<Element, Window, FlipOptions<'a, Element>>
impl<'a, Element: Clone, Window: Clone> MiddlewareWithOptions<Element, Window, FlipOptions<Element>>
for Flip<'a, Element, Window>
{
fn options(&self) -> &Derivable<Element, Window, FlipOptions<'a, Element>> {
fn options(&self) -> &Derivable<Element, Window, FlipOptions<Element>> {
&self.options
}
}
12 changes: 7 additions & 5 deletions packages/core/src/middleware/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ pub struct OffsetData {
/// Modifies the placement by translating the floating element along the specified axes.
///
/// See <https://floating-ui.com/docs/offset> for the original documentation.
pub struct Offset<'a, Element, Window> {
pub struct Offset<'a, Element: Clone, Window: Clone> {
options: Derivable<'a, Element, Window, OffsetOptions>,
}

impl<'a, Element, Window> Offset<'a, Element, Window> {
impl<'a, Element: Clone, Window: Clone> Offset<'a, Element, Window> {
/// Constructs a new instance of this middleware.
pub fn new(options: OffsetOptions) -> Self {
Offset {
Expand All @@ -135,15 +135,17 @@ impl<'a, Element, Window> Offset<'a, Element, Window> {
}
}

impl<'a, Element, Window> Clone for Offset<'a, Element, Window> {
impl<'a, Element: Clone, Window: Clone> Clone for Offset<'a, Element, Window> {
fn clone(&self) -> Self {
Self {
options: self.options.clone(),
}
}
}

impl<'a, Element, Window> Middleware<Element, Window> for Offset<'a, Element, Window> {
impl<'a, Element: Clone, Window: Clone> Middleware<Element, Window>
for Offset<'a, Element, Window>
{
fn name(&self) -> &'static str {
OFFSET_NAME
}
Expand Down Expand Up @@ -196,7 +198,7 @@ impl<'a, Element, Window> Middleware<Element, Window> for Offset<'a, Element, Wi
}
}

impl<'a, Element, Window> MiddlewareWithOptions<Element, Window, OffsetOptions>
impl<'a, Element: Clone, Window: Clone> MiddlewareWithOptions<Element, Window, OffsetOptions>
for Offset<'a, Element, Window>
{
fn options(&self) -> &Derivable<Element, Window, OffsetOptions> {
Expand Down
Loading

0 comments on commit 565b174

Please sign in to comment.