@thi.ng/rdom-components 0.6.38 → 0.6.39

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-12-09T19:12:03Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
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.
package/README.md CHANGED
@@ -82,9 +82,7 @@ directory are using this package:
82
82
 
83
83
  | Screenshot | Description | Live demo | Source |
84
84
  |:---------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------|:----------------------------------------------------------|:---------------------------------------------------------------------------------------|
85
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/big-font.png" width="240"/> | Large ASCII font text generator using @thi.ng/rdom | [Demo](https://demo.thi.ng/umbrella/big-font/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/big-font) |
86
85
  | <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) |
87
- | <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) |
88
86
  | <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) |
89
87
  | <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) |
90
88
  | <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) |
package/accordion.js CHANGED
@@ -5,10 +5,26 @@ import { $promise } from "@thi.ng/rdom/promise";
5
5
  import { dedupe } from "@thi.ng/transducers/dedupe";
6
6
  import { map } from "@thi.ng/transducers/map";
7
7
  import { range } from "@thi.ng/transducers/range";
8
- export const accordion = (src, { attribs, head, sections, error }) => {
9
- return $list(src.transform(dedupe(), map((id) => [
10
- ...map((i) => [i, i === id], range(sections.length)),
11
- ])), "div", attribs.wrapper, ([i, sel]) => section(sel ? attribs.sectionOn : attribs.sectionOff, head(src, sections[i].title, i, sel), sel
12
- ? div(attribs.content, $promise(sections[i].content(i), error))
13
- : null));
8
+ const accordion = (src, { attribs, head, sections, error }) => {
9
+ return $list(
10
+ src.transform(
11
+ dedupe(),
12
+ map((id) => [
13
+ ...map((i) => [i, i === id], range(sections.length))
14
+ ])
15
+ ),
16
+ "div",
17
+ attribs.wrapper,
18
+ ([i, sel]) => section(
19
+ sel ? attribs.sectionOn : attribs.sectionOff,
20
+ head(src, sections[i].title, i, sel),
21
+ sel ? div(
22
+ attribs.content,
23
+ $promise(sections[i].content(i), error)
24
+ ) : null
25
+ )
26
+ );
27
+ };
28
+ export {
29
+ accordion
14
30
  };
package/dropdown.js CHANGED
@@ -3,92 +3,64 @@ import { $input } from "@thi.ng/rdom/event";
3
3
  import { __nextID } from "@thi.ng/rdom/idgen";
4
4
  import { $list } from "@thi.ng/rdom/list";
5
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
- */
23
- export const dynamicDropdown = (items, sel, opts) => {
24
- opts = {
25
- value: String,
26
- label: String,
27
- ...opts,
28
- };
29
- return $list(items, "select", { onchange: $input(sel), ...opts.attribs }, $option(sel, opts));
6
+ const dynamicDropdown = (items, sel, opts) => {
7
+ opts = {
8
+ value: String,
9
+ label: String,
10
+ ...opts
11
+ };
12
+ return $list(
13
+ items,
14
+ "select",
15
+ { onchange: $input(sel), ...opts.attribs },
16
+ $option(sel, opts)
17
+ );
30
18
  };
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
- */
49
- export const staticDropdown = (items, sel, opts) => {
50
- opts = {
51
- value: String,
52
- label: String,
53
- ...opts,
54
- };
55
- return select({ onchange: $input(sel), ...opts.attribs }, ...items.map($option(sel, opts)));
19
+ const staticDropdown = (items, sel, opts) => {
20
+ opts = {
21
+ value: String,
22
+ label: String,
23
+ ...opts
24
+ };
25
+ return select(
26
+ { onchange: $input(sel), ...opts.attribs },
27
+ ...items.map($option(sel, opts))
28
+ );
56
29
  };
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") }));
30
+ const staticDropdownAlt = (items, sel, opts) => {
31
+ opts = {
32
+ value: String,
33
+ label: String,
34
+ ...opts
35
+ };
36
+ return $replace(
37
+ sel.map(
38
+ (id) => select(
39
+ { onchange: $input(sel), ...opts.attribs },
40
+ ...items.map((x) => {
41
+ const value = opts.value(x);
42
+ return option(
43
+ { value, selected: value === id },
44
+ opts.label(x)
45
+ );
46
+ })
47
+ ),
48
+ { id: __nextID("dropdown") }
49
+ )
50
+ );
87
51
  };
88
52
  const $option = (sel, { label, value }) => (x) => {
89
- let v = value(x);
90
- return option({
91
- value: v,
92
- selected: sel.map((x) => v === x, { id: __nextID("opt") }),
93
- }, label(x));
53
+ let v = value(x);
54
+ return option(
55
+ {
56
+ value: v,
57
+ selected: sel.map((x2) => v === x2, { id: __nextID("opt") })
58
+ },
59
+ label(x)
60
+ );
61
+ };
62
+ export {
63
+ dynamicDropdown,
64
+ staticDropdown,
65
+ staticDropdownAlt
94
66
  };
package/editor.js CHANGED
@@ -4,31 +4,45 @@ import { textArea } from "@thi.ng/hiccup-html/forms";
4
4
  import { $compile } from "@thi.ng/rdom/compile";
5
5
  import { reactive } from "@thi.ng/rstream/stream";
6
6
  import { computeCursorPos } from "@thi.ng/strings/cursor";
7
- export const editor = (src, opts = {}) => {
8
- opts = meldDeepObj({
9
- editor: {
10
- attribs: {
11
- spellcheck: false,
12
- },
13
- },
14
- cursor: {
15
- format: (pos) => pos[0] + ":" + pos[1],
16
- },
17
- }, opts);
18
- let inner;
19
- const fmt = opts.cursor.format;
20
- const cursor = reactive(0).map((pos) => fmt(inner
21
- ? computeCursorPos(inner.el.value, pos)
22
- : [1, 1]));
23
- const setCursor = (e) => cursor.next(e.target.selectionStart);
24
- return div(opts.wrapper, (inner = $compile(textArea({
7
+ const editor = (src, opts = {}) => {
8
+ opts = meldDeepObj(
9
+ {
10
+ editor: {
11
+ attribs: {
12
+ spellcheck: false
13
+ }
14
+ },
15
+ cursor: {
16
+ format: (pos) => pos[0] + ":" + pos[1]
17
+ }
18
+ },
19
+ opts
20
+ );
21
+ let inner;
22
+ const fmt = opts.cursor.format;
23
+ const cursor = reactive(0).map(
24
+ (pos) => fmt(
25
+ inner ? computeCursorPos(inner.el.value, pos) : [1, 1]
26
+ )
27
+ );
28
+ const setCursor = (e) => cursor.next(e.target.selectionStart);
29
+ return div(
30
+ opts.wrapper,
31
+ inner = $compile(
32
+ textArea({
25
33
  ...opts.editor.attribs,
26
34
  value: src,
27
35
  oninput: (e) => {
28
- setCursor(e);
29
- src.next(e.target.value);
36
+ setCursor(e);
37
+ src.next(e.target.value);
30
38
  },
31
39
  onkeyup: setCursor,
32
- onmouseup: setCursor,
33
- }))), div(opts.cursor.attribs, cursor));
40
+ onmouseup: setCursor
41
+ })
42
+ ),
43
+ div(opts.cursor.attribs, cursor)
44
+ );
45
+ };
46
+ export {
47
+ editor
34
48
  };
package/icon-button.js CHANGED
@@ -1,14 +1,18 @@
1
1
  import { button } from "@thi.ng/hiccup-html/forms";
2
2
  import { i } from "@thi.ng/hiccup-html/inline";
3
- export const iconButton = (opts) => {
4
- const isLeft = opts.iconPos !== "right";
5
- const icon = i({
6
- style: {
7
- fill: "currentColor",
8
- [`margin-${isLeft ? "right" : "left"}`]: "0.5rem",
9
- },
10
- }, opts.icon);
11
- return isLeft
12
- ? button(opts.attribs, icon, opts.label)
13
- : button(opts.attribs, opts.label, icon);
3
+ const iconButton = (opts) => {
4
+ const isLeft = opts.iconPos !== "right";
5
+ const icon = i(
6
+ {
7
+ style: {
8
+ fill: "currentColor",
9
+ [`margin-${isLeft ? "right" : "left"}`]: "0.5rem"
10
+ }
11
+ },
12
+ opts.icon
13
+ );
14
+ return isLeft ? button(opts.attribs, icon, opts.label) : button(opts.attribs, opts.label, icon);
15
+ };
16
+ export {
17
+ iconButton
14
18
  };
package/input.js CHANGED
@@ -1,20 +1,30 @@
1
1
  import { div } from "@thi.ng/hiccup-html/blocks";
2
- import { inputNumber, } from "@thi.ng/hiccup-html/forms";
2
+ import {
3
+ inputNumber
4
+ } from "@thi.ng/hiccup-html/forms";
3
5
  import { $inputNum } from "@thi.ng/rdom/event";
4
6
  import { pluck } from "@thi.ng/transducers/pluck";
5
7
  import { repeatedly } from "@thi.ng/transducers/repeatedly";
6
- export const inputNumeric = (dest, attribs) => inputNumber({
7
- ...attribs,
8
- value: dest,
9
- oninput: $inputNum(dest),
8
+ const inputNumeric = (dest, attribs) => inputNumber({
9
+ ...attribs,
10
+ value: dest,
11
+ oninput: $inputNum(dest)
10
12
  });
11
- export const inputVector = (dim, dest, outerAttribs = {}, innerAttribs) => div(outerAttribs, ...repeatedly((i) => inputVectorCoord(dim, i, dest, innerAttribs), dim));
12
- export const inputVectorCoord = (dim, i, dest, attribs) => inputNumber({
13
- ...attribs,
14
- value: dest.transform(pluck(i)),
15
- oninput: (e) => {
16
- const vec = (dest.deref() || new Array(dim).fill(0)).slice();
17
- vec[i] = parseFloat(e.target.value);
18
- dest.next(vec);
19
- },
13
+ const inputVector = (dim, dest, outerAttribs = {}, innerAttribs) => div(
14
+ outerAttribs,
15
+ ...repeatedly((i) => inputVectorCoord(dim, i, dest, innerAttribs), dim)
16
+ );
17
+ const inputVectorCoord = (dim, i, dest, attribs) => inputNumber({
18
+ ...attribs,
19
+ value: dest.transform(pluck(i)),
20
+ oninput: (e) => {
21
+ const vec = (dest.deref() || new Array(dim).fill(0)).slice();
22
+ vec[i] = parseFloat(e.target.value);
23
+ dest.next(vec);
24
+ }
20
25
  });
26
+ export {
27
+ inputNumeric,
28
+ inputVector,
29
+ inputVectorCoord
30
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rdom-components",
3
- "version": "0.6.38",
3
+ "version": "0.6.39",
4
4
  "description": "Collection of unstyled, customizable components for @thi.ng/rdom",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -24,7 +24,9 @@
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && tsc --declaration",
27
+ "build": "yarn build:esbuild && yarn build:decl",
28
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
29
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
28
30
  "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
29
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
@@ -33,16 +35,17 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.11",
37
- "@thi.ng/associative": "^6.3.23",
38
- "@thi.ng/hiccup-html": "^2.3.0",
39
- "@thi.ng/rdom": "^0.13.3",
40
- "@thi.ng/rstream": "^8.2.13",
41
- "@thi.ng/strings": "^3.7.2",
42
- "@thi.ng/transducers": "^8.8.14"
38
+ "@thi.ng/api": "^8.9.12",
39
+ "@thi.ng/associative": "^6.3.24",
40
+ "@thi.ng/hiccup-html": "^2.3.1",
41
+ "@thi.ng/rdom": "^0.13.4",
42
+ "@thi.ng/rstream": "^8.2.14",
43
+ "@thi.ng/strings": "^3.7.3",
44
+ "@thi.ng/transducers": "^8.8.15"
43
45
  },
44
46
  "devDependencies": {
45
47
  "@microsoft/api-extractor": "^7.38.3",
48
+ "esbuild": "^0.19.8",
46
49
  "rimraf": "^5.0.5",
47
50
  "tools": "^0.0.1",
48
51
  "typedoc": "^0.25.4",
@@ -54,6 +57,7 @@
54
57
  "dom",
55
58
  "hiccup",
56
59
  "html",
60
+ "rdom",
57
61
  "reactive",
58
62
  "rstream",
59
63
  "typescript",
@@ -103,5 +107,5 @@
103
107
  "status": "alpha",
104
108
  "year": 2020
105
109
  },
106
- "gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
110
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
107
111
  }
package/radio.js CHANGED
@@ -1,19 +1,31 @@
1
1
  import { div } from "@thi.ng/hiccup-html/blocks";
2
- import { label, radio, } from "@thi.ng/hiccup-html/forms";
2
+ import {
3
+ label,
4
+ radio
5
+ } from "@thi.ng/hiccup-html/forms";
3
6
  import { $input } from "@thi.ng/rdom/event";
4
- export const staticRadio = (items, sel, opts) => {
5
- opts = {
6
- label: (x, radio) => label({ for: String(x) }, String(x), radio),
7
- value: String,
8
- ...opts,
9
- };
10
- return div({ ...opts.attribs }, ...items.map($radio(sel, opts)));
7
+ const staticRadio = (items, sel, opts) => {
8
+ opts = {
9
+ label: (x, radio2) => label({ for: String(x) }, String(x), radio2),
10
+ value: String,
11
+ ...opts
12
+ };
13
+ return div(
14
+ { ...opts.attribs },
15
+ ...items.map($radio(sel, opts))
16
+ );
11
17
  };
12
18
  const $radio = (sel, opts) => (x) => {
13
- let v = opts.value(x);
14
- return opts.label(x, radio({
15
- value: v,
16
- checked: sel.map((x) => v === x),
17
- onchange: $input(sel),
18
- }));
19
+ let v = opts.value(x);
20
+ return opts.label(
21
+ x,
22
+ radio({
23
+ value: v,
24
+ checked: sel.map((x2) => v === x2),
25
+ onchange: $input(sel)
26
+ })
27
+ );
28
+ };
29
+ export {
30
+ staticRadio
19
31
  };
package/tabs.js CHANGED
@@ -6,12 +6,28 @@ import { $switch } from "@thi.ng/rdom/switch";
6
6
  import { dedupe } from "@thi.ng/transducers/dedupe";
7
7
  import { map } from "@thi.ng/transducers/map";
8
8
  import { range } from "@thi.ng/transducers/range";
9
- export const tabs = (src, opts) => {
10
- const { attribs, head, sections } = { attribs: {}, ...opts };
11
- return div(attribs.wrapper, $list(src.map((id) => [
12
- ...map((i) => [i, i === id], range(sections.length)),
13
- ]), "div", attribs.tab, ([i, sel]) => head(src, sections[i].title, i, sel)), $switch(src.transform(dedupe()), identity, sections.reduce((acc, { content }, i) => {
14
- acc[i] = async (i) => section(attribs.content, await content(i));
9
+ const tabs = (src, opts) => {
10
+ const { attribs, head, sections } = { attribs: {}, ...opts };
11
+ return div(
12
+ attribs.wrapper,
13
+ $list(
14
+ src.map((id) => [
15
+ ...map((i) => [i, i === id], range(sections.length))
16
+ ]),
17
+ "div",
18
+ attribs.tab,
19
+ ([i, sel]) => head(src, sections[i].title, i, sel)
20
+ ),
21
+ $switch(
22
+ src.transform(dedupe()),
23
+ identity,
24
+ sections.reduce((acc, { content }, i) => {
25
+ acc[i] = async (i2) => section(attribs.content, await content(i2));
15
26
  return acc;
16
- }, {})));
27
+ }, {})
28
+ )
29
+ );
30
+ };
31
+ export {
32
+ tabs
17
33
  };