Thomas G. Lopes commited on
Commit
a0911b1
·
1 Parent(s): 7bfbc58

virtualization rules

Browse files
package.json CHANGED
@@ -52,7 +52,7 @@
52
  "highlight.js": "^11.10.0",
53
  "jiti": "^2.4.2",
54
  "jsdom": "^26.0.0",
55
- "melt": "^0.40.0",
56
  "openai": "^4.90.0",
57
  "playwright": "^1.52.0",
58
  "postcss": "^8.4.38",
 
52
  "highlight.js": "^11.10.0",
53
  "jiti": "^2.4.2",
54
  "jsdom": "^26.0.0",
55
+ "melt": "^0.40.2",
56
  "openai": "^4.90.0",
57
  "playwright": "^1.52.0",
58
  "postcss": "^8.4.38",
pnpm-lock.yaml CHANGED
@@ -136,8 +136,8 @@ importers:
136
  specifier: ^26.0.0
137
  version: 26.1.0
138
  melt:
139
- specifier: ^0.40.0
140
- version: 0.40.0(@floating-ui/[email protected])([email protected])
141
  openai:
142
  specifier: ^4.90.0
143
  version: 4.90.0([email protected])([email protected])
@@ -2281,8 +2281,8 @@ packages:
2281
  resolution: {integrity: sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==}
2282
  engines: {node: '>= 0.8'}
2283
 
2284
2285
- resolution: {integrity: sha512-G+urf5f2Cy62cXiPQ+nf3muscjIE9e38kjDWZckU4x08bDaP+hryJ9rrsu81V1x0ZAgEwnMAMKVAFrEdomOYWw==}
2286
  peerDependencies:
2287
  '@floating-ui/dom': ^1.6.0
2288
  svelte: ^5.30.1
@@ -5399,7 +5399,7 @@ snapshots:
5399
 
5400
5401
 
5402
5403
  dependencies:
5404
  '@floating-ui/dom': 1.6.13
5405
  dequal: 2.0.3
 
136
  specifier: ^26.0.0
137
  version: 26.1.0
138
  melt:
139
+ specifier: ^0.40.2
140
+ version: 0.40.2(@floating-ui/[email protected])([email protected])
141
  openai:
142
  specifier: ^4.90.0
143
  version: 4.90.0([email protected])([email protected])
 
2281
  resolution: {integrity: sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==}
2282
  engines: {node: '>= 0.8'}
2283
 
2284
2285
+ resolution: {integrity: sha512-lmf17KdERiDZ4Fefx4B/nrvMptG8QqUexMuRlaxT9AlbX7zbjaqPfJz31ekRvkcw6pgYOuYmQPmhY6jlUDVqSw==}
2286
  peerDependencies:
2287
  '@floating-ui/dom': ^1.6.0
2288
  svelte: ^5.30.1
 
5399
 
5400
5401
 
5402
5403
  dependencies:
5404
  '@floating-ui/dom': 1.6.13
5405
  dequal: 2.0.3
src/lib/components/inference-playground/model-selector-modal.svelte CHANGED
@@ -92,14 +92,33 @@
92
  onClose?.();
93
  },
94
  onNavigate(current, direction) {
95
- const currIdx = allFilteredModels.findIndex(item => item.type === "model" && item.content === current);
96
- // TODO: get next/prev item, scroll to it, and return its content. Make sure
97
- // to wrap around.
 
 
98
  if (direction === "next") {
 
 
 
99
  }
100
- if (direction === "prev") {
 
 
 
 
 
 
 
 
101
  }
102
- return null;
 
 
 
 
 
 
103
  },
104
  });
105
  $effect(() => {
 
92
  onClose?.();
93
  },
94
  onNavigate(current, direction) {
95
+ if (current === "__custom__") return null;
96
+ const modelItems = allFilteredModels.filter(item => item.type === "model");
97
+ const currIdx = modelItems.findIndex(item => typeof item.content === "object" && item.content.id === current);
98
+
99
+ let nextIdx: number;
100
  if (direction === "next") {
101
+ nextIdx = currIdx === -1 ? 0 : (currIdx + 1) % modelItems.length;
102
+ } else {
103
+ nextIdx = currIdx === -1 ? modelItems.length - 1 : (currIdx - 1 + modelItems.length) % modelItems.length;
104
  }
105
+
106
+ const nextItem = modelItems[nextIdx];
107
+ if (!nextItem) return null;
108
+
109
+ // Scroll to the item
110
+ const allItems = allFilteredModels;
111
+ const actualIdx = allItems.findIndex(item => item === nextItem);
112
+ if (actualIdx !== -1) {
113
+ virtualScroll.scrollToIndex(actualIdx);
114
  }
115
+
116
+ // Return the content for highlighting
117
+ return nextItem.content === "__custom__"
118
+ ? "__custom__"
119
+ : typeof nextItem.content === "object"
120
+ ? nextItem.content.id
121
+ : null;
122
  },
123
  });
124
  $effect(() => {
src/lib/spells/virtual-scroll.svelte.ts CHANGED
@@ -62,6 +62,34 @@ export class VirtualScroll {
62
  }));
63
  }
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  #attachmentKey = createAttachmentKey();
66
  get container() {
67
  return {
 
62
  }));
63
  }
64
 
65
+ scrollToIndex(index: number) {
66
+ const { start, end } = this.visibleRange;
67
+
68
+ // Only scroll if the index is not currently visible
69
+ if (index >= start && index <= end) {
70
+ return; // Already visible, no need to scroll
71
+ }
72
+
73
+ let targetScrollTop: number;
74
+
75
+ if (index < start) {
76
+ // Scrolling up - position item at top with some buffer
77
+ targetScrollTop = (index - this.overscan) * this.itemHeight;
78
+ } else {
79
+ // Scrolling down - position item at bottom with some buffer
80
+ const visibleItems = Math.floor(this.#containerSize.height / this.itemHeight);
81
+ targetScrollTop = (index - visibleItems + 1 + this.overscan) * this.itemHeight;
82
+ }
83
+
84
+ const maxScrollTop = this.totalHeight - this.#containerSize.height;
85
+ this.#scrollTop = Math.max(0, Math.min(targetScrollTop, maxScrollTop));
86
+
87
+ // Update the actual scroll container
88
+ if (this.#containerEl) {
89
+ this.#containerEl.scrollTop = this.#scrollTop;
90
+ }
91
+ }
92
+
93
  #attachmentKey = createAttachmentKey();
94
  get container() {
95
  return {