@r2digisolutions/components 0.23.1 → 0.24.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.
Files changed (43) hide show
  1. package/dist/components/atoms/BrandMark/BrandMark.svelte +47 -7
  2. package/dist/components/atoms/BrandMark/BrandMark.svelte.d.ts +4 -0
  3. package/dist/components/atoms/Slider/Slider.svelte +19 -15
  4. package/dist/components/atoms/Slider/Slider.svelte.d.ts +2 -0
  5. package/dist/components/atoms/VerifiedBadge/VerifiedBadge.svelte +76 -0
  6. package/dist/components/atoms/VerifiedBadge/VerifiedBadge.svelte.d.ts +12 -0
  7. package/dist/components/molecules/AuthCard/AuthCard.svelte +19 -4
  8. package/dist/components/molecules/AuthCard/AuthCard.svelte.d.ts +4 -0
  9. package/dist/components/molecules/CanvasElementsPanel/CanvasElementsPanel.svelte +90 -26
  10. package/dist/components/molecules/CanvasInspector/CanvasInspector.svelte +176 -5
  11. package/dist/components/molecules/Combobox/Combobox.svelte +2 -2
  12. package/dist/components/molecules/DateTimePicker/DateTimePicker.svelte +121 -33
  13. package/dist/components/molecules/FormSection/FormSection.svelte +25 -28
  14. package/dist/components/molecules/ImageEditor/ImageEditor.svelte +183 -0
  15. package/dist/components/molecules/ImageEditor/ImageEditor.svelte.d.ts +19 -0
  16. package/dist/components/molecules/LocaleSwitcher/LocaleSwitcher.svelte +58 -35
  17. package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte +293 -39
  18. package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte.d.ts +6 -1
  19. package/dist/components/molecules/MediaStage/MediaStage.svelte +302 -245
  20. package/dist/components/molecules/MentionInput/MentionInput.svelte +332 -120
  21. package/dist/components/molecules/MentionInput/MentionInput.svelte.d.ts +13 -2
  22. package/dist/components/molecules/Select/Select.svelte +14 -1
  23. package/dist/components/molecules/Select/Select.svelte.d.ts +3 -0
  24. package/dist/components/molecules/UserMenu/UserMenu.svelte +30 -27
  25. package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte +200 -17
  26. package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte.d.ts +14 -0
  27. package/dist/components/organisms/AppShell/AppShell.svelte +7 -1
  28. package/dist/components/organisms/AppShell/AppShell.svelte.d.ts +2 -0
  29. package/dist/components/organisms/AuthShell/AuthShell.svelte +61 -29
  30. package/dist/components/organisms/AuthShell/AuthShell.svelte.d.ts +4 -0
  31. package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte +156 -7
  32. package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte.d.ts +5 -0
  33. package/dist/components/organisms/Navbar/Navbar.svelte +2 -2
  34. package/dist/components/organisms/ProfileHeaderUploader/ProfileHeaderUploader.svelte +343 -140
  35. package/dist/components/organisms/ProfileHeaderUploader/ProfileHeaderUploader.svelte.d.ts +25 -1
  36. package/dist/index.d.ts +4 -1
  37. package/dist/index.js +3 -1
  38. package/dist/styles.css +17 -0
  39. package/dist/utils/canvasDocument.d.ts +56 -4
  40. package/dist/utils/canvasDocument.js +91 -2
  41. package/dist/utils/canvasExport.d.ts +1 -1
  42. package/dist/utils/canvasExport.js +15 -25
  43. 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
- /** Dropdown above or below the field. */
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 suggestions
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
- const listId = 'mention-listbox';
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
- const re = new RegExp(`${escapeRegExp(trigger)}([\\w.-]*)$`);
80
- const match = before.match(re);
81
- if (!match) return null;
82
- return { query: match[1] ?? '', start: match.index ?? 0 };
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(trigger)}[\\w.-]*$`);
118
- const replaced = before.replace(re, `${trigger}${item.label} `);
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 gap-1.5', className]}>
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="mention-input">{label}</label>
415
+ <label class="text-sm font-medium text-primary" for={fieldId}>{label}</label>
211
416
  {/if}
212
417
 
213
- <div class="relative">
418
+ <div>
214
419
  <textarea
215
420
  bind:this={textareaEl}
216
- id="mention-input"
421
+ id={fieldId}
217
422
  class={[
218
- 'w-full resize-y rounded-xl border border-border bg-surface-elevated px-3.5 py-2.5 text-sm text-primary shadow-sm',
219
- 'placeholder:text-muted outline-none transition',
220
- 'focus:border-brand-500 focus:ring-2 focus:ring-brand-500/20',
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
- <span class="min-w-0 flex-1">
305
- <span class="block truncate text-sm font-medium text-primary">
306
- {trigger}{#each highlight(item.label, query) as part}
307
- {#if part.match}
308
- <mark class="rounded-sm bg-brand-500/20 text-brand-700 dark:text-brand-300"
309
- >{part.text}</mark
310
- >
311
- {:else}
312
- {part.text}
313
- {/if}
314
- {/each}
315
- </span>
316
- {#if item.description || item.meta}
317
- <span class="block truncate text-xs text-muted">
318
- {item.description ?? item.meta}
319
- </span>
320
- {/if}
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
- {#if active}
324
- <span class="hidden shrink-0 text-[10px] font-medium text-muted sm:inline">
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
- </button>
329
- </li>
330
- {/each}
331
- </ul>
332
- {:else if query}
333
- <div
334
- class="rounded-xl border border-border bg-surface-elevated px-3 py-3 text-center text-sm text-muted shadow-xl"
335
- role="status"
336
- >
337
- No one matching “{query}”
338
- </div>
339
- {/if}
340
- </div>
341
- {/if}
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] text-muted">
348
- <span class="font-medium text-secondary">{trigger}</span> to mention ·
349
- <kbd class="rounded border border-border bg-surface px-1 py-0.5 font-mono text-[10px]">↑</kbd>
350
- <kbd class="rounded border border-border bg-surface px-1 py-0.5 font-mono text-[10px]">↓</kbd>
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 border-border bg-surface px-1 py-0.5 font-mono text-[10px]">Enter</kbd>
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 border-border bg-surface px-1 py-0.5 font-mono text-[10px]">Esc</kbd>
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
- /** Dropdown above or below the field. */
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
  }
@@ -1,4 +1,5 @@
1
1
  <script lang="ts">
2
+ import type { Snippet } from 'svelte';
2
3
  import { on } from 'svelte/events';
3
4
  import { createId } from '../../../utils/id.js';
4
5
  import { popoverInvokerToggle } from '../../../utils/popoverInvoker.js';
@@ -37,6 +38,8 @@
37
38
  listboxMinWidth?: number;
38
39
  class?: string;
39
40
  onchange?: (value: string) => void;
41
+ /** Extra row at the bottom of the list (for example, create). */
42
+ footer?: Snippet;
40
43
  }
41
44
 
42
45
  let {
@@ -55,7 +58,8 @@
55
58
  size = 'md',
56
59
  listboxMinWidth,
57
60
  class: className = '',
58
- onchange
61
+ onchange,
62
+ footer
59
63
  }: SelectProps = $props();
60
64
 
61
65
  let isOpen = $state(false);
@@ -739,6 +743,15 @@
739
743
  {/each}
740
744
  {/if}
741
745
  </div>
746
+ {#if footer}
747
+ <div
748
+ class="border-border p-1.5 shrink-0 border-t"
749
+ role="presentation"
750
+ onclick={() => closeListbox()}
751
+ >
752
+ {@render footer()}
753
+ </div>
754
+ {/if}
742
755
  </div>
743
756
  </div>
744
757
 
@@ -1,3 +1,4 @@
1
+ import type { Snippet } from 'svelte';
1
2
  export interface SelectOption {
2
3
  value: string;
3
4
  label: string;
@@ -31,6 +32,8 @@ interface SelectProps {
31
32
  listboxMinWidth?: number;
32
33
  class?: string;
33
34
  onchange?: (value: string) => void;
35
+ /** Extra row at the bottom of the list (for example, create). */
36
+ footer?: Snippet;
34
37
  }
35
38
  declare const Select: import("svelte").Component<SelectProps, {}, "value">;
36
39
  type Select = ReturnType<typeof Select>;