@lumeland/plugin-jsx 0.0.0-stage → 1.0.0-beta-2
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 +10 -0
- package/LICENSE +21 -0
- package/build/deps/ssx.d.ts +1 -0
- package/build/deps/ssx.js +1 -0
- package/build/src/mod.d.ts +45 -0
- package/build/src/mod.js +57 -0
- package/package.json +28 -3
- package/README.md +0 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/)
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
|
+
|
|
8
|
+
## 1.0.0 - Unreleased
|
|
9
|
+
|
|
10
|
+
First version
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 - Oscar Otero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { renderComponent } from "@lumeland/ssx/jsx-runtime";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { renderComponent } from "@lumeland/ssx/jsx-runtime";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type Site from "@lumeland/core/site.ts";
|
|
2
|
+
import type { Engine, Helper } from "@lumeland/core/renderer.ts";
|
|
3
|
+
export interface Options {
|
|
4
|
+
/** File extensions to load */
|
|
5
|
+
extensions?: string[];
|
|
6
|
+
/** Optional sub-extension for page files */
|
|
7
|
+
pageSubExtension?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Custom includes path
|
|
10
|
+
* @default `site.options.includes`
|
|
11
|
+
*/
|
|
12
|
+
includes?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const defaults: {
|
|
15
|
+
extensions: string[];
|
|
16
|
+
pageSubExtension: string;
|
|
17
|
+
};
|
|
18
|
+
/** Template engine to render JSX files */
|
|
19
|
+
export declare class JsxEngine implements Engine {
|
|
20
|
+
helpers: Record<string, Helper>;
|
|
21
|
+
basePath: string;
|
|
22
|
+
includes: string;
|
|
23
|
+
constructor(basePath: string, includes: string);
|
|
24
|
+
deleteCache(): void;
|
|
25
|
+
render(content: unknown, data?: Record<string, unknown>): Promise<string>;
|
|
26
|
+
addHelper(name: string, fn: Helper): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A plugin to render JSX files to HTML
|
|
30
|
+
* @see https://lume.land/plugins/jsx/
|
|
31
|
+
*/
|
|
32
|
+
export declare function jsx(userOptions?: Options): (site: Site) => void;
|
|
33
|
+
export default jsx;
|
|
34
|
+
/** Extends global data interface */
|
|
35
|
+
declare global {
|
|
36
|
+
namespace Lume {
|
|
37
|
+
interface GlobalData {
|
|
38
|
+
/**
|
|
39
|
+
* The JSX children elements
|
|
40
|
+
* @see https://lume.land/plugins/jsx/
|
|
41
|
+
*/
|
|
42
|
+
children?: JSX.Children;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
package/build/src/mod.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { renderComponent } from "../deps/ssx.js";
|
|
2
|
+
import loader from "@lumeland/core/loaders/module.ts";
|
|
3
|
+
import { merge } from "@lumeland/core/utils/object.ts";
|
|
4
|
+
// Default options
|
|
5
|
+
export const defaults = {
|
|
6
|
+
extensions: [".jsx", ".tsx"],
|
|
7
|
+
pageSubExtension: ".page",
|
|
8
|
+
};
|
|
9
|
+
/** Template engine to render JSX files */
|
|
10
|
+
export class JsxEngine {
|
|
11
|
+
helpers = {};
|
|
12
|
+
basePath;
|
|
13
|
+
includes;
|
|
14
|
+
constructor(basePath, includes) {
|
|
15
|
+
this.basePath = basePath;
|
|
16
|
+
this.includes = includes;
|
|
17
|
+
}
|
|
18
|
+
deleteCache() { }
|
|
19
|
+
async render(content, data = {}) {
|
|
20
|
+
// If content is a string, convert to a JSX element
|
|
21
|
+
if (typeof content === "string") {
|
|
22
|
+
content = { __html: content };
|
|
23
|
+
}
|
|
24
|
+
// Create the children property
|
|
25
|
+
let children = data.content ?? data.children;
|
|
26
|
+
// If the children is a string, convert to a JSX element
|
|
27
|
+
if (typeof children === "string") {
|
|
28
|
+
children = { __html: children };
|
|
29
|
+
}
|
|
30
|
+
const result = typeof content === "function" ? await content({ ...data, children }, this.helpers) : content;
|
|
31
|
+
return typeof result === "string" ? result : renderComponent(result);
|
|
32
|
+
}
|
|
33
|
+
addHelper(name, fn) {
|
|
34
|
+
this.helpers[name] = fn;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A plugin to render JSX files to HTML
|
|
39
|
+
* @see https://lume.land/plugins/jsx/
|
|
40
|
+
*/
|
|
41
|
+
export function jsx(userOptions) {
|
|
42
|
+
return (site) => {
|
|
43
|
+
const options = merge({ ...defaults, includes: site.options.includes }, userOptions);
|
|
44
|
+
const engine = new JsxEngine(site.src("/"), options.includes);
|
|
45
|
+
// Ignore includes folder
|
|
46
|
+
if (options.includes) {
|
|
47
|
+
site.ignore(options.includes);
|
|
48
|
+
}
|
|
49
|
+
// Load the pages and register the engine
|
|
50
|
+
site.loadPages(options.extensions, {
|
|
51
|
+
loader,
|
|
52
|
+
engine,
|
|
53
|
+
pageSubExtension: options.pageSubExtension,
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export default jsx;
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumeland/plugin-jsx",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0-beta-2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"build",
|
|
8
|
+
"CHANGELOG.md"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./build/src/mod.d.ts",
|
|
14
|
+
"import": "./build/src/mod.js"
|
|
15
|
+
},
|
|
16
|
+
"./*.ts": {
|
|
17
|
+
"types": "./build/src/*.d.ts",
|
|
18
|
+
"import": "./build/src/*.js"
|
|
19
|
+
},
|
|
20
|
+
"./*.js": {
|
|
21
|
+
"types": "./build/src/*.d.ts",
|
|
22
|
+
"import": "./build/src/*.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@lumeland/ssx": "^0.1.16"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@lumeland/core": "1.0.0-beta-4"
|
|
30
|
+
}
|
|
6
31
|
}
|
package/README.md
DELETED