@sybilion/uilib 1.3.43 → 1.3.46

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 (56) hide show
  1. package/assets/logo.svg +1 -1
  2. package/dist/esm/components/ui/Chart/Chart.styl.js +1 -1
  3. package/dist/esm/components/ui/ChartAreaInteractive/ChartAreaInteractive.js +7 -1
  4. package/dist/esm/components/ui/Chat/ChatPrompt/ChatPrompt.js +7 -5
  5. package/dist/esm/components/ui/Chat/ChatPrompt/ChatPrompt.styl.js +1 -1
  6. package/dist/esm/components/ui/Chat/ChatPrompt/ChatPromptComposer.js +8 -4
  7. package/dist/esm/components/ui/Chat/ChatPrompt/chatPromptComposerInsert.js +67 -0
  8. package/dist/esm/components/ui/Chat/ChatPrompt/useChatPromptEditor.js +24 -17
  9. package/dist/esm/components/ui/Logo/Logo.styl.js +1 -1
  10. package/dist/esm/components/ui/Logo/logo.svg.js +1 -1
  11. package/dist/esm/components/ui/Page/PageFooter/PageFooter.js +3 -2
  12. package/dist/esm/components/ui/Page/PageHeader/PageHeader.js +1 -1
  13. package/dist/esm/components/ui/TextWithDeferTooltip/TextWithDeferTooltip.js +23 -1
  14. package/dist/esm/components/widgets/DriverCard/DriverCard.js +1 -1
  15. package/dist/esm/components/widgets/DriversComparisonChart/DriversComparisonChart.js +1 -0
  16. package/dist/esm/components/widgets/PerformanceChart/PerformanceTable.js +1 -0
  17. package/dist/esm/index.js +1 -0
  18. package/dist/esm/tiptap/slash-mention/SlashSuggestionList.styl.js +2 -2
  19. package/dist/esm/tiptap/slash-mention/createSlashMentionExtension.js +45 -28
  20. package/dist/esm/types/src/components/ui/Chat/Chat.d.ts +1 -2
  21. package/dist/esm/types/src/components/ui/Chat/Chat.types.d.ts +1 -1
  22. package/dist/esm/types/src/components/ui/Chat/ChatPrompt/ChatPrompt.d.ts +3 -1
  23. package/dist/esm/types/src/components/ui/Chat/ChatPrompt/ChatPromptComposer.d.ts +3 -3
  24. package/dist/esm/types/src/components/ui/Chat/ChatPrompt/ChatPromptComposer.types.d.ts +2 -0
  25. package/dist/esm/types/src/components/ui/Chat/ChatPrompt/chatPromptComposerInsert.d.ts +35 -0
  26. package/dist/esm/types/src/components/ui/Chat/ChatPrompt/useChatPromptEditor.d.ts +0 -2
  27. package/dist/esm/types/src/components/ui/Chat/index.d.ts +3 -0
  28. package/dist/esm/types/src/components/ui/Page/PageFooter/PageFooter.d.ts +1 -2
  29. package/dist/esm/types/src/docs/pages/ChatSheetPage.d.ts +1 -0
  30. package/dist/esm/types/src/tiptap/slash-mention/types.d.ts +7 -2
  31. package/package.json +1 -1
  32. package/src/components/ui/Chart/Chart.styl +2 -1
  33. package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.tsx +8 -1
  34. package/src/components/ui/Chat/Chat.types.ts +1 -1
  35. package/src/components/ui/Chat/ChatPrompt/ChatPrompt.styl +26 -1
  36. package/src/components/ui/Chat/ChatPrompt/ChatPrompt.tsx +86 -65
  37. package/src/components/ui/Chat/ChatPrompt/ChatPromptComposer.tsx +31 -13
  38. package/src/components/ui/Chat/ChatPrompt/ChatPromptComposer.types.ts +11 -0
  39. package/src/components/ui/Chat/ChatPrompt/chatPromptComposerInsert.ts +122 -0
  40. package/src/components/ui/Chat/ChatPrompt/useChatPromptEditor.ts +34 -21
  41. package/src/components/ui/Chat/index.ts +9 -0
  42. package/src/components/ui/Logo/Logo.styl +1 -0
  43. package/src/components/ui/Logo/logo.svg +1 -1
  44. package/src/components/ui/Page/PageFooter/PageFooter.tsx +2 -3
  45. package/src/components/ui/Page/PageHeader/PageHeader.tsx +1 -1
  46. package/src/components/ui/TextWithDeferTooltip/TextWithDeferTooltip.tsx +35 -4
  47. package/src/components/widgets/DriverCard/DriverCard.tsx +5 -1
  48. package/src/docs/DocsShell.tsx +1 -6
  49. package/src/docs/pages/ChatSheetPage.tsx +61 -0
  50. package/src/docs/pages/ChatSlashCommandsPage.tsx +46 -120
  51. package/src/docs/pages/TooltipPage.tsx +0 -31
  52. package/src/docs/registry.ts +6 -0
  53. package/src/tiptap/slash-mention/SlashSuggestionList.styl +4 -0
  54. package/src/tiptap/slash-mention/SlashSuggestionList.styl.d.ts +1 -0
  55. package/src/tiptap/slash-mention/createSlashMentionExtension.ts +46 -27
  56. package/src/tiptap/slash-mention/types.ts +7 -2
@@ -10,6 +10,7 @@ import {
10
10
  SlashSuggestionList,
11
11
  type SlashSuggestionListHandle,
12
12
  } from './SlashSuggestionList';
13
+ import S from './SlashSuggestionList.styl';
13
14
  import { filterSlashItems } from './defaultChatSlashItems';
14
15
  import type {
15
16
  CreateSlashMentionExtensionOptions,
@@ -17,6 +18,30 @@ import type {
17
18
  SlashSuggestionPlacement,
18
19
  } from './types';
19
20
 
21
+ const SlashMention = Mention.extend({
22
+ addAttributes() {
23
+ return {
24
+ ...this.parent?.(),
25
+ className: {
26
+ default: null,
27
+ parseHTML: element => element.getAttribute('data-slash-class'),
28
+ renderHTML: attributes => {
29
+ if (!attributes.className) return {};
30
+ return { 'data-slash-class': attributes.className };
31
+ },
32
+ },
33
+ color: {
34
+ default: null,
35
+ parseHTML: element => element.getAttribute('data-slash-color'),
36
+ renderHTML: attributes => {
37
+ if (!attributes.color) return {};
38
+ return { 'data-slash-color': attributes.color };
39
+ },
40
+ },
41
+ };
42
+ },
43
+ });
44
+
20
45
  const SUGGESTION_GAP_PX = 4;
21
46
 
22
47
  function placeSlashSuggestionPopup(
@@ -124,28 +149,11 @@ export function slashMentionSuggestionRender(
124
149
  };
125
150
  }
126
151
 
127
- function clearSlashTriggerEditor(
128
- editor: Editor,
129
- range: { from: number; to: number },
130
- ): void {
131
- if (editor.isDestroyed) return;
132
- try {
133
- editor.chain().focus().deleteRange(range).clearContent().run();
134
- } catch {
135
- // Editor view may be tearing down during suggestion exit.
136
- }
152
+ function slashMentionChipStyle(color: string | null): string | undefined {
153
+ if (!color) return undefined;
154
+ return `color: ${color}; background-color: color-mix(in srgb, ${color} 30%, transparent);`;
137
155
  }
138
156
 
139
- function collapseEditorSelectionEnd(editor: Editor): void {
140
- if (editor.isDestroyed) return;
141
- try {
142
- editor.view?.dom?.ownerDocument?.defaultView
143
- ?.getSelection?.()
144
- ?.collapseToEnd();
145
- } catch {
146
- // view.dom throws when editor is not mounted
147
- }
148
- }
149
157
  function insertDefaultMention(
150
158
  editor: Editor,
151
159
  range: { from: number; to: number },
@@ -166,6 +174,8 @@ function insertDefaultMention(
166
174
  id: props.id,
167
175
  label: props.label,
168
176
  mentionSuggestionChar: slashChar,
177
+ className: props.className ?? null,
178
+ color: props.color ?? null,
169
179
  },
170
180
  },
171
181
  { type: 'text', text: ' ' },
@@ -212,27 +222,38 @@ export function createSlashMentionExtension({
212
222
  current: null,
213
223
  };
214
224
 
215
- return Mention.configure({
225
+ return SlashMention.configure({
216
226
  renderText({ node }) {
217
227
  return `/${node.attrs.id as string}`;
218
228
  },
219
- renderHTML({ options, node, suggestion }) {
220
- const suggestionChar = suggestion?.char ?? slashChar;
229
+ renderHTML({ options, node }) {
221
230
  const id =
222
231
  typeof node.attrs.id === 'string'
223
232
  ? node.attrs.id
224
233
  : String(node.attrs.id ?? '');
234
+ const label =
235
+ typeof node.attrs.label === 'string' && node.attrs.label.trim() !== ''
236
+ ? node.attrs.label
237
+ : id;
238
+ const color =
239
+ typeof node.attrs.color === 'string' ? node.attrs.color : null;
240
+ const className = [S.mention, node.attrs.className]
241
+ .filter(Boolean)
242
+ .join(' ');
243
+ const chipStyle = slashMentionChipStyle(color);
244
+
225
245
  return [
226
246
  'span',
227
247
  mergeAttributes(
228
248
  {
229
249
  'data-type': 'mention',
230
250
  'data-slash-command': id,
231
- class: 'slash-mention',
251
+ class: className,
252
+ ...(chipStyle ? { style: chipStyle } : {}),
232
253
  },
233
254
  options.HTMLAttributes,
234
255
  ),
235
- `${suggestionChar}${id}`,
256
+ label,
236
257
  ];
237
258
  },
238
259
  suggestion: {
@@ -245,8 +266,6 @@ export function createSlashMentionExtension({
245
266
  command: ({ editor, range, props }) => {
246
267
  const item = props as SlashCommandItem;
247
268
  if (onItemCommand?.({ editor, range, item }) === true) {
248
- clearSlashTriggerEditor(editor, range);
249
- queueMicrotask(() => collapseEditorSelectionEnd(editor));
250
269
  return null;
251
270
  }
252
271
  insertDefaultMention(editor, range, item, slashChar);
@@ -4,6 +4,10 @@ export type SlashCommandItem = {
4
4
  id: string;
5
5
  label: string;
6
6
  description?: string;
7
+ /** Extra class on the inserted mention chip (merged with `slash-mention`). */
8
+ className?: string;
9
+ /** CSS color for chip text; background is 30% of this color mixed with transparent. */
10
+ color?: string;
7
11
  };
8
12
 
9
13
  export type SlashItemCommandContext = {
@@ -14,8 +18,9 @@ export type SlashItemCommandContext = {
14
18
  };
15
19
 
16
20
  /**
17
- * If provided, run when a slash item is picked. Return true to skip mention insert
18
- * (extension clears the trigger text from the composer).
21
+ * If provided, run when a slash item is picked. Return true to skip default mention insert
22
+ * and handle the composer yourself (e.g. `createChatPromptComposerHandle(editor).insertAtCaret`
23
+ * with `{ replaceRange: range }` to replace `/query` with a custom chip).
19
24
  */
20
25
  export type SlashOnItemCommand = (ctx: SlashItemCommandContext) => boolean;
21
26