@medyll/idae-be 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/be.d.ts +1 -0
- package/dist/be.js +1 -0
- package/dist/modules/dom.d.ts +12 -1
- package/dist/modules/dom.js +32 -0
- package/package.json +1 -1
package/dist/be.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ export declare class Be {
|
|
|
52
52
|
clear: DomHandler['clear'];
|
|
53
53
|
normalize: DomHandler['normalize'];
|
|
54
54
|
wrap: DomHandler['wrap'];
|
|
55
|
+
unwrap: DomHandler['unwrap'];
|
|
55
56
|
text: (actions: TextHandlerHandle) => Be;
|
|
56
57
|
private textHandler;
|
|
57
58
|
appendText: TextHandler['append'];
|
package/dist/be.js
CHANGED
package/dist/modules/dom.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ declare enum domMethods {
|
|
|
13
13
|
wrap = "wrap",
|
|
14
14
|
normalize = "normalize",
|
|
15
15
|
replace = "replace",
|
|
16
|
-
clear = "clear"
|
|
16
|
+
clear = "clear",
|
|
17
|
+
unwrap = "unwrap"
|
|
17
18
|
}
|
|
18
19
|
type Content = string | HTMLElement | Be;
|
|
19
20
|
export interface DomHandlerHandle {
|
|
@@ -203,6 +204,16 @@ export declare class DomHandler implements DomHandlerInterface, CommonHandler<Do
|
|
|
203
204
|
* beInstance.wrap('section'); // Wraps the div with a <section> element
|
|
204
205
|
*/
|
|
205
206
|
wrap(tag?: string, callback?: HandlerCallBackFn): Be;
|
|
207
|
+
/**
|
|
208
|
+
* Removes the parent element of the selected element(s), keeping the selected element(s) in the DOM.
|
|
209
|
+
* @param callback - Optional callback function to execute after unwrapping.
|
|
210
|
+
* @returns The Be instance for method chaining.
|
|
211
|
+
* @example
|
|
212
|
+
* // HTML: <div id="wrapper"><span id="child">Content</span></div>
|
|
213
|
+
* const beInstance = be('#child');
|
|
214
|
+
* beInstance.unwrap(); // Removes the <div id="wrapper">, keeping <span id="child">
|
|
215
|
+
*/
|
|
216
|
+
unwrap(callback?: HandlerCallBackFn): Be;
|
|
206
217
|
private adjacentElement;
|
|
207
218
|
private normalizeContent;
|
|
208
219
|
private insertContent;
|
package/dist/modules/dom.js
CHANGED
|
@@ -14,6 +14,7 @@ var domMethods;
|
|
|
14
14
|
domMethods["normalize"] = "normalize";
|
|
15
15
|
domMethods["replace"] = "replace";
|
|
16
16
|
domMethods["clear"] = "clear";
|
|
17
|
+
domMethods["unwrap"] = "unwrap";
|
|
17
18
|
})(domMethods || (domMethods = {}));
|
|
18
19
|
/**
|
|
19
20
|
* Handles DOM manipulation operations for Be elements.
|
|
@@ -63,6 +64,9 @@ export class DomHandler {
|
|
|
63
64
|
case 'wrap':
|
|
64
65
|
this.wrap(props.tag, props.callback);
|
|
65
66
|
break;
|
|
67
|
+
case 'unwrap':
|
|
68
|
+
this.unwrap(props.callback);
|
|
69
|
+
break;
|
|
66
70
|
}
|
|
67
71
|
});
|
|
68
72
|
return this.beElement;
|
|
@@ -350,6 +354,34 @@ export class DomHandler {
|
|
|
350
354
|
});
|
|
351
355
|
return this.beElement;
|
|
352
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* Removes the parent element of the selected element(s), keeping the selected element(s) in the DOM.
|
|
359
|
+
* @param callback - Optional callback function to execute after unwrapping.
|
|
360
|
+
* @returns The Be instance for method chaining.
|
|
361
|
+
* @example
|
|
362
|
+
* // HTML: <div id="wrapper"><span id="child">Content</span></div>
|
|
363
|
+
* const beInstance = be('#child');
|
|
364
|
+
* beInstance.unwrap(); // Removes the <div id="wrapper">, keeping <span id="child">
|
|
365
|
+
*/
|
|
366
|
+
unwrap(callback) {
|
|
367
|
+
this.beElement.eachNode((el) => {
|
|
368
|
+
const parent = el.parentElement;
|
|
369
|
+
if (parent) {
|
|
370
|
+
// Move the element itself before the parent
|
|
371
|
+
while (el.firstChild) {
|
|
372
|
+
parent.insertBefore(el.firstChild, el);
|
|
373
|
+
}
|
|
374
|
+
// Remove the parent after moving its children
|
|
375
|
+
parent.replaceWith(...Array.from(parent.childNodes));
|
|
376
|
+
}
|
|
377
|
+
callback?.({
|
|
378
|
+
fragment: undefined,
|
|
379
|
+
be: be(el),
|
|
380
|
+
root: this.beElement
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
return this.beElement;
|
|
384
|
+
}
|
|
353
385
|
adjacentElement(element, content, mode) {
|
|
354
386
|
const normalizedContent = this.normalizeContent(content);
|
|
355
387
|
if (typeof content === 'string') {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medyll/idae-be",
|
|
3
3
|
"scope": "@medyll",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.12.0",
|
|
5
5
|
"description": "A modern, lightweight, and extensible DOM manipulation library built with TypeScript. Designed for precise element targeting and manipulation using a callback-based approach. Features include advanced DOM traversal, event handling, style management, attribute control, HTTP content loading, timers, and more. Ideal for developers seeking a modular and consistent API for dynamic web applications.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"DOM",
|