@lumeland/plugin-jsx 0.0.0-stage → 1.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/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
+ }
@@ -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,33 @@
1
1
  {
2
2
  "name": "@lumeland/plugin-jsx",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-beta-3",
4
+ "description": "",
5
+ "homepage": "https://lume.land/plugins/jsx/",
6
+ "license": "MIT",
7
+ "author": "Óscar Otero",
8
+ "files": [
9
+ "build",
10
+ "CHANGELOG.md"
11
+ ],
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./build/src/mod.d.ts",
16
+ "import": "./build/src/mod.js"
17
+ },
18
+ "./*.ts": {
19
+ "types": "./build/src/*.d.ts",
20
+ "import": "./build/src/*.js"
21
+ },
22
+ "./*.js": {
23
+ "types": "./build/src/*.d.ts",
24
+ "import": "./build/src/*.js"
25
+ }
26
+ },
27
+ "dependencies": {
28
+ "@lumeland/ssx": "^0.1.16"
29
+ },
30
+ "peerDependencies": {
31
+ "@lumeland/core": "1.0.0-beta-5"
32
+ }
6
33
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.