@tltdsh/mx 1.0.1 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +90 -5
  2. package/package.json +33 -4
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # mx.js
2
2
 
3
- Reactive UI library in **890 bytes** (brotli). 4 globals, zero dependencies, no build step.
3
+ Expressive UI library in **890 bytes** (brotli) for building high-end, enterprise-level applications. 4 globals, zero dependencies, no build step.
4
4
 
5
5
  [**Documentation**](https://mxjs.dev)
6
6
 
@@ -36,7 +36,6 @@ CamelCase auto-converts to kebab-case: `mx.priceChart()` → `<price-chart>`.
36
36
  ## Quick start
37
37
 
38
38
  ```js
39
- // Define a component
40
39
  define('counter', {
41
40
  $({ count = 0 }) {
42
41
  return [
@@ -47,8 +46,94 @@ define('counter', {
47
46
  }
48
47
  })
49
48
 
50
- // Mount it
51
- document.body.append(dom.counter({ count: 10 }))
49
+ document.body.render(mx.counter({ count: 10 }))
50
+ ```
51
+
52
+ ## Examples
53
+
54
+ ### SVG sparkline
55
+
56
+ ```js
57
+ define('sparkline', {
58
+ $({ history = [], width = 80, height = 24 }) {
59
+ if (!history.length) return []
60
+ let min = Math.min(...history), max = Math.max(...history)
61
+ let range = max - min || 1
62
+ let points = history.map((v, i) =>
63
+ (i / (history.length - 1) * width).toFixed(1) + ',' +
64
+ (height - ((v - min) / range * (height - 2) + 1)).toFixed(1)
65
+ ).join(' ')
66
+ return mx.svg({ viewBox: '0 0 ' + width + ' ' + height, width, height, fill: 'none' },
67
+ mx.polyline({ points, stroke: '#0071e3', 'stroke-width': '1.5', 'stroke-linecap': 'round' })
68
+ )
69
+ }
70
+ })
71
+ ```
72
+
73
+ ### Sortable table
74
+
75
+ ```js
76
+ define('data-table', {
77
+ $({ rows = [], sortKey = 'name', sortDir = 1 }) {
78
+ let sorted = [...rows].sort((a, b) => {
79
+ let va = a[sortKey], vb = b[sortKey]
80
+ return sortDir * (typeof va === 'string' ? va.localeCompare(vb) : va - vb)
81
+ })
82
+ let header = (label, key) =>
83
+ mx.th({ onclick: _ => this.$({ sortKey: key, sortDir: sortKey === key ? -sortDir : 1 }) },
84
+ label, sortKey === key ? (sortDir > 0 ? ' ▲' : ' ▼') : null
85
+ )
86
+ return mx.table(
87
+ mx.thead(mx.tr(header('Name', 'name'), header('Value', 'value'))),
88
+ mx.tbody(...sorted.map(r => mx.tr(mx.td(r.name), mx.td(r.value))))
89
+ )
90
+ }
91
+ })
92
+ ```
93
+
94
+ ### Keyed list with persistent DOM
95
+
96
+ ```js
97
+ define('drink-builder', {
98
+ $({ drinks = [], onadd, onremove }) {
99
+ this._rowMap ||= new Map
100
+ for (let [id] of this._rowMap)
101
+ if (!drinks.find(d => d.id === id)) this._rowMap.delete(id)
102
+ for (let d of drinks) {
103
+ let el = this._rowMap.get(d.id)
104
+ if (!el) { el = dom.drinkRow(); this._rowMap.set(d.id, el) }
105
+ el.$({ drink: d, onremove })
106
+ }
107
+ return [
108
+ !!drinks.length && mx.div({ class: 'list' },
109
+ ...drinks.map(d => this._rowMap.get(d.id))
110
+ ),
111
+ mx.button({ onclick: _ => onadd?.() }, '+ Add drink')
112
+ ]
113
+ }
114
+ })
115
+ ```
116
+
117
+ ### Toast notifications
118
+
119
+ ```js
120
+ let toastContainer = null
121
+
122
+ function toast(message, type = 'info') {
123
+ if (!toastContainer) {
124
+ toastContainer = dom.div({ class: 'toast-container' })
125
+ document.body.append(toastContainer)
126
+ }
127
+ let el = dom.div({ class: 'toast toast-' + type },
128
+ mx.span(message),
129
+ mx.button({ onclick() { el.remove() } }, '×')
130
+ )
131
+ toastContainer.append(el)
132
+ setTimeout(_ => el.remove(), 4000)
133
+ }
134
+
135
+ toast.success = msg => toast(msg, 'success')
136
+ toast.error = msg => toast(msg, 'error')
52
137
  ```
53
138
 
54
139
  ## How it works
@@ -109,4 +194,4 @@ import { mx, dom, define, type MxChild, type MxAttrs } from '@tltdsh/mx'
109
194
 
110
195
  ## License
111
196
 
112
- [0BSD](./LICENSE) — do whatever you want.
197
+ 0BSD — do whatever you want.
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@tltdsh/mx",
3
- "version": "1.0.1",
4
- "description": "Reactive UI library in 890 bytes. 4 globals, zero dependencies, no build step.",
3
+ "version": "1.0.2",
4
+ "description": "Expressive UI library in 890 bytes for building high-end, enterprise-level applications. 4 globals, zero dependencies, no build step.",
5
5
  "license": "0BSD",
6
6
  "author": "tltdsh",
7
7
  "homepage": "https://mxjs.dev",
8
+
8
9
  "main": "mx.min.js",
9
10
  "module": "mx.mjs",
10
11
  "types": "mx.d.ts",
@@ -19,7 +20,8 @@
19
20
  "files": [
20
21
  "mx.min.js",
21
22
  "mx.mjs",
22
- "mx.d.ts"
23
+ "mx.d.ts",
24
+ "LICENSE"
23
25
  ],
24
26
  "sideEffects": true,
25
27
  "keywords": [
@@ -30,12 +32,17 @@
30
32
  "engine",
31
33
  "protocol",
32
34
  "reactive",
35
+ "expressive",
33
36
  "render",
37
+ "rendering",
34
38
  "reconciliation",
35
39
  "virtual-dom",
36
40
  "components",
41
+ "component-library",
37
42
  "custom-elements",
38
43
  "web-components",
44
+ "enterprise",
45
+ "production",
39
46
  "tiny",
40
47
  "lightweight",
41
48
  "minimal",
@@ -44,6 +51,7 @@
44
51
  "fast",
45
52
  "performant",
46
53
  "efficient",
54
+ "high-performance",
47
55
  "no-dependencies",
48
56
  "zero-dependencies",
49
57
  "no-build",
@@ -52,19 +60,40 @@
52
60
  "no-jsx",
53
61
  "no-virtual-dom",
54
62
  "dom-first",
63
+ "dom-manipulation",
55
64
  "svg",
56
65
  "frontend",
57
66
  "front-end",
58
67
  "view",
68
+ "view-layer",
59
69
  "template",
70
+ "templating",
60
71
  "declarative",
61
72
  "state-management",
73
+ "state",
62
74
  "vanilla",
63
75
  "vanilla-js",
64
76
  "plain-js",
65
77
  "browser",
66
78
  "client-side",
67
79
  "spa",
68
- "single-page-app"
80
+ "single-page-app",
81
+ "web",
82
+ "webapp",
83
+ "web-app",
84
+ "html",
85
+ "javascript",
86
+ "js",
87
+ "ui-library",
88
+ "ui-framework",
89
+ "ui-engine",
90
+ "element",
91
+ "node",
92
+ "tree",
93
+ "diff",
94
+ "patch",
95
+ "proxy",
96
+ "keyed",
97
+ "keyed-list"
69
98
  ]
70
99
  }