web-signature 0.0.6 → 0.0.7

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/bundle/index.js CHANGED
@@ -1 +1 @@
1
- class e{element;instance;constructor(e,t){this.instance=e,this.element=t}}let t=0;class n{components={};refs={};constructor(){}contact(e){let t=document.querySelector(e);if(!t)throw new Error(`Element not found for selector: ${e}`);let n=document.createElement("div");n.innerHTML=t.innerHTML,this.render(n),t.replaceChildren(...Array.from(n.childNodes))}add(e){this.components[e.name]&&console.warn(new Error(`Component with name ${e.name} already exists.`)),this.components[e.name]=e}ref(e){return this.refs[e]?.element}contactWith(e,...t){let n=this.refs[e];if(!n)throw new Error(`Ref with name ${e} does not exist.`);return n.instance.onContact(...t)}render(n){for(const r of Object.keys(this.components)){let o=this.components[r];for(const s of Array.from(n.querySelectorAll(r))){let n=new o;n.onInit?.(),s instanceof HTMLElement&&(n.content=s.innerHTML.trim());let i=document.createElement("template");if(i.innerHTML=n.render().trim(),i.content.children.length>1)throw new Error(`Component '${r}' must render a single root element.`);this.render(i),n.onRender?.();let c=i.content.firstElementChild;if(s.hasAttribute("ref")){let r=s.getAttribute("ref");if(t++,""===r&&(r=`r${t}${Math.random().toString(36).substring(2,15)}${t}`),this.refs[r])throw new Error(`Ref with name ${r} already exists.`);this.refs[r]=new e(n,c),c.setAttribute("ref",r)}s.replaceWith(i.content),n.onMount?.(c)}}}}class r{content}function o(){return new n}export{r as Component,n as Signature,o as default};
1
+ class e{element;instance;constructor(e,t){this.instance=e,this.element=t}}let t=0;class n{components={};refs={};constructor(){}contact(e){let t=document.querySelector(e);if(!t)throw new Error(`Element not found for selector: ${e}`);let n=document.createElement("div");n.innerHTML=t.innerHTML,this.render(n),t.replaceChildren(...Array.from(n.childNodes))}add(e){this.components[e.name]&&console.warn(new Error(`Component with name ${e.name} already exists.`)),this.components[e.name]=e}ref(e){return this.refs[e]?.element}contactWith(e,...t){let n=this.refs[e];if(!n)throw new Error(`Ref with name ${e} does not exist.`);let r=n.instance;return r.onContact?.(...t)}render(n){for(const r of Object.keys(this.components)){let o=this.components[r];for(const s of Array.from(n.querySelectorAll(r))){let n=new o;n.onInit?.(),s instanceof HTMLElement&&(n.content=s.innerHTML.trim());let i=document.createElement("template");if(i.innerHTML=n.render().trim(),i.content.children.length>1)throw new Error(`Component '${r}' must render a single root element.`);this.render(i),n.onRender?.();let c=i.content.firstElementChild;if(s.hasAttribute("ref")){let r=s.getAttribute("ref");if(t++,""===r&&(r=`r${t}${Math.random().toString(36).substring(2,15)}${t}`),this.refs[r])throw new Error(`Ref with name ${r} already exists.`);this.refs[r]=new e(n,c),c.setAttribute("ref",r)}s.replaceWith(i.content),n.onMount?.(c)}}}}class r{content}function o(){return new n}export{r as Component,n as Signature,o as default};
package/dist/Signature.js CHANGED
@@ -51,7 +51,7 @@ export default class Signature {
51
51
  throw new Error(`Ref with name ${name} does not exist.`);
52
52
  }
53
53
  let instance = ref.instance;
54
- return instance.onContact(...props);
54
+ return instance.onContact?.(...props);
55
55
  }
56
56
  render(frame) {
57
57
  for (const com of Object.keys(this.components)) {
@@ -3,9 +3,9 @@ export default abstract class Component implements component {
3
3
  abstract readonly name: string;
4
4
  content?: string;
5
5
  abstract render(): string;
6
- abstract onInit(): void;
7
- abstract onRender(): void;
8
- abstract onMount(el: Element): void;
9
- abstract onContact<P extends any[], T>(...props: P): T;
6
+ abstract onInit?(): void;
7
+ abstract onRender?(): void;
8
+ abstract onMount?(el: Element): void;
9
+ abstract onContact?(...props: any[]): any;
10
10
  }
11
11
  export type ComponentConstructor = new () => Component;
@@ -27,6 +27,6 @@ export default class Signature {
27
27
  * @template T The type of the return value of the component's onContact method.
28
28
  * @returns {T} The return value of the component's onContact method.
29
29
  */
30
- contactWith<P extends any[], T>(name: string, ...props: P): T;
30
+ contactWith(name: string, ...props: any[]): any;
31
31
  private render;
32
32
  }
@@ -12,16 +12,16 @@ interface Component {
12
12
  /**
13
13
  * Lifecycle hook that is called when the component is initialized.
14
14
  */
15
- onInit(): void;
15
+ onInit?(): void;
16
16
  /**
17
17
  * Lifecycle hook that is called when the component is rendered.
18
18
  */
19
- onRender(): void;
19
+ onRender?(): void;
20
20
  /**
21
21
  * Lifecycle hook that is called when the component is mounted to the DOM.
22
22
  * @param {Element} el The element to which the component is mounted.
23
23
  */
24
- onMount(el: Element): void;
24
+ onMount?(el: Element): void;
25
25
  /**
26
26
  * Lifecycle hook called via Signature.contactWith
27
27
  * @template P
@@ -29,6 +29,6 @@ interface Component {
29
29
  * @template T What should this hook return.
30
30
  * @returns {T} What should this hook return.
31
31
  */
32
- onContact<P extends any[], T>(...props: P): T;
32
+ onContact?(...props: any[]): any;
33
33
  }
34
34
  export default Component;
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "web-signature",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Primitive and fast framework for rendering web interfaces",
5
5
  "license": "ISC",
6
6
  "author": "PinBib",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "github.com/Pinbib/Signature"
10
+ },
7
11
  "type": "module",
8
12
  "main": "./dist/index.js",
9
13
  "types": "./dist/d/index.d.ts",
package/src/Component.ts CHANGED
@@ -6,13 +6,13 @@ export default abstract class Component implements component {
6
6
 
7
7
  abstract render(): string;
8
8
 
9
- abstract onInit(): void;
9
+ abstract onInit?(): void;
10
10
 
11
- abstract onRender(): void;
11
+ abstract onRender?(): void;
12
12
 
13
- abstract onMount(el: Element): void;
13
+ abstract onMount?(el: Element): void;
14
14
 
15
- abstract onContact<P extends any[], T>(...props: P): T;
15
+ abstract onContact?(...props: any[]): any;
16
16
  }
17
17
 
18
18
  export type ComponentConstructor = new () => Component;
package/src/Signature.ts CHANGED
@@ -58,7 +58,7 @@ export default class Signature {
58
58
  * @template T The type of the return value of the component's onContact method.
59
59
  * @returns {T} The return value of the component's onContact method.
60
60
  */
61
- public contactWith<P extends any[], T>(name: string, ...props: P): T {
61
+ public contactWith(name: string, ...props: any[]): any {
62
62
  let ref = this.refs[name];
63
63
 
64
64
  if (!ref) {
@@ -67,7 +67,7 @@ export default class Signature {
67
67
 
68
68
  let instance = ref.instance;
69
69
 
70
- return instance.onContact<P, T>(...props);
70
+ return instance.onContact?.(...props);
71
71
  }
72
72
 
73
73
  private render(frame: Element): void {
@@ -15,18 +15,18 @@ interface Component {
15
15
  /**
16
16
  * Lifecycle hook that is called when the component is initialized.
17
17
  */
18
- onInit(): void;
18
+ onInit?(): void;
19
19
 
20
20
  /**
21
21
  * Lifecycle hook that is called when the component is rendered.
22
22
  */
23
- onRender(): void;
23
+ onRender?(): void;
24
24
 
25
25
  /**
26
26
  * Lifecycle hook that is called when the component is mounted to the DOM.
27
27
  * @param {Element} el The element to which the component is mounted.
28
28
  */
29
- onMount(el: Element): void;
29
+ onMount?(el: Element): void;
30
30
 
31
31
  /**
32
32
  * Lifecycle hook called via Signature.contactWith
@@ -35,7 +35,7 @@ interface Component {
35
35
  * @template T What should this hook return.
36
36
  * @returns {T} What should this hook return.
37
37
  */
38
- onContact<P extends any[], T>(...props: P): T;
38
+ onContact?(...props: any[]): any;
39
39
  }
40
40
 
41
41
  export default Component;