v0.0.9
revert: $Node.parent
This commit is contained in:
parent
ec62a580b6
commit
d28953d354
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
extensions
|
||||||
|
.npmignore
|
||||||
|
bun.lockb
|
||||||
|
node_modules
|
@ -3,39 +3,41 @@ import { $Node } from "./node/$Node";
|
|||||||
import { $Text } from "./node/$Text";
|
import { $Text } from "./node/$Text";
|
||||||
|
|
||||||
export class $NodeManager {
|
export class $NodeManager {
|
||||||
#container: $Container;
|
$container: $Container;
|
||||||
elementList = new Set<$Node>
|
$elementList = new Set<$Node>
|
||||||
constructor(container: $Container) {
|
constructor(container: $Container) {
|
||||||
this.#container = container;
|
this.$container = container;
|
||||||
}
|
}
|
||||||
|
|
||||||
add(element: $Node | string) {
|
add(element: $Node | string) {
|
||||||
if (typeof element === 'string') {
|
if (typeof element === 'string') {
|
||||||
const text = new $Text(element);
|
const text = new $Text(element);
|
||||||
this.elementList.add(text);
|
this.$elementList.add(text);
|
||||||
|
(text as Mutable<$Node>).parent = this.$container;
|
||||||
} else {
|
} else {
|
||||||
this.elementList.add(element);
|
this.$elementList.add(element);
|
||||||
|
(element as Mutable<$Node>).parent = this.$container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(element: $Node) {
|
remove(element: $Node) {
|
||||||
if (!this.elementList.has(element)) return this;
|
if (!this.$elementList.has(element)) return this;
|
||||||
this.elementList.delete(element);
|
this.$elementList.delete(element);
|
||||||
|
(element as Mutable<$Node>).parent = undefined;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeAll(render = true) {
|
removeAll(render = true) {
|
||||||
this.elementList.forEach(ele => this.remove(ele));
|
this.$elementList.forEach(ele => this.remove(ele));
|
||||||
if (render) this.render();
|
if (render) this.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
replace(target: $Node, replace: $Node) {
|
replace(target: $Node, replace: $Node) {
|
||||||
const array = this.array.map(node => {
|
const array = this.array
|
||||||
if (node === target) return replace;
|
array.splice(array.indexOf(target), 1, replace);
|
||||||
else return node;
|
target.remove();
|
||||||
})
|
this.$elementList.clear();
|
||||||
this.elementList.clear();
|
array.forEach(node => this.$elementList.add(node));
|
||||||
array.forEach(node => this.elementList.add(node));
|
|
||||||
return this;
|
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}
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
import { $State } from "./$State";
|
import { $State } from "./$State";
|
||||||
import { $AsyncNode } from "./node/$AsyncNode";
|
|
||||||
import { $Container } from "./node/$Container";
|
import { $Container } from "./node/$Container";
|
||||||
import { $Document } from "./node/$Document";
|
import { $Document } from "./node/$Document";
|
||||||
import { $Node } from "./node/$Node";
|
import { $Node } from "./node/$Node";
|
||||||
|
@ -5,6 +5,7 @@ export abstract class $Node<N extends Node = Node> {
|
|||||||
abstract readonly dom: N;
|
abstract readonly dom: N;
|
||||||
readonly __hidden: boolean = false;
|
readonly __hidden: boolean = false;
|
||||||
private domEvents: {[key: string]: Map<Function, Function>} = {};
|
private domEvents: {[key: string]: Map<Function, Function>} = {};
|
||||||
|
readonly parent?: $Container;
|
||||||
|
|
||||||
on<K extends keyof HTMLElementEventMap>(type: K, callback: (event: HTMLElementEventMap[K], $node: this) => any, options?: AddEventListenerOptions | boolean) {
|
on<K extends keyof HTMLElementEventMap>(type: K, callback: (event: HTMLElementEventMap[K], $node: this) => any, options?: AddEventListenerOptions | boolean) {
|
||||||
if (!this.domEvents[type]) this.domEvents[type] = new Map()
|
if (!this.domEvents[type]) this.domEvents[type] = new Map()
|
||||||
@ -30,12 +31,12 @@ export abstract class $Node<N extends Node = Node> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hide(): boolean;
|
hide(): boolean;
|
||||||
hide(hide?: boolean | $State<boolean>): this;
|
hide(hide?: boolean | $State<boolean>, render?: boolean): this;
|
||||||
hide(hide?: boolean | $State<boolean>) { return $.fluent(this, arguments, () => this.__hidden, () => {
|
hide(hide?: boolean | $State<boolean>, render = true) { return $.fluent(this, arguments, () => this.__hidden, () => {
|
||||||
if (hide === undefined) return;
|
if (hide === undefined) return;
|
||||||
if (hide instanceof $State) { (this as Mutable<$Node>).__hidden = hide.value; hide.use(this, 'hide')}
|
if (hide instanceof $State) { (this as Mutable<$Node>).__hidden = hide.value; hide.use(this, 'hide')}
|
||||||
else (this as Mutable<$Node>).__hidden = hide;
|
else (this as Mutable<$Node>).__hidden = hide;
|
||||||
this.parent?.children.render();
|
if (render) this.parent?.children.render();
|
||||||
return this;
|
return this;
|
||||||
})}
|
})}
|
||||||
|
|
||||||
@ -64,8 +65,4 @@ export abstract class $Node<N extends Node = Node> {
|
|||||||
if (this instanceof $Element) return true;
|
if (this instanceof $Element) return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
get parent() {
|
|
||||||
return this.dom.parentElement?.$ as $Container | undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
43
package.json
43
package.json
@ -1,22 +1,25 @@
|
|||||||
{
|
{
|
||||||
"name": "fluentx",
|
"name": "fluentx",
|
||||||
"description": "Fast, fluent, simple web builder",
|
"version": "0.0.9",
|
||||||
"version": "0.0.9",
|
"author": {
|
||||||
"type": "module",
|
"name": "defaultkavy",
|
||||||
"module": "index.ts",
|
"email": "defaultkavy@gmail.com",
|
||||||
"author": {
|
"url": "https://github.com/defaultkavy"
|
||||||
"name": "defaultkavy",
|
},
|
||||||
"email": "defaultkavy@gmail.com",
|
"repository": {
|
||||||
"url": "https://github.com/defaultkavy"
|
"type": "git",
|
||||||
},
|
"url": "git+https://github.com/defaultkavy/fluentx.git"
|
||||||
"keywords": ["web", "front-end", "lib", "fluent", "framework"],
|
},
|
||||||
"homepage": "https://github.com/defaultkavy/fluentx",
|
"module": "index.ts",
|
||||||
"repository": {
|
"bugs": {
|
||||||
"type": "git",
|
"url": "https://github.com/defaultkavy/fluentx/issues"
|
||||||
"url": "git+https://github.com/defaultkavy/fluentx.git"
|
},
|
||||||
},
|
"description": "Fast, fluent, simple web builder",
|
||||||
"bugs": {
|
"homepage": "https://github.com/defaultkavy/fluentx",
|
||||||
"url": "https://github.com/defaultkavy/fluentx/issues"
|
"keywords": ["web", "front-end", "lib", "fluent", "framework"],
|
||||||
},
|
"license": "ISC",
|
||||||
"license": "ISC"
|
"type": "module",
|
||||||
|
"workspaces": [
|
||||||
|
"extensions/*"
|
||||||
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user