@starci/eslint-grammar-core 0.37.2 → 0.38.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.
@@ -0,0 +1,64 @@
1
+ import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
2
+ import { grammarName } from "./lib/grammar-jsx.js";
3
+ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
4
+ /**
5
+ * ROWS IN A CARD (owner, 2026-11-09, ROWS-IN-CARD). A list of rows or key-value rows is always a card: on the pink well a card with a shadow and no border, on a white
6
+ * surface (aside, pane, drawer) a card with a 1px border and no shadow. Grammar draws that edge itself (the SURFACE-ELEVATION rule) when the rows stand in a
7
+ * `SurfaceCard` or a `Section`; a row primitive written bare on a surface is the repeated bug of a list with no edge.
8
+ *
9
+ * WHAT IT READS. In product source, a Grammar `DescriptionList` (key-value rows) or `DisclosureList` (disclosure rows) that no `SurfaceCard`, `Section`, `DataTable`
10
+ * or `Accordion` of the same file encloses. A row primitive passed as a JSX attribute value (`body={<DescriptionList/>}`) is judged where the receiving component draws it.
11
+ *
12
+ * WHAT IT LEAVES ALONE. `ListBox` (a selectable list pane and a menu are navigation, not rows of data: no static signal tells them apart), a row primitive another
13
+ * file wraps (a file whose only job is to return the rows is flagged here: wrap it in the `Section` or card in the same file), and non-product source.
14
+ */
15
+ const ROWS = new Set(["DescriptionList", "DisclosureList"]);
16
+ const CARDS = new Set(["SurfaceCard", "Section", "DataTable", "Accordion"]);
17
+ /** True when the element sits inside a Grammar card of this file, or inside a JSX attribute (the receiver draws it). */
18
+ const isHosted = (context, opening) => {
19
+ let previous = opening;
20
+ for (let current = opening.parent?.parent; current !== undefined && current !== null; previous = current, current = current.parent) {
21
+ if (current.type === "JSXAttribute")
22
+ return true;
23
+ if (current.type !== "JSXElement")
24
+ continue;
25
+ if (previous === current.openingElement)
26
+ continue;
27
+ const name = grammarName(context, current.openingElement);
28
+ if (name !== null && CARDS.has(name))
29
+ return true;
30
+ }
31
+ return false;
32
+ };
33
+ /** A list of rows stands in a card. */
34
+ export const rowsInCard = defineRule({
35
+ meta: {
36
+ type: "problem",
37
+ docs: { description: "ROWS-IN-CARD: a DescriptionList or DisclosureList stands in a SurfaceCard or a Section, so it is a card (shadow on the well, 1px border on a white surface)." },
38
+ schema: [],
39
+ messages: {
40
+ bare: "A `{{name}}` stands with no card around it. Rows are always a card: put them in a `Section` (`kind=\"list\"`) or a `SurfaceCard`; Grammar draws the shadow on the pink well and the 1px border on a white aside, pane or drawer by itself.",
41
+ },
42
+ },
43
+ create(context) {
44
+ if (!isProductSource(context))
45
+ return {};
46
+ return {
47
+ JSXOpeningElement(opening) {
48
+ const name = grammarName(context, opening);
49
+ if (name === null || !ROWS.has(name))
50
+ return;
51
+ if (isHosted(context, opening))
52
+ return;
53
+ context.report({ node: opening, messageId: "bare", data: { name } });
54
+ },
55
+ };
56
+ },
57
+ });
58
+ /** The rules this law contributes to the plugin. */
59
+ export const rules = {
60
+ "rows-in-card": rowsInCard,
61
+ };
62
+ defineFamilyRules(rules, "knowledge/ui/presentation/grammar-laws.yaml#ROWS-IN-CARD");
63
+ /** Every rule of this law is an error. */
64
+ export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
@@ -1,5 +1,5 @@
1
1
  import type { Rule } from "eslint";
2
- /** A section head holds one navigation Link or one info IconButton: no Button, no second command. */
2
+ /** A section head holds one navigation Link, one info IconButton or one neutral small Button: no commit, no icon Button, no second command. */
3
3
  export declare const sectionHeadAction: Rule.RuleModule;
4
4
  /** The rules this law contributes to the plugin. */
5
5
  export declare const rules: Record<string, Rule.RuleModule>;
@@ -1,18 +1,20 @@
1
1
  import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
2
- import { attributeOf, grammarName } from "./lib/grammar-jsx.js";
2
+ import { attributeOf, grammarName, literalString } from "./lib/grammar-jsx.js";
3
3
  import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
4
4
  /**
5
5
  * THE SECTION HEAD (owner, 2026-11-09, SECTION-HEAD-ACTION). A section's head is ONE row: the label (14, 500) and an optional count chip at the
6
- * start, and at the end at most ONE thing: a navigation `Link variant="head"` (the label then an arrow that slides on hover) or an info
7
- * `IconButton`. Navigation is a Link, never a Button, and the head never holds two commands.
6
+ * start, and at the end at most ONE thing: a navigation `Link variant="head"` (the label then an arrow that slides on hover), an info `IconButton`,
7
+ * or (0.37.25) a neutral small `Button` ("Gắn thêm provider"). The head never holds two commands.
8
8
  *
9
9
  * WHAT IT READS. A Grammar `Section` in product source whose `action` prop holds:
10
- * - a Grammar `Button` (message `button`): navigation is a `Link variant="head"`;
10
+ * - a Grammar `Button` that is not exactly `intent="neutral" size="sm"` (message `button`: a primary/commit or any other size is refused);
11
+ * - a `Button` that carries an icon (`startGlyph`, `startContent`, `endContent`, `icon`; message `icon`);
11
12
  * - more than one Grammar `Button`, `Link`, `IconButton` or `TextAction` (message `many`): the head has room for one.
12
13
  *
13
- * WHAT IT LEAVES ALONE. A `Section` with no `action`, an `action` that holds one Link or one IconButton, other components, and non-product source.
14
+ * WHAT IT LEAVES ALONE. A `Section` with no `action`, an `action` that holds one Link, one IconButton or one neutral sm text Button, other components, and non-product source.
14
15
  */
15
16
  const COMMANDS = new Set(["Button", "Link", "IconButton", "TextAction"]);
17
+ const ICON_PROPS = ["startGlyph", "startContent", "endContent", "icon", "iconSource"];
16
18
  /** Every Grammar command element an expression holds, in source order. */
17
19
  const commandsIn = (context, root) => {
18
20
  const found = [];
@@ -40,14 +42,15 @@ const commandsIn = (context, root) => {
40
42
  visit(root);
41
43
  return found;
42
44
  };
43
- /** A section head holds one navigation Link or one info IconButton: no Button, no second command. */
45
+ /** A section head holds one navigation Link, one info IconButton or one neutral small Button: no commit, no icon Button, no second command. */
44
46
  export const sectionHeadAction = defineRule({
45
47
  meta: {
46
48
  type: "problem",
47
- docs: { description: "SECTION-HEAD-ACTION: a Section's head action is one Link variant=\"head\" or one IconButton; never a Button, never more than one." },
49
+ docs: { description: "SECTION-HEAD-ACTION: a Section's head action is one Link variant=\"head\", one IconButton or one neutral sm Button; never a commit Button, never more than one." },
48
50
  schema: [],
49
51
  messages: {
50
- button: "A `Button` in a `Section` head `action`: the head's navigation is a `Link variant=\"head\"` (the label then a sliding arrow). A command that is not navigation belongs in the card or the page header.",
52
+ button: "A `Button` in a `Section` head `action` must be `intent=\"neutral\" size=\"sm\"` (a small quiet pill at the end of the label row); a primary or commit Button spends the view's one CTA, and another size breaks the head's 32px row. Navigation can also be a `Link variant=\"head\"`.",
53
+ icon: "A `Button` in a `Section` head `action` has no icon (`{{prop}}`): the head's neutral sm Button is text only.",
51
54
  many: "A `Section` head holds at most ONE thing at its end (a `Link variant=\"head\"` or an info `IconButton`); this `action` holds {{count}} commands. Keep the one that navigates and move the rest into the body.",
52
55
  },
53
56
  },
@@ -62,9 +65,16 @@ export const sectionHeadAction = defineRule({
62
65
  if (action === undefined || action.value === null)
63
66
  return;
64
67
  const commands = commandsIn(context, action.value);
65
- for (const command of commands)
66
- if (command.name === "Button")
68
+ for (const command of commands) {
69
+ if (command.name !== "Button")
70
+ continue;
71
+ const isNeutralSmall = literalString(attributeOf(command.node, "intent")) === "neutral" && literalString(attributeOf(command.node, "size")) === "sm";
72
+ if (!isNeutralSmall)
67
73
  context.report({ node: command.node, messageId: "button" });
74
+ const icon = ICON_PROPS.find((name) => attributeOf(command.node, name) !== undefined);
75
+ if (icon !== undefined)
76
+ context.report({ node: command.node, messageId: "icon", data: { prop: icon } });
77
+ }
68
78
  if (commands.length > 1)
69
79
  context.report({ node: action, messageId: "many", data: { count: String(commands.length) } });
70
80
  },
@@ -1,5 +1,5 @@
1
1
  import type { Rule } from "eslint";
2
- /** A table, list or chart standing alone is the surface, never wrapped in a card. */
2
+ /** A table component or a chart standing alone is the surface, never wrapped in a card; list cards are valid. */
3
3
  export declare const singleChildCard: Rule.RuleModule;
4
4
  /** The rules this law contributes to the plugin. */
5
5
  export declare const rules: Record<string, Rule.RuleModule>;
@@ -1,38 +1,26 @@
1
1
  import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
2
- import { attributeOf, elementNameOf, grammarName, hasSpread, renderedChildren, stringProp } from "./lib/grammar-jsx.js";
2
+ import { attributeOf, elementNameOf, grammarName, hasSpread, renderedChildren } from "./lib/grammar-jsx.js";
3
3
  import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
4
4
  /**
5
- * The lone surface law (owner, 2026-11-09, SINGLE-CHILD-CARD): a card groups two or more different parts (figures + list +
6
- * actions) or carries zones (tabs, search, head actions). A table, a list or a chart standing alone IS the surface: the
7
- * title sits above it as a `Section` head and one line sits under it as `Section caption` (muted, sm). The Grammar draws a
8
- * standalone `DataTable` (`surface="card"`) and every `Section kind="list"` as its own card (border, card radius, card shadow), so a
9
- * `SurfaceCard` around either is a second card around the first.
5
+ * The lone surface law (owner, 2026-11-09, SINGLE-CHILD-CARD; aligned 0.37.8): a card groups two or more different parts or carries zones. A card holding a LIST or
6
+ * key-value rows (`SurfaceCard kind="list"`, `kind="table"`, `kind="select"`, a `ListBox`, `DisclosureList`, `Section kind="list"`, a `DescriptionList`) is valid, alone or
7
+ * not: one list card with its head and count chip, or a bordered key-value card on a white aside, is the law. What is wrong is a card wrapping ONE non-list leaf that
8
+ * is a surface on its own: a `DataTable` (standalone it draws its own card) or a chart. The title sits above it as a `Section` head.
10
9
  *
11
- * WHAT IT READS. A Grammar `SurfaceCard` (imported from `@starci/grammar`) with no zones: no `headers` or `footers` prop (an
12
- * empty array literal counts as none) and no `labelEnd` (head actions). Its body is read through fragments, `cond && <x/>`,
13
- * `cond ? <x/> : <y/>` and `.map`, ignoring blank text. It is refused when that body is ONE element and that element is:
14
- * - a table: `DataTable`;
15
- * - a list: `ListBox`, `ItemList`, `DisclosureList`, `Timeline`, or `Section kind="list"`;
16
- * - a chart: `BarChart`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`.
17
- * It is also refused when the card is the data-driven form of the same thing: `SurfaceCard kind="table"` or `kind="list"`.
10
+ * WHAT IT READS. A Grammar `SurfaceCard` (imported from `@starci/grammar`) with no zones: no `headers` or `footers` prop (an empty array literal counts as none) and no
11
+ * `labelEnd` (head actions). Its body is read through fragments, `cond && <x/>`, `cond ? <x/> : <y/>` and `.map`, ignoring blank text. It is refused when that body is ONE
12
+ * element and that element is a `DataTable` or a chart: `BarChart`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`.
18
13
  *
19
- * DECIDED. `Meter`, `Progress` and `ProgressCircle` are single values, not charts. `DescriptionList` (term/value facts of one
20
- * record) and `Accordion` are not read as lists here: a record's facts are the `kind="details"` card. `SurfaceCard
21
- * kind="figures"`, `details`, `accordion` and `tile` are not judged. `SurfaceCard` rules for kinds, depth and nesting stay with
22
- * `surface-card-kind`, `no-raised-surface-in-surface` and `surface-depth`; none is read again here.
14
+ * DECIDED. Lists and key-value rows are never refused here. `Meter`, `Progress` and `ProgressCircle` are single values, not charts. `SurfaceCard kind="figures"`, `details`,
15
+ * `accordion`, `list`, `table`, `select` and `tile` are not judged. Kinds, depth and nesting stay with `surface-card-kind`, `no-raised-surface-in-surface` and `surface-depth`.
23
16
  *
24
- * WHAT IT LEAVES ALONE. A card with two or more body children, a card with zones or `labelEnd`, a card with a JSX spread (a
25
- * prop may arrive that the source does not show), a non-Grammar `SurfaceCard`, and non-product source.
17
+ * WHAT IT LEAVES ALONE. A card with two or more body children, a card with zones or `labelEnd`, a card with a JSX spread, a non-Grammar `SurfaceCard`, and non-product source.
26
18
  *
27
19
  * WHERE IT APPLIES. Product source (`isProductSource`).
28
20
  */
29
21
  /** The table, list and chart components that are a surface on their own, with the word the message names them by. */
30
22
  const LONE = new Map([
31
23
  ["DataTable", "table"],
32
- ["ListBox", "list"],
33
- ["ItemList", "list"],
34
- ["DisclosureList", "list"],
35
- ["Timeline", "list"],
36
24
  ["BarChart", "chart"],
37
25
  ["ProportionBar", "chart"],
38
26
  ["BubbleMap", "chart"],
@@ -63,18 +51,16 @@ const loneChild = (context, card) => {
63
51
  const name = elementNameOf(child);
64
52
  if (name === null || grammarName(context, child.openingElement) === null)
65
53
  return null;
66
- if (name === "Section")
67
- return stringProp(child.openingElement, "kind") === "list" ? "Section kind=\"list\"" : null;
68
54
  return LONE.has(name) ? name : null;
69
55
  };
70
- /** A table, list or chart standing alone is the surface, never wrapped in a card. */
56
+ /** A table component or a chart standing alone is the surface, never wrapped in a card; list cards are valid. */
71
57
  export const singleChildCard = defineRule({
72
58
  meta: {
73
59
  type: "problem",
74
- docs: { description: "SINGLE-CHILD-CARD: a SurfaceCard with no zones whose only content is a table, list or chart is a second frame; the title is a Section head." },
60
+ docs: { description: "SINGLE-CHILD-CARD: a SurfaceCard with no zones whose only content is a DataTable or a chart is a second frame; a card holding list or key-value rows is valid." },
75
61
  schema: [],
76
62
  messages: {
77
- lone: "A {{child}} standing alone is the surface: drop the SurfaceCard, put its title in a `Section` head (`title`) and one line under it in `Section caption`. A card groups two or more different parts, or carries zones (tabs, search, head actions).",
63
+ lone: "A {{child}} standing alone is the surface: drop the SurfaceCard, put its title in a `Section` head (`title`) and one line under it in `Section caption`. A card groups two or more different parts, or carries zones (tabs, search, head actions); a card of list or key-value rows is always valid.",
78
64
  },
79
65
  },
80
66
  create(context) {
@@ -85,11 +71,10 @@ export const singleChildCard = defineRule({
85
71
  const opening = element.openingElement;
86
72
  if (grammarName(context, opening) !== "SurfaceCard" || hasSpread(opening) || hasZones(opening))
87
73
  return;
88
- const kind = stringProp(opening, "kind");
89
- const child = kind === "table" || kind === "list" ? kind : loneChild(context, element);
74
+ const child = loneChild(context, element);
90
75
  if (child === null)
91
76
  return;
92
- context.report({ node: opening, messageId: "lone", data: { child: kind === child ? child : `\`${child}\`` } });
77
+ context.report({ node: opening, messageId: "lone", data: { child: `\`${child}\`` } });
93
78
  },
94
79
  };
95
80
  },
@@ -3,21 +3,19 @@ import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
3
3
  import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
4
4
  /**
5
5
  * The surface nesting law (HFS R340 `FE_RAISED_SURFACE_IN_SURFACE`): a surface never stands inside another surface. A
6
- * `SurfaceCard` inside another `SurfaceCard`, inside a `Pane surface`, or inside a `Dialog`, `Drawer`, `AlertDialog` or
7
- * `Popover` is refused; the Grammar has one depth, raised, and draws no nested edge: a surface never
8
- * sits in a surface, dialogs and drawers included. The Grammar throws the same refusal in development; this is its
6
+ * `SurfaceCard` inside another `SurfaceCard` is refused (0.37.5, owner: a card inside a card is the only nesting refused; a white `Pane surface`, `Drawer`,
7
+ * `Dialog` or `Popover` hosts cards, drawn bordered with no shadow). The Grammar throws the same refusal in development; this is its
9
8
  * same-file half, and R356 closes it across files.
10
9
  *
11
10
  * WHAT IT READS. A `SurfaceCard` element (or `<ns>.SurfaceCard`) imported from `@starci/grammar` that a `SurfaceCard`,
12
- * `Dialog`, `Drawer`, `AlertDialog`, `Popover` or `Pane` with a `surface` prop of the same file encloses. An overlay's
13
- * `trigger` is not its content, so a card written in a trigger is not enclosed by it. A surface nobody encloses in this file
11
+ * `SurfaceCard` of the same file encloses. A surface nobody encloses in this file
14
12
  * (its parent may nest it) is judged where the parent is written.
15
13
  *
16
14
  * WHERE IT APPLIES. Product source (`isProductSource`).
17
15
  */
18
16
  const GRAMMAR_SOURCE = /^@starci\/grammar(?:\/(?:common|core|offset-pop))?$/;
19
17
  /** Surfaces and overlays whose content is a surface. */
20
- const HOSTS = new Set(["SurfaceCard", "Dialog", "Drawer", "AlertDialog", "Popover", "Pane"]);
18
+ const HOSTS = new Set(["SurfaceCard"]);
21
19
  /** The element name of a JSX name: `SurfaceCard`, or `G.SurfaceCard` as `SurfaceCard`. */
22
20
  const nameOf = (name) => {
23
21
  if (name.type === "JSXIdentifier")
@@ -65,7 +63,7 @@ const enclosingHost = (context, opening) => {
65
63
  export const noRaisedSurfaceInSurface = defineRule({
66
64
  meta: {
67
65
  type: "problem",
68
- docs: { description: "R340: a SurfaceCard never stands inside another SurfaceCard, a Pane surface, or a Dialog, Drawer, AlertDialog or Popover." },
66
+ docs: { description: "R340: a SurfaceCard never stands inside another SurfaceCard." },
69
67
  schema: [],
70
68
  messages: {
71
69
  nested: "This `SurfaceCard` stands inside {{host}}: a surface never stands inside a surface (the Grammar has one depth and draws no nested edge). Give the content to the host's own body, or use a kind of the outer card (`bands`, `list`, `figures`) for what needs its own faces.",
package/dist/tabs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Rule } from "eslint";
2
- /** No pill in JSX: the pill is the `switch` header zone of a card. */
2
+ /** No pill in JSX: the pill is the `switch` header zone of a card, or the value of a row `control`. */
3
3
  export declare const tabsSwitchZone: Rule.RuleModule;
4
4
  /** At most two underline layers. */
5
5
  export declare const tabsDepth: Rule.RuleModule;
package/dist/tabs.js CHANGED
@@ -6,8 +6,10 @@ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
6
6
  *
7
7
  * `tabs-switch-zone`. The pill (`Tabs appearance="primary"`) is a mode or period switch of one block. The Grammar draws it
8
8
  * only as the `switch` header zone of a `SurfaceCard` (`headers={[{ kind: "switch", label, items, selectedKey, onSelect }]}`);
9
- * a `<Tabs appearance="primary">` written in JSX (a page body, under the page tabs, a pane, a drawer) is a finding. The
10
- * item checks (two to four, no count, no href) stay in `no-primary-tabs-misuse`.
9
+ * a `<Tabs appearance="primary">` written in JSX (a page body, under the page tabs, a pane, a drawer) is a finding. One
10
+ * exception (0.37.16, owner 2026-11-10): a row-level mode choice ("Tu dong | Hoi" on an agent's ability row) lives in the row's
11
+ * `control` slot, so a pill that is the value of a `control` (an object property named `control` in a select item or list row
12
+ * literal, or a JSX attribute `control={...}`) is allowed. The item checks (two to four, no count, no href) stay in `no-primary-tabs-misuse`.
11
13
  *
12
14
  * `tabs-depth`. A page stacks at most two underline layers: the page tabs (`Page header.tabs`) and one region set. A `Tabs`
13
15
  * is nested in another when it stands in the panel the other selects: inside a conditional or `&&` whose test reads the
@@ -34,17 +36,39 @@ const literalOf = (attribute) => {
34
36
  };
35
37
  /** Whether a `Tabs` element draws the pill. */
36
38
  const isPill = (opening) => literalOf(attributeOf(opening, "appearance")) === "primary";
37
- /** No pill in JSX: the pill is the `switch` header zone of a card. */
39
+ /** Whether a node is an object property whose key is `control`. */
40
+ const isControlProperty = (node) => node.type === "Property" && !node.computed && ((node.key.type === "Identifier" && node.key.name === "control") || (node.key.type === "Literal" && node.key.value === "control"));
41
+ /**
42
+ * Whether the pill stands as the value of a row `control`: climbing through fragments, expression containers, conditionals and
43
+ * `&&`/`||`/`??` it reaches an object property named `control` or a JSX attribute `control={...}`. A component or element that
44
+ * merely wraps the pill is not the slot.
45
+ */
46
+ const isRowControl = (opening) => {
47
+ let child = opening.parent ?? opening;
48
+ for (let node = child.parent; node !== undefined && node !== null; child = node, node = node.parent) {
49
+ if (node.type === "JSXFragment" || node.type === "JSXExpressionContainer")
50
+ continue;
51
+ if (node.type === "ConditionalExpression" && child !== node.test)
52
+ continue;
53
+ if (node.type === "LogicalExpression" && child === node.right)
54
+ continue;
55
+ if (node.type === "JSXAttribute")
56
+ return node.name.type === "JSXIdentifier" && node.name.name === "control";
57
+ return isControlProperty(node) && node.value === child;
58
+ }
59
+ return false;
60
+ };
61
+ /** No pill in JSX: the pill is the `switch` header zone of a card, or the value of a row `control`. */
38
62
  export const tabsSwitchZone = defineRule({
39
63
  meta: {
40
64
  type: "problem",
41
65
  docs: {
42
- description: "A pill (Tabs appearance=\"primary\") stands only as the switch header zone of a SurfaceCard; written in JSX anywhere else it is a finding.",
66
+ description: "A pill (Tabs appearance=\"primary\") stands only as the switch header zone of a SurfaceCard or as the value of a row `control`; written in JSX anywhere else it is a finding.",
43
67
  url: "knowledge/ui/presentation/grammar-laws.yaml#TABS-SWITCH-ZONE",
44
68
  },
45
69
  schema: [],
46
70
  messages: {
47
- pill: "A pill (`Tabs appearance=\"primary\"`) switches a mode or period of one block and is drawn only as the `switch` header zone of its card: `headers={[{ kind: \"switch\", label, items, selectedKey, onSelect }]}`, two to four short options with no count and no href. Written here it stands loose in the page. Views of a page are page tabs (`Page header.tabs`); views or filters inside a region are underline `Tabs`.",
71
+ pill: "A pill (`Tabs appearance=\"primary\"`) switches a mode or period of one block and is drawn only as the `switch` header zone of its card: `headers={[{ kind: \"switch\", label, items, selectedKey, onSelect }]}`, two to four short options with no count and no href. A row-level mode choice is the one other place: the row's `control` (`items={[{ id, title, control: <Tabs appearance=\"primary\" ... /> }]}`). Written here it stands loose in the page. Views of a page are page tabs (`Page header.tabs`); views or filters inside a region are underline `Tabs`.",
48
72
  },
49
73
  },
50
74
  create(context) {
@@ -52,7 +76,7 @@ export const tabsSwitchZone = defineRule({
52
76
  return {};
53
77
  return {
54
78
  JSXOpeningElement(opening) {
55
- if (elementName(opening) !== "Tabs" || !isPill(opening))
79
+ if (elementName(opening) !== "Tabs" || !isPill(opening) || isRowControl(opening))
56
80
  return;
57
81
  context.report({ node: opening, messageId: "pill" });
58
82
  },
@@ -0,0 +1,37 @@
1
+ # Message surfaces
2
+
3
+ Law module: `message-surfaces.ts`. Finding code: `FE_MESSAGE_SURFACES`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#MESSAGE-SURFACES`. Grammar laws: `DNA-COMMON-CHAT-SURFACES` (0.37.31), `DNA-COMMON-CHAT-FRAME` (0.37.33).
4
+
5
+ Every chat (team chat, an agent's chat, an inbox thread, the assistant) draws the same three faces, and they belong to the Grammar: the thread is the page tone (`--background`; a `PaneSection scroll role="log"` paints it whatever `tone` says), a message of someone else (`MessageBubble` incoming, `MessageCard`) is the flat `--surface` with no border and no shadow, and the reader's own message is `--accent` with `--accent-foreground`. The replies a message card offers are `SurfaceCard kind="list" layout="suggestions"` (one bordered list, a pressable plain-text row per reply with a chevron); the pills by the composer stay `Button size="sm"` (`suggestion-buttons`).
6
+
7
+ A chat is one frame on any page (0.37.33): its head, its thread and its composer footer are `--background`, whether it stands in a white pane, the aside, a drawer, a dialog or a popover; the rest of the page keeps its own rule. The frame is a `Pane content="chat"` (a pane whose own stack holds a thread is drawn as one too); the app gives it no tone, and a message in it is flat (no border, no shadow).
8
+
9
+ The rule is an error in `coreGrammarConfig`; it cannot be switched off or suppressed inline.
10
+
11
+ ## `starci-grammar/message-surfaces`
12
+
13
+ Flagged, in cheap static shapes only:
14
+
15
+ - a `className`, `class`, `style`, `UNSAFE_className` or `UNSAFE_style` attribute on a Grammar `MessageBubble` or `MessageCard`;
16
+ - a static class string (an attribute, a template without expressions, a `cn`/`clsx`/`cx`/`classNames`/`twMerge`/`twJoin` argument) or a style key in product source that names a Grammar message part (`starci-core-message-bubble…`, `starci-core-message-card…`);
17
+ - a `PaneSection` whose `scroll` object literal states `role: "log"` together with `tone: "surface"` (the Grammar ignores it: a thread is always the page tone);
18
+ - `surface` on a chat frame: a `Pane` with `content="chat"`, or a `Pane` whose own JSX children (fragments opened) hold a `PaneSection` with `scroll.role: "log"` (the frame is `--background`; the Grammar ignores the tone).
19
+
20
+ A spread, a computed class and a tone held in a variable are not read; a thread drawn by a component of the app's own (a `ChatThreadBand`) is not seen through, so such a pane states `content="chat"`.
21
+
22
+ **Invalid**
23
+
24
+ ```tsx
25
+ <MessageBubble className="shadow-none" body={text} />
26
+ <div className="[&_.starci-core-message-bubble-body]:bg-white">{thread}</div>
27
+ <PaneSection scroll={{ label: "Thread", role: "log", tone: "surface" }}>{thread}</PaneSection>
28
+ <Pane area="room" surface content="chat" footer={composer}>{head}{thread}</Pane>
29
+ ```
30
+
31
+ **Valid**
32
+
33
+ ```tsx
34
+ <Pane area="room" content="chat" label="Phòng" footer={composer}>{head}{thread}</Pane>
35
+ <PaneSection scroll={{ label: "Thread", role: "log", align: "end" }}>{thread}</PaneSection>
36
+ <MessageCard title="Quy trình đang dừng" body={<SurfaceCard kind="list" layout="suggestions" ariaLabel="Gợi ý" empty={null} items={replies} />} />
37
+ ```
@@ -0,0 +1,25 @@
1
+ # A card has no description
2
+
3
+ Law module: `no-card-lead-description.ts`. Finding code: `FE_NO_CARD_LEAD_DESCRIPTION`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#CARD-NO-DESCRIPTION`.
4
+
5
+ A card head is its label, a count chip, one fact and one end action. It has no description or subtitle (the `SurfaceCard` type has no such prop). A line that explains the card's data (a legend, a source, a period) is the card `note`; a line that explains a row is that row's subtitle.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/no-card-lead-description`
10
+
11
+ A Grammar `Text` with `tone="muted"` written immediately before a Grammar `SurfaceCard` in the same children list (message `lead`). A muted `Text` anywhere else, a native `<p>` and any other tone are not read.
12
+
13
+ **Invalid**
14
+
15
+ ```tsx
16
+ <Stack><Heading level={3}>Chung</Heading><Text tone="muted">Chọn cách agent làm việc.</Text><SurfaceCard kind="select" label="Chế độ" ... /></Stack>
17
+ ```
18
+
19
+ **Valid**
20
+
21
+ ```tsx
22
+ <SurfaceCard kind="select" label="Chế độ" items={[{ id: "auto", title: "Tự làm", subtitle: "Agent trả lời ngay, bạn xem lại sau." }]} ... />
23
+ ```
24
+
25
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -0,0 +1,30 @@
1
+ # One Label per section
2
+
3
+ Law module: `no-nested-label.ts`. Finding code: `FE_NO_NESTED_LABEL`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#LABEL-SUBLABEL-HIERARCHY`.
4
+
5
+ A section has exactly ONE Label (its head, 14 / 500, 12px above its content). The groups inside it are named by a Sublabel (12 / 500 muted, 8px above the card): a `Section` or `SurfaceCard` takes `sublabel` and then has no `title` / `label` (the types refuse both together). Groups stand 24px apart.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/no-nested-label`
10
+
11
+ A Grammar `Section` with `title`, or a `SurfaceCard` with `label`, whose JSX ancestor in the same file is a Grammar `Section` with `title` or `SurfaceCard` with `label` (message `nested`). Nesting across files and elements passed as attribute values are not read.
12
+
13
+ **Invalid**
14
+
15
+ ```tsx
16
+ <Section title="Agent hiểu gì về việc của bạn">
17
+ <SurfaceCard kind="select" label="Được tự làm" ... />
18
+ </Section>
19
+ ```
20
+
21
+ **Valid**
22
+
23
+ ```tsx
24
+ <Section title="Agent hiểu gì về việc của bạn">
25
+ <SurfaceCard kind="select" sublabel="Được tự làm" ... />
26
+ <SurfaceCard kind="select" sublabel="Phải hỏi bạn" ... />
27
+ </Section>
28
+ ```
29
+
30
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -0,0 +1,25 @@
1
+ # Rows of data are always a card
2
+
3
+ Law module: `rows-in-card.ts`. Finding code: `FE_ROWS_IN_CARD`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#ROWS-IN-CARD`.
4
+
5
+ A list of rows or key-value rows is a card: on the pink well a shadow and no border, on a white surface (aside, pane, drawer) a 1px border and no shadow. Grammar draws that edge itself when the rows stand in a `Section` or a `SurfaceCard`.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/rows-in-card`
10
+
11
+ A Grammar `DescriptionList` or `DisclosureList` that no `SurfaceCard`, `Section`, `DataTable` or `Accordion` of the same file encloses (message `bare`). A row primitive passed as a JSX attribute value is judged where the receiver draws it. `ListBox` (a navigation list or menu) is not read.
12
+
13
+ **Invalid**
14
+
15
+ ```tsx
16
+ <Stack><DescriptionList items={items} /></Stack>
17
+ ```
18
+
19
+ **Valid**
20
+
21
+ ```tsx
22
+ <SurfaceCard label="Details"><DescriptionList items={items} /></SurfaceCard>
23
+ ```
24
+
25
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -2,19 +2,20 @@
2
2
 
3
3
  Law module: `section-head-action.ts`. Finding code: `FE_SECTION_HEAD_ACTION`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#SECTION-HEAD-ACTION`.
4
4
 
5
- A `Section` head is ONE row: the label (14, weight 500) and an optional count chip at the start, and at the end at most ONE thing: a navigation `Link variant="head"` (the label then an arrow that slides about 3px on hover) or an info `IconButton`. A `description` is not under the label: it is a caption below the body.
5
+ A `Section` head is ONE row: the label (14, weight 500) and an optional count chip at the start, and at the end at most ONE thing: a navigation `Link variant="head"` (the label then an arrow that slides about 3px on hover), an info `IconButton`, or a neutral small text `Button` (0.37.25). A `description` is not under the label: it is a caption below the body.
6
6
 
7
7
  Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
8
 
9
9
  ## `starci-grammar/section-head-action`
10
10
 
11
- - A Grammar `Button` inside a `Section`'s `action` prop (message `button`): navigation is a `Link`.
11
+ - A Grammar `Button` inside a `Section`'s `action` prop that is not exactly `intent="neutral" size="sm"` (message `button`), or that carries an icon prop (`startGlyph`, `startContent`, `endContent`, `icon`; message `icon`).
12
12
  - More than one Grammar `Button`, `Link`, `IconButton` or `TextAction` inside that `action` (message `many`).
13
13
 
14
14
  **Invalid**
15
15
 
16
16
  ```tsx
17
- <Section title="Runs" action={<Button size="sm" onPress={open}>Open</Button>}>...</Section>
17
+ <Section title="Runs" action={<Button intent="commit" size="sm" onPress={open}>Open</Button>}>...</Section>
18
+ <Section title="Runs" action={<Button intent="neutral" size="sm" startGlyph="plus" onPress={open}>Add</Button>}>...</Section>
18
19
  <Section title="Runs" action={<><Link href="/a">A</Link><IconButton label="About" glyph="more" /></>}>...</Section>
19
20
  ```
20
21
 
@@ -23,6 +24,7 @@ Every rule below is an error in `coreGrammarConfig`; none can be switched off or
23
24
  ```tsx
24
25
  <Section title="Runs" count={3} action={<Link variant="head" href="/runs">All runs</Link>}>...</Section>
25
26
  <Section title="Runs" action={<IconButton label="About runs" glyph="more" />}>...</Section>
27
+ <Section title="Provider" count={2} action={<Button intent="neutral" size="sm" onPress={add}>Gắn thêm provider</Button>}>...</Section>
26
28
  ```
27
29
 
28
30
  Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -1,35 +1,33 @@
1
- # A table, list or chart standing alone is the surface
1
+ # A lone DataTable or chart is the surface; a list card is always valid
2
2
 
3
3
  Law module: `single-child-card.ts`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#SINGLE-CHILD-CARD`. Finding code: `FE_SINGLE_CHILD_CARD`.
4
4
 
5
- A card (`SurfaceCard`) groups two or more different parts (figures + list + actions), or carries zones (tabs, search, head actions). A table, list or chart standing alone IS the surface: its title sits above it as a `Section` head and one line sits under it as `Section caption` (muted, sm). The Grammar draws a standalone `DataTable` (`surface="card"`) and every `Section kind="list"` as its own card (border, card radius, card shadow; the table keeps HeroUI's native look inside), so a card around either is a second card.
5
+ A card (`SurfaceCard`) groups two or more different parts (figures + list + actions), or carries zones (tabs, search, head actions). A card of LIST or key-value rows (`kind="list"`, `kind="table"`, `kind="select"`, a `ListBox`, `DisclosureList`, `Timeline`, `Section kind="list"`, a `DescriptionList`) is valid alone or not (aligned in 0.37.8: one list card with its head and count chip, or a bordered key-value card on a white aside, is the law). A standalone `DataTable` (`surface="card"`) or chart IS the surface: its title sits above it as a `Section` head and one line under it as `Section caption`, so a card around it is a second card.
6
6
 
7
7
  Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
8
 
9
9
  ## `starci-grammar/single-child-card`
10
10
 
11
- A Grammar `SurfaceCard` is refused when it has no zones (no `headers` or `footers` prop, an empty array counts as none, and no `labelEnd`) and either:
11
+ A Grammar `SurfaceCard` is refused when it has no zones (no `headers` or `footers` prop, an empty array counts as none, and no `labelEnd`) and its only body child (looked through fragments, `cond && x`, `cond ? x : y` and `.map`; blank text ignored) is:
12
12
 
13
- - its only body child (looked through fragments, `cond && x`, `cond ? x : y` and `.map`; blank text ignored) is a table, a list or a chart:
14
- - table: `DataTable`
15
- - list: `ListBox`, `ItemList`, `DisclosureList`, `Timeline`, `Section kind="list"`
16
- - chart: `BarChart`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`
17
- - or it is `kind="table"` or `kind="list"` (the data-driven form of the same lone table or list).
13
+ - table: `DataTable`
14
+ - chart: `BarChart`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`
18
15
 
19
- Not flagged: a card with two or more body children, a card with zones or `labelEnd`, a card with a JSX spread, `kind` `figures`, `details`, `accordion` or `tile`, a non-Grammar `SurfaceCard`, and non-product source. `Meter`, `Progress` and `DescriptionList` (a record's term/value facts; its card is `kind="details"`) are not read as table, list or chart.
16
+ Not flagged: any list or key-value card (`kind="list"`, `kind="table"`, `kind="select"`, `ListBox`, `DisclosureList`, `Timeline`, `Section kind="list"`, `DescriptionList`), a card with two or more body children, a card with zones or `labelEnd`, a card with a JSX spread, `kind` `figures`, `details`, `accordion` or `tile`, a non-Grammar `SurfaceCard`, and non-product source. `Meter` and `Progress` are single values, not charts.
20
17
 
21
18
  **Invalid**
22
19
 
23
20
  ```tsx
24
21
  <SurfaceCard label="Runs"><DataTable columns={columns} rows={runs} /></SurfaceCard>
25
- <SurfaceCard label="Runs" kind="list" items={runs} empty={null} />
22
+ <SurfaceCard label="Usage"><BarChart data={usage} /></SurfaceCard>
26
23
  ```
27
24
 
28
25
  **Valid**
29
26
 
30
27
  ```tsx
31
28
  <Section title="Runs" caption="Last 30 days"><DataTable columns={columns} rows={runs} /></Section>
32
- <Section title="Runs" caption="Last 30 days" kind="list" items={runs} />
29
+ <SurfaceCard label="Runs" kind="list" items={runs} empty={null} />
30
+ <SurfaceCard label="Runs"><ListBox items={runs} /></SurfaceCard>
33
31
  <SurfaceCard label="Runs" headers={[{ kind: "search", /* ... */ }]}><DataTable columns={columns} rows={runs} /></SurfaceCard>
34
32
  <SurfaceCard label="Runs"><Text>3 failed</Text><DataTable columns={columns} rows={runs} /></SurfaceCard>
35
33
  ```
@@ -2,10 +2,7 @@
2
2
 
3
3
  Law module: `surface-depth.ts`. Catalogue: R340 FE_RAISED_SURFACE_IN_SURFACE.
4
4
 
5
- The Grammar draws one depth, raised, and no nested edge: a `SurfaceCard` inside another `SurfaceCard`, inside a
6
- `Pane surface`, or inside a `Dialog`, `Drawer`, `AlertDialog` or `Popover` is refused: a surface
7
- never sits in a surface, dialogs and drawers included. Development throws the same refusal from the Grammar itself; this rule is
8
- its same-file half and R356 closes it across files.
5
+ A `SurfaceCard` inside another `SurfaceCard` is refused (0.37.5): a card never sits in a card. A white `Pane surface`, `Drawer`, `Dialog`, `AlertDialog` or `Popover` HOSTS cards: on a white ground a card is the group and draws a 1px border with no shadow (SURFACE-ELEVATION); on the pink well it has the shadow and no border. Development throws the card-in-card refusal from the Grammar itself; this rule is its same-file half and R356 closes it across files.
9
6
 
10
7
  Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline. It applies to product
11
8
  source (the route, feature, component, hook, foundation, module and transport tiers and the workspace packages); a script or
@@ -13,11 +10,7 @@ a file no slot owns is not judged.
13
10
 
14
11
  ## `starci-grammar/no-raised-surface-in-surface`
15
12
 
16
- A `SurfaceCard` (or `<ns>.SurfaceCard`) imported from `@starci/grammar` that a `SurfaceCard`, `Dialog`, `Drawer`,
17
- `AlertDialog`, `Popover`, or a `Pane` with a `surface` prop of the same file encloses is a finding. An overlay's `trigger` is
18
- not its content, so a card written in a trigger is not enclosed by it. A surface no element of the file encloses is judged
19
- where its parent is written. The fix gives the content to the host's own body, or uses a kind of the outer card (`bands`,
20
- `list`, `figures`) for what needs its own faces.
13
+ A `SurfaceCard` (or `<ns>.SurfaceCard`) imported from `@starci/grammar` that another `SurfaceCard` of the same file encloses is a finding. A card no element of the file encloses is judged where its parent is written. The fix gives the content to the outer card's own body, or uses a kind of the outer card (`bands`, `list`, `figures`) for what needs its own faces.
21
14
 
22
15
  **Invalid** (`src/components/blocks/Runs/component.tsx`)
23
16
 
package/docs/tabs.md CHANGED
@@ -6,7 +6,7 @@ Underline tabs switch panels: the page tabs (`Page header.tabs`) and, inside a t
6
6
 
7
7
  ## `starci-grammar/tabs-switch-zone`
8
8
 
9
- Finding code: `FE_TABS_SWITCH_ZONE`. A `<Tabs appearance="primary">` written in JSX is a finding wherever it stands (a page body, under the page tabs, a pane, a drawer). The pill is drawn only as the `switch` header zone of a card, which has no JSX to write. The item checks (two to four options, no `count`, `href` or `isAttention`) stay in `no-primary-tabs-misuse` (R380).
9
+ Finding code: `FE_TABS_SWITCH_ZONE`. A `<Tabs appearance="primary">` written in JSX is a finding wherever it stands (a page body, under the page tabs, a pane, a drawer). The pill is drawn as the `switch` header zone of a card, which has no JSX to write, and, since 0.37.16, as the value of a row `control` (an object property named `control` in a select item or list row literal, or a JSX attribute `control={...}`, directly or through a fragment, conditional or `&&`): a row-level mode choice such as "Auto | Ask" lives in the row. The item checks (two to four options, no `count`, `href` or `isAttention`) stay in `no-primary-tabs-misuse` (R380).
10
10
 
11
11
  **Invalid**
12
12
 
@@ -19,6 +19,7 @@ Finding code: `FE_TABS_SWITCH_ZONE`. A `<Tabs appearance="primary">` written in
19
19
  **Valid**
20
20
 
21
21
  ```tsx
22
+ <SurfaceCard kind="select" label="Agent" selectionMode="multiple" items={[{ id: "send", title: "Send", control: <Tabs appearance="primary" label="Send" items={modes} selectedKey={mode} onSelect={setMode} /> }]} value={value} onChange={setValue} />
22
23
  <SurfaceCard kind="list" label="Cash" headers={[{ kind: "switch", label: "Period", items: periods, selectedKey: period, onSelect: setPeriod }]} items={rows} empty={empty} />
23
24
  ```
24
25