@taocompany/magic-grid-mcp 0.15.0 → 0.15.1

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.
@@ -5,6 +5,8 @@ export interface ParsedAttr {
5
5
  literalValue: string | boolean | null;
6
6
  raw: string;
7
7
  isBinding: boolean;
8
+ /** `:prop="expr"` 的表达式原文;非绑定为 undefined */
9
+ expression?: string;
8
10
  }
9
11
  export interface MagicGridBlock {
10
12
  line: number;
@@ -1 +1 @@
1
- {"version":3,"file":"parseMagicGrid.d.ts","sourceRoot":"","sources":["../../src/scan/parseMagicGrid.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,iCAAiC;IACjC,YAAY,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;IACrC,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB;AAKD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE,CAgBtF;AAiED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAYtF"}
1
+ {"version":3,"file":"parseMagicGrid.d.ts","sourceRoot":"","sources":["../../src/scan/parseMagicGrid.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,iCAAiC;IACjC,YAAY,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;IACrC,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,OAAO,CAAA;IAClB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB;AAKD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE,CAgBtF;AAiED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAYtF"}
@@ -58,7 +58,7 @@ function parseAttrs(attrSource, baseLine) {
58
58
  continue;
59
59
  }
60
60
  if (isBinding) {
61
- attrs.push({ name, line, literalValue: null, raw, isBinding: true });
61
+ attrs.push({ name, line, literalValue: null, raw, isBinding: true, expression: match[4] });
62
62
  continue;
63
63
  }
64
64
  attrs.push({
@@ -0,0 +1,9 @@
1
+ import type { ParsedAttr } from '../scan/parseMagicGrid.js';
2
+ import type { UncheckedItem, ValidationIssue } from '../types.js';
3
+ /**
4
+ * `hover-behavior` 是对象 prop:静态写法一定错;`:hover-behavior` 仅对象字面量可校验,
5
+ * 变量 / 计算属性进 unchecked。
6
+ * @returns 是否完成了静态校验
7
+ */
8
+ export declare function checkHoverBehavior(file: string, attr: ParsedAttr, errors: ValidationIssue[], unchecked: UncheckedItem[]): boolean;
9
+ //# sourceMappingURL=hoverBehaviorLiteral.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hoverBehaviorLiteral.d.ts","sourceRoot":"","sources":["../../src/validate/hoverBehaviorLiteral.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAMjE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,eAAe,EAAE,EACzB,SAAS,EAAE,aAAa,EAAE,GACzB,OAAO,CA6DT"}
@@ -0,0 +1,66 @@
1
+ const HOVER_TYPES = ['row', 'default'];
2
+ const HOVER_KEYS = new Set(['type', 'keep']);
3
+ const RULE = 'hover-behavior-shape';
4
+ /**
5
+ * `hover-behavior` 是对象 prop:静态写法一定错;`:hover-behavior` 仅对象字面量可校验,
6
+ * 变量 / 计算属性进 unchecked。
7
+ * @returns 是否完成了静态校验
8
+ */
9
+ export function checkHoverBehavior(file, attr, errors, unchecked) {
10
+ if (!attr.isBinding) {
11
+ const value = typeof attr.literalValue === 'string' ? attr.literalValue.trim() : '';
12
+ const type = HOVER_TYPES.includes(value) ? value : 'row';
13
+ const to = `:hover-behavior="{ type: '${type}' }"`;
14
+ errors.push({
15
+ file,
16
+ line: attr.line,
17
+ rule: RULE,
18
+ severity: 'error',
19
+ message: `${attr.raw} 无效:hover-behavior 是对象 prop,应写 ${to}`,
20
+ fix: { kind: 'fix-literal', from: attr.raw, to },
21
+ });
22
+ return true;
23
+ }
24
+ const expression = attr.expression?.trim() ?? '';
25
+ if (!expression.startsWith('{')) {
26
+ unchecked.push({
27
+ reason: 'binding-not-literal',
28
+ at: `${file}:${attr.line}`,
29
+ detail: `${attr.raw} 非对象字面量,无法静态校验 HoverBehavior`,
30
+ });
31
+ return false;
32
+ }
33
+ let value;
34
+ try {
35
+ value = new Function(`return (${expression})`)();
36
+ }
37
+ catch {
38
+ unchecked.push({
39
+ reason: 'parse-error',
40
+ at: `${file}:${attr.line}`,
41
+ detail: 'hover-behavior 字面量无法解析为对象',
42
+ });
43
+ return false;
44
+ }
45
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
46
+ return true;
47
+ }
48
+ const push = (message, fix) => errors.push({ file, line: attr.line, rule: RULE, severity: 'error', message, fix });
49
+ const record = value;
50
+ for (const key of Object.keys(record)) {
51
+ if (!HOVER_KEYS.has(key)) {
52
+ push(`HoverBehavior 未知字段「${key}」,只支持 type / keep`);
53
+ }
54
+ }
55
+ if ('type' in record && !HOVER_TYPES.includes(record.type)) {
56
+ push(`hover-behavior type「${String(record.type)}」无效,允许值:${HOVER_TYPES.join(' | ')}`, {
57
+ kind: 'fix-literal',
58
+ from: String(record.type),
59
+ to: 'row',
60
+ });
61
+ }
62
+ if ('keep' in record && typeof record.keep !== 'boolean') {
63
+ push(`hover-behavior keep 应为 boolean,收到 ${JSON.stringify(record.keep)}`);
64
+ }
65
+ return true;
66
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"validateUsage.d.ts","sourceRoot":"","sources":["../../src/validate/validateUsage.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,KAAK,EAGV,mBAAmB,EAEpB,MAAM,aAAa,CAAA;AAWpB,UAAU,eAAe;IACvB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,EAC/B,OAAO,EAAE,eAAe,GACvB,mBAAmB,CAmIrB"}
1
+ {"version":3,"file":"validateUsage.d.ts","sourceRoot":"","sources":["../../src/validate/validateUsage.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,KAAK,EAGV,mBAAmB,EAEpB,MAAM,aAAa,CAAA;AAYpB,UAAU,eAAe;IACvB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,EAC/B,OAAO,EAAE,eAAe,GACvB,mBAAmB,CA2IrB"}
@@ -2,6 +2,7 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { collectSourceFiles } from '../scan/collectSourceFiles.js';
4
4
  import { findMagicGridBlocks, findStyleImports, } from '../scan/parseMagicGrid.js';
5
+ import { checkHoverBehavior } from './hoverBehaviorLiteral.js';
5
6
  import { checkPropTypeLiteral } from './propTypeLiteral.js';
6
7
  const RESERVED_COL_KEYS = new Set([
7
8
  '__tree__',
@@ -58,6 +59,13 @@ export function validateMagicGridUsage(resolved, options) {
58
59
  checked++;
59
60
  continue;
60
61
  }
62
+ if (resolvePropName(attr.name) === 'hoverBehavior') {
63
+ checkable++;
64
+ if (checkHoverBehavior(rel, attr, errors, unchecked)) {
65
+ checked++;
66
+ }
67
+ continue;
68
+ }
61
69
  if (attr.isBinding) {
62
70
  unchecked.push({
63
71
  reason: 'binding-not-literal',
@@ -281,16 +289,27 @@ function checkTreeRules(file, blockLine, props, attrs, errors) {
281
289
  const loadTree = props.get('loadTreeChildren') ??
282
290
  attrs.find((a) => resolvePropName(a.name) === 'loadTreeChildren');
283
291
  const truthy = (attr) => attr?.literalValue === true || attr?.literalValue === 'true';
284
- if (truthy(tree) && !getDataPath) {
292
+ const treeEnabled = (attr) => {
293
+ if (!attr) {
294
+ return false;
295
+ }
296
+ if (truthy(attr)) {
297
+ return true;
298
+ }
299
+ return (typeof attr.literalValue === 'string' &&
300
+ attr.literalValue !== '' &&
301
+ attr.literalValue !== 'false');
302
+ };
303
+ if (treeEnabled(tree) && !getDataPath) {
285
304
  errors.push({
286
305
  file,
287
306
  line: blockLine,
288
307
  rule: 'tree-requires-getdatapath',
289
308
  severity: 'error',
290
- message: 'tree: true 时必须提供 getDataPath',
309
+ message: '开启 tree 时必须提供 getDataPath。tree 为 true 时树列取第一个 isTree: true;为字符串时该值是树列 prop,且该列必须 isTree: true',
291
310
  });
292
311
  }
293
- if (truthy(tree) && truthy(rowGrouping)) {
312
+ if (treeEnabled(tree) && truthy(rowGrouping)) {
294
313
  errors.push({
295
314
  file,
296
315
  line: blockLine,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taocompany/magic-grid-mcp",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "CLI and MCP tools for validating @taocompany/magic-grid usage",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  "test:run": "vitest run"
34
34
  },
35
35
  "peerDependencies": {
36
- "@taocompany/magic-grid": "0.15.0"
36
+ "@taocompany/magic-grid": "0.15.1"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "@taocompany/magic-grid": {