Completes the generic module platform that enables modules to contribute
UI elements, runtime JS components, and search resources without any
core hardcoding.
New generic UI slot types:
- topbar.right_item: module-contributed topbar buttons
- layout.body_end_template: module-contributed dialog/overlay templates
- layout.head_style: module-contributed global CSS
- runtime.component: declarative JS component registration with phase ordering
New infrastructure:
- ModuleAutoloader: PSR-4 autoloading for module-local PHP classes
- ModuleRuntimePageBuilder: symlinks module pages into runtime directory
- ModuleRuntimeAssetPublisher: publishes module CSS/JS to web/modules/
- ModulePermissionSynchronizer: syncs module permissions to DB
- CLI scripts: module-runtime-sync, module-build, module-migrate,
module-permissions-sync, module-assets-sync
- {{userId}} placeholder in SearchDataService for user-scoped search queries
- Component runtime with phased initialization (early/default/late)
- AppContainer.protectExistingBindings() to prevent module→core overwrites
- Architecture tests: ModuleStructureContractTest, CoreTemplateIsolationTest,
FrontendComponentRuntimeContractTest, AppContainerIsolationContractTest
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
68 lines
1.7 KiB
JavaScript
68 lines
1.7 KiB
JavaScript
/**
|
|
* Namespaced localStorage helper for UI components.
|
|
*/
|
|
const safeStorageGet = (key) => {
|
|
const normalized = String(key || '').trim();
|
|
if (normalized === '') {
|
|
return null;
|
|
}
|
|
try {
|
|
return window.localStorage.getItem(normalized);
|
|
} catch {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
const safeStorageSet = (key, value) => {
|
|
const normalized = String(key || '').trim();
|
|
if (normalized === '') {
|
|
return;
|
|
}
|
|
try {
|
|
window.localStorage.setItem(normalized, value);
|
|
} catch {
|
|
// localStorage may be unavailable; fail safe.
|
|
}
|
|
};
|
|
|
|
const safeStorageRemove = (key) => {
|
|
const normalized = String(key || '').trim();
|
|
if (normalized === '') {
|
|
return;
|
|
}
|
|
try {
|
|
window.localStorage.removeItem(normalized);
|
|
} catch {
|
|
// localStorage may be unavailable; fail safe.
|
|
}
|
|
};
|
|
|
|
const normalizeToken = (value) => String(value ?? '')
|
|
.trim()
|
|
.toLowerCase()
|
|
.replaceAll(/[^a-z0-9._-]+/g, '-')
|
|
.replaceAll(/^-+|-+$/g, '');
|
|
|
|
export function createUiStorage(options = {}) {
|
|
const namespace = normalizeToken(options.namespace || 'app-ui') || 'app-ui';
|
|
const version = normalizeToken(options.version || 'v1') || 'v1';
|
|
const scope = normalizeToken(options.scope || '') || 'global';
|
|
const basePrefix = `${namespace}:${version}:${scope}`;
|
|
|
|
const buildKey = (bucket, key) => {
|
|
const normalizedBucket = normalizeToken(bucket || 'component') || 'component';
|
|
const normalizedKey = normalizeToken(key || '');
|
|
if (normalizedKey === '') {
|
|
return '';
|
|
}
|
|
return `${basePrefix}:${normalizedBucket}:${normalizedKey}`;
|
|
};
|
|
|
|
return {
|
|
buildKey,
|
|
getItem: safeStorageGet,
|
|
setItem: safeStorageSet,
|
|
removeItem: safeStorageRemove,
|
|
};
|
|
}
|