@e280/sly 0.2.5 → 0.3.0-1
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/LICENSE +1 -1
- package/README.md +302 -614
- package/package.json +6 -8
- package/s/_archive/README.md +1221 -0
- package/s/_archive/view/index.ts +7 -0
- package/s/_archive/view/types.ts +45 -0
- package/s/demo/demo.bundle.ts +2 -9
- package/s/demo/views/counter-light.ts +13 -0
- package/s/demo/views/counter-shadow.ts +16 -0
- package/s/demo/views/demo.ts +21 -20
- package/s/demo/views/loaders.ts +7 -7
- package/s/index.html.ts +30 -33
- package/s/index.ts +0 -2
- package/s/loaders/make.ts +1 -1
- package/s/loaders/parts/ascii-anim.ts +6 -8
- package/s/loaders/parts/error-display.ts +9 -9
- package/s/tests.test.ts +1 -4
- package/s/view/common/css-reset.ts +19 -0
- package/s/view/hooks/plumbing/hooks.ts +28 -0
- package/s/view/hooks/plumbing/hookscope.ts +12 -0
- package/s/view/hooks/use-css.ts +14 -0
- package/s/view/hooks/use-cx.ts +41 -0
- package/s/view/hooks/use-life.ts +17 -0
- package/s/view/hooks/use-mount.ts +30 -0
- package/s/view/hooks/use-name.ts +10 -0
- package/s/view/hooks/use-once.ts +9 -0
- package/s/view/hooks/use-op.ts +12 -0
- package/s/view/hooks/use-ref.ts +11 -0
- package/s/view/hooks/use-signal.ts +16 -0
- package/s/view/hooks/use-state.ts +20 -0
- package/s/view/hooks/use-wake.ts +8 -0
- package/s/view/index.ts +17 -4
- package/s/view/light.ts +50 -0
- package/s/view/parts/apply-attrs.ts +22 -0
- package/s/view/parts/apply-styles.ts +21 -0
- package/s/view/parts/cx.ts +26 -0
- package/s/view/parts/reactivity.ts +22 -0
- package/s/view/parts/sly-shadow.ts +8 -0
- package/s/view/shadow.ts +93 -0
- package/s/view/types.ts +15 -34
- package/x/demo/demo.bundle.js +2 -8
- package/x/demo/demo.bundle.js.map +1 -1
- package/x/demo/demo.bundle.min.js +45 -63
- package/x/demo/demo.bundle.min.js.map +4 -4
- package/x/demo/views/counter-light.d.ts +1 -0
- package/x/demo/views/counter-light.js +10 -0
- package/x/demo/views/counter-light.js.map +1 -0
- package/x/demo/views/counter-shadow.d.ts +1 -0
- package/x/demo/views/counter-shadow.js +12 -0
- package/x/demo/views/counter-shadow.js.map +1 -0
- package/x/demo/views/demo.d.ts +1 -4
- package/x/demo/views/demo.js +21 -20
- package/x/demo/views/demo.js.map +1 -1
- package/x/demo/views/loaders.d.ts +1 -1
- package/x/demo/views/loaders.js +7 -7
- package/x/demo/views/loaders.js.map +1 -1
- package/x/index.d.ts +0 -2
- package/x/index.html +30 -140
- package/x/index.html.js +31 -31
- package/x/index.html.js.map +1 -1
- package/x/index.js +0 -2
- package/x/index.js.map +1 -1
- package/x/loaders/make.d.ts +1 -1
- package/x/loaders/parts/ascii-anim.d.ts +1 -1
- package/x/loaders/parts/ascii-anim.js +6 -7
- package/x/loaders/parts/ascii-anim.js.map +1 -1
- package/x/loaders/parts/error-display.d.ts +1 -1
- package/x/loaders/parts/error-display.js +9 -9
- package/x/loaders/parts/error-display.js.map +1 -1
- package/x/tests.test.js +1 -4
- package/x/tests.test.js.map +1 -1
- package/x/view/common/css-reset.js +17 -0
- package/x/view/common/css-reset.js.map +1 -0
- package/x/view/hooks/plumbing/hooks.d.ts +11 -0
- package/x/view/hooks/plumbing/hooks.js +26 -0
- package/x/view/hooks/plumbing/hooks.js.map +1 -0
- package/x/view/hooks/plumbing/hookscope.d.ts +10 -0
- package/x/view/hooks/plumbing/hookscope.js +12 -0
- package/x/view/hooks/plumbing/hookscope.js.map +1 -0
- package/x/view/hooks/use-css.d.ts +4 -0
- package/x/view/hooks/use-css.js +10 -0
- package/x/view/hooks/use-css.js.map +1 -0
- package/x/view/hooks/use-cx.d.ts +10 -0
- package/x/view/hooks/use-cx.js +33 -0
- package/x/view/hooks/use-cx.js.map +1 -0
- package/x/view/hooks/use-life.d.ts +2 -0
- package/x/view/hooks/use-life.js +13 -0
- package/x/view/hooks/use-life.js.map +1 -0
- package/x/{base/utils/mounts.d.ts → view/hooks/use-mount.d.ts} +1 -0
- package/x/{base/utils/mounts.js → view/hooks/use-mount.js} +7 -1
- package/x/view/hooks/use-mount.js.map +1 -0
- package/x/view/hooks/use-name.d.ts +2 -0
- package/x/view/hooks/use-name.js +8 -0
- package/x/view/hooks/use-name.js.map +1 -0
- package/x/view/hooks/use-once.d.ts +2 -0
- package/x/view/hooks/use-once.js +7 -0
- package/x/view/hooks/use-once.js.map +1 -0
- package/x/view/hooks/use-op.d.ts +3 -0
- package/x/view/hooks/use-op.js +9 -0
- package/x/view/hooks/use-op.js.map +1 -0
- package/x/view/hooks/use-ref.d.ts +5 -0
- package/x/view/hooks/use-ref.js +11 -0
- package/x/view/hooks/use-ref.js.map +1 -0
- package/x/view/hooks/use-signal.d.ts +3 -0
- package/x/view/hooks/use-signal.js +12 -0
- package/x/view/hooks/use-signal.js.map +1 -0
- package/x/view/hooks/use-state.d.ts +1 -0
- package/x/view/hooks/use-state.js +17 -0
- package/x/view/hooks/use-state.js.map +1 -0
- package/x/view/hooks/use-wake.d.ts +2 -0
- package/x/view/hooks/use-wake.js +6 -0
- package/x/view/hooks/use-wake.js.map +1 -0
- package/x/view/index.d.ts +15 -4
- package/x/view/index.js +15 -4
- package/x/view/index.js.map +1 -1
- package/x/view/light.d.ts +2 -0
- package/x/view/light.js +41 -0
- package/x/view/light.js.map +1 -0
- package/x/view/parts/apply-attrs.d.ts +2 -0
- package/x/view/parts/apply-attrs.js +22 -0
- package/x/view/parts/apply-attrs.js.map +1 -0
- package/x/{base/utils → view/parts}/apply-styles.js.map +1 -1
- package/x/view/parts/cx.d.ts +12 -0
- package/x/view/parts/cx.js +24 -0
- package/x/view/parts/cx.js.map +1 -0
- package/x/view/parts/reactivity.d.ts +5 -0
- package/x/view/parts/reactivity.js +18 -0
- package/x/view/parts/reactivity.js.map +1 -0
- package/x/view/parts/sly-shadow.d.ts +3 -0
- package/x/view/parts/sly-shadow.js +7 -0
- package/x/view/parts/sly-shadow.js.map +1 -0
- package/x/view/shadow.d.ts +6 -0
- package/x/view/shadow.js +72 -0
- package/x/view/shadow.js.map +1 -0
- package/x/view/types.d.ts +13 -21
- package/s/demo/views/counter.ts +0 -50
- package/s/demo/views/fastcount.ts +0 -29
- package/s/demo/views/mounting.ts +0 -36
- package/x/base/css-reset.js +0 -19
- package/x/base/css-reset.js.map +0 -1
- package/x/base/element.d.ts +0 -19
- package/x/base/element.js +0 -55
- package/x/base/element.js.map +0 -1
- package/x/base/index.d.ts +0 -5
- package/x/base/index.js +0 -6
- package/x/base/index.js.map +0 -1
- package/x/base/types.d.ts +0 -3
- package/x/base/types.js +0 -3
- package/x/base/types.js.map +0 -1
- package/x/base/use.d.ts +0 -59
- package/x/base/use.js +0 -129
- package/x/base/use.js.map +0 -1
- package/x/base/utils/attr-watcher.d.ts +0 -8
- package/x/base/utils/attr-watcher.js +0 -20
- package/x/base/utils/attr-watcher.js.map +0 -1
- package/x/base/utils/mounts.js.map +0 -1
- package/x/base/utils/reactor.d.ts +0 -5
- package/x/base/utils/reactor.js +0 -25
- package/x/base/utils/reactor.js.map +0 -1
- package/x/base/utils/states.d.ts +0 -13
- package/x/base/utils/states.js +0 -41
- package/x/base/utils/states.js.map +0 -1
- package/x/base/utils/use-attrs.d.ts +0 -11
- package/x/base/utils/use-attrs.js +0 -18
- package/x/base/utils/use-attrs.js.map +0 -1
- package/x/demo/views/counter.d.ts +0 -375
- package/x/demo/views/counter.js +0 -42
- package/x/demo/views/counter.js.map +0 -1
- package/x/demo/views/fastcount.d.ts +0 -12
- package/x/demo/views/fastcount.js +0 -21
- package/x/demo/views/fastcount.js.map +0 -1
- package/x/demo/views/mounting.d.ts +0 -3
- package/x/demo/views/mounting.js +0 -28
- package/x/demo/views/mounting.js.map +0 -1
- package/x/spa/index.barrel.d.ts +0 -4
- package/x/spa/index.barrel.js +0 -3
- package/x/spa/index.barrel.js.map +0 -1
- package/x/spa/index.d.ts +0 -2
- package/x/spa/index.js +0 -2
- package/x/spa/index.js.map +0 -1
- package/x/spa/plumbing/braces.d.ts +0 -12
- package/x/spa/plumbing/braces.js +0 -55
- package/x/spa/plumbing/braces.js.map +0 -1
- package/x/spa/plumbing/primitives.d.ts +0 -22
- package/x/spa/plumbing/primitives.js +0 -65
- package/x/spa/plumbing/primitives.js.map +0 -1
- package/x/spa/plumbing/router-core.d.ts +0 -13
- package/x/spa/plumbing/router-core.js +0 -38
- package/x/spa/plumbing/router-core.js.map +0 -1
- package/x/spa/plumbing/types.d.ts +0 -35
- package/x/spa/plumbing/types.js +0 -2
- package/x/spa/plumbing/types.js.map +0 -1
- package/x/spa/router.d.ts +0 -13
- package/x/spa/router.js +0 -39
- package/x/spa/router.js.map +0 -1
- package/x/spa/spa.test.d.ts +0 -15
- package/x/spa/spa.test.js +0 -78
- package/x/spa/spa.test.js.map +0 -1
- package/x/view/utils/contextualize.d.ts +0 -13
- package/x/view/utils/contextualize.js +0 -18
- package/x/view/utils/contextualize.js.map +0 -1
- package/x/view/utils/make-component.d.ts +0 -5
- package/x/view/utils/make-component.js +0 -17
- package/x/view/utils/make-component.js.map +0 -1
- package/x/view/utils/make-view.d.ts +0 -2
- package/x/view/utils/make-view.js +0 -32
- package/x/view/utils/make-view.js.map +0 -1
- package/x/view/utils/parts/capsule.d.ts +0 -12
- package/x/view/utils/parts/capsule.js +0 -56
- package/x/view/utils/parts/capsule.js.map +0 -1
- package/x/view/utils/parts/chain.d.ts +0 -13
- package/x/view/utils/parts/chain.js +0 -26
- package/x/view/utils/parts/chain.js.map +0 -1
- package/x/view/utils/parts/context.d.ts +0 -9
- package/x/view/utils/parts/context.js +0 -10
- package/x/view/utils/parts/context.js.map +0 -1
- package/x/view/utils/parts/directive.d.ts +0 -5
- package/x/view/utils/parts/directive.js +0 -20
- package/x/view/utils/parts/directive.js.map +0 -1
- package/x/view/utils/parts/naked.d.ts +0 -18
- package/x/view/utils/parts/naked.js +0 -57
- package/x/view/utils/parts/naked.js.map +0 -1
- package/x/view/utils/parts/sly-view.d.ts +0 -6
- package/x/view/utils/parts/sly-view.js +0 -16
- package/x/view/utils/parts/sly-view.js.map +0 -1
- package/x/view/view.d.ts +0 -11
- package/x/view/view.js +0 -15
- package/x/view/view.js.map +0 -1
- /package/s/{base → _archive/base}/css-reset.ts +0 -0
- /package/s/{base → _archive/base}/element.ts +0 -0
- /package/s/{base → _archive/base}/index.ts +0 -0
- /package/s/{base → _archive/base}/types.ts +0 -0
- /package/s/{base → _archive/base}/use.ts +0 -0
- /package/s/{base → _archive/base}/utils/apply-styles.ts +0 -0
- /package/s/{base → _archive/base}/utils/attr-watcher.ts +0 -0
- /package/s/{base → _archive/base}/utils/mounts.ts +0 -0
- /package/s/{base → _archive/base}/utils/reactor.ts +0 -0
- /package/s/{base → _archive/base}/utils/states.ts +0 -0
- /package/s/{base → _archive/base}/utils/use-attrs.ts +0 -0
- /package/s/{spa → _archive/spa}/index.barrel.ts +0 -0
- /package/s/{spa → _archive/spa}/index.ts +0 -0
- /package/s/{spa → _archive/spa}/plumbing/braces.ts +0 -0
- /package/s/{spa → _archive/spa}/plumbing/primitives.ts +0 -0
- /package/s/{spa → _archive/spa}/plumbing/router-core.ts +0 -0
- /package/s/{spa → _archive/spa}/plumbing/types.ts +0 -0
- /package/s/{spa → _archive/spa}/router.ts +0 -0
- /package/s/{spa → _archive/spa}/spa.test.ts +0 -0
- /package/s/{view → _archive/view}/utils/contextualize.ts +0 -0
- /package/s/{view → _archive/view}/utils/make-component.ts +0 -0
- /package/s/{view → _archive/view}/utils/make-view.ts +0 -0
- /package/s/{view → _archive/view}/utils/parts/capsule.ts +0 -0
- /package/s/{view → _archive/view}/utils/parts/chain.ts +0 -0
- /package/s/{view → _archive/view}/utils/parts/context.ts +0 -0
- /package/s/{view → _archive/view}/utils/parts/directive.ts +0 -0
- /package/s/{view → _archive/view}/utils/parts/naked.ts +0 -0
- /package/s/{view → _archive/view}/utils/parts/sly-view.ts +0 -0
- /package/s/{view → _archive/view}/view.ts +0 -0
- /package/x/{base → view/common}/css-reset.d.ts +0 -0
- /package/x/{base/utils → view/parts}/apply-styles.d.ts +0 -0
- /package/x/{base/utils → view/parts}/apply-styles.js +0 -0
package/s/view/light.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
import {microbounce} from "@e280/stz"
|
|
3
|
+
|
|
4
|
+
import {View} from "./types.js"
|
|
5
|
+
import {LightCx} from "./parts/cx.js"
|
|
6
|
+
import {hooks} from "./hooks/plumbing/hooks.js"
|
|
7
|
+
import {Reactivity} from "./parts/reactivity.js"
|
|
8
|
+
import {Hookscope} from "./hooks/plumbing/hookscope.js"
|
|
9
|
+
import {AsyncDirective, directive, Part} from "lit/async-directive.js"
|
|
10
|
+
|
|
11
|
+
export function light<Props extends any[]>(view: View<Props>) {
|
|
12
|
+
return directive(class D extends AsyncDirective {
|
|
13
|
+
#props!: Props
|
|
14
|
+
#cx = new LightCx(microbounce(() => {
|
|
15
|
+
if (!this.#props) throw new Error("cannot render before props")
|
|
16
|
+
if (this.isConnected) {
|
|
17
|
+
const content = this.render(...this.#props)
|
|
18
|
+
this.setValue(content)
|
|
19
|
+
this.#cx.doneRender()
|
|
20
|
+
}
|
|
21
|
+
}))
|
|
22
|
+
#hookscope = new Hookscope(this.#cx)
|
|
23
|
+
#reactivity = new Reactivity()
|
|
24
|
+
|
|
25
|
+
update(part: Part, props: any[]) {
|
|
26
|
+
const ret = super.update(part, props)
|
|
27
|
+
if (this.isConnected) this.#cx.doneRender()
|
|
28
|
+
return ret
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
render(...props: Props) {
|
|
32
|
+
this.#props = props
|
|
33
|
+
return this.#reactivity.observe(
|
|
34
|
+
() => hooks.wrap(this.#hookscope, () => view(...this.#props)),
|
|
35
|
+
this.#cx.render,
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
disconnected() {
|
|
40
|
+
this.#hookscope.mounts.unmountAll()
|
|
41
|
+
this.#reactivity.clear()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
reconnected() {
|
|
45
|
+
this.#hookscope.mounts.remountAll()
|
|
46
|
+
this.#cx.render()
|
|
47
|
+
}
|
|
48
|
+
}) as View<Props>
|
|
49
|
+
}
|
|
50
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
import {ViewAttr, ViewAttrs} from "../types.js"
|
|
3
|
+
|
|
4
|
+
export function applyAttrs(element: HTMLElement, attrs: ViewAttrs) {
|
|
5
|
+
for (const [name, value] of Object.entries(attrs))
|
|
6
|
+
applyAttr(element, name, value)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function applyAttr(element: HTMLElement, name: string, value: ViewAttr) {
|
|
10
|
+
const existing = element.getAttribute(name)
|
|
11
|
+
const v = coerce(value)
|
|
12
|
+
if (v === existing) return
|
|
13
|
+
if (v === null) element.removeAttribute(name)
|
|
14
|
+
else element.setAttribute(name, v)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function coerce(value: ViewAttr) {
|
|
18
|
+
if (typeof value === "string") return value
|
|
19
|
+
else if (typeof value === "number") return value.toString()
|
|
20
|
+
return value ? "" : null
|
|
21
|
+
}
|
|
22
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
import {adoptStyles, CSSResultGroup, CSSResultOrNative, getCompatibleStyle} from "lit"
|
|
3
|
+
|
|
4
|
+
export function applyStyles(shadow: ShadowRoot, styles?: CSSResultGroup) {
|
|
5
|
+
adoptStyles(shadow, prepareStyles(styles))
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function prepareStyles(styles?: CSSResultGroup): Array<CSSResultOrNative> {
|
|
9
|
+
const elementStyles = []
|
|
10
|
+
|
|
11
|
+
if (Array.isArray(styles)) {
|
|
12
|
+
const set = new Set((styles as Array<unknown>).flat(Infinity).reverse())
|
|
13
|
+
for (const s of set)
|
|
14
|
+
elementStyles.unshift(getCompatibleStyle(s as CSSResultOrNative))
|
|
15
|
+
}
|
|
16
|
+
else if (styles !== undefined)
|
|
17
|
+
elementStyles.push(getCompatibleStyle(styles))
|
|
18
|
+
|
|
19
|
+
return elementStyles
|
|
20
|
+
}
|
|
21
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
import {defer} from "@e280/stz"
|
|
3
|
+
|
|
4
|
+
export class LightCx {
|
|
5
|
+
count = 0
|
|
6
|
+
rendered = defer<void>()
|
|
7
|
+
|
|
8
|
+
constructor(public render: () => Promise<void>) {}
|
|
9
|
+
|
|
10
|
+
doneRender() {
|
|
11
|
+
this.count++
|
|
12
|
+
this.rendered.resolve()
|
|
13
|
+
this.rendered = defer()
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class ShadowCx extends LightCx {
|
|
18
|
+
constructor(
|
|
19
|
+
render: () => Promise<void>,
|
|
20
|
+
public host: HTMLElement,
|
|
21
|
+
public shadow: ShadowRoot,
|
|
22
|
+
) {
|
|
23
|
+
super(render)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
import {tracker} from "@e280/strata"
|
|
3
|
+
|
|
4
|
+
export class Reactivity {
|
|
5
|
+
#stoppers: (() => void)[] = []
|
|
6
|
+
|
|
7
|
+
clear() {
|
|
8
|
+
this.#stoppers.forEach(stop => stop())
|
|
9
|
+
this.#stoppers = []
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
observe<X>(fn: () => X, rerender: () => Promise<void>) {
|
|
13
|
+
const {seen, result} = tracker.observe(fn)
|
|
14
|
+
this.clear()
|
|
15
|
+
for (const item of seen) {
|
|
16
|
+
const stop = tracker.subscribe(item, rerender)
|
|
17
|
+
this.#stoppers.push(stop)
|
|
18
|
+
}
|
|
19
|
+
return result
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
package/s/view/shadow.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
|
|
2
|
+
import {microbounce} from "@e280/stz"
|
|
3
|
+
import {render as litRender} from "lit"
|
|
4
|
+
|
|
5
|
+
import {dom} from "../dom/dom.js"
|
|
6
|
+
import {ShadowCx} from "./parts/cx.js"
|
|
7
|
+
import {SlyShadow} from "./parts/sly-shadow.js"
|
|
8
|
+
import {hooks} from "./hooks/plumbing/hooks.js"
|
|
9
|
+
import {Reactivity} from "./parts/reactivity.js"
|
|
10
|
+
import {applyAttrs} from "./parts/apply-attrs.js"
|
|
11
|
+
import {Hookscope} from "./hooks/plumbing/hookscope.js"
|
|
12
|
+
import {View, Placement, ShadowSetup, ShadowView} from "./types.js"
|
|
13
|
+
import {AsyncDirective, directive, PartInfo} from "lit/async-directive.js"
|
|
14
|
+
|
|
15
|
+
export function shadow<Props extends any[]>(view: View<Props>) {
|
|
16
|
+
const setupFn = (): ShadowSetup => {
|
|
17
|
+
dom.register({SlyShadow}, {soft: true})
|
|
18
|
+
const host = document.createElement("sly-shadow")
|
|
19
|
+
const shadow = host.attachShadow({mode: "open"})
|
|
20
|
+
return {host, shadow}
|
|
21
|
+
}
|
|
22
|
+
return rawShadow(setupFn, view)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
shadow.config = (setupFn: () => ShadowSetup) => (
|
|
26
|
+
<Props extends any[]>(view: View<Props>) => (
|
|
27
|
+
rawShadow(setupFn, view)
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
export function rawShadow<Props extends any[]>(
|
|
32
|
+
setup: () => ShadowSetup,
|
|
33
|
+
view: View<Props>,
|
|
34
|
+
) {
|
|
35
|
+
|
|
36
|
+
const directiveFn = directive(class extends AsyncDirective {
|
|
37
|
+
#cx
|
|
38
|
+
#hookscope
|
|
39
|
+
#props!: Props
|
|
40
|
+
#reactivity = new Reactivity()
|
|
41
|
+
|
|
42
|
+
constructor(part: PartInfo) {
|
|
43
|
+
super(part)
|
|
44
|
+
const {host, shadow} = setup()
|
|
45
|
+
const rerender = microbounce(() => {
|
|
46
|
+
if (!this.#props) throw new Error("cannot render before props")
|
|
47
|
+
if (!this.isConnected) return
|
|
48
|
+
const content = this.#renderContent(this.#props)
|
|
49
|
+
litRender(content, this.#cx.shadow)
|
|
50
|
+
this.#cx.doneRender()
|
|
51
|
+
})
|
|
52
|
+
this.#cx = new ShadowCx(rerender, host, shadow)
|
|
53
|
+
this.#hookscope = new Hookscope(this.#cx)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
#renderContent(props: Props) {
|
|
57
|
+
this.#props = props
|
|
58
|
+
return this.#reactivity.observe(
|
|
59
|
+
() => hooks.wrap(this.#hookscope, () => view(...this.#props)),
|
|
60
|
+
this.#cx.render,
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
render({props, children, attrs}: Placement<Props>) {
|
|
65
|
+
const {host} = this.#cx
|
|
66
|
+
if (!this.isConnected) return host
|
|
67
|
+
if (attrs) applyAttrs(host, attrs)
|
|
68
|
+
litRender(children, this.#cx.host)
|
|
69
|
+
litRender(this.#renderContent(props), this.#cx.shadow)
|
|
70
|
+
this.#cx.doneRender()
|
|
71
|
+
return host
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
disconnected() {
|
|
75
|
+
this.#hookscope.mounts.unmountAll()
|
|
76
|
+
this.#reactivity.clear()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
reconnected() {
|
|
80
|
+
this.#hookscope.mounts.remountAll()
|
|
81
|
+
this.#cx.render()
|
|
82
|
+
}
|
|
83
|
+
}) as ShadowView<[Placement<Props>]>
|
|
84
|
+
|
|
85
|
+
function shadowView(...props: Props) {
|
|
86
|
+
return directiveFn({props})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
shadowView.with = directiveFn
|
|
90
|
+
|
|
91
|
+
return shadowView as ShadowView<Props>
|
|
92
|
+
}
|
|
93
|
+
|
package/s/view/types.ts
CHANGED
|
@@ -1,45 +1,26 @@
|
|
|
1
1
|
|
|
2
2
|
import {TemplateResult} from "lit"
|
|
3
|
-
import {
|
|
4
|
-
import {DirectiveResult} from "lit/directive.js"
|
|
5
|
-
|
|
6
|
-
import {Use} from "../base/use.js"
|
|
7
|
-
import {BaseElement} from "../base/element.js"
|
|
8
|
-
import {ViewChain} from "./utils/parts/chain.js"
|
|
3
|
+
import {DirectiveResult} from "lit/async-directive.js"
|
|
9
4
|
|
|
10
5
|
export type Content = TemplateResult | DirectiveResult | HTMLElement | string | null | undefined | void | Content[]
|
|
11
6
|
|
|
12
|
-
export type
|
|
13
|
-
(use: Use) =>
|
|
14
|
-
(...props: Props) =>
|
|
15
|
-
Content
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
export type View<Props extends any[]> = {
|
|
19
|
-
(...props: Props): DirectiveResult
|
|
20
|
-
props: (...props: Props) => ViewChain<Props>
|
|
21
|
-
transmute: <PropsB extends any[]>(convert: (...propsB: PropsB) => Props) => View<PropsB>
|
|
22
|
-
component: <B extends Constructor<BaseElement>>(Base?: B) => {
|
|
23
|
-
props: (propFn: (component: InstanceType<B>) => Props) => (
|
|
24
|
-
ComponentClass<B, Props>
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
naked: (host: HTMLElement) => NakedView<Props>
|
|
28
|
-
}
|
|
7
|
+
export type View<Props extends any[]> = (...props: Props) => Content
|
|
29
8
|
|
|
30
|
-
export type
|
|
31
|
-
|
|
32
|
-
? Props
|
|
33
|
-
: never
|
|
34
|
-
)
|
|
9
|
+
export type ViewAttr = string | number | boolean
|
|
10
|
+
export type ViewAttrs = Record<string, ViewAttr>
|
|
35
11
|
|
|
36
|
-
export type
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
12
|
+
export type Placement<Props extends any[]> = {
|
|
13
|
+
props: Props
|
|
14
|
+
children?: Content
|
|
15
|
+
attrs?: ViewAttrs
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type ShadowView<Props extends any[]> = View<Props> & {
|
|
19
|
+
with: (placement: Placement<Props>) => Content
|
|
20
|
+
}
|
|
40
21
|
|
|
41
|
-
export type
|
|
22
|
+
export type ShadowSetup = {
|
|
42
23
|
host: HTMLElement
|
|
43
|
-
|
|
24
|
+
shadow: ShadowRoot
|
|
44
25
|
}
|
|
45
26
|
|
package/x/demo/demo.bundle.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { dom } from "../dom/dom.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { FastcountElement } from "./views/fastcount.js";
|
|
5
|
-
dom.register({
|
|
6
|
-
DemoComponent,
|
|
7
|
-
CounterComponent,
|
|
8
|
-
FastcountElement,
|
|
9
|
-
});
|
|
2
|
+
import { Demo } from "./views/demo.js";
|
|
3
|
+
dom.in(".demo").render(Demo());
|
|
10
4
|
console.log("🦝 sly");
|
|
11
5
|
//# sourceMappingURL=demo.bundle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"demo.bundle.js","sourceRoot":"","sources":["../../s/demo/demo.bundle.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAC,MAAM,eAAe,CAAA;AACjC,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"demo.bundle.js","sourceRoot":"","sources":["../../s/demo/demo.bundle.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAC,MAAM,eAAe,CAAA;AACjC,OAAO,EAAC,IAAI,EAAC,MAAM,iBAAiB,CAAA;AAEpC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;AAC9B,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA"}
|