@thi.ng/rdom 0.10.13 → 0.10.15

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-02T18:09:03Z
3
+ - **Last updated**: 2023-03-09T13:01:59Z
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
@@ -13,9 +13,11 @@ This project is part of the
13
13
  - [From hdom to rdom: Reactive UIs without virtual DOMs](#from-hdom-to-rdom-reactive-uis-without-virtual-doms)
14
14
  - [Targetted, isolated updates](#targetted-isolated-updates)
15
15
  - [Async updates, scheduling & life cycle methods](#async-updates-scheduling--life-cycle-methods)
16
+ - [@thi.ng/atom integration](#thingatom-integration)
17
+ - [DOM creation & mutation](#dom-creation--mutation)
18
+ - [Control structures](#control-structures)
19
+ - [Event handlers for reactive streams](#event-handlers-for-reactive-streams)
16
20
  - [Status](#status)
17
- - [HIC SUNT DRACONES](#hic-sunt-dracones)
18
- - [@thi.ng/atom integration](#thingatom-integration)
19
21
  - [Support packages](#support-packages)
20
22
  - [Related packages](#related-packages)
21
23
  - [Installation](#installation)
@@ -72,13 +74,13 @@ only that body/subtree in the target DOM will be impacted/updated directly...
72
74
  The package provides an interface
73
75
  [`IComponent`](https://docs.thi.ng/umbrella/rdom/interfaces/IComponent.html)
74
76
  (with a super simple life cycle API), a base component class
75
- [`Component`](https://docs.thi.ng/umbrella/rdom/classes/Component.html) for stubbing and a
76
- number of fundamental control constructs & component-wrappers for composing more
77
- complex components and to reduce boilerplate for various situations. Whilst
78
- targetting a standard JS DOM by default, each component can decide for itself
79
- what kind of target data structure (apart from a browser DOM) it manages. _rdom_
80
- components themselves have **no mandatory** knowledge of a browser DOM. As an
81
- example, similar to
77
+ [`Component`](https://docs.thi.ng/umbrella/rdom/classes/Component.html) for
78
+ stubbing and a number of fundamental control constructs & component-wrappers for
79
+ composing more complex components and to reduce boilerplate for various
80
+ situations. Whilst targetting a standard JS DOM by default, each component can
81
+ decide for itself what kind of target data structure (apart from a browser DOM)
82
+ it manages. _rdom_ components themselves have **no mandatory** knowledge of a
83
+ browser DOM. As an example, similar to
82
84
  [@thi.ng/hdom-canvas](https://github.com/thi-ng/umbrella/tree/develop/packages/hiccup-canvas),
83
85
  the
84
86
  [@thi.ng/rdom-canvas](https://github.com/thi-ng/umbrella/tree/develop/packages/rdom-canvas)
@@ -91,7 +93,13 @@ draw calls.
91
93
  Since there's no central coordination in _rdom_ (neither explicitly nor
92
94
  implicitly), each component can (and does) update whenever its state value has
93
95
  changed. Likewise, components are free to directly manipulate the DOM through
94
- other means, as hinted at earlier. Various _rdom_ control constructs are dispatching component updates via a central scheduler. By default this is only a dummy implementation which processes tasks immediately. However, as usual _rdom_ only relies on the [`IScheduler`](https://docs.thi.ng/umbrella/rdom/interfaces/IScheduler.html) interface and so supports other implementations, like [`RAFScheduler`](https://docs.thi.ng/umbrella/rdom/classes/RAFScheduler.html).
96
+ other means, as hinted at earlier. Various _rdom_ control constructs are
97
+ dispatching component updates via a central scheduler. By default this is only a
98
+ dummy implementation which processes tasks immediately. However, as usual _rdom_
99
+ only relies on the
100
+ [`IScheduler`](https://docs.thi.ng/umbrella/rdom/interfaces/IScheduler.html)
101
+ interface and so supports other implementations, like
102
+ [`RAFScheduler`](https://docs.thi.ng/umbrella/rdom/classes/RAFScheduler.html).
95
103
 
96
104
  The [`IComponent`](https://docs.thi.ng/umbrella/rdom/interfaces/icomponent.html)
97
105
  interface is at the heart of _rdom_. It defines three lifecycle methods to:
@@ -110,24 +118,11 @@ please consult the docs for these packages to learn more about the available
110
118
  constructs and patterns. Most of _rdom_ only deals with either subscribing to
111
119
  reactive values and/or wrapping/transforming existing subscriptions, either
112
120
  explicitly using the provided control components (e.g.
113
- [`$sub()`](https://docs.thi.ng/umbrella/rdom/modules.html#_sub)) or using
114
- [`$compile()`](https://docs.thi.ng/umbrella/rdom/modules.html#_compile) to
121
+ [`$sub()`](https://docs.thi.ng/umbrella/rdom/functions/_sub.html)) or using
122
+ [`$compile()`](https://docs.thi.ng/umbrella/rdom/functions/_compile.html) to
115
123
  auto-wrap such values embedded in an hiccup tree.
116
124
 
117
- ## Status
118
-
119
- **BETA** - possibly breaking changes forthcoming
120
-
121
- [Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Brdom%5D+in%3Atitle)
122
-
123
- #### HIC SUNT DRACONES
124
-
125
- This is still a young project. Even though most of the overall approach,
126
- component lifecycle and API are fairly stable by now (after ~75 commits) and
127
- used in production, so far there's only brief documentation and only few public
128
- examples. This is being worked & improved on...
129
-
130
- #### @thi.ng/atom integration
125
+ ### @thi.ng/atom integration
131
126
 
132
127
  For the sake of deduplication of functionality and to keep the number of
133
128
  dependencies to a minimum, direct
@@ -136,8 +131,118 @@ integration has been removed in favor of using relevant
136
131
  [@thi.ng/rstream](https://github.com/thi-ng/umbrella/tree/develop/packages/rstream)
137
132
  constructs, which can be used as lightweight adapters, i.e.:
138
133
 
139
- - [`fromAtom()`](https://docs.thi.ng/umbrella/rstream/modules.html#fromAtom)
140
- - [`fromView()`](https://docs.thi.ng/umbrella/rstream/modules.html#fromView)
134
+ - [`fromAtom()`](https://docs.thi.ng/umbrella/rstream/functions/fromAtom.html)
135
+ - [`fromObject()`](https://docs.thi.ng/umbrella/rstream/functions/fromObject.html)
136
+ - [`fromView()`](https://docs.thi.ng/umbrella/rstream/functions/fromView.html)
137
+
138
+ ## DOM creation & mutation
139
+
140
+ The package provides many functions to simplify the creation of individual or
141
+ entire trees of DOM elements and to manipulate them at a later time. The single
142
+ most important function of the package is
143
+ [$compile](https://docs.thi.ng/umbrella/rdom/functions/_compile.html). It acts
144
+ as a facade for many of these other functions and creates an actual DOM from a
145
+ given hiccup component tree. It also automatically wraps any reactive values
146
+ contained therein.
147
+
148
+ **All of these functions are also usable, even if you don't intend to use any
149
+ other package features!**
150
+
151
+ - [$addChild](https://docs.thi.ng/umbrella/rdom/functions/_addChild.html)
152
+ - [$attribs](https://docs.thi.ng/umbrella/rdom/functions/_attribs.html)
153
+ - [$clear](https://docs.thi.ng/umbrella/rdom/functions/_clear.html)
154
+ - [$comment](https://docs.thi.ng/umbrella/rdom/functions/_comment.html)
155
+ - [$el](https://docs.thi.ng/umbrella/rdom/functions/_el.html)
156
+ - [$html](https://docs.thi.ng/umbrella/rdom/functions/_html.html)
157
+ - [$moveTo](https://docs.thi.ng/umbrella/rdom/functions/_moveTo.html)
158
+ - [$remove](https://docs.thi.ng/umbrella/rdom/functions/_remove.html)
159
+ - [$style](https://docs.thi.ng/umbrella/rdom/functions/_style.html)
160
+ - [$text](https://docs.thi.ng/umbrella/rdom/functions/_text.html)
161
+ - [$tree](https://docs.thi.ng/umbrella/rdom/functions/_tree.html)
162
+
163
+ ## Control structures
164
+
165
+ For more advanced usage, rdom provides a range of control structures (container
166
+ components) to simplify the handling of reactive states and reduce boilerplate
167
+ for the implementation of common UI structures (e.g. item lists of any kind).
168
+
169
+ The following links lead to the documentation of these wrappers, incl. small
170
+ code examples:
171
+
172
+ - [$klist](https://docs.thi.ng/umbrella/rdom/functions/_klist.html)
173
+ - [$list](https://docs.thi.ng/umbrella/rdom/functions/_list.html)
174
+ - [$object](https://docs.thi.ng/umbrella/rdom/functions/_object-1.html)
175
+ - [$promise](https://docs.thi.ng/umbrella/rdom/functions/_promise-1.html)
176
+ - [$refresh](https://docs.thi.ng/umbrella/rdom/functions/_refresh.html)
177
+ - [$replace](https://docs.thi.ng/umbrella/rdom/functions/_replace.html)
178
+ - [$sub](https://docs.thi.ng/umbrella/rdom/functions/_sub-1.html)
179
+ - [$subObject](https://docs.thi.ng/umbrella/rdom/functions/_subObject.html)
180
+ - [$switch](https://docs.thi.ng/umbrella/rdom/functions/_switch.html)
181
+ - [$wrapHtml](https://docs.thi.ng/umbrella/rdom/functions/_wrapHtml.html)
182
+ - [$wrapText](https://docs.thi.ng/umbrella/rdom/functions/_wrapText.html)
183
+
184
+ ### Event handlers for reactive streams
185
+
186
+ Reactive rdom component are based on
187
+ [@thi.ng/rstream](https://github.com/thi-ng/umbrella/tree/develop/packages/rstream)
188
+ subscriptions. In order to create a feedback loop between those reactive state
189
+ values and their subscribed UI components, input event handlers need to feed any
190
+ user changes back to those reactive state(s). To reduce boilerplate for these
191
+ tasks, the following higher order input event handlers are provided:
192
+
193
+ - [$input](https://docs.thi.ng/umbrella/rdom/functions/_input.html)
194
+ - [$inputCheckbox](https://docs.thi.ng/umbrella/rdom/functions/_inputCheckbox.html)
195
+ - [$inputFile](https://docs.thi.ng/umbrella/rdom/functions/_inputFile.html)
196
+ - [$inputFiles](https://docs.thi.ng/umbrella/rdom/functions/_inputFiles.html)
197
+ - [$inputNum](https://docs.thi.ng/umbrella/rdom/functions/_inputNum.html)
198
+ - [$inputTrigger](https://docs.thi.ng/umbrella/rdom/functions/_inputTrigger.html)
199
+
200
+ ```ts
201
+ import { $compile, $input } from "@thi.ng/rdom";
202
+ import { reactive, trace } from "@thi.ng/rstream";
203
+
204
+ // reactive value/state w/ transformation
205
+ const name = reactive("").map((x) => x.toUpperCase());
206
+
207
+ // reactive text field for `name`
208
+ $compile(["input", {
209
+ type: "text",
210
+ // any value changes are fed back into `name`, which in return
211
+ // triggers an update of this (and any other) subscription
212
+ oninput: $input(name),
213
+ value: name
214
+ }]).mount(document.body);
215
+
216
+ // addtional subscription for debug console output
217
+ name.subscribe(trace("name:"));
218
+ ```
219
+
220
+ Click counter:
221
+
222
+ ```ts
223
+ import { $compile, $inputTrigger } from "@thi.ng/rdom";
224
+ import { reactive } from "@thi.ng/rstream";
225
+ import { count, scan } from "@thi.ng/transducers";
226
+
227
+ // reactive value/stream setup
228
+ const clicks = reactive(true);
229
+
230
+ // button component with reactive label showing click count
231
+ $compile([
232
+ "button",
233
+ // $inputTrigger merely emits `true` onto the given reactive stream
234
+ { onclick: $inputTrigger(clicks) },
235
+ "clicks: ",
236
+ // using transducers to transform click stream into a counter
237
+ clicks.transform(scan(count(-1))),
238
+ ]).mount(document.body);
239
+ ```
240
+
241
+ ## Status
242
+
243
+ **STABLE** - used in production
244
+
245
+ [Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Brdom%5D+in%3Atitle)
141
246
 
142
247
  ## Support packages
143
248
 
@@ -216,9 +321,9 @@ A selection:
216
321
 
217
322
  TODO
218
323
 
219
- Currently, documentation only exists in the form of small examples and
220
- various doc strings (incomplete). I'm working to alleviate this
221
- situation ASAP... In that respect, PRs are welcome as well!
324
+ Currently, documentation only exists in the form of small examples and various
325
+ doc strings (incomplete). I'm working to alleviate this situation ASAP... In
326
+ that respect, PRs are welcome as well!
222
327
 
223
328
  ### Basic usage
224
329
 
package/dom.d.ts CHANGED
@@ -31,12 +31,17 @@ export declare const $tree: (tree: any, parent: Element, idx?: NumOrElement) =>
31
31
  * Create a single DOM element and optionally attaches it to `parent`.
32
32
  *
33
33
  * @remarks
34
+ * If `tag` is a namespaced tagname (e.g. `prefix:tag`), the element will be
35
+ * created via `document.createElementNS()` and the prefix will be resolved via
36
+ * known aliases registered by {@link registerPrefix}. SVG element names do not
37
+ * need to be prefixed and are recognized automatically.
38
+ *
34
39
  * Supports Emmet-style tag names in this form: `tag#id.class1.class2`.
35
- * `attribs` is a plain object of element attributes. See
36
- * {@link $attribs} for further details.
40
+ * `attribs` is a plain object of element attributes. See {@link $attribs} for
41
+ * further details.
37
42
  *
38
- * If `parent` is given, but no `idx` arg, the new element will be
39
- * appended as child.
43
+ * If `parent` is given, but no `idx` arg, the new element will be appended as
44
+ * child.
40
45
  *
41
46
  * @param tag -
42
47
  * @param attribs -
@@ -157,8 +162,8 @@ export declare const $attribs: (el: Element, attribs: any) => void;
157
162
  */
158
163
  export declare const $style: (el: Element, rules: string | any) => void;
159
164
  /**
160
- * Registers an XML namespace prefix and its URL for later use, e.g. to
161
- * define namespaced elements/attributes.
165
+ * Registers an XML namespace prefix and its URL for later use, e.g. to define
166
+ * namespaced elements/attributes via {@link $el}, {@link $tree}.
162
167
  *
163
168
  * @param prefix -
164
169
  * @param url -
package/dom.js CHANGED
@@ -93,12 +93,17 @@ const $treeIter = (tree, parent) => {
93
93
  * Create a single DOM element and optionally attaches it to `parent`.
94
94
  *
95
95
  * @remarks
96
+ * If `tag` is a namespaced tagname (e.g. `prefix:tag`), the element will be
97
+ * created via `document.createElementNS()` and the prefix will be resolved via
98
+ * known aliases registered by {@link registerPrefix}. SVG element names do not
99
+ * need to be prefixed and are recognized automatically.
100
+ *
96
101
  * Supports Emmet-style tag names in this form: `tag#id.class1.class2`.
97
- * `attribs` is a plain object of element attributes. See
98
- * {@link $attribs} for further details.
102
+ * `attribs` is a plain object of element attributes. See {@link $attribs} for
103
+ * further details.
99
104
  *
100
- * If `parent` is given, but no `idx` arg, the new element will be
101
- * appended as child.
105
+ * If `parent` is given, but no `idx` arg, the new element will be appended as
106
+ * child.
102
107
  *
103
108
  * @param tag -
104
109
  * @param attribs -
@@ -394,8 +399,8 @@ const PREFIXES = {
394
399
  xmlns: XML_XMLNS,
395
400
  };
396
401
  /**
397
- * Registers an XML namespace prefix and its URL for later use, e.g. to
398
- * define namespaced elements/attributes.
402
+ * Registers an XML namespace prefix and its URL for later use, e.g. to define
403
+ * namespaced elements/attributes via {@link $el}, {@link $tree}.
399
404
  *
400
405
  * @param prefix -
401
406
  * @param url -
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rdom",
3
- "version": "0.10.13",
3
+ "version": "0.10.15",
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",
@@ -38,15 +38,15 @@
38
38
  "@thi.ng/api": "^8.7.3",
39
39
  "@thi.ng/checks": "^3.3.9",
40
40
  "@thi.ng/errors": "^2.2.12",
41
- "@thi.ng/hiccup": "^4.2.35",
41
+ "@thi.ng/hiccup": "^4.2.36",
42
42
  "@thi.ng/paths": "^5.1.32",
43
43
  "@thi.ng/prefixes": "^2.1.19",
44
- "@thi.ng/rstream": "^7.2.42",
44
+ "@thi.ng/rstream": "^7.2.43",
45
45
  "@thi.ng/strings": "^3.4.1"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@microsoft/api-extractor": "^7.34.2",
49
- "@thi.ng/testament": "^0.3.11",
49
+ "@thi.ng/testament": "^0.3.12",
50
50
  "rimraf": "^4.1.2",
51
51
  "tools": "^0.0.1",
52
52
  "typedoc": "^0.23.24",
@@ -137,8 +137,7 @@
137
137
  "hiccup-svg",
138
138
  "transducers"
139
139
  ],
140
- "status": "beta",
141
140
  "year": 2020
142
141
  },
143
- "gitHead": "8342900eedc77bb09edb8c544804578b71f8acc6\n"
142
+ "gitHead": "8ab2cbfe2f59b7ef672b6e1cf2a43368f8437ddf\n"
144
143
  }