@medyll/idae-be 0.85.0 → 0.87.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 +6 -10
- package/dist/be.js +13 -18
- package/dist/modules/attrs.d.ts +52 -0
- package/dist/modules/attrs.js +52 -7
- package/dist/modules/classes.d.ts +31 -5
- package/dist/modules/classes.js +31 -5
- package/dist/modules/data.d.ts +25 -0
- package/dist/modules/data.js +25 -0
- package/dist/modules/dom.d.ts +107 -0
- package/dist/modules/dom.js +107 -0
- package/dist/modules/events.d.ts +38 -0
- package/dist/modules/events.js +38 -0
- package/dist/modules/position.d.ts +34 -15
- package/dist/modules/position.js +34 -16
- package/dist/modules/styles.d.ts +25 -6
- package/dist/modules/styles.js +25 -7
- package/dist/modules/text.d.ts +77 -0
- package/dist/modules/text.js +77 -0
- package/dist/modules/timers.d.ts +41 -1
- package/dist/modules/timers.js +40 -0
- package/dist/modules/walk.d.ts +24 -0
- package/dist/modules/walk.js +24 -0
- package/package.json +1 -1
package/dist/be.d.ts
CHANGED
|
@@ -6,10 +6,11 @@ import { EventsHandler, type EventHandlerHandle } from './modules/events.js';
|
|
|
6
6
|
import { type ClassHandlerHandler, ClassesHandler } from './modules/classes.js';
|
|
7
7
|
import { DomHandler, type DomHandlerHandle } from './modules/dom.js';
|
|
8
8
|
import { PositionHandler, type PositionHandlerHandle } from './modules/position.js';
|
|
9
|
-
import { WalkHandler } from './modules/walk.js';
|
|
9
|
+
import { WalkHandler, type WalkHandlerHandle } from './modules/walk.js';
|
|
10
10
|
import { TextHandler, type TextHandlerHandle } from './modules/text.js';
|
|
11
|
-
import { TimersHandler } from './modules/timers.js';
|
|
11
|
+
import { TimersHandler, type TimerHandlerHandle } from './modules/timers.js';
|
|
12
12
|
export declare class Be {
|
|
13
|
+
[key: string]: unknown;
|
|
13
14
|
inputNode: HTMLElement | HTMLElement[] | string;
|
|
14
15
|
isWhat: IsWhat;
|
|
15
16
|
timerOut: NodeJS.Timeout | null;
|
|
@@ -71,7 +72,7 @@ export declare class Be {
|
|
|
71
72
|
removeClass: ClassesHandler['remove'];
|
|
72
73
|
toggleClass: ClassesHandler['toggle'];
|
|
73
74
|
replaceClass: ClassesHandler['replace'];
|
|
74
|
-
walk: (actions:
|
|
75
|
+
walk: (actions: WalkHandlerHandle) => Be;
|
|
75
76
|
private walkHandler;
|
|
76
77
|
up: WalkHandler['up'];
|
|
77
78
|
next: WalkHandler['next'];
|
|
@@ -84,7 +85,7 @@ export declare class Be {
|
|
|
84
85
|
firstChild: WalkHandler['firstChild'];
|
|
85
86
|
find: WalkHandler['find'];
|
|
86
87
|
findAll: WalkHandler['findAll'];
|
|
87
|
-
timers: (actions:
|
|
88
|
+
timers: (actions: TimerHandlerHandle) => Be;
|
|
88
89
|
private timerHandler;
|
|
89
90
|
timeout: TimersHandler['timeout'];
|
|
90
91
|
interval: TimersHandler['interval'];
|
|
@@ -123,14 +124,9 @@ export declare class Be {
|
|
|
123
124
|
data?: T;
|
|
124
125
|
headers?: Record<string, string>;
|
|
125
126
|
}): Promise<any>;
|
|
126
|
-
get node(): HTMLElement | HTMLElement[];
|
|
127
127
|
eachNode(callback: (el: HTMLElement) => void, firstChild?: boolean): void;
|
|
128
|
-
/** DOM
|
|
129
|
-
* Handles various DOM operations on the element(s).
|
|
130
|
-
* @param actions An object specifying the DOM actions to perform.
|
|
131
|
-
* @returns The Be instance for method chaining.
|
|
132
|
-
*/
|
|
133
128
|
get html(): string | null;
|
|
129
|
+
get node(): HTMLElement | HTMLElement[];
|
|
134
130
|
private attach;
|
|
135
131
|
private handle;
|
|
136
132
|
}
|
package/dist/be.js
CHANGED
|
@@ -118,11 +118,11 @@ export class Be {
|
|
|
118
118
|
this.attach(StylesHandler, 'Style');
|
|
119
119
|
// dataSet
|
|
120
120
|
this.dataHandler = new DataHandler(this);
|
|
121
|
-
this.data = this.handle(this.
|
|
121
|
+
this.data = this.handle(this.dataHandler);
|
|
122
122
|
this.attach(DataHandler, 'Data');
|
|
123
123
|
// attributes
|
|
124
124
|
this.attrHandler = new AttrHandler(this);
|
|
125
|
-
this.attrs = this.handle(this.
|
|
125
|
+
this.attrs = this.handle(this.attrHandler);
|
|
126
126
|
this.attach(AttrHandler, 'Attr');
|
|
127
127
|
// position
|
|
128
128
|
this.positionHandler = new PositionHandler(this);
|
|
@@ -130,7 +130,7 @@ export class Be {
|
|
|
130
130
|
this.attach(PositionHandler);
|
|
131
131
|
// text
|
|
132
132
|
this.textHandler = new TextHandler(this);
|
|
133
|
-
this.
|
|
133
|
+
this.text = this.handle(this.textHandler);
|
|
134
134
|
this.attach(TextHandler, 'Text');
|
|
135
135
|
// dom and handle
|
|
136
136
|
this.domHandler = new DomHandler(this);
|
|
@@ -263,16 +263,6 @@ export class Be {
|
|
|
263
263
|
headers: options.headers || {}
|
|
264
264
|
}).then((response) => response.json());
|
|
265
265
|
}
|
|
266
|
-
get node() {
|
|
267
|
-
switch (this.isWhat) {
|
|
268
|
-
case 'element':
|
|
269
|
-
return this.inputNode;
|
|
270
|
-
case 'array':
|
|
271
|
-
return Array.from(this.inputNode);
|
|
272
|
-
case 'qy':
|
|
273
|
-
return Array.from(document.querySelectorAll(this.inputNode));
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
266
|
eachNode(callback, firstChild) {
|
|
277
267
|
switch (this.isWhat) {
|
|
278
268
|
case 'element':
|
|
@@ -294,14 +284,19 @@ export class Be {
|
|
|
294
284
|
break;
|
|
295
285
|
}
|
|
296
286
|
}
|
|
297
|
-
/** DOM
|
|
298
|
-
* Handles various DOM operations on the element(s).
|
|
299
|
-
* @param actions An object specifying the DOM actions to perform.
|
|
300
|
-
* @returns The Be instance for method chaining.
|
|
301
|
-
*/
|
|
302
287
|
get html() {
|
|
303
288
|
return this.isWhat === 'element' ? this.inputNode.innerHTML : null;
|
|
304
289
|
}
|
|
290
|
+
get node() {
|
|
291
|
+
switch (this.isWhat) {
|
|
292
|
+
case 'element':
|
|
293
|
+
return this.inputNode;
|
|
294
|
+
case 'array':
|
|
295
|
+
return Array.from(this.inputNode);
|
|
296
|
+
case 'qy':
|
|
297
|
+
return Array.from(document.querySelectorAll(this.inputNode));
|
|
298
|
+
}
|
|
299
|
+
}
|
|
305
300
|
attach(Handler, suffix = '') {
|
|
306
301
|
const fromMethods = Handler.methods || [];
|
|
307
302
|
fromMethods.forEach((method) => {
|
package/dist/modules/attrs.d.ts
CHANGED
|
@@ -10,14 +10,66 @@ export type AttrHandlerHandle = {
|
|
|
10
10
|
get: AttrHandler['get'];
|
|
11
11
|
delete: AttrHandler['delete'];
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Handles attribute operations for Be elements.
|
|
15
|
+
*/
|
|
13
16
|
export declare class AttrHandler implements CommonHandler<AttrHandler, AttrHandler> {
|
|
14
17
|
private beElement;
|
|
15
18
|
static methods: attrMethods[];
|
|
19
|
+
/**
|
|
20
|
+
* Initializes the AttrHandler with a Be element.
|
|
21
|
+
* @param element - The Be element to operate on.
|
|
22
|
+
*/
|
|
16
23
|
constructor(element: Be);
|
|
24
|
+
/**
|
|
25
|
+
* Handles dynamic method calls for attribute operations.
|
|
26
|
+
* @param actions - The actions to perform (e.g., set, get, delete).
|
|
27
|
+
* @returns The Be element for chaining.
|
|
28
|
+
*/
|
|
17
29
|
handle(actions: Partial<AttrHandlerHandle>): Be;
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves the value of an attribute.
|
|
32
|
+
* @param name - The name of the attribute to retrieve.
|
|
33
|
+
* @returns The value of the attribute, or `null` if not found.
|
|
34
|
+
* @example
|
|
35
|
+
* // HTML: <div id="test" data-role="admin"></div>
|
|
36
|
+
* const beInstance = be('#test');
|
|
37
|
+
* const role = beInstance.getAttr('data-role');
|
|
38
|
+
* console.log(role); // Output: "admin"
|
|
39
|
+
*/
|
|
18
40
|
get(name?: string): string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Sets one or more attributes on the element(s).
|
|
43
|
+
* @param nameOrObject - A key-value pair or an object containing multiple key-value pairs.
|
|
44
|
+
* @param value - The value to set if a single key is provided.
|
|
45
|
+
* @returns The Be element for chaining.
|
|
46
|
+
* @example
|
|
47
|
+
* // HTML: <div id="test"></div>
|
|
48
|
+
* const beInstance = be('#test');
|
|
49
|
+
* beInstance.setAttr('data-role', 'admin'); // Sets a single attribute
|
|
50
|
+
* beInstance.setAttr({ class: 'highlight', title: 'Hello' }); // Sets multiple attributes
|
|
51
|
+
*/
|
|
19
52
|
set(nameOrObject: string | Record<string, string>, value?: string): Be;
|
|
53
|
+
/**
|
|
54
|
+
* Deletes one or more attributes from the element(s).
|
|
55
|
+
* @param nameOrObject - A key or an object containing multiple keys to delete.
|
|
56
|
+
* @returns The Be element for chaining.
|
|
57
|
+
* @example
|
|
58
|
+
* // HTML: <div id="test" data-role="admin" class="highlight"></div>
|
|
59
|
+
* const beInstance = be('#test');
|
|
60
|
+
* beInstance.deleteAttr('data-role'); // Deletes a single attribute
|
|
61
|
+
* beInstance.deleteAttr({ class: '' }); // Deletes multiple attributes
|
|
62
|
+
*/
|
|
20
63
|
delete(nameOrObject: string | Record<string, string>): Be;
|
|
64
|
+
/**
|
|
65
|
+
* Retrieves all attributes as a key-value pair object.
|
|
66
|
+
* @returns An object containing all attributes, or `null` if not applicable.
|
|
67
|
+
* @example
|
|
68
|
+
* // HTML: <div id="test" data-role="admin" class="highlight"></div>
|
|
69
|
+
* const beInstance = be('#test');
|
|
70
|
+
* const attributes = beInstance.attrs.valueOf();
|
|
71
|
+
* console.log(attributes); // Output: { id: "test", "data-role": "admin", class: "highlight" }
|
|
72
|
+
*/
|
|
21
73
|
valueOf(): Record<string, string> | null;
|
|
22
74
|
}
|
|
23
75
|
export {};
|
package/dist/modules/attrs.js
CHANGED
|
@@ -5,12 +5,24 @@ var attrMethods;
|
|
|
5
5
|
attrMethods["get"] = "get";
|
|
6
6
|
attrMethods["delete"] = "delete";
|
|
7
7
|
})(attrMethods || (attrMethods = {}));
|
|
8
|
+
/**
|
|
9
|
+
* Handles attribute operations for Be elements.
|
|
10
|
+
*/
|
|
8
11
|
export class AttrHandler {
|
|
9
12
|
beElement;
|
|
10
13
|
static methods = Object.values(attrMethods);
|
|
14
|
+
/**
|
|
15
|
+
* Initializes the AttrHandler with a Be element.
|
|
16
|
+
* @param element - The Be element to operate on.
|
|
17
|
+
*/
|
|
11
18
|
constructor(element) {
|
|
12
19
|
this.beElement = element;
|
|
13
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Handles dynamic method calls for attribute operations.
|
|
23
|
+
* @param actions - The actions to perform (e.g., set, get, delete).
|
|
24
|
+
* @returns The Be element for chaining.
|
|
25
|
+
*/
|
|
14
26
|
handle(actions) {
|
|
15
27
|
Object.entries(actions).forEach(([method, props]) => {
|
|
16
28
|
switch (method) {
|
|
@@ -22,15 +34,18 @@ export class AttrHandler {
|
|
|
22
34
|
break;
|
|
23
35
|
}
|
|
24
36
|
});
|
|
25
|
-
/* this.beElement.eachNode((el) => {
|
|
26
|
-
if (actions.delete) {
|
|
27
|
-
this.delete(actions.delete);
|
|
28
|
-
}
|
|
29
|
-
if (actions.set) {
|
|
30
|
-
}
|
|
31
|
-
}); */
|
|
32
37
|
return this.beElement;
|
|
33
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Retrieves the value of an attribute.
|
|
41
|
+
* @param name - The name of the attribute to retrieve.
|
|
42
|
+
* @returns The value of the attribute, or `null` if not found.
|
|
43
|
+
* @example
|
|
44
|
+
* // HTML: <div id="test" data-role="admin"></div>
|
|
45
|
+
* const beInstance = be('#test');
|
|
46
|
+
* const role = beInstance.getAttr('data-role');
|
|
47
|
+
* console.log(role); // Output: "admin"
|
|
48
|
+
*/
|
|
34
49
|
get(name) {
|
|
35
50
|
if (typeof this.beElement.inputNode === 'string')
|
|
36
51
|
return (document.querySelector(this.beElement.inputNode || '')?.getAttribute(name || '') || null);
|
|
@@ -39,6 +54,17 @@ export class AttrHandler {
|
|
|
39
54
|
const el = this.beElement.inputNode;
|
|
40
55
|
return name ? el.getAttribute(name) : null;
|
|
41
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Sets one or more attributes on the element(s).
|
|
59
|
+
* @param nameOrObject - A key-value pair or an object containing multiple key-value pairs.
|
|
60
|
+
* @param value - The value to set if a single key is provided.
|
|
61
|
+
* @returns The Be element for chaining.
|
|
62
|
+
* @example
|
|
63
|
+
* // HTML: <div id="test"></div>
|
|
64
|
+
* const beInstance = be('#test');
|
|
65
|
+
* beInstance.setAttr('data-role', 'admin'); // Sets a single attribute
|
|
66
|
+
* beInstance.setAttr({ class: 'highlight', title: 'Hello' }); // Sets multiple attributes
|
|
67
|
+
*/
|
|
42
68
|
set(nameOrObject, value) {
|
|
43
69
|
this.beElement.eachNode((el) => {
|
|
44
70
|
if (typeof nameOrObject === 'string' && value !== undefined) {
|
|
@@ -52,6 +78,16 @@ export class AttrHandler {
|
|
|
52
78
|
});
|
|
53
79
|
return this.beElement;
|
|
54
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Deletes one or more attributes from the element(s).
|
|
83
|
+
* @param nameOrObject - A key or an object containing multiple keys to delete.
|
|
84
|
+
* @returns The Be element for chaining.
|
|
85
|
+
* @example
|
|
86
|
+
* // HTML: <div id="test" data-role="admin" class="highlight"></div>
|
|
87
|
+
* const beInstance = be('#test');
|
|
88
|
+
* beInstance.deleteAttr('data-role'); // Deletes a single attribute
|
|
89
|
+
* beInstance.deleteAttr({ class: '' }); // Deletes multiple attributes
|
|
90
|
+
*/
|
|
55
91
|
delete(nameOrObject) {
|
|
56
92
|
this.beElement.eachNode((el) => {
|
|
57
93
|
if (typeof nameOrObject === 'string') {
|
|
@@ -65,6 +101,15 @@ export class AttrHandler {
|
|
|
65
101
|
});
|
|
66
102
|
return this.beElement;
|
|
67
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Retrieves all attributes as a key-value pair object.
|
|
106
|
+
* @returns An object containing all attributes, or `null` if not applicable.
|
|
107
|
+
* @example
|
|
108
|
+
* // HTML: <div id="test" data-role="admin" class="highlight"></div>
|
|
109
|
+
* const beInstance = be('#test');
|
|
110
|
+
* const attributes = beInstance.attrs.valueOf();
|
|
111
|
+
* console.log(attributes); // Output: { id: "test", "data-role": "admin", class: "highlight" }
|
|
112
|
+
*/
|
|
68
113
|
valueOf() {
|
|
69
114
|
if (this.beElement.isWhat !== 'element')
|
|
70
115
|
return null;
|
|
@@ -35,22 +35,48 @@ export declare class ClassesHandler implements CommonHandler<ClassesHandler, Cla
|
|
|
35
35
|
methods: string[] | keyof ClassesHandler;
|
|
36
36
|
valueOf(): string;
|
|
37
37
|
handle(actions: ClassHandlerHandlerHandle): Be;
|
|
38
|
+
/**
|
|
39
|
+
* Adds one or more classes to the element(s).
|
|
40
|
+
* @param className - The class or classes to add.
|
|
41
|
+
* @returns The Be instance for method chaining.
|
|
42
|
+
* @example
|
|
43
|
+
* // HTML: <div id="test"></div>
|
|
44
|
+
* const beInstance = be('#test');
|
|
45
|
+
* beInstance.addClass('highlight'); // Adds a single class
|
|
46
|
+
* beInstance.addClass(['highlight', 'active']); // Adds multiple classes
|
|
47
|
+
*/
|
|
38
48
|
add(className: string | string[]): Be;
|
|
39
49
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @param className The class to toggle.
|
|
50
|
+
* Toggles a class on the element(s).
|
|
51
|
+
* @param className - The class or classes to toggle.
|
|
42
52
|
* @returns The Be instance for method chaining.
|
|
53
|
+
* @example
|
|
54
|
+
* // HTML: <div id="test" class="highlight"></div>
|
|
55
|
+
* const beInstance = be('#test');
|
|
56
|
+
* beInstance.toggleClass('highlight'); // Removes the "highlight" class
|
|
57
|
+
* beInstance.toggleClass('active'); // Adds the "active" class
|
|
43
58
|
*/
|
|
44
59
|
toggle(className: string | string[]): Be;
|
|
45
60
|
/**
|
|
46
|
-
*
|
|
61
|
+
* Replaces a class on the element(s) with another class.
|
|
62
|
+
* @param sourceClassName - The class to replace.
|
|
63
|
+
* @param targetClassName - The class to replace it with.
|
|
47
64
|
* @returns The Be instance for method chaining.
|
|
65
|
+
* @example
|
|
66
|
+
* // HTML: <div id="test" class="old-class"></div>
|
|
67
|
+
* const beInstance = be('#test');
|
|
68
|
+
* beInstance.replaceClass('old-class', 'new-class'); // Replaces "old-class" with "new-class"
|
|
48
69
|
*/
|
|
49
70
|
replace(sourceClassName: string, targetClassName: string): Be;
|
|
50
71
|
/**
|
|
51
|
-
*
|
|
52
|
-
* @param className The class to remove.
|
|
72
|
+
* Removes one or more classes from the element(s).
|
|
73
|
+
* @param className - The class or classes to remove.
|
|
53
74
|
* @returns The Be instance for method chaining.
|
|
75
|
+
* @example
|
|
76
|
+
* // HTML: <div id="test" class="highlight active"></div>
|
|
77
|
+
* const beInstance = be('#test');
|
|
78
|
+
* beInstance.removeClass('highlight'); // Removes the "highlight" class
|
|
79
|
+
* beInstance.removeClass(['highlight', 'active']); // Removes multiple classes
|
|
54
80
|
*/
|
|
55
81
|
remove(className: string | string[]): Be;
|
|
56
82
|
}
|
package/dist/modules/classes.js
CHANGED
|
@@ -31,15 +31,30 @@ export class ClassesHandler {
|
|
|
31
31
|
});
|
|
32
32
|
return this.beElement;
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Adds one or more classes to the element(s).
|
|
36
|
+
* @param className - The class or classes to add.
|
|
37
|
+
* @returns The Be instance for method chaining.
|
|
38
|
+
* @example
|
|
39
|
+
* // HTML: <div id="test"></div>
|
|
40
|
+
* const beInstance = be('#test');
|
|
41
|
+
* beInstance.addClass('highlight'); // Adds a single class
|
|
42
|
+
* beInstance.addClass(['highlight', 'active']); // Adds multiple classes
|
|
43
|
+
*/
|
|
34
44
|
add(className) {
|
|
35
45
|
const classesToAdd = Array.isArray(className) ? className : className.split(' ');
|
|
36
46
|
this.beElement.eachNode((el) => el.classList.add(...classesToAdd.filter((c) => c.trim() !== '')));
|
|
37
47
|
return this.beElement;
|
|
38
48
|
}
|
|
39
49
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @param className The class to toggle.
|
|
50
|
+
* Toggles a class on the element(s).
|
|
51
|
+
* @param className - The class or classes to toggle.
|
|
42
52
|
* @returns The Be instance for method chaining.
|
|
53
|
+
* @example
|
|
54
|
+
* // HTML: <div id="test" class="highlight"></div>
|
|
55
|
+
* const beInstance = be('#test');
|
|
56
|
+
* beInstance.toggleClass('highlight'); // Removes the "highlight" class
|
|
57
|
+
* beInstance.toggleClass('active'); // Adds the "active" class
|
|
43
58
|
*/
|
|
44
59
|
toggle(className) {
|
|
45
60
|
const classesToToggle = Array.isArray(className) ? className : className.split(' ');
|
|
@@ -49,17 +64,28 @@ export class ClassesHandler {
|
|
|
49
64
|
return this.beElement;
|
|
50
65
|
}
|
|
51
66
|
/**
|
|
52
|
-
*
|
|
67
|
+
* Replaces a class on the element(s) with another class.
|
|
68
|
+
* @param sourceClassName - The class to replace.
|
|
69
|
+
* @param targetClassName - The class to replace it with.
|
|
53
70
|
* @returns The Be instance for method chaining.
|
|
71
|
+
* @example
|
|
72
|
+
* // HTML: <div id="test" class="old-class"></div>
|
|
73
|
+
* const beInstance = be('#test');
|
|
74
|
+
* beInstance.replaceClass('old-class', 'new-class'); // Replaces "old-class" with "new-class"
|
|
54
75
|
*/
|
|
55
76
|
replace(sourceClassName, targetClassName) {
|
|
56
77
|
this.beElement.eachNode((el) => el.classList.replace(sourceClassName, targetClassName));
|
|
57
78
|
return this.beElement;
|
|
58
79
|
}
|
|
59
80
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @param className The class to remove.
|
|
81
|
+
* Removes one or more classes from the element(s).
|
|
82
|
+
* @param className - The class or classes to remove.
|
|
62
83
|
* @returns The Be instance for method chaining.
|
|
84
|
+
* @example
|
|
85
|
+
* // HTML: <div id="test" class="highlight active"></div>
|
|
86
|
+
* const beInstance = be('#test');
|
|
87
|
+
* beInstance.removeClass('highlight'); // Removes the "highlight" class
|
|
88
|
+
* beInstance.removeClass(['highlight', 'active']); // Removes multiple classes
|
|
63
89
|
*/
|
|
64
90
|
remove(className) {
|
|
65
91
|
const classesToRemove = Array.isArray(className) ? className : className.split(' ');
|
package/dist/modules/data.d.ts
CHANGED
|
@@ -37,6 +37,11 @@ export declare class DataHandler implements CommonHandler<DataHandler> {
|
|
|
37
37
|
* Retrieves the value of a `data-*` attribute.
|
|
38
38
|
* @param key - The key of the `data-*` attribute to retrieve.
|
|
39
39
|
* @returns The value of the attribute, or `null` if not found.
|
|
40
|
+
* @example
|
|
41
|
+
* // HTML: <div id="test" data-role="admin"></div>
|
|
42
|
+
* const beInstance = be('#test');
|
|
43
|
+
* const role = beInstance.getData('role');
|
|
44
|
+
* console.log(role); // Output: "admin"
|
|
40
45
|
*/
|
|
41
46
|
get(key: string): string | null;
|
|
42
47
|
/**
|
|
@@ -44,23 +49,43 @@ export declare class DataHandler implements CommonHandler<DataHandler> {
|
|
|
44
49
|
* @param keyOrObject - A key-value pair or an object containing multiple key-value pairs.
|
|
45
50
|
* @param value - The value to set if a single key is provided.
|
|
46
51
|
* @returns The Be element for chaining.
|
|
52
|
+
* @example
|
|
53
|
+
* // HTML: <div id="test"></div>
|
|
54
|
+
* const beInstance = be('#test');
|
|
55
|
+
* beInstance.setData('role', 'admin'); // Sets a single `data-role` attribute
|
|
56
|
+
* beInstance.setData({ role: 'admin', type: 'user' }); // Sets multiple `data-*` attributes
|
|
47
57
|
*/
|
|
48
58
|
set(keyOrObject: string | Record<string, string>, value?: string): Be;
|
|
49
59
|
/**
|
|
50
60
|
* Deletes one or more `data-*` attributes.
|
|
51
61
|
* @param keyOrObject - A key or an object containing multiple keys to delete.
|
|
52
62
|
* @returns The Be element for chaining.
|
|
63
|
+
* @example
|
|
64
|
+
* // HTML: <div id="test" data-role="admin" data-type="user"></div>
|
|
65
|
+
* const beInstance = be('#test');
|
|
66
|
+
* beInstance.deleteData('role'); // Deletes the `data-role` attribute
|
|
67
|
+
* beInstance.deleteData({ type: '' }); // Deletes the `data-type` attribute
|
|
53
68
|
*/
|
|
54
69
|
delete(keyOrObject: string | Record<string, string>): Be;
|
|
55
70
|
/**
|
|
56
71
|
* Retrieves the value of a specific `data-*` attribute.
|
|
57
72
|
* @param key - The key of the `data-*` attribute to retrieve.
|
|
58
73
|
* @returns The value of the attribute, or `null` if not found.
|
|
74
|
+
* @example
|
|
75
|
+
* // HTML: <div id="test" data-role="admin"></div>
|
|
76
|
+
* const beInstance = be('#test');
|
|
77
|
+
* const role = beInstance.getKey('role');
|
|
78
|
+
* console.log(role); // Output: "admin"
|
|
59
79
|
*/
|
|
60
80
|
getKey(key: string | string[]): string | null;
|
|
61
81
|
/**
|
|
62
82
|
* Retrieves all `data-*` attributes as a DOMStringMap.
|
|
63
83
|
* @returns A DOMStringMap containing all `data-*` attributes, or `null` if not applicable.
|
|
84
|
+
* @example
|
|
85
|
+
* // HTML: <div id="test" data-role="admin" data-type="user"></div>
|
|
86
|
+
* const beInstance = be('#test');
|
|
87
|
+
* const dataAttributes = beInstance.data.valueOf();
|
|
88
|
+
* console.log(dataAttributes); // Output: { role: "admin", type: "user" }
|
|
64
89
|
*/
|
|
65
90
|
valueOf(): DOMStringMap | null;
|
|
66
91
|
}
|
package/dist/modules/data.js
CHANGED
|
@@ -40,6 +40,11 @@ export class DataHandler {
|
|
|
40
40
|
* Retrieves the value of a `data-*` attribute.
|
|
41
41
|
* @param key - The key of the `data-*` attribute to retrieve.
|
|
42
42
|
* @returns The value of the attribute, or `null` if not found.
|
|
43
|
+
* @example
|
|
44
|
+
* // HTML: <div id="test" data-role="admin"></div>
|
|
45
|
+
* const beInstance = be('#test');
|
|
46
|
+
* const role = beInstance.getData('role');
|
|
47
|
+
* console.log(role); // Output: "admin"
|
|
43
48
|
*/
|
|
44
49
|
get(key) {
|
|
45
50
|
if (this.beElement.isWhat !== 'element')
|
|
@@ -51,6 +56,11 @@ export class DataHandler {
|
|
|
51
56
|
* @param keyOrObject - A key-value pair or an object containing multiple key-value pairs.
|
|
52
57
|
* @param value - The value to set if a single key is provided.
|
|
53
58
|
* @returns The Be element for chaining.
|
|
59
|
+
* @example
|
|
60
|
+
* // HTML: <div id="test"></div>
|
|
61
|
+
* const beInstance = be('#test');
|
|
62
|
+
* beInstance.setData('role', 'admin'); // Sets a single `data-role` attribute
|
|
63
|
+
* beInstance.setData({ role: 'admin', type: 'user' }); // Sets multiple `data-*` attributes
|
|
54
64
|
*/
|
|
55
65
|
set(keyOrObject, value) {
|
|
56
66
|
this.beElement.eachNode((el) => {
|
|
@@ -69,6 +79,11 @@ export class DataHandler {
|
|
|
69
79
|
* Deletes one or more `data-*` attributes.
|
|
70
80
|
* @param keyOrObject - A key or an object containing multiple keys to delete.
|
|
71
81
|
* @returns The Be element for chaining.
|
|
82
|
+
* @example
|
|
83
|
+
* // HTML: <div id="test" data-role="admin" data-type="user"></div>
|
|
84
|
+
* const beInstance = be('#test');
|
|
85
|
+
* beInstance.deleteData('role'); // Deletes the `data-role` attribute
|
|
86
|
+
* beInstance.deleteData({ type: '' }); // Deletes the `data-type` attribute
|
|
72
87
|
*/
|
|
73
88
|
delete(keyOrObject) {
|
|
74
89
|
this.beElement.eachNode((el) => {
|
|
@@ -89,6 +104,11 @@ export class DataHandler {
|
|
|
89
104
|
* Retrieves the value of a specific `data-*` attribute.
|
|
90
105
|
* @param key - The key of the `data-*` attribute to retrieve.
|
|
91
106
|
* @returns The value of the attribute, or `null` if not found.
|
|
107
|
+
* @example
|
|
108
|
+
* // HTML: <div id="test" data-role="admin"></div>
|
|
109
|
+
* const beInstance = be('#test');
|
|
110
|
+
* const role = beInstance.getKey('role');
|
|
111
|
+
* console.log(role); // Output: "admin"
|
|
92
112
|
*/
|
|
93
113
|
getKey(key) {
|
|
94
114
|
if (this.beElement.isWhat !== 'element')
|
|
@@ -98,6 +118,11 @@ export class DataHandler {
|
|
|
98
118
|
/**
|
|
99
119
|
* Retrieves all `data-*` attributes as a DOMStringMap.
|
|
100
120
|
* @returns A DOMStringMap containing all `data-*` attributes, or `null` if not applicable.
|
|
121
|
+
* @example
|
|
122
|
+
* // HTML: <div id="test" data-role="admin" data-type="user"></div>
|
|
123
|
+
* const beInstance = be('#test');
|
|
124
|
+
* const dataAttributes = beInstance.data.valueOf();
|
|
125
|
+
* console.log(dataAttributes); // Output: { role: "admin", type: "user" }
|
|
101
126
|
*/
|
|
102
127
|
valueOf() {
|
|
103
128
|
if (this.beElement.isWhat !== 'element')
|
package/dist/modules/dom.d.ts
CHANGED
|
@@ -66,6 +66,9 @@ export interface DomHandlerHandle {
|
|
|
66
66
|
export interface DomHandlerInterface {
|
|
67
67
|
insert(mode: 'afterbegin' | 'afterend' | 'beforebegin' | 'beforeend', element: HTMLElement | Be, callback?: HandlerCallBackFn): Be;
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Handles DOM manipulation operations for Be elements.
|
|
71
|
+
*/
|
|
69
72
|
export declare class DomHandler implements DomHandlerInterface, CommonHandler<DomHandler, DomHandlerHandle> {
|
|
70
73
|
private beElement;
|
|
71
74
|
static methods: domMethods[];
|
|
@@ -83,18 +86,122 @@ export declare class DomHandler implements DomHandlerInterface, CommonHandler<Do
|
|
|
83
86
|
* @returns The Be instance for method chaining.
|
|
84
87
|
*/
|
|
85
88
|
handle(actions: DomHandlerHandle): Be;
|
|
89
|
+
/**
|
|
90
|
+
* Updates the content of the element(s).
|
|
91
|
+
* @param content - The new content to set.
|
|
92
|
+
* @param callback - Optional callback function.
|
|
93
|
+
* @returns The Be instance for method chaining.
|
|
94
|
+
* @example
|
|
95
|
+
* // HTML: <div id="test"></div>
|
|
96
|
+
* const beInstance = be('#test');
|
|
97
|
+
* beInstance.update('<p>Updated content</p>'); // Updates the content of the element
|
|
98
|
+
*/
|
|
86
99
|
update(content: string, callback?: HandlerCallBackFn): Be;
|
|
100
|
+
/**
|
|
101
|
+
* Appends content to the element(s).
|
|
102
|
+
* @param content - The content to append (string, HTMLElement, or Be instance).
|
|
103
|
+
* @param callback - Optional callback function to execute after appending.
|
|
104
|
+
* @returns The Be instance for method chaining.
|
|
105
|
+
* @example
|
|
106
|
+
* // HTML: <div id="test"></div>
|
|
107
|
+
* const beInstance = be('#test');
|
|
108
|
+
* beInstance.append('<span>Appended</span>'); // Appends content to the element
|
|
109
|
+
*/
|
|
87
110
|
append(content: Content, callback?: HandlerCallBackFn): Be;
|
|
111
|
+
/**
|
|
112
|
+
* Prepends content to the element(s).
|
|
113
|
+
* @param content - The content to prepend (string, HTMLElement, or Be instance).
|
|
114
|
+
* @param callback - Optional callback function to execute after prepending.
|
|
115
|
+
* @returns The Be instance for method chaining.
|
|
116
|
+
* @example
|
|
117
|
+
* // HTML: <div id="test"></div>
|
|
118
|
+
* const beInstance = be('#test');
|
|
119
|
+
* beInstance.prepend('<span>Prepended</span>'); // Prepends content to the element
|
|
120
|
+
*/
|
|
88
121
|
prepend(content: Content, callback?: HandlerCallBackFn): Be;
|
|
122
|
+
/**
|
|
123
|
+
* Inserts content into the element(s) at a specified position.
|
|
124
|
+
* @param mode - The position to insert the content ('afterbegin', 'afterend', 'beforebegin', 'beforeend').
|
|
125
|
+
* @param element - The content to insert (string, HTMLElement, or Be instance).
|
|
126
|
+
* @param callback - Optional callback function to execute after insertion.
|
|
127
|
+
* @returns The Be instance for method chaining.
|
|
128
|
+
* @example
|
|
129
|
+
* // HTML: <div id="test"></div>
|
|
130
|
+
* const beInstance = be('#test');
|
|
131
|
+
* beInstance.insert('afterbegin', '<span>Inserted</span>'); // Inserts content at the beginning
|
|
132
|
+
*/
|
|
89
133
|
insert(mode: 'afterbegin' | 'afterend' | 'beforebegin' | 'beforeend', element: HTMLElement | Be | string, callback?: HandlerCallBackFn): Be;
|
|
134
|
+
/**
|
|
135
|
+
* Inserts content at the beginning of the element(s).
|
|
136
|
+
* @param content - The content to insert (string, HTMLElement, or Be instance).
|
|
137
|
+
* @param callback - Optional callback function to execute after insertion.
|
|
138
|
+
* @returns The Be instance for method chaining.
|
|
139
|
+
*/
|
|
90
140
|
afterBegin(content: Content, callback?: HandlerCallBackFn): Be;
|
|
141
|
+
/**
|
|
142
|
+
* Inserts content after the element(s).
|
|
143
|
+
* @param content - The content to insert (string, HTMLElement, or Be instance).
|
|
144
|
+
* @param callback - Optional callback function to execute after insertion.
|
|
145
|
+
* @returns The Be instance for method chaining.
|
|
146
|
+
*/
|
|
91
147
|
afterEnd(content: Content, callback?: HandlerCallBackFn): Be;
|
|
148
|
+
/**
|
|
149
|
+
* Inserts content before the element(s).
|
|
150
|
+
* @param content - The content to insert (string, HTMLElement, or Be instance).
|
|
151
|
+
* @param callback - Optional callback function to execute after insertion.
|
|
152
|
+
* @returns The Be instance for method chaining.
|
|
153
|
+
*/
|
|
92
154
|
beforeBegin(content: Content, callback?: HandlerCallBackFn): Be;
|
|
155
|
+
/**
|
|
156
|
+
* Inserts content at the end of the element(s).
|
|
157
|
+
* @param content - The content to insert (string, HTMLElement, or Be instance).
|
|
158
|
+
* @param callback - Optional callback function to execute after insertion.
|
|
159
|
+
* @returns The Be instance for method chaining.
|
|
160
|
+
*/
|
|
93
161
|
beforeEnd(content: Content, callback?: HandlerCallBackFn): Be;
|
|
162
|
+
/**
|
|
163
|
+
* Replaces the element(s) with new content.
|
|
164
|
+
* @param content - The content to replace the element(s) with (string, HTMLElement, or Be instance).
|
|
165
|
+
* @param callback - Optional callback function to execute after replacement.
|
|
166
|
+
* @returns The Be instance for method chaining.
|
|
167
|
+
*/
|
|
94
168
|
replace(content: Content, callback?: HandlerCallBackFn): Be;
|
|
169
|
+
/**
|
|
170
|
+
* Removes the element(s) from the DOM.
|
|
171
|
+
* @param callback - Optional callback function to execute after removal.
|
|
172
|
+
* @returns The Be instance for method chaining.
|
|
173
|
+
* @example
|
|
174
|
+
* // HTML: <div id="test"><span>To be removed</span></div>
|
|
175
|
+
* const beInstance = be('#test span');
|
|
176
|
+
* beInstance.remove(); // Removes the span element
|
|
177
|
+
*/
|
|
95
178
|
remove(callback?: HandlerCallBackFn): Be;
|
|
179
|
+
/**
|
|
180
|
+
* Clears the content of the element(s).
|
|
181
|
+
* @param callback - Optional callback function to execute after clearing.
|
|
182
|
+
* @returns The Be instance for method chaining.
|
|
183
|
+
* @example
|
|
184
|
+
* // HTML: <div id="test"><span>Content</span></div>
|
|
185
|
+
* const beInstance = be('#test');
|
|
186
|
+
* beInstance.clear(); // Clears the content of the div
|
|
187
|
+
*/
|
|
96
188
|
clear(callback?: HandlerCallBackFn): Be;
|
|
189
|
+
/**
|
|
190
|
+
* Normalizes the content of the element(s).
|
|
191
|
+
* @param callback - Optional callback function to execute after normalization.
|
|
192
|
+
* @returns The Be instance for method chaining.
|
|
193
|
+
*/
|
|
97
194
|
normalize(callback?: HandlerCallBackFn): Be;
|
|
195
|
+
/**
|
|
196
|
+
* Wraps the element(s) with a new element.
|
|
197
|
+
* @param tag - The tag name of the wrapper element (default is 'div').
|
|
198
|
+
* @param callback - Optional callback function to execute after wrapping.
|
|
199
|
+
* @returns The Be instance for method chaining.
|
|
200
|
+
* @example
|
|
201
|
+
* // HTML: <div id="test"></div>
|
|
202
|
+
* const beInstance = be('#test');
|
|
203
|
+
* beInstance.wrap('section'); // Wraps the div with a <section> element
|
|
204
|
+
*/
|
|
98
205
|
wrap(tag?: string, callback?: HandlerCallBackFn): Be;
|
|
99
206
|
private adjacentElement;
|
|
100
207
|
private normalizeContent;
|