@keboola/design 1.0.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/README.md +83 -0
- package/package.json +151 -0
- package/src/blocks/AIKit/AnswerSummary.stories.tsx +38 -0
- package/src/blocks/AIKit/AnswerSummary.tsx +63 -0
- package/src/blocks/AIKit/CollapsibleStepHeader.stories.tsx +53 -0
- package/src/blocks/AIKit/CollapsibleStepHeader.tsx +65 -0
- package/src/blocks/AIKit/InlineStepDetail.stories.tsx +25 -0
- package/src/blocks/AIKit/InlineStepDetail.tsx +13 -0
- package/src/blocks/AIKit/InlineStepLabel.stories.tsx +37 -0
- package/src/blocks/AIKit/InlineStepLabel.tsx +36 -0
- package/src/blocks/AIKit/MessageBubble.stories.tsx +137 -0
- package/src/blocks/AIKit/MessageBubble.tsx +68 -0
- package/src/blocks/AIKit/PlanApproval.stories.tsx +121 -0
- package/src/blocks/AIKit/PlanApproval.test.tsx +241 -0
- package/src/blocks/AIKit/PlanApproval.tsx +345 -0
- package/src/blocks/AIKit/PlanRewritingIndicator.test.tsx +17 -0
- package/src/blocks/AIKit/PlanRewritingIndicator.tsx +20 -0
- package/src/blocks/AIKit/PromptInput.stories.tsx +98 -0
- package/src/blocks/AIKit/PromptInput.tsx +218 -0
- package/src/blocks/AIKit/PromptInputAction.tsx +18 -0
- package/src/blocks/AIKit/PromptInputSubmit.tsx +55 -0
- package/src/blocks/AIKit/Question.stories.tsx +235 -0
- package/src/blocks/AIKit/Question.tsx +323 -0
- package/src/blocks/AIKit/QuestionBlock.stories.tsx +99 -0
- package/src/blocks/AIKit/QuestionBlock.tsx +83 -0
- package/src/blocks/AIKit/SuggestedPrompt.stories.tsx +88 -0
- package/src/blocks/AIKit/SuggestedPrompt.tsx +35 -0
- package/src/blocks/AIKit/ThinkingIndicator.stories.tsx +21 -0
- package/src/blocks/AIKit/ThinkingIndicator.tsx +14 -0
- package/src/blocks/AIKit/index.ts +12 -0
- package/src/blocks/AutoSaveTextarea/AutoSaveTextarea.stories.tsx +78 -0
- package/src/blocks/AutoSaveTextarea/AutoSaveTextarea.tsx +103 -0
- package/src/blocks/AutoSaveTextarea/index.ts +1 -0
- package/src/blocks/ClipboardButton/ClipboardButton.stories.tsx +28 -0
- package/src/blocks/ClipboardButton/ClipboardButton.tsx +41 -0
- package/src/blocks/ClipboardButton/ClipboardInline.tsx +41 -0
- package/src/blocks/ClipboardButton/index.ts +2 -0
- package/src/blocks/ColorInput/ColorInput.stories.tsx +109 -0
- package/src/blocks/ColorInput/ColorInput.test.tsx +163 -0
- package/src/blocks/ColorInput/ColorInput.tsx +169 -0
- package/src/blocks/ColorInput/ColorPicker.tsx +39 -0
- package/src/blocks/ColorInput/index.ts +1 -0
- package/src/blocks/ColorInput/utils.test.ts +189 -0
- package/src/blocks/ColorInput/utils.ts +74 -0
- package/src/blocks/EmptyConfigurationActionCard/EmptyConfigurationActionCard.stories.tsx +30 -0
- package/src/blocks/EmptyConfigurationActionCard/EmptyConfigurationActionCard.tsx +20 -0
- package/src/blocks/EmptyConfigurationActionCard/index.ts +1 -0
- package/src/blocks/EmptyState/EmptyState.stories.tsx +93 -0
- package/src/blocks/EmptyState/EmptyState.tsx +130 -0
- package/src/blocks/EmptyState/index.ts +1 -0
- package/src/blocks/ErrorState/ErrorState.stories.tsx +125 -0
- package/src/blocks/ErrorState/ErrorState.tsx +132 -0
- package/src/blocks/ErrorState/index.ts +1 -0
- package/src/blocks/Form/components/FormBody.tsx +27 -0
- package/src/blocks/Form/components/SubmitButton.tsx +30 -0
- package/src/blocks/Form/connectors/CheckboxField.tsx +34 -0
- package/src/blocks/Form/connectors/FieldShell.tsx +46 -0
- package/src/blocks/Form/connectors/NumberField.tsx +36 -0
- package/src/blocks/Form/connectors/PasswordField.tsx +38 -0
- package/src/blocks/Form/connectors/SelectField.tsx +73 -0
- package/src/blocks/Form/connectors/SwitchField.tsx +34 -0
- package/src/blocks/Form/connectors/TextAreaField.tsx +36 -0
- package/src/blocks/Form/connectors/TextField.tsx +36 -0
- package/src/blocks/Form/contexts.ts +4 -0
- package/src/blocks/Form/formHook.ts +30 -0
- package/src/blocks/Form/index.ts +2 -0
- package/src/blocks/Form/setServerFieldErrors.test.ts +38 -0
- package/src/blocks/Form/setServerFieldErrors.ts +21 -0
- package/src/blocks/MermaidDiagram/MermaidDiagram.stories.tsx +87 -0
- package/src/blocks/MermaidDiagram/MermaidDiagram.tsx +266 -0
- package/src/blocks/MermaidDiagram/index.ts +1 -0
- package/src/blocks/MultiActionButtonGroup/MultiActionButton.stories.tsx +118 -0
- package/src/blocks/MultiActionButtonGroup/MultiActionButton.tsx +40 -0
- package/src/blocks/MultiActionButtonGroup/MultiActionButtonGroup.tsx +16 -0
- package/src/blocks/MultiActionButtonGroup/index.ts +1 -0
- package/src/blocks/MultiCombobox/MultiCombobox.stories.tsx +324 -0
- package/src/blocks/MultiCombobox/MultiCombobox.tsx +241 -0
- package/src/blocks/MultiCombobox/index.ts +1 -0
- package/src/blocks/NumberInput/NumberInput.stories.tsx +112 -0
- package/src/blocks/NumberInput/NumberInput.test.tsx +148 -0
- package/src/blocks/NumberInput/NumberInput.tsx +89 -0
- package/src/blocks/NumberInput/index.ts +1 -0
- package/src/blocks/PageHeader/AGENTS.md +77 -0
- package/src/blocks/PageHeader/PageHeader.stories.tsx +272 -0
- package/src/blocks/PageHeader/PageHeader.tsx +7 -0
- package/src/blocks/PageHeader/PageHeaderDetail.tsx +62 -0
- package/src/blocks/PageHeader/PageHeaderIndex.tsx +56 -0
- package/src/blocks/PageHeader/index.ts +1 -0
- package/src/blocks/PageHeader/styles.ts +6 -0
- package/src/blocks/PageLayout/AGENTS.md +94 -0
- package/src/blocks/PageLayout/PageLayout.stories.tsx +143 -0
- package/src/blocks/PageLayout/PageLayout.tsx +130 -0
- package/src/blocks/PageLayout/index.ts +1 -0
- package/src/blocks/PasswordInput/PasswordInput.stories.tsx +114 -0
- package/src/blocks/PasswordInput/PasswordInput.test.tsx +219 -0
- package/src/blocks/PasswordInput/PasswordInput.tsx +180 -0
- package/src/blocks/PasswordInput/index.ts +1 -0
- package/src/blocks/SearchInput/SearchInput.stories.tsx +127 -0
- package/src/blocks/SearchInput/SearchInput.test.tsx +162 -0
- package/src/blocks/SearchInput/SearchInput.tsx +146 -0
- package/src/blocks/SearchInput/index.ts +1 -0
- package/src/blocks/SearchInputWithNavigation/SearchInputWithNavigation.stories.tsx +73 -0
- package/src/blocks/SearchInputWithNavigation/SearchInputWithNavigation.tsx +89 -0
- package/src/blocks/SearchInputWithNavigation/index.ts +1 -0
- package/src/blocks/SplitButton/SplitButton.stories.tsx +88 -0
- package/src/blocks/SplitButton/SplitButton.tsx +68 -0
- package/src/blocks/SplitButton/index.ts +1 -0
- package/src/blocks/Tagger/TagItem.tsx +29 -0
- package/src/blocks/Tagger/TagSelectPopover/TagSelectCreateItem.tsx +42 -0
- package/src/blocks/Tagger/TagSelectPopover/TagSelectItem.tsx +31 -0
- package/src/blocks/Tagger/TagSelectPopover/TagSelectList.tsx +67 -0
- package/src/blocks/Tagger/TagSelectPopover/TagSelectPopover.tsx +34 -0
- package/src/blocks/Tagger/TagSelectPopover/TagSelectValue.tsx +47 -0
- package/src/blocks/Tagger/TagSelectPopover/index.ts +1 -0
- package/src/blocks/Tagger/Tagger.stories.tsx +80 -0
- package/src/blocks/Tagger/Tagger.tsx +101 -0
- package/src/blocks/Tagger/index.ts +1 -0
- package/src/blocks/Tagger/types.ts +11 -0
- package/src/blocks/Textarea/Textarea.stories.tsx +47 -0
- package/src/blocks/Textarea/Textarea.tsx +50 -0
- package/src/blocks/Textarea/index.ts +1 -0
- package/src/components/Alert/Alert.stories.tsx +93 -0
- package/src/components/Alert/Alert.tsx +103 -0
- package/src/components/Alert/AlertAction.tsx +31 -0
- package/src/components/Alert/AlertCollapsibleIcon.tsx +26 -0
- package/src/components/Alert/AlertDescription.tsx +31 -0
- package/src/components/Alert/AlertIcon.tsx +43 -0
- package/src/components/Alert/AlertRoot.tsx +64 -0
- package/src/components/Alert/AlertTitle.tsx +25 -0
- package/src/components/Alert/index.ts +1 -0
- package/src/components/Avatar.stories.tsx +22 -0
- package/src/components/Avatar.tsx +88 -0
- package/src/components/Badge/Badge.stories.tsx +106 -0
- package/src/components/Badge/Badge.tsx +55 -0
- package/src/components/Badge/BadgeAddon.tsx +63 -0
- package/src/components/Badge/BadgeButton.tsx +39 -0
- package/src/components/Badge/BadgeLabel.tsx +37 -0
- package/src/components/Badge/BadgeRoot.tsx +21 -0
- package/src/components/Badge/index.ts +1 -0
- package/src/components/Badge/styles.ts +74 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.tsx +135 -0
- package/src/components/Breadcrumb/Breadcrumb.tsx +23 -0
- package/src/components/Breadcrumb/BreadcrumbEllipsis.tsx +43 -0
- package/src/components/Breadcrumb/BreadcrumbItem.tsx +9 -0
- package/src/components/Breadcrumb/BreadcrumbLink.tsx +48 -0
- package/src/components/Breadcrumb/BreadcrumbList.tsx +26 -0
- package/src/components/Breadcrumb/BreadcrumbPage.tsx +22 -0
- package/src/components/Breadcrumb/BreadcrumbSeparator.tsx +28 -0
- package/src/components/Breadcrumb/index.ts +1 -0
- package/src/components/Button/Button.stories.tsx +68 -0
- package/src/components/Button/Button.tsx +73 -0
- package/src/components/Button/ButtonInline.stories.tsx +54 -0
- package/src/components/Button/ButtonInline.tsx +73 -0
- package/src/components/Button/index.ts +3 -0
- package/src/components/Button/styles.ts +292 -0
- package/src/components/ButtonGroup/ButtonGroup.stories.tsx +118 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +79 -0
- package/src/components/ButtonGroup/index.ts +1 -0
- package/src/components/Calendar/Calendar.stories.tsx +101 -0
- package/src/components/Calendar/Calendar.tsx +44 -0
- package/src/components/Calendar/index.ts +2 -0
- package/src/components/Card/Card.stories.tsx +60 -0
- package/src/components/Card/Card.tsx +25 -0
- package/src/components/Card/CardContent.tsx +5 -0
- package/src/components/Card/CardHeader.tsx +5 -0
- package/src/components/Card/CardTitle.tsx +13 -0
- package/src/components/Card/index.ts +1 -0
- package/src/components/Card/styles.ts +32 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +210 -0
- package/src/components/Checkbox/Checkbox.test.tsx +140 -0
- package/src/components/Checkbox/Checkbox.tsx +86 -0
- package/src/components/Checkbox/index.ts +1 -0
- package/src/components/Checkbox/styles.ts +77 -0
- package/src/components/Clipboard/Clipboard.stories.tsx +44 -0
- package/src/components/Clipboard/Clipboard.tsx +89 -0
- package/src/components/Clipboard/index.ts +1 -0
- package/src/components/CodeEditor/ButtonToolbar.tsx +14 -0
- package/src/components/CodeEditor/CodeEditor.tsx +155 -0
- package/src/components/CodeEditor/SqlEditor.stories.tsx +76 -0
- package/src/components/CodeEditor/SqlEditor.tsx +206 -0
- package/src/components/CodeEditor/ToggleComponentHelp.tsx +7 -0
- package/src/components/CodeEditor/activeQueryHighlight.test.ts +178 -0
- package/src/components/CodeEditor/activeQueryHighlight.ts +245 -0
- package/src/components/CodeEditor/helpers.ts +100 -0
- package/src/components/CodeEditor/highlighting.ts +184 -0
- package/src/components/CodeEditor/index.ts +3 -0
- package/src/components/CodeEditor/search.ts +186 -0
- package/src/components/Collapse.stories.tsx +56 -0
- package/src/components/Collapse.tsx +61 -0
- package/src/components/Collapsible/Collapsible.stories.tsx +55 -0
- package/src/components/Collapsible/Collapsible.tsx +11 -0
- package/src/components/Collapsible/CollapsibleContent.tsx +25 -0
- package/src/components/Collapsible/index.ts +1 -0
- package/src/components/CollapsiblePanel.stories.tsx +25 -0
- package/src/components/CollapsiblePanel.tsx +130 -0
- package/src/components/Combobox/Combobox.stories.tsx +426 -0
- package/src/components/Combobox/Combobox.test.tsx +165 -0
- package/src/components/Combobox/Combobox.tsx +347 -0
- package/src/components/Combobox/ComboboxChips.tsx +63 -0
- package/src/components/Combobox/ComboboxContent.tsx +95 -0
- package/src/components/Combobox/ComboboxEmpty.tsx +30 -0
- package/src/components/Combobox/ComboboxInput.tsx +10 -0
- package/src/components/Combobox/ComboboxInputGroup.tsx +38 -0
- package/src/components/Combobox/ComboboxItem.tsx +71 -0
- package/src/components/Combobox/ComboboxItemIndicator.tsx +76 -0
- package/src/components/Combobox/ComboboxList.tsx +32 -0
- package/src/components/Combobox/ComboboxRoot.tsx +5 -0
- package/src/components/Combobox/ComboboxSeparator.tsx +20 -0
- package/src/components/Combobox/Group/ComboboxCollection.tsx +7 -0
- package/src/components/Combobox/Group/ComboboxGroup.tsx +23 -0
- package/src/components/Combobox/Group/ComboboxGroupLabel.tsx +38 -0
- package/src/components/Combobox/Group/index.ts +3 -0
- package/src/components/Combobox/index.ts +1 -0
- package/src/components/Combobox/types.ts +26 -0
- package/src/components/Combobox/utils.test.ts +95 -0
- package/src/components/Combobox/utils.ts +103 -0
- package/src/components/Command/Command.stories.tsx +376 -0
- package/src/components/Command/Command.tsx +37 -0
- package/src/components/Command/CommandContent.tsx +19 -0
- package/src/components/Command/CommandEmpty.tsx +6 -0
- package/src/components/Command/CommandGroup.tsx +26 -0
- package/src/components/Command/CommandInput.tsx +27 -0
- package/src/components/Command/CommandItem/CheckIndicator.tsx +74 -0
- package/src/components/Command/CommandItem/CommandItem.tsx +91 -0
- package/src/components/Command/CommandItem/index.ts +1 -0
- package/src/components/Command/CommandList.tsx +32 -0
- package/src/components/Command/CommandSeparator.tsx +13 -0
- package/src/components/Command/index.ts +6 -0
- package/src/components/DatePicker/DatePicker.tsx +37 -0
- package/src/components/DatePicker/index.ts +1 -0
- package/src/components/DiffView/DiffView.stories.tsx +80 -0
- package/src/components/DiffView/DiffView.tsx +131 -0
- package/src/components/DiffView/DiffViewMark.tsx +21 -0
- package/src/components/DiffView/DiffViewTd.tsx +84 -0
- package/src/components/DiffView/DiffViewTh.tsx +23 -0
- package/src/components/DiffView/index.ts +11 -0
- package/src/components/DiffView/util.test.ts +231 -0
- package/src/components/DiffView/util.ts +311 -0
- package/src/components/DotsLoader.tsx +22 -0
- package/src/components/DropdownMenu/DropdownMenu.stories.tsx +306 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +61 -0
- package/src/components/DropdownMenu/DropdownMenuCheckboxItem.tsx +52 -0
- package/src/components/DropdownMenu/DropdownMenuContent.tsx +52 -0
- package/src/components/DropdownMenu/DropdownMenuContext.tsx +13 -0
- package/src/components/DropdownMenu/DropdownMenuItem.tsx +74 -0
- package/src/components/DropdownMenu/DropdownMenuItemDescription.tsx +42 -0
- package/src/components/DropdownMenu/DropdownMenuItemIndicator.tsx +98 -0
- package/src/components/DropdownMenu/DropdownMenuLabel.tsx +21 -0
- package/src/components/DropdownMenu/DropdownMenuRadioGroup/DropdownMenuRadioGroup.tsx +31 -0
- package/src/components/DropdownMenu/DropdownMenuRadioGroup/DropdownMenuRadioItem.tsx +64 -0
- package/src/components/DropdownMenu/DropdownMenuRadioGroup/index.ts +2 -0
- package/src/components/DropdownMenu/DropdownMenuSeparator.tsx +35 -0
- package/src/components/DropdownMenu/DropdownMenuSub/DropdownMenuSub.tsx +3 -0
- package/src/components/DropdownMenu/DropdownMenuSub/DropdownMenuSubContent.tsx +21 -0
- package/src/components/DropdownMenu/DropdownMenuSub/DropdownMenuSubTrigger.tsx +17 -0
- package/src/components/DropdownMenu/DropdownMenuSub/index.ts +3 -0
- package/src/components/DropdownMenu/DropdownMenuTrigger.tsx +19 -0
- package/src/components/DropdownMenu/ItemIcon.tsx +22 -0
- package/src/components/DropdownMenu/index.ts +1 -0
- package/src/components/DropdownMenu/styles.ts +82 -0
- package/src/components/EmptySearchContent.stories.tsx +12 -0
- package/src/components/EmptySearchContent.tsx +13 -0
- package/src/components/FieldBox/FieldBox.stories.tsx +138 -0
- package/src/components/FieldBox/FieldBox.tsx +43 -0
- package/src/components/FieldBox/FieldBoxDescription.tsx +18 -0
- package/src/components/FieldBox/FieldBoxTitle.tsx +20 -0
- package/src/components/FieldBox/index.ts +1 -0
- package/src/components/FieldBox/styles.ts +37 -0
- package/src/components/FormGroup/FormGroup.stories.tsx +120 -0
- package/src/components/FormGroup/FormGroup.tsx +33 -0
- package/src/components/FormGroup/FormGroupColorInput.tsx +15 -0
- package/src/components/FormGroup/FormGroupHelp.tsx +17 -0
- package/src/components/FormGroup/FormGroupNumberInput.tsx +15 -0
- package/src/components/FormGroup/FormGroupTextInput.tsx +15 -0
- package/src/components/FormGroup/FormGroupTextarea.tsx +12 -0
- package/src/components/FormGroup/context.ts +11 -0
- package/src/components/FormGroup/index.ts +2 -0
- package/src/components/FormGroup/types.ts +5 -0
- package/src/components/FullScreenModal/FullScreenModal.tsx +8 -0
- package/src/components/FullScreenModal/FullScreenModalBody.tsx +16 -0
- package/src/components/FullScreenModal/FullScreenModalHeader.tsx +89 -0
- package/src/components/FullScreenModal/FullScreenModalRoot.tsx +79 -0
- package/src/components/FullScreenModal/index.ts +3 -0
- package/src/components/HelpBlock/HelpBlock.stories.tsx +28 -0
- package/src/components/HelpBlock/HelpBlock.tsx +31 -0
- package/src/components/HelpBlock/index.ts +1 -0
- package/src/components/HoverCard/HoverCard.stories.tsx +77 -0
- package/src/components/HoverCard/HoverCard.tsx +13 -0
- package/src/components/HoverCard/HoverCardContent.tsx +63 -0
- package/src/components/HoverCard/index.ts +1 -0
- package/src/components/Icon/Icon.stories.tsx +26 -0
- package/src/components/Icon/Icon.tsx +10 -0
- package/src/components/Icon/Icons.mdx +28 -0
- package/src/components/Icon/constants.ts +1 -0
- package/src/components/Icon/index.ts +27 -0
- package/src/components/Input/DateInput/DateInput.stories.tsx +58 -0
- package/src/components/Input/DateInput/DateInput.tsx +140 -0
- package/src/components/Input/DateInput/helpers.test.ts +102 -0
- package/src/components/Input/DateInput/helpers.ts +59 -0
- package/src/components/Input/DateInput/index.ts +1 -0
- package/src/components/Input/DateRangeInput/DateRangeInput.stories.tsx +66 -0
- package/src/components/Input/DateRangeInput/DateRangeInput.tsx +141 -0
- package/src/components/Input/DateRangeInput/helpers.test.ts +146 -0
- package/src/components/Input/DateRangeInput/helpers.ts +36 -0
- package/src/components/Input/DateRangeInput/index.ts +1 -0
- package/src/components/Input/Input.stories.tsx +93 -0
- package/src/components/Input/Input.test.tsx +112 -0
- package/src/components/Input/Input.tsx +147 -0
- package/src/components/Input/TextInput/TextInput.stories.tsx +68 -0
- package/src/components/Input/TextInput/TextInput.test.tsx +52 -0
- package/src/components/Input/TextInput/TextInput.tsx +57 -0
- package/src/components/Input/TextInput/index.ts +1 -0
- package/src/components/Input/TimeInput/TimeInput.stories.tsx +89 -0
- package/src/components/Input/TimeInput/TimeInput.tsx +103 -0
- package/src/components/Input/TimeInput/index.ts +1 -0
- package/src/components/Input/index.ts +4 -0
- package/src/components/Input/utils.ts +11 -0
- package/src/components/InputGroup/InputGroup.stories.tsx +208 -0
- package/src/components/InputGroup/InputGroup.tsx +228 -0
- package/src/components/InputGroup/InputGroupAddon.tsx +46 -0
- package/src/components/InputGroup/InputGroupButton.tsx +25 -0
- package/src/components/InputGroup/InputGroupInput.tsx +34 -0
- package/src/components/InputGroup/InputGroupText.tsx +21 -0
- package/src/components/InputGroup/InputGroupTextArea.tsx +78 -0
- package/src/components/InputGroup/index.ts +1 -0
- package/src/components/Kbd/Kbd.stories.tsx +82 -0
- package/src/components/Kbd/Kbd.tsx +17 -0
- package/src/components/Kbd/KbdGroup.tsx +35 -0
- package/src/components/Kbd/KbdSeparator.tsx +9 -0
- package/src/components/Kbd/index.ts +3 -0
- package/src/components/Kbd/keyboardKeys.ts +40 -0
- package/src/components/Kbd/styles.ts +39 -0
- package/src/components/Label/Label.stories.tsx +53 -0
- package/src/components/Label/Label.tsx +31 -0
- package/src/components/Label/index.ts +1 -0
- package/src/components/Link.stories.tsx +19 -0
- package/src/components/Link.tsx +37 -0
- package/src/components/MarkdownEditor/MarkdownEditor.stories.tsx +120 -0
- package/src/components/MarkdownEditor/MarkdownEditor.test.ts +171 -0
- package/src/components/MarkdownEditor/MarkdownEditor.tsx +155 -0
- package/src/components/MarkdownEditor/context.ts +10 -0
- package/src/components/MarkdownEditor/index.ts +1 -0
- package/src/components/MarkdownEditor/nodes/ImageNode.tsx +115 -0
- package/src/components/MarkdownEditor/nodes/ImageNodeComponent.tsx +18 -0
- package/src/components/MarkdownEditor/nodes/MermaidNode.tsx +72 -0
- package/src/components/MarkdownEditor/nodes/MermaidNodeComponent.tsx +35 -0
- package/src/components/MarkdownEditor/plugins/ImagePastePlugin.tsx +149 -0
- package/src/components/MarkdownEditor/plugins/KeyboardPlugin.tsx +37 -0
- package/src/components/MarkdownEditor/plugins/MarkdownSyncPlugin.tsx +56 -0
- package/src/components/MarkdownEditor/plugins/ToolbarPlugin.tsx +274 -0
- package/src/components/MarkdownEditor/plugins/toolbar/AlignmentDropdown.tsx +93 -0
- package/src/components/MarkdownEditor/plugins/toolbar/BlockTypeDropdown.tsx +133 -0
- package/src/components/MarkdownEditor/plugins/toolbar/LinkPanel.tsx +160 -0
- package/src/components/MarkdownEditor/plugins/toolbar/ToolbarButton.tsx +36 -0
- package/src/components/MarkdownEditor/plugins/toolbar/ToolbarDivider.tsx +1 -0
- package/src/components/MarkdownEditor/theme.ts +39 -0
- package/src/components/MarkdownEditor/transformers.ts +179 -0
- package/src/components/MarkedText/MarkedText.stories.tsx +46 -0
- package/src/components/MarkedText/MarkedText.tsx +36 -0
- package/src/components/MarkedText/index.ts +1 -0
- package/src/components/MarkedText/utils.test.ts +193 -0
- package/src/components/MarkedText/utils.ts +37 -0
- package/src/components/MergeEditor/AcceptControls/AcceptButton.tsx +20 -0
- package/src/components/MergeEditor/AcceptControls/AcceptControls.tsx +66 -0
- package/src/components/MergeEditor/ConflictStatus/ConflictStatusIndicator.tsx +38 -0
- package/src/components/MergeEditor/MergeEditor.stories.tsx +211 -0
- package/src/components/MergeEditor/MergeEditor.tsx +116 -0
- package/src/components/MergeEditor/MergePane.tsx +95 -0
- package/src/components/MergeEditor/PaneHeader.tsx +11 -0
- package/src/components/MergeEditor/constants.ts +48 -0
- package/src/components/MergeEditor/decorations.ts +126 -0
- package/src/components/MergeEditor/helpers.test.ts +172 -0
- package/src/components/MergeEditor/helpers.ts +118 -0
- package/src/components/MergeEditor/index.ts +5 -0
- package/src/components/MergeEditor/useMergeDiff.ts +573 -0
- package/src/components/MergeEditor/useScrollSync.ts +79 -0
- package/src/components/Modal/Modal.stories.tsx +678 -0
- package/src/components/Modal/Modal.tsx +23 -0
- package/src/components/Modal/ModalBody.tsx +23 -0
- package/src/components/Modal/ModalCloseIcon.tsx +32 -0
- package/src/components/Modal/ModalContent.tsx +87 -0
- package/src/components/Modal/ModalDescription.tsx +20 -0
- package/src/components/Modal/ModalFooter.tsx +15 -0
- package/src/components/Modal/ModalHeader.tsx +50 -0
- package/src/components/Modal/ModalIcon.tsx +83 -0
- package/src/components/Modal/ModalOverlay.tsx +42 -0
- package/src/components/Modal/ModalTitle.tsx +12 -0
- package/src/components/Modal/index.ts +1 -0
- package/src/components/Navbar/Navbar.stories.tsx +179 -0
- package/src/components/Navbar/Navbar.tsx +80 -0
- package/src/components/Navbar/NavbarContent.tsx +20 -0
- package/src/components/Navbar/NavbarFooter.tsx +11 -0
- package/src/components/Navbar/NavbarHeader.tsx +11 -0
- package/src/components/Navbar/NavbarMenu.tsx +30 -0
- package/src/components/Navbar/NavbarMenuAvatar.tsx +67 -0
- package/src/components/Navbar/NavbarMenuButton.tsx +134 -0
- package/src/components/Navbar/NavbarMenuItem.tsx +9 -0
- package/src/components/Navbar/NavbarMenuItemAdornment.tsx +65 -0
- package/src/components/Navbar/index.ts +1 -0
- package/src/components/Pagination/Pagination.stories.tsx +132 -0
- package/src/components/Pagination/Pagination.tsx +34 -0
- package/src/components/Pagination/PaginationButton.tsx +36 -0
- package/src/components/Pagination/PaginationContent.tsx +12 -0
- package/src/components/Pagination/PaginationEllipsis.tsx +26 -0
- package/src/components/Pagination/PaginationItem.tsx +9 -0
- package/src/components/Pagination/PaginationNext.tsx +19 -0
- package/src/components/Pagination/PaginationPrevious.tsx +11 -0
- package/src/components/Pagination/index.ts +1 -0
- package/src/components/PanelWithDetails.stories.tsx +28 -0
- package/src/components/PanelWithDetails.tsx +66 -0
- package/src/components/Popconfirm/Popconfirm.stories.tsx +365 -0
- package/src/components/Popconfirm/Popconfirm.tsx +82 -0
- package/src/components/Popconfirm/PopconfirmBody.tsx +5 -0
- package/src/components/Popconfirm/PopconfirmCancel.tsx +45 -0
- package/src/components/Popconfirm/PopconfirmConfirm.tsx +57 -0
- package/src/components/Popconfirm/PopconfirmContent.tsx +33 -0
- package/src/components/Popconfirm/PopconfirmFooter.tsx +9 -0
- package/src/components/Popconfirm/PopconfirmTrigger.tsx +22 -0
- package/src/components/Popconfirm/context.ts +19 -0
- package/src/components/Popconfirm/index.ts +1 -0
- package/src/components/Popover/Popover.stories.tsx +85 -0
- package/src/components/Popover/Popover.tsx +15 -0
- package/src/components/Popover/PopoverContent.tsx +99 -0
- package/src/components/Popover/index.ts +1 -0
- package/src/components/Progress/Progress.stories.tsx +67 -0
- package/src/components/Progress/Progress.tsx +45 -0
- package/src/components/Progress/index.ts +1 -0
- package/src/components/RadioGroup/Radio.tsx +67 -0
- package/src/components/RadioGroup/RadioGroup.stories.tsx +300 -0
- package/src/components/RadioGroup/RadioGroup.tsx +64 -0
- package/src/components/RadioGroup/RadioGroupItem.tsx +60 -0
- package/src/components/RadioGroup/RadioGroupItemButton.tsx +79 -0
- package/src/components/RadioGroup/RadioGroupSeparator.tsx +12 -0
- package/src/components/RadioGroup/context.ts +13 -0
- package/src/components/RadioGroup/index.ts +1 -0
- package/src/components/Resizable/Resizable.stories.tsx +50 -0
- package/src/components/Resizable/ResizableHandle.tsx +50 -0
- package/src/components/Resizable/ResizablePanel.tsx +12 -0
- package/src/components/Resizable/ResizablePanelGroup.tsx +19 -0
- package/src/components/Resizable/index.ts +3 -0
- package/src/components/ScrollArea/ScrollArea.stories.tsx +43 -0
- package/src/components/ScrollArea/ScrollArea.tsx +50 -0
- package/src/components/ScrollArea/ScrollBar.tsx +32 -0
- package/src/components/ScrollArea/index.ts +2 -0
- package/src/components/Search/ClearButton.tsx +42 -0
- package/src/components/Search/Search.stories.tsx +77 -0
- package/src/components/Search/Search.test.tsx +224 -0
- package/src/components/Search/Search.tsx +139 -0
- package/src/components/Search/SearchForm.tsx +37 -0
- package/src/components/Search/index.ts +2 -0
- package/src/components/Search/styles.ts +88 -0
- package/src/components/Search/utils.ts +11 -0
- package/src/components/Select/Select.stories.tsx +109 -0
- package/src/components/Select/Select.tsx +130 -0
- package/src/components/Select/SelectContent.tsx +101 -0
- package/src/components/Select/SelectGroup.tsx +10 -0
- package/src/components/Select/SelectItem.tsx +71 -0
- package/src/components/Select/SelectLabel.tsx +32 -0
- package/src/components/Select/SelectRoot.tsx +6 -0
- package/src/components/Select/SelectSeparator.tsx +13 -0
- package/src/components/Select/SelectTrigger.tsx +161 -0
- package/src/components/Select/index.ts +1 -0
- package/src/components/Separator/Separator.stories.tsx +41 -0
- package/src/components/Separator/Separator.tsx +84 -0
- package/src/components/Separator/index.ts +1 -0
- package/src/components/Sheet/Sheet.stories.tsx +63 -0
- package/src/components/Sheet/Sheet.tsx +21 -0
- package/src/components/Sheet/SheetBody.tsx +12 -0
- package/src/components/Sheet/SheetContent.tsx +131 -0
- package/src/components/Sheet/SheetFooter.tsx +9 -0
- package/src/components/Sheet/SheetHeader.tsx +39 -0
- package/src/components/Sheet/SheetOverlay.tsx +11 -0
- package/src/components/Sheet/SheetTitle.tsx +12 -0
- package/src/components/Sheet/index.ts +1 -0
- package/src/components/Sidebar/Sidebar.stories.tsx +812 -0
- package/src/components/Sidebar/Sidebar.tsx +225 -0
- package/src/components/Sidebar/SidebarContent.tsx +61 -0
- package/src/components/Sidebar/SidebarFillTrigger.tsx +25 -0
- package/src/components/Sidebar/SidebarFooter.tsx +13 -0
- package/src/components/Sidebar/SidebarGroup/SidebarGroup.tsx +23 -0
- package/src/components/Sidebar/SidebarGroup/SidebarGroupAction.tsx +49 -0
- package/src/components/Sidebar/SidebarGroup/SidebarGroupContent.tsx +20 -0
- package/src/components/Sidebar/SidebarGroup/SidebarGroupLabel.tsx +76 -0
- package/src/components/Sidebar/SidebarGroup/index.ts +4 -0
- package/src/components/Sidebar/SidebarHeader.tsx +20 -0
- package/src/components/Sidebar/SidebarInstanceContext.ts +18 -0
- package/src/components/Sidebar/SidebarMenu/SidebarMenu.tsx +28 -0
- package/src/components/Sidebar/SidebarMenu/SidebarMenuAction.tsx +69 -0
- package/src/components/Sidebar/SidebarMenu/SidebarMenuBadge.tsx +56 -0
- package/src/components/Sidebar/SidebarMenu/SidebarMenuButton.tsx +108 -0
- package/src/components/Sidebar/SidebarMenu/SidebarMenuCard.tsx +107 -0
- package/src/components/Sidebar/SidebarMenu/SidebarMenuIcon.tsx +30 -0
- package/src/components/Sidebar/SidebarMenu/SidebarMenuItem.tsx +9 -0
- package/src/components/Sidebar/SidebarMenu/SidebarMenuSub.tsx +143 -0
- package/src/components/Sidebar/SidebarMenu/SidebarMenuSubItem.tsx +106 -0
- package/src/components/Sidebar/SidebarMenu/SidebarSearchInput.tsx +90 -0
- package/src/components/Sidebar/SidebarMenu/index.ts +10 -0
- package/src/components/Sidebar/SidebarProvider/SidebarProvider.tsx +171 -0
- package/src/components/Sidebar/SidebarProvider/context.ts +35 -0
- package/src/components/Sidebar/SidebarProvider/index.ts +2 -0
- package/src/components/Sidebar/SidebarProvider/useHoverTracking.test.ts +199 -0
- package/src/components/Sidebar/SidebarProvider/useHoverTracking.ts +72 -0
- package/src/components/Sidebar/SidebarProvider/useSidebarState.ts +50 -0
- package/src/components/Sidebar/SidebarProvider/useTransitionPresence.test.ts +179 -0
- package/src/components/Sidebar/SidebarProvider/useTransitionPresence.ts +53 -0
- package/src/components/Sidebar/SidebarResizeHandle.tsx +28 -0
- package/src/components/Sidebar/SidebarSeparator.tsx +15 -0
- package/src/components/Sidebar/SidebarTrigger.tsx +40 -0
- package/src/components/Sidebar/index.ts +3 -0
- package/src/components/Sidebar/types.ts +6 -0
- package/src/components/Sidebar/useResizeSidebar.ts +112 -0
- package/src/components/Sidebar/utils.test.ts +178 -0
- package/src/components/Sidebar/utils.ts +70 -0
- package/src/components/Skeleton/Skeleton.stories.tsx +54 -0
- package/src/components/Skeleton/Skeleton.tsx +54 -0
- package/src/components/Skeleton/SkeletonList.stories.tsx +11 -0
- package/src/components/Skeleton/SkeletonList.tsx +65 -0
- package/src/components/Slider/Slider.stories.tsx +99 -0
- package/src/components/Slider/Slider.tsx +85 -0
- package/src/components/Slider/SliderThumb.tsx +57 -0
- package/src/components/Slider/SliderTrack.tsx +49 -0
- package/src/components/Slider/index.ts +1 -0
- package/src/components/Slider/useInteracting.test.ts +159 -0
- package/src/components/Slider/useInteracting.ts +64 -0
- package/src/components/Switch/Switch.stories.tsx +177 -0
- package/src/components/Switch/Switch.tsx +58 -0
- package/src/components/Switch/index.ts +1 -0
- package/src/components/Switch/styles.ts +173 -0
- package/src/components/Table/Table.stories.tsx +106 -0
- package/src/components/Table/Table.tsx +51 -0
- package/src/components/Table/TableBody.tsx +22 -0
- package/src/components/Table/TableCell.tsx +7 -0
- package/src/components/Table/TableFooter.tsx +15 -0
- package/src/components/Table/TableHead.tsx +15 -0
- package/src/components/Table/TableHeader.tsx +20 -0
- package/src/components/Table/TableRow.tsx +11 -0
- package/src/components/Table/index.ts +1 -0
- package/src/components/Tabs.stories.tsx +123 -0
- package/src/components/Tabs.tsx +111 -0
- package/src/components/ThemeProvider/AIGradientSvg.tsx +18 -0
- package/src/components/ThemeProvider/ThemeProvider.tsx +25 -0
- package/src/components/ThemeProvider/index.ts +1 -0
- package/src/components/TimePicker/TimePicker.tsx +95 -0
- package/src/components/TimePicker/TimePickerButton.tsx +39 -0
- package/src/components/TimePicker/index.ts +1 -0
- package/src/components/TimePicker/utils.ts +31 -0
- package/src/components/Timeline/Timeline.stories.tsx +246 -0
- package/src/components/Timeline/Timeline.tsx +35 -0
- package/src/components/Timeline/TimelineConnector.tsx +154 -0
- package/src/components/Timeline/TimelineContent.tsx +18 -0
- package/src/components/Timeline/TimelineItem.tsx +14 -0
- package/src/components/Timeline/index.ts +1 -0
- package/src/components/Timeline/useLastLineHeight.ts +36 -0
- package/src/components/Toast/Toast.stories.tsx +178 -0
- package/src/components/Toast/ToastAction.tsx +40 -0
- package/src/components/Toast/ToastDescription.tsx +28 -0
- package/src/components/Toast/ToastDismiss.tsx +36 -0
- package/src/components/Toast/ToastDuration.tsx +43 -0
- package/src/components/Toast/ToastRoot.tsx +130 -0
- package/src/components/Toast/ToastTitle.tsx +33 -0
- package/src/components/Toast/Toaster.tsx +25 -0
- package/src/components/Toast/index.ts +3 -0
- package/src/components/Toast/toast.tsx +94 -0
- package/src/components/Toast/useNotification.tsx +33 -0
- package/src/components/Toggle/Toggle.stories.tsx +67 -0
- package/src/components/Toggle/Toggle.tsx +197 -0
- package/src/components/Toggle/index.ts +1 -0
- package/src/components/Tooltip/Tooltip.stories.tsx +82 -0
- package/src/components/Tooltip/Tooltip.tsx +87 -0
- package/src/components/Tooltip/TooltipContent.tsx +90 -0
- package/src/components/Tooltip/TooltipRoot.tsx +12 -0
- package/src/components/Tooltip/TooltipTrigger.tsx +42 -0
- package/src/components/Tooltip/index.ts +1 -0
- package/src/components/Truncated.stories.tsx +72 -0
- package/src/components/Truncated.tsx +78 -0
- package/src/components/ZoomableSvg/ZoomableSvg.stories.tsx +53 -0
- package/src/components/ZoomableSvg/ZoomableSvg.tsx +198 -0
- package/src/components/ZoomableSvg/index.ts +1 -0
- package/src/constants/keyCodes.ts +5 -0
- package/src/docs/Colors.mdx +19 -0
- package/src/docs/Spacing.mdx +35 -0
- package/src/docs/Typography.mdx +63 -0
- package/src/docs/components/Typeset.tsx +35 -0
- package/src/hooks/useAutosizeInput.stories.tsx +142 -0
- package/src/hooks/useAutosizeInput.test.tsx +77 -0
- package/src/hooks/useAutosizeInput.tsx +107 -0
- package/src/hooks/useElement.ts +16 -0
- package/src/hooks/useScrollbarPosition.ts +68 -0
- package/src/icon-names.ts +20 -0
- package/src/index.ts +87 -0
- package/src/styles.css +212 -0
- package/src/utils/classNames.test.ts +16 -0
- package/src/utils/classNames.ts +27 -0
- package/src/utils/copyToClipboard.ts +3 -0
- package/src/utils/createChangeInputEvent.ts +28 -0
- package/src/utils/createPrefixedString.ts +2 -0
- package/src/utils/debounce.test.ts +63 -0
- package/src/utils/debounce.ts +17 -0
- package/src/utils/decorators.tsx +16 -0
- package/src/utils/escapeStringRegexp.ts +4 -0
- package/src/utils/index.ts +11 -0
- package/src/utils/isMac.ts +26 -0
- package/src/utils/mergeRefs.ts +23 -0
- package/src/utils/noop.ts +1 -0
- package/src/utils/useSHA256.ts +21 -0
- package/src/vite-env.d.ts +1 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import { CodeNode } from '@lexical/code';
|
|
4
|
+
import { LinkNode } from '@lexical/link';
|
|
5
|
+
import { ListItemNode, ListNode } from '@lexical/list';
|
|
6
|
+
import { $convertFromMarkdownString } from '@lexical/markdown';
|
|
7
|
+
import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin';
|
|
8
|
+
import { CheckListPlugin } from '@lexical/react/LexicalCheckListPlugin';
|
|
9
|
+
import { ClickableLinkPlugin } from '@lexical/react/LexicalClickableLinkPlugin';
|
|
10
|
+
import type { InitialConfigType } from '@lexical/react/LexicalComposer';
|
|
11
|
+
import { LexicalComposer } from '@lexical/react/LexicalComposer';
|
|
12
|
+
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
13
|
+
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
|
|
14
|
+
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
|
|
15
|
+
import { HorizontalRuleNode } from '@lexical/react/LexicalHorizontalRuleNode';
|
|
16
|
+
import { HorizontalRulePlugin } from '@lexical/react/LexicalHorizontalRulePlugin';
|
|
17
|
+
import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
|
|
18
|
+
import { ListPlugin } from '@lexical/react/LexicalListPlugin';
|
|
19
|
+
import { MarkdownShortcutPlugin } from '@lexical/react/LexicalMarkdownShortcutPlugin';
|
|
20
|
+
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
21
|
+
import { TabIndentationPlugin } from '@lexical/react/LexicalTabIndentationPlugin';
|
|
22
|
+
import { HeadingNode, QuoteNode } from '@lexical/rich-text';
|
|
23
|
+
|
|
24
|
+
import { cn } from '../../utils';
|
|
25
|
+
|
|
26
|
+
import { ImageNode } from './nodes/ImageNode';
|
|
27
|
+
import { MermaidNode } from './nodes/MermaidNode';
|
|
28
|
+
import { ImagePastePlugin } from './plugins/ImagePastePlugin';
|
|
29
|
+
import { KeyboardPlugin } from './plugins/KeyboardPlugin';
|
|
30
|
+
import { MarkdownSyncPlugin } from './plugins/MarkdownSyncPlugin';
|
|
31
|
+
import { ToolbarPlugin } from './plugins/ToolbarPlugin';
|
|
32
|
+
import { ImageRendererProvider } from './context';
|
|
33
|
+
import { editorTheme } from './theme';
|
|
34
|
+
import { CUSTOM_TRANSFORMERS, preprocessMarkdown } from './transformers';
|
|
35
|
+
|
|
36
|
+
export type MarkdownEditorProps = {
|
|
37
|
+
/** Markdown string (controlled) */
|
|
38
|
+
value: string;
|
|
39
|
+
onChange?: (markdown: string) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Renders content but never accepts input. Use for permanent view-only contexts
|
|
42
|
+
* (e.g. a current user lacks edit permission). Toolbar is hidden.
|
|
43
|
+
*/
|
|
44
|
+
readOnly?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Temporarily blocks input but signals intent to re-enable
|
|
47
|
+
* (e.g. while a save is in flight). Functionally identical to `readOnly` today.
|
|
48
|
+
*/
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
placeholder?: string;
|
|
51
|
+
autoFocus?: boolean;
|
|
52
|
+
/** Invoked on Cmd/Ctrl+Enter — typically used to commit a form. */
|
|
53
|
+
onSave?: () => void;
|
|
54
|
+
/** Invoked on Escape — typically used to discard or close the editor. */
|
|
55
|
+
onCancel?: () => void;
|
|
56
|
+
/**
|
|
57
|
+
* Async image upload. Resolved URL is embedded as the image src
|
|
58
|
+
* (`` in the underlying markdown).
|
|
59
|
+
*/
|
|
60
|
+
onImageUpload?: (file: File) => Promise<{ url: string }>;
|
|
61
|
+
className?: string;
|
|
62
|
+
imageRenderer?: (props: { src: string; alt: string }) => ReactNode;
|
|
63
|
+
showToolbar?: boolean;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const EDITOR_NODES = [
|
|
67
|
+
ImageNode,
|
|
68
|
+
MermaidNode,
|
|
69
|
+
HeadingNode,
|
|
70
|
+
QuoteNode,
|
|
71
|
+
ListNode,
|
|
72
|
+
ListItemNode,
|
|
73
|
+
CodeNode,
|
|
74
|
+
LinkNode,
|
|
75
|
+
HorizontalRuleNode,
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
export const MarkdownEditor = ({
|
|
79
|
+
value,
|
|
80
|
+
onChange,
|
|
81
|
+
readOnly = false,
|
|
82
|
+
placeholder,
|
|
83
|
+
autoFocus = false,
|
|
84
|
+
disabled = false,
|
|
85
|
+
onSave,
|
|
86
|
+
onCancel,
|
|
87
|
+
onImageUpload,
|
|
88
|
+
className,
|
|
89
|
+
imageRenderer,
|
|
90
|
+
showToolbar = false,
|
|
91
|
+
}: MarkdownEditorProps) => {
|
|
92
|
+
const editable = !readOnly && !disabled;
|
|
93
|
+
|
|
94
|
+
// Lexical reads editorState only on first render; later prop changes are applied by MarkdownSyncPlugin.
|
|
95
|
+
const [initialConfig] = useState<InitialConfigType>(() => ({
|
|
96
|
+
namespace: 'MarkdownEditor',
|
|
97
|
+
theme: editorTheme,
|
|
98
|
+
nodes: EDITOR_NODES,
|
|
99
|
+
onError: (error: Error) => {
|
|
100
|
+
console.error('[MarkdownEditor] uncaught editor error', error);
|
|
101
|
+
},
|
|
102
|
+
editable,
|
|
103
|
+
editorState: () => {
|
|
104
|
+
$convertFromMarkdownString(preprocessMarkdown(value), CUSTOM_TRANSFORMERS);
|
|
105
|
+
},
|
|
106
|
+
}));
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<LexicalComposer initialConfig={initialConfig}>
|
|
110
|
+
<ImageRendererProvider value={imageRenderer ?? null}>
|
|
111
|
+
<div className={cn('tw-prose', className)}>
|
|
112
|
+
{showToolbar && editable && <ToolbarPlugin />}
|
|
113
|
+
<div
|
|
114
|
+
className={cn(
|
|
115
|
+
'tw-relative tw-rounded-md tw-p-2 tw-transition-colors',
|
|
116
|
+
editable &&
|
|
117
|
+
'tw-cursor-text hover:tw-bg-neutral-50 focus-within:tw-ring-2 focus-within:tw-ring-secondary-500/40',
|
|
118
|
+
)}
|
|
119
|
+
>
|
|
120
|
+
<RichTextPlugin
|
|
121
|
+
contentEditable={
|
|
122
|
+
<ContentEditable
|
|
123
|
+
className="tw-min-h-[100px] tw-outline-none"
|
|
124
|
+
aria-placeholder={placeholder ?? ''}
|
|
125
|
+
placeholder={
|
|
126
|
+
placeholder ? (
|
|
127
|
+
<div className="tw-pointer-events-none tw-absolute tw-left-2 tw-top-[calc(0.5rem+0.35em)] tw-select-none tw-text-neutral-400">
|
|
128
|
+
{placeholder}
|
|
129
|
+
</div>
|
|
130
|
+
) : (
|
|
131
|
+
<div />
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
/>
|
|
135
|
+
}
|
|
136
|
+
ErrorBoundary={LexicalErrorBoundary}
|
|
137
|
+
/>
|
|
138
|
+
</div>
|
|
139
|
+
<HistoryPlugin />
|
|
140
|
+
<LinkPlugin />
|
|
141
|
+
<ClickableLinkPlugin newTab />
|
|
142
|
+
<ListPlugin />
|
|
143
|
+
<CheckListPlugin />
|
|
144
|
+
<HorizontalRulePlugin />
|
|
145
|
+
<TabIndentationPlugin />
|
|
146
|
+
<MarkdownShortcutPlugin transformers={CUSTOM_TRANSFORMERS} />
|
|
147
|
+
<MarkdownSyncPlugin value={value} editable={editable} onChange={onChange} />
|
|
148
|
+
<ImagePastePlugin onImageUpload={onImageUpload} />
|
|
149
|
+
<KeyboardPlugin onSave={onSave} onCancel={onCancel} />
|
|
150
|
+
{autoFocus && <AutoFocusPlugin />}
|
|
151
|
+
</div>
|
|
152
|
+
</ImageRendererProvider>
|
|
153
|
+
</LexicalComposer>
|
|
154
|
+
);
|
|
155
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createContext, use } from 'react';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
type ImageRenderer = (props: { src: string; alt: string }) => ReactNode;
|
|
5
|
+
|
|
6
|
+
const ImageRendererContext = createContext<ImageRenderer | null>(null);
|
|
7
|
+
|
|
8
|
+
export const ImageRendererProvider = ImageRendererContext;
|
|
9
|
+
|
|
10
|
+
export const useImageRenderer = (): ImageRenderer | null => use(ImageRendererContext);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MarkdownEditor, type MarkdownEditorProps } from './MarkdownEditor';
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/* eslint-disable react/only-export-components -- Lexical convention: $create/$is helpers co-locate with node */
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import type {
|
|
4
|
+
DOMConversionMap,
|
|
5
|
+
DOMExportOutput,
|
|
6
|
+
EditorConfig,
|
|
7
|
+
LexicalNode,
|
|
8
|
+
NodeKey,
|
|
9
|
+
SerializedLexicalNode,
|
|
10
|
+
Spread,
|
|
11
|
+
} from 'lexical';
|
|
12
|
+
import { DecoratorNode } from 'lexical';
|
|
13
|
+
|
|
14
|
+
import { ImageNodeComponent } from './ImageNodeComponent';
|
|
15
|
+
|
|
16
|
+
type SerializedImageNode = Spread<{ src: string; altText: string }, SerializedLexicalNode>;
|
|
17
|
+
|
|
18
|
+
export class ImageNode extends DecoratorNode<ReactNode> {
|
|
19
|
+
__src: string;
|
|
20
|
+
__altText: string;
|
|
21
|
+
|
|
22
|
+
static getType(): string {
|
|
23
|
+
return 'image';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static clone(node: ImageNode): ImageNode {
|
|
27
|
+
return new ImageNode(node.__src, node.__altText, node.__key);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
constructor(src: string, altText: string, key?: NodeKey) {
|
|
31
|
+
super(key);
|
|
32
|
+
this.__src = src;
|
|
33
|
+
this.__altText = altText;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getSrc(): string {
|
|
37
|
+
return this.__src;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getAlt(): string {
|
|
41
|
+
return this.__altText;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setSrc(src: string): void {
|
|
45
|
+
const writable = this.getWritable();
|
|
46
|
+
writable.__src = src;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
setAlt(altText: string): void {
|
|
50
|
+
const writable = this.getWritable();
|
|
51
|
+
writable.__altText = altText;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
createDOM(config: EditorConfig): HTMLElement {
|
|
55
|
+
const span = document.createElement('span');
|
|
56
|
+
const className = config.theme.image;
|
|
57
|
+
if (typeof className === 'string') {
|
|
58
|
+
span.className = className;
|
|
59
|
+
}
|
|
60
|
+
return span;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
updateDOM(): boolean {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
decorate(): ReactNode {
|
|
68
|
+
return <ImageNodeComponent src={this.__src} alt={this.__altText} />;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
isInline(): boolean {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static importJSON(serializedNode: SerializedImageNode): ImageNode {
|
|
76
|
+
return $createImageNode(serializedNode.src, serializedNode.altText);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
exportJSON(): SerializedImageNode {
|
|
80
|
+
return {
|
|
81
|
+
type: 'image',
|
|
82
|
+
version: 1,
|
|
83
|
+
src: this.__src,
|
|
84
|
+
altText: this.__altText,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
exportDOM(): DOMExportOutput {
|
|
89
|
+
const element = document.createElement('img');
|
|
90
|
+
element.setAttribute('src', this.__src);
|
|
91
|
+
element.setAttribute('alt', this.__altText);
|
|
92
|
+
return { element };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static importDOM(): DOMConversionMap | null {
|
|
96
|
+
return {
|
|
97
|
+
img: () => ({
|
|
98
|
+
conversion: (domNode: HTMLElement) => {
|
|
99
|
+
const src = domNode.getAttribute('src') || '';
|
|
100
|
+
const alt = domNode.getAttribute('alt') || '';
|
|
101
|
+
return { node: $createImageNode(src, alt) };
|
|
102
|
+
},
|
|
103
|
+
priority: 0,
|
|
104
|
+
}),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const $createImageNode = (src: string, altText: string): ImageNode => {
|
|
110
|
+
return new ImageNode(src, altText);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const $isImageNode = (node: LexicalNode | null | undefined): node is ImageNode => {
|
|
114
|
+
return node instanceof ImageNode;
|
|
115
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useImageRenderer } from '../context';
|
|
2
|
+
|
|
3
|
+
const isPlaceholder = (src: string) => src.startsWith('upload-placeholder-');
|
|
4
|
+
|
|
5
|
+
export const ImageNodeComponent = ({ src, alt }: { src: string; alt: string }) => {
|
|
6
|
+
const renderer = useImageRenderer();
|
|
7
|
+
|
|
8
|
+
if (isPlaceholder(src)) {
|
|
9
|
+
return (
|
|
10
|
+
<span className="tw-inline-flex tw-items-center tw-gap-1 tw-rounded tw-bg-neutral-100 tw-px-2 tw-py-1 tw-text-xs tw-text-neutral-400">
|
|
11
|
+
Uploading image…
|
|
12
|
+
</span>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (renderer) return <>{renderer({ src, alt })}</>;
|
|
17
|
+
return <img src={src} alt={alt} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* eslint-disable react/only-export-components -- Lexical convention: $create/$is helpers co-locate with node */
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import type { LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
|
|
4
|
+
import { DecoratorNode } from 'lexical';
|
|
5
|
+
|
|
6
|
+
import { MermaidNodeComponent } from './MermaidNodeComponent';
|
|
7
|
+
|
|
8
|
+
type SerializedMermaidNode = Spread<{ code: string }, SerializedLexicalNode>;
|
|
9
|
+
|
|
10
|
+
export class MermaidNode extends DecoratorNode<ReactNode> {
|
|
11
|
+
__code: string;
|
|
12
|
+
|
|
13
|
+
static getType(): string {
|
|
14
|
+
return 'mermaid';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static clone(node: MermaidNode): MermaidNode {
|
|
18
|
+
return new MermaidNode(node.__code, node.__key);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(code: string, key?: NodeKey) {
|
|
22
|
+
super(key);
|
|
23
|
+
this.__code = code;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getCode(): string {
|
|
27
|
+
return this.__code;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setCode(code: string): void {
|
|
31
|
+
const writable = this.getWritable();
|
|
32
|
+
writable.__code = code;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
createDOM(): HTMLElement {
|
|
36
|
+
const div = document.createElement('div');
|
|
37
|
+
div.setAttribute('data-lexical-mermaid', 'true');
|
|
38
|
+
return div;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
updateDOM(): boolean {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
decorate(): ReactNode {
|
|
46
|
+
return <MermaidNodeComponent code={this.__code} />;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
isInline(): boolean {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static importJSON(serializedNode: SerializedMermaidNode): MermaidNode {
|
|
54
|
+
return $createMermaidNode(serializedNode.code);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
exportJSON(): SerializedMermaidNode {
|
|
58
|
+
return {
|
|
59
|
+
type: 'mermaid',
|
|
60
|
+
version: 1,
|
|
61
|
+
code: this.__code,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const $createMermaidNode = (code: string): MermaidNode => {
|
|
67
|
+
return new MermaidNode(code);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const $isMermaidNode = (node: LexicalNode | null | undefined): node is MermaidNode => {
|
|
71
|
+
return node instanceof MermaidNode;
|
|
72
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { lazy, Suspense } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Skeleton } from '../../../components/Skeleton/Skeleton';
|
|
4
|
+
|
|
5
|
+
const MermaidDiagram = lazy(() =>
|
|
6
|
+
import('../../../blocks/MermaidDiagram/MermaidDiagram').then(
|
|
7
|
+
(m) => ({ default: m.MermaidDiagram }),
|
|
8
|
+
(error: unknown) => {
|
|
9
|
+
// Falling back to raw code on chunk-load failure (typically a stale tab after deploy).
|
|
10
|
+
// Logging so we don't silently swap implementations.
|
|
11
|
+
console.error('[MarkdownEditor] failed to load MermaidDiagram chunk', error);
|
|
12
|
+
return {
|
|
13
|
+
default: ({ code }: { code: string }) => (
|
|
14
|
+
<pre>
|
|
15
|
+
<code>{code}</code>
|
|
16
|
+
</pre>
|
|
17
|
+
),
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export const MermaidNodeComponent = ({ code }: { code: string }) => {
|
|
24
|
+
return (
|
|
25
|
+
<Suspense
|
|
26
|
+
fallback={
|
|
27
|
+
<div className="tw-my-3 tw-overflow-hidden tw-rounded-card tw-border tw-border-neutral-150 tw-bg-neutral-50 tw-p-6">
|
|
28
|
+
<Skeleton className="tw-h-40" />
|
|
29
|
+
</div>
|
|
30
|
+
}
|
|
31
|
+
>
|
|
32
|
+
<MermaidDiagram code={code} />
|
|
33
|
+
</Suspense>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import type { NodeKey } from 'lexical';
|
|
4
|
+
import {
|
|
5
|
+
$getNodeByKey,
|
|
6
|
+
$insertNodes,
|
|
7
|
+
COMMAND_PRIORITY_CRITICAL,
|
|
8
|
+
DROP_COMMAND,
|
|
9
|
+
PASTE_COMMAND,
|
|
10
|
+
} from 'lexical';
|
|
11
|
+
|
|
12
|
+
import { toast } from '../../Toast/toast';
|
|
13
|
+
import { $createImageNode, $isImageNode } from '../nodes/ImageNode';
|
|
14
|
+
|
|
15
|
+
const ACCEPTED_IMAGE_TYPES = [
|
|
16
|
+
'image/png',
|
|
17
|
+
'image/jpeg',
|
|
18
|
+
'image/gif',
|
|
19
|
+
'image/webp',
|
|
20
|
+
'image/svg+xml',
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const MAX_IMAGE_SIZE = 10 * 1024 * 1024; // 10 MB
|
|
24
|
+
|
|
25
|
+
const PLACEHOLDER_PREFIX = 'upload-placeholder-';
|
|
26
|
+
|
|
27
|
+
const generatePlaceholderId = (): string => {
|
|
28
|
+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
|
29
|
+
return crypto.randomUUID();
|
|
30
|
+
}
|
|
31
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const isAcceptedImageType = (type: string) => ACCEPTED_IMAGE_TYPES.includes(type);
|
|
35
|
+
|
|
36
|
+
const getImageFilesFromDataTransfer = (dataTransfer: DataTransfer | null): File[] => {
|
|
37
|
+
if (!dataTransfer) return [];
|
|
38
|
+
|
|
39
|
+
if (dataTransfer.items.length > 0) {
|
|
40
|
+
const files: File[] = [];
|
|
41
|
+
for (const item of dataTransfer.items) {
|
|
42
|
+
if (item.kind === 'file' && isAcceptedImageType(item.type)) {
|
|
43
|
+
const file = item.getAsFile();
|
|
44
|
+
if (file) files.push(file);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (files.length > 0) return files;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return Array.from(dataTransfer.files).filter((file) => isAcceptedImageType(file.type));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const escapeMarkdownAlt = (text: string) => text.replace(/[[\]()]/g, '');
|
|
54
|
+
|
|
55
|
+
type ImagePastePluginProps = {
|
|
56
|
+
onImageUpload?: (file: File) => Promise<{ url: string }>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const ImagePastePlugin = ({ onImageUpload }: ImagePastePluginProps) => {
|
|
60
|
+
const [editor] = useLexicalComposerContext();
|
|
61
|
+
const onImageUploadRef = useRef(onImageUpload);
|
|
62
|
+
onImageUploadRef.current = onImageUpload;
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const uploadFile = (file: File) => {
|
|
66
|
+
const upload = onImageUploadRef.current;
|
|
67
|
+
if (!upload) return;
|
|
68
|
+
|
|
69
|
+
if (file.size > MAX_IMAGE_SIZE) {
|
|
70
|
+
toast.error(`Image "${file.name}" is too large. Maximum size is 10 MB.`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Insert placeholder and start upload outside the command handler
|
|
75
|
+
// to avoid nested editor.update() batching issues
|
|
76
|
+
let nodeKey: NodeKey | null = null;
|
|
77
|
+
|
|
78
|
+
editor.update(() => {
|
|
79
|
+
const placeholderNode = $createImageNode(
|
|
80
|
+
`${PLACEHOLDER_PREFIX}${generatePlaceholderId()}`,
|
|
81
|
+
'Uploading image\u2026',
|
|
82
|
+
);
|
|
83
|
+
$insertNodes([placeholderNode]);
|
|
84
|
+
nodeKey = placeholderNode.getKey();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (!nodeKey) return;
|
|
88
|
+
const capturedKey: NodeKey = nodeKey;
|
|
89
|
+
|
|
90
|
+
upload(file)
|
|
91
|
+
.then(({ url }) => {
|
|
92
|
+
editor.update(() => {
|
|
93
|
+
const node = $getNodeByKey(capturedKey);
|
|
94
|
+
if ($isImageNode(node)) {
|
|
95
|
+
const altText = escapeMarkdownAlt(file.name.replace(/\.[^.]+$/, '') || 'image');
|
|
96
|
+
node.setSrc(url);
|
|
97
|
+
node.setAlt(altText);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
})
|
|
101
|
+
.catch((error: unknown) => {
|
|
102
|
+
console.error('[MarkdownEditor] image upload failed', error);
|
|
103
|
+
toast.error(`Failed to upload "${file.name}". Please try again.`);
|
|
104
|
+
editor.update(() => {
|
|
105
|
+
const node = $getNodeByKey(capturedKey);
|
|
106
|
+
if (node) node.remove();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const removePaste = editor.registerCommand(
|
|
112
|
+
PASTE_COMMAND,
|
|
113
|
+
(event) => {
|
|
114
|
+
if (!onImageUploadRef.current) return false;
|
|
115
|
+
if (!(event instanceof ClipboardEvent)) return false;
|
|
116
|
+
const files = getImageFilesFromDataTransfer(event.clipboardData);
|
|
117
|
+
if (files.length === 0) return false;
|
|
118
|
+
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
// Defer upload to next microtask to escape the command handler's update context
|
|
121
|
+
Promise.resolve().then(() => files.forEach(uploadFile));
|
|
122
|
+
return true;
|
|
123
|
+
},
|
|
124
|
+
COMMAND_PRIORITY_CRITICAL,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const removeDrop = editor.registerCommand(
|
|
128
|
+
DROP_COMMAND,
|
|
129
|
+
(event: DragEvent) => {
|
|
130
|
+
if (!onImageUploadRef.current) return false;
|
|
131
|
+
const files = getImageFilesFromDataTransfer(event.dataTransfer);
|
|
132
|
+
if (files.length === 0) return false;
|
|
133
|
+
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
// Defer upload to next microtask to escape the command handler's update context
|
|
136
|
+
Promise.resolve().then(() => files.forEach(uploadFile));
|
|
137
|
+
return true;
|
|
138
|
+
},
|
|
139
|
+
COMMAND_PRIORITY_CRITICAL,
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
return () => {
|
|
143
|
+
removePaste();
|
|
144
|
+
removeDrop();
|
|
145
|
+
};
|
|
146
|
+
}, [editor]);
|
|
147
|
+
|
|
148
|
+
return null;
|
|
149
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { COMMAND_PRIORITY_HIGH, KEY_DOWN_COMMAND } from 'lexical';
|
|
4
|
+
|
|
5
|
+
type KeyboardPluginProps = {
|
|
6
|
+
onSave?: () => void;
|
|
7
|
+
onCancel?: () => void;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const KeyboardPlugin = ({ onSave, onCancel }: KeyboardPluginProps) => {
|
|
11
|
+
const [editor] = useLexicalComposerContext();
|
|
12
|
+
const onSaveRef = useRef(onSave);
|
|
13
|
+
onSaveRef.current = onSave;
|
|
14
|
+
const onCancelRef = useRef(onCancel);
|
|
15
|
+
onCancelRef.current = onCancel;
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
return editor.registerCommand(
|
|
19
|
+
KEY_DOWN_COMMAND,
|
|
20
|
+
(event: KeyboardEvent) => {
|
|
21
|
+
if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
onSaveRef.current?.();
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (event.key === 'Escape') {
|
|
27
|
+
onCancelRef.current?.();
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
},
|
|
32
|
+
COMMAND_PRIORITY_HIGH,
|
|
33
|
+
);
|
|
34
|
+
}, [editor]);
|
|
35
|
+
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { $convertFromMarkdownString, $convertToMarkdownString } from '@lexical/markdown';
|
|
3
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
4
|
+
|
|
5
|
+
import { CUSTOM_TRANSFORMERS, postprocessMarkdown, preprocessMarkdown } from '../transformers';
|
|
6
|
+
|
|
7
|
+
const IMPORT_TAG = 'markdown-import';
|
|
8
|
+
|
|
9
|
+
type MarkdownSyncPluginProps = {
|
|
10
|
+
value: string;
|
|
11
|
+
editable: boolean;
|
|
12
|
+
onChange?: (markdown: string) => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const MarkdownSyncPlugin = ({ value, editable, onChange }: MarkdownSyncPluginProps) => {
|
|
16
|
+
const [editor] = useLexicalComposerContext();
|
|
17
|
+
const lastExportedRef = useRef(value);
|
|
18
|
+
const onChangeRef = useRef(onChange);
|
|
19
|
+
onChangeRef.current = onChange;
|
|
20
|
+
|
|
21
|
+
// Sync editable state — only when it actually changes
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
editor.setEditable(editable);
|
|
24
|
+
}, [editor, editable]);
|
|
25
|
+
|
|
26
|
+
// Import: external value -> editor state
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (value === lastExportedRef.current) return;
|
|
29
|
+
lastExportedRef.current = value;
|
|
30
|
+
|
|
31
|
+
editor.update(
|
|
32
|
+
() => {
|
|
33
|
+
$convertFromMarkdownString(preprocessMarkdown(value), CUSTOM_TRANSFORMERS);
|
|
34
|
+
},
|
|
35
|
+
{ tag: IMPORT_TAG },
|
|
36
|
+
);
|
|
37
|
+
}, [editor, value]);
|
|
38
|
+
|
|
39
|
+
// Export: editor state -> onChange (subscription)
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
return editor.registerUpdateListener(({ tags }) => {
|
|
42
|
+
if (tags.has(IMPORT_TAG)) return;
|
|
43
|
+
|
|
44
|
+
editor.getEditorState().read(() => {
|
|
45
|
+
const raw = $convertToMarkdownString(CUSTOM_TRANSFORMERS);
|
|
46
|
+
const markdown = postprocessMarkdown(raw);
|
|
47
|
+
if (markdown !== lastExportedRef.current) {
|
|
48
|
+
lastExportedRef.current = markdown;
|
|
49
|
+
onChangeRef.current?.(markdown);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}, [editor]);
|
|
54
|
+
|
|
55
|
+
return null;
|
|
56
|
+
};
|