meno-core 1.0.0
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/bin/cli.ts +281 -0
- package/build-static.ts +298 -0
- package/bunfig.toml +39 -0
- package/entries/client-router.tsx +111 -0
- package/entries/server-router.tsx +71 -0
- package/lib/client/ClientInitializer.test.ts +9 -0
- package/lib/client/ClientInitializer.test.ts.skip +92 -0
- package/lib/client/ClientInitializer.ts +60 -0
- package/lib/client/ErrorBoundary.test.tsx +595 -0
- package/lib/client/ErrorBoundary.tsx +230 -0
- package/lib/client/componentRegistry.test.ts +165 -0
- package/lib/client/componentRegistry.ts +18 -0
- package/lib/client/contexts/ThemeContext.tsx +73 -0
- package/lib/client/core/ComponentBuilder.test.ts +677 -0
- package/lib/client/core/ComponentBuilder.ts +660 -0
- package/lib/client/core/ComponentRenderer.test.tsx +176 -0
- package/lib/client/core/ComponentRenderer.tsx +83 -0
- package/lib/client/core/cmsTemplateProcessor.ts +129 -0
- package/lib/client/elementRegistry.ts +81 -0
- package/lib/client/hmr/HMRManager.tsx +179 -0
- package/lib/client/hmr/index.ts +5 -0
- package/lib/client/hmrWebSocket.test.ts +9 -0
- package/lib/client/hmrWebSocket.ts +250 -0
- package/lib/client/hooks/useColorVariables.test.ts +166 -0
- package/lib/client/hooks/useColorVariables.ts +249 -0
- package/lib/client/hooks/usePropertyAutocomplete.test.ts +9 -0
- package/lib/client/hooks/usePropertyAutocomplete.ts +40 -0
- package/lib/client/hydration/HydrationUtils.test.ts +154 -0
- package/lib/client/hydration/HydrationUtils.ts +35 -0
- package/lib/client/i18nConfigService.test.ts +74 -0
- package/lib/client/i18nConfigService.ts +78 -0
- package/lib/client/index.ts +56 -0
- package/lib/client/navigation.test.ts +441 -0
- package/lib/client/navigation.ts +23 -0
- package/lib/client/responsiveStyleResolver.test.ts +491 -0
- package/lib/client/responsiveStyleResolver.ts +184 -0
- package/lib/client/routing/RouteLoader.test.ts +635 -0
- package/lib/client/routing/RouteLoader.ts +347 -0
- package/lib/client/routing/Router.tsx +382 -0
- package/lib/client/scripts/ScriptExecutor.test.ts +489 -0
- package/lib/client/scripts/ScriptExecutor.ts +171 -0
- package/lib/client/scripts/formHandler.ts +103 -0
- package/lib/client/styleProcessor.test.ts +126 -0
- package/lib/client/styleProcessor.ts +92 -0
- package/lib/client/styles/StyleInjector.test.ts +354 -0
- package/lib/client/styles/StyleInjector.ts +154 -0
- package/lib/client/templateEngine.test.ts +660 -0
- package/lib/client/templateEngine.ts +667 -0
- package/lib/client/theme.test.ts +173 -0
- package/lib/client/theme.ts +159 -0
- package/lib/client/utils/toast.ts +46 -0
- package/lib/server/createServer.ts +170 -0
- package/lib/server/cssGenerator.test.ts +172 -0
- package/lib/server/cssGenerator.ts +58 -0
- package/lib/server/fileWatcher.ts +134 -0
- package/lib/server/index.ts +55 -0
- package/lib/server/jsonLoader.test.ts +103 -0
- package/lib/server/jsonLoader.ts +350 -0
- package/lib/server/middleware/cors.test.ts +177 -0
- package/lib/server/middleware/cors.ts +69 -0
- package/lib/server/middleware/errorHandler.test.ts +208 -0
- package/lib/server/middleware/errorHandler.ts +63 -0
- package/lib/server/middleware/index.ts +9 -0
- package/lib/server/middleware/logger.test.ts +233 -0
- package/lib/server/middleware/logger.ts +99 -0
- package/lib/server/pageCache.test.ts +167 -0
- package/lib/server/pageCache.ts +97 -0
- package/lib/server/projectContext.ts +51 -0
- package/lib/server/providers/fileSystemCMSProvider.test.ts +292 -0
- package/lib/server/providers/fileSystemCMSProvider.ts +227 -0
- package/lib/server/providers/fileSystemPageProvider.ts +83 -0
- package/lib/server/routes/api/cms.test.ts +177 -0
- package/lib/server/routes/api/cms.ts +82 -0
- package/lib/server/routes/api/colors.ts +59 -0
- package/lib/server/routes/api/components.ts +70 -0
- package/lib/server/routes/api/config.test.ts +9 -0
- package/lib/server/routes/api/config.ts +28 -0
- package/lib/server/routes/api/core-routes.ts +182 -0
- package/lib/server/routes/api/functions.ts +170 -0
- package/lib/server/routes/api/index.ts +69 -0
- package/lib/server/routes/api/pages.ts +95 -0
- package/lib/server/routes/api/shared.test.ts +81 -0
- package/lib/server/routes/api/shared.ts +31 -0
- package/lib/server/routes/editor.test.ts +9 -0
- package/lib/server/routes/index.ts +104 -0
- package/lib/server/routes/pages.ts +161 -0
- package/lib/server/routes/static.ts +107 -0
- package/lib/server/services/ColorService.ts +193 -0
- package/lib/server/services/cmsService.test.ts +388 -0
- package/lib/server/services/cmsService.ts +296 -0
- package/lib/server/services/componentService.test.ts +276 -0
- package/lib/server/services/componentService.ts +346 -0
- package/lib/server/services/configService.ts +156 -0
- package/lib/server/services/fileWatcherService.ts +67 -0
- package/lib/server/services/index.ts +10 -0
- package/lib/server/services/pageService.test.ts +258 -0
- package/lib/server/services/pageService.ts +240 -0
- package/lib/server/ssrRenderer.test.ts +1005 -0
- package/lib/server/ssrRenderer.ts +878 -0
- package/lib/server/utilityClassGenerator.ts +11 -0
- package/lib/server/utils/index.ts +5 -0
- package/lib/server/utils/jsonLineMapper.test.ts +100 -0
- package/lib/server/utils/jsonLineMapper.ts +166 -0
- package/lib/server/validateStyleCoverage.test.ts +9 -0
- package/lib/server/validateStyleCoverage.ts +167 -0
- package/lib/server/websocketManager.test.ts +9 -0
- package/lib/server/websocketManager.ts +95 -0
- package/lib/shared/attributeNodeUtils.test.ts +152 -0
- package/lib/shared/attributeNodeUtils.ts +50 -0
- package/lib/shared/breakpoints.test.ts +166 -0
- package/lib/shared/breakpoints.ts +65 -0
- package/lib/shared/colorProperties.test.ts +111 -0
- package/lib/shared/colorProperties.ts +40 -0
- package/lib/shared/colorVariableUtils.test.ts +319 -0
- package/lib/shared/colorVariableUtils.ts +97 -0
- package/lib/shared/constants.test.ts +175 -0
- package/lib/shared/constants.ts +116 -0
- package/lib/shared/cssGeneration.ts +481 -0
- package/lib/shared/cssProperties.test.ts +252 -0
- package/lib/shared/cssProperties.ts +338 -0
- package/lib/shared/elementUtils.test.ts +245 -0
- package/lib/shared/elementUtils.ts +90 -0
- package/lib/shared/fontLoader.ts +97 -0
- package/lib/shared/i18n.test.ts +313 -0
- package/lib/shared/i18n.ts +286 -0
- package/lib/shared/index.ts +50 -0
- package/lib/shared/interfaces/contentProvider.test.ts +9 -0
- package/lib/shared/interfaces/contentProvider.ts +121 -0
- package/lib/shared/nodeUtils.test.ts +320 -0
- package/lib/shared/nodeUtils.ts +220 -0
- package/lib/shared/pathArrayUtils.test.ts +315 -0
- package/lib/shared/pathArrayUtils.ts +17 -0
- package/lib/shared/pathUtils.test.ts +260 -0
- package/lib/shared/pathUtils.ts +244 -0
- package/lib/shared/paths/Path.test.ts +74 -0
- package/lib/shared/paths/Path.ts +23 -0
- package/lib/shared/paths/PathConverter.test.ts +232 -0
- package/lib/shared/paths/PathConverter.ts +141 -0
- package/lib/shared/paths/PathUtils.ts +290 -0
- package/lib/shared/paths/PathValidator.test.ts +193 -0
- package/lib/shared/paths/PathValidator.ts +53 -0
- package/lib/shared/paths/index.ts +48 -0
- package/lib/shared/propResolver.test.ts +639 -0
- package/lib/shared/propResolver.ts +124 -0
- package/lib/shared/registry/BaseNodeTypeRegistry.test.ts +190 -0
- package/lib/shared/registry/BaseNodeTypeRegistry.ts +200 -0
- package/lib/shared/registry/ClientNodeTypeRegistry.ts +34 -0
- package/lib/shared/registry/ClientRegistry.test.ts +26 -0
- package/lib/shared/registry/ClientRegistry.ts +15 -0
- package/lib/shared/registry/ComponentRegistry.test.ts +293 -0
- package/lib/shared/registry/ComponentRegistry.ts +100 -0
- package/lib/shared/registry/NodeTypeDefinition.ts +198 -0
- package/lib/shared/registry/NodeTypeManager.ts +94 -0
- package/lib/shared/registry/RegistryManager.test.ts +58 -0
- package/lib/shared/registry/RegistryManager.ts +60 -0
- package/lib/shared/registry/SSRNodeTypeRegistry.ts +33 -0
- package/lib/shared/registry/SSRRegistry.test.ts +26 -0
- package/lib/shared/registry/SSRRegistry.ts +15 -0
- package/lib/shared/registry/createNodeType.ts +175 -0
- package/lib/shared/registry/defineNodeType.ts +73 -0
- package/lib/shared/registry/fieldPresets.ts +109 -0
- package/lib/shared/registry/index.ts +50 -0
- package/lib/shared/registry/nodeTypes/ComponentInstanceNodeType.ts +71 -0
- package/lib/shared/registry/nodeTypes/EmbedNodeType.ts +61 -0
- package/lib/shared/registry/nodeTypes/HtmlNodeType.ts +88 -0
- package/lib/shared/registry/nodeTypes/LocaleListNodeType.ts +66 -0
- package/lib/shared/registry/nodeTypes/ObjectLinkNodeType.ts +75 -0
- package/lib/shared/registry/nodeTypes/SlotMarkerType.ts +49 -0
- package/lib/shared/registry/nodeTypes/TextNodeType.ts +52 -0
- package/lib/shared/registry/nodeTypes/index.ts +75 -0
- package/lib/shared/responsiveScaling.test.ts +268 -0
- package/lib/shared/responsiveScaling.ts +194 -0
- package/lib/shared/responsiveStyleUtils.test.ts +300 -0
- package/lib/shared/responsiveStyleUtils.ts +139 -0
- package/lib/shared/slugTranslator.test.ts +325 -0
- package/lib/shared/slugTranslator.ts +177 -0
- package/lib/shared/styleNodeUtils.test.ts +132 -0
- package/lib/shared/styleNodeUtils.ts +102 -0
- package/lib/shared/styleUtils.test.ts +238 -0
- package/lib/shared/styleUtils.ts +63 -0
- package/lib/shared/themeDefaults.test.ts +113 -0
- package/lib/shared/themeDefaults.ts +103 -0
- package/lib/shared/tree/PathBuilder.ts +383 -0
- package/lib/shared/treePathUtils.test.ts +539 -0
- package/lib/shared/treePathUtils.ts +339 -0
- package/lib/shared/types/api.ts +58 -0
- package/lib/shared/types/cms.ts +95 -0
- package/lib/shared/types/colors.ts +45 -0
- package/lib/shared/types/components.ts +121 -0
- package/lib/shared/types/errors.test.ts +103 -0
- package/lib/shared/types/errors.ts +69 -0
- package/lib/shared/types/index.ts +96 -0
- package/lib/shared/types/nodes.ts +20 -0
- package/lib/shared/types/rendering.ts +61 -0
- package/lib/shared/types/styles.ts +38 -0
- package/lib/shared/types.ts +11 -0
- package/lib/shared/utilityClassConfig.ts +287 -0
- package/lib/shared/utilityClassMapper.test.ts +140 -0
- package/lib/shared/utilityClassMapper.ts +229 -0
- package/lib/shared/utils/fileUtils.test.ts +99 -0
- package/lib/shared/utils/fileUtils.ts +56 -0
- package/lib/shared/utils.test.ts +261 -0
- package/lib/shared/utils.ts +84 -0
- package/lib/shared/validation/index.ts +7 -0
- package/lib/shared/validation/propValidator.test.ts +178 -0
- package/lib/shared/validation/propValidator.ts +238 -0
- package/lib/shared/validation/schemas.test.ts +177 -0
- package/lib/shared/validation/schemas.ts +401 -0
- package/lib/shared/validation/validators.test.ts +109 -0
- package/lib/shared/validation/validators.ts +304 -0
- package/lib/test-utils/dom-setup.ts +55 -0
- package/lib/test-utils/factories/ConsoleMockFactory.ts +200 -0
- package/lib/test-utils/factories/DomMockFactory.ts +487 -0
- package/lib/test-utils/factories/EventMockFactory.ts +244 -0
- package/lib/test-utils/factories/FetchMockFactory.ts +210 -0
- package/lib/test-utils/factories/ServerMockFactory.ts +223 -0
- package/lib/test-utils/factories/StoreMockFactory.ts +370 -0
- package/lib/test-utils/factories/index.ts +11 -0
- package/lib/test-utils/fixtures.ts +134 -0
- package/lib/test-utils/helpers/asyncHelpers.test.ts +112 -0
- package/lib/test-utils/helpers/asyncHelpers.ts +196 -0
- package/lib/test-utils/helpers/index.ts +6 -0
- package/lib/test-utils/helpers.test.ts +73 -0
- package/lib/test-utils/helpers.ts +90 -0
- package/lib/test-utils/index.ts +17 -0
- package/lib/test-utils/mockFactories.ts +92 -0
- package/lib/test-utils/mocks.ts +341 -0
- package/package.json +38 -0
- package/templates/index-router.html +34 -0
- package/tsconfig.json +14 -0
- package/vite.config.ts +43 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style Injector
|
|
3
|
+
* Handles CSS injection from component definitions into the page
|
|
4
|
+
* Supports template processing for per-instance CSS
|
|
5
|
+
* Unified with server-side CSS generation for consistency
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ComponentRegistry } from '../componentRegistry';
|
|
9
|
+
import type { ElementRegistry } from '../elementRegistry';
|
|
10
|
+
import { hasTemplates, processCodeTemplates } from '../templateEngine';
|
|
11
|
+
import { generateUtilityCSS, extractUtilityClassesFromHTML } from '../../shared/cssGeneration';
|
|
12
|
+
import { getCachedBreakpointConfig, getCachedResponsiveScalesConfig } from '../responsiveStyleResolver';
|
|
13
|
+
import { DEFAULT_BREAKPOINTS } from '../../shared/breakpoints';
|
|
14
|
+
import { DEFAULT_RESPONSIVE_SCALES } from '../../shared/responsiveScaling';
|
|
15
|
+
|
|
16
|
+
export interface StyleInjectorConfig {
|
|
17
|
+
componentRegistry: ComponentRegistry;
|
|
18
|
+
elementRegistry: ElementRegistry;
|
|
19
|
+
styleId?: string; // Default: 'component-css'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* StyleInjector manages CSS injection from components into the page DOM
|
|
24
|
+
*
|
|
25
|
+
* Features:
|
|
26
|
+
* - Collects CSS from all registered components
|
|
27
|
+
* - Processes templates per component instance when needed
|
|
28
|
+
* - Manages style tag lifecycle (removal/recreation)
|
|
29
|
+
*/
|
|
30
|
+
export class StyleInjector {
|
|
31
|
+
private componentRegistry: ComponentRegistry;
|
|
32
|
+
private elementRegistry: ElementRegistry;
|
|
33
|
+
private styleId: string;
|
|
34
|
+
|
|
35
|
+
constructor(config: StyleInjectorConfig) {
|
|
36
|
+
this.componentRegistry = config.componentRegistry;
|
|
37
|
+
this.elementRegistry = config.elementRegistry;
|
|
38
|
+
this.styleId = config.styleId || 'component-css';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Inject CSS from all registered components into the page
|
|
43
|
+
* Processes templates per component instance if needed
|
|
44
|
+
* Also generates utility CSS from classes used in the DOM
|
|
45
|
+
*/
|
|
46
|
+
inject(): void {
|
|
47
|
+
try {
|
|
48
|
+
const allComponents = this.componentRegistry.getAll();
|
|
49
|
+
const processedCSSBlocks: string[] = [];
|
|
50
|
+
|
|
51
|
+
// Collect CSS from all components and process templates per instance
|
|
52
|
+
for (const [name, component] of Object.entries(allComponents)) {
|
|
53
|
+
if (component?.component?.css) {
|
|
54
|
+
const originalCSS = component.component.css;
|
|
55
|
+
|
|
56
|
+
// Check if CSS contains templates
|
|
57
|
+
if (hasTemplates(originalCSS)) {
|
|
58
|
+
// Process CSS for each component instance (templates need instance-specific props)
|
|
59
|
+
// Get all root paths for this component directly from registry
|
|
60
|
+
const componentRootPaths = this.elementRegistry.getComponentRootPaths(name);
|
|
61
|
+
|
|
62
|
+
// Process CSS for each instance
|
|
63
|
+
for (const rootPath of componentRootPaths) {
|
|
64
|
+
try {
|
|
65
|
+
const props = this.elementRegistry.getComponentProps(rootPath);
|
|
66
|
+
if (props) {
|
|
67
|
+
const processedCSS = processCodeTemplates(originalCSS, props);
|
|
68
|
+
processedCSSBlocks.push(`/* Component: ${name} (instance) */\n${processedCSS}`);
|
|
69
|
+
}
|
|
70
|
+
} catch (error) {
|
|
71
|
+
// Fallback to original CSS if template processing fails
|
|
72
|
+
processedCSSBlocks.push(`/* Component: ${name} */\n${originalCSS}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
// No templates - render CSS only once for all instances
|
|
77
|
+
processedCSSBlocks.push(`/* Component: ${name} */\n${originalCSS}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Generate utility CSS from classes currently used in the DOM
|
|
83
|
+
const utilityCSS = this.generateUtilityCSS();
|
|
84
|
+
if (utilityCSS) {
|
|
85
|
+
processedCSSBlocks.push(`/* Utility Classes */\n${utilityCSS}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Inject CSS into page
|
|
89
|
+
if (processedCSSBlocks.length > 0) {
|
|
90
|
+
const combinedCSS = processedCSSBlocks.join('\n\n');
|
|
91
|
+
|
|
92
|
+
// Remove existing component CSS style tag if it exists
|
|
93
|
+
const existingStyle = document.getElementById(this.styleId);
|
|
94
|
+
if (existingStyle) {
|
|
95
|
+
existingStyle.remove();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Create new style tag and append to head
|
|
99
|
+
if (document.head) {
|
|
100
|
+
const styleTag = document.createElement('style');
|
|
101
|
+
styleTag.id = this.styleId;
|
|
102
|
+
styleTag.textContent = combinedCSS;
|
|
103
|
+
document.head.appendChild(styleTag);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Generate utility CSS from classes used in the current DOM
|
|
112
|
+
* Uses shared CSS generation for consistency with static render
|
|
113
|
+
* Includes responsive scales config for auto-scaling calculations
|
|
114
|
+
*/
|
|
115
|
+
private generateUtilityCSS(): string {
|
|
116
|
+
try {
|
|
117
|
+
// Get the root element where components are rendered
|
|
118
|
+
const rootElement = document.getElementById('root') || document.body;
|
|
119
|
+
if (!rootElement) return '';
|
|
120
|
+
|
|
121
|
+
// Extract all utility classes from the rendered DOM
|
|
122
|
+
const usedClasses = extractUtilityClassesFromHTML(rootElement.innerHTML);
|
|
123
|
+
if (usedClasses.size === 0) return '';
|
|
124
|
+
|
|
125
|
+
// Get cached configs (or use defaults if not yet loaded)
|
|
126
|
+
const breakpointConfig = getCachedBreakpointConfig() || DEFAULT_BREAKPOINTS;
|
|
127
|
+
const responsiveScalesConfig = getCachedResponsiveScalesConfig() || DEFAULT_RESPONSIVE_SCALES;
|
|
128
|
+
|
|
129
|
+
// Generate CSS for the extracted classes using shared utility
|
|
130
|
+
// Pass both breakpoint and responsive scales config for consistency with SSR
|
|
131
|
+
return generateUtilityCSS(usedClasses, breakpointConfig, responsiveScalesConfig);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
return '';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Remove the injected style tag
|
|
139
|
+
*/
|
|
140
|
+
clear(): void {
|
|
141
|
+
const existingStyle = document.getElementById(this.styleId);
|
|
142
|
+
if (existingStyle) {
|
|
143
|
+
existingStyle.remove();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Check if style tag exists in DOM
|
|
149
|
+
*/
|
|
150
|
+
exists(): boolean {
|
|
151
|
+
return document.getElementById(this.styleId) !== null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|