@r2digisolutions/components 0.23.0 → 0.24.0
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/components/atoms/Avatar/Avatar.stories.js +1 -1
- package/dist/components/atoms/BrandMark/BrandMark.svelte +47 -7
- package/dist/components/atoms/BrandMark/BrandMark.svelte.d.ts +4 -0
- package/dist/components/atoms/Input/Input.svelte +5 -4
- package/dist/components/atoms/Slider/Slider.svelte +19 -15
- package/dist/components/atoms/Slider/Slider.svelte.d.ts +2 -0
- package/dist/components/molecules/AuthCard/AuthCard.svelte +19 -4
- package/dist/components/molecules/AuthCard/AuthCard.svelte.d.ts +4 -0
- package/dist/components/molecules/CanvasElementsPanel/CanvasElementsPanel.svelte +90 -26
- package/dist/components/molecules/CanvasInspector/CanvasInspector.svelte +176 -5
- package/dist/components/molecules/ChipBar/ChipBar.svelte +18 -5
- package/dist/components/molecules/ChipBar/ChipBar.svelte.d.ts +1 -1
- package/dist/components/molecules/Combobox/Combobox.svelte +2 -2
- package/dist/components/molecules/DateTimePicker/DateTimePicker.svelte +121 -33
- package/dist/components/molecules/FormSection/FormSection.svelte +25 -28
- package/dist/components/molecules/ImageEditor/ImageEditor.svelte +183 -0
- package/dist/components/molecules/ImageEditor/ImageEditor.svelte.d.ts +19 -0
- package/dist/components/molecules/KnowledgeCard/KnowledgeCard.svelte +5 -5
- package/dist/components/molecules/LocaleSwitcher/LocaleSwitcher.svelte +58 -35
- package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte +293 -39
- package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte.d.ts +6 -1
- package/dist/components/molecules/MediaStage/MediaStage.svelte +302 -245
- package/dist/components/molecules/MentionInput/MentionInput.svelte +332 -120
- package/dist/components/molecules/MentionInput/MentionInput.svelte.d.ts +13 -2
- package/dist/components/molecules/SearchBar/SearchBar.svelte +7 -1
- package/dist/components/molecules/SearchInput/SearchInput.svelte +77 -18
- package/dist/components/molecules/SearchInput/SearchInput.svelte.d.ts +4 -0
- package/dist/components/molecules/SearchInput/SearchInputStory.svelte +1 -0
- package/dist/components/molecules/Select/Select.svelte +14 -1
- package/dist/components/molecules/Select/Select.svelte.d.ts +3 -0
- package/dist/components/molecules/UserMenu/UserMenu.svelte +30 -27
- package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte +200 -17
- package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte.d.ts +14 -0
- package/dist/components/organisms/AppShell/AppShell.svelte +7 -1
- package/dist/components/organisms/AppShell/AppShell.svelte.d.ts +2 -0
- package/dist/components/organisms/AuthShell/AuthShell.svelte +61 -29
- package/dist/components/organisms/AuthShell/AuthShell.svelte.d.ts +4 -0
- package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte +156 -7
- package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte.d.ts +5 -0
- package/dist/components/organisms/Navbar/Navbar.svelte +2 -2
- package/dist/components/organisms/ProfileHeaderUploader/ProfileHeaderUploader.svelte +314 -141
- package/dist/components/organisms/ProfileHeaderUploader/ProfileHeaderUploader.svelte.d.ts +20 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/styles.css +17 -0
- package/dist/utils/canvasDocument.d.ts +56 -4
- package/dist/utils/canvasDocument.js +91 -2
- package/dist/utils/canvasExport.d.ts +1 -1
- package/dist/utils/canvasExport.js +15 -25
- package/package.json +1 -1
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { on } from 'svelte/events';
|
|
3
|
+
import { createId } from '../../../utils/id.js';
|
|
4
|
+
|
|
2
5
|
export interface MentionSuggestion {
|
|
3
6
|
id: string;
|
|
4
7
|
label: string;
|
|
@@ -19,13 +22,21 @@
|
|
|
19
22
|
rows?: number;
|
|
20
23
|
disabled?: boolean;
|
|
21
24
|
readonly?: boolean;
|
|
22
|
-
/** Character that opens mentions. Default `@`. */
|
|
25
|
+
/** Character that opens mentions. Default `@`. Ignored when `triggers` is set. */
|
|
23
26
|
trigger?: string;
|
|
27
|
+
/** Several openers in one field, e.g. `['@', '#']`. */
|
|
28
|
+
triggers?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* Suggestions per opener. When omitted, `suggestions` is used for every trigger
|
|
31
|
+
* (single-trigger fields stay as they were).
|
|
32
|
+
*/
|
|
33
|
+
suggestionsByTrigger?: Record<string, MentionSuggestion[]>;
|
|
24
34
|
/** Max suggestions shown. */
|
|
25
35
|
maxSuggestions?: number;
|
|
26
|
-
/**
|
|
36
|
+
/** Preferred side of the @ or #. The list flips if there is no room. */
|
|
27
37
|
placement?: 'top' | 'bottom';
|
|
28
38
|
class?: string;
|
|
39
|
+
onquery?: (detail: { trigger: string; query: string }) => void;
|
|
29
40
|
onselect?: (item: MentionSuggestion) => void;
|
|
30
41
|
onchange?: (value: string) => void;
|
|
31
42
|
}
|
|
@@ -40,9 +51,12 @@
|
|
|
40
51
|
disabled = false,
|
|
41
52
|
readonly = false,
|
|
42
53
|
trigger = '@',
|
|
54
|
+
triggers,
|
|
55
|
+
suggestionsByTrigger,
|
|
43
56
|
maxSuggestions = 8,
|
|
44
57
|
placement = 'top',
|
|
45
58
|
class: className = '',
|
|
59
|
+
onquery,
|
|
46
60
|
onselect,
|
|
47
61
|
onchange
|
|
48
62
|
}: MentionInputProps = $props();
|
|
@@ -50,15 +64,27 @@
|
|
|
50
64
|
let open = $state(false);
|
|
51
65
|
let query = $state('');
|
|
52
66
|
let caret = $state(0);
|
|
67
|
+
/** Index of the `@` or `#` that opened the list. */
|
|
68
|
+
let anchorIndex = $state(0);
|
|
53
69
|
let activeIndex = $state(0);
|
|
70
|
+
let activeTrigger = $state('');
|
|
54
71
|
let textareaEl = $state<HTMLTextAreaElement | null>(null);
|
|
55
72
|
let listEl = $state<HTMLUListElement | null>(null);
|
|
73
|
+
let popoverEl = $state<HTMLDivElement | null>(null);
|
|
74
|
+
let fieldId = $state('');
|
|
75
|
+
let listId = $state('');
|
|
76
|
+
|
|
77
|
+
const triggerList = $derived(triggers?.length ? triggers : [trigger]);
|
|
78
|
+
const currentTrigger = $derived(activeTrigger || triggerList[0] || '@');
|
|
79
|
+
const pool = $derived(
|
|
80
|
+
suggestionsByTrigger ? (suggestionsByTrigger[currentTrigger] ?? []) : suggestions
|
|
81
|
+
);
|
|
56
82
|
|
|
57
83
|
const escapeRegExp = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
58
84
|
|
|
59
85
|
const filtered = $derived.by(() => {
|
|
60
86
|
const q = query.toLowerCase();
|
|
61
|
-
return
|
|
87
|
+
return pool
|
|
62
88
|
.filter((s) => {
|
|
63
89
|
if (s.disabled) return false;
|
|
64
90
|
if (!q) return true;
|
|
@@ -72,22 +98,43 @@
|
|
|
72
98
|
});
|
|
73
99
|
|
|
74
100
|
const showList = $derived(open && !disabled && !readonly);
|
|
75
|
-
|
|
101
|
+
|
|
102
|
+
$effect(() => {
|
|
103
|
+
fieldId ||= createId('mention-input');
|
|
104
|
+
listId ||= createId('mention-list');
|
|
105
|
+
});
|
|
76
106
|
|
|
77
107
|
function detectMention(text: string, pos: number) {
|
|
78
108
|
const before = text.slice(0, pos);
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
109
|
+
let best: { trigger: string; query: string; start: number } | null = null;
|
|
110
|
+
for (const opener of triggerList) {
|
|
111
|
+
const others = triggerList
|
|
112
|
+
.filter((item) => item !== opener)
|
|
113
|
+
.map(escapeRegExp)
|
|
114
|
+
.join('');
|
|
115
|
+
const re = new RegExp(`${escapeRegExp(opener)}([^\\s${others}]*)$`);
|
|
116
|
+
const match = before.match(re);
|
|
117
|
+
if (!match) continue;
|
|
118
|
+
const candidate = {
|
|
119
|
+
trigger: opener,
|
|
120
|
+
query: match[1] ?? '',
|
|
121
|
+
start: match.index ?? 0
|
|
122
|
+
};
|
|
123
|
+
if (!best || candidate.start >= best.start) best = candidate;
|
|
124
|
+
}
|
|
125
|
+
return best;
|
|
83
126
|
}
|
|
84
127
|
|
|
85
128
|
function syncFromCaret(text: string, pos: number) {
|
|
86
129
|
const mention = detectMention(text, pos);
|
|
87
130
|
if (mention) {
|
|
131
|
+
const changed = mention.query !== query || mention.trigger !== activeTrigger || !open;
|
|
88
132
|
query = mention.query;
|
|
133
|
+
activeTrigger = mention.trigger;
|
|
134
|
+
anchorIndex = mention.start;
|
|
89
135
|
open = true;
|
|
90
|
-
activeIndex = 0;
|
|
136
|
+
if (changed) activeIndex = 0;
|
|
137
|
+
onquery?.({ trigger: mention.trigger, query: mention.query });
|
|
91
138
|
} else {
|
|
92
139
|
open = false;
|
|
93
140
|
query = '';
|
|
@@ -114,8 +161,8 @@
|
|
|
114
161
|
|
|
115
162
|
const before = value.slice(0, caret);
|
|
116
163
|
const after = value.slice(caret);
|
|
117
|
-
const re = new RegExp(`${escapeRegExp(
|
|
118
|
-
const replaced = before.replace(re, `${
|
|
164
|
+
const re = new RegExp(`${escapeRegExp(currentTrigger)}[^\\s]*$`);
|
|
165
|
+
const replaced = before.replace(re, `${currentTrigger}${item.label} `);
|
|
119
166
|
const nextCaret = replaced.length;
|
|
120
167
|
|
|
121
168
|
value = replaced + after;
|
|
@@ -198,26 +245,184 @@
|
|
|
198
245
|
}
|
|
199
246
|
|
|
200
247
|
$effect(() => {
|
|
201
|
-
// Keep activeIndex in range when filter shrinks
|
|
202
248
|
if (activeIndex >= filtered.length) {
|
|
203
249
|
activeIndex = Math.max(0, filtered.length - 1);
|
|
204
250
|
}
|
|
205
251
|
});
|
|
252
|
+
|
|
253
|
+
const MIRROR_PROPS = [
|
|
254
|
+
'direction',
|
|
255
|
+
'boxSizing',
|
|
256
|
+
'width',
|
|
257
|
+
'overflowX',
|
|
258
|
+
'overflowY',
|
|
259
|
+
'borderTopWidth',
|
|
260
|
+
'borderRightWidth',
|
|
261
|
+
'borderBottomWidth',
|
|
262
|
+
'borderLeftWidth',
|
|
263
|
+
'borderStyle',
|
|
264
|
+
'paddingTop',
|
|
265
|
+
'paddingRight',
|
|
266
|
+
'paddingBottom',
|
|
267
|
+
'paddingLeft',
|
|
268
|
+
'fontStyle',
|
|
269
|
+
'fontVariant',
|
|
270
|
+
'fontWeight',
|
|
271
|
+
'fontStretch',
|
|
272
|
+
'fontSize',
|
|
273
|
+
'fontFamily',
|
|
274
|
+
'lineHeight',
|
|
275
|
+
'letterSpacing',
|
|
276
|
+
'textAlign',
|
|
277
|
+
'textTransform',
|
|
278
|
+
'textIndent',
|
|
279
|
+
'wordSpacing',
|
|
280
|
+
'tabSize'
|
|
281
|
+
] as const;
|
|
282
|
+
|
|
283
|
+
/** Viewport box of the character at `index` inside a textarea. */
|
|
284
|
+
function caretBox(textarea: HTMLTextAreaElement, index: number, text: string) {
|
|
285
|
+
const computed = getComputedStyle(textarea);
|
|
286
|
+
const mirror = document.createElement('div');
|
|
287
|
+
const mirrorStyle = mirror.style;
|
|
288
|
+
mirrorStyle.position = 'absolute';
|
|
289
|
+
mirrorStyle.visibility = 'hidden';
|
|
290
|
+
mirrorStyle.whiteSpace = 'pre-wrap';
|
|
291
|
+
mirrorStyle.overflowWrap = 'break-word';
|
|
292
|
+
mirrorStyle.top = '0';
|
|
293
|
+
mirrorStyle.left = '0';
|
|
294
|
+
mirrorStyle.pointerEvents = 'none';
|
|
295
|
+
|
|
296
|
+
for (const prop of MIRROR_PROPS) {
|
|
297
|
+
mirrorStyle[prop] = computed[prop];
|
|
298
|
+
}
|
|
299
|
+
mirrorStyle.whiteSpace = 'pre-wrap';
|
|
300
|
+
mirrorStyle.overflow = 'hidden';
|
|
301
|
+
|
|
302
|
+
const safeIndex = Math.max(0, Math.min(index, text.length));
|
|
303
|
+
mirror.textContent = text.slice(0, safeIndex);
|
|
304
|
+
const marker = document.createElement('span');
|
|
305
|
+
marker.textContent = text.slice(safeIndex, safeIndex + 1) || '.';
|
|
306
|
+
mirror.appendChild(marker);
|
|
307
|
+
document.body.appendChild(mirror);
|
|
308
|
+
|
|
309
|
+
const borderTop = parseFloat(computed.borderTopWidth) || 0;
|
|
310
|
+
const borderLeft = parseFloat(computed.borderLeftWidth) || 0;
|
|
311
|
+
const lineHeight = marker.offsetHeight || parseFloat(computed.lineHeight) || 20;
|
|
312
|
+
const localTop = marker.offsetTop + borderTop;
|
|
313
|
+
const localLeft = marker.offsetLeft + borderLeft;
|
|
314
|
+
mirror.remove();
|
|
315
|
+
|
|
316
|
+
const rect = textarea.getBoundingClientRect();
|
|
317
|
+
return {
|
|
318
|
+
top: rect.top + localTop - textarea.scrollTop,
|
|
319
|
+
left: rect.left + localLeft - textarea.scrollLeft,
|
|
320
|
+
lineHeight,
|
|
321
|
+
field: rect
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function placePopover() {
|
|
326
|
+
if (!textareaEl || !popoverEl) return;
|
|
327
|
+
const index = anchorIndex;
|
|
328
|
+
const text = value;
|
|
329
|
+
const rect = textareaEl.getBoundingClientRect();
|
|
330
|
+
if (rect.width < 2) return;
|
|
331
|
+
|
|
332
|
+
const gap = 6;
|
|
333
|
+
const margin = 8;
|
|
334
|
+
const point = caretBox(textareaEl, index, text);
|
|
335
|
+
const fieldStyle = getComputedStyle(textareaEl);
|
|
336
|
+
const borderTop = parseFloat(fieldStyle.borderTopWidth) || 0;
|
|
337
|
+
const borderBottom = parseFloat(fieldStyle.borderBottomWidth) || 0;
|
|
338
|
+
const borderLeft = parseFloat(fieldStyle.borderLeftWidth) || 0;
|
|
339
|
+
const borderRight = parseFloat(fieldStyle.borderRightWidth) || 0;
|
|
340
|
+
const visibleTop = rect.top + borderTop;
|
|
341
|
+
const visibleBottom = rect.bottom - borderBottom;
|
|
342
|
+
const visibleLeft = rect.left + borderLeft;
|
|
343
|
+
const visibleRight = rect.right - borderRight;
|
|
344
|
+
|
|
345
|
+
let lineTop = point.top;
|
|
346
|
+
let lineBottom = point.top + point.lineHeight;
|
|
347
|
+
if (lineBottom < visibleTop) {
|
|
348
|
+
lineTop = visibleTop;
|
|
349
|
+
lineBottom = visibleTop;
|
|
350
|
+
} else if (lineTop > visibleBottom) {
|
|
351
|
+
lineTop = visibleBottom;
|
|
352
|
+
lineBottom = visibleBottom;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
let anchorLeft = point.left;
|
|
356
|
+
if (anchorLeft < visibleLeft) anchorLeft = visibleLeft;
|
|
357
|
+
if (anchorLeft > visibleRight - 12) anchorLeft = Math.max(visibleLeft, visibleRight - 12);
|
|
358
|
+
|
|
359
|
+
const width = Math.min(320, rect.width, window.innerWidth - margin * 2);
|
|
360
|
+
const maxLeft = window.innerWidth - margin - width;
|
|
361
|
+
const left = Math.min(Math.max(margin, anchorLeft), Math.max(margin, maxLeft));
|
|
362
|
+
|
|
363
|
+
const spaceBelow = window.innerHeight - lineBottom - gap - margin;
|
|
364
|
+
const spaceAbove = lineTop - gap - margin;
|
|
365
|
+
const openUp =
|
|
366
|
+
placement === 'top' ? spaceAbove > 80 : spaceBelow < 120 && spaceAbove > spaceBelow;
|
|
367
|
+
const height = Math.min(256, Math.max(72, openUp ? spaceAbove : spaceBelow));
|
|
368
|
+
|
|
369
|
+
popoverEl.style.width = `${width}px`;
|
|
370
|
+
popoverEl.style.maxHeight = `${height}px`;
|
|
371
|
+
popoverEl.style.left = `${left}px`;
|
|
372
|
+
const used = Math.min(popoverEl.offsetHeight || height, height);
|
|
373
|
+
popoverEl.style.top = openUp
|
|
374
|
+
? `${Math.max(margin, lineTop - gap - used)}px`
|
|
375
|
+
: `${lineBottom + gap}px`;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
$effect(() => {
|
|
379
|
+
const el = popoverEl;
|
|
380
|
+
const visible = showList && (filtered.length > 0 || query.length > 0);
|
|
381
|
+
if (!el) return;
|
|
382
|
+
if (visible) {
|
|
383
|
+
if (!el.matches(':popover-open')) el.showPopover();
|
|
384
|
+
placePopover();
|
|
385
|
+
} else if (el.matches(':popover-open')) {
|
|
386
|
+
el.hidePopover();
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
$effect(() => {
|
|
391
|
+
if (!showList) return;
|
|
392
|
+
const field = textareaEl;
|
|
393
|
+
const offResize = on(window, 'resize', () => placePopover());
|
|
394
|
+
const offScroll = on(window, 'scroll', () => placePopover(), { capture: true });
|
|
395
|
+
const offFieldScroll = field ? on(field, 'scroll', () => placePopover()) : () => {};
|
|
396
|
+
const observer = field ? new ResizeObserver(() => placePopover()) : null;
|
|
397
|
+
if (field) observer?.observe(field);
|
|
398
|
+
const offPointer = on(window, 'pointerdown', (event) => {
|
|
399
|
+
const target = event.target as Node | null;
|
|
400
|
+
if (textareaEl?.contains(target) || popoverEl?.contains(target)) return;
|
|
401
|
+
open = false;
|
|
402
|
+
});
|
|
403
|
+
return () => {
|
|
404
|
+
offResize();
|
|
405
|
+
offScroll();
|
|
406
|
+
offFieldScroll();
|
|
407
|
+
observer?.disconnect();
|
|
408
|
+
offPointer();
|
|
409
|
+
};
|
|
410
|
+
});
|
|
206
411
|
</script>
|
|
207
412
|
|
|
208
|
-
<div class={['flex w-full flex-col
|
|
413
|
+
<div class={['gap-1.5 flex w-full flex-col', className]}>
|
|
209
414
|
{#if label}
|
|
210
|
-
<label class="text-sm font-medium text-primary" for=
|
|
415
|
+
<label class="text-sm font-medium text-primary" for={fieldId}>{label}</label>
|
|
211
416
|
{/if}
|
|
212
417
|
|
|
213
|
-
<div
|
|
418
|
+
<div>
|
|
214
419
|
<textarea
|
|
215
420
|
bind:this={textareaEl}
|
|
216
|
-
id=
|
|
421
|
+
id={fieldId}
|
|
217
422
|
class={[
|
|
218
|
-
'
|
|
219
|
-
'placeholder:text-muted outline-none
|
|
220
|
-
'focus:border-brand-500 focus:ring-
|
|
423
|
+
'rounded-xl border-border bg-surface-elevated px-3.5 py-2.5 text-sm text-primary shadow-sm w-full resize-y border',
|
|
424
|
+
'placeholder:text-muted transition outline-none',
|
|
425
|
+
'focus:border-brand-500 focus:ring-brand-500/20 focus:ring-2',
|
|
221
426
|
disabled && 'cursor-not-allowed opacity-60',
|
|
222
427
|
readonly && 'bg-surface'
|
|
223
428
|
]}
|
|
@@ -239,120 +444,127 @@
|
|
|
239
444
|
onclick={onSelect}
|
|
240
445
|
onkeyup={(e) => {
|
|
241
446
|
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') onSelect();
|
|
242
|
-
}}
|
|
243
|
-
></textarea>
|
|
244
|
-
|
|
245
|
-
{#if showList}
|
|
246
|
-
<div
|
|
247
|
-
class={[
|
|
248
|
-
'absolute left-0 z-30 w-full',
|
|
249
|
-
placement === 'top' ? 'bottom-full mb-2' : 'top-full mt-2'
|
|
250
|
-
]}
|
|
251
|
-
>
|
|
252
|
-
{#if filtered.length}
|
|
253
|
-
<ul
|
|
254
|
-
bind:this={listEl}
|
|
255
|
-
id={listId}
|
|
256
|
-
class="max-h-64 overflow-auto rounded-xl border border-border bg-surface-elevated py-1.5 shadow-xl"
|
|
257
|
-
role="listbox"
|
|
258
|
-
aria-label="Mention suggestions"
|
|
259
|
-
>
|
|
260
|
-
<li class="px-3 pb-1.5 pt-1 text-[10px] font-medium uppercase tracking-wide text-muted">
|
|
261
|
-
Mentions
|
|
262
|
-
{#if query}
|
|
263
|
-
<span class="normal-case tracking-normal text-secondary"> · {trigger}{query}</span>
|
|
264
|
-
{/if}
|
|
265
|
-
</li>
|
|
266
|
-
{#each filtered as item, i (item.id)}
|
|
267
|
-
{@const active = i === activeIndex}
|
|
268
|
-
<li role="presentation">
|
|
269
|
-
<button
|
|
270
|
-
type="button"
|
|
271
|
-
id="mention-option-{item.id}"
|
|
272
|
-
data-mention-index={i}
|
|
273
|
-
role="option"
|
|
274
|
-
aria-selected={active}
|
|
275
|
-
class={[
|
|
276
|
-
'flex w-full items-center gap-3 px-3 py-2 text-left transition-colors',
|
|
277
|
-
active
|
|
278
|
-
? 'bg-brand-50 dark:bg-brand-950/40'
|
|
279
|
-
: 'hover:bg-surface-overlay'
|
|
280
|
-
]}
|
|
281
|
-
onmousedown={(e) => e.preventDefault()}
|
|
282
|
-
onclick={() => insert(item)}
|
|
283
|
-
onmouseenter={() => (activeIndex = i)}
|
|
284
|
-
>
|
|
285
|
-
{#if item.avatar}
|
|
286
|
-
<img
|
|
287
|
-
src={item.avatar}
|
|
288
|
-
alt=""
|
|
289
|
-
class="h-8 w-8 shrink-0 rounded-full object-cover ring-1 ring-border"
|
|
290
|
-
/>
|
|
291
|
-
{:else}
|
|
292
|
-
<span
|
|
293
|
-
class={[
|
|
294
|
-
'flex h-8 w-8 shrink-0 items-center justify-center rounded-full text-[11px] font-semibold',
|
|
295
|
-
active
|
|
296
|
-
? 'bg-brand-500 text-white'
|
|
297
|
-
: 'bg-surface-overlay text-secondary'
|
|
298
|
-
]}
|
|
299
|
-
>
|
|
300
|
-
{initials(item.label)}
|
|
301
|
-
</span>
|
|
302
|
-
{/if}
|
|
447
|
+
}}></textarea>
|
|
303
448
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
449
|
+
<div
|
|
450
|
+
bind:this={popoverEl}
|
|
451
|
+
popover="manual"
|
|
452
|
+
class="mention-popover rounded-xl border-border bg-surface-elevated shadow-xl overflow-auto border outline-none"
|
|
453
|
+
>
|
|
454
|
+
{#if showList && filtered.length}
|
|
455
|
+
<ul bind:this={listEl} id={listId} class="py-1.5" role="listbox" aria-label="Suggestions">
|
|
456
|
+
<li class="px-3 pb-1.5 pt-1 font-medium tracking-wide text-muted text-[10px] uppercase">
|
|
457
|
+
{currentTrigger === '#' ? 'Hashtags' : 'Mentions'}
|
|
458
|
+
{#if query}
|
|
459
|
+
<span class="tracking-normal text-secondary normal-case">
|
|
460
|
+
· {currentTrigger}{query}</span
|
|
461
|
+
>
|
|
462
|
+
{/if}
|
|
463
|
+
</li>
|
|
464
|
+
{#each filtered as item, i (item.id)}
|
|
465
|
+
{@const active = i === activeIndex}
|
|
466
|
+
<li role="presentation">
|
|
467
|
+
<button
|
|
468
|
+
type="button"
|
|
469
|
+
id="mention-option-{item.id}"
|
|
470
|
+
data-mention-index={i}
|
|
471
|
+
role="option"
|
|
472
|
+
aria-selected={active}
|
|
473
|
+
class={[
|
|
474
|
+
'gap-3 px-3 py-2 flex w-full items-center text-left transition-colors',
|
|
475
|
+
active ? 'bg-brand-50 dark:bg-brand-950/40' : 'hover:bg-surface-overlay'
|
|
476
|
+
]}
|
|
477
|
+
onmousedown={(e) => e.preventDefault()}
|
|
478
|
+
onclick={() => insert(item)}
|
|
479
|
+
onmouseenter={() => (activeIndex = i)}
|
|
480
|
+
>
|
|
481
|
+
{#if item.avatar}
|
|
482
|
+
<img
|
|
483
|
+
src={item.avatar}
|
|
484
|
+
alt=""
|
|
485
|
+
class="h-8 w-8 ring-border shrink-0 rounded-full object-cover ring-1"
|
|
486
|
+
/>
|
|
487
|
+
{:else}
|
|
488
|
+
<span
|
|
489
|
+
class={[
|
|
490
|
+
'h-8 w-8 font-semibold flex shrink-0 items-center justify-center rounded-full text-[11px]',
|
|
491
|
+
active ? 'bg-brand-500 text-white' : 'bg-surface-overlay text-secondary'
|
|
492
|
+
]}
|
|
493
|
+
>
|
|
494
|
+
{initials(item.label)}
|
|
321
495
|
</span>
|
|
496
|
+
{/if}
|
|
322
497
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
498
|
+
<span class="min-w-0 flex-1">
|
|
499
|
+
<span class="text-sm font-medium text-primary block truncate">
|
|
500
|
+
{currentTrigger}{#each highlight(item.label, query) as part, index (index)}
|
|
501
|
+
{#if part.match}
|
|
502
|
+
<mark class="rounded-sm bg-brand-500/20 text-brand-700 dark:text-brand-300"
|
|
503
|
+
>{part.text}</mark
|
|
504
|
+
>
|
|
505
|
+
{:else}
|
|
506
|
+
{part.text}
|
|
507
|
+
{/if}
|
|
508
|
+
{/each}
|
|
509
|
+
</span>
|
|
510
|
+
{#if item.description || item.meta}
|
|
511
|
+
<span class="text-xs text-muted block truncate">
|
|
512
|
+
{item.description ?? item.meta}
|
|
326
513
|
</span>
|
|
327
514
|
{/if}
|
|
328
|
-
</
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
515
|
+
</span>
|
|
516
|
+
|
|
517
|
+
{#if active}
|
|
518
|
+
<span class="font-medium text-muted sm:inline hidden shrink-0 text-[10px]">
|
|
519
|
+
↵
|
|
520
|
+
</span>
|
|
521
|
+
{/if}
|
|
522
|
+
</button>
|
|
523
|
+
</li>
|
|
524
|
+
{/each}
|
|
525
|
+
</ul>
|
|
526
|
+
{:else if showList && query}
|
|
527
|
+
<div class="px-3 py-3 text-sm text-muted text-center" role="status">
|
|
528
|
+
No matches for “{query}”
|
|
529
|
+
</div>
|
|
530
|
+
{/if}
|
|
531
|
+
</div>
|
|
342
532
|
</div>
|
|
343
533
|
|
|
344
534
|
{#if helperText}
|
|
345
535
|
<p class="text-xs text-muted">{helperText}</p>
|
|
346
536
|
{:else}
|
|
347
|
-
<p class="text-[11px]
|
|
348
|
-
<span class="font-medium text-secondary">{
|
|
349
|
-
<kbd class="rounded border
|
|
350
|
-
<kbd class="rounded border
|
|
537
|
+
<p class="text-muted text-[11px]">
|
|
538
|
+
<span class="font-medium text-secondary">{triggerList.join(' ')}</span> to insert ·
|
|
539
|
+
<kbd class="rounded border-border bg-surface px-1 py-0.5 font-mono border text-[10px]">↑</kbd>
|
|
540
|
+
<kbd class="rounded border-border bg-surface px-1 py-0.5 font-mono border text-[10px]">↓</kbd>
|
|
351
541
|
navigate ·
|
|
352
|
-
<kbd class="rounded border
|
|
542
|
+
<kbd class="rounded border-border bg-surface px-1 py-0.5 font-mono border text-[10px]"
|
|
543
|
+
>Enter</kbd
|
|
544
|
+
>
|
|
353
545
|
select ·
|
|
354
|
-
<kbd class="rounded border
|
|
546
|
+
<kbd class="rounded border-border bg-surface px-1 py-0.5 font-mono border text-[10px]"
|
|
547
|
+
>Esc</kbd
|
|
548
|
+
>
|
|
355
549
|
close
|
|
356
550
|
</p>
|
|
357
551
|
{/if}
|
|
358
552
|
</div>
|
|
553
|
+
|
|
554
|
+
<style>
|
|
555
|
+
.mention-popover {
|
|
556
|
+
position: fixed;
|
|
557
|
+
inset: unset;
|
|
558
|
+
margin: 0;
|
|
559
|
+
width: max-content;
|
|
560
|
+
height: max-content;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
.mention-popover:popover-open {
|
|
564
|
+
display: block;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
.mention-popover:not(:popover-open) {
|
|
568
|
+
display: none;
|
|
569
|
+
}
|
|
570
|
+
</style>
|
|
@@ -17,13 +17,24 @@ interface MentionInputProps {
|
|
|
17
17
|
rows?: number;
|
|
18
18
|
disabled?: boolean;
|
|
19
19
|
readonly?: boolean;
|
|
20
|
-
/** Character that opens mentions. Default `@`. */
|
|
20
|
+
/** Character that opens mentions. Default `@`. Ignored when `triggers` is set. */
|
|
21
21
|
trigger?: string;
|
|
22
|
+
/** Several openers in one field, e.g. `['@', '#']`. */
|
|
23
|
+
triggers?: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Suggestions per opener. When omitted, `suggestions` is used for every trigger
|
|
26
|
+
* (single-trigger fields stay as they were).
|
|
27
|
+
*/
|
|
28
|
+
suggestionsByTrigger?: Record<string, MentionSuggestion[]>;
|
|
22
29
|
/** Max suggestions shown. */
|
|
23
30
|
maxSuggestions?: number;
|
|
24
|
-
/**
|
|
31
|
+
/** Preferred side of the @ or #. The list flips if there is no room. */
|
|
25
32
|
placement?: 'top' | 'bottom';
|
|
26
33
|
class?: string;
|
|
34
|
+
onquery?: (detail: {
|
|
35
|
+
trigger: string;
|
|
36
|
+
query: string;
|
|
37
|
+
}) => void;
|
|
27
38
|
onselect?: (item: MentionSuggestion) => void;
|
|
28
39
|
onchange?: (value: string) => void;
|
|
29
40
|
}
|
|
@@ -59,7 +59,13 @@
|
|
|
59
59
|
|
|
60
60
|
function submit() {
|
|
61
61
|
if (busy) return;
|
|
62
|
-
|
|
62
|
+
const el =
|
|
63
|
+
typeof document !== 'undefined'
|
|
64
|
+
? (document.getElementById(inputId) as HTMLInputElement | null)
|
|
65
|
+
: null;
|
|
66
|
+
const live = el?.value ?? value;
|
|
67
|
+
value = live;
|
|
68
|
+
onsubmit?.(live);
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
function clear() {
|