@aprovan/patchwork-editor 0.1.2-dev.03aaf5b → 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.
@@ -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(originalProject.entry);
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(originalProject.entry);
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 (
@@ -1,5 +1,7 @@
1
- export { CodeBlockExtension } from './CodeBlockExtension';
2
- export { CodePreview } from './CodePreview';
3
- export { MarkdownEditor } from './MarkdownEditor';
4
- export { ServicesInspector, type ServiceInfo } from './ServicesInspector';
5
- export * from './edit';
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 './components';
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 './components/edit';
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 './lib';
93
+ } from "./lib";