@thi.ng/rdom-components 0.5.39 → 0.6.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-03-27T19:05:49Z
3
+ - **Last updated**: 2023-04-08T11:09:50Z
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,18 @@ 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.6.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rdom-components@0.6.0) (2023-04-08)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add staticDropdownAlt(), add docs ([0f1b922](https://github.com/thi-ng/umbrella/commit/0f1b922))
17
+
18
+ #### 🩹 Bug fixes
19
+
20
+ - update dropdown args & attrib handling ([f2bd62b](https://github.com/thi-ng/umbrella/commit/f2bd62b))
21
+ - update static/dynamicDropdown()
22
+ - allow user attribs to supply onchange handler
23
+
12
24
  ## [0.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rdom-components@0.5.0) (2022-07-12)
13
25
 
14
26
  #### 🚀 Features
package/README.md CHANGED
@@ -61,7 +61,7 @@ For Node.js REPL:
61
61
  const rdomComponents = await import("@thi.ng/rdom-components");
62
62
  ```
63
63
 
64
- Package sizes (brotli'd, pre-treeshake): ESM: 1.21 KB
64
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.28 KB
65
65
 
66
66
  ## Dependencies
67
67
 
@@ -87,6 +87,7 @@ A selection:
87
87
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/color-themes.png" width="240"/> | Probabilistic color theme generator | [Demo](https://demo.thi.ng/umbrella/color-themes/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/color-themes) |
88
88
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/dominant-colors.png" width="240"/> | Color palette generation via dominant color extraction from uploaded images | [Demo](https://demo.thi.ng/umbrella/dominant-colors/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/dominant-colors) |
89
89
  | <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) |
90
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/trace-bitmap.jpg" width="240"/> | Multi-layer vectorization & dithering of bitmap images | [Demo](https://demo.thi.ng/umbrella/trace-bitmap/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/trace-bitmap) |
90
91
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-channel-mixer.jpg" width="240"/> | rdom & WebGL-based image channel editor | [Demo](https://demo.thi.ng/umbrella/webgl-channel-mixer/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-channel-mixer) |
91
92
 
92
93
  ## API
package/dropdown.d.ts CHANGED
@@ -1,11 +1,67 @@
1
1
  import type { Fn } from "@thi.ng/api";
2
2
  import { type SelectAttribs } from "@thi.ng/hiccup-html/forms";
3
- import type { ISubscribable, Subscription } from "@thi.ng/rstream";
3
+ import type { ISubscribable, ISubscription } from "@thi.ng/rstream";
4
4
  export interface DropdownOpts<T> {
5
5
  attribs: Partial<SelectAttribs>;
6
6
  label: Fn<T, string>;
7
7
  value: Fn<T, string>;
8
8
  }
9
- export declare const dynamicDropdown: <T = string, S extends string = string>(items: ISubscribable<T[]>, sel: Subscription<S, S>, opts?: Partial<DropdownOpts<T>> | undefined) => import("@thi.ng/rdom").IComponent<T[]>;
10
- export declare const staticDropdown: <T = string, S extends string = string>(items: T[], sel: Subscription<S, S>, opts?: Partial<DropdownOpts<T>> | undefined) => [string, import("@thi.ng/api").Nullable<Partial<SelectAttribs>>, ...any[]];
9
+ /**
10
+ * Dropdown `<select>` component with dynamically defined list of items (via
11
+ * subscription) and reactive updates using additionally provided `sel`
12
+ * subscription.
13
+ *
14
+ * @remarks
15
+ * Only single selections are supported. Each generated `<option>` element will
16
+ * have its own child subscription to update its `selected` attribute based on
17
+ * current value of `sel`.
18
+ *
19
+ * See {@link staticDropdown} or {@link staticDropdownAlt} for use cases where
20
+ * the items themselves are statically defined.
21
+ *
22
+ * @param items
23
+ * @param sel
24
+ * @param opts
25
+ */
26
+ export declare const dynamicDropdown: <T = string, S extends string = string>(items: ISubscribable<T[]>, sel: ISubscription<S, S>, opts?: Partial<DropdownOpts<T>> | undefined) => import("@thi.ng/rdom").IComponent<T[]>;
27
+ /**
28
+ * Dropdown `<select>` component with statically defined list of items, but
29
+ * reactive updates using provided `sel` subscription.
30
+ *
31
+ * @remarks
32
+ * Only single selections are supported. Each generated `<option>` element will
33
+ * have its own child subscription to update its `selected` attribute based on
34
+ * current value of `sel`.
35
+ *
36
+ * See {@link staticDropdownAlt} for alternative approach or
37
+ * {@link dynamicDropdown} for use cases where the items themselves are
38
+ * dynamically changeable.
39
+ *
40
+ * @param items
41
+ * @param sel
42
+ * @param opts
43
+ * @returns
44
+ */
45
+ export declare const staticDropdown: <T = string, S extends string = string>(items: T[], sel: ISubscription<S, S>, opts?: Partial<DropdownOpts<T>> | undefined) => [string, import("@thi.ng/api").Nullable<Partial<SelectAttribs>>, ...any[]];
46
+ /**
47
+ * Similar to {@link staticDropdown}, but using only a single subscription for
48
+ * the entire dropdown.
49
+ *
50
+ * @remarks
51
+ * **IMPORTANT:** This component is replacing its entire `<select>` element (and
52
+ * all its children) with each value change of `sel`. The component will only be
53
+ * fully mounted when `sel` produces a non-null value. In other words, `sel`
54
+ * **MUST** be pre-initialized for the component to show up (e.g. using
55
+ * rstream's
56
+ * [`reactive`](https://docs.thi.ng/umbrella/rstream/functions/reactive.html)
57
+ * with a seed value).
58
+ *
59
+ * Internally uses thi.ng/rdom
60
+ * [`$replace()`](https://docs.thi.ng/umbrella/rdom/functions/_replace.html).
61
+ *
62
+ * @param items
63
+ * @param sel
64
+ * @param opts
65
+ */
66
+ export declare const staticDropdownAlt: <T = string, S extends string = string>(items: T[], sel: ISubscription<S, S>, opts?: Partial<DropdownOpts<T>> | undefined) => import("@thi.ng/rdom").IComponent<[string, import("@thi.ng/api").Nullable<Partial<SelectAttribs>>, ...any[]]>;
11
67
  //# sourceMappingURL=dropdown.d.ts.map
package/dropdown.js CHANGED
@@ -1,23 +1,94 @@
1
1
  import { option, select } from "@thi.ng/hiccup-html/forms";
2
2
  import { $input } from "@thi.ng/rdom/event";
3
+ import { __nextID } from "@thi.ng/rdom/idgen";
3
4
  import { $list } from "@thi.ng/rdom/list";
5
+ import { $replace } from "@thi.ng/rdom/replace";
6
+ /**
7
+ * Dropdown `<select>` component with dynamically defined list of items (via
8
+ * subscription) and reactive updates using additionally provided `sel`
9
+ * subscription.
10
+ *
11
+ * @remarks
12
+ * Only single selections are supported. Each generated `<option>` element will
13
+ * have its own child subscription to update its `selected` attribute based on
14
+ * current value of `sel`.
15
+ *
16
+ * See {@link staticDropdown} or {@link staticDropdownAlt} for use cases where
17
+ * the items themselves are statically defined.
18
+ *
19
+ * @param items
20
+ * @param sel
21
+ * @param opts
22
+ */
4
23
  export const dynamicDropdown = (items, sel, opts) => {
5
24
  opts = {
6
25
  value: String,
7
26
  label: String,
8
27
  ...opts,
9
28
  };
10
- return $list(items, "select", { ...opts.attribs, onchange: $input(sel) }, $option(sel, opts));
29
+ return $list(items, "select", { onchange: $input(sel), ...opts.attribs }, $option(sel, opts));
11
30
  };
31
+ /**
32
+ * Dropdown `<select>` component with statically defined list of items, but
33
+ * reactive updates using provided `sel` subscription.
34
+ *
35
+ * @remarks
36
+ * Only single selections are supported. Each generated `<option>` element will
37
+ * have its own child subscription to update its `selected` attribute based on
38
+ * current value of `sel`.
39
+ *
40
+ * See {@link staticDropdownAlt} for alternative approach or
41
+ * {@link dynamicDropdown} for use cases where the items themselves are
42
+ * dynamically changeable.
43
+ *
44
+ * @param items
45
+ * @param sel
46
+ * @param opts
47
+ * @returns
48
+ */
12
49
  export const staticDropdown = (items, sel, opts) => {
13
50
  opts = {
14
51
  value: String,
15
52
  label: String,
16
53
  ...opts,
17
54
  };
18
- return select({ ...opts.attribs, onchange: $input(sel) }, ...items.map($option(sel, opts)));
55
+ return select({ onchange: $input(sel), ...opts.attribs }, ...items.map($option(sel, opts)));
56
+ };
57
+ /**
58
+ * Similar to {@link staticDropdown}, but using only a single subscription for
59
+ * the entire dropdown.
60
+ *
61
+ * @remarks
62
+ * **IMPORTANT:** This component is replacing its entire `<select>` element (and
63
+ * all its children) with each value change of `sel`. The component will only be
64
+ * fully mounted when `sel` produces a non-null value. In other words, `sel`
65
+ * **MUST** be pre-initialized for the component to show up (e.g. using
66
+ * rstream's
67
+ * [`reactive`](https://docs.thi.ng/umbrella/rstream/functions/reactive.html)
68
+ * with a seed value).
69
+ *
70
+ * Internally uses thi.ng/rdom
71
+ * [`$replace()`](https://docs.thi.ng/umbrella/rdom/functions/_replace.html).
72
+ *
73
+ * @param items
74
+ * @param sel
75
+ * @param opts
76
+ */
77
+ export const staticDropdownAlt = (items, sel, opts) => {
78
+ opts = {
79
+ value: String,
80
+ label: String,
81
+ ...opts,
82
+ };
83
+ return $replace(sel.map((id) => select({ onchange: $input(sel), ...opts.attribs }, ...items.map((x) => {
84
+ const value = opts.value(x);
85
+ return option({ value, selected: value === id }, opts.label(x));
86
+ })), { id: __nextID("dropdown") }));
19
87
  };
20
88
  const $option = (sel, { label, value }) => (x) => {
21
89
  let v = value(x);
22
- return option({ value: v, selected: sel.map((x) => v === x) }, label(x));
90
+ return option({
91
+ value: v,
92
+ selected: sel.map((x) => v === x, { id: __nextID("opt") }),
93
+ }, label(x));
23
94
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rdom-components",
3
- "version": "0.5.39",
3
+ "version": "0.6.0",
4
4
  "description": "Collection of unstyled, customizable components for @thi.ng/rdom",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,21 +34,21 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.7.5",
38
- "@thi.ng/associative": "^6.2.33",
39
- "@thi.ng/hiccup-html": "^2.2.12",
40
- "@thi.ng/rdom": "^0.10.18",
41
- "@thi.ng/rstream": "^7.2.46",
42
- "@thi.ng/strings": "^3.4.3",
43
- "@thi.ng/transducers": "^8.4.1"
37
+ "@thi.ng/api": "^8.7.6",
38
+ "@thi.ng/associative": "^6.2.34",
39
+ "@thi.ng/hiccup-html": "^2.2.13",
40
+ "@thi.ng/rdom": "^0.11.0",
41
+ "@thi.ng/rstream": "^8.0.0",
42
+ "@thi.ng/strings": "^3.4.4",
43
+ "@thi.ng/transducers": "^8.4.2"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@microsoft/api-extractor": "^7.34.4",
47
- "@thi.ng/testament": "^0.3.14",
47
+ "@thi.ng/testament": "^0.3.15",
48
48
  "rimraf": "^4.4.1",
49
49
  "tools": "^0.0.1",
50
50
  "typedoc": "^0.23.28",
51
- "typescript": "^5.0.2"
51
+ "typescript": "^5.0.4"
52
52
  },
53
53
  "keywords": [
54
54
  "browser",
@@ -105,5 +105,5 @@
105
105
  "status": "alpha",
106
106
  "year": 2020
107
107
  },
108
- "gitHead": "83b15b34326d480cbca0472b20390d4d3bbb792a\n"
108
+ "gitHead": "abcedd9e4e06a4b631f363610eec572f79b571c1\n"
109
109
  }