@knighted/jsx 1.3.2 → 1.4.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.
package/README.md CHANGED
@@ -20,6 +20,7 @@ A runtime JSX template tag backed by the [`oxc-parser`](https://github.com/oxc-p
20
20
  - [Node / SSR usage](#node--ssr-usage)
21
21
  - [Browser usage](#browser-usage)
22
22
  - [TypeScript plugin](docs/ts-plugin.md)
23
+ - [TypeScript guide](docs/typescript.md)
23
24
  - [Component testing](docs/testing.md)
24
25
  - [CLI setup](docs/cli.md)
25
26
 
@@ -206,6 +207,45 @@ This repository ships a ready-to-run fixture under `test/fixtures/node-ssr` that
206
207
 
207
208
  See how to [integrate with Next.js](./docs/nextjs-integration.md).
208
209
 
210
+ ## TypeScript integration
211
+
212
+ The [`@knighted/jsx-ts-plugin`](docs/ts-plugin.md) keeps DOM (`jsx`) and React (`reactJsx`) templates type-safe with a single config block. The plugin maps each helper to the right mode by default, so you can mix DOM nodes and React components in the same file without juggling multiple plugin entries.
213
+
214
+ ```jsonc
215
+ // tsconfig.json
216
+ {
217
+ "compilerOptions": {
218
+ "plugins": [
219
+ {
220
+ "name": "@knighted/jsx-ts-plugin",
221
+ "tagModes": {
222
+ "jsx": "dom",
223
+ "reactJsx": "react",
224
+ },
225
+ },
226
+ ],
227
+ },
228
+ }
229
+ ```
230
+
231
+ - Choose **TypeScript: Select TypeScript Version → Use Workspace Version** in VS Code so the plugin loads from `node_modules`.
232
+ - Run `tsc --noEmit` (or your build step) to surface the same diagnostics your editor shows.
233
+ - Set `jsxImportSource` to `@knighted/jsx` when compiling `.tsx` helpers. The package publishes the `@knighted/jsx/jsx-runtime` module TypeScript expects. The runtime export exists solely for diagnostics and will throw if you call it at execution time—switch back to tagged templates before shipping code.
234
+ - Drop `/* @jsx-dom */` or `/* @jsx-react */` immediately before a tagged template when you need a one-off override.
235
+ - Import the `JsxRenderable` helper type from `@knighted/jsx` whenever you annotate DOM-facing utilities without the plugin:
236
+
237
+ ```ts
238
+ import type { JsxRenderable } from '@knighted/jsx'
239
+
240
+ const coerceToDom = (value: unknown): JsxRenderable => value ?? ''
241
+ const view = jsx`<section>${coerceToDom(data)}</section>`
242
+ ```
243
+
244
+ > [!TIP]
245
+ > Full `tsconfig` examples (single config or split React + DOM helper projects) live in [docs/typescript.md](docs/typescript.md).
246
+
247
+ Head over to [docs/ts-plugin.md](docs/ts-plugin.md) for deeper guidance, advanced options, and troubleshooting tips.
248
+
209
249
  ## Browser usage
210
250
 
211
251
  When you are not using a bundler, load the module directly from a CDN that understands npm packages:
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Fragment = void 0;
4
+ exports.jsx = jsx;
5
+ exports.jsxs = jsxs;
6
+ exports.jsxDEV = jsxDEV;
7
+ const runtimeModuleId = '@knighted/jsx/jsx-runtime';
8
+ const fragmentSymbolDescription = `${runtimeModuleId}::Fragment`;
9
+ const runtimeNotAvailable = () => {
10
+ throw new Error(`The automatic JSX runtime is only published for TypeScript diagnostics. ` +
11
+ `Render DOM nodes through the jsx tagged template exported by @knighted/jsx instead.`);
12
+ };
13
+ exports.Fragment = Symbol.for(fragmentSymbolDescription);
14
+ function jsx(_, __, ___) {
15
+ return runtimeNotAvailable();
16
+ }
17
+ function jsxs(_, __, ___) {
18
+ return runtimeNotAvailable();
19
+ }
20
+ function jsxDEV(_, __, ___, ____, _____, ______) {
21
+ return runtimeNotAvailable();
22
+ }
@@ -0,0 +1,32 @@
1
+ import type { JsxRenderable } from './jsx.cjs';
2
+ export declare const Fragment: unique symbol;
3
+ export declare function jsx(_: unknown, __?: unknown, ___?: unknown): JsxRenderable;
4
+ export declare function jsxs(_: unknown, __?: unknown, ___?: unknown): JsxRenderable;
5
+ export declare function jsxDEV(_: unknown, __?: unknown, ___?: unknown, ____?: boolean, _____?: unknown, ______?: unknown): JsxRenderable;
6
+ type DataAttributes = {
7
+ [K in `data-${string}`]?: string | number | boolean | null | undefined;
8
+ };
9
+ type AriaAttributes = {
10
+ [K in `aria-${string}`]?: string | number | boolean | null | undefined;
11
+ };
12
+ type EventHandlers<T extends EventTarget> = {
13
+ [K in keyof GlobalEventHandlersEventMap as `on${Capitalize<string & K>}`]?: (event: GlobalEventHandlersEventMap[K]) => void;
14
+ };
15
+ type ElementProps<Tag extends keyof HTMLElementTagNameMap> = Omit<Partial<HTMLElementTagNameMap[Tag]>, 'children'> & EventHandlers<HTMLElementTagNameMap[Tag]> & DataAttributes & AriaAttributes & {
16
+ class?: string;
17
+ className?: string;
18
+ style?: string | Record<string, string | number>;
19
+ ref?: ((value: HTMLElementTagNameMap[Tag]) => void) | {
20
+ current: HTMLElementTagNameMap[Tag] | null;
21
+ };
22
+ children?: JsxRenderable | JsxRenderable[];
23
+ };
24
+ declare global {
25
+ namespace JSX {
26
+ type Element = JsxRenderable;
27
+ type IntrinsicElements = {
28
+ [Tag in keyof HTMLElementTagNameMap]: ElementProps<Tag>;
29
+ };
30
+ }
31
+ }
32
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { JsxRenderable } from './jsx.js';
2
+ export declare const Fragment: unique symbol;
3
+ export declare function jsx(_: unknown, __?: unknown, ___?: unknown): JsxRenderable;
4
+ export declare function jsxs(_: unknown, __?: unknown, ___?: unknown): JsxRenderable;
5
+ export declare function jsxDEV(_: unknown, __?: unknown, ___?: unknown, ____?: boolean, _____?: unknown, ______?: unknown): JsxRenderable;
6
+ type DataAttributes = {
7
+ [K in `data-${string}`]?: string | number | boolean | null | undefined;
8
+ };
9
+ type AriaAttributes = {
10
+ [K in `aria-${string}`]?: string | number | boolean | null | undefined;
11
+ };
12
+ type EventHandlers<T extends EventTarget> = {
13
+ [K in keyof GlobalEventHandlersEventMap as `on${Capitalize<string & K>}`]?: (event: GlobalEventHandlersEventMap[K]) => void;
14
+ };
15
+ type ElementProps<Tag extends keyof HTMLElementTagNameMap> = Omit<Partial<HTMLElementTagNameMap[Tag]>, 'children'> & EventHandlers<HTMLElementTagNameMap[Tag]> & DataAttributes & AriaAttributes & {
16
+ class?: string;
17
+ className?: string;
18
+ style?: string | Record<string, string | number>;
19
+ ref?: ((value: HTMLElementTagNameMap[Tag]) => void) | {
20
+ current: HTMLElementTagNameMap[Tag] | null;
21
+ };
22
+ children?: JsxRenderable | JsxRenderable[];
23
+ };
24
+ declare global {
25
+ namespace JSX {
26
+ type Element = JsxRenderable;
27
+ type IntrinsicElements = {
28
+ [Tag in keyof HTMLElementTagNameMap]: ElementProps<Tag>;
29
+ };
30
+ }
31
+ }
32
+ export {};
@@ -0,0 +1,16 @@
1
+ const runtimeModuleId = '@knighted/jsx/jsx-runtime';
2
+ const fragmentSymbolDescription = `${runtimeModuleId}::Fragment`;
3
+ const runtimeNotAvailable = () => {
4
+ throw new Error(`The automatic JSX runtime is only published for TypeScript diagnostics. ` +
5
+ `Render DOM nodes through the jsx tagged template exported by @knighted/jsx instead.`);
6
+ };
7
+ export const Fragment = Symbol.for(fragmentSymbolDescription);
8
+ export function jsx(_, __, ___) {
9
+ return runtimeNotAvailable();
10
+ }
11
+ export function jsxs(_, __, ___) {
12
+ return runtimeNotAvailable();
13
+ }
14
+ export function jsxDEV(_, __, ___, ____, _____, ______) {
15
+ return runtimeNotAvailable();
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knighted/jsx",
3
- "version": "1.3.2",
3
+ "version": "1.4.1",
4
4
  "description": "Runtime JSX tagged template that renders DOM or React trees anywhere without a build step.",
5
5
  "keywords": [
6
6
  "jsx runtime",
@@ -26,6 +26,16 @@
26
26
  "import": "./dist/index.js",
27
27
  "default": "./dist/index.js"
28
28
  },
29
+ "./jsx-runtime": {
30
+ "types": "./dist/jsx-runtime.d.ts",
31
+ "import": "./dist/jsx-runtime.js",
32
+ "default": "./dist/jsx-runtime.js"
33
+ },
34
+ "./jsx-dev-runtime": {
35
+ "types": "./dist/jsx-runtime.d.ts",
36
+ "import": "./dist/jsx-runtime.js",
37
+ "default": "./dist/jsx-runtime.js"
38
+ },
29
39
  "./lite": {
30
40
  "types": "./dist/index.d.ts",
31
41
  "import": "./dist/lite/index.js",