@e280/sly 0.2.0-3 → 0.2.0-30
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 +624 -97
- package/package.json +13 -6
- package/s/base/element.ts +76 -0
- package/s/base/index.ts +6 -0
- package/s/{views → base}/use.ts +25 -16
- package/s/base/utils/attr-watcher.ts +22 -0
- package/s/base/utils/reactor.ts +32 -0
- package/s/base/utils/states.ts +49 -0
- package/s/base/utils/use-attrs.ts +36 -0
- package/s/demo/demo.bundle.ts +9 -5
- package/s/demo/views/counter.ts +21 -24
- package/s/demo/views/demo.ts +10 -6
- package/s/demo/views/fastcount.ts +29 -0
- package/s/demo/views/loaders.ts +7 -7
- package/s/dom/attrs/attrs.ts +21 -0
- package/s/dom/attrs/parts/attr-fns.ts +68 -0
- package/s/dom/attrs/parts/attr-proxies.ts +35 -0
- package/s/dom/attrs/parts/attr-spec.ts +29 -0
- package/s/dom/attrs/parts/on-attrs.ts +8 -0
- package/s/dom/dom.ts +22 -38
- package/s/dom/index.ts +4 -0
- package/s/dom/parts/dom-scope.ts +46 -0
- package/s/dom/parts/el.ts +14 -0
- package/s/dom/parts/elmer.ts +38 -0
- package/s/dom/parts/eve.ts +24 -0
- package/s/dom/parts/mk.ts +9 -0
- package/s/dom/parts/queries.ts +26 -0
- package/s/dom/{register.ts → parts/register.ts} +2 -7
- package/s/dom/types.ts +42 -0
- package/s/index.html.ts +4 -2
- package/s/index.ts +7 -19
- package/s/loaders/index.barrel.ts +10 -0
- package/s/loaders/index.ts +4 -0
- package/s/loaders/make.ts +14 -0
- package/s/loaders/mock.ts +11 -0
- package/s/{ops/loaders → loaders}/parts/anims.ts +1 -1
- package/s/{ops/loaders → loaders}/parts/ascii-anim.ts +6 -5
- package/s/{ops/loaders → loaders}/parts/error-display.ts +2 -2
- package/s/loaders/types.ts +6 -0
- package/s/loot/drag-and-drops.ts +82 -0
- package/s/loot/{drop.ts → drops.ts} +8 -17
- package/s/loot/helpers.ts +3 -3
- package/s/loot/index.barrel.ts +5 -0
- package/s/loot/index.ts +2 -3
- package/s/ops/index.ts +5 -0
- package/s/ops/op.ts +1 -0
- package/s/spa/index.barrel.ts +6 -0
- package/s/spa/index.ts +4 -0
- package/s/spa/plumbing/braces.ts +76 -0
- package/s/spa/plumbing/primitives.ts +85 -0
- package/s/spa/plumbing/router-core.ts +49 -0
- package/s/spa/plumbing/types.ts +45 -0
- package/s/spa/router.ts +49 -0
- package/s/spa/spa.test.ts +91 -0
- package/s/tests.test.ts +4 -1
- package/s/view/index.ts +7 -0
- package/s/view/types.ts +39 -0
- package/s/view/utils/contextualize.ts +45 -0
- package/s/view/utils/make-component.ts +34 -0
- package/s/view/utils/make-view.ts +48 -0
- package/s/view/utils/parts/capsule.ts +67 -0
- package/s/view/utils/parts/chain.ts +40 -0
- package/s/view/utils/parts/context.ts +11 -0
- package/s/view/utils/parts/directive.ts +29 -0
- package/s/view/utils/parts/sly-view.ts +15 -0
- package/s/view/view.ts +24 -0
- package/x/base/css-reset.js.map +1 -0
- package/x/base/element.d.ts +19 -0
- package/x/base/element.js +52 -0
- package/x/base/element.js.map +1 -0
- package/x/base/index.d.ts +4 -0
- package/x/base/index.js +5 -0
- package/x/base/index.js.map +1 -0
- package/x/{views → base}/use.d.ts +8 -4
- package/x/{views → base}/use.js +15 -9
- package/x/base/use.js.map +1 -0
- package/x/base/utils/apply-styles.js.map +1 -0
- package/x/base/utils/attr-watcher.d.ts +8 -0
- package/x/base/utils/attr-watcher.js +20 -0
- package/x/base/utils/attr-watcher.js.map +1 -0
- package/x/base/utils/mounts.js.map +1 -0
- package/x/base/utils/reactor.d.ts +5 -0
- package/x/base/utils/reactor.js +25 -0
- package/x/base/utils/reactor.js.map +1 -0
- package/x/base/utils/states.d.ts +13 -0
- package/x/base/utils/states.js +41 -0
- package/x/base/utils/states.js.map +1 -0
- package/x/base/utils/use-attrs.d.ts +11 -0
- package/x/base/utils/use-attrs.js +18 -0
- package/x/base/utils/use-attrs.js.map +1 -0
- package/x/demo/demo.bundle.js +8 -4
- package/x/demo/demo.bundle.js.map +1 -1
- package/x/demo/demo.bundle.min.js +19 -22
- package/x/demo/demo.bundle.min.js.map +4 -4
- package/x/demo/views/counter.d.ts +374 -1
- package/x/demo/views/counter.js +19 -22
- package/x/demo/views/counter.js.map +1 -1
- package/x/demo/views/demo.d.ts +4 -1
- package/x/demo/views/demo.js +10 -5
- package/x/demo/views/demo.js.map +1 -1
- package/x/demo/views/fastcount.d.ts +12 -0
- package/x/demo/views/fastcount.js +21 -0
- package/x/demo/views/fastcount.js.map +1 -0
- package/x/demo/views/loaders.js +6 -6
- package/x/demo/views/loaders.js.map +1 -1
- package/x/dom/attrs/attrs.d.ts +23 -0
- package/x/dom/attrs/attrs.js +17 -0
- package/x/dom/attrs/attrs.js.map +1 -0
- package/x/dom/attrs/parts/attr-fns.d.ts +16 -0
- package/x/dom/attrs/parts/attr-fns.js +64 -0
- package/x/dom/attrs/parts/attr-fns.js.map +1 -0
- package/x/dom/attrs/parts/attr-proxies.d.ts +8 -0
- package/x/dom/attrs/parts/attr-proxies.js +21 -0
- package/x/dom/attrs/parts/attr-proxies.js.map +1 -0
- package/x/dom/attrs/parts/attr-spec.d.ts +3 -0
- package/x/dom/attrs/parts/attr-spec.js +21 -0
- package/x/dom/attrs/parts/attr-spec.js.map +1 -0
- package/x/dom/attrs/parts/on-attrs.d.ts +2 -0
- package/x/dom/attrs/parts/on-attrs.js +7 -0
- package/x/dom/attrs/parts/on-attrs.js.map +1 -0
- package/x/dom/dom.d.ts +15 -16
- package/x/dom/dom.js +21 -34
- package/x/dom/dom.js.map +1 -1
- package/x/dom/index.d.ts +2 -0
- package/x/dom/index.js +3 -0
- package/x/dom/index.js.map +1 -0
- package/x/dom/parts/dashify.js.map +1 -0
- package/x/dom/parts/dom-scope.d.ts +15 -0
- package/x/dom/parts/dom-scope.js +35 -0
- package/x/dom/parts/dom-scope.js.map +1 -0
- package/x/dom/parts/el.d.ts +2 -0
- package/x/dom/parts/el.js +7 -0
- package/x/dom/parts/el.js.map +1 -0
- package/x/dom/parts/elmer.d.ts +11 -0
- package/x/dom/parts/elmer.js +32 -0
- package/x/dom/parts/elmer.js.map +1 -0
- package/x/dom/parts/eve.d.ts +7 -0
- package/x/dom/parts/eve.js +16 -0
- package/x/dom/parts/eve.js.map +1 -0
- package/x/dom/parts/mk.d.ts +2 -0
- package/x/dom/parts/mk.js +7 -0
- package/x/dom/parts/mk.js.map +1 -0
- package/x/dom/parts/queries.d.ts +4 -0
- package/x/dom/parts/queries.js +13 -0
- package/x/dom/parts/queries.js.map +1 -0
- package/x/dom/{register.d.ts → parts/register.d.ts} +2 -6
- package/x/dom/parts/register.js.map +1 -0
- package/x/dom/types.d.ts +15 -0
- package/x/index.d.ts +7 -16
- package/x/index.html +6 -4
- package/x/index.html.js +4 -2
- package/x/index.html.js.map +1 -1
- package/x/index.js +7 -16
- package/x/index.js.map +1 -1
- package/x/loaders/index.barrel.d.ts +7 -0
- package/x/loaders/index.barrel.js +7 -0
- package/x/loaders/index.barrel.js.map +1 -0
- package/x/loaders/index.d.ts +2 -0
- package/x/loaders/index.js +2 -0
- package/x/loaders/index.js.map +1 -0
- package/x/loaders/make.d.ts +3 -0
- package/x/loaders/make.js +6 -0
- package/x/loaders/make.js.map +1 -0
- package/x/loaders/mock.d.ts +2 -0
- package/x/loaders/mock.js +8 -0
- package/x/loaders/mock.js.map +1 -0
- package/x/{ops/loaders → loaders}/parts/anims.d.ts +1 -1
- package/x/loaders/parts/anims.js.map +1 -0
- package/x/{ops/loaders → loaders}/parts/ascii-anim.d.ts +2 -2
- package/x/{ops/loaders → loaders}/parts/ascii-anim.js +4 -4
- package/x/loaders/parts/ascii-anim.js.map +1 -0
- package/x/loaders/parts/error-display.d.ts +1 -0
- package/x/{ops/loaders → loaders}/parts/error-display.js +2 -2
- package/x/loaders/parts/error-display.js.map +1 -0
- package/x/loaders/types.d.ts +3 -0
- package/x/loaders/types.js.map +1 -0
- package/x/loot/drag-and-drops.d.ts +30 -0
- package/x/loot/drag-and-drops.js +63 -0
- package/x/loot/drag-and-drops.js.map +1 -0
- package/x/loot/{drop.d.ts → drops.d.ts} +3 -5
- package/x/loot/drops.js +25 -0
- package/x/loot/drops.js.map +1 -0
- package/x/loot/helpers.d.ts +3 -3
- package/x/loot/helpers.js +3 -3
- package/x/loot/helpers.js.map +1 -1
- package/x/loot/index.barrel.d.ts +3 -0
- package/x/loot/index.barrel.js +4 -0
- package/x/loot/index.barrel.js.map +1 -0
- package/x/loot/index.d.ts +2 -3
- package/x/loot/index.js +1 -3
- package/x/loot/index.js.map +1 -1
- package/x/ops/index.d.ts +3 -0
- package/x/ops/index.js +4 -0
- package/x/ops/index.js.map +1 -0
- package/x/ops/op.js +1 -0
- package/x/ops/op.js.map +1 -1
- package/x/spa/index.barrel.d.ts +4 -0
- package/x/spa/index.barrel.js +3 -0
- package/x/spa/index.barrel.js.map +1 -0
- package/x/spa/index.d.ts +2 -0
- package/x/spa/index.js +2 -0
- package/x/spa/index.js.map +1 -0
- package/x/spa/plumbing/braces.d.ts +12 -0
- package/x/spa/plumbing/braces.js +55 -0
- package/x/spa/plumbing/braces.js.map +1 -0
- package/x/spa/plumbing/primitives.d.ts +22 -0
- package/x/spa/plumbing/primitives.js +65 -0
- package/x/spa/plumbing/primitives.js.map +1 -0
- package/x/spa/plumbing/router-core.d.ts +13 -0
- package/x/spa/plumbing/router-core.js +38 -0
- package/x/spa/plumbing/router-core.js.map +1 -0
- package/x/spa/plumbing/types.d.ts +35 -0
- package/x/spa/plumbing/types.js +2 -0
- package/x/spa/plumbing/types.js.map +1 -0
- package/x/spa/router.d.ts +16 -0
- package/x/spa/router.js +39 -0
- package/x/spa/router.js.map +1 -0
- package/x/spa/spa.test.d.ts +15 -0
- package/x/spa/spa.test.js +78 -0
- package/x/spa/spa.test.js.map +1 -0
- package/x/tests.test.js +4 -1
- package/x/tests.test.js.map +1 -1
- package/x/view/index.d.ts +5 -0
- package/x/view/index.js +6 -0
- package/x/view/index.js.map +1 -0
- package/x/view/types.d.ts +21 -0
- package/x/view/types.js +2 -0
- package/x/{views → view}/types.js.map +1 -1
- package/x/view/utils/contextualize.d.ts +13 -0
- package/x/view/utils/contextualize.js +18 -0
- package/x/view/utils/contextualize.js.map +1 -0
- package/x/view/utils/make-component.d.ts +5 -0
- package/x/view/utils/make-component.js +17 -0
- package/x/view/utils/make-component.js.map +1 -0
- package/x/view/utils/make-view.d.ts +2 -0
- package/x/view/utils/make-view.js +24 -0
- package/x/view/utils/make-view.js.map +1 -0
- package/x/view/utils/parts/capsule.d.ts +13 -0
- package/x/view/utils/parts/capsule.js +49 -0
- package/x/view/utils/parts/capsule.js.map +1 -0
- package/x/view/utils/parts/chain.d.ts +13 -0
- package/x/view/utils/parts/chain.js +26 -0
- package/x/view/utils/parts/chain.js.map +1 -0
- package/x/view/utils/parts/context.d.ts +9 -0
- package/x/view/utils/parts/context.js +10 -0
- package/x/view/utils/parts/context.js.map +1 -0
- package/x/view/utils/parts/directive.d.ts +5 -0
- package/x/view/utils/parts/directive.js +18 -0
- package/x/view/utils/parts/directive.js.map +1 -0
- package/x/view/utils/parts/sly-view.d.ts +5 -0
- package/x/view/utils/parts/sly-view.js +13 -0
- package/x/view/utils/parts/sly-view.js.map +1 -0
- package/x/view/view.d.ts +11 -0
- package/x/view/view.js +15 -0
- package/x/view/view.js.map +1 -0
- package/s/loot/drag-drop.ts +0 -76
- package/s/ops/loaders/make-loader.ts +0 -18
- package/s/views/attributes.ts +0 -89
- package/s/views/types.ts +0 -40
- package/s/views/utils/apply-attrs.ts +0 -33
- package/s/views/view.ts +0 -150
- package/x/dom/dashify.js.map +0 -1
- package/x/dom/register.js.map +0 -1
- package/x/loot/drag-drop.d.ts +0 -29
- package/x/loot/drag-drop.js +0 -54
- package/x/loot/drag-drop.js.map +0 -1
- package/x/loot/drop.js +0 -32
- package/x/loot/drop.js.map +0 -1
- package/x/ops/loaders/make-loader.d.ts +0 -5
- package/x/ops/loaders/make-loader.js +0 -7
- package/x/ops/loaders/make-loader.js.map +0 -1
- package/x/ops/loaders/parts/anims.js.map +0 -1
- package/x/ops/loaders/parts/ascii-anim.js.map +0 -1
- package/x/ops/loaders/parts/error-display.d.ts +0 -1
- package/x/ops/loaders/parts/error-display.js.map +0 -1
- package/x/views/attributes.d.ts +0 -10
- package/x/views/attributes.js +0 -46
- package/x/views/attributes.js.map +0 -1
- package/x/views/css-reset.js.map +0 -1
- package/x/views/types.d.ts +0 -31
- package/x/views/use.js.map +0 -1
- package/x/views/utils/apply-attrs.d.ts +0 -2
- package/x/views/utils/apply-attrs.js +0 -21
- package/x/views/utils/apply-attrs.js.map +0 -1
- package/x/views/utils/apply-styles.js.map +0 -1
- package/x/views/utils/mounts.js.map +0 -1
- package/x/views/view.d.ts +0 -9
- package/x/views/view.js +0 -116
- package/x/views/view.js.map +0 -1
- /package/s/{views → base}/css-reset.ts +0 -0
- /package/s/{views → base}/utils/apply-styles.ts +0 -0
- /package/s/{views → base}/utils/mounts.ts +0 -0
- /package/s/dom/{dashify.ts → parts/dashify.ts} +0 -0
- /package/x/{views → base}/css-reset.d.ts +0 -0
- /package/x/{views → base}/css-reset.js +0 -0
- /package/x/{views → base}/utils/apply-styles.d.ts +0 -0
- /package/x/{views → base}/utils/apply-styles.js +0 -0
- /package/x/{views → base}/utils/mounts.d.ts +0 -0
- /package/x/{views → base}/utils/mounts.js +0 -0
- /package/x/dom/{dashify.d.ts → parts/dashify.d.ts} +0 -0
- /package/x/dom/{dashify.js → parts/dashify.js} +0 -0
- /package/x/dom/{register.js → parts/register.js} +0 -0
- /package/x/{ops/loaders → loaders}/parts/anims.js +0 -0
- /package/x/{views → loaders}/types.js +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
import {attrGet, attrSet} from "./attr-fns.js"
|
|
3
|
+
import {AttrSpec, AttrTypes} from "../../types.js"
|
|
4
|
+
|
|
5
|
+
/** specify available html attributes and their types and create a proxy accessor */
|
|
6
|
+
export const attrSpec = <A extends AttrSpec>(
|
|
7
|
+
e: HTMLElement,
|
|
8
|
+
spec: A,
|
|
9
|
+
) => new Proxy(spec, {
|
|
10
|
+
|
|
11
|
+
get: (_target, key: string) => {
|
|
12
|
+
switch (spec[key]) {
|
|
13
|
+
case String: return attrGet.string(e, key)
|
|
14
|
+
case Number: return attrGet.number(e, key)
|
|
15
|
+
case Boolean: return attrGet.boolean(e, key)
|
|
16
|
+
default: throw new Error(`invalid attribute type for "${key}"`)
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
set: (_target, key: string, value: any) => {
|
|
21
|
+
switch (spec[key]) {
|
|
22
|
+
case String: return attrSet.string(e, key, value)
|
|
23
|
+
case Number: return attrSet.number(e, key, value)
|
|
24
|
+
case Boolean: return attrSet.boolean(e, key, value)
|
|
25
|
+
default: throw new Error(`invalid attribute type for "${key}"`)
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
}) as any as AttrTypes<A>
|
|
29
|
+
|
package/s/dom/dom.ts
CHANGED
|
@@ -1,51 +1,35 @@
|
|
|
1
1
|
|
|
2
2
|
import {render} from "lit"
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {el} from "./parts/el.js"
|
|
4
|
+
import {mk} from "./parts/mk.js"
|
|
5
|
+
import {eve} from "./parts/eve.js"
|
|
6
|
+
import {attrs} from "./attrs/attrs.js"
|
|
7
|
+
import {elmer} from "./parts/elmer.js"
|
|
8
|
+
import {Content} from "../view/types.js"
|
|
9
|
+
import {Dom} from "./parts/dom-scope.js"
|
|
10
|
+
import {register} from "./parts/register.js"
|
|
5
11
|
import {Queryable, Renderable} from "./types.js"
|
|
12
|
+
import {queryAll, queryMaybe, queryRequire} from "./parts/queries.js"
|
|
6
13
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
in<E extends HTMLElement>(elementOrSelector: E | string) {
|
|
11
|
-
return new Dom(
|
|
12
|
-
typeof elementOrSelector === "string"
|
|
13
|
-
? this.require<E>(elementOrSelector)
|
|
14
|
-
: elementOrSelector
|
|
15
|
-
)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
require<E extends Element = HTMLElement>(selector: string) {
|
|
19
|
-
const e = this.element.querySelector<E>(selector)
|
|
20
|
-
if (!e) throw new Error(`$1 ${selector} not found`)
|
|
21
|
-
return e
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
maybe<E extends Element = HTMLElement>(selector: string) {
|
|
25
|
-
return this.element.querySelector<E>(selector)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
all<E extends Element = HTMLElement>(selector: string) {
|
|
29
|
-
return Array.from(this.element.querySelectorAll<E>(selector))
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
render(...content: Content[]) {
|
|
33
|
-
return render(content, this.element as Renderable)
|
|
34
|
-
}
|
|
14
|
+
export function dom<E extends Element>(selector: string, container: Queryable = document): E {
|
|
15
|
+
return queryRequire<E>(selector, container)
|
|
35
16
|
}
|
|
36
17
|
|
|
37
|
-
|
|
38
|
-
return new Dom(
|
|
18
|
+
dom.in = <E extends HTMLElement>(selectorOrElement: string | E, container: Queryable = document) => {
|
|
19
|
+
return new Dom(container).in(selectorOrElement)
|
|
39
20
|
}
|
|
40
21
|
|
|
41
|
-
|
|
22
|
+
dom.require = queryRequire
|
|
23
|
+
dom.maybe = queryMaybe
|
|
24
|
+
dom.all = queryAll
|
|
25
|
+
|
|
26
|
+
dom.el = el
|
|
27
|
+
dom.elmer = elmer
|
|
28
|
+
dom.mk = mk
|
|
29
|
+
dom.events = eve
|
|
30
|
+
dom.attrs = attrs
|
|
42
31
|
dom.register = register
|
|
43
32
|
dom.render = (container: Renderable, ...content: Content[]) => {
|
|
44
33
|
return render(content, container)
|
|
45
34
|
}
|
|
46
35
|
|
|
47
|
-
dom.in = doc.in.bind(doc)
|
|
48
|
-
dom.require = doc.require.bind(doc)
|
|
49
|
-
dom.maybe = doc.maybe.bind(doc)
|
|
50
|
-
dom.all = doc.all.bind(doc)
|
|
51
|
-
|
package/s/dom/index.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
import {render} from "lit"
|
|
3
|
+
import {eve, EveSpec} from "./eve.js"
|
|
4
|
+
import {attrs} from "../attrs/attrs.js"
|
|
5
|
+
import {Content} from "../../view/types.js"
|
|
6
|
+
import {Attrs, Queryable, Renderable} from "../types.js"
|
|
7
|
+
import {queryAll, queryMaybe, queryRequire} from "./queries.js"
|
|
8
|
+
|
|
9
|
+
export class Dom<C extends Queryable> {
|
|
10
|
+
#attrs?: Attrs
|
|
11
|
+
|
|
12
|
+
constructor(public element: C) {}
|
|
13
|
+
|
|
14
|
+
in<E extends HTMLElement>(selectorOrElement: string | E) {
|
|
15
|
+
return new Dom<E>(
|
|
16
|
+
(typeof selectorOrElement === "string")
|
|
17
|
+
? queryRequire(selectorOrElement, this.element) as E
|
|
18
|
+
: selectorOrElement
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
require<E extends Element = HTMLElement>(selector: string) {
|
|
23
|
+
return queryRequire<E>(selector, this.element)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
maybe<E extends Element = HTMLElement>(selector: string) {
|
|
27
|
+
return queryMaybe<E>(selector, this.element)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
all<E extends Element = HTMLElement>(selector: string) {
|
|
31
|
+
return queryAll<E>(selector, this.element)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
render(...content: Content[]) {
|
|
35
|
+
return render(content, this.element as Renderable)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get attrs(): Attrs {
|
|
39
|
+
return this.#attrs ??= attrs(this.element as HTMLElement)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
events(spec: EveSpec) {
|
|
43
|
+
return eve(this.element, spec)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
import {AttrValue} from "../types.js"
|
|
3
|
+
import {attrSet} from "../attrs/parts/attr-fns.js"
|
|
4
|
+
|
|
5
|
+
export function el<E extends HTMLElement>(
|
|
6
|
+
tagName: string,
|
|
7
|
+
attrs: Record<string, AttrValue> = {},
|
|
8
|
+
) {
|
|
9
|
+
|
|
10
|
+
const element = document.createElement(tagName) as E
|
|
11
|
+
attrSet.record(element, attrs)
|
|
12
|
+
return element
|
|
13
|
+
}
|
|
14
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
import {AttrValue} from "../types.js"
|
|
3
|
+
import {attrSet} from "../attrs/parts/attr-fns.js"
|
|
4
|
+
|
|
5
|
+
export function elmer<E extends HTMLElement = HTMLElement>(tagName: string) {
|
|
6
|
+
return new Elmer<E>(tagName)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class Elmer<E extends HTMLElement = HTMLElement> {
|
|
10
|
+
#attrs = new Map<string, AttrValue>()
|
|
11
|
+
#children: (Node | string)[] = []
|
|
12
|
+
|
|
13
|
+
constructor(public tagName: string) {}
|
|
14
|
+
|
|
15
|
+
attr(key: string, value: AttrValue = true) {
|
|
16
|
+
this.#attrs.set(key, value)
|
|
17
|
+
return this
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
attrs(record: Record<string, AttrValue>) {
|
|
21
|
+
for (const [key, value] of Object.entries(record))
|
|
22
|
+
this.attr(key, value)
|
|
23
|
+
return this
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
children(...elements: (Node | string)[]) {
|
|
27
|
+
this.#children.push(...elements)
|
|
28
|
+
return this
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
done() {
|
|
32
|
+
const element = document.createElement(this.tagName)
|
|
33
|
+
attrSet.entries(element, this.#attrs)
|
|
34
|
+
element.append(...this.#children)
|
|
35
|
+
return element as E
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
export type EveFn = (event: any) => void
|
|
3
|
+
export type EveConfig = [options: AddEventListenerOptions, fn: EveFn]
|
|
4
|
+
export type EveHandler = EveFn | EveConfig
|
|
5
|
+
export type EveSpec = {[eventName: string]: EveHandler}
|
|
6
|
+
|
|
7
|
+
export function eve(target: EventTarget, events: EveSpec) {
|
|
8
|
+
let detachers: (() => void)[] = []
|
|
9
|
+
|
|
10
|
+
for (const [eventName, handler] of Object.entries(events)) {
|
|
11
|
+
if (typeof handler === "function") {
|
|
12
|
+
target.addEventListener(eventName, handler)
|
|
13
|
+
detachers.push(() => target.removeEventListener(eventName, handler))
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const [options, fn] = handler
|
|
17
|
+
target.addEventListener(eventName, fn, options)
|
|
18
|
+
detachers.push(() => target.removeEventListener(eventName, fn))
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return () => detachers.forEach(d => d())
|
|
23
|
+
}
|
|
24
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
import {Queryable} from "../types.js"
|
|
3
|
+
|
|
4
|
+
export function queryRequire<E extends Element>(
|
|
5
|
+
selector: string,
|
|
6
|
+
container: Queryable = document,
|
|
7
|
+
) {
|
|
8
|
+
const e = container.querySelector<E>(selector)
|
|
9
|
+
if (!e) throw new Error(`element not found (${selector})`)
|
|
10
|
+
return e
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function queryMaybe<E extends Element>(
|
|
14
|
+
selector: string,
|
|
15
|
+
container: Queryable = document,
|
|
16
|
+
) {
|
|
17
|
+
return container.querySelector<E>(selector)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function queryAll<E extends Element>(
|
|
21
|
+
selector: string,
|
|
22
|
+
container: Queryable = document,
|
|
23
|
+
) {
|
|
24
|
+
return Array.from(container.querySelectorAll<E>(selector))
|
|
25
|
+
}
|
|
26
|
+
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import {dashify} from "./dashify.js"
|
|
3
|
-
import {HTMLElementClasses} from "
|
|
4
|
-
|
|
5
|
-
export type RegistrationOptions = {
|
|
6
|
-
soft: boolean
|
|
7
|
-
upgrade: boolean
|
|
8
|
-
}
|
|
3
|
+
import {HTMLElementClasses, RegisterOptions} from "../types.js"
|
|
9
4
|
|
|
10
5
|
/**
|
|
11
6
|
* register custom elements (web components) to the dom
|
|
@@ -21,7 +16,7 @@ export type RegistrationOptions = {
|
|
|
21
16
|
*/
|
|
22
17
|
export function register<E extends HTMLElementClasses>(
|
|
23
18
|
elements: E,
|
|
24
|
-
options: Partial<
|
|
19
|
+
options: Partial<RegisterOptions> = {},
|
|
25
20
|
) {
|
|
26
21
|
|
|
27
22
|
const {
|
package/s/dom/types.ts
CHANGED
|
@@ -1,8 +1,50 @@
|
|
|
1
1
|
|
|
2
|
+
import {attrs} from "./attrs/attrs.js"
|
|
3
|
+
|
|
2
4
|
export type Renderable = HTMLElement | ShadowRoot | DocumentFragment
|
|
3
5
|
export type Queryable = HTMLElement | ShadowRoot | Element | Document | DocumentFragment
|
|
4
6
|
|
|
7
|
+
// attrs
|
|
8
|
+
|
|
9
|
+
export type AttrValue = string | boolean | number | undefined | null | void
|
|
10
|
+
|
|
11
|
+
export type AttrKind = (
|
|
12
|
+
| typeof String
|
|
13
|
+
| typeof Number
|
|
14
|
+
| typeof Boolean
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
export type AttrType<H extends AttrKind> = (
|
|
18
|
+
H extends typeof String
|
|
19
|
+
? string | undefined
|
|
20
|
+
|
|
21
|
+
: H extends typeof Number
|
|
22
|
+
? number | undefined
|
|
23
|
+
|
|
24
|
+
: H extends typeof Boolean
|
|
25
|
+
? boolean
|
|
26
|
+
|
|
27
|
+
: never
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
export type AttrSpec = {
|
|
31
|
+
[key: string]: AttrKind
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type AttrTypes<A extends AttrSpec> = {
|
|
35
|
+
[P in keyof A]: AttrType<A[P]>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type Attrs = ReturnType<typeof attrs>
|
|
39
|
+
|
|
40
|
+
// register
|
|
41
|
+
|
|
5
42
|
export type HTMLElementClasses = {
|
|
6
43
|
[key: string]: {new(...args: any[]): HTMLElement}
|
|
7
44
|
}
|
|
8
45
|
|
|
46
|
+
export type RegisterOptions = {
|
|
47
|
+
soft: boolean
|
|
48
|
+
upgrade: boolean
|
|
49
|
+
}
|
|
50
|
+
|
package/s/index.html.ts
CHANGED
|
@@ -29,8 +29,10 @@ export default ssg.page(import.meta.url, async orb => ({
|
|
|
29
29
|
<h1>sly testing page</h1>
|
|
30
30
|
<p><a href="https://github.com/e280/sly">github.com/e280/sly</a></p>
|
|
31
31
|
<p class=lil>v${orb.packageVersion()}</p>
|
|
32
|
-
|
|
33
|
-
<
|
|
32
|
+
|
|
33
|
+
<fastcount-element></fastcount-element>
|
|
34
|
+
<counter-component start=280 step=2>component</counter-component>
|
|
35
|
+
<demo-component></demo-component>
|
|
34
36
|
`,
|
|
35
37
|
}))
|
|
36
38
|
|
package/s/index.ts
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./dom/
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./ops/loaders/parts/error-display.js"
|
|
10
|
-
export * from "./ops/op.js"
|
|
11
|
-
export * from "./ops/podium.js"
|
|
12
|
-
export * from "./ops/types.js"
|
|
13
|
-
|
|
14
|
-
export * as loot from "./loot/index.js"
|
|
15
|
-
|
|
16
|
-
export * from "./views/attributes.js"
|
|
17
|
-
export * from "./views/css-reset.js"
|
|
18
|
-
export * from "./views/types.js"
|
|
19
|
-
export * from "./views/use.js"
|
|
20
|
-
export * from "./views/view.js"
|
|
2
|
+
export * from "./base/index.js"
|
|
3
|
+
export * from "./dom/index.js"
|
|
4
|
+
export * from "./loaders/index.js"
|
|
5
|
+
export * from "./loot/index.js"
|
|
6
|
+
export * from "./ops/index.js"
|
|
7
|
+
export * from "./spa/index.js"
|
|
8
|
+
export * from "./view/index.js"
|
|
21
9
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
import {Loader} from "./types.js"
|
|
3
|
+
import {earth} from "./parts/anims.js"
|
|
4
|
+
import type {Content} from "../view/types.js"
|
|
5
|
+
import {ErrorDisplay} from "./parts/error-display.js"
|
|
6
|
+
|
|
7
|
+
export function make(
|
|
8
|
+
loading: () => Content = earth,
|
|
9
|
+
error: (error: any) => Content = (error: any) => ErrorDisplay(error),
|
|
10
|
+
): Loader {
|
|
11
|
+
|
|
12
|
+
return (op, ready) => op.select({loading, ready, error})
|
|
13
|
+
}
|
|
14
|
+
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
import {css} from "lit"
|
|
3
|
-
import {nap,
|
|
3
|
+
import {nap, cycle} from "@e280/stz"
|
|
4
4
|
|
|
5
|
-
import {view} from "
|
|
6
|
-
import {Content} from "
|
|
7
|
-
import {cssReset} from "
|
|
5
|
+
import {view} from "../../view/view.js"
|
|
6
|
+
import {Content} from "../../view/types.js"
|
|
7
|
+
import {cssReset} from "../../base/css-reset.js"
|
|
8
8
|
|
|
9
9
|
export function makeAsciiAnim(hz: number, frames: string[]): () => Content {
|
|
10
10
|
return () => AsciiAnim({hz, frames})
|
|
@@ -17,9 +17,10 @@ export const AsciiAnim = view(use => ({hz, frames}: {
|
|
|
17
17
|
|
|
18
18
|
use.name("loading")
|
|
19
19
|
use.styles(cssReset, style)
|
|
20
|
+
|
|
20
21
|
const frame = use.signal(0)
|
|
21
22
|
|
|
22
|
-
use.mount(() =>
|
|
23
|
+
use.mount(() => cycle(async() => {
|
|
23
24
|
await nap(1000 / hz)
|
|
24
25
|
const next = frame.get() + 1
|
|
25
26
|
frame.set(next >= frames.length ? 0 : next)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import {css, html} from "lit"
|
|
3
|
-
import {view} from "
|
|
4
|
-
import {cssReset} from "
|
|
3
|
+
import {view} from "../../view/view.js"
|
|
4
|
+
import {cssReset} from "../../base/css-reset.js"
|
|
5
5
|
|
|
6
6
|
export const ErrorDisplay = view(use => (error: any) => {
|
|
7
7
|
use.name("error")
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
import {signal} from "@e280/strata"
|
|
3
|
+
import {Drops} from "./drops.js"
|
|
4
|
+
import {outsideCurrentTarget} from "./helpers.js"
|
|
5
|
+
|
|
6
|
+
/** respond to user dragging-and-dropping things around on a webpage */
|
|
7
|
+
export class DragAndDrops<Draggy, Droppy> {
|
|
8
|
+
|
|
9
|
+
/** what is currently being dragged */
|
|
10
|
+
$draggy = signal<Draggy | undefined>(undefined)
|
|
11
|
+
|
|
12
|
+
/** what dropzone are we curently hovering over */
|
|
13
|
+
$droppy = signal<Droppy | undefined>(undefined)
|
|
14
|
+
|
|
15
|
+
constructor(private params: {
|
|
16
|
+
|
|
17
|
+
/** accept a dropped item that was declared within this system */
|
|
18
|
+
acceptDrop: (event: DragEvent, draggy: Draggy, droppy: Droppy) => void
|
|
19
|
+
|
|
20
|
+
/** also accept drops on the side */
|
|
21
|
+
backchannelDrops?: Drops
|
|
22
|
+
}) {}
|
|
23
|
+
|
|
24
|
+
get dragging() {
|
|
25
|
+
return this.$draggy()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get hovering() {
|
|
29
|
+
return this.$droppy()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** make event listeners to attach to your dragzone(s) */
|
|
33
|
+
dragzone = (getDraggy: () => Draggy) => ({
|
|
34
|
+
draggable: "true",
|
|
35
|
+
|
|
36
|
+
dragstart: (_: DragEvent) => {
|
|
37
|
+
this.$draggy.value = getDraggy()
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
dragend: (_: DragEvent) => {
|
|
41
|
+
this.$draggy.value = undefined
|
|
42
|
+
this.$droppy.value = undefined
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
/** make event listeners to attach to your dropzones(s) */
|
|
47
|
+
dropzone = (getDroppy: () => Droppy) => ({
|
|
48
|
+
dragenter: (_: DragEvent) => {},
|
|
49
|
+
|
|
50
|
+
dragover: (event: DragEvent) => {
|
|
51
|
+
event.preventDefault()
|
|
52
|
+
if (this.$draggy())
|
|
53
|
+
this.$droppy.value = getDroppy()
|
|
54
|
+
else
|
|
55
|
+
this.params.backchannelDrops?.dragover(event)
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
dragleave: (event: DragEvent) => {
|
|
59
|
+
if (outsideCurrentTarget(event))
|
|
60
|
+
this.$droppy.value = undefined
|
|
61
|
+
this.params.backchannelDrops?.dragleave(event)
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
drop: (event: DragEvent) => {
|
|
65
|
+
event.preventDefault()
|
|
66
|
+
const {acceptDrop} = this.params
|
|
67
|
+
const draggy = this.$draggy()
|
|
68
|
+
const droppy = this.$droppy()
|
|
69
|
+
try {
|
|
70
|
+
if (draggy && droppy)
|
|
71
|
+
acceptDrop(event, draggy, droppy)
|
|
72
|
+
else
|
|
73
|
+
this.params.backchannelDrops?.drop(event)
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
this.$draggy.value = undefined
|
|
77
|
+
this.$droppy.value = undefined
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
import {signal} from "@e280/strata"
|
|
3
|
-
import {
|
|
3
|
+
import {outsideCurrentTarget} from "./helpers.js"
|
|
4
4
|
|
|
5
|
-
/** dropzone that accepts dropped stuff like files */
|
|
6
|
-
export class
|
|
7
|
-
|
|
5
|
+
/** dropzone that accepts user-dropped stuff like files */
|
|
6
|
+
export class Drops {
|
|
7
|
+
$indicator = signal(false)
|
|
8
8
|
|
|
9
9
|
constructor(private params: {
|
|
10
10
|
|
|
@@ -15,28 +15,19 @@ export class Drop {
|
|
|
15
15
|
acceptDrop: (event: DragEvent) => void
|
|
16
16
|
}) {}
|
|
17
17
|
|
|
18
|
-
get indicator() {
|
|
19
|
-
return this.#$indicator.value
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
resetIndicator = () => {
|
|
23
|
-
this.#$indicator.value = false
|
|
24
|
-
}
|
|
25
|
-
|
|
26
18
|
dragover = (event: DragEvent) => {
|
|
27
19
|
event.preventDefault()
|
|
28
|
-
|
|
29
|
-
this.#$indicator.value = true
|
|
20
|
+
this.$indicator.value = this.params.predicate(event)
|
|
30
21
|
}
|
|
31
22
|
|
|
32
23
|
dragleave = (event: DragEvent) => {
|
|
33
|
-
if (
|
|
34
|
-
this
|
|
24
|
+
if (outsideCurrentTarget(event))
|
|
25
|
+
this.$indicator.value = false
|
|
35
26
|
}
|
|
36
27
|
|
|
37
28
|
drop = (event: DragEvent) => {
|
|
38
29
|
event.preventDefault()
|
|
39
|
-
this
|
|
30
|
+
this.$indicator.value = false
|
|
40
31
|
if (this.params.predicate(event))
|
|
41
32
|
this.params.acceptDrop(event)
|
|
42
33
|
}
|
package/s/loot/helpers.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
export function
|
|
2
|
+
export function hasFiles(event: DragEvent) {
|
|
3
3
|
return !!(
|
|
4
4
|
event.dataTransfer &&
|
|
5
5
|
event.dataTransfer.types.includes("Files")
|
|
6
6
|
)
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export function
|
|
9
|
+
export function files(event: DragEvent) {
|
|
10
10
|
return event.dataTransfer
|
|
11
11
|
? Array.from(event.dataTransfer.files)
|
|
12
12
|
: []
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export function
|
|
15
|
+
export function outsideCurrentTarget(event: DragEvent) {
|
|
16
16
|
const isCursorOutsideViewport = !event.relatedTarget || (
|
|
17
17
|
event.clientX === 0 &&
|
|
18
18
|
event.clientY === 0
|
package/s/loot/index.ts
CHANGED