@sigx/runtime-core 0.1.6 → 0.1.8

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
@@ -1,4 +1,5 @@
1
1
  import { detectAccess, effect, isComputed, signal, signal as signal$1, untrack } from "@sigx/reactivity";
2
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
2
3
  var platformModelProcessor = null;
3
4
  function setPlatformModelProcessor(fn) {
4
5
  platformModelProcessor = fn;
@@ -20,14 +21,64 @@ function registerContextExtension(extension) {
20
21
  function applyContextExtensions(ctx) {
21
22
  for (const extension of contextExtensions) extension(ctx);
22
23
  }
24
+ var require___vite_browser_external = /* @__PURE__ */ __commonJSMin(((exports, module) => {
25
+ module.exports = {};
26
+ }));
27
+ var asyncLocalStorage = null;
28
+ try {
29
+ if (typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined") {
30
+ const nodeAsync = globalThis.process?.versions?.node ? require___vite_browser_external() : null;
31
+ if (nodeAsync?.AsyncLocalStorage) asyncLocalStorage = new nodeAsync.AsyncLocalStorage();
32
+ }
33
+ } catch {}
34
+ var _fallbackContext = {
35
+ currentComponentContext: null,
36
+ currentSuspenseBoundary: null
37
+ };
38
+ function getRequestContext() {
39
+ if (asyncLocalStorage) {
40
+ const store = asyncLocalStorage.getStore();
41
+ if (store) return store;
42
+ }
43
+ return _fallbackContext;
44
+ }
45
+ function getCurrentInstanceSafe() {
46
+ return getRequestContext().currentComponentContext;
47
+ }
48
+ function setCurrentInstanceSafe(ctx) {
49
+ const reqCtx = getRequestContext();
50
+ const prev = reqCtx.currentComponentContext;
51
+ reqCtx.currentComponentContext = ctx;
52
+ return prev;
53
+ }
54
+ function getCurrentSuspenseBoundarySafe() {
55
+ return getRequestContext().currentSuspenseBoundary;
56
+ }
57
+ function setCurrentSuspenseBoundarySafe(boundary) {
58
+ const reqCtx = getRequestContext();
59
+ const prev = reqCtx.currentSuspenseBoundary;
60
+ reqCtx.currentSuspenseBoundary = boundary;
61
+ return prev;
62
+ }
63
+ function runInRequestScope(fn) {
64
+ if (asyncLocalStorage) return asyncLocalStorage.run({
65
+ currentComponentContext: null,
66
+ currentSuspenseBoundary: null
67
+ }, fn);
68
+ return fn();
69
+ }
70
+ function hasRequestIsolation() {
71
+ return asyncLocalStorage !== null;
72
+ }
23
73
  var currentComponentContext = null;
24
74
  function getCurrentInstance() {
25
- return currentComponentContext;
75
+ return getCurrentInstanceSafe() ?? currentComponentContext;
26
76
  }
27
77
  function setCurrentInstance(ctx) {
28
- const prev = currentComponentContext;
78
+ const prevSafe = setCurrentInstanceSafe(ctx);
79
+ const prevModule = currentComponentContext;
29
80
  currentComponentContext = ctx;
30
- return prev;
81
+ return prevSafe ?? prevModule;
31
82
  }
32
83
  function onMounted(fn) {
33
84
  if (currentComponentContext) currentComponentContext.onMounted(fn);
@@ -126,6 +177,14 @@ function provideAppContext(ctx, appContext) {
126
177
  ctx.provides.set(appContextToken, appContext);
127
178
  if (appContext.provides) for (const [token, value] of appContext.provides) ctx.provides.set(token, value);
128
179
  }
180
+ const __DIRECTIVE__ = Symbol.for("sigx.directive");
181
+ function defineDirective(definition) {
182
+ definition[__DIRECTIVE__] = true;
183
+ return definition;
184
+ }
185
+ function isDirective(value) {
186
+ return value != null && typeof value === "object" && value[__DIRECTIVE__] === true;
187
+ }
129
188
  var isDev = typeof process !== "undefined" && process.env.NODE_ENV !== "production" || true;
130
189
  var defaultMountFn = null;
131
190
  function setDefaultMount(mountFn) {
@@ -140,7 +199,8 @@ function defineApp(rootComponent) {
140
199
  app: null,
141
200
  provides: /* @__PURE__ */ new Map(),
142
201
  config: {},
143
- hooks: []
202
+ hooks: [],
203
+ directives: /* @__PURE__ */ new Map()
144
204
  };
145
205
  let isMounted = false;
146
206
  let container = null;
@@ -170,6 +230,14 @@ function defineApp(rootComponent) {
170
230
  context.hooks.push(hooks);
171
231
  return app;
172
232
  },
233
+ directive(name, definition) {
234
+ if (definition !== void 0) {
235
+ if (isDev && !isDirective(definition)) console.warn(`[sigx] app.directive('${name}', ...) received a value that is not a valid directive definition. Use defineDirective() to create directive definitions.`);
236
+ context.directives.set(name, definition);
237
+ return app;
238
+ }
239
+ return context.directives.get(name);
240
+ },
173
241
  mount(target, renderFn) {
174
242
  if (isMounted) {
175
243
  if (isDev) console.warn("App is already mounted. Call app.unmount() first.");
@@ -422,7 +490,7 @@ function jsxs(type, props, key) {
422
490
  const jsxDEV = jsx;
423
491
  var currentSuspenseBoundary = null;
424
492
  function registerPendingPromise(promise) {
425
- const boundary = currentSuspenseBoundary;
493
+ const boundary = getCurrentSuspenseBoundarySafe() ?? currentSuspenseBoundary;
426
494
  if (boundary) {
427
495
  boundary.pending.add(promise);
428
496
  promise.finally(() => {
@@ -506,8 +574,9 @@ const Suspense = component((ctx) => {
506
574
  return () => {
507
575
  state.isReady;
508
576
  state.pendingCount;
509
- const prevBoundary = currentSuspenseBoundary;
577
+ const prevBoundary = getCurrentSuspenseBoundarySafe() ?? currentSuspenseBoundary;
510
578
  currentSuspenseBoundary = boundary;
579
+ setCurrentSuspenseBoundarySafe(boundary);
511
580
  try {
512
581
  const children = slots.default();
513
582
  if (boundary.pending.size > 0) {
@@ -532,12 +601,41 @@ const Suspense = component((ctx) => {
532
601
  throw err;
533
602
  } finally {
534
603
  currentSuspenseBoundary = prevBoundary;
604
+ setCurrentSuspenseBoundarySafe(prevBoundary);
535
605
  }
536
606
  };
537
607
  }, { name: "Suspense" });
538
608
  function isLazyComponent(component) {
539
609
  return component && component.__lazy === true;
540
610
  }
611
+ const ErrorBoundary = component((ctx) => {
612
+ const { fallback } = ctx.props;
613
+ const { slots } = ctx;
614
+ const state = ctx.signal({
615
+ hasError: false,
616
+ error: null
617
+ });
618
+ const retry = () => {
619
+ state.hasError = false;
620
+ state.error = null;
621
+ };
622
+ return () => {
623
+ if (state.hasError && state.error) {
624
+ if (typeof fallback === "function") return fallback(state.error, retry);
625
+ return fallback ?? null;
626
+ }
627
+ try {
628
+ return slots.default();
629
+ } catch (e) {
630
+ const error = e instanceof Error ? e : new Error(String(e));
631
+ state.hasError = true;
632
+ state.error = error;
633
+ if (process.env.NODE_ENV !== "production") console.error("[ErrorBoundary] Caught error during render:", error);
634
+ if (typeof fallback === "function") return fallback(error, retry);
635
+ return fallback ?? null;
636
+ }
637
+ };
638
+ }, { name: "ErrorBoundary" });
541
639
  var Utils = class {
542
640
  static isPromise(value) {
543
641
  return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
@@ -777,7 +875,7 @@ function createEmit(reactiveProps) {
777
875
  };
778
876
  }
779
877
  function createRenderer(options) {
780
- const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, cloneNode: hostCloneNode, insertStaticContent: hostInsertStaticContent } = options;
878
+ const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, cloneNode: hostCloneNode, insertStaticContent: hostInsertStaticContent, patchDirective: hostPatchDirective, onElementMounted: hostOnElementMounted, onElementUnmounted: hostOnElementUnmounted } = options;
781
879
  let currentAppContext = null;
782
880
  function render(element, container, appContext) {
783
881
  if (appContext) currentAppContext = appContext;
@@ -899,7 +997,9 @@ function createRenderer(options) {
899
997
  vnode.dom = element;
900
998
  element.__vnode = vnode;
901
999
  if (vnode.props) {
902
- for (const key in vnode.props) if (key !== "children" && key !== "key" && key !== "ref") hostPatchProp(element, key, null, vnode.props[key], isSVG);
1000
+ for (const key in vnode.props) if (key !== "children" && key !== "key" && key !== "ref") if (key.charCodeAt(0) === 117 && key.startsWith("use:")) {
1001
+ if (hostPatchDirective) hostPatchDirective(element, key.slice(4), null, vnode.props[key], currentAppContext);
1002
+ } else hostPatchProp(element, key, null, vnode.props[key], isSVG);
903
1003
  if (vnode.props.ref) untrack(() => {
904
1004
  if (typeof vnode.props.ref === "function") vnode.props.ref(element);
905
1005
  else if (typeof vnode.props.ref === "object") vnode.props.ref.current = element;
@@ -911,6 +1011,7 @@ function createRenderer(options) {
911
1011
  mount(child, element, null, childIsSVG);
912
1012
  });
913
1013
  hostInsert(element, container, before);
1014
+ if (hostOnElementMounted) hostOnElementMounted(element);
914
1015
  }
915
1016
  function unmount(vnode, container) {
916
1017
  const internalVNode = vnode;
@@ -935,6 +1036,7 @@ function createRenderer(options) {
935
1036
  if (typeof vnode.props.ref === "function") vnode.props.ref(null);
936
1037
  else if (vnode.props.ref && typeof vnode.props.ref === "object") vnode.props.ref.current = null;
937
1038
  });
1039
+ if (hostOnElementUnmounted && vnode.dom) hostOnElementUnmounted(vnode.dom);
938
1040
  if (vnode.children && vnode.children.length > 0) vnode.children.forEach((child) => unmount(child, vnode.dom));
939
1041
  if (vnode.dom) hostRemove(vnode.dom);
940
1042
  }
@@ -999,6 +1101,12 @@ function createRenderer(options) {
999
1101
  }
1000
1102
  if (newVNode.type === Text) {
1001
1103
  newVNode.dom = oldVNode.dom;
1104
+ if (!newVNode.dom) {
1105
+ const textNode = hostCreateText(String(newVNode.text));
1106
+ newVNode.dom = textNode;
1107
+ if (container) hostInsert(textNode, container, oldVNode.dom || null);
1108
+ return;
1109
+ }
1002
1110
  if (oldVNode.text !== newVNode.text) hostSetText(newVNode.dom, String(newVNode.text));
1003
1111
  return;
1004
1112
  }
@@ -1015,11 +1123,15 @@ function createRenderer(options) {
1015
1123
  const isSVG = tag === "svg" || isSvgTag(tag);
1016
1124
  const oldProps = oldVNode.props || {};
1017
1125
  const newProps = newVNode.props || {};
1018
- for (const key in oldProps) if (!(key in newProps) && key !== "children" && key !== "key" && key !== "ref") hostPatchProp(element, key, oldProps[key], null, isSVG);
1126
+ for (const key in oldProps) if (!(key in newProps) && key !== "children" && key !== "key" && key !== "ref") if (key.charCodeAt(0) === 117 && key.startsWith("use:")) {
1127
+ if (hostPatchDirective) hostPatchDirective(element, key.slice(4), oldProps[key], null, currentAppContext);
1128
+ } else hostPatchProp(element, key, oldProps[key], null, isSVG);
1019
1129
  for (const key in newProps) {
1020
1130
  const oldValue = oldProps[key];
1021
1131
  const newValue = newProps[key];
1022
- if (key !== "children" && key !== "key" && key !== "ref" && oldValue !== newValue) hostPatchProp(element, key, oldValue, newValue, isSVG);
1132
+ if (key !== "children" && key !== "key" && key !== "ref" && oldValue !== newValue) if (key.charCodeAt(0) === 117 && key.startsWith("use:")) {
1133
+ if (hostPatchDirective) hostPatchDirective(element, key.slice(4), oldValue, newValue, currentAppContext);
1134
+ } else hostPatchProp(element, key, oldValue, newValue, isSVG);
1023
1135
  }
1024
1136
  patchChildren(oldVNode, newVNode, element, isSVG && tag !== "foreignObject");
1025
1137
  }
@@ -1236,6 +1348,6 @@ function createRenderer(options) {
1236
1348
  mountComponent
1237
1349
  };
1238
1350
  }
1239
- export { CLIENT_DIRECTIVES, CLIENT_DIRECTIVE_PREFIX, Fragment, InstanceLifetimes, SubscriptionHandler, Suspense, Text, Utils, applyContextExtensions, component, compound, createEmit, createModel, createModelFromBinding, createPropsAccessor, createPropsProxy, createRenderer, createSlots, createTopic, defineApp, defineFactory, defineInjectable, defineProvide, filterClientDirectives, getAppContextToken, getComponentMeta, getComponentPlugins, getCurrentInstance, getDefaultMount, getHydrationDirective, getModelSymbol, getPlatformModelProcessor, guid, handleComponentError, hasClientDirective, isComponent, isLazyComponent, isModel, jsx, jsxDEV, jsxs, lazy, normalizeSubTree, notifyComponentCreated, notifyComponentMounted, notifyComponentUnmounted, notifyComponentUpdated, onCreated, onMounted, onUnmounted, onUpdated, provideAppContext, registerComponentPlugin, registerContextExtension, registerPendingPromise, serializeProps, setCurrentInstance, setDefaultMount, setPlatformModelProcessor, signal, toSubscriber, useAppContext, valueOf };
1351
+ export { CLIENT_DIRECTIVES, CLIENT_DIRECTIVE_PREFIX, ErrorBoundary, Fragment, InstanceLifetimes, SubscriptionHandler, Suspense, Text, Utils, __DIRECTIVE__, applyContextExtensions, component, compound, createEmit, createModel, createModelFromBinding, createPropsAccessor, createPropsProxy, createRenderer, createSlots, createTopic, defineApp, defineDirective, defineFactory, defineInjectable, defineProvide, filterClientDirectives, getAppContextToken, getComponentMeta, getComponentPlugins, getCurrentInstance, getDefaultMount, getHydrationDirective, getModelSymbol, getPlatformModelProcessor, guid, handleComponentError, hasClientDirective, hasRequestIsolation, isComponent, isDirective, isLazyComponent, isModel, jsx, jsxDEV, jsxs, lazy, normalizeSubTree, notifyComponentCreated, notifyComponentMounted, notifyComponentUnmounted, notifyComponentUpdated, onCreated, onMounted, onUnmounted, onUpdated, provideAppContext, registerComponentPlugin, registerContextExtension, registerPendingPromise, runInRequestScope, serializeProps, setCurrentInstance, setDefaultMount, setPlatformModelProcessor, signal, toSubscriber, useAppContext, valueOf };
1240
1352
 
1241
1353
  //# sourceMappingURL=index.js.map