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"
|
|
|
|
:nodeTypeName="nodeType ? nodeType.displayName : ''"
|
|
|
|
:showTooltip="showTooltip"
|
|
|
|
@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-04-21 08:51:08 -07:00
|
|
|
import { defineComponent } from 'vue';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2022-08-01 13:35:45 -07:00
|
|
|
interface NodeIconSource {
|
2022-12-14 01:04:10 -08:00
|
|
|
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: {
|
2022-12-14 01:04:10 -08:00
|
|
|
nodeType: {},
|
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,
|
|
|
|
},
|
2022-08-01 13:35:45 -07:00
|
|
|
showTooltip: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-11-19 01:17:13 -08:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
computed: {
|
2022-12-14 01:04:10 -08:00
|
|
|
...mapStores(useRootStore),
|
|
|
|
type(): string {
|
2021-11-19 01:17:13 -08:00
|
|
|
const nodeType = this.nodeType as INodeTypeDescription | IVersionNode | null;
|
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-12-14 01:04:10 -08:00
|
|
|
color(): string {
|
2022-08-01 13:35:45 -07:00
|
|
|
const nodeType = this.nodeType as INodeTypeDescription | IVersionNode | null;
|
|
|
|
if (nodeType && nodeType.defaults && nodeType.defaults.color) {
|
|
|
|
return nodeType.defaults.color.toString();
|
2020-10-03 05:10:08 -07:00
|
|
|
}
|
2022-08-01 13:35:45 -07:00
|
|
|
return '';
|
2020-10-03 05:10:08 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
iconSource(): NodeIconSource {
|
2021-11-19 01:17:13 -08:00
|
|
|
const nodeType = this.nodeType as INodeTypeDescription | IVersionNode | null;
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
<style lang="scss"></style>
|