@mixd-id/web-scaffold 0.1.240411096 → 0.1.240411099
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/components/List.vue
CHANGED
|
@@ -50,7 +50,10 @@
|
|
|
50
50
|
</ContextMenu>
|
|
51
51
|
</div>
|
|
52
52
|
|
|
53
|
-
<div class="flex-1
|
|
53
|
+
<div v-if="loadingState === 1" class="flex-1 flex items-center justify-center">
|
|
54
|
+
<svg class="animate-spin aspect-square w-[24px] h-[24px]" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>
|
|
55
|
+
</div>
|
|
56
|
+
<div v-else class="flex-1 overflow-y-auto p-2 pt-5">
|
|
54
57
|
<TreeView v-model="items">
|
|
55
58
|
|
|
56
59
|
<template #item="{ item }">
|
|
@@ -148,7 +151,7 @@
|
|
|
148
151
|
</template>
|
|
149
152
|
</Textbox>
|
|
150
153
|
<div class="flex-1"></div>
|
|
151
|
-
<Button v-if="selectedItemChanged" class="p-1 px-5 rounded-full" @click="
|
|
154
|
+
<Button v-if="selectedItemChanged" ref="saveBtn" class="p-1 px-5 rounded-full" @click="saveApiDoc(selectedItem).then(snapshotSelectedItem)">Save</Button>
|
|
152
155
|
</div>
|
|
153
156
|
|
|
154
157
|
<button type="button" class="flex flex-row items-center text-left gap-1 p-3 px-6"
|
|
@@ -585,6 +588,7 @@
|
|
|
585
588
|
<script setup>
|
|
586
589
|
|
|
587
590
|
import {computed, getCurrentInstance, inject, onMounted, onUnmounted, ref, useTemplateRef, watch} from "vue";
|
|
591
|
+
import { queueForLater } from '../utils/helpers.mjs'
|
|
588
592
|
import { VueMonacoEditor, useMonaco } from "@guolao/vue-monaco-editor";
|
|
589
593
|
const { appContext } = getCurrentInstance()
|
|
590
594
|
|
|
@@ -614,9 +618,11 @@ const items = ref([])
|
|
|
614
618
|
const env = ref([])
|
|
615
619
|
|
|
616
620
|
const isSending = ref(false)
|
|
621
|
+
const loadingState = ref(1)
|
|
617
622
|
|
|
618
623
|
const envEdit = useTemplateRef('envEdit')
|
|
619
624
|
const workspaceEdit = useTemplateRef('workspaceEdit')
|
|
625
|
+
const saveBtn = useTemplateRef('saveBtn')
|
|
620
626
|
|
|
621
627
|
const alert = inject('alert')
|
|
622
628
|
const confirm = inject('confirm')
|
|
@@ -1046,6 +1052,8 @@ async function reloadApiDocs(id){
|
|
|
1046
1052
|
applyDocUpdates(Array.isArray(res.docs) ? res.docs : [])
|
|
1047
1053
|
}
|
|
1048
1054
|
|
|
1055
|
+
const queueReloadApiDocs = queueForLater({ delay: 1000, pop: (ids) => reloadApiDocs(ids) })
|
|
1056
|
+
|
|
1049
1057
|
function removeApiDocs(uids) {
|
|
1050
1058
|
const removeFrom = (list) => {
|
|
1051
1059
|
for(let i = list.length - 1; i >= 0; i--) {
|
|
@@ -1077,12 +1085,28 @@ async function saveApiDocs(docs) {
|
|
|
1077
1085
|
applyDocUpdates(Array.isArray(res.docs) ? res.docs : [])
|
|
1078
1086
|
}
|
|
1079
1087
|
|
|
1088
|
+
async function saveApiDoc(doc) {
|
|
1089
|
+
try{
|
|
1090
|
+
saveBtn.value.setState(2)
|
|
1091
|
+
const clean = cleanDocs([doc])[0]
|
|
1092
|
+
const updated = await socket.send(`${controller}.save-api-doc`, clean)
|
|
1093
|
+
applyDocUpdates([updated])
|
|
1094
|
+
}
|
|
1095
|
+
catch(e){
|
|
1096
|
+
alert(e)
|
|
1097
|
+
}
|
|
1098
|
+
finally{
|
|
1099
|
+
saveBtn.value.resetState()
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1080
1103
|
function load(){
|
|
1081
1104
|
socket.send(`${controller}.load`, {})
|
|
1082
1105
|
.then(res => {
|
|
1083
1106
|
workspaces.value = res.workspaces || []
|
|
1084
1107
|
env.value = res.env || []
|
|
1085
1108
|
})
|
|
1109
|
+
.finally(_ => loadingState.value = 0)
|
|
1086
1110
|
}
|
|
1087
1111
|
|
|
1088
1112
|
async function saveWorkspace(workspace) {
|
|
@@ -1144,7 +1168,7 @@ function onEvent(model, event, items){
|
|
|
1144
1168
|
removeApiDocs(items.map(i => i.uid))
|
|
1145
1169
|
}
|
|
1146
1170
|
else{
|
|
1147
|
-
|
|
1171
|
+
queueReloadApiDocs(items.map(i => i.id))
|
|
1148
1172
|
}
|
|
1149
1173
|
break
|
|
1150
1174
|
|
|
@@ -1298,8 +1322,19 @@ const savedItemSnapshot = ref(null)
|
|
|
1298
1322
|
|
|
1299
1323
|
function itemSnapshot(item) {
|
|
1300
1324
|
if(!item) return null
|
|
1301
|
-
const { lastResponse, ...rest } = item
|
|
1302
|
-
return JSON.stringify(
|
|
1325
|
+
const { lastResponse, items, ...rest } = item
|
|
1326
|
+
return JSON.stringify({
|
|
1327
|
+
id:item.id,
|
|
1328
|
+
name:item.name,
|
|
1329
|
+
headers: item.headers,
|
|
1330
|
+
query: item.query,
|
|
1331
|
+
body: item.body,
|
|
1332
|
+
method: item.method,
|
|
1333
|
+
url: item.url,
|
|
1334
|
+
type: item.type,
|
|
1335
|
+
formData: item.formData,
|
|
1336
|
+
script: item.script
|
|
1337
|
+
})
|
|
1303
1338
|
}
|
|
1304
1339
|
|
|
1305
1340
|
const selectedItemChanged = computed(() => {
|
|
@@ -1399,7 +1434,7 @@ function onKeydown(e) {
|
|
|
1399
1434
|
if((e.ctrlKey || e.metaKey) && e.key === 's') {
|
|
1400
1435
|
e.preventDefault()
|
|
1401
1436
|
if(selectedItem.value && selectedItemChanged.value) {
|
|
1402
|
-
|
|
1437
|
+
saveApiDoc(selectedItem.value).then(snapshotSelectedItem)
|
|
1403
1438
|
}
|
|
1404
1439
|
}
|
|
1405
1440
|
}
|
|
@@ -1414,6 +1449,7 @@ onUnmounted(() => {
|
|
|
1414
1449
|
socket.send('user.unsubscribe', { name: ['api-doc', 'api-workspace', 'api-env'] })
|
|
1415
1450
|
socket.offAny(onEvent)
|
|
1416
1451
|
window.removeEventListener('keydown', onKeydown)
|
|
1452
|
+
queueReloadApiDocs.cancel()
|
|
1417
1453
|
})
|
|
1418
1454
|
|
|
1419
1455
|
|
package/src/utils/helpers.mjs
CHANGED
|
@@ -406,8 +406,8 @@ const queueForLater = (params) => {
|
|
|
406
406
|
|
|
407
407
|
run: () => {
|
|
408
408
|
const items = instance.items.splice(0, instance.items.length);
|
|
409
|
-
typeof instance.pop === 'function' ? instance.pop(items) : null;
|
|
410
409
|
instance.timeoutId = null
|
|
410
|
+
typeof instance.pop === 'function' ? instance.pop(items) : null;
|
|
411
411
|
},
|
|
412
412
|
|
|
413
413
|
queue(item) {
|
|
@@ -417,11 +417,19 @@ const queueForLater = (params) => {
|
|
|
417
417
|
instance.items.push(item)
|
|
418
418
|
|
|
419
419
|
if(!instance.timeoutId)
|
|
420
|
-
instance.timeoutId =
|
|
420
|
+
instance.timeoutId = setTimeout(instance.run, instance.delay);
|
|
421
|
+
},
|
|
422
|
+
|
|
423
|
+
cancel() {
|
|
424
|
+
clearTimeout(instance.timeoutId)
|
|
425
|
+
instance.timeoutId = null
|
|
426
|
+
instance.items = []
|
|
421
427
|
}
|
|
422
428
|
}
|
|
423
429
|
|
|
424
|
-
|
|
430
|
+
const queue = instance.queue.bind(instance)
|
|
431
|
+
queue.cancel = instance.cancel
|
|
432
|
+
return queue
|
|
425
433
|
}
|
|
426
434
|
|
|
427
435
|
const queueForLaterWithKey = (params) => {
|