|
@@ -55,8 +55,9 @@
|
|
<script>
|
|
<script>
|
|
/* eslint-disable camelcase */
|
|
/* eslint-disable camelcase */
|
|
import { onMounted, shallowRef, reactive, getCurrentInstance } from 'vue';
|
|
import { onMounted, shallowRef, reactive, getCurrentInstance } from 'vue';
|
|
-import emitter from 'tiny-emitter/instance';
|
|
|
|
import { useI18n } from 'vue-i18n';
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
+import { compare } from 'compare-versions';
|
|
|
|
+import emitter from 'tiny-emitter/instance';
|
|
import { tasks } from '@/utils/shared';
|
|
import { tasks } from '@/utils/shared';
|
|
import { parseJSON } from '@/utils/helper';
|
|
import { parseJSON } from '@/utils/helper';
|
|
import { useGroupTooltip } from '@/composable/groupTooltip';
|
|
import { useGroupTooltip } from '@/composable/groupTooltip';
|
|
@@ -68,8 +69,12 @@ export default {
|
|
type: [Object, String],
|
|
type: [Object, String],
|
|
default: null,
|
|
default: null,
|
|
},
|
|
},
|
|
|
|
+ version: {
|
|
|
|
+ type: String,
|
|
|
|
+ default: '',
|
|
|
|
+ },
|
|
},
|
|
},
|
|
- emits: ['load', 'deleteBlock'],
|
|
|
|
|
|
+ emits: ['load', 'deleteBlock', 'update'],
|
|
setup(props, { emit }) {
|
|
setup(props, { emit }) {
|
|
useGroupTooltip();
|
|
useGroupTooltip();
|
|
const { t } = useI18n();
|
|
const { t } = useI18n();
|
|
@@ -184,13 +189,50 @@ export default {
|
|
emit('load', editor.value);
|
|
emit('load', editor.value);
|
|
|
|
|
|
if (props.data) {
|
|
if (props.data) {
|
|
- const data =
|
|
|
|
|
|
+ let data =
|
|
typeof props.data === 'string'
|
|
typeof props.data === 'string'
|
|
? parseJSON(props.data.replace(/BlockNewTab/g, 'BlockBasic'), null)
|
|
? parseJSON(props.data.replace(/BlockNewTab/g, 'BlockBasic'), null)
|
|
: props.data;
|
|
: props.data;
|
|
|
|
|
|
if (!data) return;
|
|
if (!data) return;
|
|
|
|
|
|
|
|
+ const currentExtVersion = chrome.runtime.getManifest().version;
|
|
|
|
+ const isOldWorkflow = compare(
|
|
|
|
+ currentExtVersion,
|
|
|
|
+ props.version || '0.0.0',
|
|
|
|
+ '>'
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (isOldWorkflow) {
|
|
|
|
+ const newDrawflowData = Object.entries(
|
|
|
|
+ data.drawflow.Home.data
|
|
|
|
+ ).reduce((obj, [key, value]) => {
|
|
|
|
+ const newBlockData = {
|
|
|
|
+ ...tasks[value.name],
|
|
|
|
+ ...value,
|
|
|
|
+ data: {
|
|
|
|
+ ...tasks[value.name].data,
|
|
|
|
+ ...value.data,
|
|
|
|
+ },
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ obj[key] = newBlockData;
|
|
|
|
+
|
|
|
|
+ return obj;
|
|
|
|
+ }, {});
|
|
|
|
+
|
|
|
|
+ const drawflowData = {
|
|
|
|
+ drawflow: { Home: { data: newDrawflowData } },
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ data = drawflowData;
|
|
|
|
+
|
|
|
|
+ emit('update', {
|
|
|
|
+ version: currentExtVersion,
|
|
|
|
+ drawflow: JSON.stringify(drawflowData),
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
editor.value.import(data);
|
|
editor.value.import(data);
|
|
} else {
|
|
} else {
|
|
editor.value.addNode(
|
|
editor.value.addNode(
|