|
@@ -1,5 +1,5 @@
|
|
<template>
|
|
<template>
|
|
- <div id="block-comparison" class="p-4">
|
|
|
|
|
|
+ <div :id="componentId" class="p-4">
|
|
<div class="flex items-center">
|
|
<div class="flex items-center">
|
|
<div
|
|
<div
|
|
:class="block.category.color"
|
|
:class="block.category.color"
|
|
@@ -15,6 +15,7 @@
|
|
@click="editor.removeNodeId(`node-${block.id}`)"
|
|
@click="editor.removeNodeId(`node-${block.id}`)"
|
|
/>
|
|
/>
|
|
<button
|
|
<button
|
|
|
|
+ :disabled="block.data.comparison && block.data.comparison.length >= 5"
|
|
class="bg-accent ml-2 rounded-lg text-white text-center"
|
|
class="bg-accent ml-2 rounded-lg text-white text-center"
|
|
style="height: 37px; width: 37px"
|
|
style="height: 37px; width: 37px"
|
|
@click="addComparison"
|
|
@click="addComparison"
|
|
@@ -39,6 +40,7 @@
|
|
<div class="flex items-center transition bg-input rounded-lg">
|
|
<div class="flex items-center transition bg-input rounded-lg">
|
|
<select
|
|
<select
|
|
v-model="block.data.comparison[index].type"
|
|
v-model="block.data.comparison[index].type"
|
|
|
|
+ :title="conditions[block.data.comparison[index]?.type] || 'Equals'"
|
|
class="
|
|
class="
|
|
bg-transparent
|
|
bg-transparent
|
|
font-mono
|
|
font-mono
|
|
@@ -71,7 +73,10 @@
|
|
v-if="block.data.comparison && block.data.comparison.length !== 0"
|
|
v-if="block.data.comparison && block.data.comparison.length !== 0"
|
|
class="text-right text-gray-600"
|
|
class="text-right text-gray-600"
|
|
>
|
|
>
|
|
- <span title="Blabla">ⓘ</span> Fallback
|
|
|
|
|
|
+ <span title="Execute when all comparisons don't meet the requirement"
|
|
|
|
+ >ⓘ</span
|
|
|
|
+ >
|
|
|
|
+ Fallback
|
|
</p>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -82,6 +87,7 @@ import { VRemixIcon as VRemixicon } from 'v-remixicon';
|
|
import { nanoid } from 'nanoid';
|
|
import { nanoid } from 'nanoid';
|
|
import { debounce } from '@/utils/helper';
|
|
import { debounce } from '@/utils/helper';
|
|
import { icons } from '@/lib/v-remixicon';
|
|
import { icons } from '@/lib/v-remixicon';
|
|
|
|
+import { useComponentId } from '@/composable/componentId';
|
|
import { useEditorBlock } from '@/composable/editorBlock';
|
|
import { useEditorBlock } from '@/composable/editorBlock';
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
@@ -91,7 +97,9 @@ const props = defineProps({
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
|
|
-const block = useEditorBlock('#block-comparison', props.editor);
|
|
|
|
|
|
+const componentId = useComponentId('block-comparison');
|
|
|
|
+const block = useEditorBlock(`#${componentId}`, props.editor);
|
|
|
|
+
|
|
const conditions = {
|
|
const conditions = {
|
|
'==': 'Equals',
|
|
'==': 'Equals',
|
|
'>': 'Greater than',
|
|
'>': 'Greater than',
|
|
@@ -101,10 +109,20 @@ const conditions = {
|
|
};
|
|
};
|
|
|
|
|
|
function addComparison() {
|
|
function addComparison() {
|
|
|
|
+ if (block.data.comparison.length >= 5) return;
|
|
|
|
+
|
|
block.data.comparison.push({ id: nanoid(6), type: '==', value: '' });
|
|
block.data.comparison.push({ id: nanoid(6), type: '==', value: '' });
|
|
|
|
+
|
|
|
|
+ if (block.data.comparison.length === 1) props.editor.addNodeOutput(block.id);
|
|
|
|
+
|
|
|
|
+ props.editor.addNodeOutput(block.id);
|
|
}
|
|
}
|
|
function deleteComparison(index) {
|
|
function deleteComparison(index) {
|
|
block.data.comparison.splice(index, 1);
|
|
block.data.comparison.splice(index, 1);
|
|
|
|
+
|
|
|
|
+ props.editor.removeNodeOutput(block.id, `output_${index + 1}`);
|
|
|
|
+ if (block.data.comparison.length === 0)
|
|
|
|
+ props.editor.removeNodeOutput(block.id, `output_1`);
|
|
}
|
|
}
|
|
|
|
|
|
watch(
|
|
watch(
|
|
@@ -113,6 +131,8 @@ watch(
|
|
props.editor.updateNodeDataFromId(block.id, {
|
|
props.editor.updateNodeDataFromId(block.id, {
|
|
comparison: toRaw(newValue),
|
|
comparison: toRaw(newValue),
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+ props.editor.updateConnectionNodes(`node-${block.id}`);
|
|
}, 250),
|
|
}, 250),
|
|
{ deep: true }
|
|
{ deep: true }
|
|
);
|
|
);
|