@manohub/ui 1.1.3 → 1.1.5

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.
@@ -59,6 +59,11 @@ export declare const ListRow: import("vue").DefineComponent<import("vue").Extrac
59
59
  type: BooleanConstructor;
60
60
  default: boolean;
61
61
  };
62
+ /** 禁用行:`is-disabled` + `aria-disabled`,行点击不再触发 `onSelect`(展开箭头的点击不受影响) */
63
+ disabled: {
64
+ type: BooleanConstructor;
65
+ default: boolean;
66
+ };
62
67
  onSelect: {
63
68
  type: PropType<(node: ListNode) => void>;
64
69
  default: undefined;
@@ -128,6 +133,11 @@ export declare const ListRow: import("vue").DefineComponent<import("vue").Extrac
128
133
  type: BooleanConstructor;
129
134
  default: boolean;
130
135
  };
136
+ /** 禁用行:`is-disabled` + `aria-disabled`,行点击不再触发 `onSelect`(展开箭头的点击不受影响) */
137
+ disabled: {
138
+ type: BooleanConstructor;
139
+ default: boolean;
140
+ };
131
141
  onSelect: {
132
142
  type: PropType<(node: ListNode) => void>;
133
143
  default: undefined;
@@ -160,6 +170,7 @@ export declare const ListRow: import("vue").DefineComponent<import("vue").Extrac
160
170
  }>> & Readonly<{}>, {
161
171
  expanded: boolean;
162
172
  caret: boolean;
173
+ disabled: boolean;
163
174
  onSelect: (node: ListNode) => void;
164
175
  onToggle: (node: ListNode) => void;
165
176
  selected: boolean;
@@ -43,6 +43,11 @@ const ListRow = /* @__PURE__ */ defineComponent({
43
43
  type: Boolean,
44
44
  default: false
45
45
  },
46
+ /** 禁用行:`is-disabled` + `aria-disabled`,行点击不再触发 `onSelect`(展开箭头的点击不受影响) */
47
+ disabled: {
48
+ type: Boolean,
49
+ default: false
50
+ },
46
51
  onSelect: {
47
52
  type: Function,
48
53
  default: void 0
@@ -75,16 +80,22 @@ const ListRow = /* @__PURE__ */ defineComponent({
75
80
  },
76
81
  setup(props) {
77
82
  return () => createVNode("div", {
78
- "class": "mh-list__row",
83
+ "class": ["mh-list__row", props.disabled ? "is-disabled" : ""].filter(Boolean).join(" "),
79
84
  "role": props.role,
80
85
  "aria-selected": props.selected,
86
+ "aria-disabled": props.disabled ? "true" : void 0,
81
87
  "aria-expanded": props.caret && props.hasChildren ? props.expanded : void 0,
82
88
  "data-selected": props.selected ? "true" : void 0,
83
89
  "data-level": props.depth,
84
90
  "style": {
85
91
  "--mh-list-level": props.depth
86
92
  },
87
- "onClick": () => props.onSelect?.(props.node)
93
+ "onClick": () => {
94
+ if (props.disabled) {
95
+ return;
96
+ }
97
+ props.onSelect?.(props.node);
98
+ }
88
99
  }, [props.caret ? props.hasChildren ? createVNode("span", {
89
100
  "class": "mh-list__caret",
90
101
  "data-expanded": props.expanded ? "true" : "false",
@@ -72,6 +72,14 @@ export declare const Tree: import("vue").DefineComponent<import("vue").ExtractPr
72
72
  type: PropType<(node: ListNode) => void>;
73
73
  default: undefined;
74
74
  };
75
+ /**
76
+ * 行禁用判定:命中的行带 `is-disabled` / `aria-disabled`,点行不再触发 `onSelect`。
77
+ * 只影响「选中」这一路;展开箭头仍可用(父节点即便不可选,也还能靠箭头开合)。
78
+ */
79
+ disabledNode: {
80
+ type: PropType<(node: ListNode) => boolean>;
81
+ default: undefined;
82
+ };
75
83
  /**
76
84
  * 标签体的自定义渲染(**替掉** `labelKey` 的纯文本)。与 `renderNode` 的分工:本 prop 渲染的是**标签本体**
77
85
  * (占位 / 省略号 / 行内对齐都由 `.mh-list__label` 承担,故必须留在那个槽里);`renderNode` 渲染标签**之后**的
@@ -216,6 +224,14 @@ export declare const Tree: import("vue").DefineComponent<import("vue").ExtractPr
216
224
  type: PropType<(node: ListNode) => void>;
217
225
  default: undefined;
218
226
  };
227
+ /**
228
+ * 行禁用判定:命中的行带 `is-disabled` / `aria-disabled`,点行不再触发 `onSelect`。
229
+ * 只影响「选中」这一路;展开箭头仍可用(父节点即便不可选,也还能靠箭头开合)。
230
+ */
231
+ disabledNode: {
232
+ type: PropType<(node: ListNode) => boolean>;
233
+ default: undefined;
234
+ };
219
235
  /**
220
236
  * 标签体的自定义渲染(**替掉** `labelKey` 的纯文本)。与 `renderNode` 的分工:本 prop 渲染的是**标签本体**
221
237
  * (占位 / 省略号 / 行内对齐都由 `.mh-list__label` 承担,故必须留在那个槽里);`renderNode` 渲染标签**之后**的
@@ -348,6 +364,7 @@ export declare const Tree: import("vue").DefineComponent<import("vue").ExtractPr
348
364
  renderNode: (node: ListNode) => unknown;
349
365
  renderActions: (node: ListNode) => unknown;
350
366
  childrenKey: string;
367
+ disabledNode: (node: ListNode) => boolean;
351
368
  expandedKeys: string[];
352
369
  defaultExpandedKeys: string[];
353
370
  defaultExpandAll: boolean;
@@ -32,6 +32,14 @@ const Tree = /* @__PURE__ */ defineComponent({
32
32
  type: Function,
33
33
  default: void 0
34
34
  },
35
+ /**
36
+ * 行禁用判定:命中的行带 `is-disabled` / `aria-disabled`,点行不再触发 `onSelect`。
37
+ * 只影响「选中」这一路;展开箭头仍可用(父节点即便不可选,也还能靠箭头开合)。
38
+ */
39
+ disabledNode: {
40
+ type: Function,
41
+ default: void 0
42
+ },
35
43
  /**
36
44
  * 标签体的自定义渲染(**替掉** `labelKey` 的纯文本)。与 `renderNode` 的分工:本 prop 渲染的是**标签本体**
37
45
  * (占位 / 省略号 / 行内对齐都由 `.mh-list__label` 承担,故必须留在那个槽里);`renderNode` 渲染标签**之后**的
@@ -213,6 +221,7 @@ const Tree = /* @__PURE__ */ defineComponent({
213
221
  "hasChildren": hasChildren,
214
222
  "expanded": expanded,
215
223
  "selected": props.selected !== void 0 && props.selected === key,
224
+ "disabled": props.disabledNode ? props.disabledNode(node) : false,
216
225
  "labelKey": props.labelKey,
217
226
  "onSelect": handleSelect,
218
227
  "onToggle": (target) => toggleExpand(nodeKey(target)),
@@ -1,10 +1,13 @@
1
1
  import { defineComponent, createVNode, Fragment } from "vue";
2
2
  import { Button } from "../button/index.js";
3
3
  import { STATE_ILLUSTRATION_ERROR_SVG, STATE_ILLUSTRATION_EMPTY_SVG } from "../../utils/state-illustration.js";
4
+ import { scopeSvgIds } from "../../utils/scope-svg-ids.js";
4
5
  const BUILT_IN_ILLUSTRATION = {
5
6
  empty: STATE_ILLUSTRATION_EMPTY_SVG,
6
7
  error: STATE_ILLUSTRATION_ERROR_SVG
7
8
  };
9
+ const BUNDLE_SEED = Math.random().toString(36).slice(2, 8);
10
+ let illustrationInstance = 0;
8
11
  const QueryState = /* @__PURE__ */ defineComponent({
9
12
  name: "QueryState",
10
13
  inheritAttrs: false,
@@ -77,6 +80,17 @@ const QueryState = /* @__PURE__ */ defineComponent({
77
80
  slots,
78
81
  attrs
79
82
  }) {
83
+ const illustrationScope = `${BUNDLE_SEED}${illustrationInstance += 1}`;
84
+ const scopedIllustrations = /* @__PURE__ */ new Map();
85
+ const builtInIllustration = (kind) => {
86
+ const cached = scopedIllustrations.get(kind);
87
+ if (cached !== void 0) {
88
+ return cached;
89
+ }
90
+ const scoped = scopeSvgIds(BUILT_IN_ILLUSTRATION[kind], illustrationScope);
91
+ scopedIllustrations.set(kind, scoped);
92
+ return scoped;
93
+ };
80
94
  const illustrationWidth = () => props.illustrationSize === void 0 ? void 0 : {
81
95
  width: typeof props.illustrationSize === "number" ? `${props.illustrationSize}px` : props.illustrationSize,
82
96
  height: "auto"
@@ -99,7 +113,7 @@ const QueryState = /* @__PURE__ */ defineComponent({
99
113
  "class": "mh-state-illustration",
100
114
  "style": illustrationWidth(),
101
115
  "aria-hidden": "true",
102
- "innerHTML": BUILT_IN_ILLUSTRATION[kind]
116
+ "innerHTML": builtInIllustration(kind)
103
117
  }, null);
104
118
  };
105
119
  const renderActions = (kind, actionText, onAction) => {
@@ -5,8 +5,9 @@
5
5
  * 显式锚 / 搜索行)、共用原子(面板 id / popover 开合 / 键盘契约)—— 故「面板长相与开合行为」只有一份规格;
6
6
  * 本件独有的只有**树体那一层**:
7
7
  *
8
- * 1. **仅叶子可选**:点叶子行即选中并收起面板;点父节点行只切换展开(父节点是「分组」而不是「选项」,选中它
9
- * 语义上是空的 —— `Tree` 自身不做这个判断,故在此兜住)。
8
+ * 1. **可选口径**:缺省只有叶子可选(点叶子行即选中并收起,点父节点行只切换展开)。
9
+ * 传 `selectable` 谓词可放开任意层级 —— 如筛选场景选中父域即筛整棵子树;
10
+ * 谓词返回 `false` 的父节点行仍可点行展开 / 收起,返回 `false` 的叶子行点击无响应。
10
11
  * 2. **本地过滤树**:搜索行在场时按关键词过滤,命中节点的**祖先链保留**、父节点自身命中则**整支保留**,并强制
11
12
  * 全展到命中层(算法与切分都是纯函数,见 `select-tree-filter.ts`);命中文本按面层的 `.mh-select__hit`
12
13
  * 高亮(靠 `Tree` 的 `renderLabel` 钩子落进标签槽)。
@@ -48,6 +49,16 @@ export declare const SelectTree: import("vue").DefineComponent<import("vue").Ext
48
49
  type: StringConstructor;
49
50
  default: string;
50
51
  };
52
+ /**
53
+ * 可选判定(缺省:只有叶子可选)。
54
+ *
55
+ * 返回 `true` 的节点点行即选中(父节点也可选,如筛选场景选父域即筛整棵子树);
56
+ * 返回 `false` 的父节点行只切换展开 / 收起,返回 `false` 的叶子行点击无响应。
57
+ */
58
+ selectable: {
59
+ type: PropType<(node: ListNode) => boolean>;
60
+ default: undefined;
61
+ };
51
62
  /** 受控值(选中叶子的主键;树选择只单选) */
52
63
  modelValue: {
53
64
  type: StringConstructor;
@@ -177,6 +188,16 @@ export declare const SelectTree: import("vue").DefineComponent<import("vue").Ext
177
188
  type: StringConstructor;
178
189
  default: string;
179
190
  };
191
+ /**
192
+ * 可选判定(缺省:只有叶子可选)。
193
+ *
194
+ * 返回 `true` 的节点点行即选中(父节点也可选,如筛选场景选父域即筛整棵子树);
195
+ * 返回 `false` 的父节点行只切换展开 / 收起,返回 `false` 的叶子行点击无响应。
196
+ */
197
+ selectable: {
198
+ type: PropType<(node: ListNode) => boolean>;
199
+ default: undefined;
200
+ };
180
201
  /** 受控值(选中叶子的主键;树选择只单选) */
181
202
  modelValue: {
182
203
  type: StringConstructor;
@@ -308,6 +329,7 @@ export declare const SelectTree: import("vue").DefineComponent<import("vue").Ext
308
329
  onSearch: (keyword: string) => void;
309
330
  emptyText: string;
310
331
  searchable: boolean;
332
+ selectable: (node: ListNode) => boolean;
311
333
  filterNode: (node: ListNode, keyword: string) => boolean;
312
334
  highlight: boolean;
313
335
  }, SlotsType<{
@@ -2,7 +2,7 @@ import { defineComponent, ref, computed, watch, createVNode, createTextVNode, Fr
2
2
  import { SelectPanel } from "./select-panel.js";
3
3
  import { SelectTrigger } from "./select-trigger.js";
4
4
  import { createSelectPanelId, createTriggerKeydown, showPanel, hidePanel } from "./select-shared.js";
5
- import { filterTreeNodes, findTreeNode, treeLabel, splitHighlight, treeNodeKey, treeChildren } from "./select-tree-filter.js";
5
+ import { filterTreeNodes, findTreeNode, treeLabel, splitHighlight, treeChildren, treeNodeKey } from "./select-tree-filter.js";
6
6
  import { Tree } from "../list/tree.js";
7
7
  const SelectTree = /* @__PURE__ */ defineComponent({
8
8
  name: "SelectTree",
@@ -28,6 +28,16 @@ const SelectTree = /* @__PURE__ */ defineComponent({
28
28
  type: String,
29
29
  default: "children"
30
30
  },
31
+ /**
32
+ * 可选判定(缺省:只有叶子可选)。
33
+ *
34
+ * 返回 `true` 的节点点行即选中(父节点也可选,如筛选场景选父域即筛整棵子树);
35
+ * 返回 `false` 的父节点行只切换展开 / 收起,返回 `false` 的叶子行点击无响应。
36
+ */
37
+ selectable: {
38
+ type: Function,
39
+ default: void 0
40
+ },
31
41
  /** 受控值(选中叶子的主键;树选择只单选) */
32
42
  modelValue: {
33
43
  type: String,
@@ -154,6 +164,7 @@ const SelectTree = /* @__PURE__ */ defineComponent({
154
164
  };
155
165
  const keyOf = (node) => treeNodeKey(node, props.rowKey);
156
166
  const childrenOf = (node) => treeChildren(node, props.childrenKey);
167
+ const isSelectable = (node) => props.selectable ? props.selectable(node) : childrenOf(node).length === 0;
157
168
  const current = computed(() => props.modelValue ?? inner.value);
158
169
  const hasValue = computed(() => current.value !== void 0 && current.value !== "");
159
170
  const collectKeys = (list) => list.flatMap((node) => [keyOf(node), ...collectKeys(childrenOf(node))]);
@@ -195,8 +206,12 @@ const SelectTree = /* @__PURE__ */ defineComponent({
195
206
  handleExpandChange([...next]);
196
207
  };
197
208
  const pick = (node) => {
198
- if (childrenOf(node).length > 0) {
199
- toggleExpand(keyOf(node));
209
+ const hasChildren = childrenOf(node).length > 0;
210
+ const canSelect = isSelectable(node);
211
+ if (!canSelect) {
212
+ if (hasChildren) {
213
+ toggleExpand(keyOf(node));
214
+ }
200
215
  return;
201
216
  }
202
217
  commit(keyOf(node));
@@ -274,6 +289,7 @@ const SelectTree = /* @__PURE__ */ defineComponent({
274
289
  "expandedKeys": expandedKeys.value,
275
290
  "onExpandChange": handleExpandChange,
276
291
  "onSelect": pick,
292
+ "disabledNode": (node) => !isSelectable(node) && childrenOf(node).length === 0,
277
293
  "renderLabel": highlightLabel,
278
294
  "renderIcon": props.renderIcon,
279
295
  "renderCaret": props.renderCaret
@@ -59,6 +59,23 @@
59
59
  color: var(--ui-primary);
60
60
  }
61
61
 
62
+ /* 禁用行(`Tree.disabledNode` 命中;`SelectTree` 用它标「不可选的叶子」):
63
+ 字色降档 + `not-allowed`,且不给滑过 / 按下反馈 —— 不再是「看起来能点、点了没反应」的死行。
64
+ 只用于不可选的叶子;不可选的父节点仍承担展开 / 收起,不禁用。 */
65
+
66
+ .mh-list__row.is-disabled,
67
+ .mh-list__row[aria-disabled='true'] {
68
+ color: var(--ui-base-content-subtle);
69
+ cursor: not-allowed;
70
+ }
71
+
72
+ .mh-list__row.is-disabled:hover,
73
+ .mh-list__row.is-disabled:active,
74
+ .mh-list__row[aria-disabled='true']:hover,
75
+ .mh-list__row[aria-disabled='true']:active {
76
+ background: transparent;
77
+ }
78
+
62
79
  /* 展开箭头:字形由 `@manohub/icon` 的 `<Icon name="chevron-down" />` 提供(本面不画字形);
63
80
  展开态即字形的本向(朝下),**收起态由本层转 −90°(指向右)** —— 与 `operations/collapse.css`
64
81
  的 `.mh-collapse-caret` 同款配方(参考实现 `@aihub/theme` 的树也是「base 字形 + 收起态转竖向」)。 */
@@ -65,7 +65,8 @@
65
65
 
66
66
  /* ===== 插画壳 =====
67
67
  内建插画是**设计交付的 SVG 原样注入**(见 `utils/state-illustration.ts`:结构 / 坐标 / 固定色值 /
68
- `id` / `<title>` 全保留),面里因此只有外壳这一件事:壳宽(264 = 设计画布宽)、窄容器里按比例收缩、
68
+ `<title>` 全保留;`id` 原样保留,但注入前按实例加后缀,见 `utils/scope-svg-ids.ts`),
69
+ 面里因此只有外壳这一件事:壳宽(264 = 设计画布宽)、窄容器里按比例收缩、
69
70
  与下方文案的间距,以及把设计稿写死 `264 × 246` 的画布拉成「随壳自适应」。
70
71
  同理,插画**不跟随主题**(图里是设计终值色,不走 `--ui-*`)——这是「原样引用」的取舍。
71
72
  `illustration` 属性给的图片地址复用同一个壳(`<img>` 自带比例,不需要第二条规则)。 */
@@ -0,0 +1,34 @@
1
+ /**
2
+ * 内联 SVG 的 **id 作用域化**:把「一份固定 id 的设计 SVG」改成「本次渲染独占」的一串。
3
+ *
4
+ * ## 为什么必须有这层
5
+ *
6
+ * `state-illustration.ts` 是设计原样导出的 SVG,里面十几个 `id`(`empty-glow-1` / `empty-badge-clip` …)
7
+ * 是**常量**,而每个 `QueryState` 实例都把它 `innerHTML` 进 DOM 一份。微前端里子应用各自打包、
8
+ * 挂**同一个文档**(aip-web:平台页签容器),于是同一种状态同屏出现两次时,文档里就有两套同名 id。
9
+ *
10
+ * 浏览器解析 `url(#…)` 按**文档树里第一个匹配**算,后出现的那份其实在借前一份的 `<defs>`:
11
+ *
12
+ * - 前一份还渲染着 ⇒ 侥幸一模一样(这就是「只开一个页面时怎么都正常」);
13
+ * - 前一份被隐藏(平台切页签 → `display:none`,那份 `<defs>` 失去布局对象、不再作为资源存在)
14
+ * ⇒ 后一份的 `url()` 全部落空,**凡靠渐变 / 图案 / 遮罩上色的图元整块不绘制**,只剩字面色值的图元;
15
+ * 靠 `<use xlink:href="#…">` 撑起来的遮罩还会被前一份的 `visibility` 连累。
16
+ *
17
+ * 症状指纹:一张「白卡片 + 灰影」—— 恰好是所有 `url(#…)` 图元消失后的残余(2026-10-17 实测,
18
+ * aip-web 的「集成对象管理」与「服务开放」两页同开、都出空态时复现)。
19
+ *
20
+ * ## 做法
21
+ *
22
+ * 渲染前给**所有 id 与三处引用**加同一个后缀:`<mask id="x-s3">` 与 `mask="url(#x-s3)"`、
23
+ * `<use xlink:href="#x-s3">` 必须同源。漏掉引用侧就是另一种空转(定义在、引用不到 —— 回形针角标)
24
+ * ,漏掉 id 侧则是「引用了别人的」。CSS 选择器不参与:本包的样式规则只按 `.mh-*` 类走。
25
+ */
26
+ /**
27
+ * 给内联 SVG 的 id 声明与引用统一加后缀。
28
+ *
29
+ * 只认双引号属性(设计导出如此);`<?xml …?>` 头原样留着,`innerHTML` 会把它当注释丢掉。
30
+ *
31
+ * @param svg 设计原样的 SVG 串
32
+ * @param scope 本实例独占的后缀。会被塞进 `url(#…)`,须只含 `[A-Za-z0-9_-]`(不得有括号 / 引号 / 空白)
33
+ */
34
+ export declare function scopeSvgIds(svg: string, scope: string): string;
@@ -0,0 +1,15 @@
1
+ function scopeSvgIds(svg, scope) {
2
+ return svg.replace(/(\bid=")([^"]+)(")/g, (_match, before, id, after) => {
3
+ return `${before}${id}-${scope}${after}`;
4
+ }).replace(/(url\(#)([^)]+)(\))/g, (_match, before, id, after) => {
5
+ return `${before}${id}-${scope}${after}`;
6
+ }).replace(
7
+ /((?:xlink:)?href="#)([^"]+)(")/g,
8
+ (_match, before, id, after) => {
9
+ return `${before}${id}-${scope}${after}`;
10
+ }
11
+ );
12
+ }
13
+ export {
14
+ scopeSvgIds
15
+ };
@@ -7,6 +7,13 @@
7
7
  * `.mh-state-illustration` 壳(`innerHTML`,与 `@manohub/icon` 渲染字形同一套路),壳宽由 `illustrationSize` 定。
8
8
  * 成功 / 异常两张暂无内建消费方,要「提交完成」整页那样的图形时按同一路子引即可。
9
9
  * 换图 = 重新从设计导出并整体替换本文件,不要在这里改结构、也不要在组件里改细节。
10
+ *
11
+ * ## 注入前必须做 id 作用域化
12
+ *
13
+ * 本文件的 `id` 是**设计原样的常量**(`empty-glow-1` / `error-card-clip-1` …),每注入一份就多一套同名 id;
14
+ * 同一文档里出现两份时,`url(#…)` 会解析到**先出现那份**的 `<defs>`,那份一旦被隐藏,后来者整块丢图。
15
+ * 故**不要**把串直接喂 `innerHTML`:一律先过 `utils/scope-svg-ids.ts` 的 `scopeSvgIds(svg, 本实例唯一后缀)`。
16
+ * 修图时也不要「顺手把 id 改成调用方前缀」—— 图是设计资产,作用域归渲染层。
10
17
  */
11
18
  /** 空态(设计稿「空状态」):圆点底纹 + 叠加卡片 + 蓝色折角 + 绿色回形针角标 */
12
19
  export declare const STATE_ILLUSTRATION_EMPTY_SVG: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manohub/ui",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "AIHub 自绘组件层:不依赖 farris 的手写 Vue TSX 组件 + 自带令牌层(Farris 规范视觉 · daisyUI 式语义令牌 · shadcn 式 API 词汇)。",
@@ -35,7 +35,7 @@
35
35
  "vue": "^3.5.0"
36
36
  },
37
37
  "dependencies": {
38
- "@manohub/icon": "^1.1.3"
38
+ "@manohub/icon": "^1.1.5"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^24.0.0",