lutra 0.1.11 → 0.1.13
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.
@@ -171,7 +171,8 @@
|
|
171
171
|
border-radius: var(--menu-border-radius);
|
172
172
|
box-shadow: 0 0.5rem 1rem var(--shadow-color);
|
173
173
|
background-color: var(--menu-background-color);
|
174
|
-
width: var(--width,
|
174
|
+
width: var(--width, fit-content);
|
175
|
+
max-width: var(--max-width, 50ch);
|
175
176
|
overflow-x: clip;
|
176
177
|
overflow-y: auto;
|
177
178
|
scrollbar-width: thin;
|
@@ -1,19 +1,25 @@
|
|
1
1
|
<script lang="ts">
|
2
2
|
import type { Component, Snippet } from "svelte";
|
3
|
+
import Icon from "./Icon.svelte";
|
3
4
|
|
4
5
|
let {
|
5
6
|
text,
|
6
7
|
snippet,
|
7
8
|
component: Comp,
|
8
|
-
props
|
9
|
+
props,
|
10
|
+
icon
|
9
11
|
}: {
|
10
12
|
text?: string;
|
11
|
-
snippet?: Snippet
|
13
|
+
snippet?: Snippet;
|
12
14
|
component?: Component;
|
13
15
|
props?: any;
|
16
|
+
icon?: string | Component;
|
14
17
|
} = $props();
|
15
18
|
</script>
|
16
19
|
|
20
|
+
{#if icon}
|
21
|
+
<Icon {icon} alt={text} />
|
22
|
+
{/if}
|
17
23
|
{#if text}
|
18
24
|
{text}
|
19
25
|
{/if}
|
@@ -22,4 +28,10 @@
|
|
22
28
|
{/if}
|
23
29
|
{#if Comp}
|
24
30
|
<Comp {...props} />
|
25
|
-
{/if}
|
31
|
+
{/if}
|
32
|
+
|
33
|
+
<style>
|
34
|
+
:global(.Icon) {
|
35
|
+
margin-inline-end: var(--menu-item-icon-gap, var(--space-sm));
|
36
|
+
}
|
37
|
+
</style>
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import type { Component, Snippet } from "svelte";
|
2
2
|
type $$ComponentProps = {
|
3
3
|
text?: string;
|
4
|
-
snippet?: Snippet
|
4
|
+
snippet?: Snippet;
|
5
5
|
component?: Component;
|
6
6
|
props?: any;
|
7
|
+
icon?: string | Component;
|
7
8
|
};
|
8
9
|
declare const MenuItemContent: Component<$$ComponentProps, {}, "">;
|
9
10
|
type MenuItemContent = ReturnType<typeof MenuItemContent>;
|
@@ -9,9 +9,11 @@ export type MenuItem = {
|
|
9
9
|
/** Text label of the item to display to the user. */
|
10
10
|
text?: string;
|
11
11
|
/** Snippet to display. */
|
12
|
-
snippet?: Snippet
|
12
|
+
snippet?: Snippet;
|
13
13
|
/** Component to display. */
|
14
14
|
component?: Component;
|
15
|
+
/** Icon to display. Pass either a Svelte Component or an URL. Use the Icon component to recolor your icons according to the user theme. */
|
16
|
+
icon?: string | Component;
|
15
17
|
/** Color to use for the item. */
|
16
18
|
color?: StatusColorOrString;
|
17
19
|
} | {
|
@@ -27,7 +29,7 @@ export type MenuItem = {
|
|
27
29
|
/** Text label of the item to display to the user. */
|
28
30
|
text?: string;
|
29
31
|
/** Snippet to display. */
|
30
|
-
snippet?: Snippet
|
32
|
+
snippet?: Snippet;
|
31
33
|
/** Component to display. */
|
32
34
|
component?: Component;
|
33
35
|
/** Keyboard shortcut to display next to the item. */
|
@@ -65,7 +67,7 @@ export type TabbedContentItem = {
|
|
65
67
|
/** Content to display when the item is selected. */
|
66
68
|
text?: string;
|
67
69
|
/** Snippet to display. */
|
68
|
-
snippet?: Snippet
|
70
|
+
snippet?: Snippet;
|
69
71
|
/** Component to display. */
|
70
72
|
component?: Component;
|
71
73
|
};
|
@@ -104,7 +104,10 @@ export function matchOnType(el, e) {
|
|
104
104
|
items.forEach((el) => {
|
105
105
|
const contentEl = el.querySelector("span.Content") ?? el.querySelector("label");
|
106
106
|
if (contentEl) {
|
107
|
-
|
107
|
+
// Remove underlines while preserving other elements (like icons)
|
108
|
+
contentEl.querySelectorAll("u").forEach((u) => {
|
109
|
+
u.replaceWith(u.textContent);
|
110
|
+
});
|
108
111
|
}
|
109
112
|
});
|
110
113
|
}
|
@@ -132,13 +135,48 @@ export function matchOnType(el, e) {
|
|
132
135
|
// add underline to the matched text
|
133
136
|
matches.forEach((el) => {
|
134
137
|
const contentEl = el.querySelector("span.Content, label");
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
138
|
+
if (!contentEl)
|
139
|
+
return;
|
140
|
+
// Find all text nodes within contentEl
|
141
|
+
const walker = document.createTreeWalker(contentEl, NodeFilter.SHOW_TEXT, null);
|
142
|
+
let textNode;
|
143
|
+
let fullText = "";
|
144
|
+
const textNodes = [];
|
145
|
+
while (textNode = walker.nextNode()) {
|
146
|
+
textNodes.push(textNode);
|
147
|
+
fullText += textNode.textContent;
|
148
|
+
}
|
149
|
+
const lowerText = fullText.toLowerCase();
|
150
|
+
const matchIndex = lowerText.indexOf(keyMemory);
|
151
|
+
if (matchIndex === -1)
|
152
|
+
return;
|
153
|
+
// Calculate position across text nodes
|
154
|
+
let currentPos = 0;
|
155
|
+
for (const node of textNodes) {
|
156
|
+
const nodeText = node.textContent || "";
|
157
|
+
const nodeLength = nodeText.length;
|
158
|
+
const nodeStart = currentPos;
|
159
|
+
const nodeEnd = currentPos + nodeLength;
|
160
|
+
// Check if this node contains any part of the match
|
161
|
+
if (matchIndex < nodeEnd && matchIndex + keyMemory.length > nodeStart) {
|
162
|
+
const relativeStart = Math.max(0, matchIndex - nodeStart);
|
163
|
+
const relativeEnd = Math.min(nodeLength, matchIndex + keyMemory.length - nodeStart);
|
164
|
+
const before = nodeText.slice(0, relativeStart);
|
165
|
+
const match = nodeText.slice(relativeStart, relativeEnd);
|
166
|
+
const after = nodeText.slice(relativeEnd);
|
167
|
+
const fragment = document.createDocumentFragment();
|
168
|
+
if (before)
|
169
|
+
fragment.appendChild(document.createTextNode(before));
|
170
|
+
if (match) {
|
171
|
+
const u = document.createElement("u");
|
172
|
+
u.textContent = match;
|
173
|
+
fragment.appendChild(u);
|
174
|
+
}
|
175
|
+
if (after)
|
176
|
+
fragment.appendChild(document.createTextNode(after));
|
177
|
+
node.replaceWith(fragment);
|
178
|
+
}
|
179
|
+
currentPos = nodeEnd;
|
142
180
|
}
|
143
181
|
});
|
144
182
|
if (keyMemory.length === 1) {
|