@potok-web-framework/core 0.1.0
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/CHANGELOG.md +7 -0
- package/bun.lock +25 -0
- package/package.json +39 -0
- package/src/block.ts +102 -0
- package/src/bootstrap-app.ts +115 -0
- package/src/client-only.ts +17 -0
- package/src/constants.ts +27 -0
- package/src/context.ts +85 -0
- package/src/detect-child.ts +21 -0
- package/src/error-boundary.ts +51 -0
- package/src/exports/client.ts +1 -0
- package/src/exports/hmr.ts +1 -0
- package/src/exports/index.ts +21 -0
- package/src/exports/jsx-runtime.ts +4 -0
- package/src/exports/server.ts +1 -0
- package/src/fragment.ts +28 -0
- package/src/global.dev.d.ts +12 -0
- package/src/hmr/hmr-dev.ts +10 -0
- package/src/hmr/register-component.ts +109 -0
- package/src/hmr/registered-component.ts +59 -0
- package/src/hmr/registry.ts +78 -0
- package/src/hmr/types.ts +6 -0
- package/src/hmr/utils.ts +20 -0
- package/src/html-element.ts +95 -0
- package/src/jsx-types.ts +13 -0
- package/src/lazy.ts +44 -0
- package/src/lib-context-reader.ts +33 -0
- package/src/lib-scripts.ts +8 -0
- package/src/lifecycle.ts +44 -0
- package/src/list.ts +175 -0
- package/src/portal.ts +101 -0
- package/src/prop-types.ts +1165 -0
- package/src/ref.ts +11 -0
- package/src/render-to-dom.ts +325 -0
- package/src/render-to-string.ts +65 -0
- package/src/server-node.ts +98 -0
- package/src/show.ts +46 -0
- package/src/signals.ts +323 -0
- package/src/store.ts +68 -0
- package/src/text.ts +35 -0
- package/src/types.ts +69 -0
- package/src/utils.ts +118 -0
- package/tests/signals.test.ts +403 -0
- package/tsconfig.json +17 -0
- package/vite.config.ts +21 -0
package/src/portal.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { LibBlock } from './block'
|
|
2
|
+
import { createEffect, untrack } from './signals'
|
|
3
|
+
import type { LibContext, PotokElement, WithChildren } from './types'
|
|
4
|
+
import { mergeContext, normalizeChildren } from './utils'
|
|
5
|
+
|
|
6
|
+
type PortalInProps = WithChildren<{
|
|
7
|
+
name: string
|
|
8
|
+
}>
|
|
9
|
+
|
|
10
|
+
class PortalInClass extends LibBlock {
|
|
11
|
+
constructor(
|
|
12
|
+
readonly props: PortalInProps,
|
|
13
|
+
readonly context: LibContext,
|
|
14
|
+
) {
|
|
15
|
+
super()
|
|
16
|
+
|
|
17
|
+
let previousName: string
|
|
18
|
+
|
|
19
|
+
if (context.portals[props.name]) {
|
|
20
|
+
console.warn(`Портал ${props.name} уже существует`)
|
|
21
|
+
} else {
|
|
22
|
+
this.addEffect(
|
|
23
|
+
createEffect(() => {
|
|
24
|
+
const name = props.name
|
|
25
|
+
|
|
26
|
+
if (name !== previousName) {
|
|
27
|
+
untrack(() => {
|
|
28
|
+
delete context.portals[name]
|
|
29
|
+
context.portals[name] = props.children
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
previousName = name
|
|
34
|
+
}),
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override unmount() {
|
|
40
|
+
super.unmount()
|
|
41
|
+
delete this.context.portals[this.props.name]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function PortalIn(props: PortalInProps): PotokElement {
|
|
46
|
+
return function (context: LibContext) {
|
|
47
|
+
return new PortalInClass(props, context)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type PortalOutProps = {
|
|
52
|
+
name: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
class PortalOutClass extends LibBlock {
|
|
56
|
+
constructor(
|
|
57
|
+
readonly props: PortalOutProps,
|
|
58
|
+
readonly context: LibContext,
|
|
59
|
+
) {
|
|
60
|
+
super()
|
|
61
|
+
|
|
62
|
+
let previousChildren: PotokElement[] | null
|
|
63
|
+
|
|
64
|
+
this.addEffect(
|
|
65
|
+
createEffect(() => {
|
|
66
|
+
const name = props.name
|
|
67
|
+
|
|
68
|
+
const children = normalizeChildren(context.portals[name])
|
|
69
|
+
|
|
70
|
+
if (!children) {
|
|
71
|
+
this.unmountChildren()
|
|
72
|
+
|
|
73
|
+
previousChildren = null
|
|
74
|
+
} else if (children !== previousChildren) {
|
|
75
|
+
this.unmountChildren()
|
|
76
|
+
|
|
77
|
+
untrack(() => {
|
|
78
|
+
children.forEach((childCreator, index) => {
|
|
79
|
+
this.children.push(
|
|
80
|
+
childCreator(
|
|
81
|
+
mergeContext(context, {
|
|
82
|
+
parentBlock: this,
|
|
83
|
+
index,
|
|
84
|
+
}),
|
|
85
|
+
),
|
|
86
|
+
)
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
previousChildren = children
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function PortalOut(props: PortalOutProps): PotokElement {
|
|
98
|
+
return function (context: LibContext) {
|
|
99
|
+
return new PortalOutClass(props, context)
|
|
100
|
+
}
|
|
101
|
+
}
|