Skip to content

Commit c74d07c

Browse files
authored
feat(gsoc'24): circuit file converted to typescript + vue and array interface extension (CircuitVerse#336)
circuit file converted to typescript + vue and array interface extenstion
1 parent ca17f78 commit c74d07c

File tree

7 files changed

+158
-88
lines changed

7 files changed

+158
-88
lines changed

src/components/Panels/PropertiesPanel/ModuleProperty/ProjectProperty/ProjectProperty.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
<p>
1616
<span>Circuit:</span>
1717
<input
18+
:ref="circnameInput"
1819
id="circname"
19-
:key="SimulatorState.activeCircuit.id"
20+
:key="SimulatorState.activeCircuit?.id"
2021
class="objectPropertyAttribute"
2122
type="text"
2223
autocomplete="off"
2324
name="changeCircuitName"
24-
:value="SimulatorState.activeCircuit.name"
25+
:value="SimulatorState.activeCircuit?.name"
2526
/>
2627
</p>
2728

@@ -104,9 +105,20 @@ import { useState } from '#/store/SimulatorStore/state'
104105
import { useProjectStore } from '#/store/projectStore'
105106
// import DeleteCircuit from '#/components/helpers/deleteCircuit/DeleteCircuit.vue'
106107
import { closeCircuit } from '#/components/helpers/deleteCircuit/DeleteCircuit.vue'
108+
import { watch } from 'vue'
109+
import { ref } from 'vue'
107110
108111
const projectStore = useProjectStore()
109112
const SimulatorState = <SimulatorStateType>useState()
113+
const circnameInput = ref<HTMLInputElement | null>(null)
114+
115+
watch(() => SimulatorState.circuit_name_clickable, () => {
116+
setTimeout(() => {
117+
if (circnameInput.value && SimulatorState.circuit_name_clickable) {
118+
circnameInput.value.select()
119+
}
120+
}, 100)
121+
})
110122
// const circuitId: Ref<string | number> = ref(0)
111123
// const circuitName: Ref<string> = ref('Untitled-Cirucit')
112124
// const ifPersistentShow: Ref<boolean> = ref(false)
@@ -125,6 +137,7 @@ type SimulatorStateType = {
125137
dialogBox: {
126138
delete_circuit: boolean
127139
}
140+
circuit_name_clickable: boolean
128141
}
129142
130143
// type CircuitItem = {

src/components/TabsBar/TabsBar.vue

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
draggable="true"
3030
@click="switchCircuit(element.id)"
3131
>
32-
<span class="circuitName noSelect">
32+
<span class="circuitName noSelect" @mousedown="circuitNameClicked">
3333
{{ truncateString(element.name, 18) }}
3434
</span>
3535
<span
@@ -79,8 +79,9 @@ import {
7979
// import MessageBox from '#/components/MessageBox/messageBox.vue'
8080
import { useState } from '#/store/SimulatorStore/state'
8181
import { closeCircuit } from '../helpers/deleteCircuit/DeleteCircuit.vue'
82+
import { circuitNameClicked } from '#/simulator/src/circuit'
8283
83-
const SimulatorState = <SimulatorStateType>useState()
84+
const SimulatorState = useState()
8485
const drag: Ref<boolean> = ref(false)
8586
const updateCount: Ref<number> = ref(0)
8687
@@ -112,13 +113,6 @@ function toggleHeight() {
112113
// focussed: boolean
113114
// }
114115
115-
type SimulatorStateType = {
116-
circuit_list: Array<Object>
117-
dialogBox: {
118-
create_circuit: boolean
119-
}
120-
}
121-
122116
// type InputArrType = {
123117
// text: string
124118
// val: string
@@ -285,7 +279,7 @@ function isEmbed(): boolean {
285279
</script>
286280

287281
<style scoped>
288-
#tabsBar{
282+
#tabsBar {
289283
padding-right: 50px;
290284
position: relative;
291285
overflow: hidden;
@@ -314,7 +308,7 @@ function isEmbed(): boolean {
314308
}
315309
316310
#tabsBar button {
317-
font-size: 1rem;
311+
font-size: 1rem;
318312
height: 20px;
319313
width: 20px;
320314
}
@@ -339,11 +333,11 @@ function isEmbed(): boolean {
339333
max-height: 30px;
340334
}
341335
342-
.toolbarButton{
336+
.toolbarButton {
343337
height: 22px;
344338
}
345339
346-
.tabsbar-toggle{
340+
.tabsbar-toggle {
347341
position: absolute;
348342
right: 2.5px;
349343
top: 2.5px;
@@ -359,10 +353,9 @@ function isEmbed(): boolean {
359353
}
360354
361355
362-
.tabsbar-close{
363-
font-size: 1rem;
356+
.tabsbar-close {
357+
font-size: 1rem;
364358
}
365-
366359
</style>
367360

368361
<!-- TODO: add types for scopelist and fix key issue with draggable -->

src/components/helpers/deleteCircuit/DeleteCircuit.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ export function closeCircuit(circuitItem: CircuitItem): void {
112112
* @category circuit
113113
*/
114114
export function deleteCurrentCircuit(
115-
scopeId: string | number = globalScope.id ?? useState().activeCircuit.id
115+
scopeId: string | number = globalScope.id ?? useState().activeCircuit?.id
116116
) {
117117
const SimulatorState = <SimulatorStateType>useState()
118118
const circuit_list = SimulatorState.circuit_list
119119
let scope = scopeList[scopeId]
120120
if (scope == undefined)
121-
scope = scopeList[globalScope.id ?? SimulatorState.activeCircuit.id]
121+
scope = scopeList[globalScope.id ?? SimulatorState.activeCircuit?.id]
122122
123123
if (scope.verilogMetadata.isVerilogCircuit) {
124124
scope.initialize()
@@ -130,7 +130,7 @@ export function deleteCurrentCircuit(
130130
)
131131
circuit_list.splice(index, 1)
132132
delete scopeList[scope.id]
133-
if (scope.id == globalScope.id ?? SimulatorState.activeCircuit.id) {
133+
if (scope.id == globalScope.id ?? SimulatorState.activeCircuit?.id) {
134134
switchCircuit(Object.keys(scopeList)[0])
135135
}
136136
showMessage('Circuit was successfully closed')

src/env.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
/// <reference types="vite/client" />
22

3+
interface Array<T> {
4+
clean(deleteValue: T): T[]
5+
extend(otherArray: T[]): void
6+
contains(value: T): boolean
7+
}
8+
39
declare module '*.vue' {
410
import type { DefineComponent } from 'vue'
511
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types

0 commit comments

Comments
 (0)