@mixd-id/web-scaffold 0.1.240411096 → 0.1.240411098
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
|
@@ -148,7 +148,7 @@
|
|
|
148
148
|
</template>
|
|
149
149
|
</Textbox>
|
|
150
150
|
<div class="flex-1"></div>
|
|
151
|
-
<Button v-if="selectedItemChanged" class="p-1 px-5 rounded-full" @click="
|
|
151
|
+
<Button v-if="selectedItemChanged" ref="saveBtn" class="p-1 px-5 rounded-full" @click="saveApiDoc(selectedItem).then(snapshotSelectedItem)">Save</Button>
|
|
152
152
|
</div>
|
|
153
153
|
|
|
154
154
|
<button type="button" class="flex flex-row items-center text-left gap-1 p-3 px-6"
|
|
@@ -585,6 +585,7 @@
|
|
|
585
585
|
<script setup>
|
|
586
586
|
|
|
587
587
|
import {computed, getCurrentInstance, inject, onMounted, onUnmounted, ref, useTemplateRef, watch} from "vue";
|
|
588
|
+
import { queueForLater } from '../utils/helpers.mjs'
|
|
588
589
|
import { VueMonacoEditor, useMonaco } from "@guolao/vue-monaco-editor";
|
|
589
590
|
const { appContext } = getCurrentInstance()
|
|
590
591
|
|
|
@@ -617,6 +618,7 @@ const isSending = ref(false)
|
|
|
617
618
|
|
|
618
619
|
const envEdit = useTemplateRef('envEdit')
|
|
619
620
|
const workspaceEdit = useTemplateRef('workspaceEdit')
|
|
621
|
+
const saveBtn = useTemplateRef('saveBtn')
|
|
620
622
|
|
|
621
623
|
const alert = inject('alert')
|
|
622
624
|
const confirm = inject('confirm')
|
|
@@ -1046,6 +1048,8 @@ async function reloadApiDocs(id){
|
|
|
1046
1048
|
applyDocUpdates(Array.isArray(res.docs) ? res.docs : [])
|
|
1047
1049
|
}
|
|
1048
1050
|
|
|
1051
|
+
const queueReloadApiDocs = queueForLater({ delay: 1000, pop: (ids) => reloadApiDocs(ids) })
|
|
1052
|
+
|
|
1049
1053
|
function removeApiDocs(uids) {
|
|
1050
1054
|
const removeFrom = (list) => {
|
|
1051
1055
|
for(let i = list.length - 1; i >= 0; i--) {
|
|
@@ -1077,6 +1081,21 @@ async function saveApiDocs(docs) {
|
|
|
1077
1081
|
applyDocUpdates(Array.isArray(res.docs) ? res.docs : [])
|
|
1078
1082
|
}
|
|
1079
1083
|
|
|
1084
|
+
async function saveApiDoc(doc) {
|
|
1085
|
+
try{
|
|
1086
|
+
saveBtn.value.setState(2)
|
|
1087
|
+
const clean = cleanDocs([doc])[0]
|
|
1088
|
+
const updated = await socket.send(`${controller}.save-api-doc`, clean)
|
|
1089
|
+
applyDocUpdates([updated])
|
|
1090
|
+
}
|
|
1091
|
+
catch(e){
|
|
1092
|
+
alert(e)
|
|
1093
|
+
}
|
|
1094
|
+
finally{
|
|
1095
|
+
saveBtn.value.resetState()
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1080
1099
|
function load(){
|
|
1081
1100
|
socket.send(`${controller}.load`, {})
|
|
1082
1101
|
.then(res => {
|
|
@@ -1144,7 +1163,7 @@ function onEvent(model, event, items){
|
|
|
1144
1163
|
removeApiDocs(items.map(i => i.uid))
|
|
1145
1164
|
}
|
|
1146
1165
|
else{
|
|
1147
|
-
|
|
1166
|
+
queueReloadApiDocs(items.map(i => i.id))
|
|
1148
1167
|
}
|
|
1149
1168
|
break
|
|
1150
1169
|
|
|
@@ -1298,8 +1317,19 @@ const savedItemSnapshot = ref(null)
|
|
|
1298
1317
|
|
|
1299
1318
|
function itemSnapshot(item) {
|
|
1300
1319
|
if(!item) return null
|
|
1301
|
-
const { lastResponse, ...rest } = item
|
|
1302
|
-
return JSON.stringify(
|
|
1320
|
+
const { lastResponse, items, ...rest } = item
|
|
1321
|
+
return JSON.stringify({
|
|
1322
|
+
id:item.id,
|
|
1323
|
+
name:item.name,
|
|
1324
|
+
headers: item.headers,
|
|
1325
|
+
query: item.query,
|
|
1326
|
+
body: item.body,
|
|
1327
|
+
method: item.method,
|
|
1328
|
+
url: item.url,
|
|
1329
|
+
type: item.type,
|
|
1330
|
+
formData: item.formData,
|
|
1331
|
+
script: item.script
|
|
1332
|
+
})
|
|
1303
1333
|
}
|
|
1304
1334
|
|
|
1305
1335
|
const selectedItemChanged = computed(() => {
|
|
@@ -1399,7 +1429,7 @@ function onKeydown(e) {
|
|
|
1399
1429
|
if((e.ctrlKey || e.metaKey) && e.key === 's') {
|
|
1400
1430
|
e.preventDefault()
|
|
1401
1431
|
if(selectedItem.value && selectedItemChanged.value) {
|
|
1402
|
-
|
|
1432
|
+
saveApiDoc(selectedItem.value).then(snapshotSelectedItem)
|
|
1403
1433
|
}
|
|
1404
1434
|
}
|
|
1405
1435
|
}
|
|
@@ -1414,6 +1444,7 @@ onUnmounted(() => {
|
|
|
1414
1444
|
socket.send('user.unsubscribe', { name: ['api-doc', 'api-workspace', 'api-env'] })
|
|
1415
1445
|
socket.offAny(onEvent)
|
|
1416
1446
|
window.removeEventListener('keydown', onKeydown)
|
|
1447
|
+
queueReloadApiDocs.cancel()
|
|
1417
1448
|
})
|
|
1418
1449
|
|
|
1419
1450
|
|
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) => {
|