@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.
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @module DomStructModule
3
+ * @description
4
+ * Provides declarative DOM tree construction from structured data (ElementStruct)
5
+ * and element removal with recursive event listener cleanup.
6
+ * Integrates with EventModule via the extension system for declarative event binding.
7
+ */
8
+ import type { ElementStruct } from './types.js';
9
+ /**
10
+ * Creates an event listener on a DOM element based on struct configuration.
11
+ * Reads the `EventModule` from registered extensions, looks up the action
12
+ * by name in `EventActions`, and attaches the listener via `addEventToStore`.
13
+ *
14
+ * @private
15
+ * @ignore
16
+ * @function createEventElement
17
+ * @param {Object} data - Event binding data.
18
+ * @param {ElementStruct} data.struct - The element struct containing event config.
19
+ * @param {Element} data.element - The DOM element to attach the listener to.
20
+ */
21
+ declare function createEventElement(data: {
22
+ struct: ElementStruct;
23
+ element: Element;
24
+ }): void;
25
+ /**
26
+ * Builds a DOM tree from a structured definition.
27
+ * Creates the root element, applies attributes, text, HTML content,
28
+ * optional event bindings, and recursively creates children.
29
+ *
30
+ * @function createFromStruct
31
+ * @param {Object} data - Struct data.
32
+ * @param {ElementStruct} data.struct - The element structure definition.
33
+ * @param {HTMLElement|ShadowRoot} [data.parent=document.body] - Parent element to append to.
34
+ * @returns {Element|false} The created element, or false on failure.
35
+ */
36
+ declare function createFromStruct(data: {
37
+ struct: ElementStruct;
38
+ parent?: HTMLElement | ShadowRoot;
39
+ }): Element | false;
40
+ /**
41
+ * Attempts to clean up an element from the store or its event listeners.
42
+ * If the element has a `data-state` attribute, it removes it from the store
43
+ * (with event cleanup if EventModule is registered). Otherwise, if EventModule
44
+ * is available, it removes all event listeners from the element.
45
+ *
46
+ * @private
47
+ * @ignore
48
+ * @function removeElementFromStoreOrEvents
49
+ * @param {Element} element - The element to clean up.
50
+ * @returns {boolean} - True if cleanup was performed.
51
+ */
52
+ declare function removeElementFromStoreOrEvents(element: Element): boolean;
53
+ /**
54
+ * Removes a DOM element and recursively cleans up its children.
55
+ * For each element with `[listener="true"]`, calls `removeAllEventsFromStore`.
56
+ * For each element with `[data-state]`, removes from the element store.
57
+ * Finally removes the element from the DOM.
58
+ *
59
+ * @function removeElement
60
+ * @param {Element} element - The element to remove.
61
+ */
62
+ declare function removeElement(element: Element): void;
63
+ export { createFromStruct, removeElement, createEventElement, removeElementFromStoreOrEvents };
package/lib/types.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ export interface ShadowConfigString {
2
+ mode: 'open' | 'closed';
3
+ }
4
+ export interface ShadowConfigObject {
5
+ mode: 'open' | 'closed';
6
+ styles?: string;
7
+ }
8
+ export type ShadowConfig = ShadowConfigString | ShadowConfigObject | string;
9
+ export interface EventStruct {
10
+ type: string;
11
+ action: string;
12
+ node?: string;
13
+ }
14
+ export interface ElementStruct {
15
+ element: string;
16
+ type?: string;
17
+ attr?: Record<string, string>;
18
+ attrNS?: Record<string, string>;
19
+ dataset?: Record<string, string>;
20
+ text?: string;
21
+ html?: string;
22
+ shadow?: ShadowConfig;
23
+ event?: EventStruct;
24
+ children?: ElementStruct[];
25
+ }
26
+ export interface CreateHTMLElementOptions {
27
+ parent?: HTMLElement | ShadowRoot;
28
+ element: {
29
+ type: string;
30
+ attr?: Array<{
31
+ name: string;
32
+ value: string;
33
+ }>;
34
+ dataset?: Array<{
35
+ name: string;
36
+ value: string;
37
+ }>;
38
+ };
39
+ shadow?: ShadowConfig;
40
+ }
41
+ export interface CreateSVGElementOptions {
42
+ parent?: HTMLElement | SVGElement;
43
+ element: {
44
+ type: string;
45
+ attr?: Array<{
46
+ name: string;
47
+ value: string;
48
+ }>;
49
+ attrNS?: Array<{
50
+ name: string;
51
+ value: string;
52
+ }>;
53
+ dataset?: Array<{
54
+ name: string;
55
+ value: string;
56
+ }>;
57
+ };
58
+ }
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "@simplybuilder/core-dom",
3
+ "version": "2.0.0",
4
+ "main": "lib/main.commonjs.min.cjs",
5
+ "module": "lib/main.esm.min.mjs",
6
+ "types": "lib/core-dom.d.ts",
7
+ "typings": "lib/core-dom.d.ts",
8
+ "exports": {
9
+ "./commonjs-module": {
10
+ "require": "./lib/main.commonjs.min.cjs"
11
+ },
12
+ "./esm-module": {
13
+ "import": "./lib/main.esm.min.mjs"
14
+ },
15
+ "./dts": {
16
+ "types": "./lib/core-dom.d.ts"
17
+ },
18
+ "./core-dom": {
19
+ "types": "./lib/core-dom.d.ts"
20
+ },
21
+ ".": {
22
+ "types": "./lib/core-dom.d.ts",
23
+ "import": "./lib/main.esm.min.mjs",
24
+ "require": "./lib/main.commonjs.min.cjs"
25
+ }
26
+ },
27
+ "files": [
28
+ "AUTHORS",
29
+ "CONTRIBUTING.md",
30
+ "GOVERNANCE.md",
31
+ "MAINTAINERS.md",
32
+ "lib/main.commonjs.cjs",
33
+ "lib/main.commonjs.min.cjs",
34
+ "lib/main.esm.min.mjs",
35
+ "lib/main.esm.mjs",
36
+ "lib/**/*.d.ts"
37
+ ],
38
+ "homepage": "https://simplybuilder.github.io",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/SimplyBuilder/sb-core-v2.git"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/SimplyBuilder/sb-core-v2/issues"
45
+ },
46
+ "author": "Jamil Services <jamilservicos@gmail.com> (https://github.com/jamilservicos)",
47
+ "funding": [
48
+ {
49
+ "type": "kofi",
50
+ "url": "https://ko-fi.com/juliojamil"
51
+ },
52
+ {
53
+ "type": "github",
54
+ "url": "https://github.com/sponsors/jamilservicos"
55
+ }
56
+ ],
57
+ "devDependencies": {
58
+ "jsdom": "^26.0.0",
59
+ "typescript": "^5.7.0",
60
+ "vitest": "^3.0.0"
61
+ },
62
+ "engines": {
63
+ "node": ">=18.0.0"
64
+ },
65
+ "license": "MIT",
66
+ "keywords": [
67
+ "jamilservicos",
68
+ "jamilservices",
69
+ "node",
70
+ "nodejs",
71
+ "node.js",
72
+ "javascript",
73
+ "typescript",
74
+ "simply-builder",
75
+ "simplybuilder",
76
+ "simply",
77
+ "builder",
78
+ "module",
79
+ "core",
80
+ "front",
81
+ "frontend",
82
+ "front-end",
83
+ "dom"
84
+ ],
85
+ "scripts": {
86
+ "clean": "rm -rf lib && rm -rf audit",
87
+ "build:js": "tsc -p tsconfig-audit.json",
88
+ "build:types": "tsc -p tsconfig-types.json",
89
+ "build:pre": "pnpm run clean && pnpm run build:js && pnpm run build:types",
90
+ "build": "pnpm run build:pre && rollup -c ./rollup.config.js ",
91
+ "test": "vitest run",
92
+ "publish:pre": "pnpm build && pnpm test",
93
+ "publish:pack": "pnpm build && tar tvf $(npm pack)"
94
+ }
95
+ }