1423 lines
43 KiB
HTML
1423 lines
43 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Prompt Database Manager</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
|
|
body {
|
|
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
|
|
background: #11111b;
|
|
color: #cdd6f4;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
/* ── Layout ── */
|
|
.app {
|
|
display: flex;
|
|
height: 100vh;
|
|
}
|
|
|
|
/* ── Sidebar ── */
|
|
.sidebar {
|
|
width: 240px;
|
|
min-width: 240px;
|
|
background: #181825;
|
|
border-right: 1px solid #313244;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.sidebar-logo {
|
|
padding: 20px;
|
|
font-size: 16px;
|
|
font-weight: 700;
|
|
color: #cba6f7;
|
|
border-bottom: 1px solid #313244;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
.sidebar-logo span { font-size: 20px; }
|
|
|
|
.sidebar-label {
|
|
padding: 16px 20px 8px;
|
|
font-size: 11px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 1.5px;
|
|
color: #585b70;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.cat-list {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 4px 12px;
|
|
}
|
|
|
|
.cat-item {
|
|
padding: 10px 14px;
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
transition: all .15s;
|
|
margin-bottom: 2px;
|
|
user-select: none;
|
|
}
|
|
.cat-item:hover { background: #1e1e2e; }
|
|
.cat-item.active {
|
|
background: #313244;
|
|
color: #cba6f7;
|
|
font-weight: 600;
|
|
}
|
|
.cat-item .cat-count {
|
|
font-size: 11px;
|
|
background: #313244;
|
|
color: #6c7086;
|
|
padding: 2px 8px;
|
|
border-radius: 10px;
|
|
min-width: 24px;
|
|
text-align: center;
|
|
}
|
|
.cat-item.active .cat-count {
|
|
background: #45475a;
|
|
color: #cba6f7;
|
|
}
|
|
.cat-item .cat-del {
|
|
opacity: 0;
|
|
background: none;
|
|
border: none;
|
|
color: #f38ba8;
|
|
cursor: pointer;
|
|
font-size: 13px;
|
|
padding: 2px 6px;
|
|
border-radius: 4px;
|
|
transition: all .15s;
|
|
}
|
|
.cat-item:hover .cat-del { opacity: .7; }
|
|
.cat-item .cat-del:hover { opacity: 1; background: rgba(243,139,168,.12); }
|
|
|
|
.cat-add {
|
|
padding: 12px;
|
|
border-top: 1px solid #313244;
|
|
display: flex;
|
|
gap: 6px;
|
|
}
|
|
.cat-add input {
|
|
flex: 1;
|
|
background: #1e1e2e;
|
|
border: 1px solid #313244;
|
|
color: #cdd6f4;
|
|
border-radius: 8px;
|
|
padding: 8px 12px;
|
|
font-size: 13px;
|
|
font-family: inherit;
|
|
outline: none;
|
|
transition: border-color .15s;
|
|
}
|
|
.cat-add input:focus { border-color: #cba6f7; }
|
|
.cat-add input::placeholder { color: #585b70; }
|
|
|
|
.btn-icon {
|
|
background: #313244;
|
|
border: 1px solid #45475a;
|
|
color: #a6e3a1;
|
|
width: 36px;
|
|
height: 36px;
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
font-size: 18px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
transition: all .15s;
|
|
flex-shrink: 0;
|
|
}
|
|
.btn-icon:hover { background: #45475a; border-color: #a6e3a1; }
|
|
|
|
/* ── Main ── */
|
|
.main {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.toolbar {
|
|
padding: 16px 24px;
|
|
border-bottom: 1px solid #313244;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
background: #181825;
|
|
}
|
|
.toolbar-title {
|
|
flex: 1;
|
|
font-size: 18px;
|
|
font-weight: 600;
|
|
color: #a6adc8;
|
|
}
|
|
|
|
.btn {
|
|
padding: 8px 18px;
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
font-family: inherit;
|
|
transition: all .15s;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
}
|
|
.btn-primary { background: #cba6f7; color: #11111b; }
|
|
.btn-primary:hover { background: #b48bf0; }
|
|
.btn-danger { background: #f38ba8; color: #11111b; }
|
|
.btn-danger:hover { background: #e76e8f; }
|
|
.btn-ghost { background: transparent; color: #a6adc8; border: 1px solid #45475a; }
|
|
.btn-ghost:hover { background: #313244; color: #cdd6f4; }
|
|
.btn-sm { padding: 6px 12px; font-size: 12px; }
|
|
|
|
/* ── Prompt Grid ── */
|
|
.prompt-grid {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 20px 24px;
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
|
|
gap: 12px;
|
|
align-content: start;
|
|
}
|
|
|
|
.prompt-card {
|
|
background: #1e1e2e;
|
|
border: 1px solid #313244;
|
|
border-radius: 10px;
|
|
padding: 16px;
|
|
cursor: pointer;
|
|
transition: all .2s;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
.prompt-card:hover {
|
|
border-color: #585b70;
|
|
transform: translateY(-1px);
|
|
box-shadow: 0 4px 12px rgba(0,0,0,.25);
|
|
}
|
|
.prompt-card.selected {
|
|
border-color: #cba6f7;
|
|
box-shadow: 0 0 0 1px #cba6f7;
|
|
}
|
|
|
|
.card-header {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
justify-content: space-between;
|
|
margin-bottom: 8px;
|
|
}
|
|
.card-name {
|
|
font-size: 15px;
|
|
font-weight: 600;
|
|
color: #cdd6f4;
|
|
line-height: 1.3;
|
|
}
|
|
.card-badge {
|
|
font-size: 10px;
|
|
background: #313244;
|
|
color: #89b4fa;
|
|
padding: 3px 8px;
|
|
border-radius: 6px;
|
|
text-transform: uppercase;
|
|
letter-spacing: .5px;
|
|
font-weight: 600;
|
|
white-space: nowrap;
|
|
}
|
|
.card-lora-badge {
|
|
font-size: 10px;
|
|
background: rgba(249,226,175,.12);
|
|
color: #f9e2af;
|
|
padding: 3px 8px;
|
|
border-radius: 6px;
|
|
font-weight: 600;
|
|
white-space: nowrap;
|
|
margin-left: 4px;
|
|
}
|
|
.card-text {
|
|
font-size: 13px;
|
|
color: #6c7086;
|
|
line-height: 1.5;
|
|
display: -webkit-box;
|
|
-webkit-line-clamp: 3;
|
|
-webkit-box-orient: vertical;
|
|
overflow: hidden;
|
|
flex: 1;
|
|
}
|
|
.card-loras {
|
|
margin-top: 8px;
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 4px;
|
|
}
|
|
.card-lora-tag {
|
|
font-size: 11px;
|
|
background: #1a1a2e;
|
|
color: #f9e2af;
|
|
padding: 3px 8px;
|
|
border-radius: 6px;
|
|
border: 1px solid rgba(249,226,175,.15);
|
|
}
|
|
.card-actions {
|
|
display: flex;
|
|
gap: 6px;
|
|
margin-top: 12px;
|
|
padding-top: 12px;
|
|
border-top: 1px solid #313244;
|
|
}
|
|
.card-actions .btn { flex: 1; justify-content: center; }
|
|
|
|
/* ── Empty State ── */
|
|
.empty {
|
|
grid-column: 1 / -1;
|
|
text-align: center;
|
|
padding: 60px 20px;
|
|
}
|
|
.empty-icon { font-size: 48px; margin-bottom: 12px; }
|
|
.empty-title { font-size: 16px; color: #6c7086; margin-bottom: 6px; }
|
|
.empty-hint { font-size: 13px; color: #45475a; }
|
|
|
|
/* ── Editor Drawer ── */
|
|
.drawer-overlay {
|
|
position: fixed;
|
|
inset: 0;
|
|
background: rgba(0,0,0,.5);
|
|
backdrop-filter: blur(3px);
|
|
z-index: 1000;
|
|
opacity: 0;
|
|
pointer-events: none;
|
|
display: none;
|
|
transition: opacity .2s;
|
|
}
|
|
.drawer-overlay.open { opacity: 1; pointer-events: auto; display: block; }
|
|
|
|
.drawer {
|
|
position: fixed;
|
|
top: 0;
|
|
right: -520px;
|
|
width: 500px;
|
|
max-width: 90vw;
|
|
height: 100vh;
|
|
background: #181825;
|
|
border-left: 1px solid #313244;
|
|
z-index: 1001;
|
|
display: flex;
|
|
flex-direction: column;
|
|
transition: right .25s cubic-bezier(.4,0,.2,1);
|
|
box-shadow: -8px 0 32px rgba(0,0,0,.4);
|
|
}
|
|
.drawer.open { right: 0; }
|
|
|
|
.drawer-header {
|
|
padding: 20px 24px;
|
|
border-bottom: 1px solid #313244;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
.drawer-header h3 {
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
color: #cba6f7;
|
|
}
|
|
.drawer-close {
|
|
background: none;
|
|
border: none;
|
|
color: #6c7086;
|
|
font-size: 22px;
|
|
cursor: pointer;
|
|
padding: 4px 8px;
|
|
border-radius: 6px;
|
|
transition: all .15s;
|
|
}
|
|
.drawer-close:hover { background: #313244; color: #f38ba8; }
|
|
|
|
.drawer-body {
|
|
flex: 1;
|
|
padding: 24px;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.field { margin-bottom: 16px; }
|
|
.field label {
|
|
display: block;
|
|
font-size: 12px;
|
|
color: #585b70;
|
|
margin-bottom: 6px;
|
|
text-transform: uppercase;
|
|
letter-spacing: .5px;
|
|
font-weight: 600;
|
|
}
|
|
.field input,
|
|
.field select,
|
|
.field textarea {
|
|
width: 100%;
|
|
background: #11111b;
|
|
border: 1px solid #313244;
|
|
color: #cdd6f4;
|
|
border-radius: 8px;
|
|
padding: 10px 14px;
|
|
font-size: 14px;
|
|
font-family: inherit;
|
|
outline: none;
|
|
transition: border-color .15s;
|
|
}
|
|
.field input:focus,
|
|
.field select:focus,
|
|
.field textarea:focus {
|
|
border-color: #cba6f7;
|
|
}
|
|
.field input::placeholder,
|
|
.field textarea::placeholder { color: #45475a; }
|
|
.field textarea { resize: vertical; min-height: 160px; line-height: 1.5; }
|
|
.field select { cursor: pointer; }
|
|
|
|
/* ── LoRA Section in Drawer ── */
|
|
.lora-section {
|
|
margin-top: 8px;
|
|
padding: 16px;
|
|
background: #11111b;
|
|
border: 1px solid #313244;
|
|
border-radius: 10px;
|
|
}
|
|
.lora-section-header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
margin-bottom: 12px;
|
|
}
|
|
.lora-section-title {
|
|
font-size: 12px;
|
|
color: #f9e2af;
|
|
text-transform: uppercase;
|
|
letter-spacing: .5px;
|
|
font-weight: 600;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
}
|
|
.lora-list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 8px;
|
|
}
|
|
.lora-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
background: #181825;
|
|
border: 1px solid #313244;
|
|
border-radius: 8px;
|
|
padding: 8px 12px;
|
|
}
|
|
.lora-item-name {
|
|
flex: 1;
|
|
font-size: 13px;
|
|
color: #cdd6f4;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
.lora-item-strength {
|
|
width: 65px;
|
|
background: #11111b;
|
|
border: 1px solid #313244;
|
|
color: #f9e2af;
|
|
border-radius: 6px;
|
|
padding: 4px 8px;
|
|
font-size: 13px;
|
|
text-align: center;
|
|
font-family: inherit;
|
|
outline: none;
|
|
}
|
|
.lora-item-strength:focus { border-color: #f9e2af; }
|
|
.lora-item-del {
|
|
background: none;
|
|
border: none;
|
|
color: #f38ba8;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
padding: 2px 4px;
|
|
border-radius: 4px;
|
|
opacity: .6;
|
|
transition: all .15s;
|
|
}
|
|
.lora-item-del:hover { opacity: 1; }
|
|
.lora-add-row {
|
|
display: flex;
|
|
gap: 6px;
|
|
margin-top: 8px;
|
|
}
|
|
.lora-add-row select {
|
|
flex: 1;
|
|
background: #181825;
|
|
border: 1px solid #313244;
|
|
color: #cdd6f4;
|
|
border-radius: 8px;
|
|
padding: 6px 10px;
|
|
font-size: 13px;
|
|
font-family: inherit;
|
|
outline: none;
|
|
cursor: pointer;
|
|
}
|
|
.lora-add-row select:focus { border-color: #f9e2af; }
|
|
.lora-empty {
|
|
text-align: center;
|
|
color: #45475a;
|
|
font-size: 12px;
|
|
padding: 8px;
|
|
}
|
|
|
|
.drawer-footer {
|
|
padding: 16px 24px;
|
|
border-top: 1px solid #313244;
|
|
display: flex;
|
|
gap: 8px;
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
/* ── Toast ── */
|
|
.toast {
|
|
position: fixed;
|
|
bottom: 24px;
|
|
right: 24px;
|
|
background: #313244;
|
|
color: #cdd6f4;
|
|
padding: 12px 20px;
|
|
border-radius: 10px;
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
box-shadow: 0 8px 24px rgba(0,0,0,.4);
|
|
z-index: 2000;
|
|
transform: translateY(60px);
|
|
opacity: 0;
|
|
transition: all .3s cubic-bezier(.4,0,.2,1);
|
|
}
|
|
.toast.show { transform: translateY(0); opacity: 1; }
|
|
.toast.success { border-left: 3px solid #a6e3a1; }
|
|
.toast.error { border-left: 3px solid #f38ba8; }
|
|
|
|
/* ── Scrollbar ── */
|
|
::-webkit-scrollbar { width: 6px; }
|
|
::-webkit-scrollbar-track { background: transparent; }
|
|
::-webkit-scrollbar-thumb { background: #313244; border-radius: 3px; }
|
|
::-webkit-scrollbar-thumb:hover { background: #45475a; }
|
|
|
|
/* ── Search ── */
|
|
.search-input {
|
|
background: #1e1e2e;
|
|
border: 1px solid #313244;
|
|
color: #cdd6f4;
|
|
border-radius: 8px;
|
|
padding: 8px 14px;
|
|
font-size: 13px;
|
|
font-family: inherit;
|
|
outline: none;
|
|
width: 240px;
|
|
transition: border-color .15s;
|
|
}
|
|
.search-input:focus { border-color: #cba6f7; }
|
|
.search-input::placeholder { color: #585b70; }
|
|
|
|
/* ── Drag & Drop ── */
|
|
.cat-item[draggable="true"] { cursor: grab; }
|
|
.cat-item[draggable="true"]:active { cursor: grabbing; }
|
|
.cat-item.drag-over {
|
|
background: rgba(203,166,247,.15);
|
|
border: 1px dashed #cba6f7;
|
|
border-radius: 8px;
|
|
}
|
|
.cat-item.drag-insert-before {
|
|
border-top: 2px solid #cba6f7;
|
|
margin-top: -2px;
|
|
}
|
|
.cat-item.drag-insert-after {
|
|
border-bottom: 2px solid #cba6f7;
|
|
margin-bottom: -2px;
|
|
}
|
|
.prompt-card[draggable="true"] { cursor: grab; }
|
|
.prompt-card[draggable="true"]:active { cursor: grabbing; }
|
|
.prompt-card.dragging { opacity: .4; }
|
|
.prompt-card.drop-left { border-left: 3px solid #cba6f7; }
|
|
.prompt-card.drop-right { border-right: 3px solid #cba6f7; }
|
|
|
|
/* ── List View ── */
|
|
.prompt-grid.list-view {
|
|
grid-template-columns: 1fr;
|
|
gap: 4px;
|
|
}
|
|
.prompt-grid.list-view .prompt-card {
|
|
flex-direction: row;
|
|
align-items: center;
|
|
padding: 10px 16px;
|
|
gap: 12px;
|
|
}
|
|
.prompt-grid.list-view .card-header {
|
|
margin-bottom: 0;
|
|
min-width: 200px;
|
|
max-width: 200px;
|
|
flex-direction: column;
|
|
align-items: flex-start;
|
|
gap: 4px;
|
|
}
|
|
.prompt-grid.list-view .card-text {
|
|
-webkit-line-clamp: 1;
|
|
line-clamp: 1;
|
|
flex: 1;
|
|
min-width: 0;
|
|
}
|
|
.prompt-grid.list-view .card-loras { display: none; }
|
|
.prompt-grid.list-view .card-actions { margin-top: 0; flex-shrink: 0; }
|
|
|
|
/* ── View Toggle + Sort ── */
|
|
.view-toggle { display: flex; gap: 2px; }
|
|
.view-toggle button {
|
|
background: #1e1e2e;
|
|
border: 1px solid #313244;
|
|
color: #6c7086;
|
|
width: 32px; height: 32px;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
display: flex; align-items: center; justify-content: center;
|
|
transition: all .15s;
|
|
}
|
|
.view-toggle button.active { background: #313244; color: #cba6f7; border-color: #45475a; }
|
|
.view-toggle button:hover { color: #cdd6f4; }
|
|
|
|
.sort-select {
|
|
background: #1e1e2e;
|
|
border: 1px solid #313244;
|
|
color: #cdd6f4;
|
|
border-radius: 6px;
|
|
padding: 6px 10px;
|
|
font-size: 12px;
|
|
font-family: inherit;
|
|
outline: none;
|
|
cursor: pointer;
|
|
}
|
|
.sort-select:focus { border-color: #cba6f7; }
|
|
|
|
/* ── Sidebar Actions ── */
|
|
.sidebar-actions {
|
|
padding: 8px 12px;
|
|
border-top: 1px solid #313244;
|
|
display: flex;
|
|
gap: 6px;
|
|
}
|
|
.sidebar-actions button {
|
|
flex: 1;
|
|
background: #1e1e2e;
|
|
border: 1px solid #313244;
|
|
color: #a6adc8;
|
|
border-radius: 8px;
|
|
padding: 8px 4px;
|
|
font-size: 12px;
|
|
font-family: inherit;
|
|
cursor: pointer;
|
|
transition: all .15s;
|
|
display: flex; align-items: center; justify-content: center; gap: 4px;
|
|
}
|
|
.sidebar-actions button:hover { background: #313244; color: #cdd6f4; border-color: #45475a; }
|
|
|
|
/* ── Import Modal ── */
|
|
.modal-overlay {
|
|
position: fixed; inset: 0;
|
|
background: rgba(0,0,0,.6);
|
|
z-index: 3000;
|
|
display: flex; align-items: center; justify-content: center;
|
|
opacity: 0; pointer-events: none;
|
|
transition: opacity .2s;
|
|
}
|
|
.modal-overlay.show { opacity: 1; pointer-events: all; }
|
|
.modal {
|
|
background: #1e1e2e;
|
|
border: 1px solid #313244;
|
|
border-radius: 12px;
|
|
padding: 24px;
|
|
min-width: 380px;
|
|
max-width: 450px;
|
|
box-shadow: 0 16px 48px rgba(0,0,0,.5);
|
|
}
|
|
.modal h3 { margin-bottom: 12px; color: #cdd6f4; }
|
|
.modal p { color: #6c7086; font-size: 13px; margin-bottom: 16px; line-height: 1.5; }
|
|
.modal-actions { display: flex; gap: 8px; flex-direction: column; }
|
|
.modal-actions button {
|
|
padding: 10px 16px;
|
|
border: 1px solid #313244;
|
|
border-radius: 8px;
|
|
font-size: 13px;
|
|
font-family: inherit;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all .15s;
|
|
text-align: left;
|
|
}
|
|
.modal-actions .merge-btn { background: #313244; color: #a6e3a1; }
|
|
.modal-actions .merge-btn:hover { background: #45475a; }
|
|
.modal-actions .overwrite-btn { background: #313244; color: #f9e2af; }
|
|
.modal-actions .overwrite-btn:hover { background: #45475a; }
|
|
.modal-actions .cancel-btn { background: transparent; color: #6c7086; border-color: transparent; }
|
|
.modal-actions .cancel-btn:hover { color: #cdd6f4; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="app">
|
|
<!-- Sidebar -->
|
|
<div class="sidebar">
|
|
<div class="sidebar-logo"><span>📝</span> Prompt DB</div>
|
|
<div class="sidebar-label" id="catLabel">Categories</div>
|
|
<div class="cat-list" id="catList"></div>
|
|
<div class="cat-add">
|
|
<input type="text" id="newCatInput" placeholder="New category..." />
|
|
<button class="btn-icon" id="addCatBtn" title="Add category">+</button>
|
|
</div>
|
|
<div class="sidebar-actions">
|
|
<button id="exportBtn" title="Export database">📤 Export</button>
|
|
<button id="importBtn" title="Import database">📥 Import</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Main -->
|
|
<div class="main">
|
|
<div class="toolbar">
|
|
<div class="toolbar-title" id="toolbarTitle">All Prompts</div>
|
|
<div class="view-toggle">
|
|
<button id="viewGrid" class="active" title="Grid view">▦</button>
|
|
<button id="viewList" title="List view">☰</button>
|
|
</div>
|
|
<select class="sort-select" id="sortSelect">
|
|
<option value="custom">Custom</option>
|
|
<option value="az">A → Z</option>
|
|
<option value="za">Z → A</option>
|
|
<option value="newest">Newest</option>
|
|
<option value="oldest">Oldest</option>
|
|
<option value="category">Category</option>
|
|
</select>
|
|
<input type="text" class="search-input" id="searchInput" placeholder="Search prompts..." />
|
|
<button class="btn btn-primary" id="newPromptBtn">+ New Prompt</button>
|
|
</div>
|
|
<div class="prompt-grid" id="promptGrid"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Drawer -->
|
|
<div class="drawer-overlay" id="drawerOverlay"></div>
|
|
<div class="drawer" id="drawer">
|
|
<div class="drawer-header">
|
|
<h3 id="drawerTitle">New Prompt</h3>
|
|
<button class="drawer-close" id="drawerClose">✕</button>
|
|
</div>
|
|
<div class="drawer-body">
|
|
<div class="field">
|
|
<label>Name</label>
|
|
<input type="text" id="editName" placeholder="Give your prompt a name..." />
|
|
</div>
|
|
<div class="field">
|
|
<label>Category</label>
|
|
<select id="editCategory"></select>
|
|
</div>
|
|
<div class="field">
|
|
<label>Prompt Text</label>
|
|
<textarea id="editText" placeholder="Write your prompt here..."></textarea>
|
|
</div>
|
|
<!-- LoRA Section -->
|
|
<div class="lora-section">
|
|
<div class="lora-section-header">
|
|
<span class="lora-section-title">📖 Attached LoRAs</span>
|
|
</div>
|
|
<div class="lora-list" id="loraList"></div>
|
|
<div class="lora-add-row">
|
|
<select id="loraSelect">
|
|
<option value="">Add a LoRA...</option>
|
|
</select>
|
|
<button class="btn-icon" id="addLoraBtn" title="Add LoRA" style="width:32px;height:32px;font-size:16px;color:#f9e2af;border-color:#45475a;">+</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="drawer-footer">
|
|
<button class="btn btn-danger btn-sm" id="editDelete" style="display:none;">Delete</button>
|
|
<div style="flex:1"></div>
|
|
<button class="btn btn-ghost btn-sm" id="editCancel">Cancel</button>
|
|
<button class="btn btn-primary btn-sm" id="editSave">Save</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Toast -->
|
|
<div class="toast" id="toast"></div>
|
|
|
|
<!-- Import Modal -->
|
|
<div class="modal-overlay" id="importModal">
|
|
<div class="modal">
|
|
<h3>📥 Import Database</h3>
|
|
<p>Choose how to import the selected file:</p>
|
|
<div class="modal-actions">
|
|
<button class="merge-btn" id="importMerge">🔀 Merge / Append — adds new, keeps existing</button>
|
|
<button class="overwrite-btn" id="importOverwrite">⚠️ Overwrite — replaces everything</button>
|
|
<button class="cancel-btn" id="importCancel">Cancel</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<input type="file" id="importFile" accept=".json" style="display:none" />
|
|
|
|
<script>
|
|
// ── State ──
|
|
let data = { categories: [], prompts: [] };
|
|
let selectedCategory = null;
|
|
let editingPrompt = null;
|
|
let searchQuery = "";
|
|
let availableLoras = [];
|
|
let currentLoras = [];
|
|
let viewMode = localStorage.getItem("pdb_view_mode") || "grid";
|
|
let sortMode = localStorage.getItem("pdb_sort_mode") || "custom";
|
|
let pendingImportData = null; // Holds parsed JSON during import flow
|
|
|
|
const BASE = window.location.origin;
|
|
|
|
const API = {
|
|
async getAll() {
|
|
const r = await fetch(`${BASE}/prompt_db/all`);
|
|
return r.json();
|
|
},
|
|
async getLoras() {
|
|
const r = await fetch(`${BASE}/prompt_db/loras`);
|
|
const d = await r.json();
|
|
return d.loras || [];
|
|
},
|
|
async addPrompt(category, name, text, loras) {
|
|
return fetch(`${BASE}/prompt_db/prompt`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ category, name, text, loras }),
|
|
}).then(r => r.json());
|
|
},
|
|
async updatePrompt(id, payload) {
|
|
return fetch(`${BASE}/prompt_db/prompt/${id}`, {
|
|
method: "PUT",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(payload),
|
|
}).then(r => r.json());
|
|
},
|
|
async deletePrompt(id) {
|
|
return fetch(`${BASE}/prompt_db/prompt/${id}`, { method: "DELETE" }).then(r => r.json());
|
|
},
|
|
async addCategory(name) {
|
|
return fetch(`${BASE}/prompt_db/category`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ name }),
|
|
}).then(r => r.json());
|
|
},
|
|
async deleteCategory(name) {
|
|
return fetch(`${BASE}/prompt_db/category/${encodeURIComponent(name)}`, {
|
|
method: "DELETE",
|
|
}).then(r => r.json());
|
|
},
|
|
async reorderCategories(categories) {
|
|
return fetch(`${BASE}/prompt_db/categories/reorder`, {
|
|
method: "PUT",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ categories }),
|
|
}).then(r => r.json());
|
|
},
|
|
async reorderPrompts(promptIds) {
|
|
return fetch(`${BASE}/prompt_db/prompts/reorder`, {
|
|
method: "PUT",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ prompt_ids: promptIds }),
|
|
}).then(r => r.json());
|
|
},
|
|
};
|
|
|
|
// ── Toast ──
|
|
function toast(msg, type = "success") {
|
|
const el = document.getElementById("toast");
|
|
el.textContent = msg;
|
|
el.className = `toast ${type} show`;
|
|
setTimeout(() => el.classList.remove("show"), 2500);
|
|
}
|
|
|
|
function esc(s) {
|
|
if (!s) return "";
|
|
return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");
|
|
}
|
|
|
|
// ── Render categories ──
|
|
function renderCategories() {
|
|
const list = document.getElementById("catList");
|
|
list.innerHTML = "";
|
|
|
|
// Category counter
|
|
document.getElementById("catLabel").textContent = `Categories (${data.categories.length})`;
|
|
|
|
const allEl = document.createElement("div");
|
|
allEl.className = `cat-item ${selectedCategory === null ? "active" : ""}`;
|
|
const allCount = data.prompts.length;
|
|
allEl.innerHTML = `<span>📋 All</span><span class="cat-count">${allCount}</span>`;
|
|
allEl.onclick = () => { selectedCategory = null; render(); };
|
|
list.appendChild(allEl);
|
|
|
|
for (const cat of data.categories) {
|
|
const count = data.prompts.filter(p => p.category === cat).length;
|
|
const el = document.createElement("div");
|
|
el.className = `cat-item ${selectedCategory === cat ? "active" : ""}`;
|
|
el.draggable = true;
|
|
el.dataset.category = cat;
|
|
el.innerHTML = `
|
|
<span>${esc(cat)}</span>
|
|
<span style="display:flex;align-items:center;gap:4px">
|
|
<span class="cat-count">${count}</span>
|
|
<button class="cat-del" title="Delete">✕</button>
|
|
</span>
|
|
`;
|
|
el.onclick = () => {
|
|
selectedCategory = cat;
|
|
render();
|
|
};
|
|
el.querySelector(".cat-del").onclick = async (e) => {
|
|
e.stopPropagation();
|
|
if (!confirm(`Delete category "${cat}" and all its prompts?`)) return;
|
|
await API.deleteCategory(cat);
|
|
if (selectedCategory === cat) selectedCategory = null;
|
|
data = await API.getAll();
|
|
render();
|
|
toast(`Category "${cat}" deleted`);
|
|
};
|
|
|
|
// ── Category drag (reorder) ──
|
|
el.addEventListener("dragstart", (e) => {
|
|
e.dataTransfer.setData("text/x-pdb-category", cat);
|
|
e.dataTransfer.effectAllowed = "move";
|
|
});
|
|
|
|
// ── Drop zone: accept prompts AND categories ──
|
|
el.addEventListener("dragover", (e) => {
|
|
e.preventDefault();
|
|
// Determine if it's a category reorder or prompt move
|
|
if (e.dataTransfer.types.includes("text/x-pdb-category")) {
|
|
// Category reorder — show insert line
|
|
const rect = el.getBoundingClientRect();
|
|
const midY = rect.top + rect.height / 2;
|
|
el.classList.remove("drag-over", "drag-insert-before", "drag-insert-after");
|
|
el.classList.add(e.clientY < midY ? "drag-insert-before" : "drag-insert-after");
|
|
e.dataTransfer.dropEffect = "move";
|
|
} else if (e.dataTransfer.types.includes("text/x-pdb-prompt")) {
|
|
// Prompt move — highlight category
|
|
el.classList.remove("drag-insert-before", "drag-insert-after");
|
|
el.classList.add("drag-over");
|
|
e.dataTransfer.dropEffect = "move";
|
|
}
|
|
});
|
|
|
|
el.addEventListener("dragleave", () => {
|
|
el.classList.remove("drag-over", "drag-insert-before", "drag-insert-after");
|
|
});
|
|
|
|
el.addEventListener("drop", async (e) => {
|
|
e.preventDefault();
|
|
el.classList.remove("drag-over", "drag-insert-before", "drag-insert-after");
|
|
|
|
// Handle prompt drop → move to this category
|
|
const promptId = e.dataTransfer.getData("text/x-pdb-prompt");
|
|
if (promptId) {
|
|
const prompt = data.prompts.find(p => p.id === promptId);
|
|
if (prompt && prompt.category !== cat) {
|
|
await API.updatePrompt(promptId, { category: cat });
|
|
data = await API.getAll();
|
|
render();
|
|
toast(`Moved "${prompt.name}" → ${cat}`);
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Handle category drop → reorder
|
|
const draggedCat = e.dataTransfer.getData("text/x-pdb-category");
|
|
if (draggedCat && draggedCat !== cat) {
|
|
const newOrder = [...data.categories];
|
|
const fromIdx = newOrder.indexOf(draggedCat);
|
|
if (fromIdx === -1) return;
|
|
newOrder.splice(fromIdx, 1);
|
|
const toIdx = newOrder.indexOf(cat);
|
|
const rect = el.getBoundingClientRect();
|
|
const midY = rect.top + rect.height / 2;
|
|
const insertIdx = e.clientY < midY ? toIdx : toIdx + 1;
|
|
newOrder.splice(insertIdx, 0, draggedCat);
|
|
await API.reorderCategories(newOrder);
|
|
data = await API.getAll();
|
|
render();
|
|
toast(`Reordered categories`);
|
|
}
|
|
});
|
|
|
|
list.appendChild(el);
|
|
}
|
|
}
|
|
|
|
// ── Render prompts grid ──
|
|
function renderPrompts() {
|
|
const grid = document.getElementById("promptGrid");
|
|
grid.innerHTML = "";
|
|
|
|
let prompts = selectedCategory
|
|
? data.prompts.filter(p => p.category === selectedCategory)
|
|
: [...data.prompts];
|
|
|
|
if (searchQuery) {
|
|
const q = searchQuery.toLowerCase();
|
|
prompts = prompts.filter(p =>
|
|
p.name.toLowerCase().includes(q) ||
|
|
p.text.toLowerCase().includes(q) ||
|
|
p.category.toLowerCase().includes(q)
|
|
);
|
|
}
|
|
|
|
// Apply sort
|
|
if (sortMode === "az") {
|
|
prompts.sort((a, b) => a.name.localeCompare(b.name));
|
|
} else if (sortMode === "za") {
|
|
prompts.sort((a, b) => b.name.localeCompare(a.name));
|
|
} else if (sortMode === "newest") {
|
|
prompts.reverse();
|
|
} else if (sortMode === "category") {
|
|
prompts.sort((a, b) => a.category.localeCompare(b.category));
|
|
}
|
|
// "oldest" and "custom" keep original order
|
|
|
|
// Apply view mode
|
|
grid.classList.toggle("list-view", viewMode === "list");
|
|
|
|
const title = selectedCategory || "All Prompts";
|
|
document.getElementById("toolbarTitle").textContent = `${title} (${prompts.length})`;
|
|
|
|
if (prompts.length === 0) {
|
|
grid.innerHTML = `
|
|
<div class="empty">
|
|
<div class="empty-icon">${searchQuery ? "🔍" : "📭"}</div>
|
|
<div class="empty-title">${searchQuery ? "No prompts match your search" : "No prompts yet"}</div>
|
|
<div class="empty-hint">${searchQuery ? "Try a different search term" : 'Click "+ New Prompt" to create one'}</div>
|
|
</div>`;
|
|
return;
|
|
}
|
|
|
|
for (const p of prompts) {
|
|
const hasLoras = p.loras && p.loras.length > 0;
|
|
const card = document.createElement("div");
|
|
card.className = "prompt-card";
|
|
card.draggable = true;
|
|
|
|
// ── Prompt drag ──
|
|
card.addEventListener("dragstart", (e) => {
|
|
e.dataTransfer.setData("text/x-pdb-prompt", p.id);
|
|
e.dataTransfer.effectAllowed = "move";
|
|
setTimeout(() => card.classList.add("dragging"), 0);
|
|
});
|
|
card.addEventListener("dragend", () => {
|
|
card.classList.remove("dragging");
|
|
// Clean up all drop indicators
|
|
document.querySelectorAll(".prompt-card.drop-left, .prompt-card.drop-right")
|
|
.forEach(c => c.classList.remove("drop-left", "drop-right"));
|
|
});
|
|
|
|
// ── Prompt-to-prompt drop (reorder) ──
|
|
card.addEventListener("dragover", (e) => {
|
|
if (!e.dataTransfer.types.includes("text/x-pdb-prompt")) return;
|
|
e.preventDefault();
|
|
e.dataTransfer.dropEffect = "move";
|
|
const rect = card.getBoundingClientRect();
|
|
const midX = rect.left + rect.width / 2;
|
|
card.classList.remove("drop-left", "drop-right");
|
|
card.classList.add(e.clientX < midX ? "drop-left" : "drop-right");
|
|
});
|
|
|
|
card.addEventListener("dragleave", () => {
|
|
card.classList.remove("drop-left", "drop-right");
|
|
});
|
|
|
|
card.addEventListener("drop", async (e) => {
|
|
e.preventDefault();
|
|
const insertBefore = card.classList.contains("drop-left");
|
|
card.classList.remove("drop-left", "drop-right");
|
|
|
|
const draggedId = e.dataTransfer.getData("text/x-pdb-prompt");
|
|
if (!draggedId || draggedId === p.id) return;
|
|
|
|
// Build new order from the currently displayed prompts
|
|
const currentPrompts = selectedCategory
|
|
? data.prompts.filter(pr => pr.category === selectedCategory)
|
|
: data.prompts;
|
|
const ids = currentPrompts.map(pr => pr.id).filter(id => id !== draggedId);
|
|
const targetIdx = ids.indexOf(p.id);
|
|
if (targetIdx === -1) return;
|
|
const newIdx = insertBefore ? targetIdx : targetIdx + 1;
|
|
ids.splice(newIdx, 0, draggedId);
|
|
|
|
// Include all other prompts not in the current view
|
|
const displayedSet = new Set(ids);
|
|
const fullOrder = [...ids];
|
|
for (const pr of data.prompts) {
|
|
if (!displayedSet.has(pr.id)) fullOrder.push(pr.id);
|
|
}
|
|
|
|
await API.reorderPrompts(fullOrder);
|
|
data = await API.getAll();
|
|
// Auto-switch to Custom sort
|
|
sortMode = "custom";
|
|
localStorage.setItem("pdb_sort_mode", "custom");
|
|
document.getElementById("sortSelect").value = "custom";
|
|
render();
|
|
toast("Prompts reordered");
|
|
});
|
|
|
|
let loraHtml = "";
|
|
if (hasLoras) {
|
|
loraHtml = `<div class="card-loras">`;
|
|
for (const l of p.loras) {
|
|
const shortName = (l.name || "").replace(/\.safetensors$/, "");
|
|
loraHtml += `<span class="card-lora-tag">🔗 ${esc(shortName)} (${(l.strength || 1).toFixed(2)})</span>`;
|
|
}
|
|
loraHtml += `</div>`;
|
|
}
|
|
|
|
card.innerHTML = `
|
|
<div class="card-header">
|
|
<div class="card-name">${esc(p.name)}${hasLoras ? ' <span class="card-lora-badge">📖 LoRA</span>' : ''}</div>
|
|
<div class="card-badge">${esc(p.category)}</div>
|
|
</div>
|
|
<div class="card-text">${esc(p.text)}</div>
|
|
${loraHtml}
|
|
<div class="card-actions">
|
|
<button class="btn btn-ghost btn-sm edit-btn">✏️ Edit</button>
|
|
<button class="btn btn-ghost btn-sm del-btn" style="color:#f38ba8;border-color:#45475a">🗑 Delete</button>
|
|
</div>
|
|
`;
|
|
card.querySelector(".edit-btn").onclick = () => openDrawer(p);
|
|
card.querySelector(".del-btn").onclick = async (e) => {
|
|
e.stopPropagation();
|
|
if (!confirm(`Delete prompt "${p.name}"?`)) return;
|
|
await API.deletePrompt(p.id);
|
|
data = await API.getAll();
|
|
render();
|
|
toast(`Prompt "${p.name}" deleted`);
|
|
};
|
|
grid.appendChild(card);
|
|
}
|
|
}
|
|
|
|
// ── LoRA list in drawer ──
|
|
function renderLoraList() {
|
|
const list = document.getElementById("loraList");
|
|
list.innerHTML = "";
|
|
|
|
if (currentLoras.length === 0) {
|
|
list.innerHTML = `<div class="lora-empty">No LoRAs attached</div>`;
|
|
return;
|
|
}
|
|
|
|
for (let i = 0; i < currentLoras.length; i++) {
|
|
const lora = currentLoras[i];
|
|
const shortName = (lora.name || "").replace(/\.safetensors$/, "");
|
|
|
|
const item = document.createElement("div");
|
|
item.className = "lora-item";
|
|
item.innerHTML = `
|
|
<span class="lora-item-name" title="${esc(lora.name)}">🔗 ${esc(shortName)}</span>
|
|
<input type="number" class="lora-item-strength" value="${lora.strength}" step="0.05" min="-2" max="2" />
|
|
<button class="lora-item-del" title="Remove">✕</button>
|
|
`;
|
|
|
|
item.querySelector(".lora-item-strength").onchange = (e) => {
|
|
currentLoras[i].strength = parseFloat(e.target.value) || 1.0;
|
|
};
|
|
item.querySelector(".lora-item-del").onclick = () => {
|
|
currentLoras.splice(i, 1);
|
|
renderLoraList();
|
|
};
|
|
|
|
list.appendChild(item);
|
|
}
|
|
}
|
|
|
|
function populateLoraSelect() {
|
|
const sel = document.getElementById("loraSelect");
|
|
sel.innerHTML = `<option value="">Add a LoRA...</option>`;
|
|
for (const l of availableLoras) {
|
|
sel.innerHTML += `<option value="${esc(l)}">${esc(l)}</option>`;
|
|
}
|
|
}
|
|
|
|
// ── Drawer ──
|
|
async function openDrawer(prompt = null) {
|
|
editingPrompt = prompt;
|
|
const isNew = !prompt;
|
|
|
|
document.getElementById("drawerTitle").textContent = isNew ? "New Prompt" : "Edit Prompt";
|
|
document.getElementById("editName").value = prompt?.name || "";
|
|
document.getElementById("editText").value = prompt?.text || "";
|
|
document.getElementById("editDelete").style.display = isNew ? "none" : "";
|
|
|
|
// Populate category select
|
|
const sel = document.getElementById("editCategory");
|
|
sel.innerHTML = data.categories
|
|
.map(c => `<option value="${esc(c)}" ${c === (prompt?.category || selectedCategory || data.categories[0]) ? "selected" : ""}>${esc(c)}</option>`)
|
|
.join("");
|
|
|
|
// Load LoRAs for this prompt
|
|
currentLoras = prompt?.loras ? JSON.parse(JSON.stringify(prompt.loras)) : [];
|
|
renderLoraList();
|
|
|
|
// Fetch available LoRA files
|
|
try {
|
|
availableLoras = await API.getLoras();
|
|
} catch (e) {
|
|
console.error("Failed to load LoRA list:", e);
|
|
availableLoras = [];
|
|
}
|
|
populateLoraSelect();
|
|
|
|
document.getElementById("drawerOverlay").classList.add("open");
|
|
document.getElementById("drawer").classList.add("open");
|
|
setTimeout(() => document.getElementById("editName").focus(), 200);
|
|
}
|
|
|
|
function closeDrawer() {
|
|
document.getElementById("drawerOverlay").classList.remove("open");
|
|
document.getElementById("drawer").classList.remove("open");
|
|
editingPrompt = null;
|
|
currentLoras = [];
|
|
}
|
|
|
|
function render() {
|
|
renderCategories();
|
|
renderPrompts();
|
|
}
|
|
|
|
// ── Event listeners ──
|
|
document.getElementById("addCatBtn").onclick = async () => {
|
|
const input = document.getElementById("newCatInput");
|
|
const name = input.value.trim();
|
|
if (!name) return;
|
|
const res = await API.addCategory(name);
|
|
if (res.error) { toast(res.error, "error"); return; }
|
|
input.value = "";
|
|
data = await API.getAll();
|
|
selectedCategory = name;
|
|
render();
|
|
toast(`Category "${name}" added`);
|
|
};
|
|
|
|
document.getElementById("newCatInput").addEventListener("keydown", (e) => {
|
|
if (e.key === "Enter") document.getElementById("addCatBtn").click();
|
|
});
|
|
|
|
document.getElementById("newPromptBtn").onclick = () => openDrawer();
|
|
document.getElementById("drawerOverlay").onclick = closeDrawer;
|
|
document.getElementById("drawerClose").onclick = closeDrawer;
|
|
document.getElementById("editCancel").onclick = closeDrawer;
|
|
|
|
// Add LoRA button
|
|
document.getElementById("addLoraBtn").onclick = () => {
|
|
const sel = document.getElementById("loraSelect");
|
|
const val = sel.value;
|
|
if (!val) return;
|
|
|
|
// Check if already added
|
|
if (currentLoras.some(l => l.name === val)) {
|
|
toast("LoRA already attached", "error");
|
|
return;
|
|
}
|
|
|
|
currentLoras.push({ name: val, strength: 1.0 });
|
|
renderLoraList();
|
|
sel.value = "";
|
|
};
|
|
|
|
document.getElementById("editSave").onclick = async () => {
|
|
const name = document.getElementById("editName").value.trim();
|
|
const category = document.getElementById("editCategory").value;
|
|
const text = document.getElementById("editText").value;
|
|
|
|
if (!name) { toast("Name is required", "error"); return; }
|
|
if (!category) { toast("Select a category", "error"); return; }
|
|
|
|
if (editingPrompt) {
|
|
await API.updatePrompt(editingPrompt.id, { name, category, text, loras: currentLoras });
|
|
toast(`Prompt "${name}" updated`);
|
|
} else {
|
|
await API.addPrompt(category, name, text, currentLoras);
|
|
toast(`Prompt "${name}" created`);
|
|
}
|
|
|
|
data = await API.getAll();
|
|
closeDrawer();
|
|
render();
|
|
};
|
|
|
|
document.getElementById("editDelete").onclick = async () => {
|
|
if (!editingPrompt) return;
|
|
if (!confirm(`Delete prompt "${editingPrompt.name}"?`)) return;
|
|
await API.deletePrompt(editingPrompt.id);
|
|
toast(`Prompt "${editingPrompt.name}" deleted`);
|
|
data = await API.getAll();
|
|
closeDrawer();
|
|
render();
|
|
};
|
|
|
|
document.getElementById("searchInput").addEventListener("input", (e) => {
|
|
searchQuery = e.target.value;
|
|
renderPrompts();
|
|
});
|
|
|
|
// ── View toggle ──
|
|
function setViewMode(mode) {
|
|
viewMode = mode;
|
|
localStorage.setItem("pdb_view_mode", mode);
|
|
document.getElementById("viewGrid").classList.toggle("active", mode === "grid");
|
|
document.getElementById("viewList").classList.toggle("active", mode === "list");
|
|
renderPrompts();
|
|
}
|
|
document.getElementById("viewGrid").onclick = () => setViewMode("grid");
|
|
document.getElementById("viewList").onclick = () => setViewMode("list");
|
|
|
|
// ── Sort ──
|
|
document.getElementById("sortSelect").value = sortMode;
|
|
document.getElementById("sortSelect").onchange = (e) => {
|
|
sortMode = e.target.value;
|
|
localStorage.setItem("pdb_sort_mode", sortMode);
|
|
renderPrompts();
|
|
};
|
|
|
|
// ── Export ──
|
|
document.getElementById("exportBtn").onclick = async () => {
|
|
try {
|
|
const r = await fetch(`${BASE}/prompt_db/export`);
|
|
const d = await r.json();
|
|
const blob = new Blob([JSON.stringify(d, null, 2)], { type: "application/json" });
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement("a");
|
|
a.href = url;
|
|
a.download = "prompt_db_export.json";
|
|
a.click();
|
|
URL.revokeObjectURL(url);
|
|
toast("Database exported!");
|
|
} catch (e) {
|
|
toast("Export failed", "error");
|
|
}
|
|
};
|
|
|
|
// ── Import ──
|
|
const importFileInput = document.getElementById("importFile");
|
|
const importModal = document.getElementById("importModal");
|
|
|
|
document.getElementById("importBtn").onclick = () => {
|
|
importFileInput.click();
|
|
};
|
|
|
|
importFileInput.onchange = (e) => {
|
|
const file = e.target.files[0];
|
|
if (!file) return;
|
|
const reader = new FileReader();
|
|
reader.onload = () => {
|
|
try {
|
|
pendingImportData = JSON.parse(reader.result);
|
|
if (!pendingImportData.categories || !pendingImportData.prompts) {
|
|
toast("Invalid JSON: must have categories and prompts", "error");
|
|
pendingImportData = null;
|
|
return;
|
|
}
|
|
importModal.classList.add("show");
|
|
} catch (err) {
|
|
toast("Invalid JSON file", "error");
|
|
}
|
|
};
|
|
reader.readAsText(file);
|
|
importFileInput.value = "";
|
|
};
|
|
|
|
async function doImport(mode) {
|
|
importModal.classList.remove("show");
|
|
if (!pendingImportData) return;
|
|
try {
|
|
const r = await fetch(`${BASE}/prompt_db/import`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ mode, data: pendingImportData }),
|
|
});
|
|
const res = await r.json();
|
|
if (res.success) {
|
|
data = await API.getAll();
|
|
render();
|
|
if (mode === "merge") {
|
|
toast(`Imported: +${res.prompts_added} prompts, +${res.categories_added} categories (${res.prompts_skipped} skipped)`);
|
|
} else {
|
|
toast(`Database overwritten: ${res.prompts_added} prompts, ${res.categories_added} categories`);
|
|
}
|
|
} else {
|
|
toast(res.error || "Import failed", "error");
|
|
}
|
|
} catch (e) {
|
|
toast("Import failed", "error");
|
|
}
|
|
pendingImportData = null;
|
|
}
|
|
|
|
document.getElementById("importMerge").onclick = () => doImport("merge");
|
|
document.getElementById("importOverwrite").onclick = () => {
|
|
if (confirm("This will replace ALL your prompts. Are you sure?")) {
|
|
doImport("overwrite");
|
|
}
|
|
};
|
|
document.getElementById("importCancel").onclick = () => {
|
|
importModal.classList.remove("show");
|
|
pendingImportData = null;
|
|
};
|
|
|
|
// ── Keyboard shortcuts ──
|
|
document.addEventListener("keydown", (e) => {
|
|
if (e.key === "Escape") {
|
|
if (importModal.classList.contains("show")) {
|
|
importModal.classList.remove("show");
|
|
pendingImportData = null;
|
|
} else {
|
|
closeDrawer();
|
|
}
|
|
}
|
|
// Ctrl+N = new prompt
|
|
if (e.ctrlKey && e.key === "n") {
|
|
e.preventDefault();
|
|
openDrawer();
|
|
}
|
|
// / = focus search (when not in input)
|
|
if (e.key === "/" && !e.ctrlKey && document.activeElement.tagName !== "INPUT" && document.activeElement.tagName !== "TEXTAREA") {
|
|
e.preventDefault();
|
|
document.getElementById("searchInput").focus();
|
|
}
|
|
});
|
|
|
|
// ── Init ──
|
|
(async () => {
|
|
data = await API.getAll();
|
|
// Restore view mode on load
|
|
document.getElementById("viewGrid").classList.toggle("active", viewMode === "grid");
|
|
document.getElementById("viewList").classList.toggle("active", viewMode === "list");
|
|
document.getElementById("sortSelect").value = sortMode;
|
|
render();
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|