@widgetic/editor 4.1.18 → 4.1.20

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 (94) hide show
  1. package/dist/components/WidgetPreview.svelte +77 -14
  2. package/dist/components/editors/CompositionEditorApp.svelte +71 -35
  3. package/dist/components/editors/CompositionEditorApp.svelte.d.ts +3 -1
  4. package/dist/components/editors/ContentTabBulkDrop.svelte +268 -0
  5. package/dist/components/editors/ContentTabBulkDrop.svelte.d.ts +37 -0
  6. package/dist/components/editors/EmbedAssistantPanel.svelte +303 -0
  7. package/dist/components/editors/EmbedAssistantPanel.svelte.d.ts +29 -0
  8. package/dist/components/editors/EmbedEditor.svelte +221 -15
  9. package/dist/components/editors/EmbedEditor.svelte.d.ts +31 -3
  10. package/dist/components/editors/PropsEditor.svelte +223 -30
  11. package/dist/components/editors/PropsEditor.svelte.d.ts +11 -0
  12. package/dist/components/editors/propsEditorContentStateFlatten.d.ts +12 -0
  13. package/dist/components/editors/propsEditorContentStateFlatten.js +40 -0
  14. package/dist/components/ic/BrowserInputController.svelte +184 -21
  15. package/dist/components/ic/BrowserInputController.svelte.d.ts +2 -0
  16. package/dist/components/ic/CheckboxInputController.svelte +11 -0
  17. package/dist/components/ic/ColorPickerInputController.svelte +2 -1
  18. package/dist/components/ic/DatePickerInputController.svelte +5 -3
  19. package/dist/components/ic/FontInputController.svelte +9 -4
  20. package/dist/components/ic/InputControllerHeader.svelte +4 -3
  21. package/dist/components/ic/KnowledgeDocumentsInputController.svelte +13 -0
  22. package/dist/components/ic/NumberControls.svelte +140 -17
  23. package/dist/components/ic/RadioGroupInputController.svelte +11 -0
  24. package/dist/components/ic/RangeCalendarInputController.svelte +38 -13
  25. package/dist/components/ic/TextAreaInputController.svelte +593 -321
  26. package/dist/components/ic/TextAreaPreviewInputController.svelte +46 -58
  27. package/dist/components/ic/VectorInputController.svelte +0 -1
  28. package/dist/components/ic/numberControlsValueArea.d.ts +29 -0
  29. package/dist/components/ic/numberControlsValueArea.js +51 -0
  30. package/dist/components/ic/optionGroupCardPointerDown.d.ts +9 -0
  31. package/dist/components/ic/optionGroupCardPointerDown.js +20 -0
  32. package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte +48 -6
  33. package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte.d.ts +4 -1
  34. package/dist/components/ic/shared/EditorSelectedFilePreviewOverlay.svelte +34 -0
  35. package/dist/components/ic/shared/EditorSelectedFilePreviewOverlay.svelte.d.ts +24 -0
  36. package/dist/components/ic/shared/fileBrowserOverlayEscape.d.ts +29 -0
  37. package/dist/components/ic/shared/fileBrowserOverlayEscape.js +21 -0
  38. package/dist/composition/compositionApi.d.ts +16 -0
  39. package/dist/composition/compositionApi.js +16 -1
  40. package/dist/composition/compositionEditorController.d.ts +46 -0
  41. package/dist/composition/compositionEditorController.js +277 -5
  42. package/dist/composition/compositionEditorSchemaCache.d.ts +35 -0
  43. package/dist/composition/compositionEditorSchemaCache.js +82 -0
  44. package/dist/contentBulkDrop/applyContentPlan.d.ts +18 -0
  45. package/dist/contentBulkDrop/applyContentPlan.js +55 -0
  46. package/dist/contentBulkDrop/bulkDropSummary.d.ts +4 -0
  47. package/dist/contentBulkDrop/bulkDropSummary.js +12 -0
  48. package/dist/contentBulkDrop/dragIntent.d.ts +7 -0
  49. package/dist/contentBulkDrop/dragIntent.js +24 -0
  50. package/dist/contentBulkDrop/filterDropFiles.d.ts +2 -0
  51. package/dist/contentBulkDrop/filterDropFiles.js +21 -0
  52. package/dist/contentBulkDrop/formatFileSize.d.ts +2 -0
  53. package/dist/contentBulkDrop/formatFileSize.js +13 -0
  54. package/dist/contentBulkDrop/types.d.ts +34 -0
  55. package/dist/contentBulkDrop/types.js +1 -0
  56. package/dist/contentBulkDrop/uploadQueue.d.ts +41 -0
  57. package/dist/contentBulkDrop/uploadQueue.js +114 -0
  58. package/dist/drafts/compositionDraft.d.ts +65 -0
  59. package/dist/drafts/compositionDraft.js +136 -0
  60. package/dist/drafts/compositionEditorViewState.d.ts +9 -0
  61. package/dist/drafts/compositionEditorViewState.js +33 -0
  62. package/dist/drafts/draftJournal.d.ts +59 -0
  63. package/dist/drafts/draftJournal.js +261 -0
  64. package/dist/embed/__fixtures__/gatewayGeneratedEmbedCodes.json +25 -0
  65. package/dist/embed/__fixtures__/generatedEmbedCodes.json +320 -0
  66. package/dist/embed/embedSchema.json +409 -0
  67. package/dist/embed/parseCompositionEmbedCode.d.ts +21 -0
  68. package/dist/embed/parseCompositionEmbedCode.js +379 -0
  69. package/dist/embedAssistant/embedAssistantEvents.d.ts +22 -0
  70. package/dist/embedAssistant/embedAssistantEvents.js +39 -0
  71. package/dist/embedAssistant/embedAssistantStream.d.ts +30 -0
  72. package/dist/embedAssistant/embedAssistantStream.js +125 -0
  73. package/dist/embedAssistant/highlightTiming.d.ts +1 -0
  74. package/dist/embedAssistant/highlightTiming.js +6 -0
  75. package/dist/embedAssistant/types.d.ts +27 -0
  76. package/dist/embedAssistant/types.js +1 -0
  77. package/dist/i18n/labels.js +8 -4
  78. package/dist/i18n/language.d.ts +38 -2
  79. package/dist/i18n/messages.d.ts +38 -1
  80. package/dist/i18n/messages.js +40 -1
  81. package/dist/i18n/translate.d.ts +1 -1
  82. package/dist/index.d.ts +3 -1
  83. package/dist/index.js +2 -0
  84. package/dist/utils/FontManager.d.ts +2 -0
  85. package/dist/utils/FontManager.js +16 -1
  86. package/dist/utils/isEditableEventTarget.d.ts +5 -0
  87. package/dist/utils/isEditableEventTarget.js +25 -0
  88. package/dist/utils/linkUrlValidation.d.ts +17 -0
  89. package/dist/utils/linkUrlValidation.js +120 -0
  90. package/dist/utils/mediaFileValue.d.ts +12 -0
  91. package/dist/utils/mediaFileValue.js +24 -0
  92. package/dist/utils/placeRichTextCaretAtDocumentEnd.d.ts +11 -0
  93. package/dist/utils/placeRichTextCaretAtDocumentEnd.js +26 -0
  94. package/package.json +7 -7
@@ -51,7 +51,8 @@
51
51
  ToggleGroup,
52
52
  Popover,
53
53
  Command,
54
- IconButton
54
+ IconButton,
55
+ Input
55
56
  } from '@widgetic/design-system/components';
56
57
  import {
57
58
  IconBold,
@@ -93,6 +94,8 @@
93
94
  queryAllInTreeOf,
94
95
  queryInTreeOf
95
96
  } from '../../utils/shadowDom';
97
+ import { validateLinkUrl } from '../../utils/linkUrlValidation';
98
+ import { placeRichTextCaretAtDocumentEnd } from '../../utils/placeRichTextCaretAtDocumentEnd';
96
99
 
97
100
  // Add this constant for the decoration type
98
101
  const TRANSITION_DURATION = 250;
@@ -120,6 +123,7 @@
120
123
  * State Variables
121
124
  */
122
125
  let isInitialMount = $state(false); // Tracks initial component mounting to prevent unnecessary updates
126
+ let hasPlacedCaretForOpen = $state(false); // One-shot: caret at document end when the editor first opens
123
127
  let editorInstance: TipTapEditor | null = null; // Reference to TipTap editor instance
124
128
  let textStyleDropdownOpen = $state(false); // Controls visibility of text style dropdown
125
129
  let listStyleDropdownOpen = $state(false);
@@ -152,6 +156,11 @@
152
156
  link: { value: 'link', icon: IconLink, messageKey: 'editor.textArea.toggleLink' }
153
157
  };
154
158
 
159
+ /** Inline formats rendered in the toggle group (link uses its own popover). */
160
+ const toggleFormatMapping = Object.fromEntries(
161
+ Object.entries(formatMapping).filter(([format]) => format !== 'link')
162
+ ) as Omit<FormatMapping, 'link'>;
163
+
155
164
  let currentTextStyle = $state('text'); // Track current text style
156
165
 
157
166
  let showColorPicker = $state(false);
@@ -268,9 +277,6 @@
268
277
  try {
269
278
  const coloredContent = `<span style="color: ${textColor}">${value}</span>`;
270
279
  editorInstance.commands.setContent(coloredContent);
271
-
272
- // Set caret to start after setting content
273
- editorInstance.commands.setTextSelection(0);
274
280
  } catch (error) {
275
281
  console.error('Error setting initial content and color:', error);
276
282
  }
@@ -293,9 +299,10 @@
293
299
  onFocus();
294
300
  editorHasFocus = true;
295
301
 
296
- // When focusing, ensure caret is at start if this is initial mount
297
- if (isInitialMount && editorInstance) {
298
- editorInstance.commands.setTextSelection(0);
302
+ // First focus while opening only: caret at end, without moving it on later refocus (toolbar, color, link).
303
+ if (!hasPlacedCaretForOpen && editorInstance) {
304
+ placeRichTextCaretAtDocumentEnd(editorInstance);
305
+ hasPlacedCaretForOpen = true;
299
306
  }
300
307
  });
301
308
 
@@ -352,24 +359,21 @@
352
359
  }
353
360
  }
354
361
 
355
- // Helper function to force caret and scroll to beginning
356
- function forceCaretToStart() {
357
- if (!editorInstance) return;
358
- try {
359
- // Only force caret to start if this is the initial mount
360
- if (isInitialMount) {
361
- // Force the caret (text selection) to the beginning
362
- editorInstance.chain().setTextSelection({ from: 0, to: 0 }).run();
363
- }
364
- } catch (error) {
365
- console.error('Error forcing caret to beginning:', error);
362
+ /** After content is in the DOM, place the caret at the end once when the editor opens (panel or portal). */
363
+ function placeCaretAtEndWhenOpening() {
364
+ if (!editorInstance || hasPlacedCaretForOpen) return;
365
+ if (placeRichTextCaretAtDocumentEnd(editorInstance)) {
366
+ hasPlacedCaretForOpen = true;
366
367
  }
367
368
  }
368
369
 
369
- // Only call forceCaretToStart once during initial mount
370
- if (isInitialMount) {
371
- setTimeout(forceCaretToStart, 300);
372
- }
370
+ // Run soon after mount (not a late timeout) so we do not override a click that already moved the caret.
371
+ requestAnimationFrame(() => {
372
+ requestAnimationFrame(() => {
373
+ placeCaretAtEndWhenOpening();
374
+ });
375
+ });
376
+ setTimeout(placeCaretAtEndWhenOpening, 50);
373
377
  }
374
378
 
375
379
  function handleEditorUpdate(e: any) {
@@ -436,12 +440,7 @@
436
440
  chain.toggleUnderline().run();
437
441
  break;
438
442
  case 'link':
439
- if (isAdding) {
440
- const href = window.prompt($t('editor.textArea.enterUrl'));
441
- if (href) {
442
- chain.setLink({ href }).run();
443
- }
444
- } else {
443
+ if (!isAdding) {
445
444
  chain.unsetLink().run();
446
445
  }
447
446
  break;
@@ -502,7 +501,7 @@
502
501
  function getToggleValues(): string[] {
503
502
  if (isDestroyed) return [];
504
503
  return Object.entries(activeFormats)
505
- .filter(([_, isActive]) => isActive)
504
+ .filter(([format, isActive]) => isActive && format !== 'link')
506
505
  .map(([format]) => formatMapping[format as FormatType].value);
507
506
  }
508
507
 
@@ -767,8 +766,21 @@
767
766
  }
768
767
  }
769
768
 
770
- // Add this state to track animation
771
- let isColorPickerAnimating = $state(false);
769
+ // Keeps the colour toolbar mounted until the slide transition finishes (open and close).
770
+ let colorPickerToolbarTransitioning = $state(false);
771
+ /** Slides the colour row in from below after mount so open uses the same easing as close. */
772
+ let colorPickerRowSlideIn = $state(false);
773
+
774
+ let linkPopoverOpen = $state(false);
775
+ let linkDraftUrl = $state('');
776
+ let linkValidationMessage = $state('');
777
+ let linkSelectionRange: { from: number; to: number } | null = $state(null);
778
+ let linkHasExisting = $state(false);
779
+ let linkInputElement: HTMLInputElement | null = $state(null);
780
+ let linkValidationMessageId = 'richtext-link-url-validation';
781
+
782
+ const brushToolbarButtonClass =
783
+ 'size-9 shrink-0 rounded-lg border-0 bg-background p-2 hover:bg-accent data-[state=on]:bg-brand-subtle';
772
784
 
773
785
  // Update handleColorButtonClick to ensure hex format
774
786
  function handleColorButtonClick() {
@@ -808,7 +820,14 @@
808
820
  }
809
821
 
810
822
  showColorPicker = true;
811
- isColorPickerAnimating = true;
823
+ colorPickerToolbarTransitioning = true;
824
+ colorPickerRowSlideIn = false;
825
+ scheduleColorToolbarTransitionFallback();
826
+ requestAnimationFrame(() => {
827
+ requestAnimationFrame(() => {
828
+ colorPickerRowSlideIn = true;
829
+ });
830
+ });
812
831
 
813
832
  // console.log('Color picker toolbar opened with selection:', {
814
833
  // range: selectedRange,
@@ -837,9 +856,18 @@
837
856
  // Update handleColorPickerClose function
838
857
  function handleColorPickerClose() {
839
858
  showColorPicker = false;
840
- isColorPickerAnimating = false;
859
+ colorPickerToolbarTransitioning = true;
860
+ colorPickerRowSlideIn = false;
861
+ scheduleColorToolbarTransitionFallback();
841
862
  isSelectionActive = false;
842
863
 
864
+ requestAnimationFrame(() => {
865
+ const brushButton = toolbarRef?.querySelector<HTMLButtonElement>(
866
+ '.color-picker-preview-button'
867
+ );
868
+ brushButton?.focus();
869
+ });
870
+
843
871
  if (editorInstance) {
844
872
  // Create a chain to handle all operations
845
873
  const chain = editorInstance.chain();
@@ -966,16 +994,175 @@
966
994
  // Add these near the top of the script section with other state declarations
967
995
  let isColorSelectOpen = $state(false);
968
996
 
997
+ function handleColorToolbarTransitionEnd(event: TransitionEvent) {
998
+ // Only the slide of the row itself counts. A button inside a row ends its own press transition (`transform`) and
999
+ // that event bubbles up: it unmounted the colour row ~50 ms into the slide, so the row vanished while the
1000
+ // formatting row was still sliding back in. The slide is the `translate` property (Tailwind's translate utilities).
1001
+ if (event.target !== event.currentTarget) return;
1002
+ if (event.propertyName !== 'translate' && event.propertyName !== 'transform') return;
1003
+ finishColorToolbarTransition();
1004
+ }
1005
+
1006
+ /** Lets the colour row go once its slide has ended (or once the fallback timer says it should have). */
1007
+ function finishColorToolbarTransition() {
1008
+ if (!showColorPicker) {
1009
+ colorPickerRowSlideIn = false;
1010
+ }
1011
+ colorPickerToolbarTransitioning = false;
1012
+ }
1013
+
1014
+ /** Longest the colour row stays mounted after the slide should have ended, if `transitionend` never arrives. */
1015
+ const COLOR_TOOLBAR_TRANSITION_FALLBACK_MS = 600;
1016
+ let colorToolbarTransitionFallbackTimer: ReturnType<typeof setTimeout> | null = null;
1017
+
1018
+ /** Safety net for a slide that ends without a `transitionend` (reduced motion, a toggle in the same frame). */
1019
+ function scheduleColorToolbarTransitionFallback() {
1020
+ try {
1021
+ if (colorToolbarTransitionFallbackTimer) clearTimeout(colorToolbarTransitionFallbackTimer);
1022
+ colorToolbarTransitionFallbackTimer = setTimeout(() => {
1023
+ colorToolbarTransitionFallbackTimer = null;
1024
+ if (colorPickerToolbarTransitioning) finishColorToolbarTransition();
1025
+ }, COLOR_TOOLBAR_TRANSITION_FALLBACK_MS);
1026
+ } catch (error) {
1027
+ console.error('[TextArea] Could not schedule the colour toolbar fallback', error);
1028
+ }
1029
+ }
1030
+
1031
+ function openLinkPopover() {
1032
+ if (!editorInstance) return;
1033
+
1034
+ const { from, to } = editorInstance.state.selection;
1035
+ linkSelectionRange = { from, to };
1036
+ const existingHref = String(editorInstance.getAttributes('link')?.href ?? '');
1037
+ linkDraftUrl = existingHref;
1038
+ linkHasExisting = existingHref.length > 0;
1039
+ linkValidationMessage = '';
1040
+ linkPopoverOpen = true;
1041
+ editorHasFocus = true;
1042
+
1043
+ requestAnimationFrame(() => {
1044
+ linkInputElement?.focus();
1045
+ linkInputElement?.select();
1046
+ });
1047
+ }
1048
+
1049
+ function closeLinkPopover(options: { restoreFocus?: boolean } = {}) {
1050
+ linkPopoverOpen = false;
1051
+ linkValidationMessage = '';
1052
+ if (options.restoreFocus !== false && editorInstance) {
1053
+ if (linkSelectionRange) {
1054
+ editorInstance.chain().focus().setTextSelection(linkSelectionRange).run();
1055
+ } else {
1056
+ editorInstance.commands.focus();
1057
+ }
1058
+ }
1059
+ }
1060
+
1061
+ function handleLinkPopoverOpenChange(isOpen: boolean) {
1062
+ if (!isOpen) {
1063
+ closeLinkPopover();
1064
+ }
1065
+ }
1066
+
1067
+ function handleLinkDraftInput(event: Event) {
1068
+ linkDraftUrl = (event.currentTarget as HTMLInputElement).value;
1069
+ if (linkValidationMessage) {
1070
+ linkValidationMessage = '';
1071
+ }
1072
+ }
1073
+
1074
+ function handleLinkDraftBlur() {
1075
+ const validation = validateLinkUrl(linkDraftUrl);
1076
+ if (!validation.ok && linkDraftUrl.trim()) {
1077
+ linkValidationMessage = $t(validation.messageKey);
1078
+ }
1079
+ }
1080
+
1081
+ function handleLinkInputKeyDown(event: KeyboardEvent) {
1082
+ event.stopPropagation();
1083
+ if (event.key === 'Enter') {
1084
+ event.preventDefault();
1085
+ applyLinkFromPopover();
1086
+ } else if (event.key === 'Escape') {
1087
+ event.preventDefault();
1088
+ closeLinkPopover();
1089
+ }
1090
+ }
1091
+
1092
+ function removeLinkFromPopover() {
1093
+ if (!editorInstance) return;
1094
+ try {
1095
+ // The link commands come with the Link extension; the editor's types do not know them (as in applyFormat)
1096
+ const chain = editorInstance.chain().focus() as any;
1097
+ chain.unsetLink().run();
1098
+ updateActiveFormats();
1099
+ closeLinkPopover();
1100
+ } catch (error) {
1101
+ console.error('[TextAreaInput] Could not remove link:', error);
1102
+ }
1103
+ }
1104
+
1105
+ function applyLinkFromPopover() {
1106
+ if (!editorInstance) return;
1107
+
1108
+ const trimmed = linkDraftUrl.trim();
1109
+ if (!trimmed) {
1110
+ if (linkHasExisting) {
1111
+ removeLinkFromPopover();
1112
+ return;
1113
+ }
1114
+ const validation = validateLinkUrl(linkDraftUrl);
1115
+ linkValidationMessage = $t(validation.messageKey);
1116
+ return;
1117
+ }
1118
+
1119
+ const validation = validateLinkUrl(linkDraftUrl);
1120
+ if (!validation.ok) {
1121
+ linkValidationMessage = $t(validation.messageKey);
1122
+ return;
1123
+ }
1124
+
1125
+ try {
1126
+ const range = linkSelectionRange;
1127
+ // The link commands come with the Link extension; the editor's types do not know them (as in applyFormat)
1128
+ const chain = editorInstance.chain().focus() as any;
1129
+ if (range) {
1130
+ chain.setTextSelection(range);
1131
+ }
1132
+ chain.setLink({ href: validation.normalizedHref }).run();
1133
+ updateActiveFormats();
1134
+ closeLinkPopover();
1135
+ } catch (error) {
1136
+ console.error('[TextAreaInput] Could not apply link URL:', error);
1137
+ linkValidationMessage = $t('editor.textArea.linkUrlInvalid');
1138
+ }
1139
+ }
1140
+
969
1141
  // Add handleKeyDown function
970
1142
  function handleKeyDown(event: KeyboardEvent) {
971
1143
  if (event.key === 'Escape') {
1144
+ if (linkPopoverOpen) {
1145
+ event.preventDefault();
1146
+ event.stopPropagation();
1147
+ closeLinkPopover();
1148
+ return;
1149
+ }
972
1150
  if (showColorPicker) {
973
1151
  event.preventDefault();
1152
+ event.stopPropagation();
974
1153
  handleColorPickerClose();
975
1154
  }
976
1155
  }
977
1156
  }
978
1157
 
1158
+ $effect(() => {
1159
+ if (isDestroyed) return;
1160
+ if (linkPopoverOpen && linkSelectionRange && editorInstance) {
1161
+ const { from, to } = linkSelectionRange;
1162
+ editorInstance.chain().setTextSelection({ from, to }).run();
1163
+ }
1164
+ });
1165
+
979
1166
  // Update handleEditorBlur to maintain toolbar state
980
1167
  function handleEditorBlur(relatedTarget: Node | null) {
981
1168
  if (!editorInstance) return;
@@ -985,13 +1172,16 @@
985
1172
  const colorSelectModal = queryInTreeOf(toolbarRef, '[data-radix-popper-content-wrapper]');
986
1173
  const popoverContent = queryInTreeOf(toolbarRef, '[role="dialog"]');
987
1174
  const commandMenu = queryInTreeOf(toolbarRef, '[cmdk-root]');
1175
+ const linkPopoverContent = queryInTreeOf(toolbarRef, '.richtext-link-popover');
988
1176
 
989
1177
  const isClickingInside =
990
1178
  toolbarRef?.contains(relatedTarget) ||
991
1179
  editorInstance.view.dom.contains(relatedTarget as Node) ||
992
1180
  colorSelectModal?.contains(relatedTarget as Node) ||
993
1181
  popoverContent?.contains(relatedTarget as Node) ||
994
- commandMenu?.contains(relatedTarget as Node);
1182
+ commandMenu?.contains(relatedTarget as Node) ||
1183
+ linkPopoverContent?.contains(relatedTarget as Node) ||
1184
+ linkInputElement?.contains(relatedTarget as Node);
995
1185
 
996
1186
  if (!isClickingInside) {
997
1187
  editorHasFocus = false;
@@ -1134,352 +1324,434 @@
1134
1324
  <!-- svelte-ignore event_directive_deprecated -->
1135
1325
  <div
1136
1326
  class="text-area-input-controller {className ? className + ' ' : ''}flex flex-col"
1137
- on:keydown={handleKeyDown}
1327
+ onkeydown={handleKeyDown}
1138
1328
  tabindex="-1"
1139
1329
  >
1140
- <!-- Label section -->
1141
- <div class="label-container flex items-center justify-between">
1142
- <!-- svelte-ignore a11y_label_has_associated_control -->
1143
- <label class="text-caption text-muted-foreground cursor-default select-none truncate"
1144
- >{label}</label
1145
- >
1146
- </div>
1330
+ {#if !onClose}
1331
+ <!-- Label section -->
1332
+ <div class="label-container flex items-center justify-between">
1333
+ <!-- svelte-ignore a11y_label_has_associated_control -->
1334
+ <label class="text-caption text-muted-foreground cursor-default select-none truncate"
1335
+ >{label}</label
1336
+ >
1337
+ </div>
1338
+ {/if}
1147
1339
 
1148
1340
  <!-- Main editor container -->
1149
1341
  <div
1150
- class="main-editor-container group relative flex h-full min-h-0 w-full flex-col overflow-hidden rounded-lg bg-accent px-4 pb-4 pt-4 [--editor-padding-top:0px]"
1342
+ class="main-editor-container group relative flex h-full min-h-0 w-full flex-col overflow-hidden bg-accent [--editor-padding-top:0px] {onClose
1343
+ ? 'rounded-none px-3 pb-4 pt-4'
1344
+ : 'rounded-lg px-4 pb-4 pt-4'}"
1151
1345
  style={editorStyle}
1152
- on:mousedown={handleMouseDown}
1346
+ onmousedown={handleMouseDown}
1153
1347
  >
1154
1348
  <!-- Toolbar at the top: the 36 row of buttons has 16 above it (the padding of the card) and 16 below it, then the line (1) and 16 of text space. -->
1155
1349
  <div
1156
1350
  bind:this={toolbarRef}
1157
- class="toolbar-container sticky top-0 z-20 mb-4 h-[calc(2.25rem+1rem+1px)] shrink-0 select-none overflow-visible border-b border-border bg-transparent pb-4"
1158
- on:mousedown={handleToolbarInteraction}
1159
- on:click={handleToolbarInteraction}
1160
- on:keydown={handleToolbarKeyDown}
1351
+ class="toolbar-container sticky top-0 z-20 mb-4 h-[calc(2.25rem+1rem+1px)] shrink-0 select-none border-b border-border bg-transparent pb-4"
1352
+ onmousedown={handleToolbarInteraction}
1353
+ onclick={handleToolbarInteraction}
1354
+ onkeydown={handleToolbarKeyDown}
1161
1355
  role="toolbar"
1162
1356
  aria-label={$t('editor.textArea.toolbar')}
1163
1357
  tabindex="-1"
1164
1358
  >
1359
+ <!-- The mask (round 26): the whole strip above the line, from the top edge of the card down to the line, edge to edge. The
1360
+ buttons slide up and out behind the top edge of the card, the colour bar comes up from the line, and nothing is seen
1361
+ outside the strip. The negative margins give back the card's padding (16 above the row, 16 under it, 12 or 16 at the
1362
+ sides), so the row does not move and a focus ring or a pressed scale is not cut. Popovers are portalled, so they are not clipped. -->
1165
1363
  <div
1166
- class="toolbar-items-row relative flex h-full w-full min-w-0 items-center justify-between gap-2"
1364
+ class="toolbar-motion-clip -mb-4 -mt-4 min-h-0 overflow-hidden pb-4 pt-4 {onClose
1365
+ ? '-mx-3 px-3'
1366
+ : '-mx-4 px-4'}"
1167
1367
  >
1168
- <!-- Format cluster centered; close stays on the right -->
1169
1368
  <div
1170
- class={`toolbar-items-container flex min-w-0 flex-1 items-center gap-2 transition-transform duration-base ease-out ${
1171
- showColorPicker || isColorPickerAnimating ? 'me-8' : ''
1172
- } ${
1173
- isColorPickerAnimating
1174
- ? 'translate-y-[-200%]'
1175
- : showColorPicker
1176
- ? 'translate-y-[-200%]'
1177
- : 'translate-y-0'
1178
- }`}
1369
+ class="toolbar-items-row relative flex h-full w-full min-w-0 items-center justify-between gap-2"
1179
1370
  >
1180
- <!-- Update the color picker button to show selected color -->
1181
- <Button
1182
- variant="ghost"
1183
- size="icon"
1184
- class="color-picker-preview-button size-9 shrink-0 rounded-lg border-0 bg-background p-2 hover:bg-accent data-[state=on]:bg-brand-subtle"
1185
- onclick={(e) => {
1186
- e.stopPropagation();
1187
- e.preventDefault();
1188
- const button = e.currentTarget as HTMLButtonElement;
1189
- button.blur();
1190
- handleColorButtonClick();
1191
- }}
1192
- >
1193
- <div class="toolbar-button-content flex h-full w-full items-center justify-center">
1194
- <!-- Color the brush icon based on selected color -->
1195
- <IconBrush
1196
- class="{toolbarIconClass} text-muted-foreground"
1197
- style={selectedRange ? `color: ${currentColor}` : ''}
1198
- />
1199
- </div>
1200
- </Button>
1201
-
1202
- <!-- Text Formatting Toggle Group -->
1203
- <ToggleGroup.Root
1204
- type="multiple"
1205
- class="text-formatting-toggle-group inline-flex h-9 gap-2 bg-transparent"
1206
- value={toggleValues}
1207
- onValueChange={(value) => {
1208
- if (!editorInstance) return;
1209
- if (value === undefined) return;
1210
- handleToggleChange(value);
1211
- }}
1371
+ <!-- Format cluster centered; close stays on the right -->
1372
+ <div
1373
+ class={`toolbar-items-container flex min-w-0 flex-1 items-center gap-2 transition-transform duration-base ease-out will-change-transform ${
1374
+ showColorPicker || colorPickerToolbarTransitioning ? 'me-8' : ''
1375
+ } ${showColorPicker ? 'translate-y-[-200%]' : 'translate-y-0'}`}
1376
+ ontransitionend={handleColorToolbarTransitionEnd}
1212
1377
  >
1213
- {#each Object.entries(formatMapping) as [format, { value, icon: Icon, messageKey }] (format)}
1214
- <ToggleGroup.Item
1215
- {value}
1216
- aria-label={$t(messageKey)}
1217
- data-state={activeFormats[format as FormatType] ? 'on' : 'off'}
1218
- class="size-9 shrink-0 rounded-lg border-0 bg-background p-2 hover:bg-accent data-[state=on]:bg-brand-subtle data-[state=on]:text-foreground"
1219
- >
1220
- <div class="toolbar-button-content flex h-full w-full items-center justify-center">
1221
- <Icon class="{toolbarIconClass} text-current" />
1222
- </div>
1223
- </ToggleGroup.Item>
1224
- {/each}
1225
- </ToggleGroup.Root>
1226
-
1227
- <!-- Text Style Dropdown -->
1228
- <div class="toolbar-text-style-ct inline-flex items-center shrink-0">
1229
- <Popover.Root
1230
- bind:open={textStyleDropdownOpen}
1231
- onOpenChange={(e: any) => {
1232
- handlePopoverOpenChange(e);
1233
- textStyleDropdownOpen = e;
1378
+ <!-- Update the color picker button to show selected color -->
1379
+ <Button
1380
+ variant="ghost"
1381
+ size="icon"
1382
+ class="color-picker-preview-button {brushToolbarButtonClass}"
1383
+ onclick={(e) => {
1384
+ e.stopPropagation();
1385
+ e.preventDefault();
1386
+ const button = e.currentTarget as HTMLButtonElement;
1387
+ button.blur();
1388
+ handleColorButtonClick();
1234
1389
  }}
1235
1390
  >
1391
+ <div class="toolbar-button-content flex h-full w-full items-center justify-center">
1392
+ <!-- Color the brush icon based on selected color -->
1393
+ <IconBrush
1394
+ class="{toolbarIconClass} text-muted-foreground"
1395
+ style={selectedRange ? `color: ${currentColor}` : ''}
1396
+ />
1397
+ </div>
1398
+ </Button>
1399
+
1400
+ <!-- Text Formatting Toggle Group -->
1401
+ <ToggleGroup.Root
1402
+ type="multiple"
1403
+ class="text-formatting-toggle-group inline-flex h-9 gap-2 bg-transparent"
1404
+ value={toggleValues}
1405
+ onValueChange={(value) => {
1406
+ if (!editorInstance) return;
1407
+ if (value === undefined) return;
1408
+ handleToggleChange(value);
1409
+ }}
1410
+ >
1411
+ {#each Object.entries(toggleFormatMapping) as [format, { value, icon: Icon, messageKey }] (format)}
1412
+ <ToggleGroup.Item
1413
+ {value}
1414
+ aria-label={$t(messageKey)}
1415
+ data-state={activeFormats[format as FormatType] ? 'on' : 'off'}
1416
+ class="size-9 shrink-0 rounded-lg border-0 bg-background p-2 hover:bg-accent data-[state=on]:bg-brand-subtle data-[state=on]:text-foreground"
1417
+ >
1418
+ <div
1419
+ class="toolbar-button-content flex h-full w-full items-center justify-center"
1420
+ >
1421
+ <Icon class="{toolbarIconClass} text-current" />
1422
+ </div>
1423
+ </ToggleGroup.Item>
1424
+ {/each}
1425
+ </ToggleGroup.Root>
1426
+
1427
+ <Popover.Root bind:open={linkPopoverOpen} onOpenChange={handleLinkPopoverOpenChange}>
1236
1428
  <Popover.Trigger>
1237
1429
  <Button
1238
- bind:this={triggerButton}
1239
- id="text-style-trigger"
1240
1430
  variant="ghost"
1241
- data-state={textStyleDropdownOpen ? 'open' : 'closed'}
1242
- class="toolbar-dropdown-trigger h-9 w-[51px] min-w-[51px] max-w-[51px] shrink-0 justify-center gap-1 rounded-lg border-0 bg-background p-0 hover:bg-accent data-[state=open]:ring-2 data-[state=open]:ring-ring data-[state=open]:ring-offset-2 data-[state=open]:ring-offset-background"
1243
- onclick={(e) => {
1244
- e.stopPropagation();
1245
- e.preventDefault();
1246
-
1247
- const buttonElement = e.currentTarget as HTMLButtonElement;
1248
- updateTriggerPosition(buttonElement);
1249
- buttonElement.blur();
1250
-
1251
- textStyleDropdownOpen = !textStyleDropdownOpen;
1431
+ size="icon"
1432
+ type="button"
1433
+ data-state={activeFormats.link ? 'on' : 'off'}
1434
+ aria-label={$t('editor.textArea.toggleLink')}
1435
+ aria-expanded={linkPopoverOpen}
1436
+ class="{brushToolbarButtonClass} data-[state=on]:text-foreground"
1437
+ onclick={(event) => {
1438
+ event.stopPropagation();
1439
+ event.preventDefault();
1440
+ openLinkPopover();
1252
1441
  }}
1253
1442
  >
1254
- <div
1255
- class="toolbar-button-content flex h-full w-full items-center justify-center gap-1 px-1"
1256
- >
1257
- {#if currentTextStyle === 'text'}
1258
- <IconPilcrow class={toolbarIconClass} />
1259
- {:else}
1260
- {@const activeHeading = textOptions.find((o) => o.value === currentTextStyle)}
1261
- {#if activeHeading?.icon}
1262
- <activeHeading.icon class={toolbarIconClass} />
1263
- {:else}
1264
- <span class="text-label-small">{$t(currentTextStyleMessageKey)}</span>
1265
- {/if}
1266
- {/if}
1267
- <DropdownChevron open={textStyleDropdownOpen} class={toolbarIconClass} />
1268
- </div>
1443
+ <IconLink class="{toolbarIconClass} text-current" />
1269
1444
  </Button>
1270
1445
  </Popover.Trigger>
1271
-
1272
1446
  <Popover.Content
1273
- class="richtext-toolbar-popover z-[60] w-[200px] rounded-xl border border-border bg-popover p-1 shadow-none"
1274
- align="end"
1447
+ class="richtext-link-popover z-[60] w-[min(320px,calc(100vw-2rem))] rounded-xl border border-border bg-popover p-3 shadow-none"
1448
+ align="start"
1275
1449
  sideOffset={8}
1276
1450
  portalProps={toolbarPopoverPortalProps}
1451
+ onOpenAutoFocus={(event) => event.preventDefault()}
1277
1452
  >
1278
- <Command.Root>
1279
- <Command.List
1280
- aria-label={$t('editor.textArea.textStyles')}
1281
- class="flex flex-col gap-0.5"
1453
+ <div class="flex flex-col gap-2">
1454
+ <label class="text-caption text-muted-foreground" for="richtext-link-url-input"
1455
+ >{$t('editor.textArea.linkUrlLabel')}</label
1282
1456
  >
1283
- {#each textOptions as option}
1284
- <Command.Item
1285
- value={option.value}
1286
- onclick={(e: any) => {
1287
- e.stopPropagation();
1288
- e.preventDefault();
1289
- handleCommandSelect(option.value);
1290
- }}
1291
- class="flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-body hover:bg-accent data-[selected=true]:bg-accent {option.value ===
1292
- currentTextStyle
1293
- ? 'bg-brand-subtle'
1294
- : ''}"
1457
+ <Input
1458
+ id="richtext-link-url-input"
1459
+ bind:ref={linkInputElement}
1460
+ bind:value={linkDraftUrl}
1461
+ placeholder={$t('editor.textArea.linkUrlPlaceholder')}
1462
+ aria-invalid={linkValidationMessage ? true : undefined}
1463
+ aria-describedby={linkValidationMessage ? linkValidationMessageId : undefined}
1464
+ class="h-9"
1465
+ oninput={handleLinkDraftInput}
1466
+ onblur={handleLinkDraftBlur}
1467
+ onkeydown={handleLinkInputKeyDown}
1468
+ />
1469
+ {#if linkValidationMessage}
1470
+ <p
1471
+ id={linkValidationMessageId}
1472
+ class="text-caption text-destructive"
1473
+ role="alert"
1474
+ >
1475
+ {linkValidationMessage}
1476
+ </p>
1477
+ {/if}
1478
+ <div class="flex flex-wrap items-center gap-2">
1479
+ <Button type="button" size="sm" class="h-8" onclick={applyLinkFromPopover}>
1480
+ {$t('editor.textArea.linkUrlApply')}
1481
+ </Button>
1482
+ {#if linkHasExisting}
1483
+ <Button
1484
+ type="button"
1485
+ size="sm"
1486
+ variant="ghost"
1487
+ class="h-8"
1488
+ onclick={removeLinkFromPopover}
1295
1489
  >
1296
- <span
1297
- class="flex size-4 shrink-0 items-center justify-center"
1298
- aria-hidden="true"
1299
- >
1300
- {#if option.value === currentTextStyle}
1301
- <IconCheck class={toolbarIconClass} />
1302
- {/if}
1303
- </span>
1304
- {#if option.icon}
1305
- <option.icon class="{toolbarIconClass} text-muted-foreground" />
1306
- {/if}
1307
- <span class="min-w-0 flex-1 truncate text-start"
1308
- >{$t(option.messageKey)}</span
1309
- >
1310
- </Command.Item>
1311
- {/each}
1312
- </Command.List>
1313
- </Command.Root>
1490
+ {$t('editor.textArea.linkUrlRemove')}
1491
+ </Button>
1492
+ {/if}
1493
+ </div>
1494
+ </div>
1314
1495
  </Popover.Content>
1315
1496
  </Popover.Root>
1316
- </div>
1317
1497
 
1318
- <!-- List Style Dropdown -->
1319
- <div class="toolbar-list-style-ct inline-flex items-center shrink-0">
1320
- <Popover.Root
1321
- bind:open={listStyleDropdownOpen}
1322
- onOpenChange={(e: any) => {
1323
- handlePopoverOpenChange(e);
1324
- listStyleDropdownOpen = e;
1325
- }}
1326
- >
1327
- <Popover.Trigger>
1328
- <Button
1329
- variant="ghost"
1330
- id="list-style-trigger"
1331
- data-state={listStyleDropdownOpen ? 'open' : 'closed'}
1332
- class="toolbar-dropdown-trigger h-9 w-[51px] min-w-[51px] max-w-[51px] shrink-0 justify-center gap-1 rounded-lg border-0 bg-background p-0 hover:bg-accent data-[state=open]:ring-2 data-[state=open]:ring-ring data-[state=open]:ring-offset-2 data-[state=open]:ring-offset-background"
1333
- onclick={(e) => {
1334
- e.stopPropagation();
1335
- e.preventDefault();
1336
- const buttonElement = e.currentTarget as HTMLButtonElement;
1337
- buttonElement.blur();
1338
- listStyleDropdownOpen = !listStyleDropdownOpen;
1339
- }}
1340
- >
1341
- <div
1342
- class="toolbar-button-content flex h-full w-full items-center justify-center gap-1 px-1"
1498
+ <!-- Text Style Dropdown -->
1499
+ <div class="toolbar-text-style-ct inline-flex items-center shrink-0">
1500
+ <Popover.Root
1501
+ bind:open={textStyleDropdownOpen}
1502
+ onOpenChange={(e: any) => {
1503
+ handlePopoverOpenChange(e);
1504
+ textStyleDropdownOpen = e;
1505
+ }}
1506
+ >
1507
+ <Popover.Trigger>
1508
+ <Button
1509
+ bind:this={triggerButton}
1510
+ id="text-style-trigger"
1511
+ variant="ghost"
1512
+ data-state={textStyleDropdownOpen ? 'open' : 'closed'}
1513
+ class="toolbar-dropdown-trigger h-9 w-[51px] min-w-[51px] max-w-[51px] shrink-0 justify-center gap-1 rounded-lg border-0 bg-background p-0 hover:bg-accent data-[state=open]:ring-2 data-[state=open]:ring-ring data-[state=open]:ring-offset-2 data-[state=open]:ring-offset-background"
1514
+ onclick={(e) => {
1515
+ e.stopPropagation();
1516
+ e.preventDefault();
1517
+
1518
+ const buttonElement = e.currentTarget as HTMLButtonElement;
1519
+ updateTriggerPosition(buttonElement);
1520
+ buttonElement.blur();
1521
+
1522
+ textStyleDropdownOpen = !textStyleDropdownOpen;
1523
+ }}
1343
1524
  >
1344
- {#if currentTextStyle && currentTextStyle.includes('List')}
1345
- {@const activeListOption = listOptions.find(
1346
- (opt) => opt.value === currentTextStyle
1347
- )}
1348
- {#if activeListOption?.icon}
1349
- <activeListOption.icon class={toolbarIconClass} />
1525
+ <div
1526
+ class="toolbar-button-content flex h-full w-full items-center justify-center gap-1 px-1"
1527
+ >
1528
+ {#if currentTextStyle === 'text'}
1529
+ <IconPilcrow class={toolbarIconClass} />
1530
+ {:else}
1531
+ {@const activeHeading = textOptions.find(
1532
+ (o) => o.value === currentTextStyle
1533
+ )}
1534
+ {#if activeHeading?.icon}
1535
+ <activeHeading.icon class={toolbarIconClass} />
1536
+ {:else}
1537
+ <span class="text-label-small">{$t(currentTextStyleMessageKey)}</span>
1538
+ {/if}
1350
1539
  {/if}
1351
- {:else}
1352
- <IconList class={toolbarIconClass} />
1353
- {/if}
1354
- <DropdownChevron open={listStyleDropdownOpen} class={toolbarIconClass} />
1355
- </div>
1356
- </Button>
1357
- </Popover.Trigger>
1540
+ <DropdownChevron open={textStyleDropdownOpen} class={toolbarIconClass} />
1541
+ </div>
1542
+ </Button>
1543
+ </Popover.Trigger>
1544
+
1545
+ <Popover.Content
1546
+ class="richtext-toolbar-popover z-[60] w-[200px] rounded-xl border border-border bg-popover p-1 shadow-none"
1547
+ align="end"
1548
+ sideOffset={8}
1549
+ portalProps={toolbarPopoverPortalProps}
1550
+ >
1551
+ <Command.Root>
1552
+ <Command.List
1553
+ aria-label={$t('editor.textArea.textStyles')}
1554
+ class="flex flex-col gap-0.5"
1555
+ >
1556
+ {#each textOptions as option}
1557
+ <Command.Item
1558
+ value={option.value}
1559
+ onclick={(e: any) => {
1560
+ e.stopPropagation();
1561
+ e.preventDefault();
1562
+ handleCommandSelect(option.value);
1563
+ }}
1564
+ class="flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-body hover:bg-accent data-[selected=true]:bg-accent {option.value ===
1565
+ currentTextStyle
1566
+ ? 'bg-brand-subtle'
1567
+ : ''}"
1568
+ >
1569
+ <span
1570
+ class="flex size-4 shrink-0 items-center justify-center"
1571
+ aria-hidden="true"
1572
+ >
1573
+ {#if option.value === currentTextStyle}
1574
+ <IconCheck class={toolbarIconClass} />
1575
+ {/if}
1576
+ </span>
1577
+ {#if option.icon}
1578
+ <option.icon class="{toolbarIconClass} text-muted-foreground" />
1579
+ {/if}
1580
+ <span class="min-w-0 flex-1 truncate text-start"
1581
+ >{$t(option.messageKey)}</span
1582
+ >
1583
+ </Command.Item>
1584
+ {/each}
1585
+ </Command.List>
1586
+ </Command.Root>
1587
+ </Popover.Content>
1588
+ </Popover.Root>
1589
+ </div>
1358
1590
 
1359
- <Popover.Content
1360
- class="richtext-toolbar-popover z-[60] w-[200px] rounded-xl border border-border bg-popover p-1 shadow-none"
1361
- align="end"
1362
- sideOffset={8}
1363
- portalProps={toolbarPopoverPortalProps}
1591
+ <!-- List Style Dropdown -->
1592
+ <div class="toolbar-list-style-ct inline-flex items-center shrink-0">
1593
+ <Popover.Root
1594
+ bind:open={listStyleDropdownOpen}
1595
+ onOpenChange={(e: any) => {
1596
+ handlePopoverOpenChange(e);
1597
+ listStyleDropdownOpen = e;
1598
+ }}
1364
1599
  >
1365
- <Command.Root>
1366
- <Command.List
1367
- aria-label={$t('editor.textArea.listStyles')}
1368
- class="flex flex-col gap-0.5"
1600
+ <Popover.Trigger>
1601
+ <Button
1602
+ variant="ghost"
1603
+ id="list-style-trigger"
1604
+ data-state={listStyleDropdownOpen ? 'open' : 'closed'}
1605
+ class="toolbar-dropdown-trigger h-9 w-[51px] min-w-[51px] max-w-[51px] shrink-0 justify-center gap-1 rounded-lg border-0 bg-background p-0 hover:bg-accent data-[state=open]:ring-2 data-[state=open]:ring-ring data-[state=open]:ring-offset-2 data-[state=open]:ring-offset-background"
1606
+ onclick={(e) => {
1607
+ e.stopPropagation();
1608
+ e.preventDefault();
1609
+ const buttonElement = e.currentTarget as HTMLButtonElement;
1610
+ buttonElement.blur();
1611
+ listStyleDropdownOpen = !listStyleDropdownOpen;
1612
+ }}
1369
1613
  >
1370
- {#each listOptions as option}
1371
- <Command.Item
1372
- value={option.value}
1373
- onclick={(e: any) => {
1374
- e.stopPropagation();
1375
- e.preventDefault();
1376
- handleCommandSelect(option.value);
1377
- }}
1378
- class="flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-body hover:bg-accent data-[selected=true]:bg-accent {option.value ===
1379
- currentTextStyle
1380
- ? 'bg-brand-subtle'
1381
- : ''}"
1382
- >
1383
- <span
1384
- class="flex size-4 shrink-0 items-center justify-center"
1385
- aria-hidden="true"
1386
- >
1387
- {#if option.value === currentTextStyle}
1388
- <IconCheck class={toolbarIconClass} />
1389
- {/if}
1390
- </span>
1391
- {#if option.icon}
1392
- <option.icon class="{toolbarIconClass} text-muted-foreground" />
1614
+ <div
1615
+ class="toolbar-button-content flex h-full w-full items-center justify-center gap-1 px-1"
1616
+ >
1617
+ {#if currentTextStyle && currentTextStyle.includes('List')}
1618
+ {@const activeListOption = listOptions.find(
1619
+ (opt) => opt.value === currentTextStyle
1620
+ )}
1621
+ {#if activeListOption?.icon}
1622
+ <activeListOption.icon class={toolbarIconClass} />
1393
1623
  {/if}
1394
- <span class="min-w-0 flex-1 truncate text-start"
1395
- >{$t(option.messageKey)}</span
1624
+ {:else}
1625
+ <IconList class={toolbarIconClass} />
1626
+ {/if}
1627
+ <DropdownChevron open={listStyleDropdownOpen} class={toolbarIconClass} />
1628
+ </div>
1629
+ </Button>
1630
+ </Popover.Trigger>
1631
+
1632
+ <Popover.Content
1633
+ class="richtext-toolbar-popover z-[60] w-[200px] rounded-xl border border-border bg-popover p-1 shadow-none"
1634
+ align="end"
1635
+ sideOffset={8}
1636
+ portalProps={toolbarPopoverPortalProps}
1637
+ >
1638
+ <Command.Root>
1639
+ <Command.List
1640
+ aria-label={$t('editor.textArea.listStyles')}
1641
+ class="flex flex-col gap-0.5"
1642
+ >
1643
+ {#each listOptions as option}
1644
+ <Command.Item
1645
+ value={option.value}
1646
+ onclick={(e: any) => {
1647
+ e.stopPropagation();
1648
+ e.preventDefault();
1649
+ handleCommandSelect(option.value);
1650
+ }}
1651
+ class="flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-body hover:bg-accent data-[selected=true]:bg-accent {option.value ===
1652
+ currentTextStyle
1653
+ ? 'bg-brand-subtle'
1654
+ : ''}"
1396
1655
  >
1397
- </Command.Item>
1398
- {/each}
1399
- </Command.List>
1400
- </Command.Root>
1401
- </Popover.Content>
1402
- </Popover.Root>
1656
+ <span
1657
+ class="flex size-4 shrink-0 items-center justify-center"
1658
+ aria-hidden="true"
1659
+ >
1660
+ {#if option.value === currentTextStyle}
1661
+ <IconCheck class={toolbarIconClass} />
1662
+ {/if}
1663
+ </span>
1664
+ {#if option.icon}
1665
+ <option.icon class="{toolbarIconClass} text-muted-foreground" />
1666
+ {/if}
1667
+ <span class="min-w-0 flex-1 truncate text-start"
1668
+ >{$t(option.messageKey)}</span
1669
+ >
1670
+ </Command.Item>
1671
+ {/each}
1672
+ </Command.List>
1673
+ </Command.Root>
1674
+ </Popover.Content>
1675
+ </Popover.Root>
1676
+ </div>
1403
1677
  </div>
1404
- </div>
1405
-
1406
- {#if onClose}
1407
- <IconButton
1408
- variant="ghost"
1409
- size="sm"
1410
- class="toolbar-close-button z-30 ms-auto shrink-0"
1411
- label={$t('editor.textArea.closePanel')}
1412
- onclick={(e) => {
1413
- e.stopPropagation();
1414
- e.preventDefault();
1415
- onClose();
1416
- }}
1417
- >
1418
- <IconX class={toolbarIconClass} />
1419
- </IconButton>
1420
- {/if}
1421
1678
 
1422
- {#if showColorPicker || isColorPickerAnimating}
1423
- <div
1424
- class={`color-picker-parent absolute inset-0 z-20 flex items-center gap-2 bg-accent px-1 transition-transform duration-base ease-out ${
1425
- isColorPickerAnimating
1426
- ? 'translate-y-0'
1427
- : showColorPicker
1428
- ? 'translate-y-0'
1429
- : 'translate-y-[200%]'
1430
- }`}
1431
- >
1679
+ {#if onClose}
1432
1680
  <IconButton
1433
1681
  variant="ghost"
1434
- size="default"
1435
- class="color-picker-close-button toolbar-button shrink-0"
1436
- label={$t('editor.textArea.closeColorMode')}
1682
+ size="sm"
1683
+ class="toolbar-close-button z-30 ms-auto shrink-0"
1684
+ label={$t('editor.textArea.closePanel')}
1437
1685
  onclick={(e) => {
1438
1686
  e.stopPropagation();
1439
1687
  e.preventDefault();
1440
- const button = e.currentTarget as HTMLButtonElement;
1441
- button.blur();
1442
- handleColorPickerClose();
1688
+ onClose();
1443
1689
  }}
1444
1690
  >
1445
- <IconChevronUp class={toolbarIconClass} />
1691
+ <IconX class={toolbarIconClass} />
1446
1692
  </IconButton>
1693
+ {/if}
1447
1694
 
1695
+ {#if showColorPicker || colorPickerToolbarTransitioning}
1448
1696
  <div
1449
- class="color-picker-toolbar-slot relative w-[286px] max-w-[286px] shrink-0 overflow-visible"
1697
+ class={`color-picker-toolbar-row pointer-events-none absolute inset-x-0 top-0 z-20 flex h-[calc(2.25rem+1px)] items-center gap-2 pb-0 transition-transform duration-base ease-out will-change-transform ${
1698
+ showColorPicker && colorPickerRowSlideIn ? 'translate-y-0' : 'translate-y-[200%]'
1699
+ }`}
1700
+ ontransitionend={handleColorToolbarTransitionEnd}
1450
1701
  >
1451
- <ColorPickerInputController
1452
- bind:value={currentColor}
1453
- onChange={(color) => {
1454
- currentColor = color;
1455
- handleColorChange(color);
1456
- }}
1457
- controllerId="text-color-picker"
1458
- saveRecentColors={true}
1459
- showOpacityControls={false}
1460
- showRing={false}
1461
- portalTarget="text-area-portal"
1462
- on:mousedown={handleColorPickerInteraction}
1463
- on:mousemove={handleColorPickerInteraction}
1464
- on:focus={() => {
1465
- if (editorInstance && selectedRange) {
1466
- editorInstance
1467
- .chain()
1468
- .setTextSelection(selectedRange)
1469
- .setMark('highlight', { color: 'var(--text-background-color)' })
1470
- .run();
1471
- editorInstance.view.dom.classList.add('hide-selection');
1472
- }
1473
- }}
1474
- on:blur={() => {
1475
- if (editorInstance) {
1476
- editorInstance.chain().unsetMark('highlight').run();
1477
- }
1702
+ <Button
1703
+ variant="ghost"
1704
+ size="icon"
1705
+ type="button"
1706
+ class="color-picker-back-button pointer-events-auto {brushToolbarButtonClass}"
1707
+ aria-label={$t('editor.textArea.closeColorMode')}
1708
+ onclick={(e) => {
1709
+ e.stopPropagation();
1710
+ e.preventDefault();
1711
+ const button = e.currentTarget as HTMLButtonElement;
1712
+ button.blur();
1713
+ handleColorPickerClose();
1478
1714
  }}
1479
- />
1715
+ >
1716
+ <IconChevronUp class="{toolbarIconClass} text-muted-foreground" />
1717
+ </Button>
1718
+
1719
+ <div
1720
+ class="color-picker-toolbar-slot pointer-events-auto relative w-[286px] max-w-[286px] shrink-0 overflow-visible"
1721
+ >
1722
+ <ColorPickerInputController
1723
+ bind:value={currentColor}
1724
+ onChange={(color) => {
1725
+ currentColor = color;
1726
+ handleColorChange(color);
1727
+ }}
1728
+ controllerId="text-color-picker"
1729
+ saveRecentColors={true}
1730
+ showOpacityControls={false}
1731
+ showRing={false}
1732
+ portalTarget="text-area-portal"
1733
+ on:mousedown={handleColorPickerInteraction}
1734
+ on:mousemove={handleColorPickerInteraction}
1735
+ on:focus={() => {
1736
+ if (editorInstance && selectedRange) {
1737
+ editorInstance
1738
+ .chain()
1739
+ .setTextSelection(selectedRange)
1740
+ .setMark('highlight', { color: 'var(--text-background-color)' })
1741
+ .run();
1742
+ editorInstance.view.dom.classList.add('hide-selection');
1743
+ }
1744
+ }}
1745
+ on:blur={() => {
1746
+ if (editorInstance) {
1747
+ editorInstance.chain().unsetMark('highlight').run();
1748
+ }
1749
+ }}
1750
+ />
1751
+ </div>
1480
1752
  </div>
1481
- </div>
1482
- {/if}
1753
+ {/if}
1754
+ </div>
1483
1755
  </div>
1484
1756
  </div>
1485
1757