@e280/sly 0.2.0-5 → 0.2.0-7
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/README.md +61 -36
- package/package.json +1 -1
- package/s/demo/views/counter.ts +1 -1
- package/s/demo/views/incredi.ts +2 -2
- package/s/dom/dom.ts +10 -1
- package/s/dom/register.ts +4 -1
- package/s/index.ts +2 -2
- package/s/views/base-element.ts +1 -1
- package/s/views/use.ts +7 -6
- package/x/demo/demo.bundle.min.js +13 -13
- package/x/demo/demo.bundle.min.js.map +4 -4
- package/x/demo/views/counter.js +1 -1
- package/x/demo/views/counter.js.map +1 -1
- package/x/demo/views/incredi.d.ts +1 -1
- package/x/demo/views/incredi.js +2 -2
- package/x/demo/views/incredi.js.map +1 -1
- package/x/dom/attributes.js.map +1 -0
- package/x/dom/dom.d.ts +5 -1
- package/x/dom/dom.js +5 -0
- package/x/dom/dom.js.map +1 -1
- package/x/dom/register.d.ts +5 -1
- package/x/dom/register.js.map +1 -1
- package/x/index.d.ts +2 -2
- package/x/index.html +2 -2
- package/x/index.js +2 -2
- package/x/index.js.map +1 -1
- package/x/views/base-element.js +1 -1
- package/x/views/base-element.js.map +1 -1
- package/x/views/use.d.ts +4 -4
- package/x/views/use.js +7 -6
- package/x/views/use.js.map +1 -1
- package/s/dom/types.ts +0 -8
- package/x/dom/types.d.ts +0 -7
- package/x/dom/types.js +0 -2
- package/x/dom/types.js.map +0 -1
- package/x/views/attributes.js.map +0 -1
- /package/s/{views → dom}/attributes.ts +0 -0
- /package/x/{views → dom}/attributes.d.ts +0 -0
- /package/x/{views → dom}/attributes.js +0 -0
package/README.md
CHANGED
|
@@ -4,15 +4,14 @@
|
|
|
4
4
|
# 🦝 sly
|
|
5
5
|
> *mischievous shadow views*
|
|
6
6
|
|
|
7
|
-
[@e280](https://e280.org/)'s shiny
|
|
8
|
-
sly replaces its predecessor, [slate](https://github.com/benevolent-games/slate).
|
|
7
|
+
[@e280](https://e280.org/)'s shiny new [lit](https://lit.dev/)-based frontend lib for webdevs. *(sly replaces its predecessor, [slate](https://github.com/benevolent-games/slate))*
|
|
9
8
|
|
|
10
|
-
- 🍋 **views** — hooks-based, shadow-dom'd, componentizable
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- 🫛 **ops** — tools for async operations and loading spinners
|
|
14
|
-
- 🪙 **loot** — drag-and-drop facilities
|
|
15
|
-
- 🧪
|
|
9
|
+
- 🍋 [**views**](#views) — hooks-based, shadow-dom'd, componentizable
|
|
10
|
+
- 🪵 [**base element**](#base-element) — for a more classical experience
|
|
11
|
+
- 🪄 [**dom**](#dom) — the "it's not jquery" multitool
|
|
12
|
+
- 🫛 [**ops**](#ops) — tools for async operations and loading spinners
|
|
13
|
+
- 🪙 [**loot**](#loot) — drag-and-drop facilities
|
|
14
|
+
- 🧪 testing page — https://sly.e280.org/
|
|
16
15
|
|
|
17
16
|
|
|
18
17
|
|
|
@@ -25,14 +24,15 @@ npm install @e280/sly lit
|
|
|
25
24
|
```
|
|
26
25
|
|
|
27
26
|
> [!NOTE]
|
|
28
|
-
> - 🔥 [lit](https://lit.dev/) for html rendering
|
|
27
|
+
> - 🔥 [lit](https://lit.dev/), for html rendering
|
|
29
28
|
> - ⛏️ [@e280/strata](https://github.com/e280/strata), for state management (signals, state trees)
|
|
30
|
-
> - 🏂 [@e280/stz](https://github.com/e280/stz)
|
|
31
|
-
> - 🐢 [scute](https://github.com/e280/scute)
|
|
29
|
+
> - 🏂 [@e280/stz](https://github.com/e280/stz), our ts standard library
|
|
30
|
+
> - 🐢 [@e280/scute](https://github.com/e280/scute), our buildy-bundly-buddy
|
|
32
31
|
|
|
33
32
|
|
|
34
33
|
|
|
35
34
|
<br/><br/>
|
|
35
|
+
<a id="views"></a>
|
|
36
36
|
|
|
37
37
|
## 🦝🍋 sly views
|
|
38
38
|
> *views are the crown jewel of sly.. shadow-dom'd.. hooks-based.. "ergonomics"..*
|
|
@@ -151,9 +151,9 @@ import {html, css} from "lit"
|
|
|
151
151
|
// write the signal
|
|
152
152
|
$count(2)
|
|
153
153
|
```
|
|
154
|
-
- `
|
|
154
|
+
- `derived` signals
|
|
155
155
|
```ts
|
|
156
|
-
const $product = use.
|
|
156
|
+
const $product = use.derived(() => $count() * $whatever())
|
|
157
157
|
```
|
|
158
158
|
- `lazy` signals
|
|
159
159
|
```ts
|
|
@@ -198,7 +198,8 @@ import {html, css} from "lit"
|
|
|
198
198
|
|
|
199
199
|
v // 123
|
|
200
200
|
```
|
|
201
|
-
- **use.attrs** — ergonomic typed html attribute access
|
|
201
|
+
- **use.attrs** — ergonomic typed html attribute access
|
|
202
|
+
*(see [dom.attrs](#dom.attrs) for more details)*
|
|
202
203
|
```ts
|
|
203
204
|
const attrs = use.attrs({
|
|
204
205
|
name: String,
|
|
@@ -211,14 +212,6 @@ import {html, css} from "lit"
|
|
|
211
212
|
attrs.count // 123
|
|
212
213
|
attrs.active // true
|
|
213
214
|
```
|
|
214
|
-
```ts
|
|
215
|
-
attrs.name = "zenky"
|
|
216
|
-
attrs.count = 124
|
|
217
|
-
attrs.active = false // removes html attr
|
|
218
|
-
```
|
|
219
|
-
```ts
|
|
220
|
-
attrs.name = undefined // removes the attr
|
|
221
|
-
```
|
|
222
215
|
- **use.render** — rerender the view (debounced)
|
|
223
216
|
```ts
|
|
224
217
|
use.render()
|
|
@@ -269,12 +262,13 @@ import {html, css} from "lit"
|
|
|
269
262
|
|
|
270
263
|
|
|
271
264
|
<br/><br/>
|
|
265
|
+
<a id="base-element"></a>
|
|
272
266
|
|
|
273
267
|
## 🦝🪵 sly base element
|
|
274
268
|
> *the classic experience*
|
|
275
269
|
|
|
276
270
|
```ts
|
|
277
|
-
import {BaseElement, Use,
|
|
271
|
+
import {BaseElement, Use, dom} from "@e280/sly"
|
|
278
272
|
import {html, css} from "lit"
|
|
279
273
|
```
|
|
280
274
|
|
|
@@ -294,7 +288,7 @@ base element enjoys the same `use` hooks as views.
|
|
|
294
288
|
start = 10
|
|
295
289
|
|
|
296
290
|
// custom attributes
|
|
297
|
-
attrs =
|
|
291
|
+
attrs = dom.attrs(this, {
|
|
298
292
|
multiply: Number,
|
|
299
293
|
})
|
|
300
294
|
|
|
@@ -338,7 +332,7 @@ base element enjoys the same `use` hooks as views.
|
|
|
338
332
|
myElement.start = 100
|
|
339
333
|
|
|
340
334
|
// html attributes
|
|
341
|
-
myElement.
|
|
335
|
+
myElement.attrs.multiply = 2
|
|
342
336
|
|
|
343
337
|
// methods
|
|
344
338
|
myElement.hello()
|
|
@@ -348,6 +342,7 @@ base element enjoys the same `use` hooks as views.
|
|
|
348
342
|
|
|
349
343
|
|
|
350
344
|
<br/><br/>
|
|
345
|
+
<a id="dom"></a>
|
|
351
346
|
|
|
352
347
|
## 🦝🪄 sly dom
|
|
353
348
|
> *the "it's not jquery!" multitool*
|
|
@@ -403,10 +398,33 @@ import {dom} from "@e280/sly"
|
|
|
403
398
|
```ts
|
|
404
399
|
dom.render(element, html`<p>hello world</p>`)
|
|
405
400
|
```
|
|
401
|
+
- `attrs` <a id="dom.attrs"></a> to setup a type-happy html attribute helper
|
|
402
|
+
```ts
|
|
403
|
+
const attrs = dom.attrs(element, {
|
|
404
|
+
name: String,
|
|
405
|
+
count: Number,
|
|
406
|
+
active: Boolean,
|
|
407
|
+
})
|
|
408
|
+
```
|
|
409
|
+
```ts
|
|
410
|
+
attrs.name // "chase"
|
|
411
|
+
attrs.count // 123
|
|
412
|
+
attrs.active // true
|
|
413
|
+
```
|
|
414
|
+
```ts
|
|
415
|
+
attrs.name = "zenky"
|
|
416
|
+
attrs.count = 124
|
|
417
|
+
attrs.active = false // removes html attr
|
|
418
|
+
```
|
|
419
|
+
```ts
|
|
420
|
+
attrs.name = undefined // removes the attr
|
|
421
|
+
attrs.count = undefined // removes the attr
|
|
422
|
+
```
|
|
406
423
|
|
|
407
424
|
|
|
408
425
|
|
|
409
426
|
<br/><br/>
|
|
427
|
+
<a id="ops"></a>
|
|
410
428
|
|
|
411
429
|
## 🦝🫛 sly ops
|
|
412
430
|
> *tools for async operations and loading spinners*
|
|
@@ -536,12 +554,14 @@ import {Pod, podium, Op, makeLoader, anims} from "@e280/sly"
|
|
|
536
554
|
|
|
537
555
|
|
|
538
556
|
<br/><br/>
|
|
557
|
+
<a id="loot"></a>
|
|
539
558
|
|
|
540
559
|
## 🦝🪙 loot
|
|
541
560
|
> *drag-and-drop facilities*
|
|
542
561
|
|
|
543
562
|
```ts
|
|
544
|
-
import {loot,
|
|
563
|
+
import {loot, view, dom} from "@e280/sly"
|
|
564
|
+
import {ev} from "@e280/stz"
|
|
545
565
|
```
|
|
546
566
|
|
|
547
567
|
### 🪙 `loot.Drops`
|
|
@@ -571,18 +591,20 @@ import {loot, ev, view} from "@e280/sly"
|
|
|
571
591
|
```
|
|
572
592
|
- **vanilla-js whole-page example**
|
|
573
593
|
```ts
|
|
574
|
-
// attach listeners to
|
|
594
|
+
// attach listeners to the body
|
|
575
595
|
ev(document.body, {
|
|
576
596
|
dragover: drops.dragover,
|
|
577
597
|
dragleave: drops.dragleave,
|
|
578
598
|
drop: drops.drop,
|
|
579
599
|
})
|
|
580
600
|
|
|
581
|
-
//
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
else document.body.removeAttribute("data-indicator")
|
|
601
|
+
// sly attribute handler for the body
|
|
602
|
+
const attrs = dom.attrs(document.body, {
|
|
603
|
+
"data-indicator": Boolean,
|
|
585
604
|
})
|
|
605
|
+
|
|
606
|
+
// sync the data-indicator attribute
|
|
607
|
+
drops.$indicator.on(bool => attrs["data-indicator"] = bool)
|
|
586
608
|
```
|
|
587
609
|
- **flashy css indicator for the dropzone,** so the user knows your app is eager to accept the drop
|
|
588
610
|
```css
|
|
@@ -593,7 +615,7 @@ import {loot, ev, view} from "@e280/sly"
|
|
|
593
615
|
|
|
594
616
|
### 🪙 `loot.DragAndDrops`
|
|
595
617
|
> *setup drag-and-drops between items within your page*
|
|
596
|
-
- **declare types for your
|
|
618
|
+
- **declare types for your draggy and droppy things**
|
|
597
619
|
```ts
|
|
598
620
|
// money that can be picked up and dragged
|
|
599
621
|
type Money = {value: number}
|
|
@@ -611,8 +633,7 @@ import {loot, ev, view} from "@e280/sly"
|
|
|
611
633
|
},
|
|
612
634
|
})
|
|
613
635
|
```
|
|
614
|
-
- **attach dragzone listeners**
|
|
615
|
-
(there can be many dragzones...)
|
|
636
|
+
- **attach dragzone listeners** (there can be many dragzones...)
|
|
616
637
|
```ts
|
|
617
638
|
view(use => () => {
|
|
618
639
|
const money = use.once((): Money => ({value: 280}))
|
|
@@ -628,8 +649,7 @@ import {loot, ev, view} from "@e280/sly"
|
|
|
628
649
|
`
|
|
629
650
|
})
|
|
630
651
|
```
|
|
631
|
-
- **attach dropzone listeners**
|
|
632
|
-
(there can be many dropzones...)
|
|
652
|
+
- **attach dropzone listeners** (there can be many dropzones...)
|
|
633
653
|
```ts
|
|
634
654
|
view(use => () => {
|
|
635
655
|
const bag = use.once((): Bag => ({id: 1}))
|
|
@@ -656,8 +676,13 @@ import {loot, ev, view} from "@e280/sly"
|
|
|
656
676
|
|
|
657
677
|
|
|
658
678
|
<br/><br/>
|
|
679
|
+
<a id="e280"></a>
|
|
659
680
|
|
|
660
681
|
## 🦝🧑💻 sly is by e280
|
|
661
682
|
reward us with github stars
|
|
662
683
|
build with us at https://e280.org/ but only if you're cool
|
|
663
684
|
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
<br/><br/>
|
|
688
|
+
|
package/package.json
CHANGED
package/s/demo/views/counter.ts
CHANGED
package/s/demo/views/incredi.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
import {css, html} from "lit"
|
|
3
3
|
import {nap, repeat} from "@e280/stz"
|
|
4
4
|
|
|
5
|
+
import {dom} from "../../dom/dom.js"
|
|
5
6
|
import {Use} from "../../views/use.js"
|
|
6
|
-
import {attributes} from "../../views/attributes.js"
|
|
7
7
|
import {BaseElement} from "../../views/base-element.js"
|
|
8
8
|
|
|
9
9
|
export class IncrediElement extends BaseElement {
|
|
10
10
|
static styles = css`span{color:orange}`
|
|
11
|
-
attrs =
|
|
11
|
+
attrs = dom.attrs(this, {value: Number})
|
|
12
12
|
something = {whatever: "rofl"}
|
|
13
13
|
|
|
14
14
|
render(use: Use) {
|
package/s/dom/dom.ts
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import {render} from "lit"
|
|
3
3
|
import {register} from "./register.js"
|
|
4
4
|
import {Content} from "../views/types.js"
|
|
5
|
-
import {
|
|
5
|
+
import {attributes, AttrSpec, AttrTypes} from "./attributes.js"
|
|
6
|
+
|
|
7
|
+
export type Renderable = HTMLElement | ShadowRoot | DocumentFragment
|
|
8
|
+
export type Queryable = HTMLElement | ShadowRoot | Element | Document | DocumentFragment
|
|
6
9
|
|
|
7
10
|
function require<E extends Element>(
|
|
8
11
|
container: Queryable,
|
|
@@ -41,6 +44,10 @@ export class Dom<C extends Queryable> {
|
|
|
41
44
|
render(...content: Content[]) {
|
|
42
45
|
return render(content, this.element as Renderable)
|
|
43
46
|
}
|
|
47
|
+
|
|
48
|
+
attrs<A extends AttrSpec>(spec: A) {
|
|
49
|
+
return attributes(this.element as HTMLElement, spec)
|
|
50
|
+
}
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
export function dom<E extends Queryable>(selector: string): E
|
|
@@ -56,6 +63,8 @@ dom.in = doc.in.bind(doc)
|
|
|
56
63
|
dom.require = doc.require.bind(doc)
|
|
57
64
|
dom.maybe = doc.maybe.bind(doc)
|
|
58
65
|
dom.all = doc.all.bind(doc)
|
|
66
|
+
|
|
67
|
+
dom.attrs = attributes
|
|
59
68
|
dom.register = register
|
|
60
69
|
dom.render = (container: Renderable, ...content: Content[]) => {
|
|
61
70
|
return render(content, container)
|
package/s/dom/register.ts
CHANGED
package/s/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
+
export * from "./dom/attributes.js"
|
|
2
3
|
export * from "./dom/dashify.js"
|
|
3
4
|
export * from "./dom/dom.js"
|
|
4
5
|
export * from "./dom/register.js"
|
|
5
|
-
export * from "./dom/types.js"
|
|
6
6
|
|
|
7
7
|
export * from "./ops/loaders/make-loader.js"
|
|
8
8
|
export * from "./ops/loaders/parts/ascii-anim.js"
|
|
@@ -13,7 +13,7 @@ export * from "./ops/types.js"
|
|
|
13
13
|
|
|
14
14
|
export * as loot from "./loot/index.js"
|
|
15
15
|
|
|
16
|
-
export * from "./
|
|
16
|
+
export * from "./dom/attributes.js"
|
|
17
17
|
export * from "./views/base-element.js"
|
|
18
18
|
export * from "./views/css-reset.js"
|
|
19
19
|
export * from "./views/types.js"
|
package/s/views/base-element.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {debounce, MapG} from "@e280/stz"
|
|
|
5
5
|
|
|
6
6
|
import {dom} from "../dom/dom.js"
|
|
7
7
|
import {Content} from "./types.js"
|
|
8
|
-
import {onAttrChange} from "
|
|
8
|
+
import {onAttrChange} from "../dom/attributes.js"
|
|
9
9
|
import {applyStyles} from "./utils/apply-styles.js"
|
|
10
10
|
import {Use, _disconnect, _reconnect, _wrap} from "./use.js"
|
|
11
11
|
|
package/s/views/use.ts
CHANGED
|
@@ -4,9 +4,10 @@ import {defer, MapG} from "@e280/stz"
|
|
|
4
4
|
import {signal, SignalOptions} from "@e280/strata/signals"
|
|
5
5
|
|
|
6
6
|
import {Op} from "../ops/op.js"
|
|
7
|
+
import {dom} from "../dom/dom.js"
|
|
7
8
|
import {Mounts} from "./utils/mounts.js"
|
|
8
9
|
import {applyStyles} from "./utils/apply-styles.js"
|
|
9
|
-
import {
|
|
10
|
+
import {AttrSpec, onAttrChange} from "../dom/attributes.js"
|
|
10
11
|
|
|
11
12
|
export const _wrap = Symbol()
|
|
12
13
|
export const _disconnect = Symbol()
|
|
@@ -66,7 +67,7 @@ export class Use {
|
|
|
66
67
|
|
|
67
68
|
attrs<A extends AttrSpec>(spec: A) {
|
|
68
69
|
this.mount(() => onAttrChange(this.element, this.render))
|
|
69
|
-
return this.once(() =>
|
|
70
|
+
return this.once(() => dom.attrs(this.element, spec))
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
once<V>(fn: () => V) {
|
|
@@ -106,8 +107,8 @@ export class Use {
|
|
|
106
107
|
function sig<V>(value: V, options?: Partial<SignalOptions>) {
|
|
107
108
|
return that.once(() => signal<V>(value, options))
|
|
108
109
|
}
|
|
109
|
-
sig.
|
|
110
|
-
return that.once(() => signal.
|
|
110
|
+
sig.derived = function derived<V>(formula: () => V, options?: Partial<SignalOptions>) {
|
|
111
|
+
return that.once(() => signal.derived<V>(formula, options))
|
|
111
112
|
}
|
|
112
113
|
sig.lazy = function lazy<V>(formula: () => V, options?: Partial<SignalOptions>) {
|
|
113
114
|
return that.once(() => signal.lazy<V>(formula, options))
|
|
@@ -115,8 +116,8 @@ export class Use {
|
|
|
115
116
|
return sig
|
|
116
117
|
})()
|
|
117
118
|
|
|
118
|
-
|
|
119
|
-
return this.once(() => signal.
|
|
119
|
+
derived<V>(formula: () => V, options?: Partial<SignalOptions>) {
|
|
120
|
+
return this.once(() => signal.derived<V>(formula, options))
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
lazy<V>(formula: () => V, options?: Partial<SignalOptions>) {
|