This commit is contained in:
th committed 2026-04-07 21:58:45 +02:00
1 parent a9603aa0e8
commit 719f9d51ff
13 files changed
+625 -70

No files matched your search

+23 -2
View File
@@ -1,9 +1,12 @@
// ── Shared app state ──
import { esc } from './util.js';
export const state = {
cards: [],
buckets: [],
activeBucket: 'all',
activeTags: [],
activeGroup: null,
sortMode: localStorage.getItem('hyprcrd-sort') || 'manual',
editingId: null,
@@ -15,8 +18,8 @@ export const state = {
previewVisible: false,
};
export const SORT_MODES = ['manual', 'newest', 'oldest', 'alpha'];
export const SORT_ICONS = { manual: 'ph-dots-six', newest: 'ph-sort-descending', oldest: 'ph-sort-ascending', alpha: 'ph-text-aa' };
export const SORT_MODES = ['manual', 'newest', 'oldest', 'alpha', 'tag'];
export const SORT_ICONS = { manual: 'ph-dots-six', newest: 'ph-sort-descending', oldest: 'ph-sort-ascending', alpha: 'ph-text-aa', tag: 'ph-hash' };
export const CARD_COLORS = [
{ name: 'sky', hex: '#38bdf8' }, { name: 'violet', hex: '#8b5cf6' },
@@ -26,12 +29,30 @@ export const CARD_COLORS = [
{ name: 'lime', hex: '#a3e635' }, { name: 'slate', hex: '#94a3b8' },
];
export function parseTags(card) {
return (card.tags || '').split(',').filter(Boolean);
}
export function tagChipHtml(tag) {
const parts = tag.split('/');
const segs = parts.map((p, i) => {
const path = parts.slice(0, i + 1).join('/');
return `<span class="tag-seg" data-tag="${path}">${i === 0 ? '#' : ''}${esc(p)}</span>`;
});
return `<span class="tag-chip">${segs.join('<span class="tag-sep">/</span>')}</span>`;
}
export function sortedCards(cards) {
const arr = [...cards];
switch (state.sortMode) {
case 'newest': return arr.sort((a, b) => (b.created_at || '').localeCompare(a.created_at || ''));
case 'oldest': return arr.sort((a, b) => (a.created_at || '').localeCompare(b.created_at || ''));
case 'alpha': return arr.sort((a, b) => (a.title || '').localeCompare(b.title || ''));
case 'tag': return arr.sort((a, b) => {
const at = (a.tags || '').split(',')[0] || '\uffff';
const bt = (b.tags || '').split(',')[0] || '\uffff';
return at.localeCompare(bt);
});
default: return arr.sort((a, b) => (a.position || 0) - (b.position || 0));
}
}