@thi.ng/rdom 0.12.20 → 0.13.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/CHANGELOG.md +15 -1
- package/README.md +3 -1
- package/checks.d.ts +7 -1
- package/checks.js +7 -1
- package/compile.d.ts +2 -1
- package/compile.js +9 -6
- package/component.js +1 -0
- package/dom.d.ts +1 -1
- package/dom.js +1 -0
- package/klist.js +6 -1
- package/list.js +6 -0
- package/object.js +3 -0
- package/package.json +15 -16
- package/promise.js +3 -0
- package/replace.js +3 -0
- package/scheduler.js +2 -0
- package/sub.js +5 -1
- package/switch.js +8 -0
- package/wrap.d.ts +8 -1
- package/wrap.js +18 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-11-
|
|
3
|
+
- **Last updated**: 2023-11-12T16:43:31Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,20 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [0.13.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rdom@0.13.0) (2023-11-12)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add $wrapEl() DOM element component wrapper ([298e9a1](https://github.com/thi-ng/umbrella/commit/298e9a1))
|
|
17
|
+
- update $compile() to support existing DOM elements ([859521a](https://github.com/thi-ng/umbrella/commit/859521a))
|
|
18
|
+
- update $attribs() to return element ([1f82021](https://github.com/thi-ng/umbrella/commit/1f82021))
|
|
19
|
+
|
|
20
|
+
### [0.12.21](https://github.com/thi-ng/umbrella/tree/@thi.ng/rdom@0.12.21) (2023-11-09)
|
|
21
|
+
|
|
22
|
+
#### ♻️ Refactoring
|
|
23
|
+
|
|
24
|
+
- update all tests (packages A-S) ([e3085e4](https://github.com/thi-ng/umbrella/commit/e3085e4))
|
|
25
|
+
|
|
12
26
|
### [0.12.13](https://github.com/thi-ng/umbrella/tree/@thi.ng/rdom@0.12.13) (2023-10-18)
|
|
13
27
|
|
|
14
28
|
#### 🩹 Bug fixes
|
package/README.md
CHANGED
|
@@ -278,7 +278,7 @@ For Node.js REPL:
|
|
|
278
278
|
const rdom = await import("@thi.ng/rdom");
|
|
279
279
|
```
|
|
280
280
|
|
|
281
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
281
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 4.12 KB
|
|
282
282
|
|
|
283
283
|
## Dependencies
|
|
284
284
|
|
|
@@ -309,8 +309,10 @@ directory are using this package:
|
|
|
309
309
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/lispy-repl.png" width="240"/> | Browser REPL for a Lispy S-expression based mini language | [Demo](https://demo.thi.ng/umbrella/lispy-repl/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/lispy-repl) |
|
|
310
310
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/mastodon-feed.jpg" width="240"/> | Mastodon API feed reader with support for different media types, fullscreen media modal, HTML rewriting | [Demo](https://demo.thi.ng/umbrella/mastodon-feed/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/mastodon-feed) |
|
|
311
311
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/parse-playground.png" width="240"/> | Parser grammar livecoding editor/playground & codegen | [Demo](https://demo.thi.ng/umbrella/parse-playground/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/parse-playground) |
|
|
312
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-colormatrix.jpg" width="240"/> | Matrix-based image color adjustments | [Demo](https://demo.thi.ng/umbrella/pixel-colormatrix/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pixel-colormatrix) |
|
|
312
313
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-gradients.jpg" width="240"/> | Randomized 4-point 2D color gradient image generator | [Demo](https://demo.thi.ng/umbrella/pixel-gradients/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pixel-gradients) |
|
|
313
314
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-sorting.png" width="240"/> | Interactive pixel sorting tool using thi.ng/color & thi.ng/pixel | [Demo](https://demo.thi.ng/umbrella/pixel-sorting/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pixel-sorting) |
|
|
315
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-waveform.jpg" width="240"/> | RGB waveform image analysis | [Demo](https://demo.thi.ng/umbrella/pixel-waveform/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pixel-waveform) |
|
|
314
316
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pointfree-geom.jpg" width="240"/> | Live coding playground for 2D geometry generation using @thi.ng/pointfree-lang | [Demo](https://demo.thi.ng/umbrella/pointfree-geom/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pointfree-geom) |
|
|
315
317
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/poly-subdiv.jpg" width="240"/> | Animated, iterative polygon subdivisions & visualization | [Demo](https://demo.thi.ng/umbrella/poly-subdiv/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/poly-subdiv) |
|
|
316
318
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/procedural-text.jpg" width="240"/> | Procedural stochastic text generation via custom DSL, parse grammar & AST transformation | [Demo](https://demo.thi.ng/umbrella/procedural-text/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/procedural-text) |
|
package/checks.d.ts
CHANGED
|
@@ -11,9 +11,15 @@ import type { IComponent } from "./api.js";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare const isComment: (tree: any[]) => boolean;
|
|
13
13
|
/**
|
|
14
|
-
* Returns true
|
|
14
|
+
* Returns true if given value has a {@link IComponent.mount} function.
|
|
15
15
|
*
|
|
16
16
|
* @param x
|
|
17
17
|
*/
|
|
18
18
|
export declare const isComponent: (x: any) => x is IComponent<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Returns true if given value is a DOM element.
|
|
21
|
+
*
|
|
22
|
+
* @param x
|
|
23
|
+
*/
|
|
24
|
+
export declare const isElement: (x: any) => x is Element;
|
|
19
25
|
//# sourceMappingURL=checks.d.ts.map
|
package/checks.js
CHANGED
|
@@ -12,8 +12,14 @@ import { COMMENT } from "@thi.ng/hiccup/api";
|
|
|
12
12
|
*/
|
|
13
13
|
export const isComment = (tree) => tree[0] === COMMENT;
|
|
14
14
|
/**
|
|
15
|
-
* Returns true
|
|
15
|
+
* Returns true if given value has a {@link IComponent.mount} function.
|
|
16
16
|
*
|
|
17
17
|
* @param x
|
|
18
18
|
*/
|
|
19
19
|
export const isComponent = (x) => implementsFunction(x, "mount");
|
|
20
|
+
/**
|
|
21
|
+
* Returns true if given value is a DOM element.
|
|
22
|
+
*
|
|
23
|
+
* @param x
|
|
24
|
+
*/
|
|
25
|
+
export const isElement = (x) => x instanceof Element;
|
package/compile.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ import type { IComponent } from "./api.js";
|
|
|
4
4
|
* state values into a single, nested {@link IComponent}.
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
7
|
-
* Supported formats:
|
|
7
|
+
* Supported formats/values:
|
|
8
8
|
*
|
|
9
9
|
* - hiccup component trees, i.e. `["tag#id.class", attribs, [...]]`
|
|
10
10
|
* - {@link IComponent} instances
|
|
11
|
+
* - pre-existing DOM elements
|
|
11
12
|
* - [`ISubscribable`](https://docs.thi.ng/umbrella/rstream/interfaces/ISubscribable.html)
|
|
12
13
|
* instances
|
|
13
14
|
* - [`IDeref`](https://docs.thi.ng/umbrella/api/interfaces/IDeref.html)
|
package/compile.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { isArray } from "@thi.ng/checks/is-array";
|
|
2
2
|
import { isPlainObject } from "@thi.ng/checks/is-plain-object";
|
|
3
3
|
import { isSubscribable } from "@thi.ng/rstream/checks";
|
|
4
|
-
import { isComponent } from "./checks.js";
|
|
4
|
+
import { isComponent, isElement } from "./checks.js";
|
|
5
5
|
import { $el, $remove, $tree } from "./dom.js";
|
|
6
6
|
import { SCHEDULER } from "./scheduler.js";
|
|
7
|
-
import { $
|
|
8
|
-
import { $wrapText } from "./wrap.js";
|
|
7
|
+
import { $SubA, $sub } from "./sub.js";
|
|
8
|
+
import { $wrapEl, $wrapText } from "./wrap.js";
|
|
9
9
|
/**
|
|
10
10
|
* Compiles a tree of components given in any supported format incl. reactive
|
|
11
11
|
* state values into a single, nested {@link IComponent}.
|
|
12
12
|
*
|
|
13
13
|
* @remarks
|
|
14
|
-
* Supported formats:
|
|
14
|
+
* Supported formats/values:
|
|
15
15
|
*
|
|
16
16
|
* - hiccup component trees, i.e. `["tag#id.class", attribs, [...]]`
|
|
17
17
|
* - {@link IComponent} instances
|
|
18
|
+
* - pre-existing DOM elements
|
|
18
19
|
* - [`ISubscribable`](https://docs.thi.ng/umbrella/rstream/interfaces/ISubscribable.html)
|
|
19
20
|
* instances
|
|
20
21
|
* - [`IDeref`](https://docs.thi.ng/umbrella/api/interfaces/IDeref.html)
|
|
@@ -36,7 +37,9 @@ export const $compile = (tree) => isArray(tree)
|
|
|
36
37
|
? tree
|
|
37
38
|
: isSubscribable(tree)
|
|
38
39
|
? $sub(tree, "span")
|
|
39
|
-
:
|
|
40
|
+
: tree instanceof Element
|
|
41
|
+
? $wrapEl(tree)
|
|
42
|
+
: $wrapText("span", null, tree);
|
|
40
43
|
const walk = (f, x, path = []) => {
|
|
41
44
|
if (isPlainObject(x)) {
|
|
42
45
|
for (const k in x) {
|
|
@@ -58,7 +61,7 @@ const isComplexComponent = (x) => {
|
|
|
58
61
|
return true;
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
|
-
return isSubscribable(x) || isComponent(x);
|
|
64
|
+
return isSubscribable(x) || isComponent(x) || isElement(x);
|
|
62
65
|
};
|
|
63
66
|
const complexComponent = (tree) => ({
|
|
64
67
|
async mount(parent, index = -1) {
|
package/component.js
CHANGED
package/dom.d.ts
CHANGED
|
@@ -145,7 +145,7 @@ export declare const $html: (el: HTMLElement | SVGElement, body: MaybeDeref<stri
|
|
|
145
145
|
* @param el -
|
|
146
146
|
* @param attribs -
|
|
147
147
|
*/
|
|
148
|
-
export declare const $attribs: (el: Element, attribs: any) =>
|
|
148
|
+
export declare const $attribs: (el: Element, attribs: any) => Element;
|
|
149
149
|
/**
|
|
150
150
|
* Takes an object (or string) of CSS properties, compiles them into a single
|
|
151
151
|
* CSS string and sets it as `style` attribute on the given element.
|
package/dom.js
CHANGED
|
@@ -253,6 +253,7 @@ export const $attribs = (el, attribs) => {
|
|
|
253
253
|
for (let id in attribs) {
|
|
254
254
|
setAttrib(el, id, attribs[id], attribs);
|
|
255
255
|
}
|
|
256
|
+
return el;
|
|
256
257
|
};
|
|
257
258
|
const setAttrib = (el, id, val, attribs) => {
|
|
258
259
|
implementsFunction(val, "deref") && (val = val.deref());
|
package/klist.js
CHANGED
|
@@ -57,13 +57,18 @@ import { $subWithID } from "./sub.js";
|
|
|
57
57
|
*/
|
|
58
58
|
export const $klist = (src, tag, attribs, childCtor, keyFn) => $subWithID(src, new KList(tag, attribs, childCtor, keyFn), __nextID("klist", src));
|
|
59
59
|
export class KList extends Component {
|
|
60
|
+
tag;
|
|
61
|
+
attribs;
|
|
62
|
+
ctor;
|
|
63
|
+
keyFn;
|
|
64
|
+
items = [];
|
|
65
|
+
cache;
|
|
60
66
|
constructor(tag, attribs, ctor, keyFn = (_, i) => i) {
|
|
61
67
|
super();
|
|
62
68
|
this.tag = tag;
|
|
63
69
|
this.attribs = attribs;
|
|
64
70
|
this.ctor = ctor;
|
|
65
71
|
this.keyFn = keyFn;
|
|
66
|
-
this.items = [];
|
|
67
72
|
}
|
|
68
73
|
async mount(parent, index, state) {
|
|
69
74
|
this.items = [];
|
package/list.js
CHANGED
|
@@ -51,6 +51,12 @@ import { $subWithID } from "./sub.js";
|
|
|
51
51
|
*/
|
|
52
52
|
export const $list = (src, tag, attribs, ctor, equiv) => $subWithID(src, new List(tag, attribs, ctor, equiv), __nextID("list", src));
|
|
53
53
|
export class List extends Component {
|
|
54
|
+
tag;
|
|
55
|
+
attribs;
|
|
56
|
+
ctor;
|
|
57
|
+
equiv;
|
|
58
|
+
prev;
|
|
59
|
+
items;
|
|
54
60
|
constructor(tag, attribs, ctor, equiv = (a, b) => a === b) {
|
|
55
61
|
super();
|
|
56
62
|
this.tag = tag;
|
package/object.js
CHANGED
|
@@ -76,6 +76,9 @@ export const $object = (src, opts, inner) => new $Object(src, opts, inner);
|
|
|
76
76
|
*/
|
|
77
77
|
export const $subObject = (src, opts, inner) => $subWithID(src, $object(src.deref() || {}, opts, inner), __nextID("obj", src));
|
|
78
78
|
export class $Object extends Component {
|
|
79
|
+
ctor;
|
|
80
|
+
obj;
|
|
81
|
+
inner;
|
|
79
82
|
constructor(src, opts, ctor) {
|
|
80
83
|
super();
|
|
81
84
|
this.ctor = ctor;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/rdom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Lightweight, reactive, VDOM-less UI/DOM components with async lifecycle and @thi.ng/hiccup compatible",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -28,28 +28,27 @@
|
|
|
28
28
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
29
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
30
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
31
|
-
"doc:readme": "
|
|
32
|
-
"doc:stats": "tools:module-stats",
|
|
31
|
+
"doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
|
|
33
32
|
"pub": "yarn npm publish --access public",
|
|
34
33
|
"pub:wip": "yarn npm publish --access public --no-git-tag-version",
|
|
35
|
-
"test": "
|
|
34
|
+
"test": "bun test"
|
|
36
35
|
},
|
|
37
36
|
"dependencies": {
|
|
38
|
-
"@thi.ng/api": "^8.9.
|
|
39
|
-
"@thi.ng/checks": "^3.4.
|
|
40
|
-
"@thi.ng/errors": "^2.4.
|
|
41
|
-
"@thi.ng/hiccup": "^5.0.
|
|
42
|
-
"@thi.ng/paths": "^5.1.
|
|
43
|
-
"@thi.ng/prefixes": "^2.2.
|
|
44
|
-
"@thi.ng/rstream": "^8.2.
|
|
45
|
-
"@thi.ng/strings": "^3.6.
|
|
37
|
+
"@thi.ng/api": "^8.9.8",
|
|
38
|
+
"@thi.ng/checks": "^3.4.8",
|
|
39
|
+
"@thi.ng/errors": "^2.4.2",
|
|
40
|
+
"@thi.ng/hiccup": "^5.0.7",
|
|
41
|
+
"@thi.ng/paths": "^5.1.49",
|
|
42
|
+
"@thi.ng/prefixes": "^2.2.4",
|
|
43
|
+
"@thi.ng/rstream": "^8.2.10",
|
|
44
|
+
"@thi.ng/strings": "^3.6.6"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
|
-
"@microsoft/api-extractor": "^7.38.
|
|
49
|
-
"@thi.ng/testament": "^0.
|
|
47
|
+
"@microsoft/api-extractor": "^7.38.2",
|
|
48
|
+
"@thi.ng/testament": "^0.4.1",
|
|
50
49
|
"rimraf": "^5.0.5",
|
|
51
50
|
"tools": "^0.0.1",
|
|
52
|
-
"typedoc": "^0.25.
|
|
51
|
+
"typedoc": "^0.25.3",
|
|
53
52
|
"typescript": "^5.2.2"
|
|
54
53
|
},
|
|
55
54
|
"keywords": [
|
|
@@ -142,5 +141,5 @@
|
|
|
142
141
|
],
|
|
143
142
|
"year": 2020
|
|
144
143
|
},
|
|
145
|
-
"gitHead": "
|
|
144
|
+
"gitHead": "2be4c38c9680da929339bd164acfb69ebb1fd3d0\n"
|
|
146
145
|
}
|
package/promise.js
CHANGED
|
@@ -18,6 +18,9 @@ import { Component } from "./component.js";
|
|
|
18
18
|
*/
|
|
19
19
|
export const $promise = (prom, error) => new $Promise(prom, error);
|
|
20
20
|
export class $Promise extends Component {
|
|
21
|
+
promise;
|
|
22
|
+
error;
|
|
23
|
+
inner;
|
|
21
24
|
constructor(promise, error = (e) => e) {
|
|
22
25
|
super();
|
|
23
26
|
this.promise = promise;
|
package/replace.js
CHANGED
|
@@ -37,6 +37,9 @@ import { $wrapText } from "./wrap.js";
|
|
|
37
37
|
*/
|
|
38
38
|
export const $replace = (src) => $subWithID(src, new Replace(), __nextID("replace", src));
|
|
39
39
|
export class Replace extends Component {
|
|
40
|
+
parent;
|
|
41
|
+
inner;
|
|
42
|
+
index;
|
|
40
43
|
async mount(parent, index, val) {
|
|
41
44
|
this.parent = parent;
|
|
42
45
|
this.index = index;
|
package/scheduler.js
CHANGED
package/sub.js
CHANGED
|
@@ -19,6 +19,8 @@ export function $sub(src, tag, attribs) {
|
|
|
19
19
|
*/
|
|
20
20
|
export const $subWithID = (src, inner, id) => src.subscribe(new $Sub(inner, id));
|
|
21
21
|
export class $Sub extends Subscription {
|
|
22
|
+
inner;
|
|
23
|
+
el;
|
|
22
24
|
constructor(inner, id) {
|
|
23
25
|
super(undefined, { id: id || `rdom$sub-${__nextID()}` });
|
|
24
26
|
this.inner = inner;
|
|
@@ -40,10 +42,12 @@ export class $Sub extends Subscription {
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
export class $SubA extends Subscription {
|
|
45
|
+
comp;
|
|
46
|
+
setter;
|
|
47
|
+
attr = {};
|
|
43
48
|
constructor(comp, path, id) {
|
|
44
49
|
super(undefined, { id: id || `rdom$attr-${__nextID()}` });
|
|
45
50
|
this.comp = comp;
|
|
46
|
-
this.attr = {};
|
|
47
51
|
this.setter = defSetterUnsafe(path);
|
|
48
52
|
}
|
|
49
53
|
next(a) {
|
package/switch.js
CHANGED
|
@@ -83,6 +83,14 @@ export const $switch = (src, keyFn, ctors, error, loader) => $subWithID(src, new
|
|
|
83
83
|
*/
|
|
84
84
|
export const $refresh = (src, ctor, error, loader) => $subWithID(src, new Switch(() => 0, { 0: ctor }, error, loader), __nextID("refresh", src));
|
|
85
85
|
export class Switch extends Component {
|
|
86
|
+
keyFn;
|
|
87
|
+
ctors;
|
|
88
|
+
error;
|
|
89
|
+
loader;
|
|
90
|
+
val;
|
|
91
|
+
parent;
|
|
92
|
+
inner;
|
|
93
|
+
index;
|
|
86
94
|
constructor(keyFn, ctors, error = async (e) => $wrapText("span", {}, e), loader = async () => $wrapText("span", {
|
|
87
95
|
hidden: true,
|
|
88
96
|
})) {
|
package/wrap.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IMountWithState } from "./api.js";
|
|
1
|
+
import type { IComponent, IMountWithState } from "./api.js";
|
|
2
2
|
/**
|
|
3
3
|
* Returns a component wrapper for a single DOM element whose TEXT body can be
|
|
4
4
|
* later updated/replaced via `.update()`, similarly to setting `.innerText`.
|
|
@@ -17,4 +17,11 @@ export declare const $wrapText: (tag: string, attribs?: any, body?: any) => IMou
|
|
|
17
17
|
* @param body - optional initial body
|
|
18
18
|
*/
|
|
19
19
|
export declare const $wrapHtml: (tag: string, attribs?: any, body?: import("@thi.ng/api").MaybeDeref<string> | undefined) => IMountWithState<import("@thi.ng/api").MaybeDeref<string>>;
|
|
20
|
+
/**
|
|
21
|
+
* {@link IComponent} wrapper for an existing DOM element. When mounted, the
|
|
22
|
+
* given element will be (re)attached to the parent node provided at that time.
|
|
23
|
+
*
|
|
24
|
+
* @param el
|
|
25
|
+
*/
|
|
26
|
+
export declare const $wrapEl: (el: Element) => IComponent;
|
|
20
27
|
//# sourceMappingURL=wrap.d.ts.map
|
package/wrap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $el, $html, $remove, $text } from "./dom.js";
|
|
1
|
+
import { $addChild, $el, $html, $remove, $text } from "./dom.js";
|
|
2
2
|
import { SCHEDULER } from "./scheduler.js";
|
|
3
3
|
const wrapper = (update) => (tag, attribs, body) => ({
|
|
4
4
|
el: undefined,
|
|
@@ -33,3 +33,20 @@ export const $wrapText = wrapper($text);
|
|
|
33
33
|
* @param body - optional initial body
|
|
34
34
|
*/
|
|
35
35
|
export const $wrapHtml = wrapper($html);
|
|
36
|
+
/**
|
|
37
|
+
* {@link IComponent} wrapper for an existing DOM element. When mounted, the
|
|
38
|
+
* given element will be (re)attached to the parent node provided at that time.
|
|
39
|
+
*
|
|
40
|
+
* @param el
|
|
41
|
+
*/
|
|
42
|
+
export const $wrapEl = (el) => ({
|
|
43
|
+
async mount(parent, idx) {
|
|
44
|
+
$addChild(parent, el, idx);
|
|
45
|
+
return (this.el = el);
|
|
46
|
+
},
|
|
47
|
+
async unmount() {
|
|
48
|
+
$remove(this.el);
|
|
49
|
+
this.el = undefined;
|
|
50
|
+
},
|
|
51
|
+
update() { },
|
|
52
|
+
});
|