soma-kit 0.1.7 → 0.1.9
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/package.json +2 -2
- package/spec/generated/kit-app.schema.json +27 -0
- package/spec/generated/kit-page.schema.json +7 -0
- package/spec/kit-grammar.json +105 -6
- package/src/app/app-config.ts +558 -20
- package/src/app/component-gate.ts +203 -0
- package/src/app/define-kit-app.ts +3 -0
- package/src/app/server.ts +10 -1
- package/src/base/shared.ts +48 -5
- package/src/base/text.ts +8 -2
- package/src/biz/index.ts +30 -0
- package/src/biz/page-templates/domain-templates.ts +184 -0
- package/src/compile/compile-page.ts +149 -4
- package/src/compile/parse.ts +4 -0
- package/src/compile/types.ts +5 -1
- package/src/data/embed.ts +2 -0
- package/src/data/navbar.ts +2 -2
- package/src/generated/kit-grammar-runtime.ts +7 -4
- package/src/theme/nine-dim-palettes.ts +1274 -0
- package/src/theme/theme-tokens.ts +17 -3
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// 应用扩展组件的唯一接入路径门禁(KIT-APP-004 / KIT-APP-005)。
|
|
2
|
+
//
|
|
3
|
+
// 设计原则:接入 soma-kit 只有一条路,禁止应用组件绕过标准组件库与样式编译管线:
|
|
4
|
+
// 1) KIT-APP-004:所有登记进 baseComponents / staticObjectComponents 的 App* 组件,必须经
|
|
5
|
+
// wrapKitDataComponent、composeKitDataComponents 或 declareKitUses 显式登记依赖组件与候选类元数据;
|
|
6
|
+
// 声明的 uses 必须是真实存在的内置组件名,own 候选类必须通过 checkClasses 校验(禁方括号任意值)。
|
|
7
|
+
// 2) KIT-APP-005:严禁应用组件在 templateHtml、控制器或 components/ 辅助模块中私自拼写已被 soma-kit
|
|
8
|
+
// 标准组件接管的原生表单控件(原生 <select>、原生 <input type="range">、原生 <input type="date|datetime-local|time|month|week">),
|
|
9
|
+
// 也严禁在 templateHtml 中书写内联 style 属性。下拉一律走 Select / Combobox / mountKitSelectField,
|
|
10
|
+
// 滑块一律走 Range,日期时间一律走 Date / DateRange / TimePicker。
|
|
11
|
+
|
|
12
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
|
+
import { KIT_BASE_COMPONENTS } from '../base/index';
|
|
14
|
+
import { KIT_EXTRA_COMPONENT_CANDIDATES } from '../compile/component-candidates';
|
|
15
|
+
import { KIT_STATIC_BUILTIN_LAZY_NAMES } from '../data/static-lazy';
|
|
16
|
+
import { KIT_RESIDENT_COMPONENT_NAMES, wrappedCandidateSource } from '../data/wrapped-candidates';
|
|
17
|
+
import { checkClasses } from '../object-renderer/merge-class';
|
|
18
|
+
import type { KitDiagnostic } from '../object-renderer/types';
|
|
19
|
+
|
|
20
|
+
/** declareKitUses 允许引用的内置组件全集 */
|
|
21
|
+
export const VALID_KIT_USES_NAMES: ReadonlySet<string> = new Set<string>([
|
|
22
|
+
...Object.keys(KIT_BASE_COMPONENTS),
|
|
23
|
+
...KIT_RESIDENT_COMPONENT_NAMES,
|
|
24
|
+
...KIT_STATIC_BUILTIN_LAZY_NAMES,
|
|
25
|
+
...Object.keys(KIT_EXTRA_COMPONENT_CANDIDATES),
|
|
26
|
+
'KitObjectForm',
|
|
27
|
+
'KitTableActions',
|
|
28
|
+
'KitTableHead',
|
|
29
|
+
'KitTableTools',
|
|
30
|
+
'KitCollectionState',
|
|
31
|
+
'KitTreeTable',
|
|
32
|
+
'KitVirtualRows',
|
|
33
|
+
'KitContextMenu',
|
|
34
|
+
'KitRedirect',
|
|
35
|
+
'Pager',
|
|
36
|
+
'Tree',
|
|
37
|
+
'StatGroup',
|
|
38
|
+
'Chart',
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
interface ForbiddenRule {
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly pattern: RegExp;
|
|
44
|
+
readonly message: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const FORBIDDEN_DOM_PATTERNS: readonly ForbiddenRule[] = [
|
|
48
|
+
{
|
|
49
|
+
id: 'raw-style-tag',
|
|
50
|
+
pattern: /<\s*style(?=[\s>/])/i,
|
|
51
|
+
message: '禁止在模板或控制器中手写 <style> 标签注入全局样式;请统一使用 Tailwind 候选类与 --soma-* 设计令牌',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: 'raw-style-create',
|
|
55
|
+
pattern: /createElement\s*\(\s*['"`]style['"`]\s*\)/,
|
|
56
|
+
message: '禁止调用 createElement("style") 动态注入样式表;请统一使用 Tailwind 候选类与 --soma-* 设计令牌',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: 'native-select-tag',
|
|
60
|
+
pattern: /<\s*select(?=[\s>/])/i,
|
|
61
|
+
message: '禁止手写原生 <select> 标签;请改用 soma-kit 标准组件 Select / Combobox(命令式嵌入用 mountKitSelectField)',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'native-select-create',
|
|
65
|
+
pattern: /createElement\s*\(\s*['"`]select['"`]\s*\)/,
|
|
66
|
+
message: '禁止调用 createElement("select") 创建原生下拉框;请改用 mountKitSelectField 或 Select 组件',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: 'native-range-tag',
|
|
70
|
+
pattern: /<\s*input\b[^>]*\btype\s*=\s*['"]range['"]/i,
|
|
71
|
+
message: '禁止手写原生 <input type="range"> 滑块;请改用 soma-kit 标准组件 Range(自绘无障碍 SVG 滑块)',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: 'native-range-prop',
|
|
75
|
+
pattern: /\.\s*type\s*=\s*['"`]range['"`]/,
|
|
76
|
+
message: '禁止设置 input.type = "range" 创建原生滑块;请改用 soma-kit 标准组件 Range',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 'native-date-tag',
|
|
80
|
+
pattern: /<\s*input\b[^>]*\btype\s*=\s*['"](?:date|datetime-local|time|month|week)['"]/i,
|
|
81
|
+
message: '禁止手写原生日期/时间 <input>;请改用 soma-kit 标准组件 Date / DateRange / TimePicker',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: 'native-date-prop',
|
|
85
|
+
pattern: /\.\s*type\s*=\s*['"`](?:date|datetime-local|time|month|week)['"`]/,
|
|
86
|
+
message: '禁止设置原生日期/时间 input.type;请改用 soma-kit 标准组件 Date / DateRange / TimePicker',
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
/** 剥离块注释与单行注释,保留换行符以便行号定位准确(不误伤字符串内的 URL 协议 `://`) */
|
|
91
|
+
export function stripCodeComments(source: string): string {
|
|
92
|
+
return source
|
|
93
|
+
.replace(/\/\*[\s\S]*?\*\//g, (match) => match.replace(/[^\n]/g, ' '))
|
|
94
|
+
.replace(/(^|[^:\\'"])\/\/[^\n]*/gm, '$1');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 扫描一段代码或模板文本中的禁用原生控件,返回命中的第一条违规信息与行号(1-based) */
|
|
98
|
+
export function findForbiddenNativeControls(text: string): Array<{ line: number; message: string }> {
|
|
99
|
+
const cleaned = stripCodeComments(text);
|
|
100
|
+
const lines = cleaned.split('\n');
|
|
101
|
+
const hits: Array<{ line: number; message: string }> = [];
|
|
102
|
+
for (let idx = 0; idx < lines.length; idx++) {
|
|
103
|
+
const line = lines[idx]!;
|
|
104
|
+
for (const rule of FORBIDDEN_DOM_PATTERNS) {
|
|
105
|
+
if (rule.pattern.test(line)) {
|
|
106
|
+
hits.push({ line: idx + 1, message: rule.message });
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return hits;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 装配期同步校验单个应用扩展组件(浏览器与服务端共用):
|
|
116
|
+
* 拦截未经唯一接入路径包装声明的野生组件(KIT-APP-004)与私造非标原生控件(KIT-APP-005)。
|
|
117
|
+
*/
|
|
118
|
+
export function assertSinglePathComponent(name: string, def: SomaComponentDefinition): void {
|
|
119
|
+
const meta = wrappedCandidateSource(def);
|
|
120
|
+
if (meta === undefined) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
`[soma-kit] [KIT-APP-004] 应用组件 ${name} 未经唯一接入路径声明:必须通过 wrapKitDataComponent / composeKitDataComponents 包装组合,或经 declareKitUses(${name}, uses, candidates) 显式登记依赖组件与候选类`,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
for (const used of meta.uses ?? []) {
|
|
126
|
+
if (!VALID_KIT_USES_NAMES.has(used)) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
`[soma-kit] [KIT-APP-004] 应用组件 ${name} 在 declareKitUses 中声明了未知的内置组件 "${used}"`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
for (const tok of meta.own) {
|
|
133
|
+
const bad = checkClasses(tok, `${name}.candidates`);
|
|
134
|
+
if (bad.length > 0) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`[soma-kit] [KIT-APP-004] 应用组件 ${name} 的候选类 "${tok}" 非法:${bad[0]!.message}`,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (typeof def.templateHtml === 'string' && /\sstyle\s*=/i.test(def.templateHtml)) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`[soma-kit] [KIT-APP-005] 应用组件 ${name} 的 templateHtml 含内联 style 属性;样式必须统一使用 Tailwind 候选类`,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const tplHits = typeof def.templateHtml === 'string' ? findForbiddenNativeControls(def.templateHtml) : [];
|
|
146
|
+
if (tplHits.length > 0) {
|
|
147
|
+
throw new Error(`[soma-kit] [KIT-APP-005] 应用组件 ${name} 的 templateHtml 违规:${tplHits[0]!.message}`);
|
|
148
|
+
}
|
|
149
|
+
if (typeof def.controllerFactory === 'function') {
|
|
150
|
+
const fnHits = findForbiddenNativeControls(Function.prototype.toString.call(def.controllerFactory));
|
|
151
|
+
if (fnHits.length > 0) {
|
|
152
|
+
throw new Error(`[soma-kit] [KIT-APP-005] 应用组件 ${name} 的控制器违规:${fnHits[0]!.message}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 服务端编译与 `soma kit check` 全量源码门禁:
|
|
159
|
+
* 递归扫描应用 `<root>/components` 目录下的全部实现文件(`.ts` / `.js` / `.mjs`),
|
|
160
|
+
* 防止把非标原生控件拆分到辅助渲染子模块绕过单组件检查。
|
|
161
|
+
*/
|
|
162
|
+
export async function scanAppComponentSources(root: string): Promise<KitDiagnostic[]> {
|
|
163
|
+
const fsSpec = 'node:fs/promises';
|
|
164
|
+
const pathSpec = 'node:path';
|
|
165
|
+
const fs = await import(fsSpec);
|
|
166
|
+
const path = await import(pathSpec);
|
|
167
|
+
const compDir = path.join(root, 'components');
|
|
168
|
+
const diagnostics: KitDiagnostic[] = [];
|
|
169
|
+
|
|
170
|
+
async function walk(dir: string): Promise<void> {
|
|
171
|
+
let entries: import('node:fs').Dirent[];
|
|
172
|
+
try {
|
|
173
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if ((error as { code?: string }).code === 'ENOENT') return;
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
179
|
+
for (const entry of entries) {
|
|
180
|
+
const full = path.join(dir, entry.name);
|
|
181
|
+
if (entry.isDirectory()) {
|
|
182
|
+
if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue;
|
|
183
|
+
await walk(full);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (!/\.(?:ts|js|mjs)$/.test(entry.name) || entry.name.endsWith('.d.ts')) continue;
|
|
187
|
+
const code = await fs.readFile(full, 'utf8');
|
|
188
|
+
// 仅对含可执行函数或模板字面量的组件/渲染模块扫描,跳过纯 JSON 常量数据字典
|
|
189
|
+
if (!code.includes('`') && !/\bfunction\b|=>|createElement/.test(code)) continue;
|
|
190
|
+
const rel = path.relative(root, full).split(path.sep).join('/');
|
|
191
|
+
for (const hit of findForbiddenNativeControls(code)) {
|
|
192
|
+
diagnostics.push({
|
|
193
|
+
code: 'KIT-APP-005',
|
|
194
|
+
path: `${rel}:${hit.line}`,
|
|
195
|
+
message: hit.message,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
await walk(compDir);
|
|
202
|
+
return diagnostics;
|
|
203
|
+
}
|
|
@@ -24,6 +24,7 @@ import { KitPackError, type KitPack } from './define-kit-pack';
|
|
|
24
24
|
import type { KitDiagnostic } from '../object-renderer/types';
|
|
25
25
|
import { createKitResidentDataComponents } from '../data/resident';
|
|
26
26
|
import { addWrappedOwnCandidates } from '../data/wrapped-candidates';
|
|
27
|
+
import { assertSinglePathComponent } from './component-gate';
|
|
27
28
|
import { KIT_STATIC_BUILTIN_LAZY_NAMES as KIT_STATIC_BUILTIN_NAMES, KIT_STATIC_LAZY_LOADERS } from '../data/static-lazy';
|
|
28
29
|
import type { KitFrameDefinition } from '../frames/types';
|
|
29
30
|
import type { KitNamedAction } from './define-kit-actions';
|
|
@@ -168,6 +169,7 @@ export function buildAppRegistry(options: DefineKitAppOptions): KitAppRegistry {
|
|
|
168
169
|
if (builtinBase.has(name) && !allow.has(name)) throw new Error(`[soma-kit] 基础组件 "${name}" 已内置;要覆盖请在 overrides 点名`);
|
|
169
170
|
const def = instantiate(name, input);
|
|
170
171
|
if (def.contract['layer'] !== 'basic') throw new Error(`[soma-kit] 应用基础组件 ${name} 的契约 layer 必须是 basic`);
|
|
172
|
+
assertSinglePathComponent(name, def);
|
|
171
173
|
baseComponents[name] = def;
|
|
172
174
|
}
|
|
173
175
|
|
|
@@ -181,6 +183,7 @@ export function buildAppRegistry(options: DefineKitAppOptions): KitAppRegistry {
|
|
|
181
183
|
const spec = isSpec(input);
|
|
182
184
|
const def = instantiate(name, spec ? input.define : input);
|
|
183
185
|
if (def.contract['layer'] !== 'data') throw new Error(`[soma-kit] 应用数据组件 ${name} 的契约 layer 必须是 data`);
|
|
186
|
+
assertSinglePathComponent(name, def);
|
|
184
187
|
staticComponents[name] = spec ? { definition: def, accept: input.accept } : { definition: def };
|
|
185
188
|
}
|
|
186
189
|
|
package/src/app/server.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type { KitDiagnostic } from '../object-renderer/types';
|
|
|
14
14
|
import { KIT_DEFAULT_THEME_CSS } from '../theme/kit-theme-text';
|
|
15
15
|
import { resolveKitThemeTokens, type KitThemeConfig } from '../theme/theme-tokens';
|
|
16
16
|
import { parseAppConfig } from './app-config';
|
|
17
|
+
import { scanAppComponentSources } from './component-gate';
|
|
17
18
|
import { setKitAppEnvelope } from './envelope';
|
|
18
19
|
import type { DefineKitAppOptions, KitAppRegistry } from './define-kit-app';
|
|
19
20
|
import { KIT_PAGE_OWNER, createKitServerPages } from './server-pages';
|
|
@@ -50,6 +51,10 @@ export function computeKitPageCacheKey(
|
|
|
50
51
|
.update('\0')
|
|
51
52
|
.update(JSON.stringify(appContext.envelope ?? null))
|
|
52
53
|
.update('\0')
|
|
54
|
+
.update(JSON.stringify(appContext.layout ?? null))
|
|
55
|
+
.update('\0')
|
|
56
|
+
.update(JSON.stringify(appContext.theme ?? null))
|
|
57
|
+
.update('\0')
|
|
53
58
|
.update(JSON.stringify(appContext.locales ?? null))
|
|
54
59
|
.update('\0')
|
|
55
60
|
.update((appContext.appCandidates ?? []).join('\0'))
|
|
@@ -157,7 +162,9 @@ export async function assembleKitServer(options: DefineKitAppOptions, registry:
|
|
|
157
162
|
staticContracts[name] = { accept, emits: Object.keys(entry.definition.contract.emits ?? {}), props: Object.keys(entry.definition.contract.props ?? {}) };
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
|
-
|
|
165
|
+
const sourceGateDiagnostics = await scanAppComponentSources(root);
|
|
166
|
+
diagnostics.push(...sourceGateDiagnostics);
|
|
167
|
+
if (diagnostics.length > 0) throw new KitAppAssemblyError('应用配置或扩展组件未通过唯一接入路径编译检查,拒绝启动', diagnostics);
|
|
161
168
|
|
|
162
169
|
// 3 主题头
|
|
163
170
|
let themeCss: string;
|
|
@@ -213,10 +220,12 @@ export async function assembleKitServer(options: DefineKitAppOptions, registry:
|
|
|
213
220
|
setKitAppEnvelope(config.envelope);
|
|
214
221
|
const appContext: KitAppContext = {
|
|
215
222
|
...(config.envelope !== undefined ? { envelope: config.envelope } : {}),
|
|
223
|
+
...(config.layout !== undefined ? { layout: config.layout } : {}),
|
|
216
224
|
...(options.defaultLocale !== undefined ? { defaultLocale: options.defaultLocale } : {}),
|
|
217
225
|
...(Object.keys(localeTables).length > 0 ? { locales: localeTables } : {}),
|
|
218
226
|
themeTokensCss: tokens.css,
|
|
219
227
|
...(themeInput !== undefined ? { themeConfig: themeInput } : {}),
|
|
228
|
+
...(config.theme !== undefined ? { theme: config.theme } : {}),
|
|
220
229
|
registeredActions: new Set(Object.keys(registry.actions)),
|
|
221
230
|
registeredComponents: new Set([...Object.keys(KIT_BASE_COMPONENTS), ...KIT_FORM_FIELD_DATA_COMPONENTS, ...Object.keys(registry.baseComponents)]),
|
|
222
231
|
staticComponents: staticContracts,
|
package/src/base/shared.ts
CHANGED
|
@@ -457,6 +457,8 @@ export interface KitTablistHandle {
|
|
|
457
457
|
/** 页签增删或禁用态变化后重画 ARIA 与 roving tabindex */
|
|
458
458
|
refresh(): void;
|
|
459
459
|
selected(): string | null;
|
|
460
|
+
/** 主动复位:恢复首个可用页签,并将 root 滚动位置归零 */
|
|
461
|
+
reset(): void;
|
|
460
462
|
destroy(): void;
|
|
461
463
|
}
|
|
462
464
|
|
|
@@ -473,19 +475,34 @@ export function wireKitTablist(root: HTMLElement, opts: KitTablistOptions = {}):
|
|
|
473
475
|
const idOf = opts.idOf ?? ((tab: HTMLElement): string => tab.dataset.key ?? tab.id);
|
|
474
476
|
const isDisabled = (tab: HTMLElement): boolean => tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true';
|
|
475
477
|
|
|
476
|
-
|
|
478
|
+
const findInitialSelected = (): string | null => {
|
|
479
|
+
if (opts.selected !== undefined) return opts.selected;
|
|
480
|
+
const existing = tabsOf().find((t) => t.getAttribute('aria-selected') === 'true' && !isDisabled(t));
|
|
481
|
+
if (existing) return idOf(existing);
|
|
482
|
+
const first = tabsOf().find((t) => !isDisabled(t));
|
|
483
|
+
return first ? idOf(first) : null;
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
let current: string | null = findInitialSelected();
|
|
477
487
|
let cursor: string | null = null;
|
|
478
488
|
|
|
479
489
|
const byId = (id: string | null): HTMLElement | undefined =>
|
|
480
490
|
id === null ? undefined : tabsOf().find((t) => idOf(t) === id);
|
|
481
491
|
|
|
482
492
|
const paint = (): void => {
|
|
493
|
+
const sLeft = root.scrollLeft;
|
|
494
|
+
const sTop = root.scrollTop;
|
|
483
495
|
const tabs = tabsOf();
|
|
484
496
|
root.setAttribute('role', 'tablist');
|
|
485
497
|
root.setAttribute('aria-orientation', orientation);
|
|
486
498
|
if (current === null || !tabs.some((t) => idOf(t) === current && !isDisabled(t))) {
|
|
487
|
-
const
|
|
488
|
-
|
|
499
|
+
const existing = tabs.find((t) => t.getAttribute('aria-selected') === 'true' && !isDisabled(t));
|
|
500
|
+
if (existing) {
|
|
501
|
+
current = idOf(existing);
|
|
502
|
+
} else {
|
|
503
|
+
const first = tabs.find((t) => !isDisabled(t));
|
|
504
|
+
current = first ? idOf(first) : null;
|
|
505
|
+
}
|
|
489
506
|
}
|
|
490
507
|
const focusAt = cursor !== null && tabs.some((t) => idOf(t) === cursor && !isDisabled(t)) ? cursor : current;
|
|
491
508
|
for (const tab of tabs) {
|
|
@@ -505,25 +522,50 @@ export function wireKitTablist(root: HTMLElement, opts: KitTablistOptions = {}):
|
|
|
505
522
|
if (opts.panelHidden !== false) setBoolAttr(panel, 'hidden', !on);
|
|
506
523
|
}
|
|
507
524
|
}
|
|
525
|
+
root.scrollLeft = sLeft;
|
|
526
|
+
root.scrollTop = sTop;
|
|
508
527
|
};
|
|
509
528
|
|
|
510
529
|
const focusTab = (id: string): void => {
|
|
530
|
+
const sLeft = root.scrollLeft;
|
|
531
|
+
const sTop = root.scrollTop;
|
|
511
532
|
cursor = id;
|
|
512
533
|
paint();
|
|
513
|
-
byId(id)?.focus();
|
|
534
|
+
byId(id)?.focus({ preventScroll: true });
|
|
535
|
+
root.scrollLeft = sLeft;
|
|
536
|
+
root.scrollTop = sTop;
|
|
514
537
|
};
|
|
515
538
|
|
|
516
539
|
const select = (id: string, o: { focus?: boolean; silent?: boolean } = {}): void => {
|
|
517
540
|
const tab = byId(id);
|
|
518
541
|
if (!tab || isDisabled(tab)) return;
|
|
519
542
|
const changed = current !== id;
|
|
543
|
+
const sLeft = root.scrollLeft;
|
|
544
|
+
const sTop = root.scrollTop;
|
|
520
545
|
current = id;
|
|
521
546
|
cursor = id;
|
|
522
547
|
paint();
|
|
523
|
-
if (o.focus === true) tab.focus();
|
|
548
|
+
if (o.focus === true) tab.focus({ preventScroll: true });
|
|
549
|
+
root.scrollLeft = sLeft;
|
|
550
|
+
root.scrollTop = sTop;
|
|
524
551
|
if (changed && o.silent !== true) opts.onSelect?.(id, tab);
|
|
525
552
|
};
|
|
526
553
|
|
|
554
|
+
const reset = (): void => {
|
|
555
|
+
const tabs = tabsOf();
|
|
556
|
+
const first = tabs.find((t) => !isDisabled(t));
|
|
557
|
+
const firstId = first ? idOf(first) : null;
|
|
558
|
+
const changed = current !== firstId;
|
|
559
|
+
current = firstId;
|
|
560
|
+
cursor = firstId;
|
|
561
|
+
paint();
|
|
562
|
+
root.scrollLeft = 0;
|
|
563
|
+
root.scrollTop = 0;
|
|
564
|
+
if (changed && first && firstId !== null) {
|
|
565
|
+
opts.onSelect?.(firstId, first);
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
|
|
527
569
|
const wiring = createKeyboardWiring({
|
|
528
570
|
host: root,
|
|
529
571
|
contract: {
|
|
@@ -563,6 +605,7 @@ export function wireKitTablist(root: HTMLElement, opts: KitTablistOptions = {}):
|
|
|
563
605
|
select,
|
|
564
606
|
refresh: paint,
|
|
565
607
|
selected: () => current,
|
|
608
|
+
reset,
|
|
566
609
|
destroy(): void {
|
|
567
610
|
root.removeEventListener('keydown', onKeydown);
|
|
568
611
|
root.removeEventListener('click', onClick);
|
package/src/base/text.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// (不带文本,避免凭据类文本再次上行);文字为空时不出钮。
|
|
5
5
|
|
|
6
6
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
7
|
+
import { TAG_CLASS } from './tag';
|
|
7
8
|
import { kitLocaleAt, kitText } from '../i18n/kit-text';
|
|
8
9
|
import {
|
|
9
10
|
CLASS_PROP, SIZE_PROP, OPTIONS_PROP,
|
|
@@ -24,7 +25,7 @@ const COPY_ROOT_CLASS: Record<KitSize, string> = {
|
|
|
24
25
|
};
|
|
25
26
|
const COPY_BTN_CLASS = 'inline-flex shrink-0 cursor-pointer items-center rounded-sm px-1.5 py-0.5 text-xs font-medium text-primary transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
26
27
|
|
|
27
|
-
export const KIT_TEXT_CLASS_CANDIDATES: readonly string[] = classCandidates(Object.values(COPY_ROOT_CLASS), COPY_BTN_CLASS);
|
|
28
|
+
export const KIT_TEXT_CLASS_CANDIDATES: readonly string[] = classCandidates(Object.values(COPY_ROOT_CLASS), COPY_BTN_CLASS, ...Object.values(TAG_CLASS).flatMap((m) => Object.values(m)));
|
|
28
29
|
|
|
29
30
|
const COPIED_MS = 1500;
|
|
30
31
|
|
|
@@ -103,7 +104,8 @@ export function createText(): SomaComponentDefinition {
|
|
|
103
104
|
};
|
|
104
105
|
},
|
|
105
106
|
render(root, p) {
|
|
106
|
-
const { text } = displayOf(p.value, optionsOf(p.options), str(p.format), str(p.locale, kitLocaleAt(root) || 'zh-CN'), str(p.placeholder));
|
|
107
|
+
const { text, option } = displayOf(p.value, optionsOf(p.options), str(p.format), str(p.locale, kitLocaleAt(root) || 'zh-CN'), str(p.placeholder));
|
|
108
|
+
const tone = option?.tone;
|
|
107
109
|
const size = sizeOf(p.size);
|
|
108
110
|
const raw = p.value;
|
|
109
111
|
const empty = raw === null || raw === undefined || raw === '' || (Array.isArray(raw) && raw.length === 0);
|
|
@@ -121,6 +123,10 @@ export function createText(): SomaComponentDefinition {
|
|
|
121
123
|
root.className = joinClass(COPY_ROOT_CLASS[size], p.class);
|
|
122
124
|
return;
|
|
123
125
|
}
|
|
126
|
+
if (!empty && !bool(p.copyable) && tone !== undefined) {
|
|
127
|
+
root.className = joinClass(TAG_CLASS[size][tone], p.class);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
124
130
|
root.className = joinClass(TEXT_CLASS[size], p.class);
|
|
125
131
|
},
|
|
126
132
|
}),
|
package/src/biz/index.ts
CHANGED
|
@@ -20,6 +20,17 @@ import { LandingPage } from './landing-page';
|
|
|
20
20
|
import { ResultPage } from './page-templates/result-page';
|
|
21
21
|
import { SignInPage } from './page-templates/sign-in-page';
|
|
22
22
|
import { ImportWizard } from './import-wizard';
|
|
23
|
+
import {
|
|
24
|
+
KanbanBoardDesk,
|
|
25
|
+
ScheduleGanttDesk,
|
|
26
|
+
JobQueueMonitor,
|
|
27
|
+
BulkMergeDesk,
|
|
28
|
+
RuleEngineDesk,
|
|
29
|
+
CapacityScheduleDesk,
|
|
30
|
+
TraceDiagnosticDesk,
|
|
31
|
+
TicketServiceDesk,
|
|
32
|
+
} from "./page-templates/domain-templates";
|
|
33
|
+
|
|
23
34
|
import type { KitBizDefinition } from './types';
|
|
24
35
|
|
|
25
36
|
export { defineKitBizComponent } from './define';
|
|
@@ -46,6 +57,17 @@ export { StepForm, compileStepForm, stepFormObjectName, createKitStepHub, KIT_ST
|
|
|
46
57
|
|
|
47
58
|
export { ResultPage, compileResultPage, resultPageObjectName } from './page-templates/result-page';
|
|
48
59
|
export { SignInPage, compileSignInPage, parseSignInConfig } from './page-templates/sign-in-page';
|
|
60
|
+
export {
|
|
61
|
+
KanbanBoardDesk,
|
|
62
|
+
ScheduleGanttDesk,
|
|
63
|
+
JobQueueMonitor,
|
|
64
|
+
BulkMergeDesk,
|
|
65
|
+
RuleEngineDesk,
|
|
66
|
+
CapacityScheduleDesk,
|
|
67
|
+
TraceDiagnosticDesk,
|
|
68
|
+
TicketServiceDesk,
|
|
69
|
+
} from "./page-templates/domain-templates";
|
|
70
|
+
|
|
49
71
|
export {
|
|
50
72
|
ImportWizard, compileImportWizard, importWizardObjectName, createKitImportHub, KIT_IMPORT_EVENTS, KIT_IMPORT_MIRRORS,
|
|
51
73
|
} from './import-wizard';
|
|
@@ -56,6 +78,14 @@ export {
|
|
|
56
78
|
*/
|
|
57
79
|
export const KIT_PAGE_TEMPLATES: Record<string, KitBizDefinition> = {
|
|
58
80
|
SignInPage,
|
|
81
|
+
KanbanBoardDesk,
|
|
82
|
+
ScheduleGanttDesk,
|
|
83
|
+
JobQueueMonitor,
|
|
84
|
+
BulkMergeDesk,
|
|
85
|
+
RuleEngineDesk,
|
|
86
|
+
CapacityScheduleDesk,
|
|
87
|
+
TraceDiagnosticDesk,
|
|
88
|
+
TicketServiceDesk,
|
|
59
89
|
};
|
|
60
90
|
|
|
61
91
|
export const KIT_BIZ_COMPONENTS: Record<string, KitBizDefinition> = {
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// 跨领域标准业务组件模板库(domain-templates.ts)
|
|
2
|
+
// 承接来自企业级与各行业场景的 8 个高频跨领域标准业务组件模板:
|
|
3
|
+
// 1. KanbanBoardDesk(敏捷泳道看板工作台:roles filter? + board + summary?)
|
|
4
|
+
// 2. ScheduleGanttDesk(里程碑甘特排期工作台:roles filter? + schedule + milestones?)
|
|
5
|
+
// 3. JobQueueMonitor(异步任务队列与执行日志调度台:roles metrics? + queue + logs?)
|
|
6
|
+
// 4. BulkMergeDesk(批量编辑与重复记录合并去重台:roles candidates + comparison + target?)
|
|
7
|
+
// 5. RuleEngineDesk(可视化规则引擎与流程编排台:roles catalog? + rules + simulation?)
|
|
8
|
+
// 6. CapacityScheduleDesk(排班轮值与资源容量看板:roles filter? + capacity + rotation?)
|
|
9
|
+
// 7. TraceDiagnosticDesk(调用链瀑布流与服务拓扑诊断台:roles topology? + traces + spans?)
|
|
10
|
+
// 8. TicketServiceDesk(全渠道工单客服与协同评论台:roles queue + ticket + comments?)
|
|
11
|
+
|
|
12
|
+
import { defineKitBizComponent } from "../define";
|
|
13
|
+
import type { KitBizContext, KitBizDefinition, KitBizInput, KitBizRole } from "../types";
|
|
14
|
+
import type { KitFragment } from "../../compile/fragment";
|
|
15
|
+
import type { KitObject } from "../../object-renderer/types";
|
|
16
|
+
import { emitObject } from "../../object-renderer/emit-object";
|
|
17
|
+
import { addEmit, classesIn, isRec, newParts } from "../link/shared";
|
|
18
|
+
import { checkAreas, finishTemplate, templateObjectName } from "./shared";
|
|
19
|
+
|
|
20
|
+
function compileDomainTemplate(
|
|
21
|
+
input: KitBizInput,
|
|
22
|
+
ctx: KitBizContext,
|
|
23
|
+
kind: string,
|
|
24
|
+
roleDefs: Record<string, KitBizRole>,
|
|
25
|
+
areas: readonly string[],
|
|
26
|
+
): KitFragment {
|
|
27
|
+
const out = newParts([]);
|
|
28
|
+
const fail = (code: string, message: string, path: string): void => {
|
|
29
|
+
out.diagnostics.push({ code, message, path });
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// 1. 检查必填角色
|
|
33
|
+
for (const [rName, rDef] of Object.entries(roleDefs)) {
|
|
34
|
+
if (rDef.required) {
|
|
35
|
+
const raw = input.objects[rName];
|
|
36
|
+
if (!isRec(raw)) {
|
|
37
|
+
fail("KIT-BIZ-001", `${kind} 缺少必填对象角色槽 ${rName}`, `product.objects.${rName}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 2. 检查区域类
|
|
43
|
+
checkAreas(input, kind, areas, out);
|
|
44
|
+
if (out.diagnostics.length > 0) return finishTemplate(out, "");
|
|
45
|
+
|
|
46
|
+
const areaClass = input.areaClass ?? {};
|
|
47
|
+
const sectionHtmls: string[] = [];
|
|
48
|
+
|
|
49
|
+
// 3. 逐个角色发射对象
|
|
50
|
+
for (const [rName] of Object.entries(roleDefs)) {
|
|
51
|
+
const raw = input.objects[rName];
|
|
52
|
+
if (!isRec(raw)) continue;
|
|
53
|
+
|
|
54
|
+
const objectName = templateObjectName(ctx.pageId, rName);
|
|
55
|
+
const hasFrom = isRec(raw.behavior) && raw.behavior.from !== undefined;
|
|
56
|
+
|
|
57
|
+
const emitRes = emitObject(
|
|
58
|
+
raw as unknown as KitObject,
|
|
59
|
+
{
|
|
60
|
+
object: objectName,
|
|
61
|
+
scope: `${objectName}_scope`,
|
|
62
|
+
registered: ctx.registeredComponents,
|
|
63
|
+
staticComponents: ctx.staticComponents,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
registeredActions: ctx.registeredActions,
|
|
67
|
+
formMode: hasFrom ? "edit" : "create",
|
|
68
|
+
...(hasFrom ? { formInitialPath: `page.data.${objectName}` } : {}),
|
|
69
|
+
},
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
addEmit(out, emitRes);
|
|
73
|
+
|
|
74
|
+
const customClass = areaClass[rName] ?? "";
|
|
75
|
+
const sectionClass = customClass ? ` ${customClass}` : "";
|
|
76
|
+
sectionHtmls.push(
|
|
77
|
+
`<section class="p-4 rounded-lg bg-surface border border-subtle${sectionClass}" data-soma-id="${objectName}__root">\n${emitRes.html}\n</section>`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (out.diagnostics.length > 0) return finishTemplate(out, "");
|
|
82
|
+
|
|
83
|
+
const rootClass = input.class ? ` ${input.class}` : "";
|
|
84
|
+
const html = `<div data-soma-id="${ctx.pageId}__${kind.toLowerCase()}_root" class="flex flex-col gap-4 p-4${rootClass}">\n${sectionHtmls.join("\n")}\n</div>`;
|
|
85
|
+
|
|
86
|
+
for (const c of classesIn(html)) out.candidates.add(c);
|
|
87
|
+
return finishTemplate(out, html);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 1. 敏捷泳道看板工作台
|
|
91
|
+
export const KanbanBoardDesk: KitBizDefinition = defineKitBizComponent({
|
|
92
|
+
kind: "KanbanBoardDesk",
|
|
93
|
+
roles: {
|
|
94
|
+
filter: { required: false, views: ["filter", "form"] },
|
|
95
|
+
board: { required: true, views: ["list", "summary"] },
|
|
96
|
+
summary: { required: false, views: ["summary", "list"] },
|
|
97
|
+
},
|
|
98
|
+
areas: ["root", "filter", "board", "summary"],
|
|
99
|
+
compile: (input, ctx) => compileDomainTemplate(input, ctx, "KanbanBoardDesk", KanbanBoardDesk.roles, KanbanBoardDesk.areas),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// 2. 里程碑甘特排期工作台
|
|
103
|
+
export const ScheduleGanttDesk: KitBizDefinition = defineKitBizComponent({
|
|
104
|
+
kind: "ScheduleGanttDesk",
|
|
105
|
+
roles: {
|
|
106
|
+
filter: { required: false, views: ["filter", "form"] },
|
|
107
|
+
schedule: { required: true, views: ["list", "summary"] },
|
|
108
|
+
milestones: { required: false, views: ["list", "summary"] },
|
|
109
|
+
},
|
|
110
|
+
areas: ["root", "filter", "schedule", "milestones"],
|
|
111
|
+
compile: (input, ctx) => compileDomainTemplate(input, ctx, "ScheduleGanttDesk", ScheduleGanttDesk.roles, ScheduleGanttDesk.areas),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// 3. 异步任务队列与执行日志调度台
|
|
115
|
+
export const JobQueueMonitor: KitBizDefinition = defineKitBizComponent({
|
|
116
|
+
kind: "JobQueueMonitor",
|
|
117
|
+
roles: {
|
|
118
|
+
metrics: { required: false, views: ["summary", "list"] },
|
|
119
|
+
queue: { required: true, views: ["list", "summary"] },
|
|
120
|
+
logs: { required: false, views: ["list", "summary"] },
|
|
121
|
+
},
|
|
122
|
+
areas: ["root", "metrics", "queue", "logs"],
|
|
123
|
+
compile: (input, ctx) => compileDomainTemplate(input, ctx, "JobQueueMonitor", JobQueueMonitor.roles, JobQueueMonitor.areas),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// 4. 批量编辑与重复记录合并去重台
|
|
127
|
+
export const BulkMergeDesk: KitBizDefinition = defineKitBizComponent({
|
|
128
|
+
kind: "BulkMergeDesk",
|
|
129
|
+
roles: {
|
|
130
|
+
candidates: { required: true, views: ["list", "summary"] },
|
|
131
|
+
comparison: { required: true, views: ["list", "summary", "form"] },
|
|
132
|
+
target: { required: false, views: ["form", "summary"] },
|
|
133
|
+
},
|
|
134
|
+
areas: ["root", "candidates", "comparison", "target"],
|
|
135
|
+
compile: (input, ctx) => compileDomainTemplate(input, ctx, "BulkMergeDesk", BulkMergeDesk.roles, BulkMergeDesk.areas),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// 5. 可视化规则引擎与流程编排台
|
|
139
|
+
export const RuleEngineDesk: KitBizDefinition = defineKitBizComponent({
|
|
140
|
+
kind: "RuleEngineDesk",
|
|
141
|
+
roles: {
|
|
142
|
+
catalog: { required: false, views: ["list", "summary"] },
|
|
143
|
+
rules: { required: true, views: ["list", "summary", "form"] },
|
|
144
|
+
simulation: { required: false, views: ["form", "summary"] },
|
|
145
|
+
},
|
|
146
|
+
areas: ["root", "catalog", "rules", "simulation"],
|
|
147
|
+
compile: (input, ctx) => compileDomainTemplate(input, ctx, "RuleEngineDesk", RuleEngineDesk.roles, RuleEngineDesk.areas),
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// 6. 排班轮值与资源容量看板
|
|
151
|
+
export const CapacityScheduleDesk: KitBizDefinition = defineKitBizComponent({
|
|
152
|
+
kind: "CapacityScheduleDesk",
|
|
153
|
+
roles: {
|
|
154
|
+
filter: { required: false, views: ["filter", "form"] },
|
|
155
|
+
capacity: { required: true, views: ["list", "summary"] },
|
|
156
|
+
rotation: { required: false, views: ["list", "summary"] },
|
|
157
|
+
},
|
|
158
|
+
areas: ["root", "filter", "capacity", "rotation"],
|
|
159
|
+
compile: (input, ctx) => compileDomainTemplate(input, ctx, "CapacityScheduleDesk", CapacityScheduleDesk.roles, CapacityScheduleDesk.areas),
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// 7. 调用链瀑布流与服务拓扑诊断台
|
|
163
|
+
export const TraceDiagnosticDesk: KitBizDefinition = defineKitBizComponent({
|
|
164
|
+
kind: "TraceDiagnosticDesk",
|
|
165
|
+
roles: {
|
|
166
|
+
topology: { required: false, views: ["summary", "list"] },
|
|
167
|
+
traces: { required: true, views: ["list", "summary"] },
|
|
168
|
+
spans: { required: false, views: ["list", "summary"] },
|
|
169
|
+
},
|
|
170
|
+
areas: ["root", "topology", "traces", "spans"],
|
|
171
|
+
compile: (input, ctx) => compileDomainTemplate(input, ctx, "TraceDiagnosticDesk", TraceDiagnosticDesk.roles, TraceDiagnosticDesk.areas),
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// 8. 全渠道工单客服与协同评论台
|
|
175
|
+
export const TicketServiceDesk: KitBizDefinition = defineKitBizComponent({
|
|
176
|
+
kind: "TicketServiceDesk",
|
|
177
|
+
roles: {
|
|
178
|
+
queue: { required: true, views: ["list", "summary"] },
|
|
179
|
+
ticket: { required: true, views: ["summary", "form", "list"] },
|
|
180
|
+
comments: { required: false, views: ["list", "summary"] },
|
|
181
|
+
},
|
|
182
|
+
areas: ["root", "queue", "ticket", "comments"],
|
|
183
|
+
compile: (input, ctx) => compileDomainTemplate(input, ctx, "TicketServiceDesk", TicketServiceDesk.roles, TicketServiceDesk.areas),
|
|
184
|
+
});
|