@widgetic/editor 4.1.17 → 4.1.19

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 (112) hide show
  1. package/dist/components/PreviewChromeControls.svelte +2 -2
  2. package/dist/components/WidgetPreview.svelte +79 -16
  3. package/dist/components/editors/CompositionEditorApp.svelte +71 -35
  4. package/dist/components/editors/CompositionEditorApp.svelte.d.ts +3 -1
  5. package/dist/components/editors/ContentTabBulkDrop.svelte +268 -0
  6. package/dist/components/editors/ContentTabBulkDrop.svelte.d.ts +37 -0
  7. package/dist/components/editors/EmbedAssistantPanel.svelte +303 -0
  8. package/dist/components/editors/EmbedAssistantPanel.svelte.d.ts +29 -0
  9. package/dist/components/editors/EmbedEditor.svelte +221 -15
  10. package/dist/components/editors/EmbedEditor.svelte.d.ts +31 -3
  11. package/dist/components/editors/PropsEditor.svelte +326 -37
  12. package/dist/components/editors/PropsEditor.svelte.d.ts +11 -0
  13. package/dist/components/editors/propsEditorContentStateFlatten.d.ts +12 -0
  14. package/dist/components/editors/propsEditorContentStateFlatten.js +40 -0
  15. package/dist/components/ic/AngleInputController.svelte +9 -5
  16. package/dist/components/ic/BrowserInputController.svelte +208 -132
  17. package/dist/components/ic/BrowserInputController.svelte.d.ts +2 -0
  18. package/dist/components/ic/CheckboxInputController.svelte +11 -0
  19. package/dist/components/ic/ColorPickerInputController.svelte +122 -49
  20. package/dist/components/ic/DatePickerInputController.svelte +23 -13
  21. package/dist/components/ic/FixedPositionInputController.svelte +1 -1
  22. package/dist/components/ic/FontInputController.svelte +48 -47
  23. package/dist/components/ic/InputControllerHeader.svelte +5 -4
  24. package/dist/components/ic/KnowledgeDocumentsInputController.svelte +20 -7
  25. package/dist/components/ic/NumberControls.svelte +163 -35
  26. package/dist/components/ic/PositionInputController.svelte +24 -15
  27. package/dist/components/ic/RadioGroupInputController.svelte +11 -0
  28. package/dist/components/ic/RangeCalendarInputController.svelte +73 -28
  29. package/dist/components/ic/RoundedCornersInputController.svelte +2 -2
  30. package/dist/components/ic/SliderInputController.svelte +11 -4
  31. package/dist/components/ic/TextAreaInputController.svelte +620 -327
  32. package/dist/components/ic/TextAreaPreviewInputController.svelte +53 -64
  33. package/dist/components/ic/TextInputController.svelte +15 -2
  34. package/dist/components/ic/TimeInputController.svelte +1 -1
  35. package/dist/components/ic/VectorInputController.svelte +152 -20
  36. package/dist/components/ic/numberControlsValueArea.d.ts +29 -0
  37. package/dist/components/ic/numberControlsValueArea.js +51 -0
  38. package/dist/components/ic/optionGroupCardPointerDown.d.ts +9 -0
  39. package/dist/components/ic/optionGroupCardPointerDown.js +20 -0
  40. package/dist/components/ic/shared/DropdownChevron.svelte +2 -2
  41. package/dist/components/ic/shared/DropdownChevron.svelte.d.ts +1 -1
  42. package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte +174 -0
  43. package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte.d.ts +30 -0
  44. package/dist/components/ic/shared/EditorSelectedFilePreviewOverlay.svelte +34 -0
  45. package/dist/components/ic/shared/EditorSelectedFilePreviewOverlay.svelte.d.ts +24 -0
  46. package/dist/components/ic/shared/ItemGrid.svelte +2 -2
  47. package/dist/components/ic/shared/RecentItemsSection.svelte +6 -6
  48. package/dist/components/ic/shared/editableFieldClasses.d.ts +15 -0
  49. package/dist/components/ic/shared/editableFieldClasses.js +15 -0
  50. package/dist/components/ic/shared/fileBrowserOverlayEscape.d.ts +29 -0
  51. package/dist/components/ic/shared/fileBrowserOverlayEscape.js +21 -0
  52. package/dist/components/ic/shared/index.d.ts +1 -0
  53. package/dist/components/ic/shared/index.js +1 -0
  54. package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte +41 -9
  55. package/dist/composition/compositionApi.d.ts +16 -0
  56. package/dist/composition/compositionApi.js +16 -1
  57. package/dist/composition/compositionEditorController.d.ts +46 -0
  58. package/dist/composition/compositionEditorController.js +277 -5
  59. package/dist/composition/compositionEditorSchemaCache.d.ts +35 -0
  60. package/dist/composition/compositionEditorSchemaCache.js +82 -0
  61. package/dist/contentBulkDrop/applyContentPlan.d.ts +18 -0
  62. package/dist/contentBulkDrop/applyContentPlan.js +55 -0
  63. package/dist/contentBulkDrop/bulkDropSummary.d.ts +4 -0
  64. package/dist/contentBulkDrop/bulkDropSummary.js +12 -0
  65. package/dist/contentBulkDrop/dragIntent.d.ts +7 -0
  66. package/dist/contentBulkDrop/dragIntent.js +24 -0
  67. package/dist/contentBulkDrop/filterDropFiles.d.ts +2 -0
  68. package/dist/contentBulkDrop/filterDropFiles.js +21 -0
  69. package/dist/contentBulkDrop/formatFileSize.d.ts +2 -0
  70. package/dist/contentBulkDrop/formatFileSize.js +13 -0
  71. package/dist/contentBulkDrop/types.d.ts +34 -0
  72. package/dist/contentBulkDrop/types.js +1 -0
  73. package/dist/contentBulkDrop/uploadQueue.d.ts +41 -0
  74. package/dist/contentBulkDrop/uploadQueue.js +114 -0
  75. package/dist/drafts/compositionDraft.d.ts +65 -0
  76. package/dist/drafts/compositionDraft.js +136 -0
  77. package/dist/drafts/compositionEditorViewState.d.ts +9 -0
  78. package/dist/drafts/compositionEditorViewState.js +33 -0
  79. package/dist/drafts/draftJournal.d.ts +59 -0
  80. package/dist/drafts/draftJournal.js +261 -0
  81. package/dist/embed/__fixtures__/gatewayGeneratedEmbedCodes.json +25 -0
  82. package/dist/embed/__fixtures__/generatedEmbedCodes.json +320 -0
  83. package/dist/embed/parseCompositionEmbedCode.d.ts +21 -0
  84. package/dist/embed/parseCompositionEmbedCode.js +376 -0
  85. package/dist/embedAssistant/embedAssistantEvents.d.ts +22 -0
  86. package/dist/embedAssistant/embedAssistantEvents.js +39 -0
  87. package/dist/embedAssistant/embedAssistantStream.d.ts +30 -0
  88. package/dist/embedAssistant/embedAssistantStream.js +125 -0
  89. package/dist/embedAssistant/highlightTiming.d.ts +1 -0
  90. package/dist/embedAssistant/highlightTiming.js +6 -0
  91. package/dist/embedAssistant/types.d.ts +27 -0
  92. package/dist/embedAssistant/types.js +1 -0
  93. package/dist/i18n/labels.js +8 -4
  94. package/dist/i18n/language.d.ts +297 -3
  95. package/dist/i18n/messages.d.ts +38 -1
  96. package/dist/i18n/messages.js +40 -1
  97. package/dist/i18n/translate.d.ts +1 -1
  98. package/dist/index.d.ts +3 -1
  99. package/dist/index.js +2 -0
  100. package/dist/utils/FontManager.d.ts +2 -0
  101. package/dist/utils/FontManager.js +16 -1
  102. package/dist/utils/angleMath.d.ts +2 -0
  103. package/dist/utils/angleMath.js +6 -0
  104. package/dist/utils/isEditableEventTarget.d.ts +5 -0
  105. package/dist/utils/isEditableEventTarget.js +25 -0
  106. package/dist/utils/linkUrlValidation.d.ts +17 -0
  107. package/dist/utils/linkUrlValidation.js +120 -0
  108. package/dist/utils/mediaFileValue.d.ts +12 -0
  109. package/dist/utils/mediaFileValue.js +24 -0
  110. package/dist/utils/placeRichTextCaretAtDocumentEnd.d.ts +11 -0
  111. package/dist/utils/placeRichTextCaretAtDocumentEnd.js +26 -0
  112. package/package.json +6 -6
@@ -51,14 +51,15 @@
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
- IconArrowsDiagonalMinimize,
58
58
  IconBold,
59
59
  IconBrush,
60
60
  IconCheck,
61
61
  IconChevronUp,
62
+ IconX,
62
63
  IconH1,
63
64
  IconH2,
64
65
  IconH3,
@@ -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);
@@ -166,7 +175,7 @@
166
175
  { value: 'h3', messageKey: 'editor.textArea.heading3', icon: IconH3 }
167
176
  ];
168
177
 
169
- const toolbarIconClass = 'size-4 shrink-0 stroke-[1.333]';
178
+ const toolbarIconClass = 'size-4 shrink-0 stroke-2';
170
179
 
171
180
  /** The message of the style the toolbar button shows: the plain text's when the style is none of the options. */
172
181
  let currentTextStyleMessageKey = $derived<EditorMessageKey>(
@@ -199,6 +208,20 @@
199
208
  // Add these variables to track focus state
200
209
  let editorHasFocus = $state(false);
201
210
  let toolbarRef: HTMLDivElement;
211
+ let richTextPortalTarget: HTMLElement | null = $state(null);
212
+
213
+ function resolveRichTextPortalTarget(): HTMLElement | undefined {
214
+ const portalHost = queryInTreeOf(toolbarRef, '.text-area-portal');
215
+ if (portalHost instanceof HTMLElement) return portalHost;
216
+ if (typeof document !== 'undefined') {
217
+ return document.getElementById('editor-portal') ?? document.body;
218
+ }
219
+ return undefined;
220
+ }
221
+
222
+ const toolbarPopoverPortalProps = $derived({
223
+ to: richTextPortalTarget ?? resolveRichTextPortalTarget() ?? undefined
224
+ });
202
225
 
203
226
  // Static styles — avoid $derived so teardown does not leave inert derived reads.
204
227
  const editorStyle = `
@@ -254,9 +277,6 @@
254
277
  try {
255
278
  const coloredContent = `<span style="color: ${textColor}">${value}</span>`;
256
279
  editorInstance.commands.setContent(coloredContent);
257
-
258
- // Set caret to start after setting content
259
- editorInstance.commands.setTextSelection(0);
260
280
  } catch (error) {
261
281
  console.error('Error setting initial content and color:', error);
262
282
  }
@@ -279,9 +299,10 @@
279
299
  onFocus();
280
300
  editorHasFocus = true;
281
301
 
282
- // When focusing, ensure caret is at start if this is initial mount
283
- if (isInitialMount && editorInstance) {
284
- 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;
285
306
  }
286
307
  });
287
308
 
@@ -338,24 +359,21 @@
338
359
  }
339
360
  }
340
361
 
341
- // Helper function to force caret and scroll to beginning
342
- function forceCaretToStart() {
343
- if (!editorInstance) return;
344
- try {
345
- // Only force caret to start if this is the initial mount
346
- if (isInitialMount) {
347
- // Force the caret (text selection) to the beginning
348
- editorInstance.chain().setTextSelection({ from: 0, to: 0 }).run();
349
- }
350
- } catch (error) {
351
- 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;
352
367
  }
353
368
  }
354
369
 
355
- // Only call forceCaretToStart once during initial mount
356
- if (isInitialMount) {
357
- setTimeout(forceCaretToStart, 300);
358
- }
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);
359
377
  }
360
378
 
361
379
  function handleEditorUpdate(e: any) {
@@ -422,12 +440,7 @@
422
440
  chain.toggleUnderline().run();
423
441
  break;
424
442
  case 'link':
425
- if (isAdding) {
426
- const href = window.prompt($t('editor.textArea.enterUrl'));
427
- if (href) {
428
- chain.setLink({ href }).run();
429
- }
430
- } else {
443
+ if (!isAdding) {
431
444
  chain.unsetLink().run();
432
445
  }
433
446
  break;
@@ -488,7 +501,7 @@
488
501
  function getToggleValues(): string[] {
489
502
  if (isDestroyed) return [];
490
503
  return Object.entries(activeFormats)
491
- .filter(([_, isActive]) => isActive)
504
+ .filter(([format, isActive]) => isActive && format !== 'link')
492
505
  .map(([format]) => formatMapping[format as FormatType].value);
493
506
  }
494
507
 
@@ -753,8 +766,21 @@
753
766
  }
754
767
  }
755
768
 
756
- // Add this state to track animation
757
- 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';
758
784
 
759
785
  // Update handleColorButtonClick to ensure hex format
760
786
  function handleColorButtonClick() {
@@ -794,7 +820,14 @@
794
820
  }
795
821
 
796
822
  showColorPicker = true;
797
- isColorPickerAnimating = true;
823
+ colorPickerToolbarTransitioning = true;
824
+ colorPickerRowSlideIn = false;
825
+ scheduleColorToolbarTransitionFallback();
826
+ requestAnimationFrame(() => {
827
+ requestAnimationFrame(() => {
828
+ colorPickerRowSlideIn = true;
829
+ });
830
+ });
798
831
 
799
832
  // console.log('Color picker toolbar opened with selection:', {
800
833
  // range: selectedRange,
@@ -823,9 +856,18 @@
823
856
  // Update handleColorPickerClose function
824
857
  function handleColorPickerClose() {
825
858
  showColorPicker = false;
826
- isColorPickerAnimating = false;
859
+ colorPickerToolbarTransitioning = true;
860
+ colorPickerRowSlideIn = false;
861
+ scheduleColorToolbarTransitionFallback();
827
862
  isSelectionActive = false;
828
863
 
864
+ requestAnimationFrame(() => {
865
+ const brushButton = toolbarRef?.querySelector<HTMLButtonElement>(
866
+ '.color-picker-preview-button'
867
+ );
868
+ brushButton?.focus();
869
+ });
870
+
829
871
  if (editorInstance) {
830
872
  // Create a chain to handle all operations
831
873
  const chain = editorInstance.chain();
@@ -905,8 +947,10 @@
905
947
 
906
948
  // If clicking toolbar elements or color picker, maintain expanded state
907
949
  if (
908
- target.matches('input, button, [role="button"], [tabindex="0"]') ||
909
- target.closest('.color-picker-container')
950
+ target.matches('input, button, [role="button"], [role="combobox"], [tabindex="0"]') ||
951
+ target.closest(
952
+ '.color-picker-container, [data-radix-popper-content-wrapper], [data-state="open"]'
953
+ )
910
954
  ) {
911
955
  // Keep toolbar enabled since we're interacting with it
912
956
  editorHasFocus = true;
@@ -950,16 +994,175 @@
950
994
  // Add these near the top of the script section with other state declarations
951
995
  let isColorSelectOpen = $state(false);
952
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
+
953
1141
  // Add handleKeyDown function
954
1142
  function handleKeyDown(event: KeyboardEvent) {
955
1143
  if (event.key === 'Escape') {
1144
+ if (linkPopoverOpen) {
1145
+ event.preventDefault();
1146
+ event.stopPropagation();
1147
+ closeLinkPopover();
1148
+ return;
1149
+ }
956
1150
  if (showColorPicker) {
957
1151
  event.preventDefault();
1152
+ event.stopPropagation();
958
1153
  handleColorPickerClose();
959
1154
  }
960
1155
  }
961
1156
  }
962
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
+
963
1166
  // Update handleEditorBlur to maintain toolbar state
964
1167
  function handleEditorBlur(relatedTarget: Node | null) {
965
1168
  if (!editorInstance) return;
@@ -969,13 +1172,16 @@
969
1172
  const colorSelectModal = queryInTreeOf(toolbarRef, '[data-radix-popper-content-wrapper]');
970
1173
  const popoverContent = queryInTreeOf(toolbarRef, '[role="dialog"]');
971
1174
  const commandMenu = queryInTreeOf(toolbarRef, '[cmdk-root]');
1175
+ const linkPopoverContent = queryInTreeOf(toolbarRef, '.richtext-link-popover');
972
1176
 
973
1177
  const isClickingInside =
974
1178
  toolbarRef?.contains(relatedTarget) ||
975
1179
  editorInstance.view.dom.contains(relatedTarget as Node) ||
976
1180
  colorSelectModal?.contains(relatedTarget as Node) ||
977
1181
  popoverContent?.contains(relatedTarget as Node) ||
978
- commandMenu?.contains(relatedTarget as Node);
1182
+ commandMenu?.contains(relatedTarget as Node) ||
1183
+ linkPopoverContent?.contains(relatedTarget as Node) ||
1184
+ linkInputElement?.contains(relatedTarget as Node);
979
1185
 
980
1186
  if (!isClickingInside) {
981
1187
  editorHasFocus = false;
@@ -1060,6 +1266,7 @@
1060
1266
  let stopListeningForScroll: () => void = () => {};
1061
1267
 
1062
1268
  onMount(() => {
1269
+ richTextPortalTarget = resolveRichTextPortalTarget() ?? null;
1063
1270
  stopListeningForScroll = listenForScroll(toolbarRef, handleScroll);
1064
1271
  });
1065
1272
 
@@ -1086,8 +1293,10 @@
1086
1293
  if (editorInstance) {
1087
1294
  const target = e.target as HTMLElement;
1088
1295
  const isInteractive =
1089
- target.matches('button, input, [role="button"], [tabindex="0"]') ||
1090
- target.closest('button, input, [role="button"], [tabindex="0"]');
1296
+ target.matches('button, input, [role="button"], [role="combobox"], [tabindex="0"]') ||
1297
+ target.closest(
1298
+ 'button, input, [role="button"], [role="combobox"], [tabindex="0"], [data-radix-popper-content-wrapper]'
1299
+ );
1091
1300
 
1092
1301
  if (!isInteractive) {
1093
1302
  e.preventDefault();
@@ -1115,350 +1324,434 @@
1115
1324
  <!-- svelte-ignore event_directive_deprecated -->
1116
1325
  <div
1117
1326
  class="text-area-input-controller {className ? className + ' ' : ''}flex flex-col"
1118
- on:keydown={handleKeyDown}
1327
+ onkeydown={handleKeyDown}
1119
1328
  tabindex="-1"
1120
1329
  >
1121
- <!-- Label section -->
1122
- <div class="label-container flex items-center justify-between">
1123
- <!-- svelte-ignore a11y_label_has_associated_control -->
1124
- <label class="text-caption text-muted-foreground cursor-default select-none truncate"
1125
- >{label}</label
1126
- >
1127
- </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}
1128
1339
 
1129
1340
  <!-- Main editor container -->
1130
1341
  <div
1131
- class="main-editor-container group relative flex h-full w-full flex-col gap-2 overflow-hidden rounded-lg bg-accent pt-2.5 px-4 pb-4"
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'}"
1132
1345
  style={editorStyle}
1133
- on:mousedown={handleMouseDown}
1346
+ onmousedown={handleMouseDown}
1134
1347
  >
1135
- <!-- Toolbar at the top -->
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. -->
1136
1349
  <div
1137
1350
  bind:this={toolbarRef}
1138
- class="toolbar-container sticky top-0 z-10 h-9 shrink-0 select-none overflow-visible border-b border-border bg-transparent"
1139
- on:mousedown={handleToolbarInteraction}
1140
- on:click={handleToolbarInteraction}
1141
- 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}
1142
1355
  role="toolbar"
1143
1356
  aria-label={$t('editor.textArea.toolbar')}
1144
1357
  tabindex="-1"
1145
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. -->
1146
1363
  <div
1147
- class="toolbar-items-row relative flex h-full w-full max-w-[370px] 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'}"
1148
1367
  >
1149
- <!-- Format cluster centered; close stays on the right -->
1150
1368
  <div
1151
- class={`toolbar-items-container flex min-w-0 flex-1 items-center gap-2 transition-transform duration-base ease-out ${
1152
- showColorPicker || isColorPickerAnimating ? 'me-8' : ''
1153
- } ${
1154
- isColorPickerAnimating
1155
- ? 'translate-y-[-200%]'
1156
- : showColorPicker
1157
- ? 'translate-y-[-200%]'
1158
- : 'translate-y-0'
1159
- }`}
1369
+ class="toolbar-items-row relative flex h-full w-full min-w-0 items-center justify-between gap-2"
1160
1370
  >
1161
- <!-- Update the color picker button to show selected color -->
1162
- <Button
1163
- variant="ghost"
1164
- size="icon"
1165
- 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"
1166
- onclick={(e) => {
1167
- e.stopPropagation();
1168
- e.preventDefault();
1169
- const button = e.currentTarget as HTMLButtonElement;
1170
- button.blur();
1171
- handleColorButtonClick();
1172
- }}
1173
- >
1174
- <div class="toolbar-button-content flex h-full w-full items-center justify-center">
1175
- <!-- Color the brush icon based on selected color -->
1176
- <IconBrush
1177
- class="{toolbarIconClass} text-muted-foreground"
1178
- style={selectedRange ? `color: ${currentColor}` : ''}
1179
- />
1180
- </div>
1181
- </Button>
1182
-
1183
- <!-- Text Formatting Toggle Group -->
1184
- <ToggleGroup.Root
1185
- type="multiple"
1186
- class="text-formatting-toggle-group inline-flex h-9 gap-2 bg-transparent"
1187
- value={toggleValues}
1188
- onValueChange={(value) => {
1189
- if (!editorInstance) return;
1190
- if (value === undefined) return;
1191
- handleToggleChange(value);
1192
- }}
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}
1193
1377
  >
1194
- {#each Object.entries(formatMapping) as [format, { value, icon: Icon, messageKey }] (format)}
1195
- <ToggleGroup.Item
1196
- {value}
1197
- aria-label={$t(messageKey)}
1198
- data-state={activeFormats[format as FormatType] ? 'on' : 'off'}
1199
- 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"
1200
- >
1201
- <div class="toolbar-button-content flex h-full w-full items-center justify-center">
1202
- <Icon class="{toolbarIconClass} text-current" />
1203
- </div>
1204
- </ToggleGroup.Item>
1205
- {/each}
1206
- </ToggleGroup.Root>
1207
-
1208
- <!-- Text Style Dropdown -->
1209
- <div class="toolbar-text-style-ct inline-flex items-center shrink-0">
1210
- <Popover.Root
1211
- bind:open={textStyleDropdownOpen}
1212
- onOpenChange={(e: any) => {
1213
- handlePopoverOpenChange(e);
1214
- 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();
1389
+ }}
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);
1215
1409
  }}
1216
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}>
1217
1428
  <Popover.Trigger>
1218
1429
  <Button
1219
- bind:this={triggerButton}
1220
- id="text-style-trigger"
1221
1430
  variant="ghost"
1222
- data-state={textStyleDropdownOpen ? 'open' : 'closed'}
1223
- 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"
1224
- onclick={(e) => {
1225
- e.stopPropagation();
1226
- e.preventDefault();
1227
-
1228
- const buttonElement = e.currentTarget as HTMLButtonElement;
1229
- updateTriggerPosition(buttonElement);
1230
- buttonElement.blur();
1231
-
1232
- 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();
1233
1441
  }}
1234
1442
  >
1235
- <div
1236
- class="toolbar-button-content flex h-full w-full items-center justify-center gap-1 px-1"
1237
- >
1238
- {#if currentTextStyle === 'text'}
1239
- <IconPilcrow class={toolbarIconClass} />
1240
- {:else}
1241
- {@const activeHeading = textOptions.find((o) => o.value === currentTextStyle)}
1242
- {#if activeHeading?.icon}
1243
- <activeHeading.icon class={toolbarIconClass} />
1244
- {:else}
1245
- <span class="text-label-small">{$t(currentTextStyleMessageKey)}</span>
1246
- {/if}
1247
- {/if}
1248
- <DropdownChevron open={textStyleDropdownOpen} class={toolbarIconClass} />
1249
- </div>
1443
+ <IconLink class="{toolbarIconClass} text-current" />
1250
1444
  </Button>
1251
1445
  </Popover.Trigger>
1252
-
1253
1446
  <Popover.Content
1254
- class="w-[200px] rounded-xl border border-border bg-popover p-1 shadow-none"
1255
- 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"
1256
1449
  sideOffset={8}
1450
+ portalProps={toolbarPopoverPortalProps}
1451
+ onOpenAutoFocus={(event) => event.preventDefault()}
1257
1452
  >
1258
- <Command.Root>
1259
- <Command.List
1260
- aria-label={$t('editor.textArea.textStyles')}
1261
- 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
1262
1456
  >
1263
- {#each textOptions as option}
1264
- <Command.Item
1265
- value={option.value}
1266
- onclick={(e: any) => {
1267
- e.stopPropagation();
1268
- e.preventDefault();
1269
- handleCommandSelect(option.value);
1270
- }}
1271
- 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 ===
1272
- currentTextStyle
1273
- ? 'bg-brand-subtle'
1274
- : ''}"
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}
1275
1489
  >
1276
- <span
1277
- class="flex size-4 shrink-0 items-center justify-center"
1278
- aria-hidden="true"
1279
- >
1280
- {#if option.value === currentTextStyle}
1281
- <IconCheck class={toolbarIconClass} />
1282
- {/if}
1283
- </span>
1284
- {#if option.icon}
1285
- <option.icon class="{toolbarIconClass} text-muted-foreground" />
1286
- {/if}
1287
- <span class="min-w-0 flex-1 truncate text-start"
1288
- >{$t(option.messageKey)}</span
1289
- >
1290
- </Command.Item>
1291
- {/each}
1292
- </Command.List>
1293
- </Command.Root>
1490
+ {$t('editor.textArea.linkUrlRemove')}
1491
+ </Button>
1492
+ {/if}
1493
+ </div>
1494
+ </div>
1294
1495
  </Popover.Content>
1295
1496
  </Popover.Root>
1296
- </div>
1297
1497
 
1298
- <!-- List Style Dropdown -->
1299
- <div class="toolbar-list-style-ct inline-flex items-center shrink-0">
1300
- <Popover.Root
1301
- bind:open={listStyleDropdownOpen}
1302
- onOpenChange={(e: any) => {
1303
- handlePopoverOpenChange(e);
1304
- listStyleDropdownOpen = e;
1305
- }}
1306
- >
1307
- <Popover.Trigger>
1308
- <Button
1309
- variant="ghost"
1310
- id="list-style-trigger"
1311
- data-state={listStyleDropdownOpen ? 'open' : 'closed'}
1312
- 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"
1313
- onclick={(e) => {
1314
- e.stopPropagation();
1315
- e.preventDefault();
1316
- const buttonElement = e.currentTarget as HTMLButtonElement;
1317
- buttonElement.blur();
1318
- listStyleDropdownOpen = !listStyleDropdownOpen;
1319
- }}
1320
- >
1321
- <div
1322
- 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
+ }}
1323
1524
  >
1324
- {#if currentTextStyle && currentTextStyle.includes('List')}
1325
- {@const activeListOption = listOptions.find(
1326
- (opt) => opt.value === currentTextStyle
1327
- )}
1328
- {#if activeListOption?.icon}
1329
- <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}
1330
1539
  {/if}
1331
- {:else}
1332
- <IconList class={toolbarIconClass} />
1333
- {/if}
1334
- <DropdownChevron open={listStyleDropdownOpen} class={toolbarIconClass} />
1335
- </div>
1336
- </Button>
1337
- </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>
1338
1590
 
1339
- <Popover.Content
1340
- class="style-dropdown-container w-[200px] rounded-xl border border-border bg-popover p-1 shadow-none"
1341
- align="end"
1342
- sideOffset={8}
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
+ }}
1343
1599
  >
1344
- <Command.Root>
1345
- <Command.List
1346
- aria-label={$t('editor.textArea.listStyles')}
1347
- 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
+ }}
1348
1613
  >
1349
- {#each listOptions as option}
1350
- <Command.Item
1351
- value={option.value}
1352
- onclick={(e: any) => {
1353
- e.stopPropagation();
1354
- e.preventDefault();
1355
- handleCommandSelect(option.value);
1356
- }}
1357
- 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 ===
1358
- currentTextStyle
1359
- ? 'bg-brand-subtle'
1360
- : ''}"
1361
- >
1362
- <span
1363
- class="flex size-4 shrink-0 items-center justify-center"
1364
- aria-hidden="true"
1365
- >
1366
- {#if option.value === currentTextStyle}
1367
- <IconCheck class={toolbarIconClass} />
1368
- {/if}
1369
- </span>
1370
- {#if option.icon}
1371
- <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} />
1372
1623
  {/if}
1373
- <span class="min-w-0 flex-1 truncate text-start"
1374
- >{$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
+ : ''}"
1375
1655
  >
1376
- </Command.Item>
1377
- {/each}
1378
- </Command.List>
1379
- </Command.Root>
1380
- </Popover.Content>
1381
- </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>
1382
1677
  </div>
1383
- </div>
1384
-
1385
- {#if onClose && !showColorPicker && !isColorPickerAnimating}
1386
- <IconButton
1387
- variant="ghost"
1388
- size="default"
1389
- class="toolbar-close-button z-10 ms-auto shrink-0"
1390
- label={$t('editor.textArea.closePanel')}
1391
- onclick={(e) => {
1392
- e.stopPropagation();
1393
- e.preventDefault();
1394
- onClose();
1395
- }}
1396
- >
1397
- <IconArrowsDiagonalMinimize class={toolbarIconClass} />
1398
- </IconButton>
1399
- {/if}
1400
1678
 
1401
- {#if showColorPicker || isColorPickerAnimating}
1402
- <div
1403
- class={`color-picker-parent absolute inset-0 z-20 flex items-center gap-2 bg-accent px-1 transition-transform duration-base ease-out ${
1404
- isColorPickerAnimating
1405
- ? 'translate-y-0'
1406
- : showColorPicker
1407
- ? 'translate-y-0'
1408
- : 'translate-y-[200%]'
1409
- }`}
1410
- >
1679
+ {#if onClose}
1411
1680
  <IconButton
1412
1681
  variant="ghost"
1413
- size="default"
1414
- class="color-picker-close-button toolbar-button shrink-0"
1415
- 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')}
1416
1685
  onclick={(e) => {
1417
1686
  e.stopPropagation();
1418
1687
  e.preventDefault();
1419
- const button = e.currentTarget as HTMLButtonElement;
1420
- button.blur();
1421
- handleColorPickerClose();
1688
+ onClose();
1422
1689
  }}
1423
1690
  >
1424
- <IconChevronUp class={toolbarIconClass} />
1691
+ <IconX class={toolbarIconClass} />
1425
1692
  </IconButton>
1693
+ {/if}
1426
1694
 
1695
+ {#if showColorPicker || colorPickerToolbarTransitioning}
1427
1696
  <div
1428
- 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}
1429
1701
  >
1430
- <ColorPickerInputController
1431
- bind:value={currentColor}
1432
- onChange={(color) => {
1433
- currentColor = color;
1434
- handleColorChange(color);
1435
- }}
1436
- controllerId="text-color-picker"
1437
- saveRecentColors={true}
1438
- showOpacityControls={false}
1439
- showRing={false}
1440
- portalTarget="text-area-portal"
1441
- on:mousedown={handleColorPickerInteraction}
1442
- on:mousemove={handleColorPickerInteraction}
1443
- on:focus={() => {
1444
- if (editorInstance && selectedRange) {
1445
- editorInstance
1446
- .chain()
1447
- .setTextSelection(selectedRange)
1448
- .setMark('highlight', { color: 'var(--text-background-color)' })
1449
- .run();
1450
- editorInstance.view.dom.classList.add('hide-selection');
1451
- }
1452
- }}
1453
- on:blur={() => {
1454
- if (editorInstance) {
1455
- editorInstance.chain().unsetMark('highlight').run();
1456
- }
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();
1457
1714
  }}
1458
- />
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>
1459
1752
  </div>
1460
- </div>
1461
- {/if}
1753
+ {/if}
1754
+ </div>
1462
1755
  </div>
1463
1756
  </div>
1464
1757