@thi.ng/rdom 0.12.22 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-11-09T10:28:19Z
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,14 @@ 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
+
12
20
  ### [0.12.21](https://github.com/thi-ng/umbrella/tree/@thi.ng/rdom@0.12.21) (2023-11-09)
13
21
 
14
22
  #### ♻️ Refactoring
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: 4.07 KB
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, if given value has a {@link IComponent.mount} function.
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, if given value has a {@link IComponent.mount} function.
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 { $sub, $SubA } from "./sub.js";
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
- : $wrapText("span", null, tree);
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/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) => void;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rdom",
3
- "version": "0.12.22",
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",
@@ -40,7 +40,7 @@
40
40
  "@thi.ng/hiccup": "^5.0.7",
41
41
  "@thi.ng/paths": "^5.1.49",
42
42
  "@thi.ng/prefixes": "^2.2.4",
43
- "@thi.ng/rstream": "^8.2.9",
43
+ "@thi.ng/rstream": "^8.2.10",
44
44
  "@thi.ng/strings": "^3.6.6"
45
45
  },
46
46
  "devDependencies": {
@@ -141,5 +141,5 @@
141
141
  ],
142
142
  "year": 2020
143
143
  },
144
- "gitHead": "669a3151e4302480244fe3e60eff5e732ea5b7a7\n"
144
+ "gitHead": "2be4c38c9680da929339bd164acfb69ebb1fd3d0\n"
145
145
  }
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
+ });