amateras 0.4.1 → 0.5.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/README.md +7 -5
- package/ext/html/node/$Anchor.ts +1 -1
- package/ext/html/node/$Input.ts +26 -2
- package/ext/html/node/$Label.ts +10 -1
- package/ext/i18n/src/structure/I18nDictionary.ts +2 -2
- package/ext/idb/README.md +127 -0
- package/ext/idb/package.json +13 -0
- package/ext/idb/src/core.ts +6 -0
- package/ext/idb/src/index.ts +17 -0
- package/ext/idb/src/lib/$IDBRequest.ts +8 -0
- package/ext/idb/src/structure/$IDB.ts +63 -0
- package/ext/idb/src/structure/$IDBCursor.ts +34 -0
- package/ext/idb/src/structure/$IDBIndex.ts +48 -0
- package/ext/idb/src/structure/$IDBStore.ts +103 -0
- package/ext/idb/src/structure/$IDBStoreBase.ts +30 -0
- package/ext/idb/src/structure/$IDBTransaction.ts +38 -0
- package/ext/idb/src/structure/builder/$IDBBuilder.ts +230 -0
- package/ext/idb/src/structure/builder/$IDBStoreBuilder.ts +100 -0
- package/ext/markdown/index.ts +121 -0
- package/ext/markdown/package.json +8 -0
- package/ext/router/index.ts +1 -1
- package/ext/router/node/Route.ts +2 -2
- package/ext/router/node/RouterAnchor.ts +6 -1
- package/package.json +5 -2
- package/src/core.ts +5 -3
- package/src/global.ts +3 -0
- package/src/lib/native.ts +9 -4
- package/src/lib/sleep.ts +3 -1
- package/src/lib/toArray.ts +9 -0
- package/src/lib/trycatch.ts +17 -0
- package/src/node/$Element.ts +2 -14
- package/src/node/$Node.ts +21 -8
- package/src/structure/Signal.ts +2 -2
package/src/node/$Node.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { chain } from "#lib/chain";
|
|
2
2
|
import { _document } from "#lib/env";
|
|
3
|
-
import { _Array_from, _instanceof, _JSON_stringify, forEach, isFunction, isNull, isObject, isUndefined } from "#lib/native";
|
|
3
|
+
import { _Array_from, _instanceof, _JSON_stringify, _null, _Promise, forEach, isBoolean, isFunction, isNull, isObject, isUndefined } from "#lib/native";
|
|
4
|
+
import { toArray } from "#lib/toArray";
|
|
4
5
|
import { Signal } from "#structure/Signal";
|
|
5
6
|
|
|
6
7
|
export class $Node {
|
|
@@ -12,15 +13,15 @@ export class $Node {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
content(children: $NodeContentResolver<this>) {
|
|
15
|
-
return chain(this,
|
|
16
|
-
forEach(this.childNodes, node => node.remove());
|
|
16
|
+
return chain(this, _null, _null, children, children => {
|
|
17
|
+
forEach(_Array_from(this.childNodes), node => node.remove());
|
|
17
18
|
this.insert(children);
|
|
18
19
|
})
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
insert(resolver: $NodeContentResolver<this>, position = -1) {
|
|
22
23
|
// process nodes
|
|
23
|
-
forEach(
|
|
24
|
+
forEach(toArray(resolver), resolve_child => forEach($Node.process(this, resolve_child), $node => $Node.append(this, $node, position)));
|
|
24
25
|
return this;
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -33,7 +34,7 @@ export class $Node {
|
|
|
33
34
|
replace($node: $NodeContentResolver<$Node>) {
|
|
34
35
|
if ($node)
|
|
35
36
|
this.replaceWith(
|
|
36
|
-
|
|
37
|
+
...toArray($Node.process(this, $node)).filter($node => $node).map($node => $node?.node) as Node[]
|
|
37
38
|
)
|
|
38
39
|
return this;
|
|
39
40
|
}
|
|
@@ -57,10 +58,22 @@ export class $Node {
|
|
|
57
58
|
return _instanceof(this, instance) ? this : null;
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
on(type: string, listener: any, options?: boolean | AddEventListenerOptions) {
|
|
62
|
+
return this.addEventListener(type, listener, options);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
off(type: string, listener: any, options?: boolean | EventListenerOptions) {
|
|
66
|
+
return this.removeEventListener(type, listener, options);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
once(type: string, listener: any, options?: boolean | AddEventListenerOptions) {
|
|
70
|
+
return this.on(type, listener, { once: true, ...(isBoolean(options) ? {capture: options} : options ?? {}) })
|
|
71
|
+
}
|
|
72
|
+
|
|
60
73
|
static process<T extends $Node>($node: T, content: $NodeContentResolver<any>): Array<$Node | undefined | null> {
|
|
61
74
|
if (isUndefined(content) || isNull(content) || _instanceof(content, $Node)) return [content];
|
|
62
75
|
// is Promise
|
|
63
|
-
if (_instanceof(content,
|
|
76
|
+
if (_instanceof(content, _Promise)) return [$('async').await(content, ($async, $child) => $async.replace($child as any))];
|
|
64
77
|
// is SignalFunction or ContentHandler
|
|
65
78
|
if (isFunction(content)) {
|
|
66
79
|
const signal = (content as any).signal;
|
|
@@ -86,8 +99,8 @@ export class $Node {
|
|
|
86
99
|
}
|
|
87
100
|
} else {
|
|
88
101
|
const _content = content($node) as $NodeContentResolver<$Node>;
|
|
89
|
-
if (_instanceof(_content,
|
|
90
|
-
else return
|
|
102
|
+
if (_instanceof(_content, _Promise)) return this.process($node, _content as any);
|
|
103
|
+
else return toArray(_content).map(content => this.process($node, content)).flat();
|
|
91
104
|
}
|
|
92
105
|
}
|
|
93
106
|
// is nested array
|
package/src/structure/Signal.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _instanceof, forEach, isUndefined } from "#lib/native";
|
|
1
|
+
import { _instanceof, forEach, isFunction, isUndefined } from "#lib/native";
|
|
2
2
|
|
|
3
3
|
export class Signal<T> {
|
|
4
4
|
#value: T;
|
|
@@ -16,7 +16,7 @@ export class Signal<T> {
|
|
|
16
16
|
forEach(Signal.listeners, fn => fn(this));
|
|
17
17
|
return this.#value;
|
|
18
18
|
}
|
|
19
|
-
if (
|
|
19
|
+
if (isFunction(resolver)) this.value(resolver(this.#value));
|
|
20
20
|
else if (!isUndefined(resolver)) {
|
|
21
21
|
this.#value = resolver;
|
|
22
22
|
this.emit();
|