tokensafe-ui 0.1.10 → 0.1.12

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  activeInstances
3
- } from "./chunk-PRDRKCKA.js";
3
+ } from "./chunk-N5DE4X4Z.js";
4
4
 
5
5
  // ../observer/dist/index.js
6
6
  import fs from "fs";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  buildDependencyGraph,
3
3
  observeDiff
4
- } from "./chunk-QM2CUNVR.js";
4
+ } from "./chunk-H3UPVNVN.js";
5
5
  import {
6
6
  applyPatch
7
7
  } from "./chunk-N7XIVYCL.js";
@@ -9,7 +9,7 @@ import {
9
9
  activeInstances,
10
10
  testAction,
11
11
  testEffect
12
- } from "./chunk-PRDRKCKA.js";
12
+ } from "./chunk-N5DE4X4Z.js";
13
13
 
14
14
  // ../mcp/dist/index.js
15
15
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
@@ -1177,23 +1177,23 @@ function renderVNode(node, instance) {
1177
1177
  return fragment;
1178
1178
  }
1179
1179
  if (targetType === Show) {
1180
- const container = document.createDocumentFragment();
1181
- const startAnchor = document.createComment("agent-dom:show-start");
1182
- const endAnchor = document.createComment("agent-dom:show-end");
1183
- container.appendChild(startAnchor);
1184
- container.appendChild(endAnchor);
1185
- let currentNodes = [];
1186
- let currentScope = null;
1180
+ const container2 = document.createDocumentFragment();
1181
+ const startAnchor2 = document.createComment("agent-dom:show-start");
1182
+ const endAnchor2 = document.createComment("agent-dom:show-end");
1183
+ container2.appendChild(startAnchor2);
1184
+ container2.appendChild(endAnchor2);
1185
+ let currentNodes2 = [];
1186
+ let currentScope2 = null;
1187
1187
  effect(() => {
1188
1188
  const whenVal = typeof vnode.props.when === "function" ? vnode.props.when() : vnode.props.when;
1189
- if (currentScope) {
1190
- currentScope.dispose();
1191
- currentScope = null;
1189
+ if (currentScope2) {
1190
+ currentScope2.dispose();
1191
+ currentScope2 = null;
1192
1192
  }
1193
- for (const n of currentNodes) {
1193
+ for (const n of currentNodes2) {
1194
1194
  if (n.parentNode) n.parentNode.removeChild(n);
1195
1195
  }
1196
- currentNodes = [];
1196
+ currentNodes2 = [];
1197
1197
  if (whenVal) {
1198
1198
  const { result: rendered, scope: branchScope } = createScope(() => {
1199
1199
  const branch = untrack(
@@ -1201,41 +1201,41 @@ function renderVNode(node, instance) {
1201
1201
  );
1202
1202
  return untrack(() => branch ? renderVNode(branch, instance) : null);
1203
1203
  });
1204
- currentScope = branchScope;
1204
+ currentScope2 = branchScope;
1205
1205
  if (rendered) {
1206
- const parent = endAnchor.parentNode || container;
1207
- parent.insertBefore(rendered, endAnchor);
1208
- currentNodes.push(rendered);
1206
+ const parent = endAnchor2.parentNode || container2;
1207
+ parent.insertBefore(rendered, endAnchor2);
1208
+ currentNodes2.push(rendered);
1209
1209
  }
1210
1210
  } else if (vnode.props.fallback) {
1211
1211
  const { result: rendered, scope: branchScope } = createScope(() => {
1212
1212
  return untrack(() => renderVNode(vnode.props.fallback, instance));
1213
1213
  });
1214
- currentScope = branchScope;
1214
+ currentScope2 = branchScope;
1215
1215
  if (rendered) {
1216
- const parent = endAnchor.parentNode || container;
1217
- parent.insertBefore(rendered, endAnchor);
1218
- currentNodes.push(rendered);
1216
+ const parent = endAnchor2.parentNode || container2;
1217
+ parent.insertBefore(rendered, endAnchor2);
1218
+ currentNodes2.push(rendered);
1219
1219
  }
1220
1220
  }
1221
1221
  }, {
1222
1222
  name: `control:show:${instance?.id || "root"}`,
1223
1223
  kind: "dom_binding"
1224
1224
  });
1225
- return container;
1225
+ return container2;
1226
1226
  }
1227
1227
  if (vnode.type === For) {
1228
- const container = document.createDocumentFragment();
1229
- const startAnchor = document.createComment("agent-dom:for-start");
1230
- const endAnchor = document.createComment("agent-dom:for-end");
1231
- container.appendChild(startAnchor);
1232
- container.appendChild(endAnchor);
1228
+ const container2 = document.createDocumentFragment();
1229
+ const startAnchor2 = document.createComment("agent-dom:for-start");
1230
+ const endAnchor2 = document.createComment("agent-dom:for-end");
1231
+ container2.appendChild(startAnchor2);
1232
+ container2.appendChild(endAnchor2);
1233
1233
  let currentMap = /* @__PURE__ */ new Map();
1234
1234
  effect(() => {
1235
1235
  const rawItems = typeof vnode.props.each === "function" ? vnode.props.each() : vnode.props.each || [];
1236
1236
  const items = Array.isArray(rawItems) ? rawItems : [];
1237
1237
  const newMap = /* @__PURE__ */ new Map();
1238
- const parent = endAnchor.parentNode || container;
1238
+ const parent = endAnchor2.parentNode || container2;
1239
1239
  items.forEach((item, idx) => {
1240
1240
  let itemKey;
1241
1241
  if (typeof vnode.props.key === "function") {
@@ -1250,16 +1250,16 @@ function renderVNode(node, instance) {
1250
1250
  existing.indexSignal.value = idx;
1251
1251
  newMap.set(itemKey, existing);
1252
1252
  currentMap.delete(itemKey);
1253
- parent.insertBefore(existing.node, endAnchor);
1253
+ parent.insertBefore(existing.node, endAnchor2);
1254
1254
  } else {
1255
1255
  const indexSignal = signal(idx);
1256
1256
  const { result: rendered, scope: itemScope } = createScope(() => {
1257
- const childVNode2 = untrack(() => vnode.props.children(item, () => indexSignal.value));
1258
- return untrack(() => renderVNode(childVNode2, instance));
1257
+ const childVNode = untrack(() => vnode.props.children(item, () => indexSignal.value));
1258
+ return untrack(() => renderVNode(childVNode, instance));
1259
1259
  });
1260
1260
  existing = { key: itemKey, node: rendered, indexSignal, scope: itemScope };
1261
1261
  newMap.set(itemKey, existing);
1262
- parent.insertBefore(rendered, endAnchor);
1262
+ parent.insertBefore(rendered, endAnchor2);
1263
1263
  }
1264
1264
  });
1265
1265
  for (const [_, item] of currentMap) {
@@ -1275,7 +1275,7 @@ function renderVNode(node, instance) {
1275
1275
  name: `control:for:${instance?.id || "root"}`,
1276
1276
  kind: "dom_binding"
1277
1277
  });
1278
- return container;
1278
+ return container2;
1279
1279
  }
1280
1280
  if (targetType === ErrorBoundary) {
1281
1281
  try {
@@ -1291,11 +1291,70 @@ function renderVNode(node, instance) {
1291
1291
  return renderVNode(vnode.props.fallback(err), instance);
1292
1292
  }
1293
1293
  }
1294
- let childVNode = targetType(vnode.props);
1295
- if (typeof childVNode === "function") {
1296
- childVNode = childVNode();
1294
+ const container = document.createDocumentFragment();
1295
+ const compName = targetType.name || "Component";
1296
+ const startAnchor = document.createComment(`agent-dom:${compName}-start`);
1297
+ const endAnchor = document.createComment(`agent-dom:${compName}-end`);
1298
+ container.appendChild(startAnchor);
1299
+ container.appendChild(endAnchor);
1300
+ let currentNodes = [];
1301
+ let currentScope = null;
1302
+ let isInitial = true;
1303
+ const stop = effect(() => {
1304
+ if (currentScope) {
1305
+ currentScope.dispose();
1306
+ currentScope = null;
1307
+ }
1308
+ const { result: rawChild, scope: compScope } = createScope(() => {
1309
+ let res = targetType(vnode.props);
1310
+ if (typeof res === "function") {
1311
+ res = res();
1312
+ }
1313
+ return res;
1314
+ });
1315
+ currentScope = compScope;
1316
+ let rendered = null;
1317
+ if (rawChild !== null && rawChild !== void 0 && typeof rawChild !== "boolean") {
1318
+ rendered = untrack(() => renderVNode(rawChild, instance));
1319
+ }
1320
+ if (isInitial) {
1321
+ if (rendered) {
1322
+ if (rendered instanceof DocumentFragment) {
1323
+ currentNodes = Array.from(rendered.childNodes);
1324
+ } else {
1325
+ currentNodes = [rendered];
1326
+ }
1327
+ container.insertBefore(rendered, endAnchor);
1328
+ } else {
1329
+ currentNodes = [];
1330
+ }
1331
+ isInitial = false;
1332
+ } else {
1333
+ const parent = endAnchor.parentNode;
1334
+ if (!parent) return;
1335
+ for (const n of currentNodes) {
1336
+ if (n.parentNode === parent) {
1337
+ parent.removeChild(n);
1338
+ }
1339
+ }
1340
+ currentNodes = [];
1341
+ if (rendered) {
1342
+ if (rendered instanceof DocumentFragment) {
1343
+ currentNodes = Array.from(rendered.childNodes);
1344
+ } else {
1345
+ currentNodes = [rendered];
1346
+ }
1347
+ parent.insertBefore(rendered, endAnchor);
1348
+ }
1349
+ }
1350
+ }, {
1351
+ name: `component:${compName}`,
1352
+ kind: "dom_binding"
1353
+ });
1354
+ if (instance && instance._cleanups) {
1355
+ instance._cleanups.add(stop);
1297
1356
  }
1298
- return renderVNode(childVNode, instance);
1357
+ return container;
1299
1358
  }
1300
1359
  const tagName = typeof vnode.type === "string" ? vnode.type : String(vnode.type);
1301
1360
  const isSvg = SVG_TAGS.has(tagName.toLowerCase());
@@ -2051,6 +2110,74 @@ function defineAsyncCrudComponent(options) {
2051
2110
  render
2052
2111
  });
2053
2112
  }
2113
+ function ReactBridge({
2114
+ component: Component,
2115
+ props = {},
2116
+ className = "",
2117
+ class: cls = "",
2118
+ wrapperProps = {}
2119
+ }) {
2120
+ let rootInstance = null;
2121
+ const combinedClass = `${cls} ${className}`.trim();
2122
+ const handleRef = (el) => {
2123
+ if (!el) {
2124
+ if (rootInstance) {
2125
+ try {
2126
+ rootInstance.unmount();
2127
+ } catch {
2128
+ }
2129
+ rootInstance = null;
2130
+ }
2131
+ return;
2132
+ }
2133
+ try {
2134
+ const React = globalThis.React || typeof window !== "undefined" && window.React;
2135
+ const ReactDOMClient = globalThis.ReactDOM || typeof window !== "undefined" && window.ReactDOM;
2136
+ if (ReactDOMClient && typeof ReactDOMClient.createRoot === "function") {
2137
+ if (!rootInstance) {
2138
+ rootInstance = ReactDOMClient.createRoot(el);
2139
+ }
2140
+ rootInstance.render(React ? React.createElement(Component, props) : Component(props));
2141
+ } else {
2142
+ const dynamicImport = new Function("m", "return import(m)");
2143
+ dynamicImport("react-dom/client").then(({ createRoot: createRoot2 }) => {
2144
+ dynamicImport("react").then((ReactModule) => {
2145
+ if (!rootInstance) {
2146
+ rootInstance = createRoot2(el);
2147
+ }
2148
+ rootInstance.render(ReactModule.createElement(Component, props));
2149
+ }).catch(() => {
2150
+ if (!rootInstance) {
2151
+ rootInstance = createRoot2(el);
2152
+ }
2153
+ rootInstance.render(Component(props));
2154
+ });
2155
+ }).catch((err) => {
2156
+ console.warn("[TokenSafe ReactBridge Warning]: react-dom/client could not be loaded:", err);
2157
+ });
2158
+ }
2159
+ } catch (err) {
2160
+ console.error("[TokenSafe ReactBridge Error]:", err);
2161
+ }
2162
+ };
2163
+ return h("div", {
2164
+ ref: handleRef,
2165
+ class: combinedClass || "tokensafe-react-bridge",
2166
+ ...wrapperProps
2167
+ });
2168
+ }
2169
+ function createUseSignal(useSyncExternalStore) {
2170
+ return function useSignal(sig) {
2171
+ if (!sig || typeof sig.subscribe !== "function") {
2172
+ return sig?.value;
2173
+ }
2174
+ return useSyncExternalStore(
2175
+ (notify) => sig.subscribe(notify),
2176
+ () => sig.value,
2177
+ () => sig.peek()
2178
+ );
2179
+ };
2180
+ }
2054
2181
  var VERSION = "0.2.0";
2055
2182
 
2056
2183
  export {
@@ -2088,5 +2215,7 @@ export {
2088
2215
  testAction,
2089
2216
  testEffect,
2090
2217
  defineAsyncCrudComponent,
2218
+ ReactBridge,
2219
+ createUseSignal,
2091
2220
  VERSION
2092
2221
  };
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  atomicApplySourceEdit,
3
3
  validateWorkspacePath
4
- } from "./chunk-4E3ZOBB5.js";
4
+ } from "./chunk-IV6VZQHA.js";
5
5
  import {
6
6
  buildDependencyGraph,
7
7
  observe
8
- } from "./chunk-QM2CUNVR.js";
8
+ } from "./chunk-H3UPVNVN.js";
9
9
  import {
10
10
  testAction
11
- } from "./chunk-PRDRKCKA.js";
11
+ } from "./chunk-N5DE4X4Z.js";
12
12
 
13
13
  // ../oumv/dist/chunk-ONAJHNWR.js
14
14
  import fs from "fs";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createTokensafeMcpServer
3
- } from "./chunk-4E3ZOBB5.js";
3
+ } from "./chunk-IV6VZQHA.js";
4
4
 
5
5
  // src/mcp.ts
6
6
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
package/dist/cli.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  startMcpServer
3
- } from "./chunk-RFQ234HI.js";
4
- import "./chunk-4E3ZOBB5.js";
5
- import "./chunk-QM2CUNVR.js";
3
+ } from "./chunk-QVRCZPAK.js";
4
+ import "./chunk-IV6VZQHA.js";
5
+ import "./chunk-H3UPVNVN.js";
6
6
  import "./chunk-N7XIVYCL.js";
7
- import "./chunk-PRDRKCKA.js";
7
+ import "./chunk-N5DE4X4Z.js";
8
8
 
9
9
  // src/cli.ts
10
10
  function parseCliArgs(argv) {
package/dist/index.cjs CHANGED
@@ -25,6 +25,7 @@ __export(index_exports, {
25
25
  For: () => For,
26
26
  Fragment: () => Fragment,
27
27
  GLOBAL_KEYS: () => GLOBAL_KEYS,
28
+ ReactBridge: () => ReactBridge,
28
29
  ReactiveScopeImpl: () => ReactiveScopeImpl,
29
30
  Show: () => Show,
30
31
  SignalImpl: () => SignalImpl,
@@ -36,6 +37,7 @@ __export(index_exports, {
36
37
  computed: () => computed,
37
38
  createRoot: () => createRoot,
38
39
  createScope: () => createScope,
40
+ createUseSignal: () => createUseSignal,
39
41
  defineAsyncCrudComponent: () => defineAsyncCrudComponent,
40
42
  defineComponent: () => defineComponent,
41
43
  effect: () => effect,
@@ -1237,23 +1239,23 @@ function renderVNode(node, instance) {
1237
1239
  return fragment;
1238
1240
  }
1239
1241
  if (targetType === Show) {
1240
- const container = document.createDocumentFragment();
1241
- const startAnchor = document.createComment("agent-dom:show-start");
1242
- const endAnchor = document.createComment("agent-dom:show-end");
1243
- container.appendChild(startAnchor);
1244
- container.appendChild(endAnchor);
1245
- let currentNodes = [];
1246
- let currentScope = null;
1242
+ const container2 = document.createDocumentFragment();
1243
+ const startAnchor2 = document.createComment("agent-dom:show-start");
1244
+ const endAnchor2 = document.createComment("agent-dom:show-end");
1245
+ container2.appendChild(startAnchor2);
1246
+ container2.appendChild(endAnchor2);
1247
+ let currentNodes2 = [];
1248
+ let currentScope2 = null;
1247
1249
  effect(() => {
1248
1250
  const whenVal = typeof vnode.props.when === "function" ? vnode.props.when() : vnode.props.when;
1249
- if (currentScope) {
1250
- currentScope.dispose();
1251
- currentScope = null;
1251
+ if (currentScope2) {
1252
+ currentScope2.dispose();
1253
+ currentScope2 = null;
1252
1254
  }
1253
- for (const n of currentNodes) {
1255
+ for (const n of currentNodes2) {
1254
1256
  if (n.parentNode) n.parentNode.removeChild(n);
1255
1257
  }
1256
- currentNodes = [];
1258
+ currentNodes2 = [];
1257
1259
  if (whenVal) {
1258
1260
  const { result: rendered, scope: branchScope } = createScope(() => {
1259
1261
  const branch = untrack(
@@ -1261,41 +1263,41 @@ function renderVNode(node, instance) {
1261
1263
  );
1262
1264
  return untrack(() => branch ? renderVNode(branch, instance) : null);
1263
1265
  });
1264
- currentScope = branchScope;
1266
+ currentScope2 = branchScope;
1265
1267
  if (rendered) {
1266
- const parent = endAnchor.parentNode || container;
1267
- parent.insertBefore(rendered, endAnchor);
1268
- currentNodes.push(rendered);
1268
+ const parent = endAnchor2.parentNode || container2;
1269
+ parent.insertBefore(rendered, endAnchor2);
1270
+ currentNodes2.push(rendered);
1269
1271
  }
1270
1272
  } else if (vnode.props.fallback) {
1271
1273
  const { result: rendered, scope: branchScope } = createScope(() => {
1272
1274
  return untrack(() => renderVNode(vnode.props.fallback, instance));
1273
1275
  });
1274
- currentScope = branchScope;
1276
+ currentScope2 = branchScope;
1275
1277
  if (rendered) {
1276
- const parent = endAnchor.parentNode || container;
1277
- parent.insertBefore(rendered, endAnchor);
1278
- currentNodes.push(rendered);
1278
+ const parent = endAnchor2.parentNode || container2;
1279
+ parent.insertBefore(rendered, endAnchor2);
1280
+ currentNodes2.push(rendered);
1279
1281
  }
1280
1282
  }
1281
1283
  }, {
1282
1284
  name: `control:show:${instance?.id || "root"}`,
1283
1285
  kind: "dom_binding"
1284
1286
  });
1285
- return container;
1287
+ return container2;
1286
1288
  }
1287
1289
  if (vnode.type === For) {
1288
- const container = document.createDocumentFragment();
1289
- const startAnchor = document.createComment("agent-dom:for-start");
1290
- const endAnchor = document.createComment("agent-dom:for-end");
1291
- container.appendChild(startAnchor);
1292
- container.appendChild(endAnchor);
1290
+ const container2 = document.createDocumentFragment();
1291
+ const startAnchor2 = document.createComment("agent-dom:for-start");
1292
+ const endAnchor2 = document.createComment("agent-dom:for-end");
1293
+ container2.appendChild(startAnchor2);
1294
+ container2.appendChild(endAnchor2);
1293
1295
  let currentMap = /* @__PURE__ */ new Map();
1294
1296
  effect(() => {
1295
1297
  const rawItems = typeof vnode.props.each === "function" ? vnode.props.each() : vnode.props.each || [];
1296
1298
  const items = Array.isArray(rawItems) ? rawItems : [];
1297
1299
  const newMap = /* @__PURE__ */ new Map();
1298
- const parent = endAnchor.parentNode || container;
1300
+ const parent = endAnchor2.parentNode || container2;
1299
1301
  items.forEach((item, idx) => {
1300
1302
  let itemKey;
1301
1303
  if (typeof vnode.props.key === "function") {
@@ -1310,16 +1312,16 @@ function renderVNode(node, instance) {
1310
1312
  existing.indexSignal.value = idx;
1311
1313
  newMap.set(itemKey, existing);
1312
1314
  currentMap.delete(itemKey);
1313
- parent.insertBefore(existing.node, endAnchor);
1315
+ parent.insertBefore(existing.node, endAnchor2);
1314
1316
  } else {
1315
1317
  const indexSignal = signal(idx);
1316
1318
  const { result: rendered, scope: itemScope } = createScope(() => {
1317
- const childVNode2 = untrack(() => vnode.props.children(item, () => indexSignal.value));
1318
- return untrack(() => renderVNode(childVNode2, instance));
1319
+ const childVNode = untrack(() => vnode.props.children(item, () => indexSignal.value));
1320
+ return untrack(() => renderVNode(childVNode, instance));
1319
1321
  });
1320
1322
  existing = { key: itemKey, node: rendered, indexSignal, scope: itemScope };
1321
1323
  newMap.set(itemKey, existing);
1322
- parent.insertBefore(rendered, endAnchor);
1324
+ parent.insertBefore(rendered, endAnchor2);
1323
1325
  }
1324
1326
  });
1325
1327
  for (const [_, item] of currentMap) {
@@ -1335,7 +1337,7 @@ function renderVNode(node, instance) {
1335
1337
  name: `control:for:${instance?.id || "root"}`,
1336
1338
  kind: "dom_binding"
1337
1339
  });
1338
- return container;
1340
+ return container2;
1339
1341
  }
1340
1342
  if (targetType === ErrorBoundary) {
1341
1343
  try {
@@ -1351,11 +1353,70 @@ function renderVNode(node, instance) {
1351
1353
  return renderVNode(vnode.props.fallback(err), instance);
1352
1354
  }
1353
1355
  }
1354
- let childVNode = targetType(vnode.props);
1355
- if (typeof childVNode === "function") {
1356
- childVNode = childVNode();
1356
+ const container = document.createDocumentFragment();
1357
+ const compName = targetType.name || "Component";
1358
+ const startAnchor = document.createComment(`agent-dom:${compName}-start`);
1359
+ const endAnchor = document.createComment(`agent-dom:${compName}-end`);
1360
+ container.appendChild(startAnchor);
1361
+ container.appendChild(endAnchor);
1362
+ let currentNodes = [];
1363
+ let currentScope = null;
1364
+ let isInitial = true;
1365
+ const stop = effect(() => {
1366
+ if (currentScope) {
1367
+ currentScope.dispose();
1368
+ currentScope = null;
1369
+ }
1370
+ const { result: rawChild, scope: compScope } = createScope(() => {
1371
+ let res = targetType(vnode.props);
1372
+ if (typeof res === "function") {
1373
+ res = res();
1374
+ }
1375
+ return res;
1376
+ });
1377
+ currentScope = compScope;
1378
+ let rendered = null;
1379
+ if (rawChild !== null && rawChild !== void 0 && typeof rawChild !== "boolean") {
1380
+ rendered = untrack(() => renderVNode(rawChild, instance));
1381
+ }
1382
+ if (isInitial) {
1383
+ if (rendered) {
1384
+ if (rendered instanceof DocumentFragment) {
1385
+ currentNodes = Array.from(rendered.childNodes);
1386
+ } else {
1387
+ currentNodes = [rendered];
1388
+ }
1389
+ container.insertBefore(rendered, endAnchor);
1390
+ } else {
1391
+ currentNodes = [];
1392
+ }
1393
+ isInitial = false;
1394
+ } else {
1395
+ const parent = endAnchor.parentNode;
1396
+ if (!parent) return;
1397
+ for (const n of currentNodes) {
1398
+ if (n.parentNode === parent) {
1399
+ parent.removeChild(n);
1400
+ }
1401
+ }
1402
+ currentNodes = [];
1403
+ if (rendered) {
1404
+ if (rendered instanceof DocumentFragment) {
1405
+ currentNodes = Array.from(rendered.childNodes);
1406
+ } else {
1407
+ currentNodes = [rendered];
1408
+ }
1409
+ parent.insertBefore(rendered, endAnchor);
1410
+ }
1411
+ }
1412
+ }, {
1413
+ name: `component:${compName}`,
1414
+ kind: "dom_binding"
1415
+ });
1416
+ if (instance && instance._cleanups) {
1417
+ instance._cleanups.add(stop);
1357
1418
  }
1358
- return renderVNode(childVNode, instance);
1419
+ return container;
1359
1420
  }
1360
1421
  const tagName = typeof vnode.type === "string" ? vnode.type : String(vnode.type);
1361
1422
  const isSvg = SVG_TAGS.has(tagName.toLowerCase());
@@ -2111,6 +2172,74 @@ function defineAsyncCrudComponent(options) {
2111
2172
  render
2112
2173
  });
2113
2174
  }
2175
+ function ReactBridge({
2176
+ component: Component,
2177
+ props = {},
2178
+ className = "",
2179
+ class: cls = "",
2180
+ wrapperProps = {}
2181
+ }) {
2182
+ let rootInstance = null;
2183
+ const combinedClass = `${cls} ${className}`.trim();
2184
+ const handleRef = (el) => {
2185
+ if (!el) {
2186
+ if (rootInstance) {
2187
+ try {
2188
+ rootInstance.unmount();
2189
+ } catch {
2190
+ }
2191
+ rootInstance = null;
2192
+ }
2193
+ return;
2194
+ }
2195
+ try {
2196
+ const React = globalThis.React || typeof window !== "undefined" && window.React;
2197
+ const ReactDOMClient = globalThis.ReactDOM || typeof window !== "undefined" && window.ReactDOM;
2198
+ if (ReactDOMClient && typeof ReactDOMClient.createRoot === "function") {
2199
+ if (!rootInstance) {
2200
+ rootInstance = ReactDOMClient.createRoot(el);
2201
+ }
2202
+ rootInstance.render(React ? React.createElement(Component, props) : Component(props));
2203
+ } else {
2204
+ const dynamicImport = new Function("m", "return import(m)");
2205
+ dynamicImport("react-dom/client").then(({ createRoot: createRoot2 }) => {
2206
+ dynamicImport("react").then((ReactModule) => {
2207
+ if (!rootInstance) {
2208
+ rootInstance = createRoot2(el);
2209
+ }
2210
+ rootInstance.render(ReactModule.createElement(Component, props));
2211
+ }).catch(() => {
2212
+ if (!rootInstance) {
2213
+ rootInstance = createRoot2(el);
2214
+ }
2215
+ rootInstance.render(Component(props));
2216
+ });
2217
+ }).catch((err) => {
2218
+ console.warn("[TokenSafe ReactBridge Warning]: react-dom/client could not be loaded:", err);
2219
+ });
2220
+ }
2221
+ } catch (err) {
2222
+ console.error("[TokenSafe ReactBridge Error]:", err);
2223
+ }
2224
+ };
2225
+ return h("div", {
2226
+ ref: handleRef,
2227
+ class: combinedClass || "tokensafe-react-bridge",
2228
+ ...wrapperProps
2229
+ });
2230
+ }
2231
+ function createUseSignal(useSyncExternalStore) {
2232
+ return function useSignal(sig) {
2233
+ if (!sig || typeof sig.subscribe !== "function") {
2234
+ return sig?.value;
2235
+ }
2236
+ return useSyncExternalStore(
2237
+ (notify) => sig.subscribe(notify),
2238
+ () => sig.value,
2239
+ () => sig.peek()
2240
+ );
2241
+ };
2242
+ }
2114
2243
  var VERSION = "0.2.0";
2115
2244
  // Annotate the CommonJS export names for ESM import in node:
2116
2245
  0 && (module.exports = {
@@ -2119,6 +2248,7 @@ var VERSION = "0.2.0";
2119
2248
  For,
2120
2249
  Fragment,
2121
2250
  GLOBAL_KEYS,
2251
+ ReactBridge,
2122
2252
  ReactiveScopeImpl,
2123
2253
  Show,
2124
2254
  SignalImpl,
@@ -2130,6 +2260,7 @@ var VERSION = "0.2.0";
2130
2260
  computed,
2131
2261
  createRoot,
2132
2262
  createScope,
2263
+ createUseSignal,
2133
2264
  defineAsyncCrudComponent,
2134
2265
  defineComponent,
2135
2266
  effect,