@kayjs/kay 2.0.0-beta.0 → 2.0.0-beta.3
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/package.json +1 -1
- package/src/attrs.ts +35 -0
- package/src/build/bundle.ts +617 -0
- package/src/build/compile.ts +27 -51
- package/src/build/files.ts +174 -0
- package/src/build/graph.ts +223 -0
- package/src/build/index.ts +272 -1466
- package/src/build/islands.ts +177 -0
- package/src/build/manifest.ts +229 -0
- package/src/build/plugin-host.ts +186 -0
- package/src/build/prerender.ts +102 -0
- package/src/build/report.ts +157 -0
- package/src/build/resolve.ts +51 -0
- package/src/build/routes.ts +163 -0
- package/src/build/server-entry.ts +38 -0
- package/src/build/static.ts +73 -0
- package/src/cli/check.ts +300 -129
- package/src/cli/index.ts +297 -94
- package/src/cli/new.ts +58 -38
- package/src/compiler/analyze.ts +723 -93
- package/src/compiler/dom.ts +848 -762
- package/src/compiler/mistakes.ts +354 -0
- package/src/compiler/patch.ts +1 -1
- package/src/compiler/server-only.ts +172 -23
- package/src/compiler/shared.ts +485 -0
- package/src/compiler/ssr.ts +331 -342
- package/src/context.ts +120 -0
- package/src/dev/index.ts +339 -76
- package/src/dom/action.ts +114 -14
- package/src/dom/extras.ts +121 -83
- package/src/dom/index.ts +122 -80
- package/src/dom/island.ts +71 -36
- package/src/dom/loop.ts +28 -20
- package/src/index.ts +5 -1
- package/src/jsx-runtime.ts +432 -93
- package/src/plugins/config.ts +49 -0
- package/src/plugins/context.ts +61 -0
- package/src/plugins/index.ts +10 -123
- package/src/plugins/load.ts +38 -0
- package/src/plugins/order.ts +107 -0
- package/src/plugins/services.ts +23 -0
- package/src/plugins/types.ts +197 -0
- package/src/reactivity/index.ts +237 -213
- package/src/reactivity/selector.ts +11 -9
- package/src/reactivity/store.ts +36 -11
- package/src/server/action-registry.ts +72 -0
- package/src/server/action.ts +157 -79
- package/src/server/app-entry.ts +23 -0
- package/src/server/assets.ts +182 -0
- package/src/server/compress.ts +197 -104
- package/src/server/cookies.ts +46 -16
- package/src/server/document.ts +192 -0
- package/src/server/env.ts +18 -13
- package/src/server/errors.ts +123 -0
- package/src/server/http.ts +203 -77
- package/src/server/index.ts +420 -973
- package/src/server/loader.ts +113 -0
- package/src/server/page.ts +107 -0
- package/src/server/plugin-host.ts +167 -0
- package/src/server/router.ts +69 -26
- package/src/server/security.ts +90 -59
- package/src/server/standard-schema.ts +42 -11
- package/src/server/static-dir.ts +163 -0
- package/src/server/stream.ts +94 -0
- package/src/ssr/context.ts +95 -10
- package/src/ssr/index.ts +167 -66
- package/src/style.ts +33 -0
- package/src/test/index.ts +24 -18
- package/src/unrenderable.ts +35 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Values whose String() is never what the author meant, shared by the SSR and DOM renderers so both refuse them alike.
|
|
2
|
+
|
|
3
|
+
// A value with its own toString, such as a server action printing its URL, renders as that string on purpose.
|
|
4
|
+
function hasOwnToString(value: object): boolean {
|
|
5
|
+
const { toString } = value
|
|
6
|
+
return typeof toString === 'function' && toString !== Function.prototype.toString && toString !== Object.prototype.toString && toString !== Array.prototype.toString
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function describe(value: unknown, asClass: boolean): [string, string] | undefined {
|
|
10
|
+
if (typeof value === 'function')
|
|
11
|
+
return hasOwnToString(value) ? undefined : ['a function', 'call it, or pass it to an event prop']
|
|
12
|
+
if (typeof value !== 'object' || value === null)
|
|
13
|
+
return undefined
|
|
14
|
+
if (typeof (value as { then?: unknown }).then === 'function')
|
|
15
|
+
return ['a Promise', 'await it in an async component, or make that component the only child of <Suspense>']
|
|
16
|
+
if ('peek' in value && 'value' in value)
|
|
17
|
+
return ['a signal', 'read its .value']
|
|
18
|
+
if ('__html' in value)
|
|
19
|
+
return ['a { __html } object', 'pass the string to innerHTML, or wrap trusted HTML in raw()']
|
|
20
|
+
if (asClass && Array.isArray(value))
|
|
21
|
+
return ['an array', 'join the names into one string']
|
|
22
|
+
if (hasOwnToString(value))
|
|
23
|
+
return undefined
|
|
24
|
+
const proto = Object.getPrototypeOf(value)
|
|
25
|
+
if (proto === Object.prototype || proto === null)
|
|
26
|
+
return ['a plain object', 'render one of its fields']
|
|
27
|
+
return undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Throws when `value` would print as `[object Object]`, `[object Promise]` or a function's source; `place` is `text` or an attribute name. */
|
|
31
|
+
export function assertRenderable(value: unknown, place: string): void {
|
|
32
|
+
const found = describe(value, place === 'class')
|
|
33
|
+
if (found !== undefined)
|
|
34
|
+
throw new TypeError(`kay: cannot render ${found[0]} as ${place === 'text' ? 'text' : `the ${place} attribute`}; ${found[1]}.`)
|
|
35
|
+
}
|