soma-kit 0.1.19 → 0.1.20

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soma-kit",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "SOMA 第三条 UI 路线:写死模板与规则,DSL 显式传入,基础组件 + 数据组件",
5
5
  "type": "module",
6
6
  "exports": {
@@ -52,7 +52,7 @@
52
52
  "dependencies": {
53
53
  "jiti": "1.21.7",
54
54
  "js-yaml": "4.3.2",
55
- "soma-core": "^2.2.11",
55
+ "soma-core": "^2.2.12",
56
56
  "soma-foundation": "^0.1.8",
57
57
  "tailwindcss": "^4.1.0",
58
58
  "typescript": "5.9.3"
@@ -1768,6 +1768,10 @@
1768
1768
  "type": "string",
1769
1769
  "description": "外框 Tailwind 类串"
1770
1770
  },
1771
+ "whenEmpty": {
1772
+ "type": "string",
1773
+ "description": "外框 Tailwind 类串"
1774
+ },
1771
1775
  "events": {
1772
1776
  "type": "object",
1773
1777
  "description": "浮层内写死形状数据组件的事件约定(K-1):saved -> 关窗并刷新;cancel / close -> 关窗;reload -> 刷新。overlays.<名>.events 可补自定义事件名。状态事件(与官方表单同名同载荷,组件契约 emits 里声明了才接):busy_change { busy } -> 在途时用户关窗(关闭钮 / 取消 / Esc / 点遮罩)被忽略;dirty_change { dirty } -> 有改动时按浮层 draft 处理(discard 先问、keep 不问)",
@@ -1867,9 +1867,10 @@
1867
1867
  "action": {
1868
1868
  "where": "objects.<角色>.behavior.actions[] 中 on: toolbar 的动作;被 view.form.footerActions 引用的表单底栏动作(不写 on)",
1869
1869
  "keys": [
1870
- "disabled"
1870
+ "disabled",
1871
+ "hidden"
1871
1872
  ],
1872
- "values": "view 路径;路径取值为真时动作置灰;on: toolbar 的动作只支持 disabled;表单底栏动作支持 disabled / hidden(hidden 为真不画;在途的可取消动作仍可点取消);on: row 的动作 hidden / disabled 既可写 view.<成员>(展示对象给出,整页同值)也可写 row.<字段>(见 rowState,业务对象逐行给出),二选一;on: field 的动作不支持,写了报 KIT-VIEW-006"
1873
+ "values": "view 路径;路径取值为真时动作置灰;on: toolbar 的动作与表单底栏动作支持 disabled / hidden(hidden 为真不画,工具条按钮连外壳一并收起、不进「更多」菜单;在途的可取消动作仍可点取消);on: row 的动作 hidden / disabled 既可写 view.<成员>(展示对象给出,整页同值)也可写 row.<字段>(见 rowState,业务对象逐行给出),二选一;on: field 的动作不支持,写了报 KIT-VIEW-006"
1873
1874
  },
1874
1875
  "form": {
1875
1876
  "where": "objects.<角色>.view.form",
@@ -4476,7 +4477,8 @@
4476
4477
  "span",
4477
4478
  "class",
4478
4479
  "group",
4479
- "head"
4480
+ "head",
4481
+ "whenEmpty"
4480
4482
  ]
4481
4483
  }
4482
4484
  },
@@ -4485,7 +4487,8 @@
4485
4487
  "span",
4486
4488
  "class",
4487
4489
  "group",
4488
- "head"
4490
+ "head",
4491
+ "whenEmpty"
4489
4492
  ],
4490
4493
  "areas": [
4491
4494
  "root",
@@ -4516,7 +4519,8 @@
4516
4519
  "span",
4517
4520
  "class",
4518
4521
  "group",
4519
- "head"
4522
+ "head",
4523
+ "whenEmpty"
4520
4524
  ]
4521
4525
  }
4522
4526
  },
@@ -25,7 +25,7 @@ import { KIT_ICON_NAMES, resolveKitIconName, setKitIconCached, type KitIconName
25
25
  import { mergeClass } from '../shared/merge-class';
26
26
  import { KIT_REASON_TIP_CLASS_CANDIDATES, releaseReasonTip, syncReasonTip } from './reason-tip';
27
27
  import { KIT_BUSY_PROP_DEFS, KIT_BUSY_SPIN_CLASS_CANDIDATES, KIT_ROW_ACTION_PROP_DEFS, kitBusyOf, kitRowActionPayload } from './action-busy';
28
- import { KIT_ATTR_BUSY_ICON, KIT_ATTR_BUSY_SLOT, KIT_ATTR_BUSY_SPIN, KIT_ATTR_ICON_CACHE, KIT_ATTR_PART } from '../shared/dom-attrs';
28
+ import { KIT_ATTR_ACTION_HIDDEN, KIT_ATTR_BUSY_ICON, KIT_ATTR_BUSY_SLOT, KIT_ATTR_BUSY_SPIN, KIT_ATTR_ICON_CACHE, KIT_ATTR_PART } from '../shared/dom-attrs';
29
29
 
30
30
  export {
31
31
  KIT_PART_BUTTON,
@@ -273,6 +273,7 @@ export function createButton(): SomaComponentDefinition {
273
273
  ...BADGE_PROPS,
274
274
  loading: { type: 'boolean', default: false, desc: '加载中:显示转圈,不响应点击' },
275
275
  disabled: { type: 'boolean', default: false },
276
+ hidden: { type: 'boolean', default: false, desc: '此刻隐藏(工具条动作 hidden: view.<成员> 编译注入):为真时按钮不显示、不响应点击,并在根上打 data-kit-action-hidden 供动作组外壳一并收起;缺省 false' },
276
277
  disabled_reason: { type: 'string', default: '', desc: '置灰原因文案:disabled 为真且非空时,按钮不用原生 disabled(只留 aria-disabled,保持可聚焦),原因经气泡在悬停 / 聚焦时显示(aria-describedby,Esc 隐藏);点击 / Enter / Space 仍不抛 click;disabled 为假或为空串时与没写一样' },
277
278
  type: { type: 'enum', values: ['button', 'submit', 'reset'], default: 'button', desc: '原生按钮类型' },
278
279
  tooltip: TOOLTIP_PROP,
@@ -297,6 +298,7 @@ export function createButton(): SomaComponentDefinition {
297
298
  const isBtnBlocked = (propsNow: Readonly<Record<string, unknown>>): boolean => {
298
299
  const nativeDisabled = root.tagName === 'BUTTON' && (root as HTMLButtonElement).disabled;
299
300
  return bool(propsNow.disabled)
301
+ || bool(propsNow.hidden)
300
302
  || bool(propsNow.loading)
301
303
  || kitBusyOf(propsNow, api.host)
302
304
  || nativeDisabled
@@ -369,6 +371,14 @@ export function createButton(): SomaComponentDefinition {
369
371
  };
370
372
  },
371
373
  render(root, p, api) {
374
+ // 动作此刻隐藏(hidden prop):只管自己打的标记,别处写的 hidden(权限 / 折叠)不动
375
+ if (bool(p.hidden)) {
376
+ root.hidden = true;
377
+ root.setAttribute(KIT_ATTR_ACTION_HIDDEN, '');
378
+ } else if (root.hasAttribute(KIT_ATTR_ACTION_HIDDEN)) {
379
+ root.hidden = false;
380
+ root.removeAttribute(KIT_ATTR_ACTION_HIDDEN);
381
+ }
372
382
  const loading = bool(p.loading);
373
383
  // 具名动作在途(busy / busy_action,编译期按所接动作名注入):置灰并挂 aria-busy,不带原因气泡(在途不是「不可用」);动作结束随忙闲通道重绘恢复
374
384
  const busy = kitBusyOf(p, api.host);
@@ -108,6 +108,9 @@ export function compileMultiBoard(input: KitBizInput, ctx: KitBizContext): KitFr
108
108
  if (s.group !== undefined && (typeof s.group !== 'string' || s.group.trim() === '')) {
109
109
  fail('KIT-PAGE-001', `panels.${n}.group 必须是非空字符串(面板组名,同名面板收进页内页签的同一签)`, `${at}.group`);
110
110
  }
111
+ if (s.whenEmpty !== undefined && s.whenEmpty !== 'show' && s.whenEmpty !== 'hide') {
112
+ fail('KIT-PAGE-001', `panels.${n}.whenEmpty 只许写 show(缺省:空了显示空态)或 hide(主体只剩空态时整块面板不渲染,数据回来再出现)`, `${at}.whenEmpty`);
113
+ }
111
114
  if (s.head !== undefined) {
112
115
  const host = typeof s.head === 'string' ? s.head.trim() : '';
113
116
  const hostRaw = host === '' ? undefined : rawPanels[host];
@@ -118,7 +121,7 @@ export function compileMultiBoard(input: KitBizInput, ctx: KitBizContext): KitFr
118
121
  } else if (!isStatic) {
119
122
  fail('KIT-PAGE-001', `panels.${n} 是面板头控件,必须是写死形状组件(staticComponent:SegmentedSwitch / MetaAction / ScopeSwitch 等)`, `${at}.view`);
120
123
  }
121
- for (const k of ['title', 'span', 'class', 'group'] as const) {
124
+ for (const k of ['title', 'span', 'class', 'group', 'whenEmpty'] as const) {
122
125
  if (s[k] !== undefined) fail('KIT-PAGE-001', `panels.${n} 是面板头控件,不写 ${k}(位置与分组随宿主面板 "${host}")`, `${at}.${k}`);
123
126
  }
124
127
  }
@@ -280,6 +283,7 @@ export function compileMultiBoard(input: KitBizInput, ctx: KitBizContext): KitFr
280
283
  ...(p.class !== '' ? { class: p.class } : {}),
281
284
  ...(p.group !== '' ? { group: p.group } : {}),
282
285
  ...(next ? { object: p.object } : {}),
286
+ ...((rawPanels[p.name] as unknown as Rec).whenEmpty === 'hide' ? { hideWhenEmpty: true } : {}),
283
287
  };
284
288
  // 构成分析附着(作者没写 head):控件进宿主标题行、宽条筛选作整宽顶带 top-band、说明并为宿主页脚;宿主不是独立面板时在下面退回独立成块
285
289
  const att = pl?.attach;
@@ -13,7 +13,7 @@ import { KIT_NOTICE_BOX_FOOTER, KIT_NOTICE_LIST, KIT_NOTICE_TOGGLE_FOOTER } from
13
13
  import { kitTypographyRecipe } from '../../recipes/typography';
14
14
  import { mergeClass } from '../../shared/merge-class';
15
15
  import {
16
- KIT_ATTR_BOARD, KIT_ATTR_BOARD_PANEL, KIT_ATTR_EMPTY_COLLAPSED, KIT_ATTR_NOTICE, KIT_ATTR_NOTICE_FOOTER, KIT_ATTR_PART, KIT_ATTR_PROSE_FOLDED,
16
+ KIT_ATTR_ACTION_GROUP, KIT_ATTR_BOARD, KIT_ATTR_BOARD_PANEL, KIT_ATTR_BOARD_PANEL_WHEN_EMPTY, KIT_ATTR_EMPTY_COLLAPSED, KIT_ATTR_HOST_EMPTY, KIT_ATTR_NOTICE, KIT_ATTR_NOTICE_FOOTER, KIT_ATTR_PANEL_FOOTER, KIT_ATTR_PANEL_HEAD, KIT_ATTR_PART, KIT_ATTR_PROSE_FOLDED,
17
17
  KIT_ATTR_PROSE_FOOTER, KIT_ATTR_SKELETON, KIT_ATTR_STATE, kitAttrSel,
18
18
  } from '../../shared/dom-attrs';
19
19
  import { kitText } from '../../i18n/kit-text';
@@ -46,9 +46,11 @@ function proseIn(panel: HTMLElement): HTMLElement[] {
46
46
  const EMPTY_ATTR = KIT_ATTR_EMPTY_COLLAPSED;
47
47
  const CONTENT = `svg, canvas, img, video, table, input, select, textarea, button, a, [role="img"], [role="progressbar"], ${kitAttrSel(KIT_ATTR_STATE)}, ${kitAttrSel(KIT_ATTR_SKELETON)}, [aria-busy="true"]`;
48
48
 
49
- /** el 到 panel 之间(不含 panel 自己)没有被 hidden 的祖先 */
49
+ /** el 到 panel 之间(不含 panel 自己)没有被 hidden 或 Tailwind .hidden 藏起的祖先 */
50
50
  function shownWithin(el: HTMLElement, panel: HTMLElement): boolean {
51
- for (let n: HTMLElement | null = el; n !== null && n !== panel; n = n.parentElement) if (n.hidden) return false;
51
+ for (let n: HTMLElement | null = el; n !== null && n !== panel; n = n.parentElement) {
52
+ if (n.hidden || n.classList.contains('hidden')) return false;
53
+ }
52
54
  return true;
53
55
  }
54
56
 
@@ -62,8 +64,73 @@ export function panelHasContent(panel: HTMLElement): boolean {
62
64
  return false;
63
65
  }
64
66
 
67
+ // ── 声明了 whenEmpty: hide 的面板:主体只剩空态(内置空态块或成员自报为空)且不在加载中 / 报错、无其它可见数据时整块收起,数据回来再还原
68
+ const WHEN_EMPTY_HIDE = kitAttrSel(KIT_ATTR_BOARD_PANEL_WHEN_EMPTY, 'hide');
69
+ const EMPTY_MARK = `${kitAttrSel(KIT_ATTR_STATE, 'empty')}, ${kitAttrSel(KIT_ATTR_HOST_EMPTY)}`;
70
+ const BUSY_MARK = `${kitAttrSel(KIT_ATTR_STATE, 'loading')}, ${kitAttrSel(KIT_ATTR_SKELETON)}, [aria-busy="true"]`;
71
+ const ERROR_MARK = `${kitAttrSel(KIT_ATTR_STATE, 'error')}, [role="alert"]`;
72
+ // 面板壳外围部件(标题 / 标题行工具条 / 头控件 / 页脚)与空态块自身子树:不计作「空态之外的主体数据内容」
73
+ const EMPTY_SHELL_EXEMPT = [
74
+ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
75
+ `[${KIT_ATTR_PART}^="title"]`,
76
+ kitAttrSel(KIT_ATTR_PANEL_HEAD),
77
+ kitAttrSel(KIT_ATTR_ACTION_GROUP),
78
+ kitAttrSel(KIT_ATTR_PANEL_FOOTER),
79
+ kitAttrSel(KIT_ATTR_PROSE_FOOTER),
80
+ kitAttrSel(KIT_ATTR_NOTICE_FOOTER),
81
+ EMPTY_MARK,
82
+ ].join(', ');
83
+
84
+ /** 紧邻空态块之前的纯装饰图标(aria-hidden="true",如 KitCollectionState 的空收件箱图标) */
85
+ function isEmptyCompanionIcon(el: HTMLElement, panel: HTMLElement): boolean {
86
+ for (let n: HTMLElement | null = el; n !== null && n !== panel; n = n.parentElement) {
87
+ if (n.getAttribute('aria-hidden') === 'true' && n.nextElementSibling instanceof HTMLElement && n.nextElementSibling.matches(EMPTY_MARK)) {
88
+ return true;
89
+ }
90
+ }
91
+ return false;
92
+ }
93
+
94
+ /**
95
+ * 面板主体此刻是否「只剩空态」:
96
+ * 1. 存在可见的加载态或报错态 → false(加载中与报错绝不隐藏面板);
97
+ * 2. 不存在可见的空态标记 → false;
98
+ * 3. 排除标题 / 标题行工具条 / 头控件 / 页脚与空态子树后,若仍存在任何可见真实内容(图形 / 表格 / 表单控件 / 链接 / 按钮 / 非空白文字)→ false。
99
+ */
100
+ export function panelIsEmptyState(panel: HTMLElement): boolean {
101
+ const shown = (sel: string): boolean => Array.from(panel.querySelectorAll<HTMLElement>(sel)).some((el) => shownWithin(el, panel));
102
+ if (shown(BUSY_MARK) || shown(ERROR_MARK)) return false;
103
+ if (!shown(EMPTY_MARK)) return false;
104
+ for (const node of Array.from(panel.childNodes)) {
105
+ if (node.nodeType === 3 && (node.textContent ?? '').trim() !== '') return false;
106
+ }
107
+ for (const el of Array.from(panel.querySelectorAll<HTMLElement>('*'))) {
108
+ if (!shownWithin(el, panel)) continue;
109
+ const exempt = el.closest(EMPTY_SHELL_EXEMPT);
110
+ if (exempt !== null && panel.contains(exempt) && exempt !== panel) continue;
111
+ if (isEmptyCompanionIcon(el, panel)) continue;
112
+ if (el.matches(CONTENT)) return false;
113
+ for (const node of Array.from(el.childNodes)) {
114
+ if (node.nodeType === 3 && (node.textContent ?? '').trim() !== '') return false;
115
+ }
116
+ }
117
+ return true;
118
+ }
119
+
65
120
  function collapseEmpty(board: HTMLElement): void {
66
121
  for (const panel of Array.from(board.querySelectorAll<HTMLElement>(PANEL))) {
122
+ if (panel.matches(WHEN_EMPTY_HIDE)) {
123
+ const byUs = panel.hasAttribute(EMPTY_ATTR);
124
+ if (panel.hidden && !byUs) continue; // 别人收起的不动
125
+ if (panelIsEmptyState(panel)) {
126
+ panel.hidden = true;
127
+ panel.setAttribute(EMPTY_ATTR, '');
128
+ } else if (byUs) {
129
+ panel.hidden = false;
130
+ panel.removeAttribute(EMPTY_ATTR);
131
+ }
132
+ continue;
133
+ }
67
134
  if (panel.getAttribute(KIT_ATTR_BOARD_PANEL) !== 'bare') continue;
68
135
  const collapsedByUs = panel.hasAttribute(EMPTY_ATTR);
69
136
  if (panel.hidden && !collapsedByUs) continue; // 别人(kitCollapseBlock)收起的不动
@@ -118,6 +185,12 @@ function scan(board: HTMLElement): void {
118
185
  }
119
186
  }
120
187
 
188
+ /** 观察范围:结构与文字变化,外加空态 / 加载中 / 报错标记与 hidden 的切换(whenEmpty: hide 的面板靠它们判空) */
189
+ const OBSERVE: MutationObserverInit = {
190
+ childList: true, subtree: true, characterData: true,
191
+ attributes: true, attributeFilter: ['hidden', 'aria-busy', 'role', KIT_ATTR_STATE, KIT_ATTR_HOST_EMPTY],
192
+ };
193
+
121
194
  export function createKitBoardProse(): SomaComponentDefinition {
122
195
  return {
123
196
  contract: { name: 'KitBoardProse', layer: 'data', props: {} },
@@ -132,11 +205,11 @@ export function createKitBoardProse(): SomaComponentDefinition {
132
205
  const run = (): void => {
133
206
  frame = 0;
134
207
  observer?.disconnect();
135
- try { scan(board); } finally { observer?.observe(board, { childList: true, subtree: true, characterData: true }); }
208
+ try { scan(board); } finally { observer?.observe(board, OBSERVE); }
136
209
  };
137
210
  const queue = (): void => { if (frame === 0) frame = board.ownerDocument.defaultView?.requestAnimationFrame(run) ?? 0; };
138
211
  observer = new MutationObserver(queue);
139
- observer.observe(board, { childList: true, subtree: true, characterData: true });
212
+ observer.observe(board, OBSERVE);
140
213
  queue();
141
214
  return () => { observer?.disconnect(); observer = null; };
142
215
  },
@@ -4,7 +4,7 @@
4
4
  import { kitNeutralClass, kitNeutralSpanClass, kitObjectAnchor } from '../shared/pipeline';
5
5
  import { kitSelfAttrs } from '../../shared/page-attrs-runtime';
6
6
  import {
7
- KIT_ATTR_BAND, KIT_ATTR_BOARD, KIT_ATTR_BOARD_PANEL, KIT_ATTR_CONTAINER, KIT_ATTR_EMPHASIS, KIT_ATTR_FACE_GRID, KIT_ATTR_HEAD_BAND, KIT_ATTR_HERO_STATS,
7
+ KIT_ATTR_BAND, KIT_ATTR_BOARD, KIT_ATTR_BOARD_PANEL, KIT_ATTR_BOARD_PANEL_WHEN_EMPTY, KIT_ATTR_CONTAINER, KIT_ATTR_EMPHASIS, KIT_ATTR_FACE_GRID, KIT_ATTR_HEAD_BAND, KIT_ATTR_HERO_STATS,
8
8
  KIT_ATTR_PANEL_FOOTER, KIT_ATTR_PANEL_HEAD, KIT_ATTR_PART, KIT_ATTR_ROLE, KIT_ATTR_SLOT, KIT_ATTR_SUMMARY, KIT_ATTR_TOP_BAND,
9
9
  } from '../../shared/dom-attrs';
10
10
  import { KIT_ARRANGE, arrangeSplit } from 'soma-foundation/arrange';
@@ -118,6 +118,13 @@ export interface BoardPanelBlock {
118
118
  icon?: { readonly icon: string; readonly tone?: string };
119
119
  /** 新模式下面板对象的运行期名(面板容器锚点据它拼);旧版不给 */
120
120
  object?: string;
121
+ /** 面板声明 `whenEmpty: hide`:主体只剩空态时整块面板不渲染(运行期由 KitBoardProse 按标记收起 / 还原) */
122
+ hideWhenEmpty?: boolean;
123
+ }
124
+
125
+ /** 面板壳上的「空时隐藏」标记(没声明则为空串) */
126
+ function whenEmptyMark(p: BoardPanelBlock): string {
127
+ return p.hideWhenEmpty === true ? ` ${KIT_ATTR_BOARD_PANEL_WHEN_EMPTY}="hide"` : '';
121
128
  }
122
129
 
123
130
  /** 视图标题(view.list.title 编出的 h3 标题出口,data-kit-part="title-section"):面板内容开头(之前只有空白)的第一个 */
@@ -170,7 +177,7 @@ export function boardGridHtml(blocks: readonly BoardPanelBlock[], areaClass: Rec
170
177
  // 有卡的面板才是 section(p-card 标准内边距)。唯一主体不套卡时内容落在页面对齐轴上
171
178
  const tag = plain ? 'div' : 'section';
172
179
  const titled = title !== '' || body !== p.html;
173
- return `<${tag}${cls(klass)}${plain ? '' : KIT_SHELL_FLAT_MARK}${compose} ${KIT_ATTR_BOARD_PANEL}="${titled ? 'titled' : 'bare'}">${title}${topBand}${plain && p.inFace !== true ? tablesOnCanvas(body) : body}${band}</${tag}>`;
180
+ return `<${tag}${cls(klass)}${plain ? '' : KIT_SHELL_FLAT_MARK}${compose} ${KIT_ATTR_BOARD_PANEL}="${titled ? 'titled' : 'bare'}"${whenEmptyMark(p)}>${title}${topBand}${plain && p.inFace !== true ? tablesOnCanvas(body) : body}${band}</${tag}>`;
174
181
  });
175
182
  // data-kit-face-grid:面排布(结构 CSS 按层级策略取面间距,细线档 1px 让相邻面的外缘线并成一条贯通线)
176
183
  return `<div ${KIT_ATTR_FACE_GRID}=""${cls(mergeClass(MULTI_BOARD_CLASS.panels, areaClass.panels))}>\n${sections.join('\n')}\n</div>`;
@@ -189,7 +196,7 @@ function boardPanelNext(p: BoardPanelBlock, title: string, body: string, areaCla
189
196
  const topBand = p.topBand === undefined || p.topBand === '' ? '' : `<div ${KIT_ATTR_TOP_BAND}="" class="w-full min-w-0">${p.topBand}</div>`;
190
197
  const mark = p.object !== undefined ? ` data-soma-id="${esc(kitObjectAnchor(p.object))}"` : '';
191
198
  const titled = title !== '' || body !== p.html;
192
- return `<div${mark}${cls(klass)} ${KIT_ATTR_BOARD_PANEL}="${titled ? 'titled' : 'bare'}">${title}${topBand}${body}${band}</div>`;
199
+ return `<div${mark}${cls(klass)} ${KIT_ATTR_BOARD_PANEL}="${titled ? 'titled' : 'bare'}"${whenEmptyMark(p)}>${title}${topBand}${body}${band}</div>`;
193
200
  }
194
201
 
195
202
  /** 整个壳:协作组件宿主 + 筛选卡 + 面板栅格。区域类按 7.3 同族规则覆写 */
@@ -220,9 +220,8 @@ function usageOfObject(obj: unknown, at: string, out: Usage, staticComponents?:
220
220
  }
221
221
  const footer = isRec(a) && a.on === undefined && footerIds.has(a.id);
222
222
  if (!isRec(a) || (a.on !== 'toolbar' && a.on !== 'row' && !footer)) return;
223
- // toolbar 动作只支持 disabled;底栏动作与行动作 hidden / disabled 可写 view.<成员>(行动作与 row.<字段> 二选一)
223
+ // toolbar 动作、底栏动作与行动作的 hidden / disabled 都可写 view.<成员>(行动作与 row.<字段> 二选一)
224
224
  for (const key of ['disabled', 'hidden'] as const) {
225
- if (a.on === 'toolbar' && key !== 'disabled') continue;
226
225
  const raw = a[key];
227
226
  if (isViewPath(raw)) out.members.push({ name: viewPathMember(raw), at: `${at}.behavior.actions[${i}].${key}`, sub: raw.slice('view.'.length), site: key === 'disabled' ? 'actionDisabled' : 'actionHidden' });
228
227
  }
@@ -1,6 +1,6 @@
1
1
  // 生成物,不得改写:由 soma-kit/scripts/build-kit-grammar-runtime.mjs 从 spec/kit-grammar.json 抽出。
2
2
  // 浏览器侧只读这份运行期切片(闭集与限值);编译侧读完整真源。改真源后运行 `npm run grammar:runtime -w soma-kit` 重新生成。
3
- // 真源指纹 sha256:7be73bc315a9f519a84552cbc16745a9ddef054028d92afa0d078075b16b2868
3
+ // 真源指纹 sha256:ad870a9f44173b16a276b471b9b83683d67912244552c7e48a0b590fa414afa4
4
4
 
5
5
  export const KIT_GRAMMAR_RUNTIME = {
6
6
  "i18n": {
@@ -621,9 +621,10 @@ export const KIT_GRAMMAR_RUNTIME = {
621
621
  "action": {
622
622
  "where": "objects.<角色>.behavior.actions[] 中 on: toolbar 的动作;被 view.form.footerActions 引用的表单底栏动作(不写 on)",
623
623
  "keys": [
624
- "disabled"
624
+ "disabled",
625
+ "hidden"
625
626
  ],
626
- "values": "view 路径;路径取值为真时动作置灰;on: toolbar 的动作只支持 disabled;表单底栏动作支持 disabled / hidden(hidden 为真不画;在途的可取消动作仍可点取消);on: row 的动作 hidden / disabled 既可写 view.<成员>(展示对象给出,整页同值)也可写 row.<字段>(见 rowState,业务对象逐行给出),二选一;on: field 的动作不支持,写了报 KIT-VIEW-006"
627
+ "values": "view 路径;路径取值为真时动作置灰;on: toolbar 的动作与表单底栏动作支持 disabled / hidden(hidden 为真不画,工具条按钮连外壳一并收起、不进「更多」菜单;在途的可取消动作仍可点取消);on: row 的动作 hidden / disabled 既可写 view.<成员>(展示对象给出,整页同值)也可写 row.<字段>(见 rowState,业务对象逐行给出),二选一;on: field 的动作不支持,写了报 KIT-VIEW-006"
627
628
  },
628
629
  "form": {
629
630
  "where": "objects.<角色>.view.form",
@@ -702,7 +703,8 @@ export const KIT_GRAMMAR_RUNTIME = {
702
703
  "span",
703
704
  "class",
704
705
  "group",
705
- "head"
706
+ "head",
707
+ "whenEmpty"
706
708
  ]
707
709
  }
708
710
  },
@@ -14,6 +14,7 @@ import { esc } from '../shared/escape';
14
14
  import { getCompileEnvelope } from '../shared/envelope';
15
15
  import {
16
16
  KIT_ATTR_ACTION_GROUP,
17
+ KIT_ATTR_ACTION_HIDDEN,
17
18
  KIT_ATTR_AG_ITEM,
18
19
  KIT_ATTR_AG_LABEL,
19
20
  KIT_ATTR_AG_TONE,
@@ -1940,6 +1941,9 @@ function toolbarImportance(v: ButtonVariant): KitActionImportance {
1940
1941
  * 成组排布经排布引擎(action-group.ts):恒单行、文字不折行;空间不足时次要动作按优先级逐个收进「更多」(KitActionMore,菜单里危险项置末),
1941
1942
  * 主操作恒在行尾可见;视觉序取引擎 order(非主操作按声明序在前,主操作在行尾)。
1942
1943
  */
1944
+ /** 写了 hidden 的工具条动作的外壳:里面的按钮此刻隐藏(data-kit-action-hidden)时外壳一并收起,不留空位 */
1945
+ const KIT_TOOLBAR_HIDDEN_SHELL_CLASS = `has-${KIT_ATTR_ACTION_HIDDEN}:hidden`;
1946
+
1943
1947
  function renderToolbar(ctx: Ctx, actions: readonly KitAction[]): string {
1944
1948
  const declared = actions.filter((a) => a.on === 'toolbar');
1945
1949
  if (declared.length === 0) return '';
@@ -1964,6 +1968,8 @@ function renderToolbar(ctx: Ctx, actions: readonly KitAction[]): string {
1964
1968
  ...(a.builtin === 'openCreate' ? { icon: 'plus' } : {}),
1965
1969
  // 展示对象路径:路径取值为真时按钮置灰(Button 的 disabled prop)
1966
1970
  ...(a.disabled !== undefined && isViewPath(a.disabled) ? { disabled: viewPathToCore(a.disabled) } : {}),
1971
+ // 展示对象路径:路径取值为真时按钮隐藏(Button 的 hidden prop;外壳按 data-kit-action-hidden 一并收起,「更多」菜单不列)
1972
+ ...(a.hidden !== undefined && isViewPath(a.hidden) ? { hidden: viewPathToCore(a.hidden) } : {}),
1967
1973
  // 置灰原因(disabled 为真时 Button 才显示):字面量原样带,view.<成员> 编成页面变量路径;row. 路径在入口已报 KIT-VIEW-001
1968
1974
  ...toolbarReasonProp(a),
1969
1975
  // 触发具名动作:按动作名注入 busy_action(动作在途期间按钮置灰、aria-busy,随忙闲通道恢复;不从外部改 DOM)
@@ -1974,7 +1980,7 @@ function renderToolbar(ctx: Ctx, actions: readonly KitAction[]): string {
1974
1980
  };
1975
1981
  // 外壳承载「按档隐藏」类与「更多」菜单要读的标记(标签 / 语气);壳里是真按钮,菜单选中即对它 click() 回放
1976
1982
  // next:工具条动作自报元素部件「动作」(挂在外壳上:外壳是可见性与「更多」菜单的单位)
1977
- return `<div${attr('class', projection.itemClass[a.id] ?? 'shrink-0')} ${KIT_ATTR_AG_ITEM}="${esc(a.id)}" ${KIT_ATTR_AG_LABEL}="${esc(a.name)}" ${KIT_ATTR_AG_TONE}="${esc(actionToneMark(variants.get(a.id)!))}"${nextPart(ctx, 'action')}>${host('Button', id)}</div>`;
1983
+ return `<div${attr('class', a.hidden !== undefined && isViewPath(a.hidden) ? `${projection.itemClass[a.id] ?? 'shrink-0'} ${KIT_TOOLBAR_HIDDEN_SHELL_CLASS}` : projection.itemClass[a.id] ?? 'shrink-0')} ${KIT_ATTR_AG_ITEM}="${esc(a.id)}" ${KIT_ATTR_AG_LABEL}="${esc(a.name)}" ${KIT_ATTR_AG_TONE}="${esc(actionToneMark(variants.get(a.id)!))}"${nextPart(ctx, 'action')}>${host('Button', id)}</div>`;
1978
1984
  });
1979
1985
  let more = '';
1980
1986
  if (projection.plan.hasMore || projection.moreClass !== 'hidden') {
@@ -2035,10 +2041,11 @@ function emitStaticIn(ir: KitObjectIR, options: KitStaticOptions): KitStaticEmit
2035
2041
  // 行动作:row.<字段>(业务对象逐行给出)或 view.<成员>(展示对象给出,整页同值),二选一
2036
2042
  if (!isViewPath(a[key])) checkRowPath(a[key], at, `动作 ${a.id} 的 ${key}`, ctx.diagnostics, options.schema);
2037
2043
  }
2038
- else if (a.on === 'toolbar' && key === 'disabled') checkViewPath(a[key], at, `动作 ${a.id} 的 ${key}`, ctx.diagnostics);
2044
+ // 工具条动作:disabled / hidden 都只许纯 view 路径(展示对象给出;工具栏没有「行」)
2045
+ else if (a.on === 'toolbar') checkViewPath(a[key], at, `动作 ${a.id} 的 ${key}`, ctx.diagnostics);
2039
2046
  // 表单底栏动作(不写 on、被 view.form.footerActions 引用):disabled / hidden 都只许纯 view 路径,收集成表单的 footerState prop
2040
2047
  else if (a.on === undefined && footerIds.has(a.id)) checkViewPath(a[key], at, `动作 ${a.id} 的 ${key}`, ctx.diagnostics);
2041
- else ctx.diagnostics.push({ code: 'KIT-VIEW-006', path: at, message: `动作 ${a.id} 的 ${key} 不支持 on: ${String(a.on)}(toolbar 只支持 disabled,底栏动作(被 footerActions 引用)支持 disabled / hidden,行级可用性写在 on: row 动作上)` });
2048
+ else ctx.diagnostics.push({ code: 'KIT-VIEW-006', path: at, message: `动作 ${a.id} 的 ${key} 不支持 on: ${String(a.on)}(toolbar 与底栏动作(被 footerActions 引用)支持 disabled / hidden,写 view.<成员>;行级可用性写在 on: row 动作上)` });
2042
2049
  }
2043
2050
  // 置灰原因(形态与取值已在 closed-set 核过,这里核落点与路径):toolbar 只收字面量 / view.<成员>;row 动作收字面量 / view.<成员> / row.<字段>(字段须在 schema 里);
2044
2051
  // 表单底栏动作(由 object-form 渲染)与其它位置暂不支持,写了报 KIT-VIEW-006,不静默丢弃
@@ -15,8 +15,8 @@ import {
15
15
  KIT_ATTR_BLEED, KIT_ATTR_COLLAPSE, KIT_ATTR_EMPHASIS, KIT_ATTR_ENVELOPE, KIT_ATTR_FLOW, KIT_ATTR_FLUSH,
16
16
  KIT_ATTR_HOST, KIT_ATTR_INSET, KIT_ATTR_LEVEL, KIT_ATTR_ROLE, KIT_ATTR_SCOPE, KIT_ATTR_SPAN,
17
17
  KIT_ATTR_STRIP_HIDDEN, KIT_ATTR_TITLE_HIDDEN, KIT_ATTR_DATA_STATE, KIT_ATTR_INTERACT, KIT_ATTR_PART, KIT_ATTR_ACT,
18
- KIT_ATTR_ACTION, KIT_ATTR_ACTION_GROUP, KIT_ATTR_ADD, KIT_ATTR_AG_ITEM, KIT_ATTR_ANCHORED, KIT_ATTR_ASIDE_IDLE,
19
- KIT_ATTR_AXIS, KIT_ATTR_BADGE, KIT_ATTR_BAND, KIT_ATTR_BOARD, KIT_ATTR_BOARD_PANEL, KIT_ATTR_BOUNDARY,
18
+ KIT_ATTR_ACTION, KIT_ATTR_ACTION_GROUP, KIT_ATTR_ACTION_HIDDEN, KIT_ATTR_ADD, KIT_ATTR_AG_ITEM, KIT_ATTR_ANCHORED, KIT_ATTR_ASIDE_IDLE,
19
+ KIT_ATTR_AXIS, KIT_ATTR_BADGE, KIT_ATTR_BAND, KIT_ATTR_BOARD, KIT_ATTR_BOARD_PANEL, KIT_ATTR_BOARD_PANEL_WHEN_EMPTY, KIT_ATTR_BOUNDARY,
20
20
  KIT_ATTR_BOX, KIT_ATTR_BROWSE, KIT_ATTR_BUSY_ICON, KIT_ATTR_BUSY_SLOT, KIT_ATTR_BUSY_SPIN, KIT_ATTR_CANCEL,
21
21
  KIT_ATTR_CHECK_BOX, KIT_ATTR_CHIP, KIT_ATTR_CODE, KIT_ATTR_COL, KIT_ATTR_COMPACT, KIT_ATTR_CONTAINED,
22
22
  KIT_ATTR_CONTAINER, KIT_ATTR_COUNT, KIT_ATTR_CTX, KIT_ATTR_CTXHOST, KIT_ATTR_DAY, KIT_ATTR_DENSE,
@@ -161,6 +161,7 @@ const ENTRIES: KitDomAttrSpec[] = [
161
161
  { attr: KIT_ATTR_ACT, constant: 'KIT_ATTR_ACT', kind: 'shared', owners: ['biz', 'data', 'object-renderer'], note: '挂在表格行内、权限矩阵、文件列表、树表、图片查看器的动作按钮上,值为动作 id(act);点击委托据此识别动作,行点击与虚拟行重绑据它排除交互元素(permission-matrix.ts:289、file-list.ts:206、tree-table.ts:770、image-viewer.ts:269、table-actions.ts:166)。' },
162
162
  { attr: KIT_ATTR_ACTION, constant: 'KIT_ATTR_ACTION', kind: 'shared', owners: ['base', 'biz', 'data'], note: '挂在各数据组件内可点击的动作按钮上,值为动作 key(如 copy、md-copy-code);组件根上的点击委托 closest 它后抛 action 事件(menu.ts:484、record-card.ts:309、code-view.ts:395、markdown-view.ts:373 等)。' },
163
163
  { attr: KIT_ATTR_ACTION_GROUP, constant: 'KIT_ATTR_ACTION_GROUP', kind: 'shared', owners: ['biz', 'compile', 'data', 'object-renderer'], note: '挂在对象渲染的动作组宿主上,布尔存在型;action-more 靠它找溢出收进「更多」菜单的外壳组,page-composition 据此判断页面是否有动作区(emit-static.ts:1652、action-more.ts:42,119、page-composition.ts:165)。' },
164
+ { attr: KIT_ATTR_ACTION_HIDDEN, constant: 'KIT_ATTR_ACTION_HIDDEN', kind: 'shared', owners: ['base', 'object-renderer'], note: '挂在工具条按钮根上,存在即「该动作此刻隐藏」(动作声明 hidden: view.<成员> 取值为真);动作组外壳用 has-data-kit-action-hidden 变体一并收起,不留空位(base/button.ts、object-renderer/emit-static.ts)。' },
164
165
  { attr: KIT_ATTR_ADD, constant: 'KIT_ATTR_ADD', kind: 'shared', owners: ['base', 'data'], note: '挂在 ReactionBar 的「添加表情」按钮上,布尔存在型;重绘后据它恢复焦点、点击委托识别打开表情面板(data/reaction-bar.ts:226,126,137)。' },
165
166
  { attr: KIT_ATTR_AG_ITEM, constant: 'KIT_ATTR_AG_ITEM', kind: 'shared', owners: ['biz', 'compile', 'data', 'object-renderer'], note: '挂在动作组每个动作外壳上,值为动作 id;action-more 以它枚举动作外壳,把当前被隐藏的收入「更多」菜单(emit-static.ts:1645、action-more.ts:46,54,127)。' },
166
167
  { attr: KIT_ATTR_ANCHORED, constant: 'KIT_ATTR_ANCHORED', kind: 'shared', owners: ['base', 'theme'], note: '挂在锚定浮层(下拉、气泡等)面板根上,布尔存在型;主题 nine-dim-structure 据此给进出场的位移与缩放动画(base/anchored-layer.ts:18、theme/nine-dim-structure.ts:204,225)。', aliases: [{ name: 'KIT_ANCHORED_ATTR', file: 'base/anchored-layer.ts:18' }] },
@@ -351,6 +352,7 @@ const ENTRIES: KitDomAttrSpec[] = [
351
352
  { attr: KIT_ATTR_BG_ICON, constant: 'KIT_ATTR_BG_ICON', kind: 'local', owners: ['base'], note: '挂在 ButtonGroup 按钮内的图标子节点上,布尔存在型;重绘时据它复用 / 更新图标节点(base/button-group.ts:147,143)。' },
352
353
  { attr: KIT_ATTR_BG_LABEL, constant: 'KIT_ATTR_BG_LABEL', kind: 'local', owners: ['base'], note: '挂在 ButtonGroup 按钮内的文字子节点上,布尔存在型;重绘时据它复用 / 更新文字节点(base/button-group.ts:167,163)。' },
353
354
  { attr: KIT_ATTR_BLOCKED, constant: 'KIT_ATTR_BLOCKED', kind: 'local', owners: ['data'], note: '挂在 ApprovalFlow「整单受阻」横幅上,值为受阻状态名(非 none);仅写不读,供样式 / 测试区分受阻类型(data/approval-flow.ts:269)。' },
355
+ { attr: KIT_ATTR_BOARD_PANEL_WHEN_EMPTY, constant: 'KIT_ATTR_BOARD_PANEL_WHEN_EMPTY', kind: 'local', owners: ['biz'], note: '挂在多看板面板壳上,值 "hide":面板声明了 whenEmpty: hide,面板主体只剩空态时整块面板不渲染、数据回来再还原(biz/multi-board/shell.ts、biz/multi-board/prose-fold.ts)。' },
354
356
  { attr: KIT_ATTR_BUSY, constant: 'KIT_ATTR_BUSY', kind: 'local', owners: ['data'], note: '挂在 RowEditor 因所接动作进行中而被禁用的动作按钮上,布尔存在型,用来标记「禁用是自己置的」,结束时只还原这些按钮(data/row-editor.ts:1581-1585)。' },
355
357
  { attr: KIT_ATTR_CAL_SPAN, constant: 'KIT_ATTR_CAL_SPAN', kind: 'local', owners: ['data'], note: '挂在 Calendar 跨日事件条按钮上,值为段位(起 / 中 / 止 的 spanKind);专名避开页面线写的对象宽度档属性 data-kit-span(data/calendar.ts:581)。' },
356
358
  { attr: KIT_ATTR_CALENDAR_POPOVER, constant: 'KIT_ATTR_CALENDAR_POPOVER', kind: 'local', owners: ['data'], note: '挂在 Calendar「更多」浮出的当日议程面板上,值为日期串(dayStr);点击委托据此判断点击是否在浮层内(data/calendar.ts:595,647,662)。' },
@@ -93,6 +93,7 @@ export const KIT_ATTR_PART = 'data-kit-part' as const;
93
93
 
94
94
  export const KIT_ATTR_ACT = 'data-kit-act' as const;
95
95
  export const KIT_ATTR_ACTION = 'data-kit-action' as const;
96
+ export const KIT_ATTR_ACTION_HIDDEN = 'data-kit-action-hidden' as const;
96
97
  export const KIT_ATTR_ACTION_GROUP = 'data-kit-action-group' as const;
97
98
  export const KIT_ATTR_ADD = 'data-kit-add' as const;
98
99
  export const KIT_ATTR_AG_ITEM = 'data-kit-ag-item' as const;
@@ -103,6 +104,7 @@ export const KIT_ATTR_BADGE = 'data-kit-badge' as const;
103
104
  export const KIT_ATTR_BAND = 'data-kit-band' as const;
104
105
  export const KIT_ATTR_BOARD = 'data-kit-board' as const;
105
106
  export const KIT_ATTR_BOARD_PANEL = 'data-kit-board-panel' as const;
107
+ export const KIT_ATTR_BOARD_PANEL_WHEN_EMPTY = 'data-kit-board-panel-when-empty' as const;
106
108
  export const KIT_ATTR_BOUNDARY = 'data-kit-boundary' as const;
107
109
  export const KIT_ATTR_BOX = 'data-kit-box' as const;
108
110
  export const KIT_ATTR_BROWSE = 'data-kit-browse' as const;