2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
2022-08-01 13:35:45 -07:00
|
|
|
<n8n-node-icon
|
|
|
|
:type="type"
|
|
|
|
:src="iconSource.path || iconSource.fileBuffer"
|
|
|
|
:name="iconSource.icon"
|
|
|
|
:color="color"
|
|
|
|
:disabled="disabled"
|
|
|
|
:size="size"
|
|
|
|
:circle="circle"
|
2023-12-28 00:49:58 -08:00
|
|
|
:node-type-name="nodeName ?? nodeType?.displayName ?? ''"
|
|
|
|
:show-tooltip="showTooltip"
|
|
|
|
:tooltip-position="tooltipPosition"
|
2023-11-13 03:11:16 -08:00
|
|
|
:badge="badge"
|
2022-08-01 13:35:45 -07:00
|
|
|
@click="(e) => $emit('click')"
|
|
|
|
></n8n-node-icon>
|
2019-06-23 03:35:23 -07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { IVersionNode } from '@/Interface';
|
2023-05-05 01:41:54 -07:00
|
|
|
import { useRootStore } from '@/stores/n8nRoot.store';
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { INodeTypeDescription } from 'n8n-workflow';
|
2022-11-04 06:04:31 -07:00
|
|
|
import { mapStores } from 'pinia';
|
2023-11-13 03:11:16 -08:00
|
|
|
import { defineComponent, type PropType } from 'vue';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2022-08-01 13:35:45 -07:00
|
|
|
interface NodeIconSource {
|
|
|
|
path?: string;
|
|
|
|
fileBuffer?: string;
|
|
|
|
icon?: string;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
2023-04-21 08:51:08 -07:00
|
|
|
export default defineComponent({
|
2019-06-23 03:35:23 -07:00
|
|
|
name: 'NodeIcon',
|
2021-11-19 01:17:13 -08:00
|
|
|
props: {
|
2023-11-13 03:11:16 -08:00
|
|
|
nodeType: {
|
|
|
|
type: Object as PropType<INodeTypeDescription | IVersionNode | null>,
|
|
|
|
},
|
2021-11-19 01:17:13 -08:00
|
|
|
size: {
|
|
|
|
type: Number,
|
2022-08-01 13:35:45 -07:00
|
|
|
required: false,
|
2021-11-19 01:17:13 -08:00
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
circle: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2023-10-02 08:33:43 -07:00
|
|
|
colorDefault: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
},
|
2022-08-01 13:35:45 -07:00
|
|
|
showTooltip: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2023-11-28 07:47:28 -08:00
|
|
|
tooltipPosition: {
|
|
|
|
type: String,
|
|
|
|
default: 'top',
|
|
|
|
},
|
|
|
|
nodeName: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
},
|
2021-11-19 01:17:13 -08:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
computed: {
|
2022-11-04 06:04:31 -07:00
|
|
|
...mapStores(useRootStore),
|
2022-08-01 13:35:45 -07:00
|
|
|
type(): string {
|
2023-11-13 03:11:16 -08:00
|
|
|
const nodeType = this.nodeType;
|
2022-08-01 13:35:45 -07:00
|
|
|
let iconType = 'unknown';
|
|
|
|
if (nodeType) {
|
2022-11-23 07:20:28 -08:00
|
|
|
if (nodeType.iconUrl) return 'file';
|
2022-08-01 13:35:45 -07:00
|
|
|
if ((nodeType as IVersionNode).iconData) {
|
|
|
|
iconType = (nodeType as IVersionNode).iconData.type;
|
|
|
|
} else if (nodeType.icon) {
|
|
|
|
iconType = nodeType.icon.split(':')[0] === 'file' ? 'file' : 'icon';
|
|
|
|
}
|
2019-07-25 09:50:45 -07:00
|
|
|
}
|
2022-08-01 13:35:45 -07:00
|
|
|
return iconType;
|
2019-07-25 09:50:45 -07:00
|
|
|
},
|
2022-08-01 13:35:45 -07:00
|
|
|
color(): string {
|
2023-11-13 03:11:16 -08:00
|
|
|
const nodeType = this.nodeType;
|
|
|
|
if (nodeType?.defaults?.color) {
|
2022-08-01 13:35:45 -07:00
|
|
|
return nodeType.defaults.color.toString();
|
2020-10-03 05:10:08 -07:00
|
|
|
}
|
2023-10-02 08:33:43 -07:00
|
|
|
if (this.colorDefault) {
|
|
|
|
return this.colorDefault;
|
|
|
|
}
|
2022-08-01 13:35:45 -07:00
|
|
|
return '';
|
2020-10-03 05:10:08 -07:00
|
|
|
},
|
2022-08-01 13:35:45 -07:00
|
|
|
iconSource(): NodeIconSource {
|
2023-11-13 03:11:16 -08:00
|
|
|
const nodeType = this.nodeType;
|
2022-11-23 07:20:28 -08:00
|
|
|
const baseUrl = this.rootStore.getBaseUrl;
|
2022-08-01 13:35:45 -07:00
|
|
|
const iconSource = {} as NodeIconSource;
|
|
|
|
|
|
|
|
if (nodeType) {
|
|
|
|
// If node type has icon data, use it
|
|
|
|
if ((nodeType as IVersionNode).iconData) {
|
|
|
|
return {
|
|
|
|
icon: (nodeType as IVersionNode).iconData.icon,
|
|
|
|
fileBuffer: (nodeType as IVersionNode).iconData.fileBuffer,
|
|
|
|
};
|
|
|
|
}
|
2022-11-23 07:20:28 -08:00
|
|
|
if (nodeType.iconUrl) {
|
|
|
|
return { path: baseUrl + nodeType.iconUrl };
|
|
|
|
}
|
2022-08-01 13:35:45 -07:00
|
|
|
// Otherwise, extract it from icon prop
|
|
|
|
if (nodeType.icon) {
|
2022-09-23 07:14:28 -07:00
|
|
|
const [type, path] = nodeType.icon.split(':');
|
2022-08-01 13:35:45 -07:00
|
|
|
if (type === 'file') {
|
2022-11-23 07:20:28 -08:00
|
|
|
throw new Error(`Unexpected icon: ${nodeType.icon}`);
|
2022-08-01 13:35:45 -07:00
|
|
|
} else {
|
|
|
|
iconSource.icon = path;
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
}
|
2022-08-01 13:35:45 -07:00
|
|
|
return iconSource;
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2023-11-13 03:11:16 -08:00
|
|
|
badge(): { src: string; type: string } | undefined {
|
|
|
|
const nodeType = this.nodeType as INodeTypeDescription;
|
|
|
|
if (nodeType && 'badgeIconUrl' in nodeType && nodeType.badgeIconUrl) {
|
|
|
|
return { type: 'file', src: this.rootStore.getBaseUrl + nodeType.badgeIconUrl };
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss"></style>
|