eclipsa 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.
@@ -1870,7 +1870,7 @@ const parseInsertMarker = (value) => {
1870
1870
  };
1871
1871
  //#endregion
1872
1872
  //#region core/runtime/serialization.ts
1873
- const createRuntimeSerialization = ({ createProjectionSlot, ensureRouterState, ensureRuntimeElementId, evaluateProps, findRuntimeElement, getResolvedRuntimeSymbols, isPlainObject, isProjectionSlot, isRenderObject, isRouteSlot, loadSymbol, materializeScope, materializeSymbolReference, registerScope, registerSerializedScope, resolveRenderable }) => {
1873
+ const createRuntimeSerialization = ({ createProjectionSlot, ensureRouterState, ensureRuntimeElementId, evaluateProps, findRuntimeElement, getResolvedRuntimeSymbols, isPlainObject, isProjectionSlot, isRenderObject, isRouteSlot, loadSymbol, materializeComputedSignalReference, materializeScope, materializeSymbolReference, registerScope, registerSerializedScope, resolveRenderable }) => {
1874
1874
  const getRenderComponentTypeRef = (value) => {
1875
1875
  if (typeof value !== "function") return null;
1876
1876
  return value[RENDER_COMPONENT_TYPE_KEY] ?? null;
@@ -1994,7 +1994,7 @@ const createRuntimeSerialization = ({ createProjectionSlot, ensureRouterState, e
1994
1994
  const signalMeta = getSignalMeta(candidate);
1995
1995
  if (signalMeta) return {
1996
1996
  __eclipsa_type: "ref",
1997
- kind: "signal",
1997
+ kind: signalMeta.kind === "computed-signal" ? "computed-signal" : "signal",
1998
1998
  token: signalMeta.id
1999
1999
  };
2000
2000
  if (getNavigateMeta(candidate)) return {
@@ -2128,6 +2128,7 @@ const createRuntimeSerialization = ({ createProjectionSlot, ensureRouterState, e
2128
2128
  if (!record) throw new Error(`Missing signal ${reference.token}.`);
2129
2129
  return record.handle;
2130
2130
  }
2131
+ if (reference.kind === "computed-signal") return materializeComputedSignalReference(container, reference.token);
2131
2132
  if (reference.kind === "symbol") {
2132
2133
  if (!reference.data || !Array.isArray(reference.data)) throw new TypeError("Symbol references require an encoded scope array.");
2133
2134
  const scopeId = registerSerializedScope(container, reference.data);
@@ -2373,6 +2374,7 @@ const getRuntimeSerialization = () => {
2373
2374
  isRenderObject,
2374
2375
  isRouteSlot,
2375
2376
  loadSymbol,
2377
+ materializeComputedSignalReference,
2376
2378
  materializeScope,
2377
2379
  materializeSymbolReference,
2378
2380
  registerScope,
@@ -2394,8 +2396,15 @@ const findNextNumericId = (ids, prefix) => {
2394
2396
  }
2395
2397
  return nextId;
2396
2398
  };
2397
- const getRefSignalId = (value) => getSignalMeta(value)?.id ?? null;
2398
- const getBindableSignalId = (value) => getSignalMeta(value)?.id ?? null;
2399
+ const isWritableSignalMeta = (meta) => !!meta && meta.kind !== "computed-signal";
2400
+ const getRefSignalId = (value) => {
2401
+ const signalMeta = getSignalMeta(value);
2402
+ return isWritableSignalMeta(signalMeta) ? signalMeta.id : null;
2403
+ };
2404
+ const getBindableSignalId = (value) => {
2405
+ const signalMeta = getSignalMeta(value);
2406
+ return isWritableSignalMeta(signalMeta) ? signalMeta.id : null;
2407
+ };
2399
2408
  const syncRuntimeRefMarker = (element, value) => {
2400
2409
  const signalId = getRefSignalId(value);
2401
2410
  if (signalId) {
@@ -2412,7 +2421,7 @@ const readBindableSignalValue = (value) => {
2412
2421
  };
2413
2422
  const assignRuntimeRef = (value, element, container = getCurrentContainer()) => {
2414
2423
  const signalMeta = getSignalMeta(value);
2415
- if (!signalMeta) return false;
2424
+ if (!isWritableSignalMeta(signalMeta)) return false;
2416
2425
  const record = container?.signals.get(signalMeta.id);
2417
2426
  if (record) {
2418
2427
  writeSignalValue(container, record, element);
@@ -2567,12 +2576,41 @@ const createSignalHandle = (record, container) => {
2567
2576
  setSignalMeta(handle, {
2568
2577
  get: () => record.value,
2569
2578
  id: record.id,
2579
+ kind: "signal",
2570
2580
  set: (value) => {
2571
2581
  writeSignalValue(container, record, value);
2572
2582
  }
2573
2583
  });
2574
2584
  return handle;
2575
2585
  };
2586
+ const isComputedSignalSnapshot = (value) => !!value && typeof value === "object" && value.__e_async_computed === true;
2587
+ const readComputedSignalValue = (record) => {
2588
+ recordSignalRead(record);
2589
+ const snapshot = record.value;
2590
+ if (!isComputedSignalSnapshot(snapshot)) return snapshot;
2591
+ if (snapshot.status === "pending") throw createPendingSignalError(snapshot.promise ?? Promise.resolve(void 0));
2592
+ if (snapshot.status === "rejected") throw snapshot.error;
2593
+ return snapshot.value;
2594
+ };
2595
+ const createComputedSignalHandle = (record, _container) => {
2596
+ const handle = {};
2597
+ Object.defineProperty(handle, "value", {
2598
+ configurable: true,
2599
+ enumerable: true,
2600
+ get() {
2601
+ return readComputedSignalValue(record);
2602
+ }
2603
+ });
2604
+ setSignalMeta(handle, {
2605
+ get: () => readComputedSignalValue(record),
2606
+ id: record.id,
2607
+ kind: "computed-signal",
2608
+ set: () => {
2609
+ throw new TypeError("Computed signals are read-only.");
2610
+ }
2611
+ });
2612
+ return handle;
2613
+ };
2576
2614
  const isPrimitiveSignalValue = (value) => value === null || typeof value !== "object" && typeof value !== "function";
2577
2615
  const didSignalValueChange = (previous, next) => {
2578
2616
  if (isPrimitiveSignalValue(previous) && isPrimitiveSignalValue(next)) return !Object.is(previous, next);
@@ -2742,6 +2780,10 @@ const pushContainer = (container, fn) => {
2742
2780
  }
2743
2781
  };
2744
2782
  const withRuntimeContainer = pushContainer;
2783
+ const runReactiveEffectInContainer = (effect, fn) => {
2784
+ if (!effect.container) return fn();
2785
+ return pushContainer(effect.container, fn);
2786
+ };
2745
2787
  const withRuntimeContextValue = (token, value, fn) => {
2746
2788
  const stack = getContextValueStack();
2747
2789
  stack.push({
@@ -2797,6 +2839,11 @@ const materializeSymbolReference = (container, symbolId, scopeId) => {
2797
2839
  });
2798
2840
  return fn;
2799
2841
  };
2842
+ const materializeComputedSignalReference = (container, signalId) => {
2843
+ const record = container.signals.get(signalId);
2844
+ if (!record) throw new Error(`Missing signal ${signalId}.`);
2845
+ return createComputedSignalHandle(record, container);
2846
+ };
2800
2847
  const materializeScope = (container, scopeId) => {
2801
2848
  const slots = container.scopes.get(scopeId);
2802
2849
  if (!slots) throw new Error(`Missing scope ${scopeId}.`);
@@ -2892,6 +2939,7 @@ const getOrCreateWatchState = (container, id, componentId) => {
2892
2939
  return existing;
2893
2940
  }
2894
2941
  const effect = {
2942
+ container,
2895
2943
  fn() {},
2896
2944
  signals: /* @__PURE__ */ new Set()
2897
2945
  };
@@ -5477,6 +5525,32 @@ const collectResumeHmrBoundaryIds = (container, symbolIds) => {
5477
5525
  }
5478
5526
  return result;
5479
5527
  };
5528
+ const rewriteSerializedSymbolReferenceToken = (value, affectedIds, nextSymbolId) => {
5529
+ if (Array.isArray(value)) {
5530
+ for (const entry of value) rewriteSerializedSymbolReferenceToken(entry, affectedIds, nextSymbolId);
5531
+ return;
5532
+ }
5533
+ if (!value || typeof value !== "object" || !("__eclipsa_type" in value)) return;
5534
+ switch (value.__eclipsa_type) {
5535
+ case "object":
5536
+ for (const [, entry] of value.entries) rewriteSerializedSymbolReferenceToken(entry, affectedIds, nextSymbolId);
5537
+ return;
5538
+ case "map":
5539
+ for (const [key, entry] of value.entries) {
5540
+ rewriteSerializedSymbolReferenceToken(key, affectedIds, nextSymbolId);
5541
+ rewriteSerializedSymbolReferenceToken(entry, affectedIds, nextSymbolId);
5542
+ }
5543
+ return;
5544
+ case "set":
5545
+ for (const entry of value.entries) rewriteSerializedSymbolReferenceToken(entry, affectedIds, nextSymbolId);
5546
+ return;
5547
+ case "ref":
5548
+ if (value.kind === "symbol" && affectedIds.has(value.token)) value.token = nextSymbolId;
5549
+ if (value.data !== void 0) rewriteSerializedSymbolReferenceToken(value.data, affectedIds, nextSymbolId);
5550
+ return;
5551
+ default: return;
5552
+ }
5553
+ };
5480
5554
  const applyResumeHmrSymbolReplacements = (container, replacements) => {
5481
5555
  for (const [oldSymbolId, url] of Object.entries(replacements)) {
5482
5556
  const currentUrl = container.symbols.get(oldSymbolId);
@@ -5491,6 +5565,7 @@ const applyResumeHmrSymbolReplacements = (container, replacements) => {
5491
5565
  for (const component of container.components.values()) if (affectedIds.has(component.symbol)) component.symbol = nextSymbolId;
5492
5566
  for (const watch of container.watches.values()) if (affectedIds.has(watch.symbol)) watch.symbol = nextSymbolId;
5493
5567
  for (const visible of container.visibles.values()) if (affectedIds.has(visible.symbol)) visible.symbol = nextSymbolId;
5568
+ for (const slots of container.scopes.values()) for (const slot of slots) rewriteSerializedSymbolReferenceToken(slot, affectedIds, nextSymbolId);
5494
5569
  container.symbols.set(nextSymbolId, url);
5495
5570
  invalidateRuntimeSymbolCaches(container, [nextSymbolId]);
5496
5571
  }
@@ -6238,7 +6313,10 @@ const useRuntimeSignal = (fallback) => {
6238
6313
  };
6239
6314
  const createDetachedRuntimeSignal = (container, id, fallback) => ensureSignalRecord(container, id, fallback).handle;
6240
6315
  const getRuntimeComponentId = () => getCurrentFrame()?.component.id ?? null;
6241
- const getRuntimeSignalId = (value) => getSignalMeta(value)?.id ?? null;
6316
+ const getRuntimeSignalId = (value) => {
6317
+ const signalMeta = getSignalMeta(value);
6318
+ return isWritableSignalMeta(signalMeta) ? signalMeta.id : null;
6319
+ };
6242
6320
  const useRuntimeNavigate = () => {
6243
6321
  const container = getCurrentContainer();
6244
6322
  if (!container) return createStandaloneNavigate();
@@ -6273,22 +6351,26 @@ const notFound = () => {
6273
6351
  };
6274
6352
  const isRouteNotFoundError = (error) => !!error && typeof error === "object" && (error.__eclipsa_not_found__ === true || error[ROUTE_NOT_FOUND_KEY] === true);
6275
6353
  const createEffect = (fn, options) => {
6354
+ const container = getCurrentContainer();
6276
6355
  const frame = getCurrentFrame();
6277
6356
  const effect = {
6357
+ container,
6278
6358
  fn() {
6279
- const dependencies = options?.dependencies;
6280
- if (!dependencies) {
6281
- collectTrackedDependencies(effect, fn);
6282
- return;
6283
- }
6284
- collectTrackedDependencies(effect, () => {
6285
- trackWatchDependencies(dependencies, options?.errorLabel);
6359
+ runReactiveEffectInContainer(effect, () => {
6360
+ const dependencies = options?.dependencies;
6361
+ if (!dependencies) {
6362
+ collectTrackedDependencies(effect, fn);
6363
+ return;
6364
+ }
6365
+ collectTrackedDependencies(effect, () => {
6366
+ trackWatchDependencies(dependencies, options?.errorLabel);
6367
+ });
6368
+ if (options?.untracked) {
6369
+ runWithoutDependencyTracking(fn);
6370
+ return;
6371
+ }
6372
+ fn();
6286
6373
  });
6287
- if (options?.untracked) {
6288
- runWithoutDependencyTracking(fn);
6289
- return;
6290
- }
6291
- fn();
6292
6374
  },
6293
6375
  signals: /* @__PURE__ */ new Set()
6294
6376
  };
@@ -6326,8 +6408,11 @@ const createWatch = (fn, dependencies) => {
6326
6408
  if (!container || !frame || frame.component.id === "$root" || !watchMeta) {
6327
6409
  const cleanupSlot = createCleanupSlot();
6328
6410
  const effect = {
6411
+ container,
6329
6412
  fn() {
6330
- createLocalWatchRunner(effect, cleanupSlot, fn, dependencies)();
6413
+ runReactiveEffectInContainer(effect, () => {
6414
+ createLocalWatchRunner(effect, cleanupSlot, fn, dependencies)();
6415
+ });
6331
6416
  },
6332
6417
  signals: /* @__PURE__ */ new Set()
6333
6418
  };
@@ -6963,4 +7048,4 @@ const __eclipsaAction = (id, middlewares, handler) => {
6963
7048
  //#endregion
6964
7049
  export { shouldReconnectDetachedInsertMarkers as $, deserializeValue as $n, __eclipsaLoader as $t, getRuntimeComponentId as A, createPendingSignalError as An, getActionHookMeta as At, refreshRegisteredRouteContainers as B, createRequestFetch as Bn, getRegisteredLoaderHook as Bt, createOnCleanup as C, createContext as Cn, RESUME_FINAL_STATE_ELEMENT_ID as Ct, createStandaloneRuntimeSignal as D, materializeRuntimeContextProvider as Dn, __eclipsaLazy as Dt, createResumeContainer as E, materializeRuntimeContext as En, __eclipsaEvent as Et, notFound as F, applyActionCsrfCookie as Fn, getLoaderHandleMeta as Ft, renderSSRAttr as G, registerClientHooks as Gn, registerLoaderHook as Gt, registerRuntimeScopedStyle as H, getClientHooks as Hn, getSignalMeta as Ht, preserveReusableContentInRoots as I, ensureActionCsrfToken as In, getLoaderHookMeta as It, renderString as J, runHandleError as Jn, setExternalComponentMeta as Jt, renderSSRMap as K, resetClientHooks as Kn, setActionHandleMeta as Kt, primeLocationState as L, readActionCsrfTokenFromDocument as Ln, getNavigateMeta as Lt, getRuntimeSignalId as M, isSuspenseType as Mn, getEventMeta as Mt, getStreamingResumeBootstrapScriptContent as N, ACTION_CSRF_FIELD as Nn, getExternalComponentMeta as Nt, createWatch as O, useContext as On, __eclipsaWatch as Ot, installResumeListeners as P, ACTION_CSRF_INPUT_ATTR as Pn, getLazyMeta as Pt, restoreSignalRefs as Q, withServerRequestContext as Qn, setSignalMeta as Qt, primeRouteModules as R, APP_HOOKS_ELEMENT_ID as Rn, getRegisteredActionHook as Rt, createEffect as S, resolveRouteMetadata as Sn, ACTION_FORM_ATTR$1 as St, createOnVisible as T, getRuntimeContextReference as Tn, __eclipsaComponent as Tt, renderClientInsertable as U, getCurrentServerRequestContext as Un, getWatchMeta as Ut, registerResumeContainer as V, deserializePublicValue as Vn, getRegisteredLoaderHookIds as Vt, renderClientInsertableForOwner as W, markPublicError as Wn, registerActionHook as Wt, restoreResumedExternalComponents as X, toPublicError as Xn, setLoaderHookMeta as Xt, restoreRegisteredRpcHandles as Y, serializePublicValue as Yn, setLoaderHandleMeta as Yt, restoreResumedLocalSignalEffects as Z, transformCurrentPublicError as Zn, setNavigateMeta as Zt, beginSSRContainer as _, ROUTE_REPLACE_ATTR as _n, getRememberedInsertMarkerNodeCount as _t, action as a, loader_exports as an, IS_BROWSER as ar, useRuntimeLocation as at, collectPendingSuspenseBoundaryIds as b, composeRouteMetadata as bn, rememberManagedAttributesForNodes as bt, getActionFormSubmissionId as c, registerLoader as cn, noSerialize as cr, useRuntimeRouteParams as ct, primeActionState as d, ROUTE_DATA_REQUEST_HEADER as dn, writeAsyncSignalSnapshot as dt, consumePendingSsrLoaderIds as en, escapeInlineScriptText as er, syncRuntimeRefMarker as et, registerAction as f, ROUTE_LINK_ATTR as fn, INSERT_MARKER_PREFIX as ft, beginAsyncSSRContainer as g, ROUTE_PREFLIGHT_REQUEST_HEADER as gn, parseInsertMarker as gt, assignRuntimeRef as h, ROUTE_PREFLIGHT_ENDPOINT as hn, parseComponentBoundaryMarker as ht, __eclipsaAction as i, loader as in, serializeValue as ir, tryPatchNodeSequenceInPlace as it, getRuntimeContainer as j, isPendingSignalError as jn, getComponentMeta as jt, getResumePayloadScriptContent as k, Suspense as kn, getActionHandleMeta as kt, getNormalizedActionInput as l, resolvePendingLoaders as ln, useRuntimeSignal as lt, applyResumeHmrUpdateToRegisteredContainers as m, ROUTE_PREFETCH_ATTR as mn, createInsertMarker as mt, ACTION_FORM_ATTR as n, hasLoader as nn, parseSerializedJSON as nr, toResumePayloadSubset as nt, executeAction as o, markPendingSsrLoader as on, IS_SSR as or, useRuntimeNavigate as ot, validator as p, ROUTE_MANIFEST_ELEMENT_ID as pn, createComponentBoundaryHtmlComment as pt, renderSSRValue as q, resolveReroute as qn, setActionHookMeta as qt, ACTION_FORM_FIELD as r, isPendingSsrLoaderError as rn, serializeJSONScriptContent as rr, tryPatchElementShellInPlace as rt, executeActionSubmission as s, primeLoaderState as sn, isNoSerialize as sr, useRuntimeRouteError as st, ACTION_CONTENT_TYPE as t, executeLoader as tn, escapeJSONScriptText as tr, toResumePayload as tt, hasAction as u, ROUTE_DATA_ENDPOINT as un, withRuntimeContainer as ut, bindRuntimeEvent as v, ROUTE_RPC_URL_HEADER as vn, rememberInsertMarkerRange as vt, createOnMount as w, getContextProviderMeta as wn, RESUME_STATE_ELEMENT_ID as wt, createDetachedClientInsertOwner as x, renderRouteMetadataHead as xn, syncManagedAttributeSnapshot as xt, captureClientInsertOwner as y, ROUTE_METADATA_HEAD_ATTR as yn, rememberManagedAttributesForNode as yt, readAsyncSignalSnapshot as z, attachRequestFetch as zn, getRegisteredActionHookIds as zt };
6965
7050
 
6966
- //# sourceMappingURL=action-CArGTCnQ.mjs.map
7051
+ //# sourceMappingURL=action-BcEktMN2.mjs.map