@simplybuilder/core-dom 2.0.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/AUTHORS ADDED
@@ -0,0 +1,2 @@
1
+ Jamil Services <jamilservices@gmail.com>
2
+ Jamil Services <jamilservicos@gmail.com>
@@ -0,0 +1,35 @@
1
+ ### Contributing to `@simplybuilder/core-dom`
2
+ Thank you for considering contributing to `@simplybuilder/core-dom`!
3
+ This document contains a set of guidelines for contributing to `@simplybuilder/core-dom`.
4
+ These are guidelines, not rules. Use your best judgment and feel free to propose changes to this document in a pull request.
5
+
6
+
7
+
8
+ #### How to Contribute
9
+ **Reporting Bugs**
10
+ Before creating a bug report, please check if it has already been reported. If you find a bug that has not yet been reported, create an issue using the provided template.
11
+
12
+ **When creating a bug report, make sure to include:**
13
+ - A concise description of the issue
14
+ - Steps to reproduce the issue
15
+ - Expected behavior
16
+ - Observed behavior
17
+ - Any additional information that may be helpful
18
+
19
+ **Suggesting Improvements**
20
+ Improvements are always welcome, whether in the form of new features or enhancements to existing ones. Feel free to create an issue to discuss your ideas.
21
+
22
+ #### Pull Requests
23
+ **Want to submit your own code? Great! Here are some simple steps to get started:**
24
+
25
+ - Fork the project: This allows you to have your own copy of the project to work on.
26
+ - Create a branch: Use a descriptive name for your branch, such as feature/new_feature_name or bugfix/bug_description.
27
+ - Make your changes: Make sure to follow the project's coding guidelines.
28
+ - Test your changes: Run the existing tests and add new ones if you are introducing new features.
29
+ - Submit a Pull Request: Include a clear description of what is being proposed and any other relevant information.
30
+
31
+ #### Code of Conduct
32
+ All contributors are expected to follow our Code of Conduct. Please read it before contributing.
33
+
34
+ #### Questions?
35
+ If you have any questions or need assistance, feel free to create an issue.
package/GOVERNANCE.md ADDED
@@ -0,0 +1,10 @@
1
+ The `@simplybuilder/core-dom` project is governed by [@jamilservicos](https://github.com/jamilservicos) which is responsible for high-level guidance of the project.
2
+
3
+ **The [@jamilservicos](https://github.com/jamilservicos) has final authority over this project including:**
4
+
5
+ * Technical direction
6
+ * Project governance and process (including this policy)
7
+ * Contribution policy
8
+ * GitHub repository hosting
9
+ * Conduct guidelines
10
+ * Maintaining the list of additional Collaborators
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Simply Builder by Jamil Services
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/MAINTAINERS.md ADDED
@@ -0,0 +1 @@
1
+ [@jamilservicos](https://github.com/jamilservicos) is the main/default maintainer
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # @simplybuilder/core-dom
2
+
3
+ DOM manipulation module for @simplybuilder/core. Provides element creation, attribute management, DOM tree construction, and element removal with optional event module integration.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @simplybuilder/core-dom
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { createHTMLElement, createSVGElement, createFromStruct, removeElement, domModuleExtends } from '@simplybuilder/core-dom';
15
+
16
+ // Simple element creation
17
+ const btn = createHTMLElement({
18
+ element: { type: 'button', attr: [{ name: 'class', value: 'primary' }] },
19
+ });
20
+
21
+ // Nested DOM from struct
22
+ const section = createFromStruct({
23
+ struct: {
24
+ element: 'section',
25
+ dataset: { state: 'main' },
26
+ children: [
27
+ { element: 'h1', text: 'Title' },
28
+ { element: 'p', text: 'Content' },
29
+ ],
30
+ },
31
+ });
32
+
33
+ // Element removal with cleanup
34
+ removeElement(section);
35
+ // → removes from store, cleans up event listeners, removes from DOM
36
+
37
+ // Integration with event module (optional, zero dependency)
38
+ import { eventRegister, addEventToStore, removeAllEventsFromStore } from '@simplybuilder/core-event';
39
+
40
+ domModuleExtends({
41
+ name: 'SBCoreEvent',
42
+ version: '2.0.0',
43
+ EventActions: { /* registered actions */ },
44
+ addEventToStore,
45
+ removeAllEventsFromStore,
46
+ });
47
+
48
+ // Now createFromStruct processes struct.event config
49
+ const el = createFromStruct({
50
+ struct: { element: 'button', event: { type: 'click', action: 'handleClick' } },
51
+ });
52
+ ```
53
+
54
+ ## API
55
+
56
+ - `domModuleExtends(data)` — Register an extension module (e.g., EventModule) for declarative event binding
57
+ - `createHTMLElement(options)` — Create HTML elements with attributes, dataset, shadow DOM
58
+ - `createSVGElement(options)` — Create SVG elements with namespaced attributes
59
+ - `createFromStruct(struct)` — Build nested DOM trees from struct with optional event binding
60
+ - `removeElement(element)` — Remove element, clean up store and event listeners recursively
61
+ - `addElementToStore({ key, value })` — Store element reference by key
62
+ - `getElementFromStore(key)` — Retrieve stored element by key
63
+ - `removeElementFromStore({ key, mode, EventModule? })` — Remove from store (mode 1: with event cleanup, mode 2: store only)
64
+ - `setAttr({ element, attrs })` — Set attributes on element
65
+ - `setAttrNS({ element, attrs })` — Set namespaced attributes
66
+ - `setData({ element, dataset })` — Set dataset properties
67
+ - `DomModule` — Frozen singleton with all capabilities
68
+
69
+ ## Build from Source
70
+
71
+ ```bash
72
+ pnpm install
73
+ pnpm build
74
+ ```
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @module DomAttributeModule
3
+ * @description
4
+ * Utility functions for setting standard and namespaced attributes on DOM elements.
5
+ */
6
+ interface SetAttrData {
7
+ element: HTMLElement | SVGElement;
8
+ attrs: Array<{
9
+ name: string;
10
+ value: string;
11
+ }>;
12
+ }
13
+ /**
14
+ * Sets standard attributes on a DOM element.
15
+ * Iterates the attributes array and calls `element.setAttribute` for each entry.
16
+ *
17
+ * @function setAttr
18
+ * @param {Object} data - Attribute data.
19
+ * @param {HTMLElement|SVGElement} data.element - The target element.
20
+ * @param {Array<{name: string, value: string}>} data.attrs - Array of attribute name/value pairs.
21
+ */
22
+ export declare function setAttr(data: SetAttrData): void;
23
+ /**
24
+ * Sets namespaced attributes on a DOM element (e.g., SVG attributes).
25
+ * Calls `element.setAttributeNS(null, name, value)` for each entry.
26
+ *
27
+ * @function setAttrNS
28
+ * @param {Object} data - Namespaced attribute data.
29
+ * @param {HTMLElement|SVGElement} data.element - The target element.
30
+ * @param {Array<{name: string, value: string}>} data.attrs - Array of attribute name/value pairs.
31
+ */
32
+ export declare function setAttrNS(data: SetAttrData): void;
33
+ export {};
@@ -0,0 +1 @@
1
+ export { name, version, DomModule, domModuleExtends, getElementFromStore, createFromStruct, removeElement } from "./main";
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @module DomComponentModule
3
+ * @description
4
+ * Provides functions for creating and appending HTML and SVG elements.
5
+ * Handles attribute assignment, dataset configuration, and shadow DOM creation.
6
+ */
7
+ import type { CreateHTMLElementOptions, CreateSVGElementOptions } from './types.js';
8
+ /**
9
+ * Creates an HTML element and appends it to a parent.
10
+ * Supports attribute assignment, dataset configuration with automatic
11
+ * store registration, and optional shadow DOM creation.
12
+ *
13
+ * @function createHTMLElement
14
+ * @param {Object} [options] - Element creation options.
15
+ * @param {HTMLElement|ShadowRoot} [options.parent=document.body] - Parent element to append to.
16
+ * @param {Object} options.element - Element definition with type, attr, and dataset arrays.
17
+ * @param {string} options.element.type - HTML tag name (e.g., 'div', 'button').
18
+ * @param {Array} [options.element.attr] - Array of {name, value} attribute pairs.
19
+ * @param {Array} [options.element.dataset] - Array of {name, value} dataset pairs.
20
+ * @param {ShadowConfig} [options.shadow] - Shadow DOM configuration.
21
+ * @returns {HTMLElement|ShadowRoot|undefined} The created element, shadow root, or undefined on error.
22
+ */
23
+ export declare function createHTMLElement(data?: CreateHTMLElementOptions): HTMLElement | ShadowRoot | undefined;
24
+ /**
25
+ * Creates an SVG element and appends it to a parent.
26
+ * Supports standard and namespaced attributes, and dataset configuration.
27
+ *
28
+ * @function createSVGElement
29
+ * @param {Object} [options] - Element creation options.
30
+ * @param {SVGElement|HTMLElement} [options.parent] - Parent element to append to.
31
+ * @param {Object} options.element - Element definition.
32
+ * @param {string} options.element.type - SVG tag name (e.g., 'circle', 'rect').
33
+ * @param {Array} [options.element.attr] - Array of {name, value} attribute pairs.
34
+ * @param {Array} [options.element.attrNS] - Array of {name, value} namespaced attribute pairs.
35
+ * @param {Array} [options.element.dataset] - Array of {name, value} dataset pairs.
36
+ * @returns {SVGElement|undefined} The created SVG element, or undefined on error.
37
+ */
38
+ export declare function createSVGElement(data?: CreateSVGElementOptions): SVGElement | undefined;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @module DomDatasetModule
3
+ * @description
4
+ * Utility for setting dataset properties on DOM elements.
5
+ * When the dataset name is `state`, the element is automatically
6
+ * registered in the element store for later retrieval.
7
+ */
8
+ interface SetDataData {
9
+ element: HTMLElement | SVGElement;
10
+ dataset: Array<{
11
+ name: string;
12
+ value: string;
13
+ }>;
14
+ }
15
+ /**
16
+ * Sets dataset properties on a DOM element.
17
+ * If a dataset entry has `name === 'state'`, the element is also
18
+ * registered in the element store using the state value as key.
19
+ *
20
+ * @function setData
21
+ * @param {Object} data - Dataset data.
22
+ * @param {HTMLElement|SVGElement} data.element - The target element.
23
+ * @param {Array<{name: string, value: string}>} data.dataset - Array of dataset name/value pairs.
24
+ */
25
+ declare function setData(data: SetDataData): void;
26
+ export { setData };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @module DomExtensionModule
3
+ * @description
4
+ * Extension system for the DOM module. Allows external modules (e.g., EventModule)
5
+ * to register themselves via `domModuleExtends()` and hook into the DOM creation
6
+ * and removal pipeline. Version validation ensures compatibility at runtime.
7
+ */
8
+ interface ModuleData {
9
+ name: string;
10
+ version: string;
11
+ [key: string]: unknown;
12
+ }
13
+ /**
14
+ * Internal store for module metadata, registered extensions, and version constraints.
15
+ *
16
+ * @private
17
+ * @ignore
18
+ * @type {Object}
19
+ */
20
+ declare const internalStore: {
21
+ app: {
22
+ name: string;
23
+ version: string;
24
+ };
25
+ register: Record<string, ModuleData>;
26
+ allow: Record<string, {
27
+ major?: number;
28
+ minor?: number;
29
+ patch?: number;
30
+ }>;
31
+ clearExtensions: () => void;
32
+ };
33
+ /**
34
+ * Validates that a module's version meets the minimum version requirements
35
+ * defined in `internalStore.allow`. Checks major, minor, and patch levels.
36
+ *
37
+ * @function validVersionSupport
38
+ * @param {Object} data - Module data with name and version.
39
+ * @param {string} data.name - Module identifier (e.g., 'EventModule').
40
+ * @param {string} data.version - Semantic version string (e.g., '1.0.0').
41
+ * @returns {boolean} - True if the module version is supported.
42
+ */
43
+ declare function validVersionSupport(data: ModuleData): boolean;
44
+ /**
45
+ * Registers an external module for DOM module integration.
46
+ * Validates version compatibility before storing.
47
+ * The registered module is then available to `createEventElement` and
48
+ * `removeElement` for declarative event binding and cleanup.
49
+ *
50
+ * @function domModuleExtends
51
+ * @param {Object} data - Module data.
52
+ * @param {string} data.name - Module identifier stored as key.
53
+ * @param {string} data.version - Module version for compatibility check.
54
+ * @returns {boolean} - True if registration was successful.
55
+ */
56
+ declare function domModuleExtends(data: ModuleData): boolean;
57
+ /**
58
+ * Retrieves a registered extension module by name.
59
+ *
60
+ * @function getExtension
61
+ * @param {string} name - The module identifier.
62
+ * @returns {Object|undefined} - The registered module data, or undefined.
63
+ */
64
+ declare function getExtension(name: string): ModuleData | undefined;
65
+ /**
66
+ * Returns the first registered extension, regardless of name.
67
+ * Used by struct.ts to find the EventModule without knowing its name.
68
+ *
69
+ * @function getAnyExtension
70
+ * @returns {Object|undefined} - The first registered module, or undefined.
71
+ */
72
+ declare function getAnyExtension(): ModuleData | undefined;
73
+ /**
74
+ * Removes all registered extensions. Used for testing.
75
+ *
76
+ * @function clearExtensions
77
+ */
78
+ declare function clearExtensions(): void;
79
+ export { internalStore, validVersionSupport, domModuleExtends, getExtension, getAnyExtension, clearExtensions, };
80
+ export type { ModuleData };