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.

Add voice

louloudev59e8d7302169b4
diff --git a/frontend/app/components/MarkdownEditor/ColorPickerModal.vue b/frontend/app/components/MarkdownEditor/ColorPickerModal.vue
new file mode 100644
index 00000000..f285807b
--- /dev/null
+++ b/frontend/app/components/MarkdownEditor/ColorPickerModal.vue
@@ -0,0 +1,1013 @@
+<template>
+ <div class="color-picker-modal">
+ <div class="modal-header">
+ <div class="header-icon">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
+ stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
+ <circle cx="13.5" cy="6.5" r=".5"/>
+ <circle cx="17.5" cy="10.5" r=".5"/>
+ <circle cx="8.5" cy="7.5" r=".5"/>
+ <circle cx="6.5" cy="12.5" r=".5"/>
+ <path d="M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 011.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z"/>
+</svg>
+ </div>
+ <h3>Color Palette</h3>
+ <p class="header-subtitle">Choose from predefined colors or use the color wheel</p>
+ </div>
+
+ <div class="modal-content">
+ <div class="section">
+ <h4 class="section-title">Quick Colors</h4>
+ <div class="swatches">
+ <button
+ v-for="(color, index) in availableColors"
+ :key="color"
+ class="swatch"
+ :class="{ 'primary-color': color === 'primary' }"
+ :style="{ background: `var(--${color})` }"
+ :title="color"
+ @click="selectColor(color)"
+ @mouseenter="hoveredColor = color"
+ @mouseleave="hoveredColor = null"
+ >
+ <div class="swatch-inner">
+ <div class="swatch-check" v-if="hoveredColor === color">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3">
+ <polyline points="20,6 9,17 4,12"/>
+ </svg>
+ </div>
+ </div>
+ </button>
+ </div>
+ </div>
+
+ <div class="section">
+ <h4 class="section-title">
+ Custom Color
+ </h4>
+ <div class="custom">
+ <div class="color-wheel-section">
+ <div class="color-wheel-container">
+ <canvas
+ ref="colorWheel"
+ class="color-wheel"
+ @mousedown="startColorSelection"
+ @mousemove="updateColorSelection"
+ @mouseup="stopColorSelection"
+ @click="selectColorFromWheel"
+ ></canvas>
+ <div
+ class="color-wheel-cursor"
+ :style="{
+ left: `${cursorPosition.x}px`,
+ top: `${cursorPosition.y}px`,
+ background: selectedWheelColor
+ }"
+ ></div>
+ </div>
+
+ <div class="color-controls">
+ <div class="control-group">
+ <label>Brightness</label>
+ <div class="slider-container">
+ <input
+ type="range"
+ min="0"
+ max="100"
+ v-model="brightness"
+ class="brightness-slider"
+ @input="updateWheelColor"
+ />
+ <div class="slider-track">
+ <div class="slider-fill" :style="{ width: `${brightness}%` }"></div>
+ </div>
+ </div>
+ </div>
+
+ <div class="selected-color-preview">
+ <div class="preview-circle" :style="{ background: selectedWheelColor }"></div>
+ <div class="color-info">
+ <span class="hex-value">{{ selectedWheelColor }}</span>
+ <span class="hsv-values">HSV({{ hue }}, {{ saturation }}%, {{ brightness }}%)</span>
+ </div>
+ </div>
+
+ <button class="validate-wheel-btn" @click="validateWheelColor">
+ <svg class="btn-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <path d="M5 13l4 4L19 7"/>
+ </svg>
+ <span class="btn-text">Use This Color</span>
+ </button>
+ </div>
+ </div>
+
+ <div class="input-group">
+ <div class="input-wrapper">
+ <span class="input-prefix">#</span>
+ <input
+ v-model="hexColor"
+ class="hex"
+ placeholder="RRGGBB"
+ maxlength="6"
+ @keyup.enter="applyCustomColor"
+ @input="validateHexInput"
+ />
+ </div>
+ <div class="color-preview" :style="{ background: hexColor && /^[0-9A-F]{6}$/i.test(hexColor) ? `#${hexColor}` : 'transparent' }">
+ <div class="preview-border"></div>
+ </div>
+ </div>
+
+ <button class="apply" @click="applyCustomColor" :disabled="!isValidHex">
+ <span class="btn-text">Apply Color</span>
+ <svg class="btn-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <path d="M5 13l4 4L19 7"/>
+ </svg>
+ </button>
+ </div>
+ </div>
+ </div>
+
+ <div class="modal-footer">
+ <button class="cancel-btn" @click="closeModal">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <line x1="18" y1="6" x2="6" y2="18"/>
+ <line x1="6" y1="6" x2="18" y2="18"/>
+ </svg>
+ <span>Cancel</span>
+ </button>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { ref, computed, onMounted, nextTick } from 'vue';
+import { getAppColor } from '~/composables/utils';
+
+const props = defineProps<{
+ onColorSelect: (color: string) => void;
+}>();
+
+const emit = defineEmits<{
+ (e: 'close'): void;
+}>();
+
+const hexColor = ref('');
+const hoveredColor = ref<string | null>(null);
+const colorWheel = ref<HTMLCanvasElement>();
+const isSelecting = ref(false);
+const hue = ref(0);
+const saturation = ref(100);
+const brightness = ref(100);
+const selectedWheelColor = ref('#FF0000');
+const cursorPosition = ref({ x: 150, y: 75 });
+
+const availableColors = [
+ 'primary',
+ ...Array.from({ length: 8 }, (_, i) => getAppColor(i))
+];
+
+const isValidHex = computed(() => {
+ return hexColor.value && /^[0-9A-F]{6}$/i.test(hexColor.value);
+});
+
+const selectColor = (color: string) => {
+ props.onColorSelect(color);
+ emit('close');
+};
+
+const startColorSelection = (e: MouseEvent) => {
+ isSelecting.value = true;
+ updateColorSelection(e);
+};
+
+const stopColorSelection = () => {
+ isSelecting.value = false;
+};
+
+const updateColorSelection = (e: MouseEvent) => {
+ if (!isSelecting.value || !colorWheel.value) return;
+
+ const rect = colorWheel.value.getBoundingClientRect();
+ const x = e.clientX - rect.left;
+ const y = e.clientY - rect.top;
+
+ const centerX = rect.width / 2;
+ const centerY = rect.height / 2;
+
+ const deltaX = x - centerX;
+ const deltaY = y - centerY;
+
+ const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+ const maxDistance = Math.min(centerX, centerY);
+
+ if (distance <= maxDistance) {
+ cursorPosition.value = { x, y };
+
+ const angle = Math.atan2(deltaY, deltaX) * (180 / Math.PI);
+ hue.value = angle < 0 ? angle + 360 : angle;
+
+ saturation.value = Math.min(100, (distance / maxDistance) * 100);
+
+ updateWheelColor();
+ }
+};
+
+const selectColorFromWheel = (e: MouseEvent) => {
+ updateColorSelection(e);
+ hexColor.value = selectedWheelColor.value.replace('#', '');
+};
+
+const validateWheelColor = () => {
+ props.onColorSelect(selectedWheelColor.value);
+ emit('close');
+};
+
+const updateWheelColor = () => {
+ const h = hue.value;
+ const s = saturation.value;
+ const v = brightness.value;
+
+ selectedWheelColor.value = hsvToHex(h, s, v);
+};
+
+const hsvToHex = (h: number, s: number, v: number): string => {
+ const c = (v / 100) * (s / 100);
+ const x = c * (1 - Math.abs((h / 60) % 2 - 1));
+ const m = (v / 100) - c;
+
+ let r = 0, g = 0, b = 0;
+
+ if (h >= 0 && h < 60) {
+ r = c; g = x; b = 0;
+ } else if (h >= 60 && h < 120) {
+ r = x; g = c; b = 0;
+ } else if (h >= 120 && h < 180) {
+ r = 0; g = c; b = x;
+ } else if (h >= 180 && h < 240) {
+ r = 0; g = x; b = c;
+ } else if (h >= 240 && h < 300) {
+ r = x; g = 0; b = c;
+ } else if (h >= 300 && h < 360) {
+ r = c; g = 0; b = x;
+ }
+
+ const rHex = Math.round((r + m) * 255).toString(16).padStart(2, '0');
+ const gHex = Math.round((g + m) * 255).toString(16).padStart(2, '0');
+ const bHex = Math.round((b + m) * 255).toString(16).padStart(2, '0');
+
+ return `#${rHex}${gHex}${bHex}`.toUpperCase();
+};
+
+const drawColorWheel = () => {
+ if (!colorWheel.value) return;
+
+ const canvas = colorWheel.value;
+ const ctx = canvas.getContext('2d');
+ if (!ctx) return;
+
+ const width = canvas.width;
+ const height = canvas.height;
+ const centerX = width / 2;
+ const centerY = height / 2;
+ const radius = Math.min(centerX, centerY) - 10;
+
+ ctx.clearRect(0, 0, width, height);
+
+ for (let y = 0; y < height; y++) {
+ for (let x = 0; x < width; x++) {
+ const deltaX = x - centerX;
+ const deltaY = y - centerY;
+ const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+
+ if (distance <= radius) {
+ const angle = Math.atan2(deltaY, deltaX) * (180 / Math.PI);
+ const hue = angle < 0 ? angle + 360 : angle;
+ const saturation = Math.min(100, (distance / radius) * 100);
+ const value = 100;
+
+ const color = hsvToHex(hue, saturation, value);
+ ctx.fillStyle = color;
+ ctx.fillRect(x, y, 1, 1);
+ }
+ }
+ }
+
+ // Draw outer circle
+ ctx.strokeStyle = 'var(--border-color)';
+ ctx.lineWidth = 2;
+ ctx.beginPath();
+ ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI);
+ ctx.stroke();
+};
+
+const applyCustomColor = () => {
+ if (isValidHex.value) {
+ props.onColorSelect(`#${hexColor.value}`);
+ emit('close');
+ }
+};
+
+const validateHexInput = () => {
+ hexColor.value = hexColor.value.replace(/[^0-9A-Fa-f]/g, '').toUpperCase();
+};
+
+const closeModal = () => {
+ emit('close');
+};
+
+onMounted(async () => {
+ await nextTick();
+ if (colorWheel.value) {
+ colorWheel.value.width = 240;
+ colorWheel.value.height = 120;
+ drawColorWheel();
+ }
+});
+</script>
+
+<style scoped lang="scss">
+.color-picker-modal {
+ background: transparent;
+ width: 100%;
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+ overflow: hidden;
+ padding: 0 20px;
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
+}
+
+.modal-header {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding: 24px 0 20px 0;
+ flex-shrink: 0;
+ text-align: center;
+
+ .header-icon {
+ width: 48px;
+ height: 48px;
+ background: linear-gradient(135deg, var(--primary), var(--primary-dark, var(--primary)));
+ border-radius: 16px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ margin-bottom: 16px;
+ color: white;
+
+ svg {
+ width: 24px;
+ height: 24px;
+ }
+ }
+
+ h3 {
+ margin: 0 0 8px 0;
+ font-size: 24px;
+ font-weight: 800;
+ color: var(--font-color-dark);
+ letter-spacing: -0.8px;
+ background: linear-gradient(135deg, var(--font-color-dark), var(--primary));
+ -webkit-background-clip: text;
+ -webkit-text-fill-color: transparent;
+ background-clip: text;
+ }
+
+ .header-subtitle {
+ margin: 0;
+ font-size: 14px;
+ color: var(--font-color-light);
+ font-weight: 500;
+ line-height: 1.4;
+ max-width: 280px;
+ }
+}
+
+.modal-content {
+ flex: 1;
+ display: flex;
+ flex-direction: column;
+ gap: 24px;
+ padding: 0;
+ overflow-y: auto;
+ min-height: 0;
+ padding-right: 8px;
+
+ &::-webkit-scrollbar {
+ width: 6px;
+ }
+
+ &::-webkit-scrollbar-track {
+ background: var(--bg-color-secondary);
+ border-radius: 3px;
+ }
+
+ &::-webkit-scrollbar-thumb {
+ background: var(--border-color);
+ border-radius: 3px;
+
+ &:hover {
+ background: var(--primary);
+ }
+ }
+}
+
+.section {
+ .section-title {
+ margin: 0 0 16px 0;
+ font-size: 16px;
+ font-weight: 700;
+ color: var(--font-color-dark);
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
+ position: relative;
+ padding-left: 16px;
+ display: flex;
+ align-items: center;
+ gap: 12px;
+
+ .section-icon {
+ width: 20px;
+ height: 20px;
+ color: var(--primary);
+ flex-shrink: 0;
+ }
+
+ &::before {
+ content: '';
+ position: absolute;
+ left: 0;
+ top: 50%;
+ transform: translateY(-50%);
+ width: 4px;
+ height: 16px;
+ background: linear-gradient(180deg, var(--primary), var(--primary-dark));
+ border-radius: 2px;
+ }
+ }
+}
+
+.swatches {
+ display: grid;
+ gap: 12px;
+ grid-template-columns: repeat(3, 1fr);
+ justify-items: center;
+ padding: 0 8px;
+ margin-bottom: 8px;
+}
+
+.swatch {
+ width: 48px;
+ height: 48px;
+ border-radius: 12px;
+ border: 3px solid transparent;
+ transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
+ cursor: pointer;
+ position: relative;
+ overflow: hidden;
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
+
+ &.primary-color {
+ border-color: var(--primary);
+ box-shadow: 0 6px 20px rgba(var(--primary-rgb), 0.3);
+ }
+
+ .swatch-inner {
+ width: 100%;
+ height: 100%;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ position: relative;
+ }
+
+ .swatch-check {
+ color: white;
+ filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
+
+ svg {
+ width: 18px;
+ height: 18px;
+ }
+ }
+
+ &:hover {
+ transform: translateY(-4px) scale(1.1);
+ box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
+ border-color: var(--primary);
+
+ &.primary-color {
+ box-shadow: 0 16px 40px rgba(var(--primary-rgb), 0.4);
+ }
+ }
+
+ &:active {
+ transform: translateY(-2px) scale(1.05);
+ }
+}
+
+.custom {
+ display: flex;
+ flex-direction: column;
+ gap: 20px;
+ padding: 20px;
+ background: linear-gradient(135deg, var(--bg-color-secondary), var(--bg-color));
+ border-radius: 16px;
+ border: 1px solid var(--border-color);
+ box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
+}
+
+.color-wheel-section {
+ display: flex;
+ gap: 16px;
+ align-items: flex-start;
+}
+
+.color-wheel-container {
+ position: relative;
+ flex-shrink: 0;
+}
+
+.color-wheel {
+ border-radius: 12px;
+ cursor: crosshair;
+ border: 2px solid var(--border-color);
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
+}
+
+.color-wheel-cursor {
+ position: absolute;
+ width: 16px;
+ height: 16px;
+ border-radius: 50%;
+ border: 3px solid white;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
+ pointer-events: none;
+ transform: translate(-50%, -50%);
+ z-index: 10;
+}
+
+.color-controls {
+ flex: 1;
+ display: flex;
+ flex-direction: column;
+ gap: 16px;
+}
+
+.control-group {
+ label {
+ display: block;
+ font-size: 14px;
+ font-weight: 600;
+ color: var(--font-color-dark);
+ margin-bottom: 6px;
+ }
+}
+
+.slider-container {
+ position: relative;
+}
+
+.brightness-slider {
+ width: 100%;
+ height: 6px;
+ background: transparent;
+ outline: none;
+ -webkit-appearance: none;
+ appearance: none;
+ cursor: pointer;
+ position: relative;
+ z-index: 2;
+
+ &::-webkit-slider-thumb {
+ -webkit-appearance: none;
+ appearance: none;
+ width: 18px;
+ height: 18px;
+ border-radius: 50%;
+ background: var(--primary);
+ border: 2px solid white;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
+ cursor: pointer;
+ }
+
+ &::-moz-range-thumb {
+ width: 18px;
+ height: 18px;
+ border-radius: 50%;
+ background: var(--primary);
+ border: 2px solid white;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
+ cursor: pointer;
+ border: none;
+ }
+}
+
+.slider-track {
+ position: absolute;
+ top: 50%;
+ left: 0;
+ right: 0;
+ height: 6px;
+ background: var(--border-color);
+ border-radius: 3px;
+ transform: translateY(-50%);
+ z-index: 1;
+}
+
+.slider-fill {
+ height: 100%;
+ background: linear-gradient(90deg, var(--primary), var(--primary-dark));
+ border-radius: 3px;
+ transition: width 0.1s ease;
+}
+
+.selected-color-preview {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ padding: 12px;
+ background: var(--bg-color);
+ border-radius: 10px;
+ border: 1px solid var(--border-color);
+}
+
+.preview-circle {
+ width: 40px;
+ height: 40px;
+ border-radius: 50%;
+ border: 2px solid var(--border-color);
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
+ flex-shrink: 0;
+}
+
+.color-info {
+ display: flex;
+ flex-direction: column;
+ gap: 2px;
+
+ .hex-value {
+ font-size: 14px;
+ font-weight: 700;
+ color: var(--font-color-dark);
+ font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
+ }
+
+ .hsv-values {
+ font-size: 11px;
+ color: var(--font-color-light);
+ font-weight: 500;
+ }
+}
+
+.validate-wheel-btn {
+ padding: 12px 16px;
+ border: 2px solid #3b82f6;
+ border-radius: 8px;
+ background: linear-gradient(135deg, #3b82f6, #1d4ed8);
+ color: white;
+ font-size: 13px;
+ font-weight: 600;
+ cursor: pointer;
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 8px;
+ box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
+ width: 100%;
+ margin-top: 4px;
+ min-height: 40px;
+ position: relative;
+ z-index: 100;
+
+ &:hover {
+ transform: translateY(-2px);
+ box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
+ background: linear-gradient(135deg, #2563eb, #1e40af);
+ border-color: #1e3a8a;
+
+ .btn-icon {
+ transform: scale(1.1);
+ }
+ }
+
+ &:active {
+ transform: translateY(0);
+ }
+
+ .btn-icon {
+ width: 14px;
+ height: 14px;
+ transition: all 0.3s ease;
+ color: white;
+ }
+
+ .btn-text {
+ font-weight: 600;
+ color: white;
+ }
+}
+
+.input-group {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+}
+
+.input-wrapper {
+ flex: 1;
+ display: flex;
+ align-items: center;
+ background: var(--bg-color);
+ border: 2px solid var(--border-color);
+ border-radius: 10px;
+ overflow: hidden;
+ transition: all 0.3s ease;
+
+ &:focus-within {
+ border-color: var(--primary);
+ box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
+ transform: scale(1.02);
+ }
+}
+
+.input-prefix {
+ padding: 0 10px;
+ color: var(--font-color-light);
+ font-weight: 600;
+ font-size: 14px;
+ background: var(--bg-color-secondary);
+ border-right: 1px solid var(--border-color);
+}
+
+.hex {
+ flex: 1;
+ padding: 10px 12px;
+ border: none;
+ background: transparent;
+ color: var(--font-color-dark);
+ font-size: 14px;
+ font-weight: 600;
+ font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
+ letter-spacing: 1px;
+
+ &:focus {
+ outline: none;
+ }
+
+ &::placeholder {
+ color: var(--font-color-light);
+ font-weight: 400;
+ }
+}
+
+.color-preview {
+ width: 40px;
+ height: 40px;
+ border-radius: 10px;
+ border: 2px solid var(--border-color);
+ position: relative;
+ overflow: hidden;
+
+ .preview-border {
+ position: absolute;
+ inset: 0;
+ border: 2px solid transparent;
+ border-radius: 8px;
+ background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.3) 50%, transparent 70%);
+ animation: shimmer 2s infinite;
+ }
+}
+
+@keyframes shimmer {
+ 0% { transform: translateX(-100%); }
+ 100% { transform: translateX(100%); }
+}
+
+.apply {
+ padding: 12px 20px;
+ border: none;
+ border-radius: 10px;
+ background: linear-gradient(135deg, var(--primary), var(--primary-dark));
+ color: white;
+ font-size: 14px;
+ font-weight: 600;
+ cursor: pointer;
+ transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 8px;
+
+ &:disabled {
+ opacity: 0.5;
+ cursor: not-allowed;
+ transform: none;
+ }
+
+ &:not(:disabled) {
+ &:hover {
+ transform: translateY(-2px);
+ box-shadow: 0 8px 24px rgba(var(--primary-rgb), 0.4);
+
+ .btn-icon {
+ transform: scale(1.1) rotate(5deg);
+ }
+ }
+
+ &:active {
+ transform: translateY(0);
+ }
+ }
+
+ .btn-text {
+ font-weight: 600;
+ }
+
+ .btn-icon {
+ width: 16px;
+ height: 16px;
+ transition: all 0.3s ease;
+ }
+}
+
+.modal-footer {
+ padding: 20px 0;
+ display: flex;
+ justify-content: center;
+ gap: 16px;
+ flex-shrink: 0;
+
+ .cancel-btn {
+ padding: 12px 24px;
+ border: 2px solid var(--border-color);
+ border-radius: 10px;
+ background: var(--bg-color-secondary);
+ color: var(--font-color-dark);
+ cursor: pointer;
+ font-size: 14px;
+ font-weight: 600;
+ transition: all 0.3s ease;
+ display: flex;
+ align-items: center;
+ gap: 8px;
+
+ svg {
+ width: 14px;
+ height: 14px;
+ }
+
+ &:hover {
+ background: var(--border-color);
+ border-color: var(--primary);
+ color: var(--primary);
+ transform: translateY(-2px);
+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
+ }
+
+ &:active {
+ transform: translateY(0);
+ }
+ }
+}
+
+@media (max-width: 768px) {
+ .color-picker-modal {
+ padding: 0 16px;
+ }
+
+ .modal-header {
+ padding: 24px 0 20px 0;
+
+ .header-icon {
+ width: 40px;
+ height: 40px;
+ margin-bottom: 12px;
+
+ svg {
+ width: 20px;
+ height: 20px;
+ }
+ }
+
+ h3 {
+ font-size: 20px;
+ }
+
+ .header-subtitle {
+ font-size: 13px;
+ max-width: 240px;
+ }
+ }
+
+ .modal-content {
+ gap: 24px;
+ }
+
+ .swatches {
+ grid-template-columns: repeat(2, 1fr);
+ gap: 20px;
+ padding: 0 4px;
+ }
+
+ .swatch {
+ width: 64px;
+ height: 64px;
+ }
+
+ .custom {
+ padding: 20px;
+ }
+
+ .color-wheel-section {
+ flex-direction: column;
+ gap: 16px;
+ }
+
+ .color-wheel {
+ width: 250px !important;
+ height: 125px !important;
+ }
+
+ .validate-wheel-btn {
+ padding: 12px 18px;
+ font-size: 13px;
+
+ .btn-text {
+ font-size: 13px;
+ }
+ }
+
+ .input-group {
+ flex-direction: column;
+ gap: 12px;
+ align-items: stretch;
+ }
+
+ .color-preview {
+ align-self: center;
+ }
+
+ .apply {
+ padding: 14px 24px;
+ font-size: 15px;
+ }
+
+ .modal-footer {
+ padding: 24px 0;
+
+ .cancel-btn {
+ padding: 12px 24px;
+ font-size: 14px;
+ }
+ }
+}
+
+@media (max-width: 480px) {
+ .swatches {
+ grid-template-columns: repeat(2, 1fr);
+ gap: 16px;
+ }
+
+ .swatch {
+ width: 56px;
+ height: 56px;
+ }
+
+ .custom {
+ padding: 16px;
+ }
+
+ .color-wheel {
+ width: 200px !important;
+ height: 100px !important;
+ }
+
+ .validate-wheel-btn {
+ padding: 10px 16px;
+ font-size: 12px;
+
+ .btn-text {
+ font-size: 12px;
+ }
+
+ .btn-icon {
+ width: 14px;
+ height: 14px;
+ }
+ }
+
+ .hex {
+ font-size: 14px;
+ padding: 12px 14px;
+ }
+
+ .apply {
+ padding: 12px 20px;
+ font-size: 14px;
+ }
+}
+</style>
diff --git a/frontend/app/components/MarkdownEditor/GridOrganizationModal.vue b/frontend/app/components/MarkdownEditor/GridOrganizationModal.vue
new file mode 100644
index 00000000..adb21c34
--- /dev/null
+++ b/frontend/app/components/MarkdownEditor/GridOrganizationModal.vue
@@ -0,0 +1,515 @@
+<template>
+ <div class="grid-organization-modal">
+ <div class="modal-header">
+ <h3>Grid Organization</h3>
+ </div>
+
+ <div class="modal-content">
+ <div class="table-selector">
+ <h4>Select Table Size</h4>
+ <div class="table-grid">
+ <div
+ v-for="row in 12"
+ :key="`row-${row}`"
+ class="table-row"
+ >
+ <div
+ v-for="col in 12"
+ :key="`col-${col}`"
+ class="table-cell"
+ :class="{
+ 'hovered': isHovered(row, col),
+ 'selected': isSelected(row, col)
+ }"
+ @mouseenter="handleHover(row, col)"
+ @mouseleave="handleHoverLeave()"
+ @click="selectTableSize(row, col)"
+ ></div>
+ </div>
+ </div>
+ <div class="table-info">
+ <span v-if="hoveredSize">{{ hoveredSize.rows }} × {{ hoveredSize.columns }} table</span>
+ <span v-else>Hover to see table size</span>
+ </div>
+ </div>
+
+ <div class="quick-presets">
+ <h4>Quick Presets</h4>
+ <div class="presets-grid">
+ <div
+ v-for="preset in gridPresets"
+ :key="preset.name"
+ class="preset-item"
+ @click="selectPreset(preset)"
+ >
+ <div class="preset-visual" :style="getPresetStyle(preset)">
+ <div
+ v-for="cell in preset.cells"
+ :key="cell.id"
+ class="preset-cell"
+ :style="getCellStyle(cell)"
+ ></div>
+ </div>
+ <span class="preset-name">{{ preset.name }}</span>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="modal-footer">
+ <button class="cancel-btn" @click="closeModal">Cancel</button>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { ref, computed } from 'vue';
+
+const props = defineProps<{
+ onGridSelect: (gridMarkdown: string) => void;
+}>();
+
+const emit = defineEmits<{
+ (e: 'close'): void;
+}>();
+
+const hoveredSize = ref<{ rows: number; columns: number } | null>(null);
+const selectedSize = ref<{ rows: number; columns: number } | null>(null);
+
+interface GridCell {
+ id: string;
+ col: number;
+ row: number;
+ colspan?: number;
+ rowspan?: number;
+}
+
+interface GridPreset {
+ name: string;
+ columns: number;
+ rows: number;
+ cells: GridCell[];
+}
+
+const gridPresets: GridPreset[] = [
+ {
+ name: '2x2 Grid',
+ columns: 2,
+ rows: 2,
+ cells: [
+ { id: '1', col: 1, row: 1 },
+ { id: '2', col: 2, row: 1 },
+ { id: '3', col: 1, row: 2 },
+ { id: '4', col: 2, row: 2 }
+ ]
+ },
+ {
+ name: '3x2 Grid',
+ columns: 3,
+ rows: 2,
+ cells: [
+ { id: '1', col: 1, row: 1 },
+ { id: '2', col: 2, row: 1 },
+ { id: '3', col: 3, row: 1 },
+ { id: '4', col: 1, row: 2 },
+ { id: '5', col: 2, row: 2 },
+ { id: '6', col: 3, row: 2 }
+ ]
+ },
+ {
+ name: '2x3 Grid',
+ columns: 2,
+ rows: 3,
+ cells: [
+ { id: '1', col: 1, row: 1 },
+ { id: '2', col: 2, row: 1 },
+ { id: '3', col: 1, row: 2 },
+ { id: '4', col: 2, row: 2 },
+ { id: '5', col: 1, row: 3 },
+ { id: '6', col: 2, row: 3 }
+ ]
+ },
+ {
+ name: '3x3 Grid',
+ columns: 3,
+ rows: 3,
+ cells: [
+ { id: '1', col: 1, row: 1 },
+ { id: '2', col: 2, row: 1 },
+ { id: '3', col: 3, row: 1 },
+ { id: '4', col: 1, row: 2 },
+ { id: '5', col: 2, row: 2 },
+ { id: '6', col: 3, row: 2 },
+ { id: '7', col: 1, row: 3 },
+ { id: '8', col: 2, row: 3 },
+ { id: '9', col: 3, row: 3 }
+ ]
+ },
+
+ {
+ name: 'Two Column',
+ columns: 2,
+ rows: 3,
+ cells: [
+ { id: '1', col: 1, row: 1 },
+ { id: '2', col: 2, row: 1 },
+ { id: '3', col: 1, row: 2 },
+ { id: '4', col: 2, row: 2 },
+ { id: '5', col: 1, row: 3 },
+ { id: '6', col: 2, row: 3 }
+ ]
+ }
+];
+
+const getPresetStyle = (preset: GridPreset) => {
+ return {
+ display: 'grid',
+ gridTemplateColumns: `repeat(${preset.columns}, 1fr)`,
+ gridTemplateRows: `repeat(${preset.rows}, 1fr)`,
+ gap: '2px',
+ width: '100%',
+ height: '60px'
+ };
+};
+
+const getCellStyle = (cell: GridCell) => {
+ return {
+ gridColumn: cell.colspan ? `span ${cell.colspan}` : `span 1`,
+ gridRow: cell.rowspan ? `span ${cell.rowspan}` : `span 1`,
+ backgroundColor: 'var(--primary)',
+ borderRadius: '2px'
+ };
+};
+
+const isHovered = (row: number, col: number): boolean => {
+ if (!hoveredSize.value) return false;
+ return row <= hoveredSize.value.rows && col <= hoveredSize.value.columns;
+};
+
+const isSelected = (row: number, col: number): boolean => {
+ if (!selectedSize.value) return false;
+ return row <= selectedSize.value.rows && col <= selectedSize.value.columns;
+};
+
+const handleHover = (row: number, col: number) => {
+ hoveredSize.value = { rows: row, columns: col };
+};
+
+const handleHoverLeave = () => {
+ hoveredSize.value = null;
+};
+
+const selectTableSize = (row: number, col: number) => {
+ selectedSize.value = { rows: row, columns: col };
+ const gridMarkdown = generateGridMarkdown(col, row);
+ props.onGridSelect(gridMarkdown);
+ emit('close');
+};
+
+const selectPreset = (preset: GridPreset) => {
+ const gridMarkdown = generateGridMarkdown(preset.columns, preset.rows);
+ props.onGridSelect(gridMarkdown);
+ emit('close');
+};
+
+
+
+const generateGridMarkdown = (columns: number, rows: number): string => {
+ let markdown = '\n';
+
+ markdown += '|';
+ for (let i = 0; i < columns; i++) {
+ markdown += ' Column ' + (i + 1) + ' |';
+ }
+ markdown += '\n';
+
+ markdown += '|';
+ for (let i = 0; i < columns; i++) {
+ markdown += ' --- |';
+ }
+ markdown += '\n';
+
+ for (let row = 0; row < rows; row++) {
+ markdown += '|';
+ for (let col = 0; col < columns; col++) {
+ markdown += ' Content ' + (row * columns + col + 1) + ' |';
+ }
+ markdown += '\n';
+ }
+
+ markdown += '\n';
+ return markdown;
+};
+
+const closeModal = () => {
+ emit('close');
+};
+</script>
+
+<style scoped lang="scss">
+.grid-organization-modal {
+ background: transparent;
+ width: 100%;
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+ overflow: hidden;
+ padding: 0 16px;
+}
+
+.modal-header {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ padding: 24px 0 20px 0;
+ flex-shrink: 0;
+ position: relative;
+
+ h3 {
+ margin: 0;
+ font-size: 20px;
+ font-weight: 700;
+ color: var(--font-color-dark);
+ letter-spacing: -0.5px;
+ }
+
+ &::after {
+ content: '';
+ position: absolute;
+ bottom: 0;
+ left: 50%;
+ transform: translateX(-50%);
+ width: 60px;
+ height: 3px;
+ background: linear-gradient(90deg, var(--primary), var(--primary-light, var(--primary)));
+ border-radius: 2px;
+ }
+}
+
+.modal-content {
+ flex: 1;
+ overflow: hidden;
+ display: flex;
+ flex-direction: column;
+ padding: 0;
+ gap: 32px;
+}
+
+.table-selector, .quick-presets {
+ margin-top: 8px;
+
+ h4 {
+ margin: 0 0 20px 0;
+ font-size: 18px;
+ font-weight: 600;
+ color: var(--font-color-dark);
+ display: flex;
+ align-items: center;
+ gap: 8px;
+
+ &::before {
+ content: '';
+ width: 4px;
+ height: 18px;
+ background: var(--primary);
+ border-radius: 2px;
+ }
+ }
+}
+
+.table-grid {
+ display: grid;
+ grid-template-columns: repeat(12, 1fr);
+ gap: 2px;
+ margin-bottom: 16px;
+ border: 2px solid var(--border-color);
+ border-radius: 8px;
+ padding: 4px;
+ background: var(--bg-color);
+ max-width: 400px;
+ margin-left: auto;
+ margin-right: auto;
+}
+
+.table-row {
+ display: contents;
+}
+
+.table-cell {
+ width: 16px;
+ height: 16px;
+ border: 1px solid var(--border-color);
+ background: var(--bg-color-secondary);
+ cursor: pointer;
+ transition: all 0.2s ease;
+ position: relative;
+
+ &:hover {
+ background: var(--primary);
+ border-color: var(--primary);
+ transform: scale(1.1);
+ z-index: 2;
+ }
+
+ &.hovered {
+ background: var(--primary);
+ border-color: var(--primary);
+ opacity: 0.8;
+ }
+
+ &.selected {
+ background: var(--primary);
+ border-color: var(--primary);
+ opacity: 1;
+ box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.3);
+ }
+}
+
+.table-info {
+ text-align: center;
+ padding: 12px;
+ background: var(--bg-color-secondary);
+ border-radius: 8px;
+ border: 1px solid var(--border-color);
+ font-size: 14px;
+ font-weight: 500;
+ color: var(--font-color-dark);
+ min-height: 20px;
+ max-width: 400px;
+ margin-left: auto;
+ margin-right: auto;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
+}
+
+.presets-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
+ gap: 16px;
+ margin-bottom: 16px;
+}
+
+.preset-item {
+ cursor: pointer;
+ text-align: center;
+ padding: 12px;
+ border: 2px solid transparent;
+ border-radius: 10px;
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
+ background: var(--bg-color-secondary);
+ position: relative;
+ overflow: hidden;
+
+ &::before {
+ content: '';
+ position: absolute;
+ top: 0;
+ left: 0;
+ right: 0;
+ height: 3px;
+ background: linear-gradient(90deg, var(--primary), var(--primary-light, var(--primary)));
+ transform: scaleX(0);
+ transition: transform 0.3s ease;
+ }
+
+ &:hover {
+ border-color: var(--primary);
+ background: var(--bg-color);
+ transform: translateY(-4px);
+ box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
+
+ &::before {
+ transform: scaleX(1);
+ }
+
+ .preset-visual {
+ border-color: var(--primary);
+ box-shadow: 0 4px 16px rgba(var(--primary-rgb), 0.2);
+ }
+ }
+
+ .preset-visual {
+ margin-bottom: 8px;
+ border: 2px solid var(--border-color);
+ border-radius: 6px;
+ background: var(--bg-color);
+ transition: all 0.3s ease;
+ position: relative;
+ height: 50px;
+
+ &::after {
+ content: '';
+ position: absolute;
+ inset: 0;
+ border-radius: 4px;
+ background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
+ pointer-events: none;
+ }
+ }
+
+ .preset-name {
+ font-size: 13px;
+ color: var(--font-color-dark);
+ font-weight: 600;
+ transition: color 0.3s ease;
+ }
+
+ &:hover .preset-name {
+ color: var(--primary);
+ }
+}
+
+.modal-footer {
+ padding: 24px 0;
+ display: flex;
+ justify-content: flex-end;
+ gap: 16px;
+ flex-shrink: 0;
+
+ .cancel-btn {
+ padding: 12px 24px;
+ border: 2px solid var(--border-color);
+ border-radius: 10px;
+ background: var(--bg-color-secondary);
+ color: var(--font-color-dark);
+ cursor: pointer;
+ font-size: 14px;
+ font-weight: 500;
+ transition: all 0.3s ease;
+
+ &:hover {
+ background: var(--border-color);
+ border-color: var(--primary);
+ color: var(--primary);
+ transform: translateY(-1px);
+ }
+
+ &:active {
+ transform: translateY(0);
+ }
+ }
+}
+
+@media (max-width: 768px) {
+ .table-grid {
+ grid-template-columns: repeat(8, 1fr);
+ gap: 1px;
+ max-width: 300px;
+
+ .table-cell {
+ width: 14px;
+ height: 14px;
+ }
+ }
+
+ .presets-grid {
+ grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
+ gap: 12px;
+ }
+
+ .table-info {
+ max-width: 300px;
+ font-size: 13px;
+ padding: 10px;
+ }
+}
+</style>
diff --git a/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue b/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue
index 826eec66..6135e6de 100644
--- a/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue
+++ b/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue
@@ -1,481 +1,427 @@
-<template>
- <div style="height: 100%; padding: 4px">
- <div class="editor-container">
- <Toolbar v-model="document" :minimal="minimal" @execute-action="exec" />
- <div style="display: flex; min-height: 0; padding: 6px; flex: 1; flex-direction: column; gap: 8px">
- <input v-if="!minimal" v-model="document.name" placeholder="Title" class="title" />
- <input v-if="!minimal" v-model="document.description" placeholder="Description" class="description" />
- <AppTagInput v-model="document.tags" style="margin-bottom: 10px" />
- <div ref="container" class="markdown">
- <div ref="editorContainer" class="codemirror-editor" style="border-right: 1px solid var(--border-color)" />
- <!-- eslint-disable-next-line vue/no-v-html -->
- <div v-if="showPreview" ref="markdownPreview" :class="['markdown-preview', `${usePreferences().get('theme')}-theme`]" style="position: relative" v-html="document.content_html" />
- </div>
- </div>
- </div>
- </div>
-</template>
-<script setup lang="ts">
-import { EditorView, keymap, highlightSpecialChars, drawSelection, lineNumbers, type KeyBinding } from '@codemirror/view';
-import { EditorState, Compartment } from '@codemirror/state';
-import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands';
-import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
-import { autocompletion } from '@codemirror/autocomplete';
-import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
-import { materialLight } from '@fsegurai/codemirror-theme-material-light';
-import { materialDark } from '@fsegurai/codemirror-theme-material-dark';
-import Toolbar from './Toolbar.vue';
-import ImageSelectorModal from './ImageSelectorModal.vue';
-
-import compile from '~/helpers/markdown';
-import type { Document } from '~/stores';
-import { useModal, Modal } from '~/composables/ModalBus';
-
-const props = defineProps<{ doc?: Partial<Document>; minimal?: boolean }>();
-
-const emit = defineEmits(['save', 'exit']);
-
-const editorContainer = ref<HTMLDivElement>();
-const markdownPreview = ref<HTMLDivElement>();
-const editorView = ref<EditorView | null>(null);
-const showPreview = ref(false);
-
-const document = ref<Partial<Document>>({
- ...props.doc,
- content_html: compile(props.doc?.content_markdown || ''),
-});
-
-function exec(action: string, payload?: string) {
- if (action === 'preview') return (showPreview.value = !showPreview.value);
- if (action === 'openColorPicker') return openColorModal();
- if (action === 'save') return save();
- if (action === 'goto') if (document.value.id) return useRouter().push(`/dashboard/docs/${document.value.id}`);
- if (action === 'image') return openImageSelector();
-
- if (!editorView.value) return;
-
- const view = editorView.value;
- const state = view.state;
-
- const { from, to } = state.selection.main;
- const selectedText = state.sliceDoc(from, to);
-
- let changes;
-
- switch (action) {
- case 'bold':
- changes = { from, to, insert: `**${selectedText}**` };
- break;
- case 'italic':
- changes = { from, to, insert: `*${selectedText}*` };
- break;
- case 'underline':
- changes = { from, to, insert: `__${selectedText}__` };
- break;
- case 'strike':
- changes = { from, to, insert: `~~${selectedText}~~` };
- break;
- case 'link':
- changes = { from, to, insert: `[](${selectedText})` };
- break;
- case 'code':
- changes = { from, to, insert: `\`${selectedText}\`` };
- break;
- case 'quote':
- changes = { from, to, insert: `> ${selectedText}\n` };
- break;
- case 'list':
- changes = { from, to, insert: `- ${selectedText}\n` };
- break;
- case 'orderedList':
- changes = { from, to, insert: `1. ${selectedText}\n` };
- break;
- case 'color': {
- const color = String(payload || '').trim();
- if (!color) return;
- const value = selectedText || 'text';
- const insert = `{color:${color}}(${value})`;
- changes = { from, to, insert };
- break;
- }
- }
- view.dispatch({
- changes,
- selection: { anchor: from + 2, head: to + 2 },
- });
-
- view.focus();
-}
-
-function openColorModal() {
- const rootDoc = window.document;
- const container = rootDoc.createElement('div');
- const modal = rootDoc.createElement('div');
- container.className = 'color-modal-overlay';
- modal.className = 'color-modal';
- modal.innerHTML = `
- <div class="panel">
- <div class="swatches">
- ${['primary', ...appColors].map(c => `<button class="swatch" style="background:var(--${c})" data-color="${c}"></button>`).join('')}
- </div>
- <div class="custom">
- <input class="hex" placeholder="#RRGGBB" />
- <button class="apply">Apply</button>
- </div>
- </div>
- `;
- container.appendChild(modal);
- rootDoc.body.appendChild(container);
- const close = () => {
- if (container.parentNode) rootDoc.body.removeChild(container);
- };
- container.addEventListener('click', e => {
- if (e.target === container) close();
- });
- modal.querySelectorAll('.swatch').forEach(el => {
- el.addEventListener('click', () => {
- const color = (el as HTMLElement).getAttribute('data-color') || '';
- exec('color', color);
- close();
- });
- });
- const input = modal.querySelector('.hex') as HTMLInputElement | null;
- const apply = modal.querySelector('.apply') as HTMLButtonElement | null;
- apply?.addEventListener('click', () => {
- const val = input?.value?.trim() || '';
- if (val) exec('color', val);
- close();
- });
-}
-
-function openImageSelector() {
- const modalManager = useModal();
- console.log('Modals avant ouverture:', modalManager.modals.value.length);
- // Fermer tous les modals existants avant d'en ouvrir un nouveau
- while (modalManager.modals.value.length > 0) {
- modalManager.close(modalManager.modals.value[0]);
- }
- modalManager.add(new Modal(shallowRef(ImageSelectorModal), { onImageSelect: handleImageSelect }, () => {}, true));
- console.log('Modals aprĂšs ouverture:', modalManager.modals.value.length);
-}
-
-function handleImageSelect(imageUrl: string, altText: string) {
- if (!editorView.value) return;
-
- const view = editorView.value;
- const state = view.state;
- const { from, to } = state.selection.main;
- const selectedText = state.sliceDoc(from, to);
-
- const alt = selectedText || altText;
- const insert = `![${alt}](${imageUrl})`;
-
- view.dispatch({
- changes: { from, to, insert },
- selection: { anchor: from + insert.length, head: from + insert.length },
- });
-
- 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 snippetListener = EditorView.updateListener.of(update => {
- if (!update.docChanged || !editorView.value) return;
-
- const { state, transactions } = update;
- const lastTransaction = transactions[0];
-
- const changes = lastTransaction!.changes;
-
- // Ne gĂšre que les insertions simples
- let hasInsertion = false;
- changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
- if (inserted.length > 0) {
- hasInsertion = true;
- }
- });
- if (!hasInsertion) return;
-
- // VĂ©rifie si on vient d’insĂ©rer un mot-clĂ©
- 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));
- if (!match) return;
-
- const start = cursorPos - match.length;
- const snippet = snippets[match];
-
- // remplace $0 par un curseur
- const [before, after] = snippet!.split('$0');
- const newText = (before || '') + after;
-
- const view = editorView.value;
- view.dispatch({
- changes: { from: start, to: cursorPos, insert: newText },
- selection: {
- anchor: start + (before?.length || 0),
- },
- });
-});
-const markdownKeysmap: readonly KeyBinding[] = [
- {
- key: 'Mod-b',
- run: () => {
- exec('bold');
- return true;
- },
- },
- {
- key: 'Mod-i',
- run: () => {
- exec('italic');
- return true;
- },
- },
- {
- key: 'Mod-u',
- run: () => {
- exec('underline');
- return true;
- },
- },
- {
- key: 'Mod-k',
- run: () => {
- exec('image');
- return true;
- },
- },
- {
- key: 'Mod-l',
- run: () => {
- exec('link');
- return true;
- },
- },
-];
-
-const themeCompartment = new Compartment();
-
-watch(useColorMode(), mode => {
- if (!editorView.value) return;
- editorView.value.dispatch({
- effects: themeCompartment.reconfigure(mode.value === 'dark' ? materialDark : materialLight),
- });
-});
-const updateListener = EditorView.updateListener.of(v => {
- if (v.docChanged) {
- const content = v.state.doc.toString();
- document.value.content_markdown = content;
- document.value.content_html = compile(content);
- }
-});
-const state = EditorState.create({
- doc: document.value.content_markdown || '',
- extensions: [
- lineNumbers(),
- highlightSpecialChars(),
- history(),
- drawSelection(),
- autocompletion(),
- // @ts-expect-error types error
- keymap.of([...defaultKeymap, ...historyKeymap, ...searchKeymap, indentWithTab, ...markdownKeysmap]),
- markdown({ base: markdownLanguage }),
- updateListener,
- snippetListener,
- themeCompartment.of(useColorMode().value === 'dark' ? materialDark : materialLight),
- highlightSelectionMatches({}),
- EditorView.lineWrapping,
- EditorState.allowMultipleSelections.of(true),
- ],
-});
-onMounted(() => {
- if (!editorContainer.value) return;
- editorView.value = new EditorView({
- state,
- parent: editorContainer.value,
- });
- editorView.value.scrollDOM.addEventListener('scroll', syncScroll);
- window.addEventListener('keydown', handleGlobalKeys);
-});
-
-onBeforeUnmount(() => {
- if (editorView.value) editorView.value.destroy();
- editorView.value?.scrollDOM.removeEventListener('scroll', syncScroll);
- window.removeEventListener('keydown', handleGlobalKeys);
-});
-
-function handleGlobalKeys(e: KeyboardEvent) {
- if ((e.ctrlKey || e.metaKey) && e.key === 's') {
- e.preventDefault();
- save();
- }
- if ((e.ctrlKey || e.metaKey) && e.key === 'p') {
- e.preventDefault();
- showPreview.value = !showPreview.value;
- }
-
- if (e.key === 'Escape') {
- emit('exit');
- }
-}
-
-function syncScroll() {
- if (!editorView.value?.scrollDOM || !markdownPreview.value) return;
- const scrollPercentage = editorView.value.scrollDOM.scrollTop / (editorView.value.scrollDOM.scrollHeight - editorView.value.scrollDOM.clientHeight);
- markdownPreview.value.scrollTop = scrollPercentage * (markdownPreview.value.scrollHeight - markdownPreview.value.clientHeight);
-}
-
-function save() {
- const content = editorView.value?.state.doc.toString() || '';
- document.value.content_markdown = content;
- document.value.content_html = compile(content);
- emit('save', document.value);
-}
-</script>
-
-<style scoped lang="scss">
-.markdown {
- display: flex;
- min-height: 0; /* permet aux enfants flexibles de ne pas déborder */
- flex: 1;
- gap: 8px;
-}
-
-.editor-container {
- display: flex;
- width: 100%;
- height: 100%;
- flex-direction: column;
-}
-
-.codemirror-editor {
- flex: 1;
- overflow: auto;
-}
-
-.editor-container:deep(.cm-editor) {
- height: 100%;
-}
-/* stylelint-disable */
-.editor-container:deep(.cm-selectionBackground) {
- background-color: var(--selection-color) !important;
-}
-
-.markdown-preview {
- height: 100%;
- padding: 1rem;
- background: var(--bg-color);
- flex: 1;
- overflow: auto;
-}
-
-input {
- border: none;
- outline: none;
-}
-
-.title {
- padding: 6px 10px;
- font-size: 1.5rem;
- font-weight: 600;
-}
-
-.description {
- padding: 4px 10px;
- font-size: 1.1rem;
- font-weight: 500;
-}
-.color-modal-overlay {
- position: fixed;
- z-index: 99999;
- display: flex;
- background: rgb(0 0 0 / 45%);
- align-items: center;
- inset: 0;
- justify-content: center;
-}
-
-.color-modal {
- min-width: 300px;
- padding: 16px;
- border: 1px solid var(--border-color);
- border-radius: 14px;
- background: var(--bg-color);
- box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
-}
-
-.color-modal .panel {
- display: grid;
- gap: 12px;
-}
-
-.color-modal .swatches {
- display: grid;
- gap: 8px;
- grid-template-columns: repeat(9, 1fr);
-}
-
-.color-modal .swatch {
- width: 30px;
- height: 30px;
- border-radius: 50%;
- transition: transform 0.1s ease, box-shadow 0.2s ease;
- cursor: pointer;
-}
-
-.color-modal .swatch:hover {
- box-shadow: 0 6px 16px rgb(0 0 0 / 15%);
- transform: translateY(-1px);
-}
-
-.color-modal .custom {
- display: flex;
- align-items: center;
- gap: 8px;
-}
-
-.color-modal .hex {
- padding: 8px 10px;
- border: 1px solid var(--border-color);
- border-radius: 8px;
- background: var(--bg-color);
- flex: 1;
-}
-
-.color-modal .apply {
- padding: 8px 12px;
- border: 1px solid var(--border-color);
- border-radius: 8px;
- font-weight: 600;
- background: var(--bg-contrast);
- transition: background-color 0.2s ease;
- cursor: pointer;
-}
-
-.color-modal .apply:hover {
- background: var(--border-color);
-}
-
-.image-selector-overlay {
- position: fixed;
- z-index: 99999;
- display: flex;
- background: rgb(0 0 0 / 45%);
- align-items: center;
- inset: 0;
- justify-content: center;
- padding: 20px;
-}
-</style>
+<template>
+ <div style="height: 100%; padding: 4px">
+ <div class="editor-container">
+ <Toolbar v-model="document" :minimal="minimal" @execute-action="exec" />
+ <div style="display: flex; min-height: 0; padding: 6px; flex: 1; flex-direction: column; gap: 8px">
+ <input v-if="!minimal" v-model="document.name" placeholder="Title" class="title" />
+ <input v-if="!minimal" v-model="document.description" placeholder="Description" class="description" />
+ <AppTagInput v-model="document.tags" style="margin-bottom: 10px" />
+ <div ref="container" class="markdown">
+ <div ref="editorContainer" class="codemirror-editor" style="border-right: 1px solid var(--border-color)" />
+ <!-- eslint-disable-next-line vue/no-v-html -->
+ <div v-if="showPreview" ref="markdownPreview" :class="['markdown-preview', `${usePreferences().get('theme')}-theme`]" style="position: relative" v-html="document.content_html" />
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+<script setup lang="ts">
+import { EditorView, keymap, highlightSpecialChars, drawSelection, lineNumbers, type KeyBinding } from '@codemirror/view';
+import { EditorState, Compartment } from '@codemirror/state';
+import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands';
+import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
+import { autocompletion } from '@codemirror/autocomplete';
+import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
+import { materialLight } from '@fsegurai/codemirror-theme-material-light';
+import { materialDark } from '@fsegurai/codemirror-theme-material-dark';
+import Toolbar from './Toolbar.vue';
+import ImageSelectorModal from './ImageSelectorModal.vue';
+import GridOrganizationModal from './GridOrganizationModal.vue';
+import ColorPickerModal from './ColorPickerModal.vue';
+
+import compile from '~/helpers/markdown';
+import type { Document } from '~/stores';
+import { useModal, Modal } from '~/composables/ModalBus';
+
+const props = defineProps<{ doc?: Partial<Document>; minimal?: boolean }>();
+
+const emit = defineEmits(['save', 'exit']);
+
+const editorContainer = ref<HTMLDivElement>();
+const markdownPreview = ref<HTMLDivElement>();
+const editorView = ref<EditorView | null>(null);
+const showPreview = ref(false);
+
+const document = ref<Partial<Document>>({
+ ...props.doc,
+ content_html: compile(props.doc?.content_markdown || ''),
+});
+
+function exec(action: string, payload?: string) {
+ if (action === 'preview') return (showPreview.value = !showPreview.value);
+ if (action === 'openColorPicker') return openColorModal();
+ if (action === 'save') return save();
+ if (action === 'goto') if (document.value.id) return useRouter().push(`/dashboard/docs/${document.value.id}`);
+ if (action === 'image') return openImageSelector();
+ if (action === 'gridOrganization') return openGridOrganization();
+ if (action === 'insertText') return insertText(payload || '');
+
+ if (!editorView.value) return;
+
+ const view = editorView.value;
+ const state = view.state;
+
+ const { from, to } = state.selection.main;
+ const selectedText = state.sliceDoc(from, to);
+
+ let changes;
+
+ switch (action) {
+ case 'bold':
+ changes = { from, to, insert: `**${selectedText}**` };
+ break;
+ case 'italic':
+ changes = { from, to, insert: `*${selectedText}*` };
+ break;
+ case 'underline':
+ changes = { from, to, insert: `__${selectedText}__` };
+ break;
+ case 'strike':
+ changes = { from, to, insert: `~~${selectedText}~~` };
+ break;
+ case 'link':
+ changes = { from, to, insert: `[](${selectedText})` };
+ break;
+ case 'code':
+ changes = { from, to, insert: `\`${selectedText}\`` };
+ break;
+ case 'quote':
+ changes = { from, to, insert: `> ${selectedText}\n` };
+ break;
+ case 'list':
+ changes = { from, to, insert: `- ${selectedText}\n` };
+ break;
+ case 'orderedList':
+ changes = { from, to, insert: `1. ${selectedText}\n` };
+ break;
+ case 'color': {
+ const color = String(payload || '').trim();
+ if (!color) return;
+ const value = selectedText || 'text';
+ const insert = `{color:${color}}(${value})`;
+ changes = { from, to, insert };
+ break;
+ }
+ }
+ view.dispatch({
+ changes,
+ selection: { anchor: from + 2, head: to + 2 },
+ });
+
+ view.focus();
+}
+
+function insertText(text: string) {
+ if (!editorView.value || !text) return;
+
+ const view = editorView.value;
+ const state = view.state;
+ const { from, to } = state.selection.main;
+
+ view.dispatch({
+ changes: { from, to, insert: text },
+ selection: { anchor: from + text.length, head: from + text.length },
+ });
+
+ view.focus();
+}
+
+function openColorModal() {
+ const modalManager = useModal();
+ // Fermer tous les modals existants avant d'en ouvrir un nouveau
+ while (modalManager.modals.value.length > 0) {
+ modalManager.close(modalManager.modals.value[0]);
+ }
+ modalManager.add(new Modal(shallowRef(ColorPickerModal), { onColorSelect: handleColorSelect }, () => {}, true));
+}
+
+function handleColorSelect(color: string) {
+ exec('color', color);
+}
+
+function openImageSelector() {
+ const modalManager = useModal();
+ console.log('Modals avant ouverture:', modalManager.modals.value.length);
+ // Fermer tous les modals existants avant d'en ouvrir un nouveau
+ while (modalManager.modals.value.length > 0) {
+ modalManager.close(modalManager.modals.value[0]);
+ }
+ modalManager.add(new Modal(shallowRef(ImageSelectorModal), { onImageSelect: handleImageSelect }, () => {}, true));
+ console.log('Modals aprĂšs ouverture:', modalManager.modals.value.length);
+}
+
+function openGridOrganization() {
+ const modalManager = useModal();
+ // Fermer tous les modals existants avant d'en ouvrir un nouveau
+ while (modalManager.modals.value.length > 0) {
+ modalManager.close(modalManager.modals.value[0]);
+ }
+ modalManager.add(new Modal(shallowRef(GridOrganizationModal), { onGridSelect: handleGridSelect }, () => {}, true));
+}
+
+function handleImageSelect(imageUrl: string, altText: string) {
+ if (!editorView.value) return;
+
+ const view = editorView.value;
+ const state = view.state;
+ const { from, to } = state.selection.main;
+ const selectedText = state.sliceDoc(from, to);
+
+ const alt = selectedText || altText;
+ const insert = `![${alt}](${imageUrl})`;
+
+ view.dispatch({
+ changes: { from, to, insert },
+ selection: { anchor: from + insert.length, head: from + insert.length },
+ });
+
+ view.focus();
+}
+
+function handleGridSelect(gridMarkdown: string) {
+ if (!editorView.value) return;
+
+ const view = editorView.value;
+ const state = view.state;
+ const { from, to } = state.selection.main;
+
+ view.dispatch({
+ changes: { from, to, insert: gridMarkdown },
+ selection: { anchor: from + gridMarkdown.length, head: from + gridMarkdown.length },
+ });
+
+ 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 snippetListener = EditorView.updateListener.of(update => {
+ if (!update.docChanged || !editorView.value) return;
+
+ const { state, transactions } = update;
+ const lastTransaction = transactions[0];
+
+ const changes = lastTransaction!.changes;
+
+ // Ne gĂšre que les insertions simples
+ let hasInsertion = false;
+ changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
+ if (inserted.length > 0) {
+ hasInsertion = true;
+ }
+ });
+ if (!hasInsertion) return;
+
+ // VĂ©rifie si on vient d’insĂ©rer un mot-clĂ©
+ 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));
+ if (!match) return;
+
+ const start = cursorPos - match.length;
+ const snippet = snippets[match];
+
+ // remplace $0 par un curseur
+ const [before, after] = snippet!.split('$0');
+ const newText = (before || '') + after;
+
+ const view = editorView.value;
+ view.dispatch({
+ changes: { from: start, to: cursorPos, insert: newText },
+ selection: {
+ anchor: start + (before?.length || 0),
+ },
+ });
+});
+const markdownKeysmap: readonly KeyBinding[] = [
+ {
+ key: 'Mod-b',
+ run: () => {
+ exec('bold');
+ return true;
+ },
+ },
+ {
+ key: 'Mod-i',
+ run: () => {
+ exec('italic');
+ return true;
+ },
+ },
+ {
+ key: 'Mod-u',
+ run: () => {
+ exec('underline');
+ return true;
+ },
+ },
+ {
+ key: 'Mod-k',
+ run: () => {
+ exec('image');
+ return true;
+ },
+ },
+ {
+ key: 'Mod-l',
+ run: () => {
+ exec('link');
+ return true;
+ },
+ },
+];
+
+const themeCompartment = new Compartment();
+
+watch(useColorMode(), mode => {
+ if (!editorView.value) return;
+ editorView.value.dispatch({
+ effects: themeCompartment.reconfigure(mode.value === 'dark' ? materialDark : materialLight),
+ });
+});
+const updateListener = EditorView.updateListener.of(v => {
+ if (v.docChanged) {
+ const content = v.state.doc.toString();
+ document.value.content_markdown = content;
+ document.value.content_html = compile(content);
+ }
+});
+const state = EditorState.create({
+ doc: document.value.content_markdown || '',
+ extensions: [
+ lineNumbers(),
+ highlightSpecialChars(),
+ history(),
+ drawSelection(),
+ autocompletion(),
+ // @ts-expect-error types error
+ keymap.of([...defaultKeymap, ...historyKeymap, ...searchKeymap, indentWithTab, ...markdownKeysmap]),
+ markdown({ base: markdownLanguage }),
+ updateListener,
+ snippetListener,
+ themeCompartment.of(useColorMode().value === 'dark' ? materialDark : materialLight),
+ highlightSelectionMatches({}),
+ EditorView.lineWrapping,
+ EditorState.allowMultipleSelections.of(true),
+ ],
+});
+onMounted(() => {
+ if (!editorContainer.value) return;
+ editorView.value = new EditorView({
+ state,
+ parent: editorContainer.value,
+ });
+ editorView.value.scrollDOM.addEventListener('scroll', syncScroll);
+ window.addEventListener('keydown', handleGlobalKeys);
+});
+
+onBeforeUnmount(() => {
+ if (editorView.value) editorView.value.destroy();
+ editorView.value?.scrollDOM.removeEventListener('scroll', syncScroll);
+ window.removeEventListener('keydown', handleGlobalKeys);
+});
+
+function handleGlobalKeys(e: KeyboardEvent) {
+ if ((e.ctrlKey || e.metaKey) && e.key === 's') {
+ e.preventDefault();
+ save();
+ }
+ if ((e.ctrlKey || e.metaKey) && e.key === 'p') {
+ e.preventDefault();
+ showPreview.value = !showPreview.value;
+ }
+
+ if (e.key === 'Escape') {
+ emit('exit');
+ }
+}
+
+function syncScroll() {
+ if (!editorView.value?.scrollDOM || !markdownPreview.value) return;
+ const scrollPercentage = editorView.value.scrollDOM.scrollTop / (editorView.value.scrollDOM.scrollHeight - editorView.value.scrollDOM.clientHeight);
+ markdownPreview.value.scrollTop = scrollPercentage * (markdownPreview.value.scrollHeight - markdownPreview.value.clientHeight);
+}
+
+function save() {
+ const content = editorView.value?.state.doc.toString() || '';
+ document.value.content_markdown = content;
+ document.value.content_html = compile(content);
+ emit('save', document.value);
+}
+</script>
+
+<style scoped lang="scss">
+.markdown {
+ display: flex;
+ min-height: 0; /* permet aux enfants flexibles de ne pas déborder */
+ flex: 1;
+ gap: 8px;
+}
+
+.editor-container {
+ display: flex;
+ width: 100%;
+ height: 100%;
+ flex-direction: column;
+}
+
+.codemirror-editor {
+ flex: 1;
+ overflow: auto;
+}
+
+.editor-container:deep(.cm-editor) {
+ height: 100%;
+}
+/* stylelint-disable */
+.editor-container:deep(.cm-selectionBackground) {
+ background-color: var(--selection-color) !important;
+}
+
+.markdown-preview {
+ height: 100%;
+ padding: 1rem;
+ background: var(--bg-color);
+ flex: 1;
+ overflow: auto;
+}
+
+input {
+ border: none;
+ outline: none;
+}
+
+.title {
+ padding: 6px 10px;
+ font-size: 1.5rem;
+ font-weight: 600;
+}
+
+.description {
+ padding: 4px 10px;
+ font-size: 1.1rem;
+ font-weight: 500;
+}
+
+
+.image-selector-overlay {
+ position: fixed;
+ z-index: 99999;
+ display: flex;
+ background: rgb(0 0 0 / 45%);
+ align-items: center;
+ inset: 0;
+ justify-content: center;
+ padding: 20px;
+}
+</style>
diff --git a/frontend/app/components/MarkdownEditor/Toolbar.vue b/frontend/app/components/MarkdownEditor/Toolbar.vue
index d216b9a3..fef2886d 100644
--- a/frontend/app/components/MarkdownEditor/Toolbar.vue
+++ b/frontend/app/components/MarkdownEditor/Toolbar.vue
@@ -1,193 +1,203 @@
-<template>
- <div class="toolbar">
- <!-- eslint-disable-next-line vue/no-v-html -->
- <button v-for="item in toolbar" :key="item.name" :title="item.name" class="btn" @click="emitAction(item.action)" v-html="item.icon" />
- <div class="color-picker" />
- <AppSelect v-if="!minimal" v-model="localValue.accessibility" :items="accessibilities" placeholder="Access" size="100px" class="entry" />
- <AppSelect v-if="!minimal" v-model="localValue.category" :items="categories" placeholder="Select category" size="300px" class="entry" />
- <AppHint text="Tags has been moved down" />
- <button class="help" @click="openModal">
- <Icon name="help" :big="true" fill="var(--font-color-light)" />
- </button>
- </div>
-</template>
-
-<script setup lang="ts">
-import type { Document } from '~/stores';
-import ModalSyntax from './ModalSyntax.vue';
-
-const props = defineProps<{
- modelValue: Partial<Document>;
- minimal?: boolean;
-}>();
-
-const emit = defineEmits<{
- (e: 'update:modelValue', value: Partial<Document>): void;
- (e: 'execute-action', action: string): void;
-}>();
-
-const localValue = computed({
- get: () => props.modelValue,
- set: val => emit('update:modelValue', val),
-});
-
-const emitAction = (action: string) => emit('execute-action', action);
-
-const openModal = () => useModal().add(new Modal(shallowRef(ModalSyntax), {}, () => {}, true));
-
-const categories = new TreeStructure(useSidebarTree().categories.value).generateTree().filter(i => i.data.type === 'category' && i.data.role == 2);
-
-const accessibilities: ANode[] = [
- { id: 1, label: 'Visible', parent_id: '' },
- { id: 2, label: 'Draft', parent_id: '' },
- { id: 3, label: 'Archive', parent_id: '' },
-];
-
-const toolbar = [
- {
- name: 'Bold',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M272-200v-560h221q65 0 120 40t55 111q0 51-23 78.5T602-491q25 11 55.5 41t30.5 90q0 89-65 124.5T501-200H272Zm121-112h104q48 0 58.5-24.5T566-372q0-11-10.5-35.5T494-432H393v120Zm0-228h93q33 0 48-17t15-38q0-24-17-39t-44-15h-95v109Z"/></svg>',
- action: 'bold',
- },
- {
- name: 'Italic',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M200-200v-100h160l120-360H320v-100h400v100H580L460-300h140v100H200Z"/></svg>',
- action: 'italic',
- },
- {
- name: 'Underline',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M200-120v-80h560v80H200Zm280-160q-101 0-157-63t-56-167v-330h103v336q0 56 28 91t82 35q54 0 82-35t28-91v-336h103v330q0 104-56 167t-157 63Z"/></svg>',
- action: 'underline',
- },
- {
- name: 'Strike',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M486-160q-76 0-135-45t-85-123l88-38q14 48 48.5 79t85.5 31q42 0 76-20t34-64q0-18-7-33t-19-27h112q5 14 7.5 28.5T694-340q0 86-61.5 133T486-160ZM80-480v-80h800v80H80Zm402-326q66 0 115.5 32.5T674-674l-88 39q-9-29-33.5-52T484-710q-41 0-68 18.5T386-640h-96q2-69 54.5-117.5T482-806Z"/></svg>',
- action: 'strike',
- },
- {
- name: 'Link',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M440-280H280q-83 0-141.5-58.5T80-480q0-83 58.5-141.5T280-680h160v80H280q-50 0-85 35t-35 85q0 50 35 85t85 35h160v80ZM320-440v-80h320v80H320Zm200 160v-80h160q50 0 85-35t35-85q0-50-35-85t-85-35H520v-80h160q83 0 141.5 58.5T880-480q0 83-58.5 141.5T680-280H520Z"/></svg>',
- action: 'link',
- },
- {
- name: 'Image',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm40-80h480L570-480 450-320l-90-120-120 160Zm-40 80v-560 560Z"/></svg>',
- action: 'image',
- },
- {
- name: 'Code',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M320-240 80-480l240-240 57 57-184 184 183 183-56 56Zm320 0-57-57 184-184-183-183 56-56 240 240-240 240Z"/></svg>',
- action: 'code',
- },
- {
- name: 'Quote',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="m228-240 92-160q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 23-5.5 42.5T458-480L320-240h-92Zm360 0 92-160q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 23-5.5 42.5T818-480L680-240h-92ZM320-500q25 0 42.5-17.5T380-560q0-25-17.5-42.5T320-620q-25 0-42.5 17.5T260-560q0 25 17.5 42.5T320-500Zm360 0q25 0 42.5-17.5T740-560q0-25-17.5-42.5T680-620q-25 0-42.5 17.5T620-560q0 25 17.5 42.5T680-500Zm0-60Zm-360 0Z"/></svg>',
- action: 'quote',
- },
- {
- name: 'List',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M280-600v-80h560v80H280Zm0 160v-80h560v80H280Zm0 160v-80h560v80H280ZM160-600q-17 0-28.5-11.5T120-640q0-17 11.5-28.5T160-680q17 0 28.5 11.5T200-640q0 17-11.5 28.5T160-600Zm0 160q-17 0-28.5-11.5T120-480q0-17 11.5-28.5T160-520q17 0 28.5 11.5T200-480q0 17-11.5 28.5T160-440Zm0 160q-17 0-28.5-11.5T120-320q0-17 11.5-28.5T160-360q17 0 28.5 11.5T200-320q0 17-11.5 28.5T160-280Z"/></svg>',
- action: 'list',
- },
- {
- name: 'Ordered List',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M680-80v-60h100v-30h-60v-60h60v-30H680v-60h120q17 0 28.5 11.5T840-280v40q0 17-11.5 28.5T800-200q17 0 28.5 11.5T840-160v40q0 17-11.5 28.5T800-80H680Zm0-280v-110q0-17 11.5-28.5T720-510h60v-30H680v-60h120q17 0 28.5 11.5T840-560v70q0 17-11.5 28.5T800-450h-60v30h100v60H680Zm60-280v-180h-60v-60h120v240h-60ZM120-200v-80h480v80H120Zm0-240v-80h480v80H120Zm0-240v-80h480v80H120Z"/></svg>',
- action: 'orderedList',
- },
- {
- name: 'Color',
- icon: `<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M480-80q-82 0-155-31.5t-127.5-86Q143-252 111.5-325T80-480q0-83 32.5-156t88-127Q256-817 330-848.5T488-880q80 0 151 27.5t124.5 76q53.5 48.5 85 115T880-518q0 115-70 176.5T640-280h-74q-9 0-12.5 5t-3.5 11q0 12 15 34.5t15 51.5q0 50-27.5 74T480-80Zm0-400Zm-220 40q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm120-160q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm200 0q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm120 160q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17ZM480-160q9 0 14.5-5t5.5-13q0-14-15-33t-15-57q0-42 29-67t71-25h70q66 0 113-38.5T800-518q0-121-92.5-201.5T488-800q-136 0-232 93t-96 227q0 133 93.5 226.5T480-160Z"/></svg>`,
- action: 'openColorPicker',
- },
- {
- name: 'Preview',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-480H200v480Zm280-80q-82 0-146.5-44.5T240-440q29-71 93.5-115.5T480-600q82 0 146.5 44.5T720-440q-29 71-93.5 115.5T480-280Zm0-60q56 0 102-26.5t72-73.5q-26-47-72-73.5T480-540q-56 0-102 26.5T306-440q26 47 72 73.5T480-340Zm0-100Zm0 60q25 0 42.5-17.5T540-440q0-25-17.5-42.5T480-500q-25 0-42.5 17.5T420-440q0 25 17.5 42.5T480-380Z"/></svg>',
- action: 'preview',
- },
- {
- name: 'Save',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M840-680v480q0 33-23.5 56.5T760-120H200q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h480l160 160Zm-80 34L646-760H200v560h560v-446ZM480-240q50 0 85-35t35-85q0-50-35-85t-85-35q-50 0-85 35t-35 85q0 50 35 85t85 35ZM240-560h360v-160H240v160Zm-40-86v446-560 114Z"/></svg>',
- action: 'save',
- },
- {
- name: 'Go to Document',
- icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M400-280h160v-80H400v80Zm0-160h280v-80H400v80ZM280-600h400v-80H280v80Zm200 120ZM265-80q-79 0-134.5-55.5T75-270q0-57 29.5-102t77.5-68H80v-80h240v240h-80v-97q-37 8-61 38t-24 69q0 46 32.5 78t77.5 32v80Zm135-40v-80h360v-560H200v160h-80v-160q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H400Z"/></svg>`,
- action: 'goto',
- },
-];
-</script>
-<style scoped lang="scss">
-.toolbar {
- display: flex;
- width: 100%;
- padding: 0.15rem;
- border: 1px solid var(--border-color);
- border-radius: 20px;
- color: var(--font-color-dark);
- align-items: center;
- flex-wrap: wrap;
- gap: 0 3px;
- user-select: none;
-}
-
-.btn {
- display: flex;
- margin: 0;
- padding: 4px;
- border-radius: 50%;
- transition: background-color 0.2s;
- align-items: center;
- justify-content: center;
- transform: none;
-
- &:hover {
- background-color: var(--primary-bg);
-
- &:deep(svg) {
- transition: fill 0.2s;
- fill: var(--primary);
- }
- }
-}
-
-.color-picker .btn.color {
- position: relative;
- width: 30px;
- height: 30px;
-}
-
-.color-picker .btn.color .dot {
- position: absolute;
- right: 2px;
- bottom: 2px;
- width: 8px;
- height: 8px;
- border: 1px solid var(--border-color);
- border-radius: 999px;
- background: var(--primary);
-}
-
-.btn:deep(svg) {
- width: 24px;
- height: 24px;
- fill: var(--font-color-dark);
-}
-
-input,
-.select {
- display: inline-block;
- max-width: 350px;
-}
-
-.entry {
- background-color: var(--bg-color);
-}
-
-.help {
- margin-left: auto;
-
- &:hover:deep(svg) {
- fill: var(--font-color-dark);
- }
-}
-</style>
+<template>
+ <div class="toolbar">
+ <!-- eslint-disable-next-line vue/no-v-html -->
+ <button v-for="item in toolbar" :key="item.name" :title="item.name" class="btn" @click="emitAction(item.action)" v-html="item.icon" />
+ <VoiceRecognition @transcription="handleTranscription" />
+ <div class="color-picker" />
+ <AppSelect v-if="!minimal" v-model="localValue.accessibility" :items="accessibilities" placeholder="Access" size="100px" class="entry" />
+ <AppSelect v-if="!minimal" v-model="localValue.category" :items="categories" placeholder="Select category" size="300px" class="entry" />
+ <AppHint text="Tags has been moved down" />
+ <button class="help" @click="openModal">
+ <Icon name="help" :big="true" fill="var(--font-color-light)" />
+ </button>
+ </div>
+</template>
+
+<script setup lang="ts">
+import type { Document } from '~/stores';
+import ModalSyntax from './ModalSyntax.vue';
+import VoiceRecognition from './VoiceRecognition.vue';
+
+const props = defineProps<{
+ modelValue: Partial<Document>;
+ minimal?: boolean;
+}>();
+
+const emit = defineEmits<{
+ (e: 'update:modelValue', value: Partial<Document>): void;
+ (e: 'execute-action', action: string, payload?: any): void;
+}>();
+
+const localValue = computed({
+ get: () => props.modelValue,
+ set: val => emit('update:modelValue', val),
+});
+
+const emitAction = (action: string) => emit('execute-action', action);
+
+const handleTranscription = (text: string) => {
+ emit('execute-action', 'insertText', text);
+};
+
+const openModal = () => useModal().add(new Modal(shallowRef(ModalSyntax), {}, () => {}, true));
+
+const categories = new TreeStructure(useSidebarTree().categories.value).generateTree().filter(i => i.data.type === 'category' && i.data.role == 2);
+
+const accessibilities: ANode[] = [
+ { id: 1, label: 'Visible', parent_id: '' },
+ { id: 2, label: 'Draft', parent_id: '' },
+ { id: 3, label: 'Archive', parent_id: '' },
+];
+
+const toolbar = [
+ {
+ name: 'Bold',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M272-200v-560h221q65 0 120 40t55 111q0 51-23 78.5T602-491q25 11 55.5 41t30.5 90q0 89-65 124.5T501-200H272Zm121-112h104q48 0 58.5-24.5T566-372q0-11-10.5-35.5T494-432H393v120Zm0-228h93q33 0 48-17t15-38q0-24-17-39t-44-15h-95v109Z"/></svg>',
+ action: 'bold',
+ },
+ {
+ name: 'Italic',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M200-200v-100h160l120-360H320v-100h400v100H580L460-300h140v100H200Z"/></svg>',
+ action: 'italic',
+ },
+ {
+ name: 'Underline',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M200-120v-80h560v80H200Zm280-160q-101 0-157-63t-56-167v-330h103v336q0 56 28 91t82 35q54 0 82-35t28-91v-336h103v330q0 104-56 167t-157 63Z"/></svg>',
+ action: 'underline',
+ },
+ {
+ name: 'Strike',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M486-160q-76 0-135-45t-85-123l88-38q14 48 48.5 79t85.5 31q42 0 76-20t34-64q0-18-7-33t-19-27h112q5 14 7.5 28.5T694-340q0 86-61.5 133T486-160ZM80-480v-80h800v80H80Zm402-326q66 0 115.5 32.5T674-674l-88 39q-9-29-33.5-52T484-710q-41 0-68 18.5T386-640h-96q2-69 54.5-117.5T482-806Z"/></svg>',
+ action: 'strike',
+ },
+ {
+ name: 'Link',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M440-280H280q-83 0-141.5-58.5T80-480q0-83 58.5-141.5T280-680h160v80H280q-50 0-85 35t-35 85q0 50 35 85t85 35h160v80ZM320-440v-80h320v80H320Zm200 160v-80h160q50 0 85-35t35-85q0-50-35-85t-85-35H520v-80h160q83 0 141.5 58.5T880-480q0 83-58.5 141.5T680-280H520Z"/></svg>',
+ action: 'link',
+ },
+ {
+ name: 'Image',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm40-80h480L570-480 450-320l-90-120-120 160Zm-40 80v-560 560Z"/></svg>',
+ action: 'image',
+ },
+ {
+ name: 'Code',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M320-240 80-480l240-240 57 57-184 184 183 183-56 56Zm320 0-57-57 184-184-183-183 56-56 240 240-240 240Z"/></svg>',
+ action: 'code',
+ },
+ {
+ name: 'Quote',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="m228-240 92-160q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 23-5.5 42.5T458-480L320-240h-92Zm360 0 92-160q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 23-5.5 42.5T818-480L680-240h-92ZM320-500q25 0 42.5-17.5T380-560q0-25-17.5-42.5T320-620q-25 0-42.5 17.5T260-560q0 25 17.5 42.5T320-500Zm360 0q25 0 42.5-17.5T740-560q0-25-17.5-42.5T680-620q-25 0-42.5 17.5T620-560q0 25 17.5 42.5T680-500Zm0-60Zm-360 0Z"/></svg>',
+ action: 'quote',
+ },
+ {
+ name: 'List',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M280-600v-80h560v80H280Zm0 160v-80h560v80H280Zm0 160v-80h560v80H280ZM160-600q-17 0-28.5-11.5T120-640q0-17 11.5-28.5T160-680q17 0 28.5 11.5T200-640q0 17-11.5 28.5T160-600Zm0 160q-17 0-28.5-11.5T120-480q0-17 11.5-28.5T160-520q17 0 28.5 11.5T200-480q0 17-11.5 28.5T160-440Zm0 160q-17 0-28.5-11.5T120-320q0-17 11.5-28.5T160-360q17 0 28.5 11.5T200-320q0 17-11.5 28.5T160-280Z"/></svg>',
+ action: 'list',
+ },
+ {
+ name: 'Ordered List',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M680-80v-60h100v-30h-60v-60h60v-30H680v-60h120q17 0 28.5 11.5T840-280v40q0 17-11.5 28.5T800-200q17 0 28.5 11.5T840-160v40q0 17-11.5 28.5T800-80H680Zm0-280v-110q0-17 11.5-28.5T720-510h60v-30H680v-60h120q17 0 28.5 11.5T840-560v70q0 17-11.5 28.5T800-450h-60v30h100v60H680Zm60-280v-180h-60v-60h120v240h-60ZM120-200v-80h480v80H120Zm0-240v-80h480v80H120Zm0-240v-80h480v80H120Z"/></svg>',
+ action: 'orderedList',
+ },
+ {
+ name: 'Grid Organization',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="2" y="2" width="20" height="20" rx="3" ry="3" fill="none" stroke="currentColor" stroke-width="2"/><g fill="none" stroke="currentColor" stroke-width="2"><line x1="2" y1="8" x2="22" y2="8"/><line x1="2" y1="16" x2="22" y2="16"/><line x1="8" y1="2" x2="8" y2="22"/><line x1="16" y1="2" x2="16" y2="22"/></g></svg>', action: 'gridOrganization',
+ },
+ {
+ name: 'Color',
+ icon: `<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M480-80q-82 0-155-31.5t-127.5-86Q143-252 111.5-325T80-480q0-83 32.5-156t88-127Q256-817 330-848.5T488-880q80 0 151 27.5t124.5 76q53.5 48.5 85 115T880-518q0 115-70 176.5T640-280h-74q-9 0-12.5 5t-3.5 11q0 12 15 34.5t15 51.5q0 50-27.5 74T480-80Zm0-400Zm-220 40q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm120-160q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm200 0q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm120 160q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17ZM480-160q9 0 14.5-5t5.5-13q0-14-15-33t-15-57q0-42 29-67t71-25h70q66 0 113-38.5T800-518q0-121-92.5-201.5T488-800q-136 0-232 93t-96 227q0 133 93.5 226.5T480-160Z"/></svg>`,
+ action: 'openColorPicker',
+ },
+ {
+ name: 'Preview',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-480H200v480Zm280-80q-82 0-146.5-44.5T240-440q29-71 93.5-115.5T480-600q82 0 146.5 44.5T720-440q-29 71-93.5 115.5T480-280Zm0-60q56 0 102-26.5t72-73.5q-26-47-72-73.5T480-540q-56 0-102 26.5T306-440q26 47 72 73.5T480-340Zm0-100Zm0 60q25 0 42.5-17.5T540-440q0-25-17.5-42.5T480-500q-25 0-42.5 17.5T420-440q0 25 17.5 42.5T480-380Z"/></svg>',
+ action: 'preview',
+ },
+ {
+ name: 'Save',
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M840-680v480q0 33-23.5 56.5T760-120H200q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h480l160 160Zm-80 34L646-760H200v560h560v-446ZM480-240q50 0 85-35t35-85q0-50-35-85t-85-35q-50 0-85 35t-35 85q0 50 35 85t85 35ZM240-560h360v-160H240v160Zm-40-86v446-560 114Z"/></svg>',
+ action: 'save',
+ },
+ {
+ name: 'Go to Document',
+ icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M400-280h160v-80H400v80Zm0-160h280v-80H400v80ZM280-600h400v-80H280v80Zm200 120ZM265-80q-79 0-134.5-55.5T75-270q0-57 29.5-102t77.5-68H80v-80h240v240h-80v-97q-37 8-61 38t-24 69q0 46 32.5 78t77.5 32v80Zm135-40v-80h360v-560H200v160h-80v-160q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H400Z"/></svg>`,
+ action: 'goto',
+ },
+];
+</script>
+<style scoped lang="scss">
+.toolbar {
+ display: flex;
+ width: 100%;
+ padding: 0.15rem;
+ border: 1px solid var(--border-color);
+ border-radius: 20px;
+ color: var(--font-color-dark);
+ align-items: center;
+ flex-wrap: wrap;
+ gap: 0 3px;
+ user-select: none;
+}
+
+.btn {
+ display: flex;
+ margin: 0;
+ padding: 4px;
+ border-radius: 50%;
+ transition: background-color 0.2s;
+ align-items: center;
+ justify-content: center;
+ transform: none;
+
+ &:hover {
+ background-color: var(--primary-bg);
+
+ &:deep(svg) {
+ transition: fill 0.2s;
+ fill: var(--primary);
+ }
+ }
+}
+
+.color-picker .btn.color {
+ position: relative;
+ width: 30px;
+ height: 30px;
+}
+
+.color-picker .btn.color .dot {
+ position: absolute;
+ right: 2px;
+ bottom: 2px;
+ width: 8px;
+ height: 8px;
+ border: 1px solid var(--border-color);
+ border-radius: 999px;
+ background: var(--primary);
+}
+
+.btn:deep(svg) {
+ width: 24px;
+ height: 24px;
+ fill: var(--font-color-dark);
+}
+
+input,
+.select {
+ display: inline-block;
+ max-width: 350px;
+}
+
+.entry {
+ background-color: var(--bg-color);
+}
+
+.help {
+ margin-left: auto;
+
+ &:hover:deep(svg) {
+ fill: var(--font-color-dark);
+ }
+}
+</style>
diff --git a/frontend/app/components/MarkdownEditor/VoiceRecognition.vue b/frontend/app/components/MarkdownEditor/VoiceRecognition.vue
new file mode 100644
index 00000000..6c8f3a42
--- /dev/null
+++ b/frontend/app/components/MarkdownEditor/VoiceRecognition.vue
@@ -0,0 +1,234 @@
+<template>
+ <div class="voice-recognition">
+ <div style="font-size: 10px; color: red;">Debug: {{ isRecording }} | Icon: {{ isRecording ? 'CLOSED' : 'OPEN' }}</div>
+ <button
+ :class="['btn', { 'recording': isRecording }]"
+ :title="isRecording ? 'Stop recording' : 'Start voice recognition'"
+ @click="toggleRecording"
+ >
+ <svg
+ v-if="!isRecording"
+ xmlns="http://www.w3.org/2000/svg"
+ width="24" height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ >
+ <rect x="9" y="2" width="6" height="12" rx="3"/>
+ <path d="M5 10v2a7 7 0 0 0 14 0v-2"/>
+ <path d="M12 19v3"/>
+ <path d="M8 22h8"/>
+ </svg>
+ <svg
+ v-else
+ xmlns="http://www.w3.org/2000/svg"
+ width="24" height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ >
+ <rect x="9" y="2" width="6" height="12" rx="3"/>
+ <path d="M5 10v2a7 7 0 0 0 14 0v-2"/>
+ <path d="M12 19v3"/>
+ <path d="M8 22h8"/>
+ <line x1="2" y1="2" x2="22" y2="22"/>
+ </svg>
+ </button>
+ </div>
+</template>
+
+<script setup lang="ts">
+const props = defineProps<{
+ onTranscription?: (text: string) => void;
+}>();
+
+const emit = defineEmits<{
+ (e: 'transcription', text: string): void;
+}>();
+
+const isRecording = ref(false);
+const recognition = ref<any>(null);
+const lastTranscribedText = ref('');
+const transcriptionBuffer = ref<string[]>([]);
+const isProcessing = ref(false);
+const recordingStartTime = ref(0);
+
+const language = ref('fr-FR');
+
+const startRecording = () => {
+ if (!('webkitSpeechRecognition' in window) && !('SpeechRecognition' in window)) {
+ alert('Speech recognition not supported in this browser');
+ return;
+ }
+
+ lastTranscribedText.value = '';
+ transcriptionBuffer.value = [];
+ isProcessing.value = false;
+ recordingStartTime.value = Date.now();
+ const SpeechRecognition = (window as any).SpeechRecognition || (window as any).webkitSpeechRecognition;
+ recognition.value = new SpeechRecognition();
+
+ recognition.value.continuous = true;
+ recognition.value.interimResults = false;
+ recognition.value.maxAlternatives = 1;
+ recognition.value.lang = language.value;
+
+ recognition.value.onstart = () => {
+ console.log('Speech recognition started, setting isRecording to true');
+ isRecording.value = true;
+ };
+
+ recognition.value.onresult = (event: any) => {
+ if (isProcessing.value) return;
+
+ let finalTranscript = '';
+
+ for (let i = event.resultIndex; i < event.results.length; i++) {
+ const transcript = event.results[i][0].transcript;
+ if (event.results[i].isFinal) {
+ finalTranscript += transcript;
+ }
+ }
+
+ if (finalTranscript && finalTranscript.trim()) {
+ const cleanText = finalTranscript.trim();
+
+ if (cleanText.length > 0 && cleanText !== lastTranscribedText.value) {
+ isProcessing.value = true;
+
+ setTimeout(() => {
+ lastTranscribedText.value = cleanText;
+ emit('transcription', cleanText);
+ if (props.onTranscription) {
+ props.onTranscription(cleanText);
+ }
+ isProcessing.value = false;
+ }, 100);
+ }
+ }
+ };
+
+ recognition.value.onerror = (event: any) => {
+ console.error('Speech recognition error:', event.error);
+
+ if (event.error === 'no-speech' || event.error === 'audio-capture') {
+ console.log('No speech detected, continuing recording...');
+ return;
+ }
+
+ isRecording.value = false;
+ };
+
+ recognition.value.onend = () => {
+ const recordingDuration = Date.now() - recordingStartTime.value;
+ console.log('Speech recognition ended after', recordingDuration, 'ms');
+
+ if (recordingDuration < 1000) {
+ console.log('Recording too short, restarting...');
+ if (recognition.value) {
+ recognition.value.start();
+ }
+ return;
+ }
+
+ isRecording.value = false;
+ };
+
+ recognition.value.start();
+};
+
+const stopRecording = () => {
+ const recordingDuration = Date.now() - recordingStartTime.value;
+
+ if (recordingDuration < 1000) {
+ console.log('Recording too short, not stopping yet');
+ return;
+ }
+
+ if (recognition.value) {
+ recognition.value.stop();
+ recognition.value = null;
+ }
+ isRecording.value = false;
+ console.log('Recording stopped after', recordingDuration, 'ms');
+};
+
+const toggleRecording = () => {
+ console.log('Toggle recording called, current state:', isRecording.value);
+ if (isRecording.value) {
+ console.log('Stopping recording...');
+ stopRecording();
+ } else {
+ console.log('Starting recording...');
+ startRecording();
+ }
+ console.log('New recording state:', isRecording.value);
+};
+
+onUnmounted(() => {
+ if (recognition.value) {
+ recognition.value.stop();
+ }
+});
+</script>
+
+<style scoped lang="scss">
+.voice-recognition {
+ display: inline-block;
+}
+
+.btn {
+ display: flex;
+ margin: 0;
+ padding: 4px;
+ border-radius: 50%;
+ transition: all 0.2s;
+ align-items: center;
+ justify-content: center;
+ transform: none;
+ border: none;
+ background: none;
+ cursor: pointer;
+ width: 32px;
+ height: 32px;
+
+ &:hover {
+ background-color: var(--primary-bg);
+ }
+
+ &.recording {
+ background-color: var(--error-bg);
+ animation: pulse 2s infinite;
+ }
+
+ svg {
+ width: 24px;
+ height: 24px;
+ stroke: var(--font-color-dark);
+ fill: none;
+ display: block;
+ }
+
+ &.recording svg {
+ stroke: var(--error);
+ }
+}
+
+@keyframes pulse {
+ 0% {
+ transform: scale(1);
+ }
+ 50% {
+ transform: scale(1.1);
+ }
+ 100% {
+ transform: scale(1);
+ }
+}
+</style>
diff --git a/frontend/app/components/MarkdownSyntax.vue b/frontend/app/components/MarkdownSyntax.vue
index f6604037..debed2d4 100644
--- a/frontend/app/components/MarkdownSyntax.vue
+++ b/frontend/app/components/MarkdownSyntax.vue
@@ -97,6 +97,136 @@ Custom RGB allowed: {color:#2cafcc}(custom 1) {color:#34b125}(custom 2)</pre
>
</div>
+ <h2>đŸ”Č Grid Organization</h2>
+ <p>Use the <strong>Grid Organization</strong> button in the toolbar to create custom layouts:</p>
+
+ <h3>Quick Presets</h3>
+ <p>Pre-built grid layouts for common use cases:</p>
+
+ <div class="grid-examples">
+ <div class="grid-example">
+ <h4>2x2 Grid</h4>
+ <div class="grid-preview grid-2x2">
+ <div class="grid-cell">Cell 1</div>
+ <div class="grid-cell">Cell 2</div>
+ <div class="grid-cell">Cell 3</div>
+ <div class="grid-cell">Cell 4</div>
+ </div>
+ <p><strong>Perfect for:</strong> Comparing two concepts, pros/cons lists</p>
+ </div>
+
+ <div class="grid-example">
+ <h4>3x2 Grid</h4>
+ <div class="grid-preview grid-3x2">
+ <div class="grid-cell">Cell 1</div>
+ <div class="grid-cell">Cell 2</div>
+ <div class="grid-cell">Cell 3</div>
+ <div class="grid-cell">Cell 4</div>
+ <div class="grid-cell">Cell 5</div>
+ <div class="grid-cell">Cell 6</div>
+ </div>
+ <p><strong>Ideal for:</strong> Feature comparisons, process steps</p>
+ </div>
+
+ <div class="grid-example">
+ <h4>2x3 Grid</h4>
+ <div class="grid-preview grid-2x3">
+ <div class="grid-cell">Cell 1</div>
+ <div class="grid-cell">Cell 2</div>
+ <div class="grid-cell">Cell 3</div>
+ <div class="grid-cell">Cell 4</div>
+ <div class="grid-cell">Cell 5</div>
+ <div class="grid-cell">Cell 6</div>
+ </div>
+ <p><strong>Great for:</strong> Step-by-step processes, timelines</p>
+ </div>
+
+ <div class="grid-example">
+ <h4>3x3 Grid</h4>
+ <div class="grid-preview grid-3x3">
+ <div class="grid-cell">Cell 1</div>
+ <div class="grid-cell">Cell 2</div>
+ <div class="grid-cell">Cell 3</div>
+ <div class="grid-cell">Cell 4</div>
+ <div class="grid-cell">Cell 5</div>
+ <div class="grid-cell">Cell 6</div>
+ <div class="grid-cell">Cell 7</div>
+ <div class="grid-cell">Cell 8</div>
+ <div class="grid-cell">Cell 9</div>
+ </div>
+ <p><strong>Comprehensive:</strong> Information display, data organization</p>
+ </div>
+ </div>
+ <h3>Generated Markdown</h3>
+ <p>Here's what gets inserted when you use the Grid Organization tool:</p>
+
+ <div class="markdown-examples">
+ <div class="example-section">
+ <h4>Simple 2x2 Table</h4>
+ <div class="rendered-table">
+ <table>
+ <thead>
+ <tr>
+ <th>Header 1</th>
+ <th>Header 2</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>Cell 1</td>
+ <td>Cell 2</td>
+ </tr>
+ <tr>
+ <td>Cell 3</td>
+ <td>Cell 4</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <pre>| Header 1 | Header 2 |
+|----------|----------|
+| Cell 1 | Cell 2 |
+| Cell 3 | Cell 4 |</pre>
+ </div>
+
+ <div class="example-section">
+ <h4>3x3 Data Table</h4>
+ <div class="rendered-table">
+ <table>
+ <thead>
+ <tr>
+ <th>Product</th>
+ <th>Price</th>
+ <th>Rating</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>Item A</td>
+ <td>$19.99</td>
+ <td>⭐⭐⭐⭐⭐</td>
+ </tr>
+ <tr>
+ <td>Item B</td>
+ <td>$29.99</td>
+ <td>⭐⭐⭐⭐</td>
+ </tr>
+ <tr>
+ <td>Item C</td>
+ <td>$39.99</td>
+ <td>⭐⭐⭐</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <pre>| Product | Price | Rating |
+|---------|--------|--------|
+| Item A | $19.99 | ⭐⭐⭐⭐⭐ |
+| Item B | $29.99 | ⭐⭐⭐⭐ |
+| Item C | $39.99 | ⭐⭐⭐ |</pre>
+ </div>
+ </div>
+
<h2>đŸ’» Code</h2>
<p>Inline: <code>`inline code`</code></p>
<p>Multiline:</p>
@@ -232,4 +362,238 @@ Snippets help you focus on writing, not formatting.
color: white;
overflow-x: auto;
}
+
+/* Grid Organization Examples */
+.grid-examples {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
+ gap: 2rem;
+ margin: 1.5rem 0;
+}
+
+.grid-example {
+ background: var(--bg-color-secondary);
+ border: 1px solid var(--border-color);
+ border-radius: 12px;
+ padding: 1.5rem;
+ text-align: center;
+}
+
+.grid-example h4 {
+ margin: 0 0 1rem 0;
+ color: var(--primary);
+ font-size: 1.1rem;
+ font-weight: 600;
+}
+
+.grid-preview {
+ display: grid;
+ gap: 4px;
+ margin: 1rem 0;
+ justify-content: center;
+}
+
+.grid-2x2 {
+ grid-template-columns: repeat(2, 60px);
+ grid-template-rows: repeat(2, 40px);
+}
+
+.grid-3x2 {
+ grid-template-columns: repeat(3, 50px);
+ grid-template-rows: repeat(2, 40px);
+}
+
+.grid-2x3 {
+ grid-template-columns: repeat(2, 60px);
+ grid-template-rows: repeat(3, 35px);
+}
+
+.grid-3x3 {
+ grid-template-columns: repeat(3, 50px);
+ grid-template-rows: repeat(3, 35px);
+}
+
+.grid-cell {
+ background: var(--primary);
+ color: white;
+ border-radius: 6px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 0.8rem;
+ font-weight: 500;
+ text-align: center;
+ padding: 4px;
+ transition: all 0.3s ease;
+}
+
+.grid-cell:hover {
+ transform: scale(1.05);
+ box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.3);
+}
+
+/* Custom Grid Layouts */
+.custom-grid-examples {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
+ gap: 2rem;
+ margin: 1.5rem 0;
+}
+
+.custom-grid-example {
+ background: var(--bg-color-secondary);
+ border: 1px solid var(--border-color);
+ border-radius: 12px;
+ padding: 1.5rem;
+}
+
+.custom-grid-example h4 {
+ margin: 0 0 1rem 0;
+ color: var(--primary);
+ font-size: 1.1rem;
+ font-weight: 600;
+}
+
+.custom-grid-preview {
+ display: grid;
+ gap: 4px;
+ margin: 1rem 0;
+}
+
+.header-content {
+ grid-template-columns: 2fr 1fr;
+ grid-template-rows: auto 1fr;
+}
+
+.header-content .header-cell {
+ grid-column: 1 / -1;
+ background: var(--blue);
+ height: 50px;
+}
+
+.header-content .content-cell {
+ background: var(--green);
+ height: 80px;
+}
+
+.header-content .sidebar-cell {
+ background: var(--purple);
+ height: 80px;
+}
+
+.feature-compare {
+ grid-template-columns: 1fr 1fr 1fr;
+ grid-template-rows: auto auto auto;
+}
+
+.feature-compare .feature-header {
+ grid-column: 1 / -1;
+ background: var(--primary);
+ height: 40px;
+}
+
+.feature-compare .plan-a {
+ background: var(--blue);
+ height: 35px;
+}
+
+.feature-compare .plan-b {
+ background: var(--green);
+ height: 35px;
+}
+
+.feature-compare .feature-1,
+.feature-compare .feature-2 {
+ background: var(--grey);
+ height: 35px;
+}
+
+.feature-compare .plan-a-yes,
+.feature-compare .plan-b-yes {
+ background: var(--green);
+ height: 35px;
+ font-size: 1.2rem;
+}
+
+.feature-compare .plan-a-no {
+ background: var(--red);
+ height: 35px;
+ font-size: 1.2rem;
+}
+
+/* Markdown Examples */
+.markdown-examples {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
+ gap: 2rem;
+ margin: 1.5rem 0;
+}
+
+.example-section {
+ background: var(--bg-color-secondary);
+ border: 1px solid var(--border-color);
+ border-radius: 12px;
+ padding: 1.5rem;
+}
+
+.example-section h4 {
+ margin: 0 0 1rem 0;
+ color: var(--primary);
+ font-size: 1.1rem;
+ font-weight: 600;
+}
+
+.rendered-table {
+ margin: 1rem 0;
+ overflow-x: auto;
+}
+
+.rendered-table table {
+ width: 100%;
+ border-collapse: collapse;
+ background: var(--bg-color);
+ border-radius: 8px;
+ overflow: hidden;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
+}
+
+.rendered-table th {
+ background: var(--primary);
+ color: white;
+ padding: 12px;
+ text-align: left;
+ font-weight: 600;
+}
+
+.rendered-table td {
+ padding: 10px 12px;
+ border-top: 1px solid var(--border-color);
+}
+
+.rendered-table tr:hover {
+ background: var(--bg-color-secondary);
+}
+
+/* Responsive adjustments */
+@media (max-width: 768px) {
+ .grid-examples,
+ .custom-grid-examples,
+ .markdown-examples {
+ grid-template-columns: 1fr;
+ gap: 1.5rem;
+ }
+
+ .grid-example,
+ .custom-grid-example,
+ .example-section {
+ padding: 1rem;
+ }
+
+ .grid-2x2,
+ .grid-3x2,
+ .grid-2x3,
+ .grid-3x3 {
+ transform: scale(0.9);
+ }
+}
</style>