@powerhousedao/codegen 5.0.0-staging.3 → 5.0.0-staging.30

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.
Files changed (65) hide show
  1. package/README.md +0 -1
  2. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/resolvers.esm.t +1 -1
  3. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts +2 -2
  4. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts.map +1 -1
  5. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js +7 -4
  6. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js.map +1 -1
  7. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/resolvers.esm.t +5 -1
  8. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/CreateDocument.esm.t +24 -15
  9. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveExplorer.esm.t +58 -129
  10. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FolderTree.esm.t +92 -81
  11. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/editor.esm.t +2 -37
  12. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.d.ts +4 -0
  13. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.d.ts.map +1 -1
  14. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.esm.t +6 -4
  15. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.js +2 -0
  16. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.js.map +1 -1
  17. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/editor.esm.t +87 -20
  18. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/hooks.esm.t +17 -0
  19. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts +10 -1
  20. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts.map +1 -1
  21. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.esm.t +2 -4
  22. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js +12 -1
  23. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js.map +1 -1
  24. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/factory.esm.t +1 -1
  25. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.esm.t +1 -1
  26. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/factory.esm.t +1 -1
  27. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.esm.t +1 -1
  28. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/migrations.esm.t +1 -1
  29. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/schema.esm.t +1 -1
  30. package/dist/src/codegen/graphql.d.ts +2 -2
  31. package/dist/src/codegen/graphql.d.ts.map +1 -1
  32. package/dist/src/codegen/graphql.js.map +1 -1
  33. package/dist/src/codegen/hygen.d.ts +6 -3
  34. package/dist/src/codegen/hygen.d.ts.map +1 -1
  35. package/dist/src/codegen/hygen.js +7 -1
  36. package/dist/src/codegen/hygen.js.map +1 -1
  37. package/dist/src/codegen/index.d.ts +6 -3
  38. package/dist/src/codegen/index.d.ts.map +1 -1
  39. package/dist/src/codegen/index.js +12 -24
  40. package/dist/src/codegen/index.js.map +1 -1
  41. package/dist/src/codegen/utils.d.ts +1 -1
  42. package/dist/src/codegen/utils.d.ts.map +1 -1
  43. package/dist/src/codegen/utils.js +1 -1
  44. package/dist/src/codegen/utils.js.map +1 -1
  45. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts +3 -3
  46. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts.map +1 -1
  47. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts +2 -2
  48. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts.map +1 -1
  49. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts +2 -2
  50. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts.map +1 -1
  51. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.d.ts +1 -1
  52. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.d.ts.map +1 -1
  53. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.js +1 -1
  54. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.js.map +1 -1
  55. package/dist/src/ts-morph-generator/utilities/DirectoryManager.d.ts +2 -2
  56. package/dist/src/ts-morph-generator/utilities/DirectoryManager.d.ts.map +1 -1
  57. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts +1 -1
  58. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts.map +1 -1
  59. package/dist/src/utils/validation.d.ts +1 -1
  60. package/dist/src/utils/validation.d.ts.map +1 -1
  61. package/dist/tsconfig.hygen.tsbuildinfo +1 -1
  62. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  63. package/package.json +8 -8
  64. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/EditorContainer.esm.t +0 -103
  65. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/types/css.d.esm.t +0 -8
package/README.md CHANGED
@@ -16,7 +16,6 @@ A powerful code generation toolkit for the Powerhouse ecosystem, designed to aut
16
16
  pnpm add @powerhousedao/codegen
17
17
  ```
18
18
 
19
-
20
19
  ## Templates
21
20
 
22
21
  The package supports custom templates for different output formats:
@@ -4,7 +4,7 @@ force: true
4
4
  ---
5
5
  import { type Subgraph } from "@powerhousedao/reactor-api";
6
6
 
7
- export const getResolvers = (subgraph: Subgraph) => {
7
+ export const getResolvers = (subgraph: Subgraph): Record<string, unknown> => {
8
8
  const reactor = subgraph.reactor;
9
9
 
10
10
  return ({
@@ -1,5 +1,5 @@
1
- import { type DocumentModelState } from "document-model";
2
- import { type Args } from "../generate-document-model/index.js";
1
+ import type { DocumentModelState } from "document-model";
2
+ import type { Args } from "../generate-document-model/index.js";
3
3
  type ModuleArgs = Args & {
4
4
  module: string;
5
5
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAEhE,KAAK,UAAU,GAAG,IAAI,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC5C,KAAK,cAAc,GACjB,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1G,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,cAAc,EAAE,CAAC;CAC1B,CAAC;;uBAGmB;QAAE,IAAI,EAAE,UAAU,CAAA;KAAE;;;;;;;;AADzC,wBA2CE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAEhE,KAAK,UAAU,GAAG,IAAI,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC5C,KAAK,cAAc,GACjB,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1G,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,cAAc,EAAE,CAAC;CAC1B,CAAC;;uBAGmB;QAAE,IAAI,EAAE,UAAU,CAAA;KAAE;;;;;;;;AADzC,wBAiDE"}
@@ -18,12 +18,15 @@ exports.default = {
18
18
  : [];
19
19
  const errors = actions.reduce((acc, action) => {
20
20
  action.errors.forEach((error) => {
21
- const existingError = acc.find((e) => e.code === error.code);
21
+ // Fallback: If error code is empty, generate it from the error name in PascalCase
22
+ const errorCode = error.code || (0, change_case_1.pascalCase)(error.name || "");
23
+ const normalizedError = { ...error, code: errorCode };
24
+ const existingError = acc.find((e) => e.code === errorCode);
22
25
  if (!existingError) {
23
- acc.push(error);
26
+ acc.push(normalizedError);
24
27
  }
25
- else if (JSON.stringify(existingError) !== JSON.stringify(error)) {
26
- console.warn(`Warning: Duplicate error code "${error.code}" with different fields found`);
28
+ else if (JSON.stringify(existingError) !== JSON.stringify(normalizedError)) {
29
+ console.warn(`Warning: Duplicate error code "${errorCode}" with different fields found`);
27
30
  }
28
31
  });
29
32
  return acc;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.ts"],"names":[],"mappings":";;AAAA,6CAAwC;AAgBxC,kBAAe;IACb,MAAM,EAAE,CAAC,EAAE,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AI,CAAC,aAAa,EAAE,CAAC;oBACnB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAClB,CAAC;qBAAM,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;oBACnE,OAAO,CAAC,IAAI,CACV,kCAAkC,KAAK,CAAC,IAAI,+BAA+B,CAC5E,CAAC;gBACJ,CAAC;YACH,CAAC,CAAC,CAAC;YACH,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,aAAa,CAAC,IAAI;YAChC,MAAM,EAAE,IAAA,uBAAS,EAAC,IAAI,CAAC,MAAM,CAAC;YAC9B,OAAO;YACP,MAAM;SACP,CAAC;IACJ,CAAC;CACF,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.ts"],"names":[],"mappings":";;AAAA,6CAAoD;AAgBpD,kBAAe;IACb,MAAM,EAAE,CAAC,EAAE,IAAI,EAAwB,EAAE,EAAE;QACzC,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAuB,CAAC;QAC3E,MAAM,UAAU,GACd,aAAa,CAAC,cAAc,CAAC,aAAa,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACxE,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAC/C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAC9B,CAAC;QAEF,MAAM,OAAO,GACX,eAAe,CAAC,MAAM,GAAG,CAAC;YACxB,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAA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,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,aAAa,CAAC,IAAI;YAChC,MAAM,EAAE,IAAA,uBAAS,EAAC,IAAI,CAAC,MAAM,CAAC;YAC9B,OAAO;YACP,MAAM;SACP,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -7,7 +7,7 @@ import { addFile } from "document-drive";
7
7
  import { actions <% modules.forEach(module => { %><% module.operations.forEach(op => { %>, type <%- h.changeCase.pascal(op.name) %>Input<%_ })}); %>, type <%- h.changeCase.pascal(documentType) %>Document } from "../../document-models/<%- h.changeCase.param(documentType) %>/index.js";
8
8
  import { setName } from "document-model";
9
9
 
10
- export const getResolvers = (subgraph: Subgraph) => {
10
+ export const getResolvers = (subgraph: Subgraph): Record<string, unknown> => {
11
11
  const reactor = subgraph.reactor;
12
12
 
13
13
  return ({
@@ -33,6 +33,8 @@ export const getResolvers = (subgraph: Subgraph) => {
33
33
  driveId: driveId,
34
34
  ...doc,
35
35
  ...doc.header,
36
+ created: doc.header.createdAtUtcIso,
37
+ lastModified: doc.header.lastModifiedAtUtcIso,
36
38
  state: doc.state.global,
37
39
  stateJSON: doc.state.global,
38
40
  revision: doc.header?.revision?.global ?? 0,
@@ -48,6 +50,8 @@ export const getResolvers = (subgraph: Subgraph) => {
48
50
  driveId: driveId,
49
51
  ...doc,
50
52
  ...doc.header,
53
+ created: doc.header.createdAtUtcIso,
54
+ lastModified: doc.header.lastModifiedAtUtcIso,
51
55
  state: doc.state.global,
52
56
  stateJSON: doc.state.global,
53
57
  revision: doc.header?.revision?.global ?? 0,
@@ -2,45 +2,54 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/components/CreateDocument.tsx"
3
3
  unless_exists: true
4
4
  ---
5
+ import { Button } from "@powerhousedao/design-system";
5
6
  import {
6
- addDocument,
7
+ isDocumentTypeSupported,
8
+ showPHModal,
7
9
  useDocumentModelModules,
8
10
  useSelectedDriveId,
9
- useSelectedFolder,
10
11
  type VetraDocumentModelModule,
11
12
  } from "@powerhousedao/reactor-browser";
12
- import { Button } from "@powerhousedao/design-system";
13
+
14
+ interface CreateDocumentProps {
15
+ documentTypes?: string[];
16
+ }
13
17
 
14
18
  /**
15
19
  * Document creation UI component.
16
20
  * Displays available document types as clickable buttons.
17
21
  */
18
- export const CreateDocument = () => {
22
+ export const CreateDocument = (props: CreateDocumentProps) => {
23
+ const { documentTypes = [] } = props;
24
+
19
25
  const selectedDriveId = useSelectedDriveId();
20
- const selectedFolder = useSelectedFolder();
21
26
  const documentModelModules = useDocumentModelModules();
22
27
 
23
- async function handleAddDocument(module: VetraDocumentModelModule) {
28
+ const filteredDocumentModelModules = documentModelModules.filter((module) =>
29
+ isDocumentTypeSupported(module.documentModel.id, documentTypes),
30
+ );
31
+
32
+ function handleAddDocument(module: VetraDocumentModelModule) {
24
33
  if (!selectedDriveId) {
25
34
  return;
26
35
  }
27
- await addDocument(
28
- selectedDriveId,
29
- `New ${module.documentModel.name} document`,
30
- module.documentModel.id,
31
- selectedFolder?.id,
32
- );
36
+
37
+ // Display the Create Document modal on the host app
38
+ showPHModal({
39
+ type: "createDocument",
40
+ documentType: module.documentModel.id,
41
+ });
33
42
  }
34
43
 
35
44
  return (
36
- <div className="px-6">
45
+ <div>
37
46
  {/* Customize section title here */}
38
47
  <h3 className="mb-3 mt-4 text-sm font-bold text-gray-600">
39
- New document
48
+ Create document
40
49
  </h3>
41
50
  {/* Customize layout by changing flex-wrap, gap, or grid layout */}
42
51
  <div className="flex w-full flex-wrap gap-4">
43
- {documentModelModules?.map((documentModelModule) => {
52
+ {filteredDocumentModelModules.map((documentModelModule) => {
44
53
  return (
45
54
  <Button
46
55
  key={documentModelModule.documentModel.id}
@@ -4,32 +4,28 @@ unless_exists: true
4
4
  ---
5
5
  import {
6
6
  Breadcrumbs,
7
- CreateDocumentModal,
7
+ Button,
8
8
  FileItem,
9
9
  FolderItem,
10
10
  useBreadcrumbs,
11
11
  } from "@powerhousedao/design-system";
12
12
  import {
13
- addDocument,
14
13
  type DriveEditorProps,
15
14
  getSyncStatusSync,
16
15
  setSelectedNode,
17
- useAllFolderNodes,
18
- useDocumentModelModules,
19
- useDriveContext,
16
+ showDeleteNodeModal,
20
17
  useDriveSharingType,
21
- useEditorModules,
22
- useFileChildNodes,
23
- useFolderChildNodes,
24
- useSelectedDrive,
18
+ useFileChildNodesForId,
19
+ useFolderChildNodesForId,
20
+ useNodeActions,
21
+ useNodes,
22
+ useSelectedDriveDocument,
25
23
  useSelectedFolder,
26
24
  useSelectedNodePath,
27
25
  useUserPermissions,
28
26
  } from "@powerhousedao/reactor-browser";
29
- import type { DocumentModelModule } from "document-model";
30
- import { useCallback, useRef, useState } from "react";
27
+ import { useCallback } from "react";
31
28
  import { CreateDocument } from "./CreateDocument.js";
32
- import { EditorContainer } from "./EditorContainer.js";
33
29
  import { FolderTree } from "./FolderTree.js";
34
30
 
35
31
  /**
@@ -37,14 +33,8 @@ import { FolderTree } from "./FolderTree.js";
37
33
  * Layout: Left sidebar (folder tree) + Right content area (files/folders + document editor)
38
34
  */
39
35
  export function DriveExplorer(props: DriveEditorProps) {
40
- // === DOCUMENT EDITOR STATE ===
41
- // Customize document opening/closing behavior here
42
- const [activeDocumentId, setActiveDocumentId] = useState<
43
- string | undefined
44
- >();
45
- const [openModal, setOpenModal] = useState(false);
46
- const selectedDocumentModel = useRef<DocumentModelModule | null>(null);
47
- const editorModules = useEditorModules();
36
+ const { children, editorConfig } = props;
37
+
48
38
  // === DRIVE CONTEXT HOOKS ===
49
39
  // Core drive operations and document models
50
40
  const {
@@ -54,16 +44,15 @@ export function DriveExplorer(props: DriveEditorProps) {
54
44
  onDuplicateNode,
55
45
  onMoveNode,
56
46
  onRenameNode,
57
- showDeleteNodeModal,
58
- } = useDriveContext();
47
+ } = useNodeActions();
59
48
 
60
49
  const { isAllowedToCreateDocuments } = useUserPermissions();
61
50
  // === STATE MANAGEMENT HOOKS ===
62
51
  // Core state hooks for drive navigation
63
- const [selectedDrive] = useSelectedDrive(); // Currently selected drive
52
+ const [selectedDrive] = useSelectedDriveDocument(); // Currently selected drive
64
53
  const selectedFolder = useSelectedFolder(); // Currently selected folder
65
54
  const selectedNodePath = useSelectedNodePath();
66
- const sharingType = useDriveSharingType(selectedDrive?.header.id);
55
+ const sharingType = useDriveSharingType(selectedDrive.header.id);
67
56
 
68
57
  // === NAVIGATION SETUP ===
69
58
  // Breadcrumbs for folder navigation
@@ -72,11 +61,13 @@ export function DriveExplorer(props: DriveEditorProps) {
72
61
  setSelectedNode,
73
62
  });
74
63
 
75
- const folderChildren = useFolderChildNodes();
76
- const fileChildren = useFileChildNodes();
64
+ const selectedNodeId = selectedFolder?.id || selectedDrive.header.id;
65
+
66
+ const folderChildren = useFolderChildNodesForId(selectedNodeId);
67
+ const fileChildren = useFileChildNodesForId(selectedNodeId);
77
68
 
78
- // All folders for the sidebar tree view
79
- const allFolders = useAllFolderNodes();
69
+ // All nodes (folders and files) for the sidebar tree view
70
+ const allNodes = useNodes() || [];
80
71
 
81
72
  // === EVENT HANDLERS ===
82
73
 
@@ -102,82 +93,31 @@ export function DriveExplorer(props: DriveEditorProps) {
102
93
  [onAddFolder, selectedFolder],
103
94
  );
104
95
 
105
- // Handle document creation from modal
106
- const onCreateDocument = useCallback(
107
- async (fileName: string) => {
108
- setOpenModal(false);
109
-
110
- const documentModel = selectedDocumentModel.current;
111
- if (!documentModel || !selectedDrive?.header.id) return;
112
-
113
- try {
114
- const node = await addDocument(
115
- selectedDrive.header.id,
116
- fileName,
117
- documentModel.documentModel.id,
118
- selectedFolder?.id,
119
- );
120
-
121
- selectedDocumentModel.current = null;
122
-
123
- if (node) {
124
- // Customize: Auto-open created document by uncommenting below
125
- // setActiveDocumentId(node.id);
126
- }
127
- } catch (error) {
128
- console.error("Failed to create document:", error);
129
- }
130
- },
131
- [addDocument, editorModules, selectedDrive?.header.id, selectedFolder?.id],
132
- );
133
-
134
- // === DOCUMENT EDITOR DATA ===
135
- // Filter available document types here if needed
136
- const documentModelModules = useDocumentModelModules();
137
-
138
- // Get active document and its editor components
139
- const activeDocument = activeDocumentId
140
- ? fileChildren.find((file) => file.id === activeDocumentId)
141
- : undefined;
142
-
143
- const documentModelModule = activeDocument
144
- ? documentModelModules?.find(
145
- (m) => m.documentModel.id === activeDocument.documentType,
146
- )
147
- : null;
148
-
149
- const editorModule = activeDocument
150
- ? editorModules?.find((e) =>
151
- e.documentTypes.includes(activeDocument.documentType),
152
- )
153
- : null;
96
+ // if a document is selected then it's editor will be passed as children
97
+ const showDocumentEditor = !!children;
154
98
 
155
99
  // === RENDER ===
156
100
  return (
157
101
  <div className="flex h-full">
158
- {/* === LEFT SIDEBAR: Folder Navigation === */}
159
- {/* Customize sidebar width by changing w-64 */}
160
- <div className="w-64 overflow-y-auto border-r border-gray-200 bg-white">
161
- <div className="p-4">
162
- {/* Customize sidebar title here */}
163
- <h2 className="mb-4 text-lg font-semibold text-gray-700">
164
- Drive Explorer
165
- </h2>
166
-
167
- {/* Folder tree navigation component */}
168
- <FolderTree folders={allFolders} onSelectNode={setSelectedNode} />
169
- </div>
170
- </div>
102
+ {/* === LEFT SIDEBAR: Folder and File Navigation === */}
103
+ {/* Sidebar component manages its own width, styling, and overflow */}
104
+ <FolderTree
105
+ driveId={selectedDrive.header.id}
106
+ driveName={selectedDrive.state.global.name}
107
+ nodes={allNodes}
108
+ selectedNodeId={selectedNodeId}
109
+ onSelectNode={setSelectedNode}
110
+ />
171
111
 
172
112
  {/* === RIGHT CONTENT AREA: Files/Folders or Document Editor === */}
173
113
  <div className="flex-1 overflow-y-auto p-4">
174
114
  {/* Conditional rendering: Document editor or folder contents */}
175
- {activeDocument && documentModelModule && editorModule ? (
115
+ {showDocumentEditor ? (
176
116
  // Document editor view
177
- <EditorContainer handleClose={() => setActiveDocumentId(undefined)} />
117
+ children
178
118
  ) : (
179
119
  /* Folder contents view */
180
- <div className="space-y-6">
120
+ <div className="space-y-6 px-6">
181
121
  {/* === HEADER SECTION === */}
182
122
  <div className="space-y-3">
183
123
  <div className="flex items-center justify-between">
@@ -189,36 +129,30 @@ export function DriveExplorer(props: DriveEditorProps) {
189
129
  </h2>
190
130
  {/* Customize: Add more action buttons here */}
191
131
  {isAllowedToCreateDocuments && (
192
- <button
193
- onClick={() => handleCreateFolder()}
194
- className="rounded bg-blue-500 px-3 py-1 text-sm text-white hover:bg-blue-600"
195
- >
196
- + New Folder
197
- </button>
132
+ <Button onClick={() => handleCreateFolder()}>
133
+ New Folder
134
+ </Button>
198
135
  )}
199
136
  </div>
200
137
 
201
138
  {/* Navigation breadcrumbs */}
202
- {breadcrumbs.length > 1 && (
203
- <div className="border-b border-gray-200 pb-3">
204
- <Breadcrumbs
205
- breadcrumbs={breadcrumbs}
206
- createEnabled={isAllowedToCreateDocuments}
207
- onCreate={handleCreateFolder}
208
- onBreadcrumbSelected={onBreadcrumbSelected}
209
- />
210
- </div>
211
- )}
139
+ <div className="border-b border-gray-200 pb-3">
140
+ <Breadcrumbs
141
+ breadcrumbs={breadcrumbs}
142
+ createEnabled={isAllowedToCreateDocuments}
143
+ onCreate={handleCreateFolder}
144
+ onBreadcrumbSelected={onBreadcrumbSelected}
145
+ />
146
+ </div>
212
147
  </div>
213
148
 
214
149
  {/* === FOLDERS SECTION === */}
215
- {/* Customize grid layout by changing grid-cols-1 */}
216
150
  {folderChildren.length > 0 && (
217
151
  <div>
218
- <h3 className="mb-2 text-sm font-medium text-gray-500">
219
- 📁 Folders
152
+ <h3 className="mb-2 text-sm font-bold text-gray-600">
153
+ Folders
220
154
  </h3>
221
- <div className="grid grid-cols-1 gap-2">
155
+ <div className="flex flex-wrap gap-4">
222
156
  {folderChildren.map((folderNode) => (
223
157
  <FolderItem
224
158
  key={folderNode.id}
@@ -234,7 +168,9 @@ export function DriveExplorer(props: DriveEditorProps) {
234
168
  onDuplicateNode={onDuplicateNode}
235
169
  onAddFolder={onAddFolder}
236
170
  onAddAndSelectNewFolder={handleCreateFolder}
237
- showDeleteNodeModal={showDeleteNodeModal}
171
+ showDeleteNodeModal={(node) =>
172
+ showDeleteNodeModal(node.id)
173
+ }
238
174
  />
239
175
  ))}
240
176
  </div>
@@ -242,13 +178,12 @@ export function DriveExplorer(props: DriveEditorProps) {
242
178
  )}
243
179
 
244
180
  {/* === FILES/DOCUMENTS SECTION === */}
245
- {/* Customize grid layout by changing grid-cols-1 */}
246
181
  {fileChildren.length > 0 && (
247
182
  <div>
248
- <h3 className="mb-2 text-sm font-medium text-gray-500">
249
- 📄 Documents
183
+ <h3 className="mb-2 text-sm font-semibold text-gray-600">
184
+ Documents
250
185
  </h3>
251
- <div className="grid grid-cols-1 gap-2">
186
+ <div className="flex flex-wrap gap-4">
252
187
  {fileChildren.map((fileNode) => (
253
188
  <FileItem
254
189
  key={fileNode.id}
@@ -257,7 +192,9 @@ export function DriveExplorer(props: DriveEditorProps) {
257
192
  sharingType={sharingType || "LOCAL"}
258
193
  getSyncStatusSync={getSyncStatusSync}
259
194
  setSelectedNode={setSelectedNode}
260
- showDeleteNodeModal={showDeleteNodeModal}
195
+ showDeleteNodeModal={(node) =>
196
+ showDeleteNodeModal(node.id)
197
+ }
261
198
  onRenameNode={onRenameNode}
262
199
  onDuplicateNode={onDuplicateNode}
263
200
  onAddFile={onAddFile}
@@ -275,7 +212,7 @@ export function DriveExplorer(props: DriveEditorProps) {
275
212
  {/* Customize empty state message and styling here */}
276
213
  {folderChildren.length === 0 && fileChildren.length === 0 && (
277
214
  <div className="py-12 text-center text-gray-500">
278
- <p className="text-lg">📁 This folder is empty</p>
215
+ <p className="text-lg">This folder is empty</p>
279
216
  <p className="mt-2 text-sm">
280
217
  Create your first document or folder below
281
218
  </p>
@@ -284,18 +221,10 @@ export function DriveExplorer(props: DriveEditorProps) {
284
221
 
285
222
  {/* === DOCUMENT CREATION SECTION === */}
286
223
  {/* Component for creating new documents */}
287
- <CreateDocument />
224
+ <CreateDocument documentTypes={editorConfig?.documentTypes} />
288
225
  </div>
289
226
  )}
290
227
  </div>
291
-
292
- {/* === DOCUMENT CREATION MODAL === */}
293
- {/* Modal for entering document name after selecting type */}
294
- <CreateDocumentModal
295
- onContinue={onCreateDocument}
296
- onOpenChange={(open) => setOpenModal(open)}
297
- open={openModal}
298
- />
299
228
  </div>
300
229
  );
301
230
  }