Skip to content

Commit fadebf0

Browse files
committed
ref!: remove insertAfter
1 parent be194cb commit fadebf0

File tree

4 files changed

+6
-39
lines changed

4 files changed

+6
-39
lines changed

.changeset/witty-clocks-fry.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@sv443-network/userutils": major
3+
---
4+
5+
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.
6+
To get the same behavior as `insertAfter(refElem, newElem)`, you can use `refElem.insertAdjacentElement("afterend", newElem)`

README-summary.md

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

README.md

-29
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ View the documentation of previous major releases:
2828
- [**DOM:**](#dom)
2929
- [SelectorObserver](#selectorobserver) - class that manages listeners that are called when selectors are found in the DOM
3030
- [getUnsafeWindow()](#getunsafewindow) - get the unsafeWindow object or fall back to the regular window object
31-
- [insertAfter()](#insertafter) - insert an element as a sibling after another element
3231
- [addParent()](#addparent) - add a parent element around another element
3332
- [addGlobalStyle()](#addglobalstyle) - add a global style to the page
3433
- [preloadImages()](#preloadimages) - preload images into the browser cache for faster loading later on
@@ -463,34 +462,6 @@ document.body.dispatchEvent(mouseEvent);
463462

464463
<br>
465464

466-
### insertAfter()
467-
Usage:
468-
```ts
469-
insertAfter(beforeElement: Element, afterElement: Element): Element
470-
```
471-
472-
Inserts the element passed as `afterElement` as a sibling after the passed `beforeElement`.
473-
The passed `afterElement` will be returned.
474-
475-
⚠️ This function needs to be run after the DOM has loaded (when using `@run-at document-end` or after `DOMContentLoaded` has fired).
476-
477-
<details><summary><b>Example - click to view</b></summary>
478-
479-
```ts
480-
import { insertAfter } from "@sv443-network/userutils";
481-
482-
// insert a <div> as a sibling next to an element
483-
const beforeElement = document.querySelector("#before");
484-
const afterElement = document.createElement("div");
485-
afterElement.innerText = "After";
486-
487-
insertAfter(beforeElement, afterElement);
488-
```
489-
490-
</details>
491-
492-
<br>
493-
494465
### addParent()
495466
Usage:
496467
```ts

lib/dom.ts

-9
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@ export function getUnsafeWindow() {
1111
}
1212
}
1313

14-
/**
15-
* Inserts {@linkcode afterElement} as a sibling just after the provided {@linkcode beforeElement}
16-
* @returns Returns the {@linkcode afterElement}
17-
*/
18-
export function insertAfter(beforeElement: Element, afterElement: Element) {
19-
beforeElement.parentNode?.insertBefore(afterElement, beforeElement.nextSibling);
20-
return afterElement;
21-
}
22-
2314
/**
2415
* Adds a parent container around the provided element
2516
* @returns Returns the new parent element

0 commit comments

Comments
 (0)