@thi.ng/rdom 1.3.3 → 1.4.1

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**: 2024-04-26T13:32:20Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
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,26 @@ 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
+ ### [1.4.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/rdom@1.4.1) (2024-06-21)
13
+
14
+ #### 🩹 Bug fixes
15
+
16
+ - fix [#469](https://github.com/thi-ng/umbrella/issues/469), update setAttrib() `class` handling ([6cf8c56](https://github.com/thi-ng/umbrella/commit/6cf8c56))
17
+ - use `el.setAttribute()` to be compatible w/ SVG elements
18
+ - https://developer.mozilla.org/en-US/docs/Web/API/Element/className#notes
19
+
20
+ #### ♻️ Refactoring
21
+
22
+ - rename various rest args to be more semantically meaningful ([8088a56](https://github.com/thi-ng/umbrella/commit/8088a56))
23
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
24
+
25
+ ## [1.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rdom@1.4.0) (2024-05-08)
26
+
27
+ #### 🚀 Features
28
+
29
+ - add rdom-klist example project, update readmes ([cd458ac](https://github.com/thi-ng/umbrella/commit/cd458ac))
30
+ - add rdom-klist example project, update readmes ([531437f](https://github.com/thi-ng/umbrella/commit/531437f))
31
+
12
32
  ### [1.3.3](https://github.com/thi-ng/umbrella/tree/@thi.ng/rdom@1.3.3) (2024-04-26)
13
33
 
14
34
  #### 🩹 Bug fixes
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -315,7 +315,7 @@ Browser ESM import:
315
315
 
316
316
  [JSDelivr documentation](https://www.jsdelivr.com/)
317
317
 
318
- Package sizes (brotli'd, pre-treeshake): ESM: 4.24 KB
318
+ Package sizes (brotli'd, pre-treeshake): ESM: 4.23 KB
319
319
 
320
320
  ## Dependencies
321
321
 
@@ -362,8 +362,10 @@ directory are using this package:
362
362
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-dnd.png" width="240"/> | rdom drag & drop example | [Demo](https://demo.thi.ng/umbrella/rdom-dnd/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-dnd) |
363
363
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-formgen.jpg" width="240"/> | Basic usage of the declarative rdom-forms generator | [Demo](https://demo.thi.ng/umbrella/rdom-formgen/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-formgen) |
364
364
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-key-sequences.jpg" width="240"/> | rstream & transducer-based FSM for converting key event sequences into high-level commands | [Demo](https://demo.thi.ng/umbrella/rdom-key-sequences/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-key-sequences) |
365
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-klist.png" width="240"/> | Basic usage of thi.ng/rdom keyed list component wrapper | [Demo](https://demo.thi.ng/umbrella/rdom-klist/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-klist) |
365
366
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-lazy-load.png" width="240"/> | Lazy loading components via @thi.ng/rdom | [Demo](https://demo.thi.ng/umbrella/rdom-lazy-load/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-lazy-load) |
366
367
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-lissajous.png" width="240"/> | rdom & hiccup-canvas interop test | [Demo](https://demo.thi.ng/umbrella/rdom-lissajous/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-lissajous) |
368
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-reactive-svg.jpg" width="240"/> | Animated SVG elements with reactive attributes | [Demo](https://demo.thi.ng/umbrella/rdom-reactive-svg/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-reactive-svg) |
367
369
  | | Full umbrella repo doc string search w/ paginated results | [Demo](https://demo.thi.ng/umbrella/rdom-search-docs/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-search-docs) |
368
370
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-svg-nodes.png" width="240"/> | rdom powered SVG graph with draggable nodes | [Demo](https://demo.thi.ng/umbrella/rdom-svg-nodes/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-svg-nodes) |
369
371
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-web-components.png" width="240"/> | Defining & using basic Web Components (with shadow DOM) via @thi.ng/rdom & @thi.ng/meta-css | [Demo](https://demo.thi.ng/umbrella/rdom-web-components/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-web-components) |
package/api.d.ts CHANGED
@@ -32,9 +32,9 @@ export interface IComponent<T = any> {
32
32
  *
33
33
  * @param parent -
34
34
  * @param idx -
35
- * @param xs -
35
+ * @param args -
36
36
  */
37
- mount(parent: ParentNode, idx?: NumOrElement, ...xs: any[]): Promise<Element>;
37
+ mount(parent: ParentNode, idx?: NumOrElement, ...args: any[]): Promise<Element>;
38
38
  /**
39
39
  * Async component lifecycle method to remove the component from the
40
40
  * target DOM and release any other internal resources (e.g.
package/async.js CHANGED
@@ -15,8 +15,7 @@ class $Async {
15
15
  this.el = await this.inner.mount(parent, index, void 0);
16
16
  (async () => {
17
17
  for await (let x of this.src) {
18
- if (!this.el)
19
- return;
18
+ if (!this.el) return;
20
19
  this.update(x);
21
20
  }
22
21
  })();
@@ -27,16 +26,14 @@ class $Async {
27
26
  await this.inner.unmount();
28
27
  }
29
28
  update(x) {
30
- if (this.el)
31
- this.inner.update(x);
29
+ if (this.el) this.inner.update(x);
32
30
  }
33
31
  }
34
32
  const $asyncA = async (src, comp, path) => {
35
33
  const attribs = {};
36
34
  const setter = defSetterUnsafe(path);
37
35
  for await (let x of src) {
38
- if (comp.el)
39
- $attribs(comp.el, setter(attribs, x));
36
+ if (comp.el) $attribs(comp.el, setter(attribs, x));
40
37
  }
41
38
  };
42
39
  export {
package/compile.js CHANGED
@@ -7,40 +7,37 @@ import { isComponent, isElement } from "./checks.js";
7
7
  import { $el, $remove, $tree } from "./dom.js";
8
8
  import { $SubA, $sub } from "./sub.js";
9
9
  import { $wrapEl, $wrapText } from "./wrap.js";
10
- const $compile = (tree) => isArray(tree) ? isComplexComponent(tree) ? complexComponent(tree) : basicComponent(tree) : isComponent(tree) ? tree : isSubscribable(tree) ? $sub(tree, "span") : isAsyncIterable(tree) ? $async(tree, "span") : tree instanceof Element ? $wrapEl(tree) : $wrapText("span", null, tree);
11
- const walk = (f, x, path = []) => {
10
+ const $compile = (tree) => isArray(tree) ? __isComplexComponent(tree) ? __complexComponent(tree) : __basicComponent(tree) : isComponent(tree) ? tree : isSubscribable(tree) ? $sub(tree, "span") : isAsyncIterable(tree) ? $async(tree, "span") : tree instanceof Element ? $wrapEl(tree) : $wrapText("span", null, tree);
11
+ const __walk = (f, x, path = []) => {
12
12
  if (isPlainObject(x)) {
13
13
  for (const k in x) {
14
- walk(f, x[k], [...path, k]);
14
+ __walk(f, x[k], [...path, k]);
15
15
  }
16
16
  }
17
17
  f(x, path);
18
18
  };
19
- const isComplexComponent = (x) => {
19
+ const __isComplexComponent = (x) => {
20
20
  if (isPlainObject(x)) {
21
21
  for (const k in x) {
22
- if (isComplexComponent(x[k]))
23
- return true;
22
+ if (__isComplexComponent(x[k])) return true;
24
23
  }
25
24
  } else if (isArray(x)) {
26
25
  for (let i = 0, n = x.length; i < n; i++) {
27
- if (isComplexComponent(x[i]))
28
- return true;
26
+ if (__isComplexComponent(x[i])) return true;
29
27
  }
30
28
  }
31
29
  return isSubscribable(x) || isAsyncIterable(x) || isComponent(x) || isElement(x);
32
30
  };
33
- const complexComponent = (tree) => ({
31
+ const __complexComponent = (tree) => ({
34
32
  async mount(parent, index = -1) {
35
33
  this.subs = [];
36
34
  const attribs = { ...tree[1] };
37
- walk((x, path) => {
35
+ __walk((x, path) => {
38
36
  if (isSubscribable(x)) {
39
37
  this.subs.push(x.subscribe(new $SubA(this, path)));
40
38
  } else if (isAsyncIterable(x)) {
41
39
  $asyncA(x, this, path);
42
- if (path.length === 1)
43
- delete attribs[path[0]];
40
+ if (path.length === 1) delete attribs[path[0]];
44
41
  }
45
42
  }, attribs);
46
43
  this.children = [];
@@ -65,7 +62,7 @@ const complexComponent = (tree) => ({
65
62
  update() {
66
63
  }
67
64
  });
68
- const basicComponent = (tree) => ({
65
+ const __basicComponent = (tree) => ({
69
66
  async mount(parent, index = -1) {
70
67
  return this.el = await $tree(tree, parent, index);
71
68
  },
package/component.d.ts CHANGED
@@ -7,7 +7,7 @@ import type { IComponent, NumOrElement } from "./api.js";
7
7
  */
8
8
  export declare abstract class Component<T = any> implements IComponent<T> {
9
9
  el?: Element;
10
- abstract mount(parent: ParentNode, index?: NumOrElement, ...xs: any[]): Promise<Element>;
10
+ abstract mount(parent: ParentNode, index?: NumOrElement, ...args: any[]): Promise<Element>;
11
11
  unmount(): Promise<void>;
12
12
  update(state?: T): void;
13
13
  /**
package/dom.js CHANGED
@@ -96,19 +96,19 @@ const $html = (el, body) => {
96
96
  };
97
97
  const $attribs = (el, attribs) => {
98
98
  for (let id in attribs) {
99
- setAttrib(el, id, attribs[id], attribs);
99
+ __setAttrib(el, id, attribs[id], attribs);
100
100
  }
101
101
  return el;
102
102
  };
103
103
  const __setterCache = {};
104
- const getproto = Object.getPrototypeOf;
105
- const getdesc = Object.getOwnPropertyDescriptor;
106
- const __desc = (proto, prop) => proto ? getdesc(proto, prop) ?? __desc(getproto(proto), prop) : void 0;
104
+ const __getProto = Object.getPrototypeOf;
105
+ const __getDesc = Object.getOwnPropertyDescriptor;
106
+ const __desc = (proto, prop) => proto ? __getDesc(proto, prop) ?? __desc(__getProto(proto), prop) : void 0;
107
107
  const __setter = (el, prop) => {
108
108
  const key = `${el.namespaceURI}/${el.tagName}#${prop}`;
109
- return __setterCache[key] ?? (__setterCache[key] = __desc(getproto(el), prop)?.set ?? false);
109
+ return __setterCache[key] ?? (__setterCache[key] = __desc(__getProto(el), prop)?.set ?? false);
110
110
  };
111
- const setAttrib = (el, id, val, attribs) => {
111
+ const __setAttrib = (el, id, val, attribs) => {
112
112
  implementsFunction(val, "deref") && (val = val.deref());
113
113
  if (id.startsWith("on")) {
114
114
  if (isString(val)) {
@@ -123,16 +123,19 @@ const setAttrib = (el, id, val, attribs) => {
123
123
  isArray(val) && (val = val.join(ATTRIB_JOIN_DELIMS[id] || " "));
124
124
  switch (id) {
125
125
  case "class":
126
- el.className = isString(val) ? val : mergeClasses(el.className, val);
126
+ el.setAttribute(
127
+ "class",
128
+ isString(val) ? val : mergeClasses(el.className, val)
129
+ );
127
130
  break;
128
131
  case "style":
129
132
  $style(el, val);
130
133
  break;
131
134
  case "value":
132
- updateValueAttrib(el, val);
135
+ __updateValueAttrib(el, val);
133
136
  break;
134
137
  case "data":
135
- updateDataAttribs(el, val);
138
+ __updateDataAttribs(el, val);
136
139
  break;
137
140
  case "prefix":
138
141
  el.setAttribute(id, isString(val) ? val : formatPrefixes(val));
@@ -152,7 +155,7 @@ const setAttrib = (el, id, val, attribs) => {
152
155
  }
153
156
  }
154
157
  };
155
- const updateValueAttrib = (el, value) => {
158
+ const __updateValueAttrib = (el, value) => {
156
159
  let ev;
157
160
  switch (el.type) {
158
161
  case "text":
@@ -172,7 +175,7 @@ const updateValueAttrib = (el, value) => {
172
175
  el.value = value;
173
176
  }
174
177
  };
175
- const updateDataAttribs = (el, attribs) => {
178
+ const __updateDataAttribs = (el, attribs) => {
176
179
  const data = el.dataset;
177
180
  for (let id in attribs) {
178
181
  const v = deref(attribs[id]);
package/klist.js CHANGED
@@ -32,8 +32,7 @@ class KList extends Component {
32
32
  this.cache = void 0;
33
33
  }
34
34
  async update(curr) {
35
- if (!curr)
36
- return;
35
+ if (!curr) return;
37
36
  const { keyFn, items, ctor, cache, el: parent } = this;
38
37
  const currItems = [];
39
38
  const currCache = /* @__PURE__ */ new Map();
package/list.js CHANGED
@@ -32,8 +32,7 @@ class List extends Component {
32
32
  this.prev = void 0;
33
33
  }
34
34
  async update(curr) {
35
- if (!curr)
36
- return;
35
+ if (!curr) return;
37
36
  const { ctor, equiv, items, prev, el: parent } = this;
38
37
  const nb = curr.length;
39
38
  let na = prev.length;
package/object.d.ts CHANGED
@@ -46,7 +46,7 @@ import { Component } from "./component.js";
46
46
  * @param opts - options for `fromObject()` stream setup
47
47
  * @param inner -
48
48
  */
49
- export declare const $object: <T extends object, K extends keyof T>(src: T, opts: Partial<StreamObjOpts<T, K>>, inner: Fn<StreamObj<T, K>["streams"], Promise<ComponentLike>>) => $Object<T, K>;
49
+ export declare const $object: <T extends object, K extends Keys<T>>(src: T, opts: Partial<StreamObjOpts<T, K>>, inner: Fn<StreamObj<T, K>["streams"], Promise<ComponentLike>>) => $Object<T, K>;
50
50
  /**
51
51
  * Syntax sugar for a combination of {@link $sub} and {@link $object} to allow
52
52
  * reactive updates of `$object()` components themselves.
@@ -79,7 +79,7 @@ export declare const $object: <T extends object, K extends keyof T>(src: T, opts
79
79
  * @param opts -
80
80
  * @param inner -
81
81
  */
82
- export declare const $subObject: <T extends object, K extends keyof T>(src: ISubscribable<T>, opts: Partial<StreamObjOpts<T, K>>, inner: Fn<StreamObj<T, K>["streams"], Promise<ComponentLike>>) => IComponent<T>;
82
+ export declare const $subObject: <T extends object, K extends Keys<T>>(src: ISubscribable<T>, opts: Partial<StreamObjOpts<T, K>>, inner: Fn<StreamObj<T, K>["streams"], Promise<ComponentLike>>) => IComponent<T>;
83
83
  export declare class $Object<T extends object, K extends Keys<T>> extends Component implements IMountWithState<T> {
84
84
  protected ctor: Fn<StreamObj<T, K>["streams"], Promise<ComponentLike>>;
85
85
  protected obj: StreamObj<T, K>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rdom",
3
- "version": "1.3.3",
3
+ "version": "1.4.1",
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",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/rdom#readme",
13
+ "homepage": "https://thi.ng/rdom",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -37,20 +37,20 @@
37
37
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
38
38
  },
39
39
  "dependencies": {
40
- "@thi.ng/api": "^8.11.1",
41
- "@thi.ng/checks": "^3.6.3",
42
- "@thi.ng/errors": "^2.5.6",
43
- "@thi.ng/hiccup": "^5.2.0",
44
- "@thi.ng/paths": "^5.1.80",
45
- "@thi.ng/prefixes": "^2.3.18",
46
- "@thi.ng/rstream": "^8.4.3",
47
- "@thi.ng/strings": "^3.7.32"
40
+ "@thi.ng/api": "^8.11.3",
41
+ "@thi.ng/checks": "^3.6.5",
42
+ "@thi.ng/errors": "^2.5.8",
43
+ "@thi.ng/hiccup": "^5.2.2",
44
+ "@thi.ng/paths": "^5.1.82",
45
+ "@thi.ng/prefixes": "^2.3.20",
46
+ "@thi.ng/rstream": "^8.5.1",
47
+ "@thi.ng/strings": "^3.7.34"
48
48
  },
49
49
  "devDependencies": {
50
- "@microsoft/api-extractor": "^7.43.0",
51
- "esbuild": "^0.20.2",
52
- "typedoc": "^0.25.12",
53
- "typescript": "^5.4.3"
50
+ "@microsoft/api-extractor": "^7.47.0",
51
+ "esbuild": "^0.21.5",
52
+ "typedoc": "^0.25.13",
53
+ "typescript": "^5.5.2"
54
54
  },
55
55
  "keywords": [
56
56
  "async",
@@ -145,5 +145,5 @@
145
145
  ],
146
146
  "year": 2020
147
147
  },
148
- "gitHead": "0bec55821066c18eb977a7eabd42c0bb2b096d98\n"
148
+ "gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
149
149
  }
package/sub.js CHANGED
@@ -30,8 +30,7 @@ class $Sub extends Subscription {
30
30
  this.next(x);
31
31
  }
32
32
  next(x) {
33
- if (this.el)
34
- this.inner.update(x);
33
+ if (this.el) this.inner.update(x);
35
34
  }
36
35
  }
37
36
  class $SubA extends Subscription {
@@ -43,8 +42,7 @@ class $SubA extends Subscription {
43
42
  setter;
44
43
  attr = {};
45
44
  next(a) {
46
- if (this.comp.el)
47
- $attribs(this.comp.el, this.setter(this.attr, a));
45
+ if (this.comp.el) $attribs(this.comp.el, this.setter(this.attr, a));
48
46
  }
49
47
  }
50
48
  export {
package/wrap.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { $compile } from "./compile.js";
2
2
  import { $addChild, $html, $remove, $text } from "./dom.js";
3
- const wrapper = (update) => (tag, attribs, body) => ({
3
+ const __wrapper = (update) => (tag, attribs, body) => ({
4
4
  async mount(parent, index, state) {
5
5
  this.inner = $compile([tag, attribs]);
6
6
  this.el = await this.inner.mount(parent, index);
@@ -12,12 +12,11 @@ const wrapper = (update) => (tag, attribs, body) => ({
12
12
  this.el = void 0;
13
13
  },
14
14
  update(body2) {
15
- if (this.el)
16
- update(this.el, body2);
15
+ if (this.el) update(this.el, body2);
17
16
  }
18
17
  });
19
- const $wrapText = wrapper($text);
20
- const $wrapHtml = wrapper($html);
18
+ const $wrapText = __wrapper($text);
19
+ const $wrapHtml = __wrapper($html);
21
20
  const $wrapEl = (el) => ({
22
21
  async mount(parent, idx) {
23
22
  $addChild(parent, el, idx);