@estjs/template 0.0.17-beta.4 → 0.0.17-beta.5

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,5 +1,5 @@
1
1
  import { getActiveScope, runWithScope, onCleanup, __objRest, createScope, disposeScope, __async } from './chunk-PYFF2HI3.dev.js';
2
- import { normalizeClassName, SPREAD_NAME, isObject, warn, startsWith, isSpecialBooleanAttr, isBooleanAttr, includeBooleanAttr, isSymbol, isString, isArray, kebabCase, camelCase, capitalize, HYDRATION_ANCHOR_ATTR, isBrowser, error, isPromise, isFunction, isOn, coerceArray } from '@estjs/shared';
2
+ import { normalizeClassName, SPREAD_NAME, isObject, warn, startsWith, isSpecialBooleanAttr, isBooleanAttr, includeBooleanAttr, isSymbol, isString, isArray, kebabCase, camelCase, capitalize, HYDRATION_ANCHOR_ATTR, isBrowser, error, isPromise, isFunction, isOn, coerceArray, isNumber } from '@estjs/shared';
3
3
  import { effect, shallowReactive, isSignal, isComputed, isReactive, signal } from '@estjs/signals';
4
4
 
5
5
  var REF_KEY = "ref";
@@ -148,6 +148,7 @@ function patchClass(el, prev, next2, isSVG = false) {
148
148
  }
149
149
  var normalizeClass = normalizeClassName;
150
150
  var importantRE = /\s*!important$/;
151
+ var styleDeclRE = /(?:^|;)\s*([a-z][a-z\d-]*)\s*:/gi;
151
152
  var prefixes = ["Webkit", "Moz", "ms"];
152
153
  var prefixCache = {};
153
154
  function patchStyle(el, prev, next2) {
@@ -172,9 +173,9 @@ function patchStyle(el, prev, next2) {
172
173
  }
173
174
  }
174
175
  } else if (prev && isString(prev)) {
175
- const declRE = /(?:^|;)\s*([a-z][a-z\d-]*)\s*:/gi;
176
+ styleDeclRE.lastIndex = 0;
176
177
  let match;
177
- while ((match = declRE.exec(prev)) !== null) {
178
+ while ((match = styleDeclRE.exec(prev)) !== null) {
178
179
  const key = match[1].trim();
179
180
  if (key && next2 && isObject(next2) && next2[key] == null) {
180
181
  setStyle(style, key, "");
@@ -645,7 +646,7 @@ function normalizeNode(node) {
645
646
  }
646
647
  function insert(parent, nodeFactory, before) {
647
648
  if (!parent) return;
648
- const parentScope = getActiveScope();
649
+ let parentScope = getActiveScope();
649
650
  let renderedNodes = [];
650
651
  let isFirstRun = true;
651
652
  const resolveNodes = (raw) => {
@@ -687,6 +688,7 @@ function insert(parent, nodeFactory, before) {
687
688
  effectRunner.stop();
688
689
  for (const node of renderedNodes) removeNode(node);
689
690
  renderedNodes = [];
691
+ parentScope = null;
690
692
  });
691
693
  return renderedNodes;
692
694
  }
@@ -824,9 +826,9 @@ function syncDescriptors(target, source, pruneMissing = false) {
824
826
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
825
827
  }
826
828
  if (pruneMissing) {
827
- const sourceKeys = Object.getOwnPropertyNames(source);
829
+ const sourceKeySet = new Set(Object.getOwnPropertyNames(source));
828
830
  for (const key of Object.getOwnPropertyNames(target)) {
829
- if (!sourceKeys.includes(key)) delete target[key];
831
+ if (!sourceKeySet.has(key)) delete target[key];
830
832
  }
831
833
  }
832
834
  }
@@ -1388,12 +1390,10 @@ function bindElement(node, prop, getter, setter, modifiers = {}) {
1388
1390
  onCleanup(() => runner.stop());
1389
1391
  }
1390
1392
  }
1391
-
1392
- // src/utils.ts
1393
1393
  function unwrapSlotValue(raw) {
1394
1394
  let v = raw;
1395
1395
  if (Array.isArray(v) && v.length === 1) v = v[0];
1396
- return typeof v === "function" ? v() : v;
1396
+ return isFunction(v) ? v() : v;
1397
1397
  }
1398
1398
  function useChildren(props) {
1399
1399
  const desc = Object.getOwnPropertyDescriptor(props, "children");
@@ -1711,49 +1711,50 @@ function createResource(fetcher, options) {
1711
1711
  const error4 = signal(null);
1712
1712
  const state = signal("pending");
1713
1713
  let fetchId = 0;
1714
- let currentPromise = null;
1715
- let suspenseRegistered = false;
1714
+ let controller = null;
1716
1715
  const suspenseContext = inject(SuspenseContext, null);
1717
- const fetch = () => __async(null, null, function* () {
1718
- const currentFetchId = ++fetchId;
1716
+ const doFetch = () => __async(null, null, function* () {
1717
+ const id = ++fetchId;
1718
+ controller == null ? void 0 : controller.abort();
1719
+ controller = new AbortController();
1719
1720
  loading.value = true;
1720
1721
  state.value = "pending";
1721
1722
  error4.value = null;
1722
- suspenseRegistered = false;
1723
- if (suspenseContext) {
1724
- suspenseContext.increment();
1723
+ let promise;
1724
+ try {
1725
+ promise = Promise.resolve(fetcher(controller.signal));
1726
+ } catch (error_) {
1727
+ error4.value = error_ instanceof Error ? error_ : new Error(String(error_));
1728
+ state.value = "errored";
1729
+ loading.value = false;
1730
+ return;
1725
1731
  }
1732
+ suspenseContext == null ? void 0 : suspenseContext.register(promise);
1726
1733
  try {
1727
- const promise = fetcher();
1728
- currentPromise = promise;
1729
- promise.catch(() => {
1730
- });
1731
1734
  const result = yield promise;
1732
- if (currentFetchId === fetchId) {
1735
+ if (id === fetchId) {
1733
1736
  value.value = result;
1734
1737
  state.value = "ready";
1735
1738
  loading.value = false;
1736
1739
  }
1737
1740
  } catch (error_) {
1738
- if (currentFetchId === fetchId) {
1739
- error4.value = error_ instanceof Error ? error_ : new Error(String(error_));
1740
- state.value = "errored";
1741
+ if (id !== fetchId) return;
1742
+ if (error_ instanceof DOMException && error_.name === "AbortError") {
1741
1743
  loading.value = false;
1744
+ return;
1742
1745
  }
1743
- } finally {
1744
- if (suspenseContext) {
1745
- suspenseContext.decrement();
1746
- }
1746
+ error4.value = error_ instanceof Error ? error_ : new Error(String(error_));
1747
+ state.value = "errored";
1748
+ loading.value = false;
1747
1749
  }
1748
1750
  });
1749
- fetch();
1750
- const resource = (() => {
1751
- if (!suspenseRegistered && loading.value && currentPromise && suspenseContext) {
1752
- suspenseRegistered = true;
1753
- suspenseContext.register(currentPromise);
1754
- }
1755
- return value.value;
1751
+ doFetch();
1752
+ onCleanup(() => {
1753
+ fetchId++;
1754
+ controller == null ? void 0 : controller.abort();
1755
+ controller = null;
1756
1756
  });
1757
+ const resource = (() => value.value);
1757
1758
  resource.loading = loading;
1758
1759
  resource.error = error4;
1759
1760
  resource.state = state;
@@ -1764,9 +1765,7 @@ function createResource(fetcher, options) {
1764
1765
  loading.value = false;
1765
1766
  error4.value = null;
1766
1767
  },
1767
- refetch: () => __async(null, null, function* () {
1768
- yield fetch();
1769
- })
1768
+ refetch: () => doFetch()
1770
1769
  };
1771
1770
  return [resource, actions];
1772
1771
  }
@@ -1950,9 +1949,14 @@ function For(props) {
1950
1949
  const parentScope = (_a2 = getActiveScope()) != null ? _a2 : ownerScope;
1951
1950
  const scope = createScope(parentScope);
1952
1951
  let mountedNodes = [];
1953
- runWithScope(scope, () => {
1954
- mountedNodes = mountValue(renderFn(item, index), parent, before);
1955
- });
1952
+ try {
1953
+ runWithScope(scope, () => {
1954
+ mountedNodes = mountValue(renderFn(item, index), parent, before);
1955
+ });
1956
+ } catch (error4) {
1957
+ disposeScope(scope);
1958
+ throw error4;
1959
+ }
1956
1960
  return { key, item, nodes: mountedNodes, scope };
1957
1961
  };
1958
1962
  const disposeItem = (entry) => {
@@ -2153,16 +2157,17 @@ function whenTransitionEnds(el, type, explicit, resolve2) {
2153
2157
  const finish = () => {
2154
2158
  if (done) return;
2155
2159
  done = true;
2160
+ clearTimeout(timer);
2156
2161
  el.removeEventListener(info.event, onEnd);
2157
2162
  resolve2();
2158
2163
  };
2159
2164
  const onEnd = () => finish();
2160
2165
  el.addEventListener(info.event, onEnd);
2161
- setTimeout(finish, info.timeout + 1);
2166
+ const timer = setTimeout(finish, info.timeout + 1);
2162
2167
  }
2163
2168
  function resolveDuration(d, dir) {
2164
2169
  if (d == null) return null;
2165
- if (typeof d === "number") return d;
2170
+ if (isNumber(d)) return d;
2166
2171
  return d[dir];
2167
2172
  }
2168
2173
  function validateSlot(value) {
@@ -2479,9 +2484,14 @@ function TransitionGroup(props) {
2479
2484
  const parentScope = getActiveScope();
2480
2485
  const scope = createScope(parentScope);
2481
2486
  let raw;
2482
- runWithScope(scope, () => {
2483
- raw = childrenFn(item, index);
2484
- });
2487
+ try {
2488
+ runWithScope(scope, () => {
2489
+ raw = childrenFn(item, index);
2490
+ });
2491
+ } catch (error4) {
2492
+ disposeScope(scope);
2493
+ throw error4;
2494
+ }
2485
2495
  const { el, comp } = resolveItemElement(raw, wrapper);
2486
2496
  if (!el) {
2487
2497
  disposeScope(scope);