soma-core 1.0.2 → 1.0.3

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.
@@ -31,8 +31,33 @@ function urlPathToPageBase(urlPath: string): string {
31
31
  return clean || 'index';
32
32
  }
33
33
 
34
- async function loadDomainClass(base: string): Promise<new () => any> {
34
+ type DomainModule = { default?: unknown; [key: string]: unknown };
35
+
36
+ const webAdminShellDomainLoaders: Record<string, () => Promise<DomainModule>> = {
37
+ index: () => import('web-admin-shell/domain/ui/indexClass') as Promise<DomainModule>,
38
+ 'auth-manage/route': () => import('web-admin-shell/domain/ui/auth-manage/routeClass') as Promise<DomainModule>,
39
+ 'auth-manage/menu': () => import('web-admin-shell/domain/ui/auth-manage/menuClass') as Promise<DomainModule>,
40
+ 'auth-manage/role': () => import('web-admin-shell/domain/ui/auth-manage/roleClass') as Promise<DomainModule>,
41
+ 'auth-manage/role-auth': () => import('web-admin-shell/domain/ui/auth-manage/role-authClass') as Promise<DomainModule>,
42
+ 'auth-manage/user-role': () => import('web-admin-shell/domain/ui/auth-manage/user-roleClass') as Promise<DomainModule>,
43
+ 'auth-manage/action-log': () => import('web-admin-shell/domain/ui/auth-manage/action-logClass') as Promise<DomainModule>,
44
+ 'auth-manage/dictionary': () => import('web-admin-shell/domain/ui/auth-manage/dictionaryClass') as Promise<DomainModule>,
45
+ 'auth-manage/auth-app': () => import('web-admin-shell/domain/ui/auth-manage/auth-appClass') as Promise<DomainModule>,
46
+ 'auth-manage/system': () => import('web-admin-shell/domain/ui/auth-manage/systemClass') as Promise<DomainModule>,
47
+ };
48
+
49
+ async function loadDomainClass(base: string, sourcePackage?: string | null): Promise<new () => any> {
35
50
  try {
51
+ if (sourcePackage === 'web-admin-shell') {
52
+ const load = webAdminShellDomainLoaders[base];
53
+ if (!load) throw new Error(`domain class missing: ${sourcePackage}:${base}Class`);
54
+ const mod = await load();
55
+ if (typeof mod.default === 'function') return mod.default as new () => any;
56
+ const ctor = Object.values(mod).find((v): v is new () => any => typeof v === 'function');
57
+ if (ctor) return ctor as new () => any;
58
+ throw new Error(`domain class missing: ${sourcePackage}:${base}Class`);
59
+ }
60
+
36
61
  const mod = await import(
37
62
  /* webpackInclude: /\/domain\/ui\/.*Class\.ts$/ */
38
63
  `@soma-host/domain/ui/${base}Class`
@@ -49,6 +74,7 @@ async function loadDomainClass(base: string): Promise<new () => any> {
49
74
 
50
75
  type PagePayload = {
51
76
  base: string;
77
+ sourcePackage?: string | null;
52
78
  html: string;
53
79
  ui: string;
54
80
  event: string;
@@ -242,7 +268,8 @@ function SomaPageRenderer({
242
268
  if (cancelled) return;
243
269
 
244
270
  const base = (data.base as string) || urlPathToPageBase(pagePath);
245
- const DomainClass = await loadDomainClass(base);
271
+ const sourcePackage = typeof data.sourcePackage === 'string' ? data.sourcePackage : null;
272
+ const DomainClass = await loadDomainClass(base, sourcePackage);
246
273
  const routeAssets = { routerPath };
247
274
 
248
275
  if (!isDev) {
@@ -261,7 +288,7 @@ function SomaPageRenderer({
261
288
 
262
289
  const cached = pageAssetCache.get(routerPath);
263
290
  if (cached) {
264
- const CachedClass = await loadDomainClass(cached.base);
291
+ const CachedClass = await loadDomainClass(cached.base, cached.sourcePackage);
265
292
  await mountInto(CachedClass, SomaBootstrap, {
266
293
  uiYaml: cached.ui,
267
294
  eventYaml: cached.event,
@@ -276,6 +303,7 @@ function SomaPageRenderer({
276
303
 
277
304
  const payload: PagePayload = {
278
305
  base,
306
+ sourcePackage,
279
307
  html: data.html,
280
308
  ui: data.ui,
281
309
  event: data.event,
@@ -4,6 +4,7 @@ import { existsSync } from 'fs';
4
4
  import { join, resolve } from 'path';
5
5
  import { NextRequest } from 'next/server';
6
6
  import { isSafePageBase, urlPathToCandidates } from '../../../core/compiler/page-base-resolver';
7
+ import { getSomaAssetSources, type SomaAssetSource } from '../../../core/host/source-packages';
7
8
  import { ServerFileCache } from '../../../core/infra/cache/ServerFileCache';
8
9
 
9
10
  const cache = ServerFileCache.getInstance();
@@ -12,33 +13,43 @@ function getHostDir(): string | undefined {
12
13
  return process.env.SOMA_HOST_DIR || undefined;
13
14
  }
14
15
 
15
- let watchedRoot: string | null = null;
16
+ const watchedRoots = new Set<string>();
16
17
 
17
18
  function ensureWatch(root: string) {
18
- if (watchedRoot === root) return;
19
- watchedRoot = root;
19
+ if (watchedRoots.has(root)) return;
20
+ watchedRoots.add(root);
20
21
  cache.watchAndInvalidate(root);
21
22
  }
22
23
 
23
- function resolvePageBase(hostDir: string, urlPath: string): string | null {
24
+ function resolvePageSource(sources: SomaAssetSource[], urlPath: string): { source: SomaAssetSource; base: string } | null {
24
25
  for (const candidate of urlPathToCandidates(urlPath)) {
25
26
  if (!isSafePageBase(candidate)) continue;
26
- const htmlPath = join(hostDir, 'html', `${candidate}.html`);
27
- if (existsSync(htmlPath)) return candidate;
27
+ for (const source of sources) {
28
+ const htmlPath = join(source.assetRoot, 'html', `${candidate}.html`);
29
+ if (existsSync(htmlPath)) {
30
+ return { source, base: candidate };
31
+ }
32
+ }
28
33
  }
29
34
  return null;
30
35
  }
31
36
 
32
- function collectIncludes(hostDir: string): Record<string, string> {
37
+ function collectIncludes(sources: SomaAssetSource[]): Record<string, string> {
33
38
  const includes: Record<string, string> = {};
34
- const sharedDir = join(hostDir, 'html', 'shared');
35
- try {
36
- const files = cache.readDirFiles(sharedDir, '.html');
37
- const names = cache.readDirNames(sharedDir, '.html');
38
- for (let i = 0; i < names.length; i++) {
39
- includes[`shared/${names[i]}`] = files[i];
40
- }
41
- } catch {}
39
+ const ordered = [
40
+ ...sources.filter((source) => source.type === 'package'),
41
+ ...sources.filter((source) => source.type === 'host'),
42
+ ];
43
+ for (const source of ordered) {
44
+ const sharedDir = join(source.assetRoot, 'html', 'shared');
45
+ try {
46
+ const files = cache.readDirFiles(sharedDir, '.html');
47
+ const names = cache.readDirNames(sharedDir, '.html');
48
+ for (let i = 0; i < names.length; i++) {
49
+ includes[`shared/${names[i]}`] = files[i];
50
+ }
51
+ } catch {}
52
+ }
42
53
  return includes;
43
54
  }
44
55
 
@@ -51,19 +62,26 @@ export async function GET(req: NextRequest) {
51
62
  );
52
63
  }
53
64
 
54
- ensureWatch(hostDir);
65
+ const sources = getSomaAssetSources(hostDir);
66
+ sources.forEach((source) => ensureWatch(source.assetRoot));
67
+ sources.forEach((source) => {
68
+ if (source.codeRoot !== source.assetRoot) {
69
+ ensureWatch(source.codeRoot);
70
+ }
71
+ });
55
72
 
56
73
  const urlPath = req.nextUrl.searchParams.get('path') || '/';
57
- const base = resolvePageBase(hostDir, urlPath);
74
+ const resolvedPage = resolvePageSource(sources, urlPath);
58
75
 
59
- if (!base) {
76
+ if (!resolvedPage) {
60
77
  return Response.json({ error: `Page not found: ${urlPath}` }, { status: 404 });
61
78
  }
62
79
 
63
- const htmlPath = join(hostDir, 'html', `${base}.html`);
80
+ const { source, base } = resolvedPage;
81
+ const htmlPath = join(source.assetRoot, 'html', `${base}.html`);
64
82
  const resolvedHtml = resolve(htmlPath);
65
- const resolvedHostHtml = resolve(hostDir, 'html');
66
- if (!resolvedHtml.startsWith(resolvedHostHtml)) {
83
+ const resolvedSourceHtml = resolve(source.assetRoot, 'html');
84
+ if (!resolvedHtml.startsWith(resolvedSourceHtml)) {
67
85
  return Response.json({ error: 'Invalid path' }, { status: 400 });
68
86
  }
69
87
 
@@ -72,19 +90,21 @@ export async function GET(req: NextRequest) {
72
90
 
73
91
  let ui: string, event: string, style: string, localeYaml: string, appConfigYaml: string;
74
92
  try {
75
- ui = cache.tryReadFile(join(hostDir, 'ui', `${base}_ui.yaml`));
76
- event = cache.tryReadFile(join(hostDir, 'event', `${base}_event.yaml`));
77
- style = cache.tryReadFile(join(hostDir, 'ui', `${base}_style.yaml`));
93
+ ui = cache.tryReadFile(join(source.assetRoot, 'ui', `${base}_ui.yaml`));
94
+ event = cache.tryReadFile(join(source.assetRoot, 'event', `${base}_event.yaml`));
95
+ style = cache.tryReadFile(join(source.assetRoot, 'ui', `${base}_style.yaml`));
78
96
  localeYaml = cache.tryReadFile(join(hostDir, 'config', 'locale.yaml'));
79
97
  appConfigYaml = cache.tryReadFile(join(hostDir, 'config', 'app.config.yaml'));
80
98
  } catch (e: any) {
81
99
  return Response.json({ error: `Asset read error: ${e.message}` }, { status: 500 });
82
100
  }
83
101
 
84
- const includes = collectIncludes(hostDir);
102
+ const includes = collectIncludes(sources);
85
103
 
86
104
  return Response.json({
87
105
  base,
106
+ sourceType: source.type,
107
+ sourcePackage: source.packageName ?? null,
88
108
  html,
89
109
  ui,
90
110
  event,
@@ -0,0 +1,13 @@
1
+ const faviconSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
2
+ <rect width="64" height="64" rx="14" fill="#1677ff"/>
3
+ <path d="M18 22h8l6 18 6-18h8L35 48h-6L18 22z" fill="#ffffff"/>
4
+ </svg>`;
5
+
6
+ export function GET(): Response {
7
+ return new Response(faviconSvg, {
8
+ headers: {
9
+ 'content-type': 'image/svg+xml; charset=utf-8',
10
+ 'cache-control': 'public, max-age=86400',
11
+ },
12
+ });
13
+ }
package/bin/soma.cjs CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  /**
3
3
  * SOMA CLI 薄入口 — 优先委托 dist/cli/soma.js,回退到内联实现
4
4
  */
@@ -3,6 +3,7 @@ import path from 'node:path';
3
3
  import createJiti from 'jiti';
4
4
  import type { IService } from './IService';
5
5
  import { resolveServiceFilePath } from './service-path';
6
+ import { getSomaAssetSources } from '../host/source-packages';
6
7
 
7
8
  function isService(obj: unknown): obj is IService {
8
9
  if (!obj || typeof obj !== 'object') return false;
@@ -40,8 +41,10 @@ export function loadHostService(segments: string[]): IService | null {
40
41
  const hostDir = process.env.SOMA_HOST_DIR;
41
42
  if (!hostDir) return null;
42
43
 
43
- const filePath = resolveServiceFilePath(hostDir, segments);
44
- if (!filePath || !fs.existsSync(filePath)) return null;
44
+ const filePath = getSomaAssetSources(hostDir)
45
+ .map((source) => resolveServiceFilePath(source.codeRoot, segments))
46
+ .find((candidate): candidate is string => Boolean(candidate && fs.existsSync(candidate)));
47
+ if (!filePath) return null;
45
48
 
46
49
  const isDev = process.env.NODE_ENV !== 'production';
47
50
  if (!isDev && instanceCache.has(filePath)) {
@@ -7,6 +7,9 @@ export function urlPathToCandidates(urlPath: string): string[] {
7
7
  const clean = withoutQuery.replace(/^\//, '').replace(/\.html$/i, '');
8
8
  const base = clean || 'index';
9
9
  const candidates = [base];
10
+ if (base.endsWith('/index')) {
11
+ candidates.push(base.slice(0, -'/index'.length));
12
+ }
10
13
  if (!base.includes('/') && base !== 'index') {
11
14
  candidates.push(`${base}/index`);
12
15
  }
@@ -3,6 +3,7 @@
3
3
  */
4
4
  const fs = require('node:fs');
5
5
  const path = require('node:path');
6
+ const createJiti = require('jiti');
6
7
 
7
8
  function collectHtmlFiles(dir, prefix = '', acc = []) {
8
9
  if (!fs.existsSync(dir)) return acc;
@@ -15,10 +16,123 @@ function collectHtmlFiles(dir, prefix = '', acc = []) {
15
16
  return acc;
16
17
  }
17
18
 
19
+ function readJson(filePath) {
20
+ try {
21
+ if (!fs.existsSync(filePath)) return null;
22
+ return JSON.parse(fs.readFileSync(filePath, 'utf8'));
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
27
+
28
+ function packagePathInNodeModules(hostDir, packageName) {
29
+ return path.join(hostDir, 'node_modules', ...packageName.split('/'));
30
+ }
31
+
32
+ function resolvePackageRoot(hostDir, packageName, version) {
33
+ const nodeModulesPath = packagePathInNodeModules(hostDir, packageName);
34
+ if (fs.existsSync(nodeModulesPath)) {
35
+ return nodeModulesPath;
36
+ }
37
+
38
+ if (typeof version === 'string' && version.startsWith('file:')) {
39
+ const fileRoot = path.resolve(hostDir, version.slice('file:'.length));
40
+ if (fs.existsSync(fileRoot)) {
41
+ return fileRoot;
42
+ }
43
+ }
44
+
45
+ return null;
46
+ }
47
+
48
+ function readExplicitSourcePackages() {
49
+ return String(process.env.SOMA_SOURCE_PACKAGES ?? '')
50
+ .split(',')
51
+ .map((item) => item.trim())
52
+ .filter(Boolean);
53
+ }
54
+
55
+ function readHostDependencies(hostDir) {
56
+ const packageJson = readJson(path.join(hostDir, 'package.json'));
57
+ return {
58
+ ...(packageJson?.dependencies ?? {}),
59
+ ...(packageJson?.devDependencies ?? {}),
60
+ };
61
+ }
62
+
63
+ function isSomaSourcePackage(packageRoot, explicit) {
64
+ if (explicit) return true;
65
+ const packageJson = readJson(path.join(packageRoot, 'package.json'));
66
+ return packageJson?.soma?.source === true || fs.existsSync(path.join(packageRoot, 'shell', 'html'));
67
+ }
68
+
69
+ function toPackageSource(packageName, packageRoot) {
70
+ const shellRoot = path.join(packageRoot, 'shell');
71
+ return {
72
+ type: 'package',
73
+ name: packageName,
74
+ packageName,
75
+ assetRoot: fs.existsSync(path.join(shellRoot, 'html')) ? shellRoot : packageRoot,
76
+ codeRoot: packageRoot,
77
+ };
78
+ }
79
+
80
+ function getSomaAssetSources(hostDir) {
81
+ const normalizedHostDir = path.resolve(hostDir);
82
+ const dependencies = readHostDependencies(normalizedHostDir);
83
+ const explicitPackages = new Set(readExplicitSourcePackages());
84
+ const packageNames = new Set([
85
+ ...Object.keys(dependencies),
86
+ ...explicitPackages,
87
+ ]);
88
+
89
+ const sources = [
90
+ {
91
+ type: 'host',
92
+ name: 'host',
93
+ assetRoot: normalizedHostDir,
94
+ codeRoot: normalizedHostDir,
95
+ },
96
+ ];
97
+
98
+ for (const packageName of packageNames) {
99
+ const packageRoot = resolvePackageRoot(normalizedHostDir, packageName, dependencies[packageName]);
100
+ if (!packageRoot || !isSomaSourcePackage(packageRoot, explicitPackages.has(packageName))) {
101
+ continue;
102
+ }
103
+ sources.push(toPackageSource(packageName, packageRoot));
104
+ }
105
+
106
+ return sources;
107
+ }
108
+
109
+ function collectPageEntries(sources) {
110
+ const byHtmlFile = new Map();
111
+ const orderedSources = [
112
+ ...sources.filter((source) => source.type === 'package'),
113
+ ...sources.filter((source) => source.type === 'host'),
114
+ ];
115
+
116
+ for (const source of orderedSources) {
117
+ const htmlRoot = path.join(source.assetRoot, 'html');
118
+ for (const htmlFile of collectHtmlFiles(htmlRoot).sort()) {
119
+ byHtmlFile.set(htmlFile, { source, htmlFile });
120
+ }
121
+ }
122
+
123
+ return [...byHtmlFile.values()].sort((a, b) => a.htmlFile.localeCompare(b.htmlFile));
124
+ }
125
+
18
126
  class SomaManifestWebpackPlugin {
19
127
  constructor(options = {}) {
20
128
  this.hostDir = options.hostDir;
21
129
  this.outputDir = options.outputDir ?? '.soma';
130
+ this.jiti = createJiti(__filename, {
131
+ interopDefault: true,
132
+ alias: {
133
+ '@core': path.resolve(__dirname, '..'),
134
+ },
135
+ });
22
136
  }
23
137
 
24
138
  apply(compiler) {
@@ -30,20 +144,22 @@ class SomaManifestWebpackPlugin {
30
144
  }
31
145
 
32
146
  try {
33
- const { precompileAll } = require('./full-manifest-builder');
34
- const htmlFiles = collectHtmlFiles(path.join(hostDir, 'html'));
147
+ const { precompileAll } = this.jiti('./full-manifest-builder.ts');
148
+ const sources = getSomaAssetSources(hostDir);
149
+ const pageEntries = collectPageEntries(sources);
150
+ const htmlFiles = pageEntries.map((entry) => entry.htmlFile);
35
151
  const readYaml = (filePath) =>
36
152
  fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : '';
37
153
 
38
- const pages = htmlFiles
39
- .filter((f) => !f.startsWith('shared/') && !f.startsWith('system/'))
40
- .map((htmlFile) => {
154
+ const pages = pageEntries
155
+ .filter(({ htmlFile }) => !htmlFile.startsWith('shared/') && !htmlFile.startsWith('system/'))
156
+ .map(({ source, htmlFile }) => {
41
157
  const base = htmlFile.replace(/\.html$/, '');
42
158
  return {
43
159
  path: `/${base}`,
44
- uiYaml: readYaml(path.join(hostDir, 'ui', `${base}_ui.yaml`)),
45
- eventYaml: readYaml(path.join(hostDir, 'event', `${base}_event.yaml`)),
46
- styleYaml: readYaml(path.join(hostDir, 'ui', `${base}_style.yaml`)) || undefined,
160
+ uiYaml: readYaml(path.join(source.assetRoot, 'ui', `${base}_ui.yaml`)),
161
+ eventYaml: readYaml(path.join(source.assetRoot, 'event', `${base}_event.yaml`)),
162
+ styleYaml: readYaml(path.join(source.assetRoot, 'ui', `${base}_style.yaml`)) || undefined,
47
163
  };
48
164
  });
49
165
 
@@ -1,7 +1,12 @@
1
1
  import type { IContainerAdapter } from '../container/IContainerAdapter';
2
2
  import type { SomaCompiledBinding } from '../types/manifest.types';
3
3
  import type { BindingEntry } from '../types/engine.types';
4
- import type { ShowMapping } from '../types/ui-config.types';
4
+ import type {
5
+ ExtendedShowValue,
6
+ NestedShowMapping,
7
+ ShowMapping,
8
+ ShowValue,
9
+ } from '../types/ui-config.types';
5
10
  import type { SomaScopeResolver } from './scope-resolver';
6
11
  import { longestIncreasingSubsequence } from './lis';
7
12
 
@@ -314,18 +319,24 @@ export class SomaDomRenderer {
314
319
  this.adapter.appendFragment(entry.element, fragment);
315
320
  }
316
321
 
317
- private applyShowConfig(
318
- root: HTMLElement,
319
- data: any,
320
- showConfig: ShowMapping,
321
- ): void {
322
- for (const [rawKey, config] of Object.entries(showConfig)) {
323
- if (typeof config !== 'string') {
324
- continue;
325
- }
326
-
327
- const [somaId, attrName] = rawKey.split('@');
328
- const element = root.querySelector<HTMLElement>(`[data-soma-id="${somaId}"]`);
322
+ private applyShowConfig(
323
+ root: HTMLElement,
324
+ data: any,
325
+ showConfig: ShowMapping,
326
+ ): void {
327
+ for (const [rawKey, config] of Object.entries(showConfig)) {
328
+ if (this.isNestedShowMapping(config)) {
329
+ this.applyNestedShowConfig(root, data, rawKey, config);
330
+ continue;
331
+ }
332
+
333
+ if (this.isExtendedShowValue(config)) {
334
+ this.applyExtendedShowConfig(root, data, rawKey, config);
335
+ continue;
336
+ }
337
+
338
+ const [somaId, attrName] = rawKey.split('@');
339
+ const element = root.querySelector<HTMLElement>(`[data-soma-id="${somaId}"]`);
329
340
  if (!element) {
330
341
  continue;
331
342
  }
@@ -343,13 +354,122 @@ export class SomaDomRenderer {
343
354
  continue;
344
355
  }
345
356
 
346
- this.adapter?.setText(element, value != null ? String(value) : '--');
347
- }
348
- }
349
-
350
- private resolveShowValue(valuePath: string, itemData: any): any {
351
- const segments = valuePath.split('.');
352
- const firstSeg = segments[0];
357
+ this.adapter?.setText(element, value != null ? String(value) : '--');
358
+ }
359
+ }
360
+
361
+ private applyNestedShowConfig(
362
+ root: HTMLElement,
363
+ data: any,
364
+ rawKey: string,
365
+ config: NestedShowMapping,
366
+ ): void {
367
+ if (!this.adapter) {
368
+ return;
369
+ }
370
+
371
+ const [somaId] = rawKey.split('@');
372
+ const element = root.querySelector<HTMLElement>(`[data-soma-id="${somaId}"]`);
373
+ if (!element) {
374
+ return;
375
+ }
376
+
377
+ const nestedData = this.resolveShowValue(config.bind.obj, data);
378
+ const role = this.adapter.readRole(element);
379
+ const templateCache = this.adapter.cloneTemplate(element);
380
+ if (!templateCache) {
381
+ return;
382
+ }
383
+
384
+ this.adapter.clearRenderedChildren(element);
385
+
386
+ if (Array.isArray(nestedData) || role === 'item') {
387
+ const items = Array.isArray(nestedData) ? nestedData : [];
388
+ for (const itemData of items) {
389
+ this.appendNestedTemplateItem(element, templateCache, itemData, config.show);
390
+ }
391
+ return;
392
+ }
393
+
394
+ if (nestedData && typeof nestedData === 'object') {
395
+ this.appendNestedTemplateItem(element, templateCache, nestedData, config.show);
396
+ }
397
+ }
398
+
399
+ private appendNestedTemplateItem(
400
+ container: HTMLElement,
401
+ templateCache: DocumentFragment,
402
+ itemData: any,
403
+ showConfig: ShowMapping,
404
+ ): void {
405
+ if (!this.adapter) {
406
+ return;
407
+ }
408
+
409
+ const fragment = templateCache.cloneNode(true) as DocumentFragment;
410
+ const wrapper = fragment.firstElementChild as HTMLElement | null;
411
+ if (!wrapper) {
412
+ return;
413
+ }
414
+
415
+ if (itemData && typeof itemData === 'object') {
416
+ const key = 'id' in itemData ? itemData.id : ('key' in itemData ? itemData.key : undefined);
417
+ if (key != null) {
418
+ wrapper.setAttribute('data-soma-key', String(key));
419
+ }
420
+ }
421
+
422
+ this.scopeTracker?.set(wrapper, itemData);
423
+ this.applyShowConfig(wrapper, itemData, showConfig);
424
+ this.adapter.appendFragment(container, fragment);
425
+ }
426
+
427
+ private applyExtendedShowConfig(
428
+ root: HTMLElement,
429
+ data: any,
430
+ rawKey: string,
431
+ config: ExtendedShowValue,
432
+ ): void {
433
+ const [somaId, attrName] = rawKey.split('@');
434
+ const element = root.querySelector<HTMLElement>(`[data-soma-id="${somaId}"]`);
435
+
436
+ if (element) {
437
+ if (config.text) {
438
+ const value = this.resolveShowValue(config.text, data);
439
+ if (attrName === 'html') {
440
+ this.adapter?.setHtml(element, String(value ?? ''));
441
+ } else if (attrName) {
442
+ if (value != null) {
443
+ this.adapter?.setAttribute(element, attrName, String(value));
444
+ }
445
+ } else {
446
+ this.adapter?.setText(element, value != null ? String(value) : '--');
447
+ }
448
+ }
449
+
450
+ if (config.when) {
451
+ const { path, negate } = this.parseConditionalPath(config.when);
452
+ const value = this.resolveShowValue(path, data);
453
+ this.adapter?.setVisibility(element, negate ? !value : !!value);
454
+ }
455
+
456
+ if (config.class) {
457
+ for (const [classes, path] of Object.entries(config.class)) {
458
+ const enabled = !!this.resolveShowValue(path, data);
459
+ this.adapter?.toggleClasses(element, classes.split(' ').filter(Boolean), enabled);
460
+ }
461
+ }
462
+ }
463
+
464
+ if (config.show) {
465
+ const showRoot = element ?? root;
466
+ this.applyShowConfig(showRoot, data, config.show);
467
+ }
468
+ }
469
+
470
+ private resolveShowValue(valuePath: string, itemData: any): any {
471
+ const segments = valuePath.split('.');
472
+ const firstSeg = segments[0];
353
473
 
354
474
  if (this.resolver && this.resolver.hasVar(firstSeg)) {
355
475
  const varPath = this.resolver.getVarPath(firstSeg);
@@ -358,7 +478,23 @@ export class SomaDomRenderer {
358
478
  }
359
479
  return segments.slice(1).reduce((obj: any, key: string) => obj?.[key], itemData);
360
480
  }
361
-
362
- return segments.reduce((obj: any, key: string) => obj?.[key], itemData);
363
- }
364
- }
481
+
482
+ return segments.reduce((obj: any, key: string) => obj?.[key], itemData);
483
+ }
484
+
485
+ private parseConditionalPath(valuePath: string): { path: string; negate: boolean } {
486
+ const negate = valuePath.startsWith('!');
487
+ return {
488
+ path: negate ? valuePath.slice(1) : valuePath,
489
+ negate,
490
+ };
491
+ }
492
+
493
+ private isNestedShowMapping(value: ShowValue): value is NestedShowMapping {
494
+ return typeof value === 'object' && value !== null && 'bind' in value && 'show' in value;
495
+ }
496
+
497
+ private isExtendedShowValue(value: ShowValue): value is ExtendedShowValue {
498
+ return typeof value === 'object' && value !== null;
499
+ }
500
+ }
@@ -0,0 +1,2 @@
1
+ /** Runtime fallback when host app does not provide config/app.config.yaml. */
2
+ export default {};
@@ -0,0 +1,2 @@
1
+ /** Runtime fallback when host app does not provide config/locale.yaml. */
2
+ export default {};