mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Drag-sortable WI entries.
This commit is contained in:
@ -2912,6 +2912,7 @@
|
|||||||
<form class="world_entry_form">
|
<form class="world_entry_form">
|
||||||
<div class="inline-drawer wide100p">
|
<div class="inline-drawer wide100p">
|
||||||
<div class="inline-drawer-toggle inline-drawer-header gap5px">
|
<div class="inline-drawer-toggle inline-drawer-header gap5px">
|
||||||
|
<span class="drag-handle">☰</span>
|
||||||
<div class="gap5px world_entry_thin_controls wide100p">
|
<div class="gap5px world_entry_thin_controls wide100p">
|
||||||
<div class="world_entry_form_control">
|
<div class="world_entry_form_control">
|
||||||
<label for="key">
|
<label for="key">
|
||||||
@ -3359,4 +3360,4 @@
|
|||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -126,6 +126,7 @@ async function loadWorldInfoData(name) {
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
body: JSON.stringify({ name: name }),
|
body: JSON.stringify({ name: name }),
|
||||||
|
cache: 'no-cache',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@ -176,8 +177,18 @@ function displayWorldEntries(name, data) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const entryUid in data.entries) {
|
// Convert the data.entries object into an array
|
||||||
const entry = data.entries[entryUid];
|
const entriesArray = Object.keys(data.entries).map(uid => {
|
||||||
|
const entry = data.entries[uid];
|
||||||
|
entry.displayIndex = entry.displayIndex ?? entry.uid;
|
||||||
|
return entry;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sort the entries array by displayIndex and uid
|
||||||
|
entriesArray.sort((a, b) => a.displayIndex - b.displayIndex || a.uid - b.uid);
|
||||||
|
|
||||||
|
// Loop through the sorted array and call appendWorldEntry
|
||||||
|
for (const entry of entriesArray) {
|
||||||
appendWorldEntry(name, data, entry);
|
appendWorldEntry(name, data, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,6 +217,36 @@ function displayWorldEntries(name, data) {
|
|||||||
|
|
||||||
await deleteWorldInfo(name, world_info);
|
await deleteWorldInfo(name, world_info);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check if a sortable instance exists
|
||||||
|
if ($('#world_popup_entries_list').sortable('instance') !== undefined) {
|
||||||
|
// Destroy the instance
|
||||||
|
$('#world_popup_entries_list').sortable('destroy');
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#world_popup_entries_list").sortable({
|
||||||
|
handle: ".drag-handle",
|
||||||
|
stop: async function (event, ui) {
|
||||||
|
$('#world_popup_entries_list .world_entry').each(function (index) {
|
||||||
|
const uid = $(this).data('uid');
|
||||||
|
|
||||||
|
// Update the display index in the data array
|
||||||
|
const item = data.entries[uid];
|
||||||
|
|
||||||
|
if (!item) {
|
||||||
|
console.debug(`Could not find entry with uid ${uid}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
item.displayIndex = index;
|
||||||
|
});
|
||||||
|
|
||||||
|
console.table(Object.keys(data.entries).map(uid => data.entries[uid]).map(x => ({ uid: x.uid, key: x.key.join(','), displayIndex: x.displayIndex })));
|
||||||
|
|
||||||
|
await saveWorldInfo(name, data, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$("#world_popup_entries_list").disableSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendWorldEntry(name, data, entry) {
|
function appendWorldEntry(name, data, entry) {
|
||||||
|
@ -1922,6 +1922,10 @@ grammarly-extension {
|
|||||||
column-gap: 20px;
|
column-gap: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.drag-handle {
|
||||||
|
cursor: grab;
|
||||||
|
}
|
||||||
|
|
||||||
.world_info_select_block {
|
.world_info_select_block {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
Reference in New Issue
Block a user