@powerhousedao/codegen 4.1.0-dev.22 → 4.1.0-dev.24

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.
@@ -2,109 +2,74 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/components/EditorContainer.tsx"
3
3
  unless_exists: true
4
4
  ---
5
+ import { getRevisionFromDate, useTimelineItems } from "@powerhousedao/common";
5
6
  import {
6
- useDriveContext,
7
- exportDocument,
8
- type User,
9
- type DriveEditorContext,
10
- } from "@powerhousedao/reactor-browser";
11
- import {
12
- type EditorContext,
13
- type DocumentModelModule,
14
- type EditorModule,
15
- type EditorProps,
16
- type PHDocument,
17
- } from "document-model";
18
- import {
7
+ DefaultEditorLoader,
19
8
  DocumentToolbar,
20
9
  RevisionHistory,
21
- DefaultEditorLoader,
22
10
  type TimelineItem,
23
11
  } from "@powerhousedao/design-system";
24
- import { useTimelineItems, getRevisionFromDate } from "@powerhousedao/common";
25
- import { useState, Suspense, type FC, useCallback } from "react";
26
-
27
- export interface EditorContainerProps {
28
- driveId: string;
29
- documentId: string;
30
- documentType: string;
31
- onClose: () => void;
32
- title: string;
33
- context: Omit<DriveEditorContext, "getDocumentRevision"> &
34
- Pick<EditorContext, "getDocumentRevision">;
35
- documentModelModule: DocumentModelModule<PHDocument>;
36
- editorModule: EditorModule;
37
- }
12
+ import {
13
+ exportFile,
14
+ useEditorModuleById,
15
+ useSelectedDocument,
16
+ useSelectedDrive,
17
+ } from "@powerhousedao/reactor-browser";
18
+ import { error } from "console";
19
+ import { title } from "process";
20
+ import { Suspense, useCallback, useState } from "react";
38
21
 
39
22
  /**
40
23
  * Document editor container that wraps individual document editors.
41
24
  * Handles document loading, toolbar, revision history, and dynamic editor loading.
42
25
  * Customize toolbar actions and editor context here.
43
26
  */
44
- export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
45
- const {
46
- title,
47
- driveId,
48
- context,
49
- onClose,
50
- documentId,
51
- documentType,
52
- editorModule,
53
- documentModelModule,
54
- } = props;
55
-
27
+ export const EditorContainer = (props: { handleClose: () => void }) => {
28
+ const { handleClose } = props;
56
29
  // UI state for revision history and timeline
57
30
  const [selectedTimelineItem, setSelectedTimelineItem] =
58
31
  useState<TimelineItem | null>(null);
59
32
  const [showRevisionHistory, setShowRevisionHistory] = useState(false);
60
- const { useDocumentEditorProps } = useDriveContext();
61
-
62
- const user = context.user as User | undefined;
63
-
64
- // Document data and editor state
65
- const { dispatch, error, document } = useDocumentEditorProps({
66
- documentId,
67
- documentType,
68
- driveId,
69
- documentModelModule,
70
- user,
71
- });
72
-
33
+ const [selectedDocument, dispatch] = useSelectedDocument();
34
+ const [selectedDrive] = useSelectedDrive();
73
35
  // Timeline data for revision history
74
36
  const timelineItems = useTimelineItems(
75
- documentId,
76
- document?.header.createdAtUtcIso,
77
- driveId,
37
+ selectedDocument?.header.id,
38
+ selectedDocument?.header.createdAtUtcIso,
39
+ selectedDrive?.header.id,
40
+ );
41
+ const editorModule = useEditorModuleById(
42
+ selectedDocument?.header.meta?.preferredEditor,
78
43
  );
79
44
 
80
45
  // Document export functionality - customize export behavior here
81
46
  const onExport = useCallback(async () => {
82
- if (document) {
83
- const ext = documentModelModule.documentModel.extension;
84
- await exportDocument(document, title, ext);
47
+ if (selectedDocument) {
48
+ await exportFile(selectedDocument);
85
49
  }
86
- }, [document?.header.revision.global, document?.header.revision.local]);
50
+ }, [selectedDocument]);
87
51
 
88
52
  // Loading state component
89
53
  const loadingContent = (
90
- <div className="flex-1 flex justify-center items-center h-full">
54
+ <div className="flex h-full flex-1 items-center justify-center">
91
55
  <DefaultEditorLoader />
92
56
  </div>
93
57
  );
94
58
 
95
- if (!document) return loadingContent;
59
+ if (!selectedDocument) return loadingContent;
96
60
 
97
61
  // Dynamically load the appropriate editor component for this document type
98
- const EditorComponent = editorModule.Component as FC<EditorProps<PHDocument>>;
62
+ const EditorComponent = editorModule?.Component;
63
+ if (!EditorComponent) return loadingContent;
99
64
 
100
65
  return showRevisionHistory ? (
101
66
  // Revision history view
102
67
  <RevisionHistory
103
- documentId={documentId}
104
- documentTitle={title}
105
- globalOperations={document.operations.global}
106
- key={documentId}
107
- localOperations={document.operations.local}
68
+ documentId={selectedDocument.header.id}
69
+ documentTitle={selectedDocument.header.name}
70
+ globalOperations={selectedDocument.operations.global}
71
+ key={selectedDocument.header.id}
72
+ localOperations={selectedDocument.operations.local}
108
73
  onClose={() => setShowRevisionHistory(false)}
109
74
  />
110
75
  ) : (
@@ -112,7 +77,7 @@ export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
112
77
  <Suspense fallback={loadingContent}>
113
78
  {/* Document toolbar - customize available actions here */}
114
79
  <DocumentToolbar
115
- onClose={onClose}
80
+ onClose={handleClose}
116
81
  onExport={onExport}
117
82
  onShowRevisionHistory={() => setShowRevisionHistory(true)}
118
83
  onSwitchboardLinkClick={() => {}} // Customize switchboard integration
@@ -124,12 +89,11 @@ export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
124
89
  {/* Dynamic editor component based on document type */}
125
90
  <EditorComponent
126
91
  context={{
127
- ...context,
128
92
  readMode: !!selectedTimelineItem,
129
93
  selectedTimelineRevision: getRevisionFromDate(
130
94
  selectedTimelineItem?.startDate,
131
95
  selectedTimelineItem?.endDate,
132
- document.operations.global,
96
+ selectedDocument.operations.global,
133
97
  ),
134
98
  }}
135
99
  dispatch={dispatch}
@@ -138,4 +102,4 @@ export const EditorContainer: React.FC<EditorContainerProps> = (props) => {
138
102
  />
139
103
  </Suspense>
140
104
  );
141
- };
105
+ };
@@ -2,8 +2,8 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/components/FolderTree.tsx"
3
3
  unless_exists: true
4
4
  ---
5
- import { useState } from "react";
6
5
  import type { FolderNode } from "document-drive";
6
+ import { useState } from "react";
7
7
 
8
8
  interface FolderTreeProps {
9
9
  folders: FolderNode[];
@@ -39,7 +39,7 @@ export function FolderTree({
39
39
  };
40
40
 
41
41
  // Recursive function to render folder tree structure
42
- const renderFolder = (folder: FolderNode, level: number = 0) => {
42
+ const renderFolder = (folder: FolderNode, level = 0) => {
43
43
  const hasChildren = folders.some((f) => f.parentFolder === folder.id);
44
44
  const isExpanded = expandedFolders.has(folder.id);
45
45
  const isSelected = selectedNodeId === folder.id;
@@ -47,7 +47,7 @@ export function FolderTree({
47
47
  return (
48
48
  <div key={folder.id}>
49
49
  <div
50
- className={`flex items-center py-1 px-2 cursor-pointer hover:bg-gray-100 rounded text-sm ${
50
+ className={`flex cursor-pointer items-center rounded px-2 py-1 text-sm hover:bg-gray-100 ${
51
51
  isSelected ? "bg-blue-100 text-blue-800" : ""
52
52
  }`}
53
53
  style={{ paddingLeft: `${level * 16 + 8}px` }} // Customize indentation here
@@ -56,7 +56,7 @@ export function FolderTree({
56
56
  {/* Expand/collapse button for folders with children */}
57
57
  {hasChildren && (
58
58
  <button
59
- className="w-4 h-4 mr-1 flex items-center justify-center"
59
+ className="mr-1 flex h-4 w-4 items-center justify-center"
60
60
  onClick={(e) => {
61
61
  e.stopPropagation();
62
62
  toggleFolder(folder.id);
@@ -65,7 +65,7 @@ export function FolderTree({
65
65
  {isExpanded ? "▼" : "▶"} {/* Customize expand icons here */}
66
66
  </button>
67
67
  )}
68
- {!hasChildren && <div className="w-5 mr-1" />}
68
+ {!hasChildren && <div className="mr-1 w-5" />}
69
69
  {/* Customize folder icon and styling here */}
70
70
  <span>📁 {folder.name}</span>
71
71
  </div>
@@ -86,7 +86,7 @@ export function FolderTree({
86
86
  {/* Root Directory Option */}
87
87
  {/* Customize root folder appearance here */}
88
88
  <div
89
- className={`flex items-center py-1 px-2 cursor-pointer hover:bg-gray-100 rounded text-sm ${
89
+ className={`flex cursor-pointer items-center rounded px-2 py-1 text-sm hover:bg-gray-100 ${
90
90
  !selectedNodeId ? "bg-blue-100 text-blue-800" : ""
91
91
  }`}
92
92
  onClick={() => onSelectNode(undefined)}
@@ -100,4 +100,4 @@ export function FolderTree({
100
100
  .map((folder) => renderFolder(folder))}
101
101
  </div>
102
102
  );
103
- }
103
+ }
@@ -2,70 +2,39 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/editor.tsx"
3
3
  unless_exists: true
4
4
  ---
5
- import { type DriveEditorProps } from "@powerhousedao/reactor-browser";
6
- import { AnalyticsProvider } from "@powerhousedao/reactor-browser/analytics/context";
7
- import { DriveContextProvider, useDriveContext } from "@powerhousedao/reactor-browser/hooks/useDriveContext";
8
- import { useInitializePHApp, useSetSelectedNode } from '@powerhousedao/state';
9
- import { type DocumentDriveDocument, type FileNode } from "document-drive";
10
5
  import { WagmiContext } from "@powerhousedao/design-system";
6
+ import {
7
+ AnalyticsProvider,
8
+ DriveContextProvider,
9
+ useAppConfig,
10
+ type DriveEditorProps,
11
+ } from "@powerhousedao/reactor-browser";
11
12
  import { DriveExplorer } from "./components/DriveExplorer.js";
12
- import { useCallback } from "react";
13
-
14
- export type IProps = DriveEditorProps<DocumentDriveDocument>;
15
13
 
16
14
  /**
17
15
  * Base editor component that renders the drive explorer interface.
18
16
  * Customize document opening behavior and drive-level actions here.
19
17
  */
20
- export function BaseEditor(props: IProps) {
18
+ export function BaseEditor(props: DriveEditorProps) {
21
19
  const { context, document } = props;
22
-
23
- // Get drive operations from context
24
- const {
25
- onAddFolder,
26
- onRenameNode,
27
- onCopyNode,
28
- showDeleteNodeModal,
29
- } = useDriveContext();
30
-
31
- const setSelectedNode = useSetSelectedNode();
32
-
33
- // Handle document opening - customize this to modify document open behavior
34
- const onOpenDocument = useCallback(
35
- (node: FileNode) => {
36
- setSelectedNode(node.id);
37
- },
38
- [setSelectedNode],
39
- );
40
-
41
20
  return (
42
21
  <div className="new-drive-explorer" style={{ height: "100%" }}>
43
- <DriveExplorer
44
- driveId={document.header.id}
45
- onAddFolder={onAddFolder}
46
- onRenameNode={onRenameNode}
47
- onCopyNode={onCopyNode}
48
- onOpenDocument={onOpenDocument}
49
- showDeleteNodeModal={showDeleteNodeModal}
50
- context={context}
51
- />
22
+ <DriveExplorer document={document} context={context} />
52
23
  </div>
53
24
  );
54
25
  }
55
26
 
56
27
  /**
57
28
  * Main editor entry point with required providers.
58
- * useInitializePHApp() is required for state management to work properly.
59
29
  */
60
- export default function Editor(props: IProps) {
61
- // Required: Initialize Powerhouse app state
62
- useInitializePHApp();
63
-
30
+ export default function Editor(props: DriveEditorProps) {
31
+ const appConfig = useAppConfig();
32
+ const analyticsDatabaseName = appConfig?.analyticsDatabaseName;
64
33
  return (
65
34
  // Required context providers for drive functionality
66
35
  <DriveContextProvider value={props.context}>
67
36
  <WagmiContext>
68
- <AnalyticsProvider databaseName={props.context.analyticsDatabaseName}>
37
+ <AnalyticsProvider databaseName={analyticsDatabaseName}>
69
38
  <BaseEditor {...props} />
70
39
  </AnalyticsProvider>
71
40
  </WagmiContext>
@@ -3,10 +3,9 @@ to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/index.ts"
3
3
  force: true
4
4
  ---
5
5
  import { type DriveEditorModule } from "@powerhousedao/reactor-browser";
6
- import { type DocumentDriveDocument } from "document-drive";
7
6
  import Editor from "./editor.js";
8
7
 
9
- export const module: DriveEditorModule<DocumentDriveDocument> = {
8
+ export const module: DriveEditorModule = {
10
9
  Component: Editor,
11
10
  documentTypes: ["powerhouse/document-drive"],
12
11
  config: {
@@ -4,9 +4,10 @@ force: true
4
4
  ---
5
5
  import { type ProcessorRecord } from "document-drive/processors/types";
6
6
  import { type IProcessorHostModule } from "document-drive/processors/types";
7
+ import { type PHDocumentHeader } from "document-model";
7
8
  import { <%= pascalName %>Processor } from "./index.js";
8
9
 
9
- export const <%= h.changeCase.pascal(name) %>ProcessorFactory = (module: IProcessorHostModule) => (driveId: string): ProcessorRecord[] => {
10
+ export const <%= h.changeCase.pascal(name) %>ProcessorFactory = (module: IProcessorHostModule) => (driveHeader: PHDocumentHeader): ProcessorRecord[] => {
10
11
  return [
11
12
  {
12
13
  processor: new <%= pascalName %>Processor(module.analyticsStore),
@@ -7,24 +7,26 @@ unless_exists: true
7
7
  * Auto-generated by codegen - DO NOT EDIT MANUALLY
8
8
  */
9
9
 
10
- import { type ProcessorRecord } from "document-drive/processors/types";
10
+ import { type ProcessorRecord, type ProcessorFactory } from "document-drive/processors/types";
11
11
  import { type IProcessorHostModule } from "document-drive/processors/types";
12
+ import { type PHDocumentHeader } from "document-model";
12
13
 
13
14
  // Import processor factories here as they are generated
14
15
 
15
16
  export const processorFactory = (module: IProcessorHostModule) => {
16
17
  // Initialize all processor factories once with the module
17
- const factories: Array<(driveId: string) => ProcessorRecord[]> = [];
18
+ const factories: Array<ProcessorFactory> = [];
18
19
 
19
20
  // Add processors here as they are generated
20
21
 
21
22
  // Return the inner function that will be called for each drive
22
- return (driveId: string): ProcessorRecord[] => {
23
+ return async (driveHeader: PHDocumentHeader): Promise<ProcessorRecord[]> => {
23
24
  const processors: ProcessorRecord[] = [];
24
25
 
25
- // Call each cached factory with the driveId
26
+ // Call each cached factory with the driveHeader
26
27
  for (const factory of factories) {
27
- processors.push(...factory(driveId));
28
+ const factoryProcessors = await factory(driveHeader);
29
+ processors.push(...factoryProcessors);
28
30
  }
29
31
 
30
32
  return processors;
@@ -9,11 +9,12 @@ import {
9
9
  import {
10
10
  type RelationalDbProcessorFilter,
11
11
  } from "document-drive/processors/relational";
12
+ import { type PHDocumentHeader } from "document-model";
12
13
  import { <%= pascalName %>Processor } from "./index.js";
13
14
 
14
- export const <%= h.changeCase.camel(name) %>ProcessorFactory = (module: IProcessorHostModule) => async (driveId: string): Promise<ProcessorRecord[]> => {
15
+ export const <%= h.changeCase.camel(name) %>ProcessorFactory = (module: IProcessorHostModule) => async (driveHeader: PHDocumentHeader): Promise<ProcessorRecord[]> => {
15
16
  // Create a namespace for the processor and the provided drive id
16
- const namespace = <%= pascalName %>Processor.getNamespace(driveId);
17
+ const namespace = <%= pascalName %>Processor.getNamespace(driveHeader.id);
17
18
 
18
19
  // Create a namespaced db for the processor
19
20
  const store = await module.relationalDb.createNamespace<<%= pascalName %>Processor>(
@@ -7,25 +7,26 @@ unless_exists: true
7
7
  * Auto-generated by codegen - DO NOT EDIT MANUALLY
8
8
  */
9
9
 
10
- import { type ProcessorRecord, type IProcessorHostModule } from "document-drive/processors/types";
10
+ import { type ProcessorRecord, type IProcessorHostModule, type ProcessorFactory } from "document-drive/processors/types";
11
+ import { type PHDocumentHeader } from "document-model";
11
12
 
12
13
  // Import other processor factories here as they are generated
13
14
 
14
15
  export const processorFactory = (module: IProcessorHostModule) => {
15
16
  // Initialize all processor factories once with the module
16
- const factories: Array<(driveId: string) => Promise<ProcessorRecord[]>> = [];
17
+ const factories: Array<ProcessorFactory> = [];
17
18
 
18
19
  // Add all processor factories
19
20
 
20
21
  // Add other processors here as they are generated
21
22
 
22
23
  // Return the inner function that will be called for each drive
23
- return async (driveId: string): Promise<ProcessorRecord[]> => {
24
+ return async (driveHeader: PHDocumentHeader): Promise<ProcessorRecord[]> => {
24
25
  const processors: ProcessorRecord[] = [];
25
26
 
26
- // Call each cached factory with the driveId
27
+ // Call each cached factory with the driveHeader
27
28
  for (const factory of factories) {
28
- const factoryProcessors = await factory(driveId);
29
+ const factoryProcessors = await factory(driveHeader);
29
30
  processors.push(...factoryProcessors);
30
31
  }
31
32