@flowdrop/flowdrop 1.0.1 → 1.2.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 +50 -50
- package/dist/adapters/WorkflowAdapter.d.ts +1 -1
- package/dist/adapters/WorkflowAdapter.js +25 -25
- package/dist/adapters/agentspec/AgentSpecAdapter.d.ts +2 -2
- package/dist/adapters/agentspec/AgentSpecAdapter.js +133 -122
- package/dist/adapters/agentspec/agentAdapter.d.ts +2 -2
- package/dist/adapters/agentspec/agentAdapter.js +10 -10
- package/dist/adapters/agentspec/autoLayout.d.ts +1 -1
- package/dist/adapters/agentspec/autoLayout.js +2 -2
- package/dist/adapters/agentspec/componentTypeDefaults.d.ts +1 -1
- package/dist/adapters/agentspec/componentTypeDefaults.js +120 -120
- package/dist/adapters/agentspec/defaultNodeTypes.d.ts +2 -2
- package/dist/adapters/agentspec/defaultNodeTypes.js +307 -307
- package/dist/adapters/agentspec/index.d.ts +10 -10
- package/dist/adapters/agentspec/index.js +6 -6
- package/dist/adapters/agentspec/validator.d.ts +2 -2
- package/dist/adapters/agentspec/validator.js +22 -20
- package/dist/api/enhanced-client.d.ts +3 -3
- package/dist/api/enhanced-client.js +73 -72
- package/dist/components/App.svelte +1090 -961
- package/dist/components/App.svelte.d.ts +9 -6
- package/dist/components/CanvasBanner.stories.svelte +23 -20
- package/dist/components/CanvasBanner.stories.svelte.d.ts +1 -1
- package/dist/components/CanvasBanner.svelte +52 -46
- package/dist/components/ConfigForm.svelte +1164 -1065
- package/dist/components/ConfigForm.svelte.d.ts +2 -2
- package/dist/components/ConfigModal.svelte +180 -180
- package/dist/components/ConfigModal.svelte.d.ts +1 -1
- package/dist/components/ConfigPanel.stories.svelte +35 -35
- package/dist/components/ConfigPanel.stories.svelte.d.ts +1 -1
- package/dist/components/ConfigPanel.svelte +178 -167
- package/dist/components/ConfigPanel.svelte.d.ts +1 -1
- package/dist/components/ConnectionLine.svelte +25 -25
- package/dist/components/EdgeRefresher.svelte +26 -26
- package/dist/components/FlowDropEdge.stories.svelte +179 -143
- package/dist/components/FlowDropEdge.svelte +147 -147
- package/dist/components/FlowDropEdge.svelte.d.ts +1 -1
- package/dist/components/FlowDropZone.svelte +63 -60
- package/dist/components/FlowDropZone.svelte.d.ts +1 -1
- package/dist/components/LoadingSpinner.stories.svelte +19 -19
- package/dist/components/LoadingSpinner.stories.svelte.d.ts +1 -1
- package/dist/components/LoadingSpinner.svelte +21 -21
- package/dist/components/LoadingSpinner.svelte.d.ts +1 -1
- package/dist/components/Logo.stories.svelte +13 -13
- package/dist/components/Logo.stories.svelte.d.ts +1 -1
- package/dist/components/Logo.svelte +101 -95
- package/dist/components/LogsSidebar.svelte +553 -546
- package/dist/components/LogsSidebar.svelte.d.ts +1 -1
- package/dist/components/MarkdownDisplay.stories.svelte +29 -23
- package/dist/components/MarkdownDisplay.stories.svelte.d.ts +1 -1
- package/dist/components/MarkdownDisplay.svelte +16 -14
- package/dist/components/Navbar.stories.svelte +43 -38
- package/dist/components/Navbar.stories.svelte.d.ts +1 -1
- package/dist/components/Navbar.svelte +760 -706
- package/dist/components/Navbar.svelte.d.ts +1 -1
- package/dist/components/NodeSidebar.svelte +905 -746
- package/dist/components/NodeSidebar.svelte.d.ts +5 -1
- package/dist/components/NodeStatusOverlay.stories.svelte +82 -70
- package/dist/components/NodeStatusOverlay.stories.svelte.d.ts +1 -1
- package/dist/components/NodeStatusOverlay.svelte +295 -280
- package/dist/components/NodeStatusOverlay.svelte.d.ts +3 -3
- package/dist/components/PipelineStatus.svelte +326 -300
- package/dist/components/PipelineStatus.svelte.d.ts +4 -4
- package/dist/components/PortCoordinateTracker.svelte +49 -47
- package/dist/components/PortCoordinateTracker.svelte.d.ts +1 -1
- package/dist/components/ReadOnlyDetails.svelte +156 -156
- package/dist/components/SchemaForm.stories.svelte +106 -98
- package/dist/components/SchemaForm.stories.svelte.d.ts +1 -1
- package/dist/components/SchemaForm.svelte +490 -463
- package/dist/components/SchemaForm.svelte.d.ts +2 -2
- package/dist/components/SettingsModal.svelte +226 -223
- package/dist/components/SettingsModal.svelte.d.ts +1 -1
- package/dist/components/SettingsPanel.svelte +637 -601
- package/dist/components/SettingsPanel.svelte.d.ts +1 -1
- package/dist/components/StatusIcon.stories.svelte +62 -49
- package/dist/components/StatusIcon.stories.svelte.d.ts +1 -1
- package/dist/components/StatusIcon.svelte +87 -87
- package/dist/components/StatusIcon.svelte.d.ts +2 -2
- package/dist/components/StatusLabel.stories.svelte +12 -12
- package/dist/components/StatusLabel.stories.svelte.d.ts +1 -1
- package/dist/components/StatusLabel.svelte +19 -19
- package/dist/components/ThemeToggle.stories.svelte +16 -16
- package/dist/components/ThemeToggle.stories.svelte.d.ts +1 -1
- package/dist/components/ThemeToggle.svelte +180 -169
- package/dist/components/ThemeToggle.svelte.d.ts +1 -1
- package/dist/components/UniversalNode.svelte +150 -138
- package/dist/components/UniversalNode.svelte.d.ts +3 -3
- package/dist/components/WorkflowEditor.svelte +1069 -1014
- package/dist/components/WorkflowEditor.svelte.d.ts +4 -4
- package/dist/components/form/FormArray.svelte +1034 -973
- package/dist/components/form/FormArray.svelte.d.ts +1 -1
- package/dist/components/form/FormAutocomplete.svelte +1021 -978
- package/dist/components/form/FormAutocomplete.svelte.d.ts +1 -1
- package/dist/components/form/FormCheckboxGroup.stories.svelte +23 -20
- package/dist/components/form/FormCheckboxGroup.stories.svelte.d.ts +1 -1
- package/dist/components/form/FormCheckboxGroup.svelte +136 -136
- package/dist/components/form/FormCodeEditor.svelte +452 -434
- package/dist/components/form/FormField.svelte +366 -355
- package/dist/components/form/FormField.svelte.d.ts +2 -2
- package/dist/components/form/FormFieldLight.svelte +400 -384
- package/dist/components/form/FormFieldLight.svelte.d.ts +1 -1
- package/dist/components/form/FormFieldWrapper.stories.svelte +42 -42
- package/dist/components/form/FormFieldWrapper.stories.svelte.d.ts +1 -1
- package/dist/components/form/FormFieldWrapper.svelte +100 -93
- package/dist/components/form/FormFieldWrapper.svelte.d.ts +1 -1
- package/dist/components/form/FormFieldset.svelte +108 -108
- package/dist/components/form/FormFieldset.svelte.d.ts +2 -2
- package/dist/components/form/FormMarkdownEditor.svelte +758 -725
- package/dist/components/form/FormNumberField.stories.svelte +25 -25
- package/dist/components/form/FormNumberField.stories.svelte.d.ts +1 -1
- package/dist/components/form/FormNumberField.svelte +88 -88
- package/dist/components/form/FormRangeField.stories.svelte +20 -20
- package/dist/components/form/FormRangeField.stories.svelte.d.ts +1 -1
- package/dist/components/form/FormRangeField.svelte +234 -226
- package/dist/components/form/FormSelect.stories.svelte +38 -38
- package/dist/components/form/FormSelect.stories.svelte.d.ts +1 -1
- package/dist/components/form/FormSelect.svelte +101 -101
- package/dist/components/form/FormSelect.svelte.d.ts +1 -1
- package/dist/components/form/FormTemplateEditor.svelte +847 -798
- package/dist/components/form/FormTemplateEditor.svelte.d.ts +1 -1
- package/dist/components/form/FormTextField.stories.svelte +29 -23
- package/dist/components/form/FormTextField.stories.svelte.d.ts +1 -1
- package/dist/components/form/FormTextField.svelte +68 -68
- package/dist/components/form/FormTextarea.stories.svelte +28 -25
- package/dist/components/form/FormTextarea.stories.svelte.d.ts +1 -1
- package/dist/components/form/FormTextarea.svelte +74 -74
- package/dist/components/form/FormToggle.stories.svelte +23 -20
- package/dist/components/form/FormToggle.stories.svelte.d.ts +1 -1
- package/dist/components/form/FormToggle.svelte +98 -98
- package/dist/components/form/FormUISchemaRenderer.svelte +120 -113
- package/dist/components/form/FormUISchemaRenderer.svelte.d.ts +3 -3
- package/dist/components/form/index.d.ts +19 -19
- package/dist/components/form/index.js +18 -18
- package/dist/components/form/templateAutocomplete.d.ts +2 -2
- package/dist/components/form/templateAutocomplete.js +64 -55
- package/dist/components/form/types.d.ts +6 -6
- package/dist/components/form/types.js +9 -4
- package/dist/components/icons/AlertCircleIcon.svelte +11 -0
- package/dist/components/icons/AlertCircleIcon.svelte.d.ts +26 -0
- package/dist/components/icons/CogIcon.svelte +11 -0
- package/dist/components/icons/CogIcon.svelte.d.ts +26 -0
- package/dist/components/interrupt/ChoicePrompt.stories.svelte +54 -38
- package/dist/components/interrupt/ChoicePrompt.stories.svelte.d.ts +1 -1
- package/dist/components/interrupt/ChoicePrompt.svelte +407 -383
- package/dist/components/interrupt/ChoicePrompt.svelte.d.ts +1 -1
- package/dist/components/interrupt/ConfirmationPrompt.stories.svelte +48 -48
- package/dist/components/interrupt/ConfirmationPrompt.stories.svelte.d.ts +1 -1
- package/dist/components/interrupt/ConfirmationPrompt.svelte +280 -274
- package/dist/components/interrupt/ConfirmationPrompt.svelte.d.ts +1 -1
- package/dist/components/interrupt/FormPrompt.svelte +223 -218
- package/dist/components/interrupt/FormPrompt.svelte.d.ts +1 -1
- package/dist/components/interrupt/InterruptBubble.svelte +617 -583
- package/dist/components/interrupt/InterruptBubble.svelte.d.ts +2 -2
- package/dist/components/interrupt/ReviewPrompt.stories.svelte +66 -56
- package/dist/components/interrupt/ReviewPrompt.stories.svelte.d.ts +1 -1
- package/dist/components/interrupt/ReviewPrompt.svelte +861 -841
- package/dist/components/interrupt/ReviewPrompt.svelte.d.ts +1 -1
- package/dist/components/interrupt/TextInputPrompt.stories.svelte +38 -33
- package/dist/components/interrupt/TextInputPrompt.stories.svelte.d.ts +1 -1
- package/dist/components/interrupt/TextInputPrompt.svelte +333 -328
- package/dist/components/interrupt/TextInputPrompt.svelte.d.ts +1 -1
- package/dist/components/interrupt/index.d.ts +5 -5
- package/dist/components/interrupt/index.js +5 -5
- package/dist/components/layouts/MainLayout.svelte +724 -691
- package/dist/components/layouts/MainLayout.svelte.d.ts +6 -6
- package/dist/components/nodes/GatewayNode.stories.svelte +100 -99
- package/dist/components/nodes/GatewayNode.svelte +605 -571
- package/dist/components/nodes/GatewayNode.svelte.d.ts +3 -3
- package/dist/components/nodes/IdeaNode.stories.svelte +44 -43
- package/dist/components/nodes/IdeaNode.svelte +451 -437
- package/dist/components/nodes/IdeaNode.svelte.d.ts +1 -1
- package/dist/components/nodes/NotesNode.stories.svelte +65 -64
- package/dist/components/nodes/NotesNode.svelte +380 -369
- package/dist/components/nodes/NotesNode.svelte.d.ts +1 -1
- package/dist/components/nodes/SimpleNode.stories.svelte +145 -144
- package/dist/components/nodes/SimpleNode.svelte +486 -424
- package/dist/components/nodes/SimpleNode.svelte.d.ts +1 -1
- package/dist/components/nodes/SquareNode.stories.svelte +73 -73
- package/dist/components/nodes/SquareNode.svelte +439 -380
- package/dist/components/nodes/SquareNode.svelte.d.ts +1 -1
- package/dist/components/nodes/TerminalNode.stories.svelte +13 -13
- package/dist/components/nodes/TerminalNode.svelte +709 -670
- package/dist/components/nodes/TerminalNode.svelte.d.ts +1 -1
- package/dist/components/nodes/ToolNode.stories.svelte +181 -180
- package/dist/components/nodes/ToolNode.svelte +505 -447
- package/dist/components/nodes/ToolNode.svelte.d.ts +1 -1
- package/dist/components/nodes/WorkflowNode.stories.svelte +70 -46
- package/dist/components/nodes/WorkflowNode.svelte +621 -551
- package/dist/components/nodes/WorkflowNode.svelte.d.ts +3 -3
- package/dist/components/playground/ChatPanel.svelte +945 -889
- package/dist/components/playground/ExecutionLogs.svelte +495 -472
- package/dist/components/playground/InputCollector.svelte +449 -428
- package/dist/components/playground/MessageBubble.stories.svelte +47 -47
- package/dist/components/playground/MessageBubble.stories.svelte.d.ts +1 -1
- package/dist/components/playground/MessageBubble.svelte +626 -610
- package/dist/components/playground/MessageBubble.svelte.d.ts +1 -1
- package/dist/components/playground/Playground.svelte +1088 -1057
- package/dist/components/playground/Playground.svelte.d.ts +3 -3
- package/dist/components/playground/PlaygroundModal.svelte +208 -204
- package/dist/components/playground/PlaygroundModal.svelte.d.ts +3 -3
- package/dist/components/playground/SessionManager.svelte +527 -521
- package/dist/components/playground/SessionManager.svelte.d.ts +1 -1
- package/dist/config/agentSpecEndpoints.d.ts +1 -1
- package/dist/config/agentSpecEndpoints.js +20 -20
- package/dist/config/constants.js +2 -2
- package/dist/config/defaultCategories.d.ts +1 -1
- package/dist/config/defaultCategories.js +86 -86
- package/dist/config/defaultPortConfig.d.ts +1 -1
- package/dist/config/defaultPortConfig.js +144 -144
- package/dist/config/endpoints.d.ts +4 -4
- package/dist/config/endpoints.js +65 -65
- package/dist/config/runtimeConfig.d.ts +2 -2
- package/dist/config/runtimeConfig.js +8 -8
- package/dist/core/index.d.ts +63 -59
- package/dist/core/index.js +35 -33
- package/dist/display/index.d.ts +2 -2
- package/dist/display/index.js +2 -2
- package/dist/editor/index.d.ts +62 -62
- package/dist/editor/index.js +53 -53
- package/dist/form/code.d.ts +5 -5
- package/dist/form/code.js +14 -14
- package/dist/form/fieldRegistry.d.ts +3 -3
- package/dist/form/fieldRegistry.js +11 -9
- package/dist/form/full.d.ts +8 -8
- package/dist/form/full.js +9 -9
- package/dist/form/index.d.ts +18 -18
- package/dist/form/index.js +16 -16
- package/dist/form/markdown.d.ts +4 -4
- package/dist/form/markdown.js +8 -8
- package/dist/helpers/proximityConnect.d.ts +3 -3
- package/dist/helpers/proximityConnect.js +34 -32
- package/dist/helpers/workflowEditorHelper.d.ts +5 -5
- package/dist/helpers/workflowEditorHelper.js +108 -96
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/mocks/app-environment.js +2 -2
- package/dist/mocks/app-forms.js +9 -9
- package/dist/mocks/app-navigation.js +11 -11
- package/dist/mocks/app-stores.js +8 -8
- package/dist/playground/index.d.ts +19 -19
- package/dist/playground/index.js +16 -16
- package/dist/playground/mount.d.ts +3 -3
- package/dist/playground/mount.js +24 -24
- package/dist/registry/builtinFormats.js +13 -13
- package/dist/registry/builtinNodes.d.ts +2 -2
- package/dist/registry/builtinNodes.js +77 -77
- package/dist/registry/index.d.ts +4 -4
- package/dist/registry/index.js +4 -4
- package/dist/registry/nodeComponentRegistry.d.ts +8 -8
- package/dist/registry/nodeComponentRegistry.js +11 -9
- package/dist/registry/plugin.d.ts +2 -2
- package/dist/registry/plugin.js +11 -11
- package/dist/registry/workflowFormatRegistry.d.ts +3 -3
- package/dist/registry/workflowFormatRegistry.js +2 -2
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +2 -2
- package/dist/services/agentSpecExecutionService.d.ts +3 -3
- package/dist/services/agentSpecExecutionService.js +59 -55
- package/dist/services/api.d.ts +2 -2
- package/dist/services/api.js +37 -37
- package/dist/services/apiVariableService.d.ts +1 -1
- package/dist/services/apiVariableService.js +41 -34
- package/dist/services/autoSaveService.js +8 -8
- package/dist/services/categoriesApi.d.ts +2 -2
- package/dist/services/categoriesApi.js +8 -8
- package/dist/services/draftStorage.d.ts +1 -1
- package/dist/services/draftStorage.js +11 -11
- package/dist/services/dynamicSchemaService.d.ts +1 -1
- package/dist/services/dynamicSchemaService.js +41 -39
- package/dist/services/globalSave.d.ts +2 -2
- package/dist/services/globalSave.js +41 -38
- package/dist/services/historyService.d.ts +1 -1
- package/dist/services/historyService.js +8 -8
- package/dist/services/interruptService.d.ts +1 -1
- package/dist/services/interruptService.js +35 -29
- package/dist/services/nodeExecutionService.d.ts +1 -1
- package/dist/services/nodeExecutionService.js +45 -44
- package/dist/services/playgroundService.d.ts +1 -1
- package/dist/services/playgroundService.js +29 -29
- package/dist/services/portConfigApi.d.ts +2 -2
- package/dist/services/portConfigApi.js +8 -8
- package/dist/services/settingsService.d.ts +2 -2
- package/dist/services/settingsService.js +25 -19
- package/dist/services/toastService.d.ts +4 -4
- package/dist/services/toastService.js +33 -33
- package/dist/services/variableService.d.ts +1 -1
- package/dist/services/variableService.js +36 -36
- package/dist/services/workflowStorage.d.ts +2 -2
- package/dist/services/workflowStorage.js +13 -13
- package/dist/settings/index.d.ts +7 -7
- package/dist/settings/index.js +6 -6
- package/dist/skins/default.d.ts +2 -0
- package/dist/skins/default.js +1 -0
- package/dist/skins/index.d.ts +13 -0
- package/dist/skins/index.js +30 -0
- package/dist/skins/slate.d.ts +2 -0
- package/dist/skins/slate.js +78 -0
- package/dist/stores/categoriesStore.svelte.d.ts +1 -1
- package/dist/stores/categoriesStore.svelte.js +5 -5
- package/dist/stores/editorStateMachine.svelte.d.ts +2 -2
- package/dist/stores/editorStateMachine.svelte.js +65 -33
- package/dist/stores/historyStore.svelte.d.ts +4 -4
- package/dist/stores/historyStore.svelte.js +4 -4
- package/dist/stores/interruptStore.svelte.d.ts +3 -3
- package/dist/stores/interruptStore.svelte.js +21 -21
- package/dist/stores/playgroundStore.svelte.d.ts +2 -2
- package/dist/stores/playgroundStore.svelte.js +25 -18
- package/dist/stores/portCoordinateStore.svelte.d.ts +2 -2
- package/dist/stores/portCoordinateStore.svelte.js +15 -8
- package/dist/stores/settingsStore.svelte.d.ts +2 -2
- package/dist/stores/settingsStore.svelte.js +62 -57
- package/dist/stores/workflowStore.svelte.d.ts +3 -3
- package/dist/stores/workflowStore.svelte.js +50 -47
- package/dist/stories/CanvasDecorator.svelte +35 -32
- package/dist/stories/CanvasDecorator.svelte.d.ts +2 -2
- package/dist/stories/EdgeDecorator.svelte +102 -99
- package/dist/stories/EdgeDecorator.svelte.d.ts +1 -1
- package/dist/stories/NodeDecorator.svelte +59 -53
- package/dist/stories/NodeDecorator.svelte.d.ts +1 -1
- package/dist/stories/utils.d.ts +2 -2
- package/dist/stories/utils.js +105 -67
- package/dist/styles/base.css +599 -595
- package/dist/styles/toast.css +14 -14
- package/dist/styles/tokens.css +409 -378
- package/dist/svelte-app.d.ts +12 -9
- package/dist/svelte-app.js +40 -39
- package/dist/themes/default.d.ts +2 -0
- package/dist/themes/default.js +9 -0
- package/dist/themes/index.d.ts +13 -0
- package/dist/themes/index.js +44 -0
- package/dist/themes/minimal.d.ts +2 -0
- package/dist/themes/minimal.js +11 -0
- package/dist/types/agentspec.d.ts +18 -18
- package/dist/types/agentspec.js +2 -2
- package/dist/types/auth.d.ts +1 -1
- package/dist/types/auth.js +6 -6
- package/dist/types/config.d.ts +6 -6
- package/dist/types/events.d.ts +2 -2
- package/dist/types/events.js +2 -2
- package/dist/types/index.d.ts +32 -32
- package/dist/types/index.js +6 -6
- package/dist/types/interrupt.d.ts +6 -6
- package/dist/types/interrupt.js +21 -21
- package/dist/types/interruptState.d.ts +12 -12
- package/dist/types/interruptState.js +66 -66
- package/dist/types/playground.d.ts +7 -7
- package/dist/types/playground.js +14 -14
- package/dist/types/settings.d.ts +5 -3
- package/dist/types/settings.js +25 -18
- package/dist/types/skin.d.ts +31 -0
- package/dist/types/skin.js +1 -0
- package/dist/types/theme.d.ts +35 -0
- package/dist/types/theme.js +1 -0
- package/dist/types/uischema.d.ts +4 -4
- package/dist/types/uischema.js +3 -3
- package/dist/utils/colors.d.ts +1 -1
- package/dist/utils/colors.js +97 -95
- package/dist/utils/config.d.ts +2 -2
- package/dist/utils/config.js +48 -48
- package/dist/utils/connections.d.ts +2 -2
- package/dist/utils/connections.js +15 -15
- package/dist/utils/errors.js +3 -3
- package/dist/utils/fetchWithAuth.d.ts +1 -1
- package/dist/utils/fetchWithAuth.js +2 -2
- package/dist/utils/handleIds.d.ts +2 -2
- package/dist/utils/handleIds.js +8 -8
- package/dist/utils/handlePositioning.d.ts +1 -1
- package/dist/utils/handlePositioning.js +2 -2
- package/dist/utils/icons.d.ts +1 -1
- package/dist/utils/icons.js +74 -74
- package/dist/utils/logger.d.ts +1 -1
- package/dist/utils/logger.js +7 -7
- package/dist/utils/nodeStatus.d.ts +1 -1
- package/dist/utils/nodeStatus.js +48 -48
- package/dist/utils/nodeTypes.d.ts +1 -1
- package/dist/utils/nodeTypes.js +21 -20
- package/dist/utils/nodeWrapper.d.ts +7 -7
- package/dist/utils/nodeWrapper.js +21 -19
- package/dist/utils/performanceUtils.d.ts +1 -1
- package/dist/utils/performanceUtils.js +2 -1
- package/dist/utils/sanitize.js +1 -1
- package/dist/utils/uischema.d.ts +2 -2
- package/dist/utils/uischema.js +8 -8
- package/dist/utils/validation.js +20 -8
- package/package.json +1 -1
|
@@ -21,989 +21,1032 @@
|
|
|
21
21
|
-->
|
|
22
22
|
|
|
23
23
|
<script lang="ts">
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
24
|
+
import { getContext, onMount } from "svelte";
|
|
25
|
+
import Icon from "@iconify/svelte";
|
|
26
|
+
import type { AutocompleteConfig, AuthProvider } from "../../types/index.js";
|
|
27
|
+
import type { FieldOption } from "./types.js";
|
|
28
|
+
import { buildFetchHeaders } from "../../utils/fetchWithAuth.js";
|
|
29
|
+
import { logger } from "../../utils/logger.js";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Props interface for FormAutocomplete component
|
|
33
|
+
*/
|
|
34
|
+
interface Props {
|
|
35
|
+
/** Field identifier */
|
|
36
|
+
id: string;
|
|
37
|
+
/** Current selected value (string for single, string[] for multiple) */
|
|
38
|
+
value: string | string[];
|
|
39
|
+
/** Autocomplete configuration */
|
|
40
|
+
autocomplete: AutocompleteConfig;
|
|
41
|
+
/** Whether the field is required */
|
|
42
|
+
required?: boolean;
|
|
43
|
+
/** Placeholder text */
|
|
44
|
+
placeholder?: string;
|
|
45
|
+
/** Whether the field is disabled */
|
|
46
|
+
disabled?: boolean;
|
|
47
|
+
/** ARIA description ID */
|
|
48
|
+
ariaDescribedBy?: string;
|
|
49
|
+
/** Callback when value changes */
|
|
50
|
+
onChange: (value: string | string[]) => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let {
|
|
54
|
+
id,
|
|
55
|
+
value = "",
|
|
56
|
+
autocomplete,
|
|
57
|
+
required = false,
|
|
58
|
+
placeholder = "",
|
|
59
|
+
disabled = false,
|
|
60
|
+
ariaDescribedBy,
|
|
61
|
+
onChange,
|
|
62
|
+
}: Props = $props();
|
|
63
|
+
|
|
64
|
+
// Get AuthProvider and baseUrl from context via getter functions
|
|
65
|
+
// This pattern ensures we always get the current value, even if props change after mount
|
|
66
|
+
const getAuthProvider = getContext<
|
|
67
|
+
(() => AuthProvider | undefined) | undefined
|
|
68
|
+
>("flowdrop:getAuthProvider");
|
|
69
|
+
const getBaseUrl = getContext<(() => string) | undefined>(
|
|
70
|
+
"flowdrop:getBaseUrl",
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// Configuration with defaults
|
|
74
|
+
const queryParam = $derived(autocomplete.queryParam ?? "q");
|
|
75
|
+
const minChars = $derived(autocomplete.minChars ?? 0);
|
|
76
|
+
const debounceMs = $derived(autocomplete.debounceMs ?? 300);
|
|
77
|
+
const fetchOnFocus = $derived(autocomplete.fetchOnFocus ?? false);
|
|
78
|
+
const labelField = $derived(autocomplete.labelField ?? "label");
|
|
79
|
+
const valueField = $derived(autocomplete.valueField ?? "value");
|
|
80
|
+
const allowFreeText = $derived(autocomplete.allowFreeText ?? false);
|
|
81
|
+
const multiple = $derived(autocomplete.multiple ?? false);
|
|
82
|
+
|
|
83
|
+
// Component state
|
|
84
|
+
let inputElement: HTMLInputElement | undefined = $state(undefined);
|
|
85
|
+
let containerElement: HTMLDivElement | undefined = $state(undefined);
|
|
86
|
+
let popoverElement: HTMLDivElement | undefined = $state(undefined);
|
|
87
|
+
let inputValue = $state("");
|
|
88
|
+
let suggestions = $state<FieldOption[]>([]);
|
|
89
|
+
let isOpen = $state(false);
|
|
90
|
+
let isLoading = $state(false);
|
|
91
|
+
let error = $state<string | null>(null);
|
|
92
|
+
let highlightedIndex = $state(-1);
|
|
93
|
+
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
94
|
+
let abortController: AbortController | null = null;
|
|
95
|
+
|
|
96
|
+
// Popover positioning style
|
|
97
|
+
let popoverStyle = $state("");
|
|
98
|
+
|
|
99
|
+
// Cache of value-to-label mappings for selected items
|
|
100
|
+
let labelCache = $state<Map<string, string>>(new Map());
|
|
101
|
+
|
|
102
|
+
// Generate unique IDs for accessibility
|
|
103
|
+
// svelte-ignore state_referenced_locally — id prop never changes
|
|
104
|
+
const listboxId = `${id}-listbox`;
|
|
105
|
+
// svelte-ignore state_referenced_locally
|
|
106
|
+
const getOptionId = (index: number): string => `${id}-option-${index}`;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get the selected values as an array (normalizes single/multiple)
|
|
110
|
+
*/
|
|
111
|
+
const selectedValues = $derived<string[]>(
|
|
112
|
+
multiple
|
|
113
|
+
? Array.isArray(value)
|
|
114
|
+
? value
|
|
115
|
+
: value
|
|
116
|
+
? [String(value)]
|
|
117
|
+
: []
|
|
118
|
+
: value
|
|
119
|
+
? [String(value)]
|
|
120
|
+
: [],
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Check if a value is selected
|
|
125
|
+
*/
|
|
126
|
+
function isSelected(optionValue: string): boolean {
|
|
127
|
+
return selectedValues.includes(optionValue);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Get display label for a selected value
|
|
132
|
+
*/
|
|
133
|
+
function getDisplayLabel(val: string): string {
|
|
134
|
+
// Check cache first
|
|
135
|
+
if (labelCache.has(val)) {
|
|
136
|
+
return labelCache.get(val) ?? val;
|
|
137
|
+
}
|
|
138
|
+
// Check current suggestions
|
|
139
|
+
const match = suggestions.find((s) => s.value === val);
|
|
140
|
+
if (match) {
|
|
141
|
+
labelCache.set(val, match.label);
|
|
142
|
+
return match.label;
|
|
143
|
+
}
|
|
144
|
+
// Return value as fallback
|
|
145
|
+
return val;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Build the full URL for fetching suggestions
|
|
150
|
+
* @param query - The search query
|
|
151
|
+
* @returns Full URL with query parameter
|
|
152
|
+
*/
|
|
153
|
+
function buildUrl(query: string): string {
|
|
154
|
+
const baseUrl = getBaseUrl?.() ?? "";
|
|
155
|
+
const url = autocomplete.url.startsWith("http")
|
|
156
|
+
? autocomplete.url
|
|
157
|
+
: `${baseUrl}${autocomplete.url}`;
|
|
158
|
+
|
|
159
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
160
|
+
return `${url}${separator}${encodeURIComponent(queryParam)}=${encodeURIComponent(query)}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Map API response to FieldOption array
|
|
165
|
+
* @param data - Response data from API
|
|
166
|
+
* @returns Array of FieldOption objects
|
|
167
|
+
*/
|
|
168
|
+
function mapResponse(data: unknown): FieldOption[] {
|
|
169
|
+
if (!Array.isArray(data)) {
|
|
170
|
+
logger.warn("[FormAutocomplete] Response is not an array:", data);
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return data.map((item: Record<string, unknown>) => ({
|
|
175
|
+
label: String(item[labelField] ?? item[valueField] ?? ""),
|
|
176
|
+
value: String(item[valueField] ?? ""),
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Fetch suggestions from the callback URL
|
|
182
|
+
* @param query - The search query
|
|
183
|
+
*/
|
|
184
|
+
async function fetchSuggestions(query: string): Promise<void> {
|
|
185
|
+
// Cancel any pending request
|
|
186
|
+
if (abortController) {
|
|
187
|
+
abortController.abort();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Check minimum characters requirement
|
|
191
|
+
if (query.length < minChars && query.length > 0) {
|
|
192
|
+
suggestions = [];
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
isLoading = true;
|
|
197
|
+
error = null;
|
|
198
|
+
abortController = new AbortController();
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
// Build headers with authentication (call getter to get current value)
|
|
202
|
+
const headers = await buildFetchHeaders(getAuthProvider?.());
|
|
203
|
+
|
|
204
|
+
// Fetch with timeout
|
|
205
|
+
const timeoutId = setTimeout(() => {
|
|
206
|
+
abortController?.abort();
|
|
207
|
+
}, 5000);
|
|
208
|
+
|
|
209
|
+
const response = await fetch(buildUrl(query), {
|
|
210
|
+
method: "GET",
|
|
211
|
+
headers,
|
|
212
|
+
signal: abortController.signal,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
clearTimeout(timeoutId);
|
|
216
|
+
|
|
217
|
+
if (!response.ok) {
|
|
218
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const data = await response.json();
|
|
222
|
+
const mapped = mapResponse(data);
|
|
223
|
+
|
|
224
|
+
// Update label cache with fetched suggestions
|
|
225
|
+
mapped.forEach((opt) => {
|
|
226
|
+
labelCache.set(opt.value, opt.label);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
suggestions = mapped;
|
|
230
|
+
highlightedIndex = -1;
|
|
231
|
+
} catch (err) {
|
|
232
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
233
|
+
// Request was cancelled, ignore
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
logger.error("[FormAutocomplete] Fetch error:", err);
|
|
237
|
+
error =
|
|
238
|
+
err instanceof Error ? err.message : "Failed to fetch suggestions";
|
|
239
|
+
suggestions = [];
|
|
240
|
+
} finally {
|
|
241
|
+
isLoading = false;
|
|
242
|
+
abortController = null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Debounced fetch for input changes
|
|
248
|
+
* @param query - The search query
|
|
249
|
+
*/
|
|
250
|
+
function debouncedFetch(query: string): void {
|
|
251
|
+
if (debounceTimer) {
|
|
252
|
+
clearTimeout(debounceTimer);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
debounceTimer = setTimeout(() => {
|
|
256
|
+
fetchSuggestions(query);
|
|
257
|
+
}, debounceMs);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Handle input value changes
|
|
262
|
+
* @param event - Input event
|
|
263
|
+
*/
|
|
264
|
+
function handleInput(event: Event): void {
|
|
265
|
+
const target = event.currentTarget as HTMLInputElement;
|
|
266
|
+
inputValue = target.value;
|
|
267
|
+
|
|
268
|
+
// Open dropdown
|
|
269
|
+
showDropdown();
|
|
270
|
+
|
|
271
|
+
// If allowFreeText and single mode, update the value immediately
|
|
272
|
+
if (allowFreeText && !multiple) {
|
|
273
|
+
onChange(inputValue);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Fetch suggestions with debounce
|
|
277
|
+
debouncedFetch(inputValue);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Handle input focus
|
|
282
|
+
*/
|
|
283
|
+
function handleFocus(): void {
|
|
284
|
+
if (fetchOnFocus && suggestions.length === 0 && !isLoading) {
|
|
285
|
+
fetchSuggestions(inputValue);
|
|
286
|
+
}
|
|
287
|
+
showDropdown();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Handle input blur
|
|
292
|
+
* Delayed to allow click events on options to fire first
|
|
293
|
+
*/
|
|
294
|
+
function handleBlur(): void {
|
|
295
|
+
setTimeout(() => {
|
|
296
|
+
hideDropdown();
|
|
297
|
+
|
|
298
|
+
// If not allowFreeText and single mode, validate the input
|
|
299
|
+
if (!allowFreeText && !multiple && inputValue !== "") {
|
|
300
|
+
const currentVal = selectedValues;
|
|
301
|
+
const matchingSuggestion = suggestions.find(
|
|
302
|
+
(s) =>
|
|
303
|
+
s.value === currentVal[0] ||
|
|
304
|
+
s.label.toLowerCase() === inputValue.toLowerCase(),
|
|
305
|
+
);
|
|
306
|
+
if (!matchingSuggestion && currentVal.length === 0) {
|
|
307
|
+
inputValue = "";
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}, 200);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Handle option selection
|
|
315
|
+
* @param option - Selected option
|
|
316
|
+
*/
|
|
317
|
+
function selectOption(option: FieldOption): void {
|
|
318
|
+
// Update label cache
|
|
319
|
+
labelCache.set(option.value, option.label);
|
|
320
|
+
|
|
321
|
+
if (multiple) {
|
|
322
|
+
const current = selectedValues;
|
|
323
|
+
if (current.includes(option.value)) {
|
|
324
|
+
// Remove if already selected
|
|
325
|
+
const newValues = current.filter((v) => v !== option.value);
|
|
326
|
+
onChange(newValues);
|
|
327
|
+
} else {
|
|
328
|
+
// Add to selection
|
|
329
|
+
const newValues = [...current, option.value];
|
|
330
|
+
onChange(newValues);
|
|
331
|
+
}
|
|
332
|
+
// Clear input and keep dropdown open for more selections
|
|
333
|
+
inputValue = "";
|
|
334
|
+
inputElement?.focus();
|
|
335
|
+
} else {
|
|
336
|
+
// Single selection mode
|
|
337
|
+
inputValue = "";
|
|
338
|
+
onChange(option.value);
|
|
339
|
+
hideDropdown();
|
|
340
|
+
}
|
|
341
|
+
highlightedIndex = -1;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Remove a selected tag
|
|
346
|
+
* @param valueToRemove - The value to remove
|
|
347
|
+
*/
|
|
348
|
+
function removeTag(valueToRemove: string): void {
|
|
349
|
+
if (disabled) return;
|
|
350
|
+
|
|
351
|
+
if (multiple) {
|
|
352
|
+
const current = selectedValues;
|
|
353
|
+
const newValues = current.filter((v) => v !== valueToRemove);
|
|
354
|
+
onChange(newValues);
|
|
355
|
+
} else {
|
|
356
|
+
onChange("");
|
|
357
|
+
}
|
|
358
|
+
inputElement?.focus();
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Handle keyboard navigation
|
|
363
|
+
* @param event - Keyboard event
|
|
364
|
+
*/
|
|
365
|
+
function handleKeydown(event: KeyboardEvent): void {
|
|
366
|
+
// Handle backspace to remove last tag in multiple mode
|
|
367
|
+
if (
|
|
368
|
+
event.key === "Backspace" &&
|
|
369
|
+
inputValue === "" &&
|
|
370
|
+
selectedValues.length > 0
|
|
371
|
+
) {
|
|
372
|
+
event.preventDefault();
|
|
373
|
+
const current = selectedValues;
|
|
374
|
+
if (multiple) {
|
|
375
|
+
const newValues = current.slice(0, -1);
|
|
376
|
+
onChange(newValues);
|
|
377
|
+
} else {
|
|
378
|
+
onChange("");
|
|
379
|
+
}
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (!isOpen && event.key !== "ArrowDown" && event.key !== "Enter") {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
switch (event.key) {
|
|
388
|
+
case "ArrowDown":
|
|
389
|
+
event.preventDefault();
|
|
390
|
+
if (!isOpen) {
|
|
391
|
+
showDropdown();
|
|
392
|
+
if (fetchOnFocus && suggestions.length === 0) {
|
|
393
|
+
fetchSuggestions(inputValue);
|
|
394
|
+
}
|
|
395
|
+
} else {
|
|
396
|
+
highlightedIndex = Math.min(
|
|
397
|
+
highlightedIndex + 1,
|
|
398
|
+
suggestions.length - 1,
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
break;
|
|
402
|
+
|
|
403
|
+
case "ArrowUp":
|
|
404
|
+
event.preventDefault();
|
|
405
|
+
highlightedIndex = Math.max(highlightedIndex - 1, -1);
|
|
406
|
+
break;
|
|
407
|
+
|
|
408
|
+
case "Enter":
|
|
409
|
+
event.preventDefault();
|
|
410
|
+
if (highlightedIndex >= 0 && highlightedIndex < suggestions.length) {
|
|
411
|
+
selectOption(suggestions[highlightedIndex]);
|
|
412
|
+
} else if (allowFreeText && inputValue !== "") {
|
|
413
|
+
if (multiple) {
|
|
414
|
+
const current = selectedValues;
|
|
415
|
+
if (!current.includes(inputValue)) {
|
|
416
|
+
onChange([...current, inputValue]);
|
|
417
|
+
}
|
|
418
|
+
inputValue = "";
|
|
419
|
+
} else {
|
|
420
|
+
onChange(inputValue);
|
|
421
|
+
hideDropdown();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
break;
|
|
425
|
+
|
|
426
|
+
case "Escape":
|
|
427
|
+
event.preventDefault();
|
|
428
|
+
hideDropdown();
|
|
429
|
+
highlightedIndex = -1;
|
|
430
|
+
break;
|
|
431
|
+
|
|
432
|
+
case "Tab":
|
|
433
|
+
// Allow tab to close dropdown naturally
|
|
434
|
+
hideDropdown();
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Retry failed fetch
|
|
441
|
+
*/
|
|
442
|
+
function handleRetry(): void {
|
|
443
|
+
error = null;
|
|
444
|
+
fetchSuggestions(inputValue);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Clear all selections
|
|
449
|
+
*/
|
|
450
|
+
function handleClearAll(): void {
|
|
451
|
+
inputValue = "";
|
|
452
|
+
onChange(multiple ? [] : "");
|
|
453
|
+
suggestions = [];
|
|
454
|
+
inputElement?.focus();
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Sync label cache when value prop changes externally
|
|
459
|
+
*/
|
|
460
|
+
$effect(() => {
|
|
461
|
+
// When value changes, try to find labels from suggestions
|
|
462
|
+
const vals = selectedValues;
|
|
463
|
+
vals.forEach((val) => {
|
|
464
|
+
if (!labelCache.has(val)) {
|
|
465
|
+
const match = suggestions.find((s) => s.value === val);
|
|
466
|
+
if (match) {
|
|
467
|
+
labelCache.set(val, match.label);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Calculate popover position relative to viewport
|
|
475
|
+
* Popover API renders in top layer, bypassing all stacking contexts
|
|
476
|
+
*/
|
|
477
|
+
function updatePopoverPosition(): void {
|
|
478
|
+
if (!containerElement) return;
|
|
479
|
+
|
|
480
|
+
const rect = containerElement.getBoundingClientRect();
|
|
481
|
+
const viewportHeight = window.innerHeight;
|
|
482
|
+
const maxDropdownHeight = 240; // 15rem in pixels approximately
|
|
483
|
+
const spaceBelow = viewportHeight - rect.bottom;
|
|
484
|
+
const spaceAbove = rect.top;
|
|
485
|
+
|
|
486
|
+
const left = rect.left;
|
|
487
|
+
const width = rect.width;
|
|
488
|
+
|
|
489
|
+
if (spaceBelow < maxDropdownHeight && spaceAbove > spaceBelow) {
|
|
490
|
+
// Position above the input
|
|
491
|
+
const bottom = viewportHeight - rect.top + 4;
|
|
492
|
+
const maxHeight = Math.min(spaceAbove - 8, maxDropdownHeight);
|
|
493
|
+
popoverStyle = `bottom: ${bottom}px; left: ${left}px; width: ${width}px; max-height: ${maxHeight}px;`;
|
|
494
|
+
} else {
|
|
495
|
+
// Position below the input (default)
|
|
496
|
+
const top = rect.bottom + 4;
|
|
497
|
+
const maxHeight = Math.min(spaceBelow - 8, maxDropdownHeight);
|
|
498
|
+
popoverStyle = `top: ${top}px; left: ${left}px; width: ${width}px; max-height: ${maxHeight}px;`;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Show the popover dropdown
|
|
504
|
+
*/
|
|
505
|
+
function showDropdown(): void {
|
|
506
|
+
if (!popoverElement || disabled) return;
|
|
507
|
+
|
|
508
|
+
updatePopoverPosition();
|
|
509
|
+
|
|
510
|
+
try {
|
|
511
|
+
popoverElement.showPopover();
|
|
512
|
+
isOpen = true;
|
|
513
|
+
} catch {
|
|
514
|
+
// Fallback for browsers without popover support - just set isOpen
|
|
515
|
+
isOpen = true;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Hide the popover dropdown
|
|
521
|
+
*/
|
|
522
|
+
function hideDropdown(): void {
|
|
523
|
+
if (!popoverElement) return;
|
|
524
|
+
|
|
525
|
+
try {
|
|
526
|
+
popoverElement.hidePopover();
|
|
527
|
+
} catch {
|
|
528
|
+
// Fallback for browsers without popover support
|
|
529
|
+
}
|
|
530
|
+
isOpen = false;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Effect to update popover position on scroll/resize when open
|
|
535
|
+
*/
|
|
536
|
+
$effect(() => {
|
|
537
|
+
if (isOpen && containerElement) {
|
|
538
|
+
const handlePositionUpdate = (): void => {
|
|
539
|
+
updatePopoverPosition();
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
window.addEventListener("scroll", handlePositionUpdate, true);
|
|
543
|
+
window.addEventListener("resize", handlePositionUpdate);
|
|
544
|
+
|
|
545
|
+
return () => {
|
|
546
|
+
window.removeEventListener("scroll", handlePositionUpdate, true);
|
|
547
|
+
window.removeEventListener("resize", handlePositionUpdate);
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Cleanup on unmount
|
|
554
|
+
*/
|
|
555
|
+
onMount(() => {
|
|
556
|
+
return () => {
|
|
557
|
+
// Cleanup debounce timer
|
|
558
|
+
if (debounceTimer) {
|
|
559
|
+
clearTimeout(debounceTimer);
|
|
560
|
+
}
|
|
561
|
+
// Cleanup abort controller
|
|
562
|
+
if (abortController) {
|
|
563
|
+
abortController.abort();
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
});
|
|
555
567
|
</script>
|
|
556
568
|
|
|
557
569
|
<div
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
570
|
+
bind:this={containerElement}
|
|
571
|
+
class="form-autocomplete"
|
|
572
|
+
class:form-autocomplete--disabled={disabled}
|
|
573
|
+
class:form-autocomplete--multiple={multiple}
|
|
574
|
+
class:form-autocomplete--has-value={selectedValues.length > 0}
|
|
563
575
|
>
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
576
|
+
<!-- Main input container styled like a textfield/textarea -->
|
|
577
|
+
<div
|
|
578
|
+
class="form-autocomplete__field"
|
|
579
|
+
class:form-autocomplete__field--focused={isOpen}
|
|
580
|
+
onclick={() => inputElement?.focus()}
|
|
581
|
+
onkeydown={() => {}}
|
|
582
|
+
role="presentation"
|
|
583
|
+
>
|
|
584
|
+
<!-- Selected tags -->
|
|
585
|
+
{#if selectedValues.length > 0}
|
|
586
|
+
<div class="form-autocomplete__tags">
|
|
587
|
+
{#each selectedValues as selectedVal (selectedVal)}
|
|
588
|
+
<span class="form-autocomplete__tag">
|
|
589
|
+
<span class="form-autocomplete__tag-label"
|
|
590
|
+
>{getDisplayLabel(selectedVal)}</span
|
|
591
|
+
>
|
|
592
|
+
{#if !disabled}
|
|
593
|
+
<button
|
|
594
|
+
type="button"
|
|
595
|
+
class="form-autocomplete__tag-remove"
|
|
596
|
+
aria-label={`Remove ${getDisplayLabel(selectedVal)}`}
|
|
597
|
+
onclick={(e) => {
|
|
598
|
+
e.stopPropagation();
|
|
599
|
+
removeTag(selectedVal);
|
|
600
|
+
}}
|
|
601
|
+
tabindex={-1}
|
|
602
|
+
>
|
|
603
|
+
<Icon icon="heroicons:x-mark" />
|
|
604
|
+
</button>
|
|
605
|
+
{/if}
|
|
606
|
+
</span>
|
|
607
|
+
{/each}
|
|
608
|
+
</div>
|
|
609
|
+
{/if}
|
|
610
|
+
|
|
611
|
+
<!-- Input area -->
|
|
612
|
+
<div class="form-autocomplete__input-area">
|
|
613
|
+
<input
|
|
614
|
+
bind:this={inputElement}
|
|
615
|
+
type="text"
|
|
616
|
+
{id}
|
|
617
|
+
class="form-autocomplete__input"
|
|
618
|
+
value={inputValue}
|
|
619
|
+
placeholder={selectedValues.length === 0 ? placeholder : ""}
|
|
620
|
+
{disabled}
|
|
621
|
+
aria-required={required}
|
|
622
|
+
aria-describedby={ariaDescribedBy}
|
|
623
|
+
role="combobox"
|
|
624
|
+
aria-expanded={isOpen}
|
|
625
|
+
aria-controls={listboxId}
|
|
626
|
+
aria-activedescendant={highlightedIndex >= 0
|
|
627
|
+
? getOptionId(highlightedIndex)
|
|
628
|
+
: undefined}
|
|
629
|
+
aria-autocomplete="list"
|
|
630
|
+
autocomplete="off"
|
|
631
|
+
oninput={handleInput}
|
|
632
|
+
onfocus={handleFocus}
|
|
633
|
+
onblur={handleBlur}
|
|
634
|
+
onkeydown={handleKeydown}
|
|
635
|
+
/>
|
|
636
|
+
</div>
|
|
637
|
+
|
|
638
|
+
<!-- Status icons -->
|
|
639
|
+
<div class="form-autocomplete__icons">
|
|
640
|
+
{#if isLoading}
|
|
641
|
+
<span
|
|
642
|
+
class="form-autocomplete__spinner"
|
|
643
|
+
aria-label="Loading suggestions"
|
|
644
|
+
>
|
|
645
|
+
<Icon icon="heroicons:arrow-path" />
|
|
646
|
+
</span>
|
|
647
|
+
{:else if selectedValues.length > 0 && !disabled}
|
|
648
|
+
<button
|
|
649
|
+
type="button"
|
|
650
|
+
class="form-autocomplete__clear"
|
|
651
|
+
aria-label="Clear all selections"
|
|
652
|
+
onclick={(e) => {
|
|
653
|
+
e.stopPropagation();
|
|
654
|
+
handleClearAll();
|
|
655
|
+
}}
|
|
656
|
+
tabindex={-1}
|
|
657
|
+
>
|
|
658
|
+
<Icon icon="heroicons:x-mark" />
|
|
659
|
+
</button>
|
|
660
|
+
{:else}
|
|
661
|
+
<span class="form-autocomplete__chevron" aria-hidden="true">
|
|
662
|
+
<Icon icon="heroicons:chevron-down" />
|
|
663
|
+
</span>
|
|
664
|
+
{/if}
|
|
665
|
+
</div>
|
|
666
|
+
</div>
|
|
667
|
+
|
|
668
|
+
<!-- Dropdown popover (uses Popover API to render in top layer, bypassing stacking contexts) -->
|
|
669
|
+
<!-- svelte-ignore a11y_no_static_element_interactions — role="presentation" container; onmousedown prevents focus loss from input -->
|
|
670
|
+
<div
|
|
671
|
+
bind:this={popoverElement}
|
|
672
|
+
id={listboxId}
|
|
673
|
+
class="form-autocomplete__popover"
|
|
674
|
+
popover="manual"
|
|
675
|
+
role="presentation"
|
|
676
|
+
style={popoverStyle}
|
|
677
|
+
onmousedown={(e) => e.preventDefault()}
|
|
678
|
+
>
|
|
679
|
+
<ul
|
|
680
|
+
class="form-autocomplete__listbox"
|
|
681
|
+
role="listbox"
|
|
682
|
+
aria-label="Suggestions"
|
|
683
|
+
>
|
|
684
|
+
{#if isLoading}
|
|
685
|
+
<li
|
|
686
|
+
class="form-autocomplete__status form-autocomplete__status--loading"
|
|
687
|
+
>
|
|
688
|
+
<Icon
|
|
689
|
+
icon="heroicons:arrow-path"
|
|
690
|
+
class="form-autocomplete__status-icon"
|
|
691
|
+
/>
|
|
692
|
+
<span>Loading suggestions...</span>
|
|
693
|
+
</li>
|
|
694
|
+
{:else if error}
|
|
695
|
+
<li class="form-autocomplete__status form-autocomplete__status--error">
|
|
696
|
+
<Icon
|
|
697
|
+
icon="heroicons:exclamation-triangle"
|
|
698
|
+
class="form-autocomplete__status-icon"
|
|
699
|
+
/>
|
|
700
|
+
<span>{error}</span>
|
|
701
|
+
<button
|
|
702
|
+
type="button"
|
|
703
|
+
class="form-autocomplete__retry"
|
|
704
|
+
onclick={handleRetry}
|
|
705
|
+
>
|
|
706
|
+
Retry
|
|
707
|
+
</button>
|
|
708
|
+
</li>
|
|
709
|
+
{:else if suggestions.length === 0}
|
|
710
|
+
<li class="form-autocomplete__status form-autocomplete__status--empty">
|
|
711
|
+
<Icon
|
|
712
|
+
icon="heroicons:magnifying-glass"
|
|
713
|
+
class="form-autocomplete__status-icon"
|
|
714
|
+
/>
|
|
715
|
+
<span>No results found</span>
|
|
716
|
+
</li>
|
|
717
|
+
{:else}
|
|
718
|
+
{#each suggestions as option, index (option.value)}
|
|
719
|
+
<!-- svelte-ignore a11y_click_events_have_key_events — WAI-ARIA combobox: keyboard nav handled on input, not individual options -->
|
|
720
|
+
<li
|
|
721
|
+
id={getOptionId(index)}
|
|
722
|
+
class="form-autocomplete__option"
|
|
723
|
+
class:form-autocomplete__option--highlighted={index ===
|
|
724
|
+
highlightedIndex}
|
|
725
|
+
class:form-autocomplete__option--selected={isSelected(option.value)}
|
|
726
|
+
role="option"
|
|
727
|
+
aria-selected={isSelected(option.value)}
|
|
728
|
+
onmouseenter={() => (highlightedIndex = index)}
|
|
729
|
+
onclick={() => selectOption(option)}
|
|
730
|
+
>
|
|
731
|
+
<span class="form-autocomplete__option-label">{option.label}</span>
|
|
732
|
+
{#if isSelected(option.value)}
|
|
733
|
+
<Icon
|
|
734
|
+
icon="heroicons:check"
|
|
735
|
+
class="form-autocomplete__option-check"
|
|
736
|
+
/>
|
|
737
|
+
{/if}
|
|
738
|
+
</li>
|
|
739
|
+
{/each}
|
|
740
|
+
{/if}
|
|
741
|
+
</ul>
|
|
742
|
+
</div>
|
|
701
743
|
</div>
|
|
702
744
|
|
|
703
745
|
<style>
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
746
|
+
.form-autocomplete {
|
|
747
|
+
position: relative;
|
|
748
|
+
width: 100%;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
.form-autocomplete--disabled {
|
|
752
|
+
opacity: 0.6;
|
|
753
|
+
pointer-events: none;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/* Field container styled like a textfield */
|
|
757
|
+
.form-autocomplete__field {
|
|
758
|
+
display: flex;
|
|
759
|
+
flex-wrap: wrap;
|
|
760
|
+
align-items: flex-start;
|
|
761
|
+
gap: var(--fd-space-3xs);
|
|
762
|
+
min-height: 2.625rem;
|
|
763
|
+
padding: var(--fd-space-3xs) 2.5rem var(--fd-space-3xs) var(--fd-space-md);
|
|
764
|
+
border: 1px solid var(--fd-border);
|
|
765
|
+
border-radius: var(--fd-radius-lg);
|
|
766
|
+
font-size: var(--fd-text-sm);
|
|
767
|
+
font-family: inherit;
|
|
768
|
+
color: var(--fd-foreground);
|
|
769
|
+
background-color: var(--fd-muted);
|
|
770
|
+
transition: all var(--fd-transition-normal);
|
|
771
|
+
box-shadow: var(--fd-shadow-sm);
|
|
772
|
+
cursor: text;
|
|
773
|
+
position: relative;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
.form-autocomplete__field:hover {
|
|
777
|
+
border-color: var(--fd-border-strong);
|
|
778
|
+
background-color: var(--fd-background);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
.form-autocomplete__field--focused {
|
|
782
|
+
border-color: var(--fd-primary);
|
|
783
|
+
background-color: var(--fd-background);
|
|
784
|
+
box-shadow:
|
|
785
|
+
0 0 0 3px rgba(59, 130, 246, 0.12),
|
|
786
|
+
var(--fd-shadow-sm);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
/* Multiple mode - textarea-like styling */
|
|
790
|
+
.form-autocomplete--multiple .form-autocomplete__field {
|
|
791
|
+
min-height: 3rem;
|
|
792
|
+
align-content: flex-start;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/* Tags container */
|
|
796
|
+
.form-autocomplete__tags {
|
|
797
|
+
display: flex;
|
|
798
|
+
flex-wrap: wrap;
|
|
799
|
+
gap: var(--fd-space-3xs);
|
|
800
|
+
align-items: center;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/* Individual tag - selected item chip */
|
|
804
|
+
.form-autocomplete__tag {
|
|
805
|
+
display: inline-flex;
|
|
806
|
+
align-items: center;
|
|
807
|
+
gap: var(--fd-space-3xs);
|
|
808
|
+
padding: var(--fd-space-3xs) var(--fd-space-3xs) var(--fd-space-3xs)
|
|
809
|
+
var(--fd-space-xs);
|
|
810
|
+
background-color: var(--fd-primary-muted);
|
|
811
|
+
border: 1px solid var(--fd-primary-muted);
|
|
812
|
+
border-radius: var(--fd-radius-md);
|
|
813
|
+
font-size: 0.8125rem;
|
|
814
|
+
color: var(--fd-primary-hover);
|
|
815
|
+
line-height: 1.2;
|
|
816
|
+
max-width: 100%;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
.form-autocomplete__tag-label {
|
|
820
|
+
overflow: hidden;
|
|
821
|
+
text-overflow: ellipsis;
|
|
822
|
+
white-space: nowrap;
|
|
823
|
+
max-width: 12rem;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
.form-autocomplete__tag-remove {
|
|
827
|
+
display: flex;
|
|
828
|
+
align-items: center;
|
|
829
|
+
justify-content: center;
|
|
830
|
+
padding: 0.125rem;
|
|
831
|
+
margin-left: 0.125rem;
|
|
832
|
+
border: none;
|
|
833
|
+
border-radius: var(--fd-radius-sm);
|
|
834
|
+
background: transparent;
|
|
835
|
+
color: var(--fd-primary);
|
|
836
|
+
cursor: pointer;
|
|
837
|
+
transition: all var(--fd-transition-fast);
|
|
838
|
+
flex-shrink: 0;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
.form-autocomplete__tag-remove:hover {
|
|
842
|
+
background-color: var(--fd-primary-muted);
|
|
843
|
+
color: var(--fd-primary-hover);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
.form-autocomplete__tag-remove :global(svg) {
|
|
847
|
+
width: 0.875rem;
|
|
848
|
+
height: 0.875rem;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/* Input area */
|
|
852
|
+
.form-autocomplete__input-area {
|
|
853
|
+
flex: 1;
|
|
854
|
+
min-width: 4rem;
|
|
855
|
+
display: flex;
|
|
856
|
+
align-items: center;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
.form-autocomplete__input {
|
|
860
|
+
width: 100%;
|
|
861
|
+
padding: var(--fd-space-3xs) 0;
|
|
862
|
+
border: none;
|
|
863
|
+
outline: none;
|
|
864
|
+
font-size: var(--fd-text-sm);
|
|
865
|
+
font-family: inherit;
|
|
866
|
+
color: var(--fd-foreground);
|
|
867
|
+
background-color: transparent;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
.form-autocomplete__input::placeholder {
|
|
871
|
+
color: var(--fd-muted-foreground);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/* Status icons */
|
|
875
|
+
.form-autocomplete__icons {
|
|
876
|
+
position: absolute;
|
|
877
|
+
right: var(--fd-space-xs);
|
|
878
|
+
top: 0.625rem;
|
|
879
|
+
display: flex;
|
|
880
|
+
align-items: center;
|
|
881
|
+
gap: var(--fd-space-3xs);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
.form-autocomplete__chevron,
|
|
885
|
+
.form-autocomplete__spinner {
|
|
886
|
+
display: flex;
|
|
887
|
+
align-items: center;
|
|
888
|
+
justify-content: center;
|
|
889
|
+
color: var(--fd-muted-foreground);
|
|
890
|
+
pointer-events: none;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
.form-autocomplete__chevron :global(svg),
|
|
894
|
+
.form-autocomplete__spinner :global(svg) {
|
|
895
|
+
width: 1rem;
|
|
896
|
+
height: 1rem;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
.form-autocomplete__spinner {
|
|
900
|
+
animation: autocomplete-spin 1s linear infinite;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
@keyframes autocomplete-spin {
|
|
904
|
+
from {
|
|
905
|
+
transform: rotate(0deg);
|
|
906
|
+
}
|
|
907
|
+
to {
|
|
908
|
+
transform: rotate(360deg);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
.form-autocomplete__clear {
|
|
913
|
+
display: flex;
|
|
914
|
+
align-items: center;
|
|
915
|
+
justify-content: center;
|
|
916
|
+
padding: var(--fd-space-3xs);
|
|
917
|
+
border: none;
|
|
918
|
+
border-radius: var(--fd-radius-sm);
|
|
919
|
+
background: transparent;
|
|
920
|
+
color: var(--fd-muted-foreground);
|
|
921
|
+
cursor: pointer;
|
|
922
|
+
transition: all var(--fd-transition-fast);
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
.form-autocomplete__clear:hover {
|
|
926
|
+
background-color: var(--fd-muted);
|
|
927
|
+
color: var(--fd-foreground);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
.form-autocomplete__clear :global(svg) {
|
|
931
|
+
width: 1rem;
|
|
932
|
+
height: 1rem;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
/* Popover container - renders in top layer via Popover API */
|
|
936
|
+
.form-autocomplete__popover {
|
|
937
|
+
position: fixed;
|
|
938
|
+
margin: 0;
|
|
939
|
+
padding: 0;
|
|
940
|
+
border: none;
|
|
941
|
+
background: transparent;
|
|
942
|
+
overflow: visible;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/* Reset default popover styles */
|
|
946
|
+
.form-autocomplete__popover:popover-open {
|
|
947
|
+
display: block;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/* Dropdown listbox inside popover */
|
|
951
|
+
.form-autocomplete__listbox {
|
|
952
|
+
margin: 0;
|
|
953
|
+
padding: var(--fd-space-3xs);
|
|
954
|
+
list-style: none;
|
|
955
|
+
background-color: var(--fd-background);
|
|
956
|
+
border: 1px solid var(--fd-border);
|
|
957
|
+
border-radius: var(--fd-radius-lg);
|
|
958
|
+
box-shadow: var(--fd-shadow-lg);
|
|
959
|
+
overflow-y: auto;
|
|
960
|
+
max-height: inherit;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
.form-autocomplete__option {
|
|
964
|
+
display: flex;
|
|
965
|
+
align-items: center;
|
|
966
|
+
justify-content: space-between;
|
|
967
|
+
padding: var(--fd-space-xs) var(--fd-space-md);
|
|
968
|
+
border-radius: var(--fd-radius-md);
|
|
969
|
+
cursor: pointer;
|
|
970
|
+
transition: background-color var(--fd-transition-fast);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
.form-autocomplete__option:hover,
|
|
974
|
+
.form-autocomplete__option--highlighted {
|
|
975
|
+
background-color: var(--fd-muted);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
.form-autocomplete__option--selected {
|
|
979
|
+
background-color: var(--fd-primary-muted);
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
.form-autocomplete__option--highlighted.form-autocomplete__option--selected {
|
|
983
|
+
background-color: var(--fd-primary-muted);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
.form-autocomplete__option-label {
|
|
987
|
+
font-size: var(--fd-text-sm);
|
|
988
|
+
color: var(--fd-foreground);
|
|
989
|
+
flex: 1;
|
|
990
|
+
overflow: hidden;
|
|
991
|
+
text-overflow: ellipsis;
|
|
992
|
+
white-space: nowrap;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
.form-autocomplete__option :global(.form-autocomplete__option-check) {
|
|
996
|
+
width: 1rem;
|
|
997
|
+
height: 1rem;
|
|
998
|
+
color: var(--fd-primary);
|
|
999
|
+
flex-shrink: 0;
|
|
1000
|
+
margin-left: var(--fd-space-xs);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/* Status messages */
|
|
1004
|
+
.form-autocomplete__status {
|
|
1005
|
+
display: flex;
|
|
1006
|
+
align-items: center;
|
|
1007
|
+
gap: var(--fd-space-xs);
|
|
1008
|
+
padding: var(--fd-space-md);
|
|
1009
|
+
font-size: var(--fd-text-sm);
|
|
1010
|
+
color: var(--fd-muted-foreground);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
.form-autocomplete__status--loading {
|
|
1014
|
+
color: var(--fd-primary);
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
.form-autocomplete__status--error {
|
|
1018
|
+
color: var(--fd-error);
|
|
1019
|
+
flex-wrap: wrap;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
.form-autocomplete__status--empty {
|
|
1023
|
+
color: var(--fd-muted-foreground);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
.form-autocomplete__status :global(.form-autocomplete__status-icon) {
|
|
1027
|
+
width: 1rem;
|
|
1028
|
+
height: 1rem;
|
|
1029
|
+
flex-shrink: 0;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
.form-autocomplete__status--loading :global(.form-autocomplete__status-icon) {
|
|
1033
|
+
animation: autocomplete-spin 1s linear infinite;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
.form-autocomplete__retry {
|
|
1037
|
+
margin-left: auto;
|
|
1038
|
+
padding: var(--fd-space-3xs) var(--fd-space-xs);
|
|
1039
|
+
border: 1px solid var(--fd-error);
|
|
1040
|
+
border-radius: var(--fd-radius-sm);
|
|
1041
|
+
background-color: transparent;
|
|
1042
|
+
color: var(--fd-error);
|
|
1043
|
+
font-size: var(--fd-text-xs);
|
|
1044
|
+
font-weight: 500;
|
|
1045
|
+
cursor: pointer;
|
|
1046
|
+
transition: all var(--fd-transition-fast);
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
.form-autocomplete__retry:hover {
|
|
1050
|
+
background-color: var(--fd-error-muted);
|
|
1051
|
+
}
|
|
1009
1052
|
</style>
|