mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-11-19 10:38:20 +01:00
feat: add colors to notebook icons and 16 more built-in icons
This commit is contained in:
1 parent
2ddefc51e4
commit
48e39a0cbc
4 files changed
+235
-13
No files matched your search
@@ -54,6 +54,50 @@
|
||||
<path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18" />
|
||||
{:else if icon === 'plane'}
|
||||
<path d="M22 2 9.5 14.5M22 2l-7 20-4-8-8-4Z" />
|
||||
{:else if icon === 'music'}
|
||||
<path d="M9 18V5l12-2v13" />
|
||||
<circle cx="6" cy="18" r="3" />
|
||||
<circle cx="18" cy="16" r="3" />
|
||||
{:else if icon === 'camera'}
|
||||
<path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2Z" />
|
||||
<circle cx="12" cy="13" r="4" />
|
||||
{:else if icon === 'film'}
|
||||
<rect x="2" y="2" width="20" height="20" rx="2" />
|
||||
<path d="M7 2v20M17 2v20M2 12h20M2 7h5M2 17h5M17 17h5M17 7h5" />
|
||||
{:else if icon === 'gamepad'}
|
||||
<path d="M6 11h4M8 9v4M15 12h.01M18 10h.01" />
|
||||
<path d="M17.32 5H6.68a4 4 0 0 0-3.978 3.59c-.006.052-.01.101-.017.152C2.604 9.416 2 14.456 2 16a3 3 0 0 0 3 3c1 0 1.5-.5 2-1l1.414-1.414A2 2 0 0 1 9.828 16h4.344a2 2 0 0 1 1.414.586L17 18c.5.5 1 1 2 1a3 3 0 0 0 3-3c0-1.545-.604-6.584-.685-7.258-.007-.05-.011-.1-.017-.151A4 4 0 0 0 17.32 5Z" />
|
||||
{:else if icon === 'cart'}
|
||||
<circle cx="9" cy="21" r="1" />
|
||||
<circle cx="20" cy="21" r="1" />
|
||||
<path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6" />
|
||||
{:else if icon === 'money'}
|
||||
<path d="M12 1v22M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6" />
|
||||
{:else if icon === 'health'}
|
||||
<path d="M22 12h-4l-3 9L9 3l-3 9H2" />
|
||||
{:else if icon === 'food'}
|
||||
<path d="M3 2v7c0 1.1.9 2 2 2h4a2 2 0 0 0 2-2V2M7 2v20M21 15V2a5 5 0 0 0-5 5v6c0 1.1.9 2 2 2h3Zm0 0v7" />
|
||||
{:else if icon === 'coffee'}
|
||||
<path d="M18 8h1a4 4 0 0 1 0 8h-1M2 8h16v9a4 4 0 0 1-4 4H6a4 4 0 0 1-4-4ZM6 1v3M10 1v3M14 1v3" />
|
||||
{:else if icon === 'leaf'}
|
||||
<path d="M11 20A7 7 0 0 1 9.8 6.1C15.5 5 17 4.48 19 2c1 2 2 4.18 2 8 0 5.5-4.78 10-10 10Z" />
|
||||
<path d="M2 21c0-3 1.85-5.36 5.08-6C9.5 14.52 12 13 13 12" />
|
||||
{:else if icon === 'users'}
|
||||
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2" />
|
||||
<circle cx="9" cy="7" r="4" />
|
||||
<path d="M23 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75" />
|
||||
{:else if icon === 'chat'}
|
||||
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2Z" />
|
||||
{:else if icon === 'mail'}
|
||||
<rect x="2" y="4" width="20" height="16" rx="2" />
|
||||
<path d="m22 6-10 7L2 6" />
|
||||
{:else if icon === 'lock'}
|
||||
<rect x="3" y="11" width="18" height="11" rx="2" />
|
||||
<path d="M7 11V7a5 5 0 0 1 10 0v4" />
|
||||
{:else if icon === 'wrench'}
|
||||
<path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76Z" />
|
||||
{:else if icon === 'pen'}
|
||||
<path d="M17 3a2.83 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z" />
|
||||
{:else}
|
||||
<path d="M12 3a9 9 0 1 0 0 18h1.5a1.5 1.5 0 0 0 0-3H12a1.5 1.5 0 0 1 0-3h3a6 6 0 0 0 0-12Z" />
|
||||
<path d="M7.5 10h.01M9.5 6.5h.01M14.5 6.5h.01M17 10h.01" />
|
||||
|
||||
@@ -38,11 +38,12 @@
|
||||
import TagStylePicker from './TagStylePicker.svelte';
|
||||
import {
|
||||
NOTEBOOK_ICON_OPTIONS,
|
||||
decodeBuiltinNotebookIcon,
|
||||
decodeNotebookIcon,
|
||||
encodeBuiltinNotebookIcon,
|
||||
normalizeNotebookIconKey,
|
||||
type NotebookIconId
|
||||
} from '$lib/utils/notebook-icons';
|
||||
import { TAG_COLOR_PRESETS } from '$lib/utils/tag-styles';
|
||||
|
||||
let { onViewChanged = () => {}, onBeforeNoteChange = async () => true, onBeforePathMutation = async () => null, onPathsMoved = async (_old: string, _next: string) => {} }: {
|
||||
onViewChanged?: () => void;
|
||||
@@ -134,6 +135,7 @@
|
||||
let contextMenu = $state<{ x: number; y: number; notebook: NotebookEntry } | null>(null);
|
||||
let iconPickerNotebook = $state<NotebookEntry | null>(null);
|
||||
let iconPickerElement = $state<HTMLDivElement | null>(null);
|
||||
let iconPickerColor = $state<string | null>(null);
|
||||
let trashContextMenu = $state<{ x: number; y: number } | null>(null);
|
||||
let tagsCollapsed = $state(true);
|
||||
let tagContextMenu = $state<{ x: number; y: number; tag: string } | null>(null);
|
||||
@@ -633,6 +635,7 @@
|
||||
|
||||
async function openIconPicker(nb: NotebookEntry) {
|
||||
contextMenu = null;
|
||||
iconPickerColor = decodeNotebookIcon(get(notebookIcons)[normalizeNotebookIconKey(nb.relative_path)])?.color ?? null;
|
||||
iconPickerNotebook = nb;
|
||||
await tick();
|
||||
if (!ownerIsCurrent()) return;
|
||||
@@ -647,22 +650,29 @@
|
||||
notebookIcons.set(icons);
|
||||
}
|
||||
|
||||
async function handleBuiltinIcon(nb: NotebookEntry, icon: NotebookIconId) {
|
||||
async function handleBuiltinIcon(nb: NotebookEntry, icon: NotebookIconId, close = true) {
|
||||
if (!ownerVault || !ownerIsCurrent()) return;
|
||||
const key = normalizeNotebookIconKey(nb.relative_path);
|
||||
const latest = notebookAppearance.choose(ownerVault, key);
|
||||
const value = encodeBuiltinNotebookIcon(icon);
|
||||
const value = encodeBuiltinNotebookIcon(icon, iconPickerColor);
|
||||
iconError = '';
|
||||
try {
|
||||
await notebookAppearance.run(ownerVault, key, latest,
|
||||
() => setNotebookIcon(ownerVault, key, value),
|
||||
() => publishNotebookIcon(key, value));
|
||||
if (ownerIsCurrent() && latest()) iconPickerNotebook = null;
|
||||
if (close && ownerIsCurrent() && latest()) iconPickerNotebook = null;
|
||||
} catch (e) {
|
||||
if (ownerIsCurrent() && latest()) iconError = String(e);
|
||||
}
|
||||
}
|
||||
|
||||
// The color is kept for the next built-in icon when none is set yet.
|
||||
function handleIconColor(nb: NotebookEntry, color: string | null) {
|
||||
iconPickerColor = color;
|
||||
const current = decodeNotebookIcon(get(notebookIcons)[normalizeNotebookIconKey(nb.relative_path)]);
|
||||
if (current) void handleBuiltinIcon(nb, current.icon, false);
|
||||
}
|
||||
|
||||
async function handleCustomIcon(nb: NotebookEntry) {
|
||||
if (!ownerVault || !ownerIsCurrent()) return;
|
||||
const key = normalizeNotebookIconKey(nb.relative_path);
|
||||
@@ -1069,7 +1079,8 @@
|
||||
{#each NOTEBOOK_ICON_OPTIONS as option}
|
||||
<button
|
||||
class="icon-picker-option"
|
||||
class:active={$notebookIcons[normalizeNotebookIconKey(iconPickerNotebook.relative_path)] === encodeBuiltinNotebookIcon(option.id)}
|
||||
class:active={decodeNotebookIcon($notebookIcons[normalizeNotebookIconKey(iconPickerNotebook.relative_path)])?.icon === option.id}
|
||||
style:color={iconPickerColor}
|
||||
aria-label={option.label}
|
||||
title={option.label}
|
||||
onclick={() => handleBuiltinIcon(iconPickerNotebook!, option.id)}
|
||||
@@ -1079,6 +1090,36 @@
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="icon-color-section">
|
||||
<span class="icon-color-label">Color</span>
|
||||
<div class="icon-swatches">
|
||||
<button
|
||||
class="icon-swatch none"
|
||||
class:active={!iconPickerColor}
|
||||
aria-label="Use default color"
|
||||
title="Default color"
|
||||
onclick={() => handleIconColor(iconPickerNotebook!, null)}
|
||||
></button>
|
||||
{#each TAG_COLOR_PRESETS as preset (preset)}
|
||||
<button
|
||||
class="icon-swatch"
|
||||
class:active={iconPickerColor === preset}
|
||||
style:background={preset}
|
||||
aria-label={`Use ${preset}`}
|
||||
title={preset}
|
||||
onclick={() => handleIconColor(iconPickerNotebook!, preset)}
|
||||
></button>
|
||||
{/each}
|
||||
<label class="icon-swatch custom" title="Custom color">
|
||||
<input
|
||||
type="color"
|
||||
value={iconPickerColor?.length === 7 ? iconPickerColor : '#5b6abf'}
|
||||
oninput={(e) => handleIconColor(iconPickerNotebook!, e.currentTarget.value)}
|
||||
aria-label="Custom icon color"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="icon-picker-actions">
|
||||
<button onclick={() => handleCustomIcon(iconPickerNotebook!)}>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" /><circle cx="8.5" cy="8.5" r="1.5" /><path d="m21 15-5-5L5 21" /></svg>
|
||||
@@ -1090,7 +1131,7 @@
|
||||
Use default
|
||||
</button>
|
||||
{/if}
|
||||
<p class="icon-picker-recommendation">Recommended size: <strong>1:1 aspect ratio</strong></p>
|
||||
<p class="icon-picker-recommendation">Colors apply to the built-in icons. Recommended image size: <strong>1:1 aspect ratio</strong></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1172,7 +1213,7 @@
|
||||
{@const hasChildren = nb.children.length > 0}
|
||||
{@const isCollapsed = $collapsedNotebooks.includes(nb.path)}
|
||||
{@const iconSrc = getNotebookIconSrc(nb)}
|
||||
{@const builtinIcon = decodeBuiltinNotebookIcon($notebookIcons[normalizeNotebookIconKey(nb.relative_path)])}
|
||||
{@const builtinIcon = decodeNotebookIcon($notebookIcons[normalizeNotebookIconKey(nb.relative_path)])}
|
||||
{#if editingNotebook === nb.path}
|
||||
<div class="notebook-item" style="padding-left: {4 + depth * 16}px">
|
||||
<input
|
||||
@@ -1263,9 +1304,9 @@
|
||||
{:else}
|
||||
<span class="chevron-spacer"></span>
|
||||
{/if}
|
||||
<span class="notebook-icon-slot" class:notebook-builtin-icon={!!builtinIcon}>
|
||||
<span class="notebook-icon-slot" class:notebook-builtin-icon={!!builtinIcon} style:color={builtinIcon?.color}>
|
||||
{#if builtinIcon}
|
||||
<NotebookGlyph icon={builtinIcon} size={18} />
|
||||
<NotebookGlyph icon={builtinIcon.icon} size={18} />
|
||||
{:else if iconSrc}
|
||||
<img class="notebook-icon" crossorigin="anonymous" src={iconSrc} alt="" />
|
||||
{:else if isCollapsed || nb.children.length === 0}
|
||||
@@ -1928,6 +1969,65 @@
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.icon-color-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding: 0 14px 12px;
|
||||
}
|
||||
|
||||
.icon-color-label {
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.icon-swatches {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 7px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.icon-swatch {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
padding: 0;
|
||||
border: 2px solid transparent;
|
||||
border-radius: 50%;
|
||||
background: var(--bg-tertiary);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.icon-swatch:hover,
|
||||
.icon-swatch.active {
|
||||
border-color: var(--text-primary);
|
||||
}
|
||||
|
||||
.icon-swatch.none {
|
||||
background:
|
||||
linear-gradient(to bottom right, transparent calc(50% - 1px), var(--text-tertiary) calc(50% - 1px), var(--text-tertiary) calc(50% + 1px), transparent calc(50% + 1px)),
|
||||
var(--bg-secondary);
|
||||
border-color: var(--border-color);
|
||||
}
|
||||
|
||||
.icon-swatch.custom {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
overflow: hidden;
|
||||
background: conic-gradient(from 90deg, #e11d48, #eab308, #22c55e, #3b82f6, #8b5cf6, #e11d48);
|
||||
}
|
||||
|
||||
.icon-swatch.custom input {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
transform: scale(1.4);
|
||||
}
|
||||
|
||||
.icon-picker-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
const { decodeBuiltinNotebookIcon, decodeNotebookIcon, encodeBuiltinNotebookIcon } = await import(
|
||||
new URL('./notebook-icons.ts', import.meta.url)
|
||||
);
|
||||
|
||||
test('encodes a builtin notebook icon with an optional color', () => {
|
||||
assert.equal(encodeBuiltinNotebookIcon('star'), 'builtin:star');
|
||||
assert.equal(encodeBuiltinNotebookIcon('star', null), 'builtin:star');
|
||||
assert.equal(encodeBuiltinNotebookIcon('star', '#E11D48'), 'builtin:star#e11d48');
|
||||
assert.equal(encodeBuiltinNotebookIcon('star', 'red'), 'builtin:star');
|
||||
});
|
||||
|
||||
test('decodes notebook icons with and without a color', () => {
|
||||
assert.deepEqual(decodeNotebookIcon('builtin:star'), { icon: 'star', color: null });
|
||||
assert.deepEqual(decodeNotebookIcon('builtin:star#e11d48'), { icon: 'star', color: '#e11d48' });
|
||||
assert.deepEqual(decodeNotebookIcon('builtin:star#nope'), { icon: 'star', color: null });
|
||||
});
|
||||
|
||||
test('ignores custom images and unknown builtin icons', () => {
|
||||
assert.equal(decodeNotebookIcon(null), null);
|
||||
assert.equal(decodeNotebookIcon('.helixnotes/attachments/icon#1.png'), null);
|
||||
assert.equal(decodeNotebookIcon('builtin:unknown#e11d48'), null);
|
||||
});
|
||||
|
||||
test('tag icons stay uncolored builtin ids', () => {
|
||||
assert.equal(decodeBuiltinNotebookIcon('builtin:star'), 'star');
|
||||
assert.equal(decodeBuiltinNotebookIcon('builtin:star#e11d48'), null);
|
||||
});
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isValidTagColor } from './tag-styles.ts';
|
||||
|
||||
export const NOTEBOOK_ICON_OPTIONS = [
|
||||
{ id: 'book', label: 'Book' },
|
||||
{ id: 'folder', label: 'Folder' },
|
||||
@@ -14,7 +16,23 @@ export const NOTEBOOK_ICON_OPTIONS = [
|
||||
{ id: 'archive', label: 'Archive' },
|
||||
{ id: 'globe', label: 'Globe' },
|
||||
{ id: 'plane', label: 'Travel' },
|
||||
{ id: 'palette', label: 'Creative' }
|
||||
{ id: 'palette', label: 'Creative' },
|
||||
{ id: 'music', label: 'Music' },
|
||||
{ id: 'camera', label: 'Photos' },
|
||||
{ id: 'film', label: 'Film' },
|
||||
{ id: 'gamepad', label: 'Games' },
|
||||
{ id: 'cart', label: 'Shopping' },
|
||||
{ id: 'money', label: 'Finance' },
|
||||
{ id: 'health', label: 'Health' },
|
||||
{ id: 'food', label: 'Food' },
|
||||
{ id: 'coffee', label: 'Coffee' },
|
||||
{ id: 'leaf', label: 'Nature' },
|
||||
{ id: 'users', label: 'People' },
|
||||
{ id: 'chat', label: 'Chat' },
|
||||
{ id: 'mail', label: 'Mail' },
|
||||
{ id: 'lock', label: 'Private' },
|
||||
{ id: 'wrench', label: 'Tools' },
|
||||
{ id: 'pen', label: 'Writing' }
|
||||
] as const;
|
||||
|
||||
export type NotebookIconId = (typeof NOTEBOOK_ICON_OPTIONS)[number]['id'];
|
||||
@@ -36,15 +54,31 @@ const BUILTIN_IDS: Record<NotebookIconId, true> = {
|
||||
archive: true,
|
||||
globe: true,
|
||||
plane: true,
|
||||
palette: true
|
||||
palette: true,
|
||||
music: true,
|
||||
camera: true,
|
||||
film: true,
|
||||
gamepad: true,
|
||||
cart: true,
|
||||
money: true,
|
||||
health: true,
|
||||
food: true,
|
||||
coffee: true,
|
||||
leaf: true,
|
||||
users: true,
|
||||
chat: true,
|
||||
mail: true,
|
||||
lock: true,
|
||||
wrench: true,
|
||||
pen: true
|
||||
};
|
||||
|
||||
export function normalizeNotebookIconKey(path: string): string {
|
||||
return path.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
export function encodeBuiltinNotebookIcon(icon: NotebookIconId): string {
|
||||
return `${BUILTIN_PREFIX}${icon}`;
|
||||
export function encodeBuiltinNotebookIcon(icon: NotebookIconId, color?: string | null): string {
|
||||
return `${BUILTIN_PREFIX}${icon}${isValidTagColor(color) ? color.toLowerCase() : ''}`;
|
||||
}
|
||||
|
||||
export function decodeBuiltinNotebookIcon(value: string | null | undefined): NotebookIconId | null {
|
||||
@@ -52,3 +86,17 @@ export function decodeBuiltinNotebookIcon(value: string | null | undefined): Not
|
||||
const icon = value.slice(BUILTIN_PREFIX.length);
|
||||
return Object.hasOwn(BUILTIN_IDS, icon) ? icon as NotebookIconId : null;
|
||||
}
|
||||
|
||||
/** Notebook icons keep their color in the stored value: `builtin:star#e11d48`. */
|
||||
export function decodeNotebookIcon(
|
||||
value: string | null | undefined
|
||||
): { icon: NotebookIconId; color: string | null } | null {
|
||||
const hash = value?.indexOf('#') ?? -1;
|
||||
if (hash < 0) {
|
||||
const icon = decodeBuiltinNotebookIcon(value);
|
||||
return icon ? { icon, color: null } : null;
|
||||
}
|
||||
const icon = decodeBuiltinNotebookIcon(value!.slice(0, hash));
|
||||
const color = value!.slice(hash);
|
||||
return icon ? { icon, color: isValidTagColor(color) ? color : null } : null;
|
||||
}
|
||||
Reference in new issue
Block a user