@thi.ng/rdom 1.4.0 → 1.4.2

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-05-08T18:24:31Z
3
+ - **Last updated**: 2024-06-29T09:28:36Z
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,19 @@ 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
+
12
25
  ## [1.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rdom@1.4.0) (2024-05-08)
13
26
 
14
27
  #### 🚀 Features
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 189 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
  >
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/compile.js CHANGED
@@ -7,32 +7,32 @@ 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])) return true;
22
+ if (__isComplexComponent(x[k])) return true;
23
23
  }
24
24
  } else if (isArray(x)) {
25
25
  for (let i = 0, n = x.length; i < n; i++) {
26
- if (isComplexComponent(x[i])) return true;
26
+ if (__isComplexComponent(x[i])) return true;
27
27
  }
28
28
  }
29
29
  return isSubscribable(x) || isAsyncIterable(x) || isComponent(x) || isElement(x);
30
30
  };
31
- const complexComponent = (tree) => ({
31
+ const __complexComponent = (tree) => ({
32
32
  async mount(parent, index = -1) {
33
33
  this.subs = [];
34
34
  const attribs = { ...tree[1] };
35
- walk((x, path) => {
35
+ __walk((x, path) => {
36
36
  if (isSubscribable(x)) {
37
37
  this.subs.push(x.subscribe(new $SubA(this, path)));
38
38
  } else if (isAsyncIterable(x)) {
@@ -62,7 +62,7 @@ const complexComponent = (tree) => ({
62
62
  update() {
63
63
  }
64
64
  });
65
- const basicComponent = (tree) => ({
65
+ const __basicComponent = (tree) => ({
66
66
  async mount(parent, index = -1) {
67
67
  return this.el = await $tree(tree, parent, index);
68
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/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.4.0",
3
+ "version": "1.4.2",
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.2",
41
- "@thi.ng/checks": "^3.6.4",
42
- "@thi.ng/errors": "^2.5.7",
43
- "@thi.ng/hiccup": "^5.2.1",
44
- "@thi.ng/paths": "^5.1.81",
45
- "@thi.ng/prefixes": "^2.3.19",
46
- "@thi.ng/rstream": "^8.5.0",
47
- "@thi.ng/strings": "^3.7.33"
40
+ "@thi.ng/api": "^8.11.4",
41
+ "@thi.ng/checks": "^3.6.6",
42
+ "@thi.ng/errors": "^2.5.9",
43
+ "@thi.ng/hiccup": "^5.2.3",
44
+ "@thi.ng/paths": "^5.1.83",
45
+ "@thi.ng/prefixes": "^2.3.21",
46
+ "@thi.ng/rstream": "^8.5.2",
47
+ "@thi.ng/strings": "^3.7.35"
48
48
  },
49
49
  "devDependencies": {
50
- "@microsoft/api-extractor": "^7.43.2",
51
- "esbuild": "^0.21.1",
50
+ "@microsoft/api-extractor": "^7.47.0",
51
+ "esbuild": "^0.21.5",
52
52
  "typedoc": "^0.25.13",
53
- "typescript": "^5.4.5"
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": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
148
+ "gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\n"
149
149
  }
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);
@@ -15,8 +15,8 @@ const wrapper = (update) => (tag, attribs, body) => ({
15
15
  if (this.el) update(this.el, body2);
16
16
  }
17
17
  });
18
- const $wrapText = wrapper($text);
19
- const $wrapHtml = wrapper($html);
18
+ const $wrapText = __wrapper($text);
19
+ const $wrapHtml = __wrapper($html);
20
20
  const $wrapEl = (el) => ({
21
21
  async mount(parent, idx) {
22
22
  $addChild(parent, el, idx);