@zonsh/ui 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +639 -0
- package/README.md +49 -21
- package/dist/brand.d.ts +3 -0
- package/dist/brand.js +7 -0
- package/dist/components/_breadcrumb-more.d.ts +6 -0
- package/dist/components/_breadcrumb-more.js +5 -0
- package/dist/components/_drawing-svg.d.ts +11 -0
- package/dist/components/_drawing-svg.js +30 -0
- package/dist/components/_media.d.ts +159 -0
- package/dist/components/_media.js +266 -0
- package/dist/components/_overlay.d.ts +8 -5
- package/dist/components/_overlay.js +11 -6
- package/dist/components/_scheduler-calendar.d.ts +71 -0
- package/dist/components/_scheduler-calendar.js +940 -0
- package/dist/components/_scheduler-editor.d.ts +29 -0
- package/dist/components/_scheduler-editor.js +111 -0
- package/dist/components/_scheduler-menu.d.ts +16 -0
- package/dist/components/_scheduler-menu.js +18 -0
- package/dist/components/_scheduler-parts.d.ts +164 -0
- package/dist/components/_scheduler-parts.js +327 -0
- package/dist/components/_suggest-list.d.ts +142 -0
- package/dist/components/_suggest-list.js +159 -0
- package/dist/components/_toolbar-more.d.ts +24 -0
- package/dist/components/_toolbar-more.js +25 -0
- package/dist/components/accordion.d.ts +1 -1
- package/dist/components/accordion.js +7 -7
- package/dist/components/action-sheet.d.ts +88 -0
- package/dist/components/action-sheet.js +124 -0
- package/dist/components/alert-dialog.js +3 -1
- package/dist/components/alert.d.ts +11 -18
- package/dist/components/alert.js +9 -6
- package/dist/components/app-bar.d.ts +93 -0
- package/dist/components/app-bar.js +175 -0
- package/dist/components/ascii-field.js +2 -1
- package/dist/components/audio-player.d.ts +134 -0
- package/dist/components/audio-player.js +618 -0
- package/dist/components/avatar.d.ts +6 -6
- package/dist/components/avatar.js +13 -11
- package/dist/components/badge.d.ts +12 -12
- package/dist/components/badge.js +7 -5
- package/dist/components/bottom-nav.d.ts +53 -11
- package/dist/components/bottom-nav.js +389 -24
- package/dist/components/breadcrumb.d.ts +11 -2
- package/dist/components/breadcrumb.js +60 -6
- package/dist/components/button-group.js +5 -1
- package/dist/components/button.d.ts +23 -6
- package/dist/components/button.js +64 -8
- package/dist/components/calendar.js +8 -6
- package/dist/components/card.d.ts +10 -8
- package/dist/components/card.js +15 -14
- package/dist/components/carousel.d.ts +2 -2
- package/dist/components/carousel.js +21 -8
- package/dist/components/chart.d.ts +38 -1
- package/dist/components/chart.js +27 -5
- package/dist/components/checkbox.js +2 -2
- package/dist/components/code-block.d.ts +9 -2
- package/dist/components/code-block.js +26 -7
- package/dist/components/collapsible.js +4 -4
- package/dist/components/color-picker.d.ts +2 -2
- package/dist/components/color-picker.js +5 -5
- package/dist/components/combobox.d.ts +26 -7
- package/dist/components/combobox.js +32 -13
- package/dist/components/command.d.ts +29 -5
- package/dist/components/command.js +37 -12
- package/dist/components/context-menu.d.ts +5 -2
- package/dist/components/context-menu.js +24 -3
- package/dist/components/conversation.d.ts +1 -1
- package/dist/components/conversation.js +77 -16
- package/dist/components/copy-button.d.ts +1 -1
- package/dist/components/copy-button.js +8 -6
- package/dist/components/data-table.d.ts +6 -6
- package/dist/components/data-table.js +41 -15
- package/dist/components/date-picker.d.ts +31 -9
- package/dist/components/date-picker.js +100 -18
- package/dist/components/dialog.d.ts +17 -10
- package/dist/components/dialog.js +20 -13
- package/dist/components/drawer.d.ts +26 -8
- package/dist/components/drawer.js +75 -16
- package/dist/components/drawing.d.ts +25 -0
- package/dist/components/drawing.js +32 -0
- package/dist/components/empty.js +2 -2
- package/dist/components/feature-list.d.ts +65 -13
- package/dist/components/feature-list.js +116 -15
- package/dist/components/field.js +2 -2
- package/dist/components/file-drop.d.ts +9 -7
- package/dist/components/file-drop.js +8 -43
- package/dist/components/filter-bar.d.ts +10 -9
- package/dist/components/filter-bar.js +42 -25
- package/dist/components/graph.d.ts +19 -3
- package/dist/components/graph.js +190 -28
- package/dist/components/illustration.js +53 -31
- package/dist/components/input-group.d.ts +6 -11
- package/dist/components/input-group.js +21 -19
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +3 -3
- package/dist/components/item.d.ts +9 -6
- package/dist/components/item.js +13 -8
- package/dist/components/kbd.d.ts +1 -1
- package/dist/components/kbd.js +1 -1
- package/dist/components/layout.d.ts +2 -1
- package/dist/components/layout.js +55 -11
- package/dist/components/lightbox.d.ts +76 -9
- package/dist/components/lightbox.js +354 -48
- package/dist/components/locale.d.ts +6 -6
- package/dist/components/logo.d.ts +21 -1
- package/dist/components/logo.js +32 -2
- package/dist/components/markdown-editor.d.ts +275 -0
- package/dist/components/markdown-editor.js +831 -0
- package/dist/components/mentions.d.ts +153 -0
- package/dist/components/mentions.js +507 -0
- package/dist/components/menu.d.ts +2 -1
- package/dist/components/menu.js +5 -4
- package/dist/components/menubar.d.ts +23 -5
- package/dist/components/menubar.js +153 -31
- package/dist/components/message.d.ts +62 -11
- package/dist/components/message.js +51 -14
- package/dist/components/meter.js +1 -1
- package/dist/components/money-input.d.ts +1 -1
- package/dist/components/money-input.js +1 -1
- package/dist/components/native-select.d.ts +2 -2
- package/dist/components/native-select.js +4 -4
- package/dist/components/navigation-menu.d.ts +3 -1
- package/dist/components/navigation-menu.js +23 -10
- package/dist/components/number-field.d.ts +2 -9
- package/dist/components/number-field.js +90 -26
- package/dist/components/number-roll.d.ts +26 -0
- package/dist/components/number-roll.js +81 -0
- package/dist/components/otp-field.d.ts +1 -1
- package/dist/components/otp-field.js +24 -3
- package/dist/components/pagination.d.ts +11 -3
- package/dist/components/pagination.js +59 -13
- package/dist/components/pdf-viewer.d.ts +1 -1
- package/dist/components/pdf-viewer.js +8 -8
- package/dist/components/phone-input.d.ts +1 -1
- package/dist/components/phone-input.js +2 -2
- package/dist/components/popover.js +5 -3
- package/dist/components/preview-card.d.ts +37 -2
- package/dist/components/preview-card.js +226 -2
- package/dist/components/progress.js +1 -1
- package/dist/components/prompt-input.d.ts +1 -1
- package/dist/components/prompt-input.js +35 -17
- package/dist/components/pull-to-refresh.d.ts +50 -0
- package/dist/components/pull-to-refresh.js +189 -0
- package/dist/components/quote.d.ts +6 -1
- package/dist/components/quote.js +3 -2
- package/dist/components/radio-group.js +8 -3
- package/dist/components/rating.d.ts +4 -1
- package/dist/components/rating.js +131 -10
- package/dist/components/reasoning.d.ts +1 -1
- package/dist/components/reasoning.js +7 -3
- package/dist/components/resizable.d.ts +1 -1
- package/dist/components/resizable.js +2 -2
- package/dist/components/response.d.ts +4 -3
- package/dist/components/response.js +39 -15
- package/dist/components/scheduler.d.ts +352 -0
- package/dist/components/scheduler.js +1717 -0
- package/dist/components/scroll-area.js +1 -1
- package/dist/components/select.d.ts +17 -4
- package/dist/components/select.js +140 -9
- package/dist/components/separator.d.ts +1 -1
- package/dist/components/separator.js +3 -3
- package/dist/components/sidebar.d.ts +44 -3
- package/dist/components/sidebar.js +90 -31
- package/dist/components/site-header.d.ts +18 -13
- package/dist/components/site-header.js +26 -9
- package/dist/components/skeleton.d.ts +18 -8
- package/dist/components/skeleton.js +23 -8
- package/dist/components/slider.js +2 -2
- package/dist/components/sortable.d.ts +55 -4
- package/dist/components/sortable.js +187 -94
- package/dist/components/sources.d.ts +1 -1
- package/dist/components/sources.js +2 -2
- package/dist/components/spinner.d.ts +4 -4
- package/dist/components/spinner.js +4 -4
- package/dist/components/stat.d.ts +21 -4
- package/dist/components/stat.js +17 -8
- package/dist/components/stepper.d.ts +1 -1
- package/dist/components/stepper.js +8 -7
- package/dist/components/suggestions.d.ts +11 -3
- package/dist/components/suggestions.js +10 -4
- package/dist/components/swipe-actions.d.ts +66 -0
- package/dist/components/swipe-actions.js +292 -0
- package/dist/components/switch.js +1 -1
- package/dist/components/table.d.ts +13 -7
- package/dist/components/table.js +124 -23
- package/dist/components/tabs.js +15 -8
- package/dist/components/tag.d.ts +19 -20
- package/dist/components/tag.js +9 -5
- package/dist/components/tags-input.d.ts +2 -7
- package/dist/components/tags-input.js +11 -8
- package/dist/components/textarea.d.ts +3 -2
- package/dist/components/textarea.js +4 -3
- package/dist/components/theme.d.ts +50 -7
- package/dist/components/theme.js +168 -12
- package/dist/components/time-field.d.ts +6 -10
- package/dist/components/time-field.js +19 -9
- package/dist/components/timeline.d.ts +19 -3
- package/dist/components/timeline.js +21 -9
- package/dist/components/tippy.d.ts +17 -1
- package/dist/components/tippy.js +95 -15
- package/dist/components/toast.d.ts +2 -7
- package/dist/components/toast.js +12 -8
- package/dist/components/toggle-group.d.ts +7 -1
- package/dist/components/toggle-group.js +17 -5
- package/dist/components/toggle.d.ts +2 -2
- package/dist/components/toggle.js +3 -2
- package/dist/components/tool-call.d.ts +1 -1
- package/dist/components/tool-call.js +8 -3
- package/dist/components/toolbar.d.ts +57 -4
- package/dist/components/toolbar.js +219 -16
- package/dist/components/tooltip.d.ts +5 -3
- package/dist/components/tooltip.js +14 -6
- package/dist/components/tour.d.ts +1 -1
- package/dist/components/tour.js +70 -24
- package/dist/components/tree.js +33 -10
- package/dist/components/typography.d.ts +31 -8
- package/dist/components/typography.js +21 -10
- package/dist/components/video-player.d.ts +7 -2
- package/dist/components/video-player.js +182 -225
- package/dist/index.d.ts +99 -92
- package/dist/index.js +99 -92
- package/dist/lib/calendar.d.ts +153 -0
- package/dist/lib/calendar.js +312 -0
- package/dist/lib/cn.d.ts +3 -1
- package/dist/lib/cn.js +5 -0
- package/dist/lib/code-highlight.d.ts +14 -0
- package/dist/lib/code-highlight.js +81 -18
- package/dist/lib/drag.d.ts +39 -0
- package/dist/lib/drag.js +96 -0
- package/dist/lib/editorial-assets.js +16 -8
- package/dist/lib/figure/figures/automation.js +25 -6
- package/dist/lib/figure/figures/bar-chart.js +6 -1
- package/dist/lib/figure/figures/brackets-classic.js +4 -1
- package/dist/lib/figure/figures/city.js +12 -2
- package/dist/lib/figure/figures/conveyor.js +17 -4
- package/dist/lib/figure/figures/database.js +5 -2
- package/dist/lib/figure/figures/documents.js +11 -3
- package/dist/lib/figure/figures/inbox.js +5 -2
- package/dist/lib/figure/figures/laptop.js +3 -1
- package/dist/lib/figure/figures/pipeline.js +45 -10
- package/dist/lib/figure/figures/platform.js +62 -7
- package/dist/lib/figure/figures/server.js +21 -5
- package/dist/lib/figure/figures/spreadsheet.js +29 -5
- package/dist/lib/figure/kernel.d.ts +4 -2
- package/dist/lib/figure/kernel.js +10 -5
- package/dist/lib/figure/parts.js +6 -2
- package/dist/lib/files.d.ts +31 -0
- package/dist/lib/files.js +60 -0
- package/dist/lib/gesture.d.ts +70 -0
- package/dist/lib/gesture.js +141 -0
- package/dist/lib/glide.d.ts +10 -4
- package/dist/lib/glide.js +14 -5
- package/dist/lib/icons.d.ts +1 -0
- package/dist/lib/icons.js +6 -0
- package/dist/lib/illustration-library.js +1 -6
- package/dist/lib/markdown-edit.d.ts +112 -0
- package/dist/lib/markdown-edit.js +557 -0
- package/dist/lib/markdown-rich-editor.d.ts +188 -0
- package/dist/lib/markdown-rich-editor.js +1153 -0
- package/dist/lib/markdown-rich.d.ts +63 -0
- package/dist/lib/markdown-rich.js +534 -0
- package/dist/lib/mentions.d.ts +100 -0
- package/dist/lib/mentions.js +246 -0
- package/dist/lib/motion.d.ts +18 -0
- package/dist/lib/motion.js +43 -5
- package/dist/lib/number-roll.d.ts +89 -0
- package/dist/lib/number-roll.js +391 -0
- package/dist/lib/platform.d.ts +6 -0
- package/dist/lib/platform.js +14 -0
- package/dist/lib/portal-container.d.ts +9 -0
- package/dist/lib/portal-container.js +10 -0
- package/dist/lib/press.d.ts +5 -0
- package/dist/lib/press.js +186 -0
- package/dist/lib/scheduler.d.ts +128 -0
- package/dist/lib/scheduler.js +272 -0
- package/dist/lib/scroll-edges.d.ts +9 -0
- package/dist/lib/scroll-edges.js +50 -0
- package/dist/lib/table-fit.d.ts +4 -3
- package/dist/lib/table-fit.js +92 -25
- package/dist/lib/theme-preset.d.ts +267 -0
- package/dist/lib/theme-preset.js +1046 -0
- package/dist/lib/theme-script.d.ts +23 -3
- package/dist/lib/theme-script.js +17 -5
- package/dist/lib/tippy/sprite.d.ts +36 -4
- package/dist/lib/tippy/sprite.js +188 -15
- package/dist/lib/tone.d.ts +4 -0
- package/dist/lib/tone.js +1 -0
- package/dist/messages/de.d.ts +3 -3
- package/dist/messages/de.js +274 -3
- package/dist/skills/zon-ui/SKILL.md +279 -0
- package/dist/skills/zon-ui/references/authoring.md +265 -0
- package/dist/skills/zon-ui/references/brand.md +416 -0
- package/dist/skills/zon-ui/references/components/accordion.md +199 -0
- package/dist/skills/zon-ui/references/components/action-sheet.md +268 -0
- package/dist/skills/zon-ui/references/components/alert-dialog.md +276 -0
- package/dist/skills/zon-ui/references/components/alert.md +167 -0
- package/dist/skills/zon-ui/references/components/app-bar.md +307 -0
- package/dist/skills/zon-ui/references/components/ascii-field.md +121 -0
- package/dist/skills/zon-ui/references/components/aspect-ratio.md +112 -0
- package/dist/skills/zon-ui/references/components/audio-player.md +231 -0
- package/dist/skills/zon-ui/references/components/avatar.md +98 -0
- package/dist/skills/zon-ui/references/components/badge.md +227 -0
- package/dist/skills/zon-ui/references/components/bottom-nav.md +709 -0
- package/dist/skills/zon-ui/references/components/breadcrumb.md +143 -0
- package/dist/skills/zon-ui/references/components/button-group.md +216 -0
- package/dist/skills/zon-ui/references/components/button.md +309 -0
- package/dist/skills/zon-ui/references/components/calendar.md +296 -0
- package/dist/skills/zon-ui/references/components/card.md +158 -0
- package/dist/skills/zon-ui/references/components/carousel.md +297 -0
- package/dist/skills/zon-ui/references/components/chart.md +739 -0
- package/dist/skills/zon-ui/references/components/chat.md +417 -0
- package/dist/skills/zon-ui/references/components/checkbox.md +219 -0
- package/dist/skills/zon-ui/references/components/code-block.md +143 -0
- package/dist/skills/zon-ui/references/components/code-highlight.md +118 -0
- package/dist/skills/zon-ui/references/components/collapsible.md +146 -0
- package/dist/skills/zon-ui/references/components/color-picker.md +200 -0
- package/dist/skills/zon-ui/references/components/combobox.md +455 -0
- package/dist/skills/zon-ui/references/components/command.md +326 -0
- package/dist/skills/zon-ui/references/components/contact-form.md +562 -0
- package/dist/skills/zon-ui/references/components/context-menu.md +159 -0
- package/dist/skills/zon-ui/references/components/conversation.md +146 -0
- package/dist/skills/zon-ui/references/components/copy-button.md +162 -0
- package/dist/skills/zon-ui/references/components/crm.md +1022 -0
- package/dist/skills/zon-ui/references/components/dashboard.md +612 -0
- package/dist/skills/zon-ui/references/components/data-table.md +776 -0
- package/dist/skills/zon-ui/references/components/date-picker.md +444 -0
- package/dist/skills/zon-ui/references/components/dialog.md +335 -0
- package/dist/skills/zon-ui/references/components/direction.md +165 -0
- package/dist/skills/zon-ui/references/components/drawer.md +276 -0
- package/dist/skills/zon-ui/references/components/drawing.md +94 -0
- package/dist/skills/zon-ui/references/components/empty.md +225 -0
- package/dist/skills/zon-ui/references/components/feature-list.md +412 -0
- package/dist/skills/zon-ui/references/components/field.md +209 -0
- package/dist/skills/zon-ui/references/components/file-drop.md +234 -0
- package/dist/skills/zon-ui/references/components/filter-bar.md +485 -0
- package/dist/skills/zon-ui/references/components/form.md +970 -0
- package/dist/skills/zon-ui/references/components/graph.md +339 -0
- package/dist/skills/zon-ui/references/components/illustration.md +497 -0
- package/dist/skills/zon-ui/references/components/inbox.md +263 -0
- package/dist/skills/zon-ui/references/components/input-group.md +339 -0
- package/dist/skills/zon-ui/references/components/input.md +189 -0
- package/dist/skills/zon-ui/references/components/item.md +277 -0
- package/dist/skills/zon-ui/references/components/kanban.md +626 -0
- package/dist/skills/zon-ui/references/components/kbd.md +116 -0
- package/dist/skills/zon-ui/references/components/label.md +104 -0
- package/dist/skills/zon-ui/references/components/layout.md +291 -0
- package/dist/skills/zon-ui/references/components/lightbox.md +235 -0
- package/dist/skills/zon-ui/references/components/locale.md +279 -0
- package/dist/skills/zon-ui/references/components/logo.md +257 -0
- package/dist/skills/zon-ui/references/components/markdown-editor.md +558 -0
- package/dist/skills/zon-ui/references/components/mentions.md +512 -0
- package/dist/skills/zon-ui/references/components/menu.md +218 -0
- package/dist/skills/zon-ui/references/components/menubar.md +292 -0
- package/dist/skills/zon-ui/references/components/message.md +243 -0
- package/dist/skills/zon-ui/references/components/meter.md +105 -0
- package/dist/skills/zon-ui/references/components/money-input.md +333 -0
- package/dist/skills/zon-ui/references/components/native-select.md +197 -0
- package/dist/skills/zon-ui/references/components/navigation-menu.md +253 -0
- package/dist/skills/zon-ui/references/components/number-field.md +210 -0
- package/dist/skills/zon-ui/references/components/number-roll.md +175 -0
- package/dist/skills/zon-ui/references/components/onboarding.md +896 -0
- package/dist/skills/zon-ui/references/components/otp-field.md +166 -0
- package/dist/skills/zon-ui/references/components/pagination.md +109 -0
- package/dist/skills/zon-ui/references/components/pdf-viewer.md +177 -0
- package/dist/skills/zon-ui/references/components/phone-input.md +252 -0
- package/dist/skills/zon-ui/references/components/popover.md +176 -0
- package/dist/skills/zon-ui/references/components/preview-card.md +193 -0
- package/dist/skills/zon-ui/references/components/pricing.md +724 -0
- package/dist/skills/zon-ui/references/components/progress.md +92 -0
- package/dist/skills/zon-ui/references/components/prompt-input.md +307 -0
- package/dist/skills/zon-ui/references/components/pull-to-refresh.md +188 -0
- package/dist/skills/zon-ui/references/components/quote.md +115 -0
- package/dist/skills/zon-ui/references/components/radio-group.md +215 -0
- package/dist/skills/zon-ui/references/components/rating.md +260 -0
- package/dist/skills/zon-ui/references/components/reasoning.md +102 -0
- package/dist/skills/zon-ui/references/components/resizable.md +213 -0
- package/dist/skills/zon-ui/references/components/response.md +170 -0
- package/dist/skills/zon-ui/references/components/scheduler.md +732 -0
- package/dist/skills/zon-ui/references/components/scroll-area.md +122 -0
- package/dist/skills/zon-ui/references/components/select.md +351 -0
- package/dist/skills/zon-ui/references/components/separator.md +103 -0
- package/dist/skills/zon-ui/references/components/settings.md +793 -0
- package/dist/skills/zon-ui/references/components/shop.md +1715 -0
- package/dist/skills/zon-ui/references/components/sidebar.md +813 -0
- package/dist/skills/zon-ui/references/components/sign-in.md +1639 -0
- package/dist/skills/zon-ui/references/components/site-header.md +303 -0
- package/dist/skills/zon-ui/references/components/skeleton.md +256 -0
- package/dist/skills/zon-ui/references/components/slider.md +172 -0
- package/dist/skills/zon-ui/references/components/sortable.md +405 -0
- package/dist/skills/zon-ui/references/components/sources.md +106 -0
- package/dist/skills/zon-ui/references/components/spinner.md +222 -0
- package/dist/skills/zon-ui/references/components/stat.md +267 -0
- package/dist/skills/zon-ui/references/components/stepper.md +285 -0
- package/dist/skills/zon-ui/references/components/suggestions.md +146 -0
- package/dist/skills/zon-ui/references/components/swipe-actions.md +344 -0
- package/dist/skills/zon-ui/references/components/switch.md +160 -0
- package/dist/skills/zon-ui/references/components/table.md +999 -0
- package/dist/skills/zon-ui/references/components/tabs.md +258 -0
- package/dist/skills/zon-ui/references/components/tag.md +115 -0
- package/dist/skills/zon-ui/references/components/tags-input.md +216 -0
- package/dist/skills/zon-ui/references/components/textarea.md +95 -0
- package/dist/skills/zon-ui/references/components/theme-editor.md +3940 -0
- package/dist/skills/zon-ui/references/components/theme.md +362 -0
- package/dist/skills/zon-ui/references/components/time-field.md +222 -0
- package/dist/skills/zon-ui/references/components/timeline.md +285 -0
- package/dist/skills/zon-ui/references/components/tippy.md +243 -0
- package/dist/skills/zon-ui/references/components/toast.md +220 -0
- package/dist/skills/zon-ui/references/components/toggle-group.md +261 -0
- package/dist/skills/zon-ui/references/components/toggle.md +167 -0
- package/dist/skills/zon-ui/references/components/tool-call.md +146 -0
- package/dist/skills/zon-ui/references/components/toolbar.md +260 -0
- package/dist/skills/zon-ui/references/components/tooltip.md +172 -0
- package/dist/skills/zon-ui/references/components/tour.md +423 -0
- package/dist/skills/zon-ui/references/components/tree.md +481 -0
- package/dist/skills/zon-ui/references/components/typography.md +347 -0
- package/dist/skills/zon-ui/references/components/video-player.md +386 -0
- package/dist/skills/zon-ui/references/marketing.md +467 -0
- package/dist/skills/zon-ui/references/motion.md +455 -0
- package/dist/skills/zon-ui/references/recipes.md +1232 -0
- package/dist/skills/zon-ui/references/tokens.md +866 -0
- package/dist/sources/accordion.css +4 -0
- package/dist/sources/action-sheet.css +11 -0
- package/dist/sources/alert-dialog.css +6 -0
- package/dist/sources/alert.css +3 -0
- package/dist/sources/app-bar.css +14 -0
- package/dist/sources/ascii-field.css +3 -0
- package/dist/sources/aspect-ratio.css +3 -0
- package/dist/sources/audio-player.css +20 -0
- package/dist/sources/avatar.css +3 -0
- package/dist/sources/badge.css +3 -0
- package/dist/sources/bottom-nav.css +9 -0
- package/dist/sources/breadcrumb.css +14 -0
- package/dist/sources/button-group.css +3 -0
- package/dist/sources/button.css +9 -0
- package/dist/sources/calendar.css +13 -0
- package/dist/sources/card.css +3 -0
- package/dist/sources/carousel.css +11 -0
- package/dist/sources/chart.css +5 -0
- package/dist/sources/checkbox.css +6 -0
- package/dist/sources/code-block.css +13 -0
- package/dist/sources/collapsible.css +4 -0
- package/dist/sources/color-picker.css +13 -0
- package/dist/sources/combobox.css +13 -0
- package/dist/sources/command.css +13 -0
- package/dist/sources/context-menu.css +12 -0
- package/dist/sources/conversation.css +10 -0
- package/dist/sources/copy-button.css +10 -0
- package/dist/sources/data-table.css +27 -0
- package/dist/sources/date-picker.css +20 -0
- package/dist/sources/dialog.css +9 -0
- package/dist/sources/direction.css +2 -0
- package/dist/sources/drawer.css +9 -0
- package/dist/sources/drawing.css +5 -0
- package/dist/sources/empty.css +3 -0
- package/dist/sources/feature-list.css +4 -0
- package/dist/sources/field.css +4 -0
- package/dist/sources/file-drop.css +15 -0
- package/dist/sources/filter-bar.css +30 -0
- package/dist/sources/form.css +4 -0
- package/dist/sources/graph.css +19 -0
- package/dist/sources/illustration.css +28 -0
- package/dist/sources/input-group.css +7 -0
- package/dist/sources/input.css +3 -0
- package/dist/sources/item.css +4 -0
- package/dist/sources/kbd.css +5 -0
- package/dist/sources/label.css +3 -0
- package/dist/sources/layout.css +3 -0
- package/dist/sources/lightbox.css +33 -0
- package/dist/sources/locale.css +2 -0
- package/dist/sources/logo.css +4 -0
- package/dist/sources/markdown-editor.css +41 -0
- package/dist/sources/mentions.css +13 -0
- package/dist/sources/menu.css +11 -0
- package/dist/sources/menubar.css +14 -0
- package/dist/sources/message.css +16 -0
- package/dist/sources/meter.css +4 -0
- package/dist/sources/money-input.css +10 -0
- package/dist/sources/native-select.css +4 -0
- package/dist/sources/navigation-menu.css +8 -0
- package/dist/sources/number-field.css +8 -0
- package/dist/sources/number-roll.css +6 -0
- package/dist/sources/otp-field.css +5 -0
- package/dist/sources/pagination.css +11 -0
- package/dist/sources/pdf-viewer.css +30 -0
- package/dist/sources/phone-input.css +20 -0
- package/dist/sources/popover.css +7 -0
- package/dist/sources/preview-card.css +7 -0
- package/dist/sources/progress.css +4 -0
- package/dist/sources/prompt-input.css +15 -0
- package/dist/sources/pull-to-refresh.css +14 -0
- package/dist/sources/quote.css +3 -0
- package/dist/sources/radio-group.css +5 -0
- package/dist/sources/rating.css +6 -0
- package/dist/sources/reasoning.css +6 -0
- package/dist/sources/resizable.css +4 -0
- package/dist/sources/response.css +16 -0
- package/dist/sources/scheduler.css +44 -0
- package/dist/sources/scroll-area.css +3 -0
- package/dist/sources/select.css +12 -0
- package/dist/sources/separator.css +3 -0
- package/dist/sources/sidebar.css +19 -0
- package/dist/sources/site-header.css +15 -0
- package/dist/sources/skeleton.css +3 -0
- package/dist/sources/slider.css +6 -0
- package/dist/sources/sortable.css +12 -0
- package/dist/sources/sources.css +6 -0
- package/dist/sources/spinner.css +6 -0
- package/dist/sources/stat.css +9 -0
- package/dist/sources/stepper.css +6 -0
- package/dist/sources/suggestions.css +10 -0
- package/dist/sources/swipe-actions.css +20 -0
- package/dist/sources/switch.css +5 -0
- package/dist/sources/table.css +7 -0
- package/dist/sources/tabs.css +5 -0
- package/dist/sources/tag.css +3 -0
- package/dist/sources/tags-input.css +6 -0
- package/dist/sources/textarea.css +3 -0
- package/dist/sources/theme.css +13 -0
- package/dist/sources/time-field.css +7 -0
- package/dist/sources/timeline.css +7 -0
- package/dist/sources/tippy.css +6 -0
- package/dist/sources/toast.css +6 -0
- package/dist/sources/toggle-group.css +5 -0
- package/dist/sources/toggle.css +3 -0
- package/dist/sources/tool-call.css +16 -0
- package/dist/sources/toolbar.css +14 -0
- package/dist/sources/tooltip.css +6 -0
- package/dist/sources/tour.css +14 -0
- package/dist/sources/tree.css +6 -0
- package/dist/sources/typography.css +4 -0
- package/dist/sources/video-player.css +21 -0
- package/dist/styles/ai.css +3 -0
- package/dist/styles/brand.css +98 -0
- package/dist/styles/core.css +266 -0
- package/dist/styles/editor.css +3 -0
- package/dist/styles/expressive.css +75 -77
- package/dist/styles/fonts.css +61 -117
- package/dist/styles/graph.css +4 -0
- package/dist/styles/illustration.css +4 -0
- package/dist/styles/index.css +11 -193
- package/dist/styles/material.css +177 -31
- package/dist/styles/parts/ai.css +20 -14
- package/dist/styles/parts/brand.css +2 -2
- package/dist/styles/parts/controls.css +51 -38
- package/dist/styles/parts/data.css +43 -11
- package/dist/styles/parts/editor.css +372 -0
- package/dist/styles/parts/feedback.css +75 -15
- package/dist/styles/parts/foundations.css +12 -7
- package/dist/styles/parts/graph.css +25 -9
- package/dist/styles/parts/inputs.css +172 -9
- package/dist/styles/parts/isometric.css +6 -5
- package/dist/styles/parts/navigation.css +237 -25
- package/dist/styles/parts/overlays.css +110 -8
- package/dist/styles/parts/pdf.css +15 -9
- package/dist/styles/pdf.css +3 -0
- package/dist/styles/prose.css +3 -0
- package/dist/styles/tokens.css +105 -15
- package/dist/theme.d.ts +1 -0
- package/dist/theme.js +5 -0
- package/dist/vite.d.ts +48 -59
- package/dist/vite.js +54 -21
- package/package.json +69 -2
|
@@ -0,0 +1,831 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Field as BaseField } from "@base-ui/react/field";
|
|
4
|
+
import { Tabs as BaseTabs } from "@base-ui/react/tabs";
|
|
5
|
+
import { Toolbar as BaseToolbar } from "@base-ui/react/toolbar";
|
|
6
|
+
import { useEditorState } from "@tiptap/react";
|
|
7
|
+
import { BoldIcon, ChevronDownIcon, CodeIcon, FileIcon, Heading1Icon, Heading2Icon, Heading3Icon, ImageIcon, ItalicIcon, LinkIcon, ListChecksIcon, ListIcon, ListOrderedIcon, PaperclipIcon, MinusIcon, QuoteIcon, SquareCodeIcon, StrikethroughIcon, TableIcon, TriangleAlertIcon, TypeIcon, XIcon, } from "../lib/icons.js";
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { cn } from "../lib/cn.js";
|
|
10
|
+
import { checkFiles, filesOf, pastedFiles } from "../lib/files.js";
|
|
11
|
+
import { applyEdit, blockLevel, continueList, indentList, insertTable, insertText as insertAtSelection, pasteLink, runCommand, textState, } from "../lib/markdown-edit.js";
|
|
12
|
+
import { RichSurface, } from "../lib/markdown-rich-editor.js";
|
|
13
|
+
import { mergeRefs } from "../lib/merge-refs.js";
|
|
14
|
+
import { modPressed, useShortcutKeys } from "../lib/platform.js";
|
|
15
|
+
import { Button } from "./button.js";
|
|
16
|
+
import { FileDropItem, formatFileSize } from "./file-drop.js";
|
|
17
|
+
import { InputGroup, InputGroupTextarea } from "./input-group.js";
|
|
18
|
+
import { Item, ItemActions, ItemContent, ItemDescription, ItemMedia, ItemTitle } from "./item.js";
|
|
19
|
+
import { KbdShortcut } from "./kbd.js";
|
|
20
|
+
import { useLocale, useMessages } from "./locale.js";
|
|
21
|
+
import { Menu, MenuContent, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "./menu.js";
|
|
22
|
+
import { PromptInputAttachment } from "./prompt-input.js";
|
|
23
|
+
import { Response } from "./response.js";
|
|
24
|
+
import { Spinner } from "./spinner.js";
|
|
25
|
+
import { TabsList, TabsTab } from "./tabs.js";
|
|
26
|
+
import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarHostContext, ToolbarSeparator, } from "./toolbar.js";
|
|
27
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip.js";
|
|
28
|
+
const defaultMessages = {
|
|
29
|
+
toolbar: "Formatting",
|
|
30
|
+
bold: "Bold",
|
|
31
|
+
italic: "Italic",
|
|
32
|
+
strikethrough: "Strikethrough",
|
|
33
|
+
code: "Code",
|
|
34
|
+
link: "Link",
|
|
35
|
+
heading: "Heading",
|
|
36
|
+
headingLevel: (level) => `Heading ${level}`,
|
|
37
|
+
text: "Text",
|
|
38
|
+
blockType: "Turn into",
|
|
39
|
+
divider: "Divider",
|
|
40
|
+
quote: "Quote",
|
|
41
|
+
bulletList: "Bulleted list",
|
|
42
|
+
numberedList: "Numbered list",
|
|
43
|
+
taskList: "To-do list",
|
|
44
|
+
codeBlock: "Code block",
|
|
45
|
+
table: "Table",
|
|
46
|
+
column: "Column",
|
|
47
|
+
addRowAbove: "Add row above",
|
|
48
|
+
addRowBelow: "Add row below",
|
|
49
|
+
addColumnBefore: "Add column before",
|
|
50
|
+
addColumnAfter: "Add column after",
|
|
51
|
+
deleteRow: "Delete row",
|
|
52
|
+
deleteColumn: "Delete column",
|
|
53
|
+
deleteTable: "Delete table",
|
|
54
|
+
imageAlt: "Alt text",
|
|
55
|
+
imageAltPlaceholder: "Describe the image",
|
|
56
|
+
imageRemove: "Remove image",
|
|
57
|
+
attach: "Attach files",
|
|
58
|
+
more: "More formatting",
|
|
59
|
+
slashCommands: "Blocks",
|
|
60
|
+
slashHint: "Type / for commands",
|
|
61
|
+
markdown: "Markdown",
|
|
62
|
+
linkPlaceholder: "Paste or type a link",
|
|
63
|
+
linkApply: "Apply",
|
|
64
|
+
linkOpen: "Open link",
|
|
65
|
+
linkRemove: "Remove link",
|
|
66
|
+
write: "Write",
|
|
67
|
+
preview: "Preview",
|
|
68
|
+
nothingToPreview: "Nothing to preview",
|
|
69
|
+
uploading: (name) => `Uploading ${name}…`,
|
|
70
|
+
uploadFailed: "Upload failed",
|
|
71
|
+
remove: (name) => `Remove ${name}`,
|
|
72
|
+
previewFile: (name) => `Preview ${name}`,
|
|
73
|
+
files: "Files",
|
|
74
|
+
mentions: "Suggestions",
|
|
75
|
+
mentionsLoading: "Loading…",
|
|
76
|
+
mentionsEmpty: "No matches",
|
|
77
|
+
mentionsResults: (n) => (n === 1 ? "1 suggestion" : `${n} suggestions`),
|
|
78
|
+
};
|
|
79
|
+
/** The toolbar's buttons. `heading` is the block menu ("Text ▾"); the levels and text live in it. */
|
|
80
|
+
const tools = {
|
|
81
|
+
heading: { icon: Heading3Icon },
|
|
82
|
+
bold: { icon: BoldIcon, keys: ["mod", "B"], code: "KeyB" },
|
|
83
|
+
italic: { icon: ItalicIcon, keys: ["mod", "I"], code: "KeyI" },
|
|
84
|
+
strikethrough: { icon: StrikethroughIcon, keys: ["mod", "shift", "X"], code: "KeyX", shift: true },
|
|
85
|
+
quote: { icon: QuoteIcon, keys: ["mod", "shift", "."], code: "Period", shift: true },
|
|
86
|
+
code: { icon: CodeIcon, keys: ["mod", "E"], code: "KeyE" },
|
|
87
|
+
codeBlock: { icon: SquareCodeIcon },
|
|
88
|
+
link: { icon: LinkIcon, keys: ["mod", "K"], code: "KeyK" },
|
|
89
|
+
bulletList: { icon: ListIcon, keys: ["mod", "shift", "8"], code: "Digit8", shift: true },
|
|
90
|
+
numberedList: { icon: ListOrderedIcon, keys: ["mod", "shift", "7"], code: "Digit7", shift: true },
|
|
91
|
+
taskList: { icon: ListChecksIcon, keys: ["mod", "shift", "9"], code: "Digit9", shift: true },
|
|
92
|
+
divider: { icon: MinusIcon },
|
|
93
|
+
table: { icon: TableIcon },
|
|
94
|
+
};
|
|
95
|
+
/** The toolbar's groups, in order: what the line is, marks, lists, blocks. */
|
|
96
|
+
const groups = [
|
|
97
|
+
["heading"],
|
|
98
|
+
["bold", "italic", "strikethrough", "code", "link"],
|
|
99
|
+
["bulletList", "numberedList", "taskList"],
|
|
100
|
+
["quote", "codeBlock", "table", "divider"],
|
|
101
|
+
];
|
|
102
|
+
/** The default toolbar: every group, without the divider (which "/" offers). */
|
|
103
|
+
const allTools = groups.flat().filter((c) => c !== "divider");
|
|
104
|
+
const shortcuts = allTools.flatMap((command) => {
|
|
105
|
+
const tool = tools[command];
|
|
106
|
+
return tool?.code ? [{ command, code: tool.code, shift: !!tool.shift }] : [];
|
|
107
|
+
});
|
|
108
|
+
/** What moves into the "…" menu when the toolbar doesn't fit, one by one: the least used first.
|
|
109
|
+
* Not in the list (the block menu, the paperclip, the MD toggle): they stay longest. */
|
|
110
|
+
const foldOrder = [
|
|
111
|
+
"divider",
|
|
112
|
+
"table",
|
|
113
|
+
"codeBlock",
|
|
114
|
+
"quote",
|
|
115
|
+
"taskList",
|
|
116
|
+
"numberedList",
|
|
117
|
+
"code",
|
|
118
|
+
"strikethrough",
|
|
119
|
+
"bulletList",
|
|
120
|
+
"link",
|
|
121
|
+
"italic",
|
|
122
|
+
"bold",
|
|
123
|
+
];
|
|
124
|
+
/** The marks the bubble over a selection offers, when the toolbar has them. */
|
|
125
|
+
const bubbleTools = ["bold", "italic", "strikethrough", "code", "link"];
|
|
126
|
+
/** The block menu's choices. */
|
|
127
|
+
const blockChoices = ["paragraph", "heading1", "heading2", "heading3"];
|
|
128
|
+
const blockIcons = {
|
|
129
|
+
paragraph: TypeIcon,
|
|
130
|
+
heading1: Heading1Icon,
|
|
131
|
+
heading2: Heading2Icon,
|
|
132
|
+
heading3: Heading3Icon,
|
|
133
|
+
};
|
|
134
|
+
/** The node or mark that shows a command is on, in the rich view. */
|
|
135
|
+
const activeName = {
|
|
136
|
+
bold: "bold",
|
|
137
|
+
italic: "italic",
|
|
138
|
+
strikethrough: "strike",
|
|
139
|
+
code: "code",
|
|
140
|
+
link: "link",
|
|
141
|
+
heading: "heading",
|
|
142
|
+
quote: "blockquote",
|
|
143
|
+
bulletList: "bulletList",
|
|
144
|
+
numberedList: "orderedList",
|
|
145
|
+
taskList: "taskList",
|
|
146
|
+
codeBlock: "codeBlock",
|
|
147
|
+
paragraph: "paragraph",
|
|
148
|
+
heading1: "heading",
|
|
149
|
+
heading2: "heading",
|
|
150
|
+
heading3: "heading",
|
|
151
|
+
divider: "horizontalRule",
|
|
152
|
+
table: "table",
|
|
153
|
+
};
|
|
154
|
+
/** The key pressed, as a `code`: a letter by what it types (so a shortcut follows the layout), anything else by its place. */
|
|
155
|
+
const pressed = (event) => /^[a-z]$/i.test(event.key) ? `Key${event.key.toUpperCase()}` : event.nativeEvent.code;
|
|
156
|
+
/** The shortcut for `aria-keyshortcuts`: "Meta+Shift+8" on a Mac, "Control+Shift+8" elsewhere. */
|
|
157
|
+
const ariaKeys = (keys, mod) => keys
|
|
158
|
+
.map((key) => (key === "mod" ? (mod === "⌘" ? "Meta" : "Control") : key === "shift" ? "Shift" : key))
|
|
159
|
+
.join("+");
|
|
160
|
+
const isImage = (file) => file.type.startsWith("image/");
|
|
161
|
+
/** The toolbar's and the bubble's buttons at the default 38px on a touch screen, 30px under a pointer. */
|
|
162
|
+
const touchButtons = "pointer-coarse:[&_[data-slot=toolbar-button]]:min-h-(--control-h) pointer-coarse:[&_[data-slot=toolbar-button]]:min-w-(--control-h)";
|
|
163
|
+
const MarkdownEditorContext = React.createContext(null);
|
|
164
|
+
/**
|
|
165
|
+
* The editor around a part rendered in its `children`: its view, its markdown, the textarea (in
|
|
166
|
+
* the markdown view) or the Tiptap editor (in the rich view), and edits that keep the undo history.
|
|
167
|
+
*/
|
|
168
|
+
export function useMarkdownEditor() {
|
|
169
|
+
const context = React.useContext(MarkdownEditorContext);
|
|
170
|
+
if (!context)
|
|
171
|
+
throw new Error("useMarkdownEditor must be used inside <MarkdownEditor>.");
|
|
172
|
+
return context;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* MarkdownEditor — a recessed field for writing formatted text that is stored as markdown: a
|
|
176
|
+
* comment, a message, a ticket's description. It works like the editors in Notion and Slack: bold
|
|
177
|
+
* shows bold, a list is a list, a link is a link, with a quiet toolbar and the usual shortcuts
|
|
178
|
+
* (⌘B, ⌘I, ⌘K …), and markdown typed as you go (`**bold**`, `- `, `1. `, `> `, `# `, ```). The value,
|
|
179
|
+
* in and out, is markdown. `mode="markdown"` shows the markdown itself, in a textarea, for people
|
|
180
|
+
* who would rather write it; `modeToggle` lets them switch. With `files` or `upload` it takes
|
|
181
|
+
* pasted, dropped and chosen files; `mentions` add `@` people and `#` issues as chips.
|
|
182
|
+
*
|
|
183
|
+
* Imported from `@zonsh/ui/markdown-editor`, with Tiptap installed beside it. The rule people
|
|
184
|
+
* break: storing the editor's HTML — the value is markdown, so it renders with `Response` anywhere.
|
|
185
|
+
*/
|
|
186
|
+
export function MarkdownEditor({ value: valueProp, defaultValue = "", onValueChange, mode: modeProp, defaultMode = "rich", onModeChange, modeToggle = false, ref, textareaRef: textareaRefProp, minRows = 3, maxRows = 12, tools: toolList = allTools, toolbar: toolbarAt = "top", slashCommands = true, markdownShortcuts = true, preview = false, mentions, submitOnEnter = false, files: filesProp, defaultFiles, onFilesChange, upload, accept, maxSize, maxFiles, onFileReject, id, name, form, placeholder, required, disabled = false, readOnly = false, maxLength, autoFocus, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onKeyDown, onPaste, onFocus, onBlur, className, style, labels, children, }) {
|
|
187
|
+
const text = useMessages("markdownEditor", defaultMessages, labels);
|
|
188
|
+
const locale = useLocale();
|
|
189
|
+
const { mod } = useShortcutKeys();
|
|
190
|
+
const textareaRef = React.useRef(null);
|
|
191
|
+
const refs = React.useMemo(() => mergeRefs(textareaRef, textareaRefProp), [textareaRefProp]);
|
|
192
|
+
const fileInput = React.useRef(null);
|
|
193
|
+
/** The rich view's hidden control: the Field's, holding the markdown for forms. */
|
|
194
|
+
const richControl = React.useRef(null);
|
|
195
|
+
const richRef = React.useRef(null);
|
|
196
|
+
const [editor, setEditor] = React.useState(null);
|
|
197
|
+
/* The view */
|
|
198
|
+
const [ownMode, setOwnMode] = React.useState(defaultMode);
|
|
199
|
+
const mode = modeProp ?? ownMode;
|
|
200
|
+
const rich = mode === "rich";
|
|
201
|
+
const setMode = (next) => {
|
|
202
|
+
if (next === mode)
|
|
203
|
+
return;
|
|
204
|
+
if (modeProp === undefined)
|
|
205
|
+
setOwnMode(next);
|
|
206
|
+
onModeChange?.(next);
|
|
207
|
+
switchedRef.current = true;
|
|
208
|
+
};
|
|
209
|
+
/** The view was just switched: the new one takes focus. */
|
|
210
|
+
const switchedRef = React.useRef(false);
|
|
211
|
+
/* The text */
|
|
212
|
+
const [own, setOwn] = React.useState(defaultValue);
|
|
213
|
+
const controlled = valueProp != null;
|
|
214
|
+
const value = controlled ? valueProp : own;
|
|
215
|
+
const valueRef = React.useRef(value);
|
|
216
|
+
valueRef.current = value;
|
|
217
|
+
const setValue = React.useCallback((next) => {
|
|
218
|
+
valueRef.current = next;
|
|
219
|
+
if (!controlled)
|
|
220
|
+
setOwn(next);
|
|
221
|
+
onValueChange?.(next);
|
|
222
|
+
}, [controlled, onValueChange]);
|
|
223
|
+
/* Disabled by the prop or by a disabled Field, which Base UI sets on the control. */
|
|
224
|
+
const [fieldDisabled, setFieldDisabled] = React.useState(false);
|
|
225
|
+
React.useLayoutEffect(() => {
|
|
226
|
+
const off = !!(rich ? richControl.current : textareaRef.current)?.disabled;
|
|
227
|
+
if (off !== fieldDisabled)
|
|
228
|
+
setFieldDisabled(off);
|
|
229
|
+
});
|
|
230
|
+
const off = disabled || fieldDisabled;
|
|
231
|
+
const locked = off || readOnly;
|
|
232
|
+
/* Write or preview, in the markdown view */
|
|
233
|
+
const [tab, setTab] = React.useState("write");
|
|
234
|
+
const [previewHeight, setPreviewHeight] = React.useState();
|
|
235
|
+
const tabs = preview && !rich;
|
|
236
|
+
const previewing = tabs && tab === "preview";
|
|
237
|
+
/* The staged files */
|
|
238
|
+
const takesFiles = filesProp !== undefined || defaultFiles !== undefined || !!onFilesChange || !!upload;
|
|
239
|
+
const [ownFiles, setOwnFiles] = React.useState(defaultFiles ?? []);
|
|
240
|
+
const files = filesProp ?? ownFiles;
|
|
241
|
+
const filesRef = React.useRef(files);
|
|
242
|
+
filesRef.current = files;
|
|
243
|
+
const setFiles = React.useCallback((next) => {
|
|
244
|
+
filesRef.current = next;
|
|
245
|
+
if (filesProp === undefined)
|
|
246
|
+
setOwnFiles(next);
|
|
247
|
+
onFilesChange?.(next);
|
|
248
|
+
}, [filesProp, onFilesChange]);
|
|
249
|
+
const [pending, setPending] = React.useState([]);
|
|
250
|
+
const pendingRef = React.useRef(pending);
|
|
251
|
+
pendingRef.current = pending;
|
|
252
|
+
const [dragging, setDragging] = React.useState(false);
|
|
253
|
+
/* Edits in the markdown view */
|
|
254
|
+
const edit = React.useCallback((next) => {
|
|
255
|
+
const el = textareaRef.current;
|
|
256
|
+
if (el)
|
|
257
|
+
applyEdit(el, next);
|
|
258
|
+
}, []);
|
|
259
|
+
const runRaw = React.useCallback((command) => {
|
|
260
|
+
const el = textareaRef.current;
|
|
261
|
+
if (!el || el.disabled || el.readOnly)
|
|
262
|
+
return;
|
|
263
|
+
edit(command === "table" ? insertTable(textState(el), text.column) : runCommand(textState(el), command));
|
|
264
|
+
}, [edit, text.column]);
|
|
265
|
+
const run = React.useCallback((command) => (rich ? richRef.current?.run(command) : runRaw(command)), [rich, runRaw]);
|
|
266
|
+
const insertText = React.useCallback((insert) => {
|
|
267
|
+
if (rich)
|
|
268
|
+
return richRef.current?.insertText(insert);
|
|
269
|
+
const el = textareaRef.current;
|
|
270
|
+
if (el)
|
|
271
|
+
edit(insertAtSelection(textState(el), insert));
|
|
272
|
+
}, [edit, rich]);
|
|
273
|
+
const replaceRange = React.useCallback((from, to, insert) => {
|
|
274
|
+
const el = textareaRef.current;
|
|
275
|
+
if (el)
|
|
276
|
+
edit(insertAtSelection({ value: el.value, selectionStart: from, selectionEnd: to }, insert));
|
|
277
|
+
}, [edit]);
|
|
278
|
+
const focus = React.useCallback(() => {
|
|
279
|
+
if (rich)
|
|
280
|
+
richRef.current?.focus();
|
|
281
|
+
else
|
|
282
|
+
textareaRef.current?.focus();
|
|
283
|
+
}, [rich]);
|
|
284
|
+
React.useImperativeHandle(ref, () => ({
|
|
285
|
+
focus,
|
|
286
|
+
run,
|
|
287
|
+
insertText,
|
|
288
|
+
get editor() {
|
|
289
|
+
return rich ? (richRef.current?.editor ?? null) : null;
|
|
290
|
+
},
|
|
291
|
+
get textarea() {
|
|
292
|
+
return rich ? null : textareaRef.current;
|
|
293
|
+
},
|
|
294
|
+
}), [focus, run, insertText, rich]);
|
|
295
|
+
/* After a switch, the new view has focus. */
|
|
296
|
+
React.useEffect(() => {
|
|
297
|
+
if (!switchedRef.current)
|
|
298
|
+
return;
|
|
299
|
+
switchedRef.current = false;
|
|
300
|
+
focus();
|
|
301
|
+
}, [mode, focus, editor]);
|
|
302
|
+
/** The form the editor is in: the markdown view's textarea's, or the rich view's control's. */
|
|
303
|
+
const formOf = () => (rich ? richControl.current : textareaRef.current)?.form ?? null;
|
|
304
|
+
const submit = () => {
|
|
305
|
+
const owner = formOf();
|
|
306
|
+
if (!owner)
|
|
307
|
+
return false;
|
|
308
|
+
owner.requestSubmit();
|
|
309
|
+
return true;
|
|
310
|
+
};
|
|
311
|
+
/** The markdown view's stand-ins: text at the caret, swapped in place. */
|
|
312
|
+
const rawSurface = {
|
|
313
|
+
insertPlaceholders: (list) => {
|
|
314
|
+
const el = textareaRef.current;
|
|
315
|
+
if (el)
|
|
316
|
+
edit(insertAtSelection(textState(el), list.map((p) => p.text).join("\n")));
|
|
317
|
+
},
|
|
318
|
+
replacePlaceholder: (placeholder, replacement) => {
|
|
319
|
+
// While the textarea has focus, as an edit that keeps the undo history and the selection;
|
|
320
|
+
// otherwise without taking focus.
|
|
321
|
+
const el = textareaRef.current;
|
|
322
|
+
const current = el?.value ?? valueRef.current;
|
|
323
|
+
const at = current.indexOf(placeholder);
|
|
324
|
+
if (at < 0)
|
|
325
|
+
return;
|
|
326
|
+
const end = at + placeholder.length;
|
|
327
|
+
const delta = replacement.length - placeholder.length;
|
|
328
|
+
const move = (p) => (p >= end ? p + delta : p > at ? at + replacement.length : p);
|
|
329
|
+
const state = el ? textState(el) : { value: current, selectionStart: 0, selectionEnd: 0 };
|
|
330
|
+
const next = {
|
|
331
|
+
value: current.slice(0, at) + replacement + current.slice(end),
|
|
332
|
+
selectionStart: move(state.selectionStart),
|
|
333
|
+
selectionEnd: move(state.selectionEnd),
|
|
334
|
+
};
|
|
335
|
+
if (el && document.activeElement === el)
|
|
336
|
+
applyEdit(el, next);
|
|
337
|
+
else
|
|
338
|
+
setValue(next.value);
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
/** The view showing now, for uploads that finish after a switch. */
|
|
342
|
+
const surfaceRef = React.useRef(rawSurface);
|
|
343
|
+
surfaceRef.current = rich
|
|
344
|
+
? {
|
|
345
|
+
insertPlaceholders: (list) => richRef.current?.insertPlaceholders(list),
|
|
346
|
+
replacePlaceholder: (t, md) => richRef.current?.replacePlaceholder(t, md),
|
|
347
|
+
}
|
|
348
|
+
: rawSurface;
|
|
349
|
+
const take = React.useCallback((incoming) => {
|
|
350
|
+
if (!incoming.length || locked)
|
|
351
|
+
return;
|
|
352
|
+
const staged = filesRef.current.length + pendingRef.current.length;
|
|
353
|
+
const { taken, rejected } = checkFiles(incoming, {
|
|
354
|
+
accept,
|
|
355
|
+
maxSize,
|
|
356
|
+
room: maxFiles == null ? undefined : Math.max(0, maxFiles - staged),
|
|
357
|
+
});
|
|
358
|
+
if (rejected.length)
|
|
359
|
+
onFileReject?.(rejected);
|
|
360
|
+
if (!taken.length)
|
|
361
|
+
return;
|
|
362
|
+
if (!upload) {
|
|
363
|
+
setFiles([...filesRef.current, ...taken]);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const started = taken.map((file) => ({
|
|
367
|
+
file,
|
|
368
|
+
status: "uploading",
|
|
369
|
+
placeholder: `![${text.uploading(file.name)}]()`,
|
|
370
|
+
}));
|
|
371
|
+
setPending((list) => [...list, ...started]);
|
|
372
|
+
surfaceRef.current.insertPlaceholders(started.map((p) => ({ text: p.placeholder, label: text.uploading(p.file.name) })));
|
|
373
|
+
for (const item of started) {
|
|
374
|
+
const still = () => pendingRef.current.some((p) => p.file === item.file);
|
|
375
|
+
Promise.resolve()
|
|
376
|
+
.then(() => upload(item.file))
|
|
377
|
+
.then((markdown) => {
|
|
378
|
+
// Removed while it uploaded: its stand-in goes, and so does what came back.
|
|
379
|
+
const kept = still();
|
|
380
|
+
surfaceRef.current.replacePlaceholder(item.placeholder, kept && markdown ? markdown : "");
|
|
381
|
+
setPending((list) => list.filter((p) => p.file !== item.file));
|
|
382
|
+
if (kept && !markdown)
|
|
383
|
+
setFiles([...filesRef.current, item.file]);
|
|
384
|
+
}, () => {
|
|
385
|
+
surfaceRef.current.replacePlaceholder(item.placeholder, "");
|
|
386
|
+
setPending((list) => list.map((p) => (p.file === item.file ? { ...p, status: "error" } : p)));
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
}, [accept, locked, maxFiles, maxSize, onFileReject, setFiles, text, upload]);
|
|
390
|
+
const removePending = (file) => {
|
|
391
|
+
const item = pendingRef.current.find((p) => p.file === file);
|
|
392
|
+
if (item?.status === "uploading")
|
|
393
|
+
surfaceRef.current.replacePlaceholder(item.placeholder, "");
|
|
394
|
+
const next = pendingRef.current.filter((p) => p.file !== file);
|
|
395
|
+
pendingRef.current = next;
|
|
396
|
+
setPending(next);
|
|
397
|
+
};
|
|
398
|
+
/* A form's reset puts an uncontrolled editor back to its defaults. */
|
|
399
|
+
React.useEffect(() => {
|
|
400
|
+
const owner = (rich ? richControl.current : textareaRef.current)?.form;
|
|
401
|
+
if (!owner)
|
|
402
|
+
return;
|
|
403
|
+
const reset = () => {
|
|
404
|
+
if (!controlled)
|
|
405
|
+
setOwn(defaultValue);
|
|
406
|
+
if (filesProp === undefined)
|
|
407
|
+
setOwnFiles(defaultFiles ?? []);
|
|
408
|
+
setPending([]);
|
|
409
|
+
};
|
|
410
|
+
owner.addEventListener("reset", reset);
|
|
411
|
+
return () => owner.removeEventListener("reset", reset);
|
|
412
|
+
}, [controlled, defaultValue, defaultFiles, filesProp, rich]);
|
|
413
|
+
/* Where `field-sizing: content` is missing, grow the textarea with the text by hand; the max height still caps it. */
|
|
414
|
+
React.useLayoutEffect(() => {
|
|
415
|
+
const el = textareaRef.current;
|
|
416
|
+
if (rich || !el || typeof CSS === "undefined" || CSS.supports?.("field-sizing", "content"))
|
|
417
|
+
return;
|
|
418
|
+
const fit = () => {
|
|
419
|
+
el.style.height = "auto";
|
|
420
|
+
el.style.height = `${el.scrollHeight}px`;
|
|
421
|
+
};
|
|
422
|
+
fit();
|
|
423
|
+
if (typeof ResizeObserver === "undefined")
|
|
424
|
+
return;
|
|
425
|
+
let width = el.clientWidth;
|
|
426
|
+
const resize = new ResizeObserver(() => {
|
|
427
|
+
if (el.clientWidth === width)
|
|
428
|
+
return;
|
|
429
|
+
width = el.clientWidth;
|
|
430
|
+
fit();
|
|
431
|
+
});
|
|
432
|
+
resize.observe(el);
|
|
433
|
+
return () => resize.disconnect();
|
|
434
|
+
}, [value, tab, rich]);
|
|
435
|
+
/** After Escape, Tab leaves the field even in a list, so a keyboard is never kept inside. */
|
|
436
|
+
const tabLeaves = React.useRef(false);
|
|
437
|
+
const handleKeyDown = (event) => {
|
|
438
|
+
onKeyDown?.(event);
|
|
439
|
+
const native = event.nativeEvent;
|
|
440
|
+
if (event.defaultPrevented || native.isComposing || native.keyCode === 229)
|
|
441
|
+
return;
|
|
442
|
+
const leave = tabLeaves.current;
|
|
443
|
+
tabLeaves.current = event.key === "Escape";
|
|
444
|
+
if (locked)
|
|
445
|
+
return;
|
|
446
|
+
const el = event.currentTarget;
|
|
447
|
+
if (event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey) {
|
|
448
|
+
if (leave)
|
|
449
|
+
return;
|
|
450
|
+
const next = indentList(textState(el), event.shiftKey);
|
|
451
|
+
if (!next)
|
|
452
|
+
return;
|
|
453
|
+
event.preventDefault();
|
|
454
|
+
edit(next);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if (event.key === "Enter" && modPressed(event) && !event.altKey && !event.shiftKey) {
|
|
458
|
+
if (submit())
|
|
459
|
+
event.preventDefault();
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if (event.key === "Enter" && !event.shiftKey && !event.altKey && !event.ctrlKey && !event.metaKey) {
|
|
463
|
+
const next = continueList(textState(el));
|
|
464
|
+
if (next) {
|
|
465
|
+
event.preventDefault();
|
|
466
|
+
edit(next);
|
|
467
|
+
}
|
|
468
|
+
else if (submitOnEnter && submit())
|
|
469
|
+
event.preventDefault();
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (!modPressed(event) || event.altKey)
|
|
473
|
+
return;
|
|
474
|
+
const key = pressed(event);
|
|
475
|
+
const command = allTools.find((c) => tools[c]?.code === key && !!tools[c]?.shift === event.shiftKey);
|
|
476
|
+
if (!command)
|
|
477
|
+
return;
|
|
478
|
+
event.preventDefault();
|
|
479
|
+
runRaw(command);
|
|
480
|
+
};
|
|
481
|
+
const handlePaste = (event) => {
|
|
482
|
+
onPaste?.(event);
|
|
483
|
+
if (event.defaultPrevented || locked)
|
|
484
|
+
return;
|
|
485
|
+
if (takesFiles) {
|
|
486
|
+
const pasted = pastedFiles(event.clipboardData);
|
|
487
|
+
if (pasted.length) {
|
|
488
|
+
event.preventDefault();
|
|
489
|
+
take(pasted);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
// A URL pasted over selected text links it.
|
|
494
|
+
const el = event.currentTarget;
|
|
495
|
+
const next = pasteLink(textState(el), event.clipboardData.getData("text/plain"));
|
|
496
|
+
if (!next)
|
|
497
|
+
return;
|
|
498
|
+
event.preventDefault();
|
|
499
|
+
edit(next);
|
|
500
|
+
};
|
|
501
|
+
/* The toolbar's state in the rich view: which commands are on where the caret is, and the block. */
|
|
502
|
+
const active = useEditorState({
|
|
503
|
+
editor,
|
|
504
|
+
selector: ({ editor: e }) => {
|
|
505
|
+
if (!e)
|
|
506
|
+
return "";
|
|
507
|
+
const on = allTools.filter((c) => c !== "heading" && e.isActive(activeName[c]));
|
|
508
|
+
const level = e.isActive("heading") ? Number(e.getAttributes("heading").level) || 0 : 0;
|
|
509
|
+
return [`level:${level}`, ...on, ...(e.isActive("table") ? ["inTable"] : [])].join(" ");
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
const isOn = (command) => rich && !!active && active.split(" ").includes(command);
|
|
513
|
+
/** In a table, a cell is one line: what turns a line into a block is off. */
|
|
514
|
+
const inTable = isOn("inTable");
|
|
515
|
+
const blockCommand = (command) => !/^(bold|italic|strikethrough|code|link|table|attach)$/.test(command);
|
|
516
|
+
/** The markdown view's heading level where the caret is, for the block menu. */
|
|
517
|
+
const [rawLevel, setRawLevel] = React.useState(0);
|
|
518
|
+
const level = rich ? Number(/level:(\d)/.exec(active ?? "")?.[1] ?? 0) : rawLevel;
|
|
519
|
+
const hasFiles = (event) => event.dataTransfer.types.includes("Files");
|
|
520
|
+
const shown = toolList.filter((c) => tools[c]);
|
|
521
|
+
// Read-only text is read, not written: no formatting row.
|
|
522
|
+
const showToolbar = toolbarAt !== "none" && !readOnly && (shown.length > 0 || takesFiles || modeToggle);
|
|
523
|
+
const showHeader = (showToolbar && toolbarAt === "top") || tabs;
|
|
524
|
+
const context = React.useMemo(() => ({
|
|
525
|
+
mode,
|
|
526
|
+
value,
|
|
527
|
+
disabled: off,
|
|
528
|
+
readOnly,
|
|
529
|
+
run,
|
|
530
|
+
insertText,
|
|
531
|
+
textareaRef,
|
|
532
|
+
editor: rich ? editor : null,
|
|
533
|
+
replaceRange,
|
|
534
|
+
}), [mode, value, off, readOnly, run, insertText, rich, editor, replaceRange]);
|
|
535
|
+
const toolButton = (command) => {
|
|
536
|
+
if (command === "heading")
|
|
537
|
+
return blockMenu;
|
|
538
|
+
const tool = command === "attach" ? { icon: PaperclipIcon } : tools[command];
|
|
539
|
+
const Icon = tool.icon;
|
|
540
|
+
const keys = "keys" in tool ? tool.keys : undefined;
|
|
541
|
+
const label = command === "paragraph"
|
|
542
|
+
? text.text
|
|
543
|
+
: /^heading\d$/.test(command)
|
|
544
|
+
? text.headingLevel(Number(command.slice(-1)))
|
|
545
|
+
: text[command];
|
|
546
|
+
const on = command !== "attach" && rich ? isOn(command) : undefined;
|
|
547
|
+
return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(ToolbarButton, { "aria-label": label, "aria-keyshortcuts": keys ? ariaKeys(keys, mod) : undefined, "aria-pressed": on, "data-command": command, disabled: locked || previewing || (inTable && blockCommand(command)), overflowPriority: command === "attach" ? 100 : Math.max(0, foldOrder.indexOf(command)), overflowLabel: label, overflowShortcut: keys,
|
|
548
|
+
// The text keeps focus, and its selection, through a click.
|
|
549
|
+
onMouseDown: (event) => event.preventDefault(), onClick: () => (command === "attach" ? fileInput.current?.click() : run(command)) }), children: _jsx(Icon, {}) }), _jsxs(TooltipContent, { className: "flex items-center gap-2", children: [label, keys && _jsx(KbdShortcut, { keys: keys })] })] }, command));
|
|
550
|
+
};
|
|
551
|
+
/* The block menu: what the line is — text or a heading — and what to turn it into. */
|
|
552
|
+
const blockValue = level ? `heading${level}` : "paragraph";
|
|
553
|
+
const blockLabel = level ? text.headingLevel(level) : text.text;
|
|
554
|
+
const blockMenu = (_jsxs(Menu, { onOpenChange: (open) => {
|
|
555
|
+
// Closed without a pick (Escape, a click outside): back to the text, its selection kept.
|
|
556
|
+
if (!open)
|
|
557
|
+
requestAnimationFrame(() => focus());
|
|
558
|
+
}, children: [_jsxs(ToolbarButton, { render: _jsx(MenuTrigger, {}), "data-command": "heading", "aria-label": `${text.blockType}: ${blockLabel}`, disabled: locked || previewing || inTable, className: "min-w-[7.25rem] justify-between gap-2 ps-2.5 pe-1.5 text-foreground-soft", children: [_jsx("span", { className: "truncate leading-normal", children: blockLabel }), _jsx(ChevronDownIcon, { "aria-hidden": true, className: "size-3.5! text-muted-foreground" })] }), _jsx(MenuContent, { finalFocus: false, className: "min-w-44", children: _jsx(MenuRadioGroup, { value: blockValue, onValueChange: (next) => {
|
|
559
|
+
// Back in the text first: its selection is what the command changes.
|
|
560
|
+
focus();
|
|
561
|
+
run(next);
|
|
562
|
+
}, children: blockChoices.map((choice) => {
|
|
563
|
+
const Icon = blockIcons[choice];
|
|
564
|
+
return (_jsxs(MenuRadioItem, { value: choice, "data-command": choice, closeOnClick: true, children: [_jsx(Icon, { "aria-hidden": true, className: "text-muted-foreground" }), choice === "paragraph" ? text.text : text.headingLevel(Number(choice.slice(-1)))] }, choice));
|
|
565
|
+
}) }) })] }, "heading"));
|
|
566
|
+
/*
|
|
567
|
+
* Fitting the row to the field, so it never scrolls: beside the Write and Preview tabs while it
|
|
568
|
+
* fits; on its own row under them when it doesn't; and then with the least-used commands, one by
|
|
569
|
+
* one, in the Toolbar's "…" menu — on a phone, say.
|
|
570
|
+
*/
|
|
571
|
+
const barRef = React.useRef(null);
|
|
572
|
+
const tabsRef = React.useRef(null);
|
|
573
|
+
const [stackedOwn, setStacked] = React.useState(false);
|
|
574
|
+
const natural = React.useRef(0);
|
|
575
|
+
const fitBar = React.useCallback(() => {
|
|
576
|
+
const bar = barRef.current;
|
|
577
|
+
if (!bar || !bar.clientWidth || !tabs)
|
|
578
|
+
return;
|
|
579
|
+
// The header's padding, less the row's pull to the start.
|
|
580
|
+
const room = bar.clientWidth - 12;
|
|
581
|
+
const beside = (tabsRef.current?.offsetWidth ?? 0) + 8;
|
|
582
|
+
const next = beside + natural.current > room;
|
|
583
|
+
setStacked((prev) => (prev === next ? prev : next));
|
|
584
|
+
}, [tabs]);
|
|
585
|
+
const host = React.useMemo(() => ({
|
|
586
|
+
onMenuClose: () => focus(),
|
|
587
|
+
onFit: ({ natural: width }) => {
|
|
588
|
+
if (width === natural.current)
|
|
589
|
+
return;
|
|
590
|
+
natural.current = width;
|
|
591
|
+
fitBar();
|
|
592
|
+
},
|
|
593
|
+
}), [focus, fitBar]);
|
|
594
|
+
React.useEffect(() => {
|
|
595
|
+
const bar = barRef.current;
|
|
596
|
+
if (!bar || !tabs || typeof ResizeObserver === "undefined")
|
|
597
|
+
return;
|
|
598
|
+
let width = bar.clientWidth;
|
|
599
|
+
const resize = new ResizeObserver(() => {
|
|
600
|
+
if (bar.clientWidth === width)
|
|
601
|
+
return;
|
|
602
|
+
width = bar.clientWidth;
|
|
603
|
+
fitBar();
|
|
604
|
+
});
|
|
605
|
+
resize.observe(bar);
|
|
606
|
+
return () => resize.disconnect();
|
|
607
|
+
}, [fitBar, tabs, showHeader, toolbarAt]);
|
|
608
|
+
const stacked = tabs && toolbarAt === "top" && stackedOwn;
|
|
609
|
+
const inRow = (c) => shown.includes(c);
|
|
610
|
+
const toolbarRow = showToolbar && (_jsx(ToolbarHostContext.Provider, { value: host, children: _jsxs(Toolbar, { variant: "plain", overflow: true, "data-slot": "markdown-editor-toolbar", "data-position": toolbarAt, "aria-label": text.toolbar, labels: { more: text.more }, className: cn(
|
|
611
|
+
// Its commands fold to fit, so its width never counts toward the field's: in a grid
|
|
612
|
+
// column or a shrink-to-fit box the field takes the room it is given, not the row's.
|
|
613
|
+
"flex-1 py-1 [contain:inline-size]",
|
|
614
|
+
// A finger needs a bigger target than a pointer: 38px buttons on a touch screen.
|
|
615
|
+
touchButtons,
|
|
616
|
+
// Beside the tabs, the commands end at the field's end; otherwise they start at its start.
|
|
617
|
+
tabs && toolbarAt === "top" && !stacked ? "ms-auto [justify-content:safe_flex-end]" : "-ms-2"), children: [groups.map((group, i) => {
|
|
618
|
+
const items = group.filter(inRow);
|
|
619
|
+
if (!items.length)
|
|
620
|
+
return null;
|
|
621
|
+
const before = groups.slice(0, i).some((g) => g.some(inRow));
|
|
622
|
+
return (_jsxs(React.Fragment, { children: [before && _jsx(ToolbarSeparator, {}), _jsx(ToolbarGroup, { children: items.map(toolButton) })] }, i));
|
|
623
|
+
}), takesFiles && (_jsxs(_Fragment, { children: [shown.length > 0 && _jsx(ToolbarSeparator, {}), toolButton("attach")] })), modeToggle && (_jsxs(Tooltip, { children: [_jsxs(TooltipTrigger, { render: _jsx(ToolbarButton, { "data-command": "markdown", "aria-pressed": !rich, disabled: off, overflowPriority: 100, overflowLabel: text.markdown, className: cn(!(tabs && toolbarAt === "top" && !stacked) && "ms-auto"), onMouseDown: (event) => event.preventDefault(), onClick: () => setMode(rich ? "markdown" : "rich") }), children: [_jsx("span", { "aria-hidden": true, className: "px-0.5 font-mono text-11 tracking-[0.06em]", children: "MD" }), _jsx("span", { className: "sr-only", children: text.markdown })] }), _jsx(TooltipContent, { children: text.markdown })] }))] }) }));
|
|
624
|
+
const tabsList = tabs && (_jsxs(TabsList, { ref: tabsRef, variant: "underline", className: "-mb-px shrink-0 gap-5 self-end data-[orientation=horizontal]:bg-none", children: [_jsx(TabsTab, { value: "write", children: text.write }), _jsx(TabsTab, { value: "preview", children: text.preview })] }));
|
|
625
|
+
const header = showHeader && (_jsx("div", { ref: toolbarAt === "top" ? barRef : undefined, "data-slot": "markdown-editor-header", "data-stacked": stacked ? "" : undefined, className: cn("flex min-w-0 border-b border-border/(--hairline-opacity)", stacked ? "flex-col" : "items-stretch gap-2 ps-3 pe-1"), children: stacked ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "flex border-b border-border/(--hairline-opacity) ps-3", children: tabsList }), _jsx("div", { className: "flex min-w-0 ps-3 pe-1", children: toolbarRow })] })) : (_jsxs(_Fragment, { children: [tabsList, toolbarAt === "top" && toolbarRow] })) }));
|
|
626
|
+
const footer = showToolbar && toolbarAt === "bottom" && (_jsx("div", { ref: barRef, "data-slot": "markdown-editor-footer", className: "flex min-w-0 items-stretch gap-2 border-t border-border/(--hairline-opacity) ps-3 pe-1", children: toolbarRow }));
|
|
627
|
+
/* The bubble over a selection, and the slash menu: the rich view only. */
|
|
628
|
+
const bubbleShown = rich && !locked ? bubbleTools.filter((c) => shown.includes(c)) : [];
|
|
629
|
+
const bubble = bubbleShown.length > 0 ? (_jsx(BaseToolbar.Root, { "data-slot": "markdown-editor-bubble-toolbar", "aria-label": text.toolbar, className: cn("flex items-center gap-0.5", touchButtons), children: _jsx(TooltipProvider, { children: bubbleShown.map(toolButton) }) })) : undefined;
|
|
630
|
+
const slashOn = rich && slashCommands && !locked;
|
|
631
|
+
const slashItems = React.useMemo(() => slashOn
|
|
632
|
+
? [
|
|
633
|
+
{
|
|
634
|
+
command: "paragraph",
|
|
635
|
+
label: text.text,
|
|
636
|
+
icon: _jsx(TypeIcon, {}),
|
|
637
|
+
keywords: ["text", "paragraph", "plain"],
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
command: "heading1",
|
|
641
|
+
label: text.headingLevel(1),
|
|
642
|
+
icon: _jsx(Heading1Icon, {}),
|
|
643
|
+
keywords: ["h1", "title", "#"],
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
command: "heading2",
|
|
647
|
+
label: text.headingLevel(2),
|
|
648
|
+
icon: _jsx(Heading2Icon, {}),
|
|
649
|
+
keywords: ["h2", "subtitle", "##"],
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
command: "heading3",
|
|
653
|
+
label: text.headingLevel(3),
|
|
654
|
+
icon: _jsx(Heading3Icon, {}),
|
|
655
|
+
keywords: ["h3", "###"],
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
command: "bulletList",
|
|
659
|
+
label: text.bulletList,
|
|
660
|
+
icon: _jsx(ListIcon, {}),
|
|
661
|
+
keywords: ["bullet", "unordered", "ul", "-"],
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
command: "numberedList",
|
|
665
|
+
label: text.numberedList,
|
|
666
|
+
icon: _jsx(ListOrderedIcon, {}),
|
|
667
|
+
keywords: ["numbered", "ordered", "ol", "1."],
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
command: "taskList",
|
|
671
|
+
label: text.taskList,
|
|
672
|
+
icon: _jsx(ListChecksIcon, {}),
|
|
673
|
+
keywords: ["todo", "task", "checkbox", "check", "[]"],
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
command: "quote",
|
|
677
|
+
label: text.quote,
|
|
678
|
+
icon: _jsx(QuoteIcon, {}),
|
|
679
|
+
keywords: ["blockquote", "citation", ">"],
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
command: "codeBlock",
|
|
683
|
+
label: text.codeBlock,
|
|
684
|
+
icon: _jsx(SquareCodeIcon, {}),
|
|
685
|
+
keywords: ["code", "snippet", "pre", "```"],
|
|
686
|
+
},
|
|
687
|
+
{
|
|
688
|
+
command: "table",
|
|
689
|
+
label: text.table,
|
|
690
|
+
icon: _jsx(TableIcon, {}),
|
|
691
|
+
keywords: ["table", "grid", "columns", "rows", "|"],
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
command: "divider",
|
|
695
|
+
label: text.divider,
|
|
696
|
+
icon: _jsx(MinusIcon, {}),
|
|
697
|
+
keywords: ["divider", "rule", "line", "separator", "hr", "---"],
|
|
698
|
+
},
|
|
699
|
+
...(takesFiles
|
|
700
|
+
? [
|
|
701
|
+
{
|
|
702
|
+
command: "attach",
|
|
703
|
+
label: text.attach,
|
|
704
|
+
icon: _jsx(PaperclipIcon, {}),
|
|
705
|
+
keywords: ["file", "image", "upload", "photo", "attachment"],
|
|
706
|
+
},
|
|
707
|
+
]
|
|
708
|
+
: []),
|
|
709
|
+
]
|
|
710
|
+
: undefined, [slashOn, takesFiles, text]);
|
|
711
|
+
const rows = {
|
|
712
|
+
minHeight: `calc(${minRows}lh + 1.5rem)`,
|
|
713
|
+
maxHeight: `calc(${maxRows}lh + 1.5rem)`,
|
|
714
|
+
};
|
|
715
|
+
const textarea = (_jsxs(_Fragment, { children: [_jsx(InputGroupTextarea, { ref: refs, value: value, id: id, name: name, form: form, placeholder: placeholder, required: required, maxLength: maxLength, autoFocus: autoFocus, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, disabled: disabled, readOnly: readOnly, onChange: (event) => {
|
|
716
|
+
const el = event.currentTarget;
|
|
717
|
+
setValue(el.value);
|
|
718
|
+
setRawLevel(blockLevel(textState(el)));
|
|
719
|
+
}, onKeyDown: handleKeyDown, onPaste: handlePaste, onSelect: (event) => setRawLevel(blockLevel(textState(event.currentTarget))), onFocus: onFocus, onBlur: onBlur,
|
|
720
|
+
// The rich view's type: an input's 14px at 1.5, 16px where a touch screen would zoom.
|
|
721
|
+
className: "block max-h-none min-h-0 text-sm leading-normal sm:text-sm pointer-coarse:text-base", style: { ...rows, ...style } }), children] }));
|
|
722
|
+
// The textarea's box: kept while the preview shows, so its text, selection and undo history stay.
|
|
723
|
+
const write = tabs ? (_jsx(BaseTabs.Panel, { value: "write", keepMounted: true, tabIndex: -1, "data-slot": "markdown-editor-write", className: "relative", children: textarea })) : (_jsx("div", { "data-slot": "markdown-editor-write", className: "relative", children: textarea }));
|
|
724
|
+
const previewPanel = tabs && (_jsx(BaseTabs.Panel, { value: "preview", "data-slot": "markdown-editor-preview", className: "min-w-0 px-3.5 py-3 focus-ring", style: { minHeight: previewHeight }, children: value.trim() ? (_jsx(Response, { smooth: false, children: value })) : (_jsx("p", { className: "text-sm text-muted-foreground", children: text.nothingToPreview })) }));
|
|
725
|
+
const images = files.filter(isImage);
|
|
726
|
+
const others = files.filter((f) => !isImage(f));
|
|
727
|
+
const staged = (files.length > 0 || pending.length > 0) && (_jsxs("div", { role: "group", "aria-label": text.files, "data-slot": "markdown-editor-files", className: "flex flex-col gap-2 border-t border-border/(--hairline-opacity) p-3", children: [images.length > 0 && (_jsx("div", { className: "flex flex-wrap gap-3 pe-2 pt-2", children: images.map((file, i) => (_jsx(PromptInputAttachment, { "data-slot": "markdown-editor-image", file: file, onRemove: locked ? undefined : () => setFiles(files.filter((f) => f !== file)), labels: { remove: text.remove(file.name), preview: text.previewFile(file.name) } }, `${file.name}-${file.size}-${i}`))) })), others.map((file, i) => (_jsx(FileDropItem, { "data-slot": "markdown-editor-file", file: file, labels: { remove: text.remove }, onRemove: locked ? undefined : () => setFiles(files.filter((f) => f !== file)) }, `${file.name}-${file.size}-${i}`))), pending.map(({ file, status }, i) => (_jsxs(Item, { variant: "outline", size: "sm", "data-slot": "markdown-editor-upload", "data-status": status, children: [_jsx(ItemMedia, { variant: "image", className: "grid place-items-center bg-control-surface text-muted-foreground", children: status === "uploading" ? (_jsx(Spinner, { size: "sm", label: text.uploading(file.name) })) : (_jsx(TriangleAlertIcon, { "aria-hidden": true, className: "size-4 text-destructive" })) }), _jsxs(ItemContent, { className: "min-w-0", children: [_jsxs(ItemTitle, { className: "flex max-w-full items-center gap-1.5", title: file.name, children: [isImage(file) ? (_jsx(ImageIcon, { "aria-hidden": true, className: "size-3.5 shrink-0 text-muted-foreground" })) : (_jsx(FileIcon, { "aria-hidden": true, className: "size-3.5 shrink-0 text-muted-foreground" })), _jsx("span", { className: "truncate", children: file.name })] }), _jsx(ItemDescription, { className: cn("font-mono text-11 tabular-nums", status === "error" && "text-destructive"), children: status === "error" ? text.uploadFailed : formatFileSize(file.size, locale) })] }), _jsx(ItemActions, { children: _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": text.remove(file.name), onClick: () => removePending(file), children: _jsx(XIcon, {}) }) })] }, `${file.name}-${file.size}-${i}`)))] }));
|
|
728
|
+
const fileField = takesFiles && (_jsx("input", { ref: fileInput, type: "file", hidden: true, tabIndex: -1, "aria-hidden": true, accept: accept, multiple: maxFiles !== 1, disabled: locked, "data-slot": "markdown-editor-input", onChange: (event) => {
|
|
729
|
+
const chosen = [...(event.currentTarget.files ?? [])];
|
|
730
|
+
// Reset, so the same file can be chosen again.
|
|
731
|
+
event.currentTarget.value = "";
|
|
732
|
+
take(chosen);
|
|
733
|
+
} }));
|
|
734
|
+
const field = (body, extra) => (_jsxs(InputGroup, { "data-slot": "markdown-editor", "data-mode": mode, "data-tab": tabs ? tab : undefined, "data-dragging": dragging ? "" : undefined, "data-disabled": off ? "" : undefined, "data-readonly": readOnly ? "" : undefined, ...extra, className: cn("min-h-0 flex-col items-stretch data-dragging:border-control-focus",
|
|
735
|
+
// The rich view's text is no input: its focus, invalid and disabled states are drawn here.
|
|
736
|
+
rich && [
|
|
737
|
+
"not-has-[[data-slot=markdown-editor-content][aria-invalid=true]]:has-[[data-slot=markdown-editor-content]:focus]:border-[color-mix(in_oklab,var(--field-edge),var(--control-focus))]",
|
|
738
|
+
"has-[[data-slot=markdown-editor-content][aria-invalid=true]]:border-destructive has-[[data-slot=markdown-editor-content][aria-invalid=true]]:shadow-invalid",
|
|
739
|
+
"data-disabled:cursor-not-allowed data-disabled:opacity-55",
|
|
740
|
+
], className), onDragOver: (event) => {
|
|
741
|
+
if (!takesFiles || locked || !hasFiles(event))
|
|
742
|
+
return;
|
|
743
|
+
event.preventDefault();
|
|
744
|
+
event.dataTransfer.dropEffect = "copy";
|
|
745
|
+
setDragging(true);
|
|
746
|
+
}, onDragLeave: (event) => {
|
|
747
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
748
|
+
setDragging(false);
|
|
749
|
+
}, onDrop: (event) => {
|
|
750
|
+
setDragging(false);
|
|
751
|
+
if (!takesFiles || locked || !hasFiles(event) || event.defaultPrevented)
|
|
752
|
+
return;
|
|
753
|
+
event.preventDefault();
|
|
754
|
+
take(filesOf(event.dataTransfer));
|
|
755
|
+
}, children: [header, body, previewPanel, staged, footer, fileField] }));
|
|
756
|
+
/* The label of a Field points at the rich text, which a label cannot focus: send its clicks there. */
|
|
757
|
+
const richId = React.useRef(undefined);
|
|
758
|
+
React.useEffect(() => {
|
|
759
|
+
if (!rich)
|
|
760
|
+
return;
|
|
761
|
+
const onClick = (event) => {
|
|
762
|
+
const label = event.target?.closest?.("label");
|
|
763
|
+
if (label && richId.current && label.htmlFor === richId.current)
|
|
764
|
+
richRef.current?.focus();
|
|
765
|
+
};
|
|
766
|
+
document.addEventListener("click", onClick);
|
|
767
|
+
return () => document.removeEventListener("click", onClick);
|
|
768
|
+
}, [rich]);
|
|
769
|
+
const richView = rich && (_jsx(BaseField.Control, { ref: richControl, id: id, name: name, value: value, disabled: disabled,
|
|
770
|
+
// The Field's control, out of sight, holds the markdown for forms and carries `required`, as
|
|
771
|
+
// TagsInput's does; the text takes the label, the descriptions and the validity.
|
|
772
|
+
render: (control) => {
|
|
773
|
+
const { ref: controlRef, id: controlId, name: formName, value: _value, disabled: controlOff, onChange: fieldChange, onFocus: fieldFocus, onBlur: fieldBlur, "aria-labelledby": labelledBy, "aria-describedby": describedBy, "aria-invalid": invalid, } = control;
|
|
774
|
+
richId.current = controlId;
|
|
775
|
+
const isOff = disabled || !!controlOff;
|
|
776
|
+
return field(_jsxs(_Fragment, { children: [_jsx(RichSurface, { handle: richRef, value: value, onChange: setValue, onEditor: setEditor, placeholder: placeholder, editable: !(isOff || readOnly), autoFocus: autoFocus, maxLength: maxLength, minRows: minRows, maxRows: maxRows, attrs: {
|
|
777
|
+
id: controlId,
|
|
778
|
+
"aria-label": ariaLabel,
|
|
779
|
+
"aria-labelledby": labelledBy ?? ariaLabelledBy,
|
|
780
|
+
"aria-describedby": [describedBy, ariaDescribedBy].filter(Boolean).join(" ") || undefined,
|
|
781
|
+
"aria-invalid": invalid ? "true" : undefined,
|
|
782
|
+
"aria-required": required ? "true" : undefined,
|
|
783
|
+
"aria-disabled": isOff ? "true" : undefined,
|
|
784
|
+
}, mentions: mentions, slash: slashItems, hint: slashOn ? text.slashHint : undefined, onAttach: () => fileInput.current?.click(), markdownShortcuts: markdownShortcuts, bubble: bubble,
|
|
785
|
+
// Under the selection when the toolbar is above the text, so it never covers it.
|
|
786
|
+
bubbleSide: showToolbar && toolbarAt === "top" ? "bottom" : "top", text: {
|
|
787
|
+
link: text.link,
|
|
788
|
+
linkPlaceholder: text.linkPlaceholder,
|
|
789
|
+
linkApply: text.linkApply,
|
|
790
|
+
linkOpen: text.linkOpen,
|
|
791
|
+
linkRemove: text.linkRemove,
|
|
792
|
+
mentionsLabel: text.mentions,
|
|
793
|
+
mentionsLoading: text.mentionsLoading,
|
|
794
|
+
mentionsEmpty: text.mentionsEmpty,
|
|
795
|
+
mentionsResults: text.mentionsResults,
|
|
796
|
+
slashLabel: text.slashCommands,
|
|
797
|
+
headingLevel: text.headingLevel,
|
|
798
|
+
table: text.table,
|
|
799
|
+
addRowAbove: text.addRowAbove,
|
|
800
|
+
addRowBelow: text.addRowBelow,
|
|
801
|
+
addColumnBefore: text.addColumnBefore,
|
|
802
|
+
addColumnAfter: text.addColumnAfter,
|
|
803
|
+
deleteRow: text.deleteRow,
|
|
804
|
+
deleteColumn: text.deleteColumn,
|
|
805
|
+
deleteTable: text.deleteTable,
|
|
806
|
+
imageAlt: text.imageAlt,
|
|
807
|
+
imageAltPlaceholder: text.imageAltPlaceholder,
|
|
808
|
+
imageRemove: text.imageRemove,
|
|
809
|
+
}, onFiles: takesFiles ? take : undefined, submitOnEnter: submitOnEnter, onSubmit: submit, shortcuts: shortcuts, onKeyDown: onKeyDown, onPaste: onPaste, onFocus: (event) => {
|
|
810
|
+
onFocus?.(event);
|
|
811
|
+
fieldFocus?.(event);
|
|
812
|
+
}, onBlur: (event) => {
|
|
813
|
+
onBlur?.(event);
|
|
814
|
+
// Focus leaving the text — not into its link popover — is a blur for the Field.
|
|
815
|
+
if (event.currentTarget.contains(event.relatedTarget))
|
|
816
|
+
return;
|
|
817
|
+
if (richControl.current)
|
|
818
|
+
fieldBlur?.({
|
|
819
|
+
currentTarget: richControl.current,
|
|
820
|
+
});
|
|
821
|
+
}, style: style }), children, _jsx("div", { className: "sr-only", children: _jsx("textarea", { ref: controlRef, name: formName, form: form, value: value, onChange: fieldChange, required: required, disabled: isOff, readOnly: readOnly, "aria-hidden": true, tabIndex: -1, "data-slot": "markdown-editor-value",
|
|
822
|
+
// A submit that finds it empty focuses it; it hands focus on to the text.
|
|
823
|
+
onFocus: () => richRef.current?.focus() }) })] }));
|
|
824
|
+
} }));
|
|
825
|
+
return (_jsx(MarkdownEditorContext.Provider, { value: context, children: rich ? (richView) : tabs ? (_jsx(BaseTabs.Root, { value: tab, onValueChange: (next) => {
|
|
826
|
+
// The preview opens at the height the text had, so the page doesn't jump.
|
|
827
|
+
if (next === "preview")
|
|
828
|
+
setPreviewHeight(textareaRef.current?.offsetHeight);
|
|
829
|
+
setTab(next);
|
|
830
|
+
}, className: "contents", children: field(write) })) : (field(write)) }));
|
|
831
|
+
}
|