@servlyadmin/runtime-react 0.1.39 → 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 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.39",
3
+ "version": "0.1.40",
4
4
  "description": "React wrapper for Servly runtime renderer",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",