@powerhousedao/codegen 0.49.3-dev.1 → 0.49.3-dev.2

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.
@@ -8,10 +8,10 @@ import {
8
8
  type User,
9
9
  } from "@powerhousedao/reactor-browser";
10
10
  import {
11
- documentModelDocumentModelModule,
11
+ documentModelDocumentModelModule,
12
+ type EditorModule,
12
13
  type DocumentModelModule,
13
14
  type EditorContext,
14
- type EditorProps,
15
15
  type PHDocument,
16
16
  } from "document-model";
17
17
  import {
@@ -22,6 +22,7 @@ import {
22
22
  } from "@powerhousedao/design-system";
23
23
  import { useTimelineItems, getRevisionFromDate } from "@powerhousedao/common";
24
24
  import { useState, Suspense, type FC, useCallback, lazy } from "react";
25
+ import { useDocumentModel, useDocumentEditorModule } from "../hooks/useDocumentModels.js";
25
26
 
26
27
  export interface EditorContainerProps {
27
28
  driveId: string;
@@ -32,28 +33,6 @@ export interface EditorContainerProps {
32
33
  context: EditorContext;
33
34
  }
34
35
 
35
- const documentModelsMap = {
36
- [documentModelDocumentModelModule.documentModel.id]: documentModelDocumentModelModule,
37
- };
38
-
39
- const documentEditorMap = {
40
- [documentModelDocumentModelModule.documentModel.id]: lazy(() =>
41
- import('@powerhousedao/builder-tools/style.css').then(() =>
42
- import("@powerhousedao/builder-tools/document-model-editor").then((m) => ({
43
- default: m.documentModelEditorModule.Component,
44
- }))
45
- )
46
- ),
47
- } as const;
48
-
49
- function getDocumentModel(documentType: string) {
50
- return documentModelsMap[documentType];
51
- }
52
-
53
- function getDocumentEditor(documentType: string) {
54
- return documentEditorMap[documentType];
55
- }
56
-
57
36
  export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
58
37
  const { driveId, documentId, documentType, onClose, title, context } = props;
59
38
 
@@ -64,10 +43,12 @@ export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
64
43
 
65
44
  const user = context.user as User | undefined;
66
45
 
67
- const documentModelModule = getDocumentModel(
46
+ const documentModelModule = useDocumentModel(
68
47
  documentType,
69
48
  ) as DocumentModelModule<PHDocument>;
70
49
 
50
+ const { editorModule, isLoading } = useDocumentEditorModule(documentType);
51
+
71
52
  const { dispatch, error, document } = useDocumentEditorProps({
72
53
  documentId,
73
54
  documentType,
@@ -89,11 +70,9 @@ export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
89
70
  </div>
90
71
  );
91
72
 
92
- if (!document) return loadingContent;
73
+ if (!document || isLoading) return loadingContent;
93
74
 
94
- const Editor = getDocumentEditor(documentType);
95
-
96
- if (!Editor) {
75
+ if (!editorModule) {
97
76
  console.error("No editor found for document type:", documentType);
98
77
  return (
99
78
  <div className="flex-1">
@@ -101,7 +80,9 @@ export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
101
80
  </div>
102
81
  );
103
82
  }
104
- const EditorComponent = Editor as FC<EditorProps<PHDocument>>;
83
+
84
+ const moduleWithComponent = editorModule as EditorModule<PHDocument>;
85
+ const EditorComponent = moduleWithComponent.Component;
105
86
 
106
87
  return showRevisionHistory ? (
107
88
  <RevisionHistory
@@ -120,7 +101,7 @@ export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
120
101
  onShowRevisionHistory={() => setShowRevisionHistory(true)}
121
102
  onSwitchboardLinkClick={() => {}}
122
103
  title={title}
123
- timelineButtonVisible
104
+ timelineButtonVisible={moduleWithComponent.config.timelineEnabled}
124
105
  timelineItems={timelineItems.data}
125
106
  onTimelineItemClick={setSelectedTimelineItem}
126
107
  />
@@ -0,0 +1,44 @@
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;
@@ -0,0 +1,41 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/codegen",
3
- "version": "0.49.3-dev.1",
3
+ "version": "0.49.3-dev.2",
4
4
  "license": "AGPL-3.0-only",
5
5
  "private": false,
6
6
  "type": "module",