@medyll/idae-be 0.79.0 → 0.81.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 +8 -1
- package/dist/be.js +43 -7
- package/dist/modules/attrs.js +4 -4
- package/dist/modules/data.js +3 -3
- package/dist/modules/dom.d.ts +9 -2
- package/dist/modules/dom.js +113 -27
- package/dist/modules/position.js +4 -4
- package/dist/modules/props.js +2 -2
- package/dist/modules/text.js +2 -2
- package/dist/modules/walk.js +49 -24
- package/package.json +1 -1
package/dist/be.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { WalkHandler } from './modules/walk.js';
|
|
|
11
11
|
import { TextHandler, type TextHandlerHandle } from './modules/text.js';
|
|
12
12
|
import { TimersHandler } from './modules/timers.js';
|
|
13
13
|
export declare class Be {
|
|
14
|
-
|
|
14
|
+
inputNode: HTMLElement | HTMLElement[] | string;
|
|
15
15
|
isWhat: IsWhat;
|
|
16
16
|
BeTimer: NodeJS.Timeout | null;
|
|
17
17
|
BeInterval: NodeJS.Timeout | null;
|
|
@@ -88,6 +88,12 @@ export declare class Be {
|
|
|
88
88
|
clearTimeout: TimersHandler['clearTimeout'];
|
|
89
89
|
clearInterval: TimersHandler['clearInterval'];
|
|
90
90
|
private constructor();
|
|
91
|
+
/**
|
|
92
|
+
* Normalizes the input to ensure `node` is always an HTMLElement or an array of HTMLElements.
|
|
93
|
+
* @param input - The input to normalize (string, HTMLElement, or array of HTMLElements).
|
|
94
|
+
* @returns A valid HTMLElement or an array of HTMLElements.
|
|
95
|
+
*/
|
|
96
|
+
private static getNode;
|
|
91
97
|
static elem(node: HTMLElement | HTMLElement[] | string): Be;
|
|
92
98
|
static createBe(tagOrHtml: CreateFragment, options?: {
|
|
93
99
|
is?: string;
|
|
@@ -114,6 +120,7 @@ export declare class Be {
|
|
|
114
120
|
data?: T;
|
|
115
121
|
headers?: Record<string, string>;
|
|
116
122
|
}): Promise<any>;
|
|
123
|
+
get node(): HTMLElement | HTMLElement[];
|
|
117
124
|
eachNode(callback: (el: HTMLElement) => void, firstChild?: boolean): void;
|
|
118
125
|
/** DOM
|
|
119
126
|
* Handles various DOM operations on the element(s).
|
package/dist/be.js
CHANGED
|
@@ -11,7 +11,7 @@ import { WalkHandler } from './modules/walk.js';
|
|
|
11
11
|
import { TextHandler } from './modules/text.js';
|
|
12
12
|
import { TimersHandler } from './modules/timers.js';
|
|
13
13
|
export class Be {
|
|
14
|
-
|
|
14
|
+
inputNode;
|
|
15
15
|
isWhat;
|
|
16
16
|
//
|
|
17
17
|
BeTimer = null;
|
|
@@ -103,8 +103,13 @@ export class Be {
|
|
|
103
103
|
if (input instanceof Be) {
|
|
104
104
|
return input;
|
|
105
105
|
}
|
|
106
|
-
this.
|
|
107
|
-
this.isWhat =
|
|
106
|
+
this.inputNode = Be.getNode(input);
|
|
107
|
+
this.isWhat =
|
|
108
|
+
typeof this.inputNode === 'string'
|
|
109
|
+
? 'qy'
|
|
110
|
+
: Array.isArray(this.inputNode)
|
|
111
|
+
? 'array'
|
|
112
|
+
: 'element';
|
|
108
113
|
// styles
|
|
109
114
|
this.styleHandler = new StylesHandler(this);
|
|
110
115
|
this.styles = this.handle(this.styleHandler);
|
|
@@ -150,6 +155,27 @@ export class Be {
|
|
|
150
155
|
this.timers = this.handle(this.timerHandler);
|
|
151
156
|
this.attach(TimersHandler);
|
|
152
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Normalizes the input to ensure `node` is always an HTMLElement or an array of HTMLElements.
|
|
160
|
+
* @param input - The input to normalize (string, HTMLElement, or array of HTMLElements).
|
|
161
|
+
* @returns A valid HTMLElement or an array of HTMLElements.
|
|
162
|
+
*/
|
|
163
|
+
static getNode(input) {
|
|
164
|
+
if (typeof input === 'string') {
|
|
165
|
+
// Si `input` est une chaîne, sélectionnez les éléments correspondants
|
|
166
|
+
const elements = Array.from(document.querySelectorAll(input));
|
|
167
|
+
return elements.length === 1 ? elements[0] : elements;
|
|
168
|
+
}
|
|
169
|
+
else if (input instanceof HTMLElement) {
|
|
170
|
+
// Si `input` est un seul élément DOM, retournez-le
|
|
171
|
+
return input;
|
|
172
|
+
}
|
|
173
|
+
else if (Array.isArray(input)) {
|
|
174
|
+
// Si `input` est un tableau, filtrez pour ne garder que les éléments DOM valides
|
|
175
|
+
return input.filter((n) => n instanceof HTMLElement);
|
|
176
|
+
}
|
|
177
|
+
throw new Error('Invalid input: must be a string, HTMLElement, or an array of HTMLElements.');
|
|
178
|
+
}
|
|
153
179
|
static elem(node) {
|
|
154
180
|
return new Be(node);
|
|
155
181
|
}
|
|
@@ -239,20 +265,30 @@ export class Be {
|
|
|
239
265
|
headers: options.headers || {}
|
|
240
266
|
}).then((response) => response.json());
|
|
241
267
|
}
|
|
268
|
+
get node() {
|
|
269
|
+
switch (this.isWhat) {
|
|
270
|
+
case 'element':
|
|
271
|
+
return this.inputNode;
|
|
272
|
+
case 'array':
|
|
273
|
+
return Array.from(this.inputNode);
|
|
274
|
+
case 'qy':
|
|
275
|
+
return Array.from(document.querySelectorAll(this.inputNode));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
242
278
|
eachNode(callback, firstChild) {
|
|
243
279
|
switch (this.isWhat) {
|
|
244
280
|
case 'element':
|
|
245
|
-
BeUtils.applyCallback(this.
|
|
281
|
+
BeUtils.applyCallback(this.inputNode, callback);
|
|
246
282
|
break;
|
|
247
283
|
case 'array':
|
|
248
|
-
this.
|
|
284
|
+
this.inputNode.forEach((lo) => {
|
|
249
285
|
BeUtils.applyCallback(lo, callback);
|
|
250
286
|
if (firstChild)
|
|
251
287
|
return;
|
|
252
288
|
});
|
|
253
289
|
break;
|
|
254
290
|
case 'qy':
|
|
255
|
-
document.querySelectorAll(this.
|
|
291
|
+
document.querySelectorAll(this.inputNode).forEach((el) => {
|
|
256
292
|
callback(el);
|
|
257
293
|
if (firstChild)
|
|
258
294
|
return;
|
|
@@ -266,7 +302,7 @@ export class Be {
|
|
|
266
302
|
* @returns The Be instance for method chaining.
|
|
267
303
|
*/
|
|
268
304
|
get html() {
|
|
269
|
-
return this.isWhat === 'element' ? this.
|
|
305
|
+
return this.isWhat === 'element' ? this.inputNode.innerHTML : null;
|
|
270
306
|
}
|
|
271
307
|
attach(Handler, suffix = '') {
|
|
272
308
|
const fromMethods = Handler.methods || [];
|
package/dist/modules/attrs.js
CHANGED
|
@@ -21,11 +21,11 @@ export class AttrHandler {
|
|
|
21
21
|
return this.beElement;
|
|
22
22
|
}
|
|
23
23
|
get(name) {
|
|
24
|
-
if (typeof this.beElement.
|
|
25
|
-
return document.querySelector(this.beElement.
|
|
24
|
+
if (typeof this.beElement.inputNode === 'string')
|
|
25
|
+
return (document.querySelector(this.beElement.inputNode || '')?.getAttribute(name || '') || null);
|
|
26
26
|
if (this.beElement.isWhat !== 'element')
|
|
27
27
|
return null;
|
|
28
|
-
const el = this.beElement.
|
|
28
|
+
const el = this.beElement.inputNode;
|
|
29
29
|
return name ? el.getAttribute(name) : null;
|
|
30
30
|
}
|
|
31
31
|
set(nameOrObject, value) {
|
|
@@ -57,7 +57,7 @@ export class AttrHandler {
|
|
|
57
57
|
valueOf() {
|
|
58
58
|
if (this.beElement.isWhat !== 'element')
|
|
59
59
|
return null;
|
|
60
|
-
const el = this.beElement.
|
|
60
|
+
const el = this.beElement.inputNode;
|
|
61
61
|
const attrs = {};
|
|
62
62
|
for (let i = 0; i < el.attributes.length; i++) {
|
|
63
63
|
const attr = el.attributes[i];
|
package/dist/modules/data.js
CHANGED
|
@@ -27,7 +27,7 @@ export class DataHandler {
|
|
|
27
27
|
// if space in string
|
|
28
28
|
if (this.beElement.isWhat !== 'element')
|
|
29
29
|
return null;
|
|
30
|
-
return this.beElement.
|
|
30
|
+
return this.beElement.inputNode.dataset[key] || null;
|
|
31
31
|
}
|
|
32
32
|
set(keyOrObject, value) {
|
|
33
33
|
this.beElement.eachNode((el) => {
|
|
@@ -59,11 +59,11 @@ export class DataHandler {
|
|
|
59
59
|
// if spaces in string
|
|
60
60
|
if (this.beElement.isWhat !== 'element')
|
|
61
61
|
return null;
|
|
62
|
-
return this.beElement.
|
|
62
|
+
return this.beElement.inputNode.dataset[key] || null;
|
|
63
63
|
}
|
|
64
64
|
valueOf() {
|
|
65
65
|
if (this.beElement.isWhat !== 'element')
|
|
66
66
|
return null;
|
|
67
|
-
return this.beElement.
|
|
67
|
+
return this.beElement.inputNode.dataset;
|
|
68
68
|
}
|
|
69
69
|
}
|
package/dist/modules/dom.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ declare enum domMethods {
|
|
|
17
17
|
}
|
|
18
18
|
type Content = string | HTMLElement | Be;
|
|
19
19
|
export interface DomHandlerHandle {
|
|
20
|
+
insert?: {
|
|
21
|
+
content: string | HTMLElement | Be;
|
|
22
|
+
mode: 'afterbegin' | 'afterend' | 'beforebegin' | 'beforeend';
|
|
23
|
+
callback?: (element: HandlerCallbackProps) => void;
|
|
24
|
+
};
|
|
20
25
|
update?: {
|
|
21
26
|
content: Content;
|
|
22
27
|
callback?: (element: HandlerCallbackProps) => void;
|
|
@@ -80,8 +85,8 @@ export declare class DomHandler implements DomHandlerInterface, CommonHandler<Do
|
|
|
80
85
|
update(content: string, callback?: HandlerCallBackFn): Be;
|
|
81
86
|
append(content: Content, callback?: HandlerCallBackFn): Be;
|
|
82
87
|
prepend(content: Content, callback?: HandlerCallBackFn): Be;
|
|
83
|
-
insert(mode: 'afterbegin' | 'afterend' | 'beforebegin' | 'beforeend', element: HTMLElement | Be, callback?: HandlerCallBackFn): Be;
|
|
84
|
-
afterBegin(content:
|
|
88
|
+
insert(mode: 'afterbegin' | 'afterend' | 'beforebegin' | 'beforeend', element: HTMLElement | Be | string, callback?: HandlerCallBackFn): Be;
|
|
89
|
+
afterBegin(content: Content, callback?: HandlerCallBackFn): Be;
|
|
85
90
|
afterEnd(content: Content, callback?: HandlerCallBackFn): Be;
|
|
86
91
|
beforeBegin(content: Content, callback?: HandlerCallBackFn): Be;
|
|
87
92
|
beforeEnd(content: Content, callback?: HandlerCallBackFn): Be;
|
|
@@ -91,6 +96,8 @@ export declare class DomHandler implements DomHandlerInterface, CommonHandler<Do
|
|
|
91
96
|
normalize(callback?: HandlerCallBackFn): Be;
|
|
92
97
|
wrap(tag?: string, callback?: HandlerCallBackFn): Be;
|
|
93
98
|
private adjacentElement;
|
|
99
|
+
private normalizeContent;
|
|
100
|
+
private insertContent;
|
|
94
101
|
valueOf(): string | null;
|
|
95
102
|
}
|
|
96
103
|
export {};
|
package/dist/modules/dom.js
CHANGED
|
@@ -79,15 +79,13 @@ export class DomHandler {
|
|
|
79
79
|
append(content, callback) {
|
|
80
80
|
const ret = [];
|
|
81
81
|
this.beElement.eachNode((el) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
el.appendChild(child);
|
|
86
|
-
});
|
|
82
|
+
const normalizedContent = this.normalizeContent(content);
|
|
83
|
+
if (normalizedContent instanceof DocumentFragment) {
|
|
84
|
+
el.appendChild(normalizedContent);
|
|
87
85
|
}
|
|
88
86
|
else {
|
|
89
|
-
ret.push(
|
|
90
|
-
el.appendChild(
|
|
87
|
+
ret.push(normalizedContent);
|
|
88
|
+
el.appendChild(normalizedContent);
|
|
91
89
|
}
|
|
92
90
|
});
|
|
93
91
|
callback?.({
|
|
@@ -100,15 +98,13 @@ export class DomHandler {
|
|
|
100
98
|
prepend(content, callback) {
|
|
101
99
|
const ret = [];
|
|
102
100
|
this.beElement.eachNode((el) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
el.insertBefore(child, el.firstChild);
|
|
107
|
-
});
|
|
101
|
+
const normalizedContent = this.normalizeContent(content);
|
|
102
|
+
if (normalizedContent instanceof DocumentFragment) {
|
|
103
|
+
el.insertBefore(normalizedContent, el.firstChild);
|
|
108
104
|
}
|
|
109
105
|
else {
|
|
110
|
-
ret.push(
|
|
111
|
-
el.insertBefore(
|
|
106
|
+
ret.push(normalizedContent);
|
|
107
|
+
el.insertBefore(normalizedContent, el.firstChild);
|
|
112
108
|
}
|
|
113
109
|
});
|
|
114
110
|
callback?.({
|
|
@@ -128,6 +124,8 @@ export class DomHandler {
|
|
|
128
124
|
return this.beforeBegin(element, callback);
|
|
129
125
|
case 'beforeend':
|
|
130
126
|
return this.beforeEnd(element, callback);
|
|
127
|
+
default:
|
|
128
|
+
throw new Error(`Invalid mode: ${mode}`);
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
131
|
afterBegin(content, callback) {
|
|
@@ -142,29 +140,51 @@ export class DomHandler {
|
|
|
142
140
|
return this.beElement;
|
|
143
141
|
}
|
|
144
142
|
afterEnd(content, callback) {
|
|
145
|
-
this.
|
|
143
|
+
this.beElement.eachNode((el) => {
|
|
144
|
+
// Insérer après l'élément cible
|
|
145
|
+
el.parentNode?.insertBefore(this.normalizeContent(content), el.nextSibling);
|
|
146
|
+
callback?.({
|
|
147
|
+
fragment: content,
|
|
148
|
+
be: be(el),
|
|
149
|
+
root: this.beElement
|
|
150
|
+
});
|
|
151
|
+
});
|
|
146
152
|
return this.beElement;
|
|
147
153
|
}
|
|
148
154
|
beforeBegin(content, callback) {
|
|
149
|
-
this.
|
|
155
|
+
this.beElement.eachNode((el) => {
|
|
156
|
+
// Insérer avant l'élément cible
|
|
157
|
+
el.parentNode?.insertBefore(this.normalizeContent(content), el);
|
|
158
|
+
callback?.({
|
|
159
|
+
fragment: content,
|
|
160
|
+
be: be(el),
|
|
161
|
+
root: this.beElement
|
|
162
|
+
});
|
|
163
|
+
});
|
|
150
164
|
return this.beElement;
|
|
151
165
|
}
|
|
152
166
|
beforeEnd(content, callback) {
|
|
153
|
-
this.
|
|
167
|
+
this.beElement.eachNode((el) => {
|
|
168
|
+
// Insérer à la fin de l'élément cible
|
|
169
|
+
el.appendChild(this.normalizeContent(content));
|
|
170
|
+
callback?.({
|
|
171
|
+
fragment: content,
|
|
172
|
+
be: be(el),
|
|
173
|
+
root: this.beElement
|
|
174
|
+
});
|
|
175
|
+
});
|
|
154
176
|
return this.beElement;
|
|
155
177
|
}
|
|
156
178
|
replace(content, callback) {
|
|
157
179
|
const ret = [];
|
|
158
180
|
this.beElement.eachNode((el) => {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
el.replaceWith(child);
|
|
163
|
-
});
|
|
181
|
+
const normalizedContent = this.normalizeContent(content);
|
|
182
|
+
if (normalizedContent instanceof DocumentFragment) {
|
|
183
|
+
el.replaceWith(...normalizedContent.childNodes);
|
|
164
184
|
}
|
|
165
185
|
else {
|
|
166
|
-
ret.push(
|
|
167
|
-
el.replaceWith(
|
|
186
|
+
ret.push(normalizedContent);
|
|
187
|
+
el.replaceWith(normalizedContent);
|
|
168
188
|
}
|
|
169
189
|
});
|
|
170
190
|
callback?.({
|
|
@@ -223,12 +243,78 @@ export class DomHandler {
|
|
|
223
243
|
return this.beElement;
|
|
224
244
|
}
|
|
225
245
|
adjacentElement(element, content, mode) {
|
|
226
|
-
|
|
227
|
-
|
|
246
|
+
const normalizedContent = this.normalizeContent(content);
|
|
247
|
+
if (typeof content === 'string') {
|
|
248
|
+
// Si le contenu est une chaîne HTML, utilisez insertAdjacentHTML
|
|
249
|
+
element.insertAdjacentHTML(mode, content);
|
|
250
|
+
}
|
|
251
|
+
else if (normalizedContent instanceof HTMLElement) {
|
|
252
|
+
// Si le contenu est un élément DOM, utilisez insertAdjacentElement
|
|
253
|
+
if (mode === 'afterend') {
|
|
254
|
+
element.parentNode?.insertBefore(normalizedContent, element.nextSibling);
|
|
255
|
+
}
|
|
256
|
+
else if (mode === 'beforebegin') {
|
|
257
|
+
element.parentNode?.insertBefore(normalizedContent, element);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
element.insertAdjacentElement(mode, normalizedContent);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
else if (normalizedContent instanceof DocumentFragment) {
|
|
264
|
+
// Si le contenu est un fragment, insérez chaque nœud
|
|
265
|
+
Array.from(normalizedContent.childNodes).forEach((node) => {
|
|
266
|
+
if (mode === 'afterbegin' || mode === 'beforeend') {
|
|
267
|
+
element.appendChild(node);
|
|
268
|
+
}
|
|
269
|
+
else if (mode === 'afterend') {
|
|
270
|
+
element.parentNode?.insertBefore(node, element.nextSibling);
|
|
271
|
+
}
|
|
272
|
+
else if (mode === 'beforebegin') {
|
|
273
|
+
element.parentNode?.insertBefore(node, element);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
normalizeContent(content) {
|
|
279
|
+
if (typeof content === 'string') {
|
|
280
|
+
// Si le contenu est une chaîne HTML, créez un fragment DOM
|
|
281
|
+
const template = document.createElement('template');
|
|
282
|
+
template.innerHTML = content.trim();
|
|
283
|
+
return template.content;
|
|
284
|
+
}
|
|
285
|
+
else if (content instanceof Be) {
|
|
286
|
+
// Si le contenu est une instance de Be, utilisez son premier nœud
|
|
287
|
+
if (Array.isArray(content.node)) {
|
|
288
|
+
const fragment = document.createDocumentFragment();
|
|
289
|
+
content.node.forEach((node) => {
|
|
290
|
+
if (node instanceof HTMLElement) {
|
|
291
|
+
fragment.appendChild(node);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
return fragment;
|
|
295
|
+
}
|
|
296
|
+
else if (content.node instanceof HTMLElement) {
|
|
297
|
+
return content.node;
|
|
298
|
+
}
|
|
299
|
+
throw new Error('Invalid Be instance: no valid node found.');
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
// Sinon, le contenu est déjà un HTMLElement
|
|
303
|
+
return content;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
insertContent(el, content, mode) {
|
|
307
|
+
const normalizedContent = this.normalizeContent(content);
|
|
308
|
+
if (mode === 'afterEnd') {
|
|
309
|
+
el.parentNode?.insertBefore(normalizedContent, el.nextSibling);
|
|
310
|
+
}
|
|
311
|
+
else if (mode === 'beforeEnd') {
|
|
312
|
+
el.appendChild(normalizedContent);
|
|
313
|
+
}
|
|
228
314
|
}
|
|
229
315
|
valueOf() {
|
|
230
316
|
if (this.beElement.isWhat !== 'element')
|
|
231
317
|
return null;
|
|
232
|
-
return this.beElement.
|
|
318
|
+
return this.beElement.inputNode.innerHTML;
|
|
233
319
|
}
|
|
234
320
|
}
|
package/dist/modules/position.js
CHANGED
|
@@ -44,7 +44,7 @@ export class PositionHandler {
|
|
|
44
44
|
if (!sourceEl)
|
|
45
45
|
return this.beElement;
|
|
46
46
|
const sourceRect = sourceEl.getBoundingClientRect();
|
|
47
|
-
const targetRect = this.beElement.
|
|
47
|
+
const targetRect = this.beElement.inputNode.getBoundingClientRect();
|
|
48
48
|
const { offsetX = 0, offsetY = 0, useTransform = false } = options;
|
|
49
49
|
this.beElement.eachNode((el) => {
|
|
50
50
|
if (useTransform) {
|
|
@@ -82,7 +82,7 @@ export class PositionHandler {
|
|
|
82
82
|
return this.beElement;
|
|
83
83
|
const { alignment = 'center', offset = 0, useTransform = false } = options;
|
|
84
84
|
const targetRect = targetEl.getBoundingClientRect();
|
|
85
|
-
const selfRect = this.beElement.
|
|
85
|
+
const selfRect = this.beElement.inputNode.getBoundingClientRect();
|
|
86
86
|
let x = 0, y = 0;
|
|
87
87
|
switch (alignment) {
|
|
88
88
|
case 'center':
|
|
@@ -138,7 +138,7 @@ export class PositionHandler {
|
|
|
138
138
|
const targetEl = typeof targetElement === 'string' ? document.querySelector(targetElement) : targetElement;
|
|
139
139
|
if (!targetEl)
|
|
140
140
|
return this.beElement;
|
|
141
|
-
const sourceRect = this.beElement.
|
|
141
|
+
const sourceRect = this.beElement.inputNode.getBoundingClientRect();
|
|
142
142
|
const targetRect = targetEl.getBoundingClientRect();
|
|
143
143
|
const { sourceAnchor, targetAnchor, offset = { x: 0, y: 0 } } = options;
|
|
144
144
|
let sourceX, sourceY, targetX, targetY;
|
|
@@ -169,6 +169,6 @@ export class PositionHandler {
|
|
|
169
169
|
valueOf() {
|
|
170
170
|
if (this.beElement.isWhat !== 'element')
|
|
171
171
|
return null;
|
|
172
|
-
return this.beElement.
|
|
172
|
+
return this.beElement.inputNode.getBoundingClientRect();
|
|
173
173
|
}
|
|
174
174
|
}
|
package/dist/modules/props.js
CHANGED
|
@@ -33,7 +33,7 @@ export class PropsHandler {
|
|
|
33
33
|
get(name, callback) {
|
|
34
34
|
if (this.beElement.isWhat !== 'element')
|
|
35
35
|
return null;
|
|
36
|
-
return this.beElement.
|
|
36
|
+
return this.beElement.inputNode[name];
|
|
37
37
|
}
|
|
38
38
|
set(nameOrObject, value, callback) {
|
|
39
39
|
this.beElement.eachNode((el) => {
|
|
@@ -55,7 +55,7 @@ export class PropsHandler {
|
|
|
55
55
|
valueOf() {
|
|
56
56
|
if (this.beElement.isWhat !== 'element')
|
|
57
57
|
return null;
|
|
58
|
-
const el = this.beElement.
|
|
58
|
+
const el = this.beElement.inputNode;
|
|
59
59
|
const props = {};
|
|
60
60
|
for (let prop in el) {
|
|
61
61
|
if (el.hasOwnProperty(prop)) {
|
package/dist/modules/text.js
CHANGED
|
@@ -20,7 +20,7 @@ export class TextHandler {
|
|
|
20
20
|
get text() {
|
|
21
21
|
if (this.beElement.isWhat !== 'element')
|
|
22
22
|
return null;
|
|
23
|
-
return this.beElement.
|
|
23
|
+
return this.beElement.inputNode.textContent;
|
|
24
24
|
}
|
|
25
25
|
handle(actions) {
|
|
26
26
|
this.beElement.eachNode((el) => {
|
|
@@ -86,6 +86,6 @@ export class TextHandler {
|
|
|
86
86
|
valueOf() {
|
|
87
87
|
if (this.beElement.isWhat !== 'element')
|
|
88
88
|
return null;
|
|
89
|
-
return this.beElement.
|
|
89
|
+
return this.beElement.inputNode.innerText;
|
|
90
90
|
}
|
|
91
91
|
}
|
package/dist/modules/walk.js
CHANGED
|
@@ -114,6 +114,7 @@ export class WalkHandler {
|
|
|
114
114
|
this.beElement.eachNode((el) => {
|
|
115
115
|
if (el.parentNode) {
|
|
116
116
|
const siblings = Array.from(el.parentNode.children).filter((child) => child !== el);
|
|
117
|
+
console.log('siblings found:', siblings); // Debug
|
|
117
118
|
ret.push(...siblings.filter((sibling) => !qy || sibling.matches(qy)));
|
|
118
119
|
}
|
|
119
120
|
});
|
|
@@ -186,15 +187,19 @@ export class WalkHandler {
|
|
|
186
187
|
find(qy, callback) {
|
|
187
188
|
const ret = [];
|
|
188
189
|
this.beElement.eachNode((el) => {
|
|
189
|
-
|
|
190
|
+
const found = el.querySelector(qy);
|
|
191
|
+
console.log('find result:', found); // Debug
|
|
192
|
+
if (found)
|
|
193
|
+
ret.push(found);
|
|
190
194
|
});
|
|
195
|
+
const resultBe = Be.elem(ret); // Encapsule les résultats dans une instance de Be
|
|
191
196
|
callback?.({
|
|
192
197
|
root: this.beElement,
|
|
193
|
-
be:
|
|
198
|
+
be: resultBe,
|
|
194
199
|
fragment: 'result',
|
|
195
|
-
requested:
|
|
200
|
+
requested: resultBe
|
|
196
201
|
});
|
|
197
|
-
return
|
|
202
|
+
return resultBe;
|
|
198
203
|
}
|
|
199
204
|
/**
|
|
200
205
|
* Finds all descendants that match the selector.
|
|
@@ -225,18 +230,22 @@ export class WalkHandler {
|
|
|
225
230
|
try {
|
|
226
231
|
const ret = [];
|
|
227
232
|
this.beElement.eachNode((el) => {
|
|
228
|
-
const
|
|
229
|
-
|
|
233
|
+
const result = this.selectWhile(el, method, qy);
|
|
234
|
+
console.log(`methodize result for ${method}:`, typeof result, result); // Debug
|
|
235
|
+
if (result)
|
|
236
|
+
ret.push(...(Array.isArray(result) ? result : [result]));
|
|
230
237
|
});
|
|
238
|
+
const resultBe = Be.elem(ret);
|
|
231
239
|
callback?.({
|
|
232
240
|
root: this.beElement,
|
|
233
|
-
be:
|
|
241
|
+
be: resultBe,
|
|
234
242
|
fragment: 'result',
|
|
235
|
-
requested:
|
|
243
|
+
requested: resultBe
|
|
236
244
|
});
|
|
245
|
+
return resultBe;
|
|
237
246
|
}
|
|
238
247
|
catch (e) {
|
|
239
|
-
console.
|
|
248
|
+
console.error(`Error in methodize for ${method}:`, e); // Debug
|
|
240
249
|
}
|
|
241
250
|
return this.beElement;
|
|
242
251
|
};
|
|
@@ -250,31 +259,47 @@ export class WalkHandler {
|
|
|
250
259
|
*/
|
|
251
260
|
selectWhile(element, direction, selector) {
|
|
252
261
|
const dict = {
|
|
253
|
-
up: '
|
|
254
|
-
parent: 'parentNode',
|
|
262
|
+
up: 'parentElement',
|
|
255
263
|
next: 'nextElementSibling',
|
|
256
264
|
previous: 'previousElementSibling',
|
|
257
|
-
siblings: '
|
|
265
|
+
siblings: 'parentElement',
|
|
258
266
|
children: 'children',
|
|
259
267
|
firstChild: 'firstElementChild',
|
|
260
268
|
lastChild: 'lastElementChild',
|
|
261
269
|
closest: 'closest'
|
|
262
270
|
};
|
|
263
|
-
const property = dict[direction]
|
|
264
|
-
|
|
271
|
+
const property = dict[direction];
|
|
272
|
+
// Handle recursive traversal for `up`
|
|
273
|
+
if (direction === 'up') {
|
|
274
|
+
let current = element;
|
|
275
|
+
while (current) {
|
|
276
|
+
current = current[property];
|
|
277
|
+
if (!selector || (current && current.matches(selector))) {
|
|
278
|
+
return current;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
// Handle `siblings`
|
|
284
|
+
if (direction === 'siblings') {
|
|
285
|
+
const parent = element.parentElement;
|
|
286
|
+
if (!parent)
|
|
287
|
+
return [];
|
|
288
|
+
const siblings = Array.from(parent.children).filter((child) => child !== element);
|
|
289
|
+
return selector ? siblings.filter((sibling) => sibling.matches(selector)) : siblings;
|
|
290
|
+
}
|
|
291
|
+
// Handle `children`
|
|
292
|
+
if (direction === 'children') {
|
|
265
293
|
const children = Array.from(element.children);
|
|
266
294
|
return selector ? children.filter((child) => child.matches(selector)) : children;
|
|
267
295
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
while (sibling) {
|
|
273
|
-
if (!selector || sibling.matches(selector)) {
|
|
274
|
-
return sibling;
|
|
275
|
-
}
|
|
276
|
-
sibling = sibling[property];
|
|
296
|
+
// Handle `closest`
|
|
297
|
+
if (direction === 'closest') {
|
|
298
|
+
const closest = element.closest(selector ?? '*');
|
|
299
|
+
return closest;
|
|
277
300
|
}
|
|
278
|
-
|
|
301
|
+
// Handle single-step traversal (e.g., `next`, `previous`, `firstChild`, `lastChild`)
|
|
302
|
+
const target = element[property];
|
|
303
|
+
return target && (!selector || target.matches(selector)) ? target : null;
|
|
279
304
|
}
|
|
280
305
|
}
|
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.81.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",
|