@alwatr/synapse 1.0.0 → 1.1.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/CHANGELOG.md CHANGED
@@ -3,6 +3,27 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.1.0](https://github.com/Alwatr/nanolib/compare/@alwatr/synapse@1.0.1...@alwatr/synapse@1.1.0) (2025-09-01)
7
+
8
+ ### ✨ Features
9
+
10
+ * add destroy_ method to clean up directive resources ([5b3878c](https://github.com/Alwatr/nanolib/commit/5b3878cd709dfda1cb224b296e8e36f900e1dfa3))
11
+ * add init_ method for directive initialization ([30178d4](https://github.com/Alwatr/nanolib/commit/30178d40dcd59052068a334b0e811473fa184dd5))
12
+ * add query and queryAll decorators for element selection ([7eac8d2](https://github.com/Alwatr/nanolib/commit/7eac8d241b9ad714145c42f20a7a8bf58dd4b1e1))
13
+ * update main.ts to export queryDecorators ([66631e5](https://github.com/Alwatr/nanolib/commit/66631e5ddb5e1d0ed6b3883ff2008595a13c3a62))
14
+
15
+ ### 🐛 Bug Fixes
16
+
17
+ * ensure proper initialization sequence by awaiting init_ before update_ ([f251964](https://github.com/Alwatr/nanolib/commit/f2519648c89a0347978366749b681f8e4e3578a9))
18
+ * ensure update_ method is abstract in DirectiveBase class ([beae25e](https://github.com/Alwatr/nanolib/commit/beae25e45a9cad40501b60efeb4fa6b1e566a16d))
19
+
20
+ ## [1.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/synapse@1.0.0...@alwatr/synapse@1.0.1) (2025-08-26)
21
+
22
+ ### 🐛 Bug Fixes
23
+
24
+ * add missing dependency for @alwatr/delay in package.json ([616025e](https://github.com/Alwatr/nanolib/commit/616025e6d345f16ecedf62761ec96d2ad29c5856))
25
+ * ensure directive update is delayed for proper initialization ([5bc0024](https://github.com/Alwatr/nanolib/commit/5bc0024c52c3813f463141d6508c39090638c4c8))
26
+
6
27
  ## 1.0.0 (2025-08-24)
7
28
 
8
29
  ### ✨ Features
package/README.md CHANGED
@@ -155,3 +155,11 @@ document.body.appendChild(newContent);
155
155
  // You can safely bootstrap again, and it will only process the new button
156
156
  bootstrapDirectives(newContent);
157
157
  ```
158
+
159
+ ## Sponsors
160
+
161
+ The following companies, organizations, and individuals support `nanolib` ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.
162
+
163
+ ### Contributing
164
+
165
+ Contributions are welcome! Please read our [contribution guidelines](https://github.com/Alwatr/.github/blob/next/CONTRIBUTING.md) before submitting a pull request.
@@ -25,7 +25,9 @@ export declare abstract class DirectiveBase {
25
25
  * Called to update the directive's state or behavior.
26
26
  * Must be implemented by subclasses.
27
27
  */
28
- protected abstract update_(): void;
28
+ protected abstract update_(): MaybePromise<void>;
29
+ protected init_(): MaybePromise<void>;
30
+ protected destroy_(): MaybePromise<void>;
29
31
  /**
30
32
  * Dispatches a custom event from the target element.
31
33
  * @param eventName - The name of the event.
@@ -1 +1 @@
1
- {"version":3,"file":"directiveClass.d.ts","sourceRoot":"","sources":["../src/directiveClass.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,8BAAsB,aAAa;IACjC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,SAAS,SAAC;IAE7B;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,wCAAC;IAE3B;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAEzC;;;;OAIG;gBACS,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM;IAUlD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,IAAI,IAAI;IAElC;;;;OAIG;IACH,SAAS,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI;CAI/D"}
1
+ {"version":3,"file":"directiveClass.d.ts","sourceRoot":"","sources":["../src/directiveClass.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,8BAAsB,aAAa;IACjC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,SAAS,SAAC;IAE7B;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,wCAAC;IAE3B;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAEzC;;;;OAIG;gBACS,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM;IAclD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC;IAEhD,SAAS,CAAC,KAAK,IAAI,YAAY,CAAC,IAAI,CAAC;IAIrC,SAAS,CAAC,QAAQ,IAAI,YAAY,CAAC,IAAI,CAAC;IAOxC;;;;OAIG;IACH,SAAS,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI;CAI/D"}
package/dist/main.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @alwatr/synapse v1.0.0 */
1
+ /* @alwatr/synapse v1.1.0 */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -23,7 +23,9 @@ var main_exports = {};
23
23
  __export(main_exports, {
24
24
  DirectiveBase: () => DirectiveBase,
25
25
  bootstrapDirectives: () => bootstrapDirectives,
26
- directive: () => directive
26
+ directive: () => directive,
27
+ query: () => query,
28
+ queryAll: () => queryAll
27
29
  });
28
30
  module.exports = __toCommonJS(main_exports);
29
31
 
@@ -61,6 +63,7 @@ function directive(selector) {
61
63
  }
62
64
 
63
65
  // src/directiveClass.ts
66
+ var import_delay = require("@alwatr/delay");
64
67
  var import_logger2 = require("@alwatr/logger");
65
68
  var DirectiveBase = class {
66
69
  /**
@@ -73,7 +76,19 @@ var DirectiveBase = class {
73
76
  this.logger_.logMethodArgs?.("new", { selector, element });
74
77
  this.selector_ = selector;
75
78
  this.element_ = element;
76
- this.update_();
79
+ (async () => {
80
+ await import_delay.delay.immediate();
81
+ await this.init_();
82
+ await this.update_();
83
+ })();
84
+ }
85
+ init_() {
86
+ this.logger_.logMethod?.("init");
87
+ }
88
+ destroy_() {
89
+ this.logger_.logMethod?.("destroy");
90
+ this.element_.remove();
91
+ this.element_ = null;
77
92
  }
78
93
  /**
79
94
  * Dispatches a custom event from the target element.
@@ -85,10 +100,44 @@ var DirectiveBase = class {
85
100
  this.element_.dispatchEvent(new CustomEvent(eventName, { detail, bubbles: true }));
86
101
  }
87
102
  };
103
+
104
+ // src/queryDecorator.ts
105
+ function query(selector, cache = true) {
106
+ return function(target, propertyKey) {
107
+ const privateKey = Symbol(`${String(propertyKey)}__`);
108
+ Object.defineProperty(target, propertyKey, {
109
+ get() {
110
+ if (cache === false || this[privateKey] === void 0) {
111
+ this[privateKey] = this.element_.querySelector(selector);
112
+ }
113
+ return this[privateKey];
114
+ },
115
+ configurable: true,
116
+ enumerable: true
117
+ });
118
+ };
119
+ }
120
+ function queryAll(selector, cache = true) {
121
+ return function(target, propertyKey) {
122
+ const privateKey = Symbol(`${String(propertyKey)}__`);
123
+ Object.defineProperty(target, propertyKey, {
124
+ get() {
125
+ if (cache === false || this[privateKey] === void 0) {
126
+ this[privateKey] = this.element_.querySelectorAll(selector);
127
+ }
128
+ return this[privateKey];
129
+ },
130
+ configurable: true,
131
+ enumerable: true
132
+ });
133
+ };
134
+ }
88
135
  // Annotate the CommonJS export names for ESM import in node:
89
136
  0 && (module.exports = {
90
137
  DirectiveBase,
91
138
  bootstrapDirectives,
92
- directive
139
+ directive,
140
+ query,
141
+ queryAll
93
142
  });
94
143
  //# sourceMappingURL=main.cjs.map
package/dist/main.cjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/main.ts", "../src/lib.ts", "../src/bootstrap.ts", "../src/directiveDecorator.ts", "../src/directiveClass.ts"],
4
- "sourcesContent": ["export * from './bootstrap.js';\nexport * from './directiveDecorator.js';\nexport * from './directiveClass.js';", "import {createLogger} from '@alwatr/logger';\n\nimport type {DirectiveConstructor} from './directiveDecorator.js';\n\n/**\n * Alwatr Synapse Logger.\n */\nexport const logger = createLogger('alwatr/synapse');\n\n/**\n * The registry for all directives.\n */\nexport const directiveRegistry_: {selector: string; constructor: DirectiveConstructor}[] = [];\n", "import {directiveRegistry_, logger} from './lib.js';\n\nconst initializedAttribute = '_synapseConnected';\n\n/**\n * Initializes all registered directives within a given root element.\n * If no root element is provided, it scans the entire body.\n *\n * This function is idempotent; it will not re-initialize a directive on an element\n * that has already been processed.\n *\n * @param rootElement The element to scan for directives. Defaults to `document.body`.\n *\n * @example\n * ```ts\n * // Initialize directives on the whole page after the DOM is loaded.\n * document.addEventListener('DOMContentLoaded', () => bootstrapDirectives());\n *\n * // Or, initialize directives on a dynamically added part of the page.\n * const newContent = document.createElement('div');\n * newContent.innerHTML = '<div class=\"my-button\">Click Me</div>';\n * document.body.appendChild(newContent);\n *\n * bootstrapDirectives(newContent);\n * ```\n */\nexport function bootstrapDirectives(rootElement: Element | Document = document.body): void {\n logger.logMethod?.('bootstrapDirectives');\n\n for (const {selector, constructor} of directiveRegistry_) {\n try {\n const uninitializedSelector = `${selector}:not([${initializedAttribute}])`;\n const elements = rootElement.querySelectorAll<HTMLElement>(uninitializedSelector);\n if (elements.length === 0) continue;\n\n logger.logOther?.(`Found ${elements.length} new element(s) for directive \"${selector}\"`);\n elements.forEach(element => {\n // Mark the element as processed before creating an instance\n element.setAttribute(initializedAttribute, 'true');\n // Instantiate the directive with the element.\n new constructor(element, selector);\n });\n }\n catch (err) {\n logger.error('bootstrapDirectives', 'directive_instantiation_error', err, {selector});\n }\n }\n}\n", "import {directiveRegistry_, logger} from './lib.js';\n\nimport type {DirectiveBase} from './directiveClass.js';\n\n/**\n * Type definition for a directive constructor.\n * A directive class must have a constructor that accepts an HTMLElement.\n */\nexport type DirectiveConstructor<T extends DirectiveBase = DirectiveBase> = new (element: HTMLElement, selector: string) => T;\n\n/**\n * A class decorator that registers a class as a directive.\n *\n * @param selector The CSS selector to which this directive will be attached.\n *\n * @example\n * ```ts\n * @directive('.my-button')\n * class MyButtonDirective extends DirectiveBase {\n * protected update_(): void {\n * this.element_.addEventListener('click', () => console.log('Button clicked!'));\n * }\n * }\n * ```\n */\nexport function directive(selector: string) {\n logger.logMethodArgs?.('@directive', selector);\n\n /**\n * The decorator function that receives the class constructor.\n * @param constructor The class to be registered as a directive.\n */\n return function (constructor: DirectiveConstructor): void {\n directiveRegistry_.push({selector, constructor});\n };\n}\n", "import {createLogger} from '@alwatr/logger';\n\n/**\n * Base class for creating directives that attach behavior to DOM elements.\n * Extend this class to define custom directives.\n */\nexport abstract class DirectiveBase {\n /**\n * The CSS selector for the directive.\n */\n protected readonly selector_;\n\n /**\n * Logger instance for the directive.\n */\n protected readonly logger_;\n\n /**\n * The target DOM element this directive is attached to.\n */\n protected readonly element_: HTMLElement;\n\n /**\n * Constructor to initialize the directive with the target element.\n * @param element - The DOM element this directive is attached to.\n * @param selector - The CSS selector for the directive.\n */\n constructor(element: HTMLElement, selector: string) {\n this.logger_ = createLogger(`directive:${selector}`);\n this.logger_.logMethodArgs?.('new', {selector, element});\n\n this.selector_ = selector;\n this.element_ = element;\n\n this.update_();\n }\n\n /**\n * Called to update the directive's state or behavior.\n * Must be implemented by subclasses.\n */\n protected abstract update_(): void;\n\n /**\n * Dispatches a custom event from the target element.\n * @param eventName - The name of the event.\n * @param detail - Optional data to include in the event.\n */\n protected dispatch_(eventName: string, detail?: unknown): void {\n this.logger_.logMethodArgs?.('dispatch_', {eventName, detail});\n this.element_.dispatchEvent(new CustomEvent(eventName, {detail, bubbles: true}));\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA2B;AAOpB,IAAM,aAAS,4BAAa,gBAAgB;AAK5C,IAAM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": ["../src/main.ts", "../src/lib.ts", "../src/bootstrap.ts", "../src/directiveDecorator.ts", "../src/directiveClass.ts", "../src/queryDecorator.ts"],
4
+ "sourcesContent": ["export * from './bootstrap.js';\nexport * from './directiveDecorator.js';\nexport * from './directiveClass.js';\nexport * from './queryDecorator.js';\n", "import {createLogger} from '@alwatr/logger';\n\nimport type {DirectiveConstructor} from './directiveDecorator.js';\n\n/**\n * Alwatr Synapse Logger.\n */\nexport const logger = createLogger('alwatr/synapse');\n\n/**\n * The registry for all directives.\n */\nexport const directiveRegistry_: {selector: string; constructor: DirectiveConstructor}[] = [];\n", "import {directiveRegistry_, logger} from './lib.js';\n\nconst initializedAttribute = '_synapseConnected';\n\n/**\n * Initializes all registered directives within a given root element.\n * If no root element is provided, it scans the entire body.\n *\n * This function is idempotent; it will not re-initialize a directive on an element\n * that has already been processed.\n *\n * @param rootElement The element to scan for directives. Defaults to `document.body`.\n *\n * @example\n * ```ts\n * // Initialize directives on the whole page after the DOM is loaded.\n * document.addEventListener('DOMContentLoaded', () => bootstrapDirectives());\n *\n * // Or, initialize directives on a dynamically added part of the page.\n * const newContent = document.createElement('div');\n * newContent.innerHTML = '<div class=\"my-button\">Click Me</div>';\n * document.body.appendChild(newContent);\n *\n * bootstrapDirectives(newContent);\n * ```\n */\nexport function bootstrapDirectives(rootElement: Element | Document = document.body): void {\n logger.logMethod?.('bootstrapDirectives');\n\n for (const {selector, constructor} of directiveRegistry_) {\n try {\n const uninitializedSelector = `${selector}:not([${initializedAttribute}])`;\n const elements = rootElement.querySelectorAll<HTMLElement>(uninitializedSelector);\n if (elements.length === 0) continue;\n\n logger.logOther?.(`Found ${elements.length} new element(s) for directive \"${selector}\"`);\n elements.forEach(element => {\n // Mark the element as processed before creating an instance\n element.setAttribute(initializedAttribute, 'true');\n // Instantiate the directive with the element.\n new constructor(element, selector);\n });\n }\n catch (err) {\n logger.error('bootstrapDirectives', 'directive_instantiation_error', err, {selector});\n }\n }\n}\n", "import {directiveRegistry_, logger} from './lib.js';\n\nimport type {DirectiveBase} from './directiveClass.js';\n\n/**\n * Type definition for a directive constructor.\n * A directive class must have a constructor that accepts an HTMLElement.\n */\nexport type DirectiveConstructor<T extends DirectiveBase = DirectiveBase> = new (element: HTMLElement, selector: string) => T;\n\n/**\n * A class decorator that registers a class as a directive.\n *\n * @param selector The CSS selector to which this directive will be attached.\n *\n * @example\n * ```ts\n * @directive('.my-button')\n * class MyButtonDirective extends DirectiveBase {\n * protected update_(): void {\n * this.element_.addEventListener('click', () => console.log('Button clicked!'));\n * }\n * }\n * ```\n */\nexport function directive(selector: string) {\n logger.logMethodArgs?.('@directive', selector);\n\n /**\n * The decorator function that receives the class constructor.\n * @param constructor The class to be registered as a directive.\n */\n return function (constructor: DirectiveConstructor): void {\n directiveRegistry_.push({selector, constructor});\n };\n}\n", "import {delay} from '@alwatr/delay';\nimport {createLogger} from '@alwatr/logger';\n\n/**\n * Base class for creating directives that attach behavior to DOM elements.\n * Extend this class to define custom directives.\n */\nexport abstract class DirectiveBase {\n /**\n * The CSS selector for the directive.\n */\n protected readonly selector_;\n\n /**\n * Logger instance for the directive.\n */\n protected readonly logger_;\n\n /**\n * The target DOM element this directive is attached to.\n */\n protected readonly element_: HTMLElement;\n\n /**\n * Constructor to initialize the directive with the target element.\n * @param element - The DOM element this directive is attached to.\n * @param selector - The CSS selector for the directive.\n */\n constructor(element: HTMLElement, selector: string) {\n this.logger_ = createLogger(`directive:${selector}`);\n this.logger_.logMethodArgs?.('new', {selector, element});\n\n this.selector_ = selector;\n this.element_ = element;\n\n (async () => {\n await delay.immediate();\n await this.init_();\n await this.update_();\n })();\n }\n\n /**\n * Called to update the directive's state or behavior.\n * Must be implemented by subclasses.\n */\n protected abstract update_(): MaybePromise<void>;\n\n protected init_(): MaybePromise<void> {\n this.logger_.logMethod?.('init');\n }\n\n protected destroy_(): MaybePromise<void> {\n this.logger_.logMethod?.('destroy');\n this.element_.remove();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any).element_ = null;\n }\n\n /**\n * Dispatches a custom event from the target element.\n * @param eventName - The name of the event.\n * @param detail - Optional data to include in the event.\n */\n protected dispatch_(eventName: string, detail?: unknown): void {\n this.logger_.logMethodArgs?.('dispatch_', {eventName, detail});\n this.element_.dispatchEvent(new CustomEvent(eventName, {detail, bubbles: true}));\n }\n}\n", "/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type {DirectiveBase} from './directiveClass.js';\n\n/**\n * A property decorator that queries the directive's element for a selector.\n * The query is performed once and the result is cached.\n *\n * @param selector The CSS selector to query for.\n * @param cache Whether to cache the result on first access. Defaults is true.\n *\n * @example\n * ```ts\n * @directive('[my-directive]')\n * class MyDirective extends DirectiveBase {\n * @query('.my-element')\n * protected myElement?: HTMLDivElement;\n * }\n * ```\n */\nexport function query(selector: string, cache = true) {\n return function (target: DirectiveBase, propertyKey: string): void {\n const privateKey = Symbol(`${String(propertyKey)}__`);\n\n Object.defineProperty(target, propertyKey, {\n get(this: DirectiveBase) {\n if (cache === false || (this as any)[privateKey] === undefined) {\n (this as any)[privateKey] = this.element_.querySelector(selector);\n }\n return (this as any)[privateKey];\n },\n configurable: true,\n enumerable: true,\n });\n };\n}\n\n/**\n * A property decorator that queries the directive's element for all selectors.\n * The queries are performed once and the result is cached.\n *\n * @param selector The CSS selector to query for.\n *\n * @example\n * ```ts\n * @directive('[my-directive]')\n * class MyDirective extends DirectiveBase {\n * @queryAll('.my-elements')\n * protected myElements?: NodeListOf<HTMLDivElement>;\n * }\n * ```\n */\nexport function queryAll(selector: string, cache = true) {\n return function (target: DirectiveBase, propertyKey: string): void {\n const privateKey = Symbol(`${String(propertyKey)}__`);\n\n Object.defineProperty(target, propertyKey, {\n get(this: DirectiveBase) {\n if (cache === false || (this as any)[privateKey] === undefined) {\n (this as any)[privateKey] = this.element_.querySelectorAll(selector);\n }\n return (this as any)[privateKey];\n },\n configurable: true,\n enumerable: true,\n });\n };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;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ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './bootstrap.js';
2
2
  export * from './directiveDecorator.js';
3
3
  export * from './directiveClass.js';
4
+ export * from './queryDecorator.js';
4
5
  //# sourceMappingURL=main.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}
package/dist/main.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @alwatr/synapse v1.0.0 */
1
+ /* @alwatr/synapse v1.1.0 */
2
2
 
3
3
  // src/lib.ts
4
4
  import { createLogger } from "@alwatr/logger";
@@ -34,6 +34,7 @@ function directive(selector) {
34
34
  }
35
35
 
36
36
  // src/directiveClass.ts
37
+ import { delay } from "@alwatr/delay";
37
38
  import { createLogger as createLogger2 } from "@alwatr/logger";
38
39
  var DirectiveBase = class {
39
40
  /**
@@ -46,7 +47,19 @@ var DirectiveBase = class {
46
47
  this.logger_.logMethodArgs?.("new", { selector, element });
47
48
  this.selector_ = selector;
48
49
  this.element_ = element;
49
- this.update_();
50
+ (async () => {
51
+ await delay.immediate();
52
+ await this.init_();
53
+ await this.update_();
54
+ })();
55
+ }
56
+ init_() {
57
+ this.logger_.logMethod?.("init");
58
+ }
59
+ destroy_() {
60
+ this.logger_.logMethod?.("destroy");
61
+ this.element_.remove();
62
+ this.element_ = null;
50
63
  }
51
64
  /**
52
65
  * Dispatches a custom event from the target element.
@@ -58,9 +71,43 @@ var DirectiveBase = class {
58
71
  this.element_.dispatchEvent(new CustomEvent(eventName, { detail, bubbles: true }));
59
72
  }
60
73
  };
74
+
75
+ // src/queryDecorator.ts
76
+ function query(selector, cache = true) {
77
+ return function(target, propertyKey) {
78
+ const privateKey = Symbol(`${String(propertyKey)}__`);
79
+ Object.defineProperty(target, propertyKey, {
80
+ get() {
81
+ if (cache === false || this[privateKey] === void 0) {
82
+ this[privateKey] = this.element_.querySelector(selector);
83
+ }
84
+ return this[privateKey];
85
+ },
86
+ configurable: true,
87
+ enumerable: true
88
+ });
89
+ };
90
+ }
91
+ function queryAll(selector, cache = true) {
92
+ return function(target, propertyKey) {
93
+ const privateKey = Symbol(`${String(propertyKey)}__`);
94
+ Object.defineProperty(target, propertyKey, {
95
+ get() {
96
+ if (cache === false || this[privateKey] === void 0) {
97
+ this[privateKey] = this.element_.querySelectorAll(selector);
98
+ }
99
+ return this[privateKey];
100
+ },
101
+ configurable: true,
102
+ enumerable: true
103
+ });
104
+ };
105
+ }
61
106
  export {
62
107
  DirectiveBase,
63
108
  bootstrapDirectives,
64
- directive
109
+ directive,
110
+ query,
111
+ queryAll
65
112
  };
66
113
  //# sourceMappingURL=main.mjs.map
package/dist/main.mjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/lib.ts", "../src/bootstrap.ts", "../src/directiveDecorator.ts", "../src/directiveClass.ts"],
4
- "sourcesContent": ["import {createLogger} from '@alwatr/logger';\n\nimport type {DirectiveConstructor} from './directiveDecorator.js';\n\n/**\n * Alwatr Synapse Logger.\n */\nexport const logger = createLogger('alwatr/synapse');\n\n/**\n * The registry for all directives.\n */\nexport const directiveRegistry_: {selector: string; constructor: DirectiveConstructor}[] = [];\n", "import {directiveRegistry_, logger} from './lib.js';\n\nconst initializedAttribute = '_synapseConnected';\n\n/**\n * Initializes all registered directives within a given root element.\n * If no root element is provided, it scans the entire body.\n *\n * This function is idempotent; it will not re-initialize a directive on an element\n * that has already been processed.\n *\n * @param rootElement The element to scan for directives. Defaults to `document.body`.\n *\n * @example\n * ```ts\n * // Initialize directives on the whole page after the DOM is loaded.\n * document.addEventListener('DOMContentLoaded', () => bootstrapDirectives());\n *\n * // Or, initialize directives on a dynamically added part of the page.\n * const newContent = document.createElement('div');\n * newContent.innerHTML = '<div class=\"my-button\">Click Me</div>';\n * document.body.appendChild(newContent);\n *\n * bootstrapDirectives(newContent);\n * ```\n */\nexport function bootstrapDirectives(rootElement: Element | Document = document.body): void {\n logger.logMethod?.('bootstrapDirectives');\n\n for (const {selector, constructor} of directiveRegistry_) {\n try {\n const uninitializedSelector = `${selector}:not([${initializedAttribute}])`;\n const elements = rootElement.querySelectorAll<HTMLElement>(uninitializedSelector);\n if (elements.length === 0) continue;\n\n logger.logOther?.(`Found ${elements.length} new element(s) for directive \"${selector}\"`);\n elements.forEach(element => {\n // Mark the element as processed before creating an instance\n element.setAttribute(initializedAttribute, 'true');\n // Instantiate the directive with the element.\n new constructor(element, selector);\n });\n }\n catch (err) {\n logger.error('bootstrapDirectives', 'directive_instantiation_error', err, {selector});\n }\n }\n}\n", "import {directiveRegistry_, logger} from './lib.js';\n\nimport type {DirectiveBase} from './directiveClass.js';\n\n/**\n * Type definition for a directive constructor.\n * A directive class must have a constructor that accepts an HTMLElement.\n */\nexport type DirectiveConstructor<T extends DirectiveBase = DirectiveBase> = new (element: HTMLElement, selector: string) => T;\n\n/**\n * A class decorator that registers a class as a directive.\n *\n * @param selector The CSS selector to which this directive will be attached.\n *\n * @example\n * ```ts\n * @directive('.my-button')\n * class MyButtonDirective extends DirectiveBase {\n * protected update_(): void {\n * this.element_.addEventListener('click', () => console.log('Button clicked!'));\n * }\n * }\n * ```\n */\nexport function directive(selector: string) {\n logger.logMethodArgs?.('@directive', selector);\n\n /**\n * The decorator function that receives the class constructor.\n * @param constructor The class to be registered as a directive.\n */\n return function (constructor: DirectiveConstructor): void {\n directiveRegistry_.push({selector, constructor});\n };\n}\n", "import {createLogger} from '@alwatr/logger';\n\n/**\n * Base class for creating directives that attach behavior to DOM elements.\n * Extend this class to define custom directives.\n */\nexport abstract class DirectiveBase {\n /**\n * The CSS selector for the directive.\n */\n protected readonly selector_;\n\n /**\n * Logger instance for the directive.\n */\n protected readonly logger_;\n\n /**\n * The target DOM element this directive is attached to.\n */\n protected readonly element_: HTMLElement;\n\n /**\n * Constructor to initialize the directive with the target element.\n * @param element - The DOM element this directive is attached to.\n * @param selector - The CSS selector for the directive.\n */\n constructor(element: HTMLElement, selector: string) {\n this.logger_ = createLogger(`directive:${selector}`);\n this.logger_.logMethodArgs?.('new', {selector, element});\n\n this.selector_ = selector;\n this.element_ = element;\n\n this.update_();\n }\n\n /**\n * Called to update the directive's state or behavior.\n * Must be implemented by subclasses.\n */\n protected abstract update_(): void;\n\n /**\n * Dispatches a custom event from the target element.\n * @param eventName - The name of the event.\n * @param detail - Optional data to include in the event.\n */\n protected dispatch_(eventName: string, detail?: unknown): void {\n this.logger_.logMethodArgs?.('dispatch_', {eventName, detail});\n this.element_.dispatchEvent(new CustomEvent(eventName, {detail, bubbles: true}));\n }\n}\n"],
5
- "mappings": ";;;AAAA,SAAQ,oBAAmB;AAOpB,IAAM,SAAS,aAAa,gBAAgB;AAK5C,IAAM,qBAA8E,CAAC;;;ACV5F,IAAM,uBAAuB;AAwBtB,SAAS,oBAAoB,cAAkC,SAAS,MAAY;AACzF,SAAO,YAAY,qBAAqB;AAExC,aAAW,EAAC,UAAU,YAAW,KAAK,oBAAoB;AACxD,QAAI;AACF,YAAM,wBAAwB,GAAG,QAAQ,SAAS,oBAAoB;AACtE,YAAM,WAAW,YAAY,iBAA8B,qBAAqB;AAChF,UAAI,SAAS,WAAW,EAAG;AAE3B,aAAO,WAAW,SAAS,SAAS,MAAM,kCAAkC,QAAQ,GAAG;AACvF,eAAS,QAAQ,aAAW;AAE1B,gBAAQ,aAAa,sBAAsB,MAAM;AAEjD,YAAI,YAAY,SAAS,QAAQ;AAAA,MACnC,CAAC;AAAA,IACH,SACO,KAAK;AACV,aAAO,MAAM,uBAAuB,iCAAiC,KAAK,EAAC,SAAQ,CAAC;AAAA,IACtF;AAAA,EACF;AACF;;;ACtBO,SAAS,UAAU,UAAkB;AAC1C,SAAO,gBAAgB,cAAc,QAAQ;AAM7C,SAAO,SAAU,aAAyC;AACxD,uBAAmB,KAAK,EAAC,UAAU,YAAW,CAAC;AAAA,EACjD;AACF;;;ACnCA,SAAQ,gBAAAA,qBAAmB;AAMpB,IAAe,gBAAf,MAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBlC,YAAY,SAAsB,UAAkB;AAClD,SAAK,UAAUA,cAAa,aAAa,QAAQ,EAAE;AACnD,SAAK,QAAQ,gBAAgB,OAAO,EAAC,UAAU,QAAO,CAAC;AAEvD,SAAK,YAAY;AACjB,SAAK,WAAW;AAEhB,SAAK,QAAQ;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaU,UAAU,WAAmB,QAAwB;AAC7D,SAAK,QAAQ,gBAAgB,aAAa,EAAC,WAAW,OAAM,CAAC;AAC7D,SAAK,SAAS,cAAc,IAAI,YAAY,WAAW,EAAC,QAAQ,SAAS,KAAI,CAAC,CAAC;AAAA,EACjF;AACF;",
3
+ "sources": ["../src/lib.ts", "../src/bootstrap.ts", "../src/directiveDecorator.ts", "../src/directiveClass.ts", "../src/queryDecorator.ts"],
4
+ "sourcesContent": ["import {createLogger} from '@alwatr/logger';\n\nimport type {DirectiveConstructor} from './directiveDecorator.js';\n\n/**\n * Alwatr Synapse Logger.\n */\nexport const logger = createLogger('alwatr/synapse');\n\n/**\n * The registry for all directives.\n */\nexport const directiveRegistry_: {selector: string; constructor: DirectiveConstructor}[] = [];\n", "import {directiveRegistry_, logger} from './lib.js';\n\nconst initializedAttribute = '_synapseConnected';\n\n/**\n * Initializes all registered directives within a given root element.\n * If no root element is provided, it scans the entire body.\n *\n * This function is idempotent; it will not re-initialize a directive on an element\n * that has already been processed.\n *\n * @param rootElement The element to scan for directives. Defaults to `document.body`.\n *\n * @example\n * ```ts\n * // Initialize directives on the whole page after the DOM is loaded.\n * document.addEventListener('DOMContentLoaded', () => bootstrapDirectives());\n *\n * // Or, initialize directives on a dynamically added part of the page.\n * const newContent = document.createElement('div');\n * newContent.innerHTML = '<div class=\"my-button\">Click Me</div>';\n * document.body.appendChild(newContent);\n *\n * bootstrapDirectives(newContent);\n * ```\n */\nexport function bootstrapDirectives(rootElement: Element | Document = document.body): void {\n logger.logMethod?.('bootstrapDirectives');\n\n for (const {selector, constructor} of directiveRegistry_) {\n try {\n const uninitializedSelector = `${selector}:not([${initializedAttribute}])`;\n const elements = rootElement.querySelectorAll<HTMLElement>(uninitializedSelector);\n if (elements.length === 0) continue;\n\n logger.logOther?.(`Found ${elements.length} new element(s) for directive \"${selector}\"`);\n elements.forEach(element => {\n // Mark the element as processed before creating an instance\n element.setAttribute(initializedAttribute, 'true');\n // Instantiate the directive with the element.\n new constructor(element, selector);\n });\n }\n catch (err) {\n logger.error('bootstrapDirectives', 'directive_instantiation_error', err, {selector});\n }\n }\n}\n", "import {directiveRegistry_, logger} from './lib.js';\n\nimport type {DirectiveBase} from './directiveClass.js';\n\n/**\n * Type definition for a directive constructor.\n * A directive class must have a constructor that accepts an HTMLElement.\n */\nexport type DirectiveConstructor<T extends DirectiveBase = DirectiveBase> = new (element: HTMLElement, selector: string) => T;\n\n/**\n * A class decorator that registers a class as a directive.\n *\n * @param selector The CSS selector to which this directive will be attached.\n *\n * @example\n * ```ts\n * @directive('.my-button')\n * class MyButtonDirective extends DirectiveBase {\n * protected update_(): void {\n * this.element_.addEventListener('click', () => console.log('Button clicked!'));\n * }\n * }\n * ```\n */\nexport function directive(selector: string) {\n logger.logMethodArgs?.('@directive', selector);\n\n /**\n * The decorator function that receives the class constructor.\n * @param constructor The class to be registered as a directive.\n */\n return function (constructor: DirectiveConstructor): void {\n directiveRegistry_.push({selector, constructor});\n };\n}\n", "import {delay} from '@alwatr/delay';\nimport {createLogger} from '@alwatr/logger';\n\n/**\n * Base class for creating directives that attach behavior to DOM elements.\n * Extend this class to define custom directives.\n */\nexport abstract class DirectiveBase {\n /**\n * The CSS selector for the directive.\n */\n protected readonly selector_;\n\n /**\n * Logger instance for the directive.\n */\n protected readonly logger_;\n\n /**\n * The target DOM element this directive is attached to.\n */\n protected readonly element_: HTMLElement;\n\n /**\n * Constructor to initialize the directive with the target element.\n * @param element - The DOM element this directive is attached to.\n * @param selector - The CSS selector for the directive.\n */\n constructor(element: HTMLElement, selector: string) {\n this.logger_ = createLogger(`directive:${selector}`);\n this.logger_.logMethodArgs?.('new', {selector, element});\n\n this.selector_ = selector;\n this.element_ = element;\n\n (async () => {\n await delay.immediate();\n await this.init_();\n await this.update_();\n })();\n }\n\n /**\n * Called to update the directive's state or behavior.\n * Must be implemented by subclasses.\n */\n protected abstract update_(): MaybePromise<void>;\n\n protected init_(): MaybePromise<void> {\n this.logger_.logMethod?.('init');\n }\n\n protected destroy_(): MaybePromise<void> {\n this.logger_.logMethod?.('destroy');\n this.element_.remove();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any).element_ = null;\n }\n\n /**\n * Dispatches a custom event from the target element.\n * @param eventName - The name of the event.\n * @param detail - Optional data to include in the event.\n */\n protected dispatch_(eventName: string, detail?: unknown): void {\n this.logger_.logMethodArgs?.('dispatch_', {eventName, detail});\n this.element_.dispatchEvent(new CustomEvent(eventName, {detail, bubbles: true}));\n }\n}\n", "/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type {DirectiveBase} from './directiveClass.js';\n\n/**\n * A property decorator that queries the directive's element for a selector.\n * The query is performed once and the result is cached.\n *\n * @param selector The CSS selector to query for.\n * @param cache Whether to cache the result on first access. Defaults is true.\n *\n * @example\n * ```ts\n * @directive('[my-directive]')\n * class MyDirective extends DirectiveBase {\n * @query('.my-element')\n * protected myElement?: HTMLDivElement;\n * }\n * ```\n */\nexport function query(selector: string, cache = true) {\n return function (target: DirectiveBase, propertyKey: string): void {\n const privateKey = Symbol(`${String(propertyKey)}__`);\n\n Object.defineProperty(target, propertyKey, {\n get(this: DirectiveBase) {\n if (cache === false || (this as any)[privateKey] === undefined) {\n (this as any)[privateKey] = this.element_.querySelector(selector);\n }\n return (this as any)[privateKey];\n },\n configurable: true,\n enumerable: true,\n });\n };\n}\n\n/**\n * A property decorator that queries the directive's element for all selectors.\n * The queries are performed once and the result is cached.\n *\n * @param selector The CSS selector to query for.\n *\n * @example\n * ```ts\n * @directive('[my-directive]')\n * class MyDirective extends DirectiveBase {\n * @queryAll('.my-elements')\n * protected myElements?: NodeListOf<HTMLDivElement>;\n * }\n * ```\n */\nexport function queryAll(selector: string, cache = true) {\n return function (target: DirectiveBase, propertyKey: string): void {\n const privateKey = Symbol(`${String(propertyKey)}__`);\n\n Object.defineProperty(target, propertyKey, {\n get(this: DirectiveBase) {\n if (cache === false || (this as any)[privateKey] === undefined) {\n (this as any)[privateKey] = this.element_.querySelectorAll(selector);\n }\n return (this as any)[privateKey];\n },\n configurable: true,\n enumerable: true,\n });\n };\n}\n"],
5
+ "mappings": ";;;AAAA,SAAQ,oBAAmB;AAOpB,IAAM,SAAS,aAAa,gBAAgB;AAK5C,IAAM,qBAA8E,CAAC;;;ACV5F,IAAM,uBAAuB;AAwBtB,SAAS,oBAAoB,cAAkC,SAAS,MAAY;AACzF,SAAO,YAAY,qBAAqB;AAExC,aAAW,EAAC,UAAU,YAAW,KAAK,oBAAoB;AACxD,QAAI;AACF,YAAM,wBAAwB,GAAG,QAAQ,SAAS,oBAAoB;AACtE,YAAM,WAAW,YAAY,iBAA8B,qBAAqB;AAChF,UAAI,SAAS,WAAW,EAAG;AAE3B,aAAO,WAAW,SAAS,SAAS,MAAM,kCAAkC,QAAQ,GAAG;AACvF,eAAS,QAAQ,aAAW;AAE1B,gBAAQ,aAAa,sBAAsB,MAAM;AAEjD,YAAI,YAAY,SAAS,QAAQ;AAAA,MACnC,CAAC;AAAA,IACH,SACO,KAAK;AACV,aAAO,MAAM,uBAAuB,iCAAiC,KAAK,EAAC,SAAQ,CAAC;AAAA,IACtF;AAAA,EACF;AACF;;;AC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AAA,QAClE;AACA,eAAQ,KAAa,UAAU;AAAA,MACjC;AAAA,MACA,cAAc;AAAA,MACd,YAAY;AAAA,IACd,CAAC;AAAA,EACH;AACF;AAiBO,SAAS,SAAS,UAAkB,QAAQ,MAAM;AACvD,SAAO,SAAU,QAAuB,aAA2B;AACjE,UAAM,aAAa,OAAO,GAAG,OAAO,WAAW,CAAC,IAAI;AAEpD,WAAO,eAAe,QAAQ,aAAa;AAAA,MACzC,MAAyB;AACvB,YAAI,UAAU,SAAU,KAAa,UAAU,MAAM,QAAW;AAC9D,UAAC,KAAa,UAAU,IAAI,KAAK,SAAS,iBAAiB,QAAQ;AAAA,QACrE;AACA,eAAQ,KAAa,UAAU;AAAA,MACjC;AAAA,MACA,cAAc;AAAA,MACd,YAAY;AAAA,IACd,CAAC;AAAA,EACH;AACF;",
6
6
  "names": ["createLogger"]
7
7
  }
@@ -0,0 +1,35 @@
1
+ import type { DirectiveBase } from './directiveClass.js';
2
+ /**
3
+ * A property decorator that queries the directive's element for a selector.
4
+ * The query is performed once and the result is cached.
5
+ *
6
+ * @param selector The CSS selector to query for.
7
+ * @param cache Whether to cache the result on first access. Defaults is true.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * @directive('[my-directive]')
12
+ * class MyDirective extends DirectiveBase {
13
+ * @query('.my-element')
14
+ * protected myElement?: HTMLDivElement;
15
+ * }
16
+ * ```
17
+ */
18
+ export declare function query(selector: string, cache?: boolean): (target: DirectiveBase, propertyKey: string) => void;
19
+ /**
20
+ * A property decorator that queries the directive's element for all selectors.
21
+ * The queries are performed once and the result is cached.
22
+ *
23
+ * @param selector The CSS selector to query for.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * @directive('[my-directive]')
28
+ * class MyDirective extends DirectiveBase {
29
+ * @queryAll('.my-elements')
30
+ * protected myElements?: NodeListOf<HTMLDivElement>;
31
+ * }
32
+ * ```
33
+ */
34
+ export declare function queryAll(selector: string, cache?: boolean): (target: DirectiveBase, propertyKey: string) => void;
35
+ //# sourceMappingURL=queryDecorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryDecorator.d.ts","sourceRoot":"","sources":["../src/queryDecorator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAEvD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,UAAO,IACjC,QAAQ,aAAa,EAAE,aAAa,MAAM,KAAG,IAAI,CAcnE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,UAAO,IACpC,QAAQ,aAAa,EAAE,aAAa,MAAM,KAAG,IAAI,CAcnE"}
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@alwatr/synapse",
3
3
  "description": "Connect your TypeScript classes to the DOM, declaratively.",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
6
6
  "bugs": "https://github.com/Alwatr/nanolib/issues",
7
7
  "dependencies": {
8
- "@alwatr/logger": "5.5.6"
8
+ "@alwatr/delay": "5.5.9",
9
+ "@alwatr/logger": "5.5.7"
9
10
  },
10
11
  "devDependencies": {
11
- "@alwatr/nano-build": "6.0.1",
12
+ "@alwatr/nano-build": "6.0.2",
12
13
  "@alwatr/prettier-config": "5.0.2",
13
14
  "@alwatr/tsconfig-base": "5.0.2",
14
15
  "@alwatr/type-helper": "5.4.4",
@@ -70,5 +71,5 @@
70
71
  },
71
72
  "type": "module",
72
73
  "types": "./dist/main.d.ts",
73
- "gitHead": "3c92f996e96508ea3a0432539367e34133993647"
74
+ "gitHead": "6f70c2ae343582774a7fa8694684fabb4c5ce63c"
74
75
  }