@specverse/engines 4.1.5 → 4.1.7
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/libs/instance-factories/applications/templates/generic/backend-env-generator.js +22 -0
- package/dist/libs/instance-factories/applications/templates/generic/backend-package-json-generator.js +66 -0
- package/dist/libs/instance-factories/applications/templates/generic/backend-tsconfig-generator.js +54 -0
- package/dist/libs/instance-factories/applications/templates/generic/main-generator.js +290 -0
- package/dist/libs/instance-factories/applications/templates/react/_view-components-source.js +530 -0
- package/dist/libs/instance-factories/applications/templates/react/api-client-generator.js +437 -0
- package/dist/libs/instance-factories/applications/templates/react/api-types-generator.js +146 -0
- package/dist/libs/instance-factories/applications/templates/react/app-tsx-generator.js +73 -0
- package/dist/libs/instance-factories/applications/templates/react/env-example-generator.js +18 -0
- package/dist/libs/instance-factories/applications/templates/react/field-helpers-generator.js +99 -0
- package/dist/libs/instance-factories/applications/templates/react/gitignore-generator.js +35 -0
- package/dist/libs/instance-factories/applications/templates/react/index-css-generator.js +9 -0
- package/dist/libs/instance-factories/applications/templates/react/index-html-generator.js +23 -0
- package/dist/libs/instance-factories/applications/templates/react/main-tsx-generator.js +29 -0
- package/dist/libs/instance-factories/applications/templates/react/package-json-generator.js +49 -0
- package/dist/libs/instance-factories/applications/templates/react/pattern-adapter-generator.js +156 -0
- package/dist/libs/instance-factories/applications/templates/react/react-pattern-adapter.js +935 -0
- package/dist/libs/instance-factories/applications/templates/react/relationship-field-generator.js +143 -0
- package/dist/libs/instance-factories/applications/templates/react/runtime-app-tsx-generator.js +101 -0
- package/dist/libs/instance-factories/applications/templates/react/runtime-package-json-generator.js +50 -0
- package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-generator.js +646 -0
- package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-wrapper-generator.js +65 -0
- package/dist/libs/instance-factories/applications/templates/react/tsconfig-generator.js +28 -0
- package/dist/libs/instance-factories/applications/templates/react/use-api-hooks-generator.js +132 -0
- package/dist/libs/instance-factories/applications/templates/react/view-dashboard-generator.js +143 -0
- package/dist/libs/instance-factories/applications/templates/react/view-detail-generator.js +143 -0
- package/dist/libs/instance-factories/applications/templates/react/view-form-generator.js +355 -0
- package/dist/libs/instance-factories/applications/templates/react/view-list-generator.js +91 -0
- package/dist/libs/instance-factories/applications/templates/react/view-router-generator.js +79 -0
- package/dist/libs/instance-factories/applications/templates/react/vite-config-generator.js +42 -0
- package/dist/libs/instance-factories/cli/templates/commander/cli-bin-wrapper-generator.js +11 -0
- package/dist/libs/instance-factories/cli/templates/commander/cli-entry-generator.js +111 -0
- package/dist/libs/instance-factories/cli/templates/commander/command-generator.js +928 -0
- package/dist/libs/instance-factories/communication/templates/eventemitter/bus-generator.js +83 -0
- package/dist/libs/instance-factories/communication/templates/eventemitter/publisher-generator.js +91 -0
- package/dist/libs/instance-factories/communication/templates/eventemitter/subscriber-generator.js +86 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/meta-routes-generator.js +93 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/routes-generator.js +280 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/server-generator.js +125 -0
- package/dist/libs/instance-factories/infrastructure/templates/docker-k8s/infrastructure-generator.js +25 -0
- package/dist/libs/instance-factories/orms/templates/prisma/schema-generator.js +371 -0
- package/dist/libs/instance-factories/orms/templates/prisma/services-generator.js +266 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/env-example-generator.js +51 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/env-generator.js +61 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/gitignore-generator.js +59 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/package-json-generator.js +126 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/readme-generator.js +159 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/tsconfig-generator.js +56 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/tsconfig-react-generator.js +37 -0
- package/dist/libs/instance-factories/sdks/templates/python/sdk-generator.js +29 -0
- package/dist/libs/instance-factories/sdks/templates/typescript/sdk-generator.js +28 -0
- package/dist/libs/instance-factories/services/templates/memory/generate-interpreter.js +14 -0
- package/dist/libs/instance-factories/services/templates/memory/step-conventions-memory.js +415 -0
- package/dist/libs/instance-factories/services/templates/prisma/behavior-generator.js +177 -0
- package/dist/libs/instance-factories/services/templates/prisma/controller-generator.js +413 -0
- package/dist/libs/instance-factories/services/templates/prisma/service-generator.js +243 -0
- package/dist/libs/instance-factories/services/templates/prisma/step-conventions.js +264 -0
- package/dist/libs/instance-factories/services/templates/shared-patterns.js +24 -0
- package/dist/libs/instance-factories/shared/path-resolver.js +59 -0
- package/dist/libs/instance-factories/storage/templates/mongodb/config-generator.js +13 -0
- package/dist/libs/instance-factories/storage/templates/mongodb/docker-generator.js +16 -0
- package/dist/libs/instance-factories/storage/templates/postgresql/config-generator.js +45 -0
- package/dist/libs/instance-factories/storage/templates/postgresql/docker-generator.js +46 -0
- package/dist/libs/instance-factories/storage/templates/redis/config-generator.js +14 -0
- package/dist/libs/instance-factories/storage/templates/redis/docker-generator.js +16 -0
- package/dist/libs/instance-factories/test-generation.js +145 -0
- package/dist/libs/instance-factories/testing/templates/vitest/tests-generator.js +30 -0
- package/dist/libs/instance-factories/tools/templates/mcp/mcp-server-generator.js +149 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/controllers/MCPServerController.js +232 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/events/EventEmitter.js +49 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/index.js +18 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/interfaces/ResourceProvider.js +0 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/models/LibrarySuggestion.js +97 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/models/SpecVerseResource.js +64 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/server/mcp-server.js +182 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/CLIProxyService.js +1210 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/EmbeddedResourcesAdapter.js +172 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/EntityModuleService.js +240 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/HybridResourcesProvider.js +147 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/LibraryToolsService.js +281 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorBridge.js +409 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorToolsService.js +414 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/PromptToolsService.js +467 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/ResourcesProviderService.js +135 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/types/index.js +0 -0
- package/dist/libs/instance-factories/tools/templates/vscode/static/extension.js +965 -0
- package/dist/libs/instance-factories/tools/templates/vscode/vscode-extension-generator.js +238 -0
- package/dist/libs/instance-factories/validation/templates/zod/validation-generator.js +25 -0
- package/dist/libs/instance-factories/views/index.js +48 -0
- package/dist/libs/instance-factories/views/templates/react/adapters/antd-adapter.js +742 -0
- package/dist/libs/instance-factories/views/templates/react/adapters/mui-adapter.js +824 -0
- package/dist/libs/instance-factories/views/templates/react/adapters/shadcn-adapter.js +719 -0
- package/dist/libs/instance-factories/views/templates/react/app-generator.js +45 -0
- package/dist/libs/instance-factories/views/templates/react/components-generator.js +779 -0
- package/dist/libs/instance-factories/views/templates/react/forms-generator.js +285 -0
- package/dist/libs/instance-factories/views/templates/react/frontend-package-json-generator.js +46 -0
- package/dist/libs/instance-factories/views/templates/react/hooks-generator.js +111 -0
- package/dist/libs/instance-factories/views/templates/react/index-css-generator.js +9 -0
- package/dist/libs/instance-factories/views/templates/react/index-html-generator.js +23 -0
- package/dist/libs/instance-factories/views/templates/react/main-tsx-generator.js +21 -0
- package/dist/libs/instance-factories/views/templates/react/react-component-generator.js +299 -0
- package/dist/libs/instance-factories/views/templates/react/router-generator.js +136 -0
- package/dist/libs/instance-factories/views/templates/react/router-generic-generator.js +107 -0
- package/dist/libs/instance-factories/views/templates/react/shared-utils-generator.js +179 -0
- package/dist/libs/instance-factories/views/templates/react/spec-json-generator.js +7 -0
- package/dist/libs/instance-factories/views/templates/react/types-generator.js +56 -0
- package/dist/libs/instance-factories/views/templates/react/views-metadata-generator.js +27 -0
- package/dist/libs/instance-factories/views/templates/react/vite-config-generator.js +29 -0
- package/dist/libs/instance-factories/views/templates/runtime/runtime-view-renderer.js +261 -0
- package/dist/libs/instance-factories/views/templates/shared/adapter-types.js +34 -0
- package/dist/libs/instance-factories/views/templates/shared/atomic-components-registry.js +800 -0
- package/dist/libs/instance-factories/views/templates/shared/base-generator.js +305 -0
- package/dist/libs/instance-factories/views/templates/shared/component-metadata.js +517 -0
- package/dist/libs/instance-factories/views/templates/shared/composite-pattern-types.js +0 -0
- package/dist/libs/instance-factories/views/templates/shared/composite-patterns.js +445 -0
- package/dist/libs/instance-factories/views/templates/shared/index.js +80 -0
- package/dist/libs/instance-factories/views/templates/shared/pattern-validator.js +210 -0
- package/dist/libs/instance-factories/views/templates/shared/property-mapper.js +492 -0
- package/dist/libs/instance-factories/views/templates/shared/syntax-mapper.js +321 -0
- package/dist/realize/index.js +36 -12
- package/dist/realize/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "fs";
|
|
2
|
+
import { join, dirname } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
async function generate(context) {
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = dirname(__filename);
|
|
7
|
+
const possiblePaths = [
|
|
8
|
+
// PRIORITY 1: Bundled with package (in libs/ directory)
|
|
9
|
+
join(__dirname, "../../../../../../libs/instance-factories/applications/templates/react/tailwind-adapter-generator.ts"),
|
|
10
|
+
// PRIORITY 2: Development environment (local)
|
|
11
|
+
join(__dirname, "./tailwind-adapter-generator.ts"),
|
|
12
|
+
join(__dirname, "../tailwind-adapter-generator.ts")
|
|
13
|
+
];
|
|
14
|
+
let adapterSource = null;
|
|
15
|
+
let foundPath = null;
|
|
16
|
+
for (const path of possiblePaths) {
|
|
17
|
+
if (existsSync(path)) {
|
|
18
|
+
try {
|
|
19
|
+
adapterSource = readFileSync(path, "utf-8");
|
|
20
|
+
foundPath = path;
|
|
21
|
+
break;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (adapterSource) {
|
|
27
|
+
return `/**
|
|
28
|
+
* Universal Tailwind Adapter Generator
|
|
29
|
+
*
|
|
30
|
+
* AUTO-GENERATED: Copied from @specverse/lang
|
|
31
|
+
* Source: ${foundPath}
|
|
32
|
+
*
|
|
33
|
+
* This file provides Tailwind CSS rendering for all atomic component types.
|
|
34
|
+
* It is imported by react-pattern-adapter.tsx.
|
|
35
|
+
*
|
|
36
|
+
* DO NOT EDIT: Changes will be overwritten on next generation.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
${adapterSource}
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
42
|
+
return `/**
|
|
43
|
+
* Tailwind Adapter Generator (STUB)
|
|
44
|
+
*
|
|
45
|
+
* \u26A0\uFE0F WARNING: Could not locate tailwind-adapter-generator.ts source file.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
import type { ComponentAdapter } from '@specverse/lang';
|
|
49
|
+
|
|
50
|
+
export function createUniversalTailwindAdapter(): ComponentAdapter {
|
|
51
|
+
return {
|
|
52
|
+
renderComponent(type: string, properties: Record<string, any> = {}, children?: string): string {
|
|
53
|
+
return \`<div class="p-4 border border-gray-300 rounded bg-gray-50">
|
|
54
|
+
<span class="text-gray-700">\${type}</span>
|
|
55
|
+
</div>\`;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.warn('\u26A0\uFE0F Using stub Tailwind adapter - full source file not found during generation');
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
generate
|
|
65
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function generateTsConfig(context) {
|
|
2
|
+
return JSON.stringify({
|
|
3
|
+
compilerOptions: {
|
|
4
|
+
target: "ES2020",
|
|
5
|
+
useDefineForClassFields: true,
|
|
6
|
+
lib: ["ES2020", "DOM", "DOM.Iterable"],
|
|
7
|
+
module: "ESNext",
|
|
8
|
+
skipLibCheck: true,
|
|
9
|
+
types: ["vite/client"],
|
|
10
|
+
/* Bundler mode */
|
|
11
|
+
moduleResolution: "bundler",
|
|
12
|
+
allowImportingTsExtensions: true,
|
|
13
|
+
resolveJsonModule: true,
|
|
14
|
+
isolatedModules: true,
|
|
15
|
+
noEmit: true,
|
|
16
|
+
jsx: "react-jsx",
|
|
17
|
+
/* Linting */
|
|
18
|
+
strict: true,
|
|
19
|
+
noUnusedLocals: true,
|
|
20
|
+
noUnusedParameters: true,
|
|
21
|
+
noFallthroughCasesInSwitch: true
|
|
22
|
+
},
|
|
23
|
+
include: ["src"]
|
|
24
|
+
}, null, 2);
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
generateTsConfig as default
|
|
28
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
async function generate(context) {
|
|
2
|
+
return `/**
|
|
3
|
+
* useApi - React Query Hooks
|
|
4
|
+
*
|
|
5
|
+
* Hooks match the @specverse/runtime RuntimeViewProviderValue contract.
|
|
6
|
+
* These are passed to RuntimeViewProvider and called by runtime components.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
10
|
+
import {
|
|
11
|
+
getModelSchema,
|
|
12
|
+
listEntities,
|
|
13
|
+
executeOperation,
|
|
14
|
+
transitionState
|
|
15
|
+
} from '../lib/apiClient';
|
|
16
|
+
import type { ModelSchema, Entity, ApiResponse } from '../types/api';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Query hook for model schema
|
|
20
|
+
*/
|
|
21
|
+
export function useModelSchemaQuery(modelName: string | null) {
|
|
22
|
+
return useQuery({
|
|
23
|
+
queryKey: ['modelSchema', modelName],
|
|
24
|
+
queryFn: async (): Promise<ModelSchema> => {
|
|
25
|
+
if (!modelName) throw new Error('Model name is required');
|
|
26
|
+
return await getModelSchema(modelName);
|
|
27
|
+
},
|
|
28
|
+
enabled: !!modelName,
|
|
29
|
+
staleTime: 5 * 60 * 1000,
|
|
30
|
+
refetchOnWindowFocus: false
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Query hook for entities
|
|
36
|
+
*/
|
|
37
|
+
export function useEntitiesQuery(controllerName: string | null, modelName: string | null) {
|
|
38
|
+
return useQuery({
|
|
39
|
+
queryKey: ['entities', modelName],
|
|
40
|
+
queryFn: async (): Promise<Entity[]> => {
|
|
41
|
+
if (!controllerName || !modelName) {
|
|
42
|
+
throw new Error('Controller and model names are required');
|
|
43
|
+
}
|
|
44
|
+
return await listEntities(controllerName);
|
|
45
|
+
},
|
|
46
|
+
enabled: !!controllerName && !!modelName,
|
|
47
|
+
refetchInterval: 5000
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Mutation hook for executing operations
|
|
53
|
+
* Matches RuntimeViewProviderValue.useExecuteOperationMutation contract:
|
|
54
|
+
* { controllerName, operationName, data, entityId? }
|
|
55
|
+
*/
|
|
56
|
+
export function useExecuteOperationMutation() {
|
|
57
|
+
const queryClient = useQueryClient();
|
|
58
|
+
|
|
59
|
+
return useMutation({
|
|
60
|
+
mutationFn: ({
|
|
61
|
+
controllerName,
|
|
62
|
+
operationName,
|
|
63
|
+
data,
|
|
64
|
+
params,
|
|
65
|
+
entityId
|
|
66
|
+
}: {
|
|
67
|
+
controllerName: string;
|
|
68
|
+
operationName: string;
|
|
69
|
+
data?: Record<string, any>;
|
|
70
|
+
params?: Record<string, any>;
|
|
71
|
+
entityId?: string;
|
|
72
|
+
}): Promise<ApiResponse> => {
|
|
73
|
+
// Merge: accept both 'data' and 'params' for compatibility
|
|
74
|
+
const mergedParams = { ...(data || params || {}) };
|
|
75
|
+
if (entityId) mergedParams.id = entityId;
|
|
76
|
+
return executeOperation(controllerName, operationName, mergedParams);
|
|
77
|
+
},
|
|
78
|
+
onSuccess: (_data, variables) => {
|
|
79
|
+
const modelName = variables.controllerName.replace(/Controller$/, '');
|
|
80
|
+
queryClient.invalidateQueries({ queryKey: ['entities', modelName] });
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Mutation hook for lifecycle transitions
|
|
87
|
+
* Matches RuntimeViewProviderValue.useTransitionStateMutation contract:
|
|
88
|
+
* { controllerName, entityId, targetState }
|
|
89
|
+
*/
|
|
90
|
+
export function useTransitionStateMutation() {
|
|
91
|
+
const queryClient = useQueryClient();
|
|
92
|
+
|
|
93
|
+
return useMutation({
|
|
94
|
+
mutationFn: ({
|
|
95
|
+
controllerName,
|
|
96
|
+
modelName,
|
|
97
|
+
entityId,
|
|
98
|
+
targetState,
|
|
99
|
+
toState,
|
|
100
|
+
lifecycleName
|
|
101
|
+
}: {
|
|
102
|
+
controllerName?: string;
|
|
103
|
+
modelName?: string;
|
|
104
|
+
entityId: string;
|
|
105
|
+
targetState?: string;
|
|
106
|
+
toState?: string;
|
|
107
|
+
lifecycleName?: string;
|
|
108
|
+
}): Promise<ApiResponse> => {
|
|
109
|
+
// Accept both field names for compatibility
|
|
110
|
+
const model = modelName || controllerName?.replace(/Controller$/, '') || '';
|
|
111
|
+
const state = targetState || toState || '';
|
|
112
|
+
return transitionState(model, entityId, state, lifecycleName);
|
|
113
|
+
},
|
|
114
|
+
onSuccess: (_data, variables) => {
|
|
115
|
+
const model = variables.modelName || variables.controllerName?.replace(/Controller$/, '') || '';
|
|
116
|
+
queryClient.invalidateQueries({ queryKey: ['entities', model] });
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Hook for invalidating all queries
|
|
123
|
+
*/
|
|
124
|
+
export function useInvalidateAll() {
|
|
125
|
+
const queryClient = useQueryClient();
|
|
126
|
+
return () => queryClient.invalidateQueries();
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
}
|
|
130
|
+
export {
|
|
131
|
+
generate
|
|
132
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
async function generate(context) {
|
|
2
|
+
return `/**
|
|
3
|
+
* DashboardView - Pattern-Based Dashboard View Component
|
|
4
|
+
*
|
|
5
|
+
* Uses pattern-based rendering with ReactPatternAdapter.
|
|
6
|
+
* Supports multi-component dashboard layouts with entity selection.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useState, useEffect, useMemo } from 'react';
|
|
10
|
+
import { useEntitiesQuery, useModelSchemaQuery } from '../../hooks/useApi';
|
|
11
|
+
import { usePatternAdapter, REACT_PROTOCOL_MAPPING } from '../../lib/react-pattern-adapter';
|
|
12
|
+
import type { View } from '../../types/api';
|
|
13
|
+
|
|
14
|
+
interface DashboardViewProps {
|
|
15
|
+
view: View;
|
|
16
|
+
spec?: any;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function DashboardView({ view, spec }: DashboardViewProps) {
|
|
20
|
+
const patternAdapter = usePatternAdapter();
|
|
21
|
+
|
|
22
|
+
// Determine controller and model
|
|
23
|
+
let controllerName: string;
|
|
24
|
+
let modelName: string;
|
|
25
|
+
|
|
26
|
+
if (view.controller && spec) {
|
|
27
|
+
controllerName = view.controller;
|
|
28
|
+
const controller = spec.controllers[view.controller];
|
|
29
|
+
modelName = controller.model;
|
|
30
|
+
} else {
|
|
31
|
+
modelName = view.model as string;
|
|
32
|
+
controllerName = \`\${modelName}Controller\`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Fetch data and schema
|
|
36
|
+
const { data: entities = [] } = useEntitiesQuery(controllerName, modelName);
|
|
37
|
+
const { data: schema } = useModelSchemaQuery(modelName);
|
|
38
|
+
|
|
39
|
+
// Track selected entity
|
|
40
|
+
const [selectedEntityId, setSelectedEntityId] = useState<string | null>(
|
|
41
|
+
entities.length > 0 ? entities[0].id : null
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Update selected entity when entities change
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (entities.length > 0 && !selectedEntityId) {
|
|
47
|
+
setSelectedEntityId(entities[0].id);
|
|
48
|
+
}
|
|
49
|
+
}, [entities, selectedEntityId]);
|
|
50
|
+
|
|
51
|
+
// Get selected entity
|
|
52
|
+
const selectedEntity = useMemo(
|
|
53
|
+
() => entities.find((e: any) => e.id === selectedEntityId) || null,
|
|
54
|
+
[entities, selectedEntityId]
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// Build model data and schemas
|
|
58
|
+
const modelData = useMemo(() => ({
|
|
59
|
+
[modelName]: entities
|
|
60
|
+
}), [modelName, entities]);
|
|
61
|
+
|
|
62
|
+
const modelSchemas = useMemo(() =>
|
|
63
|
+
schema ? { [modelName]: schema } : {}
|
|
64
|
+
, [modelName, schema]);
|
|
65
|
+
|
|
66
|
+
if (entities.length === 0) {
|
|
67
|
+
return <div className="p-4">No entities found</div>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Detect pattern
|
|
71
|
+
const pattern = patternAdapter.detectPattern({ ...view, type: 'dashboard' });
|
|
72
|
+
|
|
73
|
+
if (!pattern) {
|
|
74
|
+
return (
|
|
75
|
+
<div className="p-4 text-red-600">
|
|
76
|
+
Pattern not found for dashboard view
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Build render context
|
|
82
|
+
const context = {
|
|
83
|
+
pattern,
|
|
84
|
+
viewSpec: { ...view, type: 'dashboard', model: modelName },
|
|
85
|
+
modelData,
|
|
86
|
+
modelSchemas,
|
|
87
|
+
primaryModel: modelName,
|
|
88
|
+
selectedEntity,
|
|
89
|
+
primaryEntities: entities,
|
|
90
|
+
protocolMapping: REACT_PROTOCOL_MAPPING,
|
|
91
|
+
tailwindAdapter: patternAdapter['tailwindAdapter']
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Render entity selector
|
|
95
|
+
let html = '';
|
|
96
|
+
if (entities.length > 0) {
|
|
97
|
+
html += \`
|
|
98
|
+
<div class="mb-4 pb-4 border-b border-gray-200 dark:border-gray-700">
|
|
99
|
+
<label class="block text-sm font-semibold text-gray-700 dark:text-gray-200 mb-2">
|
|
100
|
+
Select \${modelName}:
|
|
101
|
+
</label>
|
|
102
|
+
<select
|
|
103
|
+
id="entity-selector"
|
|
104
|
+
class="w-full max-w-md px-3 py-2 border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
105
|
+
>
|
|
106
|
+
\${entities.map((entity: any) => {
|
|
107
|
+
const displayName = entity.data?.name || entity.data?.title || entity.id;
|
|
108
|
+
return \`<option value="\${entity.id}" \${entity.id === selectedEntityId ? 'selected' : ''}>\${displayName}</option>\`;
|
|
109
|
+
}).join('')}
|
|
110
|
+
</select>
|
|
111
|
+
</div>
|
|
112
|
+
\`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Render pattern
|
|
116
|
+
html += patternAdapter.renderPattern(context);
|
|
117
|
+
|
|
118
|
+
// Add event handler for selector
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
const selector = document.getElementById('entity-selector') as HTMLSelectElement;
|
|
121
|
+
if (selector) {
|
|
122
|
+
const handler = (e: Event) => {
|
|
123
|
+
const newId = (e.target as HTMLSelectElement).value;
|
|
124
|
+
setSelectedEntityId(newId);
|
|
125
|
+
};
|
|
126
|
+
selector.addEventListener('change', handler);
|
|
127
|
+
return () => selector.removeEventListener('change', handler);
|
|
128
|
+
}
|
|
129
|
+
}, [html]);
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<div className="runtime-view-container p-4 h-full overflow-auto">
|
|
133
|
+
<div dangerouslySetInnerHTML={{ __html: html }} />
|
|
134
|
+
</div>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export default DashboardView;
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
generate
|
|
143
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
async function generate(context) {
|
|
2
|
+
return `/**
|
|
3
|
+
* DetailView - Pattern-Based Detail View Component
|
|
4
|
+
*
|
|
5
|
+
* Uses pattern-based rendering with ReactPatternAdapter.
|
|
6
|
+
* Supports entity selection and relationship display.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useState, useEffect, useMemo } from 'react';
|
|
10
|
+
import { useEntitiesQuery, useModelSchemaQuery } from '../../hooks/useApi';
|
|
11
|
+
import { usePatternAdapter, REACT_PROTOCOL_MAPPING } from '../../lib/react-pattern-adapter';
|
|
12
|
+
import type { View } from '../../types/api';
|
|
13
|
+
|
|
14
|
+
interface DetailViewProps {
|
|
15
|
+
view: View;
|
|
16
|
+
spec?: any;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function DetailView({ view, spec }: DetailViewProps) {
|
|
20
|
+
const patternAdapter = usePatternAdapter();
|
|
21
|
+
|
|
22
|
+
// Determine controller and model
|
|
23
|
+
let controllerName: string;
|
|
24
|
+
let modelName: string;
|
|
25
|
+
|
|
26
|
+
if (view.controller && spec) {
|
|
27
|
+
controllerName = view.controller;
|
|
28
|
+
const controller = spec.controllers[view.controller];
|
|
29
|
+
modelName = controller.model;
|
|
30
|
+
} else {
|
|
31
|
+
modelName = view.model as string;
|
|
32
|
+
controllerName = \`\${modelName}Controller\`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Fetch data and schema
|
|
36
|
+
const { data: entities = [] } = useEntitiesQuery(controllerName, modelName);
|
|
37
|
+
const { data: schema } = useModelSchemaQuery(modelName);
|
|
38
|
+
|
|
39
|
+
// Track selected entity
|
|
40
|
+
const [selectedEntityId, setSelectedEntityId] = useState<string | null>(
|
|
41
|
+
entities.length > 0 ? entities[0].id : null
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Update selected entity when entities change
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (entities.length > 0 && !selectedEntityId) {
|
|
47
|
+
setSelectedEntityId(entities[0].id);
|
|
48
|
+
}
|
|
49
|
+
}, [entities, selectedEntityId]);
|
|
50
|
+
|
|
51
|
+
// Get selected entity
|
|
52
|
+
const selectedEntity = useMemo(
|
|
53
|
+
() => entities.find((e: any) => e.id === selectedEntityId) || null,
|
|
54
|
+
[entities, selectedEntityId]
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// Build model data and schemas
|
|
58
|
+
const modelData = useMemo(() => ({
|
|
59
|
+
[modelName]: entities
|
|
60
|
+
}), [modelName, entities]);
|
|
61
|
+
|
|
62
|
+
const modelSchemas = useMemo(() =>
|
|
63
|
+
schema ? { [modelName]: schema } : {}
|
|
64
|
+
, [modelName, schema]);
|
|
65
|
+
|
|
66
|
+
if (entities.length === 0) {
|
|
67
|
+
return <div className="p-4">No entities found</div>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Detect pattern
|
|
71
|
+
const pattern = patternAdapter.detectPattern({ ...view, type: 'detail' });
|
|
72
|
+
|
|
73
|
+
if (!pattern) {
|
|
74
|
+
return (
|
|
75
|
+
<div className="p-4 text-red-600">
|
|
76
|
+
Pattern not found for detail view
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Build render context
|
|
82
|
+
const context = {
|
|
83
|
+
pattern,
|
|
84
|
+
viewSpec: { ...view, type: 'detail', model: modelName },
|
|
85
|
+
modelData,
|
|
86
|
+
modelSchemas,
|
|
87
|
+
primaryModel: modelName,
|
|
88
|
+
selectedEntity,
|
|
89
|
+
primaryEntities: entities,
|
|
90
|
+
protocolMapping: REACT_PROTOCOL_MAPPING,
|
|
91
|
+
tailwindAdapter: patternAdapter['tailwindAdapter']
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Render entity selector
|
|
95
|
+
let html = '';
|
|
96
|
+
if (entities.length > 0) {
|
|
97
|
+
html += \`
|
|
98
|
+
<div class="mb-4 pb-4 border-b border-gray-200 dark:border-gray-700">
|
|
99
|
+
<label class="block text-sm font-semibold text-gray-700 dark:text-gray-200 mb-2">
|
|
100
|
+
Select \${modelName}:
|
|
101
|
+
</label>
|
|
102
|
+
<select
|
|
103
|
+
id="entity-selector"
|
|
104
|
+
class="w-full max-w-md px-3 py-2 border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
105
|
+
>
|
|
106
|
+
\${entities.map((entity: any) => {
|
|
107
|
+
const displayName = entity.data?.name || entity.data?.title || entity.id;
|
|
108
|
+
return \`<option value="\${entity.id}" \${entity.id === selectedEntityId ? 'selected' : ''}>\${displayName}</option>\`;
|
|
109
|
+
}).join('')}
|
|
110
|
+
</select>
|
|
111
|
+
</div>
|
|
112
|
+
\`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Render pattern
|
|
116
|
+
html += patternAdapter.renderPattern(context);
|
|
117
|
+
|
|
118
|
+
// Add event handler for selector
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
const selector = document.getElementById('entity-selector') as HTMLSelectElement;
|
|
121
|
+
if (selector) {
|
|
122
|
+
const handler = (e: Event) => {
|
|
123
|
+
const newId = (e.target as HTMLSelectElement).value;
|
|
124
|
+
setSelectedEntityId(newId);
|
|
125
|
+
};
|
|
126
|
+
selector.addEventListener('change', handler);
|
|
127
|
+
return () => selector.removeEventListener('change', handler);
|
|
128
|
+
}
|
|
129
|
+
}, [html]);
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<div className="runtime-view-container p-4 h-full overflow-auto">
|
|
133
|
+
<div dangerouslySetInnerHTML={{ __html: html }} />
|
|
134
|
+
</div>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export default DetailView;
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
generate
|
|
143
|
+
};
|