@lytjs/component 6.7.0 → 6.8.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.
package/dist/index.mjs CHANGED
@@ -1320,6 +1320,73 @@ function abortSuspense(boundary) {
1320
1320
  boundary.onPending.length = 0;
1321
1321
  boundary.onError.length = 0;
1322
1322
  }
1323
+ function useSuspense(promise, _key) {
1324
+ const instance = getCurrentInstance();
1325
+ if (!instance) {
1326
+ throw new Error("useSuspense must be called within a component setup function");
1327
+ }
1328
+ let boundary = findNearestSuspenseBoundary(instance);
1329
+ if (!boundary) {
1330
+ boundary = createSuspenseBoundary();
1331
+ }
1332
+ registerAsyncChild(boundary, promise);
1333
+ return void 0;
1334
+ }
1335
+ function findNearestSuspenseBoundary(instance) {
1336
+ let current = instance;
1337
+ while (current) {
1338
+ if (current.type === Suspense) {
1339
+ const setupState = current.setupState;
1340
+ if (setupState?.boundary) {
1341
+ return setupState.boundary;
1342
+ }
1343
+ }
1344
+ current = current.parent;
1345
+ }
1346
+ return null;
1347
+ }
1348
+ function startTransition(callback) {
1349
+ try {
1350
+ callback();
1351
+ } finally {
1352
+ }
1353
+ }
1354
+ var SuspenseResource = class {
1355
+ constructor(factory) {
1356
+ this.status = "pending";
1357
+ this.value = null;
1358
+ this.error = null;
1359
+ this.promise = null;
1360
+ this.load(factory);
1361
+ }
1362
+ load(factory) {
1363
+ this.status = "pending";
1364
+ this.promise = factory().then((result) => {
1365
+ this.value = result;
1366
+ this.status = "success";
1367
+ return result;
1368
+ }).catch((err) => {
1369
+ this.error = err instanceof Error ? err : new Error(String(err));
1370
+ this.status = "error";
1371
+ throw this.error;
1372
+ });
1373
+ }
1374
+ read() {
1375
+ if (this.status === "success") {
1376
+ return this.value;
1377
+ }
1378
+ if (this.status === "error") {
1379
+ throw this.error;
1380
+ }
1381
+ throw this.promise;
1382
+ }
1383
+ refresh(factory) {
1384
+ this.load(factory);
1385
+ }
1386
+ };
1387
+ function createSuspenseResource(factory) {
1388
+ return new SuspenseResource(factory);
1389
+ }
1323
1390
 
1324
1391
  // src/transition.ts
1325
1392
  var Transition = {
@@ -1755,7 +1822,11 @@ function inject2(key, options) {
1755
1822
  const actualKey = isInjectionToken(key) ? key.__token : key;
1756
1823
  const lookupKey = actualKey;
1757
1824
  if (instance) {
1758
- const result = injectFromInstance(instance, lookupKey, options);
1825
+ const result = injectFromInstance(
1826
+ instance,
1827
+ lookupKey,
1828
+ options
1829
+ );
1759
1830
  if (result !== void 0) {
1760
1831
  return result;
1761
1832
  }
@@ -1860,6 +1931,6 @@ function withProviderScope(fn) {
1860
1931
  }
1861
1932
  }
1862
1933
 
1863
- export { ErrorBoundary, InjectionError, InjectionToken, KeepAlive, PUBLIC_PROPERTIES_MAP, Suspense, Teleport, Transition, TransitionGroup, abortSuspense, activateInstance, cacheInstance, callCreatedHook, callLifecycleHook, callMountedHook, callUnmountedHook, callUpdatedHook, clearPreloadCache, createAppContext, createComponentInstance, createComponentPublicInstance, createComputedState, createKeepAliveInstance, createSignalState, createSuspenseBoundary, createSuspenseInstance, deactivateInstance, defineAsyncComponent, defineComponent, defineFunctionalComponent, emit, enterProviderScope, exitProviderScope, finishComponentSetup, getCacheKey, getCachedInstance, getCurrentInstance, getCurrentProviderNode, getProviderRoot, getSuspenseError, handleError, initProps, initSlots, inject, isComponentPreloaded, isEmitValid, isInjectionToken, isSuspensePending, linkSuspenseBoundary, matchesPattern, normalizeEmitsOptions, normalizePropsOptions, normalizeSlotValue, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, preloadComponent, preloadComponents, provide, provideAll, provideScoped, provideSingleton, provideTransient, registerAsyncChild, removeCachedInstance, resolvePropValue, resolveSuspense, setCurrentInstance, setupComponent, validateType, withProviderScope };
1934
+ export { ErrorBoundary, InjectionError, InjectionToken, KeepAlive, PUBLIC_PROPERTIES_MAP, Suspense, SuspenseResource, Teleport, Transition, TransitionGroup, abortSuspense, activateInstance, cacheInstance, callCreatedHook, callLifecycleHook, callMountedHook, callUnmountedHook, callUpdatedHook, clearPreloadCache, createAppContext, createComponentInstance, createComponentPublicInstance, createComputedState, createKeepAliveInstance, createSignalState, createSuspenseBoundary, createSuspenseInstance, createSuspenseResource, deactivateInstance, defineAsyncComponent, defineComponent, defineFunctionalComponent, emit, enterProviderScope, exitProviderScope, finishComponentSetup, getCacheKey, getCachedInstance, getCurrentInstance, getCurrentProviderNode, getProviderRoot, getSuspenseError, handleError, initProps, initSlots, inject, isComponentPreloaded, isEmitValid, isInjectionToken, isSuspensePending, linkSuspenseBoundary, matchesPattern, normalizeEmitsOptions, normalizePropsOptions, normalizeSlotValue, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, preloadComponent, preloadComponents, provide, provideAll, provideScoped, provideSingleton, provideTransient, registerAsyncChild, removeCachedInstance, resolvePropValue, resolveSuspense, setCurrentInstance, setupComponent, startTransition, useSuspense, validateType, withProviderScope };
1864
1935
  //# sourceMappingURL=index.mjs.map
1865
1936
  //# sourceMappingURL=index.mjs.map