@servlyadmin/runtime-react 0.1.9 → 0.1.11
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.mjs → index.cjs} +76 -53
- package/dist/index.js +53 -75
- package/package.json +8 -5
|
@@ -1,12 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ServlyComponent: () => ServlyComponent,
|
|
24
|
+
clearAllCaches: () => import_runtime_core2.clearAllCaches,
|
|
25
|
+
compareVersions: () => import_runtime_core2.compareVersions,
|
|
26
|
+
default: () => ServlyComponent_default,
|
|
27
|
+
fetchComponent: () => import_runtime_core2.fetchComponent,
|
|
28
|
+
getRegistryUrl: () => import_runtime_core2.getRegistryUrl,
|
|
29
|
+
invalidateCache: () => import_runtime_core2.invalidateCache,
|
|
30
|
+
isComponentAvailable: () => import_runtime_core2.isComponentAvailable,
|
|
31
|
+
parseVersion: () => import_runtime_core2.parseVersion,
|
|
32
|
+
prefetchComponents: () => import_runtime_core2.prefetchComponents,
|
|
33
|
+
resolveVersion: () => import_runtime_core2.resolveVersion,
|
|
34
|
+
satisfiesVersion: () => import_runtime_core2.satisfiesVersion,
|
|
35
|
+
setRegistryUrl: () => import_runtime_core2.setRegistryUrl
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/ServlyComponent.tsx
|
|
40
|
+
var import_react = require("react");
|
|
41
|
+
var import_react_dom = require("react-dom");
|
|
42
|
+
var import_runtime_core = require("@servlyadmin/runtime-core");
|
|
43
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
44
|
+
var LoadingSkeleton = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
10
45
|
"div",
|
|
11
46
|
{
|
|
12
47
|
className: `servly-skeleton ${className || ""}`,
|
|
@@ -16,7 +51,7 @@ var LoadingSkeleton = ({ className }) => /* @__PURE__ */ jsx(
|
|
|
16
51
|
minHeight: "100px",
|
|
17
52
|
animation: "servly-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"
|
|
18
53
|
},
|
|
19
|
-
children: /* @__PURE__ */ jsx("style", { children: `
|
|
54
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: `
|
|
20
55
|
@keyframes servly-pulse {
|
|
21
56
|
0%, 100% { opacity: 1; }
|
|
22
57
|
50% { opacity: 0.5; }
|
|
@@ -24,7 +59,7 @@ var LoadingSkeleton = ({ className }) => /* @__PURE__ */ jsx(
|
|
|
24
59
|
` })
|
|
25
60
|
}
|
|
26
61
|
);
|
|
27
|
-
var ErrorDisplay = ({ error, onRetry, className, style }) => /* @__PURE__ */ jsxs(
|
|
62
|
+
var ErrorDisplay = ({ error, onRetry, className, style }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
28
63
|
"div",
|
|
29
64
|
{
|
|
30
65
|
className: `servly-error ${className || ""}`,
|
|
@@ -36,9 +71,9 @@ var ErrorDisplay = ({ error, onRetry, className, style }) => /* @__PURE__ */ jsx
|
|
|
36
71
|
...style
|
|
37
72
|
},
|
|
38
73
|
children: [
|
|
39
|
-
/* @__PURE__ */ jsx("p", { style: { margin: 0, fontWeight: 500 }, children: "Failed to load component" }),
|
|
40
|
-
/* @__PURE__ */ jsx("p", { style: { margin: "8px 0 0", fontSize: "14px", color: "#991b1b" }, children: error.message }),
|
|
41
|
-
onRetry && /* @__PURE__ */ jsx(
|
|
74
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: { margin: 0, fontWeight: 500 }, children: "Failed to load component" }),
|
|
75
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: { margin: "8px 0 0", fontSize: "14px", color: "#991b1b" }, children: error.message }),
|
|
76
|
+
onRetry && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
42
77
|
"button",
|
|
43
78
|
{
|
|
44
79
|
onClick: onRetry,
|
|
@@ -59,8 +94,8 @@ var ErrorDisplay = ({ error, onRetry, className, style }) => /* @__PURE__ */ jsx
|
|
|
59
94
|
}
|
|
60
95
|
);
|
|
61
96
|
function useSlotElements(containerRef, isRendered) {
|
|
62
|
-
const [slotElements, setSlotElements] = useState({});
|
|
63
|
-
useEffect(() => {
|
|
97
|
+
const [slotElements, setSlotElements] = (0, import_react.useState)({});
|
|
98
|
+
(0, import_react.useEffect)(() => {
|
|
64
99
|
if (!isRendered || !containerRef.current) {
|
|
65
100
|
setSlotElements({});
|
|
66
101
|
return;
|
|
@@ -93,24 +128,24 @@ function ServlyComponent({
|
|
|
93
128
|
eventHandlers,
|
|
94
129
|
children
|
|
95
130
|
}) {
|
|
96
|
-
const containerRef = useRef(null);
|
|
97
|
-
const renderResultRef = useRef(null);
|
|
98
|
-
const abortControllerRef = useRef(null);
|
|
99
|
-
const [isRendered, setIsRendered] = useState(false);
|
|
100
|
-
const [state, setState] = useState({
|
|
131
|
+
const containerRef = (0, import_react.useRef)(null);
|
|
132
|
+
const renderResultRef = (0, import_react.useRef)(null);
|
|
133
|
+
const abortControllerRef = (0, import_react.useRef)(null);
|
|
134
|
+
const [isRendered, setIsRendered] = (0, import_react.useState)(false);
|
|
135
|
+
const [state, setState] = (0, import_react.useState)({
|
|
101
136
|
loading: true,
|
|
102
137
|
error: null,
|
|
103
138
|
data: null
|
|
104
139
|
});
|
|
105
140
|
const slotElements = useSlotElements(containerRef, isRendered);
|
|
106
|
-
const effectiveSlots = useMemo(() => {
|
|
141
|
+
const effectiveSlots = (0, import_react.useMemo)(() => {
|
|
107
142
|
const result = { ...slots };
|
|
108
143
|
if (children && !result.default) {
|
|
109
144
|
result.default = children;
|
|
110
145
|
}
|
|
111
146
|
return result;
|
|
112
147
|
}, [slots, children]);
|
|
113
|
-
const loadComponent = useCallback(async () => {
|
|
148
|
+
const loadComponent = (0, import_react.useCallback)(async () => {
|
|
114
149
|
if (abortControllerRef.current) {
|
|
115
150
|
abortControllerRef.current.abort();
|
|
116
151
|
}
|
|
@@ -124,7 +159,7 @@ function ServlyComponent({
|
|
|
124
159
|
signal: abortControllerRef.current.signal
|
|
125
160
|
};
|
|
126
161
|
try {
|
|
127
|
-
const result = await fetchComponent(id, fetchOptions);
|
|
162
|
+
const result = await (0, import_runtime_core.fetchComponent)(id, fetchOptions);
|
|
128
163
|
setState({
|
|
129
164
|
loading: false,
|
|
130
165
|
error: null,
|
|
@@ -146,7 +181,7 @@ function ServlyComponent({
|
|
|
146
181
|
onError?.(err);
|
|
147
182
|
}
|
|
148
183
|
}, [id, version, cacheStrategy, retryConfig, onLoad, onError]);
|
|
149
|
-
useEffect(() => {
|
|
184
|
+
(0, import_react.useEffect)(() => {
|
|
150
185
|
loadComponent();
|
|
151
186
|
return () => {
|
|
152
187
|
if (abortControllerRef.current) {
|
|
@@ -154,7 +189,7 @@ function ServlyComponent({
|
|
|
154
189
|
}
|
|
155
190
|
};
|
|
156
191
|
}, [loadComponent]);
|
|
157
|
-
useEffect(() => {
|
|
192
|
+
(0, import_react.useEffect)(() => {
|
|
158
193
|
if (!state.data || !containerRef.current) return;
|
|
159
194
|
const context = {
|
|
160
195
|
props,
|
|
@@ -165,7 +200,7 @@ function ServlyComponent({
|
|
|
165
200
|
renderResultRef.current.update(context);
|
|
166
201
|
return;
|
|
167
202
|
}
|
|
168
|
-
renderResultRef.current = render({
|
|
203
|
+
renderResultRef.current = (0, import_runtime_core.render)({
|
|
169
204
|
container: containerRef.current,
|
|
170
205
|
elements: state.data.layout,
|
|
171
206
|
context,
|
|
@@ -182,7 +217,7 @@ function ServlyComponent({
|
|
|
182
217
|
}
|
|
183
218
|
};
|
|
184
219
|
}, [state.data, eventHandlers]);
|
|
185
|
-
useEffect(() => {
|
|
220
|
+
(0, import_react.useEffect)(() => {
|
|
186
221
|
if (!renderResultRef.current || !state.data) return;
|
|
187
222
|
const context = {
|
|
188
223
|
props,
|
|
@@ -192,13 +227,13 @@ function ServlyComponent({
|
|
|
192
227
|
renderResultRef.current.update(context);
|
|
193
228
|
}, [props, state.data]);
|
|
194
229
|
if (state.loading) {
|
|
195
|
-
if (fallback) return /* @__PURE__ */ jsx(Fragment, { children: fallback });
|
|
196
|
-
if (showSkeleton) return /* @__PURE__ */ jsx(LoadingSkeleton, { className });
|
|
230
|
+
if (fallback) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: fallback });
|
|
231
|
+
if (showSkeleton) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingSkeleton, { className });
|
|
197
232
|
return null;
|
|
198
233
|
}
|
|
199
234
|
if (state.error) {
|
|
200
|
-
if (fallback) return /* @__PURE__ */ jsx(Fragment, { children: fallback });
|
|
201
|
-
return /* @__PURE__ */ jsx(
|
|
235
|
+
if (fallback) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: fallback });
|
|
236
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
202
237
|
ErrorDisplay,
|
|
203
238
|
{
|
|
204
239
|
error: state.error,
|
|
@@ -208,8 +243,8 @@ function ServlyComponent({
|
|
|
208
243
|
}
|
|
209
244
|
);
|
|
210
245
|
}
|
|
211
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
212
|
-
/* @__PURE__ */ jsx(
|
|
246
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
247
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
213
248
|
"div",
|
|
214
249
|
{
|
|
215
250
|
ref: containerRef,
|
|
@@ -222,32 +257,20 @@ function ServlyComponent({
|
|
|
222
257
|
Object.entries(effectiveSlots).map(([slotName, content]) => {
|
|
223
258
|
const slotEl = slotElements[slotName];
|
|
224
259
|
if (!slotEl || !content) return null;
|
|
225
|
-
return createPortal(content, slotEl, `slot-${slotName}`);
|
|
260
|
+
return (0, import_react_dom.createPortal)(content, slotEl, `slot-${slotName}`);
|
|
226
261
|
})
|
|
227
262
|
] });
|
|
228
263
|
}
|
|
229
264
|
var ServlyComponent_default = ServlyComponent;
|
|
230
265
|
|
|
231
|
-
//
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
isComponentAvailable,
|
|
236
|
-
setRegistryUrl,
|
|
237
|
-
getRegistryUrl,
|
|
238
|
-
invalidateCache,
|
|
239
|
-
clearAllCaches,
|
|
240
|
-
parseVersion,
|
|
241
|
-
compareVersions,
|
|
242
|
-
satisfiesVersion,
|
|
243
|
-
resolveVersion
|
|
244
|
-
} from "@servlyadmin/runtime-core";
|
|
245
|
-
export {
|
|
266
|
+
// src/index.ts
|
|
267
|
+
var import_runtime_core2 = require("@servlyadmin/runtime-core");
|
|
268
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
269
|
+
0 && (module.exports = {
|
|
246
270
|
ServlyComponent,
|
|
247
271
|
clearAllCaches,
|
|
248
272
|
compareVersions,
|
|
249
|
-
|
|
250
|
-
fetchComponent2 as fetchComponent,
|
|
273
|
+
fetchComponent,
|
|
251
274
|
getRegistryUrl,
|
|
252
275
|
invalidateCache,
|
|
253
276
|
isComponentAvailable,
|
|
@@ -256,4 +279,4 @@ export {
|
|
|
256
279
|
resolveVersion,
|
|
257
280
|
satisfiesVersion,
|
|
258
281
|
setRegistryUrl
|
|
259
|
-
};
|
|
282
|
+
});
|
package/dist/index.js
CHANGED
|
@@ -1,46 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
var
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// packages/runtime-react/src/index.ts
|
|
20
|
-
var index_exports = {};
|
|
21
|
-
__export(index_exports, {
|
|
22
|
-
ServlyComponent: () => ServlyComponent,
|
|
23
|
-
clearAllCaches: () => import_runtime_core2.clearAllCaches,
|
|
24
|
-
compareVersions: () => import_runtime_core2.compareVersions,
|
|
25
|
-
default: () => ServlyComponent_default,
|
|
26
|
-
fetchComponent: () => import_runtime_core2.fetchComponent,
|
|
27
|
-
getRegistryUrl: () => import_runtime_core2.getRegistryUrl,
|
|
28
|
-
invalidateCache: () => import_runtime_core2.invalidateCache,
|
|
29
|
-
isComponentAvailable: () => import_runtime_core2.isComponentAvailable,
|
|
30
|
-
parseVersion: () => import_runtime_core2.parseVersion,
|
|
31
|
-
prefetchComponents: () => import_runtime_core2.prefetchComponents,
|
|
32
|
-
resolveVersion: () => import_runtime_core2.resolveVersion,
|
|
33
|
-
satisfiesVersion: () => import_runtime_core2.satisfiesVersion,
|
|
34
|
-
setRegistryUrl: () => import_runtime_core2.setRegistryUrl
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_exports);
|
|
37
|
-
|
|
38
|
-
// packages/runtime-react/src/ServlyComponent.tsx
|
|
39
|
-
var import_react = require("react");
|
|
40
|
-
var import_react_dom = require("react-dom");
|
|
41
|
-
var import_runtime_core = require("@servlyadmin/runtime-core");
|
|
42
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
43
|
-
var LoadingSkeleton = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1
|
+
// src/ServlyComponent.tsx
|
|
2
|
+
import { useRef, useEffect, useState, useCallback, useMemo } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import {
|
|
5
|
+
render,
|
|
6
|
+
fetchComponent
|
|
7
|
+
} from "@servlyadmin/runtime-core";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
var LoadingSkeleton = ({ className }) => /* @__PURE__ */ jsx(
|
|
44
10
|
"div",
|
|
45
11
|
{
|
|
46
12
|
className: `servly-skeleton ${className || ""}`,
|
|
@@ -50,7 +16,7 @@ var LoadingSkeleton = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.
|
|
|
50
16
|
minHeight: "100px",
|
|
51
17
|
animation: "servly-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"
|
|
52
18
|
},
|
|
53
|
-
children: /* @__PURE__ */
|
|
19
|
+
children: /* @__PURE__ */ jsx("style", { children: `
|
|
54
20
|
@keyframes servly-pulse {
|
|
55
21
|
0%, 100% { opacity: 1; }
|
|
56
22
|
50% { opacity: 0.5; }
|
|
@@ -58,7 +24,7 @@ var LoadingSkeleton = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.
|
|
|
58
24
|
` })
|
|
59
25
|
}
|
|
60
26
|
);
|
|
61
|
-
var ErrorDisplay = ({ error, onRetry, className, style }) => /* @__PURE__ */
|
|
27
|
+
var ErrorDisplay = ({ error, onRetry, className, style }) => /* @__PURE__ */ jsxs(
|
|
62
28
|
"div",
|
|
63
29
|
{
|
|
64
30
|
className: `servly-error ${className || ""}`,
|
|
@@ -70,9 +36,9 @@ var ErrorDisplay = ({ error, onRetry, className, style }) => /* @__PURE__ */ (0,
|
|
|
70
36
|
...style
|
|
71
37
|
},
|
|
72
38
|
children: [
|
|
73
|
-
/* @__PURE__ */
|
|
74
|
-
/* @__PURE__ */
|
|
75
|
-
onRetry && /* @__PURE__ */
|
|
39
|
+
/* @__PURE__ */ jsx("p", { style: { margin: 0, fontWeight: 500 }, children: "Failed to load component" }),
|
|
40
|
+
/* @__PURE__ */ jsx("p", { style: { margin: "8px 0 0", fontSize: "14px", color: "#991b1b" }, children: error.message }),
|
|
41
|
+
onRetry && /* @__PURE__ */ jsx(
|
|
76
42
|
"button",
|
|
77
43
|
{
|
|
78
44
|
onClick: onRetry,
|
|
@@ -93,8 +59,8 @@ var ErrorDisplay = ({ error, onRetry, className, style }) => /* @__PURE__ */ (0,
|
|
|
93
59
|
}
|
|
94
60
|
);
|
|
95
61
|
function useSlotElements(containerRef, isRendered) {
|
|
96
|
-
const [slotElements, setSlotElements] =
|
|
97
|
-
|
|
62
|
+
const [slotElements, setSlotElements] = useState({});
|
|
63
|
+
useEffect(() => {
|
|
98
64
|
if (!isRendered || !containerRef.current) {
|
|
99
65
|
setSlotElements({});
|
|
100
66
|
return;
|
|
@@ -127,24 +93,24 @@ function ServlyComponent({
|
|
|
127
93
|
eventHandlers,
|
|
128
94
|
children
|
|
129
95
|
}) {
|
|
130
|
-
const containerRef =
|
|
131
|
-
const renderResultRef =
|
|
132
|
-
const abortControllerRef =
|
|
133
|
-
const [isRendered, setIsRendered] =
|
|
134
|
-
const [state, setState] =
|
|
96
|
+
const containerRef = useRef(null);
|
|
97
|
+
const renderResultRef = useRef(null);
|
|
98
|
+
const abortControllerRef = useRef(null);
|
|
99
|
+
const [isRendered, setIsRendered] = useState(false);
|
|
100
|
+
const [state, setState] = useState({
|
|
135
101
|
loading: true,
|
|
136
102
|
error: null,
|
|
137
103
|
data: null
|
|
138
104
|
});
|
|
139
105
|
const slotElements = useSlotElements(containerRef, isRendered);
|
|
140
|
-
const effectiveSlots =
|
|
106
|
+
const effectiveSlots = useMemo(() => {
|
|
141
107
|
const result = { ...slots };
|
|
142
108
|
if (children && !result.default) {
|
|
143
109
|
result.default = children;
|
|
144
110
|
}
|
|
145
111
|
return result;
|
|
146
112
|
}, [slots, children]);
|
|
147
|
-
const loadComponent =
|
|
113
|
+
const loadComponent = useCallback(async () => {
|
|
148
114
|
if (abortControllerRef.current) {
|
|
149
115
|
abortControllerRef.current.abort();
|
|
150
116
|
}
|
|
@@ -158,7 +124,7 @@ function ServlyComponent({
|
|
|
158
124
|
signal: abortControllerRef.current.signal
|
|
159
125
|
};
|
|
160
126
|
try {
|
|
161
|
-
const result = await
|
|
127
|
+
const result = await fetchComponent(id, fetchOptions);
|
|
162
128
|
setState({
|
|
163
129
|
loading: false,
|
|
164
130
|
error: null,
|
|
@@ -180,7 +146,7 @@ function ServlyComponent({
|
|
|
180
146
|
onError?.(err);
|
|
181
147
|
}
|
|
182
148
|
}, [id, version, cacheStrategy, retryConfig, onLoad, onError]);
|
|
183
|
-
|
|
149
|
+
useEffect(() => {
|
|
184
150
|
loadComponent();
|
|
185
151
|
return () => {
|
|
186
152
|
if (abortControllerRef.current) {
|
|
@@ -188,7 +154,7 @@ function ServlyComponent({
|
|
|
188
154
|
}
|
|
189
155
|
};
|
|
190
156
|
}, [loadComponent]);
|
|
191
|
-
|
|
157
|
+
useEffect(() => {
|
|
192
158
|
if (!state.data || !containerRef.current) return;
|
|
193
159
|
const context = {
|
|
194
160
|
props,
|
|
@@ -199,7 +165,7 @@ function ServlyComponent({
|
|
|
199
165
|
renderResultRef.current.update(context);
|
|
200
166
|
return;
|
|
201
167
|
}
|
|
202
|
-
renderResultRef.current =
|
|
168
|
+
renderResultRef.current = render({
|
|
203
169
|
container: containerRef.current,
|
|
204
170
|
elements: state.data.layout,
|
|
205
171
|
context,
|
|
@@ -216,7 +182,7 @@ function ServlyComponent({
|
|
|
216
182
|
}
|
|
217
183
|
};
|
|
218
184
|
}, [state.data, eventHandlers]);
|
|
219
|
-
|
|
185
|
+
useEffect(() => {
|
|
220
186
|
if (!renderResultRef.current || !state.data) return;
|
|
221
187
|
const context = {
|
|
222
188
|
props,
|
|
@@ -226,13 +192,13 @@ function ServlyComponent({
|
|
|
226
192
|
renderResultRef.current.update(context);
|
|
227
193
|
}, [props, state.data]);
|
|
228
194
|
if (state.loading) {
|
|
229
|
-
if (fallback) return /* @__PURE__ */
|
|
230
|
-
if (showSkeleton) return /* @__PURE__ */
|
|
195
|
+
if (fallback) return /* @__PURE__ */ jsx(Fragment, { children: fallback });
|
|
196
|
+
if (showSkeleton) return /* @__PURE__ */ jsx(LoadingSkeleton, { className });
|
|
231
197
|
return null;
|
|
232
198
|
}
|
|
233
199
|
if (state.error) {
|
|
234
|
-
if (fallback) return /* @__PURE__ */
|
|
235
|
-
return /* @__PURE__ */
|
|
200
|
+
if (fallback) return /* @__PURE__ */ jsx(Fragment, { children: fallback });
|
|
201
|
+
return /* @__PURE__ */ jsx(
|
|
236
202
|
ErrorDisplay,
|
|
237
203
|
{
|
|
238
204
|
error: state.error,
|
|
@@ -242,8 +208,8 @@ function ServlyComponent({
|
|
|
242
208
|
}
|
|
243
209
|
);
|
|
244
210
|
}
|
|
245
|
-
return /* @__PURE__ */
|
|
246
|
-
/* @__PURE__ */
|
|
211
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
212
|
+
/* @__PURE__ */ jsx(
|
|
247
213
|
"div",
|
|
248
214
|
{
|
|
249
215
|
ref: containerRef,
|
|
@@ -256,20 +222,32 @@ function ServlyComponent({
|
|
|
256
222
|
Object.entries(effectiveSlots).map(([slotName, content]) => {
|
|
257
223
|
const slotEl = slotElements[slotName];
|
|
258
224
|
if (!slotEl || !content) return null;
|
|
259
|
-
return
|
|
225
|
+
return createPortal(content, slotEl, `slot-${slotName}`);
|
|
260
226
|
})
|
|
261
227
|
] });
|
|
262
228
|
}
|
|
263
229
|
var ServlyComponent_default = ServlyComponent;
|
|
264
230
|
|
|
265
|
-
//
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
231
|
+
// src/index.ts
|
|
232
|
+
import {
|
|
233
|
+
fetchComponent as fetchComponent2,
|
|
234
|
+
prefetchComponents,
|
|
235
|
+
isComponentAvailable,
|
|
236
|
+
setRegistryUrl,
|
|
237
|
+
getRegistryUrl,
|
|
238
|
+
invalidateCache,
|
|
239
|
+
clearAllCaches,
|
|
240
|
+
parseVersion,
|
|
241
|
+
compareVersions,
|
|
242
|
+
satisfiesVersion,
|
|
243
|
+
resolveVersion
|
|
244
|
+
} from "@servlyadmin/runtime-core";
|
|
245
|
+
export {
|
|
269
246
|
ServlyComponent,
|
|
270
247
|
clearAllCaches,
|
|
271
248
|
compareVersions,
|
|
272
|
-
|
|
249
|
+
ServlyComponent_default as default,
|
|
250
|
+
fetchComponent2 as fetchComponent,
|
|
273
251
|
getRegistryUrl,
|
|
274
252
|
invalidateCache,
|
|
275
253
|
isComponentAvailable,
|
|
@@ -278,4 +256,4 @@ var import_runtime_core2 = require("@servlyadmin/runtime-core");
|
|
|
278
256
|
resolveVersion,
|
|
279
257
|
satisfiesVersion,
|
|
280
258
|
setRegistryUrl
|
|
281
|
-
}
|
|
259
|
+
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servlyadmin/runtime-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "React wrapper for Servly runtime renderer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
10
12
|
"import": "./dist/index.mjs",
|
|
11
|
-
"require": "./dist/index.js"
|
|
13
|
+
"require": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.mjs"
|
|
12
15
|
}
|
|
13
16
|
},
|
|
14
17
|
"files": [
|
|
@@ -16,6 +19,7 @@
|
|
|
16
19
|
],
|
|
17
20
|
"sideEffects": false,
|
|
18
21
|
"scripts": {
|
|
22
|
+
"build:pkg": "tsup src/index.ts --format esm,cjs --clean --external react",
|
|
19
23
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean --external react",
|
|
20
24
|
"dev": "tsup src/index.ts --format esm,cjs --dts --watch --external react"
|
|
21
25
|
},
|
|
@@ -32,7 +36,7 @@
|
|
|
32
36
|
"react-dom": ">=17.0.0"
|
|
33
37
|
},
|
|
34
38
|
"dependencies": {
|
|
35
|
-
"@servlyadmin/runtime-core": "^0.1.
|
|
39
|
+
"@servlyadmin/runtime-core": "^0.1.11"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
38
42
|
"@types/react": "^18.2.0",
|
|
@@ -40,7 +44,6 @@
|
|
|
40
44
|
"react": "^18.2.0",
|
|
41
45
|
"react-dom": "^18.2.0",
|
|
42
46
|
"tsup": "^8.0.0",
|
|
43
|
-
"typescript": "^5.3.0"
|
|
44
|
-
"vitest": "^1.0.0"
|
|
47
|
+
"typescript": "^5.3.0"
|
|
45
48
|
}
|
|
46
49
|
}
|