@powerhousedao/codegen 0.49.5-dev.0 → 0.49.5-dev.1
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/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveExplorer.esm.t +11 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/EditorContainer.esm.t +21 -26
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/editor.esm.t +3 -9
- package/package.json +2 -2
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/document-models.esm.t +0 -44
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/hooks/useDocumentModels.esm.t +0 -41
|
@@ -144,6 +144,14 @@ export function DriveExplorer({
|
|
|
144
144
|
? files.find((file) => file.id === activeDocumentId)
|
|
145
145
|
: undefined;
|
|
146
146
|
|
|
147
|
+
const documentModelModule = activeDocument
|
|
148
|
+
? context.getDocumentModelModule(activeDocument.documentType)
|
|
149
|
+
: null;
|
|
150
|
+
|
|
151
|
+
const editorModule = activeDocument
|
|
152
|
+
? context.getEditor(activeDocument.documentType)
|
|
153
|
+
: null;
|
|
154
|
+
|
|
147
155
|
return (
|
|
148
156
|
<div className="flex h-full">
|
|
149
157
|
{/* Sidebar */}
|
|
@@ -158,7 +166,7 @@ export function DriveExplorer({
|
|
|
158
166
|
|
|
159
167
|
{/* Main Content */}
|
|
160
168
|
<div className="flex-1 p-4 overflow-y-auto">
|
|
161
|
-
{activeDocument ? (
|
|
169
|
+
{activeDocument && documentModelModule && editorModule ? (
|
|
162
170
|
<EditorContainer
|
|
163
171
|
context={{
|
|
164
172
|
...context,
|
|
@@ -169,6 +177,8 @@ export function DriveExplorer({
|
|
|
169
177
|
driveId={driveId}
|
|
170
178
|
onClose={handleEditorClose}
|
|
171
179
|
title={activeDocument.name}
|
|
180
|
+
documentModelModule={documentModelModule}
|
|
181
|
+
editorModule={editorModule}
|
|
172
182
|
/>
|
|
173
183
|
) : (
|
|
174
184
|
<>
|
|
@@ -6,12 +6,13 @@ import {
|
|
|
6
6
|
useDriveContext,
|
|
7
7
|
exportDocument,
|
|
8
8
|
type User,
|
|
9
|
+
type DriveEditorContext,
|
|
9
10
|
} from "@powerhousedao/reactor-browser";
|
|
10
11
|
import {
|
|
11
|
-
documentModelDocumentModelModule,
|
|
12
|
-
type EditorModule,
|
|
13
|
-
type DocumentModelModule,
|
|
14
12
|
type EditorContext,
|
|
13
|
+
type DocumentModelModule,
|
|
14
|
+
type EditorModule,
|
|
15
|
+
type EditorProps,
|
|
15
16
|
type PHDocument,
|
|
16
17
|
} from "document-model";
|
|
17
18
|
import {
|
|
@@ -21,8 +22,7 @@ import {
|
|
|
21
22
|
type TimelineItem,
|
|
22
23
|
} from "@powerhousedao/design-system";
|
|
23
24
|
import { useTimelineItems, getRevisionFromDate } from "@powerhousedao/common";
|
|
24
|
-
import { useState, Suspense, type FC, useCallback
|
|
25
|
-
import { useDocumentModel, useDocumentEditorModule } from "../hooks/useDocumentModels.js";
|
|
25
|
+
import { useState, Suspense, type FC, useCallback } from "react";
|
|
26
26
|
|
|
27
27
|
export interface EditorContainerProps {
|
|
28
28
|
driveId: string;
|
|
@@ -30,11 +30,22 @@ export interface EditorContainerProps {
|
|
|
30
30
|
documentType: string;
|
|
31
31
|
onClose: () => void;
|
|
32
32
|
title: string;
|
|
33
|
-
context: EditorContext
|
|
33
|
+
context: Omit<DriveEditorContext, "getDocumentRevision"> & Pick<EditorContext, "getDocumentRevision">;
|
|
34
|
+
documentModelModule: DocumentModelModule<PHDocument>;
|
|
35
|
+
editorModule: EditorModule;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
|
|
37
|
-
const {
|
|
39
|
+
const {
|
|
40
|
+
title,
|
|
41
|
+
driveId,
|
|
42
|
+
context,
|
|
43
|
+
onClose,
|
|
44
|
+
documentId,
|
|
45
|
+
documentType,
|
|
46
|
+
editorModule,
|
|
47
|
+
documentModelModule,
|
|
48
|
+
} = props;
|
|
38
49
|
|
|
39
50
|
const [selectedTimelineItem, setSelectedTimelineItem] = useState<TimelineItem | null>(null);
|
|
40
51
|
const [showRevisionHistory, setShowRevisionHistory] = useState(false);
|
|
@@ -43,12 +54,6 @@ export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
|
|
|
43
54
|
|
|
44
55
|
const user = context.user as User | undefined;
|
|
45
56
|
|
|
46
|
-
const documentModelModule = useDocumentModel(
|
|
47
|
-
documentType,
|
|
48
|
-
) as DocumentModelModule<PHDocument>;
|
|
49
|
-
|
|
50
|
-
const { editorModule, isLoading } = useDocumentEditorModule(documentType);
|
|
51
|
-
|
|
52
57
|
const { dispatch, error, document } = useDocumentEditorProps({
|
|
53
58
|
documentId,
|
|
54
59
|
documentType,
|
|
@@ -70,19 +75,9 @@ export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
|
|
|
70
75
|
</div>
|
|
71
76
|
);
|
|
72
77
|
|
|
73
|
-
if (!document
|
|
74
|
-
|
|
75
|
-
if (!editorModule) {
|
|
76
|
-
console.error("No editor found for document type:", documentType);
|
|
77
|
-
return (
|
|
78
|
-
<div className="flex-1">
|
|
79
|
-
No editor found for document type: {documentType}
|
|
80
|
-
</div>
|
|
81
|
-
);
|
|
82
|
-
}
|
|
78
|
+
if (!document) return loadingContent;
|
|
83
79
|
|
|
84
|
-
const
|
|
85
|
-
const EditorComponent = moduleWithComponent.Component;
|
|
80
|
+
const EditorComponent = editorModule.Component as FC<EditorProps<PHDocument>>;
|
|
86
81
|
|
|
87
82
|
return showRevisionHistory ? (
|
|
88
83
|
<RevisionHistory
|
|
@@ -101,7 +96,7 @@ export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
|
|
|
101
96
|
onShowRevisionHistory={() => setShowRevisionHistory(true)}
|
|
102
97
|
onSwitchboardLinkClick={() => {}}
|
|
103
98
|
title={title}
|
|
104
|
-
timelineButtonVisible={
|
|
99
|
+
timelineButtonVisible={editorModule.config.timelineEnabled}
|
|
105
100
|
timelineItems={timelineItems.data}
|
|
106
101
|
onTimelineItemClick={setSelectedTimelineItem}
|
|
107
102
|
/>
|
|
@@ -67,18 +67,12 @@ export function BaseEditor(props: IProps) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export default function Editor(props: IProps) {
|
|
70
|
-
const baseEditor = props.context.analyticsStore ? (
|
|
71
|
-
<AnalyticsProvider store={props.context.analyticsStore}>
|
|
72
|
-
<BaseEditor {...props} />
|
|
73
|
-
</AnalyticsProvider>
|
|
74
|
-
) : (
|
|
75
|
-
<BaseEditor {...props} />
|
|
76
|
-
);
|
|
77
|
-
|
|
78
70
|
return (
|
|
79
71
|
<DriveContextProvider value={props.context}>
|
|
80
72
|
<WagmiContext>
|
|
81
|
-
{
|
|
73
|
+
<AnalyticsProvider databaseName={props.context.analyticsDatabaseName}>
|
|
74
|
+
<BaseEditor {...props} />
|
|
75
|
+
</AnalyticsProvider>
|
|
82
76
|
</WagmiContext>
|
|
83
77
|
</DriveContextProvider>
|
|
84
78
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/codegen",
|
|
3
|
-
"version": "0.49.5-dev.
|
|
3
|
+
"version": "0.49.5-dev.1",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"execa": "^8.0.1",
|
|
27
27
|
"hygen": "^6.2.11",
|
|
28
28
|
"prettier": "^3.4.2",
|
|
29
|
-
"@powerhousedao/config": "1.27.0-dev.9",
|
|
30
29
|
"@powerhousedao/scalars": "1.33.1-dev.7",
|
|
30
|
+
"@powerhousedao/config": "1.27.0-dev.9",
|
|
31
31
|
"document-model": "2.28.1-dev.9"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/document-models.esm.t
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/document-models.ts"
|
|
3
|
-
unless_exists: true
|
|
4
|
-
---
|
|
5
|
-
import { documentModelDocumentModelModule, type DocumentModelModule } from "document-model";
|
|
6
|
-
// Replace with your document model (you can support multiple document models)
|
|
7
|
-
// import { ToDo } from "../../document-models/index.js";
|
|
8
|
-
|
|
9
|
-
export const createLazyModuleLoader = <T,>(loader: () => Promise<T>) => {
|
|
10
|
-
let modulePromise: Promise<T> | null = null;
|
|
11
|
-
let loadedModule: T | null = null;
|
|
12
|
-
|
|
13
|
-
return () => {
|
|
14
|
-
if (loadedModule) return Promise.resolve(loadedModule);
|
|
15
|
-
if (!modulePromise) {
|
|
16
|
-
modulePromise = loader().then(module => {
|
|
17
|
-
loadedModule = module;
|
|
18
|
-
return module;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
return modulePromise;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const documentModelsMap: Record<string, DocumentModelModule<any>> = {
|
|
26
|
-
// Replace with your document model (you can support multiple document models)
|
|
27
|
-
// [ToDo.documentModel.id]: ToDo,
|
|
28
|
-
[documentModelDocumentModelModule.documentModel.id]:
|
|
29
|
-
documentModelDocumentModelModule,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const documentEditorMap = {
|
|
33
|
-
// Replace with your document model editor (you can support multiple document models editors)
|
|
34
|
-
// [ToDo.documentModel.id]: createLazyModuleLoader(() =>
|
|
35
|
-
// import("../to-do-list/index.js").then(m => m.default)
|
|
36
|
-
// ),
|
|
37
|
-
[documentModelDocumentModelModule.documentModel.id]: createLazyModuleLoader(() =>
|
|
38
|
-
import("@powerhousedao/builder-tools/style.css").then(() =>
|
|
39
|
-
import("@powerhousedao/builder-tools/document-model-editor").then(
|
|
40
|
-
m => m.documentModelEditorModule
|
|
41
|
-
)
|
|
42
|
-
)
|
|
43
|
-
),
|
|
44
|
-
} as const;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/hooks/useDocumentModels.ts"
|
|
3
|
-
unless_exists: true
|
|
4
|
-
---
|
|
5
|
-
import { useState, useEffect } from 'react';
|
|
6
|
-
import { documentModelsMap, documentEditorMap } from "../document-models.js";
|
|
7
|
-
import { type DocumentModelModule } from "document-model";
|
|
8
|
-
|
|
9
|
-
export function useDocumentModel(documentType: string): DocumentModelModule<any> {
|
|
10
|
-
return documentModelsMap[documentType];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function useDocumentEditorModule(documentType: string) {
|
|
14
|
-
const [editorModule, setEditorModule] = useState<unknown>(null);
|
|
15
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
16
|
-
const [error, setError] = useState<Error | null>(null);
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
const editorLoader = documentEditorMap[documentType];
|
|
20
|
-
|
|
21
|
-
if (editorLoader && !editorModule) {
|
|
22
|
-
setIsLoading(true);
|
|
23
|
-
|
|
24
|
-
editorLoader()
|
|
25
|
-
.then(module => {
|
|
26
|
-
setEditorModule(module);
|
|
27
|
-
setIsLoading(false);
|
|
28
|
-
})
|
|
29
|
-
.catch(err => {
|
|
30
|
-
setError(err instanceof Error ? err : new Error('Failed to load editor module'));
|
|
31
|
-
setIsLoading(false);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}, [documentType, editorModule]);
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
editorModule,
|
|
38
|
-
isLoading,
|
|
39
|
-
error
|
|
40
|
-
};
|
|
41
|
-
}
|