@tempots/dom 5.0.0 → 5.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.
Files changed (191) hide show
  1. package/dist/clean.d.ts +2 -0
  2. package/dist/clean.js +1 -0
  3. package/dist/components/Attribute.d.ts +15 -0
  4. package/dist/components/Attribute.js +16 -0
  5. package/dist/components/BooleanAttribute.d.ts +15 -0
  6. package/dist/components/BooleanAttribute.js +16 -0
  7. package/dist/components/ClassName.d.ts +13 -0
  8. package/dist/components/ClassName.js +14 -0
  9. package/dist/components/El.d.ts +15 -0
  10. package/dist/components/El.js +21 -0
  11. package/dist/components/FadeIn.d.ts +18 -0
  12. package/dist/components/FadeIn.js +52 -0
  13. package/dist/components/FadeOut.d.ts +16 -0
  14. package/dist/components/FadeOut.js +39 -0
  15. package/dist/components/For.d.ts +7 -0
  16. package/dist/components/For.js +15 -0
  17. package/dist/components/Fragment.d.ts +12 -0
  18. package/dist/components/Fragment.js +16 -0
  19. package/dist/components/HiddenWhenEmpty.d.ts +7 -0
  20. package/dist/components/HiddenWhenEmpty.js +12 -0
  21. package/dist/components/If.d.ts +14 -0
  22. package/dist/components/If.js +19 -0
  23. package/dist/components/InnerHTML.d.ts +13 -0
  24. package/dist/components/InnerHTML.js +23 -0
  25. package/dist/components/Lifecycle.d.ts +14 -0
  26. package/dist/components/Lifecycle.js +18 -0
  27. package/dist/components/Match.d.ts +33 -0
  28. package/dist/components/Match.js +44 -0
  29. package/dist/components/NotEmpty.d.ts +10 -0
  30. package/dist/components/NotEmpty.js +11 -0
  31. package/dist/components/On.d.ts +15 -0
  32. package/dist/components/On.js +14 -0
  33. package/dist/components/OnRemove.d.ts +11 -0
  34. package/dist/components/OnRemove.js +14 -0
  35. package/dist/components/OneOf.d.ts +20 -0
  36. package/dist/components/OneOf.js +45 -0
  37. package/dist/components/Portal.d.ts +15 -0
  38. package/dist/components/Portal.js +20 -0
  39. package/dist/components/Property.d.ts +15 -0
  40. package/dist/components/Property.js +16 -0
  41. package/dist/components/Provider.d.ts +28 -0
  42. package/dist/components/Provider.js +44 -0
  43. package/dist/components/Repeat.d.ts +15 -0
  44. package/dist/components/Repeat.js +33 -0
  45. package/dist/components/Shadow.d.ts +0 -0
  46. package/dist/components/Shadow.js +1 -0
  47. package/dist/components/Show.d.ts +20 -0
  48. package/dist/components/Show.js +22 -0
  49. package/dist/components/Text.d.ts +15 -0
  50. package/dist/components/Text.js +33 -0
  51. package/dist/components/TextContent.d.ts +13 -0
  52. package/dist/components/TextContent.js +23 -0
  53. package/dist/components/Tween.d.ts +75 -0
  54. package/dist/components/Tween.js +242 -0
  55. package/dist/components/animatable.d.ts +53 -0
  56. package/dist/components/animatable.js +156 -0
  57. package/dist/dom-context.d.ts +38 -0
  58. package/dist/dom-context.js +260 -0
  59. package/dist/helpers/handle-anchor-click.d.ts +4 -0
  60. package/dist/helpers/handle-anchor-click.js +43 -0
  61. package/dist/helpers/handle-text-input.d.ts +1 -0
  62. package/dist/helpers/handle-text-input.js +4 -0
  63. package/dist/helpers/is-empty-element.d.ts +2 -0
  64. package/dist/helpers/is-empty-element.js +8 -0
  65. package/dist/index.d.ts +36 -0
  66. package/dist/jsx-dev-runtime.d.ts +1 -0
  67. package/dist/jsx-dev-runtime.js +1 -0
  68. package/dist/jsx-runtime.d.ts +9 -0
  69. package/dist/jsx-runtime.js +157 -0
  70. package/dist/jsx.d.ts +806 -0
  71. package/dist/jsx.js +1 -0
  72. package/dist/prop.d.ts +43 -0
  73. package/dist/prop.js +174 -0
  74. package/dist/render.d.ts +3 -0
  75. package/dist/render.js +7 -0
  76. package/dist/renderable.d.ts +5 -0
  77. package/dist/renderable.js +1 -0
  78. package/dist/types/clean.d.ts +2 -0
  79. package/dist/types/clean.js +1 -0
  80. package/dist/types/idom-context.d.ts +27 -0
  81. package/dist/types/idom-context.js +3 -0
  82. package/dist/types/renderable.d.ts +5 -0
  83. package/dist/types/renderable.js +1 -0
  84. package/package.json +5 -1
  85. package/.eslintignore +0 -10
  86. package/.eslintrc.cjs +0 -28
  87. package/coverage/clover.xml +0 -39
  88. package/coverage/coverage-final.json +0 -2
  89. package/coverage/lcov-report/OneOf.ts.html +0 -256
  90. package/coverage/lcov-report/base.css +0 -224
  91. package/coverage/lcov-report/block-navigation.js +0 -87
  92. package/coverage/lcov-report/dom-context.ts.html +0 -928
  93. package/coverage/lcov-report/favicon.png +0 -0
  94. package/coverage/lcov-report/index.html +0 -116
  95. package/coverage/lcov-report/prettify.css +0 -1
  96. package/coverage/lcov-report/prettify.js +0 -2
  97. package/coverage/lcov-report/prop.ts.html +0 -691
  98. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  99. package/coverage/lcov-report/sorter.js +0 -196
  100. package/coverage/lcov-report/src/components/Attribute.ts.html +0 -154
  101. package/coverage/lcov-report/src/components/BooleanAttribute.ts.html +0 -154
  102. package/coverage/lcov-report/src/components/ClassName.ts.html +0 -151
  103. package/coverage/lcov-report/src/components/El.ts.html +0 -166
  104. package/coverage/lcov-report/src/components/FadeIn.ts.html +0 -262
  105. package/coverage/lcov-report/src/components/FadeOut.ts.html +0 -226
  106. package/coverage/lcov-report/src/components/For.ts.html +0 -151
  107. package/coverage/lcov-report/src/components/Fragment.ts.html +0 -142
  108. package/coverage/lcov-report/src/components/HiddenWhenEmpty.ts.html +0 -133
  109. package/coverage/lcov-report/src/components/If.ts.html +0 -217
  110. package/coverage/lcov-report/src/components/InnerHTML.ts.html +0 -178
  111. package/coverage/lcov-report/src/components/Lifecycle.ts.html +0 -157
  112. package/coverage/lcov-report/src/components/Match.ts.html +0 -286
  113. package/coverage/lcov-report/src/components/NotEmpty.tsx.html +0 -184
  114. package/coverage/lcov-report/src/components/On.ts.html +0 -151
  115. package/coverage/lcov-report/src/components/OnRemove.ts.html +0 -145
  116. package/coverage/lcov-report/src/components/OneOf.ts.html +0 -256
  117. package/coverage/lcov-report/src/components/Portal.ts.html +0 -175
  118. package/coverage/lcov-report/src/components/Property.ts.html +0 -154
  119. package/coverage/lcov-report/src/components/Provider.ts.html +0 -244
  120. package/coverage/lcov-report/src/components/Repeat.ts.html +0 -223
  121. package/coverage/lcov-report/src/components/Show.tsx.html +0 -190
  122. package/coverage/lcov-report/src/components/Text.ts.html +0 -229
  123. package/coverage/lcov-report/src/components/TextContent.ts.html +0 -178
  124. package/coverage/lcov-report/src/components/Tween.tsx.html +0 -943
  125. package/coverage/lcov-report/src/components/animatable.ts.html +0 -619
  126. package/coverage/lcov-report/src/components/index.html +0 -476
  127. package/coverage/lcov-report/src/dom-context.ts.html +0 -928
  128. package/coverage/lcov-report/src/helpers/handle-anchor-click.ts.html +0 -277
  129. package/coverage/lcov-report/src/helpers/handle-text-input.ts.html +0 -100
  130. package/coverage/lcov-report/src/helpers/index.html +0 -146
  131. package/coverage/lcov-report/src/helpers/is-empty-element.ts.html +0 -112
  132. package/coverage/lcov-report/src/index.html +0 -176
  133. package/coverage/lcov-report/src/index.ts.html +0 -412
  134. package/coverage/lcov-report/src/jsx-runtime.ts.html +0 -601
  135. package/coverage/lcov-report/src/prop.ts.html +0 -691
  136. package/coverage/lcov-report/src/render.ts.html +0 -112
  137. package/coverage/lcov-report/src/types/idom-context.ts.html +0 -184
  138. package/coverage/lcov-report/src/types/index.html +0 -116
  139. package/coverage/lcov-report/test/common.ts.html +0 -112
  140. package/coverage/lcov-report/test/index.html +0 -116
  141. package/coverage/lcov.info +0 -57
  142. package/jest.config.js +0 -5
  143. package/src/clean.ts +0 -2
  144. package/src/components/Attribute.ts +0 -23
  145. package/src/components/BooleanAttribute.ts +0 -23
  146. package/src/components/ClassName.ts +0 -22
  147. package/src/components/El.ts +0 -27
  148. package/src/components/FadeIn.ts +0 -59
  149. package/src/components/FadeOut.ts +0 -47
  150. package/src/components/For.ts +0 -22
  151. package/src/components/Fragment.ts +0 -19
  152. package/src/components/HiddenWhenEmpty.ts +0 -16
  153. package/src/components/If.ts +0 -44
  154. package/src/components/InnerHTML.ts +0 -31
  155. package/src/components/Lifecycle.ts +0 -24
  156. package/src/components/Match.ts +0 -67
  157. package/src/components/NotEmpty.tsx +0 -33
  158. package/src/components/On.ts +0 -22
  159. package/src/components/OnRemove.ts +0 -20
  160. package/src/components/OneOf.ts +0 -57
  161. package/src/components/Portal.ts +0 -30
  162. package/src/components/Property.ts +0 -23
  163. package/src/components/Provider.ts +0 -53
  164. package/src/components/Repeat.ts +0 -46
  165. package/src/components/Show.tsx +0 -35
  166. package/src/components/Text.ts +0 -48
  167. package/src/components/TextContent.ts +0 -31
  168. package/src/components/animatable.ts +0 -178
  169. package/src/dom-context.ts +0 -281
  170. package/src/helpers/handle-anchor-click.ts +0 -64
  171. package/src/helpers/handle-text-input.ts +0 -5
  172. package/src/helpers/is-empty-element.ts +0 -9
  173. package/src/index.ts +0 -109
  174. package/src/jsx-dev-runtime.ts +0 -8
  175. package/src/jsx-runtime.ts +0 -172
  176. package/src/jsx.ts +0 -1046
  177. package/src/prop.ts +0 -202
  178. package/src/render.ts +0 -9
  179. package/src/renderable.ts +0 -6
  180. package/test/common.ts +0 -9
  181. package/test/component.spec.tsx +0 -27
  182. package/test/domcontext.spec.ts +0 -36
  183. package/test/fadein.spec.tsx +0 -36
  184. package/test/fadeout.spec.tsx +0 -41
  185. package/test/if.spec.tsx +0 -30
  186. package/test/innerhtml.spec.tsx +0 -45
  187. package/test/prop.spec.ts +0 -10
  188. package/test/render.spec.tsx +0 -19
  189. package/test/textcontent.spec.tsx +0 -45
  190. package/test/when.spec.tsx +0 -30
  191. package/tsconfig.json +0 -21
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
@@ -1,6 +0,0 @@
1
- import { type DOMContext } from './dom-context'
2
- import { type Clear } from './clean'
3
-
4
- export interface Renderable {
5
- appendTo: (ctx: DOMContext) => Clear
6
- }
package/test/common.ts DELETED
@@ -1,9 +0,0 @@
1
- export type Assertion = ReturnType<typeof expect>
2
-
3
- export function expectBody() {
4
- return expect(document.body.innerHTML)
5
- }
6
-
7
- export function expectHead() {
8
- return expect(document.head.innerHTML)
9
- }
@@ -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
- })
@@ -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
- })
@@ -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
- })
@@ -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
- })
@@ -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
@@ -1,10 +0,0 @@
1
- import { Prop } from '../src/prop'
2
-
3
- describe('Prop', () => {
4
- test('get/set', () => {
5
- const prop = new Prop(1)
6
- expect(prop.get()).toBe(1)
7
- prop.set(2)
8
- expect(prop.get()).toBe(2)
9
- })
10
- })
@@ -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
- })
@@ -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
- }