|
@@ -1,7 +1,7 @@
|
|
|
<script setup lang="ts">
|
|
|
import { useStore } from '@/store'
|
|
|
const store = useStore()
|
|
|
-import { computed, shallowRef } from 'vue'
|
|
|
+import { ref, shallowRef, watch } from 'vue'
|
|
|
import VCollaps from './VCollaps.vue';
|
|
|
|
|
|
//see https://github.com/imguolao/monaco-vue#vite
|
|
@@ -37,25 +37,23 @@ const MONACO_EDITOR_OPTIONS = {
|
|
|
formatOnType: true,
|
|
|
formatOnPaste: true,
|
|
|
}
|
|
|
-
|
|
|
const { selectedNode } = storeToRefs(store)
|
|
|
+const code=ref("");
|
|
|
+let dirty=false;
|
|
|
|
|
|
-
|
|
|
-const code = computed(():string => {
|
|
|
- if(!selectedNode.value)
|
|
|
- return "";
|
|
|
- if(!selectedNode.value.nodeId.value)
|
|
|
- return "";
|
|
|
- const m=store.addressSpace?.mapping.get(selectedNode.value.nodeId.toString());
|
|
|
- if(m)
|
|
|
- return m.read;
|
|
|
- return "";
|
|
|
+watch(selectedNode, () => {
|
|
|
+ if (!selectedNode.value)
|
|
|
+ return;
|
|
|
+ if (!selectedNode.value.nodeId.value)
|
|
|
+ return;
|
|
|
+ const m = store.addressSpace?.mapping.get(selectedNode.value.nodeId.toString());
|
|
|
+ code.value = m?.read || "";
|
|
|
+ dirty=false;
|
|
|
});
|
|
|
|
|
|
const editorRef = shallowRef()
|
|
|
const handleMount = (editor: any) => {
|
|
|
- editorRef.value = editor
|
|
|
-
|
|
|
+ editorRef.value = editor;
|
|
|
}
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -64,17 +62,26 @@ const onChange = (value: string | undefined, event: monaco.editor.IModelContentC
|
|
|
return;
|
|
|
if(!value)
|
|
|
return;
|
|
|
- store.addressSpace?.mapping.set(store.selectedNode.nodeId.value.toString(), {path: store.selectedNode.nodeId.toString(), read: value, write: ""} as IMappingValue)
|
|
|
+ code.value=value;
|
|
|
+}
|
|
|
+
|
|
|
+function formChanged(){
|
|
|
+ dirty=true;
|
|
|
}
|
|
|
|
|
|
function okPressed() {
|
|
|
- console.log('TODO: Handle OK Button');
|
|
|
+ if(!dirty)
|
|
|
+ return;
|
|
|
+ if(!selectedNode.value)
|
|
|
+ return;
|
|
|
+ store.addressSpace?.mapping.set(selectedNode.value.nodeId.toString(), {path: selectedNode.value.nodeId.toString(), read: code.value, write: ""} as IMappingValue)
|
|
|
+ dirty=false;
|
|
|
}
|
|
|
defineExpose({ okPressed })
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
- <VCollaps :selected=false name="Mapping">
|
|
|
+ <VCollaps :selected=false name="Mapping" @change="formChanged()">
|
|
|
<div class="card-text" v-if="selectedNode">
|
|
|
<vue-monaco-editor
|
|
|
v-model:value="code"
|