soma-core 2.2.5 → 2.2.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/README.md +5 -6
- package/bin/soma.cjs +2 -2
- package/core/build/compiler/flat-page.ts +16 -0
- package/core/build/compiler/full-manifest-builder.ts +0 -3
- package/core/build/compiler/page-assets.ts +0 -1
- package/core/build/compiler/page-closure.ts +245 -0
- package/core/build/compiler/page-declaration-compiler.ts +2 -5
- package/core/build/compiler/soma-precompile.js +1972 -3312
- package/core/build/compiler/soma-precompile.ts +4 -7
- package/core/build/component-tree/artifact-codec.ts +4 -8
- package/core/build/lsp/soma-declaration.cjs +1 -1
- package/core/build/lsp/std-completion.generated.json +3 -3
- package/core/client/a11y/a11y-config.ts +2 -1
- package/core/client/a11y/dom-id.ts +1 -1
- package/core/client/base/SomaHttpClient.ts +11 -3
- package/core/client/base/SomaPageRootBase.ts +6 -0
- package/core/client/base/defineSomaView.ts +178 -0
- package/core/client/base/index.ts +13 -0
- package/core/client/base/view-context.ts +328 -0
- package/core/client/behavior/adapter-collection.ts +2 -2
- package/core/client/compiler/manifest-compiler.ts +5 -36
- package/core/client/component/component-definition.types.ts +2 -1
- package/core/client/component/component-manager.ts +110 -20
- package/core/client/component/structure-adapter.ts +3 -7
- package/core/client/container/IContainerAdapter.ts +4 -0
- package/core/client/container/SomaContainerAdapter.ts +52 -3
- package/core/client/data/data-object-resolver.ts +523 -184
- package/core/client/data/data-write-actions.ts +79 -15
- package/core/client/data/format-config.ts +3 -1
- package/core/client/data/region-scope-port.ts +11 -0
- package/core/client/engine/asset-resolver.ts +2 -5
- package/core/client/engine/dom-renderer.ts +7 -40
- package/core/client/engine/event-engine.ts +29 -108
- package/core/client/engine/property-watcher.ts +1 -1
- package/core/client/engine/reactive-proxy.ts +78 -17
- package/core/client/engine/runtime-builder.ts +0 -14
- package/core/client/engine/scope-resolver.ts +18 -0
- package/core/client/engine/soma-bootstrap.ts +387 -99
- package/core/client/engine/style-binder.ts +49 -106
- package/core/client/engine/timer-engine.ts +11 -1
- package/core/client/host-bridge/load-host-domain-class.ts +2 -1
- package/core/client/infra/http/SomaHttpService.ts +15 -4
- package/core/client/infra/i18n/pack-locales.ts +2 -2
- package/core/client/infra/notify/DefaultNotifyService.ts +2 -2
- package/core/client/mount/domain-rule.ts +7 -3
- package/core/client/mount/mount-page.ts +38 -5
- package/core/client/mount/types.ts +2 -0
- package/core/client/parser/confirm-spec.ts +100 -7
- package/core/client/parser/data-config-parser.ts +28 -211
- package/core/client/parser/pipeline-parser.ts +16 -60
- package/core/client/parser/style-config-parser.ts +101 -95
- package/core/client/parser/timer-parser.ts +21 -0
- package/core/client/parser/ui-config-parser.ts +64 -12
- package/core/client/registry/declaration-renderer.ts +1 -1
- package/core/client/render-ports/hide-transition.ts +9 -0
- package/core/client/render-ports/index.ts +4 -0
- package/core/client/render-ports/notify-renderer.ts +2 -1
- package/core/client/runtime/SomaRuntimeServices.ts +2 -1
- package/core/client/runtime/SomaSnapshotStore.ts +5 -0
- package/core/client/security/url-guard.ts +71 -11
- package/core/client/validation/async-check-registry.ts +2 -1
- package/core/client/validation/contract-validator.ts +2 -6
- package/core/client/validation/field-rules.ts +3 -13
- package/core/client/validation/object-rules.ts +2 -10
- package/core/index.ts +17 -39
- package/core/inspect/check-product.ts +5 -5
- package/core/inspect/runtime.ts +2 -1
- package/core/server/api/dispatch-service-api.ts +35 -36
- package/core/server/api/load-host-service.ts +8 -4
- package/core/server/api/paged-list.ts +259 -0
- package/core/server/compile-port.ts +1 -1
- package/core/server/host/app-config-composer.ts +2 -1
- package/core/server/host/empty-host-bootstrap.mjs +3 -0
- package/core/server/host/host-assembly-entry.ts +1 -0
- package/core/server/host/host-assembly.ts +50 -3
- package/core/server/host/host-caller.ts +2 -1
- package/core/server/host/host-dir.ts +9 -0
- package/core/server/host/host-response-headers.ts +2 -1
- package/core/server/host/invoke-host-request-hook.ts +28 -4
- package/core/server/host/published-page-assets.ts +2 -1
- package/core/server/host/resolve-host-request-hook.ts +25 -7
- package/core/server/host/server-page-assets.ts +4 -4
- package/core/server/host/source-aliases.cjs +345 -0
- package/core/server/host/source-aliases.ts +32 -0
- package/core/server/host/source-packages.cjs +1 -0
- package/core/server/host/virtual-pages.ts +3 -2
- package/core/server/infra/cache/ServerFileCache.ts +83 -10
- package/core/server/node.ts +10 -0
- package/core/server/registry/api-registry-store.ts +3 -1
- package/core/server/registry/declaration-precompiler.ts +0 -2
- package/core/server/registry/page-registry-repository.ts +2 -1
- package/core/server/registry/page-registry-store.ts +2 -1
- package/core/server/registry/registry-error.ts +6 -1
- package/core/server/registry/registry-file-lock.ts +296 -23
- package/core/server/registry/request-body-limit.ts +3 -2
- package/core/server/registry/validation/declaration-safety-scan.ts +151 -27
- package/core/server/runtime-space/access-gate.ts +21 -7
- package/core/server/runtime-space/bindings.ts +3 -6
- package/core/server/runtime-space/dynamic-pages.ts +181 -49
- package/core/server/runtime-space/errors.ts +3 -0
- package/core/server/runtime-space/inject.ts +78 -16
- package/core/server/runtime-space/page-grants.ts +7 -1
- package/core/server/runtime-space/resolve.ts +66 -19
- package/core/server/runtime-space/store.ts +32 -3
- package/core/server/runtime-space/submit-steps.ts +2 -1
- package/core/server/runtime-space/types.ts +3 -1
- package/core/shared/component-tree-errors.ts +2 -1
- package/core/shared/contract-a11y.ts +1 -1
- package/core/shared/contract-sections.ts +2 -2
- package/core/shared/core-diagnostic-codes.ts +14 -0
- package/core/shared/data-declaration-checks.ts +29 -3
- package/core/shared/declaration-keys.ts +1 -1
- package/core/shared/engines/engine-error.ts +2 -1
- package/core/shared/generation-error.ts +2 -1
- package/core/shared/page-envelope.ts +1 -1
- package/core/shared/pure-binding.ts +88 -0
- package/core/shared/registry-generated/diagnostic-registry-index.ts +21 -19
- package/core/shared/registry-generated/diagnostic-registry.ts +170 -177
- package/core/shared/registry-generated/limits.ts +65 -13
- package/core/shared/registry-generated/std-grammar-completion.ts +0 -4
- package/core/shared/registry-generated/std-grammar-views.ts +40 -10
- package/core/shared/registry-generated/std-grammar.ts +43 -21
- package/core/shared/soma-error.ts +36 -0
- package/core/shared/types/compile-port.types.ts +1 -1
- package/core/shared/types/data-config.types.ts +20 -18
- package/core/shared/types/engine.types.ts +0 -3
- package/core/shared/types/event.types.ts +10 -11
- package/core/shared/types/generation-error.types.ts +5 -1
- package/core/shared/types/host-assembly.types.ts +7 -1
- package/core/shared/types/manifest.types.ts +0 -3
- package/core/shared/types/region-scope.types.ts +5 -1
- package/core/shared/types/scope-manifest.types.ts +0 -2
- package/core/shared/types/style-config.types.ts +21 -21
- package/core/shared/types/ui-config.types.ts +4 -5
- package/core/shared/types/watcher.types.ts +1 -1
- package/dist/browser/runtime-bundle.manifest.json +11 -13
- package/dist/browser/soma-runtime.js +2733 -2712
- package/dist/core/index.cjs +5665 -5534
- package/dist/host-native/aot-builder.cjs +330 -1
- package/dist/host-native/native-server.cjs +5434 -4726
- package/dist/lsp/component-tree.cjs +5868 -7040
- package/dist/types/build/compiler/full-manifest-builder.d.ts +0 -2
- package/dist/types/build/compiler/page-closure.d.ts +21 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -4
- package/dist/types/build/compiler/soma-precompile.d.ts +1 -3
- package/dist/types/build/component-tree/artifact-codec.d.ts +0 -2
- package/dist/types/client/a11y/a11y-config.d.ts +2 -1
- package/dist/types/client/base/SomaHttpClient.d.ts +1 -1
- package/dist/types/client/base/SomaPageRootBase.d.ts +5 -0
- package/dist/types/client/base/defineSomaView.d.ts +46 -0
- package/dist/types/client/base/index.d.ts +2 -0
- package/dist/types/client/base/view-context.d.ts +136 -0
- package/dist/types/client/behavior/adapter-collection.d.ts +1 -1
- package/dist/types/client/compiler/manifest-compiler.d.ts +0 -3
- package/dist/types/client/component/component-definition.types.d.ts +2 -1
- package/dist/types/client/component/component-manager.d.ts +29 -0
- package/dist/types/client/container/IContainerAdapter.d.ts +3 -0
- package/dist/types/client/container/SomaContainerAdapter.d.ts +5 -0
- package/dist/types/client/data/data-object-resolver.d.ts +93 -31
- package/dist/types/client/data/format-config.d.ts +2 -1
- package/dist/types/client/engine/dom-renderer.d.ts +1 -2
- package/dist/types/client/engine/event-engine.d.ts +0 -7
- package/dist/types/client/engine/reactive-proxy.d.ts +11 -4
- package/dist/types/client/engine/runtime-builder.d.ts +0 -4
- package/dist/types/client/engine/soma-bootstrap.d.ts +44 -6
- package/dist/types/client/engine/style-binder.d.ts +8 -4
- package/dist/types/client/host-bridge/load-host-domain-class.d.ts +2 -1
- package/dist/types/client/mount/domain-rule.d.ts +2 -0
- package/dist/types/client/mount/mount-page.d.ts +2 -1
- package/dist/types/client/mount/types.d.ts +2 -0
- package/dist/types/client/parser/confirm-spec.d.ts +27 -3
- package/dist/types/client/parser/data-config-parser.d.ts +6 -5
- package/dist/types/client/parser/style-config-parser.d.ts +7 -3
- package/dist/types/client/parser/timer-parser.d.ts +5 -0
- package/dist/types/client/parser/ui-config-parser.d.ts +6 -2
- package/dist/types/client/render-ports/hide-transition.d.ts +9 -0
- package/dist/types/client/render-ports/index.d.ts +4 -0
- package/dist/types/client/render-ports/notify-renderer.d.ts +2 -1
- package/dist/types/client/runtime/SomaSnapshotStore.d.ts +2 -0
- package/dist/types/client/security/url-guard.d.ts +14 -0
- package/dist/types/client/validation/async-check-registry.d.ts +2 -1
- package/dist/types/client/validation/object-rules.d.ts +0 -5
- package/dist/types/index.d.ts +6 -11
- package/dist/types/inspect/runtime.d.ts +2 -1
- package/dist/types/server/api/dispatch-service-api.d.ts +5 -0
- package/dist/types/server/api/load-host-service.d.ts +1 -1
- package/dist/types/server/api/paged-list.d.ts +101 -0
- package/dist/types/server/compile-port.d.ts +1 -1
- package/dist/types/server/host/host-assembly-entry.d.ts +1 -1
- package/dist/types/server/host/host-assembly.d.ts +2 -0
- package/dist/types/server/host/host-dir.d.ts +2 -0
- package/dist/types/server/host/invoke-host-request-hook.d.ts +10 -3
- package/dist/types/server/host/published-page-assets.d.ts +2 -1
- package/dist/types/server/host/resolve-host-request-hook.d.ts +18 -5
- package/dist/types/server/host/server-page-assets.d.ts +2 -1
- package/dist/types/server/host/source-aliases.d.cts +53 -0
- package/dist/types/server/host/source-aliases.d.ts +30 -0
- package/dist/types/server/host/source-packages.d.cts +2 -0
- package/dist/types/server/infra/cache/ServerFileCache.d.ts +8 -0
- package/dist/types/server/node.d.ts +1 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +0 -1
- package/dist/types/server/registry/registry-error.d.ts +5 -1
- package/dist/types/server/registry/registry-file-lock.d.ts +30 -0
- package/dist/types/server/registry/request-body-limit.d.ts +3 -2
- package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +3 -0
- package/dist/types/server/runtime-space/access-gate.d.ts +7 -0
- package/dist/types/server/runtime-space/bindings.d.ts +3 -2
- package/dist/types/server/runtime-space/dynamic-pages.d.ts +6 -1
- package/dist/types/server/runtime-space/errors.d.ts +1 -1
- package/dist/types/server/runtime-space/resolve.d.ts +2 -0
- package/dist/types/server/runtime-space/store.d.ts +8 -1
- package/dist/types/server/runtime-space/submit-steps.d.ts +2 -1
- package/dist/types/server/runtime-space/types.d.ts +3 -1
- package/dist/types/shared/component-tree-errors.d.ts +2 -1
- package/dist/types/shared/core-diagnostic-codes.d.ts +1 -1
- package/dist/types/shared/declaration-keys.d.ts +1 -1
- package/dist/types/shared/engines/engine-error.d.ts +2 -1
- package/dist/types/shared/generation-error.d.ts +2 -1
- package/dist/types/shared/pure-binding.d.ts +48 -0
- package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +149 -158
- package/dist/types/shared/registry-generated/limits.d.ts +54 -10
- package/dist/types/shared/registry-generated/std-grammar-completion.d.ts +0 -30
- package/dist/types/shared/registry-generated/std-grammar-views.d.ts +97 -23
- package/dist/types/shared/registry-generated/std-grammar.d.ts +110 -242
- package/dist/types/shared/soma-error.d.ts +15 -0
- package/dist/types/shared/types/data-config.types.d.ts +17 -17
- package/dist/types/shared/types/engine.types.d.ts +0 -3
- package/dist/types/shared/types/event.types.d.ts +9 -7
- package/dist/types/shared/types/generation-error.types.d.ts +1 -1
- package/dist/types/shared/types/host-assembly.types.d.ts +2 -0
- package/dist/types/shared/types/manifest.types.d.ts +0 -3
- package/dist/types/shared/types/region-scope.types.d.ts +4 -1
- package/dist/types/shared/types/scope-manifest.types.d.ts +0 -2
- package/dist/types/shared/types/style-config.types.d.ts +17 -19
- package/dist/types/shared/types/ui-config.types.d.ts +4 -5
- package/host-native/bin/host-native.cjs +22 -1
- package/host-native/client/browser-entry.ts +21 -172
- package/host-native/src/aot-builder.ts +75 -0
- package/host-native/src/host-prepare.ts +39 -5
- package/host-native/src/manifest-http.ts +2 -3
- package/host-native/src/native-server.ts +812 -174
- package/host-native/src/page-http.ts +3 -3
- package/host-native/src/public-packages.cjs +0 -1
- package/host-native/src/registry-handler.ts +12 -5
- package/host-native/src/static-file.ts +203 -53
- package/host-native/styles/globals.css +30 -28
- package/package.json +14 -2
- package/core/client/engine/step-runner.ts +0 -212
- package/core/client/engine/trigger-engine.ts +0 -55
- package/core/client/format/zoned.ts +0 -10
- package/core/client/parser/step-parser.ts +0 -359
- package/core/client/parser/trigger-parser.ts +0 -90
- package/core/client/parser/value-lang.ts +0 -340
- package/core/client/time/instant.ts +0 -2
- package/core/shared/calc/coerce.ts +0 -2
- package/core/shared/calc/errors.ts +0 -40
- package/core/shared/calc/evaluator.ts +0 -113
- package/core/shared/calc/index.ts +0 -11
- package/core/shared/calc/lexer.ts +0 -189
- package/core/shared/calc/parser.ts +0 -193
- package/core/shared/calc/typer.ts +0 -171
- package/core/shared/date-parts.ts +0 -2
- package/core/shared/show-when.ts +0 -77
- package/core/shared/types/step.types.ts +0 -91
- package/core/shared/types/trigger.types.ts +0 -14
- package/dist/types/client/engine/step-runner.d.ts +0 -42
- package/dist/types/client/engine/trigger-engine.d.ts +0 -16
- package/dist/types/client/format/zoned.d.ts +0 -1
- package/dist/types/client/parser/step-parser.d.ts +0 -23
- package/dist/types/client/parser/trigger-parser.d.ts +0 -13
- package/dist/types/client/parser/value-lang.d.ts +0 -63
- package/dist/types/client/time/instant.d.ts +0 -1
- package/dist/types/shared/calc/coerce.d.ts +0 -1
- package/dist/types/shared/calc/errors.d.ts +0 -14
- package/dist/types/shared/calc/evaluator.d.ts +0 -2
- package/dist/types/shared/calc/index.d.ts +0 -6
- package/dist/types/shared/calc/lexer.d.ts +0 -19
- package/dist/types/shared/calc/parser.d.ts +0 -43
- package/dist/types/shared/calc/typer.d.ts +0 -11
- package/dist/types/shared/date-parts.d.ts +0 -1
- package/dist/types/shared/show-when.d.ts +0 -21
- package/dist/types/shared/types/step.types.d.ts +0 -76
- package/dist/types/shared/types/trigger.types.d.ts +0 -12
|
@@ -5,27 +5,20 @@
|
|
|
5
5
|
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
6
6
|
import type {
|
|
7
7
|
StyleConfig,
|
|
8
|
-
StyleStateRule,
|
|
9
8
|
} from '../../shared/types/style-config.types';
|
|
10
9
|
|
|
11
10
|
// ─── 内部类型 ─────────────────────────────────────────────────────────────────
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
/** 类名档位绑定(states 与 active_state 同形):成员的值就是档位名,命中档位则加该档类名 */
|
|
13
|
+
interface TierBinding {
|
|
14
14
|
somaId: string;
|
|
15
15
|
element: HTMLElement;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
/** 档位名 → 类名数组 */
|
|
17
|
+
tiers: Map<string, string[]>;
|
|
18
|
+
/** 当前被该绑定附加的类名(换档时一次性移除) */
|
|
18
19
|
currentClasses: Set<string>;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
interface ActiveStateBinding {
|
|
22
|
-
somaId: string;
|
|
23
|
-
element: HTMLElement;
|
|
24
|
-
value: string | number | boolean | null;
|
|
25
|
-
applyClasses: string[];
|
|
26
|
-
active: boolean;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
22
|
interface LeaveAnimation {
|
|
30
23
|
element: HTMLElement;
|
|
31
24
|
classes: string[];
|
|
@@ -44,8 +37,8 @@ export interface SomaStyleBinderOptions {
|
|
|
44
37
|
*
|
|
45
38
|
* 将 _style.yaml 的声明式配置转化为运行时的事件注册与执行:
|
|
46
39
|
* - base:初始化时一次性附加固定类名
|
|
47
|
-
* - states
|
|
48
|
-
* - transitions:绑定 DOM 原生事件(hover/focus/active
|
|
40
|
+
* - states:纯绑定,`bind` 路径的值是档位名,换档时正交切换类名(不比较)
|
|
41
|
+
* - transitions:绑定 DOM 原生事件(hover/focus/active),或 active_state(同 states 的档位绑定)
|
|
49
42
|
* 主题不在此:`themes` 段与内置主题变量已退役(主题是编译期事,运行期无主题切换,T19)。
|
|
50
43
|
*/
|
|
51
44
|
export class SomaStyleBinder {
|
|
@@ -54,11 +47,11 @@ export class SomaStyleBinder {
|
|
|
54
47
|
private readonly styleConfig: StyleConfig;
|
|
55
48
|
private readonly abortController = new AbortController();
|
|
56
49
|
|
|
57
|
-
/** 属性路径 →
|
|
58
|
-
private stateIndex = new Map<string,
|
|
50
|
+
/** 属性路径 → TierBinding[]:states 块的事件索引 */
|
|
51
|
+
private stateIndex = new Map<string, TierBinding[]>();
|
|
59
52
|
|
|
60
|
-
/** 属性路径 →
|
|
61
|
-
private activeStateIndex = new Map<string,
|
|
53
|
+
/** 属性路径 → TierBinding[]:transitions active_state 的事件索引 */
|
|
54
|
+
private activeStateIndex = new Map<string, TierBinding[]>();
|
|
62
55
|
|
|
63
56
|
/** somaId → base 类名数组 */
|
|
64
57
|
private baseClasses = new Map<string, string[]>();
|
|
@@ -93,44 +86,23 @@ export class SomaStyleBinder {
|
|
|
93
86
|
* 查询 stateIndex 和 activeStateIndex,对匹配的绑定执行类名切换
|
|
94
87
|
*/
|
|
95
88
|
onPropertyChange(path: string, newValue: any): void {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
for (const binding of stateBindings) {
|
|
100
|
-
// 移除当前所有 state 附加的类名
|
|
101
|
-
if (binding.currentClasses.size > 0) {
|
|
102
|
-
this.adapter.toggleClasses(
|
|
103
|
-
binding.element,
|
|
104
|
-
[...binding.currentClasses],
|
|
105
|
-
false,
|
|
106
|
-
);
|
|
107
|
-
binding.currentClasses.clear();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// 找到匹配的规则,应用其类名
|
|
111
|
-
for (const rule of binding.rules) {
|
|
112
|
-
if (rule.value === newValue) {
|
|
113
|
-
const classes = rule.apply.split(' ').filter(Boolean);
|
|
114
|
-
if (classes.length > 0) {
|
|
115
|
-
this.adapter.toggleClasses(binding.element, classes, true);
|
|
116
|
-
for (const c of classes) {
|
|
117
|
-
binding.currentClasses.add(c);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
89
|
+
this.applyTier(this.stateIndex.get(path), newValue);
|
|
90
|
+
this.applyTier(this.activeStateIndex.get(path), newValue);
|
|
91
|
+
}
|
|
124
92
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
93
|
+
/** 换档:先移除上一档附加的类名,再加新档位的类名;值不在档位闭集内则不加任何类 */
|
|
94
|
+
private applyTier(bindings: TierBinding[] | undefined, value: unknown): void {
|
|
95
|
+
if (!bindings) return;
|
|
96
|
+
const tier = value === null || value === undefined ? '' : String(value);
|
|
97
|
+
for (const binding of bindings) {
|
|
98
|
+
if (binding.currentClasses.size > 0) {
|
|
99
|
+
this.adapter.toggleClasses(binding.element, [...binding.currentClasses], false);
|
|
100
|
+
binding.currentClasses.clear();
|
|
101
|
+
}
|
|
102
|
+
const classes = binding.tiers.get(tier);
|
|
103
|
+
if (classes && classes.length > 0) {
|
|
104
|
+
this.adapter.toggleClasses(binding.element, classes, true);
|
|
105
|
+
for (const c of classes) binding.currentClasses.add(c);
|
|
134
106
|
}
|
|
135
107
|
}
|
|
136
108
|
}
|
|
@@ -169,68 +141,39 @@ export class SomaStyleBinder {
|
|
|
169
141
|
}
|
|
170
142
|
}
|
|
171
143
|
|
|
144
|
+
/** 把 `{ bind, tiers }` 登记进索引 */
|
|
145
|
+
private indexTierBinding(
|
|
146
|
+
index: Map<string, TierBinding[]>,
|
|
147
|
+
somaId: string,
|
|
148
|
+
config: { bind: string; tiers: Record<string, string> },
|
|
149
|
+
): void {
|
|
150
|
+
const el = this.adapter.findAnchor(this.container, somaId);
|
|
151
|
+
if (!el) return;
|
|
152
|
+
|
|
153
|
+
const tiers = new Map<string, string[]>();
|
|
154
|
+
for (const [tier, classes] of Object.entries(config.tiers)) {
|
|
155
|
+
tiers.set(tier, classes.split(' ').filter(Boolean));
|
|
156
|
+
}
|
|
157
|
+
const binding: TierBinding = { somaId, element: el, tiers, currentClasses: new Set() };
|
|
158
|
+
const existing = index.get(config.bind);
|
|
159
|
+
if (existing) existing.push(binding);
|
|
160
|
+
else index.set(config.bind, [binding]);
|
|
161
|
+
}
|
|
162
|
+
|
|
172
163
|
/** 从 states 配置构建属性事件索引 */
|
|
173
164
|
private buildStateIndex(): void {
|
|
174
165
|
this.stateIndex.clear();
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const el = this.adapter.findAnchor(this.container, somaId);
|
|
178
|
-
if (!el) continue;
|
|
179
|
-
|
|
180
|
-
// 按 condition 路径分组(同一路径的规则归为一个 StateBinding)
|
|
181
|
-
const byCondition = new Map<string, StyleStateRule[]>();
|
|
182
|
-
for (const rule of rules) {
|
|
183
|
-
const existing = byCondition.get(rule.condition);
|
|
184
|
-
if (existing) {
|
|
185
|
-
existing.push(rule);
|
|
186
|
-
} else {
|
|
187
|
-
byCondition.set(rule.condition, [rule]);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
for (const [condition, condRules] of byCondition) {
|
|
192
|
-
const binding: StateBinding = {
|
|
193
|
-
somaId,
|
|
194
|
-
element: el,
|
|
195
|
-
rules: condRules,
|
|
196
|
-
currentClasses: new Set(),
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const existing = this.stateIndex.get(condition);
|
|
200
|
-
if (existing) {
|
|
201
|
-
existing.push(binding);
|
|
202
|
-
} else {
|
|
203
|
-
this.stateIndex.set(condition, [binding]);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
166
|
+
for (const [somaId, config] of Object.entries(this.styleConfig.states)) {
|
|
167
|
+
this.indexTierBinding(this.stateIndex, somaId, config);
|
|
206
168
|
}
|
|
207
169
|
}
|
|
208
170
|
|
|
209
171
|
/** 从 transitions active_state 配置构建属性事件索引 */
|
|
210
172
|
private buildActiveStateIndex(): void {
|
|
211
173
|
this.activeStateIndex.clear();
|
|
212
|
-
|
|
213
174
|
for (const [somaId, transition] of Object.entries(this.styleConfig.transitions)) {
|
|
214
175
|
if (transition.trigger !== 'active_state') continue;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const el = this.adapter.findAnchor(this.container, somaId);
|
|
218
|
-
if (!el) continue;
|
|
219
|
-
|
|
220
|
-
const binding: ActiveStateBinding = {
|
|
221
|
-
somaId,
|
|
222
|
-
element: el,
|
|
223
|
-
value: transition.value ?? null,
|
|
224
|
-
applyClasses: transition.apply.split(' ').filter(Boolean),
|
|
225
|
-
active: false,
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
const existing = this.activeStateIndex.get(transition.condition);
|
|
229
|
-
if (existing) {
|
|
230
|
-
existing.push(binding);
|
|
231
|
-
} else {
|
|
232
|
-
this.activeStateIndex.set(transition.condition, [binding]);
|
|
233
|
-
}
|
|
176
|
+
this.indexTierBinding(this.activeStateIndex, somaId, transition);
|
|
234
177
|
}
|
|
235
178
|
}
|
|
236
179
|
|
|
@@ -36,12 +36,22 @@ export class SomaTimerEngine {
|
|
|
36
36
|
|
|
37
37
|
for (const timer of options.timers) {
|
|
38
38
|
const compiled = compileTimer(timer);
|
|
39
|
+
// 「执行中则跳过」(不重入):处理函数返回的 Promise 必须最终结束,否则该定时器永远处于执行中、不再触发
|
|
40
|
+
// (不引入超时数字,语义如此)。标记是每次 start 新建的闭包变量:stop / 销毁后重新 start 得到全新标记,
|
|
41
|
+
// 旧闭包里卡住的标记不会带到新一轮,所以重新启动后能正常触发。
|
|
42
|
+
let running = false;
|
|
39
43
|
const run = () => {
|
|
40
|
-
|
|
44
|
+
if (running) return;
|
|
45
|
+
const result: unknown = options.eventEngine.execute(
|
|
41
46
|
this.toCompiledEvent(compiled),
|
|
42
47
|
this.anchorEl!,
|
|
43
48
|
new Event('tick'),
|
|
44
49
|
);
|
|
50
|
+
if (result && typeof (result as Promise<unknown>).then === 'function') {
|
|
51
|
+
running = true;
|
|
52
|
+
const done = () => { running = false; };
|
|
53
|
+
(result as Promise<unknown>).then(done, done);
|
|
54
|
+
}
|
|
45
55
|
};
|
|
46
56
|
|
|
47
57
|
const register = () => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// 静态专用(RT4,《core 标准格式与 runtime 空间》§6.3 / §12 Q4):Domain 类只对磁盘上的静态页按名加载(构建期 webpackInclude 收入),
|
|
2
2
|
// 不推荐新页使用;运行期注入 / Registry 发布的页面没有这个通道,一律缺省根,页面行为写 `ACTION | 名字` 并在 browserMount.actions 登记。
|
|
3
3
|
// 动态页写了 domain 的提示判据见 ../mount/domain-rule.ts(CORE-RUNTIME-DOMAIN-STATIC-ONLY)。
|
|
4
|
+
import { SomaError } from '../../shared/soma-error';
|
|
4
5
|
import { SomaLocaleOnlyPageRoot } from '../base/SomaLocaleOnlyPageRoot';
|
|
5
6
|
import type { SomaPageRoot } from '../../shared/types/domain.types';
|
|
6
7
|
import {
|
|
@@ -15,7 +16,7 @@ const HOST_DOMAIN_LOADERS_MODULE = '@soma-host/bootstrap/soma-domain-loaders';
|
|
|
15
16
|
|
|
16
17
|
export type SomaDomainConstructor = new () => SomaPageRoot;
|
|
17
18
|
|
|
18
|
-
export class SomaDomainLoadError extends
|
|
19
|
+
export class SomaDomainLoadError extends SomaError {
|
|
19
20
|
readonly code = 'SOMA_DOMAIN_LOAD_FAILED';
|
|
20
21
|
readonly context: SomaDomainLoadContext;
|
|
21
22
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// `@/` alias. This import is preserved in emitted declarations, so an
|
|
3
3
|
// internal alias here would leak into every Host's typecheck.
|
|
4
4
|
import { SomaHttpClient, SomaHttpClientConfig, describeHttpErrorBody } from 'soma-core/base';
|
|
5
|
+
import { SOMA_PIPELINE_HOST_HTTP_REQUEST_TIMEOUT_MS } from 'soma-foundation/values';
|
|
5
6
|
import { IHttpClient, HttpRequestConfig, UploadOptions } from './IHttpClient';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -165,12 +166,15 @@ export class SomaHttpService implements IHttpClient {
|
|
|
165
166
|
const controller = new AbortController();
|
|
166
167
|
this.abortControllers.add(controller);
|
|
167
168
|
|
|
168
|
-
const timeout = config?.timeout ??
|
|
169
|
+
const timeout = config?.timeout ?? SOMA_PIPELINE_HOST_HTTP_REQUEST_TIMEOUT_MS;
|
|
169
170
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
170
171
|
|
|
171
172
|
// If caller provides an external signal, forward its abort.
|
|
172
|
-
|
|
173
|
-
|
|
173
|
+
const externalSignal = config?.signal;
|
|
174
|
+
const onExternalAbort = () => controller.abort();
|
|
175
|
+
if (externalSignal) {
|
|
176
|
+
if (externalSignal.aborted) controller.abort();
|
|
177
|
+
else externalSignal.addEventListener('abort', onExternalAbort, { once: true });
|
|
174
178
|
}
|
|
175
179
|
|
|
176
180
|
try {
|
|
@@ -211,9 +215,16 @@ export class SomaHttpService implements IHttpClient {
|
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
try { config?.onResponse?.({ status: res.status }); } catch { /* 状态回调抛错不影响请求结果 */ }
|
|
214
|
-
|
|
218
|
+
// 204 / 205 / 空响应体:成功但无内容,返回 undefined(不当 JSON 解析失败)
|
|
219
|
+
if (res.status === 204 || res.status === 205) return undefined as T;
|
|
220
|
+
// 兼容只实现 json() 的响应对象(测试桩 / 精简 polyfill)
|
|
221
|
+
if (typeof res.text !== 'function') return (await res.json()) as T;
|
|
222
|
+
const rawText = await res.text();
|
|
223
|
+
if (rawText.trim() === '') return undefined as T;
|
|
224
|
+
return JSON.parse(rawText) as T;
|
|
215
225
|
} finally {
|
|
216
226
|
clearTimeout(timeoutId);
|
|
227
|
+
if (externalSignal) externalSignal.removeEventListener('abort', onExternalAbort);
|
|
217
228
|
this.abortControllers.delete(controller);
|
|
218
229
|
}
|
|
219
230
|
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// 声明形态(TS 包对象的 `locales` 字段,或文件态包根目录的 `locales.yaml`,两者同一形状):
|
|
4
4
|
//
|
|
5
5
|
// locales:
|
|
6
|
-
// zh-CN: {
|
|
7
|
-
// en: {
|
|
6
|
+
// zh-CN: { pack.table.empty: 暂无数据, pack.pager.total: 共 {total} 条 }
|
|
7
|
+
// en: { pack.table.empty: No data, pack.pager.total: '{total} items' }
|
|
8
8
|
//
|
|
9
9
|
// 顶层键只能是语言标签(BCP 47 形),值是 { 词条键: 文案 };文案插值沿用目录的 `{name}`。
|
|
10
10
|
// 优先级沿用目录:应用词表 > 组件包词条(后注册的包优先) > core 内置受控词表;语言回落链 当前语言 → 主标签 → 应用缺省语言 → 包缺省语言。
|
|
@@ -62,8 +62,8 @@ export class DefaultNotifyService implements INotifyService {
|
|
|
62
62
|
return this.renderer.confirm({
|
|
63
63
|
message: spec.text,
|
|
64
64
|
...(title === undefined ? {} : { title }),
|
|
65
|
-
// plain
|
|
66
|
-
...(spec.level === 'plain' ? {} : { spec }),
|
|
65
|
+
// plain 且无语气不带 spec:旧渲染器与旧测试看到的请求逐字不变
|
|
66
|
+
...(spec.level === 'plain' && spec.tone === undefined ? {} : { spec }),
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
return this.confirmResult;
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
//
|
|
3
3
|
// 规则:
|
|
4
4
|
// · page 块的 `domain` 可选;缺省就是缺省根 `SomaLocaleOnlyPageRoot`;
|
|
5
|
-
// · 来源是 inject / registry(含前缀绑定)的页面写了非缺省的 `domain
|
|
6
|
-
//
|
|
5
|
+
// · 来源是 inject / registry(含前缀绑定)的页面写了非缺省的 `domain:`,且该名没有经 Host 的 `pageRoots` 类表提供
|
|
6
|
+
// (`provided`)→ 提示 `CORE-RUNTIME-DOMAIN-STATIC-ONLY`,运行期退成缺省根,页面行为写 `ACTION | 名字` 并在 `actions` 登记;
|
|
7
|
+
// 方言把展示对象类登记进 `pageRoots`(kit 的 `defineKitView`)的页面不提示;
|
|
7
8
|
// · 静态页继续支持 Domain 类(兼容,标为静态专用)。
|
|
8
9
|
// 注入期(RT2)与挂载期(mountSomaPage)共用本函数,判据只有这一份。
|
|
9
10
|
|
|
@@ -27,8 +28,11 @@ export interface SomaDomainHint {
|
|
|
27
28
|
export function domainStaticOnlyHint(input: {
|
|
28
29
|
readonly origin: SomaDomainRuleOrigin | undefined;
|
|
29
30
|
readonly domain: unknown;
|
|
31
|
+
/** 这个 domain 名已由 Host 的 `pageRoots` 类表提供类(挂载期按注册表判;注入期由方言所有者声明) */
|
|
32
|
+
readonly provided?: boolean;
|
|
30
33
|
}): SomaDomainHint | null {
|
|
31
34
|
if (input.origin === undefined || input.origin === 'static') return null;
|
|
35
|
+
if (input.provided === true) return null;
|
|
32
36
|
if (typeof input.domain !== 'string') return null;
|
|
33
37
|
const domain = input.domain.trim();
|
|
34
38
|
if (domain === '' || domain === SOMA_DEFAULT_PAGE_DOMAIN) return null;
|
|
@@ -37,7 +41,7 @@ export function domainStaticOnlyHint(input: {
|
|
|
37
41
|
severity: 'advice',
|
|
38
42
|
domain,
|
|
39
43
|
message:
|
|
40
|
-
`动态来源的页面写了 domain: ${domain}
|
|
44
|
+
`动态来源的页面写了 domain: ${domain},该名没有经 Host 的 pageRoots 类表登记,本页运行期按缺省页面根挂载(展示对象类请登记进 browserMount().pageRoots / mountSomaPage 的 pageRoots)。`
|
|
41
45
|
+ '页面行为请写 `ACTION | 名字`,并在 mountSomaPage 的 actions(或 browserMount.actions)里登记同名实现。',
|
|
42
46
|
};
|
|
43
47
|
}
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
// 差别只在打包器;本文件不依赖 React / Next,不读 `@soma-host/*` 别名(原生场景没有它)。
|
|
5
5
|
//
|
|
6
6
|
// 流程:取资产(按地址走服务协议,或直接收资产)→ 合成组件包 → 建 SomaBootstrap → mount。
|
|
7
|
-
// Domain
|
|
7
|
+
// Domain 类:动态来源页的展示对象只经 options.pageRoots(应用 browserMount().pageRoots)按 `domain:` 名取;没登记的一律缺省根,写了 domain 只给提示(domain-rule)。
|
|
8
8
|
|
|
9
|
+
import { SomaError } from '../../shared/soma-error';
|
|
9
10
|
import { SomaBootstrap, type SomaPageAssets } from '../engine/soma-bootstrap';
|
|
10
11
|
import { composeComponentPacks, type SomaComponentPack } from '../component/component-pack';
|
|
11
12
|
import { assertRuntimeArtifact } from '../../shared/component-tree-artifact';
|
|
@@ -14,7 +15,7 @@ import type { SomaMountedPage, SomaMountOptions, SomaMountPayload, SomaMountSour
|
|
|
14
15
|
|
|
15
16
|
export const SOMA_DEFAULT_PAGE_ENDPOINT = '/soma/page';
|
|
16
17
|
|
|
17
|
-
export class SomaMountError extends
|
|
18
|
+
export class SomaMountError extends SomaError {
|
|
18
19
|
readonly code = 'CORE-RUNTIME-MOUNT';
|
|
19
20
|
readonly status: number | undefined;
|
|
20
21
|
|
|
@@ -71,7 +72,21 @@ async function fetchPayload(address: string, options: SomaMountOptions): Promise
|
|
|
71
72
|
const endpoint = options.endpoint ?? SOMA_DEFAULT_PAGE_ENDPOINT;
|
|
72
73
|
const url = `${endpoint}${endpoint.includes('?') ? '&' : '?'}path=${encodeURIComponent(address)}`;
|
|
73
74
|
const res = await doFetch(url);
|
|
74
|
-
if (!res.ok)
|
|
75
|
+
if (!res.ok) {
|
|
76
|
+
const error = new SomaMountError(`取页失败 ${res.status} ${res.statusText}(${url})`, res.status);
|
|
77
|
+
// 服务端取页错误体形如 { error, code, textKey?, login? }:解析失败忽略
|
|
78
|
+
try {
|
|
79
|
+
const errBody = typeof res.json === 'function' ? await res.json() : null;
|
|
80
|
+
if (errBody !== null && typeof errBody === 'object') {
|
|
81
|
+
const { code, textKey, login } = errBody as { code?: unknown; textKey?: unknown; login?: unknown };
|
|
82
|
+
const extra = error as unknown as { serverCode?: string; textKey?: string; login?: unknown };
|
|
83
|
+
if (typeof code === 'string') extra.serverCode = code;
|
|
84
|
+
if (typeof textKey === 'string') extra.textKey = textKey;
|
|
85
|
+
if (login !== undefined) extra.login = login;
|
|
86
|
+
}
|
|
87
|
+
} catch { /* 响应体不是 JSON */ }
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
75
90
|
const body = await res.json();
|
|
76
91
|
assertPayloadShape(body, url);
|
|
77
92
|
return body;
|
|
@@ -102,7 +117,11 @@ export async function mountSomaPage(
|
|
|
102
117
|
}
|
|
103
118
|
assertRuntimeArtifact(payload);
|
|
104
119
|
|
|
105
|
-
const hint = domainStaticOnlyHint({
|
|
120
|
+
const hint = domainStaticOnlyHint({
|
|
121
|
+
origin: payload.binding?.origin,
|
|
122
|
+
domain: payload.domain,
|
|
123
|
+
provided: typeof payload.domain === 'string' && options.pageRoots !== undefined && Object.prototype.hasOwnProperty.call(options.pageRoots, payload.domain),
|
|
124
|
+
});
|
|
106
125
|
if (hint !== null) {
|
|
107
126
|
if (options.onHint) options.onHint(hint);
|
|
108
127
|
else console.warn(`[soma-core][引擎] ${hint.code} ${hint.message}`);
|
|
@@ -120,6 +139,7 @@ export async function mountSomaPage(
|
|
|
120
139
|
...(options.lazyComponents !== undefined ? { lazyComponents: options.lazyComponents } : {}),
|
|
121
140
|
...(options.actions !== undefined ? { actions: options.actions } : {}),
|
|
122
141
|
...(options.asyncChecks !== undefined ? { asyncChecks: options.asyncChecks } : {}),
|
|
142
|
+
...(options.pageRoots !== undefined ? { pageRoots: options.pageRoots } : {}),
|
|
123
143
|
...(locale !== undefined ? { locale } : {}),
|
|
124
144
|
...(options.engines !== undefined ? { engines: options.engines } : {}),
|
|
125
145
|
...(options.renderPorts !== undefined ? { renderPorts: options.renderPorts } : {}),
|
|
@@ -134,12 +154,22 @@ export async function mountSomaPage(
|
|
|
134
154
|
const generation = payload.binding?.generation;
|
|
135
155
|
const boundAddress = payload.binding?.address;
|
|
136
156
|
let unmounted = false;
|
|
157
|
+
let navSeq = 0;
|
|
137
158
|
return {
|
|
138
159
|
bootstrap,
|
|
160
|
+
/**
|
|
161
|
+
* 返回 `'updated'`:路由上下文已更新,或本次导航结果被丢弃(被更晚的导航顶替、或页面已卸载)——两种情况调用方都无需再做任何事;
|
|
162
|
+
* 返回 `'other-page'`:命中别的页面,调用方应卸载后整页重挂。返回类型是二元联合、不含「已丢弃」成员,故丢弃并入 `'updated'`。
|
|
163
|
+
*/
|
|
139
164
|
async navigateTo(next: string): Promise<'updated' | 'other-page'> {
|
|
140
165
|
if (address === undefined) throw new SomaMountError('navigateTo 只对用地址挂载的页面可用');
|
|
141
166
|
if (unmounted) throw new SomaMountError('页面已卸载');
|
|
167
|
+
navSeq += 1;
|
|
168
|
+
const seq = navSeq;
|
|
142
169
|
const incoming = await fetchPayload(next, options);
|
|
170
|
+
// 慢响应后到(被更晚的导航顶替)、或页面已卸载:丢弃,不动路由上下文。返回类型(mount/types.ts)只有 'updated' | 'other-page',
|
|
171
|
+
// 无「已丢弃」成员,故返回 'updated',语义是「调用方无需再做任何事」,不会触发整页重挂
|
|
172
|
+
if (seq !== navSeq || unmounted) return 'updated';
|
|
143
173
|
const incomingBound = incoming.binding?.address;
|
|
144
174
|
// 同一个地址模式(绑定地址相等)且产物同代:只换路由上下文;没有绑定信息或别的页面一律让调用方整页重挂
|
|
145
175
|
if (boundAddress === undefined || incomingBound !== boundAddress || incoming.binding?.generation !== generation) return 'other-page';
|
|
@@ -156,8 +186,11 @@ export async function mountSomaPage(
|
|
|
156
186
|
unmount(): void {
|
|
157
187
|
if (unmounted) return;
|
|
158
188
|
unmounted = true;
|
|
189
|
+
// 组件实例必须在 DOM 被换掉之前销毁:unmount 同步段先跑,其拒绝只记录
|
|
190
|
+
bootstrap.unmount().catch((error: unknown) => {
|
|
191
|
+
console.error('[soma-core][引擎] 页面卸载异常:', error);
|
|
192
|
+
});
|
|
159
193
|
if (container) (container as HTMLElement).innerHTML = "";
|
|
160
|
-
void bootstrap.unmount();
|
|
161
194
|
},
|
|
162
195
|
};
|
|
163
196
|
}
|
|
@@ -53,6 +53,8 @@ export interface SomaMountOptions {
|
|
|
53
53
|
readonly lazyComponents?: SomaBootstrapOptions['lazyComponents'];
|
|
54
54
|
/** 应用具名动作:`ACTION | 名字` 的实现表 */
|
|
55
55
|
readonly actions?: NonNullable<SomaBootstrapOptions['actions']>;
|
|
56
|
+
/** 展示对象(Domain 页面类)注册表:`{ 类名: 类 }`;页面的 `domain:` 命中即用该类做页面根(浏览器侧唯一的动态页 Domain 通道) */
|
|
57
|
+
readonly pageRoots?: SomaBootstrapOptions['pageRoots'];
|
|
56
58
|
/** 异步字段检查器:`rules[].async` 的名字 → 检查器(C6-c;页面引用未登记名装配期拒收 `CORE-ASYNC-CHECK-UNREGISTERED`) */
|
|
57
59
|
readonly asyncChecks?: NonNullable<SomaBootstrapOptions['asyncChecks']>;
|
|
58
60
|
readonly locale?: SomaBootstrapOptions['locale'];
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
//
|
|
3
3
|
// · 普通文案 `confirm:确认删除?` -> plain 级(旧写法逐字不变,不产 confirmSpec);
|
|
4
4
|
// · 结构化(JSON) `confirm:{"level":"typed","text":"删除订单","phrase":"DELETE"}`
|
|
5
|
-
// 严格对象:键闭集 level / text / phrase / impact,level 必写之一,text 必写非空;
|
|
6
|
-
// typed 必写 phrase,consent 必写 impact,phrase 只有 typed
|
|
5
|
+
// 严格对象:键闭集 level / text / phrase / impact / tone,level 必写之一,text 必写非空;
|
|
6
|
+
// typed 必写 phrase,consent 必写 impact,phrase 只有 typed 可写;tone 取 default / danger(不写 = default,
|
|
7
|
+
// danger 给渲染端口:确认钮警示呈现、初始焦点落「取消」,各级都可写,包括 plain)。段里不能含 `|`(管道分隔符);
|
|
7
8
|
// · 过渡编码 `confirm:soma-confirm:<level>:…` 已退役,拒收(不折算、不告警)。
|
|
8
9
|
//
|
|
9
10
|
// 判据只有这一份:`checkConfirmSpec`(对象形态)与 `parseConfirmSegment`(段文本形态);执行(弹框、键入比对、勾选)
|
|
@@ -11,20 +12,22 @@
|
|
|
11
12
|
|
|
12
13
|
import {
|
|
13
14
|
SOMA_CONFIRM_LEVELS,
|
|
15
|
+
SOMA_CONFIRM_TONES,
|
|
14
16
|
type SomaConfirmLevel,
|
|
15
17
|
type SomaConfirmSpec,
|
|
18
|
+
type SomaConfirmTone,
|
|
16
19
|
} from '../../shared/types/event.types';
|
|
17
20
|
import { isImeProcessing } from '../keyboard/ime';
|
|
18
21
|
|
|
19
|
-
export { SOMA_CONFIRM_LEVELS };
|
|
20
|
-
export type { SomaConfirmLevel, SomaConfirmSpec };
|
|
22
|
+
export { SOMA_CONFIRM_LEVELS, SOMA_CONFIRM_TONES };
|
|
23
|
+
export type { SomaConfirmLevel, SomaConfirmSpec, SomaConfirmTone };
|
|
21
24
|
|
|
22
|
-
/**
|
|
25
|
+
/** 过渡编码前缀:以它开头的 confirm 段一律拒收 */
|
|
23
26
|
const SOMA_CONFIRM_REJECTED_PREFIX = 'soma-confirm:';
|
|
24
27
|
/** 确认文案 / 键入串 / 影响说明的长度上限(与执行编排的确认文案上限同口径) */
|
|
25
28
|
export const SOMA_CONFIRM_TEXT_MAX = 1000;
|
|
26
29
|
|
|
27
|
-
const SPEC_KEYS = ['level', 'text', 'phrase', 'impact'] as const;
|
|
30
|
+
const SPEC_KEYS = ['level', 'text', 'phrase', 'impact', 'tone'] as const;
|
|
28
31
|
|
|
29
32
|
export type SomaConfirmCheck =
|
|
30
33
|
| { readonly ok: true; readonly spec: SomaConfirmSpec }
|
|
@@ -39,7 +42,7 @@ function boundedText(value: unknown, key: string): string | null {
|
|
|
39
42
|
/** 对象形态的唯一判据:闭集键、level 取值、各级必写 / 禁写的键 */
|
|
40
43
|
export function checkConfirmSpec(raw: unknown): SomaConfirmCheck {
|
|
41
44
|
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
42
|
-
return { ok: false, error: `confirm 结构必须是 { level, text, phrase?, impact? } 对象,当前值: ${JSON.stringify(raw)}` };
|
|
45
|
+
return { ok: false, error: `confirm 结构必须是 { level, text, phrase?, impact?, tone? } 对象,当前值: ${JSON.stringify(raw)}` };
|
|
43
46
|
}
|
|
44
47
|
const record = raw as Record<string, unknown>;
|
|
45
48
|
const extra = Object.keys(record).find((key) => !(SPEC_KEYS as readonly string[]).includes(key));
|
|
@@ -50,6 +53,9 @@ export function checkConfirmSpec(raw: unknown): SomaConfirmCheck {
|
|
|
50
53
|
if (typeof level !== 'string' || !(SOMA_CONFIRM_LEVELS as readonly string[]).includes(level)) {
|
|
51
54
|
return { ok: false, error: `confirm.level 必须是 ${SOMA_CONFIRM_LEVELS.join(' / ')} 之一,当前值: ${JSON.stringify(level)}` };
|
|
52
55
|
}
|
|
56
|
+
if (record.tone !== undefined && (typeof record.tone !== 'string' || !(SOMA_CONFIRM_TONES as readonly string[]).includes(record.tone))) {
|
|
57
|
+
return { ok: false, error: `confirm.tone 必须是 ${SOMA_CONFIRM_TONES.join(' / ')} 之一(不写 = default),当前值: ${JSON.stringify(record.tone)}` };
|
|
58
|
+
}
|
|
53
59
|
const textProblem = boundedText(record.text, 'text');
|
|
54
60
|
if (textProblem !== null) return { ok: false, error: textProblem };
|
|
55
61
|
for (const key of ['phrase', 'impact'] as const) {
|
|
@@ -78,6 +84,7 @@ export function checkConfirmSpec(raw: unknown): SomaConfirmCheck {
|
|
|
78
84
|
text,
|
|
79
85
|
...(lv === 'typed' ? { phrase: (record.phrase as string).trim() } : {}),
|
|
80
86
|
...(lv !== 'plain' && record.impact !== undefined ? { impact: (record.impact as string).trim() } : {}),
|
|
87
|
+
...(record.tone === 'danger' ? { tone: 'danger' as const } : {}),
|
|
81
88
|
},
|
|
82
89
|
};
|
|
83
90
|
}
|
|
@@ -108,6 +115,92 @@ export function parseConfirmSegment(message: string): SomaConfirmSegment | { rea
|
|
|
108
115
|
return { spec: { level: 'plain', text } };
|
|
109
116
|
}
|
|
110
117
|
|
|
118
|
+
// ---- 确认文案占位(触发时代入,纯字段替换,不是表达式)
|
|
119
|
+
//
|
|
120
|
+
// · 语法:`{名字}`,名字 = `[A-Za-z_][A-Za-z0-9_]*`(标识符,不含点、不含路径、不含格式化函数);
|
|
121
|
+
// `{{` 是字面 `{`,`}}` 是字面 `}`;不符合标识符语法的花括号原样保留(不是占位)。
|
|
122
|
+
// · 作用位置:确认的 `text` 与 `impact`(`phrase` 是要用户键入的比对串,永远是字面量,不代入)。
|
|
123
|
+
// · 取值:`{n}` 是保留名 = 本次触发的已选行数(载荷 `rows` 数组的长度);其余名字取载荷 `row`(对象)的同名字段,
|
|
124
|
+
// 行内触发而载荷没带 `row` 时取所在行的数据(与具名动作载荷同口径)。
|
|
125
|
+
// · 值一律转成纯文本:字符串原样、数字 / 布尔 String();对象 / 数组 / null / undefined / 缺字段 / 无行可取 = 缺失。
|
|
126
|
+
// · 失败模式(确定、不抛):缺失的占位代入 `—`(SOMA_CONFIRM_MISSING),并在开发期 console.warn 一次(按占位名去重);
|
|
127
|
+
// 宁可让用户看到「—」也不能把没代入的 `{字段}` 原样弹给用户,更不能因为文案取值失败而放行 / 吞掉确认。
|
|
128
|
+
// · 没有任何花括号的文案原样返回(同一引用的规格),不改既有页面的输出。
|
|
129
|
+
|
|
130
|
+
/** 缺失占位的代入串 */
|
|
131
|
+
export const SOMA_CONFIRM_MISSING = '—';
|
|
132
|
+
/** 保留占位名:已选行数 */
|
|
133
|
+
export const SOMA_CONFIRM_COUNT_NAME = 'n';
|
|
134
|
+
|
|
135
|
+
/** 占位取值的来源(触发时由事件引擎按载荷与所在行给出) */
|
|
136
|
+
export interface SomaConfirmContext {
|
|
137
|
+
/** 触发行 / 记录(载荷 `row`,或行内触发的所在行数据) */
|
|
138
|
+
readonly row?: unknown;
|
|
139
|
+
/** 已选行数(载荷 `rows` 数组的长度);没有批量载荷时不给 */
|
|
140
|
+
readonly count?: number;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const CONFIRM_TOKEN = /\{\{|\}\}|\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
144
|
+
const warnedMissing = new Set<string>();
|
|
145
|
+
|
|
146
|
+
/** 文案里出现的占位名(按出现顺序去重;`{{` / `}}` 转义不算)。方言编译期据此静态核对用,运行期不依赖 */
|
|
147
|
+
export function listConfirmPlaceholders(text: string): string[] {
|
|
148
|
+
const names: string[] = [];
|
|
149
|
+
for (const m of text.matchAll(CONFIRM_TOKEN)) {
|
|
150
|
+
if (m[1] !== undefined && !names.includes(m[1])) names.push(m[1]);
|
|
151
|
+
}
|
|
152
|
+
return names;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function scalarText(value: unknown): string | null {
|
|
156
|
+
if (typeof value === 'string') return value;
|
|
157
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') return String(value);
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** 代入一段确认文案里的占位;`onMissing` 收到每个缺失的占位名(引擎用它记开发期告警) */
|
|
162
|
+
export function substituteConfirmText(text: string, context: SomaConfirmContext, onMissing?: (name: string) => void): string {
|
|
163
|
+
if (!text.includes('{') && !text.includes('}')) return text;
|
|
164
|
+
const row = context.row !== null && typeof context.row === 'object' && !Array.isArray(context.row)
|
|
165
|
+
? (context.row as Record<string, unknown>)
|
|
166
|
+
: undefined;
|
|
167
|
+
return text.replace(CONFIRM_TOKEN, (token, name: string | undefined) => {
|
|
168
|
+
if (name === undefined) return token === '{{' ? '{' : '}';
|
|
169
|
+
const value = name === SOMA_CONFIRM_COUNT_NAME ? context.count : row?.[name];
|
|
170
|
+
const plain = scalarText(value);
|
|
171
|
+
if (plain !== null) return plain;
|
|
172
|
+
onMissing?.(name);
|
|
173
|
+
return SOMA_CONFIRM_MISSING;
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** 把确认规格的 text / impact 代入占位;无花括号时返回原规格(同一引用) */
|
|
178
|
+
export function resolveConfirmSpec(spec: SomaConfirmSpec, context: SomaConfirmContext, onMissing?: (name: string) => void): SomaConfirmSpec {
|
|
179
|
+
const text = substituteConfirmText(spec.text, context, onMissing);
|
|
180
|
+
const impact = spec.impact === undefined ? undefined : substituteConfirmText(spec.impact, context, onMissing);
|
|
181
|
+
if (text === spec.text && impact === spec.impact) return spec;
|
|
182
|
+
return { ...spec, text, ...(impact !== undefined ? { impact } : {}) };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** 开发期告警(按占位名去重;生产构建不输出) */
|
|
186
|
+
export function warnConfirmMissing(name: string, where: string): void {
|
|
187
|
+
if (warnedMissing.has(name)) return;
|
|
188
|
+
warnedMissing.add(name);
|
|
189
|
+
const dev = typeof process === 'undefined' || process.env?.NODE_ENV !== 'production';
|
|
190
|
+
if (dev) console.warn(`[soma-core][引擎] ${where} 的确认文案占位 {${name}} 取不到值,已代入「${SOMA_CONFIRM_MISSING}」(占位只取载荷 row 的字段,{n} 取已选行数;字面花括号写 {{ }})`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* 从事件载荷与所在行取占位来源:`row` 取载荷 `row`(没有则取所在行数据);`count` 取载荷 `rows` 数组长度。
|
|
195
|
+
* 载荷不是对象时按空载荷处理。
|
|
196
|
+
*/
|
|
197
|
+
export function confirmContextOf(payload: unknown, rowData?: unknown): SomaConfirmContext {
|
|
198
|
+
const record = payload !== null && typeof payload === 'object' && !Array.isArray(payload) ? (payload as Record<string, unknown>) : undefined;
|
|
199
|
+
const row = record !== undefined && 'row' in record ? record.row : rowData;
|
|
200
|
+
const count = Array.isArray(record?.rows) ? (record!.rows as unknown[]).length : undefined;
|
|
201
|
+
return { ...(row !== undefined ? { row } : {}), ...(count !== undefined ? { count } : {}) };
|
|
202
|
+
}
|
|
203
|
+
|
|
111
204
|
export interface SomaConfirmInput {
|
|
112
205
|
/** typed 级已键入的串 */
|
|
113
206
|
readonly typed: string;
|