@tempots/dom 5.0.0 → 5.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.
- package/README.md +1 -0
- package/clean.d.ts +2 -0
- package/clean.js +1 -0
- package/components/Attribute.d.ts +15 -0
- package/components/Attribute.js +16 -0
- package/components/BooleanAttribute.d.ts +15 -0
- package/components/BooleanAttribute.js +16 -0
- package/components/ClassName.d.ts +13 -0
- package/components/ClassName.js +14 -0
- package/components/El.d.ts +15 -0
- package/components/El.js +21 -0
- package/components/FadeIn.d.ts +18 -0
- package/components/FadeIn.js +52 -0
- package/components/FadeOut.d.ts +16 -0
- package/components/FadeOut.js +39 -0
- package/components/For.d.ts +7 -0
- package/components/For.js +15 -0
- package/components/Fragment.d.ts +12 -0
- package/components/Fragment.js +16 -0
- package/components/HiddenWhenEmpty.d.ts +7 -0
- package/components/HiddenWhenEmpty.js +12 -0
- package/components/If.d.ts +14 -0
- package/components/If.js +19 -0
- package/components/InnerHTML.d.ts +13 -0
- package/components/InnerHTML.js +23 -0
- package/components/Lifecycle.d.ts +14 -0
- package/components/Lifecycle.js +18 -0
- package/components/Match.d.ts +33 -0
- package/components/Match.js +44 -0
- package/components/NotEmpty.d.ts +10 -0
- package/components/NotEmpty.js +11 -0
- package/components/On.d.ts +15 -0
- package/components/On.js +14 -0
- package/components/OnRemove.d.ts +11 -0
- package/components/OnRemove.js +14 -0
- package/components/OneOf.d.ts +20 -0
- package/components/OneOf.js +45 -0
- package/components/Portal.d.ts +15 -0
- package/components/Portal.js +20 -0
- package/components/Property.d.ts +15 -0
- package/components/Property.js +16 -0
- package/components/Provider.d.ts +28 -0
- package/components/Provider.js +44 -0
- package/components/Repeat.d.ts +15 -0
- package/components/Repeat.js +33 -0
- package/components/Shadow.d.ts +0 -0
- package/components/Shadow.js +1 -0
- package/components/Show.d.ts +20 -0
- package/components/Show.js +22 -0
- package/components/Text.d.ts +15 -0
- package/components/Text.js +33 -0
- package/components/TextContent.d.ts +13 -0
- package/components/TextContent.js +23 -0
- package/components/Tween.d.ts +75 -0
- package/components/Tween.js +242 -0
- package/components/animatable.d.ts +53 -0
- package/components/animatable.js +156 -0
- package/dom-context.d.ts +38 -0
- package/dom-context.js +260 -0
- package/helpers/handle-anchor-click.d.ts +4 -0
- package/helpers/handle-anchor-click.js +43 -0
- package/helpers/handle-text-input.d.ts +1 -0
- package/helpers/handle-text-input.js +4 -0
- package/helpers/is-empty-element.d.ts +2 -0
- package/helpers/is-empty-element.js +8 -0
- package/index.d.ts +36 -0
- package/jsx-dev-runtime.d.ts +1 -0
- package/jsx-dev-runtime.js +1 -0
- package/jsx-runtime.d.ts +9 -0
- package/jsx-runtime.js +157 -0
- package/jsx.d.ts +806 -0
- package/jsx.js +1 -0
- package/package.json +5 -3
- package/prop.d.ts +43 -0
- package/prop.js +174 -0
- package/render.d.ts +3 -0
- package/render.js +7 -0
- package/renderable.d.ts +5 -0
- package/renderable.js +1 -0
- package/types/clean.d.ts +2 -0
- package/types/clean.js +1 -0
- package/types/idom-context.d.ts +27 -0
- package/types/idom-context.js +3 -0
- package/types/renderable.d.ts +5 -0
- package/types/renderable.js +1 -0
- package/.eslintignore +0 -10
- package/.eslintrc.cjs +0 -28
- package/coverage/clover.xml +0 -39
- package/coverage/coverage-final.json +0 -2
- package/coverage/lcov-report/OneOf.ts.html +0 -256
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/dom-context.ts.html +0 -928
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -116
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/prop.ts.html +0 -691
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/components/Attribute.ts.html +0 -154
- package/coverage/lcov-report/src/components/BooleanAttribute.ts.html +0 -154
- package/coverage/lcov-report/src/components/ClassName.ts.html +0 -151
- package/coverage/lcov-report/src/components/El.ts.html +0 -166
- package/coverage/lcov-report/src/components/FadeIn.ts.html +0 -262
- package/coverage/lcov-report/src/components/FadeOut.ts.html +0 -226
- package/coverage/lcov-report/src/components/For.ts.html +0 -151
- package/coverage/lcov-report/src/components/Fragment.ts.html +0 -142
- package/coverage/lcov-report/src/components/HiddenWhenEmpty.ts.html +0 -133
- package/coverage/lcov-report/src/components/If.ts.html +0 -217
- package/coverage/lcov-report/src/components/InnerHTML.ts.html +0 -178
- package/coverage/lcov-report/src/components/Lifecycle.ts.html +0 -157
- package/coverage/lcov-report/src/components/Match.ts.html +0 -286
- package/coverage/lcov-report/src/components/NotEmpty.tsx.html +0 -184
- package/coverage/lcov-report/src/components/On.ts.html +0 -151
- package/coverage/lcov-report/src/components/OnRemove.ts.html +0 -145
- package/coverage/lcov-report/src/components/OneOf.ts.html +0 -256
- package/coverage/lcov-report/src/components/Portal.ts.html +0 -175
- package/coverage/lcov-report/src/components/Property.ts.html +0 -154
- package/coverage/lcov-report/src/components/Provider.ts.html +0 -244
- package/coverage/lcov-report/src/components/Repeat.ts.html +0 -223
- package/coverage/lcov-report/src/components/Show.tsx.html +0 -190
- package/coverage/lcov-report/src/components/Text.ts.html +0 -229
- package/coverage/lcov-report/src/components/TextContent.ts.html +0 -178
- package/coverage/lcov-report/src/components/Tween.tsx.html +0 -943
- package/coverage/lcov-report/src/components/animatable.ts.html +0 -619
- package/coverage/lcov-report/src/components/index.html +0 -476
- package/coverage/lcov-report/src/dom-context.ts.html +0 -928
- package/coverage/lcov-report/src/helpers/handle-anchor-click.ts.html +0 -277
- package/coverage/lcov-report/src/helpers/handle-text-input.ts.html +0 -100
- package/coverage/lcov-report/src/helpers/index.html +0 -146
- package/coverage/lcov-report/src/helpers/is-empty-element.ts.html +0 -112
- package/coverage/lcov-report/src/index.html +0 -176
- package/coverage/lcov-report/src/index.ts.html +0 -412
- package/coverage/lcov-report/src/jsx-runtime.ts.html +0 -601
- package/coverage/lcov-report/src/prop.ts.html +0 -691
- package/coverage/lcov-report/src/render.ts.html +0 -112
- package/coverage/lcov-report/src/types/idom-context.ts.html +0 -184
- package/coverage/lcov-report/src/types/index.html +0 -116
- package/coverage/lcov-report/test/common.ts.html +0 -112
- package/coverage/lcov-report/test/index.html +0 -116
- package/coverage/lcov.info +0 -57
- package/jest.config.js +0 -5
- package/src/clean.ts +0 -2
- package/src/components/Attribute.ts +0 -23
- package/src/components/BooleanAttribute.ts +0 -23
- package/src/components/ClassName.ts +0 -22
- package/src/components/El.ts +0 -27
- package/src/components/FadeIn.ts +0 -59
- package/src/components/FadeOut.ts +0 -47
- package/src/components/For.ts +0 -22
- package/src/components/Fragment.ts +0 -19
- package/src/components/HiddenWhenEmpty.ts +0 -16
- package/src/components/If.ts +0 -44
- package/src/components/InnerHTML.ts +0 -31
- package/src/components/Lifecycle.ts +0 -24
- package/src/components/Match.ts +0 -67
- package/src/components/NotEmpty.tsx +0 -33
- package/src/components/On.ts +0 -22
- package/src/components/OnRemove.ts +0 -20
- package/src/components/OneOf.ts +0 -57
- package/src/components/Portal.ts +0 -30
- package/src/components/Property.ts +0 -23
- package/src/components/Provider.ts +0 -53
- package/src/components/Repeat.ts +0 -46
- package/src/components/Show.tsx +0 -35
- package/src/components/Text.ts +0 -48
- package/src/components/TextContent.ts +0 -31
- package/src/components/animatable.ts +0 -178
- package/src/dom-context.ts +0 -281
- package/src/helpers/handle-anchor-click.ts +0 -64
- package/src/helpers/handle-text-input.ts +0 -5
- package/src/helpers/is-empty-element.ts +0 -9
- package/src/index.ts +0 -109
- package/src/jsx-dev-runtime.ts +0 -8
- package/src/jsx-runtime.ts +0 -172
- package/src/jsx.ts +0 -1046
- package/src/prop.ts +0 -202
- package/src/render.ts +0 -9
- package/src/renderable.ts +0 -6
- package/test/common.ts +0 -9
- package/test/component.spec.tsx +0 -27
- package/test/domcontext.spec.ts +0 -36
- package/test/fadein.spec.tsx +0 -36
- package/test/fadeout.spec.tsx +0 -41
- package/test/if.spec.tsx +0 -30
- package/test/innerhtml.spec.tsx +0 -45
- package/test/prop.spec.ts +0 -10
- package/test/render.spec.tsx +0 -19
- package/test/textcontent.spec.tsx +0 -45
- package/test/when.spec.tsx +0 -30
- package/tsconfig.json +0 -21
- /package/{dist/index.js → index.js} +0 -0
package/src/prop.ts
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
export type ArgsToSignals<T extends [...unknown[]]> = T extends [] ? [] : T extends [infer U, ...infer V] ? [Signal<U>, ...ArgsToSignals<V>] : []
|
|
2
|
-
|
|
3
|
-
const $isSignal = Symbol('isSignal')
|
|
4
|
-
const $isProp = Symbol('isProp')
|
|
5
|
-
|
|
6
|
-
export type Value<T> = T | Signal<T>
|
|
7
|
-
|
|
8
|
-
export class Signal<T> {
|
|
9
|
-
static of<T>(value: T): Signal<T> {
|
|
10
|
-
return new Signal(value)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
static ofValue<T>(value: Value<T> | null | undefined): Signal<T> | undefined {
|
|
14
|
-
return value == null ? undefined : Signal.wrap(value)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static wrap<T>(value: T | Signal<T>): Signal<T> {
|
|
18
|
-
return Signal.isSignal<T>(value) ? value : new Signal(value)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static isSignal<T = unknown>(x: unknown): x is Signal<T> {
|
|
22
|
-
const s = x as Signal<T>
|
|
23
|
-
return s != null && typeof s.get === 'function' && typeof s.subscribe === 'function'
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Combines many into one using a merging function
|
|
28
|
-
*/
|
|
29
|
-
static combine<Args extends [...unknown[]], Out>(
|
|
30
|
-
others: ArgsToSignals<Args>,
|
|
31
|
-
f: (...args: Args) => Out
|
|
32
|
-
): Signal<Out> {
|
|
33
|
-
function getValues(others: Array<Prop<unknown>>): Args {
|
|
34
|
-
return others.map(other => other.get()) as Args
|
|
35
|
-
}
|
|
36
|
-
const prop = new Prop(f(...getValues(others)))
|
|
37
|
-
others.forEach((other: Prop<unknown>) => {
|
|
38
|
-
other.subscribe(() => {
|
|
39
|
-
prop.set(f(...getValues(others)))
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
return prop
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public readonly [$isSignal] = true
|
|
46
|
-
|
|
47
|
-
protected readonly _listeners: Array<(value: T) => void> = []
|
|
48
|
-
constructor(protected _value: T) { }
|
|
49
|
-
readonly get = (): T => {
|
|
50
|
-
return this._value
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
readonly subscribe = (listener: (value: T) => void): () => void => {
|
|
54
|
-
this._listeners.push(listener)
|
|
55
|
-
return () => {
|
|
56
|
-
const index = this._listeners.indexOf(listener)
|
|
57
|
-
if (index >= 0) { this._listeners.splice(index, 1) }
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
readonly map = <V>(f: (value: T) => V): Signal<V> => {
|
|
62
|
-
const prop = new Prop(f(this._value))
|
|
63
|
-
this.subscribe(value => { prop.set(f(value)) })
|
|
64
|
-
return prop
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
readonly flatMap = <V>(f: (value: T) => Signal<V>): Signal<V> => {
|
|
68
|
-
let signal = f(this._value)
|
|
69
|
-
const prop = new Prop(signal.get())
|
|
70
|
-
this.subscribe(value => {
|
|
71
|
-
signal.clean()
|
|
72
|
-
signal = f(value)
|
|
73
|
-
signal.subscribe(value => { prop.set(value) })
|
|
74
|
-
})
|
|
75
|
-
return prop
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
readonly tap = (f: (value: T) => void): this => {
|
|
79
|
-
f(this._value)
|
|
80
|
-
this.subscribe(f)
|
|
81
|
-
return this
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
readonly at = <K extends keyof T>(key: K): Signal<T[K]> => {
|
|
85
|
-
return this.map(value => value[key])
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
readonly filter = (predicate: (value: T) => boolean): Signal<T> => {
|
|
89
|
-
const prop = new Prop(this._value)
|
|
90
|
-
this.subscribe(value => {
|
|
91
|
-
if (predicate(value)) {
|
|
92
|
-
prop.set(value)
|
|
93
|
-
}
|
|
94
|
-
})
|
|
95
|
-
return prop
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
readonly distinct = (equality: (a: T, b: T) => boolean): Signal<T> => {
|
|
99
|
-
let lastValue = this._value
|
|
100
|
-
return this.filter(value => {
|
|
101
|
-
const result = !equality(value, lastValue)
|
|
102
|
-
lastValue = value
|
|
103
|
-
return result
|
|
104
|
-
})
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
readonly mapAsync = <V>(f: (value: T) => Promise<V>, alt: V): Signal<V> => {
|
|
108
|
-
let counter = 0
|
|
109
|
-
const prop = new Prop(alt)
|
|
110
|
-
f(this._value)
|
|
111
|
-
.then(value => {
|
|
112
|
-
if (counter === 0) prop.set(value)
|
|
113
|
-
})
|
|
114
|
-
.catch(e => {
|
|
115
|
-
throw e
|
|
116
|
-
})
|
|
117
|
-
this.subscribe(value => {
|
|
118
|
-
const matchCounter = ++counter
|
|
119
|
-
f(value)
|
|
120
|
-
.then(value => {
|
|
121
|
-
if (matchCounter === counter) { prop.set(value) }
|
|
122
|
-
})
|
|
123
|
-
.catch(e => {
|
|
124
|
-
throw e
|
|
125
|
-
})
|
|
126
|
-
})
|
|
127
|
-
return prop
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
readonly mapMaybe = <V>(f: (value: T) => V | null | undefined, alt: V): Signal<V> => {
|
|
131
|
-
const prop = new Prop(f(this._value) ?? alt)
|
|
132
|
-
this.subscribe(value => {
|
|
133
|
-
const newValue = f(value)
|
|
134
|
-
if (newValue != null) prop.set(newValue)
|
|
135
|
-
})
|
|
136
|
-
return prop
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
readonly combine = <V, Z>(other: Signal<V>, f: (a: T, b: V) => Z): Signal<Z> => {
|
|
140
|
-
const prop = new Prop(f(this._value, other.get()))
|
|
141
|
-
this.subscribe(value => { prop.set(f(value, other.get())) })
|
|
142
|
-
other.subscribe(value => { prop.set(f(this._value, value)) })
|
|
143
|
-
return prop
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
readonly feed = (prop: Prop<T>): Prop<T> => {
|
|
147
|
-
this.subscribe(value => { prop.set(value) })
|
|
148
|
-
return prop
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
readonly deriveProp = (): Prop<T> => {
|
|
152
|
-
return new Prop(this._value)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
readonly clean = (): void => {
|
|
156
|
-
this._listeners.length = 0
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export class Prop<T> extends Signal<T> {
|
|
161
|
-
static isProp<T = unknown>(x: unknown): x is Prop<T> {
|
|
162
|
-
const p = x as Prop<T>
|
|
163
|
-
return Signal.isSignal(x) && typeof p.set === 'function'
|
|
164
|
-
// return x != null && (x as Prop<T>)[$isProp] === true
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
static override of<T>(value: T): Prop<T> {
|
|
168
|
-
return new Prop(value)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
public readonly [$isProp] = true
|
|
172
|
-
|
|
173
|
-
readonly set = (value: T): void => {
|
|
174
|
-
if (this._value === value) return
|
|
175
|
-
this._value = value
|
|
176
|
-
this._listeners.forEach(listener => { listener(value) })
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
readonly update = (f: (value: T) => T): void => {
|
|
180
|
-
this.set(f(this._value))
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
readonly atLens = <K extends keyof T>(key: K): Prop<T[K]> => {
|
|
184
|
-
return this.iso(
|
|
185
|
-
value => value[key],
|
|
186
|
-
value => ({ ...this._value, [key]: value })
|
|
187
|
-
)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
readonly reducer = <V>(f: (state: T, action: V) => T) => {
|
|
191
|
-
return (action: V) => {
|
|
192
|
-
this.set(f(this._value, action))
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
readonly iso = <V>(map: (value: T) => V, reverse: (value: V) => T): Prop<V> => {
|
|
197
|
-
const prop = new Prop(map(this._value))
|
|
198
|
-
this.subscribe(value => { prop.set(map(value)) })
|
|
199
|
-
prop.subscribe(value => { this.set(reverse(value)) })
|
|
200
|
-
return prop
|
|
201
|
-
}
|
|
202
|
-
}
|
package/src/render.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { DOMContext } from './dom-context'
|
|
2
|
-
import { type JSX, makeRenderable } from './jsx-runtime'
|
|
3
|
-
import { type Clean } from './clean'
|
|
4
|
-
|
|
5
|
-
export function render(renderable: JSX.DOMNode, element: HTMLElement): Clean {
|
|
6
|
-
const ctx = DOMContext.of(element)
|
|
7
|
-
const clear = makeRenderable(renderable).appendTo(ctx)
|
|
8
|
-
return () => { clear(true) }
|
|
9
|
-
}
|
package/src/renderable.ts
DELETED
package/test/common.ts
DELETED
package/test/component.spec.tsx
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jsxImportSource ../src
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { DOMContext, Prop } from '../src'
|
|
6
|
-
import { expectBody } from './common'
|
|
7
|
-
import { makeRenderable } from '../src/jsx-runtime'
|
|
8
|
-
|
|
9
|
-
export const Custom = ({ name, email }: { name: Prop<string>, email: string }) => {
|
|
10
|
-
return (
|
|
11
|
-
<div>
|
|
12
|
-
{name}: {email}
|
|
13
|
-
</div>
|
|
14
|
-
)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe('Component', () => {
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
document.getElementsByTagName('html')[0].innerHTML = ''
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
test('should access scope', () => {
|
|
23
|
-
// Tempo.mount(<Custom name="some" />)
|
|
24
|
-
makeRenderable(<Custom name={Prop.of("foo")} email="bar@gmail.com" />).appendTo(DOMContext.of(document.body))
|
|
25
|
-
expectBody().toBe('<div>foo: bar@gmail.com</div>')
|
|
26
|
-
})
|
|
27
|
-
})
|
package/test/domcontext.spec.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { DOMContext } from '../src/dom-context'
|
|
2
|
-
|
|
3
|
-
describe('DOMContext', () => {
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
document.body.innerHTML = ''
|
|
6
|
-
document.head.innerHTML = ''
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
test('setAttribute', () => {
|
|
10
|
-
const ctx = DOMContext.of(document.createElement('div'))
|
|
11
|
-
expect(ctx.getElement()).not.toBeNull()
|
|
12
|
-
ctx.setAttribute('id', 'foo')
|
|
13
|
-
expect(ctx.getElement().outerHTML).toBe('<div id="foo"></div>')
|
|
14
|
-
ctx.setAttribute('id', null)
|
|
15
|
-
expect(ctx.getElement().outerHTML).toBe('<div></div>')
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test('setBooleanAttribute', () => {
|
|
19
|
-
const ctx = DOMContext.of(document.createElement('div'))
|
|
20
|
-
expect(ctx.getElement()).not.toBeNull()
|
|
21
|
-
ctx.setBooleanAttribute('hidden', true)
|
|
22
|
-
expect(ctx.getElement().outerHTML).toBe('<div hidden=""></div>')
|
|
23
|
-
ctx.setBooleanAttribute('hidden', false)
|
|
24
|
-
expect(ctx.getElement().outerHTML).toBe('<div></div>')
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
test('createClass', () => {
|
|
28
|
-
const ctx = DOMContext.of(document.createElement('div'))
|
|
29
|
-
const [setClass, clear] = ctx.createClass('foo')
|
|
30
|
-
expect(ctx.getElement().outerHTML).toBe('<div class="foo"></div>')
|
|
31
|
-
setClass('bar')
|
|
32
|
-
expect(ctx.getElement().outerHTML).toBe('<div class="bar"></div>')
|
|
33
|
-
clear(true)
|
|
34
|
-
expect(ctx.getElement().outerHTML).toBe('<div></div>')
|
|
35
|
-
})
|
|
36
|
-
})
|
package/test/fadein.spec.tsx
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jsxImportSource ../src
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { render, FadeIn } from '../src'
|
|
6
|
-
|
|
7
|
-
function sleep(ms: number) {
|
|
8
|
-
return new Promise(resolve => setTimeout(resolve, ms))
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
describe('FadeIn', () => {
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
document.body.innerHTML = ''
|
|
14
|
-
document.head.innerHTML = ''
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
test('with delay and start', async () => {
|
|
18
|
-
const view = <div><FadeIn delay={10} duration={10} start={{ opacity: 0 }} opacity={1} /></div>
|
|
19
|
-
render(view, document.body)
|
|
20
|
-
expect(document.body.innerHTML).toBe('<div style="opacity: 0;"></div>')
|
|
21
|
-
await sleep(1)
|
|
22
|
-
expect(document.body.innerHTML).toBe('<div style="opacity: 0;"></div>')
|
|
23
|
-
await sleep(20)
|
|
24
|
-
expect(document.body.innerHTML).toBe('<div style="opacity: 1;"></div>')
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
test('without delay and start', async () => {
|
|
28
|
-
const view = <div><FadeIn duration={10} opacity={1} /></div>
|
|
29
|
-
render(view, document.body)
|
|
30
|
-
expect(document.body.innerHTML).toBe('<div style="opacity: 0;"></div>')
|
|
31
|
-
await sleep(1)
|
|
32
|
-
expect(document.body.innerHTML).not.toBe('<div style="opacity: 0;"></div>')
|
|
33
|
-
await sleep(20)
|
|
34
|
-
expect(document.body.innerHTML).toBe('<div style="opacity: 1;"></div>')
|
|
35
|
-
})
|
|
36
|
-
})
|
package/test/fadeout.spec.tsx
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jsxImportSource ../src
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { render, FadeOut, Prop, When } from '../src'
|
|
6
|
-
|
|
7
|
-
function sleep(ms: number) {
|
|
8
|
-
return new Promise(resolve => setTimeout(resolve, ms))
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
describe('FadeOut', () => {
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
document.body.innerHTML = ''
|
|
14
|
-
document.head.innerHTML = ''
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
test('removed with clear', async () => {
|
|
18
|
-
const view = <div style="opacity: 1"><FadeOut duration={10} opacity={0} /></div>
|
|
19
|
-
const clear = render(view, document.body)
|
|
20
|
-
expect(document.body.innerHTML).toBe('<div style="opacity: 1;"></div>')
|
|
21
|
-
clear()
|
|
22
|
-
expect(document.body.innerHTML).toBe('<div style="opacity: 1;"></div>')
|
|
23
|
-
await sleep(1)
|
|
24
|
-
expect(document.body.innerHTML).not.toBe('<div style="opacity: 1;"></div>')
|
|
25
|
-
await sleep(20)
|
|
26
|
-
expect(document.body.innerHTML).toBe('')
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
test('with delay', async () => {
|
|
30
|
-
const cond = Prop.of(true)
|
|
31
|
-
const view = <When is={cond}><div style="opacity: 1"><FadeOut delay={10} duration={10} opacity={0} /></div></When>
|
|
32
|
-
render(view, document.body)
|
|
33
|
-
expect(document.body.innerHTML).toBe('<div style="opacity: 1;"></div>')
|
|
34
|
-
cond.set(false)
|
|
35
|
-
expect(document.body.innerHTML).toBe('<div style="opacity: 1;"></div>')
|
|
36
|
-
await sleep(1)
|
|
37
|
-
expect(document.body.innerHTML).toBe('<div style="opacity: 1;"></div>')
|
|
38
|
-
await sleep(20)
|
|
39
|
-
expect(document.body.innerHTML).toBe('')
|
|
40
|
-
})
|
|
41
|
-
})
|
package/test/if.spec.tsx
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jsxImportSource ../src
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { render, If, Prop } from '../src'
|
|
6
|
-
|
|
7
|
-
describe('If', () => {
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
document.body.innerHTML = ''
|
|
10
|
-
document.head.innerHTML = ''
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
test('when true/false', () => {
|
|
14
|
-
const prop = Prop.of(true)
|
|
15
|
-
const view = <If is={prop} then={<div>foo</div>} otherwise={<span>bar</span>} />
|
|
16
|
-
render(view, document.body)
|
|
17
|
-
expect(document.body.innerHTML).toBe('<div>foo</div>')
|
|
18
|
-
prop.set(false)
|
|
19
|
-
expect(document.body.innerHTML).toBe('<span>bar</span>')
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
test('without false', () => {
|
|
23
|
-
const prop = Prop.of(true)
|
|
24
|
-
const view = <If is={prop} then={<div>foo</div>} />
|
|
25
|
-
render(view, document.body)
|
|
26
|
-
expect(document.body.innerHTML).toBe('<div>foo</div>')
|
|
27
|
-
prop.set(false)
|
|
28
|
-
expect(document.body.innerHTML).toBe('')
|
|
29
|
-
})
|
|
30
|
-
})
|
package/test/innerhtml.spec.tsx
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jsxImportSource ../src
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { render, Prop, InnerHTML, When } from '../src'
|
|
6
|
-
|
|
7
|
-
describe('InnerHTML', () => {
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
document.body.innerHTML = ''
|
|
10
|
-
document.head.innerHTML = ''
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
test('set', () => {
|
|
14
|
-
const prop = Prop.of("<b>foo</b>")
|
|
15
|
-
const view = <div><InnerHTML html={prop} /></div>
|
|
16
|
-
render(view, document.body)
|
|
17
|
-
expect(document.body.innerHTML).toBe('<div><b>foo</b></div>')
|
|
18
|
-
prop.set("<i>bar</i>")
|
|
19
|
-
expect(document.body.innerHTML).toBe('<div><i>bar</i></div>')
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
test('restore', () => {
|
|
23
|
-
const cond = Prop.of(true)
|
|
24
|
-
const prop = Prop.of("foo")
|
|
25
|
-
document.body.textContent = "default"
|
|
26
|
-
const view = <When is={cond}><InnerHTML html={prop} /></When>
|
|
27
|
-
render(view, document.body)
|
|
28
|
-
expect(document.body.innerHTML).toBe('foo')
|
|
29
|
-
prop.set("bar")
|
|
30
|
-
expect(document.body.innerHTML).toBe('bar')
|
|
31
|
-
cond.set(false)
|
|
32
|
-
expect(document.body.innerHTML).toBe('default')
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
test('set nullable', () => {
|
|
36
|
-
const prop = Prop.of(undefined as string | undefined)
|
|
37
|
-
const view = <div><InnerHTML html={prop} /></div>
|
|
38
|
-
render(view, document.body)
|
|
39
|
-
expect(document.body.innerHTML).toBe('<div></div>')
|
|
40
|
-
prop.set("bar")
|
|
41
|
-
expect(document.body.innerHTML).toBe('<div>bar</div>')
|
|
42
|
-
prop.set(undefined)
|
|
43
|
-
expect(document.body.innerHTML).toBe('<div></div>')
|
|
44
|
-
})
|
|
45
|
-
})
|
package/test/prop.spec.ts
DELETED
package/test/render.spec.tsx
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jsxImportSource ../src
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { render } from '../src'
|
|
6
|
-
|
|
7
|
-
describe('render', () => {
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
document.body.innerHTML = ''
|
|
10
|
-
document.head.innerHTML = ''
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
test('render div', () => {
|
|
14
|
-
const clear = render(<div>foo</div>, document.body)
|
|
15
|
-
expect(document.body.innerHTML).toBe('<div>foo</div>')
|
|
16
|
-
clear()
|
|
17
|
-
expect(document.body.innerHTML).toBe('')
|
|
18
|
-
})
|
|
19
|
-
})
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jsxImportSource ../src
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { render, If, Prop, TextContent, When } from '../src'
|
|
6
|
-
|
|
7
|
-
describe('TextContent', () => {
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
document.body.innerHTML = ''
|
|
10
|
-
document.head.innerHTML = ''
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
test('set', () => {
|
|
14
|
-
const prop = Prop.of("foo")
|
|
15
|
-
const view = <div><TextContent value={prop} /></div>
|
|
16
|
-
render(view, document.body)
|
|
17
|
-
expect(document.body.innerHTML).toBe('<div>foo</div>')
|
|
18
|
-
prop.set("bar")
|
|
19
|
-
expect(document.body.innerHTML).toBe('<div>bar</div>')
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
test('restore', () => {
|
|
23
|
-
const cond = Prop.of(true)
|
|
24
|
-
const prop = Prop.of("foo")
|
|
25
|
-
document.body.textContent = "default"
|
|
26
|
-
const view = <When is={cond}><TextContent value={prop} /></When>
|
|
27
|
-
render(view, document.body)
|
|
28
|
-
expect(document.body.innerHTML).toBe('foo')
|
|
29
|
-
prop.set("bar")
|
|
30
|
-
expect(document.body.innerHTML).toBe('bar')
|
|
31
|
-
cond.set(false)
|
|
32
|
-
expect(document.body.innerHTML).toBe('default')
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
test('set nullable', () => {
|
|
36
|
-
const prop = Prop.of(undefined as string | undefined)
|
|
37
|
-
const view = <div><TextContent value={prop} /></div>
|
|
38
|
-
render(view, document.body)
|
|
39
|
-
expect(document.body.innerHTML).toBe('<div></div>')
|
|
40
|
-
prop.set("bar")
|
|
41
|
-
expect(document.body.innerHTML).toBe('<div>bar</div>')
|
|
42
|
-
prop.set(undefined)
|
|
43
|
-
expect(document.body.innerHTML).toBe('<div></div>')
|
|
44
|
-
})
|
|
45
|
-
})
|
package/test/when.spec.tsx
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jsxImportSource ../src
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { render, When, Unless, Prop } from '../src'
|
|
6
|
-
|
|
7
|
-
describe('When', () => {
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
document.body.innerHTML = ''
|
|
10
|
-
document.head.innerHTML = ''
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
test('when true/false', () => {
|
|
14
|
-
const prop = Prop.of(true)
|
|
15
|
-
const view = <When is={prop}><div>foo</div></When>
|
|
16
|
-
render(view, document.body)
|
|
17
|
-
expect(document.body.innerHTML).toBe('<div>foo</div>')
|
|
18
|
-
prop.set(false)
|
|
19
|
-
expect(document.body.innerHTML).toBe('')
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
test('unless true/false', () => {
|
|
23
|
-
const prop = Prop.of(false)
|
|
24
|
-
const view = <Unless is={prop}><div>foo</div></Unless>
|
|
25
|
-
render(view, document.body)
|
|
26
|
-
expect(document.body.innerHTML).toBe('<div>foo</div>')
|
|
27
|
-
prop.set(true)
|
|
28
|
-
expect(document.body.innerHTML).toBe('')
|
|
29
|
-
})
|
|
30
|
-
})
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"rootDir": "src",
|
|
4
|
-
"outDir": "dist",
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"useDefineForClassFields": true,
|
|
8
|
-
"module": "ESNext",
|
|
9
|
-
"lib": ["ESNext", "DOM"],
|
|
10
|
-
"moduleResolution": "Node",
|
|
11
|
-
"strict": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"isolatedModules": true,
|
|
14
|
-
"esModuleInterop": true,
|
|
15
|
-
"noImplicitReturns": true,
|
|
16
|
-
"skipLibCheck": true,
|
|
17
|
-
"jsx": "react-jsx",
|
|
18
|
-
"jsxImportSource": "./src",
|
|
19
|
-
},
|
|
20
|
-
"include": ["src/**/*"]
|
|
21
|
-
}
|
|
File without changes
|