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
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// { panel: '' | 'form' | 'overlay', mode, open_form, creating, editing, ov: {<浮层名>: true}, row, id, prefill, seq }
|
|
17
17
|
|
|
18
18
|
import type { SomaComponentDefinition, SomaDataPort, SomaRegionPort } from 'soma-core';
|
|
19
|
-
import { lockDocumentScroll } from 'soma-core/behavior';
|
|
19
|
+
import { createDismissableLayer, lockDocumentScroll, type DismissableLayer } from 'soma-core/behavior';
|
|
20
20
|
import { createKitController } from '../../base/shared';
|
|
21
21
|
import { KIT_CORE_MAPPING, KIT_GRAMMAR } from '../../object-renderer/defaults';
|
|
22
22
|
import { pickPath } from '../../object-renderer/path-pick';
|
|
@@ -25,6 +25,7 @@ import { askKitConfirm } from '../../data/confirm-dialog';
|
|
|
25
25
|
import { beginKitAction } from '../../base/action-busy';
|
|
26
26
|
import { trapTab } from '../../base/popup';
|
|
27
27
|
import { kitText } from '../../i18n/kit-text';
|
|
28
|
+
import { clearKitInlineError, reportKitInlineError } from '../../base/inline-error';
|
|
28
29
|
import { rowBusyName, removeKeyOf } from '../../object-renderer/table-actions';
|
|
29
30
|
import { defaultPageSize, registerKitHub, type KitNotifyTone } from './runtime-hub';
|
|
30
31
|
|
|
@@ -77,6 +78,8 @@ export interface KitRowActionTarget {
|
|
|
77
78
|
ids: readonly string[];
|
|
78
79
|
/** 该处同时抛 row_pick(整行点击):行操作列、虚拟滚动表、树表为 true,右键菜单为 false */
|
|
79
80
|
pick?: boolean;
|
|
81
|
+
/** 事件表里原本没有这处的槽位事件也照路由写(主从页详情头动作区:由编译新增的页面直接实例,不是 emitObject 先发的) */
|
|
82
|
+
force?: boolean;
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
/**
|
|
@@ -102,7 +105,7 @@ export function rewriteRowActions(args: {
|
|
|
102
105
|
for (const key of Object.keys(bag)) {
|
|
103
106
|
if (key.startsWith(`${own}${slotPrefix}`)) { delete bag[key]; existed = true; }
|
|
104
107
|
}
|
|
105
|
-
if (!existed && !force) return;
|
|
108
|
+
if (!existed && !force && target.force !== true) return;
|
|
106
109
|
for (const route of args.routes) {
|
|
107
110
|
if (route.id === 'select') {
|
|
108
111
|
if (target.pick === true) bag[`${own}row_pick`] = route.pipe;
|
|
@@ -419,14 +422,25 @@ export function createKitCoordinator(): SomaComponentDefinition {
|
|
|
419
422
|
};
|
|
420
423
|
// 第一步:聚焦正文里第一个可填写控件(头部的「×」在文档顺序上先于表单),成功返回真
|
|
421
424
|
// 遍历候选而非只取第一个:跳过隐藏 / 不可聚焦 / 只读 / 上传的文件输入;focus() 后确认真的拿到焦点才算数
|
|
425
|
+
// 可编辑控件 = 原生输入 + 自绘的同类角色(单选组 / 复选 / 开关 / 组合框 / 数值 / 滑块,KT-K-overlay-4,§6.1 G-8);
|
|
426
|
+
// 单选组只认当前项(已选中的那个;组内都未选时取第一个),不逐项停
|
|
422
427
|
const focusBodyField = (dlg: HTMLElement): boolean => {
|
|
423
428
|
const scopeEl = dlg.querySelector('[data-kit-dialog-body], [data-kit-overlay-body]') ?? dlg;
|
|
424
|
-
const candidates = scopeEl.querySelectorAll<HTMLElement>('input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [contenteditable="true"], [contenteditable=""]');
|
|
429
|
+
const candidates = scopeEl.querySelectorAll<HTMLElement>('input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [contenteditable="true"], [contenteditable=""], [role="radio"]:not(:disabled), [role="checkbox"]:not(:disabled), [role="switch"]:not(:disabled), [role="combobox"], [role="spinbutton"], [role="slider"], [role="textbox"]');
|
|
425
430
|
for (const field of candidates) {
|
|
426
431
|
const type = field instanceof HTMLInputElement ? field.type : '';
|
|
427
432
|
if (type === 'hidden' || type === 'file') continue;
|
|
428
433
|
if (unusableIn(dlg, field)) continue;
|
|
429
|
-
if ((field as HTMLInputElement).readOnly) continue;
|
|
434
|
+
if ((field as HTMLInputElement).readOnly || field.getAttribute('aria-disabled') === 'true' || field.getAttribute('aria-readonly') === 'true') continue;
|
|
435
|
+
if (field.getAttribute('role') === 'radio') {
|
|
436
|
+
const group = field.closest('[role="radiogroup"]');
|
|
437
|
+
const checked = group?.querySelector<HTMLElement>('[role="radio"][aria-checked="true"]');
|
|
438
|
+
if (checked && checked !== field) continue;
|
|
439
|
+
}
|
|
440
|
+
if (field instanceof HTMLInputElement && field.type === 'radio' && !field.checked && field.name !== '') {
|
|
441
|
+
const peers = Array.from(scopeEl.querySelectorAll<HTMLInputElement>('input[type="radio"]')).filter((r) => r.name === field.name);
|
|
442
|
+
if (peers.some((r) => r.checked)) continue;
|
|
443
|
+
}
|
|
430
444
|
field.focus();
|
|
431
445
|
if (holdsFocus(field)) return true;
|
|
432
446
|
}
|
|
@@ -434,8 +448,18 @@ export function createKitCoordinator(): SomaComponentDefinition {
|
|
|
434
448
|
};
|
|
435
449
|
// 第二步:回退聚焦,返回实际拿到焦点的元素;沿用同一套排除规则,弹窗内确无可聚焦元素时落在弹窗自身
|
|
436
450
|
// (无 tabindex 先补 -1,对话框的标准做法)并返回弹窗
|
|
451
|
+
// 顺序(KT-K-overlay-4,§6.1 G-8):正文里的可聚焦元素 → 底栏主钮(提交)→ 底栏其余钮 → 其它(含头部「×」,最后才轮到)
|
|
437
452
|
const focusFallback = (dlg: HTMLElement): HTMLElement => {
|
|
438
|
-
const
|
|
453
|
+
const sel = 'input:not(:disabled), select:not(:disabled), textarea:not(:disabled), button:not(:disabled), [tabindex]:not([tabindex="-1"])';
|
|
454
|
+
const body = dlg.querySelector('[data-kit-dialog-body], [data-kit-overlay-body]');
|
|
455
|
+
const foot = dlg.querySelector('[data-kit-overlay-foot]');
|
|
456
|
+
const ordered = [
|
|
457
|
+
...(body ? Array.from(body.querySelectorAll<HTMLElement>(sel)) : []),
|
|
458
|
+
...(foot ? Array.from(foot.querySelectorAll<HTMLElement>('[data-soma-scoped-id="kit_submit"] button:not(:disabled)')) : []),
|
|
459
|
+
...(foot ? Array.from(foot.querySelectorAll<HTMLElement>(sel)) : []),
|
|
460
|
+
...Array.from(dlg.querySelectorAll<HTMLElement>(sel)),
|
|
461
|
+
];
|
|
462
|
+
const fallbacks = ordered.filter((el, i) => ordered.indexOf(el) === i);
|
|
439
463
|
for (const el of fallbacks) {
|
|
440
464
|
const type = el instanceof HTMLInputElement ? el.type : '';
|
|
441
465
|
if (type === 'hidden' || type === 'file') continue;
|
|
@@ -567,11 +591,55 @@ export function createKitCoordinator(): SomaComponentDefinition {
|
|
|
567
591
|
const focus = port?.slice('focus');
|
|
568
592
|
if (!port || !focus) return;
|
|
569
593
|
focus.set(closedFocus(0));
|
|
594
|
+
const doc = api.host?.ownerDocument ?? (typeof document !== 'undefined' ? document : null);
|
|
595
|
+
/** 栈顶判定:把声明式浮层纳入 core 统一层栈(DismissableLayer),避免被下层浮层截走 Escape 或无法分层收口 */
|
|
596
|
+
let escapeLayer: DismissableLayer | null = null;
|
|
597
|
+
let closeOverlayByUser: (() => void) | null = null;
|
|
598
|
+
const isPopupExpanded = (el: HTMLElement | null): boolean => {
|
|
599
|
+
if (!el || el.getAttribute('aria-expanded') !== 'true') return false;
|
|
600
|
+
// 表单可折叠分组标题、树节点、JSON 树展开钮是行内展开而非弹出浮层,聚焦其上按 Esc 仍应关闭弹窗
|
|
601
|
+
if (el.hasAttribute('data-kit-group-toggle') || el.hasAttribute('data-kit-tree-toggle')) return false;
|
|
602
|
+
const role = el.getAttribute('role');
|
|
603
|
+
if (role === 'treeitem' || role === 'row') return false;
|
|
604
|
+
return true;
|
|
605
|
+
};
|
|
606
|
+
const syncEscapeLayer = (open: boolean): void => {
|
|
607
|
+
if (!doc) return;
|
|
608
|
+
if (!open) {
|
|
609
|
+
escapeLayer?.unmount();
|
|
610
|
+
escapeLayer = null;
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
if (escapeLayer === null) {
|
|
614
|
+
escapeLayer = createDismissableLayer(null, {
|
|
615
|
+
document: doc,
|
|
616
|
+
dismissOnEscape: true,
|
|
617
|
+
dismissOnOutside: false,
|
|
618
|
+
onEscapeKeyDown: (e) => {
|
|
619
|
+
if (e.defaultPrevented || focusOf(focus.get()).panel === '') return false;
|
|
620
|
+
const active = doc.activeElement as HTMLElement | null;
|
|
621
|
+
if (isPopupExpanded(active)) return false;
|
|
622
|
+
// 流程画布内有选中项或右键菜单时先让画布自己取消,二次 Esc 再关窗
|
|
623
|
+
const target = e.target as Element | null;
|
|
624
|
+
const flowStage = target?.closest?.('[role="group"][aria-roledescription]');
|
|
625
|
+
if (flowStage && (flowStage.querySelector('[data-flow-selected]') !== null || flowStage.querySelector('[data-flow-act^="menu-"]') !== null)) {
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
return undefined;
|
|
629
|
+
},
|
|
630
|
+
onDismiss: () => { closeOverlayByUser?.(); },
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
if (escapeLayer.mounted) escapeLayer.bringToFront();
|
|
634
|
+
else escapeLayer.mount();
|
|
635
|
+
};
|
|
570
636
|
const setFocus = (f: ReturnType<typeof nextFocus>): void => {
|
|
571
637
|
focus.set(f);
|
|
638
|
+
const open = focusOf(f).panel !== '';
|
|
572
639
|
// 面板已关:还在等弹窗变可见的初始焦点作废
|
|
573
|
-
if (
|
|
574
|
-
syncScrollLock(
|
|
640
|
+
if (!open) cancelDialogWait();
|
|
641
|
+
syncScrollLock(open);
|
|
642
|
+
syncEscapeLayer(open);
|
|
575
643
|
};
|
|
576
644
|
const notifySvc = (api.services as { notify?: { toast?: (o: { level: string; message: string }) => void } } | undefined)?.notify;
|
|
577
645
|
const rawInstanceId = (api as { instanceId?: unknown }).instanceId;
|
|
@@ -741,6 +809,10 @@ export function createKitCoordinator(): SomaComponentDefinition {
|
|
|
741
809
|
if (inFlightRemovals.has(flightKey)) return;
|
|
742
810
|
inFlightRemovals.add(flightKey);
|
|
743
811
|
|
|
812
|
+
const reportRemoveFailure = (raw: string): void => {
|
|
813
|
+
const text = raw !== '' ? raw : kitText('soma.kit.action_failed_plain', { name: kitText('soma.kit.delete', undefined, api.host ?? null) }, api.host ?? null);
|
|
814
|
+
reportKitInlineError(api.host ?? null, text, `remove:${object}`, () => notifySvc?.toast?.({ level: 'danger', message: text }));
|
|
815
|
+
};
|
|
744
816
|
const doRemove = (): void => {
|
|
745
817
|
if (!data || object === '') {
|
|
746
818
|
inFlightRemovals.delete(flightKey);
|
|
@@ -758,6 +830,7 @@ export function createKitCoordinator(): SomaComponentDefinition {
|
|
|
758
830
|
void pending.then((r) => {
|
|
759
831
|
if (!alive) return undefined;
|
|
760
832
|
if (r.ok) {
|
|
833
|
+
clearKitInlineError(api.host ?? null, `remove:${object}`);
|
|
761
834
|
// 删除成功:被删行不再处于已选(取消确认 / 删除失败时已选行保持原样)
|
|
762
835
|
// 已选集合只属于主对象:删的是成员对象的行时不动它
|
|
763
836
|
if (isMain) {
|
|
@@ -773,13 +846,14 @@ export function createKitCoordinator(): SomaComponentDefinition {
|
|
|
773
846
|
return undefined;
|
|
774
847
|
}
|
|
775
848
|
console.error(`[soma-kit] 删除失败:${r.message}`);
|
|
776
|
-
|
|
849
|
+
// 错误不用轻提示(KT-K-feedback-3,§6.1 G-17):行删除失败进页面就地提示条,无槽才回退轻提示
|
|
850
|
+
reportRemoveFailure(r.message);
|
|
777
851
|
return undefined;
|
|
778
852
|
}, (err: unknown) => {
|
|
779
853
|
// 删除请求本身被拒绝(Promise 拒绝):与「返回失败结果」走同一条失败提示;只挂在删除请求上,成功后的重取失败不会落到这里
|
|
780
854
|
const message = err instanceof Error ? err.message : '';
|
|
781
855
|
console.error(`[soma-kit] 删除失败:${message}`);
|
|
782
|
-
if (alive)
|
|
856
|
+
if (alive) reportRemoveFailure(message);
|
|
783
857
|
return undefined;
|
|
784
858
|
}).catch((err: unknown) => {
|
|
785
859
|
// 删除已成功之后的重取被拒绝:只记日志,可见提示由列表自己的失败态呈现
|
|
@@ -813,7 +887,7 @@ export function createKitCoordinator(): SomaComponentDefinition {
|
|
|
813
887
|
}
|
|
814
888
|
};
|
|
815
889
|
off = port.onSemantic((rawName, rawPayload) => handleSemantic(rawName, rawPayload));
|
|
816
|
-
if (
|
|
890
|
+
if (doc && typeof doc.addEventListener === 'function') {
|
|
817
891
|
// 用户发起的关窗(Esc / 点遮罩):与头部「关闭」同一裁决,有未保存修改先问
|
|
818
892
|
const closeByUser = (): void => {
|
|
819
893
|
const now = focusOf(focus.get());
|
|
@@ -829,21 +903,24 @@ export function createKitCoordinator(): SomaComponentDefinition {
|
|
|
829
903
|
.then((ok) => { if (ok && alive && !formBusy && focusOf(focus.get()).panel !== '') finish(); })
|
|
830
904
|
.catch((err: unknown) => { console.error('[soma-kit] 放弃修改确认失败:', err instanceof Error ? err.message : String(err)); });
|
|
831
905
|
};
|
|
906
|
+
closeOverlayByUser = closeByUser;
|
|
832
907
|
const onKeyDown = (e: KeyboardEvent): void => {
|
|
833
908
|
// Tab 陷阱:只管本协调组件最上层的可见弹窗;焦点在别处挂载的浮层(下拉 / 日期面板 / 确认框)里时不干预
|
|
834
909
|
if (e.key === 'Tab') {
|
|
835
910
|
if (e.defaultPrevented || focusOf(focus.get()).panel === '') return;
|
|
836
911
|
const dlg = visibleDialog();
|
|
837
912
|
if (!dlg) return;
|
|
838
|
-
const active =
|
|
839
|
-
if (active !== null && active !==
|
|
913
|
+
const active = doc.activeElement;
|
|
914
|
+
if (active !== null && active !== doc.body && !dlg.contains(active)) return;
|
|
840
915
|
trapTab(e, dlg);
|
|
841
916
|
return;
|
|
842
917
|
}
|
|
918
|
+
// Escape 优先由核心层栈(DismissableLayer)处理;此处兜底仅当层栈未挂载时生效
|
|
843
919
|
if (e.key !== 'Escape' || e.defaultPrevented || e.isComposing || e.keyCode === 229) return;
|
|
920
|
+
if (escapeLayer?.mounted) return;
|
|
844
921
|
if (focusOf(focus.get()).panel === '') return;
|
|
845
|
-
const active =
|
|
846
|
-
if (active
|
|
922
|
+
const active = doc.activeElement as HTMLElement | null;
|
|
923
|
+
if (isPopupExpanded(active)) return;
|
|
847
924
|
e.preventDefault();
|
|
848
925
|
closeByUser();
|
|
849
926
|
};
|
|
@@ -852,19 +929,23 @@ export function createKitCoordinator(): SomaComponentDefinition {
|
|
|
852
929
|
const onMouseDown = (e: MouseEvent): void => {
|
|
853
930
|
downOnScrim = scrimOf(e.target, api.host?.parentElement) !== null;
|
|
854
931
|
};
|
|
932
|
+
// 含输入的窗口(表单、带搜索的选择)不因点击遮罩关闭(knowledge/Kit主题规则与算法.md KT-K-overlay-2,2026-11-25 裁决):
|
|
933
|
+
// 只看窗口里有没有可编辑控件(结构判定,不测量);纯信息 / 只读窗口照常点遮罩关闭;Esc 与关闭钮不受影响
|
|
934
|
+
// 遮罩元素包着窗口面板(base/overlay-shell):在被点的这层遮罩里找
|
|
935
|
+
const hasInput = (scrim: HTMLElement): boolean => scrim.querySelector('input:not([type=hidden]), textarea, select, [contenteditable="true"], [role="combobox"]') !== null;
|
|
855
936
|
const onClick = (e: MouseEvent): void => {
|
|
856
937
|
const hit = scrimOf(e.target, api.host?.parentElement);
|
|
857
938
|
const was = downOnScrim;
|
|
858
939
|
downOnScrim = false;
|
|
859
|
-
if (hit !== null && was) closeByUser();
|
|
940
|
+
if (hit !== null && was && !hasInput(hit)) closeByUser();
|
|
860
941
|
};
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
942
|
+
doc.addEventListener('keydown', onKeyDown);
|
|
943
|
+
doc.addEventListener('mousedown', onMouseDown);
|
|
944
|
+
doc.addEventListener('click', onClick);
|
|
864
945
|
offKey = () => {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
946
|
+
doc.removeEventListener('keydown', onKeyDown);
|
|
947
|
+
doc.removeEventListener('mousedown', onMouseDown);
|
|
948
|
+
doc.removeEventListener('click', onClick);
|
|
868
949
|
};
|
|
869
950
|
}
|
|
870
951
|
return () => {
|
|
@@ -873,6 +954,8 @@ export function createKitCoordinator(): SomaComponentDefinition {
|
|
|
873
954
|
formBusy = false;
|
|
874
955
|
syncAriaBusy();
|
|
875
956
|
syncScrollLock(false);
|
|
957
|
+
syncEscapeLayer(false);
|
|
958
|
+
closeOverlayByUser = null;
|
|
876
959
|
for (const end of removalBusyEnds.values()) end();
|
|
877
960
|
removalBusyEnds.clear();
|
|
878
961
|
inFlightRemovals.clear();
|
|
@@ -22,8 +22,8 @@ import type { KitBizContext, KitOverlayDecl, KitOverlayEventAction } from '../ty
|
|
|
22
22
|
import { KIT_COORD_EVENTS, KIT_COORD_MIRRORS, overlayMirrorKey } from './coordinator';
|
|
23
23
|
import { addEmit, IDENT, isRec, labelDiagnostics, mirrorPath, patchProps, type Parts, type Rec } from '../link/shared';
|
|
24
24
|
import { semanticPipe, wireDialogForm } from './pipes';
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
25
|
+
import { overlayHtml, overlayIds } from './overlay-shell';
|
|
26
|
+
import { dialogWidthOf, drawerWidthOf, footerPlanOf } from '../../object-renderer/overlay-decide';
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* 抽屉里有没有提交动作:返回原因(无则 null)。判据:表单视图、behavior.write、事件接到具名动作 / saved 语义、
|
|
@@ -45,6 +45,28 @@ export function drawerSubmitReason(decl: KitOverlayDecl, view: KitView, staticCo
|
|
|
45
45
|
return null;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
const FOOTER_REASON: Readonly<Record<string, string>> = Object.freeze({
|
|
49
|
+
'left-over': '左侧次级动作超过上限',
|
|
50
|
+
extras: '有动作想放进底栏却没有位置',
|
|
51
|
+
'visible-over': '底栏可见按钮总数超过上限',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 窗口底栏排法(KIT-OVL-004,先以告警落地):右侧固定「取消 + 一个主动作」,左侧至多一个次级动作,其余进「更多」或改成正文控件。
|
|
56
|
+
* 判定在引擎(arrangeOverlayFooter,规则 kit-arrange#overlay.footer),这里只取事实(表单的 footerActions 数)并出诊断。
|
|
57
|
+
*/
|
|
58
|
+
export function adviseDialogFooter(ctx: KitBizContext, formView: unknown, path: string): void {
|
|
59
|
+
if (ctx.advise === undefined) return;
|
|
60
|
+
const plan = footerPlanOf(formView);
|
|
61
|
+
if (plan.ok) return;
|
|
62
|
+
ctx.advise({
|
|
63
|
+
code: 'KIT-OVL-004',
|
|
64
|
+
path,
|
|
65
|
+
message: `窗口底栏排不下:${FOOTER_REASON[plan.reason] ?? plan.reason}(按钮 ${plan.visible} 个)`,
|
|
66
|
+
hint: '底栏右侧只放「取消 + 主动作」,左侧至多一个次级动作;其余收进更多,或改成正文里的控件',
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
48
70
|
/** 浮层里数据组件的约定事件 -> 角色(K-1) */
|
|
49
71
|
const OVERLAY_EVENT_ROLES: Record<string, string> = KIT_GRAMMAR.overlayEventRoles.conventional as Record<string, string>;
|
|
50
72
|
const OVERLAY_ROLE_SEMANTIC: Record<string, string> = {
|
|
@@ -130,18 +152,14 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
|
|
|
130
152
|
const at = `product.overlays.${name}`;
|
|
131
153
|
if (!IDENT.test(name)) return undefined;
|
|
132
154
|
// 抽屉宽度档:width 只对 kind: drawer 有效(对话框宽度由内容定档),取值闭集 narrow / default / wide
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
else dialogTier = decl.width;
|
|
142
|
-
} else {
|
|
143
|
-
fail('KIT-BIZ-003', `浮层 ${name} 的 width 只对 kind: drawer / dialog 有效`, `${at}.width`);
|
|
144
|
-
}
|
|
155
|
+
// 窗口的大小与外观由框架按内容推导(确认 400、表单 480 / 640 / 800、只读抽屉 480 / 640,尺寸规格 §5),页面不写 width / class(KIT-OVL-003)
|
|
156
|
+
// 过渡期:KIT-OVL-002 / 003 先以告警落地(不挡编译,kit check 的弃用提示段带出),应用按 apps-todo 改完后升为错误
|
|
157
|
+
const warn = (code: string, message: string, path: string, hint: string): void => {
|
|
158
|
+
if (ctx.advise !== undefined) ctx.advise({ code, path, message, hint });
|
|
159
|
+
else fail(code, message, path);
|
|
160
|
+
};
|
|
161
|
+
for (const key of ['width', 'class'] as const) {
|
|
162
|
+
if (decl[key] !== undefined) warn('KIT-OVL-003', `浮层 ${name} 写了 ${key}:窗口的宽度与外观由框架按内容推导,该键已不生效`, `${at}.${key}`, `删掉 ${key};要换档请改内容(栏数 arrange、组件):单列 480、两列或宽组件 640、三列或画布 800、只读抽屉 480 / 640`);
|
|
145
163
|
}
|
|
146
164
|
const view = normalizeOverlayView(decl.view);
|
|
147
165
|
if (view === undefined) {
|
|
@@ -152,9 +170,13 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
|
|
|
152
170
|
if (decl.kind === 'drawer') {
|
|
153
171
|
const why = drawerSubmitReason(decl, view, ctx.staticComponents);
|
|
154
172
|
if (why !== null) {
|
|
155
|
-
fail('KIT-OVL-001', `浮层 ${name} 是抽屉却承载提交动作(${why}):填写并提交、或确认后写入的浮层改写 kind: dialog
|
|
173
|
+
fail('KIT-OVL-001', `浮层 ${name} 是抽屉却承载提交动作(${why}):填写并提交、或确认后写入的浮层改写 kind: dialog(宽度由栏数与宽组件推导),抽屉只用于只读详情`, `${at}.kind`);
|
|
156
174
|
}
|
|
175
|
+
} else if (decl.kind === 'dialog' && drawerSubmitReason(decl, view, ctx.staticComponents) === null) {
|
|
176
|
+
// 只读内容一律抽屉(KIT-OVL-002):没有表单、写入、提交动作的居中窗口是错类型
|
|
177
|
+
warn('KIT-OVL-002', `浮层 ${name} 是居中窗口却只读(没有表单视图、behavior.write、具名动作或 saved 事件)`, `${at}.kind`, '只读内容改写 kind: drawer;居中窗口只给确认与带提交的表单');
|
|
157
178
|
}
|
|
179
|
+
if (decl.kind === 'dialog') adviseDialogFooter(ctx, view.form, `${at}.view.form.footerActions`);
|
|
158
180
|
// 编辑详情(behavior.detail)与读通道(behavior.from)二选一:from 已是「按关联键取浮层对象」的读口
|
|
159
181
|
if (decl.behavior?.from !== undefined && decl.behavior?.detail !== undefined) {
|
|
160
182
|
fail('KIT-DET-001', `附加浮层 ${name} 同时写了 behavior.from 与 behavior.detail:二选一(from 已按关联键取浮层对象,detail 用于以当前行为初值的编辑表单)`, `${at}.behavior.detail`);
|
|
@@ -199,6 +221,7 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
|
|
|
199
221
|
}
|
|
200
222
|
// K-1 / M1-3:浮层里的写死形状数据组件(应用组件)按约定抛 saved / cancel / close / reload,由协调组件接;
|
|
201
223
|
// overlays.<名>.events 可再把自定义事件名映射到这四种之一。组件没抛的事件不会触发(core 对未声明的 emit 选择器惰性)
|
|
224
|
+
const submitActions = new Set<string>();
|
|
202
225
|
for (const slot of ['list', 'summary'] as const) {
|
|
203
226
|
const staticComp = view[slot]?.staticComponent;
|
|
204
227
|
if (staticComp === undefined) continue;
|
|
@@ -235,6 +258,8 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
|
|
|
235
258
|
}
|
|
236
259
|
out.events[`${anchor}.${emitName}`] = actionPipe;
|
|
237
260
|
namedOn[emitName] = role.action;
|
|
261
|
+
// 提交类事件(saved 语义)绑的应用具名动作:登记为本浮层的提交动作,成功后框架默认关窗 + 成功反馈(request 类已由宿主 closeOnSuccess)
|
|
262
|
+
if (declared === undefined && (emitName === 'saved' || OVERLAY_EVENT_ROLES[emitName] === 'saved')) submitActions.add(role.action);
|
|
238
263
|
continue;
|
|
239
264
|
}
|
|
240
265
|
// view.<方法>:浮层里组件抛出的事件调展示对象方法(载荷 = 组件 emit 的载荷;不关窗不重取,要请求走 ctx.request / ctx.action)
|
|
@@ -269,12 +294,17 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
|
|
|
269
294
|
out.events[`${ids.edit}.click`] = semanticPipe(scope, KIT_COORD_EVENTS.showEdit);
|
|
270
295
|
}
|
|
271
296
|
return {
|
|
272
|
-
//
|
|
273
|
-
html: overlayHtml(ids, decl.kind === 'drawer' ? 'drawer' : 'dialog', decl.title ?? name, ovEmit.html,
|
|
297
|
+
// 窗口宽度档只由内容经引擎推导(overlay-decide),外壳只渲染档名;页面写的宽度类(class / areaClass)被壳忽略
|
|
298
|
+
html: overlayHtml(ids, decl.kind === 'drawer' ? 'drawer' : 'dialog', decl.title ?? name, ovEmit.html, undefined, areaClass, withEdit, h.closeLabel, '', dialogWidthOf({
|
|
299
|
+
form: view.form,
|
|
300
|
+
schema: decl.schema,
|
|
301
|
+
staticComponent: view.list?.staticComponent ?? view.summary?.staticComponent,
|
|
302
|
+
}), drawerWidthOf({
|
|
274
303
|
form: view.form,
|
|
275
304
|
schema: decl.schema,
|
|
276
305
|
staticComponent: view.list?.staticComponent ?? view.summary?.staticComponent,
|
|
277
|
-
|
|
306
|
+
tableList: view.list !== undefined && view.list.staticComponent === undefined && (view.list.collection === undefined || view.list.collection.type === 'table'),
|
|
307
|
+
}), [...submitActions]),
|
|
278
308
|
mirror: { key: overlayMirrorKey(name), slice: 'focus', path: `ov.${name}`, as: 'truthy' },
|
|
279
309
|
object: ovObject,
|
|
280
310
|
};
|
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
1
|
+
// 业务组件共用的弹窗外壳(声明式调用方):浮层 id / 标题、显隐宿主、弹窗 HTML 生成。
|
|
2
|
+
// 外壳结构只在 base/overlay-shell 一份(命令式的确认 / 提示 / 选择器 / 抽屉调同一份),这里只传「决定」:哪种窗口、哪一档宽度、标题与正文是什么。
|
|
3
3
|
// 增删改查(standard-crud)、分类增删改查、主从、记录详情都用同一套弹窗壳,放在这里避免业务组件横向依赖增删改查的外壳;
|
|
4
4
|
// standard-crud/shell.ts 从这里 import 并原样 re-export。只有结构和 Tailwind 类,不写原生 CSS。
|
|
5
5
|
// 显隐层统一用 `fixed inset-0` 的遮罩 + 内层 flex 容器:显隐只靠 core 写 `hidden` 属性,不在遮罩自身叠 display 类。
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
KIT_FIXED_ATTRIBUTE, KIT_PART_DIALOG, KIT_PART_DRAWER, KIT_PART_TITLE_DIALOG,
|
|
13
|
-
kitOverlayBodyRecipe, kitOverlayFooterRecipe, kitOverlayHeaderRecipe, kitTypographyRecipe,
|
|
14
|
-
} from '../../recipes';
|
|
15
|
-
|
|
16
|
-
/** 对话框面板类串:只在这里写一份,三档宽度各传自己的宽度类(480 / 720 / 960) */
|
|
17
|
-
function dialogPanelClass(width: string): string {
|
|
18
|
-
return `flex max-h-full w-full ${width} flex-col ${KIT_DIALOG_SURFACE_CLASS} motion-safe:animate-kit-dialog-in`;
|
|
19
|
-
}
|
|
7
|
+
import { esc } from '../../shared/escape';
|
|
8
|
+
import { mergeClass } from '../../shared/merge-class';
|
|
9
|
+
import type { KitDialogTier, KitDrawerWidth } from '../../recipes/overlay';
|
|
10
|
+
import { kitShellClasses, kitShellHtml } from '../../base/overlay-shell';
|
|
11
|
+
import { kitIconHtml } from '../../shared/icons';
|
|
20
12
|
|
|
21
13
|
/**
|
|
22
14
|
* 浮层显隐外层(只放 core 写的 hidden 属性):定位类 fixed 让它出流——它自己 0 高,留在业务壳根的 flex 流里就会为每个浮层多量出一份 gap
|
|
@@ -26,8 +18,15 @@ function dialogPanelClass(width: string): string {
|
|
|
26
18
|
*/
|
|
27
19
|
export const LAYER_HOST_CLASS_ATTR = ' class="fixed z-50"';
|
|
28
20
|
|
|
29
|
-
/**
|
|
30
|
-
|
|
21
|
+
/**
|
|
22
|
+
* 浮层显隐外层上的「提交动作」标记:值是空格分隔的具名动作名。具名动作从这个浮层里触发且成功时,
|
|
23
|
+
* 框架默认关窗并给成功反馈(每个处理函数都要记得写的事归框架);处理函数调 keepOpen() 可显式不关。
|
|
24
|
+
*/
|
|
25
|
+
export const KIT_SUBMIT_ACTIONS_ATTR = 'data-kit-submit-actions';
|
|
26
|
+
|
|
27
|
+
/** 表单窗口宽度档:default 480、wide 640(两列 / 宽组件)、xwide 800(三列 / 画布) */
|
|
28
|
+
import type { KitDialogWidth } from '../../object-renderer/overlay-decide';
|
|
29
|
+
export type { KitDialogWidth };
|
|
31
30
|
|
|
32
31
|
/** 宽度类(`w-*` / `min-w-*` / `max-w-*`,含任意变体前缀):浮层宽度只由内容档位决定,页面写的宽度类不参与 */
|
|
33
32
|
const WIDTH_CLASS_TOKEN = /^(?:[^:]+:)*-?(?:min-w|max-w|w)-/;
|
|
@@ -39,77 +38,27 @@ export function stripOverlayWidthClasses(cls: string | undefined): string | unde
|
|
|
39
38
|
return kept.length === 0 ? undefined : kept.join(' ');
|
|
40
39
|
}
|
|
41
40
|
|
|
41
|
+
const DIALOG = kitShellClasses({ kind: 'dialog', dialogTier: 'default' });
|
|
42
|
+
const DRAWER = kitShellClasses({ kind: 'drawer', drawerWidth: 'default' });
|
|
43
|
+
|
|
44
|
+
/** 外壳各段类串(候选类收集与测试读;全部来自 base/overlay-shell 的一份配方) */
|
|
42
45
|
export const OVERLAY_SHELL_CLASS = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
title: kitTypographyRecipe('dialogTitle'),
|
|
56
|
-
close: 'inline-flex size-8 shrink-0 border-0 bg-transparent p-0 cursor-pointer items-center justify-center rounded-md text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
57
|
-
headerActions: 'flex items-center gap-cluster',
|
|
58
|
-
body: kitOverlayBodyRecipe(),
|
|
59
|
-
footer: kitOverlayFooterRecipe(),
|
|
46
|
+
dialogRow: DIALOG.scrim,
|
|
47
|
+
dialog: DIALOG.panel,
|
|
48
|
+
dialogWide: kitShellClasses({ kind: 'dialog', dialogTier: 'wide' }).panel,
|
|
49
|
+
dialogXWide: kitShellClasses({ kind: 'dialog', dialogTier: 'xwide' }).panel,
|
|
50
|
+
drawerRow: DRAWER.scrim,
|
|
51
|
+
drawer: DRAWER.panel,
|
|
52
|
+
header: DIALOG.header,
|
|
53
|
+
title: DIALOG.title,
|
|
54
|
+
close: DIALOG.close,
|
|
55
|
+
headerActions: DIALOG.headActions,
|
|
56
|
+
body: DIALOG.body,
|
|
57
|
+
footer: DIALOG.footer,
|
|
60
58
|
} as const;
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
* 入参是 form 视图声明(view.form);读不出字段时回 480 档。
|
|
65
|
-
*/
|
|
66
|
-
export function dialogIsWide(formView: unknown, schema?: SchemaLike): boolean {
|
|
67
|
-
const fields = formFieldsOf(formView);
|
|
68
|
-
if (fields.length > KIT_OVERLAY_LIMITS.wideFieldCount) return true;
|
|
69
|
-
return fields.some((f) => componentOfField(f, schema) === 'Transfer');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** 字段声明所在的 schema(只读 edit / component 两个键:字段控件常常写在 schema 里,而不是视图字段项里) */
|
|
73
|
-
type SchemaLike = Readonly<Record<string, { edit?: unknown; component?: unknown } | undefined>>;
|
|
74
|
-
|
|
75
|
-
/** 字段声明用的控件名:字段项自己写的 component 优先,其次 schema 里该字段的 edit / component */
|
|
76
|
-
function componentOfField(decl: unknown, schema: SchemaLike | undefined): string {
|
|
77
|
-
const name = typeof decl === 'string' ? decl : decl !== null && typeof decl === 'object' ? (decl as { name?: unknown }).name : undefined;
|
|
78
|
-
const own = decl !== null && typeof decl === 'object' ? (decl as { component?: unknown }).component : undefined;
|
|
79
|
-
if (typeof own === 'string' && own !== '') return own;
|
|
80
|
-
const fromSchema = typeof name === 'string' ? schema?.[name] : undefined;
|
|
81
|
-
const c = fromSchema?.edit ?? fromSchema?.component;
|
|
82
|
-
return typeof c === 'string' ? c : '';
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** form 视图的全部字段声明:顶层 fields 与 groups[].fields 合并(分组表单的字段在 groups 里,也算长表单) */
|
|
86
|
-
function formFieldsOf(formView: unknown): unknown[] {
|
|
87
|
-
if (formView === null || typeof formView !== 'object') return [];
|
|
88
|
-
const v = formView as { fields?: unknown; groups?: unknown };
|
|
89
|
-
const out: unknown[] = Array.isArray(v.fields) ? [...v.fields] : [];
|
|
90
|
-
if (Array.isArray(v.groups)) {
|
|
91
|
-
for (const g of v.groups) {
|
|
92
|
-
const gf = g !== null && typeof g === 'object' ? (g as { fields?: unknown }).fields : undefined;
|
|
93
|
-
if (Array.isArray(gf)) out.push(...gf);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return out;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* 对话框宽度三档:form 含画布(component: FlowEditor)走 960;含穿梭框(Transfer,字段或浮层的静态组件)或字段数超阈值走 720;其余 480。
|
|
101
|
-
* 入参是浮层内容:form 视图声明与静态组件名;页面写的宽度类不参与(见 stripOverlayWidthClasses)。
|
|
102
|
-
*/
|
|
103
|
-
export function dialogWidthOf(content: { form?: unknown; staticComponent?: unknown; schema?: SchemaLike }): KitDialogWidth {
|
|
104
|
-
const fields = formFieldsOf(content.form);
|
|
105
|
-
if (fields.some((f) => componentOfField(f, content.schema) === 'FlowEditor')) return 'xwide';
|
|
106
|
-
if (content.staticComponent === 'Transfer') return 'wide';
|
|
107
|
-
return dialogIsWide(content.form, content.schema) ? 'wide' : 'default';
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function dialogPanelOf(width: boolean | KitDialogWidth): string {
|
|
111
|
-
const tier: KitDialogWidth = width === true ? 'wide' : width === false ? 'default' : width;
|
|
112
|
-
return tier === 'xwide' ? OVERLAY_SHELL_CLASS.dialogXWide : tier === 'wide' ? OVERLAY_SHELL_CLASS.dialogWide : OVERLAY_SHELL_CLASS.dialog;
|
|
60
|
+
function tierOf(width: boolean | KitDialogWidth): KitDialogTier {
|
|
61
|
+
return width === true ? 'wide' : width === false ? 'default' : width;
|
|
113
62
|
}
|
|
114
63
|
|
|
115
64
|
/** 空串不出 class 属性,否则 ` class="..."` */
|
|
@@ -117,9 +66,9 @@ export function classAttr(value: string): string {
|
|
|
117
66
|
return value === '' ? '' : ` class="${esc(value)}"`;
|
|
118
67
|
}
|
|
119
68
|
|
|
120
|
-
/** 弹窗关闭钮(SVG
|
|
69
|
+
/** 弹窗关闭钮(SVG 图标钮,类串与命令式浮层的关闭钮同一份):各弹窗外壳共用 */
|
|
121
70
|
export function closeButtonHtml(id: string, label: string): string {
|
|
122
|
-
return `<button type="button" data-soma-id="${esc(id)}" aria-label="${esc(label)}"
|
|
71
|
+
return `<button type="button" data-soma-id="${esc(id)}" aria-label="${esc(label)}"${classAttr(OVERLAY_SHELL_CLASS.close)}>${kitIconHtml('close', 'md')}</button>`;
|
|
123
72
|
}
|
|
124
73
|
|
|
125
74
|
export interface DialogShellIds {
|
|
@@ -155,18 +104,17 @@ export function dialogTitles(formTitle: unknown, dflt: { create: string; edit: s
|
|
|
155
104
|
|
|
156
105
|
/** 新增 / 编辑弹窗:标题按 creating / editing 两个真值显隐,正文是 KitObjectForm */
|
|
157
106
|
export function dialogHtml(ids: DialogShellIds, copy: { create: string; edit: string }, body: string, areaClass: Record<string, string>, closeLabel = 'Close', footer = '', wide: boolean | KitDialogWidth = false): string {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
+ '</div></div></div>';
|
|
107
|
+
const decision = { kind: 'dialog', dialogTier: tierOf(wide) } as const;
|
|
108
|
+
const panelClass = mergeClass(kitShellClasses(decision).panel, stripOverlayWidthClasses(areaClass.dialog));
|
|
109
|
+
return `<div data-soma-id="${esc(ids.dialogLayer)}"${LAYER_HOST_CLASS_ATTR}>${kitShellHtml({
|
|
110
|
+
...decision,
|
|
111
|
+
panelClass,
|
|
112
|
+
titleId: ids.dialogTitle,
|
|
113
|
+
titleHtml: `<span data-soma-id="${esc(ids.dialogTitleCreate)}">${esc(copy.create)}</span><span data-soma-id="${esc(ids.dialogTitleEdit)}">${esc(copy.edit)}</span>`,
|
|
114
|
+
close: { label: closeLabel, somaId: ids.dialogClose },
|
|
115
|
+
bodyHtml: body,
|
|
116
|
+
footerHtml: footer !== '' ? footer : null,
|
|
117
|
+
})}</div>`;
|
|
170
118
|
}
|
|
171
119
|
|
|
172
120
|
// ---------------------------------------------------------------- 附加浮层(dialog / drawer)
|
|
@@ -193,19 +141,22 @@ export function overlayHtml(
|
|
|
193
141
|
wide: boolean | KitDialogWidth = false,
|
|
194
142
|
/** 抽屉宽度档(页面 DSL 浮层声明的 width;只对 kind: drawer 有效,缺省 default) */
|
|
195
143
|
drawerWidth: KitDrawerWidth = 'default',
|
|
144
|
+
/** 本浮层的「提交」具名动作(提交类事件绑的应用动作):成功后由框架默认关窗并给成功反馈(见 app/define-kit-actions) */
|
|
145
|
+
submitActions: readonly string[] = [],
|
|
196
146
|
): string {
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
const panel = mergeClass(mergeClass(base, stripOverlayWidthClasses(areaClass[kind])), stripOverlayWidthClasses(panelClass));
|
|
147
|
+
const decision = kind === 'drawer' ? { kind, drawerWidth } as const : { kind, dialogTier: tierOf(wide) } as const;
|
|
148
|
+
const panel = mergeClass(mergeClass(kitShellClasses(decision).panel, stripOverlayWidthClasses(areaClass[kind])), stripOverlayWidthClasses(panelClass));
|
|
200
149
|
const editHost = `<div data-soma-component="Button" data-soma-id="${esc(ids.edit)}"></div>`;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
150
|
+
const submitMark = submitActions.length > 0 ? ` ${KIT_SUBMIT_ACTIONS_ATTR}="${esc(submitActions.join(' '))}"` : '';
|
|
151
|
+
return `<div data-soma-id="${esc(ids.layer)}"${submitMark}${LAYER_HOST_CLASS_ATTR}>${kitShellHtml({
|
|
152
|
+
...decision,
|
|
153
|
+
panelClass: panel,
|
|
154
|
+
titleId: ids.title,
|
|
155
|
+
titleSomaId: ids.title,
|
|
156
|
+
titleHtml: esc(title),
|
|
157
|
+
...(withEdit ? { headActionsHtml: editHost } : {}),
|
|
158
|
+
close: { label: closeLabel, somaId: ids.close },
|
|
159
|
+
bodyHtml: body,
|
|
160
|
+
footerHtml: footer !== '' ? footer : null,
|
|
161
|
+
})}</div>`;
|
|
211
162
|
}
|
|
@@ -17,9 +17,9 @@ import { emitObject } from '../../object-renderer/emit-object';
|
|
|
17
17
|
import { savedNoticePipe } from '../../object-renderer/form-notify';
|
|
18
18
|
import { viewAnchor } from '../../object-renderer/emit-static';
|
|
19
19
|
import type { KitDiagnostic, KitObject, KitViewForm } from '../../object-renderer/types';
|
|
20
|
-
import type { KitFragment } from '../../
|
|
20
|
+
import type { KitFragment } from '../../object-renderer/fragment';
|
|
21
21
|
import type { KitBizContext, KitBizInput } from '../types';
|
|
22
|
-
import { mergeClass } from '../../
|
|
22
|
+
import { mergeClass } from '../../shared/merge-class';
|
|
23
23
|
import {
|
|
24
24
|
bizObjectName, checkRoleAllowedViews, finishBizCompile, validateBizAreaClass,
|
|
25
25
|
} from '../shared/compile-helpers';
|