2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
2021-10-27 12:55:37 -07:00
|
|
|
<n8n-input-label
|
2024-03-29 08:01:32 -07:00
|
|
|
:class="[$style.wrapper, { [$style.tipVisible]: showDragnDropTip }]"
|
2023-07-28 00:51:07 -07:00
|
|
|
:label="hideLabel ? '' : i18n.nodeText().inputLabelDisplayName(parameter, path)"
|
2023-12-28 00:49:58 -08:00
|
|
|
:tooltip-text="hideLabel ? '' : i18n.nodeText().inputLabelDescription(parameter, path)"
|
|
|
|
:show-tooltip="focused"
|
|
|
|
:show-options="menuExpanded || focused || forceShowExpression"
|
|
|
|
:options-position="optionsPosition"
|
2021-10-27 12:55:37 -07:00
|
|
|
:bold="false"
|
2023-01-20 08:07:28 -08:00
|
|
|
:size="label.size"
|
2022-10-12 05:06:28 -07:00
|
|
|
color="text-dark"
|
2021-10-27 12:55:37 -07:00
|
|
|
>
|
2023-12-13 05:45:22 -08:00
|
|
|
<template v-if="displayOptions && optionsPosition === 'top'" #options>
|
2023-12-28 00:49:58 -08:00
|
|
|
<ParameterOptions
|
2022-07-20 04:32:51 -07:00
|
|
|
:parameter="parameter"
|
|
|
|
:value="value"
|
2023-12-28 00:49:58 -08:00
|
|
|
:is-read-only="isReadOnly"
|
|
|
|
:show-options="displayOptions"
|
|
|
|
:show-expression-selector="showExpressionSelector"
|
2024-03-26 06:22:57 -07:00
|
|
|
@update:model-value="optionSelected"
|
2022-07-20 04:32:51 -07:00
|
|
|
@menu-expanded="onMenuExpanded"
|
|
|
|
/>
|
|
|
|
</template>
|
2023-12-28 00:49:58 -08:00
|
|
|
<DraggableTarget
|
2023-07-28 00:51:07 -07:00
|
|
|
type="mapping"
|
|
|
|
:disabled="isDropDisabled"
|
|
|
|
:sticky="true"
|
2024-06-18 06:04:08 -07:00
|
|
|
:sticky-offset="isExpression ? [26, 3] : [3, 3]"
|
2023-07-28 00:51:07 -07:00
|
|
|
@drop="onDrop"
|
|
|
|
>
|
|
|
|
<template #default="{ droppable, activeDrop }">
|
2024-03-13 04:57:08 -07:00
|
|
|
<ParameterInputWrapper
|
|
|
|
ref="param"
|
|
|
|
:parameter="parameter"
|
|
|
|
:model-value="value"
|
|
|
|
:path="path"
|
|
|
|
:is-read-only="isReadOnly"
|
|
|
|
:is-assignment="isAssignment"
|
|
|
|
:rows="rows"
|
|
|
|
:droppable="droppable"
|
|
|
|
:active-drop="activeDrop"
|
|
|
|
:force-show-expression="forceShowExpression"
|
|
|
|
:hint="hint"
|
|
|
|
:hide-hint="hideHint"
|
|
|
|
:hide-issues="hideIssues"
|
|
|
|
:label="label"
|
|
|
|
:event-bus="eventBus"
|
|
|
|
input-size="small"
|
|
|
|
@update="valueChanged"
|
2024-03-26 06:22:57 -07:00
|
|
|
@text-input="onTextInput"
|
2024-03-13 04:57:08 -07:00
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
|
|
|
@drop="onDrop"
|
|
|
|
/>
|
2023-07-28 00:51:07 -07:00
|
|
|
</template>
|
2023-12-28 00:49:58 -08:00
|
|
|
</DraggableTarget>
|
2024-03-13 04:57:08 -07:00
|
|
|
<div v-if="showDragnDropTip" :class="$style.tip">
|
2024-03-26 07:23:30 -07:00
|
|
|
<InlineExpressionTip />
|
2024-03-13 04:57:08 -07:00
|
|
|
</div>
|
2023-12-13 05:45:22 -08:00
|
|
|
<div
|
|
|
|
:class="{
|
|
|
|
[$style.options]: true,
|
|
|
|
[$style.visible]: menuExpanded || focused || forceShowExpression,
|
|
|
|
}"
|
|
|
|
>
|
2023-12-28 00:49:58 -08:00
|
|
|
<ParameterOptions
|
2023-12-13 05:45:22 -08:00
|
|
|
v-if="optionsPosition === 'bottom'"
|
|
|
|
:parameter="parameter"
|
|
|
|
:value="value"
|
2023-12-28 00:49:58 -08:00
|
|
|
:is-read-only="isReadOnly"
|
|
|
|
:show-options="displayOptions"
|
|
|
|
:show-expression-selector="showExpressionSelector"
|
2024-03-26 06:22:57 -07:00
|
|
|
@update:model-value="optionSelected"
|
2023-12-13 05:45:22 -08:00
|
|
|
@menu-expanded="onMenuExpanded"
|
|
|
|
/>
|
|
|
|
</div>
|
2021-10-27 12:55:37 -07:00
|
|
|
</n8n-input-label>
|
2019-06-23 03:35:23 -07:00
|
|
|
</template>
|
|
|
|
|
2024-06-18 06:04:08 -07:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { computed, ref } from 'vue';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2024-06-18 06:04:08 -07:00
|
|
|
import type { IUpdateInformation } from '@/Interface';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2022-07-20 04:32:51 -07:00
|
|
|
import DraggableTarget from '@/components/DraggableTarget.vue';
|
2024-06-18 06:04:08 -07:00
|
|
|
import ParameterInputWrapper from '@/components/ParameterInputWrapper.vue';
|
|
|
|
import ParameterOptions from '@/components/ParameterOptions.vue';
|
2023-11-28 03:15:08 -08:00
|
|
|
import { useI18n } from '@/composables/useI18n';
|
|
|
|
import { useToast } from '@/composables/useToast';
|
2023-05-05 01:41:54 -07:00
|
|
|
import { useNDVStore } from '@/stores/ndv.store';
|
2023-05-15 09:41:13 -07:00
|
|
|
import { getMappedResult } from '@/utils/mappingUtils';
|
2024-06-18 06:04:08 -07:00
|
|
|
import { hasExpressionMapping, hasOnlyListMode, isValueExpression } from '@/utils/nodeTypesUtils';
|
|
|
|
import { isResourceLocatorValue } from '@/utils/typeGuards';
|
2023-06-20 03:00:53 -07:00
|
|
|
import { createEventBus } from 'n8n-design-system/utils';
|
2024-06-18 06:04:08 -07:00
|
|
|
import type { INodeProperties, IParameterLabel, NodeParameterValueType } from 'n8n-workflow';
|
2024-03-13 04:57:08 -07:00
|
|
|
import InlineExpressionTip from './InlineExpressionEditor/InlineExpressionTip.vue';
|
2023-03-17 05:24:08 -07:00
|
|
|
|
2024-06-18 06:04:08 -07:00
|
|
|
type Props = {
|
|
|
|
parameter: INodeProperties;
|
|
|
|
path: string;
|
|
|
|
value: NodeParameterValueType;
|
|
|
|
label?: IParameterLabel;
|
|
|
|
displayOptions?: boolean;
|
|
|
|
optionsPosition?: 'bottom' | 'top';
|
|
|
|
hideHint?: boolean;
|
|
|
|
isReadOnly?: boolean;
|
|
|
|
rows?: number;
|
|
|
|
isAssignment?: boolean;
|
|
|
|
hideLabel?: boolean;
|
|
|
|
hideIssues?: boolean;
|
|
|
|
entryIndex?: number;
|
|
|
|
};
|
2023-12-28 00:49:58 -08:00
|
|
|
|
2024-06-18 06:04:08 -07:00
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
optionsPosition: 'top',
|
|
|
|
hideHint: false,
|
|
|
|
isReadOnly: false,
|
|
|
|
rows: 5,
|
|
|
|
hideLabel: false,
|
|
|
|
hideIssues: false,
|
|
|
|
label: () => ({ size: 'small' }),
|
|
|
|
});
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(event: 'blur'): void;
|
|
|
|
(event: 'update', value: IUpdateInformation): void;
|
|
|
|
}>();
|
2023-03-02 04:02:29 -08:00
|
|
|
|
2024-06-18 06:04:08 -07:00
|
|
|
const i18n = useI18n();
|
|
|
|
const toast = useToast();
|
2022-09-21 06:44:45 -07:00
|
|
|
|
2024-06-18 06:04:08 -07:00
|
|
|
const eventBus = ref(createEventBus());
|
|
|
|
const focused = ref(false);
|
|
|
|
const menuExpanded = ref(false);
|
|
|
|
const forceShowExpression = ref(false);
|
2022-07-20 04:32:51 -07:00
|
|
|
|
2024-06-18 06:04:08 -07:00
|
|
|
const ndvStore = useNDVStore();
|
2022-07-20 04:32:51 -07:00
|
|
|
|
2024-06-18 06:04:08 -07:00
|
|
|
const node = computed(() => ndvStore.activeNode);
|
|
|
|
const hint = computed(() => i18n.nodeText().hint(props.parameter, props.path));
|
|
|
|
const isInputTypeString = computed(() => props.parameter.type === 'string');
|
|
|
|
const isInputTypeNumber = computed(() => props.parameter.type === 'number');
|
|
|
|
const isResourceLocator = computed(() => props.parameter.type === 'resourceLocator');
|
|
|
|
const isDropDisabled = computed(
|
|
|
|
() => props.parameter.noDataExpression || props.isReadOnly || isResourceLocator.value,
|
|
|
|
);
|
|
|
|
const isExpression = computed(() => isValueExpression(props.parameter, props.value));
|
|
|
|
const showExpressionSelector = computed(() =>
|
|
|
|
isResourceLocator.value ? !hasOnlyListMode(props.parameter) : true,
|
|
|
|
);
|
|
|
|
const isInputDataEmpty = computed(() => ndvStore.isNDVDataEmpty('input'));
|
|
|
|
const showDragnDropTip = computed(
|
|
|
|
() =>
|
|
|
|
focused.value &&
|
|
|
|
(isInputTypeString.value || isInputTypeNumber.value) &&
|
|
|
|
!isExpression.value &&
|
|
|
|
!isDropDisabled.value &&
|
|
|
|
(!ndvStore.hasInputData || !isInputDataEmpty.value) &&
|
|
|
|
!ndvStore.isMappingOnboarded &&
|
|
|
|
ndvStore.isInputParentOfActiveNode,
|
|
|
|
);
|
2022-12-14 01:04:10 -08:00
|
|
|
|
2024-06-18 06:04:08 -07:00
|
|
|
function onFocus() {
|
|
|
|
focused.value = true;
|
|
|
|
if (!props.parameter.noDataExpression) {
|
|
|
|
ndvStore.setMappableNDVInputFocus(props.parameter.displayName);
|
|
|
|
}
|
|
|
|
ndvStore.setFocusedInputPath(props.path ?? '');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onBlur() {
|
|
|
|
focused.value = false;
|
|
|
|
if (
|
|
|
|
!props.parameter.noDataExpression &&
|
|
|
|
ndvStore.focusedMappableInput === props.parameter.displayName
|
|
|
|
) {
|
|
|
|
ndvStore.setMappableNDVInputFocus('');
|
|
|
|
}
|
|
|
|
ndvStore.setFocusedInputPath('');
|
|
|
|
emit('blur');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuExpanded(expanded: boolean) {
|
|
|
|
menuExpanded.value = expanded;
|
|
|
|
}
|
|
|
|
|
|
|
|
function optionSelected(command: string) {
|
|
|
|
eventBus.value.emit('optionSelected', command);
|
|
|
|
}
|
2022-12-14 01:04:10 -08:00
|
|
|
|
2024-06-18 06:04:08 -07:00
|
|
|
function valueChanged(parameterData: IUpdateInformation) {
|
|
|
|
emit('update', parameterData);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTextInput(parameterData: IUpdateInformation) {
|
|
|
|
if (isValueExpression(props.parameter, parameterData.value)) {
|
|
|
|
eventBus.value.emit('optionSelected', 'addExpression');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDrop(newParamValue: string) {
|
|
|
|
const value = props.value;
|
|
|
|
const updatedValue = getMappedResult(props.parameter, newParamValue, value);
|
|
|
|
const prevValue = isResourceLocator.value && isResourceLocatorValue(value) ? value.value : value;
|
|
|
|
|
|
|
|
if (updatedValue.startsWith('=')) {
|
|
|
|
forceShowExpression.value = true;
|
|
|
|
}
|
|
|
|
setTimeout(() => {
|
|
|
|
if (node.value) {
|
|
|
|
let parameterData;
|
|
|
|
if (isResourceLocator.value) {
|
|
|
|
if (!isResourceLocatorValue(props.value)) {
|
|
|
|
parameterData = {
|
|
|
|
node: node.value.name,
|
|
|
|
name: props.path,
|
|
|
|
value: { __rl: true, value: updatedValue, mode: '' },
|
|
|
|
};
|
|
|
|
} else if (
|
|
|
|
props.value.mode === 'list' &&
|
|
|
|
props.parameter.modes &&
|
|
|
|
props.parameter.modes.length > 1
|
|
|
|
) {
|
|
|
|
let mode = props.parameter.modes.find((m) => m.name === 'id') ?? null;
|
|
|
|
if (!mode) {
|
|
|
|
mode = props.parameter.modes.filter((m) => m.name !== 'list')[0];
|
|
|
|
}
|
2023-02-21 05:34:39 -08:00
|
|
|
|
2024-06-18 06:04:08 -07:00
|
|
|
parameterData = {
|
|
|
|
node: node.value.name,
|
|
|
|
name: props.path,
|
|
|
|
value: { __rl: true, value: updatedValue, mode: mode ? mode.name : '' },
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
parameterData = {
|
|
|
|
node: node.value.name,
|
|
|
|
name: props.path,
|
|
|
|
value: { __rl: true, value: updatedValue, mode: props.value?.mode },
|
|
|
|
};
|
2022-10-06 06:03:55 -07:00
|
|
|
}
|
2024-06-18 06:04:08 -07:00
|
|
|
} else {
|
|
|
|
parameterData = {
|
|
|
|
node: node.value.name,
|
|
|
|
name: props.path,
|
|
|
|
value: updatedValue,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
valueChanged(parameterData);
|
|
|
|
eventBus.value.emit('drop', updatedValue);
|
|
|
|
|
|
|
|
if (!ndvStore.isMappingOnboarded) {
|
|
|
|
toast.showMessage({
|
|
|
|
title: i18n.baseText('dataMapping.success.title'),
|
|
|
|
message: i18n.baseText('dataMapping.success.moreInfo'),
|
|
|
|
type: 'success',
|
|
|
|
dangerouslyUseHTMLString: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
ndvStore.setMappingOnboarded();
|
|
|
|
}
|
|
|
|
|
|
|
|
ndvStore.setMappingTelemetry({
|
|
|
|
dest_node_type: node.value.type,
|
|
|
|
dest_parameter: props.path,
|
|
|
|
dest_parameter_mode:
|
|
|
|
typeof prevValue === 'string' && prevValue.startsWith('=') ? 'expression' : 'fixed',
|
|
|
|
dest_parameter_empty: prevValue === '' || prevValue === undefined,
|
|
|
|
dest_parameter_had_mapping:
|
|
|
|
typeof prevValue === 'string' &&
|
|
|
|
prevValue.startsWith('=') &&
|
|
|
|
hasExpressionMapping(prevValue),
|
|
|
|
success: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
forceShowExpression.value = false;
|
|
|
|
}, 200);
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
</script>
|
2023-12-13 05:45:22 -08:00
|
|
|
|
2024-03-13 04:57:08 -07:00
|
|
|
<style lang="scss" module>
|
2023-12-13 05:45:22 -08:00
|
|
|
.wrapper {
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
.options {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-13 04:57:08 -07:00
|
|
|
|
2024-03-29 08:01:32 -07:00
|
|
|
.tipVisible {
|
|
|
|
--input-border-bottom-left-radius: 0;
|
|
|
|
--input-border-bottom-right-radius: 0;
|
|
|
|
}
|
|
|
|
|
2024-03-13 04:57:08 -07:00
|
|
|
.tip {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 2;
|
|
|
|
top: 100%;
|
|
|
|
background: var(--color-code-background);
|
|
|
|
border: var(--border-base);
|
|
|
|
border-top: none;
|
|
|
|
width: 100%;
|
|
|
|
box-shadow: 0 2px 6px 0 rgba(#441c17, 0.1);
|
|
|
|
border-bottom-left-radius: 4px;
|
|
|
|
border-bottom-right-radius: 4px;
|
|
|
|
}
|
|
|
|
|
2023-12-13 05:45:22 -08:00
|
|
|
.options {
|
|
|
|
position: absolute;
|
|
|
|
bottom: -22px;
|
|
|
|
right: 0;
|
2024-02-06 09:34:34 -08:00
|
|
|
z-index: 1;
|
2023-12-13 05:45:22 -08:00
|
|
|
opacity: 0;
|
|
|
|
transition: opacity 100ms ease-in;
|
|
|
|
|
|
|
|
&.visible {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|