Skip to content

📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

New snippets management & customizations

Smaug6739e469ad3dfbfe
diff --git a/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue b/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue
index 1bcf2f34..2ceb6a8b 100644
--- a/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue
+++ b/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue
@@ -184,17 +184,7 @@ function handleGridSelect(gridMarkdown: string) {
view.focus();
}
-const snippets: Record<string, string> = {
- '!blue': ':::blue\n$0\n:::',
- '!green': ':::green\n$0\n:::',
- '!yellow': ':::yellow\n$0\n:::',
- '!grey': ':::grey\n$0\n:::',
- '!details': ':::details\n$0\n:::',
- '!center': ':::center\n$0\n:::',
- '!m': '$$0$',
- '!property': ':::property $0\n\n:::',
- '!warning': ':::warning $0\n\n:::',
-};
+const snippets = usePreferences().get('snippets');
const snippetListener = EditorView.updateListener.of(update => {
if (!update.docChanged || !editorView.value) return;
@@ -212,20 +202,20 @@ const snippetListener = EditorView.updateListener.of(update => {
});
if (!hasInsertion) return;
- // Vérifie si on vient d’insérer un mot-clé
+ // Check if snippet work
const cursorPos = state.selection.main.head;
const line = state.doc.lineAt(cursorPos);
const textBefore = line.text.slice(0, cursorPos - line.from);
- const match = Object.keys(snippets).find(key => textBefore.endsWith(key));
+ const match = snippets.value.find(snippet => snippet.id && textBefore.endsWith(snippet.id as string));
if (!match) return;
- const start = cursorPos - match.length;
- const snippet = snippets[match];
+ const start = cursorPos - (match.id as string).length;
+ const snippet = match.label;
- // remplace $0 par un curseur
- const [before, after] = snippet!.split('$0');
- const newText = (before || '') + after;
+ // replace $0 with a cursor
+ const [before, after] = snippet.split('$0');
+ const newText = (before || '') + (after || '');
const view = editorView.value;
view.dispatch({
diff --git a/frontend/app/composables/Preferences.ts b/frontend/app/composables/Preferences.ts
index 74136676..261f4bf9 100644
--- a/frontend/app/composables/Preferences.ts
+++ b/frontend/app/composables/Preferences.ts
@@ -25,6 +25,17 @@ export const DEFAULT_PREFERENCES = {
theme: true as boolean,
navigation: true as boolean,
},
+ snippets: [
+ { id: '!blue', label: ':::blue\n$0\n:::' },
+ { id: '!green', label: ':::green\n$0\n:::' },
+ { id: '!yellow', label: ':::yellow\n$0\n:::' },
+ { id: '!grey', label: ':::grey\n$0\n:::' },
+ { id: '!details', label: ':::details\n$0\n:::' },
+ { id: '!center', label: ':::center\n$0\n:::' },
+ { id: '!m', label: '$$0$' },
+ { id: '!property', label: ':::property $0\n\n:::' },
+ { id: '!warning', label: ':::warning $0\n\n:::' },
+ ] as ANode[],
};
// Crée un type mapping automatique : chaque clé => type exact
@@ -88,7 +99,7 @@ export function usePreferences() {
};
}
-type OptionType = 'toggle' | 'select' | 'color' | 'radio' | 'groupCheckbox';
+type OptionType = 'toggle' | 'select' | 'color' | 'radio' | 'groupCheckbox' | 'anode';
interface BaseOption<T = unknown> {
label: string;
type: OptionType;
@@ -126,5 +137,11 @@ interface GroupCheckboxOption extends BaseOption<Record<string, boolean>> {
onChange?: (value: Record<string, boolean>) => void;
}
-export type Option = ToggleOption | ColorOption | SelectOption | RadioOption | GroupCheckboxOption;
-export type { ColorOption, SelectOption, RadioOption, ToggleOption, GroupCheckboxOption };
+interface AnodeOption extends BaseOption<ANode[]> {
+ type: 'anode';
+ value: ANode[];
+ onChange?: (value: ANode[]) => void;
+}
+
+export type Option = ToggleOption | ColorOption | SelectOption | RadioOption | GroupCheckboxOption | AnodeOption;
+export type { ColorOption, SelectOption, RadioOption, ToggleOption, GroupCheckboxOption, AnodeOption };
diff --git a/frontend/app/pages/dashboard/settings/_views/snippets.vue b/frontend/app/pages/dashboard/settings/_views/snippets.vue
index 9cd37ac1..a4f2f3a4 100644
--- a/frontend/app/pages/dashboard/settings/_views/snippets.vue
+++ b/frontend/app/pages/dashboard/settings/_views/snippets.vue
@@ -1,64 +1,27 @@
<template>
- <div class="snippets-page">
- <h2 class="title">Snippets</h2>
- <p class="subtitle">Manage the snippets available in the editor.</p>
-
- <!-- Actions -->
+ <div>
+ <h2 class="ctitle">Snippets</h2>
+ <!-- Actions row -->
<div class="actions">
- <button @click="addSnippet" class="btn primary">+ Add snippet</button>
- <button @click="restoreDefaults" class="btn danger">Restore defaults</button>
+ <AppButton type="primary" @click="addSnippet"> + Add snippet </AppButton>
+ <AppButton type="secondary" @click="restoreDefaults"> ↺ Restore defaults </AppButton>
</div>
-
<!-- Snippets list -->
- <table class="snippets-table">
- <thead>
- <tr>
- <th>Key</th>
- <th>Content</th>
- <th class="actions-col">Actions</th>
- </tr>
- </thead>
- <tbody>
- <tr v-for="(snippet, index) in snippets" :key="snippet.key">
- <td>
- <input v-model="snippet.key" class="input key-input" placeholder="!shortcut" />
- </td>
- <td>
- <textarea v-model="snippet.value" class="input content-input" placeholder="Snippet content..." />
- </td>
- <td class="actions-col">
- <button @click="removeSnippet(index)" class="btn small danger">Delete</button>
- </td>
- </tr>
- <tr v-if="snippets.length === 0">
- <td colspan="3" class="empty">No snippets yet</td>
- </tr>
- </tbody>
- </table>
+ <div class="snippets-list">
+ <div v-for="(snippet, index) in snippets" :key="index" class="snippet-row">
+ <input v-model="snippet.id" class="snippet-key" placeholder="!shortcut" />
+ <textarea v-model="snippet.label" class="snippet-value" placeholder="Snippet content..." />
+ <button class="delete-btn" title="Delete snippet" @click="removeSnippet(index)">✕</button>
+ </div>
+ </div>
</div>
</template>
<script setup lang="ts">
-import { ref } from 'vue';
-
-type Snippet = { key: string; value: string };
-
-const defaultSnippets: Snippet[] = [
- { key: '!blue', value: ':::blue\n$0\n:::' },
- { key: '!green', value: ':::green\n$0\n:::' },
- { key: '!yellow', value: ':::yellow\n$0\n:::' },
- { key: '!grey', value: ':::grey\n$0\n:::' },
- { key: '!details', value: ':::details\n$0\n:::' },
- { key: '!center', value: ':::center\n$0\n:::' },
- { key: '!m', value: '$$0$' },
- { key: '!property', value: ':::property $0\n\n:::' },
- { key: '!warning', value: ':::warning $0\n\n:::' },
-];
-
-const snippets = ref<Snippet[]>([...defaultSnippets]);
+const snippets = usePreferences().get('snippets');
function addSnippet() {
- snippets.value.push({ key: '!new', value: 'New snippet content' });
+ snippets.value = [{ id: '', label: '' }, ...snippets.value];
}
function removeSnippet(index: number) {
@@ -66,97 +29,75 @@ function removeSnippet(index: number) {
}
function restoreDefaults() {
- if (confirm('Are you sure you want to restore default snippets?')) {
- snippets.value = [...defaultSnippets];
- }
+ snippets.value = DEFAULT_PREFERENCES.snippets;
}
</script>
<style scoped lang="scss">
-.snippets-page {
- padding: 1.5rem;
- max-width: 800px;
- margin: auto;
-}
-
.actions {
display: flex;
- gap: 1rem;
+ justify-content: flex-end;
+ align-items: center;
margin-bottom: 1rem;
+ gap: 0.5rem;
}
-.snippets-table {
- width: 100%;
- border-collapse: collapse;
- border: 1px solid #ddd;
-
- th,
- td {
- padding: 0.75rem;
- border-bottom: 1px solid #eee;
- text-align: left;
- }
-
- th {
- background: #f8f8f8;
- font-weight: 600;
- }
+/* ---------- Snippets ---------- */
+.snippets-list {
+ display: flex;
+ flex-direction: column;
+ gap: 0.4rem;
+}
- .empty {
- text-align: center;
- color: #888;
- }
+.snippet-row {
+ display: grid;
+ grid-template-columns: 150px 1fr 32px;
+ gap: 0.5rem;
+ align-items: flex-start;
}
-.input {
- width: 100%;
- padding: 0.4rem 0.6rem;
- border: 1px solid #ccc;
+.snippet-key,
+.snippet-value {
+ border: 1px solid var(--border-color);
+ background: var(--bg-color);
+ color: var(--font-color);
border-radius: 6px;
- font-size: 0.9rem;
+ font-family: $monospace-font;
+ font-size: 0.85rem;
+ outline: none;
+ transition: border-color $transition-duration;
+ height: 50px;
}
-.key-input {
- font-weight: bold;
- font-family: monospace;
+.snippet-key {
+ padding: 0.35rem 0.5rem;
+ font-weight: 600;
}
-.content-input {
- font-family: monospace;
- min-height: 60px;
+.snippet-value {
+ padding: 0.4rem 0.6rem;
+ min-height: 44px;
resize: vertical;
}
-.actions-col {
- text-align: right;
- width: 120px;
+.snippet-key:focus,
+.snippet-value:focus {
+ border-color: var(--blue);
+ box-shadow: 0 0 0 1px var(--blue-border);
}
-.btn {
- padding: 0.4rem 0.8rem;
- border-radius: 6px;
- font-size: 0.85rem;
- cursor: pointer;
+/* ---------- Delete button ---------- */
+.delete-btn {
border: none;
- transition: background 0.2s;
-
- &.primary {
- background: #2563eb;
- color: white;
- }
-
- &.danger {
- background: #ef4444;
- color: white;
- }
-
- &.small {
- padding: 0.3rem 0.6rem;
- font-size: 0.75rem;
- }
+ background: transparent;
+ color: var(--red);
+ font-size: 0.9rem;
+ border-radius: 4px;
+ cursor: pointer;
+ padding: 0.2rem;
&:hover {
- opacity: 0.9;
+ background: var(--red-bg-light);
}
}
</style>
diff --git a/frontend/app/styles/_variables.scss b/frontend/app/styles/_variables.scss
index 0994cf07..ad7f4fa8 100644
--- a/frontend/app/styles/_variables.scss
+++ b/frontend/app/styles/_variables.scss
@@ -37,7 +37,7 @@ $primary-dark: color.adjust(#6024ec, $lightness: -10%);
--default-bg: #dde1f8;
--default-border: #dde1f8;
--bg-color: #fff;
- --bg-contrast: #f8f8f8;
+ --bg-contrast: #F1F6FD;
--bg-contrast-2: #e2ebfd;
--selection-color: #cbd4dd;
--font-color: #3c4450;