@aprovan/patchwork-editor 0.1.1-dev.6bd527d → 0.1.2-dev.ba8f277
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/.turbo/turbo-build.log +3 -3
- package/dist/components/CodePreview.d.ts +10 -1
- package/dist/components/MarkdownPreview.d.ts +8 -0
- package/dist/components/SaveStatusButton.d.ts +9 -0
- package/dist/components/ServicesInspector.d.ts +3 -4
- package/dist/components/WidgetPreview.d.ts +8 -0
- package/dist/components/edit/EditModal.d.ts +2 -1
- package/dist/components/edit/FileTree.d.ts +22 -3
- package/dist/components/edit/fileTypes.d.ts +2 -0
- package/dist/components/edit/useEditSession.d.ts +1 -0
- package/dist/components/index.d.ts +7 -5
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1030 -197
- package/package.json +4 -3
- package/src/components/CodePreview.tsx +118 -160
- package/src/components/MarkdownPreview.tsx +147 -0
- package/src/components/SaveStatusButton.tsx +55 -0
- package/src/components/ServicesInspector.tsx +101 -37
- package/src/components/WidgetPreview.tsx +102 -0
- package/src/components/edit/CodeBlockView.tsx +135 -19
- package/src/components/edit/EditModal.tsx +86 -28
- package/src/components/edit/FileTree.tsx +524 -29
- package/src/components/edit/MediaPreview.tsx +23 -5
- package/src/components/edit/api.ts +6 -1
- package/src/components/edit/fileTypes.ts +8 -0
- package/src/components/edit/useEditSession.ts +13 -3
- package/src/components/index.ts +7 -5
- package/src/index.ts +10 -6
|
@@ -14,10 +14,25 @@ function formatFileSize(bytes: number): string {
|
|
|
14
14
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
function isUrl(content: string): boolean {
|
|
18
|
+
// Check if content is a URL (absolute or relative path)
|
|
19
|
+
return content.startsWith('/') ||
|
|
20
|
+
content.startsWith('http://') ||
|
|
21
|
+
content.startsWith('https://') ||
|
|
22
|
+
content.startsWith('./') ||
|
|
23
|
+
content.startsWith('../');
|
|
24
|
+
}
|
|
25
|
+
|
|
17
26
|
function getDataUrl(content: string, mimeType: string): string {
|
|
27
|
+
// If already a data URL, return as-is
|
|
18
28
|
if (content.startsWith('data:')) {
|
|
19
29
|
return content;
|
|
20
30
|
}
|
|
31
|
+
// If content is a URL path, return it directly (browser can fetch it)
|
|
32
|
+
if (isUrl(content)) {
|
|
33
|
+
return content;
|
|
34
|
+
}
|
|
35
|
+
// Otherwise, treat as raw base64 data and construct a data URL
|
|
21
36
|
return `data:${mimeType};base64,${content}`;
|
|
22
37
|
}
|
|
23
38
|
|
|
@@ -28,10 +43,13 @@ export function MediaPreview({ content, mimeType, fileName }: MediaPreviewProps)
|
|
|
28
43
|
const dataUrl = getDataUrl(content, mimeType);
|
|
29
44
|
const isImage = isImageFile(fileName);
|
|
30
45
|
const isVideo = isVideoFile(fileName);
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
// For URLs, we can't estimate file size from the string
|
|
47
|
+
const isUrlContent = isUrl(content);
|
|
48
|
+
const estimatedBytes = isUrlContent
|
|
49
|
+
? null
|
|
50
|
+
: content.startsWith('data:')
|
|
51
|
+
? Math.floor((content.split(',')[1]?.length ?? 0) * 0.75)
|
|
52
|
+
: Math.floor(content.length * 0.75);
|
|
35
53
|
|
|
36
54
|
useEffect(() => {
|
|
37
55
|
setDimensions(null);
|
|
@@ -97,7 +115,7 @@ export function MediaPreview({ content, mimeType, fileName }: MediaPreviewProps)
|
|
|
97
115
|
{dimensions && (
|
|
98
116
|
<span>{dimensions.width} × {dimensions.height} px</span>
|
|
99
117
|
)}
|
|
100
|
-
<span>{formatFileSize(estimatedBytes)}</span>
|
|
118
|
+
{estimatedBytes !== null && <span>{formatFileSize(estimatedBytes)}</span>}
|
|
101
119
|
<span className="text-muted-foreground/60">{mimeType}</span>
|
|
102
120
|
</div>
|
|
103
121
|
</div>
|
|
@@ -27,7 +27,12 @@ export async function sendEditRequest(
|
|
|
27
27
|
const text = await streamResponse(response, onProgress);
|
|
28
28
|
|
|
29
29
|
if (!hasDiffBlocks(text)) {
|
|
30
|
-
|
|
30
|
+
// No diffs — return the original code unchanged with the response as summary
|
|
31
|
+
return {
|
|
32
|
+
newCode: request.code,
|
|
33
|
+
summary: text.trim(),
|
|
34
|
+
progressNotes: [],
|
|
35
|
+
};
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
const parsed = parseEditResponse(text);
|
|
@@ -104,6 +104,14 @@ export function isTextFile(path: string): boolean {
|
|
|
104
104
|
return TEXT_EXTENSIONS.includes(getExtension(path));
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
export function isMarkdownFile(path: string): boolean {
|
|
108
|
+
return getExtension(path) === '.md';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function isPreviewable(path: string): boolean {
|
|
112
|
+
return isCompilable(path) || isMarkdownFile(path);
|
|
113
|
+
}
|
|
114
|
+
|
|
107
115
|
export function getLanguageFromExt(path: string): string | null {
|
|
108
116
|
const ext = getExtension(path);
|
|
109
117
|
return EXTENSION_TO_LANGUAGE[ext] ?? null;
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
export interface UseEditSessionOptions {
|
|
13
13
|
originalCode?: string;
|
|
14
14
|
originalProject?: VirtualProject;
|
|
15
|
+
initialActiveFile?: string;
|
|
15
16
|
compile?: CompileFn;
|
|
16
17
|
apiEndpoint?: string;
|
|
17
18
|
}
|
|
@@ -29,6 +30,7 @@ export function useEditSession(
|
|
|
29
30
|
const {
|
|
30
31
|
originalCode,
|
|
31
32
|
originalProject: providedProject,
|
|
33
|
+
initialActiveFile,
|
|
32
34
|
compile,
|
|
33
35
|
apiEndpoint,
|
|
34
36
|
} = options;
|
|
@@ -49,7 +51,11 @@ export function useEditSession(
|
|
|
49
51
|
const lastSyncedProjectRef = useRef<VirtualProject>(originalProject);
|
|
50
52
|
|
|
51
53
|
const [project, setProject] = useState<VirtualProject>(originalProject);
|
|
52
|
-
const [activeFile, setActiveFile] = useState(
|
|
54
|
+
const [activeFile, setActiveFile] = useState(
|
|
55
|
+
initialActiveFile && originalProject.files.has(initialActiveFile)
|
|
56
|
+
? initialActiveFile
|
|
57
|
+
: originalProject.entry,
|
|
58
|
+
);
|
|
53
59
|
const [history, setHistory] = useState<EditHistoryEntry[]>([]);
|
|
54
60
|
const [isApplying, setIsApplying] = useState(false);
|
|
55
61
|
const [error, setError] = useState<string | null>(null);
|
|
@@ -61,12 +67,16 @@ export function useEditSession(
|
|
|
61
67
|
if (originalProject !== lastSyncedProjectRef.current) {
|
|
62
68
|
lastSyncedProjectRef.current = originalProject;
|
|
63
69
|
setProject(originalProject);
|
|
64
|
-
setActiveFile(
|
|
70
|
+
setActiveFile(
|
|
71
|
+
initialActiveFile && originalProject.files.has(initialActiveFile)
|
|
72
|
+
? initialActiveFile
|
|
73
|
+
: originalProject.entry,
|
|
74
|
+
);
|
|
65
75
|
setHistory([]);
|
|
66
76
|
setError(null);
|
|
67
77
|
setStreamingNotes([]);
|
|
68
78
|
}
|
|
69
|
-
}, [originalProject]);
|
|
79
|
+
}, [originalProject, initialActiveFile]);
|
|
70
80
|
|
|
71
81
|
const performEdit = useCallback(
|
|
72
82
|
async (
|
package/src/components/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export { CodeBlockExtension } from
|
|
2
|
-
export { CodePreview } from
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
1
|
+
export { CodeBlockExtension } from "./CodeBlockExtension";
|
|
2
|
+
export { CodePreview } from "./CodePreview";
|
|
3
|
+
export { WidgetPreview } from "./WidgetPreview";
|
|
4
|
+
export { MarkdownEditor } from "./MarkdownEditor";
|
|
5
|
+
export { MarkdownPreview } from "./MarkdownPreview";
|
|
6
|
+
export { ServicesInspector, type ServiceInfo } from "./ServicesInspector";
|
|
7
|
+
export * from "./edit";
|
package/src/index.ts
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
export {
|
|
3
3
|
CodeBlockExtension,
|
|
4
4
|
CodePreview,
|
|
5
|
+
WidgetPreview,
|
|
5
6
|
MarkdownEditor,
|
|
7
|
+
MarkdownPreview,
|
|
6
8
|
ServicesInspector,
|
|
7
9
|
type ServiceInfo,
|
|
8
|
-
} from
|
|
10
|
+
} from "./components";
|
|
9
11
|
|
|
10
12
|
// Edit components
|
|
11
13
|
export {
|
|
@@ -40,11 +42,13 @@ export {
|
|
|
40
42
|
isCompilable,
|
|
41
43
|
isMediaFile,
|
|
42
44
|
isTextFile,
|
|
45
|
+
isMarkdownFile,
|
|
46
|
+
isPreviewable,
|
|
43
47
|
isImageFile,
|
|
44
48
|
isVideoFile,
|
|
45
49
|
getLanguageFromExt,
|
|
46
50
|
getMimeType,
|
|
47
|
-
} from
|
|
51
|
+
} from "./components/edit";
|
|
48
52
|
|
|
49
53
|
// Lib utilities
|
|
50
54
|
export {
|
|
@@ -58,7 +62,7 @@ export {
|
|
|
58
62
|
type CodePart,
|
|
59
63
|
type ParsedPart,
|
|
60
64
|
type ExtractOptions,
|
|
61
|
-
|
|
65
|
+
|
|
62
66
|
// Diff utilities
|
|
63
67
|
parseCodeBlockAttributes,
|
|
64
68
|
parseCodeBlocks,
|
|
@@ -74,7 +78,7 @@ export {
|
|
|
74
78
|
type CodeBlock,
|
|
75
79
|
type DiffBlock,
|
|
76
80
|
type ParsedEditResponse,
|
|
77
|
-
|
|
81
|
+
|
|
78
82
|
// VFS utilities
|
|
79
83
|
getVFSConfig,
|
|
80
84
|
getVFSStore,
|
|
@@ -83,7 +87,7 @@ export {
|
|
|
83
87
|
listProjects,
|
|
84
88
|
saveFile,
|
|
85
89
|
isVFSAvailable,
|
|
86
|
-
|
|
90
|
+
|
|
87
91
|
// General utilities
|
|
88
92
|
cn,
|
|
89
|
-
} from
|
|
93
|
+
} from "./lib";
|