@arcmantle/lit-jsx 1.0.5 → 1.0.7
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 +22 -16
- package/dist/compiler/babel-plugin.d.ts +4 -0
- package/dist/compiler/babel-plugin.d.ts.map +1 -0
- package/dist/compiler/babel-plugin.js +20 -0
- package/dist/compiler/babel-plugin.js.map +1 -0
- package/dist/compiler/babel-traverse.d.ts +3 -0
- package/dist/compiler/babel-traverse.d.ts.map +1 -0
- package/dist/compiler/babel-traverse.js +7 -0
- package/dist/compiler/babel-traverse.js.map +1 -0
- package/dist/compiler/compiler-utils.d.ts +3 -2
- package/dist/compiler/compiler-utils.d.ts.map +1 -1
- package/dist/compiler/compiler-utils.js +25 -23
- package/dist/compiler/compiler-utils.js.map +1 -1
- package/dist/compiler/config.d.ts +5 -1
- package/dist/compiler/config.d.ts.map +1 -1
- package/dist/compiler/config.js +2 -2
- package/dist/compiler/config.js.map +1 -1
- package/dist/compiler/create-logger.d.ts +3 -0
- package/dist/compiler/create-logger.d.ts.map +1 -0
- package/dist/compiler/create-logger.js +32 -0
- package/dist/compiler/create-logger.js.map +1 -0
- package/dist/compiler/import-discovery.d.ts +51 -0
- package/dist/compiler/import-discovery.d.ts.map +1 -0
- package/dist/compiler/import-discovery.js +325 -0
- package/dist/compiler/import-discovery.js.map +1 -0
- package/dist/compiler/preprocess.d.ts +1 -1
- package/dist/compiler/preprocess.d.ts.map +1 -1
- package/dist/compiler/preprocess.js +5 -4
- package/dist/compiler/preprocess.js.map +1 -1
- package/dist/compiler/transpiler.js +4 -4
- package/dist/compiler/transpiler.js.map +1 -1
- package/dist/compiler/vite-plugin.d.ts +1 -0
- package/dist/compiler/vite-plugin.d.ts.map +1 -1
- package/dist/compiler/vite-plugin.js +9 -13
- package/dist/compiler/vite-plugin.js.map +1 -1
- package/dist/runtime/type-helpers.d.ts +24 -36
- package/dist/runtime/type-helpers.d.ts.map +1 -1
- package/dist/runtime/type-helpers.js +22 -34
- package/dist/runtime/type-helpers.js.map +1 -1
- package/package.json +5 -2
- package/src/compiler/babel-plugin.ts +23 -0
- package/src/compiler/babel-traverse.ts +7 -0
- package/src/compiler/compiler-utils.ts +35 -25
- package/src/compiler/config.ts +7 -2
- package/src/compiler/create-logger.ts +35 -0
- package/src/compiler/import-discovery.ts +460 -0
- package/src/compiler/preprocess.ts +9 -7
- package/src/compiler/transpiler.ts +4 -4
- package/src/compiler/vite-plugin.ts +16 -22
- package/src/runtime/type-helpers.ts +24 -36
- package/dist/compiler/babel-preset.d.ts +0 -6
- package/dist/compiler/babel-preset.d.ts.map +0 -1
- package/dist/compiler/babel-preset.js +0 -27
- package/dist/compiler/babel-preset.js.map +0 -1
- package/src/compiler/babel-preset.ts +0 -34
|
@@ -1,32 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates a
|
|
2
|
+
* Creates a component that can be used directly in JSX syntax.
|
|
3
3
|
* Also registers the custom element if it hasn't been registered yet.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```tsx
|
|
7
|
-
* import {
|
|
7
|
+
* import { toComponent } from 'jsx-lit';
|
|
8
8
|
*
|
|
9
9
|
* export class MyButton extends LitElement {
|
|
10
10
|
* static tagName = 'my-button';
|
|
11
|
-
* static tag = toJSX(MyButton);
|
|
12
|
-
*
|
|
13
|
-
* render() {
|
|
14
|
-
* return html`<button><slot></slot></button>`;
|
|
15
|
-
* }
|
|
16
11
|
* }
|
|
17
12
|
*
|
|
18
|
-
*
|
|
13
|
+
* const MyButtonComponent = toComponent(MyButton);
|
|
14
|
+
*
|
|
15
|
+
* // Usage in JSX - compiler automatically detects this as a custom element
|
|
19
16
|
* const jsx = (
|
|
20
|
-
* <
|
|
17
|
+
* <MyButtonComponent
|
|
21
18
|
* class="my-button"
|
|
22
19
|
* on-click={() => { console.log('Clicked!'); }}
|
|
23
20
|
* />
|
|
24
21
|
* );
|
|
25
22
|
* ```
|
|
26
23
|
*/
|
|
27
|
-
export const
|
|
24
|
+
export const toComponent = <T extends { new(...args: any): any; tagName: string; }>(
|
|
28
25
|
element: T,
|
|
29
|
-
):
|
|
26
|
+
): ToComponent<InstanceType<T>> => {
|
|
30
27
|
if (!element.tagName)
|
|
31
28
|
throw new Error('Element must have a static tagName property');
|
|
32
29
|
|
|
@@ -40,57 +37,48 @@ export const toJSX = <T extends { new(...args: any): any; tagName: string; }>(
|
|
|
40
37
|
return element.tagName as any;
|
|
41
38
|
};
|
|
42
39
|
|
|
43
|
-
export type
|
|
40
|
+
export type ToComponent<T extends object> = (props: JSX.JSXProps<T>) => string;
|
|
44
41
|
|
|
45
42
|
|
|
46
43
|
/**
|
|
47
|
-
* Creates a dynamic tag
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* **IMPORTANT**: Dynamic tag names must use the `.tag` property pattern to be properly
|
|
51
|
-
* compiled to lit-html static templates. Without this pattern, jsx-lit cannot detect
|
|
52
|
-
* and transform the dynamic tag name into efficient static template literals.
|
|
44
|
+
* Creates a dynamic tag that can be used directly in JSX syntax.
|
|
45
|
+
* The compiler automatically detects when this helper is used and compiles
|
|
46
|
+
* it to efficient static lit-html templates.
|
|
53
47
|
*
|
|
54
48
|
* @example
|
|
55
49
|
* ```tsx
|
|
56
50
|
* import { toTag } from 'jsx-lit';
|
|
57
51
|
*
|
|
58
|
-
* //
|
|
52
|
+
* // Creates a dynamic tag that the compiler will recognize
|
|
59
53
|
* const DynamicDiv = toTag('div');
|
|
60
54
|
* const DynamicCustomElement = toTag('my-custom-element');
|
|
61
55
|
*
|
|
62
|
-
* // Usage in JSX
|
|
56
|
+
* // Usage in JSX - compiler automatically handles the transformation
|
|
63
57
|
* function renderConditional({ useDiv }) {
|
|
64
58
|
* const Tag = toTag(useDiv ? 'div' : 'span');
|
|
65
|
-
* return <Tag
|
|
59
|
+
* return <Tag class="dynamic">Content</Tag>;
|
|
66
60
|
* }
|
|
67
61
|
*
|
|
68
|
-
* // Compiles to efficient static templates:
|
|
62
|
+
* // Compiles to efficient static templates automatically:
|
|
69
63
|
* // const Tag = toTag(useDiv ? 'div' : 'span');
|
|
70
|
-
* // const __$Tag = __$literalMap.get(Tag
|
|
64
|
+
* // const __$Tag = __$literalMap.get(Tag);
|
|
71
65
|
* // htmlStatic`<${__$Tag} class="dynamic">Content</${__$Tag}>`
|
|
72
66
|
* ```
|
|
73
67
|
*
|
|
74
68
|
* @example
|
|
75
69
|
* ```tsx
|
|
76
|
-
* // ❌
|
|
77
|
-
* const
|
|
78
|
-
* return <
|
|
70
|
+
* // ❌ Without toTag helper - won't compile to static templates
|
|
71
|
+
* const BadTag = 'div';
|
|
72
|
+
* return <BadTag>Content</BadTag>; // This won't work with jsx-lit
|
|
79
73
|
*
|
|
80
|
-
* //
|
|
81
|
-
* const BadTag = toTag('div');
|
|
82
|
-
* return <BadTag>Content</BadTag>; // Won't compile correctly
|
|
83
|
-
*
|
|
84
|
-
* // ✅ Correct usage - with .tag property
|
|
74
|
+
* // ✅ With toTag helper - compiler automatically optimizes
|
|
85
75
|
* const GoodTag = toTag('div');
|
|
86
|
-
* return <GoodTag
|
|
76
|
+
* return <GoodTag>Content</GoodTag>; // Compiles to static templates
|
|
87
77
|
* ```
|
|
88
78
|
*
|
|
89
79
|
* @param tag - The HTML tag name (standard HTML elements or custom element names)
|
|
90
|
-
* @returns
|
|
80
|
+
* @returns A tag identifier that the compiler recognizes for optimization
|
|
91
81
|
*/
|
|
92
82
|
export const toTag = <T extends keyof HTMLElementTagNameMap | (string & {})>(
|
|
93
83
|
tag: T,
|
|
94
|
-
):
|
|
95
|
-
return { tag } as any;
|
|
96
|
-
};
|
|
84
|
+
): T => tag;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { PluginObj, PluginOptions } from '@babel/core';
|
|
2
|
-
/** Compiles jsx to a combination of standard and compiled lit-html */
|
|
3
|
-
export declare const litJsxBabelPreset: (context: any, options?: {}) => {
|
|
4
|
-
plugins: [PluginObj, PluginOptions][];
|
|
5
|
-
};
|
|
6
|
-
//# sourceMappingURL=babel-preset.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"babel-preset.d.ts","sourceRoot":"","sources":["../../src/compiler/babel-preset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAQ5D,sEAAsE;AACtE,eAAO,MAAM,iBAAiB,GAC7B,SAAS,GAAG,EACZ,YAAY,KACV;IAAE,OAAO,EAAE,CAAC,SAAS,EAAE,aAAa,CAAC,EAAE,CAAC;CAqB1C,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import SyntaxJSX from '@babel/plugin-syntax-jsx';
|
|
2
|
-
import { postprocess } from './postprocess.js';
|
|
3
|
-
import { preprocess } from './preprocess.js';
|
|
4
|
-
import { transformJSXElement } from './transform-jsx.js';
|
|
5
|
-
/** Compiles jsx to a combination of standard and compiled lit-html */
|
|
6
|
-
export const litJsxBabelPreset = (context, options = {}) => {
|
|
7
|
-
return {
|
|
8
|
-
plugins: [
|
|
9
|
-
[
|
|
10
|
-
{
|
|
11
|
-
name: 'lit-jsx-transform',
|
|
12
|
-
inherits: SyntaxJSX.default,
|
|
13
|
-
visitor: {
|
|
14
|
-
JSXElement: transformJSXElement,
|
|
15
|
-
JSXFragment: transformJSXElement,
|
|
16
|
-
Program: {
|
|
17
|
-
enter: preprocess,
|
|
18
|
-
exit: postprocess,
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
Object.assign({}, options),
|
|
23
|
-
],
|
|
24
|
-
],
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=babel-preset.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"babel-preset.js","sourceRoot":"","sources":["../../src/compiler/babel-preset.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,0BAA0B,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzD,sEAAsE;AACtE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAChC,OAAY,EACZ,OAAO,GAAG,EAAE,EACiC,EAAE;IAC/C,OAAO;QACN,OAAO,EAAE;YACR;gBACC;oBACC,IAAI,EAAM,mBAAmB;oBAC7B,QAAQ,EAAE,SAAS,CAAC,OAAO;oBAC3B,OAAO,EAAG;wBACT,UAAU,EAAG,mBAAmB;wBAChC,WAAW,EAAE,mBAAmB;wBAChC,OAAO,EAAM;4BACZ,KAAK,EAAE,UAAU;4BACjB,IAAI,EAAG,WAAW;yBAClB;qBACD;iBACD;gBACD,MAAM,CAAC,MAAM,CAAC,EACb,EAAE,OAAO,CAAC;aACX;SACD;KACD,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { PluginObj, PluginOptions } from '@babel/core';
|
|
2
|
-
import SyntaxJSX from '@babel/plugin-syntax-jsx';
|
|
3
|
-
|
|
4
|
-
import { postprocess } from './postprocess.js';
|
|
5
|
-
import { preprocess } from './preprocess.js';
|
|
6
|
-
import { transformJSXElement } from './transform-jsx.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/** Compiles jsx to a combination of standard and compiled lit-html */
|
|
10
|
-
export const litJsxBabelPreset = (
|
|
11
|
-
context: any,
|
|
12
|
-
options = {},
|
|
13
|
-
): { plugins: [PluginObj, PluginOptions][]; } => {
|
|
14
|
-
return {
|
|
15
|
-
plugins: [
|
|
16
|
-
[
|
|
17
|
-
{
|
|
18
|
-
name: 'lit-jsx-transform',
|
|
19
|
-
inherits: SyntaxJSX.default,
|
|
20
|
-
visitor: {
|
|
21
|
-
JSXElement: transformJSXElement,
|
|
22
|
-
JSXFragment: transformJSXElement,
|
|
23
|
-
Program: {
|
|
24
|
-
enter: preprocess,
|
|
25
|
-
exit: postprocess,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
Object.assign({
|
|
30
|
-
}, options),
|
|
31
|
-
],
|
|
32
|
-
],
|
|
33
|
-
};
|
|
34
|
-
};
|