Kaynağa Gözat

ref!: remove insertAfter

Sv443 11 ay önce
ebeveyn
işleme
fadebf0
4 değiştirilmiş dosya ile 6 ekleme ve 39 silme
  1. 6 0
      .changeset/witty-clocks-fry.md
  2. 0 1
      README-summary.md
  3. 0 29
      README.md
  4. 0 9
      lib/dom.ts

+ 6 - 0
.changeset/witty-clocks-fry.md

@@ -0,0 +1,6 @@
+---
+"@sv443-network/userutils": major
+---
+
+Removed the function `insertAfter()` because the DOM API already has the method [`insertAdjacentElement()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentElement) that has the same functionality and even four positions to pick from.  
+To get the same behavior as `insertAfter(refElem, newElem)`, you can use `refElem.insertAdjacentElement("afterend", newElem)`

+ 0 - 1
README-summary.md

@@ -27,7 +27,6 @@ or view the documentation of previous major releases:
 - DOM:
     - [SelectorObserver](https://github.com/Sv443-Network/UserUtils#selectorobserver) - class that manages listeners that are called when selectors are found in the DOM
     - [getUnsafeWindow()](https://github.com/Sv443-Network/UserUtils#getunsafewindow) - get the unsafeWindow object or fall back to the regular window object
-    - [insertAfter()](https://github.com/Sv443-Network/UserUtils#insertafter) - insert an element as a sibling after another element
     - [addParent()](https://github.com/Sv443-Network/UserUtils#addparent) - add a parent element around another element
     - [addGlobalStyle()](https://github.com/Sv443-Network/UserUtils#addglobalstyle) - add a global style to the page
     - [preloadImages()](https://github.com/Sv443-Network/UserUtils#preloadimages) - preload images into the browser cache for faster loading later on

+ 0 - 29
README.md

@@ -28,7 +28,6 @@ View the documentation of previous major releases:
   - [**DOM:**](#dom)
     - [SelectorObserver](#selectorobserver) - class that manages listeners that are called when selectors are found in the DOM
     - [getUnsafeWindow()](#getunsafewindow) - get the unsafeWindow object or fall back to the regular window object
-    - [insertAfter()](#insertafter) - insert an element as a sibling after another element
     - [addParent()](#addparent) - add a parent element around another element
     - [addGlobalStyle()](#addglobalstyle) - add a global style to the page
     - [preloadImages()](#preloadimages) - preload images into the browser cache for faster loading later on
@@ -463,34 +462,6 @@ document.body.dispatchEvent(mouseEvent);
 
 <br>
 
-### insertAfter()
-Usage:  
-```ts
-insertAfter(beforeElement: Element, afterElement: Element): Element
-```
-  
-Inserts the element passed as `afterElement` as a sibling after the passed `beforeElement`.  
-The passed `afterElement` will be returned.  
-  
-⚠️ This function needs to be run after the DOM has loaded (when using `@run-at document-end` or after `DOMContentLoaded` has fired).  
-  
-<details><summary><b>Example - click to view</b></summary>
-
-```ts
-import { insertAfter } from "@sv443-network/userutils";
-
-// insert a <div> as a sibling next to an element
-const beforeElement = document.querySelector("#before");
-const afterElement = document.createElement("div");
-afterElement.innerText = "After";
-
-insertAfter(beforeElement, afterElement);
-```
-
-</details>
-
-<br>
-
 ### addParent()
 Usage:  
 ```ts

+ 0 - 9
lib/dom.ts

@@ -11,15 +11,6 @@ export function getUnsafeWindow() {
   }
 }
 
-/**
- * Inserts {@linkcode afterElement} as a sibling just after the provided {@linkcode beforeElement}
- * @returns Returns the {@linkcode afterElement}
- */
-export function insertAfter(beforeElement: Element, afterElement: Element) {
-  beforeElement.parentNode?.insertBefore(afterElement, beforeElement.nextSibling);
-  return afterElement;
-}
-
 /**
  * Adds a parent container around the provided element
  * @returns Returns the new parent element