@medyll/idae-be 0.2.1 → 0.3.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 +153 -153
- package/dist/be.d.ts +1 -0
- package/dist/be.js +1 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
|
|
2
|
-
# @medyll/idae-be
|
|
3
|
-
|
|
4
|
-
A powerful DOM manipulation library with a callback-based approach for precise element targeting.
|
|
5
|
-
|
|
6
|
-
## Installation
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
npm install @medyll/idae-be
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
## Key Features
|
|
13
|
-
|
|
14
|
-
- Root object persistence for consistent chaining
|
|
15
|
-
- Callback-based element manipulation for precise targeting
|
|
16
|
-
- Comprehensive DOM traversal and manipulation
|
|
17
|
-
- Event handling, style management, and attribute control
|
|
18
|
-
- Timer integration for dynamic operations
|
|
19
|
-
|
|
20
|
-
## Unique Approach
|
|
21
|
-
|
|
22
|
-
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
|
-
|
|
24
|
-
## Basic Usage
|
|
25
|
-
|
|
26
|
-
```javascript
|
|
27
|
-
import { be, toBe } from '@medyll/idae-be';
|
|
28
|
-
|
|
29
|
-
be('#container')
|
|
30
|
-
.append(toBe('<div>New content</div>'), ({ be }) => {
|
|
31
|
-
be
|
|
32
|
-
.addClass('highlight')
|
|
33
|
-
.on('click', () => console.log('Clicked!'));
|
|
34
|
-
})
|
|
35
|
-
.prepend(toBe('<h1>Title</h1>'))
|
|
36
|
-
.children(undefined, ({ be }) => {
|
|
37
|
-
be.setStyle({ color: 'blue' });
|
|
38
|
-
});
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## API Reference
|
|
42
|
-
|
|
43
|
-
### Core Methods
|
|
44
|
-
|
|
45
|
-
- `be(selector: string | HTMLElement | HTMLElement[]): Be` - Create a new Be instance
|
|
46
|
-
- `toBe(str: string | HTMLElement, options?: { tag?: string }): Be` - Convert string or HTMLElement to Be instance
|
|
47
|
-
- `createBe(tagOrHtml: string, options?: Object): Be` - Create a new Be element
|
|
48
|
-
|
|
49
|
-
### DOM Manipulation
|
|
50
|
-
|
|
51
|
-
- `update(content: string): Be`
|
|
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`
|
|
60
|
-
|
|
61
|
-
### Traversal
|
|
62
|
-
|
|
63
|
-
- `up(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
64
|
-
- `next(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
65
|
-
- `previous(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
66
|
-
- `siblings(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
67
|
-
- `children(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
68
|
-
- `closest(selector: string, callback?: HandlerCallBackFn): Be`
|
|
69
|
-
- `firstChild(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
70
|
-
- `lastChild(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
71
|
-
- `find(selector: string, callback?: HandlerCallBackFn): Be`
|
|
72
|
-
- `findAll(selector: string, callback?: HandlerCallBackFn): Be`
|
|
73
|
-
- `without(selector: string, callback?: HandlerCallBackFn): Be`
|
|
74
|
-
|
|
75
|
-
### Styling
|
|
76
|
-
|
|
77
|
-
- `setStyle(styles: Record<string, string>): Be`
|
|
78
|
-
- `getStyle(property: string): string | null`
|
|
79
|
-
- `unsetStyle(properties: string[]): Be`
|
|
80
|
-
- `addClass(className: string): Be`
|
|
81
|
-
- `removeClass(className: string): Be`
|
|
82
|
-
- `toggleClass(className: string): Be`
|
|
83
|
-
- `replaceClass(oldClass: string, newClass: string): Be`
|
|
84
|
-
|
|
85
|
-
### Events
|
|
86
|
-
|
|
87
|
-
- `on(eventName: string, handler: EventListener): Be`
|
|
88
|
-
- `off(eventName: string, handler: EventListener): Be`
|
|
89
|
-
- `fire(eventName: string, detail?: any): Be`
|
|
90
|
-
|
|
91
|
-
### Attributes and Properties
|
|
92
|
-
|
|
93
|
-
- `setAttr(name: string, value: string): Be`
|
|
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`
|
|
99
|
-
|
|
100
|
-
### Timers
|
|
101
|
-
|
|
102
|
-
- `timeout(delay: number, callback: HandlerCallBackFn): Be`
|
|
103
|
-
- `interval(delay: number, callback: HandlerCallBackFn): Be`
|
|
104
|
-
- `clearTimeout(): Be`
|
|
105
|
-
- `clearInterval(): Be`
|
|
106
|
-
|
|
107
|
-
## Advanced Example
|
|
108
|
-
|
|
109
|
-
```javascript
|
|
110
|
-
be('#app')
|
|
111
|
-
.append(toBe('<div id="content"></div>'), ({ be }) => {
|
|
112
|
-
be
|
|
113
|
-
.append(toBe('<button>Add Item</button>'), ({ be }) => {
|
|
114
|
-
be.on('click', () => {
|
|
115
|
-
content.append(toBe('<p>New item</p>'), ({ be }) => {
|
|
116
|
-
be
|
|
117
|
-
.addClass('item')
|
|
118
|
-
.setStyle({ color: 'blue' })
|
|
119
|
-
.on('click', ({ target }) => {
|
|
120
|
-
be(target).toggleClass('selected');
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
})
|
|
125
|
-
.children('.item', ({ be }) => {
|
|
126
|
-
be.setStyle({ padding: '5px', margin: '2px' });
|
|
127
|
-
});
|
|
128
|
-
})
|
|
129
|
-
.up(({ be }) => {
|
|
130
|
-
be.setStyle({ backgroundColor: '#f0f0f0' });
|
|
131
|
-
});
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
This example demonstrates:
|
|
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.
|
|
143
|
-
|
|
144
|
-
## Browser Support
|
|
145
|
-
|
|
146
|
-
Designed for modern browsers. May require polyfills for older browser support.
|
|
147
|
-
|
|
148
|
-
## Contributing
|
|
149
|
-
|
|
150
|
-
Contributions are welcome! Please submit pull requests or open issues on our GitHub repository.
|
|
151
|
-
|
|
152
|
-
## License
|
|
153
|
-
|
|
1
|
+
|
|
2
|
+
# @medyll/idae-be
|
|
3
|
+
|
|
4
|
+
A powerful DOM manipulation library with a callback-based approach for precise element targeting.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @medyll/idae-be
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Key Features
|
|
13
|
+
|
|
14
|
+
- Root object persistence for consistent chaining
|
|
15
|
+
- Callback-based element manipulation for precise targeting
|
|
16
|
+
- Comprehensive DOM traversal and manipulation
|
|
17
|
+
- Event handling, style management, and attribute control
|
|
18
|
+
- Timer integration for dynamic operations
|
|
19
|
+
|
|
20
|
+
## Unique Approach
|
|
21
|
+
|
|
22
|
+
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
|
+
|
|
24
|
+
## Basic Usage
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
import { be, toBe } from '@medyll/idae-be';
|
|
28
|
+
|
|
29
|
+
be('#container')
|
|
30
|
+
.append(toBe('<div>New content</div>'), ({ be }) => {
|
|
31
|
+
be
|
|
32
|
+
.addClass('highlight')
|
|
33
|
+
.on('click', () => console.log('Clicked!'));
|
|
34
|
+
})
|
|
35
|
+
.prepend(toBe('<h1>Title</h1>'))
|
|
36
|
+
.children(undefined, ({ be }) => {
|
|
37
|
+
be.setStyle({ color: 'blue' });
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API Reference
|
|
42
|
+
|
|
43
|
+
### Core Methods
|
|
44
|
+
|
|
45
|
+
- `be(selector: string | HTMLElement | HTMLElement[]): Be` - Create a new Be instance
|
|
46
|
+
- `toBe(str: string | HTMLElement, options?: { tag?: string }): Be` - Convert string or HTMLElement to Be instance
|
|
47
|
+
- `createBe(tagOrHtml: string, options?: Object): Be` - Create a new Be element
|
|
48
|
+
|
|
49
|
+
### DOM Manipulation
|
|
50
|
+
|
|
51
|
+
- `update(content: string): Be`
|
|
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`
|
|
60
|
+
|
|
61
|
+
### Traversal
|
|
62
|
+
|
|
63
|
+
- `up(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
64
|
+
- `next(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
65
|
+
- `previous(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
66
|
+
- `siblings(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
67
|
+
- `children(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
68
|
+
- `closest(selector: string, callback?: HandlerCallBackFn): Be`
|
|
69
|
+
- `firstChild(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
70
|
+
- `lastChild(selector?: string, callback?: HandlerCallBackFn): Be`
|
|
71
|
+
- `find(selector: string, callback?: HandlerCallBackFn): Be`
|
|
72
|
+
- `findAll(selector: string, callback?: HandlerCallBackFn): Be`
|
|
73
|
+
- `without(selector: string, callback?: HandlerCallBackFn): Be`
|
|
74
|
+
|
|
75
|
+
### Styling
|
|
76
|
+
|
|
77
|
+
- `setStyle(styles: Record<string, string>): Be`
|
|
78
|
+
- `getStyle(property: string): string | null`
|
|
79
|
+
- `unsetStyle(properties: string[]): Be`
|
|
80
|
+
- `addClass(className: string): Be`
|
|
81
|
+
- `removeClass(className: string): Be`
|
|
82
|
+
- `toggleClass(className: string): Be`
|
|
83
|
+
- `replaceClass(oldClass: string, newClass: string): Be`
|
|
84
|
+
|
|
85
|
+
### Events
|
|
86
|
+
|
|
87
|
+
- `on(eventName: string, handler: EventListener): Be`
|
|
88
|
+
- `off(eventName: string, handler: EventListener): Be`
|
|
89
|
+
- `fire(eventName: string, detail?: any): Be`
|
|
90
|
+
|
|
91
|
+
### Attributes and Properties
|
|
92
|
+
|
|
93
|
+
- `setAttr(name: string, value: string): Be`
|
|
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`
|
|
99
|
+
|
|
100
|
+
### Timers
|
|
101
|
+
|
|
102
|
+
- `timeout(delay: number, callback: HandlerCallBackFn): Be`
|
|
103
|
+
- `interval(delay: number, callback: HandlerCallBackFn): Be`
|
|
104
|
+
- `clearTimeout(): Be`
|
|
105
|
+
- `clearInterval(): Be`
|
|
106
|
+
|
|
107
|
+
## Advanced Example
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
be('#app')
|
|
111
|
+
.append(toBe('<div id="content"></div>'), ({ be }) => {
|
|
112
|
+
be
|
|
113
|
+
.append(toBe('<button>Add Item</button>'), ({ be }) => {
|
|
114
|
+
be.on('click', () => {
|
|
115
|
+
content.append(toBe('<p>New item</p>'), ({ be }) => {
|
|
116
|
+
be
|
|
117
|
+
.addClass('item')
|
|
118
|
+
.setStyle({ color: 'blue' })
|
|
119
|
+
.on('click', ({ target }) => {
|
|
120
|
+
be(target).toggleClass('selected');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
})
|
|
125
|
+
.children('.item', ({ be }) => {
|
|
126
|
+
be.setStyle({ padding: '5px', margin: '2px' });
|
|
127
|
+
});
|
|
128
|
+
})
|
|
129
|
+
.up(({ be }) => {
|
|
130
|
+
be.setStyle({ backgroundColor: '#f0f0f0' });
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
This example demonstrates:
|
|
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.
|
|
143
|
+
|
|
144
|
+
## Browser Support
|
|
145
|
+
|
|
146
|
+
Designed for modern browsers. May require polyfills for older browser support.
|
|
147
|
+
|
|
148
|
+
## Contributing
|
|
149
|
+
|
|
150
|
+
Contributions are welcome! Please submit pull requests or open issues on our GitHub repository.
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
154
|
This project is licensed under the MIT License.
|
package/dist/be.d.ts
CHANGED
|
@@ -131,6 +131,7 @@ export declare class Be {
|
|
|
131
131
|
private handle;
|
|
132
132
|
}
|
|
133
133
|
type CreateFragment = `<${string}>${string}</${string}>` | string;
|
|
134
|
+
/** set exports as root */
|
|
134
135
|
export declare const be: typeof Be.elem;
|
|
135
136
|
export declare const toBe: typeof Be.toBe;
|
|
136
137
|
export declare const beId: (id: string) => Be;
|
package/dist/be.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medyll/idae-be",
|
|
3
|
-
"
|
|
3
|
+
"scope": "@medyll",
|
|
4
|
+
"version": "0.3.0",
|
|
4
5
|
"scripts": {
|
|
5
6
|
"dev": "vite dev",
|
|
6
7
|
"build": "vite build && npm run package",
|
|
@@ -55,6 +56,5 @@
|
|
|
55
56
|
},
|
|
56
57
|
"svelte": "./dist/index.js",
|
|
57
58
|
"types": "./dist/index.d.ts",
|
|
58
|
-
"type": "module"
|
|
59
|
-
|
|
60
|
-
}
|
|
59
|
+
"type": "module"
|
|
60
|
+
}
|