react-embed-docs 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/components/Breadcrumbs.d.ts.map +1 -1
- package/dist/client/components/Breadcrumbs.js +9 -6
- package/dist/client/components/DocumentEdit.d.ts.map +1 -1
- package/dist/client/components/DocumentEdit.js +336 -8
- package/dist/client/components/DocumentList.d.ts.map +1 -1
- package/dist/client/components/DocumentList.js +18 -8
- package/dist/client/components/DocumentProvider.d.ts +1 -1
- package/dist/client/components/DocumentProvider.d.ts.map +1 -1
- package/dist/client/components/DocumentProvider.js +5 -1
- package/dist/client/components/DocumentView.d.ts.map +1 -1
- package/dist/client/components/DocumentView.js +5 -3
- package/dist/client/components/EmojiPicker.d.ts.map +1 -1
- package/dist/client/components/EmojiPicker.js +3 -1
- package/dist/client/components/ExportButton.d.ts.map +1 -1
- package/dist/client/components/ExportButton.js +14 -12
- package/dist/client/components/Layout.d.ts.map +1 -1
- package/dist/client/components/Layout.js +7 -3
- package/dist/client/components/ReactEmbedDocs.d.ts.map +1 -1
- package/dist/client/components/ReactEmbedDocs.js +2 -1
- package/dist/client/components/Sidebar.d.ts.map +1 -1
- package/dist/client/components/Sidebar.js +4 -2
- package/dist/client/components/VersionHistory.d.ts.map +1 -1
- package/dist/client/components/VersionHistory.js +13 -11
- package/dist/client/hooks/useTranslation.d.ts +13 -0
- package/dist/client/hooks/useTranslation.d.ts.map +1 -0
- package/dist/client/hooks/useTranslation.js +27 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/locales/en.json +83 -0
- package/dist/client/locales/ru.json +83 -0
- package/package.json +1 -1
- package/dist/client/components/DocsLayout.d.ts +0 -20
- package/dist/client/components/DocsLayout.d.ts.map +0 -1
- package/dist/client/components/DocsLayout.js +0 -387
- package/dist/client/providers/DocumentProvider.d.ts +0 -1
- package/dist/client/providers/DocumentProvider.d.ts.map +0 -1
- package/dist/client/providers/DocumentProvider.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DocsLayout.d.ts","sourceRoot":"","sources":["../../../src/client/components/DocsLayout.tsx"],"names":[],"mappings":"AAoCA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAavD,UAAU,eAAe;IACvB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACxB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC5B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,eAAe,EAAE,CAAA;CAChD;AAsQD,wBAAgB,UAAU,CAAC,EACzB,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,QAAkB,EAClB,UAAU,EACV,QAAQ,GACT,EAAE,eAAe,2CAgcjB"}
|
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { closestCenter, defaultDropAnimationSideEffects, DndContext, DragOverlay, KeyboardSensor, PointerSensor, useSensor, useSensors, } from '@dnd-kit/core';
|
|
4
|
-
import { SortableContext, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy, } from '@dnd-kit/sortable';
|
|
5
|
-
import { CSS } from '@dnd-kit/utilities';
|
|
6
|
-
import { ChevronDown, ChevronRight, FileText, Folder, FolderOpen, GripVertical, PanelLeftCloseIcon, PanelLeftOpenIcon, Plus, Search, } from 'lucide-react';
|
|
7
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
|
-
import { useDocumentsQuery, useReorderDocumentMutation, } from '../hooks/useDocsQuery.js';
|
|
9
|
-
import { Breadcrumbs } from './Breadcrumbs.js';
|
|
10
|
-
function SortableTreeItem({ doc, isExpanded, isCurrent, onToggle, onNavigate, }) {
|
|
11
|
-
const { attributes, listeners, setNodeRef, transform, transition, isDragging, } = useSortable({ id: doc.id });
|
|
12
|
-
const style = {
|
|
13
|
-
transform: CSS.Transform.toString(transform),
|
|
14
|
-
transition,
|
|
15
|
-
opacity: isDragging ? 0.5 : 1,
|
|
16
|
-
paddingLeft: doc.depth * 12 + 8,
|
|
17
|
-
};
|
|
18
|
-
return (_jsxs("div", { ref: setNodeRef, style: style, className: [
|
|
19
|
-
'flex items-center gap-1 w-full px-2 py-1.5 text-sm rounded-md transition-colors cursor-pointer',
|
|
20
|
-
isCurrent ? 'font-bold' : 'hover:opacity-80',
|
|
21
|
-
isDragging && 'opacity-50',
|
|
22
|
-
].join(' '), children: [_jsx("div", { ...attributes, ...listeners, className: "cursor-grab active:cursor-grabbing p-0.5 rounded", onClick: (e) => e.stopPropagation(), children: _jsx(GripVertical, { className: "h-4 w-4 text-gray-400" }) }), doc.hasChildren ? (_jsx("button", { onClick: (e) => {
|
|
23
|
-
e.stopPropagation();
|
|
24
|
-
onToggle(doc.id);
|
|
25
|
-
}, className: "p-0.5 hover:bg-gray-200 rounded shrink-0", children: isExpanded ? (_jsx(ChevronDown, { className: "h-4 w-4" })) : (_jsx(ChevronRight, { className: "h-4 w-4" })) })) : (_jsx("div", { className: "w-4" })), doc.emoji ? (_jsx("span", { className: "text-base shrink-0", children: doc.emoji })) : doc.hasChildren ? (isExpanded ? (_jsx(FolderOpen, { className: "h-4 w-4 shrink-0 text-muted" })) : (_jsx(Folder, { className: "h-4 w-4 shrink-0 text-muted" }))) : (_jsx(FileText, { className: "h-4 w-4 shrink-0 text-gray-400" })), _jsx("span", { className: "truncate flex-1", onClick: () => onNavigate(doc.id), children: doc.title })] }));
|
|
26
|
-
}
|
|
27
|
-
// Drag Overlay Item
|
|
28
|
-
function DragOverlayItem({ doc }) {
|
|
29
|
-
return (_jsxs("div", { className: [
|
|
30
|
-
'flex items-center gap-1 w-full px-2 py-1.5 text-sm text-gray-500 rounded-md shadow-lg',
|
|
31
|
-
'opacity-80',
|
|
32
|
-
].join(' '), children: [_jsx(GripVertical, { className: "h-4 w-4 text-gray-400" }), _jsx("div", { className: "w-5" }), doc.emoji ? (_jsx("span", { className: "text-base shrink-0", children: doc.emoji })) : doc.hasChildren ? (_jsx(Folder, { className: "h-4 w-4 shrink-0 text-blue-600" })) : (_jsx(FileText, { className: "h-4 w-4 shrink-0 text-gray-400" })), _jsx("span", { className: "truncate", children: doc.title })] }));
|
|
33
|
-
}
|
|
34
|
-
// Simple debounce hook
|
|
35
|
-
function useDebounce(value, delay) {
|
|
36
|
-
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
const timer = setTimeout(() => {
|
|
39
|
-
setDebouncedValue(value);
|
|
40
|
-
}, delay);
|
|
41
|
-
return () => clearTimeout(timer);
|
|
42
|
-
}, [value, delay]);
|
|
43
|
-
return debouncedValue;
|
|
44
|
-
}
|
|
45
|
-
// Build breadcrumb path for a document
|
|
46
|
-
function buildBreadcrumb(doc, allDocs) {
|
|
47
|
-
const parts = [doc.title];
|
|
48
|
-
let current = doc;
|
|
49
|
-
while (current.parentId) {
|
|
50
|
-
const parent = allDocs.find((d) => d.id === current.parentId);
|
|
51
|
-
if (!parent)
|
|
52
|
-
break;
|
|
53
|
-
parts.unshift(parent.title);
|
|
54
|
-
current = parent;
|
|
55
|
-
}
|
|
56
|
-
return parts.join(' / ');
|
|
57
|
-
}
|
|
58
|
-
// Build full path from root to document (for URL navigation)
|
|
59
|
-
function buildDocumentPath(docId, allDocs, basePath) {
|
|
60
|
-
const pathParts = [];
|
|
61
|
-
const visited = new Set();
|
|
62
|
-
let currentId = docId;
|
|
63
|
-
while (currentId) {
|
|
64
|
-
// Prevent infinite loops from circular references
|
|
65
|
-
if (visited.has(currentId))
|
|
66
|
-
break;
|
|
67
|
-
visited.add(currentId);
|
|
68
|
-
const doc = allDocs.find((d) => d.id === currentId);
|
|
69
|
-
if (!doc)
|
|
70
|
-
break;
|
|
71
|
-
pathParts.unshift(doc.slug || doc.id);
|
|
72
|
-
currentId = doc.parentId ?? null;
|
|
73
|
-
}
|
|
74
|
-
if (pathParts.length === 0)
|
|
75
|
-
return basePath;
|
|
76
|
-
return `${basePath}/${pathParts.join('/')}`;
|
|
77
|
-
}
|
|
78
|
-
// Get all ancestor IDs of a document (for auto-expanding)
|
|
79
|
-
function getAncestorIds(docId, allDocs) {
|
|
80
|
-
const ancestors = [];
|
|
81
|
-
const visited = new Set();
|
|
82
|
-
let currentId = docId;
|
|
83
|
-
while (currentId) {
|
|
84
|
-
if (visited.has(currentId))
|
|
85
|
-
break;
|
|
86
|
-
visited.add(currentId);
|
|
87
|
-
const doc = allDocs.find((d) => d.id === currentId);
|
|
88
|
-
if (!doc)
|
|
89
|
-
break;
|
|
90
|
-
if (doc.parentId) {
|
|
91
|
-
ancestors.push(doc.parentId);
|
|
92
|
-
currentId = doc.parentId;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return ancestors;
|
|
99
|
-
}
|
|
100
|
-
// Extract text snippets from BlockNote content
|
|
101
|
-
function extractTextSnippets(content, query) {
|
|
102
|
-
if (!content || typeof content !== 'object')
|
|
103
|
-
return [];
|
|
104
|
-
const snippets = [];
|
|
105
|
-
const queryLower = query.toLowerCase();
|
|
106
|
-
const extractFromBlock = (block) => {
|
|
107
|
-
if (!block || typeof block !== 'object')
|
|
108
|
-
return '';
|
|
109
|
-
const b = block;
|
|
110
|
-
// Handle text content
|
|
111
|
-
if (b.content && Array.isArray(b.content)) {
|
|
112
|
-
return b.content
|
|
113
|
-
.map((c) => {
|
|
114
|
-
if (typeof c === 'string')
|
|
115
|
-
return c;
|
|
116
|
-
if (c && typeof c === 'object') {
|
|
117
|
-
const contentItem = c;
|
|
118
|
-
if (contentItem.text && typeof contentItem.text === 'string') {
|
|
119
|
-
return contentItem.text;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return '';
|
|
123
|
-
})
|
|
124
|
-
.join(' ');
|
|
125
|
-
}
|
|
126
|
-
// Handle children
|
|
127
|
-
if (b.children && Array.isArray(b.children)) {
|
|
128
|
-
return b.children.map(extractFromBlock).join(' ');
|
|
129
|
-
}
|
|
130
|
-
return '';
|
|
131
|
-
};
|
|
132
|
-
const contentObj = content;
|
|
133
|
-
if (contentObj.content && Array.isArray(contentObj.content)) {
|
|
134
|
-
for (const block of contentObj.content) {
|
|
135
|
-
const text = extractFromBlock(block);
|
|
136
|
-
if (text.toLowerCase().includes(queryLower)) {
|
|
137
|
-
// Find the position of the match
|
|
138
|
-
const matchIndex = text.toLowerCase().indexOf(queryLower);
|
|
139
|
-
const start = Math.max(0, matchIndex - 20);
|
|
140
|
-
const end = Math.min(text.length, matchIndex + query.length + 60);
|
|
141
|
-
let snippet = text.slice(start, end);
|
|
142
|
-
// Add ellipsis if truncated
|
|
143
|
-
if (start > 0)
|
|
144
|
-
snippet = '...' + snippet;
|
|
145
|
-
if (end < text.length)
|
|
146
|
-
snippet = snippet + '...';
|
|
147
|
-
snippets.push(snippet);
|
|
148
|
-
if (snippets.length >= 2)
|
|
149
|
-
break; // Limit to 2 snippets
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return snippets;
|
|
154
|
-
}
|
|
155
|
-
export function DocsLayout({ children, currentDocId, onNavigate, basePath = '/docs', userAvatar, onSearch, }) {
|
|
156
|
-
const [expandedFolders, setExpandedFolders] = useState(new Set());
|
|
157
|
-
const [searchQuery, setSearchQuery] = useState('');
|
|
158
|
-
const [activeId, setActiveId] = useState(null);
|
|
159
|
-
const [isSidebarOpen, setIsSidebarOpen] = useState(true);
|
|
160
|
-
// Header search state
|
|
161
|
-
const [headerSearchQuery, setHeaderSearchQuery] = useState('');
|
|
162
|
-
const [showSearchResults, setShowSearchResults] = useState(false);
|
|
163
|
-
const debouncedSearchQuery = useDebounce(headerSearchQuery, 300);
|
|
164
|
-
const searchInputRef = useRef(null);
|
|
165
|
-
const { data } = useDocumentsQuery();
|
|
166
|
-
const reorderMutation = useReorderDocumentMutation();
|
|
167
|
-
const documents = data?.documents ?? [];
|
|
168
|
-
// Search query for header search
|
|
169
|
-
const { data: searchResultsData } = useDocumentsQuery(debouncedSearchQuery.length > 0 ? { search: debouncedSearchQuery } : {});
|
|
170
|
-
const searchResults = searchResultsData?.documents ?? [];
|
|
171
|
-
// Resolve currentDocId (which might be a slug) to actual document ID
|
|
172
|
-
const resolvedCurrentDocId = useMemo(() => {
|
|
173
|
-
if (!currentDocId || documents.length === 0)
|
|
174
|
-
return null;
|
|
175
|
-
// First try to find by ID
|
|
176
|
-
const byId = documents.find((d) => d.id === currentDocId);
|
|
177
|
-
if (byId)
|
|
178
|
-
return byId.id;
|
|
179
|
-
// Then try to find by slug
|
|
180
|
-
const bySlug = documents.find((d) => d.slug === currentDocId);
|
|
181
|
-
if (bySlug)
|
|
182
|
-
return bySlug.id;
|
|
183
|
-
return null;
|
|
184
|
-
}, [currentDocId, documents]);
|
|
185
|
-
// Auto-expand tree branches when current document changes
|
|
186
|
-
useEffect(() => {
|
|
187
|
-
if (!resolvedCurrentDocId || documents.length === 0)
|
|
188
|
-
return;
|
|
189
|
-
const ancestors = getAncestorIds(resolvedCurrentDocId, documents);
|
|
190
|
-
// Expand all ancestors so the current document is visible
|
|
191
|
-
if (ancestors.length > 0) {
|
|
192
|
-
setExpandedFolders((prev) => {
|
|
193
|
-
const newExpanded = new Set(prev);
|
|
194
|
-
ancestors.forEach((id) => newExpanded.add(id));
|
|
195
|
-
return newExpanded;
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
}, [resolvedCurrentDocId, documents]);
|
|
199
|
-
// Handle click outside to close search results
|
|
200
|
-
useEffect(() => {
|
|
201
|
-
const handleClickOutside = (event) => {
|
|
202
|
-
if (searchInputRef.current &&
|
|
203
|
-
!searchInputRef.current.contains(event.target)) {
|
|
204
|
-
setShowSearchResults(false);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
document.addEventListener('mousedown', handleClickOutside);
|
|
208
|
-
return () => document.removeEventListener('mousedown', handleClickOutside);
|
|
209
|
-
}, []);
|
|
210
|
-
// Build flattened tree for sortable context
|
|
211
|
-
const flattenedTree = useMemo(() => {
|
|
212
|
-
const items = [];
|
|
213
|
-
const processed = new Set();
|
|
214
|
-
const processDoc = (doc, depth) => {
|
|
215
|
-
if (processed.has(doc.id))
|
|
216
|
-
return;
|
|
217
|
-
processed.add(doc.id);
|
|
218
|
-
const children = documents.filter((d) => d.parentId === doc.id);
|
|
219
|
-
const hasChildren = children.length > 0;
|
|
220
|
-
items.push({ ...doc, depth, hasChildren });
|
|
221
|
-
// If expanded, process children
|
|
222
|
-
if (hasChildren && expandedFolders.has(doc.id)) {
|
|
223
|
-
children
|
|
224
|
-
.sort((a, b) => a.order - b.order)
|
|
225
|
-
.forEach((child) => processDoc(child, depth + 1));
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
// Process root documents
|
|
229
|
-
documents
|
|
230
|
-
.filter((d) => !d.parentId)
|
|
231
|
-
.sort((a, b) => a.order - b.order)
|
|
232
|
-
.forEach((doc) => processDoc(doc, 0));
|
|
233
|
-
return items;
|
|
234
|
-
}, [documents, expandedFolders]);
|
|
235
|
-
const getChildren = useCallback((parentId) => documents.filter((d) => d.parentId === parentId), [documents]);
|
|
236
|
-
const toggleFolder = useCallback((folderId) => {
|
|
237
|
-
setExpandedFolders((prev) => {
|
|
238
|
-
const newExpanded = new Set(prev);
|
|
239
|
-
if (newExpanded.has(folderId)) {
|
|
240
|
-
newExpanded.delete(folderId);
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
newExpanded.add(folderId);
|
|
244
|
-
}
|
|
245
|
-
return newExpanded;
|
|
246
|
-
});
|
|
247
|
-
}, []);
|
|
248
|
-
// Navigate with full path
|
|
249
|
-
const handleNavigate = useCallback((docId) => {
|
|
250
|
-
if (!onNavigate)
|
|
251
|
-
return;
|
|
252
|
-
if (docId === 'new') {
|
|
253
|
-
onNavigate(`${basePath}/new`);
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
const path = buildDocumentPath(docId, documents, basePath);
|
|
257
|
-
onNavigate(path);
|
|
258
|
-
}, [onNavigate, documents, basePath]);
|
|
259
|
-
const sensors = useSensors(useSensor(PointerSensor, {
|
|
260
|
-
activationConstraint: {
|
|
261
|
-
distance: 5,
|
|
262
|
-
},
|
|
263
|
-
}), useSensor(KeyboardSensor, {
|
|
264
|
-
coordinateGetter: sortableKeyboardCoordinates,
|
|
265
|
-
}));
|
|
266
|
-
const handleDragStart = useCallback((event) => {
|
|
267
|
-
setActiveId(event.active.id);
|
|
268
|
-
}, []);
|
|
269
|
-
const handleDragOver = useCallback((event) => {
|
|
270
|
-
const { over } = event;
|
|
271
|
-
if (!over)
|
|
272
|
-
return;
|
|
273
|
-
const overId = over.id;
|
|
274
|
-
// Auto-expand folder when hovering over it
|
|
275
|
-
const overDoc = documents.find((d) => d.id === overId);
|
|
276
|
-
if (overDoc) {
|
|
277
|
-
const children = getChildren(overId);
|
|
278
|
-
if (children.length > 0 && !expandedFolders.has(overId)) {
|
|
279
|
-
toggleFolder(overId);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}, [documents, expandedFolders, getChildren, toggleFolder]);
|
|
283
|
-
const handleDragEnd = useCallback((event) => {
|
|
284
|
-
const { active, over } = event;
|
|
285
|
-
setActiveId(null);
|
|
286
|
-
if (!over)
|
|
287
|
-
return;
|
|
288
|
-
const draggedId = active.id;
|
|
289
|
-
const overId = over.id;
|
|
290
|
-
if (draggedId === overId)
|
|
291
|
-
return;
|
|
292
|
-
const activeDoc = documents.find((d) => d.id === draggedId);
|
|
293
|
-
const overDoc = documents.find((d) => d.id === overId);
|
|
294
|
-
if (!activeDoc || !overDoc)
|
|
295
|
-
return;
|
|
296
|
-
// Calculate new parent and order
|
|
297
|
-
let newParentId = null;
|
|
298
|
-
let newOrder = 0;
|
|
299
|
-
// Determine if we're dropping before, after, or inside the target
|
|
300
|
-
const activeIndex = flattenedTree.findIndex((item) => item.id === draggedId);
|
|
301
|
-
const overIndex = flattenedTree.findIndex((item) => item.id === overId);
|
|
302
|
-
if (activeIndex === -1 || overIndex === -1)
|
|
303
|
-
return;
|
|
304
|
-
if (activeIndex < overIndex) {
|
|
305
|
-
// Dropping after the target
|
|
306
|
-
newParentId = overDoc.parentId || null;
|
|
307
|
-
newOrder = overDoc.order + 5;
|
|
308
|
-
}
|
|
309
|
-
else {
|
|
310
|
-
// Dropping before the target
|
|
311
|
-
newParentId = overDoc.parentId || null;
|
|
312
|
-
newOrder = overDoc.order - 5;
|
|
313
|
-
}
|
|
314
|
-
// Check if dropping on a folder (to make it a child)
|
|
315
|
-
const overHasChildren = getChildren(overId).length > 0;
|
|
316
|
-
if (overHasChildren && activeIndex > overIndex) {
|
|
317
|
-
// If dropping after a folder, make it the first child
|
|
318
|
-
newParentId = overId;
|
|
319
|
-
newOrder = 0;
|
|
320
|
-
}
|
|
321
|
-
// Prevent dropping a parent into its own child
|
|
322
|
-
const isChildOfActive = (docId) => {
|
|
323
|
-
const doc = documents.find((d) => d.id === docId);
|
|
324
|
-
if (!doc)
|
|
325
|
-
return false;
|
|
326
|
-
if (doc.parentId === draggedId)
|
|
327
|
-
return true;
|
|
328
|
-
if (doc.parentId)
|
|
329
|
-
return isChildOfActive(doc.parentId);
|
|
330
|
-
return false;
|
|
331
|
-
};
|
|
332
|
-
if (isChildOfActive(overId)) {
|
|
333
|
-
console.log('Cannot drop a parent into its own child');
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
// Execute the reorder
|
|
337
|
-
reorderMutation.mutate({
|
|
338
|
-
id: draggedId,
|
|
339
|
-
parentId: newParentId,
|
|
340
|
-
order: newOrder,
|
|
341
|
-
});
|
|
342
|
-
}, [documents, flattenedTree, getChildren, reorderMutation]);
|
|
343
|
-
const dropAnimation = {
|
|
344
|
-
sideEffects: defaultDropAnimationSideEffects({
|
|
345
|
-
styles: {
|
|
346
|
-
active: {
|
|
347
|
-
opacity: '0.5',
|
|
348
|
-
},
|
|
349
|
-
},
|
|
350
|
-
}),
|
|
351
|
-
};
|
|
352
|
-
const activeDoc = useMemo(() => {
|
|
353
|
-
if (!activeId)
|
|
354
|
-
return null;
|
|
355
|
-
const doc = documents.find((d) => d.id === activeId);
|
|
356
|
-
if (!doc)
|
|
357
|
-
return null;
|
|
358
|
-
const children = getChildren(doc.id);
|
|
359
|
-
return { ...doc, depth: 0, hasChildren: children.length > 0 };
|
|
360
|
-
}, [activeId, documents, getChildren]);
|
|
361
|
-
return (_jsxs("div", { className: "flex h-screen w-full", children: [_jsxs("aside", { className: [
|
|
362
|
-
'border-r border-border flex flex-col transition-all duration-200 ease-in-out overflow-hidden',
|
|
363
|
-
isSidebarOpen ? 'w-64 opacity-100' : 'w-0 opacity-0',
|
|
364
|
-
].join(' '), children: [_jsxs("div", { className: "p-4", children: [_jsxs("div", { className: "flex items-center justify-between mb-3", children: [_jsx("h2", { className: "font-semibold text-sm text-muted-foreground", children: "Documents" }), _jsx("button", { className: "p-2 hover:bg-primary rounded-md transition-colors cursor-pointer", onClick: () => handleNavigate('new'), children: _jsx(Plus, { className: "h-4 w-4" }) })] }), _jsxs("div", { className: "relative", children: [_jsx(Search, { className: "absolute left-2 top-2.5 h-4 w-4 text-gray-400" }), _jsx("input", { type: "text", placeholder: "Search docs...", value: searchQuery, onChange: (e) => setSearchQuery(e.target.value), className: "w-full pl-8 pr-3 py-2 text-sm border border-gray-300 dark:border-gray-700 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" })] })] }), _jsxs("div", { className: "flex-1 overflow-y-auto p-2 space-y-1", children: [_jsxs(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragStart: handleDragStart, onDragOver: handleDragOver, onDragEnd: handleDragEnd, children: [_jsx(SortableContext, { items: flattenedTree.map((item) => item.id), strategy: verticalListSortingStrategy, children: flattenedTree.map((doc) => (_jsx(SortableTreeItem, { doc: doc, isExpanded: expandedFolders.has(doc.id), isCurrent: doc.id === resolvedCurrentDocId, onToggle: toggleFolder, onNavigate: handleNavigate }, doc.id))) }), _jsx(DragOverlay, { dropAnimation: dropAnimation, children: activeDoc ? _jsx(DragOverlayItem, { doc: activeDoc }) : null })] }), documents.length === 0 && (_jsx("div", { className: "text-sm text-gray-500 text-center py-4", children: "No documents yet" }))] })] }), _jsxs("main", { className: "flex-1 flex flex-col min-w-0 overflow-hidden", children: [_jsxs("header", { className: "h-16 border-b border-border flex items-center justify-between px-6 shrink-0", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("button", { onClick: () => setIsSidebarOpen(!isSidebarOpen), className: "p-2 hover:bg-primary rounded-md transition-colors text-muted-foreground", title: isSidebarOpen ? 'Close sidebar' : 'Open sidebar', children: isSidebarOpen ? (_jsx(PanelLeftCloseIcon, { className: "h-6 w-6" })) : (_jsx(PanelLeftOpenIcon, { className: "h-6 w-6" })) }), _jsx(Breadcrumbs, { docId: resolvedCurrentDocId ?? undefined, documents: documents.map((d) => ({
|
|
365
|
-
id: d.id,
|
|
366
|
-
title: d.title,
|
|
367
|
-
slug: d.slug,
|
|
368
|
-
emoji: d.emoji ?? undefined,
|
|
369
|
-
parentId: d.parentId,
|
|
370
|
-
})), onNavigate: onNavigate, homeLabel: "Documents" })] }), _jsxs("div", { className: "flex items-center gap-4 py-2", children: [_jsxs("div", { ref: searchInputRef, className: "relative w-64", children: [_jsx(Search, { className: "absolute left-2 top-2.5 h-4 w-4 z-10" }), _jsx("input", { type: "text", placeholder: "Search documentation...", className: "w-full pl-8 pr-3 py-2 text-sm border border-border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent", value: headerSearchQuery, onChange: (e) => {
|
|
371
|
-
setHeaderSearchQuery(e.target.value);
|
|
372
|
-
setShowSearchResults(e.target.value.length > 0);
|
|
373
|
-
}, onFocus: () => {
|
|
374
|
-
if (headerSearchQuery.length > 0) {
|
|
375
|
-
setShowSearchResults(true);
|
|
376
|
-
}
|
|
377
|
-
} }), showSearchResults && headerSearchQuery.length > 0 && (_jsx("div", { className: "absolute top-full left-0 right-0 mt-1 border border-gray-200 rounded-md shadow-lg max-h-80 overflow-y-auto z-50", children: searchResults.length === 0 ? (_jsxs("div", { className: "px-4 py-3 text-sm text-gray-500", children: ["No results found for \"", headerSearchQuery, "\""] })) : (_jsx("div", { className: "py-1", children: searchResults.map((doc) => {
|
|
378
|
-
const breadcrumb = doc.parentId
|
|
379
|
-
? buildBreadcrumb(doc, documents)
|
|
380
|
-
: null;
|
|
381
|
-
return (_jsx("button", { onClick: () => {
|
|
382
|
-
handleNavigate(doc.id);
|
|
383
|
-
setHeaderSearchQuery('');
|
|
384
|
-
setShowSearchResults(false);
|
|
385
|
-
}, className: "w-full px-3 py-2 text-left hover:bg-gray-100 transition-colors", children: _jsxs("div", { className: "flex items-start gap-2", children: [_jsx("div", { className: "shrink-0 mt-0.5", children: doc.emoji ? (_jsx("span", { className: "text-base", children: doc.emoji })) : (_jsx(FileText, { className: "h-4 w-4 text-gray-400" })) }), _jsxs("div", { className: "flex-1 min-w-0", children: [_jsx("div", { className: "font-medium text-sm text-gray-900 truncate", children: doc.title }), breadcrumb && (_jsx("div", { className: "text-xs text-gray-500 truncate", children: breadcrumb }))] })] }) }, doc.id));
|
|
386
|
-
}) })) }))] }), _jsxs("button", { onClick: () => handleNavigate('new'), className: "px-4 py-2 bg-secondary text-white text-sm rounded-md hover:bg-gray-800 flex items-center gap-2 transition-colors", children: [_jsx(Plus, { className: "h-4 w-4" }), "Create"] }), userAvatar] })] }), _jsx("div", { className: "flex-1 overflow-auto p-6", children: children })] })] }));
|
|
387
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=DocumentProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentProvider.d.ts","sourceRoot":"","sources":["../../../src/client/providers/DocumentProvider.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|