@medyll/idae-be 0.87.0 → 0.89.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/README.md +121 -101
- package/dist/modules/attrs.d.ts +1 -0
- package/dist/modules/attrs.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
# @medyll/idae-be
|
|
3
2
|
|
|
4
3
|
A DOM walk and manipulation library with a callback-based approach for precise element targeting.
|
|
@@ -21,134 +20,155 @@ npm install @medyll/idae-be
|
|
|
21
20
|
|
|
22
21
|
Unlike jQuery and other chained libraries, `@medyll/idae-be` always returns the root object. This approach allows for consistent chaining while using callbacks to manipulate targeted elements. This design provides more control and clarity in complex DOM operations.
|
|
23
22
|
|
|
23
|
+
---
|
|
24
|
+
|
|
24
25
|
## Basic Usage
|
|
25
26
|
|
|
27
|
+
### Example 1: DOM Manipulation with Callbacks
|
|
28
|
+
|
|
26
29
|
```javascript
|
|
27
30
|
import { be, toBe } from '@medyll/idae-be';
|
|
28
31
|
|
|
32
|
+
// Select the container element
|
|
29
33
|
be('#container')
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
.append(toBe('<div>New content</div>'), ({ be }) => {
|
|
35
|
+
be.addClass('highlight')
|
|
36
|
+
.on('click', () => console.log('Clicked!'))
|
|
37
|
+
.append(toBe('<span>Nested content</span>'), ({ be }) => {
|
|
38
|
+
be.addClass('nested').on('mouseover', () => console.log('Hovered!'));
|
|
39
|
+
});
|
|
40
|
+
})
|
|
41
|
+
.prepend(toBe('<h1>Title</h1>'), ({ be }) => {
|
|
42
|
+
be.addClass('title').children(({ be }) => {
|
|
43
|
+
be.setStyle({ color: 'blue' });
|
|
44
|
+
});
|
|
45
|
+
});
|
|
39
46
|
```
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### Core Methods
|
|
48
|
+
**Comments:**
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
1. **`append`**: Adds a new `<div>` to the container and applies a class and event listener.
|
|
51
|
+
2. **Nested `append`**: Adds a `<span>` inside the appended `<div>` with its own class and event listener.
|
|
52
|
+
3. **`prepend`**: Adds a title at the beginning of the container and styles its children.
|
|
48
53
|
|
|
49
|
-
|
|
54
|
+
---
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
- `append(content: string | HTMLElement): Be`
|
|
53
|
-
- `prepend(content: string | HTMLElement): Be`
|
|
54
|
-
- `insert(mode: 'afterbegin' | 'afterend' | 'beforebegin' | 'beforeend', element: HTMLElement | Be): Be`
|
|
55
|
-
- `remove(): Be`
|
|
56
|
-
- `replace(content: string | HTMLElement): Be`
|
|
57
|
-
- `clear(): Be`
|
|
58
|
-
- `normalize(): Be`
|
|
59
|
-
- `wrap(tag?: string): Be`
|
|
56
|
+
### Example 2: Event Handling and Traversal
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
```javascript
|
|
59
|
+
import { be } from '@medyll/idae-be';
|
|
60
|
+
|
|
61
|
+
// Add a click event to all buttons inside the container
|
|
62
|
+
be('#container button').on('click', ({ target }) => {
|
|
63
|
+
be(target)
|
|
64
|
+
.toggleClass('active')
|
|
65
|
+
.siblings(({ be }) => {
|
|
66
|
+
be.removeClass('active').on('mouseover', () => console.log('Sibling hovered!'));
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Fire a custom event and handle it
|
|
71
|
+
be('#container').fire('customEvent', { detailKey: 'detailValue' }, ({ be }) => {
|
|
72
|
+
be.children(({ be }) => {
|
|
73
|
+
be.addClass('custom-event-handled');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
```
|
|
74
77
|
|
|
75
|
-
|
|
78
|
+
**Comments:**
|
|
76
79
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
- `addClass(className: string): Be`
|
|
81
|
-
- `removeClass(className: string): Be`
|
|
82
|
-
- `toggleClass(className: string): Be`
|
|
83
|
-
- `replaceClass(oldClass: string, newClass: string): Be`
|
|
80
|
+
1. **`on`**: Adds a click event to buttons and toggles a class on the clicked button.
|
|
81
|
+
2. **`siblings`**: Removes a class from sibling buttons and adds a hover event.
|
|
82
|
+
3. **`fire`**: Dispatches a custom event and applies a class to all child elements.
|
|
84
83
|
|
|
85
|
-
|
|
84
|
+
---
|
|
86
85
|
|
|
87
|
-
|
|
88
|
-
- `off(eventName: string, handler: EventListener): Be`
|
|
89
|
-
- `fire(eventName: string, detail?: any): Be`
|
|
86
|
+
### Example 3: Styling and Attributes
|
|
90
87
|
|
|
91
|
-
|
|
88
|
+
```javascript
|
|
89
|
+
import { be } from '@medyll/idae-be';
|
|
90
|
+
|
|
91
|
+
// Select an element and update its styles and attributes
|
|
92
|
+
be('#element')
|
|
93
|
+
.setStyle({ backgroundColor: 'yellow', fontSize: '16px' }, ({ be }) => {
|
|
94
|
+
be.setAttr('data-role', 'admin').children(({ be }) => {
|
|
95
|
+
be.setStyle({ color: 'red' }).setAttr('data-child', 'true');
|
|
96
|
+
});
|
|
97
|
+
})
|
|
98
|
+
.addClass('styled-element', ({ be }) => {
|
|
99
|
+
be.siblings(({ be }) => {
|
|
100
|
+
be.setStyle({ opacity: '0.5' });
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
```
|
|
92
104
|
|
|
93
|
-
|
|
94
|
-
- `getAttr(name: string): string | null`
|
|
95
|
-
- `deleteAttr(name: string): Be`
|
|
96
|
-
- `setData(key: string, value: string): Be`
|
|
97
|
-
- `getData(key: string): string | null`
|
|
98
|
-
- `deleteData(key: string): Be`
|
|
105
|
+
**Comments:**
|
|
99
106
|
|
|
100
|
-
|
|
107
|
+
1. **`setStyle`**: Applies styles to the selected element and its children.
|
|
108
|
+
2. **`setAttr`**: Sets attributes on the selected element and its children.
|
|
109
|
+
3. **`addClass`**: Adds a class to the element and modifies its siblings.
|
|
101
110
|
|
|
102
|
-
|
|
103
|
-
- `interval(delay: number, callback: HandlerCallBackFn): Be`
|
|
104
|
-
- `clearTimeout(): Be`
|
|
105
|
-
- `clearInterval(): Be`
|
|
111
|
+
---
|
|
106
112
|
|
|
107
|
-
|
|
113
|
+
### Example 4: Timers
|
|
108
114
|
|
|
109
115
|
```javascript
|
|
110
|
-
be
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
import { be } from '@medyll/idae-be';
|
|
117
|
+
|
|
118
|
+
// Set a timeout to execute a callback after 100ms
|
|
119
|
+
be('#test').timeout(100, ({ be }) => {
|
|
120
|
+
be.setStyle({ backgroundColor: 'yellow' }).append('<span>Timeout executed</span>');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Set an interval to execute a callback every 100ms
|
|
124
|
+
be('#test').interval(100, ({ be }) => {
|
|
125
|
+
be.toggleClass('highlight');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Clear a timeout before it executes
|
|
129
|
+
const timeoutInstance = be('#test').timeout(500, ({ be }) => {
|
|
130
|
+
be.setStyle({ color: 'red' });
|
|
131
|
+
});
|
|
132
|
+
timeoutInstance.clearTimeout();
|
|
133
|
+
|
|
134
|
+
// Clear an interval after 600ms
|
|
135
|
+
const intervalInstance = be('#test').interval(400, ({ be }) => {
|
|
136
|
+
be.setStyle({ fontSize: '20px' });
|
|
137
|
+
});
|
|
138
|
+
intervalInstance.clearInterval();
|
|
132
139
|
```
|
|
133
140
|
|
|
134
|
-
|
|
135
|
-
1. Nested element creation and manipulation
|
|
136
|
-
2. Event handling with dynamic content addition
|
|
137
|
-
3. Traversal and bulk operations on children
|
|
138
|
-
4. Accessing and styling parent elements
|
|
139
|
-
|
|
140
|
-
## TypeScript Support
|
|
141
|
-
|
|
142
|
-
This library is written in TypeScript and includes type definitions for a great developer experience.
|
|
141
|
+
---
|
|
143
142
|
|
|
144
|
-
|
|
143
|
+
### Example 5: Walk
|
|
145
144
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
```javascript
|
|
146
|
+
import { be } from '@medyll/idae-be';
|
|
147
|
+
|
|
148
|
+
// Traverse up the DOM tree to find the parent element
|
|
149
|
+
be('#child').up('#parent', ({ be: parent }) => {
|
|
150
|
+
parent.addClass('highlight').children(({ be: child }) => {
|
|
151
|
+
child.setStyle({ color: 'blue' });
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Find all siblings of an element and add a class
|
|
156
|
+
be('#target').siblings(({ be: siblings }) => {
|
|
157
|
+
siblings.addClass('sibling-class').children(({ be }) => {
|
|
158
|
+
be.setStyle({ fontWeight: 'bold' });
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Find the closest ancestor matching a selector
|
|
163
|
+
be('#child').closest('.ancestor', ({ be: closest }) => {
|
|
164
|
+
closest.setStyle({ border: '2px solid red' }).children(({ be }) => {
|
|
165
|
+
be.addClass('ancestor-child');
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
```
|
|
149
169
|
|
|
150
|
-
|
|
170
|
+
---
|
|
151
171
|
|
|
152
172
|
## License
|
|
153
173
|
|
|
154
|
-
This project is licensed under the MIT License.
|
|
174
|
+
This project is licensed under the MIT License.
|
package/dist/modules/attrs.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare class AttrHandler implements CommonHandler<AttrHandler, AttrHandl
|
|
|
21
21
|
* @param element - The Be element to operate on.
|
|
22
22
|
*/
|
|
23
23
|
constructor(element: Be);
|
|
24
|
+
methods: string[] | keyof AttrHandler;
|
|
24
25
|
/**
|
|
25
26
|
* Handles dynamic method calls for attribute operations.
|
|
26
27
|
* @param actions - The actions to perform (e.g., set, get, delete).
|
package/dist/modules/attrs.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medyll/idae-be",
|
|
3
3
|
"scope": "@medyll",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.89.0",
|
|
5
5
|
"description": "A powerful DOM manipulation library with a callback-based approach for precise element targeting. Provides consistent chaining, comprehensive DOM traversal, event handling, style management, and more. Written in TypeScript for modern browsers.",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite dev",
|