@pyreon/ui-core 0.11.4 → 0.11.6
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 +15 -13
- package/lib/index.d.ts +19 -12
- package/lib/index.js +29 -19
- package/package.json +24 -24
- package/src/PyreonUI.tsx +28 -34
- package/src/__tests__/PyreonUI.test.tsx +40 -37
- package/src/__tests__/compose.test.ts +8 -8
- package/src/__tests__/config.test.ts +37 -37
- package/src/__tests__/context.test.tsx +28 -27
- package/src/__tests__/hoistNonReactStatics.test.tsx +44 -44
- package/src/__tests__/isEmpty.test.ts +15 -15
- package/src/__tests__/isEqual.test.ts +28 -28
- package/src/__tests__/render.test.tsx +28 -28
- package/src/__tests__/useStableValue.test.ts +23 -23
- package/src/__tests__/utils.test.ts +149 -149
- package/src/config.ts +7 -7
- package/src/context.tsx +43 -8
- package/src/hoistNonReactStatics.ts +1 -1
- package/src/html/htmlTags.ts +142 -142
- package/src/html/index.ts +3 -3
- package/src/index.ts +19 -17
- package/src/isEmpty.ts +1 -1
- package/src/isEqual.ts +1 -1
- package/src/render.tsx +6 -6
- package/src/useStableValue.ts +2 -2
- package/src/utils.ts +3 -3
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import type { VNode } from
|
|
2
|
-
import { Fragment, h } from
|
|
3
|
-
import { describe, expect, it } from
|
|
4
|
-
import renderFn from
|
|
1
|
+
import type { VNode } from '@pyreon/core'
|
|
2
|
+
import { Fragment, h } from '@pyreon/core'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
import renderFn from '../render'
|
|
5
5
|
|
|
6
6
|
const TestComponent = (props: { label?: string }) => {
|
|
7
|
-
return h(
|
|
7
|
+
return h('span', { 'data-testid': 'test' }, props.label ?? 'default')
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
describe(
|
|
11
|
-
it(
|
|
10
|
+
describe('render', () => {
|
|
11
|
+
it('should return null for falsy content', () => {
|
|
12
12
|
expect(renderFn(null)).toBeNull()
|
|
13
13
|
expect(renderFn(undefined)).toBeNull()
|
|
14
14
|
expect(renderFn(false as any)).toBeNull()
|
|
15
|
-
expect(renderFn(
|
|
15
|
+
expect(renderFn('' as any)).toBeNull()
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
it(
|
|
19
|
-
const result = renderFn(TestComponent, { label:
|
|
18
|
+
it('should render a component with props', () => {
|
|
19
|
+
const result = renderFn(TestComponent, { label: 'hello' }) as VNode
|
|
20
20
|
expect(result).toBeDefined()
|
|
21
21
|
expect(result.type).toBe(TestComponent)
|
|
22
|
-
expect(result.props.label).toBe(
|
|
22
|
+
expect(result.props.label).toBe('hello')
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
it(
|
|
25
|
+
it('should render a component without props', () => {
|
|
26
26
|
const result = renderFn(TestComponent) as VNode
|
|
27
27
|
expect(result).toBeDefined()
|
|
28
28
|
expect(result.type).toBe(TestComponent)
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
-
it(
|
|
32
|
-
expect(renderFn(
|
|
33
|
-
expect(renderFn(
|
|
31
|
+
it('should return string content as-is (treated as text)', () => {
|
|
32
|
+
expect(renderFn('div' as any)).toBe('div')
|
|
33
|
+
expect(renderFn('hello' as any)).toBe('hello')
|
|
34
34
|
})
|
|
35
35
|
|
|
36
|
-
it(
|
|
36
|
+
it('should return primitive values as-is', () => {
|
|
37
37
|
expect(renderFn(42 as any)).toBe(42)
|
|
38
38
|
expect(renderFn(true as any)).toBe(true)
|
|
39
|
-
expect(renderFn(
|
|
39
|
+
expect(renderFn('text' as any)).toBe('text')
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
-
it(
|
|
43
|
-
const arr = [h(
|
|
42
|
+
it('should return arrays as-is', () => {
|
|
43
|
+
const arr = [h('span', { key: '1' }, 'a'), h('span', { key: '2' }, 'b')]
|
|
44
44
|
expect(renderFn(arr as any)).toBe(arr)
|
|
45
45
|
})
|
|
46
46
|
|
|
47
|
-
it(
|
|
48
|
-
const vnode = h(TestComponent, { label:
|
|
47
|
+
it('should return a VNode object without modification when no props', () => {
|
|
48
|
+
const vnode = h(TestComponent, { label: 'original' })
|
|
49
49
|
const result = renderFn(vnode as any)
|
|
50
50
|
// VNode objects are returned as-is
|
|
51
51
|
expect(result).toBe(vnode)
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
it(
|
|
55
|
-
const vnode = h(TestComponent, { label:
|
|
56
|
-
const result = renderFn(vnode as any, { label:
|
|
54
|
+
it('should return a VNode object as-is even with props (VNode path does not merge)', () => {
|
|
55
|
+
const vnode = h(TestComponent, { label: 'original' })
|
|
56
|
+
const result = renderFn(vnode as any, { label: 'cloned' })
|
|
57
57
|
// In Pyreon's render, VNode objects hit the object branch and are returned as-is
|
|
58
58
|
expect(result).toBe(vnode)
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
it(
|
|
62
|
-
const frag = h(Fragment, null, h(
|
|
61
|
+
it('should return fragment as-is', () => {
|
|
62
|
+
const frag = h(Fragment, null, h('span', null, 'a'), h('span', null, 'b'))
|
|
63
63
|
const result = renderFn(frag as any)
|
|
64
64
|
expect(result).toBe(frag)
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
it(
|
|
67
|
+
it('should return plain object as-is (fallback branch)', () => {
|
|
68
68
|
// Plain objects are not valid elements, not primitives, not arrays
|
|
69
|
-
const obj = { foo:
|
|
69
|
+
const obj = { foo: 'bar' }
|
|
70
70
|
expect(renderFn(obj as any)).toBe(obj)
|
|
71
71
|
})
|
|
72
72
|
})
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
2
|
|
|
3
3
|
// ---------------------------------------------------------------------------
|
|
4
4
|
// Minimal signal mock that stores state across calls
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
6
|
-
vi.mock(
|
|
6
|
+
vi.mock('@pyreon/reactivity', () => ({
|
|
7
7
|
signal: <T>(initial: T) => {
|
|
8
8
|
let value = initial
|
|
9
9
|
const sig = (() => value) as (() => T) & {
|
|
@@ -34,39 +34,39 @@ vi.mock("@pyreon/reactivity", () => ({
|
|
|
34
34
|
},
|
|
35
35
|
}))
|
|
36
36
|
|
|
37
|
-
import useStableValue from
|
|
37
|
+
import useStableValue from '../useStableValue'
|
|
38
38
|
|
|
39
|
-
describe(
|
|
40
|
-
describe(
|
|
41
|
-
it(
|
|
42
|
-
const result = useStableValue(
|
|
43
|
-
expect(result).toBe(
|
|
39
|
+
describe('useStableValue', () => {
|
|
40
|
+
describe('primitives', () => {
|
|
41
|
+
it('returns the value on first call with a string', () => {
|
|
42
|
+
const result = useStableValue('hello')
|
|
43
|
+
expect(result).toBe('hello')
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
it(
|
|
46
|
+
it('returns the value on first call with a number', () => {
|
|
47
47
|
const result = useStableValue(42)
|
|
48
48
|
expect(result).toBe(42)
|
|
49
49
|
})
|
|
50
50
|
|
|
51
|
-
it(
|
|
51
|
+
it('returns the value on first call with a boolean', () => {
|
|
52
52
|
const result = useStableValue(true)
|
|
53
53
|
expect(result).toBe(true)
|
|
54
54
|
})
|
|
55
55
|
|
|
56
|
-
it(
|
|
56
|
+
it('returns the value on first call with null', () => {
|
|
57
57
|
const result = useStableValue(null)
|
|
58
58
|
expect(result).toBeNull()
|
|
59
59
|
})
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
describe(
|
|
63
|
-
it(
|
|
64
|
-
const obj = { a: 1, b:
|
|
62
|
+
describe('objects', () => {
|
|
63
|
+
it('returns the object value', () => {
|
|
64
|
+
const obj = { a: 1, b: 'two' }
|
|
65
65
|
const result = useStableValue(obj)
|
|
66
|
-
expect(result).toEqual({ a: 1, b:
|
|
66
|
+
expect(result).toEqual({ a: 1, b: 'two' })
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
-
it(
|
|
69
|
+
it('returns same reference when called with deeply equal value', () => {
|
|
70
70
|
// Each call creates a new signal, so we verify the value is correct
|
|
71
71
|
const obj1 = { x: 1, y: 2 }
|
|
72
72
|
const result = useStableValue(obj1)
|
|
@@ -74,14 +74,14 @@ describe("useStableValue", () => {
|
|
|
74
74
|
})
|
|
75
75
|
})
|
|
76
76
|
|
|
77
|
-
describe(
|
|
78
|
-
it(
|
|
77
|
+
describe('arrays', () => {
|
|
78
|
+
it('returns the array value', () => {
|
|
79
79
|
const arr = [1, 2, 3]
|
|
80
80
|
const result = useStableValue(arr)
|
|
81
81
|
expect(result).toEqual([1, 2, 3])
|
|
82
82
|
})
|
|
83
83
|
|
|
84
|
-
it(
|
|
84
|
+
it('handles nested arrays', () => {
|
|
85
85
|
const arr = [
|
|
86
86
|
[1, 2],
|
|
87
87
|
[3, 4],
|
|
@@ -94,14 +94,14 @@ describe("useStableValue", () => {
|
|
|
94
94
|
})
|
|
95
95
|
})
|
|
96
96
|
|
|
97
|
-
describe(
|
|
98
|
-
it(
|
|
99
|
-
const value = { key:
|
|
97
|
+
describe('signal interaction', () => {
|
|
98
|
+
it('creates a signal with the initial value and returns peek()', () => {
|
|
99
|
+
const value = { key: 'value' }
|
|
100
100
|
const result = useStableValue(value)
|
|
101
101
|
expect(result).toEqual(value)
|
|
102
102
|
})
|
|
103
103
|
|
|
104
|
-
it(
|
|
104
|
+
it('returns the initial value even for complex nested objects', () => {
|
|
105
105
|
const complex = {
|
|
106
106
|
nested: { deep: { value: 42 } },
|
|
107
107
|
arr: [1, [2, 3]],
|