-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(AI Transform Node): Support for drag and drop #11276
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
35b4713
support for drag and drop at the end of prompt
michael-radency 9ca133e
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency 634f7f1
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency 23e0308
merge fix
michael-radency 192a507
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency a81376f
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency 4f913fc
onDrop update
michael-radency c8821a6
renamed vars
michael-radency e3c28af
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency 8eae27b
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency e4f0de7
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency e752d21
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency 3151090
split textarea into rows
michael-radency 2140961
lines to rows mapping
michael-radency 47eb92d
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency 3dde184
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency ebdf486
cursor highlight
michael-radency 9548ccd
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency 31da9e7
refactoring
michael-radency 7afadc1
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency d72d6d1
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency 64c534f
row snap position update
michael-radency b816891
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency 679369e
test fix
michael-radency e89e25f
refactoring
michael-radency 6cf7309
renamed vars
michael-radency b26ccb0
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1863…
michael-radency File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,18 @@ import { N8nButton, N8nInput, N8nTooltip } from 'n8n-design-system/components'; | |
import { useI18n } from '@/composables/useI18n'; | ||
import { useToast } from '@/composables/useToast'; | ||
import { useNDVStore } from '@/stores/ndv.store'; | ||
import { getParentNodes, generateCodeForAiTransform } from './utils'; | ||
import { | ||
getParentNodes, | ||
generateCodeForAiTransform, | ||
type TextareaRowData, | ||
getUpdatedTextareaValue, | ||
getTextareaCursorPosition, | ||
} from './utils'; | ||
import { useTelemetry } from '@/composables/useTelemetry'; | ||
import { useUIStore } from '@/stores/ui.store'; | ||
|
||
import { propertyNameFromExpression } from '../../utils/mappingUtils'; | ||
|
||
const AI_TRANSFORM_CODE_GENERATED_FOR_PROMPT = 'codeGeneratedForPrompt'; | ||
|
||
const emit = defineEmits<{ | ||
|
@@ -29,6 +37,7 @@ const i18n = useI18n(); | |
const isLoading = ref(false); | ||
const prompt = ref(props.value); | ||
const parentNodes = ref<INodeUi[]>([]); | ||
const textareaRowsData = ref<TextareaRowData | null>(null); | ||
|
||
const hasExecutionData = computed(() => (useNDVStore().ndvInputData || []).length > 0); | ||
const hasInputField = computed(() => props.parameter.typeOptions?.buttonConfig?.hasInputField); | ||
|
@@ -159,6 +168,37 @@ function useDarkBackdrop(): string { | |
onMounted(() => { | ||
parentNodes.value = getParentNodes(); | ||
}); | ||
|
||
function cleanTextareaRowsData() { | ||
textareaRowsData.value = null; | ||
} | ||
|
||
async function onDrop(value: string, event: MouseEvent) { | ||
value = propertyNameFromExpression(value); | ||
|
||
prompt.value = getUpdatedTextareaValue(event, textareaRowsData.value, value); | ||
|
||
emit('valueChanged', { | ||
name: getPath(props.parameter.name), | ||
value: prompt.value, | ||
}); | ||
} | ||
|
||
async function updateCursorPositionOnMouseMove(event: MouseEvent, activeDrop: boolean) { | ||
if (!activeDrop) return; | ||
|
||
const textarea = event.target as HTMLTextAreaElement; | ||
|
||
const position = getTextareaCursorPosition( | ||
textarea, | ||
textareaRowsData.value, | ||
event.clientX, | ||
event.clientY, | ||
); | ||
|
||
textarea.focus(); | ||
textarea.setSelectionRange(position, position); | ||
} | ||
</script> | ||
|
||
<template> | ||
|
@@ -186,16 +226,25 @@ onMounted(() => { | |
v-text="'Instructions changed'" | ||
/> | ||
</div> | ||
<N8nInput | ||
v-model="prompt" | ||
:class="$style.input" | ||
style="border: 1px solid var(--color-foreground-base)" | ||
type="textarea" | ||
:rows="6" | ||
:maxlength="inputFieldMaxLength" | ||
:placeholder="parameter.placeholder" | ||
@input="onPromptInput" | ||
/> | ||
<DraggableTarget type="mapping" :disabled="isLoading" @drop="onDrop"> | ||
<template #default="{ activeDrop, droppable }"> | ||
<N8nInput | ||
v-model="prompt" | ||
:class="[ | ||
$style.input, | ||
{ [$style.activeDrop]: activeDrop, [$style.droppable]: droppable }, | ||
]" | ||
style="border: 1.5px solid var(--color-foreground-base)" | ||
type="textarea" | ||
:rows="6" | ||
:maxlength="inputFieldMaxLength" | ||
:placeholder="parameter.placeholder" | ||
@input="onPromptInput" | ||
@mousemove="updateCursorPositionOnMouseMove($event, activeDrop)" | ||
@mouseleave="cleanTextareaRowsData" | ||
/> | ||
</template> | ||
</DraggableTarget> | ||
</div> | ||
<div :class="$style.controls"> | ||
<N8nTooltip :disabled="isSubmitEnabled"> | ||
|
@@ -227,7 +276,7 @@ onMounted(() => { | |
|
||
<style module lang="scss"> | ||
.input * { | ||
border: 0 !important; | ||
border: 1.5px transparent !important; | ||
} | ||
.input textarea { | ||
font-size: var(--font-size-2xs); | ||
|
@@ -277,4 +326,11 @@ onMounted(() => { | |
color: var(--color-warning); | ||
line-height: 1.2; | ||
} | ||
.droppable { | ||
border: 1.5px dashed var(--color-ndv-droppable-parameter) !important; | ||
} | ||
.activeDrop { | ||
border: 1.5px solid var(--color-success) !important; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be done without !important ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, we need to override defaults of N8nInput(ElInput) |
||
cursor: grabbing; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be done without !important ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, we need to override defaults of N8nInput(ElInput)