@medyll/idae-be 0.83.0 → 0.85.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.js CHANGED
@@ -127,7 +127,7 @@ export class Be {
127
127
  // position
128
128
  this.positionHandler = new PositionHandler(this);
129
129
  this.position = this.handle(this.positionHandler);
130
- this.attach(PositionHandler, 'Position');
130
+ this.attach(PositionHandler);
131
131
  // text
132
132
  this.textHandler = new TextHandler(this);
133
133
  this.dom = this.handle(this.textHandler);
@@ -306,11 +306,14 @@ export class Be {
306
306
  const fromMethods = Handler.methods || [];
307
307
  fromMethods.forEach((method) => {
308
308
  const handler = new Handler(this);
309
- const methodName = method + suffix;
309
+ const methodName = suffix ? method + suffix : method;
310
310
  if (!(method in handler)) {
311
311
  console.error(`Method ${method} not found in ${Handler.name}`, handler);
312
312
  }
313
313
  else if (methodName in this) {
314
+ if (!handler) {
315
+ console.error(`Handler ${Handler.name} not found`, handler);
316
+ }
314
317
  this[methodName] = (...args) => {
315
318
  return handler[method].apply(handler, args);
316
319
  };
@@ -7,7 +7,8 @@ declare enum attrMethods {
7
7
  }
8
8
  export type AttrHandlerHandle = {
9
9
  set: AttrHandler['set'];
10
- delete: AttrHandler['handle'];
10
+ get: AttrHandler['get'];
11
+ delete: AttrHandler['delete'];
11
12
  };
12
13
  export declare class AttrHandler implements CommonHandler<AttrHandler, AttrHandler> {
13
14
  private beElement;
@@ -12,12 +12,23 @@ export class AttrHandler {
12
12
  this.beElement = element;
13
13
  }
14
14
  handle(actions) {
15
- this.beElement.eachNode((el) => {
15
+ Object.entries(actions).forEach(([method, props]) => {
16
+ switch (method) {
17
+ case 'set':
18
+ this.set(props);
19
+ break;
20
+ case 'delete':
21
+ this.delete(props);
22
+ break;
23
+ }
24
+ });
25
+ /* this.beElement.eachNode((el) => {
16
26
  if (actions.delete) {
27
+ this.delete(actions.delete);
17
28
  }
18
29
  if (actions.set) {
19
30
  }
20
- });
31
+ }); */
21
32
  return this.beElement;
22
33
  }
23
34
  get(name) {
@@ -62,8 +62,7 @@ export declare class PositionHandler implements CommonHandler<PositionHandler, P
62
62
  * @param options.offset Optional offset from the target anchor point.
63
63
  * @returns The Be instance for method chaining.
64
64
  */
65
- snapTo(targetElement: string | HTMLElement, // SnapToOptions
66
- options: {
65
+ snapTo(targetElement: string | HTMLElement, options: {
67
66
  sourceAnchor: PositionSnapOptions;
68
67
  targetAnchor: PositionSnapOptions;
69
68
  offset?: {
@@ -132,8 +132,7 @@ export class PositionHandler {
132
132
  * @param options.offset Optional offset from the target anchor point.
133
133
  * @returns The Be instance for method chaining.
134
134
  */
135
- snapTo(targetElement, // SnapToOptions
136
- options, callback) {
135
+ snapTo(targetElement, options, callback) {
137
136
  if (this.beElement.isWhat !== 'element')
138
137
  return this.beElement;
139
138
  const targetEl = typeof targetElement === 'string' ? document.querySelector(targetElement) : targetElement;
@@ -147,6 +146,7 @@ export class PositionHandler {
147
146
  // Calculate final position
148
147
  const x = targetX - sourceX + offset.x;
149
148
  const y = targetY - sourceY + offset.y;
149
+ console.log('Calculated position:', { x, y }, [sourceX, sourceY], { sourceRect });
150
150
  // Apply position
151
151
  this.beElement.eachNode((el) => {
152
152
  const computedStyle = window.getComputedStyle(el);
package/dist/types.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { Be } from './be.js';
2
- export type CombineElements<T extends string> = T extends any ? T | `${T} ${CombineElements<T>}` : never;
2
+ export type CombineElements<T extends string> = T extends unknown ? T | `${T} ${CombineElements<T>}` : never;
3
3
  export type IsWhat = 'element' | 'array' | 'qy';
4
- export type PositionSnapOptions = 'top' | 'right' | 'bottom' | 'left' | `${'top' | 'right' | 'bottom' | 'left'} center` | 'center';
4
+ export type PositionSnapOptions = 'top' | 'right' | 'bottom' | 'left' | 'center' | `${'top' | 'bottom'} ${'left' | 'right' | 'center'}` | `${'left' | 'right'} ${'top' | 'bottom' | 'center'}`;
5
5
  export type HandlerCallbackProps = {
6
6
  be: Be;
7
- fragment: any;
7
+ fragment: unknown;
8
8
  root: Be;
9
- requested?: any;
9
+ requested?: unknown;
10
10
  method?: string;
11
11
  };
12
12
  export type HandlerCallBackFn = (element: HandlerCallbackProps) => void;
@@ -16,7 +16,7 @@ export type HandlerCallBack = {
16
16
  export type ExpandTyping<T> = T extends infer O ? {
17
17
  [K in keyof O]: O[K];
18
18
  } : never;
19
- export interface CommonHandler<T = any, H = any, V = unknown> {
19
+ export interface CommonHandler<T = unknown, H = unknown, V = unknown> {
20
20
  handle: (actions: H) => Be;
21
21
  methods: string[] | keyof T;
22
22
  valueOf: () => V;
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type Be } from './be.js';
2
- import type { CommonHandler } from './types.js';
2
+ import type { CommonHandler, PositionSnapOptions } from './types.js';
3
3
  interface isHTMLReturn {
4
4
  isHtml: boolean;
5
5
  tag: string;
@@ -18,7 +18,7 @@ export declare class BeUtils {
18
18
  returnHTMLelement?: boolean;
19
19
  transformTextToHtml?: boolean;
20
20
  }): isHTMLReturn;
21
- static calculateAnchorPoint(rect: DOMRect, anchor: string): [number, number];
21
+ static calculateAnchorPoint(rect: DOMRect, anchor: PositionSnapOptions): [number, number];
22
22
  static applyStyle(beElement: Be, property: string, value: string): void;
23
23
  static applyCallback(el: HTMLElement | HTMLCollection, callback: (el: HTMLElement) => void): void;
24
24
  static resolveIndirection<T = CommonHandler>(classHandler: CommonHandler, actions: keyof T): {
package/dist/utils.js CHANGED
@@ -62,33 +62,36 @@ export class BeUtils {
62
62
  return result;
63
63
  }
64
64
  static calculateAnchorPoint(rect, anchor) {
65
- const [vertical, horizontal] = anchor.split(' ');
66
- let x, y;
67
- switch (vertical) {
68
- case 'top':
69
- y = rect.top;
70
- break;
71
- case 'bottom':
72
- y = rect.bottom;
73
- break;
74
- case 'center':
75
- y = rect.top + rect.height / 2;
76
- break;
77
- default:
78
- y = rect.top;
65
+ let x = rect.left; // Valeur par défaut pour x
66
+ let y = rect.top; // Valeur par défaut pour y
67
+ if (typeof anchor === 'string') {
68
+ const [vertical, horizontal] = anchor.split(' ');
69
+ switch (vertical) {
70
+ case 'top':
71
+ y = rect.top;
72
+ break;
73
+ case 'bottom':
74
+ y = rect.bottom;
75
+ break;
76
+ case 'center':
77
+ y = rect.top + rect.height / 2;
78
+ x = rect.left + rect.width / 2;
79
+ break;
80
+ }
81
+ switch (horizontal) {
82
+ case 'left':
83
+ x = rect.left;
84
+ break;
85
+ case 'right':
86
+ x = rect.right;
87
+ break;
88
+ case 'center':
89
+ x = rect.left + rect.width / 2;
90
+ break;
91
+ }
79
92
  }
80
- switch (horizontal) {
81
- case 'left':
82
- x = rect.left;
83
- break;
84
- case 'right':
85
- x = rect.right;
86
- break;
87
- case 'center':
88
- x = rect.left + rect.width / 2;
89
- break;
90
- default:
91
- x = rect.left;
93
+ else {
94
+ throw new Error('Invalid anchor type. Expected a string.');
92
95
  }
93
96
  return [x, y];
94
97
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@medyll/idae-be",
3
3
  "scope": "@medyll",
4
- "version": "0.83.0",
4
+ "version": "0.85.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",