soma-core 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/component.cjs +240 -0
- package/bin/eject.cjs +174 -0
- package/bin/migrate.cjs +362 -0
- package/core/build/blocks/block-compile.ts +143 -17
- package/core/build/blocks/migrate-flat.ts +118 -25
- package/core/build/compiler/page-declaration-compiler.ts +149 -5
- package/core/build/compiler/route-builder.ts +0 -4
- package/core/build/compiler/soma-precompile.js +431 -26
- package/core/build/component/component-graph.ts +28 -105
- package/core/build/component/package-loader.ts +18 -4
- package/core/build/eject/component-eject.ts +8 -2
- package/core/build/layout/constraint-solver.ts +131 -16
- package/core/build/layout/css-emitter.ts +15 -9
- package/core/build/ooui/artifact/artifact.types.ts +275 -0
- package/core/build/ooui/artifact/emit-artifact.ts +269 -0
- package/core/build/ooui/artifact/emit-html.ts +204 -0
- package/core/build/ooui/artifact/index.ts +53 -0
- package/core/build/ooui/artifact/spatial-tree.ts +268 -0
- package/core/build/ooui/artifact/utility-class.ts +83 -0
- package/core/build/ooui/composition/candidate.types.ts +323 -0
- package/core/build/ooui/composition/control-model.ts +114 -0
- package/core/build/ooui/composition/registry.ts +520 -0
- package/core/build/ooui/composition/select.ts +232 -0
- package/core/build/ooui/diagnostics/codes.ts +230 -0
- package/core/build/ooui/diagnostics/error.ts +235 -0
- package/core/build/ooui/diagnostics/format.ts +106 -0
- package/core/build/ooui/diagnostics/index.ts +62 -0
- package/core/build/ooui/diagnostics/issue.types.ts +112 -0
- package/core/build/ooui/engine-slot.ts +184 -0
- package/core/build/ooui/index.ts +1427 -0
- package/core/build/ooui/intent/derive-intent.ts +450 -0
- package/core/build/ooui/intent/field-rules.ts +330 -0
- package/core/build/ooui/intent/intent.types.ts +476 -0
- package/core/build/ooui/intent/verb-events.ts +285 -0
- package/core/build/ooui/page/budget.ts +503 -0
- package/core/build/ooui/page/compose-page.ts +736 -0
- package/core/build/ooui/page/index.ts +66 -0
- package/core/build/ooui/page/page.types.ts +402 -0
- package/core/build/ooui/page/region-row.ts +241 -0
- package/core/build/ooui/semantic/expand-page-surface.ts +180 -0
- package/core/build/ooui/semantic/kernel.types.ts +187 -0
- package/core/build/ooui/semantic/normalize.ts +784 -0
- package/core/build/ooui/semantic/origin.types.ts +211 -0
- package/core/build/ooui/semantic/role-alias.ts +154 -0
- package/core/build/ooui/semantic/shorthand.ts +233 -0
- package/core/build/ooui/semantic/surface.types.ts +78 -0
- package/core/build/ooui/semantic/validate-request.ts +267 -0
- package/core/build/ooui/spatial/emit-utility.ts +480 -0
- package/core/build/ooui/spatial/ir.types.ts +443 -0
- package/core/build/ooui/spatial/registry.ts +565 -0
- package/core/build/ooui/spatial/solve.ts +769 -0
- package/core/build/ooui/spatial/utility.types.ts +242 -0
- package/core/build/ooui/trace/index.ts +40 -0
- package/core/build/ooui/trace/render.ts +190 -0
- package/core/build/ooui/trace/source.types.ts +69 -0
- package/core/build/ooui/trace/trace.types.ts +326 -0
- package/core/client/component/example-blocks.ts +1 -7
- package/core/client/component/theme-component-tokens.ts +12 -15
- package/core/client/data/data-object-resolver.ts +27 -8
- package/core/client/diagnostics/telemetry-context.ts +0 -4
- package/core/client/engine/asset-resolver.ts +0 -1
- package/core/client/engine/event-engine.ts +7 -3
- package/core/client/engine/soma-bootstrap.ts +292 -34
- package/core/client/engine/style-binder.ts +0 -1
- package/core/client/infra/http/IHttpClient.ts +0 -6
- package/core/client/infra/http/SomaHttpService.ts +4 -1
- package/core/client/infra/notify/DomNotifyService.ts +1 -1
- package/core/client/infra/router/router-path.ts +0 -6
- package/core/client/parser/annotation-extractor.ts +1 -1
- package/core/client/parser/blocks/namespace.ts +30 -5
- package/core/client/parser/blocks/page-parser.ts +44 -1
- package/core/client/parser/blocks/use-parser.ts +266 -46
- package/core/client/parser/data-config-parser.ts +71 -3
- package/core/client/parser/layout-parser.ts +4 -3
- package/core/client/parser/reaction-parser.ts +0 -1
- package/core/client/parser/ui-config-parser.ts +212 -74
- package/core/client/theme/scene-tokens.ts +9 -3
- package/core/client/theme/theme-axes.ts +74 -16
- package/core/client/theme/theme-engine.ts +280 -69
- package/core/client/theme/tone-solver.ts +9 -8
- package/core/index.ts +18 -4
- package/core/server/api/load-host-service.ts +8 -2
- package/core/server/declaration-safety.ts +11 -0
- package/core/server/host/page-response-request.ts +0 -2
- package/core/server/host/published-page-artifact-cache.ts +244 -0
- package/core/server/host/published-page-assets.ts +44 -5
- package/core/server/mock/node/cli.mjs +0 -1
- package/core/server/mock/node/schema-generator.mjs +0 -1
- package/core/server/ooui.ts +34 -0
- package/core/server/page-assets.ts +8 -0
- package/core/server/page-declaration.ts +18 -0
- package/core/server/registry/asset-store.ts +327 -0
- package/core/server/registry/declaration-precompiler.ts +49 -6
- package/core/server/registry/index.ts +47 -1
- package/core/server/registry/page-registry-repository.ts +6 -2
- package/core/server/registry/page-registry-store.ts +133 -19
- package/core/server/registry/publish-asset-pin.ts +557 -0
- package/core/server/registry/services/pages/List.ts +15 -3
- package/core/server/registry/validation/compile-gate.ts +180 -8
- package/core/server/registry/validation/declaration-safety-scan.ts +113 -23
- package/core/shared/component/derive-sample.ts +201 -16
- package/core/shared/component/field-lines.ts +98 -8
- package/core/shared/container-breakpoints.ts +46 -0
- package/core/shared/object-semantics.ts +240 -0
- package/core/shared/ooui-declaration.ts +235 -0
- package/core/shared/types/component-contract.types.ts +7 -6
- package/core/shared/types/data-config.types.ts +95 -0
- package/core/shared/types/domain.types.ts +0 -24
- package/core/shared/types/engine.types.ts +0 -5
- package/core/shared/types/layout-constraint.types.ts +16 -0
- package/core/shared/types/ui-config.types.ts +163 -13
- package/dist/cli/soma.js +24 -11
- package/dist/core/index.cjs +1563 -800
- package/dist/types/build/blocks/block-compile.d.ts +16 -1
- package/dist/types/build/blocks/migrate-flat.d.ts +17 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +46 -0
- package/dist/types/build/compiler/route-builder.d.ts +0 -1
- package/dist/types/build/component/component-graph.d.ts +17 -53
- package/dist/types/build/component/package-loader.d.ts +8 -1
- package/dist/types/build/layout/constraint-solver.d.ts +46 -4
- package/dist/types/build/ooui/artifact/artifact.types.d.ts +180 -0
- package/dist/types/build/ooui/artifact/emit-artifact.d.ts +58 -0
- package/dist/types/build/ooui/artifact/emit-html.d.ts +53 -0
- package/dist/types/build/ooui/artifact/index.d.ts +5 -0
- package/dist/types/build/ooui/artifact/spatial-tree.d.ts +48 -0
- package/dist/types/build/ooui/artifact/utility-class.d.ts +46 -0
- package/dist/types/build/ooui/composition/candidate.types.d.ts +206 -0
- package/dist/types/build/ooui/composition/control-model.d.ts +37 -0
- package/dist/types/build/ooui/composition/registry.d.ts +66 -0
- package/dist/types/build/ooui/composition/select.d.ts +63 -0
- package/dist/types/build/ooui/diagnostics/codes.d.ts +28 -0
- package/dist/types/build/ooui/diagnostics/error.d.ts +135 -0
- package/dist/types/build/ooui/diagnostics/format.d.ts +51 -0
- package/dist/types/build/ooui/diagnostics/index.d.ts +25 -0
- package/dist/types/build/ooui/diagnostics/issue.types.d.ts +56 -0
- package/dist/types/build/ooui/engine-slot.d.ts +41 -0
- package/dist/types/build/ooui/index.d.ts +286 -0
- package/dist/types/build/ooui/intent/derive-intent.d.ts +32 -0
- package/dist/types/build/ooui/intent/field-rules.d.ts +99 -0
- package/dist/types/build/ooui/intent/intent.types.d.ts +318 -0
- package/dist/types/build/ooui/intent/verb-events.d.ts +70 -0
- package/dist/types/build/ooui/page/budget.d.ts +28 -0
- package/dist/types/build/ooui/page/compose-page.d.ts +41 -0
- package/dist/types/build/ooui/page/index.d.ts +4 -0
- package/dist/types/build/ooui/page/page.types.d.ts +264 -0
- package/dist/types/build/ooui/page/region-row.d.ts +16 -0
- package/dist/types/build/ooui/semantic/expand-page-surface.d.ts +33 -0
- package/dist/types/build/ooui/semantic/kernel.types.d.ts +125 -0
- package/dist/types/build/ooui/semantic/normalize.d.ts +45 -0
- package/dist/types/build/ooui/semantic/origin.types.d.ts +95 -0
- package/dist/types/build/ooui/semantic/role-alias.d.ts +35 -0
- package/dist/types/build/ooui/semantic/shorthand.d.ts +60 -0
- package/dist/types/build/ooui/semantic/surface.types.d.ts +16 -0
- package/dist/types/build/ooui/semantic/validate-request.d.ts +19 -0
- package/dist/types/build/ooui/spatial/emit-utility.d.ts +43 -0
- package/dist/types/build/ooui/spatial/ir.types.d.ts +280 -0
- package/dist/types/build/ooui/spatial/registry.d.ts +110 -0
- package/dist/types/build/ooui/spatial/solve.d.ts +42 -0
- package/dist/types/build/ooui/spatial/utility.types.d.ts +191 -0
- package/dist/types/build/ooui/trace/index.d.ts +3 -0
- package/dist/types/build/ooui/trace/render.d.ts +42 -0
- package/dist/types/build/ooui/trace/source.types.d.ts +25 -0
- package/dist/types/build/ooui/trace/trace.types.d.ts +143 -0
- package/dist/types/client/component/example-blocks.d.ts +0 -2
- package/dist/types/client/component/theme-component-tokens.d.ts +8 -5
- package/dist/types/client/data/data-object-resolver.d.ts +10 -2
- package/dist/types/client/diagnostics/telemetry-context.d.ts +0 -1
- package/dist/types/client/engine/soma-bootstrap.d.ts +123 -10
- package/dist/types/client/infra/http/IHttpClient.d.ts +0 -5
- package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
- package/dist/types/client/infra/router/router-path.d.ts +0 -2
- package/dist/types/client/parser/blocks/namespace.d.ts +20 -0
- package/dist/types/client/parser/blocks/page-parser.d.ts +9 -0
- package/dist/types/client/parser/blocks/use-parser.d.ts +38 -4
- package/dist/types/client/parser/data-config-parser.d.ts +13 -0
- package/dist/types/client/parser/ui-config-parser.d.ts +1 -11
- package/dist/types/client/theme/scene-tokens.d.ts +9 -3
- package/dist/types/client/theme/theme-axes.d.ts +64 -1
- package/dist/types/client/theme/theme-engine.d.ts +13 -8
- package/dist/types/client/theme/tone-solver.d.ts +9 -5
- package/dist/types/index.d.ts +4 -5
- package/dist/types/server/declaration-safety.d.ts +7 -0
- package/dist/types/server/host/page-response-request.d.ts +0 -1
- package/dist/types/server/host/published-page-artifact-cache.d.ts +64 -0
- package/dist/types/server/ooui.d.ts +18 -0
- package/dist/types/server/page-assets.d.ts +7 -0
- package/dist/types/server/page-declaration.d.ts +14 -0
- package/dist/types/server/registry/asset-store.d.ts +112 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +23 -3
- package/dist/types/server/registry/index.d.ts +3 -1
- package/dist/types/server/registry/page-registry-store.d.ts +57 -4
- package/dist/types/server/registry/publish-asset-pin.d.ts +166 -0
- package/dist/types/server/registry/services/pages/List.d.ts +9 -3
- package/dist/types/server/registry/validation/compile-gate.d.ts +63 -0
- package/dist/types/shared/component/derive-sample.d.ts +14 -0
- package/dist/types/shared/container-breakpoints.d.ts +42 -0
- package/dist/types/shared/object-semantics.d.ts +42 -0
- package/dist/types/shared/ooui-declaration.d.ts +135 -0
- package/dist/types/shared/types/component-contract.types.d.ts +7 -6
- package/dist/types/shared/types/data-config.types.d.ts +86 -0
- package/dist/types/shared/types/domain.types.d.ts +0 -21
- package/dist/types/shared/types/engine.types.d.ts +0 -4
- package/dist/types/shared/types/layout-constraint.types.d.ts +1 -0
- package/dist/types/shared/types/ui-config.types.d.ts +157 -12
- package/next.config.js +106 -13
- package/package.json +28 -2
- package/core/client/host-bridge/index.ts +0 -27
- package/core/client/parser/yaml-loader.ts +0 -36
- package/core/shared/manifest/manifest-contract.ts +0 -12
- package/dist/types/client/host-bridge/index.d.ts +0 -9
- package/dist/types/client/parser/yaml-loader.d.ts +0 -21
- package/dist/types/shared/manifest/manifest-contract.d.ts +0 -4
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
// 意图层 ② · 动词 → 根形态 + 事件契约。§16.2 / §30.1 / §35.2 的可执行形态。
|
|
2
|
+
//
|
|
3
|
+
// ── 为什么这一层的失败模式是静默的 ─────────────────────────────────
|
|
4
|
+
// ① **事件表按动词一刀切**。这是 §35 挖出来的根因,也是本文件存在的理由:
|
|
5
|
+
// `edit: { required: ['change','submit'] }` 写下去的那天,
|
|
6
|
+
// 单测绿、矩阵绿、8 个动词全部有候选(§30.2)——**判据错了却全绿**,
|
|
7
|
+
// 因为验证用的候选表也是照同一套语汇手写的。
|
|
8
|
+
// 真相要到"唯一能零 Domain 闭环的 FormConsole 被自己的闸门刷掉"
|
|
9
|
+
// 这个反常现象出现,再往下挖一层才见到(§35.5)。
|
|
10
|
+
// 所以事件的"必需"必须写成**相对控制模型**的,不能写成绝对的。
|
|
11
|
+
//
|
|
12
|
+
// ② **必需事件与语义启用事件混成一张表**。§16.2 第一版把事件写成
|
|
13
|
+
// "动词**必然**产生",于是 `Card` / `LineChart` / `KpiBoard` 这类零 emit 的
|
|
14
|
+
// 纯展示件被判为不合格的 `inspect` / `monitor` 载体——**而它们是合法的**。
|
|
15
|
+
// §30.1 修正为"必需由动词本质决定,其余由对象语义启用"。
|
|
16
|
+
// 混在一起的表现不是报错,是"这个动词永远选不出候选",
|
|
17
|
+
// 而报出来的话指向的是构件层的候选表,不是这张事件表。
|
|
18
|
+
//
|
|
19
|
+
// ③ **动词 → 形态映射漂到封闭集之外**。原型 `full-matrix.mjs` 的
|
|
20
|
+
// `select: 'picker'` 就是这么来的(§34.3)。本文件的映射表用
|
|
21
|
+
// `SomaInteractionForm` 类型标注,漂移当场是编译错误。
|
|
22
|
+
|
|
23
|
+
import type { SomaObject, SomaVerb } from '../semantic/kernel.types';
|
|
24
|
+
import { SOMA_WRITE_VERBS } from '../semantic/kernel.types';
|
|
25
|
+
import type {
|
|
26
|
+
SomaCardinality,
|
|
27
|
+
SomaControlModel,
|
|
28
|
+
SomaInteraction,
|
|
29
|
+
SomaInteractionKind,
|
|
30
|
+
SomaInteractionPayloadType,
|
|
31
|
+
SomaIntentCapability,
|
|
32
|
+
SomaInteractionForm,
|
|
33
|
+
} from './intent.types';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 动词 → 根形态(§3.2 + §36.1 裁定 1)。
|
|
37
|
+
*
|
|
38
|
+
* 与原型 `full-matrix.mjs` 的唯一差别是 `select`:原型写 `picker`,
|
|
39
|
+
* 而 `picker` 不在封闭集里——**下拉还是分段是控件形态,属构件层**。
|
|
40
|
+
*
|
|
41
|
+
* `select` 恒取 `single-choice`:当前声明词汇里**没有任何一处能表达"选一个还是选多个"**
|
|
42
|
+
* (§17.2 说 `collection.selection.mode` 决定单选/多选,但仓库真实的
|
|
43
|
+
* `SomaWindowSelection` 只有 `base` / `toggled`,没有 `mode`——见本批 findings)。
|
|
44
|
+
* 铁律三是不猜测意图,所以这里不从 `select_all` 之类的默认值里编一个信号出来;
|
|
45
|
+
* 真要多选,走 `deriveIntent` 的逃生门显式指定 `form: 'multi-choice'`。
|
|
46
|
+
*/
|
|
47
|
+
export const VERB_ROOT_FORM: Readonly<Record<SomaVerb, SomaInteractionForm>> = {
|
|
48
|
+
inspect: 'record-detail',
|
|
49
|
+
browse: 'record-list',
|
|
50
|
+
edit: 'form',
|
|
51
|
+
select: 'single-choice',
|
|
52
|
+
compare: 'comparison',
|
|
53
|
+
advance: 'progression',
|
|
54
|
+
navigate: 'hierarchy',
|
|
55
|
+
monitor: 'timeline',
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 根形态的基数。`window` 段的有无是唯一的分叉:
|
|
60
|
+
* 声明了服务端窗口意味着"一屏一屏地取",总量前端不知道,故 `unbounded`。
|
|
61
|
+
*/
|
|
62
|
+
export function rootCardinality(verb: SomaVerb, object: SomaObject): SomaCardinality {
|
|
63
|
+
const windowed = object.window !== undefined;
|
|
64
|
+
switch (verb) {
|
|
65
|
+
case 'inspect':
|
|
66
|
+
case 'edit':
|
|
67
|
+
case 'advance':
|
|
68
|
+
return 'one';
|
|
69
|
+
case 'compare':
|
|
70
|
+
return 'few';
|
|
71
|
+
case 'browse':
|
|
72
|
+
case 'select':
|
|
73
|
+
case 'navigate':
|
|
74
|
+
case 'monitor':
|
|
75
|
+
return windowed ? 'unbounded' : 'many';
|
|
76
|
+
default:
|
|
77
|
+
return 'one';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 事件载荷契约:一个事件必然携带什么。**唯一真源**,两处语汇都从这里取 */
|
|
82
|
+
const PAYLOADS: Readonly<Record<SomaInteractionKind, Readonly<Record<string, SomaInteractionPayloadType>>>> = {
|
|
83
|
+
// 受控语汇
|
|
84
|
+
change: { field: 'field-ref', value: 'value' },
|
|
85
|
+
submit: { object: 'object-ref' },
|
|
86
|
+
cancel: {},
|
|
87
|
+
validate: { field: 'field-ref', message: 'text' },
|
|
88
|
+
select: { ids: 'object-ref-list' },
|
|
89
|
+
open: { id: 'object-ref' },
|
|
90
|
+
sort: { patch: 'window-patch' },
|
|
91
|
+
filter: { patch: 'window-patch' },
|
|
92
|
+
page: { patch: 'window-patch' },
|
|
93
|
+
pick: { id: 'object-ref' },
|
|
94
|
+
search: { keyword: 'text' },
|
|
95
|
+
transition: { object: 'object-ref', to: 'text' },
|
|
96
|
+
action: { object: 'object-ref', action: 'text' },
|
|
97
|
+
traverse: { relation: 'text', id: 'object-ref' },
|
|
98
|
+
add: { id: 'object-ref' },
|
|
99
|
+
remove: { id: 'object-ref' },
|
|
100
|
+
range: { patch: 'window-patch' },
|
|
101
|
+
drill: { id: 'object-ref' },
|
|
102
|
+
// 自治语汇
|
|
103
|
+
loaded: { object: 'object-ref' },
|
|
104
|
+
submitted: { object: 'object-ref' },
|
|
105
|
+
error: { message: 'text' },
|
|
106
|
+
row_open: { id: 'object-ref' },
|
|
107
|
+
action_done: { object: 'object-ref', action: 'text' },
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 需要宿主授权的事件(§16.4)。
|
|
112
|
+
*
|
|
113
|
+
* 判据是"这个事件一旦发生,服务端的数据就变了",不是"这个事件听起来像写"。
|
|
114
|
+
* `change` **不在**表里:受控件的 `change` 只改页面持有的 values,
|
|
115
|
+
* 落库要等 `submit`。把 `change` 算作写会让每一张受控表单都要求 `write` 端点,
|
|
116
|
+
* 连"填一半还没提交"都不许——那是把授权点定错了位置。
|
|
117
|
+
*/
|
|
118
|
+
const GRANT_REQUIRED: ReadonlySet<SomaInteractionKind> = new Set<SomaInteractionKind>([
|
|
119
|
+
'submit', 'submitted', 'transition', 'action', 'action_done',
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
/** 一个动词在某控制模型下的事件清单 */
|
|
123
|
+
interface VerbEventSpec {
|
|
124
|
+
required: readonly SomaInteractionKind[];
|
|
125
|
+
optional: readonly SomaInteractionKind[];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* §35.2 的表:**必需事件按控制模型分**。
|
|
130
|
+
*
|
|
131
|
+
* 两列的语态不同不是风格差异,是控制模型的定义:
|
|
132
|
+
* 自治型只在事情做完后通知(过去式),它永远 emit 不出 `change`——
|
|
133
|
+
* 因为它根本不需要把中间状态抛给页面。
|
|
134
|
+
*
|
|
135
|
+
* 每一格的"必需"都要能回答同一个问题:**缺了它,这个动词还成立吗?**
|
|
136
|
+
* · browse/controlled 缺 `select`:不能选中就不是浏览 → 必需;
|
|
137
|
+
* · browse/autonomous 什么都不缺:自治型自己浏览、自己翻页,页面不需要知道 → 空;
|
|
138
|
+
* · edit/autonomous 缺 `submitted`:写完了却不通知宿主,页面上其他区域
|
|
139
|
+
* 永远停在旧数据上,而那是"看着正常"的一页 → 必需;
|
|
140
|
+
* · select 两列都要 `pick`:**这次交互的产物就是被选中的东西**,
|
|
141
|
+
* 自治型也必须把它交出去,否则选了等于没选;
|
|
142
|
+
* · navigate/autonomous 取 `row_open`:它是 `traverse` 的过去式,
|
|
143
|
+
* 且是 catalog 里 `QueryConsole` 真实 emit 的名字(不是编出来的词)。
|
|
144
|
+
*/
|
|
145
|
+
export const VERB_EVENTS_BY_MODEL: Readonly<Record<SomaVerb, Readonly<Record<SomaControlModel, VerbEventSpec>>>> = {
|
|
146
|
+
inspect: {
|
|
147
|
+
controlled: { required: [], optional: ['action'] },
|
|
148
|
+
autonomous: { required: [], optional: ['loaded', 'action_done', 'error'] },
|
|
149
|
+
},
|
|
150
|
+
browse: {
|
|
151
|
+
controlled: { required: ['select'], optional: ['open', 'sort', 'filter', 'page'] },
|
|
152
|
+
autonomous: { required: [], optional: ['loaded', 'row_open', 'action_done', 'error'] },
|
|
153
|
+
},
|
|
154
|
+
edit: {
|
|
155
|
+
controlled: { required: ['change', 'submit'], optional: ['validate', 'cancel'] },
|
|
156
|
+
autonomous: { required: ['submitted'], optional: ['loaded', 'error'] },
|
|
157
|
+
},
|
|
158
|
+
select: {
|
|
159
|
+
controlled: { required: ['pick'], optional: ['search'] },
|
|
160
|
+
autonomous: { required: ['pick'], optional: ['loaded', 'search', 'error'] },
|
|
161
|
+
},
|
|
162
|
+
compare: {
|
|
163
|
+
controlled: { required: [], optional: ['add', 'remove'] },
|
|
164
|
+
autonomous: { required: [], optional: ['loaded', 'error'] },
|
|
165
|
+
},
|
|
166
|
+
advance: {
|
|
167
|
+
controlled: { required: ['transition'], optional: ['action'] },
|
|
168
|
+
autonomous: { required: ['action_done'], optional: ['loaded', 'error'] },
|
|
169
|
+
},
|
|
170
|
+
navigate: {
|
|
171
|
+
controlled: { required: ['traverse'], optional: [] },
|
|
172
|
+
autonomous: { required: ['row_open'], optional: ['loaded', 'error'] },
|
|
173
|
+
},
|
|
174
|
+
monitor: {
|
|
175
|
+
controlled: { required: [], optional: ['range', 'drill'] },
|
|
176
|
+
autonomous: { required: [], optional: ['loaded', 'error'] },
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/** 语义启用的一条事件:谁启用的、对谁必需 */
|
|
181
|
+
interface EnabledEvent {
|
|
182
|
+
kind: SomaInteractionKind;
|
|
183
|
+
requiredFor: readonly SomaControlModel[];
|
|
184
|
+
enabledBy: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 对象语义启用的能力与事件(§17.2)。
|
|
189
|
+
*
|
|
190
|
+
* 能力与事件在这里分家:`window.sort` 声明了就意味着**这次交互要能排序**(能力),
|
|
191
|
+
* 但只有受控型需要把排序意图 emit 出去(事件)——自治型自己排。
|
|
192
|
+
* 合成一个概念,自治型候选会因为"emit 不出 sort"被判成排不了序,
|
|
193
|
+
* 那是 §35 修掉的那个判据缺陷换个位置重演。
|
|
194
|
+
*/
|
|
195
|
+
export function semanticEnablement(
|
|
196
|
+
verb: SomaVerb,
|
|
197
|
+
object: SomaObject,
|
|
198
|
+
): { capabilities: SomaIntentCapability[]; events: EnabledEvent[] } {
|
|
199
|
+
const capabilities: SomaIntentCapability[] = [];
|
|
200
|
+
const events: EnabledEvent[] = [];
|
|
201
|
+
const win = object.window;
|
|
202
|
+
const collectionVerb = verb === 'browse' || verb === 'select' || verb === 'navigate' || verb === 'monitor';
|
|
203
|
+
|
|
204
|
+
if (win && collectionVerb) {
|
|
205
|
+
capabilities.push('paginate');
|
|
206
|
+
events.push({ kind: 'page', requiredFor: ['controlled'], enabledBy: 'window.block' });
|
|
207
|
+
if (win.sort.length > 0) {
|
|
208
|
+
capabilities.push('sort');
|
|
209
|
+
events.push({ kind: 'sort', requiredFor: ['controlled'], enabledBy: 'window.sort' });
|
|
210
|
+
}
|
|
211
|
+
if (win.filter !== null) {
|
|
212
|
+
capabilities.push('filter');
|
|
213
|
+
events.push({ kind: 'filter', requiredFor: ['controlled'], enabledBy: 'window.filter' });
|
|
214
|
+
}
|
|
215
|
+
if (win.group !== null) capabilities.push('group');
|
|
216
|
+
if (win.aggregate.length > 0) capabilities.push('aggregate');
|
|
217
|
+
// selection 在解析产物里恒存在(`base: 'none'` 是缺省),所以它**不能**当作
|
|
218
|
+
// "作者声明了多选"的信号——只有 base 已经是 'all' 才是作者写下的事实。
|
|
219
|
+
if (win.selection.base === 'all' || win.selection.toggled.length > 0) {
|
|
220
|
+
capabilities.push('select');
|
|
221
|
+
events.push({ kind: 'select', requiredFor: ['controlled'], enabledBy: 'window.selection' });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (object.write && (SOMA_WRITE_VERBS as readonly string[]).includes(verb)) {
|
|
226
|
+
capabilities.push('write');
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return { capabilities, events };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 组装一个动词在本次语义下的完整事件清单。
|
|
234
|
+
*
|
|
235
|
+
* 同一个 `kind` 被动词与语义各启用一次时**合并**(`requiredFor` 取并集),
|
|
236
|
+
* 而不是产出两条:两条同名事件会让构件层的 eventMap 校验对着其中一条通过、
|
|
237
|
+
* 对着另一条失败,取决于遍历顺序。
|
|
238
|
+
*/
|
|
239
|
+
export function deriveInteractions(verb: SomaVerb, object: SomaObject): SomaInteraction[] {
|
|
240
|
+
const spec = VERB_EVENTS_BY_MODEL[verb];
|
|
241
|
+
const byKind = new Map<SomaInteractionKind, SomaInteraction>();
|
|
242
|
+
|
|
243
|
+
const put = (kind: SomaInteractionKind, requiredFor: readonly SomaControlModel[], enabledBy: string) => {
|
|
244
|
+
const existing = byKind.get(kind);
|
|
245
|
+
if (existing) {
|
|
246
|
+
const merged = new Set<SomaControlModel>([...existing.requiredFor, ...requiredFor]);
|
|
247
|
+
byKind.set(kind, {
|
|
248
|
+
...existing,
|
|
249
|
+
requiredFor: (['autonomous', 'controlled'] as const).filter((m) => merged.has(m)),
|
|
250
|
+
enabledBy: existing.enabledBy === enabledBy ? enabledBy : `${existing.enabledBy}+${enabledBy}`,
|
|
251
|
+
});
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
byKind.set(kind, {
|
|
255
|
+
kind,
|
|
256
|
+
payload: PAYLOADS[kind],
|
|
257
|
+
requiresGrant: GRANT_REQUIRED.has(kind),
|
|
258
|
+
requiredFor,
|
|
259
|
+
enabledBy,
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
for (const model of ['autonomous', 'controlled'] as const) {
|
|
264
|
+
for (const kind of spec[model].required) put(kind, [model], 'verb');
|
|
265
|
+
for (const kind of spec[model].optional) put(kind, [], 'verb');
|
|
266
|
+
}
|
|
267
|
+
for (const event of semanticEnablement(verb, object).events) {
|
|
268
|
+
put(event.kind, event.requiredFor, event.enabledBy);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// 输出顺序固定为封闭集顺序:产物要能逐字比对(§19.3 幂等)
|
|
272
|
+
return [...byKind.values()].sort((a, b) => (
|
|
273
|
+
SOMA_INTERACTION_ORDER.indexOf(a.kind) - SOMA_INTERACTION_ORDER.indexOf(b.kind)
|
|
274
|
+
));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const SOMA_INTERACTION_ORDER: readonly SomaInteractionKind[] = [
|
|
278
|
+
'change', 'submit', 'cancel', 'validate',
|
|
279
|
+
'select', 'open', 'sort', 'filter', 'page',
|
|
280
|
+
'pick', 'search',
|
|
281
|
+
'transition', 'action', 'traverse',
|
|
282
|
+
'add', 'remove',
|
|
283
|
+
'range', 'drill',
|
|
284
|
+
'loaded', 'submitted', 'error', 'row_open', 'action_done',
|
|
285
|
+
];
|