@ktfth/stickjs 3.0.3 → 3.0.4
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 +26 -5
- package/README.md +51 -3
- package/llms.txt +11 -2
- package/package.json +1 -1
- package/stick.d.ts +1 -1
- package/stick.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,17 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to Stick.js will be documented here.
|
|
4
4
|
|
|
5
|
-
## v3.
|
|
6
|
-
|
|
7
|
-
### New features
|
|
5
|
+
## v3.0.4 — fetch-json, then chains, cross-element interpolation, dark mode
|
|
6
|
+
|
|
7
|
+
### New features (stick.js)
|
|
8
|
+
- **`fetch-json` handler** — GET URL, parse JSON, map fields to DOM elements via `data-stick-map="#sel:Field, …"`
|
|
9
|
+
- **`data-stick-then`** — post-fetch action chain: `"handler:target:param, …"` executes sequentially after fetch/fetch-json succeeds
|
|
10
|
+
- **Cross-element interpolation `{{#sel.prop}}`** — resolve values from any element on the page (e.g. `{{#filtro.value}}`)
|
|
11
|
+
- **`data-stick-accept="json"` + `data-stick-template`** — parse fetch response as JSON array, clone `<template>` per item with `{{field}}` interpolation
|
|
12
|
+
- **`data-stick-state-loading/done/error`** — lifecycle state actions during fetch: `"add-class:loading:#container, disable:#btn"` etc.
|
|
13
|
+
|
|
14
|
+
### New features (stick-ui.css)
|
|
15
|
+
- **Dark mode** — `--sui-*` custom properties with `prefers-color-scheme` and `data-theme="dark"` support; `--stk-*` backward-compatible aliases
|
|
16
|
+
- **Generic `.btn` / `.btn-primary` / `.btn-danger`** classes — non-prefixed aliases for quick prototyping
|
|
17
|
+
- **Badge** (`.badge`, `.stk-badge`) — info/success/warning/danger variants
|
|
18
|
+
- **Alert** (`.alert`, `.stk-alert`) — success/danger/warning/info with left-border accent
|
|
19
|
+
- **Form group** (`.form-group`, `.stk-form-group`) — label + input layout with dark mode support
|
|
20
|
+
- **Section header** (`.section-header`, `.stk-section-header`) — title + action bar with border
|
|
21
|
+
- **Generic `dialog`** base styles — centering, backdrop, animation
|
|
22
|
+
- **Generic form hover/focus** — dark-safe `input:hover`, `select:hover`, `textarea:hover`
|
|
23
|
+
|
|
24
|
+
### Bug fixes (stick-ui.css)
|
|
25
|
+
- Table row hover no longer darkens text in dark mode
|
|
26
|
+
- Button hover states preserve text color
|
|
27
|
+
- `.stk-btn-primary:hover` / `.stk-btn-destructive:hover` explicitly set color
|
|
28
|
+
- Focus ring `box-shadow` uses `var(--sui-ring-shadow)` instead of hardcoded rgba
|
|
29
|
+
|
|
30
|
+
### CLI & Infrastructure
|
|
8
31
|
- **CLI** — `npx stickjs add <component>` copies component files to `./stick-ui/` (shadcn/ui-style)
|
|
9
32
|
- **`npx stickjs list`** — list all 15 available components
|
|
10
33
|
- **`npx stickjs add --all`** — add all components at once
|
|
11
34
|
- **`--force` flag** — overwrite existing files
|
|
12
35
|
- **CDN** — all files available via jsdelivr and unpkg after npm publish
|
|
13
36
|
- **Release script** — `npm run release` minifies, publishes to npm, and deploys docs to Vercel
|
|
14
|
-
|
|
15
|
-
### Infrastructure
|
|
16
37
|
- Vercel deployment for documentation site (`docs/vercel.json`)
|
|
17
38
|
- `bin/registry.json` component manifest
|
|
18
39
|
- `bin/stickjs.js` zero-dependency CLI (Node built-ins only)
|
package/README.md
CHANGED
|
@@ -62,6 +62,13 @@ data-stick="event:handler:param"
|
|
|
62
62
|
| `data-stick-headers='{"Authorization":"Bearer TOKEN"}'` | Fetch headers (JSON string) |
|
|
63
63
|
| `data-stick-json='{"key":"{{value}}"}'` | JSON body for fetch POST (auto-sets Content-Type) |
|
|
64
64
|
| `data-stick-error="#el"` | Element to display fetch errors |
|
|
65
|
+
| `data-stick-map="#sel:Field, …"` | JSON field → DOM mapping for `fetch-json` handler |
|
|
66
|
+
| `data-stick-then="handler:tgt:p, …"` | Post-fetch action chain — executes sequentially after success |
|
|
67
|
+
| `data-stick-accept="json"` | Parse fetch response as JSON array (use with `data-stick-template`) |
|
|
68
|
+
| `data-stick-template="#tpl"` | `<template>` for JSON array rendering (with `accept=json`) |
|
|
69
|
+
| `data-stick-state-loading="…"` | State actions when fetch starts (e.g. `"add-class:loading:#el, disable:#btn"`) |
|
|
70
|
+
| `data-stick-state-done="…"` | State actions when fetch succeeds |
|
|
71
|
+
| `data-stick-state-error="…"` | State actions when fetch fails |
|
|
65
72
|
|
|
66
73
|
### Target selectors
|
|
67
74
|
|
|
@@ -95,6 +102,7 @@ Tokens in `param` are resolved at event time from the **trigger element**:
|
|
|
95
102
|
| `{{data-foo}}` | `el.dataset.foo` |
|
|
96
103
|
| `{{url:key}}` | `URLSearchParams` value from the current page URL (e.g. `{{url:q}}` → `?q=value`) |
|
|
97
104
|
| `{{href}}`, `{{src}}`, etc. | Any attribute via `el.getAttribute(name)` |
|
|
105
|
+
| `{{#sel.prop}}` | Cross-element: `querySelector(sel).prop` — e.g. `{{#myInput.value}}` |
|
|
98
106
|
|
|
99
107
|
### Synthetic events
|
|
100
108
|
|
|
@@ -235,7 +243,8 @@ Tokens in `param` are resolved at event time from the **trigger element**:
|
|
|
235
243
|
|
|
236
244
|
| Handler | Notes |
|
|
237
245
|
|---------|-------|
|
|
238
|
-
| `fetch` | Fetch `param` URL, inject response HTML into `target`. Supports `data-stick-method`, `data-stick-swap`, `data-stick-loading`, `data-stick-headers`, `data-stick-json`, `data-stick-error
|
|
246
|
+
| `fetch` | Fetch `param` URL, inject response HTML into `target`. Supports `data-stick-method`, `data-stick-swap`, `data-stick-loading`, `data-stick-headers`, `data-stick-json`, `data-stick-error`, `data-stick-accept`, `data-stick-template`, `data-stick-then`, `data-stick-state-*`. |
|
|
247
|
+
| `fetch-json` | GET `param` URL, parse JSON, map fields to DOM elements via `data-stick-map="#sel:Field, …"`. Supports `data-stick-then`, `data-stick-state-*`. |
|
|
239
248
|
|
|
240
249
|
### Debug
|
|
241
250
|
|
|
@@ -366,6 +375,45 @@ Tokens in `param` are resolved at event time from the **trigger element**:
|
|
|
366
375
|
|
|
367
376
|
<!-- Pre-fill search from URL ?q= param -->
|
|
368
377
|
<input data-stick="ready:set-value:{{url:q}}" data-stick-target="self">
|
|
378
|
+
|
|
379
|
+
<!-- fetch-json: map API fields to multiple elements -->
|
|
380
|
+
<div data-stick="ready:fetch-json:/api/kpis"
|
|
381
|
+
data-stick-map="#total:Total, #pending:Pending, #pct:Percent">
|
|
382
|
+
</div>
|
|
383
|
+
<span id="total">–</span> | <span id="pending">–</span> | <span id="pct">–</span>
|
|
384
|
+
|
|
385
|
+
<!-- Cross-element interpolation: combine filters from 2+ inputs -->
|
|
386
|
+
<select id="region"><option>North</option><option>South</option></select>
|
|
387
|
+
<select id="status"><option>active</option><option>closed</option></select>
|
|
388
|
+
<button data-stick="click:fetch:/api/data?region={{#region.value}}&status={{#status.value}}"
|
|
389
|
+
data-stick-target="#results">Filter</button>
|
|
390
|
+
|
|
391
|
+
<!-- Fetch JSON array → template cloning -->
|
|
392
|
+
<template id="row-tpl">
|
|
393
|
+
<tr><td>{{name}}</td><td>{{score}}</td></tr>
|
|
394
|
+
</template>
|
|
395
|
+
<button data-stick="click:fetch:/api/users"
|
|
396
|
+
data-stick-accept="json"
|
|
397
|
+
data-stick-template="#row-tpl"
|
|
398
|
+
data-stick-target="#tbody">Load users</button>
|
|
399
|
+
<table><tbody id="tbody"></tbody></table>
|
|
400
|
+
|
|
401
|
+
<!-- Post-fetch then chain: close modal + refresh table -->
|
|
402
|
+
<form data-stick="submit:fetch:/api/save"
|
|
403
|
+
data-stick-method="POST"
|
|
404
|
+
data-stick-target="#feedback"
|
|
405
|
+
data-stick-then="close-modal:#dialog, fetch:#table:/api/list">
|
|
406
|
+
<input name="name">
|
|
407
|
+
<button type="submit">Save</button>
|
|
408
|
+
</form>
|
|
409
|
+
|
|
410
|
+
<!-- Fetch lifecycle state management -->
|
|
411
|
+
<button data-stick="click:fetch:/api/report"
|
|
412
|
+
data-stick-target="#output"
|
|
413
|
+
data-stick-state-loading="add-class:loading:#container, disable:#submit"
|
|
414
|
+
data-stick-state-done="remove-class:loading:#container, enable:#submit"
|
|
415
|
+
data-stick-state-error="add-class:error:#container"
|
|
416
|
+
id="submit">Generate</button>
|
|
369
417
|
```
|
|
370
418
|
|
|
371
419
|
---
|
|
@@ -373,7 +421,7 @@ Tokens in `param` are resolved at event time from the **trigger element**:
|
|
|
373
421
|
## JavaScript API
|
|
374
422
|
|
|
375
423
|
```js
|
|
376
|
-
Stick.version // "
|
|
424
|
+
Stick.version // "3.0.4"
|
|
377
425
|
|
|
378
426
|
Stick.add(name, fn) // register a handler — chainable
|
|
379
427
|
Stick.remove(name) // unregister a handler — chainable
|
|
@@ -425,7 +473,7 @@ Stick.bind(el);
|
|
|
425
473
|
|
|
426
474
|
## Testing
|
|
427
475
|
|
|
428
|
-
Open `test/stick.test.html` in a browser. Covers
|
|
476
|
+
Open `test/stick.test.html` in a browser. Covers 170+ assertions across all handlers, modifiers, and edge cases.
|
|
429
477
|
|
|
430
478
|
---
|
|
431
479
|
|
package/llms.txt
CHANGED
|
@@ -38,6 +38,13 @@ data-stick-loading="Loading…" — button text while fetch is in-flight
|
|
|
38
38
|
data-stick-headers='{"Authorization":"Bearer TOKEN"}' — fetch headers (JSON string)
|
|
39
39
|
data-stick-json='{"key":"{{value}}"}' — JSON body for fetch POST
|
|
40
40
|
data-stick-error="#error-el" — element to show fetch errors in
|
|
41
|
+
data-stick-map="#sel:Field, …" — JSON field → DOM mapping for fetch-json handler
|
|
42
|
+
data-stick-then="handler:tgt:p, …" — post-fetch action chain (sequential)
|
|
43
|
+
data-stick-accept="json" — parse fetch response as JSON array
|
|
44
|
+
data-stick-template="#tpl" — <template> for JSON array rendering (with accept=json)
|
|
45
|
+
data-stick-state-loading="…" — state actions when fetch starts (e.g. "add-class:loading:#el")
|
|
46
|
+
data-stick-state-done="…" — state actions when fetch succeeds
|
|
47
|
+
data-stick-state-error="…" — state actions when fetch fails
|
|
41
48
|
data-stick-group="name" — mutual exclusivity: show/toggle/show-modal hides others in same group
|
|
42
49
|
data-stick-transition="name" — CSS enter/leave transitions: adds name-enter-active / name-leave-active classes with automatic cleanup
|
|
43
50
|
```
|
|
@@ -69,6 +76,7 @@ data-stick-transition="name" — CSS enter/leave transitions: adds name-en
|
|
|
69
76
|
{{url:key}} URLSearchParams value from current page URL (e.g. {{url:q}} for ?q=)
|
|
70
77
|
{{data-foo}} el.dataset.foo
|
|
71
78
|
{{href}} el.getAttribute("href") — any attribute name works
|
|
79
|
+
{{#sel.prop}} cross-element: querySelector(sel).prop (e.g. {{#myInput.value}})
|
|
72
80
|
```
|
|
73
81
|
|
|
74
82
|
## All built-in handlers
|
|
@@ -120,7 +128,8 @@ data-stick-transition="name" — CSS enter/leave transitions: adds name-en
|
|
|
120
128
|
| emit | alias for dispatch |
|
|
121
129
|
| store | localStorage.setItem(key, value) — param: "key:value"|
|
|
122
130
|
| restore | localStorage.getItem(param) → set target value/text |
|
|
123
|
-
| fetch | fetch(param) → inject response into target
|
|
131
|
+
| fetch | fetch(param) → inject response into target; supports accept=json, then, state lifecycle |
|
|
132
|
+
| fetch-json | GET param URL, parse JSON, map fields to DOM via data-stick-map |
|
|
124
133
|
| check | target.checked = true |
|
|
125
134
|
| uncheck | target.checked = false |
|
|
126
135
|
| toggle-check | toggle target.checked |
|
|
@@ -146,7 +155,7 @@ intersect — IntersectionObserver; fires when element enters viewport
|
|
|
146
155
|
## JavaScript API
|
|
147
156
|
|
|
148
157
|
```js
|
|
149
|
-
Stick.version // "3.0.
|
|
158
|
+
Stick.version // "3.0.4"
|
|
150
159
|
Stick.add(name, fn) // register handler; fn(el, param, event, target) => void
|
|
151
160
|
Stick.remove(name) // unregister handler
|
|
152
161
|
Stick.use(plugin) // register plugin: fn(stick) | { install } | { name: fn, … }
|
package/package.json
CHANGED
package/stick.d.ts
CHANGED
package/stick.js
CHANGED