diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f3ce53f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +extensions +.npmignore +bun.lockb +node_modules \ No newline at end of file diff --git a/lib/$NodeManager.ts b/lib/$NodeManager.ts index 20a257f..2af381e 100644 --- a/lib/$NodeManager.ts +++ b/lib/$NodeManager.ts @@ -3,39 +3,41 @@ import { $Node } from "./node/$Node"; import { $Text } from "./node/$Text"; export class $NodeManager { - #container: $Container; - elementList = new Set<$Node> + $container: $Container; + $elementList = new Set<$Node> constructor(container: $Container) { - this.#container = container; + this.$container = container; } add(element: $Node | string) { if (typeof element === 'string') { const text = new $Text(element); - this.elementList.add(text); + this.$elementList.add(text); + (text as Mutable<$Node>).parent = this.$container; } else { - this.elementList.add(element); + this.$elementList.add(element); + (element as Mutable<$Node>).parent = this.$container; } } remove(element: $Node) { - if (!this.elementList.has(element)) return this; - this.elementList.delete(element); + if (!this.$elementList.has(element)) return this; + this.$elementList.delete(element); + (element as Mutable<$Node>).parent = undefined; return this; } removeAll(render = true) { - this.elementList.forEach(ele => this.remove(ele)); + this.$elementList.forEach(ele => this.remove(ele)); if (render) this.render(); } replace(target: $Node, replace: $Node) { - const array = this.array.map(node => { - if (node === target) return replace; - else return node; - }) - this.elementList.clear(); - array.forEach(node => this.elementList.add(node)); + const array = this.array + array.splice(array.indexOf(target), 1, replace); + target.remove(); + this.$elementList.clear(); + array.forEach(node => this.$elementList.add(node)); return this; } @@ -58,7 +60,7 @@ export class $NodeManager { } } - get array() {return [...this.elementList.values()]}; + get array() {return [...this.$elementList.values()]}; - get dom() {return this.#container.dom} + get dom() {return this.$container.dom} } \ No newline at end of file diff --git a/lib/$Util.ts b/lib/$Util.ts index 48b41b6..33d3a4d 100644 --- a/lib/$Util.ts +++ b/lib/$Util.ts @@ -1,5 +1,4 @@ import { $State } from "./$State"; -import { $AsyncNode } from "./node/$AsyncNode"; import { $Container } from "./node/$Container"; import { $Document } from "./node/$Document"; import { $Node } from "./node/$Node"; diff --git a/lib/node/$Node.ts b/lib/node/$Node.ts index e62be09..7591440 100644 --- a/lib/node/$Node.ts +++ b/lib/node/$Node.ts @@ -5,6 +5,7 @@ export abstract class $Node { abstract readonly dom: N; readonly __hidden: boolean = false; private domEvents: {[key: string]: Map} = {}; + readonly parent?: $Container; on(type: K, callback: (event: HTMLElementEventMap[K], $node: this) => any, options?: AddEventListenerOptions | boolean) { if (!this.domEvents[type]) this.domEvents[type] = new Map() @@ -30,12 +31,12 @@ export abstract class $Node { } hide(): boolean; - hide(hide?: boolean | $State): this; - hide(hide?: boolean | $State) { return $.fluent(this, arguments, () => this.__hidden, () => { + hide(hide?: boolean | $State, render?: boolean): this; + hide(hide?: boolean | $State, render = true) { return $.fluent(this, arguments, () => this.__hidden, () => { if (hide === undefined) return; if (hide instanceof $State) { (this as Mutable<$Node>).__hidden = hide.value; hide.use(this, 'hide')} - else (this as Mutable<$Node>).__hidden = hide; - this.parent?.children.render(); + else (this as Mutable<$Node>).__hidden = hide; + if (render) this.parent?.children.render(); return this; })} @@ -64,8 +65,4 @@ export abstract class $Node { if (this instanceof $Element) return true; else return false; } - - get parent() { - return this.dom.parentElement?.$ as $Container | undefined; - } } \ No newline at end of file diff --git a/package.json b/package.json index 105c9bb..0b3d653 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,25 @@ { - "name": "fluentx", - "description": "Fast, fluent, simple web builder", - "version": "0.0.9", - "type": "module", - "module": "index.ts", - "author": { - "name": "defaultkavy", - "email": "defaultkavy@gmail.com", - "url": "https://github.com/defaultkavy" - }, - "keywords": ["web", "front-end", "lib", "fluent", "framework"], - "homepage": "https://github.com/defaultkavy/fluentx", - "repository": { - "type": "git", - "url": "git+https://github.com/defaultkavy/fluentx.git" - }, - "bugs": { - "url": "https://github.com/defaultkavy/fluentx/issues" - }, - "license": "ISC" + "name": "fluentx", + "version": "0.0.9", + "author": { + "name": "defaultkavy", + "email": "defaultkavy@gmail.com", + "url": "https://github.com/defaultkavy" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/defaultkavy/fluentx.git" + }, + "module": "index.ts", + "bugs": { + "url": "https://github.com/defaultkavy/fluentx/issues" + }, + "description": "Fast, fluent, simple web builder", + "homepage": "https://github.com/defaultkavy/fluentx", + "keywords": ["web", "front-end", "lib", "fluent", "framework"], + "license": "ISC", + "type": "module", + "workspaces": [ + "extensions/*" + ] } \ No newline at end of file