soma-kit 0.1.11 → 0.1.13
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 +106 -112
- package/bin/soma-kit.mjs +32 -2
- package/bin/soma.mjs +22 -0
- package/package.json +14 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +929 -37
- package/spec/generated/kit-page.schema.json +1684 -161
- package/spec/kit-grammar.json +1176 -584
- package/spec/kit-grammar.schema.json +1971 -393
- package/src/app/app-config.ts +449 -347
- package/src/app/component-gate.ts +283 -28
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +176 -33
- package/src/app/define-kit-view.ts +104 -0
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +29 -6
- package/src/app/kit-view-context.ts +439 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +11 -3
- package/src/app/server.ts +530 -103
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +667 -0
- package/src/base/action-busy.ts +103 -6
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +58 -0
- package/src/base/alert.ts +5 -3
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +99 -37
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +9 -1
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +49 -28
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +16 -11
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +10 -6
- package/src/base/context-menu.ts +10 -7
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +32 -18
- package/src/base/date.ts +135 -28
- package/src/base/delta.ts +72 -0
- package/src/base/divider.ts +2 -2
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +12 -5
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +35 -11
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +56 -35
- package/src/base/loading-gate.ts +186 -0
- package/src/base/mentions.ts +7 -6
- package/src/base/menu-button.ts +28 -12
- package/src/base/menu-core.ts +41 -8
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +3 -3
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +3 -3
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +9 -5
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +48 -16
- package/src/base/popup.ts +143 -19
- package/src/base/portal-core.ts +4 -0
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +14 -8
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +21 -4
- package/src/base/rating.ts +12 -7
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +27 -21
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +387 -49
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +10 -7
- package/src/base/switch.ts +11 -6
- package/src/base/tag-input.ts +20 -16
- package/src/base/tag.ts +68 -34
- package/src/base/text.ts +80 -18
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +18 -13
- package/src/base/tree-select.ts +21 -12
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +48 -14
- package/src/base/view-transition.ts +77 -0
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +23 -37
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +22 -5
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +5 -4
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +69 -22
- package/src/biz/link/shared.ts +127 -119
- package/src/biz/master-sub/compile.ts +127 -48
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +38 -50
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +32 -20
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +48 -43
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +7 -5
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +97 -211
- package/src/biz/shared/compile-helpers.ts +98 -0
- package/src/biz/shared/coordinator.ts +472 -92
- package/src/biz/shared/index.ts +13 -2
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +209 -0
- package/src/biz/shared/pipes.ts +50 -31
- package/src/biz/shared/remove-wire.ts +14 -0
- package/src/biz/shared/runtime-hub.ts +226 -24
- package/src/biz/single-form/compile.ts +16 -37
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +72 -255
- package/src/biz/standard-crud/shell.ts +21 -99
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/step-form/shell.ts +5 -5
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +254 -25
- package/src/cli/kit-init.ts +227 -0
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +761 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +570 -0
- package/src/compile/compile-page.ts +267 -76
- package/src/compile/component-candidates.ts +13 -2
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +63 -2
- package/src/compile/types.ts +31 -3
- package/src/compile/view-check.ts +284 -0
- package/src/data/amount-breakdown.ts +8 -3
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +3 -3
- package/src/data/assignment-picker.ts +92 -55
- package/src/data/async-result-panel.ts +111 -9
- package/src/data/breadcrumbs.ts +5 -4
- package/src/data/calendar.ts +24 -27
- package/src/data/carousel.ts +13 -8
- package/src/data/chart.ts +183 -44
- package/src/data/checklist.ts +20 -7
- package/src/data/code-view.ts +12 -6
- package/src/data/comment-thread.ts +7 -4
- package/src/data/confirm-dialog.ts +81 -18
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +3 -3
- package/src/data/embed.ts +233 -30
- package/src/data/field-mapper.ts +35 -30
- package/src/data/flow-editor-contract.ts +8 -1
- package/src/data/flow-editor.ts +113 -108
- package/src/data/flow-node-options.ts +120 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +19 -19
- package/src/data/hero.ts +4 -3
- package/src/data/image-viewer.ts +27 -30
- package/src/data/index.ts +5 -2
- package/src/data/item-list.ts +48 -31
- package/src/data/kanban.ts +82 -52
- package/src/data/media-grid.ts +20 -20
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +47 -15
- package/src/data/mockup.ts +10 -6
- package/src/data/modal-dialog.ts +49 -25
- package/src/data/navbar.ts +12 -7
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +250 -0
- package/src/data/object-form.ts +1360 -666
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +80 -34
- package/src/data/permission-matrix.ts +52 -31
- package/src/data/permission-tree.ts +71 -44
- package/src/data/pricing-table.ts +30 -14
- package/src/data/prompt-dialog.ts +124 -194
- package/src/data/reaction-bar.ts +83 -92
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +26 -5
- package/src/data/record-picker.ts +104 -55
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +8 -4
- package/src/data/rich-text.ts +61 -55
- package/src/data/row-editor.ts +362 -76
- package/src/data/rule-builder.ts +26 -20
- package/src/data/shape-util.ts +27 -9
- package/src/data/stat-group.ts +392 -109
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +24 -11
- package/src/data/steps.ts +10 -5
- package/src/data/survey.ts +27 -32
- package/src/data/system-switcher.ts +3 -3
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +19 -8
- package/src/data/tour-guide.ts +23 -30
- package/src/data/transfer.ts +62 -38
- package/src/data/tree-table.ts +152 -78
- package/src/data/tree.ts +49 -36
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +133 -82
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +26 -24
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +9 -7
- package/src/frames/shared.ts +36 -25
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +6 -6
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +4 -14
- package/src/frames/tabs-frame/wiring.ts +5 -8
- package/src/frames/top-main-frame.ts +3 -2
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +21 -5
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +3 -2
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +250 -48
- package/src/generated/kit-grammar-runtime.ts +645 -397
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +84 -29
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +112 -84
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +401 -104
- package/src/object-renderer/collection-table.ts +287 -45
- package/src/object-renderer/collection.ts +258 -104
- package/src/object-renderer/compile-data.ts +112 -102
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +38 -16
- package/src/object-renderer/display-checks.ts +4 -25
- package/src/object-renderer/emit-events.ts +224 -176
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +533 -151
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +111 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +456 -89
- package/src/object-renderer/request-actions.ts +232 -249
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +319 -111
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +429 -94
- package/src/object-renderer/types.ts +204 -127
- package/src/object-renderer/view-binding.ts +393 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +165 -28
- package/src/page-target/target.ts +262 -51
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +210 -0
- package/src/recipes/control.ts +277 -0
- package/src/recipes/index.ts +312 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +240 -0
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +99 -0
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +88 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +99 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +15 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +180 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +13 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +407 -10
- package/src/theme/kit-theme.tpl +407 -10
- package/src/theme/nine-dim-structure.ts +247 -0
- package/src/theme/surface-layers.ts +101 -0
- package/src/theme/theme-tokens.ts +130 -84
- package/src/theme/theme-types.ts +103 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
// `soma kit migrate` 的 YAML 自动改写规则(kit.app.yaml 与 *.kit.yaml)。全部是行内定点改动:
|
|
2
|
+
// 按行定位 + 按字符偏移改 flow 项,不解析再导出,所以注释、排版、引号风格原样保留。
|
|
3
|
+
// 一次遍历在「原文行」上收集全部编辑(互不重叠),最后统一应用,行号因此始终是原文件行号。
|
|
4
|
+
import { load as loadYaml } from 'js-yaml';
|
|
5
|
+
import {
|
|
6
|
+
analyzeYaml,
|
|
7
|
+
applyLineEdits,
|
|
8
|
+
childRange,
|
|
9
|
+
findClose,
|
|
10
|
+
flowEntries,
|
|
11
|
+
removeFlowEntry,
|
|
12
|
+
splitLines,
|
|
13
|
+
unquote,
|
|
14
|
+
wholeFlowMap,
|
|
15
|
+
type LineEdit,
|
|
16
|
+
type YLine,
|
|
17
|
+
} from './text-utils';
|
|
18
|
+
import {
|
|
19
|
+
DEFAULT_FONT_FAMILY,
|
|
20
|
+
DEFAULT_PALETTE,
|
|
21
|
+
LEGACY_COLOR_KEYS,
|
|
22
|
+
LEGACY_FONT_KEYS,
|
|
23
|
+
LEGACY_PALETTE_KEYS,
|
|
24
|
+
mapFontScheme,
|
|
25
|
+
mapPaletteScheme,
|
|
26
|
+
} from './theme-map';
|
|
27
|
+
import type { MigrateChange, MigrateFinding } from './types';
|
|
28
|
+
|
|
29
|
+
/** 应用信封里「判失败」的那一条(kit.app.yaml#envelope);只认 failWhen = { field, op: eq, value: false } 这一种形状 */
|
|
30
|
+
export interface EnvelopeInfo {
|
|
31
|
+
readonly failField?: string;
|
|
32
|
+
readonly messagePath?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 从 kit.app.yaml 文本读信封;读不出来返回 undefined */
|
|
36
|
+
export function envelopeOfAppYaml(text: string): EnvelopeInfo | undefined {
|
|
37
|
+
let doc: unknown;
|
|
38
|
+
try {
|
|
39
|
+
doc = loadYaml(text);
|
|
40
|
+
} catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const env = (doc as { envelope?: unknown } | null | undefined)?.envelope;
|
|
44
|
+
if (env === null || typeof env !== 'object') return undefined;
|
|
45
|
+
const e = env as { failWhen?: { field?: unknown; op?: unknown; value?: unknown }; messagePath?: unknown };
|
|
46
|
+
const fw = e.failWhen;
|
|
47
|
+
const failField = fw !== undefined && fw !== null && typeof fw.field === 'string' && fw.op === 'eq' && fw.value === false ? fw.field : undefined;
|
|
48
|
+
return {
|
|
49
|
+
...(failField !== undefined ? { failField } : {}),
|
|
50
|
+
...(typeof e.messagePath === 'string' ? { messagePath: e.messagePath } : {}),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface YamlPass {
|
|
55
|
+
readonly text: string;
|
|
56
|
+
readonly changes: MigrateChange[];
|
|
57
|
+
readonly findings: MigrateFinding[];
|
|
58
|
+
/** 已被本遍自动改写或已出报告项的原文行下标(0 基),后续通用扫描据此跳过,避免重复 */
|
|
59
|
+
readonly covered: Set<number>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface Ctx {
|
|
63
|
+
readonly file: string;
|
|
64
|
+
readonly lines: readonly string[];
|
|
65
|
+
readonly ys: readonly YLine[];
|
|
66
|
+
readonly env: EnvelopeInfo | undefined;
|
|
67
|
+
readonly edits: LineEdit[];
|
|
68
|
+
readonly changes: MigrateChange[];
|
|
69
|
+
readonly findings: MigrateFinding[];
|
|
70
|
+
readonly covered: Set<number>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const summary = (s: string): string => s.trim().replace(/\s+/g, ' ');
|
|
74
|
+
|
|
75
|
+
function change(c: Ctx, rule: string, line0: number, message: string, before?: string, after?: string): void {
|
|
76
|
+
c.changes.push({ rule, file: c.file, line: line0 + 1, message, ...(before !== undefined ? { before: summary(before) } : {}), ...(after !== undefined ? { after: summary(after) } : {}) });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function finding(c: Ctx, rule: string, line0: number, message: string, recipe: string, meta?: Record<string, string>): void {
|
|
80
|
+
c.findings.push({ rule, file: c.file, line: line0 + 1, message, recipe, ...(meta !== undefined ? { meta } : {}) });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 键行的 rest 在整行文本里的起始偏移 */
|
|
84
|
+
const restStart = (l: YLine): number => l.text.length - l.rest.length;
|
|
85
|
+
|
|
86
|
+
// ---------------------------------------------------------------- 规则 1:page.eyebrow
|
|
87
|
+
function ruleEyebrow(c: Ctx): void {
|
|
88
|
+
for (const l of c.ys) {
|
|
89
|
+
if (l.cont || l.key !== 'eyebrow' || l.path.length !== 1 || l.path[0] !== 'page') continue;
|
|
90
|
+
let end = l.i + 1;
|
|
91
|
+
while (end < c.ys.length && !c.ys[end]!.blank && c.ys[end]!.indent > l.keyCol) end += 1;
|
|
92
|
+
c.edits.push({ from: l.i, to: end, replacement: [] });
|
|
93
|
+
change(c, 'AUTO-EYEBROW', l.i, '删除 page.eyebrow(页头不再有眉题)', l.text);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ---------------------------------------------------------------- 规则 2:collection.density
|
|
98
|
+
function ruleDensity(c: Ctx): void {
|
|
99
|
+
for (const l of c.ys) {
|
|
100
|
+
if (l.cont || l.key === undefined) continue;
|
|
101
|
+
if (l.key === 'density' && l.path[l.path.length - 1] === 'collection' && l.value !== '' && !l.value.startsWith('{')) {
|
|
102
|
+
c.edits.push({ from: l.i, to: l.i + 1, replacement: [] });
|
|
103
|
+
change(c, 'AUTO-DENSITY', l.i, '删除 collection.density(密度只在 kit.app.yaml 的 theme.density,KIT-OBJ-011)', l.text);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (l.key === 'collection' && l.value.startsWith('{')) {
|
|
107
|
+
const open = restStart(l);
|
|
108
|
+
const close = findClose(l.text, open);
|
|
109
|
+
if (close < 0) continue;
|
|
110
|
+
const entries = flowEntries(l.text, open, close);
|
|
111
|
+
const k = entries.findIndex((e) => e.key === 'density');
|
|
112
|
+
if (k < 0) continue;
|
|
113
|
+
const next = removeFlowEntry(l.text, open, close, k);
|
|
114
|
+
c.edits.push({ from: l.i, to: l.i + 1, replacement: [next] });
|
|
115
|
+
change(c, 'AUTO-DENSITY', l.i, '删除 collection.density(密度只在 kit.app.yaml 的 theme.density,KIT-OBJ-011)', l.text, next);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ---------------------------------------------------------------- 规则 3~6:request 动作
|
|
121
|
+
interface ReqEntry {
|
|
122
|
+
readonly key: string;
|
|
123
|
+
readonly start: number;
|
|
124
|
+
readonly end: number;
|
|
125
|
+
readonly line: YLine;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function requestEntries(ys: readonly YLine[], range: { start: number; end: number }): ReqEntry[] {
|
|
129
|
+
const col = ys[range.start]!.keyCol;
|
|
130
|
+
const heads = ys.slice(range.start, range.end).filter((l) => !l.cont && !l.blank && l.key !== undefined && l.keyCol === col);
|
|
131
|
+
return heads.map((l, n) => {
|
|
132
|
+
let end = n + 1 < heads.length ? heads[n + 1]!.i : range.end;
|
|
133
|
+
while (end - 1 > l.i && ys[end - 1]!.blank) end -= 1;
|
|
134
|
+
return { key: l.key!, start: l.i, end, line: l };
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
type BodyPair = [string, string];
|
|
139
|
+
|
|
140
|
+
interface BodyPlan {
|
|
141
|
+
readonly pick: string[];
|
|
142
|
+
readonly bodyMap: BodyPair[];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** 一个 body 键值能否机械翻成 pick / bodyMap;不能返回原因 */
|
|
146
|
+
function planBody(pairs: readonly BodyPair[]): BodyPlan | { bad: Array<[string, string]> } {
|
|
147
|
+
const pick: string[] = [];
|
|
148
|
+
const bodyMap: BodyPair[] = [];
|
|
149
|
+
const bad: Array<[string, string]> = [];
|
|
150
|
+
for (const [k, raw] of pairs) {
|
|
151
|
+
const v = unquote(raw);
|
|
152
|
+
const m = /^\$(row|draft|focus)\.([A-Za-z_]\w*)$/.exec(v);
|
|
153
|
+
if (m !== null) {
|
|
154
|
+
const [, from, name] = m as unknown as [string, string, string];
|
|
155
|
+
if (from !== 'focus' && name === k) pick.push(k);
|
|
156
|
+
else bodyMap.push([k, name]);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (v === '$value') {
|
|
160
|
+
bodyMap.push([k, 'value']);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
bad.push([k, raw]);
|
|
164
|
+
}
|
|
165
|
+
return bad.length > 0 ? { bad } : { pick, bodyMap };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function bodyRecipe(bad: ReadonlyArray<[string, string]>): string {
|
|
169
|
+
const rows = bad.map(([k, v]) => ` ${k}: ${v}`).join('\n');
|
|
170
|
+
return [
|
|
171
|
+
'这些键值无法机械翻译(0.1.13 的 request 只认 pick / bodyMap,不再有 $ 取值路径):',
|
|
172
|
+
rows,
|
|
173
|
+
'按来源处理:',
|
|
174
|
+
' $row.<同名字段> -> pick: [字段](载荷取当前行同名字段)',
|
|
175
|
+
' $draft.<字段> -> 同名 pick;换名用 bodyMap: { 键: 草稿字段 };整个 $draft 先由展示对象写进隐藏字段 draftSnapshot(schema: { type: text, permission: w, hidden: true })再 bodyMap: { draft: draftSnapshot }',
|
|
176
|
+
' $focus.<字段> / $value -> bodyMap: { 键: 字段 } / bodyMap: { 键: value }',
|
|
177
|
+
' $loaded.* / $steps.* / $event.* / $prompt.* / 字面量 -> 由展示对象方法带进载荷:ctx.request(对象, 动作id, { row, 键: 值 }),yaml 里对应 bodyMap: { 键: 键 }',
|
|
178
|
+
].join('\n');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function ruleRequests(c: Ctx): void {
|
|
182
|
+
for (const l of c.ys) {
|
|
183
|
+
if (l.cont || l.key !== 'request' || l.value !== '') continue;
|
|
184
|
+
const range = childRange(c.ys, l.i);
|
|
185
|
+
if (range === undefined) continue;
|
|
186
|
+
const entries = requestEntries(c.ys, range);
|
|
187
|
+
const has = (k: string): boolean => entries.some((e) => e.key === k);
|
|
188
|
+
|
|
189
|
+
for (const e of entries) {
|
|
190
|
+
const el = e.line;
|
|
191
|
+
const pad = el.text.slice(0, el.keyCol);
|
|
192
|
+
if (e.key === 'ok') ruleRequestOk(c, e, entries);
|
|
193
|
+
else if (e.key === 'body') ruleRequestBody(c, e, pad, has('pick') || has('bodyMap'));
|
|
194
|
+
else if (e.key === 'then') {
|
|
195
|
+
if (el.value === 'none') {
|
|
196
|
+
const e0: LineEdit = has('read') ? { from: e.start, to: e.end, replacement: [] } : { from: e.start, to: e.end, replacement: [`${pad}read: true${el.comment !== undefined ? ` ${el.comment}` : ''}`] };
|
|
197
|
+
c.edits.push(e0);
|
|
198
|
+
change(c, 'AUTO-REQ-THEN-NONE', e.start, 'request.then: none 改为 read: true(只读请求,成功后宿主不重取)', el.text, has('read') ? '(已有 read,删除)' : 'read: true');
|
|
199
|
+
} else {
|
|
200
|
+
c.covered.add(e.start);
|
|
201
|
+
finding(
|
|
202
|
+
c,
|
|
203
|
+
'MANUAL-AFTERSAVE',
|
|
204
|
+
e.start,
|
|
205
|
+
`request.then: ${el.value === '' ? '(块形式)' : el.value} 已删除(页面不写顺序编排)`,
|
|
206
|
+
[
|
|
207
|
+
'写操作 request 成功后宿主固定重取主对象与附带对象,页面不再声明 then。要追加提示 / 跳转 / 只重取某对象,写在展示对象里:',
|
|
208
|
+
" onMount(view, ctx) {",
|
|
209
|
+
" ctx.onRequestDone('<request.into 名>', async (done) => {",
|
|
210
|
+
' if (!done.ok) return;',
|
|
211
|
+
" await ctx.reload(['<对象>']); // 或 ctx.action('具名动作', { message: done.message }) 发提示",
|
|
212
|
+
' });',
|
|
213
|
+
' }',
|
|
214
|
+
'只读请求(不要重取)声明 read: true;失败也要重取的(如服务端状态已改)在 onRequestDone 里自己 ctx.reload。',
|
|
215
|
+
].join('\n'),
|
|
216
|
+
{ kind: 'then', ...(intoNameOf(c, l) !== undefined ? { into: intoNameOf(c, l)! } : {}) },
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
} else if (e.key === 'prompt') {
|
|
220
|
+
c.covered.add(e.start);
|
|
221
|
+
const aid = actionIdOfRequest(c.ys, l);
|
|
222
|
+
finding(
|
|
223
|
+
c,
|
|
224
|
+
'MANUAL-REQ-LEGACY',
|
|
225
|
+
e.start,
|
|
226
|
+
'request.prompt(动作自带输入对话框)已删除,由展示对象方法用 ctx.prompt 问',
|
|
227
|
+
[
|
|
228
|
+
`1) 动作改为 submit: view.ask${pascal(aid ?? 'Action')}(动作上去掉 request),另加一个不渲染成按钮的 request 动作(不写 on)接住请求;`,
|
|
229
|
+
'2) 展示对象方法:',
|
|
230
|
+
` async ask${pascal(aid ?? 'Action')}(view, payload: { row?: Record<string, unknown> }, ctx) {`,
|
|
231
|
+
' const answers = await ctx.prompt({ title: \'…\', submitLabel: \'…\', fields: [{ name: \'字段\', label: \'…\', type: \'text\', required: true }] });',
|
|
232
|
+
' if (answers === null) return; // 取消 = 不发请求',
|
|
233
|
+
` ctx.request('<对象>', '${aid ?? '动作id'}Run', { row: payload.row, ...answers });`,
|
|
234
|
+
' }',
|
|
235
|
+
'3) 请求动作里 bodyMap: { 字段: 字段 } 取 answers 的同名键。',
|
|
236
|
+
].join('\n'),
|
|
237
|
+
{ kind: 'prompt', ...(aid !== undefined ? { action: aid } : {}) },
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const intoNameOf = (c: Ctx, head: YLine): string | undefined => {
|
|
245
|
+
const range = childRange(c.ys, head.i);
|
|
246
|
+
if (range === undefined) return undefined;
|
|
247
|
+
const into = requestEntries(c.ys, range).find((e) => e.key === 'into');
|
|
248
|
+
if (into === undefined) return undefined;
|
|
249
|
+
const v = into.line.value;
|
|
250
|
+
if (v.startsWith('{')) return wholeFlowMap(v)?.find((x) => x.key === 'name')?.value;
|
|
251
|
+
return v === '' ? undefined : unquote(v);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
function actionIdOfRequest(ys: readonly YLine[], head: YLine): string | undefined {
|
|
255
|
+
const same = /\bid:\s*([A-Za-z_][\w-]*)/.exec(head.text);
|
|
256
|
+
if (same !== null) return same[1];
|
|
257
|
+
for (let k = head.i - 1; k >= 0 && k > head.i - 40; k -= 1) {
|
|
258
|
+
const l = ys[k]!;
|
|
259
|
+
if (!l.blank && l.key === 'id' && l.keyCol === head.keyCol) return unquote(l.value);
|
|
260
|
+
}
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export const pascal = (s: string): string => s.replace(/(^|[-_\s])([a-zA-Z0-9])/g, (_m, _p, ch: string) => ch.toUpperCase());
|
|
265
|
+
|
|
266
|
+
function ruleRequestOk(c: Ctx, e: ReqEntry, _entries: readonly ReqEntry[]): void {
|
|
267
|
+
const el = e.line;
|
|
268
|
+
const map = el.value.startsWith('{') ? wholeFlowMap(el.value) : undefined;
|
|
269
|
+
const obj: Record<string, string> = {};
|
|
270
|
+
for (const x of map ?? []) obj[x.key] = unquote(x.value);
|
|
271
|
+
const keysOk = map !== undefined && Object.keys(obj).every((k) => k === 'path' || k === 'equals' || k === 'message');
|
|
272
|
+
const env = c.env;
|
|
273
|
+
const covered =
|
|
274
|
+
keysOk &&
|
|
275
|
+
env?.failField !== undefined &&
|
|
276
|
+
obj.path === env.failField &&
|
|
277
|
+
(obj.equals === undefined || obj.equals === 'true') &&
|
|
278
|
+
(obj.message === undefined || obj.message === env.messagePath);
|
|
279
|
+
if (covered) {
|
|
280
|
+
c.edits.push({ from: e.start, to: e.end, replacement: [] });
|
|
281
|
+
change(c, 'AUTO-REQ-OK', e.start, `删除 request.ok(应用信封 failWhen ${env!.failField}=false 与 message 已覆盖)`, el.text);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
c.covered.add(e.start);
|
|
285
|
+
const p = obj.path ?? '<路径>';
|
|
286
|
+
finding(
|
|
287
|
+
c,
|
|
288
|
+
'MANUAL-REQ-LEGACY',
|
|
289
|
+
e.start,
|
|
290
|
+
`request.ok 判定「${summary(el.value)}」不被应用信封覆盖(${env?.failField === undefined ? 'kit.app.yaml 没有 failWhen = { field, op: eq, value: false } 形状的信封' : `信封只判 ${env.failField}=false`})`,
|
|
291
|
+
[
|
|
292
|
+
'request.ok 已删除,成败只读信封。两种改法选一:',
|
|
293
|
+
` a) 让接口把业务失败也回成信封失败(推荐):服务里 ${p} 为假时回 { success: false, message },页面什么都不写;`,
|
|
294
|
+
` b) 业务结论留在 ${p}(接口 HTTP 与信封都成功):yaml 里写 read: true,展示对象按结论自己提示:`,
|
|
295
|
+
" ctx.onRequestDone('<into 名>', (done) => {",
|
|
296
|
+
` if (!(done.data as { ${p.replace(/^data\./, '')}?: boolean } | undefined)?.${p.replace(/^data\./, '')}) void ctx.action('<发提示的具名动作>', { message: done.message, tone: 'warning' });`,
|
|
297
|
+
' });',
|
|
298
|
+
].join('\n'),
|
|
299
|
+
{ kind: 'ok', path: p },
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function ruleRequestBody(c: Ctx, e: ReqEntry, pad: string, conflict: boolean): void {
|
|
304
|
+
const el = e.line;
|
|
305
|
+
let pairs: BodyPair[] | undefined;
|
|
306
|
+
if (el.value.startsWith('{')) {
|
|
307
|
+
const m = wholeFlowMap(el.value);
|
|
308
|
+
if (m !== undefined) pairs = m.map((x): BodyPair => [x.key, x.value]);
|
|
309
|
+
} else if (el.value === '') {
|
|
310
|
+
const range = childRange(c.ys, el.i);
|
|
311
|
+
if (range !== undefined) {
|
|
312
|
+
const kids = c.ys.slice(range.start, range.end);
|
|
313
|
+
const col = kids[0]!.keyCol;
|
|
314
|
+
const simple = kids.every((k) => !k.blank && !k.cont && k.key !== undefined && k.keyCol === col && k.value !== '' && !k.value.startsWith('{') && !k.value.startsWith('['));
|
|
315
|
+
if (simple) pairs = kids.map((k): BodyPair => [k.key!, k.value]);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const lines = Array.from({ length: e.end - e.start }, (_v, n) => e.start + n);
|
|
319
|
+
if (pairs === undefined || conflict) {
|
|
320
|
+
for (const n of lines) c.covered.add(n);
|
|
321
|
+
finding(
|
|
322
|
+
c,
|
|
323
|
+
'MANUAL-REQ-LEGACY',
|
|
324
|
+
e.start,
|
|
325
|
+
conflict ? 'request 里已有 pick / bodyMap,同时还留着 body,需要手工合并' : 'request.body 不是单行 / 平铺的键值写法,无法机械翻译',
|
|
326
|
+
'把 body 里的键值拆成 pick: [同名字段] 与 bodyMap: { 键: 载荷字段 }(见「request.body 旧写法」对照表)。',
|
|
327
|
+
);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const plan = planBody(pairs);
|
|
331
|
+
if ('bad' in plan) {
|
|
332
|
+
for (const n of lines) c.covered.add(n);
|
|
333
|
+
finding(c, 'MANUAL-REQ-LEGACY', e.start, `request.body 含无法机械翻译的取值(${plan.bad.map(([k]) => k).join(' / ')})`, bodyRecipe(plan.bad), { kind: 'body', fields: plan.bad.map(([k]) => k).join(',') });
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const out: string[] = [];
|
|
337
|
+
const tail = el.value.startsWith('{') && el.comment !== undefined ? ` ${el.comment}` : '';
|
|
338
|
+
if (plan.pick.length > 0) out.push(`${pad}pick: [${plan.pick.join(', ')}]${tail}`);
|
|
339
|
+
if (plan.bodyMap.length > 0) out.push(`${pad}bodyMap: { ${plan.bodyMap.map(([k, v]) => `${k}: ${v}`).join(', ')} }${plan.pick.length === 0 ? tail : ''}`);
|
|
340
|
+
if (out.length === 0) return;
|
|
341
|
+
c.edits.push({ from: e.start, to: e.end, replacement: out });
|
|
342
|
+
change(c, 'AUTO-REQ-BODY', e.start, 'request.body 的 $ 取值改为 pick / bodyMap', c.lines.slice(e.start, e.end).join(' '), out.join(' '));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// ---------------------------------------------------------------- 规则 7:浮层事件 { action, then: saved }
|
|
346
|
+
function ruleOverlayEvents(c: Ctx): void {
|
|
347
|
+
for (const l of c.ys) {
|
|
348
|
+
if (l.cont || l.key === undefined) continue;
|
|
349
|
+
const inEvents = l.path[l.path.length - 1] === 'events';
|
|
350
|
+
if (inEvents && l.value.startsWith('{')) {
|
|
351
|
+
const open = restStart(l);
|
|
352
|
+
const close = findClose(l.text, open);
|
|
353
|
+
if (close < 0) continue;
|
|
354
|
+
const entries = flowEntries(l.text, open, close);
|
|
355
|
+
if (!entries.some((e) => e.key === 'action')) continue;
|
|
356
|
+
const k = entries.findIndex((e) => e.key === 'then');
|
|
357
|
+
if (k < 0) continue;
|
|
358
|
+
if (unquote(entries[k]!.value) === 'saved') {
|
|
359
|
+
const next = removeFlowEntry(l.text, open, close, k);
|
|
360
|
+
c.edits.push({ from: l.i, to: l.i + 1, replacement: [next] });
|
|
361
|
+
change(c, 'AUTO-EVENT-THEN', l.i, '浮层事件 { action, then: saved }:请求成功后宿主固定关窗并刷新,去掉 then', l.text, next);
|
|
362
|
+
} else {
|
|
363
|
+
c.covered.add(l.i);
|
|
364
|
+
finding(c, 'MANUAL-OVERLAY-EVENT', l.i, `浮层事件的 then: ${entries[k]!.value} 已删除(events 对象形态只有 { action })`, '关窗 / 提示 / 重取放进具名动作处理函数(ctx.notify / ctx.reload / ctx.close)或展示对象 ctx.onRequestDone。');
|
|
365
|
+
}
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
if (l.key === 'then' && l.path.length >= 2 && l.path[l.path.length - 2] === 'events') {
|
|
369
|
+
if (l.value === 'saved') {
|
|
370
|
+
c.edits.push({ from: l.i, to: l.i + 1, replacement: [] });
|
|
371
|
+
change(c, 'AUTO-EVENT-THEN', l.i, '浮层事件的 then: saved 去掉(请求成功后宿主固定关窗并刷新)', l.text);
|
|
372
|
+
} else {
|
|
373
|
+
c.covered.add(l.i);
|
|
374
|
+
finding(c, 'MANUAL-OVERLAY-EVENT', l.i, `浮层事件的 then: ${l.value} 已删除`, '关窗 / 提示 / 重取放进具名动作处理函数或展示对象 ctx.onRequestDone。');
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// ---------------------------------------------------------------- 规则 8:主题九维
|
|
381
|
+
function ruleTheme(c: Ctx): void {
|
|
382
|
+
for (const l of c.ys) {
|
|
383
|
+
if (l.cont || l.key !== 'theme') continue;
|
|
384
|
+
if (l.value.startsWith('{')) {
|
|
385
|
+
if ([...LEGACY_PALETTE_KEYS, ...LEGACY_FONT_KEYS].some((k) => new RegExp(`\\b${k}\\s*:`).test(l.value))) {
|
|
386
|
+
c.covered.add(l.i);
|
|
387
|
+
finding(c, 'MANUAL-THEME', l.i, 'theme 写成了单行 flow 且含旧主题键,不做机械改写', '改成块形式后再运行 migrate,或直接按九维写:theme: { palette: CLASSIC_TECH_BLUE, font_family: SYSTEM_SANS, mode: light }');
|
|
388
|
+
}
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (l.value !== '') continue;
|
|
392
|
+
const range = childRange(c.ys, l.i);
|
|
393
|
+
if (range === undefined) continue;
|
|
394
|
+
const col = c.ys[range.start]!.keyCol;
|
|
395
|
+
const kids = c.ys.slice(range.start, range.end).filter((k) => !k.cont && !k.blank && k.key !== undefined && k.keyCol === col);
|
|
396
|
+
const named = (names: readonly string[]): YLine | undefined => kids.find((k) => names.includes(k.key!));
|
|
397
|
+
const pal = named(LEGACY_PALETTE_KEYS);
|
|
398
|
+
const font = named(LEGACY_FONT_KEYS);
|
|
399
|
+
const color = named(LEGACY_COLOR_KEYS);
|
|
400
|
+
if (pal === undefined && font === undefined && color === undefined) continue;
|
|
401
|
+
const hasPalette = kids.some((k) => k.key === 'palette');
|
|
402
|
+
const hasFamily = kids.some((k) => k.key === 'font_family');
|
|
403
|
+
const pad = ' '.repeat(col);
|
|
404
|
+
const fresh: string[] = [];
|
|
405
|
+
const notes: string[] = [];
|
|
406
|
+
if (!hasPalette && (pal !== undefined || color !== undefined)) {
|
|
407
|
+
const map = mapPaletteScheme(pal === undefined ? undefined : unquote(pal.value));
|
|
408
|
+
fresh.push(`${pad}palette: ${map.palette} # 迁移自 ${pal !== undefined ? `${pal.key}: ${unquote(pal.value)}` : 'color(品牌色号已删除)'},请核对配色`);
|
|
409
|
+
if (map.quality === 'default') {
|
|
410
|
+
finding(c, 'MANUAL-THEME', (pal ?? color!).i, `旧配色 ${pal === undefined ? '(只有品牌色 color)' : unquote(pal.value)} 没有已知的对应九维 palette,回落 ${DEFAULT_PALETTE}`, `TODO:在 24 套九维 palette 里选最接近的(见外部指南 §3.2 或 soma-design 的 kit-nine-dim.json#palettes),再用 color_depth / color_saturation 调深浅与饱和度。`);
|
|
411
|
+
} else {
|
|
412
|
+
finding(c, 'MANUAL-THEME', pal!.i, `旧配色 ${unquote(pal!.value)} 映射为 ${map.palette}(最近似,不保证逐像素一致${map.dark ? ';这是暗色板,确认 mode' : ''})`, '打开页面核对主色、页底与文字;不满意就换一套九维 palette。');
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
if (!hasFamily && font !== undefined) {
|
|
416
|
+
const map = mapFontScheme(unquote(font.value));
|
|
417
|
+
fresh.push(`${pad}font_family: ${map.family} # 迁移自 ${font.key}: ${unquote(font.value)}`);
|
|
418
|
+
if (map.quality === 'default') finding(c, 'MANUAL-THEME', font.i, `旧字体方案 ${unquote(font.value)} 没有对应的九维 font_family,回落 ${DEFAULT_FONT_FAMILY}`, 'TODO:在 SYSTEM_SANS / GEOMETRIC_ROUNDED / INDUSTRIAL_REPORT / EDITORIAL_SERIF / GEEK_MONO / BOLD_DISPLAY 里选。');
|
|
419
|
+
}
|
|
420
|
+
if (color !== undefined) notes.push(`品牌色号 color: ${unquote(color.value)} 已删除,色相由 palette 决定`);
|
|
421
|
+
const legacy = [pal, font, color].filter((x): x is YLine => x !== undefined).sort((a, b) => a.i - b.i);
|
|
422
|
+
legacy.forEach((k, n) => {
|
|
423
|
+
const end = k.i + 1;
|
|
424
|
+
c.edits.push({ from: k.i, to: end, replacement: n === 0 ? fresh : [] });
|
|
425
|
+
});
|
|
426
|
+
change(c, 'AUTO-THEME', legacy[0]!.i, `旧主题键改为九维主题:${legacy.map((k) => k.key).join(' / ')} -> ${fresh.length > 0 ? fresh.map((x) => /^[^:\s]+/.exec(x.trim())?.[0] ?? '').join(' / ') : '(删除)'}${notes.length > 0 ? `;${notes.join(';')}` : ''}`, legacy.map((k) => k.text).join(' | '), fresh.join(' | '));
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// ---------------------------------------------------------------- 规则 9:带参词条的行数据旧拼写(J3)
|
|
431
|
+
/** 带引号的 `@row.字段`(YAML 里 `@` 不能开头一个裸标量,旧拼写必带引号) */
|
|
432
|
+
const ROW_ARG_QUOTED = /(["'])@row\.([A-Za-z_][A-Za-z0-9_]*)\1/g;
|
|
433
|
+
|
|
434
|
+
function ruleTextRowArg(c: Ctx): void {
|
|
435
|
+
const taken = new Set<number>();
|
|
436
|
+
for (const e of c.edits) for (let n = e.from; n < e.to; n += 1) taken.add(n);
|
|
437
|
+
for (const l of c.ys) {
|
|
438
|
+
if (l.blank || taken.has(l.i) || l.text.trimStart().startsWith('#')) continue;
|
|
439
|
+
if (!l.text.includes('@row.')) continue;
|
|
440
|
+
const next = l.text.replace(ROW_ARG_QUOTED, (_m, _q: string, field: string) => `"{${field}}"`);
|
|
441
|
+
if (next === l.text) continue;
|
|
442
|
+
c.edits.push({ from: l.i, to: l.i + 1, replacement: [next] });
|
|
443
|
+
change(c, 'AUTO-TEXT-ROW-ARG', l.i, '带参词条 args 的 `@row.字段` 旧拼写改写为 `{字段}`(与确认文案占位同一约定,KIT-LOCALE-002)', l.text, next);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/** 一遍收集全部 YAML 自动改写编辑,并应用;kind = 页面源或应用清单 */
|
|
448
|
+
export function rewriteYaml(text: string, file: string, kind: 'page' | 'app', env: EnvelopeInfo | undefined): YamlPass {
|
|
449
|
+
const { lines, eol } = splitLines(text);
|
|
450
|
+
const ys = analyzeYaml(lines);
|
|
451
|
+
const c: Ctx = { file, lines, ys, env, edits: [], changes: [], findings: [], covered: new Set() };
|
|
452
|
+
ruleTheme(c);
|
|
453
|
+
if (kind === 'page') {
|
|
454
|
+
ruleEyebrow(c);
|
|
455
|
+
ruleDensity(c);
|
|
456
|
+
ruleRequests(c);
|
|
457
|
+
ruleOverlayEvents(c);
|
|
458
|
+
ruleTextRowArg(c);
|
|
459
|
+
}
|
|
460
|
+
for (const e of c.edits) for (let n = e.from; n < e.to; n += 1) c.covered.add(n);
|
|
461
|
+
const next = c.edits.length === 0 ? text : applyLineEdits(lines, c.edits).join(eol);
|
|
462
|
+
c.changes.sort((a, b) => a.line - b.line);
|
|
463
|
+
c.findings.sort((a, b) => a.line - b.line);
|
|
464
|
+
return { text: next, changes: c.changes, findings: c.findings, covered: c.covered };
|
|
465
|
+
}
|