@thi.ng/rdom-components 0.6.37 → 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 +1 -1
- package/README.md +0 -2
- package/accordion.js +22 -6
- package/dropdown.js +56 -84
- package/editor.js +36 -22
- package/icon-button.js +15 -11
- package/input.js +24 -14
- package/package.json +14 -11
- package/radio.js +26 -14
- package/tabs.js +23 -7
package/CHANGELOG.md
CHANGED
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
29
|
-
|
|
36
|
+
setCursor(e);
|
|
37
|
+
src.next(e.target.value);
|
|
30
38
|
},
|
|
31
39
|
onkeyup: setCursor,
|
|
32
|
-
onmouseup: setCursor
|
|
33
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 {
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const inputNumeric = (dest, attribs) => inputNumber({
|
|
9
|
+
...attribs,
|
|
10
|
+
value: dest,
|
|
11
|
+
oninput: $inputNum(dest)
|
|
10
12
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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.
|
|
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
|
|
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,17 +35,17 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
37
|
-
"@thi.ng/associative": "^6.3.
|
|
38
|
-
"@thi.ng/hiccup-html": "^2.
|
|
39
|
-
"@thi.ng/rdom": "^0.13.
|
|
40
|
-
"@thi.ng/rstream": "^8.2.
|
|
41
|
-
"@thi.ng/strings": "^3.7.
|
|
42
|
-
"@thi.ng/transducers": "^8.8.
|
|
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",
|
|
46
|
-
"
|
|
48
|
+
"esbuild": "^0.19.8",
|
|
47
49
|
"rimraf": "^5.0.5",
|
|
48
50
|
"tools": "^0.0.1",
|
|
49
51
|
"typedoc": "^0.25.4",
|
|
@@ -55,6 +57,7 @@
|
|
|
55
57
|
"dom",
|
|
56
58
|
"hiccup",
|
|
57
59
|
"html",
|
|
60
|
+
"rdom",
|
|
58
61
|
"reactive",
|
|
59
62
|
"rstream",
|
|
60
63
|
"typescript",
|
|
@@ -104,5 +107,5 @@
|
|
|
104
107
|
"status": "alpha",
|
|
105
108
|
"year": 2020
|
|
106
109
|
},
|
|
107
|
-
"gitHead": "
|
|
110
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
108
111
|
}
|
package/radio.js
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
import { div } from "@thi.ng/hiccup-html/blocks";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
label,
|
|
4
|
+
radio
|
|
5
|
+
} from "@thi.ng/hiccup-html/forms";
|
|
3
6
|
import { $input } from "@thi.ng/rdom/event";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
};
|