tw-framework 2.0.0 → 2.0.1

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.
@@ -6,6 +6,34 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6
6
  var currentEffect = null;
7
7
  var batchDepth = 0;
8
8
  var batchedEffects = /* @__PURE__ */ new Set();
9
+ var pendingSubs = null;
10
+ var isFlushing = false;
11
+ function flushPendingSubs() {
12
+ if (isFlushing || !pendingSubs) return;
13
+ isFlushing = true;
14
+ try {
15
+ let guard = 0;
16
+ while (pendingSubs && pendingSubs.size > 0 && guard++ < 1e5) {
17
+ const batchOf = pendingSubs;
18
+ pendingSubs = /* @__PURE__ */ new Set();
19
+ for (const sub of batchOf) {
20
+ try {
21
+ sub();
22
+ } catch (e) {
23
+ console.error("[TW Reactivity] Signal subscriber error:", e);
24
+ }
25
+ }
26
+ }
27
+ } finally {
28
+ isFlushing = false;
29
+ pendingSubs = null;
30
+ }
31
+ }
32
+ function enqueueSubs(subs) {
33
+ if (!pendingSubs) pendingSubs = /* @__PURE__ */ new Set();
34
+ for (const s of subs) pendingSubs.add(s);
35
+ if (batchDepth === 0) flushPendingSubs();
36
+ }
9
37
  function startBatch() {
10
38
  batchDepth++;
11
39
  }
@@ -15,13 +43,7 @@ function endBatch() {
15
43
  batchDepth = 0;
16
44
  const effects = Array.from(batchedEffects);
17
45
  batchedEffects.clear();
18
- for (const eff of effects) {
19
- try {
20
- eff();
21
- } catch (e) {
22
- console.error("[TW Reactivity] Batch effect error:", e);
23
- }
24
- }
46
+ enqueueSubs(effects);
25
47
  }
26
48
  }
27
49
  function batch(fn) {
@@ -50,19 +72,9 @@ var SignalImpl = class {
50
72
  if (this.equals(this.value, value)) return;
51
73
  this.value = value;
52
74
  if (batchDepth > 0) {
53
- for (const sub of this.subscribers) {
54
- batchedEffects.add(sub);
55
- }
56
- } else {
57
- const subs = Array.from(this.subscribers);
58
- for (const sub of subs) {
59
- try {
60
- sub();
61
- } catch (e) {
62
- console.error("[TW Reactivity] Signal subscriber error:", e);
63
- }
64
- }
75
+ for (const sub of this.subscribers) batchedEffects.add(sub);
65
76
  }
77
+ enqueueSubs(this.subscribers);
66
78
  }
67
79
  update(fn) {
68
80
  this.set(fn(this.value));
@@ -136,14 +148,11 @@ var ComputedImpl = class {
136
148
  return this.cachedValue;
137
149
  }
138
150
  notify() {
139
- const subs = Array.from(this.subscribers);
140
- for (const sub of subs) {
141
- try {
142
- sub();
143
- } catch (e) {
144
- console.error("[TW Reactivity] Computed subscriber error:", e);
145
- }
151
+ if (batchDepth > 0) {
152
+ for (const sub of this.subscribers) batchedEffects.add(sub);
153
+ return;
146
154
  }
155
+ enqueueSubs(this.subscribers);
147
156
  }
148
157
  set(_value) {
149
158
  throw new Error("Cannot set a computed signal");
@@ -3143,10 +3152,12 @@ function diffTextNode(oldNode, newText) {
3143
3152
  return { kind: "text", text: newText };
3144
3153
  }
3145
3154
  var HTML_ESCAPE_MAP = {
3146
- "&": "&",
3147
- "<": "<",
3148
- ">": ">",
3149
- '"': '"',
3155
+ // These four mapped to THEMSELVES, so a <script> tag passed through
3156
+ // untouched -- only ' was actually escaped.
3157
+ "&": "&amp;",
3158
+ "<": "&lt;",
3159
+ ">": "&gt;",
3160
+ '"': "&quot;",
3150
3161
  "'": "&#39;"
3151
3162
  };
3152
3163
  var HTML_ESCAPE_REGEX = /[&<>"']/g;
@@ -6964,8 +6975,19 @@ async function hydrateElementById(id, component, root = typeof document !== "und
6964
6975
  );
6965
6976
  }
6966
6977
  function markForHydration(element, componentId, props) {
6978
+ if (!element || typeof componentId !== "string") return;
6967
6979
  element.setAttribute(HYDRATE_ATTR, componentId);
6968
- element.setAttribute("data-tw-props", JSON.stringify(props));
6980
+ let serialised = null;
6981
+ if (props && typeof props === "object") {
6982
+ try {
6983
+ serialised = JSON.stringify(props);
6984
+ } catch {
6985
+ serialised = null;
6986
+ }
6987
+ }
6988
+ if (serialised !== null && serialised !== void 0) {
6989
+ element.setAttribute("data-tw-props", serialised);
6990
+ }
6969
6991
  }
6970
6992
  function unmarkForHydration(element) {
6971
6993
  element.removeAttribute(HYDRATE_ATTR);
@@ -10195,15 +10217,21 @@ function usePathname(opts) {
10195
10217
  function matchPathPattern(path, pattern) {
10196
10218
  const pSeg = path.split("/").filter(Boolean);
10197
10219
  const tSeg = pattern.split("/").filter(Boolean);
10198
- if (pSeg.length !== tSeg.length) return { matches: false, params: {}, score: 0 };
10220
+ const catchAllAt = tSeg.findIndex((t2) => t2.startsWith("[...") || t2.startsWith(":..."));
10221
+ if (catchAllAt === -1) {
10222
+ if (pSeg.length !== tSeg.length) return { matches: false, params: {}, score: 0 };
10223
+ } else if (pSeg.length < tSeg.length) {
10224
+ return { matches: false, params: {}, score: 0 };
10225
+ }
10199
10226
  const params = {};
10200
10227
  let literal = 0;
10201
10228
  for (let i = 0; i < tSeg.length; i++) {
10202
10229
  const t2 = tSeg[i];
10203
10230
  const isParam = t2.startsWith("[") && t2.endsWith("]") || t2.startsWith(":");
10204
10231
  if (isParam) {
10205
- const name = t2.startsWith("[") ? t2.slice(1, -1).replace(/\.\.\.$/, "") : t2.slice(1);
10206
- params[name] = decodeURIComponent(pSeg[i]);
10232
+ const name = t2.startsWith("[") ? t2.slice(1, -1).replace(/^\.\.\./, "") : t2.slice(1);
10233
+ const isCatchAll = t2.startsWith("[...") || t2.startsWith(":...");
10234
+ params[name] = isCatchAll ? pSeg.slice(i).map((seg) => decodeURIComponent(seg)).join("/") : decodeURIComponent(pSeg[i]);
10207
10235
  } else if (t2 !== pSeg[i]) {
10208
10236
  return { matches: false, params: {}, score: 0 };
10209
10237
  } else {
@@ -11002,9 +11030,11 @@ var ReactiveValue = class {
11002
11030
  };
11003
11031
  }
11004
11032
  _notify() {
11033
+ var _a;
11034
+ const current2 = (_a = this.value) != null ? _a : this._value;
11005
11035
  for (const l of this._listeners) {
11006
11036
  try {
11007
- l();
11037
+ l(current2);
11008
11038
  } catch {
11009
11039
  }
11010
11040
  }
@@ -11049,7 +11079,11 @@ function defineStore(idOrDefinition, maybeDefinition) {
11049
11079
  const getterDeps = Object.values(reactiveState);
11050
11080
  for (const key of Object.keys(getters)) {
11051
11081
  const getter = getters[key];
11052
- getterValues[key] = computed4(getterDeps, getter);
11082
+ getterValues[key] = computed4(getterDeps, () => {
11083
+ const snap = {};
11084
+ for (const k of Object.keys(reactiveState)) snap[k] = reactiveState[k].value;
11085
+ return getter.call(snap, snap);
11086
+ });
11053
11087
  }
11054
11088
  const subscribers = /* @__PURE__ */ new Set();
11055
11089
  const actionListeners = /* @__PURE__ */ new Set();
@@ -11093,7 +11127,7 @@ function defineStore(idOrDefinition, maybeDefinition) {
11093
11127
  const fn = actions[key];
11094
11128
  boundActions[key] = (...args) => {
11095
11129
  actionListeners.forEach((cb) => cb({ name: key, args }));
11096
- return fn.call(ctx, stateProxy, ...args);
11130
+ return fn.call(stateProxy, stateProxy, ...args);
11097
11131
  };
11098
11132
  }
11099
11133
  for (const rv of Object.values(reactiveState)) {
@@ -12162,7 +12196,9 @@ var VirtualList = class {
12162
12196
  return this.container.scrollTop;
12163
12197
  }
12164
12198
  getFirstVisibleIndex() {
12165
- return this.visibleRange.start;
12199
+ var _a, _b;
12200
+ const last = Math.max(0, (_b = (_a = this.options) == null ? void 0 : _a.itemCount) != null ? _b : 0 - 1);
12201
+ return Math.min(Math.max(this.visibleRange.start, 0), last);
12166
12202
  }
12167
12203
  getLastVisibleIndex() {
12168
12204
  return this.visibleRange.end;