soma-core 1.3.2 → 1.3.4
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/README.md +43 -0
- package/app/SomaPageClient.tsx +22 -68
- package/app/[...path]/page.tsx +7 -6
- package/app/api/[...path]/route.ts +3 -3
- package/app/api/soma-registry/[...path]/route.ts +67 -0
- package/app/components/SomaHostPage.tsx +3 -8
- package/app/components/SomaPageClientBoundary.tsx +13 -0
- package/app/layout.tsx +6 -1
- package/app/page.tsx +3 -3
- package/app/soma/manifest/route.ts +1 -0
- package/app/soma/page-object/route.ts +1 -1
- package/bin/soma-lsp.cjs +1 -4
- package/core/build/compiler/full-manifest-builder.ts +19 -23
- package/core/build/compiler/html-include-expander.ts +56 -0
- package/core/build/compiler/page-assets.ts +26 -0
- package/core/build/compiler/page-declaration-compiler.ts +85 -0
- package/core/build/compiler/rollup-plugin-soma.ts +4 -13
- package/core/build/compiler/route-builder.ts +0 -2
- package/core/build/compiler/rspack-plugin-soma.js +1 -10
- package/core/build/compiler/soma-manifest-webpack-plugin.js +54 -9
- package/core/build/compiler/soma-precompile.js +3581 -2387
- package/core/build/compiler/soma-precompile.ts +44 -2
- package/core/build/compiler/soma-rspack-yaml-loader.js +5 -8
- package/core/build/compiler/soma-webpack-loader.js +6 -15
- package/core/build/compiler/vite-plugin-soma.ts +9 -21
- package/core/build/component/pack-from-dir.ts +58 -0
- package/core/build/component/package-loader.ts +281 -0
- package/core/build/eject/apply-eject.ts +133 -0
- package/core/build/eject/plan-eject.ts +133 -0
- package/core/build/lsp/cross-file-diagnostics.cjs +82 -113
- package/core/build/lsp/extra-completion.cjs +14 -8
- package/core/build/lsp/lsp-navigation.cjs +50 -43
- package/core/build/lsp/soma-declaration.cjs +85 -0
- package/core/build/lsp/ui-yaml-completion.cjs +98 -104
- package/core/build/v2/block-compile.ts +200 -0
- package/core/build/v2/block-loader.ts +33 -0
- package/core/build/v2/html-index.ts +120 -0
- package/core/build/v2/migrate-v1.ts +370 -0
- package/core/build/v2/soma-file-loader.ts +216 -0
- package/core/client/adaptive/flush-scheduler.ts +96 -0
- package/core/client/adaptive/hysteresis.ts +56 -0
- package/core/client/adaptive/index.ts +23 -0
- package/core/client/adaptive/observer-pool.ts +90 -0
- package/core/client/base/SomaPageRootBase.ts +50 -0
- package/core/client/compiler/adaptive-compile.ts +136 -0
- package/core/client/compiler/manifest-compiler.ts +155 -27
- package/core/client/component/ai-catalog.ts +277 -0
- package/core/client/component/component-definition.types.ts +65 -0
- package/core/client/component/component-expander.ts +119 -0
- package/core/client/component/component-manager.ts +933 -0
- package/core/client/component/component-pack.ts +445 -0
- package/core/client/component/component-registry.ts +71 -0
- package/core/client/component/contract-compat.ts +132 -0
- package/core/client/component/example-v2.ts +132 -0
- package/core/client/component/pack-styles.ts +94 -0
- package/core/client/component/scoped-adapter.ts +85 -0
- package/core/client/component/verify-pack.ts +247 -0
- package/core/client/container/MiniProgramContainerAdapter.ts +15 -1
- package/core/client/container/ReactNativeContainerAdapter.ts +15 -1
- package/core/client/container/SomaContainerAdapter.ts +186 -180
- package/core/client/data/data-object-resolver.ts +417 -0
- package/core/client/diagnostics/SomaDiagnostics.ts +187 -186
- package/core/client/diagnostics/boot-timings.ts +152 -0
- package/core/client/engine/asset-resolver.ts +12 -2
- package/core/client/engine/dom-renderer.ts +249 -24
- package/core/client/engine/emit-event.ts +21 -0
- package/core/client/engine/event-engine.ts +34 -4
- package/core/client/engine/on-change-engine.ts +1 -1
- package/core/client/engine/property-watcher.ts +1 -1
- package/core/client/engine/reactive-proxy.ts +11 -10
- package/core/client/engine/render-engine.ts +39 -4
- package/core/client/engine/runtime-builder.ts +23 -0
- package/core/client/engine/soma-bootstrap.ts +380 -7
- package/core/client/engine/style-binder.ts +47 -1
- package/core/client/observability/error-reporter.ts +173 -0
- package/core/client/parser/adaptive-parser.ts +264 -0
- package/core/client/parser/data-config-parser.ts +396 -0
- package/core/client/parser/pipeline-parser.ts +15 -3
- package/core/client/parser/style-config-parser.ts +65 -2
- package/core/client/parser/ui-config-parser.ts +52 -3
- package/core/client/parser/v2/namespace.ts +182 -0
- package/core/client/parser/v2/page-parser.ts +359 -0
- package/core/client/parser/v2/use-parser.ts +412 -0
- package/core/client/parser/value-lang.ts +340 -0
- package/core/client/pipes/pipe-registry.ts +249 -0
- package/core/client/quality/SomaQualityRegistry.ts +3 -0
- package/core/client/registry/declaration-renderer.ts +161 -0
- package/core/client/registry/index.ts +28 -0
- package/core/client/registry/page-lifecycle.ts +171 -0
- package/core/client/registry/remote-page.ts +139 -0
- package/core/client/runtime/SomaRuntimeServices.ts +24 -0
- package/core/client/security/attribute-presence.ts +70 -0
- package/core/client/security/html-sanitizer.ts +113 -0
- package/core/client/security/url-guard.ts +0 -0
- package/core/client/theme/harmony.ts +307 -0
- package/core/client/theme/scene-tokens.ts +134 -0
- package/core/client/theme/theme-axes.ts +228 -0
- package/core/client/theme/theme-engine.ts +1196 -0
- package/core/client/theme/tone-solver.ts +118 -0
- package/core/client/typography/typography-base.ts +34 -0
- package/core/client/validation/contract-validator.ts +48 -5
- package/core/index.ts +262 -2
- package/core/server/api/IService.ts +18 -6
- package/core/server/api/load-host-service.ts +3 -3
- package/core/server/host/content-security-policy.ts +190 -0
- package/core/server/host/csp-nonce-metadata.ts +75 -0
- package/core/server/host/resolve-host-request-hook.ts +5 -0
- package/core/server/host/server-page-assets.ts +34 -7
- package/core/server/host/soma-page-compile.ts +33 -0
- package/core/server/index.ts +45 -1
- package/core/server/infra/cache/ServerFileCache.ts +1 -1
- package/core/server/mock/node/cli.mjs +2 -2
- package/core/server/registry/api-registry-store.ts +518 -0
- package/core/server/registry/conditional-object-store.ts +29 -0
- package/core/server/registry/declaration-precompiler.ts +99 -0
- package/core/server/registry/in-memory-conditional-object-store.ts +43 -0
- package/core/server/registry/index.ts +142 -0
- package/core/server/registry/page-registry-repository.ts +373 -0
- package/core/server/registry/page-registry-store.ts +932 -0
- package/core/server/registry/registry-error.ts +17 -0
- package/core/server/registry/registry-file-lock.ts +173 -0
- package/core/server/registry/registry-response.ts +71 -0
- package/core/server/registry/registry-subjects.ts +194 -0
- package/core/server/registry/registry-write-pipeline.ts +240 -0
- package/core/server/registry/request-body-limit.ts +99 -0
- package/core/server/registry/services/apis/Get.ts +25 -0
- package/core/server/registry/services/apis/List.ts +41 -0
- package/core/server/registry/services/apis/Register.ts +39 -0
- package/core/server/registry/services/apis/Unregister.ts +24 -0
- package/core/server/registry/services/index.ts +40 -0
- package/core/server/registry/services/pages/Get.ts +96 -0
- package/core/server/registry/services/pages/List.ts +53 -0
- package/core/server/registry/services/pages/Register.ts +49 -0
- package/core/server/registry/services/pages/Rollback.ts +36 -0
- package/core/server/registry/services/pages/Unregister.ts +23 -0
- package/core/server/registry/services/service-utils.ts +21 -0
- package/core/server/registry/validation/compile-gate.ts +54 -0
- package/core/server/registry/validation/component-existence.ts +55 -0
- package/core/server/registry/validation/credential-ban.ts +86 -0
- package/core/server/registry/validation/cross-check.ts +67 -0
- package/core/server/registry/validation/declaration-safety-scan.ts +102 -0
- package/core/shared/types/adaptive.types.ts +109 -0
- package/core/shared/types/component-contract.types.ts +120 -0
- package/core/shared/types/data-config.types.ts +105 -0
- package/core/shared/types/domain.types.ts +6 -0
- package/core/shared/types/engine.types.ts +41 -35
- package/core/shared/types/manifest.types.ts +55 -32
- package/core/shared/types/scope-manifest.types.ts +96 -0
- package/core/shared/types/style-config.types.ts +9 -0
- package/core/shared/types/ui-config.types.ts +118 -98
- package/dist/cli/soma.js +20 -5
- package/dist/core/index.cjs +7811 -1380
- package/dist/types/build/compiler/full-manifest-builder.d.ts +6 -2
- package/dist/types/build/compiler/html-include-expander.d.ts +19 -0
- package/dist/types/build/compiler/page-assets.d.ts +3 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +33 -0
- package/dist/types/build/compiler/rollup-plugin-soma.d.ts +0 -2
- package/dist/types/build/compiler/route-builder.d.ts +0 -1
- package/dist/types/build/compiler/soma-precompile.d.ts +17 -0
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -7
- package/dist/types/build/component/pack-from-dir.d.ts +17 -0
- package/dist/types/build/component/package-loader.d.ts +40 -0
- package/dist/types/build/eject/apply-eject.d.ts +22 -0
- package/dist/types/build/eject/plan-eject.d.ts +32 -0
- package/dist/types/build/v2/block-compile.d.ts +28 -0
- package/dist/types/build/v2/block-loader.d.ts +9 -0
- package/dist/types/build/v2/html-index.d.ts +37 -0
- package/dist/types/build/v2/migrate-v1.d.ts +32 -0
- package/dist/types/build/v2/soma-file-loader.d.ts +45 -0
- package/dist/types/client/adaptive/flush-scheduler.d.ts +13 -0
- package/dist/types/client/adaptive/hysteresis.d.ts +16 -0
- package/dist/types/client/adaptive/index.d.ts +5 -0
- package/dist/types/client/adaptive/observer-pool.d.ts +15 -0
- package/dist/types/client/base/SomaPageRootBase.d.ts +33 -0
- package/dist/types/client/compiler/adaptive-compile.d.ts +26 -0
- package/dist/types/client/compiler/manifest-compiler.d.ts +13 -2
- package/dist/types/client/component/ai-catalog.d.ts +73 -0
- package/dist/types/client/component/component-definition.types.d.ts +54 -0
- package/dist/types/client/component/component-expander.d.ts +25 -0
- package/dist/types/client/component/component-manager.d.ts +160 -0
- package/dist/types/client/component/component-pack.d.ts +110 -0
- package/dist/types/client/component/component-registry.d.ts +12 -0
- package/dist/types/client/component/contract-compat.d.ts +16 -0
- package/dist/types/client/component/example-v2.d.ts +9 -0
- package/dist/types/client/component/pack-styles.d.ts +22 -0
- package/dist/types/client/component/scoped-adapter.d.ts +18 -0
- package/dist/types/client/component/verify-pack.d.ts +14 -0
- package/dist/types/client/data/data-object-resolver.d.ts +71 -0
- package/dist/types/client/diagnostics/SomaDiagnostics.d.ts +2 -1
- package/dist/types/client/diagnostics/boot-timings.d.ts +30 -0
- package/dist/types/client/engine/asset-resolver.d.ts +7 -1
- package/dist/types/client/engine/dom-renderer.d.ts +51 -1
- package/dist/types/client/engine/emit-event.d.ts +6 -0
- package/dist/types/client/engine/event-engine.d.ts +6 -0
- package/dist/types/client/engine/render-engine.d.ts +25 -1
- package/dist/types/client/engine/runtime-builder.d.ts +7 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +118 -0
- package/dist/types/client/observability/error-reporter.d.ts +51 -0
- package/dist/types/client/parser/adaptive-parser.d.ts +28 -0
- package/dist/types/client/parser/data-config-parser.d.ts +34 -0
- package/dist/types/client/parser/pipeline-parser.d.ts +2 -0
- package/dist/types/client/parser/style-config-parser.d.ts +5 -3
- package/dist/types/client/parser/ui-config-parser.d.ts +22 -1
- package/dist/types/client/parser/v2/namespace.d.ts +52 -0
- package/dist/types/client/parser/v2/page-parser.d.ts +21 -0
- package/dist/types/client/parser/v2/use-parser.d.ts +72 -0
- package/dist/types/client/parser/value-lang.d.ts +63 -0
- package/dist/types/client/pipes/pipe-registry.d.ts +38 -0
- package/dist/types/client/registry/declaration-renderer.d.ts +50 -0
- package/dist/types/client/registry/index.d.ts +10 -0
- package/dist/types/client/registry/page-lifecycle.d.ts +61 -0
- package/dist/types/client/registry/remote-page.d.ts +52 -0
- package/dist/types/client/runtime/SomaRuntimeServices.d.ts +16 -0
- package/dist/types/client/security/attribute-presence.d.ts +7 -0
- package/dist/types/client/security/html-sanitizer.d.ts +37 -0
- package/dist/types/client/security/url-guard.d.ts +11 -0
- package/dist/types/client/theme/harmony.d.ts +77 -0
- package/dist/types/client/theme/scene-tokens.d.ts +25 -0
- package/dist/types/client/theme/theme-axes.d.ts +81 -0
- package/dist/types/client/theme/theme-engine.d.ts +77 -0
- package/dist/types/client/theme/tone-solver.d.ts +47 -0
- package/dist/types/client/typography/typography-base.d.ts +15 -0
- package/dist/types/client/validation/contract-validator.d.ts +2 -0
- package/dist/types/index.d.ts +47 -2
- package/dist/types/server/api/IService.d.ts +18 -6
- package/dist/types/server/host/content-security-policy.d.ts +53 -0
- package/dist/types/server/host/csp-nonce-metadata.d.ts +32 -0
- package/dist/types/server/host/resolve-host-request-hook.d.ts +5 -0
- package/dist/types/server/host/server-page-assets.d.ts +2 -0
- package/dist/types/server/host/soma-page-compile.d.ts +7 -0
- package/dist/types/server/index.d.ts +6 -1
- package/dist/types/server/registry/api-registry-store.d.ts +141 -0
- package/dist/types/server/registry/conditional-object-store.d.ts +27 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +30 -0
- package/dist/types/server/registry/in-memory-conditional-object-store.d.ts +8 -0
- package/dist/types/server/registry/index.d.ts +29 -0
- package/dist/types/server/registry/page-registry-repository.d.ts +58 -0
- package/dist/types/server/registry/page-registry-store.d.ts +259 -0
- package/dist/types/server/registry/registry-error.d.ts +12 -0
- package/dist/types/server/registry/registry-file-lock.d.ts +20 -0
- package/dist/types/server/registry/registry-response.d.ts +18 -0
- package/dist/types/server/registry/registry-subjects.d.ts +59 -0
- package/dist/types/server/registry/registry-write-pipeline.d.ts +48 -0
- package/dist/types/server/registry/request-body-limit.d.ts +31 -0
- package/dist/types/server/registry/services/apis/Get.d.ts +10 -0
- package/dist/types/server/registry/services/apis/List.d.ts +10 -0
- package/dist/types/server/registry/services/apis/Register.d.ts +13 -0
- package/dist/types/server/registry/services/apis/Unregister.d.ts +12 -0
- package/dist/types/server/registry/services/index.d.ts +3 -0
- package/dist/types/server/registry/services/pages/Get.d.ts +10 -0
- package/dist/types/server/registry/services/pages/List.d.ts +13 -0
- package/dist/types/server/registry/services/pages/Register.d.ts +11 -0
- package/dist/types/server/registry/services/pages/Rollback.d.ts +9 -0
- package/dist/types/server/registry/services/pages/Unregister.d.ts +9 -0
- package/dist/types/server/registry/services/service-utils.d.ts +10 -0
- package/dist/types/server/registry/validation/compile-gate.d.ts +12 -0
- package/dist/types/server/registry/validation/component-existence.d.ts +14 -0
- package/dist/types/server/registry/validation/credential-ban.d.ts +15 -0
- package/dist/types/server/registry/validation/cross-check.d.ts +16 -0
- package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +15 -0
- package/dist/types/shared/types/adaptive.types.d.ts +88 -0
- package/dist/types/shared/types/component-contract.types.d.ts +78 -0
- package/dist/types/shared/types/data-config.types.d.ts +81 -0
- package/dist/types/shared/types/domain.types.d.ts +6 -0
- package/dist/types/shared/types/engine.types.d.ts +6 -0
- package/dist/types/shared/types/manifest.types.d.ts +23 -0
- package/dist/types/shared/types/scope-manifest.types.d.ts +82 -0
- package/dist/types/shared/types/style-config.types.d.ts +8 -0
- package/dist/types/shared/types/ui-config.types.d.ts +20 -0
- package/editor/vscode/package.json +1 -24
- package/global.d.ts +5 -11
- package/next.config.js +85 -28
- package/package.json +33 -11
- package/proxy.ts +62 -0
- package/tailwind.config.ts +0 -1
- package/core/build/lsp/event-yaml-completion.cjs +0 -106
- package/core/client/engine/theme-variables.ts +0 -37
- package/dist/tsconfig.types.tsbuildinfo +0 -1
- package/dist/types/client/engine/theme-variables.d.ts +0 -3
- package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +0 -30
- package/middleware.ts +0 -33
package/next.config.js
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const { SomaManifestWebpackPlugin } = require('./core/build/compiler/soma-manifest-webpack-plugin');
|
|
5
|
-
const {
|
|
6
|
-
resolveHostConfigRoot,
|
|
7
|
-
resolveHostAppConfigPath,
|
|
8
|
-
} = require('./core/server/host/host-config-paths.cjs');
|
|
9
5
|
const {
|
|
10
6
|
readSomaPageResponseMode,
|
|
11
7
|
} = require('./core/server/host/page-response-mode.cjs');
|
|
@@ -68,28 +64,39 @@ function readHostSourceRoot() {
|
|
|
68
64
|
}
|
|
69
65
|
|
|
70
66
|
const hostSourceRoot = readHostSourceRoot();
|
|
71
|
-
|
|
67
|
+
function runtimeWatchIgnoreDirectories(env = process.env) {
|
|
68
|
+
const directories = [
|
|
69
|
+
path.join(hostDir, 'runtime'),
|
|
70
|
+
path.join(hostDir, 'data', 'soma-runtime'),
|
|
71
|
+
path.join(hostDir, '.soma', 'next', 'runtime'),
|
|
72
|
+
env.SOMA_AI_METRICS_DIR,
|
|
73
|
+
env.SOMA_AI_FAILURE_DIR,
|
|
74
|
+
env.SOMA_PAGE_REGISTRY_DIR,
|
|
75
|
+
].filter((value) => typeof value === 'string' && value.trim() !== '');
|
|
76
|
+
return [...new Set(directories.map((directory) => path.resolve(directory).replaceAll(path.sep, '/')))];
|
|
77
|
+
}
|
|
72
78
|
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
if (fs.existsSync(hostFile)) {
|
|
76
|
-
return hostFile;
|
|
77
|
-
}
|
|
78
|
-
return path.resolve(__dirname, fallbackPath);
|
|
79
|
+
function escapeRegExp(value) {
|
|
80
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
function
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
function mergeWatchIgnored(existingIgnored) {
|
|
84
|
+
const directories = runtimeWatchIgnoreDirectories();
|
|
85
|
+
const patterns = directories.map((directory) => `${directory}/**`);
|
|
86
|
+
if (existingIgnored === undefined) return patterns;
|
|
87
|
+
if (existingIgnored instanceof RegExp) {
|
|
88
|
+
const runtimeSource = directories
|
|
89
|
+
.map((directory) => `${escapeRegExp(directory)}(?:[\\\\/]|$)`)
|
|
90
|
+
.join('|');
|
|
91
|
+
return new RegExp(`(?:${existingIgnored.source})|(?:${runtimeSource})`, existingIgnored.flags);
|
|
85
92
|
}
|
|
86
|
-
return
|
|
93
|
+
return [...(Array.isArray(existingIgnored) ? existingIgnored : [existingIgnored]), ...patterns];
|
|
87
94
|
}
|
|
88
95
|
|
|
89
|
-
function
|
|
90
|
-
const
|
|
91
|
-
if (
|
|
92
|
-
return
|
|
96
|
+
function resolveOptionalHostSourceFile(relativePath, fallbackPath) {
|
|
97
|
+
const hostFile = path.resolve(hostSourceRoot, relativePath);
|
|
98
|
+
if (fs.existsSync(hostFile)) {
|
|
99
|
+
return hostFile;
|
|
93
100
|
}
|
|
94
101
|
return path.resolve(__dirname, fallbackPath);
|
|
95
102
|
}
|
|
@@ -151,14 +158,58 @@ const transpilePackages = [
|
|
|
151
158
|
]),
|
|
152
159
|
];
|
|
153
160
|
|
|
161
|
+
/**
|
|
162
|
+
* 构建期是否再跑一遍类型检查 / lint。
|
|
163
|
+
*
|
|
164
|
+
* 缺省跑(单机开发时这是最后一道拦截)。设 SOMA_BUILD_SKIP_CHECKS=1 可跳过——
|
|
165
|
+
* 两种场景需要它:
|
|
166
|
+
* 1. CI 里 `npm run verify` 已经按包跑过 `tsc --noEmit` 与 eslint,构建期重复一遍
|
|
167
|
+
* 只是把同一件事做两次;
|
|
168
|
+
* 2. **小内存机器**:实测本仓在 2GB 机器上做生产构建,编译阶段能过,
|
|
169
|
+
* 到"Linting and checking validity of types"时可用内存掉到 197MB,
|
|
170
|
+
* 构建 worker 直接被 SIGTERM(而 Next 只留下一句
|
|
171
|
+
* `build worker exited with code: null and signal: SIGTERM`,很容易被当成玄学)。
|
|
172
|
+
*/
|
|
173
|
+
const skipBuildChecks = process.env.SOMA_BUILD_SKIP_CHECKS === '1';
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* dev 服务器允许的访问来源。
|
|
177
|
+
*
|
|
178
|
+
* Next 16 起 dev 资源(HMR 与按需 chunk)默认只认 `localhost`,从 `127.0.0.1` 打开同一台
|
|
179
|
+
* 机器上的同一个服务会被判为跨 origin 而拦截。症状很有欺骗性:页面本身 200,
|
|
180
|
+
* 但 `next/dynamic` 的 chunk 永远拿不到,整页停在 "Loading page…",看起来像 SOMA 没挂载。
|
|
181
|
+
* 回环地址与 localhost 指向同一主机,这里补齐;反代域名等额外来源用
|
|
182
|
+
* `SOMA_DEV_ORIGINS`(逗号分隔)追加,不放宽到通配。
|
|
183
|
+
*/
|
|
184
|
+
const allowedDevOrigins = [
|
|
185
|
+
...new Set([
|
|
186
|
+
'localhost',
|
|
187
|
+
'127.0.0.1',
|
|
188
|
+
'[::1]',
|
|
189
|
+
...String(process.env.SOMA_DEV_ORIGINS ?? '')
|
|
190
|
+
.split(',')
|
|
191
|
+
.map((item) => item.trim())
|
|
192
|
+
.filter(Boolean),
|
|
193
|
+
]),
|
|
194
|
+
];
|
|
195
|
+
|
|
154
196
|
const nextConfig = {
|
|
155
197
|
env: {
|
|
156
198
|
SOMA_PAGE_RESPONSE_MODE: pageResponseConfig.mode,
|
|
157
199
|
},
|
|
158
200
|
|
|
201
|
+
allowedDevOrigins,
|
|
202
|
+
|
|
203
|
+
...(skipBuildChecks
|
|
204
|
+
? { typescript: { ignoreBuildErrors: true } }
|
|
205
|
+
: {}),
|
|
206
|
+
|
|
207
|
+
serverExternalPackages: ['jiti'],
|
|
208
|
+
|
|
159
209
|
experimental: {
|
|
160
210
|
externalDir: true,
|
|
161
|
-
|
|
211
|
+
// 低内存构建:并行 worker 是构建期内存的主要来源,小内存机器上把它压到 1
|
|
212
|
+
...(skipBuildChecks ? { cpus: 1, workerThreads: false } : {}),
|
|
162
213
|
},
|
|
163
214
|
|
|
164
215
|
transpilePackages,
|
|
@@ -167,8 +218,21 @@ const nextConfig = {
|
|
|
167
218
|
if (webpackCacheMode === 'memory' && dev) {
|
|
168
219
|
config.cache = { type: 'memory' };
|
|
169
220
|
}
|
|
221
|
+
if (dev) {
|
|
222
|
+
config.watchOptions = {
|
|
223
|
+
...config.watchOptions,
|
|
224
|
+
ignored: mergeWatchIgnored(config.watchOptions?.ignored),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
170
227
|
config.resolve.alias['@'] = __dirname;
|
|
171
228
|
config.resolve.alias['soma-core$'] = path.resolve(__dirname, 'core/index.ts');
|
|
229
|
+
// Webpack 不会对指向源码 `.ts` 的 package-export 子路径稳定做条件解析;
|
|
230
|
+
// 自适应布局词汇是 soma-ui 唯一需要的纯共享模块,显式落到同一份 core 源文件,
|
|
231
|
+
// 避免宿主开发服务器在首次编译时把 `soma-core/adaptive-vocabulary` 判成缺失。
|
|
232
|
+
config.resolve.alias['soma-core/adaptive-vocabulary$'] = path.resolve(
|
|
233
|
+
__dirname,
|
|
234
|
+
'core/shared/types/adaptive.types.ts',
|
|
235
|
+
);
|
|
172
236
|
config.resolve.alias['soma-core/base$'] = path.resolve(__dirname, 'core/client/base/index.ts');
|
|
173
237
|
config.resolve.alias['@core'] = path.resolve(__dirname, 'core');
|
|
174
238
|
for (const entry of hostFileDependencyEntries) {
|
|
@@ -196,13 +260,6 @@ const nextConfig = {
|
|
|
196
260
|
'bootstrap/soma-domain-loaders.ts',
|
|
197
261
|
'core/client/host-bridge/soma-domain-loaders.stub.ts',
|
|
198
262
|
);
|
|
199
|
-
config.resolve.alias['@soma-host/config/locale.yaml'] = resolveOptionalHostConfigFile(
|
|
200
|
-
'locale.yaml',
|
|
201
|
-
'core/server/host/locale.stub.ts',
|
|
202
|
-
);
|
|
203
|
-
config.resolve.alias['@soma-host/config/app.config.yaml'] = resolveHostAppConfigAlias(
|
|
204
|
-
'core/server/host/app-config.stub.ts',
|
|
205
|
-
);
|
|
206
263
|
config.resolve.alias['@soma-host'] = hostSourceRoot;
|
|
207
264
|
|
|
208
265
|
config.plugins.push(new SomaManifestWebpackPlugin({ hostDir }));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soma-core",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "SOMA — Semantic Oriented Modular Architecture. A declarative frontend framework runtime built on Next.js
|
|
3
|
+
"version": "1.3.4",
|
|
4
|
+
"description": "SOMA — Semantic Oriented Modular Architecture. A declarative frontend framework runtime built on Next.js 16 App Router.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"soma",
|
|
7
7
|
"declarative-ui",
|
|
@@ -42,7 +42,19 @@
|
|
|
42
42
|
"import": "./core/client/base/index.ts",
|
|
43
43
|
"default": "./core/client/base/index.ts"
|
|
44
44
|
},
|
|
45
|
+
"./registry": {
|
|
46
|
+
"types": "./dist/types/client/registry/index.d.ts",
|
|
47
|
+
"import": "./core/client/registry/index.ts",
|
|
48
|
+
"default": "./core/client/registry/index.ts"
|
|
49
|
+
},
|
|
50
|
+
"./adaptive": {
|
|
51
|
+
"types": "./dist/types/client/adaptive/index.d.ts",
|
|
52
|
+
"import": "./core/client/adaptive/index.ts",
|
|
53
|
+
"default": "./core/client/adaptive/index.ts"
|
|
54
|
+
},
|
|
55
|
+
"./adaptive-vocabulary": "./core/shared/types/adaptive.types.ts",
|
|
45
56
|
"./compiler/vite": "./core/build/compiler/vite-plugin-soma.ts",
|
|
57
|
+
"./compiler/precompile": "./core/build/compiler/soma-precompile.ts",
|
|
46
58
|
"./compiler/webpack-loader": "./core/build/compiler/soma-webpack-loader.js",
|
|
47
59
|
"./diagnostics": {
|
|
48
60
|
"types": "./dist/types/client/diagnostics/SomaTelemetry.d.ts",
|
|
@@ -60,6 +72,11 @@
|
|
|
60
72
|
"import": "./core/server/index.ts",
|
|
61
73
|
"default": "./core/server/index.ts"
|
|
62
74
|
},
|
|
75
|
+
"./server/registry": {
|
|
76
|
+
"types": "./dist/types/server/registry/index.d.ts",
|
|
77
|
+
"import": "./core/server/registry/index.ts",
|
|
78
|
+
"default": "./core/server/registry/index.ts"
|
|
79
|
+
},
|
|
63
80
|
"./mock/node": {
|
|
64
81
|
"types": "./core/server/mock/node/public.d.mts",
|
|
65
82
|
"import": "./core/server/mock/node/public.mjs",
|
|
@@ -74,7 +91,8 @@
|
|
|
74
91
|
"types": "./core/server/mock/testing/host-harness.d.mts",
|
|
75
92
|
"import": "./core/server/mock/testing/host-harness.mjs",
|
|
76
93
|
"default": "./core/server/mock/testing/host-harness.mjs"
|
|
77
|
-
}
|
|
94
|
+
},
|
|
95
|
+
"./package.json": "./package.json"
|
|
78
96
|
},
|
|
79
97
|
"files": [
|
|
80
98
|
"bin/soma.cjs",
|
|
@@ -87,7 +105,7 @@
|
|
|
87
105
|
"app/",
|
|
88
106
|
"dist/",
|
|
89
107
|
"dist/vscode/",
|
|
90
|
-
"
|
|
108
|
+
"proxy.ts",
|
|
91
109
|
"next.config.js",
|
|
92
110
|
"tailwind.config.ts",
|
|
93
111
|
"postcss.config.js",
|
|
@@ -95,7 +113,7 @@
|
|
|
95
113
|
"global.d.ts"
|
|
96
114
|
],
|
|
97
115
|
"engines": {
|
|
98
|
-
"node": ">=
|
|
116
|
+
"node": ">=20.9.0"
|
|
99
117
|
},
|
|
100
118
|
"scripts": {
|
|
101
119
|
"build:cli": "tsc -p tsconfig.cli.json",
|
|
@@ -105,8 +123,8 @@
|
|
|
105
123
|
"build:all": "npm run build:cli && npm run build:core-dist && npm run build:types",
|
|
106
124
|
"package:vscode": "node scripts/package-vscode.mjs",
|
|
107
125
|
"prepublishOnly": "npm run build:all",
|
|
108
|
-
"dev": "next dev",
|
|
109
|
-
"build": "next build",
|
|
126
|
+
"dev": "next dev --webpack",
|
|
127
|
+
"build": "next build --webpack",
|
|
110
128
|
"start": "next start",
|
|
111
129
|
"test": "vitest run && npm run test:mock",
|
|
112
130
|
"test:mock": "node --test tests/mock/*.test.mjs",
|
|
@@ -114,19 +132,20 @@
|
|
|
114
132
|
"verify:client-boundary": "node scripts/verify-client-boundary.mjs",
|
|
115
133
|
"verify:client-dep-graph": "node scripts/verify-client-dep-graph.mjs",
|
|
116
134
|
"test:watch": "vitest",
|
|
117
|
-
"typecheck": "tsc --noEmit"
|
|
135
|
+
"typecheck": "tsc --noEmit",
|
|
136
|
+
"verify:precompile": "node scripts/verify-precompile-fresh.mjs",
|
|
137
|
+
"theme:snapshot": "tsx scripts/build-theme-snapshot.mjs"
|
|
118
138
|
},
|
|
119
139
|
"dependencies": {
|
|
120
140
|
"ajv": "8.20.0",
|
|
121
141
|
"dompurify": "^3.4.12",
|
|
122
142
|
"jiti": "^1.21.7",
|
|
123
|
-
"js-yaml": "^4.3.0",
|
|
124
143
|
"msw": "2.15.0",
|
|
125
144
|
"reflect-metadata": "^0.2.1",
|
|
126
145
|
"server-only": "^0.0.1"
|
|
127
146
|
},
|
|
128
147
|
"peerDependencies": {
|
|
129
|
-
"next": ">=
|
|
148
|
+
"next": ">=16.3.1 <17",
|
|
130
149
|
"react": ">=18.0.0",
|
|
131
150
|
"react-dom": ">=18.0.0"
|
|
132
151
|
},
|
|
@@ -141,11 +160,14 @@
|
|
|
141
160
|
"ajv-formats": "3.0.1",
|
|
142
161
|
"autoprefixer": "^10.4.17",
|
|
143
162
|
"esbuild": "^0.25.12",
|
|
163
|
+
"js-yaml": "^4.3.1",
|
|
144
164
|
"jsdom": "^26.1.0",
|
|
145
|
-
"next": "
|
|
165
|
+
"next": "16.3.1",
|
|
166
|
+
"playwright": "^1.62.1",
|
|
146
167
|
"postcss": "^8.4.33",
|
|
147
168
|
"react": "^18.3.0",
|
|
148
169
|
"react-dom": "^18.3.0",
|
|
170
|
+
"semver": "^7.8.5",
|
|
149
171
|
"tailwindcss": "^3.4.1",
|
|
150
172
|
"typescript": "^5.3.3",
|
|
151
173
|
"vite": "6.4.3",
|
package/proxy.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import {
|
|
3
|
+
SOMA_PAGE_REQUEST_URL_HEADER,
|
|
4
|
+
shouldUseJsonPageResponse,
|
|
5
|
+
} from './core/server/host/page-response-request';
|
|
6
|
+
import {
|
|
7
|
+
createSomaCspHeader,
|
|
8
|
+
resolveSomaCspOptionsFromEnv,
|
|
9
|
+
SOMA_CSP_NONCE_HEADER,
|
|
10
|
+
} from './core/server/host/content-security-policy';
|
|
11
|
+
|
|
12
|
+
export function proxy(request: NextRequest) {
|
|
13
|
+
// CSP 默认关(SOMA_CSP 未设);开启时同时写请求头与响应头——
|
|
14
|
+
// 写请求头是 Next 的约定:框架据此给自己注入的内联脚本自动打 nonce。
|
|
15
|
+
const csp = createSomaCspHeader(resolveSomaCspOptionsFromEnv(process.env));
|
|
16
|
+
const requestHeaders = new Headers(request.headers);
|
|
17
|
+
if (csp) {
|
|
18
|
+
// 请求头恒用规范名(即使响应发的是 report-only):Next 只认这个名字来提取 nonce,
|
|
19
|
+
// 用 report-only 名字会让框架自己的内联脚本拿不到 nonce,report 档全是噪声违规
|
|
20
|
+
requestHeaders.set('content-security-policy', csp.value);
|
|
21
|
+
if (csp.nonce) {
|
|
22
|
+
requestHeaders.set(SOMA_CSP_NONCE_HEADER, csp.nonce);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const jsonPageResponse = shouldUseJsonPageResponse({
|
|
27
|
+
mode: process.env.SOMA_PAGE_RESPONSE_MODE,
|
|
28
|
+
method: request.method,
|
|
29
|
+
pathname: request.nextUrl.pathname,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!jsonPageResponse) {
|
|
33
|
+
const response = csp
|
|
34
|
+
? NextResponse.next({ request: { headers: requestHeaders } })
|
|
35
|
+
: NextResponse.next();
|
|
36
|
+
if (csp) {
|
|
37
|
+
response.headers.set(csp.name, csp.value);
|
|
38
|
+
}
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
requestHeaders.set(
|
|
43
|
+
SOMA_PAGE_REQUEST_URL_HEADER,
|
|
44
|
+
request.nextUrl.pathname + request.nextUrl.search,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const destination = new URL('/soma/page-object', request.url);
|
|
48
|
+
destination.search = '';
|
|
49
|
+
destination.searchParams.set('path', request.nextUrl.pathname);
|
|
50
|
+
|
|
51
|
+
const response = NextResponse.rewrite(destination, {
|
|
52
|
+
request: { headers: requestHeaders },
|
|
53
|
+
});
|
|
54
|
+
if (csp) {
|
|
55
|
+
response.headers.set(csp.name, csp.value);
|
|
56
|
+
}
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const config = {
|
|
61
|
+
matcher: ['/:path*'],
|
|
62
|
+
};
|
package/tailwind.config.ts
CHANGED
|
@@ -28,7 +28,6 @@ function loadHostPreset(): Config | null {
|
|
|
28
28
|
const hostPreset = loadHostPreset();
|
|
29
29
|
const sourceContent = getSomaAssetSources(hostDir).flatMap((source) => [
|
|
30
30
|
path.join(source.assetRoot, 'html/**/*.html'),
|
|
31
|
-
path.join(source.assetRoot, 'ui/**/*_style.yaml'),
|
|
32
31
|
path.join(source.assetRoot, 'styles/**/*.css'),
|
|
33
32
|
]);
|
|
34
33
|
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* _event.yaml 智能补全:锚点事件、事件类型、domain 方法
|
|
3
|
-
*/
|
|
4
|
-
const fs = require('node:fs');
|
|
5
|
-
const path = require('node:path');
|
|
6
|
-
|
|
7
|
-
const EVENT_TYPES = ['UI_REFRESH', 'NAV_ACTION', 'NAV_STATIC', 'UI_INTERACT', 'CONFIRM'];
|
|
8
|
-
const TRIGGERS = ['click', 'input', 'change', 'keydown.enter', 'submit'];
|
|
9
|
-
|
|
10
|
-
function extractSomaIdsFromHtml(html) {
|
|
11
|
-
const ids = new Set();
|
|
12
|
-
for (const m of html.matchAll(/data-soma-id=["']([^"']+)["']/g)) {
|
|
13
|
-
ids.add(m[1]);
|
|
14
|
-
}
|
|
15
|
-
return [...ids].sort();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function scanDomainMethods(hostDir, pageBase) {
|
|
19
|
-
const methods = [];
|
|
20
|
-
const classPath = path.join(hostDir, 'domain', 'ui', `${pageBase}Class.ts`);
|
|
21
|
-
if (!fs.existsSync(classPath)) return methods;
|
|
22
|
-
const src = fs.readFileSync(classPath, 'utf8');
|
|
23
|
-
for (const m of src.matchAll(/^\s+async\s+(\w+)\s*\(/gm)) methods.push(m[1]);
|
|
24
|
-
for (const m of src.matchAll(/^\s+(\w+)\s*\([^)]*\)\s*[:{]/gm)) {
|
|
25
|
-
if (!['constructor', 'onMount', 'onUnmount'].includes(m[1])) methods.push(m[1]);
|
|
26
|
-
}
|
|
27
|
-
return [...new Set(methods)].sort();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function pageBaseFromUri(uri, hostDir) {
|
|
31
|
-
if (!uri) return null;
|
|
32
|
-
const filePath = decodeURIComponent(uri.replace(/^file:\/\//, ''));
|
|
33
|
-
if (hostDir) {
|
|
34
|
-
const hostRoot = path.resolve(hostDir);
|
|
35
|
-
const resolved = path.resolve(filePath);
|
|
36
|
-
if (resolved.startsWith(hostRoot)) {
|
|
37
|
-
const rel = path.relative(hostRoot, resolved);
|
|
38
|
-
const mm = rel.match(/^event[/\\](.+)_event\.yaml$/);
|
|
39
|
-
if (mm) return mm[1].replace(/\\/g, '/');
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const name = path.basename(filePath);
|
|
43
|
-
const m = name.match(/^(.+)_event\.yaml$/);
|
|
44
|
-
return m ? m[1] : null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function linePrefix(text, position) {
|
|
48
|
-
const lines = text.split('\n');
|
|
49
|
-
return (lines[position.line] ?? '').slice(0, position.character);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function completionItem(label, detail, kind = 10) {
|
|
53
|
-
return { label, kind, detail, insertText: label };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function getEventYamlCompletions(hostDir, uri, text, position) {
|
|
57
|
-
const pageBase = pageBaseFromUri(uri, hostDir);
|
|
58
|
-
if (!pageBase) return [];
|
|
59
|
-
|
|
60
|
-
const prefix = linePrefix(text, position);
|
|
61
|
-
const trimmed = prefix.trim();
|
|
62
|
-
const items = [];
|
|
63
|
-
|
|
64
|
-
const htmlPath = path.join(hostDir, 'html', `${pageBase}.html`);
|
|
65
|
-
const somaIds = fs.existsSync(htmlPath) ? extractSomaIdsFromHtml(fs.readFileSync(htmlPath, 'utf8')) : [];
|
|
66
|
-
const methods = scanDomainMethods(hostDir, pageBase);
|
|
67
|
-
|
|
68
|
-
const anchorPartial = trimmed.match(/^([\w@]+)?$/);
|
|
69
|
-
if (anchorPartial && !trimmed.includes(':') && !trimmed.includes('|')) {
|
|
70
|
-
for (const id of somaIds) {
|
|
71
|
-
for (const trig of TRIGGERS) {
|
|
72
|
-
const label = `${id}.${trig}`;
|
|
73
|
-
if (!trimmed || label.startsWith(trimmed)) {
|
|
74
|
-
items.push(completionItem(`${label}: `, '事件锚点', 5));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return items;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const afterColon = prefix.match(/:\s*(\w*)$/);
|
|
82
|
-
if (afterColon) {
|
|
83
|
-
const partial = afterColon[1] ?? '';
|
|
84
|
-
for (const t of EVENT_TYPES) {
|
|
85
|
-
if (!partial || t.startsWith(partial)) {
|
|
86
|
-
items.push(completionItem(`${t} | `, '事件类型', 14));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return items;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const afterPipe = prefix.match(/\|\s*(page\.)?(\w*)$/);
|
|
93
|
-
if (afterPipe) {
|
|
94
|
-
const partial = afterPipe[2] ?? '';
|
|
95
|
-
for (const m of methods) {
|
|
96
|
-
if (!partial || m.startsWith(partial)) {
|
|
97
|
-
items.push(completionItem(`page.${m}`, 'domain 方法', 2));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return items;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return items;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
module.exports = { getEventYamlCompletions, EVENT_TYPES, TRIGGERS };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { ThemeConfig } from '../../shared/types/style-config.types';
|
|
2
|
-
|
|
3
|
-
const BUILTIN_THEME_VARS: Record<string, Record<string, string>> = {
|
|
4
|
-
dark: {
|
|
5
|
-
'--soma-bg': '#111827',
|
|
6
|
-
'--soma-fg': '#f9fafb',
|
|
7
|
-
'--soma-primary': '#60a5fa',
|
|
8
|
-
'--soma-border': '#374151',
|
|
9
|
-
},
|
|
10
|
-
light: {
|
|
11
|
-
'--soma-bg': '#ffffff',
|
|
12
|
-
'--soma-fg': '#111827',
|
|
13
|
-
'--soma-primary': '#3b82f6',
|
|
14
|
-
'--soma-border': '#e5e7eb',
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/** _style.yaml 主题切换时注入 CSS 变量(样式类仍由 Tailwind 提供) */
|
|
19
|
-
export function applyThemeVariables(
|
|
20
|
-
themeName: string | null,
|
|
21
|
-
themeConfig?: ThemeConfig,
|
|
22
|
-
root?: HTMLElement,
|
|
23
|
-
): void {
|
|
24
|
-
const el = root ?? (typeof document !== 'undefined' ? document.documentElement : null);
|
|
25
|
-
if (!el) return;
|
|
26
|
-
|
|
27
|
-
const vars = !themeName
|
|
28
|
-
? BUILTIN_THEME_VARS.light
|
|
29
|
-
: {
|
|
30
|
-
...(BUILTIN_THEME_VARS[themeName] ?? {}),
|
|
31
|
-
...(themeConfig?.vars ?? {}),
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
for (const [key, value] of Object.entries(vars)) {
|
|
35
|
-
el.style.setProperty(key, value);
|
|
36
|
-
}
|
|
37
|
-
}
|