@sigx/terminal 0.1.24 → 0.1.25

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.js CHANGED
@@ -665,6 +665,59 @@ function component(setup, options) {
665
665
  getComponentPlugins().forEach((p) => p.onDefine?.(options?.name, factory, setup));
666
666
  return factory;
667
667
  }
668
+ var SigxError = class extends Error {
669
+ constructor(message, options) {
670
+ super(message);
671
+ this.name = "SigxError";
672
+ this.code = options.code;
673
+ this.suggestion = options.suggestion;
674
+ if (options.cause) this.cause = options.cause;
675
+ }
676
+ };
677
+ const SigxErrorCode = {
678
+ NO_MOUNT_FUNCTION: "SIGX001",
679
+ RENDER_TARGET_NOT_FOUND: "SIGX100",
680
+ MOUNT_TARGET_NOT_FOUND: "SIGX101",
681
+ ASYNC_SETUP_CLIENT: "SIGX102",
682
+ PROVIDE_OUTSIDE_SETUP: "SIGX200",
683
+ PROVIDE_INVALID_INJECTABLE: "SIGX201"
684
+ };
685
+ function noMountFunctionError() {
686
+ return new SigxError("No mount function provided and no default mount function set.", {
687
+ code: SigxErrorCode.NO_MOUNT_FUNCTION,
688
+ suggestion: "Either pass a mount function to app.mount(), or import a platform package (e.g., @sigx/runtime-dom or @sigx/runtime-terminal) that sets the default."
689
+ });
690
+ }
691
+ function renderTargetNotFoundError(selector) {
692
+ return new SigxError(`Render target "${selector}" not found.`, {
693
+ code: SigxErrorCode.RENDER_TARGET_NOT_FOUND,
694
+ suggestion: `Make sure the element exists in your HTML: <div id="${selector.replace(/^#/, "")}"></div>`
695
+ });
696
+ }
697
+ function mountTargetNotFoundError(selector) {
698
+ return new SigxError(`Mount target "${selector}" not found.`, {
699
+ code: SigxErrorCode.MOUNT_TARGET_NOT_FOUND,
700
+ suggestion: `Make sure the element exists in your HTML: <div id="${selector.replace(/^#/, "")}"></div>`
701
+ });
702
+ }
703
+ function asyncSetupClientError(componentName) {
704
+ return new SigxError(`Async setup in component "${componentName}" is only supported during SSR.`, {
705
+ code: SigxErrorCode.ASYNC_SETUP_CLIENT,
706
+ suggestion: "On the client, use pre-loaded data from hydration or fetch in onMounted."
707
+ });
708
+ }
709
+ function provideOutsideSetupError() {
710
+ return new SigxError("defineProvide must be called inside a component setup function.", {
711
+ code: SigxErrorCode.PROVIDE_OUTSIDE_SETUP,
712
+ suggestion: "Move the defineProvide() call inside your component's setup function, or use app.defineProvide() at the app level."
713
+ });
714
+ }
715
+ function provideInvalidInjectableError() {
716
+ return new SigxError("defineProvide must be called with a function created by defineInjectable.", {
717
+ code: SigxErrorCode.PROVIDE_INVALID_INJECTABLE,
718
+ suggestion: "Create an injectable first:\n const useMyService = defineInjectable(() => new MyService());\n defineProvide(useMyService);"
719
+ });
720
+ }
668
721
  var globalInstances = /* @__PURE__ */ new Map();
669
722
  var appContextToken = Symbol("sigx:appContext");
670
723
  function lookupProvided(token) {
@@ -678,9 +731,10 @@ function lookupProvided(token) {
678
731
  }
679
732
  function provideAtComponent(token, value) {
680
733
  const ctx = getCurrentInstance();
681
- if (!ctx) throw new Error("defineProvide must be called inside a component setup function");
682
- if (!ctx.provides) ctx.provides = /* @__PURE__ */ new Map();
683
- ctx.provides.set(token, value);
734
+ if (!ctx) throw provideOutsideSetupError();
735
+ const node = ctx;
736
+ if (!node.provides) node.provides = /* @__PURE__ */ new Map();
737
+ node.provides.set(token, value);
684
738
  }
685
739
  function defineInjectable(factory) {
686
740
  const token = Symbol();
@@ -697,7 +751,7 @@ function defineInjectable(factory) {
697
751
  function defineProvide(useFn, factory) {
698
752
  const actualFactory = factory ?? useFn._factory;
699
753
  const token = useFn._token;
700
- if (!actualFactory || !token) throw new Error("defineProvide must be called with a function created by defineInjectable");
754
+ if (!actualFactory || !token) throw provideInvalidInjectableError();
701
755
  const instance = actualFactory();
702
756
  provideAtComponent(token, instance);
703
757
  return instance;
@@ -709,9 +763,10 @@ function getAppContextToken() {
709
763
  return appContextToken;
710
764
  }
711
765
  function provideAppContext(ctx, appContext) {
712
- if (!ctx.provides) ctx.provides = /* @__PURE__ */ new Map();
713
- ctx.provides.set(appContextToken, appContext);
714
- if (appContext.provides) for (const [token, value] of appContext.provides) ctx.provides.set(token, value);
766
+ const node = ctx;
767
+ if (!node.provides) node.provides = /* @__PURE__ */ new Map();
768
+ node.provides.set(appContextToken, appContext);
769
+ if (appContext.provides) for (const [token, value] of appContext.provides) node.provides.set(token, value);
715
770
  }
716
771
  const __DIRECTIVE__ = Symbol.for("sigx.directive");
717
772
  function defineDirective(definition) {
@@ -754,7 +809,7 @@ function defineApp(rootComponent) {
754
809
  defineProvide(useFn, factory) {
755
810
  const actualFactory = factory ?? useFn._factory;
756
811
  const token = useFn._token;
757
- if (!actualFactory || !token) throw new Error("defineProvide must be called with a function created by defineInjectable");
812
+ if (!actualFactory || !token) throw provideInvalidInjectableError();
758
813
  const instance = actualFactory();
759
814
  context.provides.set(token, instance);
760
815
  return instance;
@@ -777,7 +832,7 @@ function defineApp(rootComponent) {
777
832
  return app;
778
833
  }
779
834
  const mountFn = renderFn ?? defaultMountFn;
780
- if (!mountFn) throw new Error("No mount function provided and no default mount function set. Either pass a mount function to app.mount(), or import a platform package (e.g., @sigx/runtime-dom or @sigx/runtime-terminal) that sets the default.");
835
+ if (!mountFn) throw noMountFunctionError();
781
836
  container = target;
782
837
  isMounted = true;
783
838
  const result = mountFn(rootComponent, target, context);
@@ -1045,6 +1100,22 @@ function lazy(loader) {
1045
1100
  state,
1046
1101
  tick: 0
1047
1102
  });
1103
+ function renderInner(Comp) {
1104
+ const fwdProps = { ...ctx.props };
1105
+ const defaultContent = ctx.slots.default();
1106
+ if (defaultContent.length > 0) fwdProps.children = defaultContent;
1107
+ const slotsFromProps = ctx.slots._slotsFromProps;
1108
+ if (slotsFromProps) {
1109
+ const namedSlots = {};
1110
+ let hasNamed = false;
1111
+ for (const key of Object.keys(slotsFromProps)) {
1112
+ namedSlots[key] = slotsFromProps[key];
1113
+ hasNamed = true;
1114
+ }
1115
+ if (hasNamed) fwdProps.slots = namedSlots;
1116
+ }
1117
+ return jsx(Comp, fwdProps);
1118
+ }
1048
1119
  if (!promise) promise = loader().then((mod) => {
1049
1120
  Component = "default" in mod ? mod.default : mod;
1050
1121
  state = "resolved";
@@ -1073,15 +1144,13 @@ function lazy(loader) {
1073
1144
  loadState.tick++;
1074
1145
  });
1075
1146
  });
1076
- if (state === "resolved" && Component) return () => {
1077
- return jsx(Component, {});
1078
- };
1147
+ if (state === "resolved" && Component) return () => renderInner(Component);
1079
1148
  if (state === "rejected" && error) throw error;
1080
1149
  if (!registerPendingPromise(promise)) promise.catch(() => {});
1081
1150
  return () => {
1082
1151
  const currentState = loadState.state;
1083
1152
  loadState.tick;
1084
- if (currentState === "resolved" && Component) return jsx(Component, {});
1153
+ if (currentState === "resolved" && Component) return renderInner(Component);
1085
1154
  if (currentState === "rejected" && error) throw error;
1086
1155
  return null;
1087
1156
  };
@@ -1157,6 +1226,25 @@ const Suspense = component((ctx) => {
1157
1226
  function isLazyComponent(component) {
1158
1227
  return component && component.__lazy === true;
1159
1228
  }
1229
+ function useAsync(loader) {
1230
+ const state = signal({
1231
+ value: null,
1232
+ loading: true,
1233
+ error: null
1234
+ });
1235
+ loader().then((val) => {
1236
+ batch(() => {
1237
+ state.value = val;
1238
+ state.loading = false;
1239
+ });
1240
+ }).catch((err) => {
1241
+ batch(() => {
1242
+ state.error = err instanceof Error ? err : new Error(String(err));
1243
+ state.loading = false;
1244
+ });
1245
+ });
1246
+ return state;
1247
+ }
1160
1248
  const ErrorBoundary = component((ctx) => {
1161
1249
  const { fallback } = ctx.props;
1162
1250
  const { slots } = ctx;
@@ -1256,7 +1344,7 @@ function defineFactory(setup, _lifetime, _typeIdentifier) {
1256
1344
  const dispose = () => {
1257
1345
  deactivations.forEach((d) => d());
1258
1346
  subscriptions.unsubscribe();
1259
- result.dispose?.();
1347
+ if (result && typeof result === "object" && "dispose" in result && typeof result.dispose === "function") result.dispose();
1260
1348
  };
1261
1349
  if (customDispose) customDispose(dispose);
1262
1350
  else try {
@@ -1798,7 +1886,7 @@ function createRenderer(options) {
1798
1886
  let renderFn;
1799
1887
  try {
1800
1888
  const setupResult = setup(ctx);
1801
- if (setupResult && typeof setupResult.then === "function") throw new Error(`Async setup in component "${componentName}" is only supported during SSR. On the client, use pre-loaded data from hydration or fetch in onMounted.`);
1889
+ if (setupResult && typeof setupResult.then === "function") throw asyncSetupClientError(componentName ?? "anonymous");
1802
1890
  renderFn = setupResult;
1803
1891
  notifyComponentCreated(currentAppContext, componentInstance);
1804
1892
  createdHooks.forEach((hook) => hook());
@@ -1853,7 +1941,7 @@ function createRenderer(options) {
1853
1941
  };
1854
1942
  }
1855
1943
  const mountCtx = { el: container };
1856
- mountHooks.forEach((hook) => hook(mountCtx));
1944
+ untrack(() => mountHooks.forEach((hook) => hook(mountCtx)));
1857
1945
  notifyComponentMounted(currentAppContext, componentInstance);
1858
1946
  vnode.cleanup = () => {
1859
1947
  notifyComponentUnmounted(currentAppContext, componentInstance);
@@ -2425,6 +2513,6 @@ const terminalMount = (component, options, appContext) => {
2425
2513
  };
2426
2514
  };
2427
2515
  setDefaultMount(terminalMount);
2428
- export { Button, CLIENT_DIRECTIVES, CLIENT_DIRECTIVE_PREFIX, Checkbox, ComputedSymbol, ErrorBoundary, Fragment, Input, InstanceLifetimes, ProgressBar, Select, SubscriptionHandler, Suspense, Text, Utils, batch, component, compound, computed, createModel, createModelFromBinding, createTopic, defineApp, defineDirective, defineFactory, defineInjectable, defineProvide, detectAccess, effect, effectScope, exitTerminal, focus, focusNext, focusPrev, focusState, getComponentMeta, getCurrentInstance, guid, isComponent, isComputed, isDirective, isLazyComponent, isModel, isReactive, jsx, jsxDEV, jsxs, lazy, mountTerminal, onCreated, onKey, onMounted, onUnmounted, onUpdated, registerFocusable, render, renderNodeToLines, renderTerminal, signal, terminalMount, toRaw, toSubscriber, unregisterFocusable, untrack, useAppContext, watch };
2516
+ export { Button, CLIENT_DIRECTIVES, CLIENT_DIRECTIVE_PREFIX, Checkbox, ComputedSymbol, ErrorBoundary, Fragment, Input, InstanceLifetimes, ProgressBar, Select, SigxError, SigxErrorCode, SubscriptionHandler, Suspense, Text, Utils, asyncSetupClientError, batch, component, compound, computed, createModel, createModelFromBinding, createTopic, defineApp, defineDirective, defineFactory, defineInjectable, defineProvide, detectAccess, effect, effectScope, exitTerminal, focus, focusNext, focusPrev, focusState, getComponentMeta, getCurrentInstance, guid, isComponent, isComputed, isDirective, isLazyComponent, isModel, isReactive, jsx, jsxDEV, jsxs, lazy, mountTargetNotFoundError, mountTerminal, noMountFunctionError, onCreated, onKey, onMounted, onUnmounted, onUpdated, provideInvalidInjectableError, provideOutsideSetupError, registerFocusable, render, renderNodeToLines, renderTargetNotFoundError, renderTerminal, signal, terminalMount, toRaw, toSubscriber, unregisterFocusable, untrack, useAppContext, useAsync, watch };
2429
2517
 
2430
2518
  //# sourceMappingURL=index.js.map