@flowdrop/flowdrop 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/LICENSE +21 -0
- package/README.md +252 -0
- package/dist/adapters/WorkflowAdapter.d.ts +167 -0
- package/dist/adapters/WorkflowAdapter.js +368 -0
- package/dist/adapters/agentspec/AgentSpecAdapter.d.ts +96 -0
- package/dist/adapters/agentspec/AgentSpecAdapter.js +626 -0
- package/dist/adapters/agentspec/agentAdapter.d.ts +59 -0
- package/dist/adapters/agentspec/agentAdapter.js +91 -0
- package/dist/adapters/agentspec/autoLayout.d.ts +34 -0
- package/dist/adapters/agentspec/autoLayout.js +127 -0
- package/dist/adapters/agentspec/componentTypeDefaults.d.ts +73 -0
- package/dist/adapters/agentspec/componentTypeDefaults.js +238 -0
- package/dist/adapters/agentspec/defaultNodeTypes.d.ts +53 -0
- package/dist/adapters/agentspec/defaultNodeTypes.js +561 -0
- package/dist/adapters/agentspec/index.d.ts +37 -0
- package/dist/adapters/agentspec/index.js +39 -0
- package/dist/adapters/agentspec/validator.d.ts +34 -0
- package/dist/adapters/agentspec/validator.js +169 -0
- package/dist/api/enhanced-client.d.ts +183 -0
- package/dist/api/enhanced-client.js +430 -0
- package/dist/components/App.svelte +981 -0
- package/dist/components/App.svelte.d.ts +54 -0
- package/dist/components/CanvasBanner.stories.svelte +29 -0
- package/dist/components/CanvasBanner.stories.svelte.d.ts +27 -0
- package/dist/components/CanvasBanner.svelte +57 -0
- package/dist/components/CanvasBanner.svelte.d.ts +8 -0
- package/dist/components/ConfigForm.svelte +1138 -0
- package/dist/components/ConfigForm.svelte.d.ts +44 -0
- package/dist/components/ConfigModal.svelte +188 -0
- package/dist/components/ConfigModal.svelte.d.ts +13 -0
- package/dist/components/ConfigPanel.stories.svelte +47 -0
- package/dist/components/ConfigPanel.stories.svelte.d.ts +27 -0
- package/dist/components/ConfigPanel.svelte +182 -0
- package/dist/components/ConfigPanel.svelte.d.ts +32 -0
- package/dist/components/ConnectionLine.svelte +32 -0
- package/dist/components/ConnectionLine.svelte.d.ts +3 -0
- package/dist/components/EdgeRefresher.svelte +41 -0
- package/dist/components/EdgeRefresher.svelte.d.ts +9 -0
- package/dist/components/FlowDropZone.svelte +83 -0
- package/dist/components/FlowDropZone.svelte.d.ts +13 -0
- package/dist/components/LoadingSpinner.stories.svelte +30 -0
- package/dist/components/LoadingSpinner.stories.svelte.d.ts +27 -0
- package/dist/components/LoadingSpinner.svelte +36 -0
- package/dist/components/LoadingSpinner.svelte.d.ts +8 -0
- package/dist/components/Logo.stories.svelte +22 -0
- package/dist/components/Logo.stories.svelte.d.ts +27 -0
- package/dist/components/Logo.svelte +102 -0
- package/dist/components/Logo.svelte.d.ts +26 -0
- package/dist/components/LogsSidebar.svelte +563 -0
- package/dist/components/LogsSidebar.svelte.d.ts +17 -0
- package/dist/components/MarkdownDisplay.stories.svelte +36 -0
- package/dist/components/MarkdownDisplay.stories.svelte.d.ts +27 -0
- package/dist/components/MarkdownDisplay.svelte +29 -0
- package/dist/components/MarkdownDisplay.svelte.d.ts +7 -0
- package/dist/components/Navbar.stories.svelte +53 -0
- package/dist/components/Navbar.stories.svelte.d.ts +27 -0
- package/dist/components/Navbar.svelte +726 -0
- package/dist/components/Navbar.svelte.d.ts +29 -0
- package/dist/components/NodeSidebar.svelte +762 -0
- package/dist/components/NodeSidebar.svelte.d.ts +9 -0
- package/dist/components/NodeStatusOverlay.stories.svelte +85 -0
- package/dist/components/NodeStatusOverlay.stories.svelte.d.ts +27 -0
- package/dist/components/NodeStatusOverlay.svelte +327 -0
- package/dist/components/NodeStatusOverlay.svelte.d.ts +11 -0
- package/dist/components/PipelineStatus.svelte +314 -0
- package/dist/components/PipelineStatus.svelte.d.ts +20 -0
- package/dist/components/PortCoordinateTracker.svelte +58 -0
- package/dist/components/PortCoordinateTracker.svelte.d.ts +12 -0
- package/dist/components/ReadOnlyDetails.svelte +170 -0
- package/dist/components/ReadOnlyDetails.svelte.d.ts +25 -0
- package/dist/components/SchemaForm.stories.svelte +116 -0
- package/dist/components/SchemaForm.stories.svelte.d.ts +27 -0
- package/dist/components/SchemaForm.svelte +536 -0
- package/dist/components/SchemaForm.svelte.d.ts +83 -0
- package/dist/components/SettingsModal.svelte +279 -0
- package/dist/components/SettingsModal.svelte.d.ts +23 -0
- package/dist/components/SettingsPanel.svelte +638 -0
- package/dist/components/SettingsPanel.svelte.d.ts +21 -0
- package/dist/components/StatusIcon.stories.svelte +60 -0
- package/dist/components/StatusIcon.stories.svelte.d.ts +27 -0
- package/dist/components/StatusIcon.svelte +119 -0
- package/dist/components/StatusIcon.svelte.d.ts +10 -0
- package/dist/components/StatusLabel.stories.svelte +17 -0
- package/dist/components/StatusLabel.stories.svelte.d.ts +27 -0
- package/dist/components/StatusLabel.svelte +33 -0
- package/dist/components/StatusLabel.svelte.d.ts +7 -0
- package/dist/components/ThemeToggle.stories.svelte +25 -0
- package/dist/components/ThemeToggle.stories.svelte.d.ts +27 -0
- package/dist/components/ThemeToggle.svelte +185 -0
- package/dist/components/ThemeToggle.svelte.d.ts +14 -0
- package/dist/components/UniversalNode.svelte +155 -0
- package/dist/components/UniversalNode.svelte.d.ts +15 -0
- package/dist/components/WorkflowEditor.svelte +1035 -0
- package/dist/components/WorkflowEditor.svelte.d.ts +23 -0
- package/dist/components/form/FormArray.svelte +1049 -0
- package/dist/components/form/FormArray.svelte.d.ts +22 -0
- package/dist/components/form/FormAutocomplete.svelte +1009 -0
- package/dist/components/form/FormAutocomplete.svelte.d.ts +25 -0
- package/dist/components/form/FormCheckboxGroup.stories.svelte +28 -0
- package/dist/components/form/FormCheckboxGroup.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormCheckboxGroup.svelte +155 -0
- package/dist/components/form/FormCheckboxGroup.svelte.d.ts +17 -0
- package/dist/components/form/FormCodeEditor.svelte +458 -0
- package/dist/components/form/FormCodeEditor.svelte.d.ts +25 -0
- package/dist/components/form/FormField.svelte +417 -0
- package/dist/components/form/FormField.svelte.d.ts +29 -0
- package/dist/components/form/FormFieldLight.svelte +425 -0
- package/dist/components/form/FormFieldLight.svelte.d.ts +18 -0
- package/dist/components/form/FormFieldWrapper.stories.svelte +53 -0
- package/dist/components/form/FormFieldWrapper.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormFieldWrapper.svelte +125 -0
- package/dist/components/form/FormFieldWrapper.svelte.d.ts +18 -0
- package/dist/components/form/FormFieldset.svelte +142 -0
- package/dist/components/form/FormFieldset.svelte.d.ts +11 -0
- package/dist/components/form/FormMarkdownEditor.svelte +752 -0
- package/dist/components/form/FormMarkdownEditor.svelte.d.ts +33 -0
- package/dist/components/form/FormNumberField.stories.svelte +36 -0
- package/dist/components/form/FormNumberField.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormNumberField.svelte +112 -0
- package/dist/components/form/FormNumberField.svelte.d.ts +25 -0
- package/dist/components/form/FormRangeField.stories.svelte +31 -0
- package/dist/components/form/FormRangeField.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormRangeField.svelte +246 -0
- package/dist/components/form/FormRangeField.svelte.d.ts +23 -0
- package/dist/components/form/FormSelect.stories.svelte +50 -0
- package/dist/components/form/FormSelect.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormSelect.svelte +129 -0
- package/dist/components/form/FormSelect.svelte.d.ts +20 -0
- package/dist/components/form/FormTemplateEditor.svelte +825 -0
- package/dist/components/form/FormTemplateEditor.svelte.d.ts +41 -0
- package/dist/components/form/FormTextField.stories.svelte +30 -0
- package/dist/components/form/FormTextField.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormTextField.svelte +91 -0
- package/dist/components/form/FormTextField.svelte.d.ts +19 -0
- package/dist/components/form/FormTextarea.stories.svelte +34 -0
- package/dist/components/form/FormTextarea.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormTextarea.svelte +97 -0
- package/dist/components/form/FormTextarea.svelte.d.ts +21 -0
- package/dist/components/form/FormToggle.stories.svelte +30 -0
- package/dist/components/form/FormToggle.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormToggle.svelte +126 -0
- package/dist/components/form/FormToggle.svelte.d.ts +19 -0
- package/dist/components/form/FormUISchemaRenderer.svelte +136 -0
- package/dist/components/form/FormUISchemaRenderer.svelte.d.ts +32 -0
- package/dist/components/form/index.d.ts +50 -0
- package/dist/components/form/index.js +54 -0
- package/dist/components/form/templateAutocomplete.d.ts +29 -0
- package/dist/components/form/templateAutocomplete.js +254 -0
- package/dist/components/form/types.d.ts +485 -0
- package/dist/components/form/types.js +73 -0
- package/dist/components/interrupt/ChoicePrompt.stories.svelte +52 -0
- package/dist/components/interrupt/ChoicePrompt.stories.svelte.d.ts +27 -0
- package/dist/components/interrupt/ChoicePrompt.svelte +401 -0
- package/dist/components/interrupt/ChoicePrompt.svelte.d.ts +23 -0
- package/dist/components/interrupt/ConfirmationPrompt.stories.svelte +71 -0
- package/dist/components/interrupt/ConfirmationPrompt.stories.svelte.d.ts +27 -0
- package/dist/components/interrupt/ConfirmationPrompt.svelte +292 -0
- package/dist/components/interrupt/ConfirmationPrompt.svelte.d.ts +25 -0
- package/dist/components/interrupt/FormPrompt.svelte +236 -0
- package/dist/components/interrupt/FormPrompt.svelte.d.ts +23 -0
- package/dist/components/interrupt/InterruptBubble.svelte +601 -0
- package/dist/components/interrupt/InterruptBubble.svelte.d.ts +16 -0
- package/dist/components/interrupt/ReviewPrompt.stories.svelte +67 -0
- package/dist/components/interrupt/ReviewPrompt.stories.svelte.d.ts +27 -0
- package/dist/components/interrupt/ReviewPrompt.svelte +861 -0
- package/dist/components/interrupt/ReviewPrompt.svelte.d.ts +23 -0
- package/dist/components/interrupt/TextInputPrompt.stories.svelte +47 -0
- package/dist/components/interrupt/TextInputPrompt.stories.svelte.d.ts +27 -0
- package/dist/components/interrupt/TextInputPrompt.svelte +346 -0
- package/dist/components/interrupt/TextInputPrompt.svelte.d.ts +23 -0
- package/dist/components/interrupt/index.d.ts +13 -0
- package/dist/components/interrupt/index.js +15 -0
- package/dist/components/layouts/MainLayout.svelte +718 -0
- package/dist/components/layouts/MainLayout.svelte.d.ts +62 -0
- package/dist/components/nodes/GatewayNode.stories.svelte +108 -0
- package/dist/components/nodes/GatewayNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/GatewayNode.svelte +591 -0
- package/dist/components/nodes/GatewayNode.svelte.d.ts +15 -0
- package/dist/components/nodes/IdeaNode.stories.svelte +52 -0
- package/dist/components/nodes/IdeaNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/IdeaNode.svelte +455 -0
- package/dist/components/nodes/IdeaNode.svelte.d.ts +24 -0
- package/dist/components/nodes/NotesNode.stories.svelte +76 -0
- package/dist/components/nodes/NotesNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/NotesNode.svelte +378 -0
- package/dist/components/nodes/NotesNode.svelte.d.ts +24 -0
- package/dist/components/nodes/SimpleNode.stories.svelte +159 -0
- package/dist/components/nodes/SimpleNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/SimpleNode.svelte +451 -0
- package/dist/components/nodes/SimpleNode.svelte.d.ts +25 -0
- package/dist/components/nodes/SquareNode.stories.svelte +82 -0
- package/dist/components/nodes/SquareNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/SquareNode.svelte +407 -0
- package/dist/components/nodes/SquareNode.svelte.d.ts +25 -0
- package/dist/components/nodes/TerminalNode.stories.svelte +25 -0
- package/dist/components/nodes/TerminalNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/TerminalNode.svelte +690 -0
- package/dist/components/nodes/TerminalNode.svelte.d.ts +25 -0
- package/dist/components/nodes/ToolNode.stories.svelte +189 -0
- package/dist/components/nodes/ToolNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/ToolNode.svelte +471 -0
- package/dist/components/nodes/ToolNode.svelte.d.ts +36 -0
- package/dist/components/nodes/WorkflowNode.stories.svelte +55 -0
- package/dist/components/nodes/WorkflowNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/WorkflowNode.svelte +571 -0
- package/dist/components/nodes/WorkflowNode.svelte.d.ts +15 -0
- package/dist/components/playground/ChatPanel.svelte +905 -0
- package/dist/components/playground/ChatPanel.svelte.d.ts +46 -0
- package/dist/components/playground/ExecutionLogs.svelte +488 -0
- package/dist/components/playground/ExecutionLogs.svelte.d.ts +14 -0
- package/dist/components/playground/InputCollector.svelte +444 -0
- package/dist/components/playground/InputCollector.svelte.d.ts +16 -0
- package/dist/components/playground/MessageBubble.stories.svelte +62 -0
- package/dist/components/playground/MessageBubble.stories.svelte.d.ts +27 -0
- package/dist/components/playground/MessageBubble.svelte +633 -0
- package/dist/components/playground/MessageBubble.svelte.d.ts +24 -0
- package/dist/components/playground/Playground.svelte +1075 -0
- package/dist/components/playground/Playground.svelte.d.ts +25 -0
- package/dist/components/playground/PlaygroundModal.svelte +220 -0
- package/dist/components/playground/PlaygroundModal.svelte.d.ts +25 -0
- package/dist/components/playground/SessionManager.svelte +538 -0
- package/dist/components/playground/SessionManager.svelte.d.ts +20 -0
- package/dist/config/agentSpecEndpoints.d.ts +70 -0
- package/dist/config/agentSpecEndpoints.js +65 -0
- package/dist/config/constants.d.ts +43 -0
- package/dist/config/constants.js +31 -0
- package/dist/config/defaultCategories.d.ts +7 -0
- package/dist/config/defaultCategories.js +126 -0
- package/dist/config/defaultPortConfig.d.ts +6 -0
- package/dist/config/defaultPortConfig.js +201 -0
- package/dist/config/endpoints.d.ts +160 -0
- package/dist/config/endpoints.js +146 -0
- package/dist/config/runtimeConfig.d.ts +47 -0
- package/dist/config/runtimeConfig.js +80 -0
- package/dist/core/index.d.ts +75 -0
- package/dist/core/index.js +92 -0
- package/dist/display/index.d.ts +29 -0
- package/dist/display/index.js +36 -0
- package/dist/editor/index.d.ts +95 -0
- package/dist/editor/index.js +138 -0
- package/dist/form/code.d.ts +101 -0
- package/dist/form/code.js +168 -0
- package/dist/form/fieldRegistry.d.ts +169 -0
- package/dist/form/fieldRegistry.js +152 -0
- package/dist/form/full.d.ts +56 -0
- package/dist/form/full.js +80 -0
- package/dist/form/index.d.ts +77 -0
- package/dist/form/index.js +91 -0
- package/dist/form/markdown.d.ts +69 -0
- package/dist/form/markdown.js +103 -0
- package/dist/helpers/nodeLayoutHelper.d.ts +14 -0
- package/dist/helpers/nodeLayoutHelper.js +19 -0
- package/dist/helpers/proximityConnect.d.ts +94 -0
- package/dist/helpers/proximityConnect.js +314 -0
- package/dist/helpers/workflowEditorHelper.d.ts +183 -0
- package/dist/helpers/workflowEditorHelper.js +595 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +64 -0
- package/dist/mocks/app-environment.d.ts +8 -0
- package/dist/mocks/app-environment.js +16 -0
- package/dist/mocks/app-forms.d.ts +2 -0
- package/dist/mocks/app-forms.js +22 -0
- package/dist/mocks/app-navigation.d.ts +5 -0
- package/dist/mocks/app-navigation.js +36 -0
- package/dist/mocks/app-stores.d.ts +14 -0
- package/dist/mocks/app-stores.js +26 -0
- package/dist/playground/index.d.ts +131 -0
- package/dist/playground/index.js +172 -0
- package/dist/playground/mount.d.ts +203 -0
- package/dist/playground/mount.js +235 -0
- package/dist/registry/BaseRegistry.d.ts +92 -0
- package/dist/registry/BaseRegistry.js +124 -0
- package/dist/registry/builtinFormats.d.ts +23 -0
- package/dist/registry/builtinFormats.js +70 -0
- package/dist/registry/builtinNodes.d.ts +77 -0
- package/dist/registry/builtinNodes.js +211 -0
- package/dist/registry/index.d.ts +8 -0
- package/dist/registry/index.js +12 -0
- package/dist/registry/nodeComponentRegistry.d.ts +276 -0
- package/dist/registry/nodeComponentRegistry.js +262 -0
- package/dist/registry/plugin.d.ts +215 -0
- package/dist/registry/plugin.js +249 -0
- package/dist/registry/workflowFormatRegistry.d.ts +122 -0
- package/dist/registry/workflowFormatRegistry.js +96 -0
- package/dist/schema/index.d.ts +23 -0
- package/dist/schema/index.js +23 -0
- package/dist/schemas/v1/workflow.schema.json +1078 -0
- package/dist/services/agentSpecExecutionService.d.ts +106 -0
- package/dist/services/agentSpecExecutionService.js +334 -0
- package/dist/services/api.d.ts +115 -0
- package/dist/services/api.js +214 -0
- package/dist/services/apiVariableService.d.ts +114 -0
- package/dist/services/apiVariableService.js +338 -0
- package/dist/services/autoSaveService.d.ts +112 -0
- package/dist/services/autoSaveService.js +227 -0
- package/dist/services/categoriesApi.d.ts +14 -0
- package/dist/services/categoriesApi.js +49 -0
- package/dist/services/draftStorage.d.ts +171 -0
- package/dist/services/draftStorage.js +299 -0
- package/dist/services/dynamicSchemaService.d.ts +108 -0
- package/dist/services/dynamicSchemaService.js +444 -0
- package/dist/services/globalSave.d.ts +69 -0
- package/dist/services/globalSave.js +248 -0
- package/dist/services/historyService.d.ts +208 -0
- package/dist/services/historyService.js +321 -0
- package/dist/services/interruptService.d.ts +133 -0
- package/dist/services/interruptService.js +280 -0
- package/dist/services/nodeExecutionService.d.ts +63 -0
- package/dist/services/nodeExecutionService.js +266 -0
- package/dist/services/playgroundService.d.ts +130 -0
- package/dist/services/playgroundService.js +321 -0
- package/dist/services/portConfigApi.d.ts +14 -0
- package/dist/services/portConfigApi.js +54 -0
- package/dist/services/settingsService.d.ts +92 -0
- package/dist/services/settingsService.js +196 -0
- package/dist/services/toastService.d.ts +156 -0
- package/dist/services/toastService.js +265 -0
- package/dist/services/variableService.d.ts +141 -0
- package/dist/services/variableService.js +463 -0
- package/dist/services/workflowStorage.d.ts +37 -0
- package/dist/services/workflowStorage.js +116 -0
- package/dist/settings/index.d.ts +25 -0
- package/dist/settings/index.js +33 -0
- package/dist/stores/categoriesStore.svelte.d.ts +32 -0
- package/dist/stores/categoriesStore.svelte.js +77 -0
- package/dist/stores/editorStateMachine.svelte.d.ts +42 -0
- package/dist/stores/editorStateMachine.svelte.js +132 -0
- package/dist/stores/historyStore.svelte.d.ts +136 -0
- package/dist/stores/historyStore.svelte.js +207 -0
- package/dist/stores/interruptStore.svelte.d.ts +179 -0
- package/dist/stores/interruptStore.svelte.js +346 -0
- package/dist/stores/playgroundStore.svelte.d.ts +230 -0
- package/dist/stores/playgroundStore.svelte.js +515 -0
- package/dist/stores/portCoordinateStore.svelte.d.ts +66 -0
- package/dist/stores/portCoordinateStore.svelte.js +186 -0
- package/dist/stores/settingsStore.svelte.d.ts +158 -0
- package/dist/stores/settingsStore.svelte.js +544 -0
- package/dist/stores/workflowStore.svelte.d.ts +260 -0
- package/dist/stores/workflowStore.svelte.js +649 -0
- package/dist/stories/CanvasDecorator.svelte +49 -0
- package/dist/stories/CanvasDecorator.svelte.d.ts +8 -0
- package/dist/stories/NodeDecorator.svelte +73 -0
- package/dist/stories/NodeDecorator.svelte.d.ts +8 -0
- package/dist/stories/utils.d.ts +93 -0
- package/dist/stories/utils.js +122 -0
- package/dist/styles/base.css +1300 -0
- package/dist/styles/toast.css +35 -0
- package/dist/styles/tokens.css +475 -0
- package/dist/svelte-app.d.ts +150 -0
- package/dist/svelte-app.js +295 -0
- package/dist/types/agentspec.d.ts +318 -0
- package/dist/types/agentspec.js +48 -0
- package/dist/types/auth.d.ts +263 -0
- package/dist/types/auth.js +229 -0
- package/dist/types/config.d.ts +151 -0
- package/dist/types/config.js +7 -0
- package/dist/types/events.d.ts +190 -0
- package/dist/types/events.js +30 -0
- package/dist/types/index.d.ts +1234 -0
- package/dist/types/index.js +27 -0
- package/dist/types/interrupt.d.ts +390 -0
- package/dist/types/interrupt.js +145 -0
- package/dist/types/interruptState.d.ts +211 -0
- package/dist/types/interruptState.js +308 -0
- package/dist/types/playground.d.ts +351 -0
- package/dist/types/playground.js +95 -0
- package/dist/types/settings.d.ts +189 -0
- package/dist/types/settings.js +97 -0
- package/dist/types/uischema.d.ts +144 -0
- package/dist/types/uischema.js +51 -0
- package/dist/utils/colors.d.ts +288 -0
- package/dist/utils/colors.js +548 -0
- package/dist/utils/config.d.ts +37 -0
- package/dist/utils/config.js +226 -0
- package/dist/utils/connections.d.ts +125 -0
- package/dist/utils/connections.js +414 -0
- package/dist/utils/errors.d.ts +28 -0
- package/dist/utils/errors.js +44 -0
- package/dist/utils/fetchWithAuth.d.ts +25 -0
- package/dist/utils/fetchWithAuth.js +34 -0
- package/dist/utils/handleIds.d.ts +35 -0
- package/dist/utils/handleIds.js +58 -0
- package/dist/utils/handlePositioning.d.ts +31 -0
- package/dist/utils/handlePositioning.js +35 -0
- package/dist/utils/icons.d.ts +106 -0
- package/dist/utils/icons.js +157 -0
- package/dist/utils/logger.d.ts +47 -0
- package/dist/utils/logger.js +72 -0
- package/dist/utils/nodeStatus.d.ts +53 -0
- package/dist/utils/nodeStatus.js +183 -0
- package/dist/utils/nodeTypes.d.ts +117 -0
- package/dist/utils/nodeTypes.js +244 -0
- package/dist/utils/nodeWrapper.d.ts +39 -0
- package/dist/utils/nodeWrapper.js +62 -0
- package/dist/utils/performanceUtils.d.ts +30 -0
- package/dist/utils/performanceUtils.js +108 -0
- package/dist/utils/sanitize.d.ts +19 -0
- package/dist/utils/sanitize.js +31 -0
- package/dist/utils/uischema.d.ts +52 -0
- package/dist/utils/uischema.js +88 -0
- package/dist/utils/validation.d.ts +29 -0
- package/dist/utils/validation.js +39 -0
- package/package.json +292 -0
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
FormMarkdownEditor Component
|
|
3
|
+
CodeMirror 6-based Markdown editor for rich text content
|
|
4
|
+
|
|
5
|
+
Features:
|
|
6
|
+
- Full Markdown editing with CodeMirror 6
|
|
7
|
+
- Markdown syntax highlighting via @codemirror/lang-markdown
|
|
8
|
+
- Toolbar with common formatting options + keyboard shortcuts
|
|
9
|
+
- Autosave support (optional, localStorage)
|
|
10
|
+
- Status bar with word/line/character count
|
|
11
|
+
- Consistent styling with other form components
|
|
12
|
+
- Proper ARIA attributes for accessibility
|
|
13
|
+
- Dark/light theme support
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
Use with schema format: "markdown" to render this editor
|
|
17
|
+
-->
|
|
18
|
+
|
|
19
|
+
<script lang="ts">
|
|
20
|
+
import { onMount, onDestroy } from 'svelte';
|
|
21
|
+
import { EditorView, lineNumbers, drawSelection, keymap } from '@codemirror/view';
|
|
22
|
+
import { EditorState, Compartment } from '@codemirror/state';
|
|
23
|
+
import { history, historyKeymap, defaultKeymap, indentWithTab } from '@codemirror/commands';
|
|
24
|
+
import { highlightSpecialChars, highlightActiveLine } from '@codemirror/view';
|
|
25
|
+
import { syntaxHighlighting, defaultHighlightStyle } from '@codemirror/language';
|
|
26
|
+
import { markdown } from '@codemirror/lang-markdown';
|
|
27
|
+
import { oneDark } from '@codemirror/theme-one-dark';
|
|
28
|
+
|
|
29
|
+
interface Props {
|
|
30
|
+
/** Field identifier */
|
|
31
|
+
id: string;
|
|
32
|
+
/** Current value (markdown string) */
|
|
33
|
+
value: string;
|
|
34
|
+
/** Placeholder text shown when empty */
|
|
35
|
+
placeholder?: string;
|
|
36
|
+
/** Whether the field is required */
|
|
37
|
+
required?: boolean;
|
|
38
|
+
/** Editor height - "auto" or specific value like "300px" */
|
|
39
|
+
height?: string;
|
|
40
|
+
/** Whether to show the toolbar */
|
|
41
|
+
showToolbar?: boolean;
|
|
42
|
+
/** Whether to show the status bar */
|
|
43
|
+
showStatusBar?: boolean;
|
|
44
|
+
/** Whether to enable spell checking */
|
|
45
|
+
spellChecker?: boolean;
|
|
46
|
+
/** Whether to enable autosave */
|
|
47
|
+
autosave?: boolean;
|
|
48
|
+
/** Autosave delay in milliseconds */
|
|
49
|
+
autosaveDelay?: number;
|
|
50
|
+
/** Whether the field is disabled (read-only) */
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
/** Whether to use dark theme */
|
|
53
|
+
darkTheme?: boolean;
|
|
54
|
+
/** ARIA description ID */
|
|
55
|
+
ariaDescribedBy?: string;
|
|
56
|
+
/** Callback when value changes */
|
|
57
|
+
onChange: (value: string) => void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let {
|
|
61
|
+
id,
|
|
62
|
+
value = '',
|
|
63
|
+
placeholder = 'Write your markdown here...',
|
|
64
|
+
required = false,
|
|
65
|
+
height = '300px',
|
|
66
|
+
showToolbar = true,
|
|
67
|
+
showStatusBar = true,
|
|
68
|
+
spellChecker = false,
|
|
69
|
+
autosave = false,
|
|
70
|
+
autosaveDelay = 10000,
|
|
71
|
+
disabled = false,
|
|
72
|
+
darkTheme = false,
|
|
73
|
+
ariaDescribedBy,
|
|
74
|
+
onChange
|
|
75
|
+
}: Props = $props();
|
|
76
|
+
|
|
77
|
+
/** Reference to the editor container element */
|
|
78
|
+
let containerRef: HTMLDivElement | undefined = $state(undefined);
|
|
79
|
+
|
|
80
|
+
/** CodeMirror editor instance */
|
|
81
|
+
let editorView: EditorView | undefined = $state(undefined);
|
|
82
|
+
|
|
83
|
+
/** Flag to prevent update loops */
|
|
84
|
+
let isInternalUpdate = false;
|
|
85
|
+
|
|
86
|
+
/** Flag to skip $effect when change originated from the editor */
|
|
87
|
+
let isEditorUpdate = false;
|
|
88
|
+
|
|
89
|
+
/** Status bar stats */
|
|
90
|
+
let wordCount = $state(0);
|
|
91
|
+
let lineCount = $state(0);
|
|
92
|
+
let charCount = $state(0);
|
|
93
|
+
|
|
94
|
+
/** Autosave timer */
|
|
95
|
+
let autosaveTimer: ReturnType<typeof setTimeout> | undefined;
|
|
96
|
+
|
|
97
|
+
/** Theme compartment for dynamic theme switching */
|
|
98
|
+
const themeCompartment = new Compartment();
|
|
99
|
+
|
|
100
|
+
// ── Toolbar actions ──────────────────────────────────────
|
|
101
|
+
|
|
102
|
+
type ToolbarAction = {
|
|
103
|
+
id: string;
|
|
104
|
+
label: string;
|
|
105
|
+
icon: string;
|
|
106
|
+
/** If true, icon is an SVG string rendered with {@html} */
|
|
107
|
+
isSvg?: boolean;
|
|
108
|
+
shortcut?: string;
|
|
109
|
+
action: () => void;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Inline SVG icons (heroicons outline, 16x16)
|
|
113
|
+
const icons = {
|
|
114
|
+
link: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="16" height="16"><path d="M12.232 4.232a2.5 2.5 0 0 1 3.536 3.536l-1.225 1.224a.75.75 0 0 0 1.061 1.06l1.224-1.224a4 4 0 0 0-5.656-5.656l-3 3a4 4 0 0 0 .225 5.865.75.75 0 0 0 .977-1.138 2.5 2.5 0 0 1-.142-3.667l3-3Z"/><path d="M11.603 7.963a.75.75 0 0 0-.977 1.138 2.5 2.5 0 0 1 .142 3.667l-3 3a2.5 2.5 0 0 1-3.536-3.536l1.225-1.224a.75.75 0 0 0-1.061-1.06l-1.224 1.224a4 4 0 1 0 5.656 5.656l3-3a4 4 0 0 0-.225-5.865Z"/></svg>',
|
|
115
|
+
image:
|
|
116
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="16" height="16"><path fill-rule="evenodd" d="M1 5.25A2.25 2.25 0 0 1 3.25 3h13.5A2.25 2.25 0 0 1 19 5.25v9.5A2.25 2.25 0 0 1 16.75 17H3.25A2.25 2.25 0 0 1 1 14.75v-9.5Zm1.5 5.81v3.69c0 .414.336.75.75.75h13.5a.75.75 0 0 0 .75-.75v-2.69l-2.22-2.219a.75.75 0 0 0-1.06 0l-1.91 1.909.47.47a.75.75 0 1 1-1.06 1.06L6.53 8.091a.75.75 0 0 0-1.06 0L2.5 11.06Zm6.5-3.31a1.5 1.5 0 1 1 3 0 1.5 1.5 0 0 1-3 0Z" clip-rule="evenodd"/></svg>',
|
|
117
|
+
table:
|
|
118
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="16" height="16"><path fill-rule="evenodd" d="M.99 5.24A2.25 2.25 0 0 1 3.25 3h13.5A2.25 2.25 0 0 1 19 5.25v9.5A2.25 2.25 0 0 1 16.75 17H3.25A2.25 2.25 0 0 1 1 14.75v-9.5Zm8.26 4.51v3.75h1.5v-3.75h-1.5Zm1.5-1.5v-3.75h-1.5v3.75h1.5Zm-3-3.75H3.25a.75.75 0 0 0-.75.75v3h5.25v-3.75Zm-5.25 5.25v3.75c0 .414.336.75.75.75h4.5v-4.5H2.5Zm14.5 0h-5.25v4.5h4.5a.75.75 0 0 0 .75-.75v-3.75Zm0-1.5v-3a.75.75 0 0 0-.75-.75h-4.5v3.75H17Z" clip-rule="evenodd"/></svg>'
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
function wrapSelection(before: string, after: string) {
|
|
122
|
+
if (!editorView) return;
|
|
123
|
+
const { from, to } = editorView.state.selection.main;
|
|
124
|
+
const selected = editorView.state.sliceDoc(from, to);
|
|
125
|
+
const replacement = `${before}${selected || 'text'}${after}`;
|
|
126
|
+
editorView.dispatch({
|
|
127
|
+
changes: { from, to, insert: replacement },
|
|
128
|
+
selection: {
|
|
129
|
+
anchor: selected ? from + before.length : from + before.length,
|
|
130
|
+
head: selected ? from + before.length + selected.length : from + before.length + 4
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
editorView.focus();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function prefixLine(prefix: string) {
|
|
137
|
+
if (!editorView) return;
|
|
138
|
+
const { from } = editorView.state.selection.main;
|
|
139
|
+
const line = editorView.state.doc.lineAt(from);
|
|
140
|
+
const currentText = line.text;
|
|
141
|
+
|
|
142
|
+
// If already has this prefix, remove it (toggle)
|
|
143
|
+
if (currentText.startsWith(prefix)) {
|
|
144
|
+
editorView.dispatch({
|
|
145
|
+
changes: { from: line.from, to: line.from + prefix.length, insert: '' }
|
|
146
|
+
});
|
|
147
|
+
} else {
|
|
148
|
+
// Remove any existing heading prefix before adding new one
|
|
149
|
+
const headingMatch = currentText.match(/^#{1,6}\s/);
|
|
150
|
+
const removeLen = headingMatch ? headingMatch[0].length : 0;
|
|
151
|
+
editorView.dispatch({
|
|
152
|
+
changes: { from: line.from, to: line.from + removeLen, insert: prefix }
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
editorView.focus();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function insertAtCursor(text: string) {
|
|
159
|
+
if (!editorView) return;
|
|
160
|
+
const { from, to } = editorView.state.selection.main;
|
|
161
|
+
editorView.dispatch({
|
|
162
|
+
changes: { from, to, insert: text },
|
|
163
|
+
selection: { anchor: from + text.length }
|
|
164
|
+
});
|
|
165
|
+
editorView.focus();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const toolbarActions: (ToolbarAction | '|')[] = [
|
|
169
|
+
{
|
|
170
|
+
id: 'bold',
|
|
171
|
+
label: 'Bold',
|
|
172
|
+
icon: 'B',
|
|
173
|
+
shortcut: 'Mod-b',
|
|
174
|
+
action: () => wrapSelection('**', '**')
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
id: 'italic',
|
|
178
|
+
label: 'Italic',
|
|
179
|
+
icon: 'I',
|
|
180
|
+
shortcut: 'Mod-i',
|
|
181
|
+
action: () => wrapSelection('_', '_')
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
id: 'strikethrough',
|
|
185
|
+
label: 'Strikethrough',
|
|
186
|
+
icon: 'S',
|
|
187
|
+
action: () => wrapSelection('~~', '~~')
|
|
188
|
+
},
|
|
189
|
+
'|',
|
|
190
|
+
{
|
|
191
|
+
id: 'heading-1',
|
|
192
|
+
label: 'Heading 1',
|
|
193
|
+
icon: 'H1',
|
|
194
|
+
action: () => prefixLine('# ')
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
id: 'heading-2',
|
|
198
|
+
label: 'Heading 2',
|
|
199
|
+
icon: 'H2',
|
|
200
|
+
action: () => prefixLine('## ')
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
id: 'heading-3',
|
|
204
|
+
label: 'Heading 3',
|
|
205
|
+
icon: 'H3',
|
|
206
|
+
action: () => prefixLine('### ')
|
|
207
|
+
},
|
|
208
|
+
'|',
|
|
209
|
+
{
|
|
210
|
+
id: 'quote',
|
|
211
|
+
label: 'Quote',
|
|
212
|
+
icon: '"',
|
|
213
|
+
action: () => prefixLine('> ')
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
id: 'unordered-list',
|
|
217
|
+
label: 'Unordered List',
|
|
218
|
+
icon: '•',
|
|
219
|
+
action: () => prefixLine('- ')
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
id: 'ordered-list',
|
|
223
|
+
label: 'Ordered List',
|
|
224
|
+
icon: '1.',
|
|
225
|
+
action: () => prefixLine('1. ')
|
|
226
|
+
},
|
|
227
|
+
'|',
|
|
228
|
+
{
|
|
229
|
+
id: 'link',
|
|
230
|
+
label: 'Link',
|
|
231
|
+
icon: icons.link,
|
|
232
|
+
isSvg: true,
|
|
233
|
+
shortcut: 'Mod-k',
|
|
234
|
+
action: () => {
|
|
235
|
+
if (!editorView) return;
|
|
236
|
+
const { from, to } = editorView.state.selection.main;
|
|
237
|
+
const selected = editorView.state.sliceDoc(from, to);
|
|
238
|
+
const text = selected || 'link text';
|
|
239
|
+
const replacement = `[${text}](url)`;
|
|
240
|
+
editorView.dispatch({
|
|
241
|
+
changes: { from, to, insert: replacement },
|
|
242
|
+
selection: {
|
|
243
|
+
anchor: from + text.length + 3,
|
|
244
|
+
head: from + text.length + 6
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
editorView.focus();
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
id: 'image',
|
|
252
|
+
label: 'Image',
|
|
253
|
+
icon: icons.image,
|
|
254
|
+
isSvg: true,
|
|
255
|
+
action: () => insertAtCursor('')
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
id: 'table',
|
|
259
|
+
label: 'Table',
|
|
260
|
+
icon: icons.table,
|
|
261
|
+
isSvg: true,
|
|
262
|
+
action: () =>
|
|
263
|
+
insertAtCursor('\n| Header | Header |\n| ------ | ------ |\n| Cell | Cell |\n')
|
|
264
|
+
}
|
|
265
|
+
];
|
|
266
|
+
|
|
267
|
+
// ── CM6 Keyboard shortcuts for toolbar actions ───────────
|
|
268
|
+
|
|
269
|
+
function createToolbarKeymap() {
|
|
270
|
+
return keymap.of([
|
|
271
|
+
{
|
|
272
|
+
key: 'Mod-b',
|
|
273
|
+
run: () => {
|
|
274
|
+
wrapSelection('**', '**');
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
key: 'Mod-i',
|
|
280
|
+
run: () => {
|
|
281
|
+
wrapSelection('_', '_');
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
key: 'Mod-k',
|
|
287
|
+
run: () => {
|
|
288
|
+
const action = toolbarActions.find((a) => a !== '|' && a.id === 'link');
|
|
289
|
+
if (action && action !== '|') action.action();
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
key: 'Mod-h',
|
|
295
|
+
run: () => {
|
|
296
|
+
prefixLine('## ');
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
key: "Mod-'",
|
|
302
|
+
run: () => {
|
|
303
|
+
prefixLine('> ');
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
key: 'Mod-l',
|
|
309
|
+
run: () => {
|
|
310
|
+
prefixLine('- ');
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
]);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// ── Stats computation ────────────────────────────────────
|
|
318
|
+
|
|
319
|
+
function updateStats(doc: { toString: () => string; lines: number }) {
|
|
320
|
+
const text = doc.toString();
|
|
321
|
+
charCount = text.length;
|
|
322
|
+
lineCount = doc.lines;
|
|
323
|
+
const trimmed = text.trim();
|
|
324
|
+
wordCount = trimmed ? trimmed.split(/\s+/).length : 0;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// ── Editor setup ─────────────────────────────────────────
|
|
328
|
+
|
|
329
|
+
function createExtensions() {
|
|
330
|
+
const extensions = [
|
|
331
|
+
lineNumbers(),
|
|
332
|
+
highlightSpecialChars(),
|
|
333
|
+
highlightActiveLine(),
|
|
334
|
+
drawSelection(),
|
|
335
|
+
|
|
336
|
+
// Editing features (skip when read-only)
|
|
337
|
+
...(disabled
|
|
338
|
+
? [EditorState.readOnly.of(true), EditorView.editable.of(false)]
|
|
339
|
+
: [
|
|
340
|
+
history(),
|
|
341
|
+
keymap.of([...defaultKeymap, ...historyKeymap, indentWithTab]),
|
|
342
|
+
createToolbarKeymap()
|
|
343
|
+
]),
|
|
344
|
+
|
|
345
|
+
// Theme
|
|
346
|
+
themeCompartment.of(
|
|
347
|
+
darkTheme ? oneDark : syntaxHighlighting(defaultHighlightStyle, { fallback: true })
|
|
348
|
+
),
|
|
349
|
+
|
|
350
|
+
// Markdown language support
|
|
351
|
+
markdown(),
|
|
352
|
+
|
|
353
|
+
// Update listener
|
|
354
|
+
EditorView.updateListener.of((update) => {
|
|
355
|
+
if (!update.docChanged || isInternalUpdate) return;
|
|
356
|
+
|
|
357
|
+
const content = update.state.doc.toString();
|
|
358
|
+
isEditorUpdate = true;
|
|
359
|
+
onChange(content);
|
|
360
|
+
|
|
361
|
+
updateStats(update.state.doc);
|
|
362
|
+
|
|
363
|
+
// Autosave
|
|
364
|
+
if (autosave) {
|
|
365
|
+
clearTimeout(autosaveTimer);
|
|
366
|
+
autosaveTimer = setTimeout(() => {
|
|
367
|
+
try {
|
|
368
|
+
localStorage.setItem(`flowdrop-markdown-${id}`, content);
|
|
369
|
+
} catch {
|
|
370
|
+
// localStorage may be full or unavailable
|
|
371
|
+
}
|
|
372
|
+
}, autosaveDelay);
|
|
373
|
+
}
|
|
374
|
+
}),
|
|
375
|
+
|
|
376
|
+
// Custom theme
|
|
377
|
+
EditorView.theme({
|
|
378
|
+
'&': {
|
|
379
|
+
height: height,
|
|
380
|
+
fontSize: 'var(--fd-text-sm, 0.8125rem)',
|
|
381
|
+
fontFamily: "'JetBrains Mono', 'Fira Code', 'Monaco', 'Menlo', monospace"
|
|
382
|
+
},
|
|
383
|
+
'.cm-scroller': {
|
|
384
|
+
overflow: 'auto'
|
|
385
|
+
},
|
|
386
|
+
'.cm-content': {
|
|
387
|
+
minHeight: '100px',
|
|
388
|
+
padding: '0.5rem 0'
|
|
389
|
+
},
|
|
390
|
+
'&.cm-focused': {
|
|
391
|
+
outline: 'none'
|
|
392
|
+
}
|
|
393
|
+
}),
|
|
394
|
+
EditorView.lineWrapping,
|
|
395
|
+
|
|
396
|
+
// Accessibility
|
|
397
|
+
EditorView.contentAttributes.of({
|
|
398
|
+
'aria-label': 'Markdown editor',
|
|
399
|
+
'aria-multiline': 'true'
|
|
400
|
+
})
|
|
401
|
+
];
|
|
402
|
+
|
|
403
|
+
return extensions;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
onMount(() => {
|
|
407
|
+
if (!containerRef) return;
|
|
408
|
+
|
|
409
|
+
// Load autosaved content if available
|
|
410
|
+
let initialContent = value;
|
|
411
|
+
if (autosave) {
|
|
412
|
+
try {
|
|
413
|
+
const saved = localStorage.getItem(`flowdrop-markdown-${id}`);
|
|
414
|
+
if (saved !== null) {
|
|
415
|
+
initialContent = saved;
|
|
416
|
+
onChange(saved);
|
|
417
|
+
}
|
|
418
|
+
} catch {
|
|
419
|
+
// localStorage unavailable
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
editorView = new EditorView({
|
|
424
|
+
state: EditorState.create({
|
|
425
|
+
doc: initialContent,
|
|
426
|
+
extensions: createExtensions()
|
|
427
|
+
}),
|
|
428
|
+
parent: containerRef
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
updateStats(editorView.state.doc);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
onDestroy(() => {
|
|
435
|
+
if (autosaveTimer) clearTimeout(autosaveTimer);
|
|
436
|
+
if (editorView) editorView.destroy();
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Update editor content when value prop changes externally
|
|
441
|
+
*/
|
|
442
|
+
$effect(() => {
|
|
443
|
+
if (!editorView) return;
|
|
444
|
+
|
|
445
|
+
// Skip if the change originated from the editor itself
|
|
446
|
+
if (isEditorUpdate) {
|
|
447
|
+
isEditorUpdate = false;
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const currentContent = editorView.state.doc.toString();
|
|
452
|
+
if (value !== currentContent && !isInternalUpdate) {
|
|
453
|
+
isInternalUpdate = true;
|
|
454
|
+
editorView.dispatch({
|
|
455
|
+
changes: {
|
|
456
|
+
from: 0,
|
|
457
|
+
to: editorView.state.doc.length,
|
|
458
|
+
insert: value
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
isInternalUpdate = false;
|
|
462
|
+
updateStats(editorView.state.doc);
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
</script>
|
|
466
|
+
|
|
467
|
+
<div
|
|
468
|
+
class="form-markdown-editor"
|
|
469
|
+
class:form-markdown-editor--dark={darkTheme}
|
|
470
|
+
style="--editor-height: {height}"
|
|
471
|
+
>
|
|
472
|
+
<!-- Hidden input for form submission compatibility -->
|
|
473
|
+
<input
|
|
474
|
+
type="hidden"
|
|
475
|
+
{id}
|
|
476
|
+
name={id}
|
|
477
|
+
{value}
|
|
478
|
+
aria-describedby={ariaDescribedBy}
|
|
479
|
+
aria-required={required}
|
|
480
|
+
/>
|
|
481
|
+
|
|
482
|
+
<!-- Toolbar -->
|
|
483
|
+
{#if showToolbar && !disabled}
|
|
484
|
+
<div class="form-markdown-editor__toolbar" role="toolbar" aria-label="Markdown formatting">
|
|
485
|
+
{#each toolbarActions as item}
|
|
486
|
+
{#if item === '|'}
|
|
487
|
+
<span class="form-markdown-editor__separator"></span>
|
|
488
|
+
{:else}
|
|
489
|
+
<button
|
|
490
|
+
type="button"
|
|
491
|
+
class="form-markdown-editor__btn"
|
|
492
|
+
title="{item.label}{item.shortcut ? ` (${item.shortcut.replace('Mod', '⌘')})` : ''}"
|
|
493
|
+
onclick={item.action}
|
|
494
|
+
>
|
|
495
|
+
{#if item.isSvg}
|
|
496
|
+
<span class="form-markdown-editor__btn-svg">{@html item.icon}</span>
|
|
497
|
+
{:else}
|
|
498
|
+
<span
|
|
499
|
+
class="form-markdown-editor__btn-icon"
|
|
500
|
+
class:form-markdown-editor__btn-icon--bold={item.id === 'bold'}
|
|
501
|
+
class:form-markdown-editor__btn-icon--italic={item.id === 'italic'}
|
|
502
|
+
class:form-markdown-editor__btn-icon--strike={item.id === 'strikethrough'}
|
|
503
|
+
>{item.icon}</span
|
|
504
|
+
>
|
|
505
|
+
{/if}
|
|
506
|
+
</button>
|
|
507
|
+
{/if}
|
|
508
|
+
{/each}
|
|
509
|
+
</div>
|
|
510
|
+
{/if}
|
|
511
|
+
|
|
512
|
+
<!-- CodeMirror container -->
|
|
513
|
+
<div bind:this={containerRef} class="form-markdown-editor__body"></div>
|
|
514
|
+
|
|
515
|
+
<!-- Status bar -->
|
|
516
|
+
{#if showStatusBar}
|
|
517
|
+
<div class="form-markdown-editor__status">
|
|
518
|
+
<span>words: {wordCount}</span>
|
|
519
|
+
<span>lines: {lineCount}</span>
|
|
520
|
+
<span>characters: {charCount}</span>
|
|
521
|
+
</div>
|
|
522
|
+
{/if}
|
|
523
|
+
</div>
|
|
524
|
+
|
|
525
|
+
<style>
|
|
526
|
+
.form-markdown-editor {
|
|
527
|
+
position: relative;
|
|
528
|
+
width: 100%;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/* ── Toolbar ───────────────────────────────────── */
|
|
532
|
+
|
|
533
|
+
.form-markdown-editor__toolbar {
|
|
534
|
+
display: flex;
|
|
535
|
+
align-items: center;
|
|
536
|
+
gap: 0.125rem;
|
|
537
|
+
border: 1px solid var(--fd-border);
|
|
538
|
+
border-bottom: none;
|
|
539
|
+
border-radius: var(--fd-radius-lg) var(--fd-radius-lg) 0 0;
|
|
540
|
+
background-color: var(--fd-subtle);
|
|
541
|
+
padding: 0.375rem 0.5rem;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
.form-markdown-editor__btn {
|
|
545
|
+
display: flex;
|
|
546
|
+
align-items: center;
|
|
547
|
+
justify-content: center;
|
|
548
|
+
width: 2rem;
|
|
549
|
+
height: 2rem;
|
|
550
|
+
border: none;
|
|
551
|
+
border-radius: var(--fd-radius-md);
|
|
552
|
+
background: none;
|
|
553
|
+
color: var(--fd-muted-foreground);
|
|
554
|
+
cursor: pointer;
|
|
555
|
+
font-size: 0.8125rem;
|
|
556
|
+
transition: all var(--fd-transition-fast);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
.form-markdown-editor__btn:hover {
|
|
560
|
+
background-color: var(--fd-border);
|
|
561
|
+
color: var(--fd-foreground);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
.form-markdown-editor__btn-icon--bold {
|
|
565
|
+
font-weight: 700;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
.form-markdown-editor__btn-icon--italic {
|
|
569
|
+
font-style: italic;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
.form-markdown-editor__btn-icon--strike {
|
|
573
|
+
text-decoration: line-through;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
.form-markdown-editor__btn-svg {
|
|
577
|
+
display: flex;
|
|
578
|
+
align-items: center;
|
|
579
|
+
justify-content: center;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
.form-markdown-editor__separator {
|
|
583
|
+
width: 1px;
|
|
584
|
+
height: 1.25rem;
|
|
585
|
+
background-color: var(--fd-border-strong);
|
|
586
|
+
margin: 0 0.25rem;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/* ── Editor body ───────────────────────────────── */
|
|
590
|
+
|
|
591
|
+
.form-markdown-editor__body {
|
|
592
|
+
border: 1px solid var(--fd-border);
|
|
593
|
+
border-radius: var(--fd-radius-lg);
|
|
594
|
+
overflow: hidden;
|
|
595
|
+
background-color: var(--fd-muted);
|
|
596
|
+
transition: border-color var(--fd-transition-normal);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/* When toolbar is present, remove top radius */
|
|
600
|
+
.form-markdown-editor__toolbar + .form-markdown-editor__body {
|
|
601
|
+
border-top: none;
|
|
602
|
+
border-radius: 0;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
.form-markdown-editor__body:hover {
|
|
606
|
+
border-color: var(--fd-border-strong);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
.form-markdown-editor__body:focus-within {
|
|
610
|
+
border-color: var(--fd-primary);
|
|
611
|
+
background-color: var(--fd-background);
|
|
612
|
+
box-shadow:
|
|
613
|
+
0 0 0 3px var(--fd-primary-muted),
|
|
614
|
+
var(--fd-shadow-sm);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/* ── Status bar ────────────────────────────────── */
|
|
618
|
+
|
|
619
|
+
.form-markdown-editor__status {
|
|
620
|
+
display: flex;
|
|
621
|
+
gap: 1rem;
|
|
622
|
+
justify-content: flex-end;
|
|
623
|
+
border: 1px solid var(--fd-border);
|
|
624
|
+
border-top: none;
|
|
625
|
+
border-radius: 0 0 var(--fd-radius-lg) var(--fd-radius-lg);
|
|
626
|
+
background-color: var(--fd-muted);
|
|
627
|
+
padding: 0.375rem 0.75rem;
|
|
628
|
+
font-size: var(--fd-text-xs);
|
|
629
|
+
color: var(--fd-muted-foreground);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/* When no toolbar, body gets top radius */
|
|
633
|
+
.form-markdown-editor:not(:has(.form-markdown-editor__toolbar)) .form-markdown-editor__body {
|
|
634
|
+
border-radius: var(--fd-radius-lg) var(--fd-radius-lg) 0 0;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/* When no status bar, body gets bottom radius */
|
|
638
|
+
.form-markdown-editor:not(:has(.form-markdown-editor__status)) .form-markdown-editor__body {
|
|
639
|
+
border-radius: 0 0 var(--fd-radius-lg) var(--fd-radius-lg);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/* When no toolbar AND no status bar, body gets full radius */
|
|
643
|
+
.form-markdown-editor:not(:has(.form-markdown-editor__toolbar)):not(
|
|
644
|
+
:has(.form-markdown-editor__status)
|
|
645
|
+
)
|
|
646
|
+
.form-markdown-editor__body {
|
|
647
|
+
border-radius: var(--fd-radius-lg);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/* ── CM6 overrides ─────────────────────────────── */
|
|
651
|
+
/* Design tokens (--fd-*) auto-resolve for dark mode via [data-theme='dark'] */
|
|
652
|
+
/* !important needed to override oneDark's JS-injected styles */
|
|
653
|
+
|
|
654
|
+
.form-markdown-editor__body :global(.cm-editor) {
|
|
655
|
+
height: var(--editor-height, 300px);
|
|
656
|
+
background-color: var(--fd-muted) !important;
|
|
657
|
+
color: var(--fd-foreground) !important;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
.form-markdown-editor__body :global(.cm-scroller) {
|
|
661
|
+
overflow: auto;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
.form-markdown-editor__body :global(.cm-content) {
|
|
665
|
+
color: var(--fd-foreground) !important;
|
|
666
|
+
caret-color: var(--fd-foreground) !important;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
.form-markdown-editor__body :global(.cm-line) {
|
|
670
|
+
color: var(--fd-foreground) !important;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
.form-markdown-editor__body :global(.cm-gutters) {
|
|
674
|
+
background-color: var(--fd-subtle) !important;
|
|
675
|
+
border-right: 1px solid var(--fd-border);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
.form-markdown-editor__body :global(.cm-linenumber) {
|
|
679
|
+
color: var(--fd-muted-foreground) !important;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
.form-markdown-editor__body :global(.cm-cursor) {
|
|
683
|
+
border-left-color: var(--fd-muted-foreground) !important;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
.form-markdown-editor__body :global(.cm-activeLine) {
|
|
687
|
+
background-color: var(--fd-subtle) !important;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
.form-markdown-editor__body :global(.cm-activeLineGutter) {
|
|
691
|
+
background-color: var(--fd-subtle) !important;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/* ── Markdown syntax styling ───────────────────── */
|
|
695
|
+
|
|
696
|
+
.form-markdown-editor__body :global(.cm-header-1) {
|
|
697
|
+
font-size: 1.25rem;
|
|
698
|
+
line-height: 1.4;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
.form-markdown-editor__body :global(.cm-header-2) {
|
|
702
|
+
font-size: 1.125rem;
|
|
703
|
+
line-height: 1.4;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
.form-markdown-editor__body :global(.cm-header-3) {
|
|
707
|
+
font-size: 1rem;
|
|
708
|
+
line-height: 1.4;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
.form-markdown-editor__body :global(.cm-header) {
|
|
712
|
+
font-weight: 600;
|
|
713
|
+
color: var(--fd-foreground) !important;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
.form-markdown-editor__body :global(.cm-processingInstruction) {
|
|
717
|
+
color: var(--fd-success) !important;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
.form-markdown-editor__body :global(.cm-emphasis) {
|
|
721
|
+
color: var(--fd-foreground) !important;
|
|
722
|
+
font-style: italic;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
.form-markdown-editor__body :global(.cm-strong) {
|
|
726
|
+
color: var(--fd-foreground) !important;
|
|
727
|
+
font-weight: 700;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
.form-markdown-editor__body :global(.cm-strikethrough) {
|
|
731
|
+
color: var(--fd-muted-foreground) !important;
|
|
732
|
+
text-decoration: line-through;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
.form-markdown-editor__body :global(.cm-url) {
|
|
736
|
+
color: var(--fd-primary) !important;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
.form-markdown-editor__body :global(.cm-link) {
|
|
740
|
+
color: var(--fd-primary) !important;
|
|
741
|
+
text-decoration: underline;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
.form-markdown-editor__body :global(.cm-meta) {
|
|
745
|
+
color: var(--fd-muted-foreground) !important;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
.form-markdown-editor__body :global(.cm-quote) {
|
|
749
|
+
color: var(--fd-success) !important;
|
|
750
|
+
font-style: italic;
|
|
751
|
+
}
|
|
752
|
+
</style>
|