Selaa lähdekoodia

refactor: reference data

Ahmad Kholid 3 vuotta sitten
vanhempi
commit
2de213600e

+ 20 - 12
src/components/newtab/workflow/edit/TriggerEventMouse.vue

@@ -22,18 +22,26 @@
     :key="items[0]"
     class="flex items-center space-x-2 mt-2"
   >
-    <ui-input
-      v-model.number="defaultParams[items[0]]"
-      type="number"
-      class="flex-1"
-      :label="items[0]"
-    />
-    <ui-input
-      v-model.number="defaultParams[items[1]]"
-      type="number"
-      class="flex-1"
-      :label="items[1]"
-    />
+    <template v-if="items[0].startsWith('client')">
+      <ui-input
+        v-for="item in items"
+        :key="item"
+        :model-value="defaultParams[item]"
+        :label="item"
+        class="flex-1"
+        @change="defaultParams[item] = +$event || $event"
+      />
+    </template>
+    <template v-else>
+      <ui-input
+        v-for="item in items"
+        :key="item"
+        v-model.number="defaultParams[item]"
+        type="number"
+        class="flex-1"
+        :label="item"
+      />
+    </template>
   </div>
 </template>
 <script setup>

+ 2 - 2
src/content/blocks-handler/handler-trigger-event.js

@@ -20,8 +20,8 @@ const eventHandlers = {
       button: mouseButtons[params.button]?.name || 'left',
     };
 
-    if (params.clientX) commandParams.x = params.clientX;
-    if (params.clientY) commandParams.y = params.clientY;
+    if (params.clientX) commandParams.x = +params.clientX;
+    if (params.clientY) commandParams.y = +params.clientY;
 
     Object.keys(modifiers).forEach((key) => {
       if (commandParams.modifiers) return;

+ 13 - 5
src/utils/reference-data/index.js

@@ -1,4 +1,4 @@
-import { objectHasKey } from '@/utils/helper';
+import objectPath from 'object-path';
 import mustacheReplacer from './mustache-replacer';
 
 export default function ({ block, refKeys, data }) {
@@ -7,16 +7,24 @@ export default function ({ block, refKeys, data }) {
   const copyBlock = JSON.parse(JSON.stringify(block));
 
   refKeys.forEach((blockDataKey) => {
-    if (!objectHasKey(block.data, blockDataKey)) return;
+    const currentData = objectPath.get(copyBlock.data, blockDataKey);
 
-    const currentData = copyBlock.data[blockDataKey];
+    if (!currentData) return;
 
     if (Array.isArray(currentData)) {
       currentData.forEach((str, index) => {
-        currentData[index] = mustacheReplacer(str, data);
+        objectPath.set(
+          copyBlock.data,
+          `${blockDataKey}.${index}`,
+          mustacheReplacer(str, data)
+        );
       });
     } else if (typeof currentData === 'string') {
-      copyBlock.data[blockDataKey] = mustacheReplacer(currentData, data);
+      objectPath.set(
+        copyBlock.data,
+        blockDataKey,
+        mustacheReplacer(currentData, data)
+      );
     }
   });
 

+ 1 - 1
src/utils/shared.js

@@ -491,7 +491,7 @@ export const tasks = {
     outputs: 1,
     allowedInputs: true,
     maxConnection: 1,
-    refDataKeys: ['selector'],
+    refDataKeys: ['selector', 'eventParams.clientX', 'eventParams.clientY'],
     data: {
       description: '',
       findBy: 'cssSelector',