@servlyadmin/runtime-react 0.1.37 → 0.1.40
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/dist/index.cjs +29 -2
- package/dist/index.js +21 -3
- package/package.json +3 -3
- package/dist/index.d.cts +0 -52
- package/dist/index.d.ts +0 -52
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -37,7 +47,7 @@ __export(index_exports, {
|
|
|
37
47
|
module.exports = __toCommonJS(index_exports);
|
|
38
48
|
|
|
39
49
|
// src/ServlyComponent.tsx
|
|
40
|
-
var import_react = require("react");
|
|
50
|
+
var import_react = __toESM(require("react"), 1);
|
|
41
51
|
var import_react_dom = require("react-dom");
|
|
42
52
|
var import_runtime_core = require("@servlyadmin/runtime-core");
|
|
43
53
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -98,6 +108,9 @@ var ErrorDisplay = ({ error, onRetry, className, style }) => /* @__PURE__ */ (0,
|
|
|
98
108
|
]
|
|
99
109
|
}
|
|
100
110
|
);
|
|
111
|
+
function isReactElement(value) {
|
|
112
|
+
return import_react.default.isValidElement(value);
|
|
113
|
+
}
|
|
101
114
|
function useSlotElements(containerRef, isRendered) {
|
|
102
115
|
const [slotElements, setSlotElements] = (0, import_react.useState)({});
|
|
103
116
|
(0, import_react.useEffect)(() => {
|
|
@@ -143,13 +156,27 @@ function ServlyComponent({
|
|
|
143
156
|
data: null
|
|
144
157
|
});
|
|
145
158
|
const slotElements = useSlotElements(containerRef, isRendered);
|
|
159
|
+
const slotBindings = (0, import_react.useMemo)(() => {
|
|
160
|
+
if (!state.data?.layout) return /* @__PURE__ */ new Map();
|
|
161
|
+
return (0, import_runtime_core.extractSlotBindings)(state.data.layout);
|
|
162
|
+
}, [state.data?.layout]);
|
|
146
163
|
const effectiveSlots = (0, import_react.useMemo)(() => {
|
|
147
164
|
const result = { ...slots };
|
|
148
165
|
if (children && !result.default) {
|
|
149
166
|
result.default = children;
|
|
150
167
|
}
|
|
168
|
+
if (props && typeof props === "object") {
|
|
169
|
+
for (const [propName, propValue] of Object.entries(props)) {
|
|
170
|
+
if (isReactElement(propValue)) {
|
|
171
|
+
const slotId = slotBindings.get(propName);
|
|
172
|
+
if (slotId && !result[slotId]) {
|
|
173
|
+
result[slotId] = propValue;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
151
178
|
return result;
|
|
152
|
-
}, [slots, children]);
|
|
179
|
+
}, [slots, children, props, slotBindings]);
|
|
153
180
|
const loadComponent = (0, import_react.useCallback)(async () => {
|
|
154
181
|
if (abortControllerRef.current) {
|
|
155
182
|
abortControllerRef.current.abort();
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// src/ServlyComponent.tsx
|
|
2
|
-
import { useRef, useEffect, useState, useCallback, useMemo } from "react";
|
|
2
|
+
import React, { useRef, useEffect, useState, useCallback, useMemo } from "react";
|
|
3
3
|
import { createPortal } from "react-dom";
|
|
4
4
|
import {
|
|
5
5
|
render,
|
|
6
6
|
fetchComponent,
|
|
7
7
|
markElementReady,
|
|
8
|
-
injectTailwind
|
|
8
|
+
injectTailwind,
|
|
9
|
+
extractSlotBindings
|
|
9
10
|
} from "@servlyadmin/runtime-core";
|
|
10
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
12
|
if (typeof document !== "undefined") {
|
|
@@ -65,6 +66,9 @@ var ErrorDisplay = ({ error, onRetry, className, style }) => /* @__PURE__ */ jsx
|
|
|
65
66
|
]
|
|
66
67
|
}
|
|
67
68
|
);
|
|
69
|
+
function isReactElement(value) {
|
|
70
|
+
return React.isValidElement(value);
|
|
71
|
+
}
|
|
68
72
|
function useSlotElements(containerRef, isRendered) {
|
|
69
73
|
const [slotElements, setSlotElements] = useState({});
|
|
70
74
|
useEffect(() => {
|
|
@@ -110,13 +114,27 @@ function ServlyComponent({
|
|
|
110
114
|
data: null
|
|
111
115
|
});
|
|
112
116
|
const slotElements = useSlotElements(containerRef, isRendered);
|
|
117
|
+
const slotBindings = useMemo(() => {
|
|
118
|
+
if (!state.data?.layout) return /* @__PURE__ */ new Map();
|
|
119
|
+
return extractSlotBindings(state.data.layout);
|
|
120
|
+
}, [state.data?.layout]);
|
|
113
121
|
const effectiveSlots = useMemo(() => {
|
|
114
122
|
const result = { ...slots };
|
|
115
123
|
if (children && !result.default) {
|
|
116
124
|
result.default = children;
|
|
117
125
|
}
|
|
126
|
+
if (props && typeof props === "object") {
|
|
127
|
+
for (const [propName, propValue] of Object.entries(props)) {
|
|
128
|
+
if (isReactElement(propValue)) {
|
|
129
|
+
const slotId = slotBindings.get(propName);
|
|
130
|
+
if (slotId && !result[slotId]) {
|
|
131
|
+
result[slotId] = propValue;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
118
136
|
return result;
|
|
119
|
-
}, [slots, children]);
|
|
137
|
+
}, [slots, children, props, slotBindings]);
|
|
120
138
|
const loadComponent = useCallback(async () => {
|
|
121
139
|
if (abortControllerRef.current) {
|
|
122
140
|
abortControllerRef.current.abort();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servlyadmin/runtime-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
4
|
"description": "React wrapper for Servly runtime renderer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"react-dom": ">=17.0.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@servlyadmin/runtime-core": "^0.1.
|
|
39
|
+
"@servlyadmin/runtime-core": "^0.1.46"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/react": "^18.2.0",
|
|
@@ -46,4 +46,4 @@
|
|
|
46
46
|
"tsup": "^8.0.0",
|
|
47
47
|
"typescript": "^5.3.0"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
package/dist/index.d.cts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { CacheStrategy, RetryConfig } from '@servlyadmin/runtime-core';
|
|
3
|
-
export { BindingContext, CacheStrategy, ComponentData, FetchOptions, LayoutElement, PropDefinition, RetryConfig, clearAllCaches, compareVersions, fetchComponent, getRegistryUrl, invalidateCache, isComponentAvailable, parseVersion, prefetchComponents, resolveVersion, satisfiesVersion, setRegistryUrl } from '@servlyadmin/runtime-core';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* ServlyComponent
|
|
7
|
-
* React wrapper for Servly runtime renderer with slot support
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Slot content type - React nodes keyed by slot name
|
|
12
|
-
*/
|
|
13
|
-
type SlotContent = Record<string, React.ReactNode>;
|
|
14
|
-
/**
|
|
15
|
-
* Props for ServlyComponent
|
|
16
|
-
*/
|
|
17
|
-
interface ServlyComponentProps<P = Record<string, any>> {
|
|
18
|
-
/** Component ID from the registry */
|
|
19
|
-
id: string;
|
|
20
|
-
/** Version specifier (exact, range, or "latest") */
|
|
21
|
-
version?: string;
|
|
22
|
-
/** Props to pass to the component */
|
|
23
|
-
props?: P;
|
|
24
|
-
/** Slot content - React nodes to portal into named slots */
|
|
25
|
-
slots?: SlotContent;
|
|
26
|
-
/** Fallback UI while loading or on error */
|
|
27
|
-
fallback?: React.ReactNode;
|
|
28
|
-
/** Error callback */
|
|
29
|
-
onError?: (error: Error) => void;
|
|
30
|
-
/** Load complete callback */
|
|
31
|
-
onLoad?: () => void;
|
|
32
|
-
/** Custom className for wrapper */
|
|
33
|
-
className?: string;
|
|
34
|
-
/** Custom styles for wrapper */
|
|
35
|
-
style?: React.CSSProperties;
|
|
36
|
-
/** Show loading skeleton */
|
|
37
|
-
showSkeleton?: boolean;
|
|
38
|
-
/** Cache strategy */
|
|
39
|
-
cacheStrategy?: CacheStrategy;
|
|
40
|
-
/** Retry configuration */
|
|
41
|
-
retryConfig?: Partial<RetryConfig>;
|
|
42
|
-
/** Event handlers keyed by element ID then event name */
|
|
43
|
-
eventHandlers?: Record<string, Record<string, (e: Event) => void>>;
|
|
44
|
-
/** Children - rendered into default slot if no slots prop */
|
|
45
|
-
children?: React.ReactNode;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* ServlyComponent - React wrapper for Servly runtime with slot support
|
|
49
|
-
*/
|
|
50
|
-
declare function ServlyComponent<P = Record<string, any>>({ id, version, props, slots, fallback, onError, onLoad, className, style, showSkeleton, cacheStrategy, retryConfig, eventHandlers, children, }: ServlyComponentProps<P>): React.ReactElement | null;
|
|
51
|
-
|
|
52
|
-
export { ServlyComponent, type ServlyComponentProps, ServlyComponent as default };
|
package/dist/index.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { CacheStrategy, RetryConfig } from '@servlyadmin/runtime-core';
|
|
3
|
-
export { BindingContext, CacheStrategy, ComponentData, FetchOptions, LayoutElement, PropDefinition, RetryConfig, clearAllCaches, compareVersions, fetchComponent, getRegistryUrl, invalidateCache, isComponentAvailable, parseVersion, prefetchComponents, resolveVersion, satisfiesVersion, setRegistryUrl } from '@servlyadmin/runtime-core';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* ServlyComponent
|
|
7
|
-
* React wrapper for Servly runtime renderer with slot support
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Slot content type - React nodes keyed by slot name
|
|
12
|
-
*/
|
|
13
|
-
type SlotContent = Record<string, React.ReactNode>;
|
|
14
|
-
/**
|
|
15
|
-
* Props for ServlyComponent
|
|
16
|
-
*/
|
|
17
|
-
interface ServlyComponentProps<P = Record<string, any>> {
|
|
18
|
-
/** Component ID from the registry */
|
|
19
|
-
id: string;
|
|
20
|
-
/** Version specifier (exact, range, or "latest") */
|
|
21
|
-
version?: string;
|
|
22
|
-
/** Props to pass to the component */
|
|
23
|
-
props?: P;
|
|
24
|
-
/** Slot content - React nodes to portal into named slots */
|
|
25
|
-
slots?: SlotContent;
|
|
26
|
-
/** Fallback UI while loading or on error */
|
|
27
|
-
fallback?: React.ReactNode;
|
|
28
|
-
/** Error callback */
|
|
29
|
-
onError?: (error: Error) => void;
|
|
30
|
-
/** Load complete callback */
|
|
31
|
-
onLoad?: () => void;
|
|
32
|
-
/** Custom className for wrapper */
|
|
33
|
-
className?: string;
|
|
34
|
-
/** Custom styles for wrapper */
|
|
35
|
-
style?: React.CSSProperties;
|
|
36
|
-
/** Show loading skeleton */
|
|
37
|
-
showSkeleton?: boolean;
|
|
38
|
-
/** Cache strategy */
|
|
39
|
-
cacheStrategy?: CacheStrategy;
|
|
40
|
-
/** Retry configuration */
|
|
41
|
-
retryConfig?: Partial<RetryConfig>;
|
|
42
|
-
/** Event handlers keyed by element ID then event name */
|
|
43
|
-
eventHandlers?: Record<string, Record<string, (e: Event) => void>>;
|
|
44
|
-
/** Children - rendered into default slot if no slots prop */
|
|
45
|
-
children?: React.ReactNode;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* ServlyComponent - React wrapper for Servly runtime with slot support
|
|
49
|
-
*/
|
|
50
|
-
declare function ServlyComponent<P = Record<string, any>>({ id, version, props, slots, fallback, onError, onLoad, className, style, showSkeleton, cacheStrategy, retryConfig, eventHandlers, children, }: ServlyComponentProps<P>): React.ReactElement | null;
|
|
51
|
-
|
|
52
|
-
export { ServlyComponent, type ServlyComponentProps, ServlyComponent as default };
|