@evobug_com/safe-ts-vue 0.2.0 → 0.3.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/dist/inject.d.ts +2 -2
- package/dist/inject.js +2 -2
- package/dist/jsx-dev-runtime.d.ts +1 -0
- package/dist/jsx-dev-runtime.js +2 -0
- package/dist/jsx-runtime.d.ts +11 -0
- package/dist/jsx-runtime.js +43 -0
- package/dist/match.d.ts +3 -0
- package/dist/match.js +3 -0
- package/package.json +10 -2
package/dist/inject.d.ts
CHANGED
|
@@ -41,9 +41,9 @@ export declare class MissingInjectionError extends Error {
|
|
|
41
41
|
* returns the render function.
|
|
42
42
|
*
|
|
43
43
|
* ```ts
|
|
44
|
-
* export const
|
|
44
|
+
* export const CartBadge = defineComponent({
|
|
45
45
|
* setup() {
|
|
46
|
-
* return withInjection(
|
|
46
|
+
* return withInjection(CartKey, (cart) => () => h("p", `${cart.count.value} items`));
|
|
47
47
|
* },
|
|
48
48
|
* });
|
|
49
49
|
* ```
|
package/dist/inject.js
CHANGED
|
@@ -41,9 +41,9 @@ export class MissingInjectionError extends Error {
|
|
|
41
41
|
* returns the render function.
|
|
42
42
|
*
|
|
43
43
|
* ```ts
|
|
44
|
-
* export const
|
|
44
|
+
* export const CartBadge = defineComponent({
|
|
45
45
|
* setup() {
|
|
46
|
-
* return withInjection(
|
|
46
|
+
* return withInjection(CartKey, (cart) => () => h("p", `${cart.count.value} items`));
|
|
47
47
|
* },
|
|
48
48
|
* });
|
|
49
49
|
* ```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Fragment, type JSX, jsx, jsxDEV, jsxs } from "./jsx-runtime.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Fragment, type VNode, type VNodeTypes } from "vue";
|
|
2
|
+
export { Fragment };
|
|
3
|
+
/** The JSX namespace TypeScript checks the elements against: Vue's own. */
|
|
4
|
+
export type { JSX } from "vue/jsx-runtime";
|
|
5
|
+
/** What JSX hands the runtime: the attributes, and the children under `children`. */
|
|
6
|
+
export type JsxProps = Readonly<Record<string, unknown>> & {
|
|
7
|
+
readonly children?: unknown;
|
|
8
|
+
};
|
|
9
|
+
/** The vnode of one JSX element (`key` is the `key` attribute, which JSX passes apart). */
|
|
10
|
+
export declare function jsx(type: VNodeTypes, props: JsxProps | undefined, key?: PropertyKey): VNode;
|
|
11
|
+
export { jsx as jsxs, jsx as jsxDEV };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// @safe-ts std: one call into Vue's untyped vnode factory, for JSX of any element or component.
|
|
2
|
+
// A JSX runtime for Vue TSX: `"jsxImportSource": "@evobug_com/safe-ts-vue"` in tsconfig.json (and
|
|
3
|
+
// in the bundler's JSX options) compiles `<Panel title="Cart">…</Panel>` to calls of `jsx` here.
|
|
4
|
+
//
|
|
5
|
+
// Vue's own `vue/jsx-runtime` is its `h`, which hands a component its JSX children as a plain
|
|
6
|
+
// array: Vue then turns them into a default slot on every render and, in development, warns each
|
|
7
|
+
// time ("Non-function value encountered for default slot"). Here the children of a component
|
|
8
|
+
// become a default slot function, as Vue's Babel JSX plugin does at compile time. Elements,
|
|
9
|
+
// fragments and `Teleport` keep their children as they are, and an explicit slot object
|
|
10
|
+
// (`{{ default: () => …, actions: () => … }}`) or a slot function passes through.
|
|
11
|
+
import { createVNode, Fragment, isVNode, setBlockTracking } from "vue";
|
|
12
|
+
export { Fragment };
|
|
13
|
+
function isComponent(type) {
|
|
14
|
+
if (typeof type === "function")
|
|
15
|
+
return true;
|
|
16
|
+
return typeof type === "object" && type !== null && !("__isTeleport" in type && Boolean(type.__isTeleport));
|
|
17
|
+
}
|
|
18
|
+
function isSlotObject(children) {
|
|
19
|
+
return typeof children === "object" && children !== null && !Array.isArray(children) && !isVNode(children);
|
|
20
|
+
}
|
|
21
|
+
/** What `h(type, props, children)` does with a props object, without its per-kind overloads. */
|
|
22
|
+
function vnode(type, props, children) {
|
|
23
|
+
setBlockTracking(-1);
|
|
24
|
+
try {
|
|
25
|
+
return createVNode(type, props, isVNode(children) ? [children] : children);
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
setBlockTracking(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** The vnode of one JSX element (`key` is the `key` attribute, which JSX passes apart). */
|
|
32
|
+
export function jsx(type, props, key) {
|
|
33
|
+
const { children, ...rest } = { ...props };
|
|
34
|
+
if (key !== undefined)
|
|
35
|
+
rest["key"] = key;
|
|
36
|
+
if (children === undefined)
|
|
37
|
+
return vnode(type, rest, undefined);
|
|
38
|
+
if (isComponent(type) && typeof children !== "function" && !isSlotObject(children)) {
|
|
39
|
+
return vnode(type, rest, { default: () => children });
|
|
40
|
+
}
|
|
41
|
+
return vnode(type, rest, children);
|
|
42
|
+
}
|
|
43
|
+
export { jsx as jsxs, jsx as jsxDEV };
|
package/dist/match.d.ts
CHANGED
|
@@ -31,6 +31,9 @@ export type MatchSlots<E extends Tagged> = {
|
|
|
31
31
|
* transform can't rewrite (`:on="find(id)"`, slot props with defaults), and tests or tools that
|
|
32
32
|
* run without it.
|
|
33
33
|
*
|
|
34
|
+
* The value can't be missing: unlike `match(...)`, there is no `#undefined` slot. Put `<Match>`
|
|
35
|
+
* under `v-if="value"`, with `v-else` for the missing case.
|
|
36
|
+
*
|
|
34
37
|
* Pass the value, not a Ref: the template unwraps refs only at the top level, so a task's state
|
|
35
38
|
* is `:on="task.state.value"` (or destructure it: `const { state } = useTask(...)`).
|
|
36
39
|
*/
|
package/dist/match.js
CHANGED
|
@@ -19,6 +19,9 @@ import { defineComponent } from "vue";
|
|
|
19
19
|
* transform can't rewrite (`:on="find(id)"`, slot props with defaults), and tests or tools that
|
|
20
20
|
* run without it.
|
|
21
21
|
*
|
|
22
|
+
* The value can't be missing: unlike `match(...)`, there is no `#undefined` slot. Put `<Match>`
|
|
23
|
+
* under `v-if="value"`, with `v-else` for the missing case.
|
|
24
|
+
*
|
|
22
25
|
* Pass the value, not a Ref: the template unwraps refs only at the top level, so a task's state
|
|
23
26
|
* is `:on="task.state.value"` (or destructure it: `const { state } = useTask(...)`).
|
|
24
27
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evobug_com/safe-ts-vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "SAFE-TS helpers for Vue 3.5+: <Match> for enum values in templates, async tasks without races, template refs typed by where the element is, listeners and intervals tied to the component, typed props without casts, required injections, safe URLs for :href.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"safe-ts",
|
|
@@ -59,6 +59,14 @@
|
|
|
59
59
|
"./url": {
|
|
60
60
|
"types": "./dist/url.d.ts",
|
|
61
61
|
"default": "./dist/url.js"
|
|
62
|
+
},
|
|
63
|
+
"./jsx-runtime": {
|
|
64
|
+
"types": "./dist/jsx-runtime.d.ts",
|
|
65
|
+
"default": "./dist/jsx-runtime.js"
|
|
66
|
+
},
|
|
67
|
+
"./jsx-dev-runtime": {
|
|
68
|
+
"types": "./dist/jsx-dev-runtime.d.ts",
|
|
69
|
+
"default": "./dist/jsx-dev-runtime.js"
|
|
62
70
|
}
|
|
63
71
|
},
|
|
64
72
|
"files": [
|
|
@@ -67,7 +75,7 @@
|
|
|
67
75
|
"LICENSE-APACHE"
|
|
68
76
|
],
|
|
69
77
|
"peerDependencies": {
|
|
70
|
-
"@evobug_com/safe-ts-std": "^0.
|
|
78
|
+
"@evobug_com/safe-ts-std": "^0.3.0",
|
|
71
79
|
"vue": "^3.5.0"
|
|
72
80
|
},
|
|
73
81
|
"publishConfig": {
|