Implement ID-based routing and folder auto-generation from titles
Major features:
- Switch from slug-based to ID-based routing (/documents/123)
- Enable title editing with automatic slug/path regeneration
- Auto-generate folder structure from title slashes (e.g., Laravel/Livewire/Components)
- Persist sidebar folder open/close state using localStorage
- Remove slug unique constraint (ID routing makes it unnecessary)
- Implement recursive tree view with multi-level folder support
Architecture changes:
- DocumentService: Add generatePathAndSlug() for title-based path generation
- Routes: Change from {document:slug} to {document} for ID binding
- SidebarTree: Extract recursive rendering to partials/tree-item.blade.php
- Database: Remove unique constraint from documents.slug column
UI improvements:
- Display only last path component in sidebar (Components vs Laravel/Livewire/Components)
- Folder state persists across page navigation via localStorage
- Title field accepts slashes for folder organization
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
166
src/resources/views/livewire/document-editor.blade.php
Normal file
166
src/resources/views/livewire/document-editor.blade.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<div class="max-w-5xl mx-auto p-8">
|
||||
<!-- Flash Messages -->
|
||||
@if (session()->has('message'))
|
||||
<div class="mb-4 p-4 bg-green-100 border border-green-400 text-green-700 rounded">
|
||||
{{ session('message') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if (session()->has('error'))
|
||||
<div class="mb-4 p-4 bg-red-100 border border-red-400 text-red-700 rounded">
|
||||
{{ session('error') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- Header -->
|
||||
<div class="mb-6 flex items-center justify-between">
|
||||
<h1 class="text-3xl font-bold text-gray-900">
|
||||
{{ $isEditMode ? 'Edit Document' : 'New Document' }}
|
||||
</h1>
|
||||
|
||||
<div class="flex space-x-3">
|
||||
@if($isEditMode && $document)
|
||||
<a
|
||||
href="{{ route('documents.show', $document) }}"
|
||||
class="inline-flex items-center px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 bg-white hover:bg-gray-50"
|
||||
>
|
||||
Cancel
|
||||
</a>
|
||||
|
||||
<button
|
||||
wire:click="delete"
|
||||
wire:confirm="Are you sure you want to delete this document?"
|
||||
class="inline-flex items-center px-4 py-2 border border-red-300 rounded-md text-sm font-medium text-red-700 bg-white hover:bg-red-50"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
@else
|
||||
<a
|
||||
href="{{ route('documents.show', 'home') }}"
|
||||
class="inline-flex items-center px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 bg-white hover:bg-gray-50"
|
||||
>
|
||||
Cancel
|
||||
</a>
|
||||
@endif
|
||||
|
||||
<button
|
||||
wire:click="save"
|
||||
class="inline-flex items-center px-4 py-2 bg-indigo-600 border border-transparent rounded-md text-sm font-medium text-white hover:bg-indigo-700"
|
||||
>
|
||||
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4"></path>
|
||||
</svg>
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Form -->
|
||||
<form wire:submit.prevent="save" class="space-y-6">
|
||||
<!-- Title -->
|
||||
<div>
|
||||
<label for="title" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
Title
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="title"
|
||||
wire:model="title"
|
||||
class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
|
||||
placeholder="Document Title (use / for folders, e.g. Laravel/Livewire/Components)"
|
||||
>
|
||||
@error('title')
|
||||
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
|
||||
@enderror
|
||||
<p class="mt-1 text-xs text-gray-500">
|
||||
Tip: Use slashes (/) in the title to organize documents into folders automatically
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Markdown Editor -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2">
|
||||
Content
|
||||
</label>
|
||||
<div wire:ignore>
|
||||
<div x-data="markdownEditor()" x-init="initEditor()">
|
||||
<textarea
|
||||
x-ref="editor"
|
||||
class="w-full"
|
||||
>{{ $content }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" wire:model="content">
|
||||
</div>
|
||||
@error('content')
|
||||
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
|
||||
@enderror
|
||||
|
||||
<!-- Auto-save indicator -->
|
||||
<div class="flex items-center justify-between text-sm text-gray-500">
|
||||
<div wire:loading wire:target="save" class="flex items-center">
|
||||
<svg class="animate-spin h-4 w-4 mr-2 text-indigo-600" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||
</svg>
|
||||
Saving...
|
||||
</div>
|
||||
|
||||
@if($isEditMode && $document)
|
||||
<div>
|
||||
Path: <code class="text-xs bg-gray-100 px-2 py-1 rounded">{{ $document->path }}</code>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@push('styles')
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/easymde/dist/easymde.min.css">
|
||||
@endpush
|
||||
|
||||
@push('scripts')
|
||||
<script src="https://cdn.jsdelivr.net/npm/easymde/dist/easymde.min.js"></script>
|
||||
<script>
|
||||
document.addEventListener('alpine:init', () => {
|
||||
Alpine.data('markdownEditor', () => ({
|
||||
editor: null,
|
||||
|
||||
initEditor() {
|
||||
this.$nextTick(() => {
|
||||
const textarea = this.$refs.editor;
|
||||
|
||||
this.editor = new EasyMDE({
|
||||
element: textarea,
|
||||
autofocus: true,
|
||||
spellChecker: false,
|
||||
autosave: {
|
||||
enabled: false,
|
||||
},
|
||||
placeholder: 'Write your markdown here...',
|
||||
toolbar: [
|
||||
'bold', 'italic', 'heading', '|',
|
||||
'quote', 'unordered-list', 'ordered-list', '|',
|
||||
'link', 'image', '|',
|
||||
'preview', 'side-by-side', 'fullscreen', '|',
|
||||
'guide'
|
||||
],
|
||||
status: ['lines', 'words', 'cursor'],
|
||||
});
|
||||
|
||||
// エディタの変更をLivewireに反映
|
||||
this.editor.codemirror.on('change', () => {
|
||||
// wire:ignoreの外にあるhidden inputを探す
|
||||
const formElement = this.$el.closest('form');
|
||||
const hiddenInput = formElement.querySelector('input[type="hidden"][wire\\:model="content"]');
|
||||
if (hiddenInput) {
|
||||
hiddenInput.value = this.editor.value();
|
||||
hiddenInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}));
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
81
src/resources/views/livewire/document-viewer.blade.php
Normal file
81
src/resources/views/livewire/document-viewer.blade.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<div class="max-w-4xl mx-auto p-8">
|
||||
<!-- Document Header -->
|
||||
<div class="mb-8">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h1 class="text-4xl font-bold text-gray-900">
|
||||
{{ $document->title }}
|
||||
</h1>
|
||||
|
||||
@auth
|
||||
<a
|
||||
href="{{ route('documents.edit', $document) }}"
|
||||
class="inline-flex items-center px-4 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
|
||||
>
|
||||
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
|
||||
</svg>
|
||||
Edit
|
||||
</a>
|
||||
@endauth
|
||||
</div>
|
||||
|
||||
<div class="flex items-center text-sm text-gray-500 space-x-4">
|
||||
@if($document->created_by)
|
||||
<span>
|
||||
Created by {{ $document->creator->name }}
|
||||
</span>
|
||||
@endif
|
||||
|
||||
<span>
|
||||
Updated {{ $document->updated_at->diffForHumans() }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Document Content -->
|
||||
<div class="prose prose-lg max-w-none mb-12">
|
||||
{!! $renderedContent !!}
|
||||
</div>
|
||||
|
||||
<!-- Backlinks Section -->
|
||||
@if(count($backlinks) > 0)
|
||||
<div class="border-t border-gray-200 pt-8">
|
||||
<h2 class="text-xl font-semibold text-gray-900 mb-4">
|
||||
Linked References
|
||||
</h2>
|
||||
|
||||
<div class="space-y-3">
|
||||
@foreach($backlinks as $backlink)
|
||||
<a
|
||||
href="{{ route('documents.show', $backlink) }}"
|
||||
class="block p-4 bg-gray-50 rounded-lg hover:bg-gray-100 transition"
|
||||
wire:navigate
|
||||
>
|
||||
<div class="flex items-center">
|
||||
<svg class="w-4 h-4 mr-2 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
|
||||
</svg>
|
||||
<span class="text-sm font-medium text-gray-900">
|
||||
{{ $backlink->title }}
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- Document Metadata -->
|
||||
<div class="mt-12 pt-8 border-t border-gray-200">
|
||||
<div class="grid grid-cols-2 gap-4 text-sm text-gray-500">
|
||||
<div>
|
||||
<span class="font-medium">Path:</span>
|
||||
<code class="ml-2 text-xs bg-gray-100 px-2 py-1 rounded">{{ $document->path }}</code>
|
||||
</div>
|
||||
<div>
|
||||
<span class="font-medium">Last modified:</span>
|
||||
<span class="ml-2">{{ $document->updated_at->format('Y-m-d H:i:s') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
131
src/resources/views/livewire/quick-switcher.blade.php
Normal file
131
src/resources/views/livewire/quick-switcher.blade.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<div
|
||||
x-data="{ open: false }"
|
||||
@open-quick-switcher.window="console.log('Event received'); open = true; $nextTick(() => $refs.searchInput.focus())"
|
||||
@keydown.escape.window="open = false"
|
||||
@keydown.ctrl.k.window.prevent="console.log('Ctrl+K pressed'); open = true; $nextTick(() => $refs.searchInput.focus())"
|
||||
@keydown.meta.k.window.prevent="console.log('Cmd+K pressed'); open = true; $nextTick(() => $refs.searchInput.focus())"
|
||||
>
|
||||
<!-- Modal Overlay -->
|
||||
<div
|
||||
x-show="open"
|
||||
x-transition:enter="transition ease-out duration-200"
|
||||
x-transition:enter-start="opacity-0"
|
||||
x-transition:enter-end="opacity-100"
|
||||
x-transition:leave="transition ease-in duration-150"
|
||||
x-transition:leave-start="opacity-100"
|
||||
x-transition:leave-end="opacity-0"
|
||||
class="fixed inset-0 z-50 bg-gray-900 bg-opacity-50"
|
||||
@click="open = false"
|
||||
style="display: none;"
|
||||
></div>
|
||||
|
||||
<!-- Modal Content -->
|
||||
<div
|
||||
x-show="open"
|
||||
x-transition:enter="transition ease-out duration-200"
|
||||
x-transition:enter-start="opacity-0 translate-y-4"
|
||||
x-transition:enter-end="opacity-100 translate-y-0"
|
||||
x-transition:leave="transition ease-in duration-150"
|
||||
x-transition:leave-start="opacity-100 translate-y-0"
|
||||
x-transition:leave-end="opacity-0 translate-y-4"
|
||||
class="fixed inset-0 z-50 overflow-y-auto"
|
||||
style="display: none;"
|
||||
>
|
||||
<div class="flex min-h-full items-start justify-center p-4 pt-[10vh]">
|
||||
<div
|
||||
class="w-full max-w-2xl bg-white rounded-lg shadow-2xl"
|
||||
@click.stop
|
||||
wire:keydown.arrow-down.prevent="selectNext"
|
||||
wire:keydown.arrow-up.prevent="selectPrevious"
|
||||
wire:keydown.enter.prevent="selectDocument"
|
||||
>
|
||||
<!-- Search Input -->
|
||||
<div class="p-4 border-b border-gray-200">
|
||||
<div class="relative">
|
||||
<svg class="absolute left-3 top-1/2 transform -translate-y-1/2 h-5 w-5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
|
||||
</svg>
|
||||
<input
|
||||
x-ref="searchInput"
|
||||
type="text"
|
||||
wire:model.live="search"
|
||||
class="w-full pl-10 pr-4 py-3 border-0 focus:ring-0 text-lg"
|
||||
placeholder="Search documents..."
|
||||
autocomplete="off"
|
||||
>
|
||||
</div>
|
||||
<!-- Debug Info -->
|
||||
<div class="text-xs text-gray-500 mt-2">
|
||||
Search value: "{{ $search }}" | Results count: {{ count($this->results) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
<div class="max-h-96 overflow-y-auto">
|
||||
@if(empty($this->results))
|
||||
<div class="p-8 text-center text-gray-500">
|
||||
No documents found
|
||||
</div>
|
||||
@else
|
||||
<ul class="divide-y divide-gray-200">
|
||||
@foreach($this->results as $index => $result)
|
||||
<li>
|
||||
<a
|
||||
href="{{ route('documents.show', $result['id']) }}"
|
||||
class="block px-4 py-3 hover:bg-gray-50 transition {{ $index === $selectedIndex ? 'bg-indigo-50' : '' }}"
|
||||
wire:navigate
|
||||
@click="open = false"
|
||||
>
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="flex items-center">
|
||||
<svg class="flex-shrink-0 h-5 w-5 text-gray-400 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
|
||||
</svg>
|
||||
<span class="text-sm font-medium text-gray-900 truncate">
|
||||
{{ $result['title'] }}
|
||||
</span>
|
||||
</div>
|
||||
@if(!empty($result['directory']) && $result['directory'] !== '.')
|
||||
<p class="mt-1 text-xs text-gray-500 truncate ml-8">
|
||||
{{ $result['directory'] }}
|
||||
</p>
|
||||
@endif
|
||||
</div>
|
||||
@if($index === $selectedIndex)
|
||||
<kbd class="ml-2 px-2 py-1 text-xs font-semibold text-gray-800 bg-gray-100 border border-gray-200 rounded">
|
||||
↵
|
||||
</kbd>
|
||||
@endif
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<div class="px-4 py-3 bg-gray-50 border-t border-gray-200 text-xs text-gray-500">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center space-x-4">
|
||||
<span class="flex items-center">
|
||||
<kbd class="px-2 py-1 bg-white border border-gray-300 rounded text-xs font-semibold mr-1">↑</kbd>
|
||||
<kbd class="px-2 py-1 bg-white border border-gray-300 rounded text-xs font-semibold mr-2">↓</kbd>
|
||||
to navigate
|
||||
</span>
|
||||
<span class="flex items-center">
|
||||
<kbd class="px-2 py-1 bg-white border border-gray-300 rounded text-xs font-semibold mr-2">↵</kbd>
|
||||
to select
|
||||
</span>
|
||||
<span class="flex items-center">
|
||||
<kbd class="px-2 py-1 bg-white border border-gray-300 rounded text-xs font-semibold mr-2">esc</kbd>
|
||||
to close
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
31
src/resources/views/livewire/sidebar-tree.blade.php
Normal file
31
src/resources/views/livewire/sidebar-tree.blade.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<div class="p-4" x-data="sidebarState()" x-init="initExpandedFolders()">
|
||||
<div class="mb-4">
|
||||
<h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wider">
|
||||
Documents
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
@if(empty($tree))
|
||||
<div class="text-sm text-gray-500 italic">
|
||||
No documents found
|
||||
</div>
|
||||
@else
|
||||
<div class="space-y-1">
|
||||
@include('partials.tree-item', ['tree' => $tree, 'path' => ''])
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@auth
|
||||
<div class="mt-6 pt-6 border-t border-gray-200">
|
||||
<a
|
||||
href="{{ route('documents.create') }}"
|
||||
class="flex items-center justify-center px-4 py-2 text-sm font-medium text-white bg-indigo-600 rounded-md hover:bg-indigo-700"
|
||||
>
|
||||
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
|
||||
</svg>
|
||||
New Document
|
||||
</a>
|
||||
</div>
|
||||
@endauth
|
||||
</div>
|
||||
Reference in New Issue
Block a user