react-layout-sdk 1.0.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.
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+
3
+ interface ComponentFactoryProps {
4
+ componentName: string;
5
+ props: any;
6
+ placeholderName?: string;
7
+ customProps?: any;
8
+ componentMap: Record<string, React.ComponentType<any>>;
9
+ }
10
+ declare const ComponentFactory: React.FC<ComponentFactoryProps>;
11
+ interface PlaceholderProps {
12
+ name: string;
13
+ rendering: any[];
14
+ customProps?: any;
15
+ componentMap: Record<string, React.ComponentType<any>>;
16
+ }
17
+ declare const Placeholder: React.FC<PlaceholderProps>;
18
+
19
+ interface VeloxPlaceholderData {
20
+ __component: string;
21
+ [key: string]: any;
22
+ }
23
+ interface VeloxRoute {
24
+ name: string;
25
+ displayName: string;
26
+ placeholders: Record<string, VeloxPlaceholderData[]>;
27
+ }
28
+ interface VeloxContext {
29
+ pageEditing: boolean;
30
+ site: Record<string, any>;
31
+ language: string;
32
+ locales: any[];
33
+ }
34
+ interface VeloxLayoutResponse {
35
+ strapi: {
36
+ context: VeloxContext;
37
+ route: VeloxRoute;
38
+ };
39
+ }
40
+ declare const fetchVeloxLayout: (apiUrl: string, slug: string, locale?: string, options?: RequestInit) => Promise<VeloxLayoutResponse | null>;
41
+
42
+ export { ComponentFactory, type ComponentFactoryProps, Placeholder, type PlaceholderProps, type VeloxContext, type VeloxLayoutResponse, type VeloxPlaceholderData, type VeloxRoute, fetchVeloxLayout };
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+
3
+ interface ComponentFactoryProps {
4
+ componentName: string;
5
+ props: any;
6
+ placeholderName?: string;
7
+ customProps?: any;
8
+ componentMap: Record<string, React.ComponentType<any>>;
9
+ }
10
+ declare const ComponentFactory: React.FC<ComponentFactoryProps>;
11
+ interface PlaceholderProps {
12
+ name: string;
13
+ rendering: any[];
14
+ customProps?: any;
15
+ componentMap: Record<string, React.ComponentType<any>>;
16
+ }
17
+ declare const Placeholder: React.FC<PlaceholderProps>;
18
+
19
+ interface VeloxPlaceholderData {
20
+ __component: string;
21
+ [key: string]: any;
22
+ }
23
+ interface VeloxRoute {
24
+ name: string;
25
+ displayName: string;
26
+ placeholders: Record<string, VeloxPlaceholderData[]>;
27
+ }
28
+ interface VeloxContext {
29
+ pageEditing: boolean;
30
+ site: Record<string, any>;
31
+ language: string;
32
+ locales: any[];
33
+ }
34
+ interface VeloxLayoutResponse {
35
+ strapi: {
36
+ context: VeloxContext;
37
+ route: VeloxRoute;
38
+ };
39
+ }
40
+ declare const fetchVeloxLayout: (apiUrl: string, slug: string, locale?: string, options?: RequestInit) => Promise<VeloxLayoutResponse | null>;
41
+
42
+ export { ComponentFactory, type ComponentFactoryProps, Placeholder, type PlaceholderProps, type VeloxContext, type VeloxLayoutResponse, type VeloxPlaceholderData, type VeloxRoute, fetchVeloxLayout };
package/dist/index.js ADDED
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ ComponentFactory: () => ComponentFactory,
34
+ Placeholder: () => Placeholder,
35
+ fetchVeloxLayout: () => fetchVeloxLayout
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/Placeholder.tsx
40
+ var import_react = __toESM(require("react"));
41
+ var ComponentFactory = ({
42
+ componentName,
43
+ props,
44
+ placeholderName,
45
+ customProps,
46
+ componentMap
47
+ }) => {
48
+ const Component = componentMap[componentName];
49
+ if (!Component) {
50
+ console.warn(`[Velox SDK] Component not found for: ${componentName}`);
51
+ return /* @__PURE__ */ import_react.default.createElement("div", { style: {
52
+ padding: "2rem",
53
+ margin: "1rem",
54
+ border: "2px dashed #eab308",
55
+ backgroundColor: "#fef9c3",
56
+ color: "#713f12",
57
+ borderRadius: "0.75rem",
58
+ display: "flex",
59
+ flexDirection: "column",
60
+ alignItems: "center",
61
+ justifyContent: "center",
62
+ fontFamily: "sans-serif"
63
+ } }, /* @__PURE__ */ import_react.default.createElement("strong", { style: { fontSize: "1.25rem", color: "#ca8a04", marginBottom: "0.5rem" } }, "\u26A0\uFE0F Warning"), /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: "1.125rem" } }, "Component not implemented:", /* @__PURE__ */ import_react.default.createElement("code", { style: {
64
+ backgroundColor: "#f3f4f6",
65
+ padding: "0.25rem 0.5rem",
66
+ borderRadius: "0.25rem",
67
+ marginLeft: "0.5rem",
68
+ color: "#1f2937",
69
+ border: "1px solid #d1d5db"
70
+ } }, componentName)));
71
+ }
72
+ return /* @__PURE__ */ import_react.default.createElement(Component, { styles: props.styles, placeholderName, ...props, ...customProps });
73
+ };
74
+ var Placeholder = ({ name, rendering, customProps, componentMap }) => {
75
+ if (!rendering || !Array.isArray(rendering) || rendering.length === 0) return null;
76
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, rendering.map((component, index) => /* @__PURE__ */ import_react.default.createElement(
77
+ ComponentFactory,
78
+ {
79
+ key: `${component.__component}-${index}`,
80
+ componentName: component.__component,
81
+ props: component,
82
+ customProps,
83
+ placeholderName: name,
84
+ componentMap
85
+ }
86
+ )));
87
+ };
88
+
89
+ // src/index.ts
90
+ var fetchVeloxLayout = async (apiUrl, slug, locale = "en", options) => {
91
+ try {
92
+ const querySymbol = slug.includes("?") ? "&" : "?";
93
+ const res = await fetch(`${apiUrl}/api/layout/${slug}${querySymbol}locale=${locale}`, {
94
+ ...options
95
+ });
96
+ if (!res.ok) {
97
+ console.error(`[Velox SDK] Failed to fetch layout: ${res.statusText}`);
98
+ return null;
99
+ }
100
+ return await res.json();
101
+ } catch (error) {
102
+ console.error(`[Velox SDK] Network error fetching layout`, error);
103
+ return null;
104
+ }
105
+ };
106
+ // Annotate the CommonJS export names for ESM import in node:
107
+ 0 && (module.exports = {
108
+ ComponentFactory,
109
+ Placeholder,
110
+ fetchVeloxLayout
111
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,72 @@
1
+ // src/Placeholder.tsx
2
+ import React from "react";
3
+ var ComponentFactory = ({
4
+ componentName,
5
+ props,
6
+ placeholderName,
7
+ customProps,
8
+ componentMap
9
+ }) => {
10
+ const Component = componentMap[componentName];
11
+ if (!Component) {
12
+ console.warn(`[Velox SDK] Component not found for: ${componentName}`);
13
+ return /* @__PURE__ */ React.createElement("div", { style: {
14
+ padding: "2rem",
15
+ margin: "1rem",
16
+ border: "2px dashed #eab308",
17
+ backgroundColor: "#fef9c3",
18
+ color: "#713f12",
19
+ borderRadius: "0.75rem",
20
+ display: "flex",
21
+ flexDirection: "column",
22
+ alignItems: "center",
23
+ justifyContent: "center",
24
+ fontFamily: "sans-serif"
25
+ } }, /* @__PURE__ */ React.createElement("strong", { style: { fontSize: "1.25rem", color: "#ca8a04", marginBottom: "0.5rem" } }, "\u26A0\uFE0F Warning"), /* @__PURE__ */ React.createElement("div", { style: { fontSize: "1.125rem" } }, "Component not implemented:", /* @__PURE__ */ React.createElement("code", { style: {
26
+ backgroundColor: "#f3f4f6",
27
+ padding: "0.25rem 0.5rem",
28
+ borderRadius: "0.25rem",
29
+ marginLeft: "0.5rem",
30
+ color: "#1f2937",
31
+ border: "1px solid #d1d5db"
32
+ } }, componentName)));
33
+ }
34
+ return /* @__PURE__ */ React.createElement(Component, { styles: props.styles, placeholderName, ...props, ...customProps });
35
+ };
36
+ var Placeholder = ({ name, rendering, customProps, componentMap }) => {
37
+ if (!rendering || !Array.isArray(rendering) || rendering.length === 0) return null;
38
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, rendering.map((component, index) => /* @__PURE__ */ React.createElement(
39
+ ComponentFactory,
40
+ {
41
+ key: `${component.__component}-${index}`,
42
+ componentName: component.__component,
43
+ props: component,
44
+ customProps,
45
+ placeholderName: name,
46
+ componentMap
47
+ }
48
+ )));
49
+ };
50
+
51
+ // src/index.ts
52
+ var fetchVeloxLayout = async (apiUrl, slug, locale = "en", options) => {
53
+ try {
54
+ const querySymbol = slug.includes("?") ? "&" : "?";
55
+ const res = await fetch(`${apiUrl}/api/layout/${slug}${querySymbol}locale=${locale}`, {
56
+ ...options
57
+ });
58
+ if (!res.ok) {
59
+ console.error(`[Velox SDK] Failed to fetch layout: ${res.statusText}`);
60
+ return null;
61
+ }
62
+ return await res.json();
63
+ } catch (error) {
64
+ console.error(`[Velox SDK] Network error fetching layout`, error);
65
+ return null;
66
+ }
67
+ };
68
+ export {
69
+ ComponentFactory,
70
+ Placeholder,
71
+ fetchVeloxLayout
72
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "react-layout-sdk",
3
+ "version": "1.0.0",
4
+ "description": "React components for Velox SDK (Sitecore-like routing)",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "peerDependencies": {
9
+ "react": ">=18.0.0",
10
+ "react-dom": ">=18.0.0"
11
+ },
12
+ "devDependencies": {
13
+ "typescript": "^5.0.0",
14
+ "tsup": "^8.0.0",
15
+ "@types/react": "^18.0.0",
16
+ "@types/react-dom": "^18.0.0"
17
+ },
18
+ "scripts": {
19
+ "build": "tsup src/index.ts --format cjs,esm --dts",
20
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch"
21
+ }
22
+ }
@@ -0,0 +1,81 @@
1
+ import React from 'react';
2
+
3
+ export interface ComponentFactoryProps {
4
+ componentName: string;
5
+ props: any;
6
+ placeholderName?: string;
7
+ customProps?: any;
8
+ componentMap: Record<string, React.ComponentType<any>>;
9
+ }
10
+
11
+ export const ComponentFactory: React.FC<ComponentFactoryProps> = ({
12
+ componentName,
13
+ props,
14
+ placeholderName,
15
+ customProps,
16
+ componentMap
17
+ }) => {
18
+ const Component = componentMap[componentName];
19
+
20
+ if (!Component) {
21
+ console.warn(`[Velox SDK] Component not found for: ${componentName}`);
22
+ return (
23
+ <div style={{
24
+ padding: '2rem',
25
+ margin: '1rem',
26
+ border: '2px dashed #eab308',
27
+ backgroundColor: '#fef9c3',
28
+ color: '#713f12',
29
+ borderRadius: '0.75rem',
30
+ display: 'flex',
31
+ flexDirection: 'column',
32
+ alignItems: 'center',
33
+ justifyContent: 'center',
34
+ fontFamily: 'sans-serif'
35
+ }}>
36
+ <strong style={{ fontSize: '1.25rem', color: '#ca8a04', marginBottom: '0.5rem' }}>⚠️ Warning</strong>
37
+ <div style={{ fontSize: '1.125rem' }}>
38
+ Component not implemented:
39
+ <code style={{
40
+ backgroundColor: '#f3f4f6',
41
+ padding: '0.25rem 0.5rem',
42
+ borderRadius: '0.25rem',
43
+ marginLeft: '0.5rem',
44
+ color: '#1f2937',
45
+ border: '1px solid #d1d5db'
46
+ }}>
47
+ {componentName}
48
+ </code>
49
+ </div>
50
+ </div>
51
+ );
52
+ }
53
+
54
+ return <Component styles={props.styles} placeholderName={placeholderName} {...props} {...customProps} />;
55
+ };
56
+
57
+ export interface PlaceholderProps {
58
+ name: string;
59
+ rendering: any[];
60
+ customProps?: any;
61
+ componentMap: Record<string, React.ComponentType<any>>;
62
+ }
63
+
64
+ export const Placeholder: React.FC<PlaceholderProps> = ({ name, rendering, customProps, componentMap }) => {
65
+ if(!rendering || !Array.isArray(rendering) || rendering.length === 0) return null;
66
+
67
+ return (
68
+ <React.Fragment>
69
+ {rendering.map((component, index) => (
70
+ <ComponentFactory
71
+ key={`${component.__component}-${index}`}
72
+ componentName={component.__component}
73
+ props={component}
74
+ customProps={customProps}
75
+ placeholderName={name}
76
+ componentMap={componentMap}
77
+ />
78
+ ))}
79
+ </React.Fragment>
80
+ );
81
+ }
package/src/index.ts ADDED
@@ -0,0 +1,53 @@
1
+ export { Placeholder, ComponentFactory } from './Placeholder';
2
+ export type { PlaceholderProps, ComponentFactoryProps } from './Placeholder';
3
+
4
+ // Useful type definitions for the API response
5
+ export interface VeloxPlaceholderData {
6
+ __component: string;
7
+ [key: string]: any;
8
+ }
9
+
10
+ export interface VeloxRoute {
11
+ name: string;
12
+ displayName: string;
13
+ placeholders: Record<string, VeloxPlaceholderData[]>;
14
+ }
15
+
16
+ export interface VeloxContext {
17
+ pageEditing: boolean;
18
+ site: Record<string, any>;
19
+ language: string;
20
+ locales: any[];
21
+ }
22
+
23
+ export interface VeloxLayoutResponse {
24
+ strapi: {
25
+ context: VeloxContext;
26
+ route: VeloxRoute;
27
+ }
28
+ }
29
+
30
+ // Hook / Utility function to fetch layout
31
+ export const fetchVeloxLayout = async (
32
+ apiUrl: string,
33
+ slug: string,
34
+ locale: string = 'en',
35
+ options?: RequestInit
36
+ ): Promise<VeloxLayoutResponse | null> => {
37
+ try {
38
+ const querySymbol = slug.includes('?') ? '&' : '?';
39
+ const res = await fetch(`${apiUrl}/api/layout/${slug}${querySymbol}locale=${locale}`, {
40
+ ...options,
41
+ });
42
+
43
+ if (!res.ok) {
44
+ console.error(`[Velox SDK] Failed to fetch layout: ${res.statusText}`);
45
+ return null;
46
+ }
47
+
48
+ return await res.json() as VeloxLayoutResponse;
49
+ } catch (error) {
50
+ console.error(`[Velox SDK] Network error fetching layout`, error);
51
+ return null;
52
+ }
53
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2022",
4
+ "module": "esnext",
5
+ "lib": ["dom", "esnext"],
6
+ "declaration": true,
7
+ "sourceMap": true,
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "moduleResolution": "node",
13
+ "jsx": "react"
14
+ },
15
+ "include": ["src/**/*"]
16
+ }