soma-kit 0.1.14 → 0.1.15
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 +3 -3
- package/packs/finance/reconcile-desk/compile.ts +1 -1
- package/packs/finance/reconcile-desk/shell.ts +1 -1
- package/spec/generated/kit-app.schema.json +4 -2
- package/spec/generated/kit-page.schema.json +72 -2
- package/spec/kit-grammar.json +163 -57
- package/spec/kit-grammar.schema.json +0 -24
- package/src/app/app-config.ts +1 -1
- package/src/app/component-gate.ts +2 -2
- package/src/app/compose-apps.ts +5 -2
- package/src/app/define-kit-actions.ts +82 -10
- package/src/app/define-kit-app.ts +6 -5
- package/src/app/define-kit-view.ts +1 -1
- package/src/app/index.ts +7 -7
- package/src/app/kit-view-context.ts +11 -2
- package/src/app/theme-endpoint.ts +1 -1
- package/src/app/theme-runtime.ts +7 -2
- package/src/base/alert.ts +23 -20
- package/src/base/anchored-layer.ts +1 -1
- package/src/base/button.ts +30 -15
- package/src/base/cascader.ts +8 -4
- package/src/base/check-core.ts +9 -6
- package/src/base/color-picker.ts +10 -6
- package/src/base/command-palette.ts +10 -4
- package/src/base/context-menu.ts +5 -2
- package/src/base/date-range.ts +9 -6
- package/src/base/date.ts +10 -6
- package/src/base/delta.ts +4 -2
- package/src/base/divider.ts +15 -66
- package/src/base/fab.ts +11 -6
- package/src/base/gap-value.ts +1 -1
- package/src/base/hint-tips.ts +1 -1
- package/src/base/index.ts +15 -4
- package/src/base/inline-error.ts +84 -0
- package/src/base/input.ts +54 -18
- package/src/base/kbd.ts +4 -3
- package/src/base/link.ts +1 -1
- package/src/base/listbox-core.ts +70 -22
- package/src/base/mentions.ts +6 -3
- package/src/base/menu-button.ts +63 -27
- package/src/base/menu-core.ts +9 -2
- package/src/base/motion/hover-3d.ts +4 -1
- package/src/base/motion/hover-gallery.ts +4 -1
- package/src/base/otp.ts +7 -3
- package/src/base/overlay-runtime.ts +3 -2
- package/src/base/overlay-shell.ts +141 -0
- package/src/base/popover.ts +2 -2
- package/src/base/popup.ts +47 -41
- package/src/base/qty-stepper.ts +14 -9
- package/src/base/reason-tip.ts +2 -2
- package/src/{frames → base}/resize-handle.ts +1 -1
- package/src/base/segmented.ts +35 -36
- package/src/base/select.ts +1 -0
- package/src/base/shared.ts +43 -7
- package/src/base/status-tone.ts +1 -1
- package/src/base/tag-input.ts +13 -8
- package/src/base/tag.ts +53 -59
- package/src/base/text.ts +37 -13
- package/src/base/textarea.ts +1 -1
- package/src/base/time-picker.ts +9 -5
- package/src/base/tree-select.ts +12 -9
- package/src/base/upload.ts +21 -13
- package/src/biz/approval-desk/compile.ts +28 -1
- package/src/biz/approval-desk/shell.ts +2 -2
- package/src/biz/auth-panel/compile.ts +1 -1
- package/src/biz/auth-panel/shell.ts +2 -2
- package/src/biz/category-crud/compile.ts +17 -4
- package/src/biz/category-crud/shell.ts +7 -5
- package/src/biz/checkout-page/compile.ts +1 -1
- package/src/biz/checkout-page/shell.ts +7 -6
- package/src/biz/compose.ts +3 -3
- package/src/biz/define.ts +1 -1
- package/src/biz/import-wizard/compile.ts +1 -1
- package/src/biz/import-wizard/shell.ts +6 -4
- package/src/biz/index.ts +4 -3
- package/src/biz/landing-page/compile.ts +1 -1
- package/src/biz/landing-page/shell.ts +5 -4
- package/src/biz/link/shared.ts +8 -1
- package/src/biz/master-sub/compile.ts +162 -19
- package/src/biz/master-sub/detail-head.ts +7 -6
- package/src/biz/master-sub/index.ts +3 -3
- package/src/biz/master-sub/shell.ts +90 -53
- package/src/biz/multi-board/compile.ts +3 -3
- package/src/biz/multi-board/index.ts +24 -9
- package/src/biz/multi-board/prose-fold.ts +2 -2
- package/src/biz/multi-board/shell.ts +17 -13
- package/src/biz/names.ts +1 -0
- package/src/biz/notification-center/compile.ts +9 -2
- package/src/biz/notification-center/shell.ts +9 -2
- package/src/biz/page-templates/domain-templates.ts +6 -2
- package/src/biz/page-templates/result-page/compile.ts +1 -1
- package/src/biz/page-templates/result-page/shell.ts +4 -3
- package/src/biz/page-templates/shared.ts +1 -1
- package/src/biz/page-templates/sign-in-page/compile.ts +1 -1
- package/src/biz/page-templates/sign-in-page/shell.ts +4 -4
- package/src/biz/record-detail/compile.ts +5 -2
- package/src/biz/record-detail/shell.ts +4 -4
- package/src/biz/settings-center/compile.ts +1 -1
- package/src/biz/settings-center/shell.ts +8 -5
- package/src/biz/shared/action-host.ts +12 -5
- package/src/biz/shared/compile-helpers.ts +4 -4
- package/src/biz/shared/coordinator.ts +104 -21
- package/src/biz/shared/overlay-compile.ts +48 -18
- package/src/biz/shared/overlay-shell.ts +63 -112
- package/src/biz/single-form/compile.ts +2 -2
- package/src/biz/single-form/shell.ts +8 -4
- package/src/biz/standard-crud/compile.ts +11 -4
- package/src/biz/standard-crud/shell.ts +26 -9
- package/src/biz/standard-crud/summary.ts +3 -1
- package/src/biz/step-form/compile.ts +1 -1
- package/src/biz/step-form/hub.ts +4 -0
- package/src/biz/step-form/shell.ts +6 -4
- package/src/biz/types.ts +11 -4
- package/src/cli/app-layer-check.ts +375 -0
- package/src/cli/kit-cli.ts +35 -8
- package/src/cli/kit-init.ts +149 -0
- package/src/compile/access-gate-attach.ts +1 -1
- package/src/compile/action-host-attach.ts +1 -1
- package/src/compile/compile-page.ts +29 -234
- package/src/compile/component-candidates.ts +2 -1
- package/src/compile/hints.ts +5 -58
- package/src/compile/index.ts +2 -2
- package/src/compile/layout-lint/index.ts +4 -1
- package/src/compile/layout-lint/rules-composition.ts +43 -13
- package/src/compile/page-composition.ts +33 -31
- package/src/compile/redirect.ts +1 -1
- package/src/compile/stages.ts +169 -0
- package/src/compile/styles.ts +70 -32
- package/src/compile/types.ts +2 -2
- package/src/data/amount-breakdown.ts +4 -2
- package/src/data/anchor-nav.ts +4 -1
- package/src/data/approval-flow.ts +9 -4
- package/src/data/assignment-picker.ts +28 -18
- package/src/data/async-result-panel.ts +6 -2
- package/src/data/breadcrumbs.ts +13 -9
- package/src/data/calendar.ts +4 -3
- package/src/data/carousel.ts +11 -5
- package/src/data/chart.ts +153 -23
- package/src/data/checklist.ts +5 -4
- package/src/data/code-view.ts +220 -26
- package/src/data/comment-thread.ts +7 -2
- package/src/data/confirm-dialog.ts +56 -13
- package/src/data/diff.ts +4 -1
- package/src/data/dock.ts +5 -1
- package/src/data/embed.ts +1 -1
- package/src/data/engine-ports.ts +126 -0
- package/src/data/field-mapper.ts +12 -6
- package/src/data/flow-editor.ts +105 -29
- package/src/data/footer.ts +6 -2
- package/src/data/gantt.ts +11 -8
- package/src/data/hero.ts +6 -2
- package/src/data/image-viewer.ts +7 -3
- package/src/data/index.ts +12 -5
- package/src/data/item-list.ts +6 -5
- package/src/data/json-view.ts +844 -0
- package/src/data/kanban.ts +11 -8
- package/src/data/markdown-view.ts +487 -0
- package/src/data/matrix.ts +23 -14
- package/src/data/media-grid.ts +5 -2
- package/src/data/mega-menu.ts +4 -3
- package/src/data/menu-dom.ts +9 -8
- package/src/data/menu.ts +15 -9
- package/src/data/mockup.ts +9 -5
- package/src/data/modal-dialog.ts +39 -88
- package/src/data/navbar.ts +11 -7
- package/src/data/notice-list.ts +1 -1
- package/src/data/notify-renderer.ts +21 -10
- package/src/data/object-form.ts +129 -48
- package/src/data/pager.ts +12 -8
- package/src/data/panel-head.ts +1 -1
- package/src/data/permission-matrix.ts +15 -8
- package/src/data/permission-tree.ts +24 -11
- package/src/data/pricing-table.ts +8 -3
- package/src/data/reaction-bar.ts +6 -3
- package/src/data/record-card.ts +13 -9
- package/src/data/record-picker.ts +8 -4
- package/src/data/redirect.ts +1 -1
- package/src/data/request-console.ts +20 -7
- package/src/data/resident.ts +0 -12
- package/src/data/result-panel.ts +2 -2
- package/src/data/rich-text.ts +58 -96
- package/src/data/row-editor.ts +10 -5
- package/src/data/rule-builder.ts +14 -8
- package/src/data/shape-util.ts +14 -3
- package/src/data/stat-group.ts +63 -22
- package/src/data/static-lazy.ts +3 -0
- package/src/data/static-registry.ts +8 -2
- package/src/data/steps.ts +6 -2
- package/src/data/survey.ts +9 -3
- package/src/data/system-switcher.ts +15 -6
- package/src/data/text-diff.ts +663 -0
- package/src/data/timeline.ts +1 -1
- package/src/data/tour-guide.ts +6 -3
- package/src/data/transfer.ts +19 -10
- package/src/data/tree-table.ts +77 -12
- package/src/data/tree.ts +5 -2
- package/src/data/virtual-rows.ts +17 -7
- package/src/data/wrap.ts +2 -2
- package/src/frames/index.ts +3 -2
- package/src/frames/inherited-shell.ts +178 -0
- package/src/frames/list-summary.ts +59 -36
- package/src/frames/page-bar.ts +4 -2
- package/src/frames/resident-components.ts +20 -0
- package/src/frames/shared.ts +18 -14
- package/src/frames/split-frame/shell.ts +17 -11
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +12 -6
- package/src/frames/types.ts +3 -2
- package/src/frames/workspace-frame/extras.ts +19 -5
- package/src/frames/workspace-frame/shell.ts +2 -1
- package/src/frames/workspace-frame/state.ts +8 -2
- package/src/frames/workspace-frame/view.ts +125 -76
- package/src/generated/kit-grammar-runtime.ts +61 -39
- package/src/i18n/kit-text.ts +114 -2
- package/src/i18n/resolve-text-refs.ts +1 -1
- package/src/object-renderer/action-group.ts +31 -1
- package/src/object-renderer/action-more.ts +28 -12
- package/src/object-renderer/arrange.ts +37 -7
- package/src/object-renderer/collection-parts.ts +38 -7
- package/src/object-renderer/collection-table.ts +68 -23
- package/src/object-renderer/collection.ts +63 -30
- package/src/object-renderer/compile-data.ts +1 -1
- package/src/object-renderer/defaults.ts +8 -0
- package/src/object-renderer/emit-events.ts +1 -1
- package/src/object-renderer/emit-object.ts +3 -0
- package/src/object-renderer/emit-static.ts +140 -37
- package/src/object-renderer/field-value.ts +12 -239
- package/src/object-renderer/filter-toolbar.ts +103 -0
- package/src/{compile → object-renderer}/fragment.ts +2 -2
- package/src/object-renderer/index.ts +1 -1
- package/src/object-renderer/layout-facts.ts +37 -5
- package/src/object-renderer/overlay-decide.ts +82 -0
- package/src/object-renderer/render-object.ts +1 -1
- package/src/object-renderer/table-actions.ts +70 -23
- package/src/object-renderer/table-tools.ts +12 -5
- package/src/object-renderer/types.ts +9 -15
- package/src/recipes/app-blocks.ts +66 -0
- package/src/recipes/code-view.ts +56 -0
- package/src/recipes/compact-group.ts +31 -0
- package/src/recipes/container.ts +25 -15
- package/src/recipes/control.ts +21 -3
- package/src/recipes/desc-list.ts +14 -0
- package/src/recipes/divider.ts +53 -0
- package/src/recipes/emphasis.ts +12 -8
- package/src/recipes/frame-bleed.ts +3 -3
- package/src/recipes/index.ts +11 -1
- package/src/recipes/inherited-shell.ts +37 -0
- package/src/recipes/json-view.ts +49 -0
- package/src/recipes/markdown.ts +86 -0
- package/src/recipes/overlay.ts +112 -26
- package/src/recipes/page-width.ts +20 -0
- package/src/recipes/placeholder.ts +1 -1
- package/src/recipes/stat-state.ts +1 -1
- package/src/recipes/state.ts +10 -8
- package/src/recipes/status.ts +13 -12
- package/src/recipes/strip.ts +72 -0
- package/src/recipes/surface.ts +10 -6
- package/src/recipes/table-gap.ts +1 -1
- package/src/recipes/table-native-edit.ts +4 -4
- package/src/recipes/table-row.ts +11 -8
- package/src/recipes/tabs.ts +108 -31
- package/src/recipes/text-diff.ts +90 -0
- package/src/recipes/title-row.ts +4 -2
- package/src/recipes/typography.ts +2 -2
- package/src/shared/diagnostics.ts +16 -0
- package/src/shared/envelope.ts +1 -1
- package/src/shared/field-value-format.ts +246 -0
- package/src/shared/focus-ring.ts +8 -0
- package/src/shared/hints.ts +56 -0
- package/src/{base → shared}/icons.ts +12 -0
- package/src/shared/kit-error.ts +1 -1
- package/src/{object-renderer → shared}/merge-class.ts +3 -2
- package/src/shared/path-guard.ts +1 -1
- package/src/shared/primitives-types.ts +8 -0
- package/src/shared/theme-runtime-shared.ts +19 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -14
- package/src/theme/kit-theme.tpl +38 -14
- package/src/theme/nine-dim-structure.ts +66 -41
- package/src/theme/surface-layers.ts +11 -3
- package/src/theme/theme-tokens.ts +5 -1
- package/src/app/envelope.ts +0 -1
- package/src/app/notify-renderer.ts +0 -1
- package/src/app/paged-list-adapter.ts +0 -1
- package/src/app/theme-runtime-shared.ts +0 -1
- package/src/compile/kit-error.ts +0 -1
- /package/src/{base → shared}/class-candidates.ts +0 -0
|
@@ -537,242 +537,15 @@ export function checkEnumOptionsAndEditCompatibility(
|
|
|
537
537
|
}
|
|
538
538
|
|
|
539
539
|
// ---------------------------------------------------------------- 字段值格式化与解析(money / percent / daterange)
|
|
540
|
-
|
|
541
|
-
export
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
export interface KitFieldValueFormatOptions {
|
|
553
|
-
type?: string;
|
|
554
|
-
kind?: string;
|
|
555
|
-
unit?: string;
|
|
556
|
-
currency?: string;
|
|
557
|
-
format?: string;
|
|
558
|
-
decimals?: number;
|
|
559
|
-
options?: ReadonlyArray<{ value?: unknown; label?: unknown; tone?: string }>;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
/**
|
|
563
|
-
* 解析 money 字段/列的币种符号:
|
|
564
|
-
* 优先取显式配置的 `unit`(如 `'$'`、`'€'`)或 `currency`(如 `'USD' -> '$'`、`'EUR' -> '€'`、`'GBP' -> '£'`、`'JPY' -> '¥'`、`'CNY' -> '¥'`)
|
|
565
|
-
* 或 `format: 'currency:USD'`;未指定时默认回退 `'¥'`。
|
|
566
|
-
*/
|
|
567
|
-
export function resolveCurrencySymbol(
|
|
568
|
-
opts?: { unit?: string; currency?: string; format?: string } | string,
|
|
569
|
-
): string {
|
|
570
|
-
if (typeof opts === 'string') {
|
|
571
|
-
const raw = opts.trim();
|
|
572
|
-
if (raw === '') return '¥';
|
|
573
|
-
const code = raw.startsWith('currency:') ? raw.slice('currency:'.length).trim() : raw;
|
|
574
|
-
if (code === '' || code === 'currency') return '¥';
|
|
575
|
-
return CURRENCY_SYMBOLS[code.toUpperCase()] ?? code;
|
|
576
|
-
}
|
|
577
|
-
if (isRec(opts)) {
|
|
578
|
-
if (typeof opts.unit === 'string' && opts.unit.trim() !== '') {
|
|
579
|
-
const u = opts.unit.trim();
|
|
580
|
-
return CURRENCY_SYMBOLS[u.toUpperCase()] ?? u;
|
|
581
|
-
}
|
|
582
|
-
if (typeof opts.currency === 'string' && opts.currency.trim() !== '') {
|
|
583
|
-
const c = opts.currency.trim();
|
|
584
|
-
return CURRENCY_SYMBOLS[c.toUpperCase()] ?? c;
|
|
585
|
-
}
|
|
586
|
-
if (typeof opts.format === 'string' && opts.format.trim() !== '') {
|
|
587
|
-
const f = opts.format.trim();
|
|
588
|
-
if (f.startsWith('currency:')) {
|
|
589
|
-
const fc = f.slice('currency:'.length).trim();
|
|
590
|
-
if (fc !== '') return CURRENCY_SYMBOLS[fc.toUpperCase()] ?? fc;
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
return '¥';
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
/**
|
|
598
|
-
* 格式化 money 值:使用字段/列配置的 `unit` 或 `currency` 对应币种符号,未指定时默认回退 `'¥'`。
|
|
599
|
-
*/
|
|
600
|
-
export function formatMoneyValue(
|
|
601
|
-
value: unknown,
|
|
602
|
-
opts?: { unit?: string; currency?: string; format?: string; decimals?: number } | string,
|
|
603
|
-
): string {
|
|
604
|
-
if (value === null || value === undefined || value === '') return '';
|
|
605
|
-
const symbol = resolveCurrencySymbol(opts);
|
|
606
|
-
const decimals = isRec(opts) && typeof opts.decimals === 'number' && Number.isInteger(opts.decimals) && opts.decimals >= 0
|
|
607
|
-
? opts.decimals
|
|
608
|
-
: undefined;
|
|
609
|
-
if (typeof value === 'number') {
|
|
610
|
-
if (!Number.isFinite(value)) return '';
|
|
611
|
-
const numStr = decimals !== undefined ? value.toFixed(decimals) : String(Number(value.toFixed(4)));
|
|
612
|
-
return value < 0 ? `-${symbol}${numStr.slice(1)}` : `${symbol}${numStr}`;
|
|
613
|
-
}
|
|
614
|
-
const strVal = String(value).trim();
|
|
615
|
-
if (strVal === '') return '';
|
|
616
|
-
const cleaned = strVal.replace(/,/g, '');
|
|
617
|
-
const n = Number(cleaned);
|
|
618
|
-
if (Number.isFinite(n)) {
|
|
619
|
-
const numStr = decimals !== undefined ? n.toFixed(decimals) : String(Number(n.toFixed(4)));
|
|
620
|
-
return n < 0 ? `-${symbol}${numStr.slice(1)}` : `${symbol}${numStr}`;
|
|
621
|
-
}
|
|
622
|
-
return strVal.startsWith(symbol) ? strVal : `${symbol}${strVal}`;
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
/**
|
|
626
|
-
* 格式化 percent 值:统一 `soma-kit` 内 `percent` 口径为 `0..100` 原值加 `'%'`(绝不把 0.5 或 1 自动乘 100)。
|
|
627
|
-
*/
|
|
628
|
-
export function formatPercentValue(
|
|
629
|
-
value: unknown,
|
|
630
|
-
opts?: { decimals?: number },
|
|
631
|
-
): string {
|
|
632
|
-
if (value === null || value === undefined || value === '') return '';
|
|
633
|
-
const decimals = isRec(opts) && typeof opts.decimals === 'number' && Number.isInteger(opts.decimals) && opts.decimals >= 0
|
|
634
|
-
? opts.decimals
|
|
635
|
-
: undefined;
|
|
636
|
-
if (typeof value === 'number') {
|
|
637
|
-
if (!Number.isFinite(value)) return '';
|
|
638
|
-
const numStr = decimals !== undefined ? value.toFixed(decimals) : String(Number(value.toFixed(4)));
|
|
639
|
-
return `${numStr}%`;
|
|
640
|
-
}
|
|
641
|
-
const strVal = String(value).trim();
|
|
642
|
-
if (strVal === '') return '';
|
|
643
|
-
if (strVal.endsWith('%')) return strVal;
|
|
644
|
-
const n = Number(strVal);
|
|
645
|
-
if (Number.isFinite(n)) {
|
|
646
|
-
const numStr = decimals !== undefined ? n.toFixed(decimals) : String(Number(n.toFixed(4)));
|
|
647
|
-
return `${numStr}%`;
|
|
648
|
-
}
|
|
649
|
-
return `${strVal}%`;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
function normalizeDateToken(raw: unknown): string {
|
|
653
|
-
if (raw === null || raw === undefined) return '';
|
|
654
|
-
if (raw instanceof Date) {
|
|
655
|
-
return Number.isNaN(raw.getTime()) ? '' : raw.toISOString().slice(0, 10);
|
|
656
|
-
}
|
|
657
|
-
if (typeof raw === 'number') {
|
|
658
|
-
if (!Number.isFinite(raw)) return '';
|
|
659
|
-
const d = new Date(raw);
|
|
660
|
-
return Number.isNaN(d.getTime()) ? String(raw) : d.toISOString().slice(0, 10);
|
|
661
|
-
}
|
|
662
|
-
if (typeof raw === 'string') {
|
|
663
|
-
const s = raw.trim();
|
|
664
|
-
if (/^\d{4}-\d{2}-\d{2}T/.test(s)) return s.slice(0, 10);
|
|
665
|
-
return s;
|
|
666
|
-
}
|
|
667
|
-
return '';
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
/**
|
|
671
|
-
* 解析 daterange 值:兼容 `['2026-01-01', '2026-01-31']` 数组、`{ start: '2026-01-01', end: '2026-01-31' }` 对象与
|
|
672
|
-
* `'2026-01-01 ~ 2026-01-31'` 字符串,返回 `[start, end]` 二元组;空值返回 `null`。
|
|
673
|
-
*/
|
|
674
|
-
export function parseDateRangeValue(value: unknown): [string, string] | null {
|
|
675
|
-
if (value === null || value === undefined || value === '') return null;
|
|
676
|
-
if (Array.isArray(value)) {
|
|
677
|
-
const start = normalizeDateToken(value[0]);
|
|
678
|
-
const end = normalizeDateToken(value[1]);
|
|
679
|
-
if (start === '' && end === '') return null;
|
|
680
|
-
return [start, end];
|
|
681
|
-
}
|
|
682
|
-
if (isRec(value)) {
|
|
683
|
-
const start = normalizeDateToken(value.start ?? value.from ?? value.begin ?? value.startDate);
|
|
684
|
-
const end = normalizeDateToken(value.end ?? value.to ?? value.endDate);
|
|
685
|
-
if (start === '' && end === '') return null;
|
|
686
|
-
return [start, end];
|
|
687
|
-
}
|
|
688
|
-
if (typeof value === 'string') {
|
|
689
|
-
const s = value.trim();
|
|
690
|
-
if (s === '') return null;
|
|
691
|
-
if (s.includes('~')) {
|
|
692
|
-
const [a, b] = s.split(/\s*~\s*/, 2);
|
|
693
|
-
return [normalizeDateToken(a), normalizeDateToken(b)];
|
|
694
|
-
}
|
|
695
|
-
const rangeMatch = /^(\d{4}-\d{2}-\d{2})\s*(?:至|to|,|\s+-\s+)\s*(\d{4}-\d{2}-\d{2})$/i.exec(s);
|
|
696
|
-
if (rangeMatch) {
|
|
697
|
-
return [rangeMatch[1]!, rangeMatch[2]!];
|
|
698
|
-
}
|
|
699
|
-
return [normalizeDateToken(s), ''];
|
|
700
|
-
}
|
|
701
|
-
return null;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
/**
|
|
705
|
-
* 格式化 daterange 值:兼容数组、对象与字符串输入,统一格式化为 `'YYYY-MM-DD ~ YYYY-MM-DD'`。
|
|
706
|
-
*/
|
|
707
|
-
export function formatDateRangeValue(value: unknown): string {
|
|
708
|
-
const parsed = parseDateRangeValue(value);
|
|
709
|
-
if (parsed === null) return '';
|
|
710
|
-
const [start, end] = parsed;
|
|
711
|
-
if (start !== '' && end !== '') return `${start} ~ ${end}`;
|
|
712
|
-
return start !== '' ? start : end;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
/**
|
|
716
|
-
* 统一格式化字段/单元格展示值:处理 `options` 枚举映射、`money`、`percent`、`daterange`。
|
|
717
|
-
*/
|
|
718
|
-
export function formatFieldValue(
|
|
719
|
-
value: unknown,
|
|
720
|
-
field?: KitFieldValueFormatOptions | string,
|
|
721
|
-
): string {
|
|
722
|
-
if (value === null || value === undefined || value === '') return '';
|
|
723
|
-
const opts: KitFieldValueFormatOptions = typeof field === 'string' ? { type: field, format: field } : (field ?? {});
|
|
724
|
-
if (Array.isArray(opts.options) && opts.options.length > 0) {
|
|
725
|
-
const hit = opts.options.find((o) => isRec(o) && (o.value === value || String(o.value) === String(value)));
|
|
726
|
-
if (hit !== undefined) {
|
|
727
|
-
return typeof hit.label === 'string' && hit.label !== '' ? hit.label : String(hit.value ?? value);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
const kind = (opts.type ?? opts.kind ?? '').trim();
|
|
731
|
-
const fmt = (opts.format ?? '').trim();
|
|
732
|
-
if (kind === 'money' || kind === 'currency' || fmt === 'currency' || fmt.startsWith('currency:')) {
|
|
733
|
-
return formatMoneyValue(value, opts);
|
|
734
|
-
}
|
|
735
|
-
if (kind === 'percent' || fmt === 'percent') {
|
|
736
|
-
return formatPercentValue(value, opts);
|
|
737
|
-
}
|
|
738
|
-
if (kind === 'daterange' || fmt === 'daterange') {
|
|
739
|
-
return formatDateRangeValue(value);
|
|
740
|
-
}
|
|
741
|
-
if (Array.isArray(value) && value.length === 2 && typeof value[0] === 'string' && /^\d{4}-\d{2}-\d{2}/.test(value[0])) {
|
|
742
|
-
return formatDateRangeValue(value);
|
|
743
|
-
}
|
|
744
|
-
if (isRec(value) && ('start' in value || 'end' in value || 'from' in value || 'to' in value)) {
|
|
745
|
-
return formatDateRangeValue(value);
|
|
746
|
-
}
|
|
747
|
-
return String(value);
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
/**
|
|
751
|
-
* 字段类型 / 显式 format -> 展示格式化标识:
|
|
752
|
-
* daterange -> "daterange",money -> "currency",percent -> "percent",date -> "date",datetime -> "datetime"。
|
|
753
|
-
*/
|
|
754
|
-
export function displayFormatOf(type?: string, explicitFormat?: string): string {
|
|
755
|
-
if (typeof explicitFormat === 'string' && explicitFormat.trim() !== '') {
|
|
756
|
-
return explicitFormat.trim();
|
|
757
|
-
}
|
|
758
|
-
const t = typeof type === 'string' ? type.trim() : '';
|
|
759
|
-
switch (t) {
|
|
760
|
-
case 'daterange':
|
|
761
|
-
return 'daterange';
|
|
762
|
-
case 'money':
|
|
763
|
-
case 'currency':
|
|
764
|
-
return 'currency';
|
|
765
|
-
case 'percent':
|
|
766
|
-
return 'percent';
|
|
767
|
-
case 'date':
|
|
768
|
-
return 'date';
|
|
769
|
-
case 'datetime':
|
|
770
|
-
return 'datetime';
|
|
771
|
-
case 'int':
|
|
772
|
-
case 'decimal':
|
|
773
|
-
case 'number':
|
|
774
|
-
return 'number';
|
|
775
|
-
default:
|
|
776
|
-
return 'text';
|
|
777
|
-
}
|
|
778
|
-
}
|
|
540
|
+
// 已下沉至 shared/field-value-format.ts,原路径重导出以保持兼容。
|
|
541
|
+
export {
|
|
542
|
+
CURRENCY_SYMBOLS,
|
|
543
|
+
resolveCurrencySymbol,
|
|
544
|
+
formatMoneyValue,
|
|
545
|
+
formatPercentValue,
|
|
546
|
+
parseDateRangeValue,
|
|
547
|
+
formatDateRangeValue,
|
|
548
|
+
formatFieldValue,
|
|
549
|
+
displayFormatOf,
|
|
550
|
+
type KitFieldValueFormatOptions,
|
|
551
|
+
} from '../shared/field-value-format';
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// 筛选工具条形体(风格档案 SPACE_MATERIAL):简单筛选(至多 3 个字段,只有文字输入 / 静态选项枚举)不再画成「带上方标签的输入框 + 下拉」,而是一条工具条:
|
|
2
|
+
// · 文字输入 = 搜索框:凹槽底(Input variant filled)、前置放大镜、无上方标签(字段名进占位与可访问名),宽 = sizeSpec.field.searchWidthPx;
|
|
3
|
+
// · 静态选项枚举:选项少且短(foundation arrangeChoicePresentation,阈值 kit-limits#choiceForm)= 分段控件(Radio segmented,首段「全部」= 不筛选,
|
|
4
|
+
// 选中块浮起,计数由列表响应 facets 给,没有就不显示);选项多或宽 = 下拉(无上方标签,占位「全部」,宽取宽度阶梯)。
|
|
5
|
+
// 其它形态(日期 / 数字 / 远程选项 / 超过 3 个字段 / 分隔线)不进工具条,照旧走排布引擎的筛选栏。纯函数,编译期调用,运行时不测量。
|
|
6
|
+
|
|
7
|
+
import { KIT_FIELD_SEARCH_WIDTH_CLASS, KIT_FIELD_SELECT_WIDTH_CLASS } from '../recipes/strip';
|
|
8
|
+
import { textWidthEm } from 'soma-foundation/arrange';
|
|
9
|
+
import { arrangeChoicePresentation } from 'soma-foundation/arrange/table';
|
|
10
|
+
import { kitText } from '../i18n/kit-text';
|
|
11
|
+
import type { KitCell } from './types';
|
|
12
|
+
|
|
13
|
+
/** 工具条最多容纳的字段数(搜索 + 分段 + 一个下拉) */
|
|
14
|
+
export const KIT_FILTER_TOOLBAR_MAX_FIELDS = 3;
|
|
15
|
+
|
|
16
|
+
// 控件宽是理想宽(可收缩):宽容器里就是 320 / 240,窄容器(主从页左窗格头)里按比例收缩而不换行
|
|
17
|
+
const SEARCH_CELL = `${KIT_FIELD_SEARCH_WIDTH_CLASS} min-w-0`;
|
|
18
|
+
const SELECT_CELL = `${KIT_FIELD_SELECT_WIDTH_CLASS} min-w-0`;
|
|
19
|
+
const SEGMENT_CELL = 'shrink-0';
|
|
20
|
+
/** 工具条容器:单行垂直居中、不换行;搜索 / 分段 / 下拉之间的间距取间距阶梯 12 */
|
|
21
|
+
export const KIT_FILTER_TOOLBAR_WRAP = 'flex items-center gap-3';
|
|
22
|
+
/** 工具条里的动作区(即时档的「清除」/ 提交档的查询重置):贴在最后一个控件后 */
|
|
23
|
+
export const KIT_FILTER_TOOLBAR_ACTIONS = 'flex items-center gap-2';
|
|
24
|
+
|
|
25
|
+
/** 宿主元素上的标记属性:页面壳据此把工具条放在画布上(其余筛选收进白色分组面) */
|
|
26
|
+
export const KIT_FILTER_TOOLBAR_MARK = 'data-kit-filter-toolbar';
|
|
27
|
+
|
|
28
|
+
/** 工具条用到的全部类(并入候选类) */
|
|
29
|
+
export const KIT_FILTER_TOOLBAR_CLASS_CANDIDATES: readonly string[] = [
|
|
30
|
+
...new Set([SEARCH_CELL, SELECT_CELL, SEGMENT_CELL, KIT_FILTER_TOOLBAR_WRAP, KIT_FILTER_TOOLBAR_ACTIONS, 'hidden'].flatMap((s) => s.split(/\s+/))),
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
type Option = { value: unknown; label?: unknown };
|
|
34
|
+
const optionsOf = (c: KitCell): Option[] | null => (Array.isArray(c.props.options) ? (c.props.options as unknown[]).filter((o): o is Option => o !== null && typeof o === 'object') : null);
|
|
35
|
+
|
|
36
|
+
/** 一个格能不能进工具条:编辑态;文字输入,或单选下拉(静态选项 / 远程选项都行,远程的只做下拉不做分段) */
|
|
37
|
+
function eligible(c: KitCell): boolean {
|
|
38
|
+
if (c.mode !== 'edit') return false;
|
|
39
|
+
if (c.component === 'Input') return c.optionsFrom === undefined;
|
|
40
|
+
if (c.component === 'Select') return c.props.multiple !== true && (c.optionsFrom !== undefined || (optionsOf(c)?.length ?? 0) > 0);
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 分段选项补计数:facets 是列表响应里的 `{ 字段: { 枚举值: 条数 } }`;该字段没给 / 形状不对 → 原样返回(不显示计数,绝不从已加载的行里数)。
|
|
46
|
+
* 「全部」(空值选项)的计数 = 各枚举值计数之和,仅当每个枚举值都带了计数才给(缺一项就不给,免得写出错的合计)。
|
|
47
|
+
*/
|
|
48
|
+
export function withFacetCounts(options: readonly Option[], facets: unknown, field: string): Option[] {
|
|
49
|
+
const counts = facets !== null && typeof facets === 'object' && !Array.isArray(facets) ? (facets as Record<string, unknown>)[field] : undefined;
|
|
50
|
+
if (counts === null || typeof counts !== 'object' || Array.isArray(counts)) return [...options];
|
|
51
|
+
const rec = counts as Record<string, unknown>;
|
|
52
|
+
const n = (v: unknown): number | null => (typeof v === 'number' && Number.isInteger(v) && v >= 0 ? v : null);
|
|
53
|
+
const real = options.filter((o) => o.value !== '');
|
|
54
|
+
const known = real.map((o) => n(rec[String(o.value)]));
|
|
55
|
+
const sum = known.every((k) => k !== null) ? known.reduce<number>((a, b) => a + (b ?? 0), 0) : null;
|
|
56
|
+
return options.map((o) => {
|
|
57
|
+
const c = o.value === '' ? sum : n(rec[String(o.value)]);
|
|
58
|
+
return c === null ? o : { ...o, count: c };
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 选项文案相对宽度是否能排成分段(与表单 IA18 同一口径) */
|
|
63
|
+
export function segmentable(options: readonly Option[]): boolean {
|
|
64
|
+
return arrangeChoicePresentation(options.map((o) => textWidthEm(String(o.label ?? o.value)))).mode === 'segmented';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 把一组筛选格改成工具条形体;不合格返回 null(调用方照旧排布)。
|
|
69
|
+
* 返回的格是拷贝:隐藏标签、可访问名 = 字段名、搜索 / 分段 / 下拉各自的 props 与宽度类。
|
|
70
|
+
*/
|
|
71
|
+
export function filterToolbarCells(cells: readonly KitCell[], locale: string): KitCell[] | null {
|
|
72
|
+
const real = cells.filter((c) => c.placeholder !== true);
|
|
73
|
+
if (real.length === 0 || real.length > KIT_FILTER_TOOLBAR_MAX_FIELDS) return null;
|
|
74
|
+
if (!real.every((c) => c.divider !== true && eligible(c))) return null;
|
|
75
|
+
const all = kitText('soma.kit.filter_all_option', undefined, locale);
|
|
76
|
+
return cells.map((c) => {
|
|
77
|
+
if (c.placeholder === true) return c;
|
|
78
|
+
const name = c.label;
|
|
79
|
+
const base: KitCell = { ...c, label: '', labelClass: 'hidden', help: '', props: { ...c.props, aria_label: name } };
|
|
80
|
+
if (c.component === 'Input') {
|
|
81
|
+
return {
|
|
82
|
+
...base,
|
|
83
|
+
cellClass: SEARCH_CELL,
|
|
84
|
+
props: { ...base.props, variant: 'filled', icon: 'search', ...(base.props.placeholder === undefined || base.props.placeholder === '' ? { placeholder: name } : {}) },
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// 远程选项的下拉:没有「全部」语义的占位(默认占位是「全部」),改用字段名当占位——无上方标签时靠它说明这是什么;材质与同行搜索框统一为 filled
|
|
88
|
+
if (c.optionsFrom !== undefined) {
|
|
89
|
+
return { ...base, cellClass: SELECT_CELL, props: { ...base.props, variant: 'filled', placeholder: name } };
|
|
90
|
+
}
|
|
91
|
+
const options = optionsOf(c)!;
|
|
92
|
+
if (segmentable(options)) {
|
|
93
|
+
const rest = Object.fromEntries(Object.entries(base.props).filter(([k]) => k !== 'placeholder'));
|
|
94
|
+
return {
|
|
95
|
+
...base,
|
|
96
|
+
component: 'Radio',
|
|
97
|
+
cellClass: SEGMENT_CELL,
|
|
98
|
+
props: { ...rest, variant: 'segmented', options: [{ value: '', label: all }, ...options] },
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return { ...base, cellClass: SELECT_CELL, props: { ...base.props, variant: 'filled' } };
|
|
102
|
+
});
|
|
103
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// 片段:业务组件与页面框的统一输出结构,也是编译第 3-5 步的合并单位。纯函数。
|
|
2
2
|
|
|
3
|
-
import type { KitEmitResult } from '
|
|
4
|
-
import type { KitDiagnostic } from '../
|
|
3
|
+
import type { KitEmitResult } from './emit-object';
|
|
4
|
+
import type { KitDiagnostic } from '../shared/diagnostics';
|
|
5
5
|
|
|
6
6
|
export interface KitFragment {
|
|
7
7
|
html: string;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
export { emitObject } from './emit-object';
|
|
6
6
|
export type { KitEmitInput, KitEmitResult } from './emit-object';
|
|
7
7
|
export { renderObject } from './render-object';
|
|
8
|
-
export { mergeClass, checkClasses, splitClasses } from '
|
|
8
|
+
export { mergeClass, checkClasses, splitClasses } from '../shared/merge-class';
|
|
9
9
|
export { rowVarOf, emitStatic } from './emit-static';
|
|
10
10
|
export type { KitStaticOptions, KitStaticEmit } from './emit-static';
|
|
11
11
|
export { collectCandidates, classesInHtml } from './candidates';
|
|
@@ -4,10 +4,39 @@
|
|
|
4
4
|
|
|
5
5
|
import { SOMA_PIPELINE_FIELD_ROLES } from 'soma-foundation/data/generated';
|
|
6
6
|
import type { KitPanelKind } from 'soma-foundation/kit-layout';
|
|
7
|
-
import type { KitPageDecl, KitProductDecl, KitTabDecl } from '../compile/types';
|
|
8
7
|
import { normalizeRef } from './arrange';
|
|
9
8
|
import type { KitFieldRef, KitType, KitViewSlot } from './types';
|
|
10
9
|
|
|
10
|
+
/** 布局事实提取所需的产品声明结构(结构子类型兼容 compile/types.ts 的 KitProductDecl,避免数据层反向依赖编译层) */
|
|
11
|
+
export interface KitFactProductInput {
|
|
12
|
+
kind: string;
|
|
13
|
+
objects: Record<string, unknown>;
|
|
14
|
+
class?: string;
|
|
15
|
+
areaClass?: Record<string, string>;
|
|
16
|
+
surface?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** 布局事实提取所需的页签项结构(结构子类型兼容 KitTabDecl) */
|
|
20
|
+
export interface KitFactTabInput {
|
|
21
|
+
product: KitFactProductInput;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 布局事实提取所需的页面声明结构(结构子类型兼容 KitPageDecl) */
|
|
25
|
+
export interface KitFactPageInput {
|
|
26
|
+
page: {
|
|
27
|
+
url: string;
|
|
28
|
+
title: string;
|
|
29
|
+
subtitle?: string;
|
|
30
|
+
maxWidth?: string;
|
|
31
|
+
};
|
|
32
|
+
frame: {
|
|
33
|
+
kind: string;
|
|
34
|
+
class?: string;
|
|
35
|
+
slotClass?: Record<string, string>;
|
|
36
|
+
slots: Record<string, KitFactProductInput | KitFactTabInput[]>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
11
40
|
type Rec = Record<string, unknown>;
|
|
12
41
|
const isRec = (v: unknown): v is Rec => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
13
42
|
const str = (v: unknown): string | undefined => (typeof v === 'string' ? v : undefined);
|
|
@@ -124,6 +153,8 @@ export interface KitPageFacts {
|
|
|
124
153
|
readonly url: string;
|
|
125
154
|
readonly frameKind: string;
|
|
126
155
|
readonly maxWidth: string | null;
|
|
156
|
+
/** 页面作者自己写的 page.max_width(不含页面模式推导与应用默认补上的版心);编译期由 analyzeKitPageLayout 的 declaredMaxWidth 覆写 */
|
|
157
|
+
readonly maxWidthDeclared: string | null;
|
|
127
158
|
readonly products: readonly KitFactProduct[];
|
|
128
159
|
readonly tabsDepth: number;
|
|
129
160
|
readonly frameClasses: ReadonlyArray<{ readonly key: string; readonly value: string; readonly path: string }>;
|
|
@@ -342,7 +373,7 @@ function objectFact(raw: Rec, role: string, name: string | null, isPanel: boolea
|
|
|
342
373
|
};
|
|
343
374
|
}
|
|
344
375
|
|
|
345
|
-
function productFact(product:
|
|
376
|
+
function productFact(product: KitFactProductInput, at: string, slot: string): KitFactProduct {
|
|
346
377
|
const objects: KitFactObject[] = [];
|
|
347
378
|
for (const [role, value] of Object.entries(product.objects ?? {})) {
|
|
348
379
|
if (!isRec(value)) continue;
|
|
@@ -365,16 +396,16 @@ function productFact(product: KitProductDecl, at: string, slot: string): KitFact
|
|
|
365
396
|
}
|
|
366
397
|
|
|
367
398
|
/** 页面声明 → 布局事实。声明形状不对的部分跳过,不抛。 */
|
|
368
|
-
export function extractKitPageFacts(decl:
|
|
399
|
+
export function extractKitPageFacts(decl: KitFactPageInput): KitPageFacts {
|
|
369
400
|
const products: KitFactProduct[] = [];
|
|
370
401
|
let tabsDepth = 0;
|
|
371
402
|
for (const [slot, val] of Object.entries(decl.frame.slots)) {
|
|
372
403
|
if (Array.isArray(val)) {
|
|
373
404
|
tabsDepth = Math.max(tabsDepth, 1);
|
|
374
|
-
(val as
|
|
405
|
+
(val as KitFactTabInput[]).forEach((tab, i) => products.push(productFact(tab.product, `frame.slots.${slot}[${i}].product`, slot)));
|
|
375
406
|
} else {
|
|
376
407
|
// 路径与 view-check 的 viewUsageOf 同口径(main 槽的产品在 YAML 里是顶层 product:),compile/locate 才定位得到行列
|
|
377
|
-
products.push(productFact(val as
|
|
408
|
+
products.push(productFact(val as KitFactProductInput, slot === 'main' ? 'product' : `frame.slots.${slot}`, slot));
|
|
378
409
|
}
|
|
379
410
|
}
|
|
380
411
|
const frameClasses: Array<{ key: string; value: string; path: string }> = classSites(decl.frame as unknown as Rec, 'frame', ['class']);
|
|
@@ -387,6 +418,7 @@ export function extractKitPageFacts(decl: KitPageDecl): KitPageFacts {
|
|
|
387
418
|
url: decl.page.url,
|
|
388
419
|
frameKind: decl.frame.kind,
|
|
389
420
|
maxWidth: decl.page.maxWidth ?? null,
|
|
421
|
+
maxWidthDeclared: decl.page.maxWidth ?? null,
|
|
390
422
|
products,
|
|
391
423
|
tabsDepth,
|
|
392
424
|
frameClasses,
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// 浮层决定(编译段):读页面声明里的浮层内容 -> 抽出「事实」(栏数、组件名)-> 调引擎 arrangeOverlay 拿决定(类型 / 宽度档)。
|
|
2
|
+
// 只做事实抽取与调引擎,不含任何取值、类名、阈值(规则在 kit-arrange#overlay,数字在 kit-limits);外壳(overlay-shell)只接收这里给出的档名去渲染。
|
|
3
|
+
// 流水线位置:真源 -> 引擎(soma-foundation/arrange)-> 本文件(读声明的一层,在 object-renderer,业务编译与外壳都在它之上)-> 外壳 / 配方。
|
|
4
|
+
// 不 import biz:下层不认识上层,窗口宽度档的类型在这里定义,外壳从这里取。
|
|
5
|
+
|
|
6
|
+
import { arrangeOverlay, arrangeOverlayFooter, type ArrangeOverlayFooterPlan } from 'soma-foundation/arrange';
|
|
7
|
+
import type { KitDrawerWidth } from '../recipes/overlay';
|
|
8
|
+
|
|
9
|
+
/** 表单窗口宽度档:default 480 / wide 640 / xwide 800(px 在 kit-limits#overlay.dialogPx) */
|
|
10
|
+
export type KitDialogWidth = 'default' | 'wide' | 'xwide';
|
|
11
|
+
|
|
12
|
+
/** 字段声明所在的 schema(只读 edit / component 两个键:字段控件常常写在 schema 里,而不是视图字段项里) */
|
|
13
|
+
export type SchemaLike = Readonly<Record<string, { edit?: unknown; component?: unknown } | undefined>>;
|
|
14
|
+
|
|
15
|
+
/** 浮层内容声明(事实来源):form 视图、写死形状组件名、列表是否表格形态 */
|
|
16
|
+
export interface OverlayContent {
|
|
17
|
+
form?: unknown;
|
|
18
|
+
staticComponent?: unknown;
|
|
19
|
+
schema?: SchemaLike;
|
|
20
|
+
tableList?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 字段声明用的控件名:字段项自己写的 component 优先,其次 schema 里该字段的 edit / component */
|
|
24
|
+
function componentOfField(decl: unknown, schema: SchemaLike | undefined): string {
|
|
25
|
+
const name = typeof decl === 'string' ? decl : decl !== null && typeof decl === 'object' ? (decl as { name?: unknown }).name : undefined;
|
|
26
|
+
const own = decl !== null && typeof decl === 'object' ? (decl as { component?: unknown }).component : undefined;
|
|
27
|
+
if (typeof own === 'string' && own !== '') return own;
|
|
28
|
+
const fromSchema = typeof name === 'string' ? schema?.[name] : undefined;
|
|
29
|
+
const c = fromSchema?.edit ?? fromSchema?.component;
|
|
30
|
+
return typeof c === 'string' ? c : '';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** form 视图的全部字段声明:顶层 fields 与 groups[].fields 合并 */
|
|
34
|
+
function formFieldsOf(formView: unknown): unknown[] {
|
|
35
|
+
if (formView === null || typeof formView !== 'object') return [];
|
|
36
|
+
const v = formView as { fields?: unknown; groups?: unknown };
|
|
37
|
+
const out: unknown[] = Array.isArray(v.fields) ? [...v.fields] : [];
|
|
38
|
+
if (Array.isArray(v.groups)) {
|
|
39
|
+
for (const g of v.groups) {
|
|
40
|
+
const gf = g !== null && typeof g === 'object' ? (g as { fields?: unknown }).fields : undefined;
|
|
41
|
+
if (Array.isArray(gf)) out.push(...gf);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** form 视图的栏数事实:作者显式写的 arrange(cols / matrix 的列数 / rows 的最长行),没写按单列(字段数不参与) */
|
|
48
|
+
function formColsOf(formView: unknown): number {
|
|
49
|
+
const a = formView !== null && typeof formView === 'object' ? (formView as { arrange?: unknown }).arrange : undefined;
|
|
50
|
+
if (Array.isArray(a) && typeof a[1] === 'number') return a[1];
|
|
51
|
+
if (a === null || typeof a !== 'object') return 1;
|
|
52
|
+
const o = a as { cols?: unknown; matrix?: unknown; rows?: unknown };
|
|
53
|
+
if (typeof o.cols === 'number') return o.cols;
|
|
54
|
+
if (Array.isArray(o.matrix) && typeof o.matrix[1] === 'number') return o.matrix[1];
|
|
55
|
+
if (Array.isArray(o.rows)) return o.rows.reduce<number>((m, r) => Math.max(m, Array.isArray(r) ? r.length : 0), 1);
|
|
56
|
+
return 1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 浮层内容里出现的组件名事实(字段控件 + 静态组件 + 表格形态的列表) */
|
|
60
|
+
function componentsOf(content: OverlayContent): string[] {
|
|
61
|
+
const names = formFieldsOf(content.form).map((f) => componentOfField(f, content.schema)).filter((c) => c !== '');
|
|
62
|
+
if (typeof content.staticComponent === 'string' && content.staticComponent !== '') names.push(content.staticComponent);
|
|
63
|
+
if (content.tableList === true) names.push('Table');
|
|
64
|
+
return names;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 表单窗口的宽度档:事实 -> 引擎决定(规则见 kit-arrange#overlay);字段数不参与 */
|
|
68
|
+
export function dialogWidthOf(content: OverlayContent): KitDialogWidth {
|
|
69
|
+
const plan = arrangeOverlay({ submits: true, cols: formColsOf(content.form), components: componentsOf(content) });
|
|
70
|
+
return plan.tier === 'xwide' ? 'xwide' : plan.tier === 'wide' ? 'wide' : 'default';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 窗口底栏的排法判定:事实(表单声明的底栏动作数;提交 + 取消由外壳固定给出)-> 引擎 arrangeOverlayFooter;ok 为否时 reason 给出越限项(规则在 kit-arrange#overlay.footer) */
|
|
74
|
+
export function footerPlanOf(formView: unknown): ArrangeOverlayFooterPlan {
|
|
75
|
+
const acts = formView !== null && typeof formView === 'object' ? (formView as { footerActions?: unknown }).footerActions : undefined;
|
|
76
|
+
return arrangeOverlayFooter({ hasPrimary: true, secondary: Array.isArray(acts) ? acts.length : 0 });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 只读抽屉的宽度档:事实 -> 引擎决定 */
|
|
80
|
+
export function drawerWidthOf(content: OverlayContent): KitDrawerWidth {
|
|
81
|
+
return arrangeOverlay({ cols: formColsOf(content.form), components: componentsOf(content) }).tier === 'wide' ? 'wide' : 'default';
|
|
82
|
+
}
|
|
@@ -37,7 +37,7 @@ import { checkEnumOptionsAndEditCompatibility, checkFieldRules, checkFlowFields,
|
|
|
37
37
|
import { validateRequestAction } from './request-actions';
|
|
38
38
|
import { hasBehaviorFrom, readStatePathsOf } from './crud-bridge';
|
|
39
39
|
import { KIT_ACTION_TONES } from './emit-events';
|
|
40
|
-
import { checkClasses, mergeClass, splitClasses } from '
|
|
40
|
+
import { checkClasses, mergeClass, splitClasses } from '../shared/merge-class';
|
|
41
41
|
import { filterPlanOf, filterProjectionClasses, KIT_FILTER_DIVIDER, projectFilter, type KitFilterOverride } from './filter-plan';
|
|
42
42
|
import type { ArrangeFilterPlan } from 'soma-foundation/arrange';
|
|
43
43
|
import { slotModeOf } from './mode';
|